Salome HOME
0022661: EDF GEOM: [HYDRO] Integration of the polyline editor in GEOM
[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_BooleanArray.hxx>
40 #include <TDataStd_ByteArray.hxx>
41 #include <TDataStd_Integer.hxx>
42 #include <TDataStd_IntegerArray.hxx>
43 #include <TDataStd_Real.hxx>
44 #include <TDataStd_RealArray.hxx>
45 #include <TDataStd_Comment.hxx>
46 #include <TDataStd_TreeNode.hxx>
47 #include <TDataStd_UAttribute.hxx>
48 #include <TDataStd_ChildNodeIterator.hxx>
49 #include <TDataStd_ExtStringArray.hxx>
50 #include <TDataStd_ExtStringList.hxx>
51 #include <TDocStd_Owner.hxx>
52 #include <TDocStd_Document.hxx>
53 #include <TFunction_Function.hxx>
54 #include <TNaming_NamedShape.hxx>
55 #include <TNaming_Builder.hxx>
56
57 #include <TColStd_ListOfInteger.hxx>
58 #include <TColStd_ListIteratorOfListOfInteger.hxx>
59 #include <TColStd_HArray1OfReal.hxx>
60 #include <TColStd_HArray1OfInteger.hxx>
61 #include <TColStd_HSequenceOfTransient.hxx>
62 #include <TCollection_AsciiString.hxx>
63 #include <TCollection_ExtendedString.hxx>
64
65 #include <Standard_Failure.hxx>
66 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
67
68 // This modification was introduced in frame of Mantis issue 0021251.
69 // This line allows to keep shape orientation together with the shape itself.
70 // Otherwise orientation can be lost in some cases.
71 #define KEEP_ORIENTATION_0021251
72
73 #define ARGUMENT_LABEL 1
74 #define RESULT_LABEL 2
75 #define DESCRIPTION_LABEL 3
76 #define HISTORY_LABEL 4
77 #define SUBSHAPES_LABEL 5 // 0020756: GetGroups
78 #define NAMING_LABEL 6 // 0020750: Naming during STEP import
79
80 #ifdef KEEP_ORIENTATION_0021251
81 #define ORIENTATION_LABEL 7 // 0021251: TNaming_NamedShape doesn't store orientation
82 #endif
83
84 #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
85 #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
86 #define SUB_ARGUMENT(thePos1, thePos2) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePos1)).FindChild((thePos2))
87
88 //=======================================================================
89 //function : GetFunctionTreeID
90 //purpose  :
91 //=======================================================================
92 const Standard_GUID& GEOM_Function::GetFunctionTreeID()
93 {
94   static Standard_GUID aFunctionTreeID("FF1BBB00-5D14-4df2-980B-3A668264EA16");
95   return aFunctionTreeID;
96 }
97
98
99 //=======================================================================
100 //function : GetDependencyID
101 //purpose  :
102 //=======================================================================
103 const Standard_GUID& GEOM_Function::GetDependencyID()
104 {
105   static Standard_GUID aDependencyID("E2620650-2354-41bd-8C2C-210CFCD00948");
106   return aDependencyID;
107 }
108
109 //=============================================================================
110 /*!
111  *  GetFunction:
112  */
113 //=============================================================================
114 Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry)
115 {
116   if(!theEntry.IsAttribute(TFunction_Function::GetID())) return NULL;
117
118   return new GEOM_Function(theEntry);
119 }
120
121 //=============================================================================
122 /*!
123  *  Constructor:
124  */
125 //=============================================================================
126 GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType)
127 : _label(theEntry)
128 {
129   TFunction_Function::Set(theEntry, theGUID);
130   TDataStd_Integer::Set(theEntry, theType);
131
132   //Add function to a function tree
133   Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(theEntry.Data());
134   Handle(TDataStd_TreeNode) aRoot, aNode;
135   if(!aDoc->Main().FindAttribute(GetFunctionTreeID(), aRoot))
136     aRoot = TDataStd_TreeNode::Set(aDoc->Main(), GetFunctionTreeID());
137
138   aNode = TDataStd_TreeNode::Set(theEntry, GetFunctionTreeID());
139   aRoot->Append(aNode);
140 }
141
142 //================================================================================
143 /*!
144  * \brief Retuns true if this function is the last one in the study
145  */
146 //================================================================================
147
148 bool GEOM_Function::IsLastFuntion()
149 {
150   bool isLast = false;
151
152   Handle(TDataStd_TreeNode) aNode;
153   if (_label.FindAttribute(GetFunctionTreeID(), aNode))
154     isLast = !aNode->HasNext();
155
156   return isLast;
157 }
158
159 //=============================================================================
160 /*!
161  *  GetOwner
162  */
163 //=============================================================================
164 TDF_Label GEOM_Function::GetOwnerEntry()
165 {
166   TDF_Label aFather = _label.Father();
167   while(!aFather.IsRoot()) {
168     if(aFather.IsAttribute(GEOM_Object::GetObjectID())) return aFather;
169     aFather = aFather.Father();
170   }
171
172   return TDF_Label();
173 }
174
175 //=============================================================================
176 /*!
177  *  GetType
178  */
179 //=============================================================================
180 int GEOM_Function::GetType()
181 {
182   _isDone = false;
183   Handle(TDataStd_Integer) aType;
184   if(!_label.FindAttribute(TDataStd_Integer::GetID(), aType)) return 0;
185   _isDone = true;
186   return aType->Get();
187 }
188
189 //=============================================================================
190 /*!
191  *  GetValue
192  */
193 //=============================================================================
194 TopoDS_Shape GEOM_Function::GetValue()
195 {
196   _isDone = false;
197
198   TopoDS_Shape aShape;
199   TDF_Label aLabel = GetOwnerEntry();
200   if (aLabel.IsRoot()) return aShape;
201   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
202   if (anObject.IsNull()) return aShape;
203
204   if (!anObject->IsMainShape()) {
205     bool isResult = false;
206     TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
207     if (!aResultLabel.IsNull()) {
208       Handle(TNaming_NamedShape) aNS;
209       if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
210         isResult = true;
211     }
212
213     // compare tics
214     if (isResult) {
215       // tic of this
216       Standard_Integer aTic = anObject->GetTic();
217
218       // tic of main shape
219       GEOM_ISubShape aCI (this);
220       TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
221       if (aLabelObjMainSh.IsRoot()) return aShape;
222       Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
223       if (anObjMainSh.IsNull()) return aShape;
224       Standard_Integer aTicMainSh = anObjMainSh->GetTic();
225
226       // compare
227       isResult = ((aTic == aTicMainSh) ? true : false);
228     }
229
230     if (!isResult) {
231       try {
232         OCC_CATCH_SIGNALS;
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  *  SetByteArray
482  */
483 //=============================================================================
484 void GEOM_Function::SetByteArray (int thePosition,
485                                   const Handle(TColStd_HArray1OfByte)& theArray)
486 {
487   _isDone = false;
488   if(thePosition <= 0) return;
489   TDF_Label anArgLabel = ARGUMENT(thePosition);
490   Handle(TDataStd_ByteArray) anAttr =
491     TDataStd_ByteArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
492   anAttr->ChangeArray(theArray);
493   _isDone = true;
494 }
495
496 //=============================================================================
497 /*!
498  *  GetByteArray
499  */
500 //=============================================================================
501 Handle(TColStd_HArray1OfByte) GEOM_Function::GetByteArray(int thePosition)
502 {
503   _isDone = false;
504   if(thePosition <= 0) return 0;
505   Handle(TDataStd_ByteArray) aByteArray;
506   TDF_Label anArgLabel = ARGUMENT(thePosition);
507   if(!anArgLabel.FindAttribute(TDataStd_ByteArray::GetID(), aByteArray)) return 0;
508
509   _isDone = true;
510   return aByteArray->InternalArray();
511 }
512
513 //=============================================================================
514 /*!
515  *  SetBooleanArray
516  */
517 //=============================================================================
518 void GEOM_Function::SetBooleanArray (int thePosition,
519                                      const Handle(TColStd_HArray1OfByte)& theArray)
520 {
521   _isDone = false;
522   if(thePosition <= 0) return;
523   TDF_Label anArgLabel = ARGUMENT(thePosition);
524   Handle(TDataStd_BooleanArray) anAttr =
525     TDataStd_BooleanArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
526   anAttr->SetInternalArray(theArray);
527   _isDone = true;
528 }
529
530 //=============================================================================
531 /*!
532  *  GetBooleanArray
533  */
534 //=============================================================================
535 Handle(TColStd_HArray1OfByte) GEOM_Function::GetBooleanArray(int thePosition)
536 {
537   _isDone = false;
538   if(thePosition <= 0) return 0;
539   Handle(TDataStd_BooleanArray) aBooleanArray;
540   TDF_Label anArgLabel = ARGUMENT(thePosition);
541   if(!anArgLabel.FindAttribute(TDataStd_BooleanArray::GetID(), aBooleanArray)) return 0;
542
543   _isDone = true;
544   return aBooleanArray->InternalArray();
545 }
546
547 //=============================================================================
548 /*!
549  *  SetString
550  */
551 //=============================================================================
552 void GEOM_Function::SetString(int thePosition, const TCollection_AsciiString& theValue)
553 {
554   _isDone = false;
555   if(thePosition <= 0) return;
556   TDF_Label anArgLabel = ARGUMENT(thePosition);
557   TDataStd_Comment::Set(anArgLabel, theValue);
558   _isDone = true;
559 }
560
561 //=============================================================================
562 /*!
563  *  GetString
564  */
565 //=============================================================================
566 TCollection_AsciiString GEOM_Function::GetString(int thePosition)
567 {
568   _isDone = false;
569   TCollection_AsciiString aRes;
570   if(thePosition <= 0) return aRes;
571   Handle(TDataStd_Comment) aString;
572   TDF_Label anArgLabel = ARGUMENT(thePosition);
573   if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
574
575   _isDone = true;
576   aRes = TCollection_AsciiString(aString->Get());
577   return aRes;
578 }
579
580 //=============================================================================
581 /*!
582  *  SetReference
583  */
584 //=============================================================================
585 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
586 {
587   _isDone = false;
588   if (thePosition <= 0) return;
589   if (theReference.IsNull()) return;
590   TDF_Label anArgLabel = ARGUMENT(thePosition);
591   TDF_Reference::Set(anArgLabel, theReference->GetEntry());
592   TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
593   _isDone = true;
594   return;
595 }
596
597 //=============================================================================
598 /*!
599  *  GetReference
600  */
601 //=============================================================================
602 Handle(GEOM_Function) GEOM_Function::GetReference(int thePosition)
603 {
604   _isDone = false;
605   if(thePosition <= 0) return NULL;
606   TDF_Label anArgLabel = ARGUMENT(thePosition);
607   Handle(TDF_Reference) aRef;
608   if(!anArgLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL;
609
610   _isDone = true;
611   return GetFunction(aRef->Get());
612 }
613
614
615 //=============================================================================
616 /*!
617  *  SetStringArray
618  */
619 //=============================================================================
620 void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1OfExtendedString)& theArray)
621 {
622   _isDone = false;
623   if(thePosition <= 0 || theArray.IsNull()) return;
624   TDF_Label anArgLabel = ARGUMENT(thePosition);
625
626   Handle(TDataStd_ExtStringArray) anArray =
627     TDataStd_ExtStringArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
628   anArray->ChangeArray(theArray);
629
630   _isDone = true;
631 }
632
633
634 //=============================================================================
635 /*!
636  *  GetStringArray
637  */
638 //=============================================================================
639 Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePosition)
640 {
641   _isDone = false;
642   if(thePosition <= 0) return NULL;
643   TDF_Label anArgLabel = ARGUMENT(thePosition);
644   Handle(TDataStd_ExtStringArray) anArray;
645   if(!anArgLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), anArray)) return NULL;
646
647   _isDone = true;
648   return anArray->Array();
649 }
650
651 //=======================================================================
652 //function : HasData
653 //purpose  : Returns true if data of given type already exists
654 //=======================================================================
655
656 bool GEOM_Function::HasData(int thePosition, const Standard_GUID& dataID)
657 {
658   if(thePosition <= 0) return false;
659   TDF_Label anArgLabel = ARGUMENT(thePosition);
660   return anArgLabel.IsAttribute( dataID );
661 }
662
663 //=======================================================================
664 //function : GetReferencesTreeID
665 //purpose  :
666 //=======================================================================
667 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
668 {
669   static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
670   return aReferencesTreeID;
671 }
672
673 //=============================================================================
674 /*!
675  *  SetReferenceList
676  */
677 //=============================================================================
678 void GEOM_Function::SetReferenceList (int thePosition,
679                                       const Handle(TColStd_HSequenceOfTransient)& theRefList)
680 {
681   _isDone = false;
682   if(thePosition <= 0) return;
683
684   // parent label for the list of references
685   TDF_Label anArgLabel = ARGUMENT(thePosition);
686   anArgLabel.ForgetAllAttributes();
687
688   // set TreeNode on the parent label
689   Handle(TDataStd_TreeNode) aRoot, aNode;
690   aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
691
692   // store references on sub-labels of the parent label
693   Handle(GEOM_Function) aFunc;
694   Standard_Integer ind, len = theRefList->Length();
695   for (ind = 1; ind <= len; ind++) {
696     aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
697     if (aFunc.IsNull()) continue;
698     TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
699     TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
700     TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
701
702     // set TreeNode on the child label
703     aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
704     aRoot->Append(aNode);
705   }
706
707   _isDone = true;
708   return;
709 }
710
711 //=============================================================================
712 /*!
713  *  GetReferenceList
714  */
715 //=============================================================================
716 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
717 {
718   Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
719   _isDone = false;
720   if(thePosition <= 0) return aResult;
721
722   // parent label for the list of references
723   TDF_Label anArgLabel = ARGUMENT(thePosition);
724   Handle(TDF_Reference) aRef;
725
726   // get TreeNode on the parent label
727   Handle(TDataStd_TreeNode) aRoot, aNode;
728   if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
729     return aResult;
730
731   // get references, stored on sub-labels of the parent label
732   TDF_Label aLabel_i;
733   TDataStd_ChildNodeIterator anIter (aRoot);
734   for (; anIter.More(); anIter.Next()) {
735     aNode = anIter.Value();
736     aLabel_i = aNode->Label();
737     if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
738     Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
739     if (aFunc_i.IsNull()) continue;
740     aResult->Append(aFunc_i);
741   }
742
743   _isDone = true;
744   return aResult;
745 }
746
747 //=============================================================================
748 /*!
749  *  SetShape
750  */
751 //=============================================================================
752 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
753 //{
754 //  _isDone = false;
755 //  if(thePosition <= 0 || theShape.IsNull()) return;
756 //
757 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
758 //  TNaming_Builder aBuilder(anArgLabel);
759 //  aBuilder.Generated(theShape);
760 //
761 //  _isDone = true;
762 //  return;
763 //}
764 //
765 //=============================================================================
766 /*!
767  *  GetShape
768  */
769 //=============================================================================
770 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
771 //{
772 //  _isDone = false;
773 //  TopoDS_Shape aShape;
774 //  if(thePosition <= 0) return aShape;
775 //
776 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
777 //  Handle(TNaming_NamedShape) aNS;
778 //  if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
779 //
780 //  aShape = aNS->Get();
781 //  _isDone = true;
782 //  return aShape;
783 //}
784
785
786 //=============================================================================
787 /*!
788  *  GetDependency
789  */
790 //=============================================================================
791 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
792 {
793   TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
794   for(; anIterator.More(); anIterator.Next()) {
795     if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
796   }
797 }
798
799 //=============================================================================
800 /*!
801  *  AddSubShapeReference
802  */
803 //=============================================================================
804 void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
805 {
806   _isDone = false;
807
808   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
809
810   Handle(TDataStd_ExtStringList) aList;
811   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
812     aList = new TDataStd_ExtStringList;
813     aSubShapesLabel.AddAttribute(aList);
814   }
815
816   TCollection_AsciiString anEntry;
817   TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
818   aList->Append(anEntry);
819
820   _isDone = true;
821 }
822
823 //=============================================================================
824 /*!
825  *  RemoveSubShapeReference
826  */
827 //=============================================================================
828 void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape)
829 {
830   _isDone = false;
831
832   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
833
834   Handle(TDataStd_ExtStringList) aList;
835   if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
836     TCollection_AsciiString anEntry;
837     TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
838     aList->Remove(anEntry);
839   }
840
841   _isDone = true;
842 }
843
844 //=============================================================================
845 /*!
846  *  HasSubShapeReferences
847  */
848 //=============================================================================
849 bool GEOM_Function::HasSubShapeReferences()
850 {
851   _isDone = true;
852
853   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
854   return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID());
855 }
856
857 //=============================================================================
858 /*!
859  *  GetSubShapeReferences
860  */
861 //=============================================================================
862 const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
863 {
864   _isDone = false;
865
866   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
867
868   Handle(TDataStd_ExtStringList) aList;
869   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
870     aList = new TDataStd_ExtStringList;
871     aSubShapesLabel.AddAttribute(aList);
872   }
873
874   _isDone = true;
875   return aList->List();
876 }
877
878 //=============================================================================
879 /*!
880  *  GetHistoryEntry
881  */
882 //=============================================================================
883 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
884 {
885   return _label.FindChild(HISTORY_LABEL, create);
886 }
887
888 //=============================================================================
889 /*!
890  *  GetArgumentHistoryEntry
891  */
892 //=============================================================================
893 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label&       theArgumentRefEntry,
894                                                   const Standard_Boolean create)
895 {
896   TColStd_ListOfInteger anArgumentRefTags;
897   TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
898   Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
899
900   TDF_Label aHistoryLabel = GetHistoryEntry(create);
901   if (aHistoryLabel.IsNull())
902     return aHistoryLabel;
903   Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
904
905   Standard_Integer itag;
906   TDF_Label aHistoryCurLabel = aHistoryLabel;
907   TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
908   for (itag = 1; itag <= aHistoryLabelPos; itag++) {
909     aListIter.Next();
910   }
911   for (; itag <= anArgumentRefLabelPos; itag++) {
912     aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
913     if (aHistoryCurLabel.IsNull())
914       return aHistoryCurLabel;
915     aListIter.Next();
916   }
917
918   return aHistoryCurLabel;
919 }
920
921 //=============================================================================
922 /*!
923  *  GetNamingEntry
924  */
925 //=============================================================================
926 TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
927 {
928   return _label.FindChild(NAMING_LABEL, create);
929 }
930
931 IMPLEMENT_STANDARD_HANDLE (GEOM_Function, Standard_Transient);
932 IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );