1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2019, Nefelus Inc
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 //   list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 //   this list of conditions and the following disclaimer in the documentation
15 //   and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 //   contributors may be used to endorse or promote products derived from
19 //   this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 
33 #pragma once
34 
35 #include <stdio.h>
36 #include <wire.h>
37 
38 #include "ISdb.h"
39 #include "IZdcr.h"
40 #include "atypes.h"
41 #include "dbId.h"
42 #include "dbObject.h"
43 #include "dbTypes.h"
44 #include "odb.h"
45 
46 namespace odb {
47 
48 // class Ath__searchBox;
49 
50 class dbBlockSearch
51 {
52  private:
53   dbBlock* _block;
54   dbTech* _tech;
55   uint _blockId;
56 
57   ZPtr<ISdb> _signalNetSdb;
58   ZPtr<ISdb> _netSdb;
59   ZPtr<ISdb> _netViaSdb;
60   ZPtr<ISdb> _instSdb;
61   ZPtr<ISdb> _trackSdb;
62 
63   ZPtr<IZdcr> _dcr;
64 
65   uint _blockMenuId;
66 
67   uint _block_bb_id;
68   uint _block_pin_id;
69   uint _block_obs_id;
70   uint _block_track_id;
71 
72   uint _instMenuId;
73 
74   uint _inst_bb_id;
75   uint _inst_pin_id;
76   uint _inst_obs_id;
77 
78   uint _signalMenuId;
79 
80   uint _signal_wire_id;
81   uint _signal_via_id;
82   uint _powerMenuId;
83 
84   uint _power_wire_id;
85   uint _power_via_id;
86 
87   bool _skipCutBoxes;
88 
89  public:
90   dbBlockSearch(dbBlock* blk, dbTech* tech);
91   ~dbBlockSearch();
92 
93   ZPtr<ISdb> getSignalNetSdb(ZContext& context);
94   ZPtr<ISdb> getSignalNetSdb();
95   void makeSignalNetSdb(ZContext& context);
96   void resetSignalNetSdb();
97 
98   void resetNetSdb();
99   ZPtr<ISdb> getNetSdb(ZContext& context);
100   ZPtr<ISdb> getNetSdb();
101 
102   void initSubMenus();
103   void initMenuIds();
104   uint getBbox(int* x1, int* y1, int* x2, int* y2);
105   void setViaCutsFlag(bool skipViaCuts);
106   void makeSearchDB(bool nets, bool insts, ZContext& context);
107   void makeTrackSdb(ZContext& context);
108   void makeNetSdb(ZContext& context);
109   void makeNetViaSdb(ZContext& context);
110   uint makeInstSearchDb();
111   void makeNetWireSearchDb();
112 
113   uint addViaCoordsFromWire(uint menuId,
114                             uint subMenuId,
115                             uint netId,
116                             uint shapeId);
117   uint getViasFromWires(ZPtr<ISdb> sdb,
118                         uint menuId,
119                         uint subMenuId,
120                         uint wireMenuId,
121                         dbNet* targetNet,
122                         bool excludeFlag);
123 
124   uint addViaBoxes(dbShape& s,
125                    uint menuId,
126                    uint subMenuId,
127                    uint id,
128                    uint shapeId);
129   uint addViaBoxes(dbBox* s,
130                    uint menuId,
131                    uint subMenuId,
132                    uint netId,
133                    uint shapeId);
134 
135   uint getViaLevels(dbShape& s, uint& top);
136   uint getViaLevels(dbBox* s, uint& top);
137 
138   uint addBtermBoxes(dbSet<dbBTerm>& bterms, bool ignoreFlag);
139   uint getBtermBoxes(bool ignoreFlag);
140   uint addBoxes(dbBTerm* bterm);
141 
142   void getInstBoxes(bool ignoreFlag);
143   void getInstShapes(bool vias, bool pins, bool obs);
144   uint getItermShapes(dbInst* inst, bool viaFlag);
145   uint getItermShapes(dbITerm* term, bool viaFlag);
146   uint getInstObs(dbInst* inst, bool viaFlag);
147   uint addInstShapes(dbInst* inst, bool vias, bool pinFlag, bool obsFlag);
148   uint getWiresAndVias_all(dbNet* targetNet, bool ignoreFlag);
149   uint addWireViaCoords(uint menuId,
150                         uint subMenuId,
151                         bool wireVia,
152                         uint wireId,
153                         uint shapeId);
154   uint getWireVias(uint menuId,
155                    uint subMenuId,
156                    bool wireVia,
157                    dbNet* targetNet,
158                    bool excludeFlag);
159   int getShapeLevel(dbShape* s, bool wireVia);
160   int getShapeLevel(dbSBox* s, bool wireVia);
161 
162   uint getItermShapesWithViaShapes(dbITerm* iterm);
163   uint getItermShapesNoVias(dbITerm* iterm);
164 
165   dbNet* getNet(uint wireId, uint shapeId);
166   uint selectNet();
167   bool isSignalNet(dbNet* net);
168 
169   bool getWildCardName(const char* name, char* outName);
170 
171   void getNetBbox(dbNet* net, Rect& maxRect);
172   uint getNetConnectivity(dbNet* net,
173                           bool contextFlag,
174                           uint clipMargin,
175                           bool ignoreLayerFlags,
176                           bool ignoreTypeFlags,
177                           bool ignoreBB);
178   uint getNetWires(dbNet* net,
179                    bool contextFlag,
180                    uint clipMargin,
181                    bool ignoreZuiFlags,
182                    bool ignoreBB);
183 
184   uint getNetFromDb(dbNet* net, bool ignoreZuiFlags, bool ignoreBB);
185   uint addNetShapes(dbNet* net, bool wireVia, uint menuId, uint subMenuId);
186 
187   uint addWireCoords(dbShape& s,
188                      uint menuId,
189                      uint subMenuId,
190                      uint netId,
191                      uint shapeId);
192   uint addViaCoords(dbShape& viaShape,
193                     uint menuId,
194                     uint subMenuId,
195                     uint netId,
196                     uint shapeId);
197 
198   uint addInstBoxes(dbNet* net, bool ignoreFlags);
199   uint addInstBox(dbInst* inst);
200   dbNet* getNetAndShape(dbShape& s, uint* shapeId, uint* level);
201   void selectInst();
202   void selectIterm2Net(uint itermId);
203   uint selectIterm();
204 
205   uint addInstBoxes(dbInst* inst,
206                     bool instBoxes,
207                     bool termShapes,
208                     bool instObs,
209                     bool vias);
210   void addInstConnList(dbInst* inst, bool ignoreFlags);
211   uint getConnectivityWires(dbInst* inst, bool ignoreZuiFlags);
212   void selectBterm2Net(uint btermId);
213   uint selectBterm();
214 
215   uint addSBox(uint menuId, uint subMenuId, bool wireVia, uint wireId);
216   void addNetSBoxes(dbNet* net, uint wtype, bool skipVias);
217 
218   uint getFirstShape(dbITerm* iterm,
219                      bool viaFlag,
220                      int& x1,
221                      int& y1,
222                      int& x2,
223                      int& y2);
224   uint getFirstInstObsShape(dbInst* inst,
225                             bool viaFlag,
226                             int& x1,
227                             int& y1,
228                             int& x2,
229                             int& y2);
230   uint getInstBoxes(int x1,
231                     int y1,
232                     int x2,
233                     int y2,
234                     std::vector<dbInst*>& result);  // 8/25/05
235 
236   dbRSeg* getRSeg(dbNet* net, uint shapeId);
237 
238   uint getWiresClipped(dbNet* targetNet, uint halo, bool ignoreFlag);
239 
240   uint getPowerWires(int x1,
241                      int y1,
242                      int x2,
243                      int y2,
244                      int layer,
245                      dbNet* targetNet,
246                      std::vector<dbBox*>& viaTable);
247 
248   uint getQuadCnt(int modSize, int xy1, int xy2);
249   uint makeQuadTable(uint rowCnt, uint colCnt, uint metH, uint metV);
250   uint assignTracks(uint metH, uint metV);
251 
252   //	uint getShapeCoords(dbShape *s, Ath__searchBox *bb, uint id1, uint id2,
253   // uint level); 	dbNet* getShapeCoords(bool wireVia, Ath__searchBox *bb,
254   // uint wireId, uint shapeId);
255 
256   uint createTblocks();
257   //	dbNet* getNetAndCoords(Ath__searchBox *bb, bool skipVia, bool signal,
258   // uint wid);
259   uint getNetMaxBox(dbNet* net, Ath__searchBox* maxBB);
260   void getWires(int x1, int y1, int x2, int y2);
261 
262   void addNetSBoxesOnSearch(dbNet* net, bool skipVias);
263   void addNetShapesOnSearch(dbNet* net, bool skipVias);
264   void makeGrouteSearchDb();
265 
266 
267   uint getViaLevel(dbShape* s);
268   uint getViaLevel(dbSBox* s);
269 
270   uint getNetSBoxes(dbNet* net, bool skipVias);
271 
272   void getNetSBoxesFromSearch(dbNet* net,
273                               Ath__array1D<uint>* idTable,
274                               Ath__searchBox* maxBox);
275   void getNetShapesFromSearch(dbNet* net,
276                               Ath__array1D<uint>* idTable,
277                               Ath__searchBox* maxBox);
278   void getWireIds(Ath__array1D<uint>* wireIdTable, Ath__array1D<uint>* idtable);
279 
280   uint addBlockagesOnSearch(dbBlock* block);
281   uint getBlockObs(bool ignoreFlag);
282   uint getDbBoxId(uint wid, uint wireType);
283 
284   bool setInterface2SdbAtDB();  // ISDB
285   bool connect2BlockSdb();      // ISDB
286 
287   uint makeTrackSearchDb();
288   uint getTracks(bool ignoreLayers);
289   uint addTracks(dbTrackGrid* g, uint dir, uint level, int lo[2], int hi[2]);
290 
291   int getTrackXY(int boxXY, int org, int count, int step);
292   uint getTracks(dbTrackGrid* grid,
293                  int* bb_ll,
294                  int* bb_ur,
295                  uint level,
296                  uint dir);
297   uint getTracks(dbTrackGrid* g,
298                  int org,
299                  int count,
300                  int step,
301                  int* bb_ll,
302                  int* bb_ur,
303                  uint level,
304                  uint dir);
305 
306   uint addArrow(dbInst* inst1,
307                 dbInst* inst2,
308                 int labelCnt,
309                 char** label,
310                 double* val);
311   uint addArrow(int x1,
312                 int y1,
313                 int x2,
314                 int y2,
315                 int labelCnt,
316                 char** label,
317                 double* val);
318   uint addFlightLines(dbInst* inst);
319 
320   // 2/10/2011
321   uint getPowerWiresAndVias(int x1,
322                             int y1,
323                             int x2,
324                             int y2,
325                             int layer,
326                             dbNet* targetNet,
327                             bool power_wires,
328                             std::vector<dbBox*>& viaTable);
329   uint getPowerWireVias(ZPtr<ISdb> sdb,
330                         dbNet* targetNet,
331                         bool vias,
332                         std::vector<dbBox*>& viaTable);
333 };
334 
335 }  // namespace odb
336