Begin to implement IfcConvert enhancements discussed in #20. Remove C++-specific getters and setters and use the same set() and get() functions in in both C++ and Python. Enhance output of IfcConvert, especially in error situations (spamming a hundred lines of options always hides the original error message), utilize Boost's foreach macro to provide cleaner iteration code.

This commit is contained in:
Stinkfist0
2016-03-07 22:37:36 +02:00
parent e35cefac52
commit 0da0e63687
14 changed files with 426 additions and 311 deletions
+54 -28
View File
@@ -86,6 +86,9 @@ namespace IfcGeom {
template <typename P>
class Iterator {
private:
Iterator(const Iterator&); // N/I
Iterator& operator=(const Iterator&); // N/I
Kernel kernel;
IteratorSettings settings;
@@ -121,6 +124,7 @@ namespace IfcGeom {
}
}
std::set<boost::regex> names_to_include_or_exclude; // regex containing a name or a wildcard expression
std::set<IfcSchema::Type::Enum> entities_to_include_or_exclude;
bool include_entities_in_processing;
@@ -148,7 +152,7 @@ namespace IfcGeom {
} catch (...) {}
std::set<std::string> context_types;
if (!settings.exclude_solids_and_surfaces()) {
if (!settings.get(IteratorSettings::EXCLUDE_SOLIDS_AND_SURFACES)) {
// Really this should only be 'Model', as per
// the standard 'Design' is deprecated. So,
// just for backwards compatibility:
@@ -157,7 +161,7 @@ namespace IfcGeom {
// DDS likes to output 'model view'
context_types.insert("model view");
}
if (settings.include_curves()) {
if (settings.get(IteratorSettings::INCLUDE_CURVES)) {
context_types.insert("plan");
}
@@ -250,36 +254,46 @@ namespace IfcGeom {
return true;
}
int progress() {
return 100 * done / total;
}
int progress() const { return 100 * done / total; }
const std::string& getUnitName() {
return unit_name;
}
const std::string& getUnitName() const { return unit_name; }
const P getUnitMagnitude() {
return unit_magnitude;
}
P getUnitMagnitude() const { return unit_magnitude; }
const std::string getLog() {
return Logger::GetLog();
}
std::string getLog() const { return Logger::GetLog(); }
IfcParse::IfcFile* getFile() {
return ifc_file;
}
IfcParse::IfcFile* getFile() const { return ifc_file; }
/// @note Entity names are handled case-insensitively.
void includeEntities(const std::set<std::string>& entities) {
populate_set(entities);
include_entities_in_processing = true;
}
/// @note Entity names are handled case-insensitively.
void excludeEntities(const std::set<std::string>& entities) {
populate_set(entities);
include_entities_in_processing = false;
}
// Arbitrary names or wildcard expressions are handled case-sensitively.
void include_entity_names(const std::vector<std::string>& names)
{
names_to_include_or_exclude.clear();
foreach(const std::string &name, names)
names_to_include_or_exclude.insert(IfcUtil::wildcard_string_to_regex(name));
include_entities_in_processing = true;
}
// Arbitrary names or wildcard expressions are handled case-sensitively.
void exclude_entity_names(const std::vector<std::string>& names)
{
names_to_include_or_exclude.clear();
foreach(const std::string &name, names)
names_to_include_or_exclude.insert(IfcUtil::wildcard_string_to_regex(name));
include_entities_in_processing = false;
}
private:
// Move to the next IfcRepresentation
void _nextShape() {
@@ -330,6 +344,14 @@ namespace IfcGeom {
break;
}
}
foreach(const boost::regex& r, names_to_include_or_exclude) {
if (boost::regex_match((*it)->Name(), r)) {
found = true;
break;
}
}
if (found == include_entities_in_processing) {
ifcproducts->push(*jt);
}
@@ -382,13 +404,17 @@ namespace IfcGeom {
return create();
}
Element<P>* get() {
// TODO: Test settings and throw
if (current_triangulation) return current_triangulation;
else if (current_serialization) return current_serialization;
else if (current_shape_model) return current_shape_model;
else return 0;
}
/// Gets or takes the representation of the current geometrical entity.
/// @param take_ownership Pass in 'true' as if wishing to maintain the element lifetime yourself.
Element<P>* get(bool take_ownership = false)
{
// TODO: Test settings and throw
Element<P>* ret = 0;
if (current_triangulation) { ret = current_triangulation; if (take_ownership) current_triangulation = 0; }
else if (current_serialization) { ret = current_serialization; if (take_ownership) current_serialization = 0; }
else if (current_shape_model) { ret = current_shape_model; if (take_ownership) current_shape_model = 0; }
return ret;
}
const Element<P>* getObject(int id) {
@@ -430,12 +456,12 @@ namespace IfcGeom {
current_shape_model = create_shape_model_for_next_entity();
} catch (...) {}
if (!current_shape_model) return false;
if (settings.use_brep_data()) {
if (settings.get(IteratorSettings::USE_BREP_DATA)) {
try {
current_serialization = new SerializedElement<P>(*current_shape_model);
} catch (...) {}
return !!current_serialization;
} else if (!settings.disable_triangulation()) {
} else if (!settings.get(IteratorSettings::DISABLE_TRIANGULATION)) {
try {
current_triangulation = new TriangulationElement<P>(*current_shape_model);
} catch (...) {}
@@ -457,8 +483,8 @@ namespace IfcGeom {
unit_name = "METER";
unit_magnitude = 1.f;
kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.sew_shells() ? 1000 : -1);
kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.include_curves() ? (settings.exclude_solids_and_surfaces() ? -1. : 0.) : +1.));
kernel.setValue(IfcGeom::Kernel::GV_MAX_FACES_TO_SEW, settings.get(IteratorSettings::SEW_SHELLS) ? 1000 : -1);
kernel.setValue(IfcGeom::Kernel::GV_DIMENSIONALITY, (settings.get(IteratorSettings::INCLUDE_CURVES) ? (settings.get(IteratorSettings::EXCLUDE_SOLIDS_AND_SURFACES) ? -1. : 0.) : +1.));
}
bool owns_ifc_file;