Salome HOME
22752: [EDF] Provide explicit feedback on what has been done by Shape Processing...
[modules/geom.git] / src / GEOM / GEOM_Function.cxx
index 458e0a0bc75079623e12f8a53a5d664ff1401bf6..e96a3a52cc4c39a2d9793236015ea86d7811f48b 100644 (file)
@@ -62,6 +62,8 @@
 #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
 
@@ -76,6 +78,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
@@ -124,7 +127,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);
@@ -139,6 +142,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
@@ -928,5 +946,45 @@ TDF_Label GEOM_Function::GetNamingEntry (const Standard_Boolean create)
   return _label.FindChild(NAMING_LABEL, create);
 }
 
+//================================================================================
+/*!
+ * 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 = atoll( string.ToCString() );
+  return reinterpret_cast<void*> ( address );
+}
+
 IMPLEMENT_STANDARD_HANDLE (GEOM_Function, Standard_Transient);
 IMPLEMENT_STANDARD_RTTIEXT(GEOM_Function, Standard_Transient );