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