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