Developer Documentation

QtMaterialDialog.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 //=============================================================================
44 //
45 // CLASS QtMaterialDialog - IMPLEMENTATION
46 //
47 //=============================================================================
48
49
50 //== INCLUDES =================================================================
51
52
53 #include "QtMaterialDialog.hh"
54 #include "../Scenegraph/MaterialNode.hh"
55
56
57
58
59 //== NAMESPACES ==============================================================
60
61
62 namespace ACG {
63 namespace QtWidgets {
64
65
66 //== IMPLEMENTATION ==========================================================
67
68
69 QtMaterialDialog::QtMaterialDialog( QWidget * _parent,
70 SceneGraph::MaterialNode * _node )
71 : QDialog( _parent ),
72 node_(_node)
73 {
74 ui_.setupUi( this );
75 // setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
76
77 // get initial values from node
78 color_ = bak_color_ = node_->base_color();
79 ambient_ = bak_ambient_ = node_->ambient_color();
80 diffuse_ = bak_diffuse_ = node_->diffuse_color();
81 specular_ = bak_specular_ = node_->specular_color();
82 overlay_ = bak_overlay_ = node_->overlay_color();
83 shine_ = bak_shine_ = node_->shininess();
84 point_size_ = bak_point_size_ = node_->point_size();
85 line_width_ = bak_line_width_ = node_->line_width();
86 round_points_ = bak_round_points_ = node_->round_points();
87 line_smooth_ = bak_line_smooth_ = node_->line_smooth();
88 backfaceCulling_ = bak_backfaceCulling_ = node_->backface_culling();
89 alphaTest_ = bak_alphaTest_ = node_->alpha_test();
90 alphaValue_ = bak_alphaValue_ = node_->alpha_value();
91 blending_ = bak_blending_ = node_->blending();
92 blendParam1_ = bak_blendParam1_ = node_->blending_param1();
93 blendParam2_ = bak_blendParam2_ = node_->blending_param2();
94 colorMaterial_ = bak_colorMaterial_ = node_->colorMaterial();
95 multiSampling_ = bak_multiSampling_ = node_->multiSampling();
96
97 baseColorActive_ = bak_baseColorActive_ = node_->applyProperties() & SceneGraph::MaterialNode::BaseColor;
98 materialActive_ = bak_materialActive_ = node_->applyProperties() & SceneGraph::MaterialNode::Material;
99 pointSizeActive_ = bak_pointSizeActive_ = node_->applyProperties() & SceneGraph::MaterialNode::PointSize;
100 lineWidthActive_ = bak_lineWidthActive_ = node_->applyProperties() & SceneGraph::MaterialNode::LineWidth;
101 roundPointsActive_ = bak_roundPointsActive_ = node_->applyProperties() & SceneGraph::MaterialNode::RoundPoints;
102 lineSmoothActive_ = bak_lineSmoothActive_ = node_->applyProperties() & SceneGraph::MaterialNode::LineSmooth;
103 alphaTestActive_ = bak_alphaTestActive_ = node_->applyProperties() & SceneGraph::MaterialNode::AlphaTest;
104 blendingActive_ = bak_blendingActive_ = node_->applyProperties() & SceneGraph::MaterialNode::Blending;
105 backfaceCullingActive_ = bak_backfaceCullingActive_ = node_->applyProperties() & SceneGraph::MaterialNode::BackFaceCulling;
106 colorMaterialActive_ = bak_colorMaterialActive_ = node_->applyProperties() & SceneGraph::MaterialNode::ColorMaterial;
107 multiSamplingActive_ = bak_multiSamplingActive_ = node_->applyProperties() & SceneGraph::MaterialNode::MultiSampling;
108
109 if( round_points_ || line_smooth_)
110 {
111 ui_.alphaTest->setEnabled(false);
112 ui_.alpha ->setEnabled(false);
113 }
114
115 setButtonColor( ui_.baseColorButton, color_ );
116 setButtonColor( ui_.ambientColorButton, ambient_ );
117 setButtonColor( ui_.diffuseColorButton, diffuse_ );
118 setButtonColor( ui_.specularColorButton, specular_ );
119 setButtonColor( ui_.overlayColorButton, overlay_ );
120
121 ui_.shininessSlider->setValue((int)shine_);
122 ui_.shininessBox->setValue((int)shine_);
123 ui_.pointSizeSpinBox->setValue(point_size_);
124 ui_.lineWidthSpinBox->setValue(line_width_);
125 ui_.roundPointsCheckBox->setChecked(round_points_);
126 ui_.lineSmoothCheckBox->setChecked(line_smooth_);
127 ui_.backfaceCulling->setChecked( backfaceCulling_ );
128 ui_.alphaTest->setChecked( alphaTest_ );
129 ui_.alpha->setValue((int) (alphaValue_ * 100.0f) );
130 ui_.colorMaterial->setChecked( colorMaterial_ );
131 ui_.multiSampling->setChecked( multiSampling_ );
132 ui_.blending->setChecked( blending_ );
133
134 for (int i=0; i < ui_.blendParam1->count(); i++)
135 if ( ui_.blendParam1->itemText(i) == paramToStr(blendParam1_) )
136 ui_.blendParam1->setCurrentIndex( i );
137
138 for (int i=0; i < ui_.blendParam2->count(); i++)
139 if ( ui_.blendParam2->itemText(i) == paramToStr(blendParam2_) )
140 ui_.blendParam2->setCurrentIndex( i );
141
142 applyProperties_ = node_->applyProperties();
143
144 ui_.baseColorActive->setChecked( baseColorActive_ );
145 ui_.materialActive->setChecked( materialActive_ );
146 ui_.pointSizeActive->setChecked( pointSizeActive_ );
147 ui_.lineWidthActive->setChecked( lineWidthActive_ );
148 ui_.roundPointsActive->setChecked( roundPointsActive_ );
149 ui_.lineSmoothActive->setChecked( lineSmoothActive_ );
150 ui_.alphaTestActive->setChecked( alphaTestActive_ );
151 ui_.blendingActive->setChecked( blendingActive_ );
152 ui_.backfaceCullingActive->setChecked( backfaceCullingActive_ );
153 ui_.colorMaterialActive->setChecked( colorMaterialActive_ );
154 ui_.multiSamplingActive->setChecked( multiSamplingActive_ );
155
156 connect( ui_.baseColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
157 connect( ui_.ambientColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
158 connect( ui_.diffuseColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
159 connect( ui_.specularColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
160 connect( ui_.overlayColorButton, SIGNAL( clicked() ), this, SLOT( enableProperty() ) );
161 connect( ui_.shininessSlider, SIGNAL( sliderPressed() ), this, SLOT( enableProperty() ) );
162 connect( ui_.shininessBox, SIGNAL( valueChanged(int) ), this, SLOT( enableProperty(int) ) );
163 connect( ui_.pointSizeSpinBox, SIGNAL( valueChanged(double) ), this, SLOT( enableProperty(double) ) );
164 connect( ui_.lineWidthSpinBox, SIGNAL( valueChanged(double) ), this, SLOT( enableProperty(double) ) );
165 connect( ui_.roundPointsCheckBox, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
166 connect( ui_.lineSmoothCheckBox, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
167 connect( ui_.backfaceCulling, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
168 connect( ui_.alphaTest, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
169 connect( ui_.blending, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
170 connect( ui_.colorMaterial, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
171 connect( ui_.multiSampling, SIGNAL( pressed() ), this, SLOT( enableProperty() ) );
172
173 connect( ui_.baseColorButton, SIGNAL( colorChanged(QColor) ),
174 this, SLOT( changeBaseColor(QColor) ) );
175 connect( ui_.ambientColorButton, SIGNAL( colorChanged(QColor) ),
176 this, SLOT( changeAmbientColor(QColor) ) );
177 connect( ui_.diffuseColorButton, SIGNAL( colorChanged(QColor) ),
178 this, SLOT( changeDiffuseColor(QColor) ) );
179 connect( ui_.specularColorButton, SIGNAL( colorChanged(QColor) ),
180 this, SLOT( changeSpecularColor(QColor) ) );
181 connect( ui_.overlayColorButton, SIGNAL( colorChanged(QColor) ),
182 this, SLOT( changeOverlayColor(QColor) ) );
183 connect( ui_.shininessSlider, SIGNAL( valueChanged(int) ),
184 this, SLOT( changeShine(int) ) );
185
186 connect( ui_.pointSizeSpinBox, SIGNAL( valueChanged(double) ),
187 this, SLOT( changePointSize(double) ) );
188 connect( ui_.lineWidthSpinBox, SIGNAL( valueChanged(double) ),
189 this, SLOT( changeLineWidth(double) ) );
190 connect( ui_.roundPointsCheckBox, SIGNAL( toggled(bool) ),
191 this, SLOT( changeRoundPoints(bool) ) );
192 connect( ui_.lineSmoothCheckBox, SIGNAL( toggled(bool) ),
193 this, SLOT( changeLineSmooth(bool) ) );
194 connect( ui_.backfaceCulling, SIGNAL( toggled(bool) ),
195 this, SLOT( changeBackfaceCulling(bool) ) );
196 connect( ui_.alphaTest, SIGNAL( toggled(bool) ),
197 this, SLOT( changeAlphaTest(bool) ) );
198 connect( ui_.alpha, SIGNAL( valueChanged(int) ),
199 this, SLOT( changeAlphaValue(int) ) );
200 connect( ui_.colorMaterial, SIGNAL( toggled(bool) ),
201 this, SLOT( changeColorMaterial(bool) ) );
202 connect( ui_.multiSampling, SIGNAL( toggled(bool) ),
203 this, SLOT( changeMultiSampling(bool) ) );
204 connect( ui_.blending, SIGNAL( toggled(bool) ),
205 this, SLOT( changeBlending(bool) ) );
206 connect( ui_.blendParam1, SIGNAL( currentIndexChanged(const QString&) ),
207 this, SLOT( changeBlendingParam1(const QString&) ) );
208 connect( ui_.blendParam2, SIGNAL( currentIndexChanged(const QString&) ),
209 this, SLOT( changeBlendingParam2(const QString&) ) );
210
211
212 connect( ui_.baseColorActive, SIGNAL( toggled(bool) ),
213 this, SLOT( changeActive(bool) ) );
214 connect( ui_.materialActive, SIGNAL( toggled(bool) ),
215 this, SLOT( changeActive(bool) ) );
216 connect( ui_.pointSizeActive, SIGNAL( toggled(bool) ),
217 this, SLOT( changeActive(bool) ) );
218 connect( ui_.lineWidthActive, SIGNAL( toggled(bool) ),
219 this, SLOT( changeActive(bool) ) );
220 connect( ui_.roundPointsActive, SIGNAL( toggled(bool) ),
221 this, SLOT( changeActive(bool) ) );
222 connect( ui_.lineSmoothActive, SIGNAL( toggled(bool) ),
223 this, SLOT( changeActive(bool) ) );
224 connect( ui_.alphaTestActive, SIGNAL( toggled(bool) ),
225 this, SLOT( changeActive(bool) ) );
226 connect( ui_.blendingActive, SIGNAL( toggled(bool) ),
227 this, SLOT( changeActive(bool) ) );
228 connect( ui_.backfaceCullingActive, SIGNAL( toggled(bool) ),
229 this, SLOT( changeActive(bool) ) );
230 connect( ui_.colorMaterialActive, SIGNAL( toggled(bool) ),
231 this, SLOT( changeActive(bool) ) );
232 connect( ui_.multiSamplingActive, SIGNAL( toggled(bool) ),
233 this, SLOT( changeActive(bool) ) );
234
235 connect( ui_.alphaTest, SIGNAL( toggled(bool) ),
236 ui_.alpha, SLOT( setEnabled(bool) ) );
237 connect( ui_.blending, SIGNAL( toggled(bool) ),
238 ui_.blendParam1, SLOT( setEnabled(bool) ) );
239 connect( ui_.blending, SIGNAL( toggled(bool) ),
240 ui_.blendParam2, SLOT( setEnabled(bool) ) );
241
242
243 ui_.alpha->setEnabled( ui_.alphaTest->isChecked() );
244 ui_.blendParam1->setEnabled( ui_.blending->isChecked() );
245 ui_.blendParam2->setEnabled( ui_.blending->isChecked() );
246
247 ui_.baseColorActive->setChecked(baseColorActive_);
248 ui_.materialActive->setChecked(materialActive_);
249 ui_.pointSizeActive->setChecked(pointSizeActive_);
250 ui_.lineWidthActive->setChecked(lineWidthActive_);
251 ui_.roundPointsActive->setChecked(roundPointsActive_);
252 ui_.lineWidthActive->setChecked(lineWidthActive_);
253 ui_.alphaTestActive->setChecked(alphaTestActive_);
254 ui_.blendingActive->setChecked(blendingActive_);
255 ui_.backfaceCullingActive->setChecked(backfaceCullingActive_);
256 ui_.colorMaterialActive->setChecked(colorMaterialActive_);
257 ui_.multiSamplingActive->setChecked(multiSamplingActive_);
258
259 connect( ui_.okButton, SIGNAL( clicked() ),
260 this, SLOT( accept() ) );
261 connect( ui_.cancelButton, SIGNAL( clicked() ),
262 this, SLOT( reject() ) );
263
264 layout()->setSizeConstraint( QLayout::SetFixedSize );
265 }
266
267
268 //-----------------------------------------------------------------------------
269
270
271 void
272 QtMaterialDialog::setButtonColor( QtColorChooserButton* _button,
273 const Vec4f& _color )
274 {
275 _button->setColor( convertColor( _color ) );
276 }
277
278
279 //-----------------------------------------------------------------------------
280
281
282 QColor
283 QtMaterialDialog::convertColor( Vec4f _color)
284 {
285 return QColor ((int)(_color[0]*255.0),
286 (int)(_color[1]*255.0),
287 (int)(_color[2]*255.0),
288 (int)(_color[3]*255.0));
289 }
290
291
292 //-----------------------------------------------------------------------------
293
294
295 Vec4f
296 QtMaterialDialog::convertColor( QColor _color)
297 {
298 return Vec4f (_color.redF(),
299 _color.greenF(),
300 _color.blueF(),
301 _color.alphaF() );
302 }
303
304
305 //-----------------------------------------------------------------------------
306
307
308 void QtMaterialDialog::reject()
309 {
310 undoChanges();
311 QDialog::reject();
312 }
313
314
315 //-----------------------------------------------------------------------------
316
317
318 void QtMaterialDialog::applyChanges()
319 {
320
321 unsigned int properties = 0;
322
323 if (baseColorActive_) properties = properties | SceneGraph::MaterialNode::BaseColor;
324 if (materialActive_) properties = properties | SceneGraph::MaterialNode::Material;
325 if (pointSizeActive_) properties = properties | SceneGraph::MaterialNode::PointSize;
326 if (lineWidthActive_) properties = properties | SceneGraph::MaterialNode::LineWidth;
327 if (roundPointsActive_) properties = properties | SceneGraph::MaterialNode::RoundPoints;
328 if (lineSmoothActive_) properties = properties | SceneGraph::MaterialNode::LineSmooth;
329 if (alphaTestActive_) properties = properties | SceneGraph::MaterialNode::AlphaTest;
330 if (blendingActive_) properties = properties | SceneGraph::MaterialNode::Blending;
331 if (backfaceCullingActive_) properties = properties | SceneGraph::MaterialNode::BackFaceCulling;
332 if (colorMaterialActive_) properties = properties | SceneGraph::MaterialNode::ColorMaterial;
333 if (multiSamplingActive_) properties = properties | SceneGraph::MaterialNode::MultiSampling;
334
335 node_->applyProperties(properties);
336
337 node_->set_base_color(color_);
338 node_->set_ambient_color(ambient_);
339 node_->set_diffuse_color(diffuse_);
340 node_->set_specular_color(specular_);
341 node_->set_overlay_color(overlay_);
342 node_->set_shininess(shine_);
343 node_->set_point_size(point_size_);
344 node_->set_line_width(line_width_);
345 node_->set_round_points(round_points_);
346 node_->set_line_smooth(line_smooth_);
347
348 if(backfaceCulling_)
349 node_->enable_backface_culling();
350 else
351 node_->disable_backface_culling();
352
353 if(alphaTest_)
354 node_->enable_alpha_test( alphaValue_ );
355 else
356 node_->disable_alpha_test();
357
358 if(blending_)
359 node_->enable_blending( blendParam1_, blendParam2_ );
360 else
361 node_->disable_blending();
362
363 if ( colorMaterial_ )
364 node_->enable_color_material();
365 else
366 node_->disable_color_material();
367
368 if ( multiSampling_ )
369 node_->enable_multisampling();
370 else
371 node_->disable_multisampling();
372
373 // // this is not optimal !
374 // if(round_points_ || line_smooth_ )
375 // node_->enable_alpha_test(0.5);
376 // else
377 // node_->disable_alpha_test();
378
379 setButtonColor( ui_.diffuseColorButton, diffuse_ );
380 setButtonColor( ui_.ambientColorButton, ambient_ );
381 setButtonColor( ui_.specularColorButton, specular_ );
382 setButtonColor( ui_.overlayColorButton, overlay_ );
383 setButtonColor( ui_.baseColorButton, color_ );
384
385 emit signalNodeChanged(node_);
386 }
387
388
389 //-----------------------------------------------------------------------------
390
391
392 void QtMaterialDialog::undoChanges()
393 {
394
395 unsigned int properties = 0;
396
397 if (bak_baseColorActive_) properties = properties | SceneGraph::MaterialNode::BaseColor;
398 if (bak_materialActive_) properties = properties | SceneGraph::MaterialNode::Material;
399 if (bak_pointSizeActive_) properties = properties | SceneGraph::MaterialNode::PointSize;
400 if (bak_lineWidthActive_) properties = properties | SceneGraph::MaterialNode::LineWidth;
401 if (bak_roundPointsActive_) properties = properties | SceneGraph::MaterialNode::RoundPoints;
402 if (bak_lineSmoothActive_) properties = properties | SceneGraph::MaterialNode::LineSmooth;
403 if (bak_alphaTestActive_) properties = properties | SceneGraph::MaterialNode::AlphaTest;
404 if (bak_blendingActive_) properties = properties | SceneGraph::MaterialNode::Blending;
405 if (bak_backfaceCullingActive_) properties = properties | SceneGraph::MaterialNode::BackFaceCulling;
406 if (bak_colorMaterialActive_) properties = properties | SceneGraph::MaterialNode::ColorMaterial;
407 if (bak_multiSampling_) properties = properties | SceneGraph::MaterialNode::MultiSampling;
408
409 node_->applyProperties(properties);
410
411 node_->set_base_color(bak_color_);
412 node_->set_ambient_color(bak_ambient_);
413 node_->set_diffuse_color(bak_diffuse_);
414 node_->set_specular_color(bak_specular_);
415 node_->set_overlay_color(bak_overlay_);
416 node_->set_shininess(bak_shine_);
417 node_->set_point_size(bak_point_size_);
418 node_->set_line_width(bak_line_width_);
419 node_->set_round_points(bak_round_points_);
420 node_->set_line_smooth(bak_line_smooth_);
421
422 if(bak_backfaceCulling_)
423 node_->enable_backface_culling();
424 else
425 node_->disable_backface_culling();
426
427 if(bak_alphaTest_)
428 node_->enable_alpha_test( bak_alphaValue_ );
429 else
430 node_->disable_alpha_test();
431
432 if(bak_blending_)
433 node_->enable_blending( bak_blendParam1_, bak_blendParam2_ );
434 else
435 node_->disable_blending();
436
437 if ( bak_colorMaterial_ )
438 node_->enable_color_material();
439 else
440 node_->disable_color_material();
441
442 if ( bak_multiSampling_ )
443 node_->enable_multisampling();
444 else
445 node_->disable_multisampling();
446
447 setButtonColor( ui_.diffuseColorButton, diffuse_ );
448 setButtonColor( ui_.ambientColorButton, ambient_ );
449 setButtonColor( ui_.specularColorButton, specular_ );
450 setButtonColor( ui_.overlayColorButton, overlay_ );
451 setButtonColor( ui_.baseColorButton, color_ );
452
453 emit signalNodeChanged(node_);
454 }
455
456
457 //-----------------------------------------------------------------------------
458
459
460 void QtMaterialDialog::changeDiffuseColor(QColor _newColor)
461 {
462 diffuse_ = convertColor( _newColor );
463
464 if (diffuse_[3] < 1.0f)
465 {
466 ui_.blending->setCheckState(Qt::Checked);
467 }
468
469 applyChanges();
470 }
471
472
473 //-----------------------------------------------------------------------------
474
475
476 void QtMaterialDialog::changeAmbientColor(QColor _newColor)
477 {
478 ambient_ = convertColor( _newColor );
479 applyChanges();
480
481 }
482
483
484 //-----------------------------------------------------------------------------
485
486
487 void QtMaterialDialog::changeSpecularColor(QColor _newColor)
488 {
489 specular_ = convertColor( _newColor );
490 applyChanges();
491 }
492
493 //-----------------------------------------------------------------------------
494
495
496 void QtMaterialDialog::changeOverlayColor(QColor _newColor)
497 {
498 overlay_ = convertColor( _newColor );
499 applyChanges();
500 }
501
502
503 //-----------------------------------------------------------------------------
504
505
506 void QtMaterialDialog::changeBaseColor(QColor _newColor)
507 {
508 color_ = convertColor( _newColor );
509 applyChanges();
510 }
511
512
513 //-----------------------------------------------------------------------------
514
515
516 void
517 QtMaterialDialog::changeShine(int _new)
518 {
519 shine_ = _new;
520 applyChanges();
521 }
522
523
524 //-----------------------------------------------------------------------------
525
526
527 void
528 QtMaterialDialog::changePointSize(double _new)
529 {
530 point_size_ = float(_new);
531 applyChanges();
532 }
533
534
535 //-----------------------------------------------------------------------------
536
537
538 void
539 QtMaterialDialog::changeLineWidth(double _new)
540 {
541 line_width_ = float(_new);
542 applyChanges();
543 }
544
545
546 //-----------------------------------------------------------------------------
547
548
549 void
550 QtMaterialDialog::changeRoundPoints(bool _b)
551 {
552 round_points_ = (bool)_b;
553
554 // update alpha test
555 bool b2 = _b || round_points_;
556 if(b2)
557 {
558 changeAlphaTest(true);
559 changeAlphaValue(50);
560 ui_.alpha ->setValue(50);
561 }
562 ui_.alphaTest->setEnabled(!b2);
563 ui_.alpha ->setEnabled(!b2);
564 ui_.alphaTest->setChecked( b2);
565
566 applyChanges();
567 }
568
569 //-----------------------------------------------------------------------------
570
571
572 void
573 QtMaterialDialog::changeLineSmooth(bool _b)
574 {
575 line_smooth_ = (bool)_b;
576
577 // update alpha test
578 bool b2 = _b || round_points_;
579 if(b2)
580 {
581 changeAlphaTest(true);
582 changeAlphaValue(50);
583 ui_.alpha ->setValue(50);
584 }
585 ui_.alphaTest->setEnabled(!b2);
586 ui_.alpha ->setEnabled(!b2);
587 ui_.alphaTest->setChecked( b2);
588
589 applyChanges();
590 }
591
592 //-----------------------------------------------------------------------------
593
594
595 void
596 QtMaterialDialog::changeBackfaceCulling(bool _b)
597 {
598 backfaceCulling_ = (bool)_b;
599 applyChanges();
600 }
601
602 //-----------------------------------------------------------------------------
603
604
605 void
606 QtMaterialDialog::changeAlphaTest(bool _b)
607 {
608 alphaTest_ = (bool)_b;
609 applyChanges();
610 }
611
612 //-----------------------------------------------------------------------------
613
614 void
615 QtMaterialDialog::changeColorMaterial(bool _b)
616 {
617 colorMaterial_ = (bool)_b;
618 applyChanges();
619 }
620
621 //-----------------------------------------------------------------------------
622
623 void
624 QtMaterialDialog::changeMultiSampling(bool _b)
625 {
626 multiSampling_ = (bool)_b;
627 applyChanges();
628 }
629
630 //-----------------------------------------------------------------------------
631
632 void
633 QtMaterialDialog::changeAlphaValue(int _new)
634 {
635 alphaValue_ = float(_new) / 100.0f;
636 applyChanges();
637 }
638
639 //-----------------------------------------------------------------------------
640
641
642 void
643 QtMaterialDialog::changeBlending(bool _b)
644 {
645 blending_ = (bool)_b;
646 applyChanges();
647 }
648
649 //-----------------------------------------------------------------------------
650
651 void
652 QtMaterialDialog::changeBlendingParam1(const QString& _name)
653 {
654 if (_name == "GL_ZERO") blendParam1_ = GL_ZERO;
655 else if (_name == "GL_ONE") blendParam1_ = GL_ONE;
656 else if (_name == "GL_SRC_COLOR") blendParam1_ = GL_SRC_COLOR;
657 else if (_name == "GL_ONE_MINUS_SRC_COLOR") blendParam1_ = GL_ONE_MINUS_SRC_COLOR;
658 else if (_name == "GL_DST_COLOR") blendParam1_ = GL_DST_COLOR;
659 else if (_name == "GL_ONE_MINUS_DST_COLOR") blendParam1_ = GL_ONE_MINUS_DST_COLOR;
660 else if (_name == "GL_SRC_ALPHA") blendParam1_ = GL_SRC_ALPHA;
661 else if (_name == "GL_ONE_MINUS_SRC_ALPHA") blendParam1_ = GL_ONE_MINUS_SRC_ALPHA;
662 else if (_name == "GL_DST_ALPHA") blendParam1_ = GL_DST_ALPHA;
663 else if (_name == "GL_ONE_MINUS_DST_ALPHA") blendParam1_ = GL_ONE_MINUS_DST_ALPHA;
664 else if (_name == "GL_CONSTANT_COLOR") blendParam1_ = GL_CONSTANT_COLOR;
665 else if (_name == "GL_ONE_MINUS_CONSTANT_COLOR") blendParam1_ = GL_ONE_MINUS_CONSTANT_COLOR;
666 else if (_name == "GL_CONSTANT_ALPHA") blendParam1_ = GL_CONSTANT_ALPHA;
667 else if (_name == "GL_ONE_MINUS_CONSTANT_ALPHA") blendParam1_ = GL_ONE_MINUS_CONSTANT_ALPHA;
668 else{
669 std::cerr << "Blending Param unknown!" << std::endl;
670 return;
671 }
672
673 applyChanges();
674 }
675
676 //-----------------------------------------------------------------------------
677
678 void
679 QtMaterialDialog::changeBlendingParam2(const QString& _name)
680 {
681 if (_name == "GL_ZERO") blendParam2_ = GL_ZERO;
682 else if (_name == "GL_ONE") blendParam2_ = GL_ONE;
683 else if (_name == "GL_SRC_COLOR") blendParam2_ = GL_SRC_COLOR;
684 else if (_name == "GL_ONE_MINUS_SRC_COLOR") blendParam2_ = GL_ONE_MINUS_SRC_COLOR;
685 else if (_name == "GL_DST_COLOR") blendParam2_ = GL_DST_COLOR;
686 else if (_name == "GL_ONE_MINUS_DST_COLOR") blendParam2_ = GL_ONE_MINUS_DST_COLOR;
687 else if (_name == "GL_SRC_ALPHA") blendParam2_ = GL_SRC_ALPHA;
688 else if (_name == "GL_ONE_MINUS_SRC_ALPHA") blendParam2_ = GL_ONE_MINUS_SRC_ALPHA;
689 else if (_name == "GL_DST_ALPHA") blendParam2_ = GL_DST_ALPHA;
690 else if (_name == "GL_ONE_MINUS_DST_ALPHA") blendParam2_ = GL_ONE_MINUS_DST_ALPHA;
691 else if (_name == "GL_CONSTANT_COLOR") blendParam2_ = GL_CONSTANT_COLOR;
692 else if (_name == "GL_ONE_MINUS_CONSTANT_COLOR") blendParam2_ = GL_ONE_MINUS_CONSTANT_COLOR;
693 else if (_name == "GL_CONSTANT_ALPHA") blendParam2_ = GL_CONSTANT_ALPHA;
694 else if (_name == "GL_ONE_MINUS_CONSTANT_ALPHA") blendParam2_ = GL_ONE_MINUS_CONSTANT_ALPHA;
695 else{
696 std::cerr << "Blending Param unknown!" << std::endl;
697 return;
698 }
699
700 applyChanges();
701 }
702
703 //-----------------------------------------------------------------------------
704
705 void
706 QtMaterialDialog::changeActive(bool /*toggle*/)
707 {
708
709 baseColorActive_ = ui_.baseColorActive->isChecked();
710 materialActive_ = ui_.materialActive->isChecked();
711 pointSizeActive_ = ui_.pointSizeActive->isChecked();
712 lineWidthActive_ = ui_.lineWidthActive->isChecked();
713 roundPointsActive_ = ui_.roundPointsActive->isChecked();
714 lineSmoothActive_ = ui_.lineSmoothActive->isChecked();
715 blendingActive_ = ui_.blendingActive->isChecked();
716 backfaceCullingActive_ = ui_.backfaceCullingActive->isChecked();
717 colorMaterialActive_ = ui_.colorMaterialActive->isChecked();
718 multiSamplingActive_ = ui_.multiSamplingActive->isChecked();
719
720 applyChanges();
721 }
722
723 //-----------------------------------------------------------------------------
724
725 void
726 QtMaterialDialog::enableProperty(int /*i*/)
727 {
728 if (sender() == ui_.baseColorButton) ui_.baseColorActive->setChecked( true );
729 else if (sender() == ui_.ambientColorButton) ui_.materialActive->setChecked( true );
730 else if (sender() == ui_.diffuseColorButton) ui_.materialActive->setChecked( true );
731 else if (sender() == ui_.specularColorButton) ui_.materialActive->setChecked( true );
732 else if (sender() == ui_.overlayColorButton) ui_.materialActive->setChecked( true );
733 else if (sender() == ui_.shininessSlider) ui_.materialActive->setChecked( true );
734 else if (sender() == ui_.shininessBox) ui_.materialActive->setChecked( true );
735 else if (sender() == ui_.pointSizeSpinBox) ui_.pointSizeActive->setChecked( true );
736 else if (sender() == ui_.lineWidthSpinBox) ui_.lineWidthActive->setChecked( true );
737 else if (sender() == ui_.roundPointsCheckBox) ui_.roundPointsActive->setChecked( true );
738 else if (sender() == ui_.lineSmoothCheckBox) ui_.lineSmoothActive->setChecked( true );
739 else if (sender() == ui_.backfaceCulling) ui_.backfaceCullingActive->setChecked( true );
740 else if (sender() == ui_.alphaTest) ui_.alphaTestActive->setChecked( true );
741 else if (sender() == ui_.blending) ui_.blendingActive->setChecked( true );
742 else if (sender() == ui_.colorMaterial) ui_.colorMaterialActive->setChecked( true );
743 else if (sender() == ui_.multiSampling) ui_.multiSamplingActive->setChecked( true );
744 }
745
746
747 //-----------------------------------------------------------------------------
748
749 void
750 QtMaterialDialog::enableProperty(double d)
751 {
752
753 if (sender() == ui_.baseColorButton) ui_.baseColorActive->setChecked(true);
754 else if (sender() == ui_.ambientColorButton) ui_.materialActive->setChecked(true);
755 else if (sender() == ui_.diffuseColorButton) ui_.materialActive->setChecked(true);
756 else if (sender() == ui_.specularColorButton) ui_.materialActive->setChecked(true);
757 else if (sender() == ui_.overlayColorButton) ui_.materialActive->setChecked(true);
758 else if (sender() == ui_.shininessSlider) ui_.materialActive->setChecked(true);
759 else if (sender() == ui_.shininessBox) ui_.materialActive->setChecked(true);
760 else if (sender() == ui_.pointSizeSpinBox) ui_.pointSizeActive->setChecked(true);
761 else if (sender() == ui_.lineWidthSpinBox) ui_.lineWidthActive->setChecked(true);
762 else if (sender() == ui_.roundPointsCheckBox) ui_.roundPointsActive->setChecked(true);
763 else if (sender() == ui_.lineSmoothCheckBox) ui_.lineSmoothActive->setChecked(true);
764 else if (sender() == ui_.backfaceCulling) ui_.backfaceCullingActive->setChecked(true);
765 else if (sender() == ui_.alphaTest) ui_.alphaTestActive->setChecked(true);
766 else if (sender() == ui_.blending) ui_.blendingActive->setChecked(true);
767 else if (sender() == ui_.colorMaterial) ui_.colorMaterialActive->setChecked(true);
768 else if (sender() == ui_.multiSampling) ui_.multiSamplingActive->setChecked(true);
769
770 }
771
772 //-----------------------------------------------------------------------------
773
774 void
775 QtMaterialDialog::enableProperty()
776 {
777
778 if (sender() == ui_.baseColorButton) ui_.baseColorActive->setChecked( true );
779 else if (sender() == ui_.ambientColorButton) ui_.materialActive->setChecked( true );
780 else if (sender() == ui_.diffuseColorButton) ui_.materialActive->setChecked( true );
781 else if (sender() == ui_.specularColorButton) ui_.materialActive->setChecked( true );
782 else if (sender() == ui_.overlayColorButton) ui_.materialActive->setChecked( true );
783 else if (sender() == ui_.shininessSlider) ui_.materialActive->setChecked( true );
784 else if (sender() == ui_.shininessBox) ui_.materialActive->setChecked( true );
785 else if (sender() == ui_.pointSizeSpinBox) ui_.pointSizeActive->setChecked( true );
786 else if (sender() == ui_.lineWidthSpinBox) ui_.lineWidthActive->setChecked( true );
787 else if (sender() == ui_.roundPointsCheckBox) ui_.roundPointsActive->setChecked( true );
788 else if (sender() == ui_.lineSmoothCheckBox) ui_.lineSmoothActive->setChecked( true );
789 else if (sender() == ui_.backfaceCulling) ui_.backfaceCullingActive->setChecked( true );
790 else if (sender() == ui_.alphaTest) ui_.alphaTestActive->setChecked( true );
791 else if (sender() == ui_.blending) ui_.blendingActive->setChecked( true );
792 else if (sender() == ui_.colorMaterial) ui_.colorMaterialActive->setChecked( true );
793 else if (sender() == ui_.multiSampling) ui_.multiSamplingActive->setChecked( true );
794
795 }
796
797 //-----------------------------------------------------------------------------
798
799 QString QtMaterialDialog::paramToStr(GLenum _param)
800 {
801 if (_param == GL_ZERO) return "GL_ZERO";
802 else if (_param == GL_ONE) return "GL_ONE";
803 else if (_param == GL_SRC_COLOR) return "GL_SRC_COLOR";
804 else if (_param == GL_ONE_MINUS_SRC_COLOR) return "GL_ONE_MINUS_SRC_COLOR";
805 else if (_param == GL_DST_COLOR) return "GL_DST_COLOR";
806 else if (_param == GL_ONE_MINUS_DST_COLOR) return "GL_ONE_MINUS_DST_COLOR";
807 else if (_param == GL_SRC_ALPHA) return "GL_SRC_ALPHA";
808 else if (_param == GL_ONE_MINUS_SRC_ALPHA) return "GL_ONE_MINUS_SRC_ALPHA";
809 else if (_param == GL_DST_ALPHA) return "GL_DST_ALPHA";
810 else if (_param == GL_ONE_MINUS_DST_ALPHA) return "GL_ONE_MINUS_DST_ALPHA";
811 else if (_param == GL_CONSTANT_COLOR) return "GL_CONSTANT_COLOR";
812 else if (_param == GL_ONE_MINUS_CONSTANT_COLOR) return "GL_ONE_MINUS_CONSTANT_COLOR";
813 else if (_param == GL_CONSTANT_ALPHA) return "GL_CONSTANT_ALPHA";
814 else if (_param == GL_ONE_MINUS_CONSTANT_ALPHA) return "GL_ONE_MINUS_CONSTANT_ALPHA";
815 else
816 return "UNKOWN PARAM";
817 }
818
819 //=============================================================================
820 } // namespace QtWidgets
821 } // namespace ACG
822 //=============================================================================
ACG
Namespace providing different geometric functions concerning angles.
Definition: BaseObjectData.hh:68
MaterialNode
ACG::SceneGraph::MaterialNode MaterialNode
Materialnode.
Definition: BaseObjectData.hh:85
QtColorChooserButton
Definition: QtColorChooserButton.hh:48
OpenMesh::VectorT< float, 4 >