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 bool toDisplay = false;
987 std::string entry = (*anIter).second->GetID();
988 if ( !aMesh->_is_nil() ) // display only a mesh
991 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
992 if ( !anActor ) anActor = SMESH::CreateActor( entry.c_str(), /*clearLog =*/true );
993 if ( anActor ) // actor is not created for an empty mesh
995 anActor->SetEntityMode( entities );
996 //SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor ); -- 23615
1000 SMESH::UpdateView( SMESH::eDisplay, entry.c_str() );
1002 if ( SVTK_ViewWindow* vtkWnd = SMESH::GetVtkViewWindow(SMESH::GetActiveWindow() ))
1003 if ( vtkWnd->getRenderer() )
1004 vtkWnd->getRenderer()->ResetCameraClippingRange();
1006 if ( limitExceeded && !aMesh->_is_nil() )
1008 QStringList hiddenMsg;
1009 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1010 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
1011 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
1012 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
1013 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
1014 SUIT_MessageBox::warning( desktop(),
1015 tr( "SMESH_WRN_WARNING" ),
1016 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1019 arg( hiddenMsg.join(", ")));
1024 MESSAGE ( "Exception thrown during mesh visualization" );
1026 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1027 SMESH::OnVisuException();
1034 else if ( limitExceeded && !aMesh->_is_nil() )
1036 SUIT_MessageBox::warning( desktop(),
1037 tr( "SMESH_WRN_WARNING" ),
1038 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1039 arg( nbElements ).arg( limitSize ) );
1043 if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1045 SALOME_ListIO selected;
1046 selected.Append( myIObject );
1047 Sel->setSelectedObjects( selected );
1053 aMemoryReserve.release();
1055 myCompDlg->setWindowTitle
1056 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1060 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1061 bool noHypoError = ( aHypErrors.isEmpty() );
1063 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1064 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1066 bool isShowResultDlg = true;
1067 switch( aNotifyMode ) {
1068 case 0: // show the mesh computation result dialog NEVER
1069 isShowResultDlg = false;
1072 case 1: // show the mesh computation result dialog if there are some errors
1073 if ( memoryLack || !noCompError || !noHypoError )
1074 isShowResultDlg = true;
1077 isShowResultDlg = false;
1081 default: // show the result dialog after each mesh computation
1082 isShowResultDlg = true;
1086 if ( isShowResultDlg )
1087 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1090 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1091 const bool theNoCompError,
1092 SMESH::compute_error_array_var& theCompErrors,
1093 const bool theNoHypoError,
1094 const QString& theHypErrors )
1096 bool hasShape = myMesh->HasShapeToMesh();
1097 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1098 aCompDlg->myMemoryLackGroup->hide();
1100 if ( theMemoryLack )
1102 aCompDlg->myMemoryLackGroup->show();
1103 aCompDlg->myFullInfo->hide();
1104 aCompDlg->myBriefInfo->hide();
1105 aCompDlg->myHypErrorGroup->hide();
1106 aCompDlg->myCompErrorGroup->hide();
1108 else if ( theNoCompError && theNoHypoError )
1110 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1111 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1112 aCompDlg->myFullInfo->show();
1113 aCompDlg->myBriefInfo->hide();
1114 aCompDlg->myHypErrorGroup->hide();
1115 aCompDlg->myCompErrorGroup->hide();
1119 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1120 for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1121 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1122 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1124 // full or brief mesh info
1125 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1126 if ( onlyWarnings ) {
1127 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1128 aCompDlg->myFullInfo->show();
1129 aCompDlg->myBriefInfo->hide();
1131 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1132 aCompDlg->myBriefInfo->show();
1133 aCompDlg->myFullInfo->hide();
1136 // pbs of hypo definitions
1137 if ( theNoHypoError ) {
1138 aCompDlg->myHypErrorGroup->hide();
1140 aCompDlg->myHypErrorGroup->show();
1141 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1145 if ( theNoCompError )
1147 aCompDlg->myCompErrorGroup->hide();
1151 aCompDlg->myCompErrorGroup->show();
1154 aCompDlg->myWarningLabel->show();
1156 aCompDlg->myWarningLabel->hide();
1159 aCompDlg->myPublishBtn->hide();
1160 aCompDlg->myShowBtn->hide();
1163 aCompDlg->myPublishBtn->show();
1164 aCompDlg->myShowBtn->show();
1167 // fill table of errors
1168 QTableWidget* tbl = aCompDlg->myTable;
1169 tbl->setRowCount( theCompErrors->length() );
1170 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1171 else tbl->showColumn( COL_SHAPE );
1172 tbl->setColumnWidth( COL_ERROR, 200 );
1174 bool hasBadMesh = false;
1175 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1177 SMESH::ComputeError & err = theCompErrors[ row ];
1179 QString text = err.algoName.in();
1180 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1181 else tbl->item( row, COL_ALGO )->setText( text );
1183 text = SMESH::errorText( err.code, err.comment.in() );
1184 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1185 else tbl->item( row, COL_ERROR )->setText( text );
1187 text = QString("%1").arg( err.subShapeID );
1188 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1189 else tbl->item( row, COL_SHAPEID )->setText( text );
1191 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1192 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1193 else tbl->item( row, COL_SHAPE )->setText( text );
1195 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1196 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1197 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1199 text = err.hasBadMesh ? "hasBadMesh" : "";
1200 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1201 else tbl->item( row, COL_BAD_MESH )->setText( text );
1202 if ( err.hasBadMesh ) hasBadMesh = true;
1204 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1205 tbl->resizeRowToContents( row );
1207 tbl->resizeColumnToContents( COL_ALGO );
1208 tbl->resizeColumnToContents( COL_SHAPE );
1209 tbl->setWordWrap( true );
1212 aCompDlg->myBadMeshBtn->show();
1213 aCompDlg->myBadMeshToGroupBtn->show();
1216 aCompDlg->myBadMeshBtn->hide();
1217 aCompDlg->myBadMeshToGroupBtn->hide();
1219 tbl->setCurrentCell(0,0);
1220 currentCellChanged(); // to update buttons
1223 // show dialog and wait, because Compute can be invoked from Preview operation
1224 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1228 //================================================================================
1230 * \brief Stops operation
1232 //================================================================================
1234 void SMESHGUI_BaseComputeOp::stopOperation()
1236 SMESHGUI_Operation::stopOperation();
1237 if ( myTShapeDisplayer )
1238 myTShapeDisplayer->SetVisibility( false );
1239 if ( myBadMeshDisplayer ) {
1240 myBadMeshDisplayer->SetVisibility( false );
1241 // delete it in order not to have problems at its destruction when the viewer
1242 // where it worked is dead due to e.g. study closing
1243 delete myBadMeshDisplayer;
1244 myBadMeshDisplayer = 0;
1246 myIObject.Nullify();
1249 //================================================================================
1251 * \brief publish selected sub-shape
1253 //================================================================================
1255 void SMESHGUI_BaseComputeOp::onPublishShape()
1257 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1258 GEOM::GEOM_Object_var meshShape = myMesh->GetShapeToMesh();
1260 QStringList entryList;
1262 SMESH::getSelectedRows( table(), rows );
1264 foreach ( row, rows )
1266 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1267 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1268 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1270 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1272 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1273 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( myMainShape,
1274 name.toUtf8().data(),
1275 GEOM::GEOM_Object::_nil());
1276 // look for myMainShape in the table
1277 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1278 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1279 if ( so->_is_nil() ) {
1280 CORBA::String_var name = so->GetName();
1281 CORBA::String_var entry = so->GetID();
1282 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1283 table()->item( r, COL_SHAPE )->setText( shapeText );
1284 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1289 if ( curSub == 1 ) continue;
1291 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1292 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( shape,
1293 name.toUtf8().data(), myMainShape);
1294 if ( !so->_is_nil() ) {
1295 CORBA::String_var name = so->GetName();
1296 CORBA::String_var entry = so->GetID();
1297 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1298 table()->item( row, COL_SHAPE )->setText( shapeText );
1299 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1300 entryList.push_back( entry.in() );
1304 getSMESHGUI()->getApp()->updateObjectBrowser();
1305 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1307 currentCellChanged(); // to update buttons
1310 //================================================================================
1312 * \brief show mesh elements preventing computation of a submesh of current row
1314 //================================================================================
1316 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1318 myTShapeDisplayer->SetVisibility( false );
1320 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1321 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1323 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1324 SMESHGUI* gui = getSMESHGUI();
1325 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1326 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1327 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1328 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1329 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1330 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1331 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1332 vtkProperty* prop = vtkProperty::New();
1333 prop->SetLineWidth( aLineWidth * 3 );
1334 prop->SetPointSize( aPointSize * 3 );
1335 prop->SetColor( 250, 0, 250 );
1336 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1337 myBadMeshDisplayer->SetData( aMeshData.in() );
1343 //================================================================================
1345 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1347 //================================================================================
1349 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1352 SMESH::getSelectedRows( table(), rows );
1354 foreach ( row, rows )
1356 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1358 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1359 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1360 if ( grName.isEmpty() ) grName = "bad mesh";
1361 else grName = "bad mesh of " + grName;
1362 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1363 SMESH::ListOfGroups_var groups
1364 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toUtf8().data()) );
1365 update( UF_ObjBrowser | UF_Model );
1366 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1368 QStringList anEntryList;
1369 for ( size_t i = 0; i < groups->length(); ++i )
1370 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1371 anEntryList.append( so->GetID().c_str() );
1373 if ( !anEntryList.isEmpty())
1374 anApp->browseObjects( anEntryList, true, false );
1380 //================================================================================
1382 * \brief SLOT called when a selected cell in table() changed
1384 //================================================================================
1386 void SMESHGUI_BaseComputeOp::currentCellChanged()
1388 myTShapeDisplayer->SetVisibility( false );
1389 if ( myBadMeshDisplayer )
1390 myBadMeshDisplayer->SetVisibility( false );
1392 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1394 int nbSelected = SMESH::getSelectedRows( table(), rows );
1396 foreach ( row, rows )
1398 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1399 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1400 if ( hasData && !isPublished )
1401 publishEnable = true;
1403 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1404 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1406 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1413 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1416 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1417 myCompDlg->myShowBtn ->setEnabled( showEnable );
1418 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1419 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1422 //================================================================================
1424 * \brief update preview
1426 //================================================================================
1428 void SMESHGUI_BaseComputeOp::onPreviewShape()
1430 if ( myTShapeDisplayer )
1432 SUIT_OverrideCursor aWaitCursor;
1434 SMESH::getSelectedRows( table(), rows );
1436 bool showOnly = true;
1438 foreach ( row, rows )
1440 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1442 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1446 currentCellChanged(); // to update buttons
1450 //================================================================================
1454 //================================================================================
1456 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1460 delete myTShapeDisplayer;
1461 if ( myBadMeshDisplayer )
1462 delete myBadMeshDisplayer;
1465 //================================================================================
1467 * \brief Gets dialog of compute operation
1468 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1470 //================================================================================
1472 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1476 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1477 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1478 // connect signals and slots
1479 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1480 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1481 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1482 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1484 QTableWidget* aTable = me->table();
1485 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1486 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1491 //================================================================================
1493 * \brief returns from compute mesh result dialog
1495 //================================================================================
1497 bool SMESHGUI_BaseComputeOp::onApply()
1502 //================================================================================
1504 * \brief Return a table
1506 //================================================================================
1508 QTableWidget* SMESHGUI_BaseComputeOp::table()
1510 return myCompDlg->myTable;
1514 //================================================================================
1516 * \brief Constructor
1518 //================================================================================
1520 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1521 : SMESHGUI_BaseComputeOp()
1523 myHelpFileName = "constructing_meshes.html#compute-anchor";
1527 //================================================================================
1531 //================================================================================
1533 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1537 //================================================================================
1539 * \brief perform it's intention action: compute mesh
1541 //================================================================================
1543 void SMESHGUI_ComputeOp::startOperation()
1545 SMESHGUI_BaseComputeOp::startOperation();
1546 if (myMesh->_is_nil())
1551 //================================================================================
1553 * \brief check the same operations on the same mesh
1555 //================================================================================
1557 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1559 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1561 if ( !myMesh->_is_nil() && baseOp ) {
1562 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1563 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1568 //================================================================================
1570 * \brief Gets dialog of this operation
1571 * \retval LightApp_Dialog* - pointer to dialog of this operation
1573 //================================================================================
1575 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1577 return computeDlg();
1580 //================================================================================
1582 * \brief Constructor
1584 //================================================================================
1586 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1587 : SMESHGUI_BaseComputeOp(),
1590 myPreviewDisplayer( 0 ),
1595 //================================================================================
1599 //================================================================================
1601 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1608 if ( myPreviewDisplayer )
1609 delete myPreviewDisplayer;
1610 myPreviewDisplayer = 0;
1613 //================================================================================
1615 * \brief Gets current dialog of this operation
1616 * \retval LightApp_Dialog* - pointer to dialog of this operation
1618 //================================================================================
1620 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1625 //================================================================================
1627 * \brief perform it's intention action: prepare data
1629 //================================================================================
1631 void SMESHGUI_PrecomputeOp::startOperation()
1633 myHelpFileName = "constructing_meshes.html#preview-anchor"; // other anchor onCompute()
1637 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1640 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1641 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1642 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1644 myActiveDlg = myDlg;
1646 // connect signal to compute dialog. which will be shown after Compute mesh operation
1647 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1650 // disconnect signals
1651 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1652 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1653 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1654 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1655 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1658 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1659 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1660 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1661 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1662 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1663 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1664 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1665 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1666 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1667 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1670 SMESHGUI_BaseComputeOp::startOperation();
1671 if (myMesh->_is_nil())
1674 if (myDlg->getPreviewMode() == -1)
1676 // nothing to preview
1677 SUIT_MessageBox::warning(desktop(),
1678 tr("SMESH_WRN_WARNING"),
1679 tr("SMESH_WRN_NOTHING_PREVIEW"));
1684 // disconnect slot from preview dialog to have Apply from results of compute operation only
1685 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1686 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1691 //================================================================================
1693 * \brief Stops operation
1695 //================================================================================
1697 void SMESHGUI_PrecomputeOp::stopOperation()
1699 if ( myPreviewDisplayer )
1701 myPreviewDisplayer->SetVisibility( false );
1702 delete myPreviewDisplayer;
1703 myPreviewDisplayer = 0;
1705 myMapShapeId.clear();
1706 SMESHGUI_BaseComputeOp::stopOperation();
1709 //================================================================================
1711 * \brief reinitialize dialog after operaiton become active again
1713 //================================================================================
1715 void SMESHGUI_PrecomputeOp::resumeOperation()
1717 if ( myActiveDlg == myDlg )
1719 SMESHGUI_BaseComputeOp::resumeOperation();
1722 //================================================================================
1724 * \brief perform it's intention action: reinitialise dialog
1726 //================================================================================
1728 void SMESHGUI_PrecomputeOp::initDialog()
1732 QMap<int, int> modeMap;
1733 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( myIObject->getEntry() );
1734 getAssignedAlgos( pMesh, modeMap );
1735 if ( modeMap.contains( SMESH::DIM_3D ) )
1737 if ( modeMap.contains( SMESH::DIM_2D ) )
1738 modes.append( SMESH::DIM_2D );
1739 if ( modeMap.contains( SMESH::DIM_1D ) )
1740 modes.append( SMESH::DIM_1D );
1742 else if ( modeMap.contains( SMESH::DIM_2D ) )
1744 if ( modeMap.contains( SMESH::DIM_1D ) )
1745 modes.append( SMESH::DIM_1D );
1748 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1749 myOrderMgr->SetMesh( myMesh );
1750 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1751 myDlg->getMeshOrderBox()->setVisible(isOrder);
1757 myDlg->setPreviewModes( modes );
1760 //================================================================================
1762 * \brief detect assigned mesh algorithms
1764 //================================================================================
1766 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1767 QMap<int,int>& theModeMap)
1769 if ( !theMesh ) return;
1771 _PTR(SObject) aHypFolder;
1772 _PTR(GenericAttribute) anAttr;
1773 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1774 if ( theMesh->FindSubObject( aPart, aHypFolder ))
1776 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1777 for ( ; anIter->More(); anIter->Next() )
1779 _PTR(SObject) anObj = anIter->Value();
1780 _PTR(SObject) aRefObj;
1781 if ( anObj->ReferencedObject( aRefObj ) )
1786 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1788 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1789 if ( CORBA::is_nil( aVar ) )
1792 SMESH::SMESH_Algo_var algo;
1793 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1796 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1797 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1798 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1801 if ( !algo->_is_nil() )
1803 theModeMap[ dim ] = 0;
1804 if ( theModeMap.size() == 3 )
1814 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1816 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1819 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1820 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1822 _PTR(SObject) anObj = anIter->Value();
1823 _PTR(SObject) aRefObj;
1824 if ( anObj->ReferencedObject( aRefObj ) )
1829 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1831 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1832 if ( CORBA::is_nil( aVar ) )
1835 SMESH::SMESH_Algo_var algo;
1836 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1839 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1840 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1841 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1844 if ( !algo->_is_nil() )
1846 theModeMap[ dim ] = 0;
1847 if ( theModeMap.size() == 3 )
1857 //================================================================================
1859 * \brief perform it's intention action: compute mesh
1861 //================================================================================
1863 void SMESHGUI_PrecomputeOp::onCompute()
1866 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1867 myOrderMgr->SetMeshOrder();
1868 myMapShapeId.clear();
1869 myActiveDlg = computeDlg();
1870 myHelpFileName = "constructing_meshes.html#compute-anchor";
1874 //================================================================================
1876 * \brief perform it's intention action: compute mesh
1878 //================================================================================
1880 void SMESHGUI_PrecomputeOp::onCancel()
1882 QObject* curDlg = sender();
1883 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1885 // return from error messages
1890 bool isRestoreOrder = false;
1891 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1893 // ask to remove already computed mesh elements
1894 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1895 tr( "CLEAR_SUBMESH_QUESTION" ),
1896 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1898 // remove all submeshes for collected shapes
1899 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1900 for ( ; it != myMapShapeId.constEnd(); ++it )
1901 myMesh->ClearSubMesh( it.key() );
1902 isRestoreOrder = true;
1906 // return previous mesh order
1907 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1908 if (!isRestoreOrder)
1910 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1911 tr( "SMESH_REJECT_MESH_ORDER" ),
1912 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1914 myOrderMgr->SetMeshOrder(myPrevOrder);
1920 myMapShapeId.clear();
1921 SMESHGUI_BaseComputeOp::onCancel();
1924 //================================================================================
1926 * \brief perform it's intention action: preview mesh
1928 //================================================================================
1930 void SMESHGUI_PrecomputeOp::onPreview()
1932 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1935 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1939 // set modified submesh priority if any
1940 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1941 myOrderMgr->SetMeshOrder();
1943 // Compute preview of mesh,
1944 // i.e. compute mesh till indicated dimension
1945 int dim = myDlg->getPreviewMode();
1947 SMESH::MemoryReserve aMemoryReserve;
1949 SMESH::compute_error_array_var aCompErrors;
1952 bool computeFailed = true, memoryLack = false;
1954 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1955 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1957 SMESHGUI* gui = getSMESHGUI();
1958 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1959 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1960 if ( errors->length() > 0 ) {
1961 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1964 SUIT_OverrideCursor aWaitCursor;
1966 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1967 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1968 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1970 SMESH::long_array_var aShapesId = new SMESH::long_array();
1974 SMESH::MeshPreviewStruct_var previewData =
1975 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1977 if ( & previewData.in() && previewData->nodesXYZ.length() > 0 )
1979 computeFailed = false;
1980 myPreviewDisplayer->SetData( previewData );
1981 // append shape indices with computed mesh entities
1982 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1983 myMapShapeId[ aShapesId[ i ] ] = 0;
1986 myPreviewDisplayer->SetVisibility(false);
1988 catch(const SALOME::SALOME_Exception & S_ex){
1990 myPreviewDisplayer->SetVisibility(false);
1995 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1996 // check if there are memory problems
1997 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1998 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
2000 catch(const SALOME::SALOME_Exception & S_ex){
2005 aMemoryReserve.release();
2007 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2008 bool noHypoError = ( aHypErrors.isEmpty() );
2010 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2011 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2013 bool isShowError = true;
2014 switch( aNotifyMode ) {
2015 case 0: // show the mesh computation result dialog NEVER
2016 isShowError = false;
2018 case 1: // show the mesh computation result dialog if there are some errors
2019 default: // show the result dialog after each mesh computation
2020 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2021 isShowError = false;
2025 aWaitCursor.suspend();
2030 aCompDlg->setWindowTitle
2031 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2032 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2037 //================================================================================
2039 * \brief Constructor
2041 //================================================================================
2043 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2044 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2047 setWindowTitle( tr( "CAPTION" ) );
2049 setButtonText( OK, tr( "COMPUTE" ) );
2050 QFrame* main = mainFrame();
2051 main->setMinimumWidth( 300 );
2053 QVBoxLayout* layout = new QVBoxLayout( main );
2055 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2056 layout->addWidget(myOrderBox);
2058 QFrame* frame = new QFrame( main );
2059 layout->setMargin(0); layout->setSpacing(0);
2060 layout->addWidget( frame );
2062 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2063 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2065 myPreviewMode = new QtxComboBox( frame );
2066 frameLay->addWidget( myPreviewMode );
2068 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2069 frameLay->addWidget( myPreviewBtn );
2071 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2074 //================================================================================
2078 //================================================================================
2080 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2084 //================================================================================
2086 * \brief Sets available preview modes
2088 //================================================================================
2090 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2092 myPreviewMode->clear();
2093 QList<int>::const_iterator it = theModes.constBegin();
2094 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2096 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2097 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2098 myPreviewMode->setId( i, *it );
2100 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2103 //================================================================================
2105 * \brief Returns current preview mesh mode
2107 //================================================================================
2109 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2111 return myPreviewMode->currentId().toInt();
2114 //================================================================================
2116 * \brief Returns current preview mesh mode
2118 //================================================================================
2120 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2126 //================================================================================
2128 * \brief Constructor
2130 //================================================================================
2132 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2133 : SMESHGUI_BaseComputeOp()
2135 myHelpFileName = "constructing_meshes.html#evaluate-anchor";
2139 //================================================================================
2143 //================================================================================
2145 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2149 //================================================================================
2151 * \brief perform it's intention action: compute mesh
2153 //================================================================================
2155 void SMESHGUI_EvaluateOp::startOperation()
2157 SMESHGUI_BaseComputeOp::evaluateDlg();
2158 SMESHGUI_BaseComputeOp::startOperation();
2159 if (myMesh->_is_nil())
2164 //================================================================================
2166 * \brief Gets dialog of this operation
2167 * \retval LightApp_Dialog* - pointer to dialog of this operation
2169 //================================================================================
2171 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2173 return evaluateDlg();
2176 //================================================================================
2178 * \brief evaluateMesh()
2180 //================================================================================
2182 void SMESHGUI_BaseComputeOp::evaluateMesh()
2186 SMESH::MemoryReserve aMemoryReserve;
2188 SMESH::compute_error_array_var aCompErrors;
2191 bool evaluateFailed = true, memoryLack = false;
2192 SMESH::long_array_var aRes;
2194 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2195 if ( !aMeshSObj ) // IPAL21340
2198 bool hasShape = myMesh->HasShapeToMesh();
2199 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2202 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2203 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2204 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2205 if ( errors->length() > 0 ) {
2206 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2208 SUIT_OverrideCursor aWaitCursor;
2211 aRes = gen->Evaluate(myMesh, myMainShape);
2213 catch(const SALOME::SALOME_Exception & S_ex){
2219 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2221 catch(const SALOME::SALOME_Exception & S_ex){
2227 aMemoryReserve.release();
2229 evaluateFailed = ( aCompErrors->length() > 0 );
2230 myCompDlg->setWindowTitle
2231 ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2235 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2236 bool noHypoError = ( aHypErrors.isEmpty() );
2238 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2239 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2241 bool isShowResultDlg = true;
2243 //switch( aNotifyMode ) {
2244 //case 0: // show the mesh computation result dialog NEVER
2245 //isShowResultDlg = false;
2248 //case 1: // show the mesh computation result dialog if there are some errors
2249 //if ( memoryLack || !noHypoError )
2250 // isShowResultDlg = true;
2253 // isShowResultDlg = false;
2257 //default: // show the result dialog after each mesh computation
2258 //isShowResultDlg = true;
2262 if ( isShowResultDlg )
2263 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2264 noHypoError, aHypErrors);
2268 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2269 const bool theMemoryLack,
2270 const bool theNoCompError,
2271 SMESH::compute_error_array_var& theCompErrors,
2272 const bool theNoHypoError,
2273 const QString& theHypErrors)
2275 bool hasShape = myMesh->HasShapeToMesh();
2276 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2277 aCompDlg->myMemoryLackGroup->hide();
2279 if ( theMemoryLack )
2281 aCompDlg->myMemoryLackGroup->show();
2282 aCompDlg->myFullInfo->hide();
2283 aCompDlg->myBriefInfo->hide();
2284 aCompDlg->myHypErrorGroup->hide();
2285 aCompDlg->myCompErrorGroup->hide();
2287 else if ( theNoCompError && theNoHypoError )
2289 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2290 aCompDlg->myFullInfo->show();
2291 aCompDlg->myBriefInfo->hide();
2292 aCompDlg->myHypErrorGroup->hide();
2293 aCompDlg->myCompErrorGroup->hide();
2297 QTableWidget* tbl = aCompDlg->myTable;
2298 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2299 aCompDlg->myBriefInfo->show();
2300 aCompDlg->myFullInfo->hide();
2302 if ( theNoHypoError ) {
2303 aCompDlg->myHypErrorGroup->hide();
2306 aCompDlg->myHypErrorGroup->show();
2307 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2310 if ( theNoCompError ) {
2311 aCompDlg->myCompErrorGroup->hide();
2314 aCompDlg->myCompErrorGroup->show();
2316 aCompDlg->myPublishBtn->hide();
2317 aCompDlg->myShowBtn->hide();
2319 // fill table of errors
2320 tbl->setRowCount( theCompErrors->length() );
2321 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2322 else tbl->showColumn( COL_SHAPE );
2323 tbl->setColumnWidth( COL_ERROR, 200 );
2325 bool hasBadMesh = false;
2326 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2328 SMESH::ComputeError & err = theCompErrors[ row ];
2330 QString text = err.algoName.in();
2331 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2332 else tbl->item( row, COL_ALGO )->setText( text );
2334 text = SMESH::errorText( err.code, err.comment.in() );
2335 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2336 else tbl->item( row, COL_ERROR )->setText( text );
2338 text = QString("%1").arg( err.subShapeID );
2339 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2340 else tbl->item( row, COL_SHAPEID )->setText( text );
2342 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2343 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2344 else tbl->item( row, COL_SHAPE )->setText( text );
2346 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2347 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2348 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2350 text = err.hasBadMesh ? "hasBadMesh" : "";
2351 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2352 else tbl->item( row, COL_BAD_MESH )->setText( text );
2353 if ( err.hasBadMesh ) hasBadMesh = true;
2355 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2356 tbl->resizeRowToContents( row );
2358 tbl->resizeColumnToContents( COL_ALGO );
2359 tbl->resizeColumnToContents( COL_SHAPE );
2360 tbl->setWordWrap( true );
2364 aCompDlg->myBadMeshBtn->show();
2365 aCompDlg->myBadMeshToGroupBtn->show();
2369 aCompDlg->myBadMeshBtn->hide();
2370 aCompDlg->myBadMeshToGroupBtn->hide();
2372 tbl->setCurrentCell(0,0);
2373 currentCellChanged(); // to update buttons
2376 // show dialog and wait, because Compute can be invoked from Preview operation
2377 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2382 //================================================================================
2384 * \brief Gets dialog of evaluate operation
2385 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2387 //================================================================================
2389 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2393 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2394 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2395 // connect signals and slots
2396 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2397 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2398 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2399 QTableWidget* aTable = me->table();
2400 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2401 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));