1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_ComputeDlg.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
24 #include "SMESHGUI_ComputeDlg.h"
27 #include "SMESHGUI_GEOMGenUtils.h"
28 #include "SMESHGUI_MeshUtils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_MeshInfosBox.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_MeshEditPreview.h"
33 #include "SMESHGUI_MeshOrderOp.h"
34 #include "SMESHGUI_MeshOrderDlg.h"
36 #include "SMESH_Actor.h"
37 #include "SMESH_ActorUtils.h"
39 #include <SMDS_SetIterator.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GEOM includes
44 #include <GEOM_Actor.h>
45 #include <GEOM_wrap.hxx>
47 // SALOME GUI includes
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SALOME_ListIO.hxx>
51 #include <SVTK_ViewWindow.h>
52 #include <SVTK_ViewModel.h>
53 #include <SalomeApp_Application.h>
54 #include <SUIT_ResourceMgr.h>
55 #include <SUIT_OverrideCursor.h>
56 #include <SUIT_MessageBox.h>
57 #include <SUIT_Desktop.h>
58 #include <QtxComboBox.h>
60 // SALOME KERNEL includes
61 #include <SALOMEDS_SObject.hxx>
62 #include <SALOMEDSClient_SObject.hxx>
63 #include <SALOMEDS_wrap.hxx>
65 #include CORBA_SERVER_HEADER(SMESH_Group)
68 #include <BRep_Tool.hxx>
70 #include <TopExp_Explorer.hxx>
71 #include <TopTools_IndexedMapOfShape.hxx>
74 #include <TopLoc_Location.hxx>
75 #include <Poly_Triangulation.hxx>
76 #include <Bnd_Box.hxx>
77 #include <BRepBndLib.hxx>
78 #include <BRepMesh_IncrementalMesh.hxx>
80 #include <Standard_ErrorHandler.hxx>
84 #include <QPushButton>
86 #include <QRadioButton>
87 #include <QTableWidget>
88 #include <QHeaderView>
89 #include <QGridLayout>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QButtonGroup>
93 #include <QCloseEvent>
94 #include <QTimerEvent>
95 #include <QProgressBar>
98 #include <vtkProperty.h>
105 #include <sys/sysinfo.h>
111 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
114 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
117 //using namespace SMESH;
121 //=============================================================================
123 * \brief Allocate some memory at construction and release it at destruction.
124 * Is used to be able to continue working after mesh generation or visualization
125 * break due to lack of memory
127 //=============================================================================
132 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
133 void release() { delete [] myBuf; myBuf = 0; }
134 ~MemoryReserve() { release(); }
137 // =========================================================================================
139 * \brief Class showing shapes without publishing
141 // =========================================================================================
143 class TShapeDisplayer
146 // -----------------------------------------------------------------------
147 TShapeDisplayer(): myViewWindow(0)
149 myProperty = vtkProperty::New();
150 myProperty->SetRepresentationToWireframe();
151 myProperty->SetColor( 250, 0, 250 );
152 myProperty->SetAmbientColor( 250, 0, 250 );
153 myProperty->SetDiffuseColor( 250, 0, 250 );
154 //myProperty->SetSpecularColor( 250, 0, 250 );
155 myProperty->SetLineWidth( 5 );
157 // -----------------------------------------------------------------------
161 myProperty->Delete();
163 // -----------------------------------------------------------------------
166 if ( hasViewWindow() ) {
167 TActorIterator actorIt = actorIterator();
168 while ( actorIt.more() )
169 if (VTKViewer_Actor* anActor = actorIt.next()) {
170 myViewWindow->RemoveActor( anActor );
174 myIndexToShape.Clear();
176 myShownActors.clear();
179 // -----------------------------------------------------------------------
180 void SetVisibility (bool theVisibility)
182 TActorIterator actorIt = shownIterator();
183 while ( actorIt.more() )
184 if (VTKViewer_Actor* anActor = actorIt.next())
185 anActor->SetVisibility(theVisibility);
186 SMESH::RepaintCurrentView();
188 // -----------------------------------------------------------------------
189 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
191 std::string mainEntry;
192 if ( !aMainShape->_is_nil() )
193 mainEntry = aMainShape->GetStudyEntry();
194 return ( myMainEntry == mainEntry &&
195 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
197 // -----------------------------------------------------------------------
198 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
200 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
201 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
202 std::string mainEntry;
203 if ( !aMainShape->_is_nil() )
204 mainEntry = aMainShape->GetStudyEntry();
205 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
208 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
209 checkTriangulation( aShape );
210 TopExp::MapShapes(aShape, myIndexToShape);
211 myActors.resize( myIndexToShape.Extent(), 0 );
212 myShownActors.reserve( myIndexToShape.Extent() );
214 myMainEntry = mainEntry;
215 myViewWindow = aViewWindow;
217 if ( only ) { // hide shown actors
218 TActorIterator actorIt = shownIterator();
219 while ( actorIt.more() )
220 if (VTKViewer_Actor* anActor = actorIt.next())
221 anActor->SetVisibility(false);
222 myShownActors.clear();
224 // find actors to show
225 TopoDS_Shape aShape = myIndexToShape( subShapeID );
226 if ( !aShape.IsNull() ) {
227 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
228 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
229 //checkTriangulation( exp.Current() );
230 if ( GEOM_Actor* anActor = getActor( exp.Current() ) ) {
231 int UNbIsos = resMgr->integerValue( "Geometry", "iso_number_u", 1);
232 int VNbIsos = resMgr->integerValue( "Geometry", "iso_number_v", 1);
233 int aNbIsos[2] = { UNbIsos ? UNbIsos : 1, VNbIsos ? VNbIsos : 1 };
234 anActor->SetNbIsos( aNbIsos );
235 myShownActors.push_back( anActor );
238 if ( type == TopAbs_FACE ) {
239 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
240 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
241 if ( !BRep_Tool::Degenerated( edge ))
242 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
243 myShownActors.push_back( anActor );
247 myBuiltSubs.insert( subShapeID );
250 // -----------------------------------------------------------------------
254 typedef std::vector<GEOM_Actor*> TActorVec;
256 TActorVec myShownActors;
257 TopTools_IndexedMapOfShape myIndexToShape;
258 std::string myMainEntry;
259 SVTK_ViewWindow* myViewWindow;
260 vtkProperty* myProperty;
261 std::set<int> myBuiltSubs;
263 // -----------------------------------------------------------------------
264 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
265 TActorIterator actorIterator() {
266 return TActorIterator( myActors.begin(), myActors.end() );
268 TActorIterator shownIterator() {
269 return TActorIterator( myShownActors.begin(), myShownActors.end() );
271 // -----------------------------------------------------------------------
272 GEOM_Actor* getActor(const TopoDS_Shape& shape)
274 int index = myIndexToShape.FindIndex( shape ) - 1;
275 if ( index < 0 || index >= myActors.size() )
277 GEOM_Actor* & actor = myActors[ index ];
279 actor = GEOM_Actor::New();
281 actor->SetShape(shape,0,0);
282 actor->SetProperty(myProperty);
283 actor->SetShadingProperty(myProperty);
284 actor->SetWireframeProperty(myProperty);
285 actor->SetPreviewProperty(myProperty);
286 actor->PickableOff();
287 // if ( shape.ShapeType() == TopAbs_EDGE )
288 // actor->SubShapeOn();
289 myViewWindow->AddActor( actor );
294 // -----------------------------------------------------------------------
295 void checkTriangulation(const TopoDS_Shape& shape)
297 TopLoc_Location aLoc;
298 Standard_Boolean alreadymesh = Standard_True;
299 TopExp_Explorer ex(shape, TopAbs_FACE);
301 for ( ; ex.More(); ex.Next()) {
302 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
303 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
304 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
307 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
308 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
309 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
310 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
312 if (alreadymesh) return;
313 // Compute default deflection
315 BRepBndLib::Add(shape, B);
316 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
317 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
318 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
319 BRepMesh_IncrementalMesh MESH(shape,deflection);
321 // -----------------------------------------------------------------------
322 bool hasViewWindow() const
324 if ( !myViewWindow ) return false;
326 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
327 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
333 // =========================================================================================
335 * \brief Return text describing an error
337 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
338 QString errorText(int errCode, const char* comment)
342 CASE2TEXT( COMPERR_OK );
343 CASE2TEXT( COMPERR_BAD_INPUT_MESH );
344 CASE2TEXT( COMPERR_STD_EXCEPTION );
345 CASE2TEXT( COMPERR_OCC_EXCEPTION );
346 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
347 CASE2TEXT( COMPERR_EXCEPTION );
348 CASE2TEXT( COMPERR_MEMORY_PB );
349 CASE2TEXT( COMPERR_BAD_SHAPE );
350 CASE2TEXT( COMPERR_CANCELED );
351 CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
352 CASE2TEXT( COMPERR_BAD_PARMETERS );
353 case SMESH::COMPERR_ALGO_FAILED:
354 if ( strlen(comment) == 0 )
355 text = QObject::tr("COMPERR_ALGO_FAILED");
357 case SMESH::COMPERR_WARNING:
358 text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
361 text = QString("#%1").arg( -errCode );
363 if ( text.length() > 0 ) text += ". ";
364 return text + comment;
366 // -----------------------------------------------------------------------
368 * \brief Return SO of a sub-shape
370 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
372 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
373 if ( subShapeID == 1 || !so )
375 _PTR(ChildIterator) it;
376 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
377 it = study->NewChildIterator(so);
380 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
381 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
382 if ( !geom->_is_nil() ) {
383 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
384 if ( list->length() == 1 && list[0] == subShapeID )
386 GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
387 if ( aMainShape->IsSame( mainGO ))
395 // -----------------------------------------------------------------------
397 * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
399 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
401 GEOM::GEOM_Object_var aSubShape;
402 if ( subShapeID == 1 ) {
403 aSubShape = aMainShape;
404 aSubShape->Register();
406 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
407 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
408 aSubShape->Register();
411 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
412 // future call of UnRegister() will delete a servant of this new object
414 return aSubShape._retn();
416 // -----------------------------------------------------------------------
418 * \brief Return shape type name
420 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
421 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
424 if ( !aShape->_is_nil() ) {
425 switch ( aShape->GetShapeType() ) {
432 CASE2NAME( COMPSOLID );
433 CASE2NAME( COMPOUND );
439 // -----------------------------------------------------------------------
441 * \brief Return text describing a sub-shape
443 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
446 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
447 text = aSO->GetName().c_str();
448 text += QString(" (%1)").arg( aSO->GetID().c_str() );
451 text = QString("#%1").arg( subShapeID );
452 GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
453 QString typeName = shapeTypeName( shape );
454 if ( typeName.length() )
455 text += QString(" (%1)").arg(typeName);
459 // -----------------------------------------------------------------------
461 * \brief Return a list of selected rows
463 int getSelectedRows(QTableWidget* table, QList<int>& rows)
466 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
467 QTableWidgetSelectionRange range;
468 foreach( range, selRanges )
470 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
471 if ( !rows.count( row ))
474 if ( rows.isEmpty() && table->currentRow() > -1 )
475 if ( !rows.count( table->currentRow() ))
476 rows.append( table->currentRow() );
484 // =========================================================================================
486 * \brief Dialog to compute a mesh and show computation errors
488 //=======================================================================
490 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
491 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
493 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
494 aDlgLay->setMargin( 0 );
495 aDlgLay->setSpacing( SPACING );
497 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
499 aDlgLay->addWidget(aMainFrame);
501 aDlgLay->setStretchFactor(aMainFrame, 1);
504 // =========================================================================================
508 //=======================================================================
510 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
514 //=======================================================================
515 // function : createMainFrame()
516 // purpose : Create frame containing dialog's fields
517 //=======================================================================
519 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
521 QFrame* aFrame = new QFrame(theParent);
523 SUIT_ResourceMgr* rm = resourceMgr();
524 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
530 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
533 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
535 QButtonGroup* aBtnGrp = new QButtonGroup(this);
536 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
537 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
539 QRadioButton* aRBut = new QRadioButton(aPixGrp);
540 aRBut->setIcon(iconCompute);
541 aRBut->setChecked(true);
542 aPixGrpLayout->addWidget(aRBut);
543 aBtnGrp->addButton(aRBut, 0);
547 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
548 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
549 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
550 myMeshName = new QLabel(nameBox);
551 nameBoxLayout->addWidget(myMeshName);
555 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
556 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
558 // Computation errors
560 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
561 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
562 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
563 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
564 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
565 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
566 myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
568 //myTable->setReadOnly( true ); // VSR: check
569 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
570 myTable->hideColumn( COL_PUBLISHED );
571 myTable->hideColumn( COL_SHAPEID );
572 myTable->hideColumn( COL_BAD_MESH );
573 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
574 myTable->setWordWrap( true );
575 myTable->horizontalHeader()->setStretchLastSection( true );
576 myTable->setMinimumWidth( 500 );
579 headers << tr( "COL_ALGO_HEADER" );
580 headers << tr( "COL_SHAPE_HEADER" );
581 headers << tr( "COL_ERROR_HEADER" );
582 headers << tr( "COL_SHAPEID_HEADER" );
583 headers << tr( "COL_PUBLISHED_HEADER" );
585 myTable->setHorizontalHeaderLabels( headers );
588 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
589 grpLayout->setSpacing(SPACING);
590 grpLayout->setMargin(MARGIN);
591 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
592 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
593 grpLayout->addWidget( myShowBtn, 2, 0 );
594 grpLayout->addWidget( myPublishBtn, 2, 1 );
595 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
596 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
597 grpLayout->setColumnStretch( 3, 1 );
599 // Hypothesis definition errors
601 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
602 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
603 myHypErrorGroupLayout->setMargin(MARGIN);
604 myHypErrorGroupLayout->setSpacing(SPACING);
605 myHypErrorLabel = new QLabel(myHypErrorGroup);
606 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
610 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
611 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
612 myMemoryLackGroupLayout->setMargin(MARGIN);
613 myMemoryLackGroupLayout->setSpacing(SPACING);
614 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
615 QFont bold = memLackLabel->font(); bold.setBold(true);
616 memLackLabel->setFont( bold );
617 memLackLabel->setMinimumWidth(300);
618 myMemoryLackGroupLayout->addWidget(memLackLabel);
620 // add all widgets to aFrame
621 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
622 aLay->setMargin( MARGIN );
623 aLay->setSpacing( SPACING );
624 aLay->addWidget( aPixGrp );
625 aLay->addWidget( nameBox );
626 aLay->addWidget( myBriefInfo );
627 aLay->addWidget( myFullInfo );
628 aLay->addWidget( myHypErrorGroup );
629 aLay->addWidget( myCompErrorGroup );
630 aLay->addWidget( myMemoryLackGroup );
631 aLay->setStretchFactor( myCompErrorGroup, 1 );
633 ((QPushButton*) button( OK ))->setDefault( true );
638 //================================================================================
642 //================================================================================
644 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
645 : SMESHGUI_Operation(), myCompDlg( 0 )
647 myTShapeDisplayer = new SMESH::TShapeDisplayer();
648 myBadMeshDisplayer = 0;
650 //myHelpFileName = "/files/about_meshes.htm"; // V3
651 myHelpFileName = "about_meshes_page.html"; // V4
654 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
656 LightApp_SelectionMgr* Sel = selectionMgr();
657 SALOME_ListIO selected; Sel->selectedObjects( selected );
658 Handle(SALOME_InteractiveObject) anIO = selected.First();
659 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
660 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
663 //================================================================================
665 * \brief Start operation
666 * \purpose Init dialog fields, connect signals and slots, show dialog
668 //================================================================================
670 void SMESHGUI_BaseComputeOp::startOperation()
672 // create compute dialog if not created before
675 myMesh = SMESH::SMESH_Mesh::_nil();
676 myMainShape = GEOM::GEOM_Object::_nil();
679 LightApp_SelectionMgr *Sel = selectionMgr();
680 SALOME_ListIO selected; Sel->selectedObjects( selected );
682 int nbSel = selected.Extent();
684 SUIT_MessageBox::warning(desktop(),
685 tr("SMESH_WRN_WARNING"),
686 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
691 myIObject = selected.First();
692 myMesh = SMESH::GetMeshByIO(myIObject);
693 if (myMesh->_is_nil()) {
694 SUIT_MessageBox::warning(desktop(),
695 tr("SMESH_WRN_WARNING"),
696 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
700 myMainShape = myMesh->GetShapeToMesh();
702 SMESHGUI_Operation::startOperation();
705 //================================================================================
706 //================================================================================
708 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
709 SMESH::SMESH_Mesh_var mesh,
710 GEOM::GEOM_Object_var mainShape)
715 myMainShape = mainShape;
718 void SMESHGUI_ComputeDlg_QThread::run()
720 myResult = myGen->Compute(myMesh, myMainShape);
723 bool SMESHGUI_ComputeDlg_QThread::result()
728 void SMESHGUI_ComputeDlg_QThread::cancel()
730 myGen->CancelCompute(myMesh, myMainShape);
733 //================================================================================
734 //================================================================================
736 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
737 SMESH::SMESH_Gen_var gen,
738 SMESH::SMESH_Mesh_var mesh,
739 GEOM::GEOM_Object_var mainShape)
741 Qt::WindowSystemMenuHint |
742 Qt::WindowCloseButtonHint |
744 Qt::WindowMaximizeButtonHint),
745 qthread(gen, mesh, mainShape)
748 setWindowTitle(tr("TITLE"));
749 setMinimumWidth( 200 );
751 cancelButton = new QPushButton(tr("CANCEL"));
752 cancelButton->setDefault(true);
753 cancelButton->setCheckable(true);
755 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
756 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
757 nbNodesLabel = new QLabel("0", this );
758 nbElemsLabel = new QLabel("0", this );
760 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
761 freeRAMLabel = new QLabel("", this );
763 progressBar = new QProgressBar(this);
764 progressBar->setMinimum( 0 );
765 progressBar->setMaximum( 1000 );
767 QGridLayout* layout = new QGridLayout(this);
768 layout->setMargin( MARGIN );
769 layout->setSpacing( SPACING );
771 layout->addWidget(nbNodesName, row, 0);
772 layout->addWidget(nbNodesLabel, row++, 1);
773 layout->addWidget(nbElemsName, row, 0);
774 layout->addWidget(nbElemsLabel, row++, 1);
776 layout->addWidget(freeRAMName, row, 0);
777 layout->addWidget(freeRAMLabel, row++, 1);
779 layout->addWidget(progressBar, row++, 0, 1, 2);
780 layout->addWidget(cancelButton, row++, 0, 1, 2);
784 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
786 startTimer(300); // millisecs
790 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
792 return qthread.result();
795 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
798 cancelButton->setText( tr("CANCELING"));
799 cancelButton->setEnabled(false);
802 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
804 if ( !cancelButton->isChecked() ) // not yet cancelled
805 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
807 if(qthread.isFinished())
813 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
814 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
817 const int err = sysinfo( &si );
819 freeRAMLabel->setText("");
821 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
822 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
828 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
830 if(qthread.isRunning())
838 //================================================================================
840 * \brief computeMesh()
842 //================================================================================
844 void SMESHGUI_BaseComputeOp::computeMesh()
848 SMESH::MemoryReserve aMemoryReserve;
850 SMESH::compute_error_array_var aCompErrors;
853 bool computeFailed = true, memoryLack = false;
855 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
856 if ( !aMeshSObj ) // IPAL 21340
858 bool hasShape = myMesh->HasShapeToMesh();
859 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
862 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
863 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
864 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
865 if ( errors->length() > 0 ) {
866 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
868 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
869 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
870 tr( "FULL_RECOMPUTE_QUESTION" ),
871 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
873 SUIT_OverrideCursor aWaitCursor;
875 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
878 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
879 qthreaddialog.exec();
880 computeFailed = !qthreaddialog.result();
882 catch(const SALOME::SALOME_Exception & S_ex) {
886 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
889 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
890 // check if there are memory problems
891 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
892 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
894 catch(const SALOME::SALOME_Exception & S_ex) {
898 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
902 // NPAL16631: if ( !memoryLack )
904 SMESH::ModifiedMesh( aMeshSObj,
905 !computeFailed && aHypErrors.isEmpty(),
906 myMesh->NbNodes() == 0);
907 update( UF_ObjBrowser | UF_Model );
910 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
911 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
913 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
914 int entities = SMESH_Actor::eAllEntity;
918 if ( getSMESHGUI()->automaticUpdate( myMesh, &entities, &limitExceeded, &hidden ) )
921 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
924 SMESH_Actor *anActor = SMESH::FindActorByObject( myMesh );
925 if ( !anActor ) anActor = SMESH::CreateActor( aMeshSObj->GetStudy(), aMeshSObj->GetID().c_str(), true );
926 if ( anActor ) // actor is not created for an empty mesh
928 anActor->SetEntityMode( entities );
929 SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
931 SMESH::Update(myIObject, true);
935 QStringList hiddenMsg;
936 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
937 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
938 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
939 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
940 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
941 SUIT_MessageBox::warning( desktop(),
942 tr( "SMESH_WRN_WARNING" ),
943 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).arg( myMesh->NbElements() ).arg( limitSize ).arg( hiddenMsg.join(", ") ) );
948 MESSAGE ( "Exception thrown during mesh visualization" );
950 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
951 SMESH::OnVisuException();
958 else if ( limitExceeded )
960 SUIT_MessageBox::warning( desktop(),
961 tr( "SMESH_WRN_WARNING" ),
962 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( myMesh->NbElements() ).arg( limitSize ) );
965 LightApp_SelectionMgr *Sel = selectionMgr();
968 SALOME_ListIO selected;
969 selected.Append( myIObject );
970 Sel->setSelectedObjects( selected );
976 aMemoryReserve.release();
978 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
982 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
983 bool noHypoError = ( aHypErrors.isEmpty() );
985 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
986 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
988 bool isShowResultDlg = true;
989 switch( aNotifyMode ) {
990 case 0: // show the mesh computation result dialog NEVER
991 isShowResultDlg = false;
994 case 1: // show the mesh computation result dialog if there are some errors
995 if ( memoryLack || !noCompError || !noHypoError )
996 isShowResultDlg = true;
999 isShowResultDlg = false;
1003 default: // show the result dialog after each mesh computation
1004 isShowResultDlg = true;
1008 if ( isShowResultDlg )
1009 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1012 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1013 const bool theNoCompError,
1014 SMESH::compute_error_array_var& theCompErrors,
1015 const bool theNoHypoError,
1016 const QString& theHypErrors )
1018 bool hasShape = myMesh->HasShapeToMesh();
1019 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1020 aCompDlg->myMemoryLackGroup->hide();
1022 if ( theMemoryLack )
1024 aCompDlg->myMemoryLackGroup->show();
1025 aCompDlg->myFullInfo->hide();
1026 aCompDlg->myBriefInfo->hide();
1027 aCompDlg->myHypErrorGroup->hide();
1028 aCompDlg->myCompErrorGroup->hide();
1030 else if ( theNoCompError && theNoHypoError )
1032 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1033 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1034 aCompDlg->myFullInfo->show();
1035 aCompDlg->myBriefInfo->hide();
1036 aCompDlg->myHypErrorGroup->hide();
1037 aCompDlg->myCompErrorGroup->hide();
1041 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1042 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1043 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1044 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1046 // full or brief mesh info
1047 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1048 if ( onlyWarnings ) {
1049 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1050 aCompDlg->myFullInfo->show();
1051 aCompDlg->myBriefInfo->hide();
1053 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1054 aCompDlg->myBriefInfo->show();
1055 aCompDlg->myFullInfo->hide();
1058 // pbs of hypo dfinitions
1059 if ( theNoHypoError ) {
1060 aCompDlg->myHypErrorGroup->hide();
1062 aCompDlg->myHypErrorGroup->show();
1063 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1067 if ( theNoCompError )
1069 aCompDlg->myCompErrorGroup->hide();
1073 aCompDlg->myCompErrorGroup->show();
1076 aCompDlg->myWarningLabel->show();
1078 aCompDlg->myWarningLabel->hide();
1081 aCompDlg->myPublishBtn->hide();
1082 aCompDlg->myShowBtn->hide();
1085 aCompDlg->myPublishBtn->show();
1086 aCompDlg->myShowBtn->show();
1089 // fill table of errors
1090 QTableWidget* tbl = aCompDlg->myTable;
1091 tbl->setRowCount( theCompErrors->length() );
1092 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1093 else tbl->showColumn( COL_SHAPE );
1094 tbl->setColumnWidth( COL_ERROR, 200 );
1096 bool hasBadMesh = false;
1097 for ( int row = 0; row < theCompErrors->length(); ++row )
1099 SMESH::ComputeError & err = theCompErrors[ row ];
1101 QString text = err.algoName.in();
1102 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1103 else tbl->item( row, COL_ALGO )->setText( text );
1105 text = SMESH::errorText( err.code, err.comment.in() );
1106 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1107 else tbl->item( row, COL_ERROR )->setText( text );
1109 text = QString("%1").arg( err.subShapeID );
1110 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1111 else tbl->item( row, COL_SHAPEID )->setText( text );
1113 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1114 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1115 else tbl->item( row, COL_SHAPE )->setText( text );
1117 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1118 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1119 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1121 text = err.hasBadMesh ? "hasBadMesh" : "";
1122 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1123 else tbl->item( row, COL_BAD_MESH )->setText( text );
1124 if ( err.hasBadMesh ) hasBadMesh = true;
1126 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1127 tbl->resizeRowToContents( row );
1129 tbl->resizeColumnToContents( COL_ALGO );
1130 tbl->resizeColumnToContents( COL_SHAPE );
1131 tbl->setWordWrap( true );
1134 aCompDlg->myBadMeshBtn->show();
1135 aCompDlg->myBadMeshToGroupBtn->show();
1138 aCompDlg->myBadMeshBtn->hide();
1139 aCompDlg->myBadMeshToGroupBtn->hide();
1141 tbl->setCurrentCell(0,0);
1142 currentCellChanged(); // to update buttons
1145 // show dialog and wait, becase Compute can be invoked from Preview operation
1146 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1150 //================================================================================
1152 * \brief Stops operation
1154 //================================================================================
1156 void SMESHGUI_BaseComputeOp::stopOperation()
1158 SMESHGUI_Operation::stopOperation();
1159 if ( myTShapeDisplayer )
1160 myTShapeDisplayer->SetVisibility( false );
1161 if ( myBadMeshDisplayer ) {
1162 myBadMeshDisplayer->SetVisibility( false );
1163 // delete it in order not to have problems at its destruction when the viewer
1164 // where it worked is dead due to e.g. study closing
1165 delete myBadMeshDisplayer;
1166 myBadMeshDisplayer = 0;
1168 myIObject.Nullify();
1171 //================================================================================
1173 * \brief publish selected sub-shape
1175 //================================================================================
1177 void SMESHGUI_BaseComputeOp::onPublishShape()
1179 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1180 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1183 SMESH::getSelectedRows( table(), rows );
1185 foreach ( row, rows )
1187 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1188 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1189 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1191 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1193 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1194 SALOMEDS::SObject_wrap so =
1195 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1196 // look for myMainShape in the table
1197 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1198 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1199 if ( so->_is_nil() ) {
1200 CORBA::String_var name = so->GetName();
1201 CORBA::String_var entry = so->GetID();
1202 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1203 table()->item( r, COL_SHAPE )->setText( shapeText );
1204 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1209 if ( curSub == 1 ) continue;
1211 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1212 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1213 if ( !so->_is_nil() ) {
1214 CORBA::String_var name = so->GetName();
1215 CORBA::String_var entry = so->GetID();
1216 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1217 table()->item( row, COL_SHAPE )->setText( shapeText );
1218 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1222 getSMESHGUI()->getApp()->updateObjectBrowser();
1223 currentCellChanged(); // to update buttons
1226 //================================================================================
1228 * \brief show mesh elements preventing computation of a submesh of current row
1230 //================================================================================
1232 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1234 myTShapeDisplayer->SetVisibility( false );
1236 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1237 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1239 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1240 SMESHGUI* gui = getSMESHGUI();
1241 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1242 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1243 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1244 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1245 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1246 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1247 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1248 vtkProperty* prop = vtkProperty::New();
1249 prop->SetLineWidth( aLineWidth * 3 );
1250 prop->SetPointSize( aPointSize * 3 );
1251 prop->SetColor( 250, 0, 250 );
1252 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1253 myBadMeshDisplayer->SetData( aMeshData._retn() );
1259 //================================================================================
1261 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1263 //================================================================================
1265 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1268 SMESH::getSelectedRows( table(), rows );
1270 foreach ( row, rows )
1272 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1274 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1275 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1276 if ( grName.isEmpty() ) grName = "bad mesh";
1277 else grName = "bad mesh of " + grName;
1278 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1279 SMESH::ListOfGroups_var groups
1280 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1281 update( UF_ObjBrowser | UF_Model );
1282 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1284 QStringList anEntryList;
1285 for ( size_t i = 0; i < groups->length(); ++i )
1286 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1287 anEntryList.append( so->GetID().c_str() );
1289 if ( !anEntryList.isEmpty())
1290 anApp->browseObjects( anEntryList, true, false );
1296 //================================================================================
1298 * \brief SLOT called when a selected cell in table() changed
1300 //================================================================================
1302 void SMESHGUI_BaseComputeOp::currentCellChanged()
1304 myTShapeDisplayer->SetVisibility( false );
1305 if ( myBadMeshDisplayer )
1306 myBadMeshDisplayer->SetVisibility( false );
1308 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1310 int nbSelected = SMESH::getSelectedRows( table(), rows );
1312 foreach ( row, rows )
1314 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1315 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1316 if ( hasData && !isPublished )
1317 publishEnable = true;
1319 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1320 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1322 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1329 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1332 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1333 myCompDlg->myShowBtn ->setEnabled( showEnable );
1334 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1335 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1338 //================================================================================
1340 * \brief update preview
1342 //================================================================================
1344 void SMESHGUI_BaseComputeOp::onPreviewShape()
1346 if ( myTShapeDisplayer )
1348 SUIT_OverrideCursor aWaitCursor;
1350 SMESH::getSelectedRows( table(), rows );
1352 bool showOnly = true;
1354 foreach ( row, rows )
1356 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1358 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1362 currentCellChanged(); // to update buttons
1366 //================================================================================
1370 //================================================================================
1372 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1376 delete myTShapeDisplayer;
1377 if ( myBadMeshDisplayer )
1378 delete myBadMeshDisplayer;
1381 //================================================================================
1383 * \brief Gets dialog of compute operation
1384 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1386 //================================================================================
1388 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1392 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1393 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1394 // connect signals and slots
1395 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1396 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1397 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1398 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1400 QTableWidget* aTable = me->table();
1401 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1402 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1407 //================================================================================
1409 * \brief returns from compute mesh result dialog
1411 //================================================================================
1413 bool SMESHGUI_BaseComputeOp::onApply()
1418 //================================================================================
1420 * \brief Return a table
1422 //================================================================================
1424 QTableWidget* SMESHGUI_BaseComputeOp::table()
1426 return myCompDlg->myTable;
1430 //================================================================================
1432 * \brief Constructor
1434 //================================================================================
1436 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1437 : SMESHGUI_BaseComputeOp()
1442 //================================================================================
1444 * \brief Desctructor
1446 //================================================================================
1448 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1452 //================================================================================
1454 * \brief perform it's intention action: compute mesh
1456 //================================================================================
1458 void SMESHGUI_ComputeOp::startOperation()
1460 SMESHGUI_BaseComputeOp::startOperation();
1461 if (myMesh->_is_nil())
1466 //================================================================================
1468 * \brief check the same operations on the same mesh
1470 //================================================================================
1472 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1474 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1476 if ( !myMesh->_is_nil() && baseOp ) {
1477 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1478 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1483 //================================================================================
1485 * \brief Gets dialog of this operation
1486 * \retval LightApp_Dialog* - pointer to dialog of this operation
1488 //================================================================================
1490 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1492 return computeDlg();
1495 //================================================================================
1497 * \brief Constructor
1499 //================================================================================
1501 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1502 : SMESHGUI_BaseComputeOp(),
1506 myPreviewDisplayer( 0 )
1508 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1511 //================================================================================
1515 //================================================================================
1517 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1524 if ( myPreviewDisplayer )
1525 delete myPreviewDisplayer;
1526 myPreviewDisplayer = 0;
1529 //================================================================================
1531 * \brief Gets current dialog of this operation
1532 * \retval LightApp_Dialog* - pointer to dialog of this operation
1534 //================================================================================
1536 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1541 //================================================================================
1543 * \brief perform it's intention action: prepare data
1545 //================================================================================
1547 void SMESHGUI_PrecomputeOp::startOperation()
1551 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1554 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1555 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1556 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1558 myActiveDlg = myDlg;
1560 // connect signal to compute dialog. which will be shown after Compute mesh operation
1561 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1564 // disconnect signals
1565 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1566 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1567 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1568 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1569 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1572 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1573 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1574 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1575 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1576 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1577 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1578 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1579 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1580 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1581 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1584 SMESHGUI_BaseComputeOp::startOperation();
1585 if (myMesh->_is_nil())
1588 if (myDlg->getPreviewMode() == -1)
1590 // nothing to preview
1591 SUIT_MessageBox::warning(desktop(),
1592 tr("SMESH_WRN_WARNING"),
1593 tr("SMESH_WRN_NOTHING_PREVIEW"));
1598 // disconnect slot from preview dialog to have Apply from results of compute operation only
1599 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1600 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1605 //================================================================================
1607 * \brief Stops operation
1609 //================================================================================
1611 void SMESHGUI_PrecomputeOp::stopOperation()
1613 if ( myPreviewDisplayer )
1615 myPreviewDisplayer->SetVisibility( false );
1616 delete myPreviewDisplayer;
1617 myPreviewDisplayer = 0;
1619 myMapShapeId.clear();
1620 SMESHGUI_BaseComputeOp::stopOperation();
1623 //================================================================================
1625 * \brief reinitialize dialog after operaiton become active again
1627 //================================================================================
1629 void SMESHGUI_PrecomputeOp::resumeOperation()
1631 if ( myActiveDlg == myDlg )
1633 SMESHGUI_BaseComputeOp::resumeOperation();
1636 //================================================================================
1638 * \brief perform it's intention action: reinitialise dialog
1640 //================================================================================
1642 void SMESHGUI_PrecomputeOp::initDialog()
1646 QMap<int, int> modeMap;
1647 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1648 getAssignedAlgos( pMesh, modeMap );
1649 if ( modeMap.contains( SMESH::DIM_3D ) )
1651 if ( modeMap.contains( SMESH::DIM_2D ) )
1652 modes.append( SMESH::DIM_2D );
1653 if ( modeMap.contains( SMESH::DIM_1D ) )
1654 modes.append( SMESH::DIM_1D );
1656 else if ( modeMap.contains( SMESH::DIM_2D ) )
1658 if ( modeMap.contains( SMESH::DIM_1D ) )
1659 modes.append( SMESH::DIM_1D );
1662 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1663 myOrderMgr->SetMesh( myMesh );
1664 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1665 myDlg->getMeshOrderBox()->setShown(isOrder);
1671 myDlg->setPreviewModes( modes );
1674 //================================================================================
1676 * \brief detect asigned mesh algorithms
1678 //================================================================================
1680 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1681 QMap<int,int>& theModeMap)
1683 _PTR(SObject) aHypRoot;
1684 _PTR(GenericAttribute) anAttr;
1685 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1686 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1688 _PTR(ChildIterator) anIter =
1689 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1690 for ( ; anIter->More(); anIter->Next() )
1692 _PTR(SObject) anObj = anIter->Value();
1693 _PTR(SObject) aRefObj;
1694 if ( anObj->ReferencedObject( aRefObj ) )
1699 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1701 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1702 if ( CORBA::is_nil( aVar ) )
1705 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1707 SMESH::SMESH_Algo_var algo;
1709 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1710 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1711 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1714 if ( !algo->_is_nil() )
1715 theModeMap[ dim ] = 0;
1722 //================================================================================
1724 * \brief perform it's intention action: compute mesh
1726 //================================================================================
1728 void SMESHGUI_PrecomputeOp::onCompute()
1731 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1732 myOrderMgr->SetMeshOrder();
1733 myMapShapeId.clear();
1734 myActiveDlg = computeDlg();
1738 //================================================================================
1740 * \brief perform it's intention action: compute mesh
1742 //================================================================================
1744 void SMESHGUI_PrecomputeOp::onCancel()
1746 QObject* curDlg = sender();
1747 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1749 // return from error messages
1754 bool isRestoreOrder = false;
1755 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1757 // ask to remove already computed mesh elements
1758 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1759 tr( "CLEAR_SUBMESH_QUESTION" ),
1760 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1762 // remove all submeshes for collected shapes
1763 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1764 for ( ; it != myMapShapeId.constEnd(); ++it )
1765 myMesh->ClearSubMesh( *it );
1766 isRestoreOrder = true;
1770 // return previous mesh order
1771 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1772 if (!isRestoreOrder)
1774 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1775 tr( "SMESH_REJECT_MESH_ORDER" ),
1776 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1778 myOrderMgr->SetMeshOrder(myPrevOrder);
1784 myMapShapeId.clear();
1785 SMESHGUI_BaseComputeOp::onCancel();
1788 //================================================================================
1790 * \brief perform it's intention action: preview mesh
1792 //================================================================================
1794 void SMESHGUI_PrecomputeOp::onPreview()
1796 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1799 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1803 // set modified submesh priority if any
1804 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1805 myOrderMgr->SetMeshOrder();
1807 // Compute preview of mesh,
1808 // i.e. compute mesh till indicated dimension
1809 int dim = myDlg->getPreviewMode();
1811 SMESH::MemoryReserve aMemoryReserve;
1813 SMESH::compute_error_array_var aCompErrors;
1816 bool computeFailed = true, memoryLack = false;
1818 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1819 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1821 SMESHGUI* gui = getSMESHGUI();
1822 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1823 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1824 if ( errors->length() > 0 ) {
1825 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1828 SUIT_OverrideCursor aWaitCursor;
1830 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1831 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1832 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1834 SMESH::long_array_var aShapesId = new SMESH::long_array();
1836 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1840 SMESH::MeshPreviewStruct_var previewData =
1841 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1843 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1844 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1846 computeFailed = false;
1847 myPreviewDisplayer->SetData( previewRes );
1848 // append shape indeces with computed mesh entities
1849 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1850 myMapShapeId[ aShapesId[ i ] ] = 0;
1853 myPreviewDisplayer->SetVisibility(false);
1855 catch(const SALOME::SALOME_Exception & S_ex){
1857 myPreviewDisplayer->SetVisibility(false);
1861 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1864 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1865 // check if there are memory problems
1866 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1867 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1869 catch(const SALOME::SALOME_Exception & S_ex){
1874 aMemoryReserve.release();
1876 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1877 bool noHypoError = ( aHypErrors.isEmpty() );
1879 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1880 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1882 bool isShowError = true;
1883 switch( aNotifyMode ) {
1884 case 0: // show the mesh computation result dialog NEVER
1885 isShowError = false;
1887 case 1: // show the mesh computation result dialog if there are some errors
1888 default: // show the result dialog after each mesh computation
1889 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1890 isShowError = false;
1894 aWaitCursor.suspend();
1899 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1900 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1905 //================================================================================
1907 * \brief Constructor
1909 //================================================================================
1911 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1912 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1915 setWindowTitle( tr( "CAPTION" ) );
1917 setButtonText( OK, tr( "COMPUTE" ) );
1918 QFrame* main = mainFrame();
1920 QVBoxLayout* layout = new QVBoxLayout( main );
1922 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1923 layout->addWidget(myOrderBox);
1925 QFrame* frame = new QFrame( main );
1926 layout->setMargin(0); layout->setSpacing(0);
1927 layout->addWidget( frame );
1929 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1930 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1932 myPreviewMode = new QtxComboBox( frame );
1933 frameLay->addWidget( myPreviewMode );
1935 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1936 frameLay->addWidget( myPreviewBtn );
1938 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1941 //================================================================================
1945 //================================================================================
1947 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1951 //================================================================================
1953 * \brief Sets available preview modes
1955 //================================================================================
1957 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1959 myPreviewMode->clear();
1960 QList<int>::const_iterator it = theModes.constBegin();
1961 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1963 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1964 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1965 myPreviewMode->setId( i, *it );
1967 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1970 //================================================================================
1972 * \brief Returns current preview mesh mode
1974 //================================================================================
1976 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1978 return myPreviewMode->currentId();
1981 //================================================================================
1983 * \brief Returns current preview mesh mode
1985 //================================================================================
1987 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1993 //================================================================================
1995 * \brief Constructor
1997 //================================================================================
1999 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2000 : SMESHGUI_BaseComputeOp()
2005 //================================================================================
2007 * \brief Desctructor
2009 //================================================================================
2011 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2015 //================================================================================
2017 * \brief perform it's intention action: compute mesh
2019 //================================================================================
2021 void SMESHGUI_EvaluateOp::startOperation()
2023 SMESHGUI_BaseComputeOp::evaluateDlg();
2024 SMESHGUI_BaseComputeOp::startOperation();
2025 if (myMesh->_is_nil())
2030 //================================================================================
2032 * \brief Gets dialog of this operation
2033 * \retval LightApp_Dialog* - pointer to dialog of this operation
2035 //================================================================================
2037 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2039 return evaluateDlg();
2042 //================================================================================
2044 * \brief evaluateMesh()
2046 //================================================================================
2048 void SMESHGUI_BaseComputeOp::evaluateMesh()
2052 SMESH::MemoryReserve aMemoryReserve;
2054 SMESH::compute_error_array_var aCompErrors;
2057 bool evaluateFailed = true, memoryLack = false;
2058 SMESH::long_array_var aRes;
2060 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2061 if ( !aMeshSObj ) // IPAL21340
2064 bool hasShape = myMesh->HasShapeToMesh();
2065 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2068 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2069 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2070 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2071 if ( errors->length() > 0 ) {
2072 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2074 SUIT_OverrideCursor aWaitCursor;
2076 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2079 aRes = gen->Evaluate(myMesh, myMainShape);
2081 catch(const SALOME::SALOME_Exception & S_ex){
2086 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2089 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2091 catch(const SALOME::SALOME_Exception & S_ex){
2097 aMemoryReserve.release();
2099 evaluateFailed = ( aCompErrors->length() > 0 );
2100 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
2104 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2105 bool noHypoError = ( aHypErrors.isEmpty() );
2107 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2108 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2110 bool isShowResultDlg = true;
2112 //switch( aNotifyMode ) {
2113 //case 0: // show the mesh computation result dialog NEVER
2114 //isShowResultDlg = false;
2117 //case 1: // show the mesh computation result dialog if there are some errors
2118 //if ( memoryLack || !noHypoError )
2119 // isShowResultDlg = true;
2122 // isShowResultDlg = false;
2126 //default: // show the result dialog after each mesh computation
2127 //isShowResultDlg = true;
2131 if ( isShowResultDlg )
2132 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2133 noHypoError, aHypErrors);
2137 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2138 const bool theMemoryLack,
2139 const bool theNoCompError,
2140 SMESH::compute_error_array_var& theCompErrors,
2141 const bool theNoHypoError,
2142 const QString& theHypErrors)
2144 bool hasShape = myMesh->HasShapeToMesh();
2145 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2146 aCompDlg->myMemoryLackGroup->hide();
2148 if ( theMemoryLack )
2150 aCompDlg->myMemoryLackGroup->show();
2151 aCompDlg->myFullInfo->hide();
2152 aCompDlg->myBriefInfo->hide();
2153 aCompDlg->myHypErrorGroup->hide();
2154 aCompDlg->myCompErrorGroup->hide();
2156 else if ( theNoCompError && theNoHypoError )
2158 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2159 aCompDlg->myFullInfo->show();
2160 aCompDlg->myBriefInfo->hide();
2161 aCompDlg->myHypErrorGroup->hide();
2162 aCompDlg->myCompErrorGroup->hide();
2166 QTableWidget* tbl = aCompDlg->myTable;
2167 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2168 aCompDlg->myBriefInfo->show();
2169 aCompDlg->myFullInfo->hide();
2171 if ( theNoHypoError ) {
2172 aCompDlg->myHypErrorGroup->hide();
2175 aCompDlg->myHypErrorGroup->show();
2176 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2179 if ( theNoCompError ) {
2180 aCompDlg->myCompErrorGroup->hide();
2183 aCompDlg->myCompErrorGroup->show();
2185 aCompDlg->myPublishBtn->hide();
2186 aCompDlg->myShowBtn->hide();
2188 // fill table of errors
2189 tbl->setRowCount( theCompErrors->length() );
2190 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2191 else tbl->showColumn( COL_SHAPE );
2192 tbl->setColumnWidth( COL_ERROR, 200 );
2194 bool hasBadMesh = false;
2195 for ( int row = 0; row < theCompErrors->length(); ++row )
2197 SMESH::ComputeError & err = theCompErrors[ row ];
2199 QString text = err.algoName.in();
2200 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2201 else tbl->item( row, COL_ALGO )->setText( text );
2203 text = SMESH::errorText( err.code, err.comment.in() );
2204 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2205 else tbl->item( row, COL_ERROR )->setText( text );
2207 text = QString("%1").arg( err.subShapeID );
2208 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2209 else tbl->item( row, COL_SHAPEID )->setText( text );
2211 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2212 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2213 else tbl->item( row, COL_SHAPE )->setText( text );
2215 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2216 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2217 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2219 text = err.hasBadMesh ? "hasBadMesh" : "";
2220 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2221 else tbl->item( row, COL_BAD_MESH )->setText( text );
2222 if ( err.hasBadMesh ) hasBadMesh = true;
2224 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2225 tbl->resizeRowToContents( row );
2227 tbl->resizeColumnToContents( COL_ALGO );
2228 tbl->resizeColumnToContents( COL_SHAPE );
2229 tbl->setWordWrap( true );
2233 aCompDlg->myBadMeshBtn->show();
2234 aCompDlg->myBadMeshToGroupBtn->show();
2238 aCompDlg->myBadMeshBtn->hide();
2239 aCompDlg->myBadMeshToGroupBtn->hide();
2241 tbl->setCurrentCell(0,0);
2242 currentCellChanged(); // to update buttons
2245 // show dialog and wait, becase Compute can be invoked from Preview operation
2246 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2251 //================================================================================
2253 * \brief Gets dialog of evaluate operation
2254 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2256 //================================================================================
2258 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2262 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2263 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2264 // connect signals and slots
2265 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2266 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2267 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2268 QTableWidget* aTable = me->table();
2269 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2270 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));