From 6c48a8e40b3a28859d5883b13106683cbe61c73d Mon Sep 17 00:00:00 2001 From: Mack Date: Wed, 13 Nov 2024 15:27:44 +0800 Subject: [PATCH] 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 --- 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 c12b253a5..28f840853 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 5eb70f075..036b6d50b 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -4021,10 +4021,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) { @@ -4043,7 +4043,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(); @@ -5846,8 +5846,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 4963b7d97..df49232aa 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 ad342a774..8c5192c74 100644 --- a/src/slic3r/GUI/StepMeshDialog.hpp +++ b/src/slic3r/GUI/StepMeshDialog.hpp @@ -12,20 +12,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() { @@ -33,7 +27,7 @@ public: if (m_angle_last.ToDouble(&value)) { return value; } else { - return get_angle_init(); + return m_last_angle; } } private: @@ -41,8 +35,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;