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