Skip to content

Commit

Permalink
Arch: Removed Armatures property from Structures + added Host propert…
Browse files Browse the repository at this point in the history
…y to Rebars
  • Loading branch information
yorikvanhavre committed Jul 5, 2017
1 parent a390d01 commit cab3358
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 28 deletions.
8 changes: 6 additions & 2 deletions src/Mod/Arch/ArchComponent.py
Expand Up @@ -158,7 +158,7 @@ def __init__(self):
# 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)
Expand Down Expand Up @@ -303,7 +303,6 @@ def retranslateUi(self, TaskPanel):
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:
Expand Down Expand Up @@ -868,6 +867,11 @@ def claimChildren(self):
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 []

Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchPrecast.py
Expand Up @@ -59,7 +59,6 @@ def __init__(self,obj):
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"]
Expand Down
58 changes: 35 additions & 23 deletions src/Mod/Arch/ArchRebar.py
Expand Up @@ -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:
Expand Down Expand Up @@ -171,6 +161,7 @@ def __init__(self,obj):
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)

Expand Down Expand Up @@ -245,18 +236,18 @@ def getRebarData(self,obj):
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:
Expand All @@ -267,7 +258,18 @@ def execute(self,obj):
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)
Expand All @@ -279,12 +281,18 @@ def execute(self,obj):
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
Expand All @@ -306,8 +314,12 @@ def execute(self,obj):
# 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
Expand All @@ -319,7 +331,7 @@ def execute(self,obj):
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
Expand Down
1 change: 0 additions & 1 deletion src/Mod/Arch/ArchStructure.py
Expand Up @@ -402,7 +402,6 @@ def __init__(self,obj):
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"))
Expand Down
47 changes: 46 additions & 1 deletion src/Mod/Draft/Draft.py
Expand Up @@ -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


Expand Down Expand Up @@ -6198,20 +6200,62 @@ def __init__(self,vobj):
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
return ":/icons/Draft_SelectPlane.svg"

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
Expand Down Expand Up @@ -6242,6 +6286,7 @@ def attach(self,vobj):
self.onChanged(vobj,"DisplaySize")
self.onChanged(vobj,"LineColor")
self.onChanged(vobj,"Transparency")
self.Object = vobj.Object

def getDisplayModes(self,vobj):
return ["Default"]
Expand Down
22 changes: 22 additions & 0 deletions src/Mod/Draft/DraftTools.py
Expand Up @@ -334,6 +334,28 @@ def Activated(self):
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
Expand Down

0 comments on commit cab3358

Please sign in to comment.