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>
90 #include <vtkProperty.h>
99 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
101 static void addSeparator( QWidget* parent )
103 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
104 int row = l->rowCount();
105 int cols = l->columnCount();
106 for ( int i = 0; i < cols; i++ ) {
107 QFrame* hline = new QFrame( parent );
108 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
109 l->addWidget( hline, row, i );
114 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
117 //using namespace SMESH;
121 //=============================================================================
123 * \brief Allocate some memory at construction and release it at destruction.
124 * Is used to be able to continue working after mesh generation or visualization
125 * break due to lack of memory
127 //=============================================================================
132 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
133 void release() { delete [] myBuf; myBuf = 0; }
134 ~MemoryReserve() { release(); }
137 // =========================================================================================
139 * \brief Class showing shapes without publishing
141 // =========================================================================================
143 class TShapeDisplayer
146 // -----------------------------------------------------------------------
147 TShapeDisplayer(): myViewWindow(0)
149 myProperty = vtkProperty::New();
150 myProperty->SetRepresentationToWireframe();
151 myProperty->SetColor( 250, 0, 250 );
152 myProperty->SetAmbientColor( 250, 0, 250 );
153 myProperty->SetDiffuseColor( 250, 0, 250 );
154 //myProperty->SetSpecularColor( 250, 0, 250 );
155 myProperty->SetLineWidth( 5 );
157 // -----------------------------------------------------------------------
161 myProperty->Delete();
163 // -----------------------------------------------------------------------
166 if ( hasViewWindow() ) {
167 TActorIterator actorIt = actorIterator();
168 while ( actorIt.more() )
169 if (VTKViewer_Actor* anActor = actorIt.next()) {
170 myViewWindow->RemoveActor( anActor );
174 myIndexToShape.Clear();
176 myShownActors.clear();
179 // -----------------------------------------------------------------------
180 void SetVisibility (bool theVisibility)
182 TActorIterator actorIt = shownIterator();
183 while ( actorIt.more() )
184 if (VTKViewer_Actor* anActor = actorIt.next())
185 anActor->SetVisibility(theVisibility);
186 SMESH::RepaintCurrentView();
188 // -----------------------------------------------------------------------
189 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
191 std::string mainEntry;
192 if ( !aMainShape->_is_nil() )
193 mainEntry = aMainShape->GetStudyEntry();
194 return ( myMainEntry == mainEntry &&
195 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
197 // -----------------------------------------------------------------------
198 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
200 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
201 std::string mainEntry;
202 if ( !aMainShape->_is_nil() )
203 mainEntry = aMainShape->GetStudyEntry();
204 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
207 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
208 checkTriangulation( aShape );
209 TopExp::MapShapes(aShape, myIndexToShape);
210 myActors.resize( myIndexToShape.Extent(), 0 );
211 myShownActors.reserve( myIndexToShape.Extent() );
213 myMainEntry = mainEntry;
214 myViewWindow = aViewWindow;
216 if ( only ) { // hide shown actors
217 TActorIterator actorIt = shownIterator();
218 while ( actorIt.more() )
219 if (VTKViewer_Actor* anActor = actorIt.next())
220 anActor->SetVisibility(false);
221 myShownActors.clear();
223 // find actors to show
224 TopoDS_Shape aShape = myIndexToShape( subShapeID );
225 if ( !aShape.IsNull() ) {
226 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
227 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
228 //checkTriangulation( exp.Current() );
229 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
230 myShownActors.push_back( anActor );
232 if ( type == TopAbs_FACE ) {
233 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
234 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
235 if ( !BRep_Tool::Degenerated( edge ))
236 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
237 myShownActors.push_back( anActor );
241 myBuiltSubs.insert( subShapeID );
244 // -----------------------------------------------------------------------
248 typedef std::vector<GEOM_Actor*> TActorVec;
250 TActorVec myShownActors;
251 TopTools_IndexedMapOfShape myIndexToShape;
252 std::string myMainEntry;
253 SVTK_ViewWindow* myViewWindow;
254 vtkProperty* myProperty;
255 std::set<int> myBuiltSubs;
257 // -----------------------------------------------------------------------
258 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
259 TActorIterator actorIterator() {
260 return TActorIterator( myActors.begin(), myActors.end() );
262 TActorIterator shownIterator() {
263 return TActorIterator( myShownActors.begin(), myShownActors.end() );
265 // -----------------------------------------------------------------------
266 GEOM_Actor* getActor(const TopoDS_Shape& shape)
268 int index = myIndexToShape.FindIndex( shape ) - 1;
269 if ( index < 0 || index >= myActors.size() )
271 GEOM_Actor* & actor = myActors[ index ];
273 actor = GEOM_Actor::New();
275 actor->SetShape(shape,0,0);
276 actor->SetProperty(myProperty);
277 actor->SetShadingProperty(myProperty);
278 actor->SetWireframeProperty(myProperty);
279 actor->SetPreviewProperty(myProperty);
280 actor->PickableOff();
281 // if ( shape.ShapeType() == TopAbs_EDGE )
282 // actor->SubShapeOn();
283 myViewWindow->AddActor( actor );
288 // -----------------------------------------------------------------------
289 void checkTriangulation(const TopoDS_Shape& shape)
291 TopLoc_Location aLoc;
292 Standard_Boolean alreadymesh = Standard_True;
293 TopExp_Explorer ex(shape, TopAbs_FACE);
295 for ( ; ex.More(); ex.Next()) {
296 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
297 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
298 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
301 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
302 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
303 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
304 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
306 if (alreadymesh) return;
307 // Compute default deflection
309 BRepBndLib::Add(shape, B);
310 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
311 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
312 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
313 BRepMesh_IncrementalMesh MESH(shape,deflection);
315 // -----------------------------------------------------------------------
316 bool hasViewWindow() const
318 if ( !myViewWindow ) return false;
320 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
321 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
327 // =========================================================================================
329 * \brief Return text describing an error
331 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
332 QString errorText(int errCode, const char* comment)
336 CASE2TEXT( COMPERR_OK );
337 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
338 CASE2TEXT( COMPERR_STD_EXCEPTION );
339 CASE2TEXT( COMPERR_OCC_EXCEPTION );
340 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
341 CASE2TEXT( COMPERR_EXCEPTION );
342 CASE2TEXT( COMPERR_MEMORY_PB );
343 CASE2TEXT( COMPERR_BAD_SHAPE );
344 case SMESH::COMPERR_ALGO_FAILED:
345 if ( strlen(comment) == 0 )
346 text = QObject::tr("COMPERR_ALGO_FAILED");
349 text = QString("#%1").arg( -errCode );
351 if ( text.length() > 0 ) text += ". ";
352 return text + comment;
354 // -----------------------------------------------------------------------
356 * \brief Return SO of a subshape
358 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
360 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
361 if ( subShapeID == 1 || !so )
363 _PTR(ChildIterator) it;
364 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
365 it = study->NewChildIterator(so);
368 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
369 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
370 if ( !geom->_is_nil() ) {
371 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
372 if ( list->length() == 1 && list[0] == subShapeID )
379 // -----------------------------------------------------------------------
381 * \brief Return subshape by ID
383 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
385 GEOM::GEOM_Object_var aSubShape;
386 if ( subShapeID == 1 )
387 aSubShape = aMainShape;
388 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
389 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
391 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
392 return aSubShape._retn();
394 // -----------------------------------------------------------------------
396 * \brief Return shape type name
398 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
399 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
402 if ( !aShape->_is_nil() ) {
403 switch ( aShape->GetShapeType() ) {
410 CASE2NAME( COMPSOLID );
411 CASE2NAME( COMPOUND );
417 // -----------------------------------------------------------------------
419 * \brief Return text describing a subshape
421 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
424 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
425 text = aSO->GetName().c_str();
427 text = QString("#%1").arg( subShapeID );
428 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
429 if ( typeName.length() )
430 text += QString(" (%1)").arg(typeName);
434 // -----------------------------------------------------------------------
436 * \brief Return a list of selected rows
438 int getSelectedRows(QTableWidget* table, QList<int>& rows)
441 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
442 QTableWidgetSelectionRange range;
443 foreach( range, selRanges )
445 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
448 if ( rows.isEmpty() && table->currentRow() > -1 )
449 rows.append( table->currentRow() );
457 // =========================================================================================
459 * \brief Dialog to compute a mesh and show computation errors
461 //=======================================================================
463 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
464 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
466 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
467 aDlgLay->setMargin( 0 );
468 aDlgLay->setSpacing( SPACING );
470 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
472 aDlgLay->addWidget(aMainFrame);
474 aDlgLay->setStretchFactor(aMainFrame, 1);
477 // =========================================================================================
481 //=======================================================================
483 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
487 //=======================================================================
488 // function : createMainFrame()
489 // purpose : Create frame containing dialog's fields
490 //=======================================================================
492 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
494 QFrame* aFrame = new QFrame(theParent);
496 SUIT_ResourceMgr* rm = resourceMgr();
497 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
503 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
506 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
508 QButtonGroup* aBtnGrp = new QButtonGroup(this);
509 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
510 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
512 QRadioButton* aRBut = new QRadioButton(aPixGrp);
513 aRBut->setIcon(iconCompute);
514 aRBut->setChecked(true);
515 aPixGrpLayout->addWidget(aRBut);
516 aBtnGrp->addButton(aRBut, 0);
520 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
521 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
522 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
523 myMeshName = new QLabel(nameBox);
524 nameBoxLayout->addWidget(myMeshName);
528 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
529 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
531 // Computation errors
533 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
534 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
535 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
536 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
537 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
539 //myTable->setReadOnly( true ); // VSR: check
540 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
541 myTable->hideColumn( COL_PUBLISHED );
542 myTable->hideColumn( COL_SHAPEID );
543 myTable->hideColumn( COL_BAD_MESH );
544 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
547 headers << tr( "COL_ALGO_HEADER" );
548 headers << tr( "COL_SHAPE_HEADER" );
549 headers << tr( "COL_ERROR_HEADER" );
550 headers << tr( "COL_SHAPEID_HEADER" );
551 headers << tr( "COL_PUBLISHED_HEADER" );
553 myTable->setHorizontalHeaderLabels( headers );
556 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
557 grpLayout->setSpacing(SPACING);
558 grpLayout->setMargin(MARGIN);
559 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
560 grpLayout->addWidget( myShowBtn, 0, 1 );
561 grpLayout->addWidget( myPublishBtn, 1, 1 );
562 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
563 grpLayout->setRowStretch( 3, 1 );
565 // Hypothesis definition errors
567 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
568 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
569 myHypErrorGroupLayout->setMargin(MARGIN);
570 myHypErrorGroupLayout->setSpacing(SPACING);
571 myHypErrorLabel = new QLabel(myHypErrorGroup);
572 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
576 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
577 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
578 myMemoryLackGroupLayout->setMargin(MARGIN);
579 myMemoryLackGroupLayout->setSpacing(SPACING);
580 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
581 QFont bold = memLackLabel->font(); bold.setBold(true);
582 memLackLabel->setFont( bold );
583 memLackLabel->setMinimumWidth(300);
584 myMemoryLackGroupLayout->addWidget(memLackLabel);
586 // add all widgets to aFrame
587 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
588 aLay->setMargin( 0 );
589 aLay->setSpacing( 0 );
590 aLay->addWidget( aPixGrp );
591 aLay->addWidget( nameBox );
592 aLay->addWidget( myBriefInfo );
593 aLay->addWidget( myFullInfo );
594 aLay->addWidget( myHypErrorGroup );
595 aLay->addWidget( myCompErrorGroup );
596 aLay->addWidget( myMemoryLackGroup );
597 aLay->setStretchFactor( myCompErrorGroup, 1 );
599 ((QPushButton*) button( OK ))->setDefault( true );
604 //================================================================================
608 //================================================================================
610 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
611 : SMESHGUI_Operation(), myCompDlg( 0 )
613 myTShapeDisplayer = new SMESH::TShapeDisplayer();
614 myBadMeshDisplayer = 0;
616 //myHelpFileName = "/files/about_meshes.htm"; // V3
617 myHelpFileName = "about_meshes_page.html"; // V4
620 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
622 LightApp_SelectionMgr* Sel = selectionMgr();
623 SALOME_ListIO selected; Sel->selectedObjects( selected );
624 Handle(SALOME_InteractiveObject) anIO = selected.First();
625 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
626 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
629 //================================================================================
631 * \brief Start operation
632 * \purpose Init dialog fields, connect signals and slots, show dialog
634 //================================================================================
636 void SMESHGUI_BaseComputeOp::startOperation()
638 // create compute dialog if not created before
641 myMesh = SMESH::SMESH_Mesh::_nil();
642 myMainShape = GEOM::GEOM_Object::_nil();
645 LightApp_SelectionMgr *Sel = selectionMgr();
646 SALOME_ListIO selected; Sel->selectedObjects( selected );
648 int nbSel = selected.Extent();
650 SUIT_MessageBox::warning(desktop(),
651 tr("SMESH_WRN_WARNING"),
652 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
657 myIObject = selected.First();
658 myMesh = SMESH::GetMeshByIO(myIObject);
659 if (myMesh->_is_nil()) {
660 SUIT_MessageBox::warning(desktop(),
661 tr("SMESH_WRN_WARNING"),
662 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
666 myMainShape = myMesh->GetShapeToMesh();
668 SMESHGUI_Operation::startOperation();
671 //================================================================================
673 * \brief computeMesh()
675 //================================================================================
677 void SMESHGUI_BaseComputeOp::computeMesh()
681 SMESH::MemoryReserve aMemoryReserve;
683 SMESH::compute_error_array_var aCompErrors;
686 bool computeFailed = true, memoryLack = false;
688 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
689 if ( !aMeshSObj ) // IPAL 21340
691 bool hasShape = myMesh->HasShapeToMesh();
692 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
695 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
696 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
697 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
698 if ( errors->length() > 0 ) {
699 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
701 SUIT_OverrideCursor aWaitCursor;
703 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
706 if (gen->Compute(myMesh, myMainShape))
707 computeFailed = false;
709 catch(const SALOME::SALOME_Exception & S_ex){
713 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
716 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
717 // check if there are memory problems
718 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
719 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
721 catch(const SALOME::SALOME_Exception & S_ex){
725 // NPAL16631: if ( !memoryLack )
727 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
728 update( UF_ObjBrowser | UF_Model );
731 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
732 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
735 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
738 SMESH::Update(myIObject, true);
742 MESSAGE ( "Exception thrown during mesh visualization" );
744 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
745 SMESH::OnVisuException();
752 LightApp_SelectionMgr *Sel = selectionMgr();
755 SALOME_ListIO selected;
756 selected.Append( myIObject );
757 Sel->setSelectedObjects( selected );
763 aMemoryReserve.release();
765 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
769 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
770 bool noHypoError = ( aHypErrors.isEmpty() );
772 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
773 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
775 bool isShowResultDlg = true;
776 switch( aNotifyMode ) {
777 case 0: // show the mesh computation result dialog NEVER
778 isShowResultDlg = false;
781 case 1: // show the mesh computation result dialog if there are some errors
782 if ( memoryLack || !noCompError || !noHypoError )
783 isShowResultDlg = true;
786 isShowResultDlg = false;
790 default: // show the result dialog after each mesh computation
791 isShowResultDlg = true;
795 if ( isShowResultDlg )
796 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
799 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
800 const bool theNoCompError,
801 SMESH::compute_error_array_var& theCompErrors,
802 const bool theNoHypoError,
803 const QString& theHypErrors )
805 bool hasShape = myMesh->HasShapeToMesh();
806 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
807 aCompDlg->myMemoryLackGroup->hide();
811 aCompDlg->myMemoryLackGroup->show();
812 aCompDlg->myFullInfo->hide();
813 aCompDlg->myBriefInfo->hide();
814 aCompDlg->myHypErrorGroup->hide();
815 aCompDlg->myCompErrorGroup->hide();
817 else if ( theNoCompError && theNoHypoError )
819 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
820 aCompDlg->myFullInfo->SetMeshInfo( aRes );
821 aCompDlg->myFullInfo->show();
822 aCompDlg->myBriefInfo->hide();
823 aCompDlg->myHypErrorGroup->hide();
824 aCompDlg->myCompErrorGroup->hide();
828 QTableWidget* tbl = aCompDlg->myTable;
829 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
830 aCompDlg->myFullInfo->SetMeshInfo( aRes );
831 aCompDlg->myBriefInfo->show();
832 aCompDlg->myFullInfo->hide();
834 if ( theNoHypoError ) {
835 aCompDlg->myHypErrorGroup->hide();
838 aCompDlg->myHypErrorGroup->show();
839 aCompDlg->myHypErrorLabel->setText( theHypErrors );
842 if ( theNoCompError ) {
843 aCompDlg->myCompErrorGroup->hide();
846 aCompDlg->myCompErrorGroup->show();
849 aCompDlg->myPublishBtn->hide();
850 aCompDlg->myShowBtn->hide();
853 aCompDlg->myPublishBtn->show();
854 aCompDlg->myShowBtn->show();
857 // fill table of errors
858 tbl->setRowCount( theCompErrors->length() );
859 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
860 else tbl->showColumn( COL_SHAPE );
861 tbl->setColumnWidth( COL_ERROR, 200 );
863 bool hasBadMesh = false;
864 for ( int row = 0; row < theCompErrors->length(); ++row )
866 SMESH::ComputeError & err = theCompErrors[ row ];
868 QString text = err.algoName.in();
869 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
870 else tbl->item( row, COL_ALGO )->setText( text );
872 text = SMESH::errorText( err.code, err.comment.in() );
873 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
874 else tbl->item( row, COL_ERROR )->setText( text );
876 text = QString("%1").arg( err.subShapeID );
877 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
878 else tbl->item( row, COL_SHAPEID )->setText( text );
880 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
881 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
882 else tbl->item( row, COL_SHAPE )->setText( text );
884 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
885 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
886 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
888 text = err.hasBadMesh ? "hasBadMesh" : "";
889 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
890 else tbl->item( row, COL_BAD_MESH )->setText( text );
891 if ( err.hasBadMesh ) hasBadMesh = true;
893 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
894 tbl->resizeRowToContents( row );
896 tbl->resizeColumnToContents( COL_ALGO );
897 tbl->resizeColumnToContents( COL_SHAPE );
900 aCompDlg->myBadMeshBtn->show();
902 aCompDlg->myBadMeshBtn->hide();
904 tbl->setCurrentCell(0,0);
905 currentCellChanged(); // to update buttons
908 // show dialog and wait, becase Compute can be invoked from Preview operation
909 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
913 //================================================================================
915 * \brief Stops operation
917 //================================================================================
919 void SMESHGUI_BaseComputeOp::stopOperation()
921 SMESHGUI_Operation::stopOperation();
922 if ( myTShapeDisplayer )
923 myTShapeDisplayer->SetVisibility( false );
924 if ( myBadMeshDisplayer ) {
925 myBadMeshDisplayer->SetVisibility( false );
926 // delete it in order not to have problems at its destruction when the viewer
927 // where it worked is dead due to e.g. study closing
928 delete myBadMeshDisplayer;
929 myBadMeshDisplayer = 0;
934 //================================================================================
936 * \brief publish selected subshape
938 //================================================================================
940 void SMESHGUI_BaseComputeOp::onPublishShape()
942 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
943 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
946 SMESH::getSelectedRows( table(), rows );
948 foreach ( row, rows )
950 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
951 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
952 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
954 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
956 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
957 SALOMEDS::SObject_var so =
958 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
959 // look for myMainShape in the table
960 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
961 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
962 if ( so->_is_nil() ) {
963 table()->item( r, COL_SHAPE )->setText( so->GetName() );
964 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
969 if ( curSub == 1 ) continue;
971 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
972 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
973 if ( !so->_is_nil() ) {
974 table()->item( row, COL_SHAPE )->setText( so->GetName() );
975 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
979 getSMESHGUI()->getApp()->updateObjectBrowser();
980 currentCellChanged(); // to update buttons
983 //================================================================================
985 * \brief show mesh elements preventing computation of a submesh of current row
987 //================================================================================
989 void SMESHGUI_BaseComputeOp::onShowBadMesh()
991 myTShapeDisplayer->SetVisibility( false );
993 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
994 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
996 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
997 SMESHGUI* gui = getSMESHGUI();
998 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
999 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1000 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1001 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1002 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1003 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1004 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1005 // delete property !!!!!!!!!!
1006 vtkProperty* prop = vtkProperty::New();
1007 prop->SetLineWidth( aLineWidth * 3 );
1008 prop->SetPointSize( aPointSize * 3 );
1009 prop->SetColor( 250, 0, 250 );
1010 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1011 myBadMeshDisplayer->SetData( aMeshData._retn() );
1016 //================================================================================
1018 * \brief SLOT called when a selected cell in table() changed
1020 //================================================================================
1022 void SMESHGUI_BaseComputeOp::currentCellChanged()
1024 myTShapeDisplayer->SetVisibility( false );
1025 if ( myBadMeshDisplayer )
1026 myBadMeshDisplayer->SetVisibility( false );
1028 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1030 int nbSelected = SMESH::getSelectedRows( table(), rows );
1032 foreach ( row, rows )
1034 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1035 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1036 if ( hasData && !isPublished )
1037 publishEnable = true;
1039 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1040 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1042 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1049 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1052 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1053 myCompDlg->myShowBtn ->setEnabled( showEnable );
1054 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1057 //================================================================================
1059 * \brief update preview
1061 //================================================================================
1063 void SMESHGUI_BaseComputeOp::onPreviewShape()
1065 if ( myTShapeDisplayer )
1067 SUIT_OverrideCursor aWaitCursor;
1069 SMESH::getSelectedRows( table(), rows );
1071 bool showOnly = true;
1073 foreach ( row, rows )
1075 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1077 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1081 currentCellChanged(); // to update buttons
1085 //================================================================================
1089 //================================================================================
1091 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1095 delete myTShapeDisplayer;
1096 if ( myBadMeshDisplayer )
1097 delete myBadMeshDisplayer;
1100 //================================================================================
1102 * \brief Gets dialog of compute operation
1103 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1105 //================================================================================
1107 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1111 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1112 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1113 // connect signals and slots
1114 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1115 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1116 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1118 QTableWidget* aTable = me->table();
1119 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1120 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1125 //================================================================================
1127 * \brief returns from compute mesh result dialog
1129 //================================================================================
1131 bool SMESHGUI_BaseComputeOp::onApply()
1136 //================================================================================
1138 * \brief Return a table
1140 //================================================================================
1142 QTableWidget* SMESHGUI_BaseComputeOp::table()
1144 return myCompDlg->myTable;
1148 //================================================================================
1150 * \brief Constructor
1152 //================================================================================
1154 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1155 : SMESHGUI_BaseComputeOp()
1160 //================================================================================
1162 * \brief Desctructor
1164 //================================================================================
1166 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1170 //================================================================================
1172 * \brief perform it's intention action: compute mesh
1174 //================================================================================
1176 void SMESHGUI_ComputeOp::startOperation()
1178 SMESHGUI_BaseComputeOp::startOperation();
1179 if (myMesh->_is_nil())
1184 //================================================================================
1186 * \brief check the same operations on the same mesh
1188 //================================================================================
1190 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1192 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1194 if ( !myMesh->_is_nil() && baseOp ) {
1195 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1196 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1201 //================================================================================
1203 * \brief Gets dialog of this operation
1204 * \retval LightApp_Dialog* - pointer to dialog of this operation
1206 //================================================================================
1208 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1210 return computeDlg();
1213 //================================================================================
1215 * \brief Constructor
1217 //================================================================================
1219 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1220 : SMESHGUI_BaseComputeOp(),
1224 myPreviewDisplayer( 0 )
1226 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1229 //================================================================================
1233 //================================================================================
1235 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1242 if ( myPreviewDisplayer )
1243 delete myPreviewDisplayer;
1244 myPreviewDisplayer = 0;
1247 //================================================================================
1249 * \brief Gets current dialog of this operation
1250 * \retval LightApp_Dialog* - pointer to dialog of this operation
1252 //================================================================================
1254 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1259 //================================================================================
1261 * \brief perform it's intention action: prepare data
1263 //================================================================================
1265 void SMESHGUI_PrecomputeOp::startOperation()
1269 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1272 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1273 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1274 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1276 myActiveDlg = myDlg;
1278 // connect signal to compute dialog. which will be shown after Compute mesh operation
1279 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1282 // disconnect signals
1283 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1284 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1285 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1286 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1287 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1290 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1291 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1292 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1293 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1294 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1295 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1296 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1297 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1298 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1299 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1302 SMESHGUI_BaseComputeOp::startOperation();
1303 if (myMesh->_is_nil())
1306 if (myDlg->getPreviewMode() == -1)
1308 // nothing to preview
1309 SUIT_MessageBox::warning(desktop(),
1310 tr("SMESH_WRN_WARNING"),
1311 tr("SMESH_WRN_NOTHING_PREVIEW"));
1316 // disconnect slot from preview dialog to have Apply from results of compute operation only
1317 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1318 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1323 //================================================================================
1325 * \brief Stops operation
1327 //================================================================================
1329 void SMESHGUI_PrecomputeOp::stopOperation()
1331 if ( myPreviewDisplayer )
1333 myPreviewDisplayer->SetVisibility( false );
1334 delete myPreviewDisplayer;
1335 myPreviewDisplayer = 0;
1337 myMapShapeId.clear();
1338 SMESHGUI_BaseComputeOp::stopOperation();
1341 //================================================================================
1343 * \brief reinitialize dialog after operaiton become active again
1345 //================================================================================
1347 void SMESHGUI_PrecomputeOp::resumeOperation()
1349 if ( myActiveDlg == myDlg )
1351 SMESHGUI_BaseComputeOp::resumeOperation();
1354 //================================================================================
1356 * \brief perform it's intention action: reinitialise dialog
1358 //================================================================================
1360 void SMESHGUI_PrecomputeOp::initDialog()
1364 QMap<int, int> modeMap;
1365 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1366 getAssignedAlgos( pMesh, modeMap );
1367 if ( modeMap.contains( SMESH::DIM_3D ) )
1369 if ( modeMap.contains( SMESH::DIM_2D ) )
1370 modes.append( SMESH::DIM_2D );
1371 if ( modeMap.contains( SMESH::DIM_1D ) )
1372 modes.append( SMESH::DIM_1D );
1374 else if ( modeMap.contains( SMESH::DIM_2D ) )
1376 if ( modeMap.contains( SMESH::DIM_1D ) )
1377 modes.append( SMESH::DIM_1D );
1380 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1381 myOrderMgr->SetMesh( myMesh );
1382 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1383 myDlg->getMeshOrderBox()->setShown(isOrder);
1389 myDlg->setPreviewModes( modes );
1392 //================================================================================
1394 * \brief detect asigned mesh algorithms
1396 //================================================================================
1398 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1399 QMap<int,int>& theModeMap)
1401 _PTR(SObject) aHypRoot;
1402 _PTR(GenericAttribute) anAttr;
1403 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1404 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1406 _PTR(ChildIterator) anIter =
1407 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1408 for ( ; anIter->More(); anIter->Next() )
1410 _PTR(SObject) anObj = anIter->Value();
1411 _PTR(SObject) aRefObj;
1412 if ( anObj->ReferencedObject( aRefObj ) )
1417 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1419 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1420 if ( CORBA::is_nil( aVar ) )
1423 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1425 SMESH::SMESH_Algo_var algo;
1427 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1428 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1429 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1432 if ( !algo->_is_nil() )
1433 theModeMap[ dim ] = 0;
1440 //================================================================================
1442 * \brief perform it's intention action: compute mesh
1444 //================================================================================
1446 void SMESHGUI_PrecomputeOp::onCompute()
1449 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1450 myOrderMgr->SetMeshOrder();
1451 myMapShapeId.clear();
1452 myActiveDlg = computeDlg();
1456 //================================================================================
1458 * \brief perform it's intention action: compute mesh
1460 //================================================================================
1462 void SMESHGUI_PrecomputeOp::onCancel()
1464 QObject* curDlg = sender();
1465 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1467 // return from error messages
1472 bool isRestoreOrder = false;
1473 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1475 // ask to remove already computed mesh elements
1476 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1477 tr( "CLEAR_SUBMESH_QUESTION" ),
1478 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1480 // remove all submeshes for collected shapes
1481 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1482 for ( ; it != myMapShapeId.constEnd(); ++it )
1483 myMesh->ClearSubMesh( *it );
1484 isRestoreOrder = true;
1488 // return previous mesh order
1489 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1490 if (!isRestoreOrder)
1492 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1493 tr( "SMESH_REJECT_MESH_ORDER" ),
1494 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1496 myOrderMgr->SetMeshOrder(myPrevOrder);
1502 myMapShapeId.clear();
1503 SMESHGUI_BaseComputeOp::onCancel();
1506 //================================================================================
1508 * \brief perform it's intention action: preview mesh
1510 //================================================================================
1512 void SMESHGUI_PrecomputeOp::onPreview()
1514 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1517 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1521 // set modified submesh priority if any
1522 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1523 myOrderMgr->SetMeshOrder();
1525 // Compute preview of mesh,
1526 // i.e. compute mesh till indicated dimension
1527 int dim = myDlg->getPreviewMode();
1529 SMESH::MemoryReserve aMemoryReserve;
1531 SMESH::compute_error_array_var aCompErrors;
1534 bool computeFailed = true, memoryLack = false;
1536 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1537 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1539 SMESHGUI* gui = getSMESHGUI();
1540 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1541 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1542 if ( errors->length() > 0 ) {
1543 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1546 SUIT_OverrideCursor aWaitCursor;
1548 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1549 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1550 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1552 SMESH::long_array_var aShapesId = new SMESH::long_array();
1554 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1558 SMESH::MeshPreviewStruct_var previewData =
1559 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1560 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1561 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1563 computeFailed = false;
1564 myPreviewDisplayer->SetData( previewRes );
1565 // append shape indeces with computed mesh entities
1566 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1567 myMapShapeId[ aShapesId[ i ] ] = 0;
1570 myPreviewDisplayer->SetVisibility(false);
1572 catch(const SALOME::SALOME_Exception & S_ex){
1574 myPreviewDisplayer->SetVisibility(false);
1578 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1581 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1582 // check if there are memory problems
1583 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1584 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1586 catch(const SALOME::SALOME_Exception & S_ex){
1591 aMemoryReserve.release();
1593 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1594 bool noHypoError = ( aHypErrors.isEmpty() );
1596 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1597 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1599 bool isShowError = true;
1600 switch( aNotifyMode ) {
1601 case 0: // show the mesh computation result dialog NEVER
1602 isShowError = false;
1604 case 1: // show the mesh computation result dialog if there are some errors
1605 default: // show the result dialog after each mesh computation
1606 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1607 isShowError = false;
1611 aWaitCursor.suspend();
1616 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1617 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1622 //================================================================================
1624 * \brief Constructor
1626 //================================================================================
1628 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1629 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1632 setWindowTitle( tr( "CAPTION" ) );
1634 setButtonText( OK, tr( "COMPUTE" ) );
1635 QFrame* main = mainFrame();
1637 QVBoxLayout* layout = new QVBoxLayout( main );
1639 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1640 layout->addWidget(myOrderBox);
1642 QFrame* frame = new QFrame( main );
1643 layout->setMargin(0); layout->setSpacing(0);
1644 layout->addWidget( frame );
1646 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1647 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1649 myPreviewMode = new QtxComboBox( frame );
1650 frameLay->addWidget( myPreviewMode );
1652 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1653 frameLay->addWidget( myPreviewBtn );
1655 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1658 //================================================================================
1662 //================================================================================
1664 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1668 //================================================================================
1670 * \brief Sets available preview modes
1672 //================================================================================
1674 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1676 myPreviewMode->clear();
1677 QList<int>::const_iterator it = theModes.constBegin();
1678 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1680 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1681 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1682 myPreviewMode->setId( i, *it );
1684 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1687 //================================================================================
1689 * \brief Returns current preview mesh mode
1691 //================================================================================
1693 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1695 return myPreviewMode->currentId();
1698 //================================================================================
1700 * \brief Returns current preview mesh mode
1702 //================================================================================
1704 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1710 //================================================================================
1712 * \brief Constructor
1714 //================================================================================
1716 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1717 : SMESHGUI_BaseComputeOp()
1722 //================================================================================
1724 * \brief Desctructor
1726 //================================================================================
1728 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1732 //================================================================================
1734 * \brief perform it's intention action: compute mesh
1736 //================================================================================
1738 void SMESHGUI_EvaluateOp::startOperation()
1740 SMESHGUI_BaseComputeOp::evaluateDlg();
1741 SMESHGUI_BaseComputeOp::startOperation();
1742 if (myMesh->_is_nil())
1747 //================================================================================
1749 * \brief Gets dialog of this operation
1750 * \retval LightApp_Dialog* - pointer to dialog of this operation
1752 //================================================================================
1754 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1756 return evaluateDlg();
1759 //================================================================================
1761 * \brief evaluateMesh()
1763 //================================================================================
1765 void SMESHGUI_BaseComputeOp::evaluateMesh()
1769 SMESH::MemoryReserve aMemoryReserve;
1771 SMESH::compute_error_array_var aCompErrors;
1774 bool evaluateFailed = true, memoryLack = false;
1775 SMESH::long_array_var aRes;
1777 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1778 if ( !aMeshSObj ) // IPAL21340
1781 bool hasShape = myMesh->HasShapeToMesh();
1782 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1785 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1786 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1787 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1788 if ( errors->length() > 0 ) {
1789 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1791 SUIT_OverrideCursor aWaitCursor;
1793 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1796 aRes = gen->Evaluate(myMesh, myMainShape);
1798 catch(const SALOME::SALOME_Exception & S_ex){
1803 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1806 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1808 catch(const SALOME::SALOME_Exception & S_ex){
1814 aMemoryReserve.release();
1816 evaluateFailed = ( aCompErrors->length() > 0 );
1817 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1821 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1822 bool noHypoError = ( aHypErrors.isEmpty() );
1824 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1825 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1827 bool isShowResultDlg = true;
1829 //switch( aNotifyMode ) {
1830 //case 0: // show the mesh computation result dialog NEVER
1831 //isShowResultDlg = false;
1834 //case 1: // show the mesh computation result dialog if there are some errors
1835 //if ( memoryLack || !noHypoError )
1836 // isShowResultDlg = true;
1839 // isShowResultDlg = false;
1843 //default: // show the result dialog after each mesh computation
1844 //isShowResultDlg = true;
1848 if ( isShowResultDlg )
1849 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1850 noHypoError, aHypErrors);
1854 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1855 const bool theMemoryLack,
1856 const bool theNoCompError,
1857 SMESH::compute_error_array_var& theCompErrors,
1858 const bool theNoHypoError,
1859 const QString& theHypErrors)
1861 bool hasShape = myMesh->HasShapeToMesh();
1862 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1863 aCompDlg->myMemoryLackGroup->hide();
1865 if ( theMemoryLack )
1867 aCompDlg->myMemoryLackGroup->show();
1868 aCompDlg->myFullInfo->hide();
1869 aCompDlg->myBriefInfo->hide();
1870 aCompDlg->myHypErrorGroup->hide();
1871 aCompDlg->myCompErrorGroup->hide();
1873 else if ( theNoCompError && theNoHypoError )
1875 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1876 aCompDlg->myFullInfo->show();
1877 aCompDlg->myBriefInfo->hide();
1878 aCompDlg->myHypErrorGroup->hide();
1879 aCompDlg->myCompErrorGroup->hide();
1883 QTableWidget* tbl = aCompDlg->myTable;
1884 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1885 aCompDlg->myBriefInfo->show();
1886 aCompDlg->myFullInfo->hide();
1888 if ( theNoHypoError ) {
1889 aCompDlg->myHypErrorGroup->hide();
1892 aCompDlg->myHypErrorGroup->show();
1893 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1896 if ( theNoCompError ) {
1897 aCompDlg->myCompErrorGroup->hide();
1900 aCompDlg->myCompErrorGroup->show();
1902 aCompDlg->myPublishBtn->hide();
1903 aCompDlg->myShowBtn->hide();
1905 // fill table of errors
1906 tbl->setRowCount( theCompErrors->length() );
1907 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1908 else tbl->showColumn( COL_SHAPE );
1909 tbl->setColumnWidth( COL_ERROR, 200 );
1911 bool hasBadMesh = false;
1912 for ( int row = 0; row < theCompErrors->length(); ++row )
1914 SMESH::ComputeError & err = theCompErrors[ row ];
1916 QString text = err.algoName.in();
1917 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1918 else tbl->item( row, COL_ALGO )->setText( text );
1920 text = SMESH::errorText( err.code, err.comment.in() );
1921 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1922 else tbl->item( row, COL_ERROR )->setText( text );
1924 text = QString("%1").arg( err.subShapeID );
1925 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1926 else tbl->item( row, COL_SHAPEID )->setText( text );
1928 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1929 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1930 else tbl->item( row, COL_SHAPE )->setText( text );
1932 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1933 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1934 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1936 text = err.hasBadMesh ? "hasBadMesh" : "";
1937 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1938 else tbl->item( row, COL_BAD_MESH )->setText( text );
1939 if ( err.hasBadMesh ) hasBadMesh = true;
1941 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1942 tbl->resizeRowToContents( row );
1944 tbl->resizeColumnToContents( COL_ALGO );
1945 tbl->resizeColumnToContents( COL_SHAPE );
1948 aCompDlg->myBadMeshBtn->show();
1950 aCompDlg->myBadMeshBtn->hide();
1952 tbl->setCurrentCell(0,0);
1953 currentCellChanged(); // to update buttons
1956 // show dialog and wait, becase Compute can be invoked from Preview operation
1957 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1962 //================================================================================
1964 * \brief Gets dialog of evaluate operation
1965 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1967 //================================================================================
1969 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1973 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1974 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1975 // connect signals and slots
1976 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1977 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1978 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1979 QTableWidget* aTable = me->table();
1980 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1981 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));