From 5625bab1703bd3d4810b1730a34e852a66c99a00 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 7 Mar 2017 00:34:30 -0300 Subject: [PATCH] Arch: Added Hires property + display mode to all Arch objects --- src/Mod/Arch/ArchComponent.py | 48 ++++++++++++++++++++++++++++++++++- src/Mod/Arch/ArchEquipment.py | 33 ------------------------ src/Mod/Arch/ArchWall.py | 12 ++++----- 3 files changed, 53 insertions(+), 40 deletions(-) diff --git a/src/Mod/Arch/ArchComponent.py b/src/Mod/Arch/ArchComponent.py index c2f4990bc9c6..81b14af937f9 100644 --- a/src/Mod/Arch/ArchComponent.py +++ b/src/Mod/Arch/ArchComponent.py @@ -323,6 +323,7 @@ def __init__(self,obj): obj.addProperty("App::PropertyArea","VerticalArea","Arch",QT_TRANSLATE_NOOP("App::Property","The area of all vertical faces of this object")) obj.addProperty("App::PropertyArea","HorizontalArea","Arch",QT_TRANSLATE_NOOP("App::Property","The area of the projection of this object onto the XY plane")) obj.addProperty("App::PropertyLength","PerimeterLength","Arch",QT_TRANSLATE_NOOP("App::Property","The perimeter length of the horizontal area")) + obj.addProperty("App::PropertyLink","Hires","Arch",QT_TRANSLATE_NOOP("App::Property","An optional higher-resolution mesh or shape for this object")) obj.Proxy = self self.Type = "Component" self.Subvolume = None @@ -720,13 +721,58 @@ def onChanged(self,vobj,prop): return def attach(self,vobj): + from pivy import coin self.Object = vobj.Object + self.hiresgroup = coin.SoSeparator() + self.meshcolor = coin.SoBaseColor() + self.hiresgroup.addChild(self.meshcolor) + self.hiresgroup.setName("Hires") + vobj.addDisplayMode(self.hiresgroup,"Hires"); return def getDisplayModes(self,vobj): - return [] + modes=["Hires"] + return modes def setDisplayMode(self,mode): + if hasattr(self,"meshnode"): + if self.meshnode: + self.hiresgroup.removeChild(self.meshnode) + del self.meshnode + if mode == "Hires": + from pivy import coin + m = None + if hasattr(self,"Object"): + if hasattr(self.Object,"Hires"): + if self.Object.Hires: + # if the file was recently loaded, the node is not present yet + self.Object.Hires.ViewObject.show() + self.Object.Hires.ViewObject.hide() + m = self.Object.Hires.ViewObject.RootNode + if not m: + if hasattr(self.Object,"CloneOf"): + if self.Object.CloneOf: + if hasattr(self.Object.CloneOf,"Hires"): + if self.Object.CloneOf.Hires: + # if the file was recently loaded, the node is not present yet + self.Object.CloneOf.Hires.ViewObject.show() + self.Object.CloneOf.Hires.ViewObject.hide() + m = self.Object.CloneOf.Hires.ViewObject.RootNode + if m: + self.meshnode = m.copy() + for c in self.meshnode.getChildren(): + # switch the first found SoSwitch on + if isinstance(c,coin.SoSwitch): + num = 0 + if c.getNumChildren() > 0: + if c.getChild(0).getName() == "Hires": + num = 1 + print "getting node ",num," for ",self.Object.Label + c.whichChild = num + break + self.hiresgroup.addChild(self.meshnode) + else: + return "Flat Lines" return mode def __getstate__(self): diff --git a/src/Mod/Arch/ArchEquipment.py b/src/Mod/Arch/ArchEquipment.py index 1aa8c4c0a961..93d94a0cc4f1 100644 --- a/src/Mod/Arch/ArchEquipment.py +++ b/src/Mod/Arch/ArchEquipment.py @@ -264,7 +264,6 @@ def __init__(self,obj): obj.addProperty("App::PropertyString","Url","Arch",QT_TRANSLATE_NOOP("App::Property","The url of the product page of this equipment")) obj.addProperty("App::PropertyVectorList","SnapPoints","Arch",QT_TRANSLATE_NOOP("App::Property","Additional snap points for this equipment")) obj.addProperty("App::PropertyFloat","EquipmentPower","Arch",QT_TRANSLATE_NOOP("App::Property","The electric power needed by this equipment in Watts")) - obj.addProperty("App::PropertyLink","Hires","Arch",QT_TRANSLATE_NOOP("App::Property","An optional higher-resolution mesh or shape for this object")) self.Type = "Equipment" obj.Role = Roles obj.Proxy = self @@ -319,10 +318,6 @@ def attach(self, vobj): sep.addChild(symbol) rn = vobj.RootNode rn.addChild(sep) - self.hiresgroup = coin.SoGroup() - self.meshcolor = coin.SoBaseColor() - self.hiresgroup.addChild(self.meshcolor) - vobj.addDisplayMode(self.hiresgroup,"Hires"); ArchComponent.ViewProviderComponent.attach(self,vobj) def updateData(self, obj, prop): @@ -333,34 +328,6 @@ def updateData(self, obj, prop): else: self.coords.point.deleteValues(0) - def getDisplayModes(self,vobj): - modes=["Hires"] - return modes - - def setDisplayMode(self,mode): - if mode == "Hires": - m = None - if hasattr(self,"Object"): - if hasattr(self.Object,"Hires"): - if self.Object.Hires: - m = self.Object.Hires.ViewObject.RootNode - if not m: - if hasattr(self.Object,"CloneOf"): - if self.Object.CloneOf: - if hasattr(self.Object.CloneOf,"Hires"): - if self.Object.CloneOf.Hires: - m = self.Object.CloneOf.Hires.ViewObject.RootNode - if m: - self.meshnode = m.copy() - self.meshnode.getChild(1).whichChild = 0 - self.hiresgroup.addChild(self.meshnode) - else: - if hasattr(self,"meshnode"): - if self.meshnode: - self.hiresgroup.removeChild(self.meshnode) - del self.meshnode - return mode - if FreeCAD.GuiUp: FreeCADGui.addCommand('Arch_Equipment',_CommandEquipment()) diff --git a/src/Mod/Arch/ArchWall.py b/src/Mod/Arch/ArchWall.py index 071430d9e578..049a5999bc19 100644 --- a/src/Mod/Arch/ArchWall.py +++ b/src/Mod/Arch/ArchWall.py @@ -644,18 +644,21 @@ def attach(self,vobj): sep.addChild(self.fcoords) sep.addChild(self.fset) vobj.RootNode.addChild(sep) - return + ArchComponent.ViewProviderComponent.attach(self,vobj) def updateData(self,obj,prop): if prop in ["Placement","Shape"]: if obj.ViewObject.DisplayMode == "Footprint": obj.ViewObject.Proxy.setDisplayMode("Footprint") + ArchComponent.ViewProviderComponent.updateData(self,obj,prop) def getDisplayModes(self,vobj): - modes=["Footprint"] + modes = ArchComponent.ViewProviderComponent.getDisplayModes(self,vobj)+["Footprint"] return modes def setDisplayMode(self,mode): + self.fset.coordIndex.deleteValues(0) + self.fcoords.point.deleteValues(0) if mode == "Footprint": if hasattr(self,"Object"): faces = self.Object.Proxy.getFootprint(self.Object) @@ -673,10 +676,7 @@ def setDisplayMode(self,mode): self.fcoords.point.setValues(verts) self.fset.coordIndex.setValues(0,len(fdata),fdata) return "Wireframe" - else: - self.fset.coordIndex.deleteValues(0) - self.fcoords.point.deleteValues(0) - return mode + return ArchComponent.ViewProviderComponent.setDisplayMode(self,mode) if FreeCAD.GuiUp: