This module serves as the application's main configuration hub, handling the registration and setup of all circuit elements, renderers, and GUI commands. It implements the Registry pattern to provide centralized management of application components.
Key Responsibilities:
- Element registration (resistors, capacitors, wires, etc.) with their factory functions
- Renderer registration for visual component rendering
- GUI command registration for user interactions
- Dependency injection setup for the application architecture
🔧 Primary Extension Points:
- Add new element types via ElementRegistry
- Register custom renderers via RendererFactory
- Add custom commands via GUICommandRegistry
- Configure application-wide settings
Architecture Pattern: This file implements the Registry Pattern and Factory Pattern to enable dynamic component creation and loose coupling between modules.
- Description:
This module serves as the application's main configuration hub, handling the registration and setup of all circuit elements, renderers, and GUI commands. It implements the Registry pattern to provide centralized management of application components.
Key Responsibilities:
- Element registration (resistors, capacitors, wires, etc.) with their factory functions
- Renderer registration for visual component rendering
- GUI command registration for user interactions
- Dependency injection setup for the application architecture
🔧 Primary Extension Points:
- Add new element types via ElementRegistry
- Register custom renderers via RendererFactory
- Add custom commands via GUICommandRegistry
- Configure application-wide settings
Architecture Pattern: This file implements the Registry Pattern and Factory Pattern to enable dynamic component creation and loose coupling between modules.
- Source:
- Since:
- 1.0.0
Members
(inner, constant) rendererFactory
Renderer Registration - Adapter Pattern Implementation
This section registers visual renderers for each element type using the Factory and Adapter patterns.
- Description:
Renderer Registration - Adapter Pattern Implementation
This section registers visual renderers for each element type using the Factory and Adapter patterns. Each renderer adapts domain entities to visual representation on the HTML5 canvas.
Extension Pattern: To add a new renderer:
- Create a renderer class extending ElementRenderer
- Register it here with the same key as the element type
- The renderer will automatically be used for that element type
- Source:
Renderer Registration - Adapter Pattern Implementation
This section registers visual renderers for each element type using the Factory and Adapter patterns. Each renderer adapts domain entities to visual representation on the HTML5 canvas.
Extension Pattern: To add a new renderer:
- Create a renderer class extending ElementRenderer
- Register it here with the same key as the element type
- The renderer will automatically be used for that element type
Example
// Adding a renderer for a custom element
rendererFactory.register('customElement', CustomElementRenderer);
Methods
(static) setupCommands(circuitService, circuitRenderer)
Sets up and registers all GUI commands for the application.
- Description:
Sets up and registers all GUI commands for the application.
This function is responsible for registering all available commands in the GUICommandRegistry. It's called after the GUIAdapter is initialized to avoid circular dependencies and ensure that all required services (CircuitService, CircuitRenderer) are available.
Dependency Injection Pattern: Commands are registered with factory functions that receive the necessary dependencies at runtime, enabling proper dependency injection and loose coupling.
Command Categories:
- Element manipulation: add, delete, rotate, drag
- Selection: select single, multi-select, select all
- Wire operations: draw wires with splitting logic
- File operations: save/load netlist files
- Clipboard: copy/paste operations
- Source:
Example
const circuitService = new CircuitService(circuit);
const circuitRenderer = new CircuitRenderer(canvas, circuitService);
setupCommands(circuitService, circuitRenderer);
Parameters:
| Name | Type | Description |
|---|---|---|
circuitService |
CircuitService | The circuit service for domain operations |
circuitRenderer |
CircuitRenderer | The renderer for UI operations |