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