eric7.Graphics.AssociationItem

Module implementing a graphics item for an association between two items.

Global Attributes

None

Classes

AssociationItem Class implementing a graphics item for an association between two items.
AssociationPointRegion Class defining the regions for an association end point.
AssociationType Class defining the association types.

Functions

None


AssociationItem

Class implementing a graphics item for an association between two items.

The association is drawn as an arrow starting at the first items and ending at the second.

Derived from

EricArrowItem

Class Attributes

None

Class Methods

fromDict Class method to create an association item from persisted data.
parseAssociationItemDataString Class method to parse the given persistence data.

Methods

AssociationItem Constructor
__calculateEndingPoints_center Private method to calculate the ending points of the association item.
__calculateEndingPoints_rectangle Private method to calculate the ending points of the association item.
__calculateEndingPoints_topToBottom Private method to calculate the ending points of the association item.
__findIntersection Private method to calculate the intersection point of two lines.
__findPointRegion Private method to find out, which region of rectangle rect contains the point (PosX, PosY) and returns the region number.
__findRectIntersectionPoint Private method to find the intersection point of a line with a rectangle.
__mapRectFromItem Private method to map item's rectangle to this item's coordinate system.
__updateEndPoint Private method to update an endpoint.
toDict Public method to collect data to be persisted.
unassociate Public method to unassociate from the widgets.
widgetMoved Public method to recalculate the association after a widget was moved.

Static Methods

None

AssociationItem.fromDict (class method)

fromDict(data, umlItems, colors=None)

Class method to create an association item from persisted data.

data (dict)
dictionary containing the persisted data as generated by toDict()
umlItems (list of UMLItem)
list of UML items
colors (tuple of (QColor, QColor))
tuple containing the foreground and background colors
Return:
created association item
Return Type:
AssociationItem

AssociationItem.parseAssociationItemDataString (class method)

parseAssociationItemDataString(data)

Class method to parse the given persistence data.

data (str)
persisted data to be parsed
Return:
tuple with the IDs of the source and destination items, the association type and a flag indicating to associate from top to bottom
Return Type:
tuple of (int, int, int, bool)

AssociationItem (Constructor)

AssociationItem(itemA, itemB, assocType=AssociationType.NORMAL, topToBottom=False, colors=None, parent=None, )

Constructor

itemA (UMLItem)
first widget of the association
itemB (UMLItem)
second widget of the association
assocType (AssociationType)
type of the association
topToBottom (bool)
flag indicating to draw the association from item A top to item B bottom
colors (tuple of (QColor, QColor))
tuple containing the foreground and background colors
parent (QGraphicsItem)
reference to the parent object

AssociationItem.__calculateEndingPoints_center

__calculateEndingPoints_center()

Private method to calculate the ending points of the association item.

The ending points are calculated from the centers of the two associated items.

AssociationItem.__calculateEndingPoints_rectangle

__calculateEndingPoints_rectangle()

Private method to calculate the ending points of the association item.

The ending points are calculated by the following method.

For each item the diagram is divided in four Regions by its diagonals as indicated below

            +------------------------------+
            |        \  Region 2  /        |
            |         \          /         |
            |          |--------|          |
            |          | \    / |          |
            |          |  \  /  |          |
            |          |   \/   |          |
            | Region 1 |   /\   | Region 3 |
            |          |  /  \  |          |
            |          | /    \ |          |
            |          |--------|          |
            |         /          \         |
            |        /  Region 4  \        |
            +------------------------------+
        

Each diagonal is defined by two corners of the bounding rectangle.

To calculate the start point we have to find out in which region (defined by itemA's diagonals) is itemB's TopLeft corner (lets call it region M). After that the start point will be the middle point of rectangle's side contained in region M.

To calculate the end point we repeat the above but in the opposite direction (from itemB to itemA)

AssociationItem.__calculateEndingPoints_topToBottom

__calculateEndingPoints_topToBottom()

Private method to calculate the ending points of the association item.

The ending points are calculated from the top center of the lower item to the bottom center of the upper item.

AssociationItem.__findIntersection

__findIntersection(p1, p2, p3, p4)

Private method to calculate the intersection point of two lines.

The first line is determined by the points p1 and p2, the second line by p3 and p4. If the intersection point is not contained in the segment p1p2, then it returns (-1.0, -1.0).

For the function's internal calculations remember:
QT coordinates start with the point (0,0) as the topleft corner and x-values increase from left to right and y-values increase from top to bottom; it means the visible area is quadrant I in the regular XY coordinate system

            Quadrant II     |   Quadrant I
           -----------------|-----------------
            Quadrant III    |   Quadrant IV
        

In order for the linear function calculations to work in this method we must switch x and y values (x values become y values and viceversa)

p1 (QPointF)
first point of first line
p2 (QPointF)
second point of first line
p3 (QPointF)
first point of second line
p4 (QPointF)
second point of second line
Return:
the intersection point
Return Type:
QPointF

AssociationItem.__findPointRegion

__findPointRegion(rect, posX, posY)

Private method to find out, which region of rectangle rect contains the point (PosX, PosY) and returns the region number.

rect (QRectF)
rectangle to calculate the region for
posX (float)
x position of point
posY (float)
y position of point
Return:
the calculated region number
West = Region 1
North = Region 2
East = Region 3
South = Region 4
NorthWest = On diagonal 2 between Region 1 and 2
NorthEast = On diagonal 1 between Region 2 and 3
SouthEast = On diagonal 2 between Region 3 and 4
SouthWest = On diagonal 1 between Region4 and 1
Center = On diagonal 1 and On diagonal 2 (the center)
Return Type:
AssociationPointRegion

AssociationItem.__findRectIntersectionPoint

__findRectIntersectionPoint(item, p1, p2)

Private method to find the intersection point of a line with a rectangle.

item (UMLItem)
item to check against
p1 (QPointF)
first point of the line
p2 (QPointF)
second point of the line
Return:
the intersection point
Return Type:
QPointF

AssociationItem.__mapRectFromItem

__mapRectFromItem(item)

Private method to map item's rectangle to this item's coordinate system.

item (QGraphicsRectItem)
reference to the item to be mapped
Return:
item's rectangle in local coordinates
Return Type:
QRectF

AssociationItem.__updateEndPoint

__updateEndPoint(region, isWidgetA)

Private method to update an endpoint.

region (AssociationPointRegion)
the region for the endpoint
isWidgetA (bool)
flag indicating update for itemA is done

AssociationItem.toDict

toDict()

Public method to collect data to be persisted.

Return:
dictionary containing data to be persisted
Return Type:
dict

AssociationItem.unassociate

unassociate()

Public method to unassociate from the widgets.

AssociationItem.widgetMoved

widgetMoved()

Public method to recalculate the association after a widget was moved.

Up


AssociationPointRegion

Class defining the regions for an association end point.

Derived from

enum.Enum

Class Attributes

CENTER
EAST
NORTH
NORTH_EAST
NORTH_WEST
NO_REGION
SOUTH
SOUTH_EAST
SOUTH_WEST
WEST

Class Methods

None

Methods

None

Static Methods

None
Up


AssociationType

Class defining the association types.

Derived from

enum.Enum

Class Attributes

GENERALISATION
IMPORTS
NORMAL

Class Methods

None

Methods

None

Static Methods

None
Up