Salome HOME
8627f72fcd7d0f0604cc2ee5569bf299f8e2795b
[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 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
579   myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
580 #else
581   myTable->horizontalHeader()->setSectionResizeMode( COL_ERROR, QHeaderView::Interactive );
582 #endif
583   myTable->setWordWrap( true );
584   myTable->horizontalHeader()->setStretchLastSection( true );
585   myTable->setMinimumWidth( 500 );
586
587   QStringList headers;
588   headers << tr( "COL_ALGO_HEADER" );
589   headers << tr( "COL_SHAPE_HEADER" );
590   headers << tr( "COL_ERROR_HEADER" );
591   headers << tr( "COL_SHAPEID_HEADER" );
592   headers << tr( "COL_PUBLISHED_HEADER" );
593
594   myTable->setHorizontalHeaderLabels( headers );
595
596   // layouting
597   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
598   grpLayout->setSpacing(SPACING);
599   grpLayout->setMargin(MARGIN);
600   grpLayout->addWidget( myWarningLabel,      0, 0, 1, 4 );
601   grpLayout->addWidget( myTable,             1, 0, 1, 4 );
602   grpLayout->addWidget( myShowBtn,           2, 0 );
603   grpLayout->addWidget( myPublishBtn,        2, 1 );
604   grpLayout->addWidget( myBadMeshBtn,        2, 2 );
605   grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
606   grpLayout->setColumnStretch( 3, 1 );
607
608   // Hypothesis definition errors
609
610   myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
611   QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
612   myHypErrorGroupLayout->setMargin(MARGIN);
613   myHypErrorGroupLayout->setSpacing(SPACING);
614   myHypErrorLabel = new QLabel(myHypErrorGroup);
615   myHypErrorGroupLayout->addWidget(myHypErrorLabel);
616
617   // Memory Lack Label
618
619   myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
620   QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
621   myMemoryLackGroupLayout->setMargin(MARGIN);
622   myMemoryLackGroupLayout->setSpacing(SPACING);
623   QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
624   QFont bold = memLackLabel->font(); bold.setBold(true);
625   memLackLabel->setFont( bold );
626   memLackLabel->setMinimumWidth(300);
627   myMemoryLackGroupLayout->addWidget(memLackLabel);
628
629   // add all widgets to aFrame
630   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
631   aLay->setMargin( MARGIN );
632   aLay->setSpacing( SPACING );
633   aLay->addWidget( aPixGrp );
634   aLay->addWidget( nameBox );
635   aLay->addWidget( myBriefInfo );
636   aLay->addWidget( myFullInfo );
637   aLay->addWidget( myHypErrorGroup );
638   aLay->addWidget( myCompErrorGroup );
639   aLay->addWidget( myMemoryLackGroup );
640   aLay->setStretchFactor( myCompErrorGroup, 1 );
641
642   ((QPushButton*) button( OK ))->setDefault( true );
643
644   return aFrame;
645 }
646
647 //================================================================================
648 /*!
649  * \brief Constructor
650 */
651 //================================================================================
652
653 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
654   : SMESHGUI_Operation(), myCompDlg( 0 )
655 {
656   myTShapeDisplayer = new SMESH::TShapeDisplayer();
657   myBadMeshDisplayer = 0;
658
659   //myHelpFileName = "/files/about_meshes.htm"; // V3
660   myHelpFileName = "about_meshes_page.html"; // V4
661 }
662
663 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
664 {
665   LightApp_SelectionMgr* Sel = selectionMgr();
666   SALOME_ListIO selected; Sel->selectedObjects( selected );
667   Handle(SALOME_InteractiveObject) anIO = selected.First();
668   SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
669   return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
670 }
671
672 //================================================================================
673 /*!
674  * \brief Start operation
675  * \purpose Init dialog fields, connect signals and slots, show dialog
676  */
677 //================================================================================
678
679 void SMESHGUI_BaseComputeOp::startOperation()
680 {
681   // create compute dialog if not created before
682   computeDlg();
683
684   myMesh      = SMESH::SMESH_Mesh::_nil();
685   myMainShape = GEOM::GEOM_Object::_nil();
686
687   // check selection
688   LightApp_SelectionMgr *Sel = selectionMgr();
689   SALOME_ListIO selected; Sel->selectedObjects( selected );
690
691   int nbSel = selected.Extent();
692   if (nbSel != 1) {
693     SUIT_MessageBox::warning(desktop(),
694                              tr("SMESH_WRN_WARNING"),
695                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
696     onCancel();
697     return;
698   }
699
700   myIObject = selected.First();
701   myMesh = SMESH::GetMeshByIO(myIObject);
702   if (myMesh->_is_nil()) {
703     SUIT_MessageBox::warning(desktop(),
704                              tr("SMESH_WRN_WARNING"),
705                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
706     onCancel();
707     return;
708   }
709   myMainShape = myMesh->GetShapeToMesh();
710
711   SMESHGUI_Operation::startOperation();
712 }
713
714 //================================================================================
715 //================================================================================
716
717 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
718                                                          SMESH::SMESH_Mesh_var mesh,
719                                                          GEOM::GEOM_Object_var mainShape)
720 {
721   myResult = false;
722   myGen = gen;
723   myMesh = mesh;
724   myMainShape = mainShape;
725 }
726
727 void SMESHGUI_ComputeDlg_QThread::run()
728 {
729   myResult = myGen->Compute(myMesh, myMainShape);
730 }
731
732 bool SMESHGUI_ComputeDlg_QThread::result()
733 {
734   return myResult;
735 }
736
737 void SMESHGUI_ComputeDlg_QThread::cancel()
738 {
739   myGen->CancelCompute(myMesh, myMainShape);
740 }
741
742 //================================================================================
743 //================================================================================
744
745 SMESHGUI_ComputeDlg_QThreadQDialog::
746 SMESHGUI_ComputeDlg_QThreadQDialog(QWidget             * parent,
747                                    SMESH::SMESH_Gen_var  gen,
748                                    SMESH::SMESH_Mesh_var mesh,
749                                    GEOM::GEOM_Object_var mainShape)
750   : QDialog(parent,
751             Qt::WindowSystemMenuHint |
752             Qt::WindowCloseButtonHint |
753             Qt::Dialog |
754             Qt::WindowMaximizeButtonHint),
755     qthread(gen, mesh, mainShape)
756 {
757   // --
758   setWindowTitle(tr("TITLE"));
759   setMinimumWidth( 200 );
760
761   cancelButton = new QPushButton(tr("CANCEL"));
762   cancelButton->setDefault(true);
763   cancelButton->setCheckable(true);
764
765   QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
766   QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
767   nbNodesLabel = new QLabel("0", this );
768   nbElemsLabel = new QLabel("0", this );
769 #ifndef WIN32
770   QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
771   freeRAMLabel = new QLabel("", this );
772 #endif
773   progressBar  = new QProgressBar(this);
774   progressBar->setMinimum( 0 );
775   progressBar->setMaximum( 1000 );
776
777   QGridLayout* layout = new QGridLayout(this);
778   layout->setMargin( MARGIN );
779   layout->setSpacing( SPACING );
780   int row = 0;
781   layout->addWidget(nbNodesName,  row,   0);
782   layout->addWidget(nbNodesLabel, row++, 1);
783   layout->addWidget(nbElemsName,  row,   0);
784   layout->addWidget(nbElemsLabel, row++, 1);
785 #ifndef WIN32
786   layout->addWidget(freeRAMName,  row,   0);
787   layout->addWidget(freeRAMLabel, row++, 1);
788 #endif
789   layout->addWidget(progressBar,  row++, 0, 1, 2);
790   layout->addWidget(cancelButton, row++, 0, 1, 2);
791   adjustSize();
792   update();
793
794   connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
795   // --
796   startTimer(300); // millisecs
797   qthread.start();
798 }
799
800 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
801 {
802   return qthread.result();
803 }
804
805 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
806 {
807   qthread.cancel();
808   cancelButton->setText( tr("CANCELING"));
809   cancelButton->setEnabled(false);
810 }
811
812 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
813 {
814   if ( !cancelButton->isChecked() ) // not yet cancelled
815     progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
816
817   if(qthread.isFinished())
818   {
819     close();
820   }
821   else
822   {
823     nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
824     nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
825 #ifndef WIN32
826     struct sysinfo si;
827     const int err = sysinfo( &si );
828     if ( err )
829       freeRAMLabel->setText("");
830     else
831       freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
832                              ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
833 #endif
834   }
835   event->accept();
836 }
837
838 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
839 {
840   if(qthread.isRunning())
841   {
842       event->ignore();
843       return;
844     }
845   event->accept();
846 }
847
848 //================================================================================
849 /*!
850  * \brief computeMesh()
851 */
852 //================================================================================
853
854 void SMESHGUI_BaseComputeOp::computeMesh()
855 {
856   // COMPUTE MESH
857
858   SMESH::MemoryReserve aMemoryReserve;
859
860   SMESH::compute_error_array_var aCompErrors;
861   QString                        aHypErrors;
862
863   bool computeFailed = true, memoryLack = false;
864
865   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
866   if ( !aMeshSObj ) // IPAL 21340
867     return;
868   bool hasShape = myMesh->HasShapeToMesh();
869   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
870   if ( shapeOK )
871   {
872     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
873     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
874     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
875     if ( errors->length() > 0 ) {
876       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
877     }
878     if ( myMesh->HasModificationsToDiscard() && // issue 0020693
879          SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
880                                     tr( "FULL_RECOMPUTE_QUESTION" ),
881                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
882       myMesh->Clear();
883     SUIT_OverrideCursor aWaitCursor;
884     try {
885 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
886       OCC_CATCH_SIGNALS;
887 #endif
888       SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
889       qthreaddialog.exec();
890       computeFailed = !qthreaddialog.result();
891     }
892     catch(const SALOME::SALOME_Exception & S_ex) {
893       memoryLack = true;
894     }
895     try {
896 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
897       OCC_CATCH_SIGNALS;
898 #endif
899       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
900       // check if there are memory problems
901       for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
902         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
903     }
904     catch(const SALOME::SALOME_Exception & S_ex) {
905       memoryLack = true;
906     }
907
908     if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
909       memoryLack = true;
910     }
911
912     // NPAL16631: if ( !memoryLack )
913     {
914       SMESH::ModifiedMesh( aMeshSObj,
915                            !computeFailed && aHypErrors.isEmpty(),
916                            myMesh->NbNodes() == 0);
917       update( UF_ObjBrowser | UF_Model );
918
919       // SHOW MESH
920       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
921       SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
922       bool limitExceeded;
923       long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
924       int entities = SMESH_Actor::eAllEntity;
925       int hidden = 0;
926       long nbElements = 0;
927       if ( !memoryLack )
928       {
929         // List of objects that will be updated automatically
930         typedef QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > TListOf_IDSrc_SObj;
931         TListOf_IDSrc_SObj aListToUpdate;
932         SMESH::SMESH_IDSource_var aMeshObj =
933           SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
934         // put Mesh into list
935         aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aMeshObj, aMeshSObj ));
936         SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
937         // put SubMeshes into list
938         for ( CORBA::ULong i = 0; i < aSubMeshes->length(); i++ )
939         {
940           SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
941           if ( CORBA::is_nil( sm ) ) continue;
942           _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
943           if ( !smSObj ) continue;
944           SMESH::SMESH_IDSource_var aSubMeshObj =
945             SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
946           SMESH_Actor *anActor = SMESH::FindActorByObject( aSubMeshObj );
947           if ( anActor && anActor->GetVisibility() )
948             aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aSubMeshObj, smSObj ));
949         }
950         // put Groups into list
951         SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
952         for ( size_t i = 0; i < aGroups->length(); ++i )
953         {
954           SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
955           if ( CORBA::is_nil( aGrp ) ) continue;
956           SMESH::SMESH_Group_var  aStdGroup  = SMESH::SMESH_Group::_narrow( aGrp );
957           if ( !aStdGroup->_is_nil() ) continue; // don't update standalone groups
958           _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
959           if ( !aGroupSO ) continue;
960           SMESH::SMESH_IDSource_var aGroupObj =
961             SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
962           SMESH_Actor *anActor = SMESH::FindActorByObject( aGroupObj );
963           if ( anActor && anActor->GetVisibility() )
964             aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aGroupObj, aGroupSO ));
965         }
966
967         // update mesh, sub-mesh and groups, if it's possible
968         TListOf_IDSrc_SObj::iterator anIter;
969         for ( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ )
970         {
971           SMESH::SMESH_Mesh_var aMesh =
972             SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
973
974           if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded,
975                                                &hidden, &nbElements ) )
976           {
977             try {
978               OCC_CATCH_SIGNALS;
979               bool toDisplay = false;
980               if ( !aMesh->_is_nil() ) // display only a mesh
981               {
982                 toDisplay = true;
983                 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
984                 if ( !anActor ) anActor = SMESH::CreateActor( (*anIter).second->GetStudy(),
985                                                               (*anIter).second->GetID().c_str(),
986                                                               /*clearLog =*/ true );
987                 if ( anActor ) // actor is not created for an empty mesh
988                 {
989                   anActor->SetEntityMode( entities );
990                   SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
991                 }
992               }
993               Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
994                 ( (*anIter).second->GetID().c_str(), "SMESH", (*anIter).second->GetName().c_str() );
995               SMESH::Update(anIO, toDisplay);
996
997               if ( limitExceeded && !aMesh->_is_nil() )
998               {
999                 QStringList hiddenMsg;
1000                 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1001                 if ( hidden & SMESH_Actor::eEdges )      hiddenMsg << tr( "SMESH_EDGES" );
1002                 if ( hidden & SMESH_Actor::eFaces )      hiddenMsg << tr( "SMESH_FACES" );
1003                 if ( hidden & SMESH_Actor::eVolumes )    hiddenMsg << tr( "SMESH_VOLUMES" );
1004                 if ( hidden & SMESH_Actor::eBallElem )   hiddenMsg << tr( "SMESH_BALLS" );
1005                 SUIT_MessageBox::warning( desktop(),
1006                                           tr( "SMESH_WRN_WARNING" ),
1007                                           tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1008                                           arg( nbElements ).
1009                                           arg( limitSize ).
1010                                           arg( hiddenMsg.join(", ")));
1011               }
1012             }
1013             catch (...) {
1014 #ifdef _DEBUG_
1015               MESSAGE ( "Exception thrown during mesh visualization" );
1016 #endif
1017               if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1018                 SMESH::OnVisuException();
1019               }
1020               else {
1021                 memoryLack = true;
1022               }
1023             }
1024           }
1025           else if ( limitExceeded && !aMesh->_is_nil() )
1026           {
1027             SUIT_MessageBox::warning( desktop(),
1028                                       tr( "SMESH_WRN_WARNING" ),
1029                                       tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1030                                       arg( nbElements ).arg( limitSize ) );
1031           }
1032         }
1033       }
1034       if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1035       {
1036         SALOME_ListIO selected;
1037         selected.Append( myIObject );
1038         Sel->setSelectedObjects( selected );
1039       }
1040     }
1041   }
1042
1043   if ( memoryLack )
1044     aMemoryReserve.release();
1045
1046   myCompDlg->setWindowTitle
1047     ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1048
1049   // SHOW ERRORS
1050
1051   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1052   bool noHypoError = ( aHypErrors.isEmpty() );
1053
1054   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1055   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1056
1057   bool isShowResultDlg = true;
1058   switch( aNotifyMode ) {
1059   case 0: // show the mesh computation result dialog NEVER
1060     isShowResultDlg = false;
1061     commit();
1062     break;
1063   case 1: // show the mesh computation result dialog if there are some errors
1064     if ( memoryLack || !noCompError || !noHypoError )
1065       isShowResultDlg = true;
1066     else
1067     {
1068       isShowResultDlg = false;
1069       commit();
1070     }
1071     break;
1072   default: // show the result dialog after each mesh computation
1073     isShowResultDlg = true;
1074   }
1075
1076   // SHOW RESULTS
1077   if ( isShowResultDlg )
1078     showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1079 }
1080
1081 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1082                                                 const bool theNoCompError,
1083                                                 SMESH::compute_error_array_var& theCompErrors,
1084                                                 const bool theNoHypoError,
1085                                                 const QString& theHypErrors )
1086 {
1087   bool hasShape = myMesh->HasShapeToMesh();
1088   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1089   aCompDlg->myMemoryLackGroup->hide();
1090
1091   if ( theMemoryLack )
1092   {
1093     aCompDlg->myMemoryLackGroup->show();
1094     aCompDlg->myFullInfo->hide();
1095     aCompDlg->myBriefInfo->hide();
1096     aCompDlg->myHypErrorGroup->hide();
1097     aCompDlg->myCompErrorGroup->hide();
1098   }
1099   else if ( theNoCompError && theNoHypoError )
1100   {
1101     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1102     aCompDlg->myFullInfo->SetMeshInfo( aRes );
1103     aCompDlg->myFullInfo->show();
1104     aCompDlg->myBriefInfo->hide();
1105     aCompDlg->myHypErrorGroup->hide();
1106     aCompDlg->myCompErrorGroup->hide();
1107   }
1108   else
1109   {
1110     bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1111     for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1112       onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1113                        theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1114
1115     // full or brief mesh info
1116     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1117     if ( onlyWarnings ) {
1118       aCompDlg->myFullInfo->SetMeshInfo( aRes );
1119       aCompDlg->myFullInfo->show();
1120       aCompDlg->myBriefInfo->hide();
1121     } else {
1122       aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1123       aCompDlg->myBriefInfo->show();
1124       aCompDlg->myFullInfo->hide();
1125     }
1126
1127     // pbs of hypo dfinitions
1128     if ( theNoHypoError ) {
1129       aCompDlg->myHypErrorGroup->hide();
1130     } else {
1131       aCompDlg->myHypErrorGroup->show();
1132       aCompDlg->myHypErrorLabel->setText( theHypErrors );
1133     }
1134
1135     // table of errors
1136     if ( theNoCompError )
1137     {
1138       aCompDlg->myCompErrorGroup->hide();
1139     }
1140     else
1141     {
1142       aCompDlg->myCompErrorGroup->show();
1143
1144       if ( onlyWarnings )
1145         aCompDlg->myWarningLabel->show();
1146       else
1147         aCompDlg->myWarningLabel->hide();
1148
1149       if ( !hasShape ) {
1150         aCompDlg->myPublishBtn->hide();
1151         aCompDlg->myShowBtn->hide();
1152       }
1153       else {
1154         aCompDlg->myPublishBtn->show();
1155         aCompDlg->myShowBtn->show();
1156       }
1157
1158       // fill table of errors
1159       QTableWidget* tbl = aCompDlg->myTable;
1160       tbl->setRowCount( theCompErrors->length() );
1161       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1162       else             tbl->showColumn( COL_SHAPE );
1163       tbl->setColumnWidth( COL_ERROR, 200 );
1164
1165       bool hasBadMesh = false;
1166       for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1167       {
1168         SMESH::ComputeError & err = theCompErrors[ row ];
1169
1170         QString text = err.algoName.in();
1171         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1172         else tbl->item( row, COL_ALGO )->setText( text );
1173
1174         text = SMESH::errorText( err.code, err.comment.in() );
1175         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1176         else tbl->item( row, COL_ERROR )->setText( text );
1177
1178         text = QString("%1").arg( err.subShapeID );
1179         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1180         else tbl->item( row, COL_SHAPEID )->setText( text );
1181
1182         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1183         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1184         else tbl->item( row, COL_SHAPE )->setText( text );
1185
1186         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1187         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1188         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1189
1190         text = err.hasBadMesh ? "hasBadMesh" : "";
1191         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1192         else tbl->item( row, COL_BAD_MESH )->setText( text );
1193         if ( err.hasBadMesh ) hasBadMesh = true;
1194
1195         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1196         tbl->resizeRowToContents( row );
1197       }
1198       tbl->resizeColumnToContents( COL_ALGO );
1199       tbl->resizeColumnToContents( COL_SHAPE );
1200       tbl->setWordWrap( true );
1201
1202       if ( hasBadMesh ) {
1203         aCompDlg->myBadMeshBtn->show();
1204         aCompDlg->myBadMeshToGroupBtn->show();
1205       }
1206       else {
1207         aCompDlg->myBadMeshBtn->hide();
1208         aCompDlg->myBadMeshToGroupBtn->hide();
1209       }
1210       tbl->setCurrentCell(0,0);
1211       currentCellChanged(); // to update buttons
1212     }
1213   }
1214   // show dialog and wait, becase Compute can be invoked from Preview operation
1215   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1216   aCompDlg->show();
1217 }
1218
1219 //================================================================================
1220 /*!
1221  * \brief Stops operation
1222  */
1223 //================================================================================
1224
1225 void SMESHGUI_BaseComputeOp::stopOperation()
1226 {
1227   SMESHGUI_Operation::stopOperation();
1228   if ( myTShapeDisplayer )
1229     myTShapeDisplayer->SetVisibility( false );
1230   if ( myBadMeshDisplayer ) {
1231     myBadMeshDisplayer->SetVisibility( false );
1232     // delete it in order not to have problems at its destruction when the viewer
1233     // where it worked is dead due to e.g. study closing
1234     delete myBadMeshDisplayer;
1235     myBadMeshDisplayer = 0;
1236   }
1237   myIObject.Nullify();
1238 }
1239
1240 //================================================================================
1241 /*!
1242  * \brief publish selected sub-shape
1243  */
1244 //================================================================================
1245
1246 void SMESHGUI_BaseComputeOp::onPublishShape()
1247 {
1248   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1249   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1250
1251   QStringList entryList;
1252   QList<int> rows;
1253   SMESH::getSelectedRows( table(), rows );
1254   int row;
1255   foreach ( row, rows )
1256   {
1257     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1258     GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1259     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1260     {
1261       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1262       {
1263         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1264         SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, myMainShape,
1265                                                          name.toLatin1().data(),
1266                                                          GEOM::GEOM_Object::_nil());
1267         // look for myMainShape in the table
1268         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1269           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1270             if ( so->_is_nil() ) {
1271               CORBA::String_var name  = so->GetName();
1272               CORBA::String_var entry = so->GetID();
1273               QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1274               table()->item( r, COL_SHAPE     )->setText( shapeText );
1275               table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1276             }
1277             break;
1278           }
1279         }
1280         if ( curSub == 1 ) continue;
1281       }
1282       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1283       SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape,
1284                                                        name.toLatin1().data(), myMainShape);
1285       if ( !so->_is_nil() ) {
1286         CORBA::String_var name  = so->GetName();
1287         CORBA::String_var entry = so->GetID();
1288         QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1289         table()->item( row, COL_SHAPE     )->setText( shapeText );
1290         table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1291         entryList.push_back( entry.in() );
1292       }
1293     }
1294   }
1295   getSMESHGUI()->getApp()->updateObjectBrowser();
1296   getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1297
1298   currentCellChanged(); // to update buttons
1299 }
1300
1301 //================================================================================
1302 /*!
1303  * \brief show mesh elements preventing computation of a submesh of current row
1304  */
1305 //================================================================================
1306
1307 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1308 {
1309   myTShapeDisplayer->SetVisibility( false );
1310   QList<int> rows;
1311   if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1312     bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1313     if ( hasBadMesh ) {
1314       int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1315       SMESHGUI* gui = getSMESHGUI();
1316       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1317       SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1318       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1319       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1320       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1321       double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1322       double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1323       vtkProperty* prop = vtkProperty::New();
1324       prop->SetLineWidth( aLineWidth * 3 );
1325       prop->SetPointSize( aPointSize * 3 );
1326       prop->SetColor( 250, 0, 250 );
1327       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1328       myBadMeshDisplayer->SetData( aMeshData._retn() );
1329       prop->Delete();
1330     }
1331   }
1332 }
1333
1334 //================================================================================
1335 /*!
1336  * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1337  */
1338 //================================================================================
1339
1340 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1341 {
1342   QList<int> rows;
1343   SMESH::getSelectedRows( table(), rows );
1344   int row;
1345   foreach ( row, rows )
1346   {
1347     bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1348     if ( hasBadMesh ) {
1349       int     curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1350       QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1351       if ( grName.isEmpty() ) grName = "bad mesh";
1352       else                    grName = "bad mesh of " + grName;
1353       SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1354       SMESH::ListOfGroups_var groups
1355         ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1356       update( UF_ObjBrowser | UF_Model );
1357       if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1358       {
1359         QStringList anEntryList;
1360         for ( size_t i = 0; i < groups->length(); ++i )
1361           if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1362             anEntryList.append( so->GetID().c_str() );
1363
1364         if ( !anEntryList.isEmpty())
1365           anApp->browseObjects( anEntryList, true, false );
1366       }
1367     }
1368   }
1369 }
1370
1371 //================================================================================
1372 /*!
1373  * \brief SLOT called when a selected cell in table() changed
1374  */
1375 //================================================================================
1376
1377 void SMESHGUI_BaseComputeOp::currentCellChanged()
1378 {
1379   myTShapeDisplayer->SetVisibility( false );
1380   if ( myBadMeshDisplayer )
1381     myBadMeshDisplayer->SetVisibility( false );
1382
1383   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1384   QList<int> rows;
1385   int nbSelected = SMESH::getSelectedRows( table(), rows );
1386   int row;
1387   foreach ( row, rows )
1388   {
1389     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1390     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1391     if ( hasData && !isPublished )
1392       publishEnable = true;
1393
1394     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1395     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1396     if ( prsReady ) {
1397       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1398       showOnly = false;
1399     }
1400     else {
1401       showEnable = true;
1402     }
1403
1404     if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1405       hasBadMesh = true;
1406   }
1407   myCompDlg->myPublishBtn->setEnabled( publishEnable );
1408   myCompDlg->myShowBtn   ->setEnabled( showEnable );
1409   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1410   myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1411 }
1412
1413 //================================================================================
1414 /*!
1415  * \brief update preview
1416  */
1417 //================================================================================
1418
1419 void SMESHGUI_BaseComputeOp::onPreviewShape()
1420 {
1421   if ( myTShapeDisplayer )
1422   {
1423     SUIT_OverrideCursor aWaitCursor;
1424     QList<int> rows;
1425     SMESH::getSelectedRows( table(), rows );
1426
1427     bool showOnly = true;
1428     int row;
1429     foreach ( row, rows )
1430     {
1431       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1432       if ( curSub > 0 ) {
1433         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1434         showOnly = false;
1435       }
1436     }
1437     currentCellChanged(); // to update buttons
1438   }
1439 }
1440
1441 //================================================================================
1442 /*!
1443  * \brief Destructor
1444  */
1445 //================================================================================
1446
1447 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1448 {
1449   delete myCompDlg;
1450   myCompDlg = 0;
1451   delete myTShapeDisplayer;
1452   if ( myBadMeshDisplayer )
1453     delete myBadMeshDisplayer;
1454 }
1455
1456 //================================================================================
1457 /*!
1458  * \brief Gets dialog of compute operation
1459  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1460  */
1461 //================================================================================
1462
1463 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1464 {
1465   if ( !myCompDlg )
1466   {
1467     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1468     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1469     // connect signals and slots
1470     connect(myCompDlg->myShowBtn,           SIGNAL (clicked()), SLOT(onPreviewShape()));
1471     connect(myCompDlg->myPublishBtn,        SIGNAL (clicked()), SLOT(onPublishShape()));
1472     connect(myCompDlg->myBadMeshBtn,        SIGNAL (clicked()), SLOT(onShowBadMesh()));
1473     connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1474
1475     QTableWidget* aTable = me->table();
1476     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1477     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1478   }
1479   return myCompDlg;
1480 }
1481
1482 //================================================================================
1483 /*!
1484  * \brief returns from compute mesh result dialog
1485  */
1486 //================================================================================
1487
1488 bool SMESHGUI_BaseComputeOp::onApply()
1489 {
1490   return true;
1491 }
1492
1493 //================================================================================
1494 /*!
1495  * \brief Return a table
1496  */
1497 //================================================================================
1498
1499 QTableWidget* SMESHGUI_BaseComputeOp::table()
1500 {
1501   return myCompDlg->myTable;
1502 }
1503
1504
1505 //================================================================================
1506 /*!
1507  * \brief Constructor
1508 */
1509 //================================================================================
1510
1511 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1512  : SMESHGUI_BaseComputeOp()
1513 {
1514   myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1515 }
1516
1517
1518 //================================================================================
1519 /*!
1520  * \brief Desctructor
1521 */
1522 //================================================================================
1523
1524 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1525 {
1526 }
1527
1528 //================================================================================
1529 /*!
1530  * \brief perform it's intention action: compute mesh
1531  */
1532 //================================================================================
1533
1534 void SMESHGUI_ComputeOp::startOperation()
1535 {
1536   SMESHGUI_BaseComputeOp::startOperation();
1537   if (myMesh->_is_nil())
1538     return;
1539   computeMesh();
1540 }
1541
1542 //================================================================================
1543 /*!
1544  * \brief check the same operations on the same mesh
1545  */
1546 //================================================================================
1547
1548 bool SMESHGUI_BaseComputeOp::isValid(  SUIT_Operation* theOp  ) const
1549 {
1550   SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1551   bool ret = true;
1552   if ( !myMesh->_is_nil() && baseOp ) {
1553     SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1554     if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1555   }
1556   return ret;
1557 }
1558
1559 //================================================================================
1560 /*!
1561  * \brief Gets dialog of this operation
1562  * \retval LightApp_Dialog* - pointer to dialog of this operation
1563  */
1564 //================================================================================
1565
1566 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1567 {
1568   return computeDlg();
1569 }
1570
1571 //================================================================================
1572 /*!
1573  * \brief Constructor
1574  */
1575 //================================================================================
1576
1577 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1578   : SMESHGUI_BaseComputeOp(),
1579     myActiveDlg( 0 ),
1580     myDlg( 0 ),
1581     myPreviewDisplayer( 0 ),
1582     myOrderMgr( 0 )
1583 {
1584 }
1585
1586 //================================================================================
1587 /*!
1588  * \brief Destructor
1589  */
1590 //================================================================================
1591
1592 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1593 {
1594   delete myDlg;
1595   myDlg = 0;
1596   delete myOrderMgr;
1597   myOrderMgr = 0;
1598   myActiveDlg = 0;
1599   if ( myPreviewDisplayer )
1600     delete myPreviewDisplayer;
1601   myPreviewDisplayer = 0;
1602 }
1603
1604 //================================================================================
1605 /*!
1606  * \brief Gets current dialog of this operation
1607  * \retval LightApp_Dialog* - pointer to dialog of this operation
1608  */
1609 //================================================================================
1610
1611 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1612 {
1613   return myActiveDlg;
1614 }
1615
1616 //================================================================================
1617 /*!
1618  * \brief perform it's intention action: prepare data
1619  */
1620 //================================================================================
1621
1622 void SMESHGUI_PrecomputeOp::startOperation()
1623 {
1624   myHelpFileName = "constructing_meshes_page.html#preview_anchor"; // other anchor onCompute()
1625
1626   if ( !myDlg )
1627   {
1628     myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1629     
1630     // connect signals
1631     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1632     connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1633     connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1634   }
1635   myActiveDlg = myDlg;
1636
1637   // connect signal to compute dialog. which will be shown after Compute mesh operation
1638   SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1639   if ( cmpDlg )
1640   {
1641     // disconnect signals
1642     disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1643     disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1644     disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1645     disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1646     disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1647
1648     // connect signals
1649     if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1650       connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1651     if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1652       connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1653     if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1654       connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1655     if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1656       connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1657     if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1658       connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1659   }
1660
1661   SMESHGUI_BaseComputeOp::startOperation();
1662   if (myMesh->_is_nil())
1663     return;
1664
1665   if (myDlg->getPreviewMode() == -1)
1666   {
1667     // nothing to preview
1668     SUIT_MessageBox::warning(desktop(),
1669                              tr("SMESH_WRN_WARNING"),
1670                              tr("SMESH_WRN_NOTHING_PREVIEW"));
1671     onCancel();
1672     return;
1673   }
1674
1675   // disconnect slot from preview dialog to have Apply from results of compute operation only 
1676   disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1677   disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1678
1679   myDlg->show();
1680 }
1681
1682 //================================================================================
1683 /*!
1684  * \brief Stops operation
1685  */
1686 //================================================================================
1687
1688 void SMESHGUI_PrecomputeOp::stopOperation()
1689 {
1690   if ( myPreviewDisplayer )
1691   {
1692     myPreviewDisplayer->SetVisibility( false );
1693     delete myPreviewDisplayer;
1694     myPreviewDisplayer = 0;
1695   }
1696   myMapShapeId.clear();
1697   SMESHGUI_BaseComputeOp::stopOperation();
1698 }
1699
1700 //================================================================================
1701 /*!
1702  * \brief reinitialize dialog after operaiton become active again
1703  */
1704 //================================================================================
1705
1706 void SMESHGUI_PrecomputeOp::resumeOperation()
1707 {
1708   if ( myActiveDlg == myDlg )
1709     initDialog();
1710   SMESHGUI_BaseComputeOp::resumeOperation();
1711 }
1712
1713 //================================================================================
1714 /*!
1715  * \brief perform it's intention action: reinitialise dialog
1716  */
1717 //================================================================================
1718
1719 void SMESHGUI_PrecomputeOp::initDialog()
1720 {
1721   QList<int> modes;
1722
1723   QMap<int, int> modeMap;
1724   _PTR(SObject)  pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1725   getAssignedAlgos( pMesh, modeMap );
1726   if ( modeMap.contains( SMESH::DIM_3D ) )
1727   {
1728     if ( modeMap.contains( SMESH::DIM_2D ) )
1729       modes.append( SMESH::DIM_2D );
1730     if ( modeMap.contains( SMESH::DIM_1D ) )
1731       modes.append( SMESH::DIM_1D );
1732   }
1733   else if ( modeMap.contains( SMESH::DIM_2D ) )
1734   {
1735     if ( modeMap.contains( SMESH::DIM_1D ) )
1736       modes.append( SMESH::DIM_1D );
1737   }
1738
1739   myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1740   myOrderMgr->SetMesh( myMesh );
1741   bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1742   myDlg->getMeshOrderBox()->setVisible(isOrder);
1743   if ( !isOrder ) {
1744     delete myOrderMgr;
1745     myOrderMgr = 0;
1746   }
1747
1748   myDlg->setPreviewModes( modes );
1749 }
1750
1751 //================================================================================
1752 /*!
1753  * \brief detect asigned mesh algorithms
1754  */
1755 //================================================================================
1756
1757 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1758                                              QMap<int,int>& theModeMap)
1759 {
1760   if ( !theMesh ) return;
1761   _PTR(SObject)          aHypFolder;
1762   _PTR(GenericAttribute) anAttr;
1763   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1764   if ( theMesh->FindSubObject( aPart, aHypFolder ) )
1765   {
1766     _PTR(ChildIterator) anIter =
1767       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1768     for ( ; anIter->More(); anIter->Next() )
1769     {
1770       _PTR(SObject) anObj = anIter->Value();
1771       _PTR(SObject) aRefObj;
1772       if ( anObj->ReferencedObject( aRefObj ) )
1773         anObj = aRefObj;
1774       else
1775         continue;
1776
1777       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1778       {
1779         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1780         if ( CORBA::is_nil( aVar ) )
1781           continue;
1782
1783         SMESH::SMESH_Algo_var algo;
1784         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1785         {
1786           switch(dim) {
1787           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1788           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1789           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1790           default: break;
1791           }
1792           if ( !algo->_is_nil() )
1793           {
1794             theModeMap[ dim ] = 0;
1795             if ( theModeMap.size() == 3 )
1796               return;
1797             break;
1798           }
1799         }
1800       }
1801     }
1802   }
1803
1804   // check sub-meshes
1805   for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1806   {
1807     if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1808       continue;
1809
1810     _PTR(ChildIterator) anIter =
1811       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1812     for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1813     {
1814       _PTR(SObject) anObj = anIter->Value();
1815       _PTR(SObject) aRefObj;
1816       if ( anObj->ReferencedObject( aRefObj ) )
1817         anObj = aRefObj;
1818       else
1819         continue;
1820
1821       if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1822       {
1823         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1824         if ( CORBA::is_nil( aVar ) )
1825           continue;
1826
1827         SMESH::SMESH_Algo_var algo;
1828         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1829         {
1830           switch(dim) {
1831           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1832           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1833           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1834           default: break;
1835           }
1836           if ( !algo->_is_nil() )
1837           {
1838             theModeMap[ dim ] = 0;
1839             if ( theModeMap.size() == 3 )
1840               return;
1841             break;
1842           }
1843         }
1844       }
1845     }
1846   }
1847 }
1848
1849 //================================================================================
1850 /*!
1851  * \brief perform it's intention action: compute mesh
1852  */
1853 //================================================================================
1854
1855 void SMESHGUI_PrecomputeOp::onCompute()
1856 {
1857   myDlg->hide();
1858   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1859     myOrderMgr->SetMeshOrder();
1860   myMapShapeId.clear();
1861   myActiveDlg = computeDlg();
1862   myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1863   computeMesh();
1864 }
1865
1866 //================================================================================
1867 /*!
1868  * \brief perform it's intention action: compute mesh
1869  */
1870 //================================================================================
1871
1872 void SMESHGUI_PrecomputeOp::onCancel()
1873 {
1874   QObject* curDlg = sender();
1875   if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1876   {
1877     // return from error messages
1878     myDlg->show();
1879     return;
1880   }
1881
1882   bool isRestoreOrder = false;
1883   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
1884   {
1885     // ask to remove already computed mesh elements
1886     if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1887                                     tr( "CLEAR_SUBMESH_QUESTION" ),
1888                                     tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1889     {
1890       // remove all submeshes for collected shapes
1891       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1892       for ( ; it != myMapShapeId.constEnd(); ++it )
1893         myMesh->ClearSubMesh( it.key() );
1894       isRestoreOrder = true;
1895     }
1896   }
1897
1898   // return previous mesh order
1899   if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1900     if (!isRestoreOrder)
1901       isRestoreOrder = 
1902         (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1903                                     tr( "SMESH_REJECT_MESH_ORDER" ),
1904                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1905     if (isRestoreOrder)
1906       myOrderMgr->SetMeshOrder(myPrevOrder);
1907   }
1908
1909   delete myOrderMgr;
1910   myOrderMgr = 0;
1911
1912   myMapShapeId.clear();
1913   SMESHGUI_BaseComputeOp::onCancel();
1914 }
1915
1916 //================================================================================
1917 /*!
1918  * \brief perform it's intention action: preview mesh
1919  */
1920 //================================================================================
1921
1922 void SMESHGUI_PrecomputeOp::onPreview()
1923 {
1924   if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1925     return;
1926
1927   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1928   if ( !aMeshSObj )
1929     return;
1930
1931   // set modified submesh priority if any
1932   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1933     myOrderMgr->SetMeshOrder();
1934
1935   // Compute preview of mesh,
1936   // i.e. compute mesh till indicated dimension
1937   int dim = myDlg->getPreviewMode();
1938
1939   SMESH::MemoryReserve aMemoryReserve;
1940
1941   SMESH::compute_error_array_var aCompErrors;
1942   QString                        aHypErrors;
1943
1944   bool computeFailed = true, memoryLack = false;
1945
1946   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1947   aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1948
1949   SMESHGUI* gui = getSMESHGUI();
1950   SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1951   SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1952   if ( errors->length() > 0 ) {
1953     aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1954   }
1955
1956   SUIT_OverrideCursor aWaitCursor;
1957
1958   SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1959   if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1960   myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1961   
1962   SMESH::long_array_var aShapesId = new SMESH::long_array();
1963   try {
1964 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1965     OCC_CATCH_SIGNALS;
1966 #endif
1967       
1968     SMESH::MeshPreviewStruct_var previewData =
1969       gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1970
1971     SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1972     if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1973     {
1974       computeFailed = false;
1975       myPreviewDisplayer->SetData( previewRes );
1976       // append shape indeces with computed mesh entities
1977       for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1978         myMapShapeId[ aShapesId[ i ] ] = 0;
1979     }
1980     else
1981       myPreviewDisplayer->SetVisibility(false);
1982   }
1983   catch(const SALOME::SALOME_Exception & S_ex){
1984     memoryLack = true;
1985     myPreviewDisplayer->SetVisibility(false);
1986   }
1987
1988   try {
1989 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1990     OCC_CATCH_SIGNALS;
1991 #endif
1992     aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1993     // check if there are memory problems
1994     for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1995       memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1996   }
1997   catch(const SALOME::SALOME_Exception & S_ex){
1998     memoryLack = true;
1999   }
2000
2001   if ( memoryLack )
2002     aMemoryReserve.release();
2003
2004   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2005   bool noHypoError = ( aHypErrors.isEmpty() );
2006
2007   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2008   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2009
2010   bool isShowError = true;
2011   switch( aNotifyMode ) {
2012   case 0: // show the mesh computation result dialog NEVER
2013     isShowError = false;
2014     break;
2015   case 1: // show the mesh computation result dialog if there are some errors
2016   default: // show the result dialog after each mesh computation
2017     if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2018       isShowError = false;
2019     break;
2020   }
2021
2022   aWaitCursor.suspend();
2023   // SHOW ERRORS
2024   if ( isShowError )
2025   {
2026     myDlg->hide();
2027     aCompDlg->setWindowTitle
2028       ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2029     showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2030   }
2031 }
2032
2033
2034 //================================================================================
2035 /*!
2036  * \brief Constructor
2037 */
2038 //================================================================================
2039
2040 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2041  : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2042    myOrderBox(0)
2043 {
2044   setWindowTitle( tr( "CAPTION" ) );
2045
2046   setButtonText( OK, tr( "COMPUTE" ) );
2047   QFrame* main = mainFrame();
2048   main->setMinimumWidth( 300 );
2049
2050   QVBoxLayout* layout = new QVBoxLayout( main );
2051
2052   myOrderBox = new SMESHGUI_MeshOrderBox( main );
2053   layout->addWidget(myOrderBox);
2054
2055   QFrame* frame = new QFrame( main );
2056   layout->setMargin(0); layout->setSpacing(0);
2057   layout->addWidget( frame );
2058
2059   QHBoxLayout* frameLay = new QHBoxLayout( frame );
2060   frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2061   
2062   myPreviewMode = new QtxComboBox( frame );
2063   frameLay->addWidget( myPreviewMode );
2064
2065   myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2066   frameLay->addWidget( myPreviewBtn );
2067
2068   connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2069 }
2070
2071 //================================================================================
2072 /*!
2073  * \brief Destructor
2074 */
2075 //================================================================================
2076
2077 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2078 {
2079 }
2080
2081 //================================================================================
2082 /*!
2083  * \brief Sets available preview modes
2084 */
2085 //================================================================================
2086
2087 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2088 {
2089   myPreviewMode->clear();
2090   QList<int>::const_iterator it = theModes.constBegin();
2091   for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2092   {
2093     QString mode = QString( "PREVIEW_%1" ).arg( *it );
2094     myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2095     myPreviewMode->setId( i, *it );
2096   }
2097   myPreviewBtn->setEnabled( !theModes.isEmpty() );
2098 }
2099
2100 //================================================================================
2101 /*!
2102  * \brief Returns current preview mesh mode
2103 */
2104 //================================================================================
2105
2106 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2107 {
2108   return myPreviewMode->currentId().toInt();
2109 }
2110
2111 //================================================================================
2112 /*!
2113  * \brief Returns current preview mesh mode
2114 */
2115 //================================================================================
2116
2117 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2118 {
2119   return myOrderBox;
2120 }
2121
2122
2123 //================================================================================
2124 /*!
2125  * \brief Constructor
2126 */
2127 //================================================================================
2128
2129 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2130  : SMESHGUI_BaseComputeOp()
2131 {
2132   myHelpFileName = "constructing_meshes_page.html#evaluate_anchor";
2133 }
2134
2135
2136 //================================================================================
2137 /*!
2138  * \brief Desctructor
2139 */
2140 //================================================================================
2141
2142 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2143 {
2144 }
2145
2146 //================================================================================
2147 /*!
2148  * \brief perform it's intention action: compute mesh
2149  */
2150 //================================================================================
2151
2152 void SMESHGUI_EvaluateOp::startOperation()
2153 {
2154   SMESHGUI_BaseComputeOp::evaluateDlg();
2155   SMESHGUI_BaseComputeOp::startOperation();
2156   if (myMesh->_is_nil())
2157     return;
2158   evaluateMesh();
2159 }
2160
2161 //================================================================================
2162 /*!
2163  * \brief Gets dialog of this operation
2164  * \retval LightApp_Dialog* - pointer to dialog of this operation
2165  */
2166 //================================================================================
2167
2168 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2169 {
2170   return evaluateDlg();
2171 }
2172
2173 //================================================================================
2174 /*!
2175  * \brief evaluateMesh()
2176 */
2177 //================================================================================
2178
2179 void SMESHGUI_BaseComputeOp::evaluateMesh()
2180 {
2181   // EVALUATE MESH
2182
2183   SMESH::MemoryReserve aMemoryReserve;
2184
2185   SMESH::compute_error_array_var aCompErrors;
2186   QString                        aHypErrors;
2187
2188   bool evaluateFailed = true, memoryLack = false;
2189   SMESH::long_array_var aRes;
2190
2191   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2192   if ( !aMeshSObj ) //  IPAL21340
2193     return;
2194
2195   bool hasShape = myMesh->HasShapeToMesh();
2196   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2197   if ( shapeOK )
2198   {
2199     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2200     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2201     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2202     if ( errors->length() > 0 ) {
2203       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2204     }
2205     SUIT_OverrideCursor aWaitCursor;
2206     try {
2207 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2208       OCC_CATCH_SIGNALS;
2209 #endif
2210       aRes = gen->Evaluate(myMesh, myMainShape);
2211     }
2212     catch(const SALOME::SALOME_Exception & S_ex){
2213       memoryLack = true;
2214     }
2215
2216     try {
2217 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2218       OCC_CATCH_SIGNALS;
2219 #endif
2220       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2221     }
2222     catch(const SALOME::SALOME_Exception & S_ex){
2223       memoryLack = true;
2224     }
2225   }
2226
2227   if ( memoryLack )
2228     aMemoryReserve.release();
2229
2230   evaluateFailed =  ( aCompErrors->length() > 0 );
2231   myCompDlg->setWindowTitle
2232     ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2233
2234   // SHOW ERRORS
2235
2236   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2237   bool noHypoError = ( aHypErrors.isEmpty() );
2238
2239   //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2240   //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2241
2242   bool isShowResultDlg = true;
2243   //if( noHypoError )
2244   //switch( aNotifyMode ) {
2245   //case 0: // show the mesh computation result dialog NEVER
2246   //isShowResultDlg = false;
2247   //commit();
2248   //break;
2249   //case 1: // show the mesh computation result dialog if there are some errors
2250   //if ( memoryLack || !noHypoError )
2251   //  isShowResultDlg = true;
2252   //else
2253   //{
2254   //  isShowResultDlg = false;
2255   //  commit();
2256   //}
2257   //break;
2258   //default: // show the result dialog after each mesh computation
2259   //isShowResultDlg = true;
2260   //}
2261
2262   // SHOW RESULTS
2263   if ( isShowResultDlg )
2264     showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2265                         noHypoError, aHypErrors);
2266 }
2267
2268
2269 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2270                                                 const bool theMemoryLack,
2271                                                 const bool theNoCompError,
2272                                                 SMESH::compute_error_array_var& theCompErrors,
2273                                                 const bool theNoHypoError,
2274                                                 const QString& theHypErrors)
2275 {
2276   bool hasShape = myMesh->HasShapeToMesh();
2277   SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2278   aCompDlg->myMemoryLackGroup->hide();
2279
2280   if ( theMemoryLack )
2281   {
2282     aCompDlg->myMemoryLackGroup->show();
2283     aCompDlg->myFullInfo->hide();
2284     aCompDlg->myBriefInfo->hide();
2285     aCompDlg->myHypErrorGroup->hide();
2286     aCompDlg->myCompErrorGroup->hide();
2287   }
2288   else if ( theNoCompError && theNoHypoError )
2289   {
2290     aCompDlg->myFullInfo->SetMeshInfo( theRes );
2291     aCompDlg->myFullInfo->show();
2292     aCompDlg->myBriefInfo->hide();
2293     aCompDlg->myHypErrorGroup->hide();
2294     aCompDlg->myCompErrorGroup->hide();
2295   }
2296   else
2297   {
2298     QTableWidget* tbl = aCompDlg->myTable;
2299     aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2300     aCompDlg->myBriefInfo->show();
2301     aCompDlg->myFullInfo->hide();
2302
2303     if ( theNoHypoError ) {
2304       aCompDlg->myHypErrorGroup->hide();
2305     }
2306     else {
2307       aCompDlg->myHypErrorGroup->show();
2308       aCompDlg->myHypErrorLabel->setText( theHypErrors );
2309     }
2310
2311     if ( theNoCompError ) {
2312       aCompDlg->myCompErrorGroup->hide();
2313     }
2314     else {
2315       aCompDlg->myCompErrorGroup->show();
2316
2317       aCompDlg->myPublishBtn->hide();
2318       aCompDlg->myShowBtn->hide();
2319
2320       // fill table of errors
2321       tbl->setRowCount( theCompErrors->length() );
2322       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2323       else             tbl->showColumn( COL_SHAPE );
2324       tbl->setColumnWidth( COL_ERROR, 200 );
2325
2326       bool hasBadMesh = false;
2327       for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2328       {
2329         SMESH::ComputeError & err = theCompErrors[ row ];
2330
2331         QString text = err.algoName.in();
2332         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2333         else tbl->item( row, COL_ALGO )->setText( text );
2334
2335         text = SMESH::errorText( err.code, err.comment.in() );
2336         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2337         else tbl->item( row, COL_ERROR )->setText( text );
2338
2339         text = QString("%1").arg( err.subShapeID );
2340         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2341         else tbl->item( row, COL_SHAPEID )->setText( text );
2342
2343         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2344         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2345         else tbl->item( row, COL_SHAPE )->setText( text );
2346
2347         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2348         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2349         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2350
2351         text = err.hasBadMesh ? "hasBadMesh" : "";
2352         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2353         else tbl->item( row, COL_BAD_MESH )->setText( text );
2354         if ( err.hasBadMesh ) hasBadMesh = true;
2355
2356         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2357         tbl->resizeRowToContents( row );
2358       }
2359       tbl->resizeColumnToContents( COL_ALGO );
2360       tbl->resizeColumnToContents( COL_SHAPE );
2361       tbl->setWordWrap( true );
2362
2363       if ( hasBadMesh )
2364       {
2365         aCompDlg->myBadMeshBtn->show();
2366         aCompDlg->myBadMeshToGroupBtn->show();
2367       }
2368       else
2369       {
2370         aCompDlg->myBadMeshBtn->hide();
2371         aCompDlg->myBadMeshToGroupBtn->hide();
2372       }
2373       tbl->setCurrentCell(0,0);
2374       currentCellChanged(); // to update buttons
2375     }
2376   }
2377   // show dialog and wait, becase Compute can be invoked from Preview operation
2378   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2379   aCompDlg->show();
2380 }
2381
2382
2383 //================================================================================
2384 /*!
2385  * \brief Gets dialog of evaluate operation
2386  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2387  */
2388 //================================================================================
2389
2390 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2391 {
2392   if ( !myCompDlg )
2393   {
2394     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2395     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2396     // connect signals and slots
2397     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
2398     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2399     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2400     QTableWidget* aTable = me->table();
2401     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2402     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
2403   }
2404   return myCompDlg;
2405 }
2406