Skip to content

Viewer entity rules

A workflow type can declare viewer entity rules: the bidirectional mapping between its configuration and the entities a viewer (e.g. Workbench) displays alongside the CAD — probe points, planes, spheres, cylinders, and boxes. The viewer stays type-agnostic: it renders whatever entities the rules generate and sends edited entities back; the rules decide what that means for the configuration.

Rules are authored in the viewerEntityRuleSet { } block of the .workflow-type.kts script, using the workflow type's own generated configuration value model:

viewerEntityRuleSet {
    ViewerEntityRuleSet(
        listOf(
            ViewerEntityRule(
                viewerEntities =
                    ConstantValueList(
                        ProbePointValueModel(
                            name = "Probe point".asValueModel(),
                            point = configValueModel.probePoint,
                        ),
                    ),
                viewerEntityMatcher = ProbePointValueModel.matches(),
                configurationValues =
                    listOf(
                        ViewerEntityBasedConfigurationValue(
                            location = configValueModel.probePoint.reference(),
                            value = ProbePointValueModel.fromReference().point,
                        ),
                    ),
            ),
        ),
    )
}

Each rule is one semantic unit with both directions:

  • viewerEntities — a value list resolved against the configuration; each resolved element is one viewer entity (the configuration → viewer direction).
  • viewerEntityMatcher + configurationValues — for every incoming viewer entity the matcher accepts, each configuration value's value is resolved against that entity and written at its location (the viewer → configuration direction).

Every viewer entity value model provides two companions for the backward direction: matches() is a condition accepting entities of that type, and fromReference() reads the entity's attributes, so SphereValueModel.fromReference().radius is "the radius of the sphere being applied".

Mapping shapes

One-to-one — a configuration value mirrored directly (the probe point above). Values pass through in the units the user entered.

One-to-many — one entity computed from (and decomposed back into) several configuration values, e.g. a box shown as min/max corners but stored as corner plus extents. Note that computed values follow the value model convention: results of arithmetic on dimensionals are in base SI units.

Many-to-many — a configuration list mapped element-wise to a list of entities:

viewerEntities =
    configValueModel.refinementSpheres.map { sphere ->
        SphereValueModel(
            name = "Refinement sphere".asValueModel(),
            center = sphere.center,
            radius = sphere.radius,
        )
    },
...
configurationValues =
    listOf(
        ViewerEntityBasedConfigurationValue(
            location = configValueModel.refinementSpheres.element().center.reference(),
            value = SphereValueModel.fromReference().center,
        ),
    ),

Entities generated from a configuration list carry a source reference (list path plus the element's stable id) identifying the element they came from. Viewers treat it as an opaque token and send it back unchanged; the update then targets exactly that element, even if the list was reordered in between.

List elements can also be added and removed through viewer entities, as their own explicit operations rather than by inference from an update payload (an omitted entity never removes anything, and an entity without a source reference never creates anything on update — so partial updates and re-sends stay safe). An added entity carries no source reference and must match rules generated from a single configuration list; a new element with the rules' mapped values is appended there, receives its stable id, and any fields the rules do not map behave like in any partially filled configuration — defaults apply on read, and validation reports what still has to be provided. A removed entity is addressed purely by its source reference; elements already gone are tolerated.

A live example with all three shapes: e2e/components/workflow-types/test-viewer-entities-workflow/.

For the transformation endpoints and storage, see framework-developer: Viewer entities internals.

What this isn't

Populating a point field from the geometry of assigned entities (the center of mass of a selected volume) is a form action, not a displayed entity: declare it with geometryDerivationUi in the UI configuration.