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