-
Notifications
You must be signed in to change notification settings - Fork 0
/
tr_main.cpp
206 lines (163 loc) · 5.18 KB
/
tr_main.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* tr_main.cpp
*
* Copyright (c) Kartik Patel
* E-mail: [email protected]
* Download from: https://letapk.wordpress.com
*
* 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.
*
*/
//Last modified 21 June 2022
#include "tr.h"
#include "tr_vars.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainwindow;
mainwindow.show();
mainwindow.setWindowTitle(QObject::tr("Trajecstory 0.4"));
return app.exec();
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow (parent)
{
//initial window size
this->setGeometry(0, 0, 1024, 600);
window = new Window(this);
setCentralWidget(window);
setup_menu_and_toolbar ();
statusBar()->showMessage(tr("Ready"));
initialise_default_system();
}
MainWindow::~MainWindow()
{
}
void MainWindow::setup_menu_and_toolbar (void)
{
//main menu
filemenu = menuBar()->addMenu(tr("&File"));
computemenu = menuBar()->addMenu(tr("&Compute"));
helpmenu = menuBar()->addMenu(tr("&Help"));
//toolbar
tb1 = addToolBar(tr("File"));
tb1->setFloatable (false);
tb1->setMovable(false);
//file menu items
QAction *save = new QAction(tr("&Save"), this);
filemenu->addAction(save);
connect(save, SIGNAL(triggered()), this, SLOT(save()));
QAction *quit = new QAction(tr("E&xit"), this);
filemenu->addAction(quit);
connect(quit, SIGNAL(triggered()), this, SLOT(quit()));
//compute menu items
QIcon computetrajIcon = QIcon::fromTheme("", QIcon(":/images/tr.png"));
QAction *computetraj= new QAction(tr("&Trajectory"), this);
computetraj->setToolTip(tr("Compute trajectory"));
computemenu->addAction(computetraj);
computetraj->setIcon(computetrajIcon);
connect(computetraj, SIGNAL(triggered()), window->glWidget, SLOT(replot()));
//help menu
QAction *helpitem = new QAction(tr("&Help"), this);
helpmenu->addAction(helpitem);
connect(helpitem, SIGNAL(triggered()), this, SLOT(help()));
QAction *aboutitem = new QAction(tr("&About"), this);
helpmenu->addAction(aboutitem);
connect(aboutitem, SIGNAL(triggered()), this, SLOT(about()));
helpmenu->addSeparator();
QAction *aboutQtitem = new QAction(tr("About &Qt"), this);
helpmenu->addAction(aboutQtitem);
connect(aboutQtitem, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
tb1->addAction (computetraj);
connect (this, SIGNAL(set_gui()), window, SLOT(set_gui()));
connect (this, SIGNAL(set_gui()), window->b1, SLOT(click()));
connect (this, SIGNAL(replot()), window->glWidget, SLOT(replot()));
}
void MainWindow::save()
{
int i;
FILE *outfile;
char tempstring[128];
if (trajcomputed == false) {
statusBar()->showMessage(tr("Nothing to save"));
return;
}
strcpy (tempstring, "default.dat.trajectories");
outfile = fopen (tempstring, "w");
fprintf (outfile, "%.5e %.5e %.5e %.5e %.5e %.5e %.5e %.5e %.5e %.5e %i %i %i\n",
extE.x*300.0, extE.y*300.0, extE.z*300.0,
dE.x*300.0, dE.y*300.0, dE.z*300.0,
extB.x, extB.y, extB.z,
dB.x, bxxch, bxych, bxzch);
for (i = 0; i < max_points_in_traj; i++){
fprintf (outfile, "%i %.5e %.5e %.5e %.5e\n",
i,
(trajectory.time[i]),
(trajectory.trajpoint[i]).x,
(trajectory.trajpoint[i]).y,
(trajectory.trajpoint[i]).z
);
}
fprintf (outfile, "\n");
fclose (outfile);
statusBar()->showMessage(tr("Trajectory saved in file \"default.dat.trajectories\""));
}
void MainWindow::quit()
{
exit(0);
}
void MainWindow::help()
{
QFile helpfile ("./trhelp.pdf");
if (helpfile.exists() == false) {
QMessageBox msgBox;
msgBox.setIcon(QMessageBox::Information);
msgBox.setText(tr("The help file was not found"));
msgBox.exec();
}
else {
QDesktopServices::openUrl (QUrl ("./trhelp.pdf"));
}
}
void MainWindow::about()
//open a window to show program information and copyright license
{
QFile file("COPYING");
QTextStream in(&file);
QTextBrowser *gnugpl;
bool ok;
ok = file.open(QFile::ReadOnly);
if (ok == false)
return;
gnugpl = new QTextBrowser ();
gnugpl->setGeometry(100, 100, 800, 600);
gnugpl->setWindowTitle (QObject::tr("About Trajecstory"));
gnugpl->setPlainText(in.readAll());
gnugpl->setAlignment(Qt::AlignLeft);
gnugpl->show();
}
void MainWindow::initialise_default_system()
{
raystart.x = 0.0;
raystart.y = 5.0;
raystart.z = 0.0;
extP.x = 1e-19;
extP.y = 1e-19;
extP.z = 1e-19;
extE.x = extE.y = extE.z = 0.0;
E.x = extE.x;
E.y = extE.y;
E.z = extE.z;
extB.x = B.x = 5.0;
extB.y = extB.z = B.y = B.z = 0.0;
dE.x = dE.y = dE.z = 0.0;
dB.x = dB.y = dB.z = 0.0;
xmin = ymin = zmin = 0.0;
xmax = 10.0;
ymax = 10.0;
zmax = 10.0;
t2 = 5e-07;
emit set_gui();
}