Separating wx and the app controller.
This commit is contained in:
parent
8dcf789d4b
commit
6737506b14
@ -247,6 +247,7 @@ add_library(libslic3r_gui STATIC
|
||||
${LIBDIR}/slic3r/Utils/Time.hpp
|
||||
${LIBDIR}/slic3r/AppController.hpp
|
||||
${LIBDIR}/slic3r/AppController.cpp
|
||||
${LIBDIR}/slic3r/AppControllerWx.cpp
|
||||
)
|
||||
|
||||
add_library(admesh STATIC
|
||||
|
@ -5,24 +5,20 @@
|
||||
#include <sstream>
|
||||
#include <cstdarg>
|
||||
|
||||
#include <slic3r/GUI/GUI.hpp>
|
||||
//#include <slic3r/GUI/GUI.hpp>
|
||||
#include <slic3r/GUI/PresetBundle.hpp>
|
||||
#include <slic3r/GUI/MsgDialog.hpp>
|
||||
|
||||
#include <PrintConfig.hpp>
|
||||
#include <Print.hpp>
|
||||
#include <Model.hpp>
|
||||
#include <Utils.hpp>
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/progdlg.h>
|
||||
#include <wx/gauge.h>
|
||||
#include <wx/statusbr.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace GUI {
|
||||
PresetBundle* get_preset_bundle();
|
||||
}
|
||||
|
||||
static const PrintObjectStep STEP_SLICE = posSlice;
|
||||
static const PrintObjectStep STEP_PERIMETERS = posPerimeters;
|
||||
static const PrintObjectStep STEP_PREPARE_INFILL = posPrepareInfill;
|
||||
@ -32,114 +28,6 @@ static const PrintStep STEP_SKIRT = psSkirt;
|
||||
static const PrintStep STEP_BRIM = psBrim;
|
||||
static const PrintStep STEP_WIPE_TOWER = psWipeTower;
|
||||
|
||||
AppControllerBoilerplate::PathList
|
||||
AppControllerBoilerplate::query_destination_paths(
|
||||
const std::string &title,
|
||||
const std::string &extensions) const
|
||||
{
|
||||
|
||||
wxFileDialog dlg(wxTheApp->GetTopWindow(), wxString(title) );
|
||||
dlg.SetWildcard(extensions);
|
||||
|
||||
dlg.ShowModal();
|
||||
|
||||
wxArrayString paths;
|
||||
dlg.GetFilenames(paths);
|
||||
|
||||
PathList ret(paths.size(), "");
|
||||
for(auto& p : paths) ret.push_back(p.ToStdString());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AppControllerBoilerplate::Path
|
||||
AppControllerBoilerplate::query_destination_path(
|
||||
const std::string &title,
|
||||
const std::string &extensions) const
|
||||
{
|
||||
wxFileDialog dlg(wxTheApp->GetTopWindow(), title );
|
||||
dlg.SetWildcard(extensions);
|
||||
|
||||
dlg.ShowModal();
|
||||
|
||||
Path ret(dlg.GetFilename());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AppControllerBoilerplate::report_issue(IssueType issuetype,
|
||||
const std::string &description,
|
||||
const std::string &brief)
|
||||
{
|
||||
auto icon = wxICON_INFORMATION;
|
||||
switch(issuetype) {
|
||||
case IssueType::INFO: break;
|
||||
case IssueType::WARN: icon = wxICON_WARNING; break;
|
||||
case IssueType::ERR:
|
||||
case IssueType::FATAL: icon = wxICON_ERROR;
|
||||
}
|
||||
|
||||
wxString str = _("Proba szoveg");
|
||||
wxMessageBox(str + _(description), _(brief), icon);
|
||||
}
|
||||
|
||||
AppControllerBoilerplate::ProgresIndicatorPtr
|
||||
AppControllerBoilerplate::createProgressIndicator(unsigned statenum,
|
||||
const std::string& title,
|
||||
const std::string& firstmsg) const
|
||||
{
|
||||
class GuiProgressIndicator: public ProgressIndicator {
|
||||
wxProgressDialog gauge_;
|
||||
using Base = ProgressIndicator;
|
||||
wxString message_;
|
||||
public:
|
||||
|
||||
inline GuiProgressIndicator(int range, const std::string& title,
|
||||
const std::string& firstmsg):
|
||||
gauge_(_(title), _(firstmsg), range, wxTheApp->GetTopWindow())
|
||||
{
|
||||
gauge_.Show(false);
|
||||
Base::max(static_cast<float>(range));
|
||||
Base::states(static_cast<unsigned>(range));
|
||||
}
|
||||
|
||||
virtual void state(float val) override {
|
||||
if( val <= max() && val >= 1.0) {
|
||||
Base::state(val);
|
||||
gauge_.Update(static_cast<int>(val), message_);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void state(unsigned st) override {
|
||||
if( st <= max() ) {
|
||||
if(!gauge_.IsShown()) gauge_.ShowModal();
|
||||
Base::state(st);
|
||||
gauge_.Update(static_cast<int>(st), message_);
|
||||
}
|
||||
}
|
||||
|
||||
virtual void message(const std::string & msg) override {
|
||||
message_ = _(msg);
|
||||
}
|
||||
|
||||
virtual void messageFmt(const std::string& fmt, ...) {
|
||||
va_list arglist;
|
||||
va_start(arglist, fmt);
|
||||
message_ = wxString::Format(_(fmt), arglist);
|
||||
va_end(arglist);
|
||||
}
|
||||
|
||||
virtual void title(const std::string & title) override {
|
||||
gauge_.SetTitle(_(title));
|
||||
}
|
||||
};
|
||||
|
||||
auto pri =
|
||||
std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg);
|
||||
|
||||
return pri;
|
||||
}
|
||||
|
||||
void PrintController::make_skirt()
|
||||
{
|
||||
assert(print_ != nullptr);
|
||||
@ -345,88 +233,15 @@ void PrintController::slice_to_png()
|
||||
|
||||
conf.validate();
|
||||
|
||||
auto bak = progressIndicator();
|
||||
// auto bak = progressIndicator();
|
||||
progressIndicator(100, "Slicing to zipped png files...");
|
||||
std::async(std::launch::async, [this, &bak](){
|
||||
// std::async(std::launch::async, [this, bak](){
|
||||
slice();
|
||||
progressIndicator(bak);
|
||||
});
|
||||
// progressIndicator(bak);
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
void AppController::set_global_progress_indicator_id(
|
||||
unsigned gid,
|
||||
unsigned sid)
|
||||
{
|
||||
|
||||
class Wrapper: public ProgressIndicator {
|
||||
wxGauge *gauge_;
|
||||
wxStatusBar *stbar_;
|
||||
using Base = ProgressIndicator;
|
||||
std::string message_;
|
||||
|
||||
void showProgress(bool show = true) {
|
||||
gauge_->Show(show);
|
||||
gauge_->Pulse();
|
||||
}
|
||||
public:
|
||||
|
||||
inline Wrapper(wxGauge *gauge, wxStatusBar *stbar):
|
||||
gauge_(gauge), stbar_(stbar)
|
||||
{
|
||||
Base::max(static_cast<float>(gauge->GetRange()));
|
||||
Base::states(static_cast<unsigned>(gauge->GetRange()));
|
||||
}
|
||||
|
||||
virtual void state(float val) override {
|
||||
if( val <= max() && val >= 1.0) {
|
||||
Base::state(val);
|
||||
stbar_->SetStatusText(message_);
|
||||
gauge_->SetValue(static_cast<int>(val));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void state(unsigned st) override {
|
||||
if( st <= max() ) {
|
||||
Base::state(st);
|
||||
|
||||
if(!gauge_->IsShown()) showProgress(true);
|
||||
|
||||
stbar_->SetStatusText(message_);
|
||||
if(st == gauge_->GetRange()) {
|
||||
gauge_->SetValue(0);
|
||||
showProgress(false);
|
||||
} else {
|
||||
gauge_->SetValue(static_cast<int>(st));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void message(const std::string & msg) override {
|
||||
message_ = msg;
|
||||
}
|
||||
|
||||
virtual void messageFmt(const std::string& fmt, ...) {
|
||||
va_list arglist;
|
||||
va_start(arglist, fmt);
|
||||
message_ = wxString::Format(_(fmt), arglist);
|
||||
va_end(arglist);
|
||||
}
|
||||
|
||||
virtual void title(const std::string & /*title*/) override {}
|
||||
|
||||
};
|
||||
|
||||
wxGauge* gauge = dynamic_cast<wxGauge*>(wxWindow::FindWindowById(gid));
|
||||
wxStatusBar* sb = dynamic_cast<wxStatusBar*>(wxWindow::FindWindowById(sid));
|
||||
|
||||
if(gauge && sb) {
|
||||
auto&& progind = std::make_shared<Wrapper>(gauge, sb);
|
||||
progressIndicator(progind);
|
||||
if(printctl) printctl->progressIndicator(progind);
|
||||
}
|
||||
}
|
||||
|
||||
void AppControllerBoilerplate::ProgressIndicator::messageFmt(
|
||||
const std::string &fmtstr, ...) {
|
||||
std::stringstream ss;
|
||||
|
@ -4,6 +4,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
@ -68,22 +71,25 @@ public:
|
||||
|
||||
using ProgresIndicatorPtr = std::shared_ptr<ProgressIndicator>;
|
||||
|
||||
|
||||
inline void progressIndicator(ProgresIndicatorPtr progrind) {
|
||||
progressind_ = progrind;
|
||||
progressind_[std::this_thread::get_id()] = progrind;
|
||||
}
|
||||
|
||||
inline void progressIndicator(unsigned statenum,
|
||||
const std::string& title,
|
||||
const std::string& firstmsg = "") {
|
||||
progressind_ = createProgressIndicator(statenum, title, firstmsg);
|
||||
progressind_[std::this_thread::get_id()] =
|
||||
createProgressIndicator(statenum, title, firstmsg);
|
||||
}
|
||||
|
||||
inline ProgresIndicatorPtr progressIndicator() {
|
||||
if(!progressind_)
|
||||
progressind_ = createProgressIndicator(100, "Progress");
|
||||
|
||||
return progressind_;
|
||||
ProgresIndicatorPtr ret;
|
||||
if( progressind_.find(std::this_thread::get_id()) == progressind_.end())
|
||||
progressind_[std::this_thread::get_id()] = ret =
|
||||
= createProgressIndicator(100, "Progress");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -94,7 +100,7 @@ protected:
|
||||
const std::string& firstmsg = "") const;
|
||||
|
||||
private:
|
||||
ProgresIndicatorPtr progressind_;
|
||||
std::unordered_map<std::thread::id, ProgresIndicatorPtr> progressind_;
|
||||
};
|
||||
|
||||
class PrintController: public AppControllerBoilerplate {
|
||||
@ -105,6 +111,10 @@ protected:
|
||||
void make_brim();
|
||||
void make_wipe_tower();
|
||||
|
||||
void make_perimeters(PrintObject *pobj);
|
||||
void infill(PrintObject *pobj);
|
||||
void gen_support_material(PrintObject *pobj);
|
||||
|
||||
public:
|
||||
|
||||
using Ptr = std::unique_ptr<PrintController>;
|
||||
@ -116,13 +126,9 @@ public:
|
||||
}
|
||||
|
||||
void slice(PrintObject *pobj);
|
||||
void make_perimeters(PrintObject *pobj);
|
||||
void infill(PrintObject *pobj);
|
||||
void gen_support_material(PrintObject *pobj);
|
||||
|
||||
void slice();
|
||||
void slice_to_png();
|
||||
|
||||
};
|
||||
|
||||
class AppController: protected AppControllerBoilerplate {
|
||||
|
220
xs/src/slic3r/appcontrollerwx.cpp
Normal file
220
xs/src/slic3r/appcontrollerwx.cpp
Normal file
@ -0,0 +1,220 @@
|
||||
#include "AppController.hpp"
|
||||
|
||||
|
||||
#include <slic3r/GUI/GUI.hpp>
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/filedlg.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/progdlg.h>
|
||||
#include <wx/gauge.h>
|
||||
#include <wx/statusbr.h>
|
||||
#include <wx/event.h>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
AppControllerBoilerplate::PathList
|
||||
AppControllerBoilerplate::query_destination_paths(
|
||||
const std::string &title,
|
||||
const std::string &extensions) const
|
||||
{
|
||||
|
||||
wxFileDialog dlg(wxTheApp->GetTopWindow(), wxString(title) );
|
||||
dlg.SetWildcard(extensions);
|
||||
|
||||
dlg.ShowModal();
|
||||
|
||||
wxArrayString paths;
|
||||
dlg.GetFilenames(paths);
|
||||
|
||||
PathList ret(paths.size(), "");
|
||||
for(auto& p : paths) ret.push_back(p.ToStdString());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
AppControllerBoilerplate::Path
|
||||
AppControllerBoilerplate::query_destination_path(
|
||||
const std::string &title,
|
||||
const std::string &extensions) const
|
||||
{
|
||||
wxFileDialog dlg(wxTheApp->GetTopWindow(), title );
|
||||
dlg.SetWildcard(extensions);
|
||||
|
||||
dlg.ShowModal();
|
||||
|
||||
Path ret(dlg.GetFilename());
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void AppControllerBoilerplate::report_issue(IssueType issuetype,
|
||||
const std::string &description,
|
||||
const std::string &brief)
|
||||
{
|
||||
auto icon = wxICON_INFORMATION;
|
||||
switch(issuetype) {
|
||||
case IssueType::INFO: break;
|
||||
case IssueType::WARN: icon = wxICON_WARNING; break;
|
||||
case IssueType::ERR:
|
||||
case IssueType::FATAL: icon = wxICON_ERROR;
|
||||
}
|
||||
|
||||
wxString str = _("Proba szoveg");
|
||||
wxMessageBox(str + _(description), _(brief), icon);
|
||||
}
|
||||
|
||||
wxDEFINE_EVENT(PROGRESS_STATUS_UPDATE_EVENT, wxCommandEvent);
|
||||
|
||||
AppControllerBoilerplate::ProgresIndicatorPtr
|
||||
AppControllerBoilerplate::createProgressIndicator(unsigned statenum,
|
||||
const std::string& title,
|
||||
const std::string& firstmsg) const
|
||||
{
|
||||
class GuiProgressIndicator:
|
||||
public ProgressIndicator, public wxEvtHandler {
|
||||
|
||||
std::shared_ptr<wxProgressDialog> gauge_;
|
||||
using Base = ProgressIndicator;
|
||||
wxString message_;
|
||||
int range_; wxString title_;
|
||||
|
||||
// status update handler
|
||||
void _state( wxCommandEvent& evt) {
|
||||
unsigned st = evt.GetInt();
|
||||
if( st < max() ) {
|
||||
|
||||
if(!gauge_) gauge_ = std::make_shared<wxProgressDialog>(
|
||||
title_, message_, range_, wxTheApp->GetTopWindow()
|
||||
);
|
||||
|
||||
if(!gauge_->IsShown()) gauge_->ShowModal();
|
||||
Base::state(st);
|
||||
gauge_->Update(static_cast<int>(st), message_);
|
||||
|
||||
} else {
|
||||
gauge_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
inline GuiProgressIndicator(int range, const std::string& title,
|
||||
const std::string& firstmsg) :
|
||||
range_(range), message_(_(firstmsg)), title_(_(title))
|
||||
{
|
||||
Base::max(static_cast<float>(range));
|
||||
Base::states(static_cast<unsigned>(range));
|
||||
|
||||
Bind(PROGRESS_STATUS_UPDATE_EVENT,
|
||||
&GuiProgressIndicator::_state,
|
||||
this);
|
||||
}
|
||||
|
||||
virtual void state(float val) override {
|
||||
if( val >= 1.0) state(static_cast<unsigned>(val));
|
||||
}
|
||||
|
||||
virtual void state(unsigned st) override {
|
||||
// send status update event
|
||||
auto evt = new wxCommandEvent(PROGRESS_STATUS_UPDATE_EVENT);
|
||||
evt->SetInt(st);
|
||||
wxQueueEvent(this, evt);
|
||||
}
|
||||
|
||||
virtual void message(const std::string & msg) override {
|
||||
message_ = _(msg);
|
||||
}
|
||||
|
||||
virtual void messageFmt(const std::string& fmt, ...) {
|
||||
va_list arglist;
|
||||
va_start(arglist, fmt);
|
||||
message_ = wxString::Format(_(fmt), arglist);
|
||||
va_end(arglist);
|
||||
}
|
||||
|
||||
virtual void title(const std::string & title) override {
|
||||
title_ = _(title);
|
||||
}
|
||||
};
|
||||
|
||||
auto pri =
|
||||
std::make_shared<GuiProgressIndicator>(statenum, title, firstmsg);
|
||||
|
||||
return pri;
|
||||
}
|
||||
|
||||
void AppController::set_global_progress_indicator_id(
|
||||
unsigned gid,
|
||||
unsigned sid)
|
||||
{
|
||||
|
||||
class Wrapper: public ProgressIndicator {
|
||||
wxGauge *gauge_;
|
||||
wxStatusBar *stbar_;
|
||||
using Base = ProgressIndicator;
|
||||
std::string message_;
|
||||
|
||||
void showProgress(bool show = true) {
|
||||
gauge_->Show(show);
|
||||
gauge_->Pulse();
|
||||
}
|
||||
public:
|
||||
|
||||
inline Wrapper(wxGauge *gauge, wxStatusBar *stbar):
|
||||
gauge_(gauge), stbar_(stbar)
|
||||
{
|
||||
Base::max(static_cast<float>(gauge->GetRange()));
|
||||
Base::states(static_cast<unsigned>(gauge->GetRange()));
|
||||
}
|
||||
|
||||
virtual void state(float val) override {
|
||||
if( val <= max() && val >= 1.0) {
|
||||
Base::state(val);
|
||||
stbar_->SetStatusText(message_);
|
||||
gauge_->SetValue(static_cast<int>(val));
|
||||
}
|
||||
}
|
||||
|
||||
virtual void state(unsigned st) override {
|
||||
if( st <= max() ) {
|
||||
Base::state(st);
|
||||
|
||||
if(!gauge_->IsShown()) showProgress(true);
|
||||
|
||||
stbar_->SetStatusText(message_);
|
||||
if(st == gauge_->GetRange()) {
|
||||
gauge_->SetValue(0);
|
||||
showProgress(false);
|
||||
} else {
|
||||
gauge_->SetValue(static_cast<int>(st));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void message(const std::string & msg) override {
|
||||
message_ = msg;
|
||||
}
|
||||
|
||||
virtual void messageFmt(const std::string& fmt, ...) {
|
||||
va_list arglist;
|
||||
va_start(arglist, fmt);
|
||||
message_ = wxString::Format(_(fmt), arglist);
|
||||
va_end(arglist);
|
||||
}
|
||||
|
||||
virtual void title(const std::string & /*title*/) override {}
|
||||
|
||||
};
|
||||
|
||||
wxGauge* gauge = dynamic_cast<wxGauge*>(wxWindow::FindWindowById(gid));
|
||||
wxStatusBar* sb = dynamic_cast<wxStatusBar*>(wxWindow::FindWindowById(sid));
|
||||
|
||||
if(gauge && sb) {
|
||||
auto&& progind = std::make_shared<Wrapper>(gauge, sb);
|
||||
progressIndicator(progind);
|
||||
if(printctl) printctl->progressIndicator(progind);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user