forked from finallyjustice/meshviewer
/
MainWindow.cpp
181 lines (160 loc) · 6.37 KB
/
MainWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/** File: MainWindow.cpp
** Author: Dongli Zhang
** Contact: dongli.zhang0129@gmail.com
**
** Copyright (C) Dongli Zhang 2013
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
** the GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "MainWindow.h"
MainWindow::MainWindow()
{
createActions();
createMenus();
canvas=new MeshGLWidget;
canvas->setMinimumSize(600, 600);
setCentralWidget(canvas);
}
void MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu("File");
fileMenu->addAction(openAction);
fileMenu->addAction(exitAction);
modeMenu = menuBar()->addMenu("Mode");
modeMenu->addAction(modePointAction);
modeMenu->addAction(modeLineAction);
modeMenu->addAction(modeFillAction);
shadeMenu = menuBar()->addMenu("Shade");
shadeMenu->addAction(shadeSmoothAction);
shadeMenu->addAction(shadeFlatAction);
colorMenu = menuBar()->addMenu("Color");
colorMenu->addAction(redAction);
colorMenu->addAction(greenAction);
colorMenu->addAction(blueAction);
colorMenu->addAction(yellowAction);
colorMenu->addAction(purpleAction);
colorMenu->addAction(whiteAction);
helpMenu = menuBar()->addMenu("About");
helpMenu->addAction(aboutAction);
}
void MainWindow::createActions()
{
openAction = new QAction("Open", this);
connect(openAction, SIGNAL(triggered()), this, SLOT(openFile()));
exitAction = new QAction("Exit", this);
connect(exitAction, SIGNAL(triggered()), this, SLOT(close()));
signalModeMapper = new QSignalMapper(this);
modePointAction = new QAction("Point", this);
modeLineAction = new QAction("Line", this);
modeFillAction = new QAction("Fill", this);
modePointAction->setCheckable(true);
modeLineAction->setCheckable(true);
modeFillAction->setCheckable(true);
connect(modePointAction, SIGNAL(triggered()), signalModeMapper, SLOT(map()));
connect(modeLineAction, SIGNAL(triggered()), signalModeMapper, SLOT(map()));
connect(modeFillAction, SIGNAL(triggered()), signalModeMapper, SLOT(map()));
signalModeMapper->setMapping(modePointAction, 0);
signalModeMapper->setMapping(modeLineAction, 1);
signalModeMapper->setMapping(modeFillAction, 2);
connect(signalModeMapper, SIGNAL(mapped(int)), this, SLOT(setMeshMode(int)));
modeGroup = new QActionGroup(this);
modeGroup->addAction(modePointAction);
modeGroup->addAction(modeLineAction);
modeGroup->addAction(modeFillAction);
modeFillAction->setChecked(true);
signalShadeMapper = new QSignalMapper(this);
shadeSmoothAction = new QAction("Smooth", this);
shadeFlatAction = new QAction("Flat", this);
shadeSmoothAction->setCheckable(true);
shadeFlatAction->setCheckable(true);
connect(shadeSmoothAction, SIGNAL(triggered()), signalShadeMapper, SLOT(map()));
connect(shadeFlatAction, SIGNAL(triggered()), signalShadeMapper, SLOT(map()));
signalShadeMapper->setMapping(shadeSmoothAction, 0);
signalShadeMapper->setMapping(shadeFlatAction, 1);
connect(signalShadeMapper, SIGNAL(mapped(int)), this, SLOT(setMeshShade(int)));
shadeGroup = new QActionGroup(this);
shadeGroup->addAction(shadeSmoothAction);
shadeGroup->addAction(shadeFlatAction);
shadeSmoothAction->setChecked(true);
signalColorMapper = new QSignalMapper(this);
redAction = new QAction("Red", this);
greenAction = new QAction("Green", this);
blueAction = new QAction("Blue", this);
yellowAction = new QAction("Yellow", this);
purpleAction = new QAction("Purple", this);
whiteAction = new QAction("White", this);
redAction->setCheckable(true);
greenAction->setCheckable(true);
blueAction->setCheckable(true);
yellowAction->setCheckable(true);
purpleAction->setCheckable(true);
whiteAction->setCheckable(true);
connect(redAction, SIGNAL(triggered()), signalColorMapper, SLOT(map()));
connect(greenAction, SIGNAL(triggered()), signalColorMapper, SLOT(map()));
connect(blueAction, SIGNAL(triggered()), signalColorMapper, SLOT(map()));
connect(yellowAction, SIGNAL(triggered()), signalColorMapper, SLOT(map()));
connect(purpleAction, SIGNAL(triggered()), signalColorMapper, SLOT(map()));
connect(whiteAction, SIGNAL(triggered()), signalColorMapper, SLOT(map()));
signalColorMapper->setMapping(redAction, 0);
signalColorMapper->setMapping(greenAction, 1);
signalColorMapper->setMapping(blueAction, 2);
signalColorMapper->setMapping(yellowAction, 3);
signalColorMapper->setMapping(purpleAction, 4);
signalColorMapper->setMapping(whiteAction, 5);
connect(signalColorMapper, SIGNAL(mapped(int)), this, SLOT(setMeshColor(int)));
colorGroup = new QActionGroup(this);
colorGroup->addAction(redAction);
colorGroup->addAction(greenAction);
colorGroup->addAction(blueAction);
colorGroup->addAction(yellowAction);
colorGroup->addAction(purpleAction);
colorGroup->addAction(whiteAction);
greenAction->setChecked(true);
aboutAction = new QAction("About", this);
connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
}
//SLOT
void MainWindow::openFile()
{
QString filename = QFileDialog::getOpenFileName(this, "Open Obj File", ".", "obj files (*.obj)");
QByteArray filename_byte = filename.toLatin1();
char *fileName = filename_byte.data();
int fileSize=filename_byte.size();
this->setWindowTitle(filename);
canvas->drawMesh(fileName, fileSize);
}
//SLOT
void MainWindow::about()
{
QMessageBox::about(this, "About Software",
"<h3>MeshViewer</h3>"
"<p>The viewer supports obj file, with or without normal information (vn).</p>"
"<p>Contact: Dongli ZHANG, <a href=\"mailto:dozhang@cs.sunysb.edu\">dozhang@cs.sunysb.edu</a></p>");
}
//SLOT
void MainWindow::setMeshMode(int mode)
{
canvas->setMode(mode);
}
//SLOT
void MainWindow::setMeshShade(int shade)
{
canvas->setShade(shade);
}
//SLOT
void MainWindow::setMeshColor(int color)
{
canvas->setColor(color);
}