Skip to content

Commit

Permalink
Arch: Small code optimizations to the multicore IFC importer
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Jun 25, 2020
1 parent 7651e6d commit 742b6d4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/Mod/Arch/ArchProject.py
Expand Up @@ -166,6 +166,15 @@ def onDocumentRestored(self, obj):
"""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.
Expand Down
10 changes: 10 additions & 0 deletions src/Mod/Arch/ArchSite.py
Expand Up @@ -799,6 +799,16 @@ def computeAreas(self,obj):
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.
Expand Down
15 changes: 15 additions & 0 deletions src/Mod/Arch/importIFCHelper.py
Expand Up @@ -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
15 changes: 3 additions & 12 deletions src/Mod/Arch/importIFCmulticore.py
Expand Up @@ -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)
Expand All @@ -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):
Expand Down Expand Up @@ -237,23 +237,14 @@ 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()
elif parent.is_a("IfcSite"):
parentobj = Arch.makeSite()
else:
parentobj = Arch.makeBuildingPart()
parentobj.Label = parent.Name
setAttributes(parentobj,parent)
setProperties(parentobj,parent)
createModelStructure(parentobj,parent)
Expand Down

0 comments on commit 742b6d4

Please sign in to comment.