Salome HOME
fc143d84df665b546e0583e9e40ce14e2fce7be4
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // File   : SMESHGUI_ComputeDlg.cxx
23 // Author : Edward AGAPOV, Open CASCADE S.A.S.
24 // SMESH includes
25 //
26 #include "SMESHGUI_ComputeDlg.h"
27
28 #include "SMESHGUI.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33 #include "SMESHGUI_HypothesesUtils.h"
34 #include "SMESHGUI_MeshEditPreview.h"
35 #include "SMESH_ActorUtils.h"
36
37 #include <SMDS_SetIterator.hxx>
38 #include <SMDS_Mesh.hxx>
39
40 // SALOME GEOM includes
41 #include <GEOMBase.h>
42 #include <GEOM_Actor.h>
43
44 // SALOME GUI includes
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_UpdateFlags.h>
47 #include <SALOME_ListIO.hxx>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_ViewModel.h>
50 #include <SalomeApp_Application.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_Desktop.h>
55 #include <QtxComboBox.h>
56
57 // SALOME KERNEL includes
58 #include <SALOMEDS_SObject.hxx>
59 #include <SALOMEDSClient_SObject.hxx>
60
61 // OCCT includes
62 #include <BRep_Tool.hxx>
63 #include <TopExp.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
66 #include <TopoDS.hxx>
67
68 #include <TopLoc_Location.hxx>
69 #include <Poly_Triangulation.hxx>
70 #include <Bnd_Box.hxx>
71 #include <BRepBndLib.hxx>
72 #include <BRepMesh_IncrementalMesh.hxx>
73
74 #include <Standard_ErrorHandler.hxx>
75
76 // Qt includes
77 #include <QFrame>
78 #include <QPushButton>
79 #include <QLabel>
80 #include <QRadioButton>
81 #include <QTableWidget>
82 #include <QHeaderView>
83 #include <QGridLayout>
84 #include <QHBoxLayout>
85 #include <QVBoxLayout>
86 #include <QButtonGroup>
87
88 // VTK includes
89 #include <vtkProperty.h>
90
91 // STL includes
92 #include <vector>
93 #include <set>
94
95 #define SPACING 6
96 #define MARGIN  11
97
98 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
99
100 static void addSeparator( QWidget* parent )
101 {
102   QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
103   int row  = l->rowCount();
104   int cols = l->columnCount();
105   for ( int i = 0; i < cols; i++ ) {
106     QFrame* hline = new QFrame( parent );
107     hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
108     l->addWidget( hline, row, i );
109   }
110 }
111
112 enum TCol {
113   COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
114 };
115
116 //using namespace SMESH;
117
118 namespace SMESH
119 {
120   //=============================================================================
121   /*!
122    * \brief Allocate some memory at construction and release it at destruction.
123    * Is used to be able to continue working after mesh generation or visualization
124    * break due to lack of memory
125    */
126   //=============================================================================
127
128   struct MemoryReserve
129   {
130     char* myBuf;
131     MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
132     void release() { delete [] myBuf; myBuf = 0; }
133     ~MemoryReserve() { release(); }
134   };
135
136   // =========================================================================================
137   /*!
138    * \brief Class showing shapes without publishing
139    */
140   // =========================================================================================
141
142   class TShapeDisplayer
143   {
144   public:
145     // -----------------------------------------------------------------------
146     TShapeDisplayer(): myViewWindow(0)
147     {
148       myProperty = vtkProperty::New();
149       myProperty->SetRepresentationToWireframe();
150       myProperty->SetColor( 250, 0, 250 );
151       myProperty->SetAmbientColor( 250, 0, 250 );
152       myProperty->SetDiffuseColor( 250, 0, 250 );
153       //myProperty->SetSpecularColor( 250, 0, 250 );
154       myProperty->SetLineWidth( 5 );
155     }
156     // -----------------------------------------------------------------------
157     ~TShapeDisplayer()
158     {
159       DeleteActors();
160       myProperty->Delete();
161     }
162     // -----------------------------------------------------------------------
163     void DeleteActors()
164     {
165       if ( hasViewWindow() ) {
166         TActorIterator actorIt = actorIterator();
167         while ( actorIt.more() )
168           if (VTKViewer_Actor* anActor = actorIt.next()) {
169             myViewWindow->RemoveActor( anActor );
170             //anActor->Delete();
171           }
172       }
173       myIndexToShape.Clear();
174       myActors.clear();
175       myShownActors.clear();
176       myBuiltSubs.clear();
177     }
178     // -----------------------------------------------------------------------
179     void SetVisibility (bool theVisibility)
180     {
181       TActorIterator actorIt = shownIterator();
182       while ( actorIt.more() )
183         if (VTKViewer_Actor* anActor = actorIt.next())
184           anActor->SetVisibility(theVisibility);
185       SMESH::RepaintCurrentView();
186     }
187     // -----------------------------------------------------------------------
188     bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
189     {
190       std::string mainEntry;
191       if ( !aMainShape->_is_nil() )
192         mainEntry = aMainShape->GetStudyEntry();
193       return ( myMainEntry == mainEntry &&
194                myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
195     }
196     // -----------------------------------------------------------------------
197     void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
198     {
199       SVTK_ViewWindow* aViewWindow  = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
200       std::string mainEntry;
201       if ( !aMainShape->_is_nil() )
202         mainEntry = aMainShape->GetStudyEntry();
203       if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
204         DeleteActors();
205         TopoDS_Shape aShape;
206         if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
207           checkTriangulation( aShape );
208           TopExp::MapShapes(aShape, myIndexToShape);
209           myActors.resize( myIndexToShape.Extent(), 0 );
210           myShownActors.reserve( myIndexToShape.Extent() );
211         }
212         myMainEntry  = mainEntry;
213         myViewWindow = aViewWindow;
214       }
215       if ( only ) { // hide shown actors
216         TActorIterator actorIt = shownIterator();
217         while ( actorIt.more() )
218           if (VTKViewer_Actor* anActor = actorIt.next())
219             anActor->SetVisibility(false);
220         myShownActors.clear();
221       }
222       // find actors to show
223       TopoDS_Shape aShape = myIndexToShape( subShapeID );
224       if ( !aShape.IsNull() ) {
225         TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
226         for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
227           //checkTriangulation( exp.Current() );
228           if ( GEOM_Actor* anActor = getActor( exp.Current() ))
229             myShownActors.push_back( anActor );
230         }
231         if ( type == TopAbs_FACE ) {
232           for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
233             const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
234             if ( !BRep_Tool::Degenerated( edge ))
235               if ( GEOM_Actor* anActor = getActor( exp.Current() ))
236                 myShownActors.push_back( anActor );
237           }
238         }
239       }
240       myBuiltSubs.insert( subShapeID );
241       SetVisibility(true);
242     }
243     // -----------------------------------------------------------------------
244
245   private:
246
247     typedef std::vector<GEOM_Actor*> TActorVec;
248     TActorVec                  myActors;
249     TActorVec                  myShownActors;
250     TopTools_IndexedMapOfShape myIndexToShape;
251     std::string                myMainEntry;
252     SVTK_ViewWindow*           myViewWindow;
253     vtkProperty*               myProperty;
254     std::set<int>              myBuiltSubs;
255
256     // -----------------------------------------------------------------------
257     typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
258     TActorIterator actorIterator() {
259       return TActorIterator( myActors.begin(), myActors.end() );
260     }
261     TActorIterator shownIterator() {
262       return TActorIterator( myShownActors.begin(), myShownActors.end() );
263     }
264     // -----------------------------------------------------------------------
265     GEOM_Actor* getActor(const TopoDS_Shape& shape)
266     {
267       int index = myIndexToShape.FindIndex( shape ) - 1;
268       if ( index < 0 || index >= myActors.size() )
269         return 0;
270       GEOM_Actor* & actor = myActors[ index ];
271       if ( !actor ) {
272         actor = GEOM_Actor::New();
273         if ( actor ) {
274           actor->SetShape(shape,0,0);
275           actor->SetProperty(myProperty);
276           actor->SetShadingProperty(myProperty);
277           actor->SetWireframeProperty(myProperty);
278           actor->SetPreviewProperty(myProperty);
279           actor->PickableOff();
280           //         if ( shape.ShapeType() == TopAbs_EDGE )
281           //           actor->SubShapeOn();
282           myViewWindow->AddActor( actor );
283         }
284       }
285       return actor;
286     }
287     // -----------------------------------------------------------------------
288     void checkTriangulation(const TopoDS_Shape& shape)
289     {
290       TopLoc_Location aLoc;
291       Standard_Boolean alreadymesh = Standard_True;
292       TopExp_Explorer ex(shape, TopAbs_FACE);
293       if ( ex.More() )
294         for ( ; ex.More(); ex.Next()) {
295           const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
296           Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
297           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
298         }
299       else
300         for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
301           const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
302           Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
303           if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
304         }
305       if (alreadymesh) return;
306       // Compute default deflection
307       Bnd_Box B;
308       BRepBndLib::Add(shape, B);
309       Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
310       B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
311       double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
312       BRepMesh_IncrementalMesh MESH(shape,deflection);
313     }
314     // -----------------------------------------------------------------------
315     bool hasViewWindow() const
316     {
317       if ( !myViewWindow ) return false;
318
319       if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
320         return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
321                                   myViewWindow );
322       return false;
323     }
324   };
325
326   // =========================================================================================
327   /*!
328    * \brief Return text describing an error
329    */
330 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
331   QString errorText(int errCode, const char* comment)
332   {
333     QString text;
334     switch ( errCode ) {
335       CASE2TEXT( COMPERR_OK            );
336       CASE2TEXT( COMPERR_BAD_INPUT_MESH);
337       CASE2TEXT( COMPERR_STD_EXCEPTION );
338       CASE2TEXT( COMPERR_OCC_EXCEPTION );
339     case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
340       CASE2TEXT( COMPERR_EXCEPTION     );
341       CASE2TEXT( COMPERR_MEMORY_PB     );
342       CASE2TEXT( COMPERR_BAD_SHAPE     );
343     case SMESH::COMPERR_ALGO_FAILED:
344       if ( strlen(comment) == 0 )
345         text = QObject::tr("COMPERR_ALGO_FAILED");
346       break;
347     default:
348       text = QString("#%1").arg( -errCode );
349     }
350     if ( text.length() > 0 ) text += ". ";
351     return text + comment;
352   }
353   // -----------------------------------------------------------------------
354   /*!
355    * \brief Return SO of a subshape
356    */
357   _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
358   {
359     _PTR(SObject) so = SMESH::FindSObject(aMainShape);
360     if ( subShapeID == 1 || !so )
361       return so;
362     _PTR(ChildIterator) it;
363     if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
364       it =  study->NewChildIterator(so);
365     _PTR(SObject) subSO;
366     if ( it ) {
367       for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
368         GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
369         if ( !geom->_is_nil() ) {
370           GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
371           if ( list->length() == 1 && list[0] == subShapeID )
372             subSO = it->Value();
373         }
374       }
375     }
376     return subSO;
377   }
378   // -----------------------------------------------------------------------
379   /*!
380    * \brief Return subshape by ID
381    */
382   GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
383   {
384     GEOM::GEOM_Object_var aSubShape;
385     if ( subShapeID == 1 )
386       aSubShape = aMainShape;
387     else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
388       aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
389     else
390       aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
391     return aSubShape._retn();
392   }
393   // -----------------------------------------------------------------------
394   /*!
395    * \brief Return shape type name
396    */
397 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
398   QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
399   {
400     QString name = dflt;
401     if ( !aShape->_is_nil() ) {
402       switch ( aShape->GetShapeType() ) {
403       CASE2NAME( VERTEX    );
404       CASE2NAME( EDGE      );
405       CASE2NAME( WIRE      );
406       CASE2NAME( FACE      );
407       CASE2NAME( SHELL     );
408       CASE2NAME( SOLID     );
409       CASE2NAME( COMPSOLID );
410       CASE2NAME( COMPOUND  );
411       default:;
412       }
413     }
414     return name;
415   }
416   // -----------------------------------------------------------------------
417   /*!
418    * \brief Return text describing a subshape
419    */
420   QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
421   {
422     QString text;
423     if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
424       text = aSO->GetName().c_str();
425     else {
426       text = QString("#%1").arg( subShapeID );
427       QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
428       if ( typeName.length() )
429         text += QString(" (%1)").arg(typeName);
430     }
431     return text;
432   }
433   // -----------------------------------------------------------------------
434   /*!
435    * \brief Return a list of selected rows
436    */
437   int getSelectedRows(QTableWidget* table, QList<int>& rows)
438   {
439     rows.clear();
440     QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
441     QTableWidgetSelectionRange range;
442     foreach( range, selRanges )
443     {
444       for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
445         rows.append( row );
446     }
447     if ( rows.isEmpty() && table->currentRow() > -1 )
448       rows.append( table->currentRow() );
449
450     return rows.count();
451   }
452
453 } // namespace SMESH
454
455
456 // =========================================================================================
457 /*!
458  * \brief Dialog to compute a mesh and show computation errors
459  */
460 //=======================================================================
461
462 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
463  : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
464 {
465   QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
466   aDlgLay->setMargin( 0 );
467   aDlgLay->setSpacing( SPACING );
468
469   QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
470
471   aDlgLay->addWidget(aMainFrame);
472
473   aDlgLay->setStretchFactor(aMainFrame, 1);
474 }
475
476 // =========================================================================================
477 /*!
478  * \brief Destructor
479  */
480 //=======================================================================
481
482 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
483 {
484 }
485
486 //=======================================================================
487 // function : createMainFrame()
488 // purpose  : Create frame containing dialog's fields
489 //=======================================================================
490
491 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
492 {
493   QFrame* aFrame = new QFrame(theParent);
494
495   SUIT_ResourceMgr* rm = resourceMgr();
496   QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
497
498   // constructor
499
500   QGroupBox* aPixGrp;
501   if(ForEval) {
502     aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
503   }
504   else {
505     aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
506   }
507   QButtonGroup* aBtnGrp = new QButtonGroup(this);
508   QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
509   aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
510
511   QRadioButton* aRBut = new QRadioButton(aPixGrp);
512   aRBut->setIcon(iconCompute);
513   aRBut->setChecked(true);
514   aPixGrpLayout->addWidget(aRBut);
515   aBtnGrp->addButton(aRBut, 0);
516
517   // Mesh name
518
519   QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
520   QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
521   nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
522   myMeshName = new QLabel(nameBox);
523   nameBoxLayout->addWidget(myMeshName);
524
525   // Mesh Info
526
527   myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
528   myFullInfo  = new SMESHGUI_MeshInfosBox(true,  aFrame);
529
530   // Computation errors
531
532   myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
533   myTable      = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
534   myShowBtn    = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
535   myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
536   myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
537
538   //myTable->setReadOnly( true ); // VSR: check
539   myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
540   myTable->hideColumn( COL_PUBLISHED );
541   myTable->hideColumn( COL_SHAPEID );
542   myTable->hideColumn( COL_BAD_MESH );
543   myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
544
545   QStringList headers;
546   headers << tr( "COL_ALGO_HEADER" );
547   headers << tr( "COL_SHAPE_HEADER" );
548   headers << tr( "COL_ERROR_HEADER" );
549   headers << tr( "COL_SHAPEID_HEADER" );
550   headers << tr( "COL_PUBLISHED_HEADER" );
551
552   myTable->setHorizontalHeaderLabels( headers );
553
554   // layouting
555   QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
556   grpLayout->setSpacing(SPACING);
557   grpLayout->setMargin(MARGIN);
558   grpLayout->addWidget( myTable,      0, 0, 4, 1 );
559   grpLayout->addWidget( myShowBtn,    0, 1 );
560   grpLayout->addWidget( myPublishBtn, 1, 1 );
561   grpLayout->addWidget( myBadMeshBtn, 2, 1 );
562   grpLayout->setRowStretch( 3, 1 );
563
564   // Hypothesis definition errors
565
566   myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
567   QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
568   myHypErrorGroupLayout->setMargin(MARGIN);
569   myHypErrorGroupLayout->setSpacing(SPACING);
570   myHypErrorLabel = new QLabel(myHypErrorGroup);
571   myHypErrorGroupLayout->addWidget(myHypErrorLabel);
572
573   // Memory Lack Label
574
575   myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
576   QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
577   myMemoryLackGroupLayout->setMargin(MARGIN);
578   myMemoryLackGroupLayout->setSpacing(SPACING);
579   QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
580   QFont bold = memLackLabel->font(); bold.setBold(true);
581   memLackLabel->setFont( bold );
582   memLackLabel->setMinimumWidth(300);
583   myMemoryLackGroupLayout->addWidget(memLackLabel);
584
585   // add all widgets to aFrame
586   QVBoxLayout* aLay = new QVBoxLayout(aFrame);
587   aLay->setMargin( 0 );
588   aLay->setSpacing( 0 );
589   aLay->addWidget( aPixGrp );
590   aLay->addWidget( nameBox );
591   aLay->addWidget( myBriefInfo );
592   aLay->addWidget( myFullInfo );
593   aLay->addWidget( myHypErrorGroup );
594   aLay->addWidget( myCompErrorGroup );
595   aLay->addWidget( myMemoryLackGroup );
596   aLay->setStretchFactor( myCompErrorGroup, 1 );
597
598   ((QPushButton*) button( OK ))->setDefault( true );
599
600   return aFrame;
601 }
602
603 //================================================================================
604 /*!
605  * \brief Constructor
606 */
607 //================================================================================
608
609 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
610   : SMESHGUI_Operation(), myCompDlg( 0 )
611 {
612   myTShapeDisplayer = new SMESH::TShapeDisplayer();
613   myBadMeshDisplayer = 0;
614
615   //myHelpFileName = "/files/about_meshes.htm"; // V3
616   myHelpFileName = "about_meshes_page.html"; // V4
617 }
618
619 //================================================================================
620 /*!
621  * \brief Start operation
622  * \purpose Init dialog fields, connect signals and slots, show dialog
623  */
624 //================================================================================
625
626 void SMESHGUI_BaseComputeOp::startOperation()
627 {
628   // create compute dialog if not created before
629   computeDlg();
630
631   myMesh      = SMESH::SMESH_Mesh::_nil();
632   myMainShape = GEOM::GEOM_Object::_nil();
633
634   // check selection
635   LightApp_SelectionMgr *Sel = selectionMgr();
636   SALOME_ListIO selected; Sel->selectedObjects( selected );
637
638   int nbSel = selected.Extent();
639   if (nbSel != 1) {
640     SUIT_MessageBox::warning(desktop(),
641                              tr("SMESH_WRN_WARNING"),
642                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
643     onCancel();
644     return;
645   }
646
647   myIObject = selected.First();
648   myMesh = SMESH::GetMeshByIO(myIObject);
649   if (myMesh->_is_nil()) {
650     SUIT_MessageBox::warning(desktop(),
651                              tr("SMESH_WRN_WARNING"),
652                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
653     onCancel();
654
655   }
656   myMainShape = myMesh->GetShapeToMesh();
657
658   SMESHGUI_Operation::startOperation();
659 }
660
661 //================================================================================
662 /*!
663  * \brief computeMesh()
664 */
665 //================================================================================
666
667 void SMESHGUI_BaseComputeOp::computeMesh()
668 {
669   // COMPUTE MESH
670
671   SMESH::MemoryReserve aMemoryReserve;
672
673   SMESH::compute_error_array_var aCompErrors;
674   QString                        aHypErrors;
675
676   bool computeFailed = true, memoryLack = false;
677
678   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
679   bool hasShape = myMesh->HasShapeToMesh();
680   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
681   if ( shapeOK && aMeshSObj )
682   {
683     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
684     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
685     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
686     if ( errors->length() > 0 ) {
687       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
688     }
689     SUIT_OverrideCursor aWaitCursor;
690     try {
691 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
692       OCC_CATCH_SIGNALS;
693 #endif
694       if (gen->Compute(myMesh, myMainShape))
695         computeFailed = false;
696     }
697     catch(const SALOME::SALOME_Exception & S_ex){
698       memoryLack = true;
699     }
700     try {
701 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
702       OCC_CATCH_SIGNALS;
703 #endif
704       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
705       // check if there are memory problems
706       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
707         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
708     }
709     catch(const SALOME::SALOME_Exception & S_ex){
710       memoryLack = true;
711     }
712
713     // NPAL16631: if ( !memoryLack )
714     {
715       SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
716       update( UF_ObjBrowser | UF_Model );
717
718       // SHOW MESH
719       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
720       if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
721       {
722         try {
723 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
724           OCC_CATCH_SIGNALS;
725 #endif
726           SMESH::Update(myIObject, true);
727         }
728         catch (...) {
729 #ifdef _DEBUG_
730           MESSAGE ( "Exception thrown during mesh visualization" );
731 #endif
732           if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
733             SMESH::OnVisuException();
734           }
735           else {
736             memoryLack = true;
737           }
738         }
739       }
740       LightApp_SelectionMgr *Sel = selectionMgr();
741       if ( Sel )
742       {
743         SALOME_ListIO selected;
744         selected.Append( myIObject );
745         Sel->setSelectedObjects( selected );
746       }
747     }
748   }
749
750   if ( memoryLack )
751     aMemoryReserve.release();
752
753   myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
754
755   // SHOW ERRORS
756   
757   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
758   bool noHypoError = ( aHypErrors.isEmpty() );
759
760   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
761   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
762
763   bool isShowResultDlg = true;
764   switch( aNotifyMode ) {
765   case 0: // show the mesh computation result dialog NEVER
766     isShowResultDlg = false;
767     commit();
768     break;
769   case 1: // show the mesh computation result dialog if there are some errors
770     if ( memoryLack || !noCompError || !noHypoError )
771       isShowResultDlg = true;
772     else
773     {
774       isShowResultDlg = false;
775       commit();
776     }
777     break;
778   default: // show the result dialog after each mesh computation
779     isShowResultDlg = true;
780   }
781
782   // SHOW RESULTS
783   if ( isShowResultDlg )
784     showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
785 }
786
787 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
788                                                 const bool theNoCompError,
789                                                 SMESH::compute_error_array_var& theCompErrors,
790                                                 const bool     theNoHypoError,
791                                                 const QString& theHypErrors )
792 {
793   bool hasShape = myMesh->HasShapeToMesh();
794   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
795   aCompDlg->myMemoryLackGroup->hide();
796
797   if ( theMemoryLack )
798   {
799     aCompDlg->myMemoryLackGroup->show();
800     aCompDlg->myFullInfo->hide();
801     aCompDlg->myBriefInfo->hide();
802     aCompDlg->myHypErrorGroup->hide();
803     aCompDlg->myCompErrorGroup->hide();
804   }
805   else if ( theNoCompError && theNoHypoError )
806   {
807     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
808     aCompDlg->myFullInfo->SetMeshInfo( aRes );
809     aCompDlg->myFullInfo->show();
810     aCompDlg->myBriefInfo->hide();
811     aCompDlg->myHypErrorGroup->hide();
812     aCompDlg->myCompErrorGroup->hide();
813   }
814   else
815   {
816     QTableWidget* tbl = aCompDlg->myTable;
817     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
818     aCompDlg->myFullInfo->SetMeshInfo( aRes );
819     aCompDlg->myBriefInfo->show();
820     aCompDlg->myFullInfo->hide();
821
822     if ( theNoHypoError ) {
823       aCompDlg->myHypErrorGroup->hide();
824     }
825     else {
826       aCompDlg->myHypErrorGroup->show();
827       aCompDlg->myHypErrorLabel->setText( theHypErrors );
828     }
829
830     if ( theNoCompError ) {
831       aCompDlg->myCompErrorGroup->hide();
832     }
833     else {
834       aCompDlg->myCompErrorGroup->show();
835
836       if ( !hasShape ) {
837         aCompDlg->myPublishBtn->hide();
838         aCompDlg->myShowBtn->hide();
839       }
840       else {
841         aCompDlg->myPublishBtn->show();
842         aCompDlg->myShowBtn->show();
843       }
844
845       // fill table of errors
846       tbl->setRowCount( theCompErrors->length() );
847       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
848       else             tbl->showColumn( COL_SHAPE );
849       tbl->setColumnWidth( COL_ERROR, 200 );
850
851       bool hasBadMesh = false;
852       for ( int row = 0; row < theCompErrors->length(); ++row )
853       {
854         SMESH::ComputeError & err = theCompErrors[ row ];
855
856         QString text = err.algoName.in();
857         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
858         else tbl->item( row, COL_ALGO )->setText( text );
859
860         text = SMESH::errorText( err.code, err.comment.in() );
861         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
862         else tbl->item( row, COL_ERROR )->setText( text );
863
864         text = QString("%1").arg( err.subShapeID );
865         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
866         else tbl->item( row, COL_SHAPEID )->setText( text );
867
868         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
869         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
870         else tbl->item( row, COL_SHAPE )->setText( text );
871
872         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
873         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
874         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
875
876         text = err.hasBadMesh ? "hasBadMesh" : "";
877         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
878         else tbl->item( row, COL_BAD_MESH )->setText( text );
879         if ( err.hasBadMesh ) hasBadMesh = true;
880
881         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
882         tbl->resizeRowToContents( row );
883       }
884       tbl->resizeColumnToContents( COL_ALGO );
885       tbl->resizeColumnToContents( COL_SHAPE );
886
887       if ( hasBadMesh )
888         aCompDlg->myBadMeshBtn->show();
889       else
890         aCompDlg->myBadMeshBtn->hide();
891
892       tbl->setCurrentCell(0,0);
893       currentCellChanged(); // to update buttons
894     }
895   }
896   // show dialog and wait, becase Compute can be invoked from Preview operation
897   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
898   aCompDlg->show();
899 }
900
901 //================================================================================
902 /*!
903  * \brief Stops operation
904  */
905 //================================================================================
906
907 void SMESHGUI_BaseComputeOp::stopOperation()
908 {
909   SMESHGUI_Operation::stopOperation();
910   if ( myTShapeDisplayer )
911     myTShapeDisplayer->SetVisibility( false );
912   if ( myBadMeshDisplayer ) {
913     myBadMeshDisplayer->SetVisibility( false );
914     // delete it in order not to have problems at its destruction when the viewer
915     // where it worked is dead due to e.g. study closing
916     delete myBadMeshDisplayer;
917     myBadMeshDisplayer = 0;
918   }
919   myIObject.Nullify();
920 }
921
922 //================================================================================
923 /*!
924  * \brief publish selected subshape
925  */
926 //================================================================================
927
928 void SMESHGUI_BaseComputeOp::onPublishShape()
929 {
930   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
931   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
932
933   QList<int> rows;
934   SMESH::getSelectedRows( table(), rows );
935   int row;
936   foreach ( row, rows )
937   {
938     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
939     GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
940     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
941     {
942       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
943       {
944         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
945         SALOMEDS::SObject_var so =
946           geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
947         // look for myMainShape in the table
948         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
949           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
950             if ( so->_is_nil() ) {
951               table()->item( r, COL_SHAPE )->setText( so->GetName() );
952               table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
953             }
954             break;
955           }
956         }
957         if ( curSub == 1 ) continue;
958       }
959       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
960       SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
961       if ( !so->_is_nil() ) {
962         table()->item( row, COL_SHAPE )->setText( so->GetName() );
963         table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
964       }
965     }
966   }
967   getSMESHGUI()->getApp()->updateObjectBrowser();
968   currentCellChanged(); // to update buttons
969 }
970
971 //================================================================================
972 /*!
973  * \brief show mesh elements preventing computation of a submesh of current row
974  */
975 //================================================================================
976
977 void SMESHGUI_BaseComputeOp::onShowBadMesh()
978 {
979   myTShapeDisplayer->SetVisibility( false );
980   QList<int> rows;
981   if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
982     bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
983     if ( hasBadMesh ) {
984       int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
985       SMESHGUI* gui = getSMESHGUI();
986       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
987       SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
988       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
989       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
990       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
991       vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
992       vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
993       // delete property !!!!!!!!!!
994       vtkProperty* prop = vtkProperty::New();
995       prop->SetLineWidth( aLineWidth * 3 );
996       prop->SetPointSize( aPointSize * 3 );
997       prop->SetColor( 250, 0, 250 );
998       myBadMeshDisplayer->GetActor()->SetProperty( prop );
999       myBadMeshDisplayer->SetData( aMeshData._retn() );
1000     }
1001   }
1002 }
1003
1004 //================================================================================
1005 /*!
1006  * \brief SLOT called when a selected cell in table() changed
1007  */
1008 //================================================================================
1009
1010 void SMESHGUI_BaseComputeOp::currentCellChanged()
1011 {
1012   myTShapeDisplayer->SetVisibility( false );
1013   if ( myBadMeshDisplayer )
1014     myBadMeshDisplayer->SetVisibility( false );
1015
1016   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1017   QList<int> rows;
1018   int nbSelected = SMESH::getSelectedRows( table(), rows );
1019   int row;
1020   foreach ( row, rows )
1021   {
1022     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1023     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1024     if ( hasData && !isPublished )
1025       publishEnable = true;
1026
1027     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1028     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1029     if ( prsReady ) {
1030       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1031       showOnly = false;
1032     }
1033     else {
1034       showEnable = true;
1035     }
1036
1037     if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1038       hasBadMesh = true;
1039   }
1040   myCompDlg->myPublishBtn->setEnabled( publishEnable );
1041   myCompDlg->myShowBtn   ->setEnabled( showEnable );
1042   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1043 }
1044
1045 //================================================================================
1046 /*!
1047  * \brief update preview
1048  */
1049 //================================================================================
1050
1051 void SMESHGUI_BaseComputeOp::onPreviewShape()
1052 {
1053   if ( myTShapeDisplayer )
1054   {
1055     SUIT_OverrideCursor aWaitCursor;
1056     QList<int> rows;
1057     SMESH::getSelectedRows( table(), rows );
1058
1059     bool showOnly = true;
1060     int row;
1061     foreach ( row, rows )
1062     {
1063       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1064       if ( curSub > 0 ) {
1065         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1066         showOnly = false;
1067       }
1068     }
1069     currentCellChanged(); // to update buttons
1070   }
1071 }
1072
1073 //================================================================================
1074 /*!
1075  * \brief Destructor
1076  */
1077 //================================================================================
1078
1079 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1080 {
1081   delete myCompDlg;
1082   myCompDlg = 0;
1083   delete myTShapeDisplayer;
1084   if ( myBadMeshDisplayer )
1085     delete myBadMeshDisplayer;
1086 }
1087
1088 //================================================================================
1089 /*!
1090  * \brief Gets dialog of compute operation
1091  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1092  */
1093 //================================================================================
1094
1095 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1096 {
1097   if ( !myCompDlg )
1098   {
1099     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1100     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1101     // connect signals and slots
1102     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1103     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1104     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1105
1106     QTableWidget* aTable = me->table();
1107     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1108     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1109   }
1110   return myCompDlg;
1111 }
1112
1113 //================================================================================
1114 /*!
1115  * \brief returns from compute mesh result dialog
1116  */
1117 //================================================================================
1118
1119 bool SMESHGUI_BaseComputeOp::onApply()
1120 {
1121   return true;
1122 }
1123
1124 //================================================================================
1125 /*!
1126  * \brief Return a table
1127  */
1128 //================================================================================
1129
1130 QTableWidget* SMESHGUI_BaseComputeOp::table()
1131 {
1132   return myCompDlg->myTable;
1133 }
1134
1135
1136 //================================================================================
1137 /*!
1138  * \brief Constructor
1139 */
1140 //================================================================================
1141
1142 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1143  : SMESHGUI_BaseComputeOp()
1144 {
1145 }
1146
1147
1148 //================================================================================
1149 /*!
1150  * \brief Desctructor
1151 */
1152 //================================================================================
1153
1154 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1155 {
1156 }
1157
1158 //================================================================================
1159 /*!
1160  * \brief perform it's intention action: compute mesh
1161  */
1162 //================================================================================
1163
1164 void SMESHGUI_ComputeOp::startOperation()
1165 {
1166   SMESHGUI_BaseComputeOp::startOperation();
1167   computeMesh();
1168 }
1169
1170 //================================================================================
1171 /*!
1172  * \brief Gets dialog of this operation
1173  * \retval LightApp_Dialog* - pointer to dialog of this operation
1174  */
1175 //================================================================================
1176
1177 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1178 {
1179   return computeDlg();
1180 }
1181
1182 //================================================================================
1183 /*!
1184  * \brief Constructor
1185 */
1186 //================================================================================
1187
1188 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1189  : SMESHGUI_BaseComputeOp(),
1190  myDlg( 0 ),
1191  myActiveDlg( 0 ),
1192  myPreviewDisplayer( 0 )
1193 {
1194   myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1195 }
1196
1197 //================================================================================
1198 /*!
1199  * \brief Destructor
1200  */
1201 //================================================================================
1202
1203 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1204 {
1205   delete myDlg;
1206   myDlg = 0;
1207   myActiveDlg = 0;
1208   if ( myPreviewDisplayer )
1209     delete myPreviewDisplayer;
1210   myPreviewDisplayer = 0;
1211 }
1212
1213 //================================================================================
1214 /*!
1215  * \brief Gets current dialog of this operation
1216  * \retval LightApp_Dialog* - pointer to dialog of this operation
1217  */
1218 //================================================================================
1219
1220 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1221 {
1222   return myActiveDlg;
1223 }
1224
1225 //================================================================================
1226 /*!
1227  * \brief perform it's intention action: prepare data
1228  */
1229 //================================================================================
1230
1231 void SMESHGUI_PrecomputeOp::startOperation()
1232 {
1233   if ( !myDlg )
1234   {
1235     myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1236     
1237     // connect signals
1238     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1239     connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1240     connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1241   }
1242   myActiveDlg = myDlg;
1243
1244   // connect signal to compute dialog. which will be shown after Compute mesh operation
1245   SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1246   if ( cmpDlg )
1247   {
1248     // disconnect signals
1249     disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1250     disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1251     disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1252     disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1253     disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1254
1255     // connect signals
1256     if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1257       connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1258     if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1259       connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1260     if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1261       connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1262     if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1263       connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1264     if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1265       connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1266   }
1267
1268   SMESHGUI_BaseComputeOp::startOperation();
1269
1270   // disconnect slot from preview dialog to have Apply from results of compute operation only 
1271   disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1272   disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1273
1274   myDlg->show();
1275 }
1276
1277 //================================================================================
1278 /*!
1279  * \brief Stops operation
1280  */
1281 //================================================================================
1282
1283 void SMESHGUI_PrecomputeOp::stopOperation()
1284 {
1285   if ( myPreviewDisplayer )
1286   {
1287     myPreviewDisplayer->SetVisibility( false );
1288     delete myPreviewDisplayer;
1289     myPreviewDisplayer = 0;
1290   }
1291   myMapShapeId.clear();
1292   SMESHGUI_BaseComputeOp::stopOperation();
1293 }
1294
1295 //================================================================================
1296 /*!
1297  * \brief reinitialize dialog after operaiton become active again
1298  */
1299 //================================================================================
1300
1301 void SMESHGUI_PrecomputeOp::resumeOperation()
1302 {
1303   if ( myActiveDlg == myDlg )
1304     initDialog();
1305   SMESHGUI_BaseComputeOp::resumeOperation();
1306 }
1307
1308 //================================================================================
1309 /*!
1310  * \brief perform it's intention action: reinitialise dialog
1311  */
1312 //================================================================================
1313
1314 void SMESHGUI_PrecomputeOp::initDialog()
1315 {
1316   QList<int> modes;
1317
1318   QMap<int, int> modeMap;
1319   _PTR(SObject)  pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1320   getAssignedAlgos( pMesh, modeMap );
1321   if ( modeMap.contains( SMESH::DIM_3D ) )
1322   {
1323     if ( modeMap.contains( SMESH::DIM_2D ) )
1324       modes.append( SMESH::DIM_2D );
1325     if ( modeMap.contains( SMESH::DIM_1D ) )
1326       modes.append( SMESH::DIM_1D );
1327   }
1328   else if ( modeMap.contains( SMESH::DIM_2D ) )
1329   {
1330     if ( modeMap.contains( SMESH::DIM_1D ) )
1331       modes.append( SMESH::DIM_1D );
1332   }
1333
1334   myDlg->setPreviewModes( modes );
1335 }
1336
1337 //================================================================================
1338 /*!
1339  * \brief detect asigned mesh algorithms
1340  */
1341 //================================================================================
1342
1343 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1344                                              QMap<int,int>& theModeMap)
1345 {
1346   _PTR(SObject)          aHypRoot;
1347   _PTR(GenericAttribute) anAttr;
1348   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1349   if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1350   {
1351     _PTR(ChildIterator) anIter =
1352       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1353     for ( ; anIter->More(); anIter->Next() )
1354     {
1355       _PTR(SObject) anObj = anIter->Value();
1356       _PTR(SObject) aRefObj;
1357       if ( anObj->ReferencedObject( aRefObj ) )
1358         anObj = aRefObj;
1359       else
1360         continue;
1361       
1362       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1363       {
1364         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1365         if ( CORBA::is_nil( aVar ) )
1366           continue;
1367         
1368         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1369         {
1370           SMESH::SMESH_Algo_var algo;
1371           switch(dim) {
1372           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1373           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1374           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1375           default: break;
1376           }
1377           if ( !algo->_is_nil() )
1378             theModeMap[ dim ] = 0;
1379         }
1380       }
1381     }
1382   }
1383 }
1384
1385 //================================================================================
1386 /*!
1387  * \brief perform it's intention action: compute mesh
1388  */
1389 //================================================================================
1390
1391 void SMESHGUI_PrecomputeOp::onCompute()
1392 {
1393   myDlg->hide();
1394   myMapShapeId.clear();
1395   myActiveDlg = computeDlg();
1396   computeMesh();
1397 }
1398
1399 //================================================================================
1400 /*!
1401  * \brief perform it's intention action: compute mesh
1402  */
1403 //================================================================================
1404
1405 void SMESHGUI_PrecomputeOp::onCancel()
1406 {
1407   QObject* curDlg = sender();
1408   if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1409   {
1410     // return from error messages
1411     myDlg->show();
1412     return;
1413   }
1414
1415   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
1416   {
1417     // ask to remove already computed mesh elements
1418     if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1419                                     tr( "CLEAR_SUBMESH_QUESTION" ),
1420                                     tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1421     {
1422       // remove all submeshes for collected shapes
1423       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1424       for ( ; it != myMapShapeId.constEnd(); ++it )
1425         myMesh->ClearSubMesh( *it );
1426     }
1427   }
1428   myMapShapeId.clear();
1429   SMESHGUI_BaseComputeOp::onCancel();
1430 }
1431
1432 //================================================================================
1433 /*!
1434  * \brief perform it's intention action: preview mesh
1435  */
1436 //================================================================================
1437
1438 void SMESHGUI_PrecomputeOp::onPreview()
1439 {
1440   if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1441     return;
1442
1443   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1444   if ( !aMeshSObj )
1445     return;
1446   // Compute preview of mesh, 
1447   // i.e. compute mesh till indicated dimension
1448   int dim = myDlg->getPreviewMode();
1449   
1450   SMESH::MemoryReserve aMemoryReserve;
1451   
1452   SMESH::compute_error_array_var aCompErrors;
1453   QString                        aHypErrors;
1454
1455   bool computeFailed = true, memoryLack = false;
1456
1457   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1458     aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1459
1460   SMESHGUI* gui = getSMESHGUI();
1461   SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1462   SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1463   if ( errors->length() > 0 ) {
1464     aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1465   }
1466
1467   SUIT_OverrideCursor aWaitCursor;
1468
1469   SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1470   if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1471   myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1472   
1473   SMESH::long_array_var aShapesId = new SMESH::long_array();
1474   try {
1475 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1476     OCC_CATCH_SIGNALS;
1477 #endif
1478       
1479     SMESH::MeshPreviewStruct_var previewData =
1480       gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1481     SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1482     if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1483     {
1484       computeFailed = false;
1485       myPreviewDisplayer->SetData( previewRes );
1486       // append shape indeces with computed mesh entities
1487       for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1488         myMapShapeId[ aShapesId[ i ] ] = 0;
1489     }
1490     else
1491       myPreviewDisplayer->SetVisibility(false);
1492   }
1493   catch(const SALOME::SALOME_Exception & S_ex){
1494     memoryLack = true;
1495     myPreviewDisplayer->SetVisibility(false);
1496   }
1497
1498   try {
1499 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1500     OCC_CATCH_SIGNALS;
1501 #endif
1502     aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1503     // check if there are memory problems
1504     for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1505       memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1506   }
1507   catch(const SALOME::SALOME_Exception & S_ex){
1508     memoryLack = true;
1509   }
1510
1511   if ( memoryLack )
1512     aMemoryReserve.release();
1513
1514   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1515   bool noHypoError = ( aHypErrors.isEmpty() );
1516
1517   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1518   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1519
1520   bool isShowError = true;
1521   switch( aNotifyMode ) {
1522   case 0: // show the mesh computation result dialog NEVER
1523     isShowError = false;
1524     break;
1525   case 1: // show the mesh computation result dialog if there are some errors
1526   default: // show the result dialog after each mesh computation
1527     if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1528       isShowError = false;
1529     break;
1530   }
1531
1532   aWaitCursor.suspend();
1533   // SHOW ERRORS
1534   if ( isShowError )
1535   {
1536     myDlg->hide();
1537     aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1538     showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1539   }
1540 }
1541
1542
1543 //================================================================================
1544 /*!
1545  * \brief Constructor
1546 */
1547 //================================================================================
1548
1549 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1550  : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help )
1551 {
1552   setWindowTitle( tr( "CAPTION" ) );
1553
1554   setButtonText( OK, tr( "COMPUTE" ) );
1555   QFrame* main = mainFrame();
1556
1557   QVBoxLayout* layout = new QVBoxLayout( main );
1558
1559   QFrame* frame = new QFrame( main );
1560   layout->setMargin(0); layout->setSpacing(0);
1561   layout->addWidget( frame );
1562
1563   QHBoxLayout* frameLay = new QHBoxLayout( frame );
1564   frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1565   
1566   myPreviewMode = new QtxComboBox( frame );
1567   frameLay->addWidget( myPreviewMode );
1568
1569   myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1570   frameLay->addWidget( myPreviewBtn );
1571
1572   connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1573 }
1574
1575 //================================================================================
1576 /*!
1577  * \brief Destructor
1578 */
1579 //================================================================================
1580
1581 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1582 {
1583 }
1584
1585 //================================================================================
1586 /*!
1587  * \brief Sets available preview modes
1588 */
1589 //================================================================================
1590
1591 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1592 {
1593   myPreviewMode->clear();
1594   QList<int>::const_iterator it = theModes.constBegin();
1595   for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1596   {
1597     QString mode = QString( "PREVIEW_%1" ).arg( *it );
1598     myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1599     myPreviewMode->setId( i, *it );
1600   }
1601   myPreviewBtn->setEnabled( !theModes.isEmpty() );
1602 }
1603
1604 //================================================================================
1605 /*!
1606  * \brief Returns current preview mesh mode
1607 */
1608 //================================================================================
1609
1610 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1611 {
1612   return myPreviewMode->currentId();
1613 }
1614
1615
1616 //================================================================================
1617 /*!
1618  * \brief Constructor
1619 */
1620 //================================================================================
1621
1622 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1623  : SMESHGUI_BaseComputeOp()
1624 {
1625 }
1626
1627
1628 //================================================================================
1629 /*!
1630  * \brief Desctructor
1631 */
1632 //================================================================================
1633
1634 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1635 {
1636 }
1637
1638 //================================================================================
1639 /*!
1640  * \brief perform it's intention action: compute mesh
1641  */
1642 //================================================================================
1643
1644 void SMESHGUI_EvaluateOp::startOperation()
1645 {
1646   SMESHGUI_BaseComputeOp::evaluateDlg();
1647   SMESHGUI_BaseComputeOp::startOperation();
1648   evaluateMesh();
1649 }
1650
1651 //================================================================================
1652 /*!
1653  * \brief Gets dialog of this operation
1654  * \retval LightApp_Dialog* - pointer to dialog of this operation
1655  */
1656 //================================================================================
1657
1658 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1659 {
1660   return evaluateDlg();
1661 }
1662
1663 //================================================================================
1664 /*!
1665  * \brief evaluaateMesh()
1666 */
1667 //================================================================================
1668
1669 void SMESHGUI_BaseComputeOp::evaluateMesh()
1670 {
1671   // EVALUATE MESH
1672
1673   SMESH::MemoryReserve aMemoryReserve;
1674
1675   SMESH::compute_error_array_var aCompErrors;
1676   QString                        aHypErrors;
1677
1678   bool evaluateFailed = true, memoryLack = false;
1679   SMESH::long_array_var aRes;
1680
1681   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1682   bool hasShape = myMesh->HasShapeToMesh();
1683   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1684   if ( shapeOK && aMeshSObj )
1685   {
1686     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1687     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1688     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1689     if ( errors->length() > 0 ) {
1690       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1691     }
1692     SUIT_OverrideCursor aWaitCursor;
1693     try {
1694 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1695       OCC_CATCH_SIGNALS;
1696 #endif
1697       aRes = gen->Evaluate(myMesh, myMainShape);
1698     }
1699     catch(const SALOME::SALOME_Exception & S_ex){
1700       memoryLack = true;
1701     }
1702
1703     try {
1704 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1705       OCC_CATCH_SIGNALS;
1706 #endif
1707       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1708     }
1709     catch(const SALOME::SALOME_Exception & S_ex){
1710       memoryLack = true;
1711     }
1712   }
1713
1714   if ( memoryLack )
1715     aMemoryReserve.release();
1716
1717   evaluateFailed =  ( aCompErrors->length() > 0 );
1718   myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1719
1720   // SHOW ERRORS
1721   
1722   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1723   bool noHypoError = ( aHypErrors.isEmpty() );
1724
1725   //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1726   //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1727
1728   bool isShowResultDlg = true;
1729   //if( noHypoError )
1730   //switch( aNotifyMode ) {
1731   //case 0: // show the mesh computation result dialog NEVER
1732   //isShowResultDlg = false;
1733   //commit();
1734   //break;
1735   //case 1: // show the mesh computation result dialog if there are some errors
1736   //if ( memoryLack || !noHypoError )
1737   //  isShowResultDlg = true;
1738   //else
1739   //{
1740   //  isShowResultDlg = false;
1741   //  commit();
1742   //}
1743   //break;
1744   //default: // show the result dialog after each mesh computation
1745   //isShowResultDlg = true;
1746   //}
1747
1748   // SHOW RESULTS
1749   if ( isShowResultDlg )
1750     showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1751                         noHypoError, aHypErrors);
1752 }
1753
1754
1755 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1756                                                 const bool theMemoryLack,
1757                                                 const bool theNoCompError,
1758                                                 SMESH::compute_error_array_var& theCompErrors,
1759                                                 const bool theNoHypoError,
1760                                                 const QString& theHypErrors)
1761 {
1762   bool hasShape = myMesh->HasShapeToMesh();
1763   SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1764   aCompDlg->myMemoryLackGroup->hide();
1765
1766   if ( theMemoryLack )
1767   {
1768     aCompDlg->myMemoryLackGroup->show();
1769     aCompDlg->myFullInfo->hide();
1770     aCompDlg->myBriefInfo->hide();
1771     aCompDlg->myHypErrorGroup->hide();
1772     aCompDlg->myCompErrorGroup->hide();
1773   }
1774   else if ( theNoCompError && theNoHypoError )
1775   {
1776     aCompDlg->myFullInfo->SetMeshInfo( theRes );
1777     aCompDlg->myFullInfo->show();
1778     aCompDlg->myBriefInfo->hide();
1779     aCompDlg->myHypErrorGroup->hide();
1780     aCompDlg->myCompErrorGroup->hide();
1781   }
1782   else
1783   {
1784     QTableWidget* tbl = aCompDlg->myTable;
1785     aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1786     aCompDlg->myBriefInfo->show();
1787     aCompDlg->myFullInfo->hide();
1788
1789     if ( theNoHypoError ) {
1790       aCompDlg->myHypErrorGroup->hide();
1791     }
1792     else {
1793       aCompDlg->myHypErrorGroup->show();
1794       aCompDlg->myHypErrorLabel->setText( theHypErrors );
1795     }
1796
1797     if ( theNoCompError ) {
1798       aCompDlg->myCompErrorGroup->hide();
1799     }
1800     else {
1801       aCompDlg->myCompErrorGroup->show();
1802
1803       aCompDlg->myPublishBtn->hide();
1804       aCompDlg->myShowBtn->hide();
1805
1806       // fill table of errors
1807       tbl->setRowCount( theCompErrors->length() );
1808       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1809       else             tbl->showColumn( COL_SHAPE );
1810       tbl->setColumnWidth( COL_ERROR, 200 );
1811
1812       bool hasBadMesh = false;
1813       for ( int row = 0; row < theCompErrors->length(); ++row )
1814       {
1815         SMESH::ComputeError & err = theCompErrors[ row ];
1816
1817         QString text = err.algoName.in();
1818         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1819         else tbl->item( row, COL_ALGO )->setText( text );
1820
1821         text = SMESH::errorText( err.code, err.comment.in() );
1822         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1823         else tbl->item( row, COL_ERROR )->setText( text );
1824
1825         text = QString("%1").arg( err.subShapeID );
1826         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1827         else tbl->item( row, COL_SHAPEID )->setText( text );
1828
1829         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1830         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1831         else tbl->item( row, COL_SHAPE )->setText( text );
1832
1833         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1834         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1835         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1836
1837         text = err.hasBadMesh ? "hasBadMesh" : "";
1838         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1839         else tbl->item( row, COL_BAD_MESH )->setText( text );
1840         if ( err.hasBadMesh ) hasBadMesh = true;
1841
1842         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1843         tbl->resizeRowToContents( row );
1844       }
1845       tbl->resizeColumnToContents( COL_ALGO );
1846       tbl->resizeColumnToContents( COL_SHAPE );
1847
1848       if ( hasBadMesh )
1849         aCompDlg->myBadMeshBtn->show();
1850       else
1851         aCompDlg->myBadMeshBtn->hide();
1852
1853       tbl->setCurrentCell(0,0);
1854       currentCellChanged(); // to update buttons
1855     }
1856   }
1857   // show dialog and wait, becase Compute can be invoked from Preview operation
1858   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1859   aCompDlg->show();
1860 }
1861
1862
1863 //================================================================================
1864 /*!
1865  * \brief Gets dialog of evaluate operation
1866  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1867  */
1868 //================================================================================
1869
1870 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1871 {
1872   if ( !myCompDlg )
1873   {
1874     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1875     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1876     // connect signals and slots
1877     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1878     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1879     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1880     QTableWidget* aTable = me->table();
1881     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1882     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1883   }
1884   return myCompDlg;
1885 }
1886