1 // Created on: 2008-06-21
2 // Created by: Vladislav ROMASHKO
3 // Copyright (c) 2008-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
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>
26 IMPLEMENT_STANDARD_RTTIEXT(TFunction_GraphNode,TDF_Attribute)
28 //=======================================================================
30 //purpose : Static method to get an ID
31 //=======================================================================
32 const Standard_GUID& TFunction_GraphNode::GetID()
34 static Standard_GUID TFunction_GraphNodeID("DD51FA86-E171-41a4-A2C1-3A0FBF286798");
35 return TFunction_GraphNodeID;
38 //=======================================================================
40 //purpose : Finds or creates a graph node attribute
41 //=======================================================================
43 Handle(TFunction_GraphNode) TFunction_GraphNode::Set(const TDF_Label& L)
45 Handle(TFunction_GraphNode) G;
46 if (!L.FindAttribute(TFunction_GraphNode::GetID(), G))
48 G = new TFunction_GraphNode();
54 //=======================================================================
56 //purpose : Returns GUID of the function
57 //=======================================================================
59 const Standard_GUID& TFunction_GraphNode::ID() const
64 //=======================================================================
65 //function : TFunction_GraphNode
66 //purpose : Constructor
67 //=======================================================================
69 TFunction_GraphNode::TFunction_GraphNode():myStatus(TFunction_ES_WrongDefinition)
74 //=======================================================================
75 //function : AddPrevious
76 //purpose : Adds a function to the previous functions of this function.
77 //=======================================================================
79 Standard_Boolean TFunction_GraphNode::AddPrevious(const Standard_Integer funcID)
81 if (myPrevious.Contains(funcID))
82 return Standard_False;
86 return myPrevious.Add(funcID);
89 //=======================================================================
90 //function : AddPrevious
91 //purpose : Adds a function to the previous functions of this function.
92 //=======================================================================
94 Standard_Boolean TFunction_GraphNode::AddPrevious(const TDF_Label& func)
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);
103 //=======================================================================
104 //function : RemovePrevious
105 //purpose : Removes a function to the previous functions of this function.
106 //=======================================================================
108 Standard_Boolean TFunction_GraphNode::RemovePrevious(const Standard_Integer funcID)
110 if (!myPrevious.Contains(funcID))
111 return Standard_False;
115 return myPrevious.Remove(funcID);
118 //=======================================================================
119 //function : RemovePrevious
120 //purpose : Removes a function to the previous functions of this function.
121 //=======================================================================
123 Standard_Boolean TFunction_GraphNode::RemovePrevious(const TDF_Label& func)
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);
132 //=======================================================================
133 //function : GetPrevious
134 //purpose : Returns a map of previous functions.
135 //=======================================================================
137 const TColStd_MapOfInteger& TFunction_GraphNode::GetPrevious() const
142 //=======================================================================
143 //function : RemoveAllPrevious
144 //purpose : Clear the map of previous functions.
145 //=======================================================================
147 void TFunction_GraphNode::RemoveAllPrevious()
149 if (myPrevious.IsEmpty())
157 //=======================================================================
159 //purpose : Adds a function to the next functions of this function.
160 //=======================================================================
162 Standard_Boolean TFunction_GraphNode::AddNext(const Standard_Integer funcID)
164 if (myNext.Contains(funcID))
165 return Standard_False;
169 return myNext.Add(funcID);
172 //=======================================================================
174 //purpose : Adds a function to the next functions of this function.
175 //=======================================================================
177 Standard_Boolean TFunction_GraphNode::AddNext(const TDF_Label& func)
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);
186 //=======================================================================
187 //function : RemoveNext
188 //purpose : Removes a function to the next functions of this function.
189 //=======================================================================
191 Standard_Boolean TFunction_GraphNode::RemoveNext(const Standard_Integer funcID)
193 if (!myNext.Contains(funcID))
194 return Standard_False;
198 return myNext.Remove(funcID);
201 //=======================================================================
202 //function : RemoveNext
203 //purpose : Remove a function to the next functions of this function.
204 //=======================================================================
206 Standard_Boolean TFunction_GraphNode::RemoveNext(const TDF_Label& func)
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);
215 //=======================================================================
217 //purpose : Returns a map of next functions.
218 //=======================================================================
220 const TColStd_MapOfInteger& TFunction_GraphNode::GetNext() const
225 //=======================================================================
226 //function : RemoveAllNext
227 //purpose : Clear the map of next functions.
228 //=======================================================================
230 void TFunction_GraphNode::RemoveAllNext()
232 if (myNext.IsEmpty())
240 //=======================================================================
241 //function : GetStatus
242 //purpose : Returns the execution status of the function.
243 //=======================================================================
245 TFunction_ExecutionStatus TFunction_GraphNode::GetStatus() const
250 //=======================================================================
251 //function : SetStatus
252 //purpose : Defines an execution status for a function.
253 //=======================================================================
255 void TFunction_GraphNode::SetStatus(const TFunction_ExecutionStatus status)
257 if (myStatus == status)
265 //=======================================================================
268 //=======================================================================
270 void TFunction_GraphNode::Restore(const Handle(TDF_Attribute)& other)
272 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(other);
275 myPrevious = G->myPrevious;
281 myStatus = G->myStatus;
284 //=======================================================================
286 //purpose : Method for Copy mechanism
287 //=======================================================================
289 void TFunction_GraphNode::Paste(const Handle(TDF_Attribute)& into,
290 const Handle(TDF_RelocationTable)& /*RT*/) const
292 Handle(TFunction_GraphNode) G = Handle(TFunction_GraphNode)::DownCast(into);
295 G->myPrevious = myPrevious;
301 G->myStatus = myStatus;
304 //=======================================================================
305 //function : NewEmpty
306 //purpose : Returns new empty graph node attribute
307 //=======================================================================
309 Handle(TDF_Attribute) TFunction_GraphNode::NewEmpty() const
311 return new TFunction_GraphNode();
314 //=======================================================================
315 //function : References
316 //purpose : Collects the references
317 //=======================================================================
319 void TFunction_GraphNode::References(const Handle(TDF_DataSet)& /*aDataSet*/) const
324 //=======================================================================
326 //purpose : Dump of the graph node
327 //=======================================================================
329 Standard_OStream& TFunction_GraphNode::Dump (Standard_OStream& anOS) const
331 TDF_Attribute::Dump(anOS);