From 3a396e1ed3b8302cc056c47c26aed34eeabaeede Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Mon, 23 Oct 2023 18:42:20 +0200 Subject: [PATCH] Arch: Updates related to the PlaneGui class (#11153) Related issue: #5603. --- src/Mod/Arch/ArchBuildingPart.py | 43 +++++++++++++------------------- src/Mod/Arch/ArchCurtainWall.py | 4 +-- src/Mod/Arch/ArchCutPlane.py | 5 ++-- src/Mod/Arch/ArchNesting.py | 4 +-- src/Mod/Arch/ArchPanel.py | 8 +++--- src/Mod/Arch/ArchSectionPlane.py | 15 +++++------ src/Mod/Arch/ArchStructure.py | 25 +++++++++---------- src/Mod/Arch/ArchTruss.py | 4 +-- src/Mod/Arch/ArchVRM.py | 14 +++++------ src/Mod/Arch/ArchWall.py | 17 +++++++------ src/Mod/Arch/ArchWindow.py | 14 +++++------ src/Mod/Arch/importIFCHelper.py | 4 +-- 12 files changed, 75 insertions(+), 82 deletions(-) diff --git a/src/Mod/Arch/ArchBuildingPart.py b/src/Mod/Arch/ArchBuildingPart.py index 51407a1c72..ac1661efa9 100644 --- a/src/Mod/Arch/ArchBuildingPart.py +++ b/src/Mod/Arch/ArchBuildingPart.py @@ -301,9 +301,10 @@ class CommandBuildingPart: ss += "]" FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create BuildingPart")) FreeCADGui.addModule("Arch") - FreeCADGui.doCommand("obj = Arch.makeBuildingPart("+ss+")") FreeCADGui.addModule("Draft") - FreeCADGui.doCommand("obj.Placement = FreeCAD.DraftWorkingPlane.getPlacement()") + FreeCADGui.addModule("WorkingPlane") + FreeCADGui.doCommand("obj = Arch.makeBuildingPart("+ss+")") + FreeCADGui.doCommand("obj.Placement = WorkingPlane.get_working_plane().get_placement()") FreeCADGui.doCommand("Draft.autogroup(obj)") FreeCAD.ActiveDocument.commitTransaction() FreeCAD.ActiveDocument.recompute() @@ -963,30 +964,22 @@ class ViewProviderBuildingPart: FreeCADGui.Selection.clearSelection() def setWorkingPlane(self,restore=False): + vobj = self.Object.ViewObject - if hasattr(self,"Object") and hasattr(FreeCAD,"DraftWorkingPlane"): - import FreeCADGui - autoclip = False - if hasattr(self.Object.ViewObject,"AutoCutView"): - autoclip = self.Object.ViewObject.AutoCutView - if restore: - FreeCAD.DraftWorkingPlane.restore() - if autoclip: - self.Object.ViewObject.CutView = False - else: - FreeCAD.DraftWorkingPlane.save() - FreeCADGui.runCommand("Draft_SelectPlane") - if autoclip: - self.Object.ViewObject.CutView = True - if hasattr(FreeCADGui,"Snapper"): - FreeCADGui.Snapper.setGrid() - if hasattr(FreeCADGui,"draftToolBar"): - if restore and hasattr(self,"wptext"): - FreeCADGui.draftToolBar.wplabel.setText(self.wptext) - else: - self.wptext = FreeCADGui.draftToolBar.wplabel.text() - FreeCADGui.draftToolBar.wplabel.setText(self.Object.Label) - FreeCAD.DraftWorkingPlane.lastBuildingPart = self.Object.Name + import WorkingPlane + wp = WorkingPlane.get_working_plane(update=False) + autoclip = False + if hasattr(vobj,"AutoCutView"): + autoclip = vobj.AutoCutView + if restore: + if wp.label.rstrip("*") == self.Object.Label: + wp._previous() + if autoclip: + vobj.CutView = False + else: + wp.align_to_selection() + if autoclip: + vobj.CutView = True def writeCamera(self): diff --git a/src/Mod/Arch/ArchCurtainWall.py b/src/Mod/Arch/ArchCurtainWall.py index 272a946732..64ce7ea311 100644 --- a/src/Mod/Arch/ArchCurtainWall.py +++ b/src/Mod/Arch/ArchCurtainWall.py @@ -124,8 +124,8 @@ class CommandArchCurtainWall: else: # interactive line drawing self.points = [] - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + WorkingPlane.get_working_plane() if hasattr(FreeCADGui,"Snapper"): FreeCADGui.Snapper.getPoint(callback=self.getPoint) diff --git a/src/Mod/Arch/ArchCutPlane.py b/src/Mod/Arch/ArchCutPlane.py index 3aa5e1ce08..796739e360 100644 --- a/src/Mod/Arch/ArchCutPlane.py +++ b/src/Mod/Arch/ArchCutPlane.py @@ -46,8 +46,9 @@ __url__ = "http://www.freecad.org" def getPlanWithLine(line): """Function to make a plane along Normal plan""" import Part - plan = FreeCAD.DraftWorkingPlane - w = plan.getNormal() + import WorkingPlane + plan = WorkingPlane.get_working_plane() + w = plan.axis part = Part.Shape(line) out = part.extrude(w) return out diff --git a/src/Mod/Arch/ArchNesting.py b/src/Mod/Arch/ArchNesting.py index fe9dc0296c..f6533b0506 100644 --- a/src/Mod/Arch/ArchNesting.py +++ b/src/Mod/Arch/ArchNesting.py @@ -583,8 +583,8 @@ class Nester: # flatten the polygon on the XY plane - wp = WorkingPlane.plane() - wp.alignToPointAndAxis(face.CenterOfMass,face.normalAt(0,0)) + wp = WorkingPlane.PlaneBase() + wp.align_to_point_and_axis(face.CenterOfMass,face.normalAt(0,0)) pverts = [] for v in verts: vx = DraftVecUtils.project(v,wp.u) diff --git a/src/Mod/Arch/ArchPanel.py b/src/Mod/Arch/ArchPanel.py index ed5a5a6450..20fb4f4083 100644 --- a/src/Mod/Arch/ArchPanel.py +++ b/src/Mod/Arch/ArchPanel.py @@ -165,9 +165,9 @@ class CommandPanel: return # interactive mode - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() - + import WorkingPlane + WorkingPlane.get_working_plane() + self.points = [] self.tracker = DraftTrackers.boxTracker() self.tracker.width(self.Width) @@ -434,8 +434,6 @@ class _Panel(ArchComponent.Component): if self.clone(obj): return - import Part #, DraftGeomUtils - layers = [] length = 0 width = 0 diff --git a/src/Mod/Arch/ArchSectionPlane.py b/src/Mod/Arch/ArchSectionPlane.py index c2c340eaef..281c525425 100644 --- a/src/Mod/Arch/ArchSectionPlane.py +++ b/src/Mod/Arch/ArchSectionPlane.py @@ -74,7 +74,8 @@ def makeSectionPlane(objectslist=None,name=None): for o in Draft.get_group_contents(objectslist): if hasattr(o,"Shape") and hasattr(o.Shape,"BoundBox"): bb.add(o.Shape.BoundBox) - obj.Placement = FreeCAD.DraftWorkingPlane.getPlacement() + import WorkingPlane + obj.Placement = WorkingPlane.get_working_plane().get_placement() obj.Placement.Base = bb.Center if FreeCAD.GuiUp: margin = bb.XLength*0.1 @@ -391,13 +392,13 @@ def getSVG(source, svgcache = '' # render using the Arch Vector Renderer import ArchVRM, WorkingPlane - wp = WorkingPlane.plane() + wp = WorkingPlane.PlaneBase() pl = FreeCAD.Placement(source.Placement) if source.ViewObject and hasattr(source.ViewObject,"CutMargin"): mv = pl.multVec(FreeCAD.Vector(0,0,1)) mv.multiply(source.ViewObject.CutMargin) pl.move(mv) - wp.setFromPlacement(pl) + wp.align_to_placement(pl) #wp.inverse() render = ArchVRM.Renderer() render.setWorkingPlane(wp) @@ -748,9 +749,9 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face factor = None trans = None import WorkingPlane - wp = WorkingPlane.plane() - wp.alignToPointAndAxis_SVG(Vector(0,0,0),cutplane.normalAt(0,0),0) - p = wp.getLocalCoords(markervec) + wp = WorkingPlane.PlaneBase() + wp.align_to_point_and_axis_svg(Vector(0,0,0),cutplane.normalAt(0,0),0) + p = wp.get_local_coords(markervec) orlength = FreeCAD.Vector(p.x,p.y,0).Length marker = re.findall("",svg) if marker: @@ -763,7 +764,7 @@ def getCoinSVG(cutplane,objs,cameradata=None,linewidth=0.2,singleface=False,face p2 = FreeCAD.Vector(x2,y2,0) factor = orlength/p2.sub(p1).Length if factor: - orig = wp.getLocalCoords(FreeCAD.Vector(boundbox.XMin,boundbox.YMin,boundbox.ZMin)) + orig = wp.get_local_coords(FreeCAD.Vector(boundbox.XMin,boundbox.YMin,boundbox.ZMin)) orig = FreeCAD.Vector(orig.x,-orig.y,0) scaledp1 = FreeCAD.Vector(p1.x*factor,p1.y*factor,0) trans = orig.sub(scaledp1) diff --git a/src/Mod/Arch/ArchStructure.py b/src/Mod/Arch/ArchStructure.py index b575889aa4..41981f26df 100644 --- a/src/Mod/Arch/ArchStructure.py +++ b/src/Mod/Arch/ArchStructure.py @@ -170,9 +170,8 @@ def placeAlongEdge(p1,p2,horizontal=False): pl = FreeCAD.Placement() pl.Base = p1 - up = FreeCAD.Vector(0,0,1) - if hasattr(FreeCAD,"DraftWorkingPlane"): - up = FreeCAD.DraftWorkingPlane.axis + import WorkingPlane + up = WorkingPlane.get_working_plane(update=False).axis zaxis = p2.sub(p1) yaxis = up.cross(zaxis) if yaxis.Length > 0: @@ -290,6 +289,7 @@ class _CommandStructure: self.bpoint = None self.bmode = False self.precastvalues = None + self.wp = None sel = FreeCADGui.Selection.getSelection() if sel: st = Draft.getObjectsOfType(sel,"Structure") @@ -309,15 +309,15 @@ class _CommandStructure: return # interactive mode - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + self.wp = WorkingPlane.get_working_plane() self.points = [] self.tracker = DraftTrackers.boxTracker() self.tracker.width(self.Width) self.tracker.height(self.Height) self.tracker.length(self.Length) - self.tracker.setRotation(FreeCAD.DraftWorkingPlane.getRotation().Rotation) + self.tracker.setRotation(self.wp.get_placement().Rotation) self.tracker.on() self.precast = ArchPrecast._PrecastTaskPanel() self.dents = ArchPrecast._DentsTaskPanel() @@ -344,6 +344,7 @@ class _CommandStructure: horiz = True # determines the type of rotation to apply to the final object FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Structure")) FreeCADGui.addModule("Arch") + FreeCADGui.addModule("WorkingPlane") if self.Profile is not None: try: # try to update latest precast values - fails if dialog has been destroyed already self.precastvalues = self.precast.getValues() @@ -361,8 +362,7 @@ class _CommandStructure: delta = FreeCAD.Vector(0,0-self.Width/2,0) else: delta = FreeCAD.Vector(-self.Length/2,-self.Width/2,0) - if hasattr(FreeCAD,"DraftWorkingPlane"): - delta = FreeCAD.DraftWorkingPlane.getRotation().multVec(delta) + delta = self.wp.get_global_coords(delta,as_vector=True) point = point.add(delta) if self.bpoint: self.bpoint = self.bpoint.add(delta) @@ -396,7 +396,8 @@ class _CommandStructure: FreeCADGui.doCommand('s.Placement = Arch.placeAlongEdge('+DraftVecUtils.toString(self.bpoint)+","+DraftVecUtils.toString(point)+","+str(horiz)+")") else: FreeCADGui.doCommand('s.Placement.Base = '+DraftVecUtils.toString(point)) - FreeCADGui.doCommand('s.Placement.Rotation = s.Placement.Rotation.multiply(FreeCAD.DraftWorkingPlane.getRotation().Rotation)') + FreeCADGui.doCommand('wp = WorkingPlane.get_working_plane()') + FreeCADGui.doCommand('s.Placement.Rotation = s.Placement.Rotation.multiply(wp.get_placement().Rotation)') FreeCADGui.addModule("Draft") FreeCADGui.doCommand("Draft.autogroup(s)") @@ -543,16 +544,14 @@ class _CommandStructure: delta = Vector(0,0,self.Height/2) else: delta = Vector(self.Length/2,0,0) - if hasattr(FreeCAD,"DraftWorkingPlane"): - delta = FreeCAD.DraftWorkingPlane.getRotation().multVec(delta) + delta = self.wp.get_global_coords(delta,as_vector=True) if self.modec.isChecked(): self.tracker.pos(point.add(delta)) self.tracker.on() else: if self.bpoint: delta = Vector(0,0,-self.Height/2) - if hasattr(FreeCAD,"DraftWorkingPlane"): - delta = FreeCAD.DraftWorkingPlane.getRotation().multVec(delta) + delta = self.wp.get_global_coords(delta,as_vector=True) self.tracker.update([self.bpoint.add(delta),point.add(delta)]) self.tracker.on() l = (point.sub(self.bpoint)).Length diff --git a/src/Mod/Arch/ArchTruss.py b/src/Mod/Arch/ArchTruss.py index 0205a2213e..c72bf501fa 100644 --- a/src/Mod/Arch/ArchTruss.py +++ b/src/Mod/Arch/ArchTruss.py @@ -105,8 +105,8 @@ class CommandArchTruss: else: # interactive line drawing self.points = [] - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + WorkingPlane.get_working_plane() if hasattr(FreeCADGui,"Snapper"): FreeCADGui.Snapper.getPoint(callback=self.getPoint) diff --git a/src/Mod/Arch/ArchVRM.py b/src/Mod/Arch/ArchVRM.py index b8fd376081..0cfb5a933d 100644 --- a/src/Mod/Arch/ArchVRM.py +++ b/src/Mod/Arch/ArchVRM.py @@ -65,7 +65,7 @@ class Renderer: self.wp = wp else: import WorkingPlane - self.wp = WorkingPlane.plane() + self.wp = WorkingPlane.PlaneBase() if DEBUG: print("Renderer initialized on " + str(self.wp)) @@ -92,7 +92,7 @@ class Renderer: def setWorkingPlane(self,wp): "sets a Draft WorkingPlane or Placement for this renderer" if isinstance(wp,FreeCAD.Placement): - self.wp.setFromPlacement(wp) + self.wp.align_to_placement(wp) else: self.wp = wp if DEBUG: print("Renderer set on " + str(self.wp)) @@ -198,7 +198,7 @@ class Renderer: for e in edges: v = e.Vertexes[0].Point #print(v) - v = self.wp.getLocalCoords(v) + v = self.wp.get_local_coords(v) verts.append(v) verts.append(verts[0]) if len(verts) > 2: @@ -211,7 +211,7 @@ class Renderer: return None else: # restoring flipped normals - vnorm = self.wp.getLocalCoords(norm) + vnorm = self.wp.get_local_coords(norm) if vnorm.getAngle(sh.normalAt(0,0)) > 1: sh.reverse() #print("VRM: projectFace end: ",len(sh.Vertexes)," verts") @@ -220,8 +220,8 @@ class Renderer: def projectEdge(self,edge): "projects a single edge on the WP" if len(edge.Vertexes) > 1: - v1 = self.wp.getLocalCoords(edge.Vertexes[0].Point) - v2 = self.wp.getLocalCoords(edge.Vertexes[-1].Point) + v1 = self.wp.get_local_coords(edge.Vertexes[0].Point) + v2 = self.wp.get_local_coords(edge.Vertexes[-1].Point) return Part.LineSegment(v1,v2).toShape() return edge @@ -293,7 +293,7 @@ class Renderer: # http://paulbourke.net/geometry/insidepoly/ count = 0 - p = self.wp.getLocalCoords(vert.Point) + p = self.wp.get_local_coords(vert.Point) for e in face[0].Edges: p1 = e.Vertexes[0].Point p2 = e.Vertexes[-1].Point diff --git a/src/Mod/Arch/ArchWall.py b/src/Mod/Arch/ArchWall.py index 17a41a8c22..e78c73ec2e 100644 --- a/src/Mod/Arch/ArchWall.py +++ b/src/Mod/Arch/ArchWall.py @@ -316,6 +316,7 @@ class _CommandWall: sel = FreeCADGui.Selection.getSelectionEx() done = False self.existing = [] + self.wp = None if sel: # automatic mode @@ -345,9 +346,9 @@ class _CommandWall: # interactive mode self.points = [] + import WorkingPlane + self.wp = WorkingPlane.get_working_plane() self.tracker = DraftTrackers.boxTracker() - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() FreeCADGui.Snapper.getPoint(callback=self.getPoint, extradlg=self.taskbox(), title=translate("Arch","First point of wall")+":") @@ -386,8 +387,8 @@ class _CommandWall: elif len(self.points) == 2: import Part - l = Part.LineSegment(FreeCAD.DraftWorkingPlane.getLocalCoords(self.points[0]), - FreeCAD.DraftWorkingPlane.getLocalCoords(self.points[1])) + l = Part.LineSegment(self.wp.get_local_coords(self.points[0]), + self.wp.get_local_coords(self.points[1])) self.tracker.finalize() FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Wall")) FreeCADGui.addModule("Arch") @@ -431,6 +432,8 @@ class _CommandWall: """ FreeCADGui.addModule("Draft") + FreeCADGui.addModule("WorkingPlane") + FreeCADGui.doCommand("wp = WorkingPlane.get_working_plane()") if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("WallSketches",True): # Use ArchSketch if SketchArch add-on is present try: @@ -439,13 +442,13 @@ class _CommandWall: FreeCADGui.doCommand('base=ArchSketchObject.makeArchSketch()') except: FreeCADGui.doCommand('base=FreeCAD.ActiveDocument.addObject("Sketcher::SketchObject","WallTrace")') - FreeCADGui.doCommand('base.Placement = FreeCAD.DraftWorkingPlane.getPlacement()') + FreeCADGui.doCommand('base.Placement = wp.get_placement()') FreeCADGui.doCommand('base.addGeometry(trace)') else: FreeCADGui.doCommand('base=Draft.makeLine(trace)') FreeCADGui.doCommand('FreeCAD.ActiveDocument.recompute()') FreeCADGui.doCommand('wall = Arch.makeWall(base,width='+str(self.Width)+',height='+str(self.Height)+',align="'+str(self.Align)+'")') - FreeCADGui.doCommand('wall.Normal = FreeCAD.DraftWorkingPlane.getNormal()') + FreeCADGui.doCommand('wall.Normal = wp.axis') if self.MultiMat: FreeCADGui.doCommand("wall.Material = FreeCAD.ActiveDocument."+self.MultiMat.Name) FreeCADGui.doCommand("Draft.autogroup(wall)") @@ -467,7 +470,7 @@ class _CommandWall: if FreeCADGui.Control.activeDialog(): b = self.points[0] - n = FreeCAD.DraftWorkingPlane.axis + n = self.wp.axis bv = point.sub(b) dv = bv.cross(n) dv = DraftVecUtils.scaleTo(dv,self.Width/2) diff --git a/src/Mod/Arch/ArchWindow.py b/src/Mod/Arch/ArchWindow.py index 580c24b20b..0ee9d6def2 100644 --- a/src/Mod/Arch/ArchWindow.py +++ b/src/Mod/Arch/ArchWindow.py @@ -186,6 +186,7 @@ class _CommandWindow: self.Include = True self.baseFace = None self.wparams = ["Width","Height","H1","H2","H3","W1","W2","O1","O2"] + self.wp = None # autobuild mode if FreeCADGui.Selection.getSelectionEx(): @@ -235,8 +236,8 @@ class _CommandWindow: return # interactive mode - if hasattr(FreeCAD,"DraftWorkingPlane"): - FreeCAD.DraftWorkingPlane.setup() + import WorkingPlane + self.wp = WorkingPlane.get_working_plane() self.tracker = DraftTrackers.boxTracker() self.tracker.length(self.Width) @@ -274,8 +275,8 @@ class _CommandWindow: point = point.add(FreeCAD.Vector(0,0,self.Sill)) FreeCAD.ActiveDocument.openTransaction(translate("Arch","Create Window")) - FreeCADGui.doCommand("import math, FreeCAD, Arch, DraftGeomUtils") - FreeCADGui.doCommand("wp = FreeCAD.DraftWorkingPlane") + FreeCADGui.doCommand("import math, FreeCAD, Arch, DraftGeomUtils, WorkingPlane") + FreeCADGui.doCommand("wp = WorkingPlane.get_working_plane()") if self.baseFace is not None: FreeCADGui.doCommand("face = FreeCAD.ActiveDocument." + self.baseFace[0].Name + ".Shape.Faces[" + str(self.baseFace[1]) + "]") @@ -342,9 +343,8 @@ class _CommandWindow: delta = FreeCAD.Vector(self.Width/2,self.Thickness/2,self.Height/2) delta = delta.add(FreeCAD.Vector(0,0,self.Sill)) - wp = FreeCAD.DraftWorkingPlane if self.baseFace is None: - rot = FreeCAD.Rotation(wp.u,wp.v,-wp.axis,"XZY") + rot = FreeCAD.Rotation(self.wp.u,self.wp.v,-self.wp.axis,"XZY") self.tracker.setRotation(rot) if info: if "Face" in info['Component']: @@ -353,7 +353,7 @@ class _CommandWindow: self.baseFace = [o,int(info['Component'][4:])-1] #print("switching to ",o.Label," face ",self.baseFace[1]) f = o.Shape.Faces[self.baseFace[1]] - p = DraftGeomUtils.placement_from_face(f,vec_z=wp.axis,rotated=True) + p = DraftGeomUtils.placement_from_face(f,vec_z=self.wp.axis,rotated=True) rot = p.Rotation self.tracker.setRotation(rot) r = self.tracker.trans.rotation.getValue().getValue() diff --git a/src/Mod/Arch/importIFCHelper.py b/src/Mod/Arch/importIFCHelper.py index 024fe78ed1..3e86fd522e 100644 --- a/src/Mod/Arch/importIFCHelper.py +++ b/src/Mod/Arch/importIFCHelper.py @@ -714,9 +714,7 @@ def getRotation(entity): w = FreeCAD.Vector(entity.Axis3.DirectionRatios) except AttributeError: return FreeCAD.Rotation() - import WorkingPlane - p = WorkingPlane.plane(u=u, v=v, w=w) - return p.getRotation().Rotation + return FreeCAD.Rotation(u, v, w, "ZYX") def getPlacement(entity,scaling=1000):