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 //SMESH::UpdateNulData(myIObject, true);
714 if (gen->Compute(myMesh, myMainShape))
715 computeFailed = false;
717 catch(const SALOME::SALOME_Exception & S_ex){
721 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
724 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
725 // check if there are memory problems
726 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
727 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
729 catch(const SALOME::SALOME_Exception & S_ex){
733 // NPAL16631: if ( !memoryLack )
735 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
736 update( UF_ObjBrowser | UF_Model );
739 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
740 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
741 long newSize = myMesh->NbElements();
742 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
746 if ( getSMESHGUI()->automaticUpdate( newSize, &limitExceeded ) )
749 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
752 SMESH::Update(myIObject, true);
756 MESSAGE ( "Exception thrown during mesh visualization" );
758 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
759 SMESH::OnVisuException();
766 else if ( limitExceeded )
768 SUIT_MessageBox::warning( desktop(),
769 tr( "SMESH_WRN_WARNING" ),
770 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( newSize ).arg( limitSize ) );
773 LightApp_SelectionMgr *Sel = selectionMgr();
776 SALOME_ListIO selected;
777 selected.Append( myIObject );
778 Sel->setSelectedObjects( selected );
784 aMemoryReserve.release();
786 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
790 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
791 bool noHypoError = ( aHypErrors.isEmpty() );
793 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
794 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
796 bool isShowResultDlg = true;
797 switch( aNotifyMode ) {
798 case 0: // show the mesh computation result dialog NEVER
799 isShowResultDlg = false;
802 case 1: // show the mesh computation result dialog if there are some errors
803 if ( memoryLack || !noCompError || !noHypoError )
804 isShowResultDlg = true;
807 isShowResultDlg = false;
811 default: // show the result dialog after each mesh computation
812 isShowResultDlg = true;
816 if ( isShowResultDlg )
817 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
820 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
821 const bool theNoCompError,
822 SMESH::compute_error_array_var& theCompErrors,
823 const bool theNoHypoError,
824 const QString& theHypErrors )
826 bool hasShape = myMesh->HasShapeToMesh();
827 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
828 aCompDlg->myMemoryLackGroup->hide();
832 aCompDlg->myMemoryLackGroup->show();
833 aCompDlg->myFullInfo->hide();
834 aCompDlg->myBriefInfo->hide();
835 aCompDlg->myHypErrorGroup->hide();
836 aCompDlg->myCompErrorGroup->hide();
838 else if ( theNoCompError && theNoHypoError )
840 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
841 aCompDlg->myFullInfo->SetMeshInfo( aRes );
842 aCompDlg->myFullInfo->show();
843 aCompDlg->myBriefInfo->hide();
844 aCompDlg->myHypErrorGroup->hide();
845 aCompDlg->myCompErrorGroup->hide();
849 QTableWidget* tbl = aCompDlg->myTable;
850 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
851 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
852 aCompDlg->myBriefInfo->show();
853 aCompDlg->myFullInfo->hide();
855 if ( theNoHypoError ) {
856 aCompDlg->myHypErrorGroup->hide();
859 aCompDlg->myHypErrorGroup->show();
860 aCompDlg->myHypErrorLabel->setText( theHypErrors );
863 if ( theNoCompError ) {
864 aCompDlg->myCompErrorGroup->hide();
867 aCompDlg->myCompErrorGroup->show();
870 aCompDlg->myPublishBtn->hide();
871 aCompDlg->myShowBtn->hide();
874 aCompDlg->myPublishBtn->show();
875 aCompDlg->myShowBtn->show();
878 // fill table of errors
879 tbl->setRowCount( theCompErrors->length() );
880 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
881 else tbl->showColumn( COL_SHAPE );
882 tbl->setColumnWidth( COL_ERROR, 200 );
884 bool hasBadMesh = false;
885 for ( int row = 0; row < theCompErrors->length(); ++row )
887 SMESH::ComputeError & err = theCompErrors[ row ];
889 QString text = err.algoName.in();
890 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
891 else tbl->item( row, COL_ALGO )->setText( text );
893 text = SMESH::errorText( err.code, err.comment.in() );
894 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
895 else tbl->item( row, COL_ERROR )->setText( text );
897 text = QString("%1").arg( err.subShapeID );
898 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
899 else tbl->item( row, COL_SHAPEID )->setText( text );
901 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
902 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
903 else tbl->item( row, COL_SHAPE )->setText( text );
905 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
906 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
907 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
909 text = err.hasBadMesh ? "hasBadMesh" : "";
910 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
911 else tbl->item( row, COL_BAD_MESH )->setText( text );
912 if ( err.hasBadMesh ) hasBadMesh = true;
914 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
915 tbl->resizeRowToContents( row );
917 tbl->resizeColumnToContents( COL_ALGO );
918 tbl->resizeColumnToContents( COL_SHAPE );
921 aCompDlg->myBadMeshBtn->show();
923 aCompDlg->myBadMeshBtn->hide();
925 tbl->setCurrentCell(0,0);
926 currentCellChanged(); // to update buttons
929 // show dialog and wait, becase Compute can be invoked from Preview operation
930 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
934 //================================================================================
936 * \brief Stops operation
938 //================================================================================
940 void SMESHGUI_BaseComputeOp::stopOperation()
942 SMESHGUI_Operation::stopOperation();
943 if ( myTShapeDisplayer )
944 myTShapeDisplayer->SetVisibility( false );
945 if ( myBadMeshDisplayer ) {
946 myBadMeshDisplayer->SetVisibility( false );
947 // delete it in order not to have problems at its destruction when the viewer
948 // where it worked is dead due to e.g. study closing
949 delete myBadMeshDisplayer;
950 myBadMeshDisplayer = 0;
955 //================================================================================
957 * \brief publish selected subshape
959 //================================================================================
961 void SMESHGUI_BaseComputeOp::onPublishShape()
963 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
964 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
967 SMESH::getSelectedRows( table(), rows );
969 foreach ( row, rows )
971 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
972 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
973 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
975 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
977 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
978 SALOMEDS::SObject_var so =
979 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
980 // look for myMainShape in the table
981 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
982 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
983 if ( so->_is_nil() ) {
984 table()->item( r, COL_SHAPE )->setText( so->GetName() );
985 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
990 if ( curSub == 1 ) continue;
992 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
993 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
994 if ( !so->_is_nil() ) {
995 table()->item( row, COL_SHAPE )->setText( so->GetName() );
996 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1000 getSMESHGUI()->getApp()->updateObjectBrowser();
1001 currentCellChanged(); // to update buttons
1004 //================================================================================
1006 * \brief show mesh elements preventing computation of a submesh of current row
1008 //================================================================================
1010 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1012 myTShapeDisplayer->SetVisibility( false );
1014 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1015 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1017 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1018 SMESHGUI* gui = getSMESHGUI();
1019 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1020 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1021 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1022 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1023 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1024 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1025 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1026 // delete property !!!!!!!!!!
1027 vtkProperty* prop = vtkProperty::New();
1028 prop->SetLineWidth( aLineWidth * 3 );
1029 prop->SetPointSize( aPointSize * 3 );
1030 prop->SetColor( 250, 0, 250 );
1031 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1032 myBadMeshDisplayer->SetData( aMeshData._retn() );
1037 //================================================================================
1039 * \brief SLOT called when a selected cell in table() changed
1041 //================================================================================
1043 void SMESHGUI_BaseComputeOp::currentCellChanged()
1045 myTShapeDisplayer->SetVisibility( false );
1046 if ( myBadMeshDisplayer )
1047 myBadMeshDisplayer->SetVisibility( false );
1049 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1051 int nbSelected = SMESH::getSelectedRows( table(), rows );
1053 foreach ( row, rows )
1055 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1056 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1057 if ( hasData && !isPublished )
1058 publishEnable = true;
1060 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1061 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1063 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1070 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1073 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1074 myCompDlg->myShowBtn ->setEnabled( showEnable );
1075 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1078 //================================================================================
1080 * \brief update preview
1082 //================================================================================
1084 void SMESHGUI_BaseComputeOp::onPreviewShape()
1086 if ( myTShapeDisplayer )
1088 SUIT_OverrideCursor aWaitCursor;
1090 SMESH::getSelectedRows( table(), rows );
1092 bool showOnly = true;
1094 foreach ( row, rows )
1096 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1098 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1102 currentCellChanged(); // to update buttons
1106 //================================================================================
1110 //================================================================================
1112 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1116 delete myTShapeDisplayer;
1117 if ( myBadMeshDisplayer )
1118 delete myBadMeshDisplayer;
1121 //================================================================================
1123 * \brief Gets dialog of compute operation
1124 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1126 //================================================================================
1128 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1132 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1133 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1134 // connect signals and slots
1135 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1136 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1137 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1139 QTableWidget* aTable = me->table();
1140 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1141 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1146 //================================================================================
1148 * \brief returns from compute mesh result dialog
1150 //================================================================================
1152 bool SMESHGUI_BaseComputeOp::onApply()
1157 //================================================================================
1159 * \brief Return a table
1161 //================================================================================
1163 QTableWidget* SMESHGUI_BaseComputeOp::table()
1165 return myCompDlg->myTable;
1169 //================================================================================
1171 * \brief Constructor
1173 //================================================================================
1175 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1176 : SMESHGUI_BaseComputeOp()
1181 //================================================================================
1183 * \brief Desctructor
1185 //================================================================================
1187 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1191 //================================================================================
1193 * \brief perform it's intention action: compute mesh
1195 //================================================================================
1197 void SMESHGUI_ComputeOp::startOperation()
1199 SMESHGUI_BaseComputeOp::startOperation();
1200 if (myMesh->_is_nil())
1205 //================================================================================
1207 * \brief check the same operations on the same mesh
1209 //================================================================================
1211 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1213 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1215 if ( !myMesh->_is_nil() && baseOp ) {
1216 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1217 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1222 //================================================================================
1224 * \brief Gets dialog of this operation
1225 * \retval LightApp_Dialog* - pointer to dialog of this operation
1227 //================================================================================
1229 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1231 return computeDlg();
1234 //================================================================================
1236 * \brief Constructor
1238 //================================================================================
1240 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1241 : SMESHGUI_BaseComputeOp(),
1245 myPreviewDisplayer( 0 )
1247 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1250 //================================================================================
1254 //================================================================================
1256 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1263 if ( myPreviewDisplayer )
1264 delete myPreviewDisplayer;
1265 myPreviewDisplayer = 0;
1268 //================================================================================
1270 * \brief Gets current dialog of this operation
1271 * \retval LightApp_Dialog* - pointer to dialog of this operation
1273 //================================================================================
1275 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1280 //================================================================================
1282 * \brief perform it's intention action: prepare data
1284 //================================================================================
1286 void SMESHGUI_PrecomputeOp::startOperation()
1290 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1293 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1294 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1295 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1297 myActiveDlg = myDlg;
1299 // connect signal to compute dialog. which will be shown after Compute mesh operation
1300 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1303 // disconnect signals
1304 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1305 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1306 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1307 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1308 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1311 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1312 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1313 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1314 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1315 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1316 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1317 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1318 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1319 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1320 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1323 SMESHGUI_BaseComputeOp::startOperation();
1324 if (myMesh->_is_nil())
1327 if (myDlg->getPreviewMode() == -1)
1329 // nothing to preview
1330 SUIT_MessageBox::warning(desktop(),
1331 tr("SMESH_WRN_WARNING"),
1332 tr("SMESH_WRN_NOTHING_PREVIEW"));
1337 // disconnect slot from preview dialog to have Apply from results of compute operation only
1338 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1339 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1344 //================================================================================
1346 * \brief Stops operation
1348 //================================================================================
1350 void SMESHGUI_PrecomputeOp::stopOperation()
1352 if ( myPreviewDisplayer )
1354 myPreviewDisplayer->SetVisibility( false );
1355 delete myPreviewDisplayer;
1356 myPreviewDisplayer = 0;
1358 myMapShapeId.clear();
1359 SMESHGUI_BaseComputeOp::stopOperation();
1362 //================================================================================
1364 * \brief reinitialize dialog after operaiton become active again
1366 //================================================================================
1368 void SMESHGUI_PrecomputeOp::resumeOperation()
1370 if ( myActiveDlg == myDlg )
1372 SMESHGUI_BaseComputeOp::resumeOperation();
1375 //================================================================================
1377 * \brief perform it's intention action: reinitialise dialog
1379 //================================================================================
1381 void SMESHGUI_PrecomputeOp::initDialog()
1385 QMap<int, int> modeMap;
1386 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1387 getAssignedAlgos( pMesh, modeMap );
1388 if ( modeMap.contains( SMESH::DIM_3D ) )
1390 if ( modeMap.contains( SMESH::DIM_2D ) )
1391 modes.append( SMESH::DIM_2D );
1392 if ( modeMap.contains( SMESH::DIM_1D ) )
1393 modes.append( SMESH::DIM_1D );
1395 else if ( modeMap.contains( SMESH::DIM_2D ) )
1397 if ( modeMap.contains( SMESH::DIM_1D ) )
1398 modes.append( SMESH::DIM_1D );
1401 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1402 myOrderMgr->SetMesh( myMesh );
1403 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1404 myDlg->getMeshOrderBox()->setShown(isOrder);
1410 myDlg->setPreviewModes( modes );
1413 //================================================================================
1415 * \brief detect asigned mesh algorithms
1417 //================================================================================
1419 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1420 QMap<int,int>& theModeMap)
1422 _PTR(SObject) aHypRoot;
1423 _PTR(GenericAttribute) anAttr;
1424 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1425 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1427 _PTR(ChildIterator) anIter =
1428 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1429 for ( ; anIter->More(); anIter->Next() )
1431 _PTR(SObject) anObj = anIter->Value();
1432 _PTR(SObject) aRefObj;
1433 if ( anObj->ReferencedObject( aRefObj ) )
1438 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1440 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1441 if ( CORBA::is_nil( aVar ) )
1444 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1446 SMESH::SMESH_Algo_var algo;
1448 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1449 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1450 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1453 if ( !algo->_is_nil() )
1454 theModeMap[ dim ] = 0;
1461 //================================================================================
1463 * \brief perform it's intention action: compute mesh
1465 //================================================================================
1467 void SMESHGUI_PrecomputeOp::onCompute()
1470 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1471 myOrderMgr->SetMeshOrder();
1472 myMapShapeId.clear();
1473 myActiveDlg = computeDlg();
1477 //================================================================================
1479 * \brief perform it's intention action: compute mesh
1481 //================================================================================
1483 void SMESHGUI_PrecomputeOp::onCancel()
1485 QObject* curDlg = sender();
1486 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1488 // return from error messages
1493 bool isRestoreOrder = false;
1494 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1496 // ask to remove already computed mesh elements
1497 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1498 tr( "CLEAR_SUBMESH_QUESTION" ),
1499 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1501 // remove all submeshes for collected shapes
1502 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1503 for ( ; it != myMapShapeId.constEnd(); ++it )
1504 myMesh->ClearSubMesh( *it );
1505 isRestoreOrder = true;
1509 // return previous mesh order
1510 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1511 if (!isRestoreOrder)
1513 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1514 tr( "SMESH_REJECT_MESH_ORDER" ),
1515 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1517 myOrderMgr->SetMeshOrder(myPrevOrder);
1523 myMapShapeId.clear();
1524 SMESHGUI_BaseComputeOp::onCancel();
1527 //================================================================================
1529 * \brief perform it's intention action: preview mesh
1531 //================================================================================
1533 void SMESHGUI_PrecomputeOp::onPreview()
1535 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1538 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1542 // set modified submesh priority if any
1543 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1544 myOrderMgr->SetMeshOrder();
1546 // Compute preview of mesh,
1547 // i.e. compute mesh till indicated dimension
1548 int dim = myDlg->getPreviewMode();
1550 SMESH::MemoryReserve aMemoryReserve;
1552 SMESH::compute_error_array_var aCompErrors;
1555 bool computeFailed = true, memoryLack = false;
1557 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1558 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1560 SMESHGUI* gui = getSMESHGUI();
1561 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1562 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1563 if ( errors->length() > 0 ) {
1564 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1567 SUIT_OverrideCursor aWaitCursor;
1569 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1570 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1571 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1573 SMESH::long_array_var aShapesId = new SMESH::long_array();
1575 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1579 SMESH::MeshPreviewStruct_var previewData =
1580 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1582 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1583 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1585 computeFailed = false;
1586 myPreviewDisplayer->SetData( previewRes );
1587 // append shape indeces with computed mesh entities
1588 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1589 myMapShapeId[ aShapesId[ i ] ] = 0;
1592 myPreviewDisplayer->SetVisibility(false);
1594 catch(const SALOME::SALOME_Exception & S_ex){
1596 myPreviewDisplayer->SetVisibility(false);
1600 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1603 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1604 // check if there are memory problems
1605 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1606 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1608 catch(const SALOME::SALOME_Exception & S_ex){
1613 aMemoryReserve.release();
1615 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1616 bool noHypoError = ( aHypErrors.isEmpty() );
1618 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1619 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1621 bool isShowError = true;
1622 switch( aNotifyMode ) {
1623 case 0: // show the mesh computation result dialog NEVER
1624 isShowError = false;
1626 case 1: // show the mesh computation result dialog if there are some errors
1627 default: // show the result dialog after each mesh computation
1628 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1629 isShowError = false;
1633 aWaitCursor.suspend();
1638 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1639 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1644 //================================================================================
1646 * \brief Constructor
1648 //================================================================================
1650 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1651 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1654 setWindowTitle( tr( "CAPTION" ) );
1656 setButtonText( OK, tr( "COMPUTE" ) );
1657 QFrame* main = mainFrame();
1659 QVBoxLayout* layout = new QVBoxLayout( main );
1661 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1662 layout->addWidget(myOrderBox);
1664 QFrame* frame = new QFrame( main );
1665 layout->setMargin(0); layout->setSpacing(0);
1666 layout->addWidget( frame );
1668 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1669 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1671 myPreviewMode = new QtxComboBox( frame );
1672 frameLay->addWidget( myPreviewMode );
1674 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1675 frameLay->addWidget( myPreviewBtn );
1677 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1680 //================================================================================
1684 //================================================================================
1686 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1690 //================================================================================
1692 * \brief Sets available preview modes
1694 //================================================================================
1696 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1698 myPreviewMode->clear();
1699 QList<int>::const_iterator it = theModes.constBegin();
1700 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1702 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1703 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1704 myPreviewMode->setId( i, *it );
1706 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1709 //================================================================================
1711 * \brief Returns current preview mesh mode
1713 //================================================================================
1715 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1717 return myPreviewMode->currentId();
1720 //================================================================================
1722 * \brief Returns current preview mesh mode
1724 //================================================================================
1726 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1732 //================================================================================
1734 * \brief Constructor
1736 //================================================================================
1738 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1739 : SMESHGUI_BaseComputeOp()
1744 //================================================================================
1746 * \brief Desctructor
1748 //================================================================================
1750 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1754 //================================================================================
1756 * \brief perform it's intention action: compute mesh
1758 //================================================================================
1760 void SMESHGUI_EvaluateOp::startOperation()
1762 SMESHGUI_BaseComputeOp::evaluateDlg();
1763 SMESHGUI_BaseComputeOp::startOperation();
1764 if (myMesh->_is_nil())
1769 //================================================================================
1771 * \brief Gets dialog of this operation
1772 * \retval LightApp_Dialog* - pointer to dialog of this operation
1774 //================================================================================
1776 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1778 return evaluateDlg();
1781 //================================================================================
1783 * \brief evaluateMesh()
1785 //================================================================================
1787 void SMESHGUI_BaseComputeOp::evaluateMesh()
1791 SMESH::MemoryReserve aMemoryReserve;
1793 SMESH::compute_error_array_var aCompErrors;
1796 bool evaluateFailed = true, memoryLack = false;
1797 SMESH::long_array_var aRes;
1799 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1800 if ( !aMeshSObj ) // IPAL21340
1803 bool hasShape = myMesh->HasShapeToMesh();
1804 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1807 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1808 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1809 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1810 if ( errors->length() > 0 ) {
1811 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1813 SUIT_OverrideCursor aWaitCursor;
1815 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1818 aRes = gen->Evaluate(myMesh, myMainShape);
1820 catch(const SALOME::SALOME_Exception & S_ex){
1825 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1828 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1830 catch(const SALOME::SALOME_Exception & S_ex){
1836 aMemoryReserve.release();
1838 evaluateFailed = ( aCompErrors->length() > 0 );
1839 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1843 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1844 bool noHypoError = ( aHypErrors.isEmpty() );
1846 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1847 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1849 bool isShowResultDlg = true;
1851 //switch( aNotifyMode ) {
1852 //case 0: // show the mesh computation result dialog NEVER
1853 //isShowResultDlg = false;
1856 //case 1: // show the mesh computation result dialog if there are some errors
1857 //if ( memoryLack || !noHypoError )
1858 // isShowResultDlg = true;
1861 // isShowResultDlg = false;
1865 //default: // show the result dialog after each mesh computation
1866 //isShowResultDlg = true;
1870 if ( isShowResultDlg )
1871 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1872 noHypoError, aHypErrors);
1876 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1877 const bool theMemoryLack,
1878 const bool theNoCompError,
1879 SMESH::compute_error_array_var& theCompErrors,
1880 const bool theNoHypoError,
1881 const QString& theHypErrors)
1883 bool hasShape = myMesh->HasShapeToMesh();
1884 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1885 aCompDlg->myMemoryLackGroup->hide();
1887 if ( theMemoryLack )
1889 aCompDlg->myMemoryLackGroup->show();
1890 aCompDlg->myFullInfo->hide();
1891 aCompDlg->myBriefInfo->hide();
1892 aCompDlg->myHypErrorGroup->hide();
1893 aCompDlg->myCompErrorGroup->hide();
1895 else if ( theNoCompError && theNoHypoError )
1897 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1898 aCompDlg->myFullInfo->show();
1899 aCompDlg->myBriefInfo->hide();
1900 aCompDlg->myHypErrorGroup->hide();
1901 aCompDlg->myCompErrorGroup->hide();
1905 QTableWidget* tbl = aCompDlg->myTable;
1906 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1907 aCompDlg->myBriefInfo->show();
1908 aCompDlg->myFullInfo->hide();
1910 if ( theNoHypoError ) {
1911 aCompDlg->myHypErrorGroup->hide();
1914 aCompDlg->myHypErrorGroup->show();
1915 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1918 if ( theNoCompError ) {
1919 aCompDlg->myCompErrorGroup->hide();
1922 aCompDlg->myCompErrorGroup->show();
1924 aCompDlg->myPublishBtn->hide();
1925 aCompDlg->myShowBtn->hide();
1927 // fill table of errors
1928 tbl->setRowCount( theCompErrors->length() );
1929 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1930 else tbl->showColumn( COL_SHAPE );
1931 tbl->setColumnWidth( COL_ERROR, 200 );
1933 bool hasBadMesh = false;
1934 for ( int row = 0; row < theCompErrors->length(); ++row )
1936 SMESH::ComputeError & err = theCompErrors[ row ];
1938 QString text = err.algoName.in();
1939 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1940 else tbl->item( row, COL_ALGO )->setText( text );
1942 text = SMESH::errorText( err.code, err.comment.in() );
1943 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1944 else tbl->item( row, COL_ERROR )->setText( text );
1946 text = QString("%1").arg( err.subShapeID );
1947 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1948 else tbl->item( row, COL_SHAPEID )->setText( text );
1950 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1951 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1952 else tbl->item( row, COL_SHAPE )->setText( text );
1954 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1955 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1956 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1958 text = err.hasBadMesh ? "hasBadMesh" : "";
1959 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1960 else tbl->item( row, COL_BAD_MESH )->setText( text );
1961 if ( err.hasBadMesh ) hasBadMesh = true;
1963 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1964 tbl->resizeRowToContents( row );
1966 tbl->resizeColumnToContents( COL_ALGO );
1967 tbl->resizeColumnToContents( COL_SHAPE );
1970 aCompDlg->myBadMeshBtn->show();
1972 aCompDlg->myBadMeshBtn->hide();
1974 tbl->setCurrentCell(0,0);
1975 currentCellChanged(); // to update buttons
1978 // show dialog and wait, becase Compute can be invoked from Preview operation
1979 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1984 //================================================================================
1986 * \brief Gets dialog of evaluate operation
1987 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1989 //================================================================================
1991 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1995 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1996 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1997 // connect signals and slots
1998 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1999 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2000 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2001 QTableWidget* aTable = me->table();
2002 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2003 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));