1 // Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // File : SMESHGUI_DisplayEntitiesDlg.cxx
20 // Author : Alexander KOVALEV, Open CASCADE S.A.S. (alexander.kovalev@opencascade.com)
22 #include "SMESHGUI_DisplayEntitiesDlg.h"
25 #include "SMESHGUI_Utils.h"
26 #include "SMESHGUI_VTKUtils.h"
27 #include "SMESHGUI_MeshUtils.h"
31 #include <QGridLayout>
32 #include <QVBoxLayout>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <LightApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
40 #include <SALOME_ListIO.hxx>
43 const int SPACING = 6;
46 \class SMESHGUI_DisplayEntitiesDlg
47 \brief Dialog box to select entities to be displayed in viewer
52 \param parent parent widget
54 SMESHGUI_DisplayEntitiesDlg::SMESHGUI_DisplayEntitiesDlg( QWidget* parent )
55 : SMESHGUI_Dialog( parent, true, false, Standard )
57 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
59 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
60 SALOME_ListIO selected;
61 mgr->selectedObjects( selected );
62 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
64 myNbCheckedButtons = 0;
66 SALOME_ListIteratorOfListIO it( selected );
67 myIObject = selected.First();
68 if ( myIObject->hasEntry() ) {
69 myActor = SMESH::FindActorByEntry( myIObject->getEntry() );
71 myEntityMode = myActor ? myActor->GetEntityMode() : 0;
73 aMesh = SMESH::GetMeshByIO( myIObject );
76 setWindowTitle( tr( "MEN_DISP_ENT" ) );
79 QGroupBox* anEntitiesGrp = new QGroupBox( tr( "SMESH_MESHINFO_ENTITIES" ), mainFrame() );
80 QGridLayout* hl = new QGridLayout( anEntitiesGrp );
81 hl->setMargin( MARGIN );
82 hl->setSpacing( SPACING );
86 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) : aMesh->Nb0DElements();
87 my0DElemsTB = new QCheckBox( tr("SMESH_ELEMS0D"), anEntitiesGrp );
88 my0DElemsTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_ELEM0D" ) ) ) );
89 bool has0DElems = myEntityMode & SMESH_Actor::e0DElements;
90 my0DElemsTB->setChecked( has0DElems );
93 connect( my0DElemsTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
94 QLabel* nb0DElemsLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
95 hl->addWidget( my0DElemsTB, 0, 0 );
96 hl->addWidget( nb0DElemsLab, 0, 1 );
97 my0DElemsTB->setEnabled( nbElements );
98 nb0DElemsLab->setEnabled( nbElements );
101 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) : aMesh->NbEdges();
102 myEdgesTB = new QCheckBox( tr("SMESH_EDGES"), anEntitiesGrp );
103 myEdgesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_EDGE" ) ) ) );
104 bool hasEdges = myEntityMode & SMESH_Actor::eEdges;
105 myEdgesTB->setChecked( hasEdges );
107 myNbCheckedButtons++;
108 connect( myEdgesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
109 QLabel* nbEdgesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
110 hl->addWidget( myEdgesTB, 1, 0 );
111 hl->addWidget( nbEdgesLab, 1, 1 );
112 myEdgesTB->setEnabled( nbElements );
113 nbEdgesLab->setEnabled( nbElements );
116 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Face ) : aMesh->NbFaces();
117 myFacesTB = new QCheckBox( tr("SMESH_FACES"), anEntitiesGrp );
118 myFacesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TRIANGLE" ) ) ) );
119 bool hasFaces = myEntityMode & SMESH_Actor::eFaces;
120 myFacesTB->setChecked( hasFaces );
122 myNbCheckedButtons++;
123 connect( myFacesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
124 QLabel* nbFacesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
125 hl->addWidget( myFacesTB, 2, 0 );
126 hl->addWidget( nbFacesLab, 2, 1 );
127 myFacesTB->setEnabled( nbElements );
128 nbFacesLab->setEnabled( nbElements );
131 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) : aMesh->NbVolumes();
132 myVolumesTB = new QCheckBox( tr("SMESH_VOLUMES"), anEntitiesGrp );
133 myVolumesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TETRAS" ) ) ) );
134 bool hasVolumes = myEntityMode & SMESH_Actor::eVolumes;
135 myVolumesTB->setChecked( hasVolumes );
137 myNbCheckedButtons++;
138 connect( myVolumesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool) ) );
139 QLabel* nbVolumesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
140 hl->addWidget( myVolumesTB, 3, 0 );
141 hl->addWidget( nbVolumesLab, 3, 1 );
142 myVolumesTB->setEnabled( nbElements );
143 nbVolumesLab->setEnabled( nbElements );
146 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) : aMesh->NbBalls();
147 myBallsTB = new QCheckBox( tr("SMESH_BALLS"), anEntitiesGrp );
148 myBallsTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_BALL" ) ) ) );
149 bool hasBalls = myEntityMode & SMESH_Actor::eBallElem;
150 myBallsTB->setChecked( hasBalls );
152 myNbCheckedButtons++;
153 connect( myBallsTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
154 QLabel* nbBallsLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
155 hl->addWidget( myBallsTB, 4, 0 );
156 hl->addWidget( nbBallsLab, 4, 1 );
157 myBallsTB->setEnabled( nbElements );
158 nbBallsLab->setEnabled( nbElements );
160 QVBoxLayout* aDlgLay = new QVBoxLayout( mainFrame() );
161 aDlgLay->setMargin( 0 );
162 aDlgLay->setSpacing( SPACING );
163 aDlgLay->addWidget( anEntitiesGrp );
165 button( OK )->setText( tr( "SMESH_BUT_OK" ) );
167 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
168 connect( this, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
172 \brief Destructor: clean-up resources if necessary
174 SMESHGUI_DisplayEntitiesDlg::~SMESHGUI_DisplayEntitiesDlg()
178 void SMESHGUI_DisplayEntitiesDlg::InverseEntityMode(unsigned int& theOutputMode,
179 unsigned int theMode)
181 bool anIsNotPresent = ~theOutputMode & theMode;
183 theOutputMode |= theMode;
185 theOutputMode &= ~theMode;
189 \brief Slot for changing entities state
191 void SMESHGUI_DisplayEntitiesDlg::onChangeEntityMode( bool isChecked )
193 QCheckBox* aSender = (QCheckBox*)sender();
194 if ( myNbCheckedButtons == 1 && !isChecked ) {
195 SUIT_MessageBox::warning(this, tr("SMESH_WRN_WARNING"),
196 tr("WRN_AT_LEAST_ONE"));
197 disconnect( aSender, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
198 aSender->setChecked( true );
199 connect( aSender, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
202 if ( my0DElemsTB == aSender )
203 InverseEntityMode( myEntityMode, SMESH_Actor::e0DElements );
204 else if ( myEdgesTB == aSender )
205 InverseEntityMode( myEntityMode, SMESH_Actor::eEdges );
206 else if ( myFacesTB == aSender )
207 InverseEntityMode( myEntityMode, SMESH_Actor::eFaces );
208 else if ( myVolumesTB == aSender )
209 InverseEntityMode( myEntityMode, SMESH_Actor::eVolumes );
210 else if ( myBallsTB == aSender )
211 InverseEntityMode( myEntityMode, SMESH_Actor::eBallElem );
213 isChecked ? myNbCheckedButtons++ : myNbCheckedButtons--;
218 \brief Show online help on dialog box
220 void SMESHGUI_DisplayEntitiesDlg::onHelp()
222 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
223 app->onHelpContextModule( "SMESH", "display_entity_page.html" );
227 \brief Display or update the mesh in the 3D view with selected entity mode
229 void SMESHGUI_DisplayEntitiesDlg::onOk()
231 const char* entry = myIObject->getEntry();
234 myActor = SMESH::CreateActor(SMESH::GetActiveStudyDocument(),
238 if( myEntityMode != myActor->GetEntityMode() ) {
239 myActor->SetEntityMode(myEntityMode);
240 SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
241 SMESH::DisplayActor( wnd, myActor );
242 SUIT_DataOwnerPtrList aList;
243 aList.append( new LightApp_DataOwner( entry ) );
244 SMESHGUI::selectionMgr()->setSelected( aList, false );
245 SMESH::UpdateView( wnd, SMESH::eDisplay, entry );