From 32d73bca15be5817412c867f6cbddc70ef410905 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Tue, 21 Apr 2020 13:43:28 +0200 Subject: [PATCH] Arch: Added IFC import option to replace project,site and building with a group --- .../Resources/ui/preferences-ifc-export.ui | 15 ++------ src/Mod/Arch/Resources/ui/preferences-ifc.ui | 31 +++++++++------ src/Mod/Arch/importIFC.py | 38 ++++++++++++++----- 3 files changed, 51 insertions(+), 33 deletions(-) diff --git a/src/Mod/Arch/Resources/ui/preferences-ifc-export.ui b/src/Mod/Arch/Resources/ui/preferences-ifc-export.ui index 3d1df06a58..5706fac8f6 100644 --- a/src/Mod/Arch/Resources/ui/preferences-ifc-export.ui +++ b/src/Mod/Arch/Resources/ui/preferences-ifc-export.ui @@ -7,26 +7,17 @@ 0 0 463 - 421 + 466 - IFC-Export + IFC export 6 - - 9 - - - 9 - - - 9 - - + 9 diff --git a/src/Mod/Arch/Resources/ui/preferences-ifc.ui b/src/Mod/Arch/Resources/ui/preferences-ifc.ui index 089594c571..632689be18 100644 --- a/src/Mod/Arch/Resources/ui/preferences-ifc.ui +++ b/src/Mod/Arch/Resources/ui/preferences-ifc.ui @@ -7,26 +7,17 @@ 0 0 463 - 495 + 577 - IFC + IFC import 6 - - 9 - - - 9 - - - 9 - - + 9 @@ -394,6 +385,22 @@ FreeCAD object properties + + + + If this option is checked, the default Project, Site and Building objects that are usually found in an IFC file are not imported, and all objects are placed in a Group + + + Replace Project, Site and Buiding by Group + + + ifcReplaceProject + + + Mod/Arch + + + diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index bd6e343660..dbc09b5f2b 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -161,7 +161,8 @@ def getPreferences(): 'IMPORT_PROPERTIES': p.GetBool("ifcImportProperties",False), 'SPLIT_LAYERS': p.GetBool("ifcSplitLayers",False), 'FITVIEW_ONIMPORT': p.GetBool("ifcFitViewOnImport",False), - 'ALLOW_INVALID': p.GetBool("ifcAllowInvalid",False) + 'ALLOW_INVALID': p.GetBool("ifcAllowInvalid",False), + 'REPLACE_PROJECT': p.GetBool("ifcReplaceProject",False) } if preferences['MERGE_MODE_ARCH'] > 0: @@ -299,23 +300,24 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None): FreeCADGui.ActiveDocument.activeView().viewAxonometric() # Create the base project object - if len(ifcfile.by_type("IfcProject")) > 0: - projectImporter = importIFCHelper.ProjectImporter(ifcfile, objects) - projectImporter.execute() - else: - # https://forum.freecadweb.org/viewtopic.php?f=39&t=40624 - print("No IfcProject found in the ifc file. Nothing imported") - return doc + if not preferences['REPLACE_PROJECT']: + if len(ifcfile.by_type("IfcProject")) > 0: + projectImporter = importIFCHelper.ProjectImporter(ifcfile, objects) + projectImporter.execute() + else: + # https://forum.freecadweb.org/viewtopic.php?f=39&t=40624 + print("No IfcProject found in the ifc file. Nothing imported") + return doc # handle IFC products for product in products: count += 1 - pid = product.id() guid = product.GlobalId ptype = product.is_a() + if preferences['DEBUG']: print(count,"/",len(products),"object #"+str(pid),":",ptype,end="") # build list of related property sets @@ -382,6 +384,15 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None): if ptype in preferences['SKIP']: # preferences-set type skip list if preferences['DEBUG']: print(" skipped.") continue + if preferences['REPLACE_PROJECT']: # options-enabled project/site/building skip + if ptype in ['IfcProject','IfcSite']: + if preferences['DEBUG']: print(" skipped.") + continue + elif ptype in ['IfcBuilding']: + if len(ifcfile.by_type("IfcBuilding")) == 1: + # let multiple buildings through... + if preferences['DEBUG']: print(" skipped.") + continue # check if this object is sharing its shape (mapped representation) clone = None @@ -1220,6 +1231,15 @@ def insert(filename,docname,skip=[],only=[],root=None,preferences=None): if l: setattr(p[0],p[1],l) + # Grouping everything if required + if preferences['REPLACE_PROJECT']: + rootgroup = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup","Group") + rootgroup.Label = os.path.basename(filename) + for key,obj in objects.items(): + # only add top-level objects + if not obj.InList: + rootgroup.addObject(obj) + FreeCAD.ActiveDocument.recompute() if ZOOMOUT and FreeCAD.GuiUp: