Skip to content

Commit

Permalink
Arch: Add default storey when exporting to IFC + allow all Arch objec…
Browse files Browse the repository at this point in the history
…ts to have Undefined role
  • Loading branch information
yorikvanhavre committed Feb 17, 2017
1 parent 686ba70 commit b115d79
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchEquipment.py
Expand Up @@ -52,7 +52,7 @@ def QT_TRANSLATE_NOOP(ctxt,txt):
# 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"):
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchFrame.py
Expand Up @@ -49,7 +49,7 @@ def QT_TRANSLATE_NOOP(ctxt,txt):
__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
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchSpace.py
Expand Up @@ -27,7 +27,7 @@
__author__ = "Yorik van Havre"
__url__ = "http://www.freecadweb.org"

Roles = ["Space"]
Roles = ["Undefined","Space"]

SpaceTypes = [
"Undefined",
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchStructure.py
Expand Up @@ -54,7 +54,7 @@ def QT_TRANSLATE_NOOP(ctxt,txt):


# 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=[]
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchWall.py
Expand Up @@ -50,7 +50,7 @@ def QT_TRANSLATE_NOOP(ctxt,txt):
__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
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Arch/ArchWindow.py
Expand Up @@ -56,7 +56,7 @@ def QT_TRANSLATE_NOOP(ctxt,txt):
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"):
Expand Down
20 changes: 19 additions & 1 deletion src/Mod/Arch/importIFC.py
Expand Up @@ -36,6 +36,7 @@
# 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
Expand Down Expand Up @@ -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, ... }
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)]
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,"...")

Expand Down

0 comments on commit b115d79

Please sign in to comment.