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