Path: blob/devel/ElmerGUI/Application/src/glcontrol.cpp
3203 views
/*****************************************************************************1* *2* Elmer, A Finite Element Software for Multiphysical Problems *3* *4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *5* *6* This program is free software; you can redistribute it and/or *7* modify it under the terms of the GNU General Public License *8* as published by the Free Software Foundation; either version 2 *9* of the License, or (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program (in file fem/GPL-2); if not, write to the *18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *19* Boston, MA 02110-1301, USA. *20* *21*****************************************************************************/2223/*****************************************************************************24* *25* ElmerGUI glcontrol *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *30* Email: [email protected] *31* Web: http://www.csc.fi/elmer *32* Address: CSC - IT Center for Science Ltd. *33* Keilaranta 14 *34* 02101 Espoo, Finland *35* *36* Original Date: 15 Mar 2008 *37* *38*****************************************************************************/3940#include <QtGui>41#include <iostream>42#include "glcontrol.h"4344using namespace std;4546GLcontrol::GLcontrol(QWidget *parent)47: QDialog(parent)48{49ui.setupUi(this);5051connect(ui.okButton, SIGNAL(clicked()),52this, SLOT(okButtonClicked()));5354connect(ui.closeButton, SIGNAL(clicked()),55this, SLOT(close()));5657connect(ui.ambientDial, SIGNAL(sliderReleased()),58this, SLOT(okButtonClicked()));5960connect(ui.diffuseDial, SIGNAL(sliderReleased()),61this, SLOT(okButtonClicked()));6263connect(ui.specularDial, SIGNAL(sliderReleased()),64this, SLOT(okButtonClicked()));6566connect(ui.posxSpinBox, SIGNAL(editingFinished()),67this, SLOT(okButtonClicked()));6869connect(ui.posySpinBox, SIGNAL(editingFinished()),70this, SLOT(okButtonClicked()));7172connect(ui.poszSpinBox, SIGNAL(editingFinished()),73this, SLOT(okButtonClicked()));7475connect(ui.matAmbientDial, SIGNAL(sliderReleased()),76this, SLOT(okButtonClicked()));7778connect(ui.matDiffuseDial, SIGNAL(sliderReleased()),79this, SLOT(okButtonClicked()));8081connect(ui.matSpecularDial, SIGNAL(sliderReleased()),82this, SLOT(okButtonClicked()));8384connect(ui.matShininessDial, SIGNAL(sliderReleased()),85this, SLOT(okButtonClicked()));8687setWindowIcon(QIcon(":/icons/Mesh3D.png"));8889ui.okButton->setIcon(QIcon::fromTheme("dialog-accept"));90ui.closeButton->setIcon(QIcon::fromTheme("dialog-error-round"));91}9293GLcontrol::~GLcontrol()94{95}9697void GLcontrol::okButtonClicked()98{99GLfloat light_ambient[4];100GLfloat light_diffuse[4];101GLfloat light_specular[4];102GLfloat light_position[4];103GLfloat mat_ambient[4];104GLfloat mat_diffuse[4];105GLfloat mat_specular[4];106GLfloat high_shininess[1];107108int ambientMaximum = ui.ambientDial->maximum();109int diffuseMaximum = ui.diffuseDial->maximum();110int specularMaximum = ui.specularDial->maximum();111112int ambientValue = ui.ambientDial->value();113int diffuseValue = ui.diffuseDial->value();114int specularValue = ui.specularDial->value();115116int posxValue = ui.posxSpinBox->value();117int posyValue = ui.posySpinBox->value();118int poszValue = ui.poszSpinBox->value();119120int matAmbientMaximum = ui.matAmbientDial->maximum();121int matDiffuseMaximum = ui.matDiffuseDial->maximum();122int matSpecularMaximum = ui.matSpecularDial->maximum();123int matShininessMaximum = ui.matShininessDial->maximum();124125int matAmbientValue = ui.matAmbientDial->value();126int matDiffuseValue = ui.matDiffuseDial->value();127int matSpecularValue = ui.matSpecularDial->value();128int matShininessValue = ui.matShininessDial->value();129130ambient = (GLfloat)ambientValue / (GLfloat)ambientMaximum;131diffuse = (GLfloat)diffuseValue / (GLfloat)diffuseMaximum;132specular = (GLfloat)specularValue / (GLfloat)specularMaximum;133134posx = (GLfloat)posxValue;135posy = (GLfloat)posyValue;136posz = (GLfloat)poszValue;137138matAmbient = (GLfloat)matAmbientValue / (GLfloat)matAmbientMaximum;139matDiffuse = (GLfloat)matDiffuseValue / (GLfloat)matDiffuseMaximum;140matSpecular = (GLfloat)matSpecularValue / (GLfloat)matSpecularMaximum;141matShininess = (GLfloat)matShininessValue / (GLfloat)matShininessMaximum;142matShininess *= 100.0;143144light_ambient[0] = ambient;145light_ambient[1] = ambient;146light_ambient[2] = ambient;147light_ambient[3] = 1.0;148149light_diffuse[0] = diffuse;150light_diffuse[1] = diffuse;151light_diffuse[2] = diffuse;152light_diffuse[3] = 1.0;153154light_specular[0] = specular;155light_specular[1] = specular;156light_specular[2] = specular;157light_specular[3] = 1.0;158159light_position[0] = posx;160light_position[1] = posy;161light_position[2] = posz;162light_position[3] = 0.0;163164mat_ambient[0] = matAmbient;165mat_ambient[1] = matAmbient;166mat_ambient[2] = matAmbient;167mat_ambient[3] = 1.0;168169mat_diffuse[0] = matDiffuse;170mat_diffuse[1] = matDiffuse;171mat_diffuse[2] = matDiffuse;172mat_diffuse[3] = 1.0;173174mat_specular[0] = matSpecular;175mat_specular[1] = matSpecular;176mat_specular[2] = matSpecular;177mat_specular[3] = 1.0;178179high_shininess[0] = matShininess;180181glPushMatrix();182glMatrixMode(GL_MODELVIEW);183glLoadIdentity();184185glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);186glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);187glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);188glLightfv(GL_LIGHT0, GL_POSITION, light_position);189glEnable(GL_LIGHT0);190191glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);192glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);193glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);194glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess);195glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);196glEnable(GL_COLOR_MATERIAL);197198glPopMatrix();199200glWidget->updateGL();201}202203204