-
Notifications
You must be signed in to change notification settings - Fork 0
/
RenderArea.cpp
177 lines (163 loc) · 6.19 KB
/
RenderArea.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
#include "RenderArea.h"
#include "Tables.h"
#include <QGraphicsPixmapItem>
RenderArea::RenderArea(QWidget* parent): QGraphicsView(parent)
{
setMinimumSize(200, 400);
_scene = new QGraphicsScene();
_view = new QGraphicsView(_scene);
setScene(_scene);
connect(_scene, &QGraphicsScene::changed, this, &RenderArea::changeScene);
}
void RenderArea::drawConstruction(const Params& params)
{
vecForDraw = params.type_for_each_rod;
scaling();
_scene->clear();
double coordX = 0;
double coordY = 0;
double endX = 0;
_items.resize(vecForDraw.size());
for (auto i = 0; i < _items.size(); ++i)
{
endX += vecForDraw[i][4];
if (i == 0)
{
coordX = 0;
coordY = vecForDraw[i][1]/2;
}
else
coordX = coordX + vecForDraw[i-1][4];
_items[i] = new QGraphicsRectItem(coordX, coordY - vecForDraw[i][1]/2,
vecForDraw[i][4], vecForDraw[i][1]);
_scene->addItem(_items[i]);
drawDistrLoads(i, params, coordX, coordY); // отрисовка продольных нагрузок
drawCentredLoads(i, params, coordX, coordY); // отрисовка сосредоточенных нагрузок
}
drawCentredLoads(params.centred_loads.size() - 1, params, endX, coordY);
drawFixedNodes(params, coordY, endX);
}
void RenderArea::drawDistrLoads(const int& i, const Params& params,const double& coordX, const double& coordY)
{
if (params.distr_loads[i] > 0)
{
QPixmap pixmap(":/resources/img/distrLoads+.jpg");
drawDistr(pixmap, coordX, coordY, i);
}
if (params.distr_loads[i] < 0)
{
QPixmap pixmap(":/resources/img/distrLoads-.jpg");
drawDistr(pixmap, coordX, coordY, i);
}
}
void RenderArea::drawFixedNodes(const Params& params, const double& coordY, const double& endX)
{
if (params.fixed_nodes[0] == 1)
{
QPixmap pixmap(":/resources/img/left.jpg");
QGraphicsPixmapItem* item = _scene->addPixmap(pixmap);
item->setPos(0 - pixmap.width(), coordY - pixmap.height()/2);
}
if (params.fixed_nodes[1] == params.centred_loads.size())
{
QPixmap pixmap(":/resources/img/right.jpg");
QGraphicsPixmapItem* item = _scene->addPixmap(pixmap);
item->setPos(endX + 1, coordY - pixmap.height()/2);
}
}
void RenderArea::drawDistr(QPixmap& pixmap, const double& coordX, const double& coordY,
const int& i)
{
double a = vecForDraw[i][4];
double coord_for_distr = coordX;
int check_scale_for_distr = static_cast<int>(vecForDraw[i][4]/pixmap.width());
int rest = int(a) % pixmap.width();
if (pixmap.width() <= vecForDraw[i][4])
pixmap = pixmap.scaled(pixmap.width(), static_cast<int>(vecForDraw[i][1]/6), Qt::IgnoreAspectRatio);
else
pixmap = pixmap.scaled(static_cast<int>(vecForDraw[i][4]),
static_cast<int>(vecForDraw[i][1]/6), Qt::IgnoreAspectRatio);
for (auto j = 0; j <= check_scale_for_distr; ++j)
{
if (j == check_scale_for_distr)
{
pixmap = pixmap.copy(0, 0, rest, pixmap.height());
QGraphicsPixmapItem* item = _scene->addPixmap(pixmap);
item->setPos(coord_for_distr, coordY - pixmap.height()/2);
}
else
{
QGraphicsPixmapItem* item = _scene->addPixmap(pixmap);
item->setPos(coord_for_distr, coordY - pixmap.height()/2);
}
coord_for_distr += pixmap.width();
}
}
void RenderArea::drawCentredLoads(const int& i, const Params& params, const double& coordX, const double& coordY)
{
if (params.centred_loads[i] > 0)
{
QPixmap pixmap(":/resources/img/centredLoads+.jpg");
drawCentred(pixmap, params, coordX, coordY, i);
}
if (params.centred_loads[i] < 0)
{
QPixmap pixmap(":/resources/img/centredLoads-.jpg");
drawCentred(pixmap, params, coordX, coordY, i);
}
}
void RenderArea::drawCentred(QPixmap &pixmap, const Params ¶ms, const double &coordX, const double &coordY, const int &i)
{
int j = i;
if (i == params.centred_loads.size() - 1)
{
--j;
if (params.centred_loads[i] < 0)
{
pixmap = pixmap.scaled(static_cast<int>(vecForDraw[j][4]/6),
static_cast<int>(vecForDraw[j][1]/6), Qt::IgnoreAspectRatio);
}
if (params.centred_loads[i] > 0)
{
pixmap = pixmap.scaled(static_cast<int>(vecForDraw[j][4]/6),
static_cast<int>(vecForDraw[j][1]/6), Qt::IgnoreAspectRatio);
}
}
else
{
if (params.centred_loads[i] > 0 || i == 0)
pixmap = pixmap.scaled(static_cast<int>(vecForDraw[i][4]/6),
static_cast<int>(vecForDraw[i][1]/6), Qt::IgnoreAspectRatio);
if (params.centred_loads[i] < 0 && i != 0)
pixmap = pixmap.scaled(static_cast<int>(vecForDraw[i-1][4]/6),
static_cast<int>(vecForDraw[i-1][1]/6), Qt::IgnoreAspectRatio);
}
QGraphicsPixmapItem* item = _scene->addPixmap(pixmap);
if (params.centred_loads[i] > 0)
item->setPos(coordX, coordY - pixmap.height()/2);
else if (params.centred_loads[i] < 0)
item->setPos(coordX - pixmap.width(), coordY - pixmap.height()/2);
}
void RenderArea::changeScene()
{
QRectF rect = _scene->itemsBoundingRect();
_scene->setSceneRect(rect);
}
void RenderArea::scaling()
{
double allLength = 0;
double maxWidth = 0;
for (auto i = 0; i < vecForDraw.size(); ++i)
{
allLength += vecForDraw[i][4];
if (vecForDraw[i][1] > maxWidth)
maxWidth = vecForDraw[i][1];
}
double kForL = 1600 / allLength;
double kForW = 400 / maxWidth;
for (auto i = 0; i < vecForDraw.size(); ++i)
{
vecForDraw[i][1] = vecForDraw[i][1]*kForW;
vecForDraw[i][4] = vecForDraw[i][4]*kForL;
}
}