Arch: Added Footprint display mode to Spaces

This commit is contained in:
Yorik van Havre
2019-05-13 16:33:38 -03:00
parent f1eeae6754
commit 35900818e5

View File

@@ -286,8 +286,6 @@ class _Space(ArchComponent.Component):
obj.SpaceType = SpaceTypes
if not "FloorThickness" in pl:
obj.addProperty("App::PropertyLength", "FloorThickness","Space",QT_TRANSLATE_NOOP("App::Property","The thickness of the floor finish"))
if not "Zone" in pl:
obj.addProperty("App::PropertyLink", "Zone", "Space",QT_TRANSLATE_NOOP("App::Property","A zone this space is part of"))
if not "NumberOfPeople" in pl:
obj.addProperty("App::PropertyInteger", "NumberOfPeople","Space",QT_TRANSLATE_NOOP("App::Property","The number of people who typically occupy this space"))
if not "LightingPower" in pl:
@@ -433,9 +431,32 @@ class _Space(ArchComponent.Component):
"returns the horizontal area at the center of the space"
self.face = self.getFootprint(obj)
if self.face:
if not notouch:
if hasattr(obj,"PerimeterLength"):
if self.face.OuterWire.Length != obj.PerimeterLength.Value:
obj.PerimeterLength = self.face.OuterWire.Length
if hasattr(obj,"VerticalArea"):
a = 0
for f in obj.Shape.Faces:
ang = f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1))
if (ang > 1.57) and (ang < 1.571):
a += f.Area
if a != obj.VerticalArea.Value:
obj.VerticalArea = a
#print "area of ",obj.Label," : ",f.Area
return self.face.Area
else:
return 0
def getFootprint(self,obj):
"returns a face that represents the footprint of this space"
import Part,DraftGeomUtils
if not hasattr(obj.Shape,"CenterOfMass"):
return 0
return None
try:
pl = Part.makePlane(1,1)
pl.translate(obj.Shape.CenterOfMass)
@@ -444,24 +465,12 @@ class _Space(ArchComponent.Component):
e = sh.section(cutplane)
e = Part.__sortEdges__(e.Edges)
w = Part.Wire(e)
self.face = Part.Face(w)
dv = FreeCAD.Vector(obj.Shape.CenterOfMass.x,obj.Shape.CenterOfMass.y,obj.Shape.BoundBox.ZMin)
dv = dv.sub(obj.Shape.CenterOfMass)
w.translate(dv)
return Part.Face(w)
except Part.OCCError:
return 0
else:
if not notouch:
if hasattr(obj,"PerimeterLength"):
if w.Length != obj.PerimeterLength.Value:
obj.PerimeterLength = w.Length
if hasattr(obj,"VerticalArea"):
a = 0
for f in sh.Faces:
ang = f.normalAt(0,0).getAngle(FreeCAD.Vector(0,0,1))
if (ang > 1.57) and (ang < 1.571):
a += f.Area
if a != obj.VerticalArea.Value:
obj.VerticalArea = a
#print "area of ",obj.Label," : ",f.Area
return self.face.Area
return None
class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
@@ -505,6 +514,7 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
if not "TextAlign" in pl:
vobj.addProperty("App::PropertyEnumeration", "TextAlign", "Space",QT_TRANSLATE_NOOP("App::Property","The justification of the text"))
vobj.TextAlign = ["Left","Center","Right"]
vobj.TextAlign = "Center"
if not "Decimals" in pl:
vobj.addProperty("App::PropertyInteger", "Decimals", "Space",QT_TRANSLATE_NOOP("App::Property","The number of decimals to use for calculated texts"))
vobj.Decimals = Draft.getParam("dimPrecision",2)
@@ -555,6 +565,19 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
self.onChanged(vobj,"FirstLine")
self.onChanged(vobj,"LineSpacing")
self.onChanged(vobj,"FontName")
self.Object = vobj.Object
# footprint mode
self.fmat = coin.SoMaterial()
self.fcoords = coin.SoCoordinate3()
self.fset = coin.SoIndexedFaceSet()
fhints = coin.SoShapeHints()
fhints.vertexOrdering = fhints.COUNTERCLOCKWISE
sep = coin.SoSeparator()
sep.addChild(self.fmat)
sep.addChild(self.fcoords)
sep.addChild(fhints)
sep.addChild(self.fset)
vobj.RootNode.addChild(sep)
def updateData(self,obj,prop):
@@ -652,7 +675,7 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
elif prop == "TextPosition":
if hasattr(self,"coords") and hasattr(self,"header") and hasattr(vobj,"TextPosition") and hasattr(vobj,"FirstLine"):
pos = self.getTextPosition(vobj)
self.coords.translation.setValue([pos.x,pos.y,pos.z])
self.coords.translation.setValue([pos.x,pos.y,pos.z+0.01]) # adding small z offset to separate from bottom face
up = vobj.FirstLine.Value * vobj.LineSpacing
self.header.translation.setValue([0,up,0])
@@ -680,6 +703,14 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
self.label.whichChild = 0
else:
self.label.whichChild = -1
elif prop == "ShapeColor":
if hasattr(vobj,"ShapeColor"):
self.fmat.diffuseColor.setValue((vobj.ShapeColor[0],vobj.ShapeColor[1],vobj.ShapeColor[2]))
elif prop == "Transparency":
if hasattr(vobj,"Transparency"):
self.fmat.transparency.setValue(vobj.Transparency/100.0)
def setEdit(self,vobj,mode):
taskd = SpaceTaskPanel()
@@ -689,6 +720,33 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent):
FreeCADGui.Control.showDialog(taskd)
return True
def getDisplayModes(self,vobj):
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"):
face = self.Object.Proxy.getFootprint(self.Object)
if face:
verts = []
fdata = []
idx = 0
tri = face.tessellate(1)
for v in tri[0]:
verts.append([v.x,v.y,v.z])
for f in tri[1]:
fdata.extend([f[0]+idx,f[1]+idx,f[2]+idx,-1])
idx += len(tri[0])
self.fcoords.point.setValues(verts)
self.fset.coordIndex.setValues(0,len(fdata),fdata)
return "Points"
return ArchComponent.ViewProviderComponent.setDisplayMode(self,mode)
class SpaceTaskPanel(ArchComponent.ComponentTaskPanel):