From f915ad7190ab3a75fb012be416129ac024c27780 Mon Sep 17 00:00:00 2001 From: Roy-043 Date: Sun, 27 Apr 2025 10:51:26 +0200 Subject: [PATCH] BIM: Update working plane related code Some code stemming from the old BIM external workbench still used `FreeCAD.DraftWorkingPlane`. --- src/Mod/BIM/bimcommands/BimDimensions.py | 10 ++++-- src/Mod/BIM/bimcommands/BimImagePlane.py | 8 +++-- src/Mod/BIM/bimcommands/BimLibrary.py | 4 +-- src/Mod/BIM/bimcommands/BimNudge.py | 36 +++++++++---------- src/Mod/BIM/bimcommands/BimProjectManager.py | 37 +++++++++++--------- src/Mod/BIM/bimcommands/BimSetup.py | 32 ++++++----------- src/Mod/BIM/bimcommands/BimSketch.py | 5 ++- src/Mod/BIM/bimcommands/BimViews.py | 3 +- 8 files changed, 68 insertions(+), 67 deletions(-) diff --git a/src/Mod/BIM/bimcommands/BimDimensions.py b/src/Mod/BIM/bimcommands/BimDimensions.py index a3ea684efc..1b1fed782f 100644 --- a/src/Mod/BIM/bimcommands/BimDimensions.py +++ b/src/Mod/BIM/bimcommands/BimDimensions.py @@ -66,7 +66,10 @@ class BIM_DimensionHorizontal(gui_dimensions.Dimension): } def Activated(self): - self.dir = FreeCAD.DraftWorkingPlane.u + + import WorkingPlane + + self.dir = WorkingPlane.get_working_plane().u super().Activated() @@ -88,7 +91,10 @@ class BIM_DimensionVertical(gui_dimensions.Dimension): } def Activated(self): - self.dir = FreeCAD.DraftWorkingPlane.v + + import WorkingPlane + + self.dir = WorkingPlane.get_working_plane().v super().Activated() diff --git a/src/Mod/BIM/bimcommands/BimImagePlane.py b/src/Mod/BIM/bimcommands/BimImagePlane.py index 94b4fb9a73..56ba73cfc1 100644 --- a/src/Mod/BIM/bimcommands/BimImagePlane.py +++ b/src/Mod/BIM/bimcommands/BimImagePlane.py @@ -86,6 +86,7 @@ class BIM_ImagePlane: def PointCallback(self, point, snapinfo): import os import DraftVecUtils + import WorkingPlane if not point: # cancelled @@ -109,10 +110,11 @@ class BIM_ImagePlane: midpoint = self.basepoint.add( self.opposite.sub(self.basepoint).multiply(0.5) ) - rotation = FreeCAD.DraftWorkingPlane.getRotation().Rotation + wp = WorkingPlane.get_working_plane() + rotation = wp.get_placement().Rotation diagonal = self.opposite.sub(self.basepoint) - length = DraftVecUtils.project(diagonal, FreeCAD.DraftWorkingPlane.u).Length - height = DraftVecUtils.project(diagonal, FreeCAD.DraftWorkingPlane.v).Length + length = DraftVecUtils.project(diagonal, wp.u).Length + height = DraftVecUtils.project(diagonal, wp.v).Length FreeCAD.ActiveDocument.openTransaction("Create image plane") image = FreeCAD.ActiveDocument.addObject( "Image::ImagePlane", "ImagePlane" diff --git a/src/Mod/BIM/bimcommands/BimLibrary.py b/src/Mod/BIM/bimcommands/BimLibrary.py index c027b376a4..de6f2f9f25 100644 --- a/src/Mod/BIM/bimcommands/BimLibrary.py +++ b/src/Mod/BIM/bimcommands/BimLibrary.py @@ -652,6 +652,7 @@ class BIM_Library_TaskPanel: def place(self, path): import Part + import WorkingPlane self.shape = Part.read(path) if hasattr(FreeCADGui, "Snapper"): @@ -665,8 +666,7 @@ class BIM_Library_TaskPanel: self.delta = self.shape.BoundBox.Center self.box.move(self.delta) self.box.on() - if hasattr(FreeCAD, "DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + WorkingPlane.get_working_plane() self.origin = self.makeOriginWidget() FreeCADGui.Snapper.getPoint( movecallback=self.mouseMove, diff --git a/src/Mod/BIM/bimcommands/BimNudge.py b/src/Mod/BIM/bimcommands/BimNudge.py index 1aed02e458..afd5c677eb 100644 --- a/src/Mod/BIM/bimcommands/BimNudge.py +++ b/src/Mod/BIM/bimcommands/BimNudge.py @@ -38,6 +38,7 @@ class BIM_Nudge: "mode can be dist, up, down, left, right. dist returns a float in mm, other modes return a 3D vector" from PySide import QtGui + import WorkingPlane mw = FreeCADGui.getMainWindow() if mw: @@ -87,22 +88,15 @@ class BIM_Nudge: return None if mode == "dist": return dist - elif mode == "up": - return FreeCAD.Vector(FreeCAD.DraftWorkingPlane.v).multiply(dist) - elif mode == "down": - return ( - FreeCAD.Vector(FreeCAD.DraftWorkingPlane.v) - .negative() - .multiply(dist) - ) - elif mode == "right": - return FreeCAD.Vector(FreeCAD.DraftWorkingPlane.u).multiply(dist) - elif mode == "left": - return ( - FreeCAD.Vector(FreeCAD.DraftWorkingPlane.u) - .negative() - .multiply(dist) - ) + wp = WorkingPlane.get_working_plane() + if mode == "up": + return FreeCAD.Vector(wp.v).multiply(dist) + if mode == "down": + return FreeCAD.Vector(wp.v).negative().multiply(dist) + if mode == "right": + return FreeCAD.Vector(wp.u).multiply(dist) + if mode == "left": + return FreeCAD.Vector(wp.u).negative().multiply(dist) return None def toStr(self, objs): @@ -291,6 +285,9 @@ class BIM_Nudge_RotateLeft(BIM_Nudge): } def Activated(self): + + import WorkingPlane + sel = FreeCADGui.Selection.getSelection() if sel: center = self.getCenter(sel) @@ -302,7 +299,7 @@ class BIM_Nudge_RotateLeft(BIM_Nudge): + ",45,FreeCAD." + str(center) + ",FreeCAD." - + str(FreeCAD.DraftWorkingPlane.axis) + + str(WorkingPlane.get_working_plane().axis) + ")" ) FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()") @@ -319,6 +316,9 @@ class BIM_Nudge_RotateRight(BIM_Nudge): } def Activated(self): + + import WorkingPlane + sel = FreeCADGui.Selection.getSelection() if sel: center = self.getCenter(sel) @@ -330,7 +330,7 @@ class BIM_Nudge_RotateRight(BIM_Nudge): + ",-45,FreeCAD." + str(center) + ",FreeCAD." - + str(FreeCAD.DraftWorkingPlane.axis) + + str(WorkingPlane.get_working_plane().axis) + ")" ) FreeCADGui.doCommand("FreeCAD.ActiveDocument.recompute()") diff --git a/src/Mod/BIM/bimcommands/BimProjectManager.py b/src/Mod/BIM/bimcommands/BimProjectManager.py index 89eae7a36b..e9d0ab1d21 100644 --- a/src/Mod/BIM/bimcommands/BimProjectManager.py +++ b/src/Mod/BIM/bimcommands/BimProjectManager.py @@ -573,17 +573,19 @@ class BIM_ProjectManager: def saveTemplate(self): """saves the contents of the current file as a template""" + import WorkingPlane + d = FreeCAD.ActiveDocument if not d: d = FreeCAD.newDocument() # build list of useful settings to store + wp = WorkingPlane.get_working_plane() values = {} - if hasattr(FreeCAD, "DraftWorkingPlane"): - values["wpposition"] = str(FreeCAD.DraftWorkingPlane.position) - values["wpu"] = str(FreeCAD.DraftWorkingPlane.u) - values["wpv"] = str(FreeCAD.DraftWorkingPlane.v) - values["wpaxis"] = str(FreeCAD.DraftWorkingPlane.axis) + values["wpposition"] = str(wp.position) + values["wpu"] = str(wp.u) + values["wpv"] = str(wp.v) + values["wpaxis"] = str(wp.axis) values["unit"] = str( FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").GetInt( "UserSchema", 0 @@ -672,8 +674,10 @@ class BIM_ProjectManager: def loadTemplate(self): """loads the contents of a template into the current file""" - import FreeCADGui from PySide import QtGui + import FreeCADGui + import WorkingPlane + from FreeCAD import Vector # required for following eval calls filename = QtGui.QFileDialog.getOpenFileName( QtGui.QApplication.activeWindow(), @@ -698,17 +702,16 @@ class BIM_ProjectManager: FreeCAD.ActiveDocument = d values = d.Meta bimunit = 0 - if hasattr(FreeCAD, "DraftWorkingPlane"): - from FreeCAD import Vector - - if "wppos" in values: - FreeCAD.DraftWorkingPlane.position = eval(values["wpposition"]) - if "wpu" in values: - FreeCAD.DraftWorkingPlane.u = eval(values["wpu"]) - if "wpv" in values: - FreeCAD.DraftWorkingPlane.v = eval(values["wpv"]) - if "wpaxis" in values: - FreeCAD.DraftWorkingPlane.axis = eval(values["wpaxis"]) + wp = WorkingPlane.get_working_plane() + if "wpposition" in values: + wp.position = eval(values["wpposition"]) + if "wpu" in values: + wp.u = eval(values["wpu"]) + if "wpv" in values: + wp.v = eval(values["wpv"]) + if "wpaxis" in values: + wp.axis = eval(values["wpaxis"]) + wp._handle_custom(_hist_add=True) # update the widget if "unit" in values: FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Units").SetInt( "UserSchema", int(values["unit"]) diff --git a/src/Mod/BIM/bimcommands/BimSetup.py b/src/Mod/BIM/bimcommands/BimSetup.py index 753e996cc8..7f08f42bfd 100644 --- a/src/Mod/BIM/bimcommands/BimSetup.py +++ b/src/Mod/BIM/bimcommands/BimSetup.py @@ -52,9 +52,10 @@ class BIM_Setup: 0.16 # How many times TechDraw dim arrows are smaller than Draft ) - # load dialog from PySide import QtGui + import WorkingPlane + # load dialog self.form = FreeCADGui.PySideUic.loadUi(":/ui/dialogSetup.ui") # center the dialog over FreeCAD window @@ -315,26 +316,15 @@ class BIM_Setup: ) # set the working plane - if hasattr(FreeCAD, "DraftWorkingPlane") and hasattr( - FreeCADGui, "draftToolBar" - ): - if wp == 1: - FreeCAD.DraftWorkingPlane.alignToPointAndAxis( - FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 0, 1), 0 - ) - FreeCADGui.draftToolBar.wplabel.setText("Top(XY)") - elif wp == 2: - FreeCAD.DraftWorkingPlane.alignToPointAndAxis( - FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, 1, 0), 0 - ) - FreeCADGui.draftToolBar.wplabel.setText("Front(XZ)") - elif wp == 3: - FreeCAD.DraftWorkingPlane.alignToPointAndAxis( - FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(1, 0, 0), 0 - ) - FreeCADGui.draftToolBar.wplabel.setText("Side(YZ)") - else: - FreeCADGui.draftToolBar.wplabel.setText("Auto") + wplane = WorkingPlane.get_working_plane() + if wp == 1: + wplane.set_to_top() + elif wp == 2: + wplane.set_to_front() + elif wp == 3: + wplane.set_to_side() + else: + wplane.set_to_auto() # set Draft toolbar if hasattr(FreeCADGui, "draftToolBar"): diff --git a/src/Mod/BIM/bimcommands/BimSketch.py b/src/Mod/BIM/bimcommands/BimSketch.py index 9f78a303a8..21247a33c5 100644 --- a/src/Mod/BIM/bimcommands/BimSketch.py +++ b/src/Mod/BIM/bimcommands/BimSketch.py @@ -47,6 +47,7 @@ class BIM_Sketch: return v def Activated(self): + import WorkingPlane from draftutils import params issnap = False if hasattr(FreeCAD, "DraftWorkingPlane"): @@ -65,9 +66,7 @@ class BIM_Sketch: sk.ViewObject.LineColor = params.get_param_view("DefaultShapeLineColor") sk.ViewObject.PointColor = params.get_param_view("DefaultShapeLineColor") sk.ViewObject.LineWidth = params.get_param_view("DefaultShapeLineWidth") - p = FreeCAD.DraftWorkingPlane.getPlacement() - p.Base = FreeCAD.DraftWorkingPlane.position - sk.Placement = p + sk.Placement = WorkingPlane.get_working_plane().get_placement() FreeCADGui.ActiveDocument.setEdit(sk.Name) FreeCADGui.activateWorkbench("SketcherWorkbench") diff --git a/src/Mod/BIM/bimcommands/BimViews.py b/src/Mod/BIM/bimcommands/BimViews.py index d98b8159e0..9ce9db4ced 100644 --- a/src/Mod/BIM/bimcommands/BimViews.py +++ b/src/Mod/BIM/bimcommands/BimViews.py @@ -357,9 +357,10 @@ class BIM_Views: "adds a WP proxy" import Draft + import WorkingPlane FreeCAD.ActiveDocument.openTransaction("Create WP Proxy") - obj = Draft.makeWorkingPlaneProxy(FreeCAD.DraftWorkingPlane.getPlacement()) + obj = Draft.makeWorkingPlaneProxy(WorkingPlane.get_working_plane().get_placement()) self.addToSelection(obj) FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute()