Extract only model or only config from 3mf

This commit is contained in:
Enrico Turri 2018-11-16 09:26:41 +01:00
parent 6bf9ff713d
commit 21202b55b2
3 changed files with 114 additions and 43 deletions

View file

@ -251,7 +251,7 @@ void MainFrame::init_menubar()
wxMenu* fileMenu = new wxMenu; wxMenu* fileMenu = new wxMenu;
{ {
#if ENABLE_NEW_MENU_LAYOUT #if ENABLE_NEW_MENU_LAYOUT
append_menu_item(fileMenu, wxID_ANY, _(L("Open…\tCtrl+O")), _(L("Open a project file")), wxMenuItem* item_open = append_menu_item(fileMenu, wxID_ANY, _(L("Open…\tCtrl+O")), _(L("Open a project file")),
[this](wxCommandEvent&) { if (m_plater) m_plater->load_project(); }, "brick_add.png"); [this](wxCommandEvent&) { if (m_plater) m_plater->load_project(); }, "brick_add.png");
wxMenuItem* item_save = append_menu_item(fileMenu, wxID_ANY, _(L("Save\tCtrl+S")), _(L("Save current project file")), wxMenuItem* item_save = append_menu_item(fileMenu, wxID_ANY, _(L("Save\tCtrl+S")), _(L("Save current project file")),
[this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(m_plater->get_project_filename().wx_str()); }, "disk.png"); [this](wxCommandEvent&) { if (m_plater) m_plater->export_3mf(m_plater->get_project_filename().wx_str()); }, "disk.png");
@ -261,11 +261,14 @@ void MainFrame::init_menubar()
fileMenu->AppendSeparator(); fileMenu->AppendSeparator();
wxMenu* import_menu = new wxMenu(); wxMenu* import_menu = new wxMenu();
append_menu_item(import_menu, wxID_ANY, _(L("Import STL/OBJ/AMF/3MF…\tCtrl+I")), _(L("Load a model")), wxMenuItem* item_import_model = append_menu_item(import_menu, wxID_ANY, _(L("Import STL/OBJ/AMF/3MF…\tCtrl+I")), _(L("Load a model")),
[this](wxCommandEvent&) { if (m_plater) m_plater->add_model(); }, "brick_add.png"); [this](wxCommandEvent&) { if (m_plater) m_plater->add_model(); }, "brick_add.png");
import_menu->AppendSeparator(); import_menu->AppendSeparator();
append_menu_item(import_menu, wxID_ANY, _(L("Import Config…\tCtrl+L")), _(L("Load exported configuration file")), append_menu_item(import_menu, wxID_ANY, _(L("Import Config…\tCtrl+L")), _(L("Load exported configuration file")),
[this](wxCommandEvent&) { load_config_file(); }, "plugin_add.png"); [this](wxCommandEvent&) { load_config_file(); }, "plugin_add.png");
append_menu_item(import_menu, wxID_ANY, _(L("Import Config from project…\tCtrl+Alt+L")), _(L("Load configuration from project file")),
[this](wxCommandEvent&) { if (m_plater) m_plater->extract_config_from_project(); }, "plugin_add.png");
import_menu->AppendSeparator();
append_menu_item(import_menu, wxID_ANY, _(L("Import Config Bundle…")), _(L("Load presets from a bundle")), append_menu_item(import_menu, wxID_ANY, _(L("Import Config Bundle…")), _(L("Load presets from a bundle")),
[this](wxCommandEvent&) { load_configbundle(); }, "lorry_add.png"); [this](wxCommandEvent&) { load_configbundle(); }, "lorry_add.png");
append_submenu(fileMenu, import_menu, wxID_ANY, _(L("Import")), _(L(""))); append_submenu(fileMenu, import_menu, wxID_ANY, _(L("Import")), _(L("")));
@ -332,11 +335,13 @@ void MainFrame::init_menubar()
[this](wxCommandEvent&) { Close(false); } ); [this](wxCommandEvent&) { Close(false); } );
#if ENABLE_NEW_MENU_LAYOUT #if ENABLE_NEW_MENU_LAYOUT
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_save()); }, item_save->GetId()); Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(m_plater != nullptr); }, item_open->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_save()); }, item_save_as->GetId()); Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_save()); }, item_save->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_export_gcode()); }, item_export_gcode->GetId()); Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_save()); }, item_save_as->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_export_model()); }, item_export_stl->GetId()); Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(m_plater != nullptr); }, item_import_model->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_export_model()); }, item_export_amf->GetId()); Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_export_gcode()); }, item_export_gcode->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_export_model()); }, item_export_stl->GetId());
Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable((m_plater != nullptr) && can_export_model()); }, item_export_amf->GetId());
#endif // ENABLE_NEW_MENU_LAYOUT #endif // ENABLE_NEW_MENU_LAYOUT
} }

View file

@ -909,7 +909,11 @@ struct Plater::priv
std::string get_config(const std::string &key) const; std::string get_config(const std::string &key) const;
BoundingBoxf bed_shape_bb() const; BoundingBoxf bed_shape_bb() const;
BoundingBox scaled_bed_shape_bb() const; BoundingBox scaled_bed_shape_bb() const;
#if ENABLE_NEW_MENU_LAYOUT
std::vector<size_t> load_files(const std::vector<fs::path>& input_files, bool load_model, bool load_config);
#else
std::vector<size_t> load_files(const std::vector<fs::path> &input_files); std::vector<size_t> load_files(const std::vector<fs::path> &input_files);
#endif // ENABLE_NEW_MENU_LAYOUT
std::vector<size_t> load_model_objects(const ModelObjectPtrs &model_objects); std::vector<size_t> load_model_objects(const ModelObjectPtrs &model_objects);
std::unique_ptr<CheckboxFileDialog> get_export_file(GUI::FileType file_type); std::unique_ptr<CheckboxFileDialog> get_export_file(GUI::FileType file_type);
@ -1176,7 +1180,11 @@ BoundingBox Plater::priv::scaled_bed_shape_bb() const
return bed_shape.bounding_box(); return bed_shape.bounding_box();
} }
#if ENABLE_NEW_MENU_LAYOUT
std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_files, bool load_model, bool load_config)
#else
std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_files) std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_files)
#endif // ENABLE_NEW_MENU_LAYOUT
{ {
if (input_files.empty()) { return std::vector<size_t>(); } if (input_files.empty()) { return std::vector<size_t>(); }
@ -1196,7 +1204,11 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
wxProgressDialog dlg(loading, loading); wxProgressDialog dlg(loading, loading);
dlg.Pulse(); dlg.Pulse();
#if ENABLE_NEW_MENU_LAYOUT
auto *new_model = (!load_model || one_by_one) ? nullptr : new Slic3r::Model();
#else
auto *new_model = one_by_one ? nullptr : new Slic3r::Model(); auto *new_model = one_by_one ? nullptr : new Slic3r::Model();
#endif // ENABLE_NEW_MENU_LAYOUT
std::vector<size_t> obj_idxs; std::vector<size_t> obj_idxs;
for (size_t i = 0; i < input_files.size(); i++) { for (size_t i = 0; i < input_files.size(); i++) {
@ -1215,23 +1227,35 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
{ {
DynamicPrintConfig config_loaded; DynamicPrintConfig config_loaded;
model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, false); model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, false);
if (! config_loaded.empty()) { #if ENABLE_NEW_MENU_LAYOUT
// Based on the printer technology field found in the loaded config, select the base for the config, if (load_config && !config_loaded.empty()) {
PrinterTechnology printer_technology = Preset::printer_technology(config_loaded); #else
config.apply(printer_technology == ptFFF ? if (!config_loaded.empty()) {
#endif // ENABLE_NEW_MENU_LAYOUT
// Based on the printer technology field found in the loaded config, select the base for the config,
PrinterTechnology printer_technology = Preset::printer_technology(config_loaded);
config.apply(printer_technology == ptFFF ?
static_cast<const ConfigBase&>(FullPrintConfig::defaults()) : static_cast<const ConfigBase&>(FullPrintConfig::defaults()) :
static_cast<const ConfigBase&>(SLAFullPrintConfig::defaults())); static_cast<const ConfigBase&>(SLAFullPrintConfig::defaults()));
// and place the loaded config over the base. // and place the loaded config over the base.
config += std::move(config_loaded); config += std::move(config_loaded);
} }
} }
if (! config.empty()) { #if ENABLE_NEW_MENU_LAYOUT
Preset::normalize(config); if (load_config)
wxGetApp().preset_bundle->load_config_model(filename.string(), std::move(config)); {
wxGetApp().load_current_presets(); #endif // ENABLE_NEW_MENU_LAYOUT
} if (!config.empty()) {
wxGetApp().app_config->update_config_dir(path.parent_path().string()); Preset::normalize(config);
} else { wxGetApp().preset_bundle->load_config_model(filename.string(), std::move(config));
wxGetApp().load_current_presets();
}
wxGetApp().app_config->update_config_dir(path.parent_path().string());
#if ENABLE_NEW_MENU_LAYOUT
}
#endif // ENABLE_NEW_MENU_LAYOUT
}
else {
model = Slic3r::Model::read_from_file(path.string(), nullptr, false); model = Slic3r::Model::read_from_file(path.string(), nullptr, false);
for (auto obj : model.objects) for (auto obj : model.objects)
if (obj->name.empty()) if (obj->name.empty())
@ -1243,35 +1267,42 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
continue; continue;
} }
// The model should now be initialized #if ENABLE_NEW_MENU_LAYOUT
if (load_model)
{
#endif // ENABLE_NEW_MENU_LAYOUT
// The model should now be initialized
if (model.looks_like_multipart_object()) { if (model.looks_like_multipart_object()) {
wxMessageDialog dlg(q, _(L( wxMessageDialog dlg(q, _(L(
"This file contains several objects positioned at multiple heights. " "This file contains several objects positioned at multiple heights. "
"Instead of considering them as multiple objects, should I consider\n" "Instead of considering them as multiple objects, should I consider\n"
"this file as a single object having multiple parts?\n" "this file as a single object having multiple parts?\n"
)), _(L("Multi-part object detected")), wxICON_WARNING | wxYES | wxNO); )), _(L("Multi-part object detected")), wxICON_WARNING | wxYES | wxNO);
if (dlg.ShowModal() == wxID_YES) { if (dlg.ShowModal() == wxID_YES) {
model.convert_multipart_object(nozzle_dmrs->values.size()); model.convert_multipart_object(nozzle_dmrs->values.size());
}
} }
}
if (type_3mf) { if (type_3mf) {
for (ModelObject* model_object : model.objects) { for (ModelObject* model_object : model.objects) {
model_object->center_around_origin(); model_object->center_around_origin();
model_object->ensure_on_bed(); model_object->ensure_on_bed();
}
} }
}
if (one_by_one) { if (one_by_one) {
auto loaded_idxs = load_model_objects(model.objects); auto loaded_idxs = load_model_objects(model.objects);
obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end()); obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end());
} else { } else {
// This must be an .stl or .obj file, which may contain a maximum of one volume. // This must be an .stl or .obj file, which may contain a maximum of one volume.
for (const ModelObject* model_object : model.objects) { for (const ModelObject* model_object : model.objects) {
new_model->add_object(*model_object); new_model->add_object(*model_object);
}
} }
#if ENABLE_NEW_MENU_LAYOUT
} }
#endif // ENABLE_NEW_MENU_LAYOUT
} }
if (new_model != nullptr) { if (new_model != nullptr) {
@ -1288,9 +1319,16 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end()); obj_idxs.insert(obj_idxs.end(), loaded_idxs.begin(), loaded_idxs.end());
} }
wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().string()); #if ENABLE_NEW_MENU_LAYOUT
// XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames... if (load_model)
statusbar()->set_status_text(_(L("Loaded"))); {
#endif // ENABLE_NEW_MENU_LAYOUT
wxGetApp().app_config->update_skein_dir(input_files[input_files.size() - 1].parent_path().string());
// XXX: Plater.pm had @loaded_files, but didn't seem to fill them with the filenames...
statusbar()->set_status_text(_(L("Loaded")));
#if ENABLE_NEW_MENU_LAYOUT
}
#endif // ENABLE_NEW_MENU_LAYOUT
return obj_idxs; return obj_idxs;
} }
@ -2160,10 +2198,33 @@ void Plater::add()
for (const auto &file : input_files) { for (const auto &file : input_files) {
input_paths.push_back(file.wx_str()); input_paths.push_back(file.wx_str());
} }
#if ENABLE_NEW_MENU_LAYOUT
load_files(input_paths, true, false);
#else
load_files(input_paths); load_files(input_paths);
#endif // ENABLE_NEW_MENU_LAYOUT
} }
#if ENABLE_NEW_MENU_LAYOUT
void Plater::extract_config_from_project()
{
wxString input_file;
wxGetApp().load_project(this, input_file);
if (input_file.empty())
return;
std::vector<fs::path> input_paths;
input_paths.push_back(input_file.wx_str());
load_files(input_paths, false, true);
}
#endif // ENABLE_NEW_MENU_LAYOUT
#if ENABLE_NEW_MENU_LAYOUT
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); }
#else
void Plater::load_files(const std::vector<fs::path> &input_files) { p->load_files(input_files); } void Plater::load_files(const std::vector<fs::path> &input_files) { p->load_files(input_files); }
#endif // ENABLE_NEW_MENU_LAYOUT
void Plater::update(bool force_autocenter) { p->update(force_autocenter); } void Plater::update(bool force_autocenter) { p->update(force_autocenter); }

View file

@ -114,11 +114,16 @@ public:
#if ENABLE_NEW_MENU_LAYOUT #if ENABLE_NEW_MENU_LAYOUT
void load_project(); void load_project();
void add_model(); void add_model();
void extract_config_from_project();
#else #else
void add(); void add();
#endif // ENABLE_NEW_MENU_LAYOUT #endif // ENABLE_NEW_MENU_LAYOUT
#if ENABLE_NEW_MENU_LAYOUT
void load_files(const std::vector<boost::filesystem::path>& input_files, bool load_model = true, bool load_config = true);
#else
void load_files(const std::vector<boost::filesystem::path> &input_files); void load_files(const std::vector<boost::filesystem::path> &input_files);
#endif // ENABLE_NEW_MENU_LAYOUT
void update(bool force_autocenter = false); void update(bool force_autocenter = false);
void select_view(const std::string& direction); void select_view(const std::string& direction);