1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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>
64 #include "utilities.h"
66 #include CORBA_SERVER_HEADER(SMESH_Group)
69 #include <BRep_Tool.hxx>
71 #include <TopExp_Explorer.hxx>
72 #include <TopTools_IndexedMapOfShape.hxx>
75 #include <TopLoc_Location.hxx>
76 #include <Poly_Triangulation.hxx>
77 #include <Bnd_Box.hxx>
78 #include <BRepBndLib.hxx>
79 #include <BRepMesh_IncrementalMesh.hxx>
81 #include <Standard_ErrorHandler.hxx>
85 #include <QPushButton>
87 #include <QRadioButton>
88 #include <QTableWidget>
89 #include <QHeaderView>
90 #include <QGridLayout>
91 #include <QHBoxLayout>
92 #include <QVBoxLayout>
93 #include <QButtonGroup>
94 #include <QCloseEvent>
95 #include <QTimerEvent>
96 #include <QProgressBar>
99 #include <vtkProperty.h>
106 #include <sys/sysinfo.h>
112 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
115 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
118 //using namespace SMESH;
122 //=============================================================================
124 * \brief Allocate some memory at construction and release it at destruction.
125 * Is used to be able to continue working after mesh generation or visualization
126 * break due to lack of memory
128 //=============================================================================
133 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
134 void release() { delete [] myBuf; myBuf = 0; }
135 ~MemoryReserve() { release(); }
138 // =========================================================================================
140 * \brief Class showing shapes without publishing
142 // =========================================================================================
144 class TShapeDisplayer
147 // -----------------------------------------------------------------------
148 TShapeDisplayer(): myViewWindow(0)
150 myProperty = vtkProperty::New();
151 myProperty->SetRepresentationToWireframe();
152 myProperty->SetColor( 250, 0, 250 );
153 myProperty->SetAmbientColor( 250, 0, 250 );
154 myProperty->SetDiffuseColor( 250, 0, 250 );
155 //myProperty->SetSpecularColor( 250, 0, 250 );
156 myProperty->SetLineWidth( 5 );
158 // -----------------------------------------------------------------------
162 myProperty->Delete();
164 // -----------------------------------------------------------------------
167 if ( hasViewWindow() ) {
168 TActorIterator actorIt = actorIterator();
169 while ( actorIt.more() )
170 if (VTKViewer_Actor* anActor = actorIt.next()) {
171 myViewWindow->RemoveActor( anActor );
175 myIndexToShape.Clear();
177 myShownActors.clear();
180 // -----------------------------------------------------------------------
181 void SetVisibility (bool theVisibility)
183 TActorIterator actorIt = shownIterator();
184 while ( actorIt.more() )
185 if (VTKViewer_Actor* anActor = actorIt.next())
186 anActor->SetVisibility(theVisibility);
187 SMESH::RepaintCurrentView();
189 // -----------------------------------------------------------------------
190 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
192 std::string mainEntry;
193 if ( !aMainShape->_is_nil() )
194 mainEntry = aMainShape->GetStudyEntry();
195 return ( myMainEntry == mainEntry &&
196 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
198 // -----------------------------------------------------------------------
199 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
201 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
202 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
203 std::string mainEntry;
204 if ( !aMainShape->_is_nil() )
205 mainEntry = aMainShape->GetStudyEntry();
206 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
209 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
210 checkTriangulation( aShape );
211 TopExp::MapShapes(aShape, myIndexToShape);
212 myActors.resize( myIndexToShape.Extent(), 0 );
213 myShownActors.reserve( myIndexToShape.Extent() );
215 myMainEntry = mainEntry;
216 myViewWindow = aViewWindow;
218 if ( only ) { // hide shown actors
219 TActorIterator actorIt = shownIterator();
220 while ( actorIt.more() )
221 if (VTKViewer_Actor* anActor = actorIt.next())
222 anActor->SetVisibility(false);
223 myShownActors.clear();
225 // find actors to show
226 TopoDS_Shape aShape = myIndexToShape( subShapeID );
227 if ( !aShape.IsNull() ) {
228 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
229 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
230 //checkTriangulation( exp.Current() );
231 if ( GEOM_Actor* anActor = getActor( exp.Current() ) ) {
232 int UNbIsos = resMgr->integerValue( "Geometry", "iso_number_u", 1);
233 int VNbIsos = resMgr->integerValue( "Geometry", "iso_number_v", 1);
234 int aNbIsos[2] = { UNbIsos ? UNbIsos : 1, VNbIsos ? VNbIsos : 1 };
235 anActor->SetNbIsos( aNbIsos );
236 myShownActors.push_back( anActor );
239 if ( type == TopAbs_FACE ) {
240 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
241 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
242 if ( !BRep_Tool::Degenerated( edge ))
243 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
244 myShownActors.push_back( anActor );
248 myBuiltSubs.insert( subShapeID );
251 // -----------------------------------------------------------------------
255 typedef std::vector<GEOM_Actor*> TActorVec;
257 TActorVec myShownActors;
258 TopTools_IndexedMapOfShape myIndexToShape;
259 std::string myMainEntry;
260 SVTK_ViewWindow* myViewWindow;
261 vtkProperty* myProperty;
262 std::set<int> myBuiltSubs;
264 // -----------------------------------------------------------------------
265 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
266 TActorIterator actorIterator() {
267 return TActorIterator( myActors.begin(), myActors.end() );
269 TActorIterator shownIterator() {
270 return TActorIterator( myShownActors.begin(), myShownActors.end() );
272 // -----------------------------------------------------------------------
273 GEOM_Actor* getActor(const TopoDS_Shape& shape)
275 int index = myIndexToShape.FindIndex( shape ) - 1;
276 if ( index < 0 || index >= myActors.size() )
278 GEOM_Actor* & actor = myActors[ index ];
280 actor = GEOM_Actor::New();
282 actor->SetShape(shape,0,0);
283 actor->SetProperty(myProperty);
284 actor->SetShadingProperty(myProperty);
285 actor->SetWireframeProperty(myProperty);
286 actor->SetPreviewProperty(myProperty);
287 actor->PickableOff();
288 // if ( shape.ShapeType() == TopAbs_EDGE )
289 // actor->SubShapeOn();
290 myViewWindow->AddActor( actor );
295 // -----------------------------------------------------------------------
296 void checkTriangulation(const TopoDS_Shape& shape)
298 TopLoc_Location aLoc;
299 Standard_Boolean alreadymesh = Standard_True;
300 TopExp_Explorer ex(shape, TopAbs_FACE);
302 for ( ; ex.More(); ex.Next()) {
303 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
304 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
305 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
308 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
309 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
310 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
311 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
313 if (alreadymesh) return;
314 // Compute default deflection
316 BRepBndLib::Add(shape, B);
317 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
318 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
319 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
320 BRepMesh_IncrementalMesh MESH(shape,deflection);
322 // -----------------------------------------------------------------------
323 bool hasViewWindow() const
325 if ( !myViewWindow ) return false;
327 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
328 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
334 // =========================================================================================
336 * \brief Return text describing an error
338 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
339 QString errorText(int errCode, const char* comment)
343 CASE2TEXT( COMPERR_OK );
344 CASE2TEXT( COMPERR_BAD_INPUT_MESH );
345 CASE2TEXT( COMPERR_STD_EXCEPTION );
346 CASE2TEXT( COMPERR_OCC_EXCEPTION );
347 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
348 CASE2TEXT( COMPERR_EXCEPTION );
349 CASE2TEXT( COMPERR_MEMORY_PB );
350 CASE2TEXT( COMPERR_BAD_SHAPE );
351 CASE2TEXT( COMPERR_CANCELED );
352 CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
353 CASE2TEXT( COMPERR_BAD_PARMETERS );
354 case SMESH::COMPERR_ALGO_FAILED:
355 if ( strlen(comment) == 0 )
356 text = QObject::tr("COMPERR_ALGO_FAILED");
358 case SMESH::COMPERR_WARNING:
359 text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
362 text = QString("#%1").arg( -errCode );
364 if ( text.length() > 0 ) text += ". ";
365 return text + comment;
367 // -----------------------------------------------------------------------
369 * \brief Return SO of a sub-shape
371 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
373 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
374 if ( subShapeID == 1 || !so )
376 _PTR(ChildIterator) it;
377 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
378 it = study->NewChildIterator(so);
381 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
382 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
383 if ( !geom->_is_nil() ) {
384 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
385 if ( list->length() == 1 && list[0] == subShapeID )
387 GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
388 if ( aMainShape->IsSame( mainGO ))
396 // -----------------------------------------------------------------------
398 * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
400 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
402 GEOM::GEOM_Object_var aSubShape;
403 if ( subShapeID == 1 ) {
404 aSubShape = aMainShape;
405 aSubShape->Register();
407 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
408 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
409 aSubShape->Register();
412 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
413 // future call of UnRegister() will delete a servant of this new object
415 return aSubShape._retn();
417 // -----------------------------------------------------------------------
419 * \brief Return shape type name
421 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
422 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
425 if ( !aShape->_is_nil() ) {
426 switch ( aShape->GetShapeType() ) {
433 CASE2NAME( COMPSOLID );
434 CASE2NAME( COMPOUND );
440 // -----------------------------------------------------------------------
442 * \brief Return text describing a sub-shape
444 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
447 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
448 text = aSO->GetName().c_str();
449 text += QString(" (%1)").arg( aSO->GetID().c_str() );
452 text = QString("#%1").arg( subShapeID );
453 GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
454 QString typeName = shapeTypeName( shape );
455 if ( typeName.length() )
456 text += QString(" (%1)").arg(typeName);
460 // -----------------------------------------------------------------------
462 * \brief Return a list of selected rows
464 int getSelectedRows(QTableWidget* table, QList<int>& rows)
467 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
468 QTableWidgetSelectionRange range;
469 foreach( range, selRanges )
471 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
472 if ( !rows.count( row ))
475 if ( rows.isEmpty() && table->currentRow() > -1 )
476 if ( !rows.count( table->currentRow() ))
477 rows.append( table->currentRow() );
485 // =========================================================================================
487 * \brief Dialog to compute a mesh and show computation errors
489 //=======================================================================
491 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
492 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
494 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
495 aDlgLay->setMargin( 0 );
496 aDlgLay->setSpacing( SPACING );
498 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
500 aDlgLay->addWidget(aMainFrame);
502 aDlgLay->setStretchFactor(aMainFrame, 1);
505 // =========================================================================================
509 //=======================================================================
511 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
515 //=======================================================================
516 // function : createMainFrame()
517 // purpose : Create frame containing dialog's fields
518 //=======================================================================
520 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
522 QFrame* aFrame = new QFrame(theParent);
524 SUIT_ResourceMgr* rm = resourceMgr();
525 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
531 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
534 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
536 QButtonGroup* aBtnGrp = new QButtonGroup(this);
537 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
538 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
540 QRadioButton* aRBut = new QRadioButton(aPixGrp);
541 aRBut->setIcon(iconCompute);
542 aRBut->setChecked(true);
543 aPixGrpLayout->addWidget(aRBut);
544 aBtnGrp->addButton(aRBut, 0);
548 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
549 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
550 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
551 myMeshName = new QLabel(nameBox);
552 nameBoxLayout->addWidget(myMeshName);
556 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
557 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
559 // Computation errors
561 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
562 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
563 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
564 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
565 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
566 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
567 myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
569 //myTable->setReadOnly( true ); // VSR: check
570 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
571 myTable->hideColumn( COL_PUBLISHED );
572 myTable->hideColumn( COL_SHAPEID );
573 myTable->hideColumn( COL_BAD_MESH );
574 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
575 myTable->setWordWrap( true );
576 myTable->horizontalHeader()->setStretchLastSection( true );
577 myTable->setMinimumWidth( 500 );
580 headers << tr( "COL_ALGO_HEADER" );
581 headers << tr( "COL_SHAPE_HEADER" );
582 headers << tr( "COL_ERROR_HEADER" );
583 headers << tr( "COL_SHAPEID_HEADER" );
584 headers << tr( "COL_PUBLISHED_HEADER" );
586 myTable->setHorizontalHeaderLabels( headers );
589 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
590 grpLayout->setSpacing(SPACING);
591 grpLayout->setMargin(MARGIN);
592 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
593 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
594 grpLayout->addWidget( myShowBtn, 2, 0 );
595 grpLayout->addWidget( myPublishBtn, 2, 1 );
596 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
597 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
598 grpLayout->setColumnStretch( 3, 1 );
600 // Hypothesis definition errors
602 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
603 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
604 myHypErrorGroupLayout->setMargin(MARGIN);
605 myHypErrorGroupLayout->setSpacing(SPACING);
606 myHypErrorLabel = new QLabel(myHypErrorGroup);
607 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
611 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
612 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
613 myMemoryLackGroupLayout->setMargin(MARGIN);
614 myMemoryLackGroupLayout->setSpacing(SPACING);
615 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
616 QFont bold = memLackLabel->font(); bold.setBold(true);
617 memLackLabel->setFont( bold );
618 memLackLabel->setMinimumWidth(300);
619 myMemoryLackGroupLayout->addWidget(memLackLabel);
621 // add all widgets to aFrame
622 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
623 aLay->setMargin( MARGIN );
624 aLay->setSpacing( SPACING );
625 aLay->addWidget( aPixGrp );
626 aLay->addWidget( nameBox );
627 aLay->addWidget( myBriefInfo );
628 aLay->addWidget( myFullInfo );
629 aLay->addWidget( myHypErrorGroup );
630 aLay->addWidget( myCompErrorGroup );
631 aLay->addWidget( myMemoryLackGroup );
632 aLay->setStretchFactor( myCompErrorGroup, 1 );
634 ((QPushButton*) button( OK ))->setDefault( true );
639 //================================================================================
643 //================================================================================
645 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
646 : SMESHGUI_Operation(), myCompDlg( 0 )
648 myTShapeDisplayer = new SMESH::TShapeDisplayer();
649 myBadMeshDisplayer = 0;
651 //myHelpFileName = "/files/about_meshes.htm"; // V3
652 myHelpFileName = "about_meshes_page.html"; // V4
655 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
657 LightApp_SelectionMgr* Sel = selectionMgr();
658 SALOME_ListIO selected; Sel->selectedObjects( selected );
659 Handle(SALOME_InteractiveObject) anIO = selected.First();
660 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
661 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
664 //================================================================================
666 * \brief Start operation
667 * \purpose Init dialog fields, connect signals and slots, show dialog
669 //================================================================================
671 void SMESHGUI_BaseComputeOp::startOperation()
673 // create compute dialog if not created before
676 myMesh = SMESH::SMESH_Mesh::_nil();
677 myMainShape = GEOM::GEOM_Object::_nil();
680 LightApp_SelectionMgr *Sel = selectionMgr();
681 SALOME_ListIO selected; Sel->selectedObjects( selected );
683 int nbSel = selected.Extent();
685 SUIT_MessageBox::warning(desktop(),
686 tr("SMESH_WRN_WARNING"),
687 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
692 myIObject = selected.First();
693 myMesh = SMESH::GetMeshByIO(myIObject);
694 if (myMesh->_is_nil()) {
695 SUIT_MessageBox::warning(desktop(),
696 tr("SMESH_WRN_WARNING"),
697 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
701 myMainShape = myMesh->GetShapeToMesh();
703 SMESHGUI_Operation::startOperation();
706 //================================================================================
707 //================================================================================
709 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
710 SMESH::SMESH_Mesh_var mesh,
711 GEOM::GEOM_Object_var mainShape)
716 myMainShape = mainShape;
719 void SMESHGUI_ComputeDlg_QThread::run()
721 myResult = myGen->Compute(myMesh, myMainShape);
724 bool SMESHGUI_ComputeDlg_QThread::result()
729 void SMESHGUI_ComputeDlg_QThread::cancel()
731 myGen->CancelCompute(myMesh, myMainShape);
734 //================================================================================
735 //================================================================================
737 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
738 SMESH::SMESH_Gen_var gen,
739 SMESH::SMESH_Mesh_var mesh,
740 GEOM::GEOM_Object_var mainShape)
742 Qt::WindowSystemMenuHint |
743 Qt::WindowCloseButtonHint |
745 Qt::WindowMaximizeButtonHint),
746 qthread(gen, mesh, mainShape)
749 setWindowTitle(tr("TITLE"));
750 setMinimumWidth( 200 );
752 cancelButton = new QPushButton(tr("CANCEL"));
753 cancelButton->setDefault(true);
754 cancelButton->setCheckable(true);
756 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
757 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
758 nbNodesLabel = new QLabel("0", this );
759 nbElemsLabel = new QLabel("0", this );
761 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
762 freeRAMLabel = new QLabel("", this );
764 progressBar = new QProgressBar(this);
765 progressBar->setMinimum( 0 );
766 progressBar->setMaximum( 1000 );
768 QGridLayout* layout = new QGridLayout(this);
769 layout->setMargin( MARGIN );
770 layout->setSpacing( SPACING );
772 layout->addWidget(nbNodesName, row, 0);
773 layout->addWidget(nbNodesLabel, row++, 1);
774 layout->addWidget(nbElemsName, row, 0);
775 layout->addWidget(nbElemsLabel, row++, 1);
777 layout->addWidget(freeRAMName, row, 0);
778 layout->addWidget(freeRAMLabel, row++, 1);
780 layout->addWidget(progressBar, row++, 0, 1, 2);
781 layout->addWidget(cancelButton, row++, 0, 1, 2);
785 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
787 startTimer(300); // millisecs
791 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
793 return qthread.result();
796 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
799 cancelButton->setText( tr("CANCELING"));
800 cancelButton->setEnabled(false);
803 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
805 if ( !cancelButton->isChecked() ) // not yet cancelled
806 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
808 if(qthread.isFinished())
814 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
815 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
818 const int err = sysinfo( &si );
820 freeRAMLabel->setText("");
822 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
823 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
829 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
831 if(qthread.isRunning())
839 //================================================================================
841 * \brief computeMesh()
843 //================================================================================
845 void SMESHGUI_BaseComputeOp::computeMesh()
849 SMESH::MemoryReserve aMemoryReserve;
851 SMESH::compute_error_array_var aCompErrors;
854 bool computeFailed = true, memoryLack = false;
856 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
857 if ( !aMeshSObj ) // IPAL 21340
859 bool hasShape = myMesh->HasShapeToMesh();
860 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
863 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
864 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
865 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
866 if ( errors->length() > 0 ) {
867 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
869 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
870 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
871 tr( "FULL_RECOMPUTE_QUESTION" ),
872 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
874 SUIT_OverrideCursor aWaitCursor;
876 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
879 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
880 qthreaddialog.exec();
881 computeFailed = !qthreaddialog.result();
883 catch(const SALOME::SALOME_Exception & S_ex) {
887 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
890 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
891 // check if there are memory problems
892 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
893 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
895 catch(const SALOME::SALOME_Exception & S_ex) {
899 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
903 // NPAL16631: if ( !memoryLack )
905 SMESH::ModifiedMesh( aMeshSObj,
906 !computeFailed && aHypErrors.isEmpty(),
907 myMesh->NbNodes() == 0);
908 update( UF_ObjBrowser | UF_Model );
911 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
912 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
914 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
915 int entities = SMESH_Actor::eAllEntity;
920 // List of objects that will be updated automatically
921 QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > aListToUpdate;
922 SMESH::SMESH_IDSource_var aMeshObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
923 // put Mesh into list
924 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aMeshObj, aMeshSObj) );
925 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
926 // put SubMeshes into list
927 for ( int i = 0; i < aSubMeshes->length(); i++ ) {
928 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
929 if ( CORBA::is_nil( sm ) ) continue;
930 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
931 if ( !smSObj ) continue;
932 SMESH::SMESH_IDSource_var aSubMeshObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
933 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aSubMeshObj, smSObj) );
935 // put Groups into list
936 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
937 for ( size_t i = 0; i < aGroups->length(); ++i ) {
938 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
939 if ( CORBA::is_nil( aGrp ) ) continue;
940 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
941 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGrp );
942 SMESH::SMESH_GroupOnFilter_var aFltGroup = SMESH::SMESH_GroupOnFilter::_narrow( aGrp );
943 if ( !aStdGroup->_is_nil() ) continue; // don't update the standalone groups
944 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
945 if ( !aGroupSO ) continue;
946 SMESH::SMESH_IDSource_var aGroupObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
947 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aGroupObj, aGroupSO) );
950 // update mesh, sub-mesh and groups, if it's possible
951 QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > >::iterator anIter;
952 for( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ ) {
953 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
954 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded, &hidden, &nbElements ) )
957 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
960 bool toDisplay = false;
962 if ( !aMesh->_is_nil() ) { // display a mesh only
964 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
965 if ( !anActor ) anActor = SMESH::CreateActor( (*anIter).second->GetStudy(), (*anIter).second->GetID().c_str(), true );
966 if ( anActor ) // actor is not created for an empty mesh
968 anActor->SetEntityMode( entities );
969 SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
972 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
973 ( (*anIter).second->GetID().c_str(), "SMESH", (*anIter).second->GetName().c_str() );
974 SMESH::Update(anIO, toDisplay);
976 if ( limitExceeded && !aMesh->_is_nil() )
978 QStringList hiddenMsg;
979 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
980 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
981 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
982 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
983 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
984 SUIT_MessageBox::warning( desktop(),
985 tr( "SMESH_WRN_WARNING" ),
986 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).arg( nbElements ).arg( limitSize ).arg( hiddenMsg.join(", ") ) );
991 MESSAGE ( "Exception thrown during mesh visualization" );
993 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
994 SMESH::OnVisuException();
1001 else if ( limitExceeded && !aMesh->_is_nil() )
1003 SUIT_MessageBox::warning( desktop(),
1004 tr( "SMESH_WRN_WARNING" ),
1005 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( nbElements ).arg( limitSize ) );
1009 LightApp_SelectionMgr *Sel = selectionMgr();
1012 SALOME_ListIO selected;
1013 selected.Append( myIObject );
1014 Sel->setSelectedObjects( selected );
1020 aMemoryReserve.release();
1022 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1026 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1027 bool noHypoError = ( aHypErrors.isEmpty() );
1029 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1030 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1032 bool isShowResultDlg = true;
1033 switch( aNotifyMode ) {
1034 case 0: // show the mesh computation result dialog NEVER
1035 isShowResultDlg = false;
1038 case 1: // show the mesh computation result dialog if there are some errors
1039 if ( memoryLack || !noCompError || !noHypoError )
1040 isShowResultDlg = true;
1043 isShowResultDlg = false;
1047 default: // show the result dialog after each mesh computation
1048 isShowResultDlg = true;
1052 if ( isShowResultDlg )
1053 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1056 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1057 const bool theNoCompError,
1058 SMESH::compute_error_array_var& theCompErrors,
1059 const bool theNoHypoError,
1060 const QString& theHypErrors )
1062 bool hasShape = myMesh->HasShapeToMesh();
1063 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1064 aCompDlg->myMemoryLackGroup->hide();
1066 if ( theMemoryLack )
1068 aCompDlg->myMemoryLackGroup->show();
1069 aCompDlg->myFullInfo->hide();
1070 aCompDlg->myBriefInfo->hide();
1071 aCompDlg->myHypErrorGroup->hide();
1072 aCompDlg->myCompErrorGroup->hide();
1074 else if ( theNoCompError && theNoHypoError )
1076 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1077 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1078 aCompDlg->myFullInfo->show();
1079 aCompDlg->myBriefInfo->hide();
1080 aCompDlg->myHypErrorGroup->hide();
1081 aCompDlg->myCompErrorGroup->hide();
1085 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1086 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1087 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1088 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1090 // full or brief mesh info
1091 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1092 if ( onlyWarnings ) {
1093 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1094 aCompDlg->myFullInfo->show();
1095 aCompDlg->myBriefInfo->hide();
1097 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1098 aCompDlg->myBriefInfo->show();
1099 aCompDlg->myFullInfo->hide();
1102 // pbs of hypo dfinitions
1103 if ( theNoHypoError ) {
1104 aCompDlg->myHypErrorGroup->hide();
1106 aCompDlg->myHypErrorGroup->show();
1107 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1111 if ( theNoCompError )
1113 aCompDlg->myCompErrorGroup->hide();
1117 aCompDlg->myCompErrorGroup->show();
1120 aCompDlg->myWarningLabel->show();
1122 aCompDlg->myWarningLabel->hide();
1125 aCompDlg->myPublishBtn->hide();
1126 aCompDlg->myShowBtn->hide();
1129 aCompDlg->myPublishBtn->show();
1130 aCompDlg->myShowBtn->show();
1133 // fill table of errors
1134 QTableWidget* tbl = aCompDlg->myTable;
1135 tbl->setRowCount( theCompErrors->length() );
1136 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1137 else tbl->showColumn( COL_SHAPE );
1138 tbl->setColumnWidth( COL_ERROR, 200 );
1140 bool hasBadMesh = false;
1141 for ( int row = 0; row < theCompErrors->length(); ++row )
1143 SMESH::ComputeError & err = theCompErrors[ row ];
1145 QString text = err.algoName.in();
1146 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1147 else tbl->item( row, COL_ALGO )->setText( text );
1149 text = SMESH::errorText( err.code, err.comment.in() );
1150 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1151 else tbl->item( row, COL_ERROR )->setText( text );
1153 text = QString("%1").arg( err.subShapeID );
1154 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1155 else tbl->item( row, COL_SHAPEID )->setText( text );
1157 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1158 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1159 else tbl->item( row, COL_SHAPE )->setText( text );
1161 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1162 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1163 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1165 text = err.hasBadMesh ? "hasBadMesh" : "";
1166 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1167 else tbl->item( row, COL_BAD_MESH )->setText( text );
1168 if ( err.hasBadMesh ) hasBadMesh = true;
1170 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1171 tbl->resizeRowToContents( row );
1173 tbl->resizeColumnToContents( COL_ALGO );
1174 tbl->resizeColumnToContents( COL_SHAPE );
1175 tbl->setWordWrap( true );
1178 aCompDlg->myBadMeshBtn->show();
1179 aCompDlg->myBadMeshToGroupBtn->show();
1182 aCompDlg->myBadMeshBtn->hide();
1183 aCompDlg->myBadMeshToGroupBtn->hide();
1185 tbl->setCurrentCell(0,0);
1186 currentCellChanged(); // to update buttons
1189 // show dialog and wait, becase Compute can be invoked from Preview operation
1190 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1194 //================================================================================
1196 * \brief Stops operation
1198 //================================================================================
1200 void SMESHGUI_BaseComputeOp::stopOperation()
1202 SMESHGUI_Operation::stopOperation();
1203 if ( myTShapeDisplayer )
1204 myTShapeDisplayer->SetVisibility( false );
1205 if ( myBadMeshDisplayer ) {
1206 myBadMeshDisplayer->SetVisibility( false );
1207 // delete it in order not to have problems at its destruction when the viewer
1208 // where it worked is dead due to e.g. study closing
1209 delete myBadMeshDisplayer;
1210 myBadMeshDisplayer = 0;
1212 myIObject.Nullify();
1215 //================================================================================
1217 * \brief publish selected sub-shape
1219 //================================================================================
1221 void SMESHGUI_BaseComputeOp::onPublishShape()
1223 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1224 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1227 SMESH::getSelectedRows( table(), rows );
1229 foreach ( row, rows )
1231 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1232 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1233 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1235 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1237 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1238 SALOMEDS::SObject_wrap so =
1239 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1240 // look for myMainShape in the table
1241 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1242 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1243 if ( so->_is_nil() ) {
1244 CORBA::String_var name = so->GetName();
1245 CORBA::String_var entry = so->GetID();
1246 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1247 table()->item( r, COL_SHAPE )->setText( shapeText );
1248 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1253 if ( curSub == 1 ) continue;
1255 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1256 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1257 if ( !so->_is_nil() ) {
1258 CORBA::String_var name = so->GetName();
1259 CORBA::String_var entry = so->GetID();
1260 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1261 table()->item( row, COL_SHAPE )->setText( shapeText );
1262 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1266 getSMESHGUI()->getApp()->updateObjectBrowser();
1267 currentCellChanged(); // to update buttons
1270 //================================================================================
1272 * \brief show mesh elements preventing computation of a submesh of current row
1274 //================================================================================
1276 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1278 myTShapeDisplayer->SetVisibility( false );
1280 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1281 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1283 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1284 SMESHGUI* gui = getSMESHGUI();
1285 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1286 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1287 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1288 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1289 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1290 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1291 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1292 vtkProperty* prop = vtkProperty::New();
1293 prop->SetLineWidth( aLineWidth * 3 );
1294 prop->SetPointSize( aPointSize * 3 );
1295 prop->SetColor( 250, 0, 250 );
1296 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1297 myBadMeshDisplayer->SetData( aMeshData._retn() );
1303 //================================================================================
1305 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1307 //================================================================================
1309 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1312 SMESH::getSelectedRows( table(), rows );
1314 foreach ( row, rows )
1316 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1318 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1319 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1320 if ( grName.isEmpty() ) grName = "bad mesh";
1321 else grName = "bad mesh of " + grName;
1322 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1323 SMESH::ListOfGroups_var groups
1324 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1325 update( UF_ObjBrowser | UF_Model );
1326 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1328 QStringList anEntryList;
1329 for ( size_t i = 0; i < groups->length(); ++i )
1330 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1331 anEntryList.append( so->GetID().c_str() );
1333 if ( !anEntryList.isEmpty())
1334 anApp->browseObjects( anEntryList, true, false );
1340 //================================================================================
1342 * \brief SLOT called when a selected cell in table() changed
1344 //================================================================================
1346 void SMESHGUI_BaseComputeOp::currentCellChanged()
1348 myTShapeDisplayer->SetVisibility( false );
1349 if ( myBadMeshDisplayer )
1350 myBadMeshDisplayer->SetVisibility( false );
1352 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1354 int nbSelected = SMESH::getSelectedRows( table(), rows );
1356 foreach ( row, rows )
1358 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1359 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1360 if ( hasData && !isPublished )
1361 publishEnable = true;
1363 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1364 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1366 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1373 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1376 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1377 myCompDlg->myShowBtn ->setEnabled( showEnable );
1378 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1379 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1382 //================================================================================
1384 * \brief update preview
1386 //================================================================================
1388 void SMESHGUI_BaseComputeOp::onPreviewShape()
1390 if ( myTShapeDisplayer )
1392 SUIT_OverrideCursor aWaitCursor;
1394 SMESH::getSelectedRows( table(), rows );
1396 bool showOnly = true;
1398 foreach ( row, rows )
1400 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1402 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1406 currentCellChanged(); // to update buttons
1410 //================================================================================
1414 //================================================================================
1416 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1420 delete myTShapeDisplayer;
1421 if ( myBadMeshDisplayer )
1422 delete myBadMeshDisplayer;
1425 //================================================================================
1427 * \brief Gets dialog of compute operation
1428 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1430 //================================================================================
1432 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1436 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1437 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1438 // connect signals and slots
1439 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1440 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1441 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1442 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1444 QTableWidget* aTable = me->table();
1445 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1446 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1451 //================================================================================
1453 * \brief returns from compute mesh result dialog
1455 //================================================================================
1457 bool SMESHGUI_BaseComputeOp::onApply()
1462 //================================================================================
1464 * \brief Return a table
1466 //================================================================================
1468 QTableWidget* SMESHGUI_BaseComputeOp::table()
1470 return myCompDlg->myTable;
1474 //================================================================================
1476 * \brief Constructor
1478 //================================================================================
1480 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1481 : SMESHGUI_BaseComputeOp()
1486 //================================================================================
1488 * \brief Desctructor
1490 //================================================================================
1492 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1496 //================================================================================
1498 * \brief perform it's intention action: compute mesh
1500 //================================================================================
1502 void SMESHGUI_ComputeOp::startOperation()
1504 SMESHGUI_BaseComputeOp::startOperation();
1505 if (myMesh->_is_nil())
1510 //================================================================================
1512 * \brief check the same operations on the same mesh
1514 //================================================================================
1516 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1518 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1520 if ( !myMesh->_is_nil() && baseOp ) {
1521 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1522 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1527 //================================================================================
1529 * \brief Gets dialog of this operation
1530 * \retval LightApp_Dialog* - pointer to dialog of this operation
1532 //================================================================================
1534 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1536 return computeDlg();
1539 //================================================================================
1541 * \brief Constructor
1543 //================================================================================
1545 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1546 : SMESHGUI_BaseComputeOp(),
1550 myPreviewDisplayer( 0 )
1552 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1555 //================================================================================
1559 //================================================================================
1561 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1568 if ( myPreviewDisplayer )
1569 delete myPreviewDisplayer;
1570 myPreviewDisplayer = 0;
1573 //================================================================================
1575 * \brief Gets current dialog of this operation
1576 * \retval LightApp_Dialog* - pointer to dialog of this operation
1578 //================================================================================
1580 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1585 //================================================================================
1587 * \brief perform it's intention action: prepare data
1589 //================================================================================
1591 void SMESHGUI_PrecomputeOp::startOperation()
1595 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1598 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1599 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1600 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1602 myActiveDlg = myDlg;
1604 // connect signal to compute dialog. which will be shown after Compute mesh operation
1605 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1608 // disconnect signals
1609 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1610 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1611 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1612 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1613 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1616 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1617 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1618 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1619 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1620 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1621 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1622 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1623 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1624 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1625 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1628 SMESHGUI_BaseComputeOp::startOperation();
1629 if (myMesh->_is_nil())
1632 if (myDlg->getPreviewMode() == -1)
1634 // nothing to preview
1635 SUIT_MessageBox::warning(desktop(),
1636 tr("SMESH_WRN_WARNING"),
1637 tr("SMESH_WRN_NOTHING_PREVIEW"));
1642 // disconnect slot from preview dialog to have Apply from results of compute operation only
1643 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1644 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1649 //================================================================================
1651 * \brief Stops operation
1653 //================================================================================
1655 void SMESHGUI_PrecomputeOp::stopOperation()
1657 if ( myPreviewDisplayer )
1659 myPreviewDisplayer->SetVisibility( false );
1660 delete myPreviewDisplayer;
1661 myPreviewDisplayer = 0;
1663 myMapShapeId.clear();
1664 SMESHGUI_BaseComputeOp::stopOperation();
1667 //================================================================================
1669 * \brief reinitialize dialog after operaiton become active again
1671 //================================================================================
1673 void SMESHGUI_PrecomputeOp::resumeOperation()
1675 if ( myActiveDlg == myDlg )
1677 SMESHGUI_BaseComputeOp::resumeOperation();
1680 //================================================================================
1682 * \brief perform it's intention action: reinitialise dialog
1684 //================================================================================
1686 void SMESHGUI_PrecomputeOp::initDialog()
1690 QMap<int, int> modeMap;
1691 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1692 getAssignedAlgos( pMesh, modeMap );
1693 if ( modeMap.contains( SMESH::DIM_3D ) )
1695 if ( modeMap.contains( SMESH::DIM_2D ) )
1696 modes.append( SMESH::DIM_2D );
1697 if ( modeMap.contains( SMESH::DIM_1D ) )
1698 modes.append( SMESH::DIM_1D );
1700 else if ( modeMap.contains( SMESH::DIM_2D ) )
1702 if ( modeMap.contains( SMESH::DIM_1D ) )
1703 modes.append( SMESH::DIM_1D );
1706 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1707 myOrderMgr->SetMesh( myMesh );
1708 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1709 myDlg->getMeshOrderBox()->setShown(isOrder);
1715 myDlg->setPreviewModes( modes );
1718 //================================================================================
1720 * \brief detect asigned mesh algorithms
1722 //================================================================================
1724 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1725 QMap<int,int>& theModeMap)
1727 _PTR(SObject) aHypRoot;
1728 _PTR(GenericAttribute) anAttr;
1729 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1730 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1732 _PTR(ChildIterator) anIter =
1733 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1734 for ( ; anIter->More(); anIter->Next() )
1736 _PTR(SObject) anObj = anIter->Value();
1737 _PTR(SObject) aRefObj;
1738 if ( anObj->ReferencedObject( aRefObj ) )
1743 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1745 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1746 if ( CORBA::is_nil( aVar ) )
1749 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1751 SMESH::SMESH_Algo_var algo;
1753 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1754 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1755 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1758 if ( !algo->_is_nil() )
1759 theModeMap[ dim ] = 0;
1766 //================================================================================
1768 * \brief perform it's intention action: compute mesh
1770 //================================================================================
1772 void SMESHGUI_PrecomputeOp::onCompute()
1775 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1776 myOrderMgr->SetMeshOrder();
1777 myMapShapeId.clear();
1778 myActiveDlg = computeDlg();
1782 //================================================================================
1784 * \brief perform it's intention action: compute mesh
1786 //================================================================================
1788 void SMESHGUI_PrecomputeOp::onCancel()
1790 QObject* curDlg = sender();
1791 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1793 // return from error messages
1798 bool isRestoreOrder = false;
1799 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1801 // ask to remove already computed mesh elements
1802 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1803 tr( "CLEAR_SUBMESH_QUESTION" ),
1804 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1806 // remove all submeshes for collected shapes
1807 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1808 for ( ; it != myMapShapeId.constEnd(); ++it )
1809 myMesh->ClearSubMesh( *it );
1810 isRestoreOrder = true;
1814 // return previous mesh order
1815 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1816 if (!isRestoreOrder)
1818 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1819 tr( "SMESH_REJECT_MESH_ORDER" ),
1820 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1822 myOrderMgr->SetMeshOrder(myPrevOrder);
1828 myMapShapeId.clear();
1829 SMESHGUI_BaseComputeOp::onCancel();
1832 //================================================================================
1834 * \brief perform it's intention action: preview mesh
1836 //================================================================================
1838 void SMESHGUI_PrecomputeOp::onPreview()
1840 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1843 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1847 // set modified submesh priority if any
1848 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1849 myOrderMgr->SetMeshOrder();
1851 // Compute preview of mesh,
1852 // i.e. compute mesh till indicated dimension
1853 int dim = myDlg->getPreviewMode();
1855 SMESH::MemoryReserve aMemoryReserve;
1857 SMESH::compute_error_array_var aCompErrors;
1860 bool computeFailed = true, memoryLack = false;
1862 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1863 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1865 SMESHGUI* gui = getSMESHGUI();
1866 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1867 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1868 if ( errors->length() > 0 ) {
1869 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1872 SUIT_OverrideCursor aWaitCursor;
1874 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1875 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1876 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1878 SMESH::long_array_var aShapesId = new SMESH::long_array();
1880 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1884 SMESH::MeshPreviewStruct_var previewData =
1885 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1887 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1888 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1890 computeFailed = false;
1891 myPreviewDisplayer->SetData( previewRes );
1892 // append shape indeces with computed mesh entities
1893 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1894 myMapShapeId[ aShapesId[ i ] ] = 0;
1897 myPreviewDisplayer->SetVisibility(false);
1899 catch(const SALOME::SALOME_Exception & S_ex){
1901 myPreviewDisplayer->SetVisibility(false);
1905 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1908 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1909 // check if there are memory problems
1910 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1911 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1913 catch(const SALOME::SALOME_Exception & S_ex){
1918 aMemoryReserve.release();
1920 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1921 bool noHypoError = ( aHypErrors.isEmpty() );
1923 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1924 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1926 bool isShowError = true;
1927 switch( aNotifyMode ) {
1928 case 0: // show the mesh computation result dialog NEVER
1929 isShowError = false;
1931 case 1: // show the mesh computation result dialog if there are some errors
1932 default: // show the result dialog after each mesh computation
1933 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1934 isShowError = false;
1938 aWaitCursor.suspend();
1943 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1944 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1949 //================================================================================
1951 * \brief Constructor
1953 //================================================================================
1955 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1956 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1959 setWindowTitle( tr( "CAPTION" ) );
1961 setButtonText( OK, tr( "COMPUTE" ) );
1962 QFrame* main = mainFrame();
1964 QVBoxLayout* layout = new QVBoxLayout( main );
1966 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1967 layout->addWidget(myOrderBox);
1969 QFrame* frame = new QFrame( main );
1970 layout->setMargin(0); layout->setSpacing(0);
1971 layout->addWidget( frame );
1973 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1974 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1976 myPreviewMode = new QtxComboBox( frame );
1977 frameLay->addWidget( myPreviewMode );
1979 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1980 frameLay->addWidget( myPreviewBtn );
1982 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1985 //================================================================================
1989 //================================================================================
1991 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1995 //================================================================================
1997 * \brief Sets available preview modes
1999 //================================================================================
2001 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2003 myPreviewMode->clear();
2004 QList<int>::const_iterator it = theModes.constBegin();
2005 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2007 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2008 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2009 myPreviewMode->setId( i, *it );
2011 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2014 //================================================================================
2016 * \brief Returns current preview mesh mode
2018 //================================================================================
2020 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2022 return myPreviewMode->currentId();
2025 //================================================================================
2027 * \brief Returns current preview mesh mode
2029 //================================================================================
2031 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2037 //================================================================================
2039 * \brief Constructor
2041 //================================================================================
2043 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2044 : SMESHGUI_BaseComputeOp()
2049 //================================================================================
2051 * \brief Desctructor
2053 //================================================================================
2055 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2059 //================================================================================
2061 * \brief perform it's intention action: compute mesh
2063 //================================================================================
2065 void SMESHGUI_EvaluateOp::startOperation()
2067 SMESHGUI_BaseComputeOp::evaluateDlg();
2068 SMESHGUI_BaseComputeOp::startOperation();
2069 if (myMesh->_is_nil())
2074 //================================================================================
2076 * \brief Gets dialog of this operation
2077 * \retval LightApp_Dialog* - pointer to dialog of this operation
2079 //================================================================================
2081 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2083 return evaluateDlg();
2086 //================================================================================
2088 * \brief evaluateMesh()
2090 //================================================================================
2092 void SMESHGUI_BaseComputeOp::evaluateMesh()
2096 SMESH::MemoryReserve aMemoryReserve;
2098 SMESH::compute_error_array_var aCompErrors;
2101 bool evaluateFailed = true, memoryLack = false;
2102 SMESH::long_array_var aRes;
2104 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2105 if ( !aMeshSObj ) // IPAL21340
2108 bool hasShape = myMesh->HasShapeToMesh();
2109 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2112 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2113 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2114 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2115 if ( errors->length() > 0 ) {
2116 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2118 SUIT_OverrideCursor aWaitCursor;
2120 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2123 aRes = gen->Evaluate(myMesh, myMainShape);
2125 catch(const SALOME::SALOME_Exception & S_ex){
2130 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2133 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2135 catch(const SALOME::SALOME_Exception & S_ex){
2141 aMemoryReserve.release();
2143 evaluateFailed = ( aCompErrors->length() > 0 );
2144 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
2148 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2149 bool noHypoError = ( aHypErrors.isEmpty() );
2151 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2152 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2154 bool isShowResultDlg = true;
2156 //switch( aNotifyMode ) {
2157 //case 0: // show the mesh computation result dialog NEVER
2158 //isShowResultDlg = false;
2161 //case 1: // show the mesh computation result dialog if there are some errors
2162 //if ( memoryLack || !noHypoError )
2163 // isShowResultDlg = true;
2166 // isShowResultDlg = false;
2170 //default: // show the result dialog after each mesh computation
2171 //isShowResultDlg = true;
2175 if ( isShowResultDlg )
2176 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2177 noHypoError, aHypErrors);
2181 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2182 const bool theMemoryLack,
2183 const bool theNoCompError,
2184 SMESH::compute_error_array_var& theCompErrors,
2185 const bool theNoHypoError,
2186 const QString& theHypErrors)
2188 bool hasShape = myMesh->HasShapeToMesh();
2189 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2190 aCompDlg->myMemoryLackGroup->hide();
2192 if ( theMemoryLack )
2194 aCompDlg->myMemoryLackGroup->show();
2195 aCompDlg->myFullInfo->hide();
2196 aCompDlg->myBriefInfo->hide();
2197 aCompDlg->myHypErrorGroup->hide();
2198 aCompDlg->myCompErrorGroup->hide();
2200 else if ( theNoCompError && theNoHypoError )
2202 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2203 aCompDlg->myFullInfo->show();
2204 aCompDlg->myBriefInfo->hide();
2205 aCompDlg->myHypErrorGroup->hide();
2206 aCompDlg->myCompErrorGroup->hide();
2210 QTableWidget* tbl = aCompDlg->myTable;
2211 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2212 aCompDlg->myBriefInfo->show();
2213 aCompDlg->myFullInfo->hide();
2215 if ( theNoHypoError ) {
2216 aCompDlg->myHypErrorGroup->hide();
2219 aCompDlg->myHypErrorGroup->show();
2220 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2223 if ( theNoCompError ) {
2224 aCompDlg->myCompErrorGroup->hide();
2227 aCompDlg->myCompErrorGroup->show();
2229 aCompDlg->myPublishBtn->hide();
2230 aCompDlg->myShowBtn->hide();
2232 // fill table of errors
2233 tbl->setRowCount( theCompErrors->length() );
2234 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2235 else tbl->showColumn( COL_SHAPE );
2236 tbl->setColumnWidth( COL_ERROR, 200 );
2238 bool hasBadMesh = false;
2239 for ( int row = 0; row < theCompErrors->length(); ++row )
2241 SMESH::ComputeError & err = theCompErrors[ row ];
2243 QString text = err.algoName.in();
2244 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2245 else tbl->item( row, COL_ALGO )->setText( text );
2247 text = SMESH::errorText( err.code, err.comment.in() );
2248 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2249 else tbl->item( row, COL_ERROR )->setText( text );
2251 text = QString("%1").arg( err.subShapeID );
2252 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2253 else tbl->item( row, COL_SHAPEID )->setText( text );
2255 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2256 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2257 else tbl->item( row, COL_SHAPE )->setText( text );
2259 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2260 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2261 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2263 text = err.hasBadMesh ? "hasBadMesh" : "";
2264 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2265 else tbl->item( row, COL_BAD_MESH )->setText( text );
2266 if ( err.hasBadMesh ) hasBadMesh = true;
2268 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2269 tbl->resizeRowToContents( row );
2271 tbl->resizeColumnToContents( COL_ALGO );
2272 tbl->resizeColumnToContents( COL_SHAPE );
2273 tbl->setWordWrap( true );
2277 aCompDlg->myBadMeshBtn->show();
2278 aCompDlg->myBadMeshToGroupBtn->show();
2282 aCompDlg->myBadMeshBtn->hide();
2283 aCompDlg->myBadMeshToGroupBtn->hide();
2285 tbl->setCurrentCell(0,0);
2286 currentCellChanged(); // to update buttons
2289 // show dialog and wait, becase Compute can be invoked from Preview operation
2290 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2295 //================================================================================
2297 * \brief Gets dialog of evaluate operation
2298 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2300 //================================================================================
2302 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2306 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2307 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2308 // connect signals and slots
2309 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2310 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2311 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2312 QTableWidget* aTable = me->table();
2313 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2314 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));