Molecule Viewer
 All Classes Functions Variables Enumerations Pages
MainWindow.cpp
1 
2 #include "widget.h"
3 #include "MainWindow.hpp"
4 
5 #include <fstream>
6 #include <QCoreApplication>
7 #include <QGLFormat>
8 #include <QHBoxLayout>
9 #include <QFileDialog>
10 #include <QDockWidget>
11 #include <QDebug>
12 
13 
14 
15 
17 {
18 
19  Ui_MainWindow MainWindow_ui;
20  MainWindow_ui.setupUi(this);
21 
22  //Specify an OpenGL 3.3 format using the Core profile.
23  // That is, no old-school fixed pipeline functionality
24  //QGLFormat glformat;
25  //glformat.setVersion(3, 0);
26  //glformat.setProfile(QGLFormat::CoreProfile);
27  //glformat.setSampleBuffers(true);
28 
29  _GLWidget = new Widget(this);
30  _mainapp = new AppMain();
31  _GLWidget->setMainApp(_mainapp);
32  QHBoxLayout *layout = new QHBoxLayout;
33  layout->addWidget(_GLWidget);
34  MainWindow_ui.centralwidget->setLayout(layout);
35 
36  QWidget * settingsWidget = new QWidget(this);
37 
38 
39  //Set up UI
40  _settings_ui.setupUi(settingsWidget);
41  _settings_ui.FileLabel->setText("Open Molecule Data: File => Load Molecule");
42  _settings_ui.PointIntensitySlider->setRange(0,255);
43  _settings_ui.GlossinessSlider->setRange(0,255);
44  _settings_ui.AmbientIntensitySlider->setRange(0,255);
45  _settings_ui.BorderVarianceSlider->setRange(0,255);
46  _settings_ui.BorderWidthSlider->setRange(0,255);
47  SetSelections();
48  connect(_settings_ui.PresetComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(PresetChanged(QString)));
49  connect(_settings_ui.PointIntensitySlider, SIGNAL(valueChanged(int)), this, SLOT(PointIntensityChanged(int)));
50  connect(_settings_ui.GlossinessSlider, SIGNAL(valueChanged(int)), this, SLOT(GlossinessChanged(int)));
51  connect(_settings_ui.ShadowCheckBox, SIGNAL(stateChanged(int)), this, SLOT(ShadowChanged(int)));
52  connect(_settings_ui.AmbientOcclusionRadioButton, SIGNAL(toggled(bool)), this, SLOT(AmbientOcclusionChanged(bool)));
53  connect(_settings_ui.AmbientIntensitySlider, SIGNAL(valueChanged(int)), this, SLOT(AmbientIntensityChanged(int)));
54  connect(_settings_ui.BorderWidthSlider, SIGNAL(valueChanged(int)), this, SLOT(BorderWidthChanged(int)));
55  connect(_settings_ui.BorderVarianceSlider, SIGNAL(valueChanged(int)), this, SLOT(BorderVarianceChanged(int)));
56  connect(_settings_ui.ColorComboBox, SIGNAL(currentTextChanged(QString)), this, SLOT(ColorModeChanged(QString)));
57  connect(_settings_ui.OcclusionPresetBox, SIGNAL(currentIndexChanged(int)), this, SLOT(OcclusionQualityChanged(int)));
58  layout->addWidget(settingsWidget);
59  settingsWidget->setFixedWidth(245);
60  setMinimumHeight(610);
61  setMinimumWidth(610);
62 
63  //Set start settings
64  PresetChanged("Combined Lighting");
65  OcclusionQualityChanged(2);
66 
67 }
68 
70 {
71  delete _mainapp;
72 }
73 
74 
76 
77  _settings_ui.FileLabel->setText("Loading PDB File...");
78 
79  QString filename = QFileDialog::getOpenFileName(this, "Load molecule data", QString(), "Protein Data Bank (*.pdb);;All files (*)");
80  if (filename.isNull())
81  return;
82  string file = filename.toStdString();
83 
84  std::ifstream in(file.c_str());
85  if (!in.good()) {
86  _settings_ui.FileLabel->setText("Could not load valid PDB file.");
87  return;
88  }
89 
90  if (!_mainapp->LoadMolecule(file)) {
91  _settings_ui.FileLabel->setText("Could not load valid PDB file.");
92  return;
93  }
94 
95  _settings_ui.FileLabel->setText(QString::fromStdString(file.substr(file.find_last_of("/")+1)));
96 
97  _mainapp->ChangeLightIntensity(_pointLightIntensity);
98  _mainapp->ChangeGlossiness(_glossiness);
99  _mainapp->ToggleShadow(_shadows);
100  _mainapp->ToggleAmbientOcclusion(_ambientOcclusionActive);
101  _mainapp->ChangeAmbientIntensity(_ambientIntensity);
102  _mainapp->ChangeBorder(_borderWidth, _borderVariance);
103 
104 };
105 
106 
108  close();
109 };
110 
111 
112 
113 
114 void MainWindow::PointIntensityChanged(const int changedValue) {
115  _pointLightIntensity = changedValue;
116  _mainapp->ChangeLightIntensity(_pointLightIntensity);
117  _settings_ui.PresetComboBox->setCurrentIndex(0);
118  _GLWidget->updateGL();
119 }
120 void MainWindow::GlossinessChanged(const int changedValue) {
121  _glossiness = changedValue;
122  _mainapp->ChangeGlossiness(_glossiness);
123  _settings_ui.PresetComboBox->setCurrentIndex(0);
124  _GLWidget->updateGL();
125 }
126 void MainWindow::ShadowChanged(const int changedValue) {
127  if (changedValue==0)
128  _shadows = false;
129  else
130  _shadows = true;
131  _mainapp->ToggleShadow(_shadows);
132  _settings_ui.PresetComboBox->setCurrentIndex(0);
133  _GLWidget->updateGL();
134 }
135 void MainWindow::AmbientOcclusionChanged(const bool changedValue) {
136  if (changedValue)
137  _ambientOcclusionActive = true;
138  else
139  _ambientOcclusionActive = false;
140  _mainapp->ToggleAmbientOcclusion(_ambientOcclusionActive);
141  _settings_ui.PresetComboBox->setCurrentIndex(0);
142  _GLWidget->updateGL();
143 }
144 void MainWindow::AmbientIntensityChanged(const int changedValue) {
145  _ambientIntensity = changedValue;
146  _mainapp->ChangeAmbientIntensity(_ambientIntensity);
147  _settings_ui.PresetComboBox->setCurrentIndex(0);
148  _GLWidget->updateGL();
149 }
150 void MainWindow::BorderWidthChanged(const int changedValue) {
151  _borderWidth = changedValue;
152  _mainapp->ChangeBorder(_borderWidth, _borderVariance);
153  _settings_ui.PresetComboBox->setCurrentIndex(0);
154  _GLWidget->updateGL();
155 }
156 void MainWindow::BorderVarianceChanged(const int changedValue) {
157  _borderVariance = changedValue;
158  _mainapp->ChangeBorder(_borderWidth, _borderVariance);
159  _settings_ui.PresetComboBox->setCurrentIndex(0);
160  _GLWidget->updateGL();
161 }
162 
163 void MainWindow::ColorModeChanged(const QString changedValue) {
164 
165  if (changedValue.compare("Per Atom")==0) {
166  _mainapp->ChangeColorMode(0);
167  _GLWidget->updateGL();
168  } else if (changedValue.compare("Per Chain")==0) {
169 
170  _mainapp->ChangeColorMode(1);
171  _GLWidget->updateGL();
172  } else if (changedValue.compare("No Color")==0) {
173 
174  _mainapp->ChangeColorMode(2);
175  _GLWidget->updateGL();
176 
177  }
178 }
179 
180 
181 void MainWindow::OcclusionQualityChanged(const int changedValue) {
182 
183  _mainapp->ChangeOcclusionQuality(changedValue);
184  _GLWidget->updateGL();
185 
186  _settings_ui.OcclusionPresetBox->setCurrentIndex(changedValue);
187 }
188 
189 
190 void MainWindow::PresetChanged(const QString changedValue) {
191 
192  if (changedValue.compare("Combined Lighting")==0) {
193  _shadows = true;
194  _ambientOcclusionActive = true;
195  _glossiness = 128;
196  _ambientIntensity = 100;
197  _pointLightIntensity = 150;
198  _borderWidth = 0;
199  _borderVariance = 128;
200  _colorMode = 0;
201  _mainapp->ToggleShadow(_shadows);
202  _mainapp->ChangeLightIntensity(_pointLightIntensity);
203  _mainapp->ChangeGlossiness(_glossiness);
204  _mainapp->ToggleAmbientOcclusion(_ambientOcclusionActive);
205  _mainapp->ChangeAmbientIntensity(_ambientIntensity);
206  _mainapp->ChangeBorder(_borderWidth, _borderVariance);
207  _mainapp->ChangeColorMode(_colorMode);
208  SetSelections();
209  _GLWidget->updateGL();
210  _settings_ui.PresetComboBox->setCurrentText(changedValue);
211  } else if (changedValue.compare("Ambient Occlusion Only")==0) {
212  _shadows = false;
213  _ambientOcclusionActive = true;
214  _ambientIntensity = 230;
215  _pointLightIntensity = 0;
216  _borderWidth = 0;
217  _colorMode = 0;
218  _mainapp->ToggleShadow(_shadows);
219  _mainapp->ChangeLightIntensity(_pointLightIntensity);
220  _mainapp->ToggleAmbientOcclusion(_ambientOcclusionActive);
221  _mainapp->ChangeAmbientIntensity(_ambientIntensity);
222  _mainapp->ChangeBorder(_borderWidth, _borderVariance);
223  _mainapp->ChangeColorMode(_colorMode);
224  SetSelections();
225  _GLWidget->updateGL();
226  _settings_ui.PresetComboBox->setCurrentText(changedValue);
227  } else if (changedValue.compare("Direct Lighting Only")==0) {
228  _shadows = false;
229  _ambientOcclusionActive = false;
230  _glossiness = 128;
231  _ambientIntensity = 64;
232  _pointLightIntensity = 128;
233  _borderWidth = 0;
234  _colorMode = 0;
235  _mainapp->ToggleShadow(_shadows);
236  _mainapp->ChangeLightIntensity(_pointLightIntensity);
237  _mainapp->ChangeGlossiness(_glossiness);
238  _mainapp->ToggleAmbientOcclusion(_ambientOcclusionActive);
239  _mainapp->ChangeAmbientIntensity(_ambientIntensity);
240  _mainapp->ChangeBorder(_borderWidth, _borderVariance);
241  _mainapp->ChangeColorMode(_colorMode);
242  SetSelections();
243  _GLWidget->updateGL();
244  _settings_ui.PresetComboBox->setCurrentText(changedValue);
245  } else if (changedValue.compare("Shape Perception")==0) {
246  _shadows = false;
247  _ambientOcclusionActive = true;
248  _pointLightIntensity = 0;
249  _ambientIntensity = 230;
250  _borderWidth = 128;
251  _borderVariance = 128;
252  _colorMode = 2;
253  _mainapp->ToggleShadow(_shadows);
254  _mainapp->ChangeLightIntensity(_pointLightIntensity);
255  _mainapp->ToggleAmbientOcclusion(_ambientOcclusionActive);
256  _mainapp->ChangeAmbientIntensity(_ambientIntensity);
257  _mainapp->ChangeBorder(_borderWidth, _borderVariance);
258  _mainapp->ChangeColorMode(_colorMode);
259  SetSelections();
260  _GLWidget->updateGL();
261  _settings_ui.PresetComboBox->setCurrentText(changedValue);
262  }
263 }
264 
265 
266 
268 
269  _settings_ui.ShadowCheckBox->setChecked(_shadows);
270  _settings_ui.AmbientOcclusionRadioButton->setChecked(_ambientOcclusionActive);
271  _settings_ui.AmbientConstantRadioButton->setChecked(!_ambientOcclusionActive);
272  _settings_ui.PointIntensitySlider->setValue(_pointLightIntensity);
273  _settings_ui.GlossinessSlider->setValue(_glossiness);
274  _settings_ui.AmbientIntensitySlider->setValue(_ambientIntensity);
275  _settings_ui.BorderVarianceSlider->setValue(_borderWidth);
276  _settings_ui.BorderWidthSlider->setValue(_borderWidth);
277  _settings_ui.ColorComboBox->setCurrentIndex(_colorMode);
278 
279 }