mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-03 03:42:05 +00:00
On current QIDI firmware a Box slot holds a material id string instead of a dictionary index, so filament sync could only match it by type. QIDI spools synced as Generic presets, for example QIDI PETG Tough and QIDI PETG-CF both as Generic PETG.
For these slots the name is now built from the box's vendor_str and filament_str, and the slot gets the visible, compatible preset with that name and the slot's filament type. When no preset matches, and on firmware with numeric slots, the slot gets the same preset as before.
(cherry picked from commit 16b658a281)
85 lines
4.1 KiB
C++
85 lines
4.1 KiB
C++
#include <catch2/catch_message.hpp>
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/generators/catch_generators.hpp>
|
|
|
|
#include <string>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include "slic3r/Utils/QidiPrinterAgent.hpp"
|
|
#include "slic3r/Utils/bambu_networking.hpp"
|
|
|
|
using namespace Slic3r;
|
|
|
|
TEST_CASE("A filament mapped to a Box slot saves that slot in its tool variable", "[QidiPrinterAgent]")
|
|
{
|
|
// Filament 2 is mapped to slot 5; filaments 0 and 1 have no slot.
|
|
// SAVE_VARIABLE reads VALUE as a Python literal, so the slot name needs its own quotes.
|
|
CHECK(QidiPrinterAgent::build_tool_slot_script("[-1, -1, 5]") == "SAVE_VARIABLE VARIABLE=value_t2 VALUE=\"'slot5'\"");
|
|
}
|
|
|
|
TEST_CASE("Each mapped filament gets its own tool variable line", "[QidiPrinterAgent]")
|
|
{
|
|
CHECK(QidiPrinterAgent::build_tool_slot_script("[3, -1, 0]") ==
|
|
"SAVE_VARIABLE VARIABLE=value_t0 VALUE=\"'slot3'\"\n"
|
|
"SAVE_VARIABLE VARIABLE=value_t2 VALUE=\"'slot0'\"");
|
|
}
|
|
|
|
TEST_CASE("A mapping without a usable Box slot saves nothing", "[QidiPrinterAgent]")
|
|
{
|
|
const std::string mapping = GENERATE(as<std::string>{},
|
|
"", // empty mapping
|
|
"[]", // no filaments
|
|
"[-1, -1]", // no filament has a slot
|
|
"[16]", // past the firmware's slot15
|
|
"[\"slot1\"]", // not a slot index
|
|
"{\"0\": 1}", // not an array
|
|
"[1,"); // not valid JSON
|
|
CAPTURE(mapping);
|
|
CHECK(QidiPrinterAgent::build_tool_slot_script(mapping).empty());
|
|
}
|
|
|
|
TEST_CASE("Filaments past the firmware's last tool variable are skipped", "[QidiPrinterAgent]")
|
|
{
|
|
// The firmware has value_t0 to value_t15: filament 15 maps to slot 1, filament 16 to slot 4.
|
|
std::string mapping = "[";
|
|
for (int filament = 0; filament < 15; ++filament)
|
|
mapping += "-1, ";
|
|
mapping += "1, 4]";
|
|
|
|
CHECK(QidiPrinterAgent::build_tool_slot_script(mapping) == "SAVE_VARIABLE VARIABLE=value_t15 VALUE=\"'slot1'\"");
|
|
}
|
|
|
|
TEST_CASE("The print start of a 3MF names the plate to print", "[QidiPrinterAgent]")
|
|
{
|
|
PrintParams params;
|
|
params.plate_index = 2;
|
|
|
|
CHECK(QidiPrinterAgent::print_start_request(params, "Cube.gcode.3mf") ==
|
|
nlohmann::json{{"filename", "Cube.gcode.3mf"}, {"plateindex", "2"}});
|
|
CHECK(QidiPrinterAgent::print_start_request(params, "Cube.gcode") == nlohmann::json{{"filename", "Cube.gcode"}});
|
|
}
|
|
|
|
TEST_CASE("A Box slot's filament name matches its per-printer preset", "[QidiPrinterAgent]")
|
|
{
|
|
// The Box reports vendor and product ("QIDI" + "PETG Tough"); presets add an "@<printer> <nozzle>" suffix.
|
|
CHECK(QidiPrinterAgent::preset_matches_slot("QIDI PETG Tough @Qidi X-Max 4 0.4 nozzle", "PETG", "QIDI PETG Tough", "PETG"));
|
|
// The type is compared before normalize_filament_type, which turns "PETG-CF" into "PETG".
|
|
CHECK(QidiPrinterAgent::preset_matches_slot("QIDI PETG-CF", "PETG-CF", "qidi petg-cf", "petg-cf"));
|
|
}
|
|
|
|
TEST_CASE("A Box slot's filament name does not match a different product or an empty name", "[QidiPrinterAgent]")
|
|
{
|
|
// A shared prefix is not a match, so "QIDI PETG" must not pick "QIDI PETG Tough".
|
|
CHECK_FALSE(QidiPrinterAgent::preset_matches_slot("QIDI PETG Tough @Qidi X-Max 4 0.4 nozzle", "PETG", "QIDI PETG", "PETG"));
|
|
CHECK_FALSE(QidiPrinterAgent::preset_matches_slot("Generic PETG @Qidi X-Max 4 0.4 nozzle", "PETG", "QIDI PETG Tough", "PETG"));
|
|
CHECK_FALSE(QidiPrinterAgent::preset_matches_slot("QIDI PETG Tough", "PETG", "", "PETG"));
|
|
}
|
|
|
|
TEST_CASE("A Box slot's filament name does not match a preset for a different material", "[QidiPrinterAgent]")
|
|
{
|
|
// The slot's name and type disagree, so the preset with that name is for another material.
|
|
CHECK_FALSE(QidiPrinterAgent::preset_matches_slot("QIDI PETG Tough @Qidi X-Max 4 0.4 nozzle", "PETG", "QIDI PETG Tough", "PLA"));
|
|
CHECK_FALSE(QidiPrinterAgent::preset_matches_slot("QIDI PETG Tough", "PETG", "QIDI PETG Tough", ""));
|
|
}
|