/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #include "IfcCurveSegmentParametrizationTask.h" #include "daiValidationCommon.h" #include "IfcEntity.h" #include "IfcCurveSegment.h" #include "IfcFile.h" #define BASE_CURVE_SEGMENT_NAME "IfcCurveSegment" using namespace OdIfc; using namespace OdDAI; ODRX_VALIDATION_CONS_DEFINE_MEMBERS(CurveSegmentParametrizationValidationTask, ExtentValidationTask, RXIMPL_CONSTR); ODRX_CONS_DEFINE_MEMBERS(CurveSegmentParametrizationValidationHealer, OdDAI::ValidationHealer, RXIMPL_CONSTR); CurveSegmentParametrizationValidationTask::CurveSegmentParametrizationValidationTask() { m_extentName = BASE_CURVE_SEGMENT_NAME; } OdDAI::Logical CurveSegmentParametrizationValidationTask::validate(OdDAI::InstanceValidationContext* instanceCtx, OdSharedPtr& invalidParams) { InvalidRxArrayValidationParams* invalidInstances = new InvalidRxArrayValidationParams(); invalidParams = invalidInstances; OdDAI::InstanceValidationContext* pIfcCtx = dynamic_cast(instanceCtx); if (pIfcCtx == nullptr) { return Logical::False; } OdDAIObjectId idParentCurve; pIfcCtx->pInstance->getAttr("parentcurve") >> idParentCurve; if (idParentCurve.isValid() == false) { return Logical::True; // Not responsibility of this validation task. } OdDAI::ApplicationInstancePtr parentCurve = idParentCurve.openObject(); if (parentCurve->isKindOf("ifcclothoid") == false) { return Logical::True; } bool isSegmentStartOk{ true }; bool isSegmentLengthOk{ true }; // OdDAI::Select* segmentStart{}; if (!(pIfcCtx->pInstance->getAttr("segmentstart") >> segmentStart)) { ODA_ASSERT_ONCE(!"Error while processing segment start!"); return Logical::False; } else if (segmentStart->underlyingTypeName() == "ifcparametervalue") { double paramVal{}; segmentStart->getDouble(paramVal); if (OdGreater(fabs(paramVal), Oda2PI)) { isSegmentStartOk = false; } } // OdDAI::Select* segmentLength{}; if (!(pIfcCtx->pInstance->getAttr("segmentlength") >> segmentLength)) { ODA_ASSERT_ONCE(!"Error while processing segment length!"); return Logical::False; } else if (segmentLength->underlyingTypeName() == "ifcparametervalue") { double paramVal{}; segmentLength->getDouble(paramVal); if (OdGreater(fabs(paramVal), Oda2PI)) { isSegmentLengthOk = false; } } if (!isSegmentStartOk || !isSegmentLengthOk) { InvalidRxObjectsValidationParams irxovp({ pIfcCtx->pInstance }, "Incorrect segment start/length", Logical::False); invalidInstances->addData(irxovp); return Logical::False; } return Logical::True; } OdAnsiString CurveSegmentParametrizationValidationTask::description() const { return "Curve segments parametrization validation"; } OdDAI::Logical CurveSegmentParametrizationValidationHealer::heal(OdDAI::Model* model, OdDAI::ValidationTask::InvalidValidationParamsBase* invalidParams) { OdDAIObjectIds invalidInstances; OdDAI::ValidationTask::InvalidObjectIdsValidationParams* idsParams = dynamic_cast(invalidParams); if (idsParams) { invalidInstances = idsParams->invalidObjects; } OdDAI::ValidationTask::InvalidRxObjectsValidationParams* rxObjectsParams = dynamic_cast(invalidParams); if (rxObjectsParams) { for (const auto& it : rxObjectsParams->invalidObjects) { OdDAI::ApplicationInstancePtr inst = it; invalidInstances.append(inst->id()); } } OdDAI::Logical res = OdDAI::Logical::False; for (auto invalidInstance : invalidInstances) { OdDAI::ApplicationInstance* curveSegment = invalidInstance.openObject(); if (!curveSegment->isKindOf("ifccurvesegment")) continue; OdDAI::Select* segmentStart{}; if ((curveSegment->getAttr("segmentstart") >> segmentStart)) { if (segmentStart->underlyingTypeName() == "ifcparametervalue") { double paramVal{}; segmentStart->getDouble(paramVal); if (OdGreater(fabs(paramVal), Oda2PI)) { if (segmentStart->underlyingTypeName("ifclengthmeasure")) { segmentStart->setDouble(paramVal); res = OdDAI::Logical::True; } } } } OdDAI::Select* segmentLength{}; if ((curveSegment->getAttr("segmentlength") >> segmentLength)) { if (segmentLength->underlyingTypeName() == "ifcparametervalue") { double paramVal{}; segmentLength->getDouble(paramVal); if (OdGreater(fabs(paramVal), Oda2PI)) { if (segmentLength->underlyingTypeName("ifclengthmeasure")) { segmentLength->setDouble(paramVal); res = OdDAI::Logical::True; } } } } } return res; }