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