1 // Copyright (C) 2007-2016 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 <SVTK_Renderer.h>
58 #include <SalomeApp_Application.h>
60 // SALOME KERNEL includes
61 #include <SALOMEDS_SObject.hxx>
62 #include <SALOMEDSClient_SObject.hxx>
63 #include <SALOMEDS_wrap.hxx>
64 #include "utilities.h"
66 #include CORBA_SERVER_HEADER(SMESH_Group)
69 #include <BRepBndLib.hxx>
70 #include <BRepMesh_IncrementalMesh.hxx>
71 #include <BRep_Tool.hxx>
72 #include <Bnd_Box.hxx>
73 #include <Poly_Triangulation.hxx>
75 #include <TopExp_Explorer.hxx>
76 #include <TopLoc_Location.hxx>
77 #include <TopTools_IndexedMapOfShape.hxx>
80 #include <Standard_ErrorHandler.hxx>
84 #include <QPushButton>
86 #include <QRadioButton>
87 #include <QTableWidget>
88 #include <QHeaderView>
89 #include <QGridLayout>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QButtonGroup>
93 #include <QCloseEvent>
94 #include <QTimerEvent>
95 #include <QProgressBar>
98 #include <vtkProperty.h>
99 #include <vtkRenderer.h>
105 #if !defined WIN32 && !defined __APPLE__
106 #include <sys/sysinfo.h>
112 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
113 #define __SHAPE_RGB__ 250, 0, 250
116 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
119 //using namespace SMESH;
123 //=============================================================================
125 * \brief Allocate some memory at construction and release it at destruction.
126 * Is used to be able to continue working after mesh generation or visualization
127 * break due to lack of memory
129 //=============================================================================
134 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
135 void release() { delete [] myBuf; myBuf = 0; }
136 ~MemoryReserve() { release(); }
139 // =========================================================================================
141 * \brief Class showing shapes without publishing
143 // =========================================================================================
145 class TShapeDisplayer
148 // -----------------------------------------------------------------------
149 TShapeDisplayer(): myViewWindow(0)
151 myProperty = vtkProperty::New();
152 myProperty->SetRepresentationToWireframe();
153 myProperty->SetColor( __SHAPE_RGB__ );
154 myProperty->SetAmbientColor( __SHAPE_RGB__ );
155 myProperty->SetDiffuseColor( __SHAPE_RGB__ );
156 //myProperty->SetSpecularColor( __SHAPE_RGB__ );
157 myProperty->SetLineWidth( 5 );
159 // -----------------------------------------------------------------------
163 myProperty->Delete();
165 // -----------------------------------------------------------------------
168 if ( hasViewWindow() ) {
169 TActorIterator actorIt = actorIterator();
170 while ( actorIt.more() )
171 if (VTKViewer_Actor* anActor = actorIt.next()) {
172 myViewWindow->RemoveActor( anActor );
176 myIndexToShape.Clear();
178 myShownActors.clear();
181 // -----------------------------------------------------------------------
182 void SetVisibility (bool theVisibility)
184 TActorIterator actorIt = shownIterator();
185 while ( actorIt.more() )
186 if (VTKViewer_Actor* anActor = actorIt.next())
187 anActor->SetVisibility(theVisibility);
188 SMESH::RepaintCurrentView();
190 // -----------------------------------------------------------------------
191 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
193 std::string mainEntry;
194 if ( !aMainShape->_is_nil() )
195 mainEntry = aMainShape->GetStudyEntry();
196 return ( myMainEntry == mainEntry &&
197 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
199 // -----------------------------------------------------------------------
200 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
202 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
203 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
204 std::string mainEntry;
205 if ( !aMainShape->_is_nil() )
206 mainEntry = aMainShape->GetStudyEntry();
207 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
210 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
211 checkTriangulation( aShape );
212 TopExp::MapShapes(aShape, myIndexToShape);
213 myActors.resize( myIndexToShape.Extent(), 0 );
214 myShownActors.reserve( myIndexToShape.Extent() );
216 myMainEntry = mainEntry;
217 myViewWindow = aViewWindow;
219 if ( only ) { // hide shown actors
220 TActorIterator actorIt = shownIterator();
221 while ( actorIt.more() )
222 if (VTKViewer_Actor* anActor = actorIt.next())
223 anActor->SetVisibility(false);
224 myShownActors.clear();
226 // find actors to show
227 TopoDS_Shape aShape = myIndexToShape( subShapeID );
228 if ( !aShape.IsNull() ) {
229 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
230 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
231 //checkTriangulation( exp.Current() );
232 if ( GEOM_Actor* anActor = getActor( exp.Current() ) ) {
233 int UNbIsos = resMgr->integerValue( "Geometry", "iso_number_u", 1);
234 int VNbIsos = resMgr->integerValue( "Geometry", "iso_number_v", 1);
235 int aNbIsos[2] = { UNbIsos ? UNbIsos : 1, VNbIsos ? VNbIsos : 1 };
236 anActor->SetNbIsos( aNbIsos );
237 myShownActors.push_back( anActor );
240 if ( type == TopAbs_FACE ) {
241 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
242 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
243 if ( !BRep_Tool::Degenerated( edge ))
244 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
245 myShownActors.push_back( anActor );
249 myBuiltSubs.insert( subShapeID );
252 // -----------------------------------------------------------------------
256 typedef std::vector<GEOM_Actor*> TActorVec;
258 TActorVec myShownActors;
259 TopTools_IndexedMapOfShape myIndexToShape;
260 std::string myMainEntry;
261 SVTK_ViewWindow* myViewWindow;
262 vtkProperty* myProperty;
263 std::set<int> myBuiltSubs;
265 // -----------------------------------------------------------------------
266 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
267 TActorIterator actorIterator() {
268 return TActorIterator( myActors.begin(), myActors.end() );
270 TActorIterator shownIterator() {
271 return TActorIterator( myShownActors.begin(), myShownActors.end() );
273 // -----------------------------------------------------------------------
274 GEOM_Actor* getActor(const TopoDS_Shape& shape)
276 int index = myIndexToShape.FindIndex( shape ) - 1;
277 if ( index < 0 || index >= (int) myActors.size() )
279 GEOM_Actor* & actor = myActors[ index ];
281 actor = GEOM_Actor::New();
283 actor->SetShape(shape,0,0);
284 // actor->SetProperty(myProperty);
285 // actor->SetShadingProperty(myProperty);
286 // actor->SetWireframeProperty(myProperty);
287 // actor->SetPreviewProperty(myProperty);
288 actor->PickableOff();
290 actor->SetWidth( myProperty->GetLineWidth() );
291 actor->SetIsosWidth( myProperty->GetLineWidth() );
292 actor->SetIsosColor( __SHAPE_RGB__ );
293 actor->SetColor( __SHAPE_RGB__ );
294 // if ( shape.ShapeType() == TopAbs_EDGE )
295 // actor->SubShapeOn();
296 myViewWindow->AddActor( actor );
301 // -----------------------------------------------------------------------
302 void checkTriangulation(const TopoDS_Shape& shape)
304 TopLoc_Location aLoc;
305 Standard_Boolean alreadymesh = Standard_True;
306 TopExp_Explorer ex(shape, TopAbs_FACE);
308 for ( ; ex.More(); ex.Next()) {
309 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
310 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
311 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
314 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
315 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
316 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
317 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
319 if (alreadymesh) return;
320 // Compute default deflection
322 BRepBndLib::Add(shape, B);
323 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
324 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
325 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
326 BRepMesh_IncrementalMesh MESH(shape,deflection);
328 // -----------------------------------------------------------------------
329 bool hasViewWindow() const
331 if ( !myViewWindow ) return false;
333 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
334 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
340 // =========================================================================================
342 * \brief Return text describing an error
344 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
345 QString errorText(int errCode, const char* comment)
349 CASE2TEXT( COMPERR_OK );
350 CASE2TEXT( COMPERR_BAD_INPUT_MESH );
351 CASE2TEXT( COMPERR_STD_EXCEPTION );
352 CASE2TEXT( COMPERR_OCC_EXCEPTION );
353 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
354 CASE2TEXT( COMPERR_EXCEPTION );
355 CASE2TEXT( COMPERR_MEMORY_PB );
356 CASE2TEXT( COMPERR_BAD_SHAPE );
357 CASE2TEXT( COMPERR_CANCELED );
358 CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
359 CASE2TEXT( COMPERR_BAD_PARMETERS );
360 case SMESH::COMPERR_ALGO_FAILED:
361 if ( strlen(comment) == 0 )
362 text = QObject::tr("COMPERR_ALGO_FAILED");
364 case SMESH::COMPERR_WARNING:
365 text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
368 text = QString("#%1").arg( -errCode );
370 if ( text.length() > 0 ) text += ". ";
371 return text + comment;
373 // -----------------------------------------------------------------------
375 * \brief Return SO of a sub-shape
377 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
379 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
380 if ( subShapeID == 1 || !so )
382 _PTR(ChildIterator) it;
383 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
384 it = study->NewChildIterator(so);
387 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
388 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
389 if ( !geom->_is_nil() ) {
390 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
391 if ( list->length() == 1 && list[0] == subShapeID )
393 GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
394 if ( aMainShape->IsSame( mainGO ))
402 // -----------------------------------------------------------------------
404 * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
406 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
408 GEOM::GEOM_Object_var aSubShape;
409 if ( subShapeID == 1 ) {
410 aSubShape = aMainShape;
411 aSubShape->Register();
413 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
414 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
415 aSubShape->Register();
418 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
419 // future call of UnRegister() will delete a servant of this new object
421 return aSubShape._retn();
423 // -----------------------------------------------------------------------
425 * \brief Return shape type name
427 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
428 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
431 if ( !aShape->_is_nil() ) {
432 switch ( aShape->GetShapeType() ) {
439 CASE2NAME( COMPSOLID );
440 CASE2NAME( COMPOUND );
446 // -----------------------------------------------------------------------
448 * \brief Return text describing a sub-shape
450 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
453 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
454 text = aSO->GetName().c_str();
455 text += QString(" (%1)").arg( aSO->GetID().c_str() );
458 text = QString("#%1").arg( subShapeID );
459 GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
460 QString typeName = shapeTypeName( shape );
461 if ( typeName.length() )
462 text += QString(" (%1)").arg(typeName);
466 // -----------------------------------------------------------------------
468 * \brief Return a list of selected rows
470 int getSelectedRows(QTableWidget* table, QList<int>& rows)
473 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
474 QTableWidgetSelectionRange range;
475 foreach( range, selRanges )
477 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
478 if ( !rows.count( row ))
481 if ( rows.isEmpty() && table->currentRow() > -1 )
482 if ( !rows.count( table->currentRow() ))
483 rows.append( table->currentRow() );
491 // =========================================================================================
493 * \brief Dialog to compute a mesh and show computation errors
495 //=======================================================================
497 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
498 : SMESHGUI_Dialog( parent, false, true, Close | Help )
500 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
501 aDlgLay->setMargin( 0 );
502 aDlgLay->setSpacing( SPACING );
504 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
506 aDlgLay->addWidget(aMainFrame);
508 aDlgLay->setStretchFactor(aMainFrame, 1);
511 // =========================================================================================
515 //=======================================================================
517 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
521 //=======================================================================
522 // function : createMainFrame()
523 // purpose : Create frame containing dialog's fields
524 //=======================================================================
526 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
528 QFrame* aFrame = new QFrame(theParent);
530 SUIT_ResourceMgr* rm = resourceMgr();
531 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
537 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
540 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
542 QButtonGroup* aBtnGrp = new QButtonGroup(this);
543 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
544 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
546 QRadioButton* aRBut = new QRadioButton(aPixGrp);
547 aRBut->setIcon(iconCompute);
548 aRBut->setChecked(true);
549 aPixGrpLayout->addWidget(aRBut);
550 aBtnGrp->addButton(aRBut, 0);
554 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
555 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
556 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
557 myMeshName = new QLabel(nameBox);
558 nameBoxLayout->addWidget(myMeshName);
562 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
563 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
565 // Computation errors
567 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
568 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
569 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
570 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
571 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
572 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
573 myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
575 //myTable->setReadOnly( true ); // VSR: check
576 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
577 myTable->hideColumn( COL_PUBLISHED );
578 myTable->hideColumn( COL_SHAPEID );
579 myTable->hideColumn( COL_BAD_MESH );
580 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
581 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
583 myTable->horizontalHeader()->setSectionResizeMode( COL_ERROR, QHeaderView::Interactive );
585 myTable->setWordWrap( true );
586 myTable->horizontalHeader()->setStretchLastSection( true );
587 myTable->setMinimumWidth( 500 );
590 headers << tr( "COL_ALGO_HEADER" );
591 headers << tr( "COL_SHAPE_HEADER" );
592 headers << tr( "COL_ERROR_HEADER" );
593 headers << tr( "COL_SHAPEID_HEADER" );
594 headers << tr( "COL_PUBLISHED_HEADER" );
596 myTable->setHorizontalHeaderLabels( headers );
599 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
600 grpLayout->setSpacing(SPACING);
601 grpLayout->setMargin(MARGIN);
602 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
603 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
604 grpLayout->addWidget( myShowBtn, 2, 0 );
605 grpLayout->addWidget( myPublishBtn, 2, 1 );
606 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
607 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
608 grpLayout->setColumnStretch( 3, 1 );
610 // Hypothesis definition errors
612 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
613 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
614 myHypErrorGroupLayout->setMargin(MARGIN);
615 myHypErrorGroupLayout->setSpacing(SPACING);
616 myHypErrorLabel = new QLabel(myHypErrorGroup);
617 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
621 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
622 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
623 myMemoryLackGroupLayout->setMargin(MARGIN);
624 myMemoryLackGroupLayout->setSpacing(SPACING);
625 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
626 QFont bold = memLackLabel->font(); bold.setBold(true);
627 memLackLabel->setFont( bold );
628 memLackLabel->setMinimumWidth(300);
629 myMemoryLackGroupLayout->addWidget(memLackLabel);
631 // add all widgets to aFrame
632 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
633 aLay->setMargin( MARGIN );
634 aLay->setSpacing( SPACING );
635 aLay->addWidget( aPixGrp );
636 aLay->addWidget( nameBox );
637 aLay->addWidget( myBriefInfo );
638 aLay->addWidget( myFullInfo );
639 aLay->addWidget( myHypErrorGroup );
640 aLay->addWidget( myCompErrorGroup );
641 aLay->addWidget( myMemoryLackGroup );
642 aLay->setStretchFactor( myCompErrorGroup, 1 );
644 ((QPushButton*) button( OK ))->setDefault( true );
649 //================================================================================
653 //================================================================================
655 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
656 : SMESHGUI_Operation(), myCompDlg( 0 )
658 myTShapeDisplayer = new SMESH::TShapeDisplayer();
659 myBadMeshDisplayer = 0;
661 //myHelpFileName = "/files/about_meshes.htm"; // V3
662 myHelpFileName = "about_meshes_page.html"; // V4
665 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
667 LightApp_SelectionMgr* Sel = selectionMgr();
668 SALOME_ListIO selected; Sel->selectedObjects( selected );
669 Handle(SALOME_InteractiveObject) anIO = selected.First();
670 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
671 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
674 //================================================================================
676 * \brief Start operation
677 * \purpose Init dialog fields, connect signals and slots, show dialog
679 //================================================================================
681 void SMESHGUI_BaseComputeOp::startOperation()
683 // create compute dialog if not created before
686 myMesh = SMESH::SMESH_Mesh::_nil();
687 myMainShape = GEOM::GEOM_Object::_nil();
688 myCurShape = GEOM::GEOM_Object::_nil();
691 LightApp_SelectionMgr *Sel = selectionMgr();
692 SALOME_ListIO selected; Sel->selectedObjects( selected );
694 int nbSel = selected.Extent();
696 SUIT_MessageBox::warning(desktop(),
697 tr("SMESH_WRN_WARNING"),
698 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
703 myIObject = selected.First();
704 CORBA::Object_var anObj = SMESH::IObjectToObject( myIObject );
706 myMesh = SMESH::SMESH_Mesh::_narrow(anObj);
707 if ( myMesh->_is_nil() )
709 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
710 if ( !aSubMesh->_is_nil() )
712 myMesh = aSubMesh->GetFather();
713 myCurShape = aSubMesh->GetSubShape();
718 myCurShape = myMesh->GetShapeToMesh();
721 if (myMesh->_is_nil()) {
722 SUIT_MessageBox::warning(desktop(),
723 tr("SMESH_WRN_WARNING"),
724 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
729 myMainShape = myMesh->GetShapeToMesh();
731 SMESHGUI_Operation::startOperation();
734 //================================================================================
735 //================================================================================
737 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
738 SMESH::SMESH_Mesh_var mesh,
739 GEOM::GEOM_Object_var mainShape)
744 myMainShape = mainShape;
747 void SMESHGUI_ComputeDlg_QThread::run()
749 myResult = myGen->Compute(myMesh, myMainShape);
752 bool SMESHGUI_ComputeDlg_QThread::result()
757 void SMESHGUI_ComputeDlg_QThread::cancel()
759 myGen->CancelCompute(myMesh, myMainShape);
762 //================================================================================
763 //================================================================================
765 SMESHGUI_ComputeDlg_QThreadQDialog::
766 SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
767 SMESH::SMESH_Gen_var gen,
768 SMESH::SMESH_Mesh_var mesh,
769 GEOM::GEOM_Object_var mainShape)
771 Qt::WindowSystemMenuHint |
772 Qt::WindowCloseButtonHint |
774 Qt::WindowMaximizeButtonHint),
775 qthread(gen, mesh, mainShape)
778 setWindowTitle(tr("TITLE"));
779 setMinimumWidth( 200 );
781 cancelButton = new QPushButton(tr("CANCEL"));
782 cancelButton->setDefault(true);
783 cancelButton->setCheckable(true);
785 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
786 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
787 nbNodesLabel = new QLabel("0", this );
788 nbElemsLabel = new QLabel("0", this );
789 #if !defined WIN32 && !defined __APPLE__
790 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
791 freeRAMLabel = new QLabel("", this );
793 progressBar = new QProgressBar(this);
794 progressBar->setMinimum( 0 );
795 progressBar->setMaximum( 1000 );
797 QGridLayout* layout = new QGridLayout(this);
798 layout->setMargin( MARGIN );
799 layout->setSpacing( SPACING );
801 layout->addWidget(nbNodesName, row, 0);
802 layout->addWidget(nbNodesLabel, row++, 1);
803 layout->addWidget(nbElemsName, row, 0);
804 layout->addWidget(nbElemsLabel, row++, 1);
805 #if !defined WIN32 && !defined __APPLE__
806 layout->addWidget(freeRAMName, row, 0);
807 layout->addWidget(freeRAMLabel, row++, 1);
809 layout->addWidget(progressBar, row++, 0, 1, 2);
810 layout->addWidget(cancelButton, row++, 0, 1, 2);
814 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
816 startTimer(300); // millisecs
820 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
822 return qthread.result();
825 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
828 cancelButton->setText( tr("CANCELING"));
829 cancelButton->setEnabled(false);
832 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
834 if ( !cancelButton->isChecked() ) // not yet cancelled
835 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
837 if(qthread.isFinished())
843 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
844 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
845 #if !defined WIN32 && !defined __APPLE__
847 const int err = sysinfo( &si );
849 freeRAMLabel->setText("");
851 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
852 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
858 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
860 if(qthread.isRunning())
868 //================================================================================
870 * \brief computeMesh()
872 //================================================================================
874 void SMESHGUI_BaseComputeOp::computeMesh()
878 SMESH::MemoryReserve aMemoryReserve;
880 SMESH::compute_error_array_var aCompErrors;
883 bool computeFailed = true, memoryLack = false;
885 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
886 if ( !aMeshSObj ) // IPAL 21340
888 bool hasShape = myMesh->HasShapeToMesh();
889 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
892 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
893 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
894 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
895 if ( errors->length() > 0 ) {
896 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
898 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
899 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
900 tr( "FULL_RECOMPUTE_QUESTION" ),
901 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
903 SUIT_OverrideCursor aWaitCursor;
906 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myCurShape);
907 qthreaddialog.exec();
908 computeFailed = !qthreaddialog.result();
910 catch(const SALOME::SALOME_Exception & S_ex) {
915 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
916 // check if there are memory problems
917 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
918 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
920 catch(const SALOME::SALOME_Exception & S_ex) {
924 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
928 // NPAL16631: if ( !memoryLack )
930 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID(myIObject->getEntry());
931 SMESH::ModifiedMesh( sobj,
932 !computeFailed && aHypErrors.isEmpty(),
933 myMesh->NbNodes() == 0);
934 update( UF_ObjBrowser | UF_Model );
937 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
938 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
940 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
941 int entities = SMESH_Actor::eAllEntity;
946 // List of objects that will be updated automatically
947 typedef QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > TListOf_IDSrc_SObj;
948 TListOf_IDSrc_SObj aListToUpdate;
949 SMESH::SMESH_IDSource_var aMeshObj =
950 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
951 // put Mesh into list
952 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aMeshObj, aMeshSObj ));
953 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
954 // put SubMeshes into list
955 for ( CORBA::ULong i = 0; i < aSubMeshes->length(); i++ )
957 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
958 if ( CORBA::is_nil( sm ) ) continue;
959 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
960 if ( !smSObj ) continue;
961 SMESH::SMESH_IDSource_var aSubMeshObj =
962 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
963 SMESH_Actor *anActor = SMESH::FindActorByObject( aSubMeshObj );
964 if ( anActor && anActor->GetVisibility() )
965 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aSubMeshObj, smSObj ));
967 // put Groups into list
968 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
969 for ( size_t i = 0; i < aGroups->length(); ++i )
971 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
972 if ( CORBA::is_nil( aGrp ) ) continue;
973 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
974 if ( !aStdGroup->_is_nil() ) continue; // don't update standalone groups
975 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
976 if ( !aGroupSO ) continue;
977 SMESH::SMESH_IDSource_var aGroupObj =
978 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
979 SMESH_Actor *anActor = SMESH::FindActorByObject( aGroupObj );
980 if ( anActor && anActor->GetVisibility() )
981 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aGroupObj, aGroupSO ));
984 // update mesh, sub-mesh and groups, if it's possible
985 TListOf_IDSrc_SObj::iterator anIter;
986 for ( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ )
988 SMESH::SMESH_Mesh_var aMesh =
989 SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
991 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded,
992 &hidden, &nbElements ) )
996 bool toDisplay = false;
997 if ( !aMesh->_is_nil() ) // display only a mesh
1000 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
1001 if ( !anActor ) anActor = SMESH::CreateActor( (*anIter).second->GetStudy(),
1002 (*anIter).second->GetID().c_str(),
1003 /*clearLog =*/ true );
1004 if ( anActor ) // actor is not created for an empty mesh
1006 anActor->SetEntityMode( entities );
1007 SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
1010 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1011 ( (*anIter).second->GetID().c_str(), "SMESH", (*anIter).second->GetName().c_str() );
1012 SMESH::Update(anIO, toDisplay);
1014 if ( SVTK_ViewWindow* vtkWnd = SMESH::GetVtkViewWindow(SMESH::GetActiveWindow() ))
1015 if ( vtkWnd->getRenderer() )
1016 vtkWnd->getRenderer()->ResetCameraClippingRange();
1018 if ( limitExceeded && !aMesh->_is_nil() )
1020 QStringList hiddenMsg;
1021 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1022 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
1023 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
1024 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
1025 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
1026 SUIT_MessageBox::warning( desktop(),
1027 tr( "SMESH_WRN_WARNING" ),
1028 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1031 arg( hiddenMsg.join(", ")));
1036 MESSAGE ( "Exception thrown during mesh visualization" );
1038 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1039 SMESH::OnVisuException();
1046 else if ( limitExceeded && !aMesh->_is_nil() )
1048 SUIT_MessageBox::warning( desktop(),
1049 tr( "SMESH_WRN_WARNING" ),
1050 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1051 arg( nbElements ).arg( limitSize ) );
1055 if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1057 SALOME_ListIO selected;
1058 selected.Append( myIObject );
1059 Sel->setSelectedObjects( selected );
1065 aMemoryReserve.release();
1067 myCompDlg->setWindowTitle
1068 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1072 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1073 bool noHypoError = ( aHypErrors.isEmpty() );
1075 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1076 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1078 bool isShowResultDlg = true;
1079 switch( aNotifyMode ) {
1080 case 0: // show the mesh computation result dialog NEVER
1081 isShowResultDlg = false;
1084 case 1: // show the mesh computation result dialog if there are some errors
1085 if ( memoryLack || !noCompError || !noHypoError )
1086 isShowResultDlg = true;
1089 isShowResultDlg = false;
1093 default: // show the result dialog after each mesh computation
1094 isShowResultDlg = true;
1098 if ( isShowResultDlg )
1099 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1102 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1103 const bool theNoCompError,
1104 SMESH::compute_error_array_var& theCompErrors,
1105 const bool theNoHypoError,
1106 const QString& theHypErrors )
1108 bool hasShape = myMesh->HasShapeToMesh();
1109 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1110 aCompDlg->myMemoryLackGroup->hide();
1112 if ( theMemoryLack )
1114 aCompDlg->myMemoryLackGroup->show();
1115 aCompDlg->myFullInfo->hide();
1116 aCompDlg->myBriefInfo->hide();
1117 aCompDlg->myHypErrorGroup->hide();
1118 aCompDlg->myCompErrorGroup->hide();
1120 else if ( theNoCompError && theNoHypoError )
1122 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1123 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1124 aCompDlg->myFullInfo->show();
1125 aCompDlg->myBriefInfo->hide();
1126 aCompDlg->myHypErrorGroup->hide();
1127 aCompDlg->myCompErrorGroup->hide();
1131 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1132 for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1133 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1134 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1136 // full or brief mesh info
1137 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1138 if ( onlyWarnings ) {
1139 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1140 aCompDlg->myFullInfo->show();
1141 aCompDlg->myBriefInfo->hide();
1143 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1144 aCompDlg->myBriefInfo->show();
1145 aCompDlg->myFullInfo->hide();
1148 // pbs of hypo dfinitions
1149 if ( theNoHypoError ) {
1150 aCompDlg->myHypErrorGroup->hide();
1152 aCompDlg->myHypErrorGroup->show();
1153 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1157 if ( theNoCompError )
1159 aCompDlg->myCompErrorGroup->hide();
1163 aCompDlg->myCompErrorGroup->show();
1166 aCompDlg->myWarningLabel->show();
1168 aCompDlg->myWarningLabel->hide();
1171 aCompDlg->myPublishBtn->hide();
1172 aCompDlg->myShowBtn->hide();
1175 aCompDlg->myPublishBtn->show();
1176 aCompDlg->myShowBtn->show();
1179 // fill table of errors
1180 QTableWidget* tbl = aCompDlg->myTable;
1181 tbl->setRowCount( theCompErrors->length() );
1182 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1183 else tbl->showColumn( COL_SHAPE );
1184 tbl->setColumnWidth( COL_ERROR, 200 );
1186 bool hasBadMesh = false;
1187 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1189 SMESH::ComputeError & err = theCompErrors[ row ];
1191 QString text = err.algoName.in();
1192 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1193 else tbl->item( row, COL_ALGO )->setText( text );
1195 text = SMESH::errorText( err.code, err.comment.in() );
1196 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1197 else tbl->item( row, COL_ERROR )->setText( text );
1199 text = QString("%1").arg( err.subShapeID );
1200 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1201 else tbl->item( row, COL_SHAPEID )->setText( text );
1203 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1204 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1205 else tbl->item( row, COL_SHAPE )->setText( text );
1207 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1208 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1209 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1211 text = err.hasBadMesh ? "hasBadMesh" : "";
1212 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1213 else tbl->item( row, COL_BAD_MESH )->setText( text );
1214 if ( err.hasBadMesh ) hasBadMesh = true;
1216 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1217 tbl->resizeRowToContents( row );
1219 tbl->resizeColumnToContents( COL_ALGO );
1220 tbl->resizeColumnToContents( COL_SHAPE );
1221 tbl->setWordWrap( true );
1224 aCompDlg->myBadMeshBtn->show();
1225 aCompDlg->myBadMeshToGroupBtn->show();
1228 aCompDlg->myBadMeshBtn->hide();
1229 aCompDlg->myBadMeshToGroupBtn->hide();
1231 tbl->setCurrentCell(0,0);
1232 currentCellChanged(); // to update buttons
1235 // show dialog and wait, becase Compute can be invoked from Preview operation
1236 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1240 //================================================================================
1242 * \brief Stops operation
1244 //================================================================================
1246 void SMESHGUI_BaseComputeOp::stopOperation()
1248 SMESHGUI_Operation::stopOperation();
1249 if ( myTShapeDisplayer )
1250 myTShapeDisplayer->SetVisibility( false );
1251 if ( myBadMeshDisplayer ) {
1252 myBadMeshDisplayer->SetVisibility( false );
1253 // delete it in order not to have problems at its destruction when the viewer
1254 // where it worked is dead due to e.g. study closing
1255 delete myBadMeshDisplayer;
1256 myBadMeshDisplayer = 0;
1258 myIObject.Nullify();
1261 //================================================================================
1263 * \brief publish selected sub-shape
1265 //================================================================================
1267 void SMESHGUI_BaseComputeOp::onPublishShape()
1269 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1270 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1271 GEOM::GEOM_Object_var meshShape = myMesh->GetShapeToMesh();
1273 QStringList entryList;
1275 SMESH::getSelectedRows( table(), rows );
1277 foreach ( row, rows )
1279 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1280 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1281 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1283 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1285 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1286 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, myMainShape,
1287 name.toLatin1().data(),
1288 GEOM::GEOM_Object::_nil());
1289 // look for myMainShape in the table
1290 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1291 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1292 if ( so->_is_nil() ) {
1293 CORBA::String_var name = so->GetName();
1294 CORBA::String_var entry = so->GetID();
1295 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1296 table()->item( r, COL_SHAPE )->setText( shapeText );
1297 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1302 if ( curSub == 1 ) continue;
1304 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1305 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape,
1306 name.toLatin1().data(), myMainShape);
1307 if ( !so->_is_nil() ) {
1308 CORBA::String_var name = so->GetName();
1309 CORBA::String_var entry = so->GetID();
1310 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1311 table()->item( row, COL_SHAPE )->setText( shapeText );
1312 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1313 entryList.push_back( entry.in() );
1317 getSMESHGUI()->getApp()->updateObjectBrowser();
1318 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1320 currentCellChanged(); // to update buttons
1323 //================================================================================
1325 * \brief show mesh elements preventing computation of a submesh of current row
1327 //================================================================================
1329 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1331 myTShapeDisplayer->SetVisibility( false );
1333 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1334 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1336 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1337 SMESHGUI* gui = getSMESHGUI();
1338 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1339 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1340 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1341 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1342 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1343 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1344 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1345 vtkProperty* prop = vtkProperty::New();
1346 prop->SetLineWidth( aLineWidth * 3 );
1347 prop->SetPointSize( aPointSize * 3 );
1348 prop->SetColor( 250, 0, 250 );
1349 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1350 myBadMeshDisplayer->SetData( aMeshData._retn() );
1356 //================================================================================
1358 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1360 //================================================================================
1362 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1365 SMESH::getSelectedRows( table(), rows );
1367 foreach ( row, rows )
1369 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1371 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1372 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1373 if ( grName.isEmpty() ) grName = "bad mesh";
1374 else grName = "bad mesh of " + grName;
1375 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1376 SMESH::ListOfGroups_var groups
1377 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1378 update( UF_ObjBrowser | UF_Model );
1379 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1381 QStringList anEntryList;
1382 for ( size_t i = 0; i < groups->length(); ++i )
1383 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1384 anEntryList.append( so->GetID().c_str() );
1386 if ( !anEntryList.isEmpty())
1387 anApp->browseObjects( anEntryList, true, false );
1393 //================================================================================
1395 * \brief SLOT called when a selected cell in table() changed
1397 //================================================================================
1399 void SMESHGUI_BaseComputeOp::currentCellChanged()
1401 myTShapeDisplayer->SetVisibility( false );
1402 if ( myBadMeshDisplayer )
1403 myBadMeshDisplayer->SetVisibility( false );
1405 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1407 int nbSelected = SMESH::getSelectedRows( table(), rows );
1409 foreach ( row, rows )
1411 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1412 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1413 if ( hasData && !isPublished )
1414 publishEnable = true;
1416 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1417 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1419 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1426 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1429 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1430 myCompDlg->myShowBtn ->setEnabled( showEnable );
1431 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1432 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1435 //================================================================================
1437 * \brief update preview
1439 //================================================================================
1441 void SMESHGUI_BaseComputeOp::onPreviewShape()
1443 if ( myTShapeDisplayer )
1445 SUIT_OverrideCursor aWaitCursor;
1447 SMESH::getSelectedRows( table(), rows );
1449 bool showOnly = true;
1451 foreach ( row, rows )
1453 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1455 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1459 currentCellChanged(); // to update buttons
1463 //================================================================================
1467 //================================================================================
1469 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1473 delete myTShapeDisplayer;
1474 if ( myBadMeshDisplayer )
1475 delete myBadMeshDisplayer;
1478 //================================================================================
1480 * \brief Gets dialog of compute operation
1481 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1483 //================================================================================
1485 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1489 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1490 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1491 // connect signals and slots
1492 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1493 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1494 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1495 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1497 QTableWidget* aTable = me->table();
1498 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1499 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1504 //================================================================================
1506 * \brief returns from compute mesh result dialog
1508 //================================================================================
1510 bool SMESHGUI_BaseComputeOp::onApply()
1515 //================================================================================
1517 * \brief Return a table
1519 //================================================================================
1521 QTableWidget* SMESHGUI_BaseComputeOp::table()
1523 return myCompDlg->myTable;
1527 //================================================================================
1529 * \brief Constructor
1531 //================================================================================
1533 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1534 : SMESHGUI_BaseComputeOp()
1536 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1540 //================================================================================
1542 * \brief Desctructor
1544 //================================================================================
1546 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1550 //================================================================================
1552 * \brief perform it's intention action: compute mesh
1554 //================================================================================
1556 void SMESHGUI_ComputeOp::startOperation()
1558 SMESHGUI_BaseComputeOp::startOperation();
1559 if (myMesh->_is_nil())
1564 //================================================================================
1566 * \brief check the same operations on the same mesh
1568 //================================================================================
1570 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1572 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1574 if ( !myMesh->_is_nil() && baseOp ) {
1575 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1576 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1581 //================================================================================
1583 * \brief Gets dialog of this operation
1584 * \retval LightApp_Dialog* - pointer to dialog of this operation
1586 //================================================================================
1588 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1590 return computeDlg();
1593 //================================================================================
1595 * \brief Constructor
1597 //================================================================================
1599 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1600 : SMESHGUI_BaseComputeOp(),
1603 myPreviewDisplayer( 0 ),
1608 //================================================================================
1612 //================================================================================
1614 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1621 if ( myPreviewDisplayer )
1622 delete myPreviewDisplayer;
1623 myPreviewDisplayer = 0;
1626 //================================================================================
1628 * \brief Gets current dialog of this operation
1629 * \retval LightApp_Dialog* - pointer to dialog of this operation
1631 //================================================================================
1633 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1638 //================================================================================
1640 * \brief perform it's intention action: prepare data
1642 //================================================================================
1644 void SMESHGUI_PrecomputeOp::startOperation()
1646 myHelpFileName = "constructing_meshes_page.html#preview_anchor"; // other anchor onCompute()
1650 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1653 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1654 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1655 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1657 myActiveDlg = myDlg;
1659 // connect signal to compute dialog. which will be shown after Compute mesh operation
1660 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1663 // disconnect signals
1664 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1665 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1666 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1667 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1668 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1671 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1672 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1673 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1674 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1675 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1676 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1677 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1678 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1679 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1680 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1683 SMESHGUI_BaseComputeOp::startOperation();
1684 if (myMesh->_is_nil())
1687 if (myDlg->getPreviewMode() == -1)
1689 // nothing to preview
1690 SUIT_MessageBox::warning(desktop(),
1691 tr("SMESH_WRN_WARNING"),
1692 tr("SMESH_WRN_NOTHING_PREVIEW"));
1697 // disconnect slot from preview dialog to have Apply from results of compute operation only
1698 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1699 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1704 //================================================================================
1706 * \brief Stops operation
1708 //================================================================================
1710 void SMESHGUI_PrecomputeOp::stopOperation()
1712 if ( myPreviewDisplayer )
1714 myPreviewDisplayer->SetVisibility( false );
1715 delete myPreviewDisplayer;
1716 myPreviewDisplayer = 0;
1718 myMapShapeId.clear();
1719 SMESHGUI_BaseComputeOp::stopOperation();
1722 //================================================================================
1724 * \brief reinitialize dialog after operaiton become active again
1726 //================================================================================
1728 void SMESHGUI_PrecomputeOp::resumeOperation()
1730 if ( myActiveDlg == myDlg )
1732 SMESHGUI_BaseComputeOp::resumeOperation();
1735 //================================================================================
1737 * \brief perform it's intention action: reinitialise dialog
1739 //================================================================================
1741 void SMESHGUI_PrecomputeOp::initDialog()
1745 QMap<int, int> modeMap;
1746 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1747 getAssignedAlgos( pMesh, modeMap );
1748 if ( modeMap.contains( SMESH::DIM_3D ) )
1750 if ( modeMap.contains( SMESH::DIM_2D ) )
1751 modes.append( SMESH::DIM_2D );
1752 if ( modeMap.contains( SMESH::DIM_1D ) )
1753 modes.append( SMESH::DIM_1D );
1755 else if ( modeMap.contains( SMESH::DIM_2D ) )
1757 if ( modeMap.contains( SMESH::DIM_1D ) )
1758 modes.append( SMESH::DIM_1D );
1761 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1762 myOrderMgr->SetMesh( myMesh );
1763 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1764 myDlg->getMeshOrderBox()->setVisible(isOrder);
1770 myDlg->setPreviewModes( modes );
1773 //================================================================================
1775 * \brief detect assigned mesh algorithms
1777 //================================================================================
1779 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1780 QMap<int,int>& theModeMap)
1782 if ( !theMesh ) return;
1784 _PTR(SObject) aHypFolder;
1785 _PTR(GenericAttribute) anAttr;
1786 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1787 if ( theMesh->FindSubObject( aPart, aHypFolder ))
1789 _PTR(ChildIterator) anIter =
1790 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1791 for ( ; anIter->More(); anIter->Next() )
1793 _PTR(SObject) anObj = anIter->Value();
1794 _PTR(SObject) aRefObj;
1795 if ( anObj->ReferencedObject( aRefObj ) )
1800 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1802 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1803 if ( CORBA::is_nil( aVar ) )
1806 SMESH::SMESH_Algo_var algo;
1807 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1810 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1811 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1812 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1815 if ( !algo->_is_nil() )
1817 theModeMap[ dim ] = 0;
1818 if ( theModeMap.size() == 3 )
1828 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1830 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1833 _PTR(ChildIterator) anIter =
1834 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1835 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1837 _PTR(SObject) anObj = anIter->Value();
1838 _PTR(SObject) aRefObj;
1839 if ( anObj->ReferencedObject( aRefObj ) )
1844 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1846 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1847 if ( CORBA::is_nil( aVar ) )
1850 SMESH::SMESH_Algo_var algo;
1851 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1854 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1855 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1856 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1859 if ( !algo->_is_nil() )
1861 theModeMap[ dim ] = 0;
1862 if ( theModeMap.size() == 3 )
1872 //================================================================================
1874 * \brief perform it's intention action: compute mesh
1876 //================================================================================
1878 void SMESHGUI_PrecomputeOp::onCompute()
1881 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1882 myOrderMgr->SetMeshOrder();
1883 myMapShapeId.clear();
1884 myActiveDlg = computeDlg();
1885 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1889 //================================================================================
1891 * \brief perform it's intention action: compute mesh
1893 //================================================================================
1895 void SMESHGUI_PrecomputeOp::onCancel()
1897 QObject* curDlg = sender();
1898 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1900 // return from error messages
1905 bool isRestoreOrder = false;
1906 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1908 // ask to remove already computed mesh elements
1909 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1910 tr( "CLEAR_SUBMESH_QUESTION" ),
1911 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1913 // remove all submeshes for collected shapes
1914 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1915 for ( ; it != myMapShapeId.constEnd(); ++it )
1916 myMesh->ClearSubMesh( it.key() );
1917 isRestoreOrder = true;
1921 // return previous mesh order
1922 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1923 if (!isRestoreOrder)
1925 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1926 tr( "SMESH_REJECT_MESH_ORDER" ),
1927 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1929 myOrderMgr->SetMeshOrder(myPrevOrder);
1935 myMapShapeId.clear();
1936 SMESHGUI_BaseComputeOp::onCancel();
1939 //================================================================================
1941 * \brief perform it's intention action: preview mesh
1943 //================================================================================
1945 void SMESHGUI_PrecomputeOp::onPreview()
1947 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1950 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1954 // set modified submesh priority if any
1955 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1956 myOrderMgr->SetMeshOrder();
1958 // Compute preview of mesh,
1959 // i.e. compute mesh till indicated dimension
1960 int dim = myDlg->getPreviewMode();
1962 SMESH::MemoryReserve aMemoryReserve;
1964 SMESH::compute_error_array_var aCompErrors;
1967 bool computeFailed = true, memoryLack = false;
1969 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1970 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1972 SMESHGUI* gui = getSMESHGUI();
1973 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1974 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1975 if ( errors->length() > 0 ) {
1976 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1979 SUIT_OverrideCursor aWaitCursor;
1981 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1982 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1983 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1985 SMESH::long_array_var aShapesId = new SMESH::long_array();
1987 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1991 SMESH::MeshPreviewStruct_var previewData =
1992 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1994 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1995 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1997 computeFailed = false;
1998 myPreviewDisplayer->SetData( previewRes );
1999 // append shape indeces with computed mesh entities
2000 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
2001 myMapShapeId[ aShapesId[ i ] ] = 0;
2004 myPreviewDisplayer->SetVisibility(false);
2006 catch(const SALOME::SALOME_Exception & S_ex){
2008 myPreviewDisplayer->SetVisibility(false);
2012 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2015 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2016 // check if there are memory problems
2017 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
2018 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
2020 catch(const SALOME::SALOME_Exception & S_ex){
2025 aMemoryReserve.release();
2027 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2028 bool noHypoError = ( aHypErrors.isEmpty() );
2030 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2031 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2033 bool isShowError = true;
2034 switch( aNotifyMode ) {
2035 case 0: // show the mesh computation result dialog NEVER
2036 isShowError = false;
2038 case 1: // show the mesh computation result dialog if there are some errors
2039 default: // show the result dialog after each mesh computation
2040 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2041 isShowError = false;
2045 aWaitCursor.suspend();
2050 aCompDlg->setWindowTitle
2051 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2052 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2057 //================================================================================
2059 * \brief Constructor
2061 //================================================================================
2063 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2064 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2067 setWindowTitle( tr( "CAPTION" ) );
2069 setButtonText( OK, tr( "COMPUTE" ) );
2070 QFrame* main = mainFrame();
2071 main->setMinimumWidth( 300 );
2073 QVBoxLayout* layout = new QVBoxLayout( main );
2075 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2076 layout->addWidget(myOrderBox);
2078 QFrame* frame = new QFrame( main );
2079 layout->setMargin(0); layout->setSpacing(0);
2080 layout->addWidget( frame );
2082 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2083 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2085 myPreviewMode = new QtxComboBox( frame );
2086 frameLay->addWidget( myPreviewMode );
2088 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2089 frameLay->addWidget( myPreviewBtn );
2091 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2094 //================================================================================
2098 //================================================================================
2100 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2104 //================================================================================
2106 * \brief Sets available preview modes
2108 //================================================================================
2110 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2112 myPreviewMode->clear();
2113 QList<int>::const_iterator it = theModes.constBegin();
2114 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2116 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2117 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2118 myPreviewMode->setId( i, *it );
2120 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2123 //================================================================================
2125 * \brief Returns current preview mesh mode
2127 //================================================================================
2129 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2131 return myPreviewMode->currentId().toInt();
2134 //================================================================================
2136 * \brief Returns current preview mesh mode
2138 //================================================================================
2140 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2146 //================================================================================
2148 * \brief Constructor
2150 //================================================================================
2152 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2153 : SMESHGUI_BaseComputeOp()
2155 myHelpFileName = "constructing_meshes_page.html#evaluate_anchor";
2159 //================================================================================
2161 * \brief Desctructor
2163 //================================================================================
2165 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2169 //================================================================================
2171 * \brief perform it's intention action: compute mesh
2173 //================================================================================
2175 void SMESHGUI_EvaluateOp::startOperation()
2177 SMESHGUI_BaseComputeOp::evaluateDlg();
2178 SMESHGUI_BaseComputeOp::startOperation();
2179 if (myMesh->_is_nil())
2184 //================================================================================
2186 * \brief Gets dialog of this operation
2187 * \retval LightApp_Dialog* - pointer to dialog of this operation
2189 //================================================================================
2191 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2193 return evaluateDlg();
2196 //================================================================================
2198 * \brief evaluateMesh()
2200 //================================================================================
2202 void SMESHGUI_BaseComputeOp::evaluateMesh()
2206 SMESH::MemoryReserve aMemoryReserve;
2208 SMESH::compute_error_array_var aCompErrors;
2211 bool evaluateFailed = true, memoryLack = false;
2212 SMESH::long_array_var aRes;
2214 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2215 if ( !aMeshSObj ) // IPAL21340
2218 bool hasShape = myMesh->HasShapeToMesh();
2219 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2222 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2223 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2224 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2225 if ( errors->length() > 0 ) {
2226 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2228 SUIT_OverrideCursor aWaitCursor;
2230 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2233 aRes = gen->Evaluate(myMesh, myMainShape);
2235 catch(const SALOME::SALOME_Exception & S_ex){
2240 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2243 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2245 catch(const SALOME::SALOME_Exception & S_ex){
2251 aMemoryReserve.release();
2253 evaluateFailed = ( aCompErrors->length() > 0 );
2254 myCompDlg->setWindowTitle
2255 ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2259 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2260 bool noHypoError = ( aHypErrors.isEmpty() );
2262 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2263 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2265 bool isShowResultDlg = true;
2267 //switch( aNotifyMode ) {
2268 //case 0: // show the mesh computation result dialog NEVER
2269 //isShowResultDlg = false;
2272 //case 1: // show the mesh computation result dialog if there are some errors
2273 //if ( memoryLack || !noHypoError )
2274 // isShowResultDlg = true;
2277 // isShowResultDlg = false;
2281 //default: // show the result dialog after each mesh computation
2282 //isShowResultDlg = true;
2286 if ( isShowResultDlg )
2287 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2288 noHypoError, aHypErrors);
2292 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2293 const bool theMemoryLack,
2294 const bool theNoCompError,
2295 SMESH::compute_error_array_var& theCompErrors,
2296 const bool theNoHypoError,
2297 const QString& theHypErrors)
2299 bool hasShape = myMesh->HasShapeToMesh();
2300 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2301 aCompDlg->myMemoryLackGroup->hide();
2303 if ( theMemoryLack )
2305 aCompDlg->myMemoryLackGroup->show();
2306 aCompDlg->myFullInfo->hide();
2307 aCompDlg->myBriefInfo->hide();
2308 aCompDlg->myHypErrorGroup->hide();
2309 aCompDlg->myCompErrorGroup->hide();
2311 else if ( theNoCompError && theNoHypoError )
2313 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2314 aCompDlg->myFullInfo->show();
2315 aCompDlg->myBriefInfo->hide();
2316 aCompDlg->myHypErrorGroup->hide();
2317 aCompDlg->myCompErrorGroup->hide();
2321 QTableWidget* tbl = aCompDlg->myTable;
2322 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2323 aCompDlg->myBriefInfo->show();
2324 aCompDlg->myFullInfo->hide();
2326 if ( theNoHypoError ) {
2327 aCompDlg->myHypErrorGroup->hide();
2330 aCompDlg->myHypErrorGroup->show();
2331 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2334 if ( theNoCompError ) {
2335 aCompDlg->myCompErrorGroup->hide();
2338 aCompDlg->myCompErrorGroup->show();
2340 aCompDlg->myPublishBtn->hide();
2341 aCompDlg->myShowBtn->hide();
2343 // fill table of errors
2344 tbl->setRowCount( theCompErrors->length() );
2345 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2346 else tbl->showColumn( COL_SHAPE );
2347 tbl->setColumnWidth( COL_ERROR, 200 );
2349 bool hasBadMesh = false;
2350 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2352 SMESH::ComputeError & err = theCompErrors[ row ];
2354 QString text = err.algoName.in();
2355 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2356 else tbl->item( row, COL_ALGO )->setText( text );
2358 text = SMESH::errorText( err.code, err.comment.in() );
2359 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2360 else tbl->item( row, COL_ERROR )->setText( text );
2362 text = QString("%1").arg( err.subShapeID );
2363 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2364 else tbl->item( row, COL_SHAPEID )->setText( text );
2366 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2367 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2368 else tbl->item( row, COL_SHAPE )->setText( text );
2370 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2371 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2372 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2374 text = err.hasBadMesh ? "hasBadMesh" : "";
2375 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2376 else tbl->item( row, COL_BAD_MESH )->setText( text );
2377 if ( err.hasBadMesh ) hasBadMesh = true;
2379 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2380 tbl->resizeRowToContents( row );
2382 tbl->resizeColumnToContents( COL_ALGO );
2383 tbl->resizeColumnToContents( COL_SHAPE );
2384 tbl->setWordWrap( true );
2388 aCompDlg->myBadMeshBtn->show();
2389 aCompDlg->myBadMeshToGroupBtn->show();
2393 aCompDlg->myBadMeshBtn->hide();
2394 aCompDlg->myBadMeshToGroupBtn->hide();
2396 tbl->setCurrentCell(0,0);
2397 currentCellChanged(); // to update buttons
2400 // show dialog and wait, becase Compute can be invoked from Preview operation
2401 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2406 //================================================================================
2408 * \brief Gets dialog of evaluate operation
2409 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2411 //================================================================================
2413 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2417 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2418 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2419 // connect signals and slots
2420 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2421 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2422 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2423 QTableWidget* aTable = me->table();
2424 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2425 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));