#2805 IfcGeom dynamic casting updates

This commit is contained in:
Thomas Krijnen
2023-06-22 14:07:34 +02:00
parent e9d0b8ab66
commit 65cb47e2d8
7 changed files with 32 additions and 29 deletions
+4 -4
View File
@@ -991,7 +991,7 @@ std::pair<std::string, double> IfcGeom::Kernel::initializeUnits(IfcSchema::IfcUn
} else {
for (auto it = units->begin(); it != units->end(); ++it) {
IfcSchema::IfcUnit* base = *it;
if (base->declaration().is(IfcSchema::IfcNamedUnit::Class())) {
if (base->as<IfcSchema::IfcNamedUnit>()) {
IfcSchema::IfcNamedUnit* named_unit = base->as<IfcSchema::IfcNamedUnit>();
if (named_unit->UnitType() == IfcSchema::IfcUnitEnum::IfcUnit_LENGTHUNIT ||
named_unit->UnitType() == IfcSchema::IfcUnitEnum::IfcUnit_PLANEANGLEUNIT)
@@ -999,10 +999,10 @@ std::pair<std::string, double> IfcGeom::Kernel::initializeUnits(IfcSchema::IfcUn
std::string current_unit_name;
const double current_unit_magnitude = IfcParse::get_SI_equivalent<IfcSchema>(named_unit);
if (current_unit_magnitude != 0.) {
if (named_unit->declaration().is(IfcSchema::IfcConversionBasedUnit::Class())) {
IfcSchema::IfcConversionBasedUnit* u = (IfcSchema::IfcConversionBasedUnit*)base;
if (named_unit->as<IfcSchema::IfcConversionBasedUnit>()) {
IfcSchema::IfcConversionBasedUnit* u = named_unit->as<IfcSchema::IfcConversionBasedUnit>();
current_unit_name = u->Name();
} else if (named_unit->declaration().is(IfcSchema::IfcSIUnit::Class())) {
} else if (named_unit->as<IfcSchema::IfcSIUnit>()) {
IfcSchema::IfcSIUnit* si_unit = named_unit->as<IfcSchema::IfcSIUnit>();
if (si_unit->Prefix()) {
current_unit_name = IfcSchema::IfcSIPrefix::ToString(*si_unit->Prefix()) + unit_name;
+2 -2
View File
@@ -347,8 +347,8 @@ public:
if (surface_style->Side() != IfcSchema::IfcSurfaceSide::IfcSurfaceSide_NEGATIVE) {
auto styles_elements = surface_style->Styles();
for (auto mt = styles_elements->begin(); mt != styles_elements->end(); ++mt) {
if ((*mt)->declaration().is(T::Class())) {
return std::make_pair(surface_style, (T*) *mt);
if ((*mt)->as<T>())) {
return std::make_pair(surface_style, (*mt)->as<T>());
}
}
}
+6 -6
View File
@@ -58,14 +58,14 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcGeometricSet* l, IfcRepresenta
part_succes = true;
decltype(parent_style) style = 0;
if (element->declaration().is(IfcSchema::IfcPoint::Class())) {
style = get_style((IfcSchema::IfcPoint*) element);
if (element->as<IfcSchema::IfcPoint>()) {
style = get_style(element->as<IfcSchema::IfcPoint>());
}
else if (element->declaration().is(IfcSchema::IfcCurve::Class())) {
style = get_style((IfcSchema::IfcCurve*) element);
else if (element->as<IfcSchema::IfcPoint>()) {
style = get_style(element->as<IfcSchema::IfcPoint>());
}
else if (element->declaration().is(IfcSchema::IfcSurface::Class())) {
style = get_style((IfcSchema::IfcSurface*) element);
else if (element->as<IfcSchema::IfcPoint>()) {
style = get_style(element->as<IfcSchema::IfcPoint>());
}
shapes.push_back(IfcRepresentationShapeItem(l->data().id(), s, style ? style : parent_style));
}
+5 -5
View File
@@ -61,8 +61,8 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcIndexedPolyCurve* l, TopoDS_Wi
auto segments = *l->Segments();
for (auto it = segments->begin(); it != segments->end(); ++it) {
auto segment = *it;
if (segment->declaration().is(IfcSchema::IfcLineIndex::Class())) {
IfcSchema::IfcLineIndex* line = (IfcSchema::IfcLineIndex*) segment;
if (segment->as<IfcSchema::IfcLineIndex>()) {
IfcSchema::IfcLineIndex* line = segment->as<IfcSchema::IfcLineIndex>();
std::vector<int> indices = *line;
gp_Pnt previous;
for (std::vector<int>::const_iterator jt = indices.begin(); jt != indices.end(); ++jt) {
@@ -80,8 +80,8 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcIndexedPolyCurve* l, TopoDS_Wi
}
previous = current;
}
} else if (segment->declaration().is(IfcSchema::IfcArcIndex::Class())) {
IfcSchema::IfcArcIndex* arc = (IfcSchema::IfcArcIndex*) segment;
} else if (segment->as<IfcSchema::IfcArcIndex>()) {
IfcSchema::IfcArcIndex* arc = segment->as<IfcSchema::IfcArcIndex>();
std::vector<int> indices = *arc;
if (indices.size() != 3) {
throw IfcParse::IfcException("Invalid IfcArcIndex encountered");
@@ -103,7 +103,7 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcIndexedPolyCurve* l, TopoDS_Wi
Logger::Warning("Ignoring segment on", l);
}
} 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()) {
+2 -2
View File
@@ -28,8 +28,8 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcShellBasedSurfaceModel* l, Ifc
for(auto it = shells->begin(); it != shells->end(); ++ it) {
TopoDS_Shape s;
decltype(collective_style) shell_style;
if ((*it)->declaration().is(IfcSchema::IfcRepresentationItem::Class())) {
shell_style = get_style((IfcSchema::IfcRepresentationItem*)*it);
if ((*it)->as<IfcSchema::IfcRepresentationItem>()) {
shell_style = get_style((*it)->as<IfcSchema::IfcRepresentationItem>());
}
if (convert_shape(*it,s)) {
shapes.push_back(IfcRepresentationShapeItem(l->data().id(), s, shell_style ? shell_style : collective_style));
+8 -8
View File
@@ -85,11 +85,11 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcTrimmedCurve* l, TopoDS_Wire&
for (auto it = trims1->begin(); it != trims1->end(); it ++ ) {
auto i = *it;
if ( i->declaration().is(IfcSchema::IfcCartesianPoint::Class()) ) {
IfcGeom::Kernel::convert((IfcSchema::IfcCartesianPoint*)i, pnts[sense_agreement] );
if (i->as<IfcSchema::IfcCartesianPoint>()) {
IfcGeom::Kernel::convert(i->as<IfcSchema::IfcCartesianPoint>(), pnts[sense_agreement] );
has_pnts[sense_agreement] = true;
} else if ( i->declaration().is(IfcSchema::IfcParameterValue::Class()) ) {
const double value = *((IfcSchema::IfcParameterValue*)i);
} else if (i->as<IfcSchema::IfcParameterValue>()) {
const double value = *i->as<IfcSchema::IfcParameterValue>();
flts[sense_agreement] = value * parameterFactor;
has_flts[sense_agreement] = true;
}
@@ -97,11 +97,11 @@ bool IfcGeom::Kernel::convert(const IfcSchema::IfcTrimmedCurve* l, TopoDS_Wire&
for (auto it = trims2->begin(); it != trims2->end(); it ++ ) {
auto i = *it;
if ( i->declaration().is(IfcSchema::IfcCartesianPoint::Class()) ) {
IfcGeom::Kernel::convert((IfcSchema::IfcCartesianPoint*)i, pnts[1-sense_agreement] );
if (i->as<IfcSchema::IfcCartesianPoint>()) {
IfcGeom::Kernel::convert(i->as<IfcSchema::IfcCartesianPoint>(), pnts[1-sense_agreement] );
has_pnts[1-sense_agreement] = true;
} else if ( i->declaration().is(IfcSchema::IfcParameterValue::Class()) ) {
const double value = *((IfcSchema::IfcParameterValue*)i);
} else if (i->as<IfcSchema::IfcParameterValue>()) {
const double value = *i->as<IfcSchema::IfcParameterValue>();
flts[1-sense_agreement] = value * parameterFactor;
has_flts[1-sense_agreement] = true;
}
+5 -2
View File
@@ -45,8 +45,11 @@ public:
template <class U>
typename U::list::ptr as() {
typename U::list::ptr r(new typename U::list);
const bool all = !U::Class().as_entity();
for (it i = begin(); i != end(); ++i) if (all || (*i)->declaration().is(U::Class())) r->push((U*)*i);
for (it i = begin(); i != end(); ++i) {
if ((*i)->as<U>()) {
r->push((*i)->as<U>());
}
}
return r;
}
void remove(IfcUtil::IfcBaseClass*);