Merge branch 'master' into v0.6.0

# Conflicts:
#	src/ifcconvert/IfcConvert.cpp
#	src/ifcgeom/IfcGeomRenderStyles.cpp
#	src/ifcparse/IfcParse.cpp
This commit is contained in:
Thomas Krijnen
2018-10-30 14:32:28 +01:00
8 changed files with 149 additions and 51 deletions
+32 -19
View File
@@ -35,6 +35,7 @@
#include "../ifcgeom_schema_agnostic/IfcGeomFilter.h"
#include "../ifcgeom_schema_agnostic/IfcGeomIterator.h"
#include "../ifcgeom_schema_agnostic/IfcGeomRenderStyles.h"
#include <Standard_Version.hxx>
@@ -43,6 +44,7 @@
#endif
#include <boost/program_options.hpp>
#include <boost/make_shared.hpp>
#include <fstream>
#include <sstream>
@@ -177,6 +179,7 @@ int main(int argc, char** argv)
exclusion_filter exclude_filter;
exclusion_traverse_filter exclude_traverse_filter;
std::string filter_filename;
std::string default_material_filename;
po::options_description geom_options("Geometry options");
geom_options.add_options()
@@ -257,8 +260,10 @@ int main(int argc, char** argv)
"Sets the deflection tolerance of the mesher, 1e-3 by default if not specified.")
("generate-uvs",
"Generates UVs (texture coordinates) by using simple box projection. Requires normals. "
"Not guaranteed to work properly if used with --weld-vertices.");
"Not guaranteed to work properly if used with --weld-vertices.")
("default-material-file", po::value<std::string>(&default_material_filename),
"Specifies a material file that describes the material object types will have"
"if an object does not have any specified material in the IFC file.");
std::string bounds, offset_str;
#ifdef HAVE_ICU
@@ -488,7 +493,18 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
}
if (!default_material_filename.empty()) {
try {
IfcGeom::set_default_style_file(default_material_filename);
} catch (const std::exception& e) {
std::cerr << "[Error] Could not read default material file " << default_material_filename << ":" << std::endl;
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
}
/// @todo Clean up this filter code further.
std::vector<geom_filter> used_filters;
if (include_filter.type != geom_filter::UNUSED) { used_filters.push_back(include_filter); }
@@ -535,7 +551,7 @@ int main(int argc, char** argv)
settings.set_deflection_tolerance(deflection_tolerance);
settings.precision = precision;
GeometrySerializer* serializer;
boost::shared_ptr<GeometrySerializer> serializer; /**< @todo use std::unique_ptr when possible */
if (output_extension == ".obj") {
// Do not use temp file for MTL as it's such a small file.
const std::string mtl_filename = change_extension(output_filename, "mtl");
@@ -543,28 +559,28 @@ int main(int argc, char** argv)
Logger::Notice("Using world coords when writing WaveFront OBJ files");
settings.set(IfcGeom::IteratorSettings::USE_WORLD_COORDS, true);
}
serializer = new WaveFrontOBJSerializer(output_temp_filename, mtl_filename, settings);
serializer = boost::make_shared<WaveFrontOBJSerializer>(output_temp_filename, mtl_filename, settings);
#ifdef WITH_OPENCOLLADA
} else if (output_extension == ".dae") {
serializer = new ColladaSerializer(output_temp_filename, settings);
serializer = boost::make_shared<ColladaSerializer>(output_temp_filename, settings);
#endif
} else if (output_extension == ".stp") {
serializer = new StepSerializer(output_temp_filename, settings);
serializer = boost::make_shared<StepSerializer>(output_temp_filename, settings);
} else if (output_extension == ".igs") {
#if OCC_VERSION_HEX < 0x60900
// According to https://tracker.dev.opencascade.org/view.php?id=25689 something has been fixed in 6.9.0
IGESControl_Controller::Init(); // work around Open Cascade bug
#endif
serializer = new IgesSerializer(output_temp_filename, settings);
serializer = boost::make_shared<IgesSerializer>(output_temp_filename, settings);
} else if (output_extension == ".svg") {
settings.set(IfcGeom::IteratorSettings::DISABLE_TRIANGULATION, true);
serializer = new SvgSerializer(output_temp_filename, settings);
serializer = boost::make_shared<SvgSerializer>(output_temp_filename, settings);
if (vmap.count("section-height") != 0) {
Logger::Notice("Overriding section height");
static_cast<SvgSerializer*>(serializer)->setSectionHeight(section_height);
static_cast<SvgSerializer*>(serializer.get())->setSectionHeight(section_height);
}
if (bounding_width.is_initialized() && bounding_height.is_initialized()) {
static_cast<SvgSerializer*>(serializer)->setBoundingRectangle(bounding_width.get(), bounding_height.get());
static_cast<SvgSerializer*>(serializer.get())->setBoundingRectangle(bounding_width.get(), bounding_height.get());
}
} else {
std::cerr << "[Error] Unknown output filename extension '" + output_extension + "'\n";
@@ -573,13 +589,11 @@ int main(int argc, char** argv)
return EXIT_FAILURE;
}
// NOTE After this point, make sure to delete serializer upon application exit.
if (use_element_hierarchy && output_extension != ".dae") {
std::cerr << "[Error] --use-element-hierarchy can be used only with .dae output.\n";
/// @todo Lots of duplicate error-and-exit code.
write_log(!quiet);
print_usage();
delete serializer;
std::remove(output_temp_filename.c_str()); /**< @todo Windows Unicode support */
return EXIT_FAILURE;
}
@@ -600,7 +614,6 @@ int main(int argc, char** argv)
}
if (!serializer->ready()) {
delete serializer;
std::remove(output_temp_filename.c_str()); /**< @todo Windows Unicode support */
write_log(!quiet);
return EXIT_FAILURE;
@@ -610,6 +623,8 @@ int main(int argc, char** argv)
time(&start);
if (!init_input_file(input_filename, ifc_file, no_progress || quiet, mmap)) {
write_log(!quiet);
std::remove(output_temp_filename.c_str()); /**< @todo Windows Unicode support */
return EXIT_FAILURE;
}
@@ -618,7 +633,6 @@ int main(int argc, char** argv)
/// @todo It would be nice to know and print separate error prints for a case where we found no entities
/// and for a case we found no entities that satisfy our filtering criteria.
Logger::Error("No geometrical entities found");
delete serializer;
std::remove(output_temp_filename.c_str()); /**< @todo Windows Unicode support */
write_log(!quiet);
return EXIT_FAILURE;
@@ -641,7 +655,6 @@ int main(int argc, char** argv)
if (center_model) {
if (site_local_placement || building_local_placement) {
Logger::Error("Cannot use --center-model together with --{site,building}-local-placement");
delete serializer;
return EXIT_FAILURE;
}
@@ -658,7 +671,6 @@ int main(int argc, char** argv)
} else {
if (sscanf(offset_str.c_str(), "%lf;%lf;%lf", &offset[0], &offset[1], &offset[2]) != 3) {
std::cerr << "[Error] Invalid use of --model-offset\n";
delete serializer;
std::remove(output_temp_filename.c_str()); /**< @todo Windows Unicode support */
print_options(serializer_options);
return EXIT_FAILURE;
@@ -732,7 +744,8 @@ int main(int argc, char** argv)
}
serializer->finalize();
delete serializer;
// Make sure the dtor is explicitly run here (e.g. output files are closed before renaming them).
serializer.reset();
// Renaming might fail (e.g. maybe the existing file was open in a viewer application)
// Do not remove the temp file as user can salvage the conversion result from it.