diff --git a/src/OrcaSlicer.cpp b/src/OrcaSlicer.cpp index 7cd84babe0..32b02f8faf 100644 --- a/src/OrcaSlicer.cpp +++ b/src/OrcaSlicer.cpp @@ -1386,7 +1386,7 @@ int CLI::run(int argc, char **argv) // BBS: adjust whebackup //LoadStrategy strategy = LoadStrategy::LoadModel | LoadStrategy::LoadConfig|LoadStrategy::AddDefaultInstances; //if (load_aux) strategy = strategy | LoadStrategy::LoadAuxiliary; - model = Model::read_from_file(file, &config, &config_substitutions, strategy, &plate_data_src, &project_presets, &is_bbl_3mf, &file_version, nullptr, nullptr, nullptr, nullptr, nullptr, plate_to_slice); + model = Model::read_from_file(file, &config, &config_substitutions, strategy, &plate_data_src, &project_presets, &is_bbl_3mf, &file_version, nullptr, nullptr, nullptr, plate_to_slice); if (is_bbl_3mf) { if (!first_file) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 51676fae0a..c8aa08be6b 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -409,6 +409,14 @@ void AppConfig::set_defaults() set_str("print", "timelapse", "1"); } + if (get("enable_step_mesh_setting").empty()) { + set_bool("enable_step_mesh_setting", true); + } + if (get("linear_defletion", "angle_defletion").empty()) { + set("linear_defletion", "0.003"); + set("angle_defletion", "0.5"); + } + // Remove legacy window positions/sizes erase("app", "main_frame_maximized"); erase("app", "main_frame_pos"); diff --git a/src/libslic3r/GCode/CoolingBuffer.hpp b/src/libslic3r/GCode/CoolingBuffer.hpp index dcbf0120b8..fba27b289b 100644 --- a/src/libslic3r/GCode/CoolingBuffer.hpp +++ b/src/libslic3r/GCode/CoolingBuffer.hpp @@ -4,6 +4,7 @@ #include "../libslic3r.h" #include #include +#include namespace Slic3r { diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 066eaeda98..be27f7c704 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -177,18 +177,67 @@ Model::~Model() Slic3r::remove_backup(*this, true); } +Model Model::read_from_step(const std::string& input_file, + LoadStrategy options, + ImportStepProgressFn stepFn, + StepIsUtf8Fn stepIsUtf8Fn, + std::function step_mesh_fn, + double linear_defletion, + double angle_defletion) +{ + Model model; + bool result = false; + bool is_cb_cancel = false; + std::string message; + Step step_file(input_file); + step_file.load(); + if (step_mesh_fn) { + if (step_mesh_fn(step_file, linear_defletion, angle_defletion) == -1) { + Model empty_model; + return empty_model; + } + } + result = load_step(input_file.c_str(), &model, is_cb_cancel, linear_defletion, angle_defletion, stepFn, stepIsUtf8Fn); + if (is_cb_cancel) { + Model empty_model; + return empty_model; + } + + if (!result) { + if (message.empty()) + throw Slic3r::RuntimeError(_L("Loading of a model file failed.")); + else + throw Slic3r::RuntimeError(message); + } + + if (model.objects.empty()) + throw Slic3r::RuntimeError(_L("The supplied file couldn't be read because it's empty")); + + for (ModelObject *o : model.objects) + o->input_file = input_file; + + if (options & LoadStrategy::AddDefaultInstances) + model.add_default_instances(); + + return model; +} + // BBS: add part plate related logic // BBS: backup & restore // Loading model from a file, it may be a simple geometry file as STL or OBJ, however it may be a project file as well. -Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* config, ConfigSubstitutionContext* config_substitutions, - LoadStrategy options, PlateDataPtrs* plate_data, std::vector* project_presets, bool *is_xxx, Semver* file_version, Import3mfProgressFn proFn, - ImportstlProgressFn stlFn, - ImportStepProgressFn stepFn, - StepIsUtf8Fn stepIsUtf8Fn, - BBLProject * project, - int plate_id, - ObjImportColorFn objFn, - std::function step_mesh_fn) +Model Model::read_from_file(const std::string& input_file, + DynamicPrintConfig* config, + ConfigSubstitutionContext* config_substitutions, + LoadStrategy options, + PlateDataPtrs* plate_data, + std::vector* project_presets, + bool *is_xxx, + Semver* file_version, + Import3mfProgressFn proFn, + ImportstlProgressFn stlFn, + BBLProject * project, + int plate_id, + ObjImportColorFn objFn) { Model model; @@ -212,20 +261,7 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c bool result = false; bool is_cb_cancel = false; std::string message; - if (boost::algorithm::iends_with(input_file, ".stp") || - boost::algorithm::iends_with(input_file, ".step")) { - double linear_defletion = 0.003; - double angle_defletion = 0.5; - Step step_file(input_file); - step_file.load(); - if (step_mesh_fn) { - if (step_mesh_fn(step_file, linear_defletion, angle_defletion) == -1) { - Model empty_model; - return empty_model; - } - } - result = load_step(input_file.c_str(), &model, is_cb_cancel, linear_defletion, angle_defletion, stepFn, stepIsUtf8Fn); - } else if (boost::algorithm::iends_with(input_file, ".stl")) + if (boost::algorithm::iends_with(input_file, ".stl")) result = load_stl(input_file.c_str(), &model, nullptr, stlFn); else if (boost::algorithm::iends_with(input_file, ".oltp")) result = load_stl(input_file.c_str(), &model, nullptr, stlFn,256); diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 9170b2e40d..1e45f6bb7d 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -6,6 +6,7 @@ #include "Geometry.hpp" #include "ObjectID.hpp" #include "Point.hpp" +#include "AppConfig.hpp" #include "PrintConfig.hpp" #include "Slicing.hpp" #include "SLA/SupportPoint.hpp" @@ -1530,6 +1531,14 @@ public: OBJECTBASE_DERIVED_COPY_MOVE_CLONE(Model) + static Model read_from_step(const std::string& input_file, + LoadStrategy options, + ImportStepProgressFn stepFn, + StepIsUtf8Fn stepIsUtf8Fn, + std::function step_mesh_fn, + double linear_defletion, + double angle_defletion); + //BBS: add part plate related logic // BBS: backup //BBS: is_xxx is used for is_bbs_3mf when loading 3mf, is used for is_inches when loading amf @@ -1539,12 +1548,9 @@ public: LoadStrategy options = LoadStrategy::AddDefaultInstances, PlateDataPtrs* plate_data = nullptr, std::vector* project_presets = nullptr, bool* is_xxx = nullptr, Semver* file_version = nullptr, Import3mfProgressFn proFn = nullptr, ImportstlProgressFn stlFn = nullptr, - ImportStepProgressFn stepFn = nullptr, - StepIsUtf8Fn stepIsUtf8Fn = nullptr, BBLProject * project = nullptr, int plate_id = 0, - ObjImportColorFn objFn = nullptr, - std::function step_mesh_fn = nullptr + ObjImportColorFn objFn = nullptr ); // BBS static bool obj_import_vertex_color_deal(const std::vector &vertex_filament_ids, const unsigned char &first_extruder_id, Model *model); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index a5ec5bed3a..904520cba2 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4156,45 +4156,22 @@ std::vector Plater::priv::load_files(const std::vector& input_ filament_ids.clear(); } }; - auto step_mesh = [this, &path, &is_user_cancel](Slic3r::Step& file, double& linear_value, double& angle_value)-> int { - if (boost::iends_with(path.string(), ".step") || - boost::iends_with(path.string(), ".stp")){ - StepMeshDialog mesh_dlg(nullptr, file); - if (mesh_dlg.ShowModal() == wxID_OK) { - linear_value = mesh_dlg.get_linear_defletion(); - angle_value = mesh_dlg.get_angle_defletion(); - return 1; - } - } - is_user_cancel = true; - return -1; - }; - model = Slic3r::Model:: read_from_file( - path.string(), nullptr, nullptr, strategy, &plate_data, &project_presets, &is_xxx, &file_version, nullptr, - [this, &dlg, real_filename, &progress_percent, &file_percent, INPUT_FILES_RATIO, total_files, i, &designer_model_id, &designer_country_code](int current, int total, bool &cancel, std::string &mode_id, std::string &code) - { - designer_model_id = mode_id; - designer_country_code = code; - - bool cont = true; - float percent_float = (100.0f * (float)i / (float)total_files) + INPUT_FILES_RATIO * 100.0f * ((float)current / (float)total) / (float)total_files; - BOOST_LOG_TRIVIAL(trace) << "load_stl_file: percent(float)=" << percent_float << ", curr = " << current << ", total = " << total; - progress_percent = (int)percent_float; - wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); - cont = dlg.Update(progress_percent, msg); - cancel = !cont; - }, - [this, &dlg, real_filename, &progress_percent, &file_percent, step_percent, INPUT_FILES_RATIO, total_files, i](int load_stage, int current, int total, bool &cancel) - { - bool cont = true; - float percent_float = (100.0f * (float)i / (float)total_files) + INPUT_FILES_RATIO * ((float)step_percent[load_stage] + (float)current * (float)(step_percent[load_stage + 1] - step_percent[load_stage]) / (float)total) / (float)total_files; - BOOST_LOG_TRIVIAL(trace) << "load_step_file: percent(float)=" << percent_float << ", stage = " << load_stage << ", curr = " << current << ", total = " << total; - progress_percent = (int)percent_float; - wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); - cont = dlg.Update(progress_percent, msg); - cancel = !cont; - }, - [](int isUtf8StepFile) { + if (boost::algorithm::iends_with(path.string(), ".stp") || + boost::algorithm::iends_with(path.string(), ".step")) { + double linear = std::stod(wxGetApp().app_config->get("linear_defletion")); + double angle = std::stod(wxGetApp().app_config->get("angle_defletion")); + model = Slic3r::Model:: read_from_step(path.string(), strategy, + [this, &dlg, real_filename, &progress_percent, &file_percent, step_percent, INPUT_FILES_RATIO, total_files, i](int load_stage, int current, int total, bool &cancel) + { + bool cont = true; + float percent_float = (100.0f * (float)i / (float)total_files) + INPUT_FILES_RATIO * ((float)step_percent[load_stage] + (float)current * (float)(step_percent[load_stage + 1] - step_percent[load_stage]) / (float)total) / (float)total_files; + BOOST_LOG_TRIVIAL(trace) << "load_step_file: percent(float)=" << percent_float << ", stage = " << load_stage << ", curr = " << current << ", total = " << total; + progress_percent = (int)percent_float; + wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); + cont = dlg.Update(progress_percent, msg); + cancel = !cont; + }, + [](int isUtf8StepFile) { if (!isUtf8StepFile) { const auto no_warn = wxGetApp().app_config->get_bool("step_not_utf8_no_warn"); if (!no_warn) { @@ -4208,8 +4185,40 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } }, - nullptr, 0, obj_color_fun, step_mesh); + [this, &path, &is_user_cancel, &linear, &angle](Slic3r::Step& file, double& linear_value, double& angle_value)-> int { + if (wxGetApp().app_config->get_bool("enable_step_mesh_setting")) { + StepMeshDialog mesh_dlg(nullptr, file); + if (mesh_dlg.ShowModal() == wxID_OK) { + linear_value = mesh_dlg.get_linear_defletion(); + angle_value = mesh_dlg.get_angle_defletion(); + return 1; + } + }else { + linear_value = linear; + angle_value = angle; + return 1; + } + is_user_cancel = true; + return -1; + }, linear, angle); + }else { + model = Slic3r::Model:: read_from_file( + path.string(), nullptr, nullptr, strategy, &plate_data, &project_presets, &is_xxx, &file_version, nullptr, + [this, &dlg, real_filename, &progress_percent, &file_percent, INPUT_FILES_RATIO, total_files, i, &designer_model_id, &designer_country_code](int current, int total, bool &cancel, std::string &mode_id, std::string &code) + { + designer_model_id = mode_id; + designer_country_code = code; + bool cont = true; + float percent_float = (100.0f * (float)i / (float)total_files) + INPUT_FILES_RATIO * 100.0f * ((float)current / (float)total) / (float)total_files; + BOOST_LOG_TRIVIAL(trace) << "load_stl_file: percent(float)=" << percent_float << ", curr = " << current << ", total = " << total; + progress_percent = (int)percent_float; + wxString msg = wxString::Format(_L("Loading file: %s"), from_path(real_filename)); + cont = dlg.Update(progress_percent, msg); + cancel = !cont; + }, + nullptr, 0, obj_color_fun); + } if (designer_model_id.empty() && boost::algorithm::iends_with(path.string(), ".stl")) { read_binary_stl(path.string(), designer_model_id, designer_country_code); @@ -5952,7 +5961,7 @@ void Plater::priv::reload_from_disk() // BBS: backup new_model = Model::read_from_file(path, nullptr, nullptr, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, &plate_data, &project_presets, nullptr, - nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, 0, obj_color_fun); + nullptr, nullptr, nullptr, nullptr, 0, obj_color_fun); for (ModelObject* model_object : new_model.objects) { model_object->center_around_origin(); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 8bc00295bf..77dce6fa74 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -1171,6 +1171,7 @@ wxWindow* PreferencesDialog::create_general_page() auto item_calc_mode = create_item_checkbox(_L("Flushing volumes: Auto-calculate every time the color changed."), page, _L("If enabled, auto-calculate every time the color changed."), 50, "auto_calculate"); auto item_calc_in_long_retract = create_item_checkbox(_L("Flushing volumes: Auto-calculate every time when the filament is changed."), page, _L("If enabled, auto-calculate every time when filament is changed"), 50, "auto_calculate_when_filament_change"); auto item_remember_printer_config = create_item_checkbox(_L("Remember printer configuration"), page, _L("If enabled, Orca will remember and switch filament/process configuration for each printer automatically."), 50, "remember_printer_config"); + auto item_step_mesh_setting = create_item_checkbox(_L("Show the step mesh parameter setting dialog."), page, _L("If enabled,a parameter settings dialog will appear during STEP file import."), 50, "enable_step_mesh_setting"); auto item_multi_machine = create_item_checkbox(_L("Multi-device Management(Take effect after restarting Orca)."), page, _L("With this option enabled, you can send a task to multiple devices at the same time and manage multiple devices."), 50, "enable_multi_machine"); auto item_auto_arrange = create_item_checkbox(_L("Auto arrange plate after cloning"), page, _L("Auto arrange plate after object cloning"), 50, "auto_arrange"); auto title_presets = create_item_title(_L("Presets"), page, _L("Presets")); @@ -1250,6 +1251,7 @@ wxWindow* PreferencesDialog::create_general_page() sizer_page->Add(item_hints, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_calc_in_long_retract, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_multi_machine, 0, wxTOP, FromDIP(3)); + sizer_page->Add(item_step_mesh_setting, 0, wxTOP, FromDIP(3)); sizer_page->Add(item_auto_arrange, 0, wxTOP, FromDIP(3)); sizer_page->Add(title_presets, 0, wxTOP | wxEXPAND, FromDIP(20)); sizer_page->Add(item_calc_mode, 0, wxTOP, FromDIP(3)); diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 96e71cbd25..4963b7d97b 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -229,7 +229,9 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxBoxSizer* bSizer_button = new wxBoxSizer(wxHORIZONTAL); bSizer_button->SetMinSize(wxSize(FromDIP(100), -1)); - + m_checkbox = new wxCheckBox(this, wxID_ANY, _L("Don't show again"), wxDefaultPosition, wxDefaultSize, 0); + bSizer_button->Add(m_checkbox, 0, wxALIGN_LEFT); + bSizer_button->AddStretchSpacer(1); StateColor btn_bg_green(std::pair(wxColour(27, 136, 68), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), std::pair(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal)); m_button_ok = new Button(this, _L("OK")); @@ -246,6 +248,12 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) stop_task(); if (validate_number_range(angle_input->GetTextCtrl()->GetValue(), 0.01, 1) && validate_number_range(linear_input->GetTextCtrl()->GetValue(), 0.001, 0.1)) { + if (m_checkbox->IsChecked()) { + wxGetApp().app_config->set_bool("enable_step_mesh_setting", false); + } + wxGetApp().app_config->set("linear_defletion", std::to_string(get_linear_defletion())); + wxGetApp().app_config->set("angle_defletion", std::to_string(get_angle_defletion())); + EndModal(wxID_OK); } SetFocusIgnoringChildren(); @@ -268,7 +276,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) EndModal(wxID_CANCEL); }); - bSizer->Add(bSizer_button, 0, wxALIGN_RIGHT | wxRIGHT| wxBOTTOM, LEFT_RIGHT_PADING); + bSizer->Add(bSizer_button, 1, wxEXPAND | wxALL, LEFT_RIGHT_PADING); this->SetSizer(bSizer); update_mesh_number_text(); diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index 48bff2adc3..aeab7ffabd 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -2,6 +2,7 @@ #define _STEP_MESH_DIALOG_H_ #include +#include "GUI_App.hpp" #include "GUI_Utils.hpp" #include "libslic3r/Format/STEP.hpp" #include "Widgets/Button.hpp" @@ -12,12 +13,18 @@ class StepMeshDialog : public Slic3r::GUI::DPIDialog public: StepMeshDialog(wxWindow* parent, Slic3r::Step& file); void on_dpi_changed(const wxRect& suggested_rect) override; + inline double get_linear_init() { + return std::stod(Slic3r::GUI::wxGetApp().app_config->get("linear_defletion")); + } + inline double get_angle_init() { + return std::stod(Slic3r::GUI::wxGetApp().app_config->get("angle_defletion")); + } inline double get_linear_defletion() { double value; if (m_linear_last.ToDouble(&value)) { return value; }else { - return 0.003; + return get_linear_init(); } } inline double get_angle_defletion() { @@ -25,15 +32,16 @@ public: if (m_angle_last.ToDouble(&value)) { return value; } else { - return 0.5; + return get_angle_init(); } } private: Slic3r::Step& m_file; Button* m_button_ok = nullptr; Button* m_button_cancel = nullptr; - wxString m_linear_last = wxString::Format("%.3f", 0.003); - wxString m_angle_last = wxString::Format("%.2f", 0.5); + wxCheckBox* m_checkbox = nullptr; + wxString m_linear_last = wxString::Format("%.3f", get_linear_init()); + wxString m_angle_last = wxString::Format("%.2f", get_angle_init()); wxStaticText* mesh_face_number_text; double m_last_linear; double m_last_angle; diff --git a/src/slic3r/Utils/CalibUtils.cpp b/src/slic3r/Utils/CalibUtils.cpp index 0732b99370..bb51427654 100644 --- a/src/slic3r/Utils/CalibUtils.cpp +++ b/src/slic3r/Utils/CalibUtils.cpp @@ -303,7 +303,7 @@ static void read_model_from_file(const std::string& input_file, Model& model) std::vector project_presets; model = Model::read_from_file(input_file, &config, &config_substitutions, strategy, &plate_data_src, &project_presets, - &is_bbl_3mf, &file_version, nullptr, nullptr, nullptr, nullptr, nullptr, plate_to_slice); + &is_bbl_3mf, &file_version, nullptr, nullptr, nullptr, plate_to_slice); model.add_default_instances(); for (auto object : model.objects)