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