Salome HOME
Migration on OCCT > 7.1: properly set TDataStd_ExtStringList attribute
[modules/geom.git] / src / GEOM / GEOM_Function.cxx
index db4658cf2c61b9f263a5173e611e045f46ccfcf1..952dbd3e95a0d7bd9e4fa89fb3d6a01581232cef 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -36,6 +36,8 @@
 #include <TDF_Data.hxx>
 #include <TDF_ChildIterator.hxx>
 #include <TDF_Reference.hxx>
+#include <TDataStd_BooleanArray.hxx>
+#include <TDataStd_ByteArray.hxx>
 #include <TDataStd_Integer.hxx>
 #include <TDataStd_IntegerArray.hxx>
 #include <TDataStd_Real.hxx>
 
 #include <TColStd_ListOfInteger.hxx>
 #include <TColStd_ListIteratorOfListOfInteger.hxx>
-#include <TColStd_HArray1OfReal.hxx>
-#include <TColStd_HArray1OfInteger.hxx>
-#include <TColStd_HSequenceOfTransient.hxx>
-#include <TCollection_AsciiString.hxx>
 #include <TCollection_ExtendedString.hxx>
 
+#include <cstdlib>
+
 #include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
@@ -74,6 +74,7 @@
 #define HISTORY_LABEL 4
 #define SUBSHAPES_LABEL 5 // 0020756: GetGroups
 #define NAMING_LABEL 6 // 0020750: Naming during STEP import
+#define CALLBACK_LABEL 1 // TDataStd_Comment
 
 #ifdef KEEP_ORIENTATION_0021251
 #define ORIENTATION_LABEL 7 // 0021251: TNaming_NamedShape doesn't store orientation
@@ -122,7 +123,7 @@ Handle(GEOM_Function) GEOM_Function::GetFunction(const TDF_Label& theEntry)
  */
 //=============================================================================
 GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& theGUID, int theType)
-: _label(theEntry)
+  : _label(theEntry), _isCallBackData(false)
 {
   TFunction_Function::Set(theEntry, theGUID);
   TDataStd_Integer::Set(theEntry, theType);
@@ -137,6 +138,21 @@ GEOM_Function::GEOM_Function(const TDF_Label& theEntry, const Standard_GUID& the
   aRoot->Append(aNode);
 }
 
+//================================================================================
+/*!
+ * \brief 
+ * 
+ * 
+ */
+//================================================================================
+
+GEOM_Function::~GEOM_Function()
+{
+  if ( _isCallBackData ) {
+    _label.FindChild( CALLBACK_LABEL ).ForgetAttribute( TDataStd_Comment::GetID() );
+  }
+}
+
 //================================================================================
 /*!
  * \brief Retuns true if this function is the last one in the study
@@ -227,9 +243,7 @@ TopoDS_Shape GEOM_Function::GetValue()
 
     if (!isResult) {
       try {
-#if OCC_VERSION_LARGE > 0x06010000
         OCC_CATCH_SIGNALS;
-#endif
         GEOM_Solver aSolver(GEOM_Engine::GetEngine());
         if (!aSolver.ComputeFunction(this)) {
           MESSAGE("GEOM_Object::GetValue Error : Can't build a sub-shape");
@@ -476,6 +490,74 @@ Handle(TColStd_HArray1OfInteger) GEOM_Function::GetIntegerArray(int thePosition)
   return anIntegerArray->Array();
 }
 
+//=============================================================================
+/*!
+ *  SetByteArray
+ */
+//=============================================================================
+void GEOM_Function::SetByteArray (int thePosition,
+                                  const Handle(TColStd_HArray1OfByte)& theArray)
+{
+  _isDone = false;
+  if(thePosition <= 0) return;
+  TDF_Label anArgLabel = ARGUMENT(thePosition);
+  Handle(TDataStd_ByteArray) anAttr =
+    TDataStd_ByteArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
+  anAttr->ChangeArray(theArray);
+  _isDone = true;
+}
+
+//=============================================================================
+/*!
+ *  GetByteArray
+ */
+//=============================================================================
+Handle(TColStd_HArray1OfByte) GEOM_Function::GetByteArray(int thePosition)
+{
+  _isDone = false;
+  if(thePosition <= 0) return 0;
+  Handle(TDataStd_ByteArray) aByteArray;
+  TDF_Label anArgLabel = ARGUMENT(thePosition);
+  if(!anArgLabel.FindAttribute(TDataStd_ByteArray::GetID(), aByteArray)) return 0;
+
+  _isDone = true;
+  return aByteArray->InternalArray();
+}
+
+//=============================================================================
+/*!
+ *  SetBooleanArray
+ */
+//=============================================================================
+void GEOM_Function::SetBooleanArray (int thePosition,
+                                     const Handle(TColStd_HArray1OfByte)& theArray)
+{
+  _isDone = false;
+  if(thePosition <= 0) return;
+  TDF_Label anArgLabel = ARGUMENT(thePosition);
+  Handle(TDataStd_BooleanArray) anAttr =
+    TDataStd_BooleanArray::Set(anArgLabel, theArray->Lower(), theArray->Upper());
+  anAttr->SetInternalArray(theArray);
+  _isDone = true;
+}
+
+//=============================================================================
+/*!
+ *  GetBooleanArray
+ */
+//=============================================================================
+Handle(TColStd_HArray1OfByte) GEOM_Function::GetBooleanArray(int thePosition)
+{
+  _isDone = false;
+  if(thePosition <= 0) return 0;
+  Handle(TDataStd_BooleanArray) aBooleanArray;
+  TDF_Label anArgLabel = ARGUMENT(thePosition);
+  if(!anArgLabel.FindAttribute(TDataStd_BooleanArray::GetID(), aBooleanArray)) return 0;
+
+  _isDone = true;
+  return aBooleanArray->InternalArray();
+}
+
 //=============================================================================
 /*!
  *  SetString
@@ -503,9 +585,10 @@ TCollection_AsciiString GEOM_Function::GetString(int thePosition)
   Handle(TDataStd_Comment) aString;
   TDF_Label anArgLabel = ARGUMENT(thePosition);
   if(!anArgLabel.FindAttribute(TDataStd_Comment::GetID(), aString)) return aRes;
-
+  char *str = new char[aString->Get().LengthOfCString()+1];
+  aString->Get().ToUTF8CString(str);
+  aRes = TCollection_AsciiString(str);
   _isDone = true;
-  aRes = TCollection_AsciiString(aString->Get());
   return aRes;
 }
 
@@ -739,12 +822,7 @@ void GEOM_Function::AddSubShapeReference(Handle(GEOM_Function) theSubShape)
 
   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
 
-  Handle(TDataStd_ExtStringList) aList;
-  if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
-    aList = new TDataStd_ExtStringList;
-    aSubShapesLabel.AddAttribute(aList);
-  }
-
+  Handle(TDataStd_ExtStringList) aList = TDataStd_ExtStringList::Set( aSubShapesLabel );
   TCollection_AsciiString anEntry;
   TDF_Tool::Entry(theSubShape->GetOwnerEntry(), anEntry);
   aList->Append(anEntry);
@@ -797,11 +875,7 @@ const TDataStd_ListOfExtendedString& GEOM_Function::GetSubShapeReferences()
 
   TDF_Label aSubShapesLabel = _label.FindChild(SUBSHAPES_LABEL);
 
-  Handle(TDataStd_ExtStringList) aList;
-  if (!aSubShapesLabel.FindAttribute(TDataStd_ExtStringList::GetID(), aList)) {
-    aList = new TDataStd_ExtStringList;
-    aSubShapesLabel.AddAttribute(aList);
-  }
+  Handle(TDataStd_ExtStringList) aList = TDataStd_ExtStringList::Set( aSubShapesLabel );
 
   _isDone = true;
   return aList->List();
@@ -860,5 +934,50 @@ TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
   return _label.FindChild(NAMING_LABEL, create);
 }
 
-IMPLEMENT_STANDARD_HANDLE (GEOM_Function, Standard_Transient);
-IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );
+//================================================================================
+/*!
+ * Save a pointer to a data holder intended to pass temporary data Driver -> Operation.
+ * This method should be called by Operation to set the data holder.
+ * An instance of GEOM_Function that sets the data holder will remove the
+ * corresponding OCAF attribute at it's destruction
+ */
+//================================================================================
+
+void GEOM_Function::SetCallBackData( void* data )
+{
+  std::ostringstream strm;
+  strm << (long long) data;
+  TCollection_ExtendedString string( strm.str().c_str() );
+
+  TDF_Label aChild = _label.FindChild(CALLBACK_LABEL);
+  TDataStd_Comment::Set(aChild, string);
+
+  _isCallBackData = true; // I will remove TDataStd_Comment at destruction
+}
+
+//================================================================================
+/*!
+ * Returns a pointer to a data holder intended to pass data Driver -> Operation.
+ * This method should be called by Driver to get the data holder to fill it in.
+ * Returns NULL if the Operation have not set the data holder.
+ */
+//================================================================================
+
+void* GEOM_Function::GetCallBackData()
+{
+  Handle(TDataStd_Comment) aComment;
+  TDF_Label aChild = _label.FindChild( CALLBACK_LABEL );
+  if(!aChild.FindAttribute(TDataStd_Comment::GetID(), aComment)) return NULL;
+  TCollection_AsciiString string( aComment->Get() );
+
+  long long address;
+#ifndef WIN32
+  address = atoll ( string.ToCString() );
+#else
+  address = _strtoi64 ( string.ToCString(), NULL, 10 );
+#endif
+
+  return reinterpret_cast<void*> ( address );
+}
+
+OCCT_IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );