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