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