From 11716e0f11f97aba75cee2221646bbd2431c4e27 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sat, 28 Apr 2018 18:15:16 -0500 Subject: [PATCH] More misc functions (used to live as static functions in Slic3r::GUI perl file). Passing -DVAR_ABS and -DVAR_ABS_PATH=/path/to/slic3r/var on compile redirects where Slic3r expects to find its var directory. --- src/GUI/misc_ui.cpp | 32 ++++++++++++++++++++++++++++---- src/GUI/misc_ui.hpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index ef00fa2d3..8183ec020 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -1,5 +1,8 @@ #include "misc_ui.hpp" #include +#include + +#include namespace Slic3r { namespace GUI { @@ -14,11 +17,18 @@ void check_version(bool manual) { #endif const wxString var(const wxString& in) { + // TODO replace center string with path to VAR in actual distribution later + if (VAR_ABS) { + return VAR_ABS_PATH + "/" + in; + } else { + return bin() + VAR_REL + "/" + in; + } +} + +const wxString bin() { wxFileName f(wxStandardPaths::Get().GetExecutablePath()); wxString appPath(f.GetPath()); - - // replace center string with path to VAR in actual distribution later - return appPath + "/../var/" + in; + return appPath; } /// Returns the path to Slic3r's default user data directory. @@ -28,7 +38,6 @@ const wxString home(const wxString& in) { return wxGetHomeDir() + "/." + in + "/"; } - wxString decode_path(const wxString& in) { // TODO Stub return in; @@ -38,6 +47,21 @@ wxString encode_path(const wxString& in) { // TODO Stub return in; } + +void show_error(wxWindow* parent, const wxString& message) { + wxMessageDialog(parent, message, _("Error"), wxOK | wxICON_ERROR).ShowModal(); +} + +void show_info(wxWindow* parent, const wxString& message, const wxString& title = _("Notice")) { + wxMessageDialog(parent, message, title, wxOK | wxICON_INFORMATION).ShowModal(); +} + +void fatal_error(wxWindow* parent, const wxString& message) { + show_error(parent, message); + throw std::runtime_error(message.ToStdString()); +} + + /* sub append_submenu { my ($self, $menu, $string, $description, $submenu, $id, $icon) = @_; diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index 5276a3f8c..d8586fec7 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -29,16 +29,47 @@ constexpr bool isDev = true; constexpr bool isDev = false; #endif + +/// Mostly useful for Linux distro maintainers, this will change where Slic3r assumes +/// its ./var directory lives (where its art assets are). +/// Define VAR_ABS and VAR_ABS_PATH +#ifndef VAR_ABS + #define VAR_ABS false +#else + #define VAR_ABS true +#endif +#ifndef VAR_ABS_PATH + #define VAR_ABS_PATH "/usr/share/Slic3r/var" +#endif + +#ifndef VAR_REL // Redefine on compile + #define VAR_REL L"/../var" +#endif + /// Performs a check via the Internet for a new version of Slic3r. /// If this version of Slic3r was compiled with -DSLIC3R_DEV, check the development /// space instead of release. void check_version(bool manual = false); +/// Provides a path to Slic3r's var dir. const wxString var(const wxString& in); +/// Provide a path to where Slic3r exec'd from. +const wxString bin(); + /// Always returns path to home directory. const wxString home(const wxString& in = "Slic3r"); +/// Shows an error messagebox +void show_error(wxWindow* parent, const wxString& message); + +/// Shows an info messagebox. +void show_info(wxWindow* parent, const wxString& message, const wxString& title); + +/// Show an error messagebox and then throw an exception. +void fatal_error(wxWindow* parent, const wxString& message); + + template void append_menu_item(wxMenu* menu, const wxString& name,const wxString& help, T lambda, int id = wxID_ANY, const wxString& icon = "", const wxString& accel = "") { wxMenuItem* tmp = menu->Append(wxID_ANY, name, help);