-
Notifications
You must be signed in to change notification settings - Fork 19
/
SatelliteWindow.cpp
executable file
·202 lines (180 loc) · 7.2 KB
/
SatelliteWindow.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
#include "SatelliteWindow.h"
SatelliteWindow::SatelliteWindow(bool isNew, Satellite *sat, Planet *planet, QWidget *parent) : QDialog(parent)
{
m_isNew = isNew;
m_sat = sat;
m_planet = planet;
setModal(true);
setWindowTitle("Configure satellite");
mainLayout = new QVBoxLayout;
satFrame = new QGroupBox("General information", this);
orbFrame = new QGroupBox("Orbit", this);
attFrame = new QGroupBox("Attitude", this);
propFrame = new QGroupBox("Propulsion engine", this);
mainLayout->addWidget(satFrame);
mainLayout->addWidget(orbFrame);
mainLayout->addWidget(attFrame);
mainLayout->addWidget(propFrame);
satForm = new QFormLayout(satFrame);
orbForm = new QFormLayout(orbFrame);
attForm = new QFormLayout(attFrame);
propForm = new QFormLayout(propFrame);
//General information
satNameF = new QLineEdit;
QRegExp filter("^[^\]\[ ]+$");
QRegExpValidator *v = new QRegExpValidator(filter);
satNameF->setValidator(v);
satForm->addRow("Satellite name:", satNameF);
importButton = new QPushButton("Import satellite");
satForm->addWidget(importButton);
//Orbit
aBox = new QDoubleSpinBox;
aBox->setDecimals(3);
aBox->setSingleStep(1.0);
aBox->setMinimum(m_planet->getRadius()); // Initially set minimum to R but adapt it in onEChanged slot
aBox->setMaximum(Constants::maxSatA);
aBox->setToolTip(QString("[%1 , %2]").arg(aBox->minimum()).arg(aBox->maximum()));
orbForm->addRow("Semimajor axis (km):", aBox);
eBox = new QDoubleSpinBox;
eBox->setDecimals(8);
eBox->setSingleStep(0.01);
eBox->setMinimum(0.0);
eBox->setMaximum(0.999); // Initially set maximum to 1.0 but adapt it in onAChanged slot
eBox->setToolTip(QString("[%1 , %2]").arg(eBox->minimum()).arg(eBox->maximum()));
orbForm->addRow("Eccentricity:", eBox);
iBox = new QDoubleSpinBox;
iBox->setDecimals(4);
iBox->setSingleStep(0.1);
iBox->setMinimum(0.0);
iBox->setMaximum(Constants::pi);
iBox->setToolTip(QString("[%1 , %2]").arg(iBox->minimum()).arg(iBox->maximum()));
orbForm->addRow("Inclination (rad):", iBox);
OmBox = new QDoubleSpinBox;
OmBox->setDecimals(4);
OmBox->setSingleStep(0.1);
OmBox->setMinimum(0.0);
OmBox->setMaximum(Constants::twopi);
OmBox->setToolTip(QString("[%1 , %2]").arg(OmBox->minimum()).arg(OmBox->maximum()));
orbForm->addRow("Longitude of the ascending node (rad):", OmBox);
omBox = new QDoubleSpinBox;
omBox->setDecimals(4);
omBox->setSingleStep(0.1);
omBox->setMinimum(0.0);
omBox->setMaximum(Constants::twopi);
omBox->setToolTip(QString("[%1 , %2]").arg(omBox->minimum()).arg(omBox->maximum()));
orbForm->addRow("Argument of periapsis (rad):", omBox);
tpBox = new QDoubleSpinBox;
tpBox->setDecimals(4);
tpBox->setSingleStep(1.0);
double period = 1.0/Constants::twopi*std::sqrt(std::pow(aBox->value(), 3.0)/m_planet->getMu());
tpBox->setRange(-period, period); // Update with onAChanged slot
tpBox->setToolTip(QString("[%1 , %2]").arg(tpBox->minimum()).arg(tpBox->maximum()));
orbForm->addRow("Epoch (s) - can be negative:", tpBox);
//Attitude
rxBox = new QDoubleSpinBox;
rxBox->setDecimals(4);
rxBox->setSingleStep(0.1);
rxBox->setMinimum(0.0);
rxBox->setMaximum(Constants::twopi);
rxBox->setToolTip(QString("[%1 , %2]").arg(rxBox->minimum()).arg(rxBox->maximum()));
attForm->addRow("Rotation around X axis (rad):", rxBox);
ryBox = new QDoubleSpinBox;
ryBox->setDecimals(4);
ryBox->setSingleStep(0.1);
ryBox->setMinimum(0.0);
ryBox->setMaximum(Constants::twopi);
ryBox->setToolTip(QString("[%1 , %2]").arg(ryBox->minimum()).arg(ryBox->maximum()));
attForm->addRow("Rotation around Y axis (rad):", ryBox);
rzBox = new QDoubleSpinBox;
rzBox->setDecimals(4);
rzBox->setSingleStep(0.1);
rzBox->setMinimum(0.0);
rzBox->setMaximum(Constants::twopi);
rzBox->setToolTip(QString("[%1 , %2]").arg(rzBox->minimum()).arg(rzBox->maximum()));
attForm->addRow("Rotation around Z axis (rad):", rzBox);
//Propulsion
//TO DO
//Confirm button
confirmButton = new QPushButton;
if(isNew)
confirmButton->setText("Add satellite");
else
confirmButton->setText("Apply");
confirmButton->setDefault(true);
mainLayout->addWidget(confirmButton);
setLayout(mainLayout);
//If existing satellite, use its values in form, else default values
if(!isNew)
{
satNameF->setText(m_sat->getName().c_str());
aBox->setValue(m_sat->getOrbit()->getA());
aBox->setMinimum(m_planet->getRadius()/(1.0-m_sat->getOrbit()->gete()));
aBox->setToolTip(QString("[%1 , %2]").arg(aBox->minimum()).arg(aBox->maximum()));
eBox->setValue(m_sat->getOrbit()->gete());
eBox->setMaximum(1.0-m_planet->getRadius()/m_sat->getOrbit()->getA());
eBox->setToolTip(QString("[%1 , %2]").arg(eBox->minimum()).arg(eBox->maximum()));
iBox->setValue(m_sat->getOrbit()->getI());
OmBox->setValue(m_sat->getOrbit()->getOmega());
omBox->setValue(m_sat->getOrbit()->getomega());
tpBox->setValue(m_sat->getOrbit()->getTp());
rxBox->setValue(m_sat->getRx());
ryBox->setValue(m_sat->getRy());
rzBox->setValue(m_sat->getRz());
}
else
{
satNameF->setText("Satellite");
aBox->setValue(m_planet->a_geo());
eBox->setValue(0.0);
iBox->setValue(0.0);
OmBox->setValue(0.0);
omBox->setValue(0.0);
tpBox->setValue(0.0);
rxBox->setValue(0.0);
ryBox->setValue(0.0);
rzBox->setValue(0.0);
}
connect(aBox, SIGNAL(valueChanged(double)), this, SLOT(onAChanged(double)));
connect(eBox, SIGNAL(valueChanged(double)), this, SLOT(onEChanged(double)));
connect(confirmButton, SIGNAL(clicked()), this, SLOT(confirmSlot()));
}
SatelliteWindow::~SatelliteWindow()
{
}
void SatelliteWindow::confirmSlot(void)
{
if(satNameF->text().isEmpty())
{
QMessageBox::warning(this, "Empty name", "Please enter a satellite name !");
return;
}
m_sat->setName(satNameF->text().toStdString());
m_sat->getOrbit()->setA(aBox->value());
m_sat->getOrbit()->sete(eBox->value());
m_sat->getOrbit()->setI(iBox->value());
m_sat->getOrbit()->setOmega(OmBox->value());
m_sat->getOrbit()->setomega(omBox->value());
m_sat->getOrbit()->setTp(tpBox->value());
m_sat->setRx(rxBox->value());
m_sat->setRy(ryBox->value());
m_sat->setRz(rzBox->value());
done(QDialog::Accepted);
}
void SatelliteWindow::onAChanged(double a)
{
//update e maximum
eBox->setMaximum(1.0-m_planet->getRadius()/a);
eBox->setToolTip(QString("[%1 , %2]").arg(eBox->minimum()).arg(eBox->maximum()));
//update tp range
double period = 1.0/Constants::twopi*std::sqrt(std::pow(aBox->value(), 3.0)/m_planet->getMu());
tpBox->setRange(-period, period);
tpBox->setToolTip(QString("[%1 , %2]").arg(tpBox->minimum()).arg(tpBox->maximum()));
return;
}
void SatelliteWindow::onEChanged(double e)
{
//update a minimum
aBox->setMinimum(m_planet->getRadius()/(1.0-e));
aBox->setToolTip(QString("[%1 , %2]").arg(aBox->minimum()).arg(aBox->maximum()));
return;
}