/////////////////////////////////////////////////////////////////////////////// // 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 _DbBlockRepresentation_h_Included_ #define _DbBlockRepresentation_h_Included_ #include "TD_PackPush.h" #include "RxObjectImpl.h" #include "DbBlockReference.h" #include "DbEvalGraph.h" #include "IntArray.h" #define STL_USING_MAP #define STL_USING_SET #include "OdaSTL.h" class OdDbBlockParameter; class OdDbDynBlockReference; class OdDbAttributeDefinition; class OdDbAttribute; class OdDbBlockRepresentationContextImpl; /** \details */ class DYNBLOCKS_EXPORT OdDbBlockRepresentationContext : public OdRxObject { OdDbBlockRepresentationContextImpl* m_pImpl; public: OdDbBlockRepresentationContext(); ~OdDbBlockRepresentationContext(); // initialize the new context void init(const OdDbDynBlockReference* ref, OdDbBlockReference* dbref, OdDbEvalGraph* gr); // initialize NDBRO graph data from the block reference extension dictionary void loadInstanceData(bool bRequireEvaluate = false); // clears NDBRO graph void compactRepresentation(); // returns the representation entites (including attributes) corresponding to the original block entity id bool originalToRepresentationEntities(OdDbObjectId id, OdDbEntityPtrArray& res) const; // extension of the previous method also handling graph nodes, assoc dependencies and assoc actions bool originalToRepresentationObjects(OdDbObjectId id, OdDbObjectPtrArray& res) const; // converts ids from the representation block to the ids in the original block (possibly many to one correspondence) bool representationPathToOriginalPath(OdDbObjectIdArray&) const; // returns all the entities in the representation block, and attributes (opened for write if the block is DBRO) void getAllEntities(OdDbEntityPtrArray&); // set RepBTag on representation block static void tagBlockRecord(OdDbBlockTableRecord* repBTR, const OdDbHandle& originalBlockHandle); // remove dynamic block related xdata && xdictionary entries static void clearRepBlock(OdDbBlockTableRecord* repRTR); // create representation block for the insert void createRepresentation(bool copied = true, bool force = false); // clear original id -> representation entities mapping (e.g. if the representation block is modified) void emptyEntityCache(); // create history record for the latest property change void addHistoryRecord(const OdString& name, const OdDbEvalVariant& value, OdDbEvalNodeId node); // returns history record chain saved as xrecord on the block reference (null if no history recorded) OdDbXrecordPtr getHistoryRecord() const; // update parameter value from the history record bool applyHistory(OdResBufPtr pRb); // saves instance data (ACAD_ENHANCEDBLOCKDATA), creating intermediate dictionaries if necessary void updateRepresentation(); // returns the anonymous block id (null if not present) OdDbObjectId getRepresentation() const; // returns original (template, master) dynamic block record id OdDbObjectId getOriginal() const; // returns the graph node with the given id (representation NDBRO node if there is an NDBRO graph) OdDbEvalExprPtr getRepresentationNode(OdDbEvalNodeId id) const; // returns the block reference this context is associated with (may be NDBRO) OdDbBlockReferencePtr getReference() const; // returns the NDBRO graph, creating one if it did not exist, never returns null OdDbEvalGraphPtr getGraph() const; // returns NDBRO representation block if it did exist, or usual representation block otherwise (may return null, if neither of them exist) OdDbBlockTableRecordPtr getBlock() const; // create the utility dictionaries and OdDbBlockRepresentationData attached to the block reference (as necessary), and caches/updates the pointers to them in the context void updateCachedData(OdDbBlockReference* ref, bool createMissingDictionaries); // saves the context data to the undo stream (usually before resetting the context) void writeUndo(OdDbEvalGraph* gr); // read the context data from the undo stream void readUndo(OdDbObjectId refId, OdDbDwgFiler* pFiler); // get the context attached to the block (does not create the context, may return null) // if "validate" is true - checks if the "AcDbBlockRepresentation" is present in the xdictionary (clears the context and returns null if not) static OdDbBlockRepresentationContext* getRepresentationContext(const OdDbBlockReference* br, bool validate = true); // returns the representation attribute corresponding to the given definition OdDbAttributePtr getAttribute(OdDbAttributeDefinition*); // returns the (block transform) * m * (inverted block transform) OdGeMatrix3d getRelativeMatrix(const OdGeMatrix3d& m) const; // returns the (block transform) * v OdGeVector3d getRelativeOffset(const OdGeVector3d& v) const; // returns the cached pointer to the dictionary where instance data is stored OdDbObjectId getBlockData() const; // returns the cached pointer to the dictionary where instance data is stored whe the block requires history OdDbObjectId getBlockHData() const; // set the RepETag indices on the original block (helper function called when creating a new dynamic block definition) static OdResult tagEntitiesInBlock(OdDbObjectId blockId); // activates a parameter or a grip point node before setting a property OdResult makeNodeActive(OdDbEvalNodeId id); // sets a parameter value or a grip position OdResult setPropertyValue(const OdString& name, const OdDbEvalVariant& value, bool useBlockTransform = true); // recalculate the block after setting a property OdResult evaluateActiveNode(); void removeRepresentationEntityFromCache(OdDbObjectId, OdDbEntity*); void addRepresentationEntityToCache(OdDbObjectId, OdDbEntity*); // enum indicating evaluation modes in the OdDbEvalContext enum class EvaluationMode { Init = 1, //< evaluation called for every node after the context is created, does nothing for most of the nodes, initializes grip points positions Eval = 2, //< regular evaluation Replay = 3 //< evaluation called when reapplying properties from history records }; void markContext(OdDbEvalContext* ctx, EvaluationMode); // calls evaluate() wuth EvaluationMode::Init for all the nodes void initializeNodes(); static bool isCreatingRepresentation(); static void setIsCreatingRepresentation(bool bIsCreatingRep); private: void updateBPT(); friend class OdDbDynBlockReference; friend class OdDbDynBlockTableRecord; protected: static bool m_bIsActiveBlockTableRecordCloner; }; void DYNBLOCKS_EXPORT oddbUpdateAttributes(OdDbBlockReference* pRef, OdDbBlockTableRecord* pBlk); #include "TD_PackPop.h" #endif // _DbBlockRepresentation_h_Included_