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