Salome HOME
Fix Bug IPAL8770: There is no any warning message if to export polygonal elements...
[modules/smesh.git] / src / SMESHGUI / SMESHGUI.cxx
index 6f22f89613b8334cd2e9aabe7fe9c3b9165c2a9b..2c49e211ecc167a32529d775be8f98a6aa6614eb 100644 (file)
 #include <SVTK_ViewWindow.h>
 #include <SVTK_ViewModel.h>
 
+#include <VTKViewer_ViewManager.h>
+
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_GEOMGenUtils.h"
 #include "SMESHGUI_MeshUtils.h"
@@ -238,6 +240,8 @@ namespace{
                                QObject::tr("SMESH_BUT_OK"));
          wc.resume();
        }
+
+       SMESHGUI::GetSMESHGUI()->updateObjBrowser();
       }
       catch (const SALOME::SALOME_Exception& S_ex){
        wc.suspend();
@@ -303,9 +307,26 @@ namespace{
            SUIT_FileDlg* fd = new SUIT_FileDlg( SMESHGUI::desktop(), false, true, true );
            fd->setCaption( aTitle );
            fd->setFilters( filters );
-           fd->exec();
-           aFilename = fd->selectedFile();
-           aFormat = aFilterMap[fd->selectedFilter()];
+           bool is_ok = false;
+           while(!is_ok){
+             fd->exec();
+             aFilename = fd->selectedFile();
+             aFormat = aFilterMap[fd->selectedFilter()];
+             is_ok = true;
+             if( !aFilename.isEmpty()
+                 && (aMesh->NbPolygons()>0 or aMesh->NbPolyhedrons()>0) 
+                 && aFormat==SMESH::MED_V2_1){
+               int aRet = SUIT_MessageBox::warn2(SMESHGUI::desktop(),
+                                                 QObject::tr("SMESH_WRN_WARNING"),
+                                                 QObject::tr("SMESH_EXPORT_MED_V2_1").arg(anIObject->getName()),
+                                                 QObject::tr("SMESH_BUT_YES"),
+                                                 QObject::tr("SMESH_BUT_NO"),
+                                                 0,1,0);
+               if(aRet){
+                 is_ok = false;
+               }
+             }
+           }
            delete fd;
          }
        if ( !aFilename.isEmpty() ) {
@@ -800,46 +821,10 @@ namespace{
   }
 }
 
-//=============================================================================
-/*!
- *
- */
-//=============================================================================
-class CustomItem : public QCustomMenuItem
-{
-public:
-  CustomItem(const QString& s, const QFont& f) : myString(s), myFont(f) {}
-  ~CustomItem() {}
-
-  void paint(QPainter* p, const QColorGroup& cg, bool act, bool /*enabled*/, int x, int y, int w, int h)
-  {
-    p->save();
-    p->fillRect( x, y, w, h, act ? cg.highlight() : cg.mid() );
-    p->setPen( act ? cg.highlightedText() : cg.buttonText() );
-    p->setFont( myFont );
-    p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
-    p->restore();
-  }
-
-  QSize sizeHint()
-  {
-    return QFontMetrics( myFont ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip | SingleLine, myString );
-  }
-
-  bool fullSpan() const
-  {
-    return true;
-  }
-
-private:
-  QString myString;
-  QFont   myFont;
-};
-
 extern "C" {
   Standard_EXPORT CAM_Module* createModule()
   {
-    return SMESHGUI::GetSMESHGUI();
+    return new SMESHGUI();
   }
 }
 
@@ -851,7 +836,7 @@ SMESH::SMESH_Gen_var SMESHGUI::myComponentSMESH = SMESH::SMESH_Gen::_nil();
  */
 //=============================================================================
 SMESHGUI::SMESHGUI() :
-  SalomeApp_Module( "SMESH" )
+SalomeApp_Module( "SMESH" )
 {
   if ( CORBA::is_nil( myComponentSMESH ) )
   {
@@ -860,6 +845,7 @@ SMESHGUI::SMESHGUI() :
     myComponentSMESH = SMESH::SMESH_Gen::_narrow( comp );
   }
 
+  myAutomaticUpdate = false;
   myActiveDialogBox = 0 ;
   myState = -1 ;
 
@@ -911,24 +897,32 @@ SUIT_ResourceMgr* SMESHGUI::resourceMgr()
 //=============================================================================
 SMESHGUI* SMESHGUI::GetSMESHGUI()
 {
-  static SMESHGUI* aSMESHGUI = NULL;
-  if( !aSMESHGUI )
-    aSMESHGUI = new SMESHGUI();
-
-  if(_PTR(Study) aStudy = SMESH::GetActiveStudyDocument())
-    GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
+  SMESHGUI* smeshMod = 0;
+  SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
+  if ( app )
+  {
+    CAM_Module* module = app->module( "Mesh" );
+    smeshMod = dynamic_cast<SMESHGUI*>( module );
+  }
 
-  SUIT_ResourceMgr* mgr = resourceMgr();
-  if( mgr )
-  /* Automatic Update flag */
-    aSMESHGUI->myAutomaticUpdate = ( mgr->stringValue( "SMESH", "AutomaticUpdate" ).compare( "true" ) == 0 );
+  if ( smeshMod && smeshMod->application() && smeshMod->application()->activeStudy() )
+  {
+    SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( smeshMod->application()->activeStudy() );
+    if ( study )
+    {
+      _PTR(Study) aStudy = study->studyDS();
+      if ( aStudy )
+       GetSMESHGen()->SetCurrentStudy( _CAST(Study,aStudy)->GetStudy() );
+    }
+  }
 
-  return aSMESHGUI;
+  return smeshMod;
 }
 
 extern "C"
 {
-  Standard_EXPORT SMESHGUI* GetComponentGUI() {
+  Standard_EXPORT SMESHGUI* GetComponentGUI()
+  {
     return SMESHGUI::GetSMESHGUI();
   }
 }
@@ -1095,11 +1089,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
   if( !mgr )
     return false;
 
-  SUIT_ViewManager* vm = application()->activeViewManager();
-  if( !vm )
-    return false;
-
-  SUIT_ViewWindow* view =vm->getActiveView();
+  SUIT_ViewWindow* view = application()->desktop()->activeWindow();
   SVTK_ViewWindow* vtkwnd = dynamic_cast<SVTK_ViewWindow*>( view );
 
   QAction* act = action( theCommandID );
@@ -1177,6 +1167,10 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     {
       if(checkLock(aStudy)) break;
       SMESH::UpdateView();
+
+      SALOME_ListIO l;
+      SalomeApp_SelectionMgr *aSel = SMESHGUI::selectionMgr();
+      aSel->setSelectedObjects( l );
       break;
     }
 
@@ -1350,6 +1344,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
                              tr("SMESH_WRN_VIEWER_VTK"),
                              tr("SMESH_BUT_OK"));
       }
+      updateObjBrowser();
       break;
     }
 
@@ -1530,6 +1525,13 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
     }
   case 801:                                     // CREATE GROUP
     {
+      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();
       SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
@@ -1551,6 +1553,13 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
   case 802:                                     // CONSTRUCT GROUP
     {
+      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();
 
@@ -1812,7 +1821,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
        mgr->setValue( "SMESH", "SettingsElementsSelectTol", aTolItems );
 
        // update current study settings
-       SMESH::UpdateSelectionProp();
+       SMESH::UpdateSelectionProp( this );
 
        if( vtkwnd ) {
          // update VTK viewer properties
@@ -1878,6 +1887,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
           }
         }
       }
+      updateObjBrowser( true );
       break;
     }
 
@@ -2263,7 +2273,7 @@ bool SMESHGUI::OnGUIEvent( int theCommandID )
 
   }
 
-  updateObjBrowser();
+  //updateObjBrowser();
   return true;
 }
 
@@ -2304,7 +2314,6 @@ bool SMESHGUI::OnKeyPress( QKeyEvent * pe, SUIT_ViewWindow * wnd )
 //=============================================================================
 bool SMESHGUI::SetSettings(SUIT_Desktop* parent)
 {
-  MESSAGE("SMESHGUI::SetSettings.");
   SMESHGUI::GetSMESHGUI();
   
   SUIT_ResourceMgr* mgr = resourceMgr();
@@ -2343,6 +2352,7 @@ bool SMESHGUI::SetSettings(SUIT_Desktop* parent)
     action( 10001 )->setOn( false );
     action( 10003 )->setOn( true );
   }
+
   action( 10003 )->setOn( Shrink );
 
   // Automatic Update
@@ -2361,10 +2371,12 @@ bool SMESHGUI::SetSettings(SUIT_Desktop* parent)
     action( 10071 )->setOn( false );
 
   // Selection
-  SMESH::UpdateSelectionProp();
+  SMESH::UpdateSelectionProp( this );
 
   // menus disable
-  //action( 111 )->setEnabled( false );        // IMPORT DAT
+  action( 111 )->setEnabled( false );  // IMPORT DAT
+
+  //action( 112 )->setEnabled( false );
   //parent->menuBar()->setItemEnabled(112, false);     // IMPORT UNV
 
   return true;
@@ -2448,6 +2460,11 @@ void SMESHGUI::initialize( CAM_Application* app )
 {
   SalomeApp_Module::initialize( app );
 
+  SUIT_ResourceMgr* mgr = app->resourceMgr();
+  if ( mgr )
+  /* Automatic Update flag */
+    myAutomaticUpdate = mgr->booleanValue( "SMESH", "AutomaticUpdate", myAutomaticUpdate );
+
   // ----- create actions --------------
 
   createSMESHAction(  111, "DAT", "", (CTRL+Key_B) );
@@ -2829,17 +2846,18 @@ void SMESHGUI::initialize( CAM_Application* app )
     isNotEmpty("numberOfNodes <> 0"),
 
     // has nodes, edges, etc in VISIBLE! actor
-    hasNodes("(numberOfNodes > 0 && isVisible)"),
-    hasElems("count( elemTypes ) > 0"),
-    hasDifferentElems("count( elemTypes ) > 1"),
-    hasEdges("{'Edge'} in elemTypes"),
-    hasFaces("{'Face'} in elemTypes"),
-    hasVolumes("{'Volume'} in elemTypes");
+    hasNodes("(numberOfNodes > 0 )"),//&& isVisible)"),
+    hasElems("(count( elemTypes ) > 0)"),
+    hasDifferentElems("(count( elemTypes ) > 1)"),
+    hasEdges("({'Edge'} in elemTypes)"),
+    hasFaces("({'Face'} in elemTypes)"),
+    hasVolumes("({'Volume'} in elemTypes)");
 
   QString aSelCount = QString( "%1 = 1" ).arg( QtxPopupMgr::Selection::defSelCountParam() );
-  QString aClient = QString( "%1client in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() ).arg( View );
+  QString lc = QtxPopupMgr::Selection::defEquality();
+  QString aClient = QString( "%1client in {%2}" ).arg( lc ).arg( "'VTKViewer'" );
   QString aType = QString( "%1type in {%2}" ).arg( QtxPopupMgr::Selection::defEquality() ).arg( mesh_group );
-  QString aMeshInVTK = aClient + "&&" + aType + "&&" + aSelCount;
+  QString aMeshInVTK = aClient + "&&" + aType;// + "&&" + aSelCount;
   
   //-------------------------------------------------
   // Numbering
@@ -3016,6 +3034,9 @@ void SMESHGUI::initialize( CAM_Application* app )
   popupMgr()->setRule( action( 302 ), aRule + "&&" + isNotEmpty, true );
 
   popupMgr()->insert( separator(), -1, -1 );
+
+  connect( application(), SIGNAL( viewManagerAdded( SUIT_ViewManager* ) ), 
+          this, SLOT( onViewManagerAdded( SUIT_ViewManager* ) ) );
 }
 
 bool SMESHGUI::activateModule( SUIT_Study* study )
@@ -3024,9 +3045,9 @@ bool SMESHGUI::activateModule( SUIT_Study* study )
 
   setMenuShown( true );
   setToolShown( true );
+  SetSettings( desktop() );
 
   return res;
-  //SetSettings( desktop() );
 }
 
 bool SMESHGUI::deactivateModule( SUIT_Study* study )
@@ -3051,6 +3072,11 @@ void SMESHGUI::OnGUIEvent()
 
 SMESH::SMESH_Gen_var SMESHGUI::GetSMESHGen()
 {
+  if ( CORBA::is_nil( myComponentSMESH ) )
+    {
+      SMESHGUI aGUI; //SRN BugID: IPAL9186: Create an instance of SMESHGUI to initialize myComponentSMESH
+      return aGUI.myComponentSMESH;
+    }  
   return myComponentSMESH;
 }
 
@@ -3078,3 +3104,9 @@ void SMESHGUI::viewManagers( QStringList& list ) const
 {
   list.append( SVTK_Viewer::Type() );
 }
+
+void SMESHGUI::onViewManagerAdded( SUIT_ViewManager* mgr )
+{
+  if( dynamic_cast<VTKViewer_ViewManager*>( mgr ) )
+    SMESH::UpdateSelectionProp( this );
+}