1 // Copyright (C) 2014-2024 CEA, EDF, 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>
36 #include <smIdType.hxx>
39 #include <QGridLayout>
42 #include <QVBoxLayout>
45 const int SPACING = 6;
48 \class SMESHGUI_DisplayEntitiesDlg
49 \brief Dialog box to select entities to be displayed in viewer
54 \param parent parent widget
56 SMESHGUI_DisplayEntitiesDlg::SMESHGUI_DisplayEntitiesDlg( QWidget* parent )
57 : SMESHGUI_Dialog( parent, true, false, Standard )
59 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
61 LightApp_SelectionMgr* mgr = SMESHGUI::selectionMgr();
62 SALOME_ListIO selected;
63 mgr->selectedObjects( selected );
64 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_nil();
66 myNbCheckedButtons = 0;
68 SALOME_ListIteratorOfListIO it( selected );
69 myIObject = selected.First();
70 if ( myIObject->hasEntry() ) {
71 myActor = SMESH::FindActorByEntry( myIObject->getEntry() );
73 myEntityMode = myActor ? myActor->GetEntityMode() : 0;
75 aMesh = SMESH::GetMeshByIO( myIObject );
78 setWindowTitle( tr( "MEN_DISP_ENT" ) );
81 QGroupBox* anEntitiesGrp = new QGroupBox( tr( "SMESH_MESHINFO_ENTITIES" ), mainFrame() );
82 QGridLayout* hl = new QGridLayout( anEntitiesGrp );
83 hl->setMargin( MARGIN );
84 hl->setSpacing( SPACING );
88 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_0DElement ) : aMesh->Nb0DElements();
89 my0DElemsTB = new QCheckBox( tr("SMESH_ELEMS0D"), anEntitiesGrp );
90 my0DElemsTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_ELEM0D" ) ) ) );
91 bool has0DElems = myEntityMode & SMESH_Actor::e0DElements;
92 my0DElemsTB->setChecked( has0DElems );
95 connect( my0DElemsTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
96 QLabel* nb0DElemsLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
97 hl->addWidget( my0DElemsTB, 0, 0 );
98 hl->addWidget( nb0DElemsLab, 0, 1 );
99 my0DElemsTB->setEnabled( nbElements );
100 nb0DElemsLab->setEnabled( nbElements );
101 myNbTypes = ( nbElements > 0 );
104 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Edge ) : aMesh->NbEdges();
105 myEdgesTB = new QCheckBox( tr("SMESH_EDGES"), anEntitiesGrp );
106 myEdgesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_EDGE" ) ) ) );
107 bool hasEdges = myEntityMode & SMESH_Actor::eEdges;
108 myEdgesTB->setChecked( hasEdges );
110 myNbCheckedButtons++;
111 connect( myEdgesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
112 QLabel* nbEdgesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
113 hl->addWidget( myEdgesTB, 1, 0 );
114 hl->addWidget( nbEdgesLab, 1, 1 );
115 myEdgesTB->setEnabled( nbElements );
116 nbEdgesLab->setEnabled( nbElements );
117 myNbTypes += ( nbElements > 0 );
120 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Face ) : aMesh->NbFaces();
121 myFacesTB = new QCheckBox( tr("SMESH_FACES"), anEntitiesGrp );
122 myFacesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TRIANGLE" ) ) ) );
123 bool hasFaces = myEntityMode & SMESH_Actor::eFaces;
124 myFacesTB->setChecked( hasFaces );
126 myNbCheckedButtons++;
127 connect( myFacesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
128 QLabel* nbFacesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
129 hl->addWidget( myFacesTB, 2, 0 );
130 hl->addWidget( nbFacesLab, 2, 1 );
131 myFacesTB->setEnabled( nbElements );
132 nbFacesLab->setEnabled( nbElements );
133 myNbTypes += ( nbElements > 0 );
136 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Volume ) : aMesh->NbVolumes();
137 myVolumesTB = new QCheckBox( tr("SMESH_VOLUMES"), anEntitiesGrp );
138 myVolumesTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_TETRAS" ) ) ) );
139 bool hasVolumes = myEntityMode & SMESH_Actor::eVolumes;
140 myVolumesTB->setChecked( hasVolumes );
142 myNbCheckedButtons++;
143 connect( myVolumesTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool) ) );
144 QLabel* nbVolumesLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
145 hl->addWidget( myVolumesTB, 3, 0 );
146 hl->addWidget( nbVolumesLab, 3, 1 );
147 myVolumesTB->setEnabled( nbElements );
148 nbVolumesLab->setEnabled( nbElements );
149 myNbTypes += ( nbElements > 0 );
152 nbElements = myActor ? myActor->GetObject()->GetNbEntities( SMDSAbs_Ball ) : aMesh->NbBalls();
153 myBallsTB = new QCheckBox( tr("SMESH_BALLS"), anEntitiesGrp );
154 myBallsTB->setIcon( QIcon( aResMgr->loadPixmap( "SMESH", tr( "ICON_DLG_BALL" ) ) ) );
155 bool hasBalls = myEntityMode & SMESH_Actor::eBallElem;
156 myBallsTB->setChecked( hasBalls );
158 myNbCheckedButtons++;
159 connect( myBallsTB, SIGNAL(toggled(bool)), this, SLOT(onChangeEntityMode(bool)) );
160 QLabel* nbBallsLab = new QLabel( QString("%1").arg(nbElements).toLatin1().data(), anEntitiesGrp );
161 hl->addWidget( myBallsTB, 4, 0 );
162 hl->addWidget( nbBallsLab, 4, 1 );
163 myBallsTB->setEnabled( nbElements );
164 nbBallsLab->setEnabled( nbElements );
165 myNbTypes += ( nbElements > 0 );
167 QVBoxLayout* aDlgLay = new QVBoxLayout( mainFrame() );
168 aDlgLay->setMargin( 0 );
169 aDlgLay->setSpacing( SPACING );
170 aDlgLay->addWidget( anEntitiesGrp );
172 button( OK )->setText( tr( "SMESH_BUT_OK" ) );
174 connect( this, SIGNAL( dlgHelp() ), this, SLOT( onHelp() ));
175 connect( this, SIGNAL( dlgOk() ), this, SLOT( onOk() ));
181 \brief Destructor: clean-up resources if necessary
183 SMESHGUI_DisplayEntitiesDlg::~SMESHGUI_DisplayEntitiesDlg()
187 void SMESHGUI_DisplayEntitiesDlg::InverseEntityMode(unsigned int& theOutputMode,
188 unsigned int theMode)
190 bool anIsNotPresent = ~theOutputMode & theMode;
192 theOutputMode |= theMode;
194 theOutputMode &= ~theMode;
198 \brief Slot for changing entities state
200 void SMESHGUI_DisplayEntitiesDlg::onChangeEntityMode( bool isChecked )
202 QCheckBox* aSender = (QCheckBox*)sender();
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.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(entry, true);
240 if( myEntityMode != myActor->GetEntityMode() ) {
241 myActor->SetEntityMode(myEntityMode);
242 SUIT_ViewWindow* wnd = SMESH::GetActiveWindow();
243 SMESH::DisplayActor( wnd, myActor );
244 SUIT_DataOwnerPtrList aList;
245 aList.append( new LightApp_DataOwner( entry ) );
246 SMESHGUI::selectionMgr()->setSelected( aList, false );
247 SMESH::UpdateView( wnd, SMESH::eDisplay, entry );
252 * \brief Enable/disable OK button depending on nb of selected entities
254 void SMESHGUI_DisplayEntitiesDlg::updateButtons()
256 setButtonEnabled( myNbCheckedButtons > 0 || myNbTypes == 0, OK );