Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshDlg.cxx
index 8f427ffe9f7eae7d56db26505623f46eff8aa842..e05e2022df3ef9fe44b8edaed9bc4761a9aa68d0 100644 (file)
@@ -1,3 +1,22 @@
+// Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// 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/
+//
 /**
 *  SMESH SMESHGUI
 *
@@ -25,6 +44,7 @@
 #include <qcombobox.h>
 #include <qpopupmenu.h>
 #include <qcursor.h>
+#include <qpushbutton.h>
 
 /*!
  * \brief Tab for tab widget containing controls for definition of 
@@ -95,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
   
@@ -121,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();
@@ -128,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 );
 }
 
 //================================================================================
@@ -147,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 );
   }
 }
@@ -166,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 );
 }
 
 //================================================================================
@@ -268,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 );
+  }
 }
 
 //================================================================================
@@ -351,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
   
@@ -358,17 +394,22 @@ 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();
+  QButton* aHypoSetButton = new QPushButton( mainFrame(), "aHypoSetButton");
+  aHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
   
   // Fill layout
-  
   QVBoxLayout* aLay = new QVBoxLayout( mainFrame(), 0, 5 );
   aLay->addWidget( aGrp );
   aLay->addItem( new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum) );
   aLay->addWidget( myTabWg );
-  
+  aLay->addWidget( aHypoSetButton );
+
   // Disable controls if necessary
   setObjectShown( Mesh, false );
   if ( theToCreate )
@@ -389,10 +430,16 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh
     objectWg( Mesh, Btn )->hide();
     objectWg( Geom, Btn )->hide();
   }
+
+  // Connect signals and slots
+  connect( aHypoSetButton, SIGNAL( clicked() ), SLOT( onHypoSetButton() ) );
+  connect( myHypoSetPopup, SIGNAL( activated( int ) ), SLOT( onHypoSetPopup( int ) ) );
 }
 
 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
 {
+  if ( myHypoSetPopup )
+    delete myHypoSetPopup;
 }
 
 //================================================================================
@@ -430,18 +477,102 @@ void SMESHGUI_MeshDlg::reset()
 //================================================================================    
 void SMESHGUI_MeshDlg::setCurrentTab( const int theId  )
 {
-  myTabWg->setCurrentPage( theId );
+  myTabWg->setCurrentPage( Dim3D - theId );
 }
-  
 
+//================================================================================
+/*!
+ * \brief Enable/disable tabs
+  * \param int - maximum possible dimention
+ */
+//================================================================================
 
+void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
+{
+  const int DIM = maxDim - 1;
+  for ( int dim = Dim1D; dim <= Dim3D; ++dim ) {
+    bool enable = ( dim <= DIM );
+    if ( !enable )
+      myTabs[ dim ]->reset();
+    myTabWg->setTabEnabled( myTabs[ dim ], enable );
+  }
+  // deselect desabled tab
+  if ( !myTabWg->isTabEnabled( myTabWg->currentPage() ))
+    setCurrentTab( DIM - 1 );
+}
 
+//================================================================================
+/*!
+ * \brief Sets list of available Sets of Hypotheses
+ */
+//================================================================================
 
+void SMESHGUI_MeshDlg::setHypoSets( const QStringList& theSets )
+{
+  myHypoSetPopup->clear();
+  for ( int i = 0, n = theSets.count(); i < n; i++ ) {
+    myHypoSetPopup->insertItem( theSets[ i ], i );
+  }
+}
 
+//================================================================================
+/*!
+ * \brief Emits hypoSet signal
+ * 
+ * SLOT is called when a hypotheses set is selected. Emits hypoSet
+ * signal to notify operation about this event
+ */
+//================================================================================
 
+void SMESHGUI_MeshDlg::onHypoSetPopup( int theIndex )
+{
+  emit hypoSet( myHypoSetPopup->text( theIndex ));
+}
+  
+//================================================================================
+/*!
+ * \brief Shows myHypoSetPopup
+ */
+//================================================================================
 
+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 );
+}