Slicing in C++ with progress indication.
This commit is contained in:
parent
5f310e1520
commit
8dcf789d4b
@ -71,6 +71,9 @@ sub new {
|
||||
$self->{statusbar}->GetId(),
|
||||
);
|
||||
|
||||
$appController->set_model($self->{plater}->{model});
|
||||
$appController->set_print($self->{plater}->{print});
|
||||
|
||||
$self->{loaded} = 1;
|
||||
|
||||
# initialize layout
|
||||
@ -124,8 +127,6 @@ sub _init_tabpanel {
|
||||
if (!$self->{no_controller}) {
|
||||
$panel->AddPage($self->{controller} = Slic3r::GUI::Controller->new($panel), L("Controller"));
|
||||
}
|
||||
$appController->set_model($self->{plater}->{model});
|
||||
$appController->set_print($self->{plater}->{print});
|
||||
}
|
||||
|
||||
#TODO this is an example of a Slic3r XS interface call to add a new preset editor page to the main view.
|
||||
@ -391,7 +392,8 @@ sub on_plater_selection_changed {
|
||||
|
||||
sub slice_to_png {
|
||||
my $self = shift;
|
||||
$appController->slice_to_png;
|
||||
$self->{plater}->async_apply_config;
|
||||
$appController->print_ctl()->slice_to_png();
|
||||
}
|
||||
|
||||
# To perform the "Quck Slice", "Quick Slice and Save As", "Repeat last Quick Slice" and "Slice to SVG".
|
||||
|
@ -66,6 +66,7 @@ REGISTER_CLASS(TabIface, "GUI::Tab");
|
||||
REGISTER_CLASS(PresetUpdater, "PresetUpdater");
|
||||
REGISTER_CLASS(OctoPrint, "OctoPrint");
|
||||
REGISTER_CLASS(AppController, "AppController");
|
||||
REGISTER_CLASS(PrintController, "PrintController");
|
||||
|
||||
SV* ConfigBase__as_hash(ConfigBase* THIS)
|
||||
{
|
||||
|
@ -1,5 +1,10 @@
|
||||
#include "AppController.hpp"
|
||||
|
||||
#include <future>
|
||||
#include <thread>
|
||||
#include <sstream>
|
||||
#include <cstdarg>
|
||||
|
||||
#include <slic3r/GUI/GUI.hpp>
|
||||
#include <slic3r/GUI/PresetBundle.hpp>
|
||||
#include <slic3r/GUI/MsgDialog.hpp>
|
||||
@ -18,6 +23,15 @@
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
static const PrintObjectStep STEP_SLICE = posSlice;
|
||||
static const PrintObjectStep STEP_PERIMETERS = posPerimeters;
|
||||
static const PrintObjectStep STEP_PREPARE_INFILL = posPrepareInfill;
|
||||
static const PrintObjectStep STEP_INFILL = posInfill;
|
||||
static const PrintObjectStep STEP_SUPPORTMATERIAL = posSupportMaterial;
|
||||
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,
|
||||
@ -65,7 +79,8 @@ void AppControllerBoilerplate::report_issue(IssueType issuetype,
|
||||
case IssueType::FATAL: icon = wxICON_ERROR;
|
||||
}
|
||||
|
||||
wxMessageBox(_(description), _(brief), icon);
|
||||
wxString str = _("Proba szoveg");
|
||||
wxMessageBox(str + _(description), _(brief), icon);
|
||||
}
|
||||
|
||||
AppControllerBoilerplate::ProgresIndicatorPtr
|
||||
@ -76,13 +91,14 @@ AppControllerBoilerplate::createProgressIndicator(unsigned statenum,
|
||||
class GuiProgressIndicator: public ProgressIndicator {
|
||||
wxProgressDialog gauge_;
|
||||
using Base = ProgressIndicator;
|
||||
std::string message_;
|
||||
wxString message_;
|
||||
public:
|
||||
|
||||
inline GuiProgressIndicator(int range, const std::string& title,
|
||||
const std::string& firstmsg):
|
||||
gauge_(title, firstmsg, range, wxTheApp->GetTopWindow())
|
||||
gauge_(_(title), _(firstmsg), range, wxTheApp->GetTopWindow())
|
||||
{
|
||||
gauge_.Show(false);
|
||||
Base::max(static_cast<float>(range));
|
||||
Base::states(static_cast<unsigned>(range));
|
||||
}
|
||||
@ -96,18 +112,25 @@ AppControllerBoilerplate::createProgressIndicator(unsigned statenum,
|
||||
|
||||
virtual void state(unsigned st) override {
|
||||
if( st <= max() ) {
|
||||
if(!gauge_.IsShown()) gauge_.ShowModal();
|
||||
Base::state(st);
|
||||
gauge_.Update(static_cast<int>(st), message_);
|
||||
if(!gauge_.IsShown()) gauge_.ShowModal();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void message(const std::string & msg) override {
|
||||
message_ = msg;
|
||||
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);
|
||||
gauge_.SetTitle(_(title));
|
||||
}
|
||||
};
|
||||
|
||||
@ -117,12 +140,78 @@ AppControllerBoilerplate::createProgressIndicator(unsigned statenum,
|
||||
return pri;
|
||||
}
|
||||
|
||||
void AppController::sliceObject(PrintObject *pobj)
|
||||
void PrintController::make_skirt()
|
||||
{
|
||||
assert(pobj != nullptr);
|
||||
if(pobj->state.is_done(posSlice)) return;
|
||||
assert(print_ != nullptr);
|
||||
|
||||
pobj->state.set_started(posSlice);
|
||||
// prerequisites
|
||||
for(auto obj : print_->objects) make_perimeters(obj);
|
||||
for(auto obj : print_->objects) infill(obj);
|
||||
for(auto obj : print_->objects) gen_support_material(obj);
|
||||
|
||||
if(!print_->state.is_done(STEP_SKIRT)) {
|
||||
print_->state.set_started(STEP_SKIRT);
|
||||
print_->skirt.clear();
|
||||
if(print_->has_skirt()) print_->_make_skirt();
|
||||
|
||||
print_->state.set_done(STEP_SKIRT);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintController::make_brim()
|
||||
{
|
||||
assert(print_ != nullptr);
|
||||
|
||||
// prerequisites
|
||||
for(auto obj : print_->objects) make_perimeters(obj);
|
||||
for(auto obj : print_->objects) infill(obj);
|
||||
for(auto obj : print_->objects) gen_support_material(obj);
|
||||
make_skirt();
|
||||
|
||||
if(!print_->state.is_done(STEP_BRIM)) {
|
||||
print_->state.set_started(STEP_BRIM);
|
||||
|
||||
// since this method must be idempotent, we clear brim paths *before*
|
||||
// checking whether we need to generate them
|
||||
print_->brim.clear();
|
||||
|
||||
if(print_->config.brim_width > 0) print_->_make_brim();
|
||||
|
||||
print_->state.set_done(STEP_BRIM);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintController::make_wipe_tower()
|
||||
{
|
||||
assert(print_ != nullptr);
|
||||
|
||||
// prerequisites
|
||||
for(auto obj : print_->objects) make_perimeters(obj);
|
||||
for(auto obj : print_->objects) infill(obj);
|
||||
for(auto obj : print_->objects) gen_support_material(obj);
|
||||
make_skirt();
|
||||
make_brim();
|
||||
|
||||
if(!print_->state.is_done(STEP_WIPE_TOWER)) {
|
||||
print_->state.set_started(STEP_WIPE_TOWER);
|
||||
|
||||
// since this method must be idempotent, we clear brim paths *before*
|
||||
// checking whether we need to generate them
|
||||
print_->brim.clear();
|
||||
|
||||
if(print_->has_wipe_tower()) print_->_make_wipe_tower();
|
||||
|
||||
print_->state.set_done(STEP_WIPE_TOWER);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintController::slice(PrintObject *pobj)
|
||||
{
|
||||
assert(pobj != nullptr && print_ != nullptr);
|
||||
|
||||
if(pobj->state.is_done(STEP_SLICE)) return;
|
||||
|
||||
pobj->state.set_started(STEP_SLICE);
|
||||
|
||||
pobj->_slice();
|
||||
|
||||
@ -140,72 +229,129 @@ void AppController::sliceObject(PrintObject *pobj)
|
||||
"STL file(s) or check their size or thickness and retry"
|
||||
);
|
||||
|
||||
pobj->state.set_done(posSlice);
|
||||
pobj->state.set_done(STEP_SLICE);
|
||||
}
|
||||
|
||||
void AppController::slice()
|
||||
void PrintController::make_perimeters(PrintObject *pobj)
|
||||
{
|
||||
assert(pobj != nullptr);
|
||||
|
||||
slice(pobj);
|
||||
|
||||
auto&& prgind = progressIndicator();
|
||||
|
||||
if (!pobj->state.is_done(STEP_PERIMETERS)) {
|
||||
pobj->_make_perimeters();
|
||||
}
|
||||
}
|
||||
|
||||
void PrintController::infill(PrintObject *pobj)
|
||||
{
|
||||
assert(pobj != nullptr);
|
||||
|
||||
make_perimeters(pobj);
|
||||
|
||||
if (!pobj->state.is_done(STEP_PREPARE_INFILL)) {
|
||||
pobj->state.set_started(STEP_PREPARE_INFILL);
|
||||
|
||||
pobj->_prepare_infill();
|
||||
|
||||
pobj->state.set_done(STEP_PREPARE_INFILL);
|
||||
}
|
||||
|
||||
pobj->_infill();
|
||||
}
|
||||
|
||||
void PrintController::gen_support_material(PrintObject *pobj)
|
||||
{
|
||||
assert(pobj != nullptr);
|
||||
|
||||
// prerequisites
|
||||
slice(pobj);
|
||||
|
||||
if(!pobj->state.is_done(STEP_SUPPORTMATERIAL)) {
|
||||
pobj->state.set_started(STEP_SUPPORTMATERIAL);
|
||||
|
||||
pobj->clear_support_layers();
|
||||
|
||||
if((pobj->config.support_material || pobj->config.raft_layers > 0)
|
||||
&& pobj->layers.size() > 1) {
|
||||
pobj->_generate_support_material();
|
||||
}
|
||||
|
||||
pobj->state.set_done(STEP_SUPPORTMATERIAL);
|
||||
}
|
||||
}
|
||||
|
||||
void PrintController::slice()
|
||||
{
|
||||
Slic3r::trace(3, "Starting the slicing process.");
|
||||
|
||||
for(auto obj : print_->objects) {
|
||||
sliceObject(obj);
|
||||
// print_->//status_cb->(20, "Generating perimeters");
|
||||
obj->_make_perimeters();
|
||||
}
|
||||
progressIndicator()->update(20u, "Generating perimeters");
|
||||
for(auto obj : print_->objects) make_perimeters(obj);
|
||||
|
||||
// $self->status_cb->(70, "Infilling layers");
|
||||
progressIndicator()->update(60u, "Infilling layers");
|
||||
for(auto obj : print_->objects) infill(obj);
|
||||
|
||||
// $_->infill for @{$self->objects};
|
||||
progressIndicator()->update(70u, "Generating support material");
|
||||
for(auto obj : print_->objects) gen_support_material(obj);
|
||||
|
||||
// $_->generate_support_material for @{$self->objects};
|
||||
// $self->make_skirt;
|
||||
// $self->make_brim; # must come after make_skirt
|
||||
// $self->make_wipe_tower;
|
||||
progressIndicator()->messageFmt("Weight: %.1fg, Cost: %.1f",
|
||||
print_->total_weight,
|
||||
print_->total_cost);
|
||||
|
||||
// # time to make some statistics
|
||||
// if (0) {
|
||||
// eval "use Devel::Size";
|
||||
// print "MEMORY USAGE:\n";
|
||||
// printf " meshes = %.1fMb\n", List::Util::sum(map Devel::Size::total_size($_->meshes), @{$self->objects})/1024/1024;
|
||||
// printf " layer slices = %.1fMb\n", List::Util::sum(map Devel::Size::total_size($_->slices), map @{$_->layers}, @{$self->objects})/1024/1024;
|
||||
// printf " region slices = %.1fMb\n", List::Util::sum(map Devel::Size::total_size($_->slices), map @{$_->regions}, map @{$_->layers}, @{$self->objects})/1024/1024;
|
||||
// printf " perimeters = %.1fMb\n", List::Util::sum(map Devel::Size::total_size($_->perimeters), map @{$_->regions}, map @{$_->layers}, @{$self->objects})/1024/1024;
|
||||
// printf " fills = %.1fMb\n", List::Util::sum(map Devel::Size::total_size($_->fills), map @{$_->regions}, map @{$_->layers}, @{$self->objects})/1024/1024;
|
||||
// printf " print object = %.1fMb\n", Devel::Size::total_size($self)/1024/1024;
|
||||
// }
|
||||
// if (0) {
|
||||
// eval "use Slic3r::Test::SectionCut";
|
||||
// Slic3r::Test::SectionCut->new(print => $self)->export_svg("section_cut.svg");
|
||||
// }
|
||||
// Slic3r::trace(3, "Slicing process finished.")
|
||||
progressIndicator()->state(85u);
|
||||
|
||||
|
||||
progressIndicator()->update(88u, "Generating skirt");
|
||||
make_skirt();
|
||||
|
||||
|
||||
progressIndicator()->update(90u, "Generating brim");
|
||||
make_brim();
|
||||
|
||||
progressIndicator()->update(95u, "Generating wipe tower");
|
||||
make_wipe_tower();
|
||||
|
||||
progressIndicator()->update(100u, "Done");
|
||||
|
||||
// time to make some statistics..
|
||||
|
||||
Slic3r::trace(3, "Slicing process finished.");
|
||||
}
|
||||
|
||||
void AppController::slice_to_png()
|
||||
void PrintController::slice_to_png()
|
||||
{
|
||||
assert(model_ != nullptr);
|
||||
|
||||
auto pri = globalProgressIndicator(); //createProgressIndicator(100, "Gauge", "operation");
|
||||
// auto pri = globalProgressIndicator();
|
||||
|
||||
pri->title("Operation");
|
||||
pri->message("...");
|
||||
// pri->title("Operation");
|
||||
// pri->message("...");
|
||||
|
||||
for(unsigned i = 1; i <= 100; i++ ) {
|
||||
pri->state(i);
|
||||
wxMilliSleep(100);
|
||||
}
|
||||
// for(unsigned i = 1; i <= 100; i++ ) {
|
||||
// pri->state(i);
|
||||
// wxMilliSleep(100);
|
||||
// }
|
||||
|
||||
// auto zipfilepath = query_destination_path( "Path to zip file...",
|
||||
// "*.zip");
|
||||
|
||||
// auto presetbundle = GUI::get_preset_bundle();
|
||||
auto presetbundle = GUI::get_preset_bundle();
|
||||
|
||||
// assert(presetbundle);
|
||||
assert(presetbundle);
|
||||
|
||||
// auto conf = presetbundle->full_config();
|
||||
auto conf = presetbundle->full_config();
|
||||
|
||||
// conf.validate();
|
||||
conf.validate();
|
||||
|
||||
auto bak = progressIndicator();
|
||||
progressIndicator(100, "Slicing to zipped png files...");
|
||||
std::async(std::launch::async, [this, &bak](){
|
||||
slice();
|
||||
progressIndicator(bak);
|
||||
});
|
||||
|
||||
// slice();
|
||||
}
|
||||
|
||||
void AppController::set_global_progress_indicator_id(
|
||||
@ -246,11 +392,11 @@ void AppController::set_global_progress_indicator_id(
|
||||
|
||||
if(!gauge_->IsShown()) showProgress(true);
|
||||
|
||||
stbar_->SetStatusText(message_);
|
||||
if(st == gauge_->GetRange()) {
|
||||
gauge_->SetValue(0);
|
||||
showProgress(false);
|
||||
} else {
|
||||
stbar_->SetStatusText(message_);
|
||||
gauge_->SetValue(static_cast<int>(st));
|
||||
}
|
||||
}
|
||||
@ -260,6 +406,13 @@ void AppController::set_global_progress_indicator_id(
|
||||
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 {}
|
||||
|
||||
};
|
||||
@ -267,8 +420,38 @@ void AppController::set_global_progress_indicator_id(
|
||||
wxGauge* gauge = dynamic_cast<wxGauge*>(wxWindow::FindWindowById(gid));
|
||||
wxStatusBar* sb = dynamic_cast<wxStatusBar*>(wxWindow::FindWindowById(sid));
|
||||
|
||||
if(gauge && sb)
|
||||
globalProgressIndicator(std::make_shared<Wrapper>(gauge, sb));
|
||||
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;
|
||||
va_list args;
|
||||
va_start(args, fmtstr);
|
||||
|
||||
auto fmt = fmtstr.begin();
|
||||
|
||||
while (*fmt != '\0') {
|
||||
if (*fmt == 'd') {
|
||||
int i = va_arg(args, int);
|
||||
ss << i << '\n';
|
||||
} else if (*fmt == 'c') {
|
||||
// note automatic conversion to integral type
|
||||
int c = va_arg(args, int);
|
||||
ss << static_cast<char>(c) << '\n';
|
||||
} else if (*fmt == 'f') {
|
||||
double d = va_arg(args, double);
|
||||
ss << d << '\n';
|
||||
}
|
||||
++fmt;
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
message(ss.str());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,6 +58,8 @@ public:
|
||||
virtual void message(const std::string&) = 0;
|
||||
virtual void title(const std::string&) = 0;
|
||||
|
||||
virtual void messageFmt(const std::string& fmt, ...);
|
||||
|
||||
template<class T>
|
||||
void update(T st, const std::string& msg) {
|
||||
message(msg); state(st);
|
||||
@ -66,40 +68,76 @@ public:
|
||||
|
||||
using ProgresIndicatorPtr = std::shared_ptr<ProgressIndicator>;
|
||||
|
||||
|
||||
inline void progressIndicator(ProgresIndicatorPtr progrind) {
|
||||
progressind_ = progrind;
|
||||
}
|
||||
|
||||
inline void progressIndicator(unsigned statenum,
|
||||
const std::string& title,
|
||||
const std::string& firstmsg = "") {
|
||||
progressind_ = createProgressIndicator(statenum, title, firstmsg);
|
||||
}
|
||||
|
||||
inline ProgresIndicatorPtr progressIndicator() {
|
||||
if(!progressind_)
|
||||
progressind_ = createProgressIndicator(100, "Progress");
|
||||
|
||||
return progressind_;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
ProgresIndicatorPtr createProgressIndicator(
|
||||
unsigned statenum,
|
||||
const std::string& title,
|
||||
const std::string& firstmsg = "") const;
|
||||
|
||||
inline void globalProgressIndicator(ProgresIndicatorPtr progrind) {
|
||||
glob_progressind_ = progrind;
|
||||
}
|
||||
|
||||
inline ProgresIndicatorPtr globalProgressIndicator() {
|
||||
if(!glob_progressind_)
|
||||
glob_progressind_ = createProgressIndicator(100, "Progress");
|
||||
|
||||
return glob_progressind_;
|
||||
}
|
||||
|
||||
private:
|
||||
ProgresIndicatorPtr glob_progressind_;
|
||||
ProgresIndicatorPtr progressind_;
|
||||
};
|
||||
|
||||
class AppController: protected AppControllerBoilerplate {
|
||||
Model *model_ = nullptr; Print *print_ = nullptr;
|
||||
class PrintController: public AppControllerBoilerplate {
|
||||
Print *print_ = nullptr;
|
||||
protected:
|
||||
|
||||
void sliceObject(PrintObject *pobj);
|
||||
void make_skirt();
|
||||
void make_brim();
|
||||
void make_wipe_tower();
|
||||
|
||||
public:
|
||||
|
||||
void slice();
|
||||
using Ptr = std::unique_ptr<PrintController>;
|
||||
|
||||
explicit inline PrintController(Print *print): print_(print) {}
|
||||
|
||||
inline static Ptr create(Print *print) {
|
||||
return std::make_unique<PrintController>(print);
|
||||
}
|
||||
|
||||
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 {
|
||||
Model *model_ = nullptr;
|
||||
PrintController::Ptr printctl;
|
||||
public:
|
||||
|
||||
PrintController * print_ctl() { return printctl.get(); }
|
||||
|
||||
void set_model(Model *model) { model_ = model; }
|
||||
|
||||
void set_print(Print *print) { print_ = print; }
|
||||
void set_print(Print *print) {
|
||||
printctl = PrintController::create(print);
|
||||
printctl->progressIndicator(progressIndicator());
|
||||
}
|
||||
|
||||
void set_global_progress_indicator_id(unsigned gauge_id,
|
||||
unsigned statusbar_id);
|
||||
|
@ -7,14 +7,20 @@
|
||||
#include "libslic3r/Print.hpp"
|
||||
%}
|
||||
|
||||
%name{Slic3r::PrintController} class PrintController {
|
||||
|
||||
PrintController(Print *print);
|
||||
|
||||
void slice_to_png();
|
||||
void slice();
|
||||
};
|
||||
|
||||
%name{Slic3r::AppController} class AppController {
|
||||
|
||||
AppController();
|
||||
|
||||
void slice_to_png();
|
||||
|
||||
PrintController *print_ctl();
|
||||
void set_model(Model *model);
|
||||
void set_print(Print *print);
|
||||
void set_global_progress_indicator_id(unsigned gauge_id, unsigned statusbar_id);
|
||||
|
||||
};
|
@ -216,7 +216,8 @@ Ref<PrintObjectSupportMaterial> O_OBJECT_SLIC3R_T
|
||||
Clone<PrintObjectSupportMaterial> O_OBJECT_SLIC3R_T
|
||||
|
||||
AppConfig* O_OBJECT_SLIC3R
|
||||
AppController* O_OBJECT_SLIC3R
|
||||
AppController* O_OBJECT_SLIC3R
|
||||
PrintController* O_OBJECT_SLIC3R
|
||||
Ref<AppConfig> O_OBJECT_SLIC3R_T
|
||||
|
||||
GLShader* O_OBJECT_SLIC3R
|
||||
|
@ -269,3 +269,4 @@
|
||||
%};
|
||||
};
|
||||
%typemap{AppController*};
|
||||
%typemap{PrintController*};
|
Loading…
Reference in New Issue
Block a user