Skip to content

Commit

Permalink
Arch: IFC bugfix + added pref option to use DAE triangulation options
Browse files Browse the repository at this point in the history
  • Loading branch information
yorikvanhavre committed Dec 18, 2015
1 parent cfba4a3 commit 45292eb
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 13 deletions.
12 changes: 8 additions & 4 deletions src/Mod/Arch/ArchCommands.py
Expand Up @@ -498,11 +498,15 @@ def meshToShape(obj,mark=True,fast=True,tol=0.001,flat=False,cut=True):
return newobj
return None

def removeCurves(shape,tolerance=5):
'''removeCurves(shape,tolerance=5): replaces curved faces in a shape
with faceted segments'''
def removeCurves(shape,dae=False,tolerance=5):
'''removeCurves(shape,dae,tolerance=5): replaces curved faces in a shape
with faceted segments. If dae is True, DAE triangulation options are used'''
import Mesh
t = shape.cleaned().tessellate(tolerance)
if dae:
import importDAE
t = importDAE.triangulate(shape.cleaned())
else:
t = shape.cleaned().tessellate(tolerance)
m = Mesh.Mesh(t)
return getShapeFromMesh(m)

Expand Down
26 changes: 23 additions & 3 deletions src/Mod/Arch/Resources/ui/preferences-ifc.ui
Expand Up @@ -319,13 +319,33 @@
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_4">
<property name="toolTip">
<string>Curved shapes that cannot be represented as curves in IFC are decomposed into flat facets. If this is checked, simple triangulation will be used, otherwise some additional calculation is done to join coplanar facets.</string>
<string>Use triangulation options set in the DAE options page</string>
</property>
<property name="text">
<string>Use classic triangulation</string>
<string>Use DAE triangulation options</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ifcClassicTriangulation</cstring>
<cstring>ifcUseDaeOptions</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="Gui::PrefCheckBox" name="checkBox_5">
<property name="toolTip">
<string>Curved shapes that cannot be represented as curves in IFC are decomposed into flat facets. If this is checked, some additional calculation is done to join coplanar facets.</string>
</property>
<property name="text">
<string>Join coplanar facets when triangulating</string>
</property>
<property name="prefEntry" stdset="0">
<cstring>ifcJoinCoplanarFacets</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Arch</cstring>
Expand Down
21 changes: 15 additions & 6 deletions src/Mod/Arch/importIFC.py
Expand Up @@ -832,8 +832,8 @@ def export(exportList,filename):
if b:
clones.setdefault(b.Name,[]).append(o.Name)

print "clones table: ",clones
print objectslist
#print "clones table: ",clones
#print objectslist

# products
for obj in objectslist:
Expand Down Expand Up @@ -1170,7 +1170,7 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
dataset = fcshape.Solids
else:
dataset = fcshape.Shells
print "Warning! object contains no solids"
if DEBUG: print "Warning! object contains no solids"
for fcsolid in dataset:
fcsolid.scale(0.001) # to meters
faces = []
Expand All @@ -1183,9 +1183,15 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
curves = True
break
if curves:
if FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("ifcClassicTriangulation",False):
joinfacets = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("ifcJoinCoplanarFacets",False)
usedae = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Arch").GetBool("ifcUseDaeOptions",False)
if not joinfacets:
shapetype = "triangulated"
tris = fcsolid.tessellate(tessellation)
if usedae:
import importDAE
tris = importDAE.triangulate(fcsolid)
else:
tris = fcsolid.tessellate(tessellation)
for tri in tris[1]:
pts = [ifcfile.createIfcCartesianPoint(tuple(tris[0][i])) for i in tri]
loop = ifcfile.createIfcPolyLoop(pts)
Expand All @@ -1194,7 +1200,10 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
faces.append(face)
fcsolid = Part.Shape() # empty shape so below code is not executed
else:
fcsolid = Arch.removeCurves(fcsolid)
fcsolid = Arch.removeCurves(fcsolid,dae=usedae)
if not fcsolid:
if DEBUG: print "Error: Unable to triangulate shape"
fcsolid = Part.Shape()

for fcface in fcsolid.Faces:
loops = []
Expand Down

0 comments on commit 45292eb

Please sign in to comment.