Developer documentation | Axl-2.5.1

axlInspectorObjectTorus.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectTorus.cpp ---
2  *
3  * Author: Valntin Michelet
4  * Copyright (C) 2008 - Valntin Michelet, Inria.
5  * Created: Tue Nov 9 16:58:59 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Nov 9 17:09:38 2010 (+0100)
8  * By: Valntin Michelet
9  * Update #: 19
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 
22 #include <axlCore/axlTorus.h>
23 #include <axlCore/axlPoint.h>
25 
26 #include <dtkGuiSupport/dtkColorButton.h>
27 #include <dtkGuiSupport/dtkSplitter.h>
28 
29 #include <QtGui>
30 
31 class axlInspectorObjectTorusPrivate {
32 public:
33  axlTorus* torus;
34 
35  QDoubleSpinBox* coordinateCenter_x;
36  QDoubleSpinBox* coordinateCenter_y;
37  QDoubleSpinBox* coordinateCenter_z;
38 
39  QDoubleSpinBox* coordinateDirection_x;
40  QDoubleSpinBox* coordinateDirection_y;
41  QDoubleSpinBox* coordinateDirection_z;
42 
43  QDoubleSpinBox* ringRadius;
44  QDoubleSpinBox* crossSectionRadius;
45 
46  dtkColorButton *colorButton;
47 
48  QComboBox *comboBoxShader;
49 
50  QCheckBox* checkBoxShader;
51  QLineEdit* lineEditShader;
52  QPushButton* buttonShader;
53 
54  QSlider* sliderOpacity;
55 };
56 
58  QFrame(parent),
59  d(new axlInspectorObjectTorusPrivate) {
60 
61  d->coordinateCenter_x = NULL;
62  d->coordinateCenter_y = NULL;
63  d->coordinateCenter_z = NULL;
64 
65  d->coordinateDirection_x = NULL;
66  d->coordinateDirection_y = NULL;
67  d->coordinateDirection_z = NULL;
68 
69  d->ringRadius = NULL;
70  d->crossSectionRadius = NULL;
71 
72  d->colorButton = NULL;
73 
74  d->comboBoxShader = NULL;
75 
76  d->checkBoxShader = NULL;
77  d->lineEditShader = NULL;
78  d->buttonShader = NULL;
79 
80  d->sliderOpacity = NULL;
81 }
82 
84  delete d;
85  d = NULL;
86 }
87 
89  return QSize(300, 300);
90 }
91 
93  d->torus = torus;
94  connect(d->torus, SIGNAL(modifiedGeometry(void)), this, SLOT( updateValues(void)));
95  initWidget();
96 }
97 
98 void axlInspectorObjectTorus::initWidget(void) {
99 
100  QVBoxLayout *layoutTop = new QVBoxLayout(this);
101  layoutTop->addWidget(new QLabel("axlInspectorObjectTorus", this));
102 
103  //CENTER//
104  d->coordinateCenter_x = new QDoubleSpinBox(this);
105  d->coordinateCenter_x->setRange(-1000, 1000);
106  d->coordinateCenter_x->setValue(d->torus->centerPoint()->x());
107  d->coordinateCenter_x->setSingleStep(0.1);
108 
109  QHBoxLayout *layoutCenter_x = new QHBoxLayout;
110  layoutCenter_x->addWidget(new QLabel("X",this));
111  layoutCenter_x->addWidget(d->coordinateCenter_x);
112 
113  d->coordinateCenter_y = new QDoubleSpinBox(this);
114  d->coordinateCenter_y->setRange(-1000, 1000);
115  d->coordinateCenter_y->setValue(d->torus->centerPoint()->y());
116  d->coordinateCenter_y->setSingleStep(0.1);
117 
118  QHBoxLayout *layoutCenter_y = new QHBoxLayout;
119  layoutCenter_y->addWidget(new QLabel("Y",this));
120  layoutCenter_y->addWidget(d->coordinateCenter_y);
121 
122  d->coordinateCenter_z = new QDoubleSpinBox(this);
123  d->coordinateCenter_z->setRange(-1000, 1000);
124  d->coordinateCenter_z->setValue(d->torus->centerPoint()->z());
125  d->coordinateCenter_z->setSingleStep(0.1);
126 
127  QHBoxLayout *layoutCenter_z = new QHBoxLayout;
128  layoutCenter_z->addWidget(new QLabel("Z",this));
129  layoutCenter_z->addWidget(d->coordinateCenter_z);
130 
131  //DIRECTION//
132  d->coordinateDirection_x = new QDoubleSpinBox(this);
133  d->coordinateDirection_x->setRange(-1000, 1000);
134  d->coordinateDirection_x->setValue(d->torus->direction()->x());
135  d->coordinateDirection_x->setSingleStep(0.1);
136 
137  QHBoxLayout *layoutDirection_x = new QHBoxLayout;
138  layoutDirection_x->addWidget(new QLabel("X",this));
139  layoutDirection_x->addWidget(d->coordinateDirection_x);
140 
141  d->coordinateDirection_y = new QDoubleSpinBox(this);
142  d->coordinateDirection_y->setRange(-1000, 1000);
143  d->coordinateDirection_y->setValue(d->torus->direction()->y());
144  d->coordinateDirection_y->setSingleStep(0.1);
145 
146  QHBoxLayout *layoutDirection_y = new QHBoxLayout;
147  layoutDirection_y->addWidget(new QLabel("Y",this));
148  layoutDirection_y->addWidget(d->coordinateDirection_y);
149 
150  d->coordinateDirection_z = new QDoubleSpinBox(this);
151  d->coordinateDirection_z->setRange(-1000, 1000);
152  d->coordinateDirection_z->setValue(d->torus->direction()->z());
153  d->coordinateDirection_z->setSingleStep(0.1);
154 
155  QHBoxLayout *layoutDirection_z = new QHBoxLayout;
156  layoutDirection_z->addWidget(new QLabel("Z",this));
157  layoutDirection_z->addWidget(d->coordinateDirection_z);
158 
159  //RING RADIUS//
160  d->ringRadius = new QDoubleSpinBox(this);
161  d->ringRadius->setValue(d->torus->ringRadius());
162  d->ringRadius->setSingleStep(0.1);
163 
164  QHBoxLayout *layoutRingRadius = new QHBoxLayout;
165  layoutRingRadius->addWidget(new QLabel("Ring Radius",this));
166  layoutRingRadius->addWidget(d->ringRadius);
167  d->ringRadius->setValue(d->torus->ringRadius());
168 
169  //CROSS SECTION RADIUS//
170  d->crossSectionRadius = new QDoubleSpinBox(this);
171  d->crossSectionRadius->setValue(d->torus->crossSectionRadius());
172  d->crossSectionRadius->setSingleStep(0.1);
173 
174  QHBoxLayout *layoutCrossSectionRadius = new QHBoxLayout;
175  layoutCrossSectionRadius->addWidget(new QLabel("Cross Section Radius",this));
176  layoutCrossSectionRadius->addWidget(d->crossSectionRadius);
177  d->crossSectionRadius->setValue(d->torus->crossSectionRadius());
178 
180  d->colorButton = new dtkColorButton(this);
181 
182  QHBoxLayout *layoutColorButton = new QHBoxLayout;
183  layoutColorButton->addWidget(new QLabel("Color",this));
184  layoutColorButton->addWidget(d->colorButton);
185  d->colorButton->setColor(this->initColorValue());
186 
188  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
189 
190  QHBoxLayout *layoutOpacity = new QHBoxLayout;
191  layoutOpacity->addWidget(new QLabel("Opacity",this));
192  layoutOpacity->addWidget(d->sliderOpacity);
193  d->sliderOpacity->setMaximum(100);
194  d->sliderOpacity->setValue(initOpacityValue());
195 
197  d->comboBoxShader = new QComboBox(this);
198  d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
199 
200  d->checkBoxShader = new QCheckBox(this);
201  d->lineEditShader = new QLineEdit(this);
202  d->buttonShader = new QPushButton(this);
203  d->buttonShader->setText("open");
204 
205  d->lineEditShader->setText(this->initShaderValue());
206  this->initComboBoxShaderValue();
207 
208  if(d->lineEditShader->text().isEmpty())
209  {
210  d->lineEditShader->setEnabled(false);
211  d->buttonShader->setEnabled(false);
212  d->comboBoxShader->setEnabled(false);
213  }
214  else
215  d->checkBoxShader->setChecked(true);
216 
218  QVBoxLayout *layoutShader = new QVBoxLayout;
219  QHBoxLayout *layoutShader1 = new QHBoxLayout;
220 
221  QLabel *labelShader = new QLabel("Shader",this);
222  layoutShader1->addWidget(labelShader);
223  layoutShader1->addWidget(d->checkBoxShader);
224  layoutShader1->addWidget(d->comboBoxShader);
225  layoutShader1->addWidget(d->buttonShader);
226 
227  layoutShader1->setStretchFactor(labelShader, 2);
228  layoutShader1->setStretchFactor(d->checkBoxShader, 1);
229  layoutShader1->setStretchFactor(d->comboBoxShader, 4);
230  layoutShader1->setStretchFactor(d->buttonShader, 3);
231 
232  layoutShader->addLayout(layoutShader1);
233  layoutShader->addWidget(d->lineEditShader);
234 
235 
236  layoutTop->addWidget(new QLabel("Center:",this));
237  layoutTop->addLayout(layoutCenter_x);
238  layoutTop->addLayout(layoutCenter_y);
239  layoutTop->addLayout(layoutCenter_z);
240 
241  layoutTop->addWidget(new QLabel("Second point to create direction:",this));
242  layoutTop->addLayout(layoutDirection_x);
243  layoutTop->addLayout(layoutDirection_y);
244  layoutTop->addLayout(layoutDirection_z);
245 
246  layoutTop->addLayout(layoutRingRadius);
247  layoutTop->addLayout(layoutCrossSectionRadius);
248 
249  layoutTop->addLayout(layoutColorButton);
250  layoutTop->addLayout(layoutOpacity);
251  layoutTop->addLayout(layoutShader);
252 
253  QWidget *top = new QWidget(this);
254  top->setLayout(layoutTop);
255  top->setMaximumWidth(295);
256 
257  dtkSplitter *splitter = new dtkSplitter(this, true);
258  splitter->setOrientation(Qt::Vertical);
259  splitter->addWidget(top);
260 
261  QVBoxLayout *layout = new QVBoxLayout(this);
262  layout->setContentsMargins(0, 0, 0, 0);
263  layout->setSpacing(0);
264  layout->addWidget(splitter);
265 
266  connect(d->coordinateCenter_x, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedCenter_x(double)));
267  connect(d->coordinateCenter_y, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedCenter_y(double)));
268  connect(d->coordinateCenter_z, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedCenter_z(double)));
269 
270  connect(d->coordinateDirection_x, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedDirection_x(double)));
271  connect(d->coordinateDirection_y, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedDirection_y(double)));
272  connect(d->coordinateDirection_z, SIGNAL(valueChanged(double)), this, SLOT(onCoordDataChangedDirection_z(double)));
273 
274  connect(d->ringRadius, SIGNAL(valueChanged(double)), this, SLOT(onRingRadiusChanged(double)));
275  connect(d->crossSectionRadius, SIGNAL(valueChanged(double)), this, SLOT(onCrossSectionRadiusChanged(double)));
276 
277  connect(d->colorButton, SIGNAL(colorChanged(QColor)), this, SLOT(onColorChanged(QColor)));
278 
279  connect(d->sliderOpacity, SIGNAL(valueChanged(int)), this, SLOT(onOpacityChanged(int)));
280  connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)), this, SLOT(onLineEditShaderChanged(QString)));
281  connect(d->checkBoxShader, SIGNAL(clicked(bool)), this, SLOT(onShaderStateChanged(bool)));
282  connect(d->buttonShader, SIGNAL(clicked()), this, SLOT(openShader()));
283  connect(d->lineEditShader, SIGNAL(textChanged(QString)), this, SLOT(onShaderChanged(QString)));
284 }
285 
286 QString axlInspectorObjectTorus::initShaderValue(void) {
287  return d->torus->shader();
288 }
289 
290 QColor axlInspectorObjectTorus::initColorValue(void) {
291  return d->torus->color();
292 }
293 
294 int axlInspectorObjectTorus::initOpacityValue(void) {
295  double initOpacity = 0.0;
296  double opacity = d->torus->opacity();
297  if(opacity > initOpacity)
298  initOpacity = opacity;
299 
300  return 100 * (1.0 - initOpacity);
301 }
302 
304  if(d->lineEditShader->isEnabled()) {
305  QString fileToOpen;
306  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("xml document (*.xml)"));
307  d->lineEditShader->setText(fileToOpen);
308  }
309 }
310 
312  d->torus->setShader(shader);
313 // emit dataChangedByShader(d->torus, d->lineEditShader->text());
314 // emit modifiedProperty(d->torus, 2);
315  d->torus->touchProperty();
316 // emit update();
317 }
318 
320  if(isShader) {
321  d->comboBoxShader->setEnabled(true);
322  d->lineEditShader->setEnabled(true);
323  d->buttonShader->setEnabled(true);
324  onLineEditShaderChanged(d->comboBoxShader->currentText());
325 
326 // emit dataChangedByShader(d->torus, d->lineEditShader->text());
327  } else {
328  d->comboBoxShader->setEnabled(false);
329  d->lineEditShader->setEnabled(false);
330  d->buttonShader->setEnabled(false);
331 
332  d->torus->setShader("");
333 // emit dataChangedByShader(d->torus, "");
334  }
335 
336 // emit modifiedProperty(d->torus, 2);
337  d->torus->touchProperty();
338 // emit update();
339 }
340 
341 void axlInspectorObjectTorus::initComboBoxShaderValue(void) {
342  if(d->comboBoxShader) {
343  // First add item of axlShader.qrc, then find shader from shader path
344  QDir dirShader( ":axlShader/shader/");
345  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
346 
347  QFileInfoList list = dirShader.entryInfoList();
348  // for (int i = 0; i < list.size(); ++i) {
349  // d->comboBoxShader->addItem(list.at(i).fileName());
350  // }
351 
352  QSettings settings("inria", "dtk");
353  QString defaultPath;
354  settings.beginGroup("shader");
355  QString defaultPathShader = settings.value("path", defaultPath).toString();
356  defaultPathShader.append("/");
357 
358  QDir defaultDirShader(defaultPathShader);
359  QStringList filters;
360  filters << "*.xml";
361  defaultDirShader.setNameFilters(filters);
362  QFileInfoList list2 = defaultDirShader.entryInfoList();
363 
364  list.append(list2);
365 
366  QStringList items;
367 
368  for (int i = 0; i < list.size(); ++i) {
369  if(!items.contains(list.at(i).fileName()))
370  items << list.at(i).fileName();
371  }
372 
373  qSort(items.begin(), items.end(), caseInsensitiveLessThan);
374  int indInitShader = -1;
375  int indCurrentShader = -1;
376 
377 
378  foreach(QString item, items) {
379  indCurrentShader++;
380  d->comboBoxShader->addItem(item);
381 
382  QFileInfo currentFileInfo(d->lineEditShader->text());
383 
384  if(currentFileInfo.exists()) {
385  if(item == currentFileInfo.fileName())
386  indInitShader = indCurrentShader;
387  }
388  }
389 
390  //init the value from the lineEditShader.
391  if(indInitShader != -1)
392  d->comboBoxShader->setCurrentIndex(indInitShader);
393  }
394 }
395 
397  // First add item of axlShader.qrc, then find shader from shader path
398  QDir dirShader( ":axlShader/shader/");
399  dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
400 
401  QFileInfo currentFile(dirShader, shader);
402  if(!currentFile.exists()) {
403  QSettings settings("inria", "dtk");
404  QString defaultPath;
405  settings.beginGroup("shader");
406  QString defaultPathShader = settings.value("path", defaultPath).toString();
407  defaultPathShader.append("/");
408 
409  QDir defaultDirShader(defaultPathShader);
410  currentFile = QFileInfo(defaultDirShader, shader);
411  }
412  d->lineEditShader->setText(currentFile.absoluteFilePath());
413 }
414 
416  d->torus->centerPoint()->x() = x;
417  d->torus->touchGeometry();
418  //emit dataChangedByGeometry(d->torus);
419 // emit update();
420 }
421 
423  d->torus->centerPoint()->y() = y;
424  d->torus->touchGeometry();
425  //emit dataChangedByGeometry(d->torus);
426 // emit update();
427 }
428 
430  d->torus->centerPoint()->z() = z;
431  d->torus->touchGeometry();
432  //emit dataChangedByGeometry(d->torus);
433 // emit update();
434 }
435 
437  d->torus->direction()->x() = x;
438  d->torus->touchGeometry();
439  //emit dataChangedByGeometry(d->torus);
440 // emit update();
441 }
442 
444  d->torus->direction()->y() = y;
445  d->torus->touchGeometry();
446  //emit dataChangedByGeometry(d->torus);
447 // emit update();
448 }
449 
451  d->torus->direction()->z() = z;
452  d->torus->touchGeometry();
453  //emit dataChangedByGeometry(d->torus);
454 // emit update();
455 }
456 
458  d->torus->setRingRadius(ringRadius);
459  d->torus->touchGeometry();
460  //emit dataChangedByGeometry(d->torus);
461 // emit update();
462 }
463 
465  d->torus->setCrossSectionRadius(crossSectionRadius);
466  d->torus->touchGeometry();
467  //emit dataChangedByGeometry(d->torus);
468 // emit update();
469 }
470 
472  QVariant variant = d->torus->QObject::property("color");
473  if(variant.isValid()) {
474  d->torus->setColor(color);
475 // emit dataChangedByColor(d->torus, color.redF(), color.greenF(), color.blueF());
476 // emit modifiedProperty(d->torus, 0);
477  d->torus->touchProperty();
478  }
479 // emit update();
480 }
481 
483  double opacity_d = 1.0 - 0.01 * opacity; // range from 0.00 to 1.00
484 
485  QVariant variant = d->torus->QObject::property("opacity");
486  if(variant.isValid()) {
487  d->torus->setOpacity(opacity_d);
488 // emit dataChangedByOpacity(d->torus, opacity_d);
489 // emit modifiedProperty(d->torus, 1);
490  d->torus->touchProperty();
491  }
492 // emit update();
493 }
494 
496 {
497 // this->blockSignals(true);
498  const QSignalBlocker blockerCoordCenterX(d->coordinateCenter_x);
499  const QSignalBlocker blockerCoordCenterY(d->coordinateCenter_y);
500  const QSignalBlocker blockerCoordCenterZ(d->coordinateCenter_z);
501  const QSignalBlocker blockerCoordDirectionX(d->coordinateDirection_x);
502  const QSignalBlocker blockerCoordDirectionY(d->coordinateDirection_y);
503  const QSignalBlocker blockerCoordDirectionZ(d->coordinateDirection_z);
504  const QSignalBlocker blockerRingRadius(d->ringRadius);
505  const QSignalBlocker blockerCrossSectionRadius(d->crossSectionRadius);
506 
507  d->coordinateCenter_x->setValue(d->torus->centerPoint()->x());
508  d->coordinateCenter_y->setValue(d->torus->centerPoint()->y());
509  d->coordinateCenter_z->setValue(d->torus->centerPoint()->z());
510 
511  d->coordinateDirection_x->setValue(d->torus->direction()->x());
512  d->coordinateDirection_y->setValue(d->torus->direction()->y());
513  d->coordinateDirection_z->setValue(d->torus->direction()->z());
514 
515  d->ringRadius->setValue(d->torus->ringRadius());
516  d->crossSectionRadius->setValue(d->torus->crossSectionRadius());
517 // this->blockSignals(false);
518 }
void onRingRadiusChanged(double ringRadius)
axlInspectorObjectTorus(QWidget *parent=0)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
void onCrossSectionRadiusChanged(double crossSectionRadius)
void onLineEditShaderChanged(QString shader)
void onShaderStateChanged(bool isShader)
void onShaderChanged(QString shader)
void colorChanged(QColor color, dtkAbstractData *data)