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:
Damir Galeevandyw4z authored and GitHub committed 2026-11-03 14:14:17 +08:00
1 parent e2acd9ec06
commit fa5f7e3db4
34 files changed
+3320 -209

No files matched your search

+41 -6
View File
@@ -18,6 +18,7 @@
#include <cstddef>
#include <cstdlib>
#include <algorithm>
#include <limits>
#include "slic3r/GUI/GUI_ObjectSettings.hpp"
#include <tuple>
#include <wx/bmpcbox.h>
@@ -1298,7 +1299,9 @@ void ObjectDataViewModel::DeleteVolumeChildren(wxDataViewItem& parent)
// set m_containet to FALSE if parent has no child
#ifndef __WXGTK__
root->m_container = false;
// Instances, settings and other rows may remain after the volumes are gone.
if (root->GetChildCount() == 0)
root->m_container = false;
#endif //__WXGTK__
}
@@ -2105,12 +2108,44 @@ unsigned int ObjectDataViewModel::GetChildren(const wxDataViewItem &parent, wxDa
return 0;
}
unsigned int count = node->GetChildren().GetCount();
for (unsigned int pos = 0; pos < count; pos++)
{
ObjectDataViewModelNode* child = node->GetChildren().Item(pos);
array.Add(wxDataViewItem((void*)child));
std::vector<ObjectDataViewModelNode*> children;
for (auto* child : node->GetChildren())
children.push_back(child);
if (node->m_type == itObject && node->m_model_object != nullptr) {
const ModelObject& object = *node->m_model_object;
if (std::any_of(object.volumes.begin(), object.volumes.end(), [](const ModelVolume* volume) {
return volume->import_display_order >= 0;
})) {
// Node indices count visible volumes; cut connectors do not create tree nodes.
std::vector<const ModelVolume*> visible_parts;
for (const ModelVolume* part : object.volumes)
if (!(object.is_cut() && part->is_cut_connector()))
visible_parts.push_back(part);
std::vector<size_t> slots;
std::vector<ObjectDataViewModelNode*> parts;
for (size_t i = 0; i < children.size(); ++i)
if (children[i]->GetType() == itVolume) {
slots.push_back(i);
parts.push_back(children[i]);
}
auto rank = [&](const ObjectDataViewModelNode* part) {
const int index = part->GetIdx();
if (index >= 0 && size_t(index) < visible_parts.size() &&
visible_parts[size_t(index)]->import_display_order >= 0)
return size_t(visible_parts[size_t(index)]->import_display_order);
return std::numeric_limits<size_t>::max();
};
std::stable_sort(parts.begin(), parts.end(), [&](const auto* a, const auto* b) {
return rank(a) < rank(b);
});
// Keep settings/layers/instances in their existing slots and never alter m_idx.
for (size_t i = 0; i < slots.size(); ++i)
children[slots[i]] = parts[i];
}
}
const auto count = static_cast<unsigned int>(children.size());
for (auto* child : children)
array.Add(wxDataViewItem((void*)child));
return count;
}