Salome HOME
0052451: "Assign a set of hypotheses" is disabled by mistake
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_MeshOp.cxx
index b8b73db38494950beca98d8676fb13c3fa38e85e..8a3346e8f4364dd8fca32de7f9c73ca6cf5399ca 100644 (file)
@@ -41,6 +41,7 @@
 #include <GEOMBase.h>
 #include <GeometryGUI.h>
 #include <GEOM_wrap.hxx>
+#include <GEOMImpl_Types.hxx>
 
 // SALOME GUI includes
 #include <SalomeApp_Tools.h>
@@ -688,10 +689,13 @@ void SMESHGUI_MeshOp::selectionDone()
       myDlg->adjustSize();
       readMesh();
     }
+    int curIndex = myDlg->currentMeshType( );
     QStringList TypeMeshList;
     createMeshTypeList( TypeMeshList );
     setAvailableMeshType( TypeMeshList );
-    setFilteredAlgoData( myMaxShapeDim, myDlg->currentMeshType( ));
+    curIndex =( curIndex >= TypeMeshList.count() ) ? 0 : curIndex;
+    myDlg->setCurrentMeshType( curIndex );
+    setFilteredAlgoData( myMaxShapeDim, curIndex);
   }
   catch ( const SALOME::SALOME_Exception& S_ex )
   {
@@ -1392,34 +1396,35 @@ void SMESHGUI_MeshOp::onAlgoSelected( const int theIndex,
 
   const bool isSubmesh = ( myToCreate ? !myIsMesh : myDlg->isObjectShown( SMESHGUI_MeshDlg::Mesh ));
 
-  // if ( aDim >= SMESH::DIM_2D ) myAvailableHypData[ aDim ][ Algo ] = myFilteredAlgoData[aDim];
   HypothesisData* algoData = hypData( aDim, Algo, theIndex );
   HypothesisData* algoByDim[4];
   algoByDim[ aDim ] = algoData;
 
   QStringList anAvailable;
 
-  // check that tab enable, if algorithm building needed algo is one less than dimension
-  if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() &&
-       ( aDim > SMESH::DIM_0D ) && !isAccessibleDim( aDim - 1 ) ){
-    myDlg->enableTab( aDim - 1 );
-  }
-  if ( (myDlg->currentMeshType() != MT_ANY) &&
-       (( !algoData && ( aDim > SMESH::DIM_0D ) && isAccessibleDim( aDim - 1 )) ||
-        ( algoData && myIsOnGeometry && algoData->InputTypes.isEmpty() &&
-          ( aDim > SMESH::DIM_0D ) && isAccessibleDim( aDim - 1 ) ) ) ){
-    for (int i = aDim - 1; i >= SMESH::DIM_0D; i--){
-      if ( isAccessibleDim( i ) ) {
-        myDlg->disableTab( i );
-        setCurrentHyp(i, Algo, -1);
-      }
+  // check that tab enabled of one less dimension
+  if ( aDim > SMESH::DIM_0D )
+  {
+    if ( isAccessibleDim( aDim - 1 ) )
+    {
+      if (( myDlg->currentMeshType() != MT_ANY ) &&
+          ( !algoData || ( myIsOnGeometry && algoData->InputTypes.isEmpty() )))
+        for (int i = aDim - 1; i >= SMESH::DIM_0D; i--)
+          if ( isAccessibleDim( i ) ) {
+            myDlg->disableTab( i );
+            setCurrentHyp(i, Algo, -1);
+          }
+    }
+    else if ( algoData && myIsOnGeometry && !algoData->InputTypes.isEmpty() )
+    {
+      myDlg->enableTab( aDim - 1 );
     }
   }
 
   // check that algorithms of other dimentions are compatible with
   // the selected one
   if ( !algoData ) { // all algos becomes available
-    if (myDlg->currentMeshType() == MT_ANY)
+    if (myDlg->currentMeshType() == MT_ANY || aDim == SMESH::DIM_1D || aDim == SMESH::DIM_0D)
       availableHyps( aDim, Algo, anAvailable, myAvailableHypData[ aDim ][ Algo ]);
     else{
       anAvailable.clear();
@@ -2076,13 +2081,9 @@ void SMESHGUI_MeshOp::readMesh()
     }
 
     // Get name of geometry object
-    GEOM::GEOM_Object_var aGeomVar = SMESH::GetShapeOnMeshOrSubMesh( pObj );
-    if ( !aGeomVar->_is_nil() )
-    {
-      _PTR(SObject) aGeomSO = studyDS()->FindObjectID( aGeomVar->GetStudyEntry() );
-      QString aShapeName = name( aGeomSO );
-      myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, aShapeName );
-    }
+    CORBA::String_var name = SMESH::GetGeomName( pObj );
+    if ( name.in() )
+      myDlg->setObjectText( SMESHGUI_MeshDlg::Geom, name.in() );
   }
 
   // Get hypotheses and algorithms assigned to the mesh/sub-mesh
@@ -2530,36 +2531,43 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
   int anCurrentAvailableAlgo = 0;
   bool isNone = true;
   switch ( theIndex ) {
-  case MT_ANY:{
+  case MT_ANY:
     anCompareType = "ANY";
     aDim = SMESH::DIM_3D;
-  }
-  break;
-  case MT_TRIANGULAR:{
+    break;
+  case MT_TRIANGULAR:
     aDim = SMESH::DIM_2D;
     anCompareType = "TRIA";
-  }
-  break;
-  case MT_QUADRILATERAL:{
+    break;
+  case MT_QUADRILATERAL:
     aDim = SMESH::DIM_2D;
     anCompareType = "QUAD";
-  }
-  break;
-  case MT_TETRAHEDRAL:{
+    break;
+  case MT_TETRAHEDRAL:
     aDim = SMESH::DIM_3D;
     anCompareType = "TETRA";
-  }
-  break;
-  case MT_HEXAHEDRAL:{
+    break;
+  case MT_HEXAHEDRAL:
     aDim = SMESH::DIM_3D;
     anCompareType = "HEXA";
-  }
-  break;
+    break;
   default:;
   }
+
+  bool toCheckIsApplicableToAll = !myIsMesh;
+  GEOM::GEOM_Object_var aGeomVar;
+  QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
+  if ( _PTR(SObject) so = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
+  {
+    CORBA::Object_var obj = _CAST( SObject,so )->GetObject();
+    aGeomVar = GEOM::GEOM_Object::_narrow( obj );
+    if ( !aGeomVar->_is_nil() && toCheckIsApplicableToAll )
+      toCheckIsApplicableToAll = ( aGeomVar->GetType() == GEOM_GROUP );
+  }
+
   if ( anCompareType == "ANY" )
   {
-    for ( int dim = SMESH::DIM_2D; dim <= SMESH::DIM_3D; dim++ )
+    for ( int dim = SMESH::DIM_3D; dim >= SMESH::DIM_2D; dim-- )
     {
       isNone = currentHyp( dim, Algo ) < 0;
       isAvailableChoiceAlgo = false;
@@ -2567,40 +2575,40 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
       availableHyps( dim, Algo, anAvailableAlgs, anAvailableAlgsData );
       //return current algo in current tab and set new algorithm list
       HypothesisData* algoCur;
-      if ( !isNone && !myAvailableHypData[dim][Algo].empty() ){
+      if ( !isNone && !myAvailableHypData[dim][Algo].empty() ) {
         algoCur = myAvailableHypData[dim][Algo].at( currentHyp( dim, Algo ) );
       }
       myAvailableHypData[dim][Algo].clear();
       anAvailableAlgs.clear();
-      for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
+      if ( dim != SMESH::DIM_2D || currentHyp( SMESH::DIM_3D, Algo ) < 0 ||
+           myAvailableHypData[SMESH::DIM_3D][Algo].empty() ||
+           !myAvailableHypData[SMESH::DIM_3D][Algo].at( currentHyp( SMESH::DIM_3D, Algo ) )->InputTypes.isEmpty() )
       {
-        HypothesisData* curAlgo = anAvailableAlgsData.at(i);
-        QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-        GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
-        if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
+        for (int i = 0 ; i < anAvailableAlgsData.count(); i++)
         {
-          aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
-        }
-        if ( aGeomVar->_is_nil() ||
-           ( !aGeomVar->_is_nil() && SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, !myIsMesh ))){
-          anAvailableAlgs.append( curAlgo->Label );
-          myAvailableHypData[dim][Algo].append( curAlgo );
+          HypothesisData* curAlgo = anAvailableAlgsData.at(i);
+          if ( aGeomVar->_is_nil() ||
+              SMESH::IsApplicable( curAlgo->TypeName, aGeomVar, toCheckIsApplicableToAll ))
+          {
+            anAvailableAlgs.append( curAlgo->Label );
+            myAvailableHypData[dim][Algo].append( curAlgo );
+          }
         }
-      }
-      if ( !isNone && algoCur ){
-        for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
-        {
-          HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
-          if ( algoAny->Label == algoCur->Label ){
-            isAvailableChoiceAlgo = true;
-            anCurrentAvailableAlgo = i;
-            break;
+        if ( !isNone && algoCur ) {
+          for (int i = 0 ; i < myAvailableHypData[dim][Algo].count(); i++)
+          {
+            HypothesisData* algoAny = myAvailableHypData[dim][Algo].at(i);
+            if ( algoAny->Label == algoCur->Label ){
+              isAvailableChoiceAlgo = true;
+              anCurrentAvailableAlgo = i;
+              break;
+            }
           }
         }
-      }
-      else if ( !isNone ){
-        isAvailableChoiceAlgo = true;
-        anCurrentAvailableAlgo = currentHyp( dim, Algo );
+        else if ( !isNone ) {
+          isAvailableChoiceAlgo = true;
+          anCurrentAvailableAlgo = currentHyp( dim, Algo );
+        }
       }
       myDlg->tab( dim )->setAvailableHyps( Algo, anAvailableAlgs );
       if ( isAvailableChoiceAlgo )
@@ -2652,27 +2660,22 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
         QStringList::const_iterator inElemType = algoIn->OutputTypes.begin();
         for ( ; inElemType != algoIn->OutputTypes.end(); inElemType++ )
         {
-          if ( *inElemType == anCurrentCompareType ){
+          if ( *inElemType == anCurrentCompareType ) {
             isAvailableAlgo = true;
             break;
           }
         }
-        if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ){
-          QString anEntry = myDlg->selectedObject( SMESHGUI_MeshDlg::Geom );
-          GEOM::GEOM_Object_var aGeomVar = GEOM::GEOM_Object::_nil();
-          if ( _PTR(SObject) pGeom = studyDS()->FindObjectID( anEntry.toLatin1().data() ))
-          {
-            aGeomVar= GEOM::GEOM_Object::_narrow( _CAST( SObject,pGeom )->GetObject() );
-          }
+        if ( isAvailableAlgo || algoIn->OutputTypes.count()==0 ) {
           if ( aGeomVar->_is_nil() || myMaxShapeDim != dim ||
-             ( !aGeomVar->_is_nil() && SMESH::IsApplicable( algoIn->TypeName, aGeomVar, !myIsMesh ))){
+               SMESH::IsApplicable( algoIn->TypeName, aGeomVar, toCheckIsApplicableToAll ))
+          {
             anAvailableAlgs.append( algoIn->Label );
             myAvailableHypData[dim][Algo].append( algoIn );
             myFilteredAlgoData[dim].append( algoIn );
           }
         }
         //algorithm will be active, if the chosen algorithm available in the current mesh type
-        if ( !isNoneAlg &&  isAvailableAlgo && algoIn->Label == anCurrentAlgo ){
+        if ( !isNoneAlg &&  isAvailableAlgo && algoIn->Label == anCurrentAlgo ) {
           isAvailableChoiceAlgo = true;
           anCurrentAvailableAlgo = anAvailableAlgs.count() - 1 ;
         }
@@ -2686,21 +2689,20 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
         setCurrentHyp( dim, Algo, -1 );
     }
 
-    int aMaxShapeDim = ( myMaxShapeDim != aDim) ? aDim : myMaxShapeDim;
     if ( isNone || isReqDisBound ) {
-      for ( int i = SMESH::DIM_0D; i <= aMaxShapeDim; i++ ) {
+      for ( int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++ ) {
         if ( aDim != i ) {
           myDlg->disableTab( i );
           setCurrentHyp(i, Algo, -1);
         }
       }
     }
-    else if ( !isNone ){
+    else if ( !isNone ) {
       if ( aDim == SMESH::DIM_2D){
         myDlg->disableTab( SMESH::DIM_3D );
         setCurrentHyp( SMESH::DIM_3D, Algo, -1);
       }
-      for ( int i = aMaxShapeDim; i > SMESH::DIM_0D; i-- )
+      for ( int i = myMaxShapeDim; i > SMESH::DIM_0D; i-- )
       {
         isReqDisBound = ( currentHyp( i, Algo ) < 0 ) ? true :
             myAvailableHypData[i][Algo].at( currentHyp( i, Algo ) )->InputTypes.isEmpty();
@@ -2730,13 +2732,26 @@ void SMESHGUI_MeshOp::setFilteredAlgoData( const int theTabIndex, const int theI
       isAvailable = false;
       if ( HypothesisData* algoDataIn = SMESH::GetHypothesisData( currentHypoSet->current() ))
       {
-        for (int i = SMESH::DIM_0D; i <= SMESH::DIM_3D; i++)
+        for (int i = SMESH::DIM_0D; i <= myMaxShapeDim; i++)
         {
-          for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
-            HypothesisData* aCurAlgo =  hypData( i, Algo, j );
-            if ( aCurAlgo->Label == algoDataIn->Label ){
-              isAvailable = true;
-              break;
+          if ( myAvailableHypData[i][Algo].count() == 0 ) {
+            availableHyps( i, Algo, anAvailableAlgs, anAvailableAlgsData );
+            for ( int j = 0 ; j < anAvailableAlgsData.count(); j++ )
+            {
+              HypothesisData* aCurAlgo = anAvailableAlgsData.at( j );
+              if ( aCurAlgo->Label == algoDataIn->Label ){
+                isAvailable = true;
+                break;
+              }
+            }
+          }
+          else {
+            for (int j = 0; j < myAvailableHypData[i][Algo].count(); ++j) {
+              HypothesisData* aCurAlgo = hypData( i, Algo, j );
+              if ( aCurAlgo->Label == algoDataIn->Label ){
+                isAvailable = true;
+                break;
+              }
             }
           }
           if ( isAvailable ) break;