- Overview
- Purpose of MhSnapperShape
- Examples of Stored State
- Shape Properties
- Providing shape to MhSnapper
- Configuration of Shapes
MhSnapperShape
Overview
MhSnapperShape
is intended to be overridden to store any product specific state of an MhSnapper
. The MhSnapperShape
is responsible for determining the identity of the MhSnapper
and is provided to the MhSnapper
by the MhSnapperSpawner
that creates it. The MhSnapperShape
is stored in the shape
field on MhSnapper
.
Purpose of MhSnapperShape
-
Identity: It provides each
MhSnapper
with a distinct identity. - State Storage: It holds important data like dimensions, connectors, and other product specific options.
-
Connector Behavior: Controls many
Connector
control methods typically overridden onSnapper
such asallowTrySnap
,connected
, anddisconnected
. -
User Configurability: The
MhSnapperShape
is the only item configured by the user in a drawing.
Examples of Stored State
- Dimensions: Defines the size and shape of the snapper.
- Bounds: Defines the area that the snapper occupies.
-
Connectors: Creates and stores the
MhSnapper
s connectors. - Product Options: Stores any product specific options such as material, color, or any other configurable options.
- Geometries: Stores any geometries, which control collision detection in the system.
Shape Properties
Fields added to MhSnapperShape
which are intended to be user-configurable in the drawing should be added to the props
of the MhShape
these will be exposed by the owning MhSnapper
and any PropInputSetting
s on the shape will be visible on the selection of the MhSnapper
.
Providing shape to MhSnapper
The MhSnapperShape
is provided to the MhSnapper
by the MhSnapperSpawner
that creates it. MhSnapperSpawner
s populate the snapper spawned with the appropriate MhSnapperShape
and MhBehavior
s to spawn the object that the spawner inserts. This is done by overriding the shapeClass
method on the MhSnapperSpawner
and returning the Class
of the appropriate MhSnapperShape
for the given MhSnapper
.
... public Class shapeClass() { //Use custom shape here return MhSnapperShape; } ...
Configuration of Shapes
The shape is the item primarily altered by the configuration dialog and it's MhConfigItem
s. To get proper values to configure defaults via the configuration dialog, an MhSnapperShape
must be registered to an MhConfigItem
object. This is done by overriding the shapes
method on he MhConfigItem
and providing all shapes configured by that MhConfigItem
.
... public MhSnapperShape[] shapes() { //Return all shapes configured by this config item return [MhSnapperShape: MyCustomShape()]; } ...
Comments
0 comments
Please sign in to leave a comment.