Fixed a bug in the Win32 start wrapper (wrong number of parameters was passed for the GUI slic3r.exe).

Reworked command line processing for the GUI slic3r. Now the config is loaded first, then the model files (also the configs from AMF/3MF are applied), and lastly the free standing parameters are applied.
Fixed unescaping for command line parameters. The string parameters are now not unescaped, string vector parameters are unescaped only if enquoted.
Tab::load_current_preset() - disabled CallAfter for predictability. With CallAfter, it was difficult to call the method in sequence with other methods.
Fixed some missing ->Destroy() calls on dialogs created from MainFrame
Fixed some compiler warnings.
This commit is contained in:
bubnikv 2019-01-09 10:43:17 +01:00
parent 094e3cb565
commit 5b1c1d5922
11 changed files with 194 additions and 92 deletions

View file

@ -10,6 +10,8 @@
#include <wx/glcanvas.h>
#include <wx/debug.h>
#include <boost/algorithm/string/predicate.hpp>
#include "libslic3r/Print.hpp"
#include "libslic3r/Polygon.hpp"
@ -635,28 +637,34 @@ void MainFrame::export_config()
}
// Load a config file containing a Print, Filament & Printer preset.
void MainFrame::load_config_file(wxString file/* = wxEmptyString*/)
void MainFrame::load_config_file()
{
if (file.IsEmpty()) {
if (!wxGetApp().check_unsaved_changes())
return;
auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")),
!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
"config.ini", "INI files (*.ini, *.gcode)|*.ini;*.INI;*.gcode;*.g", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dlg->ShowModal() != wxID_OK)
return;
file = dlg->GetPath();
dlg->Destroy();
if (!wxGetApp().check_unsaved_changes())
return;
auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")),
!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
"config.ini", "INI files (*.ini, *.gcode)|*.ini;*.INI;*.gcode;*.g", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
wxString file;
if (dlg->ShowModal() == wxID_OK)
file = dlg->GetPath();
dlg->Destroy();
if (! file.IsEmpty() && this->load_config_file(file.ToUTF8().data())) {
wxGetApp().app_config->update_config_dir(get_dir_name(file));
m_last_config = file;
}
}
// Load a config file containing a Print, Filament & Printer preset from command line.
bool MainFrame::load_config_file(const std::string &path)
{
try {
wxGetApp().preset_bundle->load_config_file(file.ToUTF8().data());
wxGetApp().preset_bundle->load_config_file(path);
} catch (const std::exception &ex) {
show_error(this, ex.what());
return;
return false;
}
wxGetApp().load_current_presets();
wxGetApp().app_config->update_config_dir(get_dir_name(file));
m_last_config = file;
wxGetApp().load_current_presets();
return true;
}
void MainFrame::export_configbundle()
@ -700,11 +708,13 @@ void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool re
auto dlg = new wxFileDialog(this, _(L("Select configuration to load:")),
!m_last_config.IsEmpty() ? get_dir_name(m_last_config) : wxGetApp().app_config->get_last_dir(),
"config.ini", file_wildcards(FT_INI), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
if (dlg->ShowModal() != wxID_OK)
return;
if (dlg->ShowModal() != wxID_OK) {
dlg->Destroy();
return;
}
file = dlg->GetPath();
dlg->Destroy();
}
dlg->Destroy();
}
wxGetApp().app_config->update_config_dir(get_dir_name(file));
@ -727,10 +737,37 @@ void MainFrame::load_configbundle(wxString file/* = wxEmptyString, const bool re
// Also update the platter with the new presets.
void MainFrame::load_config(const DynamicPrintConfig& config)
{
for (auto tab : wxGetApp().tabs_list)
tab->load_config(config);
if (m_plater)
PrinterTechnology printer_technology = wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology();
const auto *opt_printer_technology = config.option<ConfigOptionEnum<PrinterTechnology>>("printer_technology");
if (opt_printer_technology != nullptr && opt_printer_technology->value != printer_technology) {
printer_technology = opt_printer_technology->value;
this->plater()->set_printer_technology(printer_technology);
}
#if 0
for (auto tab : wxGetApp().tabs_list)
if (tab->supports_printer_technology(printer_technology)) {
if (tab->name() == "printer")
static_cast<TabPrinter*>(tab)->update_pages();
tab->load_config(config);
}
if (m_plater)
m_plater->on_config_change(config);
#else
// Load the currently selected preset into the GUI, update the preset selection box.
//FIXME this is not quite safe for multi-extruder printers,
// as the number of extruders is not adjusted for the vector values.
// (see PresetBundle::update_multi_material_filament_presets())
// Better to call PresetBundle::load_config() instead?
for (auto tab : wxGetApp().tabs_list)
if (tab->supports_printer_technology(printer_technology)) {
// Only apply keys, which are present in the tab's config. Ignore the other keys.
for (const std::string &opt_key : tab->get_config()->diff(config))
// Ignore print_settings_id, printer_settings_id, filament_settings_id etc.
if (! boost::algorithm::ends_with(opt_key, "_settings_id"))
tab->get_config()->option(opt_key)->set(config.option(opt_key));
}
wxGetApp().load_current_presets();
#endif
}
void MainFrame::select_tab(size_t tab) const
@ -806,14 +843,14 @@ void MainFrame::update_ui_from_settings()
tab->update_ui_from_settings();
}
std::string MainFrame::get_base_name(const wxString full_name) const
std::string MainFrame::get_base_name(const wxString &full_name) const
{
return boost::filesystem::path(full_name).filename().string();
return boost::filesystem::path(full_name.wx_str()).filename().string();
}
std::string MainFrame::get_dir_name(const wxString full_name) const
std::string MainFrame::get_dir_name(const wxString &full_name) const
{
return boost::filesystem::path(full_name).parent_path().string();
return boost::filesystem::path(full_name.wx_str()).parent_path().string();
}

View file

@ -53,8 +53,8 @@ class MainFrame : public wxFrame
PrintHostQueueDialog *m_printhost_queue_dlg;
std::string get_base_name(const wxString full_name) const ;
std::string get_dir_name(const wxString full_name) const ;
std::string get_base_name(const wxString &full_name) const;
std::string get_dir_name(const wxString &full_name) const;
void on_presets_changed(SimpleEvent&);
void on_value_changed(wxCommandEvent&);
@ -86,7 +86,10 @@ public:
void reslice_now();
void repair_stl();
void export_config();
void load_config_file(wxString file = wxEmptyString);
// Query user for the config file and open it.
void load_config_file();
// Open a config file. Return true if loaded.
bool load_config_file(const std::string &path);
void export_configbundle();
void load_configbundle(wxString file = wxEmptyString);
void load_config(const DynamicPrintConfig& config);

View file

@ -2594,6 +2594,16 @@ void Plater::extract_config_from_project()
void Plater::load_files(const std::vector<fs::path>& input_files, bool load_model, bool load_config) { p->load_files(input_files, load_model, load_config); }
// To be called when providing a list of files to the GUI slic3r on command line.
void Plater::load_files(const std::vector<std::string>& input_files, bool load_model, bool load_config)
{
std::vector<fs::path> paths;
paths.reserve(input_files.size());
for (const std::string &path : input_files)
paths.emplace_back(path);
p->load_files(paths, load_model, load_config);
}
void Plater::update() { p->update(); }
void Plater::update_ui_from_settings() { p->update_ui_from_settings(); }

View file

@ -116,6 +116,8 @@ public:
void extract_config_from_project();
void load_files(const std::vector<boost::filesystem::path>& input_files, bool load_model = true, bool load_config = true);
// To be called when providing a list of files to the GUI slic3r on command line.
void load_files(const std::vector<std::string>& input_files, bool load_model = true, bool load_config = true);
void update();
void select_view(const std::string& direction);

View file

@ -2283,7 +2283,7 @@ void TabPrinter::update_sla()
// Initialize the UI from the current preset
void Tab::load_current_preset()
{
auto preset = m_presets->get_edited_preset();
const Preset& preset = m_presets->get_edited_preset();
(preset.is_default || preset.is_system) ? m_btn_delete_preset->Disable() : m_btn_delete_preset->Enable(true);
@ -2302,11 +2302,14 @@ void Tab::load_current_preset()
m_undo_to_sys_btn->Enable(!preset.is_default);
#if 0
// use CallAfter because some field triggers schedule on_change calls using CallAfter,
// and we don't want them to be called after this update_dirty() as they would mark the
// preset dirty again
// (not sure this is true anymore now that update_dirty is idempotent)
wxTheApp->CallAfter([this]{
wxTheApp->CallAfter([this]
#endif
{
// checking out if this Tab exists till this moment
if (!wxGetApp().checked_tab(this))
return;
@ -2354,7 +2357,10 @@ void Tab::load_current_preset()
init_options_list();
update_visibility();
update_changed_ui();
});
}
#if 0
);
#endif
}
//Regerenerate content of the page tree.
@ -2428,7 +2434,6 @@ void Tab::select_preset(std::string preset_name)
bool print_tab = m_presets->type() == Preset::TYPE_PRINT || m_presets->type() == Preset::TYPE_SLA_PRINT;
bool printer_tab = m_presets->type() == Preset::TYPE_PRINTER;
bool canceled = false;
// m_reload_dependent_tabs = {};
m_dependent_tabs = {};
if (current_dirty && !may_discard_current_dirty_preset()) {
canceled = true;

View file

@ -185,7 +185,6 @@ protected:
bool m_disable_tree_sel_changed_event;
bool m_show_incompatible_presets;
std::vector<std::string> m_reload_dependent_tabs = {};
std::vector<Preset::Type> m_dependent_tabs = {};
enum OptStatus { osSystemValue = 1, osInitValue = 2 };
std::map<std::string, int> m_options_list;
@ -265,7 +264,6 @@ public:
DynamicPrintConfig* get_config() { return m_config; }
PresetCollection* get_presets() { return m_presets; }
std::vector<std::string> get_dependent_tabs() { return m_reload_dependent_tabs; }
size_t get_selected_preset_item() { return m_selected_preset_item; }
void on_value_change(const std::string& opt_key, const boost::any& value);