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 SMESH::SMESH_Mesh_ptr SMESHGUI_BaseComputeOp::getMesh()
624 LightApp_SelectionMgr* Sel = selectionMgr();
625 SALOME_ListIO selected; Sel->selectedObjects( selected );
626 Handle(SALOME_InteractiveObject) anIO = selected.First();
627 SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(anIO);
628 return myMesh->_is_nil() ? aMesh._retn() : SMESH::SMESH_Mesh::_duplicate( myMesh );
631 //================================================================================
633 * \brief Start operation
634 * \purpose Init dialog fields, connect signals and slots, show dialog
636 //================================================================================
638 void SMESHGUI_BaseComputeOp::startOperation()
640 // create compute dialog if not created before
643 myMesh = SMESH::SMESH_Mesh::_nil();
644 myMainShape = GEOM::GEOM_Object::_nil();
647 LightApp_SelectionMgr *Sel = selectionMgr();
648 SALOME_ListIO selected; Sel->selectedObjects( selected );
650 int nbSel = selected.Extent();
652 SUIT_MessageBox::warning(desktop(),
653 tr("SMESH_WRN_WARNING"),
654 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
659 myIObject = selected.First();
660 myMesh = SMESH::GetMeshByIO(myIObject);
661 if (myMesh->_is_nil()) {
662 SUIT_MessageBox::warning(desktop(),
663 tr("SMESH_WRN_WARNING"),
664 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
668 myMainShape = myMesh->GetShapeToMesh();
670 SMESHGUI_Operation::startOperation();
673 //================================================================================
675 * \brief computeMesh()
677 //================================================================================
679 void SMESHGUI_BaseComputeOp::computeMesh()
683 SMESH::MemoryReserve aMemoryReserve;
685 SMESH::compute_error_array_var aCompErrors;
688 bool computeFailed = true, memoryLack = false;
690 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
691 if ( !aMeshSObj ) // IPAL 21340
693 bool hasShape = myMesh->HasShapeToMesh();
694 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
697 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
698 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
699 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
700 if ( errors->length() > 0 ) {
701 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
703 SUIT_OverrideCursor aWaitCursor;
705 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
708 if (gen->Compute(myMesh, myMainShape))
709 computeFailed = false;
711 catch(const SALOME::SALOME_Exception & S_ex){
715 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
718 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
719 // check if there are memory problems
720 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
721 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
723 catch(const SALOME::SALOME_Exception & S_ex){
727 // NPAL16631: if ( !memoryLack )
729 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
730 update( UF_ObjBrowser | UF_Model );
733 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
734 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
737 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
740 SMESH::Update(myIObject, true);
744 MESSAGE ( "Exception thrown during mesh visualization" );
746 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
747 SMESH::OnVisuException();
754 LightApp_SelectionMgr *Sel = selectionMgr();
757 SALOME_ListIO selected;
758 selected.Append( myIObject );
759 Sel->setSelectedObjects( selected );
765 aMemoryReserve.release();
767 myCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
771 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
772 bool noHypoError = ( aHypErrors.isEmpty() );
774 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
775 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
777 bool isShowResultDlg = true;
778 switch( aNotifyMode ) {
779 case 0: // show the mesh computation result dialog NEVER
780 isShowResultDlg = false;
783 case 1: // show the mesh computation result dialog if there are some errors
784 if ( memoryLack || !noCompError || !noHypoError )
785 isShowResultDlg = true;
788 isShowResultDlg = false;
792 default: // show the result dialog after each mesh computation
793 isShowResultDlg = true;
797 if ( isShowResultDlg )
798 showComputeResult( memoryLack, noCompError,aCompErrors, noHypoError, aHypErrors );
801 void SMESHGUI_BaseComputeOp::showComputeResult( const bool theMemoryLack,
802 const bool theNoCompError,
803 SMESH::compute_error_array_var& theCompErrors,
804 const bool theNoHypoError,
805 const QString& theHypErrors )
807 bool hasShape = myMesh->HasShapeToMesh();
808 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
809 aCompDlg->myMemoryLackGroup->hide();
813 aCompDlg->myMemoryLackGroup->show();
814 aCompDlg->myFullInfo->hide();
815 aCompDlg->myBriefInfo->hide();
816 aCompDlg->myHypErrorGroup->hide();
817 aCompDlg->myCompErrorGroup->hide();
819 else if ( theNoCompError && theNoHypoError )
821 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
822 aCompDlg->myFullInfo->SetMeshInfo( aRes );
823 aCompDlg->myFullInfo->show();
824 aCompDlg->myBriefInfo->hide();
825 aCompDlg->myHypErrorGroup->hide();
826 aCompDlg->myCompErrorGroup->hide();
830 QTableWidget* tbl = aCompDlg->myTable;
831 SMESH::long_array_var aRes = myMesh->GetMeshInfo();
832 aCompDlg->myFullInfo->SetMeshInfo( aRes );
833 aCompDlg->myBriefInfo->show();
834 aCompDlg->myFullInfo->hide();
836 if ( theNoHypoError ) {
837 aCompDlg->myHypErrorGroup->hide();
840 aCompDlg->myHypErrorGroup->show();
841 aCompDlg->myHypErrorLabel->setText( theHypErrors );
844 if ( theNoCompError ) {
845 aCompDlg->myCompErrorGroup->hide();
848 aCompDlg->myCompErrorGroup->show();
851 aCompDlg->myPublishBtn->hide();
852 aCompDlg->myShowBtn->hide();
855 aCompDlg->myPublishBtn->show();
856 aCompDlg->myShowBtn->show();
859 // fill table of errors
860 tbl->setRowCount( theCompErrors->length() );
861 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
862 else tbl->showColumn( COL_SHAPE );
863 tbl->setColumnWidth( COL_ERROR, 200 );
865 bool hasBadMesh = false;
866 for ( int row = 0; row < theCompErrors->length(); ++row )
868 SMESH::ComputeError & err = theCompErrors[ row ];
870 QString text = err.algoName.in();
871 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
872 else tbl->item( row, COL_ALGO )->setText( text );
874 text = SMESH::errorText( err.code, err.comment.in() );
875 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
876 else tbl->item( row, COL_ERROR )->setText( text );
878 text = QString("%1").arg( err.subShapeID );
879 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
880 else tbl->item( row, COL_SHAPEID )->setText( text );
882 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
883 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
884 else tbl->item( row, COL_SHAPE )->setText( text );
886 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
887 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
888 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
890 text = err.hasBadMesh ? "hasBadMesh" : "";
891 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
892 else tbl->item( row, COL_BAD_MESH )->setText( text );
893 if ( err.hasBadMesh ) hasBadMesh = true;
895 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
896 tbl->resizeRowToContents( row );
898 tbl->resizeColumnToContents( COL_ALGO );
899 tbl->resizeColumnToContents( COL_SHAPE );
902 aCompDlg->myBadMeshBtn->show();
904 aCompDlg->myBadMeshBtn->hide();
906 tbl->setCurrentCell(0,0);
907 currentCellChanged(); // to update buttons
910 // show dialog and wait, becase Compute can be invoked from Preview operation
911 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
915 //================================================================================
917 * \brief Stops operation
919 //================================================================================
921 void SMESHGUI_BaseComputeOp::stopOperation()
923 SMESHGUI_Operation::stopOperation();
924 if ( myTShapeDisplayer )
925 myTShapeDisplayer->SetVisibility( false );
926 if ( myBadMeshDisplayer ) {
927 myBadMeshDisplayer->SetVisibility( false );
928 // delete it in order not to have problems at its destruction when the viewer
929 // where it worked is dead due to e.g. study closing
930 delete myBadMeshDisplayer;
931 myBadMeshDisplayer = 0;
936 //================================================================================
938 * \brief publish selected subshape
940 //================================================================================
942 void SMESHGUI_BaseComputeOp::onPublishShape()
944 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
945 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
948 SMESH::getSelectedRows( table(), rows );
950 foreach ( row, rows )
952 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
953 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
954 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
956 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
958 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
959 SALOMEDS::SObject_var so =
960 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
961 // look for myMainShape in the table
962 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
963 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
964 if ( so->_is_nil() ) {
965 table()->item( r, COL_SHAPE )->setText( so->GetName() );
966 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
971 if ( curSub == 1 ) continue;
973 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
974 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
975 if ( !so->_is_nil() ) {
976 table()->item( row, COL_SHAPE )->setText( so->GetName() );
977 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
981 getSMESHGUI()->getApp()->updateObjectBrowser();
982 currentCellChanged(); // to update buttons
985 //================================================================================
987 * \brief show mesh elements preventing computation of a submesh of current row
989 //================================================================================
991 void SMESHGUI_BaseComputeOp::onShowBadMesh()
993 myTShapeDisplayer->SetVisibility( false );
995 if ( SMESH::getSelectedRows( table(), rows ) == 1 ) {
996 bool hasBadMesh = ( !table()->item(rows.front(), COL_BAD_MESH)->text().isEmpty() );
998 int curSub = table()->item(rows.front(), COL_SHAPEID)->text().toInt();
999 SMESHGUI* gui = getSMESHGUI();
1000 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1001 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1002 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1003 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1004 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1005 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1006 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1007 // delete property !!!!!!!!!!
1008 vtkProperty* prop = vtkProperty::New();
1009 prop->SetLineWidth( aLineWidth * 3 );
1010 prop->SetPointSize( aPointSize * 3 );
1011 prop->SetColor( 250, 0, 250 );
1012 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1013 myBadMeshDisplayer->SetData( aMeshData._retn() );
1018 //================================================================================
1020 * \brief SLOT called when a selected cell in table() changed
1022 //================================================================================
1024 void SMESHGUI_BaseComputeOp::currentCellChanged()
1026 myTShapeDisplayer->SetVisibility( false );
1027 if ( myBadMeshDisplayer )
1028 myBadMeshDisplayer->SetVisibility( false );
1030 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1032 int nbSelected = SMESH::getSelectedRows( table(), rows );
1034 foreach ( row, rows )
1036 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1037 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1038 if ( hasData && !isPublished )
1039 publishEnable = true;
1041 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1042 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1044 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1051 if ( !table()->item(row, COL_BAD_MESH)->text().isEmpty() )
1054 myCompDlg->myPublishBtn->setEnabled( publishEnable );
1055 myCompDlg->myShowBtn ->setEnabled( showEnable );
1056 myCompDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1059 //================================================================================
1061 * \brief update preview
1063 //================================================================================
1065 void SMESHGUI_BaseComputeOp::onPreviewShape()
1067 if ( myTShapeDisplayer )
1069 SUIT_OverrideCursor aWaitCursor;
1071 SMESH::getSelectedRows( table(), rows );
1073 bool showOnly = true;
1075 foreach ( row, rows )
1077 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1079 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1083 currentCellChanged(); // to update buttons
1087 //================================================================================
1091 //================================================================================
1093 SMESHGUI_BaseComputeOp::~SMESHGUI_BaseComputeOp()
1097 delete myTShapeDisplayer;
1098 if ( myBadMeshDisplayer )
1099 delete myBadMeshDisplayer;
1102 //================================================================================
1104 * \brief Gets dialog of compute operation
1105 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1107 //================================================================================
1109 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::computeDlg() const
1113 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1114 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), false );
1115 // connect signals and slots
1116 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1117 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1118 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1120 QTableWidget* aTable = me->table();
1121 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1122 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
1127 //================================================================================
1129 * \brief returns from compute mesh result dialog
1131 //================================================================================
1133 bool SMESHGUI_BaseComputeOp::onApply()
1138 //================================================================================
1140 * \brief Return a table
1142 //================================================================================
1144 QTableWidget* SMESHGUI_BaseComputeOp::table()
1146 return myCompDlg->myTable;
1150 //================================================================================
1152 * \brief Constructor
1154 //================================================================================
1156 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
1157 : SMESHGUI_BaseComputeOp()
1162 //================================================================================
1164 * \brief Desctructor
1166 //================================================================================
1168 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1172 //================================================================================
1174 * \brief perform it's intention action: compute mesh
1176 //================================================================================
1178 void SMESHGUI_ComputeOp::startOperation()
1180 SMESHGUI_BaseComputeOp::startOperation();
1181 if (myMesh->_is_nil())
1186 //================================================================================
1188 * \brief check the same operations on the same mesh
1190 //================================================================================
1192 bool SMESHGUI_BaseComputeOp::isValid( SUIT_Operation* theOp ) const
1194 SMESHGUI_BaseComputeOp* baseOp = dynamic_cast<SMESHGUI_BaseComputeOp*>( theOp );
1196 if ( !myMesh->_is_nil() && baseOp ) {
1197 SMESH::SMESH_Mesh_var aMesh = baseOp->getMesh();
1198 if ( !aMesh->_is_nil() && aMesh->GetId() == myMesh->GetId() ) ret = false;
1203 //================================================================================
1205 * \brief Gets dialog of this operation
1206 * \retval LightApp_Dialog* - pointer to dialog of this operation
1208 //================================================================================
1210 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1212 return computeDlg();
1215 //================================================================================
1217 * \brief Constructor
1219 //================================================================================
1221 SMESHGUI_PrecomputeOp::SMESHGUI_PrecomputeOp()
1222 : SMESHGUI_BaseComputeOp(),
1226 myPreviewDisplayer( 0 )
1228 myHelpFileName = "constructing_meshes_page.html#preview_mesh_anchor";
1231 //================================================================================
1235 //================================================================================
1237 SMESHGUI_PrecomputeOp::~SMESHGUI_PrecomputeOp()
1244 if ( myPreviewDisplayer )
1245 delete myPreviewDisplayer;
1246 myPreviewDisplayer = 0;
1249 //================================================================================
1251 * \brief Gets current dialog of this operation
1252 * \retval LightApp_Dialog* - pointer to dialog of this operation
1254 //================================================================================
1256 LightApp_Dialog* SMESHGUI_PrecomputeOp::dlg() const
1261 //================================================================================
1263 * \brief perform it's intention action: prepare data
1265 //================================================================================
1267 void SMESHGUI_PrecomputeOp::startOperation()
1271 myDlg = new SMESHGUI_PrecomputeDlg( desktop() );
1274 connect( myDlg, SIGNAL( preview() ), this, SLOT( onPreview() ) );
1275 connect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onCompute() ) );
1276 connect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onCompute() ) );
1278 myActiveDlg = myDlg;
1280 // connect signal to compute dialog. which will be shown after Compute mesh operation
1281 SMESHGUI_ComputeDlg* cmpDlg = computeDlg();
1284 // disconnect signals
1285 disconnect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1286 disconnect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1287 disconnect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1288 disconnect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1289 disconnect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1292 if( cmpDlg->testButtonFlags( QtxDialog::OK ) )
1293 connect( cmpDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1294 if( cmpDlg->testButtonFlags( QtxDialog::Apply ) )
1295 connect( cmpDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1296 if( cmpDlg->testButtonFlags( QtxDialog::Help ) )
1297 connect( cmpDlg, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
1298 if( cmpDlg->testButtonFlags( QtxDialog::Cancel ) )
1299 connect( cmpDlg, SIGNAL( dlgCancel() ), this, SLOT( onCancel() ) );
1300 if( cmpDlg->testButtonFlags( QtxDialog::Close ) )
1301 connect( cmpDlg, SIGNAL( dlgClose() ), this, SLOT( onCancel() ) );
1304 SMESHGUI_BaseComputeOp::startOperation();
1305 if (myMesh->_is_nil())
1308 if (myDlg->getPreviewMode() == -1)
1310 // nothing to preview
1311 SUIT_MessageBox::warning(desktop(),
1312 tr("SMESH_WRN_WARNING"),
1313 tr("SMESH_WRN_NOTHING_PREVIEW"));
1318 // disconnect slot from preview dialog to have Apply from results of compute operation only
1319 disconnect( myDlg, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
1320 disconnect( myDlg, SIGNAL( dlgApply() ), this, SLOT( onApply() ) );
1325 //================================================================================
1327 * \brief Stops operation
1329 //================================================================================
1331 void SMESHGUI_PrecomputeOp::stopOperation()
1333 if ( myPreviewDisplayer )
1335 myPreviewDisplayer->SetVisibility( false );
1336 delete myPreviewDisplayer;
1337 myPreviewDisplayer = 0;
1339 myMapShapeId.clear();
1340 SMESHGUI_BaseComputeOp::stopOperation();
1343 //================================================================================
1345 * \brief reinitialize dialog after operaiton become active again
1347 //================================================================================
1349 void SMESHGUI_PrecomputeOp::resumeOperation()
1351 if ( myActiveDlg == myDlg )
1353 SMESHGUI_BaseComputeOp::resumeOperation();
1356 //================================================================================
1358 * \brief perform it's intention action: reinitialise dialog
1360 //================================================================================
1362 void SMESHGUI_PrecomputeOp::initDialog()
1366 QMap<int, int> modeMap;
1367 _PTR(SObject) pMesh = studyDS()->FindObjectID( myIObject->getEntry() );
1368 getAssignedAlgos( pMesh, modeMap );
1369 if ( modeMap.contains( SMESH::DIM_3D ) )
1371 if ( modeMap.contains( SMESH::DIM_2D ) )
1372 modes.append( SMESH::DIM_2D );
1373 if ( modeMap.contains( SMESH::DIM_1D ) )
1374 modes.append( SMESH::DIM_1D );
1376 else if ( modeMap.contains( SMESH::DIM_2D ) )
1378 if ( modeMap.contains( SMESH::DIM_1D ) )
1379 modes.append( SMESH::DIM_1D );
1382 myOrderMgr = new SMESHGUI_MeshOrderMgr( myDlg->getMeshOrderBox() );
1383 myOrderMgr->SetMesh( myMesh );
1384 bool isOrder = myOrderMgr->GetMeshOrder(myPrevOrder);
1385 myDlg->getMeshOrderBox()->setShown(isOrder);
1391 myDlg->setPreviewModes( modes );
1394 //================================================================================
1396 * \brief detect asigned mesh algorithms
1398 //================================================================================
1400 void SMESHGUI_PrecomputeOp::getAssignedAlgos(_PTR(SObject) theMesh,
1401 QMap<int,int>& theModeMap)
1403 _PTR(SObject) aHypRoot;
1404 _PTR(GenericAttribute) anAttr;
1405 int aPart = SMESH::Tag_RefOnAppliedAlgorithms;
1406 if ( theMesh && theMesh->FindSubObject( aPart, aHypRoot ) )
1408 _PTR(ChildIterator) anIter =
1409 SMESH::GetActiveStudyDocument()->NewChildIterator( aHypRoot );
1410 for ( ; anIter->More(); anIter->Next() )
1412 _PTR(SObject) anObj = anIter->Value();
1413 _PTR(SObject) aRefObj;
1414 if ( anObj->ReferencedObject( aRefObj ) )
1419 if ( anObj->FindAttribute( anAttr, "AttributeName" ) )
1421 CORBA::Object_var aVar = _CAST(SObject,anObj)->GetObject();
1422 if ( CORBA::is_nil( aVar ) )
1425 for( int dim = SMESH::DIM_1D; dim <= SMESH::DIM_3D; dim++ )
1427 SMESH::SMESH_Algo_var algo;
1429 case SMESH::DIM_1D: algo = SMESH::SMESH_1D_Algo::_narrow( aVar ); break;
1430 case SMESH::DIM_2D: algo = SMESH::SMESH_2D_Algo::_narrow( aVar ); break;
1431 case SMESH::DIM_3D: algo = SMESH::SMESH_3D_Algo::_narrow( aVar ); break;
1434 if ( !algo->_is_nil() )
1435 theModeMap[ dim ] = 0;
1442 //================================================================================
1444 * \brief perform it's intention action: compute mesh
1446 //================================================================================
1448 void SMESHGUI_PrecomputeOp::onCompute()
1451 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1452 myOrderMgr->SetMeshOrder();
1453 myMapShapeId.clear();
1454 myActiveDlg = computeDlg();
1458 //================================================================================
1460 * \brief perform it's intention action: compute mesh
1462 //================================================================================
1464 void SMESHGUI_PrecomputeOp::onCancel()
1466 QObject* curDlg = sender();
1467 if ( curDlg == computeDlg() && myActiveDlg == myDlg )
1469 // return from error messages
1474 bool isRestoreOrder = false;
1475 if ( myActiveDlg == myDlg && !myMesh->_is_nil() && myMapShapeId.count() )
1477 // ask to remove already computed mesh elements
1478 if ( SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1479 tr( "CLEAR_SUBMESH_QUESTION" ),
1480 tr( "SMESH_BUT_DELETE" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0 )
1482 // remove all submeshes for collected shapes
1483 QMap<int,int>::const_iterator it = myMapShapeId.constBegin();
1484 for ( ; it != myMapShapeId.constEnd(); ++it )
1485 myMesh->ClearSubMesh( *it );
1486 isRestoreOrder = true;
1490 // return previous mesh order
1491 if (myOrderMgr && myOrderMgr->IsOrderChanged()) {
1492 if (!isRestoreOrder)
1494 (SUIT_MessageBox::question( desktop(), tr( "SMESH_WARNING" ),
1495 tr( "SMESH_REJECT_MESH_ORDER" ),
1496 tr( "SMESH_BUT_YES" ), tr( "SMESH_BUT_NO" ), 0, 1 ) == 0);
1498 myOrderMgr->SetMeshOrder(myPrevOrder);
1504 myMapShapeId.clear();
1505 SMESHGUI_BaseComputeOp::onCancel();
1508 //================================================================================
1510 * \brief perform it's intention action: preview mesh
1512 //================================================================================
1514 void SMESHGUI_PrecomputeOp::onPreview()
1516 if ( !myDlg || myMesh->_is_nil() || myMainShape->_is_nil() )
1519 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1523 // set modified submesh priority if any
1524 if (myOrderMgr && myOrderMgr->IsOrderChanged())
1525 myOrderMgr->SetMeshOrder();
1527 // Compute preview of mesh,
1528 // i.e. compute mesh till indicated dimension
1529 int dim = myDlg->getPreviewMode();
1531 SMESH::MemoryReserve aMemoryReserve;
1533 SMESH::compute_error_array_var aCompErrors;
1536 bool computeFailed = true, memoryLack = false;
1538 SMESHGUI_ComputeDlg* aCompDlg = computeDlg();
1539 aCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1541 SMESHGUI* gui = getSMESHGUI();
1542 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1543 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1544 if ( errors->length() > 0 ) {
1545 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1548 SUIT_OverrideCursor aWaitCursor;
1550 SVTK_ViewWindow* view = SMESH::GetViewWindow( gui );
1551 if ( myPreviewDisplayer ) delete myPreviewDisplayer;
1552 myPreviewDisplayer = new SMESHGUI_MeshEditPreview( view );
1554 SMESH::long_array_var aShapesId = new SMESH::long_array();
1556 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1560 SMESH::MeshPreviewStruct_var previewData =
1561 gen->Precompute(myMesh, myMainShape, (SMESH::Dimension)dim, aShapesId);
1562 SMESH::MeshPreviewStruct* previewRes = previewData._retn();
1563 if ( previewRes && previewRes->nodesXYZ.length() > 0 )
1565 computeFailed = false;
1566 myPreviewDisplayer->SetData( previewRes );
1567 // append shape indeces with computed mesh entities
1568 for ( int i = 0, n = aShapesId->length(); i < n; i++ )
1569 myMapShapeId[ aShapesId[ i ] ] = 0;
1572 myPreviewDisplayer->SetVisibility(false);
1574 catch(const SALOME::SALOME_Exception & S_ex){
1576 myPreviewDisplayer->SetVisibility(false);
1580 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1583 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1584 // check if there are memory problems
1585 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1586 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1588 catch(const SALOME::SALOME_Exception & S_ex){
1593 aMemoryReserve.release();
1595 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1596 bool noHypoError = ( aHypErrors.isEmpty() );
1598 SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( gui );
1599 int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1601 bool isShowError = true;
1602 switch( aNotifyMode ) {
1603 case 0: // show the mesh computation result dialog NEVER
1604 isShowError = false;
1606 case 1: // show the mesh computation result dialog if there are some errors
1607 default: // show the result dialog after each mesh computation
1608 if ( !computeFailed && !memoryLack && noCompError && noHypoError )
1609 isShowError = false;
1613 aWaitCursor.suspend();
1618 aCompDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1619 showComputeResult( memoryLack, noCompError, aCompErrors, noHypoError, aHypErrors );
1624 //================================================================================
1626 * \brief Constructor
1628 //================================================================================
1630 SMESHGUI_PrecomputeDlg::SMESHGUI_PrecomputeDlg( QWidget* parent )
1631 : SMESHGUI_Dialog( parent, false, false, OK | Cancel | Help ),
1634 setWindowTitle( tr( "CAPTION" ) );
1636 setButtonText( OK, tr( "COMPUTE" ) );
1637 QFrame* main = mainFrame();
1639 QVBoxLayout* layout = new QVBoxLayout( main );
1641 myOrderBox = new SMESHGUI_MeshOrderBox( main );
1642 layout->addWidget(myOrderBox);
1644 QFrame* frame = new QFrame( main );
1645 layout->setMargin(0); layout->setSpacing(0);
1646 layout->addWidget( frame );
1648 QHBoxLayout* frameLay = new QHBoxLayout( frame );
1649 frameLay->setMargin(0); frameLay->setSpacing(SPACING);
1651 myPreviewMode = new QtxComboBox( frame );
1652 frameLay->addWidget( myPreviewMode );
1654 myPreviewBtn = new QPushButton( tr( "PREVIEW" ), frame );
1655 frameLay->addWidget( myPreviewBtn );
1657 connect( myPreviewBtn, SIGNAL( clicked( bool ) ), this, SIGNAL( preview() ) );
1660 //================================================================================
1664 //================================================================================
1666 SMESHGUI_PrecomputeDlg::~SMESHGUI_PrecomputeDlg()
1670 //================================================================================
1672 * \brief Sets available preview modes
1674 //================================================================================
1676 void SMESHGUI_PrecomputeDlg::setPreviewModes( const QList<int>& theModes )
1678 myPreviewMode->clear();
1679 QList<int>::const_iterator it = theModes.constBegin();
1680 for ( int i = 0; it != theModes.constEnd(); ++it, i++ )
1682 QString mode = QString( "PREVIEW_%1" ).arg( *it );
1683 myPreviewMode->addItem( tr( mode.toLatin1().data() ) );
1684 myPreviewMode->setId( i, *it );
1686 myPreviewBtn->setEnabled( !theModes.isEmpty() );
1689 //================================================================================
1691 * \brief Returns current preview mesh mode
1693 //================================================================================
1695 int SMESHGUI_PrecomputeDlg::getPreviewMode() const
1697 return myPreviewMode->currentId();
1700 //================================================================================
1702 * \brief Returns current preview mesh mode
1704 //================================================================================
1706 SMESHGUI_MeshOrderBox* SMESHGUI_PrecomputeDlg::getMeshOrderBox() const
1712 //================================================================================
1714 * \brief Constructor
1716 //================================================================================
1718 SMESHGUI_EvaluateOp::SMESHGUI_EvaluateOp()
1719 : SMESHGUI_BaseComputeOp()
1724 //================================================================================
1726 * \brief Desctructor
1728 //================================================================================
1730 SMESHGUI_EvaluateOp::~SMESHGUI_EvaluateOp()
1734 //================================================================================
1736 * \brief perform it's intention action: compute mesh
1738 //================================================================================
1740 void SMESHGUI_EvaluateOp::startOperation()
1742 SMESHGUI_BaseComputeOp::evaluateDlg();
1743 SMESHGUI_BaseComputeOp::startOperation();
1744 if (myMesh->_is_nil())
1749 //================================================================================
1751 * \brief Gets dialog of this operation
1752 * \retval LightApp_Dialog* - pointer to dialog of this operation
1754 //================================================================================
1756 LightApp_Dialog* SMESHGUI_EvaluateOp::dlg() const
1758 return evaluateDlg();
1761 //================================================================================
1763 * \brief evaluateMesh()
1765 //================================================================================
1767 void SMESHGUI_BaseComputeOp::evaluateMesh()
1771 SMESH::MemoryReserve aMemoryReserve;
1773 SMESH::compute_error_array_var aCompErrors;
1776 bool evaluateFailed = true, memoryLack = false;
1777 SMESH::long_array_var aRes;
1779 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
1780 if ( !aMeshSObj ) // IPAL21340
1783 bool hasShape = myMesh->HasShapeToMesh();
1784 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
1787 myCompDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
1788 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
1789 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
1790 if ( errors->length() > 0 ) {
1791 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
1793 SUIT_OverrideCursor aWaitCursor;
1795 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1798 aRes = gen->Evaluate(myMesh, myMainShape);
1800 catch(const SALOME::SALOME_Exception & S_ex){
1805 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1808 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
1810 catch(const SALOME::SALOME_Exception & S_ex){
1816 aMemoryReserve.release();
1818 evaluateFailed = ( aCompErrors->length() > 0 );
1819 myCompDlg->setWindowTitle(tr( evaluateFailed ? "SMESH_WRN_EVALUATE_FAILED" : "SMESH_EVALUATE_SUCCEED"));
1823 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1824 bool noHypoError = ( aHypErrors.isEmpty() );
1826 //SUIT_ResourceMgr* resMgr = SMESH::GetResourceMgr( SMESHGUI::GetSMESHGUI() );
1827 //int aNotifyMode = resMgr->integerValue( "SMESH", "show_result_notification" );
1829 bool isShowResultDlg = true;
1831 //switch( aNotifyMode ) {
1832 //case 0: // show the mesh computation result dialog NEVER
1833 //isShowResultDlg = false;
1836 //case 1: // show the mesh computation result dialog if there are some errors
1837 //if ( memoryLack || !noHypoError )
1838 // isShowResultDlg = true;
1841 // isShowResultDlg = false;
1845 //default: // show the result dialog after each mesh computation
1846 //isShowResultDlg = true;
1850 if ( isShowResultDlg )
1851 showEvaluateResult( aRes, memoryLack, noCompError, aCompErrors,
1852 noHypoError, aHypErrors);
1856 void SMESHGUI_BaseComputeOp::showEvaluateResult(const SMESH::long_array& theRes,
1857 const bool theMemoryLack,
1858 const bool theNoCompError,
1859 SMESH::compute_error_array_var& theCompErrors,
1860 const bool theNoHypoError,
1861 const QString& theHypErrors)
1863 bool hasShape = myMesh->HasShapeToMesh();
1864 SMESHGUI_ComputeDlg* aCompDlg = evaluateDlg();
1865 aCompDlg->myMemoryLackGroup->hide();
1867 if ( theMemoryLack )
1869 aCompDlg->myMemoryLackGroup->show();
1870 aCompDlg->myFullInfo->hide();
1871 aCompDlg->myBriefInfo->hide();
1872 aCompDlg->myHypErrorGroup->hide();
1873 aCompDlg->myCompErrorGroup->hide();
1875 else if ( theNoCompError && theNoHypoError )
1877 aCompDlg->myFullInfo->SetMeshInfo( theRes );
1878 aCompDlg->myFullInfo->show();
1879 aCompDlg->myBriefInfo->hide();
1880 aCompDlg->myHypErrorGroup->hide();
1881 aCompDlg->myCompErrorGroup->hide();
1885 QTableWidget* tbl = aCompDlg->myTable;
1886 aCompDlg->myBriefInfo->SetMeshInfo( theRes );
1887 aCompDlg->myBriefInfo->show();
1888 aCompDlg->myFullInfo->hide();
1890 if ( theNoHypoError ) {
1891 aCompDlg->myHypErrorGroup->hide();
1894 aCompDlg->myHypErrorGroup->show();
1895 aCompDlg->myHypErrorLabel->setText( theHypErrors );
1898 if ( theNoCompError ) {
1899 aCompDlg->myCompErrorGroup->hide();
1902 aCompDlg->myCompErrorGroup->show();
1904 aCompDlg->myPublishBtn->hide();
1905 aCompDlg->myShowBtn->hide();
1907 // fill table of errors
1908 tbl->setRowCount( theCompErrors->length() );
1909 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1910 else tbl->showColumn( COL_SHAPE );
1911 tbl->setColumnWidth( COL_ERROR, 200 );
1913 bool hasBadMesh = false;
1914 for ( int row = 0; row < theCompErrors->length(); ++row )
1916 SMESH::ComputeError & err = theCompErrors[ row ];
1918 QString text = err.algoName.in();
1919 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1920 else tbl->item( row, COL_ALGO )->setText( text );
1922 text = SMESH::errorText( err.code, err.comment.in() );
1923 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1924 else tbl->item( row, COL_ERROR )->setText( text );
1926 text = QString("%1").arg( err.subShapeID );
1927 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1928 else tbl->item( row, COL_SHAPEID )->setText( text );
1930 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1931 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1932 else tbl->item( row, COL_SHAPE )->setText( text );
1934 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1935 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1936 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1938 text = err.hasBadMesh ? "hasBadMesh" : "";
1939 if ( !tbl->item( row, COL_BAD_MESH ) ) tbl->setItem( row, COL_BAD_MESH, new QTableWidgetItem( text ) );
1940 else tbl->item( row, COL_BAD_MESH )->setText( text );
1941 if ( err.hasBadMesh ) hasBadMesh = true;
1943 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1944 tbl->resizeRowToContents( row );
1946 tbl->resizeColumnToContents( COL_ALGO );
1947 tbl->resizeColumnToContents( COL_SHAPE );
1950 aCompDlg->myBadMeshBtn->show();
1952 aCompDlg->myBadMeshBtn->hide();
1954 tbl->setCurrentCell(0,0);
1955 currentCellChanged(); // to update buttons
1958 // show dialog and wait, becase Compute can be invoked from Preview operation
1959 //aCompDlg->exec(); // this way it becomes modal - impossible to rotate model in the Viewer
1964 //================================================================================
1966 * \brief Gets dialog of evaluate operation
1967 * \retval SMESHGUI_ComputeDlg* - pointer to dialog of this operation
1969 //================================================================================
1971 SMESHGUI_ComputeDlg* SMESHGUI_BaseComputeOp::evaluateDlg() const
1975 SMESHGUI_BaseComputeOp* me = (SMESHGUI_BaseComputeOp*)this;
1976 me->myCompDlg = new SMESHGUI_ComputeDlg( desktop(), true );
1977 // connect signals and slots
1978 connect(myCompDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
1979 connect(myCompDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
1980 connect(myCompDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
1981 QTableWidget* aTable = me->table();
1982 connect(aTable, SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
1983 connect(aTable, SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));