From 61ebddf9b8038b514346970c06208d7d5ba0fd9d Mon Sep 17 00:00:00 2001 From: Mack Date: Mon, 9 Sep 2024 11:52:59 +0800 Subject: [PATCH 01/23] NEW:add step mesh parameters jira: STUDIO-7415 Change-Id: I5e09a1eb1ad31063ad56d08d5738907a804dc112 (cherry picked from commit ccbe9630076b754ab440e98977c4164afff96250) (cherry picked from commit 84e7063c54a99e8a1440e74f831c6d1f6828f3f8) --- src/libslic3r/Format/STEP.cpp | 18 ++- src/libslic3r/Format/STEP.hpp | 8 +- src/libslic3r/Model.cpp | 20 ++- src/libslic3r/Model.hpp | 3 +- src/slic3r/CMakeLists.txt | 2 + src/slic3r/GUI/Plater.cpp | 18 ++- src/slic3r/GUI/StepMeshDialog.cpp | 216 ++++++++++++++++++++++++++++++ src/slic3r/GUI/StepMeshDialog.hpp | 42 ++++++ 8 files changed, 314 insertions(+), 13 deletions(-) create mode 100644 src/slic3r/GUI/StepMeshDialog.cpp create mode 100644 src/slic3r/GUI/StepMeshDialog.hpp diff --git a/src/libslic3r/Format/STEP.cpp b/src/libslic3r/Format/STEP.cpp index 45e938d1b6..283fe63798 100644 --- a/src/libslic3r/Format/STEP.cpp +++ b/src/libslic3r/Format/STEP.cpp @@ -34,9 +34,6 @@ #include "TopExp_Explorer.hxx" #include "BRep_Tool.hxx" -const double STEP_TRANS_CHORD_ERROR = 0.003; -const double STEP_TRANS_ANGLE_RES = 0.5; - namespace Slic3r { @@ -223,7 +220,10 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p } } -bool load_step(const char *path, Model *model, bool& is_cancel, ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn) +bool load_step(const char *path, Model *model, bool& is_cancel, + double linear_defletion/*=0.003*/, + double angle_defletion/*= 0.5*/, + ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn, long& mesh_face_num) { bool cb_cancel = false; if (stepFn) { @@ -278,7 +278,7 @@ bool load_step(const char *path, Model *model, bool& is_cancel, ImportStepProgre stl.resize(namedSolids.size()); tbb::parallel_for(tbb::blocked_range(0, namedSolids.size()), [&](const tbb::blocked_range &range) { for (size_t i = range.begin(); i < range.end(); i++) { - BRepMesh_IncrementalMesh mesh(namedSolids[i].solid, STEP_TRANS_CHORD_ERROR, false, STEP_TRANS_ANGLE_RES, true); + BRepMesh_IncrementalMesh mesh(namedSolids[i].solid, linear_defletion, false, angle_defletion, true); // BBS: calculate total number of the nodes and triangles int aNbNodes = 0; int aNbTriangles = 0; @@ -351,6 +351,14 @@ bool load_step(const char *path, Model *model, bool& is_cancel, ImportStepProgre } }); + if (mesh_face_num != -1) { + for (size_t i = 0; i < stl.size(); i++) { + // Test for overflow + mesh_face_num += stl[i].stats.number_of_facets; + } + return true; + } + ModelObject *new_object = model->add_object(); const char * last_slash = strrchr(path, DIR_SEPARATOR); new_object->name.assign((last_slash == nullptr) ? path : last_slash + 1); diff --git a/src/libslic3r/Format/STEP.hpp b/src/libslic3r/Format/STEP.hpp index b86933a346..72f8327106 100644 --- a/src/libslic3r/Format/STEP.hpp +++ b/src/libslic3r/Format/STEP.hpp @@ -17,7 +17,13 @@ typedef std::function StepIsUtf8Fn; //BBS: Load an step file into a provided model. -extern bool load_step(const char *path, Model *model, bool& is_cancel, ImportStepProgressFn proFn = nullptr, StepIsUtf8Fn isUtf8Fn = nullptr); +extern bool load_step(const char *path, Model *model, + bool& is_cancel, + double linear_defletion = 0.003, + double angle_defletion = 0.5, + ImportStepProgressFn proFn = nullptr, + StepIsUtf8Fn isUtf8Fn = nullptr, + long& mesh_face_num = *(new long(-1))); //BBS: Used to detect what kind of encoded type is used in name field of step // If is encoded in UTF8, the file don't need to be handled, then return the original path directly. diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index a047d1db48..79c424ff79 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -27,6 +27,7 @@ #include "SVG.hpp" #include +#include #include "GCodeWriter.hpp" // BBS: for segment @@ -186,7 +187,8 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c StepIsUtf8Fn stepIsUtf8Fn, BBLProject * project, int plate_id, - ObjImportColorFn objFn) + ObjImportColorFn objFn, + std::function step_mesh_fn) { Model model; @@ -211,9 +213,19 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c bool is_cb_cancel = false; std::string message; if (boost::algorithm::iends_with(input_file, ".stp") || - boost::algorithm::iends_with(input_file, ".step")) - result = load_step(input_file.c_str(), &model, is_cb_cancel, stepFn, stepIsUtf8Fn); - else if (boost::algorithm::iends_with(input_file, ".stl")) + boost::algorithm::iends_with(input_file, ".step")) { + double linear_defletion = 0.003; + double angle_defletion = 0.5; + if (step_mesh_fn) { + if (step_mesh_fn(linear_defletion, angle_defletion) == -1) { + result = false; + goto end; + } + } + result = load_step(input_file.c_str(), &model, is_cb_cancel, linear_defletion, angle_defletion, stepFn, stepIsUtf8Fn); + end: + BOOST_LOG_TRIVIAL(info) << "Cancel step mesh dialog"; + } else 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 f3000d9628..b243bca945 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1543,7 +1543,8 @@ public: StepIsUtf8Fn stepIsUtf8Fn = nullptr, BBLProject * project = nullptr, int plate_id = 0, - ObjImportColorFn objFn = nullptr + ObjImportColorFn objFn = nullptr, + std::function step_mesh_fn = 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/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 1e5ae34510..628aab75b5 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -312,6 +312,8 @@ set(SLIC3R_GUI_SOURCES GUI/RemovableDriveManager.hpp GUI/SendSystemInfoDialog.cpp GUI/SendSystemInfoDialog.hpp + GUI/StepMeshDialog.cpp + GUI/StepMeshDialog.hpp GUI/SurfaceDrag.cpp GUI/SurfaceDrag.hpp GUI/TextLines.cpp diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c0436e7fc1..50fa2bd084 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -151,6 +151,7 @@ #include "DailyTips.hpp" #include "CreatePresetsDialog.hpp" #include "FileArchiveDialog.hpp" +#include "StepMeshDialog.hpp" using boost::optional; namespace fs = boost::filesystem; @@ -4155,7 +4156,20 @@ std::vector Plater::priv::load_files(const std::vector& input_ filament_ids.clear(); } }; - model = Slic3r::Model::read_from_file( + auto step_mesh = [this, &path, &is_user_cancel](double& linear_value, double& angle_value)-> int { + if (boost::iends_with(path.string(), ".step") || + boost::iends_with(path.string(), ".stp")){ + StepMeshDialog mesh_dlg(nullptr, path); + 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 = false; + 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) { @@ -4194,7 +4208,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } }, - nullptr, 0, obj_color_fun); + nullptr, 0, obj_color_fun, step_mesh); if (designer_model_id.empty() && boost::algorithm::iends_with(path.string(), ".stl")) { diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp new file mode 100644 index 0000000000..60d2acde1a --- /dev/null +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -0,0 +1,216 @@ +#include "StepMeshDialog.hpp" +#include "BBLStatusBar.hpp" +#include "I18N.hpp" +#include "GUI_App.hpp" +#include "Widgets/Button.hpp" +#include "MainFrame.hpp" +#include +#include + +using namespace Slic3r; +using namespace Slic3r::GUI; + +static int _scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit() / 10; } +static int _ITEM_WIDTH() { return _scale(30); } +#define MIN_DIALOG_WIDTH FromDIP(400) +#define SLIDER_WIDTH FromDIP(150) +#define TEXT_CTRL_WIDTH FromDIP(40) +#define BUTTON_SIZE wxSize(FromDIP(58), FromDIP(24)) +#define BUTTON_BORDER FromDIP(int(400 - 58 * 2) / 8) +#define SLIDER_SCALE(val) ((val) / 0.001) +#define SLIDER_UNSCALE(val) ((val) * 0.001) +#define SLIDER_SCALE_10(val) ((val) / 0.01) +#define SLIDER_UNSCALE_10(val) ((val) * 0.01) +#define LEFT_RIGHT_PADING FromDIP(20) + +void StepMeshDialog::on_dpi_changed(const wxRect& suggested_rect) { +}; + +bool StepMeshDialog:: validate_number_range(const wxString& value, double min, double max) { + double num; + if (!value.ToDouble(&num)) { + return false; + } + return (num >= min && num <= max); +} + +StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) + : DPIDialog(parent ? parent : static_cast(wxGetApp().mainframe), + wxID_ANY, + _(L("Step file import parameters")), + wxDefaultPosition, + wxDefaultSize, + wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/), m_file(file) +{ + std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") + % Slic3r::resources_dir()).str(); + SetIcon(wxIcon(Slic3r::encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO)); + + SetBackgroundColour(*wxWHITE); + + wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL); + bSizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); + + wxBoxSizer* linear_sizer = new wxBoxSizer(wxHORIZONTAL); + //linear_sizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); + wxStaticText* linear_title = new wxStaticText(this, + wxID_ANY, + _L("Linear Deflection:")); + linear_sizer->Add(linear_title, 0, wxALIGN_LEFT); + linear_sizer->AddStretchSpacer(1); + wxSlider* linear_slider = new wxSlider(this, wxID_ANY, + SLIDER_SCALE(get_linear_defletion()), + 1, 100, wxDefaultPosition, + wxSize(SLIDER_WIDTH, -1), + wxSL_HORIZONTAL); + linear_sizer->Add(linear_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); + wxTextValidator valid_number(wxFILTER_NUMERIC); + wxTextCtrl* linear_textctrl = new wxTextCtrl(this, wxID_ANY, + m_linear_last, + wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), + 0, valid_number); + linear_sizer->Add(linear_textctrl, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); + // textctrl loss focus + linear_textctrl->Bind(wxEVT_KILL_FOCUS, ([this, linear_textctrl](wxFocusEvent& e) { + wxString value = linear_textctrl->GetValue(); + if(!validate_number_range(value, 0.001, 0.1)) { + linear_textctrl->SetValue(m_linear_last); + } + m_linear_last = value; + update_mesh_number_text(); + e.Skip(); + })); + // slider bind textctrl + linear_slider->Bind(wxEVT_SLIDER, ([this, linear_slider, linear_textctrl](wxCommandEvent& e) { + double slider_value = SLIDER_UNSCALE(linear_slider->GetValue()); + linear_textctrl->SetValue(wxString::Format("%.3f", slider_value)); + m_linear_last = wxString::Format("%.3f", slider_value); + update_mesh_number_text(); + })); + // textctrl bind slider + linear_textctrl->Bind(wxEVT_TEXT, ([this, linear_textctrl, linear_slider](wxCommandEvent& e) { + double slider_value_long; + int slider_value; + wxString value = linear_textctrl->GetValue(); + if (value.ToDouble(&slider_value_long)) { + slider_value = SLIDER_SCALE(slider_value_long); + if (slider_value >= linear_slider->GetMin() && slider_value <= linear_slider->GetMax()) { + linear_slider->SetValue(slider_value); + } + } + })); + + bSizer->Add(linear_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING); + + wxBoxSizer* angle_sizer = new wxBoxSizer(wxHORIZONTAL); + wxStaticText* angle_title = new wxStaticText(this, + wxID_ANY, + _L("Angle Deflection:")); + angle_sizer->Add(angle_title, 0, wxALIGN_LEFT); + angle_sizer->AddStretchSpacer(1); + wxSlider* angle_slider = new wxSlider(this, wxID_ANY, + SLIDER_SCALE_10(get_angle_defletion()), + 1, 100, wxDefaultPosition, + wxSize(SLIDER_WIDTH, -1), + wxSL_HORIZONTAL); + angle_sizer->Add(angle_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); + wxTextCtrl* angle_textctrl = new wxTextCtrl(this, wxID_ANY, + m_angle_last, + wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), + 0, valid_number); + angle_sizer->Add(angle_textctrl, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); + // textctrl loss focus + angle_textctrl->Bind(wxEVT_KILL_FOCUS, ([this, angle_textctrl](wxFocusEvent& e) { + wxString value = angle_textctrl->GetValue(); + if (!validate_number_range(value, 0.01, 1)) { + angle_textctrl->SetValue(m_angle_last); + } + m_angle_last = value; + update_mesh_number_text(); + e.Skip(); + })); + // slider bind textctrl + angle_slider->Bind(wxEVT_SLIDER, ([this, angle_slider, angle_textctrl](wxCommandEvent& e) { + double slider_value = SLIDER_UNSCALE_10(angle_slider->GetValue()); + angle_textctrl->SetValue(wxString::Format("%.2f", slider_value)); + m_angle_last = wxString::Format("%.2f", slider_value); + update_mesh_number_text(); + })); + // textctrl bind slider + linear_textctrl->Bind(wxEVT_TEXT, ([this, angle_slider, angle_textctrl](wxCommandEvent& e) { + double slider_value_long; + int slider_value; + wxString value = angle_textctrl->GetValue(); + if (value.ToDouble(&slider_value_long)) { + slider_value = SLIDER_SCALE_10(slider_value_long); + if (slider_value >= angle_slider->GetMin() && slider_value <= angle_slider->GetMax()) { + angle_slider->SetValue(slider_value); + } + } + })); + + bSizer->Add(angle_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); + + + mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("Number of generated surfaces: 0")); + bSizer->Add(mesh_face_number_text, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); + + wxBoxSizer* bSizer_button = new wxBoxSizer(wxHORIZONTAL); + bSizer_button->SetMinSize(wxSize(FromDIP(100), -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")); + m_button_ok->SetBackgroundColor(btn_bg_green); + m_button_ok->SetBorderColor(*wxWHITE); + m_button_ok->SetTextColor(wxColour(0xFFFFFE)); + m_button_ok->SetFont(Label::Body_12); + m_button_ok->SetSize(BUTTON_SIZE); + m_button_ok->SetMinSize(BUTTON_SIZE); + m_button_ok->SetCornerRadius(FromDIP(12)); + bSizer_button->Add(m_button_ok, 0, wxALIGN_RIGHT, BUTTON_BORDER); + + m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { EndModal(wxID_OK); }); + + StateColor btn_bg_white(std::pair(wxColour(206, 206, 206), StateColor::Pressed), std::pair(wxColour(238, 238, 238), StateColor::Hovered), + std::pair(*wxWHITE, StateColor::Normal)); + + m_button_cancel = new Button(this, _L("Cancel")); + m_button_cancel->SetBackgroundColor(btn_bg_white); + m_button_cancel->SetBorderColor(wxColour(38, 46, 48)); + m_button_cancel->SetFont(Label::Body_12); + m_button_cancel->SetSize(BUTTON_SIZE); + m_button_cancel->SetMinSize(BUTTON_SIZE); + m_button_cancel->SetCornerRadius(FromDIP(12)); + bSizer_button->Add(m_button_cancel, 0, wxALIGN_RIGHT | wxLEFT, BUTTON_BORDER); + + m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { EndModal(wxID_CANCEL); }); + + bSizer->Add(bSizer_button, 0, wxALIGN_RIGHT | wxRIGHT| wxBOTTOM, LEFT_RIGHT_PADING); + + this->SetSizer(bSizer); + update_mesh_number_text(); + this->Layout(); + bSizer->Fit(this); + + this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) { }); + + wxGetApp().UpdateDlgDarkUI(this); +} + +long StepMeshDialog::get_mesh_number() +{ + Model model; + long number = 0; + const std::string file_path = m_file.string(); + bool is_cb_cancel = false; + bool result = load_step(file_path.c_str(), &model, is_cb_cancel, get_linear_defletion(), get_angle_defletion(), nullptr, nullptr, number); + return number; +} + +void StepMeshDialog::update_mesh_number_text() +{ + long number = get_mesh_number(); + wxString newText = wxString::Format("Number of generated surfaces: %d", number); + mesh_face_number_text->SetLabel(newText); +} \ No newline at end of file diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp new file mode 100644 index 0000000000..24754cd138 --- /dev/null +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -0,0 +1,42 @@ +#ifndef _STEP_MESH_DIALOG_H_ +#define _STEP_MESH_DIALOG_H_ + +#include "GUI_Utils.hpp" +#include +#include +class Button; +namespace fs = boost::filesystem; +class StepMeshDialog : public Slic3r::GUI::DPIDialog +{ +public: + StepMeshDialog(wxWindow* parent, fs::path file); + void on_dpi_changed(const wxRect& suggested_rect) override; + inline double get_linear_defletion() { + double value; + if (m_linear_last.ToDouble(&value)) { + return value; + }else { + return 0.003; + } + } + inline double get_angle_defletion() { + double value; + if (m_angle_last.ToDouble(&value)) { + return value; + } else { + return 0.5; + } + } + long get_mesh_number(); +private: + fs::path 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); + wxStaticText* mesh_face_number_text; + bool validate_number_range(const wxString& value, double min, double max); + void update_mesh_number_text(); +}; + +#endif // _STEP_MESH_DIALOG_H_ \ No newline at end of file From e1477e642cd92052410b5e54a8ab9f8fd79ce35d Mon Sep 17 00:00:00 2001 From: Mack Date: Tue, 29 Oct 2024 16:17:08 +0800 Subject: [PATCH 02/23] FIX:Replace non-UTF8 characters in STEP model names with IDs on import jira: STUDIO-8055 Change-Id: I9255a7a871ebc9920ec683d1a2a80cd53ada0f10 (cherry picked from commit 89be3166e286346254a08c8efc188e0cea83f2a4) --- src/libslic3r/Format/STEP.cpp | 2 +- src/libslic3r/Format/STEP.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Format/STEP.cpp b/src/libslic3r/Format/STEP.cpp index 283fe63798..a637cdd3ca 100644 --- a/src/libslic3r/Format/STEP.cpp +++ b/src/libslic3r/Format/STEP.cpp @@ -182,7 +182,7 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p if (referredLabel.FindAttribute(TDataStd_Name::GetID(), shapeName)) name = TCollection_AsciiString(shapeName->Get()).ToCString(); - if (name == "") + if (name == "" || !StepPreProcessor::isUtf8(name)) name = std::to_string(id++); std::string fullName{name}; diff --git a/src/libslic3r/Format/STEP.hpp b/src/libslic3r/Format/STEP.hpp index 72f8327106..64e52aa9be 100644 --- a/src/libslic3r/Format/STEP.hpp +++ b/src/libslic3r/Format/STEP.hpp @@ -42,8 +42,8 @@ class StepPreProcessor { public: bool preprocess(const char* path, std::string &output_path); static bool isUtf8File(const char* path); -private: static bool isUtf8(const std::string str); +private: static bool isGBK(const std::string str); static int preNum(const unsigned char byte); //BBS: default is UTF8 for most step file. From f91b520bb82c28c50b2d2efc76d8d6639ea55490 Mon Sep 17 00:00:00 2001 From: Mack Date: Fri, 20 Sep 2024 18:12:48 +0800 Subject: [PATCH 03/23] ENH: step mesh operation adjustment 1.Put commctrl.h into pch precompilation(OCCT conflicts) 2.Replace input wxWidgets to support loss focus verification(STUDIO-8101) 3.Optimize slider interaction and trigger mesh when push up slider(STUDIO-8099) 4.Optimize step loading method, separate import of step and mesh 5.Fix dialog cancel button logic; 6.mesh tasks into sub-threads to prevent blocking the UI; JIRA: STUDIO-8101 STUDIO-8099 Change-Id: I50bbb43953a5128f358c6880032d20693531333b (cherry picked from commit ed7ab6b505a2becf8f38edb3c43b96e51eac3317) --- src/libslic3r/Format/STEP.cpp | 113 +++++++++++- src/libslic3r/Format/STEP.hpp | 54 ++++++ src/libslic3r/Model.cpp | 12 +- src/libslic3r/Model.hpp | 2 +- src/slic3r/GUI/CameraUtils.cpp | 2 +- src/slic3r/GUI/CameraUtils.hpp | 2 +- src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp | 2 + src/slic3r/GUI/Plater.cpp | 6 +- src/slic3r/GUI/StepMeshDialog.cpp | 205 +++++++++++++++------- src/slic3r/GUI/StepMeshDialog.hpp | 17 +- src/slic3r/pchheader.hpp | 5 + 11 files changed, 326 insertions(+), 94 deletions(-) diff --git a/src/libslic3r/Format/STEP.cpp b/src/libslic3r/Format/STEP.cpp index a637cdd3ca..38c507bacd 100644 --- a/src/libslic3r/Format/STEP.cpp +++ b/src/libslic3r/Format/STEP.cpp @@ -33,6 +33,8 @@ #include "TopExp_Explorer.hxx" #include "TopExp_Explorer.hxx" #include "BRep_Tool.hxx" +#include "BRepTools.hxx" +#include namespace Slic3r { @@ -163,13 +165,6 @@ int StepPreProcessor::preNum(const unsigned char byte) { return num; } -struct NamedSolid { - NamedSolid(const TopoDS_Shape& s, - const std::string& n) : solid{s}, name{n} {} - const TopoDS_Shape solid; - const std::string name; -}; - static void getNamedSolids(const TopLoc_Location& location, const std::string& prefix, unsigned int& id, const Handle(XCAFDoc_ShapeTool) shapeTool, const TDF_Label label, std::vector& namedSolids) { @@ -206,7 +201,7 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p i++; const TopoDS_Shape& currentShape = explorer.Current(); namedSolids.emplace_back(TopoDS::Solid(currentShape), fullName + "-SOLID-" + std::to_string(i)); - } + } break; case TopAbs_SOLID: namedSolids.emplace_back(TopoDS::Solid(transform.Shape()), fullName); @@ -324,7 +319,7 @@ bool load_step(const char *path, Model *model, bool& is_cancel, } // BBS: copy triangles const TopAbs_Orientation anOrientation = anExpSF.Current().Orientation(); - Standard_Integer anId[3]; + Standard_Integer anId[3] = {}; for (Standard_Integer aTriIter = 1; aTriIter <= aTriangulation->NbTriangles(); ++aTriIter) { Poly_Triangle aTri = aTriangulation->Triangle(aTriIter); @@ -403,4 +398,104 @@ bool load_step(const char *path, Model *model, bool& is_cancel, return true; } +Step::Step(fs::path path, ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn): + m_stepFn(stepFn), + m_utf8Fn(isUtf8Fn) +{ + m_path = path.string(); + m_app->NewDocument(TCollection_ExtendedString("BinXCAF"), m_doc); +} + +Step::Step(std::string path, ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn) : + m_path(path), + m_stepFn(stepFn), + m_utf8Fn(isUtf8Fn) +{ + m_app->NewDocument(TCollection_ExtendedString("BinXCAF"), m_doc); +} + +bool Step::load() +{ + if (!StepPreProcessor::isUtf8File(m_path.c_str()) && m_utf8Fn) { + m_utf8Fn(false); + return false; + } + + STEPCAFControl_Reader reader; + reader.SetNameMode(true); + IFSelect_ReturnStatus stat = reader.ReadFile(m_path.c_str()); + if (stat != IFSelect_RetDone || !reader.Transfer(m_doc)) { + m_app->Close(m_doc); + return false; + } + m_shape_tool = XCAFDoc_DocumentTool::ShapeTool(m_doc->Main()); + TDF_LabelSequence topLevelShapes; + m_shape_tool->GetFreeShapes(topLevelShapes); + unsigned int id{ 1 }; + Standard_Integer topShapeLength = topLevelShapes.Length() + 1; + for (Standard_Integer iLabel = 1; iLabel < topShapeLength; ++iLabel) { + getNamedSolids(TopLoc_Location{}, "", id, m_shape_tool, topLevelShapes.Value(iLabel), m_name_solids); + } + + return true; +} + +void Step::clean_mesh_data() +{ + for (const auto& name_solid : m_name_solids) { + BRepTools::Clean(name_solid.solid); + } +} + +unsigned int Step::get_triangle_num(double linear_defletion, double angle_defletion) +{ + unsigned int tri_num = 0; + Handle(StepProgressIncdicator) progress = new StepProgressIncdicator(m_stop_mesh); + clean_mesh_data(); + IMeshTools_Parameters param; + param.Deflection = linear_defletion; + param.Angle = angle_defletion; + param.InParallel = true; + for (int i = 0; i < m_name_solids.size(); ++i) { + BRepMesh_IncrementalMesh mesh(m_name_solids[i].solid, param, progress->Start()); + for (TopExp_Explorer anExpSF(m_name_solids[i].solid, TopAbs_FACE); anExpSF.More(); anExpSF.Next()) { + TopLoc_Location aLoc; + Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(TopoDS::Face(anExpSF.Current()), aLoc); + if (!aTriangulation.IsNull()) { + tri_num += aTriangulation->NbTriangles(); + } + } + if (m_stop_mesh.load()) { + return 0; + } + } + return tri_num; +} + +unsigned int Step::get_triangle_num_tbb(double linear_defletion, double angle_defletion) +{ + unsigned int tri_num = 0; + clean_mesh_data(); + tbb::parallel_for(tbb::blocked_range(0, m_name_solids.size()), + [&](const tbb::blocked_range& range) { + for (size_t i = range.begin(); i < range.end(); i++) { + unsigned int solids_tri_num = 0; + BRepMesh_IncrementalMesh mesh(m_name_solids[i].solid, linear_defletion, false, angle_defletion, true); + for (TopExp_Explorer anExpSF(m_name_solids[i].solid, TopAbs_FACE); anExpSF.More(); anExpSF.Next()) { + TopLoc_Location aLoc; + Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(TopoDS::Face(anExpSF.Current()), aLoc); + if (!aTriangulation.IsNull()) { + solids_tri_num += aTriangulation->NbTriangles(); + } + } + m_name_solids[i].tri_face_cout = solids_tri_num; + } + + }); + for (int i = 0; i < m_name_solids.size(); ++i) { + tri_num += m_name_solids[i].tri_face_cout; + } + return tri_num; +} + }; // namespace Slic3r diff --git a/src/libslic3r/Format/STEP.hpp b/src/libslic3r/Format/STEP.hpp index 64e52aa9be..40c8669b86 100644 --- a/src/libslic3r/Format/STEP.hpp +++ b/src/libslic3r/Format/STEP.hpp @@ -1,5 +1,14 @@ #ifndef slic3r_Format_STEP_hpp_ #define slic3r_Format_STEP_hpp_ +#include "XCAFDoc_DocumentTool.hxx" +#include "XCAFApp_Application.hxx" +#include "XCAFDoc_ShapeTool.hxx" +#include +#include +#include +#include + +namespace fs = boost::filesystem; namespace Slic3r { @@ -16,6 +25,16 @@ const int LOAD_STEP_STAGE_UNIT_NUM = 5; typedef std::function ImportStepProgressFn; typedef std::function StepIsUtf8Fn; +struct NamedSolid +{ + NamedSolid(const TopoDS_Shape& s, + const std::string& n) : solid{ s }, name{ n } { + } + const TopoDS_Shape solid; + const std::string name; + int tri_face_cout = 0; +}; + //BBS: Load an step file into a provided model. extern bool load_step(const char *path, Model *model, bool& is_cancel, @@ -50,6 +69,41 @@ private: EncodedType m_encode_type = EncodedType::UTF8; }; +class StepProgressIncdicator : public Message_ProgressIndicator +{ +public: + StepProgressIncdicator(std::atomic& stop_flag) : should_stop(stop_flag){} + + Standard_Boolean UserBreak() override { return should_stop.load(); } + + void Show(const Message_ProgressScope&, const Standard_Boolean) override { + std::cout << "Progress: " << GetPosition() << "%" << std::endl; + } +private: + std::atomic& should_stop; +}; + +class Step +{ +public: + Step(fs::path path, ImportStepProgressFn stepFn = nullptr, StepIsUtf8Fn isUtf8Fn = nullptr); + Step(std::string path, ImportStepProgressFn stepFn = nullptr, StepIsUtf8Fn isUtf8Fn = nullptr); + bool load(); + unsigned int get_triangle_num(double linear_defletion, double angle_defletion); + unsigned int get_triangle_num_tbb(double linear_defletion, double angle_defletion); + void clean_mesh_data(); + + std::atomic m_stop_mesh; +private: + std::string m_path; + ImportStepProgressFn m_stepFn; + StepIsUtf8Fn m_utf8Fn; + Handle(XCAFApp_Application) m_app = XCAFApp_Application::GetApplication(); + Handle(TDocStd_Document) m_doc; + Handle(XCAFDoc_ShapeTool) m_shape_tool; + std::vector m_name_solids; +}; + }; // namespace Slic3r #endif /* slic3r_Format_STEP_hpp_ */ diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index 79c424ff79..066eaeda98 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -188,7 +188,7 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c BBLProject * project, int plate_id, ObjImportColorFn objFn, - std::function step_mesh_fn) + std::function step_mesh_fn) { Model model; @@ -216,15 +216,15 @@ Model Model::read_from_file(const std::string& input_file, DynamicPrintConfig* c 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(linear_defletion, angle_defletion) == -1) { - result = false; - goto end; + 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); - end: - BOOST_LOG_TRIVIAL(info) << "Cancel step mesh dialog"; } else 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")) diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index b243bca945..9170b2e40d 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1544,7 +1544,7 @@ public: BBLProject * project = nullptr, int plate_id = 0, ObjImportColorFn objFn = nullptr, - std::function step_mesh_fn = nullptr + std::function step_mesh_fn = 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/CameraUtils.cpp b/src/slic3r/GUI/CameraUtils.cpp index fb8e84fb8a..a14e99c9c5 100644 --- a/src/slic3r/GUI/CameraUtils.cpp +++ b/src/slic3r/GUI/CameraUtils.cpp @@ -38,7 +38,7 @@ Points CameraUtils::project(const Camera & camera, return result; } -Point CameraUtils::project(const Camera &camera, const Vec3d &point) +Slic3r::Point CameraUtils::project(const Camera &camera, const Vec3d &point) { // IMPROVE: do it faster when you need it (inspire in project multi point) return project(camera, std::vector{point}).front(); diff --git a/src/slic3r/GUI/CameraUtils.hpp b/src/slic3r/GUI/CameraUtils.hpp index c3e938ec42..6e953bf6ee 100644 --- a/src/slic3r/GUI/CameraUtils.hpp +++ b/src/slic3r/GUI/CameraUtils.hpp @@ -25,7 +25,7 @@ public: /// projected points by camera into coordinate of camera. /// x(from left to right), y(from top to bottom) static Points project(const Camera& camera, const std::vector &points); - static Point project(const Camera& camera, const Vec3d &point); + static Slic3r::Point project(const Camera& camera, const Vec3d &point); /// /// Create hull around GLVolume in 2d space of camera diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp index e316861dbd..0d6480abd7 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBrimEars.hpp @@ -174,6 +174,8 @@ protected: void find_single(); }; +wxDECLARE_EVENT(wxEVT_THREAD_DONE, wxCommandEvent); + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 50fa2bd084..a5ec5bed3a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4156,17 +4156,17 @@ std::vector Plater::priv::load_files(const std::vector& input_ filament_ids.clear(); } }; - auto step_mesh = [this, &path, &is_user_cancel](double& linear_value, double& angle_value)-> int { + 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, path); + 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 = false; + is_user_cancel = true; return -1; }; model = Slic3r::Model:: read_from_file( diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 60d2acde1a..85989accf9 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -1,11 +1,15 @@ #include "StepMeshDialog.hpp" -#include "BBLStatusBar.hpp" -#include "I18N.hpp" -#include "GUI_App.hpp" -#include "Widgets/Button.hpp" -#include "MainFrame.hpp" + +#include +#include #include #include +#include "GUI_App.hpp" +#include "I18N.hpp" +#include "MainFrame.hpp" +#include "Widgets/Button.hpp" +#include "Widgets/TextInput.hpp" +#include using namespace Slic3r; using namespace Slic3r::GUI; @@ -14,7 +18,7 @@ static int _scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit( static int _ITEM_WIDTH() { return _scale(30); } #define MIN_DIALOG_WIDTH FromDIP(400) #define SLIDER_WIDTH FromDIP(150) -#define TEXT_CTRL_WIDTH FromDIP(40) +#define TEXT_CTRL_WIDTH FromDIP(50) #define BUTTON_SIZE wxSize(FromDIP(58), FromDIP(24)) #define BUTTON_BORDER FromDIP(int(400 - 58 * 2) / 8) #define SLIDER_SCALE(val) ((val) / 0.001) @@ -23,18 +27,28 @@ static int _ITEM_WIDTH() { return _scale(30); } #define SLIDER_UNSCALE_10(val) ((val) * 0.01) #define LEFT_RIGHT_PADING FromDIP(20) +wxDEFINE_EVENT(wxEVT_THREAD_DONE, wxCommandEvent); + void StepMeshDialog::on_dpi_changed(const wxRect& suggested_rect) { }; bool StepMeshDialog:: validate_number_range(const wxString& value, double min, double max) { - double num; - if (!value.ToDouble(&num)) { + double num = 0.0; + if (value.IsEmpty()) { return false; } + try { + if (!value.ToDouble(&num)) { + return false; + } + } catch (...) { + return false; + } + return (num >= min && num <= max); } -StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) +StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) : DPIDialog(parent ? parent : static_cast(wxGetApp().mainframe), wxID_ANY, _(L("Step file import parameters")), @@ -42,6 +56,8 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) wxDefaultSize, wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/), m_file(file) { + Bind(wxEVT_THREAD_DONE, &StepMeshDialog::on_task_done, this); + std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % Slic3r::resources_dir()).str(); SetIcon(wxIcon(Slic3r::encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO)); @@ -64,34 +80,28 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) wxSize(SLIDER_WIDTH, -1), wxSL_HORIZONTAL); linear_sizer->Add(linear_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); - wxTextValidator valid_number(wxFILTER_NUMERIC); - wxTextCtrl* linear_textctrl = new wxTextCtrl(this, wxID_ANY, - m_linear_last, - wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), - 0, valid_number); - linear_sizer->Add(linear_textctrl, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); - // textctrl loss focus - linear_textctrl->Bind(wxEVT_KILL_FOCUS, ([this, linear_textctrl](wxFocusEvent& e) { - wxString value = linear_textctrl->GetValue(); - if(!validate_number_range(value, 0.001, 0.1)) { - linear_textctrl->SetValue(m_linear_last); + + auto linear_input = new ::TextInput(this, m_linear_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1)); + linear_input->GetTextCtrl()->SetFont(Label::Body_12); + linear_input->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); + linear_sizer->Add(linear_input, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); + linear_input->Bind(wxEVT_KILL_FOCUS, ([this, linear_input](wxFocusEvent& e) { + wxString value = linear_input->GetTextCtrl()->GetValue(); + if (validate_number_range(value, 0.001, 0.1)) { + m_linear_last = value; + update_mesh_number_text(); + } else { + MessageDialog msg_dlg(nullptr, _L("Please input a valid value (0.001 < angle deflection < 0.1)"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + linear_input->GetTextCtrl()->SetValue(m_linear_last); } - m_linear_last = value; - update_mesh_number_text(); e.Skip(); })); - // slider bind textctrl - linear_slider->Bind(wxEVT_SLIDER, ([this, linear_slider, linear_textctrl](wxCommandEvent& e) { - double slider_value = SLIDER_UNSCALE(linear_slider->GetValue()); - linear_textctrl->SetValue(wxString::Format("%.3f", slider_value)); - m_linear_last = wxString::Format("%.3f", slider_value); - update_mesh_number_text(); - })); // textctrl bind slider - linear_textctrl->Bind(wxEVT_TEXT, ([this, linear_textctrl, linear_slider](wxCommandEvent& e) { + linear_input->Bind(wxEVT_TEXT, ([this, linear_slider, linear_input](wxCommandEvent& e) { double slider_value_long; int slider_value; - wxString value = linear_textctrl->GetValue(); + wxString value = linear_input->GetTextCtrl()->GetValue(); if (value.ToDouble(&slider_value_long)) { slider_value = SLIDER_SCALE(slider_value_long); if (slider_value >= linear_slider->GetMin() && slider_value <= linear_slider->GetMax()) { @@ -99,6 +109,15 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) } } })); + linear_slider->Bind(wxEVT_SLIDER, ([this, linear_slider, linear_input](wxCommandEvent& e) { + double slider_value = SLIDER_UNSCALE(linear_slider->GetValue()); + linear_input->GetTextCtrl()->SetValue(wxString::Format("%.3f", slider_value)); + m_linear_last = wxString::Format("%.3f", slider_value); + })); + linear_slider->Bind(wxEVT_LEFT_UP, ([this](wxMouseEvent& e) { + update_mesh_number_text(); + e.Skip(); + })); bSizer->Add(linear_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING); @@ -114,33 +133,28 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) wxSize(SLIDER_WIDTH, -1), wxSL_HORIZONTAL); angle_sizer->Add(angle_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); - wxTextCtrl* angle_textctrl = new wxTextCtrl(this, wxID_ANY, - m_angle_last, - wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), - 0, valid_number); - angle_sizer->Add(angle_textctrl, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); - // textctrl loss focus - angle_textctrl->Bind(wxEVT_KILL_FOCUS, ([this, angle_textctrl](wxFocusEvent& e) { - wxString value = angle_textctrl->GetValue(); - if (!validate_number_range(value, 0.01, 1)) { - angle_textctrl->SetValue(m_angle_last); + + auto angle_input = new::TextInput(this, m_angle_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1)); + angle_input->GetTextCtrl()->SetFont(Label::Body_12); + angle_input->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); + angle_sizer->Add(angle_input, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); + angle_input->Bind(wxEVT_KILL_FOCUS, ([this, angle_input](wxFocusEvent& e) { + wxString value = angle_input->GetTextCtrl()->GetValue(); + if (validate_number_range(value, 0.01, 1)) { + m_angle_last = value; + update_mesh_number_text(); + } else { + MessageDialog msg_dlg(nullptr, _L("Please input a valid value (0.01 < angle deflection < 1.0)"), wxEmptyString, wxICON_WARNING | wxOK); + msg_dlg.ShowModal(); + angle_input->GetTextCtrl()->SetValue(m_angle_last); } - m_angle_last = value; - update_mesh_number_text(); e.Skip(); })); - // slider bind textctrl - angle_slider->Bind(wxEVT_SLIDER, ([this, angle_slider, angle_textctrl](wxCommandEvent& e) { - double slider_value = SLIDER_UNSCALE_10(angle_slider->GetValue()); - angle_textctrl->SetValue(wxString::Format("%.2f", slider_value)); - m_angle_last = wxString::Format("%.2f", slider_value); - update_mesh_number_text(); - })); // textctrl bind slider - linear_textctrl->Bind(wxEVT_TEXT, ([this, angle_slider, angle_textctrl](wxCommandEvent& e) { + angle_input->Bind(wxEVT_TEXT, ([this, angle_slider, angle_input](wxCommandEvent& e) { double slider_value_long; int slider_value; - wxString value = angle_textctrl->GetValue(); + wxString value = angle_input->GetTextCtrl()->GetValue(); if (value.ToDouble(&slider_value_long)) { slider_value = SLIDER_SCALE_10(slider_value_long); if (slider_value >= angle_slider->GetMin() && slider_value <= angle_slider->GetMax()) { @@ -149,11 +163,25 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) } })); + angle_slider->Bind(wxEVT_SLIDER, ([this, angle_slider, angle_input](wxCommandEvent& e) { + double slider_value = SLIDER_UNSCALE_10(angle_slider->GetValue()); + angle_input->GetTextCtrl()->SetValue(wxString::Format("%.2f", slider_value)); + m_angle_last = wxString::Format("%.2f", slider_value); + })); + angle_slider->Bind(wxEVT_LEFT_UP, ([this](wxMouseEvent& e) { + update_mesh_number_text(); + e.Skip(); + })); + bSizer->Add(angle_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); - - mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("Number of generated surfaces: 0")); - bSizer->Add(mesh_face_number_text, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); + wxBoxSizer* mesh_face_number_sizer = new wxBoxSizer(wxHORIZONTAL); + wxStaticText* mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets: ")); + mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("0")); + mesh_face_number_text->SetMinSize(wxSize(FromDIP(150), -1)); + mesh_face_number_sizer->Add(mesh_face_number_title, 0, wxALIGN_LEFT); + mesh_face_number_sizer->Add(mesh_face_number_text, 0, wxALIGN_LEFT); + bSizer->Add(mesh_face_number_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); wxBoxSizer* bSizer_button = new wxBoxSizer(wxHORIZONTAL); bSizer_button->SetMinSize(wxSize(FromDIP(100), -1)); @@ -170,7 +198,14 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) m_button_ok->SetCornerRadius(FromDIP(12)); bSizer_button->Add(m_button_ok, 0, wxALIGN_RIGHT, BUTTON_BORDER); - m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { EndModal(wxID_OK); }); + m_button_ok->Bind(wxEVT_LEFT_DOWN, [this, angle_input, linear_input](wxMouseEvent& e) { + stop_task(); + if (validate_number_range(angle_input->GetTextCtrl()->GetValue(), 0.01, 1) && + validate_number_range(linear_input->GetTextCtrl()->GetValue(), 0.001, 0.1)) { + EndModal(wxID_OK); + } + SetFocusIgnoringChildren(); + }); StateColor btn_bg_white(std::pair(wxColour(206, 206, 206), StateColor::Pressed), std::pair(wxColour(238, 238, 238), StateColor::Hovered), std::pair(*wxWHITE, StateColor::Normal)); @@ -184,7 +219,10 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) m_button_cancel->SetCornerRadius(FromDIP(12)); bSizer_button->Add(m_button_cancel, 0, wxALIGN_RIGHT | wxLEFT, BUTTON_BORDER); - m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { EndModal(wxID_CANCEL); }); + m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { + stop_task(); + EndModal(wxID_CANCEL); + }); bSizer->Add(bSizer_button, 0, wxALIGN_RIGHT | wxRIGHT| wxBOTTOM, LEFT_RIGHT_PADING); @@ -193,24 +231,57 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, fs::path file) this->Layout(); bSizer->Fit(this); - this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) { }); + this->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + SetFocusIgnoringChildren(); + }); + mesh_face_number_text->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { + SetFocusIgnoringChildren(); + }); + + this->Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& e) { + stop_task(); + EndModal(wxID_CANCEL); + }); wxGetApp().UpdateDlgDarkUI(this); } -long StepMeshDialog::get_mesh_number() +void StepMeshDialog::on_task_done(wxCommandEvent& event) { - Model model; - long number = 0; - const std::string file_path = m_file.string(); - bool is_cb_cancel = false; - bool result = load_step(file_path.c_str(), &model, is_cb_cancel, get_linear_defletion(), get_angle_defletion(), nullptr, nullptr, number); - return number; + wxString text = event.GetString(); + mesh_face_number_text->SetLabel(text); + if (task.valid()) { + task.get(); + } +} + +void StepMeshDialog::stop_task() +{ + if (task.valid()) { + m_file.m_stop_mesh.store(true); + unsigned int test = task.get(); + m_file.m_stop_mesh.store(false); + std::cout << test << std::endl; + } + } void StepMeshDialog::update_mesh_number_text() { - long number = get_mesh_number(); - wxString newText = wxString::Format("Number of generated surfaces: %d", number); + if (m_last_linear == get_linear_defletion() && m_last_angle == get_angle_defletion()) + return; + wxString newText = wxString::Format(_L("Calculating, please wait...")); mesh_face_number_text->SetLabel(newText); + + stop_task(); + task = std::async(std::launch::async, [&] { + unsigned int number = m_file.get_triangle_num(get_linear_defletion(), get_angle_defletion()); + if (number != 0) { + wxString number_text = wxString::Format("%d", number); + wxCommandEvent event(wxEVT_THREAD_DONE); + event.SetString(number_text); + wxPostEvent(this, event); + } + return number; + }); } \ No newline at end of file diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index 24754cd138..48bff2adc3 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -1,15 +1,16 @@ #ifndef _STEP_MESH_DIALOG_H_ #define _STEP_MESH_DIALOG_H_ +#include #include "GUI_Utils.hpp" -#include -#include +#include "libslic3r/Format/STEP.hpp" +#include "Widgets/Button.hpp" class Button; -namespace fs = boost::filesystem; + class StepMeshDialog : public Slic3r::GUI::DPIDialog { public: - StepMeshDialog(wxWindow* parent, fs::path file); + StepMeshDialog(wxWindow* parent, Slic3r::Step& file); void on_dpi_changed(const wxRect& suggested_rect) override; inline double get_linear_defletion() { double value; @@ -27,16 +28,20 @@ public: return 0.5; } } - long get_mesh_number(); private: - fs::path m_file; + 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); wxStaticText* mesh_face_number_text; + double m_last_linear; + double m_last_angle; + std::future task; bool validate_number_range(const wxString& value, double min, double max); void update_mesh_number_text(); + void on_task_done(wxCommandEvent& event); + void stop_task(); }; #endif // _STEP_MESH_DIALOG_H_ \ No newline at end of file diff --git a/src/slic3r/pchheader.hpp b/src/slic3r/pchheader.hpp index 1413839185..7519cbb399 100644 --- a/src/slic3r/pchheader.hpp +++ b/src/slic3r/pchheader.hpp @@ -6,6 +6,11 @@ #define NOMINMAX #endif #include + #include +#endif + +#ifdef __APPLE__ + #include #endif #include From 6d7260a6e94f1408d857f0bcbd76edccc1e3ef81 Mon Sep 17 00:00:00 2001 From: Mack Date: Tue, 8 Oct 2024 20:35:27 +0800 Subject: [PATCH 04/23] FIX:Parameter value has not changed, no recalculation jira: STUDIO-8283 Change-Id: I3564ff0993de1c3b8e039fc0115b4ccd81b2a5a2 (cherry picked from commit fecd3c3297c8dc85775622d65e292492523cc150) --- src/slic3r/GUI/StepMeshDialog.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 85989accf9..449b32f450 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -91,7 +91,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) m_linear_last = value; update_mesh_number_text(); } else { - MessageDialog msg_dlg(nullptr, _L("Please input a valid value (0.001 < angle deflection < 0.1)"), wxEmptyString, wxICON_WARNING | wxOK); + MessageDialog msg_dlg(nullptr, _L("Please input a valid value (0.001 < linear deflection < 0.1)"), wxEmptyString, wxICON_WARNING | wxOK); msg_dlg.ShowModal(); linear_input->GetTextCtrl()->SetValue(m_linear_last); } @@ -281,6 +281,8 @@ void StepMeshDialog::update_mesh_number_text() wxCommandEvent event(wxEVT_THREAD_DONE); event.SetString(number_text); wxPostEvent(this, event); + m_last_linear = get_linear_defletion(); + m_last_angle = get_angle_defletion(); } return number; }); From 288a367e4ddded7e0c90bbaed604045f5654fde4 Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Wed, 9 Oct 2024 12:13:00 +0800 Subject: [PATCH 05/23] ENH:translate texts jira: none Change-Id: If48a4a25c379f589f80af2715f825c5e1b13dfac (cherry picked from commit 3bc4bf93bd98372e3bfd932ed096b57cd645b4bd) --- src/slic3r/GUI/StepMeshDialog.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 449b32f450..bdab0790c1 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -71,7 +71,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) //linear_sizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); wxStaticText* linear_title = new wxStaticText(this, wxID_ANY, - _L("Linear Deflection:")); + _L("Linear Deflection")); linear_sizer->Add(linear_title, 0, wxALIGN_LEFT); linear_sizer->AddStretchSpacer(1); wxSlider* linear_slider = new wxSlider(this, wxID_ANY, @@ -124,7 +124,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxBoxSizer* angle_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText* angle_title = new wxStaticText(this, wxID_ANY, - _L("Angle Deflection:")); + _L("Angle Deflection")); angle_sizer->Add(angle_title, 0, wxALIGN_LEFT); angle_sizer->AddStretchSpacer(1); wxSlider* angle_slider = new wxSlider(this, wxID_ANY, @@ -176,7 +176,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) bSizer->Add(angle_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); wxBoxSizer* mesh_face_number_sizer = new wxBoxSizer(wxHORIZONTAL); - wxStaticText* mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets: ")); + wxStaticText* mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets")); mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("0")); mesh_face_number_text->SetMinSize(wxSize(FromDIP(150), -1)); mesh_face_number_sizer->Add(mesh_face_number_title, 0, wxALIGN_LEFT); From 8c4794de38ac4fda023dd8ffc138df954e16d0bc Mon Sep 17 00:00:00 2001 From: Mack Date: Sat, 12 Oct 2024 23:24:24 +0800 Subject: [PATCH 06/23] ENH:step mesh optimize interface jira: STUDIO-8281 Change-Id: Ic1e3e958816d6a213f68009ecc0b9430ba4b5482 (cherry picked from commit 072ba8339b1acd46c6d1a5a91b671f98f4045b37) --- src/slic3r/GUI/StepMeshDialog.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index bdab0790c1..5af7116d70 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -17,8 +17,8 @@ using namespace Slic3r::GUI; static int _scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit() / 10; } static int _ITEM_WIDTH() { return _scale(30); } #define MIN_DIALOG_WIDTH FromDIP(400) -#define SLIDER_WIDTH FromDIP(150) -#define TEXT_CTRL_WIDTH FromDIP(50) +#define SLIDER_WIDTH FromDIP(200) +#define TEXT_CTRL_WIDTH FromDIP(70) #define BUTTON_SIZE wxSize(FromDIP(58), FromDIP(24)) #define BUTTON_BORDER FromDIP(int(400 - 58 * 2) / 8) #define SLIDER_SCALE(val) ((val) / 0.001) @@ -70,8 +70,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxBoxSizer* linear_sizer = new wxBoxSizer(wxHORIZONTAL); //linear_sizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); wxStaticText* linear_title = new wxStaticText(this, - wxID_ANY, - _L("Linear Deflection")); + wxID_ANY, _L("Linear Deflection") + ": "); linear_sizer->Add(linear_title, 0, wxALIGN_LEFT); linear_sizer->AddStretchSpacer(1); wxSlider* linear_slider = new wxSlider(this, wxID_ANY, @@ -81,7 +80,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxSL_HORIZONTAL); linear_sizer->Add(linear_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); - auto linear_input = new ::TextInput(this, m_linear_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1)); + auto linear_input = new ::TextInput(this, m_linear_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), wxTE_CENTER); linear_input->GetTextCtrl()->SetFont(Label::Body_12); linear_input->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); linear_sizer->Add(linear_input, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); @@ -123,8 +122,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxBoxSizer* angle_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText* angle_title = new wxStaticText(this, - wxID_ANY, - _L("Angle Deflection")); + wxID_ANY, _L("Angle Deflection") + ": "); angle_sizer->Add(angle_title, 0, wxALIGN_LEFT); angle_sizer->AddStretchSpacer(1); wxSlider* angle_slider = new wxSlider(this, wxID_ANY, @@ -134,7 +132,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxSL_HORIZONTAL); angle_sizer->Add(angle_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); - auto angle_input = new::TextInput(this, m_angle_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1)); + auto angle_input = new ::TextInput(this, m_angle_last, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(TEXT_CTRL_WIDTH, -1), wxTE_CENTER); angle_input->GetTextCtrl()->SetFont(Label::Body_12); angle_input->GetTextCtrl()->SetValidator(wxTextValidator(wxFILTER_NUMERIC)); angle_sizer->Add(angle_input, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); @@ -176,7 +174,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) bSizer->Add(angle_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); wxBoxSizer* mesh_face_number_sizer = new wxBoxSizer(wxHORIZONTAL); - wxStaticText* mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets")); + wxStaticText *mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets") + ": "); mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("0")); mesh_face_number_text->SetMinSize(wxSize(FromDIP(150), -1)); mesh_face_number_sizer->Add(mesh_face_number_title, 0, wxALIGN_LEFT); From 207d08476c632bb9c21cd6c078dc5ef8ebc8de38 Mon Sep 17 00:00:00 2001 From: Mack Date: Mon, 21 Oct 2024 09:49:04 +0800 Subject: [PATCH 07/23] ENH: update step mesh ui jira:nojira Change-Id: I7ba88d1ad80fa1e8152393c523bc301187e543d1 (cherry picked from commit 8dfd3bbb0c2b32ba95d942a662c4223b9001c40a) --- resources/images/step_mesh_info.svg | 5 ++++ src/slic3r/GUI/StepMeshDialog.cpp | 46 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 resources/images/step_mesh_info.svg diff --git a/resources/images/step_mesh_info.svg b/resources/images/step_mesh_info.svg new file mode 100644 index 0000000000..c12b253a53 --- /dev/null +++ b/resources/images/step_mesh_info.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 5af7116d70..d2bc18f1e3 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "GUI_App.hpp" #include "I18N.hpp" #include "MainFrame.hpp" @@ -29,6 +30,23 @@ static int _ITEM_WIDTH() { return _scale(30); } wxDEFINE_EVENT(wxEVT_THREAD_DONE, wxCommandEvent); +class CenteredStaticText : public wxStaticText +{ +public: + CenteredStaticText(wxWindow* parent, wxWindowID id, const wxString& label, const wxPoint& position, const wxSize& size = wxDefaultSize, long style = 0) + : wxStaticText(parent, id, label, position, size, style) { + CenterOnPosition(position); + } + + void CenterOnPosition(const wxPoint& position) { + int textWidth, textHeight; + GetTextExtent(GetLabel(), &textWidth, &textHeight); + int x = position.x - textWidth / 2; + int y = position.y - textHeight / 2; + SetPosition(wxPoint(x, y)); + } +}; + void StepMeshDialog::on_dpi_changed(const wxRect& suggested_rect) { }; @@ -67,6 +85,34 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL); bSizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); + auto image_bitmap = create_scaled_bitmap("step_mesh_info", this, FromDIP(120), false, std::string(), false, false, true); + int image_width = image_bitmap.GetWidth(); + int image_height = image_bitmap.GetHeight(); + wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, image_bitmap.GetSize(), wxTAB_TRAVERSAL); + overlay_panel->SetBackgroundStyle(wxBG_STYLE_PAINT); + wxStaticBitmap *image = new wxStaticBitmap(overlay_panel, wxID_ANY, image_bitmap, wxDefaultPosition, wxDefaultSize, 0); + + CenteredStaticText* text_1 = new CenteredStaticText (overlay_panel, wxID_ANY, _L("Rough"), + wxPoint(overlay_panel->GetSize().GetWidth() / 6, + overlay_panel->GetSize().GetHeight() / 2)); + CenteredStaticText* text_2 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Smooth"), + wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, + overlay_panel->GetSize().GetHeight() / 2)); + CenteredStaticText* text_3 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Linear"), + wxPoint(overlay_panel->GetSize().GetWidth() / 2, + overlay_panel->GetSize().GetHeight() * 1.3 / 3)); + CenteredStaticText* text_4 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Angle"), + wxPoint(overlay_panel->GetSize().GetWidth() / 2, + overlay_panel->GetSize().GetHeight() * 2 / 3)); + CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Many faces"), + wxPoint(overlay_panel->GetSize().GetWidth() / 6, + overlay_panel->GetSize().GetHeight() * 2.8 / 3)); + CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Few faces"), + wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, + overlay_panel->GetSize().GetHeight() * 2.8 / 3)); + + bSizer->Add(overlay_panel, 0, wxALIGN_CENTER | wxALL, 10); + wxBoxSizer* linear_sizer = new wxBoxSizer(wxHORIZONTAL); //linear_sizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); wxStaticText* linear_title = new wxStaticText(this, From 65e5b193e126f3c2673041003181bbbd6fa7d6ab Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 25 Oct 2024 21:45:14 +0800 Subject: [PATCH 08/23] ENH: translation jira: STUDIO-8530 Change-Id: I43aeda64251165eaa2fc7f26b6dbaf548bc62057 (cherry picked from commit 9c799cc98641e546e736acbf6c944cc3c230ba58) --- src/slic3r/GUI/StepMeshDialog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index d2bc18f1e3..96e71cbd25 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -104,10 +104,10 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) CenteredStaticText* text_4 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Angle"), wxPoint(overlay_panel->GetSize().GetWidth() / 2, overlay_panel->GetSize().GetHeight() * 2 / 3)); - CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Many faces"), + CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Fewer faces"), wxPoint(overlay_panel->GetSize().GetWidth() / 6, overlay_panel->GetSize().GetHeight() * 2.8 / 3)); - CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Few faces"), + CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("More faces"), wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, overlay_panel->GetSize().GetHeight() * 2.8 / 3)); From 0bc2444079e4ff85761515b20bbe625d8f4c98a7 Mon Sep 17 00:00:00 2001 From: Mack Date: Fri, 8 Nov 2024 21:06:57 +0800 Subject: [PATCH 09/23] ENH:Add 'Don't show again' to the step mesh jira: STUDIO-8606 Change-Id: I2382b9052e2c994a458ad36ca61eb94c517927c6 (cherry picked from commit 0cce6619ce12aa8540f6dfca6d9ee79ffba65c19) --- src/OrcaSlicer.cpp | 2 +- src/libslic3r/AppConfig.cpp | 8 +++ src/libslic3r/GCode/CoolingBuffer.hpp | 1 + src/libslic3r/Model.cpp | 82 +++++++++++++++++------- src/libslic3r/Model.hpp | 14 +++-- src/slic3r/GUI/Plater.cpp | 91 +++++++++++++++------------ src/slic3r/GUI/Preferences.cpp | 2 + src/slic3r/GUI/StepMeshDialog.cpp | 12 +++- src/slic3r/GUI/StepMeshDialog.hpp | 16 +++-- src/slic3r/Utils/CalibUtils.cpp | 2 +- 10 files changed, 154 insertions(+), 76 deletions(-) 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) From 9b439ff5a22d387210939575bdd5edc299a12f74 Mon Sep 17 00:00:00 2001 From: Mack Date: Wed, 13 Nov 2024 15:27:44 +0800 Subject: [PATCH 10/23] FIX:STEP mesh crashes in specific language 1.fix dark model 2.fix reload file 3.fix macos ui jira: STUDIO-8722 Change-Id: I17c723cbf88b97b187c72fbc6f65fc2da591465f (cherry picked from commit 6c48a8e40b3a28859d5883b13106683cbe61c73d) --- resources/images/step_mesh_info.svg | 6 +++--- src/slic3r/GUI/Plater.cpp | 22 +++++++++++++++------- src/slic3r/GUI/StepMeshDialog.cpp | 24 +++++++++++++----------- src/slic3r/GUI/StepMeshDialog.hpp | 16 +++++----------- 4 files changed, 36 insertions(+), 32 deletions(-) diff --git a/resources/images/step_mesh_info.svg b/resources/images/step_mesh_info.svg index c12b253a53..28f840853a 100644 --- a/resources/images/step_mesh_info.svg +++ b/resources/images/step_mesh_info.svg @@ -1,5 +1,5 @@ - - - + + + diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 904520cba2..234937c128 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4156,10 +4156,10 @@ std::vector Plater::priv::load_files(const std::vector& input_ filament_ids.clear(); } }; - 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")); + if (boost::iends_with(path.string(), ".stp") || + boost::iends_with(path.string(), ".step")) { + double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_defletion")); + double angle = string_to_double_decimal_point(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) { @@ -4187,7 +4187,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ }, [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); + StepMeshDialog mesh_dlg(nullptr, file, linear, angle); if (mesh_dlg.ShowModal() == wxID_OK) { linear_value = mesh_dlg.get_linear_defletion(); angle_value = mesh_dlg.get_angle_defletion(); @@ -5960,8 +5960,16 @@ void Plater::priv::reload_from_disk() std::vector project_presets; // BBS: backup - new_model = Model::read_from_file(path, nullptr, nullptr, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, &plate_data, &project_presets, nullptr, - nullptr, nullptr, nullptr, nullptr, 0, obj_color_fun); + if (boost::iends_with(path, ".stp") || + boost::iends_with(path, ".step")) { + double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_defletion")); + double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_defletion")); + new_model = Model::read_from_step(path, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, nullptr, nullptr, nullptr, linear, angle); + }else { + new_model = Model::read_from_file(path, nullptr, nullptr, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, &plate_data, &project_presets, nullptr, 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/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 4963b7d97b..df49232aa7 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -66,7 +66,7 @@ bool StepMeshDialog:: validate_number_range(const wxString& value, double min, d return (num >= min && num <= max); } -StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) +StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double linear_init, double angle_init) : DPIDialog(parent ? parent : static_cast(wxGetApp().mainframe), wxID_ANY, _(L("Step file import parameters")), @@ -74,6 +74,9 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxDefaultSize, wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/), m_file(file) { + m_linear_last = wxString::Format("%.3f", linear_init); + m_angle_last = wxString::Format("%.2f", angle_init); + Bind(wxEVT_THREAD_DONE, &StepMeshDialog::on_task_done, this); std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") @@ -85,17 +88,16 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) wxBoxSizer* bSizer = new wxBoxSizer(wxVERTICAL); bSizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); - auto image_bitmap = create_scaled_bitmap("step_mesh_info", this, FromDIP(120), false, std::string(), false, false, true); - int image_width = image_bitmap.GetWidth(); - int image_height = image_bitmap.GetHeight(); - wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, image_bitmap.GetSize(), wxTAB_TRAVERSAL); + auto image_bitmap = create_scaled_bitmap("step_mesh_info", this, FromDIP(120)); + + wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(image_bitmap.GetWidth()), FromDIP(image_bitmap.GetHeight())), wxTAB_TRAVERSAL); overlay_panel->SetBackgroundStyle(wxBG_STYLE_PAINT); wxStaticBitmap *image = new wxStaticBitmap(overlay_panel, wxID_ANY, image_bitmap, wxDefaultPosition, wxDefaultSize, 0); - CenteredStaticText* text_1 = new CenteredStaticText (overlay_panel, wxID_ANY, _L("Rough"), + CenteredStaticText* text_1 = new CenteredStaticText (overlay_panel, wxID_ANY, _L("Smooth"), wxPoint(overlay_panel->GetSize().GetWidth() / 6, overlay_panel->GetSize().GetHeight() / 2)); - CenteredStaticText* text_2 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Smooth"), + CenteredStaticText* text_2 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Rough"), wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, overlay_panel->GetSize().GetHeight() / 2)); CenteredStaticText* text_3 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Linear"), @@ -104,10 +106,10 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) CenteredStaticText* text_4 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Angle"), wxPoint(overlay_panel->GetSize().GetWidth() / 2, overlay_panel->GetSize().GetHeight() * 2 / 3)); - CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Fewer faces"), + CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("More faces"), wxPoint(overlay_panel->GetSize().GetWidth() / 6, overlay_panel->GetSize().GetHeight() * 2.8 / 3)); - CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("More faces"), + CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Fewer faces"), wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, overlay_panel->GetSize().GetHeight() * 2.8 / 3)); @@ -251,8 +253,8 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file) 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())); + wxGetApp().app_config->set("linear_defletion", float_to_string_decimal_point(get_linear_defletion(), 3)); + wxGetApp().app_config->set("angle_defletion", float_to_string_decimal_point(get_angle_defletion(), 2)); EndModal(wxID_OK); } diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index aeab7ffabd..0f6fa8d8a2 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -11,20 +11,14 @@ class Button; class StepMeshDialog : public Slic3r::GUI::DPIDialog { public: - StepMeshDialog(wxWindow* parent, Slic3r::Step& file); + StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double linear_init, double angle_init); 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 get_linear_init(); + return m_last_linear; } } inline double get_angle_defletion() { @@ -32,7 +26,7 @@ public: if (m_angle_last.ToDouble(&value)) { return value; } else { - return get_angle_init(); + return m_last_angle; } } private: @@ -40,8 +34,8 @@ private: Button* m_button_ok = nullptr; Button* m_button_cancel = nullptr; wxCheckBox* m_checkbox = nullptr; - wxString m_linear_last = wxString::Format("%.3f", get_linear_init()); - wxString m_angle_last = wxString::Format("%.2f", get_angle_init()); + wxString m_linear_last; + wxString m_angle_last; wxStaticText* mesh_face_number_text; double m_last_linear; double m_last_angle; From 0d9534bcf1224012be0cf99cf17b78c81669bacb Mon Sep 17 00:00:00 2001 From: Mack Date: Wed, 13 Nov 2024 20:05:14 +0800 Subject: [PATCH 11/23] FIX:m_last_linear and m_last_angle add init value jira: studio-8739 Change-Id: Ib1052856e7f9b4e427a58fb89f828dc0e6593247 (cherry picked from commit 8e2b233730ece85c04149aa4d1328519b3b79100) --- src/slic3r/GUI/StepMeshDialog.cpp | 4 ++-- src/slic3r/GUI/StepMeshDialog.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index df49232aa7..e353dd2c8c 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -90,9 +90,9 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line auto image_bitmap = create_scaled_bitmap("step_mesh_info", this, FromDIP(120)); - wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(FromDIP(image_bitmap.GetWidth()), FromDIP(image_bitmap.GetHeight())), wxTAB_TRAVERSAL); + wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, image_bitmap.GetSize(), wxTAB_TRAVERSAL); overlay_panel->SetBackgroundStyle(wxBG_STYLE_PAINT); - wxStaticBitmap *image = new wxStaticBitmap(overlay_panel, wxID_ANY, image_bitmap, wxDefaultPosition, wxDefaultSize, 0); + wxStaticBitmap *image = new wxStaticBitmap(overlay_panel, wxID_ANY, image_bitmap, wxDefaultPosition, overlay_panel->GetSize(), 0); CenteredStaticText* text_1 = new CenteredStaticText (overlay_panel, wxID_ANY, _L("Smooth"), wxPoint(overlay_panel->GetSize().GetWidth() / 6, diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index 0f6fa8d8a2..d746226ca0 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -37,8 +37,8 @@ private: wxString m_linear_last; wxString m_angle_last; wxStaticText* mesh_face_number_text; - double m_last_linear; - double m_last_angle; + double m_last_linear = 0.003; + double m_last_angle = 0.5; std::future task; bool validate_number_range(const wxString& value, double min, double max); void update_mesh_number_text(); From d27630cec71e8a73656ba1b680800699285544e8 Mon Sep 17 00:00:00 2001 From: Mack Date: Thu, 14 Nov 2024 19:12:45 +0800 Subject: [PATCH 12/23] ENH:update step mesh ui jira: nojira Change-Id: I4cea486dee7fafa6495d63e8557ff790cc1640dc (cherry picked from commit b2b157f1a49a53d119a382a686a6e343899e98b9) --- src/slic3r/GUI/StepMeshDialog.cpp | 58 +++++++++++++++++++------------ 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index e353dd2c8c..9c4b93099b 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -90,30 +90,44 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line auto image_bitmap = create_scaled_bitmap("step_mesh_info", this, FromDIP(120)); - wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, image_bitmap.GetSize(), wxTAB_TRAVERSAL); - overlay_panel->SetBackgroundStyle(wxBG_STYLE_PAINT); - wxStaticBitmap *image = new wxStaticBitmap(overlay_panel, wxID_ANY, image_bitmap, wxDefaultPosition, overlay_panel->GetSize(), 0); + // wxPanel* overlay_panel = new wxPanel(this, wxID_ANY, wxDefaultPosition, image_bitmap.GetSize(), wxTAB_TRAVERSAL); + // overlay_panel->SetBackgroundStyle(wxBG_STYLE_PAINT); + // wxStaticBitmap *image = new wxStaticBitmap(overlay_panel, wxID_ANY, image_bitmap, wxDefaultPosition, overlay_panel->GetSize(), 0); - CenteredStaticText* text_1 = new CenteredStaticText (overlay_panel, wxID_ANY, _L("Smooth"), - wxPoint(overlay_panel->GetSize().GetWidth() / 6, - overlay_panel->GetSize().GetHeight() / 2)); - CenteredStaticText* text_2 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Rough"), - wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, - overlay_panel->GetSize().GetHeight() / 2)); - CenteredStaticText* text_3 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Linear"), - wxPoint(overlay_panel->GetSize().GetWidth() / 2, - overlay_panel->GetSize().GetHeight() * 1.3 / 3)); - CenteredStaticText* text_4 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Angle"), - wxPoint(overlay_panel->GetSize().GetWidth() / 2, - overlay_panel->GetSize().GetHeight() * 2 / 3)); - CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("More faces"), - wxPoint(overlay_panel->GetSize().GetWidth() / 6, - overlay_panel->GetSize().GetHeight() * 2.8 / 3)); - CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Fewer faces"), - wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, - overlay_panel->GetSize().GetHeight() * 2.8 / 3)); + // CenteredStaticText* text_1 = new CenteredStaticText (overlay_panel, wxID_ANY, _L("Smooth"), + // wxPoint(overlay_panel->GetSize().GetWidth() / 6, + // overlay_panel->GetSize().GetHeight() / 2)); + // CenteredStaticText* text_2 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Rough"), + // wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, + // overlay_panel->GetSize().GetHeight() / 2)); + // CenteredStaticText* text_3 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Linear"), + // wxPoint(overlay_panel->GetSize().GetWidth() / 2, + // overlay_panel->GetSize().GetHeight() * 1.3 / 3)); + // CenteredStaticText* text_4 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Reduce Angle"), + // wxPoint(overlay_panel->GetSize().GetWidth() / 2, + // overlay_panel->GetSize().GetHeight() * 2 / 3)); + // CenteredStaticText* text_5 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("More faces"), + // wxPoint(overlay_panel->GetSize().GetWidth() / 6, + // overlay_panel->GetSize().GetHeight() * 2.8 / 3)); + // CenteredStaticText* text_6 = new CenteredStaticText(overlay_panel, wxID_ANY, _L("Fewer faces"), + // wxPoint(overlay_panel->GetSize().GetWidth() * 5 / 6, + // overlay_panel->GetSize().GetHeight() * 2.8 / 3)); - bSizer->Add(overlay_panel, 0, wxALIGN_CENTER | wxALL, 10); + // bSizer->Add(overlay_panel, 0, wxALIGN_CENTER | wxALL, 10); + + wxBoxSizer* tips_sizer = new wxBoxSizer(wxVERTICAL); + wxStaticText* info = new wxStaticText(this, wxID_ANY, _L("Smaller linear and angular deflections result in higher-quality transformations but increase the transfer time.")); + wxStaticText *tips = new wxStaticText(this, wxID_ANY, _L("See BambuLab Wiki")); + wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false); + font.SetUnderlined(true); + tips->SetFont(font); + tips->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { + wxLaunchDefaultBrowser("https://wiki.bambulab.com/en/software/bambu-studio/step"); + }); + info->Wrap(FromDIP(400)); + tips_sizer->Add(info, 0, wxALIGN_LEFT); + tips_sizer->Add(tips, 0, wxALIGN_LEFT); + bSizer->Add(tips_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING); wxBoxSizer* linear_sizer = new wxBoxSizer(wxHORIZONTAL); //linear_sizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); From 6590ccf168ba13405f3b9082da3b568fadd32971 Mon Sep 17 00:00:00 2001 From: Mack Date: Thu, 14 Nov 2024 19:24:46 +0800 Subject: [PATCH 13/23] ENH:translate step mesh text jira: nojira Change-Id: Ic8c9e010551cc9acab9e863e60321a6b64f83778 (cherry picked from commit 228a19e6049bae320560c5eac05580bee354860e) --- src/slic3r/GUI/StepMeshDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 9c4b93099b..fa64b447d0 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -116,7 +116,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line // bSizer->Add(overlay_panel, 0, wxALIGN_CENTER | wxALL, 10); wxBoxSizer* tips_sizer = new wxBoxSizer(wxVERTICAL); - wxStaticText* info = new wxStaticText(this, wxID_ANY, _L("Smaller linear and angular deflections result in higher-quality transformations but increase the transfer time.")); + wxStaticText* info = new wxStaticText(this, wxID_ANY, _L("Smaller linear and angular deflections result in higher-quality transformations but increase the processing time.")); wxStaticText *tips = new wxStaticText(this, wxID_ANY, _L("See BambuLab Wiki")); wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false); font.SetUnderlined(true); From 1e756862212a3c40f6d64562a98c1ae5c56029cb Mon Sep 17 00:00:00 2001 From: Mack Date: Thu, 14 Nov 2024 22:26:34 +0800 Subject: [PATCH 14/23] FIX:If the angle and linear deflections get incorrect values, reset them to the default values jira: nojira Change-Id: Ia2c64a2a0ebe30641192fdb716234f34c356a6c6 (cherry picked from commit f9d9d40c4fd72ddf4c6aaa9b3d45851bf1fe7ffc) --- src/slic3r/GUI/Plater.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 234937c128..c8144da43f 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4159,7 +4159,9 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (boost::iends_with(path.string(), ".stp") || boost::iends_with(path.string(), ".step")) { double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_defletion")); + if (linear <= 0) linear = 0.003; double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_defletion")); + if (angle <= 0) angle = 0.5; 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) { From 588f42e2e272c96c8783d2e92f608d718896a5d1 Mon Sep 17 00:00:00 2001 From: Mack Date: Thu, 28 Nov 2024 12:23:59 +0800 Subject: [PATCH 15/23] NEW:step mesh add 'Split compound and compsolid' Optimize getting STEP node names. Fix load_same_type_files() GITHUB: #5214 Change-Id: I7d1035c122f21e3b08305509489bce415634ae80 (cherry picked from commit 76a401bfca1897994795cb37ffa9cbcbdaca8b6c) (cherry picked from commit a0669137ec7e698320d0bc50ee986cb3f0e85164) --- src/libslic3r/AppConfig.cpp | 3 +++ src/libslic3r/Format/STEP.cpp | 34 ++++++++++++++++++++++--------- src/libslic3r/Format/STEP.hpp | 3 ++- src/libslic3r/Model.cpp | 9 ++++---- src/libslic3r/Model.hpp | 5 +++-- src/slic3r/GUI/Plater.cpp | 12 +++++++---- src/slic3r/GUI/StepMeshDialog.cpp | 7 +++++++ src/slic3r/GUI/StepMeshDialog.hpp | 4 ++++ 8 files changed, 56 insertions(+), 21 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index c8aa08be6b..6efaf3f670 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -416,6 +416,9 @@ void AppConfig::set_defaults() set("linear_defletion", "0.003"); set("angle_defletion", "0.5"); } + if (get("is_split_compound").empty()) { + set_bool("is_split_compound", false); + } // Remove legacy window positions/sizes erase("app", "main_frame_maximized"); diff --git a/src/libslic3r/Format/STEP.cpp b/src/libslic3r/Format/STEP.cpp index 38c507bacd..9b7988c247 100644 --- a/src/libslic3r/Format/STEP.cpp +++ b/src/libslic3r/Format/STEP.cpp @@ -165,16 +165,21 @@ int StepPreProcessor::preNum(const unsigned char byte) { return num; } -static void getNamedSolids(const TopLoc_Location& location, const std::string& prefix, - unsigned int& id, const Handle(XCAFDoc_ShapeTool) shapeTool, - const TDF_Label label, std::vector& namedSolids) { +static void getNamedSolids(const TopLoc_Location& location, + const std::string& prefix, + unsigned int& id, + const Handle(XCAFDoc_ShapeTool) shapeTool, + const TDF_Label label, + std::vector& namedSolids, + bool isSplitCompound = false) { TDF_Label referredLabel{label}; if (shapeTool->IsReference(label)) shapeTool->GetReferredShape(label, referredLabel); std::string name; Handle(TDataStd_Name) shapeName; - if (referredLabel.FindAttribute(TDataStd_Name::GetID(), shapeName)) + if (referredLabel.FindAttribute(TDataStd_Name::GetID(), shapeName) || + label.FindAttribute(TDataStd_Name::GetID(), shapeName)) name = TCollection_AsciiString(shapeName->Get()).ToCString(); if (name == "" || !StepPreProcessor::isUtf8(name)) @@ -185,7 +190,7 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p TDF_LabelSequence components; if (shapeTool->GetComponents(referredLabel, components)) { for (Standard_Integer compIndex = 1; compIndex <= components.Length(); ++compIndex) { - getNamedSolids(localLocation, fullName, id, shapeTool, components.Value(compIndex), namedSolids); + getNamedSolids(localLocation, fullName, id, shapeTool, components.Value(compIndex), namedSolids, isSplitCompound); } } else { TopoDS_Shape shape; @@ -196,11 +201,19 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p int i = 0; switch (shape_type) { case TopAbs_COMPOUND: + if (!isSplitCompound) { + namedSolids.emplace_back(TopoDS::Compound(transform.Shape()), fullName); + break; + } case TopAbs_COMPSOLID: - for (explorer.Init(transform.Shape(), TopAbs_SOLID); explorer.More(); explorer.Next()) { - i++; - const TopoDS_Shape& currentShape = explorer.Current(); - namedSolids.emplace_back(TopoDS::Solid(currentShape), fullName + "-SOLID-" + std::to_string(i)); + if (!isSplitCompound) { + namedSolids.emplace_back(TopoDS::CompSolid(transform.Shape()), fullName); + } else { + for (explorer.Init(transform.Shape(), TopAbs_SOLID); explorer.More(); explorer.Next()) { + i++; + const TopoDS_Shape& currentShape = explorer.Current(); + namedSolids.emplace_back(TopoDS::Solid(currentShape), fullName + "-SOLID-" + std::to_string(i)); + } } break; case TopAbs_SOLID: @@ -218,6 +231,7 @@ static void getNamedSolids(const TopLoc_Location& location, const std::string& p bool load_step(const char *path, Model *model, bool& is_cancel, double linear_defletion/*=0.003*/, double angle_defletion/*= 0.5*/, + bool isSplitCompound, ImportStepProgressFn stepFn, StepIsUtf8Fn isUtf8Fn, long& mesh_face_num) { bool cb_cancel = false; @@ -266,7 +280,7 @@ bool load_step(const char *path, Model *model, bool& is_cancel, return false; } } - getNamedSolids(TopLoc_Location{}, "", id, shapeTool, topLevelShapes.Value(iLabel), namedSolids); + getNamedSolids(TopLoc_Location{}, "", id, shapeTool, topLevelShapes.Value(iLabel), namedSolids, isSplitCompound); } std::vector stl; diff --git a/src/libslic3r/Format/STEP.hpp b/src/libslic3r/Format/STEP.hpp index 40c8669b86..85c8f655ef 100644 --- a/src/libslic3r/Format/STEP.hpp +++ b/src/libslic3r/Format/STEP.hpp @@ -40,6 +40,7 @@ extern bool load_step(const char *path, Model *model, bool& is_cancel, double linear_defletion = 0.003, double angle_defletion = 0.5, + bool isSplitCompound = false, ImportStepProgressFn proFn = nullptr, StepIsUtf8Fn isUtf8Fn = nullptr, long& mesh_face_num = *(new long(-1))); @@ -62,7 +63,7 @@ public: bool preprocess(const char* path, std::string &output_path); static bool isUtf8File(const char* path); static bool isUtf8(const std::string str); -private: +private: static bool isGBK(const std::string str); static int preNum(const unsigned char byte); //BBS: default is UTF8 for most step file. diff --git a/src/libslic3r/Model.cpp b/src/libslic3r/Model.cpp index be27f7c704..1911deafaa 100644 --- a/src/libslic3r/Model.cpp +++ b/src/libslic3r/Model.cpp @@ -181,9 +181,10 @@ Model Model::read_from_step(const std::string& LoadStrategy options, ImportStepProgressFn stepFn, StepIsUtf8Fn stepIsUtf8Fn, - std::function step_mesh_fn, + std::function step_mesh_fn, double linear_defletion, - double angle_defletion) + double angle_defletion, + bool is_split_compound) { Model model; bool result = false; @@ -192,12 +193,12 @@ Model Model::read_from_step(const std::string& Step step_file(input_file); step_file.load(); if (step_mesh_fn) { - if (step_mesh_fn(step_file, linear_defletion, angle_defletion) == -1) { + if (step_mesh_fn(step_file, linear_defletion, angle_defletion, is_split_compound) == -1) { Model empty_model; return empty_model; } } - result = load_step(input_file.c_str(), &model, is_cb_cancel, linear_defletion, angle_defletion, stepFn, stepIsUtf8Fn); + result = load_step(input_file.c_str(), &model, is_cb_cancel, linear_defletion, angle_defletion, is_split_compound, stepFn, stepIsUtf8Fn); if (is_cb_cancel) { Model empty_model; return empty_model; diff --git a/src/libslic3r/Model.hpp b/src/libslic3r/Model.hpp index 1e45f6bb7d..cee1f732c6 100644 --- a/src/libslic3r/Model.hpp +++ b/src/libslic3r/Model.hpp @@ -1535,9 +1535,10 @@ public: LoadStrategy options, ImportStepProgressFn stepFn, StepIsUtf8Fn stepIsUtf8Fn, - std::function step_mesh_fn, + std::function step_mesh_fn, double linear_defletion, - double angle_defletion); + double angle_defletion, + bool is_split_compound); //BBS: add part plate related logic // BBS: backup diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index c8144da43f..2ebeda4267 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4162,6 +4162,7 @@ std::vector Plater::priv::load_files(const std::vector& input_ if (linear <= 0) linear = 0.003; double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_defletion")); if (angle <= 0) angle = 0.5; + bool split_compound = wxGetApp().app_config->get_bool("is_split_compound"); 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) { @@ -4187,22 +4188,24 @@ std::vector Plater::priv::load_files(const std::vector& input_ } } }, - [this, &path, &is_user_cancel, &linear, &angle](Slic3r::Step& file, double& linear_value, double& angle_value)-> int { + [this, &path, &is_user_cancel, &linear, &angle, &split_compound](Slic3r::Step& file, double& linear_value, double& angle_value, bool& is_split)-> int { if (wxGetApp().app_config->get_bool("enable_step_mesh_setting")) { StepMeshDialog mesh_dlg(nullptr, file, linear, angle); if (mesh_dlg.ShowModal() == wxID_OK) { linear_value = mesh_dlg.get_linear_defletion(); - angle_value = mesh_dlg.get_angle_defletion(); + angle_value = mesh_dlg.get_angle_defletion(); + is_split = mesh_dlg.get_split_compound_value(); return 1; } }else { linear_value = linear; angle_value = angle; + is_split = split_compound; return 1; } is_user_cancel = true; return -1; - }, linear, angle); + }, linear, angle, split_compound); }else { model = Slic3r::Model:: read_from_file( path.string(), nullptr, nullptr, strategy, &plate_data, &project_presets, &is_xxx, &file_version, nullptr, @@ -5966,7 +5969,8 @@ void Plater::priv::reload_from_disk() boost::iends_with(path, ".step")) { double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_defletion")); double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_defletion")); - new_model = Model::read_from_step(path, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, nullptr, nullptr, nullptr, linear, angle); + bool is_split = wxGetApp().app_config->get_bool("is_split_compound"); + new_model = Model::read_from_step(path, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, nullptr, nullptr, nullptr, linear, angle, is_split); }else { new_model = Model::read_from_file(path, nullptr, nullptr, LoadStrategy::AddDefaultInstances | LoadStrategy::LoadModel, &plate_data, &project_presets, nullptr, nullptr, nullptr, nullptr, nullptr, 0, obj_color_fun); } diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index fa64b447d0..fe9dbc9bbf 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -235,6 +235,12 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line bSizer->Add(angle_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); + wxBoxSizer* check_sizer = new wxBoxSizer(wxHORIZONTAL); + m_split_compound_checkbox = new wxCheckBox(this, wxID_ANY, _L("Split compound and compsolid into multiple objects"), wxDefaultPosition, wxDefaultSize, 0); + m_split_compound_checkbox->SetValue(wxGetApp().app_config->get_bool("is_split_compound")); + check_sizer->Add(m_split_compound_checkbox, 0, wxALIGN_LEFT); + bSizer->Add(check_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); + wxBoxSizer* mesh_face_number_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText *mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets") + ": "); mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("0")); @@ -267,6 +273,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line if (m_checkbox->IsChecked()) { wxGetApp().app_config->set_bool("enable_step_mesh_setting", false); } + wxGetApp().app_config->set_bool("is_split_compound", m_split_compound_checkbox->GetValue()); wxGetApp().app_config->set("linear_defletion", float_to_string_decimal_point(get_linear_defletion(), 3)); wxGetApp().app_config->set("angle_defletion", float_to_string_decimal_point(get_angle_defletion(), 2)); diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index d746226ca0..0ccf5d3e67 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -29,11 +29,15 @@ public: return m_last_angle; } } + inline bool get_split_compound_value() { + return m_split_compound_checkbox->GetValue(); + } private: Slic3r::Step& m_file; Button* m_button_ok = nullptr; Button* m_button_cancel = nullptr; wxCheckBox* m_checkbox = nullptr; + wxCheckBox* m_split_compound_checkbox = nullptr; wxString m_linear_last; wxString m_angle_last; wxStaticText* mesh_face_number_text; From d14571edfe8b889b1a87a870474ed7963de9087e Mon Sep 17 00:00:00 2001 From: Mack Date: Mon, 23 Dec 2024 15:12:34 +0800 Subject: [PATCH 16/23] ENH:Optimize the STEP mesh UI jira: nojira Change-Id: Ie8d4f1eace04b2c51d4975c67b9a4deb7d88a56f (cherry picked from commit b9aa0397600ab0f5040ac719277c7b16b1371435) --- src/slic3r/GUI/StepMeshDialog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index fe9dbc9bbf..5035bf51d7 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -117,9 +117,10 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxBoxSizer* tips_sizer = new wxBoxSizer(wxVERTICAL); wxStaticText* info = new wxStaticText(this, wxID_ANY, _L("Smaller linear and angular deflections result in higher-quality transformations but increase the processing time.")); - wxStaticText *tips = new wxStaticText(this, wxID_ANY, _L("See BambuLab Wiki")); + wxStaticText *tips = new wxStaticText(this, wxID_ANY, _L("View Wiki for more information")); wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false); font.SetUnderlined(true); + tips->SetForegroundColour(wxColour(0, 174, 66)); tips->SetFont(font); tips->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { wxLaunchDefaultBrowser("https://wiki.bambulab.com/en/software/bambu-studio/step"); From affa9068f0604ec23af27d500d131ac36da607b1 Mon Sep 17 00:00:00 2001 From: mack-test Date: Fri, 10 Jan 2025 16:32:29 +0800 Subject: [PATCH 17/23] Fix:on Mac,step mesh shows a count of 0 initially jira: STUDIO-9595 Change-Id: I9908d3eff394ada12dd9ab0a2c10ca8a78d4f1f6 (cherry picked from commit 8bafed6e0a0ac7237077e7e0a964706e35e5ed12) --- src/slic3r/GUI/StepMeshDialog.cpp | 10 +++++----- src/slic3r/GUI/StepMeshDialog.hpp | 1 + 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 5035bf51d7..c29151d7a0 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -344,22 +344,22 @@ void StepMeshDialog::stop_task() void StepMeshDialog::update_mesh_number_text() { - if (m_last_linear == get_linear_defletion() && m_last_angle == get_angle_defletion()) + if ((m_last_linear == get_linear_defletion()) && (m_last_angle == get_angle_defletion()) && (m_mesh_number != 0)) return; wxString newText = wxString::Format(_L("Calculating, please wait...")); mesh_face_number_text->SetLabel(newText); stop_task(); task = std::async(std::launch::async, [&] { - unsigned int number = m_file.get_triangle_num(get_linear_defletion(), get_angle_defletion()); - if (number != 0) { - wxString number_text = wxString::Format("%d", number); + unsigned int m_mesh_number = m_file.get_triangle_num(get_linear_defletion(), get_angle_defletion()); + if (m_mesh_number != 0) { + wxString number_text = wxString::Format("%d", m_mesh_number); wxCommandEvent event(wxEVT_THREAD_DONE); event.SetString(number_text); wxPostEvent(this, event); m_last_linear = get_linear_defletion(); m_last_angle = get_angle_defletion(); } - return number; + return m_mesh_number; }); } \ No newline at end of file diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index 0ccf5d3e67..1f3804b448 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -43,6 +43,7 @@ private: wxStaticText* mesh_face_number_text; double m_last_linear = 0.003; double m_last_angle = 0.5; + unsigned int m_mesh_number = 0; std::future task; bool validate_number_range(const wxString& value, double min, double max); void update_mesh_number_text(); From 08eeed9c72cad9748b986cda508774ec6bb9b55f Mon Sep 17 00:00:00 2001 From: "yongfang.bian" Date: Mon, 13 Jan 2025 15:46:24 +0800 Subject: [PATCH 18/23] Fix:step mesh using boost thread github: #5304 Change-Id: I4afc5978b00eed20c46a1bf4100c9a0f0328daf8 (cherry picked from commit 151f40ad4dbf871576937f9674ac532c32df27d0) --- src/libslic3r/Format/STEP.cpp | 37 ++++++++++++--------- src/slic3r/GUI/StepMeshDialog.cpp | 55 +++++++++++++++++++------------ src/slic3r/GUI/StepMeshDialog.hpp | 3 +- 3 files changed, 57 insertions(+), 38 deletions(-) diff --git a/src/libslic3r/Format/STEP.cpp b/src/libslic3r/Format/STEP.cpp index 9b7988c247..5105d26776 100644 --- a/src/libslic3r/Format/STEP.cpp +++ b/src/libslic3r/Format/STEP.cpp @@ -464,25 +464,30 @@ void Step::clean_mesh_data() unsigned int Step::get_triangle_num(double linear_defletion, double angle_defletion) { unsigned int tri_num = 0; - Handle(StepProgressIncdicator) progress = new StepProgressIncdicator(m_stop_mesh); - clean_mesh_data(); - IMeshTools_Parameters param; - param.Deflection = linear_defletion; - param.Angle = angle_defletion; - param.InParallel = true; - for (int i = 0; i < m_name_solids.size(); ++i) { - BRepMesh_IncrementalMesh mesh(m_name_solids[i].solid, param, progress->Start()); - for (TopExp_Explorer anExpSF(m_name_solids[i].solid, TopAbs_FACE); anExpSF.More(); anExpSF.Next()) { - TopLoc_Location aLoc; - Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(TopoDS::Face(anExpSF.Current()), aLoc); - if (!aTriangulation.IsNull()) { - tri_num += aTriangulation->NbTriangles(); + try { + Handle(StepProgressIncdicator) progress = new StepProgressIncdicator(m_stop_mesh); + clean_mesh_data(); + IMeshTools_Parameters param; + param.Deflection = linear_defletion; + param.Angle = angle_defletion; + param.InParallel = true; + for (int i = 0; i < m_name_solids.size(); ++i) { + BRepMesh_IncrementalMesh mesh(m_name_solids[i].solid, param, progress->Start()); + for (TopExp_Explorer anExpSF(m_name_solids[i].solid, TopAbs_FACE); anExpSF.More(); anExpSF.Next()) { + TopLoc_Location aLoc; + Handle(Poly_Triangulation) aTriangulation = BRep_Tool::Triangulation(TopoDS::Face(anExpSF.Current()), aLoc); + if (!aTriangulation.IsNull()) { + tri_num += aTriangulation->NbTriangles(); + } + } + if (m_stop_mesh.load()) { + return 0; } } - if (m_stop_mesh.load()) { - return 0; - } + } catch(Exception e) { + return 0; } + return tri_num; } diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index c29151d7a0..65a36c4597 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -19,6 +19,7 @@ static int _scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit( static int _ITEM_WIDTH() { return _scale(30); } #define MIN_DIALOG_WIDTH FromDIP(400) #define SLIDER_WIDTH FromDIP(200) +#define SLIDER_HEIGHT FromDIP(25) #define TEXT_CTRL_WIDTH FromDIP(70) #define BUTTON_SIZE wxSize(FromDIP(58), FromDIP(24)) #define BUTTON_BORDER FromDIP(int(400 - 58 * 2) / 8) @@ -139,7 +140,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxSlider* linear_slider = new wxSlider(this, wxID_ANY, SLIDER_SCALE(get_linear_defletion()), 1, 100, wxDefaultPosition, - wxSize(SLIDER_WIDTH, -1), + wxSize(SLIDER_WIDTH, SLIDER_HEIGHT), wxSL_HORIZONTAL); linear_sizer->Add(linear_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); @@ -191,7 +192,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxSlider* angle_slider = new wxSlider(this, wxID_ANY, SLIDER_SCALE_10(get_angle_defletion()), 1, 100, wxDefaultPosition, - wxSize(SLIDER_WIDTH, -1), + wxSize(SLIDER_WIDTH, SLIDER_HEIGHT), wxSL_HORIZONTAL); angle_sizer->Add(angle_slider, 0, wxALIGN_RIGHT | wxLEFT, FromDIP(5)); @@ -303,7 +304,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line bSizer->Add(bSizer_button, 1, wxEXPAND | wxALL, LEFT_RIGHT_PADING); this->SetSizer(bSizer); - update_mesh_number_text(); + // update_mesh_number_text(); this->Layout(); bSizer->Fit(this); @@ -322,22 +323,34 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxGetApp().UpdateDlgDarkUI(this); } +StepMeshDialog::~StepMeshDialog() +{ + stop_task(); +} + void StepMeshDialog::on_task_done(wxCommandEvent& event) { wxString text = event.GetString(); mesh_face_number_text->SetLabel(text); - if (task.valid()) { - task.get(); + if(m_task) { + if (m_task->joinable()) { + m_task->join(); + delete m_task; + m_task = nullptr; + } } } void StepMeshDialog::stop_task() { - if (task.valid()) { + if(m_task) { m_file.m_stop_mesh.store(true); - unsigned int test = task.get(); + if (m_task->joinable()) { + m_task->join(); + delete m_task; + m_task = nullptr; + } m_file.m_stop_mesh.store(false); - std::cout << test << std::endl; } } @@ -348,18 +361,18 @@ void StepMeshDialog::update_mesh_number_text() return; wxString newText = wxString::Format(_L("Calculating, please wait...")); mesh_face_number_text->SetLabel(newText); - stop_task(); - task = std::async(std::launch::async, [&] { - unsigned int m_mesh_number = m_file.get_triangle_num(get_linear_defletion(), get_angle_defletion()); - if (m_mesh_number != 0) { - wxString number_text = wxString::Format("%d", m_mesh_number); - wxCommandEvent event(wxEVT_THREAD_DONE); - event.SetString(number_text); - wxPostEvent(this, event); - m_last_linear = get_linear_defletion(); - m_last_angle = get_angle_defletion(); - } - return m_mesh_number; - }); + if (!m_task) { + m_task = new boost::thread(Slic3r::create_thread([this]() -> void { + m_mesh_number = m_file.get_triangle_num(get_linear_defletion(), get_angle_defletion()); + if (m_mesh_number != 0) { + wxString number_text = wxString::Format("%d", m_mesh_number); + wxCommandEvent event(wxEVT_THREAD_DONE); + event.SetString(number_text); + wxPostEvent(this, event); + m_last_linear = get_linear_defletion(); + m_last_angle = get_angle_defletion(); + } + })); + } } \ No newline at end of file diff --git a/src/slic3r/GUI/StepMeshDialog.hpp b/src/slic3r/GUI/StepMeshDialog.hpp index 1f3804b448..4ea70ae6e7 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -12,6 +12,7 @@ class StepMeshDialog : public Slic3r::GUI::DPIDialog { public: StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double linear_init, double angle_init); + ~StepMeshDialog() override; void on_dpi_changed(const wxRect& suggested_rect) override; inline double get_linear_defletion() { double value; @@ -44,7 +45,7 @@ private: double m_last_linear = 0.003; double m_last_angle = 0.5; unsigned int m_mesh_number = 0; - std::future task; + boost::thread* m_task {nullptr}; bool validate_number_range(const wxString& value, double min, double max); void update_mesh_number_text(); void on_task_done(wxCommandEvent& event); From 72d8c8292703e99535c7ea46174af032a5a8701d Mon Sep 17 00:00:00 2001 From: MackBambu Date: Mon, 10 Mar 2025 10:03:54 +0800 Subject: [PATCH 19/23] Fix:fix step mesh dark mode on linux jira: STUDIO-10665 Change-Id: I9e9e837441b5627406cdadcbfdaa4c16abc2d762 (cherry picked from commit e02f44d8dde01de0715935e609a5634fc1faee4e) --- src/slic3r/GUI/StepMeshDialog.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 65a36c4597..38c2c55928 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -28,6 +28,7 @@ static int _ITEM_WIDTH() { return _scale(30); } #define SLIDER_SCALE_10(val) ((val) / 0.01) #define SLIDER_UNSCALE_10(val) ((val) * 0.01) #define LEFT_RIGHT_PADING FromDIP(20) +#define FONT_COLOR wxColour("#6B6B6B") wxDEFINE_EVENT(wxEVT_THREAD_DONE, wxCommandEvent); @@ -118,10 +119,11 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxBoxSizer* tips_sizer = new wxBoxSizer(wxVERTICAL); wxStaticText* info = new wxStaticText(this, wxID_ANY, _L("Smaller linear and angular deflections result in higher-quality transformations but increase the processing time.")); + info->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR)); wxStaticText *tips = new wxStaticText(this, wxID_ANY, _L("View Wiki for more information")); wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false); font.SetUnderlined(true); - tips->SetForegroundColour(wxColour(0, 174, 66)); + tips->SetForegroundColour(StateColor::darkModeColorFor(wxColour(0, 174, 66))); tips->SetFont(font); tips->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { wxLaunchDefaultBrowser("https://wiki.bambulab.com/en/software/bambu-studio/step"); @@ -135,6 +137,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line //linear_sizer->SetMinSize(wxSize(MIN_DIALOG_WIDTH, -1)); wxStaticText* linear_title = new wxStaticText(this, wxID_ANY, _L("Linear Deflection") + ": "); + linear_title->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR)); linear_sizer->Add(linear_title, 0, wxALIGN_LEFT); linear_sizer->AddStretchSpacer(1); wxSlider* linear_slider = new wxSlider(this, wxID_ANY, @@ -187,6 +190,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxBoxSizer* angle_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText* angle_title = new wxStaticText(this, wxID_ANY, _L("Angle Deflection") + ": "); + angle_title->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR)); angle_sizer->Add(angle_title, 0, wxALIGN_LEFT); angle_sizer->AddStretchSpacer(1); wxSlider* angle_slider = new wxSlider(this, wxID_ANY, @@ -239,13 +243,16 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxBoxSizer* check_sizer = new wxBoxSizer(wxHORIZONTAL); m_split_compound_checkbox = new wxCheckBox(this, wxID_ANY, _L("Split compound and compsolid into multiple objects"), wxDefaultPosition, wxDefaultSize, 0); + m_split_compound_checkbox->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR)); m_split_compound_checkbox->SetValue(wxGetApp().app_config->get_bool("is_split_compound")); check_sizer->Add(m_split_compound_checkbox, 0, wxALIGN_LEFT); bSizer->Add(check_sizer, 1, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING); wxBoxSizer* mesh_face_number_sizer = new wxBoxSizer(wxHORIZONTAL); wxStaticText *mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets") + ": "); + mesh_face_number_title->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR)); mesh_face_number_text = new wxStaticText(this, wxID_ANY, _L("0")); + mesh_face_number_text->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR)); mesh_face_number_text->SetMinSize(wxSize(FromDIP(150), -1)); mesh_face_number_sizer->Add(mesh_face_number_title, 0, wxALIGN_LEFT); mesh_face_number_sizer->Add(mesh_face_number_text, 0, wxALIGN_LEFT); @@ -254,6 +261,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line 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); + m_checkbox->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR)); 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), From b65d6172cc7f0e4531a1fc48cf9eb8d64dbf91b8 Mon Sep 17 00:00:00 2001 From: Mack Date: Tue, 11 Mar 2025 18:52:57 +0800 Subject: [PATCH 20/23] Fix:Step mesh didn't initially count faces jira: STUDIO-10273 Change-Id: Ic7e672edae03f5ce00e564eaf82dd1c474b84558 (cherry picked from commit 7e4932eec4a12e02f0f40b5e783d38ae1b66a30a) --- src/slic3r/GUI/StepMeshDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 38c2c55928..41f24608e3 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -312,7 +312,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line bSizer->Add(bSizer_button, 1, wxEXPAND | wxALL, LEFT_RIGHT_PADING); this->SetSizer(bSizer); - // update_mesh_number_text(); + update_mesh_number_text(); this->Layout(); bSizer->Fit(this); From ef8649910ff0de07c22370df89860a4af89e60fe Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 27 Mar 2025 23:43:20 +0800 Subject: [PATCH 21/23] Fix build failure caused by OCCT and boost::regex --- src/libslic3r/pchheader.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libslic3r/pchheader.hpp b/src/libslic3r/pchheader.hpp index e6591f5740..349e3f0d4c 100644 --- a/src/libslic3r/pchheader.hpp +++ b/src/libslic3r/pchheader.hpp @@ -88,6 +88,7 @@ #include #include #include +#include // boost/property_tree/json_parser/detail/parser.hpp includes boost/bind.hpp, which is deprecated. // Suppress the following boost message: From 5c7cb0578faff2f4f325d10d4b6aff3c48a0e8c5 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Thu, 27 Mar 2025 23:58:20 +0800 Subject: [PATCH 22/23] Update link color --- src/slic3r/GUI/StepMeshDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/slic3r/GUI/StepMeshDialog.cpp b/src/slic3r/GUI/StepMeshDialog.cpp index 41f24608e3..c2ad838c66 100644 --- a/src/slic3r/GUI/StepMeshDialog.cpp +++ b/src/slic3r/GUI/StepMeshDialog.cpp @@ -123,7 +123,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line wxStaticText *tips = new wxStaticText(this, wxID_ANY, _L("View Wiki for more information")); wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false); font.SetUnderlined(true); - tips->SetForegroundColour(StateColor::darkModeColorFor(wxColour(0, 174, 66))); + tips->SetForegroundColour(StateColor::darkModeColorFor(wxColour(0, 151, 137))); tips->SetFont(font); tips->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { wxLaunchDefaultBrowser("https://wiki.bambulab.com/en/software/bambu-studio/step"); From 5dee7297cf4243151ad115b6e2dfd7c18020e254 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Fri, 28 Mar 2025 09:13:18 +0800 Subject: [PATCH 23/23] Fix mac build error --- src/slic3r/pchheader.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/slic3r/pchheader.hpp b/src/slic3r/pchheader.hpp index 7519cbb399..591b41092d 100644 --- a/src/slic3r/pchheader.hpp +++ b/src/slic3r/pchheader.hpp @@ -9,10 +9,6 @@ #include #endif -#ifdef __APPLE__ - #include -#endif - #include #include #include