Extract duplicate into core; support it in the script engine + wx GUI

A script using `duplicate` failed with "unsupported command 'duplicate'"
because the clone logic was still inline in the tui command. Extract it to
core/app/edit.hpp::duplicate_module(System*, src, dst) -> {ok, error, parts,
signals}: a deep clone of a module (parts, pins with spec + nc_origin, signals
with type overrides, pin→signal wiring; no connections), refusing on an unknown
source or an already-taken destination name.

  - the tui `duplicate` command renders the result (output unchanged);
  - the script engine dispatches `duplicate` to it — the failing script now runs;
  - the wx GUI gains Edit ▸ Duplicate module… (PickModule + a name prompt).

tests/test_edit.cpp: deep clone wires to the clone's own signal (not the
source's) and preserves the type; unknown source / existing destination
refused. 412 core assertions green; tui + wx build clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 22:04:45 +02:00
parent 794430e86c
commit c2b1f4c4ae
7 changed files with 155 additions and 44 deletions

View File

@@ -248,6 +248,15 @@ private:
+ " ports bound" + (r.unbound ? (", " + std::to_string(r.unbound) + " unbound") : ""));
return true;
}
if (cmd == "duplicate") {
if (!need(2)) return false;
DuplicateResult r = duplicate_module(sys_.get(), a[0], a[1]);
if (!r.ok) { emit(r.error); return false; }
emit("duplicate: '" + a[0] + "' → '" + a[1] + "' ("
+ std::to_string(r.parts) + " part(s), "
+ std::to_string(r.signals) + " signal(s))");
return true;
}
if (cmd == "verify") {
render_verify();
return true;