simple-circuit-engine 0.0.10 → 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.
Files changed (141) hide show
  1. package/AGENTS.md +13 -7
  2. package/CLAUDE.md +16 -103
  3. package/README.md +8 -5
  4. package/dist/core/index.d.ts +2 -23
  5. package/dist/core/index.js +75 -2000
  6. package/dist/core/setup.d.ts +17 -0
  7. package/dist/core/simulation/CircuitRunner.d.ts +176 -0
  8. package/dist/core/simulation/DirtyTracker.d.ts +87 -0
  9. package/dist/core/simulation/EventQueue.d.ts +68 -0
  10. package/dist/core/simulation/StateManager.d.ts +100 -0
  11. package/dist/core/simulation/behaviors/BehaviorRegistry.d.ts +70 -0
  12. package/dist/core/simulation/behaviors/ComponentBehavior.d.ts +53 -0
  13. package/dist/core/simulation/behaviors/basic/BatteryBehavior.d.ts +14 -0
  14. package/dist/core/simulation/behaviors/basic/ClockBehavior.d.ts +24 -0
  15. package/dist/core/simulation/behaviors/basic/DoubleThrowSwitchBehavior.d.ts +33 -0
  16. package/dist/core/simulation/behaviors/basic/LightbulbBehavior.d.ts +23 -0
  17. package/dist/core/simulation/behaviors/basic/RectangleLEDBehavior.d.ts +24 -0
  18. package/dist/core/simulation/behaviors/basic/RelayBehavior.d.ts +33 -0
  19. package/dist/core/simulation/behaviors/basic/SmallLEDBehavior.d.ts +24 -0
  20. package/dist/core/simulation/behaviors/basic/SwitchBehavior.d.ts +33 -0
  21. package/dist/core/simulation/behaviors/basic/index.d.ts +20 -0
  22. package/dist/core/simulation/behaviors/gates/InverterBehavior.d.ts +29 -0
  23. package/dist/core/simulation/behaviors/gates/Nand4GateBehavior.d.ts +18 -0
  24. package/dist/core/simulation/behaviors/gates/Nand8GateBehavior.d.ts +18 -0
  25. package/dist/core/simulation/behaviors/gates/NandGateBehavior.d.ts +28 -0
  26. package/dist/core/simulation/behaviors/gates/Nor4GateBehavior.d.ts +18 -0
  27. package/dist/core/simulation/behaviors/gates/Nor8GateBehavior.d.ts +18 -0
  28. package/dist/core/simulation/behaviors/gates/NorGateBehavior.d.ts +22 -0
  29. package/dist/core/simulation/behaviors/gates/Xor4GateBehavior.d.ts +18 -0
  30. package/dist/core/simulation/behaviors/gates/Xor8GateBehavior.d.ts +18 -0
  31. package/dist/core/simulation/behaviors/gates/XorGateBehavior.d.ts +22 -0
  32. package/dist/core/simulation/behaviors/gates/index.d.ts +34 -0
  33. package/dist/core/simulation/behaviors/index.d.ts +24 -0
  34. package/dist/core/simulation/behaviors/types.d.ts +101 -0
  35. package/dist/core/simulation/index.d.ts +18 -0
  36. package/dist/core/simulation/states/ComponentState.d.ts +57 -0
  37. package/dist/core/simulation/states/SimulationState.d.ts +46 -0
  38. package/dist/core/simulation/states/basic/BatteryState.d.ts +16 -0
  39. package/dist/core/simulation/states/basic/ClockState.d.ts +16 -0
  40. package/dist/core/simulation/states/basic/DoubleThrowSwitchState.d.ts +21 -0
  41. package/dist/core/simulation/states/basic/LightbulbState.d.ts +21 -0
  42. package/dist/core/simulation/states/basic/RectangleLEDState.d.ts +9 -0
  43. package/dist/core/simulation/states/basic/RelayState.d.ts +25 -0
  44. package/dist/core/simulation/states/basic/SmallLEDState.d.ts +21 -0
  45. package/dist/core/simulation/states/basic/SwitchState.d.ts +25 -0
  46. package/dist/core/simulation/states/gates/InverterState.d.ts +17 -0
  47. package/dist/core/simulation/states/gates/Nand4GateState.d.ts +10 -0
  48. package/dist/core/simulation/states/gates/Nand8GateState.d.ts +10 -0
  49. package/dist/core/simulation/states/gates/NandGateState.d.ts +16 -0
  50. package/dist/core/simulation/states/gates/Nor4GateState.d.ts +10 -0
  51. package/dist/core/simulation/states/gates/Nor8GateState.d.ts +10 -0
  52. package/dist/core/simulation/states/gates/NorGateState.d.ts +10 -0
  53. package/dist/core/simulation/states/gates/Xor4GateState.d.ts +10 -0
  54. package/dist/core/simulation/states/gates/Xor8GateState.d.ts +10 -0
  55. package/dist/core/simulation/states/gates/XorGateState.d.ts +10 -0
  56. package/dist/core/simulation/states/gates/index.d.ts +25 -0
  57. package/dist/core/simulation/states/index.d.ts +26 -0
  58. package/dist/core/simulation/states/types.d.ts +32 -0
  59. package/dist/core/simulation/types.d.ts +155 -0
  60. package/dist/core/topology/Circuit.d.ts +420 -0
  61. package/dist/core/topology/CircuitMetadata.d.ts +24 -0
  62. package/dist/core/topology/CircuitOptions.d.ts +14 -0
  63. package/dist/core/topology/Component.d.ts +152 -0
  64. package/dist/core/topology/ENode.d.ts +200 -0
  65. package/dist/core/topology/Wire.d.ts +130 -0
  66. package/dist/core/topology/delays.d.ts +52 -0
  67. package/dist/core/topology/index.d.ts +14 -0
  68. package/dist/core/topology/types.d.ts +175 -0
  69. package/dist/core/utils/CameraOptions.d.ts +83 -0
  70. package/dist/core/utils/MemoizeDecorator.d.ts +9 -0
  71. package/dist/core/utils/Position.d.ts +166 -0
  72. package/dist/core/utils/Position3D.d.ts +77 -0
  73. package/dist/core/utils/Rotation.d.ts +82 -0
  74. package/dist/core/utils/index.d.ts +24 -0
  75. package/dist/core/utils/types.d.ts +35 -0
  76. package/dist/core-Bjta9Y7_.js +2707 -0
  77. package/dist/core-Bjta9Y7_.js.map +1 -0
  78. package/dist/index.d.ts +13 -6286
  79. package/dist/index.js +120 -100
  80. package/dist/scene/CircuitEngine.d.ts +270 -0
  81. package/dist/scene/index.d.ts +1 -2
  82. package/dist/scene/index.js +44 -38
  83. package/dist/scene/setup.d.ts +18 -0
  84. package/dist/scene/shared/AbstractCircuitController.d.ts +211 -0
  85. package/dist/scene/shared/BranchingPointVisualFactory.d.ts +70 -0
  86. package/dist/scene/shared/EventEmitter.d.ts +92 -0
  87. package/dist/scene/shared/HoverManager.d.ts +151 -0
  88. package/dist/scene/shared/SelectionManager.d.ts +159 -0
  89. package/dist/scene/shared/WireVisualManager.d.ts +242 -0
  90. package/dist/scene/shared/components/ComponentVisualFactory.d.ts +438 -0
  91. package/dist/scene/shared/components/DefaultVisualFactory.d.ts +51 -0
  92. package/dist/scene/shared/components/FactoryRegistry.d.ts +84 -0
  93. package/dist/scene/shared/components/GroupedFactoryRegistry.d.ts +153 -0
  94. package/dist/scene/shared/components/basic/BatteryVisualFactory.d.ts +13 -0
  95. package/dist/scene/shared/components/basic/ClockVisualFactory.d.ts +79 -0
  96. package/dist/scene/shared/components/basic/DoubleThrowSwitchVisualFactory.d.ts +87 -0
  97. package/dist/scene/shared/components/basic/LabelVisualFactory.d.ts +148 -0
  98. package/dist/scene/shared/components/basic/LightbulbVisualFactory.d.ts +72 -0
  99. package/dist/scene/shared/components/basic/RectangleLEDVisualFactory.d.ts +86 -0
  100. package/dist/scene/shared/components/basic/RelayVisualFactory.d.ts +92 -0
  101. package/dist/scene/shared/components/basic/SmallLEDVisualFactory.d.ts +86 -0
  102. package/dist/scene/shared/components/basic/SwitchVisualFactory.d.ts +85 -0
  103. package/dist/scene/shared/components/gates/InverterVisualFactory.d.ts +104 -0
  104. package/dist/scene/shared/components/gates/Nand4GateVisualFactory.d.ts +27 -0
  105. package/dist/scene/shared/components/gates/Nand8GateVisualFactory.d.ts +27 -0
  106. package/dist/scene/shared/components/gates/NandGateVisualFactory.d.ts +101 -0
  107. package/dist/scene/shared/components/gates/Nor4GateVisualFactory.d.ts +27 -0
  108. package/dist/scene/shared/components/gates/Nor8GateVisualFactory.d.ts +27 -0
  109. package/dist/scene/shared/components/gates/NorGateVisualFactory.d.ts +101 -0
  110. package/dist/scene/shared/components/gates/Xor4GateVisualFactory.d.ts +29 -0
  111. package/dist/scene/shared/components/gates/Xor8GateVisualFactory.d.ts +29 -0
  112. package/dist/scene/shared/components/gates/XorGateVisualFactory.d.ts +103 -0
  113. package/dist/scene/shared/components/index.d.ts +29 -0
  114. package/dist/scene/shared/components/types.d.ts +43 -0
  115. package/dist/scene/shared/types.d.ts +476 -0
  116. package/dist/scene/shared/utils/CameraUtils.d.ts +23 -0
  117. package/dist/scene/shared/utils/ColorUtils.d.ts +26 -0
  118. package/dist/scene/shared/utils/ControlsUtils.d.ts +8 -0
  119. package/dist/scene/shared/utils/GeometryUtils.d.ts +261 -0
  120. package/dist/scene/shared/utils/LayerConstants.d.ts +40 -0
  121. package/dist/scene/shared/utils/LightingUtils.d.ts +31 -0
  122. package/dist/scene/shared/utils/MaterialUtils.d.ts +73 -0
  123. package/dist/scene/shared/utils/Options.d.ts +16 -0
  124. package/dist/scene/simulation/CircuitRunnerController.d.ts +227 -0
  125. package/dist/scene/static/CircuitController.d.ts +227 -0
  126. package/dist/scene/static/CircuitWriter.d.ts +146 -0
  127. package/dist/scene/static/PinTooltipWidget.d.ts +26 -0
  128. package/dist/scene/static/tools/BuildTool.d.ts +286 -0
  129. package/dist/scene/static/tools/ComponentPickerWidget.d.ts +82 -0
  130. package/dist/scene/static/tools/ConfigPanelWidget.d.ts +93 -0
  131. package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
  132. package/dist/scene-CVsDdySt.js +7357 -0
  133. package/dist/scene-CVsDdySt.js.map +1 -0
  134. package/package.json +24 -25
  135. package/dist/CircuitRunner-DEb7JdNf.js +0 -1809
  136. package/dist/CircuitRunner-DEb7JdNf.js.map +0 -1
  137. package/dist/core/index.js.map +0 -1
  138. package/dist/index.js.map +0 -1
  139. package/dist/scene/index.js.map +0 -1
  140. package/dist/setup-AB1vFiis.js +0 -9918
  141. package/dist/setup-AB1vFiis.js.map +0 -1
@@ -0,0 +1,227 @@
1
+ import { Euler } from 'three';
2
+ import { Component, Wire, ENode, UUID, ComponentType, ENodeSourceType, Circuit } from '../../core/index.ts';
3
+ import { IFactoryRegistry } from '../shared/components/ComponentVisualFactory';
4
+ import { ToolType, SharedResources, ControllerOptions } from '../shared/types';
5
+ import { SelectionManager } from '../shared/SelectionManager';
6
+ import { CircuitWriter } from './CircuitWriter';
7
+ import { AbstractCircuitController } from '../shared/AbstractCircuitController';
8
+ /**
9
+ * Static Circuit Controller for editing circuits
10
+ * @module scene/static/CircuitController
11
+ *
12
+ * Manages static circuit THREE.js scene with support for editing tools.
13
+ */
14
+ import * as THREE from 'three';
15
+ /**
16
+ * Static Circuit Controller Implementation
17
+ *
18
+ * Manager providing a bidirectional interface between a Circuit and a Three.js scene/camera ready to be rendered.
19
+ * Supports view manipulation and editing via integrated tool system.
20
+ * Provides event hooks for error handling and state changes.
21
+ */
22
+ export declare class CircuitController extends AbstractCircuitController {
23
+ private _editMode;
24
+ readonly circuitWriter: CircuitWriter;
25
+ private _selectionManager;
26
+ private _configPanelManager;
27
+ private _pinTooltipWidget;
28
+ private _lastClientX;
29
+ private _lastClientY;
30
+ private _tooltipMouseMoveHandler;
31
+ private _tools;
32
+ private _activeTool;
33
+ /**
34
+ * Constructor and initialization
35
+ */
36
+ /**
37
+ * Create a new Static Circuit Controller
38
+ *
39
+ * @param factoryRegistry - Component visual factory registry
40
+ * @param sharedResources - Optional shared resources for facade pattern (CircuitEngine)
41
+ * @throws {TypeError} factoryRegistry is null/undefined
42
+ */
43
+ constructor(factoryRegistry: IFactoryRegistry, sharedResources?: SharedResources);
44
+ /**
45
+ * Specific Initialization logic, performed after AbstractCircuitController initialization
46
+ * @private
47
+ */
48
+ protected onInitialize(_options?: ControllerOptions): void;
49
+ protected emitReady(): void;
50
+ /**
51
+ * Enable or disable edit mode (FR-006, FR-027)
52
+ * When disabled, deactivates any active tool and resets tool state
53
+ *
54
+ * @param enabled - True to enable edit mode, false to disable
55
+ */
56
+ setEditMode(enabled: boolean): void;
57
+ /**
58
+ * specific disposal prepended at the beginning of dispose process
59
+ */
60
+ protected onDispose(): void;
61
+ onSetActive(active: boolean): void;
62
+ setCircuit(circuit: Circuit | null): void;
63
+ /**
64
+ * specific logic when to render a new set circuit
65
+ * @protected
66
+ */
67
+ protected onSetCircuit(): void;
68
+ /**
69
+ * Get the SelectionManager instance for direct manipulation
70
+ * @returns SelectionManager
71
+ */
72
+ getSelectionManager(): SelectionManager;
73
+ private handlePointerDown;
74
+ private _applySelectionVisual;
75
+ private _initializeSelectionManager;
76
+ /**
77
+ * Initialize ConfigPanelManager (T013)
78
+ * @private
79
+ */
80
+ private _initializeConfigPanelManager;
81
+ private _initializePinTooltip;
82
+ private _disposePinTooltip;
83
+ /**
84
+ * Open the config panel for a component (T014)
85
+ *
86
+ * @param componentId - UUID of the component to edit
87
+ * @param screenPosition - Screen coordinates for panel positioning
88
+ * @returns true if panel opened, false if component has no config
89
+ */
90
+ openConfigPanel(componentId: UUID, screenPosition: {
91
+ x: number;
92
+ y: number;
93
+ }): boolean;
94
+ /**
95
+ * Tool System Methods
96
+ */
97
+ /**
98
+ * Convenience method that toggle a tool on if it is off (possibly deactivating previous tool), or off if it is on
99
+ * @param toolType
100
+ */
101
+ toggleTool(toolType: ToolType): void;
102
+ deactivateTool(toolType: ToolType): void;
103
+ /**
104
+ * Get the currently active tool (FR-028)
105
+ *
106
+ * @returns Current tool type or null if no tool is active
107
+ */
108
+ getActiveTool(): ToolType | null;
109
+ /**
110
+ * Set the active editing tool (FR-026, FR-028, FR-034)
111
+ * Only one tool can be active at a time
112
+ * Switching tools will deactivate the previous tool
113
+ *
114
+ * @param toolType - Type of tool to activate
115
+ * @throws {Error} If edit mode is not enabled
116
+ */
117
+ setActiveTool(toolType: ToolType): void;
118
+ /**
119
+ * Initialize editing tools
120
+ * @private
121
+ */
122
+ private _initializeTools;
123
+ /**
124
+ * recreate all visuals based on circuit data
125
+ * Should be called on an already cleared scene
126
+ * @private
127
+ */
128
+ private _fullUpdate;
129
+ private _createComponentObject3D;
130
+ /**
131
+ * Index component mesh and its pins meshes for interaction (hover, selection)
132
+ * @param componentId
133
+ * @param object3D
134
+ * @private
135
+ */
136
+ private _indexComponentObject3D;
137
+ private _removeComponentObject3D;
138
+ /**
139
+ * Create enode (branching point ONLY) visual object and add to scene
140
+ * pin enodes are created and attache to their components by createComponentObject3D()
141
+ *
142
+ * @param enode
143
+ * @private
144
+ */
145
+ private _createEnodeObject3D;
146
+ private _removeEnodeObject3D;
147
+ addBranchingPoint(worldPosition: THREE.Vector3, sourceType?: ENodeSourceType | undefined): ENode;
148
+ /**
149
+ * Split wire either :
150
+ * - at a position, inserting a new branching point and two new wires replacing the deleted ones
151
+ * - at an existing target enode, replacing the wire by two new wires connected to this enode
152
+ * @param wireId
153
+ * @param worldPosition - world Position for the new branching point : no effect if targetEnodeId provided
154
+ * @param targetEnodeId - if provided, the existing enode to split the wire at
155
+ */
156
+ splitWire(wireId: UUID, worldPosition: THREE.Vector3, targetEnodeId?: UUID | null): {
157
+ branchingPoint: ENode;
158
+ wires: Wire[];
159
+ };
160
+ /**
161
+ * Remove branching point enode visual and update the circuit and visuals
162
+ * @param enodeId
163
+ */
164
+ removeBranchingPoint(enodeId: UUID): void;
165
+ private _createWireObject3D;
166
+ /**
167
+ * add a wire between two enodes : update the circuit and add visuals
168
+ * @param sourceEnodeId
169
+ * @param targetEnodeId
170
+ */
171
+ addWire(sourceEnodeId: UUID, targetEnodeId: UUID): Wire;
172
+ /**
173
+ * Add a component to the circuit and scene
174
+ *
175
+ * @param type - Component type to add
176
+ * @param worldPosition - Position in 3D world coordinates (x, z)
177
+ * @param rotation - 3D world rotation, if left null the default componentType rotation is applied
178
+ * @param config - Optional configuration map for the component
179
+ * @param pinSources - Optional array of source types for the component pins
180
+ * @returns The created Component
181
+ */
182
+ addComponent(type: ComponentType, worldPosition: THREE.Vector3, rotation: Euler | null, config?: Map<string, string> | undefined, pinSources?: Array<ENodeSourceType | undefined | null> | undefined): Component;
183
+ /**
184
+ * edit component config and update visuals if necessary
185
+ *
186
+ * @param componentId
187
+ * @param newConfig - map of parameters to be merged into the current config
188
+ */
189
+ editComponentConfig(componentId: UUID, newConfig: Map<string, string>): void;
190
+ /**
191
+ * cycle component config and update visuals if necessary
192
+ * have effect only on components that supports fast config cycle (used to invert logic or initial state of switches)
193
+ * else use editComponentConfig
194
+ *
195
+ * @returns if the component has changed config
196
+ * @param componentId
197
+ */
198
+ cycleComponentConfig(componentId: UUID): boolean;
199
+ /**
200
+ * Remove a component from the circuit and scene
201
+ *
202
+ * @param componentId - UUID of the component to remove
203
+ */
204
+ removeComponent(componentId: UUID): void;
205
+ /**
206
+ * Update an enode based to a new source type.
207
+ * @param enodeId - UUID of the enode
208
+ * @param sourceType - New source type (null for no source)
209
+ */
210
+ updateEnodeSourceType(enodeId: UUID, sourceType: ENodeSourceType | null): void;
211
+ /**
212
+ * Remove wire visual and update the circuit
213
+ * @param wireId
214
+ */
215
+ removeWire(wireId: UUID): void;
216
+ /**
217
+ * Automatically adjust the circuit grid size and divisions based on positions of all core circuit elements.
218
+ */
219
+ autoAdjustCircuitGridSize(): void;
220
+ /**
221
+ * Hook called before exporting the circuit visualization.
222
+ * Saves world informations such as camera position, in the circuit metadata.
223
+ */
224
+ beforeExport(): void;
225
+ private _removeWireObject3D;
226
+ protected _removeAllVisuals(): void;
227
+ }
@@ -0,0 +1,146 @@
1
+ import { Euler, Object3D, Vector3 } from 'three';
2
+ import { ENodeSourceType, UUID, ENode, Wire, Component, ComponentType } from '../../core/index.ts';
3
+ import { CircuitController } from './CircuitController';
4
+ /**
5
+ * Manages editing operations of 3D models from the circuit scene into the core circuit model.
6
+ */
7
+ export declare class CircuitWriter {
8
+ private _controller;
9
+ constructor(controller: CircuitController);
10
+ /**
11
+ * add branching point to the core circuit model and emits the appropriate event.
12
+ * @param position - the world position to add the branching point at
13
+ * @param sourceType - optional source type for the branching point
14
+ * @throws Error
15
+ * @return The circuit enode
16
+ */
17
+ saveAddBranchingPoint(position: Vector3, sourceType?: ENodeSourceType | undefined): ENode;
18
+ /**
19
+ * edit branching point to the core circuit model and emits the appropriate event.
20
+ * @param branchingPoint - the branching point Object3D
21
+ * @param emit - should the event be emitted if commit OK (error event will always be)
22
+ * @throws Error
23
+ * @return The circuit enode
24
+ */
25
+ saveEditBranchingPoint(branchingPoint: Object3D, emit?: boolean): ENode;
26
+ /**
27
+ * delete branching point in the core circuit model and emits the appropriate event.
28
+ * @param enodeId - the branching point id
29
+ * @throws Error
30
+ * @return The circuit enode
31
+ */
32
+ saveDeleteBranchingPoint(enodeId: UUID): {
33
+ deletedWires?: UUID[] | undefined;
34
+ mergedWires?: UUID[] | undefined;
35
+ newWire?: Wire | undefined;
36
+ };
37
+ /**
38
+ * add wire to the core circuit model and emits the appropriate event.
39
+ * @param sourceEnodeId - the source enode ID
40
+ * @param targetEnodeId - the target enode ID
41
+ * @throws Error
42
+ * @return The circuit wire
43
+ */
44
+ saveAddWire(sourceEnodeId: UUID, targetEnodeId: UUID): Wire;
45
+ /**
46
+ * Save wire split operation to circuit model. Either :
47
+ * - at a position, inserting a new branching point and two new wires replacing the deleted ones
48
+ * - at an existing target enode, replacing the wire by two new wires connected to this enode
49
+ * @param wireId - Wire to split
50
+ * @param worldPosition - world Position for the new branching point : no effect if targetEnodeId provided
51
+ * @param targetEnodeId - if provided, the existing enode to split the wire at
52
+ * @returns Object containing the new branching point and two wires
53
+ */
54
+ saveSplitWire(wireId: UUID, worldPosition: Vector3, targetEnodeId?: UUID | null): {
55
+ branchingPoint: ENode;
56
+ wires: Wire[];
57
+ };
58
+ /**
59
+ * delete wire to the core circuit model and emits the appropriate event.
60
+ * @param wireId - the wire ID
61
+ * @throws Error
62
+ * @return The circuit wire
63
+ */
64
+ saveDeleteWire(wireId: UUID): void;
65
+ /**
66
+ * Used to commit wire edits (intermediate positions) to the core circuit model and emits the appropriate event.
67
+ * If emit positions are also simplified before committing.
68
+ * @param wireId - the wire ID
69
+ * @param positions
70
+ * @param emit
71
+ * @return The circuit wire
72
+ */
73
+ saveEditWirePositions(wireId: UUID, positions: Array<{
74
+ x: number;
75
+ y: number;
76
+ }>, emit?: boolean): Wire | undefined;
77
+ /**
78
+ * Used to simplify wire path in the core circuit model and emits the appropriate event.
79
+ * Notably used when end enodes move is committed.
80
+ * @param wireId - the wire ID
81
+ * @return The circuit wire
82
+ */
83
+ saveSimplifyWirePositions(wireId: UUID): Wire | undefined;
84
+ /**
85
+ * Save ENode sourceType update (T011)
86
+ * @param enodeId - ENode to update
87
+ * @param sourceType - New sourceType value
88
+ */
89
+ saveEditENodeSourceType(enodeId: UUID, sourceType: ENodeSourceType | null): void;
90
+ /**
91
+ * Add a component to the circuit model and emit the appropriate event
92
+ * handles conversion of world position and rotation to circuit model values
93
+ * @param type - Component type to add
94
+ * @param position - world Position
95
+ * @param rotation - world Rotation
96
+ * @param config - optional initial component configuration
97
+ * @param pinSources - optional array of ENode source types for each component pin
98
+ * @returns The created Component
99
+ * @throws Error if circuit is not available or component creation fails
100
+ */
101
+ saveAddComponent(type: ComponentType, position: Vector3, rotation: Euler, config?: Map<string, string> | undefined, pinSources?: Array<ENodeSourceType | undefined | null> | undefined): Component;
102
+ /**
103
+ * Save edits made to a component in the circuit model and emit the appropriate event
104
+ * @param componentId
105
+ * @param visual
106
+ * @param emit - should the event be emitted if commit OK (error event will always be)
107
+ */
108
+ saveEditComponent(componentId: UUID, visual: Object3D, emit?: boolean): Component;
109
+ /**
110
+ * Save edits made to a component configuration in the circuit model and emit the appropriate event
111
+ * @param componentId
112
+ * @param parameters - updated configuration parameters
113
+ */
114
+ saveEditComponentConfig(componentId: UUID, parameters: Map<string, string>): Component;
115
+ /**
116
+ * cycle component config and update visuals if necessary
117
+ * have effect only on components that supports fast config cycle (used to invert logic or initial state of switches)
118
+ * if component supports it, update the supported config item to the next value in the cycle
119
+ * @param componentId
120
+ * @returns object with hasChanged boolean and updated component
121
+ * @throws Error if circuit is not available or component not found
122
+ */
123
+ cycleComponentConfig(componentId: UUID): {
124
+ hasChanged: boolean;
125
+ component: Component;
126
+ };
127
+ /**
128
+ * Delete a component from the circuit model and emit the appropriate event
129
+ * @param componentId - UUID of the component to delete
130
+ * @returns Information about removed wires and enodes
131
+ * @throws Error if circuit is not available or component not found
132
+ */
133
+ saveDeleteComponent(componentId: UUID): {
134
+ deletedWires: UUID[];
135
+ deletedENodes: UUID[];
136
+ };
137
+ /**
138
+ * Automatically adjust the circuit size and divisions based on positions of all core circuit elements.
139
+ * @return if the size/division has been updated or not
140
+ */
141
+ saveAutoAdjustCircuitSize(): boolean;
142
+ /**
143
+ * Save current camera parameters, position and target into circuit metadata
144
+ */
145
+ saveCameraOptions(): void;
146
+ }
@@ -0,0 +1,26 @@
1
+ import { ComponentType } from '../../core/index.ts';
2
+ /**
3
+ * Manages a transient HTML tooltip displayed when hovering a component pin.
4
+ *
5
+ * Lifecycle: created by CircuitController on init, disposed on deactivation/disposal.
6
+ * Positioning: fixed, follows the raw client mouse coordinates.
7
+ */
8
+ export declare class PinTooltipWidget {
9
+ private _element;
10
+ private _currentComponentType;
11
+ private _clickHandler;
12
+ private readonly _onHelpRequested;
13
+ constructor(onHelpRequested: (componentType: ComponentType) => void);
14
+ /**
15
+ * Show tooltip at the given client coordinates for the specified pin.
16
+ * If already showing for the same component type, only repositions.
17
+ */
18
+ show(pinLabel: string, componentType: ComponentType, clientX: number, clientY: number): void;
19
+ /** Hide and remove the tooltip element */
20
+ hide(): void;
21
+ /** Update cursor position without recreating the tooltip */
22
+ updatePosition(clientX: number, clientY: number): void;
23
+ get isVisible(): boolean;
24
+ dispose(): void;
25
+ private _position;
26
+ }
@@ -0,0 +1,286 @@
1
+ import { IEditingTool, ToolType, CursorType } from '../../shared/types';
2
+ import { CircuitController } from '../CircuitController';
3
+ /**
4
+ * Build Tool Implementation
5
+ * @module scene/static/tools/BuildTool
6
+ *
7
+ * Unified tool for all circuit editing operations:
8
+ * - Wire creation between endpoints
9
+ * - Element positioning (components, branching points, wire points)
10
+ * - Component rotation
11
+ * - Element deletion
12
+ * - Branching point creation
13
+ * - Component placement & addition (add_component mode with picker widget)
14
+ *
15
+ * Replaces old: PositionTool, WireTool, DeleteTool, BranchingPointTool, AddComponentTool
16
+ */
17
+ import * as THREE from 'three';
18
+ /**
19
+ * Unified tool for building circuits
20
+ * Implements all circuit editing functionality in a single tool
21
+ */
22
+ export declare class BuildTool implements IEditingTool {
23
+ readonly type: ToolType;
24
+ private _controller;
25
+ private mode;
26
+ private lastCancelledOp;
27
+ private lastOperationCompletedTs;
28
+ private wireCreationState;
29
+ private wireDragState;
30
+ private componentDragState;
31
+ private bpDragState;
32
+ private clipboard;
33
+ private pickerWidget;
34
+ private ghostPreview;
35
+ private hasOverlap;
36
+ private pickerSelection;
37
+ /**
38
+ * Construct a new BuildTool instance
39
+ * @param controller - The circuit scene controllerType instance
40
+ */
41
+ constructor(controller: CircuitController);
42
+ /**
43
+ * Activate build tool and set up event listeners
44
+ * Resets all tool state and attaches DOM event handlers
45
+ */
46
+ onActivate(): void;
47
+ /**
48
+ * Deactivate build tool and clean up event listeners
49
+ * Cancels any active operations and removes all event handlers
50
+ */
51
+ onDeactivate(): void;
52
+ /**
53
+ * Cancel current ongoing operation : can be called from outside if needed
54
+ */
55
+ cancelOperation(): void;
56
+ /**
57
+ * Get the current cursor type for this tool
58
+ * Returns cursor based on current mode and hover state
59
+ */
60
+ getCursorType(): CursorType;
61
+ /**
62
+ * Get preview objects to render in the scene
63
+ * Returns array of preview objects currently visible
64
+ */
65
+ getPreviewObjects(): THREE.Object3D[];
66
+ /**
67
+ * Handle pointer down event
68
+ * Routes to appropriate operation based on hover target and state
69
+ */
70
+ private handlePointerDown;
71
+ /**
72
+ * Handle pointer up event
73
+ *
74
+ * Ends current operation, commits final positions to the circuit model,
75
+ * and re-enables camera controls.
76
+ *
77
+ * Completes current operation based on mode
78
+ */
79
+ private handlePointerUp;
80
+ /**
81
+ * Handle grid position move event according to ongoing mode
82
+ * Updates preview or drag position during active operations
83
+ */
84
+ private handleGridPositionMove;
85
+ /**
86
+ * Handle keyboard events
87
+ * Supports Escape (cancel), Delete/Backspace (delete), R (rotate), Ctrl+C (copy), Ctrl+V (paste)
88
+ */
89
+ private handleKeyDown;
90
+ /**
91
+ * Handle double-click events
92
+ * Routes to rotation (component) or branching point creation (wire/empty)
93
+ */
94
+ private handleDblClick;
95
+ /**
96
+ * Operations lifecycle methods
97
+ * (start, update, cancel, complete)
98
+ */
99
+ /**
100
+ * Start wire creation from source enode
101
+ * @param sourceEnodeId - Source enode ID
102
+ */
103
+ private startWireCreation;
104
+ /**
105
+ * Update wire creation preview with new target position
106
+ * @param position
107
+ * @private
108
+ */
109
+ private updateWireCreation;
110
+ /**
111
+ * Cancel wire creation and reset state
112
+ */
113
+ private cancelWireCreation;
114
+ /**
115
+ * Complete wire creation between source enode and :
116
+ * - existing target enode if it is hovered
117
+ * - new branching point on wire if target is a wire
118
+ * - new branching point if target is null
119
+ * @param hoveredElement - Currently hovered element at wire creation end
120
+ */
121
+ private completeWireCreation;
122
+ /**
123
+ * Start wire dragging operation
124
+ * @param wireId - Wire being dragged
125
+ * @param targetType - Type of drag target
126
+ * @param pointIndex - Index of intermediate point, or -1 for new/branching
127
+ * @param worldPosition - Initial position
128
+ */
129
+ private startWireDrag;
130
+ /**
131
+ * Update drag target position during drag
132
+ * @param worldPosition - Current cursor position in world space
133
+ */
134
+ private updateWireDrag;
135
+ /**
136
+ * Cancel wire drag operation and revert to original positions
137
+ */
138
+ private cancelWireDrag;
139
+ /**
140
+ * Commit drag operation and persist changes
141
+ */
142
+ private completeWireDrag;
143
+ /**
144
+ * Start component dragging operation
145
+ * @param componentId - UUID of the component being dragged
146
+ * @param worldPosition - Initial position
147
+ */
148
+ private startComponentDrag;
149
+ /**
150
+ * Update component visual position during drag
151
+ * @param worldPosition - Current cursor position in world space
152
+ */
153
+ private updateComponentDrag;
154
+ /**
155
+ * Cancel component drag operation and revert to original positions
156
+ */
157
+ private cancelComponentDrag;
158
+ /**
159
+ * complete component drag operation and persist changes
160
+ */
161
+ private completeComponentDrag;
162
+ /**
163
+ * Start branching point dragging operation
164
+ * @param enodeId - UUID of the branching point being dragged
165
+ * @param worldPosition - Initial position
166
+ */
167
+ private startBPDrag;
168
+ /**
169
+ * Update branching point position during drag
170
+ * @param worldPosition - Current cursor position in world space
171
+ */
172
+ private updateBPDrag;
173
+ /**
174
+ * Cancel branching point drag operation and revert to original positions
175
+ */
176
+ private cancelBPDrag;
177
+ /**
178
+ * Commit branching point drag operation and persist changes
179
+ */
180
+ private completeBPDrag;
181
+ /**
182
+ * private helpers
183
+ */
184
+ /**
185
+ * Create a standalone branching point at empty grid position (T048)
186
+ * @param worldPosition - 3D position in world space
187
+ */
188
+ private createStandaloneBranchingPoint;
189
+ /**
190
+ * Create a branching point on an existing wire, splitting it (T044)
191
+ * @param wireId - Wire to split
192
+ * @param worldPosition - 3D position in world space
193
+ */
194
+ private createBranchingPointOnWire;
195
+ /**
196
+ * Check if hoveredElement is a valid wire target during wire creation
197
+ * @param hoveredElement - Current hovered element or null
198
+ * @returns True if target is valid for wire endpoint
199
+ */
200
+ private isValidWireTarget;
201
+ /**
202
+ * Rotate a component 90° clockwise
203
+ *
204
+ * Updates both the circuit model and visual representation.
205
+ * Emits componentRotated event to notify listeners.
206
+ * Only works on selected components (not wires or enodes).
207
+ */
208
+ private rotateComponent;
209
+ /**
210
+ * Check if wire intermediate point should be merged or deleted
211
+ * Returns updated positions array after merge/delete check
212
+ * @param wire - Wire being modified
213
+ * @returns Final intermediate positions array
214
+ */
215
+ private checkMergeDelete;
216
+ /**
217
+ * Copy component type and rotation to clipboard
218
+ * @param componentId - UUID of the component to copy
219
+ */
220
+ private copyComponent;
221
+ /**
222
+ * Paste component from clipboard at hovered position
223
+ * Creates a new component with the type and rotation from clipboard
224
+ */
225
+ private pasteComponent;
226
+ /**
227
+ * Cycles the sourceType of an enode: null → Voltage → Current → null
228
+ * Updates both model and visual immediately.
229
+ * @param enodeId - UUID of the enode to cycle
230
+ * @param hitbox - hitbox of the enode being clicked
231
+ */
232
+ private cycleEnodeSourceType;
233
+ /**
234
+ * Open config panel for component (T014)
235
+ * Converts component world position to screen coordinates and opens panel
236
+ * @param componentId - UUID of the component to configure
237
+ * @param event - Mouse event for screen position
238
+ */
239
+ private openConfigPanel;
240
+ /**
241
+ * Enter add_component mode: open the picker widget and listen for cursor movement
242
+ * @param event - Mouse event (used for widget positioning)
243
+ */
244
+ private enterAddComponentMode;
245
+ /**
246
+ * Exit add_component mode: close widget, dispose ghost, return to idle
247
+ */
248
+ private exitAddComponentMode;
249
+ /**
250
+ * Called when user selects or deselects an item in the picker widget
251
+ */
252
+ private onPickerSelectionChange;
253
+ /**
254
+ * Place the currently selected item (component or branching point) at cursor position
255
+ */
256
+ private placeSelectedItem;
257
+ /**
258
+ * Update ghost preview position and overlap check during add_component mode
259
+ */
260
+ private updateAddComponentPreview;
261
+ /**
262
+ * Create ghost preview for the selected item
263
+ * @param selection - Component type or branching point sentinel
264
+ */
265
+ private createGhostPreview;
266
+ /**
267
+ * Dispose ghost preview and cleanup resources
268
+ */
269
+ private disposeGhostPreview;
270
+ /**
271
+ * Apply semi-transparent ghost effect to preview object
272
+ */
273
+ private applyGhostEffect;
274
+ /**
275
+ * Check if ghost preview overlaps with existing components
276
+ */
277
+ private checkGhostOverlap;
278
+ /**
279
+ * Apply red emissive to indicate invalid placement
280
+ */
281
+ private applyInvalidEffect;
282
+ /**
283
+ * Remove red emissive invalid placement effect
284
+ */
285
+ private removeInvalidEffect;
286
+ }