Salome HOME
Preparation of intermediate revision
[modules/geom.git] / src / GEOMBase / GEOMBase_Helper.cxx
index 326998aed8a2fd7511a803bfc5dfc03aaa4e77ed..ed25af099d54cdb3d475fc7a742a41f126a11c36 100755 (executable)
@@ -40,6 +40,7 @@
 #include <SalomeApp_Module.h>
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
+#include <SalomeApp_Notebook.h>
 #include <LightApp_SelectionMgr.h>
 #include <LightApp_DataOwner.h>
 #include <SalomeApp_Tools.h>
 #include <TColStd_MapOfInteger.hxx>
 #include <TCollection_AsciiString.hxx>
 
+//To disable automatic genericobj management, the following line should be commented.
+//Otherwise, it should be uncommented. Refer to KERNEL_SRC/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
+//#define WITHGENERICOBJ
+
 //================================================================
 // Function : getActiveView
 // Purpose  : Get active view window, returns 0 if no open study frame
@@ -80,8 +85,11 @@ GEOM::GEOM_Gen_ptr GEOMBase_Helper::getGeomEngine()
 // Purpose  :
 //================================================================
 GEOMBase_Helper::GEOMBase_Helper( SUIT_Desktop* desktop )
-  : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), isPreview( false )
+  : myDesktop( desktop ), myViewWindow( 0 ), myDisplayer( 0 ), myCommand( 0 ), myNoteBook( 0 ), isPreview( false )
 {
+  if( SalomeApp_Application* app = (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )
+    if( SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() ) )
+      myNoteBook = new SalomeApp_Notebook( appStudy );
 }
 
 //================================================================
@@ -106,6 +114,14 @@ GEOMBase_Helper::~GEOMBase_Helper()
   
   if (myDisplayer)
     delete myDisplayer;
+  if ( !CORBA::is_nil( myOperation ) )
+    myOperation->Destroy();
+
+  if( myNoteBook )
+  {
+    delete myNoteBook;
+    myNoteBook = 0;
+  }
 }
 
 //================================================================
@@ -264,9 +280,10 @@ void GEOMBase_Helper::displayPreview( const bool   activate,
     else {
       for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it )
       {
-        displayPreview( *it, true, activate, false, lineWidth, displayMode, color );
+           GEOM::GEOM_Object_var obj=*it;
+        displayPreview( obj, true, activate, false, lineWidth, displayMode, color );
         if ( toRemoveFromEngine )
-          getGeomEngine()->RemoveObject( *it );
+             obj->Destroy();
       }
     }
   }
@@ -524,6 +541,7 @@ void GEOMBase_Helper::addInStudy( GEOM::GEOM_Object_ptr theObj, const char* theN
   // Each dialog is responsible for this method implementation,
   // default implementation does nothing
   restoreSubShapes(aStudyDS, aSO);
+  aSO->Destroy();
 }
 
 //================================================================
@@ -623,7 +641,7 @@ char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
       }
     }
   }
-  return "";
+  return (char*)"";
 }
 
 //================================================================
@@ -699,6 +717,7 @@ bool GEOMBase_Helper::abortCommand()
     return false;
 
   myCommand->abort();
+  delete myCommand; // I don't know where to delete this object here ?
   myCommand = 0;
 
   return true;
@@ -714,6 +733,7 @@ bool GEOMBase_Helper::commitCommand( const char* )
     return false;
 
   myCommand->commit();
+  delete myCommand; // I don't know where to delete this object here ?
   myCommand = 0;
 
   return true;
@@ -806,11 +826,12 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
        const int nbObjs = objects.size();
         int aNumber = 1;
        for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
+         GEOM::GEOM_Object_var obj=*it;
          if ( publish ) {
            QString aName = getNewObjectName();
            if ( nbObjs > 1 ) {
               if (aName.isEmpty())
-                aName = getPrefix(*it);
+                aName = getPrefix(obj);
               if (nbObjs <= 30) {
                 // Try to find a unique name
                 aName = GEOMBase::GetDefaultName(aName);
@@ -821,18 +842,24 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
            } else {
              // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
              if ( aName.isEmpty() )
-               aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
+               aName = GEOMBase::GetDefaultName( getPrefix( obj ) );
            }
-           addInStudy( *it, aName.toLatin1().constData() );
+           addInStudy( obj, aName.toLatin1().constData() );
             // updateView=false
-           display( *it, false );
+           display( obj, false );
+#ifdef WITHGENERICOBJ
+           // obj has been published in study. Its refcount has been incremented.
+           // It is safe to decrement its refcount
+           // so that it will be destroyed when the entry in study will be removed
+           obj->Destroy();
+#endif
          }
          else {
             // asv : fix of PAL6454. If publish==false, then the original shape
             // was modified, and need to be re-cached in GEOM_Client before redisplay
-           clearShapeBuffer( *it );
+           clearShapeBuffer( obj );
             // withChildren=true, updateView=false
-           redisplay( *it, true, false );
+           redisplay( obj, true, false );
           }
        }