From fdcb07003c3e3941fa05e3bc8f4ee9df002480bc Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 28 Jul 2011 10:28:57 -0400 Subject: [PATCH] snap lines to shape handles while drawing --- SketchWidget.py | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/SketchWidget.py b/SketchWidget.py index e81995b..f436cc1 100644 --- a/SketchWidget.py +++ b/SketchWidget.py @@ -376,16 +376,31 @@ class SketchWidget: self.cancel_drawing_shape() def do_line_left_click(self, x, y): - start = self.screenPtToPt((x, self.size[1] - y)) - previous_line = None + click_pt = self.screenPtToPt((x, self.size[1] - y)) + start = click_pt + start_pt_ref = None + if self.hover_snap_point is not None: + start = self.hover_snap_point[0].getPt(self.hover_snap_point[1]) + start_pt_ref = self.hover_snap_point if self.drawingShape is not None: + # end a currently drawing line start = self.drawingShape.getPt(1) # start at last snap point - previous_line = self.drawingShape + prev_line = self.drawingShape + if self.hover_snap_point is not None: + c = Connect(self.hover_snap_point[0], self.hover_snap_point[1], + self.drawingShape, 1) + self.drawingConstraints['c2'] = c + pt = self.hover_snap_point[0].getPt(self.hover_snap_point[1]) + self.drawingShape.setPt(1, pt) self.merge_in_drawing_shape() - self.drawingShape = Line(start[0], start[1], start[0], start[1]) - if previous_line is not None: - connect = Connect(previous_line, 1, self.drawingShape, 0) - self.drawingConstraints['c'] = connect + start = prev_line.getPt(1) + start_pt_ref = (prev_line, 1) + # begin a new line + self.drawingShape = Line( + start[0], start[1], click_pt[0], click_pt[1]) + if start_pt_ref is not None: + c = Connect(start_pt_ref[0], start_pt_ref[1], self.drawingShape, 0) + self.drawingConstraints['c1'] = c self.queue_redraw() def do_line_right_click(self, x, y):