Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/src/glcontrol.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ElmerGUI glcontrol *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
41
#include <QtGui>
42
#include <iostream>
43
#include "glcontrol.h"
44
45
using namespace std;
46
47
GLcontrol::GLcontrol(QWidget *parent)
48
: QDialog(parent)
49
{
50
ui.setupUi(this);
51
52
connect(ui.okButton, SIGNAL(clicked()),
53
this, SLOT(okButtonClicked()));
54
55
connect(ui.closeButton, SIGNAL(clicked()),
56
this, SLOT(close()));
57
58
connect(ui.ambientDial, SIGNAL(sliderReleased()),
59
this, SLOT(okButtonClicked()));
60
61
connect(ui.diffuseDial, SIGNAL(sliderReleased()),
62
this, SLOT(okButtonClicked()));
63
64
connect(ui.specularDial, SIGNAL(sliderReleased()),
65
this, SLOT(okButtonClicked()));
66
67
connect(ui.posxSpinBox, SIGNAL(editingFinished()),
68
this, SLOT(okButtonClicked()));
69
70
connect(ui.posySpinBox, SIGNAL(editingFinished()),
71
this, SLOT(okButtonClicked()));
72
73
connect(ui.poszSpinBox, SIGNAL(editingFinished()),
74
this, SLOT(okButtonClicked()));
75
76
connect(ui.matAmbientDial, SIGNAL(sliderReleased()),
77
this, SLOT(okButtonClicked()));
78
79
connect(ui.matDiffuseDial, SIGNAL(sliderReleased()),
80
this, SLOT(okButtonClicked()));
81
82
connect(ui.matSpecularDial, SIGNAL(sliderReleased()),
83
this, SLOT(okButtonClicked()));
84
85
connect(ui.matShininessDial, SIGNAL(sliderReleased()),
86
this, SLOT(okButtonClicked()));
87
88
setWindowIcon(QIcon(":/icons/Mesh3D.png"));
89
90
ui.okButton->setIcon(QIcon::fromTheme("dialog-accept"));
91
ui.closeButton->setIcon(QIcon::fromTheme("dialog-error-round"));
92
}
93
94
GLcontrol::~GLcontrol()
95
{
96
}
97
98
void GLcontrol::okButtonClicked()
99
{
100
GLfloat light_ambient[4];
101
GLfloat light_diffuse[4];
102
GLfloat light_specular[4];
103
GLfloat light_position[4];
104
GLfloat mat_ambient[4];
105
GLfloat mat_diffuse[4];
106
GLfloat mat_specular[4];
107
GLfloat high_shininess[1];
108
109
int ambientMaximum = ui.ambientDial->maximum();
110
int diffuseMaximum = ui.diffuseDial->maximum();
111
int specularMaximum = ui.specularDial->maximum();
112
113
int ambientValue = ui.ambientDial->value();
114
int diffuseValue = ui.diffuseDial->value();
115
int specularValue = ui.specularDial->value();
116
117
int posxValue = ui.posxSpinBox->value();
118
int posyValue = ui.posySpinBox->value();
119
int poszValue = ui.poszSpinBox->value();
120
121
int matAmbientMaximum = ui.matAmbientDial->maximum();
122
int matDiffuseMaximum = ui.matDiffuseDial->maximum();
123
int matSpecularMaximum = ui.matSpecularDial->maximum();
124
int matShininessMaximum = ui.matShininessDial->maximum();
125
126
int matAmbientValue = ui.matAmbientDial->value();
127
int matDiffuseValue = ui.matDiffuseDial->value();
128
int matSpecularValue = ui.matSpecularDial->value();
129
int matShininessValue = ui.matShininessDial->value();
130
131
ambient = (GLfloat)ambientValue / (GLfloat)ambientMaximum;
132
diffuse = (GLfloat)diffuseValue / (GLfloat)diffuseMaximum;
133
specular = (GLfloat)specularValue / (GLfloat)specularMaximum;
134
135
posx = (GLfloat)posxValue;
136
posy = (GLfloat)posyValue;
137
posz = (GLfloat)poszValue;
138
139
matAmbient = (GLfloat)matAmbientValue / (GLfloat)matAmbientMaximum;
140
matDiffuse = (GLfloat)matDiffuseValue / (GLfloat)matDiffuseMaximum;
141
matSpecular = (GLfloat)matSpecularValue / (GLfloat)matSpecularMaximum;
142
matShininess = (GLfloat)matShininessValue / (GLfloat)matShininessMaximum;
143
matShininess *= 100.0;
144
145
light_ambient[0] = ambient;
146
light_ambient[1] = ambient;
147
light_ambient[2] = ambient;
148
light_ambient[3] = 1.0;
149
150
light_diffuse[0] = diffuse;
151
light_diffuse[1] = diffuse;
152
light_diffuse[2] = diffuse;
153
light_diffuse[3] = 1.0;
154
155
light_specular[0] = specular;
156
light_specular[1] = specular;
157
light_specular[2] = specular;
158
light_specular[3] = 1.0;
159
160
light_position[0] = posx;
161
light_position[1] = posy;
162
light_position[2] = posz;
163
light_position[3] = 0.0;
164
165
mat_ambient[0] = matAmbient;
166
mat_ambient[1] = matAmbient;
167
mat_ambient[2] = matAmbient;
168
mat_ambient[3] = 1.0;
169
170
mat_diffuse[0] = matDiffuse;
171
mat_diffuse[1] = matDiffuse;
172
mat_diffuse[2] = matDiffuse;
173
mat_diffuse[3] = 1.0;
174
175
mat_specular[0] = matSpecular;
176
mat_specular[1] = matSpecular;
177
mat_specular[2] = matSpecular;
178
mat_specular[3] = 1.0;
179
180
high_shininess[0] = matShininess;
181
182
glPushMatrix();
183
glMatrixMode(GL_MODELVIEW);
184
glLoadIdentity();
185
186
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
187
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
188
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
189
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
190
glEnable(GL_LIGHT0);
191
192
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
193
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
194
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
195
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, high_shininess);
196
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
197
glEnable(GL_COLOR_MATERIAL);
198
199
glPopMatrix();
200
201
glWidget->updateGL();
202
}
203
204