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) + " :" )
102 static void addSeparator( QWidget* parent )
104 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
105 int row = l->rowCount();
106 int cols = l->columnCount();
107 for ( int i = 0; i < cols; i++ ) {
108 QFrame* hline = new QFrame( parent );
109 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
110 l->addWidget( hline, row, i );
116 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
119 //using namespace SMESH;
123 //=============================================================================
125 * \brief Allocate some memory at construction and release it at destruction.
126 * Is used to be able to continue working after mesh generation or visualization
127 * break due to lack of memory
129 //=============================================================================
134 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
135 void release() { delete [] myBuf; myBuf = 0; }
136 ~MemoryReserve() { release(); }
139 // =========================================================================================
141 * \brief Class showing shapes without publishing
143 // =========================================================================================
145 class TShapeDisplayer
148 // -----------------------------------------------------------------------
149 TShapeDisplayer(): myViewWindow(0)
151 myProperty = vtkProperty::New();
152 myProperty->SetRepresentationToWireframe();
153 myProperty->SetColor( 250, 0, 250 );
154 myProperty->SetAmbientColor( 250, 0, 250 );
155 myProperty->SetDiffuseColor( 250, 0, 250 );
156 //myProperty->SetSpecularColor( 250, 0, 250 );
157 myProperty->SetLineWidth( 5 );
159 // -----------------------------------------------------------------------
163 myProperty->Delete();
165 // -----------------------------------------------------------------------
168 if ( hasViewWindow() ) {
169 TActorIterator actorIt = actorIterator();
170 while ( actorIt.more() )
171 if (VTKViewer_Actor* anActor = actorIt.next()) {
172 myViewWindow->RemoveActor( anActor );
176 myIndexToShape.Clear();
178 myShownActors.clear();
181 // -----------------------------------------------------------------------
182 void SetVisibility (bool theVisibility)
184 TActorIterator actorIt = shownIterator();
185 while ( actorIt.more() )
186 if (VTKViewer_Actor* anActor = actorIt.next())
187 anActor->SetVisibility(theVisibility);
188 SMESH::RepaintCurrentView();
190 // -----------------------------------------------------------------------
191 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
193 std::string mainEntry;
194 if ( !aMainShape->_is_nil() )
195 mainEntry = aMainShape->GetStudyEntry();
196 return ( myMainEntry == mainEntry &&
197 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
199 // -----------------------------------------------------------------------
200 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
202 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
203 std::string mainEntry;
204 if ( !aMainShape->_is_nil() )
205 mainEntry = aMainShape->GetStudyEntry();
206 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
209 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
210 checkTriangulation( aShape );
211 TopExp::MapShapes(aShape, myIndexToShape);
212 myActors.resize( myIndexToShape.Extent(), 0 );
213 myShownActors.reserve( myIndexToShape.Extent() );
215 myMainEntry = mainEntry;
216 myViewWindow = aViewWindow;
218 if ( only ) { // hide shown actors
219 TActorIterator actorIt = shownIterator();
220 while ( actorIt.more() )
221 if (VTKViewer_Actor* anActor = actorIt.next())
222 anActor->SetVisibility(false);
223 myShownActors.clear();
225 // find actors to show
226 TopoDS_Shape aShape = myIndexToShape( subShapeID );
227 if ( !aShape.IsNull() ) {
228 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
229 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
230 //checkTriangulation( exp.Current() );
231 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
232 myShownActors.push_back( anActor );
234 if ( type == TopAbs_FACE ) {
235 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
236 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
237 if ( !BRep_Tool::Degenerated( edge ))
238 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
239 myShownActors.push_back( anActor );
243 myBuiltSubs.insert( subShapeID );
246 // -----------------------------------------------------------------------
250 typedef std::vector<GEOM_Actor*> TActorVec;
252 TActorVec myShownActors;
253 TopTools_IndexedMapOfShape myIndexToShape;
254 std::string myMainEntry;
255 SVTK_ViewWindow* myViewWindow;
256 vtkProperty* myProperty;
257 std::set<int> myBuiltSubs;
259 // -----------------------------------------------------------------------
260 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
261 TActorIterator actorIterator() {
262 return TActorIterator( myActors.begin(), myActors.end() );
264 TActorIterator shownIterator() {
265 return TActorIterator( myShownActors.begin(), myShownActors.end() );
267 // -----------------------------------------------------------------------
268 GEOM_Actor* getActor(const TopoDS_Shape& shape)
270 int index = myIndexToShape.FindIndex( shape ) - 1;
271 if ( index < 0 || index >= myActors.size() )
273 GEOM_Actor* & actor = myActors[ index ];
275 actor = GEOM_Actor::New();
277 actor->SetShape(shape,0,0);
278 actor->SetProperty(myProperty);
279 actor->SetShadingProperty(myProperty);
280 actor->SetWireframeProperty(myProperty);
281 actor->SetPreviewProperty(myProperty);
282 actor->PickableOff();
283 // if ( shape.ShapeType() == TopAbs_EDGE )
284 // actor->SubShapeOn();
285 myViewWindow->AddActor( actor );
290 // -----------------------------------------------------------------------
291 void checkTriangulation(const TopoDS_Shape& shape)
293 TopLoc_Location aLoc;
294 Standard_Boolean alreadymesh = Standard_True;
295 TopExp_Explorer ex(shape, TopAbs_FACE);
297 for ( ; ex.More(); ex.Next()) {
298 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
299 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
300 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
303 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
304 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
305 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
306 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
308 if (alreadymesh) return;
309 // Compute default deflection
311 BRepBndLib::Add(shape, B);
312 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
313 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
314 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
315 BRepMesh_IncrementalMesh MESH(shape,deflection);
317 // -----------------------------------------------------------------------
318 bool hasViewWindow() const
320 if ( !myViewWindow ) return false;
322 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
323 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
329 // =========================================================================================
331 * \brief Return text describing an error
333 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
334 QString errorText(int errCode, const char* comment)
338 CASE2TEXT( COMPERR_OK );
339 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
340 CASE2TEXT( COMPERR_STD_EXCEPTION );
341 CASE2TEXT( COMPERR_OCC_EXCEPTION );
342 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
343 CASE2TEXT( COMPERR_EXCEPTION );
344 CASE2TEXT( COMPERR_MEMORY_PB );
345 CASE2TEXT( COMPERR_BAD_SHAPE );
346 case SMESH::COMPERR_ALGO_FAILED:
347 if ( strlen(comment) == 0 )
348 text = QObject::tr("COMPERR_ALGO_FAILED");
351 text = QString("#%1").arg( -errCode );
353 if ( text.length() > 0 ) text += ". ";
354 return text + comment;
356 // -----------------------------------------------------------------------
358 * \brief Return SO of a subshape
360 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
362 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
363 if ( subShapeID == 1 || !so )
365 _PTR(ChildIterator) it;
366 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
367 it = study->NewChildIterator(so);
370 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
371 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
372 if ( !geom->_is_nil() ) {
373 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
374 if ( list->length() == 1 && list[0] == subShapeID )
381 // -----------------------------------------------------------------------
383 * \brief Return subshape by ID
385 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
387 GEOM::GEOM_Object_var aSubShape;
388 if ( subShapeID == 1 )
389 aSubShape = aMainShape;
390 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
391 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
393 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
394 return aSubShape._retn();
396 // -----------------------------------------------------------------------
398 * \brief Return shape type name
400 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
401 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
404 if ( !aShape->_is_nil() ) {
405 switch ( aShape->GetShapeType() ) {
412 CASE2NAME( COMPSOLID );
413 CASE2NAME( COMPOUND );
419 // -----------------------------------------------------------------------
421 * \brief Return text describing a subshape
423 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
426 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
427 text = aSO->GetName().c_str();
429 text = QString("#%1").arg( subShapeID );
430 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
431 if ( typeName.length() )
432 text += QString(" (%1)").arg(typeName);
436 // -----------------------------------------------------------------------
438 * \brief Return a list of selected rows
440 int getSelectedRows(QTableWidget* table, QList<int>& rows)
443 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
444 QTableWidgetSelectionRange range;
445 foreach( range, selRanges )
447 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
450 if ( rows.isEmpty() && table->currentRow() > -1 )
451 rows.append( table->currentRow() );
459 // =========================================================================================
461 * \brief Dialog to compute a mesh and show computation errors
463 //=======================================================================
465 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
466 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
468 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
469 aDlgLay->setMargin( 0 );
470 aDlgLay->setSpacing( SPACING );
472 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
474 aDlgLay->addWidget(aMainFrame);
476 aDlgLay->setStretchFactor(aMainFrame, 1);
479 // =========================================================================================
483 //=======================================================================
485 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
489 //=======================================================================
490 // function : createMainFrame()
491 // purpose : Create frame containing dialog's fields
492 //=======================================================================
494 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
496 QFrame* aFrame = new QFrame(theParent);
498 SUIT_ResourceMgr* rm = resourceMgr();
499 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
505 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
508 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
510 QButtonGroup* aBtnGrp = new QButtonGroup(this);
511 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
512 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
514 QRadioButton* aRBut = new QRadioButton(aPixGrp);
515 aRBut->setIcon(iconCompute);
516 aRBut->setChecked(true);
517 aPixGrpLayout->addWidget(aRBut);
518 aBtnGrp->addButton(aRBut, 0);
522 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
523 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
524 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
525 myMeshName = new QLabel(nameBox);
526 nameBoxLayout->addWidget(myMeshName);
530 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
531 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
533 // Computation errors
535 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
536 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
537 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
538 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
539 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
541 //myTable->setReadOnly( true ); // VSR: check
542 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
543 myTable->hideColumn( COL_PUBLISHED );
544 myTable->hideColumn( COL_SHAPEID );
545 myTable->hideColumn( COL_BAD_MESH );
546 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
549 headers << tr( "COL_ALGO_HEADER" );
550 headers << tr( "COL_SHAPE_HEADER" );
551 headers << tr( "COL_ERROR_HEADER" );
552 headers << tr( "COL_SHAPEID_HEADER" );
553 headers << tr( "COL_PUBLISHED_HEADER" );
555 myTable->setHorizontalHeaderLabels( headers );
558 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
559 grpLayout->setSpacing(SPACING);
560 grpLayout->setMargin(MARGIN);
561 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
562 grpLayout->addWidget( myShowBtn, 0, 1 );
563 grpLayout->addWidget( myPublishBtn, 1, 1 );
564 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
565 grpLayout->setRowStretch( 3, 1 );
567 // Hypothesis definition errors
569 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
570 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
571 myHypErrorGroupLayout->setMargin(MARGIN);
572 myHypErrorGroupLayout->setSpacing(SPACING);
573 myHypErrorLabel = new QLabel(myHypErrorGroup);
574 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
578 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
579 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
580 myMemoryLackGroupLayout->setMargin(MARGIN);
581 myMemoryLackGroupLayout->setSpacing(SPACING);
582 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
583 QFont bold = memLackLabel->font(); bold.setBold(true);
584 memLackLabel->setFont( bold );
585 memLackLabel->setMinimumWidth(300);
586 myMemoryLackGroupLayout->addWidget(memLackLabel);
588 // add all widgets to aFrame
589 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
590 aLay->setMargin( 0 );
591 aLay->setSpacing( 0 );
592 aLay->addWidget( aPixGrp );
593 aLay->addWidget( nameBox );
594 aLay->addWidget( myBriefInfo );
595 aLay->addWidget( myFullInfo );
596 aLay->addWidget( myHypErrorGroup );
597 aLay->addWidget( myCompErrorGroup );
598 aLay->addWidget( myMemoryLackGroup );
599 aLay->setStretchFactor( myCompErrorGroup, 1 );
601 ((QPushButton*) button( OK ))->setDefault( true );
606 //================================================================================
610 //================================================================================
612 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
613 : SMESHGUI_Operation(), myCompDlg( 0 )
615 myTShapeDisplayer = new SMESH::TShapeDisplayer();
616 myBadMeshDisplayer = 0;
618 //myHelpFileName = "/files/about_meshes.htm"; // V3
619 myHelpFileName = "about_meshes_page.html"; // V4
622 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
624 LightApp_SelectionMgr* Sel = selectionMgr();
625 SALOME_ListIO selected; Sel->selectedObjects( selected );
626 Handle(SALOME_InteractiveObject) anIO = selected.First();
627 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
628 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
631 //================================================================================
633 * \brief Start operation
634 * \purpose Init dialog fields, connect signals and slots, show dialog
636 //================================================================================
638 void SMESHGUI_BaseComputeOp::startOperation()
640 // create compute dialog if not created before
643 myMesh = SMESH::SMESH_Mesh::_nil();
644 myMainShape = GEOM::GEOM_Object::_nil();
647 LightApp_SelectionMgr *Sel = selectionMgr();
648 SALOME_ListIO selected; Sel->selectedObjects( selected );
650 int nbSel = selected.Extent();
652 SUIT_MessageBox::warning(desktop(),
653 tr("SMESH_WRN_WARNING"),
654 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
659 myIObject = selected.First();
660 myMesh = SMESH::GetMeshByIO(myIObject);
661 if (myMesh->_is_nil()) {
662 SUIT_MessageBox::warning(desktop(),
663 tr("SMESH_WRN_WARNING"),
664 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
668 myMainShape = myMesh->GetShapeToMesh();
670 SMESHGUI_Operation::startOperation();
673 //================================================================================
675 * \brief computeMesh()
677 //================================================================================
679 void SMESHGUI_BaseComputeOp::computeMesh()
683 SMESH::MemoryReserve aMemoryReserve;
685 SMESH::compute_error_array_var aCompErrors;
688 bool computeFailed = true, memoryLack = false;
690 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
691 if ( !aMeshSObj ) // IPAL 21340
693 bool hasShape = myMesh->HasShapeToMesh();
694 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
697 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
698 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
699 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
700 if ( errors->length() > 0 ) {
701 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
703 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
704 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
705 tr( "FULL_RECOMPUTE_QUESTION" ),
706 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
708 SUIT_OverrideCursor aWaitCursor;
710 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
713 if (gen->Compute(myMesh, myMainShape))
714 computeFailed = false;
716 catch(const SALOME::SALOME_Exception & S_ex){
720 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
723 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
724 // check if there are memory problems
725 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
726 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
728 catch(const SALOME::SALOME_Exception & S_ex){
732 // NPAL16631: if ( !memoryLack )
734 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
735 update( UF_ObjBrowser | UF_Model );
738 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
739 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
740 long newSize = myMesh->NbElements();
741 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
745 if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
748 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
751 SMESH::Update(myIObject, true);
755 MESSAGE ( "Exception thrown during mesh visualization" );
757 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
758 SMESH::OnVisuException();
765 else if ( limitExceeded )
767 SUIT_MessageBox::warning( desktop(),
768 tr( "SMESH_WRN_WARNING" ),
769 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
772 LightApp_SelectionMgr *Sel = selectionMgr();
775 SALOME_ListIO selected;
776 selected.Append( myIObject );
777 Sel->setSelectedObjects( selected );
783 aMemoryReserve.release();
785 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
789 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
790 bool noHypoError = ( aHypErrors.isEmpty() );
792 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
793 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
795 bool isShowResultDlg = true;
796 switch( aNotifyMode ) {
797 case 0: // show the mesh computation result dialog NEVER
798 isShowResultDlg = false;
801 case 1: // show the mesh computation result dialog if there are some errors
802 if ( memoryLack || !noCompError || !noHypoError )
803 isShowResultDlg = true;
806 isShowResultDlg = false;
810 default: // show the result dialog after each mesh computation
811 isShowResultDlg = true;
815 if ( isShowResultDlg )
816 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
819 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
820 const bool theNoCompError,
821 SMESH::compute_error_array_var& theCompErrors,
822 const bool theNoHypoError,
823 const QString& theHypErrors )
825 bool hasShape = myMesh->HasShapeToMesh();
826 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
827 aCompDlg->myMemoryLackGroup->hide();
831 aCompDlg->myMemoryLackGroup->show();
832 aCompDlg->myFullInfo->hide();
833 aCompDlg->myBriefInfo->hide();
834 aCompDlg->myHypErrorGroup->hide();
835 aCompDlg->myCompErrorGroup->hide();
837 else if ( theNoCompError && theNoHypoError )
839 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
840 aCompDlg->myFullInfo->SetMeshInfo( aRes );
841 aCompDlg->myFullInfo->show();
842 aCompDlg->myBriefInfo->hide();
843 aCompDlg->myHypErrorGroup->hide();
844 aCompDlg->myCompErrorGroup->hide();
848 QTableWidget* tbl = aCompDlg->myTable;
849 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
850 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
851 aCompDlg->myBriefInfo->show();
852 aCompDlg->myFullInfo->hide();
854 if ( theNoHypoError ) {
855 aCompDlg->myHypErrorGroup->hide();
858 aCompDlg->myHypErrorGroup->show();
859 aCompDlg->myHypErrorLabel->setText( theHypErrors );
862 if ( theNoCompError ) {
863 aCompDlg->myCompErrorGroup->hide();
866 aCompDlg->myCompErrorGroup->show();
869 aCompDlg->myPublishBtn->hide();
870 aCompDlg->myShowBtn->hide();
873 aCompDlg->myPublishBtn->show();
874 aCompDlg->myShowBtn->show();
877 // fill table of errors
878 tbl->setRowCount( theCompErrors->length() );
879 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
880 else tbl->showColumn( COL_SHAPE );
881 tbl->setColumnWidth( COL_ERROR, 200 );
883 bool hasBadMesh = false;
884 for ( int row = 0; row < theCompErrors->length(); ++row )
886 SMESH::ComputeError & err = theCompErrors[ row ];
888 QString text = err.algoName.in();
889 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
890 else tbl->item( row, COL_ALGO )->setText( text );
892 text = SMESH::errorText( err.code, err.comment.in() );
893 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
894 else tbl->item( row, COL_ERROR )->setText( text );
896 text = QString("%1").arg( err.subShapeID );
897 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
898 else tbl->item( row, COL_SHAPEID )->setText( text );
900 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
901 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
902 else tbl->item( row, COL_SHAPE )->setText( text );
904 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
905 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
906 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
908 text = err.hasBadMesh ? "hasBadMesh" : "";
909 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
910 else tbl->item( row, COL_BAD_MESH )->setText( text );
911 if ( err.hasBadMesh ) hasBadMesh = true;
913 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
914 tbl->resizeRowToContents( row );
916 tbl->resizeColumnToContents( COL_ALGO );
917 tbl->resizeColumnToContents( COL_SHAPE );
920 aCompDlg->myBadMeshBtn->show();
922 aCompDlg->myBadMeshBtn->hide();
924 tbl->setCurrentCell(0,0);
925 currentCellChanged(); // to update buttons
928 // show dialog and wait, becase Compute can be invoked from Preview operation
929 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
933 //================================================================================
935 * \brief Stops operation
937 //================================================================================
939 void SMESHGUI_BaseComputeOp::stopOperation()
941 SMESHGUI_Operation::stopOperation();
942 if ( myTShapeDisplayer )
943 myTShapeDisplayer->SetVisibility( false );
944 if ( myBadMeshDisplayer ) {
945 myBadMeshDisplayer->SetVisibility( false );
946 // delete it in order not to have problems at its destruction when the viewer
947 // where it worked is dead due to e.g. study closing
948 delete myBadMeshDisplayer;
949 myBadMeshDisplayer = 0;
954 //================================================================================
956 * \brief publish selected subshape
958 //================================================================================
960 void SMESHGUI_BaseComputeOp::onPublishShape()
962 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
963 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
966 SMESH::getSelectedRows( table(), rows );
968 foreach ( row, rows )
970 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
971 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
972 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
974 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
976 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
977 SALOMEDS::SObject_var so =
978 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
979 // look for myMainShape in the table
980 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
981 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
982 if ( so->_is_nil() ) {
983 table()->item( r, COL_SHAPE )->setText( so->GetName() );
984 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
989 if ( curSub == 1 ) continue;
991 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
992 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
993 if ( !so->_is_nil() ) {
994 table()->item( row, COL_SHAPE )->setText( so->GetName() );
995 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
999 getSMESHGUI()->getApp()->updateObjectBrowser();
1000 currentCellChanged(); // to update buttons
1003 //================================================================================
1005 * \brief show mesh elements preventing computation of a submesh of current row
1007 //================================================================================
1009 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1011 myTShapeDisplayer->SetVisibility( false );
1013 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1014 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1016 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1017 SMESHGUI* gui = getSMESHGUI();
1018 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1019 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1020 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1021 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1022 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1023 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1024 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1025 // delete property !!!!!!!!!!
1026 vtkProperty* prop = vtkProperty::New();
1027 prop->SetLineWidth( aLineWidth * 3 );
1028 prop->SetPointSize( aPointSize * 3 );
1029 prop->SetColor( 250, 0, 250 );
1030 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1031 myBadMeshDisplayer->SetData( aMeshData._retn() );
1036 //================================================================================
1038 * \brief SLOT called when a selected cell in table() changed
1040 //================================================================================
1042 void SMESHGUI_BaseComputeOp::currentCellChanged()
1044 myTShapeDisplayer->SetVisibility( false );
1045 if ( myBadMeshDisplayer )
1046 myBadMeshDisplayer->SetVisibility( false );
1048 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1050 int nbSelected = SMESH::getSelectedRows( table(), rows );
1052 foreach ( row, rows )
1054 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1055 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1056 if ( hasData && !isPublished )
1057 publishEnable = true;
1059 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1060 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1062 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1069 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1072 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1073 myCompDlg->myShowBtn ->setEnabled( showEnable );
1074 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1077 //================================================================================
1079 * \brief update preview
1081 //================================================================================
1083 void SMESHGUI_BaseComputeOp::onPreviewShape()
1085 if ( myTShapeDisplayer )
1087 SUIT_OverrideCursor aWaitCursor;
1089 SMESH::getSelectedRows( table(), rows );
1091 bool showOnly = true;
1093 foreach ( row, rows )
1095 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1097 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1101 currentCellChanged(); // to update buttons
1105 //================================================================================
1109 //================================================================================
1111 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1115 delete myTShapeDisplayer;
1116 if ( myBadMeshDisplayer )
1117 delete myBadMeshDisplayer;
1120 //================================================================================
1122 * \brief Gets dialog of compute operation
1123 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1125 //================================================================================
1127 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1131 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1132 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1133 // connect signals and slots
1134 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1135 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1136 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1138 QTableWidget* aTable = me->table();
1139 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1140 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1145 //================================================================================
1147 * \brief returns from compute mesh result dialog
1149 //================================================================================
1151 bool SMESHGUI_BaseComputeOp::onApply()
1156 //================================================================================
1158 * \brief Return a table
1160 //================================================================================
1162 QTableWidget* SMESHGUI_BaseComputeOp::table()
1164 return myCompDlg->myTable;
1168 //================================================================================
1170 * \brief Constructor
1172 //================================================================================
1174 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1175 : SMESHGUI_BaseComputeOp()
1180 //================================================================================
1182 * \brief Desctructor
1184 //================================================================================
1186 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1190 //================================================================================
1192 * \brief perform it's intention action: compute mesh
1194 //================================================================================
1196 void SMESHGUI_ComputeOp::startOperation()
1198 SMESHGUI_BaseComputeOp::startOperation();
1199 if (myMesh->_is_nil())
1204 //================================================================================
1206 * \brief check the same operations on the same mesh
1208 //================================================================================
1210 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1212 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1214 if ( !myMesh->_is_nil() && baseOp ) {
1215 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1216 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1221 //================================================================================
1223 * \brief Gets dialog of this operation
1224 * \retval LightApp_Dialog* - pointer to dialog of this operation
1226 //================================================================================
1228 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1230 return computeDlg();
1233 //================================================================================
1235 * \brief Constructor
1237 //================================================================================
1239 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1240 : SMESHGUI_BaseComputeOp(),
1244 myPreviewDisplayer( 0 )
1246 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1249 //================================================================================
1253 //================================================================================
1255 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1262 if ( myPreviewDisplayer )
1263 delete myPreviewDisplayer;
1264 myPreviewDisplayer = 0;
1267 //================================================================================
1269 * \brief Gets current dialog of this operation
1270 * \retval LightApp_Dialog* - pointer to dialog of this operation
1272 //================================================================================
1274 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1279 //================================================================================
1281 * \brief perform it's intention action: prepare data
1283 //================================================================================
1285 void SMESHGUI_PrecomputeOp::startOperation()
1289 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1292 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1293 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1294 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1296 myActiveDlg = myDlg;
1298 // connect signal to compute dialog. which will be shown after Compute mesh operation
1299 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1302 // disconnect signals
1303 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1304 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1305 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1306 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1307 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1310 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1311 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1312 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1313 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1314 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1315 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1316 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1317 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1318 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1319 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1322 SMESHGUI_BaseComputeOp::startOperation();
1323 if (myMesh->_is_nil())
1326 if (myDlg->getPreviewMode() == -1)
1328 // nothing to preview
1329 SUIT_MessageBox::warning(desktop(),
1330 tr("SMESH_WRN_WARNING"),
1331 tr("SMESH_WRN_NOTHING_PREVIEW"));
1336 // disconnect slot from preview dialog to have Apply from results of compute operation only
1337 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1338 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1343 //================================================================================
1345 * \brief Stops operation
1347 //================================================================================
1349 void SMESHGUI_PrecomputeOp::stopOperation()
1351 if ( myPreviewDisplayer )
1353 myPreviewDisplayer->SetVisibility( false );
1354 delete myPreviewDisplayer;
1355 myPreviewDisplayer = 0;
1357 myMapShapeId.clear();
1358 SMESHGUI_BaseComputeOp::stopOperation();
1361 //================================================================================
1363 * \brief reinitialize dialog after operaiton become active again
1365 //================================================================================
1367 void SMESHGUI_PrecomputeOp::resumeOperation()
1369 if ( myActiveDlg == myDlg )
1371 SMESHGUI_BaseComputeOp::resumeOperation();
1374 //================================================================================
1376 * \brief perform it's intention action: reinitialise dialog
1378 //================================================================================
1380 void SMESHGUI_PrecomputeOp::initDialog()
1384 QMap<int, int> modeMap;
1385 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1386 getAssignedAlgos( pMesh, modeMap );
1387 if ( modeMap.contains( SMESH::DIM_3D ) )
1389 if ( modeMap.contains( SMESH::DIM_2D ) )
1390 modes.append( SMESH::DIM_2D );
1391 if ( modeMap.contains( SMESH::DIM_1D ) )
1392 modes.append( SMESH::DIM_1D );
1394 else if ( modeMap.contains( SMESH::DIM_2D ) )
1396 if ( modeMap.contains( SMESH::DIM_1D ) )
1397 modes.append( SMESH::DIM_1D );
1400 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1401 myOrderMgr->SetMesh( myMesh );
1402 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1403 myDlg->getMeshOrderBox()->setShown(isOrder);
1409 myDlg->setPreviewModes( modes );
1412 //================================================================================
1414 * \brief detect asigned mesh algorithms
1416 //================================================================================
1418 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1419 QMap<int,int>& theModeMap)
1421 _PTR(SObject) aHypRoot;
1422 _PTR(GenericAttribute) anAttr;
1423 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1424 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1426 _PTR(ChildIterator) anIter =
1427 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1428 for ( ; anIter->More(); anIter->Next() )
1430 _PTR(SObject) anObj = anIter->Value();
1431 _PTR(SObject) aRefObj;
1432 if ( anObj->ReferencedObject( aRefObj ) )
1437 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1439 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1440 if ( CORBA::is_nil( aVar ) )
1443 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1445 SMESH::SMESH_Algo_var algo;
1447 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1448 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1449 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1452 if ( !algo->_is_nil() )
1453 theModeMap[ dim ] = 0;
1460 //================================================================================
1462 * \brief perform it's intention action: compute mesh
1464 //================================================================================
1466 void SMESHGUI_PrecomputeOp::onCompute()
1469 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1470 myOrderMgr->SetMeshOrder();
1471 myMapShapeId.clear();
1472 myActiveDlg = computeDlg();
1476 //================================================================================
1478 * \brief perform it's intention action: compute mesh
1480 //================================================================================
1482 void SMESHGUI_PrecomputeOp::onCancel()
1484 QObject* curDlg = sender();
1485 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1487 // return from error messages
1492 bool isRestoreOrder = false;
1493 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1495 // ask to remove already computed mesh elements
1496 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1497 tr( "CLEAR_SUBMESH_QUESTION" ),
1498 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1500 // remove all submeshes for collected shapes
1501 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1502 for ( ; it != myMapShapeId.constEnd(); ++it )
1503 myMesh->ClearSubMesh( *it );
1504 isRestoreOrder = true;
1508 // return previous mesh order
1509 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1510 if (!isRestoreOrder)
1512 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1513 tr( "SMESH_REJECT_MESH_ORDER" ),
1514 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1516 myOrderMgr->SetMeshOrder(myPrevOrder);
1522 myMapShapeId.clear();
1523 SMESHGUI_BaseComputeOp::onCancel();
1526 //================================================================================
1528 * \brief perform it's intention action: preview mesh
1530 //================================================================================
1532 void SMESHGUI_PrecomputeOp::onPreview()
1534 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1537 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1541 // set modified submesh priority if any
1542 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1543 myOrderMgr->SetMeshOrder();
1545 // Compute preview of mesh,
1546 // i.e. compute mesh till indicated dimension
1547 int dim = myDlg->getPreviewMode();
1549 SMESH::MemoryReserve aMemoryReserve;
1551 SMESH::compute_error_array_var aCompErrors;
1554 bool computeFailed = true, memoryLack = false;
1556 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1557 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1559 SMESHGUI* gui = getSMESHGUI();
1560 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1561 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1562 if ( errors->length() > 0 ) {
1563 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1566 SUIT_OverrideCursor aWaitCursor;
1568 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1569 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1570 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1572 SMESH::long_array_var aShapesId = new SMESH::long_array();
1574 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1578 SMESH::MeshPreviewStruct_var previewData =
1579 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1581 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1582 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1584 computeFailed = false;
1585 myPreviewDisplayer->SetData( previewRes );
1586 // append shape indeces with computed mesh entities
1587 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1588 myMapShapeId[ aShapesId[ i ] ] = 0;
1591 myPreviewDisplayer->SetVisibility(false);
1593 catch(const SALOME::SALOME_Exception & S_ex){
1595 myPreviewDisplayer->SetVisibility(false);
1599 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1602 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1603 // check if there are memory problems
1604 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1605 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1607 catch(const SALOME::SALOME_Exception & S_ex){
1612 aMemoryReserve.release();
1614 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1615 bool noHypoError = ( aHypErrors.isEmpty() );
1617 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1618 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1620 bool isShowError = true;
1621 switch( aNotifyMode ) {
1622 case 0: // show the mesh computation result dialog NEVER
1623 isShowError = false;
1625 case 1: // show the mesh computation result dialog if there are some errors
1626 default: // show the result dialog after each mesh computation
1627 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1628 isShowError = false;
1632 aWaitCursor.suspend();
1637 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1638 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1643 //================================================================================
1645 * \brief Constructor
1647 //================================================================================
1649 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1650 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1653 setWindowTitle( tr( "CAPTION" ) );
1655 setButtonText( OK, tr( "COMPUTE" ) );
1656 QFrame* main = mainFrame();
1658 QVBoxLayout* layout = new QVBoxLayout( main );
1660 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1661 layout->addWidget(myOrderBox);
1663 QFrame* frame = new QFrame( main );
1664 layout->setMargin(0); layout->setSpacing(0);
1665 layout->addWidget( frame );
1667 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1668 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1670 myPreviewMode = new QtxComboBox( frame );
1671 frameLay->addWidget( myPreviewMode );
1673 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1674 frameLay->addWidget( myPreviewBtn );
1676 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1679 //================================================================================
1683 //================================================================================
1685 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1689 //================================================================================
1691 * \brief Sets available preview modes
1693 //================================================================================
1695 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1697 myPreviewMode->clear();
1698 QList<int>::const_iterator it = theModes.constBegin();
1699 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1701 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1702 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1703 myPreviewMode->setId( i, *it );
1705 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1708 //================================================================================
1710 * \brief Returns current preview mesh mode
1712 //================================================================================
1714 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1716 return myPreviewMode->currentId();
1719 //================================================================================
1721 * \brief Returns current preview mesh mode
1723 //================================================================================
1725 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1731 //================================================================================
1733 * \brief Constructor
1735 //================================================================================
1737 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1738 : SMESHGUI_BaseComputeOp()
1743 //================================================================================
1745 * \brief Desctructor
1747 //================================================================================
1749 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1753 //================================================================================
1755 * \brief perform it's intention action: compute mesh
1757 //================================================================================
1759 void SMESHGUI_EvaluateOp::startOperation()
1761 SMESHGUI_BaseComputeOp::evaluateDlg();
1762 SMESHGUI_BaseComputeOp::startOperation();
1763 if (myMesh->_is_nil())
1768 //================================================================================
1770 * \brief Gets dialog of this operation
1771 * \retval LightApp_Dialog* - pointer to dialog of this operation
1773 //================================================================================
1775 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1777 return evaluateDlg();
1780 //================================================================================
1782 * \brief evaluateMesh()
1784 //================================================================================
1786 void SMESHGUI_BaseComputeOp::evaluateMesh()
1790 SMESH::MemoryReserve aMemoryReserve;
1792 SMESH::compute_error_array_var aCompErrors;
1795 bool evaluateFailed = true, memoryLack = false;
1796 SMESH::long_array_var aRes;
1798 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1799 if ( !aMeshSObj ) // IPAL21340
1802 bool hasShape = myMesh->HasShapeToMesh();
1803 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1806 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1807 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1808 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1809 if ( errors->length() > 0 ) {
1810 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1812 SUIT_OverrideCursor aWaitCursor;
1814 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1817 aRes = gen->Evaluate(myMesh, myMainShape);
1819 catch(const SALOME::SALOME_Exception & S_ex){
1824 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1827 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1829 catch(const SALOME::SALOME_Exception & S_ex){
1835 aMemoryReserve.release();
1837 evaluateFailed = ( aCompErrors->length() > 0 );
1838 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1842 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1843 bool noHypoError = ( aHypErrors.isEmpty() );
1845 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1846 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1848 bool isShowResultDlg = true;
1850 //switch( aNotifyMode ) {
1851 //case 0: // show the mesh computation result dialog NEVER
1852 //isShowResultDlg = false;
1855 //case 1: // show the mesh computation result dialog if there are some errors
1856 //if ( memoryLack || !noHypoError )
1857 // isShowResultDlg = true;
1860 // isShowResultDlg = false;
1864 //default: // show the result dialog after each mesh computation
1865 //isShowResultDlg = true;
1869 if ( isShowResultDlg )
1870 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1871 noHypoError, aHypErrors);
1875 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1876 const bool theMemoryLack,
1877 const bool theNoCompError,
1878 SMESH::compute_error_array_var& theCompErrors,
1879 const bool theNoHypoError,
1880 const QString& theHypErrors)
1882 bool hasShape = myMesh->HasShapeToMesh();
1883 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1884 aCompDlg->myMemoryLackGroup->hide();
1886 if ( theMemoryLack )
1888 aCompDlg->myMemoryLackGroup->show();
1889 aCompDlg->myFullInfo->hide();
1890 aCompDlg->myBriefInfo->hide();
1891 aCompDlg->myHypErrorGroup->hide();
1892 aCompDlg->myCompErrorGroup->hide();
1894 else if ( theNoCompError && theNoHypoError )
1896 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1897 aCompDlg->myFullInfo->show();
1898 aCompDlg->myBriefInfo->hide();
1899 aCompDlg->myHypErrorGroup->hide();
1900 aCompDlg->myCompErrorGroup->hide();
1904 QTableWidget* tbl = aCompDlg->myTable;
1905 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1906 aCompDlg->myBriefInfo->show();
1907 aCompDlg->myFullInfo->hide();
1909 if ( theNoHypoError ) {
1910 aCompDlg->myHypErrorGroup->hide();
1913 aCompDlg->myHypErrorGroup->show();
1914 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1917 if ( theNoCompError ) {
1918 aCompDlg->myCompErrorGroup->hide();
1921 aCompDlg->myCompErrorGroup->show();
1923 aCompDlg->myPublishBtn->hide();
1924 aCompDlg->myShowBtn->hide();
1926 // fill table of errors
1927 tbl->setRowCount( theCompErrors->length() );
1928 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1929 else tbl->showColumn( COL_SHAPE );
1930 tbl->setColumnWidth( COL_ERROR, 200 );
1932 bool hasBadMesh = false;
1933 for ( int row = 0; row < theCompErrors->length(); ++row )
1935 SMESH::ComputeError & err = theCompErrors[ row ];
1937 QString text = err.algoName.in();
1938 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1939 else tbl->item( row, COL_ALGO )->setText( text );
1941 text = SMESH::errorText( err.code, err.comment.in() );
1942 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1943 else tbl->item( row, COL_ERROR )->setText( text );
1945 text = QString("%1").arg( err.subShapeID );
1946 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1947 else tbl->item( row, COL_SHAPEID )->setText( text );
1949 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1950 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1951 else tbl->item( row, COL_SHAPE )->setText( text );
1953 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1954 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1955 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1957 text = err.hasBadMesh ? "hasBadMesh" : "";
1958 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1959 else tbl->item( row, COL_BAD_MESH )->setText( text );
1960 if ( err.hasBadMesh ) hasBadMesh = true;
1962 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1963 tbl->resizeRowToContents( row );
1965 tbl->resizeColumnToContents( COL_ALGO );
1966 tbl->resizeColumnToContents( COL_SHAPE );
1969 aCompDlg->myBadMeshBtn->show();
1971 aCompDlg->myBadMeshBtn->hide();
1973 tbl->setCurrentCell(0,0);
1974 currentCellChanged(); // to update buttons
1977 // show dialog and wait, becase Compute can be invoked from Preview operation
1978 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1983 //================================================================================
1985 * \brief Gets dialog of evaluate operation
1986 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1988 //================================================================================
1990 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1994 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1995 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1996 // connect signals and slots
1997 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1998 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1999 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2000 QTableWidget* aTable = me->table();
2001 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2002 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));