示例#1
0
 def unlink(self):
     canvas = self.canvas
     c1 = canvas.get_connection(self.head)
     c2 = canvas.get_connection(self.tail)
     if c1 and c2:
         adapter = IConnect(c1.connected, self)
         adapter.disconnect(self.head)
     super(CommentLineItem, self).unlink()
示例#2
0
 def disconnect_subject(self, handle):
     super().disconnect_subject(handle)
     line = self.line
     opposite = line.opposite(handle)
     otc = self.get_connected(opposite)
     if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
         adapter = IConnect(otc, line)
         adapter.decombine_nodes()
示例#3
0
    def unlink(self):
        assert self.canvas

        canvas = self.canvas
        c1 = canvas.get_connection(self.head)
        c2 = canvas.get_connection(self.tail)
        if c1 and c2:
            adapter = IConnect(c1.connected, self)
            adapter.disconnect(self.head)
        super().unlink()
示例#4
0
    def allow(self, line, handle, item, port=None):
        """
        Glue line's handle to an item.

        If port is not provided, then first port is used.
        """
        if port is None and len(item.ports()) > 0:
            port = item.ports()[0]

        adapter = IConnect(item, line)
        return adapter.allow(handle, port)
示例#5
0
    def __call__(self):
        handle = self.handle
        item = self.item
        canvas = self.item.canvas
        cinfo = canvas.get_connection(handle)

        if self.disable:
            log.debug(f"Not disconnecting {item}.{handle} (disabled)")
        else:
            log.debug(f"Disconnecting {item}.{handle}")
            if cinfo:
                adapter = IConnect(cinfo.connected, item)
                adapter.disconnect(handle)
示例#6
0
    def __call__(self):
        handle = self.handle
        item = self.item
        canvas = self.item.canvas
        cinfo = canvas.get_connection(handle)

        if self.disable:
            log.debug("Not disconnecting %s.%s (disabled)" % (item, handle))
        else:
            log.debug("Disconnecting %s.%s" % (item, handle))
            if cinfo:
                adapter = IConnect(cinfo.connected, item)
                adapter.disconnect(handle)
示例#7
0
    def connect_subject(self, handle):
        line = self.line

        # TODO: connect opposite side again (in case it's a join/fork or
        #       decision/merge node)
        c1 = self.get_connected(line.head)
        c2 = self.get_connected(line.tail)
        if isinstance(c1, ObjectNodeItem) or isinstance(c2, ObjectNodeItem):
            relation: UML.ActivityEdge = self.relationship_or_new(
                UML.ObjectFlow, UML.ObjectFlow.source, UML.ObjectFlow.target)
        else:
            relation = self.relationship_or_new(UML.ControlFlow,
                                                UML.ControlFlow.source,
                                                UML.ControlFlow.target)
        line.subject = relation
        opposite = line.opposite(handle)
        otc = self.get_connected(opposite)
        if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
            adapter = IConnect(otc, line)
            adapter.combine_nodes()
示例#8
0
    def connect(self, sink):
        """
        Create connection at handle level and at model level.
        """
        handle = self.handle
        item = self.item
        cinfo = item.canvas.get_connection(handle)

        try:
            callback = DisconnectHandle(self.item, self.handle)
            if cinfo and cinfo.connected is sink.item:
                # reconnect only constraint - leave model intact
                log.debug("performing reconnect constraint")
                constraint = sink.port.constraint(item.canvas, item, handle,
                                                  sink.item)
                item.canvas.reconnect_item(item, handle, constraint=constraint)
            elif cinfo:
                # first disconnect but disable disconnection handle as
                # reconnection is going to happen
                adapter = IConnect(sink.item, item)
                try:
                    connect = adapter.reconnect
                except AttributeError:
                    connect = adapter.connect
                else:
                    cinfo.callback.disable = True
                self.disconnect()

                # new connection
                self.connect_handle(sink, callback=callback)

                # adapter requires both ends to be connected.
                connect(handle, sink.port)
            else:
                # new connection
                adapter = IConnect(sink.item, item)
                self.connect_handle(sink, callback=callback)
                adapter.connect(handle, sink.port)
        except Exception as e:
            log.error("Error during connect", exc_info=True)
示例#9
0
def test_query(comment):
    assert IConnect(comment, commentline)
示例#10
0
 def allow(self, sink):
     adapter = IConnect(sink.item, self.item)
     return adapter and adapter.allow(self.handle, sink.port)
示例#11
0
        otc = self.get_connected(opposite)
        if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
            adapter = IConnect(otc, line)
            adapter.combine_nodes()

    def disconnect_subject(self, handle):
        super().disconnect_subject(handle)
        line = self.line
        opposite = line.opposite(handle)
        otc = self.get_connected(opposite)
        if opposite and isinstance(otc, (ForkNodeItem, DecisionNodeItem)):
            adapter = IConnect(otc, line)
            adapter.decombine_nodes()


IConnect.register(ActionItem, FlowItem)(FlowConnect)
IConnect.register(ActivityNodeItem, FlowItem)(FlowConnect)
IConnect.register(ObjectNodeItem, FlowItem)(FlowConnect)
IConnect.register(SendSignalActionItem, FlowItem)(FlowConnect)
IConnect.register(AcceptEventActionItem, FlowItem)(FlowConnect)


class FlowForkDecisionNodeConnect(FlowConnect):
    """
    Abstract class with common behaviour for Fork/Join node and
    Decision/Merge node.
    """

    element: Union[ForkNodeItem, DecisionNodeItem]
    fork_node_cls: Type[UML.ControlNode]
    join_node_cls: Type[UML.ControlNode]
示例#12
0
    def _create_attribute(self, clazz, attr):
        static = False
        many = False
        if "static" in attr.attrtype:
            static = True
        if "many" in attr.attrtype:
            many = True
        compositescreated = self.parser.GetCompositeClassesForAttr(
            attr.attrname, clazz)
        tail_type = None
        if compositescreated:
            tail_type, tail_type_item = self._find_class_by_name(
                compositescreated[0])

        if tail_type:
            # Create an association:
            # print "%s %s <@>----> %s" % (attr.attrname, static, str(compositescreated))
            # The property on the tail of the association (tail_end) is owned
            # by the class connected on the head_end (head_type)
            head_type = clazz.gaphor_class
            head_type_item = clazz.gaphor_class_item

            # relation = self.element_factory.create(UML.Association)
            # head_end = self.element_factory.create(UML.Property)
            # head_end.lowerValue = self.element_factory.create(UML.LiteralSpecification)
            # tail_end = self.element_factory.create(UML.Property)
            # tail_end.name = attr.attrname
            # tail_end.visibility = self._visibility(attr.attrname)
            # tail_end.aggregation = 'composite'
            # tail_end.lowerValue = self.element_factory.create(UML.LiteralSpecification)
            # relation.package = self.diagram.namespace
            # relation.memberEnd = head_end
            # relation.memberEnd = tail_end
            # head_end.type = head_type
            # tail_end.type = tail_type
            # head_type.ownedAttribute = tail_end
            # tail_type.ownedAttribute = head_end

            # Now the subject
            # association.subject = relation
            # association.head_end.subject = head_end
            # association.tail_end.subject = tail_end

            # Create the diagram item:
            association = self.diagram.create(AssociationItem)

            adapter = IConnect(head_type_item, association)
            assert adapter
            handle = association.handles()[0]
            adapter.connect(handle)

            adapter = IConnect(tail_type_item, association)
            assert adapter
            handle = association.handles()[-1]
            adapter.connect(handle)

            # Apply attribute information to the association (ends)
            association.head_end.navigability = False
            tail_prop = association.tail_end.subject
            tail_prop.name = attr.attrname
            tail_prop.visibility = self._visibility(attr.attrname)
            tail_prop.aggregation = "composite"
        else:
            # Create a simple attribute:
            # print "%s %s" % (attr.attrname, static)
            prop = self.element_factory.create(UML.Property)
            prop.name = attr.attrname
            prop.visibility = self._visibility(attr.attrname)
            prop.isStatic = static
            clazz.gaphor_class.ownedAttribute = prop
        # print many
        import pprint

        pprint.pprint(attr)
示例#13
0
 def test_query(self):
     assert IConnect(self.comment, self.commentline)