1 // File: TObj_TReference.hxx
2 // Created: Tue Nov 23 12:54:28 2004
3 // Author: Pavel TELKOV
4 // Copyright: Open CASCADE 2007
5 // The original implementation Copyright: (C) RINA S.p.A
7 #ifndef TObj_TReference_HeaderFile
8 #define TObj_TReference_HeaderFile
10 #include <TObj_Common.hxx>
11 #include <TDF_Attribute.hxx>
12 #include <TDF_Label.hxx>
14 class Handle(TObj_TReference);
15 class Handle(TObj_Object);
17 class Handle(TDF_RelocationTable);
20 * Attribute for storing references to the objects which implement
21 * TObj_Object interface in the OCAF tree.
22 * Its persistency mechanism provides transparent method for storing
23 * cross-model references.
24 * Each reference, when created, registers itself in the referred object,
25 * to support back references
28 class TObj_TReference : public TDF_Attribute
31 //! Standard methods of OCAF attribute
34 Standard_EXPORT TObj_TReference();
36 //! This method is used in implementation of ID()
37 static Standard_EXPORT const Standard_GUID& GetID();
39 //! Returns the ID of TObj_TReference attribute.
40 Standard_EXPORT const Standard_GUID& ID() const;
43 //! Method for create TObj_TReference object
45 //! Creates reference on TDF_Label <theLabel> to the object <theObject> and
46 //! creates backreference from the object <theObject> to <theMaster> one.
47 static Standard_EXPORT Handle(TObj_TReference) Set
48 (const TDF_Label& theLabel,
49 const Handle(TObj_Object)& theObject,
50 const Handle(TObj_Object)& theMaster);
53 //! Methods for setting and obtaining referenced object
55 //! Sets the reference to the theObject
56 Standard_EXPORT void Set(const Handle(TObj_Object)& theObject,
57 const TDF_Label& theMasterLabel);
59 //! Sets the reference to the theObject at indicated Label.
60 //! It is method for persistent only. Don`t use anywhere else.
61 Standard_EXPORT void Set(const TDF_Label& theLabel,
62 const TDF_Label& theMasterLabel);
64 //! Returns the referenced theObject
65 Standard_EXPORT Handle(TObj_Object) Get() const;
67 //! Returns the Label of master object.
68 Standard_EXPORT TDF_Label GetMasterLabel() const {return myMasterLabel;}
70 //! Returns the referred label.
71 Standard_EXPORT TDF_Label GetLabel() const {return myLabel;}
74 //! Redefined OCAF abstract methods
76 //! Returns an new empty TObj_TReference attribute. It is used by the
78 Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
80 //! Restores the backuped contents from <theWith> into this one. It is used
81 //! when aborting a transaction.
82 Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theWith);
84 //! This method is used when copying an attribute from a source structure
85 //! into a target structure.
86 Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto,
87 const Handle(TDF_RelocationTable)& theRT) const;
89 //! Remove back references of it reference if it is in other document.
90 virtual Standard_EXPORT void BeforeForget();
92 //! It is necessary for tranzaction mechanism (Undo/Redo).
93 virtual Standard_EXPORT Standard_Boolean BeforeUndo
94 (const Handle(TDF_AttributeDelta)& theDelta,
95 const Standard_Boolean isForced = Standard_False);
97 //! It is necessary for tranzaction mechanism (Undo/Redo).
98 virtual Standard_EXPORT Standard_Boolean AfterUndo
99 (const Handle(TDF_AttributeDelta)& theDelta,
100 const Standard_Boolean isForced = Standard_False);
102 //! Check if back reference exists for reference.
103 virtual Standard_EXPORT void AfterResume();
105 //! Called after retrieval reference from file.
106 virtual Standard_EXPORT Standard_Boolean AfterRetrieval
107 (const Standard_Boolean forceIt = Standard_False);
111 TDF_Label myLabel; //!< Label that indicate referenced object
112 TDF_Label myMasterLabel; //!< Label of object that have this reference.
116 DEFINE_STANDARD_RTTI(TObj_TReference)
119 //! Define handle class for TObj_TReference
120 DEFINE_STANDARD_HANDLE(TObj_TReference,TDF_Attribute)