mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-30 17:05:35 -05:00
Keep original body names when importing STEP, AMF and 3MF geometry (#17050)
* Keep original body names when importing STEP, AMF and 3MF geometry STEP, AMF and 3MF bodies keep the names stored in the file. The three formats share one geometry import path with matching dialogs, per-format Preferences and cleanup of unsupported characters. AMF body groups load as one object, nested groups are flattened, and a CAD 3MF is imported as geometry. * Use the app's widgets in the geometry import dialogs Check boxes, radio buttons and the name replacement field in the STEP, AMF/3MF and name cleanup dialogs now use the app's own controls instead of the native ones; the name cleanup preview uses the dialogs' label font. * Address review: AMF layout, Open Project cancel, part visibility - AMF: the import dialog offers "Separate objects (as before)" first and uses it by default, so files from PrusaSlicer and Slic3r, which keep a whole plate in one constellation, load as separate objects again. The assembly modes are opt-in. - File > Open Project with a CAD 3MF replaces the project only after the import dialogs were answered and the file was read with geometry to load. A Cancel or an empty file keeps the current project, its unsaved state, notifications and preview state; close_with_confirm() can hand back its closing steps for this. - The object list no longer changes the model while it checks whether a single-object import hides its parts: ModelObject::hides_imported_parts() is used by the list, Split to parts and its menu check, and the painting gizmos' list update shows or hides the parts when painting changes. Removing the part rows keeps the object a container for its instances. - Progress: staged reading takes the first part of the bar and never goes back within a file; the load loop takes the rest. - A constellation id equal to an object id is logged as a warning. - set_import_volume_order() is defined next to sort_objects(). * Address review: part rename on drag, Multi-part check for unplaced AMF - Dragging a part of an imported object cancels a name editor that is still open before the part rows are rebuilt. On GTK the editor opened by pressing the selected row outlived the deleted row and wrote its name into another part. - The Multi-part check reads zero for objects the file does not place, as min_z() did in Release builds, instead of their mesh height: the meshes are already centered by then, so different heights asked the question where main does not. - Non-printable AMF groups skip the Multi-part question only in the assembly modes; Separate objects asks as before. - The first AMF load mode is "Load as separate objects". --------- Co-authored-by: yw4z <ywsyildiz@gmail.com>
This commit is contained in:
1 parent
e2acd9ec06
commit
fa5f7e3db4
34 files changed
+3320
-209
No files matched your search
@@ -1,6 +1,7 @@
|
||||
#include "StepMeshDialog.hpp"
|
||||
|
||||
#include "libslic3r/Format/STEP.hpp"
|
||||
#include "slic3r/GUI/GeometryImportDialog.hpp"
|
||||
#include "slic3r/GUI/GUI_Utils.hpp"
|
||||
#include "slic3r/GUI/Widgets/StateColor.hpp"
|
||||
#include "slic3r/GUI/Widgets/Label.hpp"
|
||||
@@ -14,6 +15,7 @@
|
||||
#include <wx/gdicmn.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/slider.h>
|
||||
#include <wx/tglbtn.h>
|
||||
#include <wx/dcmemory.h>
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
@@ -21,6 +23,7 @@
|
||||
#include "Widgets/Button.hpp"
|
||||
#include "Widgets/TextInput.hpp"
|
||||
#include "Widgets/DialogButtons.hpp"
|
||||
#include "Widgets/RadioGroup.hpp"
|
||||
#include "Widgets/RoundedRectangle.hpp"
|
||||
#include <chrono>
|
||||
#include <wx/string.h>
|
||||
@@ -84,13 +87,14 @@ bool StepMeshDialog:: validate_number_range(const wxString& value, double min, d
|
||||
return (num >= min && num <= max);
|
||||
}
|
||||
|
||||
StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double linear_init, double angle_init)
|
||||
StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double linear_init, double angle_init,
|
||||
Slic3r::GUI::GeometryImportOptions* import_options)
|
||||
: DPIDialog(parent ? parent : static_cast<wxWindow *>(wxGetApp().mainframe),
|
||||
wxID_ANY,
|
||||
_(L("STEP file import parameters")),
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize,
|
||||
wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/), m_file(file)
|
||||
wxDEFAULT_DIALOG_STYLE /* | wxRESIZE_BORDER*/), m_import_options(import_options), m_file(file)
|
||||
{
|
||||
m_linear_last = wxString::Format("%.3f", linear_init);
|
||||
m_angle_last = wxString::Format("%.2f", angle_init);
|
||||
@@ -255,13 +259,38 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line
|
||||
|
||||
bSizer->Add(angle_sizer, 0, 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->SetFont(::Label::Body_14);
|
||||
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, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
|
||||
// App-styled check boxes, the same as in the AMF and 3MF import dialogs.
|
||||
m_split_compound_checkbox = add_import_checkbox(this, *bSizer, _L("Split compound and compsolid into multiple objects"),
|
||||
wxGetApp().app_config->get_bool("is_split_compound"), wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
|
||||
if (m_import_options != nullptr) {
|
||||
m_split_compound_checkbox.SetToolTip(_L("Loads each body of a multi-body part separately. Needed to keep the bodies' original names."));
|
||||
m_split_compound_checkbox.SetValue(m_import_options->split_compound);
|
||||
m_load_mode = new RadioGroup(this, {_L("Load as an assembly"), _L("Load as a single object (can be split later)")}, wxVERTICAL);
|
||||
m_load_mode->SetSelection(m_import_options->load_as_assembly ? 0 : 1);
|
||||
m_load_mode->SetRadioTooltip(1, _L("The original bodies and names are kept inside the object. Use Split to parts to show them as separate parts."));
|
||||
bSizer->Add(m_load_mode, 0, wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
|
||||
m_keep_names_checkbox = add_import_checkbox(this, *bSizer, _L("Keep original names"), m_import_options->keep_names,
|
||||
wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
|
||||
m_keep_names_checkbox.SetToolTip(_L("Use the body names stored in the file, when there are any. Needs Split compound for parts with several bodies."));
|
||||
m_sort_names_checkbox = add_import_checkbox(this, *bSizer, _L("Sort parts by name"), m_import_options->sort_names,
|
||||
wxLEFT | wxRIGHT | wxTOP, LEFT_RIGHT_PADING);
|
||||
m_sort_names_checkbox.SetToolTip(_L("Sort the parts inside each imported assembly in the object list. This does not change the order used for slicing. Available when Keep original names is on."));
|
||||
// The dialog opens with the remembered values; only the user's clicks move the linked option.
|
||||
m_keep_names_checkbox.box->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) {
|
||||
// Body names of a multi-body part exist only after splitting it.
|
||||
if (m_keep_names_checkbox.GetValue())
|
||||
m_split_compound_checkbox.SetValue(true);
|
||||
e.Skip();
|
||||
});
|
||||
m_split_compound_checkbox.box->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent& e) {
|
||||
if (!m_split_compound_checkbox.GetValue() && m_keep_names_checkbox.GetValue()) {
|
||||
m_keep_names_checkbox.SetValue(false);
|
||||
m_sort_names_checkbox.Enable(false);
|
||||
}
|
||||
e.Skip();
|
||||
});
|
||||
Slic3r::GUI::link_sort_to_keep(m_keep_names_checkbox, m_sort_names_checkbox);
|
||||
}
|
||||
|
||||
wxBoxSizer* mesh_face_number_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
wxStaticText *mesh_face_number_title = new wxStaticText(this, wxID_ANY, _L("Number of triangular facets") + ": ");
|
||||
@@ -276,20 +305,16 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line
|
||||
|
||||
bSizer->AddSpacer(FromDIP(10));
|
||||
|
||||
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);
|
||||
m_save_default_checkbox = add_import_checkbox(this, *bSizer,
|
||||
m_import_options ? _L("Remember my choice") : _L("Save these settings as default"), false, wxLEFT | wxRIGHT, LEFT_RIGHT_PADING);
|
||||
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)."));
|
||||
|
||||
bSizer->AddSpacer(FromDIP(10));
|
||||
|
||||
m_checkbox = new wxCheckBox(this, wxID_ANY, _L("Don't show again"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_checkbox->SetFont(::Label::Body_14);
|
||||
m_checkbox->SetForegroundColour(StateColor::darkModeColorFor(FONT_COLOR));
|
||||
bSizer->Add(m_checkbox, 0, wxLEFT, LEFT_RIGHT_PADING);
|
||||
m_checkbox = add_import_checkbox(this, *bSizer,
|
||||
m_import_options ? _L("Don't ask again") : _L("Don't show again"), false, wxLEFT, LEFT_RIGHT_PADING);
|
||||
if (m_import_options != nullptr)
|
||||
m_checkbox.SetToolTip(_L("Save these choices and apply them without asking next time. You can show this dialog again in Preferences."));
|
||||
|
||||
wxBoxSizer* bSizer_button = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
@@ -312,13 +337,26 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line
|
||||
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);
|
||||
}
|
||||
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));
|
||||
if (m_import_options != nullptr) {
|
||||
// The callback uses these values now; AppConfig is updated only after batch success.
|
||||
m_import_options->keep_names = m_keep_names_checkbox.GetValue();
|
||||
m_import_options->split_compound = m_split_compound_checkbox.GetValue();
|
||||
m_import_options->sort_names = m_sort_names_checkbox.GetValue();
|
||||
m_import_options->load_as_assembly = m_load_mode->GetSelection() == 0;
|
||||
m_import_options->remember = m_save_default_checkbox.GetValue();
|
||||
m_import_options->dont_ask = m_checkbox.GetValue();
|
||||
m_import_options->linear_deflection = get_linear_deflection();
|
||||
m_import_options->angle_deflection = get_angle_deflection();
|
||||
m_import_options->chosen = true;
|
||||
} else {
|
||||
if (m_checkbox.GetValue()) {
|
||||
wxGetApp().app_config->set_bool("enable_step_mesh_setting", false);
|
||||
}
|
||||
if (m_save_default_checkbox.GetValue()) {
|
||||
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);
|
||||
@@ -336,6 +374,8 @@ StepMeshDialog::StepMeshDialog(wxWindow* parent, Slic3r::Step& file, double line
|
||||
this->SetSizerAndFit(bSizer);
|
||||
update_mesh_number_text();
|
||||
this->Layout();
|
||||
// DPIDialog centres itself before the sizer sets the final size.
|
||||
CenterOnParent();
|
||||
|
||||
this->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {
|
||||
SetFocusIgnoringChildren();
|
||||
@@ -404,4 +444,4 @@ void StepMeshDialog::update_mesh_number_text()
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user