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