Removed Strings.hpp, replaced with wxString

Fixed UTF8 rendering of status messages.
This commit is contained in:
bubnikv 2018-09-12 13:17:47 +02:00
parent 0235f1a821
commit bb70ad6090
14 changed files with 51 additions and 116 deletions

View File

@ -78,6 +78,7 @@ sub new {
$self->{statusbar}->Embed; $self->{statusbar}->Embed;
$self->{statusbar}->SetStatusText(L("Version ").$Slic3r::VERSION.L(" - Remember to check for updates at http://github.com/prusa3d/slic3r/releases")); $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++ # 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_global_progress_indicator($self->{statusbar});
$appController->set_model($self->{plater}->{model}); $appController->set_model($self->{plater}->{model});

View File

@ -263,6 +263,7 @@ add_library(libslic3r_gui STATIC
${LIBDIR}/slic3r/GUI/UpdateDialogs.hpp ${LIBDIR}/slic3r/GUI/UpdateDialogs.hpp
${LIBDIR}/slic3r/GUI/FirmwareDialog.cpp ${LIBDIR}/slic3r/GUI/FirmwareDialog.cpp
${LIBDIR}/slic3r/GUI/FirmwareDialog.hpp ${LIBDIR}/slic3r/GUI/FirmwareDialog.hpp
${LIBDIR}/slic3r/GUI/ProgressIndicator.hpp
${LIBDIR}/slic3r/GUI/ProgressStatusBar.hpp ${LIBDIR}/slic3r/GUI/ProgressStatusBar.hpp
${LIBDIR}/slic3r/GUI/ProgressStatusBar.cpp ${LIBDIR}/slic3r/GUI/ProgressStatusBar.cpp
${LIBDIR}/slic3r/Utils/Http.cpp ${LIBDIR}/slic3r/Utils/Http.cpp
@ -285,11 +286,9 @@ add_library(libslic3r_gui STATIC
${LIBDIR}/slic3r/Utils/Time.hpp ${LIBDIR}/slic3r/Utils/Time.hpp
${LIBDIR}/slic3r/Utils/HexFile.cpp ${LIBDIR}/slic3r/Utils/HexFile.cpp
${LIBDIR}/slic3r/Utils/HexFile.hpp ${LIBDIR}/slic3r/Utils/HexFile.hpp
${LIBDIR}/slic3r/ProgressIndicator.hpp
${LIBDIR}/slic3r/AppController.hpp ${LIBDIR}/slic3r/AppController.hpp
${LIBDIR}/slic3r/AppController.cpp ${LIBDIR}/slic3r/AppController.cpp
${LIBDIR}/slic3r/AppControllerWx.cpp ${LIBDIR}/slic3r/AppControllerWx.cpp
${LIBDIR}/slic3r/Strings.hpp
) )
add_library(admesh STATIC add_library(admesh STATIC

View File

@ -14,7 +14,6 @@
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/log/trivial.hpp> #include <boost/log/trivial.hpp>
//#include "slic3r/ProgressIndicator.hpp"
#include "PrintExport.hpp" #include "PrintExport.hpp"
//! macro used to mark string used at localization, //! macro used to mark string used at localization,

View File

@ -11,7 +11,6 @@
#include <ModelArrange.hpp> #include <ModelArrange.hpp>
#include <slic3r/GUI/PresetBundle.hpp> #include <slic3r/GUI/PresetBundle.hpp>
#include <PrintConfig.hpp>
#include <Print.hpp> #include <Print.hpp>
#include <PrintExport.hpp> #include <PrintExport.hpp>
#include <Geometry.hpp> #include <Geometry.hpp>
@ -409,7 +408,7 @@ const PrintConfig &PrintController::config() const
#endif #endif
void ProgressIndicator::message_fmt( void ProgressIndicator::message_fmt(
const string &fmtstr, ...) { const wxString &fmtstr, ...) {
std::stringstream ss; std::stringstream ss;
va_list args; va_list args;
va_start(args, fmtstr); va_start(args, fmtstr);

View File

@ -7,7 +7,9 @@
#include <atomic> #include <atomic>
#include <iostream> #include <iostream>
#include "ProgressIndicator.hpp" #include "GUI/ProgressIndicator.hpp"
#include <PrintConfig.hpp>
namespace Slic3r { namespace Slic3r {
@ -46,7 +48,7 @@ public:
AppControllerBoilerplate(); AppControllerBoilerplate();
~AppControllerBoilerplate(); ~AppControllerBoilerplate();
using Path = string; using Path = wxString;
using PathList = std::vector<Path>; using PathList = std::vector<Path>;
/// Common runtime issue types /// Common runtime issue types
@ -67,20 +69,20 @@ public:
* @return Returns a list of paths choosed by the user. * @return Returns a list of paths choosed by the user.
*/ */
PathList query_destination_paths( PathList query_destination_paths(
const string& title, const wxString& title,
const std::string& extensions) const; const std::string& extensions) const;
/** /**
* @brief Same as query_destination_paths but works for directories only. * @brief Same as query_destination_paths but works for directories only.
*/ */
PathList query_destination_dirs( PathList query_destination_dirs(
const string& title) const; const wxString& title) const;
/** /**
* @brief Same as query_destination_paths but returns only one path. * @brief Same as query_destination_paths but returns only one path.
*/ */
Path query_destination_path( Path query_destination_path(
const string& title, const wxString& title,
const std::string& extensions, const std::string& extensions,
const std::string& hint = "") const; const std::string& hint = "") const;
@ -95,11 +97,11 @@ public:
* title. * title.
*/ */
bool report_issue(IssueType issuetype, bool report_issue(IssueType issuetype,
const string& description, const wxString& description,
const string& brief); const wxString& brief);
bool report_issue(IssueType issuetype, bool report_issue(IssueType issuetype,
const string& description); const wxString& description);
/** /**
* @brief Return the global progress indicator for the current controller. * @brief Return the global progress indicator for the current controller.
@ -150,12 +152,12 @@ protected:
*/ */
ProgresIndicatorPtr create_progress_indicator( ProgresIndicatorPtr create_progress_indicator(
unsigned statenum, unsigned statenum,
const string& title, const wxString& title,
const string& firstmsg) const; const wxString& firstmsg) const;
ProgresIndicatorPtr create_progress_indicator( ProgresIndicatorPtr create_progress_indicator(
unsigned statenum, unsigned statenum,
const string& title) const; const wxString& title) const;
// This is a global progress indicator placeholder. In the Slic3r UI it can // This is a global progress indicator placeholder. In the Slic3r UI it can
// contain the progress indicator on the statusbar. // contain the progress indicator on the statusbar.

View File

@ -33,7 +33,7 @@ void AppControllerBoilerplate::process_events()
AppControllerBoilerplate::PathList AppControllerBoilerplate::PathList
AppControllerBoilerplate::query_destination_paths( AppControllerBoilerplate::query_destination_paths(
const string &title, const wxString &title,
const std::string &extensions) const const std::string &extensions) const
{ {
@ -53,7 +53,7 @@ AppControllerBoilerplate::query_destination_paths(
AppControllerBoilerplate::Path AppControllerBoilerplate::Path
AppControllerBoilerplate::query_destination_path( AppControllerBoilerplate::query_destination_path(
const string &title, const wxString &title,
const std::string &extensions, const std::string &extensions,
const std::string& hint) const const std::string& hint) const
{ {
@ -72,8 +72,8 @@ AppControllerBoilerplate::query_destination_path(
} }
bool AppControllerBoilerplate::report_issue(IssueType issuetype, bool AppControllerBoilerplate::report_issue(IssueType issuetype,
const string &description, const wxString &description,
const string &brief) const wxString &brief)
{ {
auto icon = wxICON_INFORMATION; auto icon = wxICON_INFORMATION;
auto style = wxOK|wxCENTRE; auto style = wxOK|wxCENTRE;
@ -91,9 +91,9 @@ bool AppControllerBoilerplate::report_issue(IssueType issuetype,
bool AppControllerBoilerplate::report_issue( bool AppControllerBoilerplate::report_issue(
AppControllerBoilerplate::IssueType issuetype, 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); wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
@ -137,8 +137,8 @@ public:
/// Get the mode of parallel operation. /// Get the mode of parallel operation.
inline bool asynch() const { return is_asynch_; } inline bool asynch() const { return is_asynch_; }
inline GuiProgressIndicator(int range, const string& title, inline GuiProgressIndicator(int range, const wxString& title,
const string& firstmsg) : const wxString& firstmsg) :
gauge_(title, firstmsg, range, wxTheApp->GetTopWindow(), gauge_(title, firstmsg, range, wxTheApp->GetTopWindow(),
wxPD_APP_MODAL | wxPD_AUTO_HIDE), wxPD_APP_MODAL | wxPD_AUTO_HIDE),
message_(firstmsg), message_(firstmsg),
@ -171,18 +171,18 @@ public:
} else _state(st); } else _state(st);
} }
virtual void message(const string & msg) override { virtual void message(const wxString & msg) override {
message_ = msg; message_ = msg;
} }
virtual void messageFmt(const string& fmt, ...) { virtual void messageFmt(const wxString& fmt, ...) {
va_list arglist; va_list arglist;
va_start(arglist, fmt); va_start(arglist, fmt);
message_ = wxString::Format(wxString(fmt), arglist); message_ = wxString::Format(wxString(fmt), arglist);
va_end(arglist); va_end(arglist);
} }
virtual void title(const string & title) override { virtual void title(const wxString & title) override {
title_ = title; title_ = title;
} }
}; };
@ -190,7 +190,7 @@ public:
AppControllerBoilerplate::ProgresIndicatorPtr AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator( AppControllerBoilerplate::create_progress_indicator(
unsigned statenum, const string& title, const string& firstmsg) const unsigned statenum, const wxString& title, const wxString& firstmsg) const
{ {
auto pri = auto pri =
std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg); std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg);
@ -204,9 +204,9 @@ AppControllerBoilerplate::create_progress_indicator(
AppControllerBoilerplate::ProgresIndicatorPtr AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator(unsigned statenum, 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 { namespace {
@ -271,18 +271,18 @@ public:
} }
} }
virtual void message(const string & msg) override { virtual void message(const wxString & msg) override {
message_ = msg; message_ = msg;
} }
virtual void message_fmt(const string& fmt, ...) override { virtual void message_fmt(const wxString& fmt, ...) override {
va_list arglist; va_list arglist;
va_start(arglist, fmt); va_start(arglist, fmt);
message_ = wxString::Format(fmt, arglist); message_ = wxString::Format(fmt, arglist);
va_end(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 { virtual void on_cancel(CancelFn fn) override {
sbar_->set_cancel_callback(fn); sbar_->set_cancel_callback(fn);

View File

@ -20,6 +20,7 @@
#include <wx/image.h> #include <wx/image.h>
#include <wx/settings.h> #include <wx/settings.h>
// Print now includes tbb, and tbb includes Windows. This breaks compilation of wxWidgets if included before wx.
#include "../../libslic3r/Print.hpp" #include "../../libslic3r/Print.hpp"
#include <tbb/parallel_for.h> #include <tbb/parallel_for.h>

View File

@ -48,6 +48,7 @@
#include "AboutDialog.hpp" #include "AboutDialog.hpp"
#include "AppConfig.hpp" #include "AppConfig.hpp"
#include "ConfigSnapshotDialog.hpp" #include "ConfigSnapshotDialog.hpp"
#include "ProgressStatusBar.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "MsgDialog.hpp" #include "MsgDialog.hpp"
#include "ConfigWizard.hpp" #include "ConfigWizard.hpp"
@ -114,6 +115,7 @@ void break_to_debugger()
// Passing the wxWidgets GUI classes instantiated by the Perl part to C++. // Passing the wxWidgets GUI classes instantiated by the Perl part to C++.
wxApp *g_wxApp = nullptr; wxApp *g_wxApp = nullptr;
wxFrame *g_wxMainFrame = nullptr; wxFrame *g_wxMainFrame = nullptr;
ProgressStatusBar *g_progress_status_bar = nullptr;
wxNotebook *g_wxTabPanel = nullptr; wxNotebook *g_wxTabPanel = nullptr;
wxPanel *g_wxPlater = nullptr; wxPanel *g_wxPlater = nullptr;
AppConfig *g_AppConfig = nullptr; AppConfig *g_AppConfig = nullptr;
@ -207,6 +209,13 @@ void set_main_frame(wxFrame *main_frame)
wxFrame* get_main_frame() { return g_wxMainFrame; } 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) void set_tab_panel(wxNotebook *tab_panel)
{ {
g_wxTabPanel = tab_panel; g_wxTabPanel = tab_panel;

View File

@ -33,6 +33,7 @@ namespace Slic3r {
class PresetBundle; class PresetBundle;
class PresetCollection; class PresetCollection;
class Print; class Print;
class ProgressStatusBar;
class AppConfig; class AppConfig;
class PresetUpdater; class PresetUpdater;
class DynamicPrintConfig; class DynamicPrintConfig;
@ -99,6 +100,7 @@ void break_to_debugger();
// Passing the wxWidgets GUI classes instantiated by the Perl part to C++. // Passing the wxWidgets GUI classes instantiated by the Perl part to C++.
void set_wxapp(wxApp *app); void set_wxapp(wxApp *app);
void set_main_frame(wxFrame *main_frame); void set_main_frame(wxFrame *main_frame);
void set_progress_status_bar(ProgressStatusBar *prsb);
void set_tab_panel(wxNotebook *tab_panel); void set_tab_panel(wxNotebook *tab_panel);
void set_plater(wxPanel *plater); void set_plater(wxPanel *plater);
void set_app_config(AppConfig *app_config); void set_app_config(AppConfig *app_config);
@ -123,6 +125,7 @@ AppConfig* get_app_config();
wxApp* get_app(); wxApp* get_app();
PresetBundle* get_preset_bundle(); PresetBundle* get_preset_bundle();
wxFrame* get_main_frame(); wxFrame* get_main_frame();
ProgressStatusBar* get_progress_status_bar();
wxNotebook * get_tab_panel(); wxNotebook * get_tab_panel();
wxNotebook* get_tab_panel(); wxNotebook* get_tab_panel();

View File

@ -135,7 +135,7 @@ void ProgressStatusBar::embed(wxFrame *frame)
void ProgressStatusBar::set_status_text(const std::string& txt) void ProgressStatusBar::set_status_text(const std::string& txt)
{ {
self->SetStatusText(txt); self->SetStatusText(wxString::FromUTF8(txt.c_str()));
} }
void ProgressStatusBar::show_cancel_button() void ProgressStatusBar::show_cancel_button()

View File

@ -1,71 +0,0 @@
#ifndef IPROGRESSINDICATOR_HPP
#define IPROGRESSINDICATOR_HPP
#include <string>
#include <functional>
#include "Strings.hpp"
namespace Slic3r {
/**
* @brief Generic progress indication interface.
*/
class ProgressIndicator {
public:
using CancelFn = std::function<void(void)>; // 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

View File

@ -1,10 +0,0 @@
#ifndef STRINGS_HPP
#define STRINGS_HPP
#include "GUI/GUI.hpp"
namespace Slic3r {
using string = wxString;
}
#endif // STRINGS_HPP

View File

@ -35,6 +35,9 @@ bool is_windows10()
void set_wxapp(SV *ui) void set_wxapp(SV *ui)
%code%{ Slic3r::GUI::set_wxapp((wxApp*)wxPli_sv_2_object(aTHX_ ui, "Wx::App")); %}; %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) void set_main_frame(SV *ui)
%code%{ Slic3r::GUI::set_main_frame((wxFrame*)wxPli_sv_2_object(aTHX_ ui, "Wx::Frame")); %}; %code%{ Slic3r::GUI::set_main_frame((wxFrame*)wxPli_sv_2_object(aTHX_ ui, "Wx::Frame")); %};

View File

@ -36,7 +36,7 @@
void Embed() void Embed()
%code%{ THIS->embed(); %}; %code%{ THIS->embed(); %};
void SetStatusText(std::string txt) void SetStatusText(const char *txt)
%code%{ THIS->set_status_text(txt); %}; %code%{ THIS->set_status_text(txt); %};
void ShowCancelButton() void ShowCancelButton()