Arch: remove trailling white spaces

This commit is contained in:
Bernd Hahnebach 2015-08-11 20:55:16 +02:00
parent 4dc09efd0d
commit 73808aa15d

View File

@ -1,7 +1,7 @@
#*************************************************************************** #***************************************************************************
#* * #* *
#* Copyright (c) 2014 * #* Copyright (c) 2014 *
#* Yorik van Havre <yorik@uncreated.net> * #* Yorik van Havre <yorik@uncreated.net> *
#* * #* *
#* This program is free software; you can redistribute it and/or modify * #* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU Lesser General Public License (LGPL) * #* it under the terms of the GNU Lesser General Public License (LGPL) *
@ -32,7 +32,7 @@ if open.__module__ == '__builtin__':
# which IFC type must create which FreeCAD type # which IFC type must create which FreeCAD type
typesmap = { "Site": ["IfcSite"], typesmap = { "Site": ["IfcSite"],
"Building": ["IfcBuilding"], "Building": ["IfcBuilding"],
"Floor": ["IfcBuildingStorey"], "Floor": ["IfcBuildingStorey"],
"Structure": ["IfcBeam", "IfcBeamStandardCase", "IfcColumn", "IfcColumnStandardCase", "IfcSlab", "IfcFooting", "IfcPile", "IfcTendon"], "Structure": ["IfcBeam", "IfcBeamStandardCase", "IfcColumn", "IfcColumnStandardCase", "IfcSlab", "IfcFooting", "IfcPile", "IfcTendon"],
"Wall": ["IfcWall", "IfcWallStandardCase", "IfcCurtainWall"], "Wall": ["IfcWall", "IfcWallStandardCase", "IfcCurtainWall"],
@ -94,7 +94,7 @@ END-ISO-10303-21;
""" """
def decode(filename,utf=False): def decode(filename,utf=False):
if isinstance(filename,unicode): if isinstance(filename,unicode):
# workaround since ifcopenshell currently can't handle unicode filenames # workaround since ifcopenshell currently can't handle unicode filenames
if utf: if utf:
encoding = "utf8" encoding = "utf8"
@ -114,29 +114,29 @@ def doubleClickTree(item,column):
addr[0].setSelected(True) addr[0].setSelected(True)
def explore(filename=None): def explore(filename=None):
"""explore([filename]): opens a dialog showing """explore([filename]): opens a dialog showing
the contents of an IFC file. If no filename is given, a dialog will the contents of an IFC file. If no filename is given, a dialog will
pop up to choose a file.""" pop up to choose a file."""
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
DEBUG = p.GetBool("ifcDebug",False) DEBUG = p.GetBool("ifcDebug",False)
try: try:
import ifcopenshell import ifcopenshell
except: except:
FreeCAD.Console.PrintError("IfcOpenShell was not found on this system. IFC support is disabled\n") FreeCAD.Console.PrintError("IfcOpenShell was not found on this system. IFC support is disabled\n")
return return
if not filename: if not filename:
from PySide import QtGui from PySide import QtGui
filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'IFC files','*.ifc') filename = QtGui.QFileDialog.getOpenFileName(QtGui.qApp.activeWindow(),'IFC files','*.ifc')
if filename: if filename:
filename = filename[0] filename = filename[0]
from PySide import QtCore,QtGui from PySide import QtCore,QtGui
filename = decode(filename,utf=True) filename = decode(filename,utf=True)
if not os.path.exists(filename): if not os.path.exists(filename):
print "File not found" print "File not found"
return return
@ -156,7 +156,7 @@ def explore(filename=None):
bold = QtGui.QFont() bold = QtGui.QFont()
bold.setWeight(75) bold.setWeight(75)
bold.setBold(True) bold.setBold(True)
entities = ifc.by_type("IfcRoot") entities = ifc.by_type("IfcRoot")
entities += ifc.by_type("IfcRepresentation") entities += ifc.by_type("IfcRepresentation")
entities += ifc.by_type("IfcRepresentationItem") entities += ifc.by_type("IfcRepresentationItem")
@ -165,7 +165,7 @@ def explore(filename=None):
entities += ifc.by_type("IfcPhysicalSimpleQuantity") entities += ifc.by_type("IfcPhysicalSimpleQuantity")
entities += ifc.by_type("IfcMaterial") entities += ifc.by_type("IfcMaterial")
entities = sorted(entities, key=lambda eid: eid.id()) entities = sorted(entities, key=lambda eid: eid.id())
done = [] done = []
for entity in entities: for entity in entities:
@ -203,7 +203,7 @@ def explore(filename=None):
item.setIcon(1,QtGui.QIcon(":icons/Arch_Material.svg")) item.setIcon(1,QtGui.QIcon(":icons/Arch_Material.svg"))
item.setText(2,str(entity.is_a())) item.setText(2,str(entity.is_a()))
item.setFont(2,bold); item.setFont(2,bold);
i = 0 i = 0
while True: while True:
try: try:
@ -242,7 +242,7 @@ def explore(filename=None):
t = str(argitem) t = str(argitem)
else: else:
colored = True colored = True
t = "Entity #" + str(argitem.id()) + ": " + str(argitem.is_a()) t = "Entity #" + str(argitem.id()) + ": " + str(argitem.is_a())
else: else:
t = argitem t = argitem
t = " " + str(t) t = " " + str(t)
@ -251,14 +251,14 @@ def explore(filename=None):
if colored: if colored:
item.setForeground(2,QtGui.QBrush(QtGui.QColor("#005AFF"))) item.setForeground(2,QtGui.QBrush(QtGui.QColor("#005AFF")))
i += 1 i += 1
d = QtGui.QDialog() d = QtGui.QDialog()
d.setObjectName("IfcExplorer") d.setObjectName("IfcExplorer")
d.setWindowTitle("Ifc Explorer") d.setWindowTitle("Ifc Explorer")
d.resize(640, 480) d.resize(640, 480)
layout = QtGui.QVBoxLayout(d) layout = QtGui.QVBoxLayout(d)
layout.addWidget(tree) layout.addWidget(tree)
tree.itemDoubleClicked.connect(doubleClickTree) tree.itemDoubleClicked.connect(doubleClickTree)
d.exec_() d.exec_()
@ -282,7 +282,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
skip can contain a list of ids of objects to be skipped, only can restrict the import to skip can contain a list of ids of objects to be skipped, only can restrict the import to
certain object ids (will also get their children) and root can be used to certain object ids (will also get their children) and root can be used to
import only the derivates of a certain element type (default = ifcProduct).""" import only the derivates of a certain element type (default = ifcProduct)."""
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
DEBUG = p.GetBool("ifcDebug",False) DEBUG = p.GetBool("ifcDebug",False)
PREFIX_NUMBERS = p.GetBool("ifcPrefixNumbers",False) PREFIX_NUMBERS = p.GetBool("ifcPrefixNumbers",False)
@ -300,7 +300,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
GET_EXTRUSIONS = False GET_EXTRUSIONS = False
if not SEPARATE_OPENINGS: if not SEPARATE_OPENINGS:
SKIP.append("IfcOpeningElement") SKIP.append("IfcOpeningElement")
try: try:
import ifcopenshell import ifcopenshell
except: except:
@ -313,9 +313,9 @@ def insert(filename,docname,skip=[],only=[],root=None):
except: except:
doc = FreeCAD.newDocument(docname) doc = FreeCAD.newDocument(docname)
FreeCAD.ActiveDocument = doc FreeCAD.ActiveDocument = doc
if DEBUG: print "done." if DEBUG: print "done."
global ifcfile # keeping global for debugging purposes global ifcfile # keeping global for debugging purposes
filename = decode(filename,utf=True) filename = decode(filename,utf=True)
ifcfile = ifcopenshell.open(filename) ifcfile = ifcopenshell.open(filename)
@ -324,7 +324,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
settings.set(settings.USE_BREP_DATA,True) settings.set(settings.USE_BREP_DATA,True)
settings.set(settings.SEW_SHELLS,True) settings.set(settings.SEW_SHELLS,True)
settings.set(settings.USE_WORLD_COORDS,True) settings.set(settings.USE_WORLD_COORDS,True)
if SEPARATE_OPENINGS: if SEPARATE_OPENINGS:
settings.set(settings.DISABLE_OPENING_SUBTRACTIONS,True) settings.set(settings.DISABLE_OPENING_SUBTRACTIONS,True)
if MERGE_MODE_STRUCT != 3: if MERGE_MODE_STRUCT != 3:
settings.set(settings.INCLUDE_CURVES,True) settings.set(settings.INCLUDE_CURVES,True)
@ -335,7 +335,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
openings = ifcfile.by_type("IfcOpeningElement") openings = ifcfile.by_type("IfcOpeningElement")
annotations = ifcfile.by_type("IfcAnnotation") annotations = ifcfile.by_type("IfcAnnotation")
materials = ifcfile.by_type("IfcMaterial") materials = ifcfile.by_type("IfcMaterial")
if DEBUG: print "Building relationships table...", if DEBUG: print "Building relationships table...",
# building relations tables # building relations tables
@ -385,7 +385,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
if it.Items: if it.Items:
if it.Items[0].id() == r.id(): if it.Items[0].id() == r.id():
colors[m.RepresentedMaterial.id()] = (c.Red,c.Green,c.Blue) colors[m.RepresentedMaterial.id()] = (c.Red,c.Green,c.Blue)
if only: # only import a list of IDs and their children if only: # only import a list of IDs and their children
ids = [] ids = []
while only: while only:
@ -394,9 +394,9 @@ def insert(filename,docname,skip=[],only=[],root=None):
if currentid in additions.keys(): if currentid in additions.keys():
only.extend(additions[currentid]) only.extend(additions[currentid])
products = [ifcfile[currentid] for currentid in ids] products = [ifcfile[currentid] for currentid in ids]
if DEBUG: print "done." if DEBUG: print "done."
count = 0 count = 0
from FreeCAD import Base from FreeCAD import Base
progressbar = Base.ProgressIndicator() progressbar = Base.ProgressIndicator()
@ -404,7 +404,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
# products # products
for product in products: for product in products:
pid = product.id() pid = product.id()
guid = product.GlobalId guid = product.GlobalId
ptype = product.is_a() ptype = product.is_a()
@ -435,19 +435,19 @@ def insert(filename,docname,skip=[],only=[],root=None):
if ptype in SKIP: # preferences-set type skip list if ptype in SKIP: # preferences-set type skip list
if DEBUG: print " skipped." if DEBUG: print " skipped."
continue continue
try: try:
cr = ifcopenshell.geom.create_shape(settings,product) cr = ifcopenshell.geom.create_shape(settings,product)
brep = cr.geometry.brep_data brep = cr.geometry.brep_data
except: except:
pass # IfcOpenShell will yield an error if a given product has no shape, but we don't care pass # IfcOpenShell will yield an error if a given product has no shape, but we don't care
if brep: if brep:
if DEBUG: print " ",str(len(brep)/1000),"k ", if DEBUG: print " ",str(len(brep)/1000),"k ",
shape = Part.Shape() shape = Part.Shape()
shape.importBrepFromString(brep) shape.importBrepFromString(brep)
shape.scale(1000.0) # IfcOpenShell always outputs in meters shape.scale(1000.0) # IfcOpenShell always outputs in meters
if not shape.isNull(): if not shape.isNull():
@ -474,7 +474,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
baseobj.Dir = ex[1] baseobj.Dir = ex[1]
if FreeCAD.GuiUp: if FreeCAD.GuiUp:
baseface.ViewObject.hide() baseface.ViewObject.hide()
if not baseobj: if not baseobj:
baseobj = FreeCAD.ActiveDocument.addObject("Part::Feature",name+"_body") baseobj = FreeCAD.ActiveDocument.addObject("Part::Feature",name+"_body")
baseobj.Shape = shape baseobj.Shape = shape
else: else:
@ -482,12 +482,12 @@ def insert(filename,docname,skip=[],only=[],root=None):
if not shape.isValid(): if not shape.isValid():
if DEBUG: print "invalid shape ", if DEBUG: print "invalid shape ",
#continue #continue
else: else:
if DEBUG: print " no brep \n", if DEBUG: print " no brep \n",
if MERGE_MODE_ARCH == 0 and archobj : if MERGE_MODE_ARCH == 0 and archobj :
# full Arch objects # full Arch objects
for freecadtype,ifctypes in typesmap.items(): for freecadtype,ifctypes in typesmap.items():
if ptype in ifctypes: if ptype in ifctypes:
@ -519,9 +519,9 @@ def insert(filename,docname,skip=[],only=[],root=None):
sols = str(obj.Shape.Solids) if hasattr(obj,"Shape") else "[]" sols = str(obj.Shape.Solids) if hasattr(obj,"Shape") else "[]"
if DEBUG: print sols if DEBUG: print sols
objects[pid] = obj objects[pid] = obj
elif (MERGE_MODE_ARCH == 1 and archobj) or (MERGE_MODE_STRUCT == 0 and not archobj): elif (MERGE_MODE_ARCH == 1 and archobj) or (MERGE_MODE_STRUCT == 0 and not archobj):
# non-parametric Arch objects # non-parametric Arch objects
if ptype in ["IfcSite","IfcBuilding","IfcBuildingStorey"]: if ptype in ["IfcSite","IfcBuilding","IfcBuildingStorey"]:
for freecadtype,ifctypes in typesmap.items(): for freecadtype,ifctypes in typesmap.items():
@ -529,9 +529,9 @@ def insert(filename,docname,skip=[],only=[],root=None):
obj = getattr(Arch,"make"+freecadtype)(baseobj=None,name=name) obj = getattr(Arch,"make"+freecadtype)(baseobj=None,name=name)
elif baseobj: elif baseobj:
obj = Arch.makeComponent(baseobj,name=name,delete=True) obj = Arch.makeComponent(baseobj,name=name,delete=True)
elif (MERGE_MODE_ARCH == 2 and archobj) or (MERGE_MODE_STRUCT == 1 and not archobj): elif (MERGE_MODE_ARCH == 2 and archobj) or (MERGE_MODE_STRUCT == 1 and not archobj):
# Part shapes # Part shapes
if ptype in ["IfcSite","IfcBuilding","IfcBuildingStorey"]: if ptype in ["IfcSite","IfcBuilding","IfcBuildingStorey"]:
for freecadtype,ifctypes in typesmap.items(): for freecadtype,ifctypes in typesmap.items():
@ -540,12 +540,12 @@ def insert(filename,docname,skip=[],only=[],root=None):
elif baseobj: elif baseobj:
obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name) obj = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
obj.Shape = shape obj.Shape = shape
if obj: if obj:
obj.Label = name obj.Label = name
objects[pid] = obj objects[pid] = obj
# properties # properties
if pid in properties: if pid in properties:
if hasattr(obj,"IfcAttributes"): if hasattr(obj,"IfcAttributes"):
@ -555,21 +555,21 @@ def insert(filename,docname,skip=[],only=[],root=None):
if o.is_a("IfcPropertySingleValue"): if o.is_a("IfcPropertySingleValue"):
a[o.Name.decode("unicode_escape").encode("utf8")] = str(o.NominalValue) a[o.Name.decode("unicode_escape").encode("utf8")] = str(o.NominalValue)
obj.IfcAttributes = a obj.IfcAttributes = a
# color # color
if FreeCAD.GuiUp and (pid in colors) and hasattr(obj.ViewObject,"ShapeColor"): if FreeCAD.GuiUp and (pid in colors) and hasattr(obj.ViewObject,"ShapeColor"):
if DEBUG: print " setting color: ",colors[pid] if DEBUG: print " setting color: ",colors[pid]
obj.ViewObject.ShapeColor = colors[pid] obj.ViewObject.ShapeColor = colors[pid]
# if DEBUG is on, recompute after each shape # if DEBUG is on, recompute after each shape
if DEBUG: FreeCAD.ActiveDocument.recompute() if DEBUG: FreeCAD.ActiveDocument.recompute()
count += 1 count += 1
progressbar.next() progressbar.next()
progressbar.stop() progressbar.stop()
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
if MERGE_MODE_STRUCT == 2: if MERGE_MODE_STRUCT == 2:
if DEBUG: print "Joining Structural shapes..." if DEBUG: print "Joining Structural shapes..."
@ -591,7 +591,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedStruct") obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedStruct")
obj.Shape = Part.makeCompound(structshapes.values()) obj.Shape = Part.makeCompound(structshapes.values())
else: else:
if DEBUG: print "Processing Struct relationships..." if DEBUG: print "Processing Struct relationships..."
# groups # groups
@ -618,9 +618,9 @@ def insert(filename,docname,skip=[],only=[],root=None):
if MERGE_MODE_ARCH == 3: if MERGE_MODE_ARCH == 3:
if DEBUG: print "Joining Arch shapes..." if DEBUG: print "Joining Arch shapes..."
for host,children in additions.items(): # Arch for host,children in additions.items(): # Arch
if ifcfile[host].is_a("IfcBuildingStorey"): if ifcfile[host].is_a("IfcBuildingStorey"):
compound = [] compound = []
@ -642,11 +642,11 @@ def insert(filename,docname,skip=[],only=[],root=None):
if shapes: # remaining Arch shapes if shapes: # remaining Arch shapes
obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedArch") obj = FreeCAD.ActiveDocument.addObject("Part::Feature","UnclaimedArch")
obj.Shape = Part.makeCompound(shapes.values()) obj.Shape = Part.makeCompound(shapes.values())
else: else:
if DEBUG: print "Processing Arch relationships..." if DEBUG: print "Processing Arch relationships..."
# subtractions # subtractions
if SEPARATE_OPENINGS: if SEPARATE_OPENINGS:
for subtraction in subtractions: for subtraction in subtractions:
@ -654,7 +654,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
if DEBUG: print "subtracting ",objects[subtraction[0]].Label, " from ", objects[subtraction[1]].Label if DEBUG: print "subtracting ",objects[subtraction[0]].Label, " from ", objects[subtraction[1]].Label
Arch.removeComponents(objects[subtraction[0]],objects[subtraction[1]]) Arch.removeComponents(objects[subtraction[0]],objects[subtraction[1]])
if DEBUG: FreeCAD.ActiveDocument.recompute() if DEBUG: FreeCAD.ActiveDocument.recompute()
# additions # additions
for host,children in additions.items(): for host,children in additions.items():
if host in objects.keys(): if host in objects.keys():
@ -667,27 +667,27 @@ def insert(filename,docname,skip=[],only=[],root=None):
if DEBUG: print "adding ",len(cobs), " object(s) to ", objects[host].Label if DEBUG: print "adding ",len(cobs), " object(s) to ", objects[host].Label
Arch.addComponents(cobs,objects[host]) Arch.addComponents(cobs,objects[host])
if DEBUG: FreeCAD.ActiveDocument.recompute() if DEBUG: FreeCAD.ActiveDocument.recompute()
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
# cleaning bad shapes # cleaning bad shapes
for obj in objects.values(): for obj in objects.values():
if obj.isDerivedFrom("Part::Feature"): if obj.isDerivedFrom("Part::Feature"):
if obj.Shape.isNull(): if obj.Shape.isNull():
Arch.rebuildArchShape(obj) Arch.rebuildArchShape(obj)
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
# 2D elements # 2D elements
if DEBUG and annotations: print "Creating 2D geometry..." if DEBUG and annotations: print "Creating 2D geometry..."
for annotation in annotations: for annotation in annotations:
aid = annotation.id() aid = annotation.id()
if aid in skip: continue # user given id skip list if aid in skip: continue # user given id skip list
if "IfcAnnotation" in SKIP: continue # preferences-set type skip list if "IfcAnnotation" in SKIP: continue # preferences-set type skip list
name = "Annotation" name = "Annotation"
if annotation.Name: if annotation.Name:
name = annotation.Name.decode("unicode_escape").encode("utf8") name = annotation.Name.decode("unicode_escape").encode("utf8")
if PREFIX_NUMBERS: name = "ID" + str(aid) + " " + name if PREFIX_NUMBERS: name = "ID" + str(aid) + " " + name
shapes2d = [] shapes2d = []
@ -700,13 +700,13 @@ def insert(filename,docname,skip=[],only=[],root=None):
o = FreeCAD.ActiveDocument.addObject("Part::Feature",name) o = FreeCAD.ActiveDocument.addObject("Part::Feature",name)
o.Shape = sh o.Shape = sh
count += 1 count += 1
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
# Materials # Materials
if DEBUG and materials: print "Creating materials..." if DEBUG and materials: print "Creating materials..."
fcmats = {} fcmats = {}
for material in materials: for material in materials:
name = "Material" name = "Material"
@ -727,9 +727,9 @@ def insert(filename,docname,skip=[],only=[],root=None):
if o in objects: if o in objects:
if hasattr(objects[o],"BaseMaterial"): if hasattr(objects[o],"BaseMaterial"):
objects[o].BaseMaterial = mat objects[o].BaseMaterial = mat
FreeCAD.ActiveDocument.recompute() FreeCAD.ActiveDocument.recompute()
if FreeCAD.GuiUp: if FreeCAD.GuiUp:
import FreeCADGui import FreeCADGui
FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.SendMsgToActiveView("ViewFit")
@ -739,10 +739,10 @@ def insert(filename,docname,skip=[],only=[],root=None):
def export(exportList,filename): def export(exportList,filename):
"exports FreeCAD contents to an IFC file" "exports FreeCAD contents to an IFC file"
p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch") p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch")
FORCEBREP = p.GetBool("ifcExportAsBrep",False) FORCEBREP = p.GetBool("ifcExportAsBrep",False)
DEBUG = p.GetBool("ifcDebug",False) DEBUG = p.GetBool("ifcDebug",False)
try: try:
global ifcopenshell global ifcopenshell
@ -782,14 +782,14 @@ def export(exportList,filename):
products = {} # { Name: IfcEntity, ... } products = {} # { Name: IfcEntity, ... }
surfstyles = {} # { (r,g,b): IfcEntity, ... } surfstyles = {} # { (r,g,b): IfcEntity, ... }
count = 1 count = 1
# products # products
for obj in objectslist: for obj in objectslist:
# getting generic data # getting generic data
name = str(obj.Label.encode("utf8")) name = str(obj.Label.encode("utf8"))
description = str(obj.Description) if hasattr(obj,"Description") else "" description = str(obj.Description) if hasattr(obj,"Description") else ""
# getting uid # getting uid
uid = None uid = None
if hasattr(obj,"IfcAttributes"): if hasattr(obj,"IfcAttributes"):
@ -797,7 +797,7 @@ def export(exportList,filename):
uid = str(obj.IfcAttributes["IfcUID"]) uid = str(obj.IfcAttributes["IfcUID"])
if not uid: if not uid:
uid = ifcopenshell.guid.compress(uuid.uuid1().hex) uid = ifcopenshell.guid.compress(uuid.uuid1().hex)
# setting the IFC type + name conversions # setting the IFC type + name conversions
if hasattr(obj,"Role"): if hasattr(obj,"Role"):
ifctype = obj.Role.replace(" ","") ifctype = obj.Role.replace(" ","")
@ -813,17 +813,17 @@ def export(exportList,filename):
ifctypes.extend(v) ifctypes.extend(v)
if not ifctype in ifctypes: if not ifctype in ifctypes:
ifctype = "IfcBuildingElementProxy" ifctype = "IfcBuildingElementProxy"
# getting the "Force BREP" flag # getting the "Force BREP" flag
brepflag = False brepflag = False
if hasattr(obj,"IfcAttributes"): if hasattr(obj,"IfcAttributes"):
if "FlagForceBrep" in obj.IfcAttributes.keys(): if "FlagForceBrep" in obj.IfcAttributes.keys():
if obj.IfcAttributes["FlagForceBrep"] == "True": if obj.IfcAttributes["FlagForceBrep"] == "True":
brepflag = True brepflag = True
# getting the representation # getting the representation
representation,placement,shapetype = getRepresentation(ifcfile,context,obj,forcebrep=(brepflag or FORCEBREP)) representation,placement,shapetype = getRepresentation(ifcfile,context,obj,forcebrep=(brepflag or FORCEBREP))
if DEBUG: print str(count).ljust(3)," : ", ifctype, " (",shapetype,") : ",name if DEBUG: print str(count).ljust(3)," : ", ifctype, " (",shapetype,") : ",name
# setting the arguments # setting the arguments
@ -847,11 +847,11 @@ def export(exportList,filename):
args = args + ["ELEMENT",None,None,None] args = args + ["ELEMENT",None,None,None]
elif ifctype == "IfcBuildingStorey": elif ifctype == "IfcBuildingStorey":
args = args + ["ELEMENT",obj.Placement.Base.z] args = args + ["ELEMENT",obj.Placement.Base.z]
# creating the product # creating the product
product = getattr(ifcfile,"create"+ifctype)(*args) product = getattr(ifcfile,"create"+ifctype)(*args)
products[obj.Name] = product products[obj.Name] = product
# additions # additions
if hasattr(obj,"Additions") and (shapetype == "extrusion"): if hasattr(obj,"Additions") and (shapetype == "extrusion"):
for o in obj.Additions: for o in obj.Additions:
@ -859,7 +859,7 @@ def export(exportList,filename):
if DEBUG: print " adding ",c2," : ",str(o.Label) if DEBUG: print " adding ",c2," : ",str(o.Label)
prod2 = ifcfile.createIfcBuildingElementProxy(ifcopenshell.guid.compress(uuid.uuid1().hex),history,str(o.Label),None,None,p2,r2,None,"ELEMENT") prod2 = ifcfile.createIfcBuildingElementProxy(ifcopenshell.guid.compress(uuid.uuid1().hex),history,str(o.Label),None,None,p2,r2,None,"ELEMENT")
ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'Addition','',product,[prod2]) ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'Addition','',product,[prod2])
# subtractions # subtractions
if hasattr(obj,"Subtractions") and (shapetype == "extrusion"): if hasattr(obj,"Subtractions") and (shapetype == "extrusion"):
for o in obj.Subtractions: for o in obj.Subtractions:
@ -867,7 +867,7 @@ def export(exportList,filename):
if DEBUG: print " subtracting ",c2," : ",str(o.Label) if DEBUG: print " subtracting ",c2," : ",str(o.Label)
prod2 = ifcfile.createIfcOpeningElement(ifcopenshell.guid.compress(uuid.uuid1().hex),history,str(o.Label),None,None,p2,r2,None) prod2 = ifcfile.createIfcOpeningElement(ifcopenshell.guid.compress(uuid.uuid1().hex),history,str(o.Label),None,None,p2,r2,None)
ifcfile.createIfcRelVoidsElement(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'Subtraction','',product,prod2) ifcfile.createIfcRelVoidsElement(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'Subtraction','',product,prod2)
# properties # properties
if hasattr(obj,"IfcAttributes"): if hasattr(obj,"IfcAttributes"):
props = [] props = []
@ -898,9 +898,9 @@ def export(exportList,filename):
if props: if props:
pset = ifcfile.createIfcPropertySet(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'PropertySet',None,props) pset = ifcfile.createIfcPropertySet(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'PropertySet',None,props)
ifcfile.createIfcRelDefinesByProperties(ifcopenshell.guid.compress(uuid.uuid1().hex),history,None,None,[product],pset) ifcfile.createIfcRelDefinesByProperties(ifcopenshell.guid.compress(uuid.uuid1().hex),history,None,None,[product],pset)
count += 1 count += 1
# relationships # relationships
sites = [] sites = []
buildings = [] buildings = []
@ -916,7 +916,7 @@ def export(exportList,filename):
floors.append(floor) floors.append(floor)
building = products[building.Name] building = products[building.Name]
if floors: if floors:
ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'BuildingLink','',building,floors) ifcfile.createIfcRelAggregates(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'BuildingLink','',building,floors)
buildings.append(building) buildings.append(building)
site = products[site.Name] site = products[site.Name]
if buildings: if buildings:
@ -957,21 +957,21 @@ def export(exportList,filename):
ifcfile.createIfcRelAssociatesMaterial(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'MaterialLink','',relobjs,mat) ifcfile.createIfcRelAssociatesMaterial(ifcopenshell.guid.compress(uuid.uuid1().hex),history,'MaterialLink','',relobjs,mat)
if DEBUG: print "writing ",filename,"..." if DEBUG: print "writing ",filename,"..."
filename = decode(filename) filename = decode(filename)
ifcfile.write(filename) ifcfile.write(filename)
def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tessellation=1): def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tessellation=1):
"""returns an IfcShapeRepresentation object or None""" """returns an IfcShapeRepresentation object or None"""
import Part,math,DraftGeomUtils,DraftVecUtils import Part,math,DraftGeomUtils,DraftVecUtils
shapes = [] shapes = []
placement = None placement = None
productdef = None productdef = None
shapetype = "no shape" shapetype = "no shape"
if not forcebrep: if not forcebrep:
profile = None profile = None
if hasattr(obj,"Proxy"): if hasattr(obj,"Proxy"):
@ -985,33 +985,33 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
p.scale(0.001) # to meters p.scale(0.001) # to meters
r = obj.Proxy.getPlacement(obj) r = obj.Proxy.getPlacement(obj)
r.Base = r.Base.multiply(0.001) # to meters r.Base = r.Base.multiply(0.001) # to meters
if len(p.Edges) == 1: if len(p.Edges) == 1:
pxvc = ifcfile.createIfcDirection((1.0,0.0)) pxvc = ifcfile.createIfcDirection((1.0,0.0))
povc = ifcfile.createIfcCartesianPoint((0.0,0.0)) povc = ifcfile.createIfcCartesianPoint((0.0,0.0))
pt = ifcfile.createIfcAxis2Placement2D(povc,pxvc) pt = ifcfile.createIfcAxis2Placement2D(povc,pxvc)
# extruded circle # extruded circle
if isinstance(p.Edges[0].Curve,Part.Circle): if isinstance(p.Edges[0].Curve,Part.Circle):
profile = ifcfile.createIfcCircleProfileDef("AREA",None,pt, p.Edges[0].Curve.Radius) profile = ifcfile.createIfcCircleProfileDef("AREA",None,pt, p.Edges[0].Curve.Radius)
# extruded ellipse # extruded ellipse
elif isinstance(p.Edges[0].Curve,Part.Ellipse): elif isinstance(p.Edges[0].Curve,Part.Ellipse):
profile = ifcfile.createIfcEllipseProfileDef("AREA",None,pt, p.Edges[0].Curve.MajorRadius, p.Edges[0].Curve.MinorRadius) profile = ifcfile.createIfcEllipseProfileDef("AREA",None,pt, p.Edges[0].Curve.MajorRadius, p.Edges[0].Curve.MinorRadius)
else: else:
curves = False curves = False
for e in p.Edges: for e in p.Edges:
if isinstance(e.Curve,Part.Circle): if isinstance(e.Curve,Part.Circle):
curves = True curves = True
# extruded polyline # extruded polyline
if not curves: if not curves:
w = Part.Wire(DraftGeomUtils.sortEdges(p.Edges)) w = Part.Wire(DraftGeomUtils.sortEdges(p.Edges))
pts = [ifcfile.createIfcCartesianPoint(tuple(v.Point)[:2]) for v in w.Vertexes+[w.Vertexes[0]]] pts = [ifcfile.createIfcCartesianPoint(tuple(v.Point)[:2]) for v in w.Vertexes+[w.Vertexes[0]]]
pol = ifcfile.createIfcPolyline(pts) pol = ifcfile.createIfcPolyline(pts)
# extruded composite curve # extruded composite curve
else: else:
segments = [] segments = []
@ -1031,7 +1031,7 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
p1 = math.degrees(-DraftVecUtils.angle(e.Vertexes[0].Point.sub(e.Curve.Center))) p1 = math.degrees(-DraftVecUtils.angle(e.Vertexes[0].Point.sub(e.Curve.Center)))
p2 = math.degrees(-DraftVecUtils.angle(e.Vertexes[-1].Point.sub(e.Curve.Center))) p2 = math.degrees(-DraftVecUtils.angle(e.Vertexes[-1].Point.sub(e.Curve.Center)))
da = DraftVecUtils.angle(e.valueAt(e.FirstParameter+0.1).sub(e.Curve.Center),e.Vertexes[0].Point.sub(e.Curve.Center)) da = DraftVecUtils.angle(e.valueAt(e.FirstParameter+0.1).sub(e.Curve.Center),e.Vertexes[0].Point.sub(e.Curve.Center))
if p1 < 0: if p1 < 0:
p1 = 360 + p1 p1 = 360 + p1
if p2 < 0: if p2 < 0:
p2 = 360 + p2 p2 = 360 + p2
@ -1042,7 +1042,7 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
plc = ifcfile.createIfcAxis2Placement2D(ovc,xvc) plc = ifcfile.createIfcAxis2Placement2D(ovc,xvc)
cir = ifcfile.createIfcCircle(plc,e.Curve.Radius) cir = ifcfile.createIfcCircle(plc,e.Curve.Radius)
curve = ifcfile.createIfcTrimmedCurve(cir,[ifcfile.createIfcParameterValue(p1)],[ifcfile.createIfcParameterValue(p2)],follow,"PARAMETER") curve = ifcfile.createIfcTrimmedCurve(cir,[ifcfile.createIfcParameterValue(p1)],[ifcfile.createIfcParameterValue(p2)],follow,"PARAMETER")
else: else:
verts = [vertex.Point for vertex in e.Vertexes] verts = [vertex.Point for vertex in e.Vertexes]
if last: if last:
@ -1057,10 +1057,10 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
curve = ifcfile.createIfcPolyline(pts) curve = ifcfile.createIfcPolyline(pts)
segment = ifcfile.createIfcCompositeCurveSegment("CONTINUOUS",True,curve) segment = ifcfile.createIfcCompositeCurveSegment("CONTINUOUS",True,curve)
segments.append(segment) segments.append(segment)
pol = ifcfile.createIfcCompositeCurve(segments,False) pol = ifcfile.createIfcCompositeCurve(segments,False)
profile = ifcfile.createIfcArbitraryClosedProfileDef("AREA",None,pol) profile = ifcfile.createIfcArbitraryClosedProfileDef("AREA",None,pol)
if profile: if profile:
xvc = ifcfile.createIfcDirection(tuple(r.Rotation.multVec(FreeCAD.Vector(1,0,0)))) xvc = ifcfile.createIfcDirection(tuple(r.Rotation.multVec(FreeCAD.Vector(1,0,0))))
zvc = ifcfile.createIfcDirection(tuple(r.Rotation.multVec(FreeCAD.Vector(0,0,1)))) zvc = ifcfile.createIfcDirection(tuple(r.Rotation.multVec(FreeCAD.Vector(0,0,1))))
@ -1071,9 +1071,9 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
shapes.append(shape) shapes.append(shape)
solidType = "SweptSolid" solidType = "SweptSolid"
shapetype = "extrusion" shapetype = "extrusion"
if not shapes: if not shapes:
# brep representation # brep representation
fcshape = None fcshape = None
solidType = "Brep" solidType = "Brep"
@ -1147,13 +1147,13 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
loops.append(bound) loops.append(bound)
face = ifcfile.createIfcFace(loops) face = ifcfile.createIfcFace(loops)
faces.append(face) faces.append(face)
shell = ifcfile.createIfcClosedShell(faces) shell = ifcfile.createIfcClosedShell(faces)
shape = ifcfile.createIfcFacetedBrep(shell) shape = ifcfile.createIfcFacetedBrep(shell)
shapes.append(shape) shapes.append(shape)
if shapes: if shapes:
# set surface style # set surface style
if FreeCAD.GuiUp and (not subtraction) and hasattr(obj.ViewObject,"ShapeColor"): if FreeCAD.GuiUp and (not subtraction) and hasattr(obj.ViewObject,"ShapeColor"):
# only set a surface style if the object has no material. # only set a surface style if the object has no material.
@ -1175,8 +1175,8 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
surfstyles[rgb] = psa surfstyles[rgb] = psa
for shape in shapes: for shape in shapes:
isi = ifcfile.createIfcStyledItem(shape,[psa],None) isi = ifcfile.createIfcStyledItem(shape,[psa],None)
xvc = ifcfile.createIfcDirection((1.0,0.0,0.0)) xvc = ifcfile.createIfcDirection((1.0,0.0,0.0))
zvc = ifcfile.createIfcDirection((0.0,0.0,1.0)) zvc = ifcfile.createIfcDirection((0.0,0.0,1.0))
ovc = ifcfile.createIfcCartesianPoint((0.0,0.0,0.0)) ovc = ifcfile.createIfcCartesianPoint((0.0,0.0,0.0))
@ -1184,26 +1184,26 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
placement = ifcfile.createIfcLocalPlacement(None,gpl) placement = ifcfile.createIfcLocalPlacement(None,gpl)
representation = ifcfile.createIfcShapeRepresentation(context,'Body',solidType,shapes) representation = ifcfile.createIfcShapeRepresentation(context,'Body',solidType,shapes)
productdef = ifcfile.createIfcProductDefinitionShape(None,None,[representation]) productdef = ifcfile.createIfcProductDefinitionShape(None,None,[representation])
return productdef,placement,shapetype return productdef,placement,shapetype
def setRepresentation(representation): def setRepresentation(representation):
"""Returns a shape from a 2D IfcShapeRepresentation""" """Returns a shape from a 2D IfcShapeRepresentation"""
def getPolyline(ent): def getPolyline(ent):
pts = [] pts = []
for p in ent.Points: for p in ent.Points:
c = p.Coordinates c = p.Coordinates
pts.append(FreeCAD.Vector(c[0],c[1],c[2] if len(c) > 2 else 0)) pts.append(FreeCAD.Vector(c[0],c[1],c[2] if len(c) > 2 else 0))
return Part.makePolygon(pts) return Part.makePolygon(pts)
def getCircle(ent): def getCircle(ent):
c = ent.Position.Location.Coordinates c = ent.Position.Location.Coordinates
c = FreeCAD.Vector(c[0],c[1],c[2] if len(c) > 2 else 0) c = FreeCAD.Vector(c[0],c[1],c[2] if len(c) > 2 else 0)
r = ent.Radius r = ent.Radius
return Part.makeCircle(r,c) return Part.makeCircle(r,c)
result = [] result = []
if representation.is_a("IfcShapeRepresentation"): if representation.is_a("IfcShapeRepresentation"):
for item in representation.Items: for item in representation.Items:
@ -1231,4 +1231,4 @@ def setRepresentation(representation):
e.rotate(bc.Curve.Center,FreeCAD.Vector(0,0,1),math.degrees(a)) e.rotate(bc.Curve.Center,FreeCAD.Vector(0,0,1),math.degrees(a))
result.append(e) result.append(e)
return result return result