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"
34 #include "SMESH_Actor.h"
36 #include "SUIT_OverrideCursor.h"
38 #include "SALOME_ListIO.hxx"
39 #include "SALOME_ListIteratorOfListIO.hxx"
40 #include "SALOME_InteractiveObject.hxx"
42 #include "SalomeApp_Study.h"
43 #include "SalomeApp_SelectionMgr.h"
45 #include "SVTK_ViewWindow.h"
49 #include <qpushbutton.h>
52 #include <qgroupbox.h>
56 //=================================================================================
57 // class : SMESHGUI_TransparencyDlg()
60 //=================================================================================
61 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg (QWidget* parent,
65 : QDialog(parent, name, modal, WStyle_Customize | WStyle_NormalBorder |
66 WStyle_Title | WStyle_SysMenu | WDestructiveClose)
69 setName("SMESHGUI_TransparencyDlg");
70 setCaption(tr("SMESH_TRANSPARENCY_TITLE" ));
71 setSizeGripEnabled(TRUE);
72 QGridLayout* SMESHGUI_TransparencyDlgLayout = new QGridLayout(this);
73 SMESHGUI_TransparencyDlgLayout->setSpacing(6);
74 SMESHGUI_TransparencyDlgLayout->setMargin(11);
76 /*************************************************************************/
77 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
78 GroupC1->setColumnLayout(0, Qt::Vertical);
79 GroupC1->layout()->setSpacing(0);
80 GroupC1->layout()->setMargin(0);
81 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
82 GroupC1Layout->setAlignment(Qt::AlignTop);
83 GroupC1Layout->setSpacing(6);
84 GroupC1Layout->setMargin(11);
86 TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
87 TextLabelTransparent->setText(tr("SMESH_TRANSPARENCY_TRANSPARENT" ));
88 TextLabelTransparent->setAlignment(AlignLeft);
89 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
91 ValueLab = new QLabel(GroupC1, "ValueLab");
92 ValueLab->setAlignment(AlignCenter);
93 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
94 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
95 GroupC1Layout->addWidget(ValueLab, 0, 1);
97 TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
98 TextLabelOpaque->setText(tr("SMESH_TRANSPARENCY_OPAQUE" ));
99 TextLabelOpaque->setAlignment(AlignRight);
100 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
102 Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
103 Slider1->setFocusPolicy(QWidget::NoFocus);
104 Slider1->setMinimumSize(300, 0);
105 Slider1->setTickmarks(QSlider::Above);
106 Slider1->setTickInterval(10);
107 Slider1->setTracking(true);
108 Slider1->setMinValue(0);
109 Slider1->setMaxValue(100);
110 Slider1->setLineStep(1);
111 Slider1->setPageStep(10);
112 GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
114 /*************************************************************************/
115 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
116 GroupButtons->setColumnLayout(0, Qt::Vertical);
117 GroupButtons->layout()->setSpacing(0);
118 GroupButtons->layout()->setMargin(0);
119 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
120 GroupButtonsLayout->setAlignment(Qt::AlignTop);
121 GroupButtonsLayout->setSpacing(6);
122 GroupButtonsLayout->setMargin(11);
124 buttonOk = new QPushButton(GroupButtons, "buttonOk");
125 buttonOk->setText(tr("SMESH_BUT_CLOSE"));
126 buttonOk->setAutoDefault(TRUE);
127 buttonOk->setDefault(TRUE);
128 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
129 GroupButtonsLayout->addWidget(buttonOk, 0, 1);
130 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
132 SMESHGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
133 SMESHGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
135 mySelectionMgr = SMESHGUI::selectionMgr();
138 this->onSelectionChanged();
140 // signals and slots connections : after ValueHasChanged()
141 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
142 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
143 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
144 connect(SMESHGUI::GetSMESHGUI(), SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnOk()));
145 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
147 /* Move widget on the botton right corner of main widget */
149 SMESHGUI::GetSMESHGUI()->DefineDlgPosition(this, x, y);
154 //=================================================================================
155 // function : ~SMESHGUI_TransparencyDlg()
157 //=================================================================================
158 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
160 // no need to delete child widgets, Qt does it all for us
163 //=======================================================================
164 // function : ClickOnOk()
166 //=======================================================================
167 void SMESHGUI_TransparencyDlg::ClickOnOk()
172 //=================================================================================
173 // function : SetTransparency()
174 // purpose : Called when value of slider change
175 // : or the first time as initilisation
176 //=================================================================================
177 void SMESHGUI_TransparencyDlg::SetTransparency()
179 if (SVTK_ViewWindow* aVTKViewWindow = SMESH::GetCurrentVtkView()) {
180 SUIT_OverrideCursor wc;
181 float opacity = this->Slider1->value() / 100.;
184 mySelectionMgr->selectedObjects(aList);
186 SALOME_ListIteratorOfListIO It (aList);
187 for (;It.More(); It.Next()) {
188 Handle(SALOME_InteractiveObject) IOS = It.Value();
189 SMESH_Actor* anActor = SMESH::FindActorByEntry(IOS->getEntry());
191 anActor->SetOpacity(opacity);
193 aVTKViewWindow->Repaint();
198 //=================================================================================
199 // function : ValueHasChanged()
200 // purpose : Called when user moves a slider
201 //=================================================================================
202 void SMESHGUI_TransparencyDlg::ValueHasChanged()
204 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
207 //=================================================================================
208 // function : onSelectionChanged()
209 // purpose : Called when selection is changed
210 //=================================================================================
211 void SMESHGUI_TransparencyDlg::onSelectionChanged()
213 if (SVTK_ViewWindow* aVTKViewWindow = SMESH::GetCurrentVtkView()) {
217 mySelectionMgr->selectedObjects(aList);
219 if (aList.Extent() == 1) {
220 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
221 if (!FirstIOS.IsNull()) {
222 SMESH_Actor* anActor = SMESH::FindActorByEntry(FirstIOS->getEntry());
224 opacity = int(anActor->GetOpacity() * 100. + 0.5);
226 } else if (aList.Extent() > 1) {
227 SALOME_ListIteratorOfListIO It (aList);
229 for (; It.More(); It.Next()) {
230 Handle(SALOME_InteractiveObject) IO = It.Value();
232 SMESH_Actor* anActor = SMESH::FindActorByEntry(IO->getEntry());
234 int op = int(anActor->GetOpacity() * 100. + 0.5);
237 else if (setOp != op) {
248 Slider1->setValue(opacity);