1 // GDS3D, a program for viewing GDSII files in 3D.
2 // Created by Jasper Velner and Michiel Soer, http://icd.el.utwente.nl
3 // Based on code by Roger Light, http://atchoo.org/gds2pov/
4 //
5 // Copyright (C) 2013 IC-Design Group, University of Twente.
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20
21 #ifndef __GDSOBJECT_H__
22 #define __GDSOBJECT_H__
23
24 #include "gds_globals.h"
25 #include "process_cfg.h"
26 #include "gdselements.h"
27 #include "gdspath.h"
28 #include "gdstext.h"
29 #include "gdspolygon.h"
30
31 class PolySpace {
32 private:
33 bool _hasBBox;
34
35 GDSBB BBox;
36 size_t cur_size;
37 protected:
38 public:
PolySpace()39 PolySpace() { _hasBBox = false; cur_size = 0; BBox.clear();
40 }
41 vector<GDSPolygon*> polys;
42 ~PolySpace();
43 void Clear();
44 void Add(vector<GDSPolygon*> polyList);
45 void Add(GDSPolygon* poly);
46 bool Remove(GDSPolygon* poly);
47 bool Update(GDSPolygon * poly);
48 vector<GDSPolygon*> Get();
49 GDSBB GetBB();
50 size_t size();
51 };
52
53 class PolygonSort
54 {
55 private:
56 // Temp list with full size
57 PolySpace polys;
58
59 // List of poly devided by space area
60 map < GDSBB, PolySpace> PolyBySpace;
61 public:
62 void Add(vector<GDSPolygon*> polyList);
63 bool Add(GDSPolygon* poly);
64 map<GDSBB, PolySpace>::iterator Find(GDSPolygon * poly);
65 bool Remove(GDSPolygon* poly);
66 bool Remove(GDSPolygon * poly, GDSBB polyBBox);
67 bool Update(GDSPolygon * poly, GDSBB prevBB);
68 vector<GDSPolygon*> Get();
69 vector<GDSPolygon*> GetPolyInside(GDSBB BBox);
70 vector<GDSPolygon*> GetPolyNear(GDSBB BBox);
71 void SpaceDiv(PolySpace poly_list);
72 size_t GetPolyBySpaceSize();
73 bool Find(GDSBB BB);
74 void Check();
75 void Clear();
76 void ClearPolys();
77 };
78
79 class Net {
80 private:
81 bool _hasBBox;
82 GDS3DBB BBox;
83 PolygonSort polys;
84 public:
85 Net();
86 ~Net();
87 GDS3DBB GetBB();
88 void AddPoly(GDSPolygon * poly);
89 vector<GDSPolygon*> GetPolys();
90 vector<GDSPolygon*> GetPolysNear(GDSBB BB);
91 };
92 class Nets {
93 protected:
94 set<char*> NetList;
95 map<char*, Net*> PolyByNet;
96 public:
97 ~Nets();
98 void CleanNetName();
99 void AddPolyToNet(GDSPolygon * poly, char *NetName);
100 void SetNetName(GDSPolygon * poly);
101 vector<GDSPolygon*> GetPolyOnNet(char * NetName, Point2D P);
102 vector<GDSPolygon*> GetPolyOnNet(char * NetName, GDSBB BB);
103 vector<GDSPolygon*> GetPolyOnNet(char *NetName);
104 GDS3DBB GetNetBB(char *NetName);
105 vector<char*> GetNetsNames();
106 bool find(GDSPolygon * poly);
107 size_t size();
108 };
109
110 typedef struct GDSRef
111 {
112 GDSObject *object;
113 GDSMat mat;
114 }GDSRef;
115
116
117 class KeyInstance {
118 private:
119 GDSRef ref;
120 public:
121 GDSObject *object;
122 GDSMat Mat;
123
KeyInstance()124 KeyInstance() { object = NULL; }
125
126 KeyInstance(class GDSObject *object, GDSMat Mat);
127 KeyInstance(struct GDSRef ref);
128
129 bool operator<(const KeyInstance & A) const;
130 bool operator()(const KeyInstance & A) const;
131 };
132
133 class GDSObject
134 {
135 protected:
136 // Temporary data for parsing
137 vector<GDSPath*> PathItems;
138 vector<GDSText*> TextItems;
139 vector<SRefElement*> SRefItems;
140 vector<ARefElement*> ARefItems;
141
142 size_t PointCount;
143 size_t AccumPointCount;
144 bool noHierarchy;
145
146 bool hasBoundary;
147 GDSBB boundary;
148 bool has3DBoundary;
149 GDS3DBB _3Dboundary;
150
151 char *Name;
152 char *GDSName;
153 bool PCell; // After PCell detection
154 bool collapsed;
155 Nets Object_Nets;
156
157 // For Net checking
158 set<GDSPolygon*> checked_poly;
159 set<GDSPolygon*> unchecked_poly;
160 //vector<GDSPolygon*> pool_poly;
161 PolygonSort pool_poly;
162
163 public:
164 // Please move to private...
165 vector<GDSPolygon*> PolygonItems;
166 vector<GDSRef*> refs; // Use these references for rendering
167
168 GDSObject(char *Name, char *gdsName);
169 virtual ~GDSObject();
170
171 // Adding of new elements
172 void AddText(float newX, float newY, float newZ, bool newFlipped, float newMag, int newVJust, int newHJust, struct ProcessLayer *newlayer);
173 class GDSText *GetCurrentText();
174 void AddPolygon(double Height, double Thickness, size_t Points, struct ProcessLayer *layer);
175 class GDSPolygon *GetCurrentPolygon();
176 void AddSRef(char *Name, float X, float Y, int Flipped, float Mag);
177 void SetSRefRotation(float X, float Y, float Z);
178 void AddARef(char *Name, float X1, float Y1, float X2, float Y2, float X3, float Y3, int Columns, int Rows, int Flipped, float Mag);
179 void SetARefRotation(float X, float Y, float Z);
180 void AddPath(int PathType, float Height, float Thickness, int Points, float Width, float BgnExtn, float EndExtn, struct ProcessLayer *layer);
181 class GDSPath *GetCurrentPath();
182
183 void ConnectReferences(class GDSObjectList *Objects);
184 void TransformAddObject(GDSObject *obj, GDSMat mat);
185
186 // Get stuff
187 char *GetName();
188 char * GetGDSName();
189 bool referencesToObject(char *name);
190 bool referencesToObject(GDSObject * object);
191 char *GetProcessName();
192 bool Has3DBBox();
193 void ResetBBox();
194 GDS3DBB GetTotal3DBoundary();
195 GDSBB GetTotalBoundary();
196 bool isPCell();
197 size_t GetNumSRefs();
198 SRefElement* GetSRef(unsigned int index);
199 size_t GetNumARefs();
200 ARefElement* GetARef(unsigned int index);
201
202 // Flatten lower part of hierarchy
203 void printHierarchy(int);
204 size_t countTotalPoints();
205 void collapseHierachy();
206
207 // Netlist
208 void SetNetName(GDSPolygon * poly);
209 size_t GetNetsSize();
210 vector<char*> GetNetsNames();
211 vector<GDSPolygon*> GetPolyOnNet(char * NetName);
212 void FindAllConnectPoly(GDSPolygon * poly);
213 void SetPool_Poly();
214 vector<GDSPolygon*> GetPolyNear(Point2D P);
215 vector<GDSPolygon*> GetPolyNear(GDSBB BB);
216 void intersectPoly(GDSPolygon * poly);
217 Nets GetNetlist();
218
219 void CleanNetList();
220
221 };
222
223
224 inline bool KeyInstance::operator<(const KeyInstance& A) const
225 {
226 if (this->Mat < A.Mat)
227 return true;
228 else if (A.Mat < this->Mat)
229 return false;
230 else if (this->object->countTotalPoints() < A.object->countTotalPoints())
231 return true;
232 else if (this->object->countTotalPoints() > A.object->countTotalPoints())
233 return false;
234 //We should never reach this point, means matrices are equal and countTotalPoints are equal
235 return false;
236 }
operator()237 inline bool KeyInstance::operator()(const KeyInstance& A) const
238 {
239 if (this->Mat < A.Mat)
240 return true;
241 else if (A.Mat < this->Mat)
242 return false;
243 else if (this->object->countTotalPoints() < A.object->countTotalPoints())
244 return true;
245 else if (this->object->countTotalPoints() > A.object->countTotalPoints())
246 return false;
247 //We should never reach this point, means matrices are equal and countTotalPoints are equal
248 return false;
249 }
250
251 #endif // __GDSOBJECT_H__
252
253