2023-11-08 19:42:41 -08:00
|
|
|
/********************************************************************************
|
|
|
|
|
* *
|
|
|
|
|
* This file is part of IfcOpenShell. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is free software: you can redistribute it and/or modify *
|
|
|
|
|
* it under the terms of the Lesser GNU General Public License as published by *
|
|
|
|
|
* the Free Software Foundation, either version 3.0 of the License, or *
|
|
|
|
|
* (at your option) any later version. *
|
|
|
|
|
* *
|
|
|
|
|
* IfcOpenShell is distributed in the hope that it will be useful, *
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
|
* Lesser GNU General Public License for more details. *
|
|
|
|
|
* *
|
|
|
|
|
* You should have received a copy of the Lesser GNU General Public License *
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
|
|
|
|
* *
|
|
|
|
|
********************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "mapping.h"
|
|
|
|
|
#define mapping POSTFIX_SCHEMA(mapping)
|
|
|
|
|
using namespace ifcopenshell::geometry;
|
|
|
|
|
|
2025-01-02 11:10:56 -08:00
|
|
|
#include "../function_item_evaluator.h"
|
2024-09-10 10:11:17 -07:00
|
|
|
|
2023-11-08 19:42:41 -08:00
|
|
|
#ifdef SCHEMA_HAS_IfcSegmentedReferenceCurve
|
|
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
taxonomy::ptr mapping::map_impl(const IfcSchema::IfcSegmentedReferenceCurve& inst) {
|
|
|
|
|
if (!inst.BaseCurve().as<IfcSchema::IfcGradientCurve>())
|
2026-06-10 18:30:54 +02:00
|
|
|
logger_.Warning("GEO", 291, "Expected IfcSegmentedReferenceCurve.BaseCurve to be IfcGradient", inst); // CT 4.1.7.1.1.3
|
2023-11-08 19:42:41 -08:00
|
|
|
|
2026-01-04 10:40:02 +01:00
|
|
|
auto segments = inst.Segments();
|
2023-11-08 19:42:41 -08:00
|
|
|
|
2025-01-02 11:10:56 -08:00
|
|
|
taxonomy::piecewise_function::spans_t spans;
|
2026-01-04 10:40:02 +01:00
|
|
|
for (auto& segment : segments) {
|
|
|
|
|
if (auto cseg = segment.as<IfcSchema::IfcCurveSegment>()) {
|
2023-11-08 19:42:41 -08:00
|
|
|
// @todo check that we don't get a mixture of implicit and explicit definitions
|
2026-01-04 10:40:02 +01:00
|
|
|
auto crv = map(cseg);
|
2025-01-02 11:10:56 -08:00
|
|
|
if (auto fi = taxonomy::dcast<taxonomy::function_item>(crv); crv && fi /*crv->kind() == taxonomy::FUNCTION_ITEM*/) {
|
|
|
|
|
// crv->kind() is polymorphic and the kind of the actual function_item is returned. PWF can have spans of any FUNCTION_ITEM
|
|
|
|
|
// for this reason, a dynamic cast is used and if crv is a function_item it is added to the span
|
|
|
|
|
spans.push_back(fi);
|
|
|
|
|
} else {
|
2026-06-10 18:30:54 +02:00
|
|
|
logger_.Error("UNS", 17, "Unsupported");
|
2023-11-08 19:42:41 -08:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2026-06-10 18:30:54 +02:00
|
|
|
logger_.Error("UNS", 18, "Unsupported");
|
2023-11-08 19:42:41 -08:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
2024-07-29 09:48:15 -07:00
|
|
|
}
|
2023-11-08 19:42:41 -08:00
|
|
|
|
2024-07-29 09:48:15 -07:00
|
|
|
// Get starting position of cant curve, relative to the gradient curve.
|
|
|
|
|
// The cant curve can start before or after the start of the gradient curve
|
2026-01-04 10:40:02 +01:00
|
|
|
auto& first_segment = segments.front();
|
2025-05-17 16:01:28 +02:00
|
|
|
taxonomy::matrix4::ptr p;
|
|
|
|
|
#ifdef SCHEMA_IfcCurveSegment_HAS_Placement
|
2026-01-04 10:40:02 +01:00
|
|
|
p = taxonomy::cast<taxonomy::matrix4>(map(first_segment.as<IfcSchema::IfcCurveSegment>().Placement()));
|
2025-05-17 16:01:28 +02:00
|
|
|
#else
|
|
|
|
|
throw std::runtime_error("Unsupported schema");
|
|
|
|
|
#endif
|
|
|
|
|
const Eigen::Matrix4d& m = p->ccomponents();
|
2024-07-29 09:48:15 -07:00
|
|
|
double cant_start = m(0, 3); // start of cant curve
|
|
|
|
|
|
2025-01-02 11:10:56 -08:00
|
|
|
auto cant = taxonomy::make<taxonomy::piecewise_function>(cant_start,spans);
|
2026-01-04 10:40:02 +01:00
|
|
|
auto gradient = taxonomy::cast<taxonomy::gradient_function>(map(inst.BaseCurve()));
|
2024-09-06 08:38:44 -07:00
|
|
|
|
2025-01-02 11:10:56 -08:00
|
|
|
auto cant_function = taxonomy::make<taxonomy::cant_function>(gradient, cant, inst);
|
|
|
|
|
if (!(0 < cant_function->length())) {
|
2026-06-10 18:30:54 +02:00
|
|
|
logger_.Error("GEO", 292, "IfcSegmentedReferenceCurve does not have a common domain with BaseCurve");
|
2025-01-02 11:10:56 -08:00
|
|
|
cant_function = nullptr;
|
|
|
|
|
}
|
|
|
|
|
return cant_function;
|
2023-11-08 19:42:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|