@@ -46,6 +46,7 @@ import FreeCAD
|
||||
import FreeCADGui
|
||||
import Draft
|
||||
import DraftVecUtils
|
||||
import WorkingPlane
|
||||
|
||||
from draftutils.translate import translate
|
||||
|
||||
@@ -552,17 +553,6 @@ class DraftToolBar:
|
||||
self.wplabel = self._pushbutton(
|
||||
"wplabel", self.toptray, icon='Draft_SelectPlane',
|
||||
hide=False,width=120)
|
||||
defaultWP = Draft.getParam("defaultWP",0)
|
||||
if defaultWP == 1:
|
||||
self.wplabel.setText(translate("draft","Top"))
|
||||
elif defaultWP == 2:
|
||||
self.wplabel.setText(translate("draft","Front"))
|
||||
elif defaultWP == 3:
|
||||
self.wplabel.setText(translate("draft","Side"))
|
||||
else:
|
||||
self.wplabel.setText(translate("draft","Auto"))
|
||||
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/General")
|
||||
bsize = p.GetInt("ToolbarIconSize",24)+2
|
||||
|
||||
self.styleButton = self._pushbutton(
|
||||
"stylebutton", self.toptray, icon='Draft_Apply', hide=False,
|
||||
@@ -694,7 +684,6 @@ class DraftToolBar:
|
||||
|
||||
def retranslateTray(self,widget=None):
|
||||
|
||||
self.wplabel.setToolTip(translate("draft", "Current working plane")+":"+self.wplabel.text())
|
||||
self.styleButton.setToolTip(translate("draft", "Change default style for new objects"))
|
||||
self.constrButton.setToolTip(translate("draft", "Toggle construction mode"))
|
||||
self.autoGroupButton.setToolTip(translate("draft", "Autogroup off"))
|
||||
@@ -1103,10 +1092,11 @@ class DraftToolBar:
|
||||
if self.pointcallback:
|
||||
self.pointcallback(num_vec, self.globalMode, self.relativeMode)
|
||||
else:
|
||||
plane = WorkingPlane.get_working_plane(update=False)
|
||||
ref_vec = FreeCAD.Vector(0, 0, 0)
|
||||
if FreeCAD.DraftWorkingPlane and not self.globalMode:
|
||||
num_vec = FreeCAD.DraftWorkingPlane.getGlobalRot(num_vec)
|
||||
ref_vec = FreeCAD.DraftWorkingPlane.getGlobalCoords(ref_vec)
|
||||
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]
|
||||
|
||||
@@ -1283,7 +1273,8 @@ class DraftToolBar:
|
||||
if hasattr(self.sourceCmd,"node"):
|
||||
if self.sourceCmd.node:
|
||||
last = self.sourceCmd.node[-1]
|
||||
delta = FreeCAD.DraftWorkingPlane.getGlobalCoords(
|
||||
plane = WorkingPlane.get_working_plane(update=False)
|
||||
delta = plane.get_global_coords(
|
||||
FreeCAD.Vector(self.x,self.y,self.z))
|
||||
FreeCADGui.Snapper.trackLine.p2(last.add(delta))
|
||||
|
||||
@@ -1310,13 +1301,13 @@ class DraftToolBar:
|
||||
return
|
||||
|
||||
if not plane:
|
||||
plane = FreeCAD.DraftWorkingPlane
|
||||
plane = WorkingPlane.get_working_plane(update=False)
|
||||
# get coords to display
|
||||
if not last:
|
||||
if self.globalMode:
|
||||
last = FreeCAD.Vector(0,0,0)
|
||||
else:
|
||||
last = plane.getPlacement().Base
|
||||
last = plane.position
|
||||
dp = None
|
||||
if point:
|
||||
dp = point
|
||||
@@ -1324,12 +1315,12 @@ class DraftToolBar:
|
||||
if self.globalMode:
|
||||
dp = point - last
|
||||
else:
|
||||
dp = plane.getLocalRot(point - last)
|
||||
dp = plane.get_local_coords(point - last, as_vector=True)
|
||||
else:
|
||||
if self.globalMode:
|
||||
dp = point
|
||||
else:
|
||||
dp = plane.getLocalCoords(point)
|
||||
dp = plane.get_local_coords(point)
|
||||
# set widgets
|
||||
if dp:
|
||||
if self.mask in ['y','z']:
|
||||
@@ -1628,7 +1619,8 @@ class DraftToolBar:
|
||||
self.update_cartesian_coords()
|
||||
if self.angleLock.isChecked():
|
||||
if not self.globalMode:
|
||||
angle_vec = FreeCAD.DraftWorkingPlane.getGlobalRot(self.angle)
|
||||
plane = WorkingPlane.get_working_plane(update=False)
|
||||
angle_vec = plane.get_global_coords(self.angle, as_vector=True)
|
||||
else:
|
||||
angle_vec = self.angle
|
||||
FreeCADGui.Snapper.setAngle(angle_vec)
|
||||
@@ -1638,7 +1630,8 @@ class DraftToolBar:
|
||||
self.update_cartesian_coords()
|
||||
if self.alock:
|
||||
if not self.globalMode:
|
||||
angle_vec = FreeCAD.DraftWorkingPlane.getGlobalRot(self.angle)
|
||||
plane = WorkingPlane.get_working_plane(update=False)
|
||||
angle_vec = plane.get_global_coords(self.angle, as_vector=True)
|
||||
else:
|
||||
angle_vec = self.angle
|
||||
FreeCADGui.Snapper.setAngle(angle_vec)
|
||||
|
||||
@@ -68,8 +68,7 @@ __url__ = "https://www.freecad.org"
|
||||
if not hasattr(FreeCADGui, "Snapper"):
|
||||
FreeCADGui.Snapper = gui_snapper.Snapper()
|
||||
|
||||
if not hasattr(FreeCAD, "DraftWorkingPlane"):
|
||||
FreeCAD.DraftWorkingPlane = WorkingPlane.plane()
|
||||
WorkingPlane.get_working_plane()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Commands that have been migrated to their own modules
|
||||
@@ -99,17 +98,6 @@ from draftguitools.gui_layers import Layer
|
||||
# update the translation engine
|
||||
FreeCADGui.updateLocale()
|
||||
|
||||
# sets the default working plane
|
||||
plane = WorkingPlane.plane()
|
||||
FreeCAD.DraftWorkingPlane = plane
|
||||
defaultWP = Draft.getParam("defaultWP",0)
|
||||
if defaultWP == 1: plane.alignToPointAndAxis(Vector(0,0,0), Vector(0,0,1), 0)
|
||||
elif defaultWP == 2: plane.alignToPointAndAxis(Vector(0,0,0), Vector(0,1,0), 0)
|
||||
elif defaultWP == 3: plane.alignToPointAndAxis(Vector(0,0,0), Vector(1,0,0), 0)
|
||||
|
||||
# last snapped objects, for quick intersection calculation
|
||||
lastObj = [0,0]
|
||||
|
||||
# Set modifier keys
|
||||
from draftguitools.gui_tool_utils import MODCONSTRAIN
|
||||
from draftguitools.gui_tool_utils import MODSNAP
|
||||
|
||||
@@ -494,8 +494,8 @@ class Arc_3Points(gui_base.GuiCommandSimplest):
|
||||
# Set up the working plane and launch the Snapper
|
||||
# with the indicated callbacks: one for when the user clicks
|
||||
# on the 3D view, and another for when the user moves the pointer.
|
||||
if hasattr(App, "DraftWorkingPlane"):
|
||||
App.DraftWorkingPlane.setup()
|
||||
import WorkingPlane
|
||||
WorkingPlane.get_working_plane()
|
||||
|
||||
Gui.Snapper.getPoint(callback=self.getPoint,
|
||||
movecallback=self.drawArc)
|
||||
|
||||
@@ -36,6 +36,7 @@ of the DraftToolBar, the Snapper, and the working plane.
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
import DraftVecUtils
|
||||
import WorkingPlane
|
||||
import draftutils.utils as utils
|
||||
import draftutils.gui_utils as gui_utils
|
||||
import draftutils.todo as todo
|
||||
@@ -59,9 +60,7 @@ class DraftTool:
|
||||
properties of the running tools such as the task panel, the snapping
|
||||
functions, and the grid trackers.
|
||||
|
||||
It also connects with the `DraftWorkingPlane` class
|
||||
that is installed in the `FreeCAD` namespace in order to set up
|
||||
the working plane if it doesn't exist.
|
||||
It also connects with the `WorkingPlane` class.
|
||||
|
||||
This class is intended to be replaced by newer classes inside the
|
||||
`gui_base` module, in particular, `GuiCommandBase`.
|
||||
@@ -128,8 +127,7 @@ class DraftTool:
|
||||
self.ui = Gui.draftToolBar
|
||||
self.ui.sourceCmd = self
|
||||
self.view = gui_utils.get_3d_view()
|
||||
self.wp = App.DraftWorkingPlane
|
||||
self.wp.setup()
|
||||
self.wp = WorkingPlane.get_working_plane()
|
||||
|
||||
self.planetrack = None
|
||||
if utils.get_param("showPlaneTracker", False):
|
||||
@@ -166,7 +164,7 @@ class DraftTool:
|
||||
self.ui.sourceCmd = None
|
||||
if self.planetrack:
|
||||
self.planetrack.finalize()
|
||||
self.wp.restore()
|
||||
self.wp._restore()
|
||||
if hasattr(Gui, "Snapper"):
|
||||
Gui.Snapper.off()
|
||||
if self.call:
|
||||
@@ -218,8 +216,7 @@ class DraftTool:
|
||||
of the current tool
|
||||
"""
|
||||
# Current plane rotation as a string
|
||||
p = self.wp.getRotation()
|
||||
qr = p.Rotation.Q
|
||||
qr = self.wp.get_placement().Rotation.Q
|
||||
qr = "({0}, {1}, {2}, {3})".format(qr[0], qr[1], qr[2], qr[3])
|
||||
|
||||
# Support object
|
||||
@@ -265,8 +262,8 @@ class Creator(DraftTool):
|
||||
It is the `featureName` of the object, to know what is being run.
|
||||
"""
|
||||
super().Activated(name)
|
||||
# call self.wp.save to sync with self.wp.restore called in finish method
|
||||
self.wp.save()
|
||||
# call _save to sync with _restore called in finish method
|
||||
self.wp._save()
|
||||
self.support = gui_tool_utils.get_support()
|
||||
|
||||
|
||||
@@ -286,6 +283,6 @@ class Modifier(DraftTool):
|
||||
|
||||
def Activated(self, name="None", is_subtool=False):
|
||||
super().Activated(name, is_subtool)
|
||||
# call self.wp.save to sync with self.wp.restore called in finish method
|
||||
self.wp.save()
|
||||
# call _save to sync with _restore called in finish method
|
||||
self.wp._save()
|
||||
## @}
|
||||
|
||||
@@ -580,14 +580,14 @@ class Dimension(gui_base_original.Creator):
|
||||
by projecting on the working plane.
|
||||
"""
|
||||
if not self.proj_point1 or not self.proj_point2:
|
||||
self.proj_point1 = self.wp.projectPoint(self.node[0])
|
||||
self.proj_point2 = self.wp.projectPoint(self.node[1])
|
||||
self.proj_point1 = self.wp.project_point(self.node[0])
|
||||
self.proj_point2 = self.wp.project_point(self.node[1])
|
||||
proj_u= self.wp.u.dot(self.proj_point2 - self.proj_point1)
|
||||
proj_v= self.wp.v.dot(self.proj_point2 - self.proj_point1)
|
||||
active_view = Gui.ActiveDocument.ActiveView
|
||||
cursor = active_view.getCursorPos()
|
||||
cursor_point = active_view.getPoint(cursor)
|
||||
self.point = self.wp.projectPoint(cursor_point)
|
||||
self.point = self.wp.project_point(cursor_point)
|
||||
if not self.force:
|
||||
ref_point = self.point - (self.proj_point2 + self.proj_point1)*1/2
|
||||
ref_angle = abs(ref_point.getAngle(self.wp.u))
|
||||
|
||||
@@ -309,10 +309,6 @@ class Edit(gui_base_original.Modifier):
|
||||
|
||||
self.register_editing_callbacks()
|
||||
|
||||
# TODO: align working plane when editing starts
|
||||
# App.DraftWorkingPlane.save()
|
||||
# self.alignWorkingPlane()
|
||||
|
||||
|
||||
def numericInput(self, numx, numy, numz):
|
||||
"""Execute callback by the toolbar to activate the update function.
|
||||
|
||||
@@ -101,7 +101,7 @@ class Label(gui_base_original.Creator):
|
||||
dist = v.Length
|
||||
h = self.wp.u
|
||||
n = self.wp.axis
|
||||
r = self.wp.getRotation().Rotation
|
||||
r = self.wp.get_placement().Rotation
|
||||
|
||||
if abs(DraftVecUtils.angle(v, h, n)) <= math.pi/4:
|
||||
direction = "Horizontal"
|
||||
|
||||
@@ -182,9 +182,6 @@ class Line(gui_base_original.Creator):
|
||||
self.commit(translate("draft", "Create Wire"),
|
||||
_cmd_list)
|
||||
super().finish()
|
||||
if hasattr(Gui, "Snapper"):
|
||||
Gui.Snapper.setGrid(tool=True)
|
||||
Gui.Snapper.restack()
|
||||
if cont or (cont is None and self.ui and self.ui.continueMode):
|
||||
self.Activated()
|
||||
|
||||
@@ -259,10 +256,7 @@ class Line(gui_base_original.Creator):
|
||||
n = self.wp.axis
|
||||
p = self.node[-1]
|
||||
v = self.node[-1].sub(self.node[-2])
|
||||
self.wp.alignToPointAndAxis(p, n, upvec=v)
|
||||
if hasattr(Gui, "Snapper"):
|
||||
Gui.Snapper.setGrid()
|
||||
Gui.Snapper.restack()
|
||||
self.wp.align_to_point_and_axis(p, n, upvec=v, _hist_add=False)
|
||||
if self.planetrack:
|
||||
self.planetrack.set(self.node[-1])
|
||||
|
||||
|
||||
@@ -60,16 +60,14 @@ class Draft_WorkingPlaneProxy:
|
||||
|
||||
def Activated(self):
|
||||
"""Execute when the command is called."""
|
||||
if hasattr(App, "DraftWorkingPlane"):
|
||||
App.DraftWorkingPlane.setup()
|
||||
App.ActiveDocument.openTransaction("Create WP proxy")
|
||||
Gui.addModule("Draft")
|
||||
_cmd = "Draft.make_workingplaneproxy("
|
||||
_cmd += "FreeCAD.DraftWorkingPlane.getPlacement()"
|
||||
_cmd += ")"
|
||||
Gui.doCommand(_cmd)
|
||||
App.ActiveDocument.commitTransaction()
|
||||
App.ActiveDocument.recompute()
|
||||
App.ActiveDocument.openTransaction("Create WP proxy")
|
||||
Gui.addModule("Draft")
|
||||
Gui.addModule("WorkingPlane")
|
||||
_cmd = "pl = WorkingPlane.get_working_plane().get_placement()"
|
||||
_cmd += "Draft.make_workingplaneproxy(pl)"
|
||||
Gui.doCommand(_cmd)
|
||||
App.ActiveDocument.commitTransaction()
|
||||
App.ActiveDocument.recompute()
|
||||
|
||||
|
||||
Gui.addCommand('Draft_WorkingPlaneProxy', Draft_WorkingPlaneProxy())
|
||||
|
||||
@@ -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 = self.wp.getGlobalCoords(self.delta)
|
||||
self.delta = self.wp.get_global_coords(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 =self.wp.getGlobalCoords(self.delta)
|
||||
self.delta =self.wp.get_global_coords(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 = self.wp.getGlobalCoords(delta)
|
||||
delta = self.wp.get_global_coords(delta)
|
||||
for ghost in self.ghosts:
|
||||
ghost.scale(delta)
|
||||
# calculate a correction factor depending on the scaling center
|
||||
|
||||
@@ -36,6 +36,7 @@ as they operate on selections and graphical properties.
|
||||
# @{
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
import WorkingPlane
|
||||
import draftutils.gui_utils as gui_utils
|
||||
import draftutils.utils as utils
|
||||
|
||||
@@ -205,7 +206,7 @@ def get_point(target, args, noTracker=False):
|
||||
mask = None
|
||||
|
||||
ctrlPoint = App.Vector(point)
|
||||
wp = App.DraftWorkingPlane
|
||||
wp = WorkingPlane.get_working_plane(update=False)
|
||||
if target.node:
|
||||
if target.featureName == "Rectangle":
|
||||
ui.displayPoint(point, target.node[0], plane=wp, mask=mask)
|
||||
@@ -222,7 +223,7 @@ getPoint = get_point
|
||||
def set_working_plane_to_object_under_cursor(mouseEvent):
|
||||
"""Align the working plane to the face under the cursor.
|
||||
|
||||
The working plane is only aligned if it is `'weak'`.
|
||||
The working plane is only aligned if it is `'auto'`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
@@ -242,8 +243,8 @@ def set_working_plane_to_object_under_cursor(mouseEvent):
|
||||
return None
|
||||
if "Face" not in objectUnderCursor["Component"]:
|
||||
return None
|
||||
wp = App.DraftWorkingPlane
|
||||
if wp.weak is False:
|
||||
wp = WorkingPlane.get_working_plane(update=False)
|
||||
if not wp.auto:
|
||||
return None
|
||||
|
||||
import Part
|
||||
@@ -255,11 +256,8 @@ def set_working_plane_to_object_under_cursor(mouseEvent):
|
||||
sub = objectUnderCursor["Component"]
|
||||
shape = Part.getShape(obj, sub, needSubElement=True, retType=0)
|
||||
|
||||
if wp.alignToFace(shape) is True:
|
||||
wp.weak = True
|
||||
if hasattr(Gui, "Snapper"):
|
||||
Gui.Snapper.setGrid()
|
||||
Gui.Snapper.restack()
|
||||
if wp.align_to_face(shape, _hist_add=False):
|
||||
wp.auto = True
|
||||
return obj
|
||||
|
||||
return None
|
||||
@@ -271,15 +269,15 @@ setWorkingPlaneToObjectUnderCursor = set_working_plane_to_object_under_cursor
|
||||
def set_working_plane_to_selected_object():
|
||||
"""Align the working plane to a preselected face.
|
||||
|
||||
The working plane is only aligned if it is `'weak'`.
|
||||
The working plane is only aligned if it is `'auto'`.
|
||||
|
||||
Returns
|
||||
-------
|
||||
App::DocumentObject or None
|
||||
The parent object the face belongs to, if alignment occurred, or None.
|
||||
"""
|
||||
wp = App.DraftWorkingPlane
|
||||
if wp.weak is False:
|
||||
wp = WorkingPlane.get_working_plane(update=False)
|
||||
if not wp.auto:
|
||||
return None
|
||||
|
||||
sels = Gui.Selection.getSelectionEx("", 0)
|
||||
@@ -293,11 +291,8 @@ def set_working_plane_to_selected_object():
|
||||
needSubElement=True,
|
||||
retType=0)
|
||||
|
||||
if wp.alignToFace(shape) is True:
|
||||
wp.weak = True
|
||||
if hasattr(Gui, "Snapper"):
|
||||
Gui.Snapper.setGrid()
|
||||
Gui.Snapper.restack()
|
||||
if wp.align_to_face(shape, _hist_add=False):
|
||||
wp.auto = True
|
||||
return sels[0].Object
|
||||
|
||||
return None
|
||||
@@ -309,7 +304,7 @@ setWorkingPlaneToSelectedObject = set_working_plane_to_selected_object
|
||||
def get_support(mouseEvent=None):
|
||||
""""Align the working plane to a preselected face or the face under the cursor.
|
||||
|
||||
The working plane is only aligned if it is `'weak'`.
|
||||
The working plane is only aligned if it is `'auto'`.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
||||
Reference in New Issue
Block a user