| 26 | #ifdef SCHEMA_HAS_IfcSegmentedReferenceCurve |
| 27 | |
| 28 | taxonomy::ptr mapping::map_impl(const IfcSchema::IfcSegmentedReferenceCurve* inst) { |
| 29 | if (!inst->BaseCurve()->as<IfcSchema::IfcGradientCurve>()) |
| 30 | Logger::Warning("Expected IfcSegmentedReferenceCurve.BaseCurve to be IfcGradient", inst); // CT 4.1.7.1.1.3 |
| 31 | |
| 32 | auto segments = inst->Segments(); |
| 33 | |
| 34 | taxonomy::piecewise_function::spans_t spans; |
| 35 | for (auto& segment : *segments) { |
| 36 | if (segment->as<IfcSchema::IfcCurveSegment>()) { |
| 37 | // @todo check that we don't get a mixture of implicit and explicit definitions |
| 38 | auto crv = map(segment->as<IfcSchema::IfcCurveSegment>()); |
| 39 | if (auto fi = taxonomy::dcast<taxonomy::function_item>(crv); crv && fi /*crv->kind() == taxonomy::FUNCTION_ITEM*/) { |
| 40 | // crv->kind() is polymorphic and the kind of the actual function_item is returned. PWF can have spans of any FUNCTION_ITEM |
| 41 | // for this reason, a dynamic cast is used and if crv is a function_item it is added to the span |
| 42 | spans.push_back(fi); |
| 43 | } else { |
| 44 | Logger::Error("Unsupported"); |
| 45 | return nullptr; |
| 46 | } |
| 47 | } else { |
| 48 | Logger::Error("Unsupported"); |
| 49 | return nullptr; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // Get starting position of cant curve, relative to the gradient curve. |
| 54 | // The cant curve can start before or after the start of the gradient curve |
| 55 | auto first_segment = *(segments->begin()); |
| 56 | taxonomy::matrix4::ptr p; |
| 57 | #ifdef SCHEMA_IfcCurveSegment_HAS_Placement |
| 58 | p = taxonomy::cast<taxonomy::matrix4>(map(first_segment->as<IfcSchema::IfcCurveSegment>()->Placement())); |
| 59 | #else |
| 60 | throw std::runtime_error("Unsupported schema"); |
| 61 | #endif |
| 62 | const Eigen::Matrix4d& m = p->ccomponents(); |
| 63 | double cant_start = m(0, 3); // start of cant curve |
| 64 | |
| 65 | auto cant = taxonomy::make<taxonomy::piecewise_function>(cant_start,spans); |
| 66 | auto gradient = taxonomy::cast<taxonomy::gradient_function>(map(inst->BaseCurve())); |
| 67 | |
| 68 | auto cant_function = taxonomy::make<taxonomy::cant_function>(gradient, cant, inst); |
| 69 | if (!(0 < cant_function->length())) { |
| 70 | Logger::Error("IfcSegmentedReferenceCurve does not have a common domain with BaseCurve"); |
| 71 | cant_function = nullptr; |
| 72 | } |
| 73 | return cant_function; |
| 74 | } |
| 75 | |
| 76 | #endif |