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