WIP: Reconstruction of background processing update timer,

added unique IDs to the Model / ModelObject / ModelVolume objects,
added a copy of Model hierarchy at the Print,
WIP: new Print::apply() method to update the Print's copy of Model,
to update the Print's PrintObjects, to update status of the Print and
PrintObjects, and to possibly stop the background processing.
This commit is contained in:
bubnikv 2018-10-17 11:12:38 +02:00
parent 404ef147b3
commit 7ed2752b2b
8 changed files with 602 additions and 111 deletions

View file

@ -159,7 +159,7 @@ void MainFrame::init_tabpanel()
if (m_plater) {
// load initial config
auto full_config = wxGetApp().preset_bundle->full_config();
m_plater->on_config_change(&full_config);
m_plater->on_config_change(full_config);
// Show a correct number of filament fields.
// nozzle_diameter is undefined when SLA printer is selected
@ -530,9 +530,10 @@ void MainFrame::quick_slice(const int qs){
// Slic3r::GUI::catch_error(this, [](){ if (m_progress_dialog) m_progress_dialog->Destroy(); });
}
void MainFrame::reslice_now(){
// if (m_plater)
// m_plater->reslice();
void MainFrame::reslice_now()
{
if (m_plater)
m_plater->reslice();
}
void MainFrame::repair_stl()
@ -611,12 +612,13 @@ void MainFrame::load_config_file(wxString file/* = wxEmptyString*/)
file = dlg->GetPath();
dlg->Destroy();
}
// eval{
try {
wxGetApp().preset_bundle->load_config_file(file.ToStdString());
// };
// Dont proceed further if the config file cannot be loaded.
// if (Slic3r::GUI::catch_error(this))
// return;
} catch (std::exception & /* ex */) {
// Dont proceed further if the config file cannot be loaded.
// if (Slic3r::GUI::catch_error(this))
// return;
}
for (auto tab : m_options_tabs )
tab.second->load_current_preset();
wxGetApp().app_config->update_config_dir(get_dir_name(file));
@ -644,18 +646,20 @@ void MainFrame::export_configbundle()
dlg->Destroy();
if (!file.IsEmpty()) {
// Export the config bundle.
wxGetApp().app_config->update_config_dir(get_dir_name(file));
// eval{
wxGetApp().app_config->update_config_dir(get_dir_name(file));
try {
wxGetApp().preset_bundle->export_configbundle(file.ToStdString());
// };
} catch (std::exception & /* ex */) {
// Slic3r::GUI::catch_error(this);
}
}
}
// Loading a config bundle with an external file name used to be used
// to auto - install a config bundle on a fresh user account,
// but that behavior was not documented and likely buggy.
void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool reset_user_profile*/){
void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool reset_user_profile*/)
{
if (!wxGetApp().check_unsaved_changes())
return;
if (file.IsEmpty()) {
@ -671,10 +675,11 @@ void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool re
wxGetApp().app_config->update_config_dir(get_dir_name(file));
auto presets_imported = 0;
// eval{
try {
presets_imported = wxGetApp().preset_bundle->load_configbundle(file.ToStdString());
// };
} catch (std::exception & /* ex */) {
// Slic3r::GUI::catch_error(this) and return;
}
// Load the currently selected preset into the GUI, update the preset selection box.
for (auto tab : m_options_tabs)
@ -686,20 +691,24 @@ void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool re
// Load a provied DynamicConfig into the Print / Filament / Printer tabs, thus modifying the active preset.
// Also update the platter with the new presets.
void MainFrame::load_config(const DynamicPrintConfig& config){
void MainFrame::load_config(const DynamicPrintConfig& config)
{
for (auto tab : m_options_tabs)
tab.second->load_config(config);
// if (m_plater) m_plater->on_config_change(config);
if (m_plater)
m_plater->on_config_change(config);
}
void MainFrame::select_tab(size_t tab) const{
void MainFrame::select_tab(size_t tab) const
{
m_tabpanel->SetSelection(tab);
}
// Set a camera direction, zoom to all objects.
void MainFrame::select_view(const std::string& direction){
// if (m_plater)
// m_plater->select_view(direction);
void MainFrame::select_view(const std::string& direction)
{
// if (m_plater)
// m_plater->select_view(direction);
}
wxMenuItem* MainFrame::append_menu_item(wxMenu* menu,
@ -743,8 +752,7 @@ void MainFrame::on_presets_changed(SimpleEvent &event)
if (preset_type == Slic3r::Preset::TYPE_PRINTER) {
// Printer selected at the Printer tab, update "compatible" marks at the print and filament selectors.
// XXX: Do this in a more C++ way
std::vector<std::string> tab_names_other = { "print", "filament", "sla_material" };
for (const auto tab_name_other : tab_names_other) {
for (const auto tab_name_other : { "print", "filament", "sla_material" }) {
Tab* cur_tab = m_options_tabs[tab_name_other];
// If the printer tells us that the print or filament preset has been switched or invalidated,
// refresh the print or filament tab page.Otherwise just refresh the combo box.
@ -756,8 +764,7 @@ void MainFrame::on_presets_changed(SimpleEvent &event)
cur_tab->load_current_preset();
}
}
// XXX: ?
// m_plater->on_config_change(tab->get_config());
m_plater->on_config_change(*tab->get_config());
}
}
@ -769,18 +776,19 @@ void MainFrame::on_value_changed(wxCommandEvent& event)
return;
auto opt_key = event.GetString();
auto config = tab->get_config();
if (m_plater) {
m_plater->on_config_change(config); // propagate config change events to the plater
if (opt_key == "extruders_count"){
auto value = event.GetInt();
m_plater->on_extruders_change(value);
}
m_plater->on_config_change(*tab->get_config()); // propagate config change events to the plater
if (opt_key == "extruders_count"){
auto value = event.GetInt();
m_plater->on_extruders_change(value);
}
}
// Don't save while loading for the first time.
if (m_loaded) {
AppConfig &cfg = *wxGetApp().app_config;
if (cfg.get("autosave") == "1")
cfg.save();
}
// don't save while loading for the first time
// #ys_FIXME ?autosave?
// if (wxGetApp().autosave && m_loaded)
// m_config->save(wxGetApp().autosave);
}
// Called after the Preferences dialog is closed and the program settings are saved.

View file

@ -209,6 +209,7 @@ PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) :
if (dialog->ShowModal() == wxID_OK) {
DynamicPrintConfig cfg = *wxGetApp().get_tab(Preset::TYPE_PRINTER)->get_config();
//FIXME this is too expensive to call full_config to get just the extruder color!
auto colors = static_cast<ConfigOptionStrings*>(wxGetApp().preset_bundle->full_config().option("extruder_colour")->clone());
colors->values[extruder_idx] = dialog->GetColourData().GetColour().GetAsString(wxC2S_HTML_SYNTAX);
@ -216,7 +217,7 @@ PresetComboBox::PresetComboBox(wxWindow *parent, Preset::Type preset_type) :
wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg);
wxGetApp().preset_bundle->update_platter_filament_ui(extruder_idx, this);
wxGetApp().plater()->on_config_change(&cfg);
wxGetApp().plater()->on_config_change(cfg);
}
dialog->Destroy();
});
@ -741,7 +742,8 @@ struct Plater::priv
Sidebar *sidebar;
wxGLCanvas *canvas3D; // TODO: Use GLCanvas3D when we can
Preview *preview;
BackgroundSlicingProcess background_process;
BackgroundSlicingProcess background_process;
wxTimer background_process_timer;
static const std::regex pattern_bundle;
static const std::regex pattern_3mf;
@ -855,15 +857,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
_3DScene::enable_shader(canvas3D, true);
_3DScene::enable_force_zoom_to_bed(canvas3D, true);
// XXX: apply_config_timer
// {
// my $timer_id = Wx::NewId();
// $self->{apply_config_timer} = Wx::Timer->new($self, $timer_id);
// EVT_TIMER($self, $timer_id, sub {
// my ($self, $event) = @_;
// $self->async_apply_config;
// });
// }
background_process_timer.Bind(wxEVT_TIMER, [this](wxTimerEvent &evt){ this->async_apply_config(); }, 0);
auto *bed_shape = config->opt<ConfigOptionPoints>("bed_shape");
_3DScene::set_bed_shape(canvas3D, bed_shape->values);
@ -961,7 +955,7 @@ void Plater::priv::update(bool force_autocenter)
preview->reset_gcode_preview_data();
preview->reload_print();
// schedule_background_process(); // TODO
schedule_background_process();
}
void Plater::priv::update_ui_from_settings()
@ -1172,7 +1166,7 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
_3DScene::zoom_to_volumes(canvas3D);
object_list_changed();
// $self->schedule_background_process;
this->schedule_background_process();
return obj_idxs;
}
@ -1449,12 +1443,40 @@ void Plater::priv::split_object()
void Plater::priv::schedule_background_process()
{
// TODO
// Trigger the timer event after 0.5s
this->background_process_timer.Start(500, wxTIMER_ONE_SHOT);
}
void Plater::priv::async_apply_config()
{
// TODO
// Apply new config to the possibly running background task.
bool was_running = this->background_process.running();
bool invalidated = this->background_process.apply_config(wxGetApp().preset_bundle->full_config());
// Just redraw the 3D canvas without reloading the scene to consume the update of the layer height profile.
if (Slic3r::_3DScene::is_layers_editing_enabled(this->canvas3D))
this->canvas3D->Refresh();
// If the apply_config caused the calculation to stop, or it was not running yet:
if (invalidated) {
if (was_running) {
// Hide the slicing results if the current slicing status is no more valid.
this->sidebar->show_info_sizers(false);
}
if (this->get_config("background_processing") == "1")
this->background_process.start();
if (was_running) {
// 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);
}
}
}
}
void Plater::priv::start_background_process()
@ -1542,8 +1564,7 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
// Synchronize config.ini with the current selections.
wxGetApp().preset_bundle->export_selections(*wxGetApp().app_config);
// update plater with new config
auto config = wxGetApp().preset_bundle->full_config();
wxGetApp().plater()->on_config_change(&config);
wxGetApp().plater()->on_config_change(wxGetApp().preset_bundle->full_config());
}
void Plater::priv::on_progress_event()
@ -1677,7 +1698,8 @@ void Plater::priv::on_scale_uniformly(SimpleEvent&)
// $self->selection_changed(1); # refresh info (size, volume etc.)
// $self->update;
// $self->schedule_background_process;
this->schedule_background_process();
}
void Plater::priv::on_wipetower_moved(Vec3dEvent &evt)
@ -1756,7 +1778,7 @@ void Plater::increase(size_t num)
p->selection_changed();
// $self->schedule_background_process;
this->p->schedule_background_process();
}
void Plater::decrease(size_t num)
@ -1933,11 +1955,11 @@ void Plater::on_extruders_change(int num_extruders)
GetParent()->Layout();
}
void Plater::on_config_change(DynamicPrintConfig* config)
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());
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 (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);
@ -1948,7 +1970,7 @@ void Plater::on_config_change(DynamicPrintConfig* config)
update_scheduled = true;
}
// else if(opt_key == "serial_port") {
// sidebar()->p->btn_print->Show(config->get("serial_port")); // ???: btn_print is removed
// sidebar()->p->btn_print->Show(config.get("serial_port")); // ???: btn_print is removed
// Layout();
// }
else if (opt_key == "print_host") {
@ -1982,10 +2004,8 @@ void Plater::on_config_change(DynamicPrintConfig* config)
if (update_scheduled)
update();
if (!p->main_frame->is_loaded()) return ;
// (re)start timer
// schedule_background_process();
if (p->main_frame->is_loaded())
this->p->schedule_background_process();
}
wxGLCanvas* Plater::canvas3D()
@ -2012,7 +2032,7 @@ void Plater::changed_object_settings(int obj_idx)
if (list->is_parts_changed() || list->is_part_settings_changed()) {
// stop_background_process();
// $self->{print}->reload_object($obj_idx);
// schedule_background_process();
this->p->schedule_background_process();
#if !ENABLE_EXTENDED_SELECTION
if (p->canvas3D) _3DScene::reload_scene(p->canvas3D, true);
auto selections = p->collect_selections();
@ -2021,7 +2041,7 @@ void Plater::changed_object_settings(int obj_idx)
_3DScene::reload_scene(p->canvas3D, false);
}
else {
// schedule_background_process();
this->p->schedule_background_process();
}
}

View file

@ -123,7 +123,7 @@ public:
void send_gcode();
void on_extruders_change(int extruders_count);
void on_config_change(DynamicPrintConfig* config);
void on_config_change(const DynamicPrintConfig &config);
wxGLCanvas* canvas3D();
private: