def test_iconnect(self): """ Test basic glue functionality using CommentItem and CommentLine items. """ element_factory = Application.get_service('element_factory') diagram = element_factory.create(UML.Diagram) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) #assert comment.height == 50 #assert comment.width == 100 actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, 'View should be available here' tool = ConnectHandleTool(view) # select handle: handle = line.handles()[-1] tool._grabbed_item = line tool._grabbed_handle = handle # Should glue to (238, 248) handle.pos = 245, 248 item = tool.glue(line, handle, (245, 248)) self.assertTrue(item is not None) self.assertEquals((238, 248), view.canvas.get_matrix_i2c(line).transform_point( handle.x, handle.y)) handle.pos = 245, 248 tool.connect(line, handle, (245, 248)) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo.constraint is not None) self.assertTrue(cinfo.connected is actor, cinfo.connected) self.assertEquals( (238, 248), view.get_matrix_i2v(line).transform_point(handle.x, handle.y)) Connector(line, handle).disconnect() #tool.disconnect(line, handle) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def test_iconnect(self): """ Test basic glue functionality using CommentItem and CommentLine items. """ element_factory = Application.get_service('element_factory') diagram = element_factory.create(UML.Diagram) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) #assert comment.height == 50 #assert comment.width == 100 actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, 'View should be available here' tool = ConnectHandleTool(view) # select handle: handle = line.handles()[-1] tool._grabbed_item = line tool._grabbed_handle = handle # Should glue to (238, 248) handle.pos = 245, 248 item = tool.glue(line, handle, (245, 248)) self.assertTrue(item is not None) self.assertEquals((238, 248), view.canvas.get_matrix_i2c(line).transform_point(handle.x, handle.y)) handle.pos = 245, 248 tool.connect(line, handle, (245, 248)) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo.constraint is not None) self.assertTrue(cinfo.connected is actor, cinfo.connected) self.assertEquals((238, 248), view.get_matrix_i2v(line).transform_point(handle.x, handle.y)) Connector(line, handle).disconnect() #tool.disconnect(line, handle) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def test_iconnect(self): """ Test basic glue functionality using CommentItem and CommentLine items. """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) self.event_manager.handle(DiagramShow(diagram)) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, "View should be available here" comment_bb = view.get_item_bounding_box(comment) # select handle: handle = line.handles()[-1] tool = ConnectHandleTool(view=view) tool.grab_handle(line, handle) handle.pos = (comment_bb.x, comment_bb.y) item = tool.glue(line, handle, handle.pos) assert item is not None tool.connect(line, handle, handle.pos) cinfo = diagram.canvas.get_connection(handle) assert cinfo.constraint is not None assert cinfo.connected is actor, cinfo.connected Connector(line, handle).disconnect() cinfo = diagram.canvas.get_connection(handle) assert cinfo is None
def test_iconnect(self): """ Test basic glue functionality using CommentItem and CommentLine items. """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) self.component_registry.handle(DiagramShow(diagram)) comment = diagram.create( CommentItem, subject=element_factory.create(UML.Comment) ) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, "View should be available here" comment_bb = view.get_item_bounding_box(comment) # select handle: handle = line.handles()[-1] tool = ConnectHandleTool(view=view) tool.grab_handle(line, handle) handle.pos = (comment_bb.x, comment_bb.y) item = tool.glue(line, handle, handle.pos) self.assertTrue(item is not None) tool.connect(line, handle, handle.pos) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo.constraint is not None) self.assertTrue(cinfo.connected is actor, cinfo.connected) Connector(line, handle).disconnect() cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def test_connect_comment_and_actor(self): """Test connect/disconnect on comment and actor using comment-line. """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) self.event_manager.handle(DiagramShow(diagram)) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, "View should be available here" tool = ConnectHandleTool(view) # Connect one end to the Comment: handle = line.handles()[0] tool.grab_handle(line, handle) handle.pos = (0, 0) sink = tool.glue(line, handle, handle.pos) assert sink is not None assert sink.item is comment tool.connect(line, handle, handle.pos) cinfo = diagram.canvas.get_connection(handle) assert cinfo is not None, None assert cinfo.item is line assert cinfo.connected is comment # Connect the other end to the Actor: actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) handle = line.handles()[-1] tool.grab_handle(line, handle) handle.pos = (0, 0) sink = tool.glue(line, handle, handle.pos) assert sink, f"No sink at {handle.pos}" assert sink.item is actor tool.connect(line, handle, handle.pos) cinfo = view.canvas.get_connection(handle) assert cinfo.item is line assert cinfo.connected is actor # Try to connect far away from any item will only do a full disconnect self.assertEqual(len(comment.subject.annotatedElement), 1, comment.subject.annotatedElement) assert actor.subject in comment.subject.annotatedElement sink = tool.glue(line, handle, (500, 500)) assert sink is None, sink tool.connect(line, handle, (500, 500)) cinfo = view.canvas.get_connection(handle) assert cinfo is None
def test_iconnect_2(self): """Test connect/disconnect on comment and actor using comment-line. """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) self.component_registry.handle(DiagramShow(diagram)) comment = diagram.create( CommentItem, subject=element_factory.create(UML.Comment) ) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, "View should be available here" tool = ConnectHandleTool(view) # Connect one end to the Comment: handle = line.handles()[0] tool.grab_handle(line, handle) comment_bb = view.get_item_bounding_box(comment) handle.pos = (comment_bb.x1, comment_bb.y1) sink = tool.glue(line, handle, handle.pos) assert sink is not None assert sink.item is comment tool.connect(line, handle, handle.pos) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is not None, None) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is comment) # Connect the other end to the Actor: handle = line.handles()[-1] tool.grab_handle(line, handle) actor_bb = view.get_item_bounding_box(actor) handle.pos = actor_bb.x1, actor_bb.y1 sink = tool.glue(line, handle, handle.pos) self.assertTrue(sink.item is actor) tool.connect(line, handle, handle.pos) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is actor) # Try to connect far away from any item will only do a full disconnect self.assertEqual( len(comment.subject.annotatedElement), 1, comment.subject.annotatedElement ) self.assertTrue(actor.subject in comment.subject.annotatedElement) sink = tool.glue(line, handle, (500, 500)) self.assertTrue(sink is None, sink) tool.connect(line, handle, (500, 500)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def test_iconnect_2(self): """Test connect/disconnect on comment and actor using comment-line. """ element_factory = Application.get_service("element_factory") diagram = element_factory.create(UML.Diagram) self.component_registry.handle(DiagramShow(diagram)) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, "View should be available here" tool = ConnectHandleTool(view) # Connect one end to the Comment: handle = line.handles()[0] tool.grab_handle(line, handle) comment_bb = view.get_item_bounding_box(comment) handle.pos = (comment_bb.x1, comment_bb.y1) sink = tool.glue(line, handle, handle.pos) assert sink is not None assert sink.item is comment tool.connect(line, handle, handle.pos) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is not None, None) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is comment) # Connect the other end to the Actor: handle = line.handles()[-1] tool.grab_handle(line, handle) actor_bb = view.get_item_bounding_box(actor) handle.pos = actor_bb.x1, actor_bb.y1 sink = tool.glue(line, handle, handle.pos) self.assertTrue(sink.item is actor) tool.connect(line, handle, handle.pos) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is actor) # Try to connect far away from any item will only do a full disconnect self.assertEqual(len(comment.subject.annotatedElement), 1, comment.subject.annotatedElement) self.assertTrue(actor.subject in comment.subject.annotatedElement) sink = tool.glue(line, handle, (500, 500)) self.assertTrue(sink is None, sink) tool.connect(line, handle, (500, 500)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def test_iconnect_2(self): """Test connect/disconnect on comment and actor using comment-line. """ element_factory = Application.get_service('element_factory') diagram = element_factory.create(UML.Diagram) #self.main_window.show_diagram(diagram) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, 'View should be available here' tool = ConnectHandleTool(view) # select handle: handle = line.handles()[0] tool.grab_handle(line, handle) # Connect one end to the Comment #handle.pos = view.get_matrix_v2i(line).transform_point(45, 48) sink = tool.glue(line, handle, (0, 0)) assert sink is not None assert sink.item is comment tool.connect(line, handle, (0, 0)) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is not None, None) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is comment) pos = view.get_matrix_i2v(line).transform_point(handle.x, handle.y) self.assertAlmostEquals(0, pos[0], 0.00001) self.assertAlmostEquals(0, pos[1], 0.00001) # Connect the other end to the actor: handle = line.handles()[-1] tool.grab_handle(line, handle) handle.pos = 140, 150 sink = tool.glue(line, handle, (200, 200)) self.assertTrue(sink.item is actor) tool.connect(line, handle, (200, 200)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is actor) self.assertEquals( (200, 200), view.get_matrix_i2v(line).transform_point(handle.x, handle.y)) # Try to connect far away from any item will only do a full disconnect self.assertEquals(len(comment.subject.annotatedElement), 1, comment.subject.annotatedElement) self.assertTrue(actor.subject in comment.subject.annotatedElement) sink = tool.glue(line, handle, (500, 500)) self.assertTrue(sink is None, sink) tool.connect(line, handle, (500, 500)) self.assertEquals((200, 200), view.canvas.get_matrix_i2c(line).transform_point( handle.x, handle.y)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo is None)
def test_iconnect_2(self): """Test connect/disconnect on comment and actor using comment-line. """ element_factory = Application.get_service('element_factory') diagram = element_factory.create(UML.Diagram) #self.main_window.show_diagram(diagram) comment = diagram.create(CommentItem, subject=element_factory.create(UML.Comment)) actor = diagram.create(ActorItem, subject=element_factory.create(UML.Actor)) actor.matrix.translate(200, 200) diagram.canvas.update_matrix(actor) line = diagram.create(CommentLineItem) view = self.get_diagram_view(diagram) assert view, 'View should be available here' tool = ConnectHandleTool(view) # select handle: handle = line.handles()[0] tool.grab_handle(line, handle) # Connect one end to the Comment #handle.pos = view.get_matrix_v2i(line).transform_point(45, 48) sink = tool.glue(line, handle, (0, 0)) assert sink is not None assert sink.item is comment tool.connect(line, handle, (0, 0)) cinfo = diagram.canvas.get_connection(handle) self.assertTrue(cinfo is not None, None) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is comment) pos = view.get_matrix_i2v(line).transform_point(handle.x, handle.y) self.assertAlmostEquals(0, pos[0], 0.00001) self.assertAlmostEquals(0, pos[1], 0.00001) # Connect the other end to the actor: handle = line.handles()[-1] tool.grab_handle(line, handle) handle.pos = 140, 150 sink = tool.glue(line, handle, (200, 200)) self.assertTrue(sink.item is actor) tool.connect(line, handle, (200, 200)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo.item is line) self.assertTrue(cinfo.connected is actor) self.assertEquals((200, 200), view.get_matrix_i2v(line).transform_point(handle.x, handle.y)) # Try to connect far away from any item will only do a full disconnect self.assertEquals(len(comment.subject.annotatedElement), 1, comment.subject.annotatedElement) self.assertTrue(actor.subject in comment.subject.annotatedElement) sink = tool.glue(line, handle, (500, 500)) self.assertTrue(sink is None, sink) tool.connect(line, handle, (500, 500)) self.assertEquals((200, 200), view.canvas.get_matrix_i2c(line).transform_point(handle.x, handle.y)) cinfo = view.canvas.get_connection(handle) self.assertTrue(cinfo is None)