Skip to content

Commit 509c34d

Browse files
committed
Initial attempt at new python wrapper
1 parent da616ff commit 509c34d

29 files changed

Lines changed: 3353 additions & 417 deletions

README

Lines changed: 0 additions & 65 deletions
This file was deleted.

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
IfcOpenShell
2+
============
3+
open source (LGPL) software library for working with the IFC file format
4+
5+
6+
http://IfcOpenShell.org
7+
8+
About this repository
9+
=====================
10+
11+
This is an initiative to expose the functionality of IfcOpenShell for parsing and writing IFC files to a Python interface. The creation of a topological representation for building elements using Open Cascade is also wrapped by returning a string serialization of the Open Cascade TopoDS_Shape. Using SWIG a wrapper is obtained for a C++ Class which evaluates its Express attribute names and indices at runtime. The functions created by the SWIG wrapper closely resemble the C++ structure. The idea is to create an additional wrapper around these function in Python that is more idiomatic to Python.
12+
13+
The following interactive session illustrates its use:
14+
15+
>>> import IfcImport
16+
>>> f = IfcImport.open(filename)
17+
>>> f.by_type("ifcwall")
18+
[#170=IfcWallStandardCase('0lJANQLbCEHPkU1Xq9w_bk',#13,'Wand-001',$,$,#167,#240,'2F4CA5DA-5653-0E45-9B-9E-061D09EBE96E'),
19+
#288=IfcWallStandardCase('1sFBHOg98nGQTuD1XjjAKK',#13,'Wand-002',$,$,#285,#358,'763CB458-A892-3141-A7-78-34186DB4A514')]
20+
>>> wall = _[0]
21+
>>> brep_data = IfcImport.create_shape(wall)
22+
>>> wall.get_argument_count()
23+
8
24+
>>> wall.get_argument('GlobalId')
25+
'0lJANQLbCEHPkU1Xq9w_bk'
26+
>>> wall.get_argument_index('Name')
27+
2
28+
>>> wall.set_argument(2,"John")
29+
>>> wall.get_argument('Name')
30+
'John'
31+
>>> wall.get_argument_index("foo")
32+
Traceback (most recent call last):
33+
File "<stdin>", line 1, in <module>
34+
File "IfcImport.py", line 112, in get_argument_index
35+
def get_argument_index(self, *args): return _IfcImport.Entity_get_argument_index(self, *args)
36+
RuntimeError: Argument foo not found on IfcRoot
37+
>>> wall.set_argument(5,"Hi")
38+
Traceback (most recent call last):
39+
File "<stdin>", line 1, in <module>
40+
File "IfcImport.py", line 114, in set_argument
41+
def set_argument(self, *args): return _IfcImport.Entity_set_argument(self, *args)
42+
RuntimeError: STRING is not a valid type for 'ObjectPlacement'
43+
>>> e = IfcImport.Entity("IfcJohn")
44+
Traceback (most recent call last):
45+
File "<stdin>", line 1, in <module>
46+
File "IfcImport.py", line 105, in __init__
47+
this = _IfcImport.new_Entity(*args)
48+
RuntimeError: Unable to find find keyword in schema
49+
>>> pnt = IfcImport.Entity("ifccartesianpoint")
50+
[60478 refs]
51+
>>> pnt.set_argument(0,IfcImport.Doubles([0,0,0]))
52+
[60486 refs]
53+
>>> pnt
54+
=IfcCartesianPoint((0,0,0))
55+
>>> f.add(pnt)
56+
>>> f.write("out.ifc")
57+
58+
**TODO**: By creating an additional wrapper in Python around these methods some syntactic sugar can be added so one is able to say the following instead:
59+
60+
d = IfcDocument()
61+
my_wall = d.createIfcWallStandardCase("1$gyu8123...",Representation=my_repr)
62+
63+
With a document specifying a 'catch-all' function that creates the ifc entity based on the method being called, perhaps like so:
64+
65+
class IfcDocument:
66+
def create_entity(self,type,*args,**kwargs):
67+
e = new IfcEntity(type)
68+
# set all attributes in args and kwargs
69+
self.add(e)
70+
return e
71+
def __getattr__(self,attr):
72+
if attr[0:5] == 'create': return functools.partial(self.create_entity,attr[5:])
73+
...
74+
75+
76+
Compiling on Windows
77+
====================
78+
Users are advised to use the Visual Studio .sln file in the win/ folder.
79+
For Windows users a prebuilt Open CASCADE version is available from the
80+
http://opencascade.org website. Download and install this version and
81+
provide the paths to the Open CASCADE header and library files to MS
82+
Visual Studio C++.
83+
84+
For building the Autodesk 3ds Max plugin, the 3ds Max SDK needs to be
85+
installed as well as 3ds Max itself. Please provide the include and
86+
library paths to Visual Studio.
87+
88+
For building the IfcPython wrapper, SWIG needs to be installed. Please
89+
download the latest swigwin version from http://www.swig.org/download.html.
90+
After extracting the .zip file, please add the extracted folder to the PATH
91+
environment variable. Python needs to be installed, please provide the
92+
include and library paths to Visual Studio.
93+
94+
95+
96+
Compiling on *nix
97+
====================
98+
Users are advised to build IfcOpenShell using the cmake file provided in
99+
the cmake/ folder. There might be an Open CASCADE package in your operating
100+
system's software repository. If not, you will need to compile Open
101+
CASCADE yourself. See http://opencascade.org.
102+
103+
For building the IfcPython wrapper, SWIG and Python development are
104+
required.
105+
106+
To build IfcOpenShell please take the following steps:
107+
$ cd /path/to/IfcOpenShell/cmake
108+
$ mkdir build
109+
$ cd build
110+
Optionally:
111+
$ OCC_INCLUDE_PATH="/path/to/OpenCASCADE/include"
112+
$ OCC_LIBRARY_PATH="/path/to/OpenCASCADE/lib"
113+
$ export OCC_INCLUDE_PATH
114+
$ export OCC_LIBRARY_PATH
115+
$ cmake ../
116+
$ make
117+
118+
If all worked out correctly you can now use IfcOpenShell. For example:
119+
$ wget ftp://ftp.dds.no/pub/ifc/Munkerud/Munkerud_hus6_BE.zip
120+
$ unzip Munkerud_hus6_BE.zip
121+
$ ./IfcObj Munkerud_hus6_BE.ifc
122+
$ less Munkerud_hus6_BE.obj

cmake/CMakeLists.txt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ ENDIF(MSVC)
9191
INCLUDE_DIRECTORIES(${OCC_INCLUDE_DIR} /usr/inc /usr/local/inc /usr/local/include/oce ${ICU_INCLUDE_DIR})
9292

9393
ADD_LIBRARY(IfcParse STATIC
94+
../src/ifcparse/Ifc2x3-rt.cpp
9495
../src/ifcparse/Ifc2x3.cpp
95-
../src/ifcparse/IfcUtil.cpp
96-
../src/ifcparse/IfcParse.cpp
9796
../src/ifcparse/IfcCharacterDecoder.cpp
98-
99-
../src/ifcparse/IfcWrite.cpp
10097
../src/ifcparse/IfcGuidHelper.cpp
98+
../src/ifcparse/IfcParse.cpp
99+
../src/ifcparse/IfcUntypedEntity.cpp
100+
../src/ifcparse/IfcUtil.cpp
101+
../src/ifcparse/IfcWrite.cpp
101102
)
102103

103104
ADD_LIBRARY(IfcGeom STATIC
@@ -150,17 +151,20 @@ SET(include_files_geom
150151
../src/ifcgeom/IfcShapeList.h
151152
)
152153
SET(include_files_parse
154+
../src/ifcparse/ArgumentType.h
155+
../src/ifcparse/Ifc2x3-rt.h
153156
../src/ifcparse/Ifc2x3.h
154157
../src/ifcparse/Ifc2x3enum.h
155158
../src/ifcparse/IfcCharacterDecoder.h
156159
../src/ifcparse/IfcException.h
157160
../src/ifcparse/IfcFile.h
158161
../src/ifcparse/IfcParse.h
162+
../src/ifcparse/IfcSpfStream.h
163+
../src/ifcparse/IfcUntypedEntity.h
159164
../src/ifcparse/IfcUtil.h
160-
../src/ifcparse/SharedPointer.h
161-
162165
../src/ifcparse/IfcWrite.h
163-
../src/ifcparse/IfcWritableEntity.h
166+
../src/ifcparse/IfcWritableEntity.h
167+
../src/ifcparse/SharedPointer.h
164168
)
165169
INSTALL(FILES ${include_files_geom} DESTINATION include/ifcgeom)
166170
INSTALL(FILES ${include_files_parse} DESTINATION include/ifcparse)

0 commit comments

Comments
 (0)