Domain - Signal carries a SignalType (Power/GndShield/Other), auto-inferred from the name in Signal::Signal via infer_signal_type. Override with the new `set-signal-type` command. - SignalType extracted to its own header so Pin can store an `expected_signal_type` without a pins↔signals include cycle. - pin_role(connector_type, pin_name) → SignalType lookup, called from set-type to populate each Pin's expected_signal_type. The VPX 3U table is currently a stub (returns Other). - New `verify` command walks typed parts and reports pins whose connected signal's type doesn't match the expectation. - ODS importer no longer drops pins with empty signal column — they stay in the part as NC, matching the rule "a pin is either NC or connected to a signal". - persist: new S tag for non-default signal type overrides. Tests - doctest v2.4.11 via FetchContent (with CMAKE_POLICY_VERSION_MINIMUM shim, doctest's CMakeLists has a too-old floor for current CMake). - Source files moved into a static library `essim_lib` so both `essim` and `essim_tests` reuse the same compilation. main.cpp is the only file kept out of the lib. - Layer 1 (pure helpers): ToLower, LongestCommonPrefix, Tokenize, NaturalLess (numeric/case/leading-zero edge cases + total-order invariants), signal_type round-trips and infer_signal_type families, VpxTransform registry + symmetry + reference-table mapping for connector P0 row 1, IdentityTransform same-name wiring. - Layer 2 (round-trip): build a synthetic 2-module system in code, save → restore → assert modules / parts / connector_types / NC pins / signal type overrides / connections + pin_map are all preserved. - Tui::Tokenize moved to a free function in tui_helpers so tests can call it without dragging ftxui into the unit-test layer. - 27 test cases, 123 assertions, ~150 ms. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
16 KiB
essim — notes for Claude
System digital twin: simulator for the interconnections between cards/boards. C++17, FTXUI for the TUI, importers for external netlist formats.
Build
cmake -S . -B build
cmake --build build -j
./build/essim
- CMake 3.14+ required (uses
FetchContent_MakeAvailable). - FTXUI is fetched at configure time from GitHub (
v6.1.9, shallow clone). First configure pays ~20 s for the clone; subsequent ones are cached inbuild/_deps/. - System dependencies (resolved via
find_package):libzip(targetlibzip::zip) andpugixml(targetpugixml::pugixml). Used by the ODS importer. Available on Arch viapacman -S libzip pugixml. - Sources are collected with
file(GLOB_RECURSE ALL_SOURCES "src/*.cpp"). After adding a new.cpp, re-runcmake -S . -B build— CMake does not re-glob automatically and link will fail with "undefined reference".
Layout
src/
main.cpp -- launches Tui
system/ -- domain model
syselmts.hpp SystemElement + SystemElementContainer<T> (templated, get/merge/iterate)
modules.{hpp,cpp} Module, Modules
parts.{hpp,cpp} Part, Parts
pins.{hpp,cpp} Pin, Pins
signals.{hpp,cpp} Signal, Signals
connect.{hpp,cpp} Connection, Connections
transform.{hpp,cpp} transforms applied to the model
system.{hpp,cpp} System: owns Modules + Connections, exposes Load()
imports/ -- adapters that populate the domain
import_base.hpp ImportBase interface
import_mentor.{hpp,cpp} Mentor Graphics netlist parser (done)
tui/ -- FTXUI shell, split by responsibility
tui.{hpp,cpp} Class Tui (state + Run() orchestrator + screen-mode event dispatcher)
tui_helpers.{hpp,cpp} Free helpers: ToLower, NaturalLess, LongestCommonPrefix
shell.cpp Print, Submit, Dispatch, Finalize, Tokenize, history persistence
completion.cpp CompleteCommand, CompletePath, CompleteInline
commands.cpp RegisterCommands (all built-in commands declared here)
screen_main.cpp BuildMainScreen (visualisation area + bottom input)
screen_search.cpp BuildSearchScreen
screen_connect.cpp BuildConnectScreen + shared RefreshFilteredPartList helper
screen_settype.cpp BuildSettypeScreen
screen_explore.cpp BuildExploreScreen (browse modules → parts/signals/connections → details; not scriptable)
doc/classes.puml -- PlantUML class diagram
include/ and lib/ are kept empty by design — FTXUI used to live there as precompiled .a + headers, now it comes through FetchContent.
Domain conventions
- Everything in
system/is pointer-based (commitd8122d1: "everything is pointer"). Containers storeT*, ownership lives with the container. SystemElementContainer<T>::merge(name)is the get-or-create primitive — call it instead ofaddwhen you don't know whether the element already exists.addthrows on duplicate names or empty names.using namespace std;is present insyselmts.hpp— pre-existing, don't add moreusing namespacein headers.- Include guards
_NAME_HPP_and#pragma onceare both used. Match the existing style.
TUI
Tui::Run() enters an FTXUI fullscreen loop:
- Top: scrollable visualisation area (
window+vscroll_indicator | yframe, last line getsfocusso it auto-scrolls). - Bottom: single-line
Inputinside a border. Label switches between>(normal) and<question>?(during a multi-step prompt). CatchEventis wrapped outside theRenderer(not betweenRendererandInput). Pattern:Renderer(input_component, lambda)thenCatchEvent(renderer, handler). WrappingCatchEvent(input, …)inside aContainer::Vertical({…})and thenRenderer(container, …)was found to break theInput's content rendering on at least one terminal — typed characters didn't show even thoughon_enterfired correctly.InputOption::transformis overridden to avoid hard-coded colors (default setsWhite on Blackwhen focused, which is unreadable on light terminal themes). The custom transform only appliesdimto the placeholder; everything else inherits terminal default fg/bg, so the UI adapts to any theme.InputOption::multilinemust be set tofalsefor the command prompt. Default istrue, and FTXUI'sHandleReturn()then both inserts\ninto the content and fireson_enter— soSubmit()would receive"help\n"instead of"help"and command lookups would all fall through to "unknown command".- Commands live in a
std::map<std::string, CommandSpec>registry built inRegisterCommands(). EachCommandSpeccarriesparams(list ofParam{name, completion}wherecompletionis theTui::Completionenum:None | Path | Command), anaction(args)lambda, aprompt_for_missingbool (defaulttrue), a one-linedescriptionstring, and ascriptablebool (defaulttrue). Settingscriptable = false(e.g.explore) excludes the command from the script-save buffer; if a non-scriptable command is invoked from a sourced file theSourceloop still aborts via thescreen_idx != 0check, since these commands are typically screen-openers.Dispatch(raw)tokenises the input (whitespace split with"…"quoting), takes inline args first, and (only whenprompt_for_missing) pushes aPromptonto the queue for each missing param. The last prompt's callback callsFinalize(). Setprompt_for_missing = falsefor commands that accept either zero args or a full arg list (e.g.search: bare → interactive, full → inline) — the action gets called immediately with whatever it received and decides what to do. Tabcompletes byParam::completion:PathtriggersCompletePath()(filesystem listing with~/expansion),CommandtriggersCompleteCommand()(matches against the registry),Nonedoes nothing. Both work inline (CompleteInline()figures out the arg position) and inside a multi-step prompt.help(no args) iterates the registry and printsname — descriptionfor every command.help <command>describes a single command, including eachParam's name. The argument hasCompletion::Command, sohelp <Tab>lists registered commands.Finalize()rebuilds the canonical inline form (name arg1 "arg with spaces" arg3) and writes that to history — so aloadcommand answered via interactive prompts still shows up inhistory(and on disk) as a single inline line, ready to be replayed via ↑.- Multi-step prompts work via a
std::deque<Prompt>queue.Submit()pops them one by one before falling back to dispatch. Adding a new command = one entry inRegisterCommands(); the prompt-flow and inline-flow are both handled automatically. - Tab completion: at the top-level prompt (no
pending), completes built-in command names. Inside a prompt withpath_completion = true(e.g. thefilenamestep ofload), completes file paths viastd::filesystem::directory_iterator(handles~/, dirs get a trailing/). Logic: 1 match → replace; multiple with progress on the longest common prefix → extend; multiple stuck at LCP → list candidates in the visualisation area.
Built-in commands: new, load, save, restore, source, script-save, connect, set-type, search, explore, clear, help, quit/exit. Esc cancels an in-progress multi-step prompt.
script-save <file> writes a replay-ready script of every command issued since the last new (the recorded buffer is cleared inside the new action). The buffer is appended to inside Finalize() after the action runs, with a denylist of commands that aren't useful in a replay: clear, help, quit, exit, source, script-save. Note the source exclusion: when a script is sourced, the individual lines inside the script are recorded (because each goes through Finalize), so the saved script reproduces the same end state without the indirection.
source <file> reads a script line by line and feeds each line through Submit(). While the script is running, in_source = true is set on the Tui and:
Dispatch/Finalizeskip writing to memory + on-disk history.- After each
Submit, ifscreen_idx != 0(a screen was opened by an "interactive" command like bareconnect/search/set-type), the script is aborted with an error message andscreen_idxis reset to 0 — interactive screen-opening commands are explicitly disallowed in scripts.
Pending prompts (from incomplete inline commands) are NOT considered interactive and are filled by subsequent script lines, the way you'd expect. Lines starting with # and blank lines are skipped; leading/trailing whitespace is trimmed; ~/ is expanded.
save / restore (src/system/persist.{hpp,cpp}): tab-delimited line format, no extra deps. Tags: M (module), P (part with connector_type), N (pin → signal name; empty = NC), S (signal → type override; only emitted for non-default), C (connection header with endpoints + transform_name), W (wire pair within the current connection).
Signals carry a type (SignalType::Power | GndShield | Other) auto-inferred from the name in Signal::Signal via infer_signal_type (heuristic: GND/GROUND/SHIELD/CHASSIS → GndShield; PWR/VCC/VDD/VEE/VSS/VBAT/VS_/VS3_*/+/- prefixes → Power; else Other). Override with set-signal-type <module> <signal> <power|gnd|other>. The explore screen shows the type in the signal detail header.
Pin role expectations: every Pin carries an expected_signal_type populated by set-type from a per-(connector_type, pin_name) lookup (src/system/pin_role.{hpp,cpp}). The framework is wired end-to-end; the actual VPX 3U lookup table is currently a stub returning Other for all positions — fill in vpx_3u_role(col, row, idx) with the real VITA 46 layout when needed. The verify command walks all typed parts and reports pins whose connected signal's type doesn't match the expectation.
SignalType lives in its own header src/system/signal_type.hpp (extracted from signals to avoid a pins↔signals include cycle).
Pins are either NC (signal() == nullptr) or connected to exactly one signal. The ODS importer creates a Pin for every row that has a non-empty pin name, even when the signal column is empty or "NC" — the pin stays in the Part as NC. restore replaces Tui::sys entirely (unique_ptr::reset). Names are stored as-is — must not contain TAB or newline (true for the EE netlists we ingest). Format is versioned by the # essim system snapshot v1 header for future compatibility.
Connector types & transforms: every Part carries a connector_type string (default "", set via the set-type command — inline set-type m p kind or bare which opens a TUI screen with module menu, part filter+menu, type input, list of types already in use, and an Apply button). When connect validates a pair, it consults TransformRegistry::lookup(p1->connector_type, p2->connector_type) (defined in src/system/transform.{hpp,cpp}) — both directions of the pair are tried. If neither is registered, an IdentityTransform fallback wires each pin of A to the same-name pin of B (when present). The resulting (Pin*, Pin*) list and the transform's name are stored on the Connection (pin_map, transform_name). To register a real transform: define a Transform subclass in transform.cpp and call TransformRegistry::get().add("kindA", "kindB", new MyTransform()) at init — there's no startup hook for this yet, so a small RegisterBuiltinTransforms() helper is the natural place to add when more types appear.
screen_idx mapping: 0 = main TUI, 1 = search, 2 = connect, 3 = set-type. Adding a new screen mode is the same recipe each time: state members, Container::Vertical of focusable components, a Renderer lambda that recomputes derived state per frame (e.g. filtered part lists), an entry in Container::Tab, and Tab/Esc handling in the outer CatchEvent.
connect is dual-mode (prompt_for_missing = false):
- Inline:
connect m1 p1 m2 p2. Each part argument is resolved as exact name first, then case-insensitive substring; ambiguous → lists candidates and aborts. - Bare: opens a dedicated full-screen layout (
screen_idx = 2) with two columns (endpoint 1/endpoint 2). Each column has a moduleMenu, a part filterInput, and a filtered partMenu. AButton(" Connect ")at the bottom commits.Tabcycles focus across the 7 components,Escleaves.
The connect screen rebuilds the filtered part lists inside the Renderer lambda each frame (cheap; lets the part menus react live to module changes and filter typing). Selection indices are clamped if a list shrinks below the previous index.
The Connection record stores Module*/Part* for both endpoints (added to Connection for this — minimal struct fields, no behaviour change).
search switches to a second full-screen layout (handled by Container::Tab({main, search}, &screen_idx)). Layout:
- Left column:
Menufor the module list andMenufor the type (parts/signals). - Right column:
Inputfor the live filter query, plus a results panel rebuilt every frame. Tabcycles focus between the query input and the menus. Implemented manually in the outerCatchEvent:Menu::OnEventconsumesEvent::Tabto cycle its own entries and returnstrue, which preventsContainer::Verticalfrom ever seeing the event (Container only cycles between children when the active child returnsfalse). So we short-circuit Tab/TabReverse upstream and mutatesearch_focus_idxdirectly.Escexits the search mode (flipsscreen_idxback to 0). The search state (selected module/type, query) is preserved across re-entries untilsearchis run again.
Adding a new screen mode = drop a screen_<name>.cpp defining Component Tui::BuildXxxScreen(), add corresponding state members in tui.hpp, register a BuildXxxScreen declaration in the screen-builders block, then in tui.cpp::Run() add a child to Container::Tab and a case in the screen-mode switch of the outer CatchEvent (Tab cycling + Esc-leave). Commands lived in commands.cpp set screen_idx to enter the new mode.
Command history is persisted on disk and loaded on startup. Path resolution is platform-aware:
- Linux/macOS:
$XDG_DATA_HOME/essim/history, falling back to~/.local/share/essim/history. - Windows:
%LOCALAPPDATA%\essim\history, falling back to%APPDATA%\…then%USERPROFILE%\AppData\Local\….
Each successful submission appends a single line to the file (so a crash doesn't lose history). Multi-step prompt answers are NOT persisted — only top-level commands.
Gotchas
System::LoadforIMPORT_ALTIUM: the corresponding constructor line is still commented out, soimpstays uninitialised → UB onimp->parse(...).IMPORT_MENTORandIMPORT_ODSare wired. Wrap calls intry/catch(the TUI does).- ODS importer: each spreadsheet sheet becomes a
Part(sheet name = part name). Rows are pin/signal pairs; the first non-empty row of each sheet is dropped as a header (no validation of header content). Empty cells skip the row;"NC"keeps the pin in the part but doesn't connect it to a signal. Pins or parts whose name collides (rare in well-formed sheets) are silently dropped. System::Loadthrowsstd::runtime_error("Unknown import type")for any value outside the three enum cases.Modules/Parts/etc. have no const-correct iteration on the*accessor; iterators onSystemElementContainer<T>are available butbegin()/end()are non-const-safe in some places.
Memory layout for sessions
Persistent notes live in ~/.claude/projects/-home-francois-Projets-essim/memory/. Index: MEMORY.md. Add project/feedback/user/reference entries there when relevant — see top-level Claude Code memory rules.