-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
282 lines (238 loc) · 9.17 KB
/
Copy pathmainwindow.cpp
File metadata and controls
282 lines (238 loc) · 9.17 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QSettings>
#include <QDir>
#include <QFileDialog>
#include "obj2xmac.h"
#include "rmXmacWriter.h"
#include "rmObjReader.h"
rmOut MainWindow::out("mainwindow.cpp");
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
instr = new ShortInstruction(this);
readSettings();
updateLanguage();
}
MainWindow::~MainWindow()
{
delete ui;
delete instr;
}
void MainWindow::writeSettings(void)
{
QSettings settings;
settings.setValue("onlyVertsMode", ui->radioButton_verts->isChecked());
settings.setValue("newXmacMode", (ui->checkBox->checkState() == Qt::Checked));
settings.setValue("smoothingAngle", ui->spinBox_angle->value());
settings.setValue("objPath", objPath);
settings.setValue("xmacPath", xmacPath);
settings.setValue("newXmacPath", newXmacPath);
settings.setValue("localeStr", localeStr);
settings.beginGroup("MainWindow");
settings.setValue("size", size());
settings.setValue("pos", pos());
settings.endGroup();
}
void MainWindow::readSettings(void)
{
QSettings settings;
QSettings generalSettings("Baltram", "general");
ui->radioButton_mesh->setChecked(true); // Actually not necessary.
if (settings.value("onlyVertsMode", false).toBool() == true) {
ui->radioButton_verts->setChecked(true);
}
ui->checkBox->setChecked(settings.value("newXmacMode").toBool());
ui->spinBox_angle->setValue(settings.value("smoothingAngle", 50).toInt());
objPath = settings.value("objPath", QString(getenv("USERPROFILE")).append("\\Desktop\\")).toString();
xmacPath = settings.value("xmacPath", generalSettings.value("RisenDir").toString().append("\\data\\compiled\\animations\\_emfx36\\")).toString();
newXmacPath = settings.value("newXmacPath", QString(getenv("USERPROFILE")).append("\\Desktop\\")).toString();
ui->lineEdit_obj->setText(objPath);
ui->lineEdit_xmac->setText(xmacPath);
ui->lineEdit_newXmac->setText(newXmacPath);
localeStr = settings.value("localeStr").toString();
if (localeStr == "") {
int langId = generalSettings.value("NSISLanguage").toInt();
switch (langId)
{
case 1031: // German.
{
localeStr = "de";
break;
}
default: // English (1033).
{
localeStr = "en";
}
}
}
settings.beginGroup("MainWindow");
resize(settings.value("size", size()).toSize());
move(settings.value("pos", QPoint(400, 200)).toPoint());
settings.endGroup();
}
void MainWindow::closeEvent(QCloseEvent * event)
{
writeSettings();
event->accept();
}
void MainWindow::updateLanguage(void)
{
Obj2xmac::setLanguage(localeStr);
ui->menuLanguage->setIcon(QIcon(QString(":/flags/").append((localeStr == "en") ? "gb" : localeStr).append(".png")));
ui->retranslateUi(this);
instr->retranslate();
}
void MainWindow::on_actionEnglish_triggered()
{
localeStr = "en";
updateLanguage();
}
void MainWindow::on_actionGerman_triggered()
{
localeStr = "de";
updateLanguage();
}
void MainWindow::on_actionAbout_triggered()
{
//QMessageBox aboutMsg(tr("About obj2xmac..."), tr("{\\rtf1\\ansi{\\field{\\*\\fldinst HYPERLINK \"http://www.google.com/\"}{\\fldrslt http://www.google.com}}obj2xmac v0.1\n January 27th 2010\n by Baltram\n\nbaltram-lielb@web.de\nhttp://forum.worldofplayers.de/forum/showthread.php?t=689155}"), QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this);
QMessageBox aboutMsg(tr("About obj2xmac"), tr("<p></p><b>obj2xmac v0.1</b> (February 13th 2011)<div style='text-indent:16px;'>by <a href='mailto:baltram-lielb@web.de'>Baltram</a> @<a href='http://forum.worldofplayers.de/forum/member.php?u=33859'>WoP</a></div><p>Support: <a href='http://www.baltr.de/obj2xmac.htm'>www.baltr.de/obj2xmac.htm</a></p><p></p>"), QMessageBox::NoIcon, QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton, this);
aboutMsg.exec();
}
void MainWindow::on_actionExit_triggered()
{
this->close();
}
void MainWindow::on_checkBox_stateChanged(int newState)
{
if (newState == 2) {
ui->lineEdit_newXmac->setEnabled(true);
ui->pushButton_newXmac->setEnabled(true);
}
else {
ui->lineEdit_newXmac->setEnabled(false);
ui->pushButton_newXmac->setEnabled(false);
}
}
void MainWindow::on_pushButton_obj_clicked()
{
QString userDir = QFileDialog::getOpenFileName(this, tr("Select Wavefront OBJ file to open"), objPath, tr("Wavefront OBJ files (*.obj)")).toAscii();
userDir.replace('/', '\\');
if (userDir != "") {
ui->lineEdit_obj->setText(userDir);
}
}
void MainWindow::on_pushButton_xmac_clicked()
{
QString userDir = QFileDialog::getOpenFileName(this, tr("Select Risen animation actor file to open"), xmacPath, tr("Risen XMAC files (*._xmac)")).toAscii();
userDir.replace('/', '\\');
if (userDir != "") {
ui->lineEdit_xmac->setText(userDir);
}
}
void MainWindow::on_pushButton_newXmac_clicked()
{
QString userDir = QFileDialog::getSaveFileName(this, tr("Select Risen animation actor file to save"), newXmacPath, tr("Risen XMAC files (*._xmac)")).toAscii();
userDir.replace('/', '\\');
if (userDir != "") {
ui->lineEdit_newXmac->setText(userDir);
}
}
void MainWindow::on_pushButton_convert_clicked()
{
QFileInfo fileInfo;
rmBool onlyVerts = ui->radioButton_verts->isChecked();
fileInfo.setFile(objPath);
if (!fileInfo.exists()) {
OUT_ERR(string(tr("There is no such file:").toAscii()) << "\n\n" << "\"" << string(objPath.toAscii()) << "\"")
return;
}
fileInfo.setFile(xmacPath);
if (!fileInfo.exists()) {
OUT_ERR(string(tr("There is no such file:").toAscii()) << "\n\n" << "\"" << string(xmacPath.toAscii()) << "\"")
return;
}
string objFilePath(objPath.toAscii());
string xmacFilePath(xmacPath.toAscii());
string newXmacFilePath((ui->checkBox->checkState() == Qt::Checked) ? string(newXmacPath.toAscii()) : xmacFilePath);
rmScene s;
try {
rmObjReader::readObjFileToScene(&rmInFileStream(objFilePath), &s);
if (!onlyVerts) {
s.getNode(0).getMesh()->calcVNormalsByAngle(ui->spinBox_angle->value());
}
if ((s.getNode(0).getMesh()->getNumFaces() == 0) && (ui->radioButton_mesh->isChecked())) {
OUT_ERR(string(tr("No triangles found:").toAscii()) << "\n\n" << objFilePath)
return;
}
}
catch (std::exception & e) {
OUT_ERR(string(tr("Error reading from file:").toAscii()) << "\n\n" << objFilePath)
return;
}
try {
if (onlyVerts) {
rmXmacWriter::overwriteVertices(xmacFilePath, &s.getNode(0));
}
else {
rmXmacWriter::replaceMesh(xmacFilePath, s);
}
}
catch (std::exception & e) {
remove(xmacFilePath.append(".rmnew").c_str());
rmLPCChar what = e.what();
if (strcmp(what, "56739001") == 0) {
OUT_ERR(string(tr("Unable to create temporary file:").toAscii()) << "\n\n" << xmacFilePath << ".rmnew" << "\n\n" << string(tr("Try running this application with administrator rights.").toAscii()))
}
else if (strcmp(what, "56739002") == 0) {
OUT_ERR(string(tr("Vertex counts of OBJ file and corresponding XMAC mesh differ.").toAscii()))
}
else if (strcmp(what, "56739003") == 0) {
OUT_ERR("\"" << s.getNode(0).getName() << "\": " << string(tr("No such mesh found in XMAC file.").toAscii()))
}
else if (strcmp(what, "56739004") == 0) {
OUT_ERR(string(tr("Could not open file:").toAscii()) << "\n\n" << xmacFilePath)
}
else {
OUT_ERR(string(tr("Corrupt OBJ or XMAC file.").toAscii()))
}
return;
}
try {
rename(newXmacFilePath.c_str(), string(newXmacFilePath).append("rmnew2").c_str());
if (rename(string(xmacFilePath).append(".rmnew").c_str(), newXmacFilePath.c_str()) != 0) {
exception e;
throw e;
}
remove(string(newXmacFilePath).append("rmnew2").c_str());
}
catch (exception & e) {
rename(string(newXmacFilePath).append("rmnew2").c_str(), newXmacFilePath.c_str());
remove(xmacFilePath.append(".rmnew").c_str());
OUT_ERR(string(tr("Error writing to file:").toAscii()) << "\n\n" << newXmacFilePath)
return;
}
OUT_MSG(string(tr("XMAC file has been successfully rebuilt!").toAscii()))
}
void MainWindow::on_lineEdit_obj_textChanged(QString )
{
objPath = ui->lineEdit_obj->text();
}
void MainWindow::on_lineEdit_xmac_textChanged(QString )
{
xmacPath = ui->lineEdit_xmac->text();
}
void MainWindow::on_lineEdit_newXmac_textChanged(QString )
{
newXmacPath = ui->lineEdit_newXmac->text();
}
void MainWindow::on_actionShortInstruction_triggered()
{
instr->show();
}
void MainWindow::on_actionConvert_triggered()
{
on_pushButton_convert_clicked();
}