3939#include " ../ifcconvert/IgesSerializer.h"
4040#include " ../ifcconvert/StepSerializer.h"
4141#include " ../ifcconvert/WavefrontObjSerializer.h"
42+ #include " ../ifcconvert/XmlSerializer.h"
4243
4344void 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 (" \n Conversion took %d seconds\n " , dif );
345+
346+ return 0 ;
319347}
320348
321349void write_log () {
0 commit comments