Updated IfcBlender.py

Fix gcc compilation (Patch by Jochem Berndsen)
This commit is contained in:
Thomas Krijnen
2011-06-01 13:19:36 +00:00
parent 357bae86e3
commit 7bd1a3e7e4
3 changed files with 91 additions and 83 deletions
+1 -54
View File
@@ -618,57 +618,4 @@ an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
<program> Copyright (C) <year> <name of author>
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
END OF TERMS AND CONDITIONS
+84 -23
View File
@@ -1,51 +1,112 @@
import bpy, mathutils
##############################################################################
# #
#This file is part of IfcOpenShell. #
# #
#IfcOpenShell is free software: you can redistribute it and/or modify #
#it under the terms of the Lesser GNU General Public License as published by #
#the Free Software Foundation, either version 3.0 of the License, or #
#(at your option) any later version. #
# #
#IfcOpenShell is distributed in the hope that it will be useful, #
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
#Lesser GNU General Public License for more details. #
# #
#You should have received a copy of the Lesser GNU General Public License #
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
# #
##############################################################################
bl_info = {
"name": "IfcBlender",
"description": "Import files in the "\
"Industry Foundation Classes (.ifc) file format",
"author": "Thomas Krijnen, IfcOpenShell",
"blender": (2, 5, 6),
"api": 32738,
"location": "File > Import",
"warning": "This addon requires several "\
"Open CASCADE libraries to be installed",
"wiki_url": "http://sourceforge.net/apps/"\
"mediawiki/ifcopenshell/index.php",
"tracker_url": "http://sourceforge.net/tracker/?group_id=543113",
"category": "Import-Export"}
import bpy
import mathutils
from bpy.props import *
from io_utils import ImportHelper
class ImportIFC(bpy.types.Operator, ImportHelper):
'''Load an IFC File'''
bl_idname = "import_scene.ifc"
bl_label = "Import IFC"
bl_label = "Import .ifc file"
filename_ext = ".ifc"
filter_glob = StringProperty(default="*.ifc", options={'HIDDEN'})
def execute(self, context):
import IFCimport
IFCimport.init_objs(self.filepath)
import IfcImport
if not IfcImport.Init(self.filepath):
return {'FINISHED'}
ids = {}
while True:
ob = IFCimport.current_obj()
print (ob.name)
if not ob.type in ['IFCSPACE','IFCOPENINGELEMENT']:
ob = IfcImport.Get()
if not ob.type in ['IFCSPACE', 'IFCOPENINGELEMENT']:
f = ob.mesh.faces
v = ob.mesh.verts
m = ob.matrix
if ob.mesh.id in ids: me = ids[ob.mesh.id]
if ob.mesh.id in ids:
me = ids[ob.mesh.id]
else:
verts = []
faces = []
for i in range(0,len(f),3):
faces.append([f[i+0],f[i+1],f[i+2]])
for i in range(0,len(v),3):
verts.append([v[i+0],v[i+1],v[i+2]])
me = bpy.data.meshes.new('mesh%d'%ob.mesh.id)
me.from_pydata(verts,[],faces)
for i in range(0, len(f), 3):
faces.append([f[i + 0], f[i + 1], f[i + 2]])
for i in range(0, len(v), 3):
verts.append([v[i + 0], v[i + 1], v[i + 2]])
me = bpy.data.meshes.new('mesh%d' % ob.mesh.id)
me.from_pydata(verts, [], faces)
if ob.type in bpy.data.materials:
mat = bpy.data.materials[ob.type]
mat.use_fake_user = True
else: mat = bpy.data.materials.new(ob.type)
else:
mat = bpy.data.materials.new(ob.type)
me.materials.append(mat)
ids[ob.mesh.id] = me
bob = bpy.data.objects.new(ob.name,me)
bob.matrix_world = mathutils.Matrix([m[0],m[1],m[2],0],[m[3],m[4],m[5],0],[m[6],m[7],m[8],0],[m[9],m[10],m[11],1])
bob = bpy.data.objects.new(ob.name, me)
bob.matrix_world = mathutils.Matrix(([m[0], m[1], m[2], 0],
[m[3], m[4], m[5], 0],
[m[6], m[7], m[8], 0],
[m[9], m[10], m[11], 1]))
bpy.context.scene.objects.link(bob)
me.update()
if not IFCimport.next_obj(): break
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_name(name=bob.name)
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.normals_make_consistent()
bpy.ops.object.mode_set(mode='OBJECT')
if not IfcImport.Next():
break
return {'FINISHED'}
def menu_func_import(self, context):
self.layout.operator(ImportIFC.bl_idname, text="Industry Foundation Classes (.ifc)")
self.layout.operator(ImportIFC.bl_idname,
text="Industry Foundation Classes (.ifc)")
def register():
bpy.utils.register_module(__name__)
bpy.types.INFO_MT_file_import.append(menu_func_import)
register()
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.INFO_MT_file_import.remove(menu_func_import)
if __name__ == "__main__":
register()
+6 -6
View File
@@ -177,13 +177,13 @@ bool IfcGeom::convert(IfcSchema::Face* IfcFace, TopoDS_Face& face) {
IfcEntity loop = bound->Loop();
TopoDS_Wire wire;
if ( ! IfcGeom::convert_wire(loop,wire) ) return false;
BRepBuilderAPI_MakeFace mf = BRepBuilderAPI_MakeFace(wire);
BRepBuilderAPI_MakeFace mf(wire, false);
BRepBuilderAPI_FaceError er = mf.Error();
if ( er == BRepBuilderAPI_NotPlanar ) {
std::cout << "[Notice] Trying to fix non-planar face" << std::endl;
ShapeFix_ShapeTolerance FTol;
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
mf = BRepBuilderAPI_MakeFace(wire);
mf = BRepBuilderAPI_MakeFace(wire, false);
er = mf.Error();
}
if ( er != BRepBuilderAPI_FaceDone ) return false;
@@ -226,7 +226,7 @@ bool IfcGeom::convert(IfcSchema::ArbitraryClosedProfileDef* IfcArbitraryClosedPr
bool IfcGeom::convert(IfcSchema::ArbitraryProfileDefWithVoids* IfcArbitraryProfileDefWithVoids, TopoDS_Face& face) {
TopoDS_Wire profile;
if ( ! IfcGeom::convert_wire(IfcArbitraryProfileDefWithVoids->Polyline(),profile) ) return false;
BRepBuilderAPI_MakeFace mf = BRepBuilderAPI_MakeFace(profile);
BRepBuilderAPI_MakeFace mf(profile, false);
IfcEntities voids = IfcArbitraryProfileDefWithVoids->Voids();
for( IfcParse::Entities::it it = voids->begin(); it != voids->end(); ++ it ) {
TopoDS_Wire hole;
@@ -357,16 +357,16 @@ bool IfcGeom::convert_openings(const IfcSchema::BuildingElement* IfcBuildingElem
return true;
}
bool IfcGeom::convert_wire_to_face(const TopoDS_Wire& wire, TopoDS_Face& face) {
BRepBuilderAPI_MakeFace mf = BRepBuilderAPI_MakeFace(wire);
BRepBuilderAPI_MakeFace mf(wire, false);
BRepBuilderAPI_FaceError er = mf.Error();
if ( er == BRepBuilderAPI_NotPlanar ) {
std::cout << "[Notice] Trying to fix non-planar face" << std::endl;
ShapeFix_ShapeTolerance FTol;
FTol.SetTolerance(wire, 0.01, TopAbs_WIRE);
mf = BRepBuilderAPI_MakeFace(wire);
mf = BRepBuilderAPI_MakeFace(wire, false);
er = mf.Error();
}
if ( er != BRepBuilderAPI_FaceDone ) return false;
face = mf.Face();
return true;
}
}