X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_ComputeDlg.cxx;h=7bf81c56cca5918ccbd2a78f177abd3ba273a683;hb=aafd432548d29b49e42ce58a1942ac215c2ffb3a;hp=ccd700190a6f67b26a9e24799aeee12d78270eaa;hpb=9357f5c87098aff2b95b754d69f66c76d2df9c24;p=modules%2Fsmesh.git diff --git a/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx b/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx index ccd700190..7bf81c56c 100644 --- a/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ComputeDlg.cxx @@ -1,20 +1,20 @@ -// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 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. +// 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. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : SMESHGUI_ComputeDlg.cxx @@ -85,6 +85,8 @@ #include #include #include +#include +#include // VTK includes #include @@ -98,6 +100,7 @@ #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" ) +/* OBSOLETE static void addSeparator( QWidget* parent ) { QGridLayout* l = qobject_cast( parent->layout() ); @@ -109,6 +112,7 @@ static void addSeparator( QWidget* parent ) l->addWidget( hline, row, i ); } } +*/ enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS @@ -333,18 +337,22 @@ namespace SMESH { QString text; switch ( errCode ) { - CASE2TEXT( COMPERR_OK ); - CASE2TEXT( COMPERR_BAD_INPUT_MESH); - CASE2TEXT( COMPERR_STD_EXCEPTION ); - CASE2TEXT( COMPERR_OCC_EXCEPTION ); + CASE2TEXT( COMPERR_OK ); + CASE2TEXT( COMPERR_BAD_INPUT_MESH ); + CASE2TEXT( COMPERR_STD_EXCEPTION ); + CASE2TEXT( COMPERR_OCC_EXCEPTION ); case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception" - CASE2TEXT( COMPERR_EXCEPTION ); - CASE2TEXT( COMPERR_MEMORY_PB ); - CASE2TEXT( COMPERR_BAD_SHAPE ); + CASE2TEXT( COMPERR_EXCEPTION ); + CASE2TEXT( COMPERR_MEMORY_PB ); + CASE2TEXT( COMPERR_BAD_SHAPE ); + CASE2TEXT( COMPERR_CANCELED ); + CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE ); case SMESH::COMPERR_ALGO_FAILED: if ( strlen(comment) == 0 ) text = QObject::tr("COMPERR_ALGO_FAILED"); break; + case SMESH::COMPERR_WARNING: + return comment ? QString(comment) : QObject::tr("COMPERR_UNKNOWN"); default: text = QString("#%1").arg( -errCode ); } @@ -353,7 +361,7 @@ namespace SMESH } // ----------------------------------------------------------------------- /*! - * \brief Return SO of a subshape + * \brief Return SO of a sub-shape */ _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape) { @@ -378,7 +386,7 @@ namespace SMESH } // ----------------------------------------------------------------------- /*! - * \brief Return subshape by ID + * \brief Return sub-shape by ID */ GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape) { @@ -416,7 +424,7 @@ namespace SMESH } // ----------------------------------------------------------------------- /*! - * \brief Return text describing a subshape + * \brief Return text describing a sub-shape */ QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape ) { @@ -531,10 +539,11 @@ QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval) // Computation errors myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame); - myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup); - myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup); - myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup); - myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup); + myWarningLabel = new QLabel(QString("%1").arg(tr("COMPUTE_WARNING")), myCompErrorGroup); + myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup); + myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup); + myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup); + myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup); //myTable->setReadOnly( true ); // VSR: check myTable->setEditTriggers( QAbstractItemView::NoEditTriggers ); @@ -542,6 +551,9 @@ QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval) myTable->hideColumn( COL_SHAPEID ); myTable->hideColumn( COL_BAD_MESH ); myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive ); + myTable->setWordWrap( true ); + myTable->horizontalHeader()->setStretchLastSection( true ); + myTable->setMinimumWidth( 500 ); QStringList headers; headers << tr( "COL_ALGO_HEADER" ); @@ -556,11 +568,12 @@ QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval) QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup); grpLayout->setSpacing(SPACING); grpLayout->setMargin(MARGIN); - grpLayout->addWidget( myTable, 0, 0, 4, 1 ); - grpLayout->addWidget( myShowBtn, 0, 1 ); - grpLayout->addWidget( myPublishBtn, 1, 1 ); - grpLayout->addWidget( myBadMeshBtn, 2, 1 ); - grpLayout->setRowStretch( 3, 1 ); + 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->setColumnStretch( 3, 1 ); // Hypothesis definition errors @@ -668,6 +681,87 @@ void SMESHGUI_BaseComputeOp::startOperation() SMESHGUI_Operation::startOperation(); } +//================================================================================ +//================================================================================ + +SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen, + SMESH::SMESH_Mesh_var mesh, + GEOM::GEOM_Object_var mainShape) +{ + myResult = false; + myGen = gen; + myMesh = mesh; + myMainShape = mainShape; +} + +void SMESHGUI_ComputeDlg_QThread::run() +{ + myResult = myGen->Compute(myMesh, myMainShape); +} + +bool SMESHGUI_ComputeDlg_QThread::result() +{ + return myResult; +} + +void SMESHGUI_ComputeDlg_QThread::cancel() +{ + myGen->CancelCompute(myMesh, myMainShape); +} + +//================================================================================ +//================================================================================ + +SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *parent, + SMESH::SMESH_Gen_var gen, + SMESH::SMESH_Mesh_var mesh, + GEOM::GEOM_Object_var mainShape) + : QDialog(parent), + qthread(gen, mesh, mainShape) +{ + // -- + setWindowTitle(tr("Compute")); + cancelButton = new QPushButton(tr("Cancel")); + cancelButton->setDefault(true); + connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel())); + QHBoxLayout *layout = new QHBoxLayout; + layout->addWidget(cancelButton); + setLayout(layout); + resize(200, 50); + // -- + startTimer(30); // 30 millisecs + qthread.start(); +} + +bool SMESHGUI_ComputeDlg_QThreadQDialog::result() +{ + return qthread.result(); +} + +void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel() +{ + qthread.cancel(); +} + +void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event) +{ + if(qthread.isFinished()) + { + close(); + } + event->accept(); +} + +void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event) +{ + if(qthread.isRunning()) + { + event->ignore(); + return; + } + event->accept(); +} + //================================================================================ /*! * \brief computeMesh() @@ -708,7 +802,16 @@ void SMESHGUI_BaseComputeOp::computeMesh() #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; #endif - if (gen->Compute(myMesh, myMainShape)) + //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){ @@ -727,6 +830,10 @@ void SMESHGUI_BaseComputeOp::computeMesh() memoryLack = true; } + if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes? + memoryLack = true; + } + // NPAL16631: if ( !memoryLack ) { SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0); @@ -734,25 +841,38 @@ void SMESHGUI_BaseComputeOp::computeMesh() // SHOW MESH // NPAL16631: if ( getSMESHGUI()->automaticUpdate() ) - if ( !memoryLack && getSMESHGUI()->automaticUpdate() ) + SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() ); + long newSize = myMesh->NbElements(); + bool limitExceeded; + if ( !memoryLack ) { - try { + if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) ) + { + try { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 - OCC_CATCH_SIGNALS; + OCC_CATCH_SIGNALS; #endif - SMESH::Update(myIObject, true); - } - catch (...) { + SMESH::Update(myIObject, true); + } + catch (...) { #ifdef _DEBUG_ - MESSAGE ( "Exception thrown during mesh visualization" ); + MESSAGE ( "Exception thrown during mesh visualization" ); #endif - if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning? - SMESH::OnVisuException(); - } - else { - memoryLack = true; + if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning? + SMESH::OnVisuException(); + } + else { + memoryLack = true; + } } } + else if ( limitExceeded ) + { + long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 ); + SUIT_MessageBox::warning( desktop(), + tr( "SMESH_WRN_WARNING" ), + tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) ); + } } LightApp_SelectionMgr *Sel = selectionMgr(); if ( Sel ) @@ -804,7 +924,7 @@ void SMESHGUI_BaseComputeOp::computeMesh() void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack, const bool theNoCompError, SMESH::compute_error_array_var& theCompErrors, - const bool theNoHypoError, + const bool theNoHypoError, const QString& theHypErrors ) { bool hasShape = myMesh->HasShapeToMesh(); @@ -830,26 +950,45 @@ void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack, } else { - QTableWidget* tbl = aCompDlg->myTable; + bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported + for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i ) + onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING || + theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE ); + + // full or brief mesh info SMESH::long_array_var aRes = myMesh->GetMeshInfo(); - aCompDlg->myBriefInfo->SetMeshInfo( aRes ); - aCompDlg->myBriefInfo->show(); - aCompDlg->myFullInfo->hide(); + if ( onlyWarnings ) { + aCompDlg->myFullInfo->SetMeshInfo( aRes ); + aCompDlg->myFullInfo->show(); + aCompDlg->myBriefInfo->hide(); + } else { + aCompDlg->myBriefInfo->SetMeshInfo( aRes ); + aCompDlg->myBriefInfo->show(); + aCompDlg->myFullInfo->hide(); + } + // pbs of hypo dfinitions if ( theNoHypoError ) { aCompDlg->myHypErrorGroup->hide(); - } - else { + } else { aCompDlg->myHypErrorGroup->show(); aCompDlg->myHypErrorLabel->setText( theHypErrors ); } - if ( theNoCompError ) { + // table of errors + if ( theNoCompError ) + { aCompDlg->myCompErrorGroup->hide(); } - else { + else + { aCompDlg->myCompErrorGroup->show(); + if ( onlyWarnings ) + aCompDlg->myWarningLabel->show(); + else + aCompDlg->myWarningLabel->hide(); + if ( !hasShape ) { aCompDlg->myPublishBtn->hide(); aCompDlg->myShowBtn->hide(); @@ -860,6 +999,7 @@ void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack, } // fill table of errors + QTableWidget* tbl = aCompDlg->myTable; tbl->setRowCount( theCompErrors->length() ); if ( !hasShape ) tbl->hideColumn( COL_SHAPE ); else tbl->showColumn( COL_SHAPE ); @@ -900,6 +1040,7 @@ void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack, } tbl->resizeColumnToContents( COL_ALGO ); tbl->resizeColumnToContents( COL_SHAPE ); + tbl->setWordWrap( true ); if ( hasBadMesh ) aCompDlg->myBadMeshBtn->show(); @@ -938,7 +1079,7 @@ void SMESHGUI_BaseComputeOp::stopOperation() //================================================================================ /*! - * \brief publish selected subshape + * \brief publish selected sub-shape */ //================================================================================ @@ -1007,13 +1148,13 @@ void SMESHGUI_BaseComputeOp::onShowBadMesh() SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub); vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3); vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1); - // delete property !!!!!!!!!! vtkProperty* prop = vtkProperty::New(); prop->SetLineWidth( aLineWidth * 3 ); prop->SetPointSize( aPointSize * 3 ); prop->SetColor( 250, 0, 250 ); myBadMeshDisplayer->GetActor()->SetProperty( prop ); myBadMeshDisplayer->SetData( aMeshData._retn() ); + prop->Delete(); } } } @@ -1562,6 +1703,7 @@ void SMESHGUI_PrecomputeOp::onPreview() SMESH::MeshPreviewStruct_var previewData = gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId); + SMESH::MeshPreviewStruct* previewRes = previewData._retn(); if ( previewRes && previewRes->nodesXYZ.length() > 0 ) { @@ -1948,6 +2090,7 @@ void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes, } tbl->resizeColumnToContents( COL_ALGO ); tbl->resizeColumnToContents( COL_SHAPE ); + tbl->setWordWrap( true ); if ( hasBadMesh ) aCompDlg->myBadMeshBtn->show();