Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TObj / TObj_TReference.hxx
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
6
7 #ifndef TObj_TReference_HeaderFile
8 #define TObj_TReference_HeaderFile
9
10 #include <TObj_Common.hxx>
11 #include <TDF_Attribute.hxx>
12 #include <TDF_Label.hxx>
13
14 class Handle(TObj_TReference);
15 class Handle(TObj_Object);
16 class Standard_GUID;
17 class Handle(TDF_RelocationTable);
18
19 /**
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
26 */
27
28 class TObj_TReference : public TDF_Attribute
29 {
30  public:
31   //! Standard methods of OCAF attribute
32
33   //! Empty constructor
34   Standard_EXPORT TObj_TReference();
35
36   //! This method is used in implementation of ID()
37   static Standard_EXPORT const Standard_GUID& GetID();
38
39   //! Returns the ID of TObj_TReference attribute.
40   Standard_EXPORT const Standard_GUID& ID() const;
41
42  public:
43   //! Method for create TObj_TReference object
44
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);
51
52  public:
53   //! Methods for setting and obtaining referenced object
54
55   //! Sets the reference to the theObject
56   Standard_EXPORT void Set(const Handle(TObj_Object)& theObject,
57                            const TDF_Label&               theMasterLabel);
58
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);
63
64   //! Returns the referenced theObject
65   Standard_EXPORT Handle(TObj_Object) Get() const;
66
67   //! Returns the Label of master object.
68   Standard_EXPORT TDF_Label GetMasterLabel() const {return myMasterLabel;}
69
70   //! Returns the referred label.
71   Standard_EXPORT TDF_Label GetLabel() const {return myLabel;}
72
73  public:
74   //! Redefined OCAF abstract methods
75
76   //! Returns an new empty TObj_TReference attribute. It is used by the
77   //! copy algorithm.
78   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const;
79
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);
83
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;
88
89   //! Remove back references of it reference if it is in other document.
90   virtual Standard_EXPORT void BeforeForget();
91
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);
96
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);
101
102   //! Check if back reference exists for reference.
103   virtual Standard_EXPORT void AfterResume();
104
105   //! Called after retrieval reference from file.
106   virtual Standard_EXPORT Standard_Boolean AfterRetrieval
107                          (const Standard_Boolean forceIt = Standard_False);
108
109  private:
110   //! Fields
111   TDF_Label myLabel;          //!< Label that indicate referenced object
112   TDF_Label myMasterLabel;    //!< Label of object that have this reference.
113
114  public:
115   //! CASCADE RTTI
116   DEFINE_STANDARD_RTTI(TObj_TReference)
117 };
118
119 //! Define handle class for TObj_TReference
120 DEFINE_STANDARD_HANDLE(TObj_TReference,TDF_Attribute)
121
122 #endif
123
124 #ifdef _MSC_VER
125 #pragma once
126 #endif