Salome HOME
BUG: SMESH::GetGEOMGen() returns GEOM_Engine instead of SHAPERSTUDY
[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               SMESH::UpdateView( SMESH::eDisplay, entry.c_str() );
998
999               if ( SVTK_ViewWindow* vtkWnd = SMESH::GetVtkViewWindow(SMESH::GetActiveWindow() ))
1000                 if ( vtkWnd->getRenderer() )
1001                   vtkWnd->getRenderer()->ResetCameraClippingRange();
1002
1003               if ( limitExceeded && !aMesh->_is_nil() )
1004               {
1005                 QStringList hiddenMsg;
1006                 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1007                 if ( hidden & SMESH_Actor::eEdges )      hiddenMsg << tr( "SMESH_EDGES" );
1008                 if ( hidden & SMESH_Actor::eFaces )      hiddenMsg << tr( "SMESH_FACES" );
1009                 if ( hidden & SMESH_Actor::eVolumes )    hiddenMsg << tr( "SMESH_VOLUMES" );
1010                 if ( hidden & SMESH_Actor::eBallElem )   hiddenMsg << tr( "SMESH_BALLS" );
1011                 SUIT_MessageBox::warning( desktop(),
1012                                           tr( "SMESH_WRN_WARNING" ),
1013                                           tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1014                                           arg( nbElements ).
1015                                           arg( limitSize ).
1016                                           arg( hiddenMsg.join(", ")));
1017               }
1018             }
1019             catch (...) {
1020 #ifdef _DEBUG_
1021               MESSAGE ( "Exception thrown during mesh visualization" );
1022 #endif
1023               if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1024                 SMESH::OnVisuException();
1025               }
1026               else {
1027                 memoryLack = true;
1028               }
1029             }
1030           }
1031           else if ( limitExceeded && !aMesh->_is_nil() )
1032           {
1033             SUIT_MessageBox::warning( desktop(),
1034                                       tr( "SMESH_WRN_WARNING" ),
1035                                       tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1036                                       arg( nbElements ).arg( limitSize ) );
1037           }
1038         }
1039       }
1040       if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1041       {
1042         SALOME_ListIO selected;
1043         selected.Append( myIObject );
1044         Sel->setSelectedObjects( selected );
1045       }
1046     }
1047   }
1048
1049   if ( memoryLack )
1050     aMemoryReserve.release();
1051
1052   myCompDlg->setWindowTitle
1053     ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1054
1055   // SHOW ERRORS
1056
1057   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1058   bool noHypoError = ( aHypErrors.isEmpty() );
1059
1060   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1061   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1062
1063   bool isShowResultDlg = true;
1064   switch( aNotifyMode ) {
1065   case 0: // show the mesh computation result dialog NEVER
1066     isShowResultDlg = false;
1067     commit();
1068     break;
1069   case 1: // show the mesh computation result dialog if there are some errors
1070     if ( memoryLack || !noCompError || !noHypoError )
1071       isShowResultDlg = true;
1072     else
1073     {
1074       isShowResultDlg = false;
1075       commit();
1076     }
1077     break;
1078   default: // show the result dialog after each mesh computation
1079     isShowResultDlg = true;
1080   }
1081
1082   // SHOW RESULTS
1083   if ( isShowResultDlg )
1084     showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1085 }
1086
1087 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1088                                                 const bool theNoCompError,
1089                                                 SMESH::compute_error_array_var& theCompErrors,
1090                                                 const bool theNoHypoError,
1091                                                 const QString& theHypErrors )
1092 {
1093   bool hasShape = myMesh->HasShapeToMesh();
1094   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1095   aCompDlg->myMemoryLackGroup->hide();
1096
1097   if ( theMemoryLack )
1098   {
1099     aCompDlg->myMemoryLackGroup->show();
1100     aCompDlg->myFullInfo->hide();
1101     aCompDlg->myBriefInfo->hide();
1102     aCompDlg->myHypErrorGroup->hide();
1103     aCompDlg->myCompErrorGroup->hide();
1104   }
1105   else if ( theNoCompError && theNoHypoError )
1106   {
1107     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1108     aCompDlg->myFullInfo->SetMeshInfo( aRes );
1109     aCompDlg->myFullInfo->show();
1110     aCompDlg->myBriefInfo->hide();
1111     aCompDlg->myHypErrorGroup->hide();
1112     aCompDlg->myCompErrorGroup->hide();
1113   }
1114   else
1115   {
1116     bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1117     for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1118       onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1119                        theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1120
1121     // full or brief mesh info
1122     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1123     if ( onlyWarnings ) {
1124       aCompDlg->myFullInfo->SetMeshInfo( aRes );
1125       aCompDlg->myFullInfo->show();
1126       aCompDlg->myBriefInfo->hide();
1127     } else {
1128       aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1129       aCompDlg->myBriefInfo->show();
1130       aCompDlg->myFullInfo->hide();
1131     }
1132
1133     // pbs of hypo definitions
1134     if ( theNoHypoError ) {
1135       aCompDlg->myHypErrorGroup->hide();
1136     } else {
1137       aCompDlg->myHypErrorGroup->show();
1138       aCompDlg->myHypErrorLabel->setText( theHypErrors );
1139     }
1140
1141     // table of errors
1142     if ( theNoCompError )
1143     {
1144       aCompDlg->myCompErrorGroup->hide();
1145     }
1146     else
1147     {
1148       aCompDlg->myCompErrorGroup->show();
1149
1150       if ( onlyWarnings )
1151         aCompDlg->myWarningLabel->show();
1152       else
1153         aCompDlg->myWarningLabel->hide();
1154
1155       if ( !hasShape ) {
1156         aCompDlg->myPublishBtn->hide();
1157         aCompDlg->myShowBtn->hide();
1158       }
1159       else {
1160         aCompDlg->myPublishBtn->show();
1161         aCompDlg->myShowBtn->show();
1162       }
1163
1164       // fill table of errors
1165       QTableWidget* tbl = aCompDlg->myTable;
1166       tbl->setRowCount( theCompErrors->length() );
1167       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1168       else             tbl->showColumn( COL_SHAPE );
1169       tbl->setColumnWidth( COL_ERROR, 200 );
1170
1171       bool hasBadMesh = false;
1172       for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1173       {
1174         SMESH::ComputeError & err = theCompErrors[ row ];
1175
1176         QString text = err.algoName.in();
1177         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1178         else tbl->item( row, COL_ALGO )->setText( text );
1179
1180         text = SMESH::errorText( err.code, err.comment.in() );
1181         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1182         else tbl->item( row, COL_ERROR )->setText( text );
1183
1184         text = QString("%1").arg( err.subShapeID );
1185         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1186         else tbl->item( row, COL_SHAPEID )->setText( text );
1187
1188         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1189         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1190         else tbl->item( row, COL_SHAPE )->setText( text );
1191
1192         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1193         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1194         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1195
1196         text = err.hasBadMesh ? "hasBadMesh" : "";
1197         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1198         else tbl->item( row, COL_BAD_MESH )->setText( text );
1199         if ( err.hasBadMesh ) hasBadMesh = true;
1200
1201         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1202         tbl->resizeRowToContents( row );
1203       }
1204       tbl->resizeColumnToContents( COL_ALGO );
1205       tbl->resizeColumnToContents( COL_SHAPE );
1206       tbl->setWordWrap( true );
1207
1208       if ( hasBadMesh ) {
1209         aCompDlg->myBadMeshBtn->show();
1210         aCompDlg->myBadMeshToGroupBtn->show();
1211       }
1212       else {
1213         aCompDlg->myBadMeshBtn->hide();
1214         aCompDlg->myBadMeshToGroupBtn->hide();
1215       }
1216       tbl->setCurrentCell(0,0);
1217       currentCellChanged(); // to update buttons
1218     }
1219   }
1220   // show dialog and wait, because Compute can be invoked from Preview operation
1221   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1222   aCompDlg->show();
1223 }
1224
1225 //================================================================================
1226 /*!
1227  * \brief Stops operation
1228  */
1229 //================================================================================
1230
1231 void SMESHGUI_BaseComputeOp::stopOperation()
1232 {
1233   SMESHGUI_Operation::stopOperation();
1234   if ( myTShapeDisplayer )
1235     myTShapeDisplayer->SetVisibility( false );
1236   if ( myBadMeshDisplayer ) {
1237     myBadMeshDisplayer->SetVisibility( false );
1238     // delete it in order not to have problems at its destruction when the viewer
1239     // where it worked is dead due to e.g. study closing
1240     delete myBadMeshDisplayer;
1241     myBadMeshDisplayer = 0;
1242   }
1243   myIObject.Nullify();
1244 }
1245
1246 //================================================================================
1247 /*!
1248  * \brief publish selected sub-shape
1249  */
1250 //================================================================================
1251
1252 void SMESHGUI_BaseComputeOp::onPublishShape()
1253 {
1254   GEOM::GEOM_Object_var meshShape = myMesh->GetShapeToMesh();
1255   GEOM::GEOM_Gen_var      geomGen = SMESH::GetGEOMGen( meshShape );
1256
1257   QStringList entryList;
1258   QList<int> rows;
1259   SMESH::getSelectedRows( table(), rows );
1260   int row;
1261   foreach ( row, rows )
1262   {
1263     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1264     GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1265     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1266     {
1267       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1268       {
1269         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1270         SALOMEDS::SObject_wrap so = geomGen->AddInStudy( myMainShape,
1271                                                          name.toUtf8().data(),
1272                                                          GEOM::GEOM_Object::_nil());
1273         // look for myMainShape in the table
1274         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1275           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1276             if ( so->_is_nil() ) {
1277               CORBA::String_var name  = so->GetName();
1278               CORBA::String_var entry = so->GetID();
1279               QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1280               table()->item( r, COL_SHAPE     )->setText( shapeText );
1281               table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1282             }
1283             break;
1284           }
1285         }
1286         if ( curSub == 1 ) continue;
1287       }
1288       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1289       SALOMEDS::SObject_wrap so = geomGen->AddInStudy( shape,
1290                                                        name.toUtf8().data(), myMainShape);
1291       if ( !so->_is_nil() ) {
1292         CORBA::String_var name  = so->GetName();
1293         CORBA::String_var entry = so->GetID();
1294         QString       shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1295         table()->item( row, COL_SHAPE     )->setText( shapeText );
1296         table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1297         entryList.push_back( entry.in() );
1298       }
1299     }
1300   }
1301   getSMESHGUI()->getApp()->updateObjectBrowser();
1302   getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1303
1304   currentCellChanged(); // to update buttons
1305 }
1306
1307 //================================================================================
1308 /*!
1309  * \brief show mesh elements preventing computation of a submesh of current row
1310  */
1311 //================================================================================
1312
1313 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1314 {
1315   myTShapeDisplayer->SetVisibility( false );
1316   QList<int> rows;
1317   if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1318     bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1319     if ( hasBadMesh ) {
1320       int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1321       SMESHGUI* gui = getSMESHGUI();
1322       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1323       SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1324       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1325       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1326       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1327       double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1328       double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1329       vtkProperty* prop = vtkProperty::New();
1330       prop->SetLineWidth( aLineWidth * 3 );
1331       prop->SetPointSize( aPointSize * 3 );
1332       prop->SetColor( 250, 0, 250 );
1333       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1334       myBadMeshDisplayer->SetData( aMeshData.in() );
1335       prop->Delete();
1336     }
1337   }
1338 }
1339
1340 //================================================================================
1341 /*!
1342  * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1343  */
1344 //================================================================================
1345
1346 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1347 {
1348   QList<int> rows;
1349   SMESH::getSelectedRows( table(), rows );
1350   int row;
1351   foreach ( row, rows )
1352   {
1353     bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1354     if ( hasBadMesh ) {
1355       int     curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1356       QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1357       if ( grName.isEmpty() ) grName = "bad mesh";
1358       else                    grName = "bad mesh of " + grName;
1359       SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1360       SMESH::ListOfGroups_var groups
1361         ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toUtf8().data()) );
1362       update( UF_ObjBrowser | UF_Model );
1363       if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1364       {
1365         QStringList anEntryList;
1366         for ( size_t i = 0; i < groups->length(); ++i )
1367           if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1368             anEntryList.append( so->GetID().c_str() );
1369
1370         if ( !anEntryList.isEmpty())
1371           anApp->browseObjects( anEntryList, true, false );
1372       }
1373     }
1374   }
1375 }
1376
1377 //================================================================================
1378 /*!
1379  * \brief SLOT called when a selected cell in table() changed
1380  */
1381 //================================================================================
1382
1383 void SMESHGUI_BaseComputeOp::currentCellChanged()
1384 {
1385   myTShapeDisplayer->SetVisibility( false );
1386   if ( myBadMeshDisplayer )
1387     myBadMeshDisplayer->SetVisibility( false );
1388
1389   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1390   QList<int> rows;
1391   int nbSelected = SMESH::getSelectedRows( table(), rows );
1392   int row;
1393   foreach ( row, rows )
1394   {
1395     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1396     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1397     if ( hasData && !isPublished )
1398       publishEnable = true;
1399
1400     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1401     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1402     if ( prsReady ) {
1403       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1404       showOnly = false;
1405     }
1406     else {
1407       showEnable = true;
1408     }
1409
1410     if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1411       hasBadMesh = true;
1412   }
1413   myCompDlg->myPublishBtn->setEnabled( publishEnable );
1414   myCompDlg->myShowBtn   ->setEnabled( showEnable );
1415   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1416   myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1417 }
1418
1419 //================================================================================
1420 /*!
1421  * \brief update preview
1422  */
1423 //================================================================================
1424
1425 void SMESHGUI_BaseComputeOp::onPreviewShape()
1426 {
1427   if ( myTShapeDisplayer )
1428   {
1429     SUIT_OverrideCursor aWaitCursor;
1430     QList<int> rows;
1431     SMESH::getSelectedRows( table(), rows );
1432
1433     bool showOnly = true;
1434     int row;
1435     foreach ( row, rows )
1436     {
1437       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1438       if ( curSub > 0 ) {
1439         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1440         showOnly = false;
1441       }
1442     }
1443     currentCellChanged(); // to update buttons
1444   }
1445 }
1446
1447 //================================================================================
1448 /*!
1449  * \brief Destructor
1450  */
1451 //================================================================================
1452
1453 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1454 {
1455   delete myCompDlg;
1456   myCompDlg = 0;
1457   delete myTShapeDisplayer;
1458   if ( myBadMeshDisplayer )
1459     delete myBadMeshDisplayer;
1460 }
1461
1462 //================================================================================
1463 /*!
1464  * \brief Gets dialog of compute operation
1465  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1466  */
1467 //================================================================================
1468
1469 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1470 {
1471   if ( !myCompDlg )
1472   {
1473     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1474     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1475     // connect signals and slots
1476     connect(myCompDlg->myShowBtn,           SIGNAL (clicked()), SLOT(onPreviewShape()));
1477     connect(myCompDlg->myPublishBtn,        SIGNAL (clicked()), SLOT(onPublishShape()));
1478     connect(myCompDlg->myBadMeshBtn,        SIGNAL (clicked()), SLOT(onShowBadMesh()));
1479     connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1480
1481     QTableWidget* aTable = me->table();
1482     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1483     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1484   }
1485   return myCompDlg;
1486 }
1487
1488 //================================================================================
1489 /*!
1490  * \brief returns from compute mesh result dialog
1491  */
1492 //================================================================================
1493
1494 bool SMESHGUI_BaseComputeOp::onApply()
1495 {
1496   return true;
1497 }
1498
1499 //================================================================================
1500 /*!
1501  * \brief Return a table
1502  */
1503 //================================================================================
1504
1505 QTableWidget* SMESHGUI_BaseComputeOp::table()
1506 {
1507   return myCompDlg->myTable;
1508 }
1509
1510
1511 //================================================================================
1512 /*!
1513  * \brief Constructor
1514 */
1515 //================================================================================
1516
1517 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1518  : SMESHGUI_BaseComputeOp()
1519 {
1520   myHelpFileName = "constructing_meshes.html#compute-anchor";
1521 }
1522
1523
1524 //================================================================================
1525 /*!
1526  * \brief Destructor
1527 */
1528 //================================================================================
1529
1530 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1531 {
1532 }
1533
1534 //================================================================================
1535 /*!
1536  * \brief perform it's intention action: compute mesh
1537  */
1538 //================================================================================
1539
1540 void SMESHGUI_ComputeOp::startOperation()
1541 {
1542   SMESHGUI_BaseComputeOp::startOperation();
1543   if (myMesh->_is_nil())
1544     return;
1545   computeMesh();
1546 }
1547
1548 //================================================================================
1549 /*!
1550  * \brief check the same operations on the same mesh
1551  */
1552 //================================================================================
1553
1554 bool SMESHGUI_BaseComputeOp::isValid(  SUIT_Operation* theOp  ) const
1555 {
1556   SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1557   bool ret = true;
1558   if ( !myMesh->_is_nil() && baseOp ) {
1559     SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1560     if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1561   }
1562   return ret;
1563 }
1564
1565 //================================================================================
1566 /*!
1567  * \brief Gets dialog of this operation
1568  * \retval LightApp_Dialog* - pointer to dialog of this operation
1569  */
1570 //================================================================================
1571
1572 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1573 {
1574   return computeDlg();
1575 }
1576
1577 //================================================================================
1578 /*!
1579  * \brief Constructor
1580  */
1581 //================================================================================
1582
1583 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1584   : SMESHGUI_BaseComputeOp(),
1585     myActiveDlg( 0 ),
1586     myDlg( 0 ),
1587     myPreviewDisplayer( 0 ),
1588     myOrderMgr( 0 )
1589 {
1590 }
1591
1592 //================================================================================
1593 /*!
1594  * \brief Destructor
1595  */
1596 //================================================================================
1597
1598 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1599 {
1600   delete myDlg;
1601   myDlg = 0;
1602   delete myOrderMgr;
1603   myOrderMgr = 0;
1604   myActiveDlg = 0;
1605   if ( myPreviewDisplayer )
1606     delete myPreviewDisplayer;
1607   myPreviewDisplayer = 0;
1608 }
1609
1610 //================================================================================
1611 /*!
1612  * \brief Gets current dialog of this operation
1613  * \retval LightApp_Dialog* - pointer to dialog of this operation
1614  */
1615 //================================================================================
1616
1617 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1618 {
1619   return myActiveDlg;
1620 }
1621
1622 //================================================================================
1623 /*!
1624  * \brief perform it's intention action: prepare data
1625  */
1626 //================================================================================
1627
1628 void SMESHGUI_PrecomputeOp::startOperation()
1629 {
1630   myHelpFileName = "constructing_meshes.html#preview-anchor"; // other anchor onCompute()
1631
1632   if ( !myDlg )
1633   {
1634     myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1635     
1636     // connect signals
1637     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1638     connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1639     connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1640   }
1641   myActiveDlg = myDlg;
1642
1643   // connect signal to compute dialog. which will be shown after Compute mesh operation
1644   SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1645   if ( cmpDlg )
1646   {
1647     // disconnect signals
1648     disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1649     disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1650     disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1651     disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1652     disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1653
1654     // connect signals
1655     if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1656       connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1657     if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1658       connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1659     if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1660       connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1661     if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1662       connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1663     if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1664       connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1665   }
1666
1667   SMESHGUI_BaseComputeOp::startOperation();
1668   if (myMesh->_is_nil())
1669     return;
1670
1671   if (myDlg->getPreviewMode() == -1)
1672   {
1673     // nothing to preview
1674     SUIT_MessageBox::warning(desktop(),
1675                              tr("SMESH_WRN_WARNING"),
1676                              tr("SMESH_WRN_NOTHING_PREVIEW"));
1677     onCancel();
1678     return;
1679   }
1680
1681   // disconnect slot from preview dialog to have Apply from results of compute operation only 
1682   disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1683   disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1684
1685   myDlg->show();
1686 }
1687
1688 //================================================================================
1689 /*!
1690  * \brief Stops operation
1691  */
1692 //================================================================================
1693
1694 void SMESHGUI_PrecomputeOp::stopOperation()
1695 {
1696   if ( myPreviewDisplayer )
1697   {
1698     myPreviewDisplayer->SetVisibility( false );
1699     delete myPreviewDisplayer;
1700     myPreviewDisplayer = 0;
1701   }
1702   myMapShapeId.clear();
1703   SMESHGUI_BaseComputeOp::stopOperation();
1704 }
1705
1706 //================================================================================
1707 /*!
1708  * \brief reinitialize dialog after operaiton become active again
1709  */
1710 //================================================================================
1711
1712 void SMESHGUI_PrecomputeOp::resumeOperation()
1713 {
1714   if ( myActiveDlg == myDlg )
1715     initDialog();
1716   SMESHGUI_BaseComputeOp::resumeOperation();
1717 }
1718
1719 //================================================================================
1720 /*!
1721  * \brief perform it's intention action: reinitialise dialog
1722  */
1723 //================================================================================
1724
1725 void SMESHGUI_PrecomputeOp::initDialog()
1726 {
1727   QList<int> modes;
1728
1729   QMap<int, int> modeMap;
1730   _PTR(SObject)  pMesh = SMESH::getStudy()->FindObjectID( myIObject->getEntry() );
1731   getAssignedAlgos( pMesh, modeMap );
1732   if ( modeMap.contains( SMESH::DIM_3D ) )
1733   {
1734     if ( modeMap.contains( SMESH::DIM_2D ) )
1735       modes.append( SMESH::DIM_2D );
1736     if ( modeMap.contains( SMESH::DIM_1D ) )
1737       modes.append( SMESH::DIM_1D );
1738   }
1739   else if ( modeMap.contains( SMESH::DIM_2D ) )
1740   {
1741     if ( modeMap.contains( SMESH::DIM_1D ) )
1742       modes.append( SMESH::DIM_1D );
1743   }
1744
1745   myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1746   myOrderMgr->SetMesh( myMesh );
1747   bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1748   myDlg->getMeshOrderBox()->setVisible(isOrder);
1749   if ( !isOrder ) {
1750     delete myOrderMgr;
1751     myOrderMgr = 0;
1752   }
1753
1754   myDlg->setPreviewModes( modes );
1755 }
1756
1757 //================================================================================
1758 /*!
1759  * \brief detect assigned mesh algorithms
1760  */
1761 //================================================================================
1762
1763 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject)  theMesh,
1764                                              QMap<int,int>& theModeMap)
1765 {
1766   if ( !theMesh ) return;
1767
1768   _PTR(SObject)          aHypFolder;
1769   _PTR(GenericAttribute) anAttr;
1770   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1771   if ( theMesh->FindSubObject( aPart, aHypFolder ))
1772   {
1773     _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1774     for ( ; anIter->More(); anIter->Next() )
1775     {
1776       _PTR(SObject) anObj = anIter->Value();
1777       _PTR(SObject) aRefObj;
1778       if ( anObj->ReferencedObject( aRefObj ) )
1779         anObj = aRefObj;
1780       else
1781         continue;
1782
1783       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1784       {
1785         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1786         if ( CORBA::is_nil( aVar ) )
1787           continue;
1788
1789         SMESH::SMESH_Algo_var algo;
1790         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1791         {
1792           switch(dim) {
1793           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1794           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1795           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1796           default: break;
1797           }
1798           if ( !algo->_is_nil() )
1799           {
1800             theModeMap[ dim ] = 0;
1801             if ( theModeMap.size() == 3 )
1802               return;
1803             break;
1804           }
1805         }
1806       }
1807     }
1808   }
1809
1810   // check sub-meshes
1811   for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1812   {
1813     if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1814       continue;
1815
1816     _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1817     for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1818     {
1819       _PTR(SObject) anObj = anIter->Value();
1820       _PTR(SObject) aRefObj;
1821       if ( anObj->ReferencedObject( aRefObj ) )
1822         anObj = aRefObj;
1823       else
1824         continue;
1825
1826       if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1827       {
1828         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1829         if ( CORBA::is_nil( aVar ) )
1830           continue;
1831
1832         SMESH::SMESH_Algo_var algo;
1833         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1834         {
1835           switch(dim) {
1836           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1837           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1838           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1839           default: break;
1840           }
1841           if ( !algo->_is_nil() )
1842           {
1843             theModeMap[ dim ] = 0;
1844             if ( theModeMap.size() == 3 )
1845               return;
1846             break;
1847           }
1848         }
1849       }
1850     }
1851   }
1852 }
1853
1854 //================================================================================
1855 /*!
1856  * \brief perform it's intention action: compute mesh
1857  */
1858 //================================================================================
1859
1860 void SMESHGUI_PrecomputeOp::onCompute()
1861 {
1862   myDlg->hide();
1863   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1864     myOrderMgr->SetMeshOrder();
1865   myMapShapeId.clear();
1866   myActiveDlg = computeDlg();
1867   myHelpFileName = "constructing_meshes.html#compute-anchor";
1868   computeMesh();
1869 }
1870
1871 //================================================================================
1872 /*!
1873  * \brief perform it's intention action: compute mesh
1874  */
1875 //================================================================================
1876
1877 void SMESHGUI_PrecomputeOp::onCancel()
1878 {
1879   QObject* curDlg = sender();
1880   if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1881   {
1882     // return from error messages
1883     myDlg->show();
1884     return;
1885   }
1886
1887   bool isRestoreOrder = false;
1888   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
1889   {
1890     // ask to remove already computed mesh elements
1891     if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1892                                     tr( "CLEAR_SUBMESH_QUESTION" ),
1893                                     tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1894     {
1895       // remove all submeshes for collected shapes
1896       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1897       for ( ; it != myMapShapeId.constEnd(); ++it )
1898         myMesh->ClearSubMesh( it.key() );
1899       isRestoreOrder = true;
1900     }
1901   }
1902
1903   // return previous mesh order
1904   if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1905     if (!isRestoreOrder)
1906       isRestoreOrder = 
1907         (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1908                                     tr( "SMESH_REJECT_MESH_ORDER" ),
1909                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1910     if (isRestoreOrder)
1911       myOrderMgr->SetMeshOrder(myPrevOrder);
1912   }
1913
1914   delete myOrderMgr;
1915   myOrderMgr = 0;
1916
1917   myMapShapeId.clear();
1918   SMESHGUI_BaseComputeOp::onCancel();
1919 }
1920
1921 //================================================================================
1922 /*!
1923  * \brief perform it's intention action: preview mesh
1924  */
1925 //================================================================================
1926
1927 void SMESHGUI_PrecomputeOp::onPreview()
1928 {
1929   if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1930     return;
1931
1932   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1933   if ( !aMeshSObj )
1934     return;
1935
1936   // set modified submesh priority if any
1937   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1938     myOrderMgr->SetMeshOrder();
1939
1940   // Compute preview of mesh,
1941   // i.e. compute mesh till indicated dimension
1942   int dim = myDlg->getPreviewMode();
1943
1944   SMESH::MemoryReserve aMemoryReserve;
1945
1946   SMESH::compute_error_array_var aCompErrors;
1947   QString                        aHypErrors;
1948
1949   bool computeFailed = true, memoryLack = false;
1950
1951   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1952   aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1953
1954   SMESHGUI* gui = getSMESHGUI();
1955   SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1956   SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1957   if ( errors->length() > 0 ) {
1958     aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1959   }
1960
1961   SUIT_OverrideCursor aWaitCursor;
1962
1963   SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1964   if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1965   myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1966   
1967   SMESH::long_array_var aShapesId = new SMESH::long_array();
1968   try {
1969     OCC_CATCH_SIGNALS;
1970       
1971     SMESH::MeshPreviewStruct_var previewData =
1972       gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1973
1974     if ( & previewData.in() && previewData->nodesXYZ.length() > 0 )
1975     {
1976       computeFailed = false;
1977       myPreviewDisplayer->SetData( previewData );
1978       // append shape indices with computed mesh entities
1979       for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1980         myMapShapeId[ aShapesId[ i ] ] = 0;
1981     }
1982     else
1983       myPreviewDisplayer->SetVisibility(false);
1984   }
1985   catch(const SALOME::SALOME_Exception & S_ex){
1986     memoryLack = true;
1987     myPreviewDisplayer->SetVisibility(false);
1988   }
1989
1990   try {
1991     OCC_CATCH_SIGNALS;
1992     aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1993     // check if there are memory problems
1994     for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1995       memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1996   }
1997   catch(const SALOME::SALOME_Exception & S_ex){
1998     memoryLack = true;
1999   }
2000
2001   if ( memoryLack )
2002     aMemoryReserve.release();
2003
2004   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2005   bool noHypoError = ( aHypErrors.isEmpty() );
2006
2007   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2008   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2009
2010   bool isShowError = true;
2011   switch( aNotifyMode ) {
2012   case 0: // show the mesh computation result dialog NEVER
2013     isShowError = false;
2014     break;
2015   case 1: // show the mesh computation result dialog if there are some errors
2016   default: // show the result dialog after each mesh computation
2017     if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2018       isShowError = false;
2019     break;
2020   }
2021
2022   aWaitCursor.suspend();
2023   // SHOW ERRORS
2024   if ( isShowError )
2025   {
2026     myDlg->hide();
2027     aCompDlg->setWindowTitle
2028       ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2029     showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2030   }
2031 }
2032
2033
2034 //================================================================================
2035 /*!
2036  * \brief Constructor
2037 */
2038 //================================================================================
2039
2040 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2041  : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2042    myOrderBox(0)
2043 {
2044   setWindowTitle( tr( "CAPTION" ) );
2045
2046   setButtonText( OK, tr( "COMPUTE" ) );
2047   QFrame* main = mainFrame();
2048   main->setMinimumWidth( 300 );
2049
2050   QVBoxLayout* layout = new QVBoxLayout( main );
2051
2052   myOrderBox = new SMESHGUI_MeshOrderBox( main );
2053   layout->addWidget(myOrderBox);
2054
2055   QFrame* frame = new QFrame( main );
2056   layout->setMargin(0); layout->setSpacing(0);
2057   layout->addWidget( frame );
2058
2059   QHBoxLayout* frameLay = new QHBoxLayout( frame );
2060   frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2061   
2062   myPreviewMode = new QtxComboBox( frame );
2063   frameLay->addWidget( myPreviewMode );
2064
2065   myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2066   frameLay->addWidget( myPreviewBtn );
2067
2068   connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2069 }
2070
2071 //================================================================================
2072 /*!
2073  * \brief Destructor
2074 */
2075 //================================================================================
2076
2077 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2078 {
2079 }
2080
2081 //================================================================================
2082 /*!
2083  * \brief Sets available preview modes
2084 */
2085 //================================================================================
2086
2087 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2088 {
2089   myPreviewMode->clear();
2090   QList<int>::const_iterator it = theModes.constBegin();
2091   for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2092   {
2093     QString mode = QString( "PREVIEW_%1" ).arg( *it );
2094     myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2095     myPreviewMode->setId( i, *it );
2096   }
2097   myPreviewBtn->setEnabled( !theModes.isEmpty() );
2098 }
2099
2100 //================================================================================
2101 /*!
2102  * \brief Returns current preview mesh mode
2103 */
2104 //================================================================================
2105
2106 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2107 {
2108   return myPreviewMode->currentId().toInt();
2109 }
2110
2111 //================================================================================
2112 /*!
2113  * \brief Returns current preview mesh mode
2114 */
2115 //================================================================================
2116
2117 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2118 {
2119   return myOrderBox;
2120 }
2121
2122
2123 //================================================================================
2124 /*!
2125  * \brief Constructor
2126 */
2127 //================================================================================
2128
2129 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2130  : SMESHGUI_BaseComputeOp()
2131 {
2132   myHelpFileName = "constructing_meshes.html#evaluate-anchor";
2133 }
2134
2135
2136 //================================================================================
2137 /*!
2138  * \brief Destructor
2139 */
2140 //================================================================================
2141
2142 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2143 {
2144 }
2145
2146 //================================================================================
2147 /*!
2148  * \brief perform it's intention action: compute mesh
2149  */
2150 //================================================================================
2151
2152 void SMESHGUI_EvaluateOp::startOperation()
2153 {
2154   SMESHGUI_BaseComputeOp::evaluateDlg();
2155   SMESHGUI_BaseComputeOp::startOperation();
2156   if (myMesh->_is_nil())
2157     return;
2158   evaluateMesh();
2159 }
2160
2161 //================================================================================
2162 /*!
2163  * \brief Gets dialog of this operation
2164  * \retval LightApp_Dialog* - pointer to dialog of this operation
2165  */
2166 //================================================================================
2167
2168 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2169 {
2170   return evaluateDlg();
2171 }
2172
2173 //================================================================================
2174 /*!
2175  * \brief evaluateMesh()
2176 */
2177 //================================================================================
2178
2179 void SMESHGUI_BaseComputeOp::evaluateMesh()
2180 {
2181   // EVALUATE MESH
2182
2183   SMESH::MemoryReserve aMemoryReserve;
2184
2185   SMESH::compute_error_array_var aCompErrors;
2186   QString                        aHypErrors;
2187
2188   bool evaluateFailed = true, memoryLack = false;
2189   SMESH::long_array_var aRes;
2190
2191   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2192   if ( !aMeshSObj ) //  IPAL21340
2193     return;
2194
2195   bool hasShape = myMesh->HasShapeToMesh();
2196   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2197   if ( shapeOK )
2198   {
2199     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2200     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2201     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2202     if ( errors->length() > 0 ) {
2203       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2204     }
2205     SUIT_OverrideCursor aWaitCursor;
2206     try {
2207       OCC_CATCH_SIGNALS;
2208       aRes = gen->Evaluate(myMesh, myMainShape);
2209     }
2210     catch(const SALOME::SALOME_Exception & S_ex){
2211       memoryLack = true;
2212     }
2213
2214     try {
2215       OCC_CATCH_SIGNALS;
2216       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2217     }
2218     catch(const SALOME::SALOME_Exception & S_ex){
2219       memoryLack = true;
2220     }
2221   }
2222
2223   if ( memoryLack )
2224     aMemoryReserve.release();
2225
2226   evaluateFailed =  ( aCompErrors->length() > 0 );
2227   myCompDlg->setWindowTitle
2228     ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2229
2230   // SHOW ERRORS
2231
2232   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2233   bool noHypoError = ( aHypErrors.isEmpty() );
2234
2235   //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2236   //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2237
2238   bool isShowResultDlg = true;
2239   //if( noHypoError )
2240   //switch( aNotifyMode ) {
2241   //case 0: // show the mesh computation result dialog NEVER
2242   //isShowResultDlg = false;
2243   //commit();
2244   //break;
2245   //case 1: // show the mesh computation result dialog if there are some errors
2246   //if ( memoryLack || !noHypoError )
2247   //  isShowResultDlg = true;
2248   //else
2249   //{
2250   //  isShowResultDlg = false;
2251   //  commit();
2252   //}
2253   //break;
2254   //default: // show the result dialog after each mesh computation
2255   //isShowResultDlg = true;
2256   //}
2257
2258   // SHOW RESULTS
2259   if ( isShowResultDlg )
2260     showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2261                         noHypoError, aHypErrors);
2262 }
2263
2264
2265 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2266                                                 const bool theMemoryLack,
2267                                                 const bool theNoCompError,
2268                                                 SMESH::compute_error_array_var& theCompErrors,
2269                                                 const bool theNoHypoError,
2270                                                 const QString& theHypErrors)
2271 {
2272   bool hasShape = myMesh->HasShapeToMesh();
2273   SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2274   aCompDlg->myMemoryLackGroup->hide();
2275
2276   if ( theMemoryLack )
2277   {
2278     aCompDlg->myMemoryLackGroup->show();
2279     aCompDlg->myFullInfo->hide();
2280     aCompDlg->myBriefInfo->hide();
2281     aCompDlg->myHypErrorGroup->hide();
2282     aCompDlg->myCompErrorGroup->hide();
2283   }
2284   else if ( theNoCompError && theNoHypoError )
2285   {
2286     aCompDlg->myFullInfo->SetMeshInfo( theRes );
2287     aCompDlg->myFullInfo->show();
2288     aCompDlg->myBriefInfo->hide();
2289     aCompDlg->myHypErrorGroup->hide();
2290     aCompDlg->myCompErrorGroup->hide();
2291   }
2292   else
2293   {
2294     QTableWidget* tbl = aCompDlg->myTable;
2295     aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2296     aCompDlg->myBriefInfo->show();
2297     aCompDlg->myFullInfo->hide();
2298
2299     if ( theNoHypoError ) {
2300       aCompDlg->myHypErrorGroup->hide();
2301     }
2302     else {
2303       aCompDlg->myHypErrorGroup->show();
2304       aCompDlg->myHypErrorLabel->setText( theHypErrors );
2305     }
2306
2307     if ( theNoCompError ) {
2308       aCompDlg->myCompErrorGroup->hide();
2309     }
2310     else {
2311       aCompDlg->myCompErrorGroup->show();
2312
2313       aCompDlg->myPublishBtn->hide();
2314       aCompDlg->myShowBtn->hide();
2315
2316       // fill table of errors
2317       tbl->setRowCount( theCompErrors->length() );
2318       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2319       else             tbl->showColumn( COL_SHAPE );
2320       tbl->setColumnWidth( COL_ERROR, 200 );
2321
2322       bool hasBadMesh = false;
2323       for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2324       {
2325         SMESH::ComputeError & err = theCompErrors[ row ];
2326
2327         QString text = err.algoName.in();
2328         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2329         else tbl->item( row, COL_ALGO )->setText( text );
2330
2331         text = SMESH::errorText( err.code, err.comment.in() );
2332         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2333         else tbl->item( row, COL_ERROR )->setText( text );
2334
2335         text = QString("%1").arg( err.subShapeID );
2336         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2337         else tbl->item( row, COL_SHAPEID )->setText( text );
2338
2339         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2340         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2341         else tbl->item( row, COL_SHAPE )->setText( text );
2342
2343         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2344         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2345         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2346
2347         text = err.hasBadMesh ? "hasBadMesh" : "";
2348         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2349         else tbl->item( row, COL_BAD_MESH )->setText( text );
2350         if ( err.hasBadMesh ) hasBadMesh = true;
2351
2352         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2353         tbl->resizeRowToContents( row );
2354       }
2355       tbl->resizeColumnToContents( COL_ALGO );
2356       tbl->resizeColumnToContents( COL_SHAPE );
2357       tbl->setWordWrap( true );
2358
2359       if ( hasBadMesh )
2360       {
2361         aCompDlg->myBadMeshBtn->show();
2362         aCompDlg->myBadMeshToGroupBtn->show();
2363       }
2364       else
2365       {
2366         aCompDlg->myBadMeshBtn->hide();
2367         aCompDlg->myBadMeshToGroupBtn->hide();
2368       }
2369       tbl->setCurrentCell(0,0);
2370       currentCellChanged(); // to update buttons
2371     }
2372   }
2373   // show dialog and wait, because Compute can be invoked from Preview operation
2374   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2375   aCompDlg->show();
2376 }
2377
2378
2379 //================================================================================
2380 /*!
2381  * \brief Gets dialog of evaluate operation
2382  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2383  */
2384 //================================================================================
2385
2386 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2387 {
2388   if ( !myCompDlg )
2389   {
2390     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2391     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2392     // connect signals and slots
2393     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
2394     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2395     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2396     QTableWidget* aTable = me->table();
2397     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2398     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
2399   }
2400   return myCompDlg;
2401 }
2402