1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_ComputeDlg.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
24 #include "SMESHGUI_ComputeDlg.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"
36 #include "SMESH_Actor.h"
37 #include "SMESH_ActorUtils.h"
39 #include <SMDS_SetIterator.hxx>
40 #include <SMDS_Mesh.hxx>
42 // SALOME GEOM includes
44 #include <GEOM_Actor.h>
45 #include <GEOM_wrap.hxx>
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>
60 // SALOME KERNEL includes
61 #include <SALOMEDS_SObject.hxx>
62 #include <SALOMEDSClient_SObject.hxx>
63 #include <SALOMEDS_wrap.hxx>
65 #include CORBA_SERVER_HEADER(SMESH_Group)
68 #include <BRep_Tool.hxx>
70 #include <TopExp_Explorer.hxx>
71 #include <TopTools_IndexedMapOfShape.hxx>
74 #include <TopLoc_Location.hxx>
75 #include <Poly_Triangulation.hxx>
76 #include <Bnd_Box.hxx>
77 #include <BRepBndLib.hxx>
78 #include <BRepMesh_IncrementalMesh.hxx>
80 #include <Standard_ErrorHandler.hxx>
84 #include <QPushButton>
86 #include <QRadioButton>
87 #include <QTableWidget>
88 #include <QHeaderView>
89 #include <QGridLayout>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QButtonGroup>
93 #include <QCloseEvent>
94 #include <QTimerEvent>
95 #include <QProgressBar>
98 #include <vtkProperty.h>
105 #include <sys/sysinfo.h>
111 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
114 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
117 //using namespace SMESH;
121 //=============================================================================
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
127 //=============================================================================
132 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
133 void release() { delete [] myBuf; myBuf = 0; }
134 ~MemoryReserve() { release(); }
137 // =========================================================================================
139 * \brief Class showing shapes without publishing
141 // =========================================================================================
143 class TShapeDisplayer
146 // -----------------------------------------------------------------------
147 TShapeDisplayer(): myViewWindow(0)
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 );
157 // -----------------------------------------------------------------------
161 myProperty->Delete();
163 // -----------------------------------------------------------------------
166 if ( hasViewWindow() ) {
167 TActorIterator actorIt = actorIterator();
168 while ( actorIt.more() )
169 if (VTKViewer_Actor* anActor = actorIt.next()) {
170 myViewWindow->RemoveActor( anActor );
174 myIndexToShape.Clear();
176 myShownActors.clear();
179 // -----------------------------------------------------------------------
180 void SetVisibility (bool theVisibility)
182 TActorIterator actorIt = shownIterator();
183 while ( actorIt.more() )
184 if (VTKViewer_Actor* anActor = actorIt.next())
185 anActor->SetVisibility(theVisibility);
186 SMESH::RepaintCurrentView();
188 // -----------------------------------------------------------------------
189 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
191 std::string mainEntry;
192 if ( !aMainShape->_is_nil() )
193 mainEntry = aMainShape->GetStudyEntry();
194 return ( myMainEntry == mainEntry &&
195 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
197 // -----------------------------------------------------------------------
198 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
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
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() );
213 myMainEntry = mainEntry;
214 myViewWindow = aViewWindow;
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();
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 );
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 );
241 myBuiltSubs.insert( subShapeID );
244 // -----------------------------------------------------------------------
248 typedef std::vector<GEOM_Actor*> TActorVec;
250 TActorVec myShownActors;
251 TopTools_IndexedMapOfShape myIndexToShape;
252 std::string myMainEntry;
253 SVTK_ViewWindow* myViewWindow;
254 vtkProperty* myProperty;
255 std::set<int> myBuiltSubs;
257 // -----------------------------------------------------------------------
258 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
259 TActorIterator actorIterator() {
260 return TActorIterator( myActors.begin(), myActors.end() );
262 TActorIterator shownIterator() {
263 return TActorIterator( myShownActors.begin(), myShownActors.end() );
265 // -----------------------------------------------------------------------
266 GEOM_Actor* getActor(const TopoDS_Shape& shape)
268 int index = myIndexToShape.FindIndex( shape ) - 1;
269 if ( index < 0 || index >= myActors.size() )
271 GEOM_Actor* & actor = myActors[ index ];
273 actor = GEOM_Actor::New();
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 );
288 // -----------------------------------------------------------------------
289 void checkTriangulation(const TopoDS_Shape& shape)
291 TopLoc_Location aLoc;
292 Standard_Boolean alreadymesh = Standard_True;
293 TopExp_Explorer ex(shape, TopAbs_FACE);
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; }
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; }
306 if (alreadymesh) return;
307 // Compute default deflection
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);
315 // -----------------------------------------------------------------------
316 bool hasViewWindow() const
318 if ( !myViewWindow ) return false;
320 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
321 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
327 // =========================================================================================
329 * \brief Return text describing an error
331 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
332 QString errorText(int errCode, const char* comment)
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 CASE2TEXT( COMPERR_CANCELED );
345 CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
346 case SMESH::COMPERR_ALGO_FAILED:
347 if ( strlen(comment) == 0 )
348 text = QObject::tr("COMPERR_ALGO_FAILED");
350 case SMESH::COMPERR_WARNING:
351 text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
354 text = QString("#%1").arg( -errCode );
356 if ( text.length() > 0 ) text += ". ";
357 return text + comment;
359 // -----------------------------------------------------------------------
361 * \brief Return SO of a sub-shape
363 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
365 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
366 if ( subShapeID == 1 || !so )
368 _PTR(ChildIterator) it;
369 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
370 it = study->NewChildIterator(so);
373 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
374 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
375 if ( !geom->_is_nil() ) {
376 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
377 if ( list->length() == 1 && list[0] == subShapeID )
384 // -----------------------------------------------------------------------
386 * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
388 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
390 GEOM::GEOM_Object_var aSubShape;
391 if ( subShapeID == 1 ) {
392 aSubShape = aMainShape;
393 aSubShape->Register();
395 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
396 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
397 aSubShape->Register();
400 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
401 // future call of UnRegister() will delete a servant of this new object
403 return aSubShape._retn();
405 // -----------------------------------------------------------------------
407 * \brief Return shape type name
409 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
410 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
413 if ( !aShape->_is_nil() ) {
414 switch ( aShape->GetShapeType() ) {
421 CASE2NAME( COMPSOLID );
422 CASE2NAME( COMPOUND );
428 // -----------------------------------------------------------------------
430 * \brief Return text describing a sub-shape
432 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
435 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
436 text = aSO->GetName().c_str();
438 text = QString("#%1").arg( subShapeID );
439 GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
440 QString typeName = shapeTypeName( shape );
441 if ( typeName.length() )
442 text += QString(" (%1)").arg(typeName);
446 // -----------------------------------------------------------------------
448 * \brief Return a list of selected rows
450 int getSelectedRows(QTableWidget* table, QList<int>& rows)
453 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
454 QTableWidgetSelectionRange range;
455 foreach( range, selRanges )
457 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
458 if ( !rows.count( row ))
461 if ( rows.isEmpty() && table->currentRow() > -1 )
462 if ( !rows.count( table->currentRow() ))
463 rows.append( table->currentRow() );
471 // =========================================================================================
473 * \brief Dialog to compute a mesh and show computation errors
475 //=======================================================================
477 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
478 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
480 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
481 aDlgLay->setMargin( 0 );
482 aDlgLay->setSpacing( SPACING );
484 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
486 aDlgLay->addWidget(aMainFrame);
488 aDlgLay->setStretchFactor(aMainFrame, 1);
491 // =========================================================================================
495 //=======================================================================
497 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
501 //=======================================================================
502 // function : createMainFrame()
503 // purpose : Create frame containing dialog's fields
504 //=======================================================================
506 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
508 QFrame* aFrame = new QFrame(theParent);
510 SUIT_ResourceMgr* rm = resourceMgr();
511 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
517 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
520 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
522 QButtonGroup* aBtnGrp = new QButtonGroup(this);
523 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
524 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
526 QRadioButton* aRBut = new QRadioButton(aPixGrp);
527 aRBut->setIcon(iconCompute);
528 aRBut->setChecked(true);
529 aPixGrpLayout->addWidget(aRBut);
530 aBtnGrp->addButton(aRBut, 0);
534 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
535 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
536 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
537 myMeshName = new QLabel(nameBox);
538 nameBoxLayout->addWidget(myMeshName);
542 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
543 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
545 // Computation errors
547 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
548 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
549 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
550 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
551 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
552 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
553 myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
555 //myTable->setReadOnly( true ); // VSR: check
556 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
557 myTable->hideColumn( COL_PUBLISHED );
558 myTable->hideColumn( COL_SHAPEID );
559 myTable->hideColumn( COL_BAD_MESH );
560 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
561 myTable->setWordWrap( true );
562 myTable->horizontalHeader()->setStretchLastSection( true );
563 myTable->setMinimumWidth( 500 );
566 headers << tr( "COL_ALGO_HEADER" );
567 headers << tr( "COL_SHAPE_HEADER" );
568 headers << tr( "COL_ERROR_HEADER" );
569 headers << tr( "COL_SHAPEID_HEADER" );
570 headers << tr( "COL_PUBLISHED_HEADER" );
572 myTable->setHorizontalHeaderLabels( headers );
575 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
576 grpLayout->setSpacing(SPACING);
577 grpLayout->setMargin(MARGIN);
578 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
579 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
580 grpLayout->addWidget( myShowBtn, 2, 0 );
581 grpLayout->addWidget( myPublishBtn, 2, 1 );
582 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
583 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
584 grpLayout->setColumnStretch( 3, 1 );
586 // Hypothesis definition errors
588 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
589 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
590 myHypErrorGroupLayout->setMargin(MARGIN);
591 myHypErrorGroupLayout->setSpacing(SPACING);
592 myHypErrorLabel = new QLabel(myHypErrorGroup);
593 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
597 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
598 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
599 myMemoryLackGroupLayout->setMargin(MARGIN);
600 myMemoryLackGroupLayout->setSpacing(SPACING);
601 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
602 QFont bold = memLackLabel->font(); bold.setBold(true);
603 memLackLabel->setFont( bold );
604 memLackLabel->setMinimumWidth(300);
605 myMemoryLackGroupLayout->addWidget(memLackLabel);
607 // add all widgets to aFrame
608 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
609 aLay->setMargin( 0 );
610 aLay->setSpacing( 0 );
611 aLay->addWidget( aPixGrp );
612 aLay->addWidget( nameBox );
613 aLay->addWidget( myBriefInfo );
614 aLay->addWidget( myFullInfo );
615 aLay->addWidget( myHypErrorGroup );
616 aLay->addWidget( myCompErrorGroup );
617 aLay->addWidget( myMemoryLackGroup );
618 aLay->setStretchFactor( myCompErrorGroup, 1 );
620 ((QPushButton*) button( OK ))->setDefault( true );
625 //================================================================================
629 //================================================================================
631 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
632 : SMESHGUI_Operation(), myCompDlg( 0 )
634 myTShapeDisplayer = new SMESH::TShapeDisplayer();
635 myBadMeshDisplayer = 0;
637 //myHelpFileName = "/files/about_meshes.htm"; // V3
638 myHelpFileName = "about_meshes_page.html"; // V4
641 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
643 LightApp_SelectionMgr* Sel = selectionMgr();
644 SALOME_ListIO selected; Sel->selectedObjects( selected );
645 Handle(SALOME_InteractiveObject) anIO = selected.First();
646 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
647 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
650 //================================================================================
652 * \brief Start operation
653 * \purpose Init dialog fields, connect signals and slots, show dialog
655 //================================================================================
657 void SMESHGUI_BaseComputeOp::startOperation()
659 // create compute dialog if not created before
662 myMesh = SMESH::SMESH_Mesh::_nil();
663 myMainShape = GEOM::GEOM_Object::_nil();
666 LightApp_SelectionMgr *Sel = selectionMgr();
667 SALOME_ListIO selected; Sel->selectedObjects( selected );
669 int nbSel = selected.Extent();
671 SUIT_MessageBox::warning(desktop(),
672 tr("SMESH_WRN_WARNING"),
673 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
678 myIObject = selected.First();
679 myMesh = SMESH::GetMeshByIO(myIObject);
680 if (myMesh->_is_nil()) {
681 SUIT_MessageBox::warning(desktop(),
682 tr("SMESH_WRN_WARNING"),
683 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
687 myMainShape = myMesh->GetShapeToMesh();
689 SMESHGUI_Operation::startOperation();
692 //================================================================================
693 //================================================================================
695 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
696 SMESH::SMESH_Mesh_var mesh,
697 GEOM::GEOM_Object_var mainShape)
702 myMainShape = mainShape;
705 void SMESHGUI_ComputeDlg_QThread::run()
707 myResult = myGen->Compute(myMesh, myMainShape);
710 bool SMESHGUI_ComputeDlg_QThread::result()
715 void SMESHGUI_ComputeDlg_QThread::cancel()
717 myGen->CancelCompute(myMesh, myMainShape);
720 //================================================================================
721 //================================================================================
723 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
724 SMESH::SMESH_Gen_var gen,
725 SMESH::SMESH_Mesh_var mesh,
726 GEOM::GEOM_Object_var mainShape)
728 Qt::WindowSystemMenuHint |
729 Qt::WindowCloseButtonHint |
731 Qt::WindowMaximizeButtonHint),
732 qthread(gen, mesh, mainShape)
735 setWindowTitle(tr("TITLE"));
736 setMinimumWidth( 200 );
738 cancelButton = new QPushButton(tr("CANCEL"));
739 cancelButton->setDefault(true);
740 cancelButton->setCheckable(true);
742 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
743 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
744 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
745 nbNodesLabel = new QLabel("0", this );
746 nbElemsLabel = new QLabel("0", this );
747 freeRAMLabel = new QLabel("", this );
748 progressBar = new QProgressBar(this);
749 progressBar->setMinimum( 0 );
750 progressBar->setMaximum( 1000 );
752 QGridLayout* layout = new QGridLayout(this);
753 layout->setMargin( MARGIN );
754 layout->setSpacing( SPACING );
756 layout->addWidget(nbNodesName, row, 0);
757 layout->addWidget(nbNodesLabel, row++, 1);
758 layout->addWidget(nbElemsName, row, 0);
759 layout->addWidget(nbElemsLabel, row++, 1);
761 layout->addWidget(freeRAMName, row, 0);
762 layout->addWidget(freeRAMLabel, row++, 1);
764 layout->addWidget(progressBar, row++, 0, 1, 2);
765 layout->addWidget(cancelButton, row++, 0, 1, 2);
769 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
771 startTimer(300); // millisecs
775 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
777 return qthread.result();
780 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
783 cancelButton->setText( tr("CANCELING"));
784 cancelButton->setEnabled(false);
787 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
789 if ( !cancelButton->isChecked() ) // not yet cancelled
790 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
792 if(qthread.isFinished())
798 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
799 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
802 const int err = sysinfo( &si );
804 freeRAMLabel->setText("");
806 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
807 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
813 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
815 if(qthread.isRunning())
823 //================================================================================
825 * \brief computeMesh()
827 //================================================================================
829 void SMESHGUI_BaseComputeOp::computeMesh()
833 SMESH::MemoryReserve aMemoryReserve;
835 SMESH::compute_error_array_var aCompErrors;
838 bool computeFailed = true, memoryLack = false;
840 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
841 if ( !aMeshSObj ) // IPAL 21340
843 bool hasShape = myMesh->HasShapeToMesh();
844 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
847 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
848 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
849 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
850 if ( errors->length() > 0 ) {
851 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
853 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
854 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
855 tr( "FULL_RECOMPUTE_QUESTION" ),
856 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
858 SUIT_OverrideCursor aWaitCursor;
860 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
863 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
864 qthreaddialog.exec();
865 computeFailed = !qthreaddialog.result();
867 catch(const SALOME::SALOME_Exception & S_ex) {
871 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
874 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
875 // check if there are memory problems
876 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
877 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
879 catch(const SALOME::SALOME_Exception & S_ex) {
883 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
887 // NPAL16631: if ( !memoryLack )
889 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
890 update( UF_ObjBrowser | UF_Model );
893 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
894 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
896 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
897 int entities = SMESH_Actor::eAllEntity;
901 if ( getSMESHGUI()->automaticUpdate( myMesh, &entities, &limitExceeded, &hidden ) )
904 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
907 SMESH_Actor *anActor = SMESH::FindActorByObject( myMesh );
908 if ( !anActor ) anActor = SMESH::CreateActor( aMeshSObj->GetStudy(), aMeshSObj->GetID().c_str(), true );
909 if ( anActor ) // actor is not created for an empty mesh
911 anActor->SetEntityMode( entities );
912 SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
914 SMESH::Update(myIObject, true);
918 QStringList hiddenMsg;
919 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
920 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
921 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
922 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
923 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
924 SUIT_MessageBox::warning( desktop(),
925 tr( "SMESH_WRN_WARNING" ),
926 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).arg( myMesh->NbElements() ).arg( limitSize ).arg( hiddenMsg.join(", ") ) );
931 MESSAGE ( "Exception thrown during mesh visualization" );
933 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
934 SMESH::OnVisuException();
941 else if ( limitExceeded )
943 SUIT_MessageBox::warning( desktop(),
944 tr( "SMESH_WRN_WARNING" ),
945 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( myMesh->NbElements() ).arg( limitSize ) );
948 LightApp_SelectionMgr *Sel = selectionMgr();
951 SALOME_ListIO selected;
952 selected.Append( myIObject );
953 Sel->setSelectedObjects( selected );
959 aMemoryReserve.release();
961 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
965 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
966 bool noHypoError = ( aHypErrors.isEmpty() );
968 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
969 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
971 bool isShowResultDlg = true;
972 switch( aNotifyMode ) {
973 case 0: // show the mesh computation result dialog NEVER
974 isShowResultDlg = false;
977 case 1: // show the mesh computation result dialog if there are some errors
978 if ( memoryLack || !noCompError || !noHypoError )
979 isShowResultDlg = true;
982 isShowResultDlg = false;
986 default: // show the result dialog after each mesh computation
987 isShowResultDlg = true;
991 if ( isShowResultDlg )
992 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
995 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
996 const bool theNoCompError,
997 SMESH::compute_error_array_var& theCompErrors,
998 const bool theNoHypoError,
999 const QString& theHypErrors )
1001 bool hasShape = myMesh->HasShapeToMesh();
1002 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1003 aCompDlg->myMemoryLackGroup->hide();
1005 if ( theMemoryLack )
1007 aCompDlg->myMemoryLackGroup->show();
1008 aCompDlg->myFullInfo->hide();
1009 aCompDlg->myBriefInfo->hide();
1010 aCompDlg->myHypErrorGroup->hide();
1011 aCompDlg->myCompErrorGroup->hide();
1013 else if ( theNoCompError && theNoHypoError )
1015 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1016 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1017 aCompDlg->myFullInfo->show();
1018 aCompDlg->myBriefInfo->hide();
1019 aCompDlg->myHypErrorGroup->hide();
1020 aCompDlg->myCompErrorGroup->hide();
1024 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1025 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1026 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1027 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1029 // full or brief mesh info
1030 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1031 if ( onlyWarnings ) {
1032 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1033 aCompDlg->myFullInfo->show();
1034 aCompDlg->myBriefInfo->hide();
1036 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1037 aCompDlg->myBriefInfo->show();
1038 aCompDlg->myFullInfo->hide();
1041 // pbs of hypo dfinitions
1042 if ( theNoHypoError ) {
1043 aCompDlg->myHypErrorGroup->hide();
1045 aCompDlg->myHypErrorGroup->show();
1046 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1050 if ( theNoCompError )
1052 aCompDlg->myCompErrorGroup->hide();
1056 aCompDlg->myCompErrorGroup->show();
1059 aCompDlg->myWarningLabel->show();
1061 aCompDlg->myWarningLabel->hide();
1064 aCompDlg->myPublishBtn->hide();
1065 aCompDlg->myShowBtn->hide();
1068 aCompDlg->myPublishBtn->show();
1069 aCompDlg->myShowBtn->show();
1072 // fill table of errors
1073 QTableWidget* tbl = aCompDlg->myTable;
1074 tbl->setRowCount( theCompErrors->length() );
1075 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1076 else tbl->showColumn( COL_SHAPE );
1077 tbl->setColumnWidth( COL_ERROR, 200 );
1079 bool hasBadMesh = false;
1080 for ( int row = 0; row < theCompErrors->length(); ++row )
1082 SMESH::ComputeError & err = theCompErrors[ row ];
1084 QString text = err.algoName.in();
1085 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1086 else tbl->item( row, COL_ALGO )->setText( text );
1088 text = SMESH::errorText( err.code, err.comment.in() );
1089 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1090 else tbl->item( row, COL_ERROR )->setText( text );
1092 text = QString("%1").arg( err.subShapeID );
1093 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1094 else tbl->item( row, COL_SHAPEID )->setText( text );
1096 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1097 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1098 else tbl->item( row, COL_SHAPE )->setText( text );
1100 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1101 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1102 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1104 text = err.hasBadMesh ? "hasBadMesh" : "";
1105 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1106 else tbl->item( row, COL_BAD_MESH )->setText( text );
1107 if ( err.hasBadMesh ) hasBadMesh = true;
1109 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1110 tbl->resizeRowToContents( row );
1112 tbl->resizeColumnToContents( COL_ALGO );
1113 tbl->resizeColumnToContents( COL_SHAPE );
1114 tbl->setWordWrap( true );
1117 aCompDlg->myBadMeshBtn->show();
1118 aCompDlg->myBadMeshToGroupBtn->show();
1121 aCompDlg->myBadMeshBtn->hide();
1122 aCompDlg->myBadMeshToGroupBtn->hide();
1124 tbl->setCurrentCell(0,0);
1125 currentCellChanged(); // to update buttons
1128 // show dialog and wait, becase Compute can be invoked from Preview operation
1129 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1133 //================================================================================
1135 * \brief Stops operation
1137 //================================================================================
1139 void SMESHGUI_BaseComputeOp::stopOperation()
1141 SMESHGUI_Operation::stopOperation();
1142 if ( myTShapeDisplayer )
1143 myTShapeDisplayer->SetVisibility( false );
1144 if ( myBadMeshDisplayer ) {
1145 myBadMeshDisplayer->SetVisibility( false );
1146 // delete it in order not to have problems at its destruction when the viewer
1147 // where it worked is dead due to e.g. study closing
1148 delete myBadMeshDisplayer;
1149 myBadMeshDisplayer = 0;
1151 myIObject.Nullify();
1154 //================================================================================
1156 * \brief publish selected sub-shape
1158 //================================================================================
1160 void SMESHGUI_BaseComputeOp::onPublishShape()
1162 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1163 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1166 SMESH::getSelectedRows( table(), rows );
1168 foreach ( row, rows )
1170 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1171 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1172 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1174 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1176 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1177 SALOMEDS::SObject_wrap so =
1178 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1179 // look for myMainShape in the table
1180 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1181 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1182 if ( so->_is_nil() ) {
1183 CORBA::String_var name = so->GetName();
1184 CORBA::String_var entry = so->GetID();
1185 table()->item( r, COL_SHAPE )->setText( name.in() );
1186 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1191 if ( curSub == 1 ) continue;
1193 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1194 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1195 if ( !so->_is_nil() ) {
1196 CORBA::String_var name = so->GetName();
1197 CORBA::String_var entry = so->GetID();
1198 table()->item( row, COL_SHAPE )->setText( name.in() );
1199 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1203 getSMESHGUI()->getApp()->updateObjectBrowser();
1204 currentCellChanged(); // to update buttons
1207 //================================================================================
1209 * \brief show mesh elements preventing computation of a submesh of current row
1211 //================================================================================
1213 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1215 myTShapeDisplayer->SetVisibility( false );
1217 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1218 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1220 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1221 SMESHGUI* gui = getSMESHGUI();
1222 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1223 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1224 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1225 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1226 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1227 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1228 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1229 vtkProperty* prop = vtkProperty::New();
1230 prop->SetLineWidth( aLineWidth * 3 );
1231 prop->SetPointSize( aPointSize * 3 );
1232 prop->SetColor( 250, 0, 250 );
1233 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1234 myBadMeshDisplayer->SetData( aMeshData._retn() );
1240 //================================================================================
1242 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1244 //================================================================================
1246 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1249 SMESH::getSelectedRows( table(), rows );
1251 foreach ( row, rows )
1253 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1255 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1256 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1257 if ( grName.isEmpty() ) grName = "bad mesh";
1258 else grName = "bad mesh of " + grName;
1259 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1260 SMESH::ListOfGroups_var groups
1261 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1262 update( UF_ObjBrowser | UF_Model );
1263 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1265 QStringList anEntryList;
1266 for ( size_t i = 0; i < groups->length(); ++i )
1267 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1268 anEntryList.append( so->GetID().c_str() );
1270 if ( !anEntryList.isEmpty())
1271 anApp->browseObjects( anEntryList, true, false );
1277 //================================================================================
1279 * \brief SLOT called when a selected cell in table() changed
1281 //================================================================================
1283 void SMESHGUI_BaseComputeOp::currentCellChanged()
1285 myTShapeDisplayer->SetVisibility( false );
1286 if ( myBadMeshDisplayer )
1287 myBadMeshDisplayer->SetVisibility( false );
1289 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1291 int nbSelected = SMESH::getSelectedRows( table(), rows );
1293 foreach ( row, rows )
1295 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1296 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1297 if ( hasData && !isPublished )
1298 publishEnable = true;
1300 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1301 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1303 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1310 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1313 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1314 myCompDlg->myShowBtn ->setEnabled( showEnable );
1315 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1316 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1319 //================================================================================
1321 * \brief update preview
1323 //================================================================================
1325 void SMESHGUI_BaseComputeOp::onPreviewShape()
1327 if ( myTShapeDisplayer )
1329 SUIT_OverrideCursor aWaitCursor;
1331 SMESH::getSelectedRows( table(), rows );
1333 bool showOnly = true;
1335 foreach ( row, rows )
1337 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1339 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1343 currentCellChanged(); // to update buttons
1347 //================================================================================
1351 //================================================================================
1353 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1357 delete myTShapeDisplayer;
1358 if ( myBadMeshDisplayer )
1359 delete myBadMeshDisplayer;
1362 //================================================================================
1364 * \brief Gets dialog of compute operation
1365 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1367 //================================================================================
1369 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1373 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1374 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1375 // connect signals and slots
1376 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1377 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1378 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1379 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1381 QTableWidget* aTable = me->table();
1382 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1383 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1388 //================================================================================
1390 * \brief returns from compute mesh result dialog
1392 //================================================================================
1394 bool SMESHGUI_BaseComputeOp::onApply()
1399 //================================================================================
1401 * \brief Return a table
1403 //================================================================================
1405 QTableWidget* SMESHGUI_BaseComputeOp::table()
1407 return myCompDlg->myTable;
1411 //================================================================================
1413 * \brief Constructor
1415 //================================================================================
1417 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1418 : SMESHGUI_BaseComputeOp()
1423 //================================================================================
1425 * \brief Desctructor
1427 //================================================================================
1429 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1433 //================================================================================
1435 * \brief perform it's intention action: compute mesh
1437 //================================================================================
1439 void SMESHGUI_ComputeOp::startOperation()
1441 SMESHGUI_BaseComputeOp::startOperation();
1442 if (myMesh->_is_nil())
1447 //================================================================================
1449 * \brief check the same operations on the same mesh
1451 //================================================================================
1453 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1455 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1457 if ( !myMesh->_is_nil() && baseOp ) {
1458 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1459 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1464 //================================================================================
1466 * \brief Gets dialog of this operation
1467 * \retval LightApp_Dialog* - pointer to dialog of this operation
1469 //================================================================================
1471 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1473 return computeDlg();
1476 //================================================================================
1478 * \brief Constructor
1480 //================================================================================
1482 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1483 : SMESHGUI_BaseComputeOp(),
1487 myPreviewDisplayer( 0 )
1489 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1492 //================================================================================
1496 //================================================================================
1498 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1505 if ( myPreviewDisplayer )
1506 delete myPreviewDisplayer;
1507 myPreviewDisplayer = 0;
1510 //================================================================================
1512 * \brief Gets current dialog of this operation
1513 * \retval LightApp_Dialog* - pointer to dialog of this operation
1515 //================================================================================
1517 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1522 //================================================================================
1524 * \brief perform it's intention action: prepare data
1526 //================================================================================
1528 void SMESHGUI_PrecomputeOp::startOperation()
1532 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1535 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1536 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1537 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1539 myActiveDlg = myDlg;
1541 // connect signal to compute dialog. which will be shown after Compute mesh operation
1542 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1545 // disconnect signals
1546 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1547 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1548 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1549 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1550 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1553 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1554 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1555 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1556 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1557 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1558 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1559 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1560 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1561 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1562 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1565 SMESHGUI_BaseComputeOp::startOperation();
1566 if (myMesh->_is_nil())
1569 if (myDlg->getPreviewMode() == -1)
1571 // nothing to preview
1572 SUIT_MessageBox::warning(desktop(),
1573 tr("SMESH_WRN_WARNING"),
1574 tr("SMESH_WRN_NOTHING_PREVIEW"));
1579 // disconnect slot from preview dialog to have Apply from results of compute operation only
1580 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1581 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1586 //================================================================================
1588 * \brief Stops operation
1590 //================================================================================
1592 void SMESHGUI_PrecomputeOp::stopOperation()
1594 if ( myPreviewDisplayer )
1596 myPreviewDisplayer->SetVisibility( false );
1597 delete myPreviewDisplayer;
1598 myPreviewDisplayer = 0;
1600 myMapShapeId.clear();
1601 SMESHGUI_BaseComputeOp::stopOperation();
1604 //================================================================================
1606 * \brief reinitialize dialog after operaiton become active again
1608 //================================================================================
1610 void SMESHGUI_PrecomputeOp::resumeOperation()
1612 if ( myActiveDlg == myDlg )
1614 SMESHGUI_BaseComputeOp::resumeOperation();
1617 //================================================================================
1619 * \brief perform it's intention action: reinitialise dialog
1621 //================================================================================
1623 void SMESHGUI_PrecomputeOp::initDialog()
1627 QMap<int, int> modeMap;
1628 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1629 getAssignedAlgos( pMesh, modeMap );
1630 if ( modeMap.contains( SMESH::DIM_3D ) )
1632 if ( modeMap.contains( SMESH::DIM_2D ) )
1633 modes.append( SMESH::DIM_2D );
1634 if ( modeMap.contains( SMESH::DIM_1D ) )
1635 modes.append( SMESH::DIM_1D );
1637 else if ( modeMap.contains( SMESH::DIM_2D ) )
1639 if ( modeMap.contains( SMESH::DIM_1D ) )
1640 modes.append( SMESH::DIM_1D );
1643 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1644 myOrderMgr->SetMesh( myMesh );
1645 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1646 myDlg->getMeshOrderBox()->setShown(isOrder);
1652 myDlg->setPreviewModes( modes );
1655 //================================================================================
1657 * \brief detect asigned mesh algorithms
1659 //================================================================================
1661 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1662 QMap<int,int>& theModeMap)
1664 _PTR(SObject) aHypRoot;
1665 _PTR(GenericAttribute) anAttr;
1666 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1667 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1669 _PTR(ChildIterator) anIter =
1670 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1671 for ( ; anIter->More(); anIter->Next() )
1673 _PTR(SObject) anObj = anIter->Value();
1674 _PTR(SObject) aRefObj;
1675 if ( anObj->ReferencedObject( aRefObj ) )
1680 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1682 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1683 if ( CORBA::is_nil( aVar ) )
1686 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1688 SMESH::SMESH_Algo_var algo;
1690 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1691 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1692 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1695 if ( !algo->_is_nil() )
1696 theModeMap[ dim ] = 0;
1703 //================================================================================
1705 * \brief perform it's intention action: compute mesh
1707 //================================================================================
1709 void SMESHGUI_PrecomputeOp::onCompute()
1712 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1713 myOrderMgr->SetMeshOrder();
1714 myMapShapeId.clear();
1715 myActiveDlg = computeDlg();
1719 //================================================================================
1721 * \brief perform it's intention action: compute mesh
1723 //================================================================================
1725 void SMESHGUI_PrecomputeOp::onCancel()
1727 QObject* curDlg = sender();
1728 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1730 // return from error messages
1735 bool isRestoreOrder = false;
1736 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1738 // ask to remove already computed mesh elements
1739 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1740 tr( "CLEAR_SUBMESH_QUESTION" ),
1741 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1743 // remove all submeshes for collected shapes
1744 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1745 for ( ; it != myMapShapeId.constEnd(); ++it )
1746 myMesh->ClearSubMesh( *it );
1747 isRestoreOrder = true;
1751 // return previous mesh order
1752 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1753 if (!isRestoreOrder)
1755 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1756 tr( "SMESH_REJECT_MESH_ORDER" ),
1757 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1759 myOrderMgr->SetMeshOrder(myPrevOrder);
1765 myMapShapeId.clear();
1766 SMESHGUI_BaseComputeOp::onCancel();
1769 //================================================================================
1771 * \brief perform it's intention action: preview mesh
1773 //================================================================================
1775 void SMESHGUI_PrecomputeOp::onPreview()
1777 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1780 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1784 // set modified submesh priority if any
1785 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1786 myOrderMgr->SetMeshOrder();
1788 // Compute preview of mesh,
1789 // i.e. compute mesh till indicated dimension
1790 int dim = myDlg->getPreviewMode();
1792 SMESH::MemoryReserve aMemoryReserve;
1794 SMESH::compute_error_array_var aCompErrors;
1797 bool computeFailed = true, memoryLack = false;
1799 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1800 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1802 SMESHGUI* gui = getSMESHGUI();
1803 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1804 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1805 if ( errors->length() > 0 ) {
1806 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1809 SUIT_OverrideCursor aWaitCursor;
1811 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1812 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1813 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1815 SMESH::long_array_var aShapesId = new SMESH::long_array();
1817 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1821 SMESH::MeshPreviewStruct_var previewData =
1822 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1824 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1825 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1827 computeFailed = false;
1828 myPreviewDisplayer->SetData( previewRes );
1829 // append shape indeces with computed mesh entities
1830 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1831 myMapShapeId[ aShapesId[ i ] ] = 0;
1834 myPreviewDisplayer->SetVisibility(false);
1836 catch(const SALOME::SALOME_Exception & S_ex){
1838 myPreviewDisplayer->SetVisibility(false);
1842 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1845 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1846 // check if there are memory problems
1847 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1848 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1850 catch(const SALOME::SALOME_Exception & S_ex){
1855 aMemoryReserve.release();
1857 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1858 bool noHypoError = ( aHypErrors.isEmpty() );
1860 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1861 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1863 bool isShowError = true;
1864 switch( aNotifyMode ) {
1865 case 0: // show the mesh computation result dialog NEVER
1866 isShowError = false;
1868 case 1: // show the mesh computation result dialog if there are some errors
1869 default: // show the result dialog after each mesh computation
1870 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1871 isShowError = false;
1875 aWaitCursor.suspend();
1880 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1881 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1886 //================================================================================
1888 * \brief Constructor
1890 //================================================================================
1892 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1893 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1896 setWindowTitle( tr( "CAPTION" ) );
1898 setButtonText( OK, tr( "COMPUTE" ) );
1899 QFrame* main = mainFrame();
1901 QVBoxLayout* layout = new QVBoxLayout( main );
1903 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1904 layout->addWidget(myOrderBox);
1906 QFrame* frame = new QFrame( main );
1907 layout->setMargin(0); layout->setSpacing(0);
1908 layout->addWidget( frame );
1910 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1911 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1913 myPreviewMode = new QtxComboBox( frame );
1914 frameLay->addWidget( myPreviewMode );
1916 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1917 frameLay->addWidget( myPreviewBtn );
1919 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1922 //================================================================================
1926 //================================================================================
1928 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1932 //================================================================================
1934 * \brief Sets available preview modes
1936 //================================================================================
1938 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1940 myPreviewMode->clear();
1941 QList<int>::const_iterator it = theModes.constBegin();
1942 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1944 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1945 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1946 myPreviewMode->setId( i, *it );
1948 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1951 //================================================================================
1953 * \brief Returns current preview mesh mode
1955 //================================================================================
1957 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1959 return myPreviewMode->currentId();
1962 //================================================================================
1964 * \brief Returns current preview mesh mode
1966 //================================================================================
1968 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1974 //================================================================================
1976 * \brief Constructor
1978 //================================================================================
1980 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1981 : SMESHGUI_BaseComputeOp()
1986 //================================================================================
1988 * \brief Desctructor
1990 //================================================================================
1992 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1996 //================================================================================
1998 * \brief perform it's intention action: compute mesh
2000 //================================================================================
2002 void SMESHGUI_EvaluateOp::startOperation()
2004 SMESHGUI_BaseComputeOp::evaluateDlg();
2005 SMESHGUI_BaseComputeOp::startOperation();
2006 if (myMesh->_is_nil())
2011 //================================================================================
2013 * \brief Gets dialog of this operation
2014 * \retval LightApp_Dialog* - pointer to dialog of this operation
2016 //================================================================================
2018 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2020 return evaluateDlg();
2023 //================================================================================
2025 * \brief evaluateMesh()
2027 //================================================================================
2029 void SMESHGUI_BaseComputeOp::evaluateMesh()
2033 SMESH::MemoryReserve aMemoryReserve;
2035 SMESH::compute_error_array_var aCompErrors;
2038 bool evaluateFailed = true, memoryLack = false;
2039 SMESH::long_array_var aRes;
2041 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2042 if ( !aMeshSObj ) // IPAL21340
2045 bool hasShape = myMesh->HasShapeToMesh();
2046 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2049 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2050 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2051 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2052 if ( errors->length() > 0 ) {
2053 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2055 SUIT_OverrideCursor aWaitCursor;
2057 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2060 aRes = gen->Evaluate(myMesh, myMainShape);
2062 catch(const SALOME::SALOME_Exception & S_ex){
2067 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2070 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2072 catch(const SALOME::SALOME_Exception & S_ex){
2078 aMemoryReserve.release();
2080 evaluateFailed = ( aCompErrors->length() > 0 );
2081 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
2085 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2086 bool noHypoError = ( aHypErrors.isEmpty() );
2088 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2089 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2091 bool isShowResultDlg = true;
2093 //switch( aNotifyMode ) {
2094 //case 0: // show the mesh computation result dialog NEVER
2095 //isShowResultDlg = false;
2098 //case 1: // show the mesh computation result dialog if there are some errors
2099 //if ( memoryLack || !noHypoError )
2100 // isShowResultDlg = true;
2103 // isShowResultDlg = false;
2107 //default: // show the result dialog after each mesh computation
2108 //isShowResultDlg = true;
2112 if ( isShowResultDlg )
2113 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2114 noHypoError, aHypErrors);
2118 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2119 const bool theMemoryLack,
2120 const bool theNoCompError,
2121 SMESH::compute_error_array_var& theCompErrors,
2122 const bool theNoHypoError,
2123 const QString& theHypErrors)
2125 bool hasShape = myMesh->HasShapeToMesh();
2126 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2127 aCompDlg->myMemoryLackGroup->hide();
2129 if ( theMemoryLack )
2131 aCompDlg->myMemoryLackGroup->show();
2132 aCompDlg->myFullInfo->hide();
2133 aCompDlg->myBriefInfo->hide();
2134 aCompDlg->myHypErrorGroup->hide();
2135 aCompDlg->myCompErrorGroup->hide();
2137 else if ( theNoCompError && theNoHypoError )
2139 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2140 aCompDlg->myFullInfo->show();
2141 aCompDlg->myBriefInfo->hide();
2142 aCompDlg->myHypErrorGroup->hide();
2143 aCompDlg->myCompErrorGroup->hide();
2147 QTableWidget* tbl = aCompDlg->myTable;
2148 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2149 aCompDlg->myBriefInfo->show();
2150 aCompDlg->myFullInfo->hide();
2152 if ( theNoHypoError ) {
2153 aCompDlg->myHypErrorGroup->hide();
2156 aCompDlg->myHypErrorGroup->show();
2157 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2160 if ( theNoCompError ) {
2161 aCompDlg->myCompErrorGroup->hide();
2164 aCompDlg->myCompErrorGroup->show();
2166 aCompDlg->myPublishBtn->hide();
2167 aCompDlg->myShowBtn->hide();
2169 // fill table of errors
2170 tbl->setRowCount( theCompErrors->length() );
2171 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2172 else tbl->showColumn( COL_SHAPE );
2173 tbl->setColumnWidth( COL_ERROR, 200 );
2175 bool hasBadMesh = false;
2176 for ( int row = 0; row < theCompErrors->length(); ++row )
2178 SMESH::ComputeError & err = theCompErrors[ row ];
2180 QString text = err.algoName.in();
2181 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2182 else tbl->item( row, COL_ALGO )->setText( text );
2184 text = SMESH::errorText( err.code, err.comment.in() );
2185 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2186 else tbl->item( row, COL_ERROR )->setText( text );
2188 text = QString("%1").arg( err.subShapeID );
2189 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2190 else tbl->item( row, COL_SHAPEID )->setText( text );
2192 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2193 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2194 else tbl->item( row, COL_SHAPE )->setText( text );
2196 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2197 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2198 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2200 text = err.hasBadMesh ? "hasBadMesh" : "";
2201 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2202 else tbl->item( row, COL_BAD_MESH )->setText( text );
2203 if ( err.hasBadMesh ) hasBadMesh = true;
2205 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2206 tbl->resizeRowToContents( row );
2208 tbl->resizeColumnToContents( COL_ALGO );
2209 tbl->resizeColumnToContents( COL_SHAPE );
2210 tbl->setWordWrap( true );
2214 aCompDlg->myBadMeshBtn->show();
2215 aCompDlg->myBadMeshToGroupBtn->show();
2219 aCompDlg->myBadMeshBtn->hide();
2220 aCompDlg->myBadMeshToGroupBtn->hide();
2222 tbl->setCurrentCell(0,0);
2223 currentCellChanged(); // to update buttons
2226 // show dialog and wait, becase Compute can be invoked from Preview operation
2227 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2232 //================================================================================
2234 * \brief Gets dialog of evaluate operation
2235 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2237 //================================================================================
2239 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2243 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2244 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2245 // connect signals and slots
2246 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2247 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2248 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2249 QTableWidget* aTable = me->table();
2250 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2251 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));