Salome HOME
Update copyright info (2010->2011)
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ComputeDlg.cxx
1 //  Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File   : SMESHGUI_ComputeDlg.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
22 // SMESH includes
23 //
24 #include "SMESHGUI_ComputeDlg.h"
25
26 #include "SMESHGUI.h"
27 #include "SMESHGUI_GEOMGenUtils.h"
28 #include "SMESHGUI_MeshUtils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_MeshInfosBox.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_MeshEditPreview.h"
33 #include "SMESHGUI_MeshOrderOp.h"
34 #include "SMESHGUI_MeshOrderDlg.h"
35
36 #include "SMESH_ActorUtils.h"
37
38 #include <SMDS_SetIterator.hxx>
39 #include <SMDS_Mesh.hxx>
40
41 // SALOME GEOM includes
42 #include <GEOMBase.h>
43 #include <GEOM_Actor.h>
44
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_UpdateFlags.h>
48 #include <SALOME_ListIO.hxx>
49 #include <SVTK_ViewWindow.h>
50 #include <SVTK_ViewModel.h>
51 #include <SalomeApp_Application.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_MessageBox.h>
55 #include <SUIT_Desktop.h>
56 #include <QtxComboBox.h>
57
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDSClient_SObject.hxx>
61
62 // OCCT includes
63 #include <BRep_Tool.hxx>
64 #include <TopExp.hxx>
65 #include <TopExp_Explorer.hxx>
66 #include <TopTools_IndexedMapOfShape.hxx>
67 #include <TopoDS.hxx>
68
69 #include <TopLoc_Location.hxx>
70 #include <Poly_Triangulation.hxx>
71 #include <Bnd_Box.hxx>
72 #include <BRepBndLib.hxx>
73 #include <BRepMesh_IncrementalMesh.hxx>
74
75 #include <Standard_ErrorHandler.hxx>
76
77 // Qt includes
78 #include <QFrame>
79 #include <QPushButton>
80 #include <QLabel>
81 #include <QRadioButton>
82 #include <QTableWidget>
83 #include <QHeaderView>
84 #include <QGridLayout>
85 #include <QHBoxLayout>
86 #include <QVBoxLayout>
87 #include <QButtonGroup>
88
89 // VTK includes
90 #include <vtkProperty.h>
91
92 // STL includes
93 #include <vector>
94 #include <set>
95
96 #define SPACING 6
97 #define MARGIN  11
98
99 #define COLONIZE(str)   (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
100
101 /* OBSOLETE
102 static void addSeparator( QWidget* parent )
103 {
104   QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
105   int row  = l->rowCount();
106   int cols = l->columnCount();
107   for ( int i = 0; i < cols; i++ ) {
108     QFrame* hline = new QFrame( parent );
109     hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
110     l->addWidget( hline, row, i );
111   }
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 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
623 {
624   LightApp_SelectionMgr* Sel = selectionMgr();
625   SALOME_ListIO selected; Sel->selectedObjects( selected );
626   Handle(SALOME_InteractiveObject) anIO = selected.First();
627   SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
628   return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
629 }
630
631 //================================================================================
632 /*!
633  * \brief Start operation
634  * \purpose Init dialog fields, connect signals and slots, show dialog
635  */
636 //================================================================================
637
638 void SMESHGUI_BaseComputeOp::startOperation()
639 {
640   // create compute dialog if not created before
641   computeDlg();
642
643   myMesh      = SMESH::SMESH_Mesh::_nil();
644   myMainShape = GEOM::GEOM_Object::_nil();
645
646   // check selection
647   LightApp_SelectionMgr *Sel = selectionMgr();
648   SALOME_ListIO selected; Sel->selectedObjects( selected );
649
650   int nbSel = selected.Extent();
651   if (nbSel != 1) {
652     SUIT_MessageBox::warning(desktop(),
653                              tr("SMESH_WRN_WARNING"),
654                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
655     onCancel();
656     return;
657   }
658
659   myIObject = selected.First();
660   myMesh = SMESH::GetMeshByIO(myIObject);
661   if (myMesh->_is_nil()) {
662     SUIT_MessageBox::warning(desktop(),
663                              tr("SMESH_WRN_WARNING"),
664                              tr("SMESH_WRN_NO_AVAILABLE_DATA"));
665     onCancel();
666     return;
667   }
668   myMainShape = myMesh->GetShapeToMesh();
669
670   SMESHGUI_Operation::startOperation();
671 }
672
673 //================================================================================
674 /*!
675  * \brief computeMesh()
676 */
677 //================================================================================
678
679 void SMESHGUI_BaseComputeOp::computeMesh()
680 {
681   // COMPUTE MESH
682
683   SMESH::MemoryReserve aMemoryReserve;
684
685   SMESH::compute_error_array_var aCompErrors;
686   QString                        aHypErrors;
687
688   bool computeFailed = true, memoryLack = false;
689
690   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
691   if ( !aMeshSObj ) // IPAL 21340
692     return;
693   bool hasShape = myMesh->HasShapeToMesh();
694   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
695   if ( shapeOK )
696   {
697     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
698     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
699     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
700     if ( errors->length() > 0 ) {
701       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
702     }
703     if ( myMesh->HasModificationsToDiscard() && // issue 0020693
704          SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
705                                     tr( "FULL_RECOMPUTE_QUESTION" ),
706                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
707       myMesh->Clear();
708     SUIT_OverrideCursor aWaitCursor;
709     try {
710 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
711       OCC_CATCH_SIGNALS;
712 #endif
713       if (gen->Compute(myMesh, myMainShape))
714         computeFailed = false;
715     }
716     catch(const SALOME::SALOME_Exception & S_ex){
717       memoryLack = true;
718     }
719     try {
720 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
721       OCC_CATCH_SIGNALS;
722 #endif
723       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
724       // check if there are memory problems
725       for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
726         memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
727     }
728     catch(const SALOME::SALOME_Exception & S_ex){
729       memoryLack = true;
730     }
731
732     // NPAL16631: if ( !memoryLack )
733     {
734       SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
735       update( UF_ObjBrowser | UF_Model );
736
737       // SHOW MESH
738       // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
739       SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
740       long newSize = myMesh->NbElements();
741       long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
742       bool limitExceeded;
743       if ( !memoryLack )
744       {
745         if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
746         {
747           try {
748 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
749             OCC_CATCH_SIGNALS;
750 #endif
751             SMESH::Update(myIObject, true);
752           }
753           catch (...) {
754 #ifdef _DEBUG_
755             MESSAGE ( "Exception thrown during mesh visualization" );
756 #endif
757             if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
758               SMESH::OnVisuException();
759             }
760             else {
761               memoryLack = true;
762             }
763           }
764         }
765         else if ( limitExceeded )
766         {
767           SUIT_MessageBox::warning( desktop(),
768                                     tr( "SMESH_WRN_WARNING" ),
769                                     tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
770         }
771       }
772       LightApp_SelectionMgr *Sel = selectionMgr();
773       if ( Sel )
774       {
775         SALOME_ListIO selected;
776         selected.Append( myIObject );
777         Sel->setSelectedObjects( selected );
778       }
779     }
780   }
781
782   if ( memoryLack )
783     aMemoryReserve.release();
784
785   myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
786
787   // SHOW ERRORS
788   
789   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
790   bool noHypoError = ( aHypErrors.isEmpty() );
791
792   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
793   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
794
795   bool isShowResultDlg = true;
796   switch( aNotifyMode ) {
797   case 0: // show the mesh computation result dialog NEVER
798     isShowResultDlg = false;
799     commit();
800     break;
801   case 1: // show the mesh computation result dialog if there are some errors
802     if ( memoryLack || !noCompError || !noHypoError )
803       isShowResultDlg = true;
804     else
805     {
806       isShowResultDlg = false;
807       commit();
808     }
809     break;
810   default: // show the result dialog after each mesh computation
811     isShowResultDlg = true;
812   }
813
814   // SHOW RESULTS
815   if ( isShowResultDlg )
816     showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
817 }
818
819 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
820                                                 const bool theNoCompError,
821                                                 SMESH::compute_error_array_var& theCompErrors,
822                                                 const bool theNoHypoError,
823                                                 const QString& theHypErrors )
824 {
825   bool hasShape = myMesh->HasShapeToMesh();
826   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
827   aCompDlg->myMemoryLackGroup->hide();
828
829   if ( theMemoryLack )
830   {
831     aCompDlg->myMemoryLackGroup->show();
832     aCompDlg->myFullInfo->hide();
833     aCompDlg->myBriefInfo->hide();
834     aCompDlg->myHypErrorGroup->hide();
835     aCompDlg->myCompErrorGroup->hide();
836   }
837   else if ( theNoCompError && theNoHypoError )
838   {
839     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
840     aCompDlg->myFullInfo->SetMeshInfo( aRes );
841     aCompDlg->myFullInfo->show();
842     aCompDlg->myBriefInfo->hide();
843     aCompDlg->myHypErrorGroup->hide();
844     aCompDlg->myCompErrorGroup->hide();
845   }
846   else
847   {
848     QTableWidget* tbl = aCompDlg->myTable;
849     SMESH::long_array_var aRes = myMesh->GetMeshInfo();
850     aCompDlg->myBriefInfo->SetMeshInfo( aRes );
851     aCompDlg->myBriefInfo->show();
852     aCompDlg->myFullInfo->hide();
853
854     if ( theNoHypoError ) {
855       aCompDlg->myHypErrorGroup->hide();
856     }
857     else {
858       aCompDlg->myHypErrorGroup->show();
859       aCompDlg->myHypErrorLabel->setText( theHypErrors );
860     }
861
862     if ( theNoCompError ) {
863       aCompDlg->myCompErrorGroup->hide();
864     }
865     else {
866       aCompDlg->myCompErrorGroup->show();
867
868       if ( !hasShape ) {
869         aCompDlg->myPublishBtn->hide();
870         aCompDlg->myShowBtn->hide();
871       }
872       else {
873         aCompDlg->myPublishBtn->show();
874         aCompDlg->myShowBtn->show();
875       }
876
877       // fill table of errors
878       tbl->setRowCount( theCompErrors->length() );
879       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
880       else             tbl->showColumn( COL_SHAPE );
881       tbl->setColumnWidth( COL_ERROR, 200 );
882
883       bool hasBadMesh = false;
884       for ( int row = 0; row < theCompErrors->length(); ++row )
885       {
886         SMESH::ComputeError & err = theCompErrors[ row ];
887
888         QString text = err.algoName.in();
889         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
890         else tbl->item( row, COL_ALGO )->setText( text );
891
892         text = SMESH::errorText( err.code, err.comment.in() );
893         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
894         else tbl->item( row, COL_ERROR )->setText( text );
895
896         text = QString("%1").arg( err.subShapeID );
897         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
898         else tbl->item( row, COL_SHAPEID )->setText( text );
899
900         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
901         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
902         else tbl->item( row, COL_SHAPE )->setText( text );
903
904         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
905         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
906         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
907
908         text = err.hasBadMesh ? "hasBadMesh" : "";
909         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
910         else tbl->item( row, COL_BAD_MESH )->setText( text );
911         if ( err.hasBadMesh ) hasBadMesh = true;
912
913         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
914         tbl->resizeRowToContents( row );
915       }
916       tbl->resizeColumnToContents( COL_ALGO );
917       tbl->resizeColumnToContents( COL_SHAPE );
918
919       if ( hasBadMesh )
920         aCompDlg->myBadMeshBtn->show();
921       else
922         aCompDlg->myBadMeshBtn->hide();
923
924       tbl->setCurrentCell(0,0);
925       currentCellChanged(); // to update buttons
926     }
927   }
928   // show dialog and wait, becase Compute can be invoked from Preview operation
929   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
930   aCompDlg->show();
931 }
932
933 //================================================================================
934 /*!
935  * \brief Stops operation
936  */
937 //================================================================================
938
939 void SMESHGUI_BaseComputeOp::stopOperation()
940 {
941   SMESHGUI_Operation::stopOperation();
942   if ( myTShapeDisplayer )
943     myTShapeDisplayer->SetVisibility( false );
944   if ( myBadMeshDisplayer ) {
945     myBadMeshDisplayer->SetVisibility( false );
946     // delete it in order not to have problems at its destruction when the viewer
947     // where it worked is dead due to e.g. study closing
948     delete myBadMeshDisplayer;
949     myBadMeshDisplayer = 0;
950   }
951   myIObject.Nullify();
952 }
953
954 //================================================================================
955 /*!
956  * \brief publish selected subshape
957  */
958 //================================================================================
959
960 void SMESHGUI_BaseComputeOp::onPublishShape()
961 {
962   GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
963   SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
964
965   QList<int> rows;
966   SMESH::getSelectedRows( table(), rows );
967   int row;
968   foreach ( row, rows )
969   {
970     int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
971     GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
972     if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
973     {
974       if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
975       {
976         QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
977         SALOMEDS::SObject_var so =
978           geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
979         // look for myMainShape in the table
980         for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
981           if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
982             if ( so->_is_nil() ) {
983               table()->item( r, COL_SHAPE )->setText( so->GetName() );
984               table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
985             }
986             break;
987           }
988         }
989         if ( curSub == 1 ) continue;
990       }
991       QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
992       SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
993       if ( !so->_is_nil() ) {
994         table()->item( row, COL_SHAPE )->setText( so->GetName() );
995         table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
996       }
997     }
998   }
999   getSMESHGUI()->getApp()->updateObjectBrowser();
1000   currentCellChanged(); // to update buttons
1001 }
1002
1003 //================================================================================
1004 /*!
1005  * \brief show mesh elements preventing computation of a submesh of current row
1006  */
1007 //================================================================================
1008
1009 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1010 {
1011   myTShapeDisplayer->SetVisibility( false );
1012   QList<int> rows;
1013   if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1014     bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1015     if ( hasBadMesh ) {
1016       int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1017       SMESHGUI* gui = getSMESHGUI();
1018       SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1019       SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1020       if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1021       myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1022       SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1023       vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1024       vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1025       // delete property !!!!!!!!!!
1026       vtkProperty* prop = vtkProperty::New();
1027       prop->SetLineWidth( aLineWidth * 3 );
1028       prop->SetPointSize( aPointSize * 3 );
1029       prop->SetColor( 250, 0, 250 );
1030       myBadMeshDisplayer->GetActor()->SetProperty( prop );
1031       myBadMeshDisplayer->SetData( aMeshData._retn() );
1032     }
1033   }
1034 }
1035
1036 //================================================================================
1037 /*!
1038  * \brief SLOT called when a selected cell in table() changed
1039  */
1040 //================================================================================
1041
1042 void SMESHGUI_BaseComputeOp::currentCellChanged()
1043 {
1044   myTShapeDisplayer->SetVisibility( false );
1045   if ( myBadMeshDisplayer )
1046     myBadMeshDisplayer->SetVisibility( false );
1047
1048   bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1049   QList<int> rows;
1050   int nbSelected = SMESH::getSelectedRows( table(), rows );
1051   int row;
1052   foreach ( row, rows )
1053   {
1054     bool hasData     = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1055     bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1056     if ( hasData && !isPublished )
1057       publishEnable = true;
1058
1059     int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1060     bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1061     if ( prsReady ) {
1062       myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1063       showOnly = false;
1064     }
1065     else {
1066       showEnable = true;
1067     }
1068
1069     if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1070       hasBadMesh = true;
1071   }
1072   myCompDlg->myPublishBtn->setEnabled( publishEnable );
1073   myCompDlg->myShowBtn   ->setEnabled( showEnable );
1074   myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1075 }
1076
1077 //================================================================================
1078 /*!
1079  * \brief update preview
1080  */
1081 //================================================================================
1082
1083 void SMESHGUI_BaseComputeOp::onPreviewShape()
1084 {
1085   if ( myTShapeDisplayer )
1086   {
1087     SUIT_OverrideCursor aWaitCursor;
1088     QList<int> rows;
1089     SMESH::getSelectedRows( table(), rows );
1090
1091     bool showOnly = true;
1092     int row;
1093     foreach ( row, rows )
1094     {
1095       int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1096       if ( curSub > 0 ) {
1097         myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1098         showOnly = false;
1099       }
1100     }
1101     currentCellChanged(); // to update buttons
1102   }
1103 }
1104
1105 //================================================================================
1106 /*!
1107  * \brief Destructor
1108  */
1109 //================================================================================
1110
1111 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1112 {
1113   delete myCompDlg;
1114   myCompDlg = 0;
1115   delete myTShapeDisplayer;
1116   if ( myBadMeshDisplayer )
1117     delete myBadMeshDisplayer;
1118 }
1119
1120 //================================================================================
1121 /*!
1122  * \brief Gets dialog of compute operation
1123  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1124  */
1125 //================================================================================
1126
1127 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1128 {
1129   if ( !myCompDlg )
1130   {
1131     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1132     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1133     // connect signals and slots
1134     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1135     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1136     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1137
1138     QTableWidget* aTable = me->table();
1139     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1140     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1141   }
1142   return myCompDlg;
1143 }
1144
1145 //================================================================================
1146 /*!
1147  * \brief returns from compute mesh result dialog
1148  */
1149 //================================================================================
1150
1151 bool SMESHGUI_BaseComputeOp::onApply()
1152 {
1153   return true;
1154 }
1155
1156 //================================================================================
1157 /*!
1158  * \brief Return a table
1159  */
1160 //================================================================================
1161
1162 QTableWidget* SMESHGUI_BaseComputeOp::table()
1163 {
1164   return myCompDlg->myTable;
1165 }
1166
1167
1168 //================================================================================
1169 /*!
1170  * \brief Constructor
1171 */
1172 //================================================================================
1173
1174 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1175  : SMESHGUI_BaseComputeOp()
1176 {
1177 }
1178
1179
1180 //================================================================================
1181 /*!
1182  * \brief Desctructor
1183 */
1184 //================================================================================
1185
1186 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1187 {
1188 }
1189
1190 //================================================================================
1191 /*!
1192  * \brief perform it's intention action: compute mesh
1193  */
1194 //================================================================================
1195
1196 void SMESHGUI_ComputeOp::startOperation()
1197 {
1198   SMESHGUI_BaseComputeOp::startOperation();
1199   if (myMesh->_is_nil())
1200     return;
1201   computeMesh();
1202 }
1203
1204 //================================================================================
1205 /*!
1206  * \brief check the same operations on the same mesh
1207  */
1208 //================================================================================
1209
1210 bool SMESHGUI_BaseComputeOp::isValid(  SUIT_Operation* theOp  ) const
1211 {
1212   SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1213   bool ret = true;
1214   if ( !myMesh->_is_nil() && baseOp ) {
1215     SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1216     if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1217   }
1218   return ret;
1219 }
1220
1221 //================================================================================
1222 /*!
1223  * \brief Gets dialog of this operation
1224  * \retval LightApp_Dialog* - pointer to dialog of this operation
1225  */
1226 //================================================================================
1227
1228 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1229 {
1230   return computeDlg();
1231 }
1232
1233 //================================================================================
1234 /*!
1235  * \brief Constructor
1236 */
1237 //================================================================================
1238
1239 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1240  : SMESHGUI_BaseComputeOp(),
1241  myDlg( 0 ),
1242  myOrderMgr( 0 ),
1243  myActiveDlg( 0 ),
1244  myPreviewDisplayer( 0 )
1245 {
1246   myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1247 }
1248
1249 //================================================================================
1250 /*!
1251  * \brief Destructor
1252  */
1253 //================================================================================
1254
1255 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1256 {
1257   delete myDlg;
1258   myDlg = 0;
1259   delete myOrderMgr;
1260   myOrderMgr = 0;
1261   myActiveDlg = 0;
1262   if ( myPreviewDisplayer )
1263     delete myPreviewDisplayer;
1264   myPreviewDisplayer = 0;
1265 }
1266
1267 //================================================================================
1268 /*!
1269  * \brief Gets current dialog of this operation
1270  * \retval LightApp_Dialog* - pointer to dialog of this operation
1271  */
1272 //================================================================================
1273
1274 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1275 {
1276   return myActiveDlg;
1277 }
1278
1279 //================================================================================
1280 /*!
1281  * \brief perform it's intention action: prepare data
1282  */
1283 //================================================================================
1284
1285 void SMESHGUI_PrecomputeOp::startOperation()
1286 {
1287   if ( !myDlg )
1288   {
1289     myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1290     
1291     // connect signals
1292     connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1293     connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1294     connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1295   }
1296   myActiveDlg = myDlg;
1297
1298   // connect signal to compute dialog. which will be shown after Compute mesh operation
1299   SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1300   if ( cmpDlg )
1301   {
1302     // disconnect signals
1303     disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1304     disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1305     disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1306     disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1307     disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1308
1309     // connect signals
1310     if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1311       connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1312     if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1313       connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1314     if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1315       connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1316     if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1317       connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1318     if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1319       connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1320   }
1321
1322   SMESHGUI_BaseComputeOp::startOperation();
1323   if (myMesh->_is_nil())
1324     return;
1325
1326   if (myDlg->getPreviewMode() == -1)
1327   {
1328     // nothing to preview
1329     SUIT_MessageBox::warning(desktop(),
1330                              tr("SMESH_WRN_WARNING"),
1331                              tr("SMESH_WRN_NOTHING_PREVIEW"));
1332     onCancel();
1333     return;
1334   }
1335
1336   // disconnect slot from preview dialog to have Apply from results of compute operation only 
1337   disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1338   disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1339
1340   myDlg->show();
1341 }
1342
1343 //================================================================================
1344 /*!
1345  * \brief Stops operation
1346  */
1347 //================================================================================
1348
1349 void SMESHGUI_PrecomputeOp::stopOperation()
1350 {
1351   if ( myPreviewDisplayer )
1352   {
1353     myPreviewDisplayer->SetVisibility( false );
1354     delete myPreviewDisplayer;
1355     myPreviewDisplayer = 0;
1356   }
1357   myMapShapeId.clear();
1358   SMESHGUI_BaseComputeOp::stopOperation();
1359 }
1360
1361 //================================================================================
1362 /*!
1363  * \brief reinitialize dialog after operaiton become active again
1364  */
1365 //================================================================================
1366
1367 void SMESHGUI_PrecomputeOp::resumeOperation()
1368 {
1369   if ( myActiveDlg == myDlg )
1370     initDialog();
1371   SMESHGUI_BaseComputeOp::resumeOperation();
1372 }
1373
1374 //================================================================================
1375 /*!
1376  * \brief perform it's intention action: reinitialise dialog
1377  */
1378 //================================================================================
1379
1380 void SMESHGUI_PrecomputeOp::initDialog()
1381 {
1382   QList<int> modes;
1383
1384   QMap<int, int> modeMap;
1385   _PTR(SObject)  pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1386   getAssignedAlgos( pMesh, modeMap );
1387   if ( modeMap.contains( SMESH::DIM_3D ) )
1388   {
1389     if ( modeMap.contains( SMESH::DIM_2D ) )
1390       modes.append( SMESH::DIM_2D );
1391     if ( modeMap.contains( SMESH::DIM_1D ) )
1392       modes.append( SMESH::DIM_1D );
1393   }
1394   else if ( modeMap.contains( SMESH::DIM_2D ) )
1395   {
1396     if ( modeMap.contains( SMESH::DIM_1D ) )
1397       modes.append( SMESH::DIM_1D );
1398   }
1399
1400   myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1401   myOrderMgr->SetMesh( myMesh );
1402   bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1403   myDlg->getMeshOrderBox()->setShown(isOrder);
1404   if ( !isOrder ) {
1405     delete myOrderMgr;
1406     myOrderMgr = 0;
1407   }
1408
1409   myDlg->setPreviewModes( modes );
1410 }
1411
1412 //================================================================================
1413 /*!
1414  * \brief detect asigned mesh algorithms
1415  */
1416 //================================================================================
1417
1418 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1419                                              QMap<int,int>& theModeMap)
1420 {
1421   _PTR(SObject)          aHypRoot;
1422   _PTR(GenericAttribute) anAttr;
1423   int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1424   if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1425   {
1426     _PTR(ChildIterator) anIter =
1427       SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1428     for ( ; anIter->More(); anIter->Next() )
1429     {
1430       _PTR(SObject) anObj = anIter->Value();
1431       _PTR(SObject) aRefObj;
1432       if ( anObj->ReferencedObject( aRefObj ) )
1433         anObj = aRefObj;
1434       else
1435         continue;
1436       
1437       if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1438       {
1439         CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1440         if ( CORBA::is_nil( aVar ) )
1441           continue;
1442         
1443         for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1444         {
1445           SMESH::SMESH_Algo_var algo;
1446           switch(dim) {
1447           case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1448           case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1449           case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1450           default: break;
1451           }
1452           if ( !algo->_is_nil() )
1453             theModeMap[ dim ] = 0;
1454         }
1455       }
1456     }
1457   }
1458 }
1459
1460 //================================================================================
1461 /*!
1462  * \brief perform it's intention action: compute mesh
1463  */
1464 //================================================================================
1465
1466 void SMESHGUI_PrecomputeOp::onCompute()
1467 {
1468   myDlg->hide();
1469   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1470     myOrderMgr->SetMeshOrder();
1471   myMapShapeId.clear();
1472   myActiveDlg = computeDlg();
1473   computeMesh();
1474 }
1475
1476 //================================================================================
1477 /*!
1478  * \brief perform it's intention action: compute mesh
1479  */
1480 //================================================================================
1481
1482 void SMESHGUI_PrecomputeOp::onCancel()
1483 {
1484   QObject* curDlg = sender();
1485   if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1486   {
1487     // return from error messages
1488     myDlg->show();
1489     return;
1490   }
1491
1492   bool isRestoreOrder = false;
1493   if ( myActiveDlg == myDlg  && !myMesh->_is_nil() && myMapShapeId.count() )
1494   {
1495     // ask to remove already computed mesh elements
1496     if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1497                                     tr( "CLEAR_SUBMESH_QUESTION" ),
1498                                     tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1499     {
1500       // remove all submeshes for collected shapes
1501       QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1502       for ( ; it != myMapShapeId.constEnd(); ++it )
1503         myMesh->ClearSubMesh( *it );
1504       isRestoreOrder = true;
1505     }
1506   }
1507
1508   // return previous mesh order
1509   if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1510     if (!isRestoreOrder)
1511       isRestoreOrder = 
1512         (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1513                                     tr( "SMESH_REJECT_MESH_ORDER" ),
1514                                     tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1515     if (isRestoreOrder)
1516       myOrderMgr->SetMeshOrder(myPrevOrder);
1517   }
1518
1519   delete myOrderMgr;
1520   myOrderMgr = 0;
1521
1522   myMapShapeId.clear();
1523   SMESHGUI_BaseComputeOp::onCancel();
1524 }
1525
1526 //================================================================================
1527 /*!
1528  * \brief perform it's intention action: preview mesh
1529  */
1530 //================================================================================
1531
1532 void SMESHGUI_PrecomputeOp::onPreview()
1533 {
1534   if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1535     return;
1536
1537   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1538   if ( !aMeshSObj )
1539     return;
1540
1541   // set modified submesh priority if any
1542   if (myOrderMgr && myOrderMgr->IsOrderChanged())
1543     myOrderMgr->SetMeshOrder();
1544
1545   // Compute preview of mesh, 
1546   // i.e. compute mesh till indicated dimension
1547   int dim = myDlg->getPreviewMode();
1548   
1549   SMESH::MemoryReserve aMemoryReserve;
1550   
1551   SMESH::compute_error_array_var aCompErrors;
1552   QString                        aHypErrors;
1553
1554   bool computeFailed = true, memoryLack = false;
1555
1556   SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1557     aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1558
1559   SMESHGUI* gui = getSMESHGUI();
1560   SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1561   SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1562   if ( errors->length() > 0 ) {
1563     aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1564   }
1565
1566   SUIT_OverrideCursor aWaitCursor;
1567
1568   SVTK_ViewWindow*    view = SMESH::GetViewWindow( gui );
1569   if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1570   myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1571   
1572   SMESH::long_array_var aShapesId = new SMESH::long_array();
1573   try {
1574 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1575     OCC_CATCH_SIGNALS;
1576 #endif
1577       
1578     SMESH::MeshPreviewStruct_var previewData =
1579       gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1580
1581     SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1582     if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1583     {
1584       computeFailed = false;
1585       myPreviewDisplayer->SetData( previewRes );
1586       // append shape indeces with computed mesh entities
1587       for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1588         myMapShapeId[ aShapesId[ i ] ] = 0;
1589     }
1590     else
1591       myPreviewDisplayer->SetVisibility(false);
1592   }
1593   catch(const SALOME::SALOME_Exception & S_ex){
1594     memoryLack = true;
1595     myPreviewDisplayer->SetVisibility(false);
1596   }
1597
1598   try {
1599 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1600     OCC_CATCH_SIGNALS;
1601 #endif
1602     aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1603     // check if there are memory problems
1604     for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1605       memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1606   }
1607   catch(const SALOME::SALOME_Exception & S_ex){
1608     memoryLack = true;
1609   }
1610
1611   if ( memoryLack )
1612     aMemoryReserve.release();
1613
1614   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1615   bool noHypoError = ( aHypErrors.isEmpty() );
1616
1617   SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1618   int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1619
1620   bool isShowError = true;
1621   switch( aNotifyMode ) {
1622   case 0: // show the mesh computation result dialog NEVER
1623     isShowError = false;
1624     break;
1625   case 1: // show the mesh computation result dialog if there are some errors
1626   default: // show the result dialog after each mesh computation
1627     if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1628       isShowError = false;
1629     break;
1630   }
1631
1632   aWaitCursor.suspend();
1633   // SHOW ERRORS
1634   if ( isShowError )
1635   {
1636     myDlg->hide();
1637     aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1638     showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1639   }
1640 }
1641
1642
1643 //================================================================================
1644 /*!
1645  * \brief Constructor
1646 */
1647 //================================================================================
1648
1649 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1650  : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1651    myOrderBox(0)
1652 {
1653   setWindowTitle( tr( "CAPTION" ) );
1654
1655   setButtonText( OK, tr( "COMPUTE" ) );
1656   QFrame* main = mainFrame();
1657
1658   QVBoxLayout* layout = new QVBoxLayout( main );
1659
1660   myOrderBox = new SMESHGUI_MeshOrderBox( main );
1661   layout->addWidget(myOrderBox);
1662
1663   QFrame* frame = new QFrame( main );
1664   layout->setMargin(0); layout->setSpacing(0);
1665   layout->addWidget( frame );
1666
1667   QHBoxLayout* frameLay = new QHBoxLayout( frame );
1668   frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1669   
1670   myPreviewMode = new QtxComboBox( frame );
1671   frameLay->addWidget( myPreviewMode );
1672
1673   myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1674   frameLay->addWidget( myPreviewBtn );
1675
1676   connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1677 }
1678
1679 //================================================================================
1680 /*!
1681  * \brief Destructor
1682 */
1683 //================================================================================
1684
1685 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1686 {
1687 }
1688
1689 //================================================================================
1690 /*!
1691  * \brief Sets available preview modes
1692 */
1693 //================================================================================
1694
1695 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1696 {
1697   myPreviewMode->clear();
1698   QList<int>::const_iterator it = theModes.constBegin();
1699   for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1700   {
1701     QString mode = QString( "PREVIEW_%1" ).arg( *it );
1702     myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1703     myPreviewMode->setId( i, *it );
1704   }
1705   myPreviewBtn->setEnabled( !theModes.isEmpty() );
1706 }
1707
1708 //================================================================================
1709 /*!
1710  * \brief Returns current preview mesh mode
1711 */
1712 //================================================================================
1713
1714 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1715 {
1716   return myPreviewMode->currentId();
1717 }
1718
1719 //================================================================================
1720 /*!
1721  * \brief Returns current preview mesh mode
1722 */
1723 //================================================================================
1724
1725 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1726 {
1727   return myOrderBox;
1728 }
1729
1730
1731 //================================================================================
1732 /*!
1733  * \brief Constructor
1734 */
1735 //================================================================================
1736
1737 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1738  : SMESHGUI_BaseComputeOp()
1739 {
1740 }
1741
1742
1743 //================================================================================
1744 /*!
1745  * \brief Desctructor
1746 */
1747 //================================================================================
1748
1749 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1750 {
1751 }
1752
1753 //================================================================================
1754 /*!
1755  * \brief perform it's intention action: compute mesh
1756  */
1757 //================================================================================
1758
1759 void SMESHGUI_EvaluateOp::startOperation()
1760 {
1761   SMESHGUI_BaseComputeOp::evaluateDlg();
1762   SMESHGUI_BaseComputeOp::startOperation();
1763   if (myMesh->_is_nil())
1764     return;
1765   evaluateMesh();
1766 }
1767
1768 //================================================================================
1769 /*!
1770  * \brief Gets dialog of this operation
1771  * \retval LightApp_Dialog* - pointer to dialog of this operation
1772  */
1773 //================================================================================
1774
1775 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1776 {
1777   return evaluateDlg();
1778 }
1779
1780 //================================================================================
1781 /*!
1782  * \brief evaluateMesh()
1783 */
1784 //================================================================================
1785
1786 void SMESHGUI_BaseComputeOp::evaluateMesh()
1787 {
1788   // EVALUATE MESH
1789
1790   SMESH::MemoryReserve aMemoryReserve;
1791
1792   SMESH::compute_error_array_var aCompErrors;
1793   QString                        aHypErrors;
1794
1795   bool evaluateFailed = true, memoryLack = false;
1796   SMESH::long_array_var aRes;
1797
1798   _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1799   if ( !aMeshSObj ) //  IPAL21340
1800     return;
1801
1802   bool hasShape = myMesh->HasShapeToMesh();
1803   bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1804   if ( shapeOK )
1805   {
1806     myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1807     SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1808     SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1809     if ( errors->length() > 0 ) {
1810       aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1811     }
1812     SUIT_OverrideCursor aWaitCursor;
1813     try {
1814 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1815       OCC_CATCH_SIGNALS;
1816 #endif
1817       aRes = gen->Evaluate(myMesh, myMainShape);
1818     }
1819     catch(const SALOME::SALOME_Exception & S_ex){
1820       memoryLack = true;
1821     }
1822
1823     try {
1824 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1825       OCC_CATCH_SIGNALS;
1826 #endif
1827       aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1828     }
1829     catch(const SALOME::SALOME_Exception & S_ex){
1830       memoryLack = true;
1831     }
1832   }
1833
1834   if ( memoryLack )
1835     aMemoryReserve.release();
1836
1837   evaluateFailed =  ( aCompErrors->length() > 0 );
1838   myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1839
1840   // SHOW ERRORS
1841   
1842   bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1843   bool noHypoError = ( aHypErrors.isEmpty() );
1844
1845   //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1846   //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1847
1848   bool isShowResultDlg = true;
1849   //if( noHypoError )
1850   //switch( aNotifyMode ) {
1851   //case 0: // show the mesh computation result dialog NEVER
1852   //isShowResultDlg = false;
1853   //commit();
1854   //break;
1855   //case 1: // show the mesh computation result dialog if there are some errors
1856   //if ( memoryLack || !noHypoError )
1857   //  isShowResultDlg = true;
1858   //else
1859   //{
1860   //  isShowResultDlg = false;
1861   //  commit();
1862   //}
1863   //break;
1864   //default: // show the result dialog after each mesh computation
1865   //isShowResultDlg = true;
1866   //}
1867
1868   // SHOW RESULTS
1869   if ( isShowResultDlg )
1870     showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1871                         noHypoError, aHypErrors);
1872 }
1873
1874
1875 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1876                                                 const bool theMemoryLack,
1877                                                 const bool theNoCompError,
1878                                                 SMESH::compute_error_array_var& theCompErrors,
1879                                                 const bool theNoHypoError,
1880                                                 const QString& theHypErrors)
1881 {
1882   bool hasShape = myMesh->HasShapeToMesh();
1883   SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1884   aCompDlg->myMemoryLackGroup->hide();
1885
1886   if ( theMemoryLack )
1887   {
1888     aCompDlg->myMemoryLackGroup->show();
1889     aCompDlg->myFullInfo->hide();
1890     aCompDlg->myBriefInfo->hide();
1891     aCompDlg->myHypErrorGroup->hide();
1892     aCompDlg->myCompErrorGroup->hide();
1893   }
1894   else if ( theNoCompError && theNoHypoError )
1895   {
1896     aCompDlg->myFullInfo->SetMeshInfo( theRes );
1897     aCompDlg->myFullInfo->show();
1898     aCompDlg->myBriefInfo->hide();
1899     aCompDlg->myHypErrorGroup->hide();
1900     aCompDlg->myCompErrorGroup->hide();
1901   }
1902   else
1903   {
1904     QTableWidget* tbl = aCompDlg->myTable;
1905     aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1906     aCompDlg->myBriefInfo->show();
1907     aCompDlg->myFullInfo->hide();
1908
1909     if ( theNoHypoError ) {
1910       aCompDlg->myHypErrorGroup->hide();
1911     }
1912     else {
1913       aCompDlg->myHypErrorGroup->show();
1914       aCompDlg->myHypErrorLabel->setText( theHypErrors );
1915     }
1916
1917     if ( theNoCompError ) {
1918       aCompDlg->myCompErrorGroup->hide();
1919     }
1920     else {
1921       aCompDlg->myCompErrorGroup->show();
1922
1923       aCompDlg->myPublishBtn->hide();
1924       aCompDlg->myShowBtn->hide();
1925
1926       // fill table of errors
1927       tbl->setRowCount( theCompErrors->length() );
1928       if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1929       else             tbl->showColumn( COL_SHAPE );
1930       tbl->setColumnWidth( COL_ERROR, 200 );
1931
1932       bool hasBadMesh = false;
1933       for ( int row = 0; row < theCompErrors->length(); ++row )
1934       {
1935         SMESH::ComputeError & err = theCompErrors[ row ];
1936
1937         QString text = err.algoName.in();
1938         if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1939         else tbl->item( row, COL_ALGO )->setText( text );
1940
1941         text = SMESH::errorText( err.code, err.comment.in() );
1942         if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1943         else tbl->item( row, COL_ERROR )->setText( text );
1944
1945         text = QString("%1").arg( err.subShapeID );
1946         if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1947         else tbl->item( row, COL_SHAPEID )->setText( text );
1948
1949         text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1950         if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1951         else tbl->item( row, COL_SHAPE )->setText( text );
1952
1953         text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1954         if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1955         else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1956
1957         text = err.hasBadMesh ? "hasBadMesh" : "";
1958         if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1959         else tbl->item( row, COL_BAD_MESH )->setText( text );
1960         if ( err.hasBadMesh ) hasBadMesh = true;
1961
1962         //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1963         tbl->resizeRowToContents( row );
1964       }
1965       tbl->resizeColumnToContents( COL_ALGO );
1966       tbl->resizeColumnToContents( COL_SHAPE );
1967
1968       if ( hasBadMesh )
1969         aCompDlg->myBadMeshBtn->show();
1970       else
1971         aCompDlg->myBadMeshBtn->hide();
1972
1973       tbl->setCurrentCell(0,0);
1974       currentCellChanged(); // to update buttons
1975     }
1976   }
1977   // show dialog and wait, becase Compute can be invoked from Preview operation
1978   //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1979   aCompDlg->show();
1980 }
1981
1982
1983 //================================================================================
1984 /*!
1985  * \brief Gets dialog of evaluate operation
1986  * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1987  */
1988 //================================================================================
1989
1990 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1991 {
1992   if ( !myCompDlg )
1993   {
1994     SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1995     me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1996     // connect signals and slots
1997     connect(myCompDlg->myShowBtn,    SIGNAL (clicked()), SLOT(onPreviewShape()));
1998     connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1999     connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2000     QTableWidget* aTable = me->table();
2001     connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2002     connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
2003   }
2004   return myCompDlg;
2005 }
2006