/////////////////////////////////////////////////////////////////////////////// // 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. /////////////////////////////////////////////////////////////////////////////// #ifndef DWGCommandsUtils_INCLUDED_ #define DWGCommandsUtils_INCLUDED_ #include "OdConstraintGroupNode.h" #include "OdGeomConstraint.h" #include "DbAssocGlobal.h" #include "OdConstrainedGeometry.h" #include "CsGeometry.h" #include "DWGConstraintsExport.h" #include #include #define ASSOCNETWORK_DICTIONARYKEY OD_T("ACAD_ASSOCNETWORK") class OdConstrainedPoint; namespace DWGConstraintUtils { struct AngleFixation { AngleFixation() : fixedAxisHint(0), lineToFixAngle(0), pt1(0), pt2(0) {} OdConstraintGroupNodeId fixedAxisHint; // if fixedAxisHint == 0 it is created as OX axis OdConstraintGroupNodeId lineToFixAngle; // if lineToFixAngle == 0 it is created as (pt1, pt2) OdConstraintGroupNodeId pt1; OdConstraintGroupNodeId pt2; }; struct ArcFixation // fixes radius and axis if ellipse { ArcFixation() : arc(0), center(0) {} OdConstraintGroupNodeId arc; OdConstraintGroupNodeId center; }; struct DistanceFixation { DistanceFixation() : pt1(0), pt2(0), line(0) {} OdConstraintGroupNodeId pt1; OdConstraintGroupNodeId pt2; OdConstraintGroupNodeId line; }; class DwgConstraintEvaluationCallback : public OdDbAssocEvaluationCallback { mutable OdSmartPtr _evalContext; public: OdGroupNodeIdArray _fixedGeom; OdArray _fixedRadius; OdArray _fixedAngle; OdArray _fixedDistance; bool _allowOverconstrain = true; DwgConstraintEvaluationCallback(); virtual ~DwgConstraintEvaluationCallback(); #if 0 virtual void beginActionEvaluation(OdDbAssocAction*) {} virtual void endActionEvaluation(OdDbAssocAction*) {} virtual void setActionEvaluationErrorStatus(OdDbAssocAction* pAction, OdResult errorStatus, const OdDbObjectId& objectId = OdDbObjectId::kNull, OdDbObject* pObject = NULL, void* pErrorInfo = NULL) {} virtual void getActionEvaluationErrorStatus(OdDbAssocAction* pAction, OdResult& errorStatus, OdDbObjectId& objectId, OdDbObject*& pObject, void*& pErrorInfo) {} virtual void beginActionEvaluationUsingObject(OdDbAssocAction* pAction, const OdDbObjectId& objectId, bool objectIsGoingToBeUsed, bool objectIsGoingToBeModified, OdDbObject*& pSubstituteObject) {} virtual void endActionEvaluationUsingObject(OdDbAssocAction* pAction, const OdDbObjectId& objectId, OdDbObject* pObject) {} virtual bool isDragging() { return false; } #endif virtual OdDbEvalContext* getAdditionalData() const; virtual bool cancelActionEvaluation() { return false; } }; using ImplicitPointArray = OdArray; DWGCONSTRAINTS_EXPORT OdDbObjectId currentSpaceId(const OdDbDatabase* pDb); void currentUCS(const OdDbObjectId& blockId, OdGePlane* plane = NULL, OdGeMatrix3d* matrix = NULL); DWGCONSTRAINTS_EXPORT OdDbObjectId getConstraintGroup(const OdDbObjectId& spaceId, bool createIfDoesNotExist); OdResult addConstrainedGeometry(OdDbDatabase* pDatabase, OdDbFullSubentPathArray& aPaths, OdArray& pConsGeoms); OdResult addConstrainedGeometry(OdDbDatabase* pDatabase, OdDbFullSubentPathArray& aPaths, const OdDbFullSubentPathArray& aPathsReqMIdPoint, OdArray& pConsGeoms); DWGCONSTRAINTS_EXPORT OdResult getConstrainedGeometry(OdDbDatabase* pDatabase, OdDbFullSubentPath& path, OdConstrainedGeometry*& pConsGeom); OdResult getFullSubentPaths(const OdDbEntity* pEnt, OdDb::SubentType subentType, OdDbFullSubentPathArray& aPaths); DWGCONSTRAINTS_EXPORT OdResult getClosestEdgeSubEntPath(const OdDbObjectId& entId, const OdGePoint3d& entPt, OdDbFullSubentPath& closestPath, double* pMinDist = NULL, OdGePoint3d* pClosestPt = NULL, OdDbFullSubentPath* closestEndPath = NULL, OdDbFullSubentPath* pathPtBeg = NULL, OdDbFullSubentPath* pathPtEnd = NULL, OdGePoint3d* closestEndPosition = NULL); DWGCONSTRAINTS_EXPORT OdResult getClosestEdgeSubEntPath(const OdDbObjectId& entId, const OdGePoint3d& entPt, OdDbFullSubentPath& closestPath, bool &createImplicitMidPoint, double* pMinDist = NULL, OdGePoint3d* pClosestPt = NULL, OdDbFullSubentPath* closestEndPath = NULL, OdDbFullSubentPath* pathPtBeg = NULL, OdDbFullSubentPath* pathPtEnd = NULL, OdGePoint3d* closestEndPosition = NULL); OdResult getClosestEdgeSubEntPathBref(const OdDbEntityPtr pEnt, const OdGePoint3d& entPt, OdDbFullSubentPath& closestPath, double* pMinDist = NULL); OdResult getClosestAxis(const OdDbObjectId& entId, const OdGePoint3d& entPt, OdDbFullSubentPath& axisEntPath); OdResult getCenterVertexPath(const OdDbObjectId& entId, OdDbFullSubentPath& vertEntPath); DWGCONSTRAINTS_EXPORT OdResult getClosestVertexPath(const OdDbObjectId& entId, const OdGePoint3d point, OdDbFullSubentPath& vertEntPath); OdResult getClosestVertexPath(const OdDbEntityPtr pEnt, const OdGePoint3d point, OdDbFullSubentPath& vertEntPath); /* Get path of edges, which adjoined to vertex. Polyline can has two such edges. The function used while creating coincident constr. by vertex path, so it's calls only for polylines. But function does not restrict input entity type and can accept any entity. */ OdResult getEdgeSubEntPathByVertexPath(const OdDbEntityPtr entity, const OdDbFullSubentPath& vertexPath, OdDbFullSubentPathArray& edgePaths); /* Check if two vertices belong to the same entity and located sequentially. */ bool isNeighboringVertices(const OdDbFullSubentPath& vertPath1, const OdDbFullSubentPath& vertPath2); OdResult addGeomConstraint(OdDbDatabase* pDatabase, const OdGeomConstraint::GeomConstraintType& constraintType, OdDbFullSubentPathArray& aPaths, DwgConstraintEvaluationCallback* callback); OdGeCurve3d* getCurveForEdgeSubentity(const OdDbObjectId& entId, const OdDbFullSubentPath& edgeSubent); OdGeMatrix3d getConstraintGroupCoordSysInv(OdDbAssoc2dConstraintGroup* p2dConstrGrp); OdResult getClosestConstrainedPoint(OdConstrainedGeometry*& pConsGeom, const OdGePoint3d& entPtInConstGrp, OdConstrainedPoint*& point); OdResult getLinearEdgeData(const OdDbObjectId& entId, const OdGePoint3d& entPt, OdDbFullSubentPath& edgeEntPath, OdGePoint3d& startPoint, OdGePoint3d& endPoint); bool isText(const OdDbObjectId& entId); bool isPoint(const OdDbObjectId& entId); bool isEllipse(const OdDbObjectId& entId); bool isCircle(const OdDbObjectId& entId); bool isBlockReference(const OdDbObjectId& entId); /** \details Fixates distance between two vertices. Uses to fixate segment length. * \param pDatabase - database. * \param firstVertexPath - path to begin vertex. * \param secondVertexPath - path to end vertex. * \param callback - evaluation callback to which fixation will be added. */ void addHintDistanceFixation(OdDbDatabasePtr pDatabase, OdDbFullSubentPath &firstVertexPath, OdDbFullSubentPath &seondVertexPath, DwgConstraintEvaluationCallback &callback); /** \details Fixates geometry. Uses to fixate vertex or edge position. * \param nodeId - constrained geometry which will be fixated. * \param callback - evaluation callback to which fixation will be added. */ void addHintGeometryFixation(OdConstraintGroupNodeId nodeId, DwgConstraintEvaluationCallback& callback); /** \details Fixates geometry. Uses to fixate vertex or edge position. * \param pDatabase - database. * \param subentPath - path to subentity which will be fixated. * \param callback - evaluation callback to which fixation will be added. */ void addHintGeometryFixation(OdDbDatabasePtr pDatabase, OdDbFullSubentPath& subentPath, DwgConstraintEvaluationCallback& callback); /** \details Fixates angle. Uses to fixate edge angle. * \param nodeId - constrained geometry which will be fixated. * \param callback - evaluation callback to which fixation will be added. */ void addHintAngleFixation(OdConstraintGroupNodeId nodeId, DwgConstraintEvaluationCallback& callback); /** \details Fixates an arc. * \param pDatabase - database. * \param centerPath - path to center vertex. * \param nodeId - constrained arc which will be fixated. * \param callback - evaluation callback to which fixation will be added. */ void addHintArcFixation(OdDbDatabasePtr pDatabase, OdDbFullSubentPath& centerPath, OdConstraintGroupNodeId nodeId, DwgConstraintEvaluationCallback& callback); void GetAllObjectsWithImplicitPoints(const OdArray& aCurveGeom, const OdArray& aPointGeom, OdGroupNodeIdArray& aNodeId); OdConstrainedImplicitPoint* FindImplicitPoint(int pointIndex, OdArray& apImplicitPoints); void getImplicitPoints(const OdConstrainedGeometry* constrainedGeometry, ImplicitPointArray& aPoints); OdConstrainedImplicitPoint* selectPoint(const ImplicitPointArray& implicitPointArray, OdConstrainedImplicitPoint::ImplicitPointType pointType); using CurvePtr = std::shared_ptr; CurvePtr getCurve(const OdDbObjectId& entityId, const OdGePoint3d& pickedPoint); OdGe::EntityId entityType(const OdDbObjectId& entityId, const OdGePoint3d& entityPoint); /** \details Determines which entity entId1 or entId2 closest to the point entPt. */ OdDbObjectId selectClosestEntity(const OdGePoint3d& pt, const OdDbObjectId& entId1, const OdDbObjectId& entId2); /** \details Gets the closest to point entity from OdDbBlockReference */ DWGCONSTRAINTS_EXPORT OdResult getClosestNestedEntity(const OdDbBlockReferencePtr blockReference, const OdGePoint3d& pt, OdDbEntityPtr &nestedEntity, double* pMinDist = nullptr); /** \details Calcuates distance from point to entity from OdDbBlockReference */ OdResult calculateDistanceToNestedEntity(const OdGePoint3d& pt, const OdDbEntityPtr entity, const OdGeMatrix3d &blockTransformation, double &result); DWGCONSTRAINTS_EXPORT OdResult getMidPoint(const OdDbEntityPtr entity, OdGePoint3d &midPoint); bool moduleIsLoaded(); } #endif