From 5bf1eee0a1256e35ded202fdce66d5d3cbae8ef5 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Thu, 25 Jun 2020 15:38:31 +0200 Subject: [PATCH] Arch: Small code optimizations to the multicore IFC importer --- src/Mod/Arch/ArchProject.py | 9 +++++++++ src/Mod/Arch/ArchSite.py | 10 ++++++++++ src/Mod/Arch/importIFCHelper.py | 15 +++++++++++++++ src/Mod/Arch/importIFCmulticore.py | 15 +++------------ 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/Mod/Arch/ArchProject.py b/src/Mod/Arch/ArchProject.py index 2c1bd7faee..ac8b5b9894 100644 --- a/src/Mod/Arch/ArchProject.py +++ b/src/Mod/Arch/ArchProject.py @@ -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. diff --git a/src/Mod/Arch/ArchSite.py b/src/Mod/Arch/ArchSite.py index e802da80e4..116fdc47e4 100644 --- a/src/Mod/Arch/ArchSite.py +++ b/src/Mod/Arch/ArchSite.py @@ -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. diff --git a/src/Mod/Arch/importIFCHelper.py b/src/Mod/Arch/importIFCHelper.py index d05f8dc719..45ad040422 100644 --- a/src/Mod/Arch/importIFCHelper.py +++ b/src/Mod/Arch/importIFCHelper.py @@ -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 diff --git a/src/Mod/Arch/importIFCmulticore.py b/src/Mod/Arch/importIFCmulticore.py index 5065a5135a..c254a6d7a5 100644 --- a/src/Mod/Arch/importIFCmulticore.py +++ b/src/Mod/Arch/importIFCmulticore.py @@ -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)