OCC22322 Improvement of Extrema performance
[occt.git] / src / TFunction / TFunction_GraphNode.cxx
1 // File:        TFunction_GraphNode.cxx
2 // Created:     Mon Jun 21 14:35:37 2008
3 // Author:      Vladislav ROMASHKO
4 //              <vladislav.romashko@opencascade.com>
5
6
7 #include <TFunction_GraphNode.ixx>
8 #include <TFunction_Scope.hxx>
9
10 //=======================================================================
11 //function : GetID
12 //purpose  : Static method to get an ID
13 //=======================================================================
14
15 const Standard_GUID&  TFunction_GraphNode::GetID() 
16 {  
17   static Standard_GUID TFunction_GraphNodeID("DD51FA86-E171-41a4-A2C1-3A0FBF286798");
18   return TFunction_GraphNodeID; 
19 }
20
21 //=======================================================================
22 //function : Set
23 //purpose  : Finds or creates a graph node attribute
24 //=======================================================================
25
26 Handle(TFunction_GraphNode) TFunction_GraphNode::Set(const TDF_Label& L)
27 {
28   Handle(TFunction_GraphNode) G;
29   if (!L.FindAttribute(TFunction_GraphNode::GetID(), G)) 
30   {
31     G = new TFunction_GraphNode();
32     L.AddAttribute(G);
33   }
34   return G;
35 }
36
37 //=======================================================================
38 //function : ID
39 //purpose  : Returns GUID of the function
40 //=======================================================================
41
42 const Standard_GUID& TFunction_GraphNode::ID() const
43
44   return GetID(); 
45 }
46
47 //=======================================================================
48 //function : TFunction_GraphNode
49 //purpose  : Constructor
50 //=======================================================================
51
52 TFunction_GraphNode::TFunction_GraphNode():myStatus(TFunction_ES_WrongDefinition)
53 {
54
55 }
56
57 //=======================================================================
58 //function : AddPrevious
59 //purpose  : Adds a function to the previous functions of this function.
60 //=======================================================================
61
62 Standard_Boolean TFunction_GraphNode::AddPrevious(const Standard_Integer funcID)
63 {
64   if (myPrevious.Contains(funcID))
65     return Standard_False;
66
67   Backup();
68
69   return myPrevious.Add(funcID);
70 }
71
72 //=======================================================================
73 //function : AddPrevious
74 //purpose  : Adds a function to the previous functions of this function.
75 //=======================================================================
76
77 Standard_Boolean TFunction_GraphNode::AddPrevious(const TDF_Label& func)
78 {
79   Handle(TFunction_Scope) scope = TFunction_Scope::Set(func);
80   if (!scope->GetFunctions().IsBound2(func))
81     return Standard_False;
82   Standard_Integer funcID = scope->GetFunctions().Find2(func);
83   return AddPrevious(funcID);
84 }
85
86 //=======================================================================
87 //function : RemovePrevious
88 //purpose  : Removes a function to the previous functions of this function.
89 //=======================================================================
90
91 Standard_Boolean TFunction_GraphNode::RemovePrevious(const Standard_Integer funcID)
92 {
93   if (!myPrevious.Contains(funcID))
94     return Standard_False;
95
96   Backup();
97
98   return myPrevious.Remove(funcID);
99 }
100
101 //=======================================================================
102 //function : RemovePrevious
103 //purpose  : Removes a function to the previous functions of this function.
104 //=======================================================================
105
106 Standard_Boolean TFunction_GraphNode::RemovePrevious(const TDF_Label& func)
107 {
108   Handle(TFunction_Scope) scope = TFunction_Scope::Set(func);
109   if (!scope->GetFunctions().IsBound2(func))
110     return Standard_False;
111   Standard_Integer funcID = scope->GetFunctions().Find2(func);
112   return RemovePrevious(funcID);
113 }
114
115 //=======================================================================
116 //function : GetPrevious
117 //purpose  : Returns a map of previous functions.
118 //=======================================================================
119
120 const TColStd_MapOfInteger& TFunction_GraphNode::GetPrevious() const
121 {
122   return myPrevious;
123 }
124
125 //=======================================================================
126 //function : RemoveAllPrevious
127 //purpose  : Clear the map of previous functions.
128 //=======================================================================
129
130 void TFunction_GraphNode::RemoveAllPrevious()
131 {
132   if (myPrevious.IsEmpty())
133     return;
134
135   Backup();
136
137   myPrevious.Clear();
138 }
139
140 //=======================================================================
141 //function : AddNext
142 //purpose  : Adds a function to the next functions of this function.
143 //=======================================================================
144
145 Standard_Boolean TFunction_GraphNode::AddNext(const Standard_Integer funcID)
146 {
147   if (myNext.Contains(funcID))
148     return Standard_False;
149
150   Backup();
151
152   return myNext.Add(funcID);
153 }
154
155 //=======================================================================
156 //function : AddNext
157 //purpose  : Adds a function to the next functions of this function.
158 //=======================================================================
159
160 Standard_Boolean TFunction_GraphNode::AddNext(const TDF_Label& func)
161 {
162   Handle(TFunction_Scope) scope = TFunction_Scope::Set(func);
163   if (!scope->GetFunctions().IsBound2(func))
164     return Standard_False;
165   Standard_Integer funcID = scope->GetFunctions().Find2(func);
166   return AddNext(funcID);
167 }
168
169 //=======================================================================
170 //function : RemoveNext
171 //purpose  : Removes a function to the next functions of this function.
172 //=======================================================================
173
174 Standard_Boolean TFunction_GraphNode::RemoveNext(const Standard_Integer funcID)
175 {
176   if (!myNext.Contains(funcID))
177     return Standard_False;
178
179   Backup();
180
181   return myNext.Remove(funcID);
182 }
183
184 //=======================================================================
185 //function : RemoveNext
186 //purpose  : Remove a function to the next functions of this function.
187 //=======================================================================
188
189 Standard_Boolean TFunction_GraphNode::RemoveNext(const TDF_Label& func)
190 {
191   Handle(TFunction_Scope) scope = TFunction_Scope::Set(func);
192   if (!scope->GetFunctions().IsBound2(func))
193     return Standard_False;
194   Standard_Integer funcID = scope->GetFunctions().Find2(func);
195   return RemoveNext(funcID);
196 }
197
198 //=======================================================================
199 //function : GetNext
200 //purpose  : Returns a map of next functions.
201 //=======================================================================
202
203 const TColStd_MapOfInteger& TFunction_GraphNode::GetNext() const
204 {
205   return myNext;
206 }
207
208 //=======================================================================
209 //function : RemoveAllNext
210 //purpose  : Clear the map of next functions.
211 //=======================================================================
212
213 void TFunction_GraphNode::RemoveAllNext()
214 {
215   if (myNext.IsEmpty())
216     return;
217
218   Backup();
219
220   myNext.Clear();
221 }
222
223 //=======================================================================
224 //function : GetStatus
225 //purpose  : Returns the execution status of the function.
226 //=======================================================================
227
228 TFunction_ExecutionStatus TFunction_GraphNode::GetStatus() const
229 {
230   return myStatus;
231 }
232
233 //=======================================================================
234 //function : SetStatus
235 //purpose  : Defines an execution status for a function.
236 //=======================================================================
237
238 void TFunction_GraphNode::SetStatus(const TFunction_ExecutionStatus status)
239 {
240   if (myStatus == status)
241     return;
242
243   Backup();
244
245   myStatus = status;
246 }
247
248 //=======================================================================
249 //function : Restore
250 //purpose  : 
251 //=======================================================================
252
253 void TFunction_GraphNode::Restore(const Handle(TDF_Attribute)& other) 
254 {
255   Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(other);
256
257   // Previous
258   myPrevious = G->myPrevious;
259
260   // Next
261   myNext = G->myNext;
262   
263   // Status
264   myStatus = G->myStatus;
265 }
266
267 //=======================================================================
268 //function : Paste
269 //purpose  : Method for Copy mechanism
270 //=======================================================================
271
272 void TFunction_GraphNode::Paste(const Handle(TDF_Attribute)& into,
273                                 const Handle(TDF_RelocationTable)& /*RT*/) const
274 {
275   Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(into);
276
277   // Previous
278   G->myPrevious = myPrevious;
279
280   // Next
281   G->myNext = myNext;
282
283   // Status
284   G->myStatus = myStatus;
285 }
286
287 //=======================================================================
288 //function : NewEmpty
289 //purpose  : Returns new empty graph node attribute
290 //=======================================================================
291
292 Handle(TDF_Attribute) TFunction_GraphNode::NewEmpty() const
293 {
294   return new TFunction_GraphNode();
295 }
296
297 //=======================================================================
298 //function : References
299 //purpose  : Collects the references
300 //=======================================================================
301
302 void TFunction_GraphNode::References(const Handle(TDF_DataSet)& /*aDataSet*/) const
303 {
304
305 }
306
307 //=======================================================================
308 //function : Dump
309 //purpose  : Dump of the graph node
310 //=======================================================================
311
312 Standard_OStream& TFunction_GraphNode::Dump (Standard_OStream& anOS) const
313 {
314   TDF_Attribute::Dump(anOS);
315   return anOS;
316 }