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;
{
#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");
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");
@ -261,11 +261,14 @@ void MainFrame::init_menubar()
fileMenu->AppendSeparator();
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");
import_menu->AppendSeparator();
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");
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")),
[this](wxCommandEvent&) { load_configbundle(); }, "lorry_add.png");
append_submenu(fileMenu, import_menu, wxID_ANY, _(L("Import")), _(L("")));
@ -332,11 +335,13 @@ void MainFrame::init_menubar()
[this](wxCommandEvent&) { Close(false); } );
#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(can_save()); }, item_save_as->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(can_export_model()); }, item_export_stl->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); }, item_open->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((m_plater != nullptr) && can_save()); }, item_save_as->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((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
}

View file

@ -909,7 +909,11 @@ struct Plater::priv
std::string get_config(const std::string &key) const;
BoundingBoxf 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);
#endif // ENABLE_NEW_MENU_LAYOUT
std::vector<size_t> load_model_objects(const ModelObjectPtrs &model_objects);
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();
}
#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)
#endif // ENABLE_NEW_MENU_LAYOUT
{
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);
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();
#endif // ENABLE_NEW_MENU_LAYOUT
std::vector<size_t> obj_idxs;
for (size_t i = 0; i < input_files.size(); i++) {
@ -1215,7 +1227,11 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
{
DynamicPrintConfig config_loaded;
model = Slic3r::Model::read_from_archive(path.string(), &config_loaded, false);
if (! config_loaded.empty()) {
#if ENABLE_NEW_MENU_LAYOUT
if (load_config && !config_loaded.empty()) {
#else
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 ?
@ -1225,13 +1241,21 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
config += std::move(config_loaded);
}
}
if (! config.empty()) {
#if ENABLE_NEW_MENU_LAYOUT
if (load_config)
{
#endif // ENABLE_NEW_MENU_LAYOUT
if (!config.empty()) {
Preset::normalize(config);
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());
} else {
#if ENABLE_NEW_MENU_LAYOUT
}
#endif // ENABLE_NEW_MENU_LAYOUT
}
else {
model = Slic3r::Model::read_from_file(path.string(), nullptr, false);
for (auto obj : model.objects)
if (obj->name.empty())
@ -1243,6 +1267,10 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
continue;
}
#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()) {
@ -1272,6 +1300,9 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path> &input_
new_model->add_object(*model_object);
}
}
#if ENABLE_NEW_MENU_LAYOUT
}
#endif // ENABLE_NEW_MENU_LAYOUT
}
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());
}
#if ENABLE_NEW_MENU_LAYOUT
if (load_model)
{
#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;
}
@ -2160,10 +2198,33 @@ void Plater::add()
for (const auto &file : input_files) {
input_paths.push_back(file.wx_str());
}
#if ENABLE_NEW_MENU_LAYOUT
load_files(input_paths, true, false);
#else
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); }
#endif // ENABLE_NEW_MENU_LAYOUT
void Plater::update(bool force_autocenter) { p->update(force_autocenter); }

View file

@ -114,11 +114,16 @@ public:
#if ENABLE_NEW_MENU_LAYOUT
void load_project();
void add_model();
void extract_config_from_project();
#else
void add();
#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);
#endif // ENABLE_NEW_MENU_LAYOUT
void update(bool force_autocenter = false);
void select_view(const std::string& direction);