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