-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
bandpassbox.cpp
174 lines (139 loc) · 4.03 KB
/
bandpassbox.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
#include <QDebug>
#include <QObject>
#include "bandpassbox.h"
BandPassBox::BandPassBox(double svol, double pvol, double pfreq, unsigned int pnum, double plen, double pdiam) :
sealedBox(svol),
portedBox(pvol, pfreq, pnum, plen, pdiam)
{
}
void BandPassBox::setSealedBoxVolume(double vol)
{
sealedBox.setVolume(vol);
}
void BandPassBox::setPortedBoxVolume(double vol)
{
portedBox.setBoxVolume(vol);
}
void BandPassBox::setPortedBoxPortNum(unsigned int val)
{
portedBox.setPortNum(val);
}
void BandPassBox::setPortedBoxPortLen(double len)
{
portedBox.setPortLen(len);
}
void BandPassBox::setPortedBoxPortDiam(double diam)
{
portedBox.setPortDiam(diam);
}
void BandPassBox::setPortedBoxSlotWidth(double width)
{
portedBox.setSlotWidth(width);
}
void BandPassBox::setPortedBoxResFreq(double freq)
{
portedBox.setResFreq(freq);
}
void BandPassBox::setPortedBoxSlotPortActivated(bool enable)
{
portedBox.setSlotPortActivated(enable);
}
void BandPassBox::updatePortedBoxPorts(double sd, double xmax)
{
portedBox.updatePorts(sd, xmax);
}
void BandPassBox::updatePortedBoxPortsLength()
{
portedBox.updatePortsLength();
}
void BandPassBox::updatePortedBoxSlots()
{
portedBox.updateSlots();
}
double BandPassBox::getSealedBoxVolume() const
{
return sealedBox.getVolume();
}
double BandPassBox::getPortedBoxVolume() const
{
return portedBox.getBoxVolume();
}
unsigned int BandPassBox::getPortedBoxPortNum() const
{
return portedBox.getPortNum();
}
double BandPassBox::getPortedBoxPortLen() const
{
return portedBox.getPortLen();
}
double BandPassBox::getPortedBoxPortDiam() const
{
return portedBox.getPortDiam();
}
bool BandPassBox::getPortedBoxSlotPortActivated() const
{
return portedBox.getSlotPortActivated();
}
double BandPassBox::getPortedBoxSlotWidth() const
{
return portedBox.getSlotWidth();
}
double BandPassBox::getPortedBoxSlotHeight() const
{
return portedBox.getSlotHeight();
}
double BandPassBox::getPortedBoxResFreq(void) const
{
return portedBox.getResFreq();
}
QDomElement BandPassBox::toDomElement(QDomDocument &doc) const
{
QDomElement e = Box::toDomElement(doc);
e.setAttribute("type", "bandpass");
QDomElement b = sealedBox.toDomElement(doc);
e.appendChild(b);
QDomElement c = portedBox.toDomElement(doc);
e.appendChild(c);
return e;
}
void BandPassBox::fromDomElement(const QDomElement &e)
{
Box::fromDomElement(e);
if (e.attribute("type") != "bandpass") {
qWarning() << __func__ << "wrong box type! (not bandpass, giving up)";
return;
}
QDomElement b = e.firstChildElement("box");
while (!b.isNull()) {
if (b.attribute("type") == "sealed")
sealedBox.fromDomElement(b);
else if (b.attribute("type") == "ported")
portedBox.fromDomElement(b);
b = b.nextSiblingElement("box");
}
}
void BandPassBox::render(QPainter *painter, const QRectF &area) const
{
if (!painter)
return;
QString params[6];
qreal tab = area.left();
painter->drawRoundedRect(area.toRect(), 5, 5);
params[0] = QObject::tr("Sealed Vol. %1 L").arg(getSealedBoxVolume());
params[1] = QObject::tr("Ported Vol. %1 L").arg(getPortedBoxVolume());
if (!getPortedBoxSlotPortActivated()) {
params[2] = QObject::tr("Port Diam. %1 cm").arg(getPortedBoxPortDiam());
} else {
params[2] = QObject::tr("Slot port %1 x %2 cm").arg(QString::number(getPortedBoxSlotWidth(), 'f', 2), QString::number(getPortedBoxSlotHeight(), 'f', 2));
}
params[3] = QObject::tr("Port Len. %1 cm").arg(QString::number(getPortedBoxPortLen(), 'f', 2));
params[4] = QObject::tr("Port Num. %1").arg(getPortedBoxPortNum());
params[5] = QObject::tr("Fb %1 Hz").arg(getPortedBoxResFreq());
for (int i = 0; i < 6; i++) {
QString text = params[i];
QRectF where(tab, area.top(), area.width() / 6, area.height());
QTextOption option(Qt::AlignVCenter|Qt::AlignLeft);
painter->drawText(where, text, option);
tab += area.width() / 6;
}
}