1 /* Authors: Lutong Wang and Bangqi Xu */
2 /*
3  * Copyright (c) 2019, The Regents of the University of California
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  *     * Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in the
12  *       documentation and/or other materials provided with the distribution.
13  *     * Neither the name of the University nor the
14  *       names of its contributors may be used to endorse or promote products
15  *       derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _GR_SHAPE_H_
30 #define _GR_SHAPE_H_
31 
32 #include "db/grObj/grFig.h"
33 #include "db/infra/frSegStyle.h"
34 
35 namespace fr {
36 class frNet;
37 class grPin;
38 class frPathSeg;
39 class grShape : public grPinFig
40 {
41  public:
42   // constructors
grShape()43   grShape() : grPinFig() {}
44   // setters
45   virtual void setLayerNum(frLayerNum tmpLayerNum) = 0;
46   // getters
47   virtual frLayerNum getLayerNum() const = 0;
48   // others
49 
50   /* from grPinFig
51    * hasPin
52    * getPin
53    * addToPin
54    * removeFromPin
55    */
56 
57   /* from grConnFig
58    * hasNet
59    * getNet
60    * getChild
61    * getParent
62    * getGrChild
63    * getGrParent
64    * addToNet
65    * removeFromNet
66    * setChild
67    * setParent
68    * setChild
69    * setParent
70    */
71 
72   /* from grFig
73    * getBBox
74    * move
75    * overlaps
76    */
77 
78   virtual void setIter(frListIter<std::unique_ptr<grShape>>& in) = 0;
79   virtual frListIter<std::unique_ptr<grShape>> getIter() const = 0;
80 
81  protected:
82 };
83 
84 class grPathSeg : public grShape
85 {
86  public:
87   // constructors
grPathSeg()88   grPathSeg()
89       : grShape(),
90         begin(),
91         end(),
92         layer(0),
93         child(nullptr),
94         parent(nullptr),
95         owner(nullptr)
96   {
97   }
grPathSeg(const grPathSeg & in)98   grPathSeg(const grPathSeg& in)
99       : begin(in.begin),
100         end(in.end),
101         layer(in.layer),
102         child(in.child),
103         parent(in.parent),
104         owner(in.owner)
105   {
106   }
107   grPathSeg(const frPathSeg& in);
108   // getters
getPoints(frPoint & beginIn,frPoint & endIn)109   void getPoints(frPoint& beginIn, frPoint& endIn) const
110   {
111     beginIn.set(begin);
112     endIn.set(end);
113   }
114 
115   // setters
setPoints(const frPoint & beginIn,const frPoint & endIn)116   void setPoints(const frPoint& beginIn, const frPoint& endIn)
117   {
118     begin.set(beginIn);
119     end.set(endIn);
120   }
121   // others
typeId()122   frBlockObjectEnum typeId() const override { return grcPathSeg; }
123 
124   /* from grShape
125    * setLayerNum
126    * getLayerNum
127    */
setLayerNum(frLayerNum numIn)128   void setLayerNum(frLayerNum numIn) override { layer = numIn; }
getLayerNum()129   frLayerNum getLayerNum() const override { return layer; }
130 
131   /* from grPinFig
132    * hasPin
133    * getPin
134    * addToPin
135    * removeFromPin
136    */
hasPin()137   bool hasPin() const override
138   {
139     return (owner) && (owner->typeId() == grcPin);
140   }
141 
getPin()142   grPin* getPin() const override { return reinterpret_cast<grPin*>(owner); }
143 
addToPin(grPin * in)144   void addToPin(grPin* in) override
145   {
146     owner = reinterpret_cast<frBlockObject*>(in);
147   }
148 
removeFromPin()149   void removeFromPin() override { owner = nullptr; }
150 
151   /* from grConnFig
152    * hasNet
153    * getNet
154    * hasGrNet
155    * getGrNet
156    * getChild
157    * getParent
158    * getGrChild
159    * getGrParent
160    * addToNet
161    * removeFromNet
162    * setChild
163    * setParent
164    */
hasNet()165   bool hasNet() const override
166   {
167     return (owner) && (owner->typeId() == frcNet);
168   }
hasGrNet()169   bool hasGrNet() const override
170   {
171     return (owner) && (owner->typeId() == grcNet);
172   }
getNet()173   frNet* getNet() const override { return reinterpret_cast<frNet*>(owner); }
getGrNet()174   grNet* getGrNet() const override { return reinterpret_cast<grNet*>(owner); }
getChild()175   frNode* getChild() const override { return reinterpret_cast<frNode*>(child); }
getParent()176   frNode* getParent() const override
177   {
178     return reinterpret_cast<frNode*>(parent);
179   }
getGrChild()180   grNode* getGrChild() const override
181   {
182     return reinterpret_cast<grNode*>(child);
183   }
getGrParent()184   grNode* getGrParent() const override
185   {
186     return reinterpret_cast<grNode*>(parent);
187   }
188 
addToNet(frBlockObject * in)189   void addToNet(frBlockObject* in) override { owner = in; }
190 
removeFromNet()191   void removeFromNet() override { owner = nullptr; }
192 
setChild(frBlockObject * in)193   void setChild(frBlockObject* in) override { child = in; }
194 
setParent(frBlockObject * in)195   void setParent(frBlockObject* in) override { parent = in; }
196 
197   /* from grFig
198    * getBBox
199    */
200   // needs to be updated
getBBox(frBox & boxIn)201   void getBBox(frBox& boxIn) const override
202   {
203     boxIn.set(begin.x(), begin.y(), end.x(), end.y());
204   }
205 
setIter(frListIter<std::unique_ptr<grShape>> & in)206   void setIter(frListIter<std::unique_ptr<grShape>>& in) override { iter = in; }
getIter()207   frListIter<std::unique_ptr<grShape>> getIter() const override { return iter; }
208 
209  protected:
210   frPoint begin;
211   frPoint end;
212   frLayerNum layer;
213   frBlockObject* child;
214   frBlockObject* parent;
215   frBlockObject* owner;
216   frListIter<std::unique_ptr<grShape>> iter;
217 };
218 }  // namespace fr
219 
220 #endif
221