b311480e |
1 | // Created on: 2004-11-23 |
2 | // Created by: Pavel TELKOV |
3 | // Copyright (c) 2004-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
19 | |
7fd59977 |
20 | // The original implementation Copyright: (C) RINA S.p.A |
21 | |
22 | #ifndef TObj_TReference_HeaderFile |
23 | #define TObj_TReference_HeaderFile |
24 | |
25 | #include <TObj_Common.hxx> |
26 | #include <TDF_Attribute.hxx> |
27 | #include <TDF_Label.hxx> |
28 | |
29 | class Handle(TObj_TReference); |
30 | class Handle(TObj_Object); |
31 | class Standard_GUID; |
32 | class Handle(TDF_RelocationTable); |
33 | |
34 | /** |
35 | * Attribute for storing references to the objects which implement |
36 | * TObj_Object interface in the OCAF tree. |
37 | * Its persistency mechanism provides transparent method for storing |
38 | * cross-model references. |
39 | * Each reference, when created, registers itself in the referred object, |
40 | * to support back references |
41 | */ |
42 | |
43 | class TObj_TReference : public TDF_Attribute |
44 | { |
45 | public: |
46 | //! Standard methods of OCAF attribute |
47 | |
48 | //! Empty constructor |
49 | Standard_EXPORT TObj_TReference(); |
50 | |
51 | //! This method is used in implementation of ID() |
52 | static Standard_EXPORT const Standard_GUID& GetID(); |
53 | |
54 | //! Returns the ID of TObj_TReference attribute. |
55 | Standard_EXPORT const Standard_GUID& ID() const; |
56 | |
57 | public: |
58 | //! Method for create TObj_TReference object |
59 | |
60 | //! Creates reference on TDF_Label <theLabel> to the object <theObject> and |
61 | //! creates backreference from the object <theObject> to <theMaster> one. |
62 | static Standard_EXPORT Handle(TObj_TReference) Set |
63 | (const TDF_Label& theLabel, |
64 | const Handle(TObj_Object)& theObject, |
65 | const Handle(TObj_Object)& theMaster); |
66 | |
67 | public: |
68 | //! Methods for setting and obtaining referenced object |
69 | |
70 | //! Sets the reference to the theObject |
71 | Standard_EXPORT void Set(const Handle(TObj_Object)& theObject, |
72 | const TDF_Label& theMasterLabel); |
73 | |
74 | //! Sets the reference to the theObject at indicated Label. |
75 | //! It is method for persistent only. Don`t use anywhere else. |
76 | Standard_EXPORT void Set(const TDF_Label& theLabel, |
77 | const TDF_Label& theMasterLabel); |
78 | |
79 | //! Returns the referenced theObject |
80 | Standard_EXPORT Handle(TObj_Object) Get() const; |
81 | |
82 | //! Returns the Label of master object. |
83 | Standard_EXPORT TDF_Label GetMasterLabel() const {return myMasterLabel;} |
84 | |
85 | //! Returns the referred label. |
86 | Standard_EXPORT TDF_Label GetLabel() const {return myLabel;} |
87 | |
88 | public: |
89 | //! Redefined OCAF abstract methods |
90 | |
91 | //! Returns an new empty TObj_TReference attribute. It is used by the |
92 | //! copy algorithm. |
93 | Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const; |
94 | |
95 | //! Restores the backuped contents from <theWith> into this one. It is used |
96 | //! when aborting a transaction. |
97 | Standard_EXPORT void Restore(const Handle(TDF_Attribute)& theWith); |
98 | |
99 | //! This method is used when copying an attribute from a source structure |
100 | //! into a target structure. |
101 | Standard_EXPORT void Paste(const Handle(TDF_Attribute)& theInto, |
102 | const Handle(TDF_RelocationTable)& theRT) const; |
103 | |
104 | //! Remove back references of it reference if it is in other document. |
105 | virtual Standard_EXPORT void BeforeForget(); |
106 | |
107 | //! It is necessary for tranzaction mechanism (Undo/Redo). |
108 | virtual Standard_EXPORT Standard_Boolean BeforeUndo |
109 | (const Handle(TDF_AttributeDelta)& theDelta, |
110 | const Standard_Boolean isForced = Standard_False); |
111 | |
112 | //! It is necessary for tranzaction mechanism (Undo/Redo). |
113 | virtual Standard_EXPORT Standard_Boolean AfterUndo |
114 | (const Handle(TDF_AttributeDelta)& theDelta, |
115 | const Standard_Boolean isForced = Standard_False); |
116 | |
117 | //! Check if back reference exists for reference. |
118 | virtual Standard_EXPORT void AfterResume(); |
119 | |
120 | //! Called after retrieval reference from file. |
121 | virtual Standard_EXPORT Standard_Boolean AfterRetrieval |
122 | (const Standard_Boolean forceIt = Standard_False); |
123 | |
124 | private: |
125 | //! Fields |
126 | TDF_Label myLabel; //!< Label that indicate referenced object |
127 | TDF_Label myMasterLabel; //!< Label of object that have this reference. |
128 | |
129 | public: |
130 | //! CASCADE RTTI |
131 | DEFINE_STANDARD_RTTI(TObj_TReference) |
132 | }; |
133 | |
134 | //! Define handle class for TObj_TReference |
135 | DEFINE_STANDARD_HANDLE(TObj_TReference,TDF_Attribute) |
136 | |
137 | #endif |
138 | |
139 | #ifdef _MSC_VER |
140 | #pragma once |
141 | #endif |