mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-29 03:31:17 -06:00
Integrated SLAPrint into background processing.
Fixed couple of compiler warnings.
This commit is contained in:
parent
811404d97a
commit
bbfbe88a5f
24 changed files with 283 additions and 89 deletions
|
|
@ -7,9 +7,10 @@
|
|||
#include <wx/stdpaths.h>
|
||||
|
||||
// Print now includes tbb, and tbb includes Windows. This breaks compilation of wxWidgets if included before wx.
|
||||
#include "../../libslic3r/Print.hpp"
|
||||
#include "../../libslic3r/Utils.hpp"
|
||||
#include "../../libslic3r/GCode/PostProcessor.hpp"
|
||||
#include "libslic3r/Print.hpp"
|
||||
#include "libslic3r/SLAPrint.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/GCode/PostProcessor.hpp"
|
||||
|
||||
//#undef NDEBUG
|
||||
#include <cassert>
|
||||
|
|
@ -35,8 +36,49 @@ BackgroundSlicingProcess::~BackgroundSlicingProcess()
|
|||
boost::nowide::remove(m_temp_output_path.c_str());
|
||||
}
|
||||
|
||||
void BackgroundSlicingProcess::select_technology(PrinterTechnology tech)
|
||||
{
|
||||
if (m_print == nullptr || m_print->technology() != tech) {
|
||||
if (m_print != nullptr)
|
||||
this->reset();
|
||||
switch (tech) {
|
||||
case ptFFF: m_print = m_fff_print; break;
|
||||
case ptSLA: m_print = m_sla_print; break;
|
||||
}
|
||||
}
|
||||
assert(m_print != nullptr);
|
||||
}
|
||||
|
||||
// This function may one day be merged into the Print, but historically the print was separated
|
||||
// from the G-code generator.
|
||||
void BackgroundSlicingProcess::process_fff()
|
||||
{
|
||||
assert(m_print == m_fff_print);
|
||||
m_print->process();
|
||||
if (! m_print->canceled()) {
|
||||
wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, new wxCommandEvent(m_event_sliced_id));
|
||||
m_fff_print->export_gcode(m_temp_output_path, m_gcode_preview_data);
|
||||
if (! m_print->canceled() && ! this->is_step_done(bspsGCodeFinalize)) {
|
||||
this->set_step_started(bspsGCodeFinalize);
|
||||
if (! m_export_path.empty()) {
|
||||
//FIXME localize the messages
|
||||
if (copy_file(m_temp_output_path, m_export_path) != 0)
|
||||
throw std::runtime_error("Copying of the temporary G-code to the output G-code failed");
|
||||
m_print->set_status(95, "Running post-processing scripts");
|
||||
run_post_process_scripts(m_export_path, m_fff_print->config());
|
||||
m_print->set_status(100, "G-code file exported to " + m_export_path);
|
||||
} else {
|
||||
m_print->set_status(100, "Slicing complete");
|
||||
}
|
||||
this->set_step_done(bspsGCodeFinalize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BackgroundSlicingProcess::thread_proc()
|
||||
{
|
||||
assert(m_print != nullptr);
|
||||
assert(m_print == m_fff_print || m_print == m_sla_print);
|
||||
std::unique_lock<std::mutex> lck(m_mutex);
|
||||
// Let the caller know we are ready to run the background processing task.
|
||||
m_state = STATE_IDLE;
|
||||
|
|
@ -56,25 +98,10 @@ void BackgroundSlicingProcess::thread_proc()
|
|||
std::string error;
|
||||
try {
|
||||
assert(m_print != nullptr);
|
||||
m_print->process();
|
||||
if (! m_print->canceled()) {
|
||||
wxQueueEvent(GUI::wxGetApp().mainframe->m_plater, new wxCommandEvent(m_event_sliced_id));
|
||||
m_print->export_gcode(m_temp_output_path, m_gcode_preview_data);
|
||||
if (! m_print->canceled() && ! this->is_step_done(bspsGCodeFinalize)) {
|
||||
this->set_step_started(bspsGCodeFinalize);
|
||||
if (! m_export_path.empty()) {
|
||||
//FIXME localize the messages
|
||||
if (copy_file(m_temp_output_path, m_export_path) != 0)
|
||||
throw std::runtime_error("Copying of the temporary G-code to the output G-code failed");
|
||||
m_print->set_status(95, "Running post-processing scripts");
|
||||
run_post_process_scripts(m_export_path, m_print->config());
|
||||
m_print->set_status(100, "G-code file exported to " + m_export_path);
|
||||
} else {
|
||||
m_print->set_status(100, "Slicing complete");
|
||||
}
|
||||
this->set_step_done(bspsGCodeFinalize);
|
||||
}
|
||||
}
|
||||
switch(m_print->technology()) {
|
||||
case ptFFF: this->process_fff(); break;
|
||||
default: m_print->process(); break;
|
||||
}
|
||||
} catch (CanceledException & /* ex */) {
|
||||
// Canceled, this is all right.
|
||||
assert(m_print->canceled());
|
||||
|
|
@ -133,6 +160,10 @@ void BackgroundSlicingProcess::join_background_thread()
|
|||
|
||||
bool BackgroundSlicingProcess::start()
|
||||
{
|
||||
if (m_print->empty())
|
||||
// The print is empty (no object in Model, or all objects are out of the print bed).
|
||||
return false;
|
||||
|
||||
std::unique_lock<std::mutex> lck(m_mutex);
|
||||
if (m_state == STATE_INITIAL) {
|
||||
// The worker thread is not running yet. Start it.
|
||||
|
|
@ -183,6 +214,7 @@ bool BackgroundSlicingProcess::reset()
|
|||
bool stopped = this->stop();
|
||||
this->reset_export();
|
||||
m_print->clear();
|
||||
this->invalidate_all_steps();
|
||||
return stopped;
|
||||
}
|
||||
|
||||
|
|
@ -203,20 +235,18 @@ void BackgroundSlicingProcess::stop_internal()
|
|||
m_print->set_cancel_callback([](){});
|
||||
}
|
||||
|
||||
// Apply config over the print. Returns false, if the new config values caused any of the already
|
||||
// processed steps to be invalidated, therefore the task will need to be restarted.
|
||||
bool BackgroundSlicingProcess::apply_config(const DynamicPrintConfig &config)
|
||||
std::string BackgroundSlicingProcess::validate()
|
||||
{
|
||||
this->stop();
|
||||
bool invalidated = m_print->apply_config(config);
|
||||
return invalidated;
|
||||
assert(m_print != nullptr);
|
||||
return m_print->validate();
|
||||
}
|
||||
|
||||
// Apply config over the print. Returns false, if the new config values caused any of the already
|
||||
// processed steps to be invalidated, therefore the task will need to be restarted.
|
||||
Print::ApplyStatus BackgroundSlicingProcess::apply(const Model &model, const DynamicPrintConfig &config)
|
||||
{
|
||||
// this->stop();
|
||||
assert(m_print != nullptr);
|
||||
assert(config.opt_enum<PrinterTechnology>("printer_technology") == m_print->technology());
|
||||
Print::ApplyStatus invalidated = m_print->apply(model, config);
|
||||
return invalidated;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ namespace Slic3r {
|
|||
class DynamicPrintConfig;
|
||||
class GCodePreviewData;
|
||||
class Model;
|
||||
class SLAPrint;
|
||||
|
||||
// Print step IDs for keeping track of the print state.
|
||||
enum BackgroundSlicingProcessStep {
|
||||
|
|
@ -28,7 +29,8 @@ public:
|
|||
// Stop the background processing and finalize the bacgkround processing thread, remove temp files.
|
||||
~BackgroundSlicingProcess();
|
||||
|
||||
void set_print(Print *print) { m_print = print; }
|
||||
void set_fff_print(Print *print) { m_fff_print = print; }
|
||||
void set_sla_print(SLAPrint *print) { m_sla_print = print; }
|
||||
void set_gcode_preview_data(GCodePreviewData *gpd) { m_gcode_preview_data = gpd; }
|
||||
// The following wxCommandEvent will be sent to the UI thread / Platter window, when the slicing is finished
|
||||
// and the background processing will transition into G-code export.
|
||||
|
|
@ -38,6 +40,8 @@ public:
|
|||
// The wxCommandEvent is sent to the UI thread asynchronously without waiting for the event to be processed.
|
||||
void set_finished_event(int event_id) { m_event_finished_id = event_id; }
|
||||
|
||||
// Activate either m_fff_print or m_sla_print.
|
||||
void select_technology(PrinterTechnology tech);
|
||||
// Start the background processing. Returns false if the background processing was already running.
|
||||
bool start();
|
||||
// Cancel the background processing. Returns false if the background processing was not running.
|
||||
|
|
@ -47,9 +51,8 @@ public:
|
|||
// Useful when the Model or configuration is being changed drastically.
|
||||
bool reset();
|
||||
|
||||
// Apply config over the print. Returns false, if the new config values caused any of the already
|
||||
// processed steps to be invalidated, therefore the task will need to be restarted.
|
||||
bool apply_config(const DynamicPrintConfig &config);
|
||||
// Validate the print. Returns an empty string if valid, returns an error message if invalid.
|
||||
std::string validate();
|
||||
// Apply config over the print. Returns false, if the new config values caused any of the already
|
||||
// processed steps to be invalidated, therefore the task will need to be restarted.
|
||||
Print::ApplyStatus apply(const Model &model, const DynamicPrintConfig &config);
|
||||
|
|
@ -90,7 +93,14 @@ private:
|
|||
// This function shall not trigger any UI update through the wxWidgets event.
|
||||
void stop_internal();
|
||||
|
||||
Print *m_print = nullptr;
|
||||
// Helper to wrap the FFF slicing & G-code generation.
|
||||
void process_fff();
|
||||
|
||||
// Currently active print. It is one of m_fff_print and m_sla_print.
|
||||
PrintBase *m_print = nullptr;
|
||||
// Non-owned pointers to Print instances.
|
||||
Print *m_fff_print = nullptr;
|
||||
SLAPrint *m_sla_print = nullptr;
|
||||
// Data structure, to which the G-code export writes its annotations.
|
||||
GCodePreviewData *m_gcode_preview_data = nullptr;
|
||||
// Temporary G-code, there is one defined for the BackgroundSlicingProcess, differentiated from the other processes by a process ID.
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@
|
|||
namespace Slic3r {
|
||||
|
||||
|
||||
struct BonjourReplyEvent : public wxEvent
|
||||
class BonjourReplyEvent : public wxEvent
|
||||
{
|
||||
public:
|
||||
BonjourReply reply;
|
||||
|
||||
BonjourReplyEvent(wxEventType eventType, int winid, BonjourReply &&reply) :
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt
|
|||
config.set_key_value(opt_key, new ConfigOptionBool(boost::any_cast<bool>(value)));
|
||||
break;
|
||||
case coBools:{
|
||||
ConfigOptionBools* vec_new = new ConfigOptionBools{ (bool)boost::any_cast<unsigned char>(value) };
|
||||
ConfigOptionBools* vec_new = new ConfigOptionBools{ boost::any_cast<unsigned char>(value) != 0 };
|
||||
config.option<ConfigOptionBools>(opt_key)->set_at(vec_new, opt_index, 0);
|
||||
break;}
|
||||
case coInt:
|
||||
|
|
|
|||
|
|
@ -92,13 +92,12 @@ bool GUI_App::OnInit()
|
|||
|
||||
// Suppress the '- default -' presets.
|
||||
preset_bundle->set_default_suppressed(app_config->get("no_defaults") == "1");
|
||||
// eval{
|
||||
preset_bundle->load_presets(*app_config);
|
||||
// };
|
||||
// if ($@) {
|
||||
// warn $@ . "\n";
|
||||
// show_error(undef, $@);
|
||||
// }
|
||||
try {
|
||||
preset_bundle->load_presets(*app_config);
|
||||
} catch (const std::exception & /* ex */) {
|
||||
// warn $@ . "\n";
|
||||
// show_error(undef, $@);
|
||||
}
|
||||
|
||||
// Let the libslic3r know the callback, which will translate messages on demand.
|
||||
Slic3r::I18N::set_translate_callback(libslic3r_translate_callback);
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ boost::optional<WindowMetrics> WindowMetrics::deserialize(const std::string &str
|
|||
|
||||
WindowMetrics res;
|
||||
res.rect = wxRect(metrics[0], metrics[1], metrics[2], metrics[3]);
|
||||
res.maximized = metrics[4];
|
||||
res.maximized = metrics[4] != 0;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
#include "libslic3r/PrintConfig.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/Print.hpp"
|
||||
#include "libslic3r/SLAPrint.hpp"
|
||||
#include "libslic3r/GCode/PreviewData.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/Polygon.hpp"
|
||||
|
|
@ -852,6 +853,7 @@ struct Plater::priv
|
|||
// Data
|
||||
Slic3r::DynamicPrintConfig *config;
|
||||
Slic3r::Print print;
|
||||
Slic3r::SLAPrint sla_print;
|
||||
Slic3r::Model model;
|
||||
Slic3r::GCodePreviewData gcode_preview_data;
|
||||
|
||||
|
|
@ -949,17 +951,19 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
|
|||
"brim_width", "variable_layer_height", "serial_port", "serial_speed", "host_type", "print_host",
|
||||
"printhost_apikey", "printhost_cafile", "nozzle_diameter", "single_extruder_multi_material",
|
||||
"wipe_tower", "wipe_tower_x", "wipe_tower_y", "wipe_tower_width", "wipe_tower_rotation_angle",
|
||||
"extruder_colour", "filament_colour", "max_print_height", "printer_model"
|
||||
"extruder_colour", "filament_colour", "max_print_height", "printer_model", "printer_technology"
|
||||
})),
|
||||
notebook(new wxNotebook(q, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNB_BOTTOM)),
|
||||
sidebar(new Sidebar(q)),
|
||||
canvas3D(GLCanvas3DManager::create_wxglcanvas(notebook))
|
||||
{
|
||||
// TODO: background_process.set_print(&slaprint);
|
||||
background_process.set_print(&print);
|
||||
background_process.set_fff_print(&print);
|
||||
background_process.set_sla_print(&sla_print);
|
||||
background_process.set_gcode_preview_data(&gcode_preview_data);
|
||||
background_process.set_sliced_event(EVT_SLICING_COMPLETED);
|
||||
background_process.set_finished_event(EVT_PROCESS_COMPLETED);
|
||||
// Default printer technology for default config.
|
||||
background_process.select_technology(wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology());
|
||||
// Register progress callback from the Print class to the Platter.
|
||||
print.set_status_callback([this](int percent, const std::string &message) {
|
||||
wxCommandEvent event(EVT_PROGRESS_BAR);
|
||||
|
|
@ -1516,6 +1520,7 @@ void Plater::priv::schedule_background_process()
|
|||
void Plater::priv::async_apply_config()
|
||||
{
|
||||
DynamicPrintConfig config = wxGetApp().preset_bundle->full_config();
|
||||
auto printer_technology = config.opt_enum<PrinterTechnology>("printer_technology");
|
||||
BoundingBox bed_box_2D = get_extents(Polygon::new_scale(config.opt<ConfigOptionPoints>("bed_shape")->values));
|
||||
BoundingBoxf3 print_volume(unscale(bed_box_2D.min(0), bed_box_2D.min(1), 0.0), unscale(bed_box_2D.max(0), bed_box_2D.max(1), scale_(config.opt_float("max_print_height"))));
|
||||
// Allow the objects to protrude below the print bed, only the part of the object above the print bed will be sliced.
|
||||
|
|
@ -1536,17 +1541,19 @@ void Plater::priv::async_apply_config()
|
|||
// Reset preview canvases. If the print has been invalidated, the preview canvases will be cleared.
|
||||
// Otherwise they will be just refreshed.
|
||||
this->gcode_preview_data.reset();
|
||||
if (this->preview != nullptr)
|
||||
this->preview->reload_print();
|
||||
// We also need to reload 3D scene because of the wipe tower preview box
|
||||
if (this->config->opt_bool("wipe_tower")) {
|
||||
// std::vector<int> selections = this->collect_selections();
|
||||
// Slic3r::_3DScene::set_objects_selections(this->canvas3D, selections);
|
||||
// Slic3r::_3DScene::reload_scene(this->canvas3D, 1);
|
||||
if (printer_technology == ptFFF) {
|
||||
if (this->preview != nullptr)
|
||||
this->preview->reload_print();
|
||||
// We also need to reload 3D scene because of the wipe tower preview box
|
||||
if (this->config->opt_bool("wipe_tower")) {
|
||||
// std::vector<int> selections = this->collect_selections();
|
||||
// Slic3r::_3DScene::set_objects_selections(this->canvas3D, selections);
|
||||
// Slic3r::_3DScene::reload_scene(this->canvas3D, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (invalidated != Print::APPLY_STATUS_UNCHANGED && this->get_config("background_processing") == "1" &&
|
||||
this->print.num_object_instances() > 0 && this->background_process.start())
|
||||
this->background_process.start())
|
||||
this->statusbar()->set_cancel_callback([this]() {
|
||||
this->statusbar()->set_status_text(L("Cancelling"));
|
||||
this->background_process.stop();
|
||||
|
|
@ -1557,13 +1564,13 @@ void Plater::priv::start_background_process()
|
|||
{
|
||||
if (this->background_process.running())
|
||||
return;
|
||||
// return if ! @{$self->{objects}} || $self->{background_slicing_process}->running;
|
||||
// Don't start process thread if Print is not valid.
|
||||
std::string err = this->q->print().validate();
|
||||
std::string err = this->background_process.validate();
|
||||
if (! err.empty()) {
|
||||
this->statusbar()->set_status_text(err);
|
||||
} else {
|
||||
// Copy the names of active presets into the placeholder parser.
|
||||
//FIXME how to generate a file name for the SLA printers?
|
||||
wxGetApp().preset_bundle->export_selections(this->q->print().placeholder_parser());
|
||||
// Start the background process.
|
||||
this->background_process.start();
|
||||
|
|
@ -2052,7 +2059,7 @@ void Plater::export_gcode(fs::path output_path)
|
|||
|
||||
std::string err = wxGetApp().preset_bundle->full_config().validate();
|
||||
if (err.empty())
|
||||
err = p->print.validate();
|
||||
err = p->background_process.validate();
|
||||
if (! err.empty()) {
|
||||
// The config is not valid
|
||||
GUI::show_error(this, _(err));
|
||||
|
|
@ -2198,7 +2205,9 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
|
|||
bool update_scheduled = false;
|
||||
for (auto opt_key : p->config->diff(config)) {
|
||||
p->config->set_key_value(opt_key, config.option(opt_key)->clone());
|
||||
if (opt_key == "bed_shape") {
|
||||
if (opt_key == "printer_technology")
|
||||
p->background_process.select_technology(config.opt_enum<PrinterTechnology>(opt_key));
|
||||
else if (opt_key == "bed_shape") {
|
||||
if (p->canvas3D) _3DScene::set_bed_shape(p->canvas3D, p->config->option<ConfigOptionPoints>(opt_key)->values);
|
||||
if (p->preview) p->preview->set_bed_shape(p->config->option<ConfigOptionPoints>(opt_key)->values);
|
||||
update_scheduled = true;
|
||||
|
|
|
|||
|
|
@ -1039,7 +1039,7 @@ std::string PresetCollection::path_from_name(const std::string &new_name) const
|
|||
const Preset& PrinterPresetCollection::default_preset_for(const DynamicPrintConfig &config) const
|
||||
{
|
||||
const ConfigOptionEnumGeneric *opt_printer_technology = config.opt<ConfigOptionEnumGeneric>("printer_technology");
|
||||
return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == 0) ? 0 : 1);
|
||||
return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == ptFFF) ? 0 : 1);
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
|||
|
|
@ -524,6 +524,8 @@ DynamicPrintConfig PresetBundle::full_fff_config() const
|
|||
};
|
||||
add_if_some_non_empty(std::move(compatible_printers_condition), "compatible_printers_condition_cummulative");
|
||||
add_if_some_non_empty(std::move(inherits), "inherits_cummulative");
|
||||
|
||||
out.option<ConfigOptionEnumGeneric>("printer_technology", true)->value = ptFFF;
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
@ -566,7 +568,9 @@ DynamicPrintConfig PresetBundle::full_sla_config() const
|
|||
};
|
||||
add_if_some_non_empty(std::move(compatible_printers_condition), "compatible_printers_condition_cummulative");
|
||||
add_if_some_non_empty(std::move(inherits), "inherits_cummulative");
|
||||
return out;
|
||||
|
||||
out.option<ConfigOptionEnumGeneric>("printer_technology", true)->value = ptSLA;
|
||||
return out;
|
||||
}
|
||||
|
||||
// Load an external config file containing the print, filament and printer presets.
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ void Chart::draw() {
|
|||
|
||||
// draw x-axis:
|
||||
float last_mark = -10000;
|
||||
for (float math_x=int(visible_area.m_x*10)/10 ; math_x < (visible_area.m_x+visible_area.m_width) ; math_x+=0.1) {
|
||||
for (float math_x=int(visible_area.m_x*10)/10 ; math_x < (visible_area.m_x+visible_area.m_width) ; math_x+=0.1f) {
|
||||
int x = math_to_screen(wxPoint2DDouble(math_x,visible_area.m_y)).x;
|
||||
int y = m_rect.GetBottom();
|
||||
if (x-last_mark < 50) continue;
|
||||
|
|
|
|||
|
|
@ -2327,7 +2327,7 @@ void Tab::update_page_tree_visibility()
|
|||
// Called by the UI combo box when the user switches profiles.
|
||||
// Select a preset by a name.If !defined(name), then the default preset is selected.
|
||||
// If the current profile is modified, user is asked to save the changes.
|
||||
void Tab::select_preset(std::string preset_name /*= ""*/)
|
||||
void Tab::select_preset(std::string preset_name)
|
||||
{
|
||||
// If no name is provided, select the "-- default --" preset.
|
||||
if (preset_name.empty())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue