Salome HOME
IPAL21120 SIGSEGV on Meshing attached Compound with Automatic Hexadralization
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMESHGUI : GUI for SMESH component
23 //  File   : SMESHGUI_ComputeDlg.cxx
24 //  Author : Edward AGAPOV
25 //  Module : SMESH
26 //
27 #include "SMESHGUI_ComputeDlg.h"
28
29 #include "SMESHGUI.h"
30 #include "SMESHGUI_GEOMGenUtils.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_HypothesesUtils.h"
35 #include "SMESHGUI_MeshEditPreview.h"
36 #include "SMESH_ActorUtils.h"
37
38 #include "SMDS_SetIterator.hxx"
39 #include "SMDS_Mesh.hxx"
40
41 #include "GEOMBase.h"
42 #include "GEOM_Actor.h"
43
44 #include "LightApp_SelectionMgr.h"
45 #include "LightApp_UpdateFlags.h"
46 #include "SALOMEDSClient_SObject.hxx"
47 #include "SALOME_ListIO.hxx"
48 #include "SVTK_ViewWindow.h"
49 #include "SVTK_ViewModel.h"
50 #include "SalomeApp_Tools.h"
51 #include "SalomeApp_Application.h"
52 #include "SUIT_ResourceMgr.h"
53 #include "SUIT_OverrideCursor.h"
54 #include "SUIT_MessageBox.h"
55 #include "SUIT_Desktop.h"
56 #include "SUIT_Study.h"
57 #include "OB_Browser.h"
58
59 // OCCT Includes
60 #include <BRep_Tool.hxx>
61 #include <TopExp.hxx>
62 #include <TopExp_Explorer.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <TopoDS.hxx>
65
66 #include <TopLoc_Location.hxx>
67 #include <Poly_Triangulation.hxx>
68 #include <Bnd_Box.hxx>
69 #include <BRepBndLib.hxx>
70 #include <BRepMesh_IncrementalMesh.hxx>
71
72 #include <Standard_ErrorHandler.hxx>
73
74 // QT Includes
75 #include <qframe.h>
76 #include <qlayout.h>
77 #include <qpushbutton.h>
78 #include <qlabel.h>
79 #include <qbuttongroup.h>
80 #include <qradiobutton.h>
81 #include <qtable.h>
82 #include <qhbox.h>
83 #include <qhgroupbox.h>
84 #include <qvgroupbox.h>
85
86 #include <vtkProperty.h>
87
88 // IDL Headers
89 #include <SALOMEconfig.h>
90 #include CORBA_SERVER_HEADER(SMESH_Gen)
91 #include CORBA_SERVER_HEADER(SMESH_Mesh)
92
93 #include <vector>
94 #include <set>
95
96 using namespace std;
97
98
99 #define SPACING 5
100 #define MARGIN  10
101
102 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
103
104 #define _SEPARATOR(father) \
105 {\
106   /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
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   (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
111 }
112
113 enum TCol {
114   COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
115 };
116
117 using namespace SMESH;
118
119 namespace SMESH {
120   
121   //=============================================================================
122   /*!
123    * \brief Allocate some memory at construction and release it at destruction.
124    * Is used to be able to continue working after mesh generation or visualization
125    * break due to lack of memory
126    */
127   //=============================================================================
128
129   struct MemoryReserve
130   {
131     char* myBuf;
132     MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
133     void release() { delete [] myBuf; myBuf = 0; }
134     ~MemoryReserve() { release(); }
135   };
136
137   // =========================================================================================
138   /*!
139    * \brief Class showing shapes without publishing
140    */
141   // =========================================================================================
142
143   class TShapeDisplayer
144   {
145   public:
146     // -----------------------------------------------------------------------
147     TShapeDisplayer(): myViewWindow(0)
148     {
149       myProperty = vtkProperty::New();
150       myProperty->SetRepresentationToWireframe();
151       myProperty->SetColor( 250, 0, 250 );
152       myProperty->SetAmbientColor( 250, 0, 250 );
153       myProperty->SetDiffuseColor( 250, 0, 250 );
154       //myProperty->SetSpecularColor( 250, 0, 250 );
155       myProperty->SetLineWidth( 5 );
156     }
157     // -----------------------------------------------------------------------
158     ~TShapeDisplayer()
159     {
160       DeleteActors();
161       myProperty->Delete();
162     }
163     // -----------------------------------------------------------------------
164     void DeleteActors()
165     {
166       if ( hasViewWindow() ) {
167         TActorIterator actorIt = actorIterator();
168         while ( actorIt.more() )
169           if (VTKViewer_Actor* anActor = actorIt.next()) {
170             myViewWindow->RemoveActor( anActor );
171             //anActor->Delete();
172           }
173       }
174       myIndexToShape.Clear();
175       myActors.clear();
176       myShownActors.clear();
177       myBuiltSubs.clear();
178     }
179     // -----------------------------------------------------------------------
180     void SetVisibility (bool theVisibility)
181     {
182       TActorIterator actorIt = shownIterator();
183       while ( actorIt.more() )
184         if (VTKViewer_Actor* anActor = actorIt.next())
185           anActor->SetVisibility(theVisibility);
186       SMESH::RepaintCurrentView();
187     }
188     // -----------------------------------------------------------------------
189     bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
190     {
191       string mainEntry;
192       if ( !aMainShape->_is_nil() )
193         mainEntry = aMainShape->GetStudyEntry();
194       return ( myMainEntry == mainEntry &&
195                myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
196     }
197     // -----------------------------------------------------------------------
198     void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
199     {
200       SVTK_ViewWindow* aViewWindow  = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
201       string mainEntry;
202       if ( !aMainShape->_is_nil() )
203         mainEntry = aMainShape->GetStudyEntry();
204       if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
205         DeleteActors();
206         TopoDS_Shape aShape;
207         if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
208           checkTriangulation( aShape );
209           TopExp::MapShapes(aShape, myIndexToShape);
210           myActors.resize( myIndexToShape.Extent(), 0 );
211           myShownActors.reserve( myIndexToShape.Extent() );
212         }
213         myMainEntry  = mainEntry;
214         myViewWindow = aViewWindow;
215       }
216       if ( only ) { // hide shown actors
217         TActorIterator actorIt = shownIterator();
218         while ( actorIt.more() )
219           if (VTKViewer_Actor* anActor = actorIt.next())
220             anActor->SetVisibility(false);
221         myShownActors.clear();
222       }
223       // find actors to show
224       TopoDS_Shape aShape = myIndexToShape( subShapeID );
225       if ( !aShape.IsNull() ) {
226         TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
227         for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
228           //checkTriangulation( exp.Current() );
229           if ( GEOM_Actor* anActor = getActor( exp.Current() ))
230             myShownActors.push_back( anActor );
231         }
232         if ( type == TopAbs_FACE ) {
233           for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
234             const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
235             if ( !BRep_Tool::Degenerated( edge ))
236               if ( GEOM_Actor* anActor = getActor( exp.Current() ))
237                 myShownActors.push_back( anActor );
238           }
239         }
240       }
241       myBuiltSubs.insert( subShapeID );
242       SetVisibility(true);
243     }
244     // -----------------------------------------------------------------------
245
246   private:
247
248     typedef std::vector<GEOM_Actor*> TActorVec;
249     TActorVec                  myActors;
250     TActorVec                  myShownActors;
251     TopTools_IndexedMapOfShape myIndexToShape;
252     string                     myMainEntry;
253     SVTK_ViewWindow*           myViewWindow;
254     vtkProperty*               myProperty;
255     std::set<int>              myBuiltSubs;
256
257     // -----------------------------------------------------------------------
258     typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
259     TActorIterator actorIterator() {
260       return TActorIterator( myActors.begin(), myActors.end() );
261     }
262     TActorIterator shownIterator() {
263       return TActorIterator( myShownActors.begin(), myShownActors.end() );
264     }
265     // -----------------------------------------------------------------------
266     GEOM_Actor* getActor(const TopoDS_Shape& shape)
267     {
268       int index = myIndexToShape.FindIndex( shape ) - 1;
269       if ( index < 0 || index >= myActors.size() )
270         return 0;
271       GEOM_Actor* & actor = myActors[ index ];
272       if ( !actor ) {
273         actor = GEOM_Actor::New();
274         if ( actor ) {
275           actor->SetShape(shape,0,0);
276           actor->SetProperty(myProperty);
277           actor->SetShadingProperty(myProperty);
278           actor->SetWireframeProperty(myProperty);
279           actor->SetPreviewProperty(myProperty);
280           actor->PickableOff();
281           //         if ( shape.ShapeType() == TopAbs_EDGE )
282           //           actor->SubShapeOn();
283           myViewWindow->AddActor( actor );
284         }
285       }
286       return actor;
287     }
288     // -----------------------------------------------------------------------
289     void checkTriangulation(const TopoDS_Shape& shape)
290     {
291       TopLoc_Location aLoc;
292       Standard_Boolean alreadymesh = Standard_True;
293       TopExp_Explorer ex(shape, TopAbs_FACE);
294       if ( ex.More() )
295         for (; ex.More(); ex.Next()) {
296           const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
297           Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
298           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
299         }
300       else
301         for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
302           const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
303           Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
304           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
305         }
306       if (alreadymesh) return;
307       // Compute default deflection
308       Bnd_Box B;
309       BRepBndLib::Add(shape, B);
310       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
311       B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
312       double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
313       BRepMesh_IncrementalMesh MESH(shape,deflection);
314     }
315     // -----------------------------------------------------------------------
316     bool hasViewWindow() const
317     {
318       if ( !myViewWindow ) return false;
319
320       if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
321         return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
322                                   myViewWindow );
323       return false;
324     }
325   };
326
327   // =========================================================================================
328   /*!
329    * \brief Return text describing an error
330    */
331 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
332   QString errorText(int errCode, const char* comment)
333   {
334     QString text;
335     switch ( errCode ) {
336       CASE2TEXT( COMPERR_OK            );
337       CASE2TEXT( COMPERR_BAD_INPUT_MESH);
338       CASE2TEXT( COMPERR_STD_EXCEPTION );
339       CASE2TEXT( COMPERR_OCC_EXCEPTION );
340     case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
341       CASE2TEXT( COMPERR_EXCEPTION     );
342       CASE2TEXT( COMPERR_MEMORY_PB     );
343       CASE2TEXT( COMPERR_BAD_SHAPE     );
344     case SMESH::COMPERR_ALGO_FAILED:
345       if ( strlen(comment) == 0 )
346         text = QObject::tr("COMPERR_ALGO_FAILED");
347       break;
348     default:
349       text = QString("#%1").arg( -errCode );
350     }
351     if ( text.length() > 0 ) text += ". ";
352     return text + comment;
353   }
354   // -----------------------------------------------------------------------
355   /*!
356    * \brief Return SO of a subshape
357    */
358   _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
359   {
360     _PTR(SObject) so = SMESH::FindSObject(aMainShape);
361     if ( subShapeID == 1 || !so )
362       return so;
363     _PTR(ChildIterator) it;
364     if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
365       it =  study->NewChildIterator(so);
366     _PTR(SObject) subSO;
367     if ( it ) {
368       for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
369         GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
370         if ( !geom->_is_nil() ) {
371           GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
372           if ( list->length() == 1 && list[0] == subShapeID )
373             subSO = it->Value();
374         }
375       }
376     }
377     return subSO;
378   }
379   // -----------------------------------------------------------------------
380   /*!
381    * \brief Return subshape by ID
382    */
383   GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
384   {
385     GEOM::GEOM_Object_var aSubShape;
386     if ( subShapeID == 1 )
387       aSubShape = aMainShape;
388     else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
389       aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
390     else
391       aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
392     return aSubShape._retn();
393   }
394   // -----------------------------------------------------------------------
395   /*!
396    * \brief Return shape type name
397    */
398 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
399   QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
400   {
401     QString name = dflt;
402     if ( !aShape->_is_nil() ) {
403       switch ( aShape->GetShapeType() ) {
404       CASE2NAME( VERTEX    );
405       CASE2NAME( EDGE      );
406       CASE2NAME( WIRE      );
407       CASE2NAME( FACE      );
408       CASE2NAME( SHELL     );
409       CASE2NAME( SOLID     );
410       CASE2NAME( COMPSOLID );
411       CASE2NAME( COMPOUND  );
412       default:;
413       }
414     }
415     return name;
416   }
417   // -----------------------------------------------------------------------
418   /*!
419    * \brief Return text describing a subshape
420    */
421   QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
422   {
423     QString text;
424     if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
425       text = aSO->GetName();
426     else {
427       text = QString("#%1").arg( subShapeID );
428       QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
429       if ( typeName.length() )
430         text += QString(" (%1)").arg(typeName);
431     }
432     return text;
433   }
434   // -----------------------------------------------------------------------
435   /*!
436    * \brief Return a list of selected rows
437    */
438   int getSelectedRows(QTable* table, list< int > & rows)
439   {
440     rows.clear();
441     int nbSel = table->numSelections();
442     for ( int i = 0; i < nbSel; ++i )
443     {
444       QTableSelection selected = table->selection(i);
445       if ( !selected.isActive() ) continue;
446       for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
447         rows.push_back( row );
448     }
449     if (rows.empty() && table->currentRow() > -1 )
450       rows.push_back( table->currentRow() );
451
452     return rows.size();
453   }
454
455 } // namespace SMESH
456
457
458 // =========================================================================================
459 /*!
460  * \brief Box showing mesh info
461  */
462 // =========================================================================================
463
464 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
465   :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
466 {
467   // title
468   QLabel* lab1 = new QLabel(this);
469   QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
470   QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
471   QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
472
473   QFont italic = lab1->font(); italic.setItalic(true);
474   QFont bold   = lab1->font(); bold.setBold(true);
475
476   lab1->setMinimumWidth(100); lab1->setFont( italic );
477   lab2->setMinimumWidth(100); lab2->setFont( italic );
478   lab3->setMinimumWidth(100); lab3->setFont( italic );
479   lab4->setMinimumWidth(100); lab4->setFont( italic );
480
481   if ( myFull )
482   {
483     // nodes
484     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
485     myNbNode = new QLabel( this );
486     new QLabel(this);
487     new QLabel(this);
488
489     _SEPARATOR(this);
490
491     // edges
492     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
493     myNbEdge = new QLabel( this );
494     myNbLinEdge = new QLabel( this );
495     myNbQuadEdge = new QLabel( this );
496
497     _SEPARATOR(this);
498
499     // faces
500     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
501     myNbFace     = new QLabel( this );
502     myNbLinFace  = new QLabel( this );
503     myNbQuadFace = new QLabel( this );
504     // triangles
505     new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
506     myNbTrai     = new QLabel( this );
507     myNbLinTrai  = new QLabel( this );
508     myNbQuadTrai = new QLabel( this );
509     // quadrangles
510     new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
511     myNbQuad     = new QLabel( this );
512     myNbLinQuad  = new QLabel( this );
513     myNbQuadQuad = new QLabel( this );
514     // poligones
515     new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
516     myNbPolyg    = new QLabel( this );
517     new QLabel("",this );
518     new QLabel("", this );
519
520     _SEPARATOR(this);
521
522     // volumes
523     (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
524     myNbVolum     = new QLabel( this );
525     myNbLinVolum  = new QLabel( this );
526     myNbQuadVolum = new QLabel( this );
527     // tetras
528     new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
529     myNbTetra     = new QLabel( this );
530     myNbLinTetra  = new QLabel( this );
531     myNbQuadTetra = new QLabel( this );
532     // hexas
533     new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
534     myNbHexa      = new QLabel( this );
535     myNbLinHexa   = new QLabel( this );
536     myNbQuadHexa  = new QLabel( this );
537     // pyras
538     new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
539     myNbPyra      = new QLabel( this );
540     myNbLinPyra   = new QLabel( this );
541     myNbQuadPyra  = new QLabel( this );
542     // prisms
543     new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
544     myNbPrism     = new QLabel( this );
545     myNbLinPrism  = new QLabel( this );
546     myNbQuadPrism = new QLabel( this );
547     // polyedres
548     new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
549     myNbPolyh     = new QLabel( this );
550     new QLabel("", this );
551     new QLabel("", this );
552   }
553   else
554   {
555     // nodes
556     new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
557     myNbNode      = new QLabel( this );
558     new QLabel(this);
559     new QLabel(this);
560
561     // edges
562     new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
563     myNbEdge      = new QLabel( this );
564     myNbLinEdge   = new QLabel( this );
565     myNbQuadEdge  = new QLabel( this );
566
567     // faces
568     new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
569     myNbFace      = new QLabel( this );
570     myNbLinFace   = new QLabel( this );
571     myNbQuadFace  = new QLabel( this );
572
573     // volumes
574     new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
575     myNbVolum     = new QLabel( this );
576     myNbLinVolum  = new QLabel( this );
577     myNbQuadVolum = new QLabel( this );
578   }
579 }
580
581 // =========================================================================================
582 /*!
583  * \brief Set mesh info
584  */
585 // =========================================================================================
586
587 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
588 {
589   const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
590   int nbTot, nbLin;
591
592   // nodes
593   myNbNode     ->setText( QString("%1").arg( mesh->NbNodes() ));
594
595   // edges
596   nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
597   myNbEdge     ->setText( QString("%1").arg( nbTot ));
598   myNbLinEdge  ->setText( QString("%1").arg( nbLin ));
599   myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
600
601   // faces
602   nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
603   myNbFace     ->setText( QString("%1").arg( nbTot ));
604   myNbLinFace  ->setText( QString("%1").arg( nbLin )); 
605   myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
606
607   // volumes
608   nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
609   myNbVolum    ->setText( QString("%1").arg( nbTot ));
610   myNbLinVolum ->setText( QString("%1").arg( nbLin ));
611   myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
612
613   if ( myFull )
614   {
615     // triangles
616     nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
617     myNbTrai     ->setText( QString("%1").arg( nbTot ));
618     myNbLinTrai  ->setText( QString("%1").arg( nbLin ));
619     myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
620     // quadrangles
621     nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
622     myNbQuad     ->setText( QString("%1").arg( nbTot ));
623     myNbLinQuad  ->setText( QString("%1").arg( nbLin ));
624     myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
625     // poligones
626     myNbPolyg    ->setText( QString("%1").arg( mesh->NbPolygons() ));
627
628     // tetras
629     nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
630     myNbTetra    ->setText( QString("%1").arg( nbTot ));
631     myNbLinTetra ->setText( QString("%1").arg( nbLin ));
632     myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
633     // hexas
634     nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
635     myNbHexa     ->setText( QString("%1").arg( nbTot ));
636     myNbLinHexa  ->setText( QString("%1").arg( nbLin ));
637     myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
638     // pyras
639     nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
640     myNbPyra     ->setText( QString("%1").arg( nbTot ));
641     myNbLinPyra  ->setText( QString("%1").arg( nbLin ));
642     myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
643     // prisms
644     nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
645     myNbPrism    ->setText( QString("%1").arg( nbTot ));
646     myNbLinPrism ->setText( QString("%1").arg( nbLin ));
647     myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
648     // polyedres
649     myNbPolyh    ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
650   }
651 }
652
653 // =========================================================================================
654 /*!
655  * \brief Dialog to compute a mesh and show computation errors
656  */
657 //=======================================================================
658
659 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, Close/* | Help*/ )
660 {
661   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
662
663   QFrame* aMainFrame = createMainFrame  (mainFrame());
664
665   aDlgLay->addWidget(aMainFrame);
666
667   aDlgLay->setStretchFactor(aMainFrame, 1);
668 }
669
670 //=======================================================================
671 // function : createMainFrame()
672 // purpose  : Create frame containing dialog's fields
673 //=======================================================================
674
675 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
676
677 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
678 {
679   QFrame* aFrame = new QFrame(theParent);
680
681   SUIT_ResourceMgr* rm = resourceMgr();
682   QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
683
684   // constructor
685
686   QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
687   aPixGrp->setExclusive(TRUE);
688   QRadioButton* aRBut = new QRadioButton(aPixGrp);
689   aRBut->setPixmap(iconCompute);
690   aRBut->setChecked(TRUE);
691
692   // Mesh name
693
694   QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
695   myMeshName = new QLabel(nameBox);
696
697   // Mesh Info
698
699   myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
700   myFullInfo  = new SMESHGUI_MeshInfosBox(true,  aFrame);
701
702   // Computation errors
703
704   myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "myCompErrorGroup");
705   myTable      = new QTable( 1, NB_COLUMNS, myCompErrorGroup, "myTable");
706   myShowBtn    = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup, "myShowBtn");
707   myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup, "myPublishBtn");
708   myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup, "myBadMeshBtn");
709
710   myTable->setReadOnly( TRUE );
711   myTable->hideColumn( COL_PUBLISHED );
712   myTable->hideColumn( COL_SHAPEID );
713   myTable->hideColumn( COL_BAD_MESH );
714   myTable->setColumnStretchable( COL_ERROR, 1 );
715   for ( int col = 0; col < NB_COLUMNS; ++col ) {
716     QString header;
717     switch ( col ) {
718     CASE2HEADER( COL_ALGO     );
719     CASE2HEADER( COL_SHAPE    );
720     CASE2HEADER( COL_ERROR    );
721     CASE2HEADER( COL_SHAPEID  );
722     CASE2HEADER( COL_PUBLISHED);
723     }
724     myTable->horizontalHeader()->setLabel( col, header );
725   }
726   // layouting
727   myCompErrorGroup->setColumnLayout(0, Qt::Vertical);
728   myCompErrorGroup->layout()->setSpacing(0);
729   myCompErrorGroup->layout()->setMargin(0);
730   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup->layout());
731   grpLayout->setAlignment(Qt::AlignTop);
732   grpLayout->setSpacing(SPACING);
733   grpLayout->setMargin(MARGIN);
734   grpLayout->addMultiCellWidget( myTable,   0, 3, 0, 0 );
735   grpLayout->addWidget         ( myShowBtn,    0, 1 );
736   grpLayout->addWidget         ( myPublishBtn, 1, 1 );
737   grpLayout->addWidget         ( myBadMeshBtn, 2, 1 );
738   grpLayout->setRowStretch( 3, 1 );
739
740   // Hypothesis definition errors
741
742   myHypErrorGroup = new QGroupBox(1,Qt::Vertical, tr("SMESH_WRN_MISSING_PARAMETERS"),aFrame);
743   myHypErrorLabel = new QLabel(myHypErrorGroup);
744
745   // Memory Lack Label
746
747   myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
748   QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
749   QFont bold = memLackLabel->font(); bold.setBold(true);
750   memLackLabel->setFont( bold );
751   memLackLabel->setMinimumWidth(300);
752
753   // add all widgets to aFrame
754   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
755   aLay->addWidget( aPixGrp );
756   aLay->addWidget( nameBox );
757   aLay->addWidget( myBriefInfo );
758   aLay->addWidget( myFullInfo );
759   aLay->addWidget( myHypErrorGroup );
760   aLay->addWidget( myCompErrorGroup );
761   aLay->addWidget( myMemoryLackGroup );
762   aLay->setStretchFactor( myCompErrorGroup, 1 );
763
764   ((QPushButton*) button( OK ))->setDefault( true );
765
766   return aFrame;
767 }
768
769 //================================================================================
770 /*!
771  * \brief Constructor
772 */
773 //================================================================================
774
775 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
776 {
777   myDlg = new SMESHGUI_ComputeDlg;
778   myTShapeDisplayer = new TShapeDisplayer();
779   myBadMeshDisplayer = 0;
780
781   //myHelpFileName = "/files/about_meshes.htm"; // V3
782   myHelpFileName = "about_meshes_page.html"; // V4
783
784   // connect signals and slots
785   connect(myDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
786   connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
787   connect(myDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
788   connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
789   connect(table(),SIGNAL(currentChanged(int,int)), SLOT(currentCellChanged()));
790 }
791
792 //=======================================================================
793 // function : startOperation()
794 // purpose  : Init dialog fields, connect signals and slots, show dialog
795 //=======================================================================
796
797 void SMESHGUI_ComputeOp::startOperation()
798 {
799   SMESHGUI_Operation::startOperation();
800
801   // check selection
802
803   myMesh      = SMESH::SMESH_Mesh::_nil();
804   myMainShape = GEOM::GEOM_Object::_nil();
805
806   LightApp_SelectionMgr *Sel = selectionMgr();
807   SALOME_ListIO selected; Sel->selectedObjects( selected );
808
809   int nbSel = selected.Extent();
810   if (nbSel != 1) {
811     SUIT_MessageBox::warn1(desktop(),
812                            tr("SMESH_WRN_WARNING"),
813                            tr("SMESH_WRN_NO_AVAILABLE_DATA"),
814                            tr("SMESH_BUT_OK"));
815     onCancel();
816     return;
817   }
818
819   Handle(SALOME_InteractiveObject) IObject = selected.First();
820   myMesh = SMESH::GetMeshByIO(IObject);
821   if (myMesh->_is_nil()) {
822     SUIT_MessageBox::warn1(desktop(),
823                            tr("SMESH_WRN_WARNING"),
824                            tr("SMESH_WRN_NO_AVAILABLE_DATA"),
825                            tr("SMESH_BUT_OK"));
826     onCancel();
827     return;
828   }
829
830   // COMPUTE MESH
831
832   MemoryReserve aMemoryReserve;
833
834   SMESH::compute_error_array_var aCompErrors;
835   QString                        aHypErrors;
836
837   bool computeFailed = true, memoryLack = false;
838
839   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
840   myMainShape = myMesh->GetShapeToMesh();
841   bool hasShape = myMesh->HasShapeToMesh();
842   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
843   if ( shapeOK && aMeshSObj )
844   {
845     myDlg->myMeshName->setText( aMeshSObj->GetName() );
846     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
847     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
848     if ( errors->length() > 0 ) {
849       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
850     }
851     SUIT_OverrideCursor aWaitCursor;
852     try {
853 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
854       OCC_CATCH_SIGNALS;
855 #endif
856       if (gen->Compute(myMesh, myMainShape))
857         computeFailed = false;
858     }
859     catch(const SALOME::SALOME_Exception & S_ex){
860       memoryLack = true;
861     }
862     try {
863 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
864       OCC_CATCH_SIGNALS;
865 #endif
866       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
867       // check if there are memory problems
868       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
869         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
870     }
871     catch(const SALOME::SALOME_Exception & S_ex){
872       memoryLack = true;
873     }
874
875     // NPAL16631: if ( !memoryLack )
876     {
877       SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
878       update( UF_ObjBrowser | UF_Model );
879
880       // SHOW MESH
881       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
882       if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
883       {
884         try {
885 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
886           OCC_CATCH_SIGNALS;
887 #endif
888           SMESH::Update(IObject, true);
889         }
890         catch (...) {
891 #ifdef _DEBUG_
892           MESSAGE ( "Exception thrown during mesh visualization" );
893 #endif
894           if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
895             SMESH::OnVisuException();
896           }
897           else {
898             memoryLack = true;
899           }
900         }
901       }
902       Sel->setSelectedObjects( selected );
903     }
904   }
905
906   if ( memoryLack )
907     aMemoryReserve.release();
908
909   myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
910   myDlg->myMemoryLackGroup->hide();
911
912   // SHOW ERRORS
913
914   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
915   bool noHypoError = ( aHypErrors.isEmpty() );
916
917   if ( memoryLack )
918   {
919     myDlg->myMemoryLackGroup->show();
920     myDlg->myFullInfo->hide();
921     myDlg->myBriefInfo->hide();
922     myDlg->myHypErrorGroup->hide();
923     myDlg->myCompErrorGroup->hide();
924   }
925   else if ( noCompError && noHypoError )
926   {
927     myDlg->myFullInfo->SetInfoByMesh( myMesh );
928     myDlg->myFullInfo->show();
929     myDlg->myBriefInfo->hide();
930     myDlg->myHypErrorGroup->hide();
931     myDlg->myCompErrorGroup->hide();
932   }
933   else
934   {
935     QTable* tbl = myDlg->myTable;
936     myDlg->myBriefInfo->SetInfoByMesh( myMesh );
937     myDlg->myBriefInfo->show();
938     myDlg->myFullInfo->hide();
939
940     if ( noHypoError ) {
941       myDlg->myHypErrorGroup->hide();
942     }
943     else {
944       myDlg->myHypErrorGroup->show();
945       myDlg->myHypErrorLabel->setText( aHypErrors );
946     }
947
948     if ( noCompError ) {
949       myDlg->myCompErrorGroup->hide();
950     }
951     else {
952       myDlg->myCompErrorGroup->show();
953
954       if ( !hasShape ) {
955         myDlg->myPublishBtn->hide();
956         myDlg->myShowBtn->hide();
957       }
958       else {
959         myDlg->myPublishBtn->show();
960         myDlg->myShowBtn->show();
961       }
962
963       // fill table of errors
964       tbl->setNumRows( aCompErrors->length() );
965       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
966       else             tbl->showColumn( COL_SHAPE );
967       tbl->setColumnWidth( COL_ERROR, 200 );
968
969       bool hasBadMesh = false;
970       for ( int row = 0; row < aCompErrors->length(); ++row )
971       {
972         SMESH::ComputeError & err = aCompErrors[ row ];
973         tbl->setText( row, COL_ALGO,    err.algoName.in() );
974         tbl->setText( row, COL_ERROR,   errorText( err.code, err.comment.in() ));
975         tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
976
977         QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
978         tbl->setText( row, COL_SHAPE,   text );
979
980         text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
981         tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
982
983         text = err.hasBadMesh ? "hasBadMesh" : "";
984         tbl->setText( row, COL_BAD_MESH, text );
985         if ( err.hasBadMesh ) hasBadMesh = true;
986
987         tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
988         tbl->adjustRow( row );
989       }
990       tbl->adjustColumn( COL_ALGO );
991       tbl->adjustColumn( COL_SHAPE );
992
993       if ( hasBadMesh )
994         myDlg->myBadMeshBtn->show();
995       else
996         myDlg->myBadMeshBtn->hide();
997
998       tbl->setCurrentCell(0,0);
999       currentCellChanged(); // to update buttons
1000     }
1001   }
1002   myDlg->show();
1003 }
1004
1005 //================================================================================
1006 /*!
1007  * \brief Stops operation
1008  */
1009 //================================================================================
1010
1011 void SMESHGUI_ComputeOp::stopOperation()
1012 {
1013   SMESHGUI_Operation::stopOperation();
1014   myTShapeDisplayer->SetVisibility( false );
1015   if ( myBadMeshDisplayer ) {
1016     myBadMeshDisplayer->SetVisibility( false );
1017     // delete it in order not to have problems at its destruction when the viewer
1018     // where it worked is dead due to e.g. study closing
1019     delete myBadMeshDisplayer;
1020     myBadMeshDisplayer = 0;
1021   }
1022 }
1023
1024 //================================================================================
1025 /*!
1026  * \brief publish selected subshape
1027  */
1028 //================================================================================
1029
1030 void SMESHGUI_ComputeOp::onPublishShape()
1031 {
1032   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1033   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1034
1035   list< int > rows;
1036   list< int >::iterator row;
1037   getSelectedRows( table(), rows );
1038   for ( row = rows.begin(); row != rows.end(); ++row )
1039   {
1040     int curSub = table()->text(*row, COL_SHAPEID).toInt();
1041     GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
1042     if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
1043     {
1044       if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
1045       {
1046         QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1047         SALOMEDS::SObject_var so =
1048           geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
1049         // look for myMainShape in the table
1050         for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
1051           if ( table()->text(r, COL_SHAPEID) == "1" ) {
1052             if ( so->_is_nil() ) {
1053               table()->setText( r, COL_SHAPE, so->GetName() );
1054               table()->setText( r, COL_PUBLISHED, so->GetID() );
1055             }
1056             break;
1057           }
1058         }
1059         if ( curSub == 1 ) continue;
1060       }
1061       QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
1062       SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
1063       if ( !so->_is_nil() ) {
1064         table()->setText( *row, COL_SHAPE, so->GetName() );
1065         table()->setText( *row, COL_PUBLISHED, so->GetID() );
1066       }
1067     }
1068   }
1069   getSMESHGUI()->getApp()->updateObjectBrowser();
1070   currentCellChanged(); // to update buttons
1071 }
1072
1073 //================================================================================
1074 /*!
1075  * \brief show mesh elements preventing computation of a submesh of current row
1076  */
1077 //================================================================================
1078
1079 void SMESHGUI_ComputeOp::onShowBadMesh()
1080 {
1081   myTShapeDisplayer->SetVisibility( false );
1082   list< int > rows;
1083   if ( getSelectedRows( table(), rows ) == 1 ) {
1084     bool hasBadMesh = ( !table()->text(rows.front(), COL_BAD_MESH).isEmpty() );
1085     if ( hasBadMesh ) {
1086       int curSub = table()->text(rows.front(), COL_SHAPEID).toInt();
1087       SMESHGUI* gui = getSMESHGUI();
1088       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1089       SVTK_ViewWindow*    view = GetViewWindow( gui );
1090       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1091       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1092       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1093       vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1094       vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1095       // delete property !!!!!!!!!!
1096       vtkProperty* prop = vtkProperty::New();
1097       prop->SetLineWidth( aLineWidth * 3 );
1098       prop->SetPointSize( aPointSize * 3 );
1099       prop->SetColor( 250, 0, 250 );
1100       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1101       myBadMeshDisplayer->SetData( aMeshData._retn() );
1102     }
1103   }
1104 }
1105
1106 //================================================================================
1107 /*!
1108  * \brief SLOT called when a selected cell in table() changed
1109  */
1110 //================================================================================
1111
1112 void SMESHGUI_ComputeOp::currentCellChanged()
1113 {
1114   myTShapeDisplayer->SetVisibility( false );
1115   if ( myBadMeshDisplayer )
1116     myBadMeshDisplayer->SetVisibility( false );
1117
1118   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1119   list< int > rows;
1120   list< int >::iterator row;
1121   int nbSelected = getSelectedRows( table(), rows );
1122   for ( row = rows.begin(); row != rows.end(); ++row )
1123   {
1124     bool hasData     = ( !table()->text(*row, COL_SHAPE).isEmpty() );
1125     bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
1126     if ( hasData && !isPublished )
1127       publishEnable = true;
1128
1129     int curSub = table()->text(*row, COL_SHAPEID).toInt();
1130     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1131     if ( prsReady ) {
1132       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1133       showOnly = false;
1134     }
1135     else {
1136       showEnable = true;
1137     }
1138
1139     if ( !table()->text(*row, COL_BAD_MESH).isEmpty() )
1140       hasBadMesh = true;
1141   }
1142   myDlg->myPublishBtn->setEnabled( publishEnable );
1143   myDlg->myShowBtn   ->setEnabled( showEnable );
1144   myDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1145 }
1146
1147 //================================================================================
1148 /*!
1149  * \brief update preview
1150  */
1151 //================================================================================
1152
1153 void SMESHGUI_ComputeOp::onPreviewShape()
1154 {
1155   if ( myTShapeDisplayer )
1156   {
1157     SUIT_OverrideCursor aWaitCursor;
1158     list< int > rows;
1159     list< int >::iterator row;
1160     getSelectedRows( table(), rows );
1161
1162     bool showOnly = true;
1163     for ( row = rows.begin(); row != rows.end(); ++row )
1164     {
1165       int curSub = table()->text(*row, COL_SHAPEID).toInt();
1166       if ( curSub > 0 ) {
1167         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1168         showOnly = false;
1169       }
1170     }
1171     currentCellChanged(); // to update buttons
1172   }
1173 }
1174
1175 //================================================================================
1176 /*!
1177  * \brief Destructor
1178  */
1179 //================================================================================
1180
1181 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1182 {
1183   delete myTShapeDisplayer;
1184   if ( myBadMeshDisplayer )
1185     delete myBadMeshDisplayer;
1186 }
1187
1188 //================================================================================
1189 /*!
1190  * \brief Gets dialog of this operation
1191  * \retval LightApp_Dialog* - pointer to dialog of this operation
1192  */
1193 //================================================================================
1194
1195 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1196 {
1197   return myDlg;
1198 }
1199
1200 //================================================================================
1201 /*!
1202  * \brief perform it's intention action: compute mesh
1203  */
1204 //================================================================================
1205
1206 bool SMESHGUI_ComputeOp::onApply()
1207 {
1208   return true;
1209 }
1210
1211 //================================================================================
1212 /*!
1213  * \brief Return a table
1214  */
1215 //================================================================================
1216
1217 QTable* SMESHGUI_ComputeOp::table()
1218 {
1219   return myDlg->myTable;
1220 }