1 // Copyright (C) 2007-2022 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 //================================================================================
661 * \brief Gets dialog of this operation
662 * \retval LightApp_Dialog* - pointer to dialog of this operation
664 //================================================================================
666 LightApp_Dialog* SMESHGUI_BaseComputeOp::dlg() const
671 //================================================================================
673 * \brief Return a selected mesh
675 //================================================================================
677 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
679 LightApp_SelectionMgr* Sel = selectionMgr();
680 SALOME_ListIO selected; Sel->selectedObjects( selected );
681 Handle(SALOME_InteractiveObject) anIO = selected.First();
682 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
683 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
686 //================================================================================
688 * \brief check the same operations on the same mesh
690 //================================================================================
692 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
694 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
696 if ( !myMesh->_is_nil() && baseOp ) {
697 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
698 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
703 //================================================================================
705 * \brief Start operation
706 * \purpose Init dialog fields, connect signals and slots, show dialog
708 //================================================================================
710 void SMESHGUI_BaseComputeOp::startOperation()
712 // create compute dialog if not created before
715 myMesh = SMESH::SMESH_Mesh::_nil();
716 myMainShape = GEOM::GEOM_Object::_nil();
717 myCurShape = GEOM::GEOM_Object::_nil();
720 LightApp_SelectionMgr *Sel = selectionMgr();
721 SALOME_ListIO selected; Sel->selectedObjects( selected );
723 int nbSel = selected.Extent();
725 SUIT_MessageBox::warning(desktop(),
726 tr("SMESH_WRN_WARNING"),
727 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
732 myIObject = selected.First();
733 CORBA::Object_var anObj = SMESH::IObjectToObject( myIObject );
735 myMesh = SMESH::SMESH_Mesh::_narrow(anObj);
736 if ( myMesh->_is_nil() )
738 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
739 if ( !aSubMesh->_is_nil() )
741 myMesh = aSubMesh->GetFather();
742 myCurShape = aSubMesh->GetSubShape();
747 myCurShape = myMesh->GetShapeToMesh();
750 if (myMesh->_is_nil()) {
751 SUIT_MessageBox::warning(desktop(),
752 tr("SMESH_WRN_WARNING"),
753 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
758 myCompDlg->myMeshName->setText( SMESH::GetName( myIObject ));
760 myMainShape = myMesh->GetShapeToMesh();
762 SMESHGUI_Operation::startOperation();
765 //================================================================================
766 //================================================================================
768 SMESHGUI_ComputeDlg_QThread::SMESHGUI_ComputeDlg_QThread(SMESH::SMESH_Gen_var gen,
769 SMESH::SMESH_Mesh_var mesh,
770 GEOM::GEOM_Object_var mainShape)
775 myMainShape = mainShape;
778 void SMESHGUI_ComputeDlg_QThread::run()
780 myResult = myGen->Compute(myMesh, myMainShape);
783 bool SMESHGUI_ComputeDlg_QThread::result()
788 void SMESHGUI_ComputeDlg_QThread::cancel()
790 myGen->CancelCompute(myMesh, myMainShape);
793 //================================================================================
794 //================================================================================
796 SMESHGUI_ComputeDlg_QThreadQDialog::
797 SMESHGUI_ComputeDlg_QThreadQDialog(QWidget * parent,
798 SMESH::SMESH_Gen_var gen,
799 SMESH::SMESH_Mesh_var mesh,
800 GEOM::GEOM_Object_var mainShape)
802 Qt::WindowSystemMenuHint |
803 Qt::WindowCloseButtonHint |
805 Qt::WindowMaximizeButtonHint),
806 qthread(gen, mesh, mainShape)
809 setWindowTitle(tr("TITLE"));
810 setMinimumWidth( 200 );
812 cancelButton = new QPushButton(tr("CANCEL"));
813 cancelButton->setDefault(true);
814 cancelButton->setCheckable(true);
816 QLabel * nbNodesName = new QLabel(tr("SMESH_MESHINFO_NODES"), this );
817 QLabel * nbElemsName = new QLabel(tr("SMESH_MESHINFO_ELEMENTS"), this );
818 nbNodesLabel = new QLabel("0", this );
819 nbElemsLabel = new QLabel("0", this );
820 #if !defined WIN32 && !defined __APPLE__
821 QLabel * freeRAMName = new QLabel(tr("SMESH_FREERAM"), this );
822 freeRAMLabel = new QLabel("", this );
824 progressBar = new QProgressBar(this);
825 progressBar->setMinimum( 0 );
826 progressBar->setMaximum( 1000 );
828 QGridLayout* layout = new QGridLayout(this);
829 layout->setMargin( MARGIN );
830 layout->setSpacing( SPACING );
832 layout->addWidget(nbNodesName, row, 0);
833 layout->addWidget(nbNodesLabel, row++, 1);
834 layout->addWidget(nbElemsName, row, 0);
835 layout->addWidget(nbElemsLabel, row++, 1);
836 #if !defined WIN32 && !defined __APPLE__
837 layout->addWidget(freeRAMName, row, 0);
838 layout->addWidget(freeRAMLabel, row++, 1);
840 layout->addWidget(progressBar, row++, 0, 1, 2);
841 layout->addWidget(cancelButton, row++, 0, 1, 2);
845 connect(cancelButton, SIGNAL(clicked()), this, SLOT(onCancel()));
847 startTimer(300); // millisecs
851 bool SMESHGUI_ComputeDlg_QThreadQDialog::result()
853 return qthread.result();
856 void SMESHGUI_ComputeDlg_QThreadQDialog::onCancel()
859 cancelButton->setText( tr("CANCELING"));
860 cancelButton->setEnabled(false);
863 void SMESHGUI_ComputeDlg_QThreadQDialog::timerEvent(QTimerEvent *event)
865 if ( !cancelButton->isChecked() ) // not yet cancelled
866 progressBar->setValue( progressBar->maximum() * qthread.getMesh()->GetComputeProgress() );
868 if(qthread.isFinished())
874 nbNodesLabel->setText( QString("%1").arg( qthread.getMesh()->NbNodes() ));
875 nbElemsLabel->setText( QString("%1").arg( qthread.getMesh()->NbElements() ));
876 #if !defined WIN32 && !defined __APPLE__
878 const int err = sysinfo( &si );
880 freeRAMLabel->setText("");
882 freeRAMLabel->setText( tr("SMESH_GIGABYTE").arg
883 ( si.freeram * si.mem_unit /1024./1024./1024., 0, 'f', 2 ));
889 void SMESHGUI_ComputeDlg_QThreadQDialog::closeEvent(QCloseEvent *event)
891 if(qthread.isRunning())
899 //================================================================================
901 * \brief computeMesh()
903 //================================================================================
905 void SMESHGUI_BaseComputeOp::computeMesh()
909 SMESH::MemoryReserve aMemoryReserve;
911 SMESH::compute_error_array_var aCompErrors;
914 bool computeFailed = true, memoryLack = false;
916 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
917 if ( !aMeshSObj ) // IPAL 21340
919 bool hasShape = myMesh->HasShapeToMesh();
920 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
923 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
924 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
925 if ( errors->length() > 0 ) {
926 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
928 if ( myMesh->HasModificationsToDiscard() && // issue 0020693
929 SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
930 tr( "FULL_RECOMPUTE_QUESTION" ),
931 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 1, 0 ) == 0 )
933 SUIT_OverrideCursor aWaitCursor;
936 SMESHGUI_ComputeDlg_QThreadQDialog qthreaddialog(desktop(), gen, myMesh, myCurShape);
937 qthreaddialog.exec();
938 computeFailed = !qthreaddialog.result();
940 catch(const SALOME::SALOME_Exception & S_ex) {
945 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
946 // check if there are memory problems
947 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
948 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
950 catch(const SALOME::SALOME_Exception & S_ex) {
954 if ( !memoryLack && !SMDS_Mesh::CheckMemory(true) ) { // has memory to show dialog boxes?
958 // NPAL16631: if ( !memoryLack )
960 update( UF_ObjBrowser | UF_Model );
963 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
964 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
966 long limitSize = resMgr->integerValue( "SMESH", "update_limit", 500000 );
967 int entities = SMESH_Actor::eAllEntity;
972 // List of objects that will be updated automatically
973 typedef QList< QPair< SMESH::SMESH_IDSource_var, _PTR(SObject) > > TListOf_IDSrc_SObj;
974 TListOf_IDSrc_SObj aListToUpdate;
975 SMESH::SMESH_IDSource_var aMeshObj =
976 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aMeshSObj );
977 // put Mesh into list
978 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aMeshObj, aMeshSObj ));
979 SMESH::submesh_array_var aSubMeshes = myMesh->GetSubMeshes();
980 // put SubMeshes into list
981 for ( CORBA::ULong i = 0; i < aSubMeshes->length(); i++ )
983 SMESH::SMESH_subMesh_var sm = aSubMeshes[i];
984 if ( CORBA::is_nil( sm ) ) continue;
985 _PTR(SObject) smSObj = SMESH::ObjectToSObject( sm );
986 if ( !smSObj ) continue;
987 SMESH::SMESH_IDSource_var aSubMeshObj =
988 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( smSObj );
989 SMESH_Actor *anActor = SMESH::FindActorByObject( aSubMeshObj );
990 if ( anActor /*&& anActor->GetVisibility()*/ )
991 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aSubMeshObj, smSObj ));
993 // put Groups into list
994 SMESH::ListOfGroups_var aGroups = myMesh->GetGroups();
995 for ( size_t i = 0; i < aGroups->length(); ++i )
997 SMESH::SMESH_GroupBase_var aGrp = aGroups[i];
998 if ( CORBA::is_nil( aGrp ) ) continue;
999 SMESH::SMESH_Group_var aStdGroup = SMESH::SMESH_Group::_narrow( aGrp );
1000 if ( !aStdGroup->_is_nil() ) continue; // don't update standalone groups
1001 _PTR(SObject) aGroupSO = SMESH::FindSObject( aGrp );
1002 if ( !aGroupSO ) continue;
1003 SMESH::SMESH_IDSource_var aGroupObj =
1004 SMESH::SObjectToInterface<SMESH::SMESH_IDSource>( aGroupSO );
1005 SMESH_Actor *anActor = SMESH::FindActorByObject( aGroupObj );
1006 if ( anActor /*&& anActor->GetVisibility()*/ )
1007 aListToUpdate.append( TListOf_IDSrc_SObj::value_type( aGroupObj, aGroupSO ));
1010 // update mesh, sub-mesh and groups, if it's possible
1011 TListOf_IDSrc_SObj::iterator anIter;
1012 for ( anIter = aListToUpdate.begin(); anIter != aListToUpdate.end(); anIter++ )
1014 SMESH::SMESH_Mesh_var aMesh =
1015 SMESH::SMESH_Mesh::_narrow( SMESH::SObjectToObject( (*anIter).second ));
1017 if ( getSMESHGUI()->automaticUpdate( (*anIter).first, &entities, &limitExceeded,
1018 &hidden, &nbElements ) )
1022 std::string entry = (*anIter).second->GetID();
1023 if ( !aMesh->_is_nil() ) // display only a mesh
1025 SMESH_Actor *anActor = SMESH::FindActorByObject( aMesh );
1026 if ( !anActor ) anActor = SMESH::CreateActor( entry.c_str(), /*clearLog =*/true );
1027 if ( anActor ) // actor is not created for an empty mesh
1029 anActor->SetEntityMode( entities );
1030 //SMESH::DisplayActor( SMESH::GetActiveWindow(), anActor ); -- 23615
1035 SMESH_Actor *anActor = SMESH::FindActorByEntry( entry.c_str() );
1037 if ( !anActor->GetVisibility() )
1040 SMESH::UpdateView( SMESH::eDisplay, entry.c_str() );
1042 if ( SVTK_ViewWindow* vtkWnd = SMESH::GetVtkViewWindow(SMESH::GetActiveWindow() ))
1043 if ( vtkWnd->getRenderer() )
1044 vtkWnd->getRenderer()->ResetCameraClippingRange();
1046 if ( limitExceeded && !aMesh->_is_nil() )
1048 QStringList hiddenMsg;
1049 if ( hidden & SMESH_Actor::e0DElements ) hiddenMsg << tr( "SMESH_ELEMS0D" );
1050 if ( hidden & SMESH_Actor::eEdges ) hiddenMsg << tr( "SMESH_EDGES" );
1051 if ( hidden & SMESH_Actor::eFaces ) hiddenMsg << tr( "SMESH_FACES" );
1052 if ( hidden & SMESH_Actor::eVolumes ) hiddenMsg << tr( "SMESH_VOLUMES" );
1053 if ( hidden & SMESH_Actor::eBallElem ) hiddenMsg << tr( "SMESH_BALLS" );
1054 SUIT_MessageBox::warning( desktop(),
1055 tr( "SMESH_WRN_WARNING" ),
1056 tr( "SMESH_WRN_SIZE_INC_LIMIT_EXCEEDED" ).
1059 arg( hiddenMsg.join(", ")));
1064 MESSAGE ( "Exception thrown during mesh visualization" );
1066 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1067 SMESH::OnVisuException();
1074 else if ( limitExceeded && !aMesh->_is_nil() )
1076 SUIT_MessageBox::warning( desktop(),
1077 tr( "SMESH_WRN_WARNING" ),
1078 tr( "SMESH_WRN_SIZE_LIMIT_EXCEEDED" ).
1079 arg( nbElements ).arg( limitSize ) );
1083 if ( LightApp_SelectionMgr *Sel = selectionMgr() )
1085 SALOME_ListIO selected;
1086 selected.Append( myIObject );
1087 Sel->setSelectedObjects( selected );
1093 aMemoryReserve.release();
1095 myCompDlg->setWindowTitle
1096 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
1100 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1101 bool noHypoError = ( aHypErrors.isEmpty() );
1103 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1104 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1106 bool isShowResultDlg = true;
1107 switch( aNotifyMode ) {
1108 case 0: // show the mesh computation result dialog NEVER
1109 isShowResultDlg = false;
1112 case 1: // show the mesh computation result dialog if there are some errors
1113 if ( memoryLack || !noCompError || !noHypoError )
1114 isShowResultDlg = true;
1117 isShowResultDlg = false;
1121 default: // show the result dialog after each mesh computation
1122 isShowResultDlg = true;
1126 if ( isShowResultDlg )
1127 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
1130 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
1131 const bool theNoCompError,
1132 SMESH::compute_error_array_var& theCompErrors,
1133 const bool theNoHypoError,
1134 const QString& theHypErrors )
1136 bool hasShape = myMesh->HasShapeToMesh();
1137 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1138 aCompDlg->myMemoryLackGroup->hide();
1140 if ( theMemoryLack )
1142 aCompDlg->myMemoryLackGroup->show();
1143 aCompDlg->myFullInfo->hide();
1144 aCompDlg->myBriefInfo->hide();
1145 aCompDlg->myHypErrorGroup->hide();
1146 aCompDlg->myCompErrorGroup->hide();
1148 else if ( theNoCompError && theNoHypoError )
1150 SMESH::smIdType_array_var aRes = myMesh->GetMeshInfo();
1151 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1152 aCompDlg->myFullInfo->show();
1153 aCompDlg->myBriefInfo->hide();
1154 aCompDlg->myHypErrorGroup->hide();
1155 aCompDlg->myCompErrorGroup->hide();
1159 bool onlyWarnings = !theNoCompError; // == valid mesh computed but there are errors reported
1160 for ( CORBA::ULong i = 0; i < theCompErrors->length() && onlyWarnings; ++i )
1161 onlyWarnings = ( theCompErrors[ i ].code == SMESH::COMPERR_WARNING ||
1162 theCompErrors[ i ].code == SMESH::COMPERR_NO_MESH_ON_SHAPE );
1164 // full or brief mesh info
1165 SMESH::smIdType_array_var aRes = myMesh->GetMeshInfo();
1166 if ( onlyWarnings ) {
1167 aCompDlg->myFullInfo->SetMeshInfo( aRes );
1168 aCompDlg->myFullInfo->show();
1169 aCompDlg->myBriefInfo->hide();
1171 aCompDlg->myBriefInfo->SetMeshInfo( aRes );
1172 aCompDlg->myBriefInfo->show();
1173 aCompDlg->myFullInfo->hide();
1176 // pbs of hypo definitions
1177 if ( theNoHypoError ) {
1178 aCompDlg->myHypErrorGroup->hide();
1180 aCompDlg->myHypErrorGroup->show();
1181 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1185 if ( theNoCompError )
1187 aCompDlg->myCompErrorGroup->hide();
1191 aCompDlg->myCompErrorGroup->show();
1194 aCompDlg->myWarningLabel->show();
1196 aCompDlg->myWarningLabel->hide();
1199 aCompDlg->myPublishBtn->hide();
1200 aCompDlg->myShowBtn->hide();
1203 aCompDlg->myPublishBtn->show();
1204 aCompDlg->myShowBtn->show();
1207 // fill table of errors
1208 QTableWidget* tbl = aCompDlg->myTable;
1209 tbl->setRowCount( theCompErrors->length() );
1210 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1211 else tbl->showColumn( COL_SHAPE );
1212 tbl->setColumnWidth( COL_ERROR, 200 );
1214 bool hasBadMesh = false;
1215 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
1217 SMESH::ComputeError & err = theCompErrors[ row ];
1219 QString text = err.algoName.in();
1220 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1221 else tbl->item( row, COL_ALGO )->setText( text );
1223 text = SMESH::errorText( err.code, err.comment.in() );
1224 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1225 else tbl->item( row, COL_ERROR )->setText( text );
1227 text = QString("%1").arg( err.subShapeID );
1228 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1229 else tbl->item( row, COL_SHAPEID )->setText( text );
1231 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1232 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1233 else tbl->item( row, COL_SHAPE )->setText( text );
1235 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1236 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1237 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1239 text = err.hasBadMesh ? "hasBadMesh" : "";
1240 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1241 else tbl->item( row, COL_BAD_MESH )->setText( text );
1242 if ( err.hasBadMesh ) hasBadMesh = true;
1244 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1245 tbl->resizeRowToContents( row );
1247 tbl->resizeColumnToContents( COL_ALGO );
1248 tbl->resizeColumnToContents( COL_SHAPE );
1249 tbl->setWordWrap( true );
1252 aCompDlg->myBadMeshBtn->show();
1253 aCompDlg->myBadMeshToGroupBtn->show();
1256 aCompDlg->myBadMeshBtn->hide();
1257 aCompDlg->myBadMeshToGroupBtn->hide();
1259 tbl->setCurrentCell(0,0);
1260 currentCellChanged(); // to update buttons
1263 // show dialog and wait, because Compute can be invoked from Preview operation
1264 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1268 //================================================================================
1270 * \brief Stops operation
1272 //================================================================================
1274 void SMESHGUI_BaseComputeOp::stopOperation()
1276 SMESHGUI_Operation::stopOperation();
1277 if ( myTShapeDisplayer )
1278 myTShapeDisplayer->SetVisibility( false );
1279 if ( myBadMeshDisplayer ) {
1280 myBadMeshDisplayer->SetVisibility( false );
1281 // delete it in order not to have problems at its destruction when the viewer
1282 // where it worked is dead due to e.g. study closing
1283 delete myBadMeshDisplayer;
1284 myBadMeshDisplayer = 0;
1286 myIObject.Nullify();
1289 //================================================================================
1291 * \brief publish selected sub-shape
1293 //================================================================================
1295 void SMESHGUI_BaseComputeOp::onPublishShape()
1297 GEOM::GEOM_Object_var meshShape = myMesh->GetShapeToMesh();
1298 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen( meshShape );
1300 QStringList entryList;
1302 SMESH::getSelectedRows( table(), rows );
1304 foreach ( row, rows )
1306 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1307 GEOM::GEOM_Object_wrap shape = SMESH::getSubShape( curSub, myMainShape );
1308 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1310 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1312 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1313 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( myMainShape,
1314 name.toUtf8().data(),
1315 GEOM::GEOM_Object::_nil());
1316 // look for myMainShape in the table
1317 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1318 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1319 if ( !so->_is_nil() ) {
1320 CORBA::String_var name = so->GetName();
1321 CORBA::String_var entry = so->GetID();
1322 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1323 table()->item( r, COL_SHAPE )->setText( shapeText );
1324 table()->item( r, COL_PUBLISHED )->setText( entry.in() );
1329 if ( curSub == 1 ) continue;
1331 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1332 SALOMEDS::SObject_wrap so = geomGen->AddInStudy( shape,
1333 name.toUtf8().data(), myMainShape);
1334 if ( !so->_is_nil() ) {
1335 CORBA::String_var name = so->GetName();
1336 CORBA::String_var entry = so->GetID();
1337 QString shapeText = QString("%1 (%2)").arg( name.in() ).arg( entry.in() );
1338 table()->item( row, COL_SHAPE )->setText( shapeText );
1339 table()->item( row, COL_PUBLISHED )->setText( entry.in() );
1340 entryList.push_back( entry.in() );
1344 getSMESHGUI()->getApp()->updateObjectBrowser();
1345 getSMESHGUI()->getApp()->browseObjects( entryList, /*isApplyAndClose=*/true );
1347 currentCellChanged(); // to update buttons
1350 //================================================================================
1352 * \brief show mesh elements preventing computation of a submesh of current row
1354 //================================================================================
1356 void SMESHGUI_BaseComputeOp::onShowBadMesh()
1358 myTShapeDisplayer->SetVisibility( false );
1360 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
1361 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
1363 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1364 SMESHGUI* gui = getSMESHGUI();
1365 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1366 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1367 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1368 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1369 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1370 double aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1371 double aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1372 vtkProperty* prop = vtkProperty::New();
1373 prop->SetLineWidth( aLineWidth * 3 );
1374 prop->SetPointSize( aPointSize * 3 );
1375 prop->SetColor( 250, 0, 250 );
1376 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1377 myBadMeshDisplayer->SetData( aMeshData.in() );
1383 //================================================================================
1385 * \brief create groups of bad mesh elements preventing computation of a submesh of current row
1387 //================================================================================
1389 void SMESHGUI_BaseComputeOp::onGroupOfBadMesh()
1392 SMESH::getSelectedRows( table(), rows );
1394 foreach ( row, rows )
1396 bool hasBadMesh = ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() );
1398 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1399 QString grName = table()->item(rows.front(), COL_SHAPE)->text();
1400 if ( grName.isEmpty() ) grName = "bad mesh";
1401 else grName = "bad mesh of " + grName;
1402 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1403 SMESH::ListOfGroups_var groups
1404 ( gen->MakeGroupsOfBadInputElements(myMesh,curSub,grName.toUtf8().data()) );
1405 update( UF_ObjBrowser | UF_Model );
1406 if( LightApp_Application* anApp = dynamic_cast<LightApp_Application*>( application() ))
1408 QStringList anEntryList;
1409 for ( size_t i = 0; i < groups->length(); ++i )
1410 if ( _PTR(SObject) so = SMESH::FindSObject( groups[i] ))
1411 anEntryList.append( so->GetID().c_str() );
1413 if ( !anEntryList.isEmpty())
1414 anApp->browseObjects( anEntryList, true, false );
1420 //================================================================================
1422 * \brief SLOT called when a selected cell in table() changed
1424 //================================================================================
1426 void SMESHGUI_BaseComputeOp::currentCellChanged()
1428 myTShapeDisplayer->SetVisibility( false );
1429 if ( myBadMeshDisplayer )
1430 myBadMeshDisplayer->SetVisibility( false );
1432 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1434 int nbSelected = SMESH::getSelectedRows( table(), rows );
1436 foreach ( row, rows )
1438 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1439 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1440 if ( hasData && !isPublished )
1441 publishEnable = true;
1443 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1444 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1446 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1453 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1456 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1457 myCompDlg->myShowBtn ->setEnabled( showEnable );
1458 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1459 myCompDlg->myBadMeshToGroupBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1462 //================================================================================
1464 * \brief update preview
1466 //================================================================================
1468 void SMESHGUI_BaseComputeOp::onPreviewShape()
1470 if ( myTShapeDisplayer )
1472 SUIT_OverrideCursor aWaitCursor;
1474 SMESH::getSelectedRows( table(), rows );
1476 bool showOnly = true;
1478 foreach ( row, rows )
1480 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1482 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1486 currentCellChanged(); // to update buttons
1490 //================================================================================
1494 //================================================================================
1496 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1500 delete myTShapeDisplayer;
1501 if ( myBadMeshDisplayer )
1502 delete myBadMeshDisplayer;
1505 //================================================================================
1507 * \brief Gets dialog of compute operation
1508 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1510 //================================================================================
1512 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1516 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1517 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1518 // connect signals and slots
1519 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1520 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1521 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1522 connect(myCompDlg->myBadMeshToGroupBtn, SIGNAL (clicked()), SLOT(onGroupOfBadMesh()));
1524 QTableWidget* aTable = me->table();
1525 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1526 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1531 //================================================================================
1533 * \brief returns from compute mesh result dialog
1535 //================================================================================
1537 bool SMESHGUI_BaseComputeOp::onApply()
1542 //================================================================================
1544 * \brief Return a table
1546 //================================================================================
1548 QTableWidget* SMESHGUI_BaseComputeOp::table()
1550 return myCompDlg->myTable;
1554 //================================================================================
1556 * \brief Constructor
1558 //================================================================================
1560 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1561 : SMESHGUI_BaseComputeOp()
1563 myHelpFileName = "constructing_meshes.html#compute-anchor";
1567 //================================================================================
1571 //================================================================================
1573 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1577 //================================================================================
1579 * \brief perform it's intention action: compute mesh
1581 //================================================================================
1583 void SMESHGUI_ComputeOp::startOperation()
1585 SMESHGUI_BaseComputeOp::startOperation();
1586 if (myMesh->_is_nil())
1591 //================================================================================
1593 * \brief Gets dialog of this operation
1594 * \retval LightApp_Dialog* - pointer to dialog of this operation
1596 //================================================================================
1598 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1600 return computeDlg();
1603 //================================================================================
1605 * \brief Constructor
1607 //================================================================================
1609 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1610 : SMESHGUI_BaseComputeOp(),
1613 myPreviewDisplayer( 0 ),
1618 //================================================================================
1622 //================================================================================
1624 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1631 if ( myPreviewDisplayer )
1632 delete myPreviewDisplayer;
1633 myPreviewDisplayer = 0;
1636 //================================================================================
1638 * \brief Gets current dialog of this operation
1639 * \retval LightApp_Dialog* - pointer to dialog of this operation
1641 //================================================================================
1643 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1648 //================================================================================
1650 * \brief perform it's intention action: prepare data
1652 //================================================================================
1654 void SMESHGUI_PrecomputeOp::startOperation()
1656 myHelpFileName = "constructing_meshes.html#preview-anchor"; // other anchor onCompute()
1660 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1663 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1664 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1665 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1667 myActiveDlg = myDlg;
1669 // connect signal to compute dialog. which will be shown after Compute mesh operation
1670 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1673 // disconnect signals
1674 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1675 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1676 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1677 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1678 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1681 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1682 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1683 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1684 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1685 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1686 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1687 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1688 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1689 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1690 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1693 SMESHGUI_BaseComputeOp::startOperation();
1694 if (myMesh->_is_nil())
1697 if (myDlg->getPreviewMode() == -1)
1699 // nothing to preview
1700 SUIT_MessageBox::warning(desktop(),
1701 tr("SMESH_WRN_WARNING"),
1702 tr("SMESH_WRN_NOTHING_PREVIEW"));
1707 // disconnect slot from preview dialog to have Apply from results of compute operation only
1708 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1709 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1714 //================================================================================
1716 * \brief Stops operation
1718 //================================================================================
1720 void SMESHGUI_PrecomputeOp::stopOperation()
1722 if ( myPreviewDisplayer )
1724 myPreviewDisplayer->SetVisibility( false );
1725 delete myPreviewDisplayer;
1726 myPreviewDisplayer = 0;
1728 myMapShapeId.clear();
1729 SMESHGUI_BaseComputeOp::stopOperation();
1732 //================================================================================
1734 * \brief reinitialize dialog after operaiton become active again
1736 //================================================================================
1738 void SMESHGUI_PrecomputeOp::resumeOperation()
1740 if ( myActiveDlg == myDlg )
1742 SMESHGUI_BaseComputeOp::resumeOperation();
1745 //================================================================================
1747 * \brief perform it's intention action: reinitialise dialog
1749 //================================================================================
1751 void SMESHGUI_PrecomputeOp::initDialog()
1755 QMap<int, int> modeMap;
1756 _PTR(SObject) pMesh = SMESH::getStudy()->FindObjectID( myIObject->getEntry() );
1757 getAssignedAlgos( pMesh, modeMap );
1758 if ( modeMap.contains( SMESH::DIM_3D ) )
1760 if ( modeMap.contains( SMESH::DIM_2D ) )
1761 modes.append( SMESH::DIM_2D );
1762 if ( modeMap.contains( SMESH::DIM_1D ) )
1763 modes.append( SMESH::DIM_1D );
1765 else if ( modeMap.contains( SMESH::DIM_2D ) )
1767 if ( modeMap.contains( SMESH::DIM_1D ) )
1768 modes.append( SMESH::DIM_1D );
1771 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1772 myOrderMgr->SetMesh( myMesh );
1773 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1774 myDlg->getMeshOrderBox()->setVisible(isOrder);
1780 myDlg->setPreviewModes( modes );
1783 //================================================================================
1785 * \brief detect assigned mesh algorithms
1787 //================================================================================
1789 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1790 QMap<int,int>& theModeMap)
1792 if ( !theMesh ) return;
1794 _PTR(SObject) aHypFolder;
1795 _PTR(GenericAttribute) anAttr;
1796 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1797 if ( theMesh->FindSubObject( aPart, aHypFolder ))
1799 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1800 for ( ; anIter->More(); anIter->Next() )
1802 _PTR(SObject) anObj = anIter->Value();
1803 _PTR(SObject) aRefObj;
1804 if ( anObj->ReferencedObject( aRefObj ) )
1809 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1811 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1812 if ( CORBA::is_nil( aVar ) )
1815 SMESH::SMESH_Algo_var algo;
1816 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1819 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1820 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1821 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1824 if ( !algo->_is_nil() )
1826 theModeMap[ dim ] = 0;
1827 if ( theModeMap.size() == 3 )
1837 for ( aPart = SMESH::Tag_SubMeshOnEdge; aPart <= SMESH::Tag_LastSubMesh; ++aPart )
1839 if ( !theMesh->FindSubObject( aPart, aHypFolder ))
1842 _PTR(ChildIterator) anIter = SMESH::getStudy()->NewChildIterator( aHypFolder );
1843 for ( anIter->InitEx(true); anIter->More(); anIter->Next() )
1845 _PTR(SObject) anObj = anIter->Value();
1846 _PTR(SObject) aRefObj;
1847 if ( anObj->ReferencedObject( aRefObj ) )
1852 if ( anObj->FindAttribute( anAttr, "AttributeName" ))
1854 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1855 if ( CORBA::is_nil( aVar ) )
1858 SMESH::SMESH_Algo_var algo;
1859 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1862 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1863 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1864 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1867 if ( !algo->_is_nil() )
1869 theModeMap[ dim ] = 0;
1870 if ( theModeMap.size() == 3 )
1880 //================================================================================
1882 * \brief perform it's intention action: compute mesh
1884 //================================================================================
1886 void SMESHGUI_PrecomputeOp::onCompute()
1889 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1890 myOrderMgr->SetMeshOrder();
1891 myMapShapeId.clear();
1892 myActiveDlg = computeDlg();
1893 myHelpFileName = "constructing_meshes.html#compute-anchor";
1897 //================================================================================
1899 * \brief perform it's intention action: compute mesh
1901 //================================================================================
1903 void SMESHGUI_PrecomputeOp::onCancel()
1905 QObject* curDlg = sender();
1906 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1908 // return from error messages
1913 bool isRestoreOrder = false;
1914 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1916 // ask to remove already computed mesh elements
1917 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1918 tr( "CLEAR_SUBMESH_QUESTION" ),
1919 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1921 // remove all submeshes for collected shapes
1922 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1923 for ( ; it != myMapShapeId.constEnd(); ++it )
1924 myMesh->ClearSubMesh( it.key() );
1925 isRestoreOrder = true;
1929 // return previous mesh order
1930 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1931 if (!isRestoreOrder)
1933 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1934 tr( "SMESH_REJECT_MESH_ORDER" ),
1935 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1937 myOrderMgr->SetMeshOrder(myPrevOrder);
1943 myMapShapeId.clear();
1944 SMESHGUI_BaseComputeOp::onCancel();
1947 //================================================================================
1949 * \brief perform it's intention action: preview mesh
1951 //================================================================================
1953 void SMESHGUI_PrecomputeOp::onPreview()
1955 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1958 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1962 // set modified submesh priority if any
1963 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1964 myOrderMgr->SetMeshOrder();
1966 // Compute preview of mesh,
1967 // i.e. compute mesh till indicated dimension
1968 int dim = myDlg->getPreviewMode();
1970 SMESH::MemoryReserve aMemoryReserve;
1972 SMESH::compute_error_array_var aCompErrors;
1975 bool computeFailed = true, memoryLack = false;
1977 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1979 SMESHGUI* gui = getSMESHGUI();
1980 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1981 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1982 if ( errors->length() > 0 ) {
1983 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1986 SUIT_OverrideCursor aWaitCursor;
1988 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1989 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1990 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1992 SMESH::long_array_var aShapesId = new SMESH::long_array();
1996 SMESH::MeshPreviewStruct_var previewData =
1997 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1999 if ( & previewData.in() && previewData->nodesXYZ.length() > 0 )
2001 computeFailed = false;
2002 myPreviewDisplayer->SetData( previewData );
2003 // append shape indices with computed mesh entities
2004 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
2005 myMapShapeId[ aShapesId[ i ] ] = 0;
2008 myPreviewDisplayer->SetVisibility(false);
2010 catch(const SALOME::SALOME_Exception & S_ex){
2012 myPreviewDisplayer->SetVisibility(false);
2017 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2018 // check if there are memory problems
2019 for ( CORBA::ULong i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
2020 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
2022 catch(const SALOME::SALOME_Exception & S_ex){
2027 aMemoryReserve.release();
2029 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2030 bool noHypoError = ( aHypErrors.isEmpty() );
2032 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
2033 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2035 bool isShowError = true;
2036 switch( aNotifyMode ) {
2037 case 0: // show the mesh computation result dialog NEVER
2038 isShowError = false;
2040 case 1: // show the mesh computation result dialog if there are some errors
2041 default: // show the result dialog after each mesh computation
2042 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
2043 isShowError = false;
2047 aWaitCursor.suspend();
2052 aCompDlg->setWindowTitle
2053 ( tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED" ));
2054 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
2059 //================================================================================
2061 * \brief Constructor
2063 //================================================================================
2065 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
2066 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
2069 setWindowTitle( tr( "CAPTION" ) );
2071 setButtonText( OK, tr( "COMPUTE" ) );
2072 QFrame* main = mainFrame();
2073 main->setMinimumWidth( 300 );
2075 QVBoxLayout* layout = new QVBoxLayout( main );
2077 myOrderBox = new SMESHGUI_MeshOrderBox( main );
2078 layout->addWidget(myOrderBox);
2080 QFrame* frame = new QFrame( main );
2081 layout->setMargin(0); layout->setSpacing(0);
2082 layout->addWidget( frame );
2084 QHBoxLayout* frameLay = new QHBoxLayout( frame );
2085 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
2087 myPreviewMode = new QtxComboBox( frame );
2088 frameLay->addWidget( myPreviewMode );
2090 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
2091 frameLay->addWidget( myPreviewBtn );
2093 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
2096 //================================================================================
2100 //================================================================================
2102 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
2106 //================================================================================
2108 * \brief Sets available preview modes
2110 //================================================================================
2112 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
2114 myPreviewMode->clear();
2115 QList<int>::const_iterator it = theModes.constBegin();
2116 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
2118 QString mode = QString( "PREVIEW_%1" ).arg( *it );
2119 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
2120 myPreviewMode->setId( i, *it );
2122 myPreviewBtn->setEnabled( !theModes.isEmpty() );
2125 //================================================================================
2127 * \brief Returns current preview mesh mode
2129 //================================================================================
2131 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
2133 return myPreviewMode->currentId().toInt();
2136 //================================================================================
2138 * \brief Returns current preview mesh mode
2140 //================================================================================
2142 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
2148 //================================================================================
2150 * \brief Constructor
2152 //================================================================================
2154 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
2155 : SMESHGUI_BaseComputeOp()
2157 myHelpFileName = "constructing_meshes.html#evaluate-anchor";
2161 //================================================================================
2165 //================================================================================
2167 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
2171 //================================================================================
2173 * \brief perform it's intention action: compute mesh
2175 //================================================================================
2177 void SMESHGUI_EvaluateOp::startOperation()
2179 SMESHGUI_BaseComputeOp::evaluateDlg();
2180 SMESHGUI_BaseComputeOp::startOperation();
2181 if (myMesh->_is_nil())
2186 //================================================================================
2188 * \brief Gets dialog of this operation
2189 * \retval LightApp_Dialog* - pointer to dialog of this operation
2191 //================================================================================
2193 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
2195 return evaluateDlg();
2198 //================================================================================
2200 * \brief evaluateMesh()
2202 //================================================================================
2204 void SMESHGUI_BaseComputeOp::evaluateMesh()
2208 SMESH::MemoryReserve aMemoryReserve;
2210 SMESH::compute_error_array_var aCompErrors;
2213 bool evaluateFailed = true, memoryLack = false;
2214 SMESH::smIdType_array_var aRes;
2216 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
2217 if ( !aMeshSObj ) // IPAL21340
2220 bool hasShape = myMesh->HasShapeToMesh();
2221 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
2224 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2225 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
2226 if ( errors->length() > 0 ) {
2227 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
2229 SUIT_OverrideCursor aWaitCursor;
2232 aRes = gen->Evaluate(myMesh, myMainShape);
2234 catch(const SALOME::SALOME_Exception & S_ex){
2240 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
2242 catch(const SALOME::SALOME_Exception & S_ex){
2248 aMemoryReserve.release();
2250 evaluateFailed = ( aCompErrors->length() > 0 );
2251 myCompDlg->setWindowTitle
2252 ( tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED" ));
2256 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
2257 bool noHypoError = ( aHypErrors.isEmpty() );
2259 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
2260 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
2262 bool isShowResultDlg = true;
2264 //switch( aNotifyMode ) {
2265 //case 0: // show the mesh computation result dialog NEVER
2266 //isShowResultDlg = false;
2269 //case 1: // show the mesh computation result dialog if there are some errors
2270 //if ( memoryLack || !noHypoError )
2271 // isShowResultDlg = true;
2274 // isShowResultDlg = false;
2278 //default: // show the result dialog after each mesh computation
2279 //isShowResultDlg = true;
2283 if ( isShowResultDlg )
2284 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
2285 noHypoError, aHypErrors);
2289 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::smIdType_array& theRes,
2290 const bool theMemoryLack,
2291 const bool theNoCompError,
2292 SMESH::compute_error_array_var& theCompErrors,
2293 const bool theNoHypoError,
2294 const QString& theHypErrors)
2296 bool hasShape = myMesh->HasShapeToMesh();
2297 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
2298 aCompDlg->myMemoryLackGroup->hide();
2300 if ( theMemoryLack )
2302 aCompDlg->myMemoryLackGroup->show();
2303 aCompDlg->myFullInfo->hide();
2304 aCompDlg->myBriefInfo->hide();
2305 aCompDlg->myHypErrorGroup->hide();
2306 aCompDlg->myCompErrorGroup->hide();
2308 else if ( theNoCompError && theNoHypoError )
2310 aCompDlg->myFullInfo->SetMeshInfo( theRes );
2311 aCompDlg->myFullInfo->show();
2312 aCompDlg->myBriefInfo->hide();
2313 aCompDlg->myHypErrorGroup->hide();
2314 aCompDlg->myCompErrorGroup->hide();
2318 QTableWidget* tbl = aCompDlg->myTable;
2319 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
2320 aCompDlg->myBriefInfo->show();
2321 aCompDlg->myFullInfo->hide();
2323 if ( theNoHypoError ) {
2324 aCompDlg->myHypErrorGroup->hide();
2327 aCompDlg->myHypErrorGroup->show();
2328 aCompDlg->myHypErrorLabel->setText( theHypErrors );
2331 if ( theNoCompError ) {
2332 aCompDlg->myCompErrorGroup->hide();
2335 aCompDlg->myCompErrorGroup->show();
2337 aCompDlg->myPublishBtn->hide();
2338 aCompDlg->myShowBtn->hide();
2340 // fill table of errors
2341 tbl->setRowCount( theCompErrors->length() );
2342 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
2343 else tbl->showColumn( COL_SHAPE );
2344 tbl->setColumnWidth( COL_ERROR, 200 );
2346 bool hasBadMesh = false;
2347 for ( int row = 0; row < (int) theCompErrors->length(); ++row )
2349 SMESH::ComputeError & err = theCompErrors[ row ];
2351 QString text = err.algoName.in();
2352 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
2353 else tbl->item( row, COL_ALGO )->setText( text );
2355 text = SMESH::errorText( err.code, err.comment.in() );
2356 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
2357 else tbl->item( row, COL_ERROR )->setText( text );
2359 text = QString("%1").arg( err.subShapeID );
2360 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
2361 else tbl->item( row, COL_SHAPEID )->setText( text );
2363 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
2364 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
2365 else tbl->item( row, COL_SHAPE )->setText( text );
2367 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
2368 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
2369 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
2371 text = err.hasBadMesh ? "hasBadMesh" : "";
2372 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
2373 else tbl->item( row, COL_BAD_MESH )->setText( text );
2374 if ( err.hasBadMesh ) hasBadMesh = true;
2376 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
2377 tbl->resizeRowToContents( row );
2379 tbl->resizeColumnToContents( COL_ALGO );
2380 tbl->resizeColumnToContents( COL_SHAPE );
2381 tbl->setWordWrap( true );
2385 aCompDlg->myBadMeshBtn->show();
2386 aCompDlg->myBadMeshToGroupBtn->show();
2390 aCompDlg->myBadMeshBtn->hide();
2391 aCompDlg->myBadMeshToGroupBtn->hide();
2393 tbl->setCurrentCell(0,0);
2394 currentCellChanged(); // to update buttons
2397 // show dialog and wait, because Compute can be invoked from Preview operation
2398 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
2403 //================================================================================
2405 * \brief Gets dialog of evaluate operation
2406 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
2408 //================================================================================
2410 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
2414 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
2415 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
2416 // connect signals and slots
2417 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
2418 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
2419 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
2420 QTableWidget* aTable = me->table();
2421 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
2422 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
2427 //================================================================================
2429 * \brief SMESHGUI_BaseComputeOp constructor
2431 //================================================================================
2433 SMESHGUI_ShowErrorsOp::SMESHGUI_ShowErrorsOp():
2434 SMESHGUI_BaseComputeOp()
2438 //================================================================================
2440 * \brief Start SMESHGUI_ShowErrorsOp
2442 //================================================================================
2444 void SMESHGUI_ShowErrorsOp::startOperation()
2446 SMESHGUI_BaseComputeOp::startOperation();
2448 if ( myMesh->_is_nil() )
2451 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
2452 SMESH::compute_error_array_var compErrors = gen->GetComputeErrors( myMesh, myMainShape );
2454 if ( compErrors->length() == 0 )
2457 showComputeResult( /*MemoryLack=*/false, /*NoCompError=*/false, compErrors,
2458 /*NoHypoError=*/true, hypErrors );
2460 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
2461 aCompDlg->setWindowTitle( tr( "SMESH_WRN_COMPUTE_FAILED" ));
2462 aCompDlg->myFullInfo->hide();
2463 aCompDlg->myBriefInfo->hide();