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 );
555 headers << tr( "COL_ALGO_HEADER" );
556 headers << tr( "COL_SHAPE_HEADER" );
557 headers << tr( "COL_ERROR_HEADER" );
558 headers << tr( "COL_SHAPEID_HEADER" );
559 headers << tr( "COL_PUBLISHED_HEADER" );
561 myTable->setHorizontalHeaderLabels( headers );
564 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
565 grpLayout->setSpacing(SPACING);
566 grpLayout->setMargin(MARGIN);
567 grpLayout->addWidget( myWarningLabel, 0, 0 );
568 grpLayout->addWidget( myTable, 1, 0, 4, 1 );
569 grpLayout->addWidget( myShowBtn, 1, 1 );
570 grpLayout->addWidget( myPublishBtn, 2, 1 );
571 grpLayout->addWidget( myBadMeshBtn, 3, 1 );
572 grpLayout->setRowStretch( 4, 1 );
574 // Hypothesis definition errors
576 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
577 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
578 myHypErrorGroupLayout->setMargin(MARGIN);
579 myHypErrorGroupLayout->setSpacing(SPACING);
580 myHypErrorLabel = new QLabel(myHypErrorGroup);
581 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
585 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
586 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
587 myMemoryLackGroupLayout->setMargin(MARGIN);
588 myMemoryLackGroupLayout->setSpacing(SPACING);
589 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
590 QFont bold = memLackLabel->font(); bold.setBold(true);
591 memLackLabel->setFont( bold );
592 memLackLabel->setMinimumWidth(300);
593 myMemoryLackGroupLayout->addWidget(memLackLabel);
595 // add all widgets to aFrame
596 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
597 aLay->setMargin( 0 );
598 aLay->setSpacing( 0 );
599 aLay->addWidget( aPixGrp );
600 aLay->addWidget( nameBox );
601 aLay->addWidget( myBriefInfo );
602 aLay->addWidget( myFullInfo );
603 aLay->addWidget( myHypErrorGroup );
604 aLay->addWidget( myCompErrorGroup );
605 aLay->addWidget( myMemoryLackGroup );
606 aLay->setStretchFactor( myCompErrorGroup, 1 );
608 ((QPushButton*) button( OK ))->setDefault( true );
613 //================================================================================
617 //================================================================================
619 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
620 : SMESHGUI_Operation(), myCompDlg( 0 )
622 myTShapeDisplayer = new SMESH::TShapeDisplayer();
623 myBadMeshDisplayer = 0;
625 //myHelpFileName = "/files/about_meshes.htm"; // V3
626 myHelpFileName = "about_meshes_page.html"; // V4
629 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
631 LightApp_SelectionMgr* Sel = selectionMgr();
632 SALOME_ListIO selected; Sel->selectedObjects( selected );
633 Handle(SALOME_InteractiveObject) anIO = selected.First();
634 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
635 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
638 //================================================================================
640 * \brief Start operation
641 * \purpose Init dialog fields, connect signals and slots, show dialog
643 //================================================================================
645 void SMESHGUI_BaseComputeOp::startOperation()
647 // create compute dialog if not created before
650 myMesh = SMESH::SMESH_Mesh::_nil();
651 myMainShape = GEOM::GEOM_Object::_nil();
654 LightApp_SelectionMgr *Sel = selectionMgr();
655 SALOME_ListIO selected; Sel->selectedObjects( selected );
657 int nbSel = selected.Extent();
659 SUIT_MessageBox::warning(desktop(),
660 tr("SMESH_WRN_WARNING"),
661 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
666 myIObject = selected.First();
667 myMesh = SMESH::GetMeshByIO(myIObject);
668 if (myMesh->_is_nil()) {
669 SUIT_MessageBox::warning(desktop(),
670 tr("SMESH_WRN_WARNING"),
671 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
675 myMainShape = myMesh->GetShapeToMesh();
677 SMESHGUI_Operation::startOperation();
680 //================================================================================
681 //================================================================================
683 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
684 SMESH::SMESH_Mesh_var mesh,
685 GEOM::GEOM_Object_var mainShape)
690 myMainShape = mainShape;
693 void SMESHGUI_ComputeDlg_QThread::run()
695 myResult = myGen->Compute(myMesh, myMainShape);
698 bool SMESHGUI_ComputeDlg_QThread::result()
703 void SMESHGUI_ComputeDlg_QThread::cancel()
705 myGen->CancelCompute(myMesh, myMainShape);
708 //================================================================================
709 //================================================================================
711 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *parent,
712 SMESH::SMESH_Gen_var gen,
713 SMESH::SMESH_Mesh_var mesh,
714 GEOM::GEOM_Object_var mainShape)
716 qthread(gen, mesh, mainShape)
719 setWindowTitle(tr("Compute"));
720 cancelButton = new QPushButton(tr("Cancel"));
721 cancelButton->setDefault(true);
722 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
723 QHBoxLayout *layout = new QHBoxLayout;
724 layout->addWidget(cancelButton);
728 startTimer(30); // 30 millisecs
732 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
734 return qthread.result();
737 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
742 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
744 if(qthread.isFinished())
751 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
753 if(qthread.isRunning())
761 //================================================================================
763 * \brief computeMesh()
765 //================================================================================
767 void SMESHGUI_BaseComputeOp::computeMesh()
771 SMESH::MemoryReserve aMemoryReserve;
773 SMESH::compute_error_array_var aCompErrors;
776 bool computeFailed = true, memoryLack = false;
778 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
779 if ( !aMeshSObj ) // IPAL 21340
781 bool hasShape = myMesh->HasShapeToMesh();
782 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
785 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
786 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
787 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
788 if ( errors->length() > 0 ) {
789 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
791 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
792 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
793 tr( "FULL_RECOMPUTE_QUESTION" ),
794 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
796 SUIT_OverrideCursor aWaitCursor;
798 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
801 //SMESH::UpdateNulData(myIObject, true);
803 #ifdef WITH_SMESH_CANCEL_COMPUTE
804 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
805 qthreaddialog.exec();
806 res = qthreaddialog.result();
808 res = gen->Compute(myMesh, myMainShape);
811 computeFailed = false;
813 catch(const SALOME::SALOME_Exception & S_ex){
817 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
820 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
821 // check if there are memory problems
822 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
823 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
825 catch(const SALOME::SALOME_Exception & S_ex){
829 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
833 // NPAL16631: if ( !memoryLack )
835 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
836 update( UF_ObjBrowser | UF_Model );
839 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
840 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
841 long newSize = myMesh->NbElements();
845 if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
848 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
851 SMESH::Update(myIObject, true);
855 MESSAGE ( "Exception thrown during mesh visualization" );
857 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
858 SMESH::OnVisuException();
865 else if ( limitExceeded )
867 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
868 SUIT_MessageBox::warning( desktop(),
869 tr( "SMESH_WRN_WARNING" ),
870 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
873 LightApp_SelectionMgr *Sel = selectionMgr();
876 SALOME_ListIO selected;
877 selected.Append( myIObject );
878 Sel->setSelectedObjects( selected );
884 aMemoryReserve.release();
886 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
890 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
891 bool noHypoError = ( aHypErrors.isEmpty() );
893 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
894 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
896 bool isShowResultDlg = true;
897 switch( aNotifyMode ) {
898 case 0: // show the mesh computation result dialog NEVER
899 isShowResultDlg = false;
902 case 1: // show the mesh computation result dialog if there are some errors
903 if ( memoryLack || !noCompError || !noHypoError )
904 isShowResultDlg = true;
907 isShowResultDlg = false;
911 default: // show the result dialog after each mesh computation
912 isShowResultDlg = true;
916 if ( isShowResultDlg )
917 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
920 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
921 const bool theNoCompError,
922 SMESH::compute_error_array_var& theCompErrors,
923 const bool theNoHypoError,
924 const QString& theHypErrors )
926 bool hasShape = myMesh->HasShapeToMesh();
927 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
928 aCompDlg->myMemoryLackGroup->hide();
932 aCompDlg->myMemoryLackGroup->show();
933 aCompDlg->myFullInfo->hide();
934 aCompDlg->myBriefInfo->hide();
935 aCompDlg->myHypErrorGroup->hide();
936 aCompDlg->myCompErrorGroup->hide();
938 else if ( theNoCompError && theNoHypoError )
940 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
941 aCompDlg->myFullInfo->SetMeshInfo( aRes );
942 aCompDlg->myFullInfo->show();
943 aCompDlg->myBriefInfo->hide();
944 aCompDlg->myHypErrorGroup->hide();
945 aCompDlg->myCompErrorGroup->hide();
949 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
950 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
951 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING );
953 // full or brief mesh info
954 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
955 if ( onlyWarnings ) {
956 aCompDlg->myFullInfo->SetMeshInfo( aRes );
957 aCompDlg->myFullInfo->show();
958 aCompDlg->myBriefInfo->hide();
960 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
961 aCompDlg->myBriefInfo->show();
962 aCompDlg->myFullInfo->hide();
965 // pbs of hypo dfinitions
966 if ( theNoHypoError ) {
967 aCompDlg->myHypErrorGroup->hide();
969 aCompDlg->myHypErrorGroup->show();
970 aCompDlg->myHypErrorLabel->setText( theHypErrors );
974 if ( theNoCompError )
976 aCompDlg->myCompErrorGroup->hide();
980 aCompDlg->myCompErrorGroup->show();
983 aCompDlg->myWarningLabel->show();
985 aCompDlg->myWarningLabel->hide();
988 aCompDlg->myPublishBtn->hide();
989 aCompDlg->myShowBtn->hide();
992 aCompDlg->myPublishBtn->show();
993 aCompDlg->myShowBtn->show();
996 // fill table of errors
997 QTableWidget* tbl = aCompDlg->myTable;
998 tbl->setRowCount( theCompErrors->length() );
999 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1000 else tbl->showColumn( COL_SHAPE );
1001 tbl->setColumnWidth( COL_ERROR, 200 );
1003 bool hasBadMesh = false;
1004 for ( int row = 0; row < theCompErrors->length(); ++row )
1006 SMESH::ComputeError & err = theCompErrors[ row ];
1008 QString text = err.algoName.in();
1009 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1010 else tbl->item( row, COL_ALGO )->setText( text );
1012 text = SMESH::errorText( err.code, err.comment.in() );
1013 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1014 else tbl->item( row, COL_ERROR )->setText( text );
1016 text = QString("%1").arg( err.subShapeID );
1017 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1018 else tbl->item( row, COL_SHAPEID )->setText( text );
1020 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1021 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1022 else tbl->item( row, COL_SHAPE )->setText( text );
1024 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1025 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1026 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1028 text = err.hasBadMesh ? "hasBadMesh" : "";
1029 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1030 else tbl->item( row, COL_BAD_MESH )->setText( text );
1031 if ( err.hasBadMesh ) hasBadMesh = true;
1033 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1034 tbl->resizeRowToContents( row );
1036 tbl->resizeColumnToContents( COL_ALGO );
1037 tbl->resizeColumnToContents( COL_SHAPE );
1040 aCompDlg->myBadMeshBtn->show();
1042 aCompDlg->myBadMeshBtn->hide();
1044 tbl->setCurrentCell(0,0);
1045 currentCellChanged(); // to update buttons
1048 // show dialog and wait, becase Compute can be invoked from Preview operation
1049 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1053 //================================================================================
1055 * \brief Stops operation
1057 //================================================================================
1059 void SMESHGUI_BaseComputeOp::stopOperation()
1061 SMESHGUI_Operation::stopOperation();
1062 if ( myTShapeDisplayer )
1063 myTShapeDisplayer->SetVisibility( false );
1064 if ( myBadMeshDisplayer ) {
1065 myBadMeshDisplayer->SetVisibility( false );
1066 // delete it in order not to have problems at its destruction when the viewer
1067 // where it worked is dead due to e.g. study closing
1068 delete myBadMeshDisplayer;
1069 myBadMeshDisplayer = 0;
1071 myIObject.Nullify();
1074 //================================================================================
1076 * \brief publish selected sub-shape
1078 //================================================================================
1080 void SMESHGUI_BaseComputeOp::onPublishShape()
1082 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1083 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1086 SMESH::getSelectedRows( table(), rows );
1088 foreach ( row, rows )
1090 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1091 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1092 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1094 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1096 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1097 SALOMEDS::SObject_var so =
1098 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1099 // look for myMainShape in the table
1100 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1101 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1102 if ( so->_is_nil() ) {
1103 table()->item( r, COL_SHAPE )->setText( so->GetName() );
1104 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1109 if ( curSub == 1 ) continue;
1111 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1112 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1113 if ( !so->_is_nil() ) {
1114 table()->item( row, COL_SHAPE )->setText( so->GetName() );
1115 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1119 getSMESHGUI()->getApp()->updateObjectBrowser();
1120 currentCellChanged(); // to update buttons
1123 //================================================================================
1125 * \brief show mesh elements preventing computation of a submesh of current row
1127 //================================================================================
1129 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1131 myTShapeDisplayer->SetVisibility( false );
1133 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1134 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1136 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1137 SMESHGUI* gui = getSMESHGUI();
1138 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1139 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1140 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1141 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1142 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1143 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1144 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1145 // delete property !!!!!!!!!!
1146 vtkProperty* prop = vtkProperty::New();
1147 prop->SetLineWidth( aLineWidth * 3 );
1148 prop->SetPointSize( aPointSize * 3 );
1149 prop->SetColor( 250, 0, 250 );
1150 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1151 myBadMeshDisplayer->SetData( aMeshData._retn() );
1156 //================================================================================
1158 * \brief SLOT called when a selected cell in table() changed
1160 //================================================================================
1162 void SMESHGUI_BaseComputeOp::currentCellChanged()
1164 myTShapeDisplayer->SetVisibility( false );
1165 if ( myBadMeshDisplayer )
1166 myBadMeshDisplayer->SetVisibility( false );
1168 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1170 int nbSelected = SMESH::getSelectedRows( table(), rows );
1172 foreach ( row, rows )
1174 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1175 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1176 if ( hasData && !isPublished )
1177 publishEnable = true;
1179 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1180 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1182 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1189 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1192 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1193 myCompDlg->myShowBtn ->setEnabled( showEnable );
1194 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1197 //================================================================================
1199 * \brief update preview
1201 //================================================================================
1203 void SMESHGUI_BaseComputeOp::onPreviewShape()
1205 if ( myTShapeDisplayer )
1207 SUIT_OverrideCursor aWaitCursor;
1209 SMESH::getSelectedRows( table(), rows );
1211 bool showOnly = true;
1213 foreach ( row, rows )
1215 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1217 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1221 currentCellChanged(); // to update buttons
1225 //================================================================================
1229 //================================================================================
1231 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1235 delete myTShapeDisplayer;
1236 if ( myBadMeshDisplayer )
1237 delete myBadMeshDisplayer;
1240 //================================================================================
1242 * \brief Gets dialog of compute operation
1243 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1245 //================================================================================
1247 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1251 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1252 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1253 // connect signals and slots
1254 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1255 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1256 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1258 QTableWidget* aTable = me->table();
1259 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1260 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1265 //================================================================================
1267 * \brief returns from compute mesh result dialog
1269 //================================================================================
1271 bool SMESHGUI_BaseComputeOp::onApply()
1276 //================================================================================
1278 * \brief Return a table
1280 //================================================================================
1282 QTableWidget* SMESHGUI_BaseComputeOp::table()
1284 return myCompDlg->myTable;
1288 //================================================================================
1290 * \brief Constructor
1292 //================================================================================
1294 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1295 : SMESHGUI_BaseComputeOp()
1300 //================================================================================
1302 * \brief Desctructor
1304 //================================================================================
1306 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1310 //================================================================================
1312 * \brief perform it's intention action: compute mesh
1314 //================================================================================
1316 void SMESHGUI_ComputeOp::startOperation()
1318 SMESHGUI_BaseComputeOp::startOperation();
1319 if (myMesh->_is_nil())
1324 //================================================================================
1326 * \brief check the same operations on the same mesh
1328 //================================================================================
1330 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1332 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1334 if ( !myMesh->_is_nil() && baseOp ) {
1335 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1336 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1341 //================================================================================
1343 * \brief Gets dialog of this operation
1344 * \retval LightApp_Dialog* - pointer to dialog of this operation
1346 //================================================================================
1348 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1350 return computeDlg();
1353 //================================================================================
1355 * \brief Constructor
1357 //================================================================================
1359 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1360 : SMESHGUI_BaseComputeOp(),
1364 myPreviewDisplayer( 0 )
1366 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1369 //================================================================================
1373 //================================================================================
1375 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1382 if ( myPreviewDisplayer )
1383 delete myPreviewDisplayer;
1384 myPreviewDisplayer = 0;
1387 //================================================================================
1389 * \brief Gets current dialog of this operation
1390 * \retval LightApp_Dialog* - pointer to dialog of this operation
1392 //================================================================================
1394 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1399 //================================================================================
1401 * \brief perform it's intention action: prepare data
1403 //================================================================================
1405 void SMESHGUI_PrecomputeOp::startOperation()
1409 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1412 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1413 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1414 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1416 myActiveDlg = myDlg;
1418 // connect signal to compute dialog. which will be shown after Compute mesh operation
1419 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1422 // disconnect signals
1423 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1424 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1425 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1426 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1427 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1430 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1431 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1432 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1433 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1434 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1435 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1436 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1437 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1438 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1439 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1442 SMESHGUI_BaseComputeOp::startOperation();
1443 if (myMesh->_is_nil())
1446 if (myDlg->getPreviewMode() == -1)
1448 // nothing to preview
1449 SUIT_MessageBox::warning(desktop(),
1450 tr("SMESH_WRN_WARNING"),
1451 tr("SMESH_WRN_NOTHING_PREVIEW"));
1456 // disconnect slot from preview dialog to have Apply from results of compute operation only
1457 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1458 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1463 //================================================================================
1465 * \brief Stops operation
1467 //================================================================================
1469 void SMESHGUI_PrecomputeOp::stopOperation()
1471 if ( myPreviewDisplayer )
1473 myPreviewDisplayer->SetVisibility( false );
1474 delete myPreviewDisplayer;
1475 myPreviewDisplayer = 0;
1477 myMapShapeId.clear();
1478 SMESHGUI_BaseComputeOp::stopOperation();
1481 //================================================================================
1483 * \brief reinitialize dialog after operaiton become active again
1485 //================================================================================
1487 void SMESHGUI_PrecomputeOp::resumeOperation()
1489 if ( myActiveDlg == myDlg )
1491 SMESHGUI_BaseComputeOp::resumeOperation();
1494 //================================================================================
1496 * \brief perform it's intention action: reinitialise dialog
1498 //================================================================================
1500 void SMESHGUI_PrecomputeOp::initDialog()
1504 QMap<int, int> modeMap;
1505 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1506 getAssignedAlgos( pMesh, modeMap );
1507 if ( modeMap.contains( SMESH::DIM_3D ) )
1509 if ( modeMap.contains( SMESH::DIM_2D ) )
1510 modes.append( SMESH::DIM_2D );
1511 if ( modeMap.contains( SMESH::DIM_1D ) )
1512 modes.append( SMESH::DIM_1D );
1514 else if ( modeMap.contains( SMESH::DIM_2D ) )
1516 if ( modeMap.contains( SMESH::DIM_1D ) )
1517 modes.append( SMESH::DIM_1D );
1520 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1521 myOrderMgr->SetMesh( myMesh );
1522 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1523 myDlg->getMeshOrderBox()->setShown(isOrder);
1529 myDlg->setPreviewModes( modes );
1532 //================================================================================
1534 * \brief detect asigned mesh algorithms
1536 //================================================================================
1538 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1539 QMap<int,int>& theModeMap)
1541 _PTR(SObject) aHypRoot;
1542 _PTR(GenericAttribute) anAttr;
1543 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1544 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1546 _PTR(ChildIterator) anIter =
1547 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1548 for ( ; anIter->More(); anIter->Next() )
1550 _PTR(SObject) anObj = anIter->Value();
1551 _PTR(SObject) aRefObj;
1552 if ( anObj->ReferencedObject( aRefObj ) )
1557 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1559 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1560 if ( CORBA::is_nil( aVar ) )
1563 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1565 SMESH::SMESH_Algo_var algo;
1567 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1568 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1569 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1572 if ( !algo->_is_nil() )
1573 theModeMap[ dim ] = 0;
1580 //================================================================================
1582 * \brief perform it's intention action: compute mesh
1584 //================================================================================
1586 void SMESHGUI_PrecomputeOp::onCompute()
1589 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1590 myOrderMgr->SetMeshOrder();
1591 myMapShapeId.clear();
1592 myActiveDlg = computeDlg();
1596 //================================================================================
1598 * \brief perform it's intention action: compute mesh
1600 //================================================================================
1602 void SMESHGUI_PrecomputeOp::onCancel()
1604 QObject* curDlg = sender();
1605 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1607 // return from error messages
1612 bool isRestoreOrder = false;
1613 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1615 // ask to remove already computed mesh elements
1616 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1617 tr( "CLEAR_SUBMESH_QUESTION" ),
1618 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1620 // remove all submeshes for collected shapes
1621 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1622 for ( ; it != myMapShapeId.constEnd(); ++it )
1623 myMesh->ClearSubMesh( *it );
1624 isRestoreOrder = true;
1628 // return previous mesh order
1629 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1630 if (!isRestoreOrder)
1632 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1633 tr( "SMESH_REJECT_MESH_ORDER" ),
1634 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1636 myOrderMgr->SetMeshOrder(myPrevOrder);
1642 myMapShapeId.clear();
1643 SMESHGUI_BaseComputeOp::onCancel();
1646 //================================================================================
1648 * \brief perform it's intention action: preview mesh
1650 //================================================================================
1652 void SMESHGUI_PrecomputeOp::onPreview()
1654 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1657 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1661 // set modified submesh priority if any
1662 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1663 myOrderMgr->SetMeshOrder();
1665 // Compute preview of mesh,
1666 // i.e. compute mesh till indicated dimension
1667 int dim = myDlg->getPreviewMode();
1669 SMESH::MemoryReserve aMemoryReserve;
1671 SMESH::compute_error_array_var aCompErrors;
1674 bool computeFailed = true, memoryLack = false;
1676 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1677 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1679 SMESHGUI* gui = getSMESHGUI();
1680 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1681 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1682 if ( errors->length() > 0 ) {
1683 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1686 SUIT_OverrideCursor aWaitCursor;
1688 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1689 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1690 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1692 SMESH::long_array_var aShapesId = new SMESH::long_array();
1694 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1698 SMESH::MeshPreviewStruct_var previewData =
1699 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1701 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1702 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1704 computeFailed = false;
1705 myPreviewDisplayer->SetData( previewRes );
1706 // append shape indeces with computed mesh entities
1707 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1708 myMapShapeId[ aShapesId[ i ] ] = 0;
1711 myPreviewDisplayer->SetVisibility(false);
1713 catch(const SALOME::SALOME_Exception & S_ex){
1715 myPreviewDisplayer->SetVisibility(false);
1719 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1722 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1723 // check if there are memory problems
1724 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1725 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1727 catch(const SALOME::SALOME_Exception & S_ex){
1732 aMemoryReserve.release();
1734 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1735 bool noHypoError = ( aHypErrors.isEmpty() );
1737 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1738 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1740 bool isShowError = true;
1741 switch( aNotifyMode ) {
1742 case 0: // show the mesh computation result dialog NEVER
1743 isShowError = false;
1745 case 1: // show the mesh computation result dialog if there are some errors
1746 default: // show the result dialog after each mesh computation
1747 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1748 isShowError = false;
1752 aWaitCursor.suspend();
1757 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1758 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1763 //================================================================================
1765 * \brief Constructor
1767 //================================================================================
1769 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1770 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1773 setWindowTitle( tr( "CAPTION" ) );
1775 setButtonText( OK, tr( "COMPUTE" ) );
1776 QFrame* main = mainFrame();
1778 QVBoxLayout* layout = new QVBoxLayout( main );
1780 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1781 layout->addWidget(myOrderBox);
1783 QFrame* frame = new QFrame( main );
1784 layout->setMargin(0); layout->setSpacing(0);
1785 layout->addWidget( frame );
1787 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1788 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1790 myPreviewMode = new QtxComboBox( frame );
1791 frameLay->addWidget( myPreviewMode );
1793 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1794 frameLay->addWidget( myPreviewBtn );
1796 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1799 //================================================================================
1803 //================================================================================
1805 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1809 //================================================================================
1811 * \brief Sets available preview modes
1813 //================================================================================
1815 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1817 myPreviewMode->clear();
1818 QList<int>::const_iterator it = theModes.constBegin();
1819 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1821 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1822 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1823 myPreviewMode->setId( i, *it );
1825 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1828 //================================================================================
1830 * \brief Returns current preview mesh mode
1832 //================================================================================
1834 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1836 return myPreviewMode->currentId();
1839 //================================================================================
1841 * \brief Returns current preview mesh mode
1843 //================================================================================
1845 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1851 //================================================================================
1853 * \brief Constructor
1855 //================================================================================
1857 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1858 : SMESHGUI_BaseComputeOp()
1863 //================================================================================
1865 * \brief Desctructor
1867 //================================================================================
1869 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1873 //================================================================================
1875 * \brief perform it's intention action: compute mesh
1877 //================================================================================
1879 void SMESHGUI_EvaluateOp::startOperation()
1881 SMESHGUI_BaseComputeOp::evaluateDlg();
1882 SMESHGUI_BaseComputeOp::startOperation();
1883 if (myMesh->_is_nil())
1888 //================================================================================
1890 * \brief Gets dialog of this operation
1891 * \retval LightApp_Dialog* - pointer to dialog of this operation
1893 //================================================================================
1895 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1897 return evaluateDlg();
1900 //================================================================================
1902 * \brief evaluateMesh()
1904 //================================================================================
1906 void SMESHGUI_BaseComputeOp::evaluateMesh()
1910 SMESH::MemoryReserve aMemoryReserve;
1912 SMESH::compute_error_array_var aCompErrors;
1915 bool evaluateFailed = true, memoryLack = false;
1916 SMESH::long_array_var aRes;
1918 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1919 if ( !aMeshSObj ) // IPAL21340
1922 bool hasShape = myMesh->HasShapeToMesh();
1923 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1926 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1927 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1928 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1929 if ( errors->length() > 0 ) {
1930 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1932 SUIT_OverrideCursor aWaitCursor;
1934 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1937 aRes = gen->Evaluate(myMesh, myMainShape);
1939 catch(const SALOME::SALOME_Exception & S_ex){
1944 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1947 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1949 catch(const SALOME::SALOME_Exception & S_ex){
1955 aMemoryReserve.release();
1957 evaluateFailed = ( aCompErrors->length() > 0 );
1958 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1962 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1963 bool noHypoError = ( aHypErrors.isEmpty() );
1965 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1966 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1968 bool isShowResultDlg = true;
1970 //switch( aNotifyMode ) {
1971 //case 0: // show the mesh computation result dialog NEVER
1972 //isShowResultDlg = false;
1975 //case 1: // show the mesh computation result dialog if there are some errors
1976 //if ( memoryLack || !noHypoError )
1977 // isShowResultDlg = true;
1980 // isShowResultDlg = false;
1984 //default: // show the result dialog after each mesh computation
1985 //isShowResultDlg = true;
1989 if ( isShowResultDlg )
1990 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1991 noHypoError, aHypErrors);
1995 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1996 const bool theMemoryLack,
1997 const bool theNoCompError,
1998 SMESH::compute_error_array_var& theCompErrors,
1999 const bool theNoHypoError,
2000 const QString& theHypErrors)
2002 bool hasShape = myMesh->HasShapeToMesh();
2003 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2004 aCompDlg->myMemoryLackGroup->hide();
2006 if ( theMemoryLack )
2008 aCompDlg->myMemoryLackGroup->show();
2009 aCompDlg->myFullInfo->hide();
2010 aCompDlg->myBriefInfo->hide();
2011 aCompDlg->myHypErrorGroup->hide();
2012 aCompDlg->myCompErrorGroup->hide();
2014 else if ( theNoCompError && theNoHypoError )
2016 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2017 aCompDlg->myFullInfo->show();
2018 aCompDlg->myBriefInfo->hide();
2019 aCompDlg->myHypErrorGroup->hide();
2020 aCompDlg->myCompErrorGroup->hide();
2024 QTableWidget* tbl = aCompDlg->myTable;
2025 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2026 aCompDlg->myBriefInfo->show();
2027 aCompDlg->myFullInfo->hide();
2029 if ( theNoHypoError ) {
2030 aCompDlg->myHypErrorGroup->hide();
2033 aCompDlg->myHypErrorGroup->show();
2034 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2037 if ( theNoCompError ) {
2038 aCompDlg->myCompErrorGroup->hide();
2041 aCompDlg->myCompErrorGroup->show();
2043 aCompDlg->myPublishBtn->hide();
2044 aCompDlg->myShowBtn->hide();
2046 // fill table of errors
2047 tbl->setRowCount( theCompErrors->length() );
2048 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2049 else tbl->showColumn( COL_SHAPE );
2050 tbl->setColumnWidth( COL_ERROR, 200 );
2052 bool hasBadMesh = false;
2053 for ( int row = 0; row < theCompErrors->length(); ++row )
2055 SMESH::ComputeError & err = theCompErrors[ row ];
2057 QString text = err.algoName.in();
2058 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2059 else tbl->item( row, COL_ALGO )->setText( text );
2061 text = SMESH::errorText( err.code, err.comment.in() );
2062 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2063 else tbl->item( row, COL_ERROR )->setText( text );
2065 text = QString("%1").arg( err.subShapeID );
2066 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2067 else tbl->item( row, COL_SHAPEID )->setText( text );
2069 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2070 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2071 else tbl->item( row, COL_SHAPE )->setText( text );
2073 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2074 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2075 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2077 text = err.hasBadMesh ? "hasBadMesh" : "";
2078 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2079 else tbl->item( row, COL_BAD_MESH )->setText( text );
2080 if ( err.hasBadMesh ) hasBadMesh = true;
2082 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2083 tbl->resizeRowToContents( row );
2085 tbl->resizeColumnToContents( COL_ALGO );
2086 tbl->resizeColumnToContents( COL_SHAPE );
2089 aCompDlg->myBadMeshBtn->show();
2091 aCompDlg->myBadMeshBtn->hide();
2093 tbl->setCurrentCell(0,0);
2094 currentCellChanged(); // to update buttons
2097 // show dialog and wait, becase Compute can be invoked from Preview operation
2098 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2103 //================================================================================
2105 * \brief Gets dialog of evaluate operation
2106 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2108 //================================================================================
2110 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2114 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2115 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2116 // connect signals and slots
2117 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2118 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2119 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2120 QTableWidget* aTable = me->table();
2121 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2122 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));