new CircuitService(circuit)
Constructs a new CircuitService.
- Description:
Constructs a new CircuitService.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
circuit |
Circuit | The circuit aggregate to manage. |
Members
circuit :Circuit
The circuit aggregate representing the current circuit design.
- Description:
The circuit aggregate representing the current circuit design.
- Source:
The circuit aggregate representing the current circuit design.
Type:
Methods
addElement(element)
Adds an element to the circuit after validation.
- Description:
Adds an element to the circuit after validation.
Delegates validation to the Circuit aggregate to ensure that the element adheres to all circuit-level rules, such as uniqueness of element ID and non-conflicting node positions.
Emits an "update" event after successfully adding the element.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
element |
Element | The element to add. |
Throws:
-
If the element violates circuit rules.
- Type
- Error
calculateBoundingBox(elements) → {Object}
Calculates the bounding box for a group of elements.
- Description:
Calculates the bounding box for a group of elements.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
elements |
Array.<Element> | Array of elements to calculate bounding box for. |
Returns:
Bounding box with minX, minY, maxX, maxY properties.
- Type
- Object
connectElements(element1, element2)
Connects two elements in the circuit if the connection is valid.
- Description:
Connects two elements in the circuit if the connection is valid.
Delegates validation to the Circuit aggregate and establishes the connection if the rules are met.
Emits an "update" event after successfully connecting the elements.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
element1 |
Element | The first element to connect. |
element2 |
Element | The second element to connect. |
Throws:
-
If the connection violates circuit rules.
- Type
- Error
deleteElement(elementId)
Deletes an element from the circuit.
- Description:
Deletes an element from the circuit.
Removes the element from the list of elements and updates any connections involving the deleted element.
Emits an "update" event after successfully deleting the element.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
elementId |
string | The unique ID of the element to delete. |
exportState() → {string}
Serializes the entire state of the circuit for undo/redo or persistence.
- Description:
Serializes the entire state of the circuit for undo/redo or persistence.
- Source:
Returns:
A JSON string representing the circuit state.
- Type
- string
findConnections(element) → {Array.<Element>}
Finds all elements connected to a given element.
- Description:
Finds all elements connected to a given element.
Searches through the circuit's connections map to identify and return all elements that share a connection with the specified element.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
element |
Element | The element whose connections to find. |
Returns:
List of connected elements.
- Type
- Array.<Element>
getElementByID(elementId) → {Element|null}
Gets a specific element by its ID.
- Description:
Gets a specific element by its ID.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
elementId |
string | The ID of the element to find. |
Returns:
The element with the given ID, or null if not found.
- Type
- Element | null
getElements() → {Array.<Element>}
Retrieves all elements in the circuit.
- Description:
Retrieves all elements in the circuit.
This is a simple delegate method to provide read-only access to the elements of the circuit aggregate.
- Source:
Returns:
The list of elements in the circuit.
- Type
- Array.<Element>
importState(snapshot)
Restores the state of the circuit from a previously exported snapshot.
- Description:
Restores the state of the circuit from a previously exported snapshot.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
snapshot |
string | A JSON string created by exportState(). |
moveElement(elementId, newPosition)
Moves an element to a new position.
- Description:
Moves an element to a new position.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
elementId |
string | The unique identifier of the element to move. |
newPosition |
Position | The new position for the reference terminal. |
rotateElement(elementId, newOrientation)
Rotates an element to a new orientation.
- Description:
Rotates an element to a new orientation.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
elementId |
string | The unique identifier of the element to rotate. |
newOrientation |
number | The new orientation (0, 90, 180, or 270 degrees). |
rotateElements(elementIds, rotationAngleDegrees)
Rotates a group of elements around the center of their bounding box.
- Description:
Rotates a group of elements around the center of their bounding box.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
elementIds |
Array.<string> | Array of element IDs to rotate. |
rotationAngleDegrees |
number | The rotation angle in degrees (90, 180, 270, etc.). |
updateElementProperties(elementId, newProperties) → {boolean}
Updates properties and label of an existing element through the service.
- Description:
Updates properties and label of an existing element through the service. This maintains proper aggregate boundary and ensures state consistency.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
elementId |
string | The ID of the element to update. |
newProperties |
Object | Object containing new property values and label. |
Returns:
True if element was found and updated, false otherwise.
- Type
- boolean