Skip to content

Commit

Permalink
Arch: support of stacked groups in IFC and added Internal property to…
Browse files Browse the repository at this point in the history
… Spaces
  • Loading branch information
yorikvanhavre committed Aug 1, 2018
1 parent 269a4a5 commit 5162f4e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/Mod/Arch/ArchSpace.py
Expand Up @@ -299,6 +299,9 @@ def setProperties(self,obj):
if not "Conditioning" in pl:
obj.addProperty("App::PropertyEnumeration","Conditioning", "Space",QT_TRANSLATE_NOOP("App::Property","The type of air conditioning of this space"))
obj.Conditioning = ConditioningTypes
if not "Internal" in pl:
obj.addProperty("App::PropertyBool", "Internal", "Space",QT_TRANSLATE_NOOP("App::Property","Specifies if this space is internal or external"))
obj.Internal = True
self.Type = "Space"
obj.setEditorMode("HorizontalArea",2)

Expand Down
43 changes: 38 additions & 5 deletions src/Mod/Arch/importIFC.py
Expand Up @@ -1016,6 +1016,7 @@ def insert(filename,docname,skip=[],only=[],root=None):

# processing remaining (normal) groups

swallowed = []
for host,children in groups.items():
if ifcfile[host].is_a("IfcGroup"):
if ifcfile[host].Name:
Expand All @@ -1024,10 +1025,12 @@ def insert(filename,docname,skip=[],only=[],root=None):
if DEBUG: print("no group name specified for entity: #", ifcfile[host].id(), ", entity type is used!")
grp_name = ifcfile[host].is_a() + "_" + str(ifcfile[host].id())
grp = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup",grp_name.encode("utf8"))
grp.Label = grp_name
objects[host] = grp
for child in children:
if child in objects.keys():
grp.addObject(objects[child])
swallowed.append(child)
else:
if DEBUG: print("unable to add object: #", child, " to group: #", ifcfile[host].id(), ", ", grp_name)

Expand Down Expand Up @@ -1082,7 +1085,11 @@ def insert(filename,docname,skip=[],only=[],root=None):

for host,children in additions.items():
if host in objects.keys():
cobs = [objects[child] for child in children if child in objects.keys()]
cobs = []
for child in children:
if child in objects.keys():
if not child in swallowed: # don't add objects already in groups
cobs.append(objects[child])
if cobs:
if DEBUG and first:
print("")
Expand Down Expand Up @@ -1449,6 +1456,7 @@ def export(exportList,filename):
groups = {} # { Host: [Child,Child,...] }
profiledefs = {} # { ProfileDefString:profiledef,...}
shapedefs = {} # { ShapeDefString:[shapes],... }
spatialelements = {} # {Name:IfcEntity, ... }

# reusable entity system

Expand Down Expand Up @@ -1611,9 +1619,20 @@ def export(exportList,filename):
kwargs.update({"OverallHeight": l/1000.0,
"OverallWidth": obj.Shape.BoundBox.ZLength/1000.0})
elif ifctype == "IfcSpace":
kwargs.update({"CompositionType": "ELEMENT",
"InteriorOrExteriorSpace": "INTERNAL",
"ElevationWithFlooring": obj.Shape.BoundBox.ZMin/1000.0})
internal = "NOTDEFINED"
if hasattr(obj,"Internal"):
if obj.Internal:
internal = "INTERNAL"
else:
internal = "EXTERNAL"
if schema == "IFC2X3":
kwargs.update({"CompositionType": "ELEMENT",
"InteriorOrExteriorSpace": internal,
"ElevationWithFlooring": obj.Shape.BoundBox.ZMin/1000.0})
else:
kwargs.update({"CompositionType": "ELEMENT",
"PredefinedType": internal,
"ElevationWithFlooring": obj.Shape.BoundBox.ZMin/1000.0})
elif ifctype == "IfcBuildingElementProxy":
if ifcopenshell.schema_identifier == "IFC4":
kwargs.update({"PredefinedType": "ELEMENT"})
Expand All @@ -1635,6 +1654,8 @@ def export(exportList,filename):
#print(obj.Label," : ",ifctype," : ",kwargs)
product = getattr(ifcfile,"create"+ifctype)(**kwargs)
products[obj.Name] = product
if ifctype in ["IfcBuilding","IfcBuildingStorey","IfcSite","IfcSpace"]:
spatialelements[obj.Name] = product

# additions

Expand Down Expand Up @@ -2009,7 +2030,7 @@ def export(exportList,filename):
for g in groups.keys():
okay = True
for c in groups[g]:
if Draft.getType(FreeCAD.ActiveDocument.getObject(c)) == "Group":
if Draft.getType(FreeCAD.ActiveDocument.getObject(c)) in ["Group","VisGroup"]:
okay = False
for s in sortedgroups:
if s[0] == c:
Expand All @@ -2020,6 +2041,7 @@ def export(exportList,filename):
if g[0] in groups.keys():
del groups[g[0]]
#print "sorted groups:",sortedgroups
containers = {}
for g in sortedgroups:
if g[1]:
children = []
Expand All @@ -2030,7 +2052,18 @@ def export(exportList,filename):
name = str(FreeCAD.ActiveDocument.getObject(g[0]).Label.encode("utf8"))
grp = ifcfile.createIfcGroup(ifcopenshell.guid.compress(uuid.uuid1().hex),history,name,'',None)
products[g[0]] = grp
spatialelements[g[0]] = grp
ass = ifcfile.createIfcRelAssignsToGroup(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'GroupLink','',children,None,grp)
# stack groups inside containers
stack = {}
for g in sortedgroups:
go = FreeCAD.ActiveDocument.getObject(g[0])
for parent in go.InList:
if hasattr(parent,"Group") and (go in parent.Group):
if (parent.Name in spatialelements) and (g[0] in spatialelements):
stack.setdefault(parent.Name,[]).append(spatialelements[g[0]])
for k,v in stack.items():
ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'GroupStackLink','',spatialelements[k],v)

# 2D objects

Expand Down

0 comments on commit 5162f4e

Please sign in to comment.