Salome HOME
0019970: create groups automatically
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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 //
23 //
24 //  File   : SMESHGUI_ComputeDlg.cxx
25 //  Author : Edward AGAPOV
26 //  Module : SMESH
27
28 #include "SMESHGUI_ComputeDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_GEOMGenUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_HypothesesUtils.h"
36 #include "SMESHGUI_MeshEditPreview.h"
37 #include "SMESH_ActorUtils.h"
38
39 #include "SMDS_SetIterator.hxx"
40 #include "SMDS_Mesh.hxx"
41
42 #include "GEOMBase.h"
43 #include "GEOM_Actor.h"
44
45 #include "LightApp_SelectionMgr.h"
46 #include "LightApp_UpdateFlags.h"
47 #include "SALOMEDSClient_SObject.hxx"
48 #include "SALOME_ListIO.hxx"
49 #include "SVTK_ViewWindow.h"
50 #include "SVTK_ViewModel.h"
51 #include "SalomeApp_Tools.h"
52 #include "SalomeApp_Application.h"
53 #include "SUIT_ResourceMgr.h"
54 #include "SUIT_OverrideCursor.h"
55 #include "SUIT_MessageBox.h"
56 #include "SUIT_Desktop.h"
57 #include "SUIT_Study.h"
58 #include "OB_Browser.h"
59
60 // OCCT Includes
61 #include <BRep_Tool.hxx>
62 #include <TopExp.hxx>
63 #include <TopExp_Explorer.hxx>
64 #include <TopTools_IndexedMapOfShape.hxx>
65 #include <TopoDS.hxx>
66
67 #include <TopLoc_Location.hxx>
68 #include <Poly_Triangulation.hxx>
69 #include <Bnd_Box.hxx>
70 #include <BRepBndLib.hxx>
71 #include <BRepMesh_IncrementalMesh.hxx>
72
73 #include <Standard_ErrorHandler.hxx>
74
75 // QT Includes
76 #include <qframe.h>
77 #include <qlayout.h>
78 #include <qpushbutton.h>
79 #include <qlabel.h>
80 #include <qbuttongroup.h>
81 #include <qradiobutton.h>
82 #include <qtable.h>
83 #include <qhbox.h>
84 #include <qhgroupbox.h>
85 #include <qvgroupbox.h>
86
87 #include <vtkProperty.h>
88
89 // IDL Headers
90 #include <SALOMEconfig.h>
91 #include CORBA_SERVER_HEADER(SMESH_Gen)
92 #include CORBA_SERVER_HEADER(SMESH_Mesh)
93
94 #include <vector>
95 #include <set>
96
97
98 #define SPACING 5
99 #define MARGIN  10
100
101 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
102
103 #define _SEPARATOR(father) \
104 {\
105   /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
106   (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
107   (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
108   (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
109   (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
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       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       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     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();
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(QTable* table, list< int > & rows)
438   {
439     rows.clear();
440     int nbSel = table->numSelections();
441     for ( int i = 0; i < nbSel; ++i )
442     {
443       QTableSelection selected = table->selection(i);
444       if ( !selected.isActive() ) continue;
445       for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
446         rows.push_back( row );
447     }
448     if (rows.empty() && table->currentRow() > -1 )
449       rows.push_back( table->currentRow() );
450
451     return rows.size();
452   }
453
454 } // namespace SMESH
455
456
457 // =========================================================================================
458 /*!
459  * \brief Box showing mesh info
460  */
461 // =========================================================================================
462
463 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
464   :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
465 {
466   // title
467   QLabel* lab1 = new QLabel(this);
468   QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
469   QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
470   QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
471
472   QFont italic = lab1->font(); italic.setItalic(true);
473   QFont bold   = lab1->font(); bold.setBold(true);
474
475   lab1->setMinimumWidth(100); lab1->setFont( italic );
476   lab2->setMinimumWidth(100); lab2->setFont( italic );
477   lab3->setMinimumWidth(100); lab3->setFont( italic );
478   lab4->setMinimumWidth(100); lab4->setFont( italic );
479
480   if ( myFull )
481   {
482     // nodes
483     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
484     myNbNode = new QLabel( this );
485     new QLabel(this);
486     new QLabel(this);
487
488     _SEPARATOR(this);
489
490     // edges
491     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
492     myNbEdge = new QLabel( this );
493     myNbLinEdge = new QLabel( this );
494     myNbQuadEdge = new QLabel( this );
495
496     _SEPARATOR(this);
497
498     // faces
499     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
500     myNbFace     = new QLabel( this );
501     myNbLinFace  = new QLabel( this );
502     myNbQuadFace = new QLabel( this );
503     // triangles
504     new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
505     myNbTrai     = new QLabel( this );
506     myNbLinTrai  = new QLabel( this );
507     myNbQuadTrai = new QLabel( this );
508     // quadrangles
509     new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
510     myNbQuad     = new QLabel( this );
511     myNbLinQuad  = new QLabel( this );
512     myNbQuadQuad = new QLabel( this );
513     // poligones
514     new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
515     myNbPolyg    = new QLabel( this );
516     new QLabel("",this );
517     new QLabel("", this );
518
519     _SEPARATOR(this);
520
521     // volumes
522     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
523     myNbVolum     = new QLabel( this );
524     myNbLinVolum  = new QLabel( this );
525     myNbQuadVolum = new QLabel( this );
526     // tetras
527     new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
528     myNbTetra     = new QLabel( this );
529     myNbLinTetra  = new QLabel( this );
530     myNbQuadTetra = new QLabel( this );
531     // hexas
532     new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
533     myNbHexa      = new QLabel( this );
534     myNbLinHexa   = new QLabel( this );
535     myNbQuadHexa  = new QLabel( this );
536     // pyras
537     new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
538     myNbPyra      = new QLabel( this );
539     myNbLinPyra   = new QLabel( this );
540     myNbQuadPyra  = new QLabel( this );
541     // prisms
542     new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
543     myNbPrism     = new QLabel( this );
544     myNbLinPrism  = new QLabel( this );
545     myNbQuadPrism = new QLabel( this );
546     // polyedres
547     new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
548     myNbPolyh     = new QLabel( this );
549     new QLabel("", this );
550     new QLabel("", this );
551   }
552   else
553   {
554     // nodes
555     new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
556     myNbNode      = new QLabel( this );
557     new QLabel(this);
558     new QLabel(this);
559
560     // edges
561     new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
562     myNbEdge      = new QLabel( this );
563     myNbLinEdge   = new QLabel( this );
564     myNbQuadEdge  = new QLabel( this );
565
566     // faces
567     new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
568     myNbFace      = new QLabel( this );
569     myNbLinFace   = new QLabel( this );
570     myNbQuadFace  = new QLabel( this );
571
572     // volumes
573     new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
574     myNbVolum     = new QLabel( this );
575     myNbLinVolum  = new QLabel( this );
576     myNbQuadVolum = new QLabel( this );
577   }
578 }
579
580 // =========================================================================================
581 /*!
582  * \brief Set mesh info
583  */
584 // =========================================================================================
585
586 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
587 {
588   const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
589   int nbTot, nbLin;
590
591   // nodes
592   myNbNode     ->setText( QString("%1").arg( mesh->NbNodes() ));
593
594   // edges
595   nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
596   myNbEdge     ->setText( QString("%1").arg( nbTot ));
597   myNbLinEdge  ->setText( QString("%1").arg( nbLin ));
598   myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
599
600   // faces
601   nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
602   myNbFace     ->setText( QString("%1").arg( nbTot ));
603   myNbLinFace  ->setText( QString("%1").arg( nbLin )); 
604   myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
605
606   // volumes
607   nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
608   myNbVolum    ->setText( QString("%1").arg( nbTot ));
609   myNbLinVolum ->setText( QString("%1").arg( nbLin ));
610   myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
611
612   if ( myFull )
613   {
614     // triangles
615     nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
616     myNbTrai     ->setText( QString("%1").arg( nbTot ));
617     myNbLinTrai  ->setText( QString("%1").arg( nbLin ));
618     myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
619     // quadrangles
620     nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
621     myNbQuad     ->setText( QString("%1").arg( nbTot ));
622     myNbLinQuad  ->setText( QString("%1").arg( nbLin ));
623     myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
624     // poligones
625     myNbPolyg    ->setText( QString("%1").arg( mesh->NbPolygons() ));
626
627     // tetras
628     nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
629     myNbTetra    ->setText( QString("%1").arg( nbTot ));
630     myNbLinTetra ->setText( QString("%1").arg( nbLin ));
631     myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
632     // hexas
633     nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
634     myNbHexa     ->setText( QString("%1").arg( nbTot ));
635     myNbLinHexa  ->setText( QString("%1").arg( nbLin ));
636     myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
637     // pyras
638     nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
639     myNbPyra     ->setText( QString("%1").arg( nbTot ));
640     myNbLinPyra  ->setText( QString("%1").arg( nbLin ));
641     myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
642     // prisms
643     nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
644     myNbPrism    ->setText( QString("%1").arg( nbTot ));
645     myNbLinPrism ->setText( QString("%1").arg( nbLin ));
646     myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
647     // polyedres
648     myNbPolyh    ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
649   }
650 }
651
652 // =========================================================================================
653 /*!
654  * \brief Dialog to compute a mesh and show computation errors
655  */
656 //=======================================================================
657
658 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, Close/* | Help*/ )
659 {
660   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
661
662   QFrame* aMainFrame = createMainFrame  (mainFrame());
663
664   aDlgLay->addWidget(aMainFrame);
665
666   aDlgLay->setStretchFactor(aMainFrame, 1);
667 }
668
669 //=======================================================================
670 // function : createMainFrame()
671 // purpose  : Create frame containing dialog's fields
672 //=======================================================================
673
674 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
675
676 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
677 {
678   QFrame* aFrame = new QFrame(theParent);
679
680   SUIT_ResourceMgr* rm = resourceMgr();
681   QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
682
683   // constructor
684
685   QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
686   aPixGrp->setExclusive(TRUE);
687   QRadioButton* aRBut = new QRadioButton(aPixGrp);
688   aRBut->setPixmap(iconCompute);
689   aRBut->setChecked(TRUE);
690
691   // Mesh name
692
693   QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
694   myMeshName = new QLabel(nameBox);
695
696   // Mesh Info
697
698   myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
699   myFullInfo  = new SMESHGUI_MeshInfosBox(true,  aFrame);
700
701   // Computation errors
702
703   myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "myCompErrorGroup");
704   myTable      = new QTable( 1, NB_COLUMNS, myCompErrorGroup, "myTable");
705   myShowBtn    = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup, "myShowBtn");
706   myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup, "myPublishBtn");
707   myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup, "myBadMeshBtn");
708
709   myTable->setReadOnly( TRUE );
710   myTable->hideColumn( COL_PUBLISHED );
711   myTable->hideColumn( COL_SHAPEID );
712   myTable->hideColumn( COL_BAD_MESH );
713   myTable->setColumnStretchable( COL_ERROR, 1 );
714   for ( int col = 0; col < NB_COLUMNS; ++col ) {
715     QString header;
716     switch ( col ) {
717     CASE2HEADER( COL_ALGO     );
718     CASE2HEADER( COL_SHAPE    );
719     CASE2HEADER( COL_ERROR    );
720     CASE2HEADER( COL_SHAPEID  );
721     CASE2HEADER( COL_PUBLISHED);
722     }
723     myTable->horizontalHeader()->setLabel( col, header );
724   }
725   // layouting
726   myCompErrorGroup->setColumnLayout(0, Qt::Vertical);
727   myCompErrorGroup->layout()->setSpacing(0);
728   myCompErrorGroup->layout()->setMargin(0);
729   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup->layout());
730   grpLayout->setAlignment(Qt::AlignTop);
731   grpLayout->setSpacing(SPACING);
732   grpLayout->setMargin(MARGIN);
733   grpLayout->addMultiCellWidget( myTable,   0, 3, 0, 0 );
734   grpLayout->addWidget         ( myShowBtn,    0, 1 );
735   grpLayout->addWidget         ( myPublishBtn, 1, 1 );
736   grpLayout->addWidget         ( myBadMeshBtn, 2, 1 );
737   grpLayout->setRowStretch( 3, 1 );
738
739   // Hypothesis definition errors
740
741   myHypErrorGroup = new QGroupBox(1,Qt::Vertical, tr("SMESH_WRN_MISSING_PARAMETERS"),aFrame);
742   myHypErrorLabel = new QLabel(myHypErrorGroup);
743
744   // Memory Lack Label
745
746   myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
747   QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
748   QFont bold = memLackLabel->font(); bold.setBold(true);
749   memLackLabel->setFont( bold );
750   memLackLabel->setMinimumWidth(300);
751
752   // add all widgets to aFrame
753   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
754   aLay->addWidget( aPixGrp );
755   aLay->addWidget( nameBox );
756   aLay->addWidget( myBriefInfo );
757   aLay->addWidget( myFullInfo );
758   aLay->addWidget( myHypErrorGroup );
759   aLay->addWidget( myCompErrorGroup );
760   aLay->addWidget( myMemoryLackGroup );
761   aLay->setStretchFactor( myCompErrorGroup, 1 );
762
763   ((QPushButton*) button( OK ))->setDefault( true );
764
765   return aFrame;
766 }
767
768 //================================================================================
769 /*!
770  * \brief Constructor
771 */
772 //================================================================================
773
774 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
775 {
776   myDlg = new SMESHGUI_ComputeDlg;
777   myTShapeDisplayer = new TShapeDisplayer();
778   myBadMeshDisplayer = 0;
779
780   //myHelpFileName = "/files/about_meshes.htm"; // V3
781   myHelpFileName = "about_meshes_page.html"; // V4
782
783   // connect signals and slots
784   connect(myDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
785   connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
786   connect(myDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
787   connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
788   connect(table(),SIGNAL(currentChanged(int,int)), SLOT(currentCellChanged()));
789 }
790
791 //=======================================================================
792 // function : startOperation()
793 // purpose  : Init dialog fields, connect signals and slots, show dialog
794 //=======================================================================
795
796 void SMESHGUI_ComputeOp::startOperation()
797 {
798   SMESHGUI_Operation::startOperation();
799
800   // check selection
801
802   myMesh      = SMESH::SMESH_Mesh::_nil();
803   myMainShape = GEOM::GEOM_Object::_nil();
804
805   LightApp_SelectionMgr *Sel = selectionMgr();
806   SALOME_ListIO selected; Sel->selectedObjects( selected );
807
808   int nbSel = selected.Extent();
809   if (nbSel != 1) {
810     SUIT_MessageBox::warn1(desktop(),
811                            tr("SMESH_WRN_WARNING"),
812                            tr("SMESH_WRN_NO_AVAILABLE_DATA"),
813                            tr("SMESH_BUT_OK"));
814     onCancel();
815     return;
816   }
817
818   Handle(SALOME_InteractiveObject) IObject = selected.First();
819   myMesh = SMESH::GetMeshByIO(IObject);
820   if (myMesh->_is_nil()) {
821     SUIT_MessageBox::warn1(desktop(),
822                            tr("SMESH_WRN_WARNING"),
823                            tr("SMESH_WRN_NO_AVAILABLE_DATA"),
824                            tr("SMESH_BUT_OK"));
825     onCancel();
826     return;
827   }
828
829   // COMPUTE MESH
830
831   MemoryReserve aMemoryReserve;
832
833   SMESH::compute_error_array_var aCompErrors;
834   QString                        aHypErrors;
835
836   bool computeFailed = true, memoryLack = false;
837
838   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
839   myMainShape = myMesh->GetShapeToMesh();
840   bool hasShape = myMesh->HasShapeToMesh();
841   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
842   if ( shapeOK && aMeshSObj )
843   {
844     myDlg->myMeshName->setText( aMeshSObj->GetName() );
845     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
846     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
847     if ( errors->length() > 0 ) {
848       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
849     }
850     SUIT_OverrideCursor aWaitCursor;
851     try {
852 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
853       OCC_CATCH_SIGNALS;
854 #endif
855       if (gen->Compute(myMesh, myMainShape))
856         computeFailed = false;
857     }
858     catch(const SALOME::SALOME_Exception & S_ex){
859       memoryLack = true;
860     }
861     try {
862 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
863       OCC_CATCH_SIGNALS;
864 #endif
865       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
866       // check if there are memory problems
867       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
868         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
869     }
870     catch(const SALOME::SALOME_Exception & S_ex){
871       memoryLack = true;
872     }
873
874     // NPAL16631: if ( !memoryLack )
875     {
876       SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
877       update( UF_ObjBrowser | UF_Model );
878
879       // SHOW MESH
880       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
881       if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
882       {
883         try {
884 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
885           OCC_CATCH_SIGNALS;
886 #endif
887           SMESH::Update(IObject, true);
888         }
889         catch (...) {
890 #ifdef _DEBUG_
891           MESSAGE ( "Exception thrown during mesh visualization" );
892 #endif
893           if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
894             SMESH::OnVisuException();
895           }
896           else {
897             memoryLack = true;
898           }
899         }
900       }
901       Sel->setSelectedObjects( selected );
902     }
903   }
904
905   if ( memoryLack )
906     aMemoryReserve.release();
907
908   myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
909   myDlg->myMemoryLackGroup->hide();
910
911   // SHOW ERRORS
912
913   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
914   bool noHypoError = ( aHypErrors.isEmpty() );
915
916   if ( memoryLack )
917   {
918     myDlg->myMemoryLackGroup->show();
919     myDlg->myFullInfo->hide();
920     myDlg->myBriefInfo->hide();
921     myDlg->myHypErrorGroup->hide();
922     myDlg->myCompErrorGroup->hide();
923   }
924   else if ( noCompError && noHypoError )
925   {
926     myDlg->myFullInfo->SetInfoByMesh( myMesh );
927     myDlg->myFullInfo->show();
928     myDlg->myBriefInfo->hide();
929     myDlg->myHypErrorGroup->hide();
930     myDlg->myCompErrorGroup->hide();
931   }
932   else
933   {
934     QTable* tbl = myDlg->myTable;
935     myDlg->myBriefInfo->SetInfoByMesh( myMesh );
936     myDlg->myBriefInfo->show();
937     myDlg->myFullInfo->hide();
938
939     if ( noHypoError ) {
940       myDlg->myHypErrorGroup->hide();
941     }
942     else {
943       myDlg->myHypErrorGroup->show();
944       myDlg->myHypErrorLabel->setText( aHypErrors );
945     }
946
947     if ( noCompError ) {
948       myDlg->myCompErrorGroup->hide();
949     }
950     else {
951       myDlg->myCompErrorGroup->show();
952
953       if ( !hasShape ) {
954         myDlg->myPublishBtn->hide();
955         myDlg->myShowBtn->hide();
956       }
957       else {
958         myDlg->myPublishBtn->show();
959         myDlg->myShowBtn->show();
960       }
961
962       // fill table of errors
963       tbl->setNumRows( aCompErrors->length() );
964       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
965       else             tbl->showColumn( COL_SHAPE );
966       tbl->setColumnWidth( COL_ERROR, 200 );
967
968       bool hasBadMesh = false;
969       for ( int row = 0; row < aCompErrors->length(); ++row )
970       {
971         SMESH::ComputeError & err = aCompErrors[ row ];
972         tbl->setText( row, COL_ALGO,    err.algoName.in() );
973         tbl->setText( row, COL_ERROR,   errorText( err.code, err.comment.in() ));
974         tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
975
976         QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
977         tbl->setText( row, COL_SHAPE,   text );
978
979         text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
980         tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
981
982         text = err.hasBadMesh ? "hasBadMesh" : "";
983         tbl->setText( row, COL_BAD_MESH, text );
984         if ( err.hasBadMesh ) hasBadMesh = true;
985
986         tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
987         tbl->adjustRow( row );
988       }
989       tbl->adjustColumn( COL_ALGO );
990       tbl->adjustColumn( COL_SHAPE );
991
992       if ( hasBadMesh )
993         myDlg->myBadMeshBtn->show();
994       else
995         myDlg->myBadMeshBtn->hide();
996
997       tbl->setCurrentCell(0,0);
998       currentCellChanged(); // to update buttons
999     }
1000   }
1001   myDlg->show();
1002 }
1003
1004 //================================================================================
1005 /*!
1006  * \brief Stops operation
1007  */
1008 //================================================================================
1009
1010 void SMESHGUI_ComputeOp::stopOperation()
1011 {
1012   SMESHGUI_Operation::stopOperation();
1013   myTShapeDisplayer->SetVisibility( false );
1014   if ( myBadMeshDisplayer ) {
1015     myBadMeshDisplayer->SetVisibility( false );
1016     // delete it in order not to have problems at its destruction when the viewer
1017     // where it worked is dead due to e.g. study closing
1018     delete myBadMeshDisplayer;
1019     myBadMeshDisplayer = 0;
1020   }
1021 }
1022
1023 //================================================================================
1024 /*!
1025  * \brief publish selected subshape
1026  */
1027 //================================================================================
1028
1029 void SMESHGUI_ComputeOp::onPublishShape()
1030 {
1031   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1032   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1033
1034   list< int > rows;
1035   list< int >::iterator row;
1036   getSelectedRows( table(), rows );
1037   for ( row = rows.begin(); row != rows.end(); ++row )
1038   {
1039     int curSub = table()->text(*row, COL_SHAPEID).toInt();
1040     GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
1041     if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
1042     {
1043       if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
1044       {
1045         QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1046         SALOMEDS::SObject_var so =
1047           geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
1048         // look for myMainShape in the table
1049         for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
1050           if ( table()->text(r, COL_SHAPEID) == "1" ) {
1051             if ( so->_is_nil() ) {
1052               table()->setText( r, COL_SHAPE, so->GetName() );
1053               table()->setText( r, COL_PUBLISHED, so->GetID() );
1054             }
1055             break;
1056           }
1057         }
1058         if ( curSub == 1 ) continue;
1059       }
1060       QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
1061       SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
1062       if ( !so->_is_nil() ) {
1063         table()->setText( *row, COL_SHAPE, so->GetName() );
1064         table()->setText( *row, COL_PUBLISHED, so->GetID() );
1065       }
1066     }
1067   }
1068   getSMESHGUI()->getApp()->updateObjectBrowser();
1069   currentCellChanged(); // to update buttons
1070 }
1071
1072 //================================================================================
1073 /*!
1074  * \brief show mesh elements preventing computation of a submesh of current row
1075  */
1076 //================================================================================
1077
1078 void SMESHGUI_ComputeOp::onShowBadMesh()
1079 {
1080   myTShapeDisplayer->SetVisibility( false );
1081   list< int > rows;
1082   if ( getSelectedRows( table(), rows ) == 1 ) {
1083     bool hasBadMesh = ( !table()->text(rows.front(), COL_BAD_MESH).isEmpty() );
1084     if ( hasBadMesh ) {
1085       int curSub = table()->text(rows.front(), COL_SHAPEID).toInt();
1086       SMESHGUI* gui = getSMESHGUI();
1087       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1088       SVTK_ViewWindow*    view = GetViewWindow( gui );
1089       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1090       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1091       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1092       vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1093       vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1094       // delete property !!!!!!!!!!
1095       vtkProperty* prop = vtkProperty::New();
1096       prop->SetLineWidth( aLineWidth * 3 );
1097       prop->SetPointSize( aPointSize * 3 );
1098       prop->SetColor( 250, 0, 250 );
1099       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1100       myBadMeshDisplayer->SetData( aMeshData._retn() );
1101     }
1102   }
1103 }
1104
1105 //================================================================================
1106 /*!
1107  * \brief SLOT called when a selected cell in table() changed
1108  */
1109 //================================================================================
1110
1111 void SMESHGUI_ComputeOp::currentCellChanged()
1112 {
1113   myTShapeDisplayer->SetVisibility( false );
1114   if ( myBadMeshDisplayer )
1115     myBadMeshDisplayer->SetVisibility( false );
1116
1117   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1118   list< int > rows;
1119   list< int >::iterator row;
1120   int nbSelected = getSelectedRows( table(), rows );
1121   for ( row = rows.begin(); row != rows.end(); ++row )
1122   {
1123     bool hasData     = ( !table()->text(*row, COL_SHAPE).isEmpty() );
1124     bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
1125     if ( hasData && !isPublished )
1126       publishEnable = true;
1127
1128     int curSub = table()->text(*row, COL_SHAPEID).toInt();
1129     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1130     if ( prsReady ) {
1131       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1132       showOnly = false;
1133     }
1134     else {
1135       showEnable = true;
1136     }
1137
1138     if ( !table()->text(*row, COL_BAD_MESH).isEmpty() )
1139       hasBadMesh = true;
1140   }
1141   myDlg->myPublishBtn->setEnabled( publishEnable );
1142   myDlg->myShowBtn   ->setEnabled( showEnable );
1143   myDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1144 }
1145
1146 //================================================================================
1147 /*!
1148  * \brief update preview
1149  */
1150 //================================================================================
1151
1152 void SMESHGUI_ComputeOp::onPreviewShape()
1153 {
1154   if ( myTShapeDisplayer )
1155   {
1156     SUIT_OverrideCursor aWaitCursor;
1157     list< int > rows;
1158     list< int >::iterator row;
1159     getSelectedRows( table(), rows );
1160
1161     bool showOnly = true;
1162     for ( row = rows.begin(); row != rows.end(); ++row )
1163     {
1164       int curSub = table()->text(*row, COL_SHAPEID).toInt();
1165       if ( curSub > 0 ) {
1166         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1167         showOnly = false;
1168       }
1169     }
1170     currentCellChanged(); // to update buttons
1171   }
1172 }
1173
1174 //================================================================================
1175 /*!
1176  * \brief Destructor
1177  */
1178 //================================================================================
1179
1180 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1181 {
1182   delete myTShapeDisplayer;
1183   if ( myBadMeshDisplayer )
1184     delete myBadMeshDisplayer;
1185 }
1186
1187 //================================================================================
1188 /*!
1189  * \brief Gets dialog of this operation
1190  * \retval LightApp_Dialog* - pointer to dialog of this operation
1191  */
1192 //================================================================================
1193
1194 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1195 {
1196   return myDlg;
1197 }
1198
1199 //================================================================================
1200 /*!
1201  * \brief perform it's intention action: compute mesh
1202  */
1203 //================================================================================
1204
1205 bool SMESHGUI_ComputeOp::onApply()
1206 {
1207   return true;
1208 }
1209
1210 //================================================================================
1211 /*!
1212  * \brief Return a table
1213  */
1214 //================================================================================
1215
1216 QTable* SMESHGUI_ComputeOp::table()
1217 {
1218   return myDlg->myTable;
1219 }