First of the editing ops to reach the wx frontend. Extract the business logic
(validate the kind, tag the part, apply the connector model) into
core/app/edit.{hpp,cpp}: app::set_connector_type(Part*, kind) -> {ok, error,
materialised}, refusing without mutation when the kind is invalid for the part.
Both TUI call sites now use it: the `set-connector-type` command and the
interactive settype screen (de-dup) — output unchanged. The wx GUI gains an
Edit ▸ Set connector type… menu: a reusable PickPart() (module → part choice
dialogs) + a kind prompt, then the same core op, logged and reflected in the
model tree. Prune the now-dead pin_model/transform_vpx includes from
commands.cpp.
Unit-tested by tests/test_edit.cpp (free-form kind tags; invalid kind refused
without mutation; null part). tui + wx build clean; 376 core assertions green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
40 lines
1.2 KiB
C++
40 lines
1.2 KiB
C++
#include <doctest/doctest.h>
|
|
|
|
#include "core/app/edit.hpp"
|
|
#include "core/domain/parts.hpp"
|
|
#include "core/domain/pins.hpp"
|
|
|
|
// app::set_connector_type is pure core: validate the kind, tag the part and
|
|
// apply the connector model. No Print/dialog/FTXUI.
|
|
|
|
TEST_CASE("set_connector_type tags a part with a free-form kind") {
|
|
Part p("J1");
|
|
p.add(new Pin("1"));
|
|
p.add(new Pin("2"));
|
|
|
|
app::SetConnectorTypeResult r = app::set_connector_type(&p, "myconn");
|
|
|
|
CHECK(r.ok);
|
|
CHECK(r.error.empty());
|
|
CHECK(p.connector_type == "myconn");
|
|
}
|
|
|
|
TEST_CASE("set_connector_type refuses a kind the part doesn't fit — no mutation") {
|
|
Part p("J1");
|
|
p.add(new Pin("1"));
|
|
p.add(new Pin("2"));
|
|
p.add(new Pin("3")); // numeric pins don't fit the VPX single-letter columns
|
|
|
|
app::SetConnectorTypeResult r = app::set_connector_type(&p, "vpx-3u-bkp-p0");
|
|
|
|
CHECK_FALSE(r.ok);
|
|
CHECK_FALSE(r.error.empty());
|
|
CHECK(p.connector_type.empty()); // refused before any change
|
|
}
|
|
|
|
TEST_CASE("set_connector_type on a null part fails cleanly") {
|
|
app::SetConnectorTypeResult r = app::set_connector_type(nullptr, "x");
|
|
CHECK_FALSE(r.ok);
|
|
CHECK_FALSE(r.error.empty());
|
|
}
|