Localization for app controller.

This commit is contained in:
tamasmeszaros 2018-07-03 10:22:55 +02:00
parent ddb4945586
commit 27b0926c19
6 changed files with 134 additions and 111 deletions

View File

@ -262,6 +262,7 @@ add_library(libslic3r_gui STATIC
${LIBDIR}/slic3r/AppController.hpp
${LIBDIR}/slic3r/AppController.cpp
${LIBDIR}/slic3r/AppControllerWx.cpp
${LIBDIR}/slic3r/Strings.hpp
)
add_library(admesh STATIC

View File

@ -60,18 +60,23 @@ void AppControllerBoilerplate::progress_indicator(
progressind_->m.unlock();
}
AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::progress_indicator(
unsigned statenum,
const std::string &title,
const std::string &firstmsg)
void AppControllerBoilerplate::progress_indicator(unsigned statenum,
const string &title,
const string &firstmsg)
{
progressind_->m.lock();
auto ret = progressind_->store[std::this_thread::get_id()] =
create_progress_indicator(statenum, title, firstmsg);;
progressind_->store[std::this_thread::get_id()] =
create_progress_indicator(statenum, title, firstmsg);
progressind_->m.unlock();
}
return ret;
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();
}
AppControllerBoilerplate::ProgresIndicatorPtr
@ -177,8 +182,8 @@ void PrintController::slice(PrintObject *pobj)
if(pobj->layers.empty())
report_issue(IssueType::ERR,
"No layers were detected. You might want to repair your "
"STL file(s) or check their size or thickness and retry"
_(L("No layers were detected. You might want to repair your "
"STL file(s) or check their size or thickness and retry"))
);
pobj->state.set_done(STEP_SLICE);
@ -235,50 +240,51 @@ void PrintController::gen_support_material(PrintObject *pobj)
}
}
void PrintController::slice()
void PrintController::slice(AppControllerBoilerplate::ProgresIndicatorPtr pri)
{
auto st = pri->state();
Slic3r::trace(3, "Starting the slicing process.");
progress_indicator()->update(20u, "Generating perimeters");
pri->update(st+20, _(L("Generating perimeters")));
for(auto obj : print_->objects) make_perimeters(obj);
progress_indicator()->update(60u, "Infilling layers");
pri->update(st+60, _(L("Infilling layers")));
for(auto obj : print_->objects) infill(obj);
progress_indicator()->update(70u, "Generating support material");
pri->update(st+70, _(L("Generating support material")));
for(auto obj : print_->objects) gen_support_material(obj);
progress_indicator()->message_fmt("Weight: %.1fg, Cost: %.1f",
print_->total_weight,
print_->total_cost);
progress_indicator()->state(85u);
pri->message_fmt(_(L("Weight: %.1fg, Cost: %.1f")),
print_->total_weight, print_->total_cost);
pri->state(st+85);
progress_indicator()->update(88u, "Generating skirt");
pri->update(st+88, _(L("Generating skirt")));
make_skirt();
progress_indicator()->update(90u, "Generating brim");
pri->update(st+90, _(L("Generating brim")));
make_brim();
progress_indicator()->update(95u, "Generating wipe tower");
pri->update(st+95, _(L("Generating wipe tower")));
make_wipe_tower();
progress_indicator()->update(100u, "Done");
pri->update(st+100, _(L("Done")));
// time to make some statistics..
Slic3r::trace(3, "Slicing process finished.");
Slic3r::trace(3, _(L("Slicing process finished.")));
}
const PrintConfig &PrintController::config() const
void PrintController::slice()
{
return print_->config;
auto pri = progress_indicator();
slice(pri);
}
void IProgressIndicator::message_fmt(
const std::string &fmtstr, ...) {
const string &fmtstr, ...) {
std::stringstream ss;
va_list args;
va_start(args, fmtstr);
@ -304,6 +310,11 @@ void IProgressIndicator::message_fmt(
message(ss.str());
}
const PrintConfig &PrintController::config() const
{
return print_->config;
}
void AppController::arrange_model()
{
auto ftr = std::async(
@ -329,24 +340,24 @@ void AppController::arrange_model()
BoundingBoxf bb(print_ctl()->config().bed_shape.values);
if(pind) pind->update(0, "Arranging objects...");
if(pind) pind->update(0, _(L("Arranging objects...")));
try {
model_->arrange_objects(dist, &bb, [pind, count](unsigned rem){
if(pind) pind->update(count - rem, "Arranging objects...");
if(pind) pind->update(count - rem, _(L("Arranging objects...")));
});
} catch(std::exception& e) {
std::cerr << e.what() << std::endl;
report_issue(IssueType::ERR,
"Could not arrange model objects! "
"Some geometries may be invalid.",
"Exception occurred");
_(L("Could not arrange model objects! "
"Some geometries may be invalid.")),
_(L("Exception occurred")));
}
// Restore previous max value
if(pind) {
pind->max(pmax);
pind->update(0, "Arranging done.");
pind->update(0, _(L("Arranging done.")));
}
});

View File

@ -16,6 +16,7 @@ class Print;
class PrintObject;
class PrintConfig;
/**
* @brief A boilerplate class for creating application logic. It should provide
* features as issue reporting and progress indication, etc...
@ -45,7 +46,7 @@ public:
AppControllerBoilerplate();
~AppControllerBoilerplate();
using Path = std::string;
using Path = string;
using PathList = std::vector<Path>;
/// Common runtime issue types
@ -66,20 +67,20 @@ public:
* @return Returns a list of paths choosed by the user.
*/
PathList query_destination_paths(
const std::string& title,
const string& title,
const std::string& extensions) const;
/**
* @brief Same as query_destination_paths but works for directories only.
*/
PathList query_destination_dirs(
const std::string& title) const;
const string& title) const;
/**
* @brief Same as query_destination_paths but returns only one path.
*/
Path query_destination_path(
const std::string& title,
const string& title,
const std::string& extensions,
const std::string& hint = "") const;
@ -94,8 +95,11 @@ public:
* title.
*/
bool report_issue(IssueType issuetype,
const std::string& description,
const std::string& brief = "");
const string& description,
const string& brief);
bool report_issue(IssueType issuetype,
const string& description);
/**
* @brief Set up a progress indicator for the current thread.
@ -109,9 +113,12 @@ public:
* @param title The title of the procedure.
* @param firstmsg The message for the first subtask to be displayed.
*/
ProgresIndicatorPtr progress_indicator(unsigned statenum,
const std::string& title,
const std::string& firstmsg = "");
void progress_indicator(unsigned statenum,
const string& title,
const string& firstmsg);
void progress_indicator(unsigned statenum,
const string& title);
/**
* @brief Return the progress indicator set up for the current thread. This
@ -161,8 +168,12 @@ protected:
*/
ProgresIndicatorPtr create_progress_indicator(
unsigned statenum,
const std::string& title,
const std::string& firstmsg = "") const;
const string& title,
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
// contain the progress indicator on the statusbar.
@ -184,6 +195,14 @@ protected:
void infill(PrintObject *pobj);
void gen_support_material(PrintObject *pobj);
/**
* @brief Slice one pront object.
* @param pobj The print object.
*/
void slice(PrintObject *pobj);
void slice(ProgresIndicatorPtr pri);
public:
// Must be public for perl to use it
@ -198,12 +217,6 @@ public:
return PrintController::Ptr( new PrintController(print) );
}
/**
* @brief Slice one pront object.
* @param pobj The print object.
*/
void slice(PrintObject *pobj);
/**
* @brief Slice the loaded print scene.
*/

View File

@ -32,11 +32,11 @@ void AppControllerBoilerplate::process_events()
AppControllerBoilerplate::PathList
AppControllerBoilerplate::query_destination_paths(
const std::string &title,
const string &title,
const std::string &extensions) const
{
wxFileDialog dlg(wxTheApp->GetTopWindow(), wxString(title) );
wxFileDialog dlg(wxTheApp->GetTopWindow(), title );
dlg.SetWildcard(extensions);
dlg.ShowModal();
@ -52,7 +52,7 @@ AppControllerBoilerplate::query_destination_paths(
AppControllerBoilerplate::Path
AppControllerBoilerplate::query_destination_path(
const std::string &title,
const string &title,
const std::string &extensions,
const std::string& hint) const
{
@ -71,8 +71,8 @@ AppControllerBoilerplate::query_destination_path(
}
bool AppControllerBoilerplate::report_issue(IssueType issuetype,
const std::string &description,
const std::string &brief)
const string &description,
const string &brief)
{
auto icon = wxICON_INFORMATION;
auto style = wxOK|wxCENTRE;
@ -84,10 +84,17 @@ bool AppControllerBoilerplate::report_issue(IssueType issuetype,
case IssueType::FATAL: icon = wxICON_ERROR;
}
auto ret = wxMessageBox(_(description), _(brief), icon | style);
auto ret = wxMessageBox(description, brief, icon | style);
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);
namespace {
@ -99,11 +106,10 @@ namespace {
class GuiProgressIndicator:
public IProgressIndicator, public wxEvtHandler {
std::shared_ptr<wxProgressDialog> gauge_;
wxProgressDialog gauge_;
using Base = IProgressIndicator;
wxString message_;
int range_; wxString title_;
unsigned prc_ = 0;
bool is_asynch_ = false;
const int id_ = wxWindow::NewControlId();
@ -111,29 +117,15 @@ class GuiProgressIndicator:
// status update handler
void _state( wxCommandEvent& evt) {
unsigned st = evt.GetInt();
message_ = evt.GetString();
_state(st);
}
// Status update implementation
void _state( unsigned st) {
if(st < max()) {
if(!gauge_) gauge_ = std::make_shared<wxProgressDialog>(
title_, message_, range_, wxTheApp->GetTopWindow(),
wxPD_APP_MODAL | wxPD_AUTO_HIDE
);
if(!gauge_->IsShown()) gauge_->ShowModal();
Base::state(st);
gauge_->Update(static_cast<int>(st), message_);
}
if(st == max()) {
prc_++;
if(prc_ == Base::procedure_count()) {
gauge_.reset();
prc_ = 0;
}
}
if(!gauge_.IsShown()) gauge_.ShowModal();
Base::state(st);
gauge_.Update(static_cast<int>(st), message_);
}
public:
@ -144,9 +136,12 @@ public:
/// Get the mode of parallel operation.
inline bool asynch() const { return is_asynch_; }
inline GuiProgressIndicator(int range, const std::string& title,
const std::string& firstmsg) :
range_(range), message_(_(firstmsg)), title_(_(title))
inline GuiProgressIndicator(int range, const string& title,
const string& firstmsg) :
gauge_(title, firstmsg, range, wxTheApp->GetTopWindow(),
wxPD_APP_MODAL | wxPD_AUTO_HIDE),
message_(firstmsg),
range_(range), title_(title)
{
Base::max(static_cast<float>(range));
Base::states(static_cast<unsigned>(range));
@ -162,7 +157,7 @@ public:
}
virtual void state(float val) override {
if( val >= 1.0) state(static_cast<unsigned>(val));
state(static_cast<unsigned>(val));
}
void state(unsigned st) {
@ -170,31 +165,31 @@ public:
if(is_asynch_) {
auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT, id_);
evt->SetInt(st);
evt->SetString(message_);
wxQueueEvent(this, evt);
} else _state(st);
}
virtual void message(const std::string & msg) override {
message_ = _(msg);
virtual void message(const string & msg) override {
message_ = msg;
}
virtual void messageFmt(const std::string& fmt, ...) {
virtual void messageFmt(const string& fmt, ...) {
va_list arglist;
va_start(arglist, fmt);
message_ = wxString::Format(_(fmt), arglist);
message_ = wxString::Format(wxString(fmt), arglist);
va_end(arglist);
}
virtual void title(const std::string & title) override {
title_ = _(title);
virtual void title(const string & title) override {
title_ = title;
}
};
}
AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator(
unsigned statenum, const std::string& title,
const std::string& firstmsg) const
unsigned statenum, const string& title, const string& firstmsg) const
{
auto pri =
std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg);
@ -206,6 +201,13 @@ AppControllerBoilerplate::create_progress_indicator(
return pri;
}
AppControllerBoilerplate::ProgresIndicatorPtr
AppControllerBoilerplate::create_progress_indicator(unsigned statenum,
const string &title) const
{
return create_progress_indicator(statenum, title, string());
}
namespace {
// A wrapper progress indicator class around the statusbar created in perl.
@ -278,18 +280,18 @@ public:
}
}
virtual void message(const std::string & msg) override {
virtual void message(const string & msg) override {
message_ = msg;
}
virtual void message_fmt(const std::string& fmt, ...) override {
virtual void message_fmt(const string& fmt, ...) override {
va_list arglist;
va_start(arglist, fmt);
message_ = wxString::Format(_(fmt), arglist);
message_ = wxString::Format(fmt, arglist);
va_end(arglist);
}
virtual void title(const std::string & /*title*/) override {}
virtual void title(const string & /*title*/) override {}
};
}
@ -305,5 +307,4 @@ void AppController::set_global_progress_indicator(
global_progressind_ = std::make_shared<Wrapper>(gauge, sb, *this);
}
}
}

View File

@ -3,6 +3,7 @@
#include <string>
#include <functional>
#include "Strings.hpp"
namespace Slic3r {
@ -16,7 +17,6 @@ public:
private:
float state_ = .0f, max_ = 1.f, step_;
CancelFn cancelfunc_ = [](){};
unsigned proc_count_ = 1;
public:
@ -43,13 +43,13 @@ public:
}
/// Message shown on the next status update.
virtual void message(const std::string&) = 0;
virtual void message(const string&) = 0;
/// 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.
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.
inline void on_cancel(CancelFn func) { cancelfunc_ = func; }
@ -60,21 +60,8 @@ public:
*/
virtual void cancel() { cancelfunc_(); }
/**
* \brief Set up how many subprocedures does the whole operation contain.
*
* This was neccesary from practical reasons. If the progress indicator is
* a dialog and we want to show the progress of a few sub operations than
* the dialog wont be closed and reopened each time a new sub operation is
* started. This is not a mandatory feature and can be ignored completely.
*/
inline void procedure_count(unsigned pc) { proc_count_ = pc; }
/// Get the current procedure count
inline unsigned procedure_count() const { return proc_count_; }
/// 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);
}
};

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