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 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
828 // NPAL16631: if ( !memoryLack )
830 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
831 update( UF_ObjBrowser | UF_Model );
834 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
835 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
836 long newSize = myMesh->NbElements();
840 if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
843 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
846 SMESH::Update(myIObject, true);
850 MESSAGE ( "Exception thrown during mesh visualization" );
852 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
853 SMESH::OnVisuException();
860 else if ( limitExceeded )
862 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
863 SUIT_MessageBox::warning( desktop(),
864 tr( "SMESH_WRN_WARNING" ),
865 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
868 LightApp_SelectionMgr *Sel = selectionMgr();
871 SALOME_ListIO selected;
872 selected.Append( myIObject );
873 Sel->setSelectedObjects( selected );
879 aMemoryReserve.release();
881 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
885 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
886 bool noHypoError = ( aHypErrors.isEmpty() );
888 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
889 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
891 bool isShowResultDlg = true;
892 switch( aNotifyMode ) {
893 case 0: // show the mesh computation result dialog NEVER
894 isShowResultDlg = false;
897 case 1: // show the mesh computation result dialog if there are some errors
898 if ( memoryLack || !noCompError || !noHypoError )
899 isShowResultDlg = true;
902 isShowResultDlg = false;
906 default: // show the result dialog after each mesh computation
907 isShowResultDlg = true;
911 if ( isShowResultDlg )
912 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
915 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
916 const bool theNoCompError,
917 SMESH::compute_error_array_var& theCompErrors,
918 const bool theNoHypoError,
919 const QString& theHypErrors )
921 bool hasShape = myMesh->HasShapeToMesh();
922 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
923 aCompDlg->myMemoryLackGroup->hide();
927 aCompDlg->myMemoryLackGroup->show();
928 aCompDlg->myFullInfo->hide();
929 aCompDlg->myBriefInfo->hide();
930 aCompDlg->myHypErrorGroup->hide();
931 aCompDlg->myCompErrorGroup->hide();
933 else if ( theNoCompError && theNoHypoError )
935 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
936 aCompDlg->myFullInfo->SetMeshInfo( aRes );
937 aCompDlg->myFullInfo->show();
938 aCompDlg->myBriefInfo->hide();
939 aCompDlg->myHypErrorGroup->hide();
940 aCompDlg->myCompErrorGroup->hide();
944 QTableWidget* tbl = aCompDlg->myTable;
945 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
946 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
947 aCompDlg->myBriefInfo->show();
948 aCompDlg->myFullInfo->hide();
950 if ( theNoHypoError ) {
951 aCompDlg->myHypErrorGroup->hide();
954 aCompDlg->myHypErrorGroup->show();
955 aCompDlg->myHypErrorLabel->setText( theHypErrors );
958 if ( theNoCompError ) {
959 aCompDlg->myCompErrorGroup->hide();
962 aCompDlg->myCompErrorGroup->show();
965 aCompDlg->myPublishBtn->hide();
966 aCompDlg->myShowBtn->hide();
969 aCompDlg->myPublishBtn->show();
970 aCompDlg->myShowBtn->show();
973 // fill table of errors
974 tbl->setRowCount( theCompErrors->length() );
975 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
976 else tbl->showColumn( COL_SHAPE );
977 tbl->setColumnWidth( COL_ERROR, 200 );
979 bool hasBadMesh = false;
980 for ( int row = 0; row < theCompErrors->length(); ++row )
982 SMESH::ComputeError & err = theCompErrors[ row ];
984 QString text = err.algoName.in();
985 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
986 else tbl->item( row, COL_ALGO )->setText( text );
988 text = SMESH::errorText( err.code, err.comment.in() );
989 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
990 else tbl->item( row, COL_ERROR )->setText( text );
992 text = QString("%1").arg( err.subShapeID );
993 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
994 else tbl->item( row, COL_SHAPEID )->setText( text );
996 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
997 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
998 else tbl->item( row, COL_SHAPE )->setText( text );
1000 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1001 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1002 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1004 text = err.hasBadMesh ? "hasBadMesh" : "";
1005 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1006 else tbl->item( row, COL_BAD_MESH )->setText( text );
1007 if ( err.hasBadMesh ) hasBadMesh = true;
1009 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1010 tbl->resizeRowToContents( row );
1012 tbl->resizeColumnToContents( COL_ALGO );
1013 tbl->resizeColumnToContents( COL_SHAPE );
1016 aCompDlg->myBadMeshBtn->show();
1018 aCompDlg->myBadMeshBtn->hide();
1020 tbl->setCurrentCell(0,0);
1021 currentCellChanged(); // to update buttons
1024 // show dialog and wait, becase Compute can be invoked from Preview operation
1025 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1029 //================================================================================
1031 * \brief Stops operation
1033 //================================================================================
1035 void SMESHGUI_BaseComputeOp::stopOperation()
1037 SMESHGUI_Operation::stopOperation();
1038 if ( myTShapeDisplayer )
1039 myTShapeDisplayer->SetVisibility( false );
1040 if ( myBadMeshDisplayer ) {
1041 myBadMeshDisplayer->SetVisibility( false );
1042 // delete it in order not to have problems at its destruction when the viewer
1043 // where it worked is dead due to e.g. study closing
1044 delete myBadMeshDisplayer;
1045 myBadMeshDisplayer = 0;
1047 myIObject.Nullify();
1050 //================================================================================
1052 * \brief publish selected subshape
1054 //================================================================================
1056 void SMESHGUI_BaseComputeOp::onPublishShape()
1058 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1059 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1062 SMESH::getSelectedRows( table(), rows );
1064 foreach ( row, rows )
1066 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1067 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1068 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1070 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1072 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1073 SALOMEDS::SObject_var so =
1074 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1075 // look for myMainShape in the table
1076 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1077 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1078 if ( so->_is_nil() ) {
1079 table()->item( r, COL_SHAPE )->setText( so->GetName() );
1080 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1085 if ( curSub == 1 ) continue;
1087 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1088 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1089 if ( !so->_is_nil() ) {
1090 table()->item( row, COL_SHAPE )->setText( so->GetName() );
1091 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1095 getSMESHGUI()->getApp()->updateObjectBrowser();
1096 currentCellChanged(); // to update buttons
1099 //================================================================================
1101 * \brief show mesh elements preventing computation of a submesh of current row
1103 //================================================================================
1105 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1107 myTShapeDisplayer->SetVisibility( false );
1109 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1110 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1112 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1113 SMESHGUI* gui = getSMESHGUI();
1114 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1115 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1116 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1117 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1118 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1119 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1120 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1121 // delete property !!!!!!!!!!
1122 vtkProperty* prop = vtkProperty::New();
1123 prop->SetLineWidth( aLineWidth * 3 );
1124 prop->SetPointSize( aPointSize * 3 );
1125 prop->SetColor( 250, 0, 250 );
1126 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1127 myBadMeshDisplayer->SetData( aMeshData._retn() );
1132 //================================================================================
1134 * \brief SLOT called when a selected cell in table() changed
1136 //================================================================================
1138 void SMESHGUI_BaseComputeOp::currentCellChanged()
1140 myTShapeDisplayer->SetVisibility( false );
1141 if ( myBadMeshDisplayer )
1142 myBadMeshDisplayer->SetVisibility( false );
1144 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1146 int nbSelected = SMESH::getSelectedRows( table(), rows );
1148 foreach ( row, rows )
1150 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1151 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1152 if ( hasData && !isPublished )
1153 publishEnable = true;
1155 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1156 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1158 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1165 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1168 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1169 myCompDlg->myShowBtn ->setEnabled( showEnable );
1170 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1173 //================================================================================
1175 * \brief update preview
1177 //================================================================================
1179 void SMESHGUI_BaseComputeOp::onPreviewShape()
1181 if ( myTShapeDisplayer )
1183 SUIT_OverrideCursor aWaitCursor;
1185 SMESH::getSelectedRows( table(), rows );
1187 bool showOnly = true;
1189 foreach ( row, rows )
1191 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1193 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1197 currentCellChanged(); // to update buttons
1201 //================================================================================
1205 //================================================================================
1207 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1211 delete myTShapeDisplayer;
1212 if ( myBadMeshDisplayer )
1213 delete myBadMeshDisplayer;
1216 //================================================================================
1218 * \brief Gets dialog of compute operation
1219 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1221 //================================================================================
1223 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1227 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1228 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1229 // connect signals and slots
1230 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1231 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1232 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1234 QTableWidget* aTable = me->table();
1235 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1236 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1241 //================================================================================
1243 * \brief returns from compute mesh result dialog
1245 //================================================================================
1247 bool SMESHGUI_BaseComputeOp::onApply()
1252 //================================================================================
1254 * \brief Return a table
1256 //================================================================================
1258 QTableWidget* SMESHGUI_BaseComputeOp::table()
1260 return myCompDlg->myTable;
1264 //================================================================================
1266 * \brief Constructor
1268 //================================================================================
1270 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1271 : SMESHGUI_BaseComputeOp()
1276 //================================================================================
1278 * \brief Desctructor
1280 //================================================================================
1282 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1286 //================================================================================
1288 * \brief perform it's intention action: compute mesh
1290 //================================================================================
1292 void SMESHGUI_ComputeOp::startOperation()
1294 SMESHGUI_BaseComputeOp::startOperation();
1295 if (myMesh->_is_nil())
1300 //================================================================================
1302 * \brief check the same operations on the same mesh
1304 //================================================================================
1306 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1308 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1310 if ( !myMesh->_is_nil() && baseOp ) {
1311 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1312 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1317 //================================================================================
1319 * \brief Gets dialog of this operation
1320 * \retval LightApp_Dialog* - pointer to dialog of this operation
1322 //================================================================================
1324 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1326 return computeDlg();
1329 //================================================================================
1331 * \brief Constructor
1333 //================================================================================
1335 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1336 : SMESHGUI_BaseComputeOp(),
1340 myPreviewDisplayer( 0 )
1342 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1345 //================================================================================
1349 //================================================================================
1351 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1358 if ( myPreviewDisplayer )
1359 delete myPreviewDisplayer;
1360 myPreviewDisplayer = 0;
1363 //================================================================================
1365 * \brief Gets current dialog of this operation
1366 * \retval LightApp_Dialog* - pointer to dialog of this operation
1368 //================================================================================
1370 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1375 //================================================================================
1377 * \brief perform it's intention action: prepare data
1379 //================================================================================
1381 void SMESHGUI_PrecomputeOp::startOperation()
1385 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1388 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1389 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1390 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1392 myActiveDlg = myDlg;
1394 // connect signal to compute dialog. which will be shown after Compute mesh operation
1395 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1398 // disconnect signals
1399 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1400 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1401 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1402 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1403 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1406 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1407 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1408 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1409 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1410 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1411 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1412 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1413 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1414 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1415 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1418 SMESHGUI_BaseComputeOp::startOperation();
1419 if (myMesh->_is_nil())
1422 if (myDlg->getPreviewMode() == -1)
1424 // nothing to preview
1425 SUIT_MessageBox::warning(desktop(),
1426 tr("SMESH_WRN_WARNING"),
1427 tr("SMESH_WRN_NOTHING_PREVIEW"));
1432 // disconnect slot from preview dialog to have Apply from results of compute operation only
1433 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1434 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1439 //================================================================================
1441 * \brief Stops operation
1443 //================================================================================
1445 void SMESHGUI_PrecomputeOp::stopOperation()
1447 if ( myPreviewDisplayer )
1449 myPreviewDisplayer->SetVisibility( false );
1450 delete myPreviewDisplayer;
1451 myPreviewDisplayer = 0;
1453 myMapShapeId.clear();
1454 SMESHGUI_BaseComputeOp::stopOperation();
1457 //================================================================================
1459 * \brief reinitialize dialog after operaiton become active again
1461 //================================================================================
1463 void SMESHGUI_PrecomputeOp::resumeOperation()
1465 if ( myActiveDlg == myDlg )
1467 SMESHGUI_BaseComputeOp::resumeOperation();
1470 //================================================================================
1472 * \brief perform it's intention action: reinitialise dialog
1474 //================================================================================
1476 void SMESHGUI_PrecomputeOp::initDialog()
1480 QMap<int, int> modeMap;
1481 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1482 getAssignedAlgos( pMesh, modeMap );
1483 if ( modeMap.contains( SMESH::DIM_3D ) )
1485 if ( modeMap.contains( SMESH::DIM_2D ) )
1486 modes.append( SMESH::DIM_2D );
1487 if ( modeMap.contains( SMESH::DIM_1D ) )
1488 modes.append( SMESH::DIM_1D );
1490 else if ( modeMap.contains( SMESH::DIM_2D ) )
1492 if ( modeMap.contains( SMESH::DIM_1D ) )
1493 modes.append( SMESH::DIM_1D );
1496 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1497 myOrderMgr->SetMesh( myMesh );
1498 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1499 myDlg->getMeshOrderBox()->setShown(isOrder);
1505 myDlg->setPreviewModes( modes );
1508 //================================================================================
1510 * \brief detect asigned mesh algorithms
1512 //================================================================================
1514 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1515 QMap<int,int>& theModeMap)
1517 _PTR(SObject) aHypRoot;
1518 _PTR(GenericAttribute) anAttr;
1519 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1520 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1522 _PTR(ChildIterator) anIter =
1523 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1524 for ( ; anIter->More(); anIter->Next() )
1526 _PTR(SObject) anObj = anIter->Value();
1527 _PTR(SObject) aRefObj;
1528 if ( anObj->ReferencedObject( aRefObj ) )
1533 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1535 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1536 if ( CORBA::is_nil( aVar ) )
1539 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1541 SMESH::SMESH_Algo_var algo;
1543 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1544 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1545 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1548 if ( !algo->_is_nil() )
1549 theModeMap[ dim ] = 0;
1556 //================================================================================
1558 * \brief perform it's intention action: compute mesh
1560 //================================================================================
1562 void SMESHGUI_PrecomputeOp::onCompute()
1565 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1566 myOrderMgr->SetMeshOrder();
1567 myMapShapeId.clear();
1568 myActiveDlg = computeDlg();
1572 //================================================================================
1574 * \brief perform it's intention action: compute mesh
1576 //================================================================================
1578 void SMESHGUI_PrecomputeOp::onCancel()
1580 QObject* curDlg = sender();
1581 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1583 // return from error messages
1588 bool isRestoreOrder = false;
1589 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1591 // ask to remove already computed mesh elements
1592 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1593 tr( "CLEAR_SUBMESH_QUESTION" ),
1594 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1596 // remove all submeshes for collected shapes
1597 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1598 for ( ; it != myMapShapeId.constEnd(); ++it )
1599 myMesh->ClearSubMesh( *it );
1600 isRestoreOrder = true;
1604 // return previous mesh order
1605 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1606 if (!isRestoreOrder)
1608 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1609 tr( "SMESH_REJECT_MESH_ORDER" ),
1610 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1612 myOrderMgr->SetMeshOrder(myPrevOrder);
1618 myMapShapeId.clear();
1619 SMESHGUI_BaseComputeOp::onCancel();
1622 //================================================================================
1624 * \brief perform it's intention action: preview mesh
1626 //================================================================================
1628 void SMESHGUI_PrecomputeOp::onPreview()
1630 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1633 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1637 // set modified submesh priority if any
1638 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1639 myOrderMgr->SetMeshOrder();
1641 // Compute preview of mesh,
1642 // i.e. compute mesh till indicated dimension
1643 int dim = myDlg->getPreviewMode();
1645 SMESH::MemoryReserve aMemoryReserve;
1647 SMESH::compute_error_array_var aCompErrors;
1650 bool computeFailed = true, memoryLack = false;
1652 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1653 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1655 SMESHGUI* gui = getSMESHGUI();
1656 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1657 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1658 if ( errors->length() > 0 ) {
1659 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1662 SUIT_OverrideCursor aWaitCursor;
1664 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1665 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1666 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1668 SMESH::long_array_var aShapesId = new SMESH::long_array();
1670 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1674 SMESH::MeshPreviewStruct_var previewData =
1675 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1677 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1678 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1680 computeFailed = false;
1681 myPreviewDisplayer->SetData( previewRes );
1682 // append shape indeces with computed mesh entities
1683 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1684 myMapShapeId[ aShapesId[ i ] ] = 0;
1687 myPreviewDisplayer->SetVisibility(false);
1689 catch(const SALOME::SALOME_Exception & S_ex){
1691 myPreviewDisplayer->SetVisibility(false);
1695 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1698 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1699 // check if there are memory problems
1700 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1701 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1703 catch(const SALOME::SALOME_Exception & S_ex){
1708 aMemoryReserve.release();
1710 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1711 bool noHypoError = ( aHypErrors.isEmpty() );
1713 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1714 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1716 bool isShowError = true;
1717 switch( aNotifyMode ) {
1718 case 0: // show the mesh computation result dialog NEVER
1719 isShowError = false;
1721 case 1: // show the mesh computation result dialog if there are some errors
1722 default: // show the result dialog after each mesh computation
1723 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1724 isShowError = false;
1728 aWaitCursor.suspend();
1733 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1734 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1739 //================================================================================
1741 * \brief Constructor
1743 //================================================================================
1745 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1746 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1749 setWindowTitle( tr( "CAPTION" ) );
1751 setButtonText( OK, tr( "COMPUTE" ) );
1752 QFrame* main = mainFrame();
1754 QVBoxLayout* layout = new QVBoxLayout( main );
1756 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1757 layout->addWidget(myOrderBox);
1759 QFrame* frame = new QFrame( main );
1760 layout->setMargin(0); layout->setSpacing(0);
1761 layout->addWidget( frame );
1763 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1764 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1766 myPreviewMode = new QtxComboBox( frame );
1767 frameLay->addWidget( myPreviewMode );
1769 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1770 frameLay->addWidget( myPreviewBtn );
1772 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1775 //================================================================================
1779 //================================================================================
1781 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1785 //================================================================================
1787 * \brief Sets available preview modes
1789 //================================================================================
1791 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1793 myPreviewMode->clear();
1794 QList<int>::const_iterator it = theModes.constBegin();
1795 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1797 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1798 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1799 myPreviewMode->setId( i, *it );
1801 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1804 //================================================================================
1806 * \brief Returns current preview mesh mode
1808 //================================================================================
1810 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1812 return myPreviewMode->currentId();
1815 //================================================================================
1817 * \brief Returns current preview mesh mode
1819 //================================================================================
1821 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1827 //================================================================================
1829 * \brief Constructor
1831 //================================================================================
1833 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1834 : SMESHGUI_BaseComputeOp()
1839 //================================================================================
1841 * \brief Desctructor
1843 //================================================================================
1845 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1849 //================================================================================
1851 * \brief perform it's intention action: compute mesh
1853 //================================================================================
1855 void SMESHGUI_EvaluateOp::startOperation()
1857 SMESHGUI_BaseComputeOp::evaluateDlg();
1858 SMESHGUI_BaseComputeOp::startOperation();
1859 if (myMesh->_is_nil())
1864 //================================================================================
1866 * \brief Gets dialog of this operation
1867 * \retval LightApp_Dialog* - pointer to dialog of this operation
1869 //================================================================================
1871 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1873 return evaluateDlg();
1876 //================================================================================
1878 * \brief evaluateMesh()
1880 //================================================================================
1882 void SMESHGUI_BaseComputeOp::evaluateMesh()
1886 SMESH::MemoryReserve aMemoryReserve;
1888 SMESH::compute_error_array_var aCompErrors;
1891 bool evaluateFailed = true, memoryLack = false;
1892 SMESH::long_array_var aRes;
1894 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1895 if ( !aMeshSObj ) // IPAL21340
1898 bool hasShape = myMesh->HasShapeToMesh();
1899 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1902 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1903 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1904 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1905 if ( errors->length() > 0 ) {
1906 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1908 SUIT_OverrideCursor aWaitCursor;
1910 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1913 aRes = gen->Evaluate(myMesh, myMainShape);
1915 catch(const SALOME::SALOME_Exception & S_ex){
1920 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1923 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1925 catch(const SALOME::SALOME_Exception & S_ex){
1931 aMemoryReserve.release();
1933 evaluateFailed = ( aCompErrors->length() > 0 );
1934 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1938 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1939 bool noHypoError = ( aHypErrors.isEmpty() );
1941 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1942 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1944 bool isShowResultDlg = true;
1946 //switch( aNotifyMode ) {
1947 //case 0: // show the mesh computation result dialog NEVER
1948 //isShowResultDlg = false;
1951 //case 1: // show the mesh computation result dialog if there are some errors
1952 //if ( memoryLack || !noHypoError )
1953 // isShowResultDlg = true;
1956 // isShowResultDlg = false;
1960 //default: // show the result dialog after each mesh computation
1961 //isShowResultDlg = true;
1965 if ( isShowResultDlg )
1966 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1967 noHypoError, aHypErrors);
1971 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1972 const bool theMemoryLack,
1973 const bool theNoCompError,
1974 SMESH::compute_error_array_var& theCompErrors,
1975 const bool theNoHypoError,
1976 const QString& theHypErrors)
1978 bool hasShape = myMesh->HasShapeToMesh();
1979 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1980 aCompDlg->myMemoryLackGroup->hide();
1982 if ( theMemoryLack )
1984 aCompDlg->myMemoryLackGroup->show();
1985 aCompDlg->myFullInfo->hide();
1986 aCompDlg->myBriefInfo->hide();
1987 aCompDlg->myHypErrorGroup->hide();
1988 aCompDlg->myCompErrorGroup->hide();
1990 else if ( theNoCompError && theNoHypoError )
1992 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1993 aCompDlg->myFullInfo->show();
1994 aCompDlg->myBriefInfo->hide();
1995 aCompDlg->myHypErrorGroup->hide();
1996 aCompDlg->myCompErrorGroup->hide();
2000 QTableWidget* tbl = aCompDlg->myTable;
2001 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2002 aCompDlg->myBriefInfo->show();
2003 aCompDlg->myFullInfo->hide();
2005 if ( theNoHypoError ) {
2006 aCompDlg->myHypErrorGroup->hide();
2009 aCompDlg->myHypErrorGroup->show();
2010 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2013 if ( theNoCompError ) {
2014 aCompDlg->myCompErrorGroup->hide();
2017 aCompDlg->myCompErrorGroup->show();
2019 aCompDlg->myPublishBtn->hide();
2020 aCompDlg->myShowBtn->hide();
2022 // fill table of errors
2023 tbl->setRowCount( theCompErrors->length() );
2024 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2025 else tbl->showColumn( COL_SHAPE );
2026 tbl->setColumnWidth( COL_ERROR, 200 );
2028 bool hasBadMesh = false;
2029 for ( int row = 0; row < theCompErrors->length(); ++row )
2031 SMESH::ComputeError & err = theCompErrors[ row ];
2033 QString text = err.algoName.in();
2034 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2035 else tbl->item( row, COL_ALGO )->setText( text );
2037 text = SMESH::errorText( err.code, err.comment.in() );
2038 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2039 else tbl->item( row, COL_ERROR )->setText( text );
2041 text = QString("%1").arg( err.subShapeID );
2042 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2043 else tbl->item( row, COL_SHAPEID )->setText( text );
2045 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2046 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2047 else tbl->item( row, COL_SHAPE )->setText( text );
2049 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2050 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2051 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2053 text = err.hasBadMesh ? "hasBadMesh" : "";
2054 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2055 else tbl->item( row, COL_BAD_MESH )->setText( text );
2056 if ( err.hasBadMesh ) hasBadMesh = true;
2058 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2059 tbl->resizeRowToContents( row );
2061 tbl->resizeColumnToContents( COL_ALGO );
2062 tbl->resizeColumnToContents( COL_SHAPE );
2065 aCompDlg->myBadMeshBtn->show();
2067 aCompDlg->myBadMeshBtn->hide();
2069 tbl->setCurrentCell(0,0);
2070 currentCellChanged(); // to update buttons
2073 // show dialog and wait, becase Compute can be invoked from Preview operation
2074 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2079 //================================================================================
2081 * \brief Gets dialog of evaluate operation
2082 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2084 //================================================================================
2086 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2090 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2091 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2092 // connect signals and slots
2093 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2094 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2095 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2096 QTableWidget* aTable = me->table();
2097 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2098 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));