1 // Copyright (C) 2014-2015 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_MeshUtils.h"
26 #include "SMESHGUI_Utils.h"
27 #include "SMESHGUI_VTKUtils.h"
29 #include <LightApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SALOME_ListIO.hxx>
32 #include <SUIT_MessageBox.h>
33 #include <SUIT_OverrideCursor.h>
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_Session.h>
38 #include <QGridLayout>
41 #include <QVBoxLayout>
44 const int SPACING = 6;
47 \class SMESHGUI_DisplayEntitiesDlg
48 \brief Dialog box to select entities to be displayed in viewer
53 \param parent parent widget
55 SMESHGUI_DisplayEntitiesDlg::SMESHGUI_DisplayEntitiesDlg( QWidget* parent )
56 : SMESHGUI_Dialog( parent, true, false, Standard )
58 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
60 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
61 SALOME_ListIO selected;
62 mgr->selectedObjects( selected );
63 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
65 myNbCheckedButtons = 0;
67 SALOME_ListIteratorOfListIO it( selected );
68 myIObject = selected.First();
69 if ( myIObject->hasEntry() ) {
70 myActor = SMESH::FindActorByEntry( myIObject->getEntry() );
72 myEntityMode = myActor ? myActor->GetEntityMode() : 0;
74 aMesh = SMESH::GetMeshByIO( myIObject );
77 setWindowTitle( tr( "MEN_DISP_ENT" ) );
80 QGroupBox* anEntitiesGrp = new QGroupBox( tr( "SMESH_MESHINFO_ENTITIES" ), mainFrame() );
81 QGridLayout* hl = new QGridLayout( anEntitiesGrp );
82 hl->setMargin( MARGIN );
83 hl->setSpacing( SPACING );
87 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) : aMesh->Nb0DElements();
88 my0DElemsTB = new QCheckBox( tr("SMESH_ELEMS0D"), anEntitiesGrp );
89 my0DElemsTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_ELEM0D" ) ) ) );
90 bool has0DElems = myEntityMode & SMESH_Actor::e0DElements;
91 my0DElemsTB->setChecked( has0DElems );
94 connect( my0DElemsTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
95 QLabel* nb0DElemsLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
96 hl->addWidget( my0DElemsTB, 0, 0 );
97 hl->addWidget( nb0DElemsLab, 0, 1 );
98 my0DElemsTB->setEnabled( nbElements );
99 nb0DElemsLab->setEnabled( nbElements );
102 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) : aMesh->NbEdges();
103 myEdgesTB = new QCheckBox( tr("SMESH_EDGES"), anEntitiesGrp );
104 myEdgesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_EDGE" ) ) ) );
105 bool hasEdges = myEntityMode & SMESH_Actor::eEdges;
106 myEdgesTB->setChecked( hasEdges );
108 myNbCheckedButtons++;
109 connect( myEdgesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
110 QLabel* nbEdgesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
111 hl->addWidget( myEdgesTB, 1, 0 );
112 hl->addWidget( nbEdgesLab, 1, 1 );
113 myEdgesTB->setEnabled( nbElements );
114 nbEdgesLab->setEnabled( nbElements );
117 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Face ) : aMesh->NbFaces();
118 myFacesTB = new QCheckBox( tr("SMESH_FACES"), anEntitiesGrp );
119 myFacesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TRIANGLE" ) ) ) );
120 bool hasFaces = myEntityMode & SMESH_Actor::eFaces;
121 myFacesTB->setChecked( hasFaces );
123 myNbCheckedButtons++;
124 connect( myFacesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
125 QLabel* nbFacesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
126 hl->addWidget( myFacesTB, 2, 0 );
127 hl->addWidget( nbFacesLab, 2, 1 );
128 myFacesTB->setEnabled( nbElements );
129 nbFacesLab->setEnabled( nbElements );
132 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) : aMesh->NbVolumes();
133 myVolumesTB = new QCheckBox( tr("SMESH_VOLUMES"), anEntitiesGrp );
134 myVolumesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TETRAS" ) ) ) );
135 bool hasVolumes = myEntityMode & SMESH_Actor::eVolumes;
136 myVolumesTB->setChecked( hasVolumes );
138 myNbCheckedButtons++;
139 connect( myVolumesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool) ) );
140 QLabel* nbVolumesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
141 hl->addWidget( myVolumesTB, 3, 0 );
142 hl->addWidget( nbVolumesLab, 3, 1 );
143 myVolumesTB->setEnabled( nbElements );
144 nbVolumesLab->setEnabled( nbElements );
147 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) : aMesh->NbBalls();
148 myBallsTB = new QCheckBox( tr("SMESH_BALLS"), anEntitiesGrp );
149 myBallsTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_BALL" ) ) ) );
150 bool hasBalls = myEntityMode & SMESH_Actor::eBallElem;
151 myBallsTB->setChecked( hasBalls );
153 myNbCheckedButtons++;
154 connect( myBallsTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
155 QLabel* nbBallsLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
156 hl->addWidget( myBallsTB, 4, 0 );
157 hl->addWidget( nbBallsLab, 4, 1 );
158 myBallsTB->setEnabled( nbElements );
159 nbBallsLab->setEnabled( nbElements );
161 QVBoxLayout* aDlgLay = new QVBoxLayout( mainFrame() );
162 aDlgLay->setMargin( 0 );
163 aDlgLay->setSpacing( SPACING );
164 aDlgLay->addWidget( anEntitiesGrp );
166 button( OK )->setText( tr( "SMESH_BUT_OK" ) );
168 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ) );
169 connect( this, SIGNAL( dlgOk() ), this, SLOT( onOk() ) );
173 \brief Destructor: clean-up resources if necessary
175 SMESHGUI_DisplayEntitiesDlg::~SMESHGUI_DisplayEntitiesDlg()
179 void SMESHGUI_DisplayEntitiesDlg::InverseEntityMode(unsigned int& theOutputMode,
180 unsigned int theMode)
182 bool anIsNotPresent = ~theOutputMode & theMode;
184 theOutputMode |= theMode;
186 theOutputMode &= ~theMode;
190 \brief Slot for changing entities state
192 void SMESHGUI_DisplayEntitiesDlg::onChangeEntityMode( bool isChecked )
194 QCheckBox* aSender = (QCheckBox*)sender();
195 if ( myNbCheckedButtons == 1 && !isChecked ) {
196 SUIT_MessageBox::warning(this, tr("SMESH_WRN_WARNING"),
197 tr("WRN_AT_LEAST_ONE"));
198 disconnect( aSender, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
199 aSender->setChecked( true );
200 connect( aSender, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
203 if ( my0DElemsTB == aSender )
204 InverseEntityMode( myEntityMode, SMESH_Actor::e0DElements );
205 else if ( myEdgesTB == aSender )
206 InverseEntityMode( myEntityMode, SMESH_Actor::eEdges );
207 else if ( myFacesTB == aSender )
208 InverseEntityMode( myEntityMode, SMESH_Actor::eFaces );
209 else if ( myVolumesTB == aSender )
210 InverseEntityMode( myEntityMode, SMESH_Actor::eVolumes );
211 else if ( myBallsTB == aSender )
212 InverseEntityMode( myEntityMode, SMESH_Actor::eBallElem );
214 isChecked ? myNbCheckedButtons++ : myNbCheckedButtons--;
219 \brief Show online help on dialog box
221 void SMESHGUI_DisplayEntitiesDlg::onHelp()
223 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
224 app->onHelpContextModule( "SMESH", "display_entity_page.html" );
228 \brief Display or update the mesh in the 3D view with selected entity mode
230 void SMESHGUI_DisplayEntitiesDlg::onOk()
232 SUIT_OverrideCursor wc;
234 const char* entry = myIObject->getEntry();
237 myActor = SMESH::CreateActor(SMESH::GetActiveStudyDocument(),
241 if( myEntityMode != myActor->GetEntityMode() ) {
242 myActor->SetEntityMode(myEntityMode);
243 SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
244 SMESH::DisplayActor( wnd, myActor );
245 SUIT_DataOwnerPtrList aList;
246 aList.append( new LightApp_DataOwner( entry ) );
247 SMESHGUI::selectionMgr()->setSelected( aList, false );
248 SMESH::UpdateView( wnd, SMESH::eDisplay, entry );