1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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, or (at your option) any later version.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOM_Function.hxx>
26 #include <GEOM_Object.hxx>
27 #include <GEOM_Solver.hxx>
28 #include <GEOM_ISubShape.hxx>
30 #include <Basics_OCCTVersion.hxx>
32 #include "utilities.h"
35 #include <TDF_Tool.hxx>
36 #include <TDF_Data.hxx>
37 #include <TDF_ChildIterator.hxx>
38 #include <TDF_Reference.hxx>
39 #include <TDataStd_BooleanArray.hxx>
40 #include <TDataStd_ByteArray.hxx>
41 #include <TDataStd_Integer.hxx>
42 #include <TDataStd_IntegerArray.hxx>
43 #include <TDataStd_Real.hxx>
44 #include <TDataStd_RealArray.hxx>
45 #include <TDataStd_Comment.hxx>
46 #include <TDataStd_TreeNode.hxx>
47 #include <TDataStd_UAttribute.hxx>
48 #include <TDataStd_ChildNodeIterator.hxx>
49 #include <TDataStd_ExtStringArray.hxx>
50 #include <TDataStd_ExtStringList.hxx>
51 #include <TDocStd_Owner.hxx>
52 #include <TDocStd_Document.hxx>
53 #include <TFunction_Function.hxx>
54 #include <TNaming_NamedShape.hxx>
55 #include <TNaming_Builder.hxx>
57 #include <TColStd_ListOfInteger.hxx>
58 #include <TColStd_ListIteratorOfListOfInteger.hxx>
59 #include <TColStd_HArray1OfReal.hxx>
60 #include <TColStd_HArray1OfInteger.hxx>
61 #include <TColStd_HSequenceOfTransient.hxx>
62 #include <TCollection_AsciiString.hxx>
63 #include <TCollection_ExtendedString.hxx>
67 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
70 // This modification was introduced in frame of Mantis issue 0021251.
71 // This line allows to keep shape orientation together with the shape itself.
72 // Otherwise orientation can be lost in some cases.
73 #define KEEP_ORIENTATION_0021251
75 #define ARGUMENT_LABEL 1
76 #define RESULT_LABEL 2
77 #define DESCRIPTION_LABEL 3
78 #define HISTORY_LABEL 4
79 #define SUBSHAPES_LABEL 5 // 0020756: GetGroups
80 #define NAMING_LABEL 6 // 0020750: Naming during STEP import
81 #define CALLBACK_LABEL 1 // TDataStd_Comment
83 #ifdef KEEP_ORIENTATION_0021251
84 #define ORIENTATION_LABEL 7 // 0021251: TNaming_NamedShape doesn't store orientation
87 #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
88 #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
89 #define SUB_ARGUMENT(thePos1, thePos2) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePos1)).FindChild((thePos2))
91 //=======================================================================
92 //function : GetFunctionTreeID
94 //=======================================================================
95 const Standard_GUID& GEOM_Function::GetFunctionTreeID()
97 static Standard_GUID aFunctionTreeID("FF1BBB00-5D14-4df2-980B-3A668264EA16");
98 return aFunctionTreeID;
102 //=======================================================================
103 //function : GetDependencyID
105 //=======================================================================
106 const Standard_GUID& GEOM_Function::GetDependencyID()
108 static Standard_GUID aDependencyID("E2620650-2354-41bd-8C2C-210CFCD00948");
109 return aDependencyID;
112 //=============================================================================
116 //=============================================================================
117 Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry)
119 if(!theEntry.IsAttribute(TFunction_Function::GetID())) return NULL;
121 return new GEOM_Function(theEntry);
124 //=============================================================================
128 //=============================================================================
129 GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType)
130 : _label(theEntry), _isCallBackData(false)
132 TFunction_Function::Set(theEntry, theGUID);
133 TDataStd_Integer::Set(theEntry, theType);
135 //Add function to a function tree
136 Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(theEntry.Data());
137 Handle(TDataStd_TreeNode) aRoot, aNode;
138 if(!aDoc->Main().FindAttribute(GetFunctionTreeID(), aRoot))
139 aRoot = TDataStd_TreeNode::Set(aDoc->Main(), GetFunctionTreeID());
141 aNode = TDataStd_TreeNode::Set(theEntry, GetFunctionTreeID());
142 aRoot->Append(aNode);
145 //================================================================================
151 //================================================================================
153 GEOM_Function::~GEOM_Function()
155 if ( _isCallBackData ) {
156 _label.FindChild( CALLBACK_LABEL ).ForgetAttribute( TDataStd_Comment::GetID() );
160 //================================================================================
162 * \brief Retuns true if this function is the last one in the study
164 //================================================================================
166 bool GEOM_Function::IsLastFuntion()
170 Handle(TDataStd_TreeNode) aNode;
171 if (_label.FindAttribute(GetFunctionTreeID(), aNode))
172 isLast = !aNode->HasNext();
177 //=============================================================================
181 //=============================================================================
182 TDF_Label GEOM_Function::GetOwnerEntry()
184 TDF_Label aFather = _label.Father();
185 while(!aFather.IsRoot()) {
186 if(aFather.IsAttribute(GEOM_Object::GetObjectID())) return aFather;
187 aFather = aFather.Father();
193 //=============================================================================
197 //=============================================================================
198 int GEOM_Function::GetType()
201 Handle(TDataStd_Integer) aType;
202 if(!_label.FindAttribute(TDataStd_Integer::GetID(), aType)) return 0;
207 //=============================================================================
211 //=============================================================================
212 TopoDS_Shape GEOM_Function::GetValue()
217 TDF_Label aLabel = GetOwnerEntry();
218 if (aLabel.IsRoot()) return aShape;
219 Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
220 if (anObject.IsNull()) return aShape;
222 if (!anObject->IsMainShape()) {
223 bool isResult = false;
224 TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
225 if (!aResultLabel.IsNull()) {
226 Handle(TNaming_NamedShape) aNS;
227 if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
234 Standard_Integer aTic = anObject->GetTic();
237 GEOM_ISubShape aCI (this);
238 TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
239 if (aLabelObjMainSh.IsRoot()) return aShape;
240 Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
241 if (anObjMainSh.IsNull()) return aShape;
242 Standard_Integer aTicMainSh = anObjMainSh->GetTic();
245 isResult = ((aTic == aTicMainSh) ? true : false);
251 GEOM_Solver aSolver(GEOM_Engine::GetEngine());
252 if (!aSolver.ComputeFunction(this)) {
253 MESSAGE("GEOM_Object::GetValue Error : Can't build a sub-shape");
257 catch (Standard_Failure) {
258 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
259 MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
265 TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
266 Handle(TNaming_NamedShape) aNS;
267 if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
271 #ifdef KEEP_ORIENTATION_0021251
272 // 0021251: TNaming_NamedShape doesn't store orientation
273 TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
274 Handle(TDataStd_Integer) anInteger;
275 if (anOrientationLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) {
276 aShape.Orientation((TopAbs_Orientation)anInteger->Get());
284 //=============================================================================
288 //=============================================================================
289 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
292 TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
293 TNaming_Builder aBuilder (aResultLabel);
295 aBuilder.Generated(theShape);
297 #ifdef KEEP_ORIENTATION_0021251
298 // 0021251: TNaming_NamedShape doesn't store orientation
299 TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
300 TDataStd_Integer::Set(anOrientationLabel, (int)theShape.Orientation());
303 // synchronisation between main shape and its sub-shapes
304 TDF_Label aLabel = GetOwnerEntry();
305 if (aLabel.IsRoot()) return;
306 Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
307 if (anObject.IsNull()) return;
308 if (anObject->IsMainShape()) {
309 // increase modifications counter of this (main) shape
310 anObject->IncrementTic();
313 // update modifications counter of this (sub-) shape to be the same as on main shape
314 GEOM_ISubShape aCI (this);
315 TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
316 if (aLabelObjMainSh.IsRoot()) return;
317 Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
318 if (anObjMainSh.IsNull()) return;
320 anObject->SetTic(anObjMainSh->GetTic());
326 //=============================================================================
330 //=============================================================================
331 Standard_GUID GEOM_Function::GetDriverGUID()
333 Handle(TFunction_Function) aFunction;
334 if(!_label.FindAttribute(TFunction_Function::GetID(), aFunction)) {
335 return TDF::LowestID();
338 return aFunction->GetDriverGUID();
341 //=============================================================================
345 //=============================================================================
346 TCollection_AsciiString GEOM_Function::GetDescription()
348 Handle(TDataStd_Comment) aComment;
349 TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
350 if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return TCollection_AsciiString();
351 TCollection_AsciiString aDescr(aComment->Get());
355 //=============================================================================
359 //=============================================================================
360 void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription)
362 TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
363 Handle(TDataStd_Comment) aComment =
364 TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription));
367 //=============================================================================
371 //=============================================================================
372 void GEOM_Function::SetReal(int thePosition, double theValue)
375 if(thePosition <= 0) return;
376 TDF_Label anArgLabel = ARGUMENT(thePosition);
377 TDataStd_Real::Set(anArgLabel, theValue);
381 //=============================================================================
385 //=============================================================================
386 void GEOM_Function::SetRealArray (int thePosition,
387 const Handle(TColStd_HArray1OfReal)& theArray)
390 if(thePosition <= 0) return;
391 TDF_Label anArgLabel = ARGUMENT(thePosition);
392 Handle(TDataStd_RealArray) anAttr =
393 TDataStd_RealArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
394 anAttr->ChangeArray(theArray);
398 //=============================================================================
402 //=============================================================================
403 double GEOM_Function::GetReal(int thePosition)
406 if(thePosition <= 0) return 0.0;
407 Handle(TDataStd_Real) aReal;
408 TDF_Label anArgLabel = ARGUMENT(thePosition);
409 if(!anArgLabel.FindAttribute(TDataStd_Real::GetID(), aReal)) return 0.0;
415 //=============================================================================
419 //=============================================================================
420 Handle(TColStd_HArray1OfReal) GEOM_Function::GetRealArray(int thePosition)
423 if(thePosition <= 0) return NULL;
424 Handle(TDataStd_RealArray) aRealArray;
425 TDF_Label anArgLabel = ARGUMENT(thePosition);
426 if(!anArgLabel.FindAttribute(TDataStd_RealArray::GetID(), aRealArray)) return NULL;
429 return aRealArray->Array();
432 //=============================================================================
436 //=============================================================================
437 void GEOM_Function::SetInteger(int thePosition, int theValue)
440 if(thePosition <= 0) return;
441 TDF_Label anArgLabel = ARGUMENT(thePosition);
442 TDataStd_Integer::Set(anArgLabel, theValue);
446 //=============================================================================
450 //=============================================================================
451 void GEOM_Function::SetIntegerArray (int thePosition,
452 const Handle(TColStd_HArray1OfInteger)& theArray)
455 if(thePosition <= 0) return;
456 TDF_Label anArgLabel = ARGUMENT(thePosition);
457 Handle(TDataStd_IntegerArray) anAttr =
458 TDataStd_IntegerArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
459 anAttr->ChangeArray(theArray);
463 //=============================================================================
467 //=============================================================================
468 int GEOM_Function::GetInteger(int thePosition)
471 if(thePosition <= 0) return 0;
472 Handle(TDataStd_Integer) anInteger;
473 TDF_Label anArgLabel = ARGUMENT(thePosition);
474 if(!anArgLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) return 0;
477 return anInteger->Get();
480 //=============================================================================
484 //=============================================================================
485 Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition)
488 if(thePosition <= 0) return 0;
489 Handle(TDataStd_IntegerArray) anIntegerArray;
490 TDF_Label anArgLabel = ARGUMENT(thePosition);
491 if(!anArgLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) return 0;
494 return anIntegerArray->Array();
497 //=============================================================================
501 //=============================================================================
502 void GEOM_Function::SetByteArray (int thePosition,
503 const Handle(TColStd_HArray1OfByte)& theArray)
506 if(thePosition <= 0) return;
507 TDF_Label anArgLabel = ARGUMENT(thePosition);
508 Handle(TDataStd_ByteArray) anAttr =
509 TDataStd_ByteArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
510 anAttr->ChangeArray(theArray);
514 //=============================================================================
518 //=============================================================================
519 Handle(TColStd_HArray1OfByte) GEOM_Function::GetByteArray(int thePosition)
522 if(thePosition <= 0) return 0;
523 Handle(TDataStd_ByteArray) aByteArray;
524 TDF_Label anArgLabel = ARGUMENT(thePosition);
525 if(!anArgLabel.FindAttribute(TDataStd_ByteArray::GetID(), aByteArray)) return 0;
528 return aByteArray->InternalArray();
531 //=============================================================================
535 //=============================================================================
536 void GEOM_Function::SetBooleanArray (int thePosition,
537 const Handle(TColStd_HArray1OfByte)& theArray)
540 if(thePosition <= 0) return;
541 TDF_Label anArgLabel = ARGUMENT(thePosition);
542 Handle(TDataStd_BooleanArray) anAttr =
543 TDataStd_BooleanArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
544 anAttr->SetInternalArray(theArray);
548 //=============================================================================
552 //=============================================================================
553 Handle(TColStd_HArray1OfByte) GEOM_Function::GetBooleanArray(int thePosition)
556 if(thePosition <= 0) return 0;
557 Handle(TDataStd_BooleanArray) aBooleanArray;
558 TDF_Label anArgLabel = ARGUMENT(thePosition);
559 if(!anArgLabel.FindAttribute(TDataStd_BooleanArray::GetID(), aBooleanArray)) return 0;
562 return aBooleanArray->InternalArray();
565 //=============================================================================
569 //=============================================================================
570 void GEOM_Function::SetString(int thePosition, const TCollection_AsciiString& theValue)
573 if(thePosition <= 0) return;
574 TDF_Label anArgLabel = ARGUMENT(thePosition);
575 TDataStd_Comment::Set(anArgLabel, theValue);
579 //=============================================================================
583 //=============================================================================
584 TCollection_AsciiString GEOM_Function::GetString(int thePosition)
587 TCollection_AsciiString aRes;
588 if(thePosition <= 0) return aRes;
589 Handle(TDataStd_Comment) aString;
590 TDF_Label anArgLabel = ARGUMENT(thePosition);
591 if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
594 aRes = TCollection_AsciiString(aString->Get());
598 //=============================================================================
602 //=============================================================================
603 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
606 if (thePosition <= 0) return;
607 if (theReference.IsNull()) return;
608 TDF_Label anArgLabel = ARGUMENT(thePosition);
609 TDF_Reference::Set(anArgLabel, theReference->GetEntry());
610 TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
615 //=============================================================================
619 //=============================================================================
620 Handle(GEOM_Function) GEOM_Function::GetReference(int thePosition)
623 if(thePosition <= 0) return NULL;
624 TDF_Label anArgLabel = ARGUMENT(thePosition);
625 Handle(TDF_Reference) aRef;
626 if(!anArgLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL;
629 return GetFunction(aRef->Get());
633 //=============================================================================
637 //=============================================================================
638 void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1OfExtendedString)& theArray)
641 if(thePosition <= 0 || theArray.IsNull()) return;
642 TDF_Label anArgLabel = ARGUMENT(thePosition);
644 Handle(TDataStd_ExtStringArray) anArray =
645 TDataStd_ExtStringArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
646 anArray->ChangeArray(theArray);
652 //=============================================================================
656 //=============================================================================
657 Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePosition)
660 if(thePosition <= 0) return NULL;
661 TDF_Label anArgLabel = ARGUMENT(thePosition);
662 Handle(TDataStd_ExtStringArray) anArray;
663 if(!anArgLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), anArray)) return NULL;
666 return anArray->Array();
669 //=======================================================================
671 //purpose : Returns true if data of given type already exists
672 //=======================================================================
674 bool GEOM_Function::HasData(int thePosition, const Standard_GUID& dataID)
676 if(thePosition <= 0) return false;
677 TDF_Label anArgLabel = ARGUMENT(thePosition);
678 return anArgLabel.IsAttribute( dataID );
681 //=======================================================================
682 //function : GetReferencesTreeID
684 //=======================================================================
685 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
687 static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
688 return aReferencesTreeID;
691 //=============================================================================
695 //=============================================================================
696 void GEOM_Function::SetReferenceList (int thePosition,
697 const Handle(TColStd_HSequenceOfTransient)& theRefList)
700 if(thePosition <= 0) return;
702 // parent label for the list of references
703 TDF_Label anArgLabel = ARGUMENT(thePosition);
704 anArgLabel.ForgetAllAttributes();
706 // set TreeNode on the parent label
707 Handle(TDataStd_TreeNode) aRoot, aNode;
708 aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
710 // store references on sub-labels of the parent label
711 Handle(GEOM_Function) aFunc;
712 Standard_Integer ind, len = theRefList->Length();
713 for (ind = 1; ind <= len; ind++) {
714 aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
715 if (aFunc.IsNull()) continue;
716 TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
717 TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
718 TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
720 // set TreeNode on the child label
721 aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
722 aRoot->Append(aNode);
729 //=============================================================================
733 //=============================================================================
734 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
736 Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
738 if(thePosition <= 0) return aResult;
740 // parent label for the list of references
741 TDF_Label anArgLabel = ARGUMENT(thePosition);
742 Handle(TDF_Reference) aRef;
744 // get TreeNode on the parent label
745 Handle(TDataStd_TreeNode) aRoot, aNode;
746 if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
749 // get references, stored on sub-labels of the parent label
751 TDataStd_ChildNodeIterator anIter (aRoot);
752 for (; anIter.More(); anIter.Next()) {
753 aNode = anIter.Value();
754 aLabel_i = aNode->Label();
755 if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
756 Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
757 if (aFunc_i.IsNull()) continue;
758 aResult->Append(aFunc_i);
765 //=============================================================================
769 //=============================================================================
770 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
773 // if(thePosition <= 0 || theShape.IsNull()) return;
775 // TDF_Label anArgLabel = ARGUMENT(thePosition);
776 // TNaming_Builder aBuilder(anArgLabel);
777 // aBuilder.Generated(theShape);
783 //=============================================================================
787 //=============================================================================
788 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
791 // TopoDS_Shape aShape;
792 // if(thePosition <= 0) return aShape;
794 // TDF_Label anArgLabel = ARGUMENT(thePosition);
795 // Handle(TNaming_NamedShape) aNS;
796 // if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
798 // aShape = aNS->Get();
804 //=============================================================================
808 //=============================================================================
809 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
811 TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
812 for(; anIterator.More(); anIterator.Next()) {
813 if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
817 //=============================================================================
819 * AddSubShapeReference
821 //=============================================================================
822 void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
826 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
828 Handle(TDataStd_ExtStringList) aList;
829 if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
830 aList = new TDataStd_ExtStringList;
831 aSubShapesLabel.AddAttribute(aList);
834 TCollection_AsciiString anEntry;
835 TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
836 aList->Append(anEntry);
841 //=============================================================================
843 * RemoveSubShapeReference
845 //=============================================================================
846 void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape)
850 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
852 Handle(TDataStd_ExtStringList) aList;
853 if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
854 TCollection_AsciiString anEntry;
855 TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
856 aList->Remove(anEntry);
862 //=============================================================================
864 * HasSubShapeReferences
866 //=============================================================================
867 bool GEOM_Function::HasSubShapeReferences()
871 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
872 return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID());
875 //=============================================================================
877 * GetSubShapeReferences
879 //=============================================================================
880 const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
884 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
886 Handle(TDataStd_ExtStringList) aList;
887 if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
888 aList = new TDataStd_ExtStringList;
889 aSubShapesLabel.AddAttribute(aList);
893 return aList->List();
896 //=============================================================================
900 //=============================================================================
901 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
903 return _label.FindChild(HISTORY_LABEL, create);
906 //=============================================================================
908 * GetArgumentHistoryEntry
910 //=============================================================================
911 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label& theArgumentRefEntry,
912 const Standard_Boolean create)
914 TColStd_ListOfInteger anArgumentRefTags;
915 TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
916 Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
918 TDF_Label aHistoryLabel = GetHistoryEntry(create);
919 if (aHistoryLabel.IsNull())
920 return aHistoryLabel;
921 Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
923 Standard_Integer itag;
924 TDF_Label aHistoryCurLabel = aHistoryLabel;
925 TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
926 for (itag = 1; itag <= aHistoryLabelPos; itag++) {
929 for (; itag <= anArgumentRefLabelPos; itag++) {
930 aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
931 if (aHistoryCurLabel.IsNull())
932 return aHistoryCurLabel;
936 return aHistoryCurLabel;
939 //=============================================================================
943 //=============================================================================
944 TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
946 return _label.FindChild(NAMING_LABEL, create);
949 //================================================================================
951 * Save a pointer to a data holder intended to pass temporary data Driver -> Operation.
952 * This method should be called by Operation to set the data holder.
953 * An instance of GEOM_Function that sets the data holder will remove the
954 * corresponding OCAF attribute at it's destruction
956 //================================================================================
958 void GEOM_Function::SetCallBackData( void* data )
960 std::ostringstream strm;
961 strm << (long long) data;
962 TCollection_ExtendedString string( strm.str().c_str() );
964 TDF_Label aChild = _label.FindChild(CALLBACK_LABEL);
965 TDataStd_Comment::Set(aChild, string);
967 _isCallBackData = true; // I will remove TDataStd_Comment at destruction
970 //================================================================================
972 * Returns a pointer to a data holder intended to pass data Driver -> Operation.
973 * This method should be called by Driver to get the data holder to fill it in.
974 * Returns NULL if the Operation have not set the data holder.
976 //================================================================================
978 void* GEOM_Function::GetCallBackData()
980 Handle(TDataStd_Comment) aComment;
981 TDF_Label aChild = _label.FindChild( CALLBACK_LABEL );
982 if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return NULL;
983 TCollection_AsciiString string( aComment->Get() );
987 address = atoll ( string.ToCString() );
989 address = _strtoi64 ( string.ToCString(), NULL, 10 );
992 return reinterpret_cast<void*> ( address );
995 IMPLEMENT_STANDARD_HANDLE (GEOM_Function, Standard_Transient);
996 IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );