Skip to content
oleegholm edited this page Jun 9, 2012 · 10 revisions

A module is basically an immutable state-machine that provides interaction Siigna and visual feedback based on incoming Events. In other words the modules are the part of Siigna that provides event-based functionality while drawing graphical representations on the View.

The utilizes three mechanisms to handle the event-flow and the graphical feedback: The EventHandler, the EventParser and the ModuleInterface.

Table of Contents

Module state

In depth article: States.
Before describing the three classes I'd like to touch on the subject of States. A state is a specific condition that the module is in at a specific time. The module can describe different states to direct the event-flow, although two states are mandatory: Start and End (with capital starting letters). Theses states indicate the starting and ending states in which modules are instantiated and ended respectively.

EventHandler

In depth article: EventHandler.
The EventHandler is the entry-point for events. That is, the EventHandler handles the event-flow from the Controller and into the module, thus deciding which states to execute the functionality of. The EventHandler uses a StateMap and a StateMachine to delegate the events.
 GENERAL NOTE: after the Menu forwards to a module with the 
 triggering event (MouseDown), other events (like MouseUp) 
 may be registered while the ForwardTo mechanism is running. 
 These events can trigger Goto events in the module, 
 unless ruled out by case matches.

StateMap

Read more: StateMap.
The StateMap is used to events into states, and every time a route is mapped the state map will change the state when the correct conditions are present. A state map, then, only serves to change the states of a given module so the events are propagated in the way the designer of the module wants. Besides the state map states can be controlled through Commands. The actual events are acted upon in the StateMachine.

StateMachine

Read more: StateMachine.
The StateMachine maps the states of the modules along with their functionalities. The state machine must contain a Start and an End node, since Siigna needs both an entry and exit point. Each state are given a list of Events that the state can choose to react on. This can be done through Scala's match, since each events are case classes.

EventParser

In depth article: EventParser.
The EventParser is a parser for events connected to a specific module. It basically transforms events into other events based on the algorithms attached to it. It is pretty handy for things like Snap and Track. In detail it uses two mechanisms to parse the events: EventSnap and EventTrack. One module can snap to many different settings (the EventSnap trait) while one module only is able to track one setting at the time (the EventTrack trait).

ModuleInterface

In depth article: ModuleInterface.
A ModuleInterface is a subtype of the Interface trait which handles graphical settings and paint-delegation in Siigna. The ModuleInterface works as the graphical entry-point into the modules. The interface is thus responsible for painting two things: First of all the module itself (via the paint-method) and the Displays (via the Display class).

Painting

A module can exist without ways to paint it's contents. But if the modules wants to show graphical feedback all you have to do is to override the paint method like so:

 override def paint(g : Graphics, t : TransformationMatrix) : Unit

The Graphics object can be used to draw shapes and the TransformationMatrix can transform them to fit the screen as is.

Modules calling modules

Modules can call another module to get its functionality. This means that commonly used operations does not have to be implemented seperately in each individual module that needs this operations, but the individual models can all forward to the same module to get the operation. A good example of this that the base modules have a Point module, that is used for setting a point, then returning its coordinates. Several modules forward to this point module, Eg. polyline, rectangle, and text.. basically all modules that needs one or more point coordinates as part of their functionality. Actually the Point module has the ability to call the Angle Gizmo module if the user wish to get a point that lies in a specific angle relative to another point. See an illustration of the Polyline-Point-AngleGizmo calling logic here: polyline module calling structure.

See also

Clone this wiki locally