def test_iconnect(event_manager, element_factory, diagrams): """Test basic glue functionality using CommentItem and CommentLine items.""" diagram = element_factory.create(UML.Diagram) event_manager.handle(DiagramOpened(diagram)) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) line = diagram.create(CommentLineItem) view = current_diagram_view(diagrams) assert view, "View should be available here" # select handle: handle = line.handles()[-1] move = HandleMove(line, handle, view) handle.pos = (0, 0) item = move.glue(handle.pos) assert item is not None move.connect(handle.pos) cinfo = diagram.connections.get_connection(handle) assert cinfo.constraint is not None assert cinfo.connected is comment, cinfo.connected ConnectorAspect(line, handle, diagram.connections).disconnect() cinfo = diagram.connections.get_connection(handle) assert cinfo is None
def test_connect(diagram, comment, commentline, connections): sink = ConnectionSink(comment) aspect = ConnectorAspect(commentline, commentline.handles()[0], connections) aspect.connect(sink) cinfo = diagram.connections.get_connection(commentline.handles()[0]) assert cinfo, cinfo
def test_allow(commentline, comment, connections): aspect = ConnectorAspect(commentline, commentline.handles()[0], connections) assert aspect.item is commentline assert aspect.handle is commentline.handles()[0] sink = ConnectionSink(comment) assert aspect.allow(sink)
def revert(self, target): # Reverse only the diagram level connection. # Associations have their own handlers connections = target.diagram.connections handle = target.handles()[self.handle_index] connector = ConnectorAspect(target, handle, connections) cinfo = connections.get_connection(handle) if cinfo: cinfo.callback.disable = True connector.disconnect()
def postload_connect(item: gaphas.Item, handle: gaphas.Handle, target: gaphas.Item): """Helper function: when loading a model, handles should be connected as part of the `postload` step. This function finds a suitable spot on the `target` item to connect the handle to. """ connector = ConnectorAspect(item, handle, item.diagram.connections) sink = _get_sink(item, handle, target) connector.connect(sink)
def connect(self, line, handle, item): """Connect line's handle to an item.""" diagram = line.diagram assert diagram is item.diagram sink = ConnectionSink(item, distance=1e4) connector = ConnectorAspect(line, handle, diagram.connections) connector.connect(sink) cinfo = diagram.connections.get_connection(handle) assert cinfo.connected is item assert cinfo.port
def revert(self, target): # Reverse only the diagram level connection. # Associations have their own handlers connections = target.diagram.connections assert connections connected = target.diagram.lookup(self.connected.id) sink = ConnectionSink(connected) sink.port = connected.ports()[self.port_index] handle = target.handles()[self.handle_index] connector = ConnectorAspect(target, handle, connections) connector.connect_handle(sink) target.handle(ItemConnected(target, handle, sink.item, sink.port))
def connect(line, handle, item, port=None): """Connect line's handle to an item. If port is not provided, then first port is used. """ diagram = line.diagram connector = ConnectorAspect(line, handle, diagram.connections) sink = ConnectionSink(item, distance=1e4) connector.connect(sink) cinfo = diagram.connections.get_connection(handle) assert cinfo.connected is item assert cinfo.port
def connect(line, handle, item, port=None): """Connect line's handle to an item. If port is not provided, then first port is used. """ diagram = line.diagram if port is None and len(item.ports()) > 0: port = item.ports()[0] sink = ConnectionSink(item, port) connector = ConnectorAspect(line, handle, diagram.connections) connector.connect(sink) cinfo = diagram.connections.get_connection(handle) assert cinfo.connected is item assert cinfo.port is port
def test_aspect_type(commentline, connections): aspect = ConnectorAspect(commentline, commentline.handles()[0], connections) assert isinstance(aspect, PresentationConnector)