1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_ComputeDlg.cxx
23 // Author : Edward AGAPOV, Open CASCADE S.A.S.
26 #include "SMESHGUI_ComputeDlg.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33 #include "SMESHGUI_HypothesesUtils.h"
34 #include "SMESHGUI_MeshEditPreview.h"
35 #include "SMESH_ActorUtils.h"
37 #include <SMDS_SetIterator.hxx>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GEOM includes
42 #include <GEOM_Actor.h>
44 // SALOME GUI includes
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_UpdateFlags.h>
47 #include <SALOME_ListIO.hxx>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_ViewModel.h>
50 #include <SalomeApp_Application.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_Desktop.h>
55 #include <QtxComboBox.h>
57 // SALOME KERNEL includes
58 #include <SALOMEDS_SObject.hxx>
59 #include <SALOMEDSClient_SObject.hxx>
62 #include <BRep_Tool.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
68 #include <TopLoc_Location.hxx>
69 #include <Poly_Triangulation.hxx>
70 #include <Bnd_Box.hxx>
71 #include <BRepBndLib.hxx>
72 #include <BRepMesh_IncrementalMesh.hxx>
74 #include <Standard_ErrorHandler.hxx>
78 #include <QPushButton>
80 #include <QRadioButton>
81 #include <QTableWidget>
82 #include <QHeaderView>
83 #include <QGridLayout>
84 #include <QHBoxLayout>
85 #include <QVBoxLayout>
86 #include <QButtonGroup>
89 #include <vtkProperty.h>
98 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
100 static void addSeparator( QWidget* parent )
102 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
103 int row = l->rowCount();
104 int cols = l->columnCount();
105 for ( int i = 0; i < cols; i++ ) {
106 QFrame* hline = new QFrame( parent );
107 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
108 l->addWidget( hline, row, i );
113 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
116 //using namespace SMESH;
120 //=============================================================================
122 * \brief Allocate some memory at construction and release it at destruction.
123 * Is used to be able to continue working after mesh generation or visualization
124 * break due to lack of memory
126 //=============================================================================
131 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
132 void release() { delete [] myBuf; myBuf = 0; }
133 ~MemoryReserve() { release(); }
136 // =========================================================================================
138 * \brief Class showing shapes without publishing
140 // =========================================================================================
142 class TShapeDisplayer
145 // -----------------------------------------------------------------------
146 TShapeDisplayer(): myViewWindow(0)
148 myProperty = vtkProperty::New();
149 myProperty->SetRepresentationToWireframe();
150 myProperty->SetColor( 250, 0, 250 );
151 myProperty->SetAmbientColor( 250, 0, 250 );
152 myProperty->SetDiffuseColor( 250, 0, 250 );
153 //myProperty->SetSpecularColor( 250, 0, 250 );
154 myProperty->SetLineWidth( 5 );
156 // -----------------------------------------------------------------------
160 myProperty->Delete();
162 // -----------------------------------------------------------------------
165 if ( hasViewWindow() ) {
166 TActorIterator actorIt = actorIterator();
167 while ( actorIt.more() )
168 if (VTKViewer_Actor* anActor = actorIt.next()) {
169 myViewWindow->RemoveActor( anActor );
173 myIndexToShape.Clear();
175 myShownActors.clear();
178 // -----------------------------------------------------------------------
179 void SetVisibility (bool theVisibility)
181 TActorIterator actorIt = shownIterator();
182 while ( actorIt.more() )
183 if (VTKViewer_Actor* anActor = actorIt.next())
184 anActor->SetVisibility(theVisibility);
185 SMESH::RepaintCurrentView();
187 // -----------------------------------------------------------------------
188 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
190 std::string mainEntry;
191 if ( !aMainShape->_is_nil() )
192 mainEntry = aMainShape->GetStudyEntry();
193 return ( myMainEntry == mainEntry &&
194 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
196 // -----------------------------------------------------------------------
197 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
199 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
200 std::string mainEntry;
201 if ( !aMainShape->_is_nil() )
202 mainEntry = aMainShape->GetStudyEntry();
203 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
206 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
207 checkTriangulation( aShape );
208 TopExp::MapShapes(aShape, myIndexToShape);
209 myActors.resize( myIndexToShape.Extent(), 0 );
210 myShownActors.reserve( myIndexToShape.Extent() );
212 myMainEntry = mainEntry;
213 myViewWindow = aViewWindow;
215 if ( only ) { // hide shown actors
216 TActorIterator actorIt = shownIterator();
217 while ( actorIt.more() )
218 if (VTKViewer_Actor* anActor = actorIt.next())
219 anActor->SetVisibility(false);
220 myShownActors.clear();
222 // find actors to show
223 TopoDS_Shape aShape = myIndexToShape( subShapeID );
224 if ( !aShape.IsNull() ) {
225 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
226 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
227 //checkTriangulation( exp.Current() );
228 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
229 myShownActors.push_back( anActor );
231 if ( type == TopAbs_FACE ) {
232 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
233 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
234 if ( !BRep_Tool::Degenerated( edge ))
235 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
236 myShownActors.push_back( anActor );
240 myBuiltSubs.insert( subShapeID );
243 // -----------------------------------------------------------------------
247 typedef std::vector<GEOM_Actor*> TActorVec;
249 TActorVec myShownActors;
250 TopTools_IndexedMapOfShape myIndexToShape;
251 std::string myMainEntry;
252 SVTK_ViewWindow* myViewWindow;
253 vtkProperty* myProperty;
254 std::set<int> myBuiltSubs;
256 // -----------------------------------------------------------------------
257 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
258 TActorIterator actorIterator() {
259 return TActorIterator( myActors.begin(), myActors.end() );
261 TActorIterator shownIterator() {
262 return TActorIterator( myShownActors.begin(), myShownActors.end() );
264 // -----------------------------------------------------------------------
265 GEOM_Actor* getActor(const TopoDS_Shape& shape)
267 int index = myIndexToShape.FindIndex( shape ) - 1;
268 if ( index < 0 || index >= myActors.size() )
270 GEOM_Actor* & actor = myActors[ index ];
272 actor = GEOM_Actor::New();
274 actor->SetShape(shape,0,0);
275 actor->SetProperty(myProperty);
276 actor->SetShadingProperty(myProperty);
277 actor->SetWireframeProperty(myProperty);
278 actor->SetPreviewProperty(myProperty);
279 actor->PickableOff();
280 // if ( shape.ShapeType() == TopAbs_EDGE )
281 // actor->SubShapeOn();
282 myViewWindow->AddActor( actor );
287 // -----------------------------------------------------------------------
288 void checkTriangulation(const TopoDS_Shape& shape)
290 TopLoc_Location aLoc;
291 Standard_Boolean alreadymesh = Standard_True;
292 TopExp_Explorer ex(shape, TopAbs_FACE);
294 for ( ; ex.More(); ex.Next()) {
295 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
296 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
297 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
300 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
301 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
302 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
303 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
305 if (alreadymesh) return;
306 // Compute default deflection
308 BRepBndLib::Add(shape, B);
309 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
310 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
311 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
312 BRepMesh_IncrementalMesh MESH(shape,deflection);
314 // -----------------------------------------------------------------------
315 bool hasViewWindow() const
317 if ( !myViewWindow ) return false;
319 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
320 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
326 // =========================================================================================
328 * \brief Return text describing an error
330 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
331 QString errorText(int errCode, const char* comment)
335 CASE2TEXT( COMPERR_OK );
336 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
337 CASE2TEXT( COMPERR_STD_EXCEPTION );
338 CASE2TEXT( COMPERR_OCC_EXCEPTION );
339 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
340 CASE2TEXT( COMPERR_EXCEPTION );
341 CASE2TEXT( COMPERR_MEMORY_PB );
342 CASE2TEXT( COMPERR_BAD_SHAPE );
343 case SMESH::COMPERR_ALGO_FAILED:
344 if ( strlen(comment) == 0 )
345 text = QObject::tr("COMPERR_ALGO_FAILED");
348 text = QString("#%1").arg( -errCode );
350 if ( text.length() > 0 ) text += ". ";
351 return text + comment;
353 // -----------------------------------------------------------------------
355 * \brief Return SO of a subshape
357 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
359 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
360 if ( subShapeID == 1 || !so )
362 _PTR(ChildIterator) it;
363 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
364 it = study->NewChildIterator(so);
367 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
368 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
369 if ( !geom->_is_nil() ) {
370 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
371 if ( list->length() == 1 && list[0] == subShapeID )
378 // -----------------------------------------------------------------------
380 * \brief Return subshape by ID
382 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
384 GEOM::GEOM_Object_var aSubShape;
385 if ( subShapeID == 1 )
386 aSubShape = aMainShape;
387 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
388 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
390 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
391 return aSubShape._retn();
393 // -----------------------------------------------------------------------
395 * \brief Return shape type name
397 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
398 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
401 if ( !aShape->_is_nil() ) {
402 switch ( aShape->GetShapeType() ) {
409 CASE2NAME( COMPSOLID );
410 CASE2NAME( COMPOUND );
416 // -----------------------------------------------------------------------
418 * \brief Return text describing a subshape
420 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
423 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
424 text = aSO->GetName().c_str();
426 text = QString("#%1").arg( subShapeID );
427 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
428 if ( typeName.length() )
429 text += QString(" (%1)").arg(typeName);
433 // -----------------------------------------------------------------------
435 * \brief Return a list of selected rows
437 int getSelectedRows(QTableWidget* table, QList<int>& rows)
440 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
441 QTableWidgetSelectionRange range;
442 foreach( range, selRanges )
444 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
447 if ( rows.isEmpty() && table->currentRow() > -1 )
448 rows.append( table->currentRow() );
456 // =========================================================================================
458 * \brief Dialog to compute a mesh and show computation errors
460 //=======================================================================
462 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
463 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
465 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
466 aDlgLay->setMargin( 0 );
467 aDlgLay->setSpacing( SPACING );
469 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
471 aDlgLay->addWidget(aMainFrame);
473 aDlgLay->setStretchFactor(aMainFrame, 1);
476 // =========================================================================================
480 //=======================================================================
482 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
486 //=======================================================================
487 // function : createMainFrame()
488 // purpose : Create frame containing dialog's fields
489 //=======================================================================
491 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
493 QFrame* aFrame = new QFrame(theParent);
495 SUIT_ResourceMgr* rm = resourceMgr();
496 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
502 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
505 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
507 QButtonGroup* aBtnGrp = new QButtonGroup(this);
508 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
509 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
511 QRadioButton* aRBut = new QRadioButton(aPixGrp);
512 aRBut->setIcon(iconCompute);
513 aRBut->setChecked(true);
514 aPixGrpLayout->addWidget(aRBut);
515 aBtnGrp->addButton(aRBut, 0);
519 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
520 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
521 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
522 myMeshName = new QLabel(nameBox);
523 nameBoxLayout->addWidget(myMeshName);
527 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
528 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
530 // Computation errors
532 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
533 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
534 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
535 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
536 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
538 //myTable->setReadOnly( true ); // VSR: check
539 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
540 myTable->hideColumn( COL_PUBLISHED );
541 myTable->hideColumn( COL_SHAPEID );
542 myTable->hideColumn( COL_BAD_MESH );
543 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
546 headers << tr( "COL_ALGO_HEADER" );
547 headers << tr( "COL_SHAPE_HEADER" );
548 headers << tr( "COL_ERROR_HEADER" );
549 headers << tr( "COL_SHAPEID_HEADER" );
550 headers << tr( "COL_PUBLISHED_HEADER" );
552 myTable->setHorizontalHeaderLabels( headers );
555 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
556 grpLayout->setSpacing(SPACING);
557 grpLayout->setMargin(MARGIN);
558 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
559 grpLayout->addWidget( myShowBtn, 0, 1 );
560 grpLayout->addWidget( myPublishBtn, 1, 1 );
561 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
562 grpLayout->setRowStretch( 3, 1 );
564 // Hypothesis definition errors
566 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
567 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
568 myHypErrorGroupLayout->setMargin(MARGIN);
569 myHypErrorGroupLayout->setSpacing(SPACING);
570 myHypErrorLabel = new QLabel(myHypErrorGroup);
571 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
575 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
576 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
577 myMemoryLackGroupLayout->setMargin(MARGIN);
578 myMemoryLackGroupLayout->setSpacing(SPACING);
579 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
580 QFont bold = memLackLabel->font(); bold.setBold(true);
581 memLackLabel->setFont( bold );
582 memLackLabel->setMinimumWidth(300);
583 myMemoryLackGroupLayout->addWidget(memLackLabel);
585 // add all widgets to aFrame
586 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
587 aLay->setMargin( 0 );
588 aLay->setSpacing( 0 );
589 aLay->addWidget( aPixGrp );
590 aLay->addWidget( nameBox );
591 aLay->addWidget( myBriefInfo );
592 aLay->addWidget( myFullInfo );
593 aLay->addWidget( myHypErrorGroup );
594 aLay->addWidget( myCompErrorGroup );
595 aLay->addWidget( myMemoryLackGroup );
596 aLay->setStretchFactor( myCompErrorGroup, 1 );
598 ((QPushButton*) button( OK ))->setDefault( true );
603 //================================================================================
607 //================================================================================
609 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
610 : SMESHGUI_Operation(), myCompDlg( 0 )
612 myTShapeDisplayer = new SMESH::TShapeDisplayer();
613 myBadMeshDisplayer = 0;
615 //myHelpFileName = "/files/about_meshes.htm"; // V3
616 myHelpFileName = "about_meshes_page.html"; // V4
619 //================================================================================
621 * \brief Start operation
622 * \purpose Init dialog fields, connect signals and slots, show dialog
624 //================================================================================
626 void SMESHGUI_BaseComputeOp::startOperation()
628 // create compute dialog if not created before
631 myMesh = SMESH::SMESH_Mesh::_nil();
632 myMainShape = GEOM::GEOM_Object::_nil();
635 LightApp_SelectionMgr *Sel = selectionMgr();
636 SALOME_ListIO selected; Sel->selectedObjects( selected );
638 int nbSel = selected.Extent();
640 SUIT_MessageBox::warning(desktop(),
641 tr("SMESH_WRN_WARNING"),
642 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
647 myIObject = selected.First();
648 myMesh = SMESH::GetMeshByIO(myIObject);
649 if (myMesh->_is_nil()) {
650 SUIT_MessageBox::warning(desktop(),
651 tr("SMESH_WRN_WARNING"),
652 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
656 myMainShape = myMesh->GetShapeToMesh();
658 SMESHGUI_Operation::startOperation();
661 //================================================================================
663 * \brief computeMesh()
665 //================================================================================
667 void SMESHGUI_BaseComputeOp::computeMesh()
671 SMESH::MemoryReserve aMemoryReserve;
673 SMESH::compute_error_array_var aCompErrors;
676 bool computeFailed = true, memoryLack = false;
678 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
679 if ( !aMeshSObj ) // IPAL 21340
681 bool hasShape = myMesh->HasShapeToMesh();
682 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
685 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
686 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
687 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
688 if ( errors->length() > 0 ) {
689 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
691 SUIT_OverrideCursor aWaitCursor;
693 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
696 if (gen->Compute(myMesh, myMainShape))
697 computeFailed = false;
699 catch(const SALOME::SALOME_Exception & S_ex){
703 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
706 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
707 // check if there are memory problems
708 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
709 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
711 catch(const SALOME::SALOME_Exception & S_ex){
715 // NPAL16631: if ( !memoryLack )
717 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
718 update( UF_ObjBrowser | UF_Model );
721 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
722 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
725 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
728 SMESH::Update(myIObject, true);
732 MESSAGE ( "Exception thrown during mesh visualization" );
734 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
735 SMESH::OnVisuException();
742 LightApp_SelectionMgr *Sel = selectionMgr();
745 SALOME_ListIO selected;
746 selected.Append( myIObject );
747 Sel->setSelectedObjects( selected );
753 aMemoryReserve.release();
755 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
759 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
760 bool noHypoError = ( aHypErrors.isEmpty() );
762 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
763 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
765 bool isShowResultDlg = true;
766 switch( aNotifyMode ) {
767 case 0: // show the mesh computation result dialog NEVER
768 isShowResultDlg = false;
771 case 1: // show the mesh computation result dialog if there are some errors
772 if ( memoryLack || !noCompError || !noHypoError )
773 isShowResultDlg = true;
776 isShowResultDlg = false;
780 default: // show the result dialog after each mesh computation
781 isShowResultDlg = true;
785 if ( isShowResultDlg )
786 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
789 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
790 const bool theNoCompError,
791 SMESH::compute_error_array_var& theCompErrors,
792 const bool theNoHypoError,
793 const QString& theHypErrors )
795 bool hasShape = myMesh->HasShapeToMesh();
796 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
797 aCompDlg->myMemoryLackGroup->hide();
801 aCompDlg->myMemoryLackGroup->show();
802 aCompDlg->myFullInfo->hide();
803 aCompDlg->myBriefInfo->hide();
804 aCompDlg->myHypErrorGroup->hide();
805 aCompDlg->myCompErrorGroup->hide();
807 else if ( theNoCompError && theNoHypoError )
809 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
810 aCompDlg->myFullInfo->SetMeshInfo( aRes );
811 aCompDlg->myFullInfo->show();
812 aCompDlg->myBriefInfo->hide();
813 aCompDlg->myHypErrorGroup->hide();
814 aCompDlg->myCompErrorGroup->hide();
818 QTableWidget* tbl = aCompDlg->myTable;
819 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
820 aCompDlg->myFullInfo->SetMeshInfo( aRes );
821 aCompDlg->myBriefInfo->show();
822 aCompDlg->myFullInfo->hide();
824 if ( theNoHypoError ) {
825 aCompDlg->myHypErrorGroup->hide();
828 aCompDlg->myHypErrorGroup->show();
829 aCompDlg->myHypErrorLabel->setText( theHypErrors );
832 if ( theNoCompError ) {
833 aCompDlg->myCompErrorGroup->hide();
836 aCompDlg->myCompErrorGroup->show();
839 aCompDlg->myPublishBtn->hide();
840 aCompDlg->myShowBtn->hide();
843 aCompDlg->myPublishBtn->show();
844 aCompDlg->myShowBtn->show();
847 // fill table of errors
848 tbl->setRowCount( theCompErrors->length() );
849 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
850 else tbl->showColumn( COL_SHAPE );
851 tbl->setColumnWidth( COL_ERROR, 200 );
853 bool hasBadMesh = false;
854 for ( int row = 0; row < theCompErrors->length(); ++row )
856 SMESH::ComputeError & err = theCompErrors[ row ];
858 QString text = err.algoName.in();
859 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
860 else tbl->item( row, COL_ALGO )->setText( text );
862 text = SMESH::errorText( err.code, err.comment.in() );
863 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
864 else tbl->item( row, COL_ERROR )->setText( text );
866 text = QString("%1").arg( err.subShapeID );
867 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
868 else tbl->item( row, COL_SHAPEID )->setText( text );
870 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
871 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
872 else tbl->item( row, COL_SHAPE )->setText( text );
874 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
875 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
876 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
878 text = err.hasBadMesh ? "hasBadMesh" : "";
879 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
880 else tbl->item( row, COL_BAD_MESH )->setText( text );
881 if ( err.hasBadMesh ) hasBadMesh = true;
883 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
884 tbl->resizeRowToContents( row );
886 tbl->resizeColumnToContents( COL_ALGO );
887 tbl->resizeColumnToContents( COL_SHAPE );
890 aCompDlg->myBadMeshBtn->show();
892 aCompDlg->myBadMeshBtn->hide();
894 tbl->setCurrentCell(0,0);
895 currentCellChanged(); // to update buttons
898 // show dialog and wait, becase Compute can be invoked from Preview operation
899 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
903 //================================================================================
905 * \brief Stops operation
907 //================================================================================
909 void SMESHGUI_BaseComputeOp::stopOperation()
911 SMESHGUI_Operation::stopOperation();
912 if ( myTShapeDisplayer )
913 myTShapeDisplayer->SetVisibility( false );
914 if ( myBadMeshDisplayer ) {
915 myBadMeshDisplayer->SetVisibility( false );
916 // delete it in order not to have problems at its destruction when the viewer
917 // where it worked is dead due to e.g. study closing
918 delete myBadMeshDisplayer;
919 myBadMeshDisplayer = 0;
924 //================================================================================
926 * \brief publish selected subshape
928 //================================================================================
930 void SMESHGUI_BaseComputeOp::onPublishShape()
932 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
933 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
936 SMESH::getSelectedRows( table(), rows );
938 foreach ( row, rows )
940 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
941 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
942 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
944 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
946 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
947 SALOMEDS::SObject_var so =
948 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
949 // look for myMainShape in the table
950 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
951 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
952 if ( so->_is_nil() ) {
953 table()->item( r, COL_SHAPE )->setText( so->GetName() );
954 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
959 if ( curSub == 1 ) continue;
961 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
962 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
963 if ( !so->_is_nil() ) {
964 table()->item( row, COL_SHAPE )->setText( so->GetName() );
965 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
969 getSMESHGUI()->getApp()->updateObjectBrowser();
970 currentCellChanged(); // to update buttons
973 //================================================================================
975 * \brief show mesh elements preventing computation of a submesh of current row
977 //================================================================================
979 void SMESHGUI_BaseComputeOp::onShowBadMesh()
981 myTShapeDisplayer->SetVisibility( false );
983 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
984 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
986 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
987 SMESHGUI* gui = getSMESHGUI();
988 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
989 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
990 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
991 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
992 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
993 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
994 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
995 // delete property !!!!!!!!!!
996 vtkProperty* prop = vtkProperty::New();
997 prop->SetLineWidth( aLineWidth * 3 );
998 prop->SetPointSize( aPointSize * 3 );
999 prop->SetColor( 250, 0, 250 );
1000 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1001 myBadMeshDisplayer->SetData( aMeshData._retn() );
1006 //================================================================================
1008 * \brief SLOT called when a selected cell in table() changed
1010 //================================================================================
1012 void SMESHGUI_BaseComputeOp::currentCellChanged()
1014 myTShapeDisplayer->SetVisibility( false );
1015 if ( myBadMeshDisplayer )
1016 myBadMeshDisplayer->SetVisibility( false );
1018 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1020 int nbSelected = SMESH::getSelectedRows( table(), rows );
1022 foreach ( row, rows )
1024 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1025 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1026 if ( hasData && !isPublished )
1027 publishEnable = true;
1029 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1030 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1032 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1039 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1042 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1043 myCompDlg->myShowBtn ->setEnabled( showEnable );
1044 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1047 //================================================================================
1049 * \brief update preview
1051 //================================================================================
1053 void SMESHGUI_BaseComputeOp::onPreviewShape()
1055 if ( myTShapeDisplayer )
1057 SUIT_OverrideCursor aWaitCursor;
1059 SMESH::getSelectedRows( table(), rows );
1061 bool showOnly = true;
1063 foreach ( row, rows )
1065 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1067 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1071 currentCellChanged(); // to update buttons
1075 //================================================================================
1079 //================================================================================
1081 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1085 delete myTShapeDisplayer;
1086 if ( myBadMeshDisplayer )
1087 delete myBadMeshDisplayer;
1090 //================================================================================
1092 * \brief Gets dialog of compute operation
1093 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1095 //================================================================================
1097 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1101 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1102 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1103 // connect signals and slots
1104 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1105 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1106 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1108 QTableWidget* aTable = me->table();
1109 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1110 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1115 //================================================================================
1117 * \brief returns from compute mesh result dialog
1119 //================================================================================
1121 bool SMESHGUI_BaseComputeOp::onApply()
1126 //================================================================================
1128 * \brief Return a table
1130 //================================================================================
1132 QTableWidget* SMESHGUI_BaseComputeOp::table()
1134 return myCompDlg->myTable;
1138 //================================================================================
1140 * \brief Constructor
1142 //================================================================================
1144 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1145 : SMESHGUI_BaseComputeOp()
1150 //================================================================================
1152 * \brief Desctructor
1154 //================================================================================
1156 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1160 //================================================================================
1162 * \brief perform it's intention action: compute mesh
1164 //================================================================================
1166 void SMESHGUI_ComputeOp::startOperation()
1168 SMESHGUI_BaseComputeOp::startOperation();
1169 if (myMesh->_is_nil())
1174 //================================================================================
1176 * \brief Gets dialog of this operation
1177 * \retval LightApp_Dialog* - pointer to dialog of this operation
1179 //================================================================================
1181 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1183 return computeDlg();
1186 //================================================================================
1188 * \brief Constructor
1190 //================================================================================
1192 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1193 : SMESHGUI_BaseComputeOp(),
1196 myPreviewDisplayer( 0 )
1198 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1201 //================================================================================
1205 //================================================================================
1207 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1212 if ( myPreviewDisplayer )
1213 delete myPreviewDisplayer;
1214 myPreviewDisplayer = 0;
1217 //================================================================================
1219 * \brief Gets current dialog of this operation
1220 * \retval LightApp_Dialog* - pointer to dialog of this operation
1222 //================================================================================
1224 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1229 //================================================================================
1231 * \brief perform it's intention action: prepare data
1233 //================================================================================
1235 void SMESHGUI_PrecomputeOp::startOperation()
1239 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1242 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1243 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1244 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1246 myActiveDlg = myDlg;
1248 // connect signal to compute dialog. which will be shown after Compute mesh operation
1249 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1252 // disconnect signals
1253 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1254 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1255 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1256 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1257 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1260 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1261 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1262 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1263 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1264 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1265 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1266 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1267 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1268 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1269 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1272 SMESHGUI_BaseComputeOp::startOperation();
1273 if (myMesh->_is_nil())
1276 // disconnect slot from preview dialog to have Apply from results of compute operation only
1277 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1278 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1283 //================================================================================
1285 * \brief Stops operation
1287 //================================================================================
1289 void SMESHGUI_PrecomputeOp::stopOperation()
1291 if ( myPreviewDisplayer )
1293 myPreviewDisplayer->SetVisibility( false );
1294 delete myPreviewDisplayer;
1295 myPreviewDisplayer = 0;
1297 myMapShapeId.clear();
1298 SMESHGUI_BaseComputeOp::stopOperation();
1301 //================================================================================
1303 * \brief reinitialize dialog after operaiton become active again
1305 //================================================================================
1307 void SMESHGUI_PrecomputeOp::resumeOperation()
1309 if ( myActiveDlg == myDlg )
1311 SMESHGUI_BaseComputeOp::resumeOperation();
1314 //================================================================================
1316 * \brief perform it's intention action: reinitialise dialog
1318 //================================================================================
1320 void SMESHGUI_PrecomputeOp::initDialog()
1324 QMap<int, int> modeMap;
1325 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1326 getAssignedAlgos( pMesh, modeMap );
1327 if ( modeMap.contains( SMESH::DIM_3D ) )
1329 if ( modeMap.contains( SMESH::DIM_2D ) )
1330 modes.append( SMESH::DIM_2D );
1331 if ( modeMap.contains( SMESH::DIM_1D ) )
1332 modes.append( SMESH::DIM_1D );
1334 else if ( modeMap.contains( SMESH::DIM_2D ) )
1336 if ( modeMap.contains( SMESH::DIM_1D ) )
1337 modes.append( SMESH::DIM_1D );
1340 myDlg->setPreviewModes( modes );
1343 //================================================================================
1345 * \brief detect asigned mesh algorithms
1347 //================================================================================
1349 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1350 QMap<int,int>& theModeMap)
1352 _PTR(SObject) aHypRoot;
1353 _PTR(GenericAttribute) anAttr;
1354 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1355 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1357 _PTR(ChildIterator) anIter =
1358 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1359 for ( ; anIter->More(); anIter->Next() )
1361 _PTR(SObject) anObj = anIter->Value();
1362 _PTR(SObject) aRefObj;
1363 if ( anObj->ReferencedObject( aRefObj ) )
1368 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1370 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1371 if ( CORBA::is_nil( aVar ) )
1374 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1376 SMESH::SMESH_Algo_var algo;
1378 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1379 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1380 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1383 if ( !algo->_is_nil() )
1384 theModeMap[ dim ] = 0;
1391 //================================================================================
1393 * \brief perform it's intention action: compute mesh
1395 //================================================================================
1397 void SMESHGUI_PrecomputeOp::onCompute()
1400 myMapShapeId.clear();
1401 myActiveDlg = computeDlg();
1405 //================================================================================
1407 * \brief perform it's intention action: compute mesh
1409 //================================================================================
1411 void SMESHGUI_PrecomputeOp::onCancel()
1413 QObject* curDlg = sender();
1414 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1416 // return from error messages
1421 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1423 // ask to remove already computed mesh elements
1424 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1425 tr( "CLEAR_SUBMESH_QUESTION" ),
1426 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1428 // remove all submeshes for collected shapes
1429 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1430 for ( ; it != myMapShapeId.constEnd(); ++it )
1431 myMesh->ClearSubMesh( *it );
1434 myMapShapeId.clear();
1435 SMESHGUI_BaseComputeOp::onCancel();
1438 //================================================================================
1440 * \brief perform it's intention action: preview mesh
1442 //================================================================================
1444 void SMESHGUI_PrecomputeOp::onPreview()
1446 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1449 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1452 // Compute preview of mesh,
1453 // i.e. compute mesh till indicated dimension
1454 int dim = myDlg->getPreviewMode();
1456 SMESH::MemoryReserve aMemoryReserve;
1458 SMESH::compute_error_array_var aCompErrors;
1461 bool computeFailed = true, memoryLack = false;
1463 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1464 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1466 SMESHGUI* gui = getSMESHGUI();
1467 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1468 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1469 if ( errors->length() > 0 ) {
1470 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1473 SUIT_OverrideCursor aWaitCursor;
1475 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1476 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1477 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1479 SMESH::long_array_var aShapesId = new SMESH::long_array();
1481 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1485 SMESH::MeshPreviewStruct_var previewData =
1486 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1487 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1488 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1490 computeFailed = false;
1491 myPreviewDisplayer->SetData( previewRes );
1492 // append shape indeces with computed mesh entities
1493 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1494 myMapShapeId[ aShapesId[ i ] ] = 0;
1497 myPreviewDisplayer->SetVisibility(false);
1499 catch(const SALOME::SALOME_Exception & S_ex){
1501 myPreviewDisplayer->SetVisibility(false);
1505 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1508 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1509 // check if there are memory problems
1510 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1511 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1513 catch(const SALOME::SALOME_Exception & S_ex){
1518 aMemoryReserve.release();
1520 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1521 bool noHypoError = ( aHypErrors.isEmpty() );
1523 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1524 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1526 bool isShowError = true;
1527 switch( aNotifyMode ) {
1528 case 0: // show the mesh computation result dialog NEVER
1529 isShowError = false;
1531 case 1: // show the mesh computation result dialog if there are some errors
1532 default: // show the result dialog after each mesh computation
1533 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1534 isShowError = false;
1538 aWaitCursor.suspend();
1543 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1544 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1549 //================================================================================
1551 * \brief Constructor
1553 //================================================================================
1555 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1556 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help )
1558 setWindowTitle( tr( "CAPTION" ) );
1560 setButtonText( OK, tr( "COMPUTE" ) );
1561 QFrame* main = mainFrame();
1563 QVBoxLayout* layout = new QVBoxLayout( main );
1565 QFrame* frame = new QFrame( main );
1566 layout->setMargin(0); layout->setSpacing(0);
1567 layout->addWidget( frame );
1569 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1570 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1572 myPreviewMode = new QtxComboBox( frame );
1573 frameLay->addWidget( myPreviewMode );
1575 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1576 frameLay->addWidget( myPreviewBtn );
1578 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1581 //================================================================================
1585 //================================================================================
1587 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1591 //================================================================================
1593 * \brief Sets available preview modes
1595 //================================================================================
1597 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1599 myPreviewMode->clear();
1600 QList<int>::const_iterator it = theModes.constBegin();
1601 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1603 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1604 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1605 myPreviewMode->setId( i, *it );
1607 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1610 //================================================================================
1612 * \brief Returns current preview mesh mode
1614 //================================================================================
1616 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1618 return myPreviewMode->currentId();
1622 //================================================================================
1624 * \brief Constructor
1626 //================================================================================
1628 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1629 : SMESHGUI_BaseComputeOp()
1634 //================================================================================
1636 * \brief Desctructor
1638 //================================================================================
1640 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1644 //================================================================================
1646 * \brief perform it's intention action: compute mesh
1648 //================================================================================
1650 void SMESHGUI_EvaluateOp::startOperation()
1652 SMESHGUI_BaseComputeOp::evaluateDlg();
1653 SMESHGUI_BaseComputeOp::startOperation();
1654 if (myMesh->_is_nil())
1659 //================================================================================
1661 * \brief Gets dialog of this operation
1662 * \retval LightApp_Dialog* - pointer to dialog of this operation
1664 //================================================================================
1666 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1668 return evaluateDlg();
1671 //================================================================================
1673 * \brief evaluateMesh()
1675 //================================================================================
1677 void SMESHGUI_BaseComputeOp::evaluateMesh()
1681 SMESH::MemoryReserve aMemoryReserve;
1683 SMESH::compute_error_array_var aCompErrors;
1686 bool evaluateFailed = true, memoryLack = false;
1687 SMESH::long_array_var aRes;
1689 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1690 if ( !aMeshSObj ) // IPAL21340
1693 bool hasShape = myMesh->HasShapeToMesh();
1694 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1697 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1698 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1699 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1700 if ( errors->length() > 0 ) {
1701 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1703 SUIT_OverrideCursor aWaitCursor;
1705 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1708 aRes = gen->Evaluate(myMesh, myMainShape);
1710 catch(const SALOME::SALOME_Exception & S_ex){
1715 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1718 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1720 catch(const SALOME::SALOME_Exception & S_ex){
1726 aMemoryReserve.release();
1728 evaluateFailed = ( aCompErrors->length() > 0 );
1729 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1733 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1734 bool noHypoError = ( aHypErrors.isEmpty() );
1736 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1737 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1739 bool isShowResultDlg = true;
1741 //switch( aNotifyMode ) {
1742 //case 0: // show the mesh computation result dialog NEVER
1743 //isShowResultDlg = false;
1746 //case 1: // show the mesh computation result dialog if there are some errors
1747 //if ( memoryLack || !noHypoError )
1748 // isShowResultDlg = true;
1751 // isShowResultDlg = false;
1755 //default: // show the result dialog after each mesh computation
1756 //isShowResultDlg = true;
1760 if ( isShowResultDlg )
1761 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1762 noHypoError, aHypErrors);
1766 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1767 const bool theMemoryLack,
1768 const bool theNoCompError,
1769 SMESH::compute_error_array_var& theCompErrors,
1770 const bool theNoHypoError,
1771 const QString& theHypErrors)
1773 bool hasShape = myMesh->HasShapeToMesh();
1774 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1775 aCompDlg->myMemoryLackGroup->hide();
1777 if ( theMemoryLack )
1779 aCompDlg->myMemoryLackGroup->show();
1780 aCompDlg->myFullInfo->hide();
1781 aCompDlg->myBriefInfo->hide();
1782 aCompDlg->myHypErrorGroup->hide();
1783 aCompDlg->myCompErrorGroup->hide();
1785 else if ( theNoCompError && theNoHypoError )
1787 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1788 aCompDlg->myFullInfo->show();
1789 aCompDlg->myBriefInfo->hide();
1790 aCompDlg->myHypErrorGroup->hide();
1791 aCompDlg->myCompErrorGroup->hide();
1795 QTableWidget* tbl = aCompDlg->myTable;
1796 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1797 aCompDlg->myBriefInfo->show();
1798 aCompDlg->myFullInfo->hide();
1800 if ( theNoHypoError ) {
1801 aCompDlg->myHypErrorGroup->hide();
1804 aCompDlg->myHypErrorGroup->show();
1805 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1808 if ( theNoCompError ) {
1809 aCompDlg->myCompErrorGroup->hide();
1812 aCompDlg->myCompErrorGroup->show();
1814 aCompDlg->myPublishBtn->hide();
1815 aCompDlg->myShowBtn->hide();
1817 // fill table of errors
1818 tbl->setRowCount( theCompErrors->length() );
1819 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1820 else tbl->showColumn( COL_SHAPE );
1821 tbl->setColumnWidth( COL_ERROR, 200 );
1823 bool hasBadMesh = false;
1824 for ( int row = 0; row < theCompErrors->length(); ++row )
1826 SMESH::ComputeError & err = theCompErrors[ row ];
1828 QString text = err.algoName.in();
1829 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1830 else tbl->item( row, COL_ALGO )->setText( text );
1832 text = SMESH::errorText( err.code, err.comment.in() );
1833 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1834 else tbl->item( row, COL_ERROR )->setText( text );
1836 text = QString("%1").arg( err.subShapeID );
1837 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1838 else tbl->item( row, COL_SHAPEID )->setText( text );
1840 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1841 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1842 else tbl->item( row, COL_SHAPE )->setText( text );
1844 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1845 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1846 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1848 text = err.hasBadMesh ? "hasBadMesh" : "";
1849 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1850 else tbl->item( row, COL_BAD_MESH )->setText( text );
1851 if ( err.hasBadMesh ) hasBadMesh = true;
1853 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1854 tbl->resizeRowToContents( row );
1856 tbl->resizeColumnToContents( COL_ALGO );
1857 tbl->resizeColumnToContents( COL_SHAPE );
1860 aCompDlg->myBadMeshBtn->show();
1862 aCompDlg->myBadMeshBtn->hide();
1864 tbl->setCurrentCell(0,0);
1865 currentCellChanged(); // to update buttons
1868 // show dialog and wait, becase Compute can be invoked from Preview operation
1869 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1874 //================================================================================
1876 * \brief Gets dialog of evaluate operation
1877 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1879 //================================================================================
1881 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1885 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1886 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1887 // connect signals and slots
1888 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1889 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1890 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1891 QTableWidget* aTable = me->table();
1892 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1893 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));