Salome HOME
PR: merged from V5_1_4rc1
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
index 9ca09b1a3ed5f218a18b5b73f922796366d20045..f239903520f4fb79fa432b7d8c0dadc8abbbc474 100644 (file)
@@ -1,7 +1,4 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 //  This library is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU Lesser General Public
@@ -19,6 +16,7 @@
 //
 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // File   : SMESHGUI_ComputeDlg.cxx
 // Author : Edward AGAPOV, Open CASCADE S.A.S.
 // SMESH includes
@@ -32,6 +30,9 @@
 #include "SMESHGUI_MeshInfosBox.h"
 #include "SMESHGUI_HypothesesUtils.h"
 #include "SMESHGUI_MeshEditPreview.h"
+#include "SMESHGUI_MeshOrderOp.h"
+#include "SMESHGUI_MeshOrderDlg.h"
+
 #include "SMESH_ActorUtils.h"
 
 #include <SMDS_SetIterator.hxx>
@@ -616,6 +617,15 @@ SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
   myHelpFileName = "about_meshes_page.html"; // V4
 }
 
+SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
+{
+  LightApp_SelectionMgr* Sel = selectionMgr();
+  SALOME_ListIO selected; Sel->selectedObjects( selected );
+  Handle(SALOME_InteractiveObject) anIO = selected.First();
+  SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
+  return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
+}
+
 //================================================================================
 /*!
  * \brief Start operation
@@ -818,7 +828,7 @@ void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
   {
     QTableWidget* tbl = aCompDlg->myTable;
     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
-    aCompDlg->myFullInfo->SetMeshInfo( aRes );
+    aCompDlg->myBriefInfo->SetMeshInfo( aRes );
     aCompDlg->myBriefInfo->show();
     aCompDlg->myFullInfo->hide();
 
@@ -1172,6 +1182,23 @@ void SMESHGUI_ComputeOp::startOperation()
   computeMesh();
 }
 
+//================================================================================
+/*!
+ * \brief check the same operations on the same mesh
+ */
+//================================================================================
+
+bool SMESHGUI_BaseComputeOp::isValid(  SUIT_Operation* theOp  ) const
+{
+  SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
+  bool ret = true;
+  if ( !myMesh->_is_nil() && baseOp ) {
+    SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
+    if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
+  }
+  return ret;
+}
+
 //================================================================================
 /*!
  * \brief Gets dialog of this operation
@@ -1193,6 +1220,7 @@ LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
  : SMESHGUI_BaseComputeOp(),
  myDlg( 0 ),
+ myOrderMgr( 0 ),
  myActiveDlg( 0 ),
  myPreviewDisplayer( 0 )
 {
@@ -1209,6 +1237,8 @@ SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
 {
   delete myDlg;
   myDlg = 0;
+  delete myOrderMgr;
+  myOrderMgr = 0;
   myActiveDlg = 0;
   if ( myPreviewDisplayer )
     delete myPreviewDisplayer;
@@ -1274,6 +1304,16 @@ void SMESHGUI_PrecomputeOp::startOperation()
   if (myMesh->_is_nil())
     return;
 
+  if (myDlg->getPreviewMode() == -1)
+  {
+    // nothing to preview
+    SUIT_MessageBox::warning(desktop(),
+                             tr("SMESH_WRN_WARNING"),
+                             tr("SMESH_WRN_NOTHING_PREVIEW"));
+    onCancel();
+    return;
+  }
+
   // 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() ) );
@@ -1338,6 +1378,15 @@ void SMESHGUI_PrecomputeOp::initDialog()
       modes.append( SMESH::DIM_1D );
   }
 
+  myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
+  myOrderMgr->SetMesh( myMesh );
+  bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
+  myDlg->getMeshOrderBox()->setShown(isOrder);
+  if ( !isOrder ) {
+    delete myOrderMgr;
+    myOrderMgr = 0;
+  }
+
   myDlg->setPreviewModes( modes );
 }
 
@@ -1398,6 +1447,8 @@ void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
 void SMESHGUI_PrecomputeOp::onCompute()
 {
   myDlg->hide();
+  if (myOrderMgr && myOrderMgr->IsOrderChanged())
+    myOrderMgr->SetMeshOrder();
   myMapShapeId.clear();
   myActiveDlg = computeDlg();
   computeMesh();
@@ -1419,6 +1470,7 @@ void SMESHGUI_PrecomputeOp::onCancel()
     return;
   }
 
+  bool isRestoreOrder = false;
   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
   {
     // ask to remove already computed mesh elements
@@ -1430,8 +1482,24 @@ void SMESHGUI_PrecomputeOp::onCancel()
       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
       for ( ; it != myMapShapeId.constEnd(); ++it )
         myMesh->ClearSubMesh( *it );
+      isRestoreOrder = true;
     }
   }
+
+  // return previous mesh order
+  if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
+    if (!isRestoreOrder)
+      isRestoreOrder = 
+        (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
+                                    tr( "SMESH_REJECT_MESH_ORDER" ),
+                                    tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
+    if (isRestoreOrder)
+      myOrderMgr->SetMeshOrder(myPrevOrder);
+  }
+
+  delete myOrderMgr;
+  myOrderMgr = 0;
+
   myMapShapeId.clear();
   SMESHGUI_BaseComputeOp::onCancel();
 }
@@ -1450,6 +1518,11 @@ void SMESHGUI_PrecomputeOp::onPreview()
   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
   if ( !aMeshSObj )
     return;
+
+  // set modified submesh priority if any
+  if (myOrderMgr && myOrderMgr->IsOrderChanged())
+    myOrderMgr->SetMeshOrder();
+
   // Compute preview of mesh, 
   // i.e. compute mesh till indicated dimension
   int dim = myDlg->getPreviewMode();
@@ -1554,7 +1627,8 @@ void SMESHGUI_PrecomputeOp::onPreview()
 //================================================================================
 
 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
- : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help )
+ : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
+   myOrderBox(0)
 {
   setWindowTitle( tr( "CAPTION" ) );
 
@@ -1563,6 +1637,9 @@ SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
 
   QVBoxLayout* layout = new QVBoxLayout( main );
 
+  myOrderBox = new SMESHGUI_MeshOrderBox( main );
+  layout->addWidget(myOrderBox);
+
   QFrame* frame = new QFrame( main );
   layout->setMargin(0); layout->setSpacing(0);
   layout->addWidget( frame );
@@ -1619,6 +1696,17 @@ int SMESHGUI_PrecomputeDlg::getPreviewMode() const
   return myPreviewMode->currentId();
 }
 
+//================================================================================
+/*!
+ * \brief Returns current preview mesh mode
+*/
+//================================================================================
+
+SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
+{
+  return myOrderBox;
+}
+
 
 //================================================================================
 /*!