Salome HOME
Merging with WPdev
[modules/geom.git] / src / GEOMBase / GEOMBase_Helper.cxx
index 7c2707cab2e42924564d415708edd2224c9888b0..fe51c488fd99f95035a985c9d5f75f2aa5e6d24f 100755 (executable)
@@ -17,7 +17,7 @@
 //  License along with this library; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 #include <SalomeApp_Module.h>
 #include <SalomeApp_Application.h>
 #include <SalomeApp_Study.h>
-#include <SalomeApp_SelectionMgr.h>
+#include <LightApp_SelectionMgr.h>
 #include <SalomeApp_Tools.h>
 #include <SalomeApp_DataModel.h>
 #include <SalomeApp_Module.h>
 
 #include <OCCViewer_ViewModel.h>
-#include <VTKViewer_ViewModel.h>
+#include <SVTK_ViewModel.h>
 
 #include <OB_Browser.h>
 
@@ -109,7 +109,8 @@ GEOMBase_Helper::~GEOMBase_Helper()
 
   globalSelection( GEOM_ALLOBJECTS, true );
 
-  delete myDisplayer;
+  if (myDisplayer)
+    delete myDisplayer;
 }
 
 //================================================================
@@ -214,7 +215,8 @@ void GEOMBase_Helper::redisplay( GEOM::GEOM_Object_ptr object,
     SalomeApp_Study* aDoc = getStudy();
     if ( aDoc && aDoc->studyDS() ) {
       _PTR(Study) aStudy = aDoc->studyDS();
-      _PTR(SObject) aSObj (aStudy->FindObjectIOR(SalomeApp_Application::orb()->object_to_string(object)));
+      CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string(object);
+      _PTR(SObject) aSObj (aStudy->FindObjectIOR(string(objStr.in())));
       if ( aSObj  ) {
        _PTR(ChildIterator) anIt ( aStudy->NewChildIterator( aSObj ) );
        for ( anIt->InitEx( true ); anIt->More(); anIt->Next() ) {
@@ -301,7 +303,8 @@ void GEOMBase_Helper::displayPreview( GEOM::GEOM_Object_ptr object,
   getDisplayer()->SetToActivate( activate );
 
   // Make a reference to GEOM_Object
-  getDisplayer()->SetName( SalomeApp_Application::orb()->object_to_string( object ) );
+  CORBA::String_var objStr = SalomeApp_Application::orb()->object_to_string( object );
+  getDisplayer()->SetName( objStr.in() );
 
   // Build prs
   SALOME_Prs* aPrs = getDisplayer()->BuildPrs( object );
@@ -337,7 +340,7 @@ void GEOMBase_Helper::displayPreview( const SALOME_Prs* prs,
   // Display prs
   SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
   if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
-       aViewManager->getType() == VTKViewer_Viewer::Type() )
+       aViewManager->getType() == SVTK_Viewer::Type() )
     {
       SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
       SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
@@ -367,7 +370,7 @@ void GEOMBase_Helper::erasePreview( const bool update )
       {
         SUIT_ViewManager* aViewManager = myViewWindow->getViewManager();
         if ( aViewManager->getType() == OCCViewer_Viewer::Type() ||
-             aViewManager->getType() == VTKViewer_Viewer::Type() )
+             aViewManager->getType() == SVTK_Viewer::Type() )
           {
             SUIT_ViewModel* aViewModel = aViewManager->getViewModel();
             SALOME_View* aView = dynamic_cast<SALOME_View*>(aViewModel);
@@ -570,11 +573,13 @@ char* GEOMBase_Helper::getEntry( GEOM::GEOM_Object_ptr object ) const
 {
   SalomeApp_Study* study = getStudy();
   if ( study )  {
-    string IOR = GEOMBase::GetIORFromObject( object);
+    char * objIOR = GEOMBase::GetIORFromObject( object );
+    string IOR( objIOR );
+    free( objIOR );
     if ( IOR != "" ) {
       _PTR(SObject) SO ( study->studyDS()->FindObjectIOR( IOR ) );
       if ( SO ) {
-       return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
+             return TCollection_AsciiString((char*)SO->GetID().c_str()).ToCString();
       }
     }
   }
@@ -601,15 +606,15 @@ void GEOMBase_Helper::clearShapeBuffer( GEOM::GEOM_Object_ptr theObj )
   if ( CORBA::is_nil( theObj ) )
     return;
 
-  string IOR = SalomeApp_Application::orb()->object_to_string( theObj );
-  TCollection_AsciiString asciiIOR( strdup( IOR.c_str() ) );
+  CORBA::String_var IOR = SalomeApp_Application::orb()->object_to_string( theObj );
+  TCollection_AsciiString asciiIOR( (char *)IOR.in() );
   GEOM_Client().RemoveShapeFromBuffer( asciiIOR );
 
   if ( !getStudy() || !getStudy()->studyDS() )
     return;
 
   _PTR(Study) aStudy = getStudy()->studyDS();
-  _PTR(SObject) aSObj ( aStudy->FindObjectIOR( IOR ) );
+  _PTR(SObject) aSObj ( aStudy->FindObjectIOR( string( IOR ) ) );
   if ( !aSObj )
     return;
 
@@ -758,13 +763,21 @@ bool GEOMBase_Helper::onAccept( const bool publish, const bool useTransaction )
       else {
        const int nbObjs = objects.size();
        bool withChildren = false;
+        int aNumber = 1;
        for ( ObjectList::iterator it = objects.begin(); it != objects.end(); ++it ) {
          if ( publish ) {
-           QString aName("");
-           if ( nbObjs > 1 )
-             aName = strlen( getNewObjectName() ) ? GEOMBase::GetDefaultName( getNewObjectName() ) : GEOMBase::GetDefaultName( getPrefix( *it ) );
-           else {
-             aName = getNewObjectName();
+           QString aName = getNewObjectName();
+           if ( nbObjs > 1 ) {
+              if (aName.isEmpty())
+                aName = getPrefix(*it);
+              if (nbObjs <= 30) {
+                // Try to find a unique name
+                aName = GEOMBase::GetDefaultName(aName);
+              } else {
+                // Don't check name uniqueness in case of numerous objects
+                aName = aName + "_" + QString::number(aNumber++);
+              }
+           } else {
              // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName()
              if ( aName.isEmpty() )
                aName = GEOMBase::GetDefaultName( getPrefix( *it ) );
@@ -926,7 +939,7 @@ const SALOME_ListIO& GEOMBase_Helper::selectedIO()
 
   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
   if ( app ) {
-    SalomeApp_SelectionMgr* aSelMgr = app->selectionMgr();
+    LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
     if ( aSelMgr )
       aSelMgr->selectedObjects( mySelected );
   }