Salome HOME
22526: SMESH 2864 - Projection and Extrusion
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
index 4883f787383fe629ea0b7640411894d2bf8bf6d9..1966e750d82e3fd3764130f88e9fbdeb245935ba 100644 (file)
@@ -1,9 +1,9 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -92,6 +92,7 @@
 #include <QButtonGroup>
 #include <QCloseEvent>
 #include <QTimerEvent>
+#include <QProgressBar>
 
 // VTK includes
 #include <vtkProperty.h>
 
 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
 
-/* OBSOLETE
-static void addSeparator( QWidget* parent )
-{
-  QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
-  int row  = l->rowCount();
-  int cols = l->columnCount();
-  for ( int i = 0; i < cols; i++ ) {
-    QFrame* hline = new QFrame( parent );
-    hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
-    l->addWidget( hline, row, i );
-  }
-}
-*/
-
 enum TCol {
   COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
 };
@@ -211,6 +198,7 @@ namespace SMESH
     void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
     {
       SVTK_ViewWindow* aViewWindow  = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
+      SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
       std::string mainEntry;
       if ( !aMainShape->_is_nil() )
         mainEntry = aMainShape->GetStudyEntry();
@@ -239,8 +227,13 @@ namespace SMESH
         TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
         for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
           //checkTriangulation( exp.Current() );
-          if ( GEOM_Actor* anActor = getActor( exp.Current() ))
+          if ( GEOM_Actor* anActor = getActor( exp.Current() ) ) {
+            int UNbIsos = resMgr->integerValue( "Geometry", "iso_number_u", 1);
+            int VNbIsos = resMgr->integerValue( "Geometry", "iso_number_v", 1);
+            int aNbIsos[2] = { UNbIsos ? UNbIsos : 1, VNbIsos ? VNbIsos : 1 };
+            anActor->SetNbIsos( aNbIsos );
             myShownActors.push_back( anActor );
+          }
         }
         if ( type == TopAbs_FACE ) {
           for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
@@ -356,6 +349,7 @@ namespace SMESH
       CASE2TEXT( COMPERR_BAD_SHAPE        );
       CASE2TEXT( COMPERR_CANCELED         );
       CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
+      CASE2TEXT( COMPERR_BAD_PARMETERS    );
     case SMESH::COMPERR_ALGO_FAILED:
       if ( strlen(comment) == 0 )
         text = QObject::tr("COMPERR_ALGO_FAILED");
@@ -388,7 +382,11 @@ namespace SMESH
         if ( !geom->_is_nil() ) {
           GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
           if ( list->length() == 1 && list[0] == subShapeID )
-            subSO = it->Value();
+          {
+            GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
+            if ( aMainShape->IsSame( mainGO ))
+              subSO = it->Value();
+          }
         }
       }
     }
@@ -445,8 +443,10 @@ namespace SMESH
   QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
   {
     QString text;
-    if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
-      text = aSO->GetName().c_str();
+    if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
+      text  = aSO->GetName().c_str();
+      text += QString(" (%1)").arg( aSO->GetID().c_str() );
+    }
     else {
       text = QString("#%1").arg( subShapeID );
       GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
@@ -619,8 +619,8 @@ QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
 
   // add all widgets to aFrame
   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
-  aLay->setMargin( 0 );
-  aLay->setSpacing( 0 );
+  aLay->setMargin( MARGIN );
+  aLay->setSpacing( SPACING );
   aLay->addWidget( aPixGrp );
   aLay->addWidget( nameBox );
   aLay->addWidget( myBriefInfo );
@@ -745,18 +745,24 @@ SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget
     qthread(gen, mesh, mainShape)
 {
   // --
-  setWindowTitle(tr("Compute"));
+  setWindowTitle(tr("TITLE"));
   setMinimumWidth( 200 );
 
-  cancelButton = new QPushButton(tr("Cancel"));
+  cancelButton = new QPushButton(tr("CANCEL"));
   cancelButton->setDefault(true);
+  cancelButton->setCheckable(true);
 
   QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
   QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
-  QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
   nbNodesLabel = new QLabel("0", this );
   nbElemsLabel = new QLabel("0", this );
+#ifndef WIN32
+  QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
   freeRAMLabel = new QLabel("", this );
+#endif
+  progressBar  = new QProgressBar(this);
+  progressBar->setMinimum( 0 );
+  progressBar->setMaximum( 1000 );
 
   QGridLayout* layout = new QGridLayout(this);
   layout->setMargin( MARGIN );
@@ -766,11 +772,12 @@ SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget
   layout->addWidget(nbNodesLabel, row++, 1);
   layout->addWidget(nbElemsName,  row,   0);
   layout->addWidget(nbElemsLabel, row++, 1);
-#ifndef WNT
+#ifndef WIN32
   layout->addWidget(freeRAMName,  row,   0);
   layout->addWidget(freeRAMLabel, row++, 1);
 #endif
-  layout->addWidget(cancelButton, row,   0, 1, 2);
+  layout->addWidget(progressBar,  row++, 0, 1, 2);
+  layout->addWidget(cancelButton, row++, 0, 1, 2);
   adjustSize();
   update();
 
@@ -788,10 +795,15 @@ bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
 {
   qthread.cancel();
-}  
+  cancelButton->setText( tr("CANCELING"));
+  cancelButton->setEnabled(false);
+}
 
 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
 {
+  if ( !cancelButton->isChecked() ) // not yet cancelled
+    progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
+
   if(qthread.isFinished())
   {
     close();
@@ -800,7 +812,7 @@ void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
   {
     nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
     nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
-#ifndef WNT
+#ifndef WIN32
     struct sysinfo si;
     const int err = sysinfo( &si );
     if ( err )
@@ -863,13 +875,9 @@ void SMESHGUI_BaseComputeOp::computeMesh()
 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
       OCC_CATCH_SIGNALS;
 #endif
-      bool res;
       SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
       qthreaddialog.exec();
-      res = qthreaddialog.result();
-      res = gen->Compute(myMesh, myMainShape);
-      if (res)
-        computeFailed = false;
+      computeFailed = !qthreaddialog.result();
     }
     catch(const SALOME::SALOME_Exception & S_ex) {
       memoryLack = true;
@@ -893,7 +901,9 @@ void SMESHGUI_BaseComputeOp::computeMesh()
 
     // NPAL16631: if ( !memoryLack )
     {
-      SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
+      SMESH::ModifiedMesh( aMeshSObj,
+                           !computeFailed && aHypErrors.isEmpty(),
+                           myMesh->NbNodes() == 0);
       update( UF_ObjBrowser | UF_Model );
 
       // SHOW MESH
@@ -902,28 +912,36 @@ void SMESHGUI_BaseComputeOp::computeMesh()
       bool limitExceeded;
       long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
       int entities = SMESH_Actor::eAllEntity;
+      int hidden = 0;
       if ( !memoryLack )
       {
-       if ( getSMESHGUI()->automaticUpdate( myMesh, &entities, &limitExceeded ) )
+        if ( getSMESHGUI()->automaticUpdate( myMesh, &entities, &limitExceeded, &hidden ) )
         {
           try {
 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
             OCC_CATCH_SIGNALS;
 #endif
-           SMESH_Actor *anActor = SMESH::FindActorByObject( myMesh );
-           if ( !anActor ) anActor = SMESH::CreateActor( aMeshSObj->GetStudy(), aMeshSObj->GetID().c_str(), true );    
-
-           anActor->SetEntityMode( entities );
-           SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
-
-           SMESH::Update(myIObject, true);
-
-           if ( limitExceeded )
-           {
-             SUIT_MessageBox::warning( desktop(),
-                                       tr( "SMESH_WRN_WARNING" ),
-                                       tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).arg( myMesh->NbElements() ).arg( limitSize ) );
-           }
+            SMESH_Actor *anActor = SMESH::FindActorByObject( myMesh );
+            if ( !anActor ) anActor = SMESH::CreateActor( aMeshSObj->GetStudy(), aMeshSObj->GetID().c_str(), true );    
+            if ( anActor ) // actor is not created for an empty mesh
+            {
+              anActor->SetEntityMode( entities );
+              SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
+            }
+            SMESH::Update(myIObject, true);
+
+            if ( limitExceeded )
+            {
+              QStringList hiddenMsg;
+              if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
+              if ( hidden & SMESH_Actor::eEdges )      hiddenMsg << tr( "SMESH_EDGES" );
+              if ( hidden & SMESH_Actor::eFaces )      hiddenMsg << tr( "SMESH_FACES" );
+              if ( hidden & SMESH_Actor::eVolumes )    hiddenMsg << tr( "SMESH_VOLUMES" );
+              if ( hidden & SMESH_Actor::eBallElem )   hiddenMsg << tr( "SMESH_BALLS" );
+              SUIT_MessageBox::warning( desktop(),
+                                        tr( "SMESH_WRN_WARNING" ),
+                                        tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).arg( myMesh->NbElements() ).arg( limitSize ).arg( hiddenMsg.join(", ") ) );
+            }
           }
           catch (...) {
 #ifdef _DEBUG_
@@ -937,7 +955,7 @@ void SMESHGUI_BaseComputeOp::computeMesh()
             }
           }
         }
-       else if ( limitExceeded )
+        else if ( limitExceeded )
         {
           SUIT_MessageBox::warning( desktop(),
                                     tr( "SMESH_WRN_WARNING" ),
@@ -1181,7 +1199,8 @@ void SMESHGUI_BaseComputeOp::onPublishShape()
             if ( so->_is_nil() ) {
               CORBA::String_var name  = so->GetName();
               CORBA::String_var entry = so->GetID();
-              table()->item( r, COL_SHAPE     )->setText( name.in() );
+              QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
+              table()->item( r, COL_SHAPE     )->setText( shapeText );
               table()->item( r, COL_PUBLISHED )->setText( entry.in() );
             }
             break;
@@ -1194,7 +1213,8 @@ void SMESHGUI_BaseComputeOp::onPublishShape()
       if ( !so->_is_nil() ) {
         CORBA::String_var name  = so->GetName();
         CORBA::String_var entry = so->GetID();
-        table()->item( row, COL_SHAPE     )->setText( name.in() );
+        QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
+        table()->item( row, COL_SHAPE     )->setText( shapeText );
         table()->item( row, COL_PUBLISHED )->setText( entry.in() );
       }
     }
@@ -1312,6 +1332,7 @@ void SMESHGUI_BaseComputeOp::currentCellChanged()
   myCompDlg->myPublishBtn->setEnabled( publishEnable );
   myCompDlg->myShowBtn   ->setEnabled( showEnable );
   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
+  myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
 }
 
 //================================================================================
@@ -2208,10 +2229,15 @@ void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
       tbl->setWordWrap( true );
 
       if ( hasBadMesh )
+      {
         aCompDlg->myBadMeshBtn->show();
+        aCompDlg->myBadMeshToGroupBtn->show();
+      }
       else
+      {
         aCompDlg->myBadMeshBtn->hide();
-
+        aCompDlg->myBadMeshToGroupBtn->hide();
+      }
       tbl->setCurrentCell(0,0);
       currentCellChanged(); // to update buttons
     }