Files
OrcaSlicer/src/slic3r/GUI/GeometryImportDialog.hpp
T
Damir Galeevandyw4z fa5f7e3db4 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>
2026-11-03 14:14:17 +08:00

72 lines
2.8 KiB
C++

#pragma once
#include <string>
#include <vector>
class CheckBox;
class wxSizer;
class wxStaticText;
class wxString;
class wxWindow;
namespace Slic3r {
class AppConfig;
class Model;
namespace GUI {
// Values remain local to an import until all of its new dialogs have succeeded.
struct GeometryImportOptions {
bool keep_names = true;
bool sort_names = false;
bool load_as_assembly = true;
// AMF only: load the objects as separate objects, as OrcaSlicer did before; the assembly choice is then unused.
bool separate_objects = false;
// STEP only: Orca's Split compound choice; without it a multi-body compound loses its body names.
bool split_compound = true;
bool show_dialog = true;
bool remember = false;
bool dont_ask = false;
bool chosen = false;
double linear_deflection = 0.003;
double angle_deflection = 0.5;
bool single_object() const { return !separate_objects && !load_as_assembly; }
};
struct GeometryImportNamePolicy {
bool show_dialog = true;
bool remove = false;
bool remember = false;
bool dont_ask = false;
bool used = false;
std::string replacement = "_";
};
// STEP and STP share one preference set; an empty result means an unrelated format.
std::string geometry_import_format(const std::string& path);
// Inspect the ZIP directory only, so CAD files do not enter the project-opening path.
bool is_geometry_only_3mf(const std::string& path);
GeometryImportOptions geometry_import_options(const AppConfig& config, const std::string& format);
GeometryImportNamePolicy geometry_import_name_policy(const AppConfig& config);
bool show_geometry_import_options(wxWindow* parent, const std::string& format, GeometryImportOptions& options);
// App-styled check box with its label, shared by the import dialogs.
struct ImportCheckBox {
::CheckBox* box = nullptr;
wxStaticText* label = nullptr;
bool GetValue() const;
void SetValue(bool value) const;
// Greys the label too and stops it toggling the box.
void Enable(bool enable) const;
void SetToolTip(const wxString& tip) const;
};
// A click on the label toggles the box and sends its wxEVT_TOGGLEBUTTON, as a click on the box does.
ImportCheckBox add_import_checkbox(wxWindow* parent, wxSizer& sizer, const wxString& text, bool value, int flags, int border);
// Sorting is offered only together with Keep original names; shared by the STEP dialog.
void link_sort_to_keep(const ImportCheckBox& keep, const ImportCheckBox& sort);
bool prepare_geometry_import_names(wxWindow* parent, const std::vector<Model*>& models, GeometryImportNamePolicy& policy);
void save_geometry_import_options(AppConfig& config, const std::string& format, const GeometryImportOptions& options);
void save_geometry_import_name_policy(AppConfig& config, const GeometryImportNamePolicy& policy);
} // namespace GUI
} // namespace Slic3r