#include "SMESHGUI_HypothesesUtils.h"
#include "SMDS_SetIterator.hxx"
+#include <SMDS_Mesh.hxx>
#include "GEOMBase.h"
#include "GEOM_Actor.h"
#include <BRepBndLib.hxx>
#include <BRepMesh_IncrementalMesh.hxx>
+#include <Standard_ErrorHandler.hxx>
+
// QT Includes
#include <qframe.h>
#include <qlayout.h>
#include <qtable.h>
#include <qhbox.h>
#include <qhgroupbox.h>
+#include <qvgroupbox.h>
#include <vtkProperty.h>
namespace SMESH {
+ //=============================================================================
+ /*!
+ * \brief Allocate some memory at construction and release it at destruction.
+ * Is used to be able to continue working after mesh generation or visualization
+ * break due to lack of memory
+ */
+ //=============================================================================
+
+ struct MemoryReserve
+ {
+ char* myBuf;
+ MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
+ ~MemoryReserve() { delete [] myBuf; }
+ };
+
// =========================================================================================
/*!
* \brief Class showing shapes without publishing
CASE2TEXT( COMPERR_BAD_INPUT_MESH);
CASE2TEXT( COMPERR_STD_EXCEPTION );
CASE2TEXT( COMPERR_OCC_EXCEPTION );
- CASE2TEXT( COMPERR_SLM_EXCEPTION );
+ case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
CASE2TEXT( COMPERR_EXCEPTION );
CASE2TEXT( COMPERR_MEMORY_PB );
CASE2TEXT( COMPERR_BAD_SHAPE );
}
// -----------------------------------------------------------------------
/*!
- * \brief Return text describing a subshape
+ * \brief Return a list of selected rows
*/
bool getSelectedRows(QTable* table, list< int > & rows)
{
for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
rows.push_back( row );
}
+ if (rows.empty() && table->currentRow() > -1 )
+ rows.push_back( table->currentRow() );
+
return !rows.empty();
}
// faces
nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
myNbFace ->setText( QString("%1").arg( nbTot ));
- myNbLinFace ->setText( QString("%1").arg( nbLin ));
+ myNbLinFace ->setText( QString("%1").arg( nbLin ));
myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
// volumes
grpLayout->addWidget ( myPublishBtn, 1, 1 );
grpLayout->setRowStretch( 2, 1 );
+ // Memory Lack Label
+
+ myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
+ QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
+ QFont bold = memLackLabel->font(); bold.setBold(true);
+ memLackLabel->setFont( bold );
+ memLackLabel->setMinimumWidth(300);
+
+ // add all widgets to aFrame
QVBoxLayout* aLay = new QVBoxLayout(aFrame);
aLay->addWidget( aPixGrp );
aLay->addWidget( nameBox );
aLay->addWidget( myBriefInfo );
aLay->addWidget( myFullInfo );
aLay->addWidget( myErrorGroup );
+ aLay->addWidget( myMemoryLackGroup );
aLay->setStretchFactor( myErrorGroup, 1 );
return aFrame;
connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
+ connect(table(),SIGNAL(currentChanged(int,int)), SLOT(currentCellChanged()));
}
//=======================================================================
// COMPUTE MESH
- bool computeFailed = true;
- int nbNodes = 0, nbEdges = 0, nbFaces = 0, nbVolums = 0;
+ bool computeFailed = true, memoryLack = false;
LightApp_SelectionMgr *Sel = selectionMgr();
SALOME_ListIO selected; Sel->selectedObjects( selected );
Handle(SALOME_InteractiveObject) IObject = selected.First();
aMesh = SMESH::GetMeshByIO(IObject);
- if (!aMesh->_is_nil()) {
+ if (!aMesh->_is_nil())
+ {
+ MemoryReserve aMemoryReserve;
+ _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
myMainShape = aMesh->GetShapeToMesh();
- if ( !myMainShape->_is_nil() ) {
+ if ( ((!myMainShape->_is_nil() && aMesh->HasShapeToMesh()) ||
+ (myMainShape->_is_nil() && !aMesh->HasShapeToMesh()))
+ && aMeshSObj )
+ {
+ myDlg->myMeshName->setText( aMeshSObj->GetName() );
SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
if ( errors->length() > 0 ) {
}
SUIT_OverrideCursor aWaitCursor;
try {
- if (gen->Compute(aMesh, myMainShape)) {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ if (gen->Compute(aMesh, myMainShape))
computeFailed = false;
- }
- else {
- anErrors = gen->GetComputeErrors( aMesh, myMainShape );
-// if ( anErrors->length() == 0 ) {
-// SUIT_MessageBox::warn1(desktop(),
-// tr("SMESH_WRN_WARNING"),
-// tr("SMESH_WRN_COMPUTE_FAILED"),
-// tr("SMESH_BUT_OK"));
-// onCancel();
-// return;
-// }
- }
}
catch(const SALOME::SALOME_Exception & S_ex){
- SalomeApp_Tools::QtCatchCorbaException(S_ex);
+ memoryLack = true;
+ //SalomeApp_Tools::QtCatchCorbaException(S_ex);
}
- if ( _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh)) {
- myDlg->myMeshName->setText( aMeshSObj->GetName() );
- SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ anErrors = gen->GetComputeErrors( aMesh, myMainShape );
+ // if ( anErrors->length() == 0 ) {
+ // SUIT_MessageBox::warn1(desktop(),
+ // tr("SMESH_WRN_WARNING"),
+ // tr("SMESH_WRN_COMPUTE_FAILED"),
+ // tr("SMESH_BUT_OK"));
+ // onCancel();
+ // return;
+ // }
+ // check if there are memory problems
+ for ( int i = 0; (i < anErrors->length()) && !memoryLack; ++i )
+ memoryLack = ( anErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
+ }
+ catch(const SALOME::SALOME_Exception & S_ex){
+ memoryLack = true;
}
- update( UF_ObjBrowser | UF_Model );
-
- // SHOW MESH
-
- if ( getSMESHGUI()->automaticUpdate() ) {
- SVTK_ViewWindow* aVTKView = SMESH::GetViewWindow(getSMESHGUI(), true);
- if (aVTKView) {
- int anId = study()->id();
- TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, IObject->getEntry());
- if (aVisualObj) {
- aVisualObj->Update();
- SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
- if (!anActor) {
- anActor = SMESH::CreateActor(studyDS(), IObject->getEntry());
- if (anActor) {
- SMESH::DisplayActor(aVTKView, anActor); //apo
- SMESH::FitAll();
- }
+
+ // NPAL16631: if ( !memoryLack )
+ {
+ SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
+ update( UF_ObjBrowser | UF_Model );
+
+ // SHOW MESH
+ // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
+ if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
+ {
+ try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+ OCC_CATCH_SIGNALS;
+#endif
+ SMESH::Update(IObject, true);
+ }
+ catch (...) {
+#ifdef _DEBUG_
+ cout << "Exception thrown during mesh visualization" << endl;
+#endif
+ if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
+ SMESH::OnVisuException();
+ }
+ else {
+ memoryLack = true;
}
- SMESH::RepaintCurrentView();
- Sel->setSelectedObjects( selected );
}
}
+ Sel->setSelectedObjects( selected );
}
}
}
onCancel();
return;
}
-
myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
+ myDlg->myMemoryLackGroup->hide();
// SHOW ERRORS
bool noError = ( !anErrors.operator->() || anErrors->length() == 0 );
- QTable* tbl = myDlg->myTable;
-
- if ( noError )
+ if ( memoryLack )
+ {
+ myDlg->myMemoryLackGroup->show();
+ myDlg->myFullInfo->hide();
+ myDlg->myBriefInfo->hide();
+ myDlg->myErrorGroup->hide();
+ }
+ else if ( noError )
{
- //tbl->setNumRows(0);
+ SUIT_OverrideCursor aWaitCursor;
myDlg->myFullInfo->SetInfoByMesh( aMesh );
myDlg->myFullInfo->show();
myDlg->myBriefInfo->hide();
}
else
{
+ QTable* tbl = myDlg->myTable;
myDlg->myBriefInfo->SetInfoByMesh( aMesh );
myDlg->myBriefInfo->show();
myDlg->myFullInfo->hide();
myDlg->myErrorGroup->show();
-
+
+ bool hasShape = aMesh->HasShapeToMesh();
+ if ( !hasShape )
+ {
+ myDlg->myPublishBtn->hide();
+ myDlg->myShowBtn->hide();
+ }
+ else
+ {
+ myDlg->myPublishBtn->show();
+ myDlg->myShowBtn->show();
+ }
// fill table of errors
tbl->setNumRows( anErrors->length() );
- bool hasShape = aMesh->HasShapeToMesh();
if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
else tbl->showColumn( COL_SHAPE );
tbl->setColumnWidth( COL_ERROR, 200 );
tbl->setCurrentCell(0,0);
currentCellChanged(); // to update buttons
}
-
myDlg->show();
}