diff --git a/src/Mod/Arch/ArchComponent.py b/src/Mod/Arch/ArchComponent.py index edd60c1f5a..9cb668b7a9 100644 --- a/src/Mod/Arch/ArchComponent.py +++ b/src/Mod/Arch/ArchComponent.py @@ -158,7 +158,7 @@ class ComponentTaskPanel: # the categories are shown only if they are not empty. self.obj = None - self.attribs = ["Base","Additions","Subtractions","Objects","Components","Axes","Fixtures","Armatures","Group"] + self.attribs = ["Base","Additions","Subtractions","Objects","Components","Axes","Fixtures","Group"] self.baseform = QtGui.QWidget() self.baseform.setObjectName("TaskPanel") self.grid = QtGui.QGridLayout(self.baseform) @@ -303,7 +303,6 @@ class ComponentTaskPanel: self.treeAxes.setText(0,QtGui.QApplication.translate("Arch", "Axes", None)) self.treeComponents.setText(0,QtGui.QApplication.translate("Arch", "Components", None)) self.treeFixtures.setText(0,QtGui.QApplication.translate("Arch", "Fixtures", None)) - self.treeArmatures.setText(0,QtGui.QApplication.translate("Arch", "Armatures", None)) self.treeGroup.setText(0,QtGui.QApplication.translate("Arch", "Group", None)) class Component: @@ -868,6 +867,11 @@ class ViewProviderComponent: objlink = getattr(self.Object,link) if objlink: c.append(objlink) + for link in self.Object.InList: + if hasattr(link,"Host"): + if link.Host: + if link.Host == self.Object: + c.append(link) return c return [] diff --git a/src/Mod/Arch/ArchPrecast.py b/src/Mod/Arch/ArchPrecast.py index 15210c8935..276028e42b 100644 --- a/src/Mod/Arch/ArchPrecast.py +++ b/src/Mod/Arch/ArchPrecast.py @@ -59,7 +59,6 @@ class _Precast(ArchComponent.Component): obj.addProperty("App::PropertyDistance","Length","Arch",QT_TRANSLATE_NOOP("App::Property","The length of this element")) obj.addProperty("App::PropertyDistance","Width","Arch",QT_TRANSLATE_NOOP("App::Property","The width of this element")) obj.addProperty("App::PropertyDistance","Height","Arch",QT_TRANSLATE_NOOP("App::Property","The height of this element")) - obj.addProperty("App::PropertyLinkList","Armatures","Arch",QT_TRANSLATE_NOOP("App::Property","Armatures contained in this element")) obj.addProperty("App::PropertyVectorList","Nodes","Arch",QT_TRANSLATE_NOOP("App::Property","The structural nodes of this element")) self.Type = "Precast" obj.Role = ["Beam","Column","Panel","Slab","Stairs"] diff --git a/src/Mod/Arch/ArchRebar.py b/src/Mod/Arch/ArchRebar.py index bd2859fc4b..4bc4e1c01c 100644 --- a/src/Mod/Arch/ArchRebar.py +++ b/src/Mod/Arch/ArchRebar.py @@ -69,17 +69,7 @@ def makeRebar(baseobj=None,sketch=None,diameter=None,amount=1,offset=None,name=" obj.Base = sketch if FreeCAD.GuiUp: sketch.ViewObject.hide() - p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") - if p.GetBool("archRemoveExternal",False): - a = baseobj.Armatures - a.append(obj) - baseobj.Armatures = a - else: - import Arch - host = getattr(Arch,"make"+Draft.getType(baseobj))(baseobj) - a = host.Armatures - a.append(obj) - host.Armatures = a + obj.Host = baseobj if diameter: obj.Diameter = diameter else: @@ -171,6 +161,7 @@ class _Rebar(ArchComponent.Component): obj.addProperty("App::PropertyVector","Direction","Arch",QT_TRANSLATE_NOOP("App::Property","The direction to use to spread the bars. Keep (0,0,0) for automatic direction.")) obj.addProperty("App::PropertyFloat","Rounding","Arch",QT_TRANSLATE_NOOP("App::Property","The fillet to apply to the angle of the base profile. This value is multiplied by the bar diameter.")) obj.addProperty("App::PropertyPlacementList","PlacementList","Arch",QT_TRANSLATE_NOOP("App::Property","List of placement of all the bars")) + obj.addProperty("App::PropertyLink","Host","Arch",QT_TRANSLATE_NOOP("App::Property","The structure object that hosts this rebar")) self.Type = "Rebar" obj.setEditorMode("Spacing",1) @@ -245,18 +236,18 @@ class _Rebar(ArchComponent.Component): wire.translate(vinterval) wires.append(wire) return [wires,obj.Diameter.Value/2] + + def onChanged(self,obj,prop): + if prop == "Host": + if hasattr(obj,"Host"): + if obj.Host: + # mark host to recompute so it can detect this object + obj.Host.touch() def execute(self,obj): if self.clone(obj): return - - if len(obj.InList) != 1: - return - if Draft.getType(obj.InList[0]) != "Structure": - return - if not obj.InList[0].Shape: - return if not obj.Base: return if not obj.Base.Shape: @@ -267,7 +258,18 @@ class _Rebar(ArchComponent.Component): return if not obj.Amount: return - father = obj.InList[0] + father = obj.Host + fathershape = None + if not father: + # support for old-style rebars + if obj.InList: + if hasattr(obj.InList[0],"Armatures"): + if obj in obj.InList[0].Armatures: + father = obj.InList[0] + if father: + if father.isDerivedFrom("Part::Feature"): + fathershape = father.Shape + wire = obj.Base.Shape.Wires[0] if hasattr(obj,"Rounding"): #print(obj.Rounding) @@ -279,12 +281,18 @@ class _Rebar(ArchComponent.Component): if not bpoint: return axis = obj.Base.Placement.Rotation.multVec(FreeCAD.Vector(0,0,-1)) - size = (ArchCommands.projectToVector(father.Shape.copy(),axis)).Length + if fathershape: + size = (ArchCommands.projectToVector(fathershape.copy(),axis)).Length + else: + size = 1 if hasattr(obj,"Direction"): if not DraftVecUtils.isNull(obj.Direction): axis = FreeCAD.Vector(obj.Direction) axis.normalize() - size = (ArchCommands.projectToVector(father.Shape.copy(),axis)).Length + if fathershape: + size = (ArchCommands.projectToVector(fathershape.copy(),axis)).Length + else: + size = 1 if hasattr(obj,"Distance"): if obj.Distance.Value: size = obj.Distance.Value @@ -306,8 +314,12 @@ class _Rebar(ArchComponent.Component): # building final shape shapes = [] placementlist = [] + if father: + rot = father.Placement.Rotation + else: + rot = FreeCAD.Rotation() if obj.Amount == 1: - barplacement = CalculatePlacement(obj.Amount, 1, size, axis, father.Placement.Rotation, obj.OffsetStart.Value, obj.OffsetEnd.Value) + barplacement = CalculatePlacement(obj.Amount, 1, size, axis, rot, obj.OffsetStart.Value, obj.OffsetEnd.Value) placementlist.append(barplacement) if hasattr(obj,"Spacing"): obj.Spacing = 0 @@ -319,7 +331,7 @@ class _Rebar(ArchComponent.Component): interval = size - (obj.OffsetStart.Value + obj.OffsetEnd.Value) interval = interval / (obj.Amount - 1) for i in range(obj.Amount): - barplacement = CalculatePlacement(obj.Amount, i+1, size, axis, father.Placement.Rotation, obj.OffsetStart.Value, obj.OffsetEnd.Value) + barplacement = CalculatePlacement(obj.Amount, i+1, size, axis, rot, obj.OffsetStart.Value, obj.OffsetEnd.Value) placementlist.append(barplacement) if hasattr(obj,"Spacing"): obj.Spacing = interval diff --git a/src/Mod/Arch/ArchStructure.py b/src/Mod/Arch/ArchStructure.py index cf1a8e2f76..15ae268bef 100644 --- a/src/Mod/Arch/ArchStructure.py +++ b/src/Mod/Arch/ArchStructure.py @@ -402,7 +402,6 @@ class _Structure(ArchComponent.Component): obj.addProperty("App::PropertyLength","Length","Arch",QT_TRANSLATE_NOOP("App::Property","The length of this element, if not based on a profile")) obj.addProperty("App::PropertyLength","Width","Arch",QT_TRANSLATE_NOOP("App::Property","The width of this element, if not based on a profile")) obj.addProperty("App::PropertyLength","Height","Arch",QT_TRANSLATE_NOOP("App::Property","The height or extrusion depth of this element. Keep 0 for automatic")) - obj.addProperty("App::PropertyLinkList","Armatures","Arch",QT_TRANSLATE_NOOP("App::Property","Armatures contained in this element")) obj.addProperty("App::PropertyVector","Normal","Arch",QT_TRANSLATE_NOOP("App::Property","The normal extrusion direction of this object (keep (0,0,0) for automatic normal)")) obj.addProperty("App::PropertyVectorList","Nodes","Arch",QT_TRANSLATE_NOOP("App::Property","The structural nodes of this element")) obj.addProperty("App::PropertyString","Profile","Arch",QT_TRANSLATE_NOOP("App::Property","A description of the standard profile this element is based upon")) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 52fb2e7a43..cb4bc51ab1 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -3614,6 +3614,8 @@ def makeWorkingPlaneProxy(placement): WorkingPlaneProxy(obj) if FreeCAD.GuiUp: ViewProviderWorkingPlaneProxy(obj.ViewObject) + obj.ViewObject.Proxy.writeCamera() + obj.ViewObject.Proxy.writeState() obj.Placement = placement @@ -6198,13 +6200,16 @@ class ViewProviderWorkingPlaneProxy: vobj.addProperty("App::PropertyPercent","Transparency","Base","") vobj.addProperty("App::PropertyFloat","LineWidth","Base","") vobj.addProperty("App::PropertyColor","LineColor","Base","") + vobj.addProperty("App::PropertyFloatList","ViewData","Base","") + vobj.addProperty("App::PropertyBool","RestoreView","Base","") + vobj.addProperty("App::PropertyMap","VisibilityMap","Base","") + vobj.addProperty("App::PropertyBool","RestoreState","Base","") vobj.DisplaySize = 100 vobj.ArrowSize = 5 vobj.Transparency = 70 vobj.LineWidth = 1 vobj.LineColor = (0.0,0.25,0.25,1.0) vobj.Proxy = self - self.Object = vobj.Object def getIcon(self): import Draft_rc @@ -6212,6 +6217,45 @@ class ViewProviderWorkingPlaneProxy: def claimChildren(self): return [] + + def doubleClicked(self,vobj): + FreeCADGui.runCommand("Draft_SelectPlane") + return True + + def setupContextMenu(self,vobj,menu): + from PySide import QtCore,QtGui + action1 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_SelectPlane.svg"),"Write camera position",menu) + QtCore.QObject.connect(action1,QtCore.SIGNAL("triggered()"),self.writeCamera) + menu.addAction(action1) + action2 = QtGui.QAction(QtGui.QIcon(":/icons/Draft_SelectPlane.svg"),"Write objects state",menu) + QtCore.QObject.connect(action2,QtCore.SIGNAL("triggered()"),self.writeState) + menu.addAction(action2) + + def writeCamera(self): + if hasattr(self,"Object"): + n = FreeCADGui.ActiveDocument.ActiveView.getCameraNode() + FreeCAD.Console.PrintMessage(QT_TRANSLATE_NOOP("Draft","Writing camera position")+"\n") + print FreeCADGui.ActiveDocument.ActiveView.getCamera() + cdata = list(n.position.getValue().getValue()) + cdata.extend(list(n.orientation.getValue().getValue())) + cdata.append(n.nearDistance.getValue()) + cdata.append(n.farDistance.getValue()) + cdata.append(n.aspectRatio.getValue()) + cdata.append(n.focalDistance.getValue()) + cdata.append(n.height.getValue()) + self.Object.ViewObject.ViewData = cdata + print self.Object.ViewObject.ViewData + + def writeState(self): + if hasattr(self,"Object"): + FreeCAD.Console.PrintMessage(QT_TRANSLATE_NOOP("Draft","Writing objects shown/hidden state")+"\n") + vis = {} + for o in FreeCAD.ActiveDocument.Objects: + if o.ViewObject: + vis[o.Name] = str(o.ViewObject.Visibility) + self.Object.ViewObject.VisibilityMap = vis + + def attach(self,vobj): from pivy import coin @@ -6242,6 +6286,7 @@ class ViewProviderWorkingPlaneProxy: self.onChanged(vobj,"DisplaySize") self.onChanged(vobj,"LineColor") self.onChanged(vobj,"Transparency") + self.Object = vobj.Object def getDisplayModes(self,vobj): return ["Default"] diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index b4af0ce051..37219add45 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -334,6 +334,28 @@ class SelectPlane(DraftTool): return elif Draft.getType(sel.Object) == "WorkingPlaneProxy": plane.setFromPlacement(sel.Object.Placement,rebase=True) + if hasattr(sel.Object.ViewObject,"RestoreView"): + if sel.Object.ViewObject.RestoreView: + if hasattr(sel.Object.ViewObject,"ViewData"): + if len(sel.Object.ViewObject.ViewData) == 12: + d = sel.Object.ViewObject.ViewData + c = FreeCADGui.ActiveDocument.ActiveView.getCameraNode() + c.position.setValue([d[0],d[1],d[2]]) + c.orientation.setValue([d[3],d[4],d[5],d[6]]) + c.nearDistance.setValue(d[7]) + c.farDistance.setValue(d[8]) + c.aspectRatio.setValue(d[9]) + c.focalDistance.setValue(d[10]) + c.height.setValue(d[11]) + if hasattr(sel.Object.ViewObject,"RestoreState"): + if sel.Object.ViewObject.RestoreState: + if hasattr(sel.Object.ViewObject,"VisibilityMap"): + if sel.Object.ViewObject.VisibilityMap: + for k,v in sel.Object.ViewObject.VisibilityMap.items(): + print k,v + o = FreeCAD.ActiveDocument.getObject(k) + if o: + o.ViewObject.Visibility = bool(v) self.display(plane.axis) self.finish() return