Salome HOME
Merge from V5_1_4_BR 07/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     SUIT_OverrideCursor aWaitCursor;
702     try {
703 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
704       OCC_CATCH_SIGNALS;
705 #endif
706       if (gen->Compute(myMesh, myMainShape))
707         computeFailed = false;
708     }
709     catch(const SALOME::SALOME_Exception & S_ex){
710       memoryLack = true;
711     }
712     try {
713 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
714       OCC_CATCH_SIGNALS;
715 #endif
716       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
717       // check if there are memory problems
718       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
719         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
720     }
721     catch(const SALOME::SALOME_Exception & S_ex){
722       memoryLack = true;
723     }
724
725     // NPAL16631: if ( !memoryLack )
726     {
727       SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
728       update( UF_ObjBrowser | UF_Model );
729
730       // SHOW MESH
731       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
732       if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
733       {
734         try {
735 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
736           OCC_CATCH_SIGNALS;
737 #endif
738           SMESH::Update(myIObject, true);
739         }
740         catch (...) {
741 #ifdef _DEBUG_
742           MESSAGE ( "Exception thrown during mesh visualization" );
743 #endif
744           if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
745             SMESH::OnVisuException();
746           }
747           else {
748             memoryLack = true;
749           }
750         }
751       }
752       LightApp_SelectionMgr *Sel = selectionMgr();
753       if ( Sel )
754       {
755         SALOME_ListIO selected;
756         selected.Append( myIObject );
757         Sel->setSelectedObjects( selected );
758       }
759     }
760   }
761
762   if ( memoryLack )
763     aMemoryReserve.release();
764
765   myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
766
767   // SHOW ERRORS
768   
769   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
770   bool noHypoError = ( aHypErrors.isEmpty() );
771
772   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
773   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
774
775   bool isShowResultDlg = true;
776   switch( aNotifyMode ) {
777   case 0: // show the mesh computation result dialog NEVER
778     isShowResultDlg = false;
779     commit();
780     break;
781   case 1: // show the mesh computation result dialog if there are some errors
782     if ( memoryLack || !noCompError || !noHypoError )
783       isShowResultDlg = true;
784     else
785     {
786       isShowResultDlg = false;
787       commit();
788     }
789     break;
790   default: // show the result dialog after each mesh computation
791     isShowResultDlg = true;
792   }
793
794   // SHOW RESULTS
795   if ( isShowResultDlg )
796     showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
797 }
798
799 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
800                                                 const bool theNoCompError,
801                                                 SMESH::compute_error_array_var& theCompErrors,
802                                                 const bool     theNoHypoError,
803                                                 const QString& theHypErrors )
804 {
805   bool hasShape = myMesh->HasShapeToMesh();
806   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
807   aCompDlg->myMemoryLackGroup->hide();
808
809   if ( theMemoryLack )
810   {
811     aCompDlg->myMemoryLackGroup->show();
812     aCompDlg->myFullInfo->hide();
813     aCompDlg->myBriefInfo->hide();
814     aCompDlg->myHypErrorGroup->hide();
815     aCompDlg->myCompErrorGroup->hide();
816   }
817   else if ( theNoCompError && theNoHypoError )
818   {
819     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
820     aCompDlg->myFullInfo->SetMeshInfo( aRes );
821     aCompDlg->myFullInfo->show();
822     aCompDlg->myBriefInfo->hide();
823     aCompDlg->myHypErrorGroup->hide();
824     aCompDlg->myCompErrorGroup->hide();
825   }
826   else
827   {
828     QTableWidget* tbl = aCompDlg->myTable;
829     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
830     aCompDlg->myBriefInfo->SetMeshInfo( aRes );
831     aCompDlg->myBriefInfo->show();
832     aCompDlg->myFullInfo->hide();
833
834     if ( theNoHypoError ) {
835       aCompDlg->myHypErrorGroup->hide();
836     }
837     else {
838       aCompDlg->myHypErrorGroup->show();
839       aCompDlg->myHypErrorLabel->setText( theHypErrors );
840     }
841
842     if ( theNoCompError ) {
843       aCompDlg->myCompErrorGroup->hide();
844     }
845     else {
846       aCompDlg->myCompErrorGroup->show();
847
848       if ( !hasShape ) {
849         aCompDlg->myPublishBtn->hide();
850         aCompDlg->myShowBtn->hide();
851       }
852       else {
853         aCompDlg->myPublishBtn->show();
854         aCompDlg->myShowBtn->show();
855       }
856
857       // fill table of errors
858       tbl->setRowCount( theCompErrors->length() );
859       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
860       else             tbl->showColumn( COL_SHAPE );
861       tbl->setColumnWidth( COL_ERROR, 200 );
862
863       bool hasBadMesh = false;
864       for ( int row = 0; row < theCompErrors->length(); ++row )
865       {
866         SMESH::ComputeError & err = theCompErrors[ row ];
867
868         QString text = err.algoName.in();
869         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
870         else tbl->item( row, COL_ALGO )->setText( text );
871
872         text = SMESH::errorText( err.code, err.comment.in() );
873         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
874         else tbl->item( row, COL_ERROR )->setText( text );
875
876         text = QString("%1").arg( err.subShapeID );
877         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
878         else tbl->item( row, COL_SHAPEID )->setText( text );
879
880         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
881         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
882         else tbl->item( row, COL_SHAPE )->setText( text );
883
884         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
885         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
886         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
887
888         text = err.hasBadMesh ? "hasBadMesh" : "";
889         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
890         else tbl->item( row, COL_BAD_MESH )->setText( text );
891         if ( err.hasBadMesh ) hasBadMesh = true;
892
893         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
894         tbl->resizeRowToContents( row );
895       }
896       tbl->resizeColumnToContents( COL_ALGO );
897       tbl->resizeColumnToContents( COL_SHAPE );
898
899       if ( hasBadMesh )
900         aCompDlg->myBadMeshBtn->show();
901       else
902         aCompDlg->myBadMeshBtn->hide();
903
904       tbl->setCurrentCell(0,0);
905       currentCellChanged(); // to update buttons
906     }
907   }
908   // show dialog and wait, becase Compute can be invoked from Preview operation
909   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
910   aCompDlg->show();
911 }
912
913 //================================================================================
914 /*!
915  * \brief Stops operation
916  */
917 //================================================================================
918
919 void SMESHGUI_BaseComputeOp::stopOperation()
920 {
921   SMESHGUI_Operation::stopOperation();
922   if ( myTShapeDisplayer )
923     myTShapeDisplayer->SetVisibility( false );
924   if ( myBadMeshDisplayer ) {
925     myBadMeshDisplayer->SetVisibility( false );
926     // delete it in order not to have problems at its destruction when the viewer
927     // where it worked is dead due to e.g. study closing
928     delete myBadMeshDisplayer;
929     myBadMeshDisplayer = 0;
930   }
931   myIObject.Nullify();
932 }
933
934 //================================================================================
935 /*!
936  * \brief publish selected subshape
937  */
938 //================================================================================
939
940 void SMESHGUI_BaseComputeOp::onPublishShape()
941 {
942   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
943   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
944
945   QList<int> rows;
946   SMESH::getSelectedRows( table(), rows );
947   int row;
948   foreach ( row, rows )
949   {
950     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
951     GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
952     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
953     {
954       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
955       {
956         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
957         SALOMEDS::SObject_var so =
958           geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
959         // look for myMainShape in the table
960         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
961           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
962             if ( so->_is_nil() ) {
963               table()->item( r, COL_SHAPE )->setText( so->GetName() );
964               table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
965             }
966             break;
967           }
968         }
969         if ( curSub == 1 ) continue;
970       }
971       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
972       SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
973       if ( !so->_is_nil() ) {
974         table()->item( row, COL_SHAPE )->setText( so->GetName() );
975         table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
976       }
977     }
978   }
979   getSMESHGUI()->getApp()->updateObjectBrowser();
980   currentCellChanged(); // to update buttons
981 }
982
983 //================================================================================
984 /*!
985  * \brief show mesh elements preventing computation of a submesh of current row
986  */
987 //================================================================================
988
989 void SMESHGUI_BaseComputeOp::onShowBadMesh()
990 {
991   myTShapeDisplayer->SetVisibility( false );
992   QList<int> rows;
993   if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
994     bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
995     if ( hasBadMesh ) {
996       int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
997       SMESHGUI* gui = getSMESHGUI();
998       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
999       SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1000       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1001       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1002       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1003       vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1004       vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1005       // delete property !!!!!!!!!!
1006       vtkProperty* prop = vtkProperty::New();
1007       prop->SetLineWidth( aLineWidth * 3 );
1008       prop->SetPointSize( aPointSize * 3 );
1009       prop->SetColor( 250, 0, 250 );
1010       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1011       myBadMeshDisplayer->SetData( aMeshData._retn() );
1012     }
1013   }
1014 }
1015
1016 //================================================================================
1017 /*!
1018  * \brief SLOT called when a selected cell in table() changed
1019  */
1020 //================================================================================
1021
1022 void SMESHGUI_BaseComputeOp::currentCellChanged()
1023 {
1024   myTShapeDisplayer->SetVisibility( false );
1025   if ( myBadMeshDisplayer )
1026     myBadMeshDisplayer->SetVisibility( false );
1027
1028   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1029   QList<int> rows;
1030   int nbSelected = SMESH::getSelectedRows( table(), rows );
1031   int row;
1032   foreach ( row, rows )
1033   {
1034     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1035     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1036     if ( hasData && !isPublished )
1037       publishEnable = true;
1038
1039     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1040     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1041     if ( prsReady ) {
1042       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1043       showOnly = false;
1044     }
1045     else {
1046       showEnable = true;
1047     }
1048
1049     if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1050       hasBadMesh = true;
1051   }
1052   myCompDlg->myPublishBtn->setEnabled( publishEnable );
1053   myCompDlg->myShowBtn   ->setEnabled( showEnable );
1054   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1055 }
1056
1057 //================================================================================
1058 /*!
1059  * \brief update preview
1060  */
1061 //================================================================================
1062
1063 void SMESHGUI_BaseComputeOp::onPreviewShape()
1064 {
1065   if ( myTShapeDisplayer )
1066   {
1067     SUIT_OverrideCursor aWaitCursor;
1068     QList<int> rows;
1069     SMESH::getSelectedRows( table(), rows );
1070
1071     bool showOnly = true;
1072     int row;
1073     foreach ( row, rows )
1074     {
1075       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1076       if ( curSub > 0 ) {
1077         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1078         showOnly = false;
1079       }
1080     }
1081     currentCellChanged(); // to update buttons
1082   }
1083 }
1084
1085 //================================================================================
1086 /*!
1087  * \brief Destructor
1088  */
1089 //================================================================================
1090
1091 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1092 {
1093   delete myCompDlg;
1094   myCompDlg = 0;
1095   delete myTShapeDisplayer;
1096   if ( myBadMeshDisplayer )
1097     delete myBadMeshDisplayer;
1098 }
1099
1100 //================================================================================
1101 /*!
1102  * \brief Gets dialog of compute operation
1103  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1104  */
1105 //================================================================================
1106
1107 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1108 {
1109   if ( !myCompDlg )
1110   {
1111     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1112     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1113     // connect signals and slots
1114     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1115     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1116     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1117
1118     QTableWidget* aTable = me->table();
1119     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1120     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1121   }
1122   return myCompDlg;
1123 }
1124
1125 //================================================================================
1126 /*!
1127  * \brief returns from compute mesh result dialog
1128  */
1129 //================================================================================
1130
1131 bool SMESHGUI_BaseComputeOp::onApply()
1132 {
1133   return true;
1134 }
1135
1136 //================================================================================
1137 /*!
1138  * \brief Return a table
1139  */
1140 //================================================================================
1141
1142 QTableWidget* SMESHGUI_BaseComputeOp::table()
1143 {
1144   return myCompDlg->myTable;
1145 }
1146
1147
1148 //================================================================================
1149 /*!
1150  * \brief Constructor
1151 */
1152 //================================================================================
1153
1154 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1155  : SMESHGUI_BaseComputeOp()
1156 {
1157 }
1158
1159
1160 //================================================================================
1161 /*!
1162  * \brief Desctructor
1163 */
1164 //================================================================================
1165
1166 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1167 {
1168 }
1169
1170 //================================================================================
1171 /*!
1172  * \brief perform it's intention action: compute mesh
1173  */
1174 //================================================================================
1175
1176 void SMESHGUI_ComputeOp::startOperation()
1177 {
1178   SMESHGUI_BaseComputeOp::startOperation();
1179   if (myMesh->_is_nil())
1180     return;
1181   computeMesh();
1182 }
1183
1184 //================================================================================
1185 /*!
1186  * \brief check the same operations on the same mesh
1187  */
1188 //================================================================================
1189
1190 bool SMESHGUI_BaseComputeOp::isValid(  SUIT_Operation* theOp  ) const
1191 {
1192   SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1193   bool ret = true;
1194   if ( !myMesh->_is_nil() && baseOp ) {
1195     SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1196     if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1197   }
1198   return ret;
1199 }
1200
1201 //================================================================================
1202 /*!
1203  * \brief Gets dialog of this operation
1204  * \retval LightApp_Dialog* - pointer to dialog of this operation
1205  */
1206 //================================================================================
1207
1208 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1209 {
1210   return computeDlg();
1211 }
1212
1213 //================================================================================
1214 /*!
1215  * \brief Constructor
1216 */
1217 //================================================================================
1218
1219 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1220  : SMESHGUI_BaseComputeOp(),
1221  myDlg( 0 ),
1222  myOrderMgr( 0 ),
1223  myActiveDlg( 0 ),
1224  myPreviewDisplayer( 0 )
1225 {
1226   myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1227 }
1228
1229 //================================================================================
1230 /*!
1231  * \brief Destructor
1232  */
1233 //================================================================================
1234
1235 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1236 {
1237   delete myDlg;
1238   myDlg = 0;
1239   delete myOrderMgr;
1240   myOrderMgr = 0;
1241   myActiveDlg = 0;
1242   if ( myPreviewDisplayer )
1243     delete myPreviewDisplayer;
1244   myPreviewDisplayer = 0;
1245 }
1246
1247 //================================================================================
1248 /*!
1249  * \brief Gets current dialog of this operation
1250  * \retval LightApp_Dialog* - pointer to dialog of this operation
1251  */
1252 //================================================================================
1253
1254 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1255 {
1256   return myActiveDlg;
1257 }
1258
1259 //================================================================================
1260 /*!
1261  * \brief perform it's intention action: prepare data
1262  */
1263 //================================================================================
1264
1265 void SMESHGUI_PrecomputeOp::startOperation()
1266 {
1267   if ( !myDlg )
1268   {
1269     myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1270     
1271     // connect signals
1272     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1273     connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1274     connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1275   }
1276   myActiveDlg = myDlg;
1277
1278   // connect signal to compute dialog. which will be shown after Compute mesh operation
1279   SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1280   if ( cmpDlg )
1281   {
1282     // disconnect signals
1283     disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1284     disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1285     disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1286     disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1287     disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1288
1289     // connect signals
1290     if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1291       connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1292     if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1293       connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1294     if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1295       connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1296     if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1297       connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1298     if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1299       connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1300   }
1301
1302   SMESHGUI_BaseComputeOp::startOperation();
1303   if (myMesh->_is_nil())
1304     return;
1305
1306   if (myDlg->getPreviewMode() == -1)
1307   {
1308     // nothing to preview
1309     SUIT_MessageBox::warning(desktop(),
1310                              tr("SMESH_WRN_WARNING"),
1311                              tr("SMESH_WRN_NOTHING_PREVIEW"));
1312     onCancel();
1313     return;
1314   }
1315
1316   // disconnect slot from preview dialog to have Apply from results of compute operation only 
1317   disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1318   disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1319
1320   myDlg->show();
1321 }
1322
1323 //================================================================================
1324 /*!
1325  * \brief Stops operation
1326  */
1327 //================================================================================
1328
1329 void SMESHGUI_PrecomputeOp::stopOperation()
1330 {
1331   if ( myPreviewDisplayer )
1332   {
1333     myPreviewDisplayer->SetVisibility( false );
1334     delete myPreviewDisplayer;
1335     myPreviewDisplayer = 0;
1336   }
1337   myMapShapeId.clear();
1338   SMESHGUI_BaseComputeOp::stopOperation();
1339 }
1340
1341 //================================================================================
1342 /*!
1343  * \brief reinitialize dialog after operaiton become active again
1344  */
1345 //================================================================================
1346
1347 void SMESHGUI_PrecomputeOp::resumeOperation()
1348 {
1349   if ( myActiveDlg == myDlg )
1350     initDialog();
1351   SMESHGUI_BaseComputeOp::resumeOperation();
1352 }
1353
1354 //================================================================================
1355 /*!
1356  * \brief perform it's intention action: reinitialise dialog
1357  */
1358 //================================================================================
1359
1360 void SMESHGUI_PrecomputeOp::initDialog()
1361 {
1362   QList<int> modes;
1363
1364   QMap<int, int> modeMap;
1365   _PTR(SObject)  pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1366   getAssignedAlgos( pMesh, modeMap );
1367   if ( modeMap.contains( SMESH::DIM_3D ) )
1368   {
1369     if ( modeMap.contains( SMESH::DIM_2D ) )
1370       modes.append( SMESH::DIM_2D );
1371     if ( modeMap.contains( SMESH::DIM_1D ) )
1372       modes.append( SMESH::DIM_1D );
1373   }
1374   else if ( modeMap.contains( SMESH::DIM_2D ) )
1375   {
1376     if ( modeMap.contains( SMESH::DIM_1D ) )
1377       modes.append( SMESH::DIM_1D );
1378   }
1379
1380   myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1381   myOrderMgr->SetMesh( myMesh );
1382   bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1383   myDlg->getMeshOrderBox()->setShown(isOrder);
1384   if ( !isOrder ) {
1385     delete myOrderMgr;
1386     myOrderMgr = 0;
1387   }
1388
1389   myDlg->setPreviewModes( modes );
1390 }
1391
1392 //================================================================================
1393 /*!
1394  * \brief detect asigned mesh algorithms
1395  */
1396 //================================================================================
1397
1398 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1399                                              QMap<int,int>& theModeMap)
1400 {
1401   _PTR(SObject)          aHypRoot;
1402   _PTR(GenericAttribute) anAttr;
1403   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1404   if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1405   {
1406     _PTR(ChildIterator) anIter =
1407       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1408     for ( ; anIter->More(); anIter->Next() )
1409     {
1410       _PTR(SObject) anObj = anIter->Value();
1411       _PTR(SObject) aRefObj;
1412       if ( anObj->ReferencedObject( aRefObj ) )
1413         anObj = aRefObj;
1414       else
1415         continue;
1416       
1417       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1418       {
1419         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1420         if ( CORBA::is_nil( aVar ) )
1421           continue;
1422         
1423         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1424         {
1425           SMESH::SMESH_Algo_var algo;
1426           switch(dim) {
1427           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1428           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1429           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1430           default: break;
1431           }
1432           if ( !algo->_is_nil() )
1433             theModeMap[ dim ] = 0;
1434         }
1435       }
1436     }
1437   }
1438 }
1439
1440 //================================================================================
1441 /*!
1442  * \brief perform it's intention action: compute mesh
1443  */
1444 //================================================================================
1445
1446 void SMESHGUI_PrecomputeOp::onCompute()
1447 {
1448   myDlg->hide();
1449   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1450     myOrderMgr->SetMeshOrder();
1451   myMapShapeId.clear();
1452   myActiveDlg = computeDlg();
1453   computeMesh();
1454 }
1455
1456 //================================================================================
1457 /*!
1458  * \brief perform it's intention action: compute mesh
1459  */
1460 //================================================================================
1461
1462 void SMESHGUI_PrecomputeOp::onCancel()
1463 {
1464   QObject* curDlg = sender();
1465   if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1466   {
1467     // return from error messages
1468     myDlg->show();
1469     return;
1470   }
1471
1472   bool isRestoreOrder = false;
1473   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
1474   {
1475     // ask to remove already computed mesh elements
1476     if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1477                                     tr( "CLEAR_SUBMESH_QUESTION" ),
1478                                     tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1479     {
1480       // remove all submeshes for collected shapes
1481       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1482       for ( ; it != myMapShapeId.constEnd(); ++it )
1483         myMesh->ClearSubMesh( *it );
1484       isRestoreOrder = true;
1485     }
1486   }
1487
1488   // return previous mesh order
1489   if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1490     if (!isRestoreOrder)
1491       isRestoreOrder = 
1492         (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1493                                     tr( "SMESH_REJECT_MESH_ORDER" ),
1494                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1495     if (isRestoreOrder)
1496       myOrderMgr->SetMeshOrder(myPrevOrder);
1497   }
1498
1499   delete myOrderMgr;
1500   myOrderMgr = 0;
1501
1502   myMapShapeId.clear();
1503   SMESHGUI_BaseComputeOp::onCancel();
1504 }
1505
1506 //================================================================================
1507 /*!
1508  * \brief perform it's intention action: preview mesh
1509  */
1510 //================================================================================
1511
1512 void SMESHGUI_PrecomputeOp::onPreview()
1513 {
1514   if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1515     return;
1516
1517   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1518   if ( !aMeshSObj )
1519     return;
1520
1521   // set modified submesh priority if any
1522   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1523     myOrderMgr->SetMeshOrder();
1524
1525   // Compute preview of mesh, 
1526   // i.e. compute mesh till indicated dimension
1527   int dim = myDlg->getPreviewMode();
1528   
1529   SMESH::MemoryReserve aMemoryReserve;
1530   
1531   SMESH::compute_error_array_var aCompErrors;
1532   QString                        aHypErrors;
1533
1534   bool computeFailed = true, memoryLack = false;
1535
1536   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1537     aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1538
1539   SMESHGUI* gui = getSMESHGUI();
1540   SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1541   SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1542   if ( errors->length() > 0 ) {
1543     aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1544   }
1545
1546   SUIT_OverrideCursor aWaitCursor;
1547
1548   SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1549   if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1550   myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1551   
1552   SMESH::long_array_var aShapesId = new SMESH::long_array();
1553   try {
1554 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1555     OCC_CATCH_SIGNALS;
1556 #endif
1557       
1558     SMESH::MeshPreviewStruct_var previewData =
1559       gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1560     SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1561     if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1562     {
1563       computeFailed = false;
1564       myPreviewDisplayer->SetData( previewRes );
1565       // append shape indeces with computed mesh entities
1566       for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1567         myMapShapeId[ aShapesId[ i ] ] = 0;
1568     }
1569     else
1570       myPreviewDisplayer->SetVisibility(false);
1571   }
1572   catch(const SALOME::SALOME_Exception & S_ex){
1573     memoryLack = true;
1574     myPreviewDisplayer->SetVisibility(false);
1575   }
1576
1577   try {
1578 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1579     OCC_CATCH_SIGNALS;
1580 #endif
1581     aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1582     // check if there are memory problems
1583     for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1584       memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1585   }
1586   catch(const SALOME::SALOME_Exception & S_ex){
1587     memoryLack = true;
1588   }
1589
1590   if ( memoryLack )
1591     aMemoryReserve.release();
1592
1593   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1594   bool noHypoError = ( aHypErrors.isEmpty() );
1595
1596   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1597   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1598
1599   bool isShowError = true;
1600   switch( aNotifyMode ) {
1601   case 0: // show the mesh computation result dialog NEVER
1602     isShowError = false;
1603     break;
1604   case 1: // show the mesh computation result dialog if there are some errors
1605   default: // show the result dialog after each mesh computation
1606     if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1607       isShowError = false;
1608     break;
1609   }
1610
1611   aWaitCursor.suspend();
1612   // SHOW ERRORS
1613   if ( isShowError )
1614   {
1615     myDlg->hide();
1616     aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1617     showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1618   }
1619 }
1620
1621
1622 //================================================================================
1623 /*!
1624  * \brief Constructor
1625 */
1626 //================================================================================
1627
1628 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1629  : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1630    myOrderBox(0)
1631 {
1632   setWindowTitle( tr( "CAPTION" ) );
1633
1634   setButtonText( OK, tr( "COMPUTE" ) );
1635   QFrame* main = mainFrame();
1636
1637   QVBoxLayout* layout = new QVBoxLayout( main );
1638
1639   myOrderBox = new SMESHGUI_MeshOrderBox( main );
1640   layout->addWidget(myOrderBox);
1641
1642   QFrame* frame = new QFrame( main );
1643   layout->setMargin(0); layout->setSpacing(0);
1644   layout->addWidget( frame );
1645
1646   QHBoxLayout* frameLay = new QHBoxLayout( frame );
1647   frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1648   
1649   myPreviewMode = new QtxComboBox( frame );
1650   frameLay->addWidget( myPreviewMode );
1651
1652   myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1653   frameLay->addWidget( myPreviewBtn );
1654
1655   connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1656 }
1657
1658 //================================================================================
1659 /*!
1660  * \brief Destructor
1661 */
1662 //================================================================================
1663
1664 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1665 {
1666 }
1667
1668 //================================================================================
1669 /*!
1670  * \brief Sets available preview modes
1671 */
1672 //================================================================================
1673
1674 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1675 {
1676   myPreviewMode->clear();
1677   QList<int>::const_iterator it = theModes.constBegin();
1678   for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1679   {
1680     QString mode = QString( "PREVIEW_%1" ).arg( *it );
1681     myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1682     myPreviewMode->setId( i, *it );
1683   }
1684   myPreviewBtn->setEnabled( !theModes.isEmpty() );
1685 }
1686
1687 //================================================================================
1688 /*!
1689  * \brief Returns current preview mesh mode
1690 */
1691 //================================================================================
1692
1693 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1694 {
1695   return myPreviewMode->currentId();
1696 }
1697
1698 //================================================================================
1699 /*!
1700  * \brief Returns current preview mesh mode
1701 */
1702 //================================================================================
1703
1704 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1705 {
1706   return myOrderBox;
1707 }
1708
1709
1710 //================================================================================
1711 /*!
1712  * \brief Constructor
1713 */
1714 //================================================================================
1715
1716 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1717  : SMESHGUI_BaseComputeOp()
1718 {
1719 }
1720
1721
1722 //================================================================================
1723 /*!
1724  * \brief Desctructor
1725 */
1726 //================================================================================
1727
1728 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1729 {
1730 }
1731
1732 //================================================================================
1733 /*!
1734  * \brief perform it's intention action: compute mesh
1735  */
1736 //================================================================================
1737
1738 void SMESHGUI_EvaluateOp::startOperation()
1739 {
1740   SMESHGUI_BaseComputeOp::evaluateDlg();
1741   SMESHGUI_BaseComputeOp::startOperation();
1742   if (myMesh->_is_nil())
1743     return;
1744   evaluateMesh();
1745 }
1746
1747 //================================================================================
1748 /*!
1749  * \brief Gets dialog of this operation
1750  * \retval LightApp_Dialog* - pointer to dialog of this operation
1751  */
1752 //================================================================================
1753
1754 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1755 {
1756   return evaluateDlg();
1757 }
1758
1759 //================================================================================
1760 /*!
1761  * \brief evaluateMesh()
1762 */
1763 //================================================================================
1764
1765 void SMESHGUI_BaseComputeOp::evaluateMesh()
1766 {
1767   // EVALUATE MESH
1768
1769   SMESH::MemoryReserve aMemoryReserve;
1770
1771   SMESH::compute_error_array_var aCompErrors;
1772   QString                        aHypErrors;
1773
1774   bool evaluateFailed = true, memoryLack = false;
1775   SMESH::long_array_var aRes;
1776
1777   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1778   if ( !aMeshSObj ) //  IPAL21340
1779     return;
1780
1781   bool hasShape = myMesh->HasShapeToMesh();
1782   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1783   if ( shapeOK )
1784   {
1785     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1786     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1787     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1788     if ( errors->length() > 0 ) {
1789       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1790     }
1791     SUIT_OverrideCursor aWaitCursor;
1792     try {
1793 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1794       OCC_CATCH_SIGNALS;
1795 #endif
1796       aRes = gen->Evaluate(myMesh, myMainShape);
1797     }
1798     catch(const SALOME::SALOME_Exception & S_ex){
1799       memoryLack = true;
1800     }
1801
1802     try {
1803 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1804       OCC_CATCH_SIGNALS;
1805 #endif
1806       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1807     }
1808     catch(const SALOME::SALOME_Exception & S_ex){
1809       memoryLack = true;
1810     }
1811   }
1812
1813   if ( memoryLack )
1814     aMemoryReserve.release();
1815
1816   evaluateFailed =  ( aCompErrors->length() > 0 );
1817   myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1818
1819   // SHOW ERRORS
1820   
1821   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1822   bool noHypoError = ( aHypErrors.isEmpty() );
1823
1824   //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1825   //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1826
1827   bool isShowResultDlg = true;
1828   //if( noHypoError )
1829   //switch( aNotifyMode ) {
1830   //case 0: // show the mesh computation result dialog NEVER
1831   //isShowResultDlg = false;
1832   //commit();
1833   //break;
1834   //case 1: // show the mesh computation result dialog if there are some errors
1835   //if ( memoryLack || !noHypoError )
1836   //  isShowResultDlg = true;
1837   //else
1838   //{
1839   //  isShowResultDlg = false;
1840   //  commit();
1841   //}
1842   //break;
1843   //default: // show the result dialog after each mesh computation
1844   //isShowResultDlg = true;
1845   //}
1846
1847   // SHOW RESULTS
1848   if ( isShowResultDlg )
1849     showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1850                         noHypoError, aHypErrors);
1851 }
1852
1853
1854 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1855                                                 const bool theMemoryLack,
1856                                                 const bool theNoCompError,
1857                                                 SMESH::compute_error_array_var& theCompErrors,
1858                                                 const bool theNoHypoError,
1859                                                 const QString& theHypErrors)
1860 {
1861   bool hasShape = myMesh->HasShapeToMesh();
1862   SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1863   aCompDlg->myMemoryLackGroup->hide();
1864
1865   if ( theMemoryLack )
1866   {
1867     aCompDlg->myMemoryLackGroup->show();
1868     aCompDlg->myFullInfo->hide();
1869     aCompDlg->myBriefInfo->hide();
1870     aCompDlg->myHypErrorGroup->hide();
1871     aCompDlg->myCompErrorGroup->hide();
1872   }
1873   else if ( theNoCompError && theNoHypoError )
1874   {
1875     aCompDlg->myFullInfo->SetMeshInfo( theRes );
1876     aCompDlg->myFullInfo->show();
1877     aCompDlg->myBriefInfo->hide();
1878     aCompDlg->myHypErrorGroup->hide();
1879     aCompDlg->myCompErrorGroup->hide();
1880   }
1881   else
1882   {
1883     QTableWidget* tbl = aCompDlg->myTable;
1884     aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1885     aCompDlg->myBriefInfo->show();
1886     aCompDlg->myFullInfo->hide();
1887
1888     if ( theNoHypoError ) {
1889       aCompDlg->myHypErrorGroup->hide();
1890     }
1891     else {
1892       aCompDlg->myHypErrorGroup->show();
1893       aCompDlg->myHypErrorLabel->setText( theHypErrors );
1894     }
1895
1896     if ( theNoCompError ) {
1897       aCompDlg->myCompErrorGroup->hide();
1898     }
1899     else {
1900       aCompDlg->myCompErrorGroup->show();
1901
1902       aCompDlg->myPublishBtn->hide();
1903       aCompDlg->myShowBtn->hide();
1904
1905       // fill table of errors
1906       tbl->setRowCount( theCompErrors->length() );
1907       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1908       else             tbl->showColumn( COL_SHAPE );
1909       tbl->setColumnWidth( COL_ERROR, 200 );
1910
1911       bool hasBadMesh = false;
1912       for ( int row = 0; row < theCompErrors->length(); ++row )
1913       {
1914         SMESH::ComputeError & err = theCompErrors[ row ];
1915
1916         QString text = err.algoName.in();
1917         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1918         else tbl->item( row, COL_ALGO )->setText( text );
1919
1920         text = SMESH::errorText( err.code, err.comment.in() );
1921         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1922         else tbl->item( row, COL_ERROR )->setText( text );
1923
1924         text = QString("%1").arg( err.subShapeID );
1925         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1926         else tbl->item( row, COL_SHAPEID )->setText( text );
1927
1928         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1929         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1930         else tbl->item( row, COL_SHAPE )->setText( text );
1931
1932         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1933         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1934         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1935
1936         text = err.hasBadMesh ? "hasBadMesh" : "";
1937         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1938         else tbl->item( row, COL_BAD_MESH )->setText( text );
1939         if ( err.hasBadMesh ) hasBadMesh = true;
1940
1941         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1942         tbl->resizeRowToContents( row );
1943       }
1944       tbl->resizeColumnToContents( COL_ALGO );
1945       tbl->resizeColumnToContents( COL_SHAPE );
1946
1947       if ( hasBadMesh )
1948         aCompDlg->myBadMeshBtn->show();
1949       else
1950         aCompDlg->myBadMeshBtn->hide();
1951
1952       tbl->setCurrentCell(0,0);
1953       currentCellChanged(); // to update buttons
1954     }
1955   }
1956   // show dialog and wait, becase Compute can be invoked from Preview operation
1957   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1958   aCompDlg->show();
1959 }
1960
1961
1962 //================================================================================
1963 /*!
1964  * \brief Gets dialog of evaluate operation
1965  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1966  */
1967 //================================================================================
1968
1969 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1970 {
1971   if ( !myCompDlg )
1972   {
1973     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1974     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1975     // connect signals and slots
1976     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1977     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1978     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1979     QTableWidget* aTable = me->table();
1980     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1981     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1982   }
1983   return myCompDlg;
1984 }
1985