Salome HOME
db4658cf2c61b9f263a5173e611e045f46ccfcf1
[modules/geom.git] / src / GEOM / GEOM_Function.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 <Basics_OCCTVersion.hxx>
31
32 #include "utilities.h"
33
34 #include <TDF.hxx>
35 #include <TDF_Tool.hxx>
36 #include <TDF_Data.hxx>
37 #include <TDF_ChildIterator.hxx>
38 #include <TDF_Reference.hxx>
39 #include <TDataStd_Integer.hxx>
40 #include <TDataStd_IntegerArray.hxx>
41 #include <TDataStd_Real.hxx>
42 #include <TDataStd_RealArray.hxx>
43 #include <TDataStd_Comment.hxx>
44 #include <TDataStd_TreeNode.hxx>
45 #include <TDataStd_UAttribute.hxx>
46 #include <TDataStd_ChildNodeIterator.hxx>
47 #include <TDataStd_ExtStringArray.hxx>
48 #include <TDataStd_ExtStringList.hxx>
49 #include <TDocStd_Owner.hxx>
50 #include <TDocStd_Document.hxx>
51 #include <TFunction_Function.hxx>
52 #include <TNaming_NamedShape.hxx>
53 #include <TNaming_Builder.hxx>
54
55 #include <TColStd_ListOfInteger.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
57 #include <TColStd_HArray1OfReal.hxx>
58 #include <TColStd_HArray1OfInteger.hxx>
59 #include <TColStd_HSequenceOfTransient.hxx>
60 #include <TCollection_AsciiString.hxx>
61 #include <TCollection_ExtendedString.hxx>
62
63 #include <Standard_Failure.hxx>
64 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
65
66 // This modification was introduced in frame of Mantis issue 0021251.
67 // This line allows to keep shape orientation together with the shape itself.
68 // Otherwise orientation can be lost in some cases.
69 #define KEEP_ORIENTATION_0021251
70
71 #define ARGUMENT_LABEL 1
72 #define RESULT_LABEL 2
73 #define DESCRIPTION_LABEL 3
74 #define HISTORY_LABEL 4
75 #define SUBSHAPES_LABEL 5 // 0020756: GetGroups
76 #define NAMING_LABEL 6 // 0020750: Naming during STEP import
77
78 #ifdef KEEP_ORIENTATION_0021251
79 #define ORIENTATION_LABEL 7 // 0021251: TNaming_NamedShape doesn't store orientation
80 #endif
81
82 #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
83 #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
84 #define SUB_ARGUMENT(thePos1, thePos2) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePos1)).FindChild((thePos2))
85
86 //=======================================================================
87 //function : GetFunctionTreeID
88 //purpose  :
89 //=======================================================================
90 const Standard_GUID& GEOM_Function::GetFunctionTreeID()
91 {
92   static Standard_GUID aFunctionTreeID("FF1BBB00-5D14-4df2-980B-3A668264EA16");
93   return aFunctionTreeID;
94 }
95
96
97 //=======================================================================
98 //function : GetDependencyID
99 //purpose  :
100 //=======================================================================
101 const Standard_GUID& GEOM_Function::GetDependencyID()
102 {
103   static Standard_GUID aDependencyID("E2620650-2354-41bd-8C2C-210CFCD00948");
104   return aDependencyID;
105 }
106
107 //=============================================================================
108 /*!
109  *  GetFunction:
110  */
111 //=============================================================================
112 Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry)
113 {
114   if(!theEntry.IsAttribute(TFunction_Function::GetID())) return NULL;
115
116   return new GEOM_Function(theEntry);
117 }
118
119 //=============================================================================
120 /*!
121  *  Constructor:
122  */
123 //=============================================================================
124 GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType)
125 : _label(theEntry)
126 {
127   TFunction_Function::Set(theEntry, theGUID);
128   TDataStd_Integer::Set(theEntry, theType);
129
130   //Add function to a function tree
131   Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(theEntry.Data());
132   Handle(TDataStd_TreeNode) aRoot, aNode;
133   if(!aDoc->Main().FindAttribute(GetFunctionTreeID(), aRoot))
134     aRoot = TDataStd_TreeNode::Set(aDoc->Main(), GetFunctionTreeID());
135
136   aNode = TDataStd_TreeNode::Set(theEntry, GetFunctionTreeID());
137   aRoot->Append(aNode);
138 }
139
140 //================================================================================
141 /*!
142  * \brief Retuns true if this function is the last one in the study
143  */
144 //================================================================================
145
146 bool GEOM_Function::IsLastFuntion()
147 {
148   bool isLast = false;
149
150   Handle(TDataStd_TreeNode) aNode;
151   if (_label.FindAttribute(GetFunctionTreeID(), aNode))
152     isLast = !aNode->HasNext();
153
154   return isLast;
155 }
156
157 //=============================================================================
158 /*!
159  *  GetOwner
160  */
161 //=============================================================================
162 TDF_Label GEOM_Function::GetOwnerEntry()
163 {
164   TDF_Label aFather = _label.Father();
165   while(!aFather.IsRoot()) {
166     if(aFather.IsAttribute(GEOM_Object::GetObjectID())) return aFather;
167     aFather = aFather.Father();
168   }
169
170   return TDF_Label();
171 }
172
173 //=============================================================================
174 /*!
175  *  GetType
176  */
177 //=============================================================================
178 int GEOM_Function::GetType()
179 {
180   _isDone = false;
181   Handle(TDataStd_Integer) aType;
182   if(!_label.FindAttribute(TDataStd_Integer::GetID(), aType)) return 0;
183   _isDone = true;
184   return aType->Get();
185 }
186
187 //=============================================================================
188 /*!
189  *  GetValue
190  */
191 //=============================================================================
192 TopoDS_Shape GEOM_Function::GetValue()
193 {
194   _isDone = false;
195
196   TopoDS_Shape aShape;
197   TDF_Label aLabel = GetOwnerEntry();
198   if (aLabel.IsRoot()) return aShape;
199   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
200   if (anObject.IsNull()) return aShape;
201
202   if (!anObject->IsMainShape()) {
203     bool isResult = false;
204     TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
205     if (!aResultLabel.IsNull()) {
206       Handle(TNaming_NamedShape) aNS;
207       if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
208         isResult = true;
209     }
210
211     // compare tics
212     if (isResult) {
213       // tic of this
214       Standard_Integer aTic = anObject->GetTic();
215
216       // tic of main shape
217       GEOM_ISubShape aCI (this);
218       TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
219       if (aLabelObjMainSh.IsRoot()) return aShape;
220       Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
221       if (anObjMainSh.IsNull()) return aShape;
222       Standard_Integer aTicMainSh = anObjMainSh->GetTic();
223
224       // compare
225       isResult = ((aTic == aTicMainSh) ? true : false);
226     }
227
228     if (!isResult) {
229       try {
230 #if OCC_VERSION_LARGE > 0x06010000
231         OCC_CATCH_SIGNALS;
232 #endif
233         GEOM_Solver aSolver(GEOM_Engine::GetEngine());
234         if (!aSolver.ComputeFunction(this)) {
235           MESSAGE("GEOM_Object::GetValue Error : Can't build a sub-shape");
236           return aShape;
237         }
238       }
239       catch (Standard_Failure) {
240         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
241         MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
242         return aShape;
243       }
244     }
245   }
246
247   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
248   Handle(TNaming_NamedShape) aNS;
249   if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
250
251   aShape = aNS->Get();
252
253 #ifdef KEEP_ORIENTATION_0021251
254   // 0021251: TNaming_NamedShape doesn't store orientation
255   TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
256   Handle(TDataStd_Integer) anInteger;
257   if (anOrientationLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) {
258     aShape.Orientation((TopAbs_Orientation)anInteger->Get());
259   }
260 #endif
261
262   _isDone = true;
263   return aShape;
264 }
265
266 //=============================================================================
267 /*!
268  *  SetValue
269  */
270 //=============================================================================
271 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
272 {
273   _isDone = false;
274   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
275   TNaming_Builder aBuilder (aResultLabel);
276
277   aBuilder.Generated(theShape);
278
279 #ifdef KEEP_ORIENTATION_0021251
280   // 0021251: TNaming_NamedShape doesn't store orientation
281   TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
282   TDataStd_Integer::Set(anOrientationLabel, (int)theShape.Orientation());
283 #endif
284
285   // synchronisation between main shape and its sub-shapes
286   TDF_Label aLabel = GetOwnerEntry();
287   if (aLabel.IsRoot()) return;
288   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
289   if (anObject.IsNull()) return;
290   if (anObject->IsMainShape()) {
291     // increase modifications counter of this (main) shape
292     anObject->IncrementTic();
293   }
294   else {
295     // update modifications counter of this (sub-) shape to be the same as on main shape
296     GEOM_ISubShape aCI (this);
297     TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
298     if (aLabelObjMainSh.IsRoot()) return;
299     Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
300     if (anObjMainSh.IsNull()) return;
301
302     anObject->SetTic(anObjMainSh->GetTic());
303   }
304
305   _isDone = true;
306 }
307
308 //=============================================================================
309 /*!
310  *  GetDriverGUID
311  */
312 //=============================================================================
313 Standard_GUID GEOM_Function::GetDriverGUID()
314 {
315   Handle(TFunction_Function) aFunction;
316   if(!_label.FindAttribute(TFunction_Function::GetID(), aFunction)) {
317     return TDF::LowestID();
318   }
319
320   return aFunction->GetDriverGUID();
321 }
322
323 //=============================================================================
324 /*!
325  *  GetDescription
326  */
327 //=============================================================================
328 TCollection_AsciiString GEOM_Function::GetDescription()
329 {
330   Handle(TDataStd_Comment) aComment;
331   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
332   if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return TCollection_AsciiString();
333   TCollection_AsciiString aDescr(aComment->Get());
334   return aDescr;
335 }
336
337 //=============================================================================
338 /*!
339  *  SetDescription
340  */
341 //=============================================================================
342 void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription)
343 {
344   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
345   Handle(TDataStd_Comment) aComment =
346     TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription));
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 =
559     TDataStd_ExtStringArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
560   anArray->ChangeArray(theArray);
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 : HasData
585 //purpose  : Returns true if data of given type already exists
586 //=======================================================================
587
588 bool GEOM_Function::HasData(int thePosition, const Standard_GUID& dataID)
589 {
590   if(thePosition <= 0) return false;
591   TDF_Label anArgLabel = ARGUMENT(thePosition);
592   return anArgLabel.IsAttribute( dataID );
593 }
594
595 //=======================================================================
596 //function : GetReferencesTreeID
597 //purpose  :
598 //=======================================================================
599 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
600 {
601   static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
602   return aReferencesTreeID;
603 }
604
605 //=============================================================================
606 /*!
607  *  SetReferenceList
608  */
609 //=============================================================================
610 void GEOM_Function::SetReferenceList (int thePosition,
611                                       const Handle(TColStd_HSequenceOfTransient)& theRefList)
612 {
613   _isDone = false;
614   if(thePosition <= 0) return;
615
616   // parent label for the list of references
617   TDF_Label anArgLabel = ARGUMENT(thePosition);
618   anArgLabel.ForgetAllAttributes();
619
620   // set TreeNode on the parent label
621   Handle(TDataStd_TreeNode) aRoot, aNode;
622   aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
623
624   // store references on sub-labels of the parent label
625   Handle(GEOM_Function) aFunc;
626   Standard_Integer ind, len = theRefList->Length();
627   for (ind = 1; ind <= len; ind++) {
628     aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
629     if (aFunc.IsNull()) continue;
630     TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
631     TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
632     TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
633
634     // set TreeNode on the child label
635     aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
636     aRoot->Append(aNode);
637   }
638
639   _isDone = true;
640   return;
641 }
642
643 //=============================================================================
644 /*!
645  *  GetReferenceList
646  */
647 //=============================================================================
648 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
649 {
650   Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
651   _isDone = false;
652   if(thePosition <= 0) return aResult;
653
654   // parent label for the list of references
655   TDF_Label anArgLabel = ARGUMENT(thePosition);
656   Handle(TDF_Reference) aRef;
657
658   // get TreeNode on the parent label
659   Handle(TDataStd_TreeNode) aRoot, aNode;
660   if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
661     return aResult;
662
663   // get references, stored on sub-labels of the parent label
664   TDF_Label aLabel_i;
665   TDataStd_ChildNodeIterator anIter (aRoot);
666   for (; anIter.More(); anIter.Next()) {
667     aNode = anIter.Value();
668     aLabel_i = aNode->Label();
669     if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
670     Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
671     if (aFunc_i.IsNull()) continue;
672     aResult->Append(aFunc_i);
673   }
674
675   _isDone = true;
676   return aResult;
677 }
678
679 //=============================================================================
680 /*!
681  *  SetShape
682  */
683 //=============================================================================
684 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
685 //{
686 //  _isDone = false;
687 //  if(thePosition <= 0 || theShape.IsNull()) return;
688 //
689 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
690 //  TNaming_Builder aBuilder(anArgLabel);
691 //  aBuilder.Generated(theShape);
692 //
693 //  _isDone = true;
694 //  return;
695 //}
696 //
697 //=============================================================================
698 /*!
699  *  GetShape
700  */
701 //=============================================================================
702 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
703 //{
704 //  _isDone = false;
705 //  TopoDS_Shape aShape;
706 //  if(thePosition <= 0) return aShape;
707 //
708 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
709 //  Handle(TNaming_NamedShape) aNS;
710 //  if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
711 //
712 //  aShape = aNS->Get();
713 //  _isDone = true;
714 //  return aShape;
715 //}
716
717
718 //=============================================================================
719 /*!
720  *  GetDependency
721  */
722 //=============================================================================
723 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
724 {
725   TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
726   for(; anIterator.More(); anIterator.Next()) {
727     if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
728   }
729 }
730
731 //=============================================================================
732 /*!
733  *  AddSubShapeReference
734  */
735 //=============================================================================
736 void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
737 {
738   _isDone = false;
739
740   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
741
742   Handle(TDataStd_ExtStringList) aList;
743   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
744     aList = new TDataStd_ExtStringList;
745     aSubShapesLabel.AddAttribute(aList);
746   }
747
748   TCollection_AsciiString anEntry;
749   TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
750   aList->Append(anEntry);
751
752   _isDone = true;
753 }
754
755 //=============================================================================
756 /*!
757  *  RemoveSubShapeReference
758  */
759 //=============================================================================
760 void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape)
761 {
762   _isDone = false;
763
764   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
765
766   Handle(TDataStd_ExtStringList) aList;
767   if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
768     TCollection_AsciiString anEntry;
769     TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
770     aList->Remove(anEntry);
771   }
772
773   _isDone = true;
774 }
775
776 //=============================================================================
777 /*!
778  *  HasSubShapeReferences
779  */
780 //=============================================================================
781 bool GEOM_Function::HasSubShapeReferences()
782 {
783   _isDone = true;
784
785   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
786   return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID());
787 }
788
789 //=============================================================================
790 /*!
791  *  GetSubShapeReferences
792  */
793 //=============================================================================
794 const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
795 {
796   _isDone = false;
797
798   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
799
800   Handle(TDataStd_ExtStringList) aList;
801   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
802     aList = new TDataStd_ExtStringList;
803     aSubShapesLabel.AddAttribute(aList);
804   }
805
806   _isDone = true;
807   return aList->List();
808 }
809
810 //=============================================================================
811 /*!
812  *  GetHistoryEntry
813  */
814 //=============================================================================
815 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
816 {
817   return _label.FindChild(HISTORY_LABEL, create);
818 }
819
820 //=============================================================================
821 /*!
822  *  GetArgumentHistoryEntry
823  */
824 //=============================================================================
825 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label&       theArgumentRefEntry,
826                                                   const Standard_Boolean create)
827 {
828   TColStd_ListOfInteger anArgumentRefTags;
829   TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
830   Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
831
832   TDF_Label aHistoryLabel = GetHistoryEntry(create);
833   if (aHistoryLabel.IsNull())
834     return aHistoryLabel;
835   Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
836
837   Standard_Integer itag;
838   TDF_Label aHistoryCurLabel = aHistoryLabel;
839   TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
840   for (itag = 1; itag <= aHistoryLabelPos; itag++) {
841     aListIter.Next();
842   }
843   for (; itag <= anArgumentRefLabelPos; itag++) {
844     aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
845     if (aHistoryCurLabel.IsNull())
846       return aHistoryCurLabel;
847     aListIter.Next();
848   }
849
850   return aHistoryCurLabel;
851 }
852
853 //=============================================================================
854 /*!
855  *  GetNamingEntry
856  */
857 //=============================================================================
858 TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
859 {
860   return _label.FindChild(NAMING_LABEL, create);
861 }
862
863 IMPLEMENT_STANDARD_HANDLE (GEOM_Function, Standard_Transient);
864 IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );