Developer documentation | Axl-2.5.1

axlInspectorObjectCone.cpp
Go to the documentation of this file.
1 /* axlInspectorObjectCone.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 "axlInspectorObjectCone.h"
21 #include "axlInspectorUtils.h"
22 
23 #include <axlCore/axlCone.h>
24 #include <axlCore/axlPoint.h>
25 
26 #include <dtkGuiSupport/dtkColorButton.h>
27 #include <dtkGuiSupport/dtkSplitter.h>
28 
29 #include <QtGui>
30 
31 class axlInspectorObjectConePrivate
32 {
33 public:
34  axlCone *cone;
35 
36  QDoubleSpinBox *coordinateApex_x;
37  QDoubleSpinBox *coordinateApex_y;
38  QDoubleSpinBox *coordinateApex_z;
39 
40  QDoubleSpinBox *coordinateBasePoint_x;
41  QDoubleSpinBox *coordinateBasePoint_y;
42  QDoubleSpinBox *coordinateBasePoint_z;
43 
44  QDoubleSpinBox *radius;
45 
46  dtkColorButton *colorButton;
47 
48  QComboBox *comboBoxShader;
49 
50  QCheckBox *checkBoxShader;
51  QLineEdit *lineEditShader;
52  QPushButton *buttonShader;
53 
54  QSlider *sliderOpacity;
55 };
56 
59  //QFrame(parent),
60  d(new axlInspectorObjectConePrivate)
61 {
62  d->coordinateApex_x = NULL;
63  d->coordinateApex_y = NULL;
64  d->coordinateApex_z = NULL;
65 
66  d->coordinateBasePoint_x = NULL;
67  d->coordinateBasePoint_y = NULL;
68  d->coordinateBasePoint_z = NULL;
69 
70  d->radius = 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 {
85  delete d;
86 
87  d = NULL;
88 }
89 
91 {
92  return QSize(300, 300);
93 }
94 
96 {
97  d->cone = cone;
98  initWidget();
99  connect(d->cone, SIGNAL(modifiedGeometry()), this, SLOT(updateValues()));
100 }
101 
102 void axlInspectorObjectCone::initWidget()
103 {
104  QVBoxLayout *layoutTop = new QVBoxLayout(this);
105  layoutTop->addWidget(new QLabel("axlInspectorObjectCone", this));
106 
107  addPointLayout (layoutTop, Apex, "Apex:",
108  d->coordinateApex, onCoordDataChangedApex,
109  d->cone->apex());
110 
111  addPointLayout (layoutTop, BasePoint, "Base point:",
112  d->coordinateBasePoint, onCoordDataChangedBasePoint,
113  d->cone->basePoint());
114 
115  addValueLayout (layoutTop, Radius, "Radius:", d->radius, onRadiusChanged, d->cone->radius());
116 
117  addColorButton (layoutTop, d->colorButton, onColorChanged, initColorValue());
118  addOpacitySlider (layoutTop, d->sliderOpacity, onOpacityChanged, initOpacityValue());
119  addShaderComboBox(layoutTop,
120  d->comboBoxShader, d->checkBoxShader, d->lineEditShader, d->buttonShader,
122  initShaderValue());
123 
124  QWidget *top = new QWidget(this);
125  top->setMaximumWidth(295);
126  top->setLayout(layoutTop);
127 
128 }
129 
131 {
132  d->lineEditShader->setText(this->filePath(shader));
133 }
134 
135 QString axlInspectorObjectCone::initShaderValue(void)
136 {
137  return d->cone->shader();
138 }
139 
140 QColor axlInspectorObjectCone::initColorValue(void)
141 {
142  return d->cone->color();
143 }
144 
145 int axlInspectorObjectCone::initOpacityValue(void)
146 {
147  double initOpacity = 0.0;
148  double opacity = d->cone->opacity();
149 
150  if(opacity > initOpacity)
151  initOpacity = opacity;
152 
153  return 100 * (1.0 - initOpacity);
154 }
155 
157 {
158  if(d->lineEditShader->isEnabled()) {
159  QString fileToOpen;
160  fileToOpen = QFileDialog::getOpenFileName(this, tr("Open shader"), "", tr("vs file (*.vs)"));
161  d->lineEditShader->setText(fileToOpen);
162  }
163 }
164 
166 {
167  d->cone->setShader(shader);
168 
169 // emit modifiedProperty(d->cone, 2);
170 // emit update();
171  d->cone->touchProperty();
172 }
173 
175 {
176  if(isShader) {
177  d->comboBoxShader->setEnabled(true);
178  d->lineEditShader->setEnabled(true);
179  d->buttonShader->setEnabled(true);
180  onLineEditShaderChanged(d->comboBoxShader->currentText());
181  } else {
182  d->comboBoxShader->setEnabled(false);
183  d->lineEditShader->setEnabled(false);
184  d->buttonShader->setEnabled(false);
185  d->cone->setShader("");
186  }
187 
188 // emit modifiedProperty(d->cone, 2);
189 // emit update();
190  d->cone->touchProperty();
191 }
192 
194 {
195  d->cone->apex()->x() = x;
196  d->cone->touchGeometry();
197 // emit update();
198 }
199 
201 {
202  d->cone->apex()->y() = y;
203  d->cone->touchGeometry();
204 // emit update();
205 }
206 
208 {
209  d->cone->apex()->z() = z;
210  d->cone->touchGeometry();
211 // emit update();
212 }
213 
215 {
216  d->cone->basePoint()->x() = x;
217  d->cone->touchGeometry();
218 // emit update();
219 }
220 
222 {
223  d->cone->basePoint()->y() = y;
224  d->cone->touchGeometry();
225 // emit update();
226 }
227 
229 {
230  d->cone->basePoint()->z() = z;
231  d->cone->touchGeometry();
232 // emit update();
233 }
234 
236 {
237  d->cone->setRadius(radius);
238  d->cone->touchGeometry();
239 // emit update();
240 }
241 
243 {
244  QVariant variant = d->cone->QObject::property("color");
245 
246  if(variant.isValid()) {
247  d->cone->setColor(color);
248 
249 // emit modifiedProperty(d->cone, 0);
250  d->cone->touchProperty();
251  }
252 
253 // emit update();
254 }
255 
257 {
258  double opacity_d = 1.0 - 0.01 * opacity;
259 
260  QVariant variant = d->cone->QObject::property("opacity");
261 
262  if(variant.isValid()) {
263  d->cone->setOpacity(opacity_d);
264 
265 // emit modifiedProperty(d->cone, 1);
266  d->cone->touchProperty();
267  }
268 
269 // emit update();
270 }
271 
273 {
274 // this->blockSignals(true);
275 
276  const QSignalBlocker blockerApexX(d->coordinateApex_x);
277  const QSignalBlocker blockerApexY(d->coordinateApex_y);
278  const QSignalBlocker blockerApexZ(d->coordinateApex_z);
279  const QSignalBlocker blockerBasePointX(d->coordinateBasePoint_x);
280  const QSignalBlocker blockerBasePointY(d->coordinateBasePoint_y);
281  const QSignalBlocker blockerBasePointZ(d->coordinateBasePoint_z);
282  const QSignalBlocker blockerRadius(d->radius);
283 
284  d->coordinateApex_x->setValue(d->cone->apex()->x());
285  d->coordinateApex_y->setValue(d->cone->apex()->y());
286  d->coordinateApex_z->setValue(d->cone->apex()->z());
287  d->coordinateBasePoint_x->setValue(d->cone->basePoint()->x());
288  d->coordinateBasePoint_y->setValue(d->cone->basePoint()->y());
289  d->coordinateBasePoint_z->setValue(d->cone->basePoint()->z());
290  d->radius->setValue(d->cone->radius());
291 
292 // this->blockSignals(false);
293 }
#define addColorButton(layoutTop, colorButton, slot, init)
#define addOpacitySlider(layoutTop, sliderOpacity, slot, init)
#define addPointLayout(layoutTop, name, title, coordinatePoint, slot, init)
#define addValueLayout(layoutTop, name, title, data, slot, init)
void onCoordDataChangedBasePoint_x(double x)
void onShaderStateChanged(bool isShader)
void onCoordDataChangedBasePoint_y(double y)
axlInspectorObjectCone(QWidget *parent=0)
Class axlCone defines 3D cones.
Definition: axlCone.h:34
#define addShaderComboBox(layoutTop, comboBoxShader, checkBoxShader, lineEditShader, buttonShader, onComboBoxChanged, onCheckBoxChanged, onTextChanged, openShader, init)
void onRadiusChanged(double radius)
void onCoordDataChangedBasePoint_z(double z)
QString filePath(const QString &shader)