| 197 | | WIDTH = 6.0 |
|---|
| 198 | | HEIGHT = 45.0 |
|---|
| 199 | | MARGIN = 10 |
|---|
| 200 | | |
|---|
| 201 | | def __init__(self, id=None): |
|---|
| 202 | | GroupBase.__init__(self) |
|---|
| 203 | | FDNode.__init__(self, id) |
|---|
| 204 | | |
|---|
| 205 | | self._join_spec = TextElement('value', '{ joinSpec = %s }', 'and') |
|---|
| 206 | | self.add(self._join_spec) |
|---|
| 207 | | |
|---|
| 208 | | for h in self.handles: |
|---|
| 209 | | h.props.movable = False |
|---|
| 210 | | h.props.visible = False |
|---|
| 211 | | self.handles[diacanvas.HANDLE_N].props.visible = True |
|---|
| 212 | | self.handles[diacanvas.HANDLE_S].props.visible = True |
|---|
| 213 | | self.handles[diacanvas.HANDLE_N].props.movable = True |
|---|
| 214 | | self.handles[diacanvas.HANDLE_S].props.movable = True |
|---|
| 215 | | |
|---|
| 216 | | |
|---|
| 217 | | def create_border(self): |
|---|
| 218 | | line = diacanvas.shape.Path() |
|---|
| 219 | | line.set_line_width(self.WIDTH) |
|---|
| 220 | | |
|---|
| 221 | | self.set(width = self.WIDTH, height = self.HEIGHT) |
|---|
| 222 | | return line |
|---|
| 223 | | |
|---|
| 224 | | |
|---|
| 225 | | def draw_border(self): |
|---|
| 226 | | """ |
|---|
| 227 | | Draw line between central handles. |
|---|
| 228 | | """ |
|---|
| 229 | | p1 = self.handles[diacanvas.HANDLE_N].get_pos_i() |
|---|
| 230 | | p2 = self.handles[diacanvas.HANDLE_S].get_pos_i() |
|---|
| 231 | | self._border.line((p1, p2)) |
|---|
| 232 | | |
|---|
| 233 | | |
|---|
| 234 | | def on_update(self, affine): |
|---|
| 235 | | """ |
|---|
| 236 | | Update fork/join node. |
|---|
| 237 | | |
|---|
| 238 | | If node is join node then update also join specification. |
|---|
| 239 | | """ |
|---|
| 240 | | FDNode.on_update(self, affine) |
|---|
| 241 | | |
|---|
| 242 | | w, h = self._join_spec.get_size() |
|---|
| 243 | | self._join_spec.update_label((self.width - w) / 2, |
|---|
| 244 | | -h - self.MARGIN) |
|---|
| 245 | | |
|---|
| 246 | | GroupBase.on_update(self, affine) |
|---|
| 247 | | |
|---|
| 248 | | |
|---|
| 249 | | def on_subject_notify(self, pspec, notifiers = ()): |
|---|
| 250 | | """ |
|---|
| 251 | | Detect changes of subject. |
|---|
| 252 | | |
|---|
| 253 | | If subject is join node, then set subject of join specification |
|---|
| 254 | | text element. |
|---|
| 255 | | """ |
|---|
| 256 | | FDNode.on_subject_notify(self, pspec, notifiers) |
|---|
| 257 | | if self.subject and isinstance(self.subject, UML.JoinNode): |
|---|
| 258 | | factory = resource(UML.ElementFactory) |
|---|
| 259 | | if not self.subject.joinSpec: |
|---|
| 260 | | self.subject.joinSpec = factory.create(UML.LiteralSpecification) |
|---|
| 261 | | self.subject.joinSpec.value = 'and' |
|---|
| 262 | | self._join_spec.subject = self.subject.joinSpec |
|---|
| 263 | | else: |
|---|
| 264 | | self._join_spec.subject = None |
|---|
| 265 | | self.request_update() |
|---|
| | 200 | def __init__(self, id = None, width = 6.0, height = 45.0): |
|---|
| | 201 | # GroupBase.__init__(self) |
|---|
| | 202 | FDNode.__init__(self, id, width, height) |
|---|
| | 203 | |
|---|
| | 204 | self._join_spec = 'join spec test' |
|---|
| | 205 | self._join_spec_x = 0 |
|---|
| | 206 | self._join_spec_y = 0 |
|---|
| | 207 | |
|---|
| | 208 | # for h in self.handles: |
|---|
| | 209 | # h.props.movable = False |
|---|
| | 210 | # h.props.visible = False |
|---|
| | 211 | # self.handles[diacanvas.HANDLE_N].props.visible = True |
|---|
| | 212 | # self.handles[diacanvas.HANDLE_S].props.visible = True |
|---|
| | 213 | # self.handles[diacanvas.HANDLE_N].props.movable = True |
|---|
| | 214 | # self.handles[diacanvas.HANDLE_S].props.movable = True |
|---|
| | 215 | |
|---|
| | 216 | def update(self, context): |
|---|
| | 217 | """ |
|---|
| | 218 | Update join specification position. |
|---|
| | 219 | """ |
|---|
| | 220 | self._join_spec_x, self._join_spec_y = get_text_point( |
|---|
| | 221 | text_extents(context.cairo, self._join_spec), |
|---|
| | 222 | self.width, self.height, |
|---|
| | 223 | (ALIGN_CENTER, ALIGN_TOP), |
|---|
| | 224 | (10, 0, 0, 0), |
|---|
| | 225 | True) |
|---|
| | 226 | |
|---|
| | 227 | |
|---|
| | 228 | def draw(self, context): |
|---|
| | 229 | """ |
|---|
| | 230 | Draw vertical line - symbol of fork and join nodes. Join |
|---|
| | 231 | specification is also drawn above the item. |
|---|
| | 232 | """ |
|---|
| | 233 | cr = context.cairo |
|---|
| | 234 | cr.set_line_width(self.width) |
|---|
| | 235 | cr.move_to(0, 0) |
|---|
| | 236 | cr.line_to(0, self.height) |
|---|
| | 237 | cr.move_to(self.name_x, self.name_y) |
|---|
| | 238 | |
|---|
| | 239 | cr.move_to(self._join_spec_x, self._join_spec_y) |
|---|
| | 240 | cr.show_text(self._join_spec) |
|---|
| | 241 | |
|---|
| | 242 | cr.stroke() |
|---|
| | 243 | super(ForkNodeItem, self).draw(context) |
|---|
| | 244 | |
|---|
| | 245 | |
|---|
| | 246 | ### def on_update(self, affine): |
|---|
| | 247 | ### """ |
|---|
| | 248 | ### Update fork/join node. |
|---|
| | 249 | ### |
|---|
| | 250 | ### If node is join node then update also join specification. |
|---|
| | 251 | ### """ |
|---|
| | 252 | ### FDNode.on_update(self, affine) |
|---|
| | 253 | ### |
|---|
| | 254 | ### w, h = self._join_spec.get_size() |
|---|
| | 255 | ### self._join_spec.update_label((self.width - w) / 2, |
|---|
| | 256 | ### -h - self.MARGIN) |
|---|
| | 257 | ### |
|---|
| | 258 | ### GroupBase.on_update(self, affine) |
|---|
| | 259 | ### |
|---|
| | 260 | ### |
|---|
| | 261 | ### def on_subject_notify(self, pspec, notifiers = ()): |
|---|
| | 262 | ### """ |
|---|
| | 263 | ### Detect changes of subject. |
|---|
| | 264 | ### |
|---|
| | 265 | ### If subject is join node, then set subject of join specification |
|---|
| | 266 | ### text element. |
|---|
| | 267 | ### """ |
|---|
| | 268 | ### FDNode.on_subject_notify(self, pspec, notifiers) |
|---|
| | 269 | ### if self.subject and isinstance(self.subject, UML.JoinNode): |
|---|
| | 270 | ### factory = resource(UML.ElementFactory) |
|---|
| | 271 | ### if not self.subject.joinSpec: |
|---|
| | 272 | ### self.subject.joinSpec = factory.create(UML.LiteralSpecification) |
|---|
| | 273 | ### self.subject.joinSpec.value = 'and' |
|---|
| | 274 | ### self._join_spec.subject = self.subject.joinSpec |
|---|
| | 275 | ### else: |
|---|
| | 276 | ### self._join_spec.subject = None |
|---|
| | 277 | ### self.request_update() |
|---|