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,159 @@
|
|
|
1
|
+
import { UUID } from '../../core/index.ts';
|
|
2
|
+
import { HoverableType, SelectionData } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Callback invoked when selection changes
|
|
5
|
+
*
|
|
6
|
+
* @param newSelection - The new selection, or null if deselected
|
|
7
|
+
* @param previousSelection - The previous selection, or null if none was selected
|
|
8
|
+
*/
|
|
9
|
+
export type SelectionCallback = (newSelection: SelectionData | null, previousSelection: SelectionData | null) => void;
|
|
10
|
+
/**
|
|
11
|
+
* Manages selected components, enodes or wires for the circuit scene.
|
|
12
|
+
* Multi-selection is planned (notably with the use of a flexible SelectionData) but still to implement.
|
|
13
|
+
*
|
|
14
|
+
* Key current responsibilities:
|
|
15
|
+
* - Track -currently single object- selection state
|
|
16
|
+
* - Notify listeners of selection changes (observer pattern)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const selectionManager = new SelectionManager();
|
|
21
|
+
*
|
|
22
|
+
*
|
|
23
|
+
* // Select a single object
|
|
24
|
+
* selectionManager.selectOne('component', 'component-uuid-1234');
|
|
25
|
+
* selectionManager.selectOne('enode', 'enode-uuid-1234');
|
|
26
|
+
* selectionManager.selectOne('wire', 'wire-uuid-1234');
|
|
27
|
+
*
|
|
28
|
+
* // Deselect
|
|
29
|
+
* selectionManager.deselect();
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class SelectionManager {
|
|
33
|
+
/** Current selection */
|
|
34
|
+
private selection;
|
|
35
|
+
/** Timestamp when selection occurred (for double-click detection) */
|
|
36
|
+
private selectedAt;
|
|
37
|
+
/** Registered selection change callbacks */
|
|
38
|
+
private callbacks;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new SelectionManager
|
|
41
|
+
*/
|
|
42
|
+
constructor();
|
|
43
|
+
/**
|
|
44
|
+
* Get the current selection
|
|
45
|
+
*
|
|
46
|
+
* @returns The SelectionData, or null if nothing is selected
|
|
47
|
+
*/
|
|
48
|
+
getSelection(): SelectionData | null;
|
|
49
|
+
/**
|
|
50
|
+
* Get the timestamp when selection occurred
|
|
51
|
+
*
|
|
52
|
+
* @returns Timestamp in milliseconds, or null if nothing is selected
|
|
53
|
+
*/
|
|
54
|
+
getSelectedAt(): number | null;
|
|
55
|
+
/**
|
|
56
|
+
* Check if a specific object is selected
|
|
57
|
+
*
|
|
58
|
+
* @param type - The type of hoverable object
|
|
59
|
+
* @param objectId - The object ID to check
|
|
60
|
+
* @returns true if the object is currently selected
|
|
61
|
+
*/
|
|
62
|
+
isSelected(type: HoverableType, objectId: UUID): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Check if anything is selected
|
|
65
|
+
*
|
|
66
|
+
* @returns true if one object is currently selected or several objects are currently selected
|
|
67
|
+
*/
|
|
68
|
+
hasSelection(): boolean;
|
|
69
|
+
private _selectionsEqual;
|
|
70
|
+
/**
|
|
71
|
+
* Select one object
|
|
72
|
+
*
|
|
73
|
+
* If another object was previously selected or a multi selection existed, they will be deselected first.
|
|
74
|
+
*
|
|
75
|
+
* @param type - The type of hoverable object to select
|
|
76
|
+
* @param objectId - The object ID to select
|
|
77
|
+
* @param userData - Optional userData of the 3D object being selected
|
|
78
|
+
*/
|
|
79
|
+
selectOne(type: HoverableType, objectId: UUID, userData?: object | undefined): void;
|
|
80
|
+
/**
|
|
81
|
+
* Deselect the current selection
|
|
82
|
+
*/
|
|
83
|
+
deselect(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Select multiple elements at once, replacing any existing selection
|
|
86
|
+
*
|
|
87
|
+
* Creates a MultiSelectionData with the provided element maps.
|
|
88
|
+
* Empty maps are allowed; passing all empty maps clears the selection.
|
|
89
|
+
*
|
|
90
|
+
* @param components - Map of component IDs to optional metadata
|
|
91
|
+
* @param enodes - Map of enode IDs to optional metadata
|
|
92
|
+
* @param wires - Map of wire IDs to optional metadata
|
|
93
|
+
*/
|
|
94
|
+
selectMultiple(components?: Map<UUID, string | null>, enodes?: Map<UUID, string | null>, wires?: Map<UUID, string | null>): void;
|
|
95
|
+
/**
|
|
96
|
+
* Add a single element to the current selection
|
|
97
|
+
*
|
|
98
|
+
* If current selection is null, creates a mono selection.
|
|
99
|
+
* If current selection is mono, converts to multi and adds element.
|
|
100
|
+
* If current selection is multi, adds element to appropriate map.
|
|
101
|
+
*
|
|
102
|
+
* No-op if element is already selected.
|
|
103
|
+
*
|
|
104
|
+
* @param type - Type of element to add
|
|
105
|
+
* @param objectId - UUID of element to add
|
|
106
|
+
* @param userData - Optional metadata for the element
|
|
107
|
+
*/
|
|
108
|
+
addToSelection(type: HoverableType, objectId: UUID, userData?: object): void;
|
|
109
|
+
/**
|
|
110
|
+
* Remove a single element from the current selection
|
|
111
|
+
*
|
|
112
|
+
* If element is in a mono selection, clears the selection.
|
|
113
|
+
* If element is in a multi selection, removes from appropriate map.
|
|
114
|
+
* If multi selection becomes single element, converts to mono.
|
|
115
|
+
*
|
|
116
|
+
* No-op if element is not selected.
|
|
117
|
+
*
|
|
118
|
+
* @param type - Type of element to remove
|
|
119
|
+
* @param objectId - UUID of element to remove
|
|
120
|
+
*/
|
|
121
|
+
removeFromSelection(type: HoverableType, objectId: UUID): void;
|
|
122
|
+
/**
|
|
123
|
+
* Get the total count of selected elements across all types
|
|
124
|
+
*
|
|
125
|
+
* @returns Number of selected elements (0 if no selection)
|
|
126
|
+
*/
|
|
127
|
+
getSelectionCount(): number;
|
|
128
|
+
/**
|
|
129
|
+
* Get all selected element IDs grouped by type
|
|
130
|
+
*
|
|
131
|
+
* Returns empty arrays if no selection.
|
|
132
|
+
* For mono selection, returns single-element array in appropriate category.
|
|
133
|
+
*
|
|
134
|
+
* @returns Object with arrays of selected IDs by type
|
|
135
|
+
*/
|
|
136
|
+
getSelectedIds(): {
|
|
137
|
+
components: UUID[];
|
|
138
|
+
enodes: UUID[];
|
|
139
|
+
wires: UUID[];
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Register a callback for selection changes
|
|
143
|
+
*
|
|
144
|
+
* @param callback - Function to call when selection changes
|
|
145
|
+
* @returns Unsubscribe function
|
|
146
|
+
*/
|
|
147
|
+
onSelectionChange(callback: SelectionCallback): () => void;
|
|
148
|
+
/**
|
|
149
|
+
* Notify all registered callbacks of selection change
|
|
150
|
+
*
|
|
151
|
+
* @param newSelection - New selection
|
|
152
|
+
* @param previousSelection - Previous selection
|
|
153
|
+
*/
|
|
154
|
+
private notifyCallbacks;
|
|
155
|
+
/**
|
|
156
|
+
* Clean up resources
|
|
157
|
+
*/
|
|
158
|
+
dispose(): void;
|
|
159
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { Line2 } from 'three/examples/jsm/lines/Line2.js';
|
|
2
|
+
import { UUID, Wire, Circuit } from '../../core/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Wire Visual Manager
|
|
5
|
+
* @module scene/shared/WireVisualManager
|
|
6
|
+
*
|
|
7
|
+
* Manages wire visual rendering with:
|
|
8
|
+
* - Pin-accurate endpoints (derived from component visuals)
|
|
9
|
+
* - Multi-segment rendering via intermediate positions
|
|
10
|
+
* - Dynamic updates during component movement
|
|
11
|
+
*/
|
|
12
|
+
import * as THREE from 'three';
|
|
13
|
+
/**
|
|
14
|
+
* Wire path representation for rendering
|
|
15
|
+
*/
|
|
16
|
+
export interface WirePath {
|
|
17
|
+
/** Wire ID */
|
|
18
|
+
wireId: UUID;
|
|
19
|
+
/** Ordered points in world space (Three.js coordinates) */
|
|
20
|
+
points: THREE.Vector3[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Delegation of CircuitController which handles wire visual rendering with proper pin targeting and dynamic updates.
|
|
24
|
+
*
|
|
25
|
+
* Key responsibilities:
|
|
26
|
+
* - Create wire visuals with endpoints at actual pin positions
|
|
27
|
+
* - Support multi-segment wires via intermediatePositions
|
|
28
|
+
* - Update wires dynamically when components move/rotate
|
|
29
|
+
* - Update wire materials for hover/selection states
|
|
30
|
+
* - may add and remove wire and branching point object3Ds in the scene directly
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const wireManager = new WireVisualManager();
|
|
35
|
+
*
|
|
36
|
+
* // Create wire visual
|
|
37
|
+
* const line = wireManager.createOrUpdateWire(wire, circuit, scene, componentGroups);
|
|
38
|
+
*
|
|
39
|
+
* // Update wires when component moves
|
|
40
|
+
* wireManager.updateWiresForComponent(componentId, circuit, componentGroups);
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare class WireVisualManager {
|
|
44
|
+
private containerWidth;
|
|
45
|
+
private containerHeight;
|
|
46
|
+
private _scene;
|
|
47
|
+
private _camera;
|
|
48
|
+
private _componentObject3Ds;
|
|
49
|
+
private _wireObject3Ds;
|
|
50
|
+
private _container;
|
|
51
|
+
private _circuit;
|
|
52
|
+
/** Shared LineMaterials for all wires (memory efficient, consistent styling) */
|
|
53
|
+
private wireMaterials;
|
|
54
|
+
/** Preview wire for wire creation mode */
|
|
55
|
+
private previewWire;
|
|
56
|
+
constructor(componentObject3Ds: Map<UUID, THREE.Object3D>, wireObject3Ds: Map<UUID, Line2>);
|
|
57
|
+
setContainer(container: HTMLElement | null): void;
|
|
58
|
+
setSceneAndCamera(scene: THREE.Scene, camera: THREE.Camera): void;
|
|
59
|
+
setCircuit(circuit: Circuit | null): void;
|
|
60
|
+
/**
|
|
61
|
+
* Set the resolution for LineMaterial rendering
|
|
62
|
+
*
|
|
63
|
+
* MUST be called after initialization and on window/container resize
|
|
64
|
+
* for Line2 to render correctly.
|
|
65
|
+
*
|
|
66
|
+
* @param width - Viewport width in pixels
|
|
67
|
+
* @param height - Viewport height in pixels
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* wireManager.setResolution(window.innerWidth, window.innerHeight);
|
|
72
|
+
*
|
|
73
|
+
* window.addEventListener('resize', () => {
|
|
74
|
+
* wireManager.setResolution(window.innerWidth, window.innerHeight);
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
setResolution(width: number, height: number): void;
|
|
79
|
+
/**
|
|
80
|
+
* Get the Line2 object for a wire
|
|
81
|
+
*
|
|
82
|
+
* @param wireId - Wire ID
|
|
83
|
+
* @returns Line2 or undefined if not found or disposed
|
|
84
|
+
*/
|
|
85
|
+
getWireLine(wireId: UUID): Line2 | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Check if a wire visual exists
|
|
88
|
+
*
|
|
89
|
+
* @param wireId - Wire ID
|
|
90
|
+
* @returns true if wire visual exists, false if not found or disposed
|
|
91
|
+
*/
|
|
92
|
+
hasWire(wireId: UUID): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Get all wire IDs managed by this controllerType
|
|
95
|
+
*
|
|
96
|
+
* @returns Array of wire UUIDs, empty if disposed
|
|
97
|
+
*/
|
|
98
|
+
getWireIds(): UUID[];
|
|
99
|
+
/**
|
|
100
|
+
* Create or update the visual for a wire using model wire positions
|
|
101
|
+
*
|
|
102
|
+
* @param wire - Wire to render
|
|
103
|
+
* @returns The created/updated Line2 object
|
|
104
|
+
*/
|
|
105
|
+
createOrUpdateWire(wire: Wire): Line2;
|
|
106
|
+
/**
|
|
107
|
+
* Update a specific wire's geometry
|
|
108
|
+
*
|
|
109
|
+
* @param wireId - Wire ID to update
|
|
110
|
+
*/
|
|
111
|
+
updateWireById(wireId: UUID): void;
|
|
112
|
+
/**
|
|
113
|
+
* Update all wires connected to a component
|
|
114
|
+
*
|
|
115
|
+
* Called when a component is moved or rotated to update wire endpoints.
|
|
116
|
+
*
|
|
117
|
+
* @param componentId - Component that moved
|
|
118
|
+
*/
|
|
119
|
+
updateWiresForComponent(componentId: UUID): void;
|
|
120
|
+
/**
|
|
121
|
+
* visual hover and selection effects
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* Apply hovered visual effect to a wire
|
|
125
|
+
* @param wireId
|
|
126
|
+
*/
|
|
127
|
+
applyHoveredVisual(wireId: UUID): void;
|
|
128
|
+
removeHoveredVisual(wireId: UUID): void;
|
|
129
|
+
applySelectedVisual(wireId: UUID): void;
|
|
130
|
+
removeSelectedVisual(wireId: UUID): void;
|
|
131
|
+
/**
|
|
132
|
+
* Apply electrical state material to a wire
|
|
133
|
+
* Used during simulation to visualize voltage/current flow
|
|
134
|
+
*
|
|
135
|
+
* @param wireId - Wire ID to update
|
|
136
|
+
* @param state - Material state: 'current', 'voltage', 'vc' (voltage and current) or 'idle'
|
|
137
|
+
*/
|
|
138
|
+
applyElectricalState(wireId: UUID, state: 'current' | 'voltage' | 'vc' | 'idle'): void;
|
|
139
|
+
/**
|
|
140
|
+
* removal and dispose
|
|
141
|
+
*/
|
|
142
|
+
/**
|
|
143
|
+
* Remove a wire visual from the scene
|
|
144
|
+
*
|
|
145
|
+
* @param wireId - Wire ID to remove
|
|
146
|
+
*/
|
|
147
|
+
removeWire(wireId: UUID): void;
|
|
148
|
+
/**
|
|
149
|
+
* Clean up all managed wire visuals
|
|
150
|
+
*/
|
|
151
|
+
dispose(): void;
|
|
152
|
+
/**
|
|
153
|
+
* Preview wire helpers
|
|
154
|
+
*/
|
|
155
|
+
/**
|
|
156
|
+
* Create a preview wire for wire creation mode.
|
|
157
|
+
* @param startPosition - World position of wire start
|
|
158
|
+
* @returns Line2 object for preview
|
|
159
|
+
*/
|
|
160
|
+
createPreviewWire(startPosition: THREE.Vector3): Line2;
|
|
161
|
+
/**
|
|
162
|
+
* Update preview wire endpoint.
|
|
163
|
+
* @param endPosition - World position of wire end
|
|
164
|
+
*/
|
|
165
|
+
updatePreviewWire(endPosition: THREE.Vector3): void;
|
|
166
|
+
/**
|
|
167
|
+
* Remove preview wire from scene.
|
|
168
|
+
*/
|
|
169
|
+
removePreviewWire(): void;
|
|
170
|
+
/**
|
|
171
|
+
* Intermediate points and position helpers
|
|
172
|
+
*/
|
|
173
|
+
/**
|
|
174
|
+
* Get pin world position by traversing component group
|
|
175
|
+
*
|
|
176
|
+
* @param enodeId - The pin's ENode ID
|
|
177
|
+
* @param componentGroup - The component's Three.js group
|
|
178
|
+
* @returns World position of the pin, or null if not found
|
|
179
|
+
*/
|
|
180
|
+
getPinWorldPositionFromGroup(enodeId: UUID, componentGroup: THREE.Object3D): THREE.Vector3 | null;
|
|
181
|
+
/**
|
|
182
|
+
* Get insertion index for a new intermediate point on a wire (T058)
|
|
183
|
+
* @param wireId - Wire ID
|
|
184
|
+
* @param worldPosition - Position where user clicked
|
|
185
|
+
* @returns Index where new point should be inserted
|
|
186
|
+
*/
|
|
187
|
+
getInsertIndexForPosition(wireId: UUID, worldPosition: THREE.Vector3): number;
|
|
188
|
+
/**
|
|
189
|
+
* Find nearest intermediate point on a wire within proximity threshold (T057)
|
|
190
|
+
* @param wireId - Wire ID to search
|
|
191
|
+
* @param clientPos - Client position (event.clientX/Y) to test - will be converted to container-relative
|
|
192
|
+
* @param thresholdPx - Proximity threshold in pixels (default: 10)
|
|
193
|
+
* @returns Object with pointIndex and distance, or null if none found
|
|
194
|
+
*/
|
|
195
|
+
findNearestIntermediatePoint(wireId: UUID, clientPos: THREE.Vector2, thresholdPx?: number): {
|
|
196
|
+
pointIndex: number;
|
|
197
|
+
distance: number;
|
|
198
|
+
} | null;
|
|
199
|
+
/**
|
|
200
|
+
* Compute the full path for a wire including intermediate positions
|
|
201
|
+
*
|
|
202
|
+
* @param wire - Wire to compute path for
|
|
203
|
+
* @returns WirePath with array of Vector3 points from start to end
|
|
204
|
+
*/
|
|
205
|
+
computeWirePath(wire: Wire): WirePath;
|
|
206
|
+
/**
|
|
207
|
+
* private helpers
|
|
208
|
+
*/
|
|
209
|
+
/**
|
|
210
|
+
* Get the world position of an ENode (pin or branching point)
|
|
211
|
+
*
|
|
212
|
+
* For pins: Traverses component group to find pin visual and gets world position
|
|
213
|
+
* For branching points: Converts grid position to world coordinates
|
|
214
|
+
*
|
|
215
|
+
* @param enodeId - The ENode ID
|
|
216
|
+
* @param enodeType - Type of the ENode (Pin or BranchingPoint)
|
|
217
|
+
* @param componentId - Parent component ID (for pins)
|
|
218
|
+
* @param circuit - Circuit for position lookup
|
|
219
|
+
* @param componentGroups - Map of component ID to Three.js objects
|
|
220
|
+
* @returns World position as Vector3
|
|
221
|
+
*/
|
|
222
|
+
private _getENodeWorldPosition;
|
|
223
|
+
/**
|
|
224
|
+
* Convert 3D world position to 2D screen position (T056)
|
|
225
|
+
* @param worldPosition - World position as Vector3
|
|
226
|
+
* @returns Screen position as Vector2
|
|
227
|
+
*/
|
|
228
|
+
private worldToScreen;
|
|
229
|
+
/**
|
|
230
|
+
* Calculate distance between two 2D screen positions (T056)
|
|
231
|
+
* @param screenPos1 - First screen position
|
|
232
|
+
* @param screenPos2 - Second screen position
|
|
233
|
+
* @returns Distance in pixels
|
|
234
|
+
*/
|
|
235
|
+
private screenDistance;
|
|
236
|
+
/**
|
|
237
|
+
* Convert client coordinates (event.clientX/Y) to container-relative coordinates
|
|
238
|
+
* @param clientPos - Position in client/viewport coordinates
|
|
239
|
+
* @returns Position relative to the container's top-left corner
|
|
240
|
+
*/
|
|
241
|
+
private clientToContainerCoords;
|
|
242
|
+
}
|