73 |
73 |
74 self.setFlag(QGraphicsItem.ItemIsMovable, False) |
74 self.setFlag(QGraphicsItem.ItemIsMovable, False) |
75 self.setFlag(QGraphicsItem.ItemIsSelectable, False) |
75 self.setFlag(QGraphicsItem.ItemIsSelectable, False) |
76 |
76 |
77 if topToBottom: |
77 if topToBottom: |
78 self.calculateEndingPoints = self.__calculateEndingPoints_topToBottom |
78 self.calculateEndingPoints = \ |
|
79 self.__calculateEndingPoints_topToBottom |
79 else: |
80 else: |
80 ## self.calculateEndingPoints = self.__calculateEndingPoints_center |
81 ## self.calculateEndingPoints = self.__calculateEndingPoints_center |
81 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle |
82 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle |
82 |
83 |
83 self.itemA = itemA |
84 self.itemA = itemA |
93 self.itemA.addAssociation(self) |
94 self.itemA.addAssociation(self) |
94 self.itemB.addAssociation(self) |
95 self.itemB.addAssociation(self) |
95 |
96 |
96 def __mapRectFromItem(self, item): |
97 def __mapRectFromItem(self, item): |
97 """ |
98 """ |
98 Private method to map item's rectangle to this item's coordinate system. |
99 Private method to map item's rectangle to this item's coordinate |
|
100 system. |
99 |
101 |
100 @param item reference to the item to be mapped (QGraphicsRectItem) |
102 @param item reference to the item to be mapped (QGraphicsRectItem) |
101 @return item's rectangle in local coordinates (QRectF) |
103 @return item's rectangle in local coordinates (QRectF) |
102 """ |
104 """ |
103 rect = item.rect() |
105 rect = item.rect() |
156 if startP.x() != -1 and startP.y() != -1 and \ |
158 if startP.x() != -1 and startP.y() != -1 and \ |
157 endP.x() != -1 and endP.y() != -1: |
159 endP.x() != -1 and endP.y() != -1: |
158 self.setPoints(startP.x(), startP.y(), endP.x(), endP.y()) |
160 self.setPoints(startP.x(), startP.y(), endP.x(), endP.y()) |
159 |
161 |
160 def __calculateEndingPoints_rectangle(self): |
162 def __calculateEndingPoints_rectangle(self): |
161 """ |
163 r""" |
162 Private method to calculate the ending points of the association item. |
164 Private method to calculate the ending points of the association item. |
163 |
165 |
164 The ending points are calculated by the following method. |
166 The ending points are calculated by the following method. |
165 |
167 |
166 For each item the diagram is divided in four Regions by its diagonals |
168 For each item the diagram is divided in four Regions by its diagonals |
185 To calculate the start point we have to find out in which |
187 To calculate the start point we have to find out in which |
186 region (defined by itemA's diagonals) is itemB's TopLeft corner |
188 region (defined by itemA's diagonals) is itemB's TopLeft corner |
187 (lets call it region M). After that the start point will be |
189 (lets call it region M). After that the start point will be |
188 the middle point of rectangle's side contained in region M. |
190 the middle point of rectangle's side contained in region M. |
189 |
191 |
190 To calculate the end point we repeat the above but in the opposite direction |
192 To calculate the end point we repeat the above but in the opposite |
191 (from itemB to itemA) |
193 direction (from itemB to itemA) |
192 """ |
194 """ |
193 if self.itemA is None or self.itemB is None: |
195 if self.itemA is None or self.itemB is None: |
194 return |
196 return |
195 |
197 |
196 self.prepareGeometryChange() |
198 self.prepareGeometryChange() |
237 |
239 |
238 self.__updateEndPoint(self.regionB, False) |
240 self.__updateEndPoint(self.regionB, False) |
239 |
241 |
240 def __findPointRegion(self, rect, posX, posY): |
242 def __findPointRegion(self, rect, posX, posY): |
241 """ |
243 """ |
242 Private method to find out, which region of rectangle rect contains the point |
244 Private method to find out, which region of rectangle rect contains |
243 (PosX, PosY) and returns the region number. |
245 the point (PosX, PosY) and returns the region number. |
244 |
246 |
245 @param rect rectangle to calculate the region for (QRectF) |
247 @param rect rectangle to calculate the region for (QRectF) |
246 @param posX x position of point (float) |
248 @param posX x position of point (float) |
247 @param posY y position of point (float) |
249 @param posY y position of point (float) |
248 @return the calculated region number<br /> |
250 @return the calculated region number<br /> |
350 else: |
352 else: |
351 self.setEndPoint(px, py) |
353 self.setEndPoint(px, py) |
352 |
354 |
353 def __findRectIntersectionPoint(self, item, p1, p2): |
355 def __findRectIntersectionPoint(self, item, p1, p2): |
354 """ |
356 """ |
355 Private method to find the intersetion point of a line with a rectangle. |
357 Private method to find the intersetion point of a line with a |
|
358 rectangle. |
356 |
359 |
357 @param item item to check against |
360 @param item item to check against |
358 @param p1 first point of the line (QPointF) |
361 @param p1 first point of the line (QPointF) |
359 @param p2 second point of the line (QPointF) |
362 @param p2 second point of the line (QPointF) |
360 @return the intersection point (QPointF) |
363 @return the intersection point (QPointF) |
479 |
482 |
480 pt.setY((b2 - b1) / (slope1 - slope2)) |
483 pt.setY((b2 - b1) / (slope1 - slope2)) |
481 pt.setX(slope1 * pt.y() + b1) |
484 pt.setX(slope1 * pt.y() + b1) |
482 # the intersection point must be inside the segment (x1, y1) (x2, y2) |
485 # the intersection point must be inside the segment (x1, y1) (x2, y2) |
483 if x2 >= x1 and y2 >= y1: |
486 if x2 >= x1 and y2 >= y1: |
484 if not ((x1 <= pt.y() and pt.y() <= x2) and (y1 <= pt.x() and pt.x() <= y2)): |
487 if not ((x1 <= pt.y() and pt.y() <= x2) and |
|
488 (y1 <= pt.x() and pt.x() <= y2)): |
485 pt.setX(-1.0) |
489 pt.setX(-1.0) |
486 pt.setY(-1.0) |
490 pt.setY(-1.0) |
487 elif x2 < x1 and y2 >= y1: |
491 elif x2 < x1 and y2 >= y1: |
488 if not ((x2 <= pt.y() and pt.y() <= x1) and (y1 <= pt.x() and pt.x() <= y2)): |
492 if not ((x2 <= pt.y() and pt.y() <= x1) and |
|
493 (y1 <= pt.x() and pt.x() <= y2)): |
489 pt.setX(-1.0) |
494 pt.setX(-1.0) |
490 pt.setY(-1.0) |
495 pt.setY(-1.0) |
491 elif x2 >= x1 and y2 < y1: |
496 elif x2 >= x1 and y2 < y1: |
492 if not ((x1 <= pt.y() and pt.y() <= x2) and (y2 <= pt.x() and pt.x() <= y1)): |
497 if not ((x1 <= pt.y() and pt.y() <= x2) and |
|
498 (y2 <= pt.x() and pt.x() <= y1)): |
493 pt.setX(-1.0) |
499 pt.setX(-1.0) |
494 pt.setY(-1.0) |
500 pt.setY(-1.0) |
495 else: |
501 else: |
496 if not ((x2 <= pt.y() and pt.y() <= x1) and (y2 <= pt.x() and pt.x() <= y1)): |
502 if not ((x2 <= pt.y() and pt.y() <= x1) and |
|
503 (y2 <= pt.x() and pt.x() <= y1)): |
497 pt.setX(-1.0) |
504 pt.setX(-1.0) |
498 pt.setY(-1.0) |
505 pt.setY(-1.0) |
499 |
506 |
500 return pt |
507 return pt |
501 |
508 |