Developer documentation | Axl-2.5.1

axlInspectorObjectSet.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectSet.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 "axlInspectorObjectSet.h"
21 
25 #include <axlCore/axlMesh.h>
26 
28 
29 #include <dtkCoreSupport/dtkAbstractData.h>
30 
31 #include <dtkGuiSupport/dtkColorButton.h>
32 #include <dtkGuiSupport/dtkSplitter.h>
33 
34 #include <QtGui>
35 
36 class axlInspectorObjectSetPrivate
37 {
38 public:
39  QList<dtkAbstractData *> dataSet;
40 
41  QSpinBox *spinBoxSampling_u;
42  QSpinBox *spinBoxSampling_v;
43 
44  QSlider *sliderSize;
45 
46  dtkColorButton *colorButton;
47  QComboBox *comboBoxShader;
48 
49  QCheckBox *checkBoxShader;
50  QLineEdit *lineEditShader;
51  QPushButton *buttonShader;
52 
53  QSlider *sliderOpacity;
54 
55  bool tagSpinBoxSampling_u;
56  bool tagSpinBoxSampling_v;
57  bool tagSizeSlider;
58  bool tagColorButton;
59  bool tagOpacitySlider;
60  bool tagCheckBoxShader;
61 };
62 
63 axlInspectorObjectSet::axlInspectorObjectSet(QWidget *parent) : QFrame(parent), d(new axlInspectorObjectSetPrivate)
64 {
65  d->spinBoxSampling_u = NULL;
66  d->spinBoxSampling_v = NULL;
67 
68  d->sliderSize = NULL;
69 
70  d->colorButton = NULL;
71  d->comboBoxShader = NULL;
72 
73  d->checkBoxShader = NULL;
74  d->lineEditShader = NULL;
75  d->buttonShader = NULL;
76 
77  d->sliderOpacity = NULL;
78 
79  d->tagSpinBoxSampling_u = true;
80  d->tagSpinBoxSampling_v = true;
81  d->tagSizeSlider = true;
82  d->tagColorButton = true;
83  d->tagCheckBoxShader = true;
84  d->tagOpacitySlider = true;
85 }
86 
88 {
89  delete d;
90 
91  d = NULL;
92 }
93 
95 {
96  return QSize(300, 300);
97 }
98 
99 void axlInspectorObjectSet::setData(QList<dtkAbstractData *> dataSet)
100 {
101  d->dataSet = dataSet;
102  initTag();
103  initWidget();
104 }
105 
106 void axlInspectorObjectSet::initTag()
107 {
108  foreach(dtkAbstractData *data, d->dataSet)
109  {
110  if (dynamic_cast<axlAbstractSurfaceBSpline *>(data))
111  {
112 
113  }
114  else if (dynamic_cast<axlAbstractCurveBSpline *>(data))
115  {
116  d->tagSpinBoxSampling_v = false;
117  }
118  else
119  {
120  d->tagSpinBoxSampling_u = false;
121  d->tagSpinBoxSampling_v = false;
122  }
123  }
124 }
125 
126 void axlInspectorObjectSet::initWidget()
127 {
128 
129  QVBoxLayout *layoutTop = new QVBoxLayout;
130  layoutTop->addWidget(new QLabel("axlInspectorObjectSet", this));
131 
132  if( d->tagSpinBoxSampling_u)
133  {
134  d->spinBoxSampling_u = new QSpinBox(this);
135  d->spinBoxSampling_u->setMaximum(10000);
136  d->spinBoxSampling_u->setMinimum(1);
137  d->spinBoxSampling_u->setValue(40);
138 
139  QHBoxLayout *layoutSampling_u = new QHBoxLayout;
140  layoutSampling_u->addWidget(new QLabel("Sampling U",this));
141  layoutSampling_u->addWidget(d->spinBoxSampling_u);
142 
143  layoutTop->addLayout(layoutSampling_u);
144 
145  connect(d->spinBoxSampling_u, SIGNAL(valueChanged(int)), this, SLOT(onSamplingDataChanged_u(int)));
146 
147  }
148 
149  if(d->tagSpinBoxSampling_v)
150  {
151  d->spinBoxSampling_v = new QSpinBox(this);
152  d->spinBoxSampling_v->setMaximum(10000);
153  d->spinBoxSampling_v->setMinimum(1);
154  d->spinBoxSampling_v->setValue(40);
155 
156  QHBoxLayout *layoutSampling_v = new QHBoxLayout;
157  layoutSampling_v->addWidget(new QLabel("Sampling V",this));
158  layoutSampling_v->addWidget(d->spinBoxSampling_v);
159 
160  layoutTop->addLayout(layoutSampling_v);
161 
162  connect(d->spinBoxSampling_v, SIGNAL(valueChanged(int)), this, SLOT(onSamplingDataChanged_v(int)));
163 
164 
165  }
166 
167  if(d->tagSizeSlider)
168  {
169  d->sliderSize = new QSlider(Qt::Horizontal, this);
170 
171  QHBoxLayout *layoutSize = new QHBoxLayout;
172  layoutSize->addWidget(new QLabel("Size",this));
173  layoutSize->addWidget(d->sliderSize);
174  d->sliderSize->setMinimum(-800);
175  d->sliderSize->setMaximum(500);
176  d->sliderSize->setValue(initSizeValue());
177 
178  layoutTop->addLayout(layoutSize);
179 
180  connect(d->sliderSize, SIGNAL(valueChanged(int)), this, SLOT(onSizeChanged(int)));
181 
182  }
183 
184 
185  if(d->tagColorButton)
186  {
187  d->colorButton = new dtkColorButton(this);
188 
189  QHBoxLayout *layoutColorButton = new QHBoxLayout;
190  layoutColorButton->addWidget(new QLabel("Color",this));
191  layoutColorButton->addWidget(d->colorButton);
192 
193  layoutTop->addLayout(layoutColorButton);
194 
195  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
196 
197  }
198 
199  if(d->tagOpacitySlider)
200  {
201  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
202 
203  QHBoxLayout *layoutOpacity = new QHBoxLayout;
204  layoutOpacity->addWidget(new QLabel("Opacity",this));
205  layoutOpacity->addWidget(d->sliderOpacity);
206  d->sliderOpacity->setMaximum(100);
207  d->sliderOpacity->setValue(initOpacityValue());
208 
209  layoutTop->addLayout(layoutOpacity);
210 
211  connect(d->sliderOpacity, SIGNAL(valueChanged(int)), this, SLOT(onOpacityChanged(int)));
212 
213  }
214 
215  if(d->tagCheckBoxShader)
216  {
217  d->comboBoxShader = new QComboBox(this);
218  d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
219  d->checkBoxShader = new QCheckBox(this);
220  d->lineEditShader = new QLineEdit(this);
221  d->buttonShader = new QPushButton(this);
222  d->buttonShader->setText("open");
223  this->initComboBoxShaderValue();
224 
225  connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)), this, SLOT(onLineEditShaderChanged(QString)));
226  connect(d->checkBoxShader, SIGNAL(clicked(bool)), this, SLOT(onShaderStateChanged(bool)));
227  connect(d->buttonShader, SIGNAL(clicked()), this, SLOT(openShader()));
228  connect(d->lineEditShader, SIGNAL(textChanged(QString)), this, SLOT(onShaderChanged(QString)));
229 
230 
231  d->lineEditShader->setEnabled(false);
232  d->buttonShader->setEnabled(false);
233  d->comboBoxShader->setEnabled(false);
234 
235 
236 
237  QVBoxLayout *layoutShader = new QVBoxLayout;
238  QHBoxLayout *layoutShader1 = new QHBoxLayout;
239 
240  QLabel *labelShader = new QLabel("Shader",this);
241  layoutShader1->addWidget(labelShader);
242  layoutShader1->addWidget(d->checkBoxShader);
243  layoutShader1->addWidget(d->comboBoxShader);
244  layoutShader1->addWidget(d->buttonShader);
245 
246  layoutShader1->setStretchFactor(labelShader, 2);
247  layoutShader1->setStretchFactor(d->checkBoxShader, 1);
248  layoutShader1->setStretchFactor(d->comboBoxShader, 4);
249  layoutShader1->setStretchFactor(d->buttonShader, 3);
250 
251  layoutShader->addLayout(layoutShader1);
252  layoutShader->addWidget(d->lineEditShader);
253 
254  layoutTop->addLayout(layoutShader);
255  }
256 
257  layoutTop->addStretch(1);
258 
259  QWidget *top = new QWidget(this);
260  top->setMaximumWidth(295);
261 
262  top->setLayout(layoutTop);
263 
264  dtkSplitter *splitter = new dtkSplitter(this, true);
265  splitter->setOrientation(Qt::Vertical);
266  splitter->addWidget(top);
267 
268  QVBoxLayout *layout = new QVBoxLayout(this);
269  layout->setContentsMargins(0, 0, 0, 0);
270  layout->setSpacing(0);
271  layout->addWidget(splitter);
272 
273 }
274 
275 int axlInspectorObjectSet::initSizeValue()
276 {
277  double initSize = 0.0;
278  foreach(dtkAbstractData *data, d->dataSet)
279  {
280 
281  if (axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data))
282  {
283  double size = axlData->size();
284  if(size > initSize)
285  initSize = size;
286  }
287 
288  }// we have the hight opacity.
289 
290  return 100.0 * (log(initSize / 0.125)) / log(2.0);
291 }
292 
293 int axlInspectorObjectSet::initOpacityValue()
294 {
295  double initOpacity = 0.0;
296  foreach(dtkAbstractData *data, d->dataSet)
297  {
298 
299  if (axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data))
300  {
301  double opacity = axlData->opacity();
302  if(opacity > initOpacity)
303  initOpacity = opacity;
304  }
305 
306  }// we have the hight opacity.
307 
308  return 100 * (1.0 - initOpacity);
309 }
310 
311 void axlInspectorObjectSet::initComboBoxShaderValue(void)
312 {
313  if(d->comboBoxShader)
314  {
315  // First add item of axlShader.qrc, then find shader from shader path
316  QDir dirShader( ":axlShader/shader/");
317  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
318 
319  QFileInfoList list = dirShader.entryInfoList();
320  // for (int i = 0; i < list.size(); ++i) {
321  // d->comboBoxShader->addItem(list.at(i).fileName());
322  // }
323 
324  QSettings settings("inria", "dtk");
325  QString defaultPath;
326  settings.beginGroup("shader");
327  QString defaultPathShader = settings.value("path", defaultPath).toString();
328  defaultPathShader.append("/");
329 
330  QDir defaultDirShader(defaultPathShader);
331  QStringList filters;
332  filters << "*.xml";
333  defaultDirShader.setNameFilters(filters);
334  QFileInfoList list2 = defaultDirShader.entryInfoList();
335 
336  list.append(list2);
337 
338  QStringList items;
339 
340  for (int i = 0; i < list.size(); ++i) {
341  if(!items.contains(list.at(i).fileName()))
342  items << list.at(i).fileName();
343  }
344 
345  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
346  int indInitShader = -1;
347  int indCurrentShader = -1;
348 
349 
350  foreach(QString item, items)
351  {
352  indCurrentShader++;
353  d->comboBoxShader->addItem(item);
354 
355  QFileInfo currentFileInfo(d->lineEditShader->text());
356 
357  if(currentFileInfo.exists())
358  {
359  if(item == currentFileInfo.fileName())
360  indInitShader =indCurrentShader;
361  }
362  }
363 
364  //init the value from the lineEditShader.
365  if(indInitShader != -1)
366  d->comboBoxShader->setCurrentIndex(indInitShader);
367 
368  }
369 }
370 
372 {
373  // First add item of axlShader.qrc, then find shader from shader path
374  QDir dirShader( ":axlShader/shader/");
375  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
376 
377  QFileInfo currentFile(dirShader, shader);
378  if(!currentFile.exists())
379  {
380  QSettings settings("inria", "dtk");
381  QString defaultPath;
382  settings.beginGroup("shader");
383  QString defaultPathShader = settings.value("path", defaultPath).toString();
384  defaultPathShader.append("/");
385 
386  QDir defaultDirShader(defaultPathShader);
387  currentFile = QFileInfo(defaultDirShader, shader);
388 
389  }
390 
391  d->lineEditShader->setText(currentFile.absoluteFilePath());
392 }
393 
395 {
396  if(d->lineEditShader->isEnabled())
397  {
398  QString fileToOpen;
399  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("xml document (*.xml)"));
400  d->lineEditShader->setText(fileToOpen);
401  }
402 }
403 
405 {
406  foreach(dtkAbstractData *data, d->dataSet)
407  {
408  if (axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data))
409  {
410  QVariant variant = axlData->QObject::property("shader");
411  if(variant.isValid())
412  axlData->setShader(shader);
413  }
414 
415 // emit dataChangedByShader(data, d->lineEditShader->text());
416  emit modifiedProperty(data, 2);
417  }
418 
419 // emit update();
420 }
421 
423 {
424  if(isShader)
425  {
426  d->comboBoxShader->setEnabled(true);
427  d->lineEditShader->setEnabled(true);
428  d->buttonShader->setEnabled(true);
429  }
430  else
431  {
432  d->comboBoxShader->setEnabled(false);
433  d->lineEditShader->setEnabled(false);
434  d->buttonShader->setEnabled(false);
435  }
436 }
437 
439 {
440  foreach(dtkAbstractData *data, d->dataSet)
441  {
442  if (axlAbstractCurveBSpline *spline_curve = dynamic_cast<axlAbstractCurveBSpline *>(data))
443  {
444  spline_curve->setNumSamples(numSamples);
445  }
446 
447  else if (axlAbstractSurfaceBSpline *spline_surface = dynamic_cast<axlAbstractSurfaceBSpline *>(data))
448  {
449  spline_surface->setNumSamples_u(numSamples);
450  }
451  }
452 
453  emit update();
454 }
455 
457 {
458  foreach(dtkAbstractData *data, d->dataSet)
459  {
460  if (axlAbstractSurfaceBSpline *spline_surface = dynamic_cast<axlAbstractSurfaceBSpline *>(data))
461  {
462  spline_surface->setNumSamples_v(numSamples);
463  }
464  }
465 
466  emit update();
467 }
468 
470 {
471  double size_d = pow(2.0, size / 100.0 - 3.0);
472 
473  foreach(dtkAbstractData *data, d->dataSet)
474  {
475  if (axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data))
476  {
477  QVariant variant = data->QObject::property("size");
478  if(variant.isValid())
479  axlData->setSize(size_d);
480  }
481 
482 // emit dataChangedByGeometry(data);
483 // // emit dataChangedBySize(data, size_d);
484  emit modifiedProperty(data,3);
485 
486  }
487 
488 // emit update();
489 }
490 
492 {
493  foreach(dtkAbstractData *data, d->dataSet)
494  {
495  if (axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data))
496  {
497  QVariant variant = data->QObject::property("color");
498  if(variant.isValid())
499  axlData->setColor(color);
500  }
501 
502 
503 // emit dataChangedByColor(data, color.redF(), color.greenF(), color.blueF());
504  emit modifiedProperty(data, 0);
505  }
506 
507 // emit update();
508 }
509 
511 {
512  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
513 
514  foreach(dtkAbstractData *data, d->dataSet)
515  {
516  if (axlAbstractData *axlData = dynamic_cast<axlAbstractData *>(data))
517  {
518  QVariant variant = axlData->QObject::property("opacity");
519  if(variant.isValid())
520  axlData->setOpacity(opacity_d);
521  }
522 // emit dataChangedByOpacity(data, opacity_d);
523  emit modifiedProperty(data, 1);
524  }
525 
526 // emit update();
527 }
528 
529 
530 
531 
void onSamplingDataChanged_v(int numSamples)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void setData(QList< dtkAbstractData * > dataSet)
void onOpacityChanged(int opacity)
void onShaderStateChanged(bool isShader)
void modifiedProperty(dtkAbstractData *, int)
void onSamplingDataChanged_u(int numSamples)
axlInspectorObjectSet(QWidget *parent=0)
void colorChanged(QColor color, dtkAbstractData *data)
void onColorChanged(QColor color)
Class axlAbstractData defines an API for all type of axel data.