1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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
24 // File : SMESHGUI_ComputeDlg.cxx
25 // Author : Edward AGAPOV
28 #include "SMESHGUI_ComputeDlg.h"
31 #include "SMESHGUI_GEOMGenUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_HypothesesUtils.h"
37 #include "SMDS_SetIterator.hxx"
38 #include <SMDS_Mesh.hxx>
41 #include "GEOM_Actor.h"
43 #include "LightApp_SelectionMgr.h"
44 #include "LightApp_UpdateFlags.h"
45 #include "SALOMEDSClient_SObject.hxx"
46 #include "SALOME_ListIO.hxx"
47 #include "SVTK_ViewWindow.h"
48 #include "SVTK_ViewModel.h"
49 #include "SalomeApp_Tools.h"
50 #include "SalomeApp_Application.h"
51 #include "SUIT_ResourceMgr.h"
52 #include "SUIT_OverrideCursor.h"
53 #include "SUIT_MessageBox.h"
54 #include "SUIT_Desktop.h"
55 #include "SUIT_Study.h"
56 #include "OB_Browser.h"
59 #include <BRep_Tool.hxx>
61 #include <TopExp_Explorer.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
65 #include <TopLoc_Location.hxx>
66 #include <Poly_Triangulation.hxx>
67 #include <Bnd_Box.hxx>
68 #include <BRepBndLib.hxx>
69 #include <BRepMesh_IncrementalMesh.hxx>
71 #include <Standard_ErrorHandler.hxx>
76 #include <qpushbutton.h>
78 #include <qbuttongroup.h>
79 #include <qradiobutton.h>
82 #include <qhgroupbox.h>
83 #include <qvgroupbox.h>
85 #include <vtkProperty.h>
88 #include <SALOMEconfig.h>
89 #include CORBA_SERVER_HEADER(SMESH_Gen)
90 #include CORBA_SERVER_HEADER(SMESH_Mesh)
99 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
101 #define _SEPARATOR(father) \
103 /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
104 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
105 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
106 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
107 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
110 enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, NB_COLUMNS };
112 using namespace SMESH;
116 //=============================================================================
118 * \brief Allocate some memory at construction and release it at destruction.
119 * Is used to be able to continue working after mesh generation or visualization
120 * break due to lack of memory
122 //=============================================================================
127 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
128 ~MemoryReserve() { delete [] myBuf; }
131 // =========================================================================================
133 * \brief Class showing shapes without publishing
135 // =========================================================================================
137 class TShapeDisplayer
140 // -----------------------------------------------------------------------
141 TShapeDisplayer(): myViewWindow(0)
143 myProperty = vtkProperty::New();
144 myProperty->SetRepresentationToWireframe();
145 myProperty->SetColor( 250, 0, 250 );
146 myProperty->SetAmbientColor( 250, 0, 250 );
147 myProperty->SetDiffuseColor( 250, 0, 250 );
148 //myProperty->SetSpecularColor( 250, 0, 250 );
149 myProperty->SetLineWidth( 5 );
151 // -----------------------------------------------------------------------
155 myProperty->Delete();
157 // -----------------------------------------------------------------------
160 if ( hasViewWindow() ) {
161 TActorIterator actorIt = actorIterator();
162 while ( actorIt.more() )
163 if (VTKViewer_Actor* anActor = actorIt.next()) {
164 myViewWindow->RemoveActor( anActor );
168 myIndexToShape.Clear();
170 myShownActors.clear();
173 // -----------------------------------------------------------------------
174 void SetVisibility (bool theVisibility)
176 TActorIterator actorIt = shownIterator();
177 while ( actorIt.more() )
178 if (VTKViewer_Actor* anActor = actorIt.next())
179 anActor->SetVisibility(theVisibility);
180 SMESH::RepaintCurrentView();
182 // -----------------------------------------------------------------------
183 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
186 if ( !aMainShape->_is_nil() )
187 mainEntry = aMainShape->GetStudyEntry();
188 return ( myMainEntry == mainEntry &&
189 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
191 // -----------------------------------------------------------------------
192 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
194 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
196 if ( !aMainShape->_is_nil() )
197 mainEntry = aMainShape->GetStudyEntry();
198 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
201 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
202 checkTriangulation( aShape );
203 TopExp::MapShapes(aShape, myIndexToShape);
204 myActors.resize( myIndexToShape.Extent(), 0 );
205 myShownActors.reserve( myIndexToShape.Extent() );
207 myMainEntry = mainEntry;
208 myViewWindow = aViewWindow;
210 if ( only ) { // hide shown actors
211 TActorIterator actorIt = shownIterator();
212 while ( actorIt.more() )
213 if (VTKViewer_Actor* anActor = actorIt.next())
214 anActor->SetVisibility(false);
215 myShownActors.clear();
217 // find actors to show
218 TopoDS_Shape aShape = myIndexToShape( subShapeID );
219 if ( !aShape.IsNull() ) {
220 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
221 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
222 //checkTriangulation( exp.Current() );
223 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
224 myShownActors.push_back( anActor );
226 if ( type == TopAbs_FACE ) {
227 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
228 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
229 if ( !BRep_Tool::Degenerated( edge ))
230 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
231 myShownActors.push_back( anActor );
235 myBuiltSubs.insert( subShapeID );
238 // -----------------------------------------------------------------------
242 typedef std::vector<GEOM_Actor*> TActorVec;
244 TActorVec myShownActors;
245 TopTools_IndexedMapOfShape myIndexToShape;
247 SVTK_ViewWindow* myViewWindow;
248 vtkProperty* myProperty;
249 std::set<int> myBuiltSubs;
251 // -----------------------------------------------------------------------
252 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
253 TActorIterator actorIterator() {
254 return TActorIterator( myActors.begin(), myActors.end() );
256 TActorIterator shownIterator() {
257 return TActorIterator( myShownActors.begin(), myShownActors.end() );
259 // -----------------------------------------------------------------------
260 GEOM_Actor* getActor(const TopoDS_Shape& shape)
262 int index = myIndexToShape.FindIndex( shape ) - 1;
263 if ( index < 0 || index >= myActors.size() )
265 GEOM_Actor* & actor = myActors[ index ];
267 actor = GEOM_Actor::New();
269 actor->setInputShape(shape,0,0);
270 //actor->SetProperty(myProperty);
271 actor->SetShadingProperty(myProperty);
272 actor->SetWireframeProperty(myProperty);
273 actor->SetPreviewProperty(myProperty);
274 actor->PickableOff();
275 // if ( shape.ShapeType() == TopAbs_EDGE )
276 // actor->SubShapeOn();
277 myViewWindow->AddActor( actor );
282 // -----------------------------------------------------------------------
283 void checkTriangulation(const TopoDS_Shape& shape)
285 TopLoc_Location aLoc;
286 Standard_Boolean alreadymesh = Standard_True;
287 TopExp_Explorer ex(shape, TopAbs_FACE);
289 for (; ex.More(); ex.Next()) {
290 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
291 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
292 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
295 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
296 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
297 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
298 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
300 if (alreadymesh) return;
301 // Compute default deflection
303 BRepBndLib::Add(shape, B);
304 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
305 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
306 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
307 BRepMesh_IncrementalMesh MESH(shape,deflection);
309 // -----------------------------------------------------------------------
310 bool hasViewWindow() const
312 if ( !myViewWindow ) return false;
314 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
315 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
321 // =========================================================================================
323 * \brief Return text describing an error
325 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
326 QString errorText(int errCode, const char* comment)
330 CASE2TEXT( COMPERR_OK );
331 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
332 CASE2TEXT( COMPERR_STD_EXCEPTION );
333 CASE2TEXT( COMPERR_OCC_EXCEPTION );
334 CASE2TEXT( COMPERR_SLM_EXCEPTION );
335 CASE2TEXT( COMPERR_EXCEPTION );
336 CASE2TEXT( COMPERR_MEMORY_PB );
337 CASE2TEXT( COMPERR_BAD_SHAPE );
338 case SMESH::COMPERR_ALGO_FAILED:
339 if ( strlen(comment) == 0 )
340 text = QObject::tr("COMPERR_ALGO_FAILED");
343 text = QString("#%1").arg( -errCode );
345 if ( text.length() > 0 ) text += ". ";
346 return text + comment;
348 // -----------------------------------------------------------------------
350 * \brief Return SO of a subshape
352 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
354 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
355 if ( subShapeID == 1 || !so )
357 _PTR(ChildIterator) it;
358 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
359 it = study->NewChildIterator(so);
362 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
363 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
364 if ( !geom->_is_nil() ) {
365 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
366 if ( list->length() == 1 && list[0] == subShapeID )
373 // -----------------------------------------------------------------------
375 * \brief Return subshape by ID
377 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
379 GEOM::GEOM_Object_var aSubShape;
380 if ( subShapeID == 1 )
381 aSubShape = aMainShape;
382 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
383 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
385 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
386 return aSubShape._retn();
388 // -----------------------------------------------------------------------
390 * \brief Return shape type name
392 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
393 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
396 if ( !aShape->_is_nil() ) {
397 switch ( aShape->GetShapeType() ) {
404 CASE2NAME( COMPSOLID );
405 CASE2NAME( COMPOUND );
411 // -----------------------------------------------------------------------
413 * \brief Return text describing a subshape
415 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
418 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
419 text = aSO->GetName();
421 text = QString("#%1").arg( subShapeID );
422 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
423 if ( typeName.length() )
424 text += QString(" (%1)").arg(typeName);
428 // -----------------------------------------------------------------------
430 * \brief Return text describing a subshape
432 bool getSelectedRows(QTable* table, list< int > & rows)
435 int nbSel = table->numSelections();
436 for ( int i = 0; i < nbSel; ++i )
438 QTableSelection selected = table->selection(i);
439 if ( !selected.isActive() ) continue;
440 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
441 rows.push_back( row );
443 return !rows.empty();
449 // =========================================================================================
451 * \brief Box showing mesh info
453 // =========================================================================================
455 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
456 :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
459 QLabel* lab1 = new QLabel(this);
460 QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
461 QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
462 QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
464 QFont italic = lab1->font(); italic.setItalic(true);
465 QFont bold = lab1->font(); bold.setBold(true);
467 lab1->setMinimumWidth(100); lab1->setFont( italic );
468 lab2->setMinimumWidth(100); lab2->setFont( italic );
469 lab3->setMinimumWidth(100); lab3->setFont( italic );
470 lab4->setMinimumWidth(100); lab4->setFont( italic );
475 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
476 myNbNode = new QLabel( this );
483 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
484 myNbEdge = new QLabel( this );
485 myNbLinEdge = new QLabel( this );
486 myNbQuadEdge = new QLabel( this );
491 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
492 myNbFace = new QLabel( this );
493 myNbLinFace = new QLabel( this );
494 myNbQuadFace = new QLabel( this );
496 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
497 myNbTrai = new QLabel( this );
498 myNbLinTrai = new QLabel( this );
499 myNbQuadTrai = new QLabel( this );
501 new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
502 myNbQuad = new QLabel( this );
503 myNbLinQuad = new QLabel( this );
504 myNbQuadQuad = new QLabel( this );
506 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
507 myNbPolyg = new QLabel( this );
508 new QLabel("",this );
509 new QLabel("", this );
514 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
515 myNbVolum = new QLabel( this );
516 myNbLinVolum = new QLabel( this );
517 myNbQuadVolum = new QLabel( this );
519 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
520 myNbTetra = new QLabel( this );
521 myNbLinTetra = new QLabel( this );
522 myNbQuadTetra = new QLabel( this );
524 new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
525 myNbHexa = new QLabel( this );
526 myNbLinHexa = new QLabel( this );
527 myNbQuadHexa = new QLabel( this );
529 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
530 myNbPyra = new QLabel( this );
531 myNbLinPyra = new QLabel( this );
532 myNbQuadPyra = new QLabel( this );
534 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
535 myNbPrism = new QLabel( this );
536 myNbLinPrism = new QLabel( this );
537 myNbQuadPrism = new QLabel( this );
539 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
540 myNbPolyh = new QLabel( this );
541 new QLabel("", this );
542 new QLabel("", this );
547 new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
548 myNbNode = new QLabel( this );
553 new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
554 myNbEdge = new QLabel( this );
555 myNbLinEdge = new QLabel( this );
556 myNbQuadEdge = new QLabel( this );
559 new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
560 myNbFace = new QLabel( this );
561 myNbLinFace = new QLabel( this );
562 myNbQuadFace = new QLabel( this );
565 new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
566 myNbVolum = new QLabel( this );
567 myNbLinVolum = new QLabel( this );
568 myNbQuadVolum = new QLabel( this );
572 // =========================================================================================
574 * \brief Set mesh info
576 // =========================================================================================
578 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
580 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
584 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
587 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
588 myNbEdge ->setText( QString("%1").arg( nbTot ));
589 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
590 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
593 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
594 myNbFace ->setText( QString("%1").arg( nbTot ));
595 myNbLinFace ->setText( QString("%1").arg( nbLin ));
596 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
599 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
600 myNbVolum ->setText( QString("%1").arg( nbTot ));
601 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
602 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
607 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
608 myNbTrai ->setText( QString("%1").arg( nbTot ));
609 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
610 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
612 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
613 myNbQuad ->setText( QString("%1").arg( nbTot ));
614 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
615 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
617 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
620 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
621 myNbTetra ->setText( QString("%1").arg( nbTot ));
622 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
623 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
625 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
626 myNbHexa ->setText( QString("%1").arg( nbTot ));
627 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
628 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
630 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
631 myNbPyra ->setText( QString("%1").arg( nbTot ));
632 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
633 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
635 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
636 myNbPrism ->setText( QString("%1").arg( nbTot ));
637 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
638 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
640 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
644 // =========================================================================================
646 * \brief Dialog to compute a mesh and show computation errors
648 //=======================================================================
650 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, OK/* | Help*/ )
652 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
654 QFrame* aMainFrame = createMainFrame (mainFrame());
656 aDlgLay->addWidget(aMainFrame);
658 aDlgLay->setStretchFactor(aMainFrame, 1);
661 //=======================================================================
662 // function : createMainFrame()
663 // purpose : Create frame containing dialog's fields
664 //=======================================================================
666 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
668 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
670 QFrame* aFrame = new QFrame(theParent);
672 SUIT_ResourceMgr* rm = resourceMgr();
673 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
677 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
678 aPixGrp->setExclusive(TRUE);
679 QRadioButton* aRBut = new QRadioButton(aPixGrp);
680 aRBut->setPixmap(iconCompute);
681 aRBut->setChecked(TRUE);
685 QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
686 myMeshName = new QLabel(nameBox);
690 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
691 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
695 myErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "errorGrBox");
696 myTable = new QTable( 1, NB_COLUMNS, myErrorGroup, "myTable");
697 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myErrorGroup, "myShowBtn");
698 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myErrorGroup, "myPublishBtn");
700 myTable->setReadOnly( TRUE );
701 myTable->hideColumn( COL_PUBLISHED );
702 myTable->hideColumn( COL_SHAPEID );
703 myTable->setColumnStretchable( COL_ERROR, 1 );
704 for ( int col = 0; col < NB_COLUMNS; ++col ) {
707 CASE2HEADER( COL_ALGO );
708 CASE2HEADER( COL_SHAPE );
709 CASE2HEADER( COL_ERROR );
710 CASE2HEADER( COL_SHAPEID );
711 CASE2HEADER( COL_PUBLISHED);
713 myTable->horizontalHeader()->setLabel( col, header );
716 myErrorGroup->setColumnLayout(0, Qt::Vertical);
717 myErrorGroup->layout()->setSpacing(0);
718 myErrorGroup->layout()->setMargin(0);
719 QGridLayout* grpLayout = new QGridLayout(myErrorGroup->layout());
720 grpLayout->setAlignment(Qt::AlignTop);
721 grpLayout->setSpacing(SPACING);
722 grpLayout->setMargin(MARGIN);
723 grpLayout->addMultiCellWidget( myTable, 0, 2, 0, 0 );
724 grpLayout->addWidget ( myShowBtn, 0, 1 );
725 grpLayout->addWidget ( myPublishBtn, 1, 1 );
726 grpLayout->setRowStretch( 2, 1 );
730 myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
731 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
732 QFont bold = memLackLabel->font(); bold.setBold(true);
733 memLackLabel->setFont( bold );
734 memLackLabel->setMinimumWidth(300);
736 // add all widgets to aFrame
737 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
738 aLay->addWidget( aPixGrp );
739 aLay->addWidget( nameBox );
740 aLay->addWidget( myBriefInfo );
741 aLay->addWidget( myFullInfo );
742 aLay->addWidget( myErrorGroup );
743 aLay->addWidget( myMemoryLackGroup );
744 aLay->setStretchFactor( myErrorGroup, 1 );
749 //================================================================================
753 //================================================================================
755 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
757 myDlg = new SMESHGUI_ComputeDlg;
758 myTShapeDisplayer = new TShapeDisplayer();
759 myHelpFileName = "/files/about_meshes.htm";
761 // connect signals and slots
762 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
763 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
764 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
767 //=======================================================================
768 // function : startOperation()
769 // purpose : Init dialog fields, connect signals and slots, show dialog
770 //=======================================================================
772 void SMESHGUI_ComputeOp::startOperation()
774 SMESHGUI_Operation::startOperation();
776 SMESH::SMESH_Mesh_var aMesh;
777 SMESH::compute_error_array_var anErrors;
779 myMainShape = GEOM::GEOM_Object::_nil();
783 bool computeFailed = true, memoryLack = false;
784 int nbNodes = 0, nbEdges = 0, nbFaces = 0, nbVolums = 0;
786 LightApp_SelectionMgr *Sel = selectionMgr();
787 SALOME_ListIO selected; Sel->selectedObjects( selected );
789 int nbSel = selected.Extent();
791 SUIT_MessageBox::warn1(desktop(),
792 tr("SMESH_WRN_WARNING"),
793 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
799 Handle(SALOME_InteractiveObject) IObject = selected.First();
800 aMesh = SMESH::GetMeshByIO(IObject);
801 if (!aMesh->_is_nil())
803 MemoryReserve aMemoryReserve;
804 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
805 myMainShape = aMesh->GetShapeToMesh();
806 if ( !myMainShape->_is_nil() && aMeshSObj )
808 myDlg->myMeshName->setText( aMeshSObj->GetName() );
809 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
810 SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
811 if ( errors->length() > 0 ) {
812 SUIT_MessageBox::warn1(desktop(), tr("SMESH_WRN_WARNING"),
813 SMESH::GetMessageOnAlgoStateErrors( errors.in() ),
818 SUIT_OverrideCursor aWaitCursor;
820 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
823 if (gen->Compute(aMesh, myMainShape))
824 computeFailed = false;
826 catch(const SALOME::SALOME_Exception & S_ex){
828 //SalomeApp_Tools::QtCatchCorbaException(S_ex);
831 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
834 anErrors = gen->GetComputeErrors( aMesh, myMainShape );
835 // if ( anErrors->length() == 0 ) {
836 // SUIT_MessageBox::warn1(desktop(),
837 // tr("SMESH_WRN_WARNING"),
838 // tr("SMESH_WRN_COMPUTE_FAILED"),
839 // tr("SMESH_BUT_OK"));
843 // check if there are memory problems
844 for ( int i = 0; i < anErrors->length() && !memoryLack; ++i )
845 memoryLack = ( anErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
847 catch(const SALOME::SALOME_Exception & S_ex){
851 // NPAL16631: if ( !memoryLack )
853 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
854 update( UF_ObjBrowser | UF_Model );
855 Sel->setSelectedObjects( selected );
858 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
859 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
862 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
865 SMESH::UpdateView(eDisplay, IObject->getEntry());
869 cout << "Exception thrown during mesh visualization" << endl;
871 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
872 SMESH::OnVisuException();
883 SUIT_MessageBox::warn1(desktop(),
884 tr("SMESH_WRN_WARNING"),
885 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
890 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
891 myDlg->myMemoryLackGroup->hide();
895 bool noError = ( !anErrors.operator->() || anErrors->length() == 0 );
899 myDlg->myMemoryLackGroup->show();
900 myDlg->myFullInfo->hide();
901 myDlg->myBriefInfo->hide();
902 myDlg->myErrorGroup->hide();
906 SUIT_OverrideCursor aWaitCursor;
907 myDlg->myFullInfo->SetInfoByMesh( aMesh );
908 myDlg->myFullInfo->show();
909 myDlg->myBriefInfo->hide();
910 myDlg->myErrorGroup->hide();
914 QTable* tbl = myDlg->myTable;
915 myDlg->myBriefInfo->SetInfoByMesh( aMesh );
916 myDlg->myBriefInfo->show();
917 myDlg->myFullInfo->hide();
918 myDlg->myErrorGroup->show();
920 // fill table of errors
921 tbl->setNumRows( anErrors->length() );
922 bool hasShape = aMesh->HasShapeToMesh();
923 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
924 else tbl->showColumn( COL_SHAPE );
925 tbl->setColumnWidth( COL_ERROR, 200 );
927 for ( int row = 0; row < anErrors->length(); ++row )
929 SMESH::ComputeError & err = anErrors[ row ];
930 tbl->setText( row, COL_ALGO, err.algoName.in() );
931 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
932 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
934 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
935 tbl->setText( row, COL_SHAPE, text );
937 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
938 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
940 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
941 tbl->adjustRow( row );
943 tbl->adjustColumn( COL_ALGO );
944 tbl->adjustColumn( COL_SHAPE );
946 tbl->setCurrentCell(0,0);
947 currentCellChanged(); // to update buttons
952 //================================================================================
954 * \brief Stops operation
956 //================================================================================
958 void SMESHGUI_ComputeOp::stopOperation()
960 SMESHGUI_Operation::stopOperation();
961 myTShapeDisplayer->SetVisibility( false );
964 //================================================================================
966 * \brief publish selected subshape
968 //================================================================================
970 void SMESHGUI_ComputeOp::onPublishShape()
972 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
973 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
976 list< int >::iterator row;
977 getSelectedRows( table(), rows );
978 for ( row = rows.begin(); row != rows.end(); ++row )
980 int curSub = table()->text(*row, COL_SHAPEID).toInt();
981 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
982 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
984 if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
986 QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
987 SALOMEDS::SObject_var so =
988 geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
989 // look for myMainShape in the table
990 for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
991 if ( table()->text(r, COL_SHAPEID) == "1" ) {
992 if ( so->_is_nil() ) {
993 table()->setText( r, COL_SHAPE, so->GetName() );
994 table()->setText( r, COL_PUBLISHED, so->GetID() );
999 if ( curSub == 1 ) continue;
1001 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
1002 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
1003 if ( !so->_is_nil() ) {
1004 table()->setText( *row, COL_SHAPE, so->GetName() );
1005 table()->setText( *row, COL_PUBLISHED, so->GetID() );
1009 getSMESHGUI()->getApp()->updateObjectBrowser();
1010 currentCellChanged(); // to update buttons
1013 //================================================================================
1015 * \brief SLOT called when a selected cell in table() changed
1017 //================================================================================
1019 void SMESHGUI_ComputeOp::currentCellChanged()
1021 myTShapeDisplayer->SetVisibility( false );
1023 bool publishEnable = 0, showEnable = 0, showOnly = 1;
1025 list< int >::iterator row;
1026 getSelectedRows( table(), rows );
1027 for ( row = rows.begin(); row != rows.end(); ++row )
1029 bool hasData = ( !table()->text(*row, COL_SHAPE).isEmpty() );
1030 bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
1031 if ( hasData && !isPublished )
1032 publishEnable = true;
1034 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1035 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1037 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1044 myDlg->myPublishBtn->setEnabled( publishEnable );
1045 myDlg->myShowBtn->setEnabled( showEnable );
1048 //================================================================================
1050 * \brief update preview
1052 //================================================================================
1054 void SMESHGUI_ComputeOp::onPreviewShape()
1056 if ( myTShapeDisplayer )
1058 SUIT_OverrideCursor aWaitCursor;
1060 list< int >::iterator row;
1061 getSelectedRows( table(), rows );
1063 bool showOnly = true;
1064 for ( row = rows.begin(); row != rows.end(); ++row )
1066 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1068 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1072 currentCellChanged(); // to update buttons
1076 //================================================================================
1080 //================================================================================
1082 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1084 if ( myTShapeDisplayer ) delete myTShapeDisplayer;
1087 //================================================================================
1089 * \brief Gets dialog of this operation
1090 * \retval LightApp_Dialog* - pointer to dialog of this operation
1092 //================================================================================
1094 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1099 //================================================================================
1101 * \brief perform it's intention action: compute mesh
1103 //================================================================================
1105 bool SMESHGUI_ComputeOp::onApply()
1110 //================================================================================
1112 * \brief Return a table
1114 //================================================================================
1116 QTable* SMESHGUI_ComputeOp::table()
1118 return myDlg->myTable;