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 case SMESH::COMPERR_ALGO_FAILED:
347 if ( strlen(comment) == 0 )
348 text = QObject::tr("COMPERR_ALGO_FAILED");
351 text = QString("#%1").arg( -errCode );
353 if ( text.length() > 0 ) text += ". ";
354 return text + comment;
356 // -----------------------------------------------------------------------
358 * \brief Return SO of a subshape
360 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
362 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
363 if ( subShapeID == 1 || !so )
365 _PTR(ChildIterator) it;
366 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
367 it = study->NewChildIterator(so);
370 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
371 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
372 if ( !geom->_is_nil() ) {
373 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
374 if ( list->length() == 1 && list[0] == subShapeID )
381 // -----------------------------------------------------------------------
383 * \brief Return subshape by ID
385 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
387 GEOM::GEOM_Object_var aSubShape;
388 if ( subShapeID == 1 )
389 aSubShape = aMainShape;
390 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
391 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
393 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
394 return aSubShape._retn();
396 // -----------------------------------------------------------------------
398 * \brief Return shape type name
400 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
401 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
404 if ( !aShape->_is_nil() ) {
405 switch ( aShape->GetShapeType() ) {
412 CASE2NAME( COMPSOLID );
413 CASE2NAME( COMPOUND );
419 // -----------------------------------------------------------------------
421 * \brief Return text describing a subshape
423 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
426 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
427 text = aSO->GetName().c_str();
429 text = QString("#%1").arg( subShapeID );
430 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
431 if ( typeName.length() )
432 text += QString(" (%1)").arg(typeName);
436 // -----------------------------------------------------------------------
438 * \brief Return a list of selected rows
440 int getSelectedRows(QTableWidget* table, QList<int>& rows)
443 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
444 QTableWidgetSelectionRange range;
445 foreach( range, selRanges )
447 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
450 if ( rows.isEmpty() && table->currentRow() > -1 )
451 rows.append( table->currentRow() );
459 // =========================================================================================
461 * \brief Dialog to compute a mesh and show computation errors
463 //=======================================================================
465 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg( QWidget* parent, bool ForEval )
466 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
468 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
469 aDlgLay->setMargin( 0 );
470 aDlgLay->setSpacing( SPACING );
472 QFrame* aMainFrame = createMainFrame(mainFrame(),ForEval);
474 aDlgLay->addWidget(aMainFrame);
476 aDlgLay->setStretchFactor(aMainFrame, 1);
479 // =========================================================================================
483 //=======================================================================
485 SMESHGUI_ComputeDlg::~SMESHGUI_ComputeDlg()
489 //=======================================================================
490 // function : createMainFrame()
491 // purpose : Create frame containing dialog's fields
492 //=======================================================================
494 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent, bool ForEval)
496 QFrame* aFrame = new QFrame(theParent);
498 SUIT_ResourceMgr* rm = resourceMgr();
499 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
505 aPixGrp = new QGroupBox(tr("EVAL_DLG"), aFrame);
508 aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
510 QButtonGroup* aBtnGrp = new QButtonGroup(this);
511 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
512 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
514 QRadioButton* aRBut = new QRadioButton(aPixGrp);
515 aRBut->setIcon(iconCompute);
516 aRBut->setChecked(true);
517 aPixGrpLayout->addWidget(aRBut);
518 aBtnGrp->addButton(aRBut, 0);
522 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
523 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
524 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
525 myMeshName = new QLabel(nameBox);
526 nameBoxLayout->addWidget(myMeshName);
530 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
531 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
533 // Computation errors
535 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
536 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
537 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
538 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
539 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup);
541 //myTable->setReadOnly( true ); // VSR: check
542 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
543 myTable->hideColumn( COL_PUBLISHED );
544 myTable->hideColumn( COL_SHAPEID );
545 myTable->hideColumn( COL_BAD_MESH );
546 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
549 headers << tr( "COL_ALGO_HEADER" );
550 headers << tr( "COL_SHAPE_HEADER" );
551 headers << tr( "COL_ERROR_HEADER" );
552 headers << tr( "COL_SHAPEID_HEADER" );
553 headers << tr( "COL_PUBLISHED_HEADER" );
555 myTable->setHorizontalHeaderLabels( headers );
558 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
559 grpLayout->setSpacing(SPACING);
560 grpLayout->setMargin(MARGIN);
561 grpLayout->addWidget( myTable, 0, 0, 4, 1 );
562 grpLayout->addWidget( myShowBtn, 0, 1 );
563 grpLayout->addWidget( myPublishBtn, 1, 1 );
564 grpLayout->addWidget( myBadMeshBtn, 2, 1 );
565 grpLayout->setRowStretch( 3, 1 );
567 // Hypothesis definition errors
569 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
570 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
571 myHypErrorGroupLayout->setMargin(MARGIN);
572 myHypErrorGroupLayout->setSpacing(SPACING);
573 myHypErrorLabel = new QLabel(myHypErrorGroup);
574 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
578 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
579 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
580 myMemoryLackGroupLayout->setMargin(MARGIN);
581 myMemoryLackGroupLayout->setSpacing(SPACING);
582 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
583 QFont bold = memLackLabel->font(); bold.setBold(true);
584 memLackLabel->setFont( bold );
585 memLackLabel->setMinimumWidth(300);
586 myMemoryLackGroupLayout->addWidget(memLackLabel);
588 // add all widgets to aFrame
589 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
590 aLay->setMargin( 0 );
591 aLay->setSpacing( 0 );
592 aLay->addWidget( aPixGrp );
593 aLay->addWidget( nameBox );
594 aLay->addWidget( myBriefInfo );
595 aLay->addWidget( myFullInfo );
596 aLay->addWidget( myHypErrorGroup );
597 aLay->addWidget( myCompErrorGroup );
598 aLay->addWidget( myMemoryLackGroup );
599 aLay->setStretchFactor( myCompErrorGroup, 1 );
601 ((QPushButton*) button( OK ))->setDefault( true );
606 //================================================================================
610 //================================================================================
612 SMESHGUI_BaseComputeOp::SMESHGUI_BaseComputeOp()
613 : SMESHGUI_Operation(), myCompDlg( 0 )
615 myTShapeDisplayer = new SMESH::TShapeDisplayer();
616 myBadMeshDisplayer = 0;
618 //myHelpFileName = "/files/about_meshes.htm"; // V3
619 myHelpFileName = "about_meshes_page.html"; // V4
622 //================================================================================
624 * \brief Start operation
625 * \purpose Init dialog fields, connect signals and slots, show dialog
627 //================================================================================
629 void SMESHGUI_BaseComputeOp::startOperation()
631 // create compute dialog if not created before
634 myMesh = SMESH::SMESH_Mesh::_nil();
635 myMainShape = GEOM::GEOM_Object::_nil();
638 LightApp_SelectionMgr *Sel = selectionMgr();
639 SALOME_ListIO selected; Sel->selectedObjects( selected );
641 int nbSel = selected.Extent();
643 SUIT_MessageBox::warning(desktop(),
644 tr("SMESH_WRN_WARNING"),
645 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
650 myIObject = selected.First();
651 myMesh = SMESH::GetMeshByIO(myIObject);
652 if (myMesh->_is_nil()) {
653 SUIT_MessageBox::warning(desktop(),
654 tr("SMESH_WRN_WARNING"),
655 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
659 myMainShape = myMesh->GetShapeToMesh();
661 SMESHGUI_Operation::startOperation();
664 //================================================================================
666 * \brief computeMesh()
668 //================================================================================
670 void SMESHGUI_BaseComputeOp::computeMesh()
674 SMESH::MemoryReserve aMemoryReserve;
676 SMESH::compute_error_array_var aCompErrors;
679 bool computeFailed = true, memoryLack = false;
681 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
682 if ( !aMeshSObj ) // IPAL 21340
684 bool hasShape = myMesh->HasShapeToMesh();
685 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
688 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
689 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
690 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
691 if ( errors->length() > 0 ) {
692 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
694 SUIT_OverrideCursor aWaitCursor;
696 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
699 if (gen->Compute(myMesh, myMainShape))
700 computeFailed = false;
702 catch(const SALOME::SALOME_Exception & S_ex){
706 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
709 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
710 // check if there are memory problems
711 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
712 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
714 catch(const SALOME::SALOME_Exception & S_ex){
718 // NPAL16631: if ( !memoryLack )
720 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
721 update( UF_ObjBrowser | UF_Model );
724 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
725 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
728 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
731 SMESH::Update(myIObject, true);
735 MESSAGE ( "Exception thrown during mesh visualization" );
737 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
738 SMESH::OnVisuException();
745 LightApp_SelectionMgr *Sel = selectionMgr();
748 SALOME_ListIO selected;
749 selected.Append( myIObject );
750 Sel->setSelectedObjects( selected );
756 aMemoryReserve.release();
758 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
762 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
763 bool noHypoError = ( aHypErrors.isEmpty() );
765 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
766 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
768 bool isShowResultDlg = true;
769 switch( aNotifyMode ) {
770 case 0: // show the mesh computation result dialog NEVER
771 isShowResultDlg = false;
774 case 1: // show the mesh computation result dialog if there are some errors
775 if ( memoryLack || !noCompError || !noHypoError )
776 isShowResultDlg = true;
779 isShowResultDlg = false;
783 default: // show the result dialog after each mesh computation
784 isShowResultDlg = true;
788 if ( isShowResultDlg )
789 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
792 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
793 const bool theNoCompError,
794 SMESH::compute_error_array_var& theCompErrors,
795 const bool theNoHypoError,
796 const QString& theHypErrors )
798 bool hasShape = myMesh->HasShapeToMesh();
799 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
800 aCompDlg->myMemoryLackGroup->hide();
804 aCompDlg->myMemoryLackGroup->show();
805 aCompDlg->myFullInfo->hide();
806 aCompDlg->myBriefInfo->hide();
807 aCompDlg->myHypErrorGroup->hide();
808 aCompDlg->myCompErrorGroup->hide();
810 else if ( theNoCompError && theNoHypoError )
812 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
813 aCompDlg->myFullInfo->SetMeshInfo( aRes );
814 aCompDlg->myFullInfo->show();
815 aCompDlg->myBriefInfo->hide();
816 aCompDlg->myHypErrorGroup->hide();
817 aCompDlg->myCompErrorGroup->hide();
821 QTableWidget* tbl = aCompDlg->myTable;
822 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
823 aCompDlg->myFullInfo->SetMeshInfo( aRes );
824 aCompDlg->myBriefInfo->show();
825 aCompDlg->myFullInfo->hide();
827 if ( theNoHypoError ) {
828 aCompDlg->myHypErrorGroup->hide();
831 aCompDlg->myHypErrorGroup->show();
832 aCompDlg->myHypErrorLabel->setText( theHypErrors );
835 if ( theNoCompError ) {
836 aCompDlg->myCompErrorGroup->hide();
839 aCompDlg->myCompErrorGroup->show();
842 aCompDlg->myPublishBtn->hide();
843 aCompDlg->myShowBtn->hide();
846 aCompDlg->myPublishBtn->show();
847 aCompDlg->myShowBtn->show();
850 // fill table of errors
851 tbl->setRowCount( theCompErrors->length() );
852 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
853 else tbl->showColumn( COL_SHAPE );
854 tbl->setColumnWidth( COL_ERROR, 200 );
856 bool hasBadMesh = false;
857 for ( int row = 0; row < theCompErrors->length(); ++row )
859 SMESH::ComputeError & err = theCompErrors[ row ];
861 QString text = err.algoName.in();
862 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
863 else tbl->item( row, COL_ALGO )->setText( text );
865 text = SMESH::errorText( err.code, err.comment.in() );
866 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
867 else tbl->item( row, COL_ERROR )->setText( text );
869 text = QString("%1").arg( err.subShapeID );
870 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
871 else tbl->item( row, COL_SHAPEID )->setText( text );
873 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
874 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
875 else tbl->item( row, COL_SHAPE )->setText( text );
877 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
878 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
879 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
881 text = err.hasBadMesh ? "hasBadMesh" : "";
882 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
883 else tbl->item( row, COL_BAD_MESH )->setText( text );
884 if ( err.hasBadMesh ) hasBadMesh = true;
886 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
887 tbl->resizeRowToContents( row );
889 tbl->resizeColumnToContents( COL_ALGO );
890 tbl->resizeColumnToContents( COL_SHAPE );
893 aCompDlg->myBadMeshBtn->show();
895 aCompDlg->myBadMeshBtn->hide();
897 tbl->setCurrentCell(0,0);
898 currentCellChanged(); // to update buttons
901 // show dialog and wait, becase Compute can be invoked from Preview operation
902 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
906 //================================================================================
908 * \brief Stops operation
910 //================================================================================
912 void SMESHGUI_BaseComputeOp::stopOperation()
914 SMESHGUI_Operation::stopOperation();
915 if ( myTShapeDisplayer )
916 myTShapeDisplayer->SetVisibility( false );
917 if ( myBadMeshDisplayer ) {
918 myBadMeshDisplayer->SetVisibility( false );
919 // delete it in order not to have problems at its destruction when the viewer
920 // where it worked is dead due to e.g. study closing
921 delete myBadMeshDisplayer;
922 myBadMeshDisplayer = 0;
927 //================================================================================
929 * \brief publish selected subshape
931 //================================================================================
933 void SMESHGUI_BaseComputeOp::onPublishShape()
935 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
936 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
939 SMESH::getSelectedRows( table(), rows );
941 foreach ( row, rows )
943 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
944 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
945 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
947 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
949 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
950 SALOMEDS::SObject_var so =
951 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
952 // look for myMainShape in the table
953 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
954 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
955 if ( so->_is_nil() ) {
956 table()->item( r, COL_SHAPE )->setText( so->GetName() );
957 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
962 if ( curSub == 1 ) continue;
964 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
965 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
966 if ( !so->_is_nil() ) {
967 table()->item( row, COL_SHAPE )->setText( so->GetName() );
968 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
972 getSMESHGUI()->getApp()->updateObjectBrowser();
973 currentCellChanged(); // to update buttons
976 //================================================================================
978 * \brief show mesh elements preventing computation of a submesh of current row
980 //================================================================================
982 void SMESHGUI_BaseComputeOp::onShowBadMesh()
984 myTShapeDisplayer->SetVisibility( false );
986 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
987 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
989 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
990 SMESHGUI* gui = getSMESHGUI();
991 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
992 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
993 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
994 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
995 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
996 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
997 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
998 // delete property !!!!!!!!!!
999 vtkProperty* prop = vtkProperty::New();
1000 prop->SetLineWidth( aLineWidth * 3 );
1001 prop->SetPointSize( aPointSize * 3 );
1002 prop->SetColor( 250, 0, 250 );
1003 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1004 myBadMeshDisplayer->SetData( aMeshData._retn() );
1009 //================================================================================
1011 * \brief SLOT called when a selected cell in table() changed
1013 //================================================================================
1015 void SMESHGUI_BaseComputeOp::currentCellChanged()
1017 myTShapeDisplayer->SetVisibility( false );
1018 if ( myBadMeshDisplayer )
1019 myBadMeshDisplayer->SetVisibility( false );
1021 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1023 int nbSelected = SMESH::getSelectedRows( table(), rows );
1025 foreach ( row, rows )
1027 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1028 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1029 if ( hasData && !isPublished )
1030 publishEnable = true;
1032 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1033 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1035 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1042 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1045 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1046 myCompDlg->myShowBtn ->setEnabled( showEnable );
1047 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1050 //================================================================================
1052 * \brief update preview
1054 //================================================================================
1056 void SMESHGUI_BaseComputeOp::onPreviewShape()
1058 if ( myTShapeDisplayer )
1060 SUIT_OverrideCursor aWaitCursor;
1062 SMESH::getSelectedRows( table(), rows );
1064 bool showOnly = true;
1066 foreach ( row, rows )
1068 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1070 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1074 currentCellChanged(); // to update buttons
1078 //================================================================================
1082 //================================================================================
1084 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1088 delete myTShapeDisplayer;
1089 if ( myBadMeshDisplayer )
1090 delete myBadMeshDisplayer;
1093 //================================================================================
1095 * \brief Gets dialog of compute operation
1096 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1098 //================================================================================
1100 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1104 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1105 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1106 // connect signals and slots
1107 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1108 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1109 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1111 QTableWidget* aTable = me->table();
1112 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1113 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1118 //================================================================================
1120 * \brief returns from compute mesh result dialog
1122 //================================================================================
1124 bool SMESHGUI_BaseComputeOp::onApply()
1129 //================================================================================
1131 * \brief Return a table
1133 //================================================================================
1135 QTableWidget* SMESHGUI_BaseComputeOp::table()
1137 return myCompDlg->myTable;
1141 //================================================================================
1143 * \brief Constructor
1145 //================================================================================
1147 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1148 : SMESHGUI_BaseComputeOp()
1153 //================================================================================
1155 * \brief Desctructor
1157 //================================================================================
1159 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1163 //================================================================================
1165 * \brief perform it's intention action: compute mesh
1167 //================================================================================
1169 void SMESHGUI_ComputeOp::startOperation()
1171 SMESHGUI_BaseComputeOp::startOperation();
1172 if (myMesh->_is_nil())
1177 //================================================================================
1179 * \brief Gets dialog of this operation
1180 * \retval LightApp_Dialog* - pointer to dialog of this operation
1182 //================================================================================
1184 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1186 return computeDlg();
1189 //================================================================================
1191 * \brief Constructor
1193 //================================================================================
1195 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1196 : SMESHGUI_BaseComputeOp(),
1200 myPreviewDisplayer( 0 )
1202 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1205 //================================================================================
1209 //================================================================================
1211 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1218 if ( myPreviewDisplayer )
1219 delete myPreviewDisplayer;
1220 myPreviewDisplayer = 0;
1223 //================================================================================
1225 * \brief Gets current dialog of this operation
1226 * \retval LightApp_Dialog* - pointer to dialog of this operation
1228 //================================================================================
1230 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1235 //================================================================================
1237 * \brief perform it's intention action: prepare data
1239 //================================================================================
1241 void SMESHGUI_PrecomputeOp::startOperation()
1245 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1248 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1249 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1250 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1252 myActiveDlg = myDlg;
1254 // connect signal to compute dialog. which will be shown after Compute mesh operation
1255 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1258 // disconnect signals
1259 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1260 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1261 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1262 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1263 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1266 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1267 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1268 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1269 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1270 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1271 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1272 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1273 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1274 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1275 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1278 SMESHGUI_BaseComputeOp::startOperation();
1279 if (myMesh->_is_nil())
1282 if (myDlg->getPreviewMode() == -1)
1284 // nothing to preview
1285 SUIT_MessageBox::warning(desktop(),
1286 tr("SMESH_WRN_WARNING"),
1287 tr("SMESH_WRN_NOTHING_PREVIEW"));
1292 // disconnect slot from preview dialog to have Apply from results of compute operation only
1293 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1294 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1299 //================================================================================
1301 * \brief Stops operation
1303 //================================================================================
1305 void SMESHGUI_PrecomputeOp::stopOperation()
1307 if ( myPreviewDisplayer )
1309 myPreviewDisplayer->SetVisibility( false );
1310 delete myPreviewDisplayer;
1311 myPreviewDisplayer = 0;
1313 myMapShapeId.clear();
1314 SMESHGUI_BaseComputeOp::stopOperation();
1317 //================================================================================
1319 * \brief reinitialize dialog after operaiton become active again
1321 //================================================================================
1323 void SMESHGUI_PrecomputeOp::resumeOperation()
1325 if ( myActiveDlg == myDlg )
1327 SMESHGUI_BaseComputeOp::resumeOperation();
1330 //================================================================================
1332 * \brief perform it's intention action: reinitialise dialog
1334 //================================================================================
1336 void SMESHGUI_PrecomputeOp::initDialog()
1340 QMap<int, int> modeMap;
1341 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1342 getAssignedAlgos( pMesh, modeMap );
1343 if ( modeMap.contains( SMESH::DIM_3D ) )
1345 if ( modeMap.contains( SMESH::DIM_2D ) )
1346 modes.append( SMESH::DIM_2D );
1347 if ( modeMap.contains( SMESH::DIM_1D ) )
1348 modes.append( SMESH::DIM_1D );
1350 else if ( modeMap.contains( SMESH::DIM_2D ) )
1352 if ( modeMap.contains( SMESH::DIM_1D ) )
1353 modes.append( SMESH::DIM_1D );
1356 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1357 myOrderMgr->SetMesh( myMesh );
1358 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1359 myDlg->getMeshOrderBox()->setShown(isOrder);
1365 myDlg->setPreviewModes( modes );
1368 //================================================================================
1370 * \brief detect asigned mesh algorithms
1372 //================================================================================
1374 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1375 QMap<int,int>& theModeMap)
1377 _PTR(SObject) aHypRoot;
1378 _PTR(GenericAttribute) anAttr;
1379 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1380 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1382 _PTR(ChildIterator) anIter =
1383 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1384 for ( ; anIter->More(); anIter->Next() )
1386 _PTR(SObject) anObj = anIter->Value();
1387 _PTR(SObject) aRefObj;
1388 if ( anObj->ReferencedObject( aRefObj ) )
1393 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1395 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1396 if ( CORBA::is_nil( aVar ) )
1399 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1401 SMESH::SMESH_Algo_var algo;
1403 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1404 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1405 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1408 if ( !algo->_is_nil() )
1409 theModeMap[ dim ] = 0;
1416 //================================================================================
1418 * \brief perform it's intention action: compute mesh
1420 //================================================================================
1422 void SMESHGUI_PrecomputeOp::onCompute()
1425 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1426 myOrderMgr->SetMeshOrder();
1427 myMapShapeId.clear();
1428 myActiveDlg = computeDlg();
1432 //================================================================================
1434 * \brief perform it's intention action: compute mesh
1436 //================================================================================
1438 void SMESHGUI_PrecomputeOp::onCancel()
1440 QObject* curDlg = sender();
1441 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1443 // return from error messages
1448 bool isRestoreOrder = false;
1449 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1451 // ask to remove already computed mesh elements
1452 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1453 tr( "CLEAR_SUBMESH_QUESTION" ),
1454 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1456 // remove all submeshes for collected shapes
1457 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1458 for ( ; it != myMapShapeId.constEnd(); ++it )
1459 myMesh->ClearSubMesh( *it );
1460 isRestoreOrder = true;
1464 // return previous mesh order
1465 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1466 if (!isRestoreOrder)
1468 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1469 tr( "SMESH_REJECT_MESH_ORDER" ),
1470 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1472 myOrderMgr->SetMeshOrder(myPrevOrder);
1478 myMapShapeId.clear();
1479 SMESHGUI_BaseComputeOp::onCancel();
1482 //================================================================================
1484 * \brief perform it's intention action: preview mesh
1486 //================================================================================
1488 void SMESHGUI_PrecomputeOp::onPreview()
1490 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1493 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1497 // set modified submesh priority if any
1498 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1499 myOrderMgr->SetMeshOrder();
1501 // Compute preview of mesh,
1502 // i.e. compute mesh till indicated dimension
1503 int dim = myDlg->getPreviewMode();
1505 SMESH::MemoryReserve aMemoryReserve;
1507 SMESH::compute_error_array_var aCompErrors;
1510 bool computeFailed = true, memoryLack = false;
1512 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1513 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1515 SMESHGUI* gui = getSMESHGUI();
1516 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1517 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1518 if ( errors->length() > 0 ) {
1519 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1522 SUIT_OverrideCursor aWaitCursor;
1524 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1525 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1526 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1528 SMESH::long_array_var aShapesId = new SMESH::long_array();
1530 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1534 SMESH::MeshPreviewStruct_var previewData =
1535 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1536 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1537 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1539 computeFailed = false;
1540 myPreviewDisplayer->SetData( previewRes );
1541 // append shape indeces with computed mesh entities
1542 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1543 myMapShapeId[ aShapesId[ i ] ] = 0;
1546 myPreviewDisplayer->SetVisibility(false);
1548 catch(const SALOME::SALOME_Exception & S_ex){
1550 myPreviewDisplayer->SetVisibility(false);
1554 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1557 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1558 // check if there are memory problems
1559 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1560 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1562 catch(const SALOME::SALOME_Exception & S_ex){
1567 aMemoryReserve.release();
1569 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1570 bool noHypoError = ( aHypErrors.isEmpty() );
1572 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1573 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1575 bool isShowError = true;
1576 switch( aNotifyMode ) {
1577 case 0: // show the mesh computation result dialog NEVER
1578 isShowError = false;
1580 case 1: // show the mesh computation result dialog if there are some errors
1581 default: // show the result dialog after each mesh computation
1582 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1583 isShowError = false;
1587 aWaitCursor.suspend();
1592 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1593 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1598 //================================================================================
1600 * \brief Constructor
1602 //================================================================================
1604 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1605 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1608 setWindowTitle( tr( "CAPTION" ) );
1610 setButtonText( OK, tr( "COMPUTE" ) );
1611 QFrame* main = mainFrame();
1613 QVBoxLayout* layout = new QVBoxLayout( main );
1615 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1616 layout->addWidget(myOrderBox);
1618 QFrame* frame = new QFrame( main );
1619 layout->setMargin(0); layout->setSpacing(0);
1620 layout->addWidget( frame );
1622 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1623 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1625 myPreviewMode = new QtxComboBox( frame );
1626 frameLay->addWidget( myPreviewMode );
1628 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1629 frameLay->addWidget( myPreviewBtn );
1631 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1634 //================================================================================
1638 //================================================================================
1640 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1644 //================================================================================
1646 * \brief Sets available preview modes
1648 //================================================================================
1650 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1652 myPreviewMode->clear();
1653 QList<int>::const_iterator it = theModes.constBegin();
1654 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1656 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1657 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1658 myPreviewMode->setId( i, *it );
1660 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1663 //================================================================================
1665 * \brief Returns current preview mesh mode
1667 //================================================================================
1669 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1671 return myPreviewMode->currentId();
1674 //================================================================================
1676 * \brief Returns current preview mesh mode
1678 //================================================================================
1680 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1686 //================================================================================
1688 * \brief Constructor
1690 //================================================================================
1692 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1693 : SMESHGUI_BaseComputeOp()
1698 //================================================================================
1700 * \brief Desctructor
1702 //================================================================================
1704 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1708 //================================================================================
1710 * \brief perform it's intention action: compute mesh
1712 //================================================================================
1714 void SMESHGUI_EvaluateOp::startOperation()
1716 SMESHGUI_BaseComputeOp::evaluateDlg();
1717 SMESHGUI_BaseComputeOp::startOperation();
1718 if (myMesh->_is_nil())
1723 //================================================================================
1725 * \brief Gets dialog of this operation
1726 * \retval LightApp_Dialog* - pointer to dialog of this operation
1728 //================================================================================
1730 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1732 return evaluateDlg();
1735 //================================================================================
1737 * \brief evaluateMesh()
1739 //================================================================================
1741 void SMESHGUI_BaseComputeOp::evaluateMesh()
1745 SMESH::MemoryReserve aMemoryReserve;
1747 SMESH::compute_error_array_var aCompErrors;
1750 bool evaluateFailed = true, memoryLack = false;
1751 SMESH::long_array_var aRes;
1753 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1754 if ( !aMeshSObj ) // IPAL21340
1757 bool hasShape = myMesh->HasShapeToMesh();
1758 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1761 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1762 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1763 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1764 if ( errors->length() > 0 ) {
1765 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1767 SUIT_OverrideCursor aWaitCursor;
1769 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1772 aRes = gen->Evaluate(myMesh, myMainShape);
1774 catch(const SALOME::SALOME_Exception & S_ex){
1779 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1782 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1784 catch(const SALOME::SALOME_Exception & S_ex){
1790 aMemoryReserve.release();
1792 evaluateFailed = ( aCompErrors->length() > 0 );
1793 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1797 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1798 bool noHypoError = ( aHypErrors.isEmpty() );
1800 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1801 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1803 bool isShowResultDlg = true;
1805 //switch( aNotifyMode ) {
1806 //case 0: // show the mesh computation result dialog NEVER
1807 //isShowResultDlg = false;
1810 //case 1: // show the mesh computation result dialog if there are some errors
1811 //if ( memoryLack || !noHypoError )
1812 // isShowResultDlg = true;
1815 // isShowResultDlg = false;
1819 //default: // show the result dialog after each mesh computation
1820 //isShowResultDlg = true;
1824 if ( isShowResultDlg )
1825 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1826 noHypoError, aHypErrors);
1830 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1831 const bool theMemoryLack,
1832 const bool theNoCompError,
1833 SMESH::compute_error_array_var& theCompErrors,
1834 const bool theNoHypoError,
1835 const QString& theHypErrors)
1837 bool hasShape = myMesh->HasShapeToMesh();
1838 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1839 aCompDlg->myMemoryLackGroup->hide();
1841 if ( theMemoryLack )
1843 aCompDlg->myMemoryLackGroup->show();
1844 aCompDlg->myFullInfo->hide();
1845 aCompDlg->myBriefInfo->hide();
1846 aCompDlg->myHypErrorGroup->hide();
1847 aCompDlg->myCompErrorGroup->hide();
1849 else if ( theNoCompError && theNoHypoError )
1851 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1852 aCompDlg->myFullInfo->show();
1853 aCompDlg->myBriefInfo->hide();
1854 aCompDlg->myHypErrorGroup->hide();
1855 aCompDlg->myCompErrorGroup->hide();
1859 QTableWidget* tbl = aCompDlg->myTable;
1860 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1861 aCompDlg->myBriefInfo->show();
1862 aCompDlg->myFullInfo->hide();
1864 if ( theNoHypoError ) {
1865 aCompDlg->myHypErrorGroup->hide();
1868 aCompDlg->myHypErrorGroup->show();
1869 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1872 if ( theNoCompError ) {
1873 aCompDlg->myCompErrorGroup->hide();
1876 aCompDlg->myCompErrorGroup->show();
1878 aCompDlg->myPublishBtn->hide();
1879 aCompDlg->myShowBtn->hide();
1881 // fill table of errors
1882 tbl->setRowCount( theCompErrors->length() );
1883 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1884 else tbl->showColumn( COL_SHAPE );
1885 tbl->setColumnWidth( COL_ERROR, 200 );
1887 bool hasBadMesh = false;
1888 for ( int row = 0; row < theCompErrors->length(); ++row )
1890 SMESH::ComputeError & err = theCompErrors[ row ];
1892 QString text = err.algoName.in();
1893 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1894 else tbl->item( row, COL_ALGO )->setText( text );
1896 text = SMESH::errorText( err.code, err.comment.in() );
1897 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1898 else tbl->item( row, COL_ERROR )->setText( text );
1900 text = QString("%1").arg( err.subShapeID );
1901 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1902 else tbl->item( row, COL_SHAPEID )->setText( text );
1904 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1905 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1906 else tbl->item( row, COL_SHAPE )->setText( text );
1908 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1909 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1910 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1912 text = err.hasBadMesh ? "hasBadMesh" : "";
1913 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1914 else tbl->item( row, COL_BAD_MESH )->setText( text );
1915 if ( err.hasBadMesh ) hasBadMesh = true;
1917 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1918 tbl->resizeRowToContents( row );
1920 tbl->resizeColumnToContents( COL_ALGO );
1921 tbl->resizeColumnToContents( COL_SHAPE );
1924 aCompDlg->myBadMeshBtn->show();
1926 aCompDlg->myBadMeshBtn->hide();
1928 tbl->setCurrentCell(0,0);
1929 currentCellChanged(); // to update buttons
1932 // show dialog and wait, becase Compute can be invoked from Preview operation
1933 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1938 //================================================================================
1940 * \brief Gets dialog of evaluate operation
1941 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1943 //================================================================================
1945 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1949 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1950 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1951 // connect signals and slots
1952 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1953 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1954 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1955 QTableWidget* aTable = me->table();
1956 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1957 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));