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