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