Salome HOME
*** empty log message ***
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 6a7cd010a8daa104ec27f7cb8d76e5bdac97fb53..0daf4dd4c25bc2c30433854483a0d89cda0a020c 100644 (file)
@@ -25,9 +25,9 @@
 //  $Header$
 
 #include "SMESHGUI.h"
-#include "SMESHGUI_InitMeshDlg.h"
-#include "SMESHGUI_AddSubMeshDlg.h"
-#include "SMESHGUI_NodesDlg.h"
+#include "SMESHGUI_InitMeshOp.h"
+#include "SMESHGUI_AddSubMeshOp.h"
+#include "SMESHGUI_NodesOp.h"
 #include "SMESHGUI_TransparencyDlg.h"
 #include "SMESHGUI_ClippingDlg.h"
 #include "SMESHGUI_GroupDlg.h"
 #include "SMESHGUI_Hypotheses.h"
 #include "SMESHGUI_HypothesesUtils.h"
 #include "SMESHGUI_MoveNodesDlg.h"
-#include "SMESHGUI_AddMeshElementDlg.h"
-#include "SMESHGUI_EditHypothesesDlg.h"
+#include "SMESHGUI_AddMeshElementOp.h"
+#include "SMESHGUI_EditHypothesesOp.h"
 #include "SMESHGUI_CreateHypothesesDlg.h"
 #include "SMESHGUI_FilterDlg.h"
 #include "SMESHGUI_FilterLibraryDlg.h"
 #include "SMESHGUI_SingleEditDlg.h"
 #include "SMESHGUI_MultiEditDlg.h"
-#include "SMESHGUI_GroupOpDlg.h"
+#include "SMESHGUI_GroupOp.h"
 #include "SMESHGUI_DeleteGroupDlg.h"
 #include "SMESHGUI_SmoothingDlg.h"
 #include "SMESHGUI_RenumberingDlg.h"
@@ -99,6 +99,8 @@
 #include "SalomeApp_Application.h"
 #include "SalomeApp_Preferences.h"
 #include "SalomeApp_VTKSelector.h"
+#include "SalomeApp_Operation.h"
+#include "SalomeApp_UpdateFlags.h"
 
 #include "SalomeApp_ImportOperation.h"
 
@@ -964,6 +966,7 @@ void SMESHGUI::ResetState()
 //=============================================================================
 void SMESHGUI::EmitSignalDeactivateDialog()
 {
+  printf( "sln: EmitSignalDeactivateDialog EmitSignalDeactivateDialog EmitSignalDeactivateDialog\n" );
   emit SignalDeactivateActiveDialog();
 }
 
@@ -1099,6 +1102,13 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   if( !mgr )
     return false;
 
+  SUIT_Operation* anOp = getOperation( theCommandID );
+  if ( anOp != 0 )
+  {
+    anOp->start();
+    return true;
+  }
+
   SUIT_ViewWindow* view = application()->desktop()->activeWindow();
   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
 
@@ -1217,7 +1227,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 400:                                    // NODES
     {
       if(checkLock(aStudy)) break;
-
+      startOperation( 400 );
+/*
       if ( vtkwnd ) {
        EmitSignalDeactivateDialog();
 
@@ -1228,7 +1239,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
                              tr("SMESH_WRN_WARNING"), 
                              tr("SMESH_WRN_VIEWER_VTK"),
                              tr("SMESH_BUT_OK"));
-      }
+      }     */
       break;
     }
 
@@ -1360,7 +1371,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 702:                                    // ADD SUB MESH
     {
       if(checkLock(aStudy)) break;
-      if( vtkwnd ) {
+      startOperation( 702 );
+/*      if( vtkwnd ) {
        EmitSignalDeactivateDialog();
        new SMESHGUI_AddSubMeshDlg( this );
       }
@@ -1368,39 +1380,35 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
        SUIT_MessageBox::warn1(desktop(),
                              tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
                              tr("SMESH_BUT_OK"));
-      }
+      }*/
       break;
     }
 
   case 703:                                    // INIT MESH
     {
       if(checkLock(aStudy)) break;
-      EmitSignalDeactivateDialog();
-      new SMESHGUI_InitMeshDlg( this );
+      startOperation( 703 );
       break;
     }
 
   case 704:                                    // EDIT Hypothesis 
     {
       if(checkLock(aStudy)) break;
-      EmitSignalDeactivateDialog();
-      new SMESHGUI_EditHypothesesDlg( this );
+      startOperation( 704 );
       break;
     }
 
   case 705:                                    //  EDIT Global Hypothesis
     {
       if(checkLock(aStudy)) break;
-      EmitSignalDeactivateDialog();
-      new SMESHGUI_EditHypothesesDlg( this );
+      startOperation( 704 );
       break;
     }
 
   case 706:                                    //  EDIT Local Hypothesis
     {
       if(checkLock(aStudy)) break;
-      EmitSignalDeactivateDialog();
-      new SMESHGUI_EditHypothesesDlg( this );
+      startOperation( 704 );
       break;
     }
 
@@ -1428,9 +1436,9 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
       */
       EmitSignalDeactivateDialog();
       if ( theCommandID == 407 )
-        new SMESHGUI_TrianglesInversionDlg(this);
+        startOperation( 407 );
       else
-        new SMESHGUI_UnionOfTwoTrianglesDlg(this);
+        startOperation( 408 );
       break;
     }
     case 409: // Change orientation
@@ -1684,24 +1692,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     case 811: // Intersect groups
     case 812: // Cut groups
     {
-      if ( !vtkwnd )
-      {
-        SUIT_MessageBox::warn1( desktop(), tr( "SMESH_WRN_WARNING" ),
-          tr( "NOT_A_VTK_VIEWER" ),tr( "SMESH_BUT_OK" ) );
-        break;
-      }
-
-      if ( checkLock( aStudy ) )
-        break;
-
-      EmitSignalDeactivateDialog();
-
-      int aMode;
-      if      ( theCommandID == 810 ) aMode = SMESHGUI_GroupOpDlg::UNION;
-      else if ( theCommandID == 811 ) aMode = SMESHGUI_GroupOpDlg::INTERSECT;
-      else                            aMode = SMESHGUI_GroupOpDlg::CUT;
-
-      ( new SMESHGUI_GroupOpDlg( this, aMode ) )->show();
+      if( !checkLock( aStudy ) )
+        startOperation( theCommandID );
       break;
     }
 
@@ -1993,7 +1985,8 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   case 4032:                                   // HEXA
     {
       if(checkLock(aStudy)) break;
-      if ( vtkwnd ) {
+      startOperation( theCommandID );
+/*      if ( vtkwnd ) {
        EmitSignalDeactivateDialog();
         SMDSAbs_ElementType type    = SMDSAbs_Edge;
         int                 nbNodes = 2;
@@ -2018,7 +2011,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
        SUIT_MessageBox::warn1(desktop(),
                              tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
                              tr("SMESH_BUT_OK"));
-      }
+      }*/
       break;
     }
   case 4033:                                   // POLYHEDRON
@@ -2464,7 +2457,7 @@ void SMESHGUI::createPopupItem( const int id,
   if( pId!=-1 )
     parentId = popupMgr()->actionId( action( pId ) );
 
-  if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
+//  if( !popupMgr()->contains( popupMgr()->actionId( action( id ) ) ) )
     popupMgr()->insert( action( id ), parentId, 0 );
 
   QChar lc = QtxPopupMgr::Selection::defEquality();
@@ -3212,3 +3205,157 @@ void SMESHGUI::createPreferences()
 void SMESHGUI::preferencesChanged( const QString&, const QString& )
 {
 }
+
+//=======================================================================
+// function : onOperationCommited
+// purpose  : SLOT called when operation commited. Set default selection mode
+//=======================================================================
+void SMESHGUI::onOperationCommited( SUIT_Operation* )
+{
+  SVTK_ViewWindow* vtkWnd =
+    dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
+  if ( vtkWnd )
+    vtkWnd->SetSelectionMode( ActorSelection );
+}
+
+//=======================================================================
+// function : onOperationAborted
+// purpose  : SLOT called when operation commited. Set default selection mode
+//=======================================================================
+void SMESHGUI::onOperationAborted( SUIT_Operation* )
+{
+  SVTK_ViewWindow* vtkWnd =
+    dynamic_cast<SVTK_ViewWindow*>( application()->desktop()->activeWindow() );
+  if ( vtkWnd )
+    vtkWnd->SetSelectionMode( ActorSelection );
+}
+
+//=======================================================================
+// function : getOperation
+// purpose  : Get operation corresponding to the given Id
+//=======================================================================
+SalomeApp_Operation* SMESHGUI::getOperation( const int theId )
+{
+  if ( myOperations.contains( theId ) )
+    return myOperations[ theId ];
+
+  // to do:
+  SalomeApp_Operation* anOp = 0;
+  /*switch( theId )
+  {
+    case ... :
+      anOp = ...;
+    break;
+  }*/
+
+  if ( anOp != 0 )
+  {
+    anOp->setModule( this );
+    connect( anOp, SIGNAL( aborted( SUIT_Operation* ) ),
+             this, SLOT( onOperationAborted( SUIT_Operation* ) ) );
+    connect( anOp, SIGNAL( commited( SUIT_Operation* ) ),
+             this, SLOT( onOperationCommited( SUIT_Operation* ) ) );
+    myOperations[ theId ] = anOp;
+    
+  }
+
+  return anOp;
+}
+
+//=======================================================================
+// function : update
+// purpose  : Update something
+//=======================================================================
+void SMESHGUI::update( const int flags )
+{
+  if ( flags & UF_Viewer | flags & UF_Forced )
+    SMESH::UpdateView();
+  else
+    SalomeApp_Module::update( flags );
+}
+
+//=======================================================================
+// function : updateControls
+// purpose  : Update state of controls
+//=======================================================================
+void SMESHGUI::updateControls()
+{
+  // to do
+}
+
+//=======================================================================
+// function : updateControls
+// purpose  : Update state of controls
+//=======================================================================
+SalomeApp_Operation* SMESHGUI::createOperation( const int id ) const
+{
+  SalomeApp_Operation* op = 0;
+  switch( id )
+  {     
+    case 400:
+      op = new SMESHGUI_NodesOp();
+      break;
+
+    case 401:
+      op = new SMESHGUI_AddMeshElementOp( SMDSAbs_Edge, 2 );
+      break;
+      
+    case 4021:
+      op = new SMESHGUI_AddMeshElementOp( SMDSAbs_Face, 3 );
+      break;
+      
+    case 4022:
+      op = new SMESHGUI_AddMeshElementOp( SMDSAbs_Face, 4 );
+      break;
+      
+    case 4023:
+      op = new SMESHGUI_AddMeshElementOp( SMDSAbs_Face, 5 ); // 5 - identificator for POLYGON
+      break;
+      
+    case 4031:
+      op = new SMESHGUI_AddMeshElementOp( SMDSAbs_Volume, 4 );
+      break;
+      
+    case 4032:
+      op = new SMESHGUI_AddMeshElementOp( SMDSAbs_Volume, 8 );
+      break;
+            
+    case 702:
+      op = new SMESHGUI_AddSubMeshOp();
+      break;
+      
+    case 703:
+      op = new SMESHGUI_InitMeshOp();
+      break;
+
+    case 704:
+      op = new SMESHGUI_EditHypothesesOp();
+      break;
+
+    case 810:
+      op = new SMESHGUI_GroupOp( SMESHGUI_GroupOp::UNION );
+      break;
+
+    case 811:
+      op = new SMESHGUI_GroupOp( SMESHGUI_GroupOp::INTERSECT );
+      break;
+
+    case 812:
+      op = new SMESHGUI_GroupOp( SMESHGUI_GroupOp::CUT );
+      break;
+      
+    default:
+      op = SalomeApp_Module::createOperation( id );
+      break;
+  }
+  return op;
+}
+
+
+
+
+
+
+
+
+