mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 19:01:02 +00:00
Merge branch 'feature/texture_displacement' of https://github.com/OrcaSlicer/OrcaSlicer into feature/texture_displacement
This commit is contained in:
@@ -9,6 +9,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_fill.cpp
|
||||
test_flow.cpp
|
||||
test_gcode_timing.cpp
|
||||
test_gcodeprocessor.cpp
|
||||
test_gcodewriter.cpp
|
||||
test_model.cpp
|
||||
test_multifilament.cpp
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include "libslic3r/libslic3r.h"
|
||||
#include "libslic3r/GCode/GCodeProcessor.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
// Bambu firmware uses the " FEATURE: " style reserved tags, everything else the Slic3r-compatible
|
||||
// "TYPE:" style, so which list applies depends on the printer kind passed in.
|
||||
TEST_CASE("Reserved keyword detection follows the printer kind it is given", "[GCodeProcessor]")
|
||||
{
|
||||
struct Case
|
||||
{
|
||||
const char* name;
|
||||
std::string gcode;
|
||||
bool reserved_on_bbl;
|
||||
bool reserved_on_non_bbl;
|
||||
};
|
||||
|
||||
const auto test_case = GENERATE(values<Case>({
|
||||
{"compatible feature tag", ";TYPE:Prime tower", false, true},
|
||||
{"compatible layer tag", ";LAYER_CHANGE", false, true},
|
||||
{"bbl feature tag", "; FEATURE: Outer wall", true, false},
|
||||
{"tag shared by both lists", ";_GP_FIRST_LINE_M73_PLACEHOLDER", true, true},
|
||||
{"bbl spells this one with a leading space", ";COLOR_CHANGE", false, true},
|
||||
{"ordinary comment", "; heat the bed", false, false},
|
||||
{"not a comment at all", "G1 X10 Y10 F3000", false, false},
|
||||
// A tag counts only as the whole comment's prefix, so neither a tag mentioned mid-comment
|
||||
// nor one trailing a real command is a reserved use.
|
||||
{"tag text later in the comment", "; the TYPE:Prime tower marker", false, false},
|
||||
{"tag trailing a command", "G1 X10 ;TYPE:Prime tower", false, false},
|
||||
}));
|
||||
|
||||
DYNAMIC_SECTION(test_case.name)
|
||||
{
|
||||
std::vector<std::string> tags;
|
||||
REQUIRE(GCodeProcessor::contains_reserved_tags(test_case.gcode, 5, tags, true) == test_case.reserved_on_bbl);
|
||||
|
||||
tags.clear();
|
||||
REQUIRE(GCodeProcessor::contains_reserved_tags(test_case.gcode, 5, tags, false) == test_case.reserved_on_non_bbl);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Reserved keyword detection reports every offending line", "[GCodeProcessor]")
|
||||
{
|
||||
const std::string gcode = ";TYPE:Prime tower\nG1 X10\n;LAYER_CHANGE\n";
|
||||
|
||||
std::vector<std::string> tags;
|
||||
REQUIRE(GCodeProcessor::contains_reserved_tags(gcode, 5, tags, false));
|
||||
REQUIRE(tags.size() == 2);
|
||||
// Reported in the order they appear, which is what makes the max_count cut-off meaningful.
|
||||
CHECK(tags[0] == "TYPE:Prime tower");
|
||||
CHECK(tags[1] == "LAYER_CHANGE");
|
||||
|
||||
SECTION("the reported count is capped at max_count")
|
||||
{
|
||||
tags.clear();
|
||||
REQUIRE(GCodeProcessor::contains_reserved_tags(gcode, 1, tags, false));
|
||||
CHECK(tags.size() == 1);
|
||||
CHECK(tags[0] == "TYPE:Prime tower");
|
||||
}
|
||||
|
||||
SECTION("a max_count of zero still reports the first tag")
|
||||
{
|
||||
tags.clear();
|
||||
REQUIRE(GCodeProcessor::contains_reserved_tags(gcode, 0, tags, false));
|
||||
CHECK(tags.size() == 1);
|
||||
}
|
||||
|
||||
SECTION("g-code with nothing reserved in it reports nothing")
|
||||
{
|
||||
tags.clear();
|
||||
CHECK_FALSE(GCodeProcessor::contains_reserved_tags("G28\n; home all axes\n", 5, tags, false));
|
||||
CHECK(tags.empty());
|
||||
}
|
||||
}
|
||||
@@ -495,3 +495,138 @@ TEST_CASE("Loops waiting for the infill are extruded after it", "[Perimeters]")
|
||||
CHECK(ceiling_roles(true) == std::vector<std::string>{ "perimeter", "infill", "perimeter" });
|
||||
CHECK(ceiling_roles(false) == std::vector<std::string>{ "perimeter", "infill" });
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// The rib spans z=[0,5] and the slab z=[5,6], so this is the slab's first layer - the only one whose
|
||||
// support comes from the rib rather than from the slab below it.
|
||||
const double slab_first_layer_z = 5.2;
|
||||
|
||||
// Rib widths either side of what the wall generators can print. At a 0.4mm nozzle the classic generator
|
||||
// builds nothing thinner than nozzle/3 = 0.133mm and Arachne drops anything below min_feature_size, 25%
|
||||
// of the nozzle = 0.1mm. 0.08mm is under both thresholds, 0.3mm over both.
|
||||
const double unprintable_rib = 0.08;
|
||||
const double printable_rib = 0.3;
|
||||
|
||||
// A 4x5mm anchor tower carrying a 20x5mm slab at z=[5,6], with a rib `rib_width` wide running the whole
|
||||
// length of the slab beneath its y=0 edge; a `rib_width` of 0 leaves the rib out. Nothing else is under
|
||||
// that edge, so whether the wall along it is an overhang rests entirely on the rib. Overhang detection
|
||||
// grows the lower slices by half the nozzle diameter before it asks, which carries either rib past the
|
||||
// 0.21mm from the slab edge to that wall - the unprintable one only fails to reach it once it is filtered
|
||||
// out for being unprintable.
|
||||
Print &slab_over_rib(Print &print, Model &model, double rib_width, const DynamicPrintConfig &config)
|
||||
{
|
||||
ModelObject *object = model.add_object();
|
||||
object->name = "slab_over_rib.stl";
|
||||
object->add_volume(make_cube(4., 5., 6.), ModelVolumeType::MODEL_PART, false);
|
||||
if (rib_width > 0.) {
|
||||
TriangleMesh rib = make_cube(20., rib_width, 5.);
|
||||
rib.translate(4.f, 0.f, 0.f);
|
||||
object->add_volume(std::move(rib), ModelVolumeType::MODEL_PART, false);
|
||||
}
|
||||
TriangleMesh slab = make_cube(20., 5., 1.);
|
||||
slab.translate(4.f, 0.f, 5.f);
|
||||
object->add_volume(std::move(slab), ModelVolumeType::MODEL_PART, false);
|
||||
object->add_instance();
|
||||
object->ensure_on_bed();
|
||||
|
||||
print.auto_assign_extruders(object);
|
||||
print.apply(model, config);
|
||||
print.validate();
|
||||
print.set_status_silent();
|
||||
return print;
|
||||
}
|
||||
|
||||
// Every setting the assertions below depend on, so none of them rests on a default. The wall line widths
|
||||
// are pinned because the rib widths above are chosen against the distance from the slab edge to its outer
|
||||
// wall, and min_feature_size because it is one of the two thresholds under test.
|
||||
DynamicPrintConfig printable_rib_config(const char *wall_generator, bool detect_thin_wall)
|
||||
{
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "wall_generator", wall_generator },
|
||||
{ "layer_height", 0.2 }, // puts a layer boundary exactly on the top of the rib
|
||||
{ "initial_layer_print_height", 0.2 },
|
||||
{ "nozzle_diameter", "0.4" },
|
||||
{ "outer_wall_line_width", 0.42 },
|
||||
{ "inner_wall_line_width", 0.45 },
|
||||
{ "wall_loops", 2 },
|
||||
{ "detect_overhang_wall", true },
|
||||
{ "detect_thin_wall", detect_thin_wall },
|
||||
{ "min_feature_size", "25%" },
|
||||
{ "raft_layers", 0 },
|
||||
// Anything that adds, drops or reorders walls would move length between the roles being counted.
|
||||
{ "extra_perimeters_on_overhangs", false },
|
||||
{ "overhang_reverse", false },
|
||||
{ "only_one_wall_top", false },
|
||||
{ "only_one_wall_first_layer", false },
|
||||
{ "unsupported_wall_last", false },
|
||||
{ "sparse_infill_density", "15%" },
|
||||
});
|
||||
return config;
|
||||
}
|
||||
|
||||
// Length of every overhang perimeter path on the layer at `print_z`, loops and open extrusions alike.
|
||||
double overhang_length_at(const Print &print, double print_z)
|
||||
{
|
||||
double len = 0.;
|
||||
const auto add_entity = [&len](const ExtrusionEntity *entity, auto &&self) -> void {
|
||||
const auto add_paths = [&len](const ExtrusionPaths &paths) {
|
||||
for (const ExtrusionPath &path : paths)
|
||||
if (path.role() == erOverhangPerimeter)
|
||||
len += path.length();
|
||||
};
|
||||
if (const auto *coll = dynamic_cast<const ExtrusionEntityCollection*>(entity)) {
|
||||
for (const ExtrusionEntity *child : coll->entities)
|
||||
self(child, self);
|
||||
} else if (const auto *loop = dynamic_cast<const ExtrusionLoop*>(entity)) {
|
||||
add_paths(loop->paths);
|
||||
} else if (const auto *multi = dynamic_cast<const ExtrusionMultiPath*>(entity)) {
|
||||
add_paths(multi->paths);
|
||||
} else if (const auto *path = dynamic_cast<const ExtrusionPath*>(entity)) {
|
||||
if (path->role() == erOverhangPerimeter)
|
||||
len += path->length();
|
||||
}
|
||||
};
|
||||
|
||||
for (const Layer *layer : print.objects().front()->layers()) {
|
||||
if (std::abs(layer->print_z - print_z) > EPSILON)
|
||||
continue;
|
||||
for (const LayerRegion *region : layer->regions())
|
||||
add_entity(®ion->perimeters, add_entity);
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// A sliver the wall generator prints nothing for holds nothing up, so it cannot be what decides that the
|
||||
// wall above it is not an overhang. The rib under the slab is the only thing that edge of the slab could
|
||||
// rest on: below the threshold of the active generator the slab has to come out exactly as it does with
|
||||
// no rib at all, and the last check is the control - a rib the generator does print anchors that wall,
|
||||
// without which the first check would hold for want of any sensitivity to the rib.
|
||||
TEST_CASE("A lower layer sliver too thin to print does not support the wall above it", "[Perimeters]")
|
||||
{
|
||||
const char *wall_generator = GENERATE("classic", "arachne");
|
||||
const bool detect_thin_wall = GENERATE(true, false);
|
||||
CAPTURE(wall_generator, detect_thin_wall);
|
||||
|
||||
auto overhang_for = [wall_generator, detect_thin_wall](double rib_width) {
|
||||
Print print;
|
||||
Model model;
|
||||
slab_over_rib(print, model, rib_width, printable_rib_config(wall_generator, detect_thin_wall));
|
||||
print.process();
|
||||
REQUIRE_FALSE(print.objects().empty());
|
||||
return overhang_length_at(print, slab_first_layer_z);
|
||||
};
|
||||
|
||||
const double no_rib = overhang_for(0.);
|
||||
const double unprintable = overhang_for(unprintable_rib);
|
||||
const double printable = overhang_for(printable_rib);
|
||||
|
||||
// Only where the slab meets the tower is it held up from below, so both of its 20mm walls overhang.
|
||||
REQUIRE(no_rib > scale_(30.));
|
||||
CHECK_THAT(unprintable, Catch::Matchers::WithinAbs(no_rib, scale_(1.)));
|
||||
// A rib that does get printed takes the 20mm outer wall running along it out of the overhangs.
|
||||
CHECK(printable < no_rib - scale_(15.));
|
||||
}
|
||||
|
||||
@@ -22,10 +22,59 @@
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <string_view>
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::Test;
|
||||
|
||||
TEST_CASE("Timelapse g-code is emitted once per layer for Bambu and non-Bambu printers", "[Print][Regression]")
|
||||
{
|
||||
struct PrinterCase {
|
||||
std::string name;
|
||||
std::string structure;
|
||||
bool is_bbl;
|
||||
};
|
||||
const PrinterCase printer = GENERATE(from_range(std::vector<PrinterCase>{
|
||||
{ "non-BBL undefined", "undefine", false },
|
||||
{ "non-BBL CoreXY", "corexy", false },
|
||||
{ "non-BBL i3", "i3", false },
|
||||
{ "non-BBL H-Bot", "hbot", false },
|
||||
{ "non-BBL Delta", "delta", false },
|
||||
{ "Bambu CoreXY", "corexy", true },
|
||||
{ "Bambu i3", "i3", true },
|
||||
}));
|
||||
INFO("printer: " << printer.name);
|
||||
|
||||
DynamicPrintConfig config = DynamicPrintConfig::full_print_config();
|
||||
config.set_deserialize_strict({
|
||||
{ "initial_layer_print_height", 0.2 },
|
||||
{ "layer_change_gcode", ";TEST_LAYER_CHANGE" },
|
||||
{ "layer_height", 0.2 },
|
||||
{ "printer_structure", printer.structure },
|
||||
{ "spiral_mode", false },
|
||||
{ "time_lapse_gcode", "TIMELAPSE_TAKE_FRAME" },
|
||||
});
|
||||
Print print;
|
||||
print.is_BBL_printer() = printer.is_bbl;
|
||||
Model model;
|
||||
init_print({ cube(20) }, print, model, config);
|
||||
const std::string gcode = Slic3r::Test::gcode(print);
|
||||
|
||||
const auto count = [&gcode](std::string_view token) {
|
||||
size_t occurrences = 0;
|
||||
size_t pos = 0;
|
||||
while ((pos = gcode.find(token, pos)) != std::string::npos) {
|
||||
++occurrences;
|
||||
pos += token.size();
|
||||
}
|
||||
return occurrences;
|
||||
};
|
||||
|
||||
const size_t layer_changes = count("\n;TEST_LAYER_CHANGE\n");
|
||||
REQUIRE(layer_changes > 0);
|
||||
CHECK(count("\nTIMELAPSE_TAKE_FRAME\n") == layer_changes);
|
||||
}
|
||||
|
||||
SCENARIO("Changing the number of solid shell layers does not make all surfaces internal", "[Print]") {
|
||||
GIVEN("sliced 20mm cube and config with top_shell_layers = 2 and bottom_shell_layers = 1") {
|
||||
Slic3r::DynamicPrintConfig config = Slic3r::DynamicPrintConfig::full_print_config();
|
||||
|
||||
@@ -43,3 +43,41 @@ TEST_CASE("AppConfig network version helpers", "[AppConfig]") {
|
||||
REQUIRE(config.is_network_version_skipped("02.01.01.52"));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("AppConfig Speed Dial recent count defaults, clamps and parses", "[AppConfig]") {
|
||||
AppConfig config;
|
||||
|
||||
SECTION("unset falls back to the default") {
|
||||
REQUIRE(config.get_speed_dial_recent_count() == SPEED_DIAL_RECENT_COUNT_DEFAULT);
|
||||
}
|
||||
|
||||
SECTION("zero disables recents") {
|
||||
config.set(SETTING_SPEED_DIAL_RECENT_COUNT, "0");
|
||||
REQUIRE(config.get_speed_dial_recent_count() == 0);
|
||||
}
|
||||
|
||||
SECTION("a value in range is returned as-is") {
|
||||
config.set(SETTING_SPEED_DIAL_RECENT_COUNT, "7");
|
||||
REQUIRE(config.get_speed_dial_recent_count() == 7);
|
||||
}
|
||||
|
||||
SECTION("the maximum is kept") {
|
||||
config.set(SETTING_SPEED_DIAL_RECENT_COUNT, "10");
|
||||
REQUIRE(config.get_speed_dial_recent_count() == SPEED_DIAL_RECENT_COUNT_MAX);
|
||||
}
|
||||
|
||||
SECTION("values above the maximum clamp down") {
|
||||
config.set(SETTING_SPEED_DIAL_RECENT_COUNT, "42");
|
||||
REQUIRE(config.get_speed_dial_recent_count() == SPEED_DIAL_RECENT_COUNT_MAX);
|
||||
}
|
||||
|
||||
SECTION("negative values clamp up to 0") {
|
||||
config.set(SETTING_SPEED_DIAL_RECENT_COUNT, "-3");
|
||||
REQUIRE(config.get_speed_dial_recent_count() == 0);
|
||||
}
|
||||
|
||||
SECTION("garbage falls back to the default") {
|
||||
config.set(SETTING_SPEED_DIAL_RECENT_COUNT, "abc");
|
||||
REQUIRE(config.get_speed_dial_recent_count() == SPEED_DIAL_RECENT_COUNT_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -594,3 +594,47 @@ TEST_CASE("update_values_from_multi_to_multi_2 sizes the destination row to the
|
||||
CHECK(object_config.update_values_from_multi_to_multi_2(src_variants, {}, dst, keys) == -1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("get_index_for_extruder returns -1 when no variant column matches the extruder", "[Config]")
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.option<ConfigOptionInts>("print_extruder_id", true)->values = {1};
|
||||
config.option<ConfigOptionStrings>("print_extruder_variant", true)->values = {"Direct Drive Standard"};
|
||||
|
||||
SECTION("the extruder that owns the column resolves to its slot") {
|
||||
REQUIRE(config.get_index_for_extruder(1, "print_extruder_id", etDirectDrive, nvtStandard, "print_extruder_variant") == 0);
|
||||
}
|
||||
|
||||
SECTION("an extruder with no matching column resolves to -1") {
|
||||
REQUIRE(config.get_index_for_extruder(2, "print_extruder_id", etDirectDrive, nvtStandard, "print_extruder_variant") == -1);
|
||||
}
|
||||
}
|
||||
|
||||
// stride scales the returned slot so callers can address stride-2 options (machine_max_*, a
|
||||
// Normal/Silent pair per column) by their pair's base slot. The printer Tab's extruder sync
|
||||
// relies on this to copy the right slots on the Motion ability page.
|
||||
TEST_CASE("get_index_for_extruder scales the variant column by the requested stride", "[Config]")
|
||||
{
|
||||
DynamicPrintConfig config;
|
||||
config.option<ConfigOptionInts>("printer_extruder_id", true)->values = {1, 2};
|
||||
config.option<ConfigOptionStrings>("printer_extruder_variant", true)->values = {"Direct Drive Standard",
|
||||
"Direct Drive High Flow"};
|
||||
|
||||
// extruder 1 resolves to column 0, extruder 2 to column 1
|
||||
const int col0_stride1 = config.get_index_for_extruder(1, "printer_extruder_id", etDirectDrive, nvtStandard,
|
||||
"printer_extruder_variant", 1);
|
||||
const int col1_stride1 = config.get_index_for_extruder(2, "printer_extruder_id", etDirectDrive, nvtHighFlow,
|
||||
"printer_extruder_variant", 1);
|
||||
REQUIRE(col0_stride1 == 0);
|
||||
REQUIRE(col1_stride1 == 1);
|
||||
|
||||
// stride 2 returns exactly twice the stride-1 index (the pair's base slot)
|
||||
const int col0_stride2 = config.get_index_for_extruder(1, "printer_extruder_id", etDirectDrive, nvtStandard,
|
||||
"printer_extruder_variant", 2);
|
||||
const int col1_stride2 = config.get_index_for_extruder(2, "printer_extruder_id", etDirectDrive, nvtHighFlow,
|
||||
"printer_extruder_variant", 2);
|
||||
REQUIRE(col0_stride2 == col0_stride1 * 2);
|
||||
REQUIRE(col1_stride2 == col1_stride1 * 2);
|
||||
REQUIRE(col0_stride2 == 0);
|
||||
REQUIRE(col1_stride2 == 2);
|
||||
}
|
||||
|
||||
@@ -335,6 +335,10 @@ TEST_CASE("The shipped defaults size the tower from the flush matrix", "[WipeTow
|
||||
const double flush_volume = WipeTower2::estimate_semm_flush_volume(config, 2);
|
||||
const double expected = std::max(double(WipeTower::get_limit_depth_by_height(5.f)), flush_volume / (0.2 * 50.));
|
||||
CHECK_THAT(estimate(config, 2, 0.2, 5.).depth, WithinAbs(expected, 1e-6));
|
||||
|
||||
// The flush volume is nonzero for one slot, but a lone filament makes no tool change.
|
||||
REQUIRE(WipeTower2::estimate_semm_flush_volume(config, 1) > 0.);
|
||||
CHECK_THAT(estimate(config, 1, 0.2, 5.).depth, WithinAbs(0., 1e-9));
|
||||
}
|
||||
|
||||
TEST_CASE("A config missing a tower key falls back to that key's default", "[WipeTowerEstimate]") {
|
||||
|
||||
@@ -18,6 +18,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_plugin_sort.cpp
|
||||
test_plugin_cloud_metadata.cpp
|
||||
test_plugin_audit.cpp
|
||||
test_shortcuts.cpp
|
||||
../fff_print/test_helpers.cpp
|
||||
)
|
||||
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "slic3r/GUI/ActionRegistry.hpp"
|
||||
#include "slic3r/GUI/NativeCommands.hpp"
|
||||
#include "slic3r/GUI/SettingsIndex.hpp"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
using Slic3r::GUI::AppAction;
|
||||
using Slic3r::GUI::AppActionRunResult;
|
||||
@@ -19,21 +25,21 @@ class TestAppAction final : public AppAction
|
||||
public:
|
||||
TestAppAction() : AppAction("test", "Action title", "src-key", "Action source") {}
|
||||
|
||||
AppActionRunResult run() const override { return {}; }
|
||||
AppActionRunResult run(const std::string& param = {}) const override { return {}; }
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("AppAction composes a stable id from prefix:title:source_key", "[speeddial][actions]")
|
||||
TEST_CASE("AppAction composes a stable id from prefix:title:source_key", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
CHECK(AppAction::compose_id("test", "Action title", "src-key") == "test:Action title:src-key");
|
||||
// source_key (not the display name) carries identity, so it is the third field.
|
||||
CHECK(AppAction::compose_id("script", "Do Thing", "pack.py") == "script:Do Thing:pack.py");
|
||||
}
|
||||
|
||||
TEST_CASE("AppAction definitions are immutable after construction", "[speeddial][actions]")
|
||||
TEST_CASE("AppAction definitions are immutable after construction", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
using StringAccessor = const std::string& (AppAction::*)() const;
|
||||
using StringAccessor = const std::string& (AppAction::*) () const;
|
||||
|
||||
STATIC_CHECK(std::is_same_v<decltype(&AppAction::id), StringAccessor>);
|
||||
STATIC_CHECK(std::is_same_v<decltype(&AppAction::title), StringAccessor>);
|
||||
@@ -47,9 +53,288 @@ TEST_CASE("AppAction definitions are immutable after construction", "[speeddial]
|
||||
CHECK(action.source_name() == "Action source");
|
||||
}
|
||||
|
||||
TEST_CASE("ActionRegistry takes exclusive ownership of published actions", "[speeddial][actions]")
|
||||
TEST_CASE("ActionRegistry takes exclusive ownership of published actions", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
using ExpectedUpsert = void (ActionRegistry::*)(std::unique_ptr<AppAction>);
|
||||
|
||||
STATIC_CHECK(std::is_same_v<decltype(&ActionRegistry::upsert), ExpectedUpsert>);
|
||||
}
|
||||
|
||||
// A dynamic "Go to Plate N" action is keyed by plate index (not the display title), so renaming
|
||||
// a plate never re-keys it - the same contract as a setting action.
|
||||
TEST_CASE("Go-to-plate actions are keyed by index, not title", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
CHECK(AppAction::compose_id("orca_plate_goto", "0", "orca") == "orca_plate_goto:0:orca");
|
||||
CHECK(AppAction::compose_id("orca_plate_goto", "2", "orca") == "orca_plate_goto:2:orca");
|
||||
}
|
||||
|
||||
// A dynamic "Open recent project" action is keyed by file path (not the display name), so renaming
|
||||
// a project or reordering the recents list never re-keys it - the same contract as a setting action.
|
||||
TEST_CASE("Recent-project actions are keyed by path, not title", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
CHECK(AppAction::compose_id("orca_recent_project", "/a/b/project.3mf", "orca") ==
|
||||
"orca_recent_project:/a/b/project.3mf:orca");
|
||||
CHECK(AppAction::compose_id("orca_recent_project", "C:/Data/cube.3mf", "orca") ==
|
||||
"orca_recent_project:C:/Data/cube.3mf:orca");
|
||||
}
|
||||
|
||||
// A built-in command is keyed by its stable catalog key (not the localized display title), so a
|
||||
// rename or a UI-language switch never re-keys the action and its persisted favourite/stats survive.
|
||||
TEST_CASE("Command actions are keyed by catalog key, not display title", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
CHECK(AppAction::compose_id("orca_command", "save_project", "orca") == "orca_command:save_project:orca");
|
||||
// The second field is the stable key, so distinct commands never collide.
|
||||
CHECK(AppAction::compose_id("orca_command", "save_project", "orca") !=
|
||||
AppAction::compose_id("orca_command", "load_project", "orca"));
|
||||
}
|
||||
|
||||
// The real catalog -> action mapping keys by the stable catalog key and copies presentation from the
|
||||
// catalog, so a rename or a UI-language switch never re-keys the action.
|
||||
TEST_CASE("Command action construction keys by catalog key", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog();
|
||||
REQUIRE_FALSE(commands.empty());
|
||||
const Slic3r::GUI::NativeCommand& c = commands.front();
|
||||
|
||||
std::unique_ptr<AppAction> action = Slic3r::GUI::NativeCommands::make_action(c);
|
||||
REQUIRE(action != nullptr);
|
||||
CHECK(action->id() == AppAction::compose_id("orca_command", c.key, "orca"));
|
||||
CHECK(action->id() != AppAction::compose_id("orca_command", c.title, "orca"));
|
||||
CHECK(action->title() == c.title);
|
||||
CHECK(action->group == c.group);
|
||||
CHECK(action->input == c.input);
|
||||
CHECK(action->icon == c.icon);
|
||||
}
|
||||
|
||||
// The footer description/wiki link is settings-only: built-in commands leave both fields empty, so
|
||||
// the palette's detail strip depends on list-level visibility for them.
|
||||
TEST_CASE("Actions default to no description or wiki link", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
const TestAppAction action;
|
||||
CHECK(action.tooltip.empty());
|
||||
CHECK(action.help_url.empty());
|
||||
|
||||
REQUIRE_FALSE(Slic3r::GUI::NativeCommands::catalog().empty());
|
||||
std::unique_ptr<AppAction> command = Slic3r::GUI::NativeCommands::make_action(Slic3r::GUI::NativeCommands::catalog().front());
|
||||
REQUIRE(command != nullptr);
|
||||
CHECK(command->tooltip.empty());
|
||||
CHECK(command->help_url.empty());
|
||||
}
|
||||
|
||||
// Two-phase commands declare the input the palette must collect before they can run.
|
||||
TEST_CASE("Two-phase commands declare their input phase", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
auto input_of = [](const std::string& key) -> std::string {
|
||||
for (const auto& c : Slic3r::GUI::NativeCommands::catalog())
|
||||
if (c.key == key)
|
||||
return c.input;
|
||||
return {};
|
||||
};
|
||||
CHECK(input_of("go_to_layer") == "percent");
|
||||
CHECK(input_of("go_to_tab") == "tab");
|
||||
}
|
||||
|
||||
// The input token vocabulary is a JS<->C++ contract (speeddial.js dispatches "percent"/"tab").
|
||||
// A typo here would leave a command that never enters its second phase, so pin the allowed set.
|
||||
TEST_CASE("Command input tokens stay in the known vocabulary", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
for (const auto& c : Slic3r::GUI::NativeCommands::catalog()) {
|
||||
INFO(c.key << " input=" << c.input);
|
||||
CHECK((c.input.empty() || c.input == "percent" || c.input == "tab"));
|
||||
}
|
||||
}
|
||||
|
||||
// The quick-launch cap must stay 10 to match the numbered Alt/Option+1..9,0 keys. The web palette
|
||||
// mirrors it as K_FAV_LIMIT (asserted in speeddial.test.js); the C++ side pins it here.
|
||||
static_assert(Slic3r::GUI::ActionRegistry::kFavLimit == 10, "kFavLimit must stay 10");
|
||||
|
||||
TEST_CASE("Favourite lists are capped and deduped preserving order", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
using Slic3r::GUI::cap_favourites;
|
||||
|
||||
CHECK(cap_favourites({}, 10) == std::vector<std::string>{});
|
||||
CHECK(cap_favourites({"a", "b", "a"}, 10) == std::vector<std::string>{"a", "b"});
|
||||
CHECK(cap_favourites({"c", "a", "b", "c"}, 3) == std::vector<std::string>{"c", "a", "b"});
|
||||
CHECK(cap_favourites({"a", "b"}, 0) == std::vector<std::string>{});
|
||||
}
|
||||
|
||||
TEST_CASE("Native command catalog has unique keys and present titles", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog();
|
||||
CHECK_FALSE(commands.empty());
|
||||
|
||||
std::set<std::string> seen;
|
||||
for (const auto& c : commands) {
|
||||
CHECK_FALSE(c.key.empty());
|
||||
CHECK_FALSE(c.title.empty());
|
||||
// A duplicated key would silently shadow the earlier command in the palette.
|
||||
CHECK(seen.insert(c.key).second);
|
||||
}
|
||||
}
|
||||
|
||||
// Every command's tile pictogram is a theme-neutral SVG (the matching GUI control's icon, or the
|
||||
// equivalent settings-group icon); an absent icon gets the page's generic placeholder. Guard
|
||||
// representative names and that every non-empty value resolves to a shipped file, so a rename/typo
|
||||
// cannot leave broken images in the palette.
|
||||
TEST_CASE("Native command icons resolve to shipped SVGs", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog();
|
||||
auto icon_of = [&commands](const std::string& key) -> const std::string* {
|
||||
for (const auto& c : commands)
|
||||
if (c.key == key)
|
||||
return &c.icon;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
struct Expected
|
||||
{
|
||||
const char* key;
|
||||
const char* icon;
|
||||
};
|
||||
for (const Expected& e : {Expected{"load_project", "menu_open"},
|
||||
Expected{"save_project", "menu_save"},
|
||||
Expected{"sync_ams", "ams_fila_sync"},
|
||||
Expected{"mode_simple", "advanced"},
|
||||
Expected{"calib_temperature", "param_temperature"},
|
||||
Expected{"calib_cornering", "param_precision"},
|
||||
Expected{"plate_add", "toolbar_add_plate"},
|
||||
Expected{"add_primitive_cube", "menu_obj_cube"},
|
||||
// These previously pointed at blank placeholder SVGs or theme-broken ones.
|
||||
Expected{"obj_delete", "delete"},
|
||||
Expected{"export_gcode", "custom-gcode_gcode"},
|
||||
Expected{"import_file", "menu_open"},
|
||||
Expected{"help_open_config_folder", "open_project"},
|
||||
Expected{"help_check_updates", "refresh"},
|
||||
Expected{"help_about", "OrcaSlicer_gradient_circle"},
|
||||
Expected{"go_to_tab", ""}}) {
|
||||
const std::string* icon = icon_of(e.key);
|
||||
INFO(e.key);
|
||||
REQUIRE(icon != nullptr);
|
||||
CHECK(*icon == e.icon);
|
||||
}
|
||||
|
||||
const boost::filesystem::path images = boost::filesystem::path(PROFILES_DIR).parent_path() / "images";
|
||||
for (const auto& c : commands) {
|
||||
if (c.icon.empty())
|
||||
continue;
|
||||
INFO(c.key << " -> " << c.icon);
|
||||
CHECK(boost::filesystem::exists(images / (c.icon + ".svg")));
|
||||
}
|
||||
}
|
||||
|
||||
// The Help-menu commands, wiki/YouTube links and the developer-mode toggle are part of the palette.
|
||||
// Guard their presence and that they stay grouped with their peers, so a catalog edit cannot drop
|
||||
// or scatter them. Groups are compared to the peer's own group to stay independent of translation.
|
||||
TEST_CASE("Native command catalog includes the Help and developer-mode commands", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog();
|
||||
auto find = [&commands](const std::string& key) -> const Slic3r::GUI::NativeCommand* {
|
||||
for (const auto& c : commands)
|
||||
if (c.key == key)
|
||||
return &c;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
const Slic3r::GUI::NativeCommand* first = find("help_keyboard_shortcuts");
|
||||
REQUIRE(first != nullptr);
|
||||
for (const char* key : {"help_setup_wizard", "help_open_config_folder", "help_troubleshoot", "help_network_test",
|
||||
"help_tip_of_the_day", "help_check_updates", "help_about", "open_wiki", "open_youtube"}) {
|
||||
const Slic3r::GUI::NativeCommand* c = find(key);
|
||||
REQUIRE(c != nullptr);
|
||||
CHECK(c->group == first->group);
|
||||
}
|
||||
|
||||
const Slic3r::GUI::NativeCommand* mode_simple = find("mode_simple");
|
||||
const Slic3r::GUI::NativeCommand* dev_mode = find("toggle_developer_mode");
|
||||
REQUIRE(mode_simple != nullptr);
|
||||
REQUIRE(dev_mode != nullptr);
|
||||
CHECK(dev_mode->group == mode_simple->group);
|
||||
}
|
||||
|
||||
// Every "Add Primitive" item and shipped handy model has a palette command, grouped as in the Add
|
||||
// menu. Groups are compared to a peer's own group to stay independent of translation.
|
||||
TEST_CASE("Native command catalog covers the Add menus", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
const std::vector<Slic3r::GUI::NativeCommand>& commands = Slic3r::GUI::NativeCommands::catalog();
|
||||
auto group_of = [&commands](const std::string& key) -> const std::string* {
|
||||
for (const auto& c : commands)
|
||||
if (c.key == key)
|
||||
return &c.group;
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
const std::string* primitive_group = group_of("add_primitive_cube");
|
||||
REQUIRE(primitive_group != nullptr);
|
||||
for (const char* key : {"add_primitive_cylinder", "add_primitive_sphere", "add_primitive_cone", "add_primitive_disc",
|
||||
"add_primitive_torus", "add_primitive_text", "add_primitive_svg"}) {
|
||||
const std::string* group = group_of(key);
|
||||
INFO(key);
|
||||
REQUIRE(group != nullptr);
|
||||
CHECK(*group == *primitive_group);
|
||||
}
|
||||
|
||||
const std::string* handy_group = group_of("add_handy_orca_cube");
|
||||
REQUIRE(handy_group != nullptr);
|
||||
for (const char* key : {"add_handy_orcasliced_combo", "add_handy_orca_badge", "add_handy_orca_tolerance_test",
|
||||
"add_handy_3dbenchy", "add_handy_cali_cat", "add_handy_autodesk_fdm_test", "add_handy_voron_cube",
|
||||
"add_handy_stanford_bunny", "add_handy_orca_string_hell"}) {
|
||||
const std::string* group = group_of(key);
|
||||
INFO(key);
|
||||
REQUIRE(group != nullptr);
|
||||
CHECK(*group == *handy_group);
|
||||
}
|
||||
}
|
||||
|
||||
// A setting action is named like its settings row, not the ConfigOptionDef label: the row's
|
||||
// Line::label, plus the field leaf when the row packs several options.
|
||||
TEST_CASE("Setting display labels mirror the settings row", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
using Slic3r::Search::compose_display_label;
|
||||
|
||||
// Single-option row: the row label is the whole title.
|
||||
CHECK(compose_display_label(L"Reverse on even", L"Reverse on even", false) == L"Reverse on even");
|
||||
// No recorded row label falls back to the field leaf.
|
||||
CHECK(compose_display_label(L"", L"Outer wall", false) == L"Outer wall");
|
||||
// Multi-option row: qualify with the leaf so the plate-temperature fields are distinct.
|
||||
CHECK(compose_display_label(L"Cool Plate", L"First layer", true) == wxString(L"Cool Plate \u2013 First layer"));
|
||||
CHECK(compose_display_label(L"Cool Plate", L"Other layers", true) == wxString(L"Cool Plate \u2013 Other layers"));
|
||||
// A leaf equal to the row label is not repeated.
|
||||
CHECK(compose_display_label(L"Skirt loops", L"Skirt loops", true) == L"Skirt loops");
|
||||
|
||||
using Slic3r::Search::resolve_setting_title;
|
||||
|
||||
// A single-option row's live label wins, so a runtime rename is reflected.
|
||||
CHECK(resolve_setting_title(L"Brim width", L"Brim ear radius", false) == L"Brim ear radius");
|
||||
// Multi-option rows keep their precomposed "row – field" label (the leaf disambiguates them).
|
||||
CHECK(resolve_setting_title(L"Cool Plate \u2013 First layer", L"Cool Plate", true) ==
|
||||
wxString(L"Cool Plate \u2013 First layer"));
|
||||
// No live row label (option not on a built page) keeps the precomposed label.
|
||||
CHECK(resolve_setting_title(L"Reverse on even", L"", false) == L"Reverse on even");
|
||||
// Neither present: empty, so the caller falls back to the descriptive label.
|
||||
CHECK(resolve_setting_title(L"", L"", false).IsEmpty());
|
||||
}
|
||||
|
||||
// A setting whose mode is above the user's current mode must be prompted before it can be edited.
|
||||
// Developer settings (comDevelop) are above every non-developer mode, so they always prompt then.
|
||||
TEST_CASE("Settings above the current mode require a switch", "[ActionSource][SpeedDial]")
|
||||
{
|
||||
using Slic3r::GUI::requires_mode_switch;
|
||||
using Slic3r::comAdvanced;
|
||||
using Slic3r::comDevelop;
|
||||
using Slic3r::comExpert;
|
||||
using Slic3r::comSimple;
|
||||
|
||||
CHECK(requires_mode_switch(comAdvanced, comSimple));
|
||||
CHECK(requires_mode_switch(comExpert, comSimple));
|
||||
CHECK(requires_mode_switch(comExpert, comAdvanced));
|
||||
CHECK(requires_mode_switch(comDevelop, comSimple));
|
||||
CHECK(requires_mode_switch(comDevelop, comAdvanced));
|
||||
CHECK(requires_mode_switch(comDevelop, comExpert));
|
||||
|
||||
CHECK_FALSE(requires_mode_switch(comSimple, comSimple));
|
||||
CHECK_FALSE(requires_mode_switch(comSimple, comAdvanced));
|
||||
CHECK_FALSE(requires_mode_switch(comAdvanced, comAdvanced));
|
||||
CHECK_FALSE(requires_mode_switch(comAdvanced, comExpert));
|
||||
CHECK_FALSE(requires_mode_switch(comExpert, comExpert));
|
||||
CHECK_FALSE(requires_mode_switch(comDevelop, comDevelop));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,329 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
#include "slic3r/GUI/KeyChord.hpp"
|
||||
#include "slic3r/GUI/Shortcuts.hpp"
|
||||
|
||||
#include <wx/event.h>
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace Slic3r::GUI;
|
||||
|
||||
namespace {
|
||||
|
||||
wxKeyEvent key_event(wxEventType type, int key_code, int modifiers = wxMOD_NONE)
|
||||
{
|
||||
wxKeyEvent evt(type);
|
||||
evt.m_keyCode = key_code;
|
||||
evt.SetControlDown(modifiers & wxMOD_CONTROL);
|
||||
evt.SetShiftDown(modifiers & wxMOD_SHIFT);
|
||||
evt.SetAltDown(modifiers & wxMOD_ALT);
|
||||
return evt;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("KeyChord round-trips through its canonical text", "[Shortcuts]")
|
||||
{
|
||||
const auto [chord, text] = GENERATE(table<KeyChord, std::string>({
|
||||
{ { 'N', wxMOD_CONTROL }, "Ctrl+N" },
|
||||
{ { 'S', wxMOD_CONTROL | wxMOD_SHIFT }, "Ctrl+Shift+S" },
|
||||
{ { WXK_RETURN, wxMOD_SHIFT | wxMOD_ALT }, "Shift+Alt+Enter" },
|
||||
{ { WXK_TAB, wxMOD_SHIFT }, "Shift+Tab" },
|
||||
{ { WXK_DELETE }, "Del" },
|
||||
{ { WXK_F5 }, "F5" },
|
||||
{ { WXK_F12, wxMOD_CONTROL }, "Ctrl+F12" },
|
||||
{ { '+' }, "+" },
|
||||
{ { '-', wxMOD_CONTROL }, "Ctrl+-" },
|
||||
{ { '?' }, "?" },
|
||||
{ { ',', wxMOD_CONTROL }, "Ctrl+," },
|
||||
}));
|
||||
CAPTURE(text);
|
||||
CHECK(chord.to_string() == text);
|
||||
REQUIRE(KeyChord::parse(text).has_value());
|
||||
CHECK(*KeyChord::parse(text) == chord);
|
||||
}
|
||||
|
||||
TEST_CASE("KeyChord::parse accepts aliases and rejects malformed text", "[Shortcuts]")
|
||||
{
|
||||
CHECK(KeyChord::parse("control+n") == KeyChord{ 'N', wxMOD_CONTROL });
|
||||
CHECK(KeyChord::parse("Cmd+Shift+Delete") == KeyChord{ WXK_DELETE, wxMOD_CONTROL | wxMOD_SHIFT });
|
||||
CHECK(KeyChord::parse("PageUp") == KeyChord{ WXK_PAGEUP });
|
||||
CHECK(KeyChord::parse("f3") == KeyChord{ WXK_F3 });
|
||||
|
||||
CHECK_FALSE(KeyChord::parse("").has_value());
|
||||
CHECK_FALSE(KeyChord::parse("Ctrl+").has_value());
|
||||
CHECK_FALSE(KeyChord::parse("Meta+A").has_value());
|
||||
CHECK_FALSE(KeyChord::parse("F25").has_value());
|
||||
CHECK_FALSE(KeyChord::parse("Shift+/").has_value()); // Shift is part of the punctuation character
|
||||
}
|
||||
|
||||
TEST_CASE("Key events normalize to the key-down key codes", "[Shortcuts]")
|
||||
{
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_KEY_DOWN, 'A', wxMOD_CONTROL)) == KeyChord{ 'A', wxMOD_CONTROL });
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_KEY_DOWN, WXK_NUMPAD5, wxMOD_CONTROL)) == KeyChord{ '5', wxMOD_CONTROL });
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_KEY_DOWN, WXK_NUMPAD_ADD)) == KeyChord{ '+' });
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_KEY_DOWN, WXK_NUMPAD_PAGEUP)) == KeyChord{ WXK_PAGEUP });
|
||||
CHECK_FALSE(KeyChord::from_event(key_event(wxEVT_KEY_DOWN, WXK_SHIFT, wxMOD_SHIFT)).valid());
|
||||
CHECK_FALSE(KeyChord::from_event(key_event(wxEVT_KEY_DOWN, WXK_CONTROL, wxMOD_CONTROL)).valid());
|
||||
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_CHAR, 'a')) == KeyChord{ 'A' });
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_CHAR, 'A', wxMOD_SHIFT)) == KeyChord{ 'A', wxMOD_SHIFT });
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_CHAR, WXK_CONTROL_C, wxMOD_CONTROL)) == KeyChord{ 'C', wxMOD_CONTROL });
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_CHAR, '+', wxMOD_SHIFT)) == KeyChord{ '+' });
|
||||
CHECK(KeyChord::from_event(key_event(wxEVT_CHAR, WXK_DELETE)) == KeyChord{ WXK_DELETE });
|
||||
CHECK_FALSE(KeyChord::from_event(key_event(wxEVT_CHAR, 0x444)).valid()); // a Cyrillic letter is not bindable
|
||||
}
|
||||
|
||||
TEST_CASE("Punctuation chords are the ones matched on char events", "[Shortcuts]")
|
||||
{
|
||||
CHECK(KeyChord{ '+' }.is_punctuation());
|
||||
CHECK(KeyChord{ '?' }.is_punctuation());
|
||||
CHECK_FALSE(KeyChord{ 'A' }.is_punctuation());
|
||||
CHECK_FALSE(KeyChord{ '1' }.is_punctuation());
|
||||
CHECK_FALSE(KeyChord{ '=', wxMOD_CONTROL }.is_punctuation());
|
||||
CHECK_FALSE(KeyChord{ WXK_DELETE }.is_punctuation());
|
||||
}
|
||||
|
||||
TEST_CASE("Chords that only the char event can resolve are recognized", "[Shortcuts]")
|
||||
{
|
||||
CHECK(KeyChord{ '/', wxMOD_SHIFT }.needs_char_event());
|
||||
CHECK(KeyChord{ '-' }.needs_char_event());
|
||||
CHECK_FALSE(KeyChord{ '=', wxMOD_CONTROL }.needs_char_event());
|
||||
CHECK_FALSE(KeyChord{ 'A', wxMOD_SHIFT }.needs_char_event());
|
||||
CHECK_FALSE(KeyChord{ '1' }.needs_char_event());
|
||||
CHECK_FALSE(KeyChord{ WXK_F5 }.needs_char_event());
|
||||
}
|
||||
|
||||
TEST_CASE("Only modified or non-printable chords qualify as menu accelerators", "[Shortcuts]")
|
||||
{
|
||||
CHECK(KeyChord{ 'N', wxMOD_CONTROL }.is_menu_accelerator());
|
||||
CHECK(KeyChord{ 'N', wxMOD_ALT }.is_menu_accelerator());
|
||||
CHECK(KeyChord{ WXK_DELETE }.is_menu_accelerator());
|
||||
CHECK(KeyChord{ WXK_F5 }.is_menu_accelerator());
|
||||
CHECK_FALSE(KeyChord{ 'A' }.is_menu_accelerator());
|
||||
CHECK_FALSE(KeyChord{ 'A', wxMOD_SHIFT }.is_menu_accelerator());
|
||||
CHECK_FALSE(KeyChord{ '?' }.is_menu_accelerator());
|
||||
CHECK_FALSE(KeyChord{ WXK_SPACE }.is_menu_accelerator());
|
||||
CHECK_FALSE(KeyChord{}.is_menu_accelerator());
|
||||
|
||||
ShortcutRegistry registry;
|
||||
CHECK(registry.accelerator(Shortcut::NewProject) == "Ctrl+N");
|
||||
#ifdef __APPLE__
|
||||
CHECK(registry.accelerator(Shortcut::DeleteSelected) == "Backspace");
|
||||
#else
|
||||
CHECK(registry.accelerator(Shortcut::DeleteSelected) == "Del");
|
||||
#endif
|
||||
CHECK(registry.accelerator(Shortcut::Arrange).empty());
|
||||
CHECK(registry.accelerator(Shortcut::ArrangePlate).empty());
|
||||
CHECK(registry.accelerator(Shortcut::KeyboardShortcuts).empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Chords convert to wx accelerator entries", "[Shortcuts]")
|
||||
{
|
||||
const wxAcceleratorEntry entry = KeyChord{ 'S', wxMOD_CONTROL | wxMOD_SHIFT }.to_accelerator_entry(42);
|
||||
CHECK(entry.GetFlags() == (wxACCEL_CTRL | wxACCEL_SHIFT));
|
||||
CHECK(entry.GetKeyCode() == 'S');
|
||||
CHECK(entry.GetCommand() == 42);
|
||||
|
||||
const wxAcceleratorEntry bare = KeyChord{ WXK_BACK }.to_accelerator_entry(7);
|
||||
CHECK(bare.GetFlags() == wxACCEL_NORMAL);
|
||||
CHECK(bare.GetKeyCode() == WXK_BACK);
|
||||
}
|
||||
|
||||
#ifndef __APPLE__
|
||||
TEST_CASE("Display text matches the canonical text without translations", "[Shortcuts]")
|
||||
{
|
||||
CHECK(KeyChord{ WXK_DELETE, wxMOD_CONTROL | wxMOD_SHIFT }.display() == "Ctrl+Shift+Del");
|
||||
CHECK(KeyChord{ WXK_DELETE, wxMOD_CONTROL | wxMOD_SHIFT }.display_parts() == std::vector<std::string>{ "Ctrl", "Shift", "Del" });
|
||||
CHECK(KeyChord{ '+' }.display() == "+");
|
||||
CHECK(KeyChord{ WXK_UP, wxMOD_SHIFT }.display() == "Shift+Arrow Up"); // the arrows keep the old dialog's names
|
||||
CHECK(KeyChord{ WXK_UP, wxMOD_SHIFT }.to_string() == "Shift+Up");
|
||||
CHECK(KeyChord{}.display().empty());
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("Every shortcut is listed under the section of its table row", "[Shortcuts]")
|
||||
{
|
||||
CHECK(shortcut_section(Shortcut::NewProject) == ShortcutSection::Project);
|
||||
CHECK(shortcut_section(Shortcut::Publish3mf) == ShortcutSection::Project);
|
||||
CHECK(shortcut_section(Shortcut::SlicePlate) == ShortcutSection::SlicingAndPrinting);
|
||||
CHECK(shortcut_section(Shortcut::GizmoBrimEars) == ShortcutSection::Gizmos);
|
||||
CHECK(shortcut_section(Shortcut::MovesSliderEnd) == ShortcutSection::Sliders);
|
||||
CHECK(shortcut_section(Shortcut::ViewDefault) == ShortcutSection::Camera);
|
||||
CHECK(shortcut_section(Shortcut::KeyboardShortcuts) == ShortcutSection::Application);
|
||||
CHECK(std::string(section_name(ShortcutSection::SlicingAndPrinting)) == "Slicing and printing");
|
||||
}
|
||||
|
||||
TEST_CASE("Default bindings never collide inside a context", "[Shortcuts]")
|
||||
{
|
||||
ShortcutRegistry registry;
|
||||
for (size_t i = 0; i < size_t(Shortcut::Count); ++i) {
|
||||
const Shortcut shortcut = Shortcut(i);
|
||||
CAPTURE(shortcut_info(shortcut).key);
|
||||
CHECK(registry.conflicts(shortcut, registry.binding(shortcut)).empty());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Shift and Ctrl variants of stepping shortcuts are left unbound", "[Shortcuts]")
|
||||
{
|
||||
ShortcutRegistry registry;
|
||||
for (size_t i = 0; i < size_t(Shortcut::Count); ++i) {
|
||||
const ShortcutInfo& info = shortcut_info(Shortcut(i));
|
||||
if (!info.modifier_variants)
|
||||
continue;
|
||||
CAPTURE(info.key);
|
||||
const KeyChord chord = registry.binding(info.id);
|
||||
for (int modifier : { int(wxMOD_SHIFT), int(wxMOD_CONTROL), int(wxMOD_SHIFT | wxMOD_CONTROL) })
|
||||
for (size_t c = 0; c < size_t(ShortcutContext::Count); ++c)
|
||||
if (info.contexts & context_bit(ShortcutContext(c)))
|
||||
CHECK_FALSE(registry.lookup(ShortcutContext(c), KeyChord{ chord.key, chord.modifiers | modifier }).has_value());
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Lookups are scoped to the context of the key press", "[Shortcuts]")
|
||||
{
|
||||
ShortcutRegistry registry;
|
||||
const KeyChord ctrl_n{ 'N', wxMOD_CONTROL };
|
||||
const KeyChord ctrl_c{ 'C', wxMOD_CONTROL };
|
||||
const KeyChord a{ 'A' };
|
||||
const KeyChord c{ 'C' };
|
||||
|
||||
CHECK(registry.lookup(ShortcutContext::Global, ctrl_n) == Shortcut::NewProject);
|
||||
CHECK_FALSE(registry.lookup(ShortcutContext::Plater, ctrl_n).has_value());
|
||||
|
||||
CHECK(registry.lookup(ShortcutContext::Plater, ctrl_c) == Shortcut::Copy);
|
||||
CHECK(registry.lookup(ShortcutContext::ObjectList, ctrl_c) == Shortcut::Copy);
|
||||
CHECK_FALSE(registry.lookup(ShortcutContext::Global, ctrl_c).has_value());
|
||||
|
||||
CHECK(registry.lookup(ShortcutContext::Plater, a) == Shortcut::Arrange);
|
||||
CHECK_FALSE(registry.lookup(ShortcutContext::Preview, a).has_value());
|
||||
|
||||
CHECK(registry.lookup(ShortcutContext::Plater, c) == Shortcut::GizmoCut);
|
||||
CHECK(registry.lookup(ShortcutContext::Preview, c) == Shortcut::ToggleGcodeWindow);
|
||||
CHECK(registry.lookup(ShortcutContext::Painting, c) == Shortcut::PaintToolCircle);
|
||||
}
|
||||
|
||||
TEST_CASE("Stepping shortcuts match with Shift or Ctrl added to their binding", "[Shortcuts]")
|
||||
{
|
||||
ShortcutRegistry registry;
|
||||
using Match = ShortcutRegistry::Match;
|
||||
auto same = [](const std::optional<Match>& match, Shortcut shortcut, int step_modifiers) {
|
||||
return match.has_value() && match->shortcut == shortcut && match->step_modifiers == step_modifiers;
|
||||
};
|
||||
CHECK(same(registry.match(ShortcutContext::Preview, { WXK_UP }), Shortcut::LayerSliderUp, 0));
|
||||
CHECK(same(registry.match(ShortcutContext::Preview, { WXK_UP, wxMOD_SHIFT }), Shortcut::LayerSliderUp, wxMOD_SHIFT));
|
||||
CHECK(same(registry.match(ShortcutContext::Plater, { WXK_LEFT, wxMOD_CONTROL | wxMOD_SHIFT }), Shortcut::MoveSelectionLeft, wxMOD_CONTROL | wxMOD_SHIFT));
|
||||
CHECK(same(registry.match(ShortcutContext::Plater, { 'A', wxMOD_SHIFT }), Shortcut::ArrangePlate, 0)); // an exact binding wins
|
||||
CHECK_FALSE(registry.match(ShortcutContext::Plater, { 'Q', wxMOD_CONTROL }).has_value()); // Orient has no variants
|
||||
CHECK_FALSE(registry.match(ShortcutContext::Preview, { WXK_UP, wxMOD_ALT }).has_value()); // Alt is not a step modifier
|
||||
|
||||
CHECK_FALSE(registry.match(ShortcutContext::Preview, { WXK_HOME, wxMOD_SHIFT }).has_value()); // Home has no variants
|
||||
|
||||
// A binding with Shift or Ctrl of its own has no steps.
|
||||
registry.bind(Shortcut::LayerSliderUp, { WXK_UP, wxMOD_CONTROL });
|
||||
CHECK(same(registry.match(ShortcutContext::Preview, { WXK_UP, wxMOD_CONTROL }), Shortcut::LayerSliderUp, 0));
|
||||
CHECK_FALSE(registry.match(ShortcutContext::Preview, { WXK_UP, wxMOD_CONTROL | wxMOD_SHIFT }).has_value());
|
||||
CHECK_FALSE(registry.match(ShortcutContext::Preview, { WXK_UP, wxMOD_SHIFT }).has_value());
|
||||
|
||||
// An exact binding on the combined step wins over it.
|
||||
registry.bind(Shortcut::Arrange, { WXK_LEFT, wxMOD_CONTROL | wxMOD_SHIFT });
|
||||
CHECK(same(registry.match(ShortcutContext::Plater, { WXK_LEFT, wxMOD_CONTROL | wxMOD_SHIFT }), Shortcut::Arrange, 0));
|
||||
CHECK(same(registry.match(ShortcutContext::Plater, { WXK_LEFT, wxMOD_SHIFT }), Shortcut::MoveSelectionLeft, wxMOD_SHIFT));
|
||||
}
|
||||
|
||||
TEST_CASE("Conflicts cover shared contexts and every Global shortcut", "[Shortcuts]")
|
||||
{
|
||||
ShortcutRegistry registry;
|
||||
CHECK(registry.conflicts(Shortcut::Arrange, { 'N', wxMOD_CONTROL }) == std::vector<Shortcut>{ Shortcut::NewProject });
|
||||
CHECK(registry.conflicts(Shortcut::NewProject, { 'A' }) == std::vector<Shortcut>{ Shortcut::Arrange });
|
||||
CHECK(registry.conflicts(Shortcut::ToggleGcodeWindow, { 'C' }).empty());
|
||||
CHECK(registry.conflicts(Shortcut::ZoomIn, { 'C' }) == std::vector<Shortcut>{ Shortcut::GizmoCut, Shortcut::ToggleGcodeWindow });
|
||||
CHECK(registry.conflicts(Shortcut::Arrange, { 'A' }).empty()); // a shortcut never conflicts with itself
|
||||
|
||||
// Only the exact chord conflicts; the steps of a stepping shortcut are reserved instead.
|
||||
CHECK(registry.conflicts(Shortcut::GoToLayer, { WXK_UP, wxMOD_SHIFT }).empty());
|
||||
CHECK(registry.conflicts(Shortcut::LayerSliderUp, { 'G', wxMOD_SHIFT }) == std::vector<Shortcut>{ Shortcut::GoToLayer });
|
||||
}
|
||||
|
||||
TEST_CASE("Shift and Ctrl with a stepping shortcut's key are reserved for its steps", "[Shortcuts]")
|
||||
{
|
||||
ShortcutRegistry registry;
|
||||
CHECK(registry.step_owner(Shortcut::GoToLayer, { WXK_UP, wxMOD_SHIFT }) == Shortcut::LayerSliderUp);
|
||||
CHECK(registry.step_owner(Shortcut::NewProject, { WXK_LEFT, wxMOD_CONTROL }) == Shortcut::MoveSelectionLeft); // Global shares every context
|
||||
CHECK_FALSE(registry.step_owner(Shortcut::GoToLayer, { WXK_UP, wxMOD_CONTROL | wxMOD_SHIFT }).has_value()); // the combined step is free
|
||||
CHECK_FALSE(registry.step_owner(Shortcut::MoveSelectionLeft, { WXK_LEFT, wxMOD_SHIFT }).has_value()); // its own step
|
||||
CHECK_FALSE(registry.step_owner(Shortcut::PaintToolCircle, { WXK_UP, wxMOD_SHIFT }).has_value()); // Painting shares no context
|
||||
registry.bind(Shortcut::LayerSliderUp, { WXK_UP, wxMOD_CONTROL });
|
||||
CHECK_FALSE(registry.step_owner(Shortcut::GoToLayer, { WXK_UP, wxMOD_CONTROL | wxMOD_SHIFT }).has_value()); // a modified binding has no steps
|
||||
}
|
||||
|
||||
TEST_CASE("Custom bindings replace the default and survive a config round trip", "[Shortcuts]")
|
||||
{
|
||||
ShortcutRegistry registry;
|
||||
const KeyChord w{ 'W' };
|
||||
registry.bind(Shortcut::Arrange, w);
|
||||
|
||||
CHECK(registry.is_customized(Shortcut::Arrange));
|
||||
CHECK(registry.lookup(ShortcutContext::Plater, w) == Shortcut::Arrange);
|
||||
CHECK_FALSE(registry.lookup(ShortcutContext::Plater, { 'A' }).has_value());
|
||||
|
||||
AppConfig config;
|
||||
registry.save(config);
|
||||
CHECK(config.get("shortcuts", "arrange") == "W");
|
||||
CHECK_FALSE(config.has("shortcuts", "orient"));
|
||||
|
||||
ShortcutRegistry loaded;
|
||||
loaded.load(config);
|
||||
CHECK(loaded.lookup(ShortcutContext::Plater, w) == Shortcut::Arrange);
|
||||
CHECK(loaded.binding(Shortcut::Orient) == KeyChord{ 'Q' });
|
||||
|
||||
SECTION("rebinding to the default clears the override")
|
||||
{
|
||||
registry.bind(Shortcut::Arrange, { 'A' });
|
||||
CHECK_FALSE(registry.is_customized(Shortcut::Arrange));
|
||||
registry.save(config);
|
||||
CHECK_FALSE(config.has("shortcuts", "arrange"));
|
||||
}
|
||||
SECTION("an invalid chord unbinds and persists as none")
|
||||
{
|
||||
registry.bind(Shortcut::Arrange, KeyChord{});
|
||||
CHECK_FALSE(registry.binding(Shortcut::Arrange).valid());
|
||||
registry.save(config);
|
||||
CHECK(config.get("shortcuts", "arrange") == "none");
|
||||
loaded.load(config);
|
||||
CHECK_FALSE(loaded.lookup(ShortcutContext::Plater, { 'A' }).has_value());
|
||||
CHECK_FALSE(loaded.lookup(ShortcutContext::Plater, w).has_value());
|
||||
}
|
||||
SECTION("reset_all restores every default")
|
||||
{
|
||||
registry.reset_all();
|
||||
CHECK(registry.lookup(ShortcutContext::Plater, { 'A' }) == Shortcut::Arrange);
|
||||
CHECK_FALSE(registry.is_customized(Shortcut::Arrange));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("A Global shortcut refuses a config binding that would swallow typing", "[Shortcuts]")
|
||||
{
|
||||
AppConfig config;
|
||||
// A string literal would pick AppConfig::set's bool overload.
|
||||
config.set("shortcuts", "save_project", std::string("S"));
|
||||
config.set("shortcuts", "new_project", std::string("F9"));
|
||||
ShortcutRegistry registry;
|
||||
registry.load(config);
|
||||
CHECK(registry.binding(Shortcut::SaveProject) == KeyChord{ 'S', wxMOD_CONTROL });
|
||||
CHECK(registry.binding(Shortcut::NewProject) == KeyChord{ WXK_F9 });
|
||||
}
|
||||
|
||||
TEST_CASE("Unreadable config entries fall back to the default binding", "[Shortcuts]")
|
||||
{
|
||||
AppConfig config;
|
||||
config.set("shortcuts", "arrange", std::string("Hyper+Q"));
|
||||
config.set("shortcuts", "no_such_shortcut", std::string("Ctrl+Q"));
|
||||
|
||||
ShortcutRegistry registry;
|
||||
registry.load(config);
|
||||
CHECK_FALSE(registry.is_customized(Shortcut::Arrange));
|
||||
CHECK(registry.lookup(ShortcutContext::Plater, { 'A' }) == Shortcut::Arrange);
|
||||
}
|
||||
Reference in New Issue
Block a user