Exposing STEP import values (#14484)

Co-authored-by: yw4z <ywsyildiz@gmail.com>
This commit is contained in:
Ian Bassi
2026-07-03 17:19:24 -03:00
committed by GitHub
parent 5a629c0199
commit 8309a9e8ee
11 changed files with 120 additions and 51 deletions

View File

@@ -2316,9 +2316,9 @@ void ObjectList::load_modifier(const wxArrayString& input_files, ModelObject& mo
try {
if (boost::iends_with(input_file, ".stp") ||
boost::iends_with(input_file, ".step")) {
double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_defletion"));
double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_deflection"));
if (linear <= 0) linear = 0.003;
double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_defletion"));
double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_deflection"));
if (angle <= 0) angle = 0.5;
bool split_compound = wxGetApp().app_config->get_bool("is_split_compound");
model = Model::read_from_step(
@@ -2328,8 +2328,8 @@ void ObjectList::load_modifier(const wxArrayString& input_files, ModelObject& mo
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();
linear_value = mesh_dlg.get_linear_deflection();
angle_value = mesh_dlg.get_angle_deflection();
is_split = mesh_dlg.get_split_compound_value();
return 1;
}

View File

@@ -6637,9 +6637,9 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& 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"));
double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_deflection"));
if (linear <= 0) linear = 0.003;
double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_defletion"));
double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_deflection"));
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,
@@ -6671,8 +6671,8 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
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();
linear_value = mesh_dlg.get_linear_deflection();
angle_value = mesh_dlg.get_angle_deflection();
is_split = mesh_dlg.get_split_compound_value();
return 1;
}
@@ -8418,8 +8418,8 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const
const bool is_step = boost::algorithm::iends_with(path, ".stp") || boost::algorithm::iends_with(path, ".step");
if (is_step) {
auto config = wxGetApp().app_config;
double linear = std::max(0.003, string_to_double_decimal_point(config->get("linear_defletion")));
double angle = std::max(0.5, string_to_double_decimal_point(config->get("angle_defletion")));
double linear = std::max(0.003, string_to_double_decimal_point(config->get("linear_deflection")));
double angle = std::max(0.5, string_to_double_decimal_point(config->get("angle_deflection")));
bool split_compound = config->get_bool("is_split_compound");
bool is_user_cancel = false;
@@ -8427,8 +8427,8 @@ bool Plater::priv::replace_volume_with_stl(int object_idx, int volume_idx, const
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();
linear_value = mesh_dlg.get_linear_deflection();
angle_value = mesh_dlg.get_angle_deflection();
is_split = mesh_dlg.get_split_compound_value();
return 1;
}
@@ -8911,8 +8911,8 @@ void Plater::priv::reload_from_disk()
// BBS: backup
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"));
double linear = string_to_double_decimal_point(wxGetApp().app_config->get("linear_deflection"));
double angle = string_to_double_decimal_point(wxGetApp().app_config->get("angle_deflection"));
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 {

View File

@@ -783,6 +783,47 @@ wxBoxSizer *PreferencesDialog::create_camera_orbit_mult_input(wxString title, wx
return m_sizer;
}
wxBoxSizer *PreferencesDialog::create_item_decimal_input(wxString title, wxString title2, wxString tooltip, std::string param, double min, double max, int decimals, const wxString wiki_url)
{
auto tip = tooltip.IsEmpty() ? title : tooltip; // auto fill tooltips with title if its empty
wxBoxSizer *m_sizer = create_item_label(title, tip, wiki_url);
auto input = new ::TextInput(m_parent, wxEmptyString, title2, wxEmptyString, wxDefaultPosition, DESIGN_INPUT_SIZE, wxTE_PROCESS_ENTER);
StateColor input_bg(std::pair<wxColour, int>(wxColour("#F0F0F1"), StateColor::Disabled), std::pair<wxColour, int>(*wxWHITE, StateColor::Enabled));
input->SetBackgroundColor(input_bg);
input->GetTextCtrl()->SetValue(app_config->get(param));
wxTextValidator validator(wxFILTER_NUMERIC);
input->SetToolTip(tooltip);
input->GetTextCtrl()->SetValidator(validator);
m_sizer->Add(input, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, FromDIP(5));
auto apply_value = [this, param, input, min, max, decimals]() {
auto value = input->GetTextCtrl()->GetValue();
double conv = min;
if (value.ToCDouble(&conv)) {
conv = conv < min ? min : conv > max ? max : conv;
auto strval = std::string(wxString::FromCDouble(conv, decimals).mb_str());
input->GetTextCtrl()->SetValue(strval);
app_config->set(param, strval);
}
};
input->GetTextCtrl()->Bind(wxEVT_TEXT_ENTER, [apply_value](wxCommandEvent &e) {
apply_value();
wxGetApp().app_config->save();
e.Skip();
});
input->GetTextCtrl()->Bind(wxEVT_KILL_FOCUS, [apply_value](wxFocusEvent &e) {
apply_value();
e.Skip();
});
return m_sizer;
}
wxBoxSizer *PreferencesDialog::create_item_backup(wxString title, wxString tooltip)
{
auto tip = tooltip.IsEmpty() ? title : tooltip; // auto fill tooltips with title if its empty
@@ -1605,6 +1646,15 @@ void PreferencesDialog::create_items()
);
g_sizer->Add(item_step_dialog);
auto item_step_linear = create_item_decimal_input(_L("STEP importing: linear deflection"), "mm", _L("Linear deflection used when meshing imported STEP files.\nSmaller values produce higher-quality meshes but increase processing time.\nUsed as the default in the import dialog, or directly when the import dialog is disabled.\nDefault: 0.003 mm."), "linear_deflection", 0.001, 0.1, 3);
g_sizer->Add(item_step_linear);
auto item_step_angle = create_item_decimal_input(_L("STEP importing: angle deflection"), "", _L("Angle deflection used when meshing imported STEP files.\nSmaller values produce higher-quality meshes but increase processing time.\nUsed as the default in the import dialog, or directly when the import dialog is disabled.\nDefault: 0.5."), "angle_deflection", 0.01, 1.0, 2);
g_sizer->Add(item_step_angle);
auto item_step_split = create_item_checkbox(_L("STEP importing: Split into multiple objects"), _L("If enabled, compound and compsolid shapes in imported STEP files are split into multiple objects.\nUsed as the default in the import dialog, or directly when the import dialog is disabled.\nDefault: disabled."), "is_split_compound");
g_sizer->Add(item_step_split);
auto item_draco_bits = create_item_spinctrl(_L("Quality level for Draco export"), "",
_L("bits"),
_L("Controls the quantization bit depth used when compressing the mesh to Draco format.\n"

View File

@@ -96,6 +96,7 @@ public:
wxBoxSizer *create_item_input(wxString title, wxString title2, wxString tooltip, std::string param, std::function<void(wxString)> onchange = {}, const wxString wiki_url = "");
wxBoxSizer *create_item_spinctrl(wxString title, wxString title2, wxString side_label, wxString tooltip, std::string param, int min, int max, std::function<void(int)> onchange = nullptr, const wxString wiki_url = "");
wxBoxSizer *create_camera_orbit_mult_input(wxString title, wxString tooltip);
wxBoxSizer *create_item_decimal_input(wxString title, wxString title2, wxString tooltip, std::string param, double min, double max, int decimals, const wxString wiki_url = "");
wxBoxSizer *create_item_backup(wxString title, wxString tooltip);
wxBoxSizer *create_item_auto_reslice(wxString title, wxString checkbox_tooltip, wxString delay_tooltip);
wxBoxSizer *create_item_bambu_cloud(wxString title, wxString tooltip);

View File

@@ -144,7 +144,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line
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()),
SLIDER_SCALE(get_linear_deflection()),
1, 100, wxDefaultPosition,
wxSize(SLIDER_WIDTH, SLIDER_HEIGHT),
wxSL_HORIZONTAL);
@@ -199,7 +199,7 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line
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()),
SLIDER_SCALE_10(get_angle_deflection()),
1, 100, wxDefaultPosition,
wxSize(SLIDER_WIDTH, SLIDER_HEIGHT),
wxSL_HORIZONTAL);
@@ -265,6 +265,14 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line
mesh_face_number_sizer->Add(mesh_face_number_text, 0, wxALIGN_LEFT);
bSizer->Add(mesh_face_number_sizer, 0, wxEXPAND | wxALL, LEFT_RIGHT_PADING);
wxBoxSizer* save_default_sizer = new wxBoxSizer(wxHORIZONTAL);
m_save_default_checkbox = new wxCheckBox(this, wxID_ANY, _L("Save these settings as default"), wxDefaultPosition, wxDefaultSize, 0);
m_save_default_checkbox->SetFont(::Label::Body_14);
m_save_default_checkbox->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR));
m_save_default_checkbox->SetToolTip(_L("If enabled, the values above are stored as the defaults used for future STEP imports (and shown in Preferences)."));
save_default_sizer->Add(m_save_default_checkbox, 0, wxALIGN_LEFT);
bSizer->Add(save_default_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT, LEFT_RIGHT_PADING);
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);
@@ -284,9 +292,11 @@ 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));
if (m_save_default_checkbox->IsChecked()) {
wxGetApp().app_config->set_bool("is_split_compound", m_split_compound_checkbox->GetValue());
wxGetApp().app_config->set("linear_deflection", float_to_string_decimal_point(get_linear_deflection(), 3));
wxGetApp().app_config->set("angle_deflection", float_to_string_decimal_point(get_angle_deflection(), 2));
}
EndModal(wxID_OK);
}
@@ -354,21 +364,21 @@ void StepMeshDialog::stop_task()
void StepMeshDialog::update_mesh_number_text()
{
if ((m_last_linear == get_linear_defletion()) && (m_last_angle == get_angle_defletion()) && (m_mesh_number != 0))
if ((m_last_linear == get_linear_deflection()) && (m_last_angle == get_angle_deflection()) && (m_mesh_number != 0))
return;
wxString newText = wxString::Format(_L("Calculating, please wait..."));
mesh_face_number_text->SetLabel(newText);
stop_task();
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());
m_mesh_number = m_file.get_triangle_num(get_linear_deflection(), get_angle_deflection());
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();
m_last_linear = get_linear_deflection();
m_last_angle = get_angle_deflection();
}
}));
}

View File

@@ -14,7 +14,7 @@ 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() {
inline double get_linear_deflection() {
double value;
if (m_linear_last.ToDouble(&value)) {
return value;
@@ -22,7 +22,7 @@ public:
return m_last_linear;
}
}
inline double get_angle_defletion() {
inline double get_angle_deflection() {
double value;
if (m_angle_last.ToDouble(&value)) {
return value;
@@ -37,6 +37,7 @@ private:
Slic3r::Step& m_file;
wxCheckBox* m_checkbox = nullptr;
wxCheckBox* m_split_compound_checkbox = nullptr;
wxCheckBox* m_save_default_checkbox = nullptr;
wxString m_linear_last;
wxString m_angle_last;
wxStaticText* mesh_face_number_text;