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>
81 #include <vtkProperty.h>
84 #include <SALOMEconfig.h>
85 #include CORBA_SERVER_HEADER(SMESH_Gen)
86 #include CORBA_SERVER_HEADER(SMESH_Mesh)
95 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
97 #define _SEPARATOR(father) \
99 /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
100 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
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);\
106 enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, NB_COLUMNS };
108 using namespace SMESH;
112 // =========================================================================================
114 * \brief Class showing shapes without publishing
116 // =========================================================================================
118 class TShapeDisplayer
121 // -----------------------------------------------------------------------
122 TShapeDisplayer(): myViewWindow(0)
124 myProperty = vtkProperty::New();
125 myProperty->SetRepresentationToWireframe();
126 myProperty->SetColor( 250, 0, 250 );
127 myProperty->SetAmbientColor( 250, 0, 250 );
128 myProperty->SetDiffuseColor( 250, 0, 250 );
129 //myProperty->SetSpecularColor( 250, 0, 250 );
130 myProperty->SetLineWidth( 5 );
132 // -----------------------------------------------------------------------
136 myProperty->Delete();
138 // -----------------------------------------------------------------------
141 if ( hasViewWindow() ) {
142 TActorIterator actorIt = actorIterator();
143 while ( actorIt.more() )
144 if (VTKViewer_Actor* anActor = actorIt.next()) {
145 myViewWindow->RemoveActor( anActor );
149 myIndexToShape.Clear();
151 myShownActors.clear();
154 // -----------------------------------------------------------------------
155 void SetVisibility (bool theVisibility)
157 TActorIterator actorIt = shownIterator();
158 while ( actorIt.more() )
159 if (VTKViewer_Actor* anActor = actorIt.next())
160 anActor->SetVisibility(theVisibility);
161 SMESH::RepaintCurrentView();
163 // -----------------------------------------------------------------------
164 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
167 if ( !aMainShape->_is_nil() )
168 mainEntry = aMainShape->GetStudyEntry();
169 return ( myMainEntry == mainEntry &&
170 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
172 // -----------------------------------------------------------------------
173 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
175 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
177 if ( !aMainShape->_is_nil() )
178 mainEntry = aMainShape->GetStudyEntry();
179 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
182 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
183 checkTriangulation( aShape );
184 TopExp::MapShapes(aShape, myIndexToShape);
185 myActors.resize( myIndexToShape.Extent(), 0 );
186 myShownActors.reserve( myIndexToShape.Extent() );
188 myMainEntry = mainEntry;
189 myViewWindow = aViewWindow;
191 if ( only ) { // hide shown actors
192 TActorIterator actorIt = shownIterator();
193 while ( actorIt.more() )
194 if (VTKViewer_Actor* anActor = actorIt.next())
195 anActor->SetVisibility(false);
196 myShownActors.clear();
198 // find actors to show
199 TopoDS_Shape aShape = myIndexToShape( subShapeID );
200 if ( !aShape.IsNull() ) {
201 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
202 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
203 //checkTriangulation( exp.Current() );
204 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
205 myShownActors.push_back( anActor );
207 if ( type == TopAbs_FACE ) {
208 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
209 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
210 if ( !BRep_Tool::Degenerated( edge ))
211 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
212 myShownActors.push_back( anActor );
216 myBuiltSubs.insert( subShapeID );
219 // -----------------------------------------------------------------------
223 typedef std::vector<GEOM_Actor*> TActorVec;
225 TActorVec myShownActors;
226 TopTools_IndexedMapOfShape myIndexToShape;
228 SVTK_ViewWindow* myViewWindow;
229 vtkProperty* myProperty;
230 std::set<int> myBuiltSubs;
232 // -----------------------------------------------------------------------
233 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
234 TActorIterator actorIterator() {
235 return TActorIterator( myActors.begin(), myActors.end() );
237 TActorIterator shownIterator() {
238 return TActorIterator( myShownActors.begin(), myShownActors.end() );
240 // -----------------------------------------------------------------------
241 GEOM_Actor* getActor(const TopoDS_Shape& shape)
243 int index = myIndexToShape.FindIndex( shape ) - 1;
244 if ( index < 0 || index >= myActors.size() )
246 GEOM_Actor* & actor = myActors[ index ];
248 actor = GEOM_Actor::New();
250 actor->setInputShape(shape,0,0);
251 //actor->SetProperty(myProperty);
252 actor->SetShadingProperty(myProperty);
253 actor->SetWireframeProperty(myProperty);
254 actor->SetPreviewProperty(myProperty);
255 actor->PickableOff();
256 // if ( shape.ShapeType() == TopAbs_EDGE )
257 // actor->SubShapeOn();
258 myViewWindow->AddActor( actor );
263 // -----------------------------------------------------------------------
264 void checkTriangulation(const TopoDS_Shape& shape)
266 TopLoc_Location aLoc;
267 Standard_Boolean alreadymesh = Standard_True;
268 TopExp_Explorer ex(shape, TopAbs_FACE);
270 for (; ex.More(); ex.Next()) {
271 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
272 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
273 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
276 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
277 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
278 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
279 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
281 if (alreadymesh) return;
282 // Compute default deflection
284 BRepBndLib::Add(shape, B);
285 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
286 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
287 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
288 BRepMesh_IncrementalMesh MESH(shape,deflection);
290 // -----------------------------------------------------------------------
291 bool hasViewWindow() const
293 if ( !myViewWindow ) return false;
295 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
296 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
302 // =========================================================================================
304 * \brief Return text describing an error
306 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
307 QString errorText(int errCode, const char* comment)
311 CASE2TEXT( COMPERR_OK );
312 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
313 CASE2TEXT( COMPERR_STD_EXCEPTION );
314 CASE2TEXT( COMPERR_OCC_EXCEPTION );
315 CASE2TEXT( COMPERR_SLM_EXCEPTION );
316 CASE2TEXT( COMPERR_EXCEPTION );
317 CASE2TEXT( COMPERR_MEMORY_PB );
318 CASE2TEXT( COMPERR_BAD_SHAPE );
319 case SMESH::COMPERR_ALGO_FAILED:
320 if ( strlen(comment) == 0 )
321 text = QObject::tr("COMPERR_ALGO_FAILED");
324 text = QString("#%1").arg( -errCode );
326 if ( text.length() > 0 ) text += ". ";
327 return text + comment;
329 // -----------------------------------------------------------------------
331 * \brief Return SO of a subshape
333 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
335 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
336 if ( subShapeID == 1 || !so )
338 _PTR(ChildIterator) it;
339 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
340 it = study->NewChildIterator(so);
343 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
344 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
345 if ( !geom->_is_nil() ) {
346 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
347 if ( list->length() == 1 && list[0] == subShapeID )
354 // -----------------------------------------------------------------------
356 * \brief Return subshape by ID
358 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
360 GEOM::GEOM_Object_var aSubShape;
361 if ( subShapeID == 1 )
362 aSubShape = aMainShape;
363 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
364 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
366 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
367 return aSubShape._retn();
369 // -----------------------------------------------------------------------
371 * \brief Return shape type name
373 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
374 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
377 if ( !aShape->_is_nil() ) {
378 switch ( aShape->GetShapeType() ) {
385 CASE2NAME( COMPSOLID );
386 CASE2NAME( COMPOUND );
392 // -----------------------------------------------------------------------
394 * \brief Return text describing a subshape
396 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
399 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
400 text = aSO->GetName();
402 text = QString("#%1").arg( subShapeID );
403 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
404 if ( typeName.length() )
405 text += QString(" (%1)").arg(typeName);
409 // -----------------------------------------------------------------------
411 * \brief Return text describing a subshape
413 bool getSelectedRows(QTable* table, list< int > & rows)
416 int nbSel = table->numSelections();
417 for ( int i = 0; i < nbSel; ++i )
419 QTableSelection selected = table->selection(i);
420 if ( !selected.isActive() ) continue;
421 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
422 rows.push_back( row );
424 return !rows.empty();
430 // =========================================================================================
432 * \brief Box showing mesh info
434 // =========================================================================================
436 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
437 :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
440 QLabel* lab1 = new QLabel(this);
441 QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
442 QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
443 QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
445 QFont italic = lab1->font(); italic.setItalic(true);
446 QFont bold = lab1->font(); bold.setBold(true);
448 lab1->setMinimumWidth(100); lab1->setFont( italic );
449 lab2->setMinimumWidth(100); lab2->setFont( italic );
450 lab3->setMinimumWidth(100); lab3->setFont( italic );
451 lab4->setMinimumWidth(100); lab4->setFont( italic );
456 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
457 myNbNode = new QLabel( this );
464 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
465 myNbEdge = new QLabel( this );
466 myNbLinEdge = new QLabel( this );
467 myNbQuadEdge = new QLabel( this );
472 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
473 myNbFace = new QLabel( this );
474 myNbLinFace = new QLabel( this );
475 myNbQuadFace = new QLabel( this );
477 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
478 myNbTrai = new QLabel( this );
479 myNbLinTrai = new QLabel( this );
480 myNbQuadTrai = new QLabel( this );
482 new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
483 myNbQuad = new QLabel( this );
484 myNbLinQuad = new QLabel( this );
485 myNbQuadQuad = new QLabel( this );
487 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
488 myNbPolyg = new QLabel( this );
489 new QLabel("",this );
490 new QLabel("", this );
495 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
496 myNbVolum = new QLabel( this );
497 myNbLinVolum = new QLabel( this );
498 myNbQuadVolum = new QLabel( this );
500 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
501 myNbTetra = new QLabel( this );
502 myNbLinTetra = new QLabel( this );
503 myNbQuadTetra = new QLabel( this );
505 new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
506 myNbHexa = new QLabel( this );
507 myNbLinHexa = new QLabel( this );
508 myNbQuadHexa = new QLabel( this );
510 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
511 myNbPyra = new QLabel( this );
512 myNbLinPyra = new QLabel( this );
513 myNbQuadPyra = new QLabel( this );
515 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
516 myNbPrism = new QLabel( this );
517 myNbLinPrism = new QLabel( this );
518 myNbQuadPrism = new QLabel( this );
520 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
521 myNbPolyh = new QLabel( this );
522 new QLabel("", this );
523 new QLabel("", this );
528 new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
529 myNbNode = new QLabel( this );
534 new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
535 myNbEdge = new QLabel( this );
536 myNbLinEdge = new QLabel( this );
537 myNbQuadEdge = new QLabel( this );
540 new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
541 myNbFace = new QLabel( this );
542 myNbLinFace = new QLabel( this );
543 myNbQuadFace = new QLabel( this );
546 new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
547 myNbVolum = new QLabel( this );
548 myNbLinVolum = new QLabel( this );
549 myNbQuadVolum = new QLabel( this );
553 // =========================================================================================
555 * \brief Set mesh info
557 // =========================================================================================
559 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
561 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
565 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
568 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
569 myNbEdge ->setText( QString("%1").arg( nbTot ));
570 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
571 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
574 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
575 myNbFace ->setText( QString("%1").arg( nbTot ));
576 myNbLinFace ->setText( QString("%1").arg( nbLin ));
577 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
580 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
581 myNbVolum ->setText( QString("%1").arg( nbTot ));
582 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
583 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
588 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
589 myNbTrai ->setText( QString("%1").arg( nbTot ));
590 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
591 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
593 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
594 myNbQuad ->setText( QString("%1").arg( nbTot ));
595 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
596 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
598 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
601 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
602 myNbTetra ->setText( QString("%1").arg( nbTot ));
603 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
604 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
606 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
607 myNbHexa ->setText( QString("%1").arg( nbTot ));
608 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
609 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
611 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
612 myNbPyra ->setText( QString("%1").arg( nbTot ));
613 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
614 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
616 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
617 myNbPrism ->setText( QString("%1").arg( nbTot ));
618 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
619 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
621 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
625 // =========================================================================================
627 * \brief Dialog to compute a mesh and show computation errors
629 //=======================================================================
631 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, OK/* | Help*/ )
633 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
635 QFrame* aMainFrame = createMainFrame (mainFrame());
637 aDlgLay->addWidget(aMainFrame);
639 aDlgLay->setStretchFactor(aMainFrame, 1);
642 //=======================================================================
643 // function : createMainFrame()
644 // purpose : Create frame containing dialog's fields
645 //=======================================================================
647 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
649 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
651 QFrame* aFrame = new QFrame(theParent);
653 SUIT_ResourceMgr* rm = resourceMgr();
654 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
658 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
659 aPixGrp->setExclusive(TRUE);
660 QRadioButton* aRBut = new QRadioButton(aPixGrp);
661 aRBut->setPixmap(iconCompute);
662 aRBut->setChecked(TRUE);
666 QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
667 myMeshName = new QLabel(nameBox);
671 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
672 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
676 myErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "errorGrBox");
677 myTable = new QTable( 1, NB_COLUMNS, myErrorGroup, "myTable");
678 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myErrorGroup, "myShowBtn");
679 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myErrorGroup, "myPublishBtn");
681 myTable->setReadOnly( TRUE );
682 myTable->hideColumn( COL_PUBLISHED );
683 myTable->hideColumn( COL_SHAPEID );
684 myTable->setColumnStretchable( COL_ERROR, 1 );
685 for ( int col = 0; col < NB_COLUMNS; ++col ) {
688 CASE2HEADER( COL_ALGO );
689 CASE2HEADER( COL_SHAPE );
690 CASE2HEADER( COL_ERROR );
691 CASE2HEADER( COL_SHAPEID );
692 CASE2HEADER( COL_PUBLISHED);
694 myTable->horizontalHeader()->setLabel( col, header );
697 myErrorGroup->setColumnLayout(0, Qt::Vertical);
698 myErrorGroup->layout()->setSpacing(0);
699 myErrorGroup->layout()->setMargin(0);
700 QGridLayout* grpLayout = new QGridLayout(myErrorGroup->layout());
701 grpLayout->setAlignment(Qt::AlignTop);
702 grpLayout->setSpacing(SPACING);
703 grpLayout->setMargin(MARGIN);
704 grpLayout->addMultiCellWidget( myTable, 0, 2, 0, 0 );
705 grpLayout->addWidget ( myShowBtn, 0, 1 );
706 grpLayout->addWidget ( myPublishBtn, 1, 1 );
707 grpLayout->setRowStretch( 2, 1 );
709 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
710 aLay->addWidget( aPixGrp );
711 aLay->addWidget( nameBox );
712 aLay->addWidget( myBriefInfo );
713 aLay->addWidget( myFullInfo );
714 aLay->addWidget( myErrorGroup );
715 aLay->setStretchFactor( myErrorGroup, 1 );
720 //================================================================================
724 //================================================================================
726 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
728 myDlg = new SMESHGUI_ComputeDlg;
729 myTShapeDisplayer = new TShapeDisplayer();
730 myHelpFileName = "/files/about_meshes.htm";
732 // connect signals and slots
733 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
734 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
735 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
738 //=======================================================================
739 // function : startOperation()
740 // purpose : Init dialog fields, connect signals and slots, show dialog
741 //=======================================================================
743 void SMESHGUI_ComputeOp::startOperation()
745 SMESHGUI_Operation::startOperation();
747 SMESH::SMESH_Mesh_var aMesh;
748 SMESH::compute_error_array_var anErrors;
750 myMainShape = GEOM::GEOM_Object::_nil();
754 bool computeFailed = true;
755 int nbNodes = 0, nbEdges = 0, nbFaces = 0, nbVolums = 0;
757 LightApp_SelectionMgr *Sel = selectionMgr();
758 SALOME_ListIO selected; Sel->selectedObjects( selected );
760 int nbSel = selected.Extent();
762 SUIT_MessageBox::warn1(desktop(),
763 tr("SMESH_WRN_WARNING"),
764 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
770 Handle(SALOME_InteractiveObject) IObject = selected.First();
771 aMesh = SMESH::GetMeshByIO(IObject);
772 if (!aMesh->_is_nil()) {
773 myMainShape = aMesh->GetShapeToMesh();
774 if ( !myMainShape->_is_nil() ) {
775 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
776 SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
777 if ( errors->length() > 0 ) {
778 SUIT_MessageBox::warn1(desktop(), tr("SMESH_WRN_WARNING"),
779 SMESH::GetMessageOnAlgoStateErrors( errors.in() ),
785 if (gen->Compute(aMesh, myMainShape)) {
786 computeFailed = false;
789 anErrors = gen->GetComputeErrors( aMesh, myMainShape );
790 // if ( anErrors->length() == 0 ) {
791 // SUIT_MessageBox::warn1(desktop(),
792 // tr("SMESH_WRN_WARNING"),
793 // tr("SMESH_WRN_COMPUTE_FAILED"),
794 // tr("SMESH_BUT_OK"));
799 if ( _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh)) {
800 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
801 myDlg->myMeshName->setText( aMeshSObj->GetName() );
804 catch(const SALOME::SALOME_Exception & S_ex){
805 SalomeApp_Tools::QtCatchCorbaException(S_ex);
807 update( UF_ObjBrowser | UF_Model );
809 if ( getSMESHGUI()->automaticUpdate() ) {
810 SVTK_ViewWindow* aVTKView = SMESH::GetViewWindow(getSMESHGUI(), true);
812 int anId = study()->id();
813 TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, IObject->getEntry());
815 aVisualObj->Update();
816 SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
818 anActor = SMESH::CreateActor(studyDS(), IObject->getEntry());
820 SMESH::DisplayActor(aVTKView, anActor); //apo
824 SMESH::RepaintCurrentView();
825 Sel->setSelectedObjects( selected );
832 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
836 bool noError = ( !anErrors.operator->() || anErrors->length() == 0 );
838 QTable* tbl = myDlg->myTable;
842 //tbl->setNumRows(0);
843 myDlg->myFullInfo->SetInfoByMesh( aMesh );
844 myDlg->myFullInfo->show();
845 myDlg->myBriefInfo->hide();
846 myDlg->myErrorGroup->hide();
850 myDlg->myBriefInfo->SetInfoByMesh( aMesh );
851 myDlg->myBriefInfo->show();
852 myDlg->myFullInfo->hide();
853 myDlg->myErrorGroup->show();
855 // fill table of errors
856 tbl->setNumRows( anErrors->length() );
857 bool hasShape = aMesh->HasShapeToMesh();
858 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
859 else tbl->showColumn( COL_SHAPE );
860 tbl->setColumnWidth( COL_ERROR, 200 );
862 for ( int row = 0; row < anErrors->length(); ++row )
864 SMESH::ComputeError & err = anErrors[ row ];
865 tbl->setText( row, COL_ALGO, err.algoName.in() );
866 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
867 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
869 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
870 tbl->setText( row, COL_SHAPE, text );
872 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
873 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
875 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
876 tbl->adjustRow( row );
878 tbl->adjustColumn( COL_ALGO );
879 tbl->adjustColumn( COL_SHAPE );
881 tbl->setCurrentCell(0,0);
882 currentCellChanged(); // to update buttons
888 //================================================================================
890 * \brief Stops operation
892 //================================================================================
894 void SMESHGUI_ComputeOp::stopOperation()
896 SMESHGUI_Operation::stopOperation();
897 myTShapeDisplayer->SetVisibility( false );
900 //================================================================================
902 * \brief publish selected subshape
904 //================================================================================
906 void SMESHGUI_ComputeOp::onPublishShape()
908 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
909 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
912 list< int >::iterator row;
913 getSelectedRows( table(), rows );
914 for ( row = rows.begin(); row != rows.end(); ++row )
916 int curSub = table()->text(*row, COL_SHAPEID).toInt();
917 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
918 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
920 if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
922 QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
923 SALOMEDS::SObject_var so =
924 geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
925 // look for myMainShape in the table
926 for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
927 if ( table()->text(r, COL_SHAPEID) == "1" ) {
928 if ( so->_is_nil() ) {
929 table()->setText( r, COL_SHAPE, so->GetName() );
930 table()->setText( r, COL_PUBLISHED, so->GetID() );
935 if ( curSub == 1 ) continue;
937 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
938 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
939 if ( !so->_is_nil() ) {
940 table()->setText( *row, COL_SHAPE, so->GetName() );
941 table()->setText( *row, COL_PUBLISHED, so->GetID() );
945 getSMESHGUI()->getApp()->updateObjectBrowser();
946 currentCellChanged(); // to update buttons
949 //================================================================================
951 * \brief SLOT called when a selected cell in table() changed
953 //================================================================================
955 void SMESHGUI_ComputeOp::currentCellChanged()
957 myTShapeDisplayer->SetVisibility( false );
959 bool publishEnable = 0, showEnable = 0, showOnly = 1;
961 list< int >::iterator row;
962 getSelectedRows( table(), rows );
963 for ( row = rows.begin(); row != rows.end(); ++row )
965 bool hasData = ( !table()->text(*row, COL_SHAPE).isEmpty() );
966 bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
967 if ( hasData && !isPublished )
968 publishEnable = true;
970 int curSub = table()->text(*row, COL_SHAPEID).toInt();
971 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
973 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
980 myDlg->myPublishBtn->setEnabled( publishEnable );
981 myDlg->myShowBtn->setEnabled( showEnable );
984 //================================================================================
986 * \brief update preview
988 //================================================================================
990 void SMESHGUI_ComputeOp::onPreviewShape()
992 if ( myTShapeDisplayer )
994 SUIT_OverrideCursor aWaitCursor;
996 list< int >::iterator row;
997 getSelectedRows( table(), rows );
999 bool showOnly = true;
1000 for ( row = rows.begin(); row != rows.end(); ++row )
1002 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1004 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1008 currentCellChanged(); // to update buttons
1012 //================================================================================
1016 //================================================================================
1018 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1020 if ( myTShapeDisplayer ) delete myTShapeDisplayer;
1023 //================================================================================
1025 * \brief Gets dialog of this operation
1026 * \retval LightApp_Dialog* - pointer to dialog of this operation
1028 //================================================================================
1030 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1035 //================================================================================
1037 * \brief perform it's intention action: compute mesh
1039 //================================================================================
1041 bool SMESHGUI_ComputeOp::onApply()
1046 //================================================================================
1048 * \brief Return a table
1050 //================================================================================
1052 QTable* SMESHGUI_ComputeOp::table()
1054 return myDlg->myTable;