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