-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlefStru.h
320 lines (288 loc) · 8.03 KB
/
lefStru.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
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
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#pragma once
#include <vector>
#include <map>
#include <optional>
#include "rect.h"
#include <iostream>
using namespace std;
namespace LEF
{
struct via
{
int m1;
rect viaRect;
rect m1Rect;
rect m2Rect;
};
struct metal
{
int ID;
float minWidth;
float maxNeedWidth=0.6;
float spacing;
float area=-1; //-1为无约束
bool vertical; //false为horizontal
qstring getName() { return "METAL"+qstring::number(ID); }
bool operator==(const metal &m) { return this->ID==m.ID; }
bool operator!=(const metal &m) { return this->ID!=m.ID; }
};
struct pin
{
qstring name;
LEF::metal metal;
vector<pinRect> allRect;
void setToLayout(float setX, float setY, qstring dire)
{
for(pinRect &r : this->allRect)
r.setToLayout(setX,setY,dire);
}
};
typedef map<qstring,vector<rect>> obs; //金属,obs块
struct cell
{
qstring cellName;
qstring instName; //用于在layout中反查使用
float sizeA1;
float sizeA2;
float setX=-1;
float setY=-1;
vector<pin> allPin;
obs o;
void setToLayout(float setX, float setY, qstring dire="N")
{
this->setX=setX;
this->setY=setY;
for(pin &p : this->allPin)
p.setToLayout(setX,setY,dire);
for(auto &p : this->o)
{
vector<rect> &allRect=p.second;
for(rect &r : allRect)
r.setToLayout(setX,setY,dire);
}
}
void setDire(qstring dire) //禁止在未调用setToLayout的情况下调用
{
this->setToLayout(this->setX,this->setY,dire);
}
void plusDbu(int dbu)
{
sizeA1*=dbu;
sizeA2*=dbu;
}
};
}
class line
{
public:
float x1;
float y1;
float x2;
float y2;
LEF::metal metal;
float startPosX;
float startPosY;
float endPosX;
float endPosY;
float width;
line(){}
line(float x1,float y1,float x2,float y2,LEF::metal metal,
float startPosX, float startPosY, float endPosX, float endPosY,float width=-1) :
x1(x1), y1(y1), x2(x2), y2(y2), metal(metal),
startPosX(startPosX), startPosY(startPosY), endPosX(endPosX), endPosY(endPosY)
{
if(width==-1)
this->width=metal.minWidth;
else
this->width=width;
if(this->y1<1 || this->y2<1 ||this->x1<1 || this->x2<1)
cout<<y2<<endl;
}
line(float x,float y,float y2,LEF::metal metal,
float startPosX, float startPosY, float endPosX, float endPosY,bool isVertical=true,float width=-1) :
metal(metal), startPosX(startPosX), startPosY(startPosY), endPosX(endPosX), endPosY(endPosY)
{
if(width==-1)
this->width=metal.minWidth;
else
this->width=width;
float w=this->width/2;
if(isVertical)
{
this->x1=x-w; //x是左边的
this->x2=x+w;
this->y1=y;
this->y2=y2;
}
else //x y反转
{
this->y1=x-w; //x是下边的
this->y2=x+w;
this->x1=y;
this->x2=y2;
}
if(this->y1<1 || this->y2<1 || this->x1<1 || this->x2<1)
cout<<y<<endl;
}
rect toRect()
{
return rect(pos(x1,y1),pos(x2,y2));
}
optional<rect> checkPinRect(LEF::cell &c, pinRect* r1, pinRect* r2)
{
//检查pin里的rect
for(LEF::pin &p : c.allPin)
{
if(p.metal==this->metal)
{
for(pinRect &r : p.allRect)
{
if(&r==r1 || &r==r2)
continue;
if(r.isIntersect(this->toRect(),this->metal.spacing,this->width))
return r;
}
}
}
return optional<rect>();
}
optional<rect> checkOBS(LEF::cell &c)
{
qstring metalName=this->metal.getName();
//检查obs
if (!(c.o.find(metalName) == c.o.end())) //这一层存在obs
{
vector<rect> &allRect=c.o[metalName];
for(rect r : allRect)
{
if(r.isIntersect(this->toRect(),this->metal.spacing,this->width))
return r;
}
}
return optional<rect>();
}
tuple<float,float> getCrossCenter(rect l)
{
float x,y;
//计算中心坐标
float this_center_x = (this->x1 + this->x2)/2;
float this_center_y = (this->y1 + this->y2)/2;
float l_center_x = (l.p1.x + l.p2.x )/2;
float l_center_y = (l.p1.y + l.p2.y )/2;
//中心的相对位置
float location_x = this_center_x - l_center_x;
float location_y = this_center_y - l_center_y;
//根据相对位置判断相交区域
if((location_x > 0) && (location_y > 0)) //this在右上
{
x = (l.p2.x + this->x1)/2;
y = (l.p2.y + this->y1)/2;
}
else if((location_x < 0) && (location_y > 0)) //在左上
{
x = (l.p1.x + this->x2)/2;
y = (l.p2.y + this->y1)/2;
}
else if((location_x > 0) && (location_y < 0)) //在右下
{
x = (l.p2.x + this->x1)/2;
y = (l.p1.y + this->y2)/2;
}
else //在左下
{
x = (l.p1.x + this->x2)/2;
y = (l.p1.y + this->y2)/2;
}
return make_tuple(x,y);
}
tuple<float,float> getCrossCenter(line &l)
{
return this->getCrossCenter(rect(pos(l.x1,l.y1),pos(l.x2,l.y2)));
}
tuple<pos,pos> getMidLine()
{
float dx=this->x2-this->x1;
float dy=this->y2-this->y1;
if(dx<dy)
{
if(this->y1<1)
cout<<y1<<endl;
float xMid=(x2+x1)/2;
return make_tuple(pos(xMid,this->y1),pos(xMid,this->y2));
}
else
{
float yMid=(y2+y1)/2;
if(yMid<1)
cout<<yMid<<endl;
return make_tuple(pos(this->x1,yMid),pos(this->x2,yMid));
}
}
void expendCrossRegion(line &l)
{
//计算中心坐标
float this_center_x = (this->x1 + this->x2)/2;
float this_center_y = (this->y1 + this->y2)/2;
float l_center_x = (l.x1 + l.x2 )/2;
float l_center_y = (l.y1 + l.y2 )/2;
//中心的相对位置
float location_x = this_center_x - l_center_x;
float location_y = this_center_y - l_center_y;
//计算长宽
float this_x = this->x2 - this->x1;
float this_y = this->y2 - this->y1;
//根据相对位置判断相交区域
if((location_x > 0) && (location_y > 0)) //this在右上
{
if(this_x > this_y) //this横l竖
{
this->x1 = l.x1 ;
l.y2 = this->y2;
}
else //this竖l横
{
this->y1 = l.y1 ;
l.x2 = this->x2;
}
}
else if((location_x < 0) && (location_y > 0)) //在左上
{
if(this_x > this_y) //this横l竖
{
this->x2 = l.x2 ;
l.y2 = this->y2;
}
else //this竖l横
{
this->y1 = l.y1 ;
l.x1 = this->x1;
}
}
else if((location_x > 0) && (location_y < 0)) //在右下
{
if(this_x > this_y) //this横l竖
{
this->x1 = l.x1 ;
l.y1 = this->y1;
}
else //this竖l横
{
this->y2 = l.y2 ;
l.x2 = this->x2;
}
}
else //在左下
{
if(this_x > this_y) //this横l竖
{
this->x2 = l.x2 ;
l.y1 = this->y1;
}
else //this竖l横
{
this->y2 = l.y2 ;
l.x1 = this->x1;
}
}
}
};