Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshDlg.cxx
index 6d9e88e588efae9c0304b35a2d9d39b2e44e5573..e05e2022df3ef9fe44b8edaed9bc4761a9aa68d0 100644 (file)
@@ -115,6 +115,7 @@ SMESHGUI_MeshTab::SMESHGUI_MeshTab( QWidget* theParent )
     connect( myEditHyp[ i ], SIGNAL( clicked() ), SLOT( onEditHyp() ) );
     connect( myHyp[ i ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
   }
+  connect( myHyp[ Algo ], SIGNAL( activated( int ) ), SLOT( onHyp( int ) ) );
   
   // Initialize controls
   
@@ -141,6 +142,8 @@ SMESHGUI_MeshTab::~SMESHGUI_MeshTab()
 void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& theHyps )
 {
   myAvailableHyps[ theId ] = theHyps;
+
+  bool enable = ! theHyps.isEmpty();
   if ( theId == Algo )
   {
     myHyp[ Algo ]->clear();
@@ -148,6 +151,11 @@ void SMESHGUI_MeshTab::setAvailableHyps( const int theId, const QStringList& the
     myHyp[ Algo ]->insertStringList( theHyps );
     myHyp[ Algo ]->setCurrentItem( 0 );
   }
+  else {
+    myCreateHyp[ theId ]->setEnabled( enable );
+    myEditHyp[ theId ]->setEnabled( false );
+  }
+  myHyp[ theId ]->setEnabled( enable );
 }
 
 //================================================================================
@@ -167,6 +175,7 @@ void SMESHGUI_MeshTab::setExistingHyps( const int theId, const QStringList& theH
     myHyp[ theId ]->insertItem( tr( "NONE" ) );
     myHyp[ theId ]->insertStringList( theHyps );
     myHyp[ theId ]->setCurrentItem( 0 );
+    myHyp[ theId ]->setEnabled( !theHyps.isEmpty() );
     myEditHyp[ theId ]->setEnabled( false );
   }
 }
@@ -186,6 +195,7 @@ void SMESHGUI_MeshTab::addHyp( const int theId, const QString& theHyp )
   myHyp[ theId ]->insertItem( theHyp );
   myHyp[ theId ]->setCurrentItem( myHyp[ theId ]->count() - 1 );
   myEditHyp[ theId ]->setEnabled( true );
+  myHyp[ theId ]->setEnabled( true );
 }
 
 //================================================================================
@@ -288,22 +298,27 @@ void SMESHGUI_MeshTab::onEditHyp()
 {
   const QObject* aSender = sender();
   int aHypType = aSender == myEditHyp[ MainHyp ] ? MainHyp : AddHyp;
-  emit editHyp( aHypType, myHyp[ aHypType ]->currentItem() );
+  emit editHyp( aHypType, myHyp[ aHypType ]->currentItem() - 1 );  // - 1 because there is NONE on the top
 }
 
 //================================================================================
 /*!
  * \brief Updates "Edit hypothesis" button state
  * 
- * SLOT called when current hypothesis changed disables "Edit hypothesis" button
- * if current hypothesis is <None>, enables otherwise
+ * SLOT called when current hypothesis changed. Disables "Edit hypothesis" button
+ * if current hypothesis is <None>, enables otherwise.
+ * If an algorithm changed, emits selectAlgo( theIndex ) signal
  */
 //================================================================================
 void SMESHGUI_MeshTab::onHyp( int theIndex )
 {
   const QObject* aSender = sender();
-  int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
-  myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
+  if ( aSender == myHyp[ Algo ] )
+    emit selectAlgo( theIndex - 1 ); // - 1 because there is NONE on the top
+  else {
+    int anIndex = aSender == myHyp[ MainHyp ] ? MainHyp : AddHyp;
+    myEditHyp[ anIndex ]->setEnabled( theIndex > 0 );
+  }
 }
 
 //================================================================================
@@ -371,6 +386,7 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh
   createObject( tr( "MESH" ), aGrp, Mesh );
   // geometry
   createObject( tr( "GEOMETRY" ), aGrp, Geom );
+  myGeomPopup = 0;
   
   // Create tab widget
   
@@ -378,9 +394,9 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh
   myTabs[ Dim1D ] = new SMESHGUI_MeshTab( myTabWg );
   myTabs[ Dim2D ] = new SMESHGUI_MeshTab( myTabWg );
   myTabs[ Dim3D ] = new SMESHGUI_MeshTab( myTabWg );
-  myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
-  myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
   myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
+  myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
+  myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
 
   // Hypotheses Sets
   myHypoSetPopup = new QPopupMenu();
@@ -461,7 +477,7 @@ void SMESHGUI_MeshDlg::reset()
 //================================================================================    
 void SMESHGUI_MeshDlg::setCurrentTab( const int theId  )
 {
-  myTabWg->setCurrentPage( theId );
+  myTabWg->setCurrentPage( Dim3D - theId );
 }
 
 //================================================================================
@@ -473,13 +489,16 @@ void SMESHGUI_MeshDlg::setCurrentTab( const int theId  )
 
 void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
 {
-  for ( int i = Dim1D; i <= Dim3D; ++i ) {
-    int dim = i + 1;
-    bool enable = ( dim <= maxDim );
+  const int DIM = maxDim - 1;
+  for ( int dim = Dim1D; dim <= Dim3D; ++dim ) {
+    bool enable = ( dim <= DIM );
     if ( !enable )
-      myTabs[ i ]->reset();
-    myTabWg->setTabEnabled( myTabs[ i ], enable );
+      myTabs[ dim ]->reset();
+    myTabWg->setTabEnabled( myTabs[ dim ], enable );
   }
+  // deselect desabled tab
+  if ( !myTabWg->isTabEnabled( myTabWg->currentPage() ))
+    setCurrentTab( DIM - 1 );
 }
 
 //================================================================================
@@ -520,3 +539,40 @@ void SMESHGUI_MeshDlg::onHypoSetButton()
 {
   myHypoSetPopup->exec( QCursor::pos() );
 }
+
+//================================================================================
+/*!
+ * \brief Enable showing of the popup when Geometry selection btn is clicked
+  * \param enable - true to enable
+ */
+//================================================================================
+
+enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
+
+void SMESHGUI_MeshDlg::setGeomPopupEnabled( const bool enable )
+{
+  if ( QButton* selBtn = dynamic_cast<QButton*>( objectWg( Geom, Btn )))
+  {
+    disconnect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
+    if ( enable ) {
+      if ( ! myGeomPopup ) {
+        myGeomPopup = new QPopupMenu();
+        myGeomPopup->insertItem( tr("DIRECT_GEOM_SELECTION"), DIRECT_GEOM_INDEX );
+        myGeomPopup->insertItem( tr("GEOM_BY_MESH_ELEM_SELECTION"), GEOM_BY_MESH_INDEX );
+        connect( myGeomPopup, SIGNAL( activated( int ) ), SLOT( onGeomPopup( int ) ) );
+      }
+      connect( selBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
+    }
+  }
+}
+
+void SMESHGUI_MeshDlg::onGeomSelectionButton(bool isBtnOn)
+{
+  if ( myGeomPopup && isBtnOn )
+    myGeomPopup->exec( QCursor::pos() );
+}
+
+void SMESHGUI_MeshDlg::onGeomPopup( int index )
+{
+  emit geomSelectionByMesh( index == GEOM_BY_MESH_INDEX );
+}