b311480e |
1 | // Created on: 2004-11-23 |
2 | // Created by: Pavel TELKOV |
973c2be1 |
3 | // Copyright (c) 2004-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // The original implementation Copyright: (C) RINA S.p.A |
17 | |
18 | #include <TObj_TObject.hxx> |
19 | |
20 | #include <Standard_GUID.hxx> |
21 | #include <TDF_AttributeDelta.hxx> |
22 | #include <TDF_ChildIterator.hxx> |
23 | |
7fd59977 |
24 | |
92efcf78 |
25 | IMPLEMENT_STANDARD_RTTIEXT(TObj_TObject,TDF_Attribute) |
26 | |
7fd59977 |
27 | //======================================================================= |
28 | //function : TObj_TObject |
29 | //purpose : |
30 | //======================================================================= |
31 | |
32 | TObj_TObject::TObj_TObject() |
33 | { |
34 | } |
35 | |
36 | //======================================================================= |
37 | //function : GetID |
38 | //purpose : |
39 | //======================================================================= |
40 | |
41 | const Standard_GUID& TObj_TObject::GetID() |
42 | { |
43 | static Standard_GUID GInterfaceID ("bbdab6a7-dca9-11d4-ba37-0060b0ee18ea"); |
44 | return GInterfaceID; |
45 | } |
46 | |
47 | //======================================================================= |
48 | //function : ID |
49 | //purpose : |
50 | //======================================================================= |
51 | |
52 | const Standard_GUID& TObj_TObject::ID() const |
53 | { |
54 | return GetID(); |
55 | } |
56 | |
57 | //======================================================================= |
58 | //function : Set |
59 | //purpose : |
60 | //======================================================================= |
61 | |
62 | void TObj_TObject::Set(const Handle(TObj_Object)& theElem) |
63 | { |
64 | Backup(); |
65 | myElem = theElem; |
66 | } |
67 | |
68 | //======================================================================= |
69 | //function : Set |
70 | //purpose : |
71 | //======================================================================= |
72 | |
73 | Handle(TObj_TObject) TObj_TObject::Set(const TDF_Label& theLabel, |
74 | const Handle(TObj_Object)& theElem) |
75 | { |
76 | Handle(TObj_TObject) A; |
77 | if (!theLabel.FindAttribute(TObj_TObject::GetID(), A)) |
78 | { |
79 | A = new TObj_TObject; |
80 | theLabel.AddAttribute(A); |
81 | } |
82 | A->Set(theElem); |
83 | return A; |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : Get |
88 | //purpose : |
89 | //======================================================================= |
90 | |
91 | Handle(TObj_Object) TObj_TObject::Get() const |
92 | { |
93 | return myElem; |
94 | } |
95 | |
96 | //======================================================================= |
97 | //function : NewEmpty |
98 | //purpose : |
99 | //======================================================================= |
100 | |
101 | Handle(TDF_Attribute) TObj_TObject::NewEmpty () const |
102 | { |
103 | return new TObj_TObject(); |
104 | } |
105 | |
106 | //======================================================================= |
107 | //function : Restore |
108 | //purpose : |
109 | //======================================================================= |
110 | |
111 | void TObj_TObject::Restore(const Handle(TDF_Attribute)& theWith) |
112 | { |
113 | Handle(TObj_TObject) R = Handle(TObj_TObject)::DownCast (theWith); |
114 | myElem = R->Get(); |
115 | } |
116 | |
117 | //======================================================================= |
118 | //function : Paste |
119 | //purpose : |
120 | //======================================================================= |
121 | |
122 | void TObj_TObject::Paste (const Handle(TDF_Attribute)& theInto, |
123 | const Handle(TDF_RelocationTable)& /* RT */) const |
124 | { |
125 | Handle(TObj_TObject) R = Handle(TObj_TObject)::DownCast (theInto); |
126 | R->Set(myElem); |
127 | } |
128 | |
129 | //======================================================================= |
130 | //function : BeforeForget |
131 | //purpose : Tell TObj_Object to die, |
132 | // i.e. (myElem->IsAlive() == false) after that |
133 | //======================================================================= |
134 | |
135 | void TObj_TObject::BeforeForget() |
136 | { |
137 | if (!myElem.IsNull()) |
138 | { |
139 | // attempt to delete all data from sublabels of object to remove dependences |
140 | TDF_Label aObjLabel = myElem->myLabel; |
141 | if (!aObjLabel.IsNull()) |
142 | { |
143 | TDF_ChildIterator aLI(aObjLabel); |
144 | TDF_Label aSubLabel; |
145 | for(; aLI.More(); aLI.Next()) |
146 | { |
147 | aSubLabel = aLI.Value(); |
148 | if (!aSubLabel.IsNull()) |
149 | aSubLabel.ForgetAllAttributes(Standard_True); |
150 | } |
151 | } |
152 | // remove back references before document die |
153 | myElem->RemoveBackReferences(TObj_Forced); |
154 | TDF_Label aNullLabel; |
155 | myElem->myLabel = aNullLabel; |
156 | } |
157 | } |
158 | |
159 | //======================================================================= |
160 | //function : AfterUndo |
161 | //purpose : Tell TObj_Object to rise from the dead, |
162 | // i.e. (myElem->IsAlive() == true) after that |
163 | //======================================================================= |
164 | |
165 | Standard_Boolean TObj_TObject::AfterUndo |
166 | (const Handle(TDF_AttributeDelta)& anAttDelta, |
167 | const Standard_Boolean /*forceIt*/) |
168 | { |
169 | if (!myElem.IsNull()) |
170 | { |
171 | TDF_Label aLabel = anAttDelta->Label(); |
172 | Handle(TDF_Attribute) anAttr; |
173 | Handle(TObj_TObject) aTObject; |
174 | Handle(TDF_Attribute) me; |
175 | me = this; |
176 | if(!aLabel.IsNull() && aLabel.FindAttribute(GetID(), anAttr)) |
177 | aTObject = Handle(TObj_TObject)::DownCast(anAttr); |
178 | |
179 | if(!aTObject.IsNull() && aTObject->Get() == myElem) |
180 | myElem->myLabel = aLabel; |
181 | else |
182 | { |
183 | TDF_Label aNullLabel; |
184 | myElem->myLabel = aNullLabel; |
185 | } |
186 | } |
187 | return Standard_True; |
188 | } |