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"
38 #include "SUIT_Session.h"
39 #include "SUIT_MessageBox.h"
41 #include "SALOME_ListIO.hxx"
42 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "SALOME_InteractiveObject.hxx"
45 #include "SalomeApp_Study.h"
46 #include "LightApp_Application.h"
47 #include "LightApp_SelectionMgr.h"
49 #include "SVTK_ViewWindow.h"
53 #include <qpushbutton.h>
56 #include <qgroupbox.h>
60 //=================================================================================
61 // class : SMESHGUI_TransparencyDlg()
64 //=================================================================================
65 SMESHGUI_TransparencyDlg::SMESHGUI_TransparencyDlg( SMESHGUI* theModule,
69 : QDialog( SMESH::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
70 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
71 mySMESHGUI( theModule ),
72 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
73 myViewWindow( SMESH::GetViewWindow( theModule ) )
76 setName("SMESHGUI_TransparencyDlg");
77 setCaption(tr("SMESH_TRANSPARENCY_TITLE" ));
78 setSizeGripEnabled(TRUE);
79 QGridLayout* SMESHGUI_TransparencyDlgLayout = new QGridLayout(this);
80 SMESHGUI_TransparencyDlgLayout->setSpacing(6);
81 SMESHGUI_TransparencyDlgLayout->setMargin(11);
83 /*************************************************************************/
84 QGroupBox* GroupC1 = new QGroupBox(this, "GroupC1");
85 GroupC1->setColumnLayout(0, Qt::Vertical);
86 GroupC1->layout()->setSpacing(0);
87 GroupC1->layout()->setMargin(0);
88 QGridLayout* GroupC1Layout = new QGridLayout(GroupC1->layout());
89 GroupC1Layout->setAlignment(Qt::AlignTop);
90 GroupC1Layout->setSpacing(6);
91 GroupC1Layout->setMargin(11);
93 TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
94 TextLabelTransparent->setText(tr("SMESH_TRANSPARENCY_TRANSPARENT" ));
95 TextLabelTransparent->setAlignment(AlignLeft);
96 GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
98 ValueLab = new QLabel(GroupC1, "ValueLab");
99 ValueLab->setAlignment(AlignCenter);
100 ValueLab->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
101 QFont fnt = ValueLab->font(); fnt.setBold(true); ValueLab->setFont(fnt);
102 GroupC1Layout->addWidget(ValueLab, 0, 1);
104 TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
105 TextLabelOpaque->setText(tr("SMESH_TRANSPARENCY_OPAQUE" ));
106 TextLabelOpaque->setAlignment(AlignRight);
107 GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
109 Slider1 = new QSlider(0, 10, 1, 5, Horizontal, GroupC1, "Slider1");
110 Slider1->setFocusPolicy(QWidget::NoFocus);
111 Slider1->setMinimumSize(300, 0);
112 Slider1->setTickmarks(QSlider::Above);
113 Slider1->setTickInterval(10);
114 Slider1->setTracking(true);
115 Slider1->setMinValue(0);
116 Slider1->setMaxValue(100);
117 Slider1->setLineStep(1);
118 Slider1->setPageStep(10);
119 GroupC1Layout->addMultiCellWidget(Slider1, 1, 1, 0, 2);
121 /*************************************************************************/
122 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
123 GroupButtons->setColumnLayout(0, Qt::Vertical);
124 GroupButtons->layout()->setSpacing(0);
125 GroupButtons->layout()->setMargin(0);
126 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
127 GroupButtonsLayout->setAlignment(Qt::AlignTop);
128 GroupButtonsLayout->setSpacing(6);
129 GroupButtonsLayout->setMargin(11);
131 buttonOk = new QPushButton(GroupButtons, "buttonOk");
132 buttonOk->setText(tr("SMESH_BUT_CLOSE"));
133 buttonOk->setAutoDefault(TRUE);
134 buttonOk->setDefault(TRUE);
135 buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
136 buttonHelp->setText(tr("SMESH_BUT_HELP"));
137 buttonHelp->setAutoDefault(TRUE);
139 //GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 0);
140 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
141 GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
142 GroupButtonsLayout->addWidget(buttonHelp, 0, 2);
143 //GroupButtonsLayout->addItem(new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 2);
145 SMESHGUI_TransparencyDlgLayout->addWidget(GroupC1, 0, 0);
146 SMESHGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
149 this->onSelectionChanged();
151 // signals and slots connections : after ValueHasChanged()
152 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
153 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(ClickOnHelp()));
154 connect(Slider1, SIGNAL(valueChanged(int)), this, SLOT(SetTransparency()));
155 connect(Slider1, SIGNAL(sliderMoved(int)), this, SLOT(ValueHasChanged()));
156 connect(mySMESHGUI, SIGNAL (SignalCloseAllDialogs()), this, SLOT(ClickOnOk()));
157 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
159 myHelpFileName = "transparency.htm";
164 //=================================================================================
165 // function : ~SMESHGUI_TransparencyDlg()
167 //=================================================================================
168 SMESHGUI_TransparencyDlg::~SMESHGUI_TransparencyDlg()
170 // no need to delete child widgets, Qt does it all for us
173 //=======================================================================
174 // function : ClickOnOk()
176 //=======================================================================
177 void SMESHGUI_TransparencyDlg::ClickOnOk()
182 //=================================================================================
183 // function : ClickOnHelp()
185 //=================================================================================
186 void SMESHGUI_TransparencyDlg::ClickOnHelp()
188 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
190 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
192 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
193 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
194 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(myHelpFileName),
195 QObject::tr("BUT_OK"));
199 //=================================================================================
200 // function : SetTransparency()
201 // purpose : Called when value of slider change
202 // : or the first time as initilisation
203 //=================================================================================
204 void SMESHGUI_TransparencyDlg::SetTransparency()
207 SUIT_OverrideCursor wc;
208 float opacity = this->Slider1->value() / 100.;
211 mySelectionMgr->selectedObjects(aList);
213 SALOME_ListIteratorOfListIO It (aList);
214 for (;It.More(); It.Next()) {
215 Handle(SALOME_InteractiveObject) IOS = It.Value();
216 SMESH_Actor* anActor = SMESH::FindActorByEntry(IOS->getEntry());
218 anActor->SetOpacity(opacity);
220 myViewWindow->Repaint();
225 //=================================================================================
226 // function : ValueHasChanged()
227 // purpose : Called when user moves a slider
228 //=================================================================================
229 void SMESHGUI_TransparencyDlg::ValueHasChanged()
231 ValueLab->setText(QString::number(this->Slider1->value()) + "%");
234 //=================================================================================
235 // function : onSelectionChanged()
236 // purpose : Called when selection is changed
237 //=================================================================================
238 void SMESHGUI_TransparencyDlg::onSelectionChanged()
244 mySelectionMgr->selectedObjects(aList);
246 if (aList.Extent() == 1) {
247 Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
248 if (!FirstIOS.IsNull()) {
249 SMESH_Actor* anActor = SMESH::FindActorByEntry(FirstIOS->getEntry());
251 opacity = int(anActor->GetOpacity() * 100. + 0.5);
253 } else if (aList.Extent() > 1) {
254 SALOME_ListIteratorOfListIO It (aList);
256 for (; It.More(); It.Next()) {
257 Handle(SALOME_InteractiveObject) IO = It.Value();
259 SMESH_Actor* anActor = SMESH::FindActorByEntry(IO->getEntry());
261 int op = int(anActor->GetOpacity() * 100. + 0.5);
264 else if (setOp != op) {
275 Slider1->setValue(opacity);