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