Arch: Small code optimizations to the multicore IFC importer

This commit is contained in:
Yorik van Havre
2020-06-25 15:38:31 +02:00
parent f3972e6fff
commit 5bf1eee0a1
4 changed files with 37 additions and 12 deletions

View File

@@ -166,6 +166,15 @@ class _Project(ArchIFC.IfcContext):
"""Method run when the document is restored. Re-add the properties."""
self.setProperties(obj)
def addObject(self,obj,child):
"Adds an object to the group of this BuildingPart"
if not child in obj.Group:
g = obj.Group
g.append(child)
obj.Group = g
class _ViewProviderProject(ArchIFCView.IfcContextView):
"""A View Provider for the project object.

View File

@@ -799,6 +799,16 @@ class _Site(ArchIFC.IfcProduct):
if obj.AdditionVolume.Value != addvol:
obj.AdditionVolume = addvol
def addObject(self,obj,child):
"Adds an object to the group of this BuildingPart"
if not child in obj.Group:
g = obj.Group
g.append(child)
obj.Group = g
class _ViewProviderSite:
"""A View Provider for the Site object.

View File

@@ -880,3 +880,18 @@ def applyColorDict(doc,colordict=None):
obj.ViewObject.Transparency = color[3]
else:
print("No valid color dict to apply")
def getParents(ifcobj):
"""finds the parent entities of an IFC entity"""
parentlist = []
if hasattr(ifcobj,"ContainedInStructure"):
for rel in ifcobj.ContainedInStructure:
parentlist.append(rel.RelatingStructure)
elif hasattr(ifcobj,"Decomposes"):
for rel in ifcobj.Decomposes:
if rel.is_a("IfcRelAggregates"):
parentlist.append(rel.RelatingObject)
return parentlist

View File

@@ -155,8 +155,6 @@ def createProduct(ifcproduct,brep):
else:
obj = Arch.makeComponent()
obj.Shape = shape
if ifcproduct.Name:
obj.Label = ifcproduct.Name
objects[ifcproduct.id()] = obj
setAttributes(obj,ifcproduct)
setProperties(obj,ifcproduct)
@@ -171,6 +169,8 @@ def setAttributes(obj,ifcproduct):
"""sets the IFC attributes of a component"""
ifctype = ArchIFC.uncamel(ifcproduct.is_a())
if ifcproduct.Name:
obj.Label = ifcproduct.Name
if ifctype in ArchIFC.IfcTypes:
obj.IfcType = ifctype
for attr in dir(ifcproduct):
@@ -237,15 +237,7 @@ def createModelStructure(obj,ifcobj):
global objects
parentlist = []
if hasattr(ifcobj,"ContainedInStructure"):
for rel in ifcobj.ContainedInStructure:
parentlist.append(rel.RelatingStructure)
elif hasattr(ifcobj,"Decomposes"):
for rel in ifcobj.Decomposes:
if rel.is_a("IfcRelAggregates"):
parentlist.append(rel.RelatingObject)
for parent in parentlist:
for parent in importIFCHelper.getParents(ifcobj):
if not parent.id() in objects:
if parent.is_a("IfcProject"):
parentobj = Arch.makeProject()
@@ -253,7 +245,6 @@ def createModelStructure(obj,ifcobj):
parentobj = Arch.makeSite()
else:
parentobj = Arch.makeBuildingPart()
parentobj.Label = parent.Name
setAttributes(parentobj,parent)
setProperties(parentobj,parent)
createModelStructure(parentobj,parent)