Back to index

salome-geom  6.5.0
GEOM_Function.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOM_Function.hxx>
00026 #include <GEOM_Object.hxx>
00027 #include <GEOM_Solver.hxx>
00028 #include <GEOM_ISubShape.hxx>
00029 
00030 #include <Basics_OCCTVersion.hxx>
00031 
00032 #include "utilities.h"
00033 
00034 #include <TDF.hxx>
00035 #include <TDF_Tool.hxx>
00036 #include <TDF_Data.hxx>
00037 #include <TDF_ChildIterator.hxx>
00038 #include <TDF_Reference.hxx>
00039 #include <TDataStd_Integer.hxx>
00040 #include <TDataStd_IntegerArray.hxx>
00041 #include <TDataStd_Real.hxx>
00042 #include <TDataStd_RealArray.hxx>
00043 #include <TDataStd_Comment.hxx>
00044 #include <TDataStd_TreeNode.hxx>
00045 #include <TDataStd_UAttribute.hxx>
00046 #include <TDataStd_ChildNodeIterator.hxx>
00047 #include <TDataStd_ExtStringArray.hxx>
00048 #include <TDataStd_ExtStringList.hxx>
00049 #include <TDocStd_Owner.hxx>
00050 #include <TDocStd_Document.hxx>
00051 #include <TFunction_Function.hxx>
00052 #include <TNaming_NamedShape.hxx>
00053 #include <TNaming_Builder.hxx>
00054 
00055 #include <TColStd_ListOfInteger.hxx>
00056 #include <TColStd_ListIteratorOfListOfInteger.hxx>
00057 #include <TColStd_HArray1OfReal.hxx>
00058 #include <TColStd_HArray1OfInteger.hxx>
00059 #include <TColStd_HSequenceOfTransient.hxx>
00060 #include <TCollection_AsciiString.hxx>
00061 #include <TCollection_ExtendedString.hxx>
00062 
00063 #include <Standard_Failure.hxx>
00064 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
00065 
00066 // This modification was introduced in frame of Mantis issue 0021251.
00067 // This line allows to keep shape orientation together with the shape itself.
00068 // Otherwise orientation can be lost in some cases.
00069 #define KEEP_ORIENTATION_0021251
00070 
00071 #define ARGUMENT_LABEL 1
00072 #define RESULT_LABEL 2
00073 #define DESCRIPTION_LABEL 3
00074 #define HISTORY_LABEL 4
00075 #define SUBSHAPES_LABEL 5 // 0020756: GetGroups
00076 #define NAMING_LABEL 6 // 0020750: Naming during STEP import
00077 
00078 #ifdef KEEP_ORIENTATION_0021251
00079 #define ORIENTATION_LABEL 7 // 0021251: TNaming_NamedShape doesn't store orientation
00080 #endif
00081 
00082 #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
00083 #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
00084 #define SUB_ARGUMENT(thePos1, thePos2) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePos1)).FindChild((thePos2))
00085 
00086 //=======================================================================
00087 //function : GetFunctionTreeID
00088 //purpose  :
00089 //=======================================================================
00090 const Standard_GUID& GEOM_Function::GetFunctionTreeID()
00091 {
00092   static Standard_GUID aFunctionTreeID("FF1BBB00-5D14-4df2-980B-3A668264EA16");
00093   return aFunctionTreeID;
00094 }
00095 
00096 
00097 //=======================================================================
00098 //function : GetDependencyID
00099 //purpose  :
00100 //=======================================================================
00101 const Standard_GUID& GEOM_Function::GetDependencyID()
00102 {
00103   static Standard_GUID aDependencyID("E2620650-2354-41bd-8C2C-210CFCD00948");
00104   return aDependencyID;
00105 }
00106 
00107 //=============================================================================
00111 //=============================================================================
00112 Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry)
00113 {
00114   if(!theEntry.IsAttribute(TFunction_Function::GetID())) return NULL;
00115 
00116   return new GEOM_Function(theEntry);
00117 }
00118 
00119 //=============================================================================
00123 //=============================================================================
00124 GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType)
00125 : _label(theEntry)
00126 {
00127   TFunction_Function::Set(theEntry, theGUID);
00128   TDataStd_Integer::Set(theEntry, theType);
00129 
00130   //Add function to a function tree
00131   Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(theEntry.Data());
00132   Handle(TDataStd_TreeNode) aRoot, aNode;
00133   if(!aDoc->Main().FindAttribute(GetFunctionTreeID(), aRoot))
00134     aRoot = TDataStd_TreeNode::Set(aDoc->Main(), GetFunctionTreeID());
00135 
00136   aNode = TDataStd_TreeNode::Set(theEntry, GetFunctionTreeID());
00137   aRoot->Append(aNode);
00138 }
00139 
00140 //=============================================================================
00144 //=============================================================================
00145 TDF_Label GEOM_Function::GetOwnerEntry()
00146 {
00147   TDF_Label aFather = _label.Father();
00148   while(!aFather.IsRoot()) {
00149     if(aFather.IsAttribute(GEOM_Object::GetObjectID())) return aFather;
00150     aFather = aFather.Father();
00151   }
00152 
00153   return TDF_Label();
00154 }
00155 
00156 //=============================================================================
00160 //=============================================================================
00161 int GEOM_Function::GetType()
00162 {
00163   _isDone = false;
00164   Handle(TDataStd_Integer) aType;
00165   if(!_label.FindAttribute(TDataStd_Integer::GetID(), aType)) return 0;
00166   _isDone = true;
00167   return aType->Get();
00168 }
00169 
00170 //=============================================================================
00174 //=============================================================================
00175 TopoDS_Shape GEOM_Function::GetValue()
00176 {
00177   _isDone = false;
00178 
00179   TopoDS_Shape aShape;
00180   TDF_Label aLabel = GetOwnerEntry();
00181   if (aLabel.IsRoot()) return aShape;
00182   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
00183   if (anObject.IsNull()) return aShape;
00184 
00185   if (!anObject->IsMainShape()) {
00186     bool isResult = false;
00187     TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
00188     if (!aResultLabel.IsNull()) {
00189       Handle(TNaming_NamedShape) aNS;
00190       if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
00191         isResult = true;
00192     }
00193 
00194     // compare tics
00195     if (isResult) {
00196       // tic of this
00197       Standard_Integer aTic = anObject->GetTic();
00198 
00199       // tic of main shape
00200       GEOM_ISubShape aCI (this);
00201       TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
00202       if (aLabelObjMainSh.IsRoot()) return aShape;
00203       Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
00204       if (anObjMainSh.IsNull()) return aShape;
00205       Standard_Integer aTicMainSh = anObjMainSh->GetTic();
00206 
00207       // compare
00208       isResult = ((aTic == aTicMainSh) ? true : false);
00209     }
00210 
00211     if (!isResult) {
00212       try {
00213 #if OCC_VERSION_LARGE > 0x06010000
00214         OCC_CATCH_SIGNALS;
00215 #endif
00216         GEOM_Solver aSolver(GEOM_Engine::GetEngine());
00217         if (!aSolver.ComputeFunction(this)) {
00218           MESSAGE("GEOM_Object::GetValue Error : Can't build a sub-shape");
00219           return aShape;
00220         }
00221       }
00222       catch (Standard_Failure) {
00223         Handle(Standard_Failure) aFail = Standard_Failure::Caught();
00224         MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
00225         return aShape;
00226       }
00227     }
00228   }
00229 
00230   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
00231   Handle(TNaming_NamedShape) aNS;
00232   if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
00233 
00234   aShape = aNS->Get();
00235 
00236 #ifdef KEEP_ORIENTATION_0021251
00237   // 0021251: TNaming_NamedShape doesn't store orientation
00238   TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
00239   Handle(TDataStd_Integer) anInteger;
00240   if (anOrientationLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) {
00241     aShape.Orientation((TopAbs_Orientation)anInteger->Get());
00242   }
00243 #endif
00244 
00245   _isDone = true;
00246   return aShape;
00247 }
00248 
00249 //=============================================================================
00253 //=============================================================================
00254 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
00255 {
00256   _isDone = false;
00257   TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
00258   TNaming_Builder aBuilder (aResultLabel);
00259 
00260   aBuilder.Generated(theShape);
00261 
00262 #ifdef KEEP_ORIENTATION_0021251
00263   // 0021251: TNaming_NamedShape doesn't store orientation
00264   TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
00265   TDataStd_Integer::Set(anOrientationLabel, (int)theShape.Orientation());
00266 #endif
00267 
00268   // synchronisation between main shape and its sub-shapes
00269   TDF_Label aLabel = GetOwnerEntry();
00270   if (aLabel.IsRoot()) return;
00271   Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
00272   if (anObject.IsNull()) return;
00273   if (anObject->IsMainShape()) {
00274     // increase modifications counter of this (main) shape
00275     anObject->IncrementTic();
00276   }
00277   else {
00278     // update modifications counter of this (sub-) shape to be the same as on main shape
00279     GEOM_ISubShape aCI (this);
00280     TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
00281     if (aLabelObjMainSh.IsRoot()) return;
00282     Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
00283     if (anObjMainSh.IsNull()) return;
00284 
00285     anObject->SetTic(anObjMainSh->GetTic());
00286   }
00287 
00288   _isDone = true;
00289 }
00290 
00291 //=============================================================================
00295 //=============================================================================
00296 Standard_GUID GEOM_Function::GetDriverGUID()
00297 {
00298   Handle(TFunction_Function) aFunction;
00299   if(!_label.FindAttribute(TFunction_Function::GetID(), aFunction)) {
00300     return TDF::LowestID();
00301   }
00302 
00303   return aFunction->GetDriverGUID();
00304 }
00305 
00306 //=============================================================================
00310 //=============================================================================
00311 TCollection_AsciiString GEOM_Function::GetDescription()
00312 {
00313   Handle(TDataStd_Comment) aComment;
00314   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
00315   if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return TCollection_AsciiString();
00316   TCollection_AsciiString aDescr(aComment->Get());
00317   return aDescr;
00318 }
00319 
00320 //=============================================================================
00324 //=============================================================================
00325 void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription)
00326 {
00327   TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
00328   Handle(TDataStd_Comment) aComment =
00329     TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription));
00330 }
00331 
00332 //=============================================================================
00336 //=============================================================================
00337 void GEOM_Function::SetReal(int thePosition, double theValue)
00338 {
00339   _isDone = false;
00340   if(thePosition <= 0) return;
00341   TDF_Label anArgLabel = ARGUMENT(thePosition);
00342   TDataStd_Real::Set(anArgLabel, theValue);
00343   _isDone = true;
00344 }
00345 
00346 //=============================================================================
00350 //=============================================================================
00351 void GEOM_Function::SetRealArray (int thePosition,
00352                                   const Handle(TColStd_HArray1OfReal)& theArray)
00353 {
00354   _isDone = false;
00355   if(thePosition <= 0) return;
00356   TDF_Label anArgLabel = ARGUMENT(thePosition);
00357   Handle(TDataStd_RealArray) anAttr =
00358     TDataStd_RealArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
00359   anAttr->ChangeArray(theArray);
00360   _isDone = true;
00361 }
00362 
00363 //=============================================================================
00367 //=============================================================================
00368 double GEOM_Function::GetReal(int thePosition)
00369 {
00370   _isDone = false;
00371   if(thePosition <= 0) return 0.0;
00372   Handle(TDataStd_Real) aReal;
00373   TDF_Label anArgLabel = ARGUMENT(thePosition);
00374   if(!anArgLabel.FindAttribute(TDataStd_Real::GetID(), aReal)) return 0.0;
00375 
00376   _isDone = true;
00377   return aReal->Get();
00378 }
00379 
00380 //=============================================================================
00384 //=============================================================================
00385 Handle(TColStd_HArray1OfReal) GEOM_Function::GetRealArray(int thePosition)
00386 {
00387   _isDone = false;
00388   if(thePosition <= 0) return NULL;
00389   Handle(TDataStd_RealArray) aRealArray;
00390   TDF_Label anArgLabel = ARGUMENT(thePosition);
00391   if(!anArgLabel.FindAttribute(TDataStd_RealArray::GetID(), aRealArray)) return NULL;
00392 
00393   _isDone = true;
00394   return aRealArray->Array();
00395 }
00396 
00397 //=============================================================================
00401 //=============================================================================
00402 void GEOM_Function::SetInteger(int thePosition, int theValue)
00403 {
00404   _isDone = false;
00405   if(thePosition <= 0) return;
00406   TDF_Label anArgLabel = ARGUMENT(thePosition);
00407   TDataStd_Integer::Set(anArgLabel, theValue);
00408   _isDone = true;
00409 }
00410 
00411 //=============================================================================
00415 //=============================================================================
00416 void GEOM_Function::SetIntegerArray (int thePosition,
00417                                      const Handle(TColStd_HArray1OfInteger)& theArray)
00418 {
00419   _isDone = false;
00420   if(thePosition <= 0) return;
00421   TDF_Label anArgLabel = ARGUMENT(thePosition);
00422   Handle(TDataStd_IntegerArray) anAttr =
00423     TDataStd_IntegerArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
00424   anAttr->ChangeArray(theArray);
00425   _isDone = true;
00426 }
00427 
00428 //=============================================================================
00432 //=============================================================================
00433 int GEOM_Function::GetInteger(int thePosition)
00434 {
00435   _isDone = false;
00436   if(thePosition <= 0) return 0;
00437   Handle(TDataStd_Integer) anInteger;
00438   TDF_Label anArgLabel = ARGUMENT(thePosition);
00439   if(!anArgLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) return 0;
00440 
00441   _isDone = true;
00442   return anInteger->Get();
00443 }
00444 
00445 //=============================================================================
00449 //=============================================================================
00450 Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition)
00451 {
00452   _isDone = false;
00453   if(thePosition <= 0) return 0;
00454   Handle(TDataStd_IntegerArray) anIntegerArray;
00455   TDF_Label anArgLabel = ARGUMENT(thePosition);
00456   if(!anArgLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) return 0;
00457 
00458   _isDone = true;
00459   return anIntegerArray->Array();
00460 }
00461 
00462 //=============================================================================
00466 //=============================================================================
00467 void GEOM_Function::SetString(int thePosition, const TCollection_AsciiString& theValue)
00468 {
00469   _isDone = false;
00470   if(thePosition <= 0) return;
00471   TDF_Label anArgLabel = ARGUMENT(thePosition);
00472   TDataStd_Comment::Set(anArgLabel, theValue);
00473   _isDone = true;
00474 }
00475 
00476 //=============================================================================
00480 //=============================================================================
00481 TCollection_AsciiString GEOM_Function::GetString(int thePosition)
00482 {
00483   _isDone = false;
00484   TCollection_AsciiString aRes;
00485   if(thePosition <= 0) return aRes;
00486   Handle(TDataStd_Comment) aString;
00487   TDF_Label anArgLabel = ARGUMENT(thePosition);
00488   if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
00489 
00490   _isDone = true;
00491   aRes = TCollection_AsciiString(aString->Get());
00492   return aRes;
00493 }
00494 
00495 //=============================================================================
00499 //=============================================================================
00500 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
00501 {
00502   _isDone = false;
00503   if (thePosition <= 0) return;
00504   if (theReference.IsNull()) return;
00505   TDF_Label anArgLabel = ARGUMENT(thePosition);
00506   TDF_Reference::Set(anArgLabel, theReference->GetEntry());
00507   TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
00508   _isDone = true;
00509   return;
00510 }
00511 
00512 //=============================================================================
00516 //=============================================================================
00517 Handle(GEOM_Function) GEOM_Function::GetReference(int thePosition)
00518 {
00519   _isDone = false;
00520   if(thePosition <= 0) return NULL;
00521   TDF_Label anArgLabel = ARGUMENT(thePosition);
00522   Handle(TDF_Reference) aRef;
00523   if(!anArgLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL;
00524 
00525   _isDone = true;
00526   return GetFunction(aRef->Get());
00527 }
00528 
00529 
00530 //=============================================================================
00534 //=============================================================================
00535 void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1OfExtendedString)& theArray)
00536 {
00537   _isDone = false;
00538   if(thePosition <= 0 || theArray.IsNull()) return;
00539   TDF_Label anArgLabel = ARGUMENT(thePosition);
00540 
00541   Handle(TDataStd_ExtStringArray) anArray = new TDataStd_ExtStringArray;
00542   anArray->ChangeArray(theArray);
00543   anArgLabel.AddAttribute(anArray);
00544 
00545   _isDone = true;
00546 }
00547 
00548 
00549 //=============================================================================
00553 //=============================================================================
00554 Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePosition)
00555 {
00556   _isDone = false;
00557   if(thePosition <= 0) return NULL;
00558   TDF_Label anArgLabel = ARGUMENT(thePosition);
00559   Handle(TDataStd_ExtStringArray) anArray;
00560   if(!anArgLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), anArray)) return NULL;
00561 
00562   _isDone = true;
00563   return anArray->Array();
00564 }
00565 
00566 //=======================================================================
00567 //function : GetReferencesTreeID
00568 //purpose  :
00569 //=======================================================================
00570 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
00571 {
00572   static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
00573   return aReferencesTreeID;
00574 }
00575 
00576 //=============================================================================
00580 //=============================================================================
00581 void GEOM_Function::SetReferenceList (int thePosition,
00582                                       const Handle(TColStd_HSequenceOfTransient)& theRefList)
00583 {
00584   _isDone = false;
00585   if(thePosition <= 0) return;
00586 
00587   // parent label for the list of references
00588   TDF_Label anArgLabel = ARGUMENT(thePosition);
00589   anArgLabel.ForgetAllAttributes();
00590 
00591   // set TreeNode on the parent label
00592   Handle(TDataStd_TreeNode) aRoot, aNode;
00593   aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
00594 
00595   // store references on sub-labels of the parent label
00596   Handle(GEOM_Function) aFunc;
00597   Standard_Integer ind, len = theRefList->Length();
00598   for (ind = 1; ind <= len; ind++) {
00599     aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
00600     if (aFunc.IsNull()) continue;
00601     TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
00602     TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
00603     TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
00604 
00605     // set TreeNode on the child label
00606     aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
00607     aRoot->Append(aNode);
00608   }
00609 
00610   _isDone = true;
00611   return;
00612 }
00613 
00614 //=============================================================================
00618 //=============================================================================
00619 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
00620 {
00621   Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
00622   _isDone = false;
00623   if(thePosition <= 0) return aResult;
00624 
00625   // parent label for the list of references
00626   TDF_Label anArgLabel = ARGUMENT(thePosition);
00627   Handle(TDF_Reference) aRef;
00628 
00629   // get TreeNode on the parent label
00630   Handle(TDataStd_TreeNode) aRoot, aNode;
00631   if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
00632     return aResult;
00633 
00634   // get references, stored on sub-labels of the parent label
00635   TDF_Label aLabel_i;
00636   TDataStd_ChildNodeIterator anIter (aRoot);
00637   for (; anIter.More(); anIter.Next()) {
00638     aNode = anIter.Value();
00639     aLabel_i = aNode->Label();
00640     if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
00641     Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
00642     if (aFunc_i.IsNull()) continue;
00643     aResult->Append(aFunc_i);
00644   }
00645 
00646   _isDone = true;
00647   return aResult;
00648 }
00649 
00650 //=============================================================================
00654 //=============================================================================
00655 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
00656 //{
00657 //  _isDone = false;
00658 //  if(thePosition <= 0 || theShape.IsNull()) return;
00659 //
00660 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
00661 //  TNaming_Builder aBuilder(anArgLabel);
00662 //  aBuilder.Generated(theShape);
00663 //
00664 //  _isDone = true;
00665 //  return;
00666 //}
00667 //
00668 //=============================================================================
00672 //=============================================================================
00673 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
00674 //{
00675 //  _isDone = false;
00676 //  TopoDS_Shape aShape;
00677 //  if(thePosition <= 0) return aShape;
00678 //
00679 //  TDF_Label anArgLabel = ARGUMENT(thePosition);
00680 //  Handle(TNaming_NamedShape) aNS;
00681 //  if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
00682 //
00683 //  aShape = aNS->Get();
00684 //  _isDone = true;
00685 //  return aShape;
00686 //}
00687 
00688 
00689 //=============================================================================
00693 //=============================================================================
00694 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
00695 {
00696   TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
00697   for(; anIterator.More(); anIterator.Next()) {
00698     if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
00699   }
00700 }
00701 
00702 //=============================================================================
00706 //=============================================================================
00707 void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
00708 {
00709   _isDone = false;
00710 
00711   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
00712 
00713   Handle(TDataStd_ExtStringList) aList;
00714   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
00715     aList = new TDataStd_ExtStringList;
00716     aSubShapesLabel.AddAttribute(aList);
00717   }
00718 
00719   TCollection_AsciiString anEntry;
00720   TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
00721   aList->Append(anEntry);
00722 
00723   _isDone = true;
00724 }
00725 
00726 //=============================================================================
00730 //=============================================================================
00731 void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape)
00732 {
00733   _isDone = false;
00734 
00735   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
00736 
00737   Handle(TDataStd_ExtStringList) aList;
00738   if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
00739     TCollection_AsciiString anEntry;
00740     TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
00741     aList->Remove(anEntry);
00742   }
00743 
00744   _isDone = true;
00745 }
00746 
00747 //=============================================================================
00751 //=============================================================================
00752 bool GEOM_Function::HasSubShapeReferences()
00753 {
00754   _isDone = true;
00755 
00756   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
00757   return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID());
00758 }
00759 
00760 //=============================================================================
00764 //=============================================================================
00765 const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
00766 {
00767   _isDone = false;
00768 
00769   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
00770 
00771   Handle(TDataStd_ExtStringList) aList;
00772   if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
00773     aList = new TDataStd_ExtStringList;
00774     aSubShapesLabel.AddAttribute(aList);
00775   }
00776 
00777   _isDone = true;
00778   return aList->List();
00779 }
00780 
00781 //=============================================================================
00785 //=============================================================================
00786 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
00787 {
00788   return _label.FindChild(HISTORY_LABEL, create);
00789 }
00790 
00791 //=============================================================================
00795 //=============================================================================
00796 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label&       theArgumentRefEntry,
00797                                                   const Standard_Boolean create)
00798 {
00799   TColStd_ListOfInteger anArgumentRefTags;
00800   TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
00801   Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
00802 
00803   TDF_Label aHistoryLabel = GetHistoryEntry(create);
00804   if (aHistoryLabel.IsNull())
00805     return aHistoryLabel;
00806   Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
00807 
00808   Standard_Integer itag;
00809   TDF_Label aHistoryCurLabel = aHistoryLabel;
00810   TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
00811   for (itag = 1; itag <= aHistoryLabelPos; itag++) {
00812     aListIter.Next();
00813   }
00814   for (; itag <= anArgumentRefLabelPos; itag++) {
00815     aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
00816     if (aHistoryCurLabel.IsNull())
00817       return aHistoryCurLabel;
00818     aListIter.Next();
00819   }
00820 
00821   return aHistoryCurLabel;
00822 }
00823 
00824 //=============================================================================
00828 //=============================================================================
00829 TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
00830 {
00831   return _label.FindChild(NAMING_LABEL, create);
00832 }
00833 
00834 //=======================================================================
00835 //function :  GEOM_Function_Type_
00836 //purpose  :
00837 //=======================================================================
00838 Standard_EXPORT Handle_Standard_Type& GEOM_Function_Type_()
00839 {
00840 
00841   static Handle_Standard_Type aType1 = STANDARD_TYPE(MMgt_TShared);
00842   if (aType1.IsNull()) aType1 = STANDARD_TYPE(MMgt_TShared);
00843   static Handle_Standard_Type aType2 = STANDARD_TYPE(Standard_Transient);
00844   if (aType2.IsNull()) aType2 = STANDARD_TYPE(Standard_Transient);
00845 
00846   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,NULL};
00847   static Handle_Standard_Type _aType = new Standard_Type("GEOM_Function",
00848                                                          sizeof(GEOM_Function),
00849                                                          1,
00850                                                          (Standard_Address)_Ancestors,
00851                                                          (Standard_Address)NULL);
00852 
00853   return _aType;
00854 }
00855 
00856 //=======================================================================
00857 //function : DownCast
00858 //purpose  :
00859 //=======================================================================
00860 
00861 const Handle(GEOM_Function) Handle(GEOM_Function)::DownCast(const Handle(Standard_Transient)& AnObject)
00862 {
00863   Handle(GEOM_Function) _anOtherObject;
00864 
00865   if (!AnObject.IsNull()) {
00866      if (AnObject->IsKind(STANDARD_TYPE(GEOM_Function))) {
00867        _anOtherObject = Handle(GEOM_Function)((Handle(GEOM_Function)&)AnObject);
00868      }
00869   }
00870 
00871   return _anOtherObject;
00872 }