1 // Copyright (C) 2007-2015 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, or (at your option) any later version.
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"
26 #include "SMDS_Mesh.hxx"
27 #include "SMDS_SetIterator.hxx"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_HypothesesUtils.h"
31 #include "SMESHGUI_MeshEditPreview.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33 #include "SMESHGUI_MeshOrderDlg.h"
34 #include "SMESHGUI_MeshOrderOp.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_VTKUtils.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_ActorUtils.h"
40 // SALOME GEOM includes
42 #include <GEOM_Actor.h>
43 #include <GEOM_wrap.hxx>
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_UpdateFlags.h>
48 #include <QtxComboBox.h>
49 #include <SALOME_ListIO.hxx>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SVTK_ViewModel.h>
56 #include <SVTK_ViewWindow.h>
57 #include <SalomeApp_Application.h>
59 // SALOME KERNEL includes
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDSClient_SObject.hxx>
62 #include <SALOMEDS_wrap.hxx>
63 #include "utilities.h"
65 #include CORBA_SERVER_HEADER(SMESH_Group)
68 #include <BRepBndLib.hxx>
69 #include <BRepMesh_IncrementalMesh.hxx>
70 #include <BRep_Tool.hxx>
71 #include <Bnd_Box.hxx>
72 #include <Poly_Triangulation.hxx>
74 #include <TopExp_Explorer.hxx>
75 #include <TopLoc_Location.hxx>
76 #include <TopTools_IndexedMapOfShape.hxx>
79 #include <Standard_ErrorHandler.hxx>
83 #include <QPushButton>
85 #include <QRadioButton>
86 #include <QTableWidget>
87 #include <QHeaderView>
88 #include <QGridLayout>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QButtonGroup>
92 #include <QCloseEvent>
93 #include <QTimerEvent>
94 #include <QProgressBar>
97 #include <vtkProperty.h>
104 #include <sys/sysinfo.h>
110 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
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 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( 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 int UNbIsos = resMgr->integerValue( "Geometry", "iso_number_u", 1);
231 int VNbIsos = resMgr->integerValue( "Geometry", "iso_number_v", 1);
232 int aNbIsos[2] = { UNbIsos ? UNbIsos : 1, VNbIsos ? VNbIsos : 1 };
233 anActor->SetNbIsos( aNbIsos );
234 myShownActors.push_back( anActor );
237 if ( type == TopAbs_FACE ) {
238 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
239 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
240 if ( !BRep_Tool::Degenerated( edge ))
241 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
242 myShownActors.push_back( anActor );
246 myBuiltSubs.insert( subShapeID );
249 // -----------------------------------------------------------------------
253 typedef std::vector<GEOM_Actor*> TActorVec;
255 TActorVec myShownActors;
256 TopTools_IndexedMapOfShape myIndexToShape;
257 std::string myMainEntry;
258 SVTK_ViewWindow* myViewWindow;
259 vtkProperty* myProperty;
260 std::set<int> myBuiltSubs;
262 // -----------------------------------------------------------------------
263 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
264 TActorIterator actorIterator() {
265 return TActorIterator( myActors.begin(), myActors.end() );
267 TActorIterator shownIterator() {
268 return TActorIterator( myShownActors.begin(), myShownActors.end() );
270 // -----------------------------------------------------------------------
271 GEOM_Actor* getActor(const TopoDS_Shape& shape)
273 int index = myIndexToShape.FindIndex( shape ) - 1;
274 if ( index < 0 || index >= myActors.size() )
276 GEOM_Actor* & actor = myActors[ index ];
278 actor = GEOM_Actor::New();
280 actor->SetShape(shape,0,0);
281 actor->SetProperty(myProperty);
282 actor->SetShadingProperty(myProperty);
283 actor->SetWireframeProperty(myProperty);
284 actor->SetPreviewProperty(myProperty);
285 actor->PickableOff();
286 // if ( shape.ShapeType() == TopAbs_EDGE )
287 // actor->SubShapeOn();
288 myViewWindow->AddActor( actor );
293 // -----------------------------------------------------------------------
294 void checkTriangulation(const TopoDS_Shape& shape)
296 TopLoc_Location aLoc;
297 Standard_Boolean alreadymesh = Standard_True;
298 TopExp_Explorer ex(shape, TopAbs_FACE);
300 for ( ; ex.More(); ex.Next()) {
301 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
302 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
303 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
306 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
307 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
308 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
309 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
311 if (alreadymesh) return;
312 // Compute default deflection
314 BRepBndLib::Add(shape, B);
315 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
316 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
317 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
318 BRepMesh_IncrementalMesh MESH(shape,deflection);
320 // -----------------------------------------------------------------------
321 bool hasViewWindow() const
323 if ( !myViewWindow ) return false;
325 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
326 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
332 // =========================================================================================
334 * \brief Return text describing an error
336 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
337 QString errorText(int errCode, const char* comment)
341 CASE2TEXT( COMPERR_OK );
342 CASE2TEXT( COMPERR_BAD_INPUT_MESH );
343 CASE2TEXT( COMPERR_STD_EXCEPTION );
344 CASE2TEXT( COMPERR_OCC_EXCEPTION );
345 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
346 CASE2TEXT( COMPERR_EXCEPTION );
347 CASE2TEXT( COMPERR_MEMORY_PB );
348 CASE2TEXT( COMPERR_BAD_SHAPE );
349 CASE2TEXT( COMPERR_CANCELED );
350 CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
351 CASE2TEXT( COMPERR_BAD_PARMETERS );
352 case SMESH::COMPERR_ALGO_FAILED:
353 if ( strlen(comment) == 0 )
354 text = QObject::tr("COMPERR_ALGO_FAILED");
356 case SMESH::COMPERR_WARNING:
357 text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
360 text = QString("#%1").arg( -errCode );
362 if ( text.length() > 0 ) text += ". ";
363 return text + comment;
365 // -----------------------------------------------------------------------
367 * \brief Return SO of a sub-shape
369 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
371 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
372 if ( subShapeID == 1 || !so )
374 _PTR(ChildIterator) it;
375 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
376 it = study->NewChildIterator(so);
379 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
380 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
381 if ( !geom->_is_nil() ) {
382 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
383 if ( list->length() == 1 && list[0] == subShapeID )
385 GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
386 if ( aMainShape->IsSame( mainGO ))
394 // -----------------------------------------------------------------------
396 * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
398 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
400 GEOM::GEOM_Object_var aSubShape;
401 if ( subShapeID == 1 ) {
402 aSubShape = aMainShape;
403 aSubShape->Register();
405 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
406 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
407 aSubShape->Register();
410 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
411 // future call of UnRegister() will delete a servant of this new object
413 return aSubShape._retn();
415 // -----------------------------------------------------------------------
417 * \brief Return shape type name
419 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
420 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
423 if ( !aShape->_is_nil() ) {
424 switch ( aShape->GetShapeType() ) {
431 CASE2NAME( COMPSOLID );
432 CASE2NAME( COMPOUND );
438 // -----------------------------------------------------------------------
440 * \brief Return text describing a sub-shape
442 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
445 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
446 text = aSO->GetName().c_str();
447 text += QString(" (%1)").arg( aSO->GetID().c_str() );
450 text = QString("#%1").arg( subShapeID );
451 GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
452 QString typeName = shapeTypeName( shape );
453 if ( typeName.length() )
454 text += QString(" (%1)").arg(typeName);
458 // -----------------------------------------------------------------------
460 * \brief Return a list of selected rows
462 int getSelectedRows(QTableWidget* table, QList<int>& rows)
465 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
466 QTableWidgetSelectionRange range;
467 foreach( range, selRanges )
469 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
470 if ( !rows.count( row ))
473 if ( rows.isEmpty() && table->currentRow() > -1 )
474 if ( !rows.count( table->currentRow() ))
475 rows.append( table->currentRow() );
483 // =========================================================================================
485 * \brief Dialog to compute a mesh and show computation errors
487 //=======================================================================
489 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
490 : SMESHGUI_Dialog( parent, false, true, Close | Help )
492 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
493 aDlgLay->setMargin( 0 );
494 aDlgLay->setSpacing( SPACING );
496 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
498 aDlgLay->addWidget(aMainFrame);
500 aDlgLay->setStretchFactor(aMainFrame, 1);
503 // =========================================================================================
507 //=======================================================================
509 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
513 //=======================================================================
514 // function : createMainFrame()
515 // purpose : Create frame containing dialog's fields
516 //=======================================================================
518 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
520 QFrame* aFrame = new QFrame(theParent);
522 SUIT_ResourceMgr* rm = resourceMgr();
523 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
529 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
532 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
534 QButtonGroup* aBtnGrp = new QButtonGroup(this);
535 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
536 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
538 QRadioButton* aRBut = new QRadioButton(aPixGrp);
539 aRBut->setIcon(iconCompute);
540 aRBut->setChecked(true);
541 aPixGrpLayout->addWidget(aRBut);
542 aBtnGrp->addButton(aRBut, 0);
546 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
547 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
548 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
549 myMeshName = new QLabel(nameBox);
550 nameBoxLayout->addWidget(myMeshName);
554 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
555 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
557 // Computation errors
559 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
560 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
561 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
562 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
563 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
564 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
565 myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
567 //myTable->setReadOnly( true ); // VSR: check
568 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
569 myTable->hideColumn( COL_PUBLISHED );
570 myTable->hideColumn( COL_SHAPEID );
571 myTable->hideColumn( COL_BAD_MESH );
572 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
573 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
575 myTable->horizontalHeader()->setSectionResizeMode( COL_ERROR, QHeaderView::Interactive );
577 myTable->setWordWrap( true );
578 myTable->horizontalHeader()->setStretchLastSection( true );
579 myTable->setMinimumWidth( 500 );
582 headers << tr( "COL_ALGO_HEADER" );
583 headers << tr( "COL_SHAPE_HEADER" );
584 headers << tr( "COL_ERROR_HEADER" );
585 headers << tr( "COL_SHAPEID_HEADER" );
586 headers << tr( "COL_PUBLISHED_HEADER" );
588 myTable->setHorizontalHeaderLabels( headers );
591 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
592 grpLayout->setSpacing(SPACING);
593 grpLayout->setMargin(MARGIN);
594 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
595 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
596 grpLayout->addWidget( myShowBtn, 2, 0 );
597 grpLayout->addWidget( myPublishBtn, 2, 1 );
598 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
599 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
600 grpLayout->setColumnStretch( 3, 1 );
602 // Hypothesis definition errors
604 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
605 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
606 myHypErrorGroupLayout->setMargin(MARGIN);
607 myHypErrorGroupLayout->setSpacing(SPACING);
608 myHypErrorLabel = new QLabel(myHypErrorGroup);
609 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
613 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
614 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
615 myMemoryLackGroupLayout->setMargin(MARGIN);
616 myMemoryLackGroupLayout->setSpacing(SPACING);
617 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
618 QFont bold = memLackLabel->font(); bold.setBold(true);
619 memLackLabel->setFont( bold );
620 memLackLabel->setMinimumWidth(300);
621 myMemoryLackGroupLayout->addWidget(memLackLabel);
623 // add all widgets to aFrame
624 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
625 aLay->setMargin( MARGIN );
626 aLay->setSpacing( SPACING );
627 aLay->addWidget( aPixGrp );
628 aLay->addWidget( nameBox );
629 aLay->addWidget( myBriefInfo );
630 aLay->addWidget( myFullInfo );
631 aLay->addWidget( myHypErrorGroup );
632 aLay->addWidget( myCompErrorGroup );
633 aLay->addWidget( myMemoryLackGroup );
634 aLay->setStretchFactor( myCompErrorGroup, 1 );
636 ((QPushButton*) button( OK ))->setDefault( true );
641 //================================================================================
645 //================================================================================
647 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
648 : SMESHGUI_Operation(), myCompDlg( 0 )
650 myTShapeDisplayer = new SMESH::TShapeDisplayer();
651 myBadMeshDisplayer = 0;
653 //myHelpFileName = "/files/about_meshes.htm"; // V3
654 myHelpFileName = "about_meshes_page.html"; // V4
657 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
659 LightApp_SelectionMgr* Sel = selectionMgr();
660 SALOME_ListIO selected; Sel->selectedObjects( selected );
661 Handle(SALOME_InteractiveObject) anIO = selected.First();
662 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
663 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
666 //================================================================================
668 * \brief Start operation
669 * \purpose Init dialog fields, connect signals and slots, show dialog
671 //================================================================================
673 void SMESHGUI_BaseComputeOp::startOperation()
675 // create compute dialog if not created before
678 myMesh = SMESH::SMESH_Mesh::_nil();
679 myMainShape = GEOM::GEOM_Object::_nil();
682 LightApp_SelectionMgr *Sel = selectionMgr();
683 SALOME_ListIO selected; Sel->selectedObjects( selected );
685 int nbSel = selected.Extent();
687 SUIT_MessageBox::warning(desktop(),
688 tr("SMESH_WRN_WARNING"),
689 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
694 myIObject = selected.First();
695 myMesh = SMESH::GetMeshByIO(myIObject);
696 if (myMesh->_is_nil()) {
697 SUIT_MessageBox::warning(desktop(),
698 tr("SMESH_WRN_WARNING"),
699 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
703 myMainShape = myMesh->GetShapeToMesh();
705 SMESHGUI_Operation::startOperation();
708 //================================================================================
709 //================================================================================
711 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
712 SMESH::SMESH_Mesh_var mesh,
713 GEOM::GEOM_Object_var mainShape)
718 myMainShape = mainShape;
721 void SMESHGUI_ComputeDlg_QThread::run()
723 myResult = myGen->Compute(myMesh, myMainShape);
726 bool SMESHGUI_ComputeDlg_QThread::result()
731 void SMESHGUI_ComputeDlg_QThread::cancel()
733 myGen->CancelCompute(myMesh, myMainShape);
736 //================================================================================
737 //================================================================================
739 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
740 SMESH::SMESH_Gen_var gen,
741 SMESH::SMESH_Mesh_var mesh,
742 GEOM::GEOM_Object_var mainShape)
744 Qt::WindowSystemMenuHint |
745 Qt::WindowCloseButtonHint |
747 Qt::WindowMaximizeButtonHint),
748 qthread(gen, mesh, mainShape)
751 setWindowTitle(tr("TITLE"));
752 setMinimumWidth( 200 );
754 cancelButton = new QPushButton(tr("CANCEL"));
755 cancelButton->setDefault(true);
756 cancelButton->setCheckable(true);
758 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
759 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
760 nbNodesLabel = new QLabel("0", this );
761 nbElemsLabel = new QLabel("0", this );
763 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
764 freeRAMLabel = new QLabel("", this );
766 progressBar = new QProgressBar(this);
767 progressBar->setMinimum( 0 );
768 progressBar->setMaximum( 1000 );
770 QGridLayout* layout = new QGridLayout(this);
771 layout->setMargin( MARGIN );
772 layout->setSpacing( SPACING );
774 layout->addWidget(nbNodesName, row, 0);
775 layout->addWidget(nbNodesLabel, row++, 1);
776 layout->addWidget(nbElemsName, row, 0);
777 layout->addWidget(nbElemsLabel, row++, 1);
779 layout->addWidget(freeRAMName, row, 0);
780 layout->addWidget(freeRAMLabel, row++, 1);
782 layout->addWidget(progressBar, row++, 0, 1, 2);
783 layout->addWidget(cancelButton, row++, 0, 1, 2);
787 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
789 startTimer(300); // millisecs
793 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
795 return qthread.result();
798 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
801 cancelButton->setText( tr("CANCELING"));
802 cancelButton->setEnabled(false);
805 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
807 if ( !cancelButton->isChecked() ) // not yet cancelled
808 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
810 if(qthread.isFinished())
816 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
817 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
820 const int err = sysinfo( &si );
822 freeRAMLabel->setText("");
824 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
825 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
831 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
833 if(qthread.isRunning())
841 //================================================================================
843 * \brief computeMesh()
845 //================================================================================
847 void SMESHGUI_BaseComputeOp::computeMesh()
851 SMESH::MemoryReserve aMemoryReserve;
853 SMESH::compute_error_array_var aCompErrors;
856 bool computeFailed = true, memoryLack = false;
858 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
859 if ( !aMeshSObj ) // IPAL 21340
861 bool hasShape = myMesh->HasShapeToMesh();
862 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
865 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
866 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
867 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
868 if ( errors->length() > 0 ) {
869 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
871 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
872 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
873 tr( "FULL_RECOMPUTE_QUESTION" ),
874 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
876 SUIT_OverrideCursor aWaitCursor;
878 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
881 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
882 qthreaddialog.exec();
883 computeFailed = !qthreaddialog.result();
885 catch(const SALOME::SALOME_Exception & S_ex) {
889 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
892 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
893 // check if there are memory problems
894 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
895 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
897 catch(const SALOME::SALOME_Exception & S_ex) {
901 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
905 // NPAL16631: if ( !memoryLack )
907 SMESH::ModifiedMesh( aMeshSObj,
908 !computeFailed && aHypErrors.isEmpty(),
909 myMesh->NbNodes() == 0);
910 update( UF_ObjBrowser | UF_Model );
913 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
914 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
916 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
917 int entities = SMESH_Actor::eAllEntity;
922 // List of objects that will be updated automatically
923 QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > aListToUpdate;
924 SMESH::SMESH_IDSource_var aMeshObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
925 // put Mesh into list
926 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aMeshObj, aMeshSObj) );
927 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
928 // put SubMeshes into list
929 for ( int i = 0; i < aSubMeshes->length(); i++ ) {
930 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
931 if ( CORBA::is_nil( sm ) ) continue;
932 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
933 if ( !smSObj ) continue;
934 SMESH::SMESH_IDSource_var aSubMeshObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
935 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aSubMeshObj, smSObj) );
937 // put Groups into list
938 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
939 for ( size_t i = 0; i < aGroups->length(); ++i ) {
940 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
941 if ( CORBA::is_nil( aGrp ) ) continue;
942 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
943 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGrp );
944 SMESH::SMESH_GroupOnFilter_var aFltGroup = SMESH::SMESH_GroupOnFilter::_narrow( aGrp );
945 if ( !aStdGroup->_is_nil() ) continue; // don't update the standalone groups
946 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
947 if ( !aGroupSO ) continue;
948 SMESH::SMESH_IDSource_var aGroupObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
949 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aGroupObj, aGroupSO) );
952 // update mesh, sub-mesh and groups, if it's possible
953 QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > >::iterator anIter;
954 for( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ ) {
955 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
956 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded, &hidden, &nbElements ) )
959 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
962 bool toDisplay = false;
964 if ( !aMesh->_is_nil() ) { // display a mesh only
966 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
967 if ( !anActor ) anActor = SMESH::CreateActor( (*anIter).second->GetStudy(), (*anIter).second->GetID().c_str(), true );
968 if ( anActor ) // actor is not created for an empty mesh
970 anActor->SetEntityMode( entities );
971 SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
974 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
975 ( (*anIter).second->GetID().c_str(), "SMESH", (*anIter).second->GetName().c_str() );
976 SMESH::Update(anIO, toDisplay);
978 if ( limitExceeded && !aMesh->_is_nil() )
980 QStringList hiddenMsg;
981 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
982 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
983 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
984 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
985 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
986 SUIT_MessageBox::warning( desktop(),
987 tr( "SMESH_WRN_WARNING" ),
988 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).arg( nbElements ).arg( limitSize ).arg( hiddenMsg.join(", ") ) );
993 MESSAGE ( "Exception thrown during mesh visualization" );
995 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
996 SMESH::OnVisuException();
1003 else if ( limitExceeded && !aMesh->_is_nil() )
1005 SUIT_MessageBox::warning( desktop(),
1006 tr( "SMESH_WRN_WARNING" ),
1007 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( nbElements ).arg( limitSize ) );
1011 LightApp_SelectionMgr *Sel = selectionMgr();
1014 SALOME_ListIO selected;
1015 selected.Append( myIObject );
1016 Sel->setSelectedObjects( selected );
1022 aMemoryReserve.release();
1024 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1028 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1029 bool noHypoError = ( aHypErrors.isEmpty() );
1031 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1032 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1034 bool isShowResultDlg = true;
1035 switch( aNotifyMode ) {
1036 case 0: // show the mesh computation result dialog NEVER
1037 isShowResultDlg = false;
1040 case 1: // show the mesh computation result dialog if there are some errors
1041 if ( memoryLack || !noCompError || !noHypoError )
1042 isShowResultDlg = true;
1045 isShowResultDlg = false;
1049 default: // show the result dialog after each mesh computation
1050 isShowResultDlg = true;
1054 if ( isShowResultDlg )
1055 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1058 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1059 const bool theNoCompError,
1060 SMESH::compute_error_array_var& theCompErrors,
1061 const bool theNoHypoError,
1062 const QString& theHypErrors )
1064 bool hasShape = myMesh->HasShapeToMesh();
1065 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1066 aCompDlg->myMemoryLackGroup->hide();
1068 if ( theMemoryLack )
1070 aCompDlg->myMemoryLackGroup->show();
1071 aCompDlg->myFullInfo->hide();
1072 aCompDlg->myBriefInfo->hide();
1073 aCompDlg->myHypErrorGroup->hide();
1074 aCompDlg->myCompErrorGroup->hide();
1076 else if ( theNoCompError && theNoHypoError )
1078 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1079 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1080 aCompDlg->myFullInfo->show();
1081 aCompDlg->myBriefInfo->hide();
1082 aCompDlg->myHypErrorGroup->hide();
1083 aCompDlg->myCompErrorGroup->hide();
1087 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1088 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1089 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1090 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1092 // full or brief mesh info
1093 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1094 if ( onlyWarnings ) {
1095 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1096 aCompDlg->myFullInfo->show();
1097 aCompDlg->myBriefInfo->hide();
1099 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1100 aCompDlg->myBriefInfo->show();
1101 aCompDlg->myFullInfo->hide();
1104 // pbs of hypo dfinitions
1105 if ( theNoHypoError ) {
1106 aCompDlg->myHypErrorGroup->hide();
1108 aCompDlg->myHypErrorGroup->show();
1109 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1113 if ( theNoCompError )
1115 aCompDlg->myCompErrorGroup->hide();
1119 aCompDlg->myCompErrorGroup->show();
1122 aCompDlg->myWarningLabel->show();
1124 aCompDlg->myWarningLabel->hide();
1127 aCompDlg->myPublishBtn->hide();
1128 aCompDlg->myShowBtn->hide();
1131 aCompDlg->myPublishBtn->show();
1132 aCompDlg->myShowBtn->show();
1135 // fill table of errors
1136 QTableWidget* tbl = aCompDlg->myTable;
1137 tbl->setRowCount( theCompErrors->length() );
1138 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1139 else tbl->showColumn( COL_SHAPE );
1140 tbl->setColumnWidth( COL_ERROR, 200 );
1142 bool hasBadMesh = false;
1143 for ( int row = 0; row < theCompErrors->length(); ++row )
1145 SMESH::ComputeError & err = theCompErrors[ row ];
1147 QString text = err.algoName.in();
1148 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1149 else tbl->item( row, COL_ALGO )->setText( text );
1151 text = SMESH::errorText( err.code, err.comment.in() );
1152 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1153 else tbl->item( row, COL_ERROR )->setText( text );
1155 text = QString("%1").arg( err.subShapeID );
1156 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1157 else tbl->item( row, COL_SHAPEID )->setText( text );
1159 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1160 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1161 else tbl->item( row, COL_SHAPE )->setText( text );
1163 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1164 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1165 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1167 text = err.hasBadMesh ? "hasBadMesh" : "";
1168 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1169 else tbl->item( row, COL_BAD_MESH )->setText( text );
1170 if ( err.hasBadMesh ) hasBadMesh = true;
1172 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1173 tbl->resizeRowToContents( row );
1175 tbl->resizeColumnToContents( COL_ALGO );
1176 tbl->resizeColumnToContents( COL_SHAPE );
1177 tbl->setWordWrap( true );
1180 aCompDlg->myBadMeshBtn->show();
1181 aCompDlg->myBadMeshToGroupBtn->show();
1184 aCompDlg->myBadMeshBtn->hide();
1185 aCompDlg->myBadMeshToGroupBtn->hide();
1187 tbl->setCurrentCell(0,0);
1188 currentCellChanged(); // to update buttons
1191 // show dialog and wait, becase Compute can be invoked from Preview operation
1192 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1196 //================================================================================
1198 * \brief Stops operation
1200 //================================================================================
1202 void SMESHGUI_BaseComputeOp::stopOperation()
1204 SMESHGUI_Operation::stopOperation();
1205 if ( myTShapeDisplayer )
1206 myTShapeDisplayer->SetVisibility( false );
1207 if ( myBadMeshDisplayer ) {
1208 myBadMeshDisplayer->SetVisibility( false );
1209 // delete it in order not to have problems at its destruction when the viewer
1210 // where it worked is dead due to e.g. study closing
1211 delete myBadMeshDisplayer;
1212 myBadMeshDisplayer = 0;
1214 myIObject.Nullify();
1217 //================================================================================
1219 * \brief publish selected sub-shape
1221 //================================================================================
1223 void SMESHGUI_BaseComputeOp::onPublishShape()
1225 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1226 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1228 QStringList entryList;
1230 SMESH::getSelectedRows( table(), rows );
1232 foreach ( row, rows )
1234 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1235 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1236 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1238 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1240 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1241 SALOMEDS::SObject_wrap so =
1242 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1243 // look for myMainShape in the table
1244 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1245 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1246 if ( so->_is_nil() ) {
1247 CORBA::String_var name = so->GetName();
1248 CORBA::String_var entry = so->GetID();
1249 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1250 table()->item( r, COL_SHAPE )->setText( shapeText );
1251 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1256 if ( curSub == 1 ) continue;
1258 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1259 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1260 if ( !so->_is_nil() ) {
1261 CORBA::String_var name = so->GetName();
1262 CORBA::String_var entry = so->GetID();
1263 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1264 table()->item( row, COL_SHAPE )->setText( shapeText );
1265 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1266 entryList.push_back( entry.in() );
1270 getSMESHGUI()->getApp()->updateObjectBrowser();
1271 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1273 currentCellChanged(); // to update buttons
1276 //================================================================================
1278 * \brief show mesh elements preventing computation of a submesh of current row
1280 //================================================================================
1282 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1284 myTShapeDisplayer->SetVisibility( false );
1286 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1287 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1289 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1290 SMESHGUI* gui = getSMESHGUI();
1291 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1292 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1293 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1294 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1295 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1296 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1297 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1298 vtkProperty* prop = vtkProperty::New();
1299 prop->SetLineWidth( aLineWidth * 3 );
1300 prop->SetPointSize( aPointSize * 3 );
1301 prop->SetColor( 250, 0, 250 );
1302 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1303 myBadMeshDisplayer->SetData( aMeshData._retn() );
1309 //================================================================================
1311 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1313 //================================================================================
1315 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1318 SMESH::getSelectedRows( table(), rows );
1320 foreach ( row, rows )
1322 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1324 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1325 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1326 if ( grName.isEmpty() ) grName = "bad mesh";
1327 else grName = "bad mesh of " + grName;
1328 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1329 SMESH::ListOfGroups_var groups
1330 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1331 update( UF_ObjBrowser | UF_Model );
1332 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1334 QStringList anEntryList;
1335 for ( size_t i = 0; i < groups->length(); ++i )
1336 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1337 anEntryList.append( so->GetID().c_str() );
1339 if ( !anEntryList.isEmpty())
1340 anApp->browseObjects( anEntryList, true, false );
1346 //================================================================================
1348 * \brief SLOT called when a selected cell in table() changed
1350 //================================================================================
1352 void SMESHGUI_BaseComputeOp::currentCellChanged()
1354 myTShapeDisplayer->SetVisibility( false );
1355 if ( myBadMeshDisplayer )
1356 myBadMeshDisplayer->SetVisibility( false );
1358 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1360 int nbSelected = SMESH::getSelectedRows( table(), rows );
1362 foreach ( row, rows )
1364 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1365 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1366 if ( hasData && !isPublished )
1367 publishEnable = true;
1369 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1370 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1372 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1379 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1382 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1383 myCompDlg->myShowBtn ->setEnabled( showEnable );
1384 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1385 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1388 //================================================================================
1390 * \brief update preview
1392 //================================================================================
1394 void SMESHGUI_BaseComputeOp::onPreviewShape()
1396 if ( myTShapeDisplayer )
1398 SUIT_OverrideCursor aWaitCursor;
1400 SMESH::getSelectedRows( table(), rows );
1402 bool showOnly = true;
1404 foreach ( row, rows )
1406 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1408 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1412 currentCellChanged(); // to update buttons
1416 //================================================================================
1420 //================================================================================
1422 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1426 delete myTShapeDisplayer;
1427 if ( myBadMeshDisplayer )
1428 delete myBadMeshDisplayer;
1431 //================================================================================
1433 * \brief Gets dialog of compute operation
1434 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1436 //================================================================================
1438 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1442 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1443 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1444 // connect signals and slots
1445 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1446 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1447 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1448 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1450 QTableWidget* aTable = me->table();
1451 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1452 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1457 //================================================================================
1459 * \brief returns from compute mesh result dialog
1461 //================================================================================
1463 bool SMESHGUI_BaseComputeOp::onApply()
1468 //================================================================================
1470 * \brief Return a table
1472 //================================================================================
1474 QTableWidget* SMESHGUI_BaseComputeOp::table()
1476 return myCompDlg->myTable;
1480 //================================================================================
1482 * \brief Constructor
1484 //================================================================================
1486 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1487 : SMESHGUI_BaseComputeOp()
1489 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1493 //================================================================================
1495 * \brief Desctructor
1497 //================================================================================
1499 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1503 //================================================================================
1505 * \brief perform it's intention action: compute mesh
1507 //================================================================================
1509 void SMESHGUI_ComputeOp::startOperation()
1511 SMESHGUI_BaseComputeOp::startOperation();
1512 if (myMesh->_is_nil())
1517 //================================================================================
1519 * \brief check the same operations on the same mesh
1521 //================================================================================
1523 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1525 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1527 if ( !myMesh->_is_nil() && baseOp ) {
1528 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1529 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1534 //================================================================================
1536 * \brief Gets dialog of this operation
1537 * \retval LightApp_Dialog* - pointer to dialog of this operation
1539 //================================================================================
1541 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1543 return computeDlg();
1546 //================================================================================
1548 * \brief Constructor
1550 //================================================================================
1552 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1553 : SMESHGUI_BaseComputeOp(),
1557 myPreviewDisplayer( 0 )
1561 //================================================================================
1565 //================================================================================
1567 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1574 if ( myPreviewDisplayer )
1575 delete myPreviewDisplayer;
1576 myPreviewDisplayer = 0;
1579 //================================================================================
1581 * \brief Gets current dialog of this operation
1582 * \retval LightApp_Dialog* - pointer to dialog of this operation
1584 //================================================================================
1586 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1591 //================================================================================
1593 * \brief perform it's intention action: prepare data
1595 //================================================================================
1597 void SMESHGUI_PrecomputeOp::startOperation()
1599 myHelpFileName = "constructing_meshes_page.html#preview_anchor"; // other anchor onCompute()
1603 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1606 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1607 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1608 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1610 myActiveDlg = myDlg;
1612 // connect signal to compute dialog. which will be shown after Compute mesh operation
1613 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1616 // disconnect signals
1617 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1618 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1619 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1620 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1621 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1624 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1625 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1626 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1627 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1628 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1629 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1630 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1631 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1632 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1633 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1636 SMESHGUI_BaseComputeOp::startOperation();
1637 if (myMesh->_is_nil())
1640 if (myDlg->getPreviewMode() == -1)
1642 // nothing to preview
1643 SUIT_MessageBox::warning(desktop(),
1644 tr("SMESH_WRN_WARNING"),
1645 tr("SMESH_WRN_NOTHING_PREVIEW"));
1650 // disconnect slot from preview dialog to have Apply from results of compute operation only
1651 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1652 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1657 //================================================================================
1659 * \brief Stops operation
1661 //================================================================================
1663 void SMESHGUI_PrecomputeOp::stopOperation()
1665 if ( myPreviewDisplayer )
1667 myPreviewDisplayer->SetVisibility( false );
1668 delete myPreviewDisplayer;
1669 myPreviewDisplayer = 0;
1671 myMapShapeId.clear();
1672 SMESHGUI_BaseComputeOp::stopOperation();
1675 //================================================================================
1677 * \brief reinitialize dialog after operaiton become active again
1679 //================================================================================
1681 void SMESHGUI_PrecomputeOp::resumeOperation()
1683 if ( myActiveDlg == myDlg )
1685 SMESHGUI_BaseComputeOp::resumeOperation();
1688 //================================================================================
1690 * \brief perform it's intention action: reinitialise dialog
1692 //================================================================================
1694 void SMESHGUI_PrecomputeOp::initDialog()
1698 QMap<int, int> modeMap;
1699 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1700 getAssignedAlgos( pMesh, modeMap );
1701 if ( modeMap.contains( SMESH::DIM_3D ) )
1703 if ( modeMap.contains( SMESH::DIM_2D ) )
1704 modes.append( SMESH::DIM_2D );
1705 if ( modeMap.contains( SMESH::DIM_1D ) )
1706 modes.append( SMESH::DIM_1D );
1708 else if ( modeMap.contains( SMESH::DIM_2D ) )
1710 if ( modeMap.contains( SMESH::DIM_1D ) )
1711 modes.append( SMESH::DIM_1D );
1714 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1715 myOrderMgr->SetMesh( myMesh );
1716 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1717 myDlg->getMeshOrderBox()->setVisible(isOrder);
1723 myDlg->setPreviewModes( modes );
1726 //================================================================================
1728 * \brief detect asigned mesh algorithms
1730 //================================================================================
1732 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1733 QMap<int,int>& theModeMap)
1735 if ( !theMesh ) return;
1736 _PTR(SObject) aHypFolder;
1737 _PTR(GenericAttribute) anAttr;
1738 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1739 if ( theMesh->FindSubObject( aPart, aHypFolder ) )
1741 _PTR(ChildIterator) anIter =
1742 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1743 for ( ; anIter->More(); anIter->Next() )
1745 _PTR(SObject) anObj = anIter->Value();
1746 _PTR(SObject) aRefObj;
1747 if ( anObj->ReferencedObject( aRefObj ) )
1752 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1754 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1755 if ( CORBA::is_nil( aVar ) )
1758 SMESH::SMESH_Algo_var algo;
1759 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1762 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1763 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1764 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1767 if ( !algo->_is_nil() )
1769 theModeMap[ dim ] = 0;
1770 if ( theModeMap.size() == 3 )
1780 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1782 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1785 _PTR(ChildIterator) anIter =
1786 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1787 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1789 _PTR(SObject) anObj = anIter->Value();
1790 _PTR(SObject) aRefObj;
1791 if ( anObj->ReferencedObject( aRefObj ) )
1796 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1798 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1799 if ( CORBA::is_nil( aVar ) )
1802 SMESH::SMESH_Algo_var algo;
1803 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1806 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1807 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1808 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1811 if ( !algo->_is_nil() )
1813 theModeMap[ dim ] = 0;
1814 if ( theModeMap.size() == 3 )
1824 //================================================================================
1826 * \brief perform it's intention action: compute mesh
1828 //================================================================================
1830 void SMESHGUI_PrecomputeOp::onCompute()
1833 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1834 myOrderMgr->SetMeshOrder();
1835 myMapShapeId.clear();
1836 myActiveDlg = computeDlg();
1837 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1841 //================================================================================
1843 * \brief perform it's intention action: compute mesh
1845 //================================================================================
1847 void SMESHGUI_PrecomputeOp::onCancel()
1849 QObject* curDlg = sender();
1850 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1852 // return from error messages
1857 bool isRestoreOrder = false;
1858 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1860 // ask to remove already computed mesh elements
1861 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1862 tr( "CLEAR_SUBMESH_QUESTION" ),
1863 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1865 // remove all submeshes for collected shapes
1866 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1867 for ( ; it != myMapShapeId.constEnd(); ++it )
1868 myMesh->ClearSubMesh( it.key() );
1869 isRestoreOrder = true;
1873 // return previous mesh order
1874 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1875 if (!isRestoreOrder)
1877 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1878 tr( "SMESH_REJECT_MESH_ORDER" ),
1879 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1881 myOrderMgr->SetMeshOrder(myPrevOrder);
1887 myMapShapeId.clear();
1888 SMESHGUI_BaseComputeOp::onCancel();
1891 //================================================================================
1893 * \brief perform it's intention action: preview mesh
1895 //================================================================================
1897 void SMESHGUI_PrecomputeOp::onPreview()
1899 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1902 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1906 // set modified submesh priority if any
1907 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1908 myOrderMgr->SetMeshOrder();
1910 // Compute preview of mesh,
1911 // i.e. compute mesh till indicated dimension
1912 int dim = myDlg->getPreviewMode();
1914 SMESH::MemoryReserve aMemoryReserve;
1916 SMESH::compute_error_array_var aCompErrors;
1919 bool computeFailed = true, memoryLack = false;
1921 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1922 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1924 SMESHGUI* gui = getSMESHGUI();
1925 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1926 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1927 if ( errors->length() > 0 ) {
1928 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1931 SUIT_OverrideCursor aWaitCursor;
1933 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1934 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1935 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1937 SMESH::long_array_var aShapesId = new SMESH::long_array();
1939 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1943 SMESH::MeshPreviewStruct_var previewData =
1944 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1946 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1947 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1949 computeFailed = false;
1950 myPreviewDisplayer->SetData( previewRes );
1951 // append shape indeces with computed mesh entities
1952 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1953 myMapShapeId[ aShapesId[ i ] ] = 0;
1956 myPreviewDisplayer->SetVisibility(false);
1958 catch(const SALOME::SALOME_Exception & S_ex){
1960 myPreviewDisplayer->SetVisibility(false);
1964 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1967 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1968 // check if there are memory problems
1969 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1970 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1972 catch(const SALOME::SALOME_Exception & S_ex){
1977 aMemoryReserve.release();
1979 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1980 bool noHypoError = ( aHypErrors.isEmpty() );
1982 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1983 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1985 bool isShowError = true;
1986 switch( aNotifyMode ) {
1987 case 0: // show the mesh computation result dialog NEVER
1988 isShowError = false;
1990 case 1: // show the mesh computation result dialog if there are some errors
1991 default: // show the result dialog after each mesh computation
1992 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1993 isShowError = false;
1997 aWaitCursor.suspend();
2002 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
2003 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2008 //================================================================================
2010 * \brief Constructor
2012 //================================================================================
2014 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2015 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2018 setWindowTitle( tr( "CAPTION" ) );
2020 setButtonText( OK, tr( "COMPUTE" ) );
2021 QFrame* main = mainFrame();
2022 main->setMinimumWidth( 300 );
2024 QVBoxLayout* layout = new QVBoxLayout( main );
2026 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2027 layout->addWidget(myOrderBox);
2029 QFrame* frame = new QFrame( main );
2030 layout->setMargin(0); layout->setSpacing(0);
2031 layout->addWidget( frame );
2033 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2034 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2036 myPreviewMode = new QtxComboBox( frame );
2037 frameLay->addWidget( myPreviewMode );
2039 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2040 frameLay->addWidget( myPreviewBtn );
2042 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2045 //================================================================================
2049 //================================================================================
2051 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2055 //================================================================================
2057 * \brief Sets available preview modes
2059 //================================================================================
2061 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2063 myPreviewMode->clear();
2064 QList<int>::const_iterator it = theModes.constBegin();
2065 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2067 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2068 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2069 myPreviewMode->setId( i, *it );
2071 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2074 //================================================================================
2076 * \brief Returns current preview mesh mode
2078 //================================================================================
2080 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2082 return myPreviewMode->currentId();
2085 //================================================================================
2087 * \brief Returns current preview mesh mode
2089 //================================================================================
2091 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2097 //================================================================================
2099 * \brief Constructor
2101 //================================================================================
2103 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2104 : SMESHGUI_BaseComputeOp()
2106 myHelpFileName = "constructing_meshes_page.html#evaluate_anchor";
2110 //================================================================================
2112 * \brief Desctructor
2114 //================================================================================
2116 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2120 //================================================================================
2122 * \brief perform it's intention action: compute mesh
2124 //================================================================================
2126 void SMESHGUI_EvaluateOp::startOperation()
2128 SMESHGUI_BaseComputeOp::evaluateDlg();
2129 SMESHGUI_BaseComputeOp::startOperation();
2130 if (myMesh->_is_nil())
2135 //================================================================================
2137 * \brief Gets dialog of this operation
2138 * \retval LightApp_Dialog* - pointer to dialog of this operation
2140 //================================================================================
2142 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2144 return evaluateDlg();
2147 //================================================================================
2149 * \brief evaluateMesh()
2151 //================================================================================
2153 void SMESHGUI_BaseComputeOp::evaluateMesh()
2157 SMESH::MemoryReserve aMemoryReserve;
2159 SMESH::compute_error_array_var aCompErrors;
2162 bool evaluateFailed = true, memoryLack = false;
2163 SMESH::long_array_var aRes;
2165 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2166 if ( !aMeshSObj ) // IPAL21340
2169 bool hasShape = myMesh->HasShapeToMesh();
2170 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2173 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2174 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2175 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2176 if ( errors->length() > 0 ) {
2177 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2179 SUIT_OverrideCursor aWaitCursor;
2181 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2184 aRes = gen->Evaluate(myMesh, myMainShape);
2186 catch(const SALOME::SALOME_Exception & S_ex){
2191 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2194 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2196 catch(const SALOME::SALOME_Exception & S_ex){
2202 aMemoryReserve.release();
2204 evaluateFailed = ( aCompErrors->length() > 0 );
2205 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
2209 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2210 bool noHypoError = ( aHypErrors.isEmpty() );
2212 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2213 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2215 bool isShowResultDlg = true;
2217 //switch( aNotifyMode ) {
2218 //case 0: // show the mesh computation result dialog NEVER
2219 //isShowResultDlg = false;
2222 //case 1: // show the mesh computation result dialog if there are some errors
2223 //if ( memoryLack || !noHypoError )
2224 // isShowResultDlg = true;
2227 // isShowResultDlg = false;
2231 //default: // show the result dialog after each mesh computation
2232 //isShowResultDlg = true;
2236 if ( isShowResultDlg )
2237 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2238 noHypoError, aHypErrors);
2242 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2243 const bool theMemoryLack,
2244 const bool theNoCompError,
2245 SMESH::compute_error_array_var& theCompErrors,
2246 const bool theNoHypoError,
2247 const QString& theHypErrors)
2249 bool hasShape = myMesh->HasShapeToMesh();
2250 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2251 aCompDlg->myMemoryLackGroup->hide();
2253 if ( theMemoryLack )
2255 aCompDlg->myMemoryLackGroup->show();
2256 aCompDlg->myFullInfo->hide();
2257 aCompDlg->myBriefInfo->hide();
2258 aCompDlg->myHypErrorGroup->hide();
2259 aCompDlg->myCompErrorGroup->hide();
2261 else if ( theNoCompError && theNoHypoError )
2263 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2264 aCompDlg->myFullInfo->show();
2265 aCompDlg->myBriefInfo->hide();
2266 aCompDlg->myHypErrorGroup->hide();
2267 aCompDlg->myCompErrorGroup->hide();
2271 QTableWidget* tbl = aCompDlg->myTable;
2272 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2273 aCompDlg->myBriefInfo->show();
2274 aCompDlg->myFullInfo->hide();
2276 if ( theNoHypoError ) {
2277 aCompDlg->myHypErrorGroup->hide();
2280 aCompDlg->myHypErrorGroup->show();
2281 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2284 if ( theNoCompError ) {
2285 aCompDlg->myCompErrorGroup->hide();
2288 aCompDlg->myCompErrorGroup->show();
2290 aCompDlg->myPublishBtn->hide();
2291 aCompDlg->myShowBtn->hide();
2293 // fill table of errors
2294 tbl->setRowCount( theCompErrors->length() );
2295 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2296 else tbl->showColumn( COL_SHAPE );
2297 tbl->setColumnWidth( COL_ERROR, 200 );
2299 bool hasBadMesh = false;
2300 for ( int row = 0; row < theCompErrors->length(); ++row )
2302 SMESH::ComputeError & err = theCompErrors[ row ];
2304 QString text = err.algoName.in();
2305 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2306 else tbl->item( row, COL_ALGO )->setText( text );
2308 text = SMESH::errorText( err.code, err.comment.in() );
2309 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2310 else tbl->item( row, COL_ERROR )->setText( text );
2312 text = QString("%1").arg( err.subShapeID );
2313 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2314 else tbl->item( row, COL_SHAPEID )->setText( text );
2316 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2317 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2318 else tbl->item( row, COL_SHAPE )->setText( text );
2320 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2321 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2322 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2324 text = err.hasBadMesh ? "hasBadMesh" : "";
2325 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2326 else tbl->item( row, COL_BAD_MESH )->setText( text );
2327 if ( err.hasBadMesh ) hasBadMesh = true;
2329 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2330 tbl->resizeRowToContents( row );
2332 tbl->resizeColumnToContents( COL_ALGO );
2333 tbl->resizeColumnToContents( COL_SHAPE );
2334 tbl->setWordWrap( true );
2338 aCompDlg->myBadMeshBtn->show();
2339 aCompDlg->myBadMeshToGroupBtn->show();
2343 aCompDlg->myBadMeshBtn->hide();
2344 aCompDlg->myBadMeshToGroupBtn->hide();
2346 tbl->setCurrentCell(0,0);
2347 currentCellChanged(); // to update buttons
2350 // show dialog and wait, becase Compute can be invoked from Preview operation
2351 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2356 //================================================================================
2358 * \brief Gets dialog of evaluate operation
2359 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2361 //================================================================================
2363 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2367 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2368 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2369 // connect signals and slots
2370 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2371 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2372 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2373 QTableWidget* aTable = me->table();
2374 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2375 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));