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 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
573 myTable->setWordWrap( true );
574 myTable->horizontalHeader()->setStretchLastSection( true );
575 myTable->setMinimumWidth( 500 );
578 headers << tr( "COL_ALGO_HEADER" );
579 headers << tr( "COL_SHAPE_HEADER" );
580 headers << tr( "COL_ERROR_HEADER" );
581 headers << tr( "COL_SHAPEID_HEADER" );
582 headers << tr( "COL_PUBLISHED_HEADER" );
584 myTable->setHorizontalHeaderLabels( headers );
587 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
588 grpLayout->setSpacing(SPACING);
589 grpLayout->setMargin(MARGIN);
590 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
591 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
592 grpLayout->addWidget( myShowBtn, 2, 0 );
593 grpLayout->addWidget( myPublishBtn, 2, 1 );
594 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
595 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
596 grpLayout->setColumnStretch( 3, 1 );
598 // Hypothesis definition errors
600 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
601 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
602 myHypErrorGroupLayout->setMargin(MARGIN);
603 myHypErrorGroupLayout->setSpacing(SPACING);
604 myHypErrorLabel = new QLabel(myHypErrorGroup);
605 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
609 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
610 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
611 myMemoryLackGroupLayout->setMargin(MARGIN);
612 myMemoryLackGroupLayout->setSpacing(SPACING);
613 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
614 QFont bold = memLackLabel->font(); bold.setBold(true);
615 memLackLabel->setFont( bold );
616 memLackLabel->setMinimumWidth(300);
617 myMemoryLackGroupLayout->addWidget(memLackLabel);
619 // add all widgets to aFrame
620 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
621 aLay->setMargin( MARGIN );
622 aLay->setSpacing( SPACING );
623 aLay->addWidget( aPixGrp );
624 aLay->addWidget( nameBox );
625 aLay->addWidget( myBriefInfo );
626 aLay->addWidget( myFullInfo );
627 aLay->addWidget( myHypErrorGroup );
628 aLay->addWidget( myCompErrorGroup );
629 aLay->addWidget( myMemoryLackGroup );
630 aLay->setStretchFactor( myCompErrorGroup, 1 );
632 ((QPushButton*) button( OK ))->setDefault( true );
637 //================================================================================
641 //================================================================================
643 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
644 : SMESHGUI_Operation(), myCompDlg( 0 )
646 myTShapeDisplayer = new SMESH::TShapeDisplayer();
647 myBadMeshDisplayer = 0;
649 //myHelpFileName = "/files/about_meshes.htm"; // V3
650 myHelpFileName = "about_meshes_page.html"; // V4
653 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
655 LightApp_SelectionMgr* Sel = selectionMgr();
656 SALOME_ListIO selected; Sel->selectedObjects( selected );
657 Handle(SALOME_InteractiveObject) anIO = selected.First();
658 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
659 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
662 //================================================================================
664 * \brief Start operation
665 * \purpose Init dialog fields, connect signals and slots, show dialog
667 //================================================================================
669 void SMESHGUI_BaseComputeOp::startOperation()
671 // create compute dialog if not created before
674 myMesh = SMESH::SMESH_Mesh::_nil();
675 myMainShape = GEOM::GEOM_Object::_nil();
678 LightApp_SelectionMgr *Sel = selectionMgr();
679 SALOME_ListIO selected; Sel->selectedObjects( selected );
681 int nbSel = selected.Extent();
683 SUIT_MessageBox::warning(desktop(),
684 tr("SMESH_WRN_WARNING"),
685 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
690 myIObject = selected.First();
691 myMesh = SMESH::GetMeshByIO(myIObject);
692 if (myMesh->_is_nil()) {
693 SUIT_MessageBox::warning(desktop(),
694 tr("SMESH_WRN_WARNING"),
695 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
699 myMainShape = myMesh->GetShapeToMesh();
701 SMESHGUI_Operation::startOperation();
704 //================================================================================
705 //================================================================================
707 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
708 SMESH::SMESH_Mesh_var mesh,
709 GEOM::GEOM_Object_var mainShape)
714 myMainShape = mainShape;
717 void SMESHGUI_ComputeDlg_QThread::run()
719 myResult = myGen->Compute(myMesh, myMainShape);
722 bool SMESHGUI_ComputeDlg_QThread::result()
727 void SMESHGUI_ComputeDlg_QThread::cancel()
729 myGen->CancelCompute(myMesh, myMainShape);
732 //================================================================================
733 //================================================================================
735 SMESHGUI_ComputeDlg_QThreadQDialog::SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
736 SMESH::SMESH_Gen_var gen,
737 SMESH::SMESH_Mesh_var mesh,
738 GEOM::GEOM_Object_var mainShape)
740 Qt::WindowSystemMenuHint |
741 Qt::WindowCloseButtonHint |
743 Qt::WindowMaximizeButtonHint),
744 qthread(gen, mesh, mainShape)
747 setWindowTitle(tr("TITLE"));
748 setMinimumWidth( 200 );
750 cancelButton = new QPushButton(tr("CANCEL"));
751 cancelButton->setDefault(true);
752 cancelButton->setCheckable(true);
754 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
755 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
756 nbNodesLabel = new QLabel("0", this );
757 nbElemsLabel = new QLabel("0", this );
759 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
760 freeRAMLabel = new QLabel("", this );
762 progressBar = new QProgressBar(this);
763 progressBar->setMinimum( 0 );
764 progressBar->setMaximum( 1000 );
766 QGridLayout* layout = new QGridLayout(this);
767 layout->setMargin( MARGIN );
768 layout->setSpacing( SPACING );
770 layout->addWidget(nbNodesName, row, 0);
771 layout->addWidget(nbNodesLabel, row++, 1);
772 layout->addWidget(nbElemsName, row, 0);
773 layout->addWidget(nbElemsLabel, row++, 1);
775 layout->addWidget(freeRAMName, row, 0);
776 layout->addWidget(freeRAMLabel, row++, 1);
778 layout->addWidget(progressBar, row++, 0, 1, 2);
779 layout->addWidget(cancelButton, row++, 0, 1, 2);
783 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
785 startTimer(300); // millisecs
789 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
791 return qthread.result();
794 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
797 cancelButton->setText( tr("CANCELING"));
798 cancelButton->setEnabled(false);
801 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
803 if ( !cancelButton->isChecked() ) // not yet cancelled
804 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
806 if(qthread.isFinished())
812 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
813 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
816 const int err = sysinfo( &si );
818 freeRAMLabel->setText("");
820 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
821 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
827 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
829 if(qthread.isRunning())
837 //================================================================================
839 * \brief computeMesh()
841 //================================================================================
843 void SMESHGUI_BaseComputeOp::computeMesh()
847 SMESH::MemoryReserve aMemoryReserve;
849 SMESH::compute_error_array_var aCompErrors;
852 bool computeFailed = true, memoryLack = false;
854 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
855 if ( !aMeshSObj ) // IPAL 21340
857 bool hasShape = myMesh->HasShapeToMesh();
858 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
861 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
862 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
863 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
864 if ( errors->length() > 0 ) {
865 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
867 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
868 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
869 tr( "FULL_RECOMPUTE_QUESTION" ),
870 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
872 SUIT_OverrideCursor aWaitCursor;
874 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
877 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myMainShape);
878 qthreaddialog.exec();
879 computeFailed = !qthreaddialog.result();
881 catch(const SALOME::SALOME_Exception & S_ex) {
885 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
888 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
889 // check if there are memory problems
890 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
891 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
893 catch(const SALOME::SALOME_Exception & S_ex) {
897 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
901 // NPAL16631: if ( !memoryLack )
903 SMESH::ModifiedMesh( aMeshSObj,
904 !computeFailed && aHypErrors.isEmpty(),
905 myMesh->NbNodes() == 0);
906 update( UF_ObjBrowser | UF_Model );
909 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
910 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
912 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
913 int entities = SMESH_Actor::eAllEntity;
918 // List of objects that will be updated automatically
919 QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > aListToUpdate;
920 SMESH::SMESH_IDSource_var aMeshObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
921 // put Mesh into list
922 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aMeshObj, aMeshSObj) );
923 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
924 // put SubMeshes into list
925 for ( int i = 0; i < aSubMeshes->length(); i++ ) {
926 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
927 if ( CORBA::is_nil( sm ) ) continue;
928 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
929 if ( !smSObj ) continue;
930 SMESH::SMESH_IDSource_var aSubMeshObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
931 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aSubMeshObj, smSObj) );
933 // put Groups into list
934 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
935 for ( size_t i = 0; i < aGroups->length(); ++i ) {
936 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
937 if ( CORBA::is_nil( aGrp ) ) continue;
938 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
939 SMESH::SMESH_GroupOnGeom_var aGeomGroup = SMESH::SMESH_GroupOnGeom::_narrow( aGrp );
940 SMESH::SMESH_GroupOnFilter_var aFltGroup = SMESH::SMESH_GroupOnFilter::_narrow( aGrp );
941 if ( !aStdGroup->_is_nil() ) continue; // don't update the standalone groups
942 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
943 if ( !aGroupSO ) continue;
944 SMESH::SMESH_IDSource_var aGroupObj = SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
945 aListToUpdate.append( QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) >(aGroupObj, aGroupSO) );
948 // update mesh, sub-mesh and groups, if it's possible
949 QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > >::iterator anIter;
950 for( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ ) {
951 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
952 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded, &hidden, &nbElements ) )
955 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
958 bool toDisplay = false;
960 if ( !aMesh->_is_nil() ) { // display a mesh only
962 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
963 if ( !anActor ) anActor = SMESH::CreateActor( (*anIter).second->GetStudy(), (*anIter).second->GetID().c_str(), true );
964 if ( anActor ) // actor is not created for an empty mesh
966 anActor->SetEntityMode( entities );
967 SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
970 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
971 ( (*anIter).second->GetID().c_str(), "SMESH", (*anIter).second->GetName().c_str() );
972 SMESH::Update(anIO, toDisplay);
974 if ( limitExceeded && !aMesh->_is_nil() )
976 QStringList hiddenMsg;
977 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
978 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
979 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
980 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
981 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
982 SUIT_MessageBox::warning( desktop(),
983 tr( "SMESH_WRN_WARNING" ),
984 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).arg( nbElements ).arg( limitSize ).arg( hiddenMsg.join(", ") ) );
989 MESSAGE ( "Exception thrown during mesh visualization" );
991 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
992 SMESH::OnVisuException();
999 else if ( limitExceeded && !aMesh->_is_nil() )
1001 SUIT_MessageBox::warning( desktop(),
1002 tr( "SMESH_WRN_WARNING" ),
1003 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).arg( nbElements ).arg( limitSize ) );
1007 LightApp_SelectionMgr *Sel = selectionMgr();
1010 SALOME_ListIO selected;
1011 selected.Append( myIObject );
1012 Sel->setSelectedObjects( selected );
1018 aMemoryReserve.release();
1020 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1024 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1025 bool noHypoError = ( aHypErrors.isEmpty() );
1027 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1028 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1030 bool isShowResultDlg = true;
1031 switch( aNotifyMode ) {
1032 case 0: // show the mesh computation result dialog NEVER
1033 isShowResultDlg = false;
1036 case 1: // show the mesh computation result dialog if there are some errors
1037 if ( memoryLack || !noCompError || !noHypoError )
1038 isShowResultDlg = true;
1041 isShowResultDlg = false;
1045 default: // show the result dialog after each mesh computation
1046 isShowResultDlg = true;
1050 if ( isShowResultDlg )
1051 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1054 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1055 const bool theNoCompError,
1056 SMESH::compute_error_array_var& theCompErrors,
1057 const bool theNoHypoError,
1058 const QString& theHypErrors )
1060 bool hasShape = myMesh->HasShapeToMesh();
1061 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1062 aCompDlg->myMemoryLackGroup->hide();
1064 if ( theMemoryLack )
1066 aCompDlg->myMemoryLackGroup->show();
1067 aCompDlg->myFullInfo->hide();
1068 aCompDlg->myBriefInfo->hide();
1069 aCompDlg->myHypErrorGroup->hide();
1070 aCompDlg->myCompErrorGroup->hide();
1072 else if ( theNoCompError && theNoHypoError )
1074 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1075 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1076 aCompDlg->myFullInfo->show();
1077 aCompDlg->myBriefInfo->hide();
1078 aCompDlg->myHypErrorGroup->hide();
1079 aCompDlg->myCompErrorGroup->hide();
1083 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1084 for ( int i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1085 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1086 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1088 // full or brief mesh info
1089 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1090 if ( onlyWarnings ) {
1091 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1092 aCompDlg->myFullInfo->show();
1093 aCompDlg->myBriefInfo->hide();
1095 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1096 aCompDlg->myBriefInfo->show();
1097 aCompDlg->myFullInfo->hide();
1100 // pbs of hypo dfinitions
1101 if ( theNoHypoError ) {
1102 aCompDlg->myHypErrorGroup->hide();
1104 aCompDlg->myHypErrorGroup->show();
1105 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1109 if ( theNoCompError )
1111 aCompDlg->myCompErrorGroup->hide();
1115 aCompDlg->myCompErrorGroup->show();
1118 aCompDlg->myWarningLabel->show();
1120 aCompDlg->myWarningLabel->hide();
1123 aCompDlg->myPublishBtn->hide();
1124 aCompDlg->myShowBtn->hide();
1127 aCompDlg->myPublishBtn->show();
1128 aCompDlg->myShowBtn->show();
1131 // fill table of errors
1132 QTableWidget* tbl = aCompDlg->myTable;
1133 tbl->setRowCount( theCompErrors->length() );
1134 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1135 else tbl->showColumn( COL_SHAPE );
1136 tbl->setColumnWidth( COL_ERROR, 200 );
1138 bool hasBadMesh = false;
1139 for ( int row = 0; row < theCompErrors->length(); ++row )
1141 SMESH::ComputeError & err = theCompErrors[ row ];
1143 QString text = err.algoName.in();
1144 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1145 else tbl->item( row, COL_ALGO )->setText( text );
1147 text = SMESH::errorText( err.code, err.comment.in() );
1148 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1149 else tbl->item( row, COL_ERROR )->setText( text );
1151 text = QString("%1").arg( err.subShapeID );
1152 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1153 else tbl->item( row, COL_SHAPEID )->setText( text );
1155 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1156 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1157 else tbl->item( row, COL_SHAPE )->setText( text );
1159 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1160 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1161 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1163 text = err.hasBadMesh ? "hasBadMesh" : "";
1164 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1165 else tbl->item( row, COL_BAD_MESH )->setText( text );
1166 if ( err.hasBadMesh ) hasBadMesh = true;
1168 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1169 tbl->resizeRowToContents( row );
1171 tbl->resizeColumnToContents( COL_ALGO );
1172 tbl->resizeColumnToContents( COL_SHAPE );
1173 tbl->setWordWrap( true );
1176 aCompDlg->myBadMeshBtn->show();
1177 aCompDlg->myBadMeshToGroupBtn->show();
1180 aCompDlg->myBadMeshBtn->hide();
1181 aCompDlg->myBadMeshToGroupBtn->hide();
1183 tbl->setCurrentCell(0,0);
1184 currentCellChanged(); // to update buttons
1187 // show dialog and wait, becase Compute can be invoked from Preview operation
1188 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1192 //================================================================================
1194 * \brief Stops operation
1196 //================================================================================
1198 void SMESHGUI_BaseComputeOp::stopOperation()
1200 SMESHGUI_Operation::stopOperation();
1201 if ( myTShapeDisplayer )
1202 myTShapeDisplayer->SetVisibility( false );
1203 if ( myBadMeshDisplayer ) {
1204 myBadMeshDisplayer->SetVisibility( false );
1205 // delete it in order not to have problems at its destruction when the viewer
1206 // where it worked is dead due to e.g. study closing
1207 delete myBadMeshDisplayer;
1208 myBadMeshDisplayer = 0;
1210 myIObject.Nullify();
1213 //================================================================================
1215 * \brief publish selected sub-shape
1217 //================================================================================
1219 void SMESHGUI_BaseComputeOp::onPublishShape()
1221 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1222 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1224 QStringList entryList;
1226 SMESH::getSelectedRows( table(), rows );
1228 foreach ( row, rows )
1230 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1231 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1232 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1234 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1236 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1237 SALOMEDS::SObject_wrap so =
1238 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1239 // look for myMainShape in the table
1240 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1241 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1242 if ( so->_is_nil() ) {
1243 CORBA::String_var name = so->GetName();
1244 CORBA::String_var entry = so->GetID();
1245 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1246 table()->item( r, COL_SHAPE )->setText( shapeText );
1247 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1252 if ( curSub == 1 ) continue;
1254 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1255 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1256 if ( !so->_is_nil() ) {
1257 CORBA::String_var name = so->GetName();
1258 CORBA::String_var entry = so->GetID();
1259 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1260 table()->item( row, COL_SHAPE )->setText( shapeText );
1261 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1262 entryList.push_back( entry.in() );
1266 getSMESHGUI()->getApp()->updateObjectBrowser();
1267 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1269 currentCellChanged(); // to update buttons
1272 //================================================================================
1274 * \brief show mesh elements preventing computation of a submesh of current row
1276 //================================================================================
1278 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1280 myTShapeDisplayer->SetVisibility( false );
1282 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1283 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1285 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1286 SMESHGUI* gui = getSMESHGUI();
1287 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1288 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1289 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1290 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1291 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1292 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1293 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1294 vtkProperty* prop = vtkProperty::New();
1295 prop->SetLineWidth( aLineWidth * 3 );
1296 prop->SetPointSize( aPointSize * 3 );
1297 prop->SetColor( 250, 0, 250 );
1298 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1299 myBadMeshDisplayer->SetData( aMeshData._retn() );
1305 //================================================================================
1307 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1309 //================================================================================
1311 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1314 SMESH::getSelectedRows( table(), rows );
1316 foreach ( row, rows )
1318 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1320 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1321 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1322 if ( grName.isEmpty() ) grName = "bad mesh";
1323 else grName = "bad mesh of " + grName;
1324 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1325 SMESH::ListOfGroups_var groups
1326 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1327 update( UF_ObjBrowser | UF_Model );
1328 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1330 QStringList anEntryList;
1331 for ( size_t i = 0; i < groups->length(); ++i )
1332 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1333 anEntryList.append( so->GetID().c_str() );
1335 if ( !anEntryList.isEmpty())
1336 anApp->browseObjects( anEntryList, true, false );
1342 //================================================================================
1344 * \brief SLOT called when a selected cell in table() changed
1346 //================================================================================
1348 void SMESHGUI_BaseComputeOp::currentCellChanged()
1350 myTShapeDisplayer->SetVisibility( false );
1351 if ( myBadMeshDisplayer )
1352 myBadMeshDisplayer->SetVisibility( false );
1354 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1356 int nbSelected = SMESH::getSelectedRows( table(), rows );
1358 foreach ( row, rows )
1360 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1361 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1362 if ( hasData && !isPublished )
1363 publishEnable = true;
1365 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1366 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1368 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1375 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1378 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1379 myCompDlg->myShowBtn ->setEnabled( showEnable );
1380 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1381 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1384 //================================================================================
1386 * \brief update preview
1388 //================================================================================
1390 void SMESHGUI_BaseComputeOp::onPreviewShape()
1392 if ( myTShapeDisplayer )
1394 SUIT_OverrideCursor aWaitCursor;
1396 SMESH::getSelectedRows( table(), rows );
1398 bool showOnly = true;
1400 foreach ( row, rows )
1402 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1404 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1408 currentCellChanged(); // to update buttons
1412 //================================================================================
1416 //================================================================================
1418 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1422 delete myTShapeDisplayer;
1423 if ( myBadMeshDisplayer )
1424 delete myBadMeshDisplayer;
1427 //================================================================================
1429 * \brief Gets dialog of compute operation
1430 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1432 //================================================================================
1434 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1438 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1439 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1440 // connect signals and slots
1441 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1442 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1443 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1444 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1446 QTableWidget* aTable = me->table();
1447 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1448 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1453 //================================================================================
1455 * \brief returns from compute mesh result dialog
1457 //================================================================================
1459 bool SMESHGUI_BaseComputeOp::onApply()
1464 //================================================================================
1466 * \brief Return a table
1468 //================================================================================
1470 QTableWidget* SMESHGUI_BaseComputeOp::table()
1472 return myCompDlg->myTable;
1476 //================================================================================
1478 * \brief Constructor
1480 //================================================================================
1482 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1483 : SMESHGUI_BaseComputeOp()
1485 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1489 //================================================================================
1491 * \brief Desctructor
1493 //================================================================================
1495 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1499 //================================================================================
1501 * \brief perform it's intention action: compute mesh
1503 //================================================================================
1505 void SMESHGUI_ComputeOp::startOperation()
1507 SMESHGUI_BaseComputeOp::startOperation();
1508 if (myMesh->_is_nil())
1513 //================================================================================
1515 * \brief check the same operations on the same mesh
1517 //================================================================================
1519 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1521 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1523 if ( !myMesh->_is_nil() && baseOp ) {
1524 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1525 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1530 //================================================================================
1532 * \brief Gets dialog of this operation
1533 * \retval LightApp_Dialog* - pointer to dialog of this operation
1535 //================================================================================
1537 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1539 return computeDlg();
1542 //================================================================================
1544 * \brief Constructor
1546 //================================================================================
1548 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1549 : SMESHGUI_BaseComputeOp(),
1553 myPreviewDisplayer( 0 )
1557 //================================================================================
1561 //================================================================================
1563 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1570 if ( myPreviewDisplayer )
1571 delete myPreviewDisplayer;
1572 myPreviewDisplayer = 0;
1575 //================================================================================
1577 * \brief Gets current dialog of this operation
1578 * \retval LightApp_Dialog* - pointer to dialog of this operation
1580 //================================================================================
1582 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1587 //================================================================================
1589 * \brief perform it's intention action: prepare data
1591 //================================================================================
1593 void SMESHGUI_PrecomputeOp::startOperation()
1595 myHelpFileName = "constructing_meshes_page.html#preview_anchor"; // other anchor onCompute()
1599 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1602 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1603 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1604 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1606 myActiveDlg = myDlg;
1608 // connect signal to compute dialog. which will be shown after Compute mesh operation
1609 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1612 // disconnect signals
1613 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1614 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1615 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1616 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1617 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1620 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1621 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1622 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1623 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1624 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1625 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1626 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1627 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1628 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1629 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1632 SMESHGUI_BaseComputeOp::startOperation();
1633 if (myMesh->_is_nil())
1636 if (myDlg->getPreviewMode() == -1)
1638 // nothing to preview
1639 SUIT_MessageBox::warning(desktop(),
1640 tr("SMESH_WRN_WARNING"),
1641 tr("SMESH_WRN_NOTHING_PREVIEW"));
1646 // disconnect slot from preview dialog to have Apply from results of compute operation only
1647 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1648 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1653 //================================================================================
1655 * \brief Stops operation
1657 //================================================================================
1659 void SMESHGUI_PrecomputeOp::stopOperation()
1661 if ( myPreviewDisplayer )
1663 myPreviewDisplayer->SetVisibility( false );
1664 delete myPreviewDisplayer;
1665 myPreviewDisplayer = 0;
1667 myMapShapeId.clear();
1668 SMESHGUI_BaseComputeOp::stopOperation();
1671 //================================================================================
1673 * \brief reinitialize dialog after operaiton become active again
1675 //================================================================================
1677 void SMESHGUI_PrecomputeOp::resumeOperation()
1679 if ( myActiveDlg == myDlg )
1681 SMESHGUI_BaseComputeOp::resumeOperation();
1684 //================================================================================
1686 * \brief perform it's intention action: reinitialise dialog
1688 //================================================================================
1690 void SMESHGUI_PrecomputeOp::initDialog()
1694 QMap<int, int> modeMap;
1695 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1696 getAssignedAlgos( pMesh, modeMap );
1697 if ( modeMap.contains( SMESH::DIM_3D ) )
1699 if ( modeMap.contains( SMESH::DIM_2D ) )
1700 modes.append( SMESH::DIM_2D );
1701 if ( modeMap.contains( SMESH::DIM_1D ) )
1702 modes.append( SMESH::DIM_1D );
1704 else if ( modeMap.contains( SMESH::DIM_2D ) )
1706 if ( modeMap.contains( SMESH::DIM_1D ) )
1707 modes.append( SMESH::DIM_1D );
1710 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1711 myOrderMgr->SetMesh( myMesh );
1712 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1713 myDlg->getMeshOrderBox()->setShown(isOrder);
1719 myDlg->setPreviewModes( modes );
1722 //================================================================================
1724 * \brief detect asigned mesh algorithms
1726 //================================================================================
1728 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1729 QMap<int,int>& theModeMap)
1731 if ( !theMesh ) return;
1732 _PTR(SObject) aHypFolder;
1733 _PTR(GenericAttribute) anAttr;
1734 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1735 if ( theMesh->FindSubObject( aPart, aHypFolder ) )
1737 _PTR(ChildIterator) anIter =
1738 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1739 for ( ; anIter->More(); anIter->Next() )
1741 _PTR(SObject) anObj = anIter->Value();
1742 _PTR(SObject) aRefObj;
1743 if ( anObj->ReferencedObject( aRefObj ) )
1748 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1750 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1751 if ( CORBA::is_nil( aVar ) )
1754 SMESH::SMESH_Algo_var algo;
1755 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1758 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1759 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1760 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1763 if ( !algo->_is_nil() )
1765 theModeMap[ dim ] = 0;
1766 if ( theModeMap.size() == 3 )
1776 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart < SMESH::Tag_LastSubMesh; ++aPart )
1778 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1781 _PTR(ChildIterator) anIter =
1782 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1783 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1785 _PTR(SObject) anObj = anIter->Value();
1786 _PTR(SObject) aRefObj;
1787 if ( anObj->ReferencedObject( aRefObj ) )
1792 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1794 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1795 if ( CORBA::is_nil( aVar ) )
1798 SMESH::SMESH_Algo_var algo;
1799 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1802 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1803 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1804 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1807 if ( !algo->_is_nil() )
1809 theModeMap[ dim ] = 0;
1810 if ( theModeMap.size() == 3 )
1820 //================================================================================
1822 * \brief perform it's intention action: compute mesh
1824 //================================================================================
1826 void SMESHGUI_PrecomputeOp::onCompute()
1829 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1830 myOrderMgr->SetMeshOrder();
1831 myMapShapeId.clear();
1832 myActiveDlg = computeDlg();
1833 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1837 //================================================================================
1839 * \brief perform it's intention action: compute mesh
1841 //================================================================================
1843 void SMESHGUI_PrecomputeOp::onCancel()
1845 QObject* curDlg = sender();
1846 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1848 // return from error messages
1853 bool isRestoreOrder = false;
1854 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1856 // ask to remove already computed mesh elements
1857 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1858 tr( "CLEAR_SUBMESH_QUESTION" ),
1859 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1861 // remove all submeshes for collected shapes
1862 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1863 for ( ; it != myMapShapeId.constEnd(); ++it )
1864 myMesh->ClearSubMesh( it.key() );
1865 isRestoreOrder = true;
1869 // return previous mesh order
1870 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1871 if (!isRestoreOrder)
1873 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1874 tr( "SMESH_REJECT_MESH_ORDER" ),
1875 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1877 myOrderMgr->SetMeshOrder(myPrevOrder);
1883 myMapShapeId.clear();
1884 SMESHGUI_BaseComputeOp::onCancel();
1887 //================================================================================
1889 * \brief perform it's intention action: preview mesh
1891 //================================================================================
1893 void SMESHGUI_PrecomputeOp::onPreview()
1895 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1898 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1902 // set modified submesh priority if any
1903 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1904 myOrderMgr->SetMeshOrder();
1906 // Compute preview of mesh,
1907 // i.e. compute mesh till indicated dimension
1908 int dim = myDlg->getPreviewMode();
1910 SMESH::MemoryReserve aMemoryReserve;
1912 SMESH::compute_error_array_var aCompErrors;
1915 bool computeFailed = true, memoryLack = false;
1917 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1918 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1920 SMESHGUI* gui = getSMESHGUI();
1921 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1922 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1923 if ( errors->length() > 0 ) {
1924 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1927 SUIT_OverrideCursor aWaitCursor;
1929 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1930 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1931 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1933 SMESH::long_array_var aShapesId = new SMESH::long_array();
1935 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1939 SMESH::MeshPreviewStruct_var previewData =
1940 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1942 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1943 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1945 computeFailed = false;
1946 myPreviewDisplayer->SetData( previewRes );
1947 // append shape indeces with computed mesh entities
1948 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1949 myMapShapeId[ aShapesId[ i ] ] = 0;
1952 myPreviewDisplayer->SetVisibility(false);
1954 catch(const SALOME::SALOME_Exception & S_ex){
1956 myPreviewDisplayer->SetVisibility(false);
1960 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1963 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1964 // check if there are memory problems
1965 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1966 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1968 catch(const SALOME::SALOME_Exception & S_ex){
1973 aMemoryReserve.release();
1975 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1976 bool noHypoError = ( aHypErrors.isEmpty() );
1978 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1979 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1981 bool isShowError = true;
1982 switch( aNotifyMode ) {
1983 case 0: // show the mesh computation result dialog NEVER
1984 isShowError = false;
1986 case 1: // show the mesh computation result dialog if there are some errors
1987 default: // show the result dialog after each mesh computation
1988 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1989 isShowError = false;
1993 aWaitCursor.suspend();
1998 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1999 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2004 //================================================================================
2006 * \brief Constructor
2008 //================================================================================
2010 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2011 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2014 setWindowTitle( tr( "CAPTION" ) );
2016 setButtonText( OK, tr( "COMPUTE" ) );
2017 QFrame* main = mainFrame();
2018 main->setMinimumWidth( 300 );
2020 QVBoxLayout* layout = new QVBoxLayout( main );
2022 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2023 layout->addWidget(myOrderBox);
2025 QFrame* frame = new QFrame( main );
2026 layout->setMargin(0); layout->setSpacing(0);
2027 layout->addWidget( frame );
2029 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2030 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2032 myPreviewMode = new QtxComboBox( frame );
2033 frameLay->addWidget( myPreviewMode );
2035 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2036 frameLay->addWidget( myPreviewBtn );
2038 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2041 //================================================================================
2045 //================================================================================
2047 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2051 //================================================================================
2053 * \brief Sets available preview modes
2055 //================================================================================
2057 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2059 myPreviewMode->clear();
2060 QList<int>::const_iterator it = theModes.constBegin();
2061 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2063 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2064 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2065 myPreviewMode->setId( i, *it );
2067 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2070 //================================================================================
2072 * \brief Returns current preview mesh mode
2074 //================================================================================
2076 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2078 return myPreviewMode->currentId();
2081 //================================================================================
2083 * \brief Returns current preview mesh mode
2085 //================================================================================
2087 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2093 //================================================================================
2095 * \brief Constructor
2097 //================================================================================
2099 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2100 : SMESHGUI_BaseComputeOp()
2102 myHelpFileName = "constructing_meshes_page.html#evaluate_anchor";
2106 //================================================================================
2108 * \brief Desctructor
2110 //================================================================================
2112 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2116 //================================================================================
2118 * \brief perform it's intention action: compute mesh
2120 //================================================================================
2122 void SMESHGUI_EvaluateOp::startOperation()
2124 SMESHGUI_BaseComputeOp::evaluateDlg();
2125 SMESHGUI_BaseComputeOp::startOperation();
2126 if (myMesh->_is_nil())
2131 //================================================================================
2133 * \brief Gets dialog of this operation
2134 * \retval LightApp_Dialog* - pointer to dialog of this operation
2136 //================================================================================
2138 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2140 return evaluateDlg();
2143 //================================================================================
2145 * \brief evaluateMesh()
2147 //================================================================================
2149 void SMESHGUI_BaseComputeOp::evaluateMesh()
2153 SMESH::MemoryReserve aMemoryReserve;
2155 SMESH::compute_error_array_var aCompErrors;
2158 bool evaluateFailed = true, memoryLack = false;
2159 SMESH::long_array_var aRes;
2161 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2162 if ( !aMeshSObj ) // IPAL21340
2165 bool hasShape = myMesh->HasShapeToMesh();
2166 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2169 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2170 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2171 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2172 if ( errors->length() > 0 ) {
2173 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2175 SUIT_OverrideCursor aWaitCursor;
2177 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2180 aRes = gen->Evaluate(myMesh, myMainShape);
2182 catch(const SALOME::SALOME_Exception & S_ex){
2187 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2190 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2192 catch(const SALOME::SALOME_Exception & S_ex){
2198 aMemoryReserve.release();
2200 evaluateFailed = ( aCompErrors->length() > 0 );
2201 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
2205 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2206 bool noHypoError = ( aHypErrors.isEmpty() );
2208 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2209 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2211 bool isShowResultDlg = true;
2213 //switch( aNotifyMode ) {
2214 //case 0: // show the mesh computation result dialog NEVER
2215 //isShowResultDlg = false;
2218 //case 1: // show the mesh computation result dialog if there are some errors
2219 //if ( memoryLack || !noHypoError )
2220 // isShowResultDlg = true;
2223 // isShowResultDlg = false;
2227 //default: // show the result dialog after each mesh computation
2228 //isShowResultDlg = true;
2232 if ( isShowResultDlg )
2233 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2234 noHypoError, aHypErrors);
2238 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2239 const bool theMemoryLack,
2240 const bool theNoCompError,
2241 SMESH::compute_error_array_var& theCompErrors,
2242 const bool theNoHypoError,
2243 const QString& theHypErrors)
2245 bool hasShape = myMesh->HasShapeToMesh();
2246 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2247 aCompDlg->myMemoryLackGroup->hide();
2249 if ( theMemoryLack )
2251 aCompDlg->myMemoryLackGroup->show();
2252 aCompDlg->myFullInfo->hide();
2253 aCompDlg->myBriefInfo->hide();
2254 aCompDlg->myHypErrorGroup->hide();
2255 aCompDlg->myCompErrorGroup->hide();
2257 else if ( theNoCompError && theNoHypoError )
2259 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2260 aCompDlg->myFullInfo->show();
2261 aCompDlg->myBriefInfo->hide();
2262 aCompDlg->myHypErrorGroup->hide();
2263 aCompDlg->myCompErrorGroup->hide();
2267 QTableWidget* tbl = aCompDlg->myTable;
2268 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2269 aCompDlg->myBriefInfo->show();
2270 aCompDlg->myFullInfo->hide();
2272 if ( theNoHypoError ) {
2273 aCompDlg->myHypErrorGroup->hide();
2276 aCompDlg->myHypErrorGroup->show();
2277 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2280 if ( theNoCompError ) {
2281 aCompDlg->myCompErrorGroup->hide();
2284 aCompDlg->myCompErrorGroup->show();
2286 aCompDlg->myPublishBtn->hide();
2287 aCompDlg->myShowBtn->hide();
2289 // fill table of errors
2290 tbl->setRowCount( theCompErrors->length() );
2291 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2292 else tbl->showColumn( COL_SHAPE );
2293 tbl->setColumnWidth( COL_ERROR, 200 );
2295 bool hasBadMesh = false;
2296 for ( int row = 0; row < theCompErrors->length(); ++row )
2298 SMESH::ComputeError & err = theCompErrors[ row ];
2300 QString text = err.algoName.in();
2301 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2302 else tbl->item( row, COL_ALGO )->setText( text );
2304 text = SMESH::errorText( err.code, err.comment.in() );
2305 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2306 else tbl->item( row, COL_ERROR )->setText( text );
2308 text = QString("%1").arg( err.subShapeID );
2309 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2310 else tbl->item( row, COL_SHAPEID )->setText( text );
2312 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2313 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2314 else tbl->item( row, COL_SHAPE )->setText( text );
2316 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2317 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2318 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2320 text = err.hasBadMesh ? "hasBadMesh" : "";
2321 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2322 else tbl->item( row, COL_BAD_MESH )->setText( text );
2323 if ( err.hasBadMesh ) hasBadMesh = true;
2325 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2326 tbl->resizeRowToContents( row );
2328 tbl->resizeColumnToContents( COL_ALGO );
2329 tbl->resizeColumnToContents( COL_SHAPE );
2330 tbl->setWordWrap( true );
2334 aCompDlg->myBadMeshBtn->show();
2335 aCompDlg->myBadMeshToGroupBtn->show();
2339 aCompDlg->myBadMeshBtn->hide();
2340 aCompDlg->myBadMeshToGroupBtn->hide();
2342 tbl->setCurrentCell(0,0);
2343 currentCellChanged(); // to update buttons
2346 // show dialog and wait, becase Compute can be invoked from Preview operation
2347 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2352 //================================================================================
2354 * \brief Gets dialog of evaluate operation
2355 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2357 //================================================================================
2359 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2363 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2364 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2365 // connect signals and slots
2366 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2367 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2368 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2369 QTableWidget* aTable = me->table();
2370 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2371 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));