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