-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnewlayer.cpp
More file actions
189 lines (173 loc) · 4.47 KB
/
newlayer.cpp
File metadata and controls
189 lines (173 loc) · 4.47 KB
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
#include "newlayer.h"
NewLayer::NewLayer(QString filePath, QColor color)
{
analysisFile(readFile(filePath));
layerColor = color;
}
NewLayer::FSN::FSN(QString dataString, QString units){
QStringList stringList = dataString.split(" ");
QString IDstr = stringList.at(0);
IDstr = IDstr.remove(0,1); //remove $
id = IDstr.toInt();
QString data = stringList.at(1);
data.remove("\r\n");
data.remove("\n");
if (data.contains("rect")){
type = "rect";
data = data.remove(0,4); //remove rect
QStringList size = data.split("x");
sizeX = size.at(0).toDouble();
sizeY = size.at(1).toDouble();
return;
} else if (data.contains("r")){
type = "round";
data = data.remove(0,1); //remove r
sizeX = data.toDouble();
sizeY = data.toDouble();
return;
}
if (data.contains("s")){
type = "square";
data = data.remove(0,1); //remove s
sizeX = data.toDouble();
sizeY = data.toDouble();
return;
}
if (data.contains("oval")){
type = "oval";
data = data.remove(0,4); //remove oval
QStringList size = data.split("x");
sizeX = size.at(0).toDouble();
sizeY = size.at(1).toDouble();
return;
}
}
NewLayer::Line::Line(QString dataString){
QStringList data = dataString.split(" ");
xS = data.at(1).toDouble();
yS = data.at(2).toDouble();
xE = data.at(3).toDouble();
yE = data.at(4).toDouble();
id = data.at(5).toInt();
}
NewLayer::Pad::Pad(QString dataString){
QStringList data = dataString.split(" ");
x = data.at(1).toDouble();
y = data.at(2).toDouble();
id = data.at(3).toInt();
}
NewLayer::~NewLayer(){
}
QStringList NewLayer::readFile(QString fileName)
{
QFile file(fileName);
QByteArray dataArray;
QStringList dataList;
if (!file.open(QIODevice::ReadOnly))
{
dataList.insert(0,"error");
return dataList;
}
int i=0;
while(!file.atEnd())
{
dataArray = file.readLine();
QString data=dataArray.data();
dataList.insert(i,data);
i++;
}
return dataList;
}
void NewLayer::analysisFile(QStringList data)
{
QChar op;
QString currentStr;
for (int i=0;i<data.size();i++)
{
currentStr = data.at(i);
op = currentStr.at(0);
if (i<10){ //searching for order or ID
if (currentStr.contains("ID=")){
QString stringID = currentStr.split("=").at(1);
stringID.remove("\n");
order = stringID.toInt();
} else if(currentStr.contains("Layer_Physical_Order")){
QString stringID = currentStr.split("=").at(1);
stringID.remove("\r\n");
order = stringID.toInt();
}
}
if (op == 'U') {
QString unitStr = currentStr.split("=").at(1);
unitStr = unitStr.remove(unitStr.length()-1,3);
if (unitStr == "MM") UNITS = "MM";
}
if (op == '$') FSNList.append(new FSN(currentStr, UNITS));
if (op == 'L') lineList.append(new Line(currentStr));
if (op == 'P') padList.append(new Pad(currentStr));
}
}
//-------Layer getters
QList<NewLayer::FSN *> NewLayer::getFSNList(){
return FSNList;
}
QList<NewLayer::Line *> NewLayer::getLineList(){
return lineList;
}
QList<NewLayer::Pad *> NewLayer::getPadList(){
return padList;
}
QString NewLayer::getUnits(){
return UNITS;
}
NewLayer::FSN* NewLayer::getFSNviaID(int necessaryId){
foreach(NewLayer::FSN* fsn, FSNList){
if (necessaryId == fsn->getId())
return fsn;
}
}
QColor NewLayer::getColor(){
return layerColor;
}
int NewLayer::getOrder(){
return order;
}
//-------FSN getters
int NewLayer::FSN::getId(){
return id;
}
double NewLayer::FSN::getSizeX(){
return sizeX;
}
double NewLayer::FSN::getSizeY(){
return sizeY;
}
QString NewLayer::FSN::getType(){
return type;
}
//-------Line getters
double NewLayer::Line::getXS(){
return xS;
}
double NewLayer::Line::getYS(){
return yS;
}
double NewLayer::Line::getXE(){
return xE;
}
double NewLayer::Line::getYE(){
return yE;
}
int NewLayer::Line::getId(){
return id;
}
//-------Pad getters
double NewLayer::Pad::getX(){
return x;
}
double NewLayer::Pad::getY(){
return y;
}
int NewLayer::Pad::getId(){
return id;
}