1 // Copyright (C) 2007-2012 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_ActorUtils.h"
38 #include <SMDS_SetIterator.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GEOM includes
43 #include <GEOM_Actor.h>
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_UpdateFlags.h>
48 #include <SALOME_ListIO.hxx>
49 #include <SVTK_ViewWindow.h>
50 #include <SVTK_ViewModel.h>
51 #include <SalomeApp_Application.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_MessageBox.h>
55 #include <SUIT_Desktop.h>
56 #include <QtxComboBox.h>
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDSClient_SObject.hxx>
63 #include <BRep_Tool.hxx>
65 #include <TopExp_Explorer.hxx>
66 #include <TopTools_IndexedMapOfShape.hxx>
69 #include <TopLoc_Location.hxx>
70 #include <Poly_Triangulation.hxx>
71 #include <Bnd_Box.hxx>
72 #include <BRepBndLib.hxx>
73 #include <BRepMesh_IncrementalMesh.hxx>
75 #include <Standard_ErrorHandler.hxx>
79 #include <QPushButton>
81 #include <QRadioButton>
82 #include <QTableWidget>
83 #include <QHeaderView>
84 #include <QGridLayout>
85 #include <QHBoxLayout>
86 #include <QVBoxLayout>
87 #include <QButtonGroup>
88 #include <QCloseEvent>
89 #include <QTimerEvent>
92 #include <vtkProperty.h>
101 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
104 static void addSeparator( QWidget* parent )
106 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
107 int row = l->rowCount();
108 int cols = l->columnCount();
109 for ( int i = 0; i < cols; i++ ) {
110 QFrame* hline = new QFrame( parent );
111 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
112 l->addWidget( hline, row, i );
118 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
121 //using namespace SMESH;
125 //=============================================================================
127 * \brief Allocate some memory at construction and release it at destruction.
128 * Is used to be able to continue working after mesh generation or visualization
129 * break due to lack of memory
131 //=============================================================================
136 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
137 void release() { delete [] myBuf; myBuf = 0; }
138 ~MemoryReserve() { release(); }
141 // =========================================================================================
143 * \brief Class showing shapes without publishing
145 // =========================================================================================
147 class TShapeDisplayer
150 // -----------------------------------------------------------------------
151 TShapeDisplayer(): myViewWindow(0)
153 myProperty = vtkProperty::New();
154 myProperty->SetRepresentationToWireframe();
155 myProperty->SetColor( 250, 0, 250 );
156 myProperty->SetAmbientColor( 250, 0, 250 );
157 myProperty->SetDiffuseColor( 250, 0, 250 );
158 //myProperty->SetSpecularColor( 250, 0, 250 );
159 myProperty->SetLineWidth( 5 );
161 // -----------------------------------------------------------------------
165 myProperty->Delete();
167 // -----------------------------------------------------------------------
170 if ( hasViewWindow() ) {
171 TActorIterator actorIt = actorIterator();
172 while ( actorIt.more() )
173 if (VTKViewer_Actor* anActor = actorIt.next()) {
174 myViewWindow->RemoveActor( anActor );
178 myIndexToShape.Clear();
180 myShownActors.clear();
183 // -----------------------------------------------------------------------
184 void SetVisibility (bool theVisibility)
186 TActorIterator actorIt = shownIterator();
187 while ( actorIt.more() )
188 if (VTKViewer_Actor* anActor = actorIt.next())
189 anActor->SetVisibility(theVisibility);
190 SMESH::RepaintCurrentView();
192 // -----------------------------------------------------------------------
193 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
195 std::string mainEntry;
196 if ( !aMainShape->_is_nil() )
197 mainEntry = aMainShape->GetStudyEntry();
198 return ( myMainEntry == mainEntry &&
199 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
201 // -----------------------------------------------------------------------
202 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
204 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
205 std::string mainEntry;
206 if ( !aMainShape->_is_nil() )
207 mainEntry = aMainShape->GetStudyEntry();
208 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
211 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
212 checkTriangulation( aShape );
213 TopExp::MapShapes(aShape, myIndexToShape);
214 myActors.resize( myIndexToShape.Extent(), 0 );
215 myShownActors.reserve( myIndexToShape.Extent() );
217 myMainEntry = mainEntry;
218 myViewWindow = aViewWindow;
220 if ( only ) { // hide shown actors
221 TActorIterator actorIt = shownIterator();
222 while ( actorIt.more() )
223 if (VTKViewer_Actor* anActor = actorIt.next())
224 anActor->SetVisibility(false);
225 myShownActors.clear();
227 // find actors to show
228 TopoDS_Shape aShape = myIndexToShape( subShapeID );
229 if ( !aShape.IsNull() ) {
230 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
231 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
232 //checkTriangulation( exp.Current() );
233 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
234 myShownActors.push_back( anActor );
236 if ( type == TopAbs_FACE ) {
237 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
238 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
239 if ( !BRep_Tool::Degenerated( edge ))
240 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
241 myShownActors.push_back( anActor );
245 myBuiltSubs.insert( subShapeID );
248 // -----------------------------------------------------------------------
252 typedef std::vector<GEOM_Actor*> TActorVec;
254 TActorVec myShownActors;
255 TopTools_IndexedMapOfShape myIndexToShape;
256 std::string myMainEntry;
257 SVTK_ViewWindow* myViewWindow;
258 vtkProperty* myProperty;
259 std::set<int> myBuiltSubs;
261 // -----------------------------------------------------------------------
262 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
263 TActorIterator actorIterator() {
264 return TActorIterator( myActors.begin(), myActors.end() );
266 TActorIterator shownIterator() {
267 return TActorIterator( myShownActors.begin(), myShownActors.end() );
269 // -----------------------------------------------------------------------
270 GEOM_Actor* getActor(const TopoDS_Shape& shape)
272 int index = myIndexToShape.FindIndex( shape ) - 1;
273 if ( index < 0 || index >= myActors.size() )
275 GEOM_Actor* & actor = myActors[ index ];
277 actor = GEOM_Actor::New();
279 actor->SetShape(shape,0,0);
280 actor->SetProperty(myProperty);
281 actor->SetShadingProperty(myProperty);
282 actor->SetWireframeProperty(myProperty);
283 actor->SetPreviewProperty(myProperty);
284 actor->PickableOff();
285 // if ( shape.ShapeType() == TopAbs_EDGE )
286 // actor->SubShapeOn();
287 myViewWindow->AddActor( actor );
292 // -----------------------------------------------------------------------
293 void checkTriangulation(const TopoDS_Shape& shape)
295 TopLoc_Location aLoc;
296 Standard_Boolean alreadymesh = Standard_True;
297 TopExp_Explorer ex(shape, TopAbs_FACE);
299 for ( ; ex.More(); ex.Next()) {
300 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
301 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
302 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
305 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
306 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
307 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
308 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
310 if (alreadymesh) return;
311 // Compute default deflection
313 BRepBndLib::Add(shape, B);
314 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
315 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
316 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
317 BRepMesh_IncrementalMesh MESH(shape,deflection);
319 // -----------------------------------------------------------------------
320 bool hasViewWindow() const
322 if ( !myViewWindow ) return false;
324 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
325 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
331 // =========================================================================================
333 * \brief Return text describing an error
335 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
336 QString errorText(int errCode, const char* comment)
340 CASE2TEXT( COMPERR_OK );
341 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
342 CASE2TEXT( COMPERR_STD_EXCEPTION );
343 CASE2TEXT( COMPERR_OCC_EXCEPTION );
344 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
345 CASE2TEXT( COMPERR_EXCEPTION );
346 CASE2TEXT( COMPERR_MEMORY_PB );
347 CASE2TEXT( COMPERR_BAD_SHAPE );
348 CASE2TEXT( COMPERR_CANCELED );
349 case SMESH::COMPERR_ALGO_FAILED:
350 if ( strlen(comment) == 0 )
351 text = QObject::tr("COMPERR_ALGO_FAILED");
353 case SMESH::COMPERR_WARNING:
354 return comment ? QString(comment) : QObject::tr("COMPERR_UNKNOWN");
356 text = QString("#%1").arg( -errCode );
358 if ( text.length() > 0 ) text += ". ";
359 return text + comment;
361 // -----------------------------------------------------------------------
363 * \brief Return SO of a sub-shape
365 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
367 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
368 if ( subShapeID == 1 || !so )
370 _PTR(ChildIterator) it;
371 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
372 it = study->NewChildIterator(so);
375 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
376 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
377 if ( !geom->_is_nil() ) {
378 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
379 if ( list->length() == 1 && list[0] == subShapeID )
386 // -----------------------------------------------------------------------
388 * \brief Return sub-shape by ID
390 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
392 GEOM::GEOM_Object_var aSubShape;
393 if ( subShapeID == 1 )
394 aSubShape = aMainShape;
395 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
396 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
398 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
399 return aSubShape._retn();
401 // -----------------------------------------------------------------------
403 * \brief Return shape type name
405 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
406 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
409 if ( !aShape->_is_nil() ) {
410 switch ( aShape->GetShapeType() ) {
417 CASE2NAME( COMPSOLID );
418 CASE2NAME( COMPOUND );
424 // -----------------------------------------------------------------------
426 * \brief Return text describing a sub-shape
428 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
431 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
432 text = aSO->GetName().c_str();
434 text = QString("#%1").arg( subShapeID );
435 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
436 if ( typeName.length() )
437 text += QString(" (%1)").arg(typeName);
441 // -----------------------------------------------------------------------
443 * \brief Return a list of selected rows
445 int getSelectedRows(QTableWidget* table, QList<int>& rows)
448 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
449 QTableWidgetSelectionRange range;
450 foreach( range, selRanges )
452 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
455 if ( rows.isEmpty() && table->currentRow() > -1 )
456 rows.append( table->currentRow() );
464 // =========================================================================================
466 * \brief Dialog to compute a mesh and show computation errors
468 //=======================================================================
470 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
471 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
473 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
474 aDlgLay->setMargin( 0 );
475 aDlgLay->setSpacing( SPACING );
477 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
479 aDlgLay->addWidget(aMainFrame);
481 aDlgLay->setStretchFactor(aMainFrame, 1);
484 // =========================================================================================
488 //=======================================================================
490 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
494 //=======================================================================
495 // function : createMainFrame()
496 // purpose : Create frame containing dialog's fields
497 //=======================================================================
499 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
501 QFrame* aFrame = new QFrame(theParent);
503 SUIT_ResourceMgr* rm = resourceMgr();
504 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
510 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
513 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
515 QButtonGroup* aBtnGrp = new QButtonGroup(this);
516 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
517 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
519 QRadioButton* aRBut = new QRadioButton(aPixGrp);
520 aRBut->setIcon(iconCompute);
521 aRBut->setChecked(true);
522 aPixGrpLayout->addWidget(aRBut);
523 aBtnGrp->addButton(aRBut, 0);
527 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
528 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
529 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
530 myMeshName = new QLabel(nameBox);
531 nameBoxLayout->addWidget(myMeshName);
535 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
536 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
538 // Computation errors
540 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
541 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
542 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
543 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
544 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
545 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
547 //myTable->setReadOnly( true ); // VSR: check
548 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
549 myTable->hideColumn( COL_PUBLISHED );
550 myTable->hideColumn( COL_SHAPEID );
551 myTable->hideColumn( COL_BAD_MESH );
552 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
553 myTable->setWordWrap( true );
554 myTable->horizontalHeader()->setStretchLastSection( true );
555 myTable->setMinimumWidth( 500 );
558 headers << tr( "COL_ALGO_HEADER" );
559 headers << tr( "COL_SHAPE_HEADER" );
560 headers << tr( "COL_ERROR_HEADER" );
561 headers << tr( "COL_SHAPEID_HEADER" );
562 headers << tr( "COL_PUBLISHED_HEADER" );
564 myTable->setHorizontalHeaderLabels( headers );
567 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
568 grpLayout->setSpacing(SPACING);
569 grpLayout->setMargin(MARGIN);
570 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
571 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
572 grpLayout->addWidget( myShowBtn, 2, 0 );
573 grpLayout->addWidget( myPublishBtn, 2, 1 );
574 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
575 grpLayout->setColumnStretch( 3, 1 );
577 // Hypothesis definition errors
579 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
580 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
581 myHypErrorGroupLayout->setMargin(MARGIN);
582 myHypErrorGroupLayout->setSpacing(SPACING);
583 myHypErrorLabel = new QLabel(myHypErrorGroup);
584 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
588 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
589 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
590 myMemoryLackGroupLayout->setMargin(MARGIN);
591 myMemoryLackGroupLayout->setSpacing(SPACING);
592 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
593 QFont bold = memLackLabel->font(); bold.setBold(true);
594 memLackLabel->setFont( bold );
595 memLackLabel->setMinimumWidth(300);
596 myMemoryLackGroupLayout->addWidget(memLackLabel);
598 // add all widgets to aFrame
599 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
600 aLay->setMargin( 0 );
601 aLay->setSpacing( 0 );
602 aLay->addWidget( aPixGrp );
603 aLay->addWidget( nameBox );
604 aLay->addWidget( myBriefInfo );
605 aLay->addWidget( myFullInfo );
606 aLay->addWidget( myHypErrorGroup );
607 aLay->addWidget( myCompErrorGroup );
608 aLay->addWidget( myMemoryLackGroup );
609 aLay->setStretchFactor( myCompErrorGroup, 1 );
611 ((QPushButton*) button( OK ))->setDefault( true );
616 //================================================================================
620 //================================================================================
622 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
623 : SMESHGUI_Operation(), myCompDlg( 0 )
625 myTShapeDisplayer = new SMESH::TShapeDisplayer();
626 myBadMeshDisplayer = 0;
628 //myHelpFileName = "/files/about_meshes.htm"; // V3
629 myHelpFileName = "about_meshes_page.html"; // V4
632 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
634 LightApp_SelectionMgr* Sel = selectionMgr();
635 SALOME_ListIO selected; Sel->selectedObjects( selected );
636 Handle(SALOME_InteractiveObject) anIO = selected.First();
637 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
638 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
641 //================================================================================
643 * \brief Start operation
644 * \purpose Init dialog fields, connect signals and slots, show dialog
646 //================================================================================
648 void SMESHGUI_BaseComputeOp::startOperation()
650 // create compute dialog if not created before
653 myMesh = SMESH::SMESH_Mesh::_nil();
654 myMainShape = GEOM::GEOM_Object::_nil();
657 LightApp_SelectionMgr *Sel = selectionMgr();
658 SALOME_ListIO selected; Sel->selectedObjects( selected );
660 int nbSel = selected.Extent();
662 SUIT_MessageBox::warning(desktop(),
663 tr("SMESH_WRN_WARNING"),
664 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
669 myIObject = selected.First();
670 myMesh = SMESH::GetMeshByIO(myIObject);
671 if (myMesh->_is_nil()) {
672 SUIT_MessageBox::warning(desktop(),
673 tr("SMESH_WRN_WARNING"),
674 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
678 myMainShape = myMesh->GetShapeToMesh();
680 SMESHGUI_Operation::startOperation();
683 //================================================================================
684 //================================================================================
686 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
687 SMESH::SMESH_Mesh_var mesh,
688 GEOM::GEOM_Object_var mainShape)
693 myMainShape = mainShape;
696 void SMESHGUI_ComputeDlg_QThread::run()
698 myResult = myGen->Compute(myMesh, myMainShape);
701 bool SMESHGUI_ComputeDlg_QThread::result()
706 void SMESHGUI_ComputeDlg_QThread::cancel()
708 myGen->CancelCompute(myMesh, myMainShape);
711 //================================================================================
712 //================================================================================
714 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *parent,
715 SMESH::SMESH_Gen_var gen,
716 SMESH::SMESH_Mesh_var mesh,
717 GEOM::GEOM_Object_var mainShape)
719 qthread(gen, mesh, mainShape)
722 setWindowTitle(tr("Compute"));
723 cancelButton = new QPushButton(tr("Cancel"));
724 cancelButton->setDefault(true);
725 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
726 QHBoxLayout *layout = new QHBoxLayout;
727 layout->addWidget(cancelButton);
731 startTimer(30); // 30 millisecs
735 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
737 return qthread.result();
740 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
745 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
747 if(qthread.isFinished())
754 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
756 if(qthread.isRunning())
764 //================================================================================
766 * \brief computeMesh()
768 //================================================================================
770 void SMESHGUI_BaseComputeOp::computeMesh()
774 SMESH::MemoryReserve aMemoryReserve;
776 SMESH::compute_error_array_var aCompErrors;
779 bool computeFailed = true, memoryLack = false;
781 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
782 if ( !aMeshSObj ) // IPAL 21340
784 bool hasShape = myMesh->HasShapeToMesh();
785 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
788 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
789 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
790 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
791 if ( errors->length() > 0 ) {
792 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
794 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
795 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
796 tr( "FULL_RECOMPUTE_QUESTION" ),
797 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
799 SUIT_OverrideCursor aWaitCursor;
801 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
804 //SMESH::UpdateNulData(myIObject, true);
806 #ifdef WITH_SMESH_CANCEL_COMPUTE
807 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
808 qthreaddialog.exec();
809 res = qthreaddialog.result();
811 res = gen->Compute(myMesh, myMainShape);
814 computeFailed = false;
816 catch(const SALOME::SALOME_Exception & S_ex){
820 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
823 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
824 // check if there are memory problems
825 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
826 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
828 catch(const SALOME::SALOME_Exception & S_ex){
832 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
836 // NPAL16631: if ( !memoryLack )
838 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
839 update( UF_ObjBrowser | UF_Model );
842 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
843 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
844 long newSize = myMesh->NbElements();
848 if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
851 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
854 SMESH::Update(myIObject, true);
858 MESSAGE ( "Exception thrown during mesh visualization" );
860 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
861 SMESH::OnVisuException();
868 else if ( limitExceeded )
870 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
871 SUIT_MessageBox::warning( desktop(),
872 tr( "SMESH_WRN_WARNING" ),
873 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
876 LightApp_SelectionMgr *Sel = selectionMgr();
879 SALOME_ListIO selected;
880 selected.Append( myIObject );
881 Sel->setSelectedObjects( selected );
887 aMemoryReserve.release();
889 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
893 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
894 bool noHypoError = ( aHypErrors.isEmpty() );
896 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
897 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
899 bool isShowResultDlg = true;
900 switch( aNotifyMode ) {
901 case 0: // show the mesh computation result dialog NEVER
902 isShowResultDlg = false;
905 case 1: // show the mesh computation result dialog if there are some errors
906 if ( memoryLack || !noCompError || !noHypoError )
907 isShowResultDlg = true;
910 isShowResultDlg = false;
914 default: // show the result dialog after each mesh computation
915 isShowResultDlg = true;
919 if ( isShowResultDlg )
920 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
923 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
924 const bool theNoCompError,
925 SMESH::compute_error_array_var& theCompErrors,
926 const bool theNoHypoError,
927 const QString& theHypErrors )
929 bool hasShape = myMesh->HasShapeToMesh();
930 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
931 aCompDlg->myMemoryLackGroup->hide();
935 aCompDlg->myMemoryLackGroup->show();
936 aCompDlg->myFullInfo->hide();
937 aCompDlg->myBriefInfo->hide();
938 aCompDlg->myHypErrorGroup->hide();
939 aCompDlg->myCompErrorGroup->hide();
941 else if ( theNoCompError && theNoHypoError )
943 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
944 aCompDlg->myFullInfo->SetMeshInfo( aRes );
945 aCompDlg->myFullInfo->show();
946 aCompDlg->myBriefInfo->hide();
947 aCompDlg->myHypErrorGroup->hide();
948 aCompDlg->myCompErrorGroup->hide();
952 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
953 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
954 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING );
956 // full or brief mesh info
957 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
958 if ( onlyWarnings ) {
959 aCompDlg->myFullInfo->SetMeshInfo( aRes );
960 aCompDlg->myFullInfo->show();
961 aCompDlg->myBriefInfo->hide();
963 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
964 aCompDlg->myBriefInfo->show();
965 aCompDlg->myFullInfo->hide();
968 // pbs of hypo dfinitions
969 if ( theNoHypoError ) {
970 aCompDlg->myHypErrorGroup->hide();
972 aCompDlg->myHypErrorGroup->show();
973 aCompDlg->myHypErrorLabel->setText( theHypErrors );
977 if ( theNoCompError )
979 aCompDlg->myCompErrorGroup->hide();
983 aCompDlg->myCompErrorGroup->show();
986 aCompDlg->myWarningLabel->show();
988 aCompDlg->myWarningLabel->hide();
991 aCompDlg->myPublishBtn->hide();
992 aCompDlg->myShowBtn->hide();
995 aCompDlg->myPublishBtn->show();
996 aCompDlg->myShowBtn->show();
999 // fill table of errors
1000 QTableWidget* tbl = aCompDlg->myTable;
1001 tbl->setRowCount( theCompErrors->length() );
1002 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1003 else tbl->showColumn( COL_SHAPE );
1004 tbl->setColumnWidth( COL_ERROR, 200 );
1006 bool hasBadMesh = false;
1007 for ( int row = 0; row < theCompErrors->length(); ++row )
1009 SMESH::ComputeError & err = theCompErrors[ row ];
1011 QString text = err.algoName.in();
1012 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1013 else tbl->item( row, COL_ALGO )->setText( text );
1015 text = SMESH::errorText( err.code, err.comment.in() );
1016 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1017 else tbl->item( row, COL_ERROR )->setText( text );
1019 text = QString("%1").arg( err.subShapeID );
1020 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1021 else tbl->item( row, COL_SHAPEID )->setText( text );
1023 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1024 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1025 else tbl->item( row, COL_SHAPE )->setText( text );
1027 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1028 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1029 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1031 text = err.hasBadMesh ? "hasBadMesh" : "";
1032 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1033 else tbl->item( row, COL_BAD_MESH )->setText( text );
1034 if ( err.hasBadMesh ) hasBadMesh = true;
1036 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1037 tbl->resizeRowToContents( row );
1039 tbl->resizeColumnToContents( COL_ALGO );
1040 tbl->resizeColumnToContents( COL_SHAPE );
1041 tbl->setWordWrap( true );
1044 aCompDlg->myBadMeshBtn->show();
1046 aCompDlg->myBadMeshBtn->hide();
1048 tbl->setCurrentCell(0,0);
1049 currentCellChanged(); // to update buttons
1052 // show dialog and wait, becase Compute can be invoked from Preview operation
1053 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1057 //================================================================================
1059 * \brief Stops operation
1061 //================================================================================
1063 void SMESHGUI_BaseComputeOp::stopOperation()
1065 SMESHGUI_Operation::stopOperation();
1066 if ( myTShapeDisplayer )
1067 myTShapeDisplayer->SetVisibility( false );
1068 if ( myBadMeshDisplayer ) {
1069 myBadMeshDisplayer->SetVisibility( false );
1070 // delete it in order not to have problems at its destruction when the viewer
1071 // where it worked is dead due to e.g. study closing
1072 delete myBadMeshDisplayer;
1073 myBadMeshDisplayer = 0;
1075 myIObject.Nullify();
1078 //================================================================================
1080 * \brief publish selected sub-shape
1082 //================================================================================
1084 void SMESHGUI_BaseComputeOp::onPublishShape()
1086 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1087 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1090 SMESH::getSelectedRows( table(), rows );
1092 foreach ( row, rows )
1094 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1095 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1096 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1098 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1100 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1101 SALOMEDS::SObject_var so =
1102 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1103 // look for myMainShape in the table
1104 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1105 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1106 if ( so->_is_nil() ) {
1107 table()->item( r, COL_SHAPE )->setText( so->GetName() );
1108 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1113 if ( curSub == 1 ) continue;
1115 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1116 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1117 if ( !so->_is_nil() ) {
1118 table()->item( row, COL_SHAPE )->setText( so->GetName() );
1119 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1123 getSMESHGUI()->getApp()->updateObjectBrowser();
1124 currentCellChanged(); // to update buttons
1127 //================================================================================
1129 * \brief show mesh elements preventing computation of a submesh of current row
1131 //================================================================================
1133 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1135 myTShapeDisplayer->SetVisibility( false );
1137 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1138 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1140 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1141 SMESHGUI* gui = getSMESHGUI();
1142 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1143 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1144 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1145 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1146 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1147 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1148 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1149 // delete property !!!!!!!!!!
1150 vtkProperty* prop = vtkProperty::New();
1151 prop->SetLineWidth( aLineWidth * 3 );
1152 prop->SetPointSize( aPointSize * 3 );
1153 prop->SetColor( 250, 0, 250 );
1154 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1155 myBadMeshDisplayer->SetData( aMeshData._retn() );
1160 //================================================================================
1162 * \brief SLOT called when a selected cell in table() changed
1164 //================================================================================
1166 void SMESHGUI_BaseComputeOp::currentCellChanged()
1168 myTShapeDisplayer->SetVisibility( false );
1169 if ( myBadMeshDisplayer )
1170 myBadMeshDisplayer->SetVisibility( false );
1172 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1174 int nbSelected = SMESH::getSelectedRows( table(), rows );
1176 foreach ( row, rows )
1178 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1179 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1180 if ( hasData && !isPublished )
1181 publishEnable = true;
1183 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1184 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1186 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1193 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1196 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1197 myCompDlg->myShowBtn ->setEnabled( showEnable );
1198 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1201 //================================================================================
1203 * \brief update preview
1205 //================================================================================
1207 void SMESHGUI_BaseComputeOp::onPreviewShape()
1209 if ( myTShapeDisplayer )
1211 SUIT_OverrideCursor aWaitCursor;
1213 SMESH::getSelectedRows( table(), rows );
1215 bool showOnly = true;
1217 foreach ( row, rows )
1219 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1221 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1225 currentCellChanged(); // to update buttons
1229 //================================================================================
1233 //================================================================================
1235 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1239 delete myTShapeDisplayer;
1240 if ( myBadMeshDisplayer )
1241 delete myBadMeshDisplayer;
1244 //================================================================================
1246 * \brief Gets dialog of compute operation
1247 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1249 //================================================================================
1251 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1255 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1256 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1257 // connect signals and slots
1258 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1259 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1260 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1262 QTableWidget* aTable = me->table();
1263 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1264 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1269 //================================================================================
1271 * \brief returns from compute mesh result dialog
1273 //================================================================================
1275 bool SMESHGUI_BaseComputeOp::onApply()
1280 //================================================================================
1282 * \brief Return a table
1284 //================================================================================
1286 QTableWidget* SMESHGUI_BaseComputeOp::table()
1288 return myCompDlg->myTable;
1292 //================================================================================
1294 * \brief Constructor
1296 //================================================================================
1298 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1299 : SMESHGUI_BaseComputeOp()
1304 //================================================================================
1306 * \brief Desctructor
1308 //================================================================================
1310 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1314 //================================================================================
1316 * \brief perform it's intention action: compute mesh
1318 //================================================================================
1320 void SMESHGUI_ComputeOp::startOperation()
1322 SMESHGUI_BaseComputeOp::startOperation();
1323 if (myMesh->_is_nil())
1328 //================================================================================
1330 * \brief check the same operations on the same mesh
1332 //================================================================================
1334 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1336 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1338 if ( !myMesh->_is_nil() && baseOp ) {
1339 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1340 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1345 //================================================================================
1347 * \brief Gets dialog of this operation
1348 * \retval LightApp_Dialog* - pointer to dialog of this operation
1350 //================================================================================
1352 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1354 return computeDlg();
1357 //================================================================================
1359 * \brief Constructor
1361 //================================================================================
1363 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1364 : SMESHGUI_BaseComputeOp(),
1368 myPreviewDisplayer( 0 )
1370 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1373 //================================================================================
1377 //================================================================================
1379 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1386 if ( myPreviewDisplayer )
1387 delete myPreviewDisplayer;
1388 myPreviewDisplayer = 0;
1391 //================================================================================
1393 * \brief Gets current dialog of this operation
1394 * \retval LightApp_Dialog* - pointer to dialog of this operation
1396 //================================================================================
1398 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1403 //================================================================================
1405 * \brief perform it's intention action: prepare data
1407 //================================================================================
1409 void SMESHGUI_PrecomputeOp::startOperation()
1413 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1416 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1417 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1418 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1420 myActiveDlg = myDlg;
1422 // connect signal to compute dialog. which will be shown after Compute mesh operation
1423 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1426 // disconnect signals
1427 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1428 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1429 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1430 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1431 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1434 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1435 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1436 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1437 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1438 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1439 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1440 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1441 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1442 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1443 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1446 SMESHGUI_BaseComputeOp::startOperation();
1447 if (myMesh->_is_nil())
1450 if (myDlg->getPreviewMode() == -1)
1452 // nothing to preview
1453 SUIT_MessageBox::warning(desktop(),
1454 tr("SMESH_WRN_WARNING"),
1455 tr("SMESH_WRN_NOTHING_PREVIEW"));
1460 // disconnect slot from preview dialog to have Apply from results of compute operation only
1461 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1462 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1467 //================================================================================
1469 * \brief Stops operation
1471 //================================================================================
1473 void SMESHGUI_PrecomputeOp::stopOperation()
1475 if ( myPreviewDisplayer )
1477 myPreviewDisplayer->SetVisibility( false );
1478 delete myPreviewDisplayer;
1479 myPreviewDisplayer = 0;
1481 myMapShapeId.clear();
1482 SMESHGUI_BaseComputeOp::stopOperation();
1485 //================================================================================
1487 * \brief reinitialize dialog after operaiton become active again
1489 //================================================================================
1491 void SMESHGUI_PrecomputeOp::resumeOperation()
1493 if ( myActiveDlg == myDlg )
1495 SMESHGUI_BaseComputeOp::resumeOperation();
1498 //================================================================================
1500 * \brief perform it's intention action: reinitialise dialog
1502 //================================================================================
1504 void SMESHGUI_PrecomputeOp::initDialog()
1508 QMap<int, int> modeMap;
1509 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1510 getAssignedAlgos( pMesh, modeMap );
1511 if ( modeMap.contains( SMESH::DIM_3D ) )
1513 if ( modeMap.contains( SMESH::DIM_2D ) )
1514 modes.append( SMESH::DIM_2D );
1515 if ( modeMap.contains( SMESH::DIM_1D ) )
1516 modes.append( SMESH::DIM_1D );
1518 else if ( modeMap.contains( SMESH::DIM_2D ) )
1520 if ( modeMap.contains( SMESH::DIM_1D ) )
1521 modes.append( SMESH::DIM_1D );
1524 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1525 myOrderMgr->SetMesh( myMesh );
1526 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1527 myDlg->getMeshOrderBox()->setShown(isOrder);
1533 myDlg->setPreviewModes( modes );
1536 //================================================================================
1538 * \brief detect asigned mesh algorithms
1540 //================================================================================
1542 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1543 QMap<int,int>& theModeMap)
1545 _PTR(SObject) aHypRoot;
1546 _PTR(GenericAttribute) anAttr;
1547 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1548 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1550 _PTR(ChildIterator) anIter =
1551 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1552 for ( ; anIter->More(); anIter->Next() )
1554 _PTR(SObject) anObj = anIter->Value();
1555 _PTR(SObject) aRefObj;
1556 if ( anObj->ReferencedObject( aRefObj ) )
1561 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1563 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1564 if ( CORBA::is_nil( aVar ) )
1567 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1569 SMESH::SMESH_Algo_var algo;
1571 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1572 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1573 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1576 if ( !algo->_is_nil() )
1577 theModeMap[ dim ] = 0;
1584 //================================================================================
1586 * \brief perform it's intention action: compute mesh
1588 //================================================================================
1590 void SMESHGUI_PrecomputeOp::onCompute()
1593 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1594 myOrderMgr->SetMeshOrder();
1595 myMapShapeId.clear();
1596 myActiveDlg = computeDlg();
1600 //================================================================================
1602 * \brief perform it's intention action: compute mesh
1604 //================================================================================
1606 void SMESHGUI_PrecomputeOp::onCancel()
1608 QObject* curDlg = sender();
1609 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1611 // return from error messages
1616 bool isRestoreOrder = false;
1617 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1619 // ask to remove already computed mesh elements
1620 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1621 tr( "CLEAR_SUBMESH_QUESTION" ),
1622 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1624 // remove all submeshes for collected shapes
1625 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1626 for ( ; it != myMapShapeId.constEnd(); ++it )
1627 myMesh->ClearSubMesh( *it );
1628 isRestoreOrder = true;
1632 // return previous mesh order
1633 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1634 if (!isRestoreOrder)
1636 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1637 tr( "SMESH_REJECT_MESH_ORDER" ),
1638 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1640 myOrderMgr->SetMeshOrder(myPrevOrder);
1646 myMapShapeId.clear();
1647 SMESHGUI_BaseComputeOp::onCancel();
1650 //================================================================================
1652 * \brief perform it's intention action: preview mesh
1654 //================================================================================
1656 void SMESHGUI_PrecomputeOp::onPreview()
1658 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1661 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1665 // set modified submesh priority if any
1666 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1667 myOrderMgr->SetMeshOrder();
1669 // Compute preview of mesh,
1670 // i.e. compute mesh till indicated dimension
1671 int dim = myDlg->getPreviewMode();
1673 SMESH::MemoryReserve aMemoryReserve;
1675 SMESH::compute_error_array_var aCompErrors;
1678 bool computeFailed = true, memoryLack = false;
1680 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1681 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1683 SMESHGUI* gui = getSMESHGUI();
1684 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1685 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1686 if ( errors->length() > 0 ) {
1687 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1690 SUIT_OverrideCursor aWaitCursor;
1692 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1693 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1694 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1696 SMESH::long_array_var aShapesId = new SMESH::long_array();
1698 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1702 SMESH::MeshPreviewStruct_var previewData =
1703 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1705 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1706 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1708 computeFailed = false;
1709 myPreviewDisplayer->SetData( previewRes );
1710 // append shape indeces with computed mesh entities
1711 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1712 myMapShapeId[ aShapesId[ i ] ] = 0;
1715 myPreviewDisplayer->SetVisibility(false);
1717 catch(const SALOME::SALOME_Exception & S_ex){
1719 myPreviewDisplayer->SetVisibility(false);
1723 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1726 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1727 // check if there are memory problems
1728 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1729 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1731 catch(const SALOME::SALOME_Exception & S_ex){
1736 aMemoryReserve.release();
1738 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1739 bool noHypoError = ( aHypErrors.isEmpty() );
1741 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1742 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1744 bool isShowError = true;
1745 switch( aNotifyMode ) {
1746 case 0: // show the mesh computation result dialog NEVER
1747 isShowError = false;
1749 case 1: // show the mesh computation result dialog if there are some errors
1750 default: // show the result dialog after each mesh computation
1751 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1752 isShowError = false;
1756 aWaitCursor.suspend();
1761 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1762 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1767 //================================================================================
1769 * \brief Constructor
1771 //================================================================================
1773 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1774 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1777 setWindowTitle( tr( "CAPTION" ) );
1779 setButtonText( OK, tr( "COMPUTE" ) );
1780 QFrame* main = mainFrame();
1782 QVBoxLayout* layout = new QVBoxLayout( main );
1784 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1785 layout->addWidget(myOrderBox);
1787 QFrame* frame = new QFrame( main );
1788 layout->setMargin(0); layout->setSpacing(0);
1789 layout->addWidget( frame );
1791 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1792 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1794 myPreviewMode = new QtxComboBox( frame );
1795 frameLay->addWidget( myPreviewMode );
1797 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1798 frameLay->addWidget( myPreviewBtn );
1800 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1803 //================================================================================
1807 //================================================================================
1809 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1813 //================================================================================
1815 * \brief Sets available preview modes
1817 //================================================================================
1819 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1821 myPreviewMode->clear();
1822 QList<int>::const_iterator it = theModes.constBegin();
1823 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1825 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1826 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1827 myPreviewMode->setId( i, *it );
1829 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1832 //================================================================================
1834 * \brief Returns current preview mesh mode
1836 //================================================================================
1838 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1840 return myPreviewMode->currentId();
1843 //================================================================================
1845 * \brief Returns current preview mesh mode
1847 //================================================================================
1849 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1855 //================================================================================
1857 * \brief Constructor
1859 //================================================================================
1861 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1862 : SMESHGUI_BaseComputeOp()
1867 //================================================================================
1869 * \brief Desctructor
1871 //================================================================================
1873 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1877 //================================================================================
1879 * \brief perform it's intention action: compute mesh
1881 //================================================================================
1883 void SMESHGUI_EvaluateOp::startOperation()
1885 SMESHGUI_BaseComputeOp::evaluateDlg();
1886 SMESHGUI_BaseComputeOp::startOperation();
1887 if (myMesh->_is_nil())
1892 //================================================================================
1894 * \brief Gets dialog of this operation
1895 * \retval LightApp_Dialog* - pointer to dialog of this operation
1897 //================================================================================
1899 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1901 return evaluateDlg();
1904 //================================================================================
1906 * \brief evaluateMesh()
1908 //================================================================================
1910 void SMESHGUI_BaseComputeOp::evaluateMesh()
1914 SMESH::MemoryReserve aMemoryReserve;
1916 SMESH::compute_error_array_var aCompErrors;
1919 bool evaluateFailed = true, memoryLack = false;
1920 SMESH::long_array_var aRes;
1922 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1923 if ( !aMeshSObj ) // IPAL21340
1926 bool hasShape = myMesh->HasShapeToMesh();
1927 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1930 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1931 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1932 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1933 if ( errors->length() > 0 ) {
1934 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1936 SUIT_OverrideCursor aWaitCursor;
1938 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1941 aRes = gen->Evaluate(myMesh, myMainShape);
1943 catch(const SALOME::SALOME_Exception & S_ex){
1948 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1951 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1953 catch(const SALOME::SALOME_Exception & S_ex){
1959 aMemoryReserve.release();
1961 evaluateFailed = ( aCompErrors->length() > 0 );
1962 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1966 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1967 bool noHypoError = ( aHypErrors.isEmpty() );
1969 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1970 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1972 bool isShowResultDlg = true;
1974 //switch( aNotifyMode ) {
1975 //case 0: // show the mesh computation result dialog NEVER
1976 //isShowResultDlg = false;
1979 //case 1: // show the mesh computation result dialog if there are some errors
1980 //if ( memoryLack || !noHypoError )
1981 // isShowResultDlg = true;
1984 // isShowResultDlg = false;
1988 //default: // show the result dialog after each mesh computation
1989 //isShowResultDlg = true;
1993 if ( isShowResultDlg )
1994 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1995 noHypoError, aHypErrors);
1999 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2000 const bool theMemoryLack,
2001 const bool theNoCompError,
2002 SMESH::compute_error_array_var& theCompErrors,
2003 const bool theNoHypoError,
2004 const QString& theHypErrors)
2006 bool hasShape = myMesh->HasShapeToMesh();
2007 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2008 aCompDlg->myMemoryLackGroup->hide();
2010 if ( theMemoryLack )
2012 aCompDlg->myMemoryLackGroup->show();
2013 aCompDlg->myFullInfo->hide();
2014 aCompDlg->myBriefInfo->hide();
2015 aCompDlg->myHypErrorGroup->hide();
2016 aCompDlg->myCompErrorGroup->hide();
2018 else if ( theNoCompError && theNoHypoError )
2020 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2021 aCompDlg->myFullInfo->show();
2022 aCompDlg->myBriefInfo->hide();
2023 aCompDlg->myHypErrorGroup->hide();
2024 aCompDlg->myCompErrorGroup->hide();
2028 QTableWidget* tbl = aCompDlg->myTable;
2029 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2030 aCompDlg->myBriefInfo->show();
2031 aCompDlg->myFullInfo->hide();
2033 if ( theNoHypoError ) {
2034 aCompDlg->myHypErrorGroup->hide();
2037 aCompDlg->myHypErrorGroup->show();
2038 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2041 if ( theNoCompError ) {
2042 aCompDlg->myCompErrorGroup->hide();
2045 aCompDlg->myCompErrorGroup->show();
2047 aCompDlg->myPublishBtn->hide();
2048 aCompDlg->myShowBtn->hide();
2050 // fill table of errors
2051 tbl->setRowCount( theCompErrors->length() );
2052 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2053 else tbl->showColumn( COL_SHAPE );
2054 tbl->setColumnWidth( COL_ERROR, 200 );
2056 bool hasBadMesh = false;
2057 for ( int row = 0; row < theCompErrors->length(); ++row )
2059 SMESH::ComputeError & err = theCompErrors[ row ];
2061 QString text = err.algoName.in();
2062 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2063 else tbl->item( row, COL_ALGO )->setText( text );
2065 text = SMESH::errorText( err.code, err.comment.in() );
2066 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2067 else tbl->item( row, COL_ERROR )->setText( text );
2069 text = QString("%1").arg( err.subShapeID );
2070 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2071 else tbl->item( row, COL_SHAPEID )->setText( text );
2073 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2074 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2075 else tbl->item( row, COL_SHAPE )->setText( text );
2077 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2078 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2079 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2081 text = err.hasBadMesh ? "hasBadMesh" : "";
2082 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2083 else tbl->item( row, COL_BAD_MESH )->setText( text );
2084 if ( err.hasBadMesh ) hasBadMesh = true;
2086 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2087 tbl->resizeRowToContents( row );
2089 tbl->resizeColumnToContents( COL_ALGO );
2090 tbl->resizeColumnToContents( COL_SHAPE );
2091 tbl->setWordWrap( true );
2094 aCompDlg->myBadMeshBtn->show();
2096 aCompDlg->myBadMeshBtn->hide();
2098 tbl->setCurrentCell(0,0);
2099 currentCellChanged(); // to update buttons
2102 // show dialog and wait, becase Compute can be invoked from Preview operation
2103 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2108 //================================================================================
2110 * \brief Gets dialog of evaluate operation
2111 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2113 //================================================================================
2115 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2119 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2120 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2121 // connect signals and slots
2122 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2123 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2124 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2125 QTableWidget* aTable = me->table();
2126 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2127 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));