1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_ComputeDlg.cxx
23 // Author : Edward AGAPOV, Open CASCADE S.A.S.
26 #include "SMESHGUI_ComputeDlg.h"
29 #include "SMESHGUI_GEOMGenUtils.h"
30 #include "SMESHGUI_MeshUtils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_MeshInfosBox.h"
33 #include "SMESHGUI_HypothesesUtils.h"
34 #include "SMESHGUI_MeshEditPreview.h"
35 #include "SMESHGUI_MeshOrderOp.h"
36 #include "SMESHGUI_MeshOrderDlg.h"
38 #include "SMESH_ActorUtils.h"
40 #include <SMDS_SetIterator.hxx>
41 #include <SMDS_Mesh.hxx>
43 // SALOME GEOM includes
45 #include <GEOM_Actor.h>
47 // SALOME GUI includes
48 #include <LightApp_SelectionMgr.h>
49 #include <LightApp_UpdateFlags.h>
50 #include <SALOME_ListIO.hxx>
51 #include <SVTK_ViewWindow.h>
52 #include <SVTK_ViewModel.h>
53 #include <SalomeApp_Application.h>
54 #include <SUIT_ResourceMgr.h>
55 #include <SUIT_OverrideCursor.h>
56 #include <SUIT_MessageBox.h>
57 #include <SUIT_Desktop.h>
58 #include <QtxComboBox.h>
60 // SALOME KERNEL includes
61 #include <SALOMEDS_SObject.hxx>
62 #include <SALOMEDSClient_SObject.hxx>
65 #include <BRep_Tool.hxx>
67 #include <TopExp_Explorer.hxx>
68 #include <TopTools_IndexedMapOfShape.hxx>
71 #include <TopLoc_Location.hxx>
72 #include <Poly_Triangulation.hxx>
73 #include <Bnd_Box.hxx>
74 #include <BRepBndLib.hxx>
75 #include <BRepMesh_IncrementalMesh.hxx>
77 #include <Standard_ErrorHandler.hxx>
81 #include <QPushButton>
83 #include <QRadioButton>
84 #include <QTableWidget>
85 #include <QHeaderView>
86 #include <QGridLayout>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QButtonGroup>
92 #include <vtkProperty.h>
101 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
103 static void addSeparator( QWidget* parent )
105 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
106 int row = l->rowCount();
107 int cols = l->columnCount();
108 for ( int i = 0; i < cols; i++ ) {
109 QFrame* hline = new QFrame( parent );
110 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
111 l->addWidget( hline, row, i );
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( 250, 0, 250 );
154 myProperty->SetAmbientColor( 250, 0, 250 );
155 myProperty->SetDiffuseColor( 250, 0, 250 );
156 //myProperty->SetSpecularColor( 250, 0, 250 );
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 std::string mainEntry;
204 if ( !aMainShape->_is_nil() )
205 mainEntry = aMainShape->GetStudyEntry();
206 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
209 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
210 checkTriangulation( aShape );
211 TopExp::MapShapes(aShape, myIndexToShape);
212 myActors.resize( myIndexToShape.Extent(), 0 );
213 myShownActors.reserve( myIndexToShape.Extent() );
215 myMainEntry = mainEntry;
216 myViewWindow = aViewWindow;
218 if ( only ) { // hide shown actors
219 TActorIterator actorIt = shownIterator();
220 while ( actorIt.more() )
221 if (VTKViewer_Actor* anActor = actorIt.next())
222 anActor->SetVisibility(false);
223 myShownActors.clear();
225 // find actors to show
226 TopoDS_Shape aShape = myIndexToShape( subShapeID );
227 if ( !aShape.IsNull() ) {
228 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
229 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
230 //checkTriangulation( exp.Current() );
231 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
232 myShownActors.push_back( anActor );
234 if ( type == TopAbs_FACE ) {
235 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
236 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
237 if ( !BRep_Tool::Degenerated( edge ))
238 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
239 myShownActors.push_back( anActor );
243 myBuiltSubs.insert( subShapeID );
246 // -----------------------------------------------------------------------
250 typedef std::vector<GEOM_Actor*> TActorVec;
252 TActorVec myShownActors;
253 TopTools_IndexedMapOfShape myIndexToShape;
254 std::string myMainEntry;
255 SVTK_ViewWindow* myViewWindow;
256 vtkProperty* myProperty;
257 std::set<int> myBuiltSubs;
259 // -----------------------------------------------------------------------
260 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
261 TActorIterator actorIterator() {
262 return TActorIterator( myActors.begin(), myActors.end() );
264 TActorIterator shownIterator() {
265 return TActorIterator( myShownActors.begin(), myShownActors.end() );
267 // -----------------------------------------------------------------------
268 GEOM_Actor* getActor(const TopoDS_Shape& shape)
270 int index = myIndexToShape.FindIndex( shape ) - 1;
271 if ( index < 0 || index >= myActors.size() )
273 GEOM_Actor* & actor = myActors[ index ];
275 actor = GEOM_Actor::New();
277 actor->SetShape(shape,0,0);
278 actor->SetProperty(myProperty);
279 actor->SetShadingProperty(myProperty);
280 actor->SetWireframeProperty(myProperty);
281 actor->SetPreviewProperty(myProperty);
282 actor->PickableOff();
283 // if ( shape.ShapeType() == TopAbs_EDGE )
284 // actor->SubShapeOn();
285 myViewWindow->AddActor( actor );
290 // -----------------------------------------------------------------------
291 void checkTriangulation(const TopoDS_Shape& shape)
293 TopLoc_Location aLoc;
294 Standard_Boolean alreadymesh = Standard_True;
295 TopExp_Explorer ex(shape, TopAbs_FACE);
297 for ( ; ex.More(); ex.Next()) {
298 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
299 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
300 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
303 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
304 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
305 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
306 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
308 if (alreadymesh) return;
309 // Compute default deflection
311 BRepBndLib::Add(shape, B);
312 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
313 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
314 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
315 BRepMesh_IncrementalMesh MESH(shape,deflection);
317 // -----------------------------------------------------------------------
318 bool hasViewWindow() const
320 if ( !myViewWindow ) return false;
322 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
323 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
329 // =========================================================================================
331 * \brief Return text describing an error
333 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
334 QString errorText(int errCode, const char* comment)
338 CASE2TEXT( COMPERR_OK );
339 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
340 CASE2TEXT( COMPERR_STD_EXCEPTION );
341 CASE2TEXT( COMPERR_OCC_EXCEPTION );
342 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
343 CASE2TEXT( COMPERR_EXCEPTION );
344 CASE2TEXT( COMPERR_MEMORY_PB );
345 CASE2TEXT( COMPERR_BAD_SHAPE );
346 CASE2TEXT( COMPERR_BAD_FACE );
347 case SMESH::COMPERR_ALGO_FAILED:
348 if ( strlen(comment) == 0 )
349 text = QObject::tr("COMPERR_ALGO_FAILED");
352 text = QString("#%1").arg( -errCode );
354 if ( text.length() > 0 ) text += ". ";
355 return text + comment;
357 // -----------------------------------------------------------------------
359 * \brief Return SO of a subshape
361 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
363 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
364 if ( subShapeID == 1 || !so )
366 _PTR(ChildIterator) it;
367 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
368 it = study->NewChildIterator(so);
371 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
372 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
373 if ( !geom->_is_nil() ) {
374 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
375 if ( list->length() == 1 && list[0] == subShapeID )
382 // -----------------------------------------------------------------------
384 * \brief Return subshape by ID
386 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
388 GEOM::GEOM_Object_var aSubShape;
389 if ( subShapeID == 1 )
390 aSubShape = aMainShape;
391 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
392 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
394 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
395 return aSubShape._retn();
397 // -----------------------------------------------------------------------
399 * \brief Return shape type name
401 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
402 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
405 if ( !aShape->_is_nil() ) {
406 switch ( aShape->GetShapeType() ) {
413 CASE2NAME( COMPSOLID );
414 CASE2NAME( COMPOUND );
420 // -----------------------------------------------------------------------
422 * \brief Return text describing a subshape
424 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
427 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
428 text = aSO->GetName().c_str();
430 text = QString("#%1").arg( subShapeID );
431 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
432 if ( typeName.length() )
433 text += QString(" (%1)").arg(typeName);
437 // -----------------------------------------------------------------------
439 * \brief Return a list of selected rows
441 int getSelectedRows(QTableWidget* table, QList<int>& rows)
444 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
445 QTableWidgetSelectionRange range;
446 foreach( range, selRanges )
448 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
451 if ( rows.isEmpty() && table->currentRow() > -1 )
452 rows.append( table->currentRow() );
460 // =========================================================================================
462 * \brief Dialog to compute a mesh and show computation errors
464 //=======================================================================
466 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
467 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
469 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
470 aDlgLay->setMargin( 0 );
471 aDlgLay->setSpacing( SPACING );
473 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
475 aDlgLay->addWidget(aMainFrame);
477 aDlgLay->setStretchFactor(aMainFrame, 1);
480 // =========================================================================================
484 //=======================================================================
486 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
490 //=======================================================================
491 // function : createMainFrame()
492 // purpose : Create frame containing dialog's fields
493 //=======================================================================
495 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
497 QFrame* aFrame = new QFrame(theParent);
499 SUIT_ResourceMgr* rm = resourceMgr();
500 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
506 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
509 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
511 QButtonGroup* aBtnGrp = new QButtonGroup(this);
512 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
513 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
515 QRadioButton* aRBut = new QRadioButton(aPixGrp);
516 aRBut->setIcon(iconCompute);
517 aRBut->setChecked(true);
518 aPixGrpLayout->addWidget(aRBut);
519 aBtnGrp->addButton(aRBut, 0);
523 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
524 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
525 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
526 myMeshName = new QLabel(nameBox);
527 nameBoxLayout->addWidget(myMeshName);
531 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
532 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
534 // Computation errors
536 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
537 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
538 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
539 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
540 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
542 //myTable->setReadOnly( true ); // VSR: check
543 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
544 myTable->hideColumn( COL_PUBLISHED );
545 myTable->hideColumn( COL_SHAPEID );
546 myTable->hideColumn( COL_BAD_MESH );
547 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
550 headers << tr( "COL_ALGO_HEADER" );
551 headers << tr( "COL_SHAPE_HEADER" );
552 headers << tr( "COL_ERROR_HEADER" );
553 headers << tr( "COL_SHAPEID_HEADER" );
554 headers << tr( "COL_PUBLISHED_HEADER" );
556 myTable->setHorizontalHeaderLabels( headers );
559 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
560 grpLayout->setSpacing(SPACING);
561 grpLayout->setMargin(MARGIN);
562 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
563 grpLayout->addWidget( myShowBtn, 0, 1 );
564 grpLayout->addWidget( myPublishBtn, 1, 1 );
565 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
566 grpLayout->setRowStretch( 3, 1 );
568 // Hypothesis definition errors
570 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
571 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
572 myHypErrorGroupLayout->setMargin(MARGIN);
573 myHypErrorGroupLayout->setSpacing(SPACING);
574 myHypErrorLabel = new QLabel(myHypErrorGroup);
575 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
579 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
580 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
581 myMemoryLackGroupLayout->setMargin(MARGIN);
582 myMemoryLackGroupLayout->setSpacing(SPACING);
583 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
584 QFont bold = memLackLabel->font(); bold.setBold(true);
585 memLackLabel->setFont( bold );
586 memLackLabel->setMinimumWidth(300);
587 myMemoryLackGroupLayout->addWidget(memLackLabel);
589 // add all widgets to aFrame
590 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
591 aLay->setMargin( 0 );
592 aLay->setSpacing( 0 );
593 aLay->addWidget( aPixGrp );
594 aLay->addWidget( nameBox );
595 aLay->addWidget( myBriefInfo );
596 aLay->addWidget( myFullInfo );
597 aLay->addWidget( myHypErrorGroup );
598 aLay->addWidget( myCompErrorGroup );
599 aLay->addWidget( myMemoryLackGroup );
600 aLay->setStretchFactor( myCompErrorGroup, 1 );
602 ((QPushButton*) button( OK ))->setDefault( true );
607 //================================================================================
611 //================================================================================
613 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
614 : SMESHGUI_Operation(), myCompDlg( 0 )
616 myTShapeDisplayer = new SMESH::TShapeDisplayer();
617 myBadMeshDisplayer = 0;
619 //myHelpFileName = "/files/about_meshes.htm"; // V3
620 myHelpFileName = "about_meshes_page.html"; // V4
623 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
625 LightApp_SelectionMgr* Sel = selectionMgr();
626 SALOME_ListIO selected; Sel->selectedObjects( selected );
627 Handle(SALOME_InteractiveObject) anIO = selected.First();
628 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
629 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
632 //================================================================================
634 * \brief Start operation
635 * \purpose Init dialog fields, connect signals and slots, show dialog
637 //================================================================================
639 void SMESHGUI_BaseComputeOp::startOperation()
641 // create compute dialog if not created before
644 myMesh = SMESH::SMESH_Mesh::_nil();
645 myMainShape = GEOM::GEOM_Object::_nil();
648 LightApp_SelectionMgr *Sel = selectionMgr();
649 SALOME_ListIO selected; Sel->selectedObjects( selected );
651 int nbSel = selected.Extent();
653 SUIT_MessageBox::warning(desktop(),
654 tr("SMESH_WRN_WARNING"),
655 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
660 myIObject = selected.First();
661 myMesh = SMESH::GetMeshByIO(myIObject);
662 if (myMesh->_is_nil()) {
663 SUIT_MessageBox::warning(desktop(),
664 tr("SMESH_WRN_WARNING"),
665 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
669 myMainShape = myMesh->GetShapeToMesh();
671 SMESHGUI_Operation::startOperation();
674 //================================================================================
676 * \brief computeMesh()
678 //================================================================================
680 void SMESHGUI_BaseComputeOp::computeMesh()
684 SMESH::MemoryReserve aMemoryReserve;
686 SMESH::compute_error_array_var aCompErrors;
689 bool computeFailed = true, memoryLack = false;
691 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
692 if ( !aMeshSObj ) // IPAL 21340
694 bool hasShape = myMesh->HasShapeToMesh();
695 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
698 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
699 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
700 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
701 if ( errors->length() > 0 ) {
702 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
704 SUIT_OverrideCursor aWaitCursor;
706 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
709 if (gen->Compute(myMesh, myMainShape))
710 computeFailed = false;
712 catch(const SALOME::SALOME_Exception & S_ex){
716 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
719 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
720 // check if there are memory problems
721 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
722 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
724 catch(const SALOME::SALOME_Exception & S_ex){
728 // NPAL16631: if ( !memoryLack )
730 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
731 update( UF_ObjBrowser | UF_Model );
734 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
735 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
738 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
741 SMESH::Update(myIObject, true);
745 MESSAGE ( "Exception thrown during mesh visualization" );
747 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
748 SMESH::OnVisuException();
755 LightApp_SelectionMgr *Sel = selectionMgr();
758 SALOME_ListIO selected;
759 selected.Append( myIObject );
760 Sel->setSelectedObjects( selected );
766 aMemoryReserve.release();
768 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
772 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
773 bool noHypoError = ( aHypErrors.isEmpty() );
775 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
776 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
778 bool isShowResultDlg = true;
779 switch( aNotifyMode ) {
780 case 0: // show the mesh computation result dialog NEVER
781 isShowResultDlg = false;
784 case 1: // show the mesh computation result dialog if there are some errors
785 if ( memoryLack || !noCompError || !noHypoError )
786 isShowResultDlg = true;
789 isShowResultDlg = false;
793 default: // show the result dialog after each mesh computation
794 isShowResultDlg = true;
798 if ( isShowResultDlg )
799 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
802 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
803 const bool theNoCompError,
804 SMESH::compute_error_array_var& theCompErrors,
805 const bool theNoHypoError,
806 const QString& theHypErrors )
808 bool hasShape = myMesh->HasShapeToMesh();
809 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
810 aCompDlg->myMemoryLackGroup->hide();
814 aCompDlg->myMemoryLackGroup->show();
815 aCompDlg->myFullInfo->hide();
816 aCompDlg->myBriefInfo->hide();
817 aCompDlg->myHypErrorGroup->hide();
818 aCompDlg->myCompErrorGroup->hide();
820 else if ( theNoCompError && theNoHypoError )
822 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
823 aCompDlg->myFullInfo->SetMeshInfo( aRes );
824 aCompDlg->myFullInfo->show();
825 aCompDlg->myBriefInfo->hide();
826 aCompDlg->myHypErrorGroup->hide();
827 aCompDlg->myCompErrorGroup->hide();
831 QTableWidget* tbl = aCompDlg->myTable;
832 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
833 aCompDlg->myFullInfo->SetMeshInfo( aRes );
834 aCompDlg->myBriefInfo->show();
835 aCompDlg->myFullInfo->hide();
837 if ( theNoHypoError ) {
838 aCompDlg->myHypErrorGroup->hide();
841 aCompDlg->myHypErrorGroup->show();
842 aCompDlg->myHypErrorLabel->setText( theHypErrors );
845 if ( theNoCompError ) {
846 aCompDlg->myCompErrorGroup->hide();
849 aCompDlg->myCompErrorGroup->show();
852 aCompDlg->myPublishBtn->hide();
853 aCompDlg->myShowBtn->hide();
856 aCompDlg->myPublishBtn->show();
857 aCompDlg->myShowBtn->show();
860 // fill table of errors
861 tbl->setRowCount( theCompErrors->length() );
862 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
863 else tbl->showColumn( COL_SHAPE );
864 tbl->setColumnWidth( COL_ERROR, 200 );
866 bool hasBadMesh = false;
867 for ( int row = 0; row < theCompErrors->length(); ++row )
869 SMESH::ComputeError & err = theCompErrors[ row ];
871 QString text = err.algoName.in();
872 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
873 else tbl->item( row, COL_ALGO )->setText( text );
875 text = SMESH::errorText( err.code, err.comment.in() );
876 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
877 else tbl->item( row, COL_ERROR )->setText( text );
879 text = QString("%1").arg( err.subShapeID );
880 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
881 else tbl->item( row, COL_SHAPEID )->setText( text );
883 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
884 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
885 else tbl->item( row, COL_SHAPE )->setText( text );
887 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
888 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
889 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
891 text = err.hasBadMesh ? "hasBadMesh" : "";
892 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
893 else tbl->item( row, COL_BAD_MESH )->setText( text );
894 if ( err.hasBadMesh ) hasBadMesh = true;
896 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
897 tbl->resizeRowToContents( row );
899 tbl->resizeColumnToContents( COL_ALGO );
900 tbl->resizeColumnToContents( COL_SHAPE );
903 aCompDlg->myBadMeshBtn->show();
905 aCompDlg->myBadMeshBtn->hide();
907 tbl->setCurrentCell(0,0);
908 currentCellChanged(); // to update buttons
911 // show dialog and wait, becase Compute can be invoked from Preview operation
912 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
916 //================================================================================
918 * \brief Stops operation
920 //================================================================================
922 void SMESHGUI_BaseComputeOp::stopOperation()
924 SMESHGUI_Operation::stopOperation();
925 if ( myTShapeDisplayer )
926 myTShapeDisplayer->SetVisibility( false );
927 if ( myBadMeshDisplayer ) {
928 myBadMeshDisplayer->SetVisibility( false );
929 // delete it in order not to have problems at its destruction when the viewer
930 // where it worked is dead due to e.g. study closing
931 delete myBadMeshDisplayer;
932 myBadMeshDisplayer = 0;
937 //================================================================================
939 * \brief publish selected subshape
941 //================================================================================
943 void SMESHGUI_BaseComputeOp::onPublishShape()
945 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
946 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
949 SMESH::getSelectedRows( table(), rows );
951 foreach ( row, rows )
953 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
954 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
955 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
957 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
959 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
960 SALOMEDS::SObject_var so =
961 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
962 // look for myMainShape in the table
963 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
964 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
965 if ( so->_is_nil() ) {
966 table()->item( r, COL_SHAPE )->setText( so->GetName() );
967 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
972 if ( curSub == 1 ) continue;
974 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
975 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
976 if ( !so->_is_nil() ) {
977 table()->item( row, COL_SHAPE )->setText( so->GetName() );
978 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
982 getSMESHGUI()->getApp()->updateObjectBrowser();
983 currentCellChanged(); // to update buttons
986 //================================================================================
988 * \brief show mesh elements preventing computation of a submesh of current row
990 //================================================================================
992 void SMESHGUI_BaseComputeOp::onShowBadMesh()
994 myTShapeDisplayer->SetVisibility( false );
996 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
997 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
999 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
1000 SMESHGUI* gui = getSMESHGUI();
1001 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1002 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1003 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1004 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1005 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1006 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1007 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1008 // delete property !!!!!!!!!!
1009 vtkProperty* prop = vtkProperty::New();
1010 prop->SetLineWidth( aLineWidth * 3 );
1011 prop->SetPointSize( aPointSize * 3 );
1012 prop->SetColor( 250, 0, 250 );
1013 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1014 myBadMeshDisplayer->SetData( aMeshData._retn() );
1019 //================================================================================
1021 * \brief SLOT called when a selected cell in table() changed
1023 //================================================================================
1025 void SMESHGUI_BaseComputeOp::currentCellChanged()
1027 myTShapeDisplayer->SetVisibility( false );
1028 if ( myBadMeshDisplayer )
1029 myBadMeshDisplayer->SetVisibility( false );
1031 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1033 int nbSelected = SMESH::getSelectedRows( table(), rows );
1035 foreach ( row, rows )
1037 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1038 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1039 if ( hasData && !isPublished )
1040 publishEnable = true;
1042 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1043 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1045 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1052 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1055 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1056 myCompDlg->myShowBtn ->setEnabled( showEnable );
1057 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1060 //================================================================================
1062 * \brief update preview
1064 //================================================================================
1066 void SMESHGUI_BaseComputeOp::onPreviewShape()
1068 if ( myTShapeDisplayer )
1070 SUIT_OverrideCursor aWaitCursor;
1072 SMESH::getSelectedRows( table(), rows );
1074 bool showOnly = true;
1076 foreach ( row, rows )
1078 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1080 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1084 currentCellChanged(); // to update buttons
1088 //================================================================================
1092 //================================================================================
1094 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1098 delete myTShapeDisplayer;
1099 if ( myBadMeshDisplayer )
1100 delete myBadMeshDisplayer;
1103 //================================================================================
1105 * \brief Gets dialog of compute operation
1106 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1108 //================================================================================
1110 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1114 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1115 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1116 // connect signals and slots
1117 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1118 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1119 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1121 QTableWidget* aTable = me->table();
1122 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1123 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1128 //================================================================================
1130 * \brief returns from compute mesh result dialog
1132 //================================================================================
1134 bool SMESHGUI_BaseComputeOp::onApply()
1139 //================================================================================
1141 * \brief Return a table
1143 //================================================================================
1145 QTableWidget* SMESHGUI_BaseComputeOp::table()
1147 return myCompDlg->myTable;
1151 //================================================================================
1153 * \brief Constructor
1155 //================================================================================
1157 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1158 : SMESHGUI_BaseComputeOp()
1163 //================================================================================
1165 * \brief Desctructor
1167 //================================================================================
1169 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1173 //================================================================================
1175 * \brief perform it's intention action: compute mesh
1177 //================================================================================
1179 void SMESHGUI_ComputeOp::startOperation()
1181 SMESHGUI_BaseComputeOp::startOperation();
1182 if (myMesh->_is_nil())
1187 //================================================================================
1189 * \brief check the same operations on the same mesh
1191 //================================================================================
1193 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1195 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1197 if ( !myMesh->_is_nil() && baseOp ) {
1198 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1199 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1204 //================================================================================
1206 * \brief Gets dialog of this operation
1207 * \retval LightApp_Dialog* - pointer to dialog of this operation
1209 //================================================================================
1211 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1213 return computeDlg();
1216 //================================================================================
1218 * \brief Constructor
1220 //================================================================================
1222 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1223 : SMESHGUI_BaseComputeOp(),
1227 myPreviewDisplayer( 0 )
1229 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1232 //================================================================================
1236 //================================================================================
1238 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1245 if ( myPreviewDisplayer )
1246 delete myPreviewDisplayer;
1247 myPreviewDisplayer = 0;
1250 //================================================================================
1252 * \brief Gets current dialog of this operation
1253 * \retval LightApp_Dialog* - pointer to dialog of this operation
1255 //================================================================================
1257 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1262 //================================================================================
1264 * \brief perform it's intention action: prepare data
1266 //================================================================================
1268 void SMESHGUI_PrecomputeOp::startOperation()
1272 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1275 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1276 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1277 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1279 myActiveDlg = myDlg;
1281 // connect signal to compute dialog. which will be shown after Compute mesh operation
1282 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1285 // disconnect signals
1286 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1287 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1288 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1289 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1290 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1293 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1294 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1295 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1296 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1297 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1298 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1299 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1300 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1301 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1302 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1305 SMESHGUI_BaseComputeOp::startOperation();
1306 if (myMesh->_is_nil())
1309 if (myDlg->getPreviewMode() == -1)
1311 // nothing to preview
1312 SUIT_MessageBox::warning(desktop(),
1313 tr("SMESH_WRN_WARNING"),
1314 tr("SMESH_WRN_NOTHING_PREVIEW"));
1319 // disconnect slot from preview dialog to have Apply from results of compute operation only
1320 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1321 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1326 //================================================================================
1328 * \brief Stops operation
1330 //================================================================================
1332 void SMESHGUI_PrecomputeOp::stopOperation()
1334 if ( myPreviewDisplayer )
1336 myPreviewDisplayer->SetVisibility( false );
1337 delete myPreviewDisplayer;
1338 myPreviewDisplayer = 0;
1340 myMapShapeId.clear();
1341 SMESHGUI_BaseComputeOp::stopOperation();
1344 //================================================================================
1346 * \brief reinitialize dialog after operaiton become active again
1348 //================================================================================
1350 void SMESHGUI_PrecomputeOp::resumeOperation()
1352 if ( myActiveDlg == myDlg )
1354 SMESHGUI_BaseComputeOp::resumeOperation();
1357 //================================================================================
1359 * \brief perform it's intention action: reinitialise dialog
1361 //================================================================================
1363 void SMESHGUI_PrecomputeOp::initDialog()
1367 QMap<int, int> modeMap;
1368 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1369 getAssignedAlgos( pMesh, modeMap );
1370 if ( modeMap.contains( SMESH::DIM_3D ) )
1372 if ( modeMap.contains( SMESH::DIM_2D ) )
1373 modes.append( SMESH::DIM_2D );
1374 if ( modeMap.contains( SMESH::DIM_1D ) )
1375 modes.append( SMESH::DIM_1D );
1377 else if ( modeMap.contains( SMESH::DIM_2D ) )
1379 if ( modeMap.contains( SMESH::DIM_1D ) )
1380 modes.append( SMESH::DIM_1D );
1383 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1384 myOrderMgr->SetMesh( myMesh );
1385 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1386 myDlg->getMeshOrderBox()->setShown(isOrder);
1392 myDlg->setPreviewModes( modes );
1395 //================================================================================
1397 * \brief detect asigned mesh algorithms
1399 //================================================================================
1401 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1402 QMap<int,int>& theModeMap)
1404 _PTR(SObject) aHypRoot;
1405 _PTR(GenericAttribute) anAttr;
1406 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1407 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1409 _PTR(ChildIterator) anIter =
1410 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1411 for ( ; anIter->More(); anIter->Next() )
1413 _PTR(SObject) anObj = anIter->Value();
1414 _PTR(SObject) aRefObj;
1415 if ( anObj->ReferencedObject( aRefObj ) )
1420 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1422 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1423 if ( CORBA::is_nil( aVar ) )
1426 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1428 SMESH::SMESH_Algo_var algo;
1430 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1431 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1432 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1435 if ( !algo->_is_nil() )
1436 theModeMap[ dim ] = 0;
1443 //================================================================================
1445 * \brief perform it's intention action: compute mesh
1447 //================================================================================
1449 void SMESHGUI_PrecomputeOp::onCompute()
1452 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1453 myOrderMgr->SetMeshOrder();
1454 myMapShapeId.clear();
1455 myActiveDlg = computeDlg();
1459 //================================================================================
1461 * \brief perform it's intention action: compute mesh
1463 //================================================================================
1465 void SMESHGUI_PrecomputeOp::onCancel()
1467 QObject* curDlg = sender();
1468 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1470 // return from error messages
1475 bool isRestoreOrder = false;
1476 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1478 // ask to remove already computed mesh elements
1479 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1480 tr( "CLEAR_SUBMESH_QUESTION" ),
1481 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1483 // remove all submeshes for collected shapes
1484 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1485 for ( ; it != myMapShapeId.constEnd(); ++it )
1486 myMesh->ClearSubMesh( *it );
1487 isRestoreOrder = true;
1491 // return previous mesh order
1492 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1493 if (!isRestoreOrder)
1495 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1496 tr( "SMESH_REJECT_MESH_ORDER" ),
1497 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1499 myOrderMgr->SetMeshOrder(myPrevOrder);
1505 myMapShapeId.clear();
1506 SMESHGUI_BaseComputeOp::onCancel();
1509 //================================================================================
1511 * \brief perform it's intention action: preview mesh
1513 //================================================================================
1515 void SMESHGUI_PrecomputeOp::onPreview()
1517 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1520 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1524 // set modified submesh priority if any
1525 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1526 myOrderMgr->SetMeshOrder();
1528 // Compute preview of mesh,
1529 // i.e. compute mesh till indicated dimension
1530 int dim = myDlg->getPreviewMode();
1532 SMESH::MemoryReserve aMemoryReserve;
1534 SMESH::compute_error_array_var aCompErrors;
1537 bool computeFailed = true, memoryLack = false;
1539 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1540 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1542 SMESHGUI* gui = getSMESHGUI();
1543 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1544 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1545 if ( errors->length() > 0 ) {
1546 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1549 SUIT_OverrideCursor aWaitCursor;
1551 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1552 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1553 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1555 SMESH::long_array_var aShapesId = new SMESH::long_array();
1557 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1561 SMESH::MeshPreviewStruct_var previewData =
1562 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1563 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1564 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1566 computeFailed = false;
1567 myPreviewDisplayer->SetData( previewRes );
1568 // append shape indeces with computed mesh entities
1569 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1570 myMapShapeId[ aShapesId[ i ] ] = 0;
1573 myPreviewDisplayer->SetVisibility(false);
1575 catch(const SALOME::SALOME_Exception & S_ex){
1577 myPreviewDisplayer->SetVisibility(false);
1581 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1584 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1585 // check if there are memory problems
1586 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1587 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1589 catch(const SALOME::SALOME_Exception & S_ex){
1594 aMemoryReserve.release();
1596 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1597 bool noHypoError = ( aHypErrors.isEmpty() );
1599 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1600 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1602 bool isShowError = true;
1603 switch( aNotifyMode ) {
1604 case 0: // show the mesh computation result dialog NEVER
1605 isShowError = false;
1607 case 1: // show the mesh computation result dialog if there are some errors
1608 default: // show the result dialog after each mesh computation
1609 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1610 isShowError = false;
1614 aWaitCursor.suspend();
1619 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1620 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1625 //================================================================================
1627 * \brief Constructor
1629 //================================================================================
1631 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1632 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1635 setWindowTitle( tr( "CAPTION" ) );
1637 setButtonText( OK, tr( "COMPUTE" ) );
1638 QFrame* main = mainFrame();
1640 QVBoxLayout* layout = new QVBoxLayout( main );
1642 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1643 layout->addWidget(myOrderBox);
1645 QFrame* frame = new QFrame( main );
1646 layout->setMargin(0); layout->setSpacing(0);
1647 layout->addWidget( frame );
1649 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1650 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1652 myPreviewMode = new QtxComboBox( frame );
1653 frameLay->addWidget( myPreviewMode );
1655 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1656 frameLay->addWidget( myPreviewBtn );
1658 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1661 //================================================================================
1665 //================================================================================
1667 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1671 //================================================================================
1673 * \brief Sets available preview modes
1675 //================================================================================
1677 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1679 myPreviewMode->clear();
1680 QList<int>::const_iterator it = theModes.constBegin();
1681 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1683 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1684 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1685 myPreviewMode->setId( i, *it );
1687 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1690 //================================================================================
1692 * \brief Returns current preview mesh mode
1694 //================================================================================
1696 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1698 return myPreviewMode->currentId();
1701 //================================================================================
1703 * \brief Returns current preview mesh mode
1705 //================================================================================
1707 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1713 //================================================================================
1715 * \brief Constructor
1717 //================================================================================
1719 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1720 : SMESHGUI_BaseComputeOp()
1725 //================================================================================
1727 * \brief Desctructor
1729 //================================================================================
1731 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1735 //================================================================================
1737 * \brief perform it's intention action: compute mesh
1739 //================================================================================
1741 void SMESHGUI_EvaluateOp::startOperation()
1743 SMESHGUI_BaseComputeOp::evaluateDlg();
1744 SMESHGUI_BaseComputeOp::startOperation();
1745 if (myMesh->_is_nil())
1750 //================================================================================
1752 * \brief Gets dialog of this operation
1753 * \retval LightApp_Dialog* - pointer to dialog of this operation
1755 //================================================================================
1757 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1759 return evaluateDlg();
1762 //================================================================================
1764 * \brief evaluateMesh()
1766 //================================================================================
1768 void SMESHGUI_BaseComputeOp::evaluateMesh()
1772 SMESH::MemoryReserve aMemoryReserve;
1774 SMESH::compute_error_array_var aCompErrors;
1777 bool evaluateFailed = true, memoryLack = false;
1778 SMESH::long_array_var aRes;
1780 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1781 if ( !aMeshSObj ) // IPAL21340
1784 bool hasShape = myMesh->HasShapeToMesh();
1785 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1788 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1789 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1790 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1791 if ( errors->length() > 0 ) {
1792 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1794 SUIT_OverrideCursor aWaitCursor;
1796 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1799 aRes = gen->Evaluate(myMesh, myMainShape);
1801 catch(const SALOME::SALOME_Exception & S_ex){
1806 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1809 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1811 catch(const SALOME::SALOME_Exception & S_ex){
1817 aMemoryReserve.release();
1819 evaluateFailed = ( aCompErrors->length() > 0 );
1820 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1824 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1825 bool noHypoError = ( aHypErrors.isEmpty() );
1827 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1828 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1830 bool isShowResultDlg = true;
1832 //switch( aNotifyMode ) {
1833 //case 0: // show the mesh computation result dialog NEVER
1834 //isShowResultDlg = false;
1837 //case 1: // show the mesh computation result dialog if there are some errors
1838 //if ( memoryLack || !noHypoError )
1839 // isShowResultDlg = true;
1842 // isShowResultDlg = false;
1846 //default: // show the result dialog after each mesh computation
1847 //isShowResultDlg = true;
1851 if ( isShowResultDlg )
1852 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1853 noHypoError, aHypErrors);
1857 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1858 const bool theMemoryLack,
1859 const bool theNoCompError,
1860 SMESH::compute_error_array_var& theCompErrors,
1861 const bool theNoHypoError,
1862 const QString& theHypErrors)
1864 bool hasShape = myMesh->HasShapeToMesh();
1865 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1866 aCompDlg->myMemoryLackGroup->hide();
1868 if ( theMemoryLack )
1870 aCompDlg->myMemoryLackGroup->show();
1871 aCompDlg->myFullInfo->hide();
1872 aCompDlg->myBriefInfo->hide();
1873 aCompDlg->myHypErrorGroup->hide();
1874 aCompDlg->myCompErrorGroup->hide();
1876 else if ( theNoCompError && theNoHypoError )
1878 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1879 aCompDlg->myFullInfo->show();
1880 aCompDlg->myBriefInfo->hide();
1881 aCompDlg->myHypErrorGroup->hide();
1882 aCompDlg->myCompErrorGroup->hide();
1886 QTableWidget* tbl = aCompDlg->myTable;
1887 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1888 aCompDlg->myBriefInfo->show();
1889 aCompDlg->myFullInfo->hide();
1891 if ( theNoHypoError ) {
1892 aCompDlg->myHypErrorGroup->hide();
1895 aCompDlg->myHypErrorGroup->show();
1896 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1899 if ( theNoCompError ) {
1900 aCompDlg->myCompErrorGroup->hide();
1903 aCompDlg->myCompErrorGroup->show();
1905 aCompDlg->myPublishBtn->hide();
1906 aCompDlg->myShowBtn->hide();
1908 // fill table of errors
1909 tbl->setRowCount( theCompErrors->length() );
1910 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1911 else tbl->showColumn( COL_SHAPE );
1912 tbl->setColumnWidth( COL_ERROR, 200 );
1914 bool hasBadMesh = false;
1915 for ( int row = 0; row < theCompErrors->length(); ++row )
1917 SMESH::ComputeError & err = theCompErrors[ row ];
1919 QString text = err.algoName.in();
1920 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1921 else tbl->item( row, COL_ALGO )->setText( text );
1923 text = SMESH::errorText( err.code, err.comment.in() );
1924 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1925 else tbl->item( row, COL_ERROR )->setText( text );
1927 text = QString("%1").arg( err.subShapeID );
1928 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1929 else tbl->item( row, COL_SHAPEID )->setText( text );
1931 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1932 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1933 else tbl->item( row, COL_SHAPE )->setText( text );
1935 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1936 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1937 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1939 text = err.hasBadMesh ? "hasBadMesh" : "";
1940 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1941 else tbl->item( row, COL_BAD_MESH )->setText( text );
1942 if ( err.hasBadMesh ) hasBadMesh = true;
1944 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1945 tbl->resizeRowToContents( row );
1947 tbl->resizeColumnToContents( COL_ALGO );
1948 tbl->resizeColumnToContents( COL_SHAPE );
1951 aCompDlg->myBadMeshBtn->show();
1953 aCompDlg->myBadMeshBtn->hide();
1955 tbl->setCurrentCell(0,0);
1956 currentCellChanged(); // to update buttons
1959 // show dialog and wait, becase Compute can be invoked from Preview operation
1960 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1965 //================================================================================
1967 * \brief Gets dialog of evaluate operation
1968 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1970 //================================================================================
1972 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1976 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1977 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1978 // connect signals and slots
1979 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1980 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1981 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1982 QTableWidget* aTable = me->table();
1983 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1984 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));