1 // Copyright (C) 2007-2016 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 "utilities.h"
33 #include <TDF_Tool.hxx>
34 #include <TDF_Data.hxx>
35 #include <TDF_ChildIterator.hxx>
36 #include <TDF_Reference.hxx>
37 #include <TDataStd_BooleanArray.hxx>
38 #include <TDataStd_ByteArray.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>
55 #include <TColStd_ListOfInteger.hxx>
56 #include <TColStd_ListIteratorOfListOfInteger.hxx>
57 #include <TCollection_ExtendedString.hxx>
61 #include <Standard_Failure.hxx>
62 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
64 // This modification was introduced in frame of Mantis issue 0021251.
65 // This line allows to keep shape orientation together with the shape itself.
66 // Otherwise orientation can be lost in some cases.
67 #define KEEP_ORIENTATION_0021251
69 #define ARGUMENT_LABEL 1
70 #define RESULT_LABEL 2
71 #define DESCRIPTION_LABEL 3
72 #define HISTORY_LABEL 4
73 #define SUBSHAPES_LABEL 5 // 0020756: GetGroups
74 #define NAMING_LABEL 6 // 0020750: Naming during STEP import
75 #define CALLBACK_LABEL 1 // TDataStd_Comment
77 #ifdef KEEP_ORIENTATION_0021251
78 #define ORIENTATION_LABEL 7 // 0021251: TNaming_NamedShape doesn't store orientation
81 #define ARGUMENTS _label.FindChild((ARGUMENT_LABEL))
82 #define ARGUMENT(thePosition) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePosition))
83 #define SUB_ARGUMENT(thePos1, thePos2) _label.FindChild((ARGUMENT_LABEL)).FindChild((thePos1)).FindChild((thePos2))
85 //=======================================================================
86 //function : GetFunctionTreeID
88 //=======================================================================
89 const Standard_GUID& GEOM_Function::GetFunctionTreeID()
91 static Standard_GUID aFunctionTreeID("FF1BBB00-5D14-4df2-980B-3A668264EA16");
92 return aFunctionTreeID;
96 //=======================================================================
97 //function : GetDependencyID
99 //=======================================================================
100 const Standard_GUID& GEOM_Function::GetDependencyID()
102 static Standard_GUID aDependencyID("E2620650-2354-41bd-8C2C-210CFCD00948");
103 return aDependencyID;
106 //=============================================================================
110 //=============================================================================
111 Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry)
113 if(!theEntry.IsAttribute(TFunction_Function::GetID())) return NULL;
115 return new GEOM_Function(theEntry);
118 //=============================================================================
122 //=============================================================================
123 GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType)
124 : _label(theEntry), _isCallBackData(false)
126 TFunction_Function::Set(theEntry, theGUID);
127 TDataStd_Integer::Set(theEntry, theType);
129 //Add function to a function tree
130 Handle(TDocStd_Document) aDoc = TDocStd_Owner::GetDocument(theEntry.Data());
131 Handle(TDataStd_TreeNode) aRoot, aNode;
132 if(!aDoc->Main().FindAttribute(GetFunctionTreeID(), aRoot))
133 aRoot = TDataStd_TreeNode::Set(aDoc->Main(), GetFunctionTreeID());
135 aNode = TDataStd_TreeNode::Set(theEntry, GetFunctionTreeID());
136 aRoot->Append(aNode);
139 //================================================================================
145 //================================================================================
147 GEOM_Function::~GEOM_Function()
149 if ( _isCallBackData ) {
150 _label.FindChild( CALLBACK_LABEL ).ForgetAttribute( TDataStd_Comment::GetID() );
154 //================================================================================
156 * \brief Retuns true if this function is the last one in the study
158 //================================================================================
160 bool GEOM_Function::IsLastFuntion()
164 Handle(TDataStd_TreeNode) aNode;
165 if (_label.FindAttribute(GetFunctionTreeID(), aNode))
166 isLast = !aNode->HasNext();
171 //=============================================================================
175 //=============================================================================
176 TDF_Label GEOM_Function::GetOwnerEntry()
178 TDF_Label aFather = _label.Father();
179 while(!aFather.IsRoot()) {
180 if(aFather.IsAttribute(GEOM_Object::GetObjectID())) return aFather;
181 aFather = aFather.Father();
187 //=============================================================================
191 //=============================================================================
192 int GEOM_Function::GetType()
195 Handle(TDataStd_Integer) aType;
196 if(!_label.FindAttribute(TDataStd_Integer::GetID(), aType)) return 0;
201 //=============================================================================
205 //=============================================================================
206 TopoDS_Shape GEOM_Function::GetValue()
211 TDF_Label aLabel = GetOwnerEntry();
212 if (aLabel.IsRoot()) return aShape;
213 Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
214 if (anObject.IsNull()) return aShape;
216 if (!anObject->IsMainShape()) {
217 bool isResult = false;
218 TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
219 if (!aResultLabel.IsNull()) {
220 Handle(TNaming_NamedShape) aNS;
221 if (aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS))
228 Standard_Integer aTic = anObject->GetTic();
231 GEOM_ISubShape aCI (this);
232 TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
233 if (aLabelObjMainSh.IsRoot()) return aShape;
234 Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
235 if (anObjMainSh.IsNull()) return aShape;
236 Standard_Integer aTicMainSh = anObjMainSh->GetTic();
239 isResult = ((aTic == aTicMainSh) ? true : false);
245 GEOM_Solver aSolver(GEOM_Engine::GetEngine());
246 if (!aSolver.ComputeFunction(this)) {
247 MESSAGE("GEOM_Object::GetValue Error : Can't build a sub-shape");
251 catch (Standard_Failure) {
252 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
253 MESSAGE("GEOM_Function::GetValue Error: " << aFail->GetMessageString());
259 TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
260 Handle(TNaming_NamedShape) aNS;
261 if (!aResultLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
265 #ifdef KEEP_ORIENTATION_0021251
266 // 0021251: TNaming_NamedShape doesn't store orientation
267 TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
268 Handle(TDataStd_Integer) anInteger;
269 if (anOrientationLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) {
270 aShape.Orientation((TopAbs_Orientation)anInteger->Get());
278 //=============================================================================
282 //=============================================================================
283 void GEOM_Function::SetValue(TopoDS_Shape& theShape)
286 TDF_Label aResultLabel = _label.FindChild(RESULT_LABEL);
287 TNaming_Builder aBuilder (aResultLabel);
289 aBuilder.Generated(theShape);
291 #ifdef KEEP_ORIENTATION_0021251
292 // 0021251: TNaming_NamedShape doesn't store orientation
293 TDF_Label anOrientationLabel = _label.FindChild(ORIENTATION_LABEL);
294 TDataStd_Integer::Set(anOrientationLabel, (int)theShape.Orientation());
297 // synchronisation between main shape and its sub-shapes
298 TDF_Label aLabel = GetOwnerEntry();
299 if (aLabel.IsRoot()) return;
300 Handle(GEOM_Object) anObject = GEOM_Object::GetObject(aLabel);
301 if (anObject.IsNull()) return;
302 if (anObject->IsMainShape()) {
303 // increase modifications counter of this (main) shape
304 anObject->IncrementTic();
307 // update modifications counter of this (sub-) shape to be the same as on main shape
308 GEOM_ISubShape aCI (this);
309 TDF_Label aLabelObjMainSh = aCI.GetMainShape()->GetOwnerEntry();
310 if (aLabelObjMainSh.IsRoot()) return;
311 Handle(GEOM_Object) anObjMainSh = GEOM_Object::GetObject(aLabelObjMainSh);
312 if (anObjMainSh.IsNull()) return;
314 anObject->SetTic(anObjMainSh->GetTic());
320 //=============================================================================
324 //=============================================================================
325 Standard_GUID GEOM_Function::GetDriverGUID()
327 Handle(TFunction_Function) aFunction;
328 if(!_label.FindAttribute(TFunction_Function::GetID(), aFunction)) {
329 return TDF::LowestID();
332 return aFunction->GetDriverGUID();
335 //=============================================================================
339 //=============================================================================
340 TCollection_AsciiString GEOM_Function::GetDescription()
342 Handle(TDataStd_Comment) aComment;
343 TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
344 if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return TCollection_AsciiString();
345 TCollection_AsciiString aDescr(aComment->Get());
349 //=============================================================================
353 //=============================================================================
354 void GEOM_Function::SetDescription(const TCollection_AsciiString& theDescription)
356 TDF_Label aChild = _label.FindChild(DESCRIPTION_LABEL);
357 Handle(TDataStd_Comment) aComment =
358 TDataStd_Comment::Set(aChild, TCollection_ExtendedString(theDescription));
361 //=============================================================================
365 //=============================================================================
366 void GEOM_Function::SetReal(int thePosition, double theValue)
369 if(thePosition <= 0) return;
370 TDF_Label anArgLabel = ARGUMENT(thePosition);
371 TDataStd_Real::Set(anArgLabel, theValue);
375 //=============================================================================
379 //=============================================================================
380 void GEOM_Function::SetRealArray (int thePosition,
381 const Handle(TColStd_HArray1OfReal)& theArray)
384 if(thePosition <= 0) return;
385 TDF_Label anArgLabel = ARGUMENT(thePosition);
386 Handle(TDataStd_RealArray) anAttr =
387 TDataStd_RealArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
388 anAttr->ChangeArray(theArray);
392 //=============================================================================
396 //=============================================================================
397 double GEOM_Function::GetReal(int thePosition)
400 if(thePosition <= 0) return 0.0;
401 Handle(TDataStd_Real) aReal;
402 TDF_Label anArgLabel = ARGUMENT(thePosition);
403 if(!anArgLabel.FindAttribute(TDataStd_Real::GetID(), aReal)) return 0.0;
409 //=============================================================================
413 //=============================================================================
414 Handle(TColStd_HArray1OfReal) GEOM_Function::GetRealArray(int thePosition)
417 if(thePosition <= 0) return NULL;
418 Handle(TDataStd_RealArray) aRealArray;
419 TDF_Label anArgLabel = ARGUMENT(thePosition);
420 if(!anArgLabel.FindAttribute(TDataStd_RealArray::GetID(), aRealArray)) return NULL;
423 return aRealArray->Array();
426 //=============================================================================
430 //=============================================================================
431 void GEOM_Function::SetInteger(int thePosition, int theValue)
434 if(thePosition <= 0) return;
435 TDF_Label anArgLabel = ARGUMENT(thePosition);
436 TDataStd_Integer::Set(anArgLabel, theValue);
440 //=============================================================================
444 //=============================================================================
445 void GEOM_Function::SetIntegerArray (int thePosition,
446 const Handle(TColStd_HArray1OfInteger)& theArray)
449 if(thePosition <= 0) return;
450 TDF_Label anArgLabel = ARGUMENT(thePosition);
451 Handle(TDataStd_IntegerArray) anAttr =
452 TDataStd_IntegerArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
453 anAttr->ChangeArray(theArray);
457 //=============================================================================
461 //=============================================================================
462 int GEOM_Function::GetInteger(int thePosition)
465 if(thePosition <= 0) return 0;
466 Handle(TDataStd_Integer) anInteger;
467 TDF_Label anArgLabel = ARGUMENT(thePosition);
468 if(!anArgLabel.FindAttribute(TDataStd_Integer::GetID(), anInteger)) return 0;
471 return anInteger->Get();
474 //=============================================================================
478 //=============================================================================
479 Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition)
482 if(thePosition <= 0) return 0;
483 Handle(TDataStd_IntegerArray) anIntegerArray;
484 TDF_Label anArgLabel = ARGUMENT(thePosition);
485 if(!anArgLabel.FindAttribute(TDataStd_IntegerArray::GetID(), anIntegerArray)) return 0;
488 return anIntegerArray->Array();
491 //=============================================================================
495 //=============================================================================
496 void GEOM_Function::SetByteArray (int thePosition,
497 const Handle(TColStd_HArray1OfByte)& theArray)
500 if(thePosition <= 0) return;
501 TDF_Label anArgLabel = ARGUMENT(thePosition);
502 Handle(TDataStd_ByteArray) anAttr =
503 TDataStd_ByteArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
504 anAttr->ChangeArray(theArray);
508 //=============================================================================
512 //=============================================================================
513 Handle(TColStd_HArray1OfByte) GEOM_Function::GetByteArray(int thePosition)
516 if(thePosition <= 0) return 0;
517 Handle(TDataStd_ByteArray) aByteArray;
518 TDF_Label anArgLabel = ARGUMENT(thePosition);
519 if(!anArgLabel.FindAttribute(TDataStd_ByteArray::GetID(), aByteArray)) return 0;
522 return aByteArray->InternalArray();
525 //=============================================================================
529 //=============================================================================
530 void GEOM_Function::SetBooleanArray (int thePosition,
531 const Handle(TColStd_HArray1OfByte)& theArray)
534 if(thePosition <= 0) return;
535 TDF_Label anArgLabel = ARGUMENT(thePosition);
536 Handle(TDataStd_BooleanArray) anAttr =
537 TDataStd_BooleanArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
538 anAttr->SetInternalArray(theArray);
542 //=============================================================================
546 //=============================================================================
547 Handle(TColStd_HArray1OfByte) GEOM_Function::GetBooleanArray(int thePosition)
550 if(thePosition <= 0) return 0;
551 Handle(TDataStd_BooleanArray) aBooleanArray;
552 TDF_Label anArgLabel = ARGUMENT(thePosition);
553 if(!anArgLabel.FindAttribute(TDataStd_BooleanArray::GetID(), aBooleanArray)) return 0;
556 return aBooleanArray->InternalArray();
559 //=============================================================================
563 //=============================================================================
564 void GEOM_Function::SetString(int thePosition, const TCollection_AsciiString& theValue)
567 if(thePosition <= 0) return;
568 TDF_Label anArgLabel = ARGUMENT(thePosition);
569 TDataStd_Comment::Set(anArgLabel, theValue);
573 //=============================================================================
577 //=============================================================================
578 TCollection_AsciiString GEOM_Function::GetString(int thePosition)
581 TCollection_AsciiString aRes;
582 if(thePosition <= 0) return aRes;
583 Handle(TDataStd_Comment) aString;
584 TDF_Label anArgLabel = ARGUMENT(thePosition);
585 if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
586 char *str = new char[aString->Get().LengthOfCString()+1];
587 aString->Get().ToUTF8CString(str);
588 aRes = TCollection_AsciiString(str);
593 //=============================================================================
597 //=============================================================================
598 void GEOM_Function::SetReference(int thePosition, Handle(GEOM_Function) theReference)
601 if (thePosition <= 0) return;
602 if (theReference.IsNull()) return;
603 TDF_Label anArgLabel = ARGUMENT(thePosition);
604 TDF_Reference::Set(anArgLabel, theReference->GetEntry());
605 TDataStd_UAttribute::Set(anArgLabel, GetDependencyID());
610 //=============================================================================
614 //=============================================================================
615 Handle(GEOM_Function) GEOM_Function::GetReference(int thePosition)
618 if(thePosition <= 0) return NULL;
619 TDF_Label anArgLabel = ARGUMENT(thePosition);
620 Handle(TDF_Reference) aRef;
621 if(!anArgLabel.FindAttribute(TDF_Reference::GetID(), aRef)) return NULL;
624 return GetFunction(aRef->Get());
628 //=============================================================================
632 //=============================================================================
633 void GEOM_Function::SetStringArray(int thePosition, const Handle(TColStd_HArray1OfExtendedString)& theArray)
636 if(thePosition <= 0 || theArray.IsNull()) return;
637 TDF_Label anArgLabel = ARGUMENT(thePosition);
639 Handle(TDataStd_ExtStringArray) anArray =
640 TDataStd_ExtStringArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
641 anArray->ChangeArray(theArray);
647 //=============================================================================
651 //=============================================================================
652 Handle(TColStd_HArray1OfExtendedString) GEOM_Function::GetStringArray(int thePosition)
655 if(thePosition <= 0) return NULL;
656 TDF_Label anArgLabel = ARGUMENT(thePosition);
657 Handle(TDataStd_ExtStringArray) anArray;
658 if(!anArgLabel.FindAttribute(TDataStd_ExtStringArray::GetID(), anArray)) return NULL;
661 return anArray->Array();
664 //=======================================================================
666 //purpose : Returns true if data of given type already exists
667 //=======================================================================
669 bool GEOM_Function::HasData(int thePosition, const Standard_GUID& dataID)
671 if(thePosition <= 0) return false;
672 TDF_Label anArgLabel = ARGUMENT(thePosition);
673 return anArgLabel.IsAttribute( dataID );
676 //=======================================================================
677 //function : GetReferencesTreeID
679 //=======================================================================
680 const Standard_GUID& GEOM_Function::GetReferencesTreeID()
682 static Standard_GUID aReferencesTreeID("FF1BBB10-5D14-4df2-980B-3A668264EA16");
683 return aReferencesTreeID;
686 //=============================================================================
690 //=============================================================================
691 void GEOM_Function::SetReferenceList (int thePosition,
692 const Handle(TColStd_HSequenceOfTransient)& theRefList)
695 if(thePosition <= 0) return;
697 // parent label for the list of references
698 TDF_Label anArgLabel = ARGUMENT(thePosition);
699 anArgLabel.ForgetAllAttributes();
701 // set TreeNode on the parent label
702 Handle(TDataStd_TreeNode) aRoot, aNode;
703 aRoot = TDataStd_TreeNode::Set(anArgLabel, GetReferencesTreeID());
705 // store references on sub-labels of the parent label
706 Handle(GEOM_Function) aFunc;
707 Standard_Integer ind, len = theRefList->Length();
708 for (ind = 1; ind <= len; ind++) {
709 aFunc = Handle(GEOM_Function)::DownCast(theRefList->Value(ind));
710 if (aFunc.IsNull()) continue;
711 TDF_Label anArgLabel_i = SUB_ARGUMENT(thePosition, ind);
712 TDF_Reference::Set(anArgLabel_i, aFunc->GetEntry());
713 TDataStd_UAttribute::Set(anArgLabel_i, GetDependencyID());
715 // set TreeNode on the child label
716 aNode = TDataStd_TreeNode::Set(anArgLabel_i, GetReferencesTreeID());
717 aRoot->Append(aNode);
724 //=============================================================================
728 //=============================================================================
729 Handle(TColStd_HSequenceOfTransient) GEOM_Function::GetReferenceList(int thePosition)
731 Handle(TColStd_HSequenceOfTransient) aResult = new TColStd_HSequenceOfTransient;
733 if(thePosition <= 0) return aResult;
735 // parent label for the list of references
736 TDF_Label anArgLabel = ARGUMENT(thePosition);
737 Handle(TDF_Reference) aRef;
739 // get TreeNode on the parent label
740 Handle(TDataStd_TreeNode) aRoot, aNode;
741 if(!anArgLabel.FindAttribute(GetReferencesTreeID(), aRoot))
744 // get references, stored on sub-labels of the parent label
746 TDataStd_ChildNodeIterator anIter (aRoot);
747 for (; anIter.More(); anIter.Next()) {
748 aNode = anIter.Value();
749 aLabel_i = aNode->Label();
750 if (!aLabel_i.FindAttribute(TDF_Reference::GetID(), aRef)) continue;
751 Handle(GEOM_Function) aFunc_i = GetFunction(aRef->Get());
752 if (aFunc_i.IsNull()) continue;
753 aResult->Append(aFunc_i);
760 //=============================================================================
764 //=============================================================================
765 //void GEOM_Function::SetShape(int thePosition, const TopoDS_Shape& theShape)
768 // if(thePosition <= 0 || theShape.IsNull()) return;
770 // TDF_Label anArgLabel = ARGUMENT(thePosition);
771 // TNaming_Builder aBuilder(anArgLabel);
772 // aBuilder.Generated(theShape);
778 //=============================================================================
782 //=============================================================================
783 //TopoDS_Shape GEOM_Function::GetShape(int thePosition)
786 // TopoDS_Shape aShape;
787 // if(thePosition <= 0) return aShape;
789 // TDF_Label anArgLabel = ARGUMENT(thePosition);
790 // Handle(TNaming_NamedShape) aNS;
791 // if(!anArgLabel.FindAttribute(TNaming_NamedShape::GetID(), aNS)) return aShape;
793 // aShape = aNS->Get();
799 //=============================================================================
803 //=============================================================================
804 void GEOM_Function::GetDependency(TDF_LabelSequence& theSeq)
806 TDF_ChildIterator anIterator(ARGUMENTS, Standard_True);
807 for(; anIterator.More(); anIterator.Next()) {
808 if(anIterator.Value().IsAttribute(GetDependencyID())) theSeq.Append(anIterator.Value());
812 //=============================================================================
814 * AddSubShapeReference
816 //=============================================================================
817 void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
821 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
823 Handle(TDataStd_ExtStringList) aList = TDataStd_ExtStringList::Set( aSubShapesLabel );
824 TCollection_AsciiString anEntry;
825 TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
826 aList->Append(anEntry);
831 //=============================================================================
833 * RemoveSubShapeReference
835 //=============================================================================
836 void GEOM_Function::RemoveSubShapeReference(Handle(GEOM_Function) theSubShape)
840 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
842 Handle(TDataStd_ExtStringList) aList;
843 if (aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
844 TCollection_AsciiString anEntry;
845 TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
846 aList->Remove(anEntry);
852 //=============================================================================
854 * HasSubShapeReferences
856 //=============================================================================
857 bool GEOM_Function::HasSubShapeReferences()
861 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
862 return aSubShapesLabel.IsAttribute(TDataStd_ExtStringList::GetID());
865 //=============================================================================
867 * GetSubShapeReferences
869 //=============================================================================
870 const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
874 TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
876 Handle(TDataStd_ExtStringList) aList = TDataStd_ExtStringList::Set( aSubShapesLabel );
879 return aList->List();
882 //=============================================================================
886 //=============================================================================
887 TDF_Label GEOM_Function::GetHistoryEntry (const Standard_Boolean create)
889 return _label.FindChild(HISTORY_LABEL, create);
892 //=============================================================================
894 * GetArgumentHistoryEntry
896 //=============================================================================
897 TDF_Label GEOM_Function::GetArgumentHistoryEntry (const TDF_Label& theArgumentRefEntry,
898 const Standard_Boolean create)
900 TColStd_ListOfInteger anArgumentRefTags;
901 TDF_Tool::TagList(theArgumentRefEntry, anArgumentRefTags);
902 Standard_Integer anArgumentRefLabelPos = anArgumentRefTags.Extent();
904 TDF_Label aHistoryLabel = GetHistoryEntry(create);
905 if (aHistoryLabel.IsNull())
906 return aHistoryLabel;
907 Standard_Integer aHistoryLabelPos = aHistoryLabel.Depth() + 1;
909 Standard_Integer itag;
910 TDF_Label aHistoryCurLabel = aHistoryLabel;
911 TColStd_ListIteratorOfListOfInteger aListIter (anArgumentRefTags);
912 for (itag = 1; itag <= aHistoryLabelPos; itag++) {
915 for (; itag <= anArgumentRefLabelPos; itag++) {
916 aHistoryCurLabel = aHistoryCurLabel.FindChild(aListIter.Value(), create);
917 if (aHistoryCurLabel.IsNull())
918 return aHistoryCurLabel;
922 return aHistoryCurLabel;
925 //=============================================================================
929 //=============================================================================
930 TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
932 return _label.FindChild(NAMING_LABEL, create);
935 //================================================================================
937 * Save a pointer to a data holder intended to pass temporary data Driver -> Operation.
938 * This method should be called by Operation to set the data holder.
939 * An instance of GEOM_Function that sets the data holder will remove the
940 * corresponding OCAF attribute at it's destruction
942 //================================================================================
944 void GEOM_Function::SetCallBackData( void* data )
946 std::ostringstream strm;
947 strm << (long long) data;
948 TCollection_ExtendedString string( strm.str().c_str() );
950 TDF_Label aChild = _label.FindChild(CALLBACK_LABEL);
951 TDataStd_Comment::Set(aChild, string);
953 _isCallBackData = true; // I will remove TDataStd_Comment at destruction
956 //================================================================================
958 * Returns a pointer to a data holder intended to pass data Driver -> Operation.
959 * This method should be called by Driver to get the data holder to fill it in.
960 * Returns NULL if the Operation have not set the data holder.
962 //================================================================================
964 void* GEOM_Function::GetCallBackData()
966 Handle(TDataStd_Comment) aComment;
967 TDF_Label aChild = _label.FindChild( CALLBACK_LABEL );
968 if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return NULL;
969 TCollection_AsciiString string( aComment->Get() );
973 address = atoll ( string.ToCString() );
975 address = _strtoi64 ( string.ToCString(), NULL, 10 );
978 return reinterpret_cast<void*> ( address );
981 IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );