Salome HOME
Merge from BR_phase16 branch (09/12/09)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_ComputeDlg.cxx
23 // Author : Edward AGAPOV, Open CASCADE S.A.S.
24 // SMESH includes
25 //
26 #include "SMESHGUI_ComputeDlg.h"
27
28 #include "SMESHGUI.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 "SMESHGUI_MeshOrderOp.h"
36 #include "SMESHGUI_MeshOrderDlg.h"
37
38 #include "SMESH_ActorUtils.h"
39
40 #include <SMDS_SetIterator.hxx>
41 #include <SMDS_Mesh.hxx>
42
43 // SALOME GEOM includes
44 #include <GEOMBase.h>
45 #include <GEOM_Actor.h>
46
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>
59
60 // SALOME KERNEL includes
61 #include <SALOMEDS_SObject.hxx>
62 #include <SALOMEDSClient_SObject.hxx>
63
64 // OCCT includes
65 #include <BRep_Tool.hxx>
66 #include <TopExp.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopTools_IndexedMapOfShape.hxx>
69 #include <TopoDS.hxx>
70
71 #include <TopLoc_Location.hxx>
72 #include <Poly_Triangulation.hxx>
73 #include <Bnd_Box.hxx>
74 #include <BRepBndLib.hxx>
75 #include <BRepMesh_IncrementalMesh.hxx>
76
77 #include <Standard_ErrorHandler.hxx>
78
79 // Qt includes
80 #include <QFrame>
81 #include <QPushButton>
82 #include <QLabel>
83 #include <QRadioButton>
84 #include <QTableWidget>
85 #include <QHeaderView>
86 #include <QGridLayout>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QButtonGroup>
90
91 // VTK includes
92 #include <vtkProperty.h>
93
94 // STL includes
95 #include <vector>
96 #include <set>
97
98 #define SPACING 6
99 #define MARGIN  11
100
101 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
102
103 static void addSeparator( QWidget* parent )
104 {
105   QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
106   int row  = l->rowCount();
107   int cols = l->columnCount();
108   for ( int i = 0; i < cols; i++ ) {
109     QFrame* hline = new QFrame( parent );
110     hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
111     l->addWidget( hline, row, i );
112   }
113 }
114
115 enum TCol {
116   COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
117 };
118
119 //using namespace SMESH;
120
121 namespace SMESH
122 {
123   //=============================================================================
124   /*!
125    * \brief Allocate some memory at construction and release it at destruction.
126    * Is used to be able to continue working after mesh generation or visualization
127    * break due to lack of memory
128    */
129   //=============================================================================
130
131   struct MemoryReserve
132   {
133     char* myBuf;
134     MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
135     void release() { delete [] myBuf; myBuf = 0; }
136     ~MemoryReserve() { release(); }
137   };
138
139   // =========================================================================================
140   /*!
141    * \brief Class showing shapes without publishing
142    */
143   // =========================================================================================
144
145   class TShapeDisplayer
146   {
147   public:
148     // -----------------------------------------------------------------------
149     TShapeDisplayer(): myViewWindow(0)
150     {
151       myProperty = vtkProperty::New();
152       myProperty->SetRepresentationToWireframe();
153       myProperty->SetColor( 250, 0, 250 );
154       myProperty->SetAmbientColor( 250, 0, 250 );
155       myProperty->SetDiffuseColor( 250, 0, 250 );
156       //myProperty->SetSpecularColor( 250, 0, 250 );
157       myProperty->SetLineWidth( 5 );
158     }
159     // -----------------------------------------------------------------------
160     ~TShapeDisplayer()
161     {
162       DeleteActors();
163       myProperty->Delete();
164     }
165     // -----------------------------------------------------------------------
166     void DeleteActors()
167     {
168       if ( hasViewWindow() ) {
169         TActorIterator actorIt = actorIterator();
170         while ( actorIt.more() )
171           if (VTKViewer_Actor* anActor = actorIt.next()) {
172             myViewWindow->RemoveActor( anActor );
173             //anActor->Delete();
174           }
175       }
176       myIndexToShape.Clear();
177       myActors.clear();
178       myShownActors.clear();
179       myBuiltSubs.clear();
180     }
181     // -----------------------------------------------------------------------
182     void SetVisibility (bool theVisibility)
183     {
184       TActorIterator actorIt = shownIterator();
185       while ( actorIt.more() )
186         if (VTKViewer_Actor* anActor = actorIt.next())
187           anActor->SetVisibility(theVisibility);
188       SMESH::RepaintCurrentView();
189     }
190     // -----------------------------------------------------------------------
191     bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
192     {
193       std::string mainEntry;
194       if ( !aMainShape->_is_nil() )
195         mainEntry = aMainShape->GetStudyEntry();
196       return ( myMainEntry == mainEntry &&
197                myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
198     }
199     // -----------------------------------------------------------------------
200     void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
201     {
202       SVTK_ViewWindow* aViewWindow  = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
203       std::string mainEntry;
204       if ( !aMainShape->_is_nil() )
205         mainEntry = aMainShape->GetStudyEntry();
206       if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
207         DeleteActors();
208         TopoDS_Shape aShape;
209         if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
210           checkTriangulation( aShape );
211           TopExp::MapShapes(aShape, myIndexToShape);
212           myActors.resize( myIndexToShape.Extent(), 0 );
213           myShownActors.reserve( myIndexToShape.Extent() );
214         }
215         myMainEntry  = mainEntry;
216         myViewWindow = aViewWindow;
217       }
218       if ( only ) { // hide shown actors
219         TActorIterator actorIt = shownIterator();
220         while ( actorIt.more() )
221           if (VTKViewer_Actor* anActor = actorIt.next())
222             anActor->SetVisibility(false);
223         myShownActors.clear();
224       }
225       // find actors to show
226       TopoDS_Shape aShape = myIndexToShape( subShapeID );
227       if ( !aShape.IsNull() ) {
228         TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
229         for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
230           //checkTriangulation( exp.Current() );
231           if ( GEOM_Actor* anActor = getActor( exp.Current() ))
232             myShownActors.push_back( anActor );
233         }
234         if ( type == TopAbs_FACE ) {
235           for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
236             const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
237             if ( !BRep_Tool::Degenerated( edge ))
238               if ( GEOM_Actor* anActor = getActor( exp.Current() ))
239                 myShownActors.push_back( anActor );
240           }
241         }
242       }
243       myBuiltSubs.insert( subShapeID );
244       SetVisibility(true);
245     }
246     // -----------------------------------------------------------------------
247
248   private:
249
250     typedef std::vector<GEOM_Actor*> TActorVec;
251     TActorVec                  myActors;
252     TActorVec                  myShownActors;
253     TopTools_IndexedMapOfShape myIndexToShape;
254     std::string                myMainEntry;
255     SVTK_ViewWindow*           myViewWindow;
256     vtkProperty*               myProperty;
257     std::set<int>              myBuiltSubs;
258
259     // -----------------------------------------------------------------------
260     typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
261     TActorIterator actorIterator() {
262       return TActorIterator( myActors.begin(), myActors.end() );
263     }
264     TActorIterator shownIterator() {
265       return TActorIterator( myShownActors.begin(), myShownActors.end() );
266     }
267     // -----------------------------------------------------------------------
268     GEOM_Actor* getActor(const TopoDS_Shape& shape)
269     {
270       int index = myIndexToShape.FindIndex( shape ) - 1;
271       if ( index < 0 || index >= myActors.size() )
272         return 0;
273       GEOM_Actor* & actor = myActors[ index ];
274       if ( !actor ) {
275         actor = GEOM_Actor::New();
276         if ( actor ) {
277           actor->SetShape(shape,0,0);
278           actor->SetProperty(myProperty);
279           actor->SetShadingProperty(myProperty);
280           actor->SetWireframeProperty(myProperty);
281           actor->SetPreviewProperty(myProperty);
282           actor->PickableOff();
283           //         if ( shape.ShapeType() == TopAbs_EDGE )
284           //           actor->SubShapeOn();
285           myViewWindow->AddActor( actor );
286         }
287       }
288       return actor;
289     }
290     // -----------------------------------------------------------------------
291     void checkTriangulation(const TopoDS_Shape& shape)
292     {
293       TopLoc_Location aLoc;
294       Standard_Boolean alreadymesh = Standard_True;
295       TopExp_Explorer ex(shape, TopAbs_FACE);
296       if ( ex.More() )
297         for ( ; ex.More(); ex.Next()) {
298           const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
299           Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
300           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
301         }
302       else
303         for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
304           const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
305           Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
306           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
307         }
308       if (alreadymesh) return;
309       // Compute default deflection
310       Bnd_Box B;
311       BRepBndLib::Add(shape, B);
312       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
313       B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
314       double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
315       BRepMesh_IncrementalMesh MESH(shape,deflection);
316     }
317     // -----------------------------------------------------------------------
318     bool hasViewWindow() const
319     {
320       if ( !myViewWindow ) return false;
321
322       if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
323         return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
324                                   myViewWindow );
325       return false;
326     }
327   };
328
329   // =========================================================================================
330   /*!
331    * \brief Return text describing an error
332    */
333 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
334   QString errorText(int errCode, const char* comment)
335   {
336     QString text;
337     switch ( errCode ) {
338       CASE2TEXT( COMPERR_OK            );
339       CASE2TEXT( COMPERR_BAD_INPUT_MESH);
340       CASE2TEXT( COMPERR_STD_EXCEPTION );
341       CASE2TEXT( COMPERR_OCC_EXCEPTION );
342     case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
343       CASE2TEXT( COMPERR_EXCEPTION     );
344       CASE2TEXT( COMPERR_MEMORY_PB     );
345       CASE2TEXT( COMPERR_BAD_SHAPE     );
346     case SMESH::COMPERR_ALGO_FAILED:
347       if ( strlen(comment) == 0 )
348         text = QObject::tr("COMPERR_ALGO_FAILED");
349       break;
350     default:
351       text = QString("#%1").arg( -errCode );
352     }
353     if ( text.length() > 0 ) text += ". ";
354     return text + comment;
355   }
356   // -----------------------------------------------------------------------
357   /*!
358    * \brief Return SO of a subshape
359    */
360   _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
361   {
362     _PTR(SObject) so = SMESH::FindSObject(aMainShape);
363     if ( subShapeID == 1 || !so )
364       return so;
365     _PTR(ChildIterator) it;
366     if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
367       it =  study->NewChildIterator(so);
368     _PTR(SObject) subSO;
369     if ( it ) {
370       for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
371         GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
372         if ( !geom->_is_nil() ) {
373           GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
374           if ( list->length() == 1 && list[0] == subShapeID )
375             subSO = it->Value();
376         }
377       }
378     }
379     return subSO;
380   }
381   // -----------------------------------------------------------------------
382   /*!
383    * \brief Return subshape by ID
384    */
385   GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
386   {
387     GEOM::GEOM_Object_var aSubShape;
388     if ( subShapeID == 1 )
389       aSubShape = aMainShape;
390     else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
391       aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
392     else
393       aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
394     return aSubShape._retn();
395   }
396   // -----------------------------------------------------------------------
397   /*!
398    * \brief Return shape type name
399    */
400 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
401   QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
402   {
403     QString name = dflt;
404     if ( !aShape->_is_nil() ) {
405       switch ( aShape->GetShapeType() ) {
406       CASE2NAME( VERTEX    );
407       CASE2NAME( EDGE      );
408       CASE2NAME( WIRE      );
409       CASE2NAME( FACE      );
410       CASE2NAME( SHELL     );
411       CASE2NAME( SOLID     );
412       CASE2NAME( COMPSOLID );
413       CASE2NAME( COMPOUND  );
414       default:;
415       }
416     }
417     return name;
418   }
419   // -----------------------------------------------------------------------
420   /*!
421    * \brief Return text describing a subshape
422    */
423   QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
424   {
425     QString text;
426     if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
427       text = aSO->GetName().c_str();
428     else {
429       text = QString("#%1").arg( subShapeID );
430       QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
431       if ( typeName.length() )
432         text += QString(" (%1)").arg(typeName);
433     }
434     return text;
435   }
436   // -----------------------------------------------------------------------
437   /*!
438    * \brief Return a list of selected rows
439    */
440   int getSelectedRows(QTableWidget* table, QList<int>& rows)
441   {
442     rows.clear();
443     QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
444     QTableWidgetSelectionRange range;
445     foreach( range, selRanges )
446     {
447       for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
448         rows.append( row );
449     }
450     if ( rows.isEmpty() && table->currentRow() > -1 )
451       rows.append( table->currentRow() );
452
453     return rows.count();
454   }
455
456 } // namespace SMESH
457
458
459 // =========================================================================================
460 /*!
461  * \brief Dialog to compute a mesh and show computation errors
462  */
463 //=======================================================================
464
465 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
466  : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
467 {
468   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
469   aDlgLay->setMargin( 0 );
470   aDlgLay->setSpacing( SPACING );
471
472   QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
473
474   aDlgLay->addWidget(aMainFrame);
475
476   aDlgLay->setStretchFactor(aMainFrame, 1);
477 }
478
479 // =========================================================================================
480 /*!
481  * \brief Destructor
482  */
483 //=======================================================================
484
485 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
486 {
487 }
488
489 //=======================================================================
490 // function : createMainFrame()
491 // purpose  : Create frame containing dialog's fields
492 //=======================================================================
493
494 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
495 {
496   QFrame* aFrame = new QFrame(theParent);
497
498   SUIT_ResourceMgr* rm = resourceMgr();
499   QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
500
501   // constructor
502
503   QGroupBox* aPixGrp;
504   if(ForEval) {
505     aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
506   }
507   else {
508     aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
509   }
510   QButtonGroup* aBtnGrp = new QButtonGroup(this);
511   QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
512   aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
513
514   QRadioButton* aRBut = new QRadioButton(aPixGrp);
515   aRBut->setIcon(iconCompute);
516   aRBut->setChecked(true);
517   aPixGrpLayout->addWidget(aRBut);
518   aBtnGrp->addButton(aRBut, 0);
519
520   // Mesh name
521
522   QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
523   QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
524   nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
525   myMeshName = new QLabel(nameBox);
526   nameBoxLayout->addWidget(myMeshName);
527
528   // Mesh Info
529
530   myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
531   myFullInfo  = new SMESHGUI_MeshInfosBox(true,  aFrame);
532
533   // Computation errors
534
535   myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
536   myTable      = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
537   myShowBtn    = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
538   myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
539   myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
540
541   //myTable->setReadOnly( true ); // VSR: check
542   myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
543   myTable->hideColumn( COL_PUBLISHED );
544   myTable->hideColumn( COL_SHAPEID );
545   myTable->hideColumn( COL_BAD_MESH );
546   myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
547
548   QStringList headers;
549   headers << tr( "COL_ALGO_HEADER" );
550   headers << tr( "COL_SHAPE_HEADER" );
551   headers << tr( "COL_ERROR_HEADER" );
552   headers << tr( "COL_SHAPEID_HEADER" );
553   headers << tr( "COL_PUBLISHED_HEADER" );
554
555   myTable->setHorizontalHeaderLabels( headers );
556
557   // layouting
558   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
559   grpLayout->setSpacing(SPACING);
560   grpLayout->setMargin(MARGIN);
561   grpLayout->addWidget( myTable,      0, 0, 4, 1 );
562   grpLayout->addWidget( myShowBtn,    0, 1 );
563   grpLayout->addWidget( myPublishBtn, 1, 1 );
564   grpLayout->addWidget( myBadMeshBtn, 2, 1 );
565   grpLayout->setRowStretch( 3, 1 );
566
567   // Hypothesis definition errors
568
569   myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
570   QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
571   myHypErrorGroupLayout->setMargin(MARGIN);
572   myHypErrorGroupLayout->setSpacing(SPACING);
573   myHypErrorLabel = new QLabel(myHypErrorGroup);
574   myHypErrorGroupLayout->addWidget(myHypErrorLabel);
575
576   // Memory Lack Label
577
578   myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
579   QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
580   myMemoryLackGroupLayout->setMargin(MARGIN);
581   myMemoryLackGroupLayout->setSpacing(SPACING);
582   QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
583   QFont bold = memLackLabel->font(); bold.setBold(true);
584   memLackLabel->setFont( bold );
585   memLackLabel->setMinimumWidth(300);
586   myMemoryLackGroupLayout->addWidget(memLackLabel);
587
588   // add all widgets to aFrame
589   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
590   aLay->setMargin( 0 );
591   aLay->setSpacing( 0 );
592   aLay->addWidget( aPixGrp );
593   aLay->addWidget( nameBox );
594   aLay->addWidget( myBriefInfo );
595   aLay->addWidget( myFullInfo );
596   aLay->addWidget( myHypErrorGroup );
597   aLay->addWidget( myCompErrorGroup );
598   aLay->addWidget( myMemoryLackGroup );
599   aLay->setStretchFactor( myCompErrorGroup, 1 );
600
601   ((QPushButton*) button( OK ))->setDefault( true );
602
603   return aFrame;
604 }
605
606 //================================================================================
607 /*!
608  * \brief Constructor
609 */
610 //================================================================================
611
612 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
613   : SMESHGUI_Operation(), myCompDlg( 0 )
614 {
615   myTShapeDisplayer = new SMESH::TShapeDisplayer();
616   myBadMeshDisplayer = 0;
617
618   //myHelpFileName = "/files/about_meshes.htm"; // V3
619   myHelpFileName = "about_meshes_page.html"; // V4
620 }
621
622 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
623 {
624   LightApp_SelectionMgr* Sel = selectionMgr();
625   SALOME_ListIO selected; Sel->selectedObjects( selected );
626   Handle(SALOME_InteractiveObject) anIO = selected.First();
627   SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
628   return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
629 }
630
631 //================================================================================
632 /*!
633  * \brief Start operation
634  * \purpose Init dialog fields, connect signals and slots, show dialog
635  */
636 //================================================================================
637
638 void SMESHGUI_BaseComputeOp::startOperation()
639 {
640   // create compute dialog if not created before
641   computeDlg();
642
643   myMesh      = SMESH::SMESH_Mesh::_nil();
644   myMainShape = GEOM::GEOM_Object::_nil();
645
646   // check selection
647   LightApp_SelectionMgr *Sel = selectionMgr();
648   SALOME_ListIO selected; Sel->selectedObjects( selected );
649
650   int nbSel = selected.Extent();
651   if (nbSel != 1) {
652     SUIT_MessageBox::warning(desktop(),
653                              tr("SMESH_WRN_WARNING"),
654                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
655     onCancel();
656     return;
657   }
658
659   myIObject = selected.First();
660   myMesh = SMESH::GetMeshByIO(myIObject);
661   if (myMesh->_is_nil()) {
662     SUIT_MessageBox::warning(desktop(),
663                              tr("SMESH_WRN_WARNING"),
664                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
665     onCancel();
666     return;
667   }
668   myMainShape = myMesh->GetShapeToMesh();
669
670   SMESHGUI_Operation::startOperation();
671 }
672
673 //================================================================================
674 /*!
675  * \brief computeMesh()
676 */
677 //================================================================================
678
679 void SMESHGUI_BaseComputeOp::computeMesh()
680 {
681   // COMPUTE MESH
682
683   SMESH::MemoryReserve aMemoryReserve;
684
685   SMESH::compute_error_array_var aCompErrors;
686   QString                        aHypErrors;
687
688   bool computeFailed = true, memoryLack = false;
689
690   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
691   if ( !aMeshSObj ) // IPAL 21340
692     return;
693   bool hasShape = myMesh->HasShapeToMesh();
694   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
695   if ( shapeOK )
696   {
697     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
698     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
699     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
700     if ( errors->length() > 0 ) {
701       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
702     }
703     SUIT_OverrideCursor aWaitCursor;
704     try {
705 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
706       OCC_CATCH_SIGNALS;
707 #endif
708       if (gen->Compute(myMesh, myMainShape))
709         computeFailed = false;
710     }
711     catch(const SALOME::SALOME_Exception & S_ex){
712       memoryLack = true;
713     }
714     try {
715 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
716       OCC_CATCH_SIGNALS;
717 #endif
718       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
719       // check if there are memory problems
720       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
721         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
722     }
723     catch(const SALOME::SALOME_Exception & S_ex){
724       memoryLack = true;
725     }
726
727     // NPAL16631: if ( !memoryLack )
728     {
729       SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
730       update( UF_ObjBrowser | UF_Model );
731
732       // SHOW MESH
733       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
734       if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
735       {
736         try {
737 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
738           OCC_CATCH_SIGNALS;
739 #endif
740           SMESH::Update(myIObject, true);
741         }
742         catch (...) {
743 #ifdef _DEBUG_
744           MESSAGE ( "Exception thrown during mesh visualization" );
745 #endif
746           if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
747             SMESH::OnVisuException();
748           }
749           else {
750             memoryLack = true;
751           }
752         }
753       }
754       LightApp_SelectionMgr *Sel = selectionMgr();
755       if ( Sel )
756       {
757         SALOME_ListIO selected;
758         selected.Append( myIObject );
759         Sel->setSelectedObjects( selected );
760       }
761     }
762   }
763
764   if ( memoryLack )
765     aMemoryReserve.release();
766
767   myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
768
769   // SHOW ERRORS
770   
771   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
772   bool noHypoError = ( aHypErrors.isEmpty() );
773
774   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
775   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
776
777   bool isShowResultDlg = true;
778   switch( aNotifyMode ) {
779   case 0: // show the mesh computation result dialog NEVER
780     isShowResultDlg = false;
781     commit();
782     break;
783   case 1: // show the mesh computation result dialog if there are some errors
784     if ( memoryLack || !noCompError || !noHypoError )
785       isShowResultDlg = true;
786     else
787     {
788       isShowResultDlg = false;
789       commit();
790     }
791     break;
792   default: // show the result dialog after each mesh computation
793     isShowResultDlg = true;
794   }
795
796   // SHOW RESULTS
797   if ( isShowResultDlg )
798     showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
799 }
800
801 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
802                                                 const bool theNoCompError,
803                                                 SMESH::compute_error_array_var& theCompErrors,
804                                                 const bool     theNoHypoError,
805                                                 const QString& theHypErrors )
806 {
807   bool hasShape = myMesh->HasShapeToMesh();
808   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
809   aCompDlg->myMemoryLackGroup->hide();
810
811   if ( theMemoryLack )
812   {
813     aCompDlg->myMemoryLackGroup->show();
814     aCompDlg->myFullInfo->hide();
815     aCompDlg->myBriefInfo->hide();
816     aCompDlg->myHypErrorGroup->hide();
817     aCompDlg->myCompErrorGroup->hide();
818   }
819   else if ( theNoCompError && theNoHypoError )
820   {
821     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
822     aCompDlg->myFullInfo->SetMeshInfo( aRes );
823     aCompDlg->myFullInfo->show();
824     aCompDlg->myBriefInfo->hide();
825     aCompDlg->myHypErrorGroup->hide();
826     aCompDlg->myCompErrorGroup->hide();
827   }
828   else
829   {
830     QTableWidget* tbl = aCompDlg->myTable;
831     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
832     aCompDlg->myFullInfo->SetMeshInfo( aRes );
833     aCompDlg->myBriefInfo->show();
834     aCompDlg->myFullInfo->hide();
835
836     if ( theNoHypoError ) {
837       aCompDlg->myHypErrorGroup->hide();
838     }
839     else {
840       aCompDlg->myHypErrorGroup->show();
841       aCompDlg->myHypErrorLabel->setText( theHypErrors );
842     }
843
844     if ( theNoCompError ) {
845       aCompDlg->myCompErrorGroup->hide();
846     }
847     else {
848       aCompDlg->myCompErrorGroup->show();
849
850       if ( !hasShape ) {
851         aCompDlg->myPublishBtn->hide();
852         aCompDlg->myShowBtn->hide();
853       }
854       else {
855         aCompDlg->myPublishBtn->show();
856         aCompDlg->myShowBtn->show();
857       }
858
859       // fill table of errors
860       tbl->setRowCount( theCompErrors->length() );
861       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
862       else             tbl->showColumn( COL_SHAPE );
863       tbl->setColumnWidth( COL_ERROR, 200 );
864
865       bool hasBadMesh = false;
866       for ( int row = 0; row < theCompErrors->length(); ++row )
867       {
868         SMESH::ComputeError & err = theCompErrors[ row ];
869
870         QString text = err.algoName.in();
871         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
872         else tbl->item( row, COL_ALGO )->setText( text );
873
874         text = SMESH::errorText( err.code, err.comment.in() );
875         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
876         else tbl->item( row, COL_ERROR )->setText( text );
877
878         text = QString("%1").arg( err.subShapeID );
879         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
880         else tbl->item( row, COL_SHAPEID )->setText( text );
881
882         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
883         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
884         else tbl->item( row, COL_SHAPE )->setText( text );
885
886         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
887         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
888         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
889
890         text = err.hasBadMesh ? "hasBadMesh" : "";
891         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
892         else tbl->item( row, COL_BAD_MESH )->setText( text );
893         if ( err.hasBadMesh ) hasBadMesh = true;
894
895         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
896         tbl->resizeRowToContents( row );
897       }
898       tbl->resizeColumnToContents( COL_ALGO );
899       tbl->resizeColumnToContents( COL_SHAPE );
900
901       if ( hasBadMesh )
902         aCompDlg->myBadMeshBtn->show();
903       else
904         aCompDlg->myBadMeshBtn->hide();
905
906       tbl->setCurrentCell(0,0);
907       currentCellChanged(); // to update buttons
908     }
909   }
910   // show dialog and wait, becase Compute can be invoked from Preview operation
911   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
912   aCompDlg->show();
913 }
914
915 //================================================================================
916 /*!
917  * \brief Stops operation
918  */
919 //================================================================================
920
921 void SMESHGUI_BaseComputeOp::stopOperation()
922 {
923   SMESHGUI_Operation::stopOperation();
924   if ( myTShapeDisplayer )
925     myTShapeDisplayer->SetVisibility( false );
926   if ( myBadMeshDisplayer ) {
927     myBadMeshDisplayer->SetVisibility( false );
928     // delete it in order not to have problems at its destruction when the viewer
929     // where it worked is dead due to e.g. study closing
930     delete myBadMeshDisplayer;
931     myBadMeshDisplayer = 0;
932   }
933   myIObject.Nullify();
934 }
935
936 //================================================================================
937 /*!
938  * \brief publish selected subshape
939  */
940 //================================================================================
941
942 void SMESHGUI_BaseComputeOp::onPublishShape()
943 {
944   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
945   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
946
947   QList<int> rows;
948   SMESH::getSelectedRows( table(), rows );
949   int row;
950   foreach ( row, rows )
951   {
952     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
953     GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
954     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
955     {
956       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
957       {
958         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
959         SALOMEDS::SObject_var so =
960           geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
961         // look for myMainShape in the table
962         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
963           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
964             if ( so->_is_nil() ) {
965               table()->item( r, COL_SHAPE )->setText( so->GetName() );
966               table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
967             }
968             break;
969           }
970         }
971         if ( curSub == 1 ) continue;
972       }
973       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
974       SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
975       if ( !so->_is_nil() ) {
976         table()->item( row, COL_SHAPE )->setText( so->GetName() );
977         table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
978       }
979     }
980   }
981   getSMESHGUI()->getApp()->updateObjectBrowser();
982   currentCellChanged(); // to update buttons
983 }
984
985 //================================================================================
986 /*!
987  * \brief show mesh elements preventing computation of a submesh of current row
988  */
989 //================================================================================
990
991 void SMESHGUI_BaseComputeOp::onShowBadMesh()
992 {
993   myTShapeDisplayer->SetVisibility( false );
994   QList<int> rows;
995   if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
996     bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
997     if ( hasBadMesh ) {
998       int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
999       SMESHGUI* gui = getSMESHGUI();
1000       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1001       SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1002       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1003       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1004       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1005       vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1006       vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1007       // delete property !!!!!!!!!!
1008       vtkProperty* prop = vtkProperty::New();
1009       prop->SetLineWidth( aLineWidth * 3 );
1010       prop->SetPointSize( aPointSize * 3 );
1011       prop->SetColor( 250, 0, 250 );
1012       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1013       myBadMeshDisplayer->SetData( aMeshData._retn() );
1014     }
1015   }
1016 }
1017
1018 //================================================================================
1019 /*!
1020  * \brief SLOT called when a selected cell in table() changed
1021  */
1022 //================================================================================
1023
1024 void SMESHGUI_BaseComputeOp::currentCellChanged()
1025 {
1026   myTShapeDisplayer->SetVisibility( false );
1027   if ( myBadMeshDisplayer )
1028     myBadMeshDisplayer->SetVisibility( false );
1029
1030   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1031   QList<int> rows;
1032   int nbSelected = SMESH::getSelectedRows( table(), rows );
1033   int row;
1034   foreach ( row, rows )
1035   {
1036     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1037     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1038     if ( hasData && !isPublished )
1039       publishEnable = true;
1040
1041     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1042     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1043     if ( prsReady ) {
1044       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1045       showOnly = false;
1046     }
1047     else {
1048       showEnable = true;
1049     }
1050
1051     if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1052       hasBadMesh = true;
1053   }
1054   myCompDlg->myPublishBtn->setEnabled( publishEnable );
1055   myCompDlg->myShowBtn   ->setEnabled( showEnable );
1056   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1057 }
1058
1059 //================================================================================
1060 /*!
1061  * \brief update preview
1062  */
1063 //================================================================================
1064
1065 void SMESHGUI_BaseComputeOp::onPreviewShape()
1066 {
1067   if ( myTShapeDisplayer )
1068   {
1069     SUIT_OverrideCursor aWaitCursor;
1070     QList<int> rows;
1071     SMESH::getSelectedRows( table(), rows );
1072
1073     bool showOnly = true;
1074     int row;
1075     foreach ( row, rows )
1076     {
1077       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1078       if ( curSub > 0 ) {
1079         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1080         showOnly = false;
1081       }
1082     }
1083     currentCellChanged(); // to update buttons
1084   }
1085 }
1086
1087 //================================================================================
1088 /*!
1089  * \brief Destructor
1090  */
1091 //================================================================================
1092
1093 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1094 {
1095   delete myCompDlg;
1096   myCompDlg = 0;
1097   delete myTShapeDisplayer;
1098   if ( myBadMeshDisplayer )
1099     delete myBadMeshDisplayer;
1100 }
1101
1102 //================================================================================
1103 /*!
1104  * \brief Gets dialog of compute operation
1105  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1106  */
1107 //================================================================================
1108
1109 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1110 {
1111   if ( !myCompDlg )
1112   {
1113     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1114     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1115     // connect signals and slots
1116     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1117     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1118     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1119
1120     QTableWidget* aTable = me->table();
1121     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1122     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1123   }
1124   return myCompDlg;
1125 }
1126
1127 //================================================================================
1128 /*!
1129  * \brief returns from compute mesh result dialog
1130  */
1131 //================================================================================
1132
1133 bool SMESHGUI_BaseComputeOp::onApply()
1134 {
1135   return true;
1136 }
1137
1138 //================================================================================
1139 /*!
1140  * \brief Return a table
1141  */
1142 //================================================================================
1143
1144 QTableWidget* SMESHGUI_BaseComputeOp::table()
1145 {
1146   return myCompDlg->myTable;
1147 }
1148
1149
1150 //================================================================================
1151 /*!
1152  * \brief Constructor
1153 */
1154 //================================================================================
1155
1156 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1157  : SMESHGUI_BaseComputeOp()
1158 {
1159 }
1160
1161
1162 //================================================================================
1163 /*!
1164  * \brief Desctructor
1165 */
1166 //================================================================================
1167
1168 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1169 {
1170 }
1171
1172 //================================================================================
1173 /*!
1174  * \brief perform it's intention action: compute mesh
1175  */
1176 //================================================================================
1177
1178 void SMESHGUI_ComputeOp::startOperation()
1179 {
1180   SMESHGUI_BaseComputeOp::startOperation();
1181   if (myMesh->_is_nil())
1182     return;
1183   computeMesh();
1184 }
1185
1186 //================================================================================
1187 /*!
1188  * \brief check the same operations on the same mesh
1189  */
1190 //================================================================================
1191
1192 bool SMESHGUI_BaseComputeOp::isValid(  SUIT_Operation* theOp  ) const
1193 {
1194   SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1195   bool ret = true;
1196   if ( !myMesh->_is_nil() && baseOp ) {
1197     SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1198     if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1199   }
1200   return ret;
1201 }
1202
1203 //================================================================================
1204 /*!
1205  * \brief Gets dialog of this operation
1206  * \retval LightApp_Dialog* - pointer to dialog of this operation
1207  */
1208 //================================================================================
1209
1210 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1211 {
1212   return computeDlg();
1213 }
1214
1215 //================================================================================
1216 /*!
1217  * \brief Constructor
1218 */
1219 //================================================================================
1220
1221 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1222  : SMESHGUI_BaseComputeOp(),
1223  myDlg( 0 ),
1224  myOrderMgr( 0 ),
1225  myActiveDlg( 0 ),
1226  myPreviewDisplayer( 0 )
1227 {
1228   myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1229 }
1230
1231 //================================================================================
1232 /*!
1233  * \brief Destructor
1234  */
1235 //================================================================================
1236
1237 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1238 {
1239   delete myDlg;
1240   myDlg = 0;
1241   delete myOrderMgr;
1242   myOrderMgr = 0;
1243   myActiveDlg = 0;
1244   if ( myPreviewDisplayer )
1245     delete myPreviewDisplayer;
1246   myPreviewDisplayer = 0;
1247 }
1248
1249 //================================================================================
1250 /*!
1251  * \brief Gets current dialog of this operation
1252  * \retval LightApp_Dialog* - pointer to dialog of this operation
1253  */
1254 //================================================================================
1255
1256 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1257 {
1258   return myActiveDlg;
1259 }
1260
1261 //================================================================================
1262 /*!
1263  * \brief perform it's intention action: prepare data
1264  */
1265 //================================================================================
1266
1267 void SMESHGUI_PrecomputeOp::startOperation()
1268 {
1269   if ( !myDlg )
1270   {
1271     myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1272     
1273     // connect signals
1274     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1275     connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1276     connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1277   }
1278   myActiveDlg = myDlg;
1279
1280   // connect signal to compute dialog. which will be shown after Compute mesh operation
1281   SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1282   if ( cmpDlg )
1283   {
1284     // disconnect signals
1285     disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1286     disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1287     disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1288     disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1289     disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1290
1291     // connect signals
1292     if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1293       connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1294     if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1295       connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1296     if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1297       connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1298     if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1299       connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1300     if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1301       connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1302   }
1303
1304   SMESHGUI_BaseComputeOp::startOperation();
1305   if (myMesh->_is_nil())
1306     return;
1307
1308   if (myDlg->getPreviewMode() == -1)
1309   {
1310     // nothing to preview
1311     SUIT_MessageBox::warning(desktop(),
1312                              tr("SMESH_WRN_WARNING"),
1313                              tr("SMESH_WRN_NOTHING_PREVIEW"));
1314     onCancel();
1315     return;
1316   }
1317
1318   // disconnect slot from preview dialog to have Apply from results of compute operation only 
1319   disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1320   disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1321
1322   myDlg->show();
1323 }
1324
1325 //================================================================================
1326 /*!
1327  * \brief Stops operation
1328  */
1329 //================================================================================
1330
1331 void SMESHGUI_PrecomputeOp::stopOperation()
1332 {
1333   if ( myPreviewDisplayer )
1334   {
1335     myPreviewDisplayer->SetVisibility( false );
1336     delete myPreviewDisplayer;
1337     myPreviewDisplayer = 0;
1338   }
1339   myMapShapeId.clear();
1340   SMESHGUI_BaseComputeOp::stopOperation();
1341 }
1342
1343 //================================================================================
1344 /*!
1345  * \brief reinitialize dialog after operaiton become active again
1346  */
1347 //================================================================================
1348
1349 void SMESHGUI_PrecomputeOp::resumeOperation()
1350 {
1351   if ( myActiveDlg == myDlg )
1352     initDialog();
1353   SMESHGUI_BaseComputeOp::resumeOperation();
1354 }
1355
1356 //================================================================================
1357 /*!
1358  * \brief perform it's intention action: reinitialise dialog
1359  */
1360 //================================================================================
1361
1362 void SMESHGUI_PrecomputeOp::initDialog()
1363 {
1364   QList<int> modes;
1365
1366   QMap<int, int> modeMap;
1367   _PTR(SObject)  pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1368   getAssignedAlgos( pMesh, modeMap );
1369   if ( modeMap.contains( SMESH::DIM_3D ) )
1370   {
1371     if ( modeMap.contains( SMESH::DIM_2D ) )
1372       modes.append( SMESH::DIM_2D );
1373     if ( modeMap.contains( SMESH::DIM_1D ) )
1374       modes.append( SMESH::DIM_1D );
1375   }
1376   else if ( modeMap.contains( SMESH::DIM_2D ) )
1377   {
1378     if ( modeMap.contains( SMESH::DIM_1D ) )
1379       modes.append( SMESH::DIM_1D );
1380   }
1381
1382   myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1383   myOrderMgr->SetMesh( myMesh );
1384   bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1385   myDlg->getMeshOrderBox()->setShown(isOrder);
1386   if ( !isOrder ) {
1387     delete myOrderMgr;
1388     myOrderMgr = 0;
1389   }
1390
1391   myDlg->setPreviewModes( modes );
1392 }
1393
1394 //================================================================================
1395 /*!
1396  * \brief detect asigned mesh algorithms
1397  */
1398 //================================================================================
1399
1400 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1401                                              QMap<int,int>& theModeMap)
1402 {
1403   _PTR(SObject)          aHypRoot;
1404   _PTR(GenericAttribute) anAttr;
1405   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1406   if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1407   {
1408     _PTR(ChildIterator) anIter =
1409       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1410     for ( ; anIter->More(); anIter->Next() )
1411     {
1412       _PTR(SObject) anObj = anIter->Value();
1413       _PTR(SObject) aRefObj;
1414       if ( anObj->ReferencedObject( aRefObj ) )
1415         anObj = aRefObj;
1416       else
1417         continue;
1418       
1419       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1420       {
1421         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1422         if ( CORBA::is_nil( aVar ) )
1423           continue;
1424         
1425         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1426         {
1427           SMESH::SMESH_Algo_var algo;
1428           switch(dim) {
1429           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1430           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1431           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1432           default: break;
1433           }
1434           if ( !algo->_is_nil() )
1435             theModeMap[ dim ] = 0;
1436         }
1437       }
1438     }
1439   }
1440 }
1441
1442 //================================================================================
1443 /*!
1444  * \brief perform it's intention action: compute mesh
1445  */
1446 //================================================================================
1447
1448 void SMESHGUI_PrecomputeOp::onCompute()
1449 {
1450   myDlg->hide();
1451   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1452     myOrderMgr->SetMeshOrder();
1453   myMapShapeId.clear();
1454   myActiveDlg = computeDlg();
1455   computeMesh();
1456 }
1457
1458 //================================================================================
1459 /*!
1460  * \brief perform it's intention action: compute mesh
1461  */
1462 //================================================================================
1463
1464 void SMESHGUI_PrecomputeOp::onCancel()
1465 {
1466   QObject* curDlg = sender();
1467   if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1468   {
1469     // return from error messages
1470     myDlg->show();
1471     return;
1472   }
1473
1474   bool isRestoreOrder = false;
1475   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
1476   {
1477     // ask to remove already computed mesh elements
1478     if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1479                                     tr( "CLEAR_SUBMESH_QUESTION" ),
1480                                     tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1481     {
1482       // remove all submeshes for collected shapes
1483       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1484       for ( ; it != myMapShapeId.constEnd(); ++it )
1485         myMesh->ClearSubMesh( *it );
1486       isRestoreOrder = true;
1487     }
1488   }
1489
1490   // return previous mesh order
1491   if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1492     if (!isRestoreOrder)
1493       isRestoreOrder = 
1494         (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1495                                     tr( "SMESH_REJECT_MESH_ORDER" ),
1496                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1497     if (isRestoreOrder)
1498       myOrderMgr->SetMeshOrder(myPrevOrder);
1499   }
1500
1501   delete myOrderMgr;
1502   myOrderMgr = 0;
1503
1504   myMapShapeId.clear();
1505   SMESHGUI_BaseComputeOp::onCancel();
1506 }
1507
1508 //================================================================================
1509 /*!
1510  * \brief perform it's intention action: preview mesh
1511  */
1512 //================================================================================
1513
1514 void SMESHGUI_PrecomputeOp::onPreview()
1515 {
1516   if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1517     return;
1518
1519   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1520   if ( !aMeshSObj )
1521     return;
1522
1523   // set modified submesh priority if any
1524   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1525     myOrderMgr->SetMeshOrder();
1526
1527   // Compute preview of mesh, 
1528   // i.e. compute mesh till indicated dimension
1529   int dim = myDlg->getPreviewMode();
1530   
1531   SMESH::MemoryReserve aMemoryReserve;
1532   
1533   SMESH::compute_error_array_var aCompErrors;
1534   QString                        aHypErrors;
1535
1536   bool computeFailed = true, memoryLack = false;
1537
1538   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1539     aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1540
1541   SMESHGUI* gui = getSMESHGUI();
1542   SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1543   SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1544   if ( errors->length() > 0 ) {
1545     aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1546   }
1547
1548   SUIT_OverrideCursor aWaitCursor;
1549
1550   SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1551   if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1552   myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1553   
1554   SMESH::long_array_var aShapesId = new SMESH::long_array();
1555   try {
1556 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1557     OCC_CATCH_SIGNALS;
1558 #endif
1559       
1560     SMESH::MeshPreviewStruct_var previewData =
1561       gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1562     SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1563     if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1564     {
1565       computeFailed = false;
1566       myPreviewDisplayer->SetData( previewRes );
1567       // append shape indeces with computed mesh entities
1568       for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1569         myMapShapeId[ aShapesId[ i ] ] = 0;
1570     }
1571     else
1572       myPreviewDisplayer->SetVisibility(false);
1573   }
1574   catch(const SALOME::SALOME_Exception & S_ex){
1575     memoryLack = true;
1576     myPreviewDisplayer->SetVisibility(false);
1577   }
1578
1579   try {
1580 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1581     OCC_CATCH_SIGNALS;
1582 #endif
1583     aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1584     // check if there are memory problems
1585     for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1586       memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1587   }
1588   catch(const SALOME::SALOME_Exception & S_ex){
1589     memoryLack = true;
1590   }
1591
1592   if ( memoryLack )
1593     aMemoryReserve.release();
1594
1595   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1596   bool noHypoError = ( aHypErrors.isEmpty() );
1597
1598   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1599   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1600
1601   bool isShowError = true;
1602   switch( aNotifyMode ) {
1603   case 0: // show the mesh computation result dialog NEVER
1604     isShowError = false;
1605     break;
1606   case 1: // show the mesh computation result dialog if there are some errors
1607   default: // show the result dialog after each mesh computation
1608     if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1609       isShowError = false;
1610     break;
1611   }
1612
1613   aWaitCursor.suspend();
1614   // SHOW ERRORS
1615   if ( isShowError )
1616   {
1617     myDlg->hide();
1618     aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1619     showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1620   }
1621 }
1622
1623
1624 //================================================================================
1625 /*!
1626  * \brief Constructor
1627 */
1628 //================================================================================
1629
1630 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1631  : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1632    myOrderBox(0)
1633 {
1634   setWindowTitle( tr( "CAPTION" ) );
1635
1636   setButtonText( OK, tr( "COMPUTE" ) );
1637   QFrame* main = mainFrame();
1638
1639   QVBoxLayout* layout = new QVBoxLayout( main );
1640
1641   myOrderBox = new SMESHGUI_MeshOrderBox( main );
1642   layout->addWidget(myOrderBox);
1643
1644   QFrame* frame = new QFrame( main );
1645   layout->setMargin(0); layout->setSpacing(0);
1646   layout->addWidget( frame );
1647
1648   QHBoxLayout* frameLay = new QHBoxLayout( frame );
1649   frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1650   
1651   myPreviewMode = new QtxComboBox( frame );
1652   frameLay->addWidget( myPreviewMode );
1653
1654   myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1655   frameLay->addWidget( myPreviewBtn );
1656
1657   connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1658 }
1659
1660 //================================================================================
1661 /*!
1662  * \brief Destructor
1663 */
1664 //================================================================================
1665
1666 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1667 {
1668 }
1669
1670 //================================================================================
1671 /*!
1672  * \brief Sets available preview modes
1673 */
1674 //================================================================================
1675
1676 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1677 {
1678   myPreviewMode->clear();
1679   QList<int>::const_iterator it = theModes.constBegin();
1680   for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1681   {
1682     QString mode = QString( "PREVIEW_%1" ).arg( *it );
1683     myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1684     myPreviewMode->setId( i, *it );
1685   }
1686   myPreviewBtn->setEnabled( !theModes.isEmpty() );
1687 }
1688
1689 //================================================================================
1690 /*!
1691  * \brief Returns current preview mesh mode
1692 */
1693 //================================================================================
1694
1695 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1696 {
1697   return myPreviewMode->currentId();
1698 }
1699
1700 //================================================================================
1701 /*!
1702  * \brief Returns current preview mesh mode
1703 */
1704 //================================================================================
1705
1706 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1707 {
1708   return myOrderBox;
1709 }
1710
1711
1712 //================================================================================
1713 /*!
1714  * \brief Constructor
1715 */
1716 //================================================================================
1717
1718 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1719  : SMESHGUI_BaseComputeOp()
1720 {
1721 }
1722
1723
1724 //================================================================================
1725 /*!
1726  * \brief Desctructor
1727 */
1728 //================================================================================
1729
1730 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1731 {
1732 }
1733
1734 //================================================================================
1735 /*!
1736  * \brief perform it's intention action: compute mesh
1737  */
1738 //================================================================================
1739
1740 void SMESHGUI_EvaluateOp::startOperation()
1741 {
1742   SMESHGUI_BaseComputeOp::evaluateDlg();
1743   SMESHGUI_BaseComputeOp::startOperation();
1744   if (myMesh->_is_nil())
1745     return;
1746   evaluateMesh();
1747 }
1748
1749 //================================================================================
1750 /*!
1751  * \brief Gets dialog of this operation
1752  * \retval LightApp_Dialog* - pointer to dialog of this operation
1753  */
1754 //================================================================================
1755
1756 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1757 {
1758   return evaluateDlg();
1759 }
1760
1761 //================================================================================
1762 /*!
1763  * \brief evaluateMesh()
1764 */
1765 //================================================================================
1766
1767 void SMESHGUI_BaseComputeOp::evaluateMesh()
1768 {
1769   // EVALUATE MESH
1770
1771   SMESH::MemoryReserve aMemoryReserve;
1772
1773   SMESH::compute_error_array_var aCompErrors;
1774   QString                        aHypErrors;
1775
1776   bool evaluateFailed = true, memoryLack = false;
1777   SMESH::long_array_var aRes;
1778
1779   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1780   if ( !aMeshSObj ) //  IPAL21340
1781     return;
1782
1783   bool hasShape = myMesh->HasShapeToMesh();
1784   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1785   if ( shapeOK )
1786   {
1787     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1788     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1789     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1790     if ( errors->length() > 0 ) {
1791       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1792     }
1793     SUIT_OverrideCursor aWaitCursor;
1794     try {
1795 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1796       OCC_CATCH_SIGNALS;
1797 #endif
1798       aRes = gen->Evaluate(myMesh, myMainShape);
1799     }
1800     catch(const SALOME::SALOME_Exception & S_ex){
1801       memoryLack = true;
1802     }
1803
1804     try {
1805 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1806       OCC_CATCH_SIGNALS;
1807 #endif
1808       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1809     }
1810     catch(const SALOME::SALOME_Exception & S_ex){
1811       memoryLack = true;
1812     }
1813   }
1814
1815   if ( memoryLack )
1816     aMemoryReserve.release();
1817
1818   evaluateFailed =  ( aCompErrors->length() > 0 );
1819   myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1820
1821   // SHOW ERRORS
1822   
1823   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1824   bool noHypoError = ( aHypErrors.isEmpty() );
1825
1826   //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1827   //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1828
1829   bool isShowResultDlg = true;
1830   //if( noHypoError )
1831   //switch( aNotifyMode ) {
1832   //case 0: // show the mesh computation result dialog NEVER
1833   //isShowResultDlg = false;
1834   //commit();
1835   //break;
1836   //case 1: // show the mesh computation result dialog if there are some errors
1837   //if ( memoryLack || !noHypoError )
1838   //  isShowResultDlg = true;
1839   //else
1840   //{
1841   //  isShowResultDlg = false;
1842   //  commit();
1843   //}
1844   //break;
1845   //default: // show the result dialog after each mesh computation
1846   //isShowResultDlg = true;
1847   //}
1848
1849   // SHOW RESULTS
1850   if ( isShowResultDlg )
1851     showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1852                         noHypoError, aHypErrors);
1853 }
1854
1855
1856 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1857                                                 const bool theMemoryLack,
1858                                                 const bool theNoCompError,
1859                                                 SMESH::compute_error_array_var& theCompErrors,
1860                                                 const bool theNoHypoError,
1861                                                 const QString& theHypErrors)
1862 {
1863   bool hasShape = myMesh->HasShapeToMesh();
1864   SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1865   aCompDlg->myMemoryLackGroup->hide();
1866
1867   if ( theMemoryLack )
1868   {
1869     aCompDlg->myMemoryLackGroup->show();
1870     aCompDlg->myFullInfo->hide();
1871     aCompDlg->myBriefInfo->hide();
1872     aCompDlg->myHypErrorGroup->hide();
1873     aCompDlg->myCompErrorGroup->hide();
1874   }
1875   else if ( theNoCompError && theNoHypoError )
1876   {
1877     aCompDlg->myFullInfo->SetMeshInfo( theRes );
1878     aCompDlg->myFullInfo->show();
1879     aCompDlg->myBriefInfo->hide();
1880     aCompDlg->myHypErrorGroup->hide();
1881     aCompDlg->myCompErrorGroup->hide();
1882   }
1883   else
1884   {
1885     QTableWidget* tbl = aCompDlg->myTable;
1886     aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1887     aCompDlg->myBriefInfo->show();
1888     aCompDlg->myFullInfo->hide();
1889
1890     if ( theNoHypoError ) {
1891       aCompDlg->myHypErrorGroup->hide();
1892     }
1893     else {
1894       aCompDlg->myHypErrorGroup->show();
1895       aCompDlg->myHypErrorLabel->setText( theHypErrors );
1896     }
1897
1898     if ( theNoCompError ) {
1899       aCompDlg->myCompErrorGroup->hide();
1900     }
1901     else {
1902       aCompDlg->myCompErrorGroup->show();
1903
1904       aCompDlg->myPublishBtn->hide();
1905       aCompDlg->myShowBtn->hide();
1906
1907       // fill table of errors
1908       tbl->setRowCount( theCompErrors->length() );
1909       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1910       else             tbl->showColumn( COL_SHAPE );
1911       tbl->setColumnWidth( COL_ERROR, 200 );
1912
1913       bool hasBadMesh = false;
1914       for ( int row = 0; row < theCompErrors->length(); ++row )
1915       {
1916         SMESH::ComputeError & err = theCompErrors[ row ];
1917
1918         QString text = err.algoName.in();
1919         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1920         else tbl->item( row, COL_ALGO )->setText( text );
1921
1922         text = SMESH::errorText( err.code, err.comment.in() );
1923         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1924         else tbl->item( row, COL_ERROR )->setText( text );
1925
1926         text = QString("%1").arg( err.subShapeID );
1927         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1928         else tbl->item( row, COL_SHAPEID )->setText( text );
1929
1930         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1931         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1932         else tbl->item( row, COL_SHAPE )->setText( text );
1933
1934         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1935         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1936         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1937
1938         text = err.hasBadMesh ? "hasBadMesh" : "";
1939         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1940         else tbl->item( row, COL_BAD_MESH )->setText( text );
1941         if ( err.hasBadMesh ) hasBadMesh = true;
1942
1943         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1944         tbl->resizeRowToContents( row );
1945       }
1946       tbl->resizeColumnToContents( COL_ALGO );
1947       tbl->resizeColumnToContents( COL_SHAPE );
1948
1949       if ( hasBadMesh )
1950         aCompDlg->myBadMeshBtn->show();
1951       else
1952         aCompDlg->myBadMeshBtn->hide();
1953
1954       tbl->setCurrentCell(0,0);
1955       currentCellChanged(); // to update buttons
1956     }
1957   }
1958   // show dialog and wait, becase Compute can be invoked from Preview operation
1959   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1960   aCompDlg->show();
1961 }
1962
1963
1964 //================================================================================
1965 /*!
1966  * \brief Gets dialog of evaluate operation
1967  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1968  */
1969 //================================================================================
1970
1971 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1972 {
1973   if ( !myCompDlg )
1974   {
1975     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1976     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1977     // connect signals and slots
1978     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1979     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1980     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1981     QTableWidget* aTable = me->table();
1982     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1983     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1984   }
1985   return myCompDlg;
1986 }
1987