IfcGeom dynamic casting updates #2805

This commit is contained in:
Thomas Krijnen
2023-06-22 14:07:34 +02:00
parent 77839efd6a
commit 3266648896
3 changed files with 15 additions and 17 deletions
+5 -5
View File
@@ -50,8 +50,8 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcIndexedPolyCurve* inst) {
auto segments = *inst->Segments(); auto segments = *inst->Segments();
for (auto it = segments->begin(); it != segments->end(); ++it) { for (auto it = segments->begin(); it != segments->end(); ++it) {
auto segment = *it; auto segment = *it;
if (segment->declaration().is(IfcSchema::IfcLineIndex::Class())) { if (segment->as<IfcSchema::IfcLineIndex>()) {
IfcSchema::IfcLineIndex* line = (IfcSchema::IfcLineIndex*) segment; IfcSchema::IfcLineIndex* line = segment->as<IfcSchema::IfcLineIndex>();
std::vector<int> indices = *line; std::vector<int> indices = *line;
taxonomy::point3::ptr previous; taxonomy::point3::ptr previous;
for (std::vector<int>::const_iterator jt = indices.begin(); jt != indices.end(); ++jt) { for (std::vector<int>::const_iterator jt = indices.begin(); jt != indices.end(); ++jt) {
@@ -64,8 +64,8 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcIndexedPolyCurve* inst) {
} }
previous = current; previous = current;
} }
} else if (segment->declaration().is(IfcSchema::IfcArcIndex::Class())) { } else if (segment->as<IfcSchema::IfcArcIndex>()) {
IfcSchema::IfcArcIndex* arc = (IfcSchema::IfcArcIndex*) segment; IfcSchema::IfcArcIndex* arc = segment->as<IfcSchema::IfcArcIndex>();
std::vector<int> indices = *arc; std::vector<int> indices = *arc;
if (indices.size() != 3) { if (indices.size() != 3) {
throw IfcParse::IfcException("Invalid IfcArcIndex encountered"); throw IfcParse::IfcException("Invalid IfcArcIndex encountered");
@@ -89,7 +89,7 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcIndexedPolyCurve* inst) {
Logger::Warning("Ignoring segment on", inst); Logger::Warning("Ignoring segment on", inst);
} }
} else { } else {
throw IfcParse::IfcException("Unexpected IfcIndexedPolyCurve segment of type " + segment->declaration().name()); throw IfcParse::IfcException("Unexpected IfcIndexedPolyCurve segment of type " + segment->as<IfcUtil::IfcBaseClass>()->declaration().name());
} }
} }
} else if (points.begin() < points.end()) { } else if (points.begin() < points.end()) {
+6 -6
View File
@@ -48,11 +48,11 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcTrimmedCurve* inst) {
for (auto it = trims1->begin(); it != trims1->end(); it ++) { for (auto it = trims1->begin(); it != trims1->end(); it ++) {
auto i = *it; auto i = *it;
if ( i->declaration().is(IfcSchema::IfcCartesianPoint::Class()) ) { if (i->as<IfcSchema::IfcCartesianPoint>()) {
pnts[sense_agreement] = taxonomy::cast<taxonomy::point3>(map(i)); pnts[sense_agreement] = taxonomy::cast<taxonomy::point3>(map(i));
has_pnts[sense_agreement] = true; has_pnts[sense_agreement] = true;
} else if ( i->declaration().is(IfcSchema::IfcParameterValue::Class()) ) { } else if (i->as<IfcSchema::IfcParameterValue>()) {
const double value = *((IfcSchema::IfcParameterValue*)i); const double value = *i->as<IfcSchema::IfcParameterValue>();
flts[sense_agreement] = value * parameterFactor; flts[sense_agreement] = value * parameterFactor;
has_flts[sense_agreement] = true; has_flts[sense_agreement] = true;
} }
@@ -60,11 +60,11 @@ taxonomy::ptr mapping::map_impl(const IfcSchema::IfcTrimmedCurve* inst) {
for (auto it = trims2->begin(); it != trims2->end(); it ++) { for (auto it = trims2->begin(); it != trims2->end(); it ++) {
auto i = *it; auto i = *it;
if ( i->declaration().is(IfcSchema::IfcCartesianPoint::Class()) ) { if (i->as<IfcSchema::IfcCartesianPoint>()) {
pnts[1 - sense_agreement] = taxonomy::cast<taxonomy::point3>(map(i)); pnts[1 - sense_agreement] = taxonomy::cast<taxonomy::point3>(map(i));
has_pnts[1-sense_agreement] = true; has_pnts[1-sense_agreement] = true;
} else if ( i->declaration().is(IfcSchema::IfcParameterValue::Class()) ) { } else if (i->as<IfcSchema::IfcParameterValue>()) {
const double value = *((IfcSchema::IfcParameterValue*)i); const double value = *i->as<IfcSchema::IfcParameterValue>();
flts[1-sense_agreement] = value * parameterFactor; flts[1-sense_agreement] = value * parameterFactor;
has_flts[1-sense_agreement] = true; has_flts[1-sense_agreement] = true;
} }
+4 -6
View File
@@ -90,10 +90,9 @@ class aggregate_of {
template <class U> template <class U>
typename U::list::ptr as() { typename U::list::ptr as() {
typename U::list::ptr result(new typename U::list); typename U::list::ptr result(new typename U::list);
const bool all = !U::Class().as_entity();
for (it i = begin(); i != end(); ++i) { for (it i = begin(); i != end(); ++i) {
if (all || (*i)->declaration().is(U::Class())) { if ((*i)->as<U>()) {
result->push((U*)*i); result->push(r->push((*i)->as<U>());
} }
} }
return result; return result;
@@ -150,13 +149,12 @@ class IFC_PARSE_API aggregate_of_aggregate_of_instance {
template <class U> template <class U>
typename aggregate_of_aggregate_of<U>::ptr as() { typename aggregate_of_aggregate_of<U>::ptr as() {
typename aggregate_of_aggregate_of<U>::ptr result(new aggregate_of_aggregate_of<U>); typename aggregate_of_aggregate_of<U>::ptr result(new aggregate_of_aggregate_of<U>);
const bool all = !U::Class().as_entity();
for (outer_it outer = begin(); outer != end(); ++outer) { for (outer_it outer = begin(); outer != end(); ++outer) {
const std::vector<IfcUtil::IfcBaseClass*>& from = *outer; const std::vector<IfcUtil::IfcBaseClass*>& from = *outer;
typename std::vector<U*> to; typename std::vector<U*> to;
for (inner_it inner = from.begin(); inner != from.end(); ++inner) { for (inner_it inner = from.begin(); inner != from.end(); ++inner) {
if (all || (*inner)->declaration().is(U::Class())) { if ((*inner)->as<U>()) {
to.push_back((U*)*inner); to.push_back((*i)->as<U>());
} }
} }
result->push(to); result->push(to);