1 // Copyright (C) 2007-2010 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");
353 text = QString("#%1").arg( -errCode );
355 if ( text.length() > 0 ) text += ". ";
356 return text + comment;
358 // -----------------------------------------------------------------------
360 * \brief Return SO of a subshape
362 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
364 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
365 if ( subShapeID == 1 || !so )
367 _PTR(ChildIterator) it;
368 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
369 it = study->NewChildIterator(so);
372 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
373 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
374 if ( !geom->_is_nil() ) {
375 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
376 if ( list->length() == 1 && list[0] == subShapeID )
383 // -----------------------------------------------------------------------
385 * \brief Return subshape by ID
387 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
389 GEOM::GEOM_Object_var aSubShape;
390 if ( subShapeID == 1 )
391 aSubShape = aMainShape;
392 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
393 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
395 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
396 return aSubShape._retn();
398 // -----------------------------------------------------------------------
400 * \brief Return shape type name
402 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
403 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
406 if ( !aShape->_is_nil() ) {
407 switch ( aShape->GetShapeType() ) {
414 CASE2NAME( COMPSOLID );
415 CASE2NAME( COMPOUND );
421 // -----------------------------------------------------------------------
423 * \brief Return text describing a subshape
425 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
428 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
429 text = aSO->GetName().c_str();
431 text = QString("#%1").arg( subShapeID );
432 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
433 if ( typeName.length() )
434 text += QString(" (%1)").arg(typeName);
438 // -----------------------------------------------------------------------
440 * \brief Return a list of selected rows
442 int getSelectedRows(QTableWidget* table, QList<int>& rows)
445 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
446 QTableWidgetSelectionRange range;
447 foreach( range, selRanges )
449 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
452 if ( rows.isEmpty() && table->currentRow() > -1 )
453 rows.append( table->currentRow() );
461 // =========================================================================================
463 * \brief Dialog to compute a mesh and show computation errors
465 //=======================================================================
467 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
468 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
470 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
471 aDlgLay->setMargin( 0 );
472 aDlgLay->setSpacing( SPACING );
474 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
476 aDlgLay->addWidget(aMainFrame);
478 aDlgLay->setStretchFactor(aMainFrame, 1);
481 // =========================================================================================
485 //=======================================================================
487 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
491 //=======================================================================
492 // function : createMainFrame()
493 // purpose : Create frame containing dialog's fields
494 //=======================================================================
496 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
498 QFrame* aFrame = new QFrame(theParent);
500 SUIT_ResourceMgr* rm = resourceMgr();
501 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
507 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
510 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
512 QButtonGroup* aBtnGrp = new QButtonGroup(this);
513 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
514 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
516 QRadioButton* aRBut = new QRadioButton(aPixGrp);
517 aRBut->setIcon(iconCompute);
518 aRBut->setChecked(true);
519 aPixGrpLayout->addWidget(aRBut);
520 aBtnGrp->addButton(aRBut, 0);
524 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
525 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
526 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
527 myMeshName = new QLabel(nameBox);
528 nameBoxLayout->addWidget(myMeshName);
532 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
533 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
535 // Computation errors
537 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
538 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
539 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
540 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
541 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
543 //myTable->setReadOnly( true ); // VSR: check
544 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
545 myTable->hideColumn( COL_PUBLISHED );
546 myTable->hideColumn( COL_SHAPEID );
547 myTable->hideColumn( COL_BAD_MESH );
548 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
551 headers << tr( "COL_ALGO_HEADER" );
552 headers << tr( "COL_SHAPE_HEADER" );
553 headers << tr( "COL_ERROR_HEADER" );
554 headers << tr( "COL_SHAPEID_HEADER" );
555 headers << tr( "COL_PUBLISHED_HEADER" );
557 myTable->setHorizontalHeaderLabels( headers );
560 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
561 grpLayout->setSpacing(SPACING);
562 grpLayout->setMargin(MARGIN);
563 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
564 grpLayout->addWidget( myShowBtn, 0, 1 );
565 grpLayout->addWidget( myPublishBtn, 1, 1 );
566 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
567 grpLayout->setRowStretch( 3, 1 );
569 // Hypothesis definition errors
571 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
572 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
573 myHypErrorGroupLayout->setMargin(MARGIN);
574 myHypErrorGroupLayout->setSpacing(SPACING);
575 myHypErrorLabel = new QLabel(myHypErrorGroup);
576 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
580 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
581 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
582 myMemoryLackGroupLayout->setMargin(MARGIN);
583 myMemoryLackGroupLayout->setSpacing(SPACING);
584 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
585 QFont bold = memLackLabel->font(); bold.setBold(true);
586 memLackLabel->setFont( bold );
587 memLackLabel->setMinimumWidth(300);
588 myMemoryLackGroupLayout->addWidget(memLackLabel);
590 // add all widgets to aFrame
591 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
592 aLay->setMargin( 0 );
593 aLay->setSpacing( 0 );
594 aLay->addWidget( aPixGrp );
595 aLay->addWidget( nameBox );
596 aLay->addWidget( myBriefInfo );
597 aLay->addWidget( myFullInfo );
598 aLay->addWidget( myHypErrorGroup );
599 aLay->addWidget( myCompErrorGroup );
600 aLay->addWidget( myMemoryLackGroup );
601 aLay->setStretchFactor( myCompErrorGroup, 1 );
603 ((QPushButton*) button( OK ))->setDefault( true );
608 //================================================================================
612 //================================================================================
614 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
615 : SMESHGUI_Operation(), myCompDlg( 0 )
617 myTShapeDisplayer = new SMESH::TShapeDisplayer();
618 myBadMeshDisplayer = 0;
620 //myHelpFileName = "/files/about_meshes.htm"; // V3
621 myHelpFileName = "about_meshes_page.html"; // V4
624 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
626 LightApp_SelectionMgr* Sel = selectionMgr();
627 SALOME_ListIO selected; Sel->selectedObjects( selected );
628 Handle(SALOME_InteractiveObject) anIO = selected.First();
629 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
630 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
633 //================================================================================
635 * \brief Start operation
636 * \purpose Init dialog fields, connect signals and slots, show dialog
638 //================================================================================
640 void SMESHGUI_BaseComputeOp::startOperation()
642 // create compute dialog if not created before
645 myMesh = SMESH::SMESH_Mesh::_nil();
646 myMainShape = GEOM::GEOM_Object::_nil();
649 LightApp_SelectionMgr *Sel = selectionMgr();
650 SALOME_ListIO selected; Sel->selectedObjects( selected );
652 int nbSel = selected.Extent();
654 SUIT_MessageBox::warning(desktop(),
655 tr("SMESH_WRN_WARNING"),
656 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
661 myIObject = selected.First();
662 myMesh = SMESH::GetMeshByIO(myIObject);
663 if (myMesh->_is_nil()) {
664 SUIT_MessageBox::warning(desktop(),
665 tr("SMESH_WRN_WARNING"),
666 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
670 myMainShape = myMesh->GetShapeToMesh();
672 SMESHGUI_Operation::startOperation();
675 //================================================================================
676 //================================================================================
678 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
679 SMESH::SMESH_Mesh_var mesh,
680 GEOM::GEOM_Object_var mainShape)
685 myMainShape = mainShape;
688 void SMESHGUI_ComputeDlg_QThread::run()
690 myResult = myGen->Compute(myMesh, myMainShape);
693 bool SMESHGUI_ComputeDlg_QThread::result()
698 void SMESHGUI_ComputeDlg_QThread::cancel()
700 myGen->CancelCompute(myMesh, myMainShape);
703 //================================================================================
704 //================================================================================
706 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget *parent,
707 SMESH::SMESH_Gen_var gen,
708 SMESH::SMESH_Mesh_var mesh,
709 GEOM::GEOM_Object_var mainShape)
711 qthread(gen, mesh, mainShape)
714 setWindowTitle(tr("Compute"));
715 cancelButton = new QPushButton(tr("Cancel"));
716 cancelButton->setDefault(true);
717 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
718 QHBoxLayout *layout = new QHBoxLayout;
719 layout->addWidget(cancelButton);
723 startTimer(30); // 30 millisecs
727 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
729 return qthread.result();
732 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
737 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
739 if(qthread.isFinished())
746 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
748 if(qthread.isRunning())
756 //================================================================================
758 * \brief computeMesh()
760 //================================================================================
762 void SMESHGUI_BaseComputeOp::computeMesh()
766 SMESH::MemoryReserve aMemoryReserve;
768 SMESH::compute_error_array_var aCompErrors;
771 bool computeFailed = true, memoryLack = false;
773 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
774 if ( !aMeshSObj ) // IPAL 21340
776 bool hasShape = myMesh->HasShapeToMesh();
777 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
780 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
781 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
782 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
783 if ( errors->length() > 0 ) {
784 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
786 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
787 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
788 tr( "FULL_RECOMPUTE_QUESTION" ),
789 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
791 SUIT_OverrideCursor aWaitCursor;
793 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
796 //SMESH::UpdateNulData(myIObject, true);
798 #ifdef WITH_SMESH_CANCEL_COMPUTE
799 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
800 qthreaddialog.exec();
801 res = qthreaddialog.result();
803 res = gen->Compute(myMesh, myMainShape);
806 computeFailed = false;
808 catch(const SALOME::SALOME_Exception & S_ex){
812 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
815 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
816 // check if there are memory problems
817 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
818 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
820 catch(const SALOME::SALOME_Exception & S_ex){
824 // NPAL16631: if ( !memoryLack )
826 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
827 update( UF_ObjBrowser | UF_Model );
830 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
831 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
832 long newSize = myMesh->NbElements();
833 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
837 if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
840 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
843 SMESH::Update(myIObject, true);
847 MESSAGE ( "Exception thrown during mesh visualization" );
849 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
850 SMESH::OnVisuException();
857 else if ( limitExceeded )
859 SUIT_MessageBox::warning( desktop(),
860 tr( "SMESH_WRN_WARNING" ),
861 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
864 LightApp_SelectionMgr *Sel = selectionMgr();
867 SALOME_ListIO selected;
868 selected.Append( myIObject );
869 Sel->setSelectedObjects( selected );
875 aMemoryReserve.release();
877 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
881 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
882 bool noHypoError = ( aHypErrors.isEmpty() );
884 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
885 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
887 bool isShowResultDlg = true;
888 switch( aNotifyMode ) {
889 case 0: // show the mesh computation result dialog NEVER
890 isShowResultDlg = false;
893 case 1: // show the mesh computation result dialog if there are some errors
894 if ( memoryLack || !noCompError || !noHypoError )
895 isShowResultDlg = true;
898 isShowResultDlg = false;
902 default: // show the result dialog after each mesh computation
903 isShowResultDlg = true;
907 if ( isShowResultDlg )
908 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
911 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
912 const bool theNoCompError,
913 SMESH::compute_error_array_var& theCompErrors,
914 const bool theNoHypoError,
915 const QString& theHypErrors )
917 bool hasShape = myMesh->HasShapeToMesh();
918 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
919 aCompDlg->myMemoryLackGroup->hide();
923 aCompDlg->myMemoryLackGroup->show();
924 aCompDlg->myFullInfo->hide();
925 aCompDlg->myBriefInfo->hide();
926 aCompDlg->myHypErrorGroup->hide();
927 aCompDlg->myCompErrorGroup->hide();
929 else if ( theNoCompError && theNoHypoError )
931 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
932 aCompDlg->myFullInfo->SetMeshInfo( aRes );
933 aCompDlg->myFullInfo->show();
934 aCompDlg->myBriefInfo->hide();
935 aCompDlg->myHypErrorGroup->hide();
936 aCompDlg->myCompErrorGroup->hide();
940 QTableWidget* tbl = aCompDlg->myTable;
941 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
942 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
943 aCompDlg->myBriefInfo->show();
944 aCompDlg->myFullInfo->hide();
946 if ( theNoHypoError ) {
947 aCompDlg->myHypErrorGroup->hide();
950 aCompDlg->myHypErrorGroup->show();
951 aCompDlg->myHypErrorLabel->setText( theHypErrors );
954 if ( theNoCompError ) {
955 aCompDlg->myCompErrorGroup->hide();
958 aCompDlg->myCompErrorGroup->show();
961 aCompDlg->myPublishBtn->hide();
962 aCompDlg->myShowBtn->hide();
965 aCompDlg->myPublishBtn->show();
966 aCompDlg->myShowBtn->show();
969 // fill table of errors
970 tbl->setRowCount( theCompErrors->length() );
971 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
972 else tbl->showColumn( COL_SHAPE );
973 tbl->setColumnWidth( COL_ERROR, 200 );
975 bool hasBadMesh = false;
976 for ( int row = 0; row < theCompErrors->length(); ++row )
978 SMESH::ComputeError & err = theCompErrors[ row ];
980 QString text = err.algoName.in();
981 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
982 else tbl->item( row, COL_ALGO )->setText( text );
984 text = SMESH::errorText( err.code, err.comment.in() );
985 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
986 else tbl->item( row, COL_ERROR )->setText( text );
988 text = QString("%1").arg( err.subShapeID );
989 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
990 else tbl->item( row, COL_SHAPEID )->setText( text );
992 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
993 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
994 else tbl->item( row, COL_SHAPE )->setText( text );
996 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
997 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
998 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1000 text = err.hasBadMesh ? "hasBadMesh" : "";
1001 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1002 else tbl->item( row, COL_BAD_MESH )->setText( text );
1003 if ( err.hasBadMesh ) hasBadMesh = true;
1005 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1006 tbl->resizeRowToContents( row );
1008 tbl->resizeColumnToContents( COL_ALGO );
1009 tbl->resizeColumnToContents( COL_SHAPE );
1012 aCompDlg->myBadMeshBtn->show();
1014 aCompDlg->myBadMeshBtn->hide();
1016 tbl->setCurrentCell(0,0);
1017 currentCellChanged(); // to update buttons
1020 // show dialog and wait, becase Compute can be invoked from Preview operation
1021 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1025 //================================================================================
1027 * \brief Stops operation
1029 //================================================================================
1031 void SMESHGUI_BaseComputeOp::stopOperation()
1033 SMESHGUI_Operation::stopOperation();
1034 if ( myTShapeDisplayer )
1035 myTShapeDisplayer->SetVisibility( false );
1036 if ( myBadMeshDisplayer ) {
1037 myBadMeshDisplayer->SetVisibility( false );
1038 // delete it in order not to have problems at its destruction when the viewer
1039 // where it worked is dead due to e.g. study closing
1040 delete myBadMeshDisplayer;
1041 myBadMeshDisplayer = 0;
1043 myIObject.Nullify();
1046 //================================================================================
1048 * \brief publish selected subshape
1050 //================================================================================
1052 void SMESHGUI_BaseComputeOp::onPublishShape()
1054 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1055 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1058 SMESH::getSelectedRows( table(), rows );
1060 foreach ( row, rows )
1062 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1063 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1064 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1066 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1068 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1069 SALOMEDS::SObject_var so =
1070 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1071 // look for myMainShape in the table
1072 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1073 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1074 if ( so->_is_nil() ) {
1075 table()->item( r, COL_SHAPE )->setText( so->GetName() );
1076 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1081 if ( curSub == 1 ) continue;
1083 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1084 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1085 if ( !so->_is_nil() ) {
1086 table()->item( row, COL_SHAPE )->setText( so->GetName() );
1087 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1091 getSMESHGUI()->getApp()->updateObjectBrowser();
1092 currentCellChanged(); // to update buttons
1095 //================================================================================
1097 * \brief show mesh elements preventing computation of a submesh of current row
1099 //================================================================================
1101 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1103 myTShapeDisplayer->SetVisibility( false );
1105 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1106 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1108 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1109 SMESHGUI* gui = getSMESHGUI();
1110 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1111 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1112 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1113 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1114 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1115 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1116 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1117 // delete property !!!!!!!!!!
1118 vtkProperty* prop = vtkProperty::New();
1119 prop->SetLineWidth( aLineWidth * 3 );
1120 prop->SetPointSize( aPointSize * 3 );
1121 prop->SetColor( 250, 0, 250 );
1122 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1123 myBadMeshDisplayer->SetData( aMeshData._retn() );
1128 //================================================================================
1130 * \brief SLOT called when a selected cell in table() changed
1132 //================================================================================
1134 void SMESHGUI_BaseComputeOp::currentCellChanged()
1136 myTShapeDisplayer->SetVisibility( false );
1137 if ( myBadMeshDisplayer )
1138 myBadMeshDisplayer->SetVisibility( false );
1140 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1142 int nbSelected = SMESH::getSelectedRows( table(), rows );
1144 foreach ( row, rows )
1146 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1147 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1148 if ( hasData && !isPublished )
1149 publishEnable = true;
1151 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1152 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1154 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1161 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1164 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1165 myCompDlg->myShowBtn ->setEnabled( showEnable );
1166 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1169 //================================================================================
1171 * \brief update preview
1173 //================================================================================
1175 void SMESHGUI_BaseComputeOp::onPreviewShape()
1177 if ( myTShapeDisplayer )
1179 SUIT_OverrideCursor aWaitCursor;
1181 SMESH::getSelectedRows( table(), rows );
1183 bool showOnly = true;
1185 foreach ( row, rows )
1187 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1189 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1193 currentCellChanged(); // to update buttons
1197 //================================================================================
1201 //================================================================================
1203 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1207 delete myTShapeDisplayer;
1208 if ( myBadMeshDisplayer )
1209 delete myBadMeshDisplayer;
1212 //================================================================================
1214 * \brief Gets dialog of compute operation
1215 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1217 //================================================================================
1219 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1223 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1224 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1225 // connect signals and slots
1226 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1227 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1228 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1230 QTableWidget* aTable = me->table();
1231 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1232 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1237 //================================================================================
1239 * \brief returns from compute mesh result dialog
1241 //================================================================================
1243 bool SMESHGUI_BaseComputeOp::onApply()
1248 //================================================================================
1250 * \brief Return a table
1252 //================================================================================
1254 QTableWidget* SMESHGUI_BaseComputeOp::table()
1256 return myCompDlg->myTable;
1260 //================================================================================
1262 * \brief Constructor
1264 //================================================================================
1266 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1267 : SMESHGUI_BaseComputeOp()
1272 //================================================================================
1274 * \brief Desctructor
1276 //================================================================================
1278 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1282 //================================================================================
1284 * \brief perform it's intention action: compute mesh
1286 //================================================================================
1288 void SMESHGUI_ComputeOp::startOperation()
1290 SMESHGUI_BaseComputeOp::startOperation();
1291 if (myMesh->_is_nil())
1296 //================================================================================
1298 * \brief check the same operations on the same mesh
1300 //================================================================================
1302 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1304 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1306 if ( !myMesh->_is_nil() && baseOp ) {
1307 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1308 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1313 //================================================================================
1315 * \brief Gets dialog of this operation
1316 * \retval LightApp_Dialog* - pointer to dialog of this operation
1318 //================================================================================
1320 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1322 return computeDlg();
1325 //================================================================================
1327 * \brief Constructor
1329 //================================================================================
1331 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1332 : SMESHGUI_BaseComputeOp(),
1336 myPreviewDisplayer( 0 )
1338 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1341 //================================================================================
1345 //================================================================================
1347 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1354 if ( myPreviewDisplayer )
1355 delete myPreviewDisplayer;
1356 myPreviewDisplayer = 0;
1359 //================================================================================
1361 * \brief Gets current dialog of this operation
1362 * \retval LightApp_Dialog* - pointer to dialog of this operation
1364 //================================================================================
1366 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1371 //================================================================================
1373 * \brief perform it's intention action: prepare data
1375 //================================================================================
1377 void SMESHGUI_PrecomputeOp::startOperation()
1381 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1384 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1385 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1386 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1388 myActiveDlg = myDlg;
1390 // connect signal to compute dialog. which will be shown after Compute mesh operation
1391 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1394 // disconnect signals
1395 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1396 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1397 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1398 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1399 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1402 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1403 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1404 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1405 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1406 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1407 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1408 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1409 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1410 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1411 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1414 SMESHGUI_BaseComputeOp::startOperation();
1415 if (myMesh->_is_nil())
1418 if (myDlg->getPreviewMode() == -1)
1420 // nothing to preview
1421 SUIT_MessageBox::warning(desktop(),
1422 tr("SMESH_WRN_WARNING"),
1423 tr("SMESH_WRN_NOTHING_PREVIEW"));
1428 // disconnect slot from preview dialog to have Apply from results of compute operation only
1429 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1430 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1435 //================================================================================
1437 * \brief Stops operation
1439 //================================================================================
1441 void SMESHGUI_PrecomputeOp::stopOperation()
1443 if ( myPreviewDisplayer )
1445 myPreviewDisplayer->SetVisibility( false );
1446 delete myPreviewDisplayer;
1447 myPreviewDisplayer = 0;
1449 myMapShapeId.clear();
1450 SMESHGUI_BaseComputeOp::stopOperation();
1453 //================================================================================
1455 * \brief reinitialize dialog after operaiton become active again
1457 //================================================================================
1459 void SMESHGUI_PrecomputeOp::resumeOperation()
1461 if ( myActiveDlg == myDlg )
1463 SMESHGUI_BaseComputeOp::resumeOperation();
1466 //================================================================================
1468 * \brief perform it's intention action: reinitialise dialog
1470 //================================================================================
1472 void SMESHGUI_PrecomputeOp::initDialog()
1476 QMap<int, int> modeMap;
1477 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1478 getAssignedAlgos( pMesh, modeMap );
1479 if ( modeMap.contains( SMESH::DIM_3D ) )
1481 if ( modeMap.contains( SMESH::DIM_2D ) )
1482 modes.append( SMESH::DIM_2D );
1483 if ( modeMap.contains( SMESH::DIM_1D ) )
1484 modes.append( SMESH::DIM_1D );
1486 else if ( modeMap.contains( SMESH::DIM_2D ) )
1488 if ( modeMap.contains( SMESH::DIM_1D ) )
1489 modes.append( SMESH::DIM_1D );
1492 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1493 myOrderMgr->SetMesh( myMesh );
1494 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1495 myDlg->getMeshOrderBox()->setShown(isOrder);
1501 myDlg->setPreviewModes( modes );
1504 //================================================================================
1506 * \brief detect asigned mesh algorithms
1508 //================================================================================
1510 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1511 QMap<int,int>& theModeMap)
1513 _PTR(SObject) aHypRoot;
1514 _PTR(GenericAttribute) anAttr;
1515 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1516 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1518 _PTR(ChildIterator) anIter =
1519 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1520 for ( ; anIter->More(); anIter->Next() )
1522 _PTR(SObject) anObj = anIter->Value();
1523 _PTR(SObject) aRefObj;
1524 if ( anObj->ReferencedObject( aRefObj ) )
1529 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1531 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1532 if ( CORBA::is_nil( aVar ) )
1535 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1537 SMESH::SMESH_Algo_var algo;
1539 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1540 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1541 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1544 if ( !algo->_is_nil() )
1545 theModeMap[ dim ] = 0;
1552 //================================================================================
1554 * \brief perform it's intention action: compute mesh
1556 //================================================================================
1558 void SMESHGUI_PrecomputeOp::onCompute()
1561 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1562 myOrderMgr->SetMeshOrder();
1563 myMapShapeId.clear();
1564 myActiveDlg = computeDlg();
1568 //================================================================================
1570 * \brief perform it's intention action: compute mesh
1572 //================================================================================
1574 void SMESHGUI_PrecomputeOp::onCancel()
1576 QObject* curDlg = sender();
1577 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1579 // return from error messages
1584 bool isRestoreOrder = false;
1585 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1587 // ask to remove already computed mesh elements
1588 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1589 tr( "CLEAR_SUBMESH_QUESTION" ),
1590 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1592 // remove all submeshes for collected shapes
1593 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1594 for ( ; it != myMapShapeId.constEnd(); ++it )
1595 myMesh->ClearSubMesh( *it );
1596 isRestoreOrder = true;
1600 // return previous mesh order
1601 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1602 if (!isRestoreOrder)
1604 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1605 tr( "SMESH_REJECT_MESH_ORDER" ),
1606 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1608 myOrderMgr->SetMeshOrder(myPrevOrder);
1614 myMapShapeId.clear();
1615 SMESHGUI_BaseComputeOp::onCancel();
1618 //================================================================================
1620 * \brief perform it's intention action: preview mesh
1622 //================================================================================
1624 void SMESHGUI_PrecomputeOp::onPreview()
1626 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1629 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1633 // set modified submesh priority if any
1634 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1635 myOrderMgr->SetMeshOrder();
1637 // Compute preview of mesh,
1638 // i.e. compute mesh till indicated dimension
1639 int dim = myDlg->getPreviewMode();
1641 SMESH::MemoryReserve aMemoryReserve;
1643 SMESH::compute_error_array_var aCompErrors;
1646 bool computeFailed = true, memoryLack = false;
1648 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1649 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1651 SMESHGUI* gui = getSMESHGUI();
1652 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1653 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1654 if ( errors->length() > 0 ) {
1655 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1658 SUIT_OverrideCursor aWaitCursor;
1660 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1661 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1662 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1664 SMESH::long_array_var aShapesId = new SMESH::long_array();
1666 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1670 SMESH::MeshPreviewStruct_var previewData =
1671 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1673 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1674 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1676 computeFailed = false;
1677 myPreviewDisplayer->SetData( previewRes );
1678 // append shape indeces with computed mesh entities
1679 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1680 myMapShapeId[ aShapesId[ i ] ] = 0;
1683 myPreviewDisplayer->SetVisibility(false);
1685 catch(const SALOME::SALOME_Exception & S_ex){
1687 myPreviewDisplayer->SetVisibility(false);
1691 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1694 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1695 // check if there are memory problems
1696 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1697 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1699 catch(const SALOME::SALOME_Exception & S_ex){
1704 aMemoryReserve.release();
1706 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1707 bool noHypoError = ( aHypErrors.isEmpty() );
1709 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1710 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1712 bool isShowError = true;
1713 switch( aNotifyMode ) {
1714 case 0: // show the mesh computation result dialog NEVER
1715 isShowError = false;
1717 case 1: // show the mesh computation result dialog if there are some errors
1718 default: // show the result dialog after each mesh computation
1719 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1720 isShowError = false;
1724 aWaitCursor.suspend();
1729 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1730 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1735 //================================================================================
1737 * \brief Constructor
1739 //================================================================================
1741 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1742 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1745 setWindowTitle( tr( "CAPTION" ) );
1747 setButtonText( OK, tr( "COMPUTE" ) );
1748 QFrame* main = mainFrame();
1750 QVBoxLayout* layout = new QVBoxLayout( main );
1752 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1753 layout->addWidget(myOrderBox);
1755 QFrame* frame = new QFrame( main );
1756 layout->setMargin(0); layout->setSpacing(0);
1757 layout->addWidget( frame );
1759 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1760 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1762 myPreviewMode = new QtxComboBox( frame );
1763 frameLay->addWidget( myPreviewMode );
1765 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1766 frameLay->addWidget( myPreviewBtn );
1768 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1771 //================================================================================
1775 //================================================================================
1777 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1781 //================================================================================
1783 * \brief Sets available preview modes
1785 //================================================================================
1787 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1789 myPreviewMode->clear();
1790 QList<int>::const_iterator it = theModes.constBegin();
1791 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1793 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1794 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1795 myPreviewMode->setId( i, *it );
1797 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1800 //================================================================================
1802 * \brief Returns current preview mesh mode
1804 //================================================================================
1806 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1808 return myPreviewMode->currentId();
1811 //================================================================================
1813 * \brief Returns current preview mesh mode
1815 //================================================================================
1817 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1823 //================================================================================
1825 * \brief Constructor
1827 //================================================================================
1829 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1830 : SMESHGUI_BaseComputeOp()
1835 //================================================================================
1837 * \brief Desctructor
1839 //================================================================================
1841 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1845 //================================================================================
1847 * \brief perform it's intention action: compute mesh
1849 //================================================================================
1851 void SMESHGUI_EvaluateOp::startOperation()
1853 SMESHGUI_BaseComputeOp::evaluateDlg();
1854 SMESHGUI_BaseComputeOp::startOperation();
1855 if (myMesh->_is_nil())
1860 //================================================================================
1862 * \brief Gets dialog of this operation
1863 * \retval LightApp_Dialog* - pointer to dialog of this operation
1865 //================================================================================
1867 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1869 return evaluateDlg();
1872 //================================================================================
1874 * \brief evaluateMesh()
1876 //================================================================================
1878 void SMESHGUI_BaseComputeOp::evaluateMesh()
1882 SMESH::MemoryReserve aMemoryReserve;
1884 SMESH::compute_error_array_var aCompErrors;
1887 bool evaluateFailed = true, memoryLack = false;
1888 SMESH::long_array_var aRes;
1890 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1891 if ( !aMeshSObj ) // IPAL21340
1894 bool hasShape = myMesh->HasShapeToMesh();
1895 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1898 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1899 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1900 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1901 if ( errors->length() > 0 ) {
1902 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1904 SUIT_OverrideCursor aWaitCursor;
1906 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1909 aRes = gen->Evaluate(myMesh, myMainShape);
1911 catch(const SALOME::SALOME_Exception & S_ex){
1916 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1919 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1921 catch(const SALOME::SALOME_Exception & S_ex){
1927 aMemoryReserve.release();
1929 evaluateFailed = ( aCompErrors->length() > 0 );
1930 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1934 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1935 bool noHypoError = ( aHypErrors.isEmpty() );
1937 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1938 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1940 bool isShowResultDlg = true;
1942 //switch( aNotifyMode ) {
1943 //case 0: // show the mesh computation result dialog NEVER
1944 //isShowResultDlg = false;
1947 //case 1: // show the mesh computation result dialog if there are some errors
1948 //if ( memoryLack || !noHypoError )
1949 // isShowResultDlg = true;
1952 // isShowResultDlg = false;
1956 //default: // show the result dialog after each mesh computation
1957 //isShowResultDlg = true;
1961 if ( isShowResultDlg )
1962 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1963 noHypoError, aHypErrors);
1967 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1968 const bool theMemoryLack,
1969 const bool theNoCompError,
1970 SMESH::compute_error_array_var& theCompErrors,
1971 const bool theNoHypoError,
1972 const QString& theHypErrors)
1974 bool hasShape = myMesh->HasShapeToMesh();
1975 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1976 aCompDlg->myMemoryLackGroup->hide();
1978 if ( theMemoryLack )
1980 aCompDlg->myMemoryLackGroup->show();
1981 aCompDlg->myFullInfo->hide();
1982 aCompDlg->myBriefInfo->hide();
1983 aCompDlg->myHypErrorGroup->hide();
1984 aCompDlg->myCompErrorGroup->hide();
1986 else if ( theNoCompError && theNoHypoError )
1988 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1989 aCompDlg->myFullInfo->show();
1990 aCompDlg->myBriefInfo->hide();
1991 aCompDlg->myHypErrorGroup->hide();
1992 aCompDlg->myCompErrorGroup->hide();
1996 QTableWidget* tbl = aCompDlg->myTable;
1997 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1998 aCompDlg->myBriefInfo->show();
1999 aCompDlg->myFullInfo->hide();
2001 if ( theNoHypoError ) {
2002 aCompDlg->myHypErrorGroup->hide();
2005 aCompDlg->myHypErrorGroup->show();
2006 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2009 if ( theNoCompError ) {
2010 aCompDlg->myCompErrorGroup->hide();
2013 aCompDlg->myCompErrorGroup->show();
2015 aCompDlg->myPublishBtn->hide();
2016 aCompDlg->myShowBtn->hide();
2018 // fill table of errors
2019 tbl->setRowCount( theCompErrors->length() );
2020 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2021 else tbl->showColumn( COL_SHAPE );
2022 tbl->setColumnWidth( COL_ERROR, 200 );
2024 bool hasBadMesh = false;
2025 for ( int row = 0; row < theCompErrors->length(); ++row )
2027 SMESH::ComputeError & err = theCompErrors[ row ];
2029 QString text = err.algoName.in();
2030 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2031 else tbl->item( row, COL_ALGO )->setText( text );
2033 text = SMESH::errorText( err.code, err.comment.in() );
2034 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2035 else tbl->item( row, COL_ERROR )->setText( text );
2037 text = QString("%1").arg( err.subShapeID );
2038 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2039 else tbl->item( row, COL_SHAPEID )->setText( text );
2041 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2042 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2043 else tbl->item( row, COL_SHAPE )->setText( text );
2045 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2046 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2047 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2049 text = err.hasBadMesh ? "hasBadMesh" : "";
2050 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2051 else tbl->item( row, COL_BAD_MESH )->setText( text );
2052 if ( err.hasBadMesh ) hasBadMesh = true;
2054 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2055 tbl->resizeRowToContents( row );
2057 tbl->resizeColumnToContents( COL_ALGO );
2058 tbl->resizeColumnToContents( COL_SHAPE );
2061 aCompDlg->myBadMeshBtn->show();
2063 aCompDlg->myBadMeshBtn->hide();
2065 tbl->setCurrentCell(0,0);
2066 currentCellChanged(); // to update buttons
2069 // show dialog and wait, becase Compute can be invoked from Preview operation
2070 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2075 //================================================================================
2077 * \brief Gets dialog of evaluate operation
2078 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2080 //================================================================================
2082 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2086 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2087 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2088 // connect signals and slots
2089 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2090 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2091 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2092 QTableWidget* aTable = me->table();
2093 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2094 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));