/////////////////////////////////////////////////////////////////////////////// // 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 "DWGConstraintCreation.h" #include "DWGCommandsUtils.h" #include "DbAssoc2dConstraintGroup.h" OdResult DwgConstraintCreation::listConstraints(OdDbDatabase* pDatabase, const OdDbObjectId& entId, const OdGePoint3d& /*entPt*/, OdGeomConstraintPtrList& constraintList) ODRX_NOEXCEPT { try { if (!DWGConstraintUtils::moduleIsLoaded()) return eNotApplicable; OdDbObjectId consGrpId = DWGConstraintUtils::getConstraintGroup(DWGConstraintUtils::currentSpaceId(pDatabase), false); if (consGrpId.isNull()) // There are no constraints in db return eOk; OdResult es = eOk; OdDbFullSubentPath subentPath; OdDbAssoc2dConstraintGroupPtr p2dConstrGrp = consGrpId.openObject(); OdArray aConstGeom; if ((es = p2dConstrGrp->getConstrainedGeometries(aConstGeom)) != eOk) return es; OdArray allConstraints; if ((es = p2dConstrGrp->getConstraints(allConstraints)) != eOk) return es; for (OdGeomConstraint* constraint : allConstraints) { OdArray connectedGeometries; constraint->getConnectedGeometries(connectedGeometries); for (OdConstrainedGeometry* connectedGeometry : connectedGeometries) { OdDbFullSubentPathArray subentPaths; es = connectedGeometry->getFullSubentPaths(subentPaths); if (es != eOk) throw OdError(es); OdDbObjectIdArray objIds = subentPaths[0].objectIds(); ODA_ASSERT_ONCE(objIds.logicalLength() > 0); if (objIds.logicalLength() == 0) break; if (objIds[0] == entId && !constraint->isInternal()) constraintList.push_back(constraint); } } constraintList.unique(); return es; } catch (const OdError& e) { return e.code(); } catch (...) { return eNotApplicable; } } OdResult DwgConstraintCreation::deleteConstraint(OdDbDatabase* pDatabase, OdGeomConstraintPtr constraint) ODRX_NOEXCEPT { try { if (!DWGConstraintUtils::moduleIsLoaded()) return eNotApplicable; OdDbObjectId consGrpId = DWGConstraintUtils::getConstraintGroup(DWGConstraintUtils::currentSpaceId(pDatabase), false); if (consGrpId.isNull()) return eInvalidInput; OdDbAssoc2dConstraintGroupPtr p2dConstrGrp = consGrpId.openObject(OdDb::kForWrite); return p2dConstrGrp->deleteConstraint(constraint.get()); } catch (const OdError& e) { return e.code(); } catch (...) { return eNotApplicable; } } OdResult DwgConstraintCreation::deleteAllConstraints(OdDbDatabase* pDatabase, const OdDbObjectId& entId, const OdGePoint3d& entPt) ODRX_NOEXCEPT { try { if (!DWGConstraintUtils::moduleIsLoaded()) return eNotApplicable; OdGeomConstraintPtrList constraintList; OdResult es = eOk; if ((es = listConstraints(pDatabase, entId, entPt, constraintList)) != eOk) return es; for (OdGeomConstraintPtrList::value_type constraint : constraintList) { es = deleteConstraint(pDatabase, constraint); if (es != eOk) break; } return es; } catch (const OdError& e) { return e.code(); } catch (...) { return eNotApplicable; } }