Developer documentation | Axl-2.5.1

axlInspectorLight.cpp
Go to the documentation of this file.
1 /* axlInspectorLight.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Wed Mar 16 17:19:51 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Wed Nov 9 14:11:16 2011 (+0100)
8  * By: Julien Wintz
9  * Update #: 54
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
20 #include "axlInspectorLight.h"
23 
24 #include <axlCore/axlPoint.h>
26 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
27 #include <dtkCoreSupport/dtkAbstractProcess.h>
28 
29 #include <QtGui>
30 
31 class axlInspectorLightPrivate
32 {
33 public:
34  axlAbstractView *view;
35 
36  QCheckBox *checkBoxUseDefaultLight;
37  QCheckBox *checkBoxHideLight;
38 
39 
40  QDoubleSpinBox *spinBoxCoordonate_x;
41  QDoubleSpinBox *spinBoxCoordonate_y;
42  QDoubleSpinBox *spinBoxCoordonate_z;
43 
44  QSpinBox *spinBoxAmbiant_x;
45  QSpinBox *spinBoxAmbiant_y;
46  QSpinBox *spinBoxAmbiant_z;
47 
48  QSpinBox *spinBoxDiffuse_x;
49  QSpinBox *spinBoxDiffuse_y;
50  QSpinBox *spinBoxDiffuse_z;
51 
52  QSpinBox *spinBoxSpecular_x;
53  QSpinBox *spinBoxSpecular_y;
54  QSpinBox *spinBoxSpecular_z;
55 
56  QSpinBox *spinBoxExponent;
57 };
58 
59 axlInspectorLight::axlInspectorLight(QWidget *parent) : QDialog(parent), d(new axlInspectorLightPrivate)
60 {
61  d->view = NULL;
62 
63  QVBoxLayout *layout = new QVBoxLayout(this);
64 
65  QGridLayout *layoutLight1 = new QGridLayout();
66 
67  // checkbox
68  QHBoxLayout *layoutCheckBox = new QHBoxLayout();
69 
70  QLabel *labelCheckBox = new QLabel("Use default light :", this);
71  labelCheckBox->setToolTip("If the box is checked, the default light of the view plugin is"
72  "actived, if not, light widget is activated. In this case, the light is"
73  "draw in the view and user can handle it");
74 
75  d->checkBoxUseDefaultLight = new QCheckBox(this);
76  d->checkBoxUseDefaultLight->setChecked(true);
77  layoutCheckBox->addWidget(labelCheckBox);
78  layoutCheckBox->addWidget(d->checkBoxUseDefaultLight);
79 
80  // checkbox
81  QHBoxLayout *layoutCheckBoxHideLight = new QHBoxLayout();
82 
83  QLabel *labelCheckBoxHideLight = new QLabel("Hide light :", this);
84  labelCheckBoxHideLight->setToolTip("Check the box to Hide or not the Light Actor");
85 
86  d->checkBoxHideLight = new QCheckBox(this);
87  d->checkBoxHideLight->setChecked(false);
88  layoutCheckBoxHideLight->addWidget(labelCheckBoxHideLight);
89  layoutCheckBoxHideLight->addWidget(d->checkBoxHideLight);
90 
91  //coordonate
92 
93  QHBoxLayout *layoutCoordonate_x = new QHBoxLayout();
94  QHBoxLayout *layoutCoordonate_y = new QHBoxLayout();
95  QHBoxLayout *layoutCoordonate_z = new QHBoxLayout();
96  QLabel *labelCoordonate = new QLabel("Position",this);
97  labelCoordonate->setToolTip("Define the light position in the world space");
98  d->spinBoxCoordonate_x = new QDoubleSpinBox(this);
99  d->spinBoxCoordonate_y = new QDoubleSpinBox(this);
100  d->spinBoxCoordonate_z = new QDoubleSpinBox(this);
101 
102  d->spinBoxCoordonate_x->setMinimum(-500);
103  d->spinBoxCoordonate_x->setMaximum(500);
104  d->spinBoxCoordonate_y->setMinimum(-500);
105  d->spinBoxCoordonate_y->setMaximum(500);
106  d->spinBoxCoordonate_z->setMinimum(-500);
107  d->spinBoxCoordonate_z->setMaximum(500);
108 
109  d->spinBoxCoordonate_x->setValue(0.0);
110  d->spinBoxCoordonate_y->setValue(0.0);
111  d->spinBoxCoordonate_z->setValue(0.0);
112 
113  d->spinBoxCoordonate_x->setSingleStep(0.1);
114  d->spinBoxCoordonate_y->setSingleStep(0.1);
115  d->spinBoxCoordonate_z->setSingleStep(0.1);
116 
117 
118  layoutCoordonate_x->addWidget(d->spinBoxCoordonate_x);
119  layoutCoordonate_y->addWidget(d->spinBoxCoordonate_y);
120  layoutCoordonate_z->addWidget(d->spinBoxCoordonate_z);
121 
122  layoutLight1->addWidget(labelCoordonate, 0, 0);
123  layoutLight1->addLayout(layoutCoordonate_x, 0, 1);
124  layoutLight1->addLayout(layoutCoordonate_y, 0, 2);
125  layoutLight1->addLayout(layoutCoordonate_z, 0, 3);
126 
127  // Ambiant
128 
129  QHBoxLayout *layoutAmbiant_x = new QHBoxLayout();
130  QHBoxLayout *layoutAmbiant_y = new QHBoxLayout();
131  QHBoxLayout *layoutAmbiant_z = new QHBoxLayout();
132  QLabel *labelAmbiant = new QLabel("Ambiant",this);
133  labelAmbiant->setToolTip("Define the light Ambiant. Each value is defined between 0 and 255");
134 
135  d->spinBoxAmbiant_x = new QSpinBox(this);
136  d->spinBoxAmbiant_x->setMinimum(0);
137  d->spinBoxAmbiant_x->setMaximum(255);
138  d->spinBoxAmbiant_x->setValue(255);
139  d->spinBoxAmbiant_y = new QSpinBox(this);
140  d->spinBoxAmbiant_y->setMinimum(0);
141  d->spinBoxAmbiant_y->setMaximum(255);
142  d->spinBoxAmbiant_y->setValue(255);
143  d->spinBoxAmbiant_z = new QSpinBox(this);
144  d->spinBoxAmbiant_z->setMinimum(0);
145  d->spinBoxAmbiant_z->setMaximum(255);
146  d->spinBoxAmbiant_z->setValue(255);
147  layoutAmbiant_x->addWidget(d->spinBoxAmbiant_x);
148  layoutAmbiant_y->addWidget(d->spinBoxAmbiant_y);
149  layoutAmbiant_z->addWidget(d->spinBoxAmbiant_z);
150  layoutLight1->addWidget(labelAmbiant, 1, 0);
151  layoutLight1->addLayout(layoutAmbiant_x, 1, 1);
152  layoutLight1->addLayout(layoutAmbiant_y, 1, 2);
153  layoutLight1->addLayout(layoutAmbiant_z, 1, 3);
154 
155  //Diffuse
156 
157  QHBoxLayout *layoutDiffuse_x = new QHBoxLayout();
158  QHBoxLayout *layoutDiffuse_y = new QHBoxLayout();
159  QHBoxLayout *layoutDiffuse_z = new QHBoxLayout();
160 
161  QLabel *labelDiffuse = new QLabel("Diffuse",this);
162  labelDiffuse->setToolTip("Define the light diffuse. Each value is defined between 0 and 255");
163 
164  d->spinBoxDiffuse_x = new QSpinBox(this);
165  d->spinBoxDiffuse_x->setMinimum(0);
166  d->spinBoxDiffuse_x->setMaximum(255);
167  d->spinBoxDiffuse_x->setValue(255);
168 
169  d->spinBoxDiffuse_y = new QSpinBox(this);
170  d->spinBoxDiffuse_y->setMinimum(0);
171  d->spinBoxDiffuse_y->setMaximum(255);
172  d->spinBoxDiffuse_y->setValue(255);
173 
174  d->spinBoxDiffuse_z = new QSpinBox(this);
175  d->spinBoxDiffuse_z->setMinimum(0);
176  d->spinBoxDiffuse_z->setMaximum(255);
177  d->spinBoxDiffuse_z->setValue(255);
178 
179  layoutDiffuse_x->addWidget(d->spinBoxDiffuse_x);
180  layoutDiffuse_y->addWidget(d->spinBoxDiffuse_y);
181  layoutDiffuse_z->addWidget(d->spinBoxDiffuse_z);
182 
183  layoutLight1->addWidget(labelDiffuse, 2, 0);
184  layoutLight1->addLayout(layoutDiffuse_x, 2, 1);
185  layoutLight1->addLayout(layoutDiffuse_y, 2, 2);
186  layoutLight1->addLayout(layoutDiffuse_z, 2, 3);
187 
188  //Specular
189 
190  QHBoxLayout *layoutSpecular_x = new QHBoxLayout();
191  QHBoxLayout *layoutSpecular_y = new QHBoxLayout();
192  QHBoxLayout *layoutSpecular_z = new QHBoxLayout();
193  QLabel *labelSpecular = new QLabel("Specular",this);
194  labelSpecular->setToolTip("Define the light Specular. Each value is defined between 0 and 255");
195  d->spinBoxSpecular_x = new QSpinBox(this);
196  d->spinBoxSpecular_x->setMinimum(0);
197  d->spinBoxSpecular_x->setMaximum(255);
198  d->spinBoxSpecular_x->setValue(255);
199  d->spinBoxSpecular_y = new QSpinBox(this);
200  d->spinBoxSpecular_y->setMinimum(0);
201  d->spinBoxSpecular_y->setMaximum(255);
202  d->spinBoxSpecular_y->setValue(255);
203  d->spinBoxSpecular_z = new QSpinBox(this);
204  d->spinBoxSpecular_z->setMinimum(0);
205  d->spinBoxSpecular_z->setMaximum(255);
206  d->spinBoxSpecular_z->setValue(255);
207  layoutSpecular_x->addWidget(d->spinBoxSpecular_x);
208  layoutSpecular_y->addWidget(d->spinBoxSpecular_y);
209  layoutSpecular_z->addWidget(d->spinBoxSpecular_z);
210 
211  layoutLight1->addWidget(labelSpecular, 3, 0);
212  layoutLight1->addLayout(layoutSpecular_x, 3, 1);
213  layoutLight1->addLayout(layoutSpecular_y, 3, 2);
214  layoutLight1->addLayout(layoutSpecular_z, 3, 3);
215 
216  //Specular Exponent
217  QHBoxLayout *layoutExponent = new QHBoxLayout();
218  QLabel *labelExponent = new QLabel("Exponent",this);
219  labelExponent->setToolTip("Define the light Specular Exponent. More the exponent is elevated, more the specular effect of the light will be strong");
220  d->spinBoxExponent = new QSpinBox(this);
221  d->spinBoxExponent->setValue(50);
222  d->spinBoxExponent->setMinimum(0);
223  layoutExponent->addWidget(labelExponent);
224  layoutExponent->addWidget(d->spinBoxExponent);
225 
226  layout->addLayout(layoutCheckBox);
227  layout->addLayout(layoutCheckBoxHideLight);
228  layout->addLayout(layoutLight1);
229  layout->addLayout(layoutExponent);
230 
231  this->setStateLight(false);
232 
233  //connection :
234  connect(d->checkBoxUseDefaultLight, SIGNAL(clicked(bool)), this, SLOT(onActiveDefaultLight(bool)));
235  connect(d->checkBoxHideLight, SIGNAL(clicked(bool)), this, SLOT(onLightVisibilityChanged(bool)));
236 
237 
238  connect(d->spinBoxCoordonate_x, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
239  connect(d->spinBoxCoordonate_y, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
240  connect(d->spinBoxCoordonate_z, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
241  connect(d->spinBoxAmbiant_x, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
242  connect(d->spinBoxAmbiant_y, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
243  connect(d->spinBoxAmbiant_z, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
244  connect(d->spinBoxDiffuse_x, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
245  connect(d->spinBoxDiffuse_y, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
246  connect(d->spinBoxDiffuse_z, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
247  connect(d->spinBoxSpecular_x, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
248  connect(d->spinBoxSpecular_y, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
249  connect(d->spinBoxSpecular_z, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
250  connect(d->spinBoxExponent, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
251 
252 }
253 
255 {
256  delete d;
257 
258  d = NULL;
259 }
260 
262 {
263  d->view = view;
264 }
265 
267 {
268  Q_UNUSED(hide)
269  //just call the onValueChanged
270  this->onValueChanged("");
271 }
272 
273 void axlInspectorLight::onActiveDefaultLight(bool useDefaultLight)
274 {
275  this->setStateLight(!useDefaultLight);
276 
277  if(d->view)
278  d->view->activeDefaultLigh(useDefaultLight);
279  else
280  qDebug()<<"No view available to change the light. Please load a view plugin";
281 
282  if(!useDefaultLight)
283  this->onValueChanged("");
284 
285 }
286 
287 void axlInspectorLight::setStateLight(bool state)
288 {
289  d->checkBoxHideLight->setEnabled(state);
290 
291  d->spinBoxCoordonate_x->setEnabled(state);
292  d->spinBoxCoordonate_y->setEnabled(state);
293  d->spinBoxCoordonate_z->setEnabled(state);
294 
295  d->spinBoxAmbiant_x->setEnabled(state);
296  d->spinBoxAmbiant_y->setEnabled(state);
297  d->spinBoxAmbiant_z->setEnabled(state);
298 
299  d->spinBoxDiffuse_x->setEnabled(state);
300  d->spinBoxDiffuse_y->setEnabled(state);
301  d->spinBoxDiffuse_z->setEnabled(state);
302 
303  d->spinBoxSpecular_x->setEnabled(state);
304  d->spinBoxSpecular_y->setEnabled(state);
305  d->spinBoxSpecular_z->setEnabled(state);
306 
307  d->spinBoxExponent->setEnabled(state);
308 }
309 
311 {
312  //Q_UNUSED(value);
313 
314  double *position = new double[3];
315  double *ambiant = new double[3];
316  double *diffuse = new double[3];
317  double *specular = new double[3];
318 
319  position[0] = (double)(d->spinBoxCoordonate_x->value());
320  position[1] = (double)(d->spinBoxCoordonate_y->value());
321  position[2] = (double)(d->spinBoxCoordonate_z->value());
322 
323  ambiant[0] = (double)((double)(d->spinBoxAmbiant_x->value())/255.0);
324  ambiant[1] = (double)(double)((d->spinBoxAmbiant_y->value())/255.0);
325  ambiant[2] = (double)(double)((d->spinBoxAmbiant_z->value())/255.0);
326 
327  diffuse[0] = (double)((double)(d->spinBoxDiffuse_x->value())/255.0);
328  diffuse[1] = (double)((double)(d->spinBoxDiffuse_y->value())/255.0);
329  diffuse[2] = (double)((double)(d->spinBoxDiffuse_z->value())/255.0);
330 
331  specular[0] = (double)((double)(d->spinBoxSpecular_x->value())/255.0);
332  specular[1] = (double)((double)(d->spinBoxSpecular_y->value())/255.0);
333  specular[2] = (double)((double)(d->spinBoxSpecular_z->value())/255.0);
334 
335  d->view->setLight(1, d->checkBoxHideLight->isChecked(), position, ambiant, diffuse, specular, d->spinBoxExponent->value());
336 
337  delete[] position;
338  delete[] ambiant;
339  delete[] diffuse;
340  delete[] specular;
341 }
342 
343 void axlInspectorLight::onPositionChanged(double x, double y, double z)
344 {
345  disconnect(d->spinBoxCoordonate_x, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
346  disconnect(d->spinBoxCoordonate_y, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
347  disconnect(d->spinBoxCoordonate_z, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
348 
349  d->spinBoxCoordonate_x->setValue(x);
350  d->spinBoxCoordonate_y->setValue(y);
351  d->spinBoxCoordonate_z->setValue(z);
352 
353  connect(d->spinBoxCoordonate_x, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
354  connect(d->spinBoxCoordonate_y, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
355  connect(d->spinBoxCoordonate_z, SIGNAL(valueChanged(QString)), this, SLOT(onValueChanged(QString)));
356 }
void onLightVisibilityChanged(bool hide)
void onValueChanged(QString value)
axlInspectorLight(QWidget *parent=0)
void onPositionChanged(double x, double y, double z)
void onActiveDefaultLight(bool useDefaultLight)
void setView(axlAbstractView *view)