added misc utility functions for the UI, including functions to get user home (for slic3r directory) and path to var.

This commit is contained in:
Joseph Lenox 2018-04-24 23:52:13 -05:00
parent 7211acc32d
commit 137716b8a3
4 changed files with 54 additions and 2 deletions

View File

@ -2,14 +2,17 @@
#define GUI_HPP #define GUI_HPP
#include "MainFrame.hpp" #include "MainFrame.hpp"
#include "Notifier.hpp" #include "Notifier.hpp"
#include <string>
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
// Friendly indices for the preset lists.
enum class PresetID { enum class PresetID {
PRINT = 0, PRINT = 0,
FILAMENT = 1, FILAMENT = 1,
PRINTER = 2 PRINTER = 2
}; };
using preset_list = std::vector<std::string>;
class App: public wxApp class App: public wxApp
{ {
@ -22,7 +25,7 @@ public:
private: private:
std::shared_ptr<Settings> gui_config; // GUI-specific configuration options std::shared_ptr<Settings> gui_config; // GUI-specific configuration options
Notifier* notifier; Notifier* notifier;
std::vector<preset_list> presets { preset_list(), preset_list(), preset_list() };
}; };
}} // namespace Slic3r::GUI }} // namespace Slic3r::GUI

View File

@ -15,6 +15,11 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si
tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(config), preset_editor_tabs(std::map<wxWindowID, PresetEditor*>()) tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(config), preset_editor_tabs(std::map<wxWindowID, PresetEditor*>())
{ {
// Set icon to either the .ico if windows or png for everything else. // Set icon to either the .ico if windows or png for everything else.
if (the_os == OS::Windows)
this->SetIcon(wxIcon(var("Slic3r.ico"), wxBITMAP_TYPE_ICO));
else
this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG));
this->init_tabpanel(); this->init_tabpanel();
this->init_menubar(); this->init_menubar();

View File

@ -11,5 +11,20 @@ void check_version(bool manual) {
#endif #endif
const wxString var(const wxString& in) {
wxFileName f(wxStandardPaths::Get().GetExecutablePath());
wxString appPath(f.GetPath());
// replace center string with path to VAR in actual distribution later
return appPath + "/../var/" + in;
}
/// Returns the path to Slic3r's default user data directory.
const wxString home(const wxString& in) {
if (the_os == OS::Windows)
return wxGetHomeDir() + "/" + in + "/";
return wxGetHomeDir() + "/." + in + "/";
}
}} // namespace Slic3r::GUI }} // namespace Slic3r::GUI

View File

@ -1,15 +1,44 @@
#ifndef MISC_UI_HPP #ifndef MISC_UI_HPP
#define MISC_UI_HPP #define MISC_UI_HPP
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/filename.h>
#include <wx/stdpaths.h>
/// Common static (that is, free-standing) functions, not part of an object hierarchy. /// Common static (that is, free-standing) functions, not part of an object hierarchy.
namespace Slic3r { namespace GUI { namespace Slic3r { namespace GUI {
enum class OS { Linux, Mac, Windows } ;
// constants to reduce the proliferation of macros in the rest of the code
#ifdef __WIN32
constexpr OS the_os = OS::Windows;
#elif __APPLE__
constexpr OS the_os = OS::Mac;
#elif __linux__
constexpr OS the_os = OS::Linux;
#endif
#ifdef SLIC3R_DEV
constexpr bool isDev = true;
#else
constexpr bool isDev = false;
#endif
/// Performs a check via the Internet for a new version of Slic3r. /// Performs a check via the Internet for a new version of Slic3r.
/// If this version of Slic3r was compiled with SLIC3R_DEV, check the development /// If this version of Slic3r was compiled with -DSLIC3R_DEV, check the development
/// space instead of release. /// space instead of release.
void check_version(bool manual = false); void check_version(bool manual = false);
const wxString var(const wxString& in);
/// Always returns path to home directory.
const wxString home(const wxString& in = "Slic3r");
}} // namespace Slic3r::GUI }} // namespace Slic3r::GUI
#endif // MISC_UI_HPP #endif // MISC_UI_HPP