Show the component libraries in the palette - #2
Merged
Merged
Conversation
The palette lists component *types* - a generic BJT, Diode, JFET - built from a hardcoded array plus a reflection scan. The part libraries in Circuit/Components/*.xml are never read, so the ~87 parts in them cannot be reached from the editor: placing a 2N3904 means dropping a bare BJT and typing IS, BF and BR by hand, and the tube models are effectively unusable. GUI_PORT_PLAN.md:85 lists component library insertion as Phase 3 work, so this looked known-incomplete rather than deliberate. ComponentLibrary reads the same XML the WPF app does: a Library element of Component elements, each handed to Circuit.Component.Deserialize. The palette becomes a tree of collapsible categories, because a flat list would put the generic Diode at the same level as the sixteen specific ones with only a trailing "s" to tell them apart - and 110 entries is too many to scan. The tiers follow the WPF app (ComponentLibrary.xaml.cs builds Common, then Generic, then the libraries), including its names, so the layout is familiar to someone coming from Windows: Common (10) everyday parts, expanded by default Generic (22) the reflection-discovered component classes Diodes (16), Op-Amps (12), Transistors (47), Tubes (12) Both Diode entries earn their place: the generic one is what you need for a part the libraries do not carry, or to hand-tune a model. Headers carry counts, and a filter box narrows the list - filtering expands every category that matched, since results hidden behind a collapsed header would defeat the search. Each LibraryPart keeps its source XElement rather than a deserialized prototype, and deserializes afresh per placement: components are mutable, so a shared instance would let an edit to one placed part appear in the next one. There is a test for that. Also fixes the reason the libraries would not have been found even with this code: Circuit.csproj marked all four XML files as Content but set CopyToOutputDirectory on Tubes.xml alone, so a host looking beside its executable saw one library out of four. Verified on this branch: builds clean, all four libraries reach the output, ComponentLibraryTests 3/3, SchematicCanvasInteractionTests 10/10, AppSettingsTests 3/3, and the palette renders as described. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second of the PRs offered in #272. Independent of #1 — either can merge first — though #1 makes this one easier to verify, since the suite currently can't be run as a whole.
Not a macOS change, like the last one. Found while adopting your branch; the behaviour is (according to Claude, running on my MacOS) "identical on Linux".
The gap
The palette lists component types — a generic BJT, Diode, JFET — from a hardcoded array plus a reflection scan. The part libraries in
Circuit/Components/*.xmlare never read, so the ~87 parts in them can't be reached from the editor. Placing a 2N3904 means dropping a bare BJT and typingIS,BF,BRby hand; the tube models are effectively unusable.GUI_PORT_PLAN.md:85lists "component library insertion" under Phase 3, so this looked known-incomplete rather than deliberate — but do say if it was intentional and I'll drop this.What it does
ComponentLibraryreads the same XML the WPF app does: aLibraryelement ofComponentelements, each handed toCircuit.Component.Deserialize.The palette becomes a tree of collapsible categories, because a flat list would put the generic
Diodeat the same level as the sixteen specific ones with only a trailing "s" between them — and 110 entries is a lot to scan. The tiers follow the WPF app (ComponentLibrary.xaml.csbuildsCommon, thenGeneric, then the libraries), names included, so it's familiar coming from Windows:Both
Diodeentries earn their place — the generic one is what you need for a part the libraries don't carry, or to hand-tune a model. Headers carry counts, and a filter box narrows the list; filtering expands every category that matched, since results hidden behind a collapsed header would defeat the search.Two details worth a look
Fresh instance per placement. Each
LibraryPartkeeps its sourceXElementrather than a deserialized prototype and deserializes again for every placement. Components are mutable, so a shared prototype would let an edit to one placed part show up in the next one. There's a test for it, and I also checked it by hand — place two 2N3904s, setBF=999on one, the other still reads 300.The libraries weren't reaching the build output.
Circuit.csprojmarked all four XML files asContentbut setCopyToOutputDirectoryonTubes.xmlalone — so even with this code, a host looking beside its executable would find one library out of four. Fixed with a wildcard. That's the only change outsideLiveSPICE.Avalonia.Verified on this branch
Builds clean; all four libraries reach the output;
ComponentLibraryTests3/3,SchematicCanvasInteractionTests10/10,AppSettingsTests3/3 (run per-class, since the suite still hangs without #1); palette renders as described.🤖 Generated with Claude Code