Arch: prep work for IFC export

This commit is contained in:
Yorik van Havre 2013-12-13 18:50:38 -02:00
parent 9bdd15f7b5
commit 6e01e6c6e5
3 changed files with 90 additions and 4 deletions

View File

@ -595,6 +595,51 @@ def addFixture(fixture,baseobject):
else:
FreeCAD.Console.PrintMessage(str(translate("Arch","This object has no support for fixtures")))
def getTuples(data):
"""getTuples(data): returns a tuple or a list of tuples from a vector
or from the vertices of a shape"""
import Part
if isinstance(data,FreeCAD.Vector):
return (data.x,data.y,data.z)
elif isinstance(data,Part.Shape):
t = []
for v in data.Vertexes:
t.append((v.X,v.Y,v.Z))
t.append(t[0]) # for IFC verts lists must be closed
return t
def getExtrusionData(obj):
"""getExtrusionData(obj): returns a closed path (a list of tuples) and a tuple expressing an extrusion
vector, or None, if a base loop and an extrusion direction cannot be extracted."""
if hasattr(obj,"Additions"):
if obj.Additions:
# provisorily treat objs with additions as breps
return None
if hasattr(obj,"Subtractions"):
if obj.Subtractions:
# provisorily treat objs with subtractions as breps
return None
if hasattr(obj,"Proxy"):
if hasattr(obj.Proxy,"BaseProfile") and hasattr(obj.Proxy,"ExtrusionVector"):
return getTuples(obj.Proxy.BaseProfile), getTuples(obj.Proxy.getExtrusionVector)
return None
def getBrepFacesData(obj):
"""getBrepFacesData(obj): returns a list(0) of lists(1) of lists(2), list(1) being a list
of vertices defining a loop, list(1) describing a face from one or more loops, list(0)
being the whole object made of several faces."""
if hasattr(obj,"Shape"):
if obj.Shape:
if obj.shape.isValid():
if not obj.Shape.isNull():
s = []
for face in obj.Shape.Faces:
f = []
for wire in face.Wires:
f.append(getTuples(wire))
s.append(f)
return s
return None
# command definitions ###############################################

View File

@ -479,9 +479,11 @@ class _Wall(ArchComponent.Component):
sh = DraftGeomUtils.bind(w1,w2)
# fixing self-intersections
sh.fix(0.1,0,1)
self.BaseProfile = sh
if height and (not flat):
norm = Vector(normal).multiply(height)
sh = sh.extrude(norm)
self.ExtrusionVector = norm
return sh
def createGeometry(self,obj):

View File

@ -581,7 +581,7 @@ def getSchema():
def group(entity,ifc,mode=None):
"gathers the children of the given entity"
# only used by internal parser
# only used by the internal parser
try:
if DEBUG: print "=====> making group",entity.id
@ -653,7 +653,7 @@ def group(entity,ifc,mode=None):
def getWire(entity,placement=None):
"returns a wire (created in the freecad document) from the given entity"
# only used by internal parser
# only used by the internal parser
if DEBUG: print "making Wire from :",entity
if not entity: return None
if entity.type == "IFCPOLYLINE":
@ -669,7 +669,7 @@ def getWire(entity,placement=None):
def getPlacement(entity):
"returns a placement from the given entity"
# only used by internal parser
# only used by the internal parser
if DEBUG: print "getting placement ",entity
if not entity: return None
pl = None
@ -697,7 +697,7 @@ def getPlacement(entity):
def getVector(entity):
"returns a vector from the given entity"
# only used by internal parser
# only used by the internal parser
if DEBUG: print "getting point from",entity
if entity.type == "IFCDIRECTION":
if len(entity.DirectionRatios) == 3:
@ -710,3 +710,42 @@ def getVector(entity):
else:
return FreeCAD.Vector(tuple(entity.Coordinates+[0]))
return None
# EXPORT ##########################################################
def export(exportList,filename):
"called when freecad exports a file"
try:
import ifcWriter
except:
print "IFC export: ifcWriter not found or unusable"
return
import Arch,Draft
application = "FreeCAD"
ver = FreeCAD.Version()
version = ver[0]+"."+ver[1]+" build"+ver[2]
owner = FreeCAD.ActiveDocument.CreatedBy
company = FreeCAD.ActiveDocument.Company
project = FreeCAD.ActiveDocument.Name
ifc = ifcWriter.IfcDocument(filename,project,owner,company,application,version)
for obj in exportList:
otype = Draft.getType(obj)
gdata = Arch.getExtrusionData(obj)
if not data:
fdata = Arch.getBrepFacesData(obj)
if otype == "Wall":
if gdata:
ifc.addWall( ifc.addExtrudedPolyline(gdata) )
elif fdata:
ifc.addWall( ifc.addFacetedBrep(fdata) )
else:
print "IFC export: error retrieving the shape of object ", obj.Name
else:
print "object type ", otype, " is not supported yet."
ifc.write()
print "Successfully exported ",filename