Developer documentation | Axl-2.5.1

axlInspectorObjectPoint.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectPoint.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/axlPoint.h>
24 
25 #include <dtkGuiSupport/dtkColorButton.h>
26 #include <dtkGuiSupport/dtkSplitter.h>
27 
28 #include <QtGui>
29 
30 class axlInspectorObjectPointPrivate
31 {
32 public:
33  axlPoint *point;
34 
35  QDoubleSpinBox *coordinate_x;
36  QDoubleSpinBox *coordinate_y;
37  QDoubleSpinBox *coordinate_z;
38 
39 // QSlider *sliderSize;
40  QDoubleSpinBox *sizeSpinBox;
41 
42 
43  dtkColorButton *colorButton;
44  QComboBox *comboBoxShader;
45 
46  QCheckBox *checkBoxShader;
47  QLineEdit *lineEditShader;
48  QPushButton *buttonShader;
49 
50  QSlider *sliderOpacity;
51 };
52 
54  axlInspectorObjectInterface(parent), //QFrame(parent),
55  d(new axlInspectorObjectPointPrivate)
56 {
57  d->coordinate_x = NULL;
58  d->coordinate_y = NULL;
59  d->coordinate_z = NULL;
60 
61 // d->sliderSize = NULL;
62  d->sizeSpinBox = NULL;
63 
64  d->colorButton = NULL;
65  d->comboBoxShader = NULL;
66 
67  d->checkBoxShader = NULL;
68  d->lineEditShader = NULL;
69  d->buttonShader = NULL;
70 
71  d->sliderOpacity = NULL;
72 }
73 
75 {
76 // if(d->point){
77 // disconnect(d->point, SIGNAL(modifiedGeometry(void)), this,SLOT( onChangedBoxValue_x(void)));
78 // disconnect(d->point, SIGNAL(modifiedGeometry(void)), this,SLOT( onChangedBoxValue_y(void)));
79 // disconnect(d->point, SIGNAL(modifiedGeometry(void)), this,SLOT( onChangedBoxValue_z(void)));
80 // d->point = NULL;
81 // }
82 
83  delete d;
84  d = NULL;
85 }
86 
88 {
89  return QSize(300, 300);
90 }
91 
93 {
94  d->point = point;
95  connect(d->point, SIGNAL(modifiedGeometry(void)), this, SLOT( updateValues(void)));
96  initWidget();
97 }
98 
99 void axlInspectorObjectPoint::initWidget()
100 {
101  QVBoxLayout *layoutTop = new QVBoxLayout(this);
102  layoutTop->addWidget(new QLabel("axlInspectorObjectPoint", this));
103 
105 
106  d->coordinate_x = new QDoubleSpinBox(this);
107  d->coordinate_x->setRange(-1000.0, 1000);
108  d->coordinate_x->setValue(d->point->x());
109  d->coordinate_x->setSingleStep(0.1);
110 
111  d->coordinate_y = new QDoubleSpinBox(this);
112  d->coordinate_y->setRange(-1000.0, 1000);
113  d->coordinate_y->setSingleStep(0.1);
114  d->coordinate_y->setValue(d->point->y());
115 
116  d->coordinate_z = new QDoubleSpinBox(this);
117  d->coordinate_z->setRange(-1000, 1000);
118  d->coordinate_z->setValue(d->point->z());
119  d->coordinate_z->setSingleStep(0.1);
120 
121  QHBoxLayout *layoutCoordinate_x = new QHBoxLayout;
122  layoutCoordinate_x->addWidget(new QLabel("X",this));
123  layoutCoordinate_x->addWidget(d->coordinate_x);
124 
125  QHBoxLayout *layoutCoordinate_y = new QHBoxLayout;
126  layoutCoordinate_y->addWidget(new QLabel("Y",this));
127  layoutCoordinate_y->addWidget(d->coordinate_y);
128 
129  QHBoxLayout *layoutCoordinate_z = new QHBoxLayout;
130  layoutCoordinate_z->addWidget(new QLabel("Z",this));
131  layoutCoordinate_z->addWidget(d->coordinate_z);
132 
134 
135 // d->sliderSize = new QSlider(Qt::Horizontal, this);
136 //
137 // QHBoxLayout *layoutSize = new QHBoxLayout;
138 // layoutSize->addWidget(new QLabel("Size ",this));
139 // layoutSize->addWidget(d->sliderSize);
140 // d->sliderSize->setMinimum(-800);
141 // d->sliderSize->setMaximum(500);
142 // d->sliderSize->setValue(initSizeValue());
143  d->sizeSpinBox = new QDoubleSpinBox(this);
144  d->sizeSpinBox->setDecimals(3);
145  d->sizeSpinBox->setRange(0, 4);
146  d->sizeSpinBox->setSingleStep(0.005);
147  d->sizeSpinBox->setValue(d->point->size());
148 
149  QHBoxLayout *layoutSize = new QHBoxLayout;
150  layoutSize->addWidget(new QLabel("Size",this));
151  layoutSize->addWidget(d->sizeSpinBox);
152 
154 
155  d->colorButton = new dtkColorButton(this);
156 
157  QHBoxLayout *layoutColorButton = new QHBoxLayout;
158  layoutColorButton->addWidget(new QLabel("Color",this));
159  layoutColorButton->addWidget(d->colorButton);
160  d->colorButton->setColor(this->initColorValue());
161 
163 
164  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
165 
166  QHBoxLayout *layoutOpacity = new QHBoxLayout;
167  layoutOpacity->addWidget(new QLabel("Opacity",this));
168  layoutOpacity->addWidget(d->sliderOpacity);
169  d->sliderOpacity->setMaximum(100);
170  d->sliderOpacity->setValue(initOpacityValue());
171 
173  d->comboBoxShader = new QComboBox(this);
174  d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
175 
176  d->checkBoxShader = new QCheckBox(this);
177  d->lineEditShader = new QLineEdit(this);
178  d->buttonShader = new QPushButton(this);
179  d->buttonShader->setText("open");
180 
181  d->lineEditShader->setText(this->initShaderValue());
182  this->initComboBoxShaderValue();
183 
184  if(d->lineEditShader->text().isEmpty())
185  {
186  d->lineEditShader->setEnabled(false);
187  d->buttonShader->setEnabled(false);
188  d->comboBoxShader->setEnabled(false);
189  }
190  else
191  d->checkBoxShader->setChecked(true);
192 
193 
195 
196  QVBoxLayout *layoutShader = new QVBoxLayout;
197  QHBoxLayout *layoutShader1 = new QHBoxLayout;
198 
199  QLabel *labelShader = new QLabel("Shader",this);
200  layoutShader1->addWidget(labelShader);
201  layoutShader1->addWidget(d->checkBoxShader);
202  layoutShader1->addWidget(d->comboBoxShader);
203  layoutShader1->addWidget(d->buttonShader);
204 
205  layoutShader1->setStretchFactor(labelShader, 2);
206  layoutShader1->setStretchFactor(d->checkBoxShader, 1);
207  layoutShader1->setStretchFactor(d->comboBoxShader, 4);
208  layoutShader1->setStretchFactor(d->buttonShader, 3);
209 
210  layoutShader->addLayout(layoutShader1);
211  layoutShader->addWidget(d->lineEditShader);
212 
213  layoutTop->addLayout(layoutCoordinate_x);
214  layoutTop->addLayout(layoutCoordinate_y);
215  layoutTop->addLayout(layoutCoordinate_z);
216 
217  layoutTop->addLayout(layoutColorButton);
218  layoutTop->addLayout(layoutSize);
219  layoutTop->addLayout(layoutOpacity);
220  layoutTop->addLayout(layoutShader);
221 
222  QWidget *top = new QWidget(this);
223  top->setMaximumWidth(295);
224 
225  top->setLayout(layoutTop);
226 
227  // dtkSplitter *splitter = new dtkSplitter(this, true);
228  // splitter->setOrientation(Qt::Vertical);
229  // splitter->addWidget(top);
230 
231  //QVBoxLayout *layout = new QVBoxLayout(this);
232  //layout->setContentsMargins(0, 0, 0, 0);
233  //layout->setSpacing(0);
234  //layout->addWidget(splitter);
235 
236 
237  connect(d->coordinate_x, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChanged_x(double)));
238  connect(d->coordinate_y, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChanged_y(double)));
239  connect(d->coordinate_z, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChanged_z(double)));
240 
241  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
242 // connect(d->sliderSize, SIGNAL(valueChanged(int)), this, SLOT(onSizeChanged(int)));
243  connect(d->sizeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onSizeChanged(double)));
244  connect(d->sliderOpacity, SIGNAL(valueChanged(int)), this, SLOT(onOpacityChanged(int)));
245 
246  connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)), this, SLOT(onLineEditShaderChanged(QString)));
247  connect(d->checkBoxShader, SIGNAL(clicked(bool)), this, SLOT(onShaderStateChanged(bool)));
248  connect(d->buttonShader, SIGNAL(clicked()), this, SLOT(openShader()));
249  connect(d->lineEditShader, SIGNAL(textChanged(QString)), this, SLOT(onShaderChanged(QString)));
250 
251 }
252 
253 
254 int axlInspectorObjectPoint::initSizeValue(void)
255 {
256  double initSize = 100.0*(log(d->point->size()/0.125))/log(2.0);
257  // if(initSize > 10.0)
258  // initSize = 10;
259  // else if(initSize < 0.0)
260  // initSize = 0;
261 
262  return initSize;
263 }
264 
265 void axlInspectorObjectPoint::initComboBoxShaderValue(void)
266 {
267  if(d->comboBoxShader) {
268 
269  QStringList filters;
270  filters << "*.vs";
271 
272  // First add item of axlShader.qrc, then find shader from shader path
273  QDir dirShader( ":axlShader/shader/");
274  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
275 
276  dirShader.setNameFilters(filters);
277 
278  QFileInfoList list = dirShader.entryInfoList();
279  // for (int i = 0; i < list.size(); ++i) {
280  // d->comboBoxShader->addItem(list.at(i).fileName());
281  // }
282 
283  QSettings settings("inria", "dtk");
284  QString defaultPath;
285  settings.beginGroup("shader");
286  QString defaultPathShader = settings.value("path", defaultPath).toString();
287  defaultPathShader.append("/");
288 
289  QDir defaultDirShader(defaultPathShader);
290  defaultDirShader.setNameFilters(filters);
291  QFileInfoList list2 = defaultDirShader.entryInfoList();
292 
293  list.append(list2);
294 
295  QStringList items;
296 
297  for (int i = 0; i < list.size(); ++i) {
298  if(!items.contains(list.at(i).fileName()))
299  items << list.at(i).fileName();
300  }
301 
302  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
303  int indInitShader = -1;
304  int indCurrentShader = -1;
305 
306  foreach(QString item, items) {
307  indCurrentShader++;
308  d->comboBoxShader->addItem(item);
309 
310  QFileInfo currentFileInfo(d->lineEditShader->text());
311 
312  if(currentFileInfo.exists())
313  {
314  if(item == currentFileInfo.fileName())
315  indInitShader =indCurrentShader;
316  }
317  }
318 
319  //init the value from the lineEditShader.
320  if(indInitShader != -1)
321  d->comboBoxShader->setCurrentIndex(indInitShader);
322  }
323 }
324 
326 {
327  // First add item of axlShader.qrc, then find shader from shader path
328  QDir dirShader( ":axlShader/shader/");
329  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
330 
331  QFileInfo currentFile(dirShader, shader);
332  if(!currentFile.exists())
333  {
334  QSettings settings("inria", "dtk");
335  QString defaultPath;
336  settings.beginGroup("shader");
337  QString defaultPathShader = settings.value("path", defaultPath).toString();
338  defaultPathShader.append("/");
339 
340  QDir defaultDirShader(defaultPathShader);
341  currentFile = QFileInfo(defaultDirShader, shader);
342 
343  }
344 
345  d->lineEditShader->setText(currentFile.absoluteFilePath());
346 }
347 
348 
349 //some adds for dynamic objects
351 {
352  double x = d->point->x();
353  d->coordinate_x->setValue(x);
354 }
355 
357 {
358  double y = d->point->y();
359  d->coordinate_y->setValue(y);
360 }
361 
363 {
364  double z = d->point->z();
365  d->coordinate_z->setValue(z);
366 }
367 //end adds for dynamic objects
368 
369 
371 {
372  const QSignalBlocker blockerCoordX(d->coordinate_x);
373  const QSignalBlocker blockerCoordY(d->coordinate_y);
374  const QSignalBlocker blockerCoordZ(d->coordinate_z);
375 
376  d->coordinate_x->setValue(d->point->x());
377  d->coordinate_y->setValue(d->point->y());
378  d->coordinate_z->setValue(d->point->z());
379 }
380 
381 QString axlInspectorObjectPoint::initShaderValue(void)
382 {
383  return d->point->shader();
384 }
385 
386 
387 QColor axlInspectorObjectPoint::initColorValue(void)
388 {
389  return d->point->color();
390 }
391 
392 
393 int axlInspectorObjectPoint::initOpacityValue(void)
394 {
395  double initOpacity = 0.0;
396  double opacity = d->point->opacity();
397  if(opacity > initOpacity)
398  initOpacity = opacity;
399 
400  return 100 * (1.0 - initOpacity);
401 }
402 
404 {
405  if(d->lineEditShader->isEnabled())
406  {
407  QString fileToOpen;
408  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("vs file (*.vs)"));
409  d->lineEditShader->setText(fileToOpen);
410  }
411 }
412 
414 {
415  d->point->setShader(shader);
416 
417 // emit modifiedProperty(d->point, AXL_PROPERTY_SHADER);
418 // emit update();
419  d->point->touchProperty();
420 }
421 
423 {
424  if(isShader)
425  {
426  d->comboBoxShader->setEnabled(true);
427  d->lineEditShader->setEnabled(true);
428  d->buttonShader->setEnabled(true);
429  onLineEditShaderChanged(d->comboBoxShader->currentText());
430 
431  d->point->setShader(d->lineEditShader->text());
432  }
433  else
434  {
435  d->comboBoxShader->setEnabled(false);
436  d->lineEditShader->setEnabled(false);
437  d->buttonShader->setEnabled(false);
438 
439  d->point->setShader("");
440  }
441 
442 // emit modifiedProperty(d->point, AXL_PROPERTY_SHADER);
443 // emit update();
444  d->point->touchProperty();
445 }
446 
448 {
449  d->point->x() = x;
450  d->point->touchGeometry();
451 // emit update();
452 }
453 
455 {
456  d->point->y() = y;
457  d->point->touchGeometry();
458 // emit update();
459 }
460 
462 {
463  d->point->z() = z;
464  d->point->touchGeometry();
465 // emit update();
466 }
467 
469 {
470  QVariant variant = d->point->QObject::property("color");
471  if(variant.isValid())
472  {
473  d->point->setColor(color);
474 // emit modifiedProperty(d->point, AXL_PROPERTY_COLOR);
475  d->point->touchProperty();
476  }
477 
478 // emit update();
479 }
480 
481 
482 //void axlInspectorObjectPoint::onSizeChanged(int size)
483 //{
484 // double size_d = pow(2.0, size/100.0 - 3.0); // range from 0.00 to 10.00
485 // d->point->setSize(size_d);
486 // d->point->touchGeometry();
487 // emit update();
488 //}
489 
491 {
492  d->point->setSize(size);
493  d->point->touchGeometry();
494 
495 // emit update();
496 }
497 
499 {
500  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
501  d->point->setOpacity(opacity_d);
502 // emit modifiedProperty(d->point, AXL_PROPERTY_OPACITY);
503 // emit update();
504  d->point->touchProperty();
505 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
void onShaderStateChanged(bool isShader)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
axlInspectorObjectPoint(QWidget *parent=0)