simple-circuit-engine 0.0.11 → 0.0.13
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 +11 -7
- package/CLAUDE.md +6 -6
- package/README.md +5 -2
- package/dist/core/index.d.ts +0 -1
- package/dist/core/index.js +85 -2115
- package/dist/core/setup.d.ts +25 -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/arithmetic/AdderBehavior.d.ts +28 -0
- package/dist/core/simulation/behaviors/arithmetic/ArithmeticBehaviorMixin.d.ts +63 -0
- package/dist/core/simulation/behaviors/arithmetic/EightBitAdderBehavior.d.ts +51 -0
- package/dist/core/simulation/behaviors/arithmetic/EightBitOnesComplementBehavior.d.ts +29 -0
- package/dist/core/simulation/behaviors/arithmetic/HalfAdderBehavior.d.ts +22 -0
- package/dist/core/simulation/behaviors/arithmetic/index.d.ts +7 -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 +28 -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/arithmetic/AdderState.d.ts +16 -0
- package/dist/core/simulation/states/arithmetic/ArithmeticState.d.ts +53 -0
- package/dist/core/simulation/states/arithmetic/EightBitAdderState.d.ts +25 -0
- package/dist/core/simulation/states/arithmetic/EightBitOnesComplementState.d.ts +18 -0
- package/dist/core/simulation/states/arithmetic/HalfAdderState.d.ts +16 -0
- package/dist/core/simulation/states/arithmetic/index.d.ts +7 -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 +31 -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 +153 -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 +189 -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-b6Q8w2sn.js +3560 -0
- package/dist/core-b6Q8w2sn.js.map +1 -0
- package/dist/i18n/index.d.ts +882 -0
- package/dist/i18n/locales/en.json.d.ts +268 -0
- package/dist/i18n/locales/fr.json.d.ts +268 -0
- package/dist/index.d.ts +14 -6306
- package/dist/index.js +136 -112
- package/dist/scene/CircuitEngine.d.ts +283 -0
- package/dist/scene/index.d.ts +1 -2
- package/dist/scene/index.js +50 -41
- package/dist/scene/setup.d.ts +26 -0
- package/dist/scene/shared/AbstractCircuitController.d.ts +217 -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/arithmetic/AdderVisualFactory.d.ts +54 -0
- package/dist/scene/shared/components/arithmetic/EightBitAdderVisualFactory.d.ts +45 -0
- package/dist/scene/shared/components/arithmetic/EightBitOnesComplementVisualFactory.d.ts +63 -0
- package/dist/scene/shared/components/arithmetic/HalfAdderVisualFactory.d.ts +55 -0
- package/dist/scene/shared/components/arithmetic/index.d.ts +4 -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 +33 -0
- package/dist/scene/shared/components/types.d.ts +43 -0
- package/dist/scene/shared/types.d.ts +474 -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 +337 -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 +228 -0
- package/dist/scene/static/CircuitWriter.d.ts +146 -0
- package/dist/scene/static/PinTooltipWidget.d.ts +31 -0
- package/dist/scene/static/tools/BuildTool.d.ts +290 -0
- package/dist/scene/static/tools/ComponentPickerWidget.d.ts +89 -0
- package/dist/scene/static/tools/ConfigPanelWidget.d.ts +107 -0
- package/dist/scene/static/tools/MultiSelectTool.d.ts +265 -0
- package/dist/scene-D4QcWeiq.js +8745 -0
- package/dist/scene-D4QcWeiq.js.map +1 -0
- package/package.json +29 -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,227 @@
|
|
|
1
|
+
import { Circuit, BehaviorRegistry } from '../../core/index.ts';
|
|
2
|
+
import { IFactoryRegistry } from '../shared/components/ComponentVisualFactory';
|
|
3
|
+
import { SharedResources, ControllerOptions } from '../shared/types';
|
|
4
|
+
import { AbstractCircuitController } from '../shared/AbstractCircuitController';
|
|
5
|
+
/**
|
|
6
|
+
* Simulation Circuit Runner Controller Implementation
|
|
7
|
+
*
|
|
8
|
+
* Manages Three.js scene for live circuit simulation visualization.
|
|
9
|
+
* Provides smooth interpolation between simulation ticks for 60fps rendering.
|
|
10
|
+
* Animates current flow through wires and component state changes.
|
|
11
|
+
*/
|
|
12
|
+
export declare class CircuitRunnerController extends AbstractCircuitController {
|
|
13
|
+
private _runner;
|
|
14
|
+
private _behaviorRegistry;
|
|
15
|
+
private _animationContext;
|
|
16
|
+
private _autoPlay;
|
|
17
|
+
private _isPlaying;
|
|
18
|
+
private _tickIntervalMs;
|
|
19
|
+
private _simulationLoopId;
|
|
20
|
+
private _clickHandler;
|
|
21
|
+
/**
|
|
22
|
+
* Create a new Simulation Circuit Controller
|
|
23
|
+
*
|
|
24
|
+
* @param factoryRegistry - Component visual factory registry
|
|
25
|
+
* @param behaviorRegistry - Component behavior registry
|
|
26
|
+
* @param sharedResources - Optional shared resources for facade pattern (CircuitEngine)
|
|
27
|
+
* @throws {TypeError} If factoryRegistry is null/undefined
|
|
28
|
+
*/
|
|
29
|
+
constructor(factoryRegistry: IFactoryRegistry, behaviorRegistry: BehaviorRegistry, sharedResources?: SharedResources);
|
|
30
|
+
/**
|
|
31
|
+
* Check if simulation is currently playing (auto-advancing ticks)
|
|
32
|
+
* Returns false if paused or no circuit loaded
|
|
33
|
+
*/
|
|
34
|
+
get isPlaying(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Get current tick interval in milliseconds
|
|
37
|
+
* Default is 500ms (2 ticks per second)
|
|
38
|
+
*/
|
|
39
|
+
get tickInterval(): number;
|
|
40
|
+
/**
|
|
41
|
+
* Set tick interval in milliseconds (50-2000ms)
|
|
42
|
+
* If simulation is playing, restarts the interval with new value
|
|
43
|
+
*
|
|
44
|
+
* @param value - Interval in milliseconds, must be between 50-2000ms
|
|
45
|
+
* @throws {RangeError} If value is outside valid range
|
|
46
|
+
*/
|
|
47
|
+
set tickInterval(value: number);
|
|
48
|
+
/**
|
|
49
|
+
* Get current simulation speed in ticks per second.
|
|
50
|
+
* Range: 1-20 TPS
|
|
51
|
+
*/
|
|
52
|
+
get simulationSpeed(): number;
|
|
53
|
+
/**
|
|
54
|
+
* Set simulation speed in ticks per second.
|
|
55
|
+
* Value is clamped to range 1-20 TPS.
|
|
56
|
+
* If simulation is playing, restarts the interval with new value.
|
|
57
|
+
* Emits 'simulationSpeedChanged' event when speed changes.
|
|
58
|
+
*
|
|
59
|
+
* @param tps - Ticks per second (1-20)
|
|
60
|
+
*/
|
|
61
|
+
set simulationSpeed(tps: number);
|
|
62
|
+
/**
|
|
63
|
+
* Minimum allowed simulation speed in ticks per second.
|
|
64
|
+
*/
|
|
65
|
+
get minSimulationSpeed(): number;
|
|
66
|
+
/**
|
|
67
|
+
* Maximum allowed simulation speed in ticks per second.
|
|
68
|
+
*/
|
|
69
|
+
get maxSimulationSpeed(): number;
|
|
70
|
+
/**
|
|
71
|
+
* Compute the number of ticks required for a transition given its duration in milliseconds.
|
|
72
|
+
* Formula: ceil(transitionUserSpanMs × simulationSpeed / 1000), minimum 1.
|
|
73
|
+
*
|
|
74
|
+
* @param transitionUserSpanMs - Transition duration in milliseconds
|
|
75
|
+
* @returns Number of ticks for the transition (minimum 1)
|
|
76
|
+
*/
|
|
77
|
+
computeTickCount(transitionUserSpanMs: number): number;
|
|
78
|
+
/**
|
|
79
|
+
* Get the transition duration from component config for user-driven transitions.
|
|
80
|
+
* @param config - Component config map
|
|
81
|
+
* @returns Transition duration in milliseconds (defaults to TRANSITION_USER_SPAN_MS)
|
|
82
|
+
*/
|
|
83
|
+
private _getTransitionUserSpan;
|
|
84
|
+
/**
|
|
85
|
+
* Get current simulation tick number
|
|
86
|
+
* Returns 0 if no circuit runner is loaded
|
|
87
|
+
*/
|
|
88
|
+
get currentTick(): number;
|
|
89
|
+
/**
|
|
90
|
+
* Specific Initialization logic, performed after AbstractCircuitController initialization
|
|
91
|
+
* @private
|
|
92
|
+
*
|
|
93
|
+
* @param options - Controller options passed to initialize()
|
|
94
|
+
*/
|
|
95
|
+
protected onInitialize(options?: ControllerOptions): void;
|
|
96
|
+
protected emitReady(): void;
|
|
97
|
+
/**
|
|
98
|
+
* specific disposal prepended at the beginning of dispose process
|
|
99
|
+
*/
|
|
100
|
+
protected onDispose(): void;
|
|
101
|
+
onSetActive(active: boolean): void;
|
|
102
|
+
setCircuit(circuit: Circuit | null): void;
|
|
103
|
+
/**
|
|
104
|
+
* specific logic when to render a new set circuit
|
|
105
|
+
* @protected
|
|
106
|
+
*/
|
|
107
|
+
protected onSetCircuit(): void;
|
|
108
|
+
/**
|
|
109
|
+
* Play automatic simulation playback
|
|
110
|
+
* Simulation will advance at the configured tick interval until paused
|
|
111
|
+
*
|
|
112
|
+
* Requires a circuit runner to be loaded via setCircuitRunner()
|
|
113
|
+
* Emits 'simulationPlayed' event on play
|
|
114
|
+
* Emits 'simulationTick' event on each tick
|
|
115
|
+
*/
|
|
116
|
+
play(): void;
|
|
117
|
+
/**
|
|
118
|
+
* Pause automatic simulation playback
|
|
119
|
+
* Safe to call even if already paused or no circuit loaded
|
|
120
|
+
*
|
|
121
|
+
* Emits 'simulationPaused' event
|
|
122
|
+
*/
|
|
123
|
+
pause(): void;
|
|
124
|
+
/**
|
|
125
|
+
* Execute a single simulation tick
|
|
126
|
+
* Simulation remains paused after step, useful for debugging
|
|
127
|
+
*
|
|
128
|
+
* If currently playing, pauses first then steps
|
|
129
|
+
* Requires a circuit runner to be loaded via setCircuitRunner()
|
|
130
|
+
* Emits 'simulationStepped' event with tick result
|
|
131
|
+
*/
|
|
132
|
+
step(): void;
|
|
133
|
+
/**
|
|
134
|
+
* Stop the simulation, reset visual to initial state
|
|
135
|
+
* Simulation remains paused after step, useful for debugging
|
|
136
|
+
*
|
|
137
|
+
* If currently playing, pauses first then steps
|
|
138
|
+
* Requires a circuit runner to be loaded via setCircuitRunner()
|
|
139
|
+
* Emits 'simulationStopped' event with tick result (0)
|
|
140
|
+
*/
|
|
141
|
+
stop(): void;
|
|
142
|
+
/**
|
|
143
|
+
* Execute one simulation tick and update visuals
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
private _executeTick;
|
|
147
|
+
/**
|
|
148
|
+
* Update component animations for dirty components
|
|
149
|
+
* @private
|
|
150
|
+
*/
|
|
151
|
+
private _updateDirtyComponents;
|
|
152
|
+
/**
|
|
153
|
+
* Update all active AnimationMixers.
|
|
154
|
+
* Called per frame from the render loop via CircuitEngine.update(delta).
|
|
155
|
+
*
|
|
156
|
+
* @param delta - Time in seconds since last frame
|
|
157
|
+
*/
|
|
158
|
+
updateAnimations(delta: number): void;
|
|
159
|
+
/**
|
|
160
|
+
* Recompute animation timescales when simulation speed changes mid-animation.
|
|
161
|
+
* Updates ticksPerSecond on userData and adjusts active action timeScales.
|
|
162
|
+
*/
|
|
163
|
+
private _updateAnimationTimescales;
|
|
164
|
+
/**
|
|
165
|
+
* Update wire visual state based on electrical state
|
|
166
|
+
* @private
|
|
167
|
+
*/
|
|
168
|
+
private _updateDirtyWires;
|
|
169
|
+
/**
|
|
170
|
+
* Update enode visual state based on electrical state
|
|
171
|
+
* Applies emissive glow to pins and branching points
|
|
172
|
+
* @private
|
|
173
|
+
*/
|
|
174
|
+
private _updateDirtyEnodes;
|
|
175
|
+
/**
|
|
176
|
+
* rollback wires/enodes/components visuals to edition state (no simulation state)
|
|
177
|
+
*/
|
|
178
|
+
_removeSimulationStateVisuals(): void;
|
|
179
|
+
/**
|
|
180
|
+
* Handle click events for component interaction
|
|
181
|
+
* @param event
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
private _handleClick;
|
|
185
|
+
/**
|
|
186
|
+
* Handle regular click events : emit user commands to the runner
|
|
187
|
+
* @param clickedElement
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
private _handleRegularClick;
|
|
191
|
+
private _handleCtrlClick;
|
|
192
|
+
/**
|
|
193
|
+
* recreate all visuals based on circuit data
|
|
194
|
+
* Should be called on an already cleared scene
|
|
195
|
+
*
|
|
196
|
+
* When using shared resources (CircuitEngine facade), skips visual creation
|
|
197
|
+
* if visuals already exist in the shared maps (created by edit controller).
|
|
198
|
+
* @private
|
|
199
|
+
*/
|
|
200
|
+
private _fullUpdate;
|
|
201
|
+
/**
|
|
202
|
+
* Consider all elements as dirty to update all visual state according to simulation state
|
|
203
|
+
* @private
|
|
204
|
+
*/
|
|
205
|
+
private _visualUpdateFromSimulationState;
|
|
206
|
+
private _createComponentObject3D;
|
|
207
|
+
/**
|
|
208
|
+
* Index component mesh and its pins meshes for interaction (hover, selection)
|
|
209
|
+
* @param componentId
|
|
210
|
+
* @param object3D
|
|
211
|
+
* @private
|
|
212
|
+
*/
|
|
213
|
+
private _indexComponentObject3D;
|
|
214
|
+
/**
|
|
215
|
+
* Create enode (branching point ONLY) visual object and add to scene
|
|
216
|
+
* pin enodes are created and attache to their components by createComponentObject3D()
|
|
217
|
+
*
|
|
218
|
+
* @param enode
|
|
219
|
+
* @private
|
|
220
|
+
*/
|
|
221
|
+
private _createEnodeObject3D;
|
|
222
|
+
private _createWireObject3D;
|
|
223
|
+
private _removeComponentObject3D;
|
|
224
|
+
private _removeEnodeObject3D;
|
|
225
|
+
private _removeWireObject3D;
|
|
226
|
+
protected _removeAllVisuals(): void;
|
|
227
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
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
|
+
setLanguage(lng: string): void;
|
|
45
|
+
/**
|
|
46
|
+
* Specific Initialization logic, performed after AbstractCircuitController initialization
|
|
47
|
+
* @private
|
|
48
|
+
*/
|
|
49
|
+
protected onInitialize(_options?: ControllerOptions): void;
|
|
50
|
+
protected emitReady(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Enable or disable edit mode (FR-006, FR-027)
|
|
53
|
+
* When disabled, deactivates any active tool and resets tool state
|
|
54
|
+
*
|
|
55
|
+
* @param enabled - True to enable edit mode, false to disable
|
|
56
|
+
*/
|
|
57
|
+
setEditMode(enabled: boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* specific disposal prepended at the beginning of dispose process
|
|
60
|
+
*/
|
|
61
|
+
protected onDispose(): void;
|
|
62
|
+
onSetActive(active: boolean): void;
|
|
63
|
+
setCircuit(circuit: Circuit | null): void;
|
|
64
|
+
/**
|
|
65
|
+
* specific logic when to render a new set circuit
|
|
66
|
+
* @protected
|
|
67
|
+
*/
|
|
68
|
+
protected onSetCircuit(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Get the SelectionManager instance for direct manipulation
|
|
71
|
+
* @returns SelectionManager
|
|
72
|
+
*/
|
|
73
|
+
getSelectionManager(): SelectionManager;
|
|
74
|
+
private handlePointerDown;
|
|
75
|
+
private _applySelectionVisual;
|
|
76
|
+
private _initializeSelectionManager;
|
|
77
|
+
/**
|
|
78
|
+
* Initialize ConfigPanelManager (T013)
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
private _initializeConfigPanelManager;
|
|
82
|
+
private _initializePinTooltip;
|
|
83
|
+
private _disposePinTooltip;
|
|
84
|
+
/**
|
|
85
|
+
* Open the config panel for a component (T014)
|
|
86
|
+
*
|
|
87
|
+
* @param componentId - UUID of the component to edit
|
|
88
|
+
* @param screenPosition - Screen coordinates for panel positioning
|
|
89
|
+
* @returns true if panel opened, false if component has no config
|
|
90
|
+
*/
|
|
91
|
+
openConfigPanel(componentId: UUID, screenPosition: {
|
|
92
|
+
x: number;
|
|
93
|
+
y: number;
|
|
94
|
+
}): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Tool System Methods
|
|
97
|
+
*/
|
|
98
|
+
/**
|
|
99
|
+
* Convenience method that toggle a tool on if it is off (possibly deactivating previous tool), or off if it is on
|
|
100
|
+
* @param toolType
|
|
101
|
+
*/
|
|
102
|
+
toggleTool(toolType: ToolType): void;
|
|
103
|
+
deactivateTool(toolType: ToolType): void;
|
|
104
|
+
/**
|
|
105
|
+
* Get the currently active tool (FR-028)
|
|
106
|
+
*
|
|
107
|
+
* @returns Current tool type or null if no tool is active
|
|
108
|
+
*/
|
|
109
|
+
getActiveTool(): ToolType | null;
|
|
110
|
+
/**
|
|
111
|
+
* Set the active editing tool (FR-026, FR-028, FR-034)
|
|
112
|
+
* Only one tool can be active at a time
|
|
113
|
+
* Switching tools will deactivate the previous tool
|
|
114
|
+
*
|
|
115
|
+
* @param toolType - Type of tool to activate
|
|
116
|
+
* @throws {Error} If edit mode is not enabled
|
|
117
|
+
*/
|
|
118
|
+
setActiveTool(toolType: ToolType): void;
|
|
119
|
+
/**
|
|
120
|
+
* Initialize editing tools
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
private _initializeTools;
|
|
124
|
+
/**
|
|
125
|
+
* recreate all visuals based on circuit data
|
|
126
|
+
* Should be called on an already cleared scene
|
|
127
|
+
* @private
|
|
128
|
+
*/
|
|
129
|
+
private _fullUpdate;
|
|
130
|
+
private _createComponentObject3D;
|
|
131
|
+
/**
|
|
132
|
+
* Index component mesh and its pins meshes for interaction (hover, selection)
|
|
133
|
+
* @param componentId
|
|
134
|
+
* @param object3D
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
private _indexComponentObject3D;
|
|
138
|
+
private _removeComponentObject3D;
|
|
139
|
+
/**
|
|
140
|
+
* Create enode (branching point ONLY) visual object and add to scene
|
|
141
|
+
* pin enodes are created and attache to their components by createComponentObject3D()
|
|
142
|
+
*
|
|
143
|
+
* @param enode
|
|
144
|
+
* @private
|
|
145
|
+
*/
|
|
146
|
+
private _createEnodeObject3D;
|
|
147
|
+
private _removeEnodeObject3D;
|
|
148
|
+
addBranchingPoint(worldPosition: THREE.Vector3, sourceType?: ENodeSourceType | undefined): ENode;
|
|
149
|
+
/**
|
|
150
|
+
* Split wire either :
|
|
151
|
+
* - at a position, inserting a new branching point and two new wires replacing the deleted ones
|
|
152
|
+
* - at an existing target enode, replacing the wire by two new wires connected to this enode
|
|
153
|
+
* @param wireId
|
|
154
|
+
* @param worldPosition - world Position for the new branching point : no effect if targetEnodeId provided
|
|
155
|
+
* @param targetEnodeId - if provided, the existing enode to split the wire at
|
|
156
|
+
*/
|
|
157
|
+
splitWire(wireId: UUID, worldPosition: THREE.Vector3, targetEnodeId?: UUID | null): {
|
|
158
|
+
branchingPoint: ENode;
|
|
159
|
+
wires: Wire[];
|
|
160
|
+
};
|
|
161
|
+
/**
|
|
162
|
+
* Remove branching point enode visual and update the circuit and visuals
|
|
163
|
+
* @param enodeId
|
|
164
|
+
*/
|
|
165
|
+
removeBranchingPoint(enodeId: UUID): void;
|
|
166
|
+
private _createWireObject3D;
|
|
167
|
+
/**
|
|
168
|
+
* add a wire between two enodes : update the circuit and add visuals
|
|
169
|
+
* @param sourceEnodeId
|
|
170
|
+
* @param targetEnodeId
|
|
171
|
+
*/
|
|
172
|
+
addWire(sourceEnodeId: UUID, targetEnodeId: UUID): Wire;
|
|
173
|
+
/**
|
|
174
|
+
* Add a component to the circuit and scene
|
|
175
|
+
*
|
|
176
|
+
* @param type - Component type to add
|
|
177
|
+
* @param worldPosition - Position in 3D world coordinates (x, z)
|
|
178
|
+
* @param rotation - 3D world rotation, if left null the default componentType rotation is applied
|
|
179
|
+
* @param config - Optional configuration map for the component
|
|
180
|
+
* @param pinSources - Optional array of source types for the component pins
|
|
181
|
+
* @returns The created Component
|
|
182
|
+
*/
|
|
183
|
+
addComponent(type: ComponentType, worldPosition: THREE.Vector3, rotation: Euler | null, config?: Map<string, string> | undefined, pinSources?: Array<ENodeSourceType | undefined | null> | undefined): Component;
|
|
184
|
+
/**
|
|
185
|
+
* edit component config and update visuals if necessary
|
|
186
|
+
*
|
|
187
|
+
* @param componentId
|
|
188
|
+
* @param newConfig - map of parameters to be merged into the current config
|
|
189
|
+
*/
|
|
190
|
+
editComponentConfig(componentId: UUID, newConfig: Map<string, string>): void;
|
|
191
|
+
/**
|
|
192
|
+
* cycle component config and update visuals if necessary
|
|
193
|
+
* have effect only on components that supports fast config cycle (used to invert logic or initial state of switches)
|
|
194
|
+
* else use editComponentConfig
|
|
195
|
+
*
|
|
196
|
+
* @returns if the component has changed config
|
|
197
|
+
* @param componentId
|
|
198
|
+
*/
|
|
199
|
+
cycleComponentConfig(componentId: UUID): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Remove a component from the circuit and scene
|
|
202
|
+
*
|
|
203
|
+
* @param componentId - UUID of the component to remove
|
|
204
|
+
*/
|
|
205
|
+
removeComponent(componentId: UUID): void;
|
|
206
|
+
/**
|
|
207
|
+
* Update an enode based to a new source type.
|
|
208
|
+
* @param enodeId - UUID of the enode
|
|
209
|
+
* @param sourceType - New source type (null for no source)
|
|
210
|
+
*/
|
|
211
|
+
updateEnodeSourceType(enodeId: UUID, sourceType: ENodeSourceType | null): void;
|
|
212
|
+
/**
|
|
213
|
+
* Remove wire visual and update the circuit
|
|
214
|
+
* @param wireId
|
|
215
|
+
*/
|
|
216
|
+
removeWire(wireId: UUID): void;
|
|
217
|
+
/**
|
|
218
|
+
* Automatically adjust the circuit grid size and divisions based on positions of all core circuit elements.
|
|
219
|
+
*/
|
|
220
|
+
autoAdjustCircuitGridSize(): void;
|
|
221
|
+
/**
|
|
222
|
+
* Hook called before exporting the circuit visualization.
|
|
223
|
+
* Saves world informations such as camera position, in the circuit metadata.
|
|
224
|
+
*/
|
|
225
|
+
beforeExport(): void;
|
|
226
|
+
private _removeWireObject3D;
|
|
227
|
+
protected _removeAllVisuals(): void;
|
|
228
|
+
}
|
|
@@ -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,31 @@
|
|
|
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
|
+
/**
|
|
25
|
+
* Signal a language change — hides any open tooltip so the next hover
|
|
26
|
+
* recreates it with updated translations.
|
|
27
|
+
*/
|
|
28
|
+
setLanguage(_lng: string): void;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
private _position;
|
|
31
|
+
}
|