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()));
149 /* Move widget on the botton right corner of main widget */
151 mySMESHGUI->DefineDlgPosition(this, x, y);
156 //=================================================================================
157 // function : ~SMESHGUI_TransparencyDlg()
159 //=================================================================================
160 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
162 // no need to delete child widgets, Qt does it all for us
165 //=======================================================================
166 // function : ClickOnOk()
168 //=======================================================================
169 void SMESHGUI_TransparencyDlg::ClickOnOk()
174 //=================================================================================
175 // function : SetTransparency()
176 // purpose : Called when value of slider change
177 // : or the first time as initilisation
178 //=================================================================================
179 void SMESHGUI_TransparencyDlg::SetTransparency()
182 SUIT_OverrideCursor wc;
183 float opacity = this->Slider1->value() / 100.;
186 mySelectionMgr->selectedObjects(aList);
188 SALOME_ListIteratorOfListIO It (aList);
189 for (;It.More(); It.Next()) {
190 Handle(SALOME_InteractiveObject) IOS = It.Value();
191 SMESH_Actor* anActor = SMESH::FindActorByEntry(IOS->getEntry());
193 anActor->SetOpacity(opacity);
195 myViewWindow->Repaint();
200 //=================================================================================
201 // function : ValueHasChanged()
202 // purpose : Called when user moves a slider
203 //=================================================================================
204 void SMESHGUI_TransparencyDlg::ValueHasChanged()
206 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
209 //=================================================================================
210 // function : onSelectionChanged()
211 // purpose : Called when selection is changed
212 //=================================================================================
213 void SMESHGUI_TransparencyDlg::onSelectionChanged()
219 mySelectionMgr->selectedObjects(aList);
221 if (aList.Extent() == 1) {
222 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
223 if (!FirstIOS.IsNull()) {
224 SMESH_Actor* anActor = SMESH::FindActorByEntry(FirstIOS->getEntry());
226 opacity = int(anActor->GetOpacity() * 100. + 0.5);
228 } else if (aList.Extent() > 1) {
229 SALOME_ListIteratorOfListIO It (aList);
231 for (; It.More(); It.Next()) {
232 Handle(SALOME_InteractiveObject) IO = It.Value();
234 SMESH_Actor* anActor = SMESH::FindActorByEntry(IO->getEntry());
236 int op = int(anActor->GetOpacity() * 100. + 0.5);
239 else if (setOp != op) {
250 Slider1->setValue(opacity);