-
Notifications
You must be signed in to change notification settings - Fork 0
/
TopologyReader.h
167 lines (129 loc) · 4.68 KB
/
TopologyReader.h
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
#ifndef TOPOLOGYREADER_H
#define TOPOLOGYREADER_H
#include <QtCore>
#include <QThread>
#include <QImage>
#include "JlCompress.h"
#include "Topology/TopologyMap.h"
#include "Topology/TopologyMapA.h"
#include "Topology/TopologyMapB.h"
#include "Topology/TopologyMapBi.h"
#include "Topology/TopologyMapC.h"
#include "Topology/TopologyMapCi.h"
#include "Topology/TopologyMapDi.h"
#include "DialogTopology.h"
class TopologyReader : public QThread
{
Q_OBJECT
public:
TopologyReader(QObject* parent = 0) : QThread(parent) {}
~TopologyReader() {}
void setPath(QString path) { _path = path; }
protected:
virtual void run()
{
int width = 2000;
int height = 2000;
QImage topology(width, height, QImage::Format_RGB32);
QByteArray coord;
QuaZip archive(_path);
archive.open(QuaZip::mdUnzip);
resetProgressBar(archive.getEntriesCount() - 3);
QuaZipFile file(&archive);
for (bool f = archive.goToFirstFile(); f; f = archive.goToNextFile())
{
QString filePath = archive.getCurrentFileName();
if (filePath.contains("META"))
continue;
file.open(QIODevice::ReadOnly);
QByteArray ba = file.readAll();
file.close();
if (filePath.contains("coord"))
{
coord = ba;
continue;
}
//qDebug() << "==========";
//qDebug() << "File :" << filePath << " Size : " << ba.size();
short mapx = filePath.split("_").at(0).toShort();
short mapy = filePath.split("_").at(1).toShort();
//qDebug() << "X:" << mapx;
//qDebug() << "Y:" << mapy;
BinaryReader* reader = new BinaryReader(ba);
qint8 type = reader->readByte();
//qDebug() << "Map type:" << type;
TopologyMap* tplg = nullptr;
switch (type)
{
case 0: tplg = new TopologyMapA(reader); break;
case 1: tplg = new TopologyMapB(reader); break;
case 2: tplg = new TopologyMapBi(reader); break;
case 3: tplg = new TopologyMapC(reader); break;
case 4: tplg = new TopologyMapCi(reader); break;
case 5: tplg = new TopologyMapD(reader); break;
default:
qDebug() << "[Error] Map type unkown!";
return;
}
tplg->read();
//tplg->print();
// Generate map
for (int y = 0; y < 18; y++)
{
for (int x = 0; x < 18; x++)
{
int offsetx = (mapx * 18) + x;
int offsety = (mapy * 18) + y;
qint8 res = tplg->isCellBlocked(offsetx, offsety);
if (res == 1)
{
topology.setPixelColor(offsetx + (width/2), offsety + (height/2), Qt::GlobalColor::darkGreen);
//qDebug() << "[" << offsetx << "," << offsety << ",1]";
}
else if (res == 0)
{
topology.setPixelColor(offsetx + (width/2), offsety + (height/2), Qt::GlobalColor::green);
//qDebug() << "[" << offsetx << "," << offsety << ",0]";
}
else if (res == -1)
{
topology.setPixelColor(offsetx + (width/2), offsety + (height/2), Qt::GlobalColor::gray);
//qDebug() << "EMPTY CELL";
}
}
}
delete tplg;
updateProgressBar();
}
archive.close();
QDir dir(QCoreApplication::applicationDirPath());
#ifdef Q_OS_MAC
dir.cdUp();
dir.cdUp();
dir.cdUp();
#endif
topology.save(dir.absolutePath() + "/" + _path.split("/").last().remove(".jar") + ".png", "PNG");
// Partition coords
if (coord.size())
{
BinaryReader* c = new BinaryReader(coord, QDataStream::BigEndian);
QVector<int> coords;
coords.reserve(coord.size() / 4);
for (int i = 0; i < coords.capacity(); ++i)
{
qint32 twoInts = c->readInt();
qDebug() << "["<<i<<"] X:" << qint16(twoInts >> 16);
qDebug() << "["<<i<<"] Y:" << qint16(twoInts & 0xFFFF);
}
}
updateTopology(topology);
}
signals:
void resetTopology();
void resetProgressBar(int max);
void updateProgressBar();
void updateTopology(QImage topology);
private:
QString _path;
};
#endif // TOPOLOGYREADER_H