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"
40 #include "GEOM_Actor.h"
42 #include "LightApp_SelectionMgr.h"
43 #include "LightApp_UpdateFlags.h"
44 #include "SALOMEDSClient_SObject.hxx"
45 #include "SALOME_ListIO.hxx"
46 #include "SVTK_ViewWindow.h"
47 #include "SVTK_ViewModel.h"
48 #include "SalomeApp_Tools.h"
49 #include "SalomeApp_Application.h"
50 #include "SUIT_ResourceMgr.h"
51 #include "SUIT_OverrideCursor.h"
52 #include "SUIT_MessageBox.h"
53 #include "SUIT_Desktop.h"
54 #include "SUIT_Study.h"
55 #include "OB_Browser.h"
58 #include <BRep_Tool.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <TopLoc_Location.hxx>
65 #include <Poly_Triangulation.hxx>
66 #include <Bnd_Box.hxx>
67 #include <BRepBndLib.hxx>
68 #include <BRepMesh_IncrementalMesh.hxx>
73 #include <qpushbutton.h>
75 #include <qbuttongroup.h>
76 #include <qradiobutton.h>
79 #include <qhgroupbox.h>
80 #include <qvgroupbox.h>
82 #include <vtkProperty.h>
85 #include <SALOMEconfig.h>
86 #include CORBA_SERVER_HEADER(SMESH_Gen)
87 #include CORBA_SERVER_HEADER(SMESH_Mesh)
96 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
98 #define _SEPARATOR(father) \
100 /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
101 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
102 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
103 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
104 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
107 enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, NB_COLUMNS };
109 using namespace SMESH;
113 //=============================================================================
115 * \brief Allocate some memory at construction and release it at destruction.
116 * Is used to be able to continue working after mesh generation or visualization
117 * break due to lack of memory
119 //=============================================================================
124 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
125 ~MemoryReserve() { delete [] myBuf; }
128 // =========================================================================================
130 * \brief Class showing shapes without publishing
132 // =========================================================================================
134 class TShapeDisplayer
137 // -----------------------------------------------------------------------
138 TShapeDisplayer(): myViewWindow(0)
140 myProperty = vtkProperty::New();
141 myProperty->SetRepresentationToWireframe();
142 myProperty->SetColor( 250, 0, 250 );
143 myProperty->SetAmbientColor( 250, 0, 250 );
144 myProperty->SetDiffuseColor( 250, 0, 250 );
145 //myProperty->SetSpecularColor( 250, 0, 250 );
146 myProperty->SetLineWidth( 5 );
148 // -----------------------------------------------------------------------
152 myProperty->Delete();
154 // -----------------------------------------------------------------------
157 if ( hasViewWindow() ) {
158 TActorIterator actorIt = actorIterator();
159 while ( actorIt.more() )
160 if (VTKViewer_Actor* anActor = actorIt.next()) {
161 myViewWindow->RemoveActor( anActor );
165 myIndexToShape.Clear();
167 myShownActors.clear();
170 // -----------------------------------------------------------------------
171 void SetVisibility (bool theVisibility)
173 TActorIterator actorIt = shownIterator();
174 while ( actorIt.more() )
175 if (VTKViewer_Actor* anActor = actorIt.next())
176 anActor->SetVisibility(theVisibility);
177 SMESH::RepaintCurrentView();
179 // -----------------------------------------------------------------------
180 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
183 if ( !aMainShape->_is_nil() )
184 mainEntry = aMainShape->GetStudyEntry();
185 return ( myMainEntry == mainEntry &&
186 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
188 // -----------------------------------------------------------------------
189 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
191 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
193 if ( !aMainShape->_is_nil() )
194 mainEntry = aMainShape->GetStudyEntry();
195 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
198 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
199 checkTriangulation( aShape );
200 TopExp::MapShapes(aShape, myIndexToShape);
201 myActors.resize( myIndexToShape.Extent(), 0 );
202 myShownActors.reserve( myIndexToShape.Extent() );
204 myMainEntry = mainEntry;
205 myViewWindow = aViewWindow;
207 if ( only ) { // hide shown actors
208 TActorIterator actorIt = shownIterator();
209 while ( actorIt.more() )
210 if (VTKViewer_Actor* anActor = actorIt.next())
211 anActor->SetVisibility(false);
212 myShownActors.clear();
214 // find actors to show
215 TopoDS_Shape aShape = myIndexToShape( subShapeID );
216 if ( !aShape.IsNull() ) {
217 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
218 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
219 //checkTriangulation( exp.Current() );
220 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
221 myShownActors.push_back( anActor );
223 if ( type == TopAbs_FACE ) {
224 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
225 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
226 if ( !BRep_Tool::Degenerated( edge ))
227 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
228 myShownActors.push_back( anActor );
232 myBuiltSubs.insert( subShapeID );
235 // -----------------------------------------------------------------------
239 typedef std::vector<GEOM_Actor*> TActorVec;
241 TActorVec myShownActors;
242 TopTools_IndexedMapOfShape myIndexToShape;
244 SVTK_ViewWindow* myViewWindow;
245 vtkProperty* myProperty;
246 std::set<int> myBuiltSubs;
248 // -----------------------------------------------------------------------
249 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
250 TActorIterator actorIterator() {
251 return TActorIterator( myActors.begin(), myActors.end() );
253 TActorIterator shownIterator() {
254 return TActorIterator( myShownActors.begin(), myShownActors.end() );
256 // -----------------------------------------------------------------------
257 GEOM_Actor* getActor(const TopoDS_Shape& shape)
259 int index = myIndexToShape.FindIndex( shape ) - 1;
260 if ( index < 0 || index >= myActors.size() )
262 GEOM_Actor* & actor = myActors[ index ];
264 actor = GEOM_Actor::New();
266 actor->setInputShape(shape,0,0);
267 //actor->SetProperty(myProperty);
268 actor->SetShadingProperty(myProperty);
269 actor->SetWireframeProperty(myProperty);
270 actor->SetPreviewProperty(myProperty);
271 actor->PickableOff();
272 // if ( shape.ShapeType() == TopAbs_EDGE )
273 // actor->SubShapeOn();
274 myViewWindow->AddActor( actor );
279 // -----------------------------------------------------------------------
280 void checkTriangulation(const TopoDS_Shape& shape)
282 TopLoc_Location aLoc;
283 Standard_Boolean alreadymesh = Standard_True;
284 TopExp_Explorer ex(shape, TopAbs_FACE);
286 for (; ex.More(); ex.Next()) {
287 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
288 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
289 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
292 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
293 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
294 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
295 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
297 if (alreadymesh) return;
298 // Compute default deflection
300 BRepBndLib::Add(shape, B);
301 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
302 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
303 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
304 BRepMesh_IncrementalMesh MESH(shape,deflection);
306 // -----------------------------------------------------------------------
307 bool hasViewWindow() const
309 if ( !myViewWindow ) return false;
311 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
312 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
318 // =========================================================================================
320 * \brief Return text describing an error
322 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
323 QString errorText(int errCode, const char* comment)
327 CASE2TEXT( COMPERR_OK );
328 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
329 CASE2TEXT( COMPERR_STD_EXCEPTION );
330 CASE2TEXT( COMPERR_OCC_EXCEPTION );
331 CASE2TEXT( COMPERR_SLM_EXCEPTION );
332 CASE2TEXT( COMPERR_EXCEPTION );
333 CASE2TEXT( COMPERR_MEMORY_PB );
334 CASE2TEXT( COMPERR_BAD_SHAPE );
335 case SMESH::COMPERR_ALGO_FAILED:
336 if ( strlen(comment) == 0 )
337 text = QObject::tr("COMPERR_ALGO_FAILED");
340 text = QString("#%1").arg( -errCode );
342 if ( text.length() > 0 ) text += ". ";
343 return text + comment;
345 // -----------------------------------------------------------------------
347 * \brief Return SO of a subshape
349 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
351 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
352 if ( subShapeID == 1 || !so )
354 _PTR(ChildIterator) it;
355 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
356 it = study->NewChildIterator(so);
359 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
360 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
361 if ( !geom->_is_nil() ) {
362 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
363 if ( list->length() == 1 && list[0] == subShapeID )
370 // -----------------------------------------------------------------------
372 * \brief Return subshape by ID
374 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
376 GEOM::GEOM_Object_var aSubShape;
377 if ( subShapeID == 1 )
378 aSubShape = aMainShape;
379 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
380 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
382 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
383 return aSubShape._retn();
385 // -----------------------------------------------------------------------
387 * \brief Return shape type name
389 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
390 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
393 if ( !aShape->_is_nil() ) {
394 switch ( aShape->GetShapeType() ) {
401 CASE2NAME( COMPSOLID );
402 CASE2NAME( COMPOUND );
408 // -----------------------------------------------------------------------
410 * \brief Return text describing a subshape
412 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
415 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
416 text = aSO->GetName();
418 text = QString("#%1").arg( subShapeID );
419 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
420 if ( typeName.length() )
421 text += QString(" (%1)").arg(typeName);
425 // -----------------------------------------------------------------------
427 * \brief Return text describing a subshape
429 bool getSelectedRows(QTable* table, list< int > & rows)
432 int nbSel = table->numSelections();
433 for ( int i = 0; i < nbSel; ++i )
435 QTableSelection selected = table->selection(i);
436 if ( !selected.isActive() ) continue;
437 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
438 rows.push_back( row );
440 return !rows.empty();
446 // =========================================================================================
448 * \brief Box showing mesh info
450 // =========================================================================================
452 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
453 :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
456 QLabel* lab1 = new QLabel(this);
457 QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
458 QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
459 QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
461 QFont italic = lab1->font(); italic.setItalic(true);
462 QFont bold = lab1->font(); bold.setBold(true);
464 lab1->setMinimumWidth(100); lab1->setFont( italic );
465 lab2->setMinimumWidth(100); lab2->setFont( italic );
466 lab3->setMinimumWidth(100); lab3->setFont( italic );
467 lab4->setMinimumWidth(100); lab4->setFont( italic );
472 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
473 myNbNode = new QLabel( this );
480 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
481 myNbEdge = new QLabel( this );
482 myNbLinEdge = new QLabel( this );
483 myNbQuadEdge = new QLabel( this );
488 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
489 myNbFace = new QLabel( this );
490 myNbLinFace = new QLabel( this );
491 myNbQuadFace = new QLabel( this );
493 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
494 myNbTrai = new QLabel( this );
495 myNbLinTrai = new QLabel( this );
496 myNbQuadTrai = new QLabel( this );
498 new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
499 myNbQuad = new QLabel( this );
500 myNbLinQuad = new QLabel( this );
501 myNbQuadQuad = new QLabel( this );
503 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
504 myNbPolyg = new QLabel( this );
505 new QLabel("",this );
506 new QLabel("", this );
511 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
512 myNbVolum = new QLabel( this );
513 myNbLinVolum = new QLabel( this );
514 myNbQuadVolum = new QLabel( this );
516 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
517 myNbTetra = new QLabel( this );
518 myNbLinTetra = new QLabel( this );
519 myNbQuadTetra = new QLabel( this );
521 new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
522 myNbHexa = new QLabel( this );
523 myNbLinHexa = new QLabel( this );
524 myNbQuadHexa = new QLabel( this );
526 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
527 myNbPyra = new QLabel( this );
528 myNbLinPyra = new QLabel( this );
529 myNbQuadPyra = new QLabel( this );
531 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
532 myNbPrism = new QLabel( this );
533 myNbLinPrism = new QLabel( this );
534 myNbQuadPrism = new QLabel( this );
536 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
537 myNbPolyh = new QLabel( this );
538 new QLabel("", this );
539 new QLabel("", this );
544 new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
545 myNbNode = new QLabel( this );
550 new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
551 myNbEdge = new QLabel( this );
552 myNbLinEdge = new QLabel( this );
553 myNbQuadEdge = new QLabel( this );
556 new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
557 myNbFace = new QLabel( this );
558 myNbLinFace = new QLabel( this );
559 myNbQuadFace = new QLabel( this );
562 new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
563 myNbVolum = new QLabel( this );
564 myNbLinVolum = new QLabel( this );
565 myNbQuadVolum = new QLabel( this );
569 // =========================================================================================
571 * \brief Set mesh info
573 // =========================================================================================
575 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
577 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
581 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
584 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
585 myNbEdge ->setText( QString("%1").arg( nbTot ));
586 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
587 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
590 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
591 myNbFace ->setText( QString("%1").arg( nbTot ));
592 myNbLinFace ->setText( QString("%1").arg( nbLin ));
593 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
596 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
597 myNbVolum ->setText( QString("%1").arg( nbTot ));
598 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
599 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
604 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
605 myNbTrai ->setText( QString("%1").arg( nbTot ));
606 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
607 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
609 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
610 myNbQuad ->setText( QString("%1").arg( nbTot ));
611 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
612 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
614 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
617 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
618 myNbTetra ->setText( QString("%1").arg( nbTot ));
619 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
620 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
622 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
623 myNbHexa ->setText( QString("%1").arg( nbTot ));
624 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
625 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
627 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
628 myNbPyra ->setText( QString("%1").arg( nbTot ));
629 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
630 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
632 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
633 myNbPrism ->setText( QString("%1").arg( nbTot ));
634 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
635 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
637 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
641 // =========================================================================================
643 * \brief Dialog to compute a mesh and show computation errors
645 //=======================================================================
647 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, OK/* | Help*/ )
649 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
651 QFrame* aMainFrame = createMainFrame (mainFrame());
653 aDlgLay->addWidget(aMainFrame);
655 aDlgLay->setStretchFactor(aMainFrame, 1);
658 //=======================================================================
659 // function : createMainFrame()
660 // purpose : Create frame containing dialog's fields
661 //=======================================================================
663 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
665 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
667 QFrame* aFrame = new QFrame(theParent);
669 SUIT_ResourceMgr* rm = resourceMgr();
670 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
674 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
675 aPixGrp->setExclusive(TRUE);
676 QRadioButton* aRBut = new QRadioButton(aPixGrp);
677 aRBut->setPixmap(iconCompute);
678 aRBut->setChecked(TRUE);
682 QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
683 myMeshName = new QLabel(nameBox);
687 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
688 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
692 myErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "errorGrBox");
693 myTable = new QTable( 1, NB_COLUMNS, myErrorGroup, "myTable");
694 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myErrorGroup, "myShowBtn");
695 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myErrorGroup, "myPublishBtn");
697 myTable->setReadOnly( TRUE );
698 myTable->hideColumn( COL_PUBLISHED );
699 myTable->hideColumn( COL_SHAPEID );
700 myTable->setColumnStretchable( COL_ERROR, 1 );
701 for ( int col = 0; col < NB_COLUMNS; ++col ) {
704 CASE2HEADER( COL_ALGO );
705 CASE2HEADER( COL_SHAPE );
706 CASE2HEADER( COL_ERROR );
707 CASE2HEADER( COL_SHAPEID );
708 CASE2HEADER( COL_PUBLISHED);
710 myTable->horizontalHeader()->setLabel( col, header );
713 myErrorGroup->setColumnLayout(0, Qt::Vertical);
714 myErrorGroup->layout()->setSpacing(0);
715 myErrorGroup->layout()->setMargin(0);
716 QGridLayout* grpLayout = new QGridLayout(myErrorGroup->layout());
717 grpLayout->setAlignment(Qt::AlignTop);
718 grpLayout->setSpacing(SPACING);
719 grpLayout->setMargin(MARGIN);
720 grpLayout->addMultiCellWidget( myTable, 0, 2, 0, 0 );
721 grpLayout->addWidget ( myShowBtn, 0, 1 );
722 grpLayout->addWidget ( myPublishBtn, 1, 1 );
723 grpLayout->setRowStretch( 2, 1 );
727 myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
728 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
729 QFont bold = memLackLabel->font(); bold.setBold(true);
730 memLackLabel->setFont( bold );
731 memLackLabel->setMinimumWidth(300);
733 // add all widgets to aFrame
734 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
735 aLay->addWidget( aPixGrp );
736 aLay->addWidget( nameBox );
737 aLay->addWidget( myBriefInfo );
738 aLay->addWidget( myFullInfo );
739 aLay->addWidget( myErrorGroup );
740 aLay->addWidget( myMemoryLackGroup );
741 aLay->setStretchFactor( myErrorGroup, 1 );
746 //================================================================================
750 //================================================================================
752 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
754 myDlg = new SMESHGUI_ComputeDlg;
755 myTShapeDisplayer = new TShapeDisplayer();
756 myHelpFileName = "/files/about_meshes.htm";
758 // connect signals and slots
759 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
760 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
761 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
764 //=======================================================================
765 // function : startOperation()
766 // purpose : Init dialog fields, connect signals and slots, show dialog
767 //=======================================================================
769 void SMESHGUI_ComputeOp::startOperation()
771 SMESHGUI_Operation::startOperation();
773 SMESH::SMESH_Mesh_var aMesh;
774 SMESH::compute_error_array_var anErrors;
776 myMainShape = GEOM::GEOM_Object::_nil();
780 bool computeFailed = true, memoryLack = false;
781 int nbNodes = 0, nbEdges = 0, nbFaces = 0, nbVolums = 0;
783 LightApp_SelectionMgr *Sel = selectionMgr();
784 SALOME_ListIO selected; Sel->selectedObjects( selected );
786 int nbSel = selected.Extent();
788 SUIT_MessageBox::warn1(desktop(),
789 tr("SMESH_WRN_WARNING"),
790 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
796 Handle(SALOME_InteractiveObject) IObject = selected.First();
797 aMesh = SMESH::GetMeshByIO(IObject);
798 if (!aMesh->_is_nil())
800 MemoryReserve aMemoryReserve;
801 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
802 myMainShape = aMesh->GetShapeToMesh();
803 if ( !myMainShape->_is_nil() && aMeshSObj )
805 myDlg->myMeshName->setText( aMeshSObj->GetName() );
806 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
807 SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
808 if ( errors->length() > 0 ) {
809 SUIT_MessageBox::warn1(desktop(), tr("SMESH_WRN_WARNING"),
810 SMESH::GetMessageOnAlgoStateErrors( errors.in() ),
815 SUIT_OverrideCursor aWaitCursor;
817 if (gen->Compute(aMesh, myMainShape))
818 computeFailed = false;
820 catch(const SALOME::SALOME_Exception & S_ex){
822 //SalomeApp_Tools::QtCatchCorbaException(S_ex);
825 anErrors = gen->GetComputeErrors( aMesh, myMainShape );
826 // if ( anErrors->length() == 0 ) {
827 // SUIT_MessageBox::warn1(desktop(),
828 // tr("SMESH_WRN_WARNING"),
829 // tr("SMESH_WRN_COMPUTE_FAILED"),
830 // tr("SMESH_BUT_OK"));
834 // check if there are memory problems
835 for ( int i = 0; i < anErrors->length() && !memoryLack; ++i )
836 memoryLack = ( anErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
838 catch(const SALOME::SALOME_Exception & S_ex){
844 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
845 update( UF_ObjBrowser | UF_Model );
849 if ( getSMESHGUI()->automaticUpdate() ) {
850 SVTK_ViewWindow* aVTKView = SMESH::GetViewWindow(getSMESHGUI(), true);
852 int anId = study()->id();
853 TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, IObject->getEntry());
855 aVisualObj->Update();
856 SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
858 anActor = SMESH::CreateActor(studyDS(), IObject->getEntry());
860 SMESH::DisplayActor(aVTKView, anActor); //apo
864 SMESH::RepaintCurrentView();
865 Sel->setSelectedObjects( selected );
877 SUIT_MessageBox::warn1(desktop(),
878 tr("SMESH_WRN_WARNING"),
879 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
884 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
885 myDlg->myMemoryLackGroup->hide();
889 bool noError = ( !anErrors.operator->() || anErrors->length() == 0 );
893 myDlg->myMemoryLackGroup->show();
894 myDlg->myFullInfo->hide();
895 myDlg->myBriefInfo->hide();
896 myDlg->myErrorGroup->hide();
900 myDlg->myFullInfo->SetInfoByMesh( aMesh );
901 myDlg->myFullInfo->show();
902 myDlg->myBriefInfo->hide();
903 myDlg->myErrorGroup->hide();
907 QTable* tbl = myDlg->myTable;
908 myDlg->myBriefInfo->SetInfoByMesh( aMesh );
909 myDlg->myBriefInfo->show();
910 myDlg->myFullInfo->hide();
911 myDlg->myErrorGroup->show();
913 // fill table of errors
914 tbl->setNumRows( anErrors->length() );
915 bool hasShape = aMesh->HasShapeToMesh();
916 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
917 else tbl->showColumn( COL_SHAPE );
918 tbl->setColumnWidth( COL_ERROR, 200 );
920 for ( int row = 0; row < anErrors->length(); ++row )
922 SMESH::ComputeError & err = anErrors[ row ];
923 tbl->setText( row, COL_ALGO, err.algoName.in() );
924 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
925 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
927 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
928 tbl->setText( row, COL_SHAPE, text );
930 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
931 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
933 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
934 tbl->adjustRow( row );
936 tbl->adjustColumn( COL_ALGO );
937 tbl->adjustColumn( COL_SHAPE );
939 tbl->setCurrentCell(0,0);
940 currentCellChanged(); // to update buttons
945 //================================================================================
947 * \brief Stops operation
949 //================================================================================
951 void SMESHGUI_ComputeOp::stopOperation()
953 SMESHGUI_Operation::stopOperation();
954 myTShapeDisplayer->SetVisibility( false );
957 //================================================================================
959 * \brief publish selected subshape
961 //================================================================================
963 void SMESHGUI_ComputeOp::onPublishShape()
965 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
966 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
969 list< int >::iterator row;
970 getSelectedRows( table(), rows );
971 for ( row = rows.begin(); row != rows.end(); ++row )
973 int curSub = table()->text(*row, COL_SHAPEID).toInt();
974 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
975 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
977 if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
979 QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
980 SALOMEDS::SObject_var so =
981 geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
982 // look for myMainShape in the table
983 for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
984 if ( table()->text(r, COL_SHAPEID) == "1" ) {
985 if ( so->_is_nil() ) {
986 table()->setText( r, COL_SHAPE, so->GetName() );
987 table()->setText( r, COL_PUBLISHED, so->GetID() );
992 if ( curSub == 1 ) continue;
994 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
995 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
996 if ( !so->_is_nil() ) {
997 table()->setText( *row, COL_SHAPE, so->GetName() );
998 table()->setText( *row, COL_PUBLISHED, so->GetID() );
1002 getSMESHGUI()->getApp()->updateObjectBrowser();
1003 currentCellChanged(); // to update buttons
1006 //================================================================================
1008 * \brief SLOT called when a selected cell in table() changed
1010 //================================================================================
1012 void SMESHGUI_ComputeOp::currentCellChanged()
1014 myTShapeDisplayer->SetVisibility( false );
1016 bool publishEnable = 0, showEnable = 0, showOnly = 1;
1018 list< int >::iterator row;
1019 getSelectedRows( table(), rows );
1020 for ( row = rows.begin(); row != rows.end(); ++row )
1022 bool hasData = ( !table()->text(*row, COL_SHAPE).isEmpty() );
1023 bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
1024 if ( hasData && !isPublished )
1025 publishEnable = true;
1027 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1028 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1030 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1037 myDlg->myPublishBtn->setEnabled( publishEnable );
1038 myDlg->myShowBtn->setEnabled( showEnable );
1041 //================================================================================
1043 * \brief update preview
1045 //================================================================================
1047 void SMESHGUI_ComputeOp::onPreviewShape()
1049 if ( myTShapeDisplayer )
1051 SUIT_OverrideCursor aWaitCursor;
1053 list< int >::iterator row;
1054 getSelectedRows( table(), rows );
1056 bool showOnly = true;
1057 for ( row = rows.begin(); row != rows.end(); ++row )
1059 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1061 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1065 currentCellChanged(); // to update buttons
1069 //================================================================================
1073 //================================================================================
1075 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1077 if ( myTShapeDisplayer ) delete myTShapeDisplayer;
1080 //================================================================================
1082 * \brief Gets dialog of this operation
1083 * \retval LightApp_Dialog* - pointer to dialog of this operation
1085 //================================================================================
1087 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1092 //================================================================================
1094 * \brief perform it's intention action: compute mesh
1096 //================================================================================
1098 bool SMESHGUI_ComputeOp::onApply()
1103 //================================================================================
1105 * \brief Return a table
1107 //================================================================================
1109 QTable* SMESHGUI_ComputeOp::table()
1111 return myDlg->myTable;