mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-23 06:01:14 -05:00
* 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>
64 lines
2.7 KiB
C++
64 lines
2.7 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include "libslic3r/Format/ImportNames.hpp"
|
|
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
using namespace Slic3r;
|
|
|
|
TEST_CASE("Imported names preserve Unicode and XML escaping characters", "[ImportNames]")
|
|
{
|
|
// Ampersands need XML escaping at serialization, not destructive renaming.
|
|
const std::vector<std::string> names{u8"Шов & тело", u8"部品2", "Same", "Same", ""};
|
|
CHECK(sanitize_import_names(names, "_") == names);
|
|
for (const auto& name : names)
|
|
CHECK_FALSE(has_unsupported_name_characters(name));
|
|
}
|
|
|
|
TEST_CASE("Each unsupported character accepts a complete replacement string", "[ImportNames]")
|
|
{
|
|
// Multi-character replacement applies to each character, including adjacent ones.
|
|
CHECK(sanitize_import_names({"Part/A:B"}, "_slash_") ==
|
|
std::vector<std::string>{"Part_slash_A_slash_B"});
|
|
CHECK(sanitize_import_names({"A//B"}, "xyz") == std::vector<std::string>{"AxyzxyzB"});
|
|
CHECK(sanitize_import_names({"A<>:/\\|?*\"B"}, "") == std::vector<std::string>{"AB"});
|
|
}
|
|
|
|
TEST_CASE("Cleaning names resolves only newly introduced sibling collisions", "[ImportNames]")
|
|
{
|
|
// Existing duplicates remain equal; a cleaned name cannot take an existing valid name.
|
|
const auto names = sanitize_import_names({"A/B", "AB", "AB", "A:B", "A/B", "AB (2)"}, "");
|
|
REQUIRE(names.size() == 6);
|
|
CHECK(names[0] == "AB (3)");
|
|
CHECK(names[1] == "AB");
|
|
CHECK(names[2] == "AB");
|
|
CHECK(names[3] == "AB (4)");
|
|
CHECK(names[4] == names[0]);
|
|
CHECK(names[5] == "AB (2)");
|
|
}
|
|
|
|
TEST_CASE("Names emptied by cleaning receive a usable fallback", "[ImportNames]")
|
|
{
|
|
// An unnamed input stays under the importer's existing fallback policy.
|
|
CHECK(sanitize_import_names({"///", "Part", ""}, "") ==
|
|
std::vector<std::string>{"Part (2)", "Part", ""});
|
|
CHECK(sanitize_import_names({"///"}, "", "Assembly/part") ==
|
|
std::vector<std::string>{"Assemblypart"});
|
|
}
|
|
|
|
TEST_CASE("Name validation rejects unsupported replacement and malformed Unicode", "[ImportNames]")
|
|
{
|
|
CHECK(valid_import_name_replacement("_slash_"));
|
|
CHECK(valid_import_name_replacement(u8"替换"));
|
|
CHECK_FALSE(valid_import_name_replacement(""));
|
|
CHECK_FALSE(valid_import_name_replacement("x/y"));
|
|
CHECK_FALSE(valid_import_name_replacement(std::string("x\x01", 2)));
|
|
CHECK_THROWS_AS(sanitize_import_names({"A/B"}, "/"), std::invalid_argument);
|
|
CHECK_THROWS_AS(sanitize_import_names({std::string("\xc3\x28", 2)}, "_"), std::invalid_argument);
|
|
CHECK(has_unsupported_name_characters(std::string("x\x01", 2)));
|
|
CHECK(has_unsupported_name_characters(u8"x\ufffe"));
|
|
CHECK_FALSE(has_unsupported_name_characters("\t\n\r"));
|
|
}
|