Developer documentation | Axl-2.5.1

axlInspectorObjectLine.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectLine.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 
20 #include "axlInspectorObjectLine.h"
21 
22 #include <axlCore/axlLine.h>
23 #include <axlCore/axlPoint.h>
24 #include <axlCore/axlDataDynamic.h>
26 
27 //#include <math>
28 #include <dtkGuiSupport/dtkColorButton.h>
29 #include <dtkGuiSupport/dtkSplitter.h>
30 
31 #include <QtGui>
32 
33 class axlInspectorObjectLinePrivate
34 {
35 public:
36  axlLine *line;
37  QDoubleSpinBox *coordinateFirst_x;
38  QDoubleSpinBox *coordinateFirst_y;
39  QDoubleSpinBox *coordinateFirst_z;
40 
41  QDoubleSpinBox *coordinateSecond_x;
42  QDoubleSpinBox *coordinateSecond_y;
43  QDoubleSpinBox *coordinateSecond_z;
44 
45 // QSlider *sliderSize;
46  QDoubleSpinBox *sizeSpinBox;
47 
48  dtkColorButton *colorButton;
49 
50  QComboBox *comboBoxShader;
51 
52  QCheckBox *checkBoxShader;
53  QLineEdit *lineEditShader;
54  QPushButton *buttonShader;
55 
56  QSlider *sliderOpacity;
57 };
58 
60  axlInspectorObjectInterface(parent), //QFrame(parent),
61  d(new axlInspectorObjectLinePrivate)
62 {
63  d->line = NULL;
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->sliderSize = NULL;
73  d->sizeSpinBox = NULL;
74 
75  d->colorButton = NULL;
76  d->comboBoxShader = NULL;
77 
78  d->checkBoxShader = NULL;
79  d->lineEditShader = NULL;
80  d->buttonShader = NULL;
81 
82  d->sliderOpacity = NULL;
83 }
84 
86 {
87  delete d;
88 
89  d = NULL;
90 }
91 
93 {
94  return QSize(300, 300);
95 }
96 
98 {
99  d->line = line;
100 
101  // connect the modification of the geometry with the widget
102  connect(d->line, SIGNAL(modifiedGeometry(void)), this, SLOT( updateValues(void)));
103 
104  initWidget();
105 }
106 
108 {
109  double initSize = 100.0*(log(d->line->size()/0.125))/log(2.0);
110 
111  return initSize;;
112 }
113 
115 {
116  return d->line->shader();
117 }
118 
119 
121 {
122  return d->line->color();
123 }
124 
126 {
127  double initOpacity = 0.0;
128  double opacity = d->line->opacity();
129 
130  if(opacity > initOpacity)
131  initOpacity = opacity;
132 
133  return 100 * (1.0 - initOpacity);
134 }
135 
137 {
138  QVBoxLayout *layoutTop = new QVBoxLayout(this);
139  layoutTop->addWidget(new QLabel("axlInspectorObjectLine", this));
140 
142  d->coordinateFirst_x = new QDoubleSpinBox(this);
143  d->coordinateFirst_x->setRange(-1000, 1000);
144  d->coordinateFirst_x->setSingleStep(0.1);
145  d->coordinateFirst_x->setValue(d->line->firstPoint()->x());
146 
147  d->coordinateFirst_y = new QDoubleSpinBox(this);
148  d->coordinateFirst_y->setRange(-1000, 1000);
149  d->coordinateFirst_y->setSingleStep(0.1);
150  d->coordinateFirst_y->setValue(d->line->firstPoint()->y());
151 
152  d->coordinateFirst_z = new QDoubleSpinBox(this);
153  d->coordinateFirst_z->setRange(-1000, 1000);
154  d->coordinateFirst_z->setSingleStep(0.1);
155  d->coordinateFirst_z->setValue(d->line->firstPoint()->z());
156 
157  d->coordinateSecond_x = new QDoubleSpinBox(this);
158  d->coordinateSecond_x->setRange(-1000, 1000);
159  d->coordinateSecond_x->setSingleStep(0.1);
160  d->coordinateSecond_x->setValue(d->line->secondPoint()->x());
161 
162  d->coordinateSecond_y = new QDoubleSpinBox(this);
163  d->coordinateSecond_y->setRange(-1000, 1000);
164  d->coordinateSecond_y->setSingleStep(0.1);
165  d->coordinateSecond_y->setValue(d->line->secondPoint()->y());
166 
167  d->coordinateSecond_z = new QDoubleSpinBox(this);
168  d->coordinateSecond_z->setRange(-1000, 1000);
169  d->coordinateSecond_z->setSingleStep(0.1);
170  d->coordinateSecond_z->setValue(d->line->secondPoint()->z());
171 
172 
173  QHBoxLayout *layoutcoordinateFirst_x = new QHBoxLayout;
174  layoutcoordinateFirst_x->addWidget(new QLabel("X",this));
175  layoutcoordinateFirst_x->addWidget(d->coordinateFirst_x);
176 
177  QHBoxLayout *layoutcoordinateFirst_y = new QHBoxLayout;
178  layoutcoordinateFirst_y->addWidget(new QLabel("Y",this));
179  layoutcoordinateFirst_y->addWidget(d->coordinateFirst_y);
180 
181  QHBoxLayout *layoutcoordinateFirst_z = new QHBoxLayout;
182  layoutcoordinateFirst_z->addWidget(new QLabel("Z",this));
183  layoutcoordinateFirst_z->addWidget(d->coordinateFirst_z);
184 
185 
186  QHBoxLayout *layoutcoordinateSecond_x = new QHBoxLayout;
187  layoutcoordinateSecond_x->addWidget(new QLabel("X",this));
188  layoutcoordinateSecond_x->addWidget(d->coordinateSecond_x);
189 
190  QHBoxLayout *layoutcoordinateSecond_y = new QHBoxLayout;
191  layoutcoordinateSecond_y->addWidget(new QLabel("Y",this));
192  layoutcoordinateSecond_y->addWidget(d->coordinateSecond_y);
193 
194  QHBoxLayout *layoutcoordinateSecond_z = new QHBoxLayout;
195  layoutcoordinateSecond_z->addWidget(new QLabel("Z",this));
196  layoutcoordinateSecond_z->addWidget(d->coordinateSecond_z);
197 
199 // d->sliderSize = new QSlider(Qt::Horizontal, this);
200 //
201 // QHBoxLayout *layoutSize = new QHBoxLayout;
202 // layoutSize->addWidget(new QLabel("Size",this));
203 // layoutSize->addWidget(d->sliderSize);
204 // d->sliderSize->setMinimum(-800);
205 // d->sliderSize->setMaximum(500);
206 // d->sliderSize->setValue(initSizeValue());
207 
208  d->sizeSpinBox = new QDoubleSpinBox(this);
209  d->sizeSpinBox->setDecimals(3);
210  d->sizeSpinBox->setRange(0, 10);
211  d->sizeSpinBox->setSingleStep(0.005);
212  d->sizeSpinBox->setValue(d->line->size());
213 
214  QHBoxLayout *layoutSize = new QHBoxLayout;
215  layoutSize->addWidget(new QLabel("Size",this));
216  layoutSize->addWidget(d->sizeSpinBox);
217 
219  d->colorButton = new dtkColorButton(this);
220 
221  QHBoxLayout *layoutColorButton = new QHBoxLayout;
222  layoutColorButton->addWidget(new QLabel("Color",this));
223  layoutColorButton->addWidget(d->colorButton);
224  d->colorButton->setColor(this->initColorValue());
225 
227  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
228 
229  QHBoxLayout *layoutOpacity = new QHBoxLayout;
230  layoutOpacity->addWidget(new QLabel("Opacity",this));
231  layoutOpacity->addWidget(d->sliderOpacity);
232  d->sliderOpacity->setMaximum(100);
233  d->sliderOpacity->setValue(initOpacityValue());
234 
236  d->comboBoxShader = new QComboBox(this);
237  d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
238 
239  d->checkBoxShader = new QCheckBox(this);
240  d->lineEditShader = new QLineEdit(this);
241  d->buttonShader = new QPushButton(this);
242  d->buttonShader->setText("open");
243 
244  d->lineEditShader->setText(this->initShaderValue());
245  this->initComboBoxShaderValue();
246 
247  if(d->lineEditShader->text().isEmpty())
248  {
249  d->lineEditShader->setEnabled(false);
250  d->buttonShader->setEnabled(false);
251  d->comboBoxShader->setEnabled(false);
252  }
253  else
254  d->checkBoxShader->setChecked(true);
255 
256  QVBoxLayout *layoutShader = new QVBoxLayout;
257  QHBoxLayout *layoutShader1 = new QHBoxLayout;
258 
259  QLabel *labelShader = new QLabel("Shader",this);
260  layoutShader1->addWidget(labelShader);
261  layoutShader1->addWidget(d->checkBoxShader);
262  layoutShader1->addWidget(d->comboBoxShader);
263  layoutShader1->addWidget(d->buttonShader);
264 
265  layoutShader1->setStretchFactor(labelShader, 2);
266  layoutShader1->setStretchFactor(d->checkBoxShader, 1);
267  layoutShader1->setStretchFactor(d->comboBoxShader, 4);
268  layoutShader1->setStretchFactor(d->buttonShader, 3);
269 
270  layoutShader->addLayout(layoutShader1);
271  layoutShader->addWidget(d->lineEditShader);
272 
274  layoutTop->addWidget(new QLabel("First point :",this));
275  layoutTop->addLayout(layoutcoordinateFirst_x);
276  layoutTop->addLayout(layoutcoordinateFirst_y);
277  layoutTop->addLayout(layoutcoordinateFirst_z);
278 
279  layoutTop->addWidget(new QLabel("Second point :",this));
280  layoutTop->addLayout(layoutcoordinateSecond_x);
281  layoutTop->addLayout(layoutcoordinateSecond_y);
282  layoutTop->addLayout(layoutcoordinateSecond_z);
283 
284  layoutTop->addLayout(layoutSize);
285 
286  layoutTop->addLayout(layoutColorButton);
287  layoutTop->addLayout(layoutOpacity);
288  layoutTop->addLayout(layoutShader);
289 
290  QWidget *top = new QWidget(this);
291 
292  top->setLayout(layoutTop);
293  top->setMaximumWidth(295);
294 
295 
296  connect(d->coordinateFirst_x, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedFirst_x(double)));
297  connect(d->coordinateFirst_y, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedFirst_y(double)));
298  connect(d->coordinateFirst_z, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedFirst_z(double)));
299  connect(d->coordinateSecond_x, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedSecond_x(double)));
300  connect(d->coordinateSecond_y, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedSecond_y(double)));
301  connect(d->coordinateSecond_z, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedSecond_z(double)));
302 
303  connect(d->sizeSpinBox, SIGNAL(valueChanged(double)), this, SLOT(onSizeChanged(double)));
304 
305  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
306 
307  connect(d->sliderOpacity, SIGNAL(valueChanged(int)), this, SLOT(onOpacityChanged(int)));
308  connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)), this, SLOT(onLineEditShaderChanged(QString)));
309  connect(d->checkBoxShader, SIGNAL(clicked(bool)), this, SLOT(onShaderStateChanged(bool)));
310  connect(d->buttonShader, SIGNAL(clicked()), this, SLOT(openShader()));
311  connect(d->lineEditShader, SIGNAL(textChanged(QString)), this, SLOT(onShaderChanged(QString)));
312 }
313 
315 {
316  if(d->comboBoxShader) {
317 
318  QStringList filters;
319  filters << "*.vs";
320 
321  // First add item of axlShader.qrc, then find shader from shader path
322  QDir dirShader( ":axlShader/shader/");
323  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
324 
325  dirShader.setNameFilters(filters);
326 
327  QFileInfoList list = dirShader.entryInfoList();
328  // for (int i = 0; i < list.size(); ++i) {
329  // d->comboBoxShader->addItem(list.at(i).fileName());
330  // }
331 
332  QSettings settings("inria", "dtk");
333  QString defaultPath;
334  settings.beginGroup("shader");
335  QString defaultPathShader = settings.value("path", defaultPath).toString();
336  defaultPathShader.append("/");
337 
338  QDir defaultDirShader(defaultPathShader);
339  defaultDirShader.setNameFilters(filters);
340  QFileInfoList list2 = defaultDirShader.entryInfoList();
341 
342  list.append(list2);
343 
344  QStringList items;
345 
346  for (int i = 0; i < list.size(); ++i) {
347  if(!items.contains(list.at(i).fileName()))
348  items << list.at(i).fileName();
349  }
350 
351  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
352  int indInitShader = -1;
353  int indCurrentShader = -1;
354 
355 
356  foreach(QString item, items) {
357  indCurrentShader++;
358  d->comboBoxShader->addItem(item);
359 
360  QFileInfo currentFileInfo(d->lineEditShader->text());
361 
362  if(currentFileInfo.exists()) {
363  if(item == currentFileInfo.fileName())
364  indInitShader =indCurrentShader;
365  }
366  }
367 
368  // init the value from the lineEditShader.
369  if(indInitShader != -1)
370  d->comboBoxShader->setCurrentIndex(indInitShader);
371 
372  }
373 }
374 
376 {
377  // First add item of axlShader.qrc, then find shader from shader path
378  QDir dirShader( ":axlShader/shader/");
379  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
380 
381  QFileInfo currentFile(dirShader, shader);
382  if(!currentFile.exists())
383  {
384  QSettings settings("inria", "dtk");
385  QString defaultPath;
386  settings.beginGroup("shader");
387  QString defaultPathShader = settings.value("path", defaultPath).toString();
388  defaultPathShader.append("/");
389 
390  QDir defaultDirShader(defaultPathShader);
391  currentFile = QFileInfo(defaultDirShader, shader);
392 
393  }
394 
395  d->lineEditShader->setText(currentFile.absoluteFilePath());
396 }
397 
399 {
400  if(d->lineEditShader->isEnabled())
401  {
402  QString fileToOpen;
403  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("vs file (*.vs)"));
404  d->lineEditShader->setText(fileToOpen);
405  }
406 }
407 
409 {
410  d->line->setShader(shader);
411 
412 // emit dataChangedByShader(d->line, d->lineEditShader->text());
413 // emit modifiedProperty(d->line, 2);
414  d->line->touchProperty();
415 // emit update();
416 }
417 
419 {
420  if(isShader)
421  {
422  d->comboBoxShader->setEnabled(true);
423  d->lineEditShader->setEnabled(true);
424  d->buttonShader->setEnabled(true);
425  onLineEditShaderChanged(d->comboBoxShader->currentText());
426 
427 // emit dataChangedByShader(d->line, d->lineEditShader->text());
428  }
429  else
430  {
431  d->comboBoxShader->setEnabled(false);
432  d->lineEditShader->setEnabled(false);
433  d->buttonShader->setEnabled(false);
434 
435  d->line->setShader("");
436 // emit dataChangedByShader(d->line, "");
437  }
438 
439 // emit modifiedProperty(d->line, 2);
440  d->line->touchProperty();
441 // emit update();
442 }
443 
445 {
446 
447  if(d->line->parent()){
448  axlDataDynamic *dynamicLine = dynamic_cast<axlDataDynamic *>(d->line->parent());
449  axlPoint *point1 = dynamic_cast<axlPoint *>(dynamicLine->inputs().at(0));
450  point1->x() = x;
451  point1->touchGeometry();
452  }else{
453  d->line->firstPoint()->x() = x;
454  }
455 
456  d->line->touchGeometry();
457 // emit update();
458 }
459 
461 {
462  if(d->line->parent()){
463  axlDataDynamic *dynamicLine = dynamic_cast<axlDataDynamic *>(d->line->parent());
464  axlPoint *point1 = dynamic_cast<axlPoint *>(dynamicLine->inputs().at(0));
465  point1->y() = y;
466  point1->touchGeometry();
467  }else{
468  d->line->firstPoint()->y() = y;
469  }
470 
471  d->line->touchGeometry();
472 // emit update();
473 }
474 
476 {
477  if(d->line->parent()){
478  axlDataDynamic *dynamicLine = dynamic_cast<axlDataDynamic *>(d->line->parent());
479  axlPoint *point1 = dynamic_cast<axlPoint *>(dynamicLine->inputs().at(0));
480  point1->z() = z;
481  point1->touchGeometry();
482  }else{
483  d->line->firstPoint()->z() = z;
484  }
485 
486  d->line->touchGeometry();
487 // emit update();
488 }
489 
490 
492 {
493  if(d->line->parent()){
494  axlDataDynamic *dynamicLine = dynamic_cast<axlDataDynamic *>(d->line->parent());
495  axlPoint *point2 = dynamic_cast<axlPoint *>(dynamicLine->inputs().at(1));
496  point2->x() = x;
497  point2->touchGeometry();
498  }else{
499  d->line->secondPoint()->x() = x;
500  }
501 
502  d->line->touchGeometry();
503 // emit update();
504 }
505 
507 {
508  if(d->line->parent()){
509  axlDataDynamic *dynamicLine = dynamic_cast<axlDataDynamic *>(d->line->parent());
510  axlPoint *point2 = dynamic_cast<axlPoint *>(dynamicLine->inputs().at(1));
511  point2->y() = y;
512  point2->touchGeometry();
513  }else{
514  d->line->secondPoint()->y() = y;
515  }
516 
517  d->line->touchGeometry();
518 // emit update();
519 }
520 
522 {
523  if(d->line->parent()){
524  axlDataDynamic *dynamicLine = dynamic_cast<axlDataDynamic *>(d->line->parent());
525  axlPoint *point2 = dynamic_cast<axlPoint *>(dynamicLine->inputs().at(1));
526  point2->z() = z;
527  point2->touchGeometry();
528  }else{
529  d->line->secondPoint()->z() = z;
530  }
531 
532  d->line->touchGeometry();
533 // emit update();
534 }
535 
537 {
538  QVariant variant = d->line->QObject::property("color");
539  if(variant.isValid())
540  {
541  d->line->setColor(color);
542 
543 // emit dataChangedByColor(d->line, color.redF(), color.greenF(), color.blueF());
544 // emit modifiedProperty(d->line, 0);
545  d->line->touchProperty();
546  }
547 
548 // emit update();
549 }
550 
551 
552 //void axlInspectorObjectLine::onSizeChanged(int size)
553 //{
554 // double size_d = pow(2.0, size/100.0 - 3.0);
555 // QVariant variant = d->line->QObject::property("size");
556 // if(variant.isValid())
557 // {
558 // d->line->setSize(size_d);
559 // //emit dataChangedByGeometry(d->line);
560 // emit modifiedProperty(d->line, 3);
561 // }
562 //
563 // emit update();
564 //}
565 
567 {
568  d->line->setSize(size);
569 
570 // emit modifiedProperty(d->line, 3);
571 // emit update();
572  d->line->touchGeometry();
573 }
574 
576 {
577  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
578 
579  QVariant variant = d->line->QObject::property("opacity");
580  if(variant.isValid())
581  {
582  d->line->setOpacity(opacity_d);
583 
584 // emit dataChangedByOpacity(d->line, opacity_d);
585 // emit modifiedProperty(d->line, 1);
586  d->line->touchProperty();
587  }
588 
589 // emit update();
590 }
591 
593 {
594 // this->blockSignals(true);
595  const QSignalBlocker blockerFirstX(d->coordinateFirst_x);
596  const QSignalBlocker blockerFirstY(d->coordinateFirst_y);
597  const QSignalBlocker blockerFirstZ(d->coordinateFirst_z);
598  const QSignalBlocker blockerSecondX(d->coordinateSecond_x);
599  const QSignalBlocker blockerSecondY(d->coordinateSecond_y);
600  const QSignalBlocker blockerSecondZ(d->coordinateSecond_z);
601 
602  d->coordinateFirst_x->setValue(d->line->firstPoint()->x());
603  d->coordinateFirst_y->setValue(d->line->firstPoint()->y());
604  d->coordinateFirst_z->setValue(d->line->firstPoint()->z());
605 
606  d->coordinateSecond_x->setValue(d->line->secondPoint()->x());
607  d->coordinateSecond_y->setValue(d->line->secondPoint()->y());
608  d->coordinateSecond_z->setValue(d->line->secondPoint()->z());
609 // this->blockSignals(false);
610 }
void touchGeometry(void)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
Class axlLine defines 3D lines.
Definition: axlLine.h:35
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void onShaderStateChanged(bool isShader)
Class axlDataDynamic defines a dynamic object.
double y
Definition: axlPoint.h:37
QList< axlAbstractData * > inputs(void)
Return input list;.
double z
Definition: axlPoint.h:38
axlInspectorObjectLine(QWidget *parent=0)
double x
Definition: axlPoint.h:37
void setData(axlLine *point)