Skip to content

Commit 3801e52

Browse files
committed
Add an XML serializer (NB: Not ifcXML / 10303-28) that describes property set data, decomposition relations and SPF header fields
1 parent c597404 commit 3801e52

File tree

10 files changed

+389
-18
lines changed

10 files changed

+389
-18
lines changed

cmake/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,12 @@ TARGET_LINK_LIBRARIES(IfcGeom IfcParse)
160160

161161
LINK_DIRECTORIES (${LINK_DIRECTORIES} ${IfcOpenShell_BINARY_DIR} ${OCC_LIBRARY_DIR} ${OPENCOLLADA_LIBRARY_DIR} /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64 ${ICU_LIBRARY_DIR} ${Boost_LIBRARY_DIRS})
162162

163-
ADD_EXECUTABLE(IfcConvert
163+
ADD_EXECUTABLE(IfcConvert
164164
../src/ifcconvert/ColladaSerializer.cpp
165165
../src/ifcconvert/IfcConvert.cpp
166166
../src/ifcconvert/OpenCascadeBasedSerializer.cpp
167-
../src/ifcconvert/WavefrontObjSerializer.cpp
167+
../src/ifcconvert/WavefrontObjSerializer.cpp
168+
../src/ifcconvert/XmlSerializer.cpp
168169
)
169170

170171
TARGET_LINK_LIBRARIES (IfcConvert IfcParse IfcGeom TKernel TKMath TKBRep TKGeomBase TKGeomAlgo TKG3d TKG2d TKShHealing TKTopAlgo TKMesh TKPrim TKBool TKBO TKFillet TKSTEP TKSTEPBase TKSTEPAttr TKXSBase TKSTEP209 TKIGES TKOffset ${Boost_LIBRARIES} ${OPENCOLLADA_LIBRARIES})

src/ifcconvert/ColladaSerializer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ class ColladaSerializer : public GeometrySerializer
157157
unit_name = name;
158158
unit_magnitude = magnitude;
159159
}
160+
void setFile(IfcParse::IfcFile*) {}
160161
};
161162

162163
#endif

src/ifcconvert/GeometrySerializer.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@
2020
#ifndef GEOMETRYSERIALIZER_H
2121
#define GEOMETRYSERIALIZER_H
2222

23+
#include "../ifcconvert/Serializer.h"
2324
#include "../ifcgeom/IfcGeomIterator.h"
2425

25-
class GeometrySerializer {
26+
class GeometrySerializer : public Serializer {
2627
public:
27-
virtual bool ready() = 0;
28-
virtual void writeHeader() = 0;
29-
virtual void finalize() = 0;
30-
virtual bool isTesselated() const = 0;
3128
virtual ~GeometrySerializer() {}
29+
30+
virtual bool isTesselated() const = 0;
3231
virtual void write(const IfcGeom::TriangulationElement<double>* o) = 0;
3332
virtual void write(const IfcGeom::BRepElement<double>* o) = 0;
3433
virtual void setUnitNameAndMagnitude(const std::string& name, float magnitude) = 0;

src/ifcconvert/IfcConvert.cpp

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "../ifcconvert/IgesSerializer.h"
4040
#include "../ifcconvert/StepSerializer.h"
4141
#include "../ifcconvert/WavefrontObjSerializer.h"
42+
#include "../ifcconvert/XmlSerializer.h"
4243

4344
void printVersion() {
4445
std::cerr << "IfcOpenShell IfcConvert " << IFCOPENSHELL_VERSION << std::endl;
@@ -55,6 +56,7 @@ void printUsage(const boost::program_options::options_description& generic_optio
5556
#endif
5657
std::cerr << " .stp STEP Standard for the Exchange of Product Data" << std::endl
5758
<< " .igs IGES Initial Graphics Exchange Specification" << std::endl
59+
<< " .xml XML Property definitions and decomposition tree" << std::endl
5860
<< std::endl
5961
<< "Command line options" << std::endl << generic_options << std::endl
6062
<< "Advanced options" << std::endl << geom_options << std::endl;
@@ -196,6 +198,31 @@ int main(int argc, char** argv) {
196198
return 1;
197199
}
198200

201+
std::string output_extension = output_filename.substr(output_filename.size()-4);
202+
for (std::string::iterator c = output_extension.begin(); c != output_extension.end(); ++c) {
203+
*c = tolower(*c);
204+
}
205+
206+
Logger::SetOutput(&std::cout, &log_stream);
207+
Logger::Verbosity(verbose ? Logger::LOG_NOTICE : Logger::LOG_ERROR);
208+
209+
if (output_extension == ".xml") {
210+
int exit_code = 1;
211+
try {
212+
XmlSerializer s(output_filename);
213+
IfcParse::IfcFile f;
214+
if (!f.Init(input_filename)) {
215+
Logger::Message(Logger::LOG_ERROR, "Unable to parse .ifc file");
216+
} else {
217+
s.setFile(&f);
218+
s.finalize();
219+
exit_code = 0;
220+
}
221+
} catch (...) {}
222+
write_log();
223+
return exit_code;
224+
}
225+
199226
IfcGeom::IteratorSettings settings;
200227

201228
settings.set(IfcGeom::IteratorSettings::APPLY_DEFAULT_MATERIALS, true);
@@ -207,14 +234,6 @@ int main(int argc, char** argv) {
207234
settings.set(IfcGeom::IteratorSettings::FORCE_CCW_FACE_ORIENTATION, force_ccw_face_orientation);
208235
settings.set(IfcGeom::IteratorSettings::DISABLE_OPENING_SUBTRACTIONS, disable_opening_subtractions);
209236

210-
std::string output_extension = output_filename.substr(output_filename.size()-4);
211-
for (std::string::iterator c = output_extension.begin(); c != output_extension.end(); ++c) {
212-
*c = tolower(*c);
213-
}
214-
215-
Logger::SetOutput(&std::cout, &log_stream);
216-
Logger::Verbosity(verbose ? Logger::LOG_NOTICE : Logger::LOG_ERROR);
217-
218237
GeometrySerializer* serializer;
219238
if (output_extension == ".obj") {
220239
const std::string mtl_filename = output_filename.substr(0,output_filename.size()-3) + "mtl";
@@ -288,9 +307,16 @@ int main(int argc, char** argv) {
288307
int old_progress = -1;
289308
Logger::Status("Creating geometry...");
290309

291-
// The functions IfcGeomObjects::Get() and IfcGeomObjects::Next() wrap an iterator of all geometrical entities in the Ifc file.
292-
// IfcGeomObjects::Get() returns an IfcGeom::TriangulationElement (see IfcGeomIterator.h for definition)
293-
// IfcGeomObjects::Next() is used to poll whether more geometrical entities are available
310+
// The functions IfcGeom::Iterator::get() and IfcGeom::Iterator::next()
311+
// wrap an iterator of all geometrical products in the Ifc file.
312+
// IfcGeom::Iterator::get() returns an IfcGeom::TriangulationElement or
313+
// -BRepElement pointer, based on current settings. (see IfcGeomIterator.h
314+
// for definition) IfcGeom::Iterator::next() is used to poll whether more
315+
// geometrical entities are available. None of these functions throw
316+
// exceptions, neither for parsing errors or geometrical errors. Upon
317+
// calling next() the entity to be returned has already been processed, a
318+
// true return value guarantees that a successfully processed product is
319+
// available.
294320
do {
295321
const IfcGeom::Element<double>* geom_object = context_iterator.get();
296322

@@ -316,6 +342,8 @@ int main(int argc, char** argv) {
316342
time(&end);
317343
int dif = (int) difftime (end,start);
318344
printf ("\nConversion took %d seconds\n", dif );
345+
346+
return 0;
319347
}
320348

321349
void write_log() {

src/ifcconvert/OpenCascadeBasedSerializer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class OpenCascadeBasedSerializer : public GeometrySerializer {
4141
void write(const IfcGeom::TriangulationElement<double>* o) {}
4242
void write(const IfcGeom::BRepElement<double>* o);
4343
bool isTesselated() const { return false; }
44+
void setFile(IfcParse::IfcFile*) {}
4445
};
4546

4647
#endif

src/ifcconvert/Serializer.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
#ifndef SERIALIZER_H
21+
#define SERIALIZER_H
22+
23+
#include "../ifcparse/IfcFile.h"
24+
25+
class Serializer {
26+
public:
27+
virtual ~Serializer() {}
28+
29+
virtual bool ready() = 0;
30+
virtual void writeHeader() = 0;
31+
virtual void finalize() = 0;
32+
virtual void setFile(IfcParse::IfcFile*) = 0;
33+
};
34+
35+
#endif

src/ifcconvert/WavefrontObjSerializer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class WaveFrontOBJSerializer : public GeometrySerializer {
5050
void finalize() {}
5151
bool isTesselated() const { return true; }
5252
void setUnitNameAndMagnitude(const std::string& name, float magnitude) {}
53+
void setFile(IfcParse::IfcFile*) {}
5354
};
5455

5556
#endif

0 commit comments

Comments
 (0)