Salome HOME
IMP 0019925 (Improve Precompute modes detection)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
index 147a6a46403c70757003e42ea855c45e591584f8..47f6db18710870cece23b62f4585fc85a8046425 100644 (file)
@@ -1433,6 +1433,17 @@ SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
   return myCompDlg;
 }
 
+//================================================================================
+/*!
+ * \brief returns from compute mesh result dialog
+ */
+//================================================================================
+
+bool SMESHGUI_BaseComputeOp::onApply()
+{
+  return true;
+}
+
 //================================================================================
 /*!
  * \brief Return a table
@@ -1479,17 +1490,6 @@ void SMESHGUI_ComputeOp::startOperation()
   computeMesh();
 }
 
-//================================================================================
-/*!
- * \brief perform it's intention action: compute mesh
- */
-//================================================================================
-
-bool SMESHGUI_ComputeOp::onApply()
-{
-  return true;
-}
-
 //================================================================================
 /*!
  * \brief Gets dialog of this operation
@@ -1514,7 +1514,7 @@ SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
  myActiveDlg( 0 ),
  myPreviewDisplayer( 0 )
 {
-  myHelpFileName = "preview_meshes_page.html"; // V4
+  myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
 }
 
 //================================================================================
@@ -1559,6 +1559,8 @@ void SMESHGUI_PrecomputeOp::startOperation()
     
     // connect signals
     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
+    connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
+    connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
   }
   myActiveDlg = myDlg;
 
@@ -1588,6 +1590,10 @@ void SMESHGUI_PrecomputeOp::startOperation()
 
   SMESHGUI_BaseComputeOp::startOperation();
 
+  // disconnect slot from preview dialog to have Apply from results of compute operation only 
+  disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
+  disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
+
   myDlg->show();
 }
 
@@ -1611,7 +1617,7 @@ void SMESHGUI_PrecomputeOp::stopOperation()
 
 //================================================================================
 /*!
- * \brief perform it's intention action: reinitialise dialog
+ * \brief reinitialize dialog after operaiton become active again
  */
 //================================================================================
 
@@ -1622,16 +1628,48 @@ void SMESHGUI_PrecomputeOp::resumeOperation()
   SMESHGUI_BaseComputeOp::resumeOperation();
 }
 
+//================================================================================
+/*!
+ * \brief perform it's intention action: reinitialise dialog
+ */
+//================================================================================
+
 void SMESHGUI_PrecomputeOp::initDialog()
 {
   QList<int> modes;
+
   QMap<int, int> modeMap;
+  _PTR(SObject)  pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
+  getAssignedAlgos( pMesh, modeMap );
+  if ( modeMap.contains( SMESH::DIM_3D ) )
+  {
+    if ( modeMap.contains( SMESH::DIM_2D ) )
+      modes.append( SMESH::DIM_2D );
+    if ( modeMap.contains( SMESH::DIM_1D ) )
+      modes.append( SMESH::DIM_1D );
+  }
+  else if ( modeMap.contains( SMESH::DIM_2D ) )
+  {
+    if ( modeMap.contains( SMESH::DIM_1D ) )
+      modes.append( SMESH::DIM_1D );
+  }
+
+  myDlg->setPreviewModes( modes );
+}
+
+//================================================================================
+/*!
+ * \brief detect asigned mesh algorithms
+ */
+//================================================================================
+
+void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
+                                             QMap<int,int>& theModeMap)
+{
   _PTR(SObject)          aHypRoot;
   _PTR(GenericAttribute) anAttr;
   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
-
-  _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
-  if ( pMesh && pMesh->FindSubObject( aPart, aHypRoot ) )
+  if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
   {
     _PTR(ChildIterator) anIter =
       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
@@ -1649,50 +1687,36 @@ void SMESHGUI_PrecomputeOp::initDialog()
         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
         if ( CORBA::is_nil( aVar ) )
           continue;
-
-        SMESH::SMESH_Algo_var algo = SMESH::SMESH_3D_Algo::_narrow( aVar );
-        if ( !algo->_is_nil() )
+        
+        for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
         {
-         modeMap[ SMESH::DIM_1D ] = 0;
-         modeMap[ SMESH::DIM_2D ] = 0;
-        }
-        else
-        {
-          algo = SMESH::SMESH_2D_Algo::_narrow( aVar );
+          SMESH::SMESH_Algo_var algo;
+          switch(dim) {
+          case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
+          case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
+          case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
+          default: break;
+          }
           if ( !algo->_is_nil() )
-            modeMap[ SMESH::DIM_2D ] = 0;
+           theModeMap[ dim ] = 0;
         }
       }
     }
   }
-  if ( modeMap.contains( SMESH::DIM_1D ) )
-    modes.append( SMESH::DIM_1D );
-  if ( modeMap.contains( SMESH::DIM_2D ) )
-    modes.append( SMESH::DIM_2D );
-
-  myDlg->setPreviewModes( modes );
 }
 
 //================================================================================
 /*!
- * \brief perform it's intention action: 
+ * \brief perform it's intention action: compute mesh
  */
 //================================================================================
 
-bool SMESHGUI_PrecomputeOp::onApply()
+void SMESHGUI_PrecomputeOp::onCompute()
 {
-  QObject* obj = sender();
-  if ( obj != myDlg && myActiveDlg == myDlg )
-    return true; // just return from error messages
-  if ( myActiveDlg == myDlg )
-  {
-    myDlg->hide();
-    myMapShapeId.clear();
-    myActiveDlg = computeDlg();
-    computeMesh();
-  }
-
-  return true;
+  myDlg->hide();
+  myMapShapeId.clear();
+  myActiveDlg = computeDlg();
+  computeMesh();
 }
 
 //================================================================================
@@ -1704,11 +1728,10 @@ bool SMESHGUI_PrecomputeOp::onApply()
 void SMESHGUI_PrecomputeOp::onCancel()
 {
   QObject* curDlg = sender();
-  if ( curDlg == computeDlg() )
+  if ( curDlg == computeDlg() && myActiveDlg == myDlg )
   {
-    if ( myActiveDlg == myDlg ) // return from error messages
-      myDlg->show();
-
+    // return from error messages
+    myDlg->show();
     return;
   }