Salome HOME
0022172: [CEA 790] create the groups corresponding to domains
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
index 1d5555e7eb71f13c1274e12da6315e3efa7c1252..be3fc2f18660e1633254a0ad6d7af06d359f2b1b 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  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
@@ -61,6 +61,8 @@
 #include <SALOMEDSClient_SObject.hxx>
 #include <SALOMEDS_wrap.hxx>
 
+#include CORBA_SERVER_HEADER(SMESH_Group)
+
 // OCCT includes
 #include <BRep_Tool.hxx>
 #include <TopExp.hxx>
@@ -354,7 +356,8 @@ namespace SMESH
         text = QObject::tr("COMPERR_ALGO_FAILED");
       break;
     case SMESH::COMPERR_WARNING:
-      return comment ? QString(comment) : QObject::tr("COMPERR_UNKNOWN");
+      text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
+      break;
     default:
       text = QString("#%1").arg( -errCode );
     }
@@ -460,10 +463,12 @@ namespace SMESH
     foreach( range, selRanges )
     {
       for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
-        rows.append( row );
+        if ( !rows.count( row ))
+             rows.append( row );
     }
     if ( rows.isEmpty() && table->currentRow() > -1 )
-      rows.append( table->currentRow() );
+      if ( !rows.count( table->currentRow() ))
+        rows.append( table->currentRow() );
 
     return rows.count();
   }
@@ -553,6 +558,7 @@ QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
   myShowBtn      = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
   myPublishBtn   = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
   myBadMeshBtn   = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
+  myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
 
   //myTable->setReadOnly( true ); // VSR: check
   myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
@@ -577,11 +583,12 @@ QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
   grpLayout->setSpacing(SPACING);
   grpLayout->setMargin(MARGIN);
-  grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
-  grpLayout->addWidget( myTable,        1, 0, 1, 4 );
-  grpLayout->addWidget( myShowBtn,      2, 0 );
-  grpLayout->addWidget( myPublishBtn,   2, 1 );
-  grpLayout->addWidget( myBadMeshBtn,   2, 2 );
+  grpLayout->addWidget( myWarningLabel,      0, 0, 1, 4 );
+  grpLayout->addWidget( myTable,             1, 0, 1, 4 );
+  grpLayout->addWidget( myShowBtn,           2, 0 );
+  grpLayout->addWidget( myPublishBtn,        2, 1 );
+  grpLayout->addWidget( myBadMeshBtn,        2, 2 );
+  grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
   grpLayout->setColumnStretch( 3, 1 );
 
   // Hypothesis definition errors
@@ -832,19 +839,15 @@ void SMESHGUI_BaseComputeOp::computeMesh()
 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
       OCC_CATCH_SIGNALS;
 #endif
-      //SMESH::UpdateNulData(myIObject, true);
       bool res;
-#ifdef WITH_SMESH_CANCEL_COMPUTE
       SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
       qthreaddialog.exec();
       res = qthreaddialog.result();
-#else
       res = gen->Compute(myMesh, myMainShape);
-#endif
       if (res)
         computeFailed = false;
     }
-    catch(const SALOME::SALOME_Exception & S_ex){
+    catch(const SALOME::SALOME_Exception & S_ex) {
       memoryLack = true;
     }
     try {
@@ -856,7 +859,7 @@ void SMESHGUI_BaseComputeOp::computeMesh()
       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
     }
-    catch(const SALOME::SALOME_Exception & S_ex){
+    catch(const SALOME::SALOME_Exception & S_ex) {
       memoryLack = true;
     }
 
@@ -1072,11 +1075,14 @@ void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
       tbl->resizeColumnToContents( COL_SHAPE );
       tbl->setWordWrap( true );
 
-      if ( hasBadMesh )
+      if ( hasBadMesh ) {
         aCompDlg->myBadMeshBtn->show();
-      else
+        aCompDlg->myBadMeshToGroupBtn->show();
+      }
+      else {
         aCompDlg->myBadMeshBtn->hide();
-
+        aCompDlg->myBadMeshToGroupBtn->hide();
+      }
       tbl->setCurrentCell(0,0);
       currentCellChanged(); // to update buttons
     }
@@ -1180,8 +1186,8 @@ void SMESHGUI_BaseComputeOp::onShowBadMesh()
       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
-      vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
-      vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
+      double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
+      double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
       vtkProperty* prop = vtkProperty::New();
       prop->SetLineWidth( aLineWidth * 3 );
       prop->SetPointSize( aPointSize * 3 );
@@ -1193,6 +1199,43 @@ void SMESHGUI_BaseComputeOp::onShowBadMesh()
   }
 }
 
+//================================================================================
+/*!
+ * \brief create groups of bad mesh elements preventing computation of a submesh of current row
+ */
+//================================================================================
+
+void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
+{
+  QList<int> rows;
+  SMESH::getSelectedRows( table(), rows );
+  int row;
+  foreach ( row, rows )
+  {
+    bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
+    if ( hasBadMesh ) {
+      int     curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
+      QString grName = table()->item(rows.front(), COL_SHAPE)->text();
+      if ( grName.isEmpty() ) grName = "bad mesh";
+      else                    grName = "bad mesh of " + grName;
+      SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
+      SMESH::ListOfGroups_var groups
+        ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
+      update( UF_ObjBrowser | UF_Model );
+      if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
+      {
+        QStringList anEntryList;
+        for ( size_t i = 0; i < groups->length(); ++i )
+          if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
+            anEntryList.append( so->GetID().c_str() );
+
+        if ( !anEntryList.isEmpty())
+          anApp->browseObjects( anEntryList, true, false );
+      }
+    }
+  }
+}
+
 //================================================================================
 /*!
  * \brief SLOT called when a selected cell in table() changed
@@ -1291,9 +1334,10 @@ SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
     // connect signals and slots
-    connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
-    connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
-    connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
+    connect(myCompDlg->myShowBtn,           SIGNAL (clicked()), SLOT(onPreviewShape()));
+    connect(myCompDlg->myPublishBtn,        SIGNAL (clicked()), SLOT(onPublishShape()));
+    connect(myCompDlg->myBadMeshBtn,        SIGNAL (clicked()), SLOT(onShowBadMesh()));
+    connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
 
     QTableWidget* aTable = me->table();
     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));