Proper localization of AppController

This commit is contained in:
tamasmeszaros 2018-07-02 16:15:21 +02:00
parent 4f27f6c6dc
commit 478dd2a93f
6 changed files with 140 additions and 115 deletions

View File

@ -270,6 +270,7 @@ add_library(libslic3r_gui STATIC
${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

@ -61,12 +61,21 @@ void AppControllerBoilerplate::progress_indicator(
} }
void AppControllerBoilerplate::progress_indicator(unsigned statenum, void AppControllerBoilerplate::progress_indicator(unsigned statenum,
const std::string &title, const string &title,
const std::string &firstmsg) const string &firstmsg)
{ {
progressind_->m.lock(); progressind_->m.lock();
progressind_->store[std::this_thread::get_id()] = progressind_->store[std::this_thread::get_id()] =
create_progress_indicator(statenum, title, firstmsg);; create_progress_indicator(statenum, title, firstmsg);
progressind_->m.unlock();
}
void AppControllerBoilerplate::progress_indicator(unsigned statenum,
const string &title)
{
progressind_->m.lock();
progressind_->store[std::this_thread::get_id()] =
create_progress_indicator(statenum, title);
progressind_->m.unlock(); progressind_->m.unlock();
} }
@ -173,8 +182,8 @@ void PrintController::slice(PrintObject *pobj)
if(pobj->layers.empty()) if(pobj->layers.empty())
report_issue(IssueType::ERR, report_issue(IssueType::ERR,
"No layers were detected. You might want to repair your " _(L("No layers were detected. You might want to repair your "
"STL file(s) or check their size or thickness and retry" "STL file(s) or check their size or thickness and retry"))
); );
pobj->state.set_done(STEP_SLICE); pobj->state.set_done(STEP_SLICE);
@ -237,37 +246,35 @@ void PrintController::slice(AppControllerBoilerplate::ProgresIndicatorPtr pri)
Slic3r::trace(3, "Starting the slicing process."); Slic3r::trace(3, "Starting the slicing process.");
pri->update(st+20, "Generating perimeters"); pri->update(st+20, _(L("Generating perimeters")));
for(auto obj : print_->objects) make_perimeters(obj); for(auto obj : print_->objects) make_perimeters(obj);
pri->update(st+60, "Infilling layers"); pri->update(st+60, _(L("Infilling layers")));
for(auto obj : print_->objects) infill(obj); for(auto obj : print_->objects) infill(obj);
pri->update(st+70, "Generating support material"); pri->update(st+70, _(L("Generating support material")));
for(auto obj : print_->objects) gen_support_material(obj); for(auto obj : print_->objects) gen_support_material(obj);
pri->message_fmt("Weight: %.1fg, Cost: %.1f", pri->message_fmt(_(L("Weight: %.1fg, Cost: %.1f")),
print_->total_weight, print_->total_weight, print_->total_cost);
print_->total_cost);
pri->state(st+85); pri->state(st+85);
pri->update(st+88, "Generating skirt"); pri->update(st+88, _(L("Generating skirt")));
make_skirt(); make_skirt();
pri->update(st+90, "Generating brim"); pri->update(st+90, _(L("Generating brim")));
make_brim(); make_brim();
pri->update(st+95, "Generating wipe tower"); pri->update(st+95, _(L("Generating wipe tower")));
make_wipe_tower(); make_wipe_tower();
pri->update(st+100, "Done"); pri->update(st+100, _(L("Done")));
// time to make some statistics.. // time to make some statistics..
Slic3r::trace(3, "Slicing process finished."); Slic3r::trace(3, _(L("Slicing process finished.")));
} }
@ -322,60 +329,57 @@ void PrintController::slice_to_png()
unscale(print_bb.size().y) > exd.height_mm) { unscale(print_bb.size().y) > exd.height_mm) {
std::stringstream ss; std::stringstream ss;
ss << _("Print will not fit and will be truncated!") << "\n" ss << _(L("Print will not fit and will be truncated!")) << "\n"
<< _("Width needed: ") << unscale(print_bb.size().x) << " mm\n" << _(L("Width needed: ")) << unscale(print_bb.size().x) << " mm\n"
<< _("Height needed: ") << unscale(print_bb.size().y) << " mm\n"; << _(L("Height needed: ")) << unscale(print_bb.size().y) << " mm\n";
report_issue(IssueType::WARN, ss.str(), "Warning"); report_issue(IssueType::WARN, ss.str(), "Warning");
} }
// std::async(supports_asynch()? std::launch::async : std::launch::deferred, auto pri = create_progress_indicator(
// [this, exd, correction]() 200, _(L("Slicing to zipped png files...")));
// {
auto pri = create_progress_indicator(200, "Slicing to zipped png files...");
try { try {
pri->update(0, "Slicing..."); pri->update(0, _(L("Slicing...")));
slice(pri); slice(pri);
} catch (std::exception& e) { } catch (std::exception& e) {
report_issue(IssueType::ERR, e.what(), "Exception"); report_issue(IssueType::ERR, e.what(), _(L("Exception occured")));
pri->cancel(); pri->cancel();
return; return;
}
auto pbak = print_->progressindicator;
print_->progressindicator = pri;
try {
print_to<FilePrinterFormat::PNG>( *print_, exd.zippath,
exd.width_mm, exd.height_mm,
exd.width_px, exd.height_px,
exd.exp_time_s, exd.exp_time_first_s);
} catch (std::exception& e) {
report_issue(IssueType::ERR, e.what(), _(L("Exception occured")));
pri->cancel();
}
if(correction) { // scale the model back
print_->invalidate_all_steps();
for(auto po : print_->objects) {
po->model_object()->scale(
Pointf3(1.0/exd.corr_x, 1.0/exd.corr_y, 1.0/exd.corr_z)
);
po->model_object()->invalidate_bounding_box();
po->reload_model_instances();
po->invalidate_all_steps();
} }
}
auto pbak = print_->progressindicator; print_->progressindicator = pbak;
print_->progressindicator = pri;
try {
print_to<FilePrinterFormat::PNG>( *print_, exd.zippath,
exd.width_mm, exd.height_mm,
exd.width_px, exd.height_px,
exd.exp_time_s, exd.exp_time_first_s);
} catch (std::exception& e) {
report_issue(IssueType::ERR, e.what(), "Exception");
pri->cancel();
}
if(correction) { // scale the model back
print_->invalidate_all_steps();
for(auto po : print_->objects) {
po->model_object()->scale(
Pointf3(1.0/exd.corr_x, 1.0/exd.corr_y, 1.0/exd.corr_z)
);
po->model_object()->invalidate_bounding_box();
po->reload_model_instances();
po->invalidate_all_steps();
}
}
print_->progressindicator = pbak;
// });
} }
void IProgressIndicator::message_fmt( void IProgressIndicator::message_fmt(
const std::string &fmtstr, ...) { const string &fmtstr, ...) {
std::stringstream ss; std::stringstream ss;
va_list args; va_list args;
va_start(args, fmtstr); va_start(args, fmtstr);

View File

@ -44,7 +44,7 @@ public:
AppControllerBoilerplate(); AppControllerBoilerplate();
~AppControllerBoilerplate(); ~AppControllerBoilerplate();
using Path = std::string; using Path = string;
using PathList = std::vector<Path>; using PathList = std::vector<Path>;
/// Common runtime issue types /// Common runtime issue types
@ -65,20 +65,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 std::string& title, const string& 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 std::string& title) const; const string& 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 std::string& title, const string& title,
const std::string& extensions, const std::string& extensions,
const std::string& hint = "") const; const std::string& hint = "") const;
@ -93,8 +93,11 @@ public:
* title. * title.
*/ */
bool report_issue(IssueType issuetype, bool report_issue(IssueType issuetype,
const std::string& description, const string& description,
const std::string& brief = ""); const string& brief);
bool report_issue(IssueType issuetype,
const string& description);
/** /**
* @brief Set up a progress indicator for the current thread. * @brief Set up a progress indicator for the current thread.
@ -109,8 +112,11 @@ public:
* @param firstmsg The message for the first subtask to be displayed. * @param firstmsg The message for the first subtask to be displayed.
*/ */
void progress_indicator(unsigned statenum, void progress_indicator(unsigned statenum,
const std::string& title, const string& title,
const std::string& firstmsg = ""); const string& firstmsg);
void progress_indicator(unsigned statenum,
const string& title);
/** /**
* @brief Return the progress indicator set up for the current thread. This * @brief Return the progress indicator set up for the current thread. This
@ -160,8 +166,12 @@ protected:
*/ */
ProgresIndicatorPtr create_progress_indicator( ProgresIndicatorPtr create_progress_indicator(
unsigned statenum, unsigned statenum,
const std::string& title, const string& title,
const std::string& firstmsg = "") const; const string& firstmsg) const;
ProgresIndicatorPtr create_progress_indicator(
unsigned statenum,
const string& 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.
@ -234,8 +244,6 @@ public:
*/ */
void slice_to_png(); void slice_to_png();
void slice_to_png(std::string dirpath);
}; };
/** /**

View File

@ -33,11 +33,11 @@ void AppControllerBoilerplate::process_events()
AppControllerBoilerplate::PathList AppControllerBoilerplate::PathList
AppControllerBoilerplate::query_destination_paths( AppControllerBoilerplate::query_destination_paths(
const std::string &title, const string &title,
const std::string &extensions) const const std::string &extensions) const
{ {
wxFileDialog dlg(wxTheApp->GetTopWindow(), wxString(title) ); wxFileDialog dlg(wxTheApp->GetTopWindow(), title );
dlg.SetWildcard(extensions); dlg.SetWildcard(extensions);
dlg.ShowModal(); dlg.ShowModal();
@ -53,7 +53,7 @@ AppControllerBoilerplate::query_destination_paths(
AppControllerBoilerplate::Path AppControllerBoilerplate::Path
AppControllerBoilerplate::query_destination_path( AppControllerBoilerplate::query_destination_path(
const std::string &title, const string &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 std::string &description, const string &description,
const std::string &brief) const string &brief)
{ {
auto icon = wxICON_INFORMATION; auto icon = wxICON_INFORMATION;
auto style = wxOK|wxCENTRE; auto style = wxOK|wxCENTRE;
@ -89,6 +89,13 @@ bool AppControllerBoilerplate::report_issue(IssueType issuetype,
return ret != wxCANCEL; return ret != wxCANCEL;
} }
bool AppControllerBoilerplate::report_issue(
AppControllerBoilerplate::IssueType issuetype,
const string &description)
{
return report_issue(issuetype, description, string());
}
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent); wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
namespace { namespace {
@ -104,7 +111,6 @@ class GuiProgressIndicator:
using Base = IProgressIndicator; using Base = IProgressIndicator;
wxString message_; wxString message_;
int range_; wxString title_; int range_; wxString title_;
// unsigned prc_ = 0;
bool is_asynch_ = false; bool is_asynch_ = false;
const int id_ = wxWindow::NewControlId(); const int id_ = wxWindow::NewControlId();
@ -118,20 +124,9 @@ class GuiProgressIndicator:
// Status update implementation // Status update implementation
void _state( unsigned st) { void _state( unsigned st) {
// if(st < max()) { if(!gauge_.IsShown()) gauge_.ShowModal();
if(!gauge_.IsShown()) gauge_.ShowModal(); Base::state(st);
Base::state(st); gauge_.Update(static_cast<int>(st), message_);
gauge_.Update(static_cast<int>(st), message_);
// }
// if(st == max()) {
// prc_++;
// if(prc_ == Base::procedure_count()) {
// //gauge_.reset();
// gauge_.Update(static_cast<int>(st), message_);
// prc_ = 0;
// }
// }
} }
public: public:
@ -142,12 +137,12 @@ 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 std::string& title, inline GuiProgressIndicator(int range, const string& title,
const std::string& firstmsg) : const string& 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),
range_(range), title_(_(title)) range_(range), title_(title)
{ {
Base::max(static_cast<float>(range)); Base::max(static_cast<float>(range));
Base::states(static_cast<unsigned>(range)); Base::states(static_cast<unsigned>(range));
@ -163,7 +158,7 @@ public:
} }
virtual void state(float val) override { virtual void state(float val) override {
/*if( val >= 1.0) */state(static_cast<unsigned>(val)); state(static_cast<unsigned>(val));
} }
void state(unsigned st) { void state(unsigned st) {
@ -176,27 +171,26 @@ public:
} else _state(st); } else _state(st);
} }
virtual void message(const std::string & msg) override { virtual void message(const string & msg) override {
message_ = _(msg); message_ = msg;
} }
virtual void messageFmt(const std::string& fmt, ...) { virtual void messageFmt(const string& fmt, ...) {
va_list arglist; va_list arglist;
va_start(arglist, fmt); va_start(arglist, fmt);
message_ = wxString::Format(_(fmt), arglist); message_ = wxString::Format(wxString(fmt), arglist);
va_end(arglist); va_end(arglist);
} }
virtual void title(const std::string & title) override { virtual void title(const string & title) override {
title_ = _(title); title_ = title;
} }
}; };
} }
AppControllerBoilerplate::ProgresIndicatorPtr AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator( AppControllerBoilerplate::create_progress_indicator(
unsigned statenum, const std::string& title, unsigned statenum, const string& title, const string& firstmsg) const
const std::string& firstmsg) const
{ {
auto pri = auto pri =
std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg); std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg);
@ -208,6 +202,13 @@ AppControllerBoilerplate::create_progress_indicator(
return pri; return pri;
} }
AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator(unsigned statenum,
const string &title) const
{
return create_progress_indicator(statenum, title, string());
}
namespace { namespace {
// A wrapper progress indicator class around the statusbar created in perl. // A wrapper progress indicator class around the statusbar created in perl.
@ -271,18 +272,18 @@ public:
} else _state(st); } else _state(st);
} }
virtual void message(const std::string & msg) override { virtual void message(const string & msg) override {
message_ = msg; message_ = msg;
} }
virtual void message_fmt(const std::string& fmt, ...) override { virtual void message_fmt(const string& fmt, ...) override {
va_list arglist; va_list arglist;
va_start(arglist, fmt); va_start(arglist, fmt);
message_ = wxString::Format(_(fmt), arglist); message_ = wxString::Format(wxString(fmt), arglist);
va_end(arglist); va_end(arglist);
} }
virtual void title(const std::string & /*title*/) override {} virtual void title(const string & /*title*/) override {}
}; };
} }
@ -396,8 +397,8 @@ PrintController::PngExportData PrintController::query_png_export_data()
if(wxFileName(filepick_ctl_->GetPath()).Exists()) if(wxFileName(filepick_ctl_->GetPath()).Exists())
if(!ctl_.report_issue(PrintController::IssueType::WARN_Q, if(!ctl_.report_issue(PrintController::IssueType::WARN_Q,
"File already exists. Overwrite?", _(L("File already exists. Overwrite?")),
"Warning")) ret = wxID_CANCEL; _(L("Warning")))) ret = wxID_CANCEL;
EndModal(ret); EndModal(ret);
} }
}; };

View File

@ -3,6 +3,7 @@
#include <string> #include <string>
#include <functional> #include <functional>
#include "Strings.hpp"
namespace Slic3r { namespace Slic3r {
@ -42,13 +43,13 @@ public:
} }
/// Message shown on the next status update. /// Message shown on the next status update.
virtual void message(const std::string&) = 0; virtual void message(const string&) = 0;
/// Title of the operaton. /// Title of the operaton.
virtual void title(const std::string&) = 0; virtual void title(const string&) = 0;
/// Formatted message for the next status update. Works just like sprinf. /// Formatted message for the next status update. Works just like sprinf.
virtual void message_fmt(const std::string& fmt, ...); virtual void message_fmt(const string& fmt, ...);
/// Set up a cancel callback for the operation if feasible. /// Set up a cancel callback for the operation if feasible.
inline void on_cancel(CancelFn func) { cancelfunc_ = func; } inline void on_cancel(CancelFn func) { cancelfunc_ = func; }
@ -60,7 +61,7 @@ public:
virtual void cancel() { cancelfunc_(); } virtual void cancel() { cancelfunc_(); }
/// Convinience function to call message and status update in one function. /// Convinience function to call message and status update in one function.
void update(float st, const std::string& msg) { void update(float st, const string& msg) {
message(msg); state(st); message(msg); state(st);
} }
}; };

10
xs/src/slic3r/Strings.hpp Normal file
View File

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