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