Use struct instead of namespace to represent schema

This commit is contained in:
Thomas Krijnen
2017-12-13 18:05:10 +01:00
parent 761e9d7248
commit 5eba7af791
18 changed files with 35799 additions and 38220 deletions
File diff suppressed because it is too large Load Diff
+7649 -8661
View File
File diff suppressed because one or more lines are too long
+2618 -2619
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+7135 -7136
View File
File diff suppressed because it is too large Load Diff
+8966 -10163
View File
File diff suppressed because one or more lines are too long
+3225 -3226
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+19 -5
View File
@@ -97,7 +97,7 @@ public:
IfcFile(std::istream& fn, int len);
IfcFile(void* data, int len);
IfcFile(IfcParse::IfcSpfStream* f);
IfcFile(const IfcParse::schema_definition* schema = IfcParse::schema_by_name(IfcSchema::Identifier));
IfcFile(const IfcParse::schema_definition* schema = IfcParse::schema_by_name("IFC4"));
~IfcFile();
@@ -149,7 +149,7 @@ public:
IfcUtil::IfcBaseClass* instance_by_id(int id);
/// Returns the entity with the specified GlobalId
IfcUtil::IfcBaseClass* instance_by_guid(const std::string& guid);
virtual IfcUtil::IfcBaseClass* instance_by_guid(const std::string& guid);
/// Performs a depth-first traversal, returning all entity instance
/// attributes as a flat list. NB: includes the root instance specified
@@ -170,8 +170,6 @@ public:
std::string createTimestamp() const;
std::pair<IfcSchema::IfcNamedUnit*, double> getUnit(IfcSchema::IfcUnitEnum::IfcUnitEnum);
void load(const IfcEntityInstanceData&);
void load(unsigned entity_instance_name, std::vector<Argument*>& attributes);
@@ -180,8 +178,24 @@ public:
void unregister_inverse(unsigned, IfcUtil::IfcBaseClass*);
const IfcParse::schema_definition* schema() const { return schema_; }
std::pair<IfcUtil::IfcBaseClass*, double> getUnit(const std::string& unit_type);
};
template <typename Schema>
class IFC_PARSE_API IfcFileWithSchema : public IfcFile {
public:
std::pair<typename Schema::IfcNamedUnit*, double> getUnit(typename Schema::IfcUnitEnum::Value unit_type) {
std::pair<IfcUtil::IfcBaseClass*, double> unit_info = IfcFile::getUnit(Schema::IfcUnitEnum::ToString(unit_type));
return std::make_pair(unit_info.first->as<typename Schema::IfcNamedUnit>(), unit_info.second);
}
/// Returns the entity with the specified GlobalId
virtual typename Schema::IfcRoot::list::ptr instance_by_guid(const std::string& guid) {
return IfcFile::instance_by_guid(guid)->as<Schema::IfcRoot>();
}
};
}
#endif
#endif
+56 -25
View File
@@ -1281,8 +1281,8 @@ void IfcFile::initialize_(IfcParse::IfcSpfStream* s) {
}
if (schema_ == 0) {
schema_ = IfcParse::schema_by_name(IfcSchema::Identifier);
Logger::Message(Logger::LOG_ERROR, "Unable to deduce schema version from header identifiers");
schema_ = IfcParse::schema_by_name("IFC4");
Logger::Message(Logger::LOG_ERROR, "Unable to deduce schema version from header identifiers, defaulting to IFC4");
}
ifcroot_type_ = schema_->declaration_by_name("IfcRoot");
@@ -1538,8 +1538,8 @@ IfcUtil::IfcBaseClass* IfcFile::addEntity(IfcUtil::IfcBaseClass* entity) {
we->setArgument(i, copy);
} else if (decl && decl->is(*schema()->declaration_by_name("IfcLengthMeasure"))) {
if (boost::math::isnan(conversion_factor)) {
const std::pair<IfcSchema::IfcNamedUnit*, double> this_file_unit = getUnit(IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT);
const std::pair<IfcSchema::IfcNamedUnit*, double> other_file_unit = other_file->getUnit(IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT);
const std::pair<IfcUtil::IfcBaseClass*, double> this_file_unit = getUnit("LENGTHUNIT");
const std::pair<IfcUtil::IfcBaseClass*, double> other_file_unit = other_file->getUnit("LENGTHUNIT");
std::cerr << other_file_unit.second << " " << this_file_unit.second << std::endl;
if (this_file_unit.first && other_file_unit.first) {
conversion_factor = other_file_unit.second / this_file_unit.second;
@@ -1938,7 +1938,7 @@ void IfcFile::setDefaultHeaderValues() {
std::vector<std::string> file_description, schema_identifiers, empty_vector;
file_description.push_back("ViewDefinition [CoordinationView]");
schema_identifiers.push_back(IfcSchema::Identifier);
schema_identifiers.push_back(schema()->name());
header().file_description().description(file_description);
header().file_description().implementation_level("2;1");
@@ -1954,38 +1954,69 @@ void IfcFile::setDefaultHeaderValues() {
header().file_schema().schema_identifiers(schema_identifiers);
}
std::pair<IfcSchema::IfcNamedUnit*, double> IfcFile::getUnit(IfcSchema::IfcUnitEnum::IfcUnitEnum type) {
std::pair<IfcSchema::IfcNamedUnit*, double> return_value((IfcSchema::IfcNamedUnit*)0, 1.);
IfcSchema::IfcProject::list::ptr projects = instances_by_type<IfcSchema::IfcProject>();
std::pair<IfcUtil::IfcBaseClass*, double> IfcFile::getUnit(const std::string& unit_type) {
std::pair<IfcUtil::IfcBaseClass*, double> return_value(0, 1.);
IfcEntityList::ptr projects = instances_by_type(schema()->declaration_by_name("IfcProject"));
if (projects->size() == 1) {
IfcSchema::IfcProject* project = *projects->begin();
IfcEntityList::ptr units = project->UnitsInContext()->Units();
IfcUtil::IfcBaseClass* project = *projects->begin();
IfcUtil::IfcBaseClass* unit_assignment = *project->data().getArgument(
project->declaration().as_entity()->attribute_index("UnitsInContext")
);
IfcEntityList::ptr units = *unit_assignment->data().getArgument(
unit_assignment->declaration().as_entity()->attribute_index("Units")
);
for (IfcEntityList::it it = units->begin(); it != units->end(); ++it) {
IfcSchema::IfcUnit* unit = *it;
if (unit->declaration().is(IfcSchema::Type::IfcNamedUnit)) {
IfcSchema::IfcNamedUnit* named_unit = (IfcSchema::IfcNamedUnit*) unit;
if (named_unit->UnitType() != type) {
if (unit->declaration().is("IfcNamedUnit")) {
const std::string file_unit_type = *unit->data().getArgument(
unit->declaration().as_entity()->attribute_index("UnitType")
);
if (file_unit_type != unit_type) {
continue;
}
IfcSchema::IfcSIUnit* siunit = 0;
if (named_unit->declaration().is(IfcSchema::Type::IfcConversionBasedUnit)) {
IfcSchema::IfcConversionBasedUnit* u = (IfcSchema::IfcConversionBasedUnit*)named_unit;
IfcSchema::IfcMeasureWithUnit* mu = u->ConversionFactor();
return_value.second *= static_cast<double>(*mu->ValueComponent()->data().getArgument(0));
return_value.first = named_unit;
if (mu->UnitComponent()->declaration().is(IfcSchema::Type::IfcSIUnit)) {
siunit = (IfcSchema::IfcSIUnit*) mu->UnitComponent();
IfcUtil::IfcBaseClass* siunit = 0;
if (unit->declaration().is("IfcConversionBasedUnit")) {
IfcUtil::IfcBaseClass* mu = *unit->data().getArgument(
unit->declaration().as_entity()->attribute_index("ConversionFactor")
);
IfcUtil::IfcBaseClass* vlc = *mu->data().getArgument(
mu->declaration().as_entity()->attribute_index("ValueComponent")
);
IfcUtil::IfcBaseClass* unc = *mu->data().getArgument(
mu->declaration().as_entity()->attribute_index("ValueComponent")
);
return_value.second *= static_cast<double>(*vlc->data().getArgument(0));
return_value.first = unit;
if (unc->declaration().is("IfcSIUnit")) {
siunit = unc;
}
} else if (named_unit->declaration().is(IfcSchema::Type::IfcSIUnit)) {
return_value.first = siunit = (IfcSchema::IfcSIUnit*) named_unit;
} else if (unit->declaration().is("IfcSIUnit")) {
return_value.first = siunit = unit;
}
if (siunit) {
if (siunit->hasPrefix()) {
return_value.second *= IfcSIPrefixToValue(siunit->Prefix());
Argument* prefix = siunit->data().getArgument(
siunit->declaration().as_entity()->attribute_index("Prefix")
);
if (!prefix->isNull()) {
return_value.second *= IfcSIPrefixToValue(*prefix);
}
}
}
}
}
return return_value;
}
+20 -18
View File
@@ -18,26 +18,27 @@
********************************************************************************/
#include "IfcSIPrefix.h"
double IfcParse::IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix v) {
if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_EXA ) return 1.e18;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_PETA ) return 1.e15;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_TERA ) return 1.e12;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_GIGA ) return 1.e9;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MEGA ) return 1.e6;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_KILO ) return 1.e3;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_HECTO ) return 1.e2;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_DECA ) return 1.;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_DECI ) return 1.e-1;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_CENTI ) return 1.e-2;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MILLI ) return 1.e-3;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_MICRO ) return 1.e-6;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_NANO ) return 1.e-9;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_PICO ) return 1.e-12;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_FEMTO ) return 1.e-15;
else if ( v == IfcSchema::IfcSIPrefix::IfcSIPrefix_ATTO ) return 1.e-18;
double IfcParse::IfcSIPrefixToValue(const std::string& v) {
if ( v == "EXA" ) return 1.e18;
else if ( v == "PETA" ) return 1.e15;
else if ( v == "TERA" ) return 1.e12;
else if ( v == "GIGA" ) return 1.e9;
else if ( v == "MEGA" ) return 1.e6;
else if ( v == "KILO" ) return 1.e3;
else if ( v == "HECTO" ) return 1.e2;
else if ( v == "DECA" ) return 1.;
else if ( v == "DECI" ) return 1.e-1;
else if ( v == "CENTI" ) return 1.e-2;
else if ( v == "MILLI" ) return 1.e-3;
else if ( v == "MICRO" ) return 1.e-6;
else if ( v == "NANO" ) return 1.e-9;
else if ( v == "PICO" ) return 1.e-12;
else if ( v == "FEMTO" ) return 1.e-15;
else if ( v == "ATTO" ) return 1.e-18;
else return 1.;
}
/*
double IfcParse::get_SI_equivalent(IfcSchema::IfcNamedUnit* named_unit) {
double scale = 1.;
IfcSchema::IfcSIUnit* si_unit = 0;
@@ -63,4 +64,5 @@ double IfcParse::get_SI_equivalent(IfcSchema::IfcNamedUnit* named_unit) {
}
return scale;
}
}
*/
+2 -2
View File
@@ -24,8 +24,8 @@
#include "ifc_parse_api.h"
namespace IfcParse {
IFC_PARSE_API double IfcSIPrefixToValue(IfcSchema::IfcSIPrefix::IfcSIPrefix);
IFC_PARSE_API double get_SI_equivalent(IfcSchema::IfcNamedUnit*);
IFC_PARSE_API double IfcSIPrefixToValue(const std::string& prefix);
// IFC_PARSE_API double get_SI_equivalent(IfcSchema::IfcNamedUnit*);
}
#endif
+1 -1
View File
@@ -36,7 +36,7 @@ static const char * const DATA = "DATA";
using namespace IfcParse;
HeaderEntity::HeaderEntity(const char * const datatype, IfcFile* file)
: IfcEntityInstanceData(IfcSchema::Type::UNDEFINED, file), _datatype(datatype)
: IfcEntityInstanceData(0, file), _datatype(datatype)
{
if (file) {
offset_in_file_ = file->stream->Tell();
+3 -3
View File
@@ -57,12 +57,12 @@ void IfcEntityList::remove(IfcUtil::IfcBaseClass* instance) {
}
}
IfcEntityList::ptr IfcEntityList::filtered(const std::set<IfcSchema::Type::Enum>& entities) {
IfcEntityList::ptr IfcEntityList::filtered(const std::set<const IfcParse::declaration*>& entities) {
IfcEntityList::ptr return_value(new IfcEntityList);
for (it it = begin(); it != end(); ++it) {
bool contained = false;
for (std::set<IfcSchema::Type::Enum>::const_iterator jt = entities.begin(); jt != entities.end(); ++jt) {
if ((*it)->declaration().is(*jt)) {
for (std::set<const IfcParse::declaration*>::const_iterator jt = entities.begin(); jt != entities.end(); ++jt) {
if ((*it)->declaration().is(**jt)) {
contained = true;
break;
}