simple-circuit-engine 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +10 -7
- package/CLAUDE.md +4 -6
- package/README.md +5 -2
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +74 -2114
- package/dist/core/setup.d.ts +17 -0
- package/dist/core/simulation/CircuitRunner.d.ts +176 -0
- package/dist/core/simulation/DirtyTracker.d.ts +87 -0
- package/dist/core/simulation/EventQueue.d.ts +68 -0
- package/dist/core/simulation/StateManager.d.ts +100 -0
- package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
- package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
- package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
- package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
- package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
- package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
- package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
- package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
- package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
- package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
- package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
- package/dist/core/simulation/behaviors/index.d.ts +24 -0
- package/dist/core/simulation/behaviors/types.d.ts +101 -0
- package/dist/core/simulation/index.d.ts +18 -0
- package/dist/core/simulation/states/ComponentState.d.ts +57 -0
- package/dist/core/simulation/states/SimulationState.d.ts +46 -0
- package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
- package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
- package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
- package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
- package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
- package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
- package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
- package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
- package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
- package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
- package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
- package/dist/core/simulation/states/gates/index.d.ts +25 -0
- package/dist/core/simulation/states/index.d.ts +26 -0
- package/dist/core/simulation/states/types.d.ts +32 -0
- package/dist/core/simulation/types.d.ts +155 -0
- package/dist/core/topology/Circuit.d.ts +420 -0
- package/dist/core/topology/CircuitMetadata.d.ts +24 -0
- package/dist/core/topology/CircuitOptions.d.ts +14 -0
- package/dist/core/topology/Component.d.ts +152 -0
- package/dist/core/topology/ENode.d.ts +200 -0
- package/dist/core/topology/Wire.d.ts +130 -0
- package/dist/core/topology/delays.d.ts +52 -0
- package/dist/core/topology/index.d.ts +14 -0
- package/dist/core/topology/types.d.ts +175 -0
- package/dist/core/utils/CameraOptions.d.ts +83 -0
- package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
- package/dist/core/utils/Position.d.ts +166 -0
- package/dist/core/utils/Position3D.d.ts +77 -0
- package/dist/core/utils/Rotation.d.ts +82 -0
- package/dist/core/utils/index.d.ts +24 -0
- package/dist/core/utils/types.d.ts +35 -0
- package/dist/core-Bjta9Y7_.js +2707 -0
- package/dist/core-Bjta9Y7_.js.map +1 -0
- package/dist/index.d.ts +13 -6306
- package/dist/index.js +117 -110
- package/dist/scene/CircuitEngine.d.ts +270 -0
- package/dist/scene/index.d.ts +0 -1
- package/dist/scene/index.js +43 -39
- package/dist/scene/setup.d.ts +18 -0
- package/dist/scene/shared/AbstractCircuitController.d.ts +211 -0
- package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
- package/dist/scene/shared/EventEmitter.d.ts +92 -0
- package/dist/scene/shared/HoverManager.d.ts +151 -0
- package/dist/scene/shared/SelectionManager.d.ts +159 -0
- package/dist/scene/shared/WireVisualManager.d.ts +242 -0
- package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
- package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
- package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
- package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
- package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
- package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
- package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
- package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
- package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
- package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
- package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
- package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
- package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
- package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
- package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
- package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
- package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
- package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
- package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
- package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
- package/dist/scene/shared/components/index.d.ts +29 -0
- package/dist/scene/shared/components/types.d.ts +43 -0
- package/dist/scene/shared/types.d.ts +476 -0
- package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
- package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
- package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
- package/dist/scene/shared/utils/GeometryUtils.d.ts +261 -0
- package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
- package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
- package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
- package/dist/scene/shared/utils/Options.d.ts +16 -0
- package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
- package/dist/scene/static/CircuitController.d.ts +227 -0
- package/dist/scene/static/CircuitWriter.d.ts +146 -0
- package/dist/scene/static/PinTooltipWidget.d.ts +26 -0
- package/dist/scene/static/tools/BuildTool.d.ts +286 -0
- package/dist/scene/static/tools/ComponentPickerWidget.d.ts +82 -0
- package/dist/scene/static/tools/ConfigPanelWidget.d.ts +93 -0
- package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
- package/dist/scene-CVsDdySt.js +7357 -0
- package/dist/scene-CVsDdySt.js.map +1 -0
- package/package.json +24 -25
- package/dist/CircuitRunner-BQQlhwjD.js +0 -1981
- package/dist/CircuitRunner-BQQlhwjD.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scene/index.js.map +0 -1
- package/dist/setup-CIq_kgaw.js +0 -10230
- package/dist/setup-CIq_kgaw.js.map +0 -1
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { UUID, Rotation, Position } from '../utils';
|
|
2
|
+
import { ComponentType, ENodeSourceType, ICircuit } from './types';
|
|
3
|
+
import { CircuitOptions } from './CircuitOptions';
|
|
4
|
+
import { CircuitMetadata } from './CircuitMetadata';
|
|
5
|
+
import { Component } from './Component';
|
|
6
|
+
import { ENode } from './ENode';
|
|
7
|
+
import { Wire } from './Wire';
|
|
8
|
+
/**
|
|
9
|
+
* Circuit container managing components, ENodes, and wires.
|
|
10
|
+
*
|
|
11
|
+
* The Circuit class provides:
|
|
12
|
+
* - Component management (add/remove with automatic pin ENode creation)
|
|
13
|
+
* - Topology queries (get by ID, enumerate all)
|
|
14
|
+
* - Automatic lifecycle management (cascade deletion, orphan cleanup)
|
|
15
|
+
* - JSON serialization for persistence
|
|
16
|
+
*
|
|
17
|
+
* **Key Principles**:
|
|
18
|
+
* - Users manage Components and Wires; ENodes are managed automatically
|
|
19
|
+
* - Removing a Component cascades to remove its pins and connected wires
|
|
20
|
+
* - Orphaned branching ENodes (no wires) are automatically removed
|
|
21
|
+
* - All operations maintain bidirectional consistency
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const circuit = new Circuit();
|
|
26
|
+
*
|
|
27
|
+
* // Add a component at position (10, 20) with 2 pins
|
|
28
|
+
* const lightbulb = circuit.addComponent(
|
|
29
|
+
* new Position(10, 20),
|
|
30
|
+
* new Rotation(90),
|
|
31
|
+
* 2
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* console.log(lightbulb.id); // UUID
|
|
35
|
+
* console.log(lightbulb.pins); // [pin-uuid-1, pin-uuid-2]
|
|
36
|
+
*
|
|
37
|
+
* // Query components
|
|
38
|
+
* const comp = circuit.getComponent(lightbulb.id);
|
|
39
|
+
* const all = circuit.getAllComponents();
|
|
40
|
+
*
|
|
41
|
+
* // Remove component (cascade deletes pins and wires)
|
|
42
|
+
* circuit.removeComponent(lightbulb.id);
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare class Circuit {
|
|
46
|
+
/**
|
|
47
|
+
* Circuit metadata holding general information.
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
metadata: CircuitMetadata;
|
|
51
|
+
/**
|
|
52
|
+
* Map of all components in the circuit (UUID → Component).
|
|
53
|
+
* @private
|
|
54
|
+
*/
|
|
55
|
+
private components;
|
|
56
|
+
/**
|
|
57
|
+
* Map of all electrical nodes in the circuit (UUID → ENode).
|
|
58
|
+
* Includes both pin nodes and branching point nodes.
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
private enodes;
|
|
62
|
+
/**
|
|
63
|
+
* Map of all wires in the circuit (UUID → Wire).
|
|
64
|
+
* @private
|
|
65
|
+
*/
|
|
66
|
+
private wires;
|
|
67
|
+
/**
|
|
68
|
+
* Create a new empty circuit.
|
|
69
|
+
*/
|
|
70
|
+
constructor(options: CircuitOptions);
|
|
71
|
+
get name(): string;
|
|
72
|
+
set name(value: string);
|
|
73
|
+
/**
|
|
74
|
+
* Add a new component to the circuit.
|
|
75
|
+
*
|
|
76
|
+
* Automatically creates pin ENodes for the component and links them
|
|
77
|
+
* bidirectionally. Pin ENode UUIDs are stored in the component's pins array.
|
|
78
|
+
* Pin labels are derived from the ComponentType metadata.
|
|
79
|
+
*
|
|
80
|
+
* @param type - Component type (Battery, Switch, LED, etc.)
|
|
81
|
+
* @param position - Grid position (x, y integers)
|
|
82
|
+
* @param rotation - Orientation angle (integer degrees)
|
|
83
|
+
* @param config - Optional configuration map for component-specific settings
|
|
84
|
+
* @returns The created Component
|
|
85
|
+
* @throws {TypeError} If position/rotation coordinates are not integers
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const lightbulb = circuit.addComponent(
|
|
90
|
+
* new Position(10, 20),
|
|
91
|
+
* new Rotation(90),
|
|
92
|
+
* ComponentType.Lightbulb
|
|
93
|
+
* );
|
|
94
|
+
*
|
|
95
|
+
* console.log(lightbulb.type); // ComponentType.Lightbulb
|
|
96
|
+
* console.log(lightbulb.pins.length); // 2
|
|
97
|
+
* console.log(lightbulb.position.x); // 10
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
addComponent(type: ComponentType, position: Position, rotation: Rotation, config?: Map<string, string> | undefined): Component;
|
|
101
|
+
/**
|
|
102
|
+
* Resolve and update the transitionSpan config for a component
|
|
103
|
+
* if automatic resolution returns undefined nothing is done on the component
|
|
104
|
+
*
|
|
105
|
+
* @param component - Component to resolve transitionSpan for
|
|
106
|
+
*/
|
|
107
|
+
resolveTransitionSpan(component: Component): void;
|
|
108
|
+
/**
|
|
109
|
+
* Remove a component from the circuit.
|
|
110
|
+
*
|
|
111
|
+
* **Cascade deletion** removes:
|
|
112
|
+
* - All pin ENodes belonging to the component
|
|
113
|
+
* - All Wires connected to those pins
|
|
114
|
+
*
|
|
115
|
+
* @param id - Component UUID
|
|
116
|
+
* @throws {Error} If component does not exist
|
|
117
|
+
* @returns Object containing arrays of deleted Wires and ENodes IDs
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```typescript
|
|
121
|
+
* circuit.removeComponent(componentId);
|
|
122
|
+
* // Component, its pins, and connected wires are all removed
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
removeComponent(id: UUID): {
|
|
126
|
+
deletedWires: UUID[];
|
|
127
|
+
deletedENodes: UUID[];
|
|
128
|
+
};
|
|
129
|
+
hasComponent(id: UUID): boolean;
|
|
130
|
+
/**
|
|
131
|
+
* Get a component by ID.
|
|
132
|
+
*
|
|
133
|
+
* @param id - Component UUID
|
|
134
|
+
* @returns The Component or undefined if not found
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const component = circuit.getComponent(componentId);
|
|
139
|
+
* if (component) {
|
|
140
|
+
* console.log(component.position);
|
|
141
|
+
* }
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
getComponent(id: UUID): Component | undefined;
|
|
145
|
+
/**
|
|
146
|
+
* Get all components in the circuit.
|
|
147
|
+
*
|
|
148
|
+
* Returns a new array on each call (defensive copy).
|
|
149
|
+
*
|
|
150
|
+
* @returns Array of all Components
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const components = circuit.getAllComponents();
|
|
155
|
+
* console.log(`Circuit has ${components.length} components`);
|
|
156
|
+
*
|
|
157
|
+
* for (const comp of components) {
|
|
158
|
+
* console.log(comp.id, comp.position);
|
|
159
|
+
* }
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
getAllComponents(): Component[];
|
|
163
|
+
getAllComponentsByType(type: ComponentType): Component[];
|
|
164
|
+
getFirstComponentOfType(type: ComponentType): Component | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Get an electrical node by ID.
|
|
167
|
+
*
|
|
168
|
+
* Note: ENodes are automatically managed and not directly created
|
|
169
|
+
* or removed by users.
|
|
170
|
+
*
|
|
171
|
+
* @param id - ENode UUID
|
|
172
|
+
* @returns The ENode or undefined if not found
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const component = circuit.addComponent(
|
|
177
|
+
* new Position(10, 20),
|
|
178
|
+
* new Rotation(0),
|
|
179
|
+
* 2
|
|
180
|
+
* );
|
|
181
|
+
*
|
|
182
|
+
* const pinId = component.pins[0];
|
|
183
|
+
* const enode = circuit.getENode(pinId);
|
|
184
|
+
* console.log(enode.type); // ENodeType.Pin
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
getENode(id: UUID): ENode | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* Get all electrical nodes in the circuit.
|
|
190
|
+
*
|
|
191
|
+
* Includes both pin nodes (from components) and branching point nodes
|
|
192
|
+
* (from wire splits).
|
|
193
|
+
*
|
|
194
|
+
* Returns a new array on each call (defensive copy).
|
|
195
|
+
*
|
|
196
|
+
* @returns Array of all ENodes
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const enodes = circuit.getAllENodes();
|
|
201
|
+
* console.log(`Circuit has ${enodes.length} electrical nodes`);
|
|
202
|
+
*
|
|
203
|
+
* for (const enode of enodes) {
|
|
204
|
+
* console.log(enode.id, enode.type);
|
|
205
|
+
* }
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
getAllENodes(): ENode[];
|
|
209
|
+
/**
|
|
210
|
+
* Add a branching point electrical node at a specific position.
|
|
211
|
+
*
|
|
212
|
+
* Branching points are used to split wires and create junctions.
|
|
213
|
+
* @param position - Grid position for the branching point
|
|
214
|
+
* @param sourceType - Optional source type (voltage/current)
|
|
215
|
+
* @returns The created ENode
|
|
216
|
+
*/
|
|
217
|
+
addBranchingPoint(position: Position, sourceType?: ENodeSourceType): ENode;
|
|
218
|
+
/**
|
|
219
|
+
* Remove a branching point electrical node from the circuit.
|
|
220
|
+
* Also removes all wires connected to this branching point if there are ony one or more than 2.
|
|
221
|
+
* In the case there are exactly two wires, they will be merged before removing the branching point.
|
|
222
|
+
*
|
|
223
|
+
* @param id - Branching point ENode UUID
|
|
224
|
+
* @throws {Error} If ENode does not exist or is not a branching point
|
|
225
|
+
*/
|
|
226
|
+
removeBranchingPoint(id: UUID): {
|
|
227
|
+
deletedWires?: UUID[] | undefined;
|
|
228
|
+
mergedWires?: UUID[] | undefined;
|
|
229
|
+
newWire?: Wire | undefined;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Add a wire connecting two electrical nodes.
|
|
233
|
+
*
|
|
234
|
+
* Validates that both nodes exist, not a self-connection, and no duplicate.
|
|
235
|
+
* Updates bidirectional references (Wire ↔ ENodes).
|
|
236
|
+
*
|
|
237
|
+
* @param node1 - First ENode UUID
|
|
238
|
+
* @param node2 - Second ENode UUID
|
|
239
|
+
* @param intermediatePositions - Optional path waypoints for rendering
|
|
240
|
+
* @returns The created Wire, or Error if validation fails
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```typescript
|
|
244
|
+
* const comp1 = circuit.addComponent(new Position(0, 0), new Rotation(0), 1);
|
|
245
|
+
* const comp2 = circuit.addComponent(new Position(10, 10), new Rotation(0), 1);
|
|
246
|
+
*
|
|
247
|
+
* const wire = circuit.addWire(comp1.pins[0], comp2.pins[0]);
|
|
248
|
+
* if (wire instanceof Error) {
|
|
249
|
+
* console.error('Failed:', wire.message);
|
|
250
|
+
* }
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
addWire(node1: UUID, node2: UUID, intermediatePositions?: Position[]): Wire | Error;
|
|
254
|
+
/**
|
|
255
|
+
* Remove a wire from the circuit.
|
|
256
|
+
*
|
|
257
|
+
* @param id - Wire UUID
|
|
258
|
+
* @throws {Error} If wire does not exist
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* circuit.removeWire(wireId);
|
|
263
|
+
* // Wire is removed
|
|
264
|
+
* ```
|
|
265
|
+
*/
|
|
266
|
+
removeWire(id: UUID): void;
|
|
267
|
+
/**
|
|
268
|
+
* Split a wire in the circuit.
|
|
269
|
+
*
|
|
270
|
+
* It creates two new wires connected by either the target enode or a new branching point ENode at the specified position.
|
|
271
|
+
* Returns 2 UUIDS of the new wires.
|
|
272
|
+
*
|
|
273
|
+
* @param id - Wire UUID
|
|
274
|
+
* @param position
|
|
275
|
+
* @throws {Error} If wire does not exist
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```typescript
|
|
279
|
+
* circuit.splitWire(wireId);
|
|
280
|
+
* // Wire and any orphaned branching points are removed
|
|
281
|
+
* ```
|
|
282
|
+
*/
|
|
283
|
+
/**
|
|
284
|
+
* Split an existing wire at a position, creating a branching point.
|
|
285
|
+
* The original wire is removed and replaced with two new wires
|
|
286
|
+
* connecting through the new branching point.
|
|
287
|
+
* NB : in the special case where targetEnode belongs to a component where the wire is already connected
|
|
288
|
+
* only one new wire will be created as this method don't allow a wire directly connecting two pins of the same component.
|
|
289
|
+
*
|
|
290
|
+
* @param wireId - Wire to split
|
|
291
|
+
* @param position - Position for the new branching point : no effect if targetEnodeId provided
|
|
292
|
+
* @param targetEnodeId - if provided, the existing enode to split the wire at
|
|
293
|
+
* @returns Object containing the new branching point and an array of the two new wires
|
|
294
|
+
* @throws Error if wireId not found
|
|
295
|
+
*/
|
|
296
|
+
splitWire(wireId: UUID, position: Position, targetEnodeId?: UUID | null): {
|
|
297
|
+
branchingPoint: ENode;
|
|
298
|
+
wires: Array<Wire>;
|
|
299
|
+
};
|
|
300
|
+
getWireBetweenNodes(node1: UUID, node2: UUID): Wire | undefined;
|
|
301
|
+
/**
|
|
302
|
+
* Get a wire by ID.
|
|
303
|
+
*
|
|
304
|
+
* @param id - Wire UUID
|
|
305
|
+
* @returns The Wire or undefined if not found
|
|
306
|
+
*/
|
|
307
|
+
getWire(id: UUID): Wire | undefined;
|
|
308
|
+
/**
|
|
309
|
+
* Get all wires in the circuit.
|
|
310
|
+
*
|
|
311
|
+
* Returns a new array on each call (defensive copy).
|
|
312
|
+
*
|
|
313
|
+
* @returns Array of all Wires
|
|
314
|
+
*/
|
|
315
|
+
getAllWires(): Wire[];
|
|
316
|
+
/**
|
|
317
|
+
* Get all wires connected to a specific ENode.
|
|
318
|
+
*
|
|
319
|
+
* @param nodeId - ENode UUID
|
|
320
|
+
* @returns Array of connected Wires, or empty array if node not found
|
|
321
|
+
*/
|
|
322
|
+
getWiresByNode(nodeId: UUID): Wire[];
|
|
323
|
+
/**
|
|
324
|
+
* Get all wires connected to a component, e.g to any pin enode of the component.
|
|
325
|
+
*
|
|
326
|
+
* @param componentId - Component UUID
|
|
327
|
+
* @returns Array of connected Wires, or empty array if component not found
|
|
328
|
+
*/
|
|
329
|
+
getWiresByComponent(componentId: UUID): Wire[];
|
|
330
|
+
/**
|
|
331
|
+
* Get both ENodes connected by a wire.
|
|
332
|
+
*
|
|
333
|
+
* @param wireId - Wire UUID
|
|
334
|
+
* @returns Tuple [node1, node2] or undefined if wire not found
|
|
335
|
+
*/
|
|
336
|
+
getNodesByWire(wireId: UUID): [ENode, ENode] | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* Check if a wire already exists between two nodes.
|
|
339
|
+
*
|
|
340
|
+
* Order-independent: returns true for (A, B) or (B, A).
|
|
341
|
+
*
|
|
342
|
+
* @param node1 - First ENode UUID
|
|
343
|
+
* @param node2 - Second ENode UUID
|
|
344
|
+
* @returns true if wire exists, false otherwise
|
|
345
|
+
*/
|
|
346
|
+
hasWireBetween(node1: UUID, node2: UUID): boolean;
|
|
347
|
+
/**
|
|
348
|
+
* Find all components with pins among the provided enode IDs set.
|
|
349
|
+
*
|
|
350
|
+
* @param pinIds - Set of pins UUIDs
|
|
351
|
+
* @returns Set of components UUIDs
|
|
352
|
+
*/
|
|
353
|
+
getComponentsOfPins(pinIds: Set<UUID>): Set<UUID>;
|
|
354
|
+
/**
|
|
355
|
+
* Get a component's pin ENode by its label.
|
|
356
|
+
* @param component
|
|
357
|
+
* @param pinLabel
|
|
358
|
+
*/
|
|
359
|
+
getComponentPinByLabel(component: Component, pinLabel: string): ENode | undefined;
|
|
360
|
+
/**
|
|
361
|
+
* Update the intermediate positions of a wire.
|
|
362
|
+
* Update the wire in place.
|
|
363
|
+
*
|
|
364
|
+
* @param wireId - Wire to update
|
|
365
|
+
* @param intermediatePositions - New intermediate positions
|
|
366
|
+
* @param simplify - Whether to simplify positions by removing collinear points : useful when finalizing wire routing
|
|
367
|
+
* @returns The updated Wire
|
|
368
|
+
* @throws Error if wireId not found
|
|
369
|
+
*/
|
|
370
|
+
updateWireIntermediatePositions(wireId: UUID, intermediatePositions: Position[], simplify?: boolean): Wire;
|
|
371
|
+
/**
|
|
372
|
+
* Simplify intermediate positions of a wire.
|
|
373
|
+
* Update the wire in place.
|
|
374
|
+
* @param wireId - Wire to simplify
|
|
375
|
+
* @returns The updated Wire
|
|
376
|
+
* @throws Error if wireId not found
|
|
377
|
+
*/
|
|
378
|
+
simplifyWireIntermediatePositions(wireId: UUID): Wire;
|
|
379
|
+
/**
|
|
380
|
+
* Update the source type of an ENode (branching point or component pin).
|
|
381
|
+
* @param enodeId - ENode to update
|
|
382
|
+
* @param sourceType - New source type (null to clear)
|
|
383
|
+
* @throws Error if enodeId not found
|
|
384
|
+
*/
|
|
385
|
+
updateENodeSourceType(enodeId: UUID, sourceType: ENodeSourceType | null): void;
|
|
386
|
+
/**
|
|
387
|
+
* iterate through all components, enodes and wires positions to get the size that allows to enclose all elements.
|
|
388
|
+
* @param margin - optional margin to add to the size
|
|
389
|
+
* @returns size that allows to enclose all elements plus margin
|
|
390
|
+
* @todo if calls to this method at each build operation ends causes slowness see to optimize by restricting checked elements
|
|
391
|
+
*/
|
|
392
|
+
getEnclosingSize(margin?: number): number;
|
|
393
|
+
/**
|
|
394
|
+
* Serialize circuit to JSON.
|
|
395
|
+
*
|
|
396
|
+
* @returns JSON-serializable object containing all components, enodes, and wires
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* ```typescript
|
|
400
|
+
* const json = circuit.toJSON();
|
|
401
|
+
* localStorage.setItem('my-circuit', JSON.stringify(json));
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
toJSON(): ICircuit;
|
|
405
|
+
/**
|
|
406
|
+
* Deserialize circuit from JSON.
|
|
407
|
+
*
|
|
408
|
+
* @param json - Circuit data
|
|
409
|
+
* @returns Circuit instance
|
|
410
|
+
* @throws {Error} If JSON is invalid or violates invariants
|
|
411
|
+
*
|
|
412
|
+
* @example
|
|
413
|
+
* ```typescript
|
|
414
|
+
* const jsonStr = localStorage.getItem('my-circuit');
|
|
415
|
+
* const json = JSON.parse(jsonStr);
|
|
416
|
+
* const circuit = Circuit.fromJSON(json);
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
static fromJSON(json: ICircuit): Circuit;
|
|
420
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CameraOptions } from '../utils';
|
|
2
|
+
import { CircuitOptions } from './CircuitOptions';
|
|
3
|
+
import { ICircuitMetadata } from './types';
|
|
4
|
+
export declare class CircuitMetadata implements ICircuitMetadata {
|
|
5
|
+
version: string;
|
|
6
|
+
options: CircuitOptions;
|
|
7
|
+
size: number;
|
|
8
|
+
divisions: number;
|
|
9
|
+
cameraOptions: CameraOptions;
|
|
10
|
+
/**
|
|
11
|
+
* Create a new CircuitMetadata holding general information about the Circuit.
|
|
12
|
+
*
|
|
13
|
+
* @param version - Circuit version
|
|
14
|
+
* @param options - Circuit options
|
|
15
|
+
* @param size - Size of the circuit grid
|
|
16
|
+
* @param divisions - Divisions in the circuit grid
|
|
17
|
+
* @param cameraOptions - Camera Options at startup
|
|
18
|
+
* @throws {TypeError} If size or divisions are not integers
|
|
19
|
+
*/
|
|
20
|
+
constructor(version: string, options: CircuitOptions, size: number, divisions: number, cameraOptions: CameraOptions);
|
|
21
|
+
toJSON(): ICircuitMetadata;
|
|
22
|
+
static fromJSON(json: ICircuitMetadata): CircuitMetadata;
|
|
23
|
+
toString(): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ICircuitOptions, LogicFamily } from './types';
|
|
2
|
+
export declare class CircuitOptions implements ICircuitOptions {
|
|
3
|
+
name: string;
|
|
4
|
+
defaultLogicFamily: LogicFamily;
|
|
5
|
+
/**
|
|
6
|
+
* Create new circuit options.
|
|
7
|
+
*
|
|
8
|
+
* @param name - Circuit name (default: Untitled Circuit)
|
|
9
|
+
* @param defaultLogicFamily - Circuit default logic family (default: CMOS1)
|
|
10
|
+
*/
|
|
11
|
+
constructor(name?: string, defaultLogicFamily?: LogicFamily);
|
|
12
|
+
toJSON(): ICircuitOptions;
|
|
13
|
+
static fromJSON(json: ICircuitOptions): CircuitOptions;
|
|
14
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { UUID, Position, Rotation } from '../utils';
|
|
2
|
+
import { ComponentType, IComponent } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Electrical component placed on the circuit grid.
|
|
5
|
+
*
|
|
6
|
+
* Components represent physical circuit elements (lightbulbs, transistors, etc.)
|
|
7
|
+
* with a specific position, orientation, and set of electrical connection pins.
|
|
8
|
+
*
|
|
9
|
+
* **Lifecycle**: Components are created and removed via the Circuit class.
|
|
10
|
+
* When a component is added to a circuit, pin ENodes are automatically created
|
|
11
|
+
* for each pin. When removed, pins and connected wires are cascade-deleted.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const position = new Position(10, 20);
|
|
16
|
+
* const rotation = new Rotation(90);
|
|
17
|
+
* const pins = ['pin-uuid-1', 'pin-uuid-2'];
|
|
18
|
+
*
|
|
19
|
+
* const component = new Component(position, rotation, pins);
|
|
20
|
+
*
|
|
21
|
+
* console.log(component.id); // "550e8400-..."
|
|
22
|
+
* console.log(component.position); // Position { x: 10, y: 20 }
|
|
23
|
+
* console.log(component.rotation); // Rotation { angle: 90 }
|
|
24
|
+
* console.log(component.pins); // ['pin-uuid-1', 'pin-uuid-2']
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class Component {
|
|
28
|
+
/**
|
|
29
|
+
* Unique identifier for this component.
|
|
30
|
+
* @readonly
|
|
31
|
+
*/
|
|
32
|
+
readonly id: UUID;
|
|
33
|
+
/**
|
|
34
|
+
* Component type (Battery, Switch, LED, etc.).
|
|
35
|
+
* @readonly
|
|
36
|
+
*/
|
|
37
|
+
readonly type: ComponentType;
|
|
38
|
+
/**
|
|
39
|
+
* Position on the 2D discrete grid.
|
|
40
|
+
* @readonly
|
|
41
|
+
*/
|
|
42
|
+
readonly position: Position;
|
|
43
|
+
/**
|
|
44
|
+
* Orientation angle in degrees.
|
|
45
|
+
* @readonly
|
|
46
|
+
*/
|
|
47
|
+
readonly rotation: Rotation;
|
|
48
|
+
/**
|
|
49
|
+
* Array of pin ENode UUIDs.
|
|
50
|
+
* Pin order is significant (index 0 is first pin, etc.).
|
|
51
|
+
* @readonly
|
|
52
|
+
*/
|
|
53
|
+
readonly pins: ReadonlyArray<UUID>;
|
|
54
|
+
/**
|
|
55
|
+
* Configuration parameters for this component instance.
|
|
56
|
+
*
|
|
57
|
+
* This map holds key-value pairs representing configurable settings
|
|
58
|
+
* The available configuration keys depend on the component type see IComponentTypeMetadata for details.
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
config: Map<string, string>;
|
|
62
|
+
/**
|
|
63
|
+
* allow to flag a component as non editable (feature to implement)
|
|
64
|
+
*/
|
|
65
|
+
editable: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Create a new component.
|
|
68
|
+
*
|
|
69
|
+
* **Note**: Typically components are created via `Circuit.addComponent()`
|
|
70
|
+
* which handles pin ENode creation automatically. This constructor is used
|
|
71
|
+
* internally by Circuit.
|
|
72
|
+
*
|
|
73
|
+
* @param type - Component type (Battery, Switch, LED, etc.)
|
|
74
|
+
* @param position - Grid position (integer x, y)
|
|
75
|
+
* @param rotation - Orientation angle (integer degrees)
|
|
76
|
+
* @param pins - Array of pin ENode UUIDs
|
|
77
|
+
*
|
|
78
|
+
* @param editable
|
|
79
|
+
* @example
|
|
80
|
+
* ```typescript
|
|
81
|
+
* // Usually created via Circuit:
|
|
82
|
+
* const component = circuit.addComponent(
|
|
83
|
+
* new Position(10, 20),
|
|
84
|
+
* new Rotation(90),
|
|
85
|
+
* ComponentType.Battery
|
|
86
|
+
* );
|
|
87
|
+
*
|
|
88
|
+
* // Direct construction (for deserialization):
|
|
89
|
+
* const component = new Component(
|
|
90
|
+
* ComponentType.Battery,
|
|
91
|
+
* new Position(10, 20),
|
|
92
|
+
* new Rotation(90),
|
|
93
|
+
* ['pin-id-1', 'pin-id-2']
|
|
94
|
+
* );
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
constructor(type: ComponentType, position: Position, rotation: Rotation, pins: ReadonlyArray<UUID>, editable?: boolean);
|
|
98
|
+
getPinLabel(pinId: UUID): string | undefined;
|
|
99
|
+
setAllParameters(config: Map<string, string>): void;
|
|
100
|
+
setParameter(key: string, value: string): void;
|
|
101
|
+
/**
|
|
102
|
+
* Update the component's position.
|
|
103
|
+
*
|
|
104
|
+
* @param newPosition - The new position for the component
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const component = circuit.getComponent(componentId);
|
|
109
|
+
* component.setPosition(new Position(15, 25));
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
setPosition(newPosition: Position): void;
|
|
113
|
+
/**
|
|
114
|
+
* Update the component's rotation.
|
|
115
|
+
*
|
|
116
|
+
* @param newRotation - The new rotation for the component
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const component = circuit.getComponent(componentId);
|
|
121
|
+
* component.setRotation(new Rotation(90));
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
setRotation(newRotation: Rotation): void;
|
|
125
|
+
/**
|
|
126
|
+
* Serialize component to JSON.
|
|
127
|
+
*
|
|
128
|
+
* @returns Plain object representation
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const json = component.toJSON();
|
|
133
|
+
* console.log(json);
|
|
134
|
+
* // {
|
|
135
|
+
* // id: "550e8400-...",
|
|
136
|
+
* // type: "battery",
|
|
137
|
+
* // position: { x: 10, y: 20 },
|
|
138
|
+
* // rotation: 90,
|
|
139
|
+
* // pins: ['pin-uuid-1', 'pin-uuid-2']
|
|
140
|
+
* // }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
toJSON(): IComponent;
|
|
144
|
+
/**
|
|
145
|
+
* Deserialize component from JSON.
|
|
146
|
+
*
|
|
147
|
+
* @param json - Component data
|
|
148
|
+
* @returns Component instance
|
|
149
|
+
*
|
|
150
|
+
*/
|
|
151
|
+
static fromJSON(json: IComponent): Component;
|
|
152
|
+
}
|