Salome HOME
Update copyright info (2010->2011)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index d672484f3c31c96bd009bb45a0a6b17da58bce94..fb0e80d2404ae6ae9133ee229cce87f1afe1754e 100644 (file)
@@ -1,4 +1,4 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+//  Copyright (C) 2007-2011  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
@@ -23,6 +23,8 @@
 //  File   : SMESHGUI.cxx
 //  Author : Nicolas REJNERI, Open CASCADE S.A.S.
 
+#include <Standard_math.hxx>  // E.A. must be included before Python.h to fix compilation on windows
+#include "Python.h"
 //  SMESH includes
 #include "SMESHGUI.h"
 #include "SMESHGUI_AddMeshElementDlg.h"
@@ -34,7 +36,7 @@
 #include "SMESHGUI_CreatePolyhedralVolumeDlg.h"
 #include "SMESHGUI_DeleteGroupDlg.h"
 #include "SMESHGUI_Displayer.h"
-#include "SMESHGUI_EditMeshDlg.h"
+#include "SMESHGUI_MergeDlg.h"
 #include "SMESHGUI_ExtrusionAlongPathDlg.h"
 #include "SMESHGUI_ExtrusionDlg.h"
 #include "SMESHGUI_FileInfoDlg.h"
@@ -71,6 +73,7 @@
 #include "SMESHGUI_ScaleDlg.h"
 #include "SMESHGUI_TransparencyDlg.h"
 #include "SMESHGUI_WhatIsDlg.h"
+#include "SMESHGUI_DuplicateNodesDlg.h"
 
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_MeshUtils.h"
 
     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
     SUIT_ViewManager* vm = anApp->activeViewManager();
-    int nbSf = vm->getViewsCount();
+    int nbSf = vm ? vm->getViewsCount() : 0;
 
     SALOME_ListIteratorOfListIO It(selected);
 
           std::string anEntry = SO->GetID();
 
           /** Erase graphical object **/
-          if(SO->FindAttribute(anAttr, "AttributeIOR")){
+          if(SO->FindAttribute(anAttr, "AttributeIOR") && vm ){
             QVector<SUIT_ViewWindow*> aViews = vm->getViews();
             for(int i = 0; i < nbSf; i++){
               SUIT_ViewWindow *sf = aViews[i];
@@ -1329,13 +1332,22 @@ LightApp_SelectionMgr* SMESHGUI::selectionMgr()
     return 0;
 }
 
-bool SMESHGUI::automaticUpdate()
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool SMESHGUI::automaticUpdate(unsigned int requestedSize, bool* limitExceeded)
 {
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
   if ( !resMgr )
     return false;
 
-  return resMgr->booleanValue( "SMESH", "auto_update", false );
+  bool autoUpdate  = resMgr->booleanValue( "SMESH", "auto_update",  false );
+  long updateLimit = resMgr->integerValue( "SMESH", "update_limit", 500000 );
+  bool exceeded = updateLimit > 0 && requestedSize > updateLimit;
+  if ( limitExceeded ) *limitExceeded = autoUpdate && exceeded;
+  return autoUpdate && !exceeded;
 }
 
 //=============================================================================
@@ -2571,36 +2583,36 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if(checkLock(aStudy)) break;
       SALOME_ListIO selected;
       if( LightApp_SelectionMgr *aSel = SMESHGUI::selectionMgr() )
-       aSel->selectedObjects( selected );
+        aSel->selectedObjects( selected );
       if ( selected.Extent() == 1 ) {
-       Handle(SALOME_InteractiveObject) anIO = selected.First();
-       SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
-       if ( !aMesh->_is_nil() ) {
-         bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
-                                                   tr( "SMESH_WARNING" ),
-                                                   tr( "REMOVE_ORPHAN_NODES_QUESTION"),
-                                                   SUIT_MessageBox::Yes |
-                                                   SUIT_MessageBox::No,
-                                                   SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
-         if( confirm ) {
-           try {
-             SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
-             int removed = aMeshEditor->RemoveOrphanNodes();
-             SUIT_MessageBox::information(SMESHGUI::desktop(),
-                                          tr("SMESH_INFORMATION"),
-                                          tr("NB_NODES_REMOVED").arg(removed));
-             if ( removed > 0 ) {
-               SMESH::UpdateView();
-               SMESHGUI::Modified();
-             }
-           }
-           catch (const SALOME::SALOME_Exception& S_ex) {
-             SalomeApp_Tools::QtCatchCorbaException(S_ex);
-           } 
-           catch (...) {
-           }
-         }
-       }
+        Handle(SALOME_InteractiveObject) anIO = selected.First();
+        SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
+        if ( !aMesh->_is_nil() ) {
+          bool confirm = SUIT_MessageBox::question( SMESHGUI::desktop(),
+                                                    tr( "SMESH_WARNING" ),
+                                                    tr( "REMOVE_ORPHAN_NODES_QUESTION"),
+                                                    SUIT_MessageBox::Yes |
+                                                    SUIT_MessageBox::No,
+                                                    SUIT_MessageBox::No ) == SUIT_MessageBox::Yes;
+          if( confirm ) {
+            try {
+              SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
+              int removed = aMeshEditor->RemoveOrphanNodes();
+              SUIT_MessageBox::information(SMESHGUI::desktop(),
+                                           tr("SMESH_INFORMATION"),
+                                           tr("NB_NODES_REMOVED").arg(removed));
+              if ( removed > 0 ) {
+                SMESH::UpdateView();
+                SMESHGUI::Modified();
+              }
+            }
+            catch (const SALOME::SALOME_Exception& S_ex) {
+              SalomeApp_Tools::QtCatchCorbaException(S_ex);
+            
+            catch (...) {
+            }
+          }
+        }
       }
       break;
     }
@@ -2689,7 +2701,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if(checkLock(aStudy)) break;
       if(vtkwnd) {
         EmitSignalDeactivateDialog();
-        ( new SMESHGUI_EditMeshDlg( this, 0 ) )->show();
+        ( new SMESHGUI_MergeDlg( this, 0 ) )->show();
       }
       else {
         SUIT_MessageBox::warning(SMESHGUI::desktop(),
@@ -2702,7 +2714,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       if (checkLock(aStudy)) break;
       if (vtkwnd) {
         EmitSignalDeactivateDialog();
-        ( new SMESHGUI_EditMeshDlg( this, 1 ) )->show();
+        ( new SMESHGUI_MergeDlg( this, 1 ) )->show();
       } else {
         SUIT_MessageBox::warning(SMESHGUI::desktop(),
                                  tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
@@ -2728,6 +2740,20 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       break;
     }
 
+  case 4069: // DUPLICATE NODES
+    {
+      if(checkLock(aStudy)) break;
+      if ( vtkwnd ) {
+        EmitSignalDeactivateDialog();
+        ( new SMESHGUI_DuplicateNodesDlg( this ) )->show();
+      }
+      else {
+        SUIT_MessageBox::warning(SMESHGUI::desktop(),
+                                 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"));
+      }
+      break;
+    }
+
   case 5105: // Library of selection filters
   {
     static QList<int> aTypes;
@@ -2812,8 +2838,9 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       LightApp_SelectionMgr* mgr = selectionMgr();
       SALOME_ListIO selected; mgr->selectedObjects( selected );
 
-      if (selected.Extent() == 1)       {
-        Handle(SALOME_InteractiveObject) anIObject = selected.First();
+      SALOME_ListIteratorOfListIO it(selected);
+      for( ; it.More(); it.Next()) {
+        Handle(SALOME_InteractiveObject) anIObject = it.Value();
         if(anIObject->hasEntry())
           if(SMESH_Actor *anActor = SMESH::FindActorByEntry(anIObject->getEntry())){
             anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
@@ -2876,7 +2903,8 @@ void SMESHGUI::BuildPresentation( const Handle(SALOME_InteractiveObject) & theIO
 // function : createSMESHAction
 // purpose  :
 //=======================================================================
-void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, const int key, const bool toggle  )
+void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QString& icon_id, 
+                                  const int key, const bool toggle, const QString& shortcutAction  )
 {
   QIcon icon;
   QWidget* parent = application()->desktop();
@@ -2893,7 +2921,8 @@ void SMESHGUI::createSMESHAction( const int id, const QString& po_id, const QStr
           menu       = tr( QString( "MEN_%1" ).arg( po_id ).toLatin1().data() ),
           status_bar = tr( QString( "STB_%1" ).arg( po_id ).toLatin1().data() );
 
-  createAction( id, tooltip, icon, menu, status_bar, key, parent, toggle, this, SLOT( OnGUIEvent() )  );
+  createAction( id, tooltip, icon, menu, status_bar, key, parent, 
+                toggle, this, SLOT( OnGUIEvent() ), shortcutAction );
 }
 
 //=======================================================================
@@ -3024,6 +3053,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createSMESHAction( 4066, "MERGE_ELEMENTS",  "ICON_DLG_MERGE_ELEMENTS" );
   createSMESHAction( 4067, "MESH_THROU_POINT","ICON_DLG_MOVE_NODE" );
   createSMESHAction( 4068, "SCALE",           "ICON_DLG_MESH_SCALE" );
+  createSMESHAction( 4069, "DUPLICATE_NODES", "ICON_SMESH_DUPLICATE_NODES" );
   createSMESHAction(  407, "INV",             "ICON_DLG_MESH_DIAGONAL" );
   createSMESHAction(  408, "UNION2",          "ICON_UNION2TRI" );
   createSMESHAction(  409, "ORIENT",          "ICON_DLG_MESH_ORIENTATION" );
@@ -3197,6 +3227,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createMenu( 4065, transfId, -1 );
   createMenu( 4066, transfId, -1 );
   createMenu( 4068, transfId, -1 );
+  createMenu( 4069, transfId, -1 );
 
   createMenu( 4067,modifyId, -1 );
   createMenu( 407, modifyId, -1 );
@@ -3297,6 +3328,7 @@ void SMESHGUI::initialize( CAM_Application* app )
   createTool( 4065, addRemTb );
   createTool( 4066, addRemTb );
   createTool( 4068, addRemTb );
+  createTool( 4069, addRemTb );
   createTool( separator(), addRemTb );
 
   createTool( 4067,modifyTb );
@@ -3679,6 +3711,21 @@ bool SMESHGUI::activateModule( SUIT_Study* study )
   setMenuShown( true );
   setToolShown( true );
 
+  // import Python module that manages SMESH plugins (need to be here because SalomePyQt API uses active module)
+  PyGILState_STATE gstate = PyGILState_Ensure();
+  PyObject* pluginsmanager=PyImport_ImportModule((char*)"salome_pluginsmanager");
+  if(pluginsmanager==NULL)
+    PyErr_Print();
+  else
+    {
+      PyObject* result=PyObject_CallMethod( pluginsmanager, (char*)"initialize", (char*)"isss",1,"smesh",tr("MEN_MESH").toStdString().c_str(),tr("SMESH_PLUGINS_OTHER").toStdString().c_str());
+      if(result==NULL)
+        PyErr_Print();
+      Py_XDECREF(result);
+    }
+  PyGILState_Release(gstate);
+  // end of GEOM plugins loading
+
   // Reset actions accelerator keys
   action(111)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_B)); // Import DAT
   action(112)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_U)); // Import UNV
@@ -3800,8 +3847,12 @@ void SMESHGUI::createPreferences()
   // General tab ------------------------------------------------------------------------
   int genTab = addPreference( tr( "PREF_TAB_GENERAL" ) );
 
-  int updateGroup = addPreference( tr( "PREF_GROUP_UPDATE" ), genTab );
-  addPreference( tr( "PREF_AUTO_UPDATE" ), updateGroup, LightApp_Preferences::Bool, "SMESH", "auto_update" );
+  int autoUpdate = addPreference( tr( "PREF_AUTO_UPDATE" ), genTab, LightApp_Preferences::Auto, "SMESH", "auto_update" );
+  int lim = addPreference( tr( "PREF_UPDATE_LIMIT" ), autoUpdate, LightApp_Preferences::IntSpin, "SMESH", "update_limit" );
+  setPreferenceProperty( lim, "min",  0 );
+  setPreferenceProperty( lim, "max",  100000000 );
+  setPreferenceProperty( lim, "step", 1000 );
+  setPreferenceProperty( lim, "special", tr( "PREF_UPDATE_LIMIT_NOLIMIT" ) );
 
   int qaGroup = addPreference( tr( "PREF_GROUP_QUALITY" ), genTab );
   setPreferenceProperty( qaGroup, "columns", 2 );