1 // Copyright (C) 2014-2020 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 );
100 myNbTypes = ( nbElements > 0 );
103 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) : aMesh->NbEdges();
104 myEdgesTB = new QCheckBox( tr("SMESH_EDGES"), anEntitiesGrp );
105 myEdgesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_EDGE" ) ) ) );
106 bool hasEdges = myEntityMode & SMESH_Actor::eEdges;
107 myEdgesTB->setChecked( hasEdges );
109 myNbCheckedButtons++;
110 connect( myEdgesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
111 QLabel* nbEdgesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
112 hl->addWidget( myEdgesTB, 1, 0 );
113 hl->addWidget( nbEdgesLab, 1, 1 );
114 myEdgesTB->setEnabled( nbElements );
115 nbEdgesLab->setEnabled( nbElements );
116 myNbTypes += ( nbElements > 0 );
119 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Face ) : aMesh->NbFaces();
120 myFacesTB = new QCheckBox( tr("SMESH_FACES"), anEntitiesGrp );
121 myFacesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TRIANGLE" ) ) ) );
122 bool hasFaces = myEntityMode & SMESH_Actor::eFaces;
123 myFacesTB->setChecked( hasFaces );
125 myNbCheckedButtons++;
126 connect( myFacesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
127 QLabel* nbFacesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
128 hl->addWidget( myFacesTB, 2, 0 );
129 hl->addWidget( nbFacesLab, 2, 1 );
130 myFacesTB->setEnabled( nbElements );
131 nbFacesLab->setEnabled( nbElements );
132 myNbTypes += ( nbElements > 0 );
135 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) : aMesh->NbVolumes();
136 myVolumesTB = new QCheckBox( tr("SMESH_VOLUMES"), anEntitiesGrp );
137 myVolumesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TETRAS" ) ) ) );
138 bool hasVolumes = myEntityMode & SMESH_Actor::eVolumes;
139 myVolumesTB->setChecked( hasVolumes );
141 myNbCheckedButtons++;
142 connect( myVolumesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool) ) );
143 QLabel* nbVolumesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
144 hl->addWidget( myVolumesTB, 3, 0 );
145 hl->addWidget( nbVolumesLab, 3, 1 );
146 myVolumesTB->setEnabled( nbElements );
147 nbVolumesLab->setEnabled( nbElements );
148 myNbTypes += ( nbElements > 0 );
151 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) : aMesh->NbBalls();
152 myBallsTB = new QCheckBox( tr("SMESH_BALLS"), anEntitiesGrp );
153 myBallsTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_BALL" ) ) ) );
154 bool hasBalls = myEntityMode & SMESH_Actor::eBallElem;
155 myBallsTB->setChecked( hasBalls );
157 myNbCheckedButtons++;
158 connect( myBallsTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
159 QLabel* nbBallsLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
160 hl->addWidget( myBallsTB, 4, 0 );
161 hl->addWidget( nbBallsLab, 4, 1 );
162 myBallsTB->setEnabled( nbElements );
163 nbBallsLab->setEnabled( nbElements );
164 myNbTypes += ( nbElements > 0 );
166 QVBoxLayout* aDlgLay = new QVBoxLayout( mainFrame() );
167 aDlgLay->setMargin( 0 );
168 aDlgLay->setSpacing( SPACING );
169 aDlgLay->addWidget( anEntitiesGrp );
171 button( OK )->setText( tr( "SMESH_BUT_OK" ) );
173 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ));
174 connect( this, SIGNAL( dlgOk() ), this, SLOT( onOk() ));
180 \brief Destructor: clean-up resources if necessary
182 SMESHGUI_DisplayEntitiesDlg::~SMESHGUI_DisplayEntitiesDlg()
186 void SMESHGUI_DisplayEntitiesDlg::InverseEntityMode(unsigned int& theOutputMode,
187 unsigned int theMode)
189 bool anIsNotPresent = ~theOutputMode & theMode;
191 theOutputMode |= theMode;
193 theOutputMode &= ~theMode;
197 \brief Slot for changing entities state
199 void SMESHGUI_DisplayEntitiesDlg::onChangeEntityMode( bool isChecked )
201 QCheckBox* aSender = (QCheckBox*)sender();
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.html" );
227 \brief Display or update the mesh in the 3D view with selected entity mode
229 void SMESHGUI_DisplayEntitiesDlg::onOk()
231 SUIT_OverrideCursor wc;
233 const char* entry = myIObject->getEntry();
236 myActor = SMESH::CreateActor(entry, true);
239 if( myEntityMode != myActor->GetEntityMode() ) {
240 myActor->SetEntityMode(myEntityMode);
241 SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
242 SMESH::DisplayActor( wnd, myActor );
243 SUIT_DataOwnerPtrList aList;
244 aList.append( new LightApp_DataOwner( entry ) );
245 SMESHGUI::selectionMgr()->setSelected( aList, false );
246 SMESH::UpdateView( wnd, SMESH::eDisplay, entry );
251 * \brief Enable/disable OK button depending on nb of selected entities
253 void SMESHGUI_DisplayEntitiesDlg::updateButtons()
255 setButtonEnabled( myNbCheckedButtons > 0 || myNbTypes == 0, OK );