forked from NHERI-SimCenter/EVW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResponseWidget.cpp
300 lines (236 loc) · 8.74 KB
/
ResponseWidget.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
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
#include "ResponseWidget.h"
#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <MainWindow.h>
#include <qcustomplot.h>
static QLineEdit *
createTextEntry(QString text,
QVBoxLayout *theLayout,
int minL=100,
int maxL=100,
QString *unitText =0)
{
QHBoxLayout *entryLayout = new QHBoxLayout();
QLabel *entryLabel = new QLabel();
entryLabel->setText(text);
QLineEdit *res = new QLineEdit();
res->setMinimumWidth(minL);
res->setMaximumWidth(maxL);
res->setValidator(new QDoubleValidator);
entryLayout->addWidget(entryLabel);
entryLayout->addWidget(res);
entryLayout->addStretch();
if (unitText != 0) {
QLabel *unitLabel = new QLabel();
unitLabel->setText(*unitText);
unitLabel->setMinimumWidth(40);
unitLabel->setMaximumWidth(50);
entryLayout->addWidget(unitLabel);
}
entryLayout->setSpacing(10);
entryLayout->setMargin(0);
theLayout->addLayout(entryLayout);
return res;
}
/* ******************* commenting out external procedure as don't like strecth
extern QLineEdit *
createTextEntry(QString text,
QVBoxLayout *theLayout,
int minL=100,
int maxL=100,
QString *unitText =0);
******************************************************** */
ResponseWidget::ResponseWidget(MainWindow *mainWindow,
int mainItem,
QString &label,
QString &xLabel,
QString &yLabel,
bool verticalLayout,
bool scale,
QWidget *parent)
: QWidget(parent), theItem(0), mainWindowItem(mainItem), main(mainWindow), scalesSame(scale)
{
// create a main layout
QVBoxLayout *mainLayout= new QVBoxLayout();
QLayout *graphsLayout;
if (verticalLayout == true)
graphsLayout = new QVBoxLayout();
else
graphsLayout = new QHBoxLayout();
theItemEdit = createTextEntry(label, mainLayout);
theItemEdit->setValidator(new QIntValidator);
connect(theItemEdit, SIGNAL(editingFinished()), this, SLOT(itemEditChanged()));
thePlot1=new QCustomPlot();
thePlot1->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
QRect rec = QApplication::desktop()->screenGeometry();
int height;
int width;
if (verticalLayout == true) {
height = 0.2*rec.height();
width = 0.5*rec.width();
} else {
height = 0.25*rec.height();
width = 0.25*rec.width();
}
thePlot1->setMinimumWidth(width);
thePlot1->setMinimumHeight(height);
// mainLayout->addWidget(thePlot1);
graphsLayout->addWidget(thePlot1);
thePlot1->xAxis->setLabel(xLabel);
thePlot1->yAxis->setLabel(yLabel);
thePlot2=new QCustomPlot();
thePlot2->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
thePlot2->setMinimumWidth(width);
thePlot2->setMinimumHeight(height);
// mainLayout->addWidget(thePlot2);
graphsLayout->addWidget(thePlot2);
thePlot2->xAxis->setLabel(xLabel);
thePlot2->yAxis->setLabel(yLabel);
mainLayout->addLayout(graphsLayout);
this->setLayout(mainLayout);
}
ResponseWidget::~ResponseWidget()
{
}
int
ResponseWidget::getItem() {
return theItem;
}
void
ResponseWidget::setItem(int newItem) {
theItem = newItem;
theItemEdit->setText(QString::number(newItem));
}
void
ResponseWidget::itemEditChanged() {
int oldItem = theItem;
QString textItems = theItemEdit->text();
theItem = textItems.toInt();
qDebug() << "ResponeWidget " << theItem << mainWindowItem;
if (oldItem == theItem)
return;
if (theItem <= 0 || theItem > main->getNumFloors()) {
theItem=oldItem;
theItemEdit->setText(QString::number(theItem));
} else {
main->setResponse(theItem, mainWindowItem);
}
}
void
ResponseWidget::setData(QVector<double> &data1, QVector<double> &data2, QVector<double> &time, int numSteps, double dt) {
double minValue = 0;
double maxValue = 0;
for (int i=0; i<numSteps; i++) {
double value = data1.at(i);
if (value < minValue)
minValue = value;
if (value > maxValue)
maxValue = value;
}
if (scalesSame == true) {
for (int i=0; i<numSteps; i++) {
double value = data2.at(i);
if (value < minValue)
minValue = value;
if (value > maxValue)
maxValue = value;
}
}
thePlot1->clearGraphs();
graph = thePlot1->addGraph();
thePlot1->graph(0)->setData(time, data1);
thePlot1->xAxis->setRange(0, numSteps*dt);
thePlot1->yAxis->setRange(minValue, maxValue);
thePlot1->axisRect()->setMargins(QMargins(0,0,0,0));
if (scalesSame == false) {
qDebug() << mainWindowItem << scalesSame;
minValue = 0;
maxValue = 0;
for (int i=0; i<numSteps; i++) {
double value = data2.at(i);
if (value < minValue)
minValue = value;
if (value > maxValue)
maxValue = value;
}
}
thePlot2->clearGraphs();
graph = thePlot2->addGraph();
thePlot2->graph(0)->setData(time, data2);
thePlot2->xAxis->setRange(0, numSteps*dt);
thePlot2->yAxis->setRange(minValue, maxValue);
//thePlot->axisRect()->setAutoMargins(QCP::msNone);
thePlot2->axisRect()->setMargins(QMargins(0,0,0,0));
QCPItemText *textLabel1 = new QCPItemText(thePlot1);
textLabel1->setPositionAlignment(Qt::AlignTop|Qt::AlignRight);
textLabel1->position->setType(QCPItemPosition::ptAxisRectRatio);
textLabel1->position->setCoords(1, 0); // place position at center/top of axis rect
textLabel1->setText("Earthquake");
textLabel1->setFont(QFont(font().family(), 16)); // make font a bit larger
QCPItemText *textLabel2 = new QCPItemText(thePlot2);
textLabel2->setPositionAlignment(Qt::AlignTop|Qt::AlignRight);
textLabel2->position->setType(QCPItemPosition::ptAxisRectRatio);
textLabel2->position->setCoords(1, 0); // place position at center/top of axis rect
textLabel2->setText("Wind");
textLabel2->setFont(QFont(font().family(), 16)); // make font a bit larger
thePlot1->replot();
thePlot2->replot();
}
void
ResponseWidget::setData(QVector<double> &data1, QVector<double> &x1,QVector<double> &data2, QVector<double> &x2, int numSteps) {
thePlot1->clearGraphs();
//thePlot->clearItems();
thePlot1->clearPlottables();
curve1 = new QCPCurve(thePlot1->xAxis, thePlot1->yAxis);
curve1->setData(x1,data1);
thePlot2->clearGraphs();
//thePlot->clearItems();
thePlot2->clearPlottables();
curve2 = new QCPCurve(thePlot2->xAxis, thePlot2->yAxis);
curve2->setData(x2,data2);
QCPItemText *textLabel1 = new QCPItemText(thePlot1);
textLabel1->setPositionAlignment(Qt::AlignTop|Qt::AlignRight);
textLabel1->position->setType(QCPItemPosition::ptAxisRectRatio);
textLabel1->position->setCoords(1, 0); // place position at center/top of axis rect
textLabel1->setText("Earthquake");
textLabel1->setFont(QFont(font().family(), 16)); // make font a bit larger
QCPItemText *textLabel2 = new QCPItemText(thePlot2);
textLabel2->setPositionAlignment(Qt::AlignTop|Qt::AlignRight);
textLabel2->position->setType(QCPItemPosition::ptAxisRectRatio);
textLabel2->position->setCoords(1, 0); // place position at center/top of axis rect
textLabel2->setText("Wind");
textLabel2->setFont(QFont(font().family(), 16)); // make font a bit larger
thePlot1->addGraph();
thePlot1->graph(0)->setName("Earthquake");
//thePlot2->plotLayout()->addElement(0, 0, new QCPTextElement(thePlot2, "Wind"));
//thePlot->graph(0)->setData(x, data, true);
double minValue = 0;
double maxValue = 0;
double xMinValue = 0;
double xMaxValue = 0;
for (int i=0; i<numSteps; i++) {
double value = data1.at(i);
double xValue = x1.at(i);
if (value < minValue)
minValue = value;
if (value > maxValue)
maxValue = value;
if (xValue < xMinValue)
xMinValue = xValue;
if (xValue > xMaxValue)
xMaxValue = xValue;
}
//
thePlot1->yAxis->setRange(minValue, maxValue);
thePlot1->xAxis->setRange(xMinValue, xMaxValue);
//thePlot->axisRect()->setAutoMargins(QCP::msNone);
// thePlot->axisRect()->setMargins(QMargins(0,0,0,0));
thePlot1->replot();
thePlot2->yAxis->setRange(minValue, maxValue);
thePlot2->xAxis->setRange(xMinValue, xMaxValue);
//thePlot->axisRect()->setAutoMargins(QCP::msNone);
// thePlot->axisRect()->setMargins(QMargins(0,0,0,0));
thePlot2->replot();
}