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