Salome HOME
23269: Meshing a composite block with IJK
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : SMESHGUI_ComputeDlg.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
22 // SMESH includes
23 //
24 #include "SMESHGUI_ComputeDlg.h"
25
26 #include "SMDS_Mesh.hxx"
27 #include "SMDS_SetIterator.hxx"
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_HypothesesUtils.h"
31 #include "SMESHGUI_MeshEditPreview.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33 #include "SMESHGUI_MeshOrderDlg.h"
34 #include "SMESHGUI_MeshOrderOp.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_VTKUtils.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_ActorUtils.h"
39
40 // SALOME GEOM includes
41 #include <GEOMBase.h>
42 #include <GEOM_Actor.h>
43 #include <GEOM_wrap.hxx>
44
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_UpdateFlags.h>
48 #include <QtxComboBox.h>
49 #include <SALOME_ListIO.hxx>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SVTK_ViewModel.h>
56 #include <SVTK_ViewWindow.h>
57 #include <SalomeApp_Application.h>
58
59 // SALOME KERNEL includes
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDSClient_SObject.hxx>
62 #include <SALOMEDS_wrap.hxx>
63 #include "utilities.h"
64
65 #include CORBA_SERVER_HEADER(SMESH_Group)
66
67 // OCCT includes
68 #include <BRepBndLib.hxx>
69 #include <BRepMesh_IncrementalMesh.hxx>
70 #include <BRep_Tool.hxx>
71 #include <Bnd_Box.hxx>
72 #include <Poly_Triangulation.hxx>
73 #include <TopExp.hxx>
74 #include <TopExp_Explorer.hxx>
75 #include <TopLoc_Location.hxx>
76 #include <TopTools_IndexedMapOfShape.hxx>
77 #include <TopoDS.hxx>
78
79 #include <Standard_ErrorHandler.hxx>
80
81 // Qt includes
82 #include <QFrame>
83 #include <QPushButton>
84 #include <QLabel>
85 #include <QRadioButton>
86 #include <QTableWidget>
87 #include <QHeaderView>
88 #include <QGridLayout>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QButtonGroup>
92 #include <QCloseEvent>
93 #include <QTimerEvent>
94 #include <QProgressBar>
95
96 // VTK includes
97 #include <vtkProperty.h>
98
99 // STL includes
100 #include <vector>
101 #include <set>
102
103 #ifndef WIN32
104 #include <sys/sysinfo.h>
105 #endif
106
107 #define SPACING 6
108 #define MARGIN  11
109
110 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
111 #define __SHAPE_RGB__ 250, 0, 250
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( __SHAPE_RGB__ );
152       myProperty->SetAmbientColor( __SHAPE_RGB__ );
153       myProperty->SetDiffuseColor( __SHAPE_RGB__ );
154       //myProperty->SetSpecularColor( __SHAPE_RGB__ );
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       SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
202       std::string mainEntry;
203       if ( !aMainShape->_is_nil() )
204         mainEntry = aMainShape->GetStudyEntry();
205       if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
206         DeleteActors();
207         TopoDS_Shape aShape;
208         if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
209           checkTriangulation( aShape );
210           TopExp::MapShapes(aShape, myIndexToShape);
211           myActors.resize( myIndexToShape.Extent(), 0 );
212           myShownActors.reserve( myIndexToShape.Extent() );
213         }
214         myMainEntry  = mainEntry;
215         myViewWindow = aViewWindow;
216       }
217       if ( only ) { // hide shown actors
218         TActorIterator actorIt = shownIterator();
219         while ( actorIt.more() )
220           if (VTKViewer_Actor* anActor = actorIt.next())
221             anActor->SetVisibility(false);
222         myShownActors.clear();
223       }
224       // find actors to show
225       TopoDS_Shape aShape = myIndexToShape( subShapeID );
226       if ( !aShape.IsNull() ) {
227         TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
228         for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
229           //checkTriangulation( exp.Current() );
230           if ( GEOM_Actor* anActor = getActor( exp.Current() ) ) {
231             int UNbIsos = resMgr->integerValue( "Geometry", "iso_number_u", 1);
232             int VNbIsos = resMgr->integerValue( "Geometry", "iso_number_v", 1);
233             int aNbIsos[2] = { UNbIsos ? UNbIsos : 1, VNbIsos ? VNbIsos : 1 };
234             anActor->SetNbIsos( aNbIsos );
235             myShownActors.push_back( anActor );
236           }
237         }
238         if ( type == TopAbs_FACE ) {
239           for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
240             const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
241             if ( !BRep_Tool::Degenerated( edge ))
242               if ( GEOM_Actor* anActor = getActor( exp.Current() ))
243                 myShownActors.push_back( anActor );
244           }
245         }
246       }
247       myBuiltSubs.insert( subShapeID );
248       SetVisibility(true);
249     }
250     // -----------------------------------------------------------------------
251
252   private:
253
254     typedef std::vector<GEOM_Actor*> TActorVec;
255     TActorVec                  myActors;
256     TActorVec                  myShownActors;
257     TopTools_IndexedMapOfShape myIndexToShape;
258     std::string                myMainEntry;
259     SVTK_ViewWindow*           myViewWindow;
260     vtkProperty*               myProperty;
261     std::set<int>              myBuiltSubs;
262
263     // -----------------------------------------------------------------------
264     typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
265     TActorIterator actorIterator() {
266       return TActorIterator( myActors.begin(), myActors.end() );
267     }
268     TActorIterator shownIterator() {
269       return TActorIterator( myShownActors.begin(), myShownActors.end() );
270     }
271     // -----------------------------------------------------------------------
272     GEOM_Actor* getActor(const TopoDS_Shape& shape)
273     {
274       int index = myIndexToShape.FindIndex( shape ) - 1;
275       if ( index < 0 || index >= (int) myActors.size() )
276         return 0;
277       GEOM_Actor* & actor = myActors[ index ];
278       if ( !actor ) {
279         actor = GEOM_Actor::New();
280         if ( actor ) {
281           actor->SetShape(shape,0,0);
282           // actor->SetProperty(myProperty);
283           // actor->SetShadingProperty(myProperty);
284           // actor->SetWireframeProperty(myProperty);
285           // actor->SetPreviewProperty(myProperty);
286           actor->PickableOff();
287           //
288           actor->SetWidth( myProperty->GetLineWidth() );
289           actor->SetIsosWidth( myProperty->GetLineWidth() );
290           actor->SetIsosColor( __SHAPE_RGB__ );
291           actor->SetColor( __SHAPE_RGB__ );
292           // if ( shape.ShapeType() == TopAbs_EDGE )
293           //   actor->SubShapeOn();
294           myViewWindow->AddActor( actor );
295         }
296       }
297       return actor;
298     }
299     // -----------------------------------------------------------------------
300     void checkTriangulation(const TopoDS_Shape& shape)
301     {
302       TopLoc_Location aLoc;
303       Standard_Boolean alreadymesh = Standard_True;
304       TopExp_Explorer ex(shape, TopAbs_FACE);
305       if ( ex.More() )
306         for ( ; ex.More(); ex.Next()) {
307           const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
308           Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
309           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
310         }
311       else
312         for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
313           const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
314           Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
315           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
316         }
317       if (alreadymesh) return;
318       // Compute default deflection
319       Bnd_Box B;
320       BRepBndLib::Add(shape, B);
321       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
322       B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
323       double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
324       BRepMesh_IncrementalMesh MESH(shape,deflection);
325     }
326     // -----------------------------------------------------------------------
327     bool hasViewWindow() const
328     {
329       if ( !myViewWindow ) return false;
330
331       if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
332         return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
333                                   myViewWindow );
334       return false;
335     }
336   };
337
338   // =========================================================================================
339   /*!
340    * \brief Return text describing an error
341    */
342 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
343   QString errorText(int errCode, const char* comment)
344   {
345     QString text;
346     switch ( errCode ) {
347       CASE2TEXT( COMPERR_OK               );
348       CASE2TEXT( COMPERR_BAD_INPUT_MESH   );
349       CASE2TEXT( COMPERR_STD_EXCEPTION    );
350       CASE2TEXT( COMPERR_OCC_EXCEPTION    );
351     case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
352       CASE2TEXT( COMPERR_EXCEPTION        );
353       CASE2TEXT( COMPERR_MEMORY_PB        );
354       CASE2TEXT( COMPERR_BAD_SHAPE        );
355       CASE2TEXT( COMPERR_CANCELED         );
356       CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
357       CASE2TEXT( COMPERR_BAD_PARMETERS    );
358     case SMESH::COMPERR_ALGO_FAILED:
359       if ( strlen(comment) == 0 )
360         text = QObject::tr("COMPERR_ALGO_FAILED");
361       break;
362     case SMESH::COMPERR_WARNING:
363       text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
364       break;
365     default:
366       text = QString("#%1").arg( -errCode );
367     }
368     if ( text.length() > 0 ) text += ". ";
369     return text + comment;
370   }
371   // -----------------------------------------------------------------------
372   /*!
373    * \brief Return SO of a sub-shape
374    */
375   _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
376   {
377     _PTR(SObject) so = SMESH::FindSObject(aMainShape);
378     if ( subShapeID == 1 || !so )
379       return so;
380     _PTR(ChildIterator) it;
381     if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
382       it =  study->NewChildIterator(so);
383     _PTR(SObject) subSO;
384     if ( it ) {
385       for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
386         GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
387         if ( !geom->_is_nil() ) {
388           GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
389           if ( list->length() == 1 && list[0] == subShapeID )
390           {
391             GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
392             if ( aMainShape->IsSame( mainGO ))
393               subSO = it->Value();
394           }
395         }
396       }
397     }
398     return subSO;
399   }
400   // -----------------------------------------------------------------------
401   /*!
402    * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
403    */
404   GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
405   {
406     GEOM::GEOM_Object_var aSubShape;
407     if ( subShapeID == 1 ) {
408       aSubShape = aMainShape;
409       aSubShape->Register();
410     }
411     else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
412       aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
413       aSubShape->Register();
414     }
415     else {
416       aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
417       // future call of UnRegister() will delete a servant of this new object
418     }
419     return aSubShape._retn();
420   }
421   // -----------------------------------------------------------------------
422   /*!
423    * \brief Return shape type name
424    */
425 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
426   QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
427   {
428     QString name = dflt;
429     if ( !aShape->_is_nil() ) {
430       switch ( aShape->GetShapeType() ) {
431       CASE2NAME( VERTEX    );
432       CASE2NAME( EDGE      );
433       CASE2NAME( WIRE      );
434       CASE2NAME( FACE      );
435       CASE2NAME( SHELL     );
436       CASE2NAME( SOLID     );
437       CASE2NAME( COMPSOLID );
438       CASE2NAME( COMPOUND  );
439       default:;
440       }
441     }
442     return name;
443   }
444   // -----------------------------------------------------------------------
445   /*!
446    * \brief Return text describing a sub-shape
447    */
448   QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
449   {
450     QString text;
451     if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
452       text  = aSO->GetName().c_str();
453       text += QString(" (%1)").arg( aSO->GetID().c_str() );
454     }
455     else {
456       text = QString("#%1").arg( subShapeID );
457       GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
458       QString typeName = shapeTypeName( shape );
459       if ( typeName.length() )
460         text += QString(" (%1)").arg(typeName);
461     }
462     return text;
463   }
464   // -----------------------------------------------------------------------
465   /*!
466    * \brief Return a list of selected rows
467    */
468   int getSelectedRows(QTableWidget* table, QList<int>& rows)
469   {
470     rows.clear();
471     QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
472     QTableWidgetSelectionRange range;
473     foreach( range, selRanges )
474     {
475       for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
476         if ( !rows.count( row ))
477              rows.append( row );
478     }
479     if ( rows.isEmpty() && table->currentRow() > -1 )
480       if ( !rows.count( table->currentRow() ))
481         rows.append( table->currentRow() );
482
483     return rows.count();
484   }
485
486 } // namespace SMESH
487
488
489 // =========================================================================================
490 /*!
491  * \brief Dialog to compute a mesh and show computation errors
492  */
493 //=======================================================================
494
495 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
496  : SMESHGUI_Dialog( parent, false, true, Close | Help )
497 {
498   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
499   aDlgLay->setMargin( 0 );
500   aDlgLay->setSpacing( SPACING );
501
502   QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
503
504   aDlgLay->addWidget(aMainFrame);
505
506   aDlgLay->setStretchFactor(aMainFrame, 1);
507 }
508
509 // =========================================================================================
510 /*!
511  * \brief Destructor
512  */
513 //=======================================================================
514
515 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
516 {
517 }
518
519 //=======================================================================
520 // function : createMainFrame()
521 // purpose  : Create frame containing dialog's fields
522 //=======================================================================
523
524 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
525 {
526   QFrame* aFrame = new QFrame(theParent);
527
528   SUIT_ResourceMgr* rm = resourceMgr();
529   QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
530
531   // constructor
532
533   QGroupBox* aPixGrp;
534   if(ForEval) {
535     aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
536   }
537   else {
538     aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
539   }
540   QButtonGroup* aBtnGrp = new QButtonGroup(this);
541   QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
542   aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
543
544   QRadioButton* aRBut = new QRadioButton(aPixGrp);
545   aRBut->setIcon(iconCompute);
546   aRBut->setChecked(true);
547   aPixGrpLayout->addWidget(aRBut);
548   aBtnGrp->addButton(aRBut, 0);
549
550   // Mesh name
551
552   QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
553   QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
554   nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
555   myMeshName = new QLabel(nameBox);
556   nameBoxLayout->addWidget(myMeshName);
557
558   // Mesh Info
559
560   myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
561   myFullInfo  = new SMESHGUI_MeshInfosBox(true,  aFrame);
562
563   // Computation errors
564
565   myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
566   myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
567   myTable        = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
568   myShowBtn      = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
569   myPublishBtn   = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
570   myBadMeshBtn   = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
571   myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
572
573   //myTable->setReadOnly( true ); // VSR: check
574   myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
575   myTable->hideColumn( COL_PUBLISHED );
576   myTable->hideColumn( COL_SHAPEID );
577   myTable->hideColumn( COL_BAD_MESH );
578   myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
579   myTable->setWordWrap( true );
580   myTable->horizontalHeader()->setStretchLastSection( true );
581   myTable->setMinimumWidth( 500 );
582
583   QStringList headers;
584   headers << tr( "COL_ALGO_HEADER" );
585   headers << tr( "COL_SHAPE_HEADER" );
586   headers << tr( "COL_ERROR_HEADER" );
587   headers << tr( "COL_SHAPEID_HEADER" );
588   headers << tr( "COL_PUBLISHED_HEADER" );
589
590   myTable->setHorizontalHeaderLabels( headers );
591
592   // layouting
593   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
594   grpLayout->setSpacing(SPACING);
595   grpLayout->setMargin(MARGIN);
596   grpLayout->addWidget( myWarningLabel,      0, 0, 1, 4 );
597   grpLayout->addWidget( myTable,             1, 0, 1, 4 );
598   grpLayout->addWidget( myShowBtn,           2, 0 );
599   grpLayout->addWidget( myPublishBtn,        2, 1 );
600   grpLayout->addWidget( myBadMeshBtn,        2, 2 );
601   grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
602   grpLayout->setColumnStretch( 3, 1 );
603
604   // Hypothesis definition errors
605
606   myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
607   QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
608   myHypErrorGroupLayout->setMargin(MARGIN);
609   myHypErrorGroupLayout->setSpacing(SPACING);
610   myHypErrorLabel = new QLabel(myHypErrorGroup);
611   myHypErrorGroupLayout->addWidget(myHypErrorLabel);
612
613   // Memory Lack Label
614
615   myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
616   QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
617   myMemoryLackGroupLayout->setMargin(MARGIN);
618   myMemoryLackGroupLayout->setSpacing(SPACING);
619   QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
620   QFont bold = memLackLabel->font(); bold.setBold(true);
621   memLackLabel->setFont( bold );
622   memLackLabel->setMinimumWidth(300);
623   myMemoryLackGroupLayout->addWidget(memLackLabel);
624
625   // add all widgets to aFrame
626   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
627   aLay->setMargin( MARGIN );
628   aLay->setSpacing( SPACING );
629   aLay->addWidget( aPixGrp );
630   aLay->addWidget( nameBox );
631   aLay->addWidget( myBriefInfo );
632   aLay->addWidget( myFullInfo );
633   aLay->addWidget( myHypErrorGroup );
634   aLay->addWidget( myCompErrorGroup );
635   aLay->addWidget( myMemoryLackGroup );
636   aLay->setStretchFactor( myCompErrorGroup, 1 );
637
638   ((QPushButton*) button( OK ))->setDefault( true );
639
640   return aFrame;
641 }
642
643 //================================================================================
644 /*!
645  * \brief Constructor
646 */
647 //================================================================================
648
649 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
650   : SMESHGUI_Operation(), myCompDlg( 0 )
651 {
652   myTShapeDisplayer = new SMESH::TShapeDisplayer();
653   myBadMeshDisplayer = 0;
654
655   //myHelpFileName = "/files/about_meshes.htm"; // V3
656   myHelpFileName = "about_meshes_page.html"; // V4
657 }
658
659 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
660 {
661   LightApp_SelectionMgr* Sel = selectionMgr();
662   SALOME_ListIO selected; Sel->selectedObjects( selected );
663   Handle(SALOME_InteractiveObject) anIO = selected.First();
664   SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
665   return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
666 }
667
668 //================================================================================
669 /*!
670  * \brief Start operation
671  * \purpose Init dialog fields, connect signals and slots, show dialog
672  */
673 //================================================================================
674
675 void SMESHGUI_BaseComputeOp::startOperation()
676 {
677   // create compute dialog if not created before
678   computeDlg();
679
680   myMesh      = SMESH::SMESH_Mesh::_nil();
681   myMainShape = GEOM::GEOM_Object::_nil();
682
683   // check selection
684   LightApp_SelectionMgr *Sel = selectionMgr();
685   SALOME_ListIO selected; Sel->selectedObjects( selected );
686
687   int nbSel = selected.Extent();
688   if (nbSel != 1) {
689     SUIT_MessageBox::warning(desktop(),
690                              tr("SMESH_WRN_WARNING"),
691                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
692     onCancel();
693     return;
694   }
695
696   myIObject = selected.First();
697   myMesh = SMESH::GetMeshByIO(myIObject);
698   if (myMesh->_is_nil()) {
699     SUIT_MessageBox::warning(desktop(),
700                              tr("SMESH_WRN_WARNING"),
701                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
702     onCancel();
703     return;
704   }
705   myMainShape = myMesh->GetShapeToMesh();
706
707   SMESHGUI_Operation::startOperation();
708 }
709
710 //================================================================================
711 //================================================================================
712
713 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
714                                                          SMESH::SMESH_Mesh_var mesh,
715                                                          GEOM::GEOM_Object_var mainShape)
716 {
717   myResult = false;
718   myGen = gen;
719   myMesh = mesh;
720   myMainShape = mainShape;
721 }
722
723 void SMESHGUI_ComputeDlg_QThread::run()
724 {
725   myResult = myGen->Compute(myMesh, myMainShape);
726 }
727
728 bool SMESHGUI_ComputeDlg_QThread::result()
729 {
730   return myResult;
731 }
732
733 void SMESHGUI_ComputeDlg_QThread::cancel()
734 {
735   myGen->CancelCompute(myMesh, myMainShape);
736 }
737
738 //================================================================================
739 //================================================================================
740
741 SMESHGUI_ComputeDlg_QThreadQDialog::
742 SMESHGUI_ComputeDlg_QThreadQDialog(QWidget             * parent,
743                                    SMESH::SMESH_Gen_var  gen,
744                                    SMESH::SMESH_Mesh_var mesh,
745                                    GEOM::GEOM_Object_var mainShape)
746   : QDialog(parent,
747             Qt::WindowSystemMenuHint |
748             Qt::WindowCloseButtonHint |
749             Qt::Dialog |
750             Qt::WindowMaximizeButtonHint),
751     qthread(gen, mesh, mainShape)
752 {
753   // --
754   setWindowTitle(tr("TITLE"));
755   setMinimumWidth( 200 );
756
757   cancelButton = new QPushButton(tr("CANCEL"));
758   cancelButton->setDefault(true);
759   cancelButton->setCheckable(true);
760
761   QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
762   QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
763   nbNodesLabel = new QLabel("0", this );
764   nbElemsLabel = new QLabel("0", this );
765 #ifndef WIN32
766   QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
767   freeRAMLabel = new QLabel("", this );
768 #endif
769   progressBar  = new QProgressBar(this);
770   progressBar->setMinimum( 0 );
771   progressBar->setMaximum( 1000 );
772
773   QGridLayout* layout = new QGridLayout(this);
774   layout->setMargin( MARGIN );
775   layout->setSpacing( SPACING );
776   int row = 0;
777   layout->addWidget(nbNodesName,  row,   0);
778   layout->addWidget(nbNodesLabel, row++, 1);
779   layout->addWidget(nbElemsName,  row,   0);
780   layout->addWidget(nbElemsLabel, row++, 1);
781 #ifndef WIN32
782   layout->addWidget(freeRAMName,  row,   0);
783   layout->addWidget(freeRAMLabel, row++, 1);
784 #endif
785   layout->addWidget(progressBar,  row++, 0, 1, 2);
786   layout->addWidget(cancelButton, row++, 0, 1, 2);
787   adjustSize();
788   update();
789
790   connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
791   // --
792   startTimer(300); // millisecs
793   qthread.start();
794 }
795
796 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
797 {
798   return qthread.result();
799 }
800
801 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
802 {
803   qthread.cancel();
804   cancelButton->setText( tr("CANCELING"));
805   cancelButton->setEnabled(false);
806 }
807
808 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
809 {
810   if ( !cancelButton->isChecked() ) // not yet cancelled
811     progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
812
813   if(qthread.isFinished())
814   {
815     close();
816   }
817   else
818   {
819     nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
820     nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
821 #ifndef WIN32
822     struct sysinfo si;
823     const int err = sysinfo( &si );
824     if ( err )
825       freeRAMLabel->setText("");
826     else
827       freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
828                              ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
829 #endif
830   }
831   event->accept();
832 }
833
834 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
835 {
836   if(qthread.isRunning())
837   {
838       event->ignore();
839       return;
840     }
841   event->accept();
842 }
843
844 //================================================================================
845 /*!
846  * \brief computeMesh()
847 */
848 //================================================================================
849
850 void SMESHGUI_BaseComputeOp::computeMesh()
851 {
852   // COMPUTE MESH
853
854   SMESH::MemoryReserve aMemoryReserve;
855
856   SMESH::compute_error_array_var aCompErrors;
857   QString                        aHypErrors;
858
859   bool computeFailed = true, memoryLack = false;
860
861   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
862   if ( !aMeshSObj ) // IPAL 21340
863     return;
864   bool hasShape = myMesh->HasShapeToMesh();
865   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
866   if ( shapeOK )
867   {
868     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
869     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
870     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
871     if ( errors->length() > 0 ) {
872       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
873     }
874     if ( myMesh->HasModificationsToDiscard() && // issue 0020693
875          SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
876                                     tr( "FULL_RECOMPUTE_QUESTION" ),
877                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
878       myMesh->Clear();
879     SUIT_OverrideCursor aWaitCursor;
880     try {
881 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
882       OCC_CATCH_SIGNALS;
883 #endif
884       SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
885       qthreaddialog.exec();
886       computeFailed = !qthreaddialog.result();
887     }
888     catch(const SALOME::SALOME_Exception & S_ex) {
889       memoryLack = true;
890     }
891     try {
892 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
893       OCC_CATCH_SIGNALS;
894 #endif
895       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
896       // check if there are memory problems
897       for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
898         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
899     }
900     catch(const SALOME::SALOME_Exception & S_ex) {
901       memoryLack = true;
902     }
903
904     if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
905       memoryLack = true;
906     }
907
908     // NPAL16631: if ( !memoryLack )
909     {
910       SMESH::ModifiedMesh( aMeshSObj,
911                            !computeFailed && aHypErrors.isEmpty(),
912                            myMesh->NbNodes() == 0);
913       update( UF_ObjBrowser | UF_Model );
914
915       // SHOW MESH
916       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
917       SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
918       bool limitExceeded;
919       long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
920       int entities = SMESH_Actor::eAllEntity;
921       int hidden = 0;
922       long nbElements = 0;
923       if ( !memoryLack )
924       {
925         // List of objects that will be updated automatically
926         typedef QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > TListOf_IDSrc_SObj;
927         TListOf_IDSrc_SObj aListToUpdate;
928         SMESH::SMESH_IDSource_var aMeshObj =
929           SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
930         // put Mesh into list
931         aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aMeshObj, aMeshSObj ));
932         SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
933         // put SubMeshes into list
934         for ( CORBA::ULong i = 0; i < aSubMeshes->length(); i++ )
935         {
936           SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
937           if ( CORBA::is_nil( sm ) ) continue;
938           _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
939           if ( !smSObj ) continue;
940           SMESH::SMESH_IDSource_var aSubMeshObj =
941             SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
942           SMESH_Actor *anActor = SMESH::FindActorByObject( aSubMeshObj );
943           if ( anActor && anActor->GetVisibility() )
944             aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aSubMeshObj, smSObj ));
945         }
946         // put Groups into list
947         SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
948         for ( size_t i = 0; i < aGroups->length(); ++i )
949         {
950           SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
951           if ( CORBA::is_nil( aGrp ) ) continue;
952           SMESH::SMESH_Group_var         aStdGroup  = SMESH::SMESH_Group::_narrow( aGrp );
953           SMESH::SMESH_GroupOnGeom_var   aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGrp );
954           SMESH::SMESH_GroupOnFilter_var aFltGroup  = SMESH::SMESH_GroupOnFilter::_narrow( aGrp );
955           if ( !aStdGroup->_is_nil() ) continue; // don't update the standalone groups
956           _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
957           if ( !aGroupSO ) continue;
958           SMESH::SMESH_IDSource_var aGroupObj =
959             SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
960           SMESH_Actor *anActor = SMESH::FindActorByObject( aGroupObj );
961           if ( anActor && anActor->GetVisibility() )
962             aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aGroupObj, aGroupSO ));
963         }
964
965         // update mesh, sub-mesh and groups, if it's possible
966         TListOf_IDSrc_SObj::iterator anIter;
967         for ( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ )
968         {
969           SMESH::SMESH_Mesh_var aMesh =
970             SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
971
972           if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded,
973                                                &hidden, &nbElements ) )
974           {
975             try {
976               OCC_CATCH_SIGNALS;
977               bool toDisplay = false;
978               if ( !aMesh->_is_nil() ) // display only a mesh
979               {
980                 toDisplay = true;
981                 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
982                 if ( !anActor ) anActor = SMESH::CreateActor( (*anIter).second->GetStudy(),
983                                                               (*anIter).second->GetID().c_str(),
984                                                               /*clearLog =*/ true );
985                 if ( anActor ) // actor is not created for an empty mesh
986                 {
987                   anActor->SetEntityMode( entities );
988                   SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
989                 }
990               }
991               Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
992                 ( (*anIter).second->GetID().c_str(), "SMESH", (*anIter).second->GetName().c_str() );
993               SMESH::Update(anIO, toDisplay);
994
995               if ( limitExceeded && !aMesh->_is_nil() )
996               {
997                 QStringList hiddenMsg;
998                 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
999                 if ( hidden & SMESH_Actor::eEdges )      hiddenMsg << tr( "SMESH_EDGES" );
1000                 if ( hidden & SMESH_Actor::eFaces )      hiddenMsg << tr( "SMESH_FACES" );
1001                 if ( hidden & SMESH_Actor::eVolumes )    hiddenMsg << tr( "SMESH_VOLUMES" );
1002                 if ( hidden & SMESH_Actor::eBallElem )   hiddenMsg << tr( "SMESH_BALLS" );
1003                 SUIT_MessageBox::warning( desktop(),
1004                                           tr( "SMESH_WRN_WARNING" ),
1005                                           tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1006                                           arg( nbElements ).
1007                                           arg( limitSize ).
1008                                           arg( hiddenMsg.join(", ")));
1009               }
1010             }
1011             catch (...) {
1012 #ifdef _DEBUG_
1013               MESSAGE ( "Exception thrown during mesh visualization" );
1014 #endif
1015               if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1016                 SMESH::OnVisuException();
1017               }
1018               else {
1019                 memoryLack = true;
1020               }
1021             }
1022           }
1023           else if ( limitExceeded && !aMesh->_is_nil() )
1024           {
1025             SUIT_MessageBox::warning( desktop(),
1026                                       tr( "SMESH_WRN_WARNING" ),
1027                                       tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1028                                       arg( nbElements ).arg( limitSize ) );
1029           }
1030         }
1031       }
1032       if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1033       {
1034         SALOME_ListIO selected;
1035         selected.Append( myIObject );
1036         Sel->setSelectedObjects( selected );
1037       }
1038     }
1039   }
1040
1041   if ( memoryLack )
1042     aMemoryReserve.release();
1043
1044   myCompDlg->setWindowTitle
1045     ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1046
1047   // SHOW ERRORS
1048
1049   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1050   bool noHypoError = ( aHypErrors.isEmpty() );
1051
1052   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1053   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1054
1055   bool isShowResultDlg = true;
1056   switch( aNotifyMode ) {
1057   case 0: // show the mesh computation result dialog NEVER
1058     isShowResultDlg = false;
1059     commit();
1060     break;
1061   case 1: // show the mesh computation result dialog if there are some errors
1062     if ( memoryLack || !noCompError || !noHypoError )
1063       isShowResultDlg = true;
1064     else
1065     {
1066       isShowResultDlg = false;
1067       commit();
1068     }
1069     break;
1070   default: // show the result dialog after each mesh computation
1071     isShowResultDlg = true;
1072   }
1073
1074   // SHOW RESULTS
1075   if ( isShowResultDlg )
1076     showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1077 }
1078
1079 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1080                                                 const bool theNoCompError,
1081                                                 SMESH::compute_error_array_var& theCompErrors,
1082                                                 const bool theNoHypoError,
1083                                                 const QString& theHypErrors )
1084 {
1085   bool hasShape = myMesh->HasShapeToMesh();
1086   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1087   aCompDlg->myMemoryLackGroup->hide();
1088
1089   if ( theMemoryLack )
1090   {
1091     aCompDlg->myMemoryLackGroup->show();
1092     aCompDlg->myFullInfo->hide();
1093     aCompDlg->myBriefInfo->hide();
1094     aCompDlg->myHypErrorGroup->hide();
1095     aCompDlg->myCompErrorGroup->hide();
1096   }
1097   else if ( theNoCompError && theNoHypoError )
1098   {
1099     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1100     aCompDlg->myFullInfo->SetMeshInfo( aRes );
1101     aCompDlg->myFullInfo->show();
1102     aCompDlg->myBriefInfo->hide();
1103     aCompDlg->myHypErrorGroup->hide();
1104     aCompDlg->myCompErrorGroup->hide();
1105   }
1106   else
1107   {
1108     bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1109     for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1110       onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1111                        theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1112
1113     // full or brief mesh info
1114     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1115     if ( onlyWarnings ) {
1116       aCompDlg->myFullInfo->SetMeshInfo( aRes );
1117       aCompDlg->myFullInfo->show();
1118       aCompDlg->myBriefInfo->hide();
1119     } else {
1120       aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1121       aCompDlg->myBriefInfo->show();
1122       aCompDlg->myFullInfo->hide();
1123     }
1124
1125     // pbs of hypo dfinitions
1126     if ( theNoHypoError ) {
1127       aCompDlg->myHypErrorGroup->hide();
1128     } else {
1129       aCompDlg->myHypErrorGroup->show();
1130       aCompDlg->myHypErrorLabel->setText( theHypErrors );
1131     }
1132
1133     // table of errors
1134     if ( theNoCompError )
1135     {
1136       aCompDlg->myCompErrorGroup->hide();
1137     }
1138     else
1139     {
1140       aCompDlg->myCompErrorGroup->show();
1141
1142       if ( onlyWarnings )
1143         aCompDlg->myWarningLabel->show();
1144       else
1145         aCompDlg->myWarningLabel->hide();
1146
1147       if ( !hasShape ) {
1148         aCompDlg->myPublishBtn->hide();
1149         aCompDlg->myShowBtn->hide();
1150       }
1151       else {
1152         aCompDlg->myPublishBtn->show();
1153         aCompDlg->myShowBtn->show();
1154       }
1155
1156       // fill table of errors
1157       QTableWidget* tbl = aCompDlg->myTable;
1158       tbl->setRowCount( theCompErrors->length() );
1159       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1160       else             tbl->showColumn( COL_SHAPE );
1161       tbl->setColumnWidth( COL_ERROR, 200 );
1162
1163       bool hasBadMesh = false;
1164       for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1165       {
1166         SMESH::ComputeError & err = theCompErrors[ row ];
1167
1168         QString text = err.algoName.in();
1169         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1170         else tbl->item( row, COL_ALGO )->setText( text );
1171
1172         text = SMESH::errorText( err.code, err.comment.in() );
1173         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1174         else tbl->item( row, COL_ERROR )->setText( text );
1175
1176         text = QString("%1").arg( err.subShapeID );
1177         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1178         else tbl->item( row, COL_SHAPEID )->setText( text );
1179
1180         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1181         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1182         else tbl->item( row, COL_SHAPE )->setText( text );
1183
1184         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1185         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1186         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1187
1188         text = err.hasBadMesh ? "hasBadMesh" : "";
1189         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1190         else tbl->item( row, COL_BAD_MESH )->setText( text );
1191         if ( err.hasBadMesh ) hasBadMesh = true;
1192
1193         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1194         tbl->resizeRowToContents( row );
1195       }
1196       tbl->resizeColumnToContents( COL_ALGO );
1197       tbl->resizeColumnToContents( COL_SHAPE );
1198       tbl->setWordWrap( true );
1199
1200       if ( hasBadMesh ) {
1201         aCompDlg->myBadMeshBtn->show();
1202         aCompDlg->myBadMeshToGroupBtn->show();
1203       }
1204       else {
1205         aCompDlg->myBadMeshBtn->hide();
1206         aCompDlg->myBadMeshToGroupBtn->hide();
1207       }
1208       tbl->setCurrentCell(0,0);
1209       currentCellChanged(); // to update buttons
1210     }
1211   }
1212   // show dialog and wait, becase Compute can be invoked from Preview operation
1213   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1214   aCompDlg->show();
1215 }
1216
1217 //================================================================================
1218 /*!
1219  * \brief Stops operation
1220  */
1221 //================================================================================
1222
1223 void SMESHGUI_BaseComputeOp::stopOperation()
1224 {
1225   SMESHGUI_Operation::stopOperation();
1226   if ( myTShapeDisplayer )
1227     myTShapeDisplayer->SetVisibility( false );
1228   if ( myBadMeshDisplayer ) {
1229     myBadMeshDisplayer->SetVisibility( false );
1230     // delete it in order not to have problems at its destruction when the viewer
1231     // where it worked is dead due to e.g. study closing
1232     delete myBadMeshDisplayer;
1233     myBadMeshDisplayer = 0;
1234   }
1235   myIObject.Nullify();
1236 }
1237
1238 //================================================================================
1239 /*!
1240  * \brief publish selected sub-shape
1241  */
1242 //================================================================================
1243
1244 void SMESHGUI_BaseComputeOp::onPublishShape()
1245 {
1246   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1247   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1248
1249   QStringList entryList;
1250   QList<int> rows;
1251   SMESH::getSelectedRows( table(), rows );
1252   int row;
1253   foreach ( row, rows )
1254   {
1255     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1256     GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1257     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1258     {
1259       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1260       {
1261         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1262         SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, myMainShape,
1263                                                          name.toLatin1().data(),
1264                                                          GEOM::GEOM_Object::_nil());
1265         // look for myMainShape in the table
1266         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1267           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1268             if ( so->_is_nil() ) {
1269               CORBA::String_var name  = so->GetName();
1270               CORBA::String_var entry = so->GetID();
1271               QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1272               table()->item( r, COL_SHAPE     )->setText( shapeText );
1273               table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1274             }
1275             break;
1276           }
1277         }
1278         if ( curSub == 1 ) continue;
1279       }
1280       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1281       SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape,
1282                                                        name.toLatin1().data(), myMainShape);
1283       if ( !so->_is_nil() ) {
1284         CORBA::String_var name  = so->GetName();
1285         CORBA::String_var entry = so->GetID();
1286         QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1287         table()->item( row, COL_SHAPE     )->setText( shapeText );
1288         table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1289         entryList.push_back( entry.in() );
1290       }
1291     }
1292   }
1293   getSMESHGUI()->getApp()->updateObjectBrowser();
1294   getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1295
1296   currentCellChanged(); // to update buttons
1297 }
1298
1299 //================================================================================
1300 /*!
1301  * \brief show mesh elements preventing computation of a submesh of current row
1302  */
1303 //================================================================================
1304
1305 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1306 {
1307   myTShapeDisplayer->SetVisibility( false );
1308   QList<int> rows;
1309   if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1310     bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1311     if ( hasBadMesh ) {
1312       int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1313       SMESHGUI* gui = getSMESHGUI();
1314       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1315       SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1316       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1317       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1318       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1319       double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1320       double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1321       vtkProperty* prop = vtkProperty::New();
1322       prop->SetLineWidth( aLineWidth * 3 );
1323       prop->SetPointSize( aPointSize * 3 );
1324       prop->SetColor( 250, 0, 250 );
1325       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1326       myBadMeshDisplayer->SetData( aMeshData._retn() );
1327       prop->Delete();
1328     }
1329   }
1330 }
1331
1332 //================================================================================
1333 /*!
1334  * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1335  */
1336 //================================================================================
1337
1338 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1339 {
1340   QList<int> rows;
1341   SMESH::getSelectedRows( table(), rows );
1342   int row;
1343   foreach ( row, rows )
1344   {
1345     bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1346     if ( hasBadMesh ) {
1347       int     curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1348       QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1349       if ( grName.isEmpty() ) grName = "bad mesh";
1350       else                    grName = "bad mesh of " + grName;
1351       SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1352       SMESH::ListOfGroups_var groups
1353         ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1354       update( UF_ObjBrowser | UF_Model );
1355       if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1356       {
1357         QStringList anEntryList;
1358         for ( size_t i = 0; i < groups->length(); ++i )
1359           if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1360             anEntryList.append( so->GetID().c_str() );
1361
1362         if ( !anEntryList.isEmpty())
1363           anApp->browseObjects( anEntryList, true, false );
1364       }
1365     }
1366   }
1367 }
1368
1369 //================================================================================
1370 /*!
1371  * \brief SLOT called when a selected cell in table() changed
1372  */
1373 //================================================================================
1374
1375 void SMESHGUI_BaseComputeOp::currentCellChanged()
1376 {
1377   myTShapeDisplayer->SetVisibility( false );
1378   if ( myBadMeshDisplayer )
1379     myBadMeshDisplayer->SetVisibility( false );
1380
1381   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1382   QList<int> rows;
1383   int nbSelected = SMESH::getSelectedRows( table(), rows );
1384   int row;
1385   foreach ( row, rows )
1386   {
1387     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1388     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1389     if ( hasData && !isPublished )
1390       publishEnable = true;
1391
1392     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1393     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1394     if ( prsReady ) {
1395       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1396       showOnly = false;
1397     }
1398     else {
1399       showEnable = true;
1400     }
1401
1402     if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1403       hasBadMesh = true;
1404   }
1405   myCompDlg->myPublishBtn->setEnabled( publishEnable );
1406   myCompDlg->myShowBtn   ->setEnabled( showEnable );
1407   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1408   myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1409 }
1410
1411 //================================================================================
1412 /*!
1413  * \brief update preview
1414  */
1415 //================================================================================
1416
1417 void SMESHGUI_BaseComputeOp::onPreviewShape()
1418 {
1419   if ( myTShapeDisplayer )
1420   {
1421     SUIT_OverrideCursor aWaitCursor;
1422     QList<int> rows;
1423     SMESH::getSelectedRows( table(), rows );
1424
1425     bool showOnly = true;
1426     int row;
1427     foreach ( row, rows )
1428     {
1429       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1430       if ( curSub > 0 ) {
1431         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1432         showOnly = false;
1433       }
1434     }
1435     currentCellChanged(); // to update buttons
1436   }
1437 }
1438
1439 //================================================================================
1440 /*!
1441  * \brief Destructor
1442  */
1443 //================================================================================
1444
1445 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1446 {
1447   delete myCompDlg;
1448   myCompDlg = 0;
1449   delete myTShapeDisplayer;
1450   if ( myBadMeshDisplayer )
1451     delete myBadMeshDisplayer;
1452 }
1453
1454 //================================================================================
1455 /*!
1456  * \brief Gets dialog of compute operation
1457  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1458  */
1459 //================================================================================
1460
1461 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1462 {
1463   if ( !myCompDlg )
1464   {
1465     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1466     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1467     // connect signals and slots
1468     connect(myCompDlg->myShowBtn,           SIGNAL (clicked()), SLOT(onPreviewShape()));
1469     connect(myCompDlg->myPublishBtn,        SIGNAL (clicked()), SLOT(onPublishShape()));
1470     connect(myCompDlg->myBadMeshBtn,        SIGNAL (clicked()), SLOT(onShowBadMesh()));
1471     connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1472
1473     QTableWidget* aTable = me->table();
1474     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1475     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1476   }
1477   return myCompDlg;
1478 }
1479
1480 //================================================================================
1481 /*!
1482  * \brief returns from compute mesh result dialog
1483  */
1484 //================================================================================
1485
1486 bool SMESHGUI_BaseComputeOp::onApply()
1487 {
1488   return true;
1489 }
1490
1491 //================================================================================
1492 /*!
1493  * \brief Return a table
1494  */
1495 //================================================================================
1496
1497 QTableWidget* SMESHGUI_BaseComputeOp::table()
1498 {
1499   return myCompDlg->myTable;
1500 }
1501
1502
1503 //================================================================================
1504 /*!
1505  * \brief Constructor
1506 */
1507 //================================================================================
1508
1509 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1510  : SMESHGUI_BaseComputeOp()
1511 {
1512   myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1513 }
1514
1515
1516 //================================================================================
1517 /*!
1518  * \brief Desctructor
1519 */
1520 //================================================================================
1521
1522 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1523 {
1524 }
1525
1526 //================================================================================
1527 /*!
1528  * \brief perform it's intention action: compute mesh
1529  */
1530 //================================================================================
1531
1532 void SMESHGUI_ComputeOp::startOperation()
1533 {
1534   SMESHGUI_BaseComputeOp::startOperation();
1535   if (myMesh->_is_nil())
1536     return;
1537   computeMesh();
1538 }
1539
1540 //================================================================================
1541 /*!
1542  * \brief check the same operations on the same mesh
1543  */
1544 //================================================================================
1545
1546 bool SMESHGUI_BaseComputeOp::isValid(  SUIT_Operation* theOp  ) const
1547 {
1548   SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1549   bool ret = true;
1550   if ( !myMesh->_is_nil() && baseOp ) {
1551     SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1552     if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1553   }
1554   return ret;
1555 }
1556
1557 //================================================================================
1558 /*!
1559  * \brief Gets dialog of this operation
1560  * \retval LightApp_Dialog* - pointer to dialog of this operation
1561  */
1562 //================================================================================
1563
1564 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1565 {
1566   return computeDlg();
1567 }
1568
1569 //================================================================================
1570 /*!
1571  * \brief Constructor
1572  */
1573 //================================================================================
1574
1575 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1576   : SMESHGUI_BaseComputeOp(),
1577     myActiveDlg( 0 ),
1578     myDlg( 0 ),
1579     myPreviewDisplayer( 0 ),
1580     myOrderMgr( 0 )
1581 {
1582 }
1583
1584 //================================================================================
1585 /*!
1586  * \brief Destructor
1587  */
1588 //================================================================================
1589
1590 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1591 {
1592   delete myDlg;
1593   myDlg = 0;
1594   delete myOrderMgr;
1595   myOrderMgr = 0;
1596   myActiveDlg = 0;
1597   if ( myPreviewDisplayer )
1598     delete myPreviewDisplayer;
1599   myPreviewDisplayer = 0;
1600 }
1601
1602 //================================================================================
1603 /*!
1604  * \brief Gets current dialog of this operation
1605  * \retval LightApp_Dialog* - pointer to dialog of this operation
1606  */
1607 //================================================================================
1608
1609 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1610 {
1611   return myActiveDlg;
1612 }
1613
1614 //================================================================================
1615 /*!
1616  * \brief perform it's intention action: prepare data
1617  */
1618 //================================================================================
1619
1620 void SMESHGUI_PrecomputeOp::startOperation()
1621 {
1622   myHelpFileName = "constructing_meshes_page.html#preview_anchor"; // other anchor onCompute()
1623
1624   if ( !myDlg )
1625   {
1626     myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1627     
1628     // connect signals
1629     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1630     connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1631     connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1632   }
1633   myActiveDlg = myDlg;
1634
1635   // connect signal to compute dialog. which will be shown after Compute mesh operation
1636   SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1637   if ( cmpDlg )
1638   {
1639     // disconnect signals
1640     disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1641     disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1642     disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1643     disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1644     disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1645
1646     // connect signals
1647     if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1648       connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1649     if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1650       connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1651     if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1652       connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1653     if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1654       connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1655     if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1656       connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1657   }
1658
1659   SMESHGUI_BaseComputeOp::startOperation();
1660   if (myMesh->_is_nil())
1661     return;
1662
1663   if (myDlg->getPreviewMode() == -1)
1664   {
1665     // nothing to preview
1666     SUIT_MessageBox::warning(desktop(),
1667                              tr("SMESH_WRN_WARNING"),
1668                              tr("SMESH_WRN_NOTHING_PREVIEW"));
1669     onCancel();
1670     return;
1671   }
1672
1673   // disconnect slot from preview dialog to have Apply from results of compute operation only 
1674   disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1675   disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1676
1677   myDlg->show();
1678 }
1679
1680 //================================================================================
1681 /*!
1682  * \brief Stops operation
1683  */
1684 //================================================================================
1685
1686 void SMESHGUI_PrecomputeOp::stopOperation()
1687 {
1688   if ( myPreviewDisplayer )
1689   {
1690     myPreviewDisplayer->SetVisibility( false );
1691     delete myPreviewDisplayer;
1692     myPreviewDisplayer = 0;
1693   }
1694   myMapShapeId.clear();
1695   SMESHGUI_BaseComputeOp::stopOperation();
1696 }
1697
1698 //================================================================================
1699 /*!
1700  * \brief reinitialize dialog after operaiton become active again
1701  */
1702 //================================================================================
1703
1704 void SMESHGUI_PrecomputeOp::resumeOperation()
1705 {
1706   if ( myActiveDlg == myDlg )
1707     initDialog();
1708   SMESHGUI_BaseComputeOp::resumeOperation();
1709 }
1710
1711 //================================================================================
1712 /*!
1713  * \brief perform it's intention action: reinitialise dialog
1714  */
1715 //================================================================================
1716
1717 void SMESHGUI_PrecomputeOp::initDialog()
1718 {
1719   QList<int> modes;
1720
1721   QMap<int, int> modeMap;
1722   _PTR(SObject)  pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1723   getAssignedAlgos( pMesh, modeMap );
1724   if ( modeMap.contains( SMESH::DIM_3D ) )
1725   {
1726     if ( modeMap.contains( SMESH::DIM_2D ) )
1727       modes.append( SMESH::DIM_2D );
1728     if ( modeMap.contains( SMESH::DIM_1D ) )
1729       modes.append( SMESH::DIM_1D );
1730   }
1731   else if ( modeMap.contains( SMESH::DIM_2D ) )
1732   {
1733     if ( modeMap.contains( SMESH::DIM_1D ) )
1734       modes.append( SMESH::DIM_1D );
1735   }
1736
1737   myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1738   myOrderMgr->SetMesh( myMesh );
1739   bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1740   myDlg->getMeshOrderBox()->setVisible(isOrder);
1741   if ( !isOrder ) {
1742     delete myOrderMgr;
1743     myOrderMgr = 0;
1744   }
1745
1746   myDlg->setPreviewModes( modes );
1747 }
1748
1749 //================================================================================
1750 /*!
1751  * \brief detect asigned mesh algorithms
1752  */
1753 //================================================================================
1754
1755 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1756                                              QMap<int,int>& theModeMap)
1757 {
1758   if ( !theMesh ) return;
1759   _PTR(SObject)          aHypFolder;
1760   _PTR(GenericAttribute) anAttr;
1761   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1762   if ( theMesh->FindSubObject( aPart, aHypFolder ) )
1763   {
1764     _PTR(ChildIterator) anIter =
1765       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1766     for ( ; anIter->More(); anIter->Next() )
1767     {
1768       _PTR(SObject) anObj = anIter->Value();
1769       _PTR(SObject) aRefObj;
1770       if ( anObj->ReferencedObject( aRefObj ) )
1771         anObj = aRefObj;
1772       else
1773         continue;
1774
1775       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1776       {
1777         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1778         if ( CORBA::is_nil( aVar ) )
1779           continue;
1780
1781         SMESH::SMESH_Algo_var algo;
1782         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1783         {
1784           switch(dim) {
1785           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1786           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1787           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1788           default: break;
1789           }
1790           if ( !algo->_is_nil() )
1791           {
1792             theModeMap[ dim ] = 0;
1793             if ( theModeMap.size() == 3 )
1794               return;
1795             break;
1796           }
1797         }
1798       }
1799     }
1800   }
1801
1802   // check sub-meshes
1803   for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1804   {
1805     if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1806       continue;
1807
1808     _PTR(ChildIterator) anIter =
1809       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1810     for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1811     {
1812       _PTR(SObject) anObj = anIter->Value();
1813       _PTR(SObject) aRefObj;
1814       if ( anObj->ReferencedObject( aRefObj ) )
1815         anObj = aRefObj;
1816       else
1817         continue;
1818
1819       if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1820       {
1821         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1822         if ( CORBA::is_nil( aVar ) )
1823           continue;
1824
1825         SMESH::SMESH_Algo_var algo;
1826         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1827         {
1828           switch(dim) {
1829           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1830           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1831           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1832           default: break;
1833           }
1834           if ( !algo->_is_nil() )
1835           {
1836             theModeMap[ dim ] = 0;
1837             if ( theModeMap.size() == 3 )
1838               return;
1839             break;
1840           }
1841         }
1842       }
1843     }
1844   }
1845 }
1846
1847 //================================================================================
1848 /*!
1849  * \brief perform it's intention action: compute mesh
1850  */
1851 //================================================================================
1852
1853 void SMESHGUI_PrecomputeOp::onCompute()
1854 {
1855   myDlg->hide();
1856   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1857     myOrderMgr->SetMeshOrder();
1858   myMapShapeId.clear();
1859   myActiveDlg = computeDlg();
1860   myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1861   computeMesh();
1862 }
1863
1864 //================================================================================
1865 /*!
1866  * \brief perform it's intention action: compute mesh
1867  */
1868 //================================================================================
1869
1870 void SMESHGUI_PrecomputeOp::onCancel()
1871 {
1872   QObject* curDlg = sender();
1873   if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1874   {
1875     // return from error messages
1876     myDlg->show();
1877     return;
1878   }
1879
1880   bool isRestoreOrder = false;
1881   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
1882   {
1883     // ask to remove already computed mesh elements
1884     if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1885                                     tr( "CLEAR_SUBMESH_QUESTION" ),
1886                                     tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1887     {
1888       // remove all submeshes for collected shapes
1889       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1890       for ( ; it != myMapShapeId.constEnd(); ++it )
1891         myMesh->ClearSubMesh( it.key() );
1892       isRestoreOrder = true;
1893     }
1894   }
1895
1896   // return previous mesh order
1897   if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1898     if (!isRestoreOrder)
1899       isRestoreOrder = 
1900         (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1901                                     tr( "SMESH_REJECT_MESH_ORDER" ),
1902                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1903     if (isRestoreOrder)
1904       myOrderMgr->SetMeshOrder(myPrevOrder);
1905   }
1906
1907   delete myOrderMgr;
1908   myOrderMgr = 0;
1909
1910   myMapShapeId.clear();
1911   SMESHGUI_BaseComputeOp::onCancel();
1912 }
1913
1914 //================================================================================
1915 /*!
1916  * \brief perform it's intention action: preview mesh
1917  */
1918 //================================================================================
1919
1920 void SMESHGUI_PrecomputeOp::onPreview()
1921 {
1922   if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1923     return;
1924
1925   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1926   if ( !aMeshSObj )
1927     return;
1928
1929   // set modified submesh priority if any
1930   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1931     myOrderMgr->SetMeshOrder();
1932
1933   // Compute preview of mesh,
1934   // i.e. compute mesh till indicated dimension
1935   int dim = myDlg->getPreviewMode();
1936
1937   SMESH::MemoryReserve aMemoryReserve;
1938
1939   SMESH::compute_error_array_var aCompErrors;
1940   QString                        aHypErrors;
1941
1942   bool computeFailed = true, memoryLack = false;
1943
1944   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1945   aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1946
1947   SMESHGUI* gui = getSMESHGUI();
1948   SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1949   SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1950   if ( errors->length() > 0 ) {
1951     aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1952   }
1953
1954   SUIT_OverrideCursor aWaitCursor;
1955
1956   SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1957   if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1958   myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1959   
1960   SMESH::long_array_var aShapesId = new SMESH::long_array();
1961   try {
1962 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1963     OCC_CATCH_SIGNALS;
1964 #endif
1965       
1966     SMESH::MeshPreviewStruct_var previewData =
1967       gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1968
1969     SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1970     if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1971     {
1972       computeFailed = false;
1973       myPreviewDisplayer->SetData( previewRes );
1974       // append shape indeces with computed mesh entities
1975       for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1976         myMapShapeId[ aShapesId[ i ] ] = 0;
1977     }
1978     else
1979       myPreviewDisplayer->SetVisibility(false);
1980   }
1981   catch(const SALOME::SALOME_Exception & S_ex){
1982     memoryLack = true;
1983     myPreviewDisplayer->SetVisibility(false);
1984   }
1985
1986   try {
1987 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1988     OCC_CATCH_SIGNALS;
1989 #endif
1990     aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1991     // check if there are memory problems
1992     for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1993       memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1994   }
1995   catch(const SALOME::SALOME_Exception & S_ex){
1996     memoryLack = true;
1997   }
1998
1999   if ( memoryLack )
2000     aMemoryReserve.release();
2001
2002   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2003   bool noHypoError = ( aHypErrors.isEmpty() );
2004
2005   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2006   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2007
2008   bool isShowError = true;
2009   switch( aNotifyMode ) {
2010   case 0: // show the mesh computation result dialog NEVER
2011     isShowError = false;
2012     break;
2013   case 1: // show the mesh computation result dialog if there are some errors
2014   default: // show the result dialog after each mesh computation
2015     if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2016       isShowError = false;
2017     break;
2018   }
2019
2020   aWaitCursor.suspend();
2021   // SHOW ERRORS
2022   if ( isShowError )
2023   {
2024     myDlg->hide();
2025     aCompDlg->setWindowTitle
2026       ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2027     showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2028   }
2029 }
2030
2031
2032 //================================================================================
2033 /*!
2034  * \brief Constructor
2035 */
2036 //================================================================================
2037
2038 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2039  : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2040    myOrderBox(0)
2041 {
2042   setWindowTitle( tr( "CAPTION" ) );
2043
2044   setButtonText( OK, tr( "COMPUTE" ) );
2045   QFrame* main = mainFrame();
2046   main->setMinimumWidth( 300 );
2047
2048   QVBoxLayout* layout = new QVBoxLayout( main );
2049
2050   myOrderBox = new SMESHGUI_MeshOrderBox( main );
2051   layout->addWidget(myOrderBox);
2052
2053   QFrame* frame = new QFrame( main );
2054   layout->setMargin(0); layout->setSpacing(0);
2055   layout->addWidget( frame );
2056
2057   QHBoxLayout* frameLay = new QHBoxLayout( frame );
2058   frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2059   
2060   myPreviewMode = new QtxComboBox( frame );
2061   frameLay->addWidget( myPreviewMode );
2062
2063   myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2064   frameLay->addWidget( myPreviewBtn );
2065
2066   connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2067 }
2068
2069 //================================================================================
2070 /*!
2071  * \brief Destructor
2072 */
2073 //================================================================================
2074
2075 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2076 {
2077 }
2078
2079 //================================================================================
2080 /*!
2081  * \brief Sets available preview modes
2082 */
2083 //================================================================================
2084
2085 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2086 {
2087   myPreviewMode->clear();
2088   QList<int>::const_iterator it = theModes.constBegin();
2089   for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2090   {
2091     QString mode = QString( "PREVIEW_%1" ).arg( *it );
2092     myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2093     myPreviewMode->setId( i, *it );
2094   }
2095   myPreviewBtn->setEnabled( !theModes.isEmpty() );
2096 }
2097
2098 //================================================================================
2099 /*!
2100  * \brief Returns current preview mesh mode
2101 */
2102 //================================================================================
2103
2104 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2105 {
2106   return myPreviewMode->currentId();
2107 }
2108
2109 //================================================================================
2110 /*!
2111  * \brief Returns current preview mesh mode
2112 */
2113 //================================================================================
2114
2115 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2116 {
2117   return myOrderBox;
2118 }
2119
2120
2121 //================================================================================
2122 /*!
2123  * \brief Constructor
2124 */
2125 //================================================================================
2126
2127 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2128  : SMESHGUI_BaseComputeOp()
2129 {
2130   myHelpFileName = "constructing_meshes_page.html#evaluate_anchor";
2131 }
2132
2133
2134 //================================================================================
2135 /*!
2136  * \brief Desctructor
2137 */
2138 //================================================================================
2139
2140 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2141 {
2142 }
2143
2144 //================================================================================
2145 /*!
2146  * \brief perform it's intention action: compute mesh
2147  */
2148 //================================================================================
2149
2150 void SMESHGUI_EvaluateOp::startOperation()
2151 {
2152   SMESHGUI_BaseComputeOp::evaluateDlg();
2153   SMESHGUI_BaseComputeOp::startOperation();
2154   if (myMesh->_is_nil())
2155     return;
2156   evaluateMesh();
2157 }
2158
2159 //================================================================================
2160 /*!
2161  * \brief Gets dialog of this operation
2162  * \retval LightApp_Dialog* - pointer to dialog of this operation
2163  */
2164 //================================================================================
2165
2166 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2167 {
2168   return evaluateDlg();
2169 }
2170
2171 //================================================================================
2172 /*!
2173  * \brief evaluateMesh()
2174 */
2175 //================================================================================
2176
2177 void SMESHGUI_BaseComputeOp::evaluateMesh()
2178 {
2179   // EVALUATE MESH
2180
2181   SMESH::MemoryReserve aMemoryReserve;
2182
2183   SMESH::compute_error_array_var aCompErrors;
2184   QString                        aHypErrors;
2185
2186   bool evaluateFailed = true, memoryLack = false;
2187   SMESH::long_array_var aRes;
2188
2189   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2190   if ( !aMeshSObj ) //  IPAL21340
2191     return;
2192
2193   bool hasShape = myMesh->HasShapeToMesh();
2194   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2195   if ( shapeOK )
2196   {
2197     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2198     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2199     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2200     if ( errors->length() > 0 ) {
2201       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2202     }
2203     SUIT_OverrideCursor aWaitCursor;
2204     try {
2205 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2206       OCC_CATCH_SIGNALS;
2207 #endif
2208       aRes = gen->Evaluate(myMesh, myMainShape);
2209     }
2210     catch(const SALOME::SALOME_Exception & S_ex){
2211       memoryLack = true;
2212     }
2213
2214     try {
2215 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2216       OCC_CATCH_SIGNALS;
2217 #endif
2218       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2219     }
2220     catch(const SALOME::SALOME_Exception & S_ex){
2221       memoryLack = true;
2222     }
2223   }
2224
2225   if ( memoryLack )
2226     aMemoryReserve.release();
2227
2228   evaluateFailed =  ( aCompErrors->length() > 0 );
2229   myCompDlg->setWindowTitle
2230     ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2231
2232   // SHOW ERRORS
2233
2234   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2235   bool noHypoError = ( aHypErrors.isEmpty() );
2236
2237   //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2238   //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2239
2240   bool isShowResultDlg = true;
2241   //if( noHypoError )
2242   //switch( aNotifyMode ) {
2243   //case 0: // show the mesh computation result dialog NEVER
2244   //isShowResultDlg = false;
2245   //commit();
2246   //break;
2247   //case 1: // show the mesh computation result dialog if there are some errors
2248   //if ( memoryLack || !noHypoError )
2249   //  isShowResultDlg = true;
2250   //else
2251   //{
2252   //  isShowResultDlg = false;
2253   //  commit();
2254   //}
2255   //break;
2256   //default: // show the result dialog after each mesh computation
2257   //isShowResultDlg = true;
2258   //}
2259
2260   // SHOW RESULTS
2261   if ( isShowResultDlg )
2262     showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2263                         noHypoError, aHypErrors);
2264 }
2265
2266
2267 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2268                                                 const bool theMemoryLack,
2269                                                 const bool theNoCompError,
2270                                                 SMESH::compute_error_array_var& theCompErrors,
2271                                                 const bool theNoHypoError,
2272                                                 const QString& theHypErrors)
2273 {
2274   bool hasShape = myMesh->HasShapeToMesh();
2275   SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2276   aCompDlg->myMemoryLackGroup->hide();
2277
2278   if ( theMemoryLack )
2279   {
2280     aCompDlg->myMemoryLackGroup->show();
2281     aCompDlg->myFullInfo->hide();
2282     aCompDlg->myBriefInfo->hide();
2283     aCompDlg->myHypErrorGroup->hide();
2284     aCompDlg->myCompErrorGroup->hide();
2285   }
2286   else if ( theNoCompError && theNoHypoError )
2287   {
2288     aCompDlg->myFullInfo->SetMeshInfo( theRes );
2289     aCompDlg->myFullInfo->show();
2290     aCompDlg->myBriefInfo->hide();
2291     aCompDlg->myHypErrorGroup->hide();
2292     aCompDlg->myCompErrorGroup->hide();
2293   }
2294   else
2295   {
2296     QTableWidget* tbl = aCompDlg->myTable;
2297     aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2298     aCompDlg->myBriefInfo->show();
2299     aCompDlg->myFullInfo->hide();
2300
2301     if ( theNoHypoError ) {
2302       aCompDlg->myHypErrorGroup->hide();
2303     }
2304     else {
2305       aCompDlg->myHypErrorGroup->show();
2306       aCompDlg->myHypErrorLabel->setText( theHypErrors );
2307     }
2308
2309     if ( theNoCompError ) {
2310       aCompDlg->myCompErrorGroup->hide();
2311     }
2312     else {
2313       aCompDlg->myCompErrorGroup->show();
2314
2315       aCompDlg->myPublishBtn->hide();
2316       aCompDlg->myShowBtn->hide();
2317
2318       // fill table of errors
2319       tbl->setRowCount( theCompErrors->length() );
2320       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2321       else             tbl->showColumn( COL_SHAPE );
2322       tbl->setColumnWidth( COL_ERROR, 200 );
2323
2324       bool hasBadMesh = false;
2325       for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2326       {
2327         SMESH::ComputeError & err = theCompErrors[ row ];
2328
2329         QString text = err.algoName.in();
2330         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2331         else tbl->item( row, COL_ALGO )->setText( text );
2332
2333         text = SMESH::errorText( err.code, err.comment.in() );
2334         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2335         else tbl->item( row, COL_ERROR )->setText( text );
2336
2337         text = QString("%1").arg( err.subShapeID );
2338         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2339         else tbl->item( row, COL_SHAPEID )->setText( text );
2340
2341         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2342         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2343         else tbl->item( row, COL_SHAPE )->setText( text );
2344
2345         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2346         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2347         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2348
2349         text = err.hasBadMesh ? "hasBadMesh" : "";
2350         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2351         else tbl->item( row, COL_BAD_MESH )->setText( text );
2352         if ( err.hasBadMesh ) hasBadMesh = true;
2353
2354         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2355         tbl->resizeRowToContents( row );
2356       }
2357       tbl->resizeColumnToContents( COL_ALGO );
2358       tbl->resizeColumnToContents( COL_SHAPE );
2359       tbl->setWordWrap( true );
2360
2361       if ( hasBadMesh )
2362       {
2363         aCompDlg->myBadMeshBtn->show();
2364         aCompDlg->myBadMeshToGroupBtn->show();
2365       }
2366       else
2367       {
2368         aCompDlg->myBadMeshBtn->hide();
2369         aCompDlg->myBadMeshToGroupBtn->hide();
2370       }
2371       tbl->setCurrentCell(0,0);
2372       currentCellChanged(); // to update buttons
2373     }
2374   }
2375   // show dialog and wait, becase Compute can be invoked from Preview operation
2376   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2377   aCompDlg->show();
2378 }
2379
2380
2381 //================================================================================
2382 /*!
2383  * \brief Gets dialog of evaluate operation
2384  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2385  */
2386 //================================================================================
2387
2388 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2389 {
2390   if ( !myCompDlg )
2391   {
2392     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2393     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2394     // connect signals and slots
2395     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
2396     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2397     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2398     QTableWidget* aTable = me->table();
2399     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2400     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
2401   }
2402   return myCompDlg;
2403 }
2404