BIM: Update working plane related code

Some code stemming from the old BIM external workbench still used `FreeCAD.DraftWorkingPlane`.
This commit is contained in:
Roy-043
2025-04-27 10:51:26 +02:00
committed by Yorik van Havre
parent ac9b65aa65
commit f915ad7190
8 changed files with 68 additions and 67 deletions

View File

@@ -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()

View File

@@ -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"

View File

@@ -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,

View File

@@ -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()")

View File

@@ -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"])

View File

@@ -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"):

View File

@@ -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")

View File

@@ -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()