28 #include <dtkCoreSupport/dtkAbstractData.h>
30 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
33 #include <dtkGuiSupport/dtkColorButton.h>
34 #include <dtkGuiSupport/dtkSplitter.h>
38 class axlInspectorObjectMeshPrivate
45 dtkColorButton *colorButton;
46 QComboBox *comboBoxShader;
48 QComboBox *comboInterpolation;
50 QCheckBox *checkBoxShader;
51 QLineEdit *lineEditShader;
52 QPushButton *buttonShader;
54 QCheckBox *checkBoxPoints;
55 QCheckBox *checkBoxUseNormals;
56 QCheckBox *checkBoxLines;
57 QCheckBox *checkBoxPoly;
59 QSlider *sliderOpacity;
65 d(new axlInspectorObjectMeshPrivate)
69 d->colorButton = NULL;
70 d->comboBoxShader = NULL;
72 d->comboInterpolation = NULL;
74 d->checkBoxShader = NULL;
75 d->lineEditShader = NULL;
76 d->buttonShader = NULL;
78 d->sliderOpacity = NULL;
92 return QSize(300, 300);
100 this->setObjectDataState();
103 void axlInspectorObjectMesh::setObjectDataState(
void)
107 mesh = d->data->mesh();
111 if(!(mesh = dynamic_cast<axlMesh *>(d->data)))
114 foreach(QString t, dtkAbstractDataFactory::instance()->converters())
120 converter->setData(d->data);
121 mesh = converter->
toMesh();
131 d->data->setMesh(mesh);
132 d->checkBoxPoly->setChecked(mesh->
face_show());
133 d->checkBoxLines->setChecked(mesh->
edge_show());
134 d->checkBoxPoints->setChecked(mesh->
vertex_show());
139 d->checkBoxUseNormals->setChecked(
true);
141 d->checkBoxUseNormals->setChecked(
false);
145 d->checkBoxUseNormals->setDisabled(
true);
146 d->comboInterpolation->setCurrentIndex(0);
147 d->comboInterpolation->setDisabled(
true);
160 void axlInspectorObjectMesh::initWidget()
164 d->sliderSize =
new QSlider(Qt::Horizontal,
this);
166 QHBoxLayout *layoutSize =
new QHBoxLayout;
167 layoutSize->addWidget(
new QLabel(
"Size",
this));
168 layoutSize->addWidget(d->sliderSize);
169 d->sliderSize->setMinimum(-800);
170 d->sliderSize->setMaximum(500);
171 d->sliderSize->setValue(initSizeValue());
175 d->sliderOpacity =
new QSlider(Qt::Horizontal,
this);
176 d->sliderOpacity->setMaximum(100);
177 QHBoxLayout *layoutOpacity =
new QHBoxLayout;
178 layoutOpacity->addWidget(
new QLabel(
"Opacity",
this));
179 layoutOpacity->addWidget(d->sliderOpacity);
180 d->sliderOpacity->setValue(initOpacityValue());
183 d->comboBoxShader =
new QComboBox(
this);
184 d->comboBoxShader->setInsertPolicy(QComboBox::InsertAlphabetically);
186 d->checkBoxShader =
new QCheckBox(
this);
187 d->lineEditShader =
new QLineEdit(
this);
188 d->buttonShader =
new QPushButton(
this);
189 d->buttonShader->setText(
"open");
190 d->lineEditShader->setText(this->initShaderValue());
191 this->initComboBoxShaderValue();
193 if(d->lineEditShader->text().isEmpty())
195 d->lineEditShader->setEnabled(
false);
196 d->buttonShader->setEnabled(
false);
197 d->comboBoxShader->setEnabled(
false);
200 d->checkBoxShader->setChecked(
true);
202 QVBoxLayout *layoutShader =
new QVBoxLayout;
203 QHBoxLayout *layoutShader1 =
new QHBoxLayout;
205 QLabel *labelShader =
new QLabel(
"Shader",
this);
206 layoutShader1->addWidget(labelShader);
207 layoutShader1->addWidget(d->checkBoxShader);
208 layoutShader1->addWidget(d->comboBoxShader);
209 layoutShader1->addWidget(d->buttonShader);
211 layoutShader1->setStretchFactor(labelShader, 2);
212 layoutShader1->setStretchFactor(d->checkBoxShader, 1);
213 layoutShader1->setStretchFactor(d->comboBoxShader, 4);
214 layoutShader1->setStretchFactor(d->buttonShader, 3);
216 layoutShader->addLayout(layoutShader1);
217 layoutShader->addWidget(d->lineEditShader);
221 d->colorButton =
new dtkColorButton(
this);
222 QHBoxLayout *layoutColorButton =
new QHBoxLayout;
223 layoutColorButton->addWidget(
new QLabel(
"Color",
this));
224 layoutColorButton->addWidget(d->colorButton);
225 d->colorButton->setColor(this->initColorValue());
228 d->comboInterpolation =
new QComboBox(
this);
229 d->comboInterpolation->setInsertPolicy(QComboBox::InsertAlphabetically);
230 d->comboInterpolation->addItems(QStringList()<<
"Flat"<<
"Gouraud"<<
"Phong");
231 QHBoxLayout *layoutInterpolationCombobox =
new QHBoxLayout;
232 layoutInterpolationCombobox->addWidget(
new QLabel(
"Interpolation",
this));
233 layoutInterpolationCombobox->addWidget(d->comboInterpolation);
234 if (
axlMesh *meshData = dynamic_cast<axlMesh *>(d->data))
235 d->comboInterpolation->setCurrentIndex(meshData->interpolation());
238 d->checkBoxPoints =
new QCheckBox(
this);
239 d->checkBoxLines =
new QCheckBox(
this);
240 d->checkBoxPoly =
new QCheckBox(
this);
241 d->checkBoxUseNormals =
new QCheckBox(
this);
244 QHBoxLayout *layoutPoints =
new QHBoxLayout;
245 layoutPoints->addWidget(
new QLabel(
"Show Points",
this));
246 layoutPoints->addWidget(d->checkBoxPoints);
248 QHBoxLayout *layoutLines =
new QHBoxLayout;
249 layoutLines->addWidget(
new QLabel(
"Show Edges",
this));
250 layoutLines->addWidget(d->checkBoxLines);
252 QHBoxLayout *layoutPolygons =
new QHBoxLayout;
253 layoutPolygons->addWidget(
new QLabel(
"Show Faces",
this));
254 layoutPolygons->addWidget(d->checkBoxPoly);
256 QHBoxLayout *layoutNormals =
new QHBoxLayout;
257 layoutNormals->addWidget(
new QLabel(
"Use Normals",
this));
258 layoutNormals->addWidget(d->checkBoxUseNormals);
262 QVBoxLayout *layoutTop =
new QVBoxLayout;
263 layoutTop->addWidget(
new QLabel(
"axlInspectorObjectMesh",
this));
264 layoutTop->addLayout(layoutColorButton);
265 layoutTop->addLayout(layoutSize);
266 layoutTop->addLayout(layoutOpacity);
267 layoutTop->addLayout(layoutShader);
268 layoutTop->addLayout(layoutInterpolationCombobox);
269 layoutTop->addLayout(layoutPoints);
270 layoutTop->addLayout(layoutLines);
271 layoutTop->addLayout(layoutPolygons);
272 layoutTop->addLayout(layoutNormals);
273 layoutTop->addStretch(1);
275 QWidget *top =
new QWidget(
this);
276 top->setLayout(layoutTop);
277 top->setMaximumWidth(295);
279 dtkSplitter *splitter =
new dtkSplitter(
this,
true);
280 splitter->setOrientation(Qt::Vertical);
281 splitter->addWidget(top);
283 QVBoxLayout *layout =
new QVBoxLayout(
this);
284 layout->setContentsMargins(0, 0, 0, 0);
285 layout->setSpacing(0);
286 layout->addWidget(splitter);
289 connect(d->colorButton, SIGNAL(colorChanged(QColor)),
this, SLOT(
onColorChanged(QColor)));
290 connect(d->sliderSize, SIGNAL(valueChanged(
int)),
this, SLOT(
onSizeChanged(
int)));
291 connect(d->sliderOpacity, SIGNAL(valueChanged(
int)),
this, SLOT(
onOpacityChanged(
int)));
292 connect(d->comboBoxShader, SIGNAL(currentIndexChanged(QString)),
this, SLOT(
onLineEditShaderChanged(QString)));
293 connect(d->comboInterpolation, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
onInterpolationChanged(
int)));
295 connect(d->buttonShader, SIGNAL(clicked()),
this, SLOT(
openShader()));
296 connect(d->lineEditShader, SIGNAL(textChanged(QString)),
this, SLOT(
onShaderChanged(QString)));
298 connect(d->checkBoxPoints, SIGNAL(clicked()),
this, SLOT(
onUpdateGeometry()));
299 connect(d->checkBoxLines, SIGNAL(clicked()),
this, SLOT(
onUpdateGeometry()));
300 connect(d->checkBoxPoly, SIGNAL(clicked()),
this, SLOT(
onUpdateGeometry()));
301 connect(d->checkBoxUseNormals, SIGNAL(clicked()),
this, SLOT(
onUpdateGeometry()));
306 int axlInspectorObjectMesh::initSizeValue(
void)
308 double initSize = 100.0*(log(d->data->size()/0.125))/log(2.0);
317 void axlInspectorObjectMesh::initComboBoxShaderValue(
void)
319 if(d->comboBoxShader) {
325 QDir dirShader(
":axlShader/shader/");
326 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
328 dirShader.setNameFilters(filters);
330 QFileInfoList list = dirShader.entryInfoList();
335 QSettings settings(
"inria",
"dtk");
337 settings.beginGroup(
"shader");
338 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
339 defaultPathShader.append(
"/");
341 QDir defaultDirShader(defaultPathShader);
342 defaultDirShader.setNameFilters(filters);
343 QFileInfoList list2 = defaultDirShader.entryInfoList();
349 for (
int i = 0; i < list.size(); ++i) {
350 if(!items.contains(list.at(i).fileName()))
351 items << list.at(i).fileName();
355 int indInitShader = -1;
356 int indCurrentShader = -1;
358 foreach(QString item, items) {
360 d->comboBoxShader->addItem(item);
362 QFileInfo currentFileInfo(d->lineEditShader->text());
364 if(currentFileInfo.exists())
366 if(item == currentFileInfo.fileName())
367 indInitShader =indCurrentShader;
372 if(indInitShader != -1)
373 d->comboBoxShader->setCurrentIndex(indInitShader);
380 QDir dirShader(
":axlShader/shader/");
381 dirShader.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
383 QFileInfo currentFile(dirShader, shader);
384 if(!currentFile.exists())
386 QSettings settings(
"inria",
"dtk");
388 settings.beginGroup(
"shader");
389 QString defaultPathShader = settings.value(
"path", defaultPath).toString();
390 defaultPathShader.append(
"/");
392 QDir defaultDirShader(defaultPathShader);
393 currentFile = QFileInfo(defaultDirShader, shader);
397 d->lineEditShader->setText(currentFile.absoluteFilePath());
402 if (
axlMesh *meshData = dynamic_cast<axlMesh *>(d->data))
403 meshData->setInterpolation(modeInterpolation);
405 if (modeInterpolation == 0 && d->checkBoxUseNormals->checkState()){
406 d->checkBoxUseNormals->setChecked(
false);
408 }
else if (modeInterpolation > 0 && (!d->checkBoxUseNormals->checkState())){
409 d->checkBoxUseNormals->setChecked(
true);
417 QString axlInspectorObjectMesh::initShaderValue(
void)
419 return d->data->shader();
423 QColor axlInspectorObjectMesh::initColorValue(
void)
425 return d->data->color();
428 int axlInspectorObjectMesh::initOpacityValue(
void)
430 double initOpacity = 0.0;
431 double opacity = d->data->opacity();
432 if(opacity > initOpacity)
433 initOpacity = opacity;
435 return 100 * (1.0 - initOpacity);
440 d->data->setColor(color);
444 d->data->touchProperty();
450 if(d->lineEditShader->isEnabled())
453 fileToOpen = QFileDialog::getOpenFileName(
this, tr(
"Open shader"),
"", tr(
"vs file (*.vs)"));
454 d->lineEditShader->setText(fileToOpen);
460 d->data->setShader(shader);
464 d->data->touchProperty();
472 d->comboBoxShader->setEnabled(
true);
473 d->lineEditShader->setEnabled(
true);
474 d->buttonShader->setEnabled(
true);
477 d->data->setShader(d->lineEditShader->text());
482 d->comboBoxShader->setEnabled(
false);
483 d->lineEditShader->setEnabled(
false);
484 d->buttonShader->setEnabled(
false);
486 d->data->setShader(
"");
492 d->data->touchProperty();
497 double size_d = pow(2.0, size/100.0 - 3.0);
498 QVariant variant = d->data->QObject::property(
"size");
499 if(variant.isValid())
501 d->data->setSize(size_d);
503 d->data->mesh()->setSize(size_d);
507 d->data->mesh()->setSize(size_d);
515 double opacity_d = 1.0 - 0.01 * opacity;
516 d->data->setOpacity(opacity_d);
517 d->data->touchProperty();
526 if ((mesh = dynamic_cast<axlMesh*>(d->data))) {
527 mesh->
vertex_show() = d->checkBoxPoints->isChecked();
528 mesh->
normal_used() = d->checkBoxUseNormals->isChecked();
529 mesh->
edge_show() = d->checkBoxLines->isChecked();
530 mesh->
face_show() = d->checkBoxPoly->isChecked();
532 d->comboInterpolation->setCurrentIndex(0);
534 if (d->comboInterpolation->currentIndex()==0)
535 d->comboInterpolation->setCurrentIndex(2);
537 d->data->touchGeometry();
540 d->data->mesh()->vertex_show() = d->checkBoxPoints->isChecked();
541 d->data->mesh()->normal_used() = d->checkBoxUseNormals->isChecked();
542 d->data->mesh()->edge_show() = d->checkBoxLines->isChecked();
543 d->data->mesh()->face_show() = d->checkBoxPoly->isChecked();
544 if (!d->data->mesh()->normal_used())
545 d->comboInterpolation->setCurrentIndex(0);
547 if (d->comboInterpolation->currentIndex()==0)
548 d->comboInterpolation->setCurrentIndex(2);
549 d->data->mesh()->touchGeometry();
~axlInspectorObjectMesh(void)
bool vertex_show(void) const
void onShaderChanged(QString)
axlInspectorObjectMesh(QWidget *parent=0)
void onLineEditShaderChanged(QString)
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
bool normal_used(void) const
void onSizeChanged(int size)
void onInterpolationChanged(int modeInterpolation)
void setData(axlAbstractData *data)
bool edge_show(void) const
#define AXL_PROPERTY_SIZE
void onShaderStateChanged(bool isShader)
void onOpacityChanged(int opacity)
void onColorChanged(QColor color)
bool face_show(void) const
int normal_count(void) const
QSize sizeHint(void) const
void modifiedProperty(dtkAbstractData *, int)
void onUpdateGeometry(void)
virtual axlMesh * toMesh(void)
Mesh conversion.
int vertex_count(void) const
Class axlAbstractData defines an API for all type of axel data.
void interpolationChanded(dtkAbstractData *data, int interpolation)
Class axlMesh defines a piecewise-linear 3D object.