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 case SMESH::COMPERR_ALGO_FAILED:
349 if ( strlen(comment) == 0 )
350 text = QObject::tr("COMPERR_ALGO_FAILED");
352 case SMESH::COMPERR_WARNING:
353 return comment ? QString(comment) : QObject::tr("COMPERR_UNKNOWN");
355 text = QString("#%1").arg( -errCode );
357 if ( text.length() > 0 ) text += ". ";
358 return text + comment;
360 // -----------------------------------------------------------------------
362 * \brief Return SO of a sub-shape
364 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
366 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
367 if ( subShapeID == 1 || !so )
369 _PTR(ChildIterator) it;
370 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
371 it = study->NewChildIterator(so);
374 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
375 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
376 if ( !geom->_is_nil() ) {
377 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
378 if ( list->length() == 1 && list[0] == subShapeID )
385 // -----------------------------------------------------------------------
387 * \brief Return sub-shape by ID
389 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
391 GEOM::GEOM_Object_var aSubShape;
392 if ( subShapeID == 1 )
393 aSubShape = aMainShape;
394 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
395 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
397 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
398 return aSubShape._retn();
400 // -----------------------------------------------------------------------
402 * \brief Return shape type name
404 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
405 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
408 if ( !aShape->_is_nil() ) {
409 switch ( aShape->GetShapeType() ) {
416 CASE2NAME( COMPSOLID );
417 CASE2NAME( COMPOUND );
423 // -----------------------------------------------------------------------
425 * \brief Return text describing a sub-shape
427 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
430 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
431 text = aSO->GetName().c_str();
433 text = QString("#%1").arg( subShapeID );
434 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
435 if ( typeName.length() )
436 text += QString(" (%1)").arg(typeName);
440 // -----------------------------------------------------------------------
442 * \brief Return a list of selected rows
444 int getSelectedRows(QTableWidget* table, QList<int>& rows)
447 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
448 QTableWidgetSelectionRange range;
449 foreach( range, selRanges )
451 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
454 if ( rows.isEmpty() && table->currentRow() > -1 )
455 rows.append( table->currentRow() );
463 // =========================================================================================
465 * \brief Dialog to compute a mesh and show computation errors
467 //=======================================================================
469 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
470 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
472 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
473 aDlgLay->setMargin( 0 );
474 aDlgLay->setSpacing( SPACING );
476 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
478 aDlgLay->addWidget(aMainFrame);
480 aDlgLay->setStretchFactor(aMainFrame, 1);
483 // =========================================================================================
487 //=======================================================================
489 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
493 //=======================================================================
494 // function : createMainFrame()
495 // purpose : Create frame containing dialog's fields
496 //=======================================================================
498 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
500 QFrame* aFrame = new QFrame(theParent);
502 SUIT_ResourceMgr* rm = resourceMgr();
503 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
509 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
512 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
514 QButtonGroup* aBtnGrp = new QButtonGroup(this);
515 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
516 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
518 QRadioButton* aRBut = new QRadioButton(aPixGrp);
519 aRBut->setIcon(iconCompute);
520 aRBut->setChecked(true);
521 aPixGrpLayout->addWidget(aRBut);
522 aBtnGrp->addButton(aRBut, 0);
526 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
527 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
528 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
529 myMeshName = new QLabel(nameBox);
530 nameBoxLayout->addWidget(myMeshName);
534 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
535 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
537 // Computation errors
539 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
540 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
541 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
542 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
543 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
544 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
546 //myTable->setReadOnly( true ); // VSR: check
547 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
548 myTable->hideColumn( COL_PUBLISHED );
549 myTable->hideColumn( COL_SHAPEID );
550 myTable->hideColumn( COL_BAD_MESH );
551 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
554 headers << tr( "COL_ALGO_HEADER" );
555 headers << tr( "COL_SHAPE_HEADER" );
556 headers << tr( "COL_ERROR_HEADER" );
557 headers << tr( "COL_SHAPEID_HEADER" );
558 headers << tr( "COL_PUBLISHED_HEADER" );
560 myTable->setHorizontalHeaderLabels( headers );
563 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
564 grpLayout->setSpacing(SPACING);
565 grpLayout->setMargin(MARGIN);
566 grpLayout->addWidget( myWarningLabel, 0, 0 );
567 grpLayout->addWidget( myTable, 1, 0, 4, 1 );
568 grpLayout->addWidget( myShowBtn, 1, 1 );
569 grpLayout->addWidget( myPublishBtn, 2, 1 );
570 grpLayout->addWidget( myBadMeshBtn, 3, 1 );
571 grpLayout->setRowStretch( 4, 1 );
573 // Hypothesis definition errors
575 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
576 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
577 myHypErrorGroupLayout->setMargin(MARGIN);
578 myHypErrorGroupLayout->setSpacing(SPACING);
579 myHypErrorLabel = new QLabel(myHypErrorGroup);
580 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
584 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
585 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
586 myMemoryLackGroupLayout->setMargin(MARGIN);
587 myMemoryLackGroupLayout->setSpacing(SPACING);
588 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
589 QFont bold = memLackLabel->font(); bold.setBold(true);
590 memLackLabel->setFont( bold );
591 memLackLabel->setMinimumWidth(300);
592 myMemoryLackGroupLayout->addWidget(memLackLabel);
594 // add all widgets to aFrame
595 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
596 aLay->setMargin( 0 );
597 aLay->setSpacing( 0 );
598 aLay->addWidget( aPixGrp );
599 aLay->addWidget( nameBox );
600 aLay->addWidget( myBriefInfo );
601 aLay->addWidget( myFullInfo );
602 aLay->addWidget( myHypErrorGroup );
603 aLay->addWidget( myCompErrorGroup );
604 aLay->addWidget( myMemoryLackGroup );
605 aLay->setStretchFactor( myCompErrorGroup, 1 );
607 ((QPushButton*) button( OK ))->setDefault( true );
612 //================================================================================
616 //================================================================================
618 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
619 : SMESHGUI_Operation(), myCompDlg( 0 )
621 myTShapeDisplayer = new SMESH::TShapeDisplayer();
622 myBadMeshDisplayer = 0;
624 //myHelpFileName = "/files/about_meshes.htm"; // V3
625 myHelpFileName = "about_meshes_page.html"; // V4
628 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
630 LightApp_SelectionMgr* Sel = selectionMgr();
631 SALOME_ListIO selected; Sel->selectedObjects( selected );
632 Handle(SALOME_InteractiveObject) anIO = selected.First();
633 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
634 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
637 //================================================================================
639 * \brief Start operation
640 * \purpose Init dialog fields, connect signals and slots, show dialog
642 //================================================================================
644 void SMESHGUI_BaseComputeOp::startOperation()
646 // create compute dialog if not created before
649 myMesh = SMESH::SMESH_Mesh::_nil();
650 myMainShape = GEOM::GEOM_Object::_nil();
653 LightApp_SelectionMgr *Sel = selectionMgr();
654 SALOME_ListIO selected; Sel->selectedObjects( selected );
656 int nbSel = selected.Extent();
658 SUIT_MessageBox::warning(desktop(),
659 tr("SMESH_WRN_WARNING"),
660 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
665 myIObject = selected.First();
666 myMesh = SMESH::GetMeshByIO(myIObject);
667 if (myMesh->_is_nil()) {
668 SUIT_MessageBox::warning(desktop(),
669 tr("SMESH_WRN_WARNING"),
670 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
674 myMainShape = myMesh->GetShapeToMesh();
676 SMESHGUI_Operation::startOperation();
679 //================================================================================
680 //================================================================================
682 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
683 SMESH::SMESH_Mesh_var mesh,
684 GEOM::GEOM_Object_var mainShape)
689 myMainShape = mainShape;
692 void SMESHGUI_ComputeDlg_QThread::run()
694 myResult = myGen->Compute(myMesh, myMainShape);
697 bool SMESHGUI_ComputeDlg_QThread::result()
702 void SMESHGUI_ComputeDlg_QThread::cancel()
704 myGen->CancelCompute(myMesh, myMainShape);
707 //================================================================================
708 //================================================================================
710 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *parent,
711 SMESH::SMESH_Gen_var gen,
712 SMESH::SMESH_Mesh_var mesh,
713 GEOM::GEOM_Object_var mainShape)
715 qthread(gen, mesh, mainShape)
718 setWindowTitle(tr("Compute"));
719 cancelButton = new QPushButton(tr("Cancel"));
720 cancelButton->setDefault(true);
721 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
722 QHBoxLayout *layout = new QHBoxLayout;
723 layout->addWidget(cancelButton);
727 startTimer(30); // 30 millisecs
731 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
733 return qthread.result();
736 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
741 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
743 if(qthread.isFinished())
750 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
752 if(qthread.isRunning())
760 //================================================================================
762 * \brief computeMesh()
764 //================================================================================
766 void SMESHGUI_BaseComputeOp::computeMesh()
770 SMESH::MemoryReserve aMemoryReserve;
772 SMESH::compute_error_array_var aCompErrors;
775 bool computeFailed = true, memoryLack = false;
777 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
778 if ( !aMeshSObj ) // IPAL 21340
780 bool hasShape = myMesh->HasShapeToMesh();
781 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
784 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
785 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
786 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
787 if ( errors->length() > 0 ) {
788 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
790 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
791 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
792 tr( "FULL_RECOMPUTE_QUESTION" ),
793 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
795 SUIT_OverrideCursor aWaitCursor;
797 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
800 //SMESH::UpdateNulData(myIObject, true);
802 #ifdef WITH_SMESH_CANCEL_COMPUTE
803 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
804 qthreaddialog.exec();
805 res = qthreaddialog.result();
807 res = gen->Compute(myMesh, myMainShape);
810 computeFailed = false;
812 catch(const SALOME::SALOME_Exception & S_ex){
816 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
819 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
820 // check if there are memory problems
821 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
822 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
824 catch(const SALOME::SALOME_Exception & S_ex){
828 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
832 // NPAL16631: if ( !memoryLack )
834 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
835 update( UF_ObjBrowser | UF_Model );
838 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
839 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
840 long newSize = myMesh->NbElements();
844 if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
847 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
850 SMESH::Update(myIObject, true);
854 MESSAGE ( "Exception thrown during mesh visualization" );
856 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
857 SMESH::OnVisuException();
864 else if ( limitExceeded )
866 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
867 SUIT_MessageBox::warning( desktop(),
868 tr( "SMESH_WRN_WARNING" ),
869 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
872 LightApp_SelectionMgr *Sel = selectionMgr();
875 SALOME_ListIO selected;
876 selected.Append( myIObject );
877 Sel->setSelectedObjects( selected );
883 aMemoryReserve.release();
885 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
889 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
890 bool noHypoError = ( aHypErrors.isEmpty() );
892 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
893 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
895 bool isShowResultDlg = true;
896 switch( aNotifyMode ) {
897 case 0: // show the mesh computation result dialog NEVER
898 isShowResultDlg = false;
901 case 1: // show the mesh computation result dialog if there are some errors
902 if ( memoryLack || !noCompError || !noHypoError )
903 isShowResultDlg = true;
906 isShowResultDlg = false;
910 default: // show the result dialog after each mesh computation
911 isShowResultDlg = true;
915 if ( isShowResultDlg )
916 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
919 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
920 const bool theNoCompError,
921 SMESH::compute_error_array_var& theCompErrors,
922 const bool theNoHypoError,
923 const QString& theHypErrors )
925 bool hasShape = myMesh->HasShapeToMesh();
926 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
927 aCompDlg->myMemoryLackGroup->hide();
931 aCompDlg->myMemoryLackGroup->show();
932 aCompDlg->myFullInfo->hide();
933 aCompDlg->myBriefInfo->hide();
934 aCompDlg->myHypErrorGroup->hide();
935 aCompDlg->myCompErrorGroup->hide();
937 else if ( theNoCompError && theNoHypoError )
939 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
940 aCompDlg->myFullInfo->SetMeshInfo( aRes );
941 aCompDlg->myFullInfo->show();
942 aCompDlg->myBriefInfo->hide();
943 aCompDlg->myHypErrorGroup->hide();
944 aCompDlg->myCompErrorGroup->hide();
948 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
949 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
950 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING );
952 // full or brief mesh info
953 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
954 if ( onlyWarnings ) {
955 aCompDlg->myFullInfo->SetMeshInfo( aRes );
956 aCompDlg->myFullInfo->show();
957 aCompDlg->myBriefInfo->hide();
959 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
960 aCompDlg->myBriefInfo->show();
961 aCompDlg->myFullInfo->hide();
964 // pbs of hypo dfinitions
965 if ( theNoHypoError ) {
966 aCompDlg->myHypErrorGroup->hide();
968 aCompDlg->myHypErrorGroup->show();
969 aCompDlg->myHypErrorLabel->setText( theHypErrors );
973 if ( theNoCompError )
975 aCompDlg->myCompErrorGroup->hide();
979 aCompDlg->myCompErrorGroup->show();
982 aCompDlg->myWarningLabel->show();
984 aCompDlg->myWarningLabel->hide();
987 aCompDlg->myPublishBtn->hide();
988 aCompDlg->myShowBtn->hide();
991 aCompDlg->myPublishBtn->show();
992 aCompDlg->myShowBtn->show();
995 // fill table of errors
996 QTableWidget* tbl = aCompDlg->myTable;
997 tbl->setRowCount( theCompErrors->length() );
998 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
999 else tbl->showColumn( COL_SHAPE );
1000 tbl->setColumnWidth( COL_ERROR, 200 );
1002 bool hasBadMesh = false;
1003 for ( int row = 0; row < theCompErrors->length(); ++row )
1005 SMESH::ComputeError & err = theCompErrors[ row ];
1007 QString text = err.algoName.in();
1008 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1009 else tbl->item( row, COL_ALGO )->setText( text );
1011 text = SMESH::errorText( err.code, err.comment.in() );
1012 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1013 else tbl->item( row, COL_ERROR )->setText( text );
1015 text = QString("%1").arg( err.subShapeID );
1016 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1017 else tbl->item( row, COL_SHAPEID )->setText( text );
1019 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1020 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1021 else tbl->item( row, COL_SHAPE )->setText( text );
1023 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1024 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1025 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1027 text = err.hasBadMesh ? "hasBadMesh" : "";
1028 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1029 else tbl->item( row, COL_BAD_MESH )->setText( text );
1030 if ( err.hasBadMesh ) hasBadMesh = true;
1032 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1033 tbl->resizeRowToContents( row );
1035 tbl->resizeColumnToContents( COL_ALGO );
1036 tbl->resizeColumnToContents( COL_SHAPE );
1039 aCompDlg->myBadMeshBtn->show();
1041 aCompDlg->myBadMeshBtn->hide();
1043 tbl->setCurrentCell(0,0);
1044 currentCellChanged(); // to update buttons
1047 // show dialog and wait, becase Compute can be invoked from Preview operation
1048 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1052 //================================================================================
1054 * \brief Stops operation
1056 //================================================================================
1058 void SMESHGUI_BaseComputeOp::stopOperation()
1060 SMESHGUI_Operation::stopOperation();
1061 if ( myTShapeDisplayer )
1062 myTShapeDisplayer->SetVisibility( false );
1063 if ( myBadMeshDisplayer ) {
1064 myBadMeshDisplayer->SetVisibility( false );
1065 // delete it in order not to have problems at its destruction when the viewer
1066 // where it worked is dead due to e.g. study closing
1067 delete myBadMeshDisplayer;
1068 myBadMeshDisplayer = 0;
1070 myIObject.Nullify();
1073 //================================================================================
1075 * \brief publish selected sub-shape
1077 //================================================================================
1079 void SMESHGUI_BaseComputeOp::onPublishShape()
1081 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1082 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1085 SMESH::getSelectedRows( table(), rows );
1087 foreach ( row, rows )
1089 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1090 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1091 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1093 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1095 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1096 SALOMEDS::SObject_var so =
1097 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1098 // look for myMainShape in the table
1099 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1100 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1101 if ( so->_is_nil() ) {
1102 table()->item( r, COL_SHAPE )->setText( so->GetName() );
1103 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1108 if ( curSub == 1 ) continue;
1110 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1111 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1112 if ( !so->_is_nil() ) {
1113 table()->item( row, COL_SHAPE )->setText( so->GetName() );
1114 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1118 getSMESHGUI()->getApp()->updateObjectBrowser();
1119 currentCellChanged(); // to update buttons
1122 //================================================================================
1124 * \brief show mesh elements preventing computation of a submesh of current row
1126 //================================================================================
1128 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1130 myTShapeDisplayer->SetVisibility( false );
1132 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1133 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1135 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1136 SMESHGUI* gui = getSMESHGUI();
1137 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1138 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1139 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1140 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1141 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1142 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1143 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1144 // delete property !!!!!!!!!!
1145 vtkProperty* prop = vtkProperty::New();
1146 prop->SetLineWidth( aLineWidth * 3 );
1147 prop->SetPointSize( aPointSize * 3 );
1148 prop->SetColor( 250, 0, 250 );
1149 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1150 myBadMeshDisplayer->SetData( aMeshData._retn() );
1155 //================================================================================
1157 * \brief SLOT called when a selected cell in table() changed
1159 //================================================================================
1161 void SMESHGUI_BaseComputeOp::currentCellChanged()
1163 myTShapeDisplayer->SetVisibility( false );
1164 if ( myBadMeshDisplayer )
1165 myBadMeshDisplayer->SetVisibility( false );
1167 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1169 int nbSelected = SMESH::getSelectedRows( table(), rows );
1171 foreach ( row, rows )
1173 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1174 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1175 if ( hasData && !isPublished )
1176 publishEnable = true;
1178 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1179 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1181 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1188 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1191 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1192 myCompDlg->myShowBtn ->setEnabled( showEnable );
1193 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1196 //================================================================================
1198 * \brief update preview
1200 //================================================================================
1202 void SMESHGUI_BaseComputeOp::onPreviewShape()
1204 if ( myTShapeDisplayer )
1206 SUIT_OverrideCursor aWaitCursor;
1208 SMESH::getSelectedRows( table(), rows );
1210 bool showOnly = true;
1212 foreach ( row, rows )
1214 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1216 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1220 currentCellChanged(); // to update buttons
1224 //================================================================================
1228 //================================================================================
1230 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1234 delete myTShapeDisplayer;
1235 if ( myBadMeshDisplayer )
1236 delete myBadMeshDisplayer;
1239 //================================================================================
1241 * \brief Gets dialog of compute operation
1242 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1244 //================================================================================
1246 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1250 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1251 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1252 // connect signals and slots
1253 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1254 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1255 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1257 QTableWidget* aTable = me->table();
1258 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1259 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1264 //================================================================================
1266 * \brief returns from compute mesh result dialog
1268 //================================================================================
1270 bool SMESHGUI_BaseComputeOp::onApply()
1275 //================================================================================
1277 * \brief Return a table
1279 //================================================================================
1281 QTableWidget* SMESHGUI_BaseComputeOp::table()
1283 return myCompDlg->myTable;
1287 //================================================================================
1289 * \brief Constructor
1291 //================================================================================
1293 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1294 : SMESHGUI_BaseComputeOp()
1299 //================================================================================
1301 * \brief Desctructor
1303 //================================================================================
1305 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1309 //================================================================================
1311 * \brief perform it's intention action: compute mesh
1313 //================================================================================
1315 void SMESHGUI_ComputeOp::startOperation()
1317 SMESHGUI_BaseComputeOp::startOperation();
1318 if (myMesh->_is_nil())
1323 //================================================================================
1325 * \brief check the same operations on the same mesh
1327 //================================================================================
1329 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1331 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1333 if ( !myMesh->_is_nil() && baseOp ) {
1334 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1335 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1340 //================================================================================
1342 * \brief Gets dialog of this operation
1343 * \retval LightApp_Dialog* - pointer to dialog of this operation
1345 //================================================================================
1347 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1349 return computeDlg();
1352 //================================================================================
1354 * \brief Constructor
1356 //================================================================================
1358 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1359 : SMESHGUI_BaseComputeOp(),
1363 myPreviewDisplayer( 0 )
1365 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1368 //================================================================================
1372 //================================================================================
1374 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1381 if ( myPreviewDisplayer )
1382 delete myPreviewDisplayer;
1383 myPreviewDisplayer = 0;
1386 //================================================================================
1388 * \brief Gets current dialog of this operation
1389 * \retval LightApp_Dialog* - pointer to dialog of this operation
1391 //================================================================================
1393 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1398 //================================================================================
1400 * \brief perform it's intention action: prepare data
1402 //================================================================================
1404 void SMESHGUI_PrecomputeOp::startOperation()
1408 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1411 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1412 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1413 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1415 myActiveDlg = myDlg;
1417 // connect signal to compute dialog. which will be shown after Compute mesh operation
1418 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1421 // disconnect signals
1422 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1423 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1424 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1425 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1426 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1429 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1430 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1431 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1432 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1433 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1434 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1435 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1436 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1437 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1438 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1441 SMESHGUI_BaseComputeOp::startOperation();
1442 if (myMesh->_is_nil())
1445 if (myDlg->getPreviewMode() == -1)
1447 // nothing to preview
1448 SUIT_MessageBox::warning(desktop(),
1449 tr("SMESH_WRN_WARNING"),
1450 tr("SMESH_WRN_NOTHING_PREVIEW"));
1455 // disconnect slot from preview dialog to have Apply from results of compute operation only
1456 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1457 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1462 //================================================================================
1464 * \brief Stops operation
1466 //================================================================================
1468 void SMESHGUI_PrecomputeOp::stopOperation()
1470 if ( myPreviewDisplayer )
1472 myPreviewDisplayer->SetVisibility( false );
1473 delete myPreviewDisplayer;
1474 myPreviewDisplayer = 0;
1476 myMapShapeId.clear();
1477 SMESHGUI_BaseComputeOp::stopOperation();
1480 //================================================================================
1482 * \brief reinitialize dialog after operaiton become active again
1484 //================================================================================
1486 void SMESHGUI_PrecomputeOp::resumeOperation()
1488 if ( myActiveDlg == myDlg )
1490 SMESHGUI_BaseComputeOp::resumeOperation();
1493 //================================================================================
1495 * \brief perform it's intention action: reinitialise dialog
1497 //================================================================================
1499 void SMESHGUI_PrecomputeOp::initDialog()
1503 QMap<int, int> modeMap;
1504 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1505 getAssignedAlgos( pMesh, modeMap );
1506 if ( modeMap.contains( SMESH::DIM_3D ) )
1508 if ( modeMap.contains( SMESH::DIM_2D ) )
1509 modes.append( SMESH::DIM_2D );
1510 if ( modeMap.contains( SMESH::DIM_1D ) )
1511 modes.append( SMESH::DIM_1D );
1513 else if ( modeMap.contains( SMESH::DIM_2D ) )
1515 if ( modeMap.contains( SMESH::DIM_1D ) )
1516 modes.append( SMESH::DIM_1D );
1519 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1520 myOrderMgr->SetMesh( myMesh );
1521 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1522 myDlg->getMeshOrderBox()->setShown(isOrder);
1528 myDlg->setPreviewModes( modes );
1531 //================================================================================
1533 * \brief detect asigned mesh algorithms
1535 //================================================================================
1537 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1538 QMap<int,int>& theModeMap)
1540 _PTR(SObject) aHypRoot;
1541 _PTR(GenericAttribute) anAttr;
1542 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1543 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1545 _PTR(ChildIterator) anIter =
1546 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1547 for ( ; anIter->More(); anIter->Next() )
1549 _PTR(SObject) anObj = anIter->Value();
1550 _PTR(SObject) aRefObj;
1551 if ( anObj->ReferencedObject( aRefObj ) )
1556 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1558 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1559 if ( CORBA::is_nil( aVar ) )
1562 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1564 SMESH::SMESH_Algo_var algo;
1566 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1567 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1568 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1571 if ( !algo->_is_nil() )
1572 theModeMap[ dim ] = 0;
1579 //================================================================================
1581 * \brief perform it's intention action: compute mesh
1583 //================================================================================
1585 void SMESHGUI_PrecomputeOp::onCompute()
1588 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1589 myOrderMgr->SetMeshOrder();
1590 myMapShapeId.clear();
1591 myActiveDlg = computeDlg();
1595 //================================================================================
1597 * \brief perform it's intention action: compute mesh
1599 //================================================================================
1601 void SMESHGUI_PrecomputeOp::onCancel()
1603 QObject* curDlg = sender();
1604 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1606 // return from error messages
1611 bool isRestoreOrder = false;
1612 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1614 // ask to remove already computed mesh elements
1615 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1616 tr( "CLEAR_SUBMESH_QUESTION" ),
1617 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1619 // remove all submeshes for collected shapes
1620 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1621 for ( ; it != myMapShapeId.constEnd(); ++it )
1622 myMesh->ClearSubMesh( *it );
1623 isRestoreOrder = true;
1627 // return previous mesh order
1628 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1629 if (!isRestoreOrder)
1631 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1632 tr( "SMESH_REJECT_MESH_ORDER" ),
1633 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1635 myOrderMgr->SetMeshOrder(myPrevOrder);
1641 myMapShapeId.clear();
1642 SMESHGUI_BaseComputeOp::onCancel();
1645 //================================================================================
1647 * \brief perform it's intention action: preview mesh
1649 //================================================================================
1651 void SMESHGUI_PrecomputeOp::onPreview()
1653 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1656 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1660 // set modified submesh priority if any
1661 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1662 myOrderMgr->SetMeshOrder();
1664 // Compute preview of mesh,
1665 // i.e. compute mesh till indicated dimension
1666 int dim = myDlg->getPreviewMode();
1668 SMESH::MemoryReserve aMemoryReserve;
1670 SMESH::compute_error_array_var aCompErrors;
1673 bool computeFailed = true, memoryLack = false;
1675 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1676 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1678 SMESHGUI* gui = getSMESHGUI();
1679 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1680 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1681 if ( errors->length() > 0 ) {
1682 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1685 SUIT_OverrideCursor aWaitCursor;
1687 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1688 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1689 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1691 SMESH::long_array_var aShapesId = new SMESH::long_array();
1693 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1697 SMESH::MeshPreviewStruct_var previewData =
1698 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1700 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1701 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1703 computeFailed = false;
1704 myPreviewDisplayer->SetData( previewRes );
1705 // append shape indeces with computed mesh entities
1706 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1707 myMapShapeId[ aShapesId[ i ] ] = 0;
1710 myPreviewDisplayer->SetVisibility(false);
1712 catch(const SALOME::SALOME_Exception & S_ex){
1714 myPreviewDisplayer->SetVisibility(false);
1718 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1721 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1722 // check if there are memory problems
1723 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1724 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1726 catch(const SALOME::SALOME_Exception & S_ex){
1731 aMemoryReserve.release();
1733 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1734 bool noHypoError = ( aHypErrors.isEmpty() );
1736 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1737 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1739 bool isShowError = true;
1740 switch( aNotifyMode ) {
1741 case 0: // show the mesh computation result dialog NEVER
1742 isShowError = false;
1744 case 1: // show the mesh computation result dialog if there are some errors
1745 default: // show the result dialog after each mesh computation
1746 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1747 isShowError = false;
1751 aWaitCursor.suspend();
1756 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1757 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1762 //================================================================================
1764 * \brief Constructor
1766 //================================================================================
1768 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1769 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1772 setWindowTitle( tr( "CAPTION" ) );
1774 setButtonText( OK, tr( "COMPUTE" ) );
1775 QFrame* main = mainFrame();
1777 QVBoxLayout* layout = new QVBoxLayout( main );
1779 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1780 layout->addWidget(myOrderBox);
1782 QFrame* frame = new QFrame( main );
1783 layout->setMargin(0); layout->setSpacing(0);
1784 layout->addWidget( frame );
1786 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1787 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1789 myPreviewMode = new QtxComboBox( frame );
1790 frameLay->addWidget( myPreviewMode );
1792 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1793 frameLay->addWidget( myPreviewBtn );
1795 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1798 //================================================================================
1802 //================================================================================
1804 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1808 //================================================================================
1810 * \brief Sets available preview modes
1812 //================================================================================
1814 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1816 myPreviewMode->clear();
1817 QList<int>::const_iterator it = theModes.constBegin();
1818 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1820 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1821 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1822 myPreviewMode->setId( i, *it );
1824 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1827 //================================================================================
1829 * \brief Returns current preview mesh mode
1831 //================================================================================
1833 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1835 return myPreviewMode->currentId();
1838 //================================================================================
1840 * \brief Returns current preview mesh mode
1842 //================================================================================
1844 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1850 //================================================================================
1852 * \brief Constructor
1854 //================================================================================
1856 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1857 : SMESHGUI_BaseComputeOp()
1862 //================================================================================
1864 * \brief Desctructor
1866 //================================================================================
1868 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1872 //================================================================================
1874 * \brief perform it's intention action: compute mesh
1876 //================================================================================
1878 void SMESHGUI_EvaluateOp::startOperation()
1880 SMESHGUI_BaseComputeOp::evaluateDlg();
1881 SMESHGUI_BaseComputeOp::startOperation();
1882 if (myMesh->_is_nil())
1887 //================================================================================
1889 * \brief Gets dialog of this operation
1890 * \retval LightApp_Dialog* - pointer to dialog of this operation
1892 //================================================================================
1894 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1896 return evaluateDlg();
1899 //================================================================================
1901 * \brief evaluateMesh()
1903 //================================================================================
1905 void SMESHGUI_BaseComputeOp::evaluateMesh()
1909 SMESH::MemoryReserve aMemoryReserve;
1911 SMESH::compute_error_array_var aCompErrors;
1914 bool evaluateFailed = true, memoryLack = false;
1915 SMESH::long_array_var aRes;
1917 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1918 if ( !aMeshSObj ) // IPAL21340
1921 bool hasShape = myMesh->HasShapeToMesh();
1922 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1925 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1926 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1927 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1928 if ( errors->length() > 0 ) {
1929 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1931 SUIT_OverrideCursor aWaitCursor;
1933 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1936 aRes = gen->Evaluate(myMesh, myMainShape);
1938 catch(const SALOME::SALOME_Exception & S_ex){
1943 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1946 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1948 catch(const SALOME::SALOME_Exception & S_ex){
1954 aMemoryReserve.release();
1956 evaluateFailed = ( aCompErrors->length() > 0 );
1957 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1961 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1962 bool noHypoError = ( aHypErrors.isEmpty() );
1964 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1965 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1967 bool isShowResultDlg = true;
1969 //switch( aNotifyMode ) {
1970 //case 0: // show the mesh computation result dialog NEVER
1971 //isShowResultDlg = false;
1974 //case 1: // show the mesh computation result dialog if there are some errors
1975 //if ( memoryLack || !noHypoError )
1976 // isShowResultDlg = true;
1979 // isShowResultDlg = false;
1983 //default: // show the result dialog after each mesh computation
1984 //isShowResultDlg = true;
1988 if ( isShowResultDlg )
1989 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1990 noHypoError, aHypErrors);
1994 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1995 const bool theMemoryLack,
1996 const bool theNoCompError,
1997 SMESH::compute_error_array_var& theCompErrors,
1998 const bool theNoHypoError,
1999 const QString& theHypErrors)
2001 bool hasShape = myMesh->HasShapeToMesh();
2002 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2003 aCompDlg->myMemoryLackGroup->hide();
2005 if ( theMemoryLack )
2007 aCompDlg->myMemoryLackGroup->show();
2008 aCompDlg->myFullInfo->hide();
2009 aCompDlg->myBriefInfo->hide();
2010 aCompDlg->myHypErrorGroup->hide();
2011 aCompDlg->myCompErrorGroup->hide();
2013 else if ( theNoCompError && theNoHypoError )
2015 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2016 aCompDlg->myFullInfo->show();
2017 aCompDlg->myBriefInfo->hide();
2018 aCompDlg->myHypErrorGroup->hide();
2019 aCompDlg->myCompErrorGroup->hide();
2023 QTableWidget* tbl = aCompDlg->myTable;
2024 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2025 aCompDlg->myBriefInfo->show();
2026 aCompDlg->myFullInfo->hide();
2028 if ( theNoHypoError ) {
2029 aCompDlg->myHypErrorGroup->hide();
2032 aCompDlg->myHypErrorGroup->show();
2033 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2036 if ( theNoCompError ) {
2037 aCompDlg->myCompErrorGroup->hide();
2040 aCompDlg->myCompErrorGroup->show();
2042 aCompDlg->myPublishBtn->hide();
2043 aCompDlg->myShowBtn->hide();
2045 // fill table of errors
2046 tbl->setRowCount( theCompErrors->length() );
2047 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2048 else tbl->showColumn( COL_SHAPE );
2049 tbl->setColumnWidth( COL_ERROR, 200 );
2051 bool hasBadMesh = false;
2052 for ( int row = 0; row < theCompErrors->length(); ++row )
2054 SMESH::ComputeError & err = theCompErrors[ row ];
2056 QString text = err.algoName.in();
2057 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2058 else tbl->item( row, COL_ALGO )->setText( text );
2060 text = SMESH::errorText( err.code, err.comment.in() );
2061 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2062 else tbl->item( row, COL_ERROR )->setText( text );
2064 text = QString("%1").arg( err.subShapeID );
2065 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2066 else tbl->item( row, COL_SHAPEID )->setText( text );
2068 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2069 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2070 else tbl->item( row, COL_SHAPE )->setText( text );
2072 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2073 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2074 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2076 text = err.hasBadMesh ? "hasBadMesh" : "";
2077 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2078 else tbl->item( row, COL_BAD_MESH )->setText( text );
2079 if ( err.hasBadMesh ) hasBadMesh = true;
2081 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2082 tbl->resizeRowToContents( row );
2084 tbl->resizeColumnToContents( COL_ALGO );
2085 tbl->resizeColumnToContents( COL_SHAPE );
2088 aCompDlg->myBadMeshBtn->show();
2090 aCompDlg->myBadMeshBtn->hide();
2092 tbl->setCurrentCell(0,0);
2093 currentCellChanged(); // to update buttons
2096 // show dialog and wait, becase Compute can be invoked from Preview operation
2097 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2102 //================================================================================
2104 * \brief Gets dialog of evaluate operation
2105 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2107 //================================================================================
2109 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2113 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2114 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2115 // connect signals and slots
2116 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2117 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2118 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2119 QTableWidget* aTable = me->table();
2120 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2121 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));