1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_ComputeDlg.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
24 #include "SMESHGUI_ComputeDlg.h"
27 #include "SMESHGUI_GEOMGenUtils.h"
28 #include "SMESHGUI_MeshUtils.h"
29 #include "SMESHGUI_VTKUtils.h"
30 #include "SMESHGUI_MeshInfosBox.h"
31 #include "SMESHGUI_HypothesesUtils.h"
32 #include "SMESHGUI_MeshEditPreview.h"
33 #include "SMESHGUI_MeshOrderOp.h"
34 #include "SMESHGUI_MeshOrderDlg.h"
36 #include "SMESH_ActorUtils.h"
38 #include <SMDS_SetIterator.hxx>
39 #include <SMDS_Mesh.hxx>
41 // SALOME GEOM includes
43 #include <GEOM_Actor.h>
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_UpdateFlags.h>
48 #include <SALOME_ListIO.hxx>
49 #include <SVTK_ViewWindow.h>
50 #include <SVTK_ViewModel.h>
51 #include <SalomeApp_Application.h>
52 #include <SUIT_ResourceMgr.h>
53 #include <SUIT_OverrideCursor.h>
54 #include <SUIT_MessageBox.h>
55 #include <SUIT_Desktop.h>
56 #include <QtxComboBox.h>
58 // SALOME KERNEL includes
59 #include <SALOMEDS_SObject.hxx>
60 #include <SALOMEDSClient_SObject.hxx>
63 #include <BRep_Tool.hxx>
65 #include <TopExp_Explorer.hxx>
66 #include <TopTools_IndexedMapOfShape.hxx>
69 #include <TopLoc_Location.hxx>
70 #include <Poly_Triangulation.hxx>
71 #include <Bnd_Box.hxx>
72 #include <BRepBndLib.hxx>
73 #include <BRepMesh_IncrementalMesh.hxx>
75 #include <Standard_ErrorHandler.hxx>
79 #include <QPushButton>
81 #include <QRadioButton>
82 #include <QTableWidget>
83 #include <QHeaderView>
84 #include <QGridLayout>
85 #include <QHBoxLayout>
86 #include <QVBoxLayout>
87 #include <QButtonGroup>
90 #include <vtkProperty.h>
99 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
101 static void addSeparator( QWidget* parent )
103 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
104 int row = l->rowCount();
105 int cols = l->columnCount();
106 for ( int i = 0; i < cols; i++ ) {
107 QFrame* hline = new QFrame( parent );
108 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
109 l->addWidget( hline, row, i );
114 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
117 //using namespace SMESH;
121 //=============================================================================
123 * \brief Allocate some memory at construction and release it at destruction.
124 * Is used to be able to continue working after mesh generation or visualization
125 * break due to lack of memory
127 //=============================================================================
132 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
133 void release() { delete [] myBuf; myBuf = 0; }
134 ~MemoryReserve() { release(); }
137 // =========================================================================================
139 * \brief Class showing shapes without publishing
141 // =========================================================================================
143 class TShapeDisplayer
146 // -----------------------------------------------------------------------
147 TShapeDisplayer(): myViewWindow(0)
149 myProperty = vtkProperty::New();
150 myProperty->SetRepresentationToWireframe();
151 myProperty->SetColor( 250, 0, 250 );
152 myProperty->SetAmbientColor( 250, 0, 250 );
153 myProperty->SetDiffuseColor( 250, 0, 250 );
154 //myProperty->SetSpecularColor( 250, 0, 250 );
155 myProperty->SetLineWidth( 5 );
157 // -----------------------------------------------------------------------
161 myProperty->Delete();
163 // -----------------------------------------------------------------------
166 if ( hasViewWindow() ) {
167 TActorIterator actorIt = actorIterator();
168 while ( actorIt.more() )
169 if (VTKViewer_Actor* anActor = actorIt.next()) {
170 myViewWindow->RemoveActor( anActor );
174 myIndexToShape.Clear();
176 myShownActors.clear();
179 // -----------------------------------------------------------------------
180 void SetVisibility (bool theVisibility)
182 TActorIterator actorIt = shownIterator();
183 while ( actorIt.more() )
184 if (VTKViewer_Actor* anActor = actorIt.next())
185 anActor->SetVisibility(theVisibility);
186 SMESH::RepaintCurrentView();
188 // -----------------------------------------------------------------------
189 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
191 std::string mainEntry;
192 if ( !aMainShape->_is_nil() )
193 mainEntry = aMainShape->GetStudyEntry();
194 return ( myMainEntry == mainEntry &&
195 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
197 // -----------------------------------------------------------------------
198 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
200 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
201 std::string mainEntry;
202 if ( !aMainShape->_is_nil() )
203 mainEntry = aMainShape->GetStudyEntry();
204 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
207 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
208 checkTriangulation( aShape );
209 TopExp::MapShapes(aShape, myIndexToShape);
210 myActors.resize( myIndexToShape.Extent(), 0 );
211 myShownActors.reserve( myIndexToShape.Extent() );
213 myMainEntry = mainEntry;
214 myViewWindow = aViewWindow;
216 if ( only ) { // hide shown actors
217 TActorIterator actorIt = shownIterator();
218 while ( actorIt.more() )
219 if (VTKViewer_Actor* anActor = actorIt.next())
220 anActor->SetVisibility(false);
221 myShownActors.clear();
223 // find actors to show
224 TopoDS_Shape aShape = myIndexToShape( subShapeID );
225 if ( !aShape.IsNull() ) {
226 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
227 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
228 //checkTriangulation( exp.Current() );
229 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
230 myShownActors.push_back( anActor );
232 if ( type == TopAbs_FACE ) {
233 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
234 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
235 if ( !BRep_Tool::Degenerated( edge ))
236 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
237 myShownActors.push_back( anActor );
241 myBuiltSubs.insert( subShapeID );
244 // -----------------------------------------------------------------------
248 typedef std::vector<GEOM_Actor*> TActorVec;
250 TActorVec myShownActors;
251 TopTools_IndexedMapOfShape myIndexToShape;
252 std::string myMainEntry;
253 SVTK_ViewWindow* myViewWindow;
254 vtkProperty* myProperty;
255 std::set<int> myBuiltSubs;
257 // -----------------------------------------------------------------------
258 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
259 TActorIterator actorIterator() {
260 return TActorIterator( myActors.begin(), myActors.end() );
262 TActorIterator shownIterator() {
263 return TActorIterator( myShownActors.begin(), myShownActors.end() );
265 // -----------------------------------------------------------------------
266 GEOM_Actor* getActor(const TopoDS_Shape& shape)
268 int index = myIndexToShape.FindIndex( shape ) - 1;
269 if ( index < 0 || index >= myActors.size() )
271 GEOM_Actor* & actor = myActors[ index ];
273 actor = GEOM_Actor::New();
275 actor->SetShape(shape,0,0);
276 actor->SetProperty(myProperty);
277 actor->SetShadingProperty(myProperty);
278 actor->SetWireframeProperty(myProperty);
279 actor->SetPreviewProperty(myProperty);
280 actor->PickableOff();
281 // if ( shape.ShapeType() == TopAbs_EDGE )
282 // actor->SubShapeOn();
283 myViewWindow->AddActor( actor );
288 // -----------------------------------------------------------------------
289 void checkTriangulation(const TopoDS_Shape& shape)
291 TopLoc_Location aLoc;
292 Standard_Boolean alreadymesh = Standard_True;
293 TopExp_Explorer ex(shape, TopAbs_FACE);
295 for ( ; ex.More(); ex.Next()) {
296 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
297 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
298 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
301 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
302 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
303 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
304 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
306 if (alreadymesh) return;
307 // Compute default deflection
309 BRepBndLib::Add(shape, B);
310 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
311 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
312 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
313 BRepMesh_IncrementalMesh MESH(shape,deflection);
315 // -----------------------------------------------------------------------
316 bool hasViewWindow() const
318 if ( !myViewWindow ) return false;
320 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
321 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
327 // =========================================================================================
329 * \brief Return text describing an error
331 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
332 QString errorText(int errCode, const char* comment)
336 CASE2TEXT( COMPERR_OK );
337 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
338 CASE2TEXT( COMPERR_STD_EXCEPTION );
339 CASE2TEXT( COMPERR_OCC_EXCEPTION );
340 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
341 CASE2TEXT( COMPERR_EXCEPTION );
342 CASE2TEXT( COMPERR_MEMORY_PB );
343 CASE2TEXT( COMPERR_BAD_SHAPE );
344 case SMESH::COMPERR_ALGO_FAILED:
345 if ( strlen(comment) == 0 )
346 text = QObject::tr("COMPERR_ALGO_FAILED");
349 text = QString("#%1").arg( -errCode );
351 if ( text.length() > 0 ) text += ". ";
352 return text + comment;
354 // -----------------------------------------------------------------------
356 * \brief Return SO of a subshape
358 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
360 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
361 if ( subShapeID == 1 || !so )
363 _PTR(ChildIterator) it;
364 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
365 it = study->NewChildIterator(so);
368 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
369 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
370 if ( !geom->_is_nil() ) {
371 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
372 if ( list->length() == 1 && list[0] == subShapeID )
379 // -----------------------------------------------------------------------
381 * \brief Return subshape by ID
383 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
385 GEOM::GEOM_Object_var aSubShape;
386 if ( subShapeID == 1 )
387 aSubShape = aMainShape;
388 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
389 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
391 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
392 return aSubShape._retn();
394 // -----------------------------------------------------------------------
396 * \brief Return shape type name
398 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
399 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
402 if ( !aShape->_is_nil() ) {
403 switch ( aShape->GetShapeType() ) {
410 CASE2NAME( COMPSOLID );
411 CASE2NAME( COMPOUND );
417 // -----------------------------------------------------------------------
419 * \brief Return text describing a subshape
421 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
424 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
425 text = aSO->GetName().c_str();
427 text = QString("#%1").arg( subShapeID );
428 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
429 if ( typeName.length() )
430 text += QString(" (%1)").arg(typeName);
434 // -----------------------------------------------------------------------
436 * \brief Return a list of selected rows
438 int getSelectedRows(QTableWidget* table, QList<int>& rows)
441 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
442 QTableWidgetSelectionRange range;
443 foreach( range, selRanges )
445 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
448 if ( rows.isEmpty() && table->currentRow() > -1 )
449 rows.append( table->currentRow() );
457 // =========================================================================================
459 * \brief Dialog to compute a mesh and show computation errors
461 //=======================================================================
463 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
464 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
466 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
467 aDlgLay->setMargin( 0 );
468 aDlgLay->setSpacing( SPACING );
470 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
472 aDlgLay->addWidget(aMainFrame);
474 aDlgLay->setStretchFactor(aMainFrame, 1);
477 // =========================================================================================
481 //=======================================================================
483 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
487 //=======================================================================
488 // function : createMainFrame()
489 // purpose : Create frame containing dialog's fields
490 //=======================================================================
492 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
494 QFrame* aFrame = new QFrame(theParent);
496 SUIT_ResourceMgr* rm = resourceMgr();
497 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
503 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
506 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
508 QButtonGroup* aBtnGrp = new QButtonGroup(this);
509 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
510 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
512 QRadioButton* aRBut = new QRadioButton(aPixGrp);
513 aRBut->setIcon(iconCompute);
514 aRBut->setChecked(true);
515 aPixGrpLayout->addWidget(aRBut);
516 aBtnGrp->addButton(aRBut, 0);
520 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
521 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
522 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
523 myMeshName = new QLabel(nameBox);
524 nameBoxLayout->addWidget(myMeshName);
528 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
529 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
531 // Computation errors
533 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
534 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
535 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
536 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
537 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
539 //myTable->setReadOnly( true ); // VSR: check
540 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
541 myTable->hideColumn( COL_PUBLISHED );
542 myTable->hideColumn( COL_SHAPEID );
543 myTable->hideColumn( COL_BAD_MESH );
544 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
547 headers << tr( "COL_ALGO_HEADER" );
548 headers << tr( "COL_SHAPE_HEADER" );
549 headers << tr( "COL_ERROR_HEADER" );
550 headers << tr( "COL_SHAPEID_HEADER" );
551 headers << tr( "COL_PUBLISHED_HEADER" );
553 myTable->setHorizontalHeaderLabels( headers );
556 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
557 grpLayout->setSpacing(SPACING);
558 grpLayout->setMargin(MARGIN);
559 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
560 grpLayout->addWidget( myShowBtn, 0, 1 );
561 grpLayout->addWidget( myPublishBtn, 1, 1 );
562 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
563 grpLayout->setRowStretch( 3, 1 );
565 // Hypothesis definition errors
567 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
568 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
569 myHypErrorGroupLayout->setMargin(MARGIN);
570 myHypErrorGroupLayout->setSpacing(SPACING);
571 myHypErrorLabel = new QLabel(myHypErrorGroup);
572 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
576 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
577 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
578 myMemoryLackGroupLayout->setMargin(MARGIN);
579 myMemoryLackGroupLayout->setSpacing(SPACING);
580 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
581 QFont bold = memLackLabel->font(); bold.setBold(true);
582 memLackLabel->setFont( bold );
583 memLackLabel->setMinimumWidth(300);
584 myMemoryLackGroupLayout->addWidget(memLackLabel);
586 // add all widgets to aFrame
587 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
588 aLay->setMargin( 0 );
589 aLay->setSpacing( 0 );
590 aLay->addWidget( aPixGrp );
591 aLay->addWidget( nameBox );
592 aLay->addWidget( myBriefInfo );
593 aLay->addWidget( myFullInfo );
594 aLay->addWidget( myHypErrorGroup );
595 aLay->addWidget( myCompErrorGroup );
596 aLay->addWidget( myMemoryLackGroup );
597 aLay->setStretchFactor( myCompErrorGroup, 1 );
599 ((QPushButton*) button( OK ))->setDefault( true );
604 //================================================================================
608 //================================================================================
610 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
611 : SMESHGUI_Operation(), myCompDlg( 0 )
613 myTShapeDisplayer = new SMESH::TShapeDisplayer();
614 myBadMeshDisplayer = 0;
616 //myHelpFileName = "/files/about_meshes.htm"; // V3
617 myHelpFileName = "about_meshes_page.html"; // V4
620 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
622 LightApp_SelectionMgr* Sel = selectionMgr();
623 SALOME_ListIO selected; Sel->selectedObjects( selected );
624 Handle(SALOME_InteractiveObject) anIO = selected.First();
625 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
626 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
629 //================================================================================
631 * \brief Start operation
632 * \purpose Init dialog fields, connect signals and slots, show dialog
634 //================================================================================
636 void SMESHGUI_BaseComputeOp::startOperation()
638 // create compute dialog if not created before
641 myMesh = SMESH::SMESH_Mesh::_nil();
642 myMainShape = GEOM::GEOM_Object::_nil();
645 LightApp_SelectionMgr *Sel = selectionMgr();
646 SALOME_ListIO selected; Sel->selectedObjects( selected );
648 int nbSel = selected.Extent();
650 SUIT_MessageBox::warning(desktop(),
651 tr("SMESH_WRN_WARNING"),
652 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
657 myIObject = selected.First();
658 myMesh = SMESH::GetMeshByIO(myIObject);
659 if (myMesh->_is_nil()) {
660 SUIT_MessageBox::warning(desktop(),
661 tr("SMESH_WRN_WARNING"),
662 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
666 myMainShape = myMesh->GetShapeToMesh();
668 SMESHGUI_Operation::startOperation();
671 //================================================================================
673 * \brief computeMesh()
675 //================================================================================
677 void SMESHGUI_BaseComputeOp::computeMesh()
681 SMESH::MemoryReserve aMemoryReserve;
683 SMESH::compute_error_array_var aCompErrors;
686 bool computeFailed = true, memoryLack = false;
688 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
689 if ( !aMeshSObj ) // IPAL 21340
691 bool hasShape = myMesh->HasShapeToMesh();
692 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
695 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
696 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
697 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
698 if ( errors->length() > 0 ) {
699 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
701 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
702 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
703 tr( "FULL_RECOMPUTE_QUESTION" ),
704 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
706 SUIT_OverrideCursor aWaitCursor;
708 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
711 if (gen->Compute(myMesh, myMainShape))
712 computeFailed = false;
714 catch(const SALOME::SALOME_Exception & S_ex){
718 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
721 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
722 // check if there are memory problems
723 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
724 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
726 catch(const SALOME::SALOME_Exception & S_ex){
730 // NPAL16631: if ( !memoryLack )
732 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
733 update( UF_ObjBrowser | UF_Model );
736 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
737 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
740 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
743 SMESH::Update(myIObject, true);
747 MESSAGE ( "Exception thrown during mesh visualization" );
749 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
750 SMESH::OnVisuException();
757 LightApp_SelectionMgr *Sel = selectionMgr();
760 SALOME_ListIO selected;
761 selected.Append( myIObject );
762 Sel->setSelectedObjects( selected );
768 aMemoryReserve.release();
770 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
774 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
775 bool noHypoError = ( aHypErrors.isEmpty() );
777 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
778 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
780 bool isShowResultDlg = true;
781 switch( aNotifyMode ) {
782 case 0: // show the mesh computation result dialog NEVER
783 isShowResultDlg = false;
786 case 1: // show the mesh computation result dialog if there are some errors
787 if ( memoryLack || !noCompError || !noHypoError )
788 isShowResultDlg = true;
791 isShowResultDlg = false;
795 default: // show the result dialog after each mesh computation
796 isShowResultDlg = true;
800 if ( isShowResultDlg )
801 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
804 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
805 const bool theNoCompError,
806 SMESH::compute_error_array_var& theCompErrors,
807 const bool theNoHypoError,
808 const QString& theHypErrors )
810 bool hasShape = myMesh->HasShapeToMesh();
811 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
812 aCompDlg->myMemoryLackGroup->hide();
816 aCompDlg->myMemoryLackGroup->show();
817 aCompDlg->myFullInfo->hide();
818 aCompDlg->myBriefInfo->hide();
819 aCompDlg->myHypErrorGroup->hide();
820 aCompDlg->myCompErrorGroup->hide();
822 else if ( theNoCompError && theNoHypoError )
824 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
825 aCompDlg->myFullInfo->SetMeshInfo( aRes );
826 aCompDlg->myFullInfo->show();
827 aCompDlg->myBriefInfo->hide();
828 aCompDlg->myHypErrorGroup->hide();
829 aCompDlg->myCompErrorGroup->hide();
833 QTableWidget* tbl = aCompDlg->myTable;
834 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
835 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
836 aCompDlg->myBriefInfo->show();
837 aCompDlg->myFullInfo->hide();
839 if ( theNoHypoError ) {
840 aCompDlg->myHypErrorGroup->hide();
843 aCompDlg->myHypErrorGroup->show();
844 aCompDlg->myHypErrorLabel->setText( theHypErrors );
847 if ( theNoCompError ) {
848 aCompDlg->myCompErrorGroup->hide();
851 aCompDlg->myCompErrorGroup->show();
854 aCompDlg->myPublishBtn->hide();
855 aCompDlg->myShowBtn->hide();
858 aCompDlg->myPublishBtn->show();
859 aCompDlg->myShowBtn->show();
862 // fill table of errors
863 tbl->setRowCount( theCompErrors->length() );
864 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
865 else tbl->showColumn( COL_SHAPE );
866 tbl->setColumnWidth( COL_ERROR, 200 );
868 bool hasBadMesh = false;
869 for ( int row = 0; row < theCompErrors->length(); ++row )
871 SMESH::ComputeError & err = theCompErrors[ row ];
873 QString text = err.algoName.in();
874 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
875 else tbl->item( row, COL_ALGO )->setText( text );
877 text = SMESH::errorText( err.code, err.comment.in() );
878 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
879 else tbl->item( row, COL_ERROR )->setText( text );
881 text = QString("%1").arg( err.subShapeID );
882 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
883 else tbl->item( row, COL_SHAPEID )->setText( text );
885 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
886 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
887 else tbl->item( row, COL_SHAPE )->setText( text );
889 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
890 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
891 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
893 text = err.hasBadMesh ? "hasBadMesh" : "";
894 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
895 else tbl->item( row, COL_BAD_MESH )->setText( text );
896 if ( err.hasBadMesh ) hasBadMesh = true;
898 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
899 tbl->resizeRowToContents( row );
901 tbl->resizeColumnToContents( COL_ALGO );
902 tbl->resizeColumnToContents( COL_SHAPE );
905 aCompDlg->myBadMeshBtn->show();
907 aCompDlg->myBadMeshBtn->hide();
909 tbl->setCurrentCell(0,0);
910 currentCellChanged(); // to update buttons
913 // show dialog and wait, becase Compute can be invoked from Preview operation
914 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
918 //================================================================================
920 * \brief Stops operation
922 //================================================================================
924 void SMESHGUI_BaseComputeOp::stopOperation()
926 SMESHGUI_Operation::stopOperation();
927 if ( myTShapeDisplayer )
928 myTShapeDisplayer->SetVisibility( false );
929 if ( myBadMeshDisplayer ) {
930 myBadMeshDisplayer->SetVisibility( false );
931 // delete it in order not to have problems at its destruction when the viewer
932 // where it worked is dead due to e.g. study closing
933 delete myBadMeshDisplayer;
934 myBadMeshDisplayer = 0;
939 //================================================================================
941 * \brief publish selected subshape
943 //================================================================================
945 void SMESHGUI_BaseComputeOp::onPublishShape()
947 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
948 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
951 SMESH::getSelectedRows( table(), rows );
953 foreach ( row, rows )
955 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
956 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
957 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
959 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
961 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
962 SALOMEDS::SObject_var so =
963 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
964 // look for myMainShape in the table
965 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
966 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
967 if ( so->_is_nil() ) {
968 table()->item( r, COL_SHAPE )->setText( so->GetName() );
969 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
974 if ( curSub == 1 ) continue;
976 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
977 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
978 if ( !so->_is_nil() ) {
979 table()->item( row, COL_SHAPE )->setText( so->GetName() );
980 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
984 getSMESHGUI()->getApp()->updateObjectBrowser();
985 currentCellChanged(); // to update buttons
988 //================================================================================
990 * \brief show mesh elements preventing computation of a submesh of current row
992 //================================================================================
994 void SMESHGUI_BaseComputeOp::onShowBadMesh()
996 myTShapeDisplayer->SetVisibility( false );
998 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
999 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1001 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1002 SMESHGUI* gui = getSMESHGUI();
1003 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1004 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1005 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1006 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1007 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1008 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1009 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1010 // delete property !!!!!!!!!!
1011 vtkProperty* prop = vtkProperty::New();
1012 prop->SetLineWidth( aLineWidth * 3 );
1013 prop->SetPointSize( aPointSize * 3 );
1014 prop->SetColor( 250, 0, 250 );
1015 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1016 myBadMeshDisplayer->SetData( aMeshData._retn() );
1021 //================================================================================
1023 * \brief SLOT called when a selected cell in table() changed
1025 //================================================================================
1027 void SMESHGUI_BaseComputeOp::currentCellChanged()
1029 myTShapeDisplayer->SetVisibility( false );
1030 if ( myBadMeshDisplayer )
1031 myBadMeshDisplayer->SetVisibility( false );
1033 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1035 int nbSelected = SMESH::getSelectedRows( table(), rows );
1037 foreach ( row, rows )
1039 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1040 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1041 if ( hasData && !isPublished )
1042 publishEnable = true;
1044 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1045 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1047 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1054 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1057 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1058 myCompDlg->myShowBtn ->setEnabled( showEnable );
1059 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1062 //================================================================================
1064 * \brief update preview
1066 //================================================================================
1068 void SMESHGUI_BaseComputeOp::onPreviewShape()
1070 if ( myTShapeDisplayer )
1072 SUIT_OverrideCursor aWaitCursor;
1074 SMESH::getSelectedRows( table(), rows );
1076 bool showOnly = true;
1078 foreach ( row, rows )
1080 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1082 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1086 currentCellChanged(); // to update buttons
1090 //================================================================================
1094 //================================================================================
1096 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1100 delete myTShapeDisplayer;
1101 if ( myBadMeshDisplayer )
1102 delete myBadMeshDisplayer;
1105 //================================================================================
1107 * \brief Gets dialog of compute operation
1108 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1110 //================================================================================
1112 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1116 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1117 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1118 // connect signals and slots
1119 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1120 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1121 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1123 QTableWidget* aTable = me->table();
1124 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1125 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1130 //================================================================================
1132 * \brief returns from compute mesh result dialog
1134 //================================================================================
1136 bool SMESHGUI_BaseComputeOp::onApply()
1141 //================================================================================
1143 * \brief Return a table
1145 //================================================================================
1147 QTableWidget* SMESHGUI_BaseComputeOp::table()
1149 return myCompDlg->myTable;
1153 //================================================================================
1155 * \brief Constructor
1157 //================================================================================
1159 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1160 : SMESHGUI_BaseComputeOp()
1165 //================================================================================
1167 * \brief Desctructor
1169 //================================================================================
1171 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1175 //================================================================================
1177 * \brief perform it's intention action: compute mesh
1179 //================================================================================
1181 void SMESHGUI_ComputeOp::startOperation()
1183 SMESHGUI_BaseComputeOp::startOperation();
1184 if (myMesh->_is_nil())
1189 //================================================================================
1191 * \brief check the same operations on the same mesh
1193 //================================================================================
1195 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1197 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1199 if ( !myMesh->_is_nil() && baseOp ) {
1200 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1201 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1206 //================================================================================
1208 * \brief Gets dialog of this operation
1209 * \retval LightApp_Dialog* - pointer to dialog of this operation
1211 //================================================================================
1213 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1215 return computeDlg();
1218 //================================================================================
1220 * \brief Constructor
1222 //================================================================================
1224 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1225 : SMESHGUI_BaseComputeOp(),
1229 myPreviewDisplayer( 0 )
1231 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1234 //================================================================================
1238 //================================================================================
1240 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1247 if ( myPreviewDisplayer )
1248 delete myPreviewDisplayer;
1249 myPreviewDisplayer = 0;
1252 //================================================================================
1254 * \brief Gets current dialog of this operation
1255 * \retval LightApp_Dialog* - pointer to dialog of this operation
1257 //================================================================================
1259 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1264 //================================================================================
1266 * \brief perform it's intention action: prepare data
1268 //================================================================================
1270 void SMESHGUI_PrecomputeOp::startOperation()
1274 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1277 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1278 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1279 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1281 myActiveDlg = myDlg;
1283 // connect signal to compute dialog. which will be shown after Compute mesh operation
1284 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1287 // disconnect signals
1288 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1289 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1290 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1291 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1292 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1295 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1296 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1297 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1298 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1299 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1300 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1301 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1302 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1303 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1304 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1307 SMESHGUI_BaseComputeOp::startOperation();
1308 if (myMesh->_is_nil())
1311 if (myDlg->getPreviewMode() == -1)
1313 // nothing to preview
1314 SUIT_MessageBox::warning(desktop(),
1315 tr("SMESH_WRN_WARNING"),
1316 tr("SMESH_WRN_NOTHING_PREVIEW"));
1321 // disconnect slot from preview dialog to have Apply from results of compute operation only
1322 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1323 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1328 //================================================================================
1330 * \brief Stops operation
1332 //================================================================================
1334 void SMESHGUI_PrecomputeOp::stopOperation()
1336 if ( myPreviewDisplayer )
1338 myPreviewDisplayer->SetVisibility( false );
1339 delete myPreviewDisplayer;
1340 myPreviewDisplayer = 0;
1342 myMapShapeId.clear();
1343 SMESHGUI_BaseComputeOp::stopOperation();
1346 //================================================================================
1348 * \brief reinitialize dialog after operaiton become active again
1350 //================================================================================
1352 void SMESHGUI_PrecomputeOp::resumeOperation()
1354 if ( myActiveDlg == myDlg )
1356 SMESHGUI_BaseComputeOp::resumeOperation();
1359 //================================================================================
1361 * \brief perform it's intention action: reinitialise dialog
1363 //================================================================================
1365 void SMESHGUI_PrecomputeOp::initDialog()
1369 QMap<int, int> modeMap;
1370 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1371 getAssignedAlgos( pMesh, modeMap );
1372 if ( modeMap.contains( SMESH::DIM_3D ) )
1374 if ( modeMap.contains( SMESH::DIM_2D ) )
1375 modes.append( SMESH::DIM_2D );
1376 if ( modeMap.contains( SMESH::DIM_1D ) )
1377 modes.append( SMESH::DIM_1D );
1379 else if ( modeMap.contains( SMESH::DIM_2D ) )
1381 if ( modeMap.contains( SMESH::DIM_1D ) )
1382 modes.append( SMESH::DIM_1D );
1385 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1386 myOrderMgr->SetMesh( myMesh );
1387 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1388 myDlg->getMeshOrderBox()->setShown(isOrder);
1394 myDlg->setPreviewModes( modes );
1397 //================================================================================
1399 * \brief detect asigned mesh algorithms
1401 //================================================================================
1403 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1404 QMap<int,int>& theModeMap)
1406 _PTR(SObject) aHypRoot;
1407 _PTR(GenericAttribute) anAttr;
1408 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1409 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1411 _PTR(ChildIterator) anIter =
1412 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1413 for ( ; anIter->More(); anIter->Next() )
1415 _PTR(SObject) anObj = anIter->Value();
1416 _PTR(SObject) aRefObj;
1417 if ( anObj->ReferencedObject( aRefObj ) )
1422 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1424 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1425 if ( CORBA::is_nil( aVar ) )
1428 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1430 SMESH::SMESH_Algo_var algo;
1432 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1433 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1434 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1437 if ( !algo->_is_nil() )
1438 theModeMap[ dim ] = 0;
1445 //================================================================================
1447 * \brief perform it's intention action: compute mesh
1449 //================================================================================
1451 void SMESHGUI_PrecomputeOp::onCompute()
1454 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1455 myOrderMgr->SetMeshOrder();
1456 myMapShapeId.clear();
1457 myActiveDlg = computeDlg();
1461 //================================================================================
1463 * \brief perform it's intention action: compute mesh
1465 //================================================================================
1467 void SMESHGUI_PrecomputeOp::onCancel()
1469 QObject* curDlg = sender();
1470 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1472 // return from error messages
1477 bool isRestoreOrder = false;
1478 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1480 // ask to remove already computed mesh elements
1481 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1482 tr( "CLEAR_SUBMESH_QUESTION" ),
1483 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1485 // remove all submeshes for collected shapes
1486 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1487 for ( ; it != myMapShapeId.constEnd(); ++it )
1488 myMesh->ClearSubMesh( *it );
1489 isRestoreOrder = true;
1493 // return previous mesh order
1494 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1495 if (!isRestoreOrder)
1497 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1498 tr( "SMESH_REJECT_MESH_ORDER" ),
1499 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1501 myOrderMgr->SetMeshOrder(myPrevOrder);
1507 myMapShapeId.clear();
1508 SMESHGUI_BaseComputeOp::onCancel();
1511 //================================================================================
1513 * \brief perform it's intention action: preview mesh
1515 //================================================================================
1517 void SMESHGUI_PrecomputeOp::onPreview()
1519 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1522 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1526 // set modified submesh priority if any
1527 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1528 myOrderMgr->SetMeshOrder();
1530 // Compute preview of mesh,
1531 // i.e. compute mesh till indicated dimension
1532 int dim = myDlg->getPreviewMode();
1534 SMESH::MemoryReserve aMemoryReserve;
1536 SMESH::compute_error_array_var aCompErrors;
1539 bool computeFailed = true, memoryLack = false;
1541 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1542 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1544 SMESHGUI* gui = getSMESHGUI();
1545 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1546 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1547 if ( errors->length() > 0 ) {
1548 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1551 SUIT_OverrideCursor aWaitCursor;
1553 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1554 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1555 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1557 SMESH::long_array_var aShapesId = new SMESH::long_array();
1559 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1563 SMESH::MeshPreviewStruct_var previewData =
1564 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1565 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1566 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1568 computeFailed = false;
1569 myPreviewDisplayer->SetData( previewRes );
1570 // append shape indeces with computed mesh entities
1571 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1572 myMapShapeId[ aShapesId[ i ] ] = 0;
1575 myPreviewDisplayer->SetVisibility(false);
1577 catch(const SALOME::SALOME_Exception & S_ex){
1579 myPreviewDisplayer->SetVisibility(false);
1583 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1586 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1587 // check if there are memory problems
1588 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1589 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1591 catch(const SALOME::SALOME_Exception & S_ex){
1596 aMemoryReserve.release();
1598 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1599 bool noHypoError = ( aHypErrors.isEmpty() );
1601 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1602 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1604 bool isShowError = true;
1605 switch( aNotifyMode ) {
1606 case 0: // show the mesh computation result dialog NEVER
1607 isShowError = false;
1609 case 1: // show the mesh computation result dialog if there are some errors
1610 default: // show the result dialog after each mesh computation
1611 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1612 isShowError = false;
1616 aWaitCursor.suspend();
1621 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1622 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1627 //================================================================================
1629 * \brief Constructor
1631 //================================================================================
1633 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1634 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1637 setWindowTitle( tr( "CAPTION" ) );
1639 setButtonText( OK, tr( "COMPUTE" ) );
1640 QFrame* main = mainFrame();
1642 QVBoxLayout* layout = new QVBoxLayout( main );
1644 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1645 layout->addWidget(myOrderBox);
1647 QFrame* frame = new QFrame( main );
1648 layout->setMargin(0); layout->setSpacing(0);
1649 layout->addWidget( frame );
1651 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1652 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1654 myPreviewMode = new QtxComboBox( frame );
1655 frameLay->addWidget( myPreviewMode );
1657 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1658 frameLay->addWidget( myPreviewBtn );
1660 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1663 //================================================================================
1667 //================================================================================
1669 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1673 //================================================================================
1675 * \brief Sets available preview modes
1677 //================================================================================
1679 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1681 myPreviewMode->clear();
1682 QList<int>::const_iterator it = theModes.constBegin();
1683 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1685 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1686 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1687 myPreviewMode->setId( i, *it );
1689 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1692 //================================================================================
1694 * \brief Returns current preview mesh mode
1696 //================================================================================
1698 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1700 return myPreviewMode->currentId();
1703 //================================================================================
1705 * \brief Returns current preview mesh mode
1707 //================================================================================
1709 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1715 //================================================================================
1717 * \brief Constructor
1719 //================================================================================
1721 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1722 : SMESHGUI_BaseComputeOp()
1727 //================================================================================
1729 * \brief Desctructor
1731 //================================================================================
1733 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1737 //================================================================================
1739 * \brief perform it's intention action: compute mesh
1741 //================================================================================
1743 void SMESHGUI_EvaluateOp::startOperation()
1745 SMESHGUI_BaseComputeOp::evaluateDlg();
1746 SMESHGUI_BaseComputeOp::startOperation();
1747 if (myMesh->_is_nil())
1752 //================================================================================
1754 * \brief Gets dialog of this operation
1755 * \retval LightApp_Dialog* - pointer to dialog of this operation
1757 //================================================================================
1759 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1761 return evaluateDlg();
1764 //================================================================================
1766 * \brief evaluateMesh()
1768 //================================================================================
1770 void SMESHGUI_BaseComputeOp::evaluateMesh()
1774 SMESH::MemoryReserve aMemoryReserve;
1776 SMESH::compute_error_array_var aCompErrors;
1779 bool evaluateFailed = true, memoryLack = false;
1780 SMESH::long_array_var aRes;
1782 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1783 if ( !aMeshSObj ) // IPAL21340
1786 bool hasShape = myMesh->HasShapeToMesh();
1787 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1790 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1791 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1792 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1793 if ( errors->length() > 0 ) {
1794 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1796 SUIT_OverrideCursor aWaitCursor;
1798 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1801 aRes = gen->Evaluate(myMesh, myMainShape);
1803 catch(const SALOME::SALOME_Exception & S_ex){
1808 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1811 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1813 catch(const SALOME::SALOME_Exception & S_ex){
1819 aMemoryReserve.release();
1821 evaluateFailed = ( aCompErrors->length() > 0 );
1822 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1826 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1827 bool noHypoError = ( aHypErrors.isEmpty() );
1829 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1830 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1832 bool isShowResultDlg = true;
1834 //switch( aNotifyMode ) {
1835 //case 0: // show the mesh computation result dialog NEVER
1836 //isShowResultDlg = false;
1839 //case 1: // show the mesh computation result dialog if there are some errors
1840 //if ( memoryLack || !noHypoError )
1841 // isShowResultDlg = true;
1844 // isShowResultDlg = false;
1848 //default: // show the result dialog after each mesh computation
1849 //isShowResultDlg = true;
1853 if ( isShowResultDlg )
1854 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1855 noHypoError, aHypErrors);
1859 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1860 const bool theMemoryLack,
1861 const bool theNoCompError,
1862 SMESH::compute_error_array_var& theCompErrors,
1863 const bool theNoHypoError,
1864 const QString& theHypErrors)
1866 bool hasShape = myMesh->HasShapeToMesh();
1867 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1868 aCompDlg->myMemoryLackGroup->hide();
1870 if ( theMemoryLack )
1872 aCompDlg->myMemoryLackGroup->show();
1873 aCompDlg->myFullInfo->hide();
1874 aCompDlg->myBriefInfo->hide();
1875 aCompDlg->myHypErrorGroup->hide();
1876 aCompDlg->myCompErrorGroup->hide();
1878 else if ( theNoCompError && theNoHypoError )
1880 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1881 aCompDlg->myFullInfo->show();
1882 aCompDlg->myBriefInfo->hide();
1883 aCompDlg->myHypErrorGroup->hide();
1884 aCompDlg->myCompErrorGroup->hide();
1888 QTableWidget* tbl = aCompDlg->myTable;
1889 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1890 aCompDlg->myBriefInfo->show();
1891 aCompDlg->myFullInfo->hide();
1893 if ( theNoHypoError ) {
1894 aCompDlg->myHypErrorGroup->hide();
1897 aCompDlg->myHypErrorGroup->show();
1898 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1901 if ( theNoCompError ) {
1902 aCompDlg->myCompErrorGroup->hide();
1905 aCompDlg->myCompErrorGroup->show();
1907 aCompDlg->myPublishBtn->hide();
1908 aCompDlg->myShowBtn->hide();
1910 // fill table of errors
1911 tbl->setRowCount( theCompErrors->length() );
1912 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1913 else tbl->showColumn( COL_SHAPE );
1914 tbl->setColumnWidth( COL_ERROR, 200 );
1916 bool hasBadMesh = false;
1917 for ( int row = 0; row < theCompErrors->length(); ++row )
1919 SMESH::ComputeError & err = theCompErrors[ row ];
1921 QString text = err.algoName.in();
1922 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1923 else tbl->item( row, COL_ALGO )->setText( text );
1925 text = SMESH::errorText( err.code, err.comment.in() );
1926 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1927 else tbl->item( row, COL_ERROR )->setText( text );
1929 text = QString("%1").arg( err.subShapeID );
1930 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1931 else tbl->item( row, COL_SHAPEID )->setText( text );
1933 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1934 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1935 else tbl->item( row, COL_SHAPE )->setText( text );
1937 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1938 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1939 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1941 text = err.hasBadMesh ? "hasBadMesh" : "";
1942 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1943 else tbl->item( row, COL_BAD_MESH )->setText( text );
1944 if ( err.hasBadMesh ) hasBadMesh = true;
1946 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1947 tbl->resizeRowToContents( row );
1949 tbl->resizeColumnToContents( COL_ALGO );
1950 tbl->resizeColumnToContents( COL_SHAPE );
1953 aCompDlg->myBadMeshBtn->show();
1955 aCompDlg->myBadMeshBtn->hide();
1957 tbl->setCurrentCell(0,0);
1958 currentCellChanged(); // to update buttons
1961 // show dialog and wait, becase Compute can be invoked from Preview operation
1962 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1967 //================================================================================
1969 * \brief Gets dialog of evaluate operation
1970 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1972 //================================================================================
1974 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1978 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1979 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1980 // connect signals and slots
1981 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1982 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1983 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1984 QTableWidget* aTable = me->table();
1985 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1986 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));