1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_ComputeDlg.cxx
23 // Author : Edward AGAPOV, Open CASCADE S.A.S.
26 #include "SMESHGUI_ComputeDlg.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33 #include "SMESHGUI_HypothesesUtils.h"
34 #include "SMESHGUI_MeshEditPreview.h"
35 #include "SMESH_ActorUtils.h"
37 #include <SMDS_SetIterator.hxx>
38 #include <SMDS_Mesh.hxx>
40 // SALOME GEOM includes
42 #include <GEOM_Actor.h>
44 // SALOME GUI includes
45 #include <LightApp_SelectionMgr.h>
46 #include <LightApp_UpdateFlags.h>
47 #include <SALOME_ListIO.hxx>
48 #include <SVTK_ViewWindow.h>
49 #include <SVTK_ViewModel.h>
50 #include <SalomeApp_Application.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_Desktop.h>
55 #include <QtxComboBox.h>
57 // SALOME KERNEL includes
58 #include <SALOMEDS_SObject.hxx>
59 #include <SALOMEDSClient_SObject.hxx>
62 #include <BRep_Tool.hxx>
64 #include <TopExp_Explorer.hxx>
65 #include <TopTools_IndexedMapOfShape.hxx>
68 #include <TopLoc_Location.hxx>
69 #include <Poly_Triangulation.hxx>
70 #include <Bnd_Box.hxx>
71 #include <BRepBndLib.hxx>
72 #include <BRepMesh_IncrementalMesh.hxx>
74 #include <Standard_ErrorHandler.hxx>
78 #include <QPushButton>
80 #include <QRadioButton>
81 #include <QTableWidget>
82 #include <QHeaderView>
83 #include <QGridLayout>
84 #include <QHBoxLayout>
85 #include <QVBoxLayout>
86 #include <QButtonGroup>
89 #include <vtkProperty.h>
98 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
100 static void addSeparator( QWidget* parent )
102 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
103 int row = l->rowCount();
104 int cols = l->columnCount();
105 for ( int i = 0; i < cols; i++ ) {
106 QFrame* hline = new QFrame( parent );
107 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
108 l->addWidget( hline, row, i );
113 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
116 //using namespace SMESH;
120 //=============================================================================
122 * \brief Allocate some memory at construction and release it at destruction.
123 * Is used to be able to continue working after mesh generation or visualization
124 * break due to lack of memory
126 //=============================================================================
131 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
132 void release() { delete [] myBuf; myBuf = 0; }
133 ~MemoryReserve() { release(); }
136 // =========================================================================================
138 * \brief Class showing shapes without publishing
140 // =========================================================================================
142 class TShapeDisplayer
145 // -----------------------------------------------------------------------
146 TShapeDisplayer(): myViewWindow(0)
148 myProperty = vtkProperty::New();
149 myProperty->SetRepresentationToWireframe();
150 myProperty->SetColor( 250, 0, 250 );
151 myProperty->SetAmbientColor( 250, 0, 250 );
152 myProperty->SetDiffuseColor( 250, 0, 250 );
153 //myProperty->SetSpecularColor( 250, 0, 250 );
154 myProperty->SetLineWidth( 5 );
156 // -----------------------------------------------------------------------
160 myProperty->Delete();
162 // -----------------------------------------------------------------------
165 if ( hasViewWindow() ) {
166 TActorIterator actorIt = actorIterator();
167 while ( actorIt.more() )
168 if (VTKViewer_Actor* anActor = actorIt.next()) {
169 myViewWindow->RemoveActor( anActor );
173 myIndexToShape.Clear();
175 myShownActors.clear();
178 // -----------------------------------------------------------------------
179 void SetVisibility (bool theVisibility)
181 TActorIterator actorIt = shownIterator();
182 while ( actorIt.more() )
183 if (VTKViewer_Actor* anActor = actorIt.next())
184 anActor->SetVisibility(theVisibility);
185 SMESH::RepaintCurrentView();
187 // -----------------------------------------------------------------------
188 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
190 std::string mainEntry;
191 if ( !aMainShape->_is_nil() )
192 mainEntry = aMainShape->GetStudyEntry();
193 return ( myMainEntry == mainEntry &&
194 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
196 // -----------------------------------------------------------------------
197 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
199 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
200 std::string mainEntry;
201 if ( !aMainShape->_is_nil() )
202 mainEntry = aMainShape->GetStudyEntry();
203 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
206 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
207 checkTriangulation( aShape );
208 TopExp::MapShapes(aShape, myIndexToShape);
209 myActors.resize( myIndexToShape.Extent(), 0 );
210 myShownActors.reserve( myIndexToShape.Extent() );
212 myMainEntry = mainEntry;
213 myViewWindow = aViewWindow;
215 if ( only ) { // hide shown actors
216 TActorIterator actorIt = shownIterator();
217 while ( actorIt.more() )
218 if (VTKViewer_Actor* anActor = actorIt.next())
219 anActor->SetVisibility(false);
220 myShownActors.clear();
222 // find actors to show
223 TopoDS_Shape aShape = myIndexToShape( subShapeID );
224 if ( !aShape.IsNull() ) {
225 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
226 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
227 //checkTriangulation( exp.Current() );
228 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
229 myShownActors.push_back( anActor );
231 if ( type == TopAbs_FACE ) {
232 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
233 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
234 if ( !BRep_Tool::Degenerated( edge ))
235 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
236 myShownActors.push_back( anActor );
240 myBuiltSubs.insert( subShapeID );
243 // -----------------------------------------------------------------------
247 typedef std::vector<GEOM_Actor*> TActorVec;
249 TActorVec myShownActors;
250 TopTools_IndexedMapOfShape myIndexToShape;
251 std::string myMainEntry;
252 SVTK_ViewWindow* myViewWindow;
253 vtkProperty* myProperty;
254 std::set<int> myBuiltSubs;
256 // -----------------------------------------------------------------------
257 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
258 TActorIterator actorIterator() {
259 return TActorIterator( myActors.begin(), myActors.end() );
261 TActorIterator shownIterator() {
262 return TActorIterator( myShownActors.begin(), myShownActors.end() );
264 // -----------------------------------------------------------------------
265 GEOM_Actor* getActor(const TopoDS_Shape& shape)
267 int index = myIndexToShape.FindIndex( shape ) - 1;
268 if ( index < 0 || index >= myActors.size() )
270 GEOM_Actor* & actor = myActors[ index ];
272 actor = GEOM_Actor::New();
274 actor->SetShape(shape,0,0);
275 actor->SetProperty(myProperty);
276 actor->SetShadingProperty(myProperty);
277 actor->SetWireframeProperty(myProperty);
278 actor->SetPreviewProperty(myProperty);
279 actor->PickableOff();
280 // if ( shape.ShapeType() == TopAbs_EDGE )
281 // actor->SubShapeOn();
282 myViewWindow->AddActor( actor );
287 // -----------------------------------------------------------------------
288 void checkTriangulation(const TopoDS_Shape& shape)
290 TopLoc_Location aLoc;
291 Standard_Boolean alreadymesh = Standard_True;
292 TopExp_Explorer ex(shape, TopAbs_FACE);
294 for ( ; ex.More(); ex.Next()) {
295 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
296 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
297 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
300 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
301 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
302 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
303 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
305 if (alreadymesh) return;
306 // Compute default deflection
308 BRepBndLib::Add(shape, B);
309 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
310 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
311 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
312 BRepMesh_IncrementalMesh MESH(shape,deflection);
314 // -----------------------------------------------------------------------
315 bool hasViewWindow() const
317 if ( !myViewWindow ) return false;
319 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
320 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
326 // =========================================================================================
328 * \brief Return text describing an error
330 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
331 QString errorText(int errCode, const char* comment)
335 CASE2TEXT( COMPERR_OK );
336 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
337 CASE2TEXT( COMPERR_STD_EXCEPTION );
338 CASE2TEXT( COMPERR_OCC_EXCEPTION );
339 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
340 CASE2TEXT( COMPERR_EXCEPTION );
341 CASE2TEXT( COMPERR_MEMORY_PB );
342 CASE2TEXT( COMPERR_BAD_SHAPE );
343 case SMESH::COMPERR_ALGO_FAILED:
344 if ( strlen(comment) == 0 )
345 text = QObject::tr("COMPERR_ALGO_FAILED");
348 text = QString("#%1").arg( -errCode );
350 if ( text.length() > 0 ) text += ". ";
351 return text + comment;
353 // -----------------------------------------------------------------------
355 * \brief Return SO of a subshape
357 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
359 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
360 if ( subShapeID == 1 || !so )
362 _PTR(ChildIterator) it;
363 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
364 it = study->NewChildIterator(so);
367 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
368 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
369 if ( !geom->_is_nil() ) {
370 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
371 if ( list->length() == 1 && list[0] == subShapeID )
378 // -----------------------------------------------------------------------
380 * \brief Return subshape by ID
382 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
384 GEOM::GEOM_Object_var aSubShape;
385 if ( subShapeID == 1 )
386 aSubShape = aMainShape;
387 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
388 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
390 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
391 return aSubShape._retn();
393 // -----------------------------------------------------------------------
395 * \brief Return shape type name
397 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
398 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
401 if ( !aShape->_is_nil() ) {
402 switch ( aShape->GetShapeType() ) {
409 CASE2NAME( COMPSOLID );
410 CASE2NAME( COMPOUND );
416 // -----------------------------------------------------------------------
418 * \brief Return text describing a subshape
420 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
423 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
424 text = aSO->GetName().c_str();
426 text = QString("#%1").arg( subShapeID );
427 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
428 if ( typeName.length() )
429 text += QString(" (%1)").arg(typeName);
433 // -----------------------------------------------------------------------
435 * \brief Return a list of selected rows
437 int getSelectedRows(QTableWidget* table, QList<int>& rows)
440 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
441 QTableWidgetSelectionRange range;
442 foreach( range, selRanges )
444 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
447 if ( rows.isEmpty() && table->currentRow() > -1 )
448 rows.append( table->currentRow() );
456 // =========================================================================================
458 * \brief Dialog to compute a mesh and show computation errors
460 //=======================================================================
462 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
463 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
465 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
466 aDlgLay->setMargin( 0 );
467 aDlgLay->setSpacing( SPACING );
469 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
471 aDlgLay->addWidget(aMainFrame);
473 aDlgLay->setStretchFactor(aMainFrame, 1);
476 // =========================================================================================
480 //=======================================================================
482 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
486 //=======================================================================
487 // function : createMainFrame()
488 // purpose : Create frame containing dialog's fields
489 //=======================================================================
491 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
493 QFrame* aFrame = new QFrame(theParent);
495 SUIT_ResourceMgr* rm = resourceMgr();
496 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
502 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
505 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
507 QButtonGroup* aBtnGrp = new QButtonGroup(this);
508 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
509 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
511 QRadioButton* aRBut = new QRadioButton(aPixGrp);
512 aRBut->setIcon(iconCompute);
513 aRBut->setChecked(true);
514 aPixGrpLayout->addWidget(aRBut);
515 aBtnGrp->addButton(aRBut, 0);
519 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
520 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
521 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
522 myMeshName = new QLabel(nameBox);
523 nameBoxLayout->addWidget(myMeshName);
527 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
528 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
530 // Computation errors
532 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
533 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
534 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
535 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
536 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
538 //myTable->setReadOnly( true ); // VSR: check
539 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
540 myTable->hideColumn( COL_PUBLISHED );
541 myTable->hideColumn( COL_SHAPEID );
542 myTable->hideColumn( COL_BAD_MESH );
543 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
546 headers << tr( "COL_ALGO_HEADER" );
547 headers << tr( "COL_SHAPE_HEADER" );
548 headers << tr( "COL_ERROR_HEADER" );
549 headers << tr( "COL_SHAPEID_HEADER" );
550 headers << tr( "COL_PUBLISHED_HEADER" );
552 myTable->setHorizontalHeaderLabels( headers );
555 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
556 grpLayout->setSpacing(SPACING);
557 grpLayout->setMargin(MARGIN);
558 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
559 grpLayout->addWidget( myShowBtn, 0, 1 );
560 grpLayout->addWidget( myPublishBtn, 1, 1 );
561 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
562 grpLayout->setRowStretch( 3, 1 );
564 // Hypothesis definition errors
566 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
567 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
568 myHypErrorGroupLayout->setMargin(MARGIN);
569 myHypErrorGroupLayout->setSpacing(SPACING);
570 myHypErrorLabel = new QLabel(myHypErrorGroup);
571 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
575 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
576 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
577 myMemoryLackGroupLayout->setMargin(MARGIN);
578 myMemoryLackGroupLayout->setSpacing(SPACING);
579 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
580 QFont bold = memLackLabel->font(); bold.setBold(true);
581 memLackLabel->setFont( bold );
582 memLackLabel->setMinimumWidth(300);
583 myMemoryLackGroupLayout->addWidget(memLackLabel);
585 // add all widgets to aFrame
586 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
587 aLay->setMargin( 0 );
588 aLay->setSpacing( 0 );
589 aLay->addWidget( aPixGrp );
590 aLay->addWidget( nameBox );
591 aLay->addWidget( myBriefInfo );
592 aLay->addWidget( myFullInfo );
593 aLay->addWidget( myHypErrorGroup );
594 aLay->addWidget( myCompErrorGroup );
595 aLay->addWidget( myMemoryLackGroup );
596 aLay->setStretchFactor( myCompErrorGroup, 1 );
598 ((QPushButton*) button( OK ))->setDefault( true );
603 //================================================================================
607 //================================================================================
609 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
610 : SMESHGUI_Operation(), myCompDlg( 0 )
612 myTShapeDisplayer = new SMESH::TShapeDisplayer();
613 myBadMeshDisplayer = 0;
615 //myHelpFileName = "/files/about_meshes.htm"; // V3
616 myHelpFileName = "about_meshes_page.html"; // V4
619 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
621 LightApp_SelectionMgr* Sel = selectionMgr();
622 SALOME_ListIO selected; Sel->selectedObjects( selected );
623 Handle(SALOME_InteractiveObject) anIO = selected.First();
624 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
625 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
628 //================================================================================
630 * \brief Start operation
631 * \purpose Init dialog fields, connect signals and slots, show dialog
633 //================================================================================
635 void SMESHGUI_BaseComputeOp::startOperation()
637 // create compute dialog if not created before
640 myMesh = SMESH::SMESH_Mesh::_nil();
641 myMainShape = GEOM::GEOM_Object::_nil();
644 LightApp_SelectionMgr *Sel = selectionMgr();
645 SALOME_ListIO selected; Sel->selectedObjects( selected );
647 int nbSel = selected.Extent();
649 SUIT_MessageBox::warning(desktop(),
650 tr("SMESH_WRN_WARNING"),
651 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
656 myIObject = selected.First();
657 myMesh = SMESH::GetMeshByIO(myIObject);
658 if (myMesh->_is_nil()) {
659 SUIT_MessageBox::warning(desktop(),
660 tr("SMESH_WRN_WARNING"),
661 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
665 myMainShape = myMesh->GetShapeToMesh();
667 SMESHGUI_Operation::startOperation();
670 //================================================================================
672 * \brief computeMesh()
674 //================================================================================
676 void SMESHGUI_BaseComputeOp::computeMesh()
680 SMESH::MemoryReserve aMemoryReserve;
682 SMESH::compute_error_array_var aCompErrors;
685 bool computeFailed = true, memoryLack = false;
687 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
688 if ( !aMeshSObj ) // IPAL 21340
690 bool hasShape = myMesh->HasShapeToMesh();
691 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
694 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
695 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
696 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
697 if ( errors->length() > 0 ) {
698 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
700 SUIT_OverrideCursor aWaitCursor;
702 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
705 if (gen->Compute(myMesh, myMainShape))
706 computeFailed = false;
708 catch(const SALOME::SALOME_Exception & S_ex){
712 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
715 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
716 // check if there are memory problems
717 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
718 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
720 catch(const SALOME::SALOME_Exception & S_ex){
724 // NPAL16631: if ( !memoryLack )
726 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
727 update( UF_ObjBrowser | UF_Model );
730 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
731 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
734 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
737 SMESH::Update(myIObject, true);
741 MESSAGE ( "Exception thrown during mesh visualization" );
743 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
744 SMESH::OnVisuException();
751 LightApp_SelectionMgr *Sel = selectionMgr();
754 SALOME_ListIO selected;
755 selected.Append( myIObject );
756 Sel->setSelectedObjects( selected );
762 aMemoryReserve.release();
764 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
768 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
769 bool noHypoError = ( aHypErrors.isEmpty() );
771 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
772 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
774 bool isShowResultDlg = true;
775 switch( aNotifyMode ) {
776 case 0: // show the mesh computation result dialog NEVER
777 isShowResultDlg = false;
780 case 1: // show the mesh computation result dialog if there are some errors
781 if ( memoryLack || !noCompError || !noHypoError )
782 isShowResultDlg = true;
785 isShowResultDlg = false;
789 default: // show the result dialog after each mesh computation
790 isShowResultDlg = true;
794 if ( isShowResultDlg )
795 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
798 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
799 const bool theNoCompError,
800 SMESH::compute_error_array_var& theCompErrors,
801 const bool theNoHypoError,
802 const QString& theHypErrors )
804 bool hasShape = myMesh->HasShapeToMesh();
805 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
806 aCompDlg->myMemoryLackGroup->hide();
810 aCompDlg->myMemoryLackGroup->show();
811 aCompDlg->myFullInfo->hide();
812 aCompDlg->myBriefInfo->hide();
813 aCompDlg->myHypErrorGroup->hide();
814 aCompDlg->myCompErrorGroup->hide();
816 else if ( theNoCompError && theNoHypoError )
818 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
819 aCompDlg->myFullInfo->SetMeshInfo( aRes );
820 aCompDlg->myFullInfo->show();
821 aCompDlg->myBriefInfo->hide();
822 aCompDlg->myHypErrorGroup->hide();
823 aCompDlg->myCompErrorGroup->hide();
827 QTableWidget* tbl = aCompDlg->myTable;
828 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
829 aCompDlg->myFullInfo->SetMeshInfo( aRes );
830 aCompDlg->myBriefInfo->show();
831 aCompDlg->myFullInfo->hide();
833 if ( theNoHypoError ) {
834 aCompDlg->myHypErrorGroup->hide();
837 aCompDlg->myHypErrorGroup->show();
838 aCompDlg->myHypErrorLabel->setText( theHypErrors );
841 if ( theNoCompError ) {
842 aCompDlg->myCompErrorGroup->hide();
845 aCompDlg->myCompErrorGroup->show();
848 aCompDlg->myPublishBtn->hide();
849 aCompDlg->myShowBtn->hide();
852 aCompDlg->myPublishBtn->show();
853 aCompDlg->myShowBtn->show();
856 // fill table of errors
857 tbl->setRowCount( theCompErrors->length() );
858 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
859 else tbl->showColumn( COL_SHAPE );
860 tbl->setColumnWidth( COL_ERROR, 200 );
862 bool hasBadMesh = false;
863 for ( int row = 0; row < theCompErrors->length(); ++row )
865 SMESH::ComputeError & err = theCompErrors[ row ];
867 QString text = err.algoName.in();
868 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
869 else tbl->item( row, COL_ALGO )->setText( text );
871 text = SMESH::errorText( err.code, err.comment.in() );
872 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
873 else tbl->item( row, COL_ERROR )->setText( text );
875 text = QString("%1").arg( err.subShapeID );
876 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
877 else tbl->item( row, COL_SHAPEID )->setText( text );
879 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
880 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
881 else tbl->item( row, COL_SHAPE )->setText( text );
883 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
884 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
885 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
887 text = err.hasBadMesh ? "hasBadMesh" : "";
888 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
889 else tbl->item( row, COL_BAD_MESH )->setText( text );
890 if ( err.hasBadMesh ) hasBadMesh = true;
892 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
893 tbl->resizeRowToContents( row );
895 tbl->resizeColumnToContents( COL_ALGO );
896 tbl->resizeColumnToContents( COL_SHAPE );
899 aCompDlg->myBadMeshBtn->show();
901 aCompDlg->myBadMeshBtn->hide();
903 tbl->setCurrentCell(0,0);
904 currentCellChanged(); // to update buttons
907 // show dialog and wait, becase Compute can be invoked from Preview operation
908 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
912 //================================================================================
914 * \brief Stops operation
916 //================================================================================
918 void SMESHGUI_BaseComputeOp::stopOperation()
920 SMESHGUI_Operation::stopOperation();
921 if ( myTShapeDisplayer )
922 myTShapeDisplayer->SetVisibility( false );
923 if ( myBadMeshDisplayer ) {
924 myBadMeshDisplayer->SetVisibility( false );
925 // delete it in order not to have problems at its destruction when the viewer
926 // where it worked is dead due to e.g. study closing
927 delete myBadMeshDisplayer;
928 myBadMeshDisplayer = 0;
933 //================================================================================
935 * \brief publish selected subshape
937 //================================================================================
939 void SMESHGUI_BaseComputeOp::onPublishShape()
941 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
942 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
945 SMESH::getSelectedRows( table(), rows );
947 foreach ( row, rows )
949 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
950 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
951 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
953 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
955 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
956 SALOMEDS::SObject_var so =
957 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
958 // look for myMainShape in the table
959 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
960 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
961 if ( so->_is_nil() ) {
962 table()->item( r, COL_SHAPE )->setText( so->GetName() );
963 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
968 if ( curSub == 1 ) continue;
970 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
971 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
972 if ( !so->_is_nil() ) {
973 table()->item( row, COL_SHAPE )->setText( so->GetName() );
974 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
978 getSMESHGUI()->getApp()->updateObjectBrowser();
979 currentCellChanged(); // to update buttons
982 //================================================================================
984 * \brief show mesh elements preventing computation of a submesh of current row
986 //================================================================================
988 void SMESHGUI_BaseComputeOp::onShowBadMesh()
990 myTShapeDisplayer->SetVisibility( false );
992 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
993 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
995 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
996 SMESHGUI* gui = getSMESHGUI();
997 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
998 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
999 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1000 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1001 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1002 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1003 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1004 // delete property !!!!!!!!!!
1005 vtkProperty* prop = vtkProperty::New();
1006 prop->SetLineWidth( aLineWidth * 3 );
1007 prop->SetPointSize( aPointSize * 3 );
1008 prop->SetColor( 250, 0, 250 );
1009 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1010 myBadMeshDisplayer->SetData( aMeshData._retn() );
1015 //================================================================================
1017 * \brief SLOT called when a selected cell in table() changed
1019 //================================================================================
1021 void SMESHGUI_BaseComputeOp::currentCellChanged()
1023 myTShapeDisplayer->SetVisibility( false );
1024 if ( myBadMeshDisplayer )
1025 myBadMeshDisplayer->SetVisibility( false );
1027 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1029 int nbSelected = SMESH::getSelectedRows( table(), rows );
1031 foreach ( row, rows )
1033 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1034 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1035 if ( hasData && !isPublished )
1036 publishEnable = true;
1038 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1039 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1041 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1048 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1051 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1052 myCompDlg->myShowBtn ->setEnabled( showEnable );
1053 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1056 //================================================================================
1058 * \brief update preview
1060 //================================================================================
1062 void SMESHGUI_BaseComputeOp::onPreviewShape()
1064 if ( myTShapeDisplayer )
1066 SUIT_OverrideCursor aWaitCursor;
1068 SMESH::getSelectedRows( table(), rows );
1070 bool showOnly = true;
1072 foreach ( row, rows )
1074 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1076 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1080 currentCellChanged(); // to update buttons
1084 //================================================================================
1088 //================================================================================
1090 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1094 delete myTShapeDisplayer;
1095 if ( myBadMeshDisplayer )
1096 delete myBadMeshDisplayer;
1099 //================================================================================
1101 * \brief Gets dialog of compute operation
1102 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1104 //================================================================================
1106 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1110 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1111 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1112 // connect signals and slots
1113 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1114 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1115 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1117 QTableWidget* aTable = me->table();
1118 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1119 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1124 //================================================================================
1126 * \brief returns from compute mesh result dialog
1128 //================================================================================
1130 bool SMESHGUI_BaseComputeOp::onApply()
1135 //================================================================================
1137 * \brief Return a table
1139 //================================================================================
1141 QTableWidget* SMESHGUI_BaseComputeOp::table()
1143 return myCompDlg->myTable;
1147 //================================================================================
1149 * \brief Constructor
1151 //================================================================================
1153 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1154 : SMESHGUI_BaseComputeOp()
1159 //================================================================================
1161 * \brief Desctructor
1163 //================================================================================
1165 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1169 //================================================================================
1171 * \brief perform it's intention action: compute mesh
1173 //================================================================================
1175 void SMESHGUI_ComputeOp::startOperation()
1177 SMESHGUI_BaseComputeOp::startOperation();
1178 if (myMesh->_is_nil())
1183 //================================================================================
1185 * \brief check the same operations on the same mesh
1187 //================================================================================
1189 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1191 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1193 if ( !myMesh->_is_nil() && baseOp ) {
1194 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1195 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1200 //================================================================================
1202 * \brief Gets dialog of this operation
1203 * \retval LightApp_Dialog* - pointer to dialog of this operation
1205 //================================================================================
1207 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1209 return computeDlg();
1212 //================================================================================
1214 * \brief Constructor
1216 //================================================================================
1218 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1219 : SMESHGUI_BaseComputeOp(),
1222 myPreviewDisplayer( 0 )
1224 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1227 //================================================================================
1231 //================================================================================
1233 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1238 if ( myPreviewDisplayer )
1239 delete myPreviewDisplayer;
1240 myPreviewDisplayer = 0;
1243 //================================================================================
1245 * \brief Gets current dialog of this operation
1246 * \retval LightApp_Dialog* - pointer to dialog of this operation
1248 //================================================================================
1250 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1255 //================================================================================
1257 * \brief perform it's intention action: prepare data
1259 //================================================================================
1261 void SMESHGUI_PrecomputeOp::startOperation()
1265 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1268 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1269 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1270 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1272 myActiveDlg = myDlg;
1274 // connect signal to compute dialog. which will be shown after Compute mesh operation
1275 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1278 // disconnect signals
1279 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1280 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1281 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1282 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1283 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1286 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1287 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1288 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1289 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1290 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1291 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1292 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1293 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1294 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1295 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1298 SMESHGUI_BaseComputeOp::startOperation();
1299 if (myMesh->_is_nil())
1302 // disconnect slot from preview dialog to have Apply from results of compute operation only
1303 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1304 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1309 //================================================================================
1311 * \brief Stops operation
1313 //================================================================================
1315 void SMESHGUI_PrecomputeOp::stopOperation()
1317 if ( myPreviewDisplayer )
1319 myPreviewDisplayer->SetVisibility( false );
1320 delete myPreviewDisplayer;
1321 myPreviewDisplayer = 0;
1323 myMapShapeId.clear();
1324 SMESHGUI_BaseComputeOp::stopOperation();
1327 //================================================================================
1329 * \brief reinitialize dialog after operaiton become active again
1331 //================================================================================
1333 void SMESHGUI_PrecomputeOp::resumeOperation()
1335 if ( myActiveDlg == myDlg )
1337 SMESHGUI_BaseComputeOp::resumeOperation();
1340 //================================================================================
1342 * \brief perform it's intention action: reinitialise dialog
1344 //================================================================================
1346 void SMESHGUI_PrecomputeOp::initDialog()
1350 QMap<int, int> modeMap;
1351 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1352 getAssignedAlgos( pMesh, modeMap );
1353 if ( modeMap.contains( SMESH::DIM_3D ) )
1355 if ( modeMap.contains( SMESH::DIM_2D ) )
1356 modes.append( SMESH::DIM_2D );
1357 if ( modeMap.contains( SMESH::DIM_1D ) )
1358 modes.append( SMESH::DIM_1D );
1360 else if ( modeMap.contains( SMESH::DIM_2D ) )
1362 if ( modeMap.contains( SMESH::DIM_1D ) )
1363 modes.append( SMESH::DIM_1D );
1366 myDlg->setPreviewModes( modes );
1369 //================================================================================
1371 * \brief detect asigned mesh algorithms
1373 //================================================================================
1375 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1376 QMap<int,int>& theModeMap)
1378 _PTR(SObject) aHypRoot;
1379 _PTR(GenericAttribute) anAttr;
1380 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1381 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1383 _PTR(ChildIterator) anIter =
1384 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1385 for ( ; anIter->More(); anIter->Next() )
1387 _PTR(SObject) anObj = anIter->Value();
1388 _PTR(SObject) aRefObj;
1389 if ( anObj->ReferencedObject( aRefObj ) )
1394 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1396 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1397 if ( CORBA::is_nil( aVar ) )
1400 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1402 SMESH::SMESH_Algo_var algo;
1404 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1405 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1406 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1409 if ( !algo->_is_nil() )
1410 theModeMap[ dim ] = 0;
1417 //================================================================================
1419 * \brief perform it's intention action: compute mesh
1421 //================================================================================
1423 void SMESHGUI_PrecomputeOp::onCompute()
1426 myMapShapeId.clear();
1427 myActiveDlg = computeDlg();
1431 //================================================================================
1433 * \brief perform it's intention action: compute mesh
1435 //================================================================================
1437 void SMESHGUI_PrecomputeOp::onCancel()
1439 QObject* curDlg = sender();
1440 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1442 // return from error messages
1447 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1449 // ask to remove already computed mesh elements
1450 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1451 tr( "CLEAR_SUBMESH_QUESTION" ),
1452 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1454 // remove all submeshes for collected shapes
1455 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1456 for ( ; it != myMapShapeId.constEnd(); ++it )
1457 myMesh->ClearSubMesh( *it );
1460 myMapShapeId.clear();
1461 SMESHGUI_BaseComputeOp::onCancel();
1464 //================================================================================
1466 * \brief perform it's intention action: preview mesh
1468 //================================================================================
1470 void SMESHGUI_PrecomputeOp::onPreview()
1472 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1475 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1478 // Compute preview of mesh,
1479 // i.e. compute mesh till indicated dimension
1480 int dim = myDlg->getPreviewMode();
1482 SMESH::MemoryReserve aMemoryReserve;
1484 SMESH::compute_error_array_var aCompErrors;
1487 bool computeFailed = true, memoryLack = false;
1489 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1490 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1492 SMESHGUI* gui = getSMESHGUI();
1493 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1494 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1495 if ( errors->length() > 0 ) {
1496 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1499 SUIT_OverrideCursor aWaitCursor;
1501 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1502 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1503 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1505 SMESH::long_array_var aShapesId = new SMESH::long_array();
1507 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1511 SMESH::MeshPreviewStruct_var previewData =
1512 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1513 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1514 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1516 computeFailed = false;
1517 myPreviewDisplayer->SetData( previewRes );
1518 // append shape indeces with computed mesh entities
1519 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1520 myMapShapeId[ aShapesId[ i ] ] = 0;
1523 myPreviewDisplayer->SetVisibility(false);
1525 catch(const SALOME::SALOME_Exception & S_ex){
1527 myPreviewDisplayer->SetVisibility(false);
1531 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1534 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1535 // check if there are memory problems
1536 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1537 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1539 catch(const SALOME::SALOME_Exception & S_ex){
1544 aMemoryReserve.release();
1546 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1547 bool noHypoError = ( aHypErrors.isEmpty() );
1549 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1550 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1552 bool isShowError = true;
1553 switch( aNotifyMode ) {
1554 case 0: // show the mesh computation result dialog NEVER
1555 isShowError = false;
1557 case 1: // show the mesh computation result dialog if there are some errors
1558 default: // show the result dialog after each mesh computation
1559 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1560 isShowError = false;
1564 aWaitCursor.suspend();
1569 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1570 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1575 //================================================================================
1577 * \brief Constructor
1579 //================================================================================
1581 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1582 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help )
1584 setWindowTitle( tr( "CAPTION" ) );
1586 setButtonText( OK, tr( "COMPUTE" ) );
1587 QFrame* main = mainFrame();
1589 QVBoxLayout* layout = new QVBoxLayout( main );
1591 QFrame* frame = new QFrame( main );
1592 layout->setMargin(0); layout->setSpacing(0);
1593 layout->addWidget( frame );
1595 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1596 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1598 myPreviewMode = new QtxComboBox( frame );
1599 frameLay->addWidget( myPreviewMode );
1601 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1602 frameLay->addWidget( myPreviewBtn );
1604 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1607 //================================================================================
1611 //================================================================================
1613 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1617 //================================================================================
1619 * \brief Sets available preview modes
1621 //================================================================================
1623 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1625 myPreviewMode->clear();
1626 QList<int>::const_iterator it = theModes.constBegin();
1627 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1629 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1630 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1631 myPreviewMode->setId( i, *it );
1633 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1636 //================================================================================
1638 * \brief Returns current preview mesh mode
1640 //================================================================================
1642 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1644 return myPreviewMode->currentId();
1648 //================================================================================
1650 * \brief Constructor
1652 //================================================================================
1654 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1655 : SMESHGUI_BaseComputeOp()
1660 //================================================================================
1662 * \brief Desctructor
1664 //================================================================================
1666 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1670 //================================================================================
1672 * \brief perform it's intention action: compute mesh
1674 //================================================================================
1676 void SMESHGUI_EvaluateOp::startOperation()
1678 SMESHGUI_BaseComputeOp::evaluateDlg();
1679 SMESHGUI_BaseComputeOp::startOperation();
1680 if (myMesh->_is_nil())
1685 //================================================================================
1687 * \brief Gets dialog of this operation
1688 * \retval LightApp_Dialog* - pointer to dialog of this operation
1690 //================================================================================
1692 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1694 return evaluateDlg();
1697 //================================================================================
1699 * \brief evaluateMesh()
1701 //================================================================================
1703 void SMESHGUI_BaseComputeOp::evaluateMesh()
1707 SMESH::MemoryReserve aMemoryReserve;
1709 SMESH::compute_error_array_var aCompErrors;
1712 bool evaluateFailed = true, memoryLack = false;
1713 SMESH::long_array_var aRes;
1715 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1716 if ( !aMeshSObj ) // IPAL21340
1719 bool hasShape = myMesh->HasShapeToMesh();
1720 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1723 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1724 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1725 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1726 if ( errors->length() > 0 ) {
1727 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1729 SUIT_OverrideCursor aWaitCursor;
1731 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1734 aRes = gen->Evaluate(myMesh, myMainShape);
1736 catch(const SALOME::SALOME_Exception & S_ex){
1741 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1744 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1746 catch(const SALOME::SALOME_Exception & S_ex){
1752 aMemoryReserve.release();
1754 evaluateFailed = ( aCompErrors->length() > 0 );
1755 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1759 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1760 bool noHypoError = ( aHypErrors.isEmpty() );
1762 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1763 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1765 bool isShowResultDlg = true;
1767 //switch( aNotifyMode ) {
1768 //case 0: // show the mesh computation result dialog NEVER
1769 //isShowResultDlg = false;
1772 //case 1: // show the mesh computation result dialog if there are some errors
1773 //if ( memoryLack || !noHypoError )
1774 // isShowResultDlg = true;
1777 // isShowResultDlg = false;
1781 //default: // show the result dialog after each mesh computation
1782 //isShowResultDlg = true;
1786 if ( isShowResultDlg )
1787 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1788 noHypoError, aHypErrors);
1792 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1793 const bool theMemoryLack,
1794 const bool theNoCompError,
1795 SMESH::compute_error_array_var& theCompErrors,
1796 const bool theNoHypoError,
1797 const QString& theHypErrors)
1799 bool hasShape = myMesh->HasShapeToMesh();
1800 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1801 aCompDlg->myMemoryLackGroup->hide();
1803 if ( theMemoryLack )
1805 aCompDlg->myMemoryLackGroup->show();
1806 aCompDlg->myFullInfo->hide();
1807 aCompDlg->myBriefInfo->hide();
1808 aCompDlg->myHypErrorGroup->hide();
1809 aCompDlg->myCompErrorGroup->hide();
1811 else if ( theNoCompError && theNoHypoError )
1813 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1814 aCompDlg->myFullInfo->show();
1815 aCompDlg->myBriefInfo->hide();
1816 aCompDlg->myHypErrorGroup->hide();
1817 aCompDlg->myCompErrorGroup->hide();
1821 QTableWidget* tbl = aCompDlg->myTable;
1822 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1823 aCompDlg->myBriefInfo->show();
1824 aCompDlg->myFullInfo->hide();
1826 if ( theNoHypoError ) {
1827 aCompDlg->myHypErrorGroup->hide();
1830 aCompDlg->myHypErrorGroup->show();
1831 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1834 if ( theNoCompError ) {
1835 aCompDlg->myCompErrorGroup->hide();
1838 aCompDlg->myCompErrorGroup->show();
1840 aCompDlg->myPublishBtn->hide();
1841 aCompDlg->myShowBtn->hide();
1843 // fill table of errors
1844 tbl->setRowCount( theCompErrors->length() );
1845 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1846 else tbl->showColumn( COL_SHAPE );
1847 tbl->setColumnWidth( COL_ERROR, 200 );
1849 bool hasBadMesh = false;
1850 for ( int row = 0; row < theCompErrors->length(); ++row )
1852 SMESH::ComputeError & err = theCompErrors[ row ];
1854 QString text = err.algoName.in();
1855 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1856 else tbl->item( row, COL_ALGO )->setText( text );
1858 text = SMESH::errorText( err.code, err.comment.in() );
1859 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1860 else tbl->item( row, COL_ERROR )->setText( text );
1862 text = QString("%1").arg( err.subShapeID );
1863 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1864 else tbl->item( row, COL_SHAPEID )->setText( text );
1866 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1867 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1868 else tbl->item( row, COL_SHAPE )->setText( text );
1870 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1871 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1872 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1874 text = err.hasBadMesh ? "hasBadMesh" : "";
1875 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1876 else tbl->item( row, COL_BAD_MESH )->setText( text );
1877 if ( err.hasBadMesh ) hasBadMesh = true;
1879 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1880 tbl->resizeRowToContents( row );
1882 tbl->resizeColumnToContents( COL_ALGO );
1883 tbl->resizeColumnToContents( COL_SHAPE );
1886 aCompDlg->myBadMeshBtn->show();
1888 aCompDlg->myBadMeshBtn->hide();
1890 tbl->setCurrentCell(0,0);
1891 currentCellChanged(); // to update buttons
1894 // show dialog and wait, becase Compute can be invoked from Preview operation
1895 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1900 //================================================================================
1902 * \brief Gets dialog of evaluate operation
1903 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1905 //================================================================================
1907 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1911 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1912 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1913 // connect signals and slots
1914 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1915 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1916 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1917 QTableWidget* aTable = me->table();
1918 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1919 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));