mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 19:01:02 +00:00
Merge remote-tracking branch 'upstream/main' into haryr/aug25-rebase
# Conflicts: # src/libslic3r/Support/TreeSupport.cpp
This commit is contained in:
@@ -30,6 +30,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_mutable_polygon.cpp
|
||||
test_mutable_priority_queue.cpp
|
||||
test_nozzle_volume_type.cpp
|
||||
test_step.cpp
|
||||
test_stl.cpp
|
||||
test_triangle_selector.cpp
|
||||
test_meshboolean.cpp
|
||||
|
||||
@@ -171,3 +171,24 @@ TEST_CASE("Corner smoothing keeps the ends of a path that returns to its start",
|
||||
REQUIRE(retrace.front() == sharp.front());
|
||||
REQUIRE(retrace.back() == sharp.back());
|
||||
}
|
||||
|
||||
TEST_CASE("Corner smoothing ignores vertices splitting a straight leg", "[FillCornerSmoothing][Regression]")
|
||||
{
|
||||
// The triangular and grid infills emit a vertex halfway along the straight run joining two of
|
||||
// their corners. Measuring the legs up to that vertex instead of up to the next corner let the
|
||||
// rounding reach only half as far there as it did into the very same run elsewhere in the
|
||||
// pattern, so geometrically identical corners came out rounded to different radii.
|
||||
const Polyline plain{ Point::new_scale(0., 20.), Point::new_scale(10., 0.),
|
||||
Point::new_scale(20., 0.), Point::new_scale(30., 20.) };
|
||||
Polyline split = plain;
|
||||
split.points.insert(split.points.begin() + 2, Point::new_scale(15., 0.));
|
||||
|
||||
Polyline smooth_plain = plain;
|
||||
smooth_polyline_corners(smooth_plain, 1., tolerance);
|
||||
Polyline smooth_split = split;
|
||||
smooth_polyline_corners(smooth_split, 1., tolerance);
|
||||
|
||||
REQUIRE(smooth_split.points == smooth_plain.points);
|
||||
// Both corners reach the middle of the 10mm run they share, which the extra vertex sat on.
|
||||
REQUIRE(contains(smooth_plain, Point::new_scale(15., 0.)));
|
||||
}
|
||||
|
||||
@@ -704,3 +704,189 @@ TEST_CASE("Sizing the filament list to a multi-tool nozzle count keeps mixed slo
|
||||
CHECK(bundle.num_mixed_filaments() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
// The nozzle-count top-up in update_multi_material_filament_presets() grows filament_presets on
|
||||
// its own, so a physical count derived from that list reports a slot no per-filament array has
|
||||
// yet. That is what made the extruder-count handler conclude there was nothing to add and leave
|
||||
// the new sidebar combo with no colour to draw.
|
||||
TEST_CASE("The physical filament count is not fooled by a lone filament_presets top-up", "[Preset][Bundle][FilamentMixer]")
|
||||
{
|
||||
PresetBundle bundle;
|
||||
|
||||
SECTION("no mixed slots") {
|
||||
bundle.set_num_filaments(4u, std::string("#FF0000"));
|
||||
bundle.printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter", true)->values =
|
||||
{ 0.4, 0.4, 0.4, 0.4, 0.4 };
|
||||
bundle.update_multi_material_filament_presets();
|
||||
|
||||
REQUIRE(bundle.filament_presets.size() == 5); // the top-up moved this list on its own
|
||||
REQUIRE(bundle.project_config.option<ConfigOptionStrings>("filament_colour")->values.size() == 4);
|
||||
CHECK(bundle.num_physical_filaments() == 4);
|
||||
}
|
||||
|
||||
SECTION("behind a mixed tail") {
|
||||
bundle.set_num_filaments(5u, std::string("#FF0000"));
|
||||
bundle.project_config.option<ConfigOptionBools>("filament_is_mixed")->values =
|
||||
{ false, false, false, false, true };
|
||||
bundle.printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter", true)->values =
|
||||
{ 0.4, 0.4, 0.4, 0.4, 0.4, 0.4 };
|
||||
bundle.update_multi_material_filament_presets();
|
||||
|
||||
REQUIRE(bundle.filament_presets.size() == 6);
|
||||
REQUIRE(bundle.project_config.option<ConfigOptionStrings>("filament_colour")->values.size() == 5);
|
||||
CHECK(bundle.num_physical_filaments() == 4);
|
||||
CHECK(bundle.num_mixed_filaments() == 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Which slots are new is a fact about the per-filament arrays, not about filament_presets, for the
|
||||
// same reason. Keyed off the wrong one, a freshly opened slot silently keeps filament 1's colour.
|
||||
TEST_CASE("New filament colours are placed by array position", "[Preset][Bundle][FilamentMixer]")
|
||||
{
|
||||
PresetBundle bundle;
|
||||
bundle.set_num_filaments(4u, std::string("#FF0000"));
|
||||
bundle.printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter", true)->values =
|
||||
{ 0.4, 0.4, 0.4, 0.4, 0.4 };
|
||||
bundle.update_multi_material_filament_presets();
|
||||
REQUIRE(bundle.filament_presets.size() == 5);
|
||||
REQUIRE(bundle.project_config.option<ConfigOptionStrings>("filament_colour")->values.size() == 4);
|
||||
|
||||
// The call Sidebar::add_custom_filament makes once the extruder count opens a slot.
|
||||
bundle.set_num_filaments(5u, std::string("#00FF00"));
|
||||
|
||||
const auto &colours = bundle.project_config.option<ConfigOptionStrings>("filament_colour")->values;
|
||||
REQUIRE(colours.size() == 5);
|
||||
CHECK(colours[4] == "#00FF00"); // not colours[0], which resize() would have padded with
|
||||
}
|
||||
|
||||
// The mixed-slot flags are written into the app config on exit and read back on the next start.
|
||||
// If the read side loses them the slots survive as filaments but stop being mixes, so the project
|
||||
// comes back with the mix showing as an ordinary physical filament.
|
||||
TEST_CASE("A saved mix is still a mix after an app restart", "[Preset][Bundle][FilamentMixer]")
|
||||
{
|
||||
AppConfig app_config;
|
||||
|
||||
// Last session: a 4-tool project carrying one mix of filaments 2 and 3 at the tail.
|
||||
{
|
||||
PresetBundle bundle;
|
||||
add_inmemory_preset(bundle.printers, "Test Printer");
|
||||
bundle.printers.select_preset_by_name("Test Printer", true);
|
||||
add_inmemory_preset(bundle.filaments, "Test Filament");
|
||||
bundle.filaments.select_preset_by_name("Test Filament", true);
|
||||
bundle.set_num_filaments(5u, std::string("#FF0000"));
|
||||
bundle.filament_presets.assign(5, "Test Filament");
|
||||
bundle.project_config.option<ConfigOptionBools>("filament_is_mixed")->values =
|
||||
{ false, false, false, false, true };
|
||||
bundle.project_config.option<ConfigOptionStrings>("filament_mixed_components")->values =
|
||||
{ "", "", "", "", "2,3" };
|
||||
bundle.export_selections(app_config);
|
||||
|
||||
REQUIRE(app_config.get_printer_setting("Test Printer", "filament_is_mixed") == "0,0,0,0,1");
|
||||
}
|
||||
|
||||
// This session.
|
||||
PresetBundle bundle;
|
||||
add_inmemory_preset(bundle.printers, "Test Printer");
|
||||
add_inmemory_preset(bundle.filaments, "Test Filament");
|
||||
bundle.load_selections(app_config);
|
||||
|
||||
CHECK(bundle.filament_presets.size() == 5);
|
||||
CHECK(bundle.num_mixed_filaments() == 1);
|
||||
CHECK(bundle.is_mixed_filament(4));
|
||||
CHECK(bundle.project_config.option<ConfigOptionStrings>("filament_mixed_components")->values[4] == "2,3");
|
||||
}
|
||||
|
||||
// The same restart, on the printer shape that actually shows the bug: a 4-tool changer whose
|
||||
// saved filament list is one longer than its nozzle count, because the extra slot is the mix.
|
||||
TEST_CASE("A saved mix survives a restart on a multi-tool printer", "[Preset][Bundle][FilamentMixer]")
|
||||
{
|
||||
auto make_toolchanger = [](PresetBundle &bundle) -> Preset & {
|
||||
Preset &p = add_inmemory_preset(bundle.printers, "Tool Changer");
|
||||
p.config.option<ConfigOptionFloats>("nozzle_diameter", true)->values = { 0.4, 0.4, 0.4, 0.4 };
|
||||
p.config.option<ConfigOptionBool>("single_extruder_multi_material", true)->value = false;
|
||||
return p;
|
||||
};
|
||||
|
||||
AppConfig app_config;
|
||||
{
|
||||
PresetBundle bundle;
|
||||
make_toolchanger(bundle);
|
||||
bundle.printers.select_preset_by_name("Tool Changer", true);
|
||||
add_inmemory_preset(bundle.filaments, "Test Filament");
|
||||
bundle.filaments.select_preset_by_name("Test Filament", true);
|
||||
bundle.set_num_filaments(5u, std::string("#FF0000"));
|
||||
bundle.filament_presets.assign(5, "Test Filament");
|
||||
bundle.project_config.option<ConfigOptionBools>("filament_is_mixed")->values =
|
||||
{ false, false, false, false, true };
|
||||
bundle.project_config.option<ConfigOptionStrings>("filament_mixed_components")->values =
|
||||
{ "", "", "", "", "1,2" };
|
||||
bundle.export_selections(app_config);
|
||||
REQUIRE(app_config.get_printer_setting("Tool Changer", "filament_is_mixed") == "0,0,0,0,1");
|
||||
}
|
||||
|
||||
PresetBundle bundle;
|
||||
make_toolchanger(bundle);
|
||||
add_inmemory_preset(bundle.filaments, "Test Filament");
|
||||
bundle.load_selections(app_config);
|
||||
|
||||
CHECK(bundle.filament_presets.size() == 5);
|
||||
CHECK(bundle.num_mixed_filaments() == 1);
|
||||
CHECK(bundle.is_mixed_filament(4));
|
||||
|
||||
SECTION("and through the GUI startup calls that follow it") {
|
||||
// GUI_App::load_current_presets sizes the list for a non-SEMM printer, growing only.
|
||||
const size_t target = 4u + bundle.num_mixed_filaments();
|
||||
if (target > bundle.filament_presets.size())
|
||||
bundle.set_num_filaments(target);
|
||||
CHECK(bundle.num_mixed_filaments() == 1);
|
||||
|
||||
// TabPrinter::extruders_count_changed.
|
||||
bundle.on_extruders_count_changed(4);
|
||||
CHECK(bundle.num_mixed_filaments() == 1);
|
||||
|
||||
// Tab::select_preset re-reads the snapshot when remember_printer_config is on.
|
||||
bundle.update_selections(app_config);
|
||||
CHECK(bundle.filament_presets.size() == 5);
|
||||
CHECK(bundle.num_mixed_filaments() == 1);
|
||||
CHECK(bundle.is_mixed_filament(4));
|
||||
}
|
||||
}
|
||||
|
||||
// The startup sizing in GUI_App::load_current_presets targets the nozzle count plus the mixes.
|
||||
// That is a floor, never a ceiling: set_num_filaments() trims at the raw tail, which is exactly
|
||||
// where the mixes live, so applying the target to a longer list deletes them. A list longer than
|
||||
// the target is reachable - raising the extruder count without saving the printer preset leaves
|
||||
// the extra physical slot behind on the next start - so the startup sizing must only ever grow.
|
||||
TEST_CASE("Sizing down to the nozzle count plus mixes is what eats the mixed tail", "[Preset][Bundle][FilamentMixer]")
|
||||
{
|
||||
// 5 physical + 1 mix, on a printer preset still reporting 4 nozzles.
|
||||
const size_t nozzle_count = 4;
|
||||
PresetBundle bundle;
|
||||
bundle.set_num_filaments(6u, std::string("#FF0000"));
|
||||
bundle.project_config.option<ConfigOptionBools>("filament_is_mixed")->values =
|
||||
{ false, false, false, false, false, true };
|
||||
bundle.project_config.option<ConfigOptionStrings>("filament_mixed_components")->values =
|
||||
{ "", "", "", "", "", "1,2" };
|
||||
REQUIRE(bundle.num_physical_filaments() == 5);
|
||||
|
||||
const size_t target = nozzle_count + bundle.num_mixed_filaments();
|
||||
REQUIRE(target < bundle.filament_presets.size());
|
||||
|
||||
SECTION("applied as written, the mix is gone and every slot reads physical") {
|
||||
bundle.set_num_filaments(target);
|
||||
|
||||
CHECK(bundle.filament_presets.size() == target);
|
||||
CHECK(bundle.num_mixed_filaments() == 0);
|
||||
CHECK(bundle.num_physical_filaments() == target);
|
||||
}
|
||||
|
||||
SECTION("applied as a floor, the mix is left alone") {
|
||||
if (target > bundle.filament_presets.size())
|
||||
bundle.set_num_filaments(target);
|
||||
|
||||
CHECK(bundle.filament_presets.size() == 6);
|
||||
CHECK(bundle.num_mixed_filaments() == 1);
|
||||
CHECK(bundle.is_mixed_filament(5));
|
||||
CHECK(bundle.project_config.option<ConfigOptionStrings>("filament_mixed_components")->values[5] == "1,2");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include <boost/nowide/fstream.hpp>
|
||||
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/Format/STEP.hpp"
|
||||
#include "test_utils.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
static void write_step_line(const std::string &path, const std::string &line)
|
||||
{
|
||||
boost::nowide::ofstream file(path, std::ios::binary);
|
||||
file << "ISO-10303-21;\n" << line << "\nEND-ISO-10303-21;\n";
|
||||
}
|
||||
|
||||
// preprocess() hands back the input path unless it transcoded into a temporary.
|
||||
static std::string preprocess_result(const std::string &line)
|
||||
{
|
||||
ScopedSlic3rTemporaryDir scratch;
|
||||
|
||||
ScopedTemporaryFile step(".step");
|
||||
write_step_line(step.string(), line);
|
||||
|
||||
std::string output_path;
|
||||
StepPreProcessor preprocessor;
|
||||
REQUIRE(preprocessor.preprocess(step.string().c_str(), output_path));
|
||||
|
||||
return output_path == step.string() ? "untouched" : "transcoded";
|
||||
}
|
||||
|
||||
// data/utf8_part_names.step is three boxes written by OCCT's own STEP writer, whose
|
||||
// PRODUCT names were then patched to raw UTF-8. Most CAD exporters write non-ASCII names
|
||||
// that way rather than in the \X2\ escape form. The third part is ASCII, as a control.
|
||||
TEST_CASE("Part names with multi-byte UTF-8 survive import", "[Step]")
|
||||
{
|
||||
// getNamedSolids() replaces a name that isUtf8() rejects with a running number.
|
||||
const std::string path = TEST_DATA_DIR PATH_SEPARATOR "utf8_part_names.step";
|
||||
|
||||
Model model;
|
||||
bool cancel = false;
|
||||
Step step(path); // no isUtf8Fn, matching how Model::read_from_step builds it
|
||||
|
||||
REQUIRE(step.load() == Step::Step_Status::LOAD_SUCCESS);
|
||||
REQUIRE(step.mesh(&model, cancel, false) == Step::Step_Status::MESH_SUCCESS);
|
||||
|
||||
REQUIRE(model.objects.size() == 1);
|
||||
const ModelObject *object = model.objects.front();
|
||||
REQUIRE(object->volumes.size() == 3);
|
||||
// "ce" is split off, or the hex escape would swallow it as further hex digits.
|
||||
CHECK(object->volumes[0]->name == "pi\xC3\xA8" "ce");
|
||||
CHECK(object->volumes[1]->name == "Geh\xC3\xA4use");
|
||||
CHECK(object->volumes[2]->name == "bracket");
|
||||
}
|
||||
|
||||
TEST_CASE("isUtf8 recognises two, three and four byte sequences", "[Step]")
|
||||
{
|
||||
CHECK(StepPreProcessor::isUtf8("\xC3\xA9")); // U+00E9
|
||||
CHECK(StepPreProcessor::isUtf8("\xE4\xB8\xAD")); // U+4E2D
|
||||
CHECK(StepPreProcessor::isUtf8("\xF0\x9F\x94\xA9")); // U+1F529
|
||||
CHECK_FALSE(StepPreProcessor::isUtf8("\x81\x30")); // 0x81 is not a lead byte
|
||||
CHECK_FALSE(StepPreProcessor::isUtf8("\xC3")); // truncated sequence
|
||||
}
|
||||
|
||||
// The only caller of isGBK is preprocess(), which nothing calls today.
|
||||
TEST_CASE("Encoding detection decides whether a step file is transcoded", "[Step]")
|
||||
{
|
||||
SECTION("UTF-8, so left alone")
|
||||
{
|
||||
// A two byte sequence also satisfies every GBK range, so misdetecting it as
|
||||
// not-UTF-8 sends it to be transcoded.
|
||||
const std::string sequence = GENERATE(std::string("\xC3\xA9"), // U+00E9
|
||||
std::string("\xE4\xB8\xAD"), // U+4E2D
|
||||
std::string("\xF0\x9F\x94\xA9")); // U+1F529
|
||||
|
||||
CHECK(preprocess_result("NAME('" + sequence + "');") == "untouched");
|
||||
}
|
||||
|
||||
SECTION("neither UTF-8 nor GBK, so left alone")
|
||||
{
|
||||
// 0x81 is not a UTF-8 lead byte, and 0x30 is below the 0x40 floor for a GBK trail.
|
||||
CHECK(preprocess_result("NAME('\x81\x30');") == "untouched");
|
||||
}
|
||||
|
||||
SECTION("GBK, so transcoded")
|
||||
{
|
||||
// U+554A in GBK, whose lead byte is not valid UTF-8. Pins the other direction,
|
||||
// since a detector that never reports GBK would pass every case above.
|
||||
CHECK(preprocess_result("NAME('\xB0\xA1');") == "transcoded");
|
||||
}
|
||||
|
||||
SECTION("plain ASCII, so left alone") { CHECK(preprocess_result("NAME('bracket');") == "untouched"); }
|
||||
}
|
||||
Reference in New Issue
Block a user