0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / TFunction / TFunction_IFunction.cxx
CommitLineData
b311480e 1// Created on: 2008-06-21
2// Created by: Vladislav ROMASHKO
973c2be1 3// Copyright (c) 2008-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.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <TFunction_DataMapOfLabelListOfLabel.hxx>
42cf5bc1 18#include <TFunction_DriverTable.hxx>
19#include <TFunction_Function.hxx>
20#include <TFunction_GraphNode.hxx>
21#include <TFunction_IFunction.hxx>
42cf5bc1 22#include <TFunction_Scope.hxx>
7fd59977 23
7fd59977 24//=======================================================================
25//function : NewFunction
26//purpose : Static method to create a new function.
27//=======================================================================
7fd59977 28Standard_Boolean TFunction_IFunction::NewFunction(const TDF_Label& L, const Standard_GUID& ID)
29{
30 // Set Function (ID, code of failure)
31 TFunction_Function::Set(L, ID)->SetFailure(0);
32
33 // Set graph node (dependencies, status)
34 Handle(TFunction_GraphNode) graphNode = TFunction_GraphNode::Set(L);
35 graphNode->RemoveAllPrevious();
36 graphNode->RemoveAllNext();
37 graphNode->SetStatus(TFunction_ES_WrongDefinition);
38
39 // Check presence of the function in the current scope
40 TFunction_Scope::Set(L)->AddFunction(L);
41
42 return TFunction_DriverTable::Get()->HasDriver(ID);
43}
44
45//=======================================================================
46//function : DeleteFunction
47//purpose : Static method to delete a function.
48//=======================================================================
49
50Standard_Boolean TFunction_IFunction::DeleteFunction(const TDF_Label& L)
51{
52 // Delete Function
53 Handle(TFunction_Function) func;
54 if (L.FindAttribute(TFunction_Function::GetID(), func))
55 L.ForgetAttribute(func);
56
57 // Take the scope of functions
58 Handle(TFunction_Scope) scope = TFunction_Scope::Set(L);
59 const Standard_Integer funcID = scope->GetFunctions().Find2(L);
60
61 // Delete graph node
62 Handle(TFunction_GraphNode) graphNode;
63 if (L.FindAttribute(TFunction_GraphNode::GetID(), graphNode))
64 {
65 const TColStd_MapOfInteger& prev = graphNode->GetPrevious();
66 const TColStd_MapOfInteger& next = graphNode->GetNext();
67 // Disconnect previous functions
68 TColStd_MapIteratorOfMapOfInteger itrm(prev);
69 for (; itrm.More(); itrm.Next())
70 {
71 const Standard_Integer ID = itrm.Key();
72 const TDF_Label& La = scope->GetFunctions().Find1(ID);
73 Handle(TFunction_GraphNode) G;
74 if (La.FindAttribute(TFunction_GraphNode::GetID(), G))
75 {
76 G->RemoveNext(funcID);
77 }
78 }
79 // Disconnect next functions
80 for (itrm.Initialize(next); itrm.More(); itrm.Next())
81 {
82 const Standard_Integer ID = itrm.Key();
83 const TDF_Label& La = scope->GetFunctions().Find1(ID);
84 Handle(TFunction_GraphNode) G;
85 if (La.FindAttribute(TFunction_GraphNode::GetID(), G))
86 {
87 G->RemovePrevious(funcID);
88 }
89 }
90
91 L.ForgetAttribute(graphNode);
92 }
93
94 // Delete the function from the current scope of functions.
95 scope->RemoveFunction(L);
96
97 return Standard_True;
98}
99
100//=======================================================================
101//function : UpdateDependencies
102//purpose : Updates the dependencies of all functions.
103//=======================================================================
104
105Standard_Boolean TFunction_IFunction::UpdateDependencies(const TDF_Label& Access)
106{
107 // Take the scope of functions.
108 Handle(TFunction_Scope) scope = TFunction_Scope::Set(Access);
109
110 // Make a data map of function - results.
111 TFunction_DataMapOfLabelListOfLabel table;
112 TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itrm(scope->GetFunctions());
113 for (; itrm.More(); itrm.Next())
114 {
115 // Label of the function
116 const TDF_Label& L = itrm.Key2();
117 TFunction_IFunction iFunction(L);
118
7fd59977 119 // Take the driver.
120 Handle(TFunction_Driver) driver = iFunction.GetDriver();
121
122 // Take the results.
123 TDF_LabelList res;
124 driver->Results(res);
125
126 // Fill-in the table
127 table.Bind(L, res);
128
129 // Clean the graph node
130 Handle(TFunction_GraphNode) graphNode = iFunction.GetGraphNode();
131 graphNode->RemoveAllPrevious();
132 graphNode->RemoveAllNext();
133 }
134
135 // Update previous and next functions for each function of the scope
136 TFunction_DataMapIteratorOfDataMapOfLabelListOfLabel itrd;
137 for (itrm.Initialize(scope->GetFunctions()); itrm.More(); itrm.Next())
138 {
139 // Label of the functions
140 const TDF_Label& L = itrm.Key2();
141 TFunction_IFunction iFunction(L);
142
7fd59977 143 // Take the driver.
144 Handle(TFunction_Driver) driver = iFunction.GetDriver();
145
146 // Take the arguments.
147 TDF_LabelList args;
148 driver->Arguments(args);
149
150 // Make a map of arguments
151 TDF_LabelMap argsMap;
152 TDF_ListIteratorOfLabelList itrl(args);
153 for (; itrl.More(); itrl.Next())
154 argsMap.Add(itrl.Value());
155
156 // ID of the function
157 const Standard_Integer funcID = itrm.Key1();
158
159 // Find the functions, which produce the arguments of this function.
160 for (itrd.Initialize(table); itrd.More(); itrd.Next())
161 {
162 const TDF_Label& anotherL = itrd.Key();
163 if (L == anotherL)
164 continue;
165 const TDF_LabelList& anotherRes = itrd.Value();
166
7fd59977 167 for (itrl.Initialize(anotherRes); itrl.More(); itrl.Next())
168 {
169 if (argsMap.Contains(itrl.Value()))
170 {
171 iFunction.GetGraphNode()->AddPrevious(anotherL);
172
173 TFunction_IFunction iAnotherFunction(anotherL);
174 iAnotherFunction.GetGraphNode()->AddNext(funcID);
175 }
176 }
177 }
178 }
179
180 return Standard_True;
181}
182
183//=======================================================================
184//function : Create
185//purpose : Constructor
186//=======================================================================
187
188TFunction_IFunction::TFunction_IFunction()
189{
190
191}
192
193//=======================================================================
194//function : Create
195//purpose : Constructor
196//=======================================================================
197
198TFunction_IFunction::TFunction_IFunction(const TDF_Label& L)
199{
200 Init(L);
201}
202
203//=======================================================================
204//function : Init
205//purpose : Initializes the interface.
206//=======================================================================
207
208void TFunction_IFunction::Init(const TDF_Label& L)
209{
210 myLabel = L;
211}
212
213//=======================================================================
214//function : Label
215//purpose : Returns the label of the interface.
216//=======================================================================
217
218const TDF_Label& TFunction_IFunction::Label() const
219{
220 return myLabel;
221}
222
223//=======================================================================
224//function : UpdateDependencies
225//purpose : Updates the dependencies of this function only.
226//=======================================================================
227
228Standard_Boolean TFunction_IFunction::UpdateDependencies() const
229{
230 // Take the arguments & results of the functions
231 TDF_LabelList args, res;
232 Handle(TFunction_Driver) D = GetDriver();
233 D->Arguments(args);
234 D->Results(res);
235
236 // Insert the arguments and results into maps for fast searching.
237 TDF_LabelMap argsMap, resMap;
238 TDF_ListIteratorOfLabelList itrl(args);
239 for (; itrl.More(); itrl.Next())
240 {
241 argsMap.Add(itrl.Value());
242 }
243 for (itrl.Initialize(res); itrl.More(); itrl.Next())
244 {
245 resMap.Add(itrl.Value());
246 }
247
248 // Consider all other functions checking their attitude to this function.
249 Handle(TFunction_Scope) scope = TFunction_Scope::Set(myLabel);
250 TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itrm(scope->GetFunctions());
251 for (; itrm.More(); itrm.Next())
252 {
253 const TDF_Label& L = itrm.Key2();
254 if (L == myLabel)
255 continue;
256 TFunction_IFunction iFunc(L);
257 D = iFunc.GetDriver();
258
259 // Arguments of another function
260 args.Clear();
261 D->Arguments(args);
262
263 // Check presence of the arguments in results of our function
264 for (itrl.Initialize(args); itrl.More(); itrl.Next())
265 {
266 if (resMap.Contains(itrl.Value()))
267 {
268 // Our function is a previous one for this function.
269 GetGraphNode()->AddNext(scope->GetFunctions().Find2(L));
270 iFunc.GetGraphNode()->AddPrevious(scope->GetFunctions().Find2(myLabel));
271 }
272 }
273
274 // Results of another function
275 res.Clear();
276 D->Results(res);
277
278 // Check presence of the results in arguments of our function
279 for (itrl.Initialize(res); itrl.More(); itrl.Next())
280 {
281 if (argsMap.Contains(itrl.Value()))
282 {
283 // Our function is a next one for this function.
284 GetGraphNode()->AddPrevious(scope->GetFunctions().Find2(L));
285 iFunc.GetGraphNode()->AddNext(scope->GetFunctions().Find2(myLabel));
286 }
287 }
288 }
289
290 return Standard_True;
291}
292
293//=======================================================================
294//function : Arguments
295//purpose : The method fills-in the list by labels,
296// where the arguments of the function are located.
297//=======================================================================
298
299void TFunction_IFunction::Arguments(TDF_LabelList& args) const
300{
301 Handle(TFunction_Driver) driver = GetDriver();
302 driver->Arguments(args);
303}
304
305//=======================================================================
306//function : Results
307//purpose : The method fills-in the list by labels,
308// where the results of the function are located.
309//=======================================================================
310
311void TFunction_IFunction::Results(TDF_LabelList& res) const
312{
313 Handle(TFunction_Driver) driver = GetDriver();
314 driver->Results(res);
315}
316
317//=======================================================================
318//function : GetPrevious
319//purpose : Returns a list of previous functions.
320//=======================================================================
321
322void TFunction_IFunction::GetPrevious(TDF_LabelList& prev) const
323{
324 Handle(TFunction_GraphNode) graph = GetGraphNode();
325 const TColStd_MapOfInteger& map = graph->GetPrevious();
326 Handle(TFunction_Scope) scope = TFunction_Scope::Set(myLabel);
327
328 TColStd_MapIteratorOfMapOfInteger itrm(map);
329 for (; itrm.More(); itrm.Next())
330 {
331 const Standard_Integer funcID = itrm.Key();
332 if (scope->GetFunctions().IsBound1(funcID))
333 {
334 prev.Append(scope->GetFunctions().Find1(funcID));
335 }
336 }
337}
338
339//=======================================================================
340//function : GetNext
341//purpose : Returns a list of next functions.
342//=======================================================================
343
344void TFunction_IFunction::GetNext(TDF_LabelList& next) const
345{
346 Handle(TFunction_GraphNode) graph = GetGraphNode();
347 const TColStd_MapOfInteger& map = graph->GetNext();
348 Handle(TFunction_Scope) scope = TFunction_Scope::Set(myLabel);
349
350 TColStd_MapIteratorOfMapOfInteger itrm(map);
351 for (; itrm.More(); itrm.Next())
352 {
353 const Standard_Integer funcID = itrm.Key();
354 if (scope->GetFunctions().IsBound1(funcID))
355 {
356 next.Append(scope->GetFunctions().Find1(funcID));
357 }
358 }
359}
360
361//=======================================================================
362//function : GetStatus
363//purpose : Returns the execution status of the function.
364//=======================================================================
365
366TFunction_ExecutionStatus TFunction_IFunction::GetStatus() const
367{
368 Handle(TFunction_GraphNode) graph = GetGraphNode();
369 return graph->GetStatus();
370}
371
372//=======================================================================
373//function : SetStatus
374//purpose : Defines an execution status for a function.
375//=======================================================================
376
377void TFunction_IFunction::SetStatus(const TFunction_ExecutionStatus status) const
378{
379 Handle(TFunction_GraphNode) graph = GetGraphNode();
380 graph->SetStatus(status);
381}
382
383//=======================================================================
384//function : GetFunctions
385//purpose : Returns the scope of functions.
386//=======================================================================
387
388const TFunction_DoubleMapOfIntegerLabel& TFunction_IFunction::GetAllFunctions() const
389{
390 return TFunction_Scope::Set(myLabel)->GetFunctions();
391}
392
393//=======================================================================
394//function : GetLogbook
395//purpose : Returns the Logbook.
396//=======================================================================
397
f486f64d 398Handle(TFunction_Logbook) TFunction_IFunction::GetLogbook() const
7fd59977 399{
400 return TFunction_Scope::Set(myLabel)->GetLogbook();
401}
402
403//=======================================================================
404//function : GetDriver
405//purpose : Returns the function driver.
406//=======================================================================
407
408Handle(TFunction_Driver) TFunction_IFunction::GetDriver(const Standard_Integer thread) const
409{
410 Handle(TFunction_Driver) driver;
411 Handle(TFunction_Function) func;
412 if (!myLabel.FindAttribute(TFunction_Function::GetID(), func))
9775fa61 413 throw Standard_NoSuchObject("TFunction_IFunction::GetDriver(): A Function is not found attached to this label");
7fd59977 414 if (!TFunction_DriverTable::Get()->FindDriver(func->GetDriverGUID(), driver, thread))
9775fa61 415 throw Standard_NoSuchObject("TFunction_IFunction::GetDriver(): A driver is not found for this ID");
7fd59977 416 driver->Init(myLabel);
417 return driver;
418}
419
420//=======================================================================
421//function : GetGraphNode
422//purpose : Returns a graph node of the function.
423//=======================================================================
424
425Handle(TFunction_GraphNode) TFunction_IFunction::GetGraphNode() const
426{
427 Handle(TFunction_GraphNode) graphNode;
428 if (!myLabel.FindAttribute(TFunction_GraphNode::GetID(), graphNode))
9775fa61 429 throw Standard_NoSuchObject("TFunction_IFunction::GetStatus(): A graph node is not found attached to this label");
7fd59977 430 return graphNode;
431}