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 myTable->horizontalHeader()->setSectionResizeMode( COL_ERROR, QHeaderView::Interactive );
579 myTable->setWordWrap( true );
580 myTable->horizontalHeader()->setStretchLastSection( true );
581 myTable->setMinimumWidth( 500 );
584 headers << tr( "COL_ALGO_HEADER" );
585 headers << tr( "COL_SHAPE_HEADER" );
586 headers << tr( "COL_ERROR_HEADER" );
587 headers << tr( "COL_SHAPEID_HEADER" );
588 headers << tr( "COL_PUBLISHED_HEADER" );
590 myTable->setHorizontalHeaderLabels( headers );
593 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
594 grpLayout->setSpacing(SPACING);
595 grpLayout->setMargin(MARGIN);
596 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
597 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
598 grpLayout->addWidget( myShowBtn, 2, 0 );
599 grpLayout->addWidget( myPublishBtn, 2, 1 );
600 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
601 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
602 grpLayout->setColumnStretch( 3, 1 );
604 // Hypothesis definition errors
606 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
607 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
608 myHypErrorGroupLayout->setMargin(MARGIN);
609 myHypErrorGroupLayout->setSpacing(SPACING);
610 myHypErrorLabel = new QLabel(myHypErrorGroup);
611 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
615 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
616 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
617 myMemoryLackGroupLayout->setMargin(MARGIN);
618 myMemoryLackGroupLayout->setSpacing(SPACING);
619 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
620 QFont bold = memLackLabel->font(); bold.setBold(true);
621 memLackLabel->setFont( bold );
622 memLackLabel->setMinimumWidth(300);
623 myMemoryLackGroupLayout->addWidget(memLackLabel);
625 // add all widgets to aFrame
626 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
627 aLay->setMargin( MARGIN );
628 aLay->setSpacing( SPACING );
629 aLay->addWidget( aPixGrp );
630 aLay->addWidget( nameBox );
631 aLay->addWidget( myBriefInfo );
632 aLay->addWidget( myFullInfo );
633 aLay->addWidget( myHypErrorGroup );
634 aLay->addWidget( myCompErrorGroup );
635 aLay->addWidget( myMemoryLackGroup );
636 aLay->setStretchFactor( myCompErrorGroup, 1 );
638 ((QPushButton*) button( OK ))->setDefault( true );
643 //================================================================================
647 //================================================================================
649 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
650 : SMESHGUI_Operation(), myCompDlg( 0 )
652 myTShapeDisplayer = new SMESH::TShapeDisplayer();
653 myBadMeshDisplayer = 0;
655 //myHelpFileName = "/files/about_meshes.htm"; // V3
656 myHelpFileName = "about_meshes.html"; // V4
659 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
661 LightApp_SelectionMgr* Sel = selectionMgr();
662 SALOME_ListIO selected; Sel->selectedObjects( selected );
663 Handle(SALOME_InteractiveObject) anIO = selected.First();
664 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
665 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
668 //================================================================================
670 * \brief Start operation
671 * \purpose Init dialog fields, connect signals and slots, show dialog
673 //================================================================================
675 void SMESHGUI_BaseComputeOp::startOperation()
677 // create compute dialog if not created before
680 myMesh = SMESH::SMESH_Mesh::_nil();
681 myMainShape = GEOM::GEOM_Object::_nil();
682 myCurShape = GEOM::GEOM_Object::_nil();
685 LightApp_SelectionMgr *Sel = selectionMgr();
686 SALOME_ListIO selected; Sel->selectedObjects( selected );
688 int nbSel = selected.Extent();
690 SUIT_MessageBox::warning(desktop(),
691 tr("SMESH_WRN_WARNING"),
692 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
697 myIObject = selected.First();
698 CORBA::Object_var anObj = SMESH::IObjectToObject( myIObject );
700 myMesh = SMESH::SMESH_Mesh::_narrow(anObj);
701 if ( myMesh->_is_nil() )
703 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
704 if ( !aSubMesh->_is_nil() )
706 myMesh = aSubMesh->GetFather();
707 myCurShape = aSubMesh->GetSubShape();
712 myCurShape = myMesh->GetShapeToMesh();
715 if (myMesh->_is_nil()) {
716 SUIT_MessageBox::warning(desktop(),
717 tr("SMESH_WRN_WARNING"),
718 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
723 myMainShape = myMesh->GetShapeToMesh();
725 SMESHGUI_Operation::startOperation();
728 //================================================================================
729 //================================================================================
731 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
732 SMESH::SMESH_Mesh_var mesh,
733 GEOM::GEOM_Object_var mainShape)
738 myMainShape = mainShape;
741 void SMESHGUI_ComputeDlg_QThread::run()
743 myResult = myGen->Compute(myMesh, myMainShape);
746 bool SMESHGUI_ComputeDlg_QThread::result()
751 void SMESHGUI_ComputeDlg_QThread::cancel()
753 myGen->CancelCompute(myMesh, myMainShape);
756 //================================================================================
757 //================================================================================
759 SMESHGUI_ComputeDlg_QThreadQDialog::
760 SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
761 SMESH::SMESH_Gen_var gen,
762 SMESH::SMESH_Mesh_var mesh,
763 GEOM::GEOM_Object_var mainShape)
765 Qt::WindowSystemMenuHint |
766 Qt::WindowCloseButtonHint |
768 Qt::WindowMaximizeButtonHint),
769 qthread(gen, mesh, mainShape)
772 setWindowTitle(tr("TITLE"));
773 setMinimumWidth( 200 );
775 cancelButton = new QPushButton(tr("CANCEL"));
776 cancelButton->setDefault(true);
777 cancelButton->setCheckable(true);
779 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
780 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
781 nbNodesLabel = new QLabel("0", this );
782 nbElemsLabel = new QLabel("0", this );
783 #if !defined WIN32 && !defined __APPLE__
784 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
785 freeRAMLabel = new QLabel("", this );
787 progressBar = new QProgressBar(this);
788 progressBar->setMinimum( 0 );
789 progressBar->setMaximum( 1000 );
791 QGridLayout* layout = new QGridLayout(this);
792 layout->setMargin( MARGIN );
793 layout->setSpacing( SPACING );
795 layout->addWidget(nbNodesName, row, 0);
796 layout->addWidget(nbNodesLabel, row++, 1);
797 layout->addWidget(nbElemsName, row, 0);
798 layout->addWidget(nbElemsLabel, row++, 1);
799 #if !defined WIN32 && !defined __APPLE__
800 layout->addWidget(freeRAMName, row, 0);
801 layout->addWidget(freeRAMLabel, row++, 1);
803 layout->addWidget(progressBar, row++, 0, 1, 2);
804 layout->addWidget(cancelButton, row++, 0, 1, 2);
808 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
810 startTimer(300); // millisecs
814 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
816 return qthread.result();
819 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
822 cancelButton->setText( tr("CANCELING"));
823 cancelButton->setEnabled(false);
826 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
828 if ( !cancelButton->isChecked() ) // not yet cancelled
829 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
831 if(qthread.isFinished())
837 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
838 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
839 #if !defined WIN32 && !defined __APPLE__
841 const int err = sysinfo( &si );
843 freeRAMLabel->setText("");
845 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
846 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
852 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
854 if(qthread.isRunning())
862 //================================================================================
864 * \brief computeMesh()
866 //================================================================================
868 void SMESHGUI_BaseComputeOp::computeMesh()
872 SMESH::MemoryReserve aMemoryReserve;
874 SMESH::compute_error_array_var aCompErrors;
877 bool computeFailed = true, memoryLack = false;
879 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
880 if ( !aMeshSObj ) // IPAL 21340
882 bool hasShape = myMesh->HasShapeToMesh();
883 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
886 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
887 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
888 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
889 if ( errors->length() > 0 ) {
890 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
892 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
893 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
894 tr( "FULL_RECOMPUTE_QUESTION" ),
895 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
897 SUIT_OverrideCursor aWaitCursor;
900 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myCurShape);
901 qthreaddialog.exec();
902 computeFailed = !qthreaddialog.result();
904 catch(const SALOME::SALOME_Exception & S_ex) {
909 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
910 // check if there are memory problems
911 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
912 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
914 catch(const SALOME::SALOME_Exception & S_ex) {
918 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
922 // NPAL16631: if ( !memoryLack )
924 update( UF_ObjBrowser | UF_Model );
927 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
928 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
930 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
931 int entities = SMESH_Actor::eAllEntity;
936 // List of objects that will be updated automatically
937 typedef QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > TListOf_IDSrc_SObj;
938 TListOf_IDSrc_SObj aListToUpdate;
939 SMESH::SMESH_IDSource_var aMeshObj =
940 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
941 // put Mesh into list
942 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aMeshObj, aMeshSObj ));
943 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
944 // put SubMeshes into list
945 for ( CORBA::ULong i = 0; i < aSubMeshes->length(); i++ )
947 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
948 if ( CORBA::is_nil( sm ) ) continue;
949 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
950 if ( !smSObj ) continue;
951 SMESH::SMESH_IDSource_var aSubMeshObj =
952 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
953 SMESH_Actor *anActor = SMESH::FindActorByObject( aSubMeshObj );
954 if ( anActor && anActor->GetVisibility() )
955 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aSubMeshObj, smSObj ));
957 // put Groups into list
958 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
959 for ( size_t i = 0; i < aGroups->length(); ++i )
961 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
962 if ( CORBA::is_nil( aGrp ) ) continue;
963 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
964 if ( !aStdGroup->_is_nil() ) continue; // don't update standalone groups
965 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
966 if ( !aGroupSO ) continue;
967 SMESH::SMESH_IDSource_var aGroupObj =
968 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
969 SMESH_Actor *anActor = SMESH::FindActorByObject( aGroupObj );
970 if ( anActor && anActor->GetVisibility() )
971 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aGroupObj, aGroupSO ));
974 // update mesh, sub-mesh and groups, if it's possible
975 TListOf_IDSrc_SObj::iterator anIter;
976 for ( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ )
978 SMESH::SMESH_Mesh_var aMesh =
979 SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
981 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded,
982 &hidden, &nbElements ) )
986 std::string entry = (*anIter).second->GetID();
987 if ( !aMesh->_is_nil() ) // display only a mesh
989 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
990 if ( !anActor ) anActor = SMESH::CreateActor( entry.c_str(), /*clearLog =*/true );
991 if ( anActor ) // actor is not created for an empty mesh
993 anActor->SetEntityMode( entities );
994 //SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor ); -- 23615
997 SMESH::UpdateView( SMESH::eDisplay, entry.c_str() );
999 if ( SVTK_ViewWindow* vtkWnd = SMESH::GetVtkViewWindow(SMESH::GetActiveWindow() ))
1000 if ( vtkWnd->getRenderer() )
1001 vtkWnd->getRenderer()->ResetCameraClippingRange();
1003 if ( limitExceeded && !aMesh->_is_nil() )
1005 QStringList hiddenMsg;
1006 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1007 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
1008 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
1009 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
1010 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
1011 SUIT_MessageBox::warning( desktop(),
1012 tr( "SMESH_WRN_WARNING" ),
1013 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1016 arg( hiddenMsg.join(", ")));
1021 MESSAGE ( "Exception thrown during mesh visualization" );
1023 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1024 SMESH::OnVisuException();
1031 else if ( limitExceeded && !aMesh->_is_nil() )
1033 SUIT_MessageBox::warning( desktop(),
1034 tr( "SMESH_WRN_WARNING" ),
1035 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1036 arg( nbElements ).arg( limitSize ) );
1040 if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1042 SALOME_ListIO selected;
1043 selected.Append( myIObject );
1044 Sel->setSelectedObjects( selected );
1050 aMemoryReserve.release();
1052 myCompDlg->setWindowTitle
1053 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1057 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1058 bool noHypoError = ( aHypErrors.isEmpty() );
1060 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1061 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1063 bool isShowResultDlg = true;
1064 switch( aNotifyMode ) {
1065 case 0: // show the mesh computation result dialog NEVER
1066 isShowResultDlg = false;
1069 case 1: // show the mesh computation result dialog if there are some errors
1070 if ( memoryLack || !noCompError || !noHypoError )
1071 isShowResultDlg = true;
1074 isShowResultDlg = false;
1078 default: // show the result dialog after each mesh computation
1079 isShowResultDlg = true;
1083 if ( isShowResultDlg )
1084 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1087 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1088 const bool theNoCompError,
1089 SMESH::compute_error_array_var& theCompErrors,
1090 const bool theNoHypoError,
1091 const QString& theHypErrors )
1093 bool hasShape = myMesh->HasShapeToMesh();
1094 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1095 aCompDlg->myMemoryLackGroup->hide();
1097 if ( theMemoryLack )
1099 aCompDlg->myMemoryLackGroup->show();
1100 aCompDlg->myFullInfo->hide();
1101 aCompDlg->myBriefInfo->hide();
1102 aCompDlg->myHypErrorGroup->hide();
1103 aCompDlg->myCompErrorGroup->hide();
1105 else if ( theNoCompError && theNoHypoError )
1107 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1108 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1109 aCompDlg->myFullInfo->show();
1110 aCompDlg->myBriefInfo->hide();
1111 aCompDlg->myHypErrorGroup->hide();
1112 aCompDlg->myCompErrorGroup->hide();
1116 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1117 for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1118 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1119 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1121 // full or brief mesh info
1122 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1123 if ( onlyWarnings ) {
1124 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1125 aCompDlg->myFullInfo->show();
1126 aCompDlg->myBriefInfo->hide();
1128 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1129 aCompDlg->myBriefInfo->show();
1130 aCompDlg->myFullInfo->hide();
1133 // pbs of hypo definitions
1134 if ( theNoHypoError ) {
1135 aCompDlg->myHypErrorGroup->hide();
1137 aCompDlg->myHypErrorGroup->show();
1138 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1142 if ( theNoCompError )
1144 aCompDlg->myCompErrorGroup->hide();
1148 aCompDlg->myCompErrorGroup->show();
1151 aCompDlg->myWarningLabel->show();
1153 aCompDlg->myWarningLabel->hide();
1156 aCompDlg->myPublishBtn->hide();
1157 aCompDlg->myShowBtn->hide();
1160 aCompDlg->myPublishBtn->show();
1161 aCompDlg->myShowBtn->show();
1164 // fill table of errors
1165 QTableWidget* tbl = aCompDlg->myTable;
1166 tbl->setRowCount( theCompErrors->length() );
1167 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1168 else tbl->showColumn( COL_SHAPE );
1169 tbl->setColumnWidth( COL_ERROR, 200 );
1171 bool hasBadMesh = false;
1172 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1174 SMESH::ComputeError & err = theCompErrors[ row ];
1176 QString text = err.algoName.in();
1177 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1178 else tbl->item( row, COL_ALGO )->setText( text );
1180 text = SMESH::errorText( err.code, err.comment.in() );
1181 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1182 else tbl->item( row, COL_ERROR )->setText( text );
1184 text = QString("%1").arg( err.subShapeID );
1185 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1186 else tbl->item( row, COL_SHAPEID )->setText( text );
1188 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1189 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1190 else tbl->item( row, COL_SHAPE )->setText( text );
1192 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1193 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1194 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1196 text = err.hasBadMesh ? "hasBadMesh" : "";
1197 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1198 else tbl->item( row, COL_BAD_MESH )->setText( text );
1199 if ( err.hasBadMesh ) hasBadMesh = true;
1201 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1202 tbl->resizeRowToContents( row );
1204 tbl->resizeColumnToContents( COL_ALGO );
1205 tbl->resizeColumnToContents( COL_SHAPE );
1206 tbl->setWordWrap( true );
1209 aCompDlg->myBadMeshBtn->show();
1210 aCompDlg->myBadMeshToGroupBtn->show();
1213 aCompDlg->myBadMeshBtn->hide();
1214 aCompDlg->myBadMeshToGroupBtn->hide();
1216 tbl->setCurrentCell(0,0);
1217 currentCellChanged(); // to update buttons
1220 // show dialog and wait, because Compute can be invoked from Preview operation
1221 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1225 //================================================================================
1227 * \brief Stops operation
1229 //================================================================================
1231 void SMESHGUI_BaseComputeOp::stopOperation()
1233 SMESHGUI_Operation::stopOperation();
1234 if ( myTShapeDisplayer )
1235 myTShapeDisplayer->SetVisibility( false );
1236 if ( myBadMeshDisplayer ) {
1237 myBadMeshDisplayer->SetVisibility( false );
1238 // delete it in order not to have problems at its destruction when the viewer
1239 // where it worked is dead due to e.g. study closing
1240 delete myBadMeshDisplayer;
1241 myBadMeshDisplayer = 0;
1243 myIObject.Nullify();
1246 //================================================================================
1248 * \brief publish selected sub-shape
1250 //================================================================================
1252 void SMESHGUI_BaseComputeOp::onPublishShape()
1254 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1255 GEOM::GEOM_Object_var meshShape = myMesh->GetShapeToMesh();
1257 QStringList entryList;
1259 SMESH::getSelectedRows( table(), rows );
1261 foreach ( row, rows )
1263 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1264 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1265 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1267 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1269 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1270 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( myMainShape,
1271 name.toUtf8().data(),
1272 GEOM::GEOM_Object::_nil());
1273 // look for myMainShape in the table
1274 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1275 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1276 if ( so->_is_nil() ) {
1277 CORBA::String_var name = so->GetName();
1278 CORBA::String_var entry = so->GetID();
1279 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1280 table()->item( r, COL_SHAPE )->setText( shapeText );
1281 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1286 if ( curSub == 1 ) continue;
1288 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1289 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( shape,
1290 name.toUtf8().data(), myMainShape);
1291 if ( !so->_is_nil() ) {
1292 CORBA::String_var name = so->GetName();
1293 CORBA::String_var entry = so->GetID();
1294 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1295 table()->item( row, COL_SHAPE )->setText( shapeText );
1296 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1297 entryList.push_back( entry.in() );
1301 getSMESHGUI()->getApp()->updateObjectBrowser();
1302 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1304 currentCellChanged(); // to update buttons
1307 //================================================================================
1309 * \brief show mesh elements preventing computation of a submesh of current row
1311 //================================================================================
1313 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1315 myTShapeDisplayer->SetVisibility( false );
1317 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1318 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1320 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1321 SMESHGUI* gui = getSMESHGUI();
1322 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1323 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1324 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1325 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1326 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1327 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1328 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1329 vtkProperty* prop = vtkProperty::New();
1330 prop->SetLineWidth( aLineWidth * 3 );
1331 prop->SetPointSize( aPointSize * 3 );
1332 prop->SetColor( 250, 0, 250 );
1333 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1334 myBadMeshDisplayer->SetData( aMeshData.in() );
1340 //================================================================================
1342 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1344 //================================================================================
1346 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1349 SMESH::getSelectedRows( table(), rows );
1351 foreach ( row, rows )
1353 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1355 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1356 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1357 if ( grName.isEmpty() ) grName = "bad mesh";
1358 else grName = "bad mesh of " + grName;
1359 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1360 SMESH::ListOfGroups_var groups
1361 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toUtf8().data()) );
1362 update( UF_ObjBrowser | UF_Model );
1363 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1365 QStringList anEntryList;
1366 for ( size_t i = 0; i < groups->length(); ++i )
1367 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1368 anEntryList.append( so->GetID().c_str() );
1370 if ( !anEntryList.isEmpty())
1371 anApp->browseObjects( anEntryList, true, false );
1377 //================================================================================
1379 * \brief SLOT called when a selected cell in table() changed
1381 //================================================================================
1383 void SMESHGUI_BaseComputeOp::currentCellChanged()
1385 myTShapeDisplayer->SetVisibility( false );
1386 if ( myBadMeshDisplayer )
1387 myBadMeshDisplayer->SetVisibility( false );
1389 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1391 int nbSelected = SMESH::getSelectedRows( table(), rows );
1393 foreach ( row, rows )
1395 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1396 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1397 if ( hasData && !isPublished )
1398 publishEnable = true;
1400 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1401 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1403 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1410 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1413 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1414 myCompDlg->myShowBtn ->setEnabled( showEnable );
1415 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1416 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1419 //================================================================================
1421 * \brief update preview
1423 //================================================================================
1425 void SMESHGUI_BaseComputeOp::onPreviewShape()
1427 if ( myTShapeDisplayer )
1429 SUIT_OverrideCursor aWaitCursor;
1431 SMESH::getSelectedRows( table(), rows );
1433 bool showOnly = true;
1435 foreach ( row, rows )
1437 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1439 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1443 currentCellChanged(); // to update buttons
1447 //================================================================================
1451 //================================================================================
1453 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1457 delete myTShapeDisplayer;
1458 if ( myBadMeshDisplayer )
1459 delete myBadMeshDisplayer;
1462 //================================================================================
1464 * \brief Gets dialog of compute operation
1465 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1467 //================================================================================
1469 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1473 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1474 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1475 // connect signals and slots
1476 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1477 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1478 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1479 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1481 QTableWidget* aTable = me->table();
1482 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1483 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1488 //================================================================================
1490 * \brief returns from compute mesh result dialog
1492 //================================================================================
1494 bool SMESHGUI_BaseComputeOp::onApply()
1499 //================================================================================
1501 * \brief Return a table
1503 //================================================================================
1505 QTableWidget* SMESHGUI_BaseComputeOp::table()
1507 return myCompDlg->myTable;
1511 //================================================================================
1513 * \brief Constructor
1515 //================================================================================
1517 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1518 : SMESHGUI_BaseComputeOp()
1520 myHelpFileName = "constructing_meshes.html#compute-anchor";
1524 //================================================================================
1528 //================================================================================
1530 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1534 //================================================================================
1536 * \brief perform it's intention action: compute mesh
1538 //================================================================================
1540 void SMESHGUI_ComputeOp::startOperation()
1542 SMESHGUI_BaseComputeOp::startOperation();
1543 if (myMesh->_is_nil())
1548 //================================================================================
1550 * \brief check the same operations on the same mesh
1552 //================================================================================
1554 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1556 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1558 if ( !myMesh->_is_nil() && baseOp ) {
1559 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1560 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1565 //================================================================================
1567 * \brief Gets dialog of this operation
1568 * \retval LightApp_Dialog* - pointer to dialog of this operation
1570 //================================================================================
1572 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1574 return computeDlg();
1577 //================================================================================
1579 * \brief Constructor
1581 //================================================================================
1583 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1584 : SMESHGUI_BaseComputeOp(),
1587 myPreviewDisplayer( 0 ),
1592 //================================================================================
1596 //================================================================================
1598 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1605 if ( myPreviewDisplayer )
1606 delete myPreviewDisplayer;
1607 myPreviewDisplayer = 0;
1610 //================================================================================
1612 * \brief Gets current dialog of this operation
1613 * \retval LightApp_Dialog* - pointer to dialog of this operation
1615 //================================================================================
1617 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1622 //================================================================================
1624 * \brief perform it's intention action: prepare data
1626 //================================================================================
1628 void SMESHGUI_PrecomputeOp::startOperation()
1630 myHelpFileName = "constructing_meshes.html#preview-anchor"; // other anchor onCompute()
1634 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1637 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1638 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1639 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1641 myActiveDlg = myDlg;
1643 // connect signal to compute dialog. which will be shown after Compute mesh operation
1644 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1647 // disconnect signals
1648 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1649 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1650 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1651 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1652 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1655 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1656 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1657 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1658 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1659 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1660 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1661 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1662 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1663 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1664 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1667 SMESHGUI_BaseComputeOp::startOperation();
1668 if (myMesh->_is_nil())
1671 if (myDlg->getPreviewMode() == -1)
1673 // nothing to preview
1674 SUIT_MessageBox::warning(desktop(),
1675 tr("SMESH_WRN_WARNING"),
1676 tr("SMESH_WRN_NOTHING_PREVIEW"));
1681 // disconnect slot from preview dialog to have Apply from results of compute operation only
1682 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1683 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1688 //================================================================================
1690 * \brief Stops operation
1692 //================================================================================
1694 void SMESHGUI_PrecomputeOp::stopOperation()
1696 if ( myPreviewDisplayer )
1698 myPreviewDisplayer->SetVisibility( false );
1699 delete myPreviewDisplayer;
1700 myPreviewDisplayer = 0;
1702 myMapShapeId.clear();
1703 SMESHGUI_BaseComputeOp::stopOperation();
1706 //================================================================================
1708 * \brief reinitialize dialog after operaiton become active again
1710 //================================================================================
1712 void SMESHGUI_PrecomputeOp::resumeOperation()
1714 if ( myActiveDlg == myDlg )
1716 SMESHGUI_BaseComputeOp::resumeOperation();
1719 //================================================================================
1721 * \brief perform it's intention action: reinitialise dialog
1723 //================================================================================
1725 void SMESHGUI_PrecomputeOp::initDialog()
1729 QMap<int, int> modeMap;
1730 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( myIObject->getEntry() );
1731 getAssignedAlgos( pMesh, modeMap );
1732 if ( modeMap.contains( SMESH::DIM_3D ) )
1734 if ( modeMap.contains( SMESH::DIM_2D ) )
1735 modes.append( SMESH::DIM_2D );
1736 if ( modeMap.contains( SMESH::DIM_1D ) )
1737 modes.append( SMESH::DIM_1D );
1739 else if ( modeMap.contains( SMESH::DIM_2D ) )
1741 if ( modeMap.contains( SMESH::DIM_1D ) )
1742 modes.append( SMESH::DIM_1D );
1745 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1746 myOrderMgr->SetMesh( myMesh );
1747 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1748 myDlg->getMeshOrderBox()->setVisible(isOrder);
1754 myDlg->setPreviewModes( modes );
1757 //================================================================================
1759 * \brief detect assigned mesh algorithms
1761 //================================================================================
1763 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1764 QMap<int,int>& theModeMap)
1766 if ( !theMesh ) return;
1768 _PTR(SObject) aHypFolder;
1769 _PTR(GenericAttribute) anAttr;
1770 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1771 if ( theMesh->FindSubObject( aPart, aHypFolder ))
1773 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1774 for ( ; anIter->More(); anIter->Next() )
1776 _PTR(SObject) anObj = anIter->Value();
1777 _PTR(SObject) aRefObj;
1778 if ( anObj->ReferencedObject( aRefObj ) )
1783 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1785 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1786 if ( CORBA::is_nil( aVar ) )
1789 SMESH::SMESH_Algo_var algo;
1790 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1793 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1794 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1795 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1798 if ( !algo->_is_nil() )
1800 theModeMap[ dim ] = 0;
1801 if ( theModeMap.size() == 3 )
1811 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1813 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1816 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1817 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1819 _PTR(SObject) anObj = anIter->Value();
1820 _PTR(SObject) aRefObj;
1821 if ( anObj->ReferencedObject( aRefObj ) )
1826 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1828 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1829 if ( CORBA::is_nil( aVar ) )
1832 SMESH::SMESH_Algo_var algo;
1833 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1836 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1837 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1838 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1841 if ( !algo->_is_nil() )
1843 theModeMap[ dim ] = 0;
1844 if ( theModeMap.size() == 3 )
1854 //================================================================================
1856 * \brief perform it's intention action: compute mesh
1858 //================================================================================
1860 void SMESHGUI_PrecomputeOp::onCompute()
1863 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1864 myOrderMgr->SetMeshOrder();
1865 myMapShapeId.clear();
1866 myActiveDlg = computeDlg();
1867 myHelpFileName = "constructing_meshes.html#compute-anchor";
1871 //================================================================================
1873 * \brief perform it's intention action: compute mesh
1875 //================================================================================
1877 void SMESHGUI_PrecomputeOp::onCancel()
1879 QObject* curDlg = sender();
1880 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1882 // return from error messages
1887 bool isRestoreOrder = false;
1888 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1890 // ask to remove already computed mesh elements
1891 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1892 tr( "CLEAR_SUBMESH_QUESTION" ),
1893 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1895 // remove all submeshes for collected shapes
1896 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1897 for ( ; it != myMapShapeId.constEnd(); ++it )
1898 myMesh->ClearSubMesh( it.key() );
1899 isRestoreOrder = true;
1903 // return previous mesh order
1904 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1905 if (!isRestoreOrder)
1907 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1908 tr( "SMESH_REJECT_MESH_ORDER" ),
1909 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1911 myOrderMgr->SetMeshOrder(myPrevOrder);
1917 myMapShapeId.clear();
1918 SMESHGUI_BaseComputeOp::onCancel();
1921 //================================================================================
1923 * \brief perform it's intention action: preview mesh
1925 //================================================================================
1927 void SMESHGUI_PrecomputeOp::onPreview()
1929 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1932 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1936 // set modified submesh priority if any
1937 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1938 myOrderMgr->SetMeshOrder();
1940 // Compute preview of mesh,
1941 // i.e. compute mesh till indicated dimension
1942 int dim = myDlg->getPreviewMode();
1944 SMESH::MemoryReserve aMemoryReserve;
1946 SMESH::compute_error_array_var aCompErrors;
1949 bool computeFailed = true, memoryLack = false;
1951 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1952 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1954 SMESHGUI* gui = getSMESHGUI();
1955 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1956 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1957 if ( errors->length() > 0 ) {
1958 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1961 SUIT_OverrideCursor aWaitCursor;
1963 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1964 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1965 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1967 SMESH::long_array_var aShapesId = new SMESH::long_array();
1971 SMESH::MeshPreviewStruct_var previewData =
1972 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1974 if ( & previewData.in() && previewData->nodesXYZ.length() > 0 )
1976 computeFailed = false;
1977 myPreviewDisplayer->SetData( previewData );
1978 // append shape indices with computed mesh entities
1979 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1980 myMapShapeId[ aShapesId[ i ] ] = 0;
1983 myPreviewDisplayer->SetVisibility(false);
1985 catch(const SALOME::SALOME_Exception & S_ex){
1987 myPreviewDisplayer->SetVisibility(false);
1992 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1993 // check if there are memory problems
1994 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1995 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1997 catch(const SALOME::SALOME_Exception & S_ex){
2002 aMemoryReserve.release();
2004 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2005 bool noHypoError = ( aHypErrors.isEmpty() );
2007 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2008 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2010 bool isShowError = true;
2011 switch( aNotifyMode ) {
2012 case 0: // show the mesh computation result dialog NEVER
2013 isShowError = false;
2015 case 1: // show the mesh computation result dialog if there are some errors
2016 default: // show the result dialog after each mesh computation
2017 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2018 isShowError = false;
2022 aWaitCursor.suspend();
2027 aCompDlg->setWindowTitle
2028 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2029 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2034 //================================================================================
2036 * \brief Constructor
2038 //================================================================================
2040 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2041 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2044 setWindowTitle( tr( "CAPTION" ) );
2046 setButtonText( OK, tr( "COMPUTE" ) );
2047 QFrame* main = mainFrame();
2048 main->setMinimumWidth( 300 );
2050 QVBoxLayout* layout = new QVBoxLayout( main );
2052 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2053 layout->addWidget(myOrderBox);
2055 QFrame* frame = new QFrame( main );
2056 layout->setMargin(0); layout->setSpacing(0);
2057 layout->addWidget( frame );
2059 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2060 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2062 myPreviewMode = new QtxComboBox( frame );
2063 frameLay->addWidget( myPreviewMode );
2065 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2066 frameLay->addWidget( myPreviewBtn );
2068 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2071 //================================================================================
2075 //================================================================================
2077 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2081 //================================================================================
2083 * \brief Sets available preview modes
2085 //================================================================================
2087 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2089 myPreviewMode->clear();
2090 QList<int>::const_iterator it = theModes.constBegin();
2091 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2093 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2094 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2095 myPreviewMode->setId( i, *it );
2097 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2100 //================================================================================
2102 * \brief Returns current preview mesh mode
2104 //================================================================================
2106 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2108 return myPreviewMode->currentId().toInt();
2111 //================================================================================
2113 * \brief Returns current preview mesh mode
2115 //================================================================================
2117 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2123 //================================================================================
2125 * \brief Constructor
2127 //================================================================================
2129 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2130 : SMESHGUI_BaseComputeOp()
2132 myHelpFileName = "constructing_meshes.html#evaluate-anchor";
2136 //================================================================================
2140 //================================================================================
2142 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2146 //================================================================================
2148 * \brief perform it's intention action: compute mesh
2150 //================================================================================
2152 void SMESHGUI_EvaluateOp::startOperation()
2154 SMESHGUI_BaseComputeOp::evaluateDlg();
2155 SMESHGUI_BaseComputeOp::startOperation();
2156 if (myMesh->_is_nil())
2161 //================================================================================
2163 * \brief Gets dialog of this operation
2164 * \retval LightApp_Dialog* - pointer to dialog of this operation
2166 //================================================================================
2168 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2170 return evaluateDlg();
2173 //================================================================================
2175 * \brief evaluateMesh()
2177 //================================================================================
2179 void SMESHGUI_BaseComputeOp::evaluateMesh()
2183 SMESH::MemoryReserve aMemoryReserve;
2185 SMESH::compute_error_array_var aCompErrors;
2188 bool evaluateFailed = true, memoryLack = false;
2189 SMESH::long_array_var aRes;
2191 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2192 if ( !aMeshSObj ) // IPAL21340
2195 bool hasShape = myMesh->HasShapeToMesh();
2196 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2199 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2200 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2201 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2202 if ( errors->length() > 0 ) {
2203 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2205 SUIT_OverrideCursor aWaitCursor;
2208 aRes = gen->Evaluate(myMesh, myMainShape);
2210 catch(const SALOME::SALOME_Exception & S_ex){
2216 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2218 catch(const SALOME::SALOME_Exception & S_ex){
2224 aMemoryReserve.release();
2226 evaluateFailed = ( aCompErrors->length() > 0 );
2227 myCompDlg->setWindowTitle
2228 ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2232 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2233 bool noHypoError = ( aHypErrors.isEmpty() );
2235 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2236 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2238 bool isShowResultDlg = true;
2240 //switch( aNotifyMode ) {
2241 //case 0: // show the mesh computation result dialog NEVER
2242 //isShowResultDlg = false;
2245 //case 1: // show the mesh computation result dialog if there are some errors
2246 //if ( memoryLack || !noHypoError )
2247 // isShowResultDlg = true;
2250 // isShowResultDlg = false;
2254 //default: // show the result dialog after each mesh computation
2255 //isShowResultDlg = true;
2259 if ( isShowResultDlg )
2260 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2261 noHypoError, aHypErrors);
2265 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2266 const bool theMemoryLack,
2267 const bool theNoCompError,
2268 SMESH::compute_error_array_var& theCompErrors,
2269 const bool theNoHypoError,
2270 const QString& theHypErrors)
2272 bool hasShape = myMesh->HasShapeToMesh();
2273 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2274 aCompDlg->myMemoryLackGroup->hide();
2276 if ( theMemoryLack )
2278 aCompDlg->myMemoryLackGroup->show();
2279 aCompDlg->myFullInfo->hide();
2280 aCompDlg->myBriefInfo->hide();
2281 aCompDlg->myHypErrorGroup->hide();
2282 aCompDlg->myCompErrorGroup->hide();
2284 else if ( theNoCompError && theNoHypoError )
2286 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2287 aCompDlg->myFullInfo->show();
2288 aCompDlg->myBriefInfo->hide();
2289 aCompDlg->myHypErrorGroup->hide();
2290 aCompDlg->myCompErrorGroup->hide();
2294 QTableWidget* tbl = aCompDlg->myTable;
2295 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2296 aCompDlg->myBriefInfo->show();
2297 aCompDlg->myFullInfo->hide();
2299 if ( theNoHypoError ) {
2300 aCompDlg->myHypErrorGroup->hide();
2303 aCompDlg->myHypErrorGroup->show();
2304 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2307 if ( theNoCompError ) {
2308 aCompDlg->myCompErrorGroup->hide();
2311 aCompDlg->myCompErrorGroup->show();
2313 aCompDlg->myPublishBtn->hide();
2314 aCompDlg->myShowBtn->hide();
2316 // fill table of errors
2317 tbl->setRowCount( theCompErrors->length() );
2318 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2319 else tbl->showColumn( COL_SHAPE );
2320 tbl->setColumnWidth( COL_ERROR, 200 );
2322 bool hasBadMesh = false;
2323 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2325 SMESH::ComputeError & err = theCompErrors[ row ];
2327 QString text = err.algoName.in();
2328 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2329 else tbl->item( row, COL_ALGO )->setText( text );
2331 text = SMESH::errorText( err.code, err.comment.in() );
2332 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2333 else tbl->item( row, COL_ERROR )->setText( text );
2335 text = QString("%1").arg( err.subShapeID );
2336 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2337 else tbl->item( row, COL_SHAPEID )->setText( text );
2339 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2340 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2341 else tbl->item( row, COL_SHAPE )->setText( text );
2343 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2344 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2345 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2347 text = err.hasBadMesh ? "hasBadMesh" : "";
2348 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2349 else tbl->item( row, COL_BAD_MESH )->setText( text );
2350 if ( err.hasBadMesh ) hasBadMesh = true;
2352 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2353 tbl->resizeRowToContents( row );
2355 tbl->resizeColumnToContents( COL_ALGO );
2356 tbl->resizeColumnToContents( COL_SHAPE );
2357 tbl->setWordWrap( true );
2361 aCompDlg->myBadMeshBtn->show();
2362 aCompDlg->myBadMeshToGroupBtn->show();
2366 aCompDlg->myBadMeshBtn->hide();
2367 aCompDlg->myBadMeshToGroupBtn->hide();
2369 tbl->setCurrentCell(0,0);
2370 currentCellChanged(); // to update buttons
2373 // show dialog and wait, because Compute can be invoked from Preview operation
2374 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2379 //================================================================================
2381 * \brief Gets dialog of evaluate operation
2382 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2384 //================================================================================
2386 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2390 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2391 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2392 // connect signals and slots
2393 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2394 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2395 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2396 QTableWidget* aTable = me->table();
2397 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2398 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));