/////////////////////////////////////////////////////////////////////////////// // 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 "OdaCommon.h" #include "DWGConstraintArgsValidator.h" #include "DbPolyline.h" ConstraintArgsValidator::ConstraintArgsValidator() : modificator(Modificator::Default), argumentNumber(0) { } bool ConstraintArgsValidator::isEntityValidForConstraint(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { OdDbEntityPtr entity = entityId.safeOpenObject(); if (entity->isKindOf(OdDbBlockReference::desc())) return true; return isEntityValidForConstraintPrivate(entityId, pickedPoint); } void ConstraintArgsValidator::setModificator(Modificator m) { modificator = m; } bool ConstraintArgsValidator::isCurveValid(DWGConstraintUtils::CurvePtr curve, const CurveTypeList& validCurves) { if (!curve) return false; OdGe::EntityId curveType = curve->type(); if (std::find(std::begin(validCurves), std::end(validCurves), curveType) != std::end(validCurves)) return true; return false; } bool CoincidentArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (modificator == Modificator::Default) return isEntityValidForTwoPointsConstraint(entityId, pickedPoint); else if (modificator == Modificator::CoincidentObjectPoint) return isEntityValidForObjPointConstraint(entityId, pickedPoint); else return false; } bool CoincidentArgsValidator::isVerticesValidForConstraint(const OdDbObjectId& entId, const OdDbFullSubentPath& vertexSubentPath1, const OdDbFullSubentPath& vertexSubentPath2) { OdDbEntityPtr entity = entId.safeOpenObject(); if (!entity->isKindOf(OdDbPolyline::desc())) return false; if (vertexSubentPath1.subentId().type() != OdDb::kVertexSubentType || vertexSubentPath2.subentId().type() != OdDb::kVertexSubentType) return false; if(vertexSubentPath1 == vertexSubentPath2) return false; if (DWGConstraintUtils::isNeighboringVertices(vertexSubentPath1, vertexSubentPath2)) return false; return true; } bool CoincidentArgsValidator::isEntityValidForTwoPointsConstraint(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (DWGConstraintUtils::isText(entityId) || DWGConstraintUtils::isPoint(entityId)) return true; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); return isCurveValid(curve, allowedCurves); } bool CoincidentArgsValidator::isEntityValidForObjPointConstraint(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (argumentNumber == 0) { argumentNumber++; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); return isCurveValid(curve, allowedCurves); } else { // Other arguments can be any point return true; } } bool FixArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (modificator == Modificator::Default) { return true; } else { DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); return isCurveValid(curve, allowedCurves); } } bool LinesConstraintArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (DWGConstraintUtils::isText(entityId)) return true; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); return isCurveValid(curve, allowedCurves); } bool HorizontalVerticalArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (modificator == Modificator::Default) { if (DWGConstraintUtils::isText(entityId)) return true; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); return isCurveValid(curve, allowedCurves); } else if (modificator == Modificator::HorVertTwoPoins) { return true; } else { return false; } } bool SymmetricArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (argumentNumber == 0) return validateFirstArgument(entityId, pickedPoint); else if (argumentNumber == 1) return validateSecondArgument(entityId, pickedPoint); else if (argumentNumber == 2) return validateThirdArgument(entityId, pickedPoint); else return false; } bool SymmetricArgsValidator::validateFirstArgument(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { argumentNumber++; if (modificator == Modificator::SymmetricTwoPoints) return true; if (DWGConstraintUtils::isPoint(entityId)) { firstEntityIsPoint = true; return true; } DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); firstCurveType = curve->type(); return isCurveValid(curve, allowedCurves); } bool SymmetricArgsValidator::validateSecondArgument(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { argumentNumber++; if (firstEntityIsPoint && DWGConstraintUtils::isPoint(entityId)) return true; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); OdGe::EntityId curveType = curve->type(); if (modificator != Modificator::SymmetricTwoPoints) return (curveType == firstCurveType); else return true; } bool SymmetricArgsValidator::validateThirdArgument(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { argumentNumber++; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); return isCurveValid(curve, allowedSymmetryLines); } TangentArgsValidator::TangentArgsValidator() : arcFirst(true) { } bool TangentArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (argumentNumber == 0) return validateFirstArgument(entityId, pickedPoint); else if (argumentNumber == 1) return validateSecondArgument(entityId, pickedPoint); else return false; } bool TangentArgsValidator::validateFirstArgument(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { argumentNumber++; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); OdGe::EntityId curveType = curve->type(); if (curveType == OdGe::kCircArc3d || curveType == OdGe::kEllipArc3d) { arcFirst = true; return true; } else if (curveType == OdGe::kLinearEnt3d || curveType == OdGe::kLineSeg3d || curveType == OdGe::kRay3d || curveType == OdGe::kLine3d) { arcFirst = false; return true; } return false; } bool TangentArgsValidator::validateSecondArgument(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { argumentNumber++; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); OdGe::EntityId curveType = curve->type(); if (arcFirst) return isCurveValid(curve, allowedCurves); else if (curveType == OdGe::kCircArc3d || curveType == OdGe::kEllipArc3d) return true; return false; } bool EqualArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { if (argumentNumber == 0) return validateFirstArgument(entityId, pickedPoint); else if (argumentNumber == 1) return validateSecondArgument(entityId, pickedPoint); else return false; } bool EqualArgsValidator::validateFirstArgument(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { argumentNumber++; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); firstCurveType = curve->type(); return isCurveValid(curve, allowedCurves); } bool EqualArgsValidator::validateSecondArgument(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { argumentNumber++; DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); OdGe::EntityId curveType = curve->type(); return (curveType == firstCurveType); } bool ConcentricArgsValidator::isEntityValidForConstraintPrivate(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint) { DWGConstraintUtils::CurvePtr curve = DWGConstraintUtils::getCurve(entityId, pickedPoint); OdGe::EntityId curveType = curve->type(); return (curveType == OdGe::kCircArc3d || curveType == OdGe::kEllipArc3d); }