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