From bb70ad609025a259f35f4f21e2fc9587c7a3fc2d Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 12 Sep 2018 13:17:47 +0200 Subject: [PATCH] Removed Strings.hpp, replaced with wxString Fixed UTF8 rendering of status messages. --- lib/Slic3r/GUI/MainFrame.pm | 1 + xs/CMakeLists.txt | 3 +- xs/src/libslic3r/Print.cpp | 1 - xs/src/slic3r/AppController.cpp | 3 +- xs/src/slic3r/AppController.hpp | 24 +++++---- xs/src/slic3r/AppControllerWx.cpp | 34 ++++++------ xs/src/slic3r/GUI/GLCanvas3D.cpp | 1 + xs/src/slic3r/GUI/GUI.cpp | 9 ++++ xs/src/slic3r/GUI/GUI.hpp | 3 ++ xs/src/slic3r/GUI/ProgressStatusBar.cpp | 2 +- xs/src/slic3r/ProgressIndicator.hpp | 71 ------------------------- xs/src/slic3r/Strings.hpp | 10 ---- xs/xsp/GUI.xsp | 3 ++ xs/xsp/ProgressStatusBar.xsp | 2 +- 14 files changed, 51 insertions(+), 116 deletions(-) delete mode 100644 xs/src/slic3r/ProgressIndicator.hpp delete mode 100644 xs/src/slic3r/Strings.hpp diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 6ecfa6860..59c39dc8b 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -78,6 +78,7 @@ sub new { $self->{statusbar}->Embed; $self->{statusbar}->SetStatusText(L("Version ").$Slic3r::VERSION.L(" - Remember to check for updates at http://github.com/prusa3d/slic3r/releases")); # Make the global status bar and its progress indicator available in C++ + Slic3r::GUI::set_progress_status_bar($self->{statusbar}); $appController->set_global_progress_indicator($self->{statusbar}); $appController->set_model($self->{plater}->{model}); diff --git a/xs/CMakeLists.txt b/xs/CMakeLists.txt index 755856dde..272a1ad71 100644 --- a/xs/CMakeLists.txt +++ b/xs/CMakeLists.txt @@ -263,6 +263,7 @@ add_library(libslic3r_gui STATIC ${LIBDIR}/slic3r/GUI/UpdateDialogs.hpp ${LIBDIR}/slic3r/GUI/FirmwareDialog.cpp ${LIBDIR}/slic3r/GUI/FirmwareDialog.hpp + ${LIBDIR}/slic3r/GUI/ProgressIndicator.hpp ${LIBDIR}/slic3r/GUI/ProgressStatusBar.hpp ${LIBDIR}/slic3r/GUI/ProgressStatusBar.cpp ${LIBDIR}/slic3r/Utils/Http.cpp @@ -285,11 +286,9 @@ add_library(libslic3r_gui STATIC ${LIBDIR}/slic3r/Utils/Time.hpp ${LIBDIR}/slic3r/Utils/HexFile.cpp ${LIBDIR}/slic3r/Utils/HexFile.hpp - ${LIBDIR}/slic3r/ProgressIndicator.hpp ${LIBDIR}/slic3r/AppController.hpp ${LIBDIR}/slic3r/AppController.cpp ${LIBDIR}/slic3r/AppControllerWx.cpp - ${LIBDIR}/slic3r/Strings.hpp ) add_library(admesh STATIC diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index ae02216df..c8a50a6bb 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -14,7 +14,6 @@ #include #include -//#include "slic3r/ProgressIndicator.hpp" #include "PrintExport.hpp" //! macro used to mark string used at localization, diff --git a/xs/src/slic3r/AppController.cpp b/xs/src/slic3r/AppController.cpp index faecf9ecd..5e259c367 100644 --- a/xs/src/slic3r/AppController.cpp +++ b/xs/src/slic3r/AppController.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -409,7 +408,7 @@ const PrintConfig &PrintController::config() const #endif void ProgressIndicator::message_fmt( - const string &fmtstr, ...) { + const wxString &fmtstr, ...) { std::stringstream ss; va_list args; va_start(args, fmtstr); diff --git a/xs/src/slic3r/AppController.hpp b/xs/src/slic3r/AppController.hpp index b9af3bbd9..740f9a630 100644 --- a/xs/src/slic3r/AppController.hpp +++ b/xs/src/slic3r/AppController.hpp @@ -7,7 +7,9 @@ #include #include -#include "ProgressIndicator.hpp" +#include "GUI/ProgressIndicator.hpp" + +#include namespace Slic3r { @@ -46,7 +48,7 @@ public: AppControllerBoilerplate(); ~AppControllerBoilerplate(); - using Path = string; + using Path = wxString; using PathList = std::vector; /// Common runtime issue types @@ -67,20 +69,20 @@ public: * @return Returns a list of paths choosed by the user. */ PathList query_destination_paths( - const string& title, + const wxString& title, const std::string& extensions) const; /** * @brief Same as query_destination_paths but works for directories only. */ PathList query_destination_dirs( - const string& title) const; + const wxString& title) const; /** * @brief Same as query_destination_paths but returns only one path. */ Path query_destination_path( - const string& title, + const wxString& title, const std::string& extensions, const std::string& hint = "") const; @@ -95,11 +97,11 @@ public: * title. */ bool report_issue(IssueType issuetype, - const string& description, - const string& brief); + const wxString& description, + const wxString& brief); bool report_issue(IssueType issuetype, - const string& description); + const wxString& description); /** * @brief Return the global progress indicator for the current controller. @@ -150,12 +152,12 @@ protected: */ ProgresIndicatorPtr create_progress_indicator( unsigned statenum, - const string& title, - const string& firstmsg) const; + const wxString& title, + const wxString& firstmsg) const; ProgresIndicatorPtr create_progress_indicator( unsigned statenum, - const string& title) const; + const wxString& title) const; // This is a global progress indicator placeholder. In the Slic3r UI it can // contain the progress indicator on the statusbar. diff --git a/xs/src/slic3r/AppControllerWx.cpp b/xs/src/slic3r/AppControllerWx.cpp index 39192e7d3..bd2859fce 100644 --- a/xs/src/slic3r/AppControllerWx.cpp +++ b/xs/src/slic3r/AppControllerWx.cpp @@ -33,7 +33,7 @@ void AppControllerBoilerplate::process_events() AppControllerBoilerplate::PathList AppControllerBoilerplate::query_destination_paths( - const string &title, + const wxString &title, const std::string &extensions) const { @@ -53,7 +53,7 @@ AppControllerBoilerplate::query_destination_paths( AppControllerBoilerplate::Path AppControllerBoilerplate::query_destination_path( - const string &title, + const wxString &title, const std::string &extensions, const std::string& hint) const { @@ -72,8 +72,8 @@ AppControllerBoilerplate::query_destination_path( } bool AppControllerBoilerplate::report_issue(IssueType issuetype, - const string &description, - const string &brief) + const wxString &description, + const wxString &brief) { auto icon = wxICON_INFORMATION; auto style = wxOK|wxCENTRE; @@ -91,9 +91,9 @@ bool AppControllerBoilerplate::report_issue(IssueType issuetype, bool AppControllerBoilerplate::report_issue( AppControllerBoilerplate::IssueType issuetype, - const string &description) + const wxString &description) { - return report_issue(issuetype, description, string()); + return report_issue(issuetype, description, wxString()); } wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent); @@ -137,8 +137,8 @@ public: /// Get the mode of parallel operation. inline bool asynch() const { return is_asynch_; } - inline GuiProgressIndicator(int range, const string& title, - const string& firstmsg) : + inline GuiProgressIndicator(int range, const wxString& title, + const wxString& firstmsg) : gauge_(title, firstmsg, range, wxTheApp->GetTopWindow(), wxPD_APP_MODAL | wxPD_AUTO_HIDE), message_(firstmsg), @@ -171,18 +171,18 @@ public: } else _state(st); } - virtual void message(const string & msg) override { + virtual void message(const wxString & msg) override { message_ = msg; } - virtual void messageFmt(const string& fmt, ...) { + virtual void messageFmt(const wxString& fmt, ...) { va_list arglist; va_start(arglist, fmt); message_ = wxString::Format(wxString(fmt), arglist); va_end(arglist); } - virtual void title(const string & title) override { + virtual void title(const wxString & title) override { title_ = title; } }; @@ -190,7 +190,7 @@ public: AppControllerBoilerplate::ProgresIndicatorPtr AppControllerBoilerplate::create_progress_indicator( - unsigned statenum, const string& title, const string& firstmsg) const + unsigned statenum, const wxString& title, const wxString& firstmsg) const { auto pri = std::make_shared(statenum, title, firstmsg); @@ -204,9 +204,9 @@ AppControllerBoilerplate::create_progress_indicator( AppControllerBoilerplate::ProgresIndicatorPtr AppControllerBoilerplate::create_progress_indicator(unsigned statenum, - const string &title) const + const wxString &title) const { - return create_progress_indicator(statenum, title, string()); + return create_progress_indicator(statenum, title, wxString()); } namespace { @@ -271,18 +271,18 @@ public: } } - virtual void message(const string & msg) override { + virtual void message(const wxString & msg) override { message_ = msg; } - virtual void message_fmt(const string& fmt, ...) override { + virtual void message_fmt(const wxString& fmt, ...) override { va_list arglist; va_start(arglist, fmt); message_ = wxString::Format(fmt, arglist); va_end(arglist); } - virtual void title(const string & /*title*/) override {} + virtual void title(const wxString & /*title*/) override {} virtual void on_cancel(CancelFn fn) override { sbar_->set_cancel_callback(fn); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index eebaffc2a..2aaa4aed9 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -20,6 +20,7 @@ #include #include +// Print now includes tbb, and tbb includes Windows. This breaks compilation of wxWidgets if included before wx. #include "../../libslic3r/Print.hpp" #include diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index dda2cb953..e5ab22e8e 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -48,6 +48,7 @@ #include "AboutDialog.hpp" #include "AppConfig.hpp" #include "ConfigSnapshotDialog.hpp" +#include "ProgressStatusBar.hpp" #include "Utils.hpp" #include "MsgDialog.hpp" #include "ConfigWizard.hpp" @@ -114,6 +115,7 @@ void break_to_debugger() // Passing the wxWidgets GUI classes instantiated by the Perl part to C++. wxApp *g_wxApp = nullptr; wxFrame *g_wxMainFrame = nullptr; +ProgressStatusBar *g_progress_status_bar = nullptr; wxNotebook *g_wxTabPanel = nullptr; wxPanel *g_wxPlater = nullptr; AppConfig *g_AppConfig = nullptr; @@ -207,6 +209,13 @@ void set_main_frame(wxFrame *main_frame) wxFrame* get_main_frame() { return g_wxMainFrame; } +void set_progress_status_bar(ProgressStatusBar *prsb) +{ + g_progress_status_bar = prsb; +} + +ProgressStatusBar* get_progress_status_bar() { return g_progress_status_bar; } + void set_tab_panel(wxNotebook *tab_panel) { g_wxTabPanel = tab_panel; diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 1f5805bb6..7105b8b4e 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -33,6 +33,7 @@ namespace Slic3r { class PresetBundle; class PresetCollection; class Print; +class ProgressStatusBar; class AppConfig; class PresetUpdater; class DynamicPrintConfig; @@ -99,6 +100,7 @@ void break_to_debugger(); // Passing the wxWidgets GUI classes instantiated by the Perl part to C++. void set_wxapp(wxApp *app); void set_main_frame(wxFrame *main_frame); +void set_progress_status_bar(ProgressStatusBar *prsb); void set_tab_panel(wxNotebook *tab_panel); void set_plater(wxPanel *plater); void set_app_config(AppConfig *app_config); @@ -123,6 +125,7 @@ AppConfig* get_app_config(); wxApp* get_app(); PresetBundle* get_preset_bundle(); wxFrame* get_main_frame(); +ProgressStatusBar* get_progress_status_bar(); wxNotebook * get_tab_panel(); wxNotebook* get_tab_panel(); diff --git a/xs/src/slic3r/GUI/ProgressStatusBar.cpp b/xs/src/slic3r/GUI/ProgressStatusBar.cpp index 224ad8af5..3c2bdee6a 100644 --- a/xs/src/slic3r/GUI/ProgressStatusBar.cpp +++ b/xs/src/slic3r/GUI/ProgressStatusBar.cpp @@ -135,7 +135,7 @@ void ProgressStatusBar::embed(wxFrame *frame) void ProgressStatusBar::set_status_text(const std::string& txt) { - self->SetStatusText(txt); + self->SetStatusText(wxString::FromUTF8(txt.c_str())); } void ProgressStatusBar::show_cancel_button() diff --git a/xs/src/slic3r/ProgressIndicator.hpp b/xs/src/slic3r/ProgressIndicator.hpp deleted file mode 100644 index 4a39e84ab..000000000 --- a/xs/src/slic3r/ProgressIndicator.hpp +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef IPROGRESSINDICATOR_HPP -#define IPROGRESSINDICATOR_HPP - -#include -#include -#include "Strings.hpp" - -namespace Slic3r { - -/** - * @brief Generic progress indication interface. - */ -class ProgressIndicator { -public: - using CancelFn = std::function; // Cancel function signature. - -private: - float state_ = .0f, max_ = 1.f, step_; - CancelFn cancelfunc_ = [](){}; - -public: - - inline virtual ~ProgressIndicator() {} - - /// Get the maximum of the progress range. - float max() const { return max_; } - - /// Get the current progress state - float state() const { return state_; } - - /// Set the maximum of the progress range - virtual void max(float maxval) { max_ = maxval; } - - /// Set the current state of the progress. - virtual void state(float val) { state_ = val; } - - /** - * @brief Number of states int the progress. Can be used instead of giving a - * maximum value. - */ - virtual void states(unsigned statenum) { - step_ = max_ / statenum; - } - - /// Message shown on the next status update. - virtual void message(const string&) = 0; - - /// Title of the operation. - virtual void title(const string&) = 0; - - /// Formatted message for the next status update. Works just like sprintf. - virtual void message_fmt(const string& fmt, ...); - - /// Set up a cancel callback for the operation if feasible. - virtual void on_cancel(CancelFn func = CancelFn()) { cancelfunc_ = func; } - - /** - * Explicitly shut down the progress indicator and call the associated - * callback. - */ - virtual void cancel() { cancelfunc_(); } - - /// Convenience function to call message and status update in one function. - void update(float st, const string& msg) { - message(msg); state(st); - } -}; - -} - -#endif // IPROGRESSINDICATOR_HPP diff --git a/xs/src/slic3r/Strings.hpp b/xs/src/slic3r/Strings.hpp deleted file mode 100644 index b267fe064..000000000 --- a/xs/src/slic3r/Strings.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef STRINGS_HPP -#define STRINGS_HPP - -#include "GUI/GUI.hpp" - -namespace Slic3r { -using string = wxString; -} - -#endif // STRINGS_HPP diff --git a/xs/xsp/GUI.xsp b/xs/xsp/GUI.xsp index f8769d358..3aee4035e 100644 --- a/xs/xsp/GUI.xsp +++ b/xs/xsp/GUI.xsp @@ -35,6 +35,9 @@ bool is_windows10() void set_wxapp(SV *ui) %code%{ Slic3r::GUI::set_wxapp((wxApp*)wxPli_sv_2_object(aTHX_ ui, "Wx::App")); %}; +void set_progress_status_bar(ProgressStatusBar *prs) + %code%{ Slic3r::GUI::set_progress_status_bar(prs); %}; + void set_main_frame(SV *ui) %code%{ Slic3r::GUI::set_main_frame((wxFrame*)wxPli_sv_2_object(aTHX_ ui, "Wx::Frame")); %}; diff --git a/xs/xsp/ProgressStatusBar.xsp b/xs/xsp/ProgressStatusBar.xsp index f59895581..6f41b2d2b 100644 --- a/xs/xsp/ProgressStatusBar.xsp +++ b/xs/xsp/ProgressStatusBar.xsp @@ -36,7 +36,7 @@ void Embed() %code%{ THIS->embed(); %}; - void SetStatusText(std::string txt) + void SetStatusText(const char *txt) %code%{ THIS->set_status_text(txt); %}; void ShowCancelButton()