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