Draft: Reduce occurrences of App.DraftWorkingPlane 2 (#10390)

This commit is contained in:
Roy-043
2023-08-28 10:17:58 +02:00
committed by GitHub
parent b8f0de8dd3
commit 36fdbdd6d9
3 changed files with 26 additions and 34 deletions

View File

@@ -69,7 +69,7 @@ class Offset(gui_base_original.Modifier):
def Activated(self):
"""Execute when the command is called."""
self.running = False
super(Offset, self).Activated(name="Offset")
super().Activated(name="Offset")
self.ghost = None
self.linetrack = None
self.arctrack = None
@@ -160,7 +160,6 @@ class Offset(gui_base_original.Modifier):
from the 3D view.
"""
import DraftGeomUtils
plane = App.DraftWorkingPlane
if arg["Type"] == "SoKeyboardEvent":
if arg["Key"] == "ESCAPE":
@@ -183,8 +182,8 @@ class Offset(gui_base_original.Modifier):
self.point)
v2 = DraftGeomUtils.getTangent(self.shape.Edges[dist[1]],
self.point)
a = -DraftVecUtils.angle(v1, v2, plane.axis)
self.dvec = DraftVecUtils.rotate(d, a, plane.axis)
a = -DraftVecUtils.angle(v1, v2, self.wp.axis)
self.dvec = DraftVecUtils.rotate(d, a, self.wp.axis)
occmode = self.ui.occOffset.isChecked()
self.param.SetBool("Offset_OCC", occmode)
_wire = DraftGeomUtils.offsetWire(self.shape,
@@ -198,8 +197,8 @@ class Offset(gui_base_original.Modifier):
self.npts = []
for p in self.sel.Points:
currtan = DraftGeomUtils.getTangent(e, p)
a = -DraftVecUtils.angle(currtan, basetan, plane.axis)
self.dvec = DraftVecUtils.rotate(d, a, plane.axis)
a = -DraftVecUtils.angle(currtan, basetan, self.wp.axis)
self.dvec = DraftVecUtils.rotate(d, a, self.wp.axis)
self.npts.append(p.add(self.dvec))
self.ghost.update(self.npts)
elif self.mode == "Circle":
@@ -274,7 +273,7 @@ class Offset(gui_base_original.Modifier):
self.linetrack.finalize()
if self.ghost:
self.ghost.finalize()
super(Offset, self).finish()
super().finish()
def numericRadius(self, rad):
"""Validate the radius entry field in the user interface.

View File

@@ -64,7 +64,7 @@ class Rotate(gui_base_original.Modifier):
def Activated(self):
"""Execute when the command is called."""
super(Rotate, self).Activated(name="Rotate")
super().Activated(name="Rotate")
if not self.ui:
return
self.ghosts = []
@@ -120,15 +120,13 @@ class Rotate(gui_base_original.Modifier):
def handle_mouse_move_event(self, arg):
"""Handle the mouse when moving."""
plane = App.DraftWorkingPlane
for ghost in self.ghosts:
ghost.off()
self.point, ctrlPoint, info = gui_tool_utils.getPoint(self, arg)
# this is to make sure radius is what you see on screen
if self.center and DraftVecUtils.dist(self.point, self.center):
viewdelta = DraftVecUtils.project(self.point.sub(self.center),
plane.axis)
self.wp.axis)
if not DraftVecUtils.isNull(viewdelta):
self.point = self.point.add(viewdelta.negative())
if self.extendedCopy:
@@ -140,9 +138,9 @@ class Rotate(gui_base_original.Modifier):
elif self.step == 1:
currentrad = DraftVecUtils.dist(self.point, self.center)
if currentrad != 0:
angle = DraftVecUtils.angle(plane.u,
angle = DraftVecUtils.angle(self.wp.u,
self.point.sub(self.center),
plane.axis)
self.wp.axis)
else:
angle = 0
self.ui.setRadiusValue(math.degrees(angle), unit="Angle")
@@ -152,9 +150,9 @@ class Rotate(gui_base_original.Modifier):
elif self.step == 2:
currentrad = DraftVecUtils.dist(self.point, self.center)
if currentrad != 0:
angle = DraftVecUtils.angle(plane.u,
angle = DraftVecUtils.angle(self.wp.u,
self.point.sub(self.center),
plane.axis)
self.wp.axis)
else:
angle = 0
if angle < self.firstangle:
@@ -163,7 +161,7 @@ class Rotate(gui_base_original.Modifier):
sweep = angle - self.firstangle
self.arctrack.setApertureAngle(sweep)
for ghost in self.ghosts:
ghost.rotate(plane.axis, sweep)
ghost.rotate(self.wp.axis, sweep)
ghost.on()
self.ui.setRadiusValue(math.degrees(sweep), 'Angle')
self.ui.radiusValue.setFocus()
@@ -214,12 +212,11 @@ class Rotate(gui_base_original.Modifier):
def set_rotation_angle(self, arg):
"""Set the rotation angle."""
plane = App.DraftWorkingPlane
# currentrad = DraftVecUtils.dist(self.point, self.center)
angle = self.point.sub(self.center).getAngle(plane.u)
_v = DraftVecUtils.project(self.point.sub(self.center), plane.v)
if _v.getAngle(plane.v) > 1:
angle = self.point.sub(self.center).getAngle(self.wp.u)
_v = DraftVecUtils.project(self.point.sub(self.center), self.wp.v)
if _v.getAngle(self.wp.v) > 1:
angle = -angle
if angle < self.firstangle:
self.angle = (2 * math.pi - self.firstangle) + angle
@@ -271,7 +268,7 @@ class Rotate(gui_base_original.Modifier):
ghost.finalize()
if cont or (cont is None and self.ui and self.ui.continueMode):
todo.ToDo.delayAfter(self.Activated, [])
super(Rotate, self).finish()
super().finish()
if self.doc:
self.doc.recompute()
@@ -298,7 +295,6 @@ class Rotate(gui_base_original.Modifier):
def build_copy_subelements_command(self):
"""Build the string to commit to copy the subelements."""
import Part
plane = App.DraftWorkingPlane
command = []
arguments = []
@@ -314,7 +310,7 @@ class Rotate(gui_base_original.Modifier):
_cmd += str(_edge_index) + ', '
_cmd += str(math.degrees(self.angle)) + ', '
_cmd += DraftVecUtils.toString(self.center) + ', '
_cmd += DraftVecUtils.toString(plane.axis)
_cmd += DraftVecUtils.toString(self.wp.axis)
_cmd += ']'
arguments.append(_cmd)
@@ -326,7 +322,6 @@ class Rotate(gui_base_original.Modifier):
def build_rotate_subelements_command(self):
"""Build the string to commit to rotate the subelements."""
import Part
plane = App.DraftWorkingPlane
command = []
V = len("Vertex")
@@ -342,7 +337,7 @@ class Rotate(gui_base_original.Modifier):
_cmd += str(_vertex_index) + ', '
_cmd += str(math.degrees(self.angle)) + ', '
_cmd += DraftVecUtils.toString(self.center) + ', '
_cmd += DraftVecUtils.toString(plane.axis)
_cmd += DraftVecUtils.toString(self.wp.axis)
_cmd += ')'
command.append(_cmd)
elif isinstance(subelement, Part.Edge):
@@ -354,7 +349,7 @@ class Rotate(gui_base_original.Modifier):
_cmd += str(_edge_index) + ', '
_cmd += str(math.degrees(self.angle)) + ', '
_cmd += DraftVecUtils.toString(self.center) + ', '
_cmd += DraftVecUtils.toString(plane.axis)
_cmd += DraftVecUtils.toString(self.wp.axis)
_cmd += ')'
command.append(_cmd)
command.append('FreeCAD.ActiveDocument.recompute()')
@@ -362,8 +357,6 @@ class Rotate(gui_base_original.Modifier):
def rotate_object(self, is_copy):
"""Move the object."""
plane = App.DraftWorkingPlane
_doc = 'FreeCAD.ActiveDocument.'
_selected = self.selected_objects
@@ -376,7 +369,7 @@ class Rotate(gui_base_original.Modifier):
_cmd += objects + ', '
_cmd += str(math.degrees(self.angle)) + ', '
_cmd += DraftVecUtils.toString(self.center) + ', '
_cmd += 'axis=' + DraftVecUtils.toString(plane.axis) + ', '
_cmd += 'axis=' + DraftVecUtils.toString(self.wp.axis) + ', '
_cmd += 'copy=' + str(is_copy)
_cmd += ')'
_cmd_list = [_cmd,

View File

@@ -73,7 +73,7 @@ class Scale(gui_base_original.Modifier):
def Activated(self):
"""Execute when the command is called."""
super(Scale, self).Activated(name="Scale")
super().Activated(name="Scale")
if not self.ui:
return
self.ghosts = []
@@ -211,7 +211,7 @@ class Scale(gui_base_original.Modifier):
def scale_with_clone(self):
"""Scale with clone."""
if self.task.relative.isChecked():
self.delta = App.DraftWorkingPlane.getGlobalCoords(self.delta)
self.delta = self.wp.getGlobalCoords(self.delta)
Gui.addModule("Draft")
@@ -325,7 +325,7 @@ class Scale(gui_base_original.Modifier):
def scale_object(self):
"""Scale the object."""
if self.task.relative.isChecked():
self.delta = App.DraftWorkingPlane.getGlobalCoords(self.delta)
self.delta =self.wp.getGlobalCoords(self.delta)
goods = []
bads = []
for obj in self.selected_objects:
@@ -371,7 +371,7 @@ class Scale(gui_base_original.Modifier):
"""Scale the preview of the object."""
delta = App.Vector(x, y, z)
if rel:
delta = App.DraftWorkingPlane.getGlobalCoords(delta)
delta = self.wp.getGlobalCoords(delta)
for ghost in self.ghosts:
ghost.scale(delta)
# calculate a correction factor depending on the scaling center
@@ -420,7 +420,7 @@ class Scale(gui_base_original.Modifier):
def finish(self, cont=False):
"""Terminate the operation."""
super(Scale, self).finish()
super().finish()
for ghost in self.ghosts:
ghost.finalize()