Skip to content

Commit a1016d8

Browse files
committed
Initial commit
0 parents  commit a1016d8

34 files changed

+16844
-0
lines changed

COPYING

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
IfcOpenShell
2+
============
3+
open source (LGPL) software library for working with the IFC file format
4+
5+
6+
http://IfcOpenShell.org
7+
8+
9+
Compiling on Windows
10+
====================
11+
Users are advised to use the Visual Studio .sln file in the win/ folder.
12+
For Windows users a prebuilt Open CASCADE version is available from the
13+
http://opencascade.org website. Download and install this version and
14+
provide the paths to the Open CASCADE header and library files to MS
15+
Visual Studio C++.
16+
17+
For building the Autodesk 3ds Max plugin, the 3ds Max SDK needs to be
18+
installed as well as 3ds Max itself. Please provide the include and
19+
library paths to Visual Studio.
20+
21+
For building the IfcPython wrapper, SWIG needs to be installed. Please
22+
download the latest swigwin version from http://www.swig.org/download.html.
23+
After extracting the .zip file, please add the extracted folder to the PATH
24+
environment variable. Python needs to be installed, please provide the
25+
include and library paths to Visual Studio.
26+
27+
28+
29+
Compiling on *nix
30+
====================
31+
Users are advised to build IfcOpenShell using the cmake file provided in
32+
the cmake/ folder. There might be an Open CASCADE package in your operating
33+
system's software repository. If not, you will need to compile Open
34+
CASCADE yourself. See http://opencascade.org.
35+
36+
For building the IfcPython wrapper, SWIG and Python development are
37+
required.
38+
39+
To build IfcOpenShell please take the following steps:
40+
$ cd /path/to/IfcOpenShell/cmake
41+
$ mkdir build
42+
$ cd build
43+
Optionally:
44+
$ OCC_INCLUDE_PATH="/path/to/OpenCASCADE/include"
45+
$ OCC_LIBRARY_PATH="/path/to/OpenCASCADE/lib"
46+
$ export OCC_INCLUDE_PATH
47+
$ export OCC_LIBRARY_PATH
48+
$ cmake ../
49+
$ make
50+
51+
If all worked out correctly you can now use IfcOpenShell. For example:
52+
$ wget ftp://ftp.dds.no/pub/ifc/Munkerud/Munkerud_hus6_BE.zip
53+
$ unzip Munkerud_hus6_BE.zip
54+
$ ./IfcObj Munkerud_hus6_BE.ifc
55+
$ less Munkerud_hus6_BE.obj
56+
Or:
57+
$ wget ftp://ftp.dds.no/pub/ifc/Munkerud/Munkerud_hus6_BE.zip
58+
$ unzip Munkerud_hus6_BE.zip
59+
$ python
60+
>>> import IfcImport
61+
>>> IfcImport.Init('Munkerud_hus6_BE.ifc')
62+
>>> geom = IfcImport.Get()
63+
>>> geom.name
64+
>>> for v in geom.mesh.verts: v
65+

cmake/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
cmake_minimum_required (VERSION 2.6)
2+
project (IfcOpenShell)
3+
4+
# Find Open CASCADE header files
5+
IF("$ENV{OCC_INCLUDE_DIR}" STREQUAL "")
6+
SET(OCC_INCLUDE_DIR "/usr/include/opencascade/" CACHE FILEPATH "Open CASCADE header files")
7+
MESSAGE(STATUS "Looking for opencascade include files in: ${OCC_INCLUDE_DIR}")
8+
MESSAGE(STATUS "Use OCC_INCLUDE_DIR to specify another directory")
9+
ELSE()
10+
SET(OCC_INCLUDE_DIR $ENV{OCC_INCLUDE_DIR} CACHE FILEPATH "Open CASCADE header files")
11+
MESSAGE(STATUS "Looking for opencascade include files in: ${OCC_INCLUDE_DIR}")
12+
ENDIF()
13+
14+
FIND_FILE(gp_Pnt_hxx "gp_Pnt.hxx" ${OCC_INCLUDE_DIR})
15+
IF(gp_Pnt_hxx)
16+
MESSAGE(STATUS "Header files found")
17+
ELSE()
18+
MESSAGE(FATAL_ERROR "Unable to find header files, aborting")
19+
ENDIF()
20+
21+
22+
# Find Open CASCADE library files
23+
IF("$ENV{OCC_LIBRARY_DIR}" STREQUAL "")
24+
SET(OCC_LIBRARY_DIR "/usr/lib/" CACHE FILEPATH "Open CASCADE library files")
25+
MESSAGE(STATUS "Looking for opencascade library files in: ${OCC_LIBRARY_DIR}")
26+
MESSAGE(STATUS "Use OCC_LIBRARY_DIR to specify another directory")
27+
ELSE()
28+
SET(OCC_LIBRARY_DIR $ENV{OCC_LIBRARY_DIR} CACHE FILEPATH "Open CASCADE library files")
29+
MESSAGE(STATUS "Looking for opencascade library files in: ${OCC_LIBRARY_DIR}")
30+
ENDIF()
31+
32+
FIND_LIBRARY(libTKernel "TKernel" ${OCC_LIBRARY_DIR})
33+
IF(libTKernel)
34+
MESSAGE(STATUS "Library files found")
35+
ELSE()
36+
MESSAGE(FATAL_ERROR "Unable to find library files, aborting")
37+
ENDIF()
38+
39+
ADD_DEFINITIONS(-DHAVE_LIMITS_H)
40+
ADD_DEFINITIONS(-DHAVE_IOSTREAM)
41+
ADD_DEFINITIONS(-DHAVE_IOMANIP)
42+
ADD_DEFINITIONS(-DHAVE_FSTREAM)
43+
ADD_DEFINITIONS(-O3)
44+
ADD_DEFINITIONS(-fPIC)
45+
46+
INCLUDE_DIRECTORIES(${OCC_INCLUDE_DIR})
47+
ADD_LIBRARY(IfcParse STATIC ../src/ifcparse/IfcEnum.cpp ../src/ifcparse/IfcTypes.cpp ../src/ifcparse/IfcParse.cpp ../src/ifcparse/IfcGeom.cpp ../src/ifcparse/IfcGeomObjects.cpp)
48+
49+
LINK_DIRECTORIES (${IfcOpenShell_BINARY_DIR} /usr/lib)
50+
ADD_EXECUTABLE(IfcObj ../src/ifcobj/IfcObj.cpp)
51+
TARGET_LINK_LIBRARIES (IfcObj IfcParse TKAdvTools TKMath TKernel TKBRep TKGeomBase TKGeomAlgo TKBool TKMesh TKShHealing)
52+
53+
# Build python wrapper using separate CMakeLists.txt
54+
ADD_SUBDIRECTORY(../src/ifcwrap .)

src/ifcblender/IfcBlender.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import bpy, mathutils
2+
from bpy.props import *
3+
from io_utils import ImportHelper
4+
5+
class ImportIFC(bpy.types.Operator, ImportHelper):
6+
'''Load an IFC File'''
7+
bl_idname = "import_scene.ifc"
8+
bl_label = "Import IFC"
9+
10+
filename_ext = ".ifc"
11+
filter_glob = StringProperty(default="*.ifc", options={'HIDDEN'})
12+
13+
def execute(self, context):
14+
import IFCimport
15+
IFCimport.init_objs(self.filepath)
16+
ids = {}
17+
while True:
18+
ob = IFCimport.current_obj()
19+
print (ob.name)
20+
if not ob.type in ['IFCSPACE','IFCOPENINGELEMENT']:
21+
f = ob.mesh.faces
22+
v = ob.mesh.verts
23+
m = ob.matrix
24+
if ob.mesh.id in ids: me = ids[ob.mesh.id]
25+
else:
26+
verts = []
27+
faces = []
28+
for i in range(0,len(f),3):
29+
faces.append([f[i+0],f[i+1],f[i+2]])
30+
for i in range(0,len(v),3):
31+
verts.append([v[i+0],v[i+1],v[i+2]])
32+
me = bpy.data.meshes.new('mesh%d'%ob.mesh.id)
33+
me.from_pydata(verts,[],faces)
34+
if ob.type in bpy.data.materials:
35+
mat = bpy.data.materials[ob.type]
36+
mat.use_fake_user = True
37+
else: mat = bpy.data.materials.new(ob.type)
38+
me.materials.append(mat)
39+
ids[ob.mesh.id] = me
40+
bob = bpy.data.objects.new(ob.name,me)
41+
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])
42+
bpy.context.scene.objects.link(bob)
43+
me.update()
44+
if not IFCimport.next_obj(): break
45+
return {'FINISHED'}
46+
47+
def menu_func_import(self, context):
48+
self.layout.operator(ImportIFC.bl_idname, text="Industry Foundation Classes (.ifc)")
49+
def register():
50+
bpy.types.INFO_MT_file_import.append(menu_func_import)
51+
register()

src/ifcmax/IfcMax.cpp

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
/********************************************************************************
2+
* *
3+
* This file is part of IfcOpenShell. *
4+
* *
5+
* IfcOpenShell is free software: you can redistribute it and/or modify *
6+
* it under the terms of the Lesser GNU General Public License as published by *
7+
* the Free Software Foundation, either version 3.0 of the License, or *
8+
* (at your option) any later version. *
9+
* *
10+
* IfcOpenShell is distributed in the hope that it will be useful, *
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13+
* Lesser GNU General Public License for more details. *
14+
* *
15+
* You should have received a copy of the Lesser GNU General Public License *
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
17+
* *
18+
********************************************************************************/
19+
20+
#include "Max.h"
21+
#include "stdmat.h"
22+
#include "decomp.h"
23+
#include "shape.h"
24+
#include "splshape.h"
25+
#include "dummy.h"
26+
#include "istdplug.h"
27+
28+
#include "../ifcmax/IfcMax.h"
29+
#include "../ifcmax/MaxMaterials.h"
30+
#include "../ifcparse/IfcGeomObjects.h"
31+
32+
int controlsInit = false;
33+
34+
BOOL WINAPI DllMain(HINSTANCE hinstDLL,ULONG fdwReason,LPVOID lpvReserved) {
35+
if (!controlsInit) {
36+
controlsInit = true;
37+
InitCommonControls();
38+
}
39+
return true;
40+
}
41+
42+
__declspec( dllexport ) const TCHAR* LibDescription() {
43+
return _T("IfcOpenShell IFC Importer");
44+
}
45+
46+
__declspec( dllexport ) int LibNumberClasses() { return 1; }
47+
48+
static class IFCImpClassDesc:public ClassDesc {
49+
public:
50+
int IsPublic() {return 1;}
51+
void * Create(BOOL loading = FALSE) {return new IFCImp;}
52+
const TCHAR * ClassName() {return _T("IFCImp");}
53+
SClass_ID SuperClassID() {return SCENE_IMPORT_CLASS_ID;}
54+
Class_ID ClassID() {return Class_ID(0x3f230dbf, 0x5b3015c2);}
55+
const TCHAR* Category() {return _T("Chrutilities");}
56+
} IFCImpDesc;
57+
58+
__declspec( dllexport ) ClassDesc* LibClassDesc(int i) {
59+
return i == 0 ? &IFCImpDesc : 0;
60+
}
61+
62+
__declspec( dllexport ) ULONG LibVersion() {
63+
return VERSION_3DSMAX;
64+
}
65+
66+
int IFCImp::ExtCount() { return 1; }
67+
68+
const TCHAR * IFCImp::Ext(int n) {
69+
return n == 0 ? _T("IFC") : _T("");
70+
}
71+
72+
const TCHAR * IFCImp::LongDesc() {
73+
return _T("IfcOpenShell IFC Importer for 3ds Max");
74+
}
75+
76+
const TCHAR * IFCImp::ShortDesc() {
77+
return _T("Industry Foundation Classes");
78+
}
79+
80+
const TCHAR * IFCImp::AuthorName() {
81+
return _T("Thomas Krijnen");
82+
}
83+
84+
const TCHAR * IFCImp::CopyrightMessage() {
85+
return _T("Copyight (c) 2011 IfcOpenShell");
86+
}
87+
88+
const TCHAR * IFCImp::OtherMessage1() {
89+
return _T("");
90+
}
91+
92+
const TCHAR * IFCImp::OtherMessage2() {
93+
return _T("");
94+
}
95+
96+
unsigned int IFCImp::Version() {
97+
return 12;
98+
}
99+
100+
static BOOL CALLBACK AboutBoxDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
101+
return TRUE;
102+
}
103+
104+
void IFCImp::ShowAbout(HWND hWnd) {}
105+
106+
DWORD WINAPI fn(LPVOID arg) { return 0; }
107+
108+
int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL suppressPrompts) {
109+
110+
itfc->ProgressStart("Importing file...", TRUE, fn, NULL);
111+
112+
if ( ! IfcGeomObjects::Init((char*)name) ) return false;
113+
114+
std::map<int, TriObject*> dict;
115+
MtlBaseLib* mats = itfc->GetSceneMtls();
116+
int slot = mats->Count();
117+
118+
do{
119+
120+
const IfcGeomObjects::IfcGeomObject* o = IfcGeomObjects::Get();
121+
122+
Mtl *m;
123+
const int matIndex = mats->FindMtlByName(MSTR(o->type.c_str()));
124+
if ( matIndex == -1 ) {
125+
StdMat2* stdm = GetMaterial(o->type);
126+
m = stdm;
127+
m->SetName(o->type.c_str());
128+
mats->Add(m);
129+
itfc->PutMtlToMtlEditor(m,slot++);
130+
} else {
131+
m = static_cast<Mtl*>((*mats)[matIndex]);
132+
}
133+
134+
std::map<int, TriObject*>::const_iterator it = dict.find(o->mesh->id);
135+
136+
TriObject* tri;
137+
if ( it == dict.end() ) {
138+
tri = CreateNewTriObject();
139+
const int numVerts = o->mesh->verts.size()/3;
140+
tri->mesh.setNumVerts(numVerts);
141+
for( int i = 0; i < numVerts; i ++ ) {
142+
tri->mesh.setVert(i,o->mesh->verts[3*i+0],o->mesh->verts[3*i+1],o->mesh->verts[3*i+2]);
143+
}
144+
const int numFaces = o->mesh->faces.size()/3;
145+
tri->mesh.setNumFaces(numFaces);
146+
for( int i = 0; i < numFaces; i ++ ) {
147+
tri->mesh.faces[i].setVerts(o->mesh->faces[3*i+0],o->mesh->faces[3*i+1],o->mesh->faces[3*i+2]);
148+
tri->mesh.faces[i].setEdgeVisFlags(o->mesh->edges[3*i+0],o->mesh->edges[3*i+1],o->mesh->edges[3*i+2]);
149+
}
150+
tri->mesh.InvalidateTopologyCache();
151+
tri->mesh.InvalidateGeomCache();
152+
tri->mesh.buildNormals();
153+
tri->mesh.BuildStripsAndEdges();
154+
dict[o->mesh->id] = tri;
155+
} else {
156+
tri = (*it).second;
157+
}
158+
159+
ImpNode* node = impitfc->CreateNode();
160+
node->Reference(tri);
161+
node->SetName(o->name.c_str());
162+
node->GetINode()->SetMtl(m);
163+
node->SetTransform(0,Matrix3 ( Point3(o->matrix[0],o->matrix[1],o->matrix[2]),Point3(o->matrix[3],o->matrix[4],o->matrix[5]),
164+
Point3(o->matrix[6],o->matrix[7],o->matrix[8]),Point3(o->matrix[9],o->matrix[10],o->matrix[11]) ));
165+
impitfc->AddNodeToScene(node);
166+
167+
itfc->ProgressUpdate(IfcGeomObjects::Progress(),true,"");
168+
169+
} while ( IfcGeomObjects::Next() );
170+
171+
itfc->ProgressEnd();
172+
173+
return true;
174+
}

src/ifcmax/IfcMax.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
LIBRARY ifcmax.dli
2+
EXPORTS
3+
LibDescription @1
4+
LibNumberClasses @2
5+
LibClassDesc @3
6+
LibVersion @4
7+
SECTIONS
8+
.data READ WRITE

0 commit comments

Comments
 (0)