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