1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_TransparencyDlg.cxx
24 // Author : Nicolas REJNERI
28 #include "SMESHGUI_TransparencyDlg.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESH_Actor.h"
35 #include "SUIT_Desktop.h"
36 #include "SUIT_OverrideCursor.h"
37 #include "SUIT_Session.h"
38 #include "SUIT_MessageBox.h"
40 #include "SALOME_ListIO.hxx"
41 #include "SALOME_ListIteratorOfListIO.hxx"
42 #include "SALOME_InteractiveObject.hxx"
44 #include "SalomeApp_Study.h"
45 #include "LightApp_Application.h"
46 #include "LightApp_SelectionMgr.h"
48 #include "SVTK_ViewWindow.h"
52 #include <qpushbutton.h>
55 #include <qgroupbox.h>
59 //=================================================================================
60 // class : SMESHGUI_TransparencyDlg()
63 //=================================================================================
64 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule,
68 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
69 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
70 mySMESHGUI( theModule ),
71 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
72 myViewWindow( SMESH::GetViewWindow( theModule ) )
75 setName("SMESHGUI_TransparencyDlg");
76 setCaption(tr("SMESH_TRANSPARENCY_TITLE" ));
77 setSizeGripEnabled(TRUE);
78 QGridLayout* SMESHGUI_TransparencyDlgLayout = new QGridLayout(this);
79 SMESHGUI_TransparencyDlgLayout->setSpacing(6);
80 SMESHGUI_TransparencyDlgLayout->setMargin(11);
82 /*************************************************************************/
83 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
84 GroupC1->setColumnLayout(0, Qt::Vertical);
85 GroupC1->layout()->setSpacing(0);
86 GroupC1->layout()->setMargin(0);
87 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
88 GroupC1Layout->setAlignment(Qt::AlignTop);
89 GroupC1Layout->setSpacing(6);
90 GroupC1Layout->setMargin(11);
92 TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
93 TextLabelTransparent->setText(tr("SMESH_TRANSPARENCY_TRANSPARENT" ));
94 TextLabelTransparent->setAlignment(AlignLeft);
95 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
97 ValueLab = new QLabel(GroupC1, "ValueLab");
98 ValueLab->setAlignment(AlignCenter);
99 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
100 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
101 GroupC1Layout->addWidget(ValueLab, 0, 1);
103 TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
104 TextLabelOpaque->setText(tr("SMESH_TRANSPARENCY_OPAQUE" ));
105 TextLabelOpaque->setAlignment(AlignRight);
106 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
108 Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
109 Slider1->setFocusPolicy(QWidget::NoFocus);
110 Slider1->setMinimumSize(300, 0);
111 Slider1->setTickmarks(QSlider::Above);
112 Slider1->setTickInterval(10);
113 Slider1->setTracking(true);
114 Slider1->setMinValue(0);
115 Slider1->setMaxValue(100);
116 Slider1->setLineStep(1);
117 Slider1->setPageStep(10);
118 GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
120 /*************************************************************************/
121 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
122 GroupButtons->setColumnLayout(0, Qt::Vertical);
123 GroupButtons->layout()->setSpacing(0);
124 GroupButtons->layout()->setMargin(0);
125 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
126 GroupButtonsLayout->setAlignment(Qt::AlignTop);
127 GroupButtonsLayout->setSpacing(6);
128 GroupButtonsLayout->setMargin(11);
130 buttonOk = new QPushButton(GroupButtons, "buttonOk");
131 buttonOk->setText(tr("SMESH_BUT_CLOSE"));
132 buttonOk->setAutoDefault(TRUE);
133 buttonOk->setDefault(TRUE);
134 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
135 buttonHelp->setText(tr("SMESH_BUT_HELP"));
136 buttonHelp->setAutoDefault(TRUE);
138 //GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
139 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
140 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
141 GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
142 //GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
144 SMESHGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
145 SMESHGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
148 this->onSelectionChanged();
150 // signals and slots connections : after ValueHasChanged()
151 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
152 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
153 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
154 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
155 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnOk()));
156 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
158 myHelpFileName = "transparency_page.html";
163 //=================================================================================
164 // function : ~SMESHGUI_TransparencyDlg()
166 //=================================================================================
167 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
169 // no need to delete child widgets, Qt does it all for us
172 //=======================================================================
173 // function : ClickOnOk()
175 //=======================================================================
176 void SMESHGUI_TransparencyDlg::ClickOnOk()
181 //=================================================================================
182 // function : ClickOnHelp()
184 //=================================================================================
185 void SMESHGUI_TransparencyDlg::ClickOnHelp()
187 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
189 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
193 platform = "winapplication";
195 platform = "application";
197 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
198 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
199 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
200 QObject::tr("BUT_OK"));
204 //=================================================================================
205 // function : SetTransparency()
206 // purpose : Called when value of slider change
207 // : or the first time as initilisation
208 //=================================================================================
209 void SMESHGUI_TransparencyDlg::SetTransparency()
212 SUIT_OverrideCursor wc;
213 float opacity = this->Slider1->value() / 100.;
216 mySelectionMgr->selectedObjects(aList);
218 SALOME_ListIteratorOfListIO It (aList);
219 for (;It.More(); It.Next()) {
220 Handle(SALOME_InteractiveObject) IOS = It.Value();
221 SMESH_Actor* anActor = SMESH::FindActorByEntry(IOS->getEntry());
223 anActor->SetOpacity(opacity);
225 myViewWindow->Repaint();
230 //=================================================================================
231 // function : ValueHasChanged()
232 // purpose : Called when user moves a slider
233 //=================================================================================
234 void SMESHGUI_TransparencyDlg::ValueHasChanged()
236 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
239 //=================================================================================
240 // function : onSelectionChanged()
241 // purpose : Called when selection is changed
242 //=================================================================================
243 void SMESHGUI_TransparencyDlg::onSelectionChanged()
249 mySelectionMgr->selectedObjects(aList);
251 if (aList.Extent() == 1) {
252 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
253 if (!FirstIOS.IsNull()) {
254 SMESH_Actor* anActor = SMESH::FindActorByEntry(FirstIOS->getEntry());
256 opacity = int(anActor->GetOpacity() * 100. + 0.5);
258 } else if (aList.Extent() > 1) {
259 SALOME_ListIteratorOfListIO It (aList);
261 for (; It.More(); It.Next()) {
262 Handle(SALOME_InteractiveObject) IO = It.Value();
264 SMESH_Actor* anActor = SMESH::FindActorByEntry(IO->getEntry());
266 int op = int(anActor->GetOpacity() * 100. + 0.5);
269 else if (setOp != op) {
280 Slider1->setValue(opacity);
285 //=================================================================================
286 // function : keyPressEvent()
288 //=================================================================================
289 void SMESHGUI_TransparencyDlg::keyPressEvent( QKeyEvent* e )
291 QDialog::keyPressEvent( e );
292 if ( e->isAccepted() )
295 if ( e->key() == Key_F1 )