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