]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_TransparencyDlg.cxx
Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/visu.git] / src / VISUGUI / VisuGUI_TransparencyDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VisuGUI_TransparencyDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_TransparencyDlg.h"
30
31 #include "VisuGUI.h"
32 #include "VisuGUI_ViewTools.h"
33 #include "VisuGUI_Tools.h"
34 #include "VISU_Actor.h"
35
36 #include "SUIT_Desktop.h"
37 #include "SUIT_OverrideCursor.h"
38 #include "SUIT_Session.h"
39 #include "SUIT_MessageBox.h"
40 #include "SUIT_ResourceMgr.h"
41
42 #include "SALOME_ListIO.hxx"
43 #include "SALOME_ListIteratorOfListIO.hxx"
44 #include "SALOME_InteractiveObject.hxx"
45
46 #include "LightApp_Study.h"
47 #include "LightApp_SelectionMgr.h"
48 #include "LightApp_Application.h"
49
50 #include "SVTK_ViewWindow.h"
51
52 // QT Includes
53 #include <qlabel.h>
54 #include <qpushbutton.h>
55 #include <qslider.h>
56 #include <qlayout.h>
57 #include <qgroupbox.h>
58
59 using namespace std;
60
61 //=================================================================================
62 // class    : VisuGUI_TransparencyDlg()
63 // purpose  :
64 //
65 //=================================================================================
66 VisuGUI_TransparencyDlg::VisuGUI_TransparencyDlg( VisuGUI* theModule,
67                                       const char* name,
68                                       bool modal,
69                                       WFlags fl)
70      : QDialog( VISU::GetDesktop( theModule ), name, modal, WStyle_Customize | WStyle_NormalBorder |
71                 WStyle_Title | WStyle_SysMenu | WDestructiveClose ),
72      mySelectionMgr( VISU::GetSelectionMgr( theModule ) ),
73      myViewWindow( VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule) )
74 {
75   if (!name)
76     setName("VisuGUI_TransparencyDlg");
77   setCaption(tr("TRANSPARENCY_TITLE" ));
78   setSizeGripEnabled(TRUE);
79   QGridLayout* VisuGUI_TransparencyDlgLayout = new QGridLayout(this);
80   VisuGUI_TransparencyDlgLayout->setSpacing(6);
81   VisuGUI_TransparencyDlgLayout->setMargin(11);
82
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);
92
93   TextLabelTransparent = new QLabel(GroupC1, "TextLabelTransparent");
94   TextLabelTransparent->setText(tr("TRANSPARENCY_TRANSPARENT" ));
95   TextLabelTransparent->setAlignment(AlignLeft);
96   GroupC1Layout->addWidget(TextLabelTransparent, 0, 0);
97
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);
103
104   TextLabelOpaque = new QLabel(GroupC1, "TextLabelOpaque");
105   TextLabelOpaque->setText(tr("TRANSPARENCY_OPAQUE" ));
106   TextLabelOpaque->setAlignment(AlignRight);
107   GroupC1Layout->addWidget(TextLabelOpaque, 0, 2);
108
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);
120
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);
130
131   buttonOk = new QPushButton(GroupButtons, "buttonOk");
132   buttonOk->setText(tr("BUT_CLOSE"));
133   buttonOk->setAutoDefault(TRUE);
134   buttonOk->setDefault(TRUE);
135
136   buttonHelp = new QPushButton(GroupButtons, "buttonHelp");
137   buttonHelp->setText(tr("BUT_HELP"));
138   buttonHelp->setAutoDefault(TRUE);
139
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
144   VisuGUI_TransparencyDlgLayout->addWidget(GroupC1,      0, 0);
145   VisuGUI_TransparencyDlgLayout->addWidget(GroupButtons, 1, 0);
146
147   // Initial state
148   this->onSelectionChanged();
149
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(mySelectionMgr,  SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
156 }
157
158 //=================================================================================
159 // function : ~VisuGUI_TransparencyDlg()
160 // purpose  :
161 //=================================================================================
162 VisuGUI_TransparencyDlg::~VisuGUI_TransparencyDlg()
163 {
164   // no need to delete child widgets, Qt does it all for us
165 }
166
167 //=======================================================================
168 // function : ClickOnOk()
169 // purpose  :
170 //=======================================================================
171 void VisuGUI_TransparencyDlg::ClickOnOk()
172 {
173   close();
174 }
175
176 //=======================================================================
177 // function : ClickOnHelp()
178 // purpose  :
179 //=======================================================================
180 void VisuGUI_TransparencyDlg::ClickOnHelp()
181 {
182   QString aHelpFileName = "/files/changing_visualization_parameters_of_the_presenetation.htm#Changing3";
183   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
184   if (app) {
185     VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
186     app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
187   }
188   else {
189     SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
190                            QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
191                            arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
192                            QObject::tr("BUT_OK"));
193   }
194 }
195
196 //=================================================================================
197 // function : SetTransparency()
198 // purpose  : Called when value of slider change
199 //          : or the first time as initilisation
200 //=================================================================================
201 void VisuGUI_TransparencyDlg::SetTransparency()
202 {
203   if( myViewWindow ) {
204     SUIT_OverrideCursor wc;
205     float opacity = this->Slider1->value() / 100.;
206
207     SALOME_ListIO aList;
208     mySelectionMgr->selectedObjects(aList);
209
210     SALOME_ListIteratorOfListIO It (aList);
211     for (;It.More(); It.Next()) {
212       Handle(SALOME_InteractiveObject) IOS = It.Value();
213       VISU_Actor* anActor = VISU::FindActor(myViewWindow, IOS->getEntry());
214       if (anActor)
215         anActor->SetOpacity(opacity);
216     }
217     myViewWindow->Repaint();
218   }
219   ValueHasChanged();
220 }
221
222 //=================================================================================
223 // function : ValueHasChanged()
224 // purpose  : Called when user moves a slider
225 //=================================================================================
226 void VisuGUI_TransparencyDlg::ValueHasChanged()
227 {
228   ValueLab->setText(QString::number(this->Slider1->value()) + "%");
229 }
230
231 //=================================================================================
232 // function : onSelectionChanged()
233 // purpose  : Called when selection is changed
234 //=================================================================================
235 void VisuGUI_TransparencyDlg::onSelectionChanged()
236 {
237   if( myViewWindow ) {
238     int opacity = 100;
239
240     SALOME_ListIO aList;
241     mySelectionMgr->selectedObjects(aList);
242
243     if (aList.Extent() == 1) {
244       Handle(SALOME_InteractiveObject) FirstIOS = aList.First();
245       if (!FirstIOS.IsNull()) {
246         VISU_Actor* anActor = VISU::FindActor(myViewWindow, FirstIOS->getEntry());
247         if (anActor)
248           opacity = int(anActor->GetOpacity() * 100. + 0.5);
249       }
250     } else if (aList.Extent() > 1) {
251       SALOME_ListIteratorOfListIO It (aList);
252       int setOp = -1;
253       for (; It.More(); It.Next()) {
254         Handle(SALOME_InteractiveObject) IO = It.Value();
255         if (!IO.IsNull()) {
256           VISU_Actor* anActor = VISU::FindActor(myViewWindow, IO->getEntry());
257           if (anActor) {
258             int op = int(anActor->GetOpacity() * 100. + 0.5);
259             if (setOp < 0)
260               setOp = op;
261             else if (setOp != op) {
262               setOp = 100;
263               break;
264             }
265           }
266         }
267       }
268       if (setOp >= 0)
269         opacity = setOp;
270     } else {
271     }
272     Slider1->setValue(opacity);
273   }
274   ValueHasChanged();
275 }