]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM/GEOM_Function.cxx
Salome HOME
c141e2e4ca881575de56f34f7982517708187c4e
[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         OCC_CATCH_SIGNALS;
231         GEOM_Solver aSolver(GEOM_Engine::GetEngine());
232         if (!aSolver.ComputeFunction(this)) {
233           MESSAGE("GEOM_Object::GetValue Error : Can't build a sub-shape");
234           return aShape;
235         }
236       }
237       catch (Standard_Failure) {
238         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
239         MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
240         return aShape;
241       }
242     }
243   }
244
245   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
246   Handle(TNaming_NamedShape) aNS;
247   if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
248
249   aShape = aNS->Get();
250
251 #ifdef KEEP_ORIENTATION_0021251
252   // 0021251: TNaming_NamedShape doesn't store orientation
253   TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
254   Handle(TDataStd_Integer) anInteger;
255   if (anOrientationLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) {
256     aShape.Orientation((TopAbs_Orientation)anInteger->Get());
257   }
258 #endif
259
260   _isDone = true;
261   return aShape;
262 }
263
264 //=============================================================================
265 /*!
266  *  SetValue
267  */
268 //=============================================================================
269 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
270 {
271   _isDone = false;
272   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
273   TNaming_Builder aBuilder (aResultLabel);
274
275   aBuilder.Generated(theShape);
276
277 #ifdef KEEP_ORIENTATION_0021251
278   // 0021251: TNaming_NamedShape doesn't store orientation
279   TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
280   TDataStd_Integer::Set(anOrientationLabel, (int)theShape.Orientation());
281 #endif
282
283   // synchronisation between main shape and its sub-shapes
284   TDF_Label aLabel = GetOwnerEntry();
285   if (aLabel.IsRoot()) return;
286   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
287   if (anObject.IsNull()) return;
288   if (anObject->IsMainShape()) {
289     // increase modifications counter of this (main) shape
290     anObject->IncrementTic();
291   }
292   else {
293     // update modifications counter of this (sub-) shape to be the same as on main shape
294     GEOM_ISubShape aCI (this);
295     TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
296     if (aLabelObjMainSh.IsRoot()) return;
297     Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
298     if (anObjMainSh.IsNull()) return;
299
300     anObject->SetTic(anObjMainSh->GetTic());
301   }
302
303   _isDone = true;
304 }
305
306 //=============================================================================
307 /*!
308  *  GetDriverGUID
309  */
310 //=============================================================================
311 Standard_GUID GEOM_Function::GetDriverGUID()
312 {
313   Handle(TFunction_Function) aFunction;
314   if(!_label.FindAttribute(TFunction_Function::GetID(), aFunction)) {
315     return TDF::LowestID();
316   }
317
318   return aFunction->GetDriverGUID();
319 }
320
321 //=============================================================================
322 /*!
323  *  GetDescription
324  */
325 //=============================================================================
326 TCollection_AsciiString GEOM_Function::GetDescription()
327 {
328   Handle(TDataStd_Comment) aComment;
329   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
330   if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return TCollection_AsciiString();
331   TCollection_AsciiString aDescr(aComment->Get());
332   return aDescr;
333 }
334
335 //=============================================================================
336 /*!
337  *  SetDescription
338  */
339 //=============================================================================
340 void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription)
341 {
342   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
343   Handle(TDataStd_Comment) aComment =
344     TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription));
345 }
346
347 //=============================================================================
348 /*!
349  *  SetReal
350  */
351 //=============================================================================
352 void GEOM_Function::SetReal(int thePosition, double theValue)
353 {
354   _isDone = false;
355   if(thePosition <= 0) return;
356   TDF_Label anArgLabel = ARGUMENT(thePosition);
357   TDataStd_Real::Set(anArgLabel, theValue);
358   _isDone = true;
359 }
360
361 //=============================================================================
362 /*!
363  *  SetRealArray
364  */
365 //=============================================================================
366 void GEOM_Function::SetRealArray (int thePosition,
367                                   const Handle(TColStd_HArray1OfReal)& theArray)
368 {
369   _isDone = false;
370   if(thePosition <= 0) return;
371   TDF_Label anArgLabel = ARGUMENT(thePosition);
372   Handle(TDataStd_RealArray) anAttr =
373     TDataStd_RealArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
374   anAttr->ChangeArray(theArray);
375   _isDone = true;
376 }
377
378 //=============================================================================
379 /*!
380  *  GetReal
381  */
382 //=============================================================================
383 double GEOM_Function::GetReal(int thePosition)
384 {
385   _isDone = false;
386   if(thePosition <= 0) return 0.0;
387   Handle(TDataStd_Real) aReal;
388   TDF_Label anArgLabel = ARGUMENT(thePosition);
389   if(!anArgLabel.FindAttribute(TDataStd_Real::GetID(), aReal)) return 0.0;
390
391   _isDone = true;
392   return aReal->Get();
393 }
394
395 //=============================================================================
396 /*!
397  *  GetRealArray
398  */
399 //=============================================================================
400 Handle(TColStd_HArray1OfReal) GEOM_Function::GetRealArray(int thePosition)
401 {
402   _isDone = false;
403   if(thePosition <= 0) return NULL;
404   Handle(TDataStd_RealArray) aRealArray;
405   TDF_Label anArgLabel = ARGUMENT(thePosition);
406   if(!anArgLabel.FindAttribute(TDataStd_RealArray::GetID(), aRealArray)) return NULL;
407
408   _isDone = true;
409   return aRealArray->Array();
410 }
411
412 //=============================================================================
413 /*!
414  *  SetInteger
415  */
416 //=============================================================================
417 void GEOM_Function::SetInteger(int thePosition, int theValue)
418 {
419   _isDone = false;
420   if(thePosition <= 0) return;
421   TDF_Label anArgLabel = ARGUMENT(thePosition);
422   TDataStd_Integer::Set(anArgLabel, theValue);
423   _isDone = true;
424 }
425
426 //=============================================================================
427 /*!
428  *  SetIntegerArray
429  */
430 //=============================================================================
431 void GEOM_Function::SetIntegerArray (int thePosition,
432                                      const Handle(TColStd_HArray1OfInteger)& theArray)
433 {
434   _isDone = false;
435   if(thePosition <= 0) return;
436   TDF_Label anArgLabel = ARGUMENT(thePosition);
437   Handle(TDataStd_IntegerArray) anAttr =
438     TDataStd_IntegerArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
439   anAttr->ChangeArray(theArray);
440   _isDone = true;
441 }
442
443 //=============================================================================
444 /*!
445  *  GetInteger
446  */
447 //=============================================================================
448 int GEOM_Function::GetInteger(int thePosition)
449 {
450   _isDone = false;
451   if(thePosition <= 0) return 0;
452   Handle(TDataStd_Integer) anInteger;
453   TDF_Label anArgLabel = ARGUMENT(thePosition);
454   if(!anArgLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) return 0;
455
456   _isDone = true;
457   return anInteger->Get();
458 }
459
460 //=============================================================================
461 /*!
462  *  GetIntegerArray
463  */
464 //=============================================================================
465 Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition)
466 {
467   _isDone = false;
468   if(thePosition <= 0) return 0;
469   Handle(TDataStd_IntegerArray) anIntegerArray;
470   TDF_Label anArgLabel = ARGUMENT(thePosition);
471   if(!anArgLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) return 0;
472
473   _isDone = true;
474   return anIntegerArray->Array();
475 }
476
477 //=============================================================================
478 /*!
479  *  SetString
480  */
481 //=============================================================================
482 void GEOM_Function::SetString(int thePosition, const TCollection_AsciiString& theValue)
483 {
484   _isDone = false;
485   if(thePosition <= 0) return;
486   TDF_Label anArgLabel = ARGUMENT(thePosition);
487   TDataStd_Comment::Set(anArgLabel, theValue);
488   _isDone = true;
489 }
490
491 //=============================================================================
492 /*!
493  *  GetString
494  */
495 //=============================================================================
496 TCollection_AsciiString GEOM_Function::GetString(int thePosition)
497 {
498   _isDone = false;
499   TCollection_AsciiString aRes;
500   if(thePosition <= 0) return aRes;
501   Handle(TDataStd_Comment) aString;
502   TDF_Label anArgLabel = ARGUMENT(thePosition);
503   if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
504
505   _isDone = true;
506   aRes = TCollection_AsciiString(aString->Get());
507   return aRes;
508 }
509
510 //=============================================================================
511 /*!
512  *  SetReference
513  */
514 //=============================================================================
515 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
516 {
517   _isDone = false;
518   if (thePosition <= 0) return;
519   if (theReference.IsNull()) return;
520   TDF_Label anArgLabel = ARGUMENT(thePosition);
521   TDF_Reference::Set(anArgLabel, theReference->GetEntry());
522   TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
523   _isDone = true;
524   return;
525 }
526
527 //=============================================================================
528 /*!
529  *  GetReference
530  */
531 //=============================================================================
532 Handle(GEOM_Function) GEOM_Function::GetReference(int thePosition)
533 {
534   _isDone = false;
535   if(thePosition <= 0) return NULL;
536   TDF_Label anArgLabel = ARGUMENT(thePosition);
537   Handle(TDF_Reference) aRef;
538   if(!anArgLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL;
539
540   _isDone = true;
541   return GetFunction(aRef->Get());
542 }
543
544
545 //=============================================================================
546 /*!
547  *  SetStringArray
548  */
549 //=============================================================================
550 void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1OfExtendedString)& theArray)
551 {
552   _isDone = false;
553   if(thePosition <= 0 || theArray.IsNull()) return;
554   TDF_Label anArgLabel = ARGUMENT(thePosition);
555
556   Handle(TDataStd_ExtStringArray) anArray =
557     TDataStd_ExtStringArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
558   anArray->ChangeArray(theArray);
559
560   _isDone = true;
561 }
562
563
564 //=============================================================================
565 /*!
566  *  GetStringArray
567  */
568 //=============================================================================
569 Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePosition)
570 {
571   _isDone = false;
572   if(thePosition <= 0) return NULL;
573   TDF_Label anArgLabel = ARGUMENT(thePosition);
574   Handle(TDataStd_ExtStringArray) anArray;
575   if(!anArgLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), anArray)) return NULL;
576
577   _isDone = true;
578   return anArray->Array();
579 }
580
581 //=======================================================================
582 //function : HasData
583 //purpose  : Returns true if data of given type already exists
584 //=======================================================================
585
586 bool GEOM_Function::HasData(int thePosition, const Standard_GUID& dataID)
587 {
588   if(thePosition <= 0) return false;
589   TDF_Label anArgLabel = ARGUMENT(thePosition);
590   return anArgLabel.IsAttribute( dataID );
591 }
592
593 //=======================================================================
594 //function : GetReferencesTreeID
595 //purpose  :
596 //=======================================================================
597 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
598 {
599   static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
600   return aReferencesTreeID;
601 }
602
603 //=============================================================================
604 /*!
605  *  SetReferenceList
606  */
607 //=============================================================================
608 void GEOM_Function::SetReferenceList (int thePosition,
609                                       const Handle(TColStd_HSequenceOfTransient)& theRefList)
610 {
611   _isDone = false;
612   if(thePosition <= 0) return;
613
614   // parent label for the list of references
615   TDF_Label anArgLabel = ARGUMENT(thePosition);
616   anArgLabel.ForgetAllAttributes();
617
618   // set TreeNode on the parent label
619   Handle(TDataStd_TreeNode) aRoot, aNode;
620   aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
621
622   // store references on sub-labels of the parent label
623   Handle(GEOM_Function) aFunc;
624   Standard_Integer ind, len = theRefList->Length();
625   for (ind = 1; ind <= len; ind++) {
626     aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
627     if (aFunc.IsNull()) continue;
628     TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
629     TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
630     TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
631
632     // set TreeNode on the child label
633     aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
634     aRoot->Append(aNode);
635   }
636
637   _isDone = true;
638   return;
639 }
640
641 //=============================================================================
642 /*!
643  *  GetReferenceList
644  */
645 //=============================================================================
646 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
647 {
648   Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
649   _isDone = false;
650   if(thePosition <= 0) return aResult;
651
652   // parent label for the list of references
653   TDF_Label anArgLabel = ARGUMENT(thePosition);
654   Handle(TDF_Reference) aRef;
655
656   // get TreeNode on the parent label
657   Handle(TDataStd_TreeNode) aRoot, aNode;
658   if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
659     return aResult;
660
661   // get references, stored on sub-labels of the parent label
662   TDF_Label aLabel_i;
663   TDataStd_ChildNodeIterator anIter (aRoot);
664   for (; anIter.More(); anIter.Next()) {
665     aNode = anIter.Value();
666     aLabel_i = aNode->Label();
667     if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
668     Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
669     if (aFunc_i.IsNull()) continue;
670     aResult->Append(aFunc_i);
671   }
672
673   _isDone = true;
674   return aResult;
675 }
676
677 //=============================================================================
678 /*!
679  *  SetShape
680  */
681 //=============================================================================
682 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
683 //{
684 //  _isDone = false;
685 //  if(thePosition <= 0 || theShape.IsNull()) return;
686 //
687 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
688 //  TNaming_Builder aBuilder(anArgLabel);
689 //  aBuilder.Generated(theShape);
690 //
691 //  _isDone = true;
692 //  return;
693 //}
694 //
695 //=============================================================================
696 /*!
697  *  GetShape
698  */
699 //=============================================================================
700 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
701 //{
702 //  _isDone = false;
703 //  TopoDS_Shape aShape;
704 //  if(thePosition <= 0) return aShape;
705 //
706 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
707 //  Handle(TNaming_NamedShape) aNS;
708 //  if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
709 //
710 //  aShape = aNS->Get();
711 //  _isDone = true;
712 //  return aShape;
713 //}
714
715
716 //=============================================================================
717 /*!
718  *  GetDependency
719  */
720 //=============================================================================
721 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
722 {
723   TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
724   for(; anIterator.More(); anIterator.Next()) {
725     if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
726   }
727 }
728
729 //=============================================================================
730 /*!
731  *  AddSubShapeReference
732  */
733 //=============================================================================
734 void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
735 {
736   _isDone = false;
737
738   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
739
740   Handle(TDataStd_ExtStringList) aList;
741   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
742     aList = new TDataStd_ExtStringList;
743     aSubShapesLabel.AddAttribute(aList);
744   }
745
746   TCollection_AsciiString anEntry;
747   TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
748   aList->Append(anEntry);
749
750   _isDone = true;
751 }
752
753 //=============================================================================
754 /*!
755  *  RemoveSubShapeReference
756  */
757 //=============================================================================
758 void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape)
759 {
760   _isDone = false;
761
762   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
763
764   Handle(TDataStd_ExtStringList) aList;
765   if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
766     TCollection_AsciiString anEntry;
767     TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
768     aList->Remove(anEntry);
769   }
770
771   _isDone = true;
772 }
773
774 //=============================================================================
775 /*!
776  *  HasSubShapeReferences
777  */
778 //=============================================================================
779 bool GEOM_Function::HasSubShapeReferences()
780 {
781   _isDone = true;
782
783   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
784   return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID());
785 }
786
787 //=============================================================================
788 /*!
789  *  GetSubShapeReferences
790  */
791 //=============================================================================
792 const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
793 {
794   _isDone = false;
795
796   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
797
798   Handle(TDataStd_ExtStringList) aList;
799   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
800     aList = new TDataStd_ExtStringList;
801     aSubShapesLabel.AddAttribute(aList);
802   }
803
804   _isDone = true;
805   return aList->List();
806 }
807
808 //=============================================================================
809 /*!
810  *  GetHistoryEntry
811  */
812 //=============================================================================
813 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
814 {
815   return _label.FindChild(HISTORY_LABEL, create);
816 }
817
818 //=============================================================================
819 /*!
820  *  GetArgumentHistoryEntry
821  */
822 //=============================================================================
823 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label&       theArgumentRefEntry,
824                                                   const Standard_Boolean create)
825 {
826   TColStd_ListOfInteger anArgumentRefTags;
827   TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
828   Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
829
830   TDF_Label aHistoryLabel = GetHistoryEntry(create);
831   if (aHistoryLabel.IsNull())
832     return aHistoryLabel;
833   Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
834
835   Standard_Integer itag;
836   TDF_Label aHistoryCurLabel = aHistoryLabel;
837   TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
838   for (itag = 1; itag <= aHistoryLabelPos; itag++) {
839     aListIter.Next();
840   }
841   for (; itag <= anArgumentRefLabelPos; itag++) {
842     aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
843     if (aHistoryCurLabel.IsNull())
844       return aHistoryCurLabel;
845     aListIter.Next();
846   }
847
848   return aHistoryCurLabel;
849 }
850
851 //=============================================================================
852 /*!
853  *  GetNamingEntry
854  */
855 //=============================================================================
856 TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
857 {
858   return _label.FindChild(NAMING_LABEL, create);
859 }
860
861 IMPLEMENT_STANDARD_HANDLE (GEOM_Function, Standard_Transient);
862 IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );