mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-29 08:32:00 -05:00
* Add co-extruded colors to the color picker
The color picker could make solid colors and gradients, but co-extruded
filaments (colors side by side along the strand, like dual color silk)
could only be kept, not created or edited.
Solid mode now works like Gradient where multi-color is allowed: its
colors show as blocks with the same - and + buttons. Two or more blocks
are a co-extruded color, one block is a plain solid. The Solid/Gradient
switch is unchanged. Co-extruded colors are saved as the existing
multicolor type (filament_colour_type 1, AMS ctype 1), which the
swatches already draw as segments.
Made with help from Claude
* Start a new solid from the selected gradient color
Made with help from Claude
* Carry colors over when switching between Solid and Gradient
Made with help from Claude
* Convert colors only on the first Solid/Gradient switch
Switching between Solid and Gradient used to copy colors across on every
switch, so edits made in one mode overwrote the other. Now the first
switch to a mode converts the other mode's colors, and after that each
mode keeps its own.
Gradient support now also allows co-extruded colors, so the separate
allow_coextruded option is removed.
Made with help from Claude
* Skip invalid favorites when loading instead of dropping all of them
Made with help from Claude
* Fix ColorPickerOptions initializer after removing allow_coextruded
Made with help from Claude
* Restore the original picker options at the project color call sites
With allow_coextruded gone, {true, true} already allows gradients and
co-extruded colors, so these two call sites no longer need to change.
Made with help from Claude
* Update the color picker design doc for the Solid/Gradient behavior
Made with help from Claude
* Merge gradient and co-extruded picker types into ColorMulti
Replace ColorGradient and ColorCoextruded with one ColorMulti
{colors, gradient} in ColorSelection = variant<ColorRGBA, ColorMulti>,
as suggested in review. This also collapses the duplicated gradient and
co-extruded branches in normalize, JSON load/save and the AMS conversion.
Made with help from Claude
---------
Co-authored-by: yw4z <ywsyildiz@gmail.com>
116 lines
5.9 KiB
C++
116 lines
5.9 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/generators/catch_generators.hpp>
|
|
|
|
#include "slic3r/GUI/AMSMaterialsSetting.hpp"
|
|
#include "slic3r/GUI/ColorPickerDialog.hpp"
|
|
#include "libslic3r/Color.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cstddef>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <variant>
|
|
#include <vector>
|
|
#include <wx/colour.h>
|
|
|
|
using namespace Slic3r;
|
|
using namespace Slic3r::GUI;
|
|
using ColorItem = ColorPickerPopup::ColorItem;
|
|
|
|
TEST_CASE("AMS custom solid colors preserve every RGBA byte with either firmware capability", "[AMSMaterialsSetting]")
|
|
{
|
|
const bool allow_gradient = GENERATE(false, true);
|
|
for (int byte = 0; byte < 256; ++byte) {
|
|
const ColorItem original{{wxColour(byte, 255 - byte, byte ^ 0x55, byte)}, 2};
|
|
const auto selection = original.picker_selection(allow_gradient);
|
|
REQUIRE(selection);
|
|
REQUIRE(std::holds_alternative<ColorRGBA>(*selection));
|
|
const ColorItem result = ColorItem::from_picker_selection(*selection);
|
|
REQUIRE(result.ctype == 2);
|
|
REQUIRE(result.colors == original.colors);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("AMS custom gradients retain repeated nodes direction and independent alpha", "[AMSMaterialsSetting]")
|
|
{
|
|
const std::vector<wxColour> colors{wxColour(255, 0, 0, 0), wxColour(0, 255, 0, 1),
|
|
wxColour(0, 0, 255, 128), wxColour(255, 0, 0, 0),
|
|
wxColour(255, 255, 0, 254), wxColour(0, 255, 255, 255),
|
|
wxColour(128, 64, 32, 80)};
|
|
const bool reverse = GENERATE(false, true);
|
|
for (size_t count = 2; count <= std::min(colors.size(), ColorPickerPopup::MAX_EDITABLE_COLORS); ++count) {
|
|
ColorItem original{{colors.begin(), colors.begin() + count}, 0};
|
|
if (reverse)
|
|
std::reverse(original.colors.begin(), original.colors.end());
|
|
const auto selection = original.picker_selection(true);
|
|
REQUIRE(selection);
|
|
REQUIRE(std::holds_alternative<ColorMulti>(*selection));
|
|
REQUIRE(std::get<ColorMulti>(*selection).gradient);
|
|
const ColorItem result = ColorItem::from_picker_selection(*selection);
|
|
REQUIRE(result.ctype == 0);
|
|
REQUIRE(result.colors == original.colors);
|
|
REQUIRE_FALSE(filament_color_picker_changed(*selection, result.picker_selection(true)));
|
|
REQUIRE_FALSE(filament_color_picker_changed(*selection, std::nullopt));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("AMS custom editing only accepts representable gradients on capable firmware", "[AMSMaterialsSetting]")
|
|
{
|
|
const std::vector<wxColour> colors{wxColour(255, 0, 0, 0), wxColour(0, 0, 255, 128)};
|
|
REQUIRE_FALSE(ColorItem{}.picker_selection(true));
|
|
REQUIRE_FALSE(ColorItem{colors, 0}.picker_selection(false));
|
|
REQUIRE_FALSE(ColorItem{colors, 1}.picker_selection(false));
|
|
REQUIRE_FALSE(ColorItem{colors, 2}.picker_selection(true));
|
|
REQUIRE_FALSE(ColorItem{std::vector<wxColour>(ColorPickerPopup::MAX_EDITABLE_COLORS + 1, colors.front()), 0}.picker_selection(true));
|
|
REQUIRE(ColorItem{colors, 0}.picker_selection(true));
|
|
REQUIRE(ColorItem{colors, 1}.picker_selection(true));
|
|
}
|
|
|
|
TEST_CASE("AMS custom co-extruded colors retain order, alpha and their color type", "[AMSMaterialsSetting]")
|
|
{
|
|
const std::vector<wxColour> colors{wxColour(255, 0, 0, 0), wxColour(0, 255, 0, 1),
|
|
wxColour(0, 0, 255, 128), wxColour(255, 255, 0, 254)};
|
|
for (size_t count = 2; count <= std::min(colors.size(), ColorPickerPopup::MAX_EDITABLE_COLORS); ++count) {
|
|
const ColorItem original{{colors.begin(), colors.begin() + count}, 1};
|
|
const auto selection = original.picker_selection(true);
|
|
REQUIRE(selection);
|
|
REQUIRE(std::holds_alternative<ColorMulti>(*selection));
|
|
REQUIRE_FALSE(std::get<ColorMulti>(*selection).gradient);
|
|
const ColorItem result = ColorItem::from_picker_selection(*selection);
|
|
REQUIRE(result.ctype == 1);
|
|
REQUIRE(result.colors == original.colors);
|
|
REQUIRE_FALSE(filament_color_picker_changed(*selection, result.picker_selection(true)));
|
|
REQUIRE(filament_color_picker_changed(*selection, ColorItem{original.colors, 0}.picker_selection(true)));
|
|
}
|
|
REQUIRE_FALSE(ColorItem{std::vector<wxColour>(ColorPickerPopup::MAX_EDITABLE_COLORS + 1, colors.front()), 1}.picker_selection(true));
|
|
}
|
|
|
|
TEST_CASE("AMS editing rejects five through seven colors while project editing retains them", "[AMSMaterialsSetting]")
|
|
{
|
|
const auto count = GENERATE(std::size_t{5}, std::size_t{6}, COLOR_PICKER_MAX_GRADIENT_COLORS);
|
|
const ColorItem original{std::vector<wxColour>(count, wxColour(12, 34, 56, 78)), 0};
|
|
REQUIRE_FALSE(original.picker_selection(true));
|
|
const auto project_selection = filament_color_picker_selection({std::vector<std::string>(count, "#0C22384E"), true});
|
|
REQUIRE(project_selection);
|
|
REQUIRE(ColorItem::from_picker_selection(*project_selection).colors == original.colors);
|
|
}
|
|
|
|
TEST_CASE("AMS alpha only edits and switching a gradient to solid replace the complete selection", "[AMSMaterialsSetting]")
|
|
{
|
|
const ColorItem original{{wxColour(255, 0, 0, 0), wxColour(0, 0, 255, 128)}, 0};
|
|
const auto initial = original.picker_selection(true);
|
|
REQUIRE(initial);
|
|
const ColorItem edited{{wxColour(255, 0, 0, 1), wxColour(0, 0, 255, 129)}, 0};
|
|
const auto selection = edited.picker_selection(true);
|
|
REQUIRE(selection);
|
|
REQUIRE(filament_color_picker_changed(*initial, selection));
|
|
REQUIRE(ColorItem::from_picker_selection(*selection).colors == edited.colors);
|
|
|
|
const ColorSelection solid = ColorRGBA(static_cast<unsigned char>(255), static_cast<unsigned char>(0),
|
|
static_cast<unsigned char>(0), static_cast<unsigned char>(0));
|
|
REQUIRE(filament_color_picker_changed(*initial, solid));
|
|
const ColorItem result = ColorItem::from_picker_selection(solid);
|
|
REQUIRE(result.ctype == 2);
|
|
REQUIRE(result.colors == std::vector<wxColour>{original.colors.front()});
|
|
}
|