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