Wednesday, October 15, 2008

Connectors


In TinkerCell, connectors (Tinkercell::ConnectionGraphicsItem ) are represented as a list of "PathVector" (Tinkercell::ConnectionGraphicsItem::PathVector) items. Each PathVector is a set of points (Tinkercell::ControlPoint) and two arrow heads (Tinkercell::ArrowHeadItem). The arrow-heads can be null. If they are not null, the arrow heads are drawn at the start and end of each path vector. The path vector itself is a path defined by a set of points. The number of points is always a (multiple of 3) + 1 because they are drawn as Beziers. When drawn as straight lines ( Tinkercell::ConnectionGraphicsItem::LineType ), the connectors ignore every 2nd and 3rd point that define the Beziers. 

The connectors also have a middle region that is designed for implementing descriptors that can be placed in the center. This has not been implemented, but the connector has all the capabilities to implement it. 

The ArrowHeadItem derives from PartGraphicsItem, hence they can be drawn using the PartGraphics drawing program. 

Getting the connected Parts

The connectors do not store pointers to the parts they are connected to separately. Rather, everything is done directly. The first control point will always be a child item of a part item. This has a few nice benefits:
  1. the control point will automatically move with the part
  2. the control point's parentItem() method can be used to find the connected parts, thus preventing the need to store a separate list for connected parts
  3. the visual representation and the actual storage of connected parts is done simultaneously, thus there will be no synchronization problems
The connector class provides various functions, such as partAt(), replacePart(), parts(), controlPoints(), arrowHeadAt(), arrowHeads(), etc. If you look at the code for the class, you will see that all of these function only rely on the list of path vectors to get the information needed. 




No comments: