From b115d794a73116bf46652e236f1da1c859dd3ae0 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Fri, 17 Feb 2017 20:47:39 -0200 Subject: [PATCH] Arch: Add default storey when exporting to IFC + allow all Arch objects to have Undefined role --- src/Mod/Arch/ArchEquipment.py | 2 +- src/Mod/Arch/ArchFrame.py | 2 +- src/Mod/Arch/ArchSpace.py | 2 +- src/Mod/Arch/ArchStructure.py | 2 +- src/Mod/Arch/ArchWall.py | 2 +- src/Mod/Arch/ArchWindow.py | 2 +- src/Mod/Arch/importIFC.py | 20 +++++++++++++++++++- 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/Mod/Arch/ArchEquipment.py b/src/Mod/Arch/ArchEquipment.py index 26755e365..1aa8c4c0a 100644 --- a/src/Mod/Arch/ArchEquipment.py +++ b/src/Mod/Arch/ArchEquipment.py @@ -52,7 +52,7 @@ else: # or hydraulic appliances in a building # presets -Roles = ["Furniture", "Hydro Equipment", "Electric Equipment"] +Roles = ["Undefined","Furniture", "Hydro Equipment", "Electric Equipment"] def makeEquipment(baseobj=None,placement=None,name="Equipment"): diff --git a/src/Mod/Arch/ArchFrame.py b/src/Mod/Arch/ArchFrame.py index 40d7d5f8d..24bd7548c 100644 --- a/src/Mod/Arch/ArchFrame.py +++ b/src/Mod/Arch/ArchFrame.py @@ -49,7 +49,7 @@ __author__ = "Yorik van Havre" __url__ = "http://www.freecadweb.org" # Possible roles for frames -Roles = ['Covering','Member','Railing','Shading Device','Tendon'] +Roles = ['Undefined','Covering','Member','Railing','Shading Device','Tendon'] def makeFrame(baseobj,profile,name=translate("Arch","Frame")): """makeFrame(baseobj,profile,[name]): creates a frame object from a base sketch (or any other object diff --git a/src/Mod/Arch/ArchSpace.py b/src/Mod/Arch/ArchSpace.py index f4c28de43..45b8704e9 100644 --- a/src/Mod/Arch/ArchSpace.py +++ b/src/Mod/Arch/ArchSpace.py @@ -27,7 +27,7 @@ __title__="FreeCAD Arch Space" __author__ = "Yorik van Havre" __url__ = "http://www.freecadweb.org" -Roles = ["Space"] +Roles = ["Undefined","Space"] SpaceTypes = [ "Undefined", diff --git a/src/Mod/Arch/ArchStructure.py b/src/Mod/Arch/ArchStructure.py index 38f474342..3e31b9c6a 100644 --- a/src/Mod/Arch/ArchStructure.py +++ b/src/Mod/Arch/ArchStructure.py @@ -54,7 +54,7 @@ __url__ = "http://www.freecadweb.org" # Possible roles for structural elements -Roles = ["Beam","Column","Slab","Wall","Curtain Wall","Roof","Foundation","Pile","Tendon"] +Roles = ["Undefined","Beam","Column","Slab","Wall","Curtain Wall","Roof","Foundation","Pile","Tendon"] #Reads preset profiles and categorizes them Categories=[] diff --git a/src/Mod/Arch/ArchWall.py b/src/Mod/Arch/ArchWall.py index a6d8efef2..071430d9e 100644 --- a/src/Mod/Arch/ArchWall.py +++ b/src/Mod/Arch/ArchWall.py @@ -50,7 +50,7 @@ __author__ = "Yorik van Havre" __url__ = "http://www.freecadweb.org" # Possible roles for walls -Roles = ['Wall','Wall Layer','Beam','Column','Curtain Wall'] +Roles = ['Undefined','Wall','Wall Layer','Beam','Column','Curtain Wall'] def makeWall(baseobj=None,length=None,width=None,height=None,align="Center",face=None,name="Wall"): '''makeWall([obj],[length],[width],[height],[align],[face],[name]): creates a wall based on the diff --git a/src/Mod/Arch/ArchWindow.py b/src/Mod/Arch/ArchWindow.py index b9bcc570a..2d2faca5e 100644 --- a/src/Mod/Arch/ArchWindow.py +++ b/src/Mod/Arch/ArchWindow.py @@ -56,7 +56,7 @@ AllowedHosts = ["Wall","Structure","Roof"] WindowPresets = ["Fixed", "Open 1-pane", "Open 2-pane", "Sash 2-pane", "Sliding 2-pane", "Simple door", "Glass door"] WindowOpeningModes = ["None","Arc 90","Arc 90 inv","Arc 45","Arc 45 inv","Arc 180","Arc 180 inv","Triangle","Triangle inv","Sliding","Sliding inv"] -Roles = ["Window","Door"] +Roles = ["Undefined","Window","Door"] def makeWindow(baseobj=None,width=None,height=None,parts=None,name="Window"): diff --git a/src/Mod/Arch/importIFC.py b/src/Mod/Arch/importIFC.py index b5e49a29e..ae90d4f92 100644 --- a/src/Mod/Arch/importIFC.py +++ b/src/Mod/Arch/importIFC.py @@ -36,6 +36,7 @@ import os,time,tempfile,uuid,FreeCAD,Part,Draft,Arch,math,DraftVecUtils # This module provides tools to import and export IFC files. DEBUG = False +ADDDEFAULTSTOREY = True if open.__module__ in ['__builtin__','io']: pyopen = open # because we'll redefine open below @@ -1017,6 +1018,7 @@ def export(exportList,filename): if obj.Shape: if obj.Shape.Edges and (not obj.Shape.Faces): annotations.append(obj) + objectslist = [obj for obj in objectslist if not obj in annotations] objectslist = Arch.pruneIncluded(objectslist) products = {} # { Name: IfcEntity, ... } surfstyles = {} # { (r,g,b): IfcEntity, ... } @@ -1233,6 +1235,7 @@ def export(exportList,filename): buildings = [] floors = [] treated = [] + defaulthost = [] for floor in Draft.getObjectsOfType(objectslist,"Floor"): objs = Draft.getGroupContents(floor,walls=True) objs = Arch.pruneIncluded(objs) @@ -1246,6 +1249,7 @@ def export(exportList,filename): if children: ifcfile.createIfcRelContainedInSpatialStructure(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'StoreyLink','',children,f) floors.append(floor.Name) + defaulthost = f for building in Draft.getObjectsOfType(objectslist,"Building"): objs = Draft.getGroupContents(building,walls=True,addgroups=True) objs = Arch.pruneIncluded(objs) @@ -1267,6 +1271,7 @@ def export(exportList,filename): if childfloors: ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'BuildingLink','',b,childfloors) buildings.append(b) + #defaulthost = b for site in Draft.getObjectsOfType(objectslist,"Site"): objs = Draft.getGroupContents(site,walls=True,addgroups=True) objs = Arch.pruneIncluded(objs) @@ -1280,6 +1285,8 @@ def export(exportList,filename): childbuildings.append(products[c.Name]) treated.append(c.Name) sites.append(products[site.Name]) + if not defaulthost: + defaulthost = products[site.Name] if not sites: if DEBUG: print ("No site found. Adding default site") sites = [ifcfile.createIfcSite(ifcopenshell.guid.compress(uuid.uuid1().hex),history,"Default Site",'',None,None,None,None,"ELEMENT",None,None,None,None,None)] @@ -1295,7 +1302,10 @@ def export(exportList,filename): if not(Draft.getType(FreeCAD.ActiveDocument.getObject(k)) in ["Site","Building","Floor"]): untreated.append(v) if untreated: - ifcfile.createIfcRelContainedInSpatialStructure(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'BuildingLinkUnassignedObjects','',untreated,buildings[0]) + if not defaulthost: + defaulthost = ifcfile.createIfcBuildingStorey(ifcopenshell.guid.compress(uuid.uuid1().hex),history,"Default Storey",'',None,None,None,None,"ELEMENT",None) + ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'DefaultStoreyLink','',buildings[0],[defaulthost]) + ifcfile.createIfcRelContainedInSpatialStructure(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'UnassignedObjectsLink','',untreated,defaulthost) # materials materials = {} @@ -1359,6 +1369,7 @@ def export(exportList,filename): # 2D objects if EXPORT_2D: + annos = [] curvestyles = {} if annotations and DEBUG: print ("exporting 2D objects...") for anno in annotations: @@ -1403,6 +1414,13 @@ def export(exportList,filename): shp = ifcfile.createIfcShapeRepresentation(context,'Annotation','Annotation2D',reps) rep = ifcfile.createIfcProductDefinitionShape(None,None,[shp]) ann = ifcfile.createIfcAnnotation(ifcopenshell.guid.compress(uuid.uuid1().hex),history,anno.Label.encode('utf8'),'',None,gpl,rep) + annos.append(ann) + if annos: + if not defaulthost: + defaulthost = ifcfile.createIfcBuildingStorey(ifcopenshell.guid.compress(uuid.uuid1().hex),history,"Default Storey",'',None,None,None,None,"ELEMENT",None) + ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'DefaultStoreyLink','',buildings[0],[defaulthost]) + ifcfile.createIfcRelContainedInSpatialStructure(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'AnnotationsLink','',annos,defaulthost) + if DEBUG: print("writing ",filename,"...")