Salome HOME
Merge from V5_1_main 14/05/2010
[modules/geom.git] / src / GEOM / GEOM_Function.cxx
1 //  Copyright (C) 2007-2010  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
23 #include <Standard_Stream.hxx>
24
25 #include <GEOM_Function.hxx>
26 #include <GEOM_Object.hxx>
27 #include <GEOM_Solver.hxx>
28 #include <GEOM_ISubShape.hxx>
29
30 #include "utilities.h"
31
32 #include <TDF.hxx>
33 #include <TDF_Tool.hxx>
34 #include <TDF_Data.hxx>
35 #include <TDF_ChildIterator.hxx>
36 #include <TDF_Reference.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  *  SetReal
306  */
307 //=============================================================================
308 void GEOM_Function::SetReal(int thePosition, double theValue)
309 {
310   _isDone = false;
311   if(thePosition <= 0) return;
312   TDF_Label anArgLabel = ARGUMENT(thePosition);
313   TDataStd_Real::Set(anArgLabel, theValue);
314   _isDone = true;
315 }
316
317 //=============================================================================
318 /*!
319  *  SetRealArray
320  */
321 //=============================================================================
322 void GEOM_Function::SetRealArray (int thePosition,
323                                   const Handle(TColStd_HArray1OfReal)& theArray)
324 {
325   _isDone = false;
326   if(thePosition <= 0) return;
327   TDF_Label anArgLabel = ARGUMENT(thePosition);
328   Handle(TDataStd_RealArray) anAttr =
329     TDataStd_RealArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
330   anAttr->ChangeArray(theArray);
331   _isDone = true;
332 }
333
334 //=============================================================================
335 /*!
336  *  GetReal
337  */
338 //=============================================================================
339 double GEOM_Function::GetReal(int thePosition)
340 {
341   _isDone = false;
342   if(thePosition <= 0) return 0.0;
343   Handle(TDataStd_Real) aReal;
344   TDF_Label anArgLabel = ARGUMENT(thePosition);
345   if(!anArgLabel.FindAttribute(TDataStd_Real::GetID(), aReal)) return 0.0;
346
347   _isDone = true;
348   return aReal->Get();
349 }
350
351 //=============================================================================
352 /*!
353  *  GetRealArray
354  */
355 //=============================================================================
356 Handle(TColStd_HArray1OfReal) GEOM_Function::GetRealArray(int thePosition)
357 {
358   _isDone = false;
359   if(thePosition <= 0) return NULL;
360   Handle(TDataStd_RealArray) aRealArray;
361   TDF_Label anArgLabel = ARGUMENT(thePosition);
362   if(!anArgLabel.FindAttribute(TDataStd_RealArray::GetID(), aRealArray)) return NULL;
363
364   _isDone = true;
365   return aRealArray->Array();
366 }
367
368 //=============================================================================
369 /*!
370  *  SetInteger
371  */
372 //=============================================================================
373 void GEOM_Function::SetInteger(int thePosition, int theValue)
374 {
375   _isDone = false;
376   if(thePosition <= 0) return;
377   TDF_Label anArgLabel = ARGUMENT(thePosition);
378   TDataStd_Integer::Set(anArgLabel, theValue);
379   _isDone = true;
380 }
381
382 //=============================================================================
383 /*!
384  *  SetIntegerArray
385  */
386 //=============================================================================
387 void GEOM_Function::SetIntegerArray (int thePosition,
388                                      const Handle(TColStd_HArray1OfInteger)& theArray)
389 {
390   _isDone = false;
391   if(thePosition <= 0) return;
392   TDF_Label anArgLabel = ARGUMENT(thePosition);
393   Handle(TDataStd_IntegerArray) anAttr =
394     TDataStd_IntegerArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
395   anAttr->ChangeArray(theArray);
396   _isDone = true;
397 }
398
399 //=============================================================================
400 /*!
401  *  GetInteger
402  */
403 //=============================================================================
404 int GEOM_Function::GetInteger(int thePosition)
405 {
406   _isDone = false;
407   if(thePosition <= 0) return 0;
408   Handle(TDataStd_Integer) anInteger;
409   TDF_Label anArgLabel = ARGUMENT(thePosition);
410   if(!anArgLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) return 0;
411
412   _isDone = true;
413   return anInteger->Get();
414 }
415
416 //=============================================================================
417 /*!
418  *  GetIntegerArray
419  */
420 //=============================================================================
421 Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition)
422 {
423   _isDone = false;
424   if(thePosition <= 0) return 0;
425   Handle(TDataStd_IntegerArray) anIntegerArray;
426   TDF_Label anArgLabel = ARGUMENT(thePosition);
427   if(!anArgLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) return 0;
428
429   _isDone = true;
430   return anIntegerArray->Array();
431 }
432
433 //=============================================================================
434 /*!
435  *  SetString
436  */
437 //=============================================================================
438 void GEOM_Function::SetString(int thePosition, const TCollection_AsciiString& theValue)
439 {
440   _isDone = false;
441   if(thePosition <= 0) return;
442   TDF_Label anArgLabel = ARGUMENT(thePosition);
443   TDataStd_Comment::Set(anArgLabel, theValue);
444   _isDone = true;
445 }
446
447 //=============================================================================
448 /*!
449  *  GetString
450  */
451 //=============================================================================
452 TCollection_AsciiString GEOM_Function::GetString(int thePosition)
453 {
454   _isDone = false;
455   TCollection_AsciiString aRes;
456   if(thePosition <= 0) return aRes;
457   Handle(TDataStd_Comment) aString;
458   TDF_Label anArgLabel = ARGUMENT(thePosition);
459   if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
460
461   _isDone = true;
462   aRes = TCollection_AsciiString(aString->Get());
463   return aRes;
464 }
465
466 //=============================================================================
467 /*!
468  *  SetReference
469  */
470 //=============================================================================
471 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
472 {
473   _isDone = false;
474   if(thePosition <= 0) return;
475   if(theReference.IsNull()) return;
476   TDF_Label anArgLabel = ARGUMENT(thePosition);
477   TDF_Reference::Set(anArgLabel, theReference->GetEntry());
478   TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
479   _isDone = true;
480   return;
481 }
482
483 //=============================================================================
484 /*!
485  *  GetReference
486  */
487 //=============================================================================
488 Handle(GEOM_Function) GEOM_Function::GetReference(int thePosition)
489 {
490   _isDone = false;
491   if(thePosition <= 0) return NULL;
492   TDF_Label anArgLabel = ARGUMENT(thePosition);
493   Handle(TDF_Reference) aRef;
494   if(!anArgLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL;
495
496   _isDone = true;
497   return GetFunction(aRef->Get());
498 }
499
500
501 //=============================================================================
502 /*!
503  *  SetStringArray
504  */
505 //=============================================================================
506 void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1OfExtendedString)& theArray)
507 {
508   _isDone = false;
509   if(thePosition <= 0 || theArray.IsNull()) return;
510   TDF_Label anArgLabel = ARGUMENT(thePosition);
511
512   Handle(TDataStd_ExtStringArray) anArray = new TDataStd_ExtStringArray;
513   anArray->ChangeArray(theArray);
514   anArgLabel.AddAttribute(anArray);
515
516   _isDone = true;
517 }
518
519
520 //=============================================================================
521 /*!
522  *  GetStringArray
523  */
524 //=============================================================================
525 Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePosition)
526 {
527   _isDone = false;
528   if(thePosition <= 0) return NULL;
529   TDF_Label anArgLabel = ARGUMENT(thePosition);
530   Handle(TDataStd_ExtStringArray) anArray;
531   if(!anArgLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), anArray)) return NULL;
532
533   _isDone = true;
534   return anArray->Array();
535 }
536
537 //=======================================================================
538 //function : GetReferencesTreeID
539 //purpose  :
540 //=======================================================================
541 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
542 {
543   static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
544   return aReferencesTreeID;
545 }
546
547 //=============================================================================
548 /*!
549  *  SetReferenceList
550  */
551 //=============================================================================
552 void GEOM_Function::SetReferenceList (int thePosition,
553                                       const Handle(TColStd_HSequenceOfTransient)& theRefList)
554 {
555   _isDone = false;
556   if(thePosition <= 0) return;
557
558   // parent label for the list of references
559   TDF_Label anArgLabel = ARGUMENT(thePosition);
560   anArgLabel.ForgetAllAttributes();
561
562   // set TreeNode on the parent label
563   Handle(TDataStd_TreeNode) aRoot, aNode;
564   aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
565
566   // store references on sub-labels of the parent label
567   Handle(GEOM_Function) aFunc;
568   Standard_Integer ind, len = theRefList->Length();
569   for (ind = 1; ind <= len; ind++) {
570     aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
571     if (aFunc.IsNull()) continue;
572     TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
573     TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
574     TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
575
576     // set TreeNode on the child label
577     aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
578     aRoot->Append(aNode);
579   }
580
581   _isDone = true;
582   return;
583 }
584
585 //=============================================================================
586 /*!
587  *  GetReferenceList
588  */
589 //=============================================================================
590 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
591 {
592   Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
593   _isDone = false;
594   if(thePosition <= 0) return aResult;
595
596   // parent label for the list of references
597   TDF_Label anArgLabel = ARGUMENT(thePosition);
598   Handle(TDF_Reference) aRef;
599
600   // get TreeNode on the parent label
601   Handle(TDataStd_TreeNode) aRoot, aNode;
602   if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
603     return aResult;
604
605   // get references, stored on sub-labels of the parent label
606   TDF_Label aLabel_i;
607   TDataStd_ChildNodeIterator anIter (aRoot);
608   for (; anIter.More(); anIter.Next()) {
609     aNode = anIter.Value();
610     aLabel_i = aNode->Label();
611     if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
612     Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
613     if (aFunc_i.IsNull()) continue;
614     aResult->Append(aFunc_i);
615   }
616
617   _isDone = true;
618   return aResult;
619 }
620
621 //=============================================================================
622 /*!
623  *  SetShape
624  */
625 //=============================================================================
626 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
627 //{
628 //  _isDone = false;
629 //  if(thePosition <= 0 || theShape.IsNull()) return;
630 //
631 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
632 //  TNaming_Builder aBuilder(anArgLabel);
633 //  aBuilder.Generated(theShape);
634 //
635 //  _isDone = true;
636 //  return;
637 //}
638 //
639 //=============================================================================
640 /*!
641  *  GetShape
642  */
643 //=============================================================================
644 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
645 //{
646 //  _isDone = false;
647 //  TopoDS_Shape aShape;
648 //  if(thePosition <= 0) return aShape;
649 //
650 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
651 //  Handle(TNaming_NamedShape) aNS;
652 //  if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
653 //
654 //  aShape = aNS->Get();
655 //  _isDone = true;
656 //  return aShape;
657 //}
658
659
660 //=============================================================================
661 /*!
662  *  GetDependency
663  */
664 //=============================================================================
665 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
666 {
667   TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
668   for(; anIterator.More(); anIterator.Next()) {
669     if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
670   }
671 }
672
673 //=============================================================================
674 /*!
675  *  GetHistoryEntry
676  */
677 //=============================================================================
678 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
679 {
680   return _label.FindChild(HISTORY_LABEL, create);
681 }
682
683 //=============================================================================
684 /*!
685  *  GetArgumentHistoryEntry
686  */
687 //=============================================================================
688 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label&       theArgumentRefEntry,
689                                                   const Standard_Boolean create)
690 {
691   TColStd_ListOfInteger anArgumentRefTags;
692   TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
693   Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
694
695   TDF_Label aHistoryLabel = GetHistoryEntry(create);
696   if (aHistoryLabel.IsNull())
697     return aHistoryLabel;
698   Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
699
700   Standard_Integer itag;
701   TDF_Label aHistoryCurLabel = aHistoryLabel;
702   TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
703   for (itag = 1; itag <= aHistoryLabelPos; itag++) {
704     aListIter.Next();
705   }
706   for (; itag <= anArgumentRefLabelPos; itag++) {
707     aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
708     if (aHistoryCurLabel.IsNull())
709       return aHistoryCurLabel;
710     aListIter.Next();
711   }
712
713   return aHistoryCurLabel;
714 }
715
716 //=======================================================================
717 //function :  GEOM_Function_Type_
718 //purpose  :
719 //=======================================================================
720 Standard_EXPORT Handle_Standard_Type& GEOM_Function_Type_()
721 {
722
723   static Handle_Standard_Type aType1 = STANDARD_TYPE(MMgt_TShared);
724   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(MMgt_TShared);
725   static Handle_Standard_Type aType2 = STANDARD_TYPE(Standard_Transient);
726   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(Standard_Transient);
727
728
729   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,NULL};
730   static Handle_Standard_Type _aType = new Standard_Type("GEOM_Function",
731                                                          sizeof(GEOM_Function),
732                                                          1,
733                                                          (Standard_Address)_Ancestors,
734                                                          (Standard_Address)NULL);
735
736   return _aType;
737 }
738
739 //=======================================================================
740 //function : DownCast
741 //purpose  :
742 //=======================================================================
743
744 const Handle(GEOM_Function) Handle(GEOM_Function)::DownCast(const Handle(Standard_Transient)& AnObject)
745 {
746   Handle(GEOM_Function) _anOtherObject;
747
748   if (!AnObject.IsNull()) {
749      if (AnObject->IsKind(STANDARD_TYPE(GEOM_Function))) {
750        _anOtherObject = Handle(GEOM_Function)((Handle(GEOM_Function)&)AnObject);
751      }
752   }
753
754   return _anOtherObject ;
755 }