]> SALOME platform Git repositories - modules/smesh.git/blob - src/SMESHGUI/SMESHGUI_ComputeDlg.cxx
Salome HOME
Qt4 porting.
[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( MARGIN );
461   l->setSpacing( SPACING );
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
823   // Mesh name
824
825   QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
826   QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
827   nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
828   myMeshName = new QLabel(nameBox);
829   nameBoxLayout->addWidget(myMeshName);
830
831   // Mesh Info
832
833   myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
834   myFullInfo  = new SMESHGUI_MeshInfosBox(true,  aFrame);
835
836   // Computation errors
837
838   myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
839   myTable      = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
840   myShowBtn    = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
841   myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
842
843   //myTable->setReadOnly( true ); // VSR: check
844   myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
845   myTable->hideColumn( COL_PUBLISHED );
846   myTable->hideColumn( COL_SHAPEID );
847   myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
848
849   QStringList headers;
850   headers << tr( "COL_ALGO_HEADER" );
851   headers << tr( "COL_SHAPE_HEADER" );
852   headers << tr( "COL_ERROR_HEADER" );
853   headers << tr( "COL_SHAPEID_HEADER" );
854   headers << tr( "COL_PUBLISHED_HEADER" );
855
856   myTable->setHorizontalHeaderLabels( headers );
857
858   // layouting
859   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
860   grpLayout->setSpacing(SPACING);
861   grpLayout->setMargin(MARGIN);
862   grpLayout->addWidget( myTable,      0, 0, 3, 1 );
863   grpLayout->addWidget( myShowBtn,    0, 1 );
864   grpLayout->addWidget( myPublishBtn, 1, 1 );
865   grpLayout->setRowStretch( 2, 1 );
866
867   // Hypothesis definition errors
868
869   myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
870   QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
871   myHypErrorGroupLayout->setMargin(MARGIN);
872   myHypErrorGroupLayout->setSpacing(SPACING);
873   myHypErrorLabel = new QLabel(myHypErrorGroup);
874   myHypErrorGroupLayout->addWidget(myHypErrorLabel);
875
876   // Memory Lack Label
877
878   myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
879   QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
880   myMemoryLackGroupLayout->setMargin(MARGIN);
881   myMemoryLackGroupLayout->setSpacing(SPACING);
882   QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
883   QFont bold = memLackLabel->font(); bold.setBold(true);
884   memLackLabel->setFont( bold );
885   memLackLabel->setMinimumWidth(300);
886   myMemoryLackGroupLayout->addWidget(memLackLabel);
887
888   // add all widgets to aFrame
889   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
890   aLay->setMargin( 0 );
891   aLay->setSpacing( 0 );
892   aLay->addWidget( aPixGrp );
893   aLay->addWidget( nameBox );
894   aLay->addWidget( myBriefInfo );
895   aLay->addWidget( myFullInfo );
896   aLay->addWidget( myHypErrorGroup );
897   aLay->addWidget( myCompErrorGroup );
898   aLay->addWidget( myMemoryLackGroup );
899   aLay->setStretchFactor( myCompErrorGroup, 1 );
900
901   ((QPushButton*) button( OK ))->setDefault( true );
902
903   return aFrame;
904 }
905
906 //================================================================================
907 /*!
908  * \brief Constructor
909 */
910 //================================================================================
911
912 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
913 {
914   myDlg = new SMESHGUI_ComputeDlg;
915   myTShapeDisplayer = new SMESH::TShapeDisplayer();
916   //myHelpFileName = "/files/about_meshes.htm"; // V3
917   myHelpFileName = "about_meshes_page.html"; // V4
918
919   // connect signals and slots
920   connect(myDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
921   connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
922   connect(table(), SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
923   connect(table(), SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
924 }
925
926 //=======================================================================
927 // function : startOperation()
928 // purpose  : Init dialog fields, connect signals and slots, show dialog
929 //=======================================================================
930
931 void SMESHGUI_ComputeOp::startOperation()
932 {
933   SMESHGUI_Operation::startOperation();
934
935   // check selection
936
937   SMESH::SMESH_Mesh_var aMesh;
938   myMainShape = GEOM::GEOM_Object::_nil();
939
940   LightApp_SelectionMgr *Sel = selectionMgr();
941   SALOME_ListIO selected; Sel->selectedObjects( selected );
942
943   int nbSel = selected.Extent();
944   if (nbSel != 1) {
945     SUIT_MessageBox::warning(desktop(),
946                              tr("SMESH_WRN_WARNING"),
947                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
948     onCancel();
949     return;
950   }
951
952   Handle(SALOME_InteractiveObject) IObject = selected.First();
953   aMesh = SMESH::GetMeshByIO(IObject);
954   if (aMesh->_is_nil()) {
955     SUIT_MessageBox::warning(desktop(),
956                              tr("SMESH_WRN_WARNING"),
957                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
958     onCancel();
959     return;
960   }
961
962   // COMPUTE MESH
963
964   SMESH::MemoryReserve aMemoryReserve;
965
966   SMESH::compute_error_array_var aCompErrors;
967   QString                        aHypErrors;
968
969   bool computeFailed = true, memoryLack = false;
970
971   _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
972   myMainShape = aMesh->GetShapeToMesh();
973   bool hasShape = aMesh->HasShapeToMesh();
974   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
975   if ( shapeOK && aMeshSObj )
976   {
977     myDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
978     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
979     SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
980     if ( errors->length() > 0 ) {
981       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
982     }
983     SUIT_OverrideCursor aWaitCursor;
984     try {
985 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
986       OCC_CATCH_SIGNALS;
987 #endif
988       if (gen->Compute(aMesh, myMainShape))
989         computeFailed = false;
990     }
991     catch(const SALOME::SALOME_Exception & S_ex){
992       memoryLack = true;
993     }
994     try {
995 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
996       OCC_CATCH_SIGNALS;
997 #endif
998       aCompErrors = gen->GetComputeErrors( aMesh, myMainShape );
999       // check if there are memory problems
1000       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1001         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1002     }
1003     catch(const SALOME::SALOME_Exception & S_ex){
1004       memoryLack = true;
1005     }
1006
1007     // NPAL16631: if ( !memoryLack )
1008     {
1009       SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
1010       update( UF_ObjBrowser | UF_Model );
1011
1012       // SHOW MESH
1013       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
1014       if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
1015       {
1016         try {
1017 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1018           OCC_CATCH_SIGNALS;
1019 #endif
1020           SMESH::Update(IObject, true);
1021         }
1022         catch (...) {
1023 #ifdef _DEBUG_
1024           cout << "Exception thrown during mesh visualization" << endl;
1025 #endif
1026           if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1027             SMESH::OnVisuException();
1028           }
1029           else {
1030             memoryLack = true;
1031           }
1032         }
1033       }
1034       Sel->setSelectedObjects( selected );
1035     }
1036   }
1037   myDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1038   myDlg->myMemoryLackGroup->hide();
1039
1040   // SHOW ERRORS
1041
1042   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1043   bool noHypoError = ( aHypErrors.isEmpty() );
1044
1045   if ( memoryLack )
1046   {
1047     myDlg->myMemoryLackGroup->show();
1048     myDlg->myFullInfo->hide();
1049     myDlg->myBriefInfo->hide();
1050     myDlg->myHypErrorGroup->hide();
1051     myDlg->myCompErrorGroup->hide();
1052   }
1053   else if ( noCompError && noHypoError )
1054   {
1055     myDlg->myFullInfo->SetInfoByMesh( aMesh );
1056     myDlg->myFullInfo->show();
1057     myDlg->myBriefInfo->hide();
1058     myDlg->myHypErrorGroup->hide();
1059     myDlg->myCompErrorGroup->hide();
1060   }
1061   else
1062   {
1063     QTableWidget* tbl = myDlg->myTable;
1064     myDlg->myBriefInfo->SetInfoByMesh( aMesh );
1065     myDlg->myBriefInfo->show();
1066     myDlg->myFullInfo->hide();
1067
1068     if ( noHypoError ) {
1069       myDlg->myHypErrorGroup->hide();
1070     }
1071     else {
1072       myDlg->myHypErrorGroup->show();
1073       myDlg->myHypErrorLabel->setText( aHypErrors );
1074     }
1075
1076     if ( noCompError ) {
1077       myDlg->myCompErrorGroup->hide();
1078     }
1079     else {
1080       myDlg->myCompErrorGroup->show();
1081
1082       if ( !hasShape ) {
1083         myDlg->myPublishBtn->hide();
1084         myDlg->myShowBtn->hide();
1085       }
1086       else {
1087         myDlg->myPublishBtn->show();
1088         myDlg->myShowBtn->show();
1089       }
1090
1091       // fill table of errors
1092       tbl->setRowCount( aCompErrors->length() );
1093       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1094       else             tbl->showColumn( COL_SHAPE );
1095       tbl->setColumnWidth( COL_ERROR, 200 );
1096
1097       for ( int row = 0; row < aCompErrors->length(); ++row )
1098       {
1099         SMESH::ComputeError & err = aCompErrors[ row ];
1100         tbl->item( row, COL_ALGO )->setText( err.algoName.in() );
1101         tbl->item( row, COL_ERROR )->setText( SMESH::errorText( err.code, err.comment.in() ));
1102         tbl->item( row, COL_SHAPEID )->setText( QString("%1").arg( err.subShapeID ));
1103
1104         QString text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1105         tbl->item( row, COL_SHAPE )->setText( text );
1106
1107         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1108         tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1109
1110         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1111         tbl->resizeRowToContents( row );
1112       }
1113       tbl->resizeColumnToContents( COL_ALGO );
1114       tbl->resizeColumnToContents( COL_SHAPE );
1115
1116       tbl->setCurrentCell(0,0);
1117       currentCellChanged(); // to update buttons
1118     }
1119   }
1120   myDlg->show();
1121 }
1122
1123 //================================================================================
1124 /*!
1125  * \brief Stops operation
1126  */
1127 //================================================================================
1128
1129 void SMESHGUI_ComputeOp::stopOperation()
1130 {
1131   SMESHGUI_Operation::stopOperation();
1132   myTShapeDisplayer->SetVisibility( false );
1133 }
1134
1135 //================================================================================
1136 /*!
1137  * \brief publish selected subshape
1138  */
1139 //================================================================================
1140
1141 void SMESHGUI_ComputeOp::onPublishShape()
1142 {
1143   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1144   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1145
1146   QList<int> rows;
1147   SMESH::getSelectedRows( table(), rows );
1148   int row;
1149   foreach ( row, rows )
1150   {
1151     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1152     GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1153     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1154     {
1155       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1156       {
1157         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1158         SALOMEDS::SObject_var so =
1159           geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1160         // look for myMainShape in the table
1161         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1162           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1163             if ( so->_is_nil() ) {
1164               table()->item( r, COL_SHAPE )->setText( so->GetName() );
1165               table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1166             }
1167             break;
1168           }
1169         }
1170         if ( curSub == 1 ) continue;
1171       }
1172       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1173       SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1174       if ( !so->_is_nil() ) {
1175         table()->item( row, COL_SHAPE )->setText( so->GetName() );
1176         table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1177       }
1178     }
1179   }
1180   getSMESHGUI()->getApp()->updateObjectBrowser();
1181   currentCellChanged(); // to update buttons
1182 }
1183
1184 //================================================================================
1185 /*!
1186  * \brief SLOT called when a selected cell in table() changed
1187  */
1188 //================================================================================
1189
1190 void SMESHGUI_ComputeOp::currentCellChanged()
1191 {
1192   myTShapeDisplayer->SetVisibility( false );
1193
1194   bool publishEnable = 0, showEnable = 0, showOnly = 1;
1195   QList<int> rows;
1196   SMESH::getSelectedRows( table(), rows );
1197   int row;
1198   foreach ( row, rows )
1199   {
1200     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1201     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1202     if ( hasData && !isPublished )
1203       publishEnable = true;
1204
1205     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1206     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1207     if ( prsReady ) {
1208       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1209       showOnly = false;
1210     }
1211     else {
1212       showEnable = true;
1213     }
1214   }
1215   myDlg->myPublishBtn->setEnabled( publishEnable );
1216   myDlg->myShowBtn->setEnabled( showEnable );
1217 }
1218
1219 //================================================================================
1220 /*!
1221  * \brief update preview
1222  */
1223 //================================================================================
1224
1225 void SMESHGUI_ComputeOp::onPreviewShape()
1226 {
1227   if ( myTShapeDisplayer )
1228   {
1229     SUIT_OverrideCursor aWaitCursor;
1230     QList<int> rows;
1231     SMESH::getSelectedRows( table(), rows );
1232
1233     bool showOnly = true;
1234     int row;
1235     foreach ( row, rows )
1236     {
1237       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1238       if ( curSub > 0 ) {
1239         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1240         showOnly = false;
1241       }
1242     }
1243     currentCellChanged(); // to update buttons
1244   }
1245 }
1246
1247 //================================================================================
1248 /*!
1249  * \brief Destructor
1250  */
1251 //================================================================================
1252
1253 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1254 {
1255   if ( myTShapeDisplayer ) delete myTShapeDisplayer;
1256 }
1257
1258 //================================================================================
1259 /*!
1260  * \brief Gets dialog of this operation
1261  * \retval LightApp_Dialog* - pointer to dialog of this operation
1262  */
1263 //================================================================================
1264
1265 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1266 {
1267   return myDlg;
1268 }
1269
1270 //================================================================================
1271 /*!
1272  * \brief perform it's intention action: compute mesh
1273  */
1274 //================================================================================
1275
1276 bool SMESHGUI_ComputeOp::onApply()
1277 {
1278   return true;
1279 }
1280
1281 //================================================================================
1282 /*!
1283  * \brief Return a table
1284  */
1285 //================================================================================
1286
1287 QTableWidget* SMESHGUI_ComputeOp::table()
1288 {
1289   return myDlg->myTable;
1290 }