Skip to content

Commit

Permalink
Arch: area properties for Arch objects - fixes #2635
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Sep 4, 2016
1 parent d4c47c3 commit 11952d2
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Mod/Arch/ArchComponent.py
Expand Up @@ -300,11 +300,17 @@ def __init__(self,obj):
obj.addProperty("App::PropertyEnumeration","Role","Arch","The role of this object")
obj.addProperty("App::PropertyBool","MoveWithHost","Arch","Specifies if this object must move together when its host is moved")
obj.addProperty("App::PropertyLink","IfcProperties","Arch","Custom IFC properties and attributes")
obj.addProperty("App::PropertyArea","VerticalArea","Arch","The area of all vertical faces of this object")
obj.addProperty("App::PropertyArea","HorizontalArea","Arch","The area of the projection of this object onto the XY plane")
obj.addProperty("App::PropertyLength","PerimeterLength","Arch","The perimeter length of the horizontal area")
obj.Proxy = self
self.Type = "Component"
self.Subvolume = None
self.MoveWithHost = False
obj.Role = Roles
obj.setEditorMode("VerticalArea",1)
obj.setEditorMode("HorizontalArea",1)
obj.setEditorMode("PerimeterLength",1)

def execute(self,obj):
if obj.Base:
Expand Down Expand Up @@ -676,6 +682,45 @@ def applyShape(self,obj,shape,placement,allowinvalid=False,allownosolid=False):
FreeCAD.Console.PrintWarning(obj.Label + " " + translate("Arch","has an invalid shape")+"\n")
else:
FreeCAD.Console.PrintWarning(obj.Label + " " + translate("Arch","has a null shape")+"\n")
self.computeAreas(obj)

def computeAreas(self,obj):
"computes the area properties"
if not obj.Shape:
return
if obj.Shape.isNull():
return
if not obj.Shape.isValid():
return
if not obj.Shape.Faces:
return
a = 0
fset = []
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 ang < 1.5707:
fset.append(f)
if a and hasattr(obj,"VerticalArea"):
if obj.VerticalArea.Value != a:
obj.VerticalArea = a
if fset and hasattr(obj,"HorizontalArea"):
import Drawing,Part
pset = []
for f in fset:
pf = Part.Face(Part.Wire(Drawing.project(f,FreeCAD.Vector(0,0,1))[0].Edges))
pset.append(pf)
if pset:
self.flatarea = pset.pop()
for f in pset:
self.flatarea = self.flatarea.fuse(f)
self.flatarea = self.flatarea.removeSplitter()
if obj.HorizontalArea.Value != self.flatarea.Area:
obj.HorizontalArea = self.flatarea.Area
if hasattr(obj,"PerimeterLength") and (len(self.flatarea.Faces) == 1):
if obj.PerimeterLength.Value != self.flatarea.Faces[0].OuterWire.Length:
obj.PerimeterLength = self.flatarea.Faces[0].OuterWire.Length


class ViewProviderComponent:
Expand Down

0 comments on commit 11952d2

Please sign in to comment.