Salome HOME
142a3a4caffe590d961a37f8de0c1db6516e3bb4
[modules/geom.git] / src / GEOM / GEOM_Function.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <Standard_Stream.hxx>
23
24 #include <GEOM_Function.hxx>
25 #include <GEOM_Object.hxx>
26 #include <GEOM_Solver.hxx>
27 #include <GEOM_ISubShape.hxx>
28
29 #include "utilities.h"
30
31 #include <TDF.hxx>
32 #include <TDF_Tool.hxx>
33 #include <TDF_Data.hxx>
34 #include <TDF_ChildIterator.hxx>
35 #include <TDF_Reference.hxx>
36 #include <TDataStd_AsciiString.hxx>
37 #include <TDataStd_Integer.hxx>
38 #include <TDataStd_IntegerArray.hxx>
39 #include <TDataStd_Real.hxx>
40 #include <TDataStd_RealArray.hxx>
41 #include <TDataStd_Comment.hxx>
42 #include <TDataStd_TreeNode.hxx>
43 #include <TDataStd_UAttribute.hxx>
44 #include <TDataStd_ChildNodeIterator.hxx>
45 #include <TDataStd_ExtStringArray.hxx>
46 #include <TDocStd_Owner.hxx>
47 #include <TDocStd_Document.hxx>
48 #include <TFunction_Function.hxx>
49 #include <TNaming_NamedShape.hxx>
50 #include <TNaming_Builder.hxx>
51
52 #include <TColStd_ListOfInteger.hxx>
53 #include <TColStd_ListIteratorOfListOfInteger.hxx>
54 #include <TColStd_HArray1OfReal.hxx>
55 #include <TColStd_HArray1OfInteger.hxx>
56 #include <TColStd_HSequenceOfTransient.hxx>
57 #include <TCollection_AsciiString.hxx>
58 #include <TCollection_ExtendedString.hxx>
59
60 #include <Standard_Failure.hxx>
61 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
62
63 #define ARGUMENT_LABEL 1
64 #define RESULT_LABEL 2
65 #define DESCRIPTION_LABEL 3
66 #define HISTORY_LABEL 4
67
68 #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
69 #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
70 #define SUB_ARGUMENT(thePos1, thePos2) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePos1)).FindChild((thePos2))
71
72 //=======================================================================
73 //function : GetFunctionTreeID
74 //purpose  :
75 //=======================================================================
76 const Standard_GUID& GEOM_Function::GetFunctionTreeID()
77 {
78   static Standard_GUID aFunctionTreeID("FF1BBB00-5D14-4df2-980B-3A668264EA16");
79   return aFunctionTreeID;
80 }
81
82
83 //=======================================================================
84 //function : GetDependencyID
85 //purpose  :
86 //=======================================================================
87 const Standard_GUID& GEOM_Function::GetDependencyID()
88 {
89   static Standard_GUID aDependencyID("E2620650-2354-41bd-8C2C-210CFCD00948");
90   return aDependencyID;
91 }
92
93 //=============================================================================
94 /*!
95  *  GetFunction:
96  */
97 //=============================================================================
98 Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry)
99 {
100   if(!theEntry.IsAttribute(TFunction_Function::GetID())) return NULL;
101
102   return new GEOM_Function(theEntry);
103 }
104
105 //=============================================================================
106 /*!
107  *  Constructor:
108  */
109 //=============================================================================
110 GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType)
111 : _label(theEntry)
112 {
113   TFunction_Function::Set(theEntry, theGUID);
114   TDataStd_Integer::Set(theEntry, theType);
115
116   //Add function to a function tree
117   Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(theEntry.Data());
118   Handle(TDataStd_TreeNode) aRoot, aNode;
119   if(!aDoc->Main().FindAttribute(GetFunctionTreeID(), aRoot))
120     aRoot = TDataStd_TreeNode::Set(aDoc->Main(), GetFunctionTreeID());
121
122   aNode = TDataStd_TreeNode::Set(theEntry, GetFunctionTreeID());
123   aRoot->Append(aNode);
124 }
125
126 //=============================================================================
127 /*!
128  *  GetOwner
129  */
130 //=============================================================================
131 TDF_Label GEOM_Function::GetOwnerEntry()
132 {
133   TDF_Label aFather = _label.Father();
134   while(!aFather.IsRoot()) {
135     if(aFather.IsAttribute(GEOM_Object::GetObjectID())) return aFather;
136     aFather = aFather.Father();
137   }
138
139   return TDF_Label();
140 }
141
142 //=============================================================================
143 /*!
144  *  GetType
145  */
146 //=============================================================================
147 int GEOM_Function::GetType()
148 {
149   _isDone = false;
150   Handle(TDataStd_Integer) aType;
151   if(!_label.FindAttribute(TDataStd_Integer::GetID(), aType)) return 0;
152   _isDone = true;
153   return aType->Get();
154 }
155
156 //=============================================================================
157 /*!
158  *  GetValue
159  */
160 //=============================================================================
161 TopoDS_Shape GEOM_Function::GetValue()
162 {
163   _isDone = false;
164
165   TopoDS_Shape aShape;
166   TDF_Label aLabel = GetOwnerEntry();
167   if (aLabel.IsRoot()) return aShape;
168   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
169   if (anObject.IsNull()) return aShape;
170
171   if (!anObject->IsMainShape()) {
172     bool isResult = false;
173     TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
174     if (!aResultLabel.IsNull()) {
175       Handle(TNaming_NamedShape) aNS;
176       if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
177         isResult = true;
178     }
179
180     // compare tics
181     if (isResult) {
182       // tic of this
183       Standard_Integer aTic = anObject->GetTic();
184
185       // tic of main shape
186       GEOM_ISubShape aCI (this);
187       TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
188       if (aLabelObjMainSh.IsRoot()) return aShape;
189       Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
190       if (anObjMainSh.IsNull()) return aShape;
191       Standard_Integer aTicMainSh = anObjMainSh->GetTic();
192
193       // compare
194       isResult = ((aTic == aTicMainSh) ? true : false);
195     }
196
197     if (!isResult) {
198       try {
199 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
200         OCC_CATCH_SIGNALS;
201 #endif
202         GEOM_Solver aSolver(GEOM_Engine::GetEngine());
203         if (!aSolver.ComputeFunction(this)) {
204           MESSAGE("GEOM_Object::GetValue Error : Can't build a sub shape");
205           return aShape;
206         }
207       }
208       catch (Standard_Failure) {
209         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
210         MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
211         return aShape;
212       }
213     }
214   }
215
216   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
217   Handle(TNaming_NamedShape) aNS;
218   if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
219
220   aShape = aNS->Get();
221
222   _isDone = true;
223   return aShape;
224 }
225
226 //=============================================================================
227 /*!
228  *  SetValue
229  */
230 //=============================================================================
231 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
232 {
233   _isDone = false;
234   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
235   TNaming_Builder aBuilder(aResultLabel);
236
237   aBuilder.Generated(theShape);
238
239   // synchronisation between main shape and its sub-shapes
240   TDF_Label aLabel = GetOwnerEntry();
241   if (aLabel.IsRoot()) return;
242   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
243   if (anObject.IsNull()) return;
244   if (anObject->IsMainShape()) {
245     // increase modifications counter of this (main) shape
246     anObject->IncrementTic();
247   }
248   else {
249     // update modifications counter of this (sub-) shape to be the same as on main shape
250     GEOM_ISubShape aCI (this);
251     TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
252     if (aLabelObjMainSh.IsRoot()) return;
253     Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
254     if (anObjMainSh.IsNull()) return;
255
256     anObject->SetTic(anObjMainSh->GetTic());
257   }
258
259   _isDone = true;
260 }
261
262 //=============================================================================
263 /*!
264  *  GetDriverGUID
265  */
266 //=============================================================================
267 Standard_GUID GEOM_Function::GetDriverGUID()
268 {
269   Handle(TFunction_Function) aFunction;
270   if(!_label.FindAttribute(TFunction_Function::GetID(), aFunction)) {
271     return TDF::LowestID();
272   }
273
274   return aFunction->GetDriverGUID();
275 }
276
277 //=============================================================================
278 /*!
279  *  GetDescription
280  */
281 //=============================================================================
282 TCollection_AsciiString GEOM_Function::GetDescription()
283 {
284   Handle(TDataStd_Comment) aComment;
285   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
286   if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return TCollection_AsciiString();
287   TCollection_AsciiString aDescr(aComment->Get());
288   return aDescr;
289 }
290
291 //=============================================================================
292 /*!
293  *  SetDescription
294  */
295 //=============================================================================
296 void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription)
297 {
298   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
299   Handle(TDataStd_Comment) aComment =
300     TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription));
301 }
302
303 //=============================================================================
304 /*!
305  *  GetArgsCount
306  */
307 //=============================================================================
308 int GEOM_Function::GetArgsCount()
309 {
310   return _label.FindChild( ARGUMENT_LABEL ).NbChildren();
311 }
312
313 //=============================================================================
314 /*!
315  *  SetParam
316  */
317 //=============================================================================
318 void GEOM_Function::SetParam( int thePosition, const TCollection_AsciiString& theParamName )
319 {
320   _isDone = false;
321   if( thePosition <= 0 )
322     return;
323
324   TDF_Label anArgLabel = ARGUMENT( thePosition );
325   TDataStd_AsciiString::Set( anArgLabel, theParamName );
326   _isDone = true;
327 }
328
329 //=============================================================================
330 /*!
331  *  GetParam
332  */
333 //=============================================================================
334 TCollection_AsciiString GEOM_Function::GetParam(int thePosition)
335 {
336   _isDone = false;
337   if( thePosition <= 0 )
338     return 0.0;
339
340   Handle( TDataStd_AsciiString ) aParam;
341   TDF_Label anArgLabel = ARGUMENT( thePosition );
342   if( !anArgLabel.FindAttribute( TDataStd_AsciiString::GetID(), aParam ) )
343     return "";
344
345   _isDone = true;
346   return aParam->Get();
347 }
348
349 //=============================================================================
350 /*!
351  *  SetReal
352  */
353 //=============================================================================
354 void GEOM_Function::SetReal(int thePosition, double theValue)
355 {
356   _isDone = false;
357   if(thePosition <= 0) return;
358   TDF_Label anArgLabel = ARGUMENT(thePosition);
359   TDataStd_Real::Set(anArgLabel, theValue);
360   _isDone = true;
361 }
362
363 //=============================================================================
364 /*!
365  *  SetRealArray
366  */
367 //=============================================================================
368 void GEOM_Function::SetRealArray (int thePosition,
369                                   const Handle(TColStd_HArray1OfReal)& theArray)
370 {
371   _isDone = false;
372   if(thePosition <= 0) return;
373   TDF_Label anArgLabel = ARGUMENT(thePosition);
374   Handle(TDataStd_RealArray) anAttr =
375     TDataStd_RealArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
376   anAttr->ChangeArray(theArray);
377   _isDone = true;
378 }
379
380 //=============================================================================
381 /*!
382  *  GetReal
383  */
384 //=============================================================================
385 double GEOM_Function::GetReal(int thePosition)
386 {
387   _isDone = false;
388   if(thePosition <= 0) return 0.0;
389   Handle(TDataStd_Real) aReal;
390   TDF_Label anArgLabel = ARGUMENT(thePosition);
391   if(!anArgLabel.FindAttribute(TDataStd_Real::GetID(), aReal)) return 0.0;
392
393   _isDone = true;
394   return aReal->Get();
395 }
396
397 //=============================================================================
398 /*!
399  *  GetRealArray
400  */
401 //=============================================================================
402 Handle(TColStd_HArray1OfReal) GEOM_Function::GetRealArray(int thePosition)
403 {
404   _isDone = false;
405   if(thePosition <= 0) return NULL;
406   Handle(TDataStd_RealArray) aRealArray;
407   TDF_Label anArgLabel = ARGUMENT(thePosition);
408   if(!anArgLabel.FindAttribute(TDataStd_RealArray::GetID(), aRealArray)) return NULL;
409
410   _isDone = true;
411   return aRealArray->Array();
412 }
413
414 //=============================================================================
415 /*!
416  *  SetInteger
417  */
418 //=============================================================================
419 void GEOM_Function::SetInteger(int thePosition, int theValue)
420 {
421   _isDone = false;
422   if(thePosition <= 0) return;
423   TDF_Label anArgLabel = ARGUMENT(thePosition);
424   TDataStd_Integer::Set(anArgLabel, theValue);
425   _isDone = true;
426 }
427
428 //=============================================================================
429 /*!
430  *  SetIntegerArray
431  */
432 //=============================================================================
433 void GEOM_Function::SetIntegerArray (int thePosition,
434                                      const Handle(TColStd_HArray1OfInteger)& theArray)
435 {
436   _isDone = false;
437   if(thePosition <= 0) return;
438   TDF_Label anArgLabel = ARGUMENT(thePosition);
439   Handle(TDataStd_IntegerArray) anAttr =
440     TDataStd_IntegerArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
441   anAttr->ChangeArray(theArray);
442   _isDone = true;
443 }
444
445 //=============================================================================
446 /*!
447  *  GetInteger
448  */
449 //=============================================================================
450 int GEOM_Function::GetInteger(int thePosition)
451 {
452   _isDone = false;
453   if(thePosition <= 0) return 0;
454   Handle(TDataStd_Integer) anInteger;
455   TDF_Label anArgLabel = ARGUMENT(thePosition);
456   if(!anArgLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) return 0;
457
458   _isDone = true;
459   return anInteger->Get();
460 }
461
462 //=============================================================================
463 /*!
464  *  GetIntegerArray
465  */
466 //=============================================================================
467 Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition)
468 {
469   _isDone = false;
470   if(thePosition <= 0) return 0;
471   Handle(TDataStd_IntegerArray) anIntegerArray;
472   TDF_Label anArgLabel = ARGUMENT(thePosition);
473   if(!anArgLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) return 0;
474
475   _isDone = true;
476   return anIntegerArray->Array();
477 }
478
479 //=============================================================================
480 /*!
481  *  SetString
482  */
483 //=============================================================================
484 void GEOM_Function::SetString(int thePosition, const TCollection_AsciiString& theValue)
485 {
486   _isDone = false;
487   if(thePosition <= 0) return;
488   TDF_Label anArgLabel = ARGUMENT(thePosition);
489   TDataStd_Comment::Set(anArgLabel, theValue);
490   _isDone = true;
491 }
492
493 //=============================================================================
494 /*!
495  *  GetString
496  */
497 //=============================================================================
498 TCollection_AsciiString GEOM_Function::GetString(int thePosition)
499 {
500   _isDone = false;
501   TCollection_AsciiString aRes;
502   if(thePosition <= 0) return aRes;
503   Handle(TDataStd_Comment) aString;
504   TDF_Label anArgLabel = ARGUMENT(thePosition);
505   if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
506
507   _isDone = true;
508   aRes = TCollection_AsciiString(aString->Get());
509   return aRes;
510 }
511
512 //=============================================================================
513 /*!
514  *  SetReference
515  */
516 //=============================================================================
517 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
518 {
519   _isDone = false;
520   if(thePosition <= 0) return;
521   if(theReference.IsNull()) return;
522   TDF_Label anArgLabel = ARGUMENT(thePosition);
523   TDF_Reference::Set(anArgLabel, theReference->GetEntry());
524   TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
525   _isDone = true;
526   return;
527 }
528
529 //=============================================================================
530 /*!
531  *  GetReference
532  */
533 //=============================================================================
534 Handle(GEOM_Function) GEOM_Function::GetReference(int thePosition)
535 {
536   _isDone = false;
537   if(thePosition <= 0) return NULL;
538   TDF_Label anArgLabel = ARGUMENT(thePosition);
539   Handle(TDF_Reference) aRef;
540   if(!anArgLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL;
541
542   _isDone = true;
543   return GetFunction(aRef->Get());
544 }
545
546
547 //=============================================================================
548 /*!
549  *  SetStringArray
550  */
551 //=============================================================================
552 void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1OfExtendedString)& theArray)
553 {
554   _isDone = false;
555   if(thePosition <= 0 || theArray.IsNull()) return;
556   TDF_Label anArgLabel = ARGUMENT(thePosition);
557
558   Handle(TDataStd_ExtStringArray) anArray = new TDataStd_ExtStringArray;
559   anArray->ChangeArray(theArray);
560   anArgLabel.AddAttribute(anArray);
561
562   _isDone = true;
563 }
564
565
566 //=============================================================================
567 /*!
568  *  GetStringArray
569  */
570 //=============================================================================
571 Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePosition)
572 {
573   _isDone = false;
574   if(thePosition <= 0) return NULL;
575   TDF_Label anArgLabel = ARGUMENT(thePosition);
576   Handle(TDataStd_ExtStringArray) anArray;
577   if(!anArgLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), anArray)) return NULL;
578
579   _isDone = true;
580   return anArray->Array();
581 }
582
583 //=======================================================================
584 //function : GetReferencesTreeID
585 //purpose  :
586 //=======================================================================
587 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
588 {
589   static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
590   return aReferencesTreeID;
591 }
592
593 //=============================================================================
594 /*!
595  *  SetReferenceList
596  */
597 //=============================================================================
598 void GEOM_Function::SetReferenceList (int thePosition,
599                                       const Handle(TColStd_HSequenceOfTransient)& theRefList)
600 {
601   _isDone = false;
602   if(thePosition <= 0) return;
603
604   // parent label for the list of references
605   TDF_Label anArgLabel = ARGUMENT(thePosition);
606   anArgLabel.ForgetAllAttributes();
607
608   // set TreeNode on the parent label
609   Handle(TDataStd_TreeNode) aRoot, aNode;
610   aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
611
612   // store references on sub-labels of the parent label
613   Handle(GEOM_Function) aFunc;
614   Standard_Integer ind, len = theRefList->Length();
615   for (ind = 1; ind <= len; ind++) {
616     aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
617     if (aFunc.IsNull()) continue;
618     TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
619     TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
620     TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
621
622     // set TreeNode on the child label
623     aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
624     aRoot->Append(aNode);
625   }
626
627   _isDone = true;
628   return;
629 }
630
631 //=============================================================================
632 /*!
633  *  GetReferenceList
634  */
635 //=============================================================================
636 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
637 {
638   Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
639   _isDone = false;
640   if(thePosition <= 0) return aResult;
641
642   // parent label for the list of references
643   TDF_Label anArgLabel = ARGUMENT(thePosition);
644   Handle(TDF_Reference) aRef;
645
646   // get TreeNode on the parent label
647   Handle(TDataStd_TreeNode) aRoot, aNode;
648   if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
649     return aResult;
650
651   // get references, stored on sub-labels of the parent label
652   TDF_Label aLabel_i;
653   TDataStd_ChildNodeIterator anIter (aRoot);
654   for (; anIter.More(); anIter.Next()) {
655     aNode = anIter.Value();
656     aLabel_i = aNode->Label();
657     if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
658     Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
659     if (aFunc_i.IsNull()) continue;
660     aResult->Append(aFunc_i);
661   }
662
663   _isDone = true;
664   return aResult;
665 }
666
667 //=============================================================================
668 /*!
669  *  SetShape
670  */
671 //=============================================================================
672 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
673 //{
674 //  _isDone = false;
675 //  if(thePosition <= 0 || theShape.IsNull()) return;
676 //
677 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
678 //  TNaming_Builder aBuilder(anArgLabel);
679 //  aBuilder.Generated(theShape);
680 //
681 //  _isDone = true;
682 //  return;
683 //}
684 //
685 //=============================================================================
686 /*!
687  *  GetShape
688  */
689 //=============================================================================
690 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
691 //{
692 //  _isDone = false;
693 //  TopoDS_Shape aShape;
694 //  if(thePosition <= 0) return aShape;
695 //
696 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
697 //  Handle(TNaming_NamedShape) aNS;
698 //  if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
699 //
700 //  aShape = aNS->Get();
701 //  _isDone = true;
702 //  return aShape;
703 //}
704
705
706 //=============================================================================
707 /*!
708  *  GetDependency
709  */
710 //=============================================================================
711 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
712 {
713   TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
714   for(; anIterator.More(); anIterator.Next()) {
715     if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
716   }
717 }
718
719 //=============================================================================
720 /*!
721  *  GetHistoryEntry
722  */
723 //=============================================================================
724 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
725 {
726   return _label.FindChild(HISTORY_LABEL, create);
727 }
728
729 //=============================================================================
730 /*!
731  *  GetArgumentHistoryEntry
732  */
733 //=============================================================================
734 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label&       theArgumentRefEntry,
735                                                   const Standard_Boolean create)
736 {
737   TColStd_ListOfInteger anArgumentRefTags;
738   TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
739   Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
740
741   TDF_Label aHistoryLabel = GetHistoryEntry(create);
742   if (aHistoryLabel.IsNull())
743     return aHistoryLabel;
744   Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
745
746   Standard_Integer itag;
747   TDF_Label aHistoryCurLabel = aHistoryLabel;
748   TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
749   for (itag = 1; itag <= aHistoryLabelPos; itag++) {
750     aListIter.Next();
751   }
752   for (; itag <= anArgumentRefLabelPos; itag++) {
753     aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
754     if (aHistoryCurLabel.IsNull())
755       return aHistoryCurLabel;
756     aListIter.Next();
757   }
758
759   return aHistoryCurLabel;
760 }
761
762 //=======================================================================
763 //function :  GEOM_Function_Type_
764 //purpose  :
765 //=======================================================================
766 Standard_EXPORT Handle_Standard_Type& GEOM_Function_Type_()
767 {
768
769   static Handle_Standard_Type aType1 = STANDARD_TYPE(MMgt_TShared);
770   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(MMgt_TShared);
771   static Handle_Standard_Type aType2 = STANDARD_TYPE(Standard_Transient);
772   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(Standard_Transient);
773
774
775   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,NULL};
776   static Handle_Standard_Type _aType = new Standard_Type("GEOM_Function",
777                                                          sizeof(GEOM_Function),
778                                                          1,
779                                                          (Standard_Address)_Ancestors,
780                                                          (Standard_Address)NULL);
781
782   return _aType;
783 }
784
785 //=======================================================================
786 //function : DownCast
787 //purpose  :
788 //=======================================================================
789
790 const Handle(GEOM_Function) Handle(GEOM_Function)::DownCast(const Handle(Standard_Transient)& AnObject)
791 {
792   Handle(GEOM_Function) _anOtherObject;
793
794   if (!AnObject.IsNull()) {
795      if (AnObject->IsKind(STANDARD_TYPE(GEOM_Function))) {
796        _anOtherObject = Handle(GEOM_Function)((Handle(GEOM_Function)&)AnObject);
797      }
798   }
799
800   return _anOtherObject ;
801 }