1 // Copyright (C) 2007-2019 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 = SMESH::getStudy()->NewChildIterator(so);
385 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
386 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
387 if ( !geom->_is_nil() ) {
388 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
389 if ( list->length() == 1 && list[0] == subShapeID )
391 GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
392 if ( aMainShape->IsSame( mainGO ))
400 // -----------------------------------------------------------------------
402 * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
404 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
406 GEOM::GEOM_Object_var aSubShape;
407 if ( subShapeID == 1 ) {
408 aSubShape = aMainShape;
409 aSubShape->Register();
411 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
412 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
413 aSubShape->Register();
416 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
417 // future call of UnRegister() will delete a servant of this new object
419 return aSubShape._retn();
421 // -----------------------------------------------------------------------
423 * \brief Return shape type name
425 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
426 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
429 if ( !aShape->_is_nil() ) {
430 switch ( aShape->GetShapeType() ) {
437 CASE2NAME( COMPSOLID );
438 CASE2NAME( COMPOUND );
444 // -----------------------------------------------------------------------
446 * \brief Return text describing a sub-shape
448 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
451 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
452 text = aSO->GetName().c_str();
453 text += QString(" (%1)").arg( aSO->GetID().c_str() );
456 text = QString("#%1").arg( subShapeID );
457 GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
458 QString typeName = shapeTypeName( shape );
459 if ( typeName.length() )
460 text += QString(" (%1)").arg(typeName);
464 // -----------------------------------------------------------------------
466 * \brief Return a list of selected rows
468 int getSelectedRows(QTableWidget* table, QList<int>& rows)
471 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
472 QTableWidgetSelectionRange range;
473 foreach( range, selRanges )
475 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
476 if ( !rows.count( row ))
479 if ( rows.isEmpty() && table->currentRow() > -1 )
480 if ( !rows.count( table->currentRow() ))
481 rows.append( table->currentRow() );
489 // =========================================================================================
491 * \brief Dialog to compute a mesh and show computation errors
493 //=======================================================================
495 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
496 : SMESHGUI_Dialog( parent, false, true, Close | Help )
498 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
499 aDlgLay->setMargin( 0 );
500 aDlgLay->setSpacing( SPACING );
502 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
504 aDlgLay->addWidget(aMainFrame);
506 aDlgLay->setStretchFactor(aMainFrame, 1);
509 // =========================================================================================
513 //=======================================================================
515 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
519 //=======================================================================
520 // function : createMainFrame()
521 // purpose : Create frame containing dialog's fields
522 //=======================================================================
524 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
526 QFrame* aFrame = new QFrame(theParent);
528 SUIT_ResourceMgr* rm = resourceMgr();
529 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
535 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
538 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
540 QButtonGroup* aBtnGrp = new QButtonGroup(this);
541 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
542 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
544 QRadioButton* aRBut = new QRadioButton(aPixGrp);
545 aRBut->setIcon(iconCompute);
546 aRBut->setChecked(true);
547 aPixGrpLayout->addWidget(aRBut);
548 aBtnGrp->addButton(aRBut, 0);
552 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
553 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
554 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
555 myMeshName = new QLabel(nameBox);
556 nameBoxLayout->addWidget(myMeshName);
560 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
561 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
563 // Computation errors
565 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
566 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
567 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
568 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
569 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
570 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
571 myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
573 //myTable->setReadOnly( true ); // VSR: check
574 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
575 myTable->hideColumn( COL_PUBLISHED );
576 myTable->hideColumn( COL_SHAPEID );
577 myTable->hideColumn( COL_BAD_MESH );
578 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
579 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
581 myTable->horizontalHeader()->setSectionResizeMode( COL_ERROR, QHeaderView::Interactive );
583 myTable->setWordWrap( true );
584 myTable->horizontalHeader()->setStretchLastSection( true );
585 myTable->setMinimumWidth( 500 );
588 headers << tr( "COL_ALGO_HEADER" );
589 headers << tr( "COL_SHAPE_HEADER" );
590 headers << tr( "COL_ERROR_HEADER" );
591 headers << tr( "COL_SHAPEID_HEADER" );
592 headers << tr( "COL_PUBLISHED_HEADER" );
594 myTable->setHorizontalHeaderLabels( headers );
597 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
598 grpLayout->setSpacing(SPACING);
599 grpLayout->setMargin(MARGIN);
600 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
601 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
602 grpLayout->addWidget( myShowBtn, 2, 0 );
603 grpLayout->addWidget( myPublishBtn, 2, 1 );
604 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
605 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
606 grpLayout->setColumnStretch( 3, 1 );
608 // Hypothesis definition errors
610 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
611 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
612 myHypErrorGroupLayout->setMargin(MARGIN);
613 myHypErrorGroupLayout->setSpacing(SPACING);
614 myHypErrorLabel = new QLabel(myHypErrorGroup);
615 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
619 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
620 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
621 myMemoryLackGroupLayout->setMargin(MARGIN);
622 myMemoryLackGroupLayout->setSpacing(SPACING);
623 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
624 QFont bold = memLackLabel->font(); bold.setBold(true);
625 memLackLabel->setFont( bold );
626 memLackLabel->setMinimumWidth(300);
627 myMemoryLackGroupLayout->addWidget(memLackLabel);
629 // add all widgets to aFrame
630 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
631 aLay->setMargin( MARGIN );
632 aLay->setSpacing( SPACING );
633 aLay->addWidget( aPixGrp );
634 aLay->addWidget( nameBox );
635 aLay->addWidget( myBriefInfo );
636 aLay->addWidget( myFullInfo );
637 aLay->addWidget( myHypErrorGroup );
638 aLay->addWidget( myCompErrorGroup );
639 aLay->addWidget( myMemoryLackGroup );
640 aLay->setStretchFactor( myCompErrorGroup, 1 );
642 ((QPushButton*) button( OK ))->setDefault( true );
647 //================================================================================
651 //================================================================================
653 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
654 : SMESHGUI_Operation(), myCompDlg( 0 )
656 myTShapeDisplayer = new SMESH::TShapeDisplayer();
657 myBadMeshDisplayer = 0;
659 //myHelpFileName = "/files/about_meshes.htm"; // V3
660 myHelpFileName = "about_meshes.html"; // V4
663 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
665 LightApp_SelectionMgr* Sel = selectionMgr();
666 SALOME_ListIO selected; Sel->selectedObjects( selected );
667 Handle(SALOME_InteractiveObject) anIO = selected.First();
668 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
669 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
672 //================================================================================
674 * \brief Start operation
675 * \purpose Init dialog fields, connect signals and slots, show dialog
677 //================================================================================
679 void SMESHGUI_BaseComputeOp::startOperation()
681 // create compute dialog if not created before
684 myMesh = SMESH::SMESH_Mesh::_nil();
685 myMainShape = GEOM::GEOM_Object::_nil();
686 myCurShape = GEOM::GEOM_Object::_nil();
689 LightApp_SelectionMgr *Sel = selectionMgr();
690 SALOME_ListIO selected; Sel->selectedObjects( selected );
692 int nbSel = selected.Extent();
694 SUIT_MessageBox::warning(desktop(),
695 tr("SMESH_WRN_WARNING"),
696 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
701 myIObject = selected.First();
702 CORBA::Object_var anObj = SMESH::IObjectToObject( myIObject );
704 myMesh = SMESH::SMESH_Mesh::_narrow(anObj);
705 if ( myMesh->_is_nil() )
707 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
708 if ( !aSubMesh->_is_nil() )
710 myMesh = aSubMesh->GetFather();
711 myCurShape = aSubMesh->GetSubShape();
716 myCurShape = myMesh->GetShapeToMesh();
719 if (myMesh->_is_nil()) {
720 SUIT_MessageBox::warning(desktop(),
721 tr("SMESH_WRN_WARNING"),
722 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
727 myMainShape = myMesh->GetShapeToMesh();
729 SMESHGUI_Operation::startOperation();
732 //================================================================================
733 //================================================================================
735 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
736 SMESH::SMESH_Mesh_var mesh,
737 GEOM::GEOM_Object_var mainShape)
742 myMainShape = mainShape;
745 void SMESHGUI_ComputeDlg_QThread::run()
747 myResult = myGen->Compute(myMesh, myMainShape);
750 bool SMESHGUI_ComputeDlg_QThread::result()
755 void SMESHGUI_ComputeDlg_QThread::cancel()
757 myGen->CancelCompute(myMesh, myMainShape);
760 //================================================================================
761 //================================================================================
763 SMESHGUI_ComputeDlg_QThreadQDialog::
764 SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
765 SMESH::SMESH_Gen_var gen,
766 SMESH::SMESH_Mesh_var mesh,
767 GEOM::GEOM_Object_var mainShape)
769 Qt::WindowSystemMenuHint |
770 Qt::WindowCloseButtonHint |
772 Qt::WindowMaximizeButtonHint),
773 qthread(gen, mesh, mainShape)
776 setWindowTitle(tr("TITLE"));
777 setMinimumWidth( 200 );
779 cancelButton = new QPushButton(tr("CANCEL"));
780 cancelButton->setDefault(true);
781 cancelButton->setCheckable(true);
783 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
784 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
785 nbNodesLabel = new QLabel("0", this );
786 nbElemsLabel = new QLabel("0", this );
787 #if !defined WIN32 && !defined __APPLE__
788 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
789 freeRAMLabel = new QLabel("", this );
791 progressBar = new QProgressBar(this);
792 progressBar->setMinimum( 0 );
793 progressBar->setMaximum( 1000 );
795 QGridLayout* layout = new QGridLayout(this);
796 layout->setMargin( MARGIN );
797 layout->setSpacing( SPACING );
799 layout->addWidget(nbNodesName, row, 0);
800 layout->addWidget(nbNodesLabel, row++, 1);
801 layout->addWidget(nbElemsName, row, 0);
802 layout->addWidget(nbElemsLabel, row++, 1);
803 #if !defined WIN32 && !defined __APPLE__
804 layout->addWidget(freeRAMName, row, 0);
805 layout->addWidget(freeRAMLabel, row++, 1);
807 layout->addWidget(progressBar, row++, 0, 1, 2);
808 layout->addWidget(cancelButton, row++, 0, 1, 2);
812 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
814 startTimer(300); // millisecs
818 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
820 return qthread.result();
823 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
826 cancelButton->setText( tr("CANCELING"));
827 cancelButton->setEnabled(false);
830 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
832 if ( !cancelButton->isChecked() ) // not yet cancelled
833 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
835 if(qthread.isFinished())
841 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
842 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
843 #if !defined WIN32 && !defined __APPLE__
845 const int err = sysinfo( &si );
847 freeRAMLabel->setText("");
849 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
850 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
856 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
858 if(qthread.isRunning())
866 //================================================================================
868 * \brief computeMesh()
870 //================================================================================
872 void SMESHGUI_BaseComputeOp::computeMesh()
876 SMESH::MemoryReserve aMemoryReserve;
878 SMESH::compute_error_array_var aCompErrors;
881 bool computeFailed = true, memoryLack = false;
883 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
884 if ( !aMeshSObj ) // IPAL 21340
886 bool hasShape = myMesh->HasShapeToMesh();
887 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
890 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
891 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
892 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
893 if ( errors->length() > 0 ) {
894 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
896 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
897 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
898 tr( "FULL_RECOMPUTE_QUESTION" ),
899 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
901 SUIT_OverrideCursor aWaitCursor;
904 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myCurShape);
905 qthreaddialog.exec();
906 computeFailed = !qthreaddialog.result();
908 catch(const SALOME::SALOME_Exception & S_ex) {
913 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
914 // check if there are memory problems
915 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
916 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
918 catch(const SALOME::SALOME_Exception & S_ex) {
922 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
926 // NPAL16631: if ( !memoryLack )
928 update( UF_ObjBrowser | UF_Model );
931 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
932 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
934 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
935 int entities = SMESH_Actor::eAllEntity;
940 // List of objects that will be updated automatically
941 typedef QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > TListOf_IDSrc_SObj;
942 TListOf_IDSrc_SObj aListToUpdate;
943 SMESH::SMESH_IDSource_var aMeshObj =
944 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
945 // put Mesh into list
946 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aMeshObj, aMeshSObj ));
947 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
948 // put SubMeshes into list
949 for ( CORBA::ULong i = 0; i < aSubMeshes->length(); i++ )
951 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
952 if ( CORBA::is_nil( sm ) ) continue;
953 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
954 if ( !smSObj ) continue;
955 SMESH::SMESH_IDSource_var aSubMeshObj =
956 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
957 SMESH_Actor *anActor = SMESH::FindActorByObject( aSubMeshObj );
958 if ( anActor && anActor->GetVisibility() )
959 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aSubMeshObj, smSObj ));
961 // put Groups into list
962 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
963 for ( size_t i = 0; i < aGroups->length(); ++i )
965 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
966 if ( CORBA::is_nil( aGrp ) ) continue;
967 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
968 if ( !aStdGroup->_is_nil() ) continue; // don't update standalone groups
969 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
970 if ( !aGroupSO ) continue;
971 SMESH::SMESH_IDSource_var aGroupObj =
972 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
973 SMESH_Actor *anActor = SMESH::FindActorByObject( aGroupObj );
974 if ( anActor && anActor->GetVisibility() )
975 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aGroupObj, aGroupSO ));
978 // update mesh, sub-mesh and groups, if it's possible
979 TListOf_IDSrc_SObj::iterator anIter;
980 for ( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ )
982 SMESH::SMESH_Mesh_var aMesh =
983 SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
985 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded,
986 &hidden, &nbElements ) )
990 bool toDisplay = false;
991 std::string entry = (*anIter).second->GetID();
992 if ( !aMesh->_is_nil() ) // display only a mesh
995 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
996 if ( !anActor ) anActor = SMESH::CreateActor( entry.c_str(), /*clearLog =*/true );
997 if ( anActor ) // actor is not created for an empty mesh
999 anActor->SetEntityMode( entities );
1000 //SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor ); -- 23615
1004 SMESH::UpdateView( SMESH::eDisplay, entry.c_str() );
1006 if ( SVTK_ViewWindow* vtkWnd = SMESH::GetVtkViewWindow(SMESH::GetActiveWindow() ))
1007 if ( vtkWnd->getRenderer() )
1008 vtkWnd->getRenderer()->ResetCameraClippingRange();
1010 if ( limitExceeded && !aMesh->_is_nil() )
1012 QStringList hiddenMsg;
1013 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1014 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
1015 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
1016 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
1017 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
1018 SUIT_MessageBox::warning( desktop(),
1019 tr( "SMESH_WRN_WARNING" ),
1020 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1023 arg( hiddenMsg.join(", ")));
1028 MESSAGE ( "Exception thrown during mesh visualization" );
1030 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1031 SMESH::OnVisuException();
1038 else if ( limitExceeded && !aMesh->_is_nil() )
1040 SUIT_MessageBox::warning( desktop(),
1041 tr( "SMESH_WRN_WARNING" ),
1042 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1043 arg( nbElements ).arg( limitSize ) );
1047 if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1049 SALOME_ListIO selected;
1050 selected.Append( myIObject );
1051 Sel->setSelectedObjects( selected );
1057 aMemoryReserve.release();
1059 myCompDlg->setWindowTitle
1060 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1064 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1065 bool noHypoError = ( aHypErrors.isEmpty() );
1067 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1068 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1070 bool isShowResultDlg = true;
1071 switch( aNotifyMode ) {
1072 case 0: // show the mesh computation result dialog NEVER
1073 isShowResultDlg = false;
1076 case 1: // show the mesh computation result dialog if there are some errors
1077 if ( memoryLack || !noCompError || !noHypoError )
1078 isShowResultDlg = true;
1081 isShowResultDlg = false;
1085 default: // show the result dialog after each mesh computation
1086 isShowResultDlg = true;
1090 if ( isShowResultDlg )
1091 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1094 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1095 const bool theNoCompError,
1096 SMESH::compute_error_array_var& theCompErrors,
1097 const bool theNoHypoError,
1098 const QString& theHypErrors )
1100 bool hasShape = myMesh->HasShapeToMesh();
1101 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1102 aCompDlg->myMemoryLackGroup->hide();
1104 if ( theMemoryLack )
1106 aCompDlg->myMemoryLackGroup->show();
1107 aCompDlg->myFullInfo->hide();
1108 aCompDlg->myBriefInfo->hide();
1109 aCompDlg->myHypErrorGroup->hide();
1110 aCompDlg->myCompErrorGroup->hide();
1112 else if ( theNoCompError && theNoHypoError )
1114 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1115 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1116 aCompDlg->myFullInfo->show();
1117 aCompDlg->myBriefInfo->hide();
1118 aCompDlg->myHypErrorGroup->hide();
1119 aCompDlg->myCompErrorGroup->hide();
1123 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1124 for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1125 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1126 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1128 // full or brief mesh info
1129 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1130 if ( onlyWarnings ) {
1131 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1132 aCompDlg->myFullInfo->show();
1133 aCompDlg->myBriefInfo->hide();
1135 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1136 aCompDlg->myBriefInfo->show();
1137 aCompDlg->myFullInfo->hide();
1140 // pbs of hypo dfinitions
1141 if ( theNoHypoError ) {
1142 aCompDlg->myHypErrorGroup->hide();
1144 aCompDlg->myHypErrorGroup->show();
1145 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1149 if ( theNoCompError )
1151 aCompDlg->myCompErrorGroup->hide();
1155 aCompDlg->myCompErrorGroup->show();
1158 aCompDlg->myWarningLabel->show();
1160 aCompDlg->myWarningLabel->hide();
1163 aCompDlg->myPublishBtn->hide();
1164 aCompDlg->myShowBtn->hide();
1167 aCompDlg->myPublishBtn->show();
1168 aCompDlg->myShowBtn->show();
1171 // fill table of errors
1172 QTableWidget* tbl = aCompDlg->myTable;
1173 tbl->setRowCount( theCompErrors->length() );
1174 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1175 else tbl->showColumn( COL_SHAPE );
1176 tbl->setColumnWidth( COL_ERROR, 200 );
1178 bool hasBadMesh = false;
1179 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1181 SMESH::ComputeError & err = theCompErrors[ row ];
1183 QString text = err.algoName.in();
1184 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1185 else tbl->item( row, COL_ALGO )->setText( text );
1187 text = SMESH::errorText( err.code, err.comment.in() );
1188 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1189 else tbl->item( row, COL_ERROR )->setText( text );
1191 text = QString("%1").arg( err.subShapeID );
1192 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1193 else tbl->item( row, COL_SHAPEID )->setText( text );
1195 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1196 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1197 else tbl->item( row, COL_SHAPE )->setText( text );
1199 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1200 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1201 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1203 text = err.hasBadMesh ? "hasBadMesh" : "";
1204 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1205 else tbl->item( row, COL_BAD_MESH )->setText( text );
1206 if ( err.hasBadMesh ) hasBadMesh = true;
1208 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1209 tbl->resizeRowToContents( row );
1211 tbl->resizeColumnToContents( COL_ALGO );
1212 tbl->resizeColumnToContents( COL_SHAPE );
1213 tbl->setWordWrap( true );
1216 aCompDlg->myBadMeshBtn->show();
1217 aCompDlg->myBadMeshToGroupBtn->show();
1220 aCompDlg->myBadMeshBtn->hide();
1221 aCompDlg->myBadMeshToGroupBtn->hide();
1223 tbl->setCurrentCell(0,0);
1224 currentCellChanged(); // to update buttons
1227 // show dialog and wait, because Compute can be invoked from Preview operation
1228 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1232 //================================================================================
1234 * \brief Stops operation
1236 //================================================================================
1238 void SMESHGUI_BaseComputeOp::stopOperation()
1240 SMESHGUI_Operation::stopOperation();
1241 if ( myTShapeDisplayer )
1242 myTShapeDisplayer->SetVisibility( false );
1243 if ( myBadMeshDisplayer ) {
1244 myBadMeshDisplayer->SetVisibility( false );
1245 // delete it in order not to have problems at its destruction when the viewer
1246 // where it worked is dead due to e.g. study closing
1247 delete myBadMeshDisplayer;
1248 myBadMeshDisplayer = 0;
1250 myIObject.Nullify();
1253 //================================================================================
1255 * \brief publish selected sub-shape
1257 //================================================================================
1259 void SMESHGUI_BaseComputeOp::onPublishShape()
1261 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1262 GEOM::GEOM_Object_var meshShape = myMesh->GetShapeToMesh();
1264 QStringList entryList;
1266 SMESH::getSelectedRows( table(), rows );
1268 foreach ( row, rows )
1270 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1271 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1272 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1274 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1276 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1277 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( myMainShape,
1278 name.toUtf8().data(),
1279 GEOM::GEOM_Object::_nil());
1280 // look for myMainShape in the table
1281 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1282 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1283 if ( so->_is_nil() ) {
1284 CORBA::String_var name = so->GetName();
1285 CORBA::String_var entry = so->GetID();
1286 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1287 table()->item( r, COL_SHAPE )->setText( shapeText );
1288 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1293 if ( curSub == 1 ) continue;
1295 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1296 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( shape,
1297 name.toUtf8().data(), myMainShape);
1298 if ( !so->_is_nil() ) {
1299 CORBA::String_var name = so->GetName();
1300 CORBA::String_var entry = so->GetID();
1301 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1302 table()->item( row, COL_SHAPE )->setText( shapeText );
1303 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1304 entryList.push_back( entry.in() );
1308 getSMESHGUI()->getApp()->updateObjectBrowser();
1309 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1311 currentCellChanged(); // to update buttons
1314 //================================================================================
1316 * \brief show mesh elements preventing computation of a submesh of current row
1318 //================================================================================
1320 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1322 myTShapeDisplayer->SetVisibility( false );
1324 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1325 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1327 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1328 SMESHGUI* gui = getSMESHGUI();
1329 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1330 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1331 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1332 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1333 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1334 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1335 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1336 vtkProperty* prop = vtkProperty::New();
1337 prop->SetLineWidth( aLineWidth * 3 );
1338 prop->SetPointSize( aPointSize * 3 );
1339 prop->SetColor( 250, 0, 250 );
1340 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1341 myBadMeshDisplayer->SetData( aMeshData.in() );
1347 //================================================================================
1349 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1351 //================================================================================
1353 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1356 SMESH::getSelectedRows( table(), rows );
1358 foreach ( row, rows )
1360 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1362 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1363 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1364 if ( grName.isEmpty() ) grName = "bad mesh";
1365 else grName = "bad mesh of " + grName;
1366 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1367 SMESH::ListOfGroups_var groups
1368 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toUtf8().data()) );
1369 update( UF_ObjBrowser | UF_Model );
1370 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1372 QStringList anEntryList;
1373 for ( size_t i = 0; i < groups->length(); ++i )
1374 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1375 anEntryList.append( so->GetID().c_str() );
1377 if ( !anEntryList.isEmpty())
1378 anApp->browseObjects( anEntryList, true, false );
1384 //================================================================================
1386 * \brief SLOT called when a selected cell in table() changed
1388 //================================================================================
1390 void SMESHGUI_BaseComputeOp::currentCellChanged()
1392 myTShapeDisplayer->SetVisibility( false );
1393 if ( myBadMeshDisplayer )
1394 myBadMeshDisplayer->SetVisibility( false );
1396 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1398 int nbSelected = SMESH::getSelectedRows( table(), rows );
1400 foreach ( row, rows )
1402 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1403 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1404 if ( hasData && !isPublished )
1405 publishEnable = true;
1407 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1408 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1410 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1417 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1420 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1421 myCompDlg->myShowBtn ->setEnabled( showEnable );
1422 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1423 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1426 //================================================================================
1428 * \brief update preview
1430 //================================================================================
1432 void SMESHGUI_BaseComputeOp::onPreviewShape()
1434 if ( myTShapeDisplayer )
1436 SUIT_OverrideCursor aWaitCursor;
1438 SMESH::getSelectedRows( table(), rows );
1440 bool showOnly = true;
1442 foreach ( row, rows )
1444 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1446 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1450 currentCellChanged(); // to update buttons
1454 //================================================================================
1458 //================================================================================
1460 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1464 delete myTShapeDisplayer;
1465 if ( myBadMeshDisplayer )
1466 delete myBadMeshDisplayer;
1469 //================================================================================
1471 * \brief Gets dialog of compute operation
1472 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1474 //================================================================================
1476 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1480 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1481 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1482 // connect signals and slots
1483 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1484 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1485 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1486 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1488 QTableWidget* aTable = me->table();
1489 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1490 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1495 //================================================================================
1497 * \brief returns from compute mesh result dialog
1499 //================================================================================
1501 bool SMESHGUI_BaseComputeOp::onApply()
1506 //================================================================================
1508 * \brief Return a table
1510 //================================================================================
1512 QTableWidget* SMESHGUI_BaseComputeOp::table()
1514 return myCompDlg->myTable;
1518 //================================================================================
1520 * \brief Constructor
1522 //================================================================================
1524 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1525 : SMESHGUI_BaseComputeOp()
1527 myHelpFileName = "constructing_meshes.html#compute-anchor";
1531 //================================================================================
1535 //================================================================================
1537 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1541 //================================================================================
1543 * \brief perform it's intention action: compute mesh
1545 //================================================================================
1547 void SMESHGUI_ComputeOp::startOperation()
1549 SMESHGUI_BaseComputeOp::startOperation();
1550 if (myMesh->_is_nil())
1555 //================================================================================
1557 * \brief check the same operations on the same mesh
1559 //================================================================================
1561 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1563 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1565 if ( !myMesh->_is_nil() && baseOp ) {
1566 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1567 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1572 //================================================================================
1574 * \brief Gets dialog of this operation
1575 * \retval LightApp_Dialog* - pointer to dialog of this operation
1577 //================================================================================
1579 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1581 return computeDlg();
1584 //================================================================================
1586 * \brief Constructor
1588 //================================================================================
1590 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1591 : SMESHGUI_BaseComputeOp(),
1594 myPreviewDisplayer( 0 ),
1599 //================================================================================
1603 //================================================================================
1605 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1612 if ( myPreviewDisplayer )
1613 delete myPreviewDisplayer;
1614 myPreviewDisplayer = 0;
1617 //================================================================================
1619 * \brief Gets current dialog of this operation
1620 * \retval LightApp_Dialog* - pointer to dialog of this operation
1622 //================================================================================
1624 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1629 //================================================================================
1631 * \brief perform it's intention action: prepare data
1633 //================================================================================
1635 void SMESHGUI_PrecomputeOp::startOperation()
1637 myHelpFileName = "constructing_meshes.html#preview-anchor"; // other anchor onCompute()
1641 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1644 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1645 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1646 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1648 myActiveDlg = myDlg;
1650 // connect signal to compute dialog. which will be shown after Compute mesh operation
1651 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1654 // disconnect signals
1655 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1656 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1657 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1658 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1659 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1662 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1663 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1664 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1665 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1666 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1667 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1668 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1669 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1670 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1671 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1674 SMESHGUI_BaseComputeOp::startOperation();
1675 if (myMesh->_is_nil())
1678 if (myDlg->getPreviewMode() == -1)
1680 // nothing to preview
1681 SUIT_MessageBox::warning(desktop(),
1682 tr("SMESH_WRN_WARNING"),
1683 tr("SMESH_WRN_NOTHING_PREVIEW"));
1688 // disconnect slot from preview dialog to have Apply from results of compute operation only
1689 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1690 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1695 //================================================================================
1697 * \brief Stops operation
1699 //================================================================================
1701 void SMESHGUI_PrecomputeOp::stopOperation()
1703 if ( myPreviewDisplayer )
1705 myPreviewDisplayer->SetVisibility( false );
1706 delete myPreviewDisplayer;
1707 myPreviewDisplayer = 0;
1709 myMapShapeId.clear();
1710 SMESHGUI_BaseComputeOp::stopOperation();
1713 //================================================================================
1715 * \brief reinitialize dialog after operaiton become active again
1717 //================================================================================
1719 void SMESHGUI_PrecomputeOp::resumeOperation()
1721 if ( myActiveDlg == myDlg )
1723 SMESHGUI_BaseComputeOp::resumeOperation();
1726 //================================================================================
1728 * \brief perform it's intention action: reinitialise dialog
1730 //================================================================================
1732 void SMESHGUI_PrecomputeOp::initDialog()
1736 QMap<int, int> modeMap;
1737 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( myIObject->getEntry() );
1738 getAssignedAlgos( pMesh, modeMap );
1739 if ( modeMap.contains( SMESH::DIM_3D ) )
1741 if ( modeMap.contains( SMESH::DIM_2D ) )
1742 modes.append( SMESH::DIM_2D );
1743 if ( modeMap.contains( SMESH::DIM_1D ) )
1744 modes.append( SMESH::DIM_1D );
1746 else if ( modeMap.contains( SMESH::DIM_2D ) )
1748 if ( modeMap.contains( SMESH::DIM_1D ) )
1749 modes.append( SMESH::DIM_1D );
1752 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1753 myOrderMgr->SetMesh( myMesh );
1754 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1755 myDlg->getMeshOrderBox()->setVisible(isOrder);
1761 myDlg->setPreviewModes( modes );
1764 //================================================================================
1766 * \brief detect assigned mesh algorithms
1768 //================================================================================
1770 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1771 QMap<int,int>& theModeMap)
1773 if ( !theMesh ) return;
1775 _PTR(SObject) aHypFolder;
1776 _PTR(GenericAttribute) anAttr;
1777 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1778 if ( theMesh->FindSubObject( aPart, aHypFolder ))
1780 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1781 for ( ; anIter->More(); anIter->Next() )
1783 _PTR(SObject) anObj = anIter->Value();
1784 _PTR(SObject) aRefObj;
1785 if ( anObj->ReferencedObject( aRefObj ) )
1790 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1792 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1793 if ( CORBA::is_nil( aVar ) )
1796 SMESH::SMESH_Algo_var algo;
1797 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1800 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1801 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1802 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1805 if ( !algo->_is_nil() )
1807 theModeMap[ dim ] = 0;
1808 if ( theModeMap.size() == 3 )
1818 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1820 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1823 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1824 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1826 _PTR(SObject) anObj = anIter->Value();
1827 _PTR(SObject) aRefObj;
1828 if ( anObj->ReferencedObject( aRefObj ) )
1833 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1835 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1836 if ( CORBA::is_nil( aVar ) )
1839 SMESH::SMESH_Algo_var algo;
1840 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1843 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1844 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1845 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1848 if ( !algo->_is_nil() )
1850 theModeMap[ dim ] = 0;
1851 if ( theModeMap.size() == 3 )
1861 //================================================================================
1863 * \brief perform it's intention action: compute mesh
1865 //================================================================================
1867 void SMESHGUI_PrecomputeOp::onCompute()
1870 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1871 myOrderMgr->SetMeshOrder();
1872 myMapShapeId.clear();
1873 myActiveDlg = computeDlg();
1874 myHelpFileName = "constructing_meshes.html#compute-anchor";
1878 //================================================================================
1880 * \brief perform it's intention action: compute mesh
1882 //================================================================================
1884 void SMESHGUI_PrecomputeOp::onCancel()
1886 QObject* curDlg = sender();
1887 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1889 // return from error messages
1894 bool isRestoreOrder = false;
1895 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1897 // ask to remove already computed mesh elements
1898 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1899 tr( "CLEAR_SUBMESH_QUESTION" ),
1900 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1902 // remove all submeshes for collected shapes
1903 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1904 for ( ; it != myMapShapeId.constEnd(); ++it )
1905 myMesh->ClearSubMesh( it.key() );
1906 isRestoreOrder = true;
1910 // return previous mesh order
1911 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1912 if (!isRestoreOrder)
1914 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1915 tr( "SMESH_REJECT_MESH_ORDER" ),
1916 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1918 myOrderMgr->SetMeshOrder(myPrevOrder);
1924 myMapShapeId.clear();
1925 SMESHGUI_BaseComputeOp::onCancel();
1928 //================================================================================
1930 * \brief perform it's intention action: preview mesh
1932 //================================================================================
1934 void SMESHGUI_PrecomputeOp::onPreview()
1936 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1939 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1943 // set modified submesh priority if any
1944 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1945 myOrderMgr->SetMeshOrder();
1947 // Compute preview of mesh,
1948 // i.e. compute mesh till indicated dimension
1949 int dim = myDlg->getPreviewMode();
1951 SMESH::MemoryReserve aMemoryReserve;
1953 SMESH::compute_error_array_var aCompErrors;
1956 bool computeFailed = true, memoryLack = false;
1958 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1959 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1961 SMESHGUI* gui = getSMESHGUI();
1962 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1963 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1964 if ( errors->length() > 0 ) {
1965 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1968 SUIT_OverrideCursor aWaitCursor;
1970 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1971 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1972 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1974 SMESH::long_array_var aShapesId = new SMESH::long_array();
1978 SMESH::MeshPreviewStruct_var previewData =
1979 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1981 if ( & previewData.in() && previewData->nodesXYZ.length() > 0 )
1983 computeFailed = false;
1984 myPreviewDisplayer->SetData( previewData );
1985 // append shape indices with computed mesh entities
1986 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1987 myMapShapeId[ aShapesId[ i ] ] = 0;
1990 myPreviewDisplayer->SetVisibility(false);
1992 catch(const SALOME::SALOME_Exception & S_ex){
1994 myPreviewDisplayer->SetVisibility(false);
1999 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2000 // check if there are memory problems
2001 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
2002 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
2004 catch(const SALOME::SALOME_Exception & S_ex){
2009 aMemoryReserve.release();
2011 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2012 bool noHypoError = ( aHypErrors.isEmpty() );
2014 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2015 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2017 bool isShowError = true;
2018 switch( aNotifyMode ) {
2019 case 0: // show the mesh computation result dialog NEVER
2020 isShowError = false;
2022 case 1: // show the mesh computation result dialog if there are some errors
2023 default: // show the result dialog after each mesh computation
2024 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2025 isShowError = false;
2029 aWaitCursor.suspend();
2034 aCompDlg->setWindowTitle
2035 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2036 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2041 //================================================================================
2043 * \brief Constructor
2045 //================================================================================
2047 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2048 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2051 setWindowTitle( tr( "CAPTION" ) );
2053 setButtonText( OK, tr( "COMPUTE" ) );
2054 QFrame* main = mainFrame();
2055 main->setMinimumWidth( 300 );
2057 QVBoxLayout* layout = new QVBoxLayout( main );
2059 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2060 layout->addWidget(myOrderBox);
2062 QFrame* frame = new QFrame( main );
2063 layout->setMargin(0); layout->setSpacing(0);
2064 layout->addWidget( frame );
2066 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2067 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2069 myPreviewMode = new QtxComboBox( frame );
2070 frameLay->addWidget( myPreviewMode );
2072 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2073 frameLay->addWidget( myPreviewBtn );
2075 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2078 //================================================================================
2082 //================================================================================
2084 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2088 //================================================================================
2090 * \brief Sets available preview modes
2092 //================================================================================
2094 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2096 myPreviewMode->clear();
2097 QList<int>::const_iterator it = theModes.constBegin();
2098 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2100 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2101 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2102 myPreviewMode->setId( i, *it );
2104 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2107 //================================================================================
2109 * \brief Returns current preview mesh mode
2111 //================================================================================
2113 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2115 return myPreviewMode->currentId().toInt();
2118 //================================================================================
2120 * \brief Returns current preview mesh mode
2122 //================================================================================
2124 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2130 //================================================================================
2132 * \brief Constructor
2134 //================================================================================
2136 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2137 : SMESHGUI_BaseComputeOp()
2139 myHelpFileName = "constructing_meshes.html#evaluate-anchor";
2143 //================================================================================
2147 //================================================================================
2149 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2153 //================================================================================
2155 * \brief perform it's intention action: compute mesh
2157 //================================================================================
2159 void SMESHGUI_EvaluateOp::startOperation()
2161 SMESHGUI_BaseComputeOp::evaluateDlg();
2162 SMESHGUI_BaseComputeOp::startOperation();
2163 if (myMesh->_is_nil())
2168 //================================================================================
2170 * \brief Gets dialog of this operation
2171 * \retval LightApp_Dialog* - pointer to dialog of this operation
2173 //================================================================================
2175 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2177 return evaluateDlg();
2180 //================================================================================
2182 * \brief evaluateMesh()
2184 //================================================================================
2186 void SMESHGUI_BaseComputeOp::evaluateMesh()
2190 SMESH::MemoryReserve aMemoryReserve;
2192 SMESH::compute_error_array_var aCompErrors;
2195 bool evaluateFailed = true, memoryLack = false;
2196 SMESH::long_array_var aRes;
2198 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2199 if ( !aMeshSObj ) // IPAL21340
2202 bool hasShape = myMesh->HasShapeToMesh();
2203 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2206 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2207 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2208 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2209 if ( errors->length() > 0 ) {
2210 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2212 SUIT_OverrideCursor aWaitCursor;
2215 aRes = gen->Evaluate(myMesh, myMainShape);
2217 catch(const SALOME::SALOME_Exception & S_ex){
2223 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2225 catch(const SALOME::SALOME_Exception & S_ex){
2231 aMemoryReserve.release();
2233 evaluateFailed = ( aCompErrors->length() > 0 );
2234 myCompDlg->setWindowTitle
2235 ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2239 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2240 bool noHypoError = ( aHypErrors.isEmpty() );
2242 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2243 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2245 bool isShowResultDlg = true;
2247 //switch( aNotifyMode ) {
2248 //case 0: // show the mesh computation result dialog NEVER
2249 //isShowResultDlg = false;
2252 //case 1: // show the mesh computation result dialog if there are some errors
2253 //if ( memoryLack || !noHypoError )
2254 // isShowResultDlg = true;
2257 // isShowResultDlg = false;
2261 //default: // show the result dialog after each mesh computation
2262 //isShowResultDlg = true;
2266 if ( isShowResultDlg )
2267 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2268 noHypoError, aHypErrors);
2272 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2273 const bool theMemoryLack,
2274 const bool theNoCompError,
2275 SMESH::compute_error_array_var& theCompErrors,
2276 const bool theNoHypoError,
2277 const QString& theHypErrors)
2279 bool hasShape = myMesh->HasShapeToMesh();
2280 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2281 aCompDlg->myMemoryLackGroup->hide();
2283 if ( theMemoryLack )
2285 aCompDlg->myMemoryLackGroup->show();
2286 aCompDlg->myFullInfo->hide();
2287 aCompDlg->myBriefInfo->hide();
2288 aCompDlg->myHypErrorGroup->hide();
2289 aCompDlg->myCompErrorGroup->hide();
2291 else if ( theNoCompError && theNoHypoError )
2293 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2294 aCompDlg->myFullInfo->show();
2295 aCompDlg->myBriefInfo->hide();
2296 aCompDlg->myHypErrorGroup->hide();
2297 aCompDlg->myCompErrorGroup->hide();
2301 QTableWidget* tbl = aCompDlg->myTable;
2302 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2303 aCompDlg->myBriefInfo->show();
2304 aCompDlg->myFullInfo->hide();
2306 if ( theNoHypoError ) {
2307 aCompDlg->myHypErrorGroup->hide();
2310 aCompDlg->myHypErrorGroup->show();
2311 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2314 if ( theNoCompError ) {
2315 aCompDlg->myCompErrorGroup->hide();
2318 aCompDlg->myCompErrorGroup->show();
2320 aCompDlg->myPublishBtn->hide();
2321 aCompDlg->myShowBtn->hide();
2323 // fill table of errors
2324 tbl->setRowCount( theCompErrors->length() );
2325 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2326 else tbl->showColumn( COL_SHAPE );
2327 tbl->setColumnWidth( COL_ERROR, 200 );
2329 bool hasBadMesh = false;
2330 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2332 SMESH::ComputeError & err = theCompErrors[ row ];
2334 QString text = err.algoName.in();
2335 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2336 else tbl->item( row, COL_ALGO )->setText( text );
2338 text = SMESH::errorText( err.code, err.comment.in() );
2339 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2340 else tbl->item( row, COL_ERROR )->setText( text );
2342 text = QString("%1").arg( err.subShapeID );
2343 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2344 else tbl->item( row, COL_SHAPEID )->setText( text );
2346 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2347 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2348 else tbl->item( row, COL_SHAPE )->setText( text );
2350 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2351 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2352 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2354 text = err.hasBadMesh ? "hasBadMesh" : "";
2355 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2356 else tbl->item( row, COL_BAD_MESH )->setText( text );
2357 if ( err.hasBadMesh ) hasBadMesh = true;
2359 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2360 tbl->resizeRowToContents( row );
2362 tbl->resizeColumnToContents( COL_ALGO );
2363 tbl->resizeColumnToContents( COL_SHAPE );
2364 tbl->setWordWrap( true );
2368 aCompDlg->myBadMeshBtn->show();
2369 aCompDlg->myBadMeshToGroupBtn->show();
2373 aCompDlg->myBadMeshBtn->hide();
2374 aCompDlg->myBadMeshToGroupBtn->hide();
2376 tbl->setCurrentCell(0,0);
2377 currentCellChanged(); // to update buttons
2380 // show dialog and wait, because Compute can be invoked from Preview operation
2381 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2386 //================================================================================
2388 * \brief Gets dialog of evaluate operation
2389 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2391 //================================================================================
2393 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2397 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2398 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2399 // connect signals and slots
2400 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2401 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2402 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2403 QTableWidget* aTable = me->table();
2404 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2405 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));