diff --git a/src/Mod/Draft/DraftGui.py b/src/Mod/Draft/DraftGui.py index d25129460c..8868164d36 100644 --- a/src/Mod/Draft/DraftGui.py +++ b/src/Mod/Draft/DraftGui.py @@ -187,9 +187,11 @@ class DraftToolBar: self.fillmode = True self.mask = None self.alock = False - self.x = 0 - self.y = 0 - self.z = 0 + self.x = 0 # coord of the point as displayed in the task panel (global/local and relative/absolute) + self.y = 0 # idem + self.z = 0 # idem + self.new_point = FreeCAD.Vector() # global point value + self.last_point = FreeCAD.Vector() # idem self.lvalue = 0 self.pvalue = 90 self.avalue = 0 @@ -757,6 +759,8 @@ class DraftToolBar: self.x = 0 self.y = 0 self.z = 0 + self.new_point = FreeCAD.Vector() + self.last_point = FreeCAD.Vector() self.pointButton.show() if rel: self.isRelative.show() todo.delay(self.setFocus, None) @@ -967,12 +971,14 @@ class DraftToolBar: params.set_param("RelativeMode", bool(val)) self.relativeMode = bool(val) self.checkLocal() + self.displayPoint(self.new_point, self.get_last_point()) self.updateSnapper() def setGlobal(self, val): params.set_param("GlobalMode", bool(val)) self.globalMode = bool(val) self.checkLocal() + self.displayPoint(self.new_point, self.get_last_point()) self.updateSnapper() def setFill(self, val): @@ -1020,14 +1026,14 @@ class DraftToolBar: def validatePoint(self): """function for checking and sending numbers entered manually""" if self.sourceCmd or self.pointcallback: - if (self.labelRadius.isVisible()): + if self.labelRadius.isVisible(): try: rad = self.radius except (ValueError, AttributeError): print("debug: DraftGui.validatePoint: AttributeError") else: self.sourceCmd.numericRadius(rad) - elif (self.labelx.isVisible()): + elif self.labelx.isVisible(): try: numx = self.x numy = self.y @@ -1035,21 +1041,12 @@ class DraftToolBar: except (ValueError, AttributeError): print("debug: DraftGui.validatePoint: AttributeError") else: - num_vec = FreeCAD.Vector(numx, numy, numz) + delta = FreeCAD.Vector(numx, numy, numz) if self.pointcallback: - self.pointcallback(num_vec, self.globalMode, self.relativeMode) + self.pointcallback(delta, self.globalMode, self.relativeMode) else: - plane = WorkingPlane.get_working_plane(update=False) - ref_vec = FreeCAD.Vector(0, 0, 0) - if plane and not self.globalMode: - num_vec = plane.get_global_coords(num_vec, as_vector=True) - ref_vec = plane.get_global_coords(ref_vec) - if self.relativeMode and self.sourceCmd.node: - ref_vec = self.sourceCmd.node[-1] - - numx, numy, numz = num_vec + ref_vec - self.sourceCmd.numericInput(numx, numy, numz) - + self.new_point = self.get_new_point(delta) + self.sourceCmd.numericInput(*self.new_point) elif self.textValue.isVisible(): return False else: @@ -1111,33 +1108,34 @@ class DraftToolBar: txt = txt[0].upper() spec = False + self.last_point = self.get_last_point() # Most frequently used shortcuts first: if txt == _get_incmd_shortcut("Relative"): if self.isRelative.isVisible(): self.isRelative.setChecked(not self.isRelative.isChecked()) - self.relativeMode = self.isRelative.isChecked() + # setRelative takes care of rest spec = True elif txt == _get_incmd_shortcut("Global"): if self.isGlobal.isVisible(): self.isGlobal.setChecked(not self.isGlobal.isChecked()) - self.globalMode = self.isGlobal.isChecked() + # setGlobal takes care of rest spec = True elif txt == _get_incmd_shortcut("Length"): if self.lengthValue.isVisible(): self.constrain("angle") - self.displayPoint() + self.displayPoint(self.new_point, self.last_point) spec = True elif txt == _get_incmd_shortcut("RestrictX"): self.constrain("x") - self.displayPoint() + self.displayPoint(self.new_point, self.last_point) spec = True elif txt == _get_incmd_shortcut("RestrictY"): self.constrain("y") - self.displayPoint() + self.displayPoint(self.new_point, self.last_point) spec = True elif txt == _get_incmd_shortcut("RestrictZ"): self.constrain("z") - self.displayPoint() + self.displayPoint(self.new_point, self.last_point) spec = True elif txt == _get_incmd_shortcut("Copy"): if self.isCopy.isVisible(): @@ -1198,6 +1196,7 @@ class DraftToolBar: widget.setProperty("text",v) widget.setFocus() widget.selectAll() + self.updateSnapper() def updateSnapper(self): """updates the snapper track line if applicable""" @@ -1206,16 +1205,8 @@ class DraftToolBar: if hasattr(FreeCADGui,"Snapper") \ and FreeCADGui.Snapper.trackLine \ and FreeCADGui.Snapper.trackLine.Visible: - # code below matches portion of validatePoint - delta = FreeCAD.Vector(self.x, self.y, self.z) - plane = WorkingPlane.get_working_plane(update=False) - ref_vec = FreeCAD.Vector(0, 0, 0) - if plane and not self.globalMode: - delta = plane.get_global_coords(delta, as_vector=True) - ref_vec = plane.get_global_coords(ref_vec) - if self.relativeMode and self.sourceCmd.node: - ref_vec = self.sourceCmd.node[-1] - FreeCADGui.Snapper.trackLine.p2(delta + ref_vec) + point = self.get_new_point(FreeCAD.Vector(self.x, self.y, self.z)) + FreeCADGui.Snapper.trackLine.p2(point) def setMouseMode(self, mode=True): """Sets self.mouse True (default) or False and sets a timer @@ -1264,6 +1255,9 @@ class DraftToolBar: else: last = plane.position + self.new_point = FreeCAD.Vector(point) + self.last_point = FreeCAD.Vector(last) + if self.relativeMode: if self.globalMode: delta = point - last @@ -1288,13 +1282,6 @@ class DraftToolBar: self.lengthValue.setText(display_external(length,None,'Length')) #if not self.angleLock.isChecked(): self.angleValue.setText(display_external(phi,None,'Angle')) - if not mask: - # automask, phi is rounded to identify one of the below cases - phi = round(phi, Draft.precision()) - if phi in [0,180,-180]: - mask = "x" - elif phi in [90,270,-90,-270]: - mask = "y" # set masks if (mask == "x") or (self.mask == "x"): @@ -1509,6 +1496,7 @@ class DraftToolBar: self.mask = val if hasattr(FreeCADGui,"Snapper"): FreeCADGui.Snapper.mask = val + self.new_point = FreeCADGui.Snapper.constrain(self.new_point, self.get_last_point()) def changeXValue(self, d): if self.display_point_active: @@ -1572,6 +1560,7 @@ class DraftToolBar: def toggleAngle(self,b): self.alock = self.angleLock.isChecked() self.update_cartesian_coords() + self.updateSnapper() if self.alock: if not self.globalMode: plane = WorkingPlane.get_working_plane(update=False) @@ -1603,6 +1592,27 @@ class DraftToolBar: self.yValue.setText(display_external(self.y,None,'Length')) self.zValue.setText(display_external(self.z,None,'Length')) + def get_last_point(self): + """Get the last point in the GCS.""" + if hasattr(self.sourceCmd, "node") and self.sourceCmd.node: + return self.sourceCmd.node[-1] + return self.last_point + + def get_new_point(self, delta): + """Get the new point in the GCS. + + The delta vector (from the task panel) can be global/local + and relative/absolute. + """ + plane = WorkingPlane.get_working_plane(update=False) + base_point = FreeCAD.Vector() + if plane and not self.globalMode: + delta = plane.get_global_coords(delta, as_vector=True) + base_point = plane.position + if self.relativeMode: + base_point = self.get_last_point() + return base_point + delta + #--------------------------------------------------------------------------- # TaskView operations #--------------------------------------------------------------------------- @@ -1655,6 +1665,8 @@ class DraftToolBar: self.x = 0 self.y = 0 self.z = 0 + self.new_point = FreeCAD.Vector() + self.last_point = FreeCAD.Vector() self.lvalue = 0 self.pvalue = 90 self.avalue = 0