Reactor System
Less than 1 minute
Reactor System
Entity reactors are used to establish relationships between entities so that when a source entity changes, related target entities are updated automatically.
Online Examples
| Example | Description | Link |
|---|---|---|
| Basic Reactor | Use event listeners to implement entity response | Online Demo{target="_blank"} |
| Associative Dimension Reactor | Dimensions automatically follow source entity updates | Online Demo{target="_blank"} |
| Multi-Type Monitor Reactor | Monitor changes across multiple entity types | Online Demo{target="_blank"} |
| Constraint Reactor | Implement geometric constraints | Online Demo{target="_blank"} |
| Lifecycle Reactor | Monitor the full entity lifecycle | Online Demo{target="_blank"} |
Overview
The reactor system is an advanced WebCAD feature used for:
- Associative dimensions: dimensions update automatically when measured entities move
- Geometric constraints: preserve relationships between entities
- Parametric design: changing one entity triggers updates to related entities
Core API
Basic Reactor
const { EntityReactorManager } = vjcad;
// Register reactor
EntityReactorManager.register({
sourceEntityId: sourceEntity.id,
targetEntityId: targetEntity.id,
onSourceModified: (source, target) => {
// Update target entity when source entity changes
target.move(source.center.x - target.center.x,
source.center.y - target.center.y);
Engine.regen();
}
});Associative Dimensions
// Create associative dimension
const dimension = new LinearDimensionEnt(/* ... */);
dimension.associateWith(lineEntity); // Associate with line entity
// When the line moves, the dimension updates automaticallyUse Cases
- Associative dimensions: dimension annotations follow measured geometry
- Equal-distance constraints: keep a fixed spacing between entities
- Parallel constraints: preserve parallel relationships between lines
- Concentric constraints: preserve concentric relationships between circles and arcs