1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_ComputeDlg.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
24 #include "SMESHGUI_ComputeDlg.h"
26 #include "SMDS_Mesh.hxx"
27 #include "SMDS_SetIterator.hxx"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_HypothesesUtils.h"
31 #include "SMESHGUI_MeshEditPreview.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33 #include "SMESHGUI_MeshOrderDlg.h"
34 #include "SMESHGUI_MeshOrderOp.h"
35 #include "SMESHGUI_MeshUtils.h"
36 #include "SMESHGUI_VTKUtils.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_ActorUtils.h"
40 // SALOME GEOM includes
42 #include <GEOM_Actor.h>
43 #include <GEOM_wrap.hxx>
45 // SALOME GUI includes
46 #include <LightApp_SelectionMgr.h>
47 #include <LightApp_UpdateFlags.h>
48 #include <QtxComboBox.h>
49 #include <SALOME_ListIO.hxx>
50 #include <SUIT_Desktop.h>
51 #include <SUIT_MessageBox.h>
52 #include <SUIT_OverrideCursor.h>
53 #include <SUIT_ResourceMgr.h>
54 #include <SUIT_Session.h>
55 #include <SVTK_ViewModel.h>
56 #include <SVTK_ViewWindow.h>
57 #include <SalomeApp_Application.h>
59 // SALOME KERNEL includes
60 #include <SALOMEDS_SObject.hxx>
61 #include <SALOMEDSClient_SObject.hxx>
62 #include <SALOMEDS_wrap.hxx>
63 #include "utilities.h"
65 #include CORBA_SERVER_HEADER(SMESH_Group)
68 #include <BRepBndLib.hxx>
69 #include <BRepMesh_IncrementalMesh.hxx>
70 #include <BRep_Tool.hxx>
71 #include <Bnd_Box.hxx>
72 #include <Poly_Triangulation.hxx>
74 #include <TopExp_Explorer.hxx>
75 #include <TopLoc_Location.hxx>
76 #include <TopTools_IndexedMapOfShape.hxx>
79 #include <Standard_ErrorHandler.hxx>
83 #include <QPushButton>
85 #include <QRadioButton>
86 #include <QTableWidget>
87 #include <QHeaderView>
88 #include <QGridLayout>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QButtonGroup>
92 #include <QCloseEvent>
93 #include <QTimerEvent>
94 #include <QProgressBar>
97 #include <vtkProperty.h>
104 #include <sys/sysinfo.h>
110 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
111 #define __SHAPE_RGB__ 250, 0, 250
114 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
117 //using namespace SMESH;
121 //=============================================================================
123 * \brief Allocate some memory at construction and release it at destruction.
124 * Is used to be able to continue working after mesh generation or visualization
125 * break due to lack of memory
127 //=============================================================================
132 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
133 void release() { delete [] myBuf; myBuf = 0; }
134 ~MemoryReserve() { release(); }
137 // =========================================================================================
139 * \brief Class showing shapes without publishing
141 // =========================================================================================
143 class TShapeDisplayer
146 // -----------------------------------------------------------------------
147 TShapeDisplayer(): myViewWindow(0)
149 myProperty = vtkProperty::New();
150 myProperty->SetRepresentationToWireframe();
151 myProperty->SetColor( __SHAPE_RGB__ );
152 myProperty->SetAmbientColor( __SHAPE_RGB__ );
153 myProperty->SetDiffuseColor( __SHAPE_RGB__ );
154 //myProperty->SetSpecularColor( __SHAPE_RGB__ );
155 myProperty->SetLineWidth( 5 );
157 // -----------------------------------------------------------------------
161 myProperty->Delete();
163 // -----------------------------------------------------------------------
166 if ( hasViewWindow() ) {
167 TActorIterator actorIt = actorIterator();
168 while ( actorIt.more() )
169 if (VTKViewer_Actor* anActor = actorIt.next()) {
170 myViewWindow->RemoveActor( anActor );
174 myIndexToShape.Clear();
176 myShownActors.clear();
179 // -----------------------------------------------------------------------
180 void SetVisibility (bool theVisibility)
182 TActorIterator actorIt = shownIterator();
183 while ( actorIt.more() )
184 if (VTKViewer_Actor* anActor = actorIt.next())
185 anActor->SetVisibility(theVisibility);
186 SMESH::RepaintCurrentView();
188 // -----------------------------------------------------------------------
189 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
191 std::string mainEntry;
192 if ( !aMainShape->_is_nil() )
193 mainEntry = aMainShape->GetStudyEntry();
194 return ( myMainEntry == mainEntry &&
195 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
197 // -----------------------------------------------------------------------
198 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
200 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
201 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
202 std::string mainEntry;
203 if ( !aMainShape->_is_nil() )
204 mainEntry = aMainShape->GetStudyEntry();
205 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
208 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
209 checkTriangulation( aShape );
210 TopExp::MapShapes(aShape, myIndexToShape);
211 myActors.resize( myIndexToShape.Extent(), 0 );
212 myShownActors.reserve( myIndexToShape.Extent() );
214 myMainEntry = mainEntry;
215 myViewWindow = aViewWindow;
217 if ( only ) { // hide shown actors
218 TActorIterator actorIt = shownIterator();
219 while ( actorIt.more() )
220 if (VTKViewer_Actor* anActor = actorIt.next())
221 anActor->SetVisibility(false);
222 myShownActors.clear();
224 // find actors to show
225 TopoDS_Shape aShape = myIndexToShape( subShapeID );
226 if ( !aShape.IsNull() ) {
227 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
228 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
229 //checkTriangulation( exp.Current() );
230 if ( GEOM_Actor* anActor = getActor( exp.Current() ) ) {
231 int UNbIsos = resMgr->integerValue( "Geometry", "iso_number_u", 1);
232 int VNbIsos = resMgr->integerValue( "Geometry", "iso_number_v", 1);
233 int aNbIsos[2] = { UNbIsos ? UNbIsos : 1, VNbIsos ? VNbIsos : 1 };
234 anActor->SetNbIsos( aNbIsos );
235 myShownActors.push_back( anActor );
238 if ( type == TopAbs_FACE ) {
239 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
240 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
241 if ( !BRep_Tool::Degenerated( edge ))
242 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
243 myShownActors.push_back( anActor );
247 myBuiltSubs.insert( subShapeID );
250 // -----------------------------------------------------------------------
254 typedef std::vector<GEOM_Actor*> TActorVec;
256 TActorVec myShownActors;
257 TopTools_IndexedMapOfShape myIndexToShape;
258 std::string myMainEntry;
259 SVTK_ViewWindow* myViewWindow;
260 vtkProperty* myProperty;
261 std::set<int> myBuiltSubs;
263 // -----------------------------------------------------------------------
264 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
265 TActorIterator actorIterator() {
266 return TActorIterator( myActors.begin(), myActors.end() );
268 TActorIterator shownIterator() {
269 return TActorIterator( myShownActors.begin(), myShownActors.end() );
271 // -----------------------------------------------------------------------
272 GEOM_Actor* getActor(const TopoDS_Shape& shape)
274 int index = myIndexToShape.FindIndex( shape ) - 1;
275 if ( index < 0 || index >= (int) myActors.size() )
277 GEOM_Actor* & actor = myActors[ index ];
279 actor = GEOM_Actor::New();
281 actor->SetShape(shape,0,0);
282 // actor->SetProperty(myProperty);
283 // actor->SetShadingProperty(myProperty);
284 // actor->SetWireframeProperty(myProperty);
285 // actor->SetPreviewProperty(myProperty);
286 actor->PickableOff();
288 actor->SetWidth( myProperty->GetLineWidth() );
289 actor->SetIsosWidth( myProperty->GetLineWidth() );
290 actor->SetIsosColor( __SHAPE_RGB__ );
291 actor->SetColor( __SHAPE_RGB__ );
292 // if ( shape.ShapeType() == TopAbs_EDGE )
293 // actor->SubShapeOn();
294 myViewWindow->AddActor( actor );
299 // -----------------------------------------------------------------------
300 void checkTriangulation(const TopoDS_Shape& shape)
302 TopLoc_Location aLoc;
303 Standard_Boolean alreadymesh = Standard_True;
304 TopExp_Explorer ex(shape, TopAbs_FACE);
306 for ( ; ex.More(); ex.Next()) {
307 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
308 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
309 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
312 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
313 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
314 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
315 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
317 if (alreadymesh) return;
318 // Compute default deflection
320 BRepBndLib::Add(shape, B);
321 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
322 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
323 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
324 BRepMesh_IncrementalMesh MESH(shape,deflection);
326 // -----------------------------------------------------------------------
327 bool hasViewWindow() const
329 if ( !myViewWindow ) return false;
331 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
332 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
338 // =========================================================================================
340 * \brief Return text describing an error
342 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
343 QString errorText(int errCode, const char* comment)
347 CASE2TEXT( COMPERR_OK );
348 CASE2TEXT( COMPERR_BAD_INPUT_MESH );
349 CASE2TEXT( COMPERR_STD_EXCEPTION );
350 CASE2TEXT( COMPERR_OCC_EXCEPTION );
351 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
352 CASE2TEXT( COMPERR_EXCEPTION );
353 CASE2TEXT( COMPERR_MEMORY_PB );
354 CASE2TEXT( COMPERR_BAD_SHAPE );
355 CASE2TEXT( COMPERR_CANCELED );
356 CASE2TEXT( COMPERR_NO_MESH_ON_SHAPE );
357 CASE2TEXT( COMPERR_BAD_PARMETERS );
358 case SMESH::COMPERR_ALGO_FAILED:
359 if ( strlen(comment) == 0 )
360 text = QObject::tr("COMPERR_ALGO_FAILED");
362 case SMESH::COMPERR_WARNING:
363 text = QObject::tr( (comment && strlen(comment)) ? "COMPERR_WARNING" : "COMPERR_UNKNOWN");
366 text = QString("#%1").arg( -errCode );
368 if ( text.length() > 0 ) text += ". ";
369 return text + comment;
371 // -----------------------------------------------------------------------
373 * \brief Return SO of a sub-shape
375 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
377 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
378 if ( subShapeID == 1 || !so )
380 _PTR(ChildIterator) it;
381 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
382 it = study->NewChildIterator(so);
385 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
386 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
387 if ( !geom->_is_nil() ) {
388 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
389 if ( list->length() == 1 && list[0] == subShapeID )
391 GEOM::GEOM_Object_var mainGO = geom->GetMainShape();
392 if ( aMainShape->IsSame( mainGO ))
400 // -----------------------------------------------------------------------
402 * \brief Return sub-shape by ID. WARNING: UnRegister() must be called on a result
404 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
406 GEOM::GEOM_Object_var aSubShape;
407 if ( subShapeID == 1 ) {
408 aSubShape = aMainShape;
409 aSubShape->Register();
411 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape )) {
412 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
413 aSubShape->Register();
416 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
417 // future call of UnRegister() will delete a servant of this new object
419 return aSubShape._retn();
421 // -----------------------------------------------------------------------
423 * \brief Return shape type name
425 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
426 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
429 if ( !aShape->_is_nil() ) {
430 switch ( aShape->GetShapeType() ) {
437 CASE2NAME( COMPSOLID );
438 CASE2NAME( COMPOUND );
444 // -----------------------------------------------------------------------
446 * \brief Return text describing a sub-shape
448 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
451 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape )) {
452 text = aSO->GetName().c_str();
453 text += QString(" (%1)").arg( aSO->GetID().c_str() );
456 text = QString("#%1").arg( subShapeID );
457 GEOM::GEOM_Object_wrap shape = getSubShape( subShapeID, aMainShape );
458 QString typeName = shapeTypeName( shape );
459 if ( typeName.length() )
460 text += QString(" (%1)").arg(typeName);
464 // -----------------------------------------------------------------------
466 * \brief Return a list of selected rows
468 int getSelectedRows(QTableWidget* table, QList<int>& rows)
471 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
472 QTableWidgetSelectionRange range;
473 foreach( range, selRanges )
475 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
476 if ( !rows.count( row ))
479 if ( rows.isEmpty() && table->currentRow() > -1 )
480 if ( !rows.count( table->currentRow() ))
481 rows.append( table->currentRow() );
489 // =========================================================================================
491 * \brief Dialog to compute a mesh and show computation errors
493 //=======================================================================
495 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
496 : SMESHGUI_Dialog( parent, false, true, Close | Help )
498 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
499 aDlgLay->setMargin( 0 );
500 aDlgLay->setSpacing( SPACING );
502 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
504 aDlgLay->addWidget(aMainFrame);
506 aDlgLay->setStretchFactor(aMainFrame, 1);
509 // =========================================================================================
513 //=======================================================================
515 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
519 //=======================================================================
520 // function : createMainFrame()
521 // purpose : Create frame containing dialog's fields
522 //=======================================================================
524 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
526 QFrame* aFrame = new QFrame(theParent);
528 SUIT_ResourceMgr* rm = resourceMgr();
529 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
535 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
538 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
540 QButtonGroup* aBtnGrp = new QButtonGroup(this);
541 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
542 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
544 QRadioButton* aRBut = new QRadioButton(aPixGrp);
545 aRBut->setIcon(iconCompute);
546 aRBut->setChecked(true);
547 aPixGrpLayout->addWidget(aRBut);
548 aBtnGrp->addButton(aRBut, 0);
552 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
553 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
554 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
555 myMeshName = new QLabel(nameBox);
556 nameBoxLayout->addWidget(myMeshName);
560 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
561 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
563 // Computation errors
565 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
566 myWarningLabel = new QLabel(QString("<b>%1</b>").arg(tr("COMPUTE_WARNING")), myCompErrorGroup);
567 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
568 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
569 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
570 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
571 myBadMeshToGroupBtn = new QPushButton(tr("GROUP_OF_BAD_MESH"), myCompErrorGroup);
573 //myTable->setReadOnly( true ); // VSR: check
574 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
575 myTable->hideColumn( COL_PUBLISHED );
576 myTable->hideColumn( COL_SHAPEID );
577 myTable->hideColumn( COL_BAD_MESH );
578 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
579 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
581 myTable->horizontalHeader()->setSectionResizeMode( COL_ERROR, QHeaderView::Interactive );
583 myTable->setWordWrap( true );
584 myTable->horizontalHeader()->setStretchLastSection( true );
585 myTable->setMinimumWidth( 500 );
588 headers << tr( "COL_ALGO_HEADER" );
589 headers << tr( "COL_SHAPE_HEADER" );
590 headers << tr( "COL_ERROR_HEADER" );
591 headers << tr( "COL_SHAPEID_HEADER" );
592 headers << tr( "COL_PUBLISHED_HEADER" );
594 myTable->setHorizontalHeaderLabels( headers );
597 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
598 grpLayout->setSpacing(SPACING);
599 grpLayout->setMargin(MARGIN);
600 grpLayout->addWidget( myWarningLabel, 0, 0, 1, 4 );
601 grpLayout->addWidget( myTable, 1, 0, 1, 4 );
602 grpLayout->addWidget( myShowBtn, 2, 0 );
603 grpLayout->addWidget( myPublishBtn, 2, 1 );
604 grpLayout->addWidget( myBadMeshBtn, 2, 2 );
605 grpLayout->addWidget( myBadMeshToGroupBtn, 2, 3 );
606 grpLayout->setColumnStretch( 3, 1 );
608 // Hypothesis definition errors
610 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
611 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
612 myHypErrorGroupLayout->setMargin(MARGIN);
613 myHypErrorGroupLayout->setSpacing(SPACING);
614 myHypErrorLabel = new QLabel(myHypErrorGroup);
615 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
619 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
620 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
621 myMemoryLackGroupLayout->setMargin(MARGIN);
622 myMemoryLackGroupLayout->setSpacing(SPACING);
623 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
624 QFont bold = memLackLabel->font(); bold.setBold(true);
625 memLackLabel->setFont( bold );
626 memLackLabel->setMinimumWidth(300);
627 myMemoryLackGroupLayout->addWidget(memLackLabel);
629 // add all widgets to aFrame
630 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
631 aLay->setMargin( MARGIN );
632 aLay->setSpacing( SPACING );
633 aLay->addWidget( aPixGrp );
634 aLay->addWidget( nameBox );
635 aLay->addWidget( myBriefInfo );
636 aLay->addWidget( myFullInfo );
637 aLay->addWidget( myHypErrorGroup );
638 aLay->addWidget( myCompErrorGroup );
639 aLay->addWidget( myMemoryLackGroup );
640 aLay->setStretchFactor( myCompErrorGroup, 1 );
642 ((QPushButton*) button( OK ))->setDefault( true );
647 //================================================================================
651 //================================================================================
653 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
654 : SMESHGUI_Operation(), myCompDlg( 0 )
656 myTShapeDisplayer = new SMESH::TShapeDisplayer();
657 myBadMeshDisplayer = 0;
659 //myHelpFileName = "/files/about_meshes.htm"; // V3
660 myHelpFileName = "about_meshes_page.html"; // V4
663 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
665 LightApp_SelectionMgr* Sel = selectionMgr();
666 SALOME_ListIO selected; Sel->selectedObjects( selected );
667 Handle(SALOME_InteractiveObject) anIO = selected.First();
668 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
669 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
672 //================================================================================
674 * \brief Start operation
675 * \purpose Init dialog fields, connect signals and slots, show dialog
677 //================================================================================
679 void SMESHGUI_BaseComputeOp::startOperation()
681 // create compute dialog if not created before
684 myMesh = SMESH::SMESH_Mesh::_nil();
685 myMainShape = GEOM::GEOM_Object::_nil();
686 myCurShape = GEOM::GEOM_Object::_nil();
689 LightApp_SelectionMgr *Sel = selectionMgr();
690 SALOME_ListIO selected; Sel->selectedObjects( selected );
692 int nbSel = selected.Extent();
694 SUIT_MessageBox::warning(desktop(),
695 tr("SMESH_WRN_WARNING"),
696 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
701 myIObject = selected.First();
702 CORBA::Object_var anObj = SMESH::IObjectToObject( myIObject );
704 myMesh = SMESH::SMESH_Mesh::_narrow(anObj);
705 if ( myMesh->_is_nil() )
707 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
708 if ( !aSubMesh->_is_nil() )
710 myMesh = aSubMesh->GetFather();
711 myCurShape = aSubMesh->GetSubShape();
716 myCurShape = myMesh->GetShapeToMesh();
719 if (myMesh->_is_nil()) {
720 SUIT_MessageBox::warning(desktop(),
721 tr("SMESH_WRN_WARNING"),
722 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
727 myMainShape = myMesh->GetShapeToMesh();
729 SMESHGUI_Operation::startOperation();
732 //================================================================================
733 //================================================================================
735 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
736 SMESH::SMESH_Mesh_var mesh,
737 GEOM::GEOM_Object_var mainShape)
742 myMainShape = mainShape;
745 void SMESHGUI_ComputeDlg_QThread::run()
747 myResult = myGen->Compute(myMesh, myMainShape);
750 bool SMESHGUI_ComputeDlg_QThread::result()
755 void SMESHGUI_ComputeDlg_QThread::cancel()
757 myGen->CancelCompute(myMesh, myMainShape);
760 //================================================================================
761 //================================================================================
763 SMESHGUI_ComputeDlg_QThreadQDialog::
764 SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
765 SMESH::SMESH_Gen_var gen,
766 SMESH::SMESH_Mesh_var mesh,
767 GEOM::GEOM_Object_var mainShape)
769 Qt::WindowSystemMenuHint |
770 Qt::WindowCloseButtonHint |
772 Qt::WindowMaximizeButtonHint),
773 qthread(gen, mesh, mainShape)
776 setWindowTitle(tr("TITLE"));
777 setMinimumWidth( 200 );
779 cancelButton = new QPushButton(tr("CANCEL"));
780 cancelButton->setDefault(true);
781 cancelButton->setCheckable(true);
783 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
784 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
785 nbNodesLabel = new QLabel("0", this );
786 nbElemsLabel = new QLabel("0", this );
788 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
789 freeRAMLabel = new QLabel("", this );
791 progressBar = new QProgressBar(this);
792 progressBar->setMinimum( 0 );
793 progressBar->setMaximum( 1000 );
795 QGridLayout* layout = new QGridLayout(this);
796 layout->setMargin( MARGIN );
797 layout->setSpacing( SPACING );
799 layout->addWidget(nbNodesName, row, 0);
800 layout->addWidget(nbNodesLabel, row++, 1);
801 layout->addWidget(nbElemsName, row, 0);
802 layout->addWidget(nbElemsLabel, row++, 1);
804 layout->addWidget(freeRAMName, row, 0);
805 layout->addWidget(freeRAMLabel, row++, 1);
807 layout->addWidget(progressBar, row++, 0, 1, 2);
808 layout->addWidget(cancelButton, row++, 0, 1, 2);
812 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
814 startTimer(300); // millisecs
818 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
820 return qthread.result();
823 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
826 cancelButton->setText( tr("CANCELING"));
827 cancelButton->setEnabled(false);
830 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
832 if ( !cancelButton->isChecked() ) // not yet cancelled
833 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
835 if(qthread.isFinished())
841 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
842 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
845 const int err = sysinfo( &si );
847 freeRAMLabel->setText("");
849 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
850 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
856 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
858 if(qthread.isRunning())
866 //================================================================================
868 * \brief computeMesh()
870 //================================================================================
872 void SMESHGUI_BaseComputeOp::computeMesh()
876 SMESH::MemoryReserve aMemoryReserve;
878 SMESH::compute_error_array_var aCompErrors;
881 bool computeFailed = true, memoryLack = false;
883 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
884 if ( !aMeshSObj ) // IPAL 21340
886 bool hasShape = myMesh->HasShapeToMesh();
887 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
890 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
891 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
892 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
893 if ( errors->length() > 0 ) {
894 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
896 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
897 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
898 tr( "FULL_RECOMPUTE_QUESTION" ),
899 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
901 SUIT_OverrideCursor aWaitCursor;
904 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myCurShape);
905 qthreaddialog.exec();
906 computeFailed = !qthreaddialog.result();
908 catch(const SALOME::SALOME_Exception & S_ex) {
913 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
914 // check if there are memory problems
915 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
916 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
918 catch(const SALOME::SALOME_Exception & S_ex) {
922 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
926 // NPAL16631: if ( !memoryLack )
928 _PTR(SObject) sobj = SMESH::GetActiveStudyDocument()->FindObjectID(myIObject->getEntry());
929 SMESH::ModifiedMesh( sobj,
930 !computeFailed && aHypErrors.isEmpty(),
931 myMesh->NbNodes() == 0);
932 update( UF_ObjBrowser | UF_Model );
935 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
936 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
938 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
939 int entities = SMESH_Actor::eAllEntity;
944 // List of objects that will be updated automatically
945 typedef QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > TListOf_IDSrc_SObj;
946 TListOf_IDSrc_SObj aListToUpdate;
947 SMESH::SMESH_IDSource_var aMeshObj =
948 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
949 // put Mesh into list
950 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aMeshObj, aMeshSObj ));
951 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
952 // put SubMeshes into list
953 for ( CORBA::ULong i = 0; i < aSubMeshes->length(); i++ )
955 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
956 if ( CORBA::is_nil( sm ) ) continue;
957 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
958 if ( !smSObj ) continue;
959 SMESH::SMESH_IDSource_var aSubMeshObj =
960 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
961 SMESH_Actor *anActor = SMESH::FindActorByObject( aSubMeshObj );
962 if ( anActor && anActor->GetVisibility() )
963 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aSubMeshObj, smSObj ));
965 // put Groups into list
966 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
967 for ( size_t i = 0; i < aGroups->length(); ++i )
969 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
970 if ( CORBA::is_nil( aGrp ) ) continue;
971 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
972 if ( !aStdGroup->_is_nil() ) continue; // don't update standalone groups
973 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
974 if ( !aGroupSO ) continue;
975 SMESH::SMESH_IDSource_var aGroupObj =
976 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
977 SMESH_Actor *anActor = SMESH::FindActorByObject( aGroupObj );
978 if ( anActor && anActor->GetVisibility() )
979 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aGroupObj, aGroupSO ));
982 // update mesh, sub-mesh and groups, if it's possible
983 TListOf_IDSrc_SObj::iterator anIter;
984 for ( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ )
986 SMESH::SMESH_Mesh_var aMesh =
987 SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
989 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded,
990 &hidden, &nbElements ) )
994 bool toDisplay = false;
995 if ( !aMesh->_is_nil() ) // display only a mesh
998 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
999 if ( !anActor ) anActor = SMESH::CreateActor( (*anIter).second->GetStudy(),
1000 (*anIter).second->GetID().c_str(),
1001 /*clearLog =*/ true );
1002 if ( anActor ) // actor is not created for an empty mesh
1004 anActor->SetEntityMode( entities );
1005 SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor );
1008 Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
1009 ( (*anIter).second->GetID().c_str(), "SMESH", (*anIter).second->GetName().c_str() );
1010 SMESH::Update(anIO, toDisplay);
1012 if ( limitExceeded && !aMesh->_is_nil() )
1014 QStringList hiddenMsg;
1015 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1016 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
1017 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
1018 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
1019 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
1020 SUIT_MessageBox::warning( desktop(),
1021 tr( "SMESH_WRN_WARNING" ),
1022 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1025 arg( hiddenMsg.join(", ")));
1030 MESSAGE ( "Exception thrown during mesh visualization" );
1032 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1033 SMESH::OnVisuException();
1040 else if ( limitExceeded && !aMesh->_is_nil() )
1042 SUIT_MessageBox::warning( desktop(),
1043 tr( "SMESH_WRN_WARNING" ),
1044 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1045 arg( nbElements ).arg( limitSize ) );
1049 if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1051 SALOME_ListIO selected;
1052 selected.Append( myIObject );
1053 Sel->setSelectedObjects( selected );
1059 aMemoryReserve.release();
1061 myCompDlg->setWindowTitle
1062 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1066 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1067 bool noHypoError = ( aHypErrors.isEmpty() );
1069 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1070 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1072 bool isShowResultDlg = true;
1073 switch( aNotifyMode ) {
1074 case 0: // show the mesh computation result dialog NEVER
1075 isShowResultDlg = false;
1078 case 1: // show the mesh computation result dialog if there are some errors
1079 if ( memoryLack || !noCompError || !noHypoError )
1080 isShowResultDlg = true;
1083 isShowResultDlg = false;
1087 default: // show the result dialog after each mesh computation
1088 isShowResultDlg = true;
1092 if ( isShowResultDlg )
1093 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1096 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1097 const bool theNoCompError,
1098 SMESH::compute_error_array_var& theCompErrors,
1099 const bool theNoHypoError,
1100 const QString& theHypErrors )
1102 bool hasShape = myMesh->HasShapeToMesh();
1103 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1104 aCompDlg->myMemoryLackGroup->hide();
1106 if ( theMemoryLack )
1108 aCompDlg->myMemoryLackGroup->show();
1109 aCompDlg->myFullInfo->hide();
1110 aCompDlg->myBriefInfo->hide();
1111 aCompDlg->myHypErrorGroup->hide();
1112 aCompDlg->myCompErrorGroup->hide();
1114 else if ( theNoCompError && theNoHypoError )
1116 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1117 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1118 aCompDlg->myFullInfo->show();
1119 aCompDlg->myBriefInfo->hide();
1120 aCompDlg->myHypErrorGroup->hide();
1121 aCompDlg->myCompErrorGroup->hide();
1125 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1126 for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1127 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1128 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1130 // full or brief mesh info
1131 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
1132 if ( onlyWarnings ) {
1133 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1134 aCompDlg->myFullInfo->show();
1135 aCompDlg->myBriefInfo->hide();
1137 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1138 aCompDlg->myBriefInfo->show();
1139 aCompDlg->myFullInfo->hide();
1142 // pbs of hypo dfinitions
1143 if ( theNoHypoError ) {
1144 aCompDlg->myHypErrorGroup->hide();
1146 aCompDlg->myHypErrorGroup->show();
1147 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1151 if ( theNoCompError )
1153 aCompDlg->myCompErrorGroup->hide();
1157 aCompDlg->myCompErrorGroup->show();
1160 aCompDlg->myWarningLabel->show();
1162 aCompDlg->myWarningLabel->hide();
1165 aCompDlg->myPublishBtn->hide();
1166 aCompDlg->myShowBtn->hide();
1169 aCompDlg->myPublishBtn->show();
1170 aCompDlg->myShowBtn->show();
1173 // fill table of errors
1174 QTableWidget* tbl = aCompDlg->myTable;
1175 tbl->setRowCount( theCompErrors->length() );
1176 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1177 else tbl->showColumn( COL_SHAPE );
1178 tbl->setColumnWidth( COL_ERROR, 200 );
1180 bool hasBadMesh = false;
1181 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1183 SMESH::ComputeError & err = theCompErrors[ row ];
1185 QString text = err.algoName.in();
1186 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1187 else tbl->item( row, COL_ALGO )->setText( text );
1189 text = SMESH::errorText( err.code, err.comment.in() );
1190 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1191 else tbl->item( row, COL_ERROR )->setText( text );
1193 text = QString("%1").arg( err.subShapeID );
1194 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1195 else tbl->item( row, COL_SHAPEID )->setText( text );
1197 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1198 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1199 else tbl->item( row, COL_SHAPE )->setText( text );
1201 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1202 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1203 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1205 text = err.hasBadMesh ? "hasBadMesh" : "";
1206 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1207 else tbl->item( row, COL_BAD_MESH )->setText( text );
1208 if ( err.hasBadMesh ) hasBadMesh = true;
1210 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1211 tbl->resizeRowToContents( row );
1213 tbl->resizeColumnToContents( COL_ALGO );
1214 tbl->resizeColumnToContents( COL_SHAPE );
1215 tbl->setWordWrap( true );
1218 aCompDlg->myBadMeshBtn->show();
1219 aCompDlg->myBadMeshToGroupBtn->show();
1222 aCompDlg->myBadMeshBtn->hide();
1223 aCompDlg->myBadMeshToGroupBtn->hide();
1225 tbl->setCurrentCell(0,0);
1226 currentCellChanged(); // to update buttons
1229 // show dialog and wait, becase Compute can be invoked from Preview operation
1230 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1234 //================================================================================
1236 * \brief Stops operation
1238 //================================================================================
1240 void SMESHGUI_BaseComputeOp::stopOperation()
1242 SMESHGUI_Operation::stopOperation();
1243 if ( myTShapeDisplayer )
1244 myTShapeDisplayer->SetVisibility( false );
1245 if ( myBadMeshDisplayer ) {
1246 myBadMeshDisplayer->SetVisibility( false );
1247 // delete it in order not to have problems at its destruction when the viewer
1248 // where it worked is dead due to e.g. study closing
1249 delete myBadMeshDisplayer;
1250 myBadMeshDisplayer = 0;
1252 myIObject.Nullify();
1255 //================================================================================
1257 * \brief publish selected sub-shape
1259 //================================================================================
1261 void SMESHGUI_BaseComputeOp::onPublishShape()
1263 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1264 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1265 GEOM::GEOM_Object_var meshShape = myMesh->GetShapeToMesh();
1267 QStringList entryList;
1269 SMESH::getSelectedRows( table(), rows );
1271 foreach ( row, rows )
1273 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1274 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1275 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1277 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1279 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1280 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, myMainShape,
1281 name.toLatin1().data(),
1282 GEOM::GEOM_Object::_nil());
1283 // look for myMainShape in the table
1284 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1285 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1286 if ( so->_is_nil() ) {
1287 CORBA::String_var name = so->GetName();
1288 CORBA::String_var entry = so->GetID();
1289 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1290 table()->item( r, COL_SHAPE )->setText( shapeText );
1291 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1296 if ( curSub == 1 ) continue;
1298 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1299 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( study, shape,
1300 name.toLatin1().data(), myMainShape);
1301 if ( !so->_is_nil() ) {
1302 CORBA::String_var name = so->GetName();
1303 CORBA::String_var entry = so->GetID();
1304 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1305 table()->item( row, COL_SHAPE )->setText( shapeText );
1306 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1307 entryList.push_back( entry.in() );
1311 getSMESHGUI()->getApp()->updateObjectBrowser();
1312 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1314 currentCellChanged(); // to update buttons
1317 //================================================================================
1319 * \brief show mesh elements preventing computation of a submesh of current row
1321 //================================================================================
1323 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1325 myTShapeDisplayer->SetVisibility( false );
1327 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1328 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1330 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1331 SMESHGUI* gui = getSMESHGUI();
1332 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1333 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1334 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1335 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1336 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1337 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1338 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1339 vtkProperty* prop = vtkProperty::New();
1340 prop->SetLineWidth( aLineWidth * 3 );
1341 prop->SetPointSize( aPointSize * 3 );
1342 prop->SetColor( 250, 0, 250 );
1343 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1344 myBadMeshDisplayer->SetData( aMeshData._retn() );
1350 //================================================================================
1352 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1354 //================================================================================
1356 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1359 SMESH::getSelectedRows( table(), rows );
1361 foreach ( row, rows )
1363 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1365 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1366 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1367 if ( grName.isEmpty() ) grName = "bad mesh";
1368 else grName = "bad mesh of " + grName;
1369 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1370 SMESH::ListOfGroups_var groups
1371 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toLatin1().data()) );
1372 update( UF_ObjBrowser | UF_Model );
1373 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1375 QStringList anEntryList;
1376 for ( size_t i = 0; i < groups->length(); ++i )
1377 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1378 anEntryList.append( so->GetID().c_str() );
1380 if ( !anEntryList.isEmpty())
1381 anApp->browseObjects( anEntryList, true, false );
1387 //================================================================================
1389 * \brief SLOT called when a selected cell in table() changed
1391 //================================================================================
1393 void SMESHGUI_BaseComputeOp::currentCellChanged()
1395 myTShapeDisplayer->SetVisibility( false );
1396 if ( myBadMeshDisplayer )
1397 myBadMeshDisplayer->SetVisibility( false );
1399 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1401 int nbSelected = SMESH::getSelectedRows( table(), rows );
1403 foreach ( row, rows )
1405 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1406 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1407 if ( hasData && !isPublished )
1408 publishEnable = true;
1410 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1411 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1413 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1420 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1423 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1424 myCompDlg->myShowBtn ->setEnabled( showEnable );
1425 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1426 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1429 //================================================================================
1431 * \brief update preview
1433 //================================================================================
1435 void SMESHGUI_BaseComputeOp::onPreviewShape()
1437 if ( myTShapeDisplayer )
1439 SUIT_OverrideCursor aWaitCursor;
1441 SMESH::getSelectedRows( table(), rows );
1443 bool showOnly = true;
1445 foreach ( row, rows )
1447 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1449 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1453 currentCellChanged(); // to update buttons
1457 //================================================================================
1461 //================================================================================
1463 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1467 delete myTShapeDisplayer;
1468 if ( myBadMeshDisplayer )
1469 delete myBadMeshDisplayer;
1472 //================================================================================
1474 * \brief Gets dialog of compute operation
1475 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1477 //================================================================================
1479 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1483 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1484 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1485 // connect signals and slots
1486 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1487 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1488 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1489 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1491 QTableWidget* aTable = me->table();
1492 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1493 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1498 //================================================================================
1500 * \brief returns from compute mesh result dialog
1502 //================================================================================
1504 bool SMESHGUI_BaseComputeOp::onApply()
1509 //================================================================================
1511 * \brief Return a table
1513 //================================================================================
1515 QTableWidget* SMESHGUI_BaseComputeOp::table()
1517 return myCompDlg->myTable;
1521 //================================================================================
1523 * \brief Constructor
1525 //================================================================================
1527 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1528 : SMESHGUI_BaseComputeOp()
1530 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1534 //================================================================================
1536 * \brief Desctructor
1538 //================================================================================
1540 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1544 //================================================================================
1546 * \brief perform it's intention action: compute mesh
1548 //================================================================================
1550 void SMESHGUI_ComputeOp::startOperation()
1552 SMESHGUI_BaseComputeOp::startOperation();
1553 if (myMesh->_is_nil())
1558 //================================================================================
1560 * \brief check the same operations on the same mesh
1562 //================================================================================
1564 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1566 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1568 if ( !myMesh->_is_nil() && baseOp ) {
1569 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1570 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1575 //================================================================================
1577 * \brief Gets dialog of this operation
1578 * \retval LightApp_Dialog* - pointer to dialog of this operation
1580 //================================================================================
1582 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1584 return computeDlg();
1587 //================================================================================
1589 * \brief Constructor
1591 //================================================================================
1593 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1594 : SMESHGUI_BaseComputeOp(),
1597 myPreviewDisplayer( 0 ),
1602 //================================================================================
1606 //================================================================================
1608 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1615 if ( myPreviewDisplayer )
1616 delete myPreviewDisplayer;
1617 myPreviewDisplayer = 0;
1620 //================================================================================
1622 * \brief Gets current dialog of this operation
1623 * \retval LightApp_Dialog* - pointer to dialog of this operation
1625 //================================================================================
1627 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1632 //================================================================================
1634 * \brief perform it's intention action: prepare data
1636 //================================================================================
1638 void SMESHGUI_PrecomputeOp::startOperation()
1640 myHelpFileName = "constructing_meshes_page.html#preview_anchor"; // other anchor onCompute()
1644 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1647 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1648 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1649 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1651 myActiveDlg = myDlg;
1653 // connect signal to compute dialog. which will be shown after Compute mesh operation
1654 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1657 // disconnect signals
1658 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1659 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1660 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1661 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1662 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1665 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1666 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1667 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1668 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1669 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1670 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1671 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1672 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1673 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1674 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1677 SMESHGUI_BaseComputeOp::startOperation();
1678 if (myMesh->_is_nil())
1681 if (myDlg->getPreviewMode() == -1)
1683 // nothing to preview
1684 SUIT_MessageBox::warning(desktop(),
1685 tr("SMESH_WRN_WARNING"),
1686 tr("SMESH_WRN_NOTHING_PREVIEW"));
1691 // disconnect slot from preview dialog to have Apply from results of compute operation only
1692 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1693 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1698 //================================================================================
1700 * \brief Stops operation
1702 //================================================================================
1704 void SMESHGUI_PrecomputeOp::stopOperation()
1706 if ( myPreviewDisplayer )
1708 myPreviewDisplayer->SetVisibility( false );
1709 delete myPreviewDisplayer;
1710 myPreviewDisplayer = 0;
1712 myMapShapeId.clear();
1713 SMESHGUI_BaseComputeOp::stopOperation();
1716 //================================================================================
1718 * \brief reinitialize dialog after operaiton become active again
1720 //================================================================================
1722 void SMESHGUI_PrecomputeOp::resumeOperation()
1724 if ( myActiveDlg == myDlg )
1726 SMESHGUI_BaseComputeOp::resumeOperation();
1729 //================================================================================
1731 * \brief perform it's intention action: reinitialise dialog
1733 //================================================================================
1735 void SMESHGUI_PrecomputeOp::initDialog()
1739 QMap<int, int> modeMap;
1740 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1741 getAssignedAlgos( pMesh, modeMap );
1742 if ( modeMap.contains( SMESH::DIM_3D ) )
1744 if ( modeMap.contains( SMESH::DIM_2D ) )
1745 modes.append( SMESH::DIM_2D );
1746 if ( modeMap.contains( SMESH::DIM_1D ) )
1747 modes.append( SMESH::DIM_1D );
1749 else if ( modeMap.contains( SMESH::DIM_2D ) )
1751 if ( modeMap.contains( SMESH::DIM_1D ) )
1752 modes.append( SMESH::DIM_1D );
1755 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1756 myOrderMgr->SetMesh( myMesh );
1757 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1758 myDlg->getMeshOrderBox()->setVisible(isOrder);
1764 myDlg->setPreviewModes( modes );
1767 //================================================================================
1769 * \brief detect asigned mesh algorithms
1771 //================================================================================
1773 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1774 QMap<int,int>& theModeMap)
1776 if ( !theMesh ) return;
1778 _PTR(SObject) aHypFolder;
1779 _PTR(GenericAttribute) anAttr;
1780 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1781 if ( theMesh->FindSubObject( aPart, aHypFolder ))
1783 _PTR(ChildIterator) anIter =
1784 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1785 for ( ; anIter->More(); anIter->Next() )
1787 _PTR(SObject) anObj = anIter->Value();
1788 _PTR(SObject) aRefObj;
1789 if ( anObj->ReferencedObject( aRefObj ) )
1794 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1796 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1797 if ( CORBA::is_nil( aVar ) )
1800 SMESH::SMESH_Algo_var algo;
1801 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1804 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1805 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1806 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1809 if ( !algo->_is_nil() )
1811 theModeMap[ dim ] = 0;
1812 if ( theModeMap.size() == 3 )
1822 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1824 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1827 _PTR(ChildIterator) anIter =
1828 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypFolder );
1829 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1831 _PTR(SObject) anObj = anIter->Value();
1832 _PTR(SObject) aRefObj;
1833 if ( anObj->ReferencedObject( aRefObj ) )
1838 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1840 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1841 if ( CORBA::is_nil( aVar ) )
1844 SMESH::SMESH_Algo_var algo;
1845 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1848 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1849 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1850 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1853 if ( !algo->_is_nil() )
1855 theModeMap[ dim ] = 0;
1856 if ( theModeMap.size() == 3 )
1866 //================================================================================
1868 * \brief perform it's intention action: compute mesh
1870 //================================================================================
1872 void SMESHGUI_PrecomputeOp::onCompute()
1875 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1876 myOrderMgr->SetMeshOrder();
1877 myMapShapeId.clear();
1878 myActiveDlg = computeDlg();
1879 myHelpFileName = "constructing_meshes_page.html#compute_anchor";
1883 //================================================================================
1885 * \brief perform it's intention action: compute mesh
1887 //================================================================================
1889 void SMESHGUI_PrecomputeOp::onCancel()
1891 QObject* curDlg = sender();
1892 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1894 // return from error messages
1899 bool isRestoreOrder = false;
1900 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1902 // ask to remove already computed mesh elements
1903 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1904 tr( "CLEAR_SUBMESH_QUESTION" ),
1905 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1907 // remove all submeshes for collected shapes
1908 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1909 for ( ; it != myMapShapeId.constEnd(); ++it )
1910 myMesh->ClearSubMesh( it.key() );
1911 isRestoreOrder = true;
1915 // return previous mesh order
1916 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1917 if (!isRestoreOrder)
1919 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1920 tr( "SMESH_REJECT_MESH_ORDER" ),
1921 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1923 myOrderMgr->SetMeshOrder(myPrevOrder);
1929 myMapShapeId.clear();
1930 SMESHGUI_BaseComputeOp::onCancel();
1933 //================================================================================
1935 * \brief perform it's intention action: preview mesh
1937 //================================================================================
1939 void SMESHGUI_PrecomputeOp::onPreview()
1941 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1944 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1948 // set modified submesh priority if any
1949 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1950 myOrderMgr->SetMeshOrder();
1952 // Compute preview of mesh,
1953 // i.e. compute mesh till indicated dimension
1954 int dim = myDlg->getPreviewMode();
1956 SMESH::MemoryReserve aMemoryReserve;
1958 SMESH::compute_error_array_var aCompErrors;
1961 bool computeFailed = true, memoryLack = false;
1963 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1964 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1966 SMESHGUI* gui = getSMESHGUI();
1967 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1968 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1969 if ( errors->length() > 0 ) {
1970 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1973 SUIT_OverrideCursor aWaitCursor;
1975 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1976 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1977 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1979 SMESH::long_array_var aShapesId = new SMESH::long_array();
1981 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1985 SMESH::MeshPreviewStruct_var previewData =
1986 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1988 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1989 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1991 computeFailed = false;
1992 myPreviewDisplayer->SetData( previewRes );
1993 // append shape indeces with computed mesh entities
1994 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1995 myMapShapeId[ aShapesId[ i ] ] = 0;
1998 myPreviewDisplayer->SetVisibility(false);
2000 catch(const SALOME::SALOME_Exception & S_ex){
2002 myPreviewDisplayer->SetVisibility(false);
2006 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2009 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2010 // check if there are memory problems
2011 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
2012 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
2014 catch(const SALOME::SALOME_Exception & S_ex){
2019 aMemoryReserve.release();
2021 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2022 bool noHypoError = ( aHypErrors.isEmpty() );
2024 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2025 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2027 bool isShowError = true;
2028 switch( aNotifyMode ) {
2029 case 0: // show the mesh computation result dialog NEVER
2030 isShowError = false;
2032 case 1: // show the mesh computation result dialog if there are some errors
2033 default: // show the result dialog after each mesh computation
2034 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2035 isShowError = false;
2039 aWaitCursor.suspend();
2044 aCompDlg->setWindowTitle
2045 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2046 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2051 //================================================================================
2053 * \brief Constructor
2055 //================================================================================
2057 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2058 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2061 setWindowTitle( tr( "CAPTION" ) );
2063 setButtonText( OK, tr( "COMPUTE" ) );
2064 QFrame* main = mainFrame();
2065 main->setMinimumWidth( 300 );
2067 QVBoxLayout* layout = new QVBoxLayout( main );
2069 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2070 layout->addWidget(myOrderBox);
2072 QFrame* frame = new QFrame( main );
2073 layout->setMargin(0); layout->setSpacing(0);
2074 layout->addWidget( frame );
2076 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2077 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2079 myPreviewMode = new QtxComboBox( frame );
2080 frameLay->addWidget( myPreviewMode );
2082 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2083 frameLay->addWidget( myPreviewBtn );
2085 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2088 //================================================================================
2092 //================================================================================
2094 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2098 //================================================================================
2100 * \brief Sets available preview modes
2102 //================================================================================
2104 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2106 myPreviewMode->clear();
2107 QList<int>::const_iterator it = theModes.constBegin();
2108 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2110 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2111 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2112 myPreviewMode->setId( i, *it );
2114 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2117 //================================================================================
2119 * \brief Returns current preview mesh mode
2121 //================================================================================
2123 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2125 return myPreviewMode->currentId().toInt();
2128 //================================================================================
2130 * \brief Returns current preview mesh mode
2132 //================================================================================
2134 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2140 //================================================================================
2142 * \brief Constructor
2144 //================================================================================
2146 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2147 : SMESHGUI_BaseComputeOp()
2149 myHelpFileName = "constructing_meshes_page.html#evaluate_anchor";
2153 //================================================================================
2155 * \brief Desctructor
2157 //================================================================================
2159 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2163 //================================================================================
2165 * \brief perform it's intention action: compute mesh
2167 //================================================================================
2169 void SMESHGUI_EvaluateOp::startOperation()
2171 SMESHGUI_BaseComputeOp::evaluateDlg();
2172 SMESHGUI_BaseComputeOp::startOperation();
2173 if (myMesh->_is_nil())
2178 //================================================================================
2180 * \brief Gets dialog of this operation
2181 * \retval LightApp_Dialog* - pointer to dialog of this operation
2183 //================================================================================
2185 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2187 return evaluateDlg();
2190 //================================================================================
2192 * \brief evaluateMesh()
2194 //================================================================================
2196 void SMESHGUI_BaseComputeOp::evaluateMesh()
2200 SMESH::MemoryReserve aMemoryReserve;
2202 SMESH::compute_error_array_var aCompErrors;
2205 bool evaluateFailed = true, memoryLack = false;
2206 SMESH::long_array_var aRes;
2208 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2209 if ( !aMeshSObj ) // IPAL21340
2212 bool hasShape = myMesh->HasShapeToMesh();
2213 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2216 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
2217 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2218 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2219 if ( errors->length() > 0 ) {
2220 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2222 SUIT_OverrideCursor aWaitCursor;
2224 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2227 aRes = gen->Evaluate(myMesh, myMainShape);
2229 catch(const SALOME::SALOME_Exception & S_ex){
2234 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
2237 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2239 catch(const SALOME::SALOME_Exception & S_ex){
2245 aMemoryReserve.release();
2247 evaluateFailed = ( aCompErrors->length() > 0 );
2248 myCompDlg->setWindowTitle
2249 ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2253 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2254 bool noHypoError = ( aHypErrors.isEmpty() );
2256 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2257 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2259 bool isShowResultDlg = true;
2261 //switch( aNotifyMode ) {
2262 //case 0: // show the mesh computation result dialog NEVER
2263 //isShowResultDlg = false;
2266 //case 1: // show the mesh computation result dialog if there are some errors
2267 //if ( memoryLack || !noHypoError )
2268 // isShowResultDlg = true;
2271 // isShowResultDlg = false;
2275 //default: // show the result dialog after each mesh computation
2276 //isShowResultDlg = true;
2280 if ( isShowResultDlg )
2281 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2282 noHypoError, aHypErrors);
2286 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
2287 const bool theMemoryLack,
2288 const bool theNoCompError,
2289 SMESH::compute_error_array_var& theCompErrors,
2290 const bool theNoHypoError,
2291 const QString& theHypErrors)
2293 bool hasShape = myMesh->HasShapeToMesh();
2294 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2295 aCompDlg->myMemoryLackGroup->hide();
2297 if ( theMemoryLack )
2299 aCompDlg->myMemoryLackGroup->show();
2300 aCompDlg->myFullInfo->hide();
2301 aCompDlg->myBriefInfo->hide();
2302 aCompDlg->myHypErrorGroup->hide();
2303 aCompDlg->myCompErrorGroup->hide();
2305 else if ( theNoCompError && theNoHypoError )
2307 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2308 aCompDlg->myFullInfo->show();
2309 aCompDlg->myBriefInfo->hide();
2310 aCompDlg->myHypErrorGroup->hide();
2311 aCompDlg->myCompErrorGroup->hide();
2315 QTableWidget* tbl = aCompDlg->myTable;
2316 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2317 aCompDlg->myBriefInfo->show();
2318 aCompDlg->myFullInfo->hide();
2320 if ( theNoHypoError ) {
2321 aCompDlg->myHypErrorGroup->hide();
2324 aCompDlg->myHypErrorGroup->show();
2325 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2328 if ( theNoCompError ) {
2329 aCompDlg->myCompErrorGroup->hide();
2332 aCompDlg->myCompErrorGroup->show();
2334 aCompDlg->myPublishBtn->hide();
2335 aCompDlg->myShowBtn->hide();
2337 // fill table of errors
2338 tbl->setRowCount( theCompErrors->length() );
2339 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2340 else tbl->showColumn( COL_SHAPE );
2341 tbl->setColumnWidth( COL_ERROR, 200 );
2343 bool hasBadMesh = false;
2344 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2346 SMESH::ComputeError & err = theCompErrors[ row ];
2348 QString text = err.algoName.in();
2349 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2350 else tbl->item( row, COL_ALGO )->setText( text );
2352 text = SMESH::errorText( err.code, err.comment.in() );
2353 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2354 else tbl->item( row, COL_ERROR )->setText( text );
2356 text = QString("%1").arg( err.subShapeID );
2357 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2358 else tbl->item( row, COL_SHAPEID )->setText( text );
2360 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2361 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2362 else tbl->item( row, COL_SHAPE )->setText( text );
2364 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2365 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2366 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2368 text = err.hasBadMesh ? "hasBadMesh" : "";
2369 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2370 else tbl->item( row, COL_BAD_MESH )->setText( text );
2371 if ( err.hasBadMesh ) hasBadMesh = true;
2373 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2374 tbl->resizeRowToContents( row );
2376 tbl->resizeColumnToContents( COL_ALGO );
2377 tbl->resizeColumnToContents( COL_SHAPE );
2378 tbl->setWordWrap( true );
2382 aCompDlg->myBadMeshBtn->show();
2383 aCompDlg->myBadMeshToGroupBtn->show();
2387 aCompDlg->myBadMeshBtn->hide();
2388 aCompDlg->myBadMeshToGroupBtn->hide();
2390 tbl->setCurrentCell(0,0);
2391 currentCellChanged(); // to update buttons
2394 // show dialog and wait, becase Compute can be invoked from Preview operation
2395 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2400 //================================================================================
2402 * \brief Gets dialog of evaluate operation
2403 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2405 //================================================================================
2407 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2411 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2412 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2413 // connect signals and slots
2414 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2415 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2416 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2417 QTableWidget* aTable = me->table();
2418 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2419 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));