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