Salome HOME
PAL10237. Add a button assigning a set of hypotheses
authoreap <eap@opencascade.com>
Tue, 1 Nov 2005 10:28:04 +0000 (10:28 +0000)
committereap <eap@opencascade.com>
Tue, 1 Nov 2005 10:28:04 +0000 (10:28 +0000)
src/SMESHGUI/SMESHGUI_MeshDlg.cxx
src/SMESHGUI/SMESHGUI_MeshDlg.h
src/SMESHGUI/SMESHGUI_MeshOp.cxx
src/SMESHGUI/SMESHGUI_MeshOp.h
src/SMESHGUI/SMESH_msg_en.po

index 8f427ffe9f7eae7d56db26505623f46eff8aa842..1454dcbf8013f4b6de83b34fa23242a63afb726a 100644 (file)
@@ -25,6 +25,7 @@
 #include <qcombobox.h>
 #include <qpopupmenu.h>
 #include <qcursor.h>
 #include <qcombobox.h>
 #include <qpopupmenu.h>
 #include <qcursor.h>
+#include <qpushbutton.h>
 
 /*!
  * \brief Tab for tab widget containing controls for definition of 
 
 /*!
  * \brief Tab for tab widget containing controls for definition of 
@@ -361,14 +362,19 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh
   myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
   myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
   myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
   myTabWg->addTab( myTabs[ Dim1D ], tr( "DIM_1D" ) );
   myTabWg->addTab( myTabs[ Dim2D ], tr( "DIM_2D" ) );
   myTabWg->addTab( myTabs[ Dim3D ], tr( "DIM_3D" ) );
+
+  // Hypotheses Sets
+  myHypoSetPopup = new QPopupMenu();
+  QButton* aHypoSetButton = new QPushButton( mainFrame(), "aHypoSetButton");
+  aHypoSetButton->setText( tr( "HYPOTHESES_SETS" ) );
   
   // Fill layout
   
   // 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 );
   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 )
   // Disable controls if necessary
   setObjectShown( Mesh, false );
   if ( theToCreate )
@@ -389,10 +395,16 @@ SMESHGUI_MeshDlg::SMESHGUI_MeshDlg( const bool theToCreate, const bool theIsMesh
     objectWg( Mesh, Btn )->hide();
     objectWg( Geom, Btn )->hide();
   }
     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()
 {
 }
 
 SMESHGUI_MeshDlg::~SMESHGUI_MeshDlg()
 {
+  if ( myHypoSetPopup )
+    delete myHypoSetPopup;
 }
 
 //================================================================================
 }
 
 //================================================================================
@@ -432,16 +444,60 @@ void SMESHGUI_MeshDlg::setCurrentTab( const int theId  )
 {
   myTabWg->setCurrentPage( theId );
 }
 {
   myTabWg->setCurrentPage( theId );
 }
-  
-
-
-
-
-
 
 
+//================================================================================
+/*!
+ * \brief Enable/disable tabs
+  * \param int - maximum possible dimention
+ */
+//================================================================================
 
 
+void SMESHGUI_MeshDlg::setMaxHypoDim( const int maxDim )
+{
+  for ( int i = Dim1D; i <= Dim3D; ++i ) {
+    int dim = i + 1;
+    bool enable = ( dim <= maxDim );
+    if ( !enable )
+      myTabs[ i ]->reset();
+    myTabWg->setTabEnabled( myTabs[ i ], enable );
+  }
+}
 
 
+//================================================================================
+/*!
+ * \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() );
+}
index 47fb33a3409cb4f934f4abae19a13283f027e641..0a03ddbf7ea04e3b8793430c99bbee404e2bd85e 100644 (file)
@@ -50,11 +50,23 @@ public:
   SMESHGUI_MeshTab*            tab( const int ) const;
   void                         reset();
   void                         setCurrentTab( const int );
   SMESHGUI_MeshTab*            tab( const int ) const;
   void                         reset();
   void                         setCurrentTab( const int );
+  void                         setMaxHypoDim( const int );
+  void                         setHypoSets( const QStringList& );
+
+signals:
+
+  void                         hypoSet( const QString& );
+
+private slots:  
+
+  void                         onHypoSetPopup( int );
+  void                         onHypoSetButton();
 
 private:
 
 private:
-  
+
   QMap< int, SMESHGUI_MeshTab* > myTabs;
   QTabWidget*                    myTabWg;
   QMap< int, SMESHGUI_MeshTab* > myTabs;
   QTabWidget*                    myTabWg;
+  QPopupMenu*                    myHypoSetPopup;
 };
 
 /*!
 };
 
 /*!
index e001bea8eb89673236448ffb97fed305c25044fa..f7d370d9e880a3ca668902f65341d209838e018e 100644 (file)
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_GEOMGenUtils.h"
 
 #include "SMESHGUI_Utils.h"
 #include "SMESHGUI_GEOMGenUtils.h"
 
-#include <SMESH_TypeFilter.hxx>
-#include <SMESH_NumberFilter.hxx>
+#include "SMESH_TypeFilter.hxx"
+#include "SMESH_NumberFilter.hxx"
+
+#include "GEOM_SelectionFilter.h"
 
 
-#include <GEOM_SelectionFilter.h>
+#include "SalomeApp_Tools.h"
+#include "SALOMEDSClient_Study.hxx"
+#include "SALOMEDSClient_AttributeIOR.hxx"
+#include "SALOMEDSClient_AttributeName.hxx"
+#include "SALOMEDS_SComponent.hxx"
+#include "SALOMEDS_SObject.hxx"
 
 
-#include <SalomeApp_Tools.h>
-#include <SALOMEDSClient_Study.hxx>
-#include <SALOMEDSClient_AttributeIOR.hxx>
-#include <SALOMEDSClient_AttributeName.hxx>
-#include <SALOMEDS_SComponent.hxx>
 
 
-#include <SalomeApp_SelectionMgr.h>
-#include <SalomeApp_UpdateFlags.h>
-#include <SUIT_MessageBox.h>
-#include <SUIT_Desktop.h>
-#include <SUIT_OverrideCursor.h>
+#include "SalomeApp_SelectionMgr.h"
+#include "SalomeApp_UpdateFlags.h"
+#include "SUIT_MessageBox.h"
+#include "SUIT_Desktop.h"
+#include "SUIT_OverrideCursor.h"
 
 
-#include <utilities.h>
+#include "GEOMBase.h"
+
+#include "utilities.h"
 
 #include <qstringlist.h>
 #include <qlineedit.h>
 
 
 #include <qstringlist.h>
 #include <qlineedit.h>
 
-#include <SALOMEDS_SObject.hxx>
-
-#define DEB_SLN
+#include <TopoDS_Shape.hxx>
+#include <TopExp_Explorer.hxx>
 
 //================================================================================
 /*!
 
 //================================================================================
 /*!
@@ -167,6 +170,7 @@ void SMESHGUI_MeshOp::startOperation()
       connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
               this, SLOT( onEditHyp( const int, const int) ) );
     }
       connect( myDlg->tab( i ), SIGNAL( editHyp( const int, const int ) ),
               this, SLOT( onEditHyp( const int, const int) ) );
     }
+    connect( myDlg, SIGNAL( hypoSet( const QString& )), SLOT( onHypoSet( const QString& )));
   }
   SMESHGUI_SelectionOp::startOperation();
 
   }
   SMESHGUI_SelectionOp::startOperation();
 
@@ -195,6 +199,8 @@ void SMESHGUI_MeshOp::startOperation()
   else
     myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
 
   else
     myDlg->activateObject( SMESHGUI_MeshDlg::Obj );
 
+  myDlg->setHypoSets( SMESH::GetHypothesesSets() );
+
   selectionDone();
 
   myDlg->setCurrentTab( SMESH::DIM_1D );
   selectionDone();
 
   myDlg->setCurrentTab( SMESH::DIM_1D );
@@ -266,6 +272,54 @@ void SMESHGUI_MeshOp::selectionDone()
     {
     }
   }
     {
     }
   }
+
+  // Enable tabs according to shape dimension
+
+  int shapeDim = 3;
+  if ( myToCreate )
+  {
+    try
+    {
+      QString aGeomEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+      _PTR(SObject) pGeom = studyDS()->FindObjectID( aGeomEntry.latin1() );
+      if ( pGeom ) {
+        GEOM::GEOM_Object_var aGeomVar =
+          GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
+        if ( !aGeomVar->_is_nil() ) {
+          shapeDim = 0;
+          switch ( aGeomVar->GetShapeType() ) {
+          case GEOM::SOLID:
+          case GEOM::SHELL:  shapeDim = 3; break;
+          case GEOM::FACE:   shapeDim = 2; break;
+          case GEOM::WIRE:   
+          case GEOM::EDGE:   shapeDim = 1; break;
+          case GEOM::VERTEX: shapeDim = 0; break;
+          default:
+            TopoDS_Shape aShape;
+            if ( GEOMBase::GetShape(aGeomVar, aShape)) {
+              TopExp_Explorer exp( aShape, TopAbs_SHELL );
+              if ( exp.More() )
+                shapeDim = 3;
+              else if ( exp.Init( aShape, TopAbs_FACE ), exp.More() )
+                shapeDim = 2;
+              else if ( exp.Init( aShape, TopAbs_EDGE ), exp.More() )
+                shapeDim = 1;
+              else
+                shapeDim = 0;
+            }
+          }
+        }
+      }
+    }
+    catch ( const SALOME::SALOME_Exception& S_ex )
+    {
+      SalomeApp_Tools::QtCatchCorbaException( S_ex );
+    }
+    catch ( ... )
+    {
+    }
+  }
+  myDlg->setMaxHypoDim( shapeDim );
 }
 
 //================================================================================
 }
 
 //================================================================================
@@ -530,6 +584,78 @@ void SMESHGUI_MeshOp::onEditHyp( const int theHypType, const int theIndex )
     aCreator->EditHypothesis( aHyp );
 }
 
     aCreator->EditHypothesis( aHyp );
 }
 
+//================================================================================
+/*!
+ * \brief Creates and selects hypothesis of hypotheses set 
+  * \param theSetName - The name of hypotheses set
+ */
+//================================================================================
+
+void SMESHGUI_MeshOp::onHypoSet( const QString& theSetName )
+{
+  HypothesesSet* aHypoSet = SMESH::GetHypothesesSet( theSetName );
+  if ( !aHypoSet ) return;
+
+  for ( int aHypType = Algo; aHypType < AddHyp; aHypType++ )
+  {
+    bool isAlgo = (aHypType == Algo);
+
+    // clear all hyps
+    for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
+      setCurrentHyp( dim, aHypType, -1 );
+
+    // set hyps from the set
+    
+    QStringList* aHypoList = isAlgo ? & aHypoSet->AlgoList : & aHypoSet->HypoList;
+    for ( int i = 0, n = aHypoList->count(); i < n; i++ )
+    {
+      const QString& aHypoTypeName = (*aHypoList)[ i ];
+      HypothesisData* aHypData = SMESH::GetHypothesisData( aHypoTypeName );
+      int aDim = aHypData->Dim[0];
+      // create or/and set
+      int index = -1;
+      if ( isAlgo )
+      {
+        QStringList aHypTypeNameList = SMESH::GetAvailableHypotheses( isAlgo, aDim );
+        index = aHypTypeNameList.findIndex( aHypoTypeName );
+        if ( index < 0 ) continue;
+        setCurrentHyp ( aDim, aHypType, index );
+      }
+      else
+      {
+        // try to find an existing hypo
+        QValueList<SMESH::SMESH_Hypothesis_var> & aList = myExistingHyps[ aDim ][ aHypType ];
+        int iHyp = 0, nbHyp = aList.count();
+        for ( ; iHyp < nbHyp; ++iHyp )
+        {
+          SMESH::SMESH_Hypothesis_var aHyp = aList[ iHyp ];
+          if ( !aHyp->_is_nil() && aHypoTypeName == aHyp->GetName() ) {
+            index = iHyp;
+            break;
+          }
+        }
+        if ( index >= 0 ) // found
+        {
+          setCurrentHyp ( aDim, aHypType, index );
+        }
+        else
+        {
+          // silently create a hypothesis
+          SMESH::CreateHypothesis( aHypoTypeName, aHypData->Label, isAlgo );
+          QStringList aNewHyps;
+          _PTR(SComponent) aFather = SMESH::GetActiveStudyDocument()->FindComponent( "SMESH" );
+          existingHyps( aDim, aHypType, aFather, aNewHyps, aList );
+          if ( aList.count() > nbHyp )
+          {
+            for ( int i = nbHyp; i < aNewHyps.count(); i++ )
+              myDlg->tab( aDim )->addHyp( aHypType, aNewHyps[ i ] );
+          }
+        }
+      }
+    } // loop on hypos in the set
+  } // loop on algo/hypo
+}
+
 //================================================================================
 /*!
  * \brief Creates mesh
 //================================================================================
 /*!
  * \brief Creates mesh
@@ -564,6 +690,8 @@ bool SMESHGUI_MeshOp::createMesh( QString& theMess )
 
   for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
   {
 
   for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
   {
+    if ( !isAccessibleDim( aDim )) continue;
+
     // assign hypotheses
     for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
     {
     // assign hypotheses
     for ( int aHypType = MainHyp; aHypType <= AddHyp; aHypType++ )
     {
@@ -620,6 +748,8 @@ bool SMESHGUI_MeshOp::createSubMesh( QString& theMess )
 
   for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
   {
 
   for ( int aDim = SMESH::DIM_1D; aDim <= SMESH::DIM_3D; aDim++ )
   {
+    if ( !isAccessibleDim( aDim )) continue;
+
     // find or create algorithm
     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
     if ( !anAlgoVar->_is_nil() )
     // find or create algorithm
     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( aDim );
     if ( !anAlgoVar->_is_nil() )
@@ -655,6 +785,18 @@ int SMESHGUI_MeshOp::currentHyp( const int theDim, const int theHypType ) const
   return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
 }
 
   return myDlg->tab( theDim )->currentHyp( theHypType ) - 1;
 }
 
+//================================================================================
+/*!
+ * \brief Returns true if hypotheses of given dim can be assigned
+  * \param theDim - hypotheses dimension
+  * \retval bool - result
+ */
+//================================================================================
+bool SMESHGUI_MeshOp::isAccessibleDim( const int theDim) const
+{
+  return myDlg->tab( theDim )->isEnabled();
+}
+
 //================================================================================
 /*!
  * \brief Sets current hypothesis or algorithms
 //================================================================================
 /*!
  * \brief Sets current hypothesis or algorithms
@@ -924,6 +1066,8 @@ bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
   // Assign new hypotheses and algorithms
   for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
   {
   // Assign new hypotheses and algorithms
   for ( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
   {
+    if ( !isAccessibleDim( dim )) continue;
+
     // find or create algorithm
     bool toDelete = false, toAdd = true;
     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
     // find or create algorithm
     bool toDelete = false, toAdd = true;
     SMESH::SMESH_Hypothesis_var anAlgoVar = getAlgo( dim );
@@ -1013,7 +1157,7 @@ bool SMESHGUI_MeshOp::editMeshOrSubMesh( QString& theMess )
   * \param theOtherOp - other operation
   * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
 *
   * \param theOtherOp - other operation
   * \return Returns TRUE if the given operator is valid for this one, FALSE otherwise
 *
-* Virtual method redefined from base class verifies whether given operator is valid for
+* method redefined from base class verifies whether given operator is valid for
 * this one (i.e. can be started "above" this operator). In current implementation method
 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
 * elements.
 * this one (i.e. can be started "above" this operator). In current implementation method
 * retuns false if theOtherOp operation is not intended for deleting objects or mesh
 * elements.
index 063ebcaac73e14becd064b87da1d7c3403a9c111..9fd854e4c8acc3ebdf98859ec169b458e18bb0bf 100644 (file)
@@ -52,6 +52,7 @@ protected slots:
   virtual bool                   onApply();
   void                           onCreateHyp( const int theHypType, const int theIndex );
   void                           onEditHyp( const int theHypType, const int theIndex );
   virtual bool                   onApply();
   void                           onCreateHyp( const int theHypType, const int theIndex );
   void                           onEditHyp( const int theHypType, const int theIndex );
+  void                           onHypoSet( const QString& theSetName );
 
 private:
   bool                           isValid( QString& ) const;
 
 private:
   bool                           isValid( QString& ) const;
@@ -69,6 +70,7 @@ private:
   bool                           editMeshOrSubMesh( QString& );
   
   int                            currentHyp( const int, const int ) const;
   bool                           editMeshOrSubMesh( QString& );
   
   int                            currentHyp( const int, const int ) const;
+  bool                           isAccessibleDim( const int ) const;
   void                           setCurrentHyp( const int, const int, const int );
   void                           setDefaultName() const;
   SMESH::SMESH_Hypothesis_var    getAlgo( const int );
   void                           setCurrentHyp( const int, const int, const int );
   void                           setDefaultName() const;
   SMESH::SMESH_Hypothesis_var    getAlgo( const int );
index 51aa35c963f2aae733e78a81619383b6171f2b1a..17ff8a0fafd4e7cc1172fbd4f2fcf38d2002144f 100644 (file)
@@ -2864,6 +2864,9 @@ msgstr "Create sub-mesh"
 msgid "SMESHGUI_MeshDlg::EDIT_MESH_SUBMESH"
 msgstr "Edit mesh/sub-mesh"
 
 msgid "SMESHGUI_MeshDlg::EDIT_MESH_SUBMESH"
 msgstr "Edit mesh/sub-mesh"
 
+msgid "SMESHGUI_MeshDlg::HYPOTHESES_SETS"
+msgstr "Assign a set of hypotheses"
+
 #-----------------------------------------------------------
 
 msgid "SMESHGUI_MeshTab::ALGORITHM"
 #-----------------------------------------------------------
 
 msgid "SMESHGUI_MeshTab::ALGORITHM"