def test_line_merge_segment(diagram, undo_manager, event_manager): with Transaction(event_manager): line = diagram.create(LinePresentation) segment = Segment(line, diagram) segment.split((5, 5)) head_handle = line.head tail_handle = line.tail with Transaction(event_manager): segment = Segment(line, diagram) segment.merge_segment(0) assert len(line.handles()) == 2 assert line.head is head_handle assert line.tail is tail_handle undo_manager.undo_transaction() assert len(line.handles()) == 3 assert line.head is head_handle assert line.tail is tail_handle undo_manager.redo_transaction() assert len(line.handles()) == 2
def test_add_segment_to_line(canvas, connections): line = Line(connections) canvas.add(line) segment = Segment(line, canvas) assert 2 == len(line.handles()) segment.split((5, 5)) assert 3 == len(line.handles())
def get_handle_at_point(self, pos, split=True): view = self.view connection_v = view.hovered_item handle = None end_handles = connection_v.end_handles(include_waypoints=True) if len(end_handles) == 4: from_handle, from_handle_waypoint, to_handle_waypoint, to_handle = end_handles cur_pos = self.view.get_matrix_v2i(connection_v).transform_point( *pos) max_distance = connection_v.line_width / 2. distance_from_segment, _ = distance_line_point( from_handle.pos, from_handle_waypoint.pos, cur_pos) if distance_from_segment < max_distance: return connection_v, from_handle distance_to_segment, _ = distance_line_point( to_handle.pos, to_handle_waypoint.pos, cur_pos) if distance_to_segment < max_distance: return connection_v, to_handle if split: try: segment = Segment(self.item, self.view) except TypeError: pass else: handle = segment.split(pos) if not handle: connection_v, handle = super(SegmentHandleFinder, self).get_handle_at_point(pos) return connection_v, handle