Developer documentation | Axl-2.5.1

axlInspectorObjectPlane.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectPlane.cpp ---
2  *
3  * Author: Meriadeg Perrinel
4  * Copyright (C) 2008 - Meriadeg Perrinel, Inria.
5  * Created: Fri Mar 18 11:19:52 2011 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Apr 3 14:20:40 2012 (+0200)
8  * By: Julien Wintz
9  * Update #: 60
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 
22 #include <axlCore/axlPlane.h>
23 #include <axlCore/axlPoint.h>
25 
26 #include <dtkGuiSupport/dtkColorButton.h>
27 #include <dtkGuiSupport/dtkSplitter.h>
28 
29 #include <QtGui>
30 
31 class axlInspectorObjectPlanePrivate
32 {
33 public:
34  axlPlane *plane;
35  QDoubleSpinBox *coordinatePoint_x;
36  QDoubleSpinBox *coordinatePoint_y;
37  QDoubleSpinBox *coordinatePoint_z;
38 
39  QDoubleSpinBox *coordinateNormal_x;
40  QDoubleSpinBox *coordinateNormal_y;
41  QDoubleSpinBox *coordinateNormal_z;
42 
43 // QSlider *sliderSize;
44  QDoubleSpinBox *sizeSpinBox;
45 
46  dtkColorButton *colorButton;
47  QComboBox *comboBoxShader;
48 
49  QCheckBox *checkBoxShader;
50  QLineEdit *lineEditShader;
51  QPushButton *buttonShader;
52 
53  QSlider *sliderOpacity;
54 };
55 
58  //QFrame(parent),
59  d(new axlInspectorObjectPlanePrivate)
60 {
61  d->coordinatePoint_x = NULL;
62  d->coordinatePoint_y = NULL;
63  d->coordinatePoint_z = NULL;
64 
65  d->coordinateNormal_x = NULL;
66  d->coordinateNormal_y = NULL;
67  d->coordinateNormal_z = NULL;
68 
69 // d->sliderSize = NULL;
70  d->sizeSpinBox = NULL;
71 
72  d->colorButton = NULL;
73  d->comboBoxShader = NULL;
74 
75  d->checkBoxShader = NULL;
76  d->lineEditShader = NULL;
77  d->buttonShader = NULL;
78 
79  d->sliderOpacity = NULL;
80 }
81 
83 {
84  delete d;
85 
86  d = NULL;
87 }
88 
90 {
91  return QSize(300, 300);
92 }
93 
95 {
96  d->plane = plane;
97  connect(d->plane, SIGNAL(modifiedGeometry(void)), this, SLOT(updateValues(void)));
98  initWidget();
99 }
100 
101 void axlInspectorObjectPlane::initWidget()
102 {
103  QVBoxLayout *layoutTop = new QVBoxLayout(this);
104  layoutTop->addWidget(new QLabel("axlInspectorObjectPlane", this));
105 
106  addPointLayout(layoutTop, Point, "Point:",
107  d->coordinatePoint, onCoordDataChangedPoint,
108  d->plane->point());
109 
110  addPointLayout(layoutTop, Normal, "Normal:",
111  d->coordinateNormal, onCoordDataChangedNormal,
112  d->plane->normal());
113 
114 // addSizeSlider (layoutTop, d->sliderSize, onSizeChanged, initSizeValue());
115  d->sizeSpinBox = new QDoubleSpinBox(this);
116  d->sizeSpinBox->setDecimals(3);
117  d->sizeSpinBox->setRange(0, 10);
118  d->sizeSpinBox->setSingleStep(0.005);
119  d->sizeSpinBox->setValue(d->plane->size());
120 
121  QHBoxLayout *layoutSize = new QHBoxLayout;
122  layoutSize->addWidget(new QLabel("Size",this));
123  layoutSize->addWidget(d->sizeSpinBox);
124  layoutTop->addLayout(layoutSize);
125  connect(d->sizeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onSizeChanged(double)));
126 
127  addColorButton(layoutTop, d->colorButton, onColorChanged, initColorValue());
128  addOpacitySlider(layoutTop, d->sliderOpacity, onOpacityChanged, initOpacityValue());
129  addShaderComboBox(layoutTop,
130  d->comboBoxShader, d->checkBoxShader, d->lineEditShader, d->buttonShader,
132  initShaderValue());
133 
134  QWidget *top = new QWidget(this);
135  top->setMaximumWidth(295);
136  top->setLayout(layoutTop);
137 }
138 
139 
140 int axlInspectorObjectPlane::initSizeValue(void)
141 {
142  double initSize = 100.0*(log(d->plane->size()/0.125))/log(2.0);
143 
144  return initSize;
145 }
146 
147 
148 
150 {
151  d->lineEditShader->setText(this->filePath(shader));
152 }
153 
154 QString axlInspectorObjectPlane::initShaderValue(void)
155 {
156  return d->plane->shader();
157 }
158 
159 
160 QColor axlInspectorObjectPlane::initColorValue(void)
161 {
162  return d->plane->color();
163 }
164 
165 
166 int axlInspectorObjectPlane::initOpacityValue(void)
167 {
168  double initOpacity = 0.0;
169  double opacity = d->plane->opacity();
170  if(opacity > initOpacity)
171  initOpacity = opacity;
172 
173  return 100 * (1.0 - initOpacity);
174 }
175 
177 {
178  if(d->lineEditShader->isEnabled())
179  {
180  QString fileToOpen;
181  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("vs file (*.vs)"));
182  d->lineEditShader->setText(fileToOpen);
183  }
184 }
185 
187 {
188  d->plane->setShader(shader);
189 // emit modifiedProperty(d->plane, 2);
190  d->plane->touchProperty();
191 // emit update();
192 }
193 
195 {
196  if(isShader)
197  {
198  d->comboBoxShader->setEnabled(true);
199  d->lineEditShader->setEnabled(true);
200  d->buttonShader->setEnabled(true);
201  onLineEditShaderChanged(d->comboBoxShader->currentText());
202  d->plane->setShader(d->lineEditShader->text());
203  }
204  else
205  {
206  d->comboBoxShader->setEnabled(false);
207  d->lineEditShader->setEnabled(false);
208  d->buttonShader->setEnabled(false);
209  d->plane->setShader("");
210  }
211 
212 // emit modifiedProperty(d->plane, 2);
213  d->plane->touchProperty();
214 // emit update();
215 }
216 
218 {
219  d->plane->point()->x() = x;
220  d->plane->touchGeometry();
221 // emit update();
222 }
223 
225 {
226  d->plane->point()->y() = y;
227  d->plane->touchGeometry();
228 // emit update();
229 }
230 
232 {
233  d->plane->point()->z() = z;
234  d->plane->touchGeometry();
235 // emit update();
236 }
237 
238 
240 {
241  d->plane->normal()->x() = x;
242  d->plane->touchGeometry();
243 // emit update();
244 }
245 
247 {
248  d->plane->normal()->y() = y;
249  d->plane->touchGeometry();
250 // emit update();
251 }
252 
254 {
255  d->plane->normal()->z() = z;
256  d->plane->touchGeometry();
257 // emit update();
258 }
259 
261 {
262  QVariant variant = d->plane->QObject::property("color");
263  if(variant.isValid())
264  {
265  d->plane->setColor(color);
266 // emit modifiedProperty(d->plane, 0);
267  d->plane->touchProperty();
268  }
269 
270 // emit update();
271 }
272 
273 
274 //void axlInspectorObjectPlane::onSizeChanged(int size)
275 //{
276 // double size_d = pow(2.0, size/100.0 - 3.0); // range from 0.00 to 10.00
277 //
278 // QVariant variant = d->plane->QObject::property("size");
279 // if(variant.isValid())
280 // {
281 // d->plane->setSize(size_d);
282 // emit modifiedProperty(d->plane, 3);
283 // }
284 //
285 // emit update();
286 //}
287 
289 {
290  d->plane->setSize(size);
291 
292 // emit modifiedProperty(d->plane, 3);
293 // emit update();
294  d->plane->touchGeometry();
295 }
296 
298 {
299  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
300 
301  QVariant variant = d->plane->QObject::property("opacity");
302  if(variant.isValid())
303  {
304  d->plane->setOpacity(opacity_d);
305 // emit modifiedProperty(d->plane, 1);
306  d->plane->touchProperty();
307  }
308 
309 // emit update();
310 }
311 
313 {
314 // this->blockSignals(true);
315  const QSignalBlocker blockerPointX(d->coordinatePoint_x);
316  const QSignalBlocker blockerPointY(d->coordinatePoint_y);
317  const QSignalBlocker blockerPointZ(d->coordinatePoint_z);
318  const QSignalBlocker blockerNormalX(d->coordinateNormal_x);
319  const QSignalBlocker blockerNormalY(d->coordinateNormal_y);
320  const QSignalBlocker blockerNormalZ(d->coordinateNormal_z);
321 
322  d->coordinatePoint_x->setValue(d->plane->point()->x());
323  d->coordinatePoint_y->setValue(d->plane->point()->y());
324  d->coordinatePoint_z->setValue(d->plane->point()->z());
325 
326  d->coordinateNormal_x->setValue(d->plane->normal()->x());
327  d->coordinateNormal_y->setValue(d->plane->normal()->y());
328  d->coordinateNormal_z->setValue(d->plane->normal()->z());
329 
330 // this->blockSignals(false);
331 }
#define addColorButton(layoutTop, colorButton, slot, init)
#define addOpacitySlider(layoutTop, sliderOpacity, slot, init)
void setData(axlPlane *pointt)
#define addPointLayout(layoutTop, name, title, coordinatePoint, slot, init)
Class axlPlane defines 3D planes.
Definition: axlPlane.h:34
void onShaderStateChanged(bool isShader)
axlInspectorObjectPlane(QWidget *parent=0)
#define addShaderComboBox(layoutTop, comboBoxShader, checkBoxShader, lineEditShader, buttonShader, onComboBoxChanged, onCheckBoxChanged, onTextChanged, openShader, init)
QString filePath(const QString &shader)