Developer documentation | Axl-2.5.1

axlInspectorObjectCylinder.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectCylinder.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/axlCylinder.h>
23 #include <axlCore/axlPoint.h>
25 
26 #include <dtkGuiSupport/dtkColorButton.h>
27 #include <dtkGuiSupport/dtkSplitter.h>
28 
29 #include <QtGui>
30 
31 class axlInspectorObjectCylinderPrivate
32 {
33 public:
34  axlCylinder *cylinder;
35  QDoubleSpinBox *coordinateFirst_x;
36  QDoubleSpinBox *coordinateFirst_y;
37  QDoubleSpinBox *coordinateFirst_z;
38 
39  QDoubleSpinBox *coordinateSecond_x;
40  QDoubleSpinBox *coordinateSecond_y;
41  QDoubleSpinBox *coordinateSecond_z;
42 
43  QDoubleSpinBox *radius;
44 
45 
46  // QSlider *sliderSize;
47 
48 
49  dtkColorButton *colorButton;
50 
51  QComboBox *comboBoxShader;
52 
53  QCheckBox *checkBoxShader;
54  QLineEdit *lineEditShader;
55  QPushButton *buttonShader;
56 
57  QSlider *sliderOpacity;
58 };
59 
61  axlInspectorObjectInterface(parent), //QFrame(parent),
62  d(new axlInspectorObjectCylinderPrivate)
63 {
64  d->coordinateFirst_x = NULL;
65  d->coordinateFirst_y = NULL;
66  d->coordinateFirst_z = NULL;
67 
68  d->coordinateSecond_x = NULL;
69  d->coordinateSecond_y = NULL;
70  d->coordinateSecond_z = NULL;
71 
72  d->radius = NULL;
73 
74  // d->sliderSize = NULL;
75 
76  d->colorButton = NULL;
77 
78  d->comboBoxShader = NULL;
79 
80  d->checkBoxShader = NULL;
81  d->lineEditShader = NULL;
82  d->buttonShader = NULL;
83 
84  d->sliderOpacity = NULL;
85 }
86 
88 {
89  delete d;
90 
91  d = NULL;
92 }
93 
95 {
96  return QSize(300, 300);
97 }
98 
100 {
101  d->cylinder = cylinder;
102  connect(d->cylinder,SIGNAL(modifiedGeometry(void)), this, SLOT(updateValues()));
103  initWidget();
104 }
105 
106 void axlInspectorObjectCylinder::initWidget()
107 {
108  QVBoxLayout *layoutTop = new QVBoxLayout(this);
109  layoutTop->addWidget(new QLabel("axlInspectorObjectCylinder", this));
110 
111  addPointLayout(layoutTop, FirstPoint, "First point:",
112  d->coordinateFirst, onCoordDataChangedFirst,
113  d->cylinder->firstPoint());
114  addPointLayout(layoutTop, SecondPoint, "Second point:",
115  d->coordinateSecond, onCoordDataChangedSecond,
116  d->cylinder->secondPoint());
117 
118  addValueLayout (layoutTop, Radius, "Radius:", d->radius, onRadiusChanged, d->cylinder->radius());
119  addColorButton (layoutTop, d->colorButton, onColorChanged, initColorValue());
120  addOpacitySlider (layoutTop, d->sliderOpacity, onOpacityChanged, initOpacityValue());
121  addShaderComboBox(layoutTop,
122  d->comboBoxShader, d->checkBoxShader, d->lineEditShader, d->buttonShader,
124  initShaderValue());
125 
126  QWidget *top = new QWidget(this);
127 
128  top->setLayout(layoutTop);
129  top->setMaximumWidth(295);
130 
131 
132 }
133 
134 
136 {
137  d->lineEditShader->setText(this->filePath(shader));
138 }
139 
140 QString axlInspectorObjectCylinder::initShaderValue(void)
141 {
142  return d->cylinder->shader();
143 }
144 
145 
146 QColor axlInspectorObjectCylinder::initColorValue(void)
147 {
148  return d->cylinder->color();
149 }
150 
151 
152 int axlInspectorObjectCylinder::initOpacityValue(void)
153 {
154  double initOpacity = 0.0;
155  double opacity = d->cylinder->opacity();
156  if(opacity > initOpacity)
157  initOpacity = opacity;
158 
159  return 100 * (1.0 - initOpacity);
160 }
161 
163 {
164  if(d->lineEditShader->isEnabled())
165  {
166  QString fileToOpen;
167  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("vs file (*.vs)"));
168  d->lineEditShader->setText(fileToOpen);
169  }
170 }
171 
173 {
174  d->cylinder->setShader(shader);
175  emit modifiedProperty(d->cylinder, 2);
176 }
177 
179 {
180  if(isShader)
181  {
182  d->comboBoxShader->setEnabled(true);
183  d->lineEditShader->setEnabled(true);
184  d->buttonShader->setEnabled(true);
185  onLineEditShaderChanged(d->comboBoxShader->currentText());
186 
187 // emit dataChangedByShader(d->cylinder, d->lineEditShader->text());
188  }
189  else
190  {
191  d->comboBoxShader->setEnabled(false);
192  d->lineEditShader->setEnabled(false);
193  d->buttonShader->setEnabled(false);
194 
195  d->cylinder->setShader("");
196 // emit dataChangedByShader(d->cylinder, "");
197  }
198 
199 // emit modifiedProperty(d->cylinder, 2);
200 // emit update();
201  d->cylinder->touchProperty();
202 }
203 
205 {
206  d->cylinder->firstPoint()->x() = x;
207  d->cylinder->touchGeometry();
208 
209  //emit dataChangedByGeometry(d->cylinder);
210 // emit update();
211 }
212 
214 {
215  d->cylinder->firstPoint()->y() = y;
216  d->cylinder->touchGeometry();
217 
218  //emit dataChangedByGeometry(d->cylinder);
219 // emit update();
220 }
221 
223 {
224  d->cylinder->firstPoint()->z() = z;
225  d->cylinder->touchGeometry();
226 
227  //emit dataChangedByGeometry(d->cylinder);
228 // emit update();
229 }
230 
231 
233 {
234  d->cylinder->secondPoint()->x() = x;
235  d->cylinder->touchGeometry();
236 
237  //emit dataChangedByGeometry(d->cylinder);
238 // emit update();
239 }
240 
242 {
243  d->cylinder->secondPoint()->y() = y;
244  d->cylinder->touchGeometry();
245 
246  //emit dataChangedByGeometry(d->cylinder);
247 // emit update();
248 }
249 
251 {
252  d->cylinder->secondPoint()->z() = z;
253  d->cylinder->touchGeometry();
254 
255  //emit dataChangedByGeometry(d->cylinder);
256 // emit update();
257 }
258 
260 {
261  d->cylinder->setRadius(radius);
262  d->cylinder->touchGeometry();
263 
264  //emit dataChangedByGeometry(d->cylinder);
265 // emit update();
266 }
267 
268 
270 {
271  QVariant variant = d->cylinder->QObject::property("color");
272  if(variant.isValid())
273  {
274  d->cylinder->setColor(color);
275 
276 // emit dataChangedByColor(d->cylinder, color.redF(), color.greenF(), color.blueF());
277 // emit modifiedProperty(d->cylinder, 0);
278  d->cylinder->touchProperty();
279  }
280 
281 // emit update();
282 }
283 
284 
285 //void axlInspectorObjectCylinder::onSizeChanged(int size)
286 //{
287 // double size_d = size / 100.0; // range from 0.00 to 10.00
288 
289 // QVariant variant = d->cylinder->QObject::property("size");
290 // if(variant.isValid())
291 // {
292 // d->cylinder->setSize(size_d);
293 // emit dataChangedByGeometry(d->cylinder);
294 
295 // //emit dataChangedBySize(d->cylinder, size_d);
296 // }
297 
298 // emit update();
299 //}
300 
302 {
303  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
304 
305  QVariant variant = d->cylinder->QObject::property("opacity");
306  if(variant.isValid())
307  {
308  d->cylinder->setOpacity(opacity_d);
309 
310 // emit dataChangedByOpacity(d->cylinder, opacity_d);
311 // emit modifiedProperty(d->cylinder, 1);
312  d->cylinder->touchProperty();
313  }
314 
315 // emit update();
316 }
317 
318 
320 {
321 // this->blockSignals(true);
322  const QSignalBlocker blockerFirstX(d->coordinateFirst_x);
323  const QSignalBlocker blockerFirstY(d->coordinateFirst_y);
324  const QSignalBlocker blockerFirstZ(d->coordinateFirst_z);
325  const QSignalBlocker blockerSecondX(d->coordinateSecond_x);
326  const QSignalBlocker blockerSecondY(d->coordinateSecond_y);
327  const QSignalBlocker blockerSecondZ(d->coordinateSecond_z);
328  const QSignalBlocker blockerRadius(d->radius);
329 
330  d->coordinateFirst_x->setValue(d->cylinder->firstPoint()->x());
331  d->coordinateFirst_y->setValue(d->cylinder->firstPoint()->y());
332  d->coordinateFirst_z->setValue(d->cylinder->firstPoint()->z());
333  d->coordinateSecond_x->setValue(d->cylinder->secondPoint()->x());
334  d->coordinateSecond_y->setValue(d->cylinder->secondPoint()->y());
335  d->coordinateSecond_z->setValue(d->cylinder->secondPoint()->z());
336  d->radius->setValue(d->cylinder->radius());
337 // this->blockSignals(false);
338 }
#define addColorButton(layoutTop, colorButton, slot, init)
#define addOpacitySlider(layoutTop, sliderOpacity, slot, init)
#define addPointLayout(layoutTop, name, title, coordinatePoint, slot, init)
Class axlCylinder defines 3D cylinders.
Definition: axlCylinder.h:33
#define addValueLayout(layoutTop, name, title, data, slot, init)
void modifiedProperty(dtkAbstractData *, int)
#define addShaderComboBox(layoutTop, comboBoxShader, checkBoxShader, lineEditShader, buttonShader, onComboBoxChanged, onCheckBoxChanged, onTextChanged, openShader, init)
void setData(axlCylinder *cylinder)
QString filePath(const QString &shader)