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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_TransparencyDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESHGUI_TransparencyDlg.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESH_Actor.h"
36 #include "SUIT_Desktop.h"
37 #include "SUIT_OverrideCursor.h"
39 #include "SALOME_ListIO.hxx"
40 #include "SALOME_ListIteratorOfListIO.hxx"
41 #include "SALOME_InteractiveObject.hxx"
43 #include "SalomeApp_Study.h"
44 #include "LightApp_SelectionMgr.h"
46 #include "SVTK_ViewWindow.h"
50 #include <qpushbutton.h>
53 #include <qgroupbox.h>
57 //=================================================================================
58 // class : SMESHGUI_TransparencyDlg()
61 //=================================================================================
62 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule,
66 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
67 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
68 mySMESHGUI( theModule ),
69 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
70 myViewWindow( SMESH::GetViewWindow( theModule ) )
73 setName("SMESHGUI_TransparencyDlg");
74 setCaption(tr("SMESH_TRANSPARENCY_TITLE" ));
75 setSizeGripEnabled(TRUE);
76 QGridLayout* SMESHGUI_TransparencyDlgLayout = new QGridLayout(this);
77 SMESHGUI_TransparencyDlgLayout->setSpacing(6);
78 SMESHGUI_TransparencyDlgLayout->setMargin(11);
80 /*************************************************************************/
81 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
82 GroupC1->setColumnLayout(0, Qt::Vertical);
83 GroupC1->layout()->setSpacing(0);
84 GroupC1->layout()->setMargin(0);
85 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
86 GroupC1Layout->setAlignment(Qt::AlignTop);
87 GroupC1Layout->setSpacing(6);
88 GroupC1Layout->setMargin(11);
90 TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
91 TextLabelTransparent->setText(tr("SMESH_TRANSPARENCY_TRANSPARENT" ));
92 TextLabelTransparent->setAlignment(AlignLeft);
93 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
95 ValueLab = new QLabel(GroupC1, "ValueLab");
96 ValueLab->setAlignment(AlignCenter);
97 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
98 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
99 GroupC1Layout->addWidget(ValueLab, 0, 1);
101 TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
102 TextLabelOpaque->setText(tr("SMESH_TRANSPARENCY_OPAQUE" ));
103 TextLabelOpaque->setAlignment(AlignRight);
104 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
106 Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
107 Slider1->setFocusPolicy(QWidget::NoFocus);
108 Slider1->setMinimumSize(300, 0);
109 Slider1->setTickmarks(QSlider::Above);
110 Slider1->setTickInterval(10);
111 Slider1->setTracking(true);
112 Slider1->setMinValue(0);
113 Slider1->setMaxValue(100);
114 Slider1->setLineStep(1);
115 Slider1->setPageStep(10);
116 GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
118 /*************************************************************************/
119 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
120 GroupButtons->setColumnLayout(0, Qt::Vertical);
121 GroupButtons->layout()->setSpacing(0);
122 GroupButtons->layout()->setMargin(0);
123 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
124 GroupButtonsLayout->setAlignment(Qt::AlignTop);
125 GroupButtonsLayout->setSpacing(6);
126 GroupButtonsLayout->setMargin(11);
128 buttonOk = new QPushButton(GroupButtons, "buttonOk");
129 buttonOk->setText(tr("SMESH_BUT_CLOSE"));
130 buttonOk->setAutoDefault(TRUE);
131 buttonOk->setDefault(TRUE);
132 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
133 GroupButtonsLayout->addWidget(buttonOk, 0, 1);
134 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
136 SMESHGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
137 SMESHGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
140 this->onSelectionChanged();
142 // signals and slots connections : after ValueHasChanged()
143 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
145 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
146 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnOk()));
147 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
152 //=================================================================================
153 // function : ~SMESHGUI_TransparencyDlg()
155 //=================================================================================
156 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
158 // no need to delete child widgets, Qt does it all for us
161 //=======================================================================
162 // function : ClickOnOk()
164 //=======================================================================
165 void SMESHGUI_TransparencyDlg::ClickOnOk()
170 //=================================================================================
171 // function : SetTransparency()
172 // purpose : Called when value of slider change
173 // : or the first time as initilisation
174 //=================================================================================
175 void SMESHGUI_TransparencyDlg::SetTransparency()
178 SUIT_OverrideCursor wc;
179 float opacity = this->Slider1->value() / 100.;
182 mySelectionMgr->selectedObjects(aList);
184 SALOME_ListIteratorOfListIO It (aList);
185 for (;It.More(); It.Next()) {
186 Handle(SALOME_InteractiveObject) IOS = It.Value();
187 SMESH_Actor* anActor = SMESH::FindActorByEntry(IOS->getEntry());
189 anActor->SetOpacity(opacity);
191 myViewWindow->Repaint();
196 //=================================================================================
197 // function : ValueHasChanged()
198 // purpose : Called when user moves a slider
199 //=================================================================================
200 void SMESHGUI_TransparencyDlg::ValueHasChanged()
202 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
205 //=================================================================================
206 // function : onSelectionChanged()
207 // purpose : Called when selection is changed
208 //=================================================================================
209 void SMESHGUI_TransparencyDlg::onSelectionChanged()
215 mySelectionMgr->selectedObjects(aList);
217 if (aList.Extent() == 1) {
218 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
219 if (!FirstIOS.IsNull()) {
220 SMESH_Actor* anActor = SMESH::FindActorByEntry(FirstIOS->getEntry());
222 opacity = int(anActor->GetOpacity() * 100. + 0.5);
224 } else if (aList.Extent() > 1) {
225 SALOME_ListIteratorOfListIO It (aList);
227 for (; It.More(); It.Next()) {
228 Handle(SALOME_InteractiveObject) IO = It.Value();
230 SMESH_Actor* anActor = SMESH::FindActorByEntry(IO->getEntry());
232 int op = int(anActor->GetOpacity() * 100. + 0.5);
235 else if (setOp != op) {
246 Slider1->setValue(opacity);