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 _DR_SHAPE_H_ 30 #define _DR_SHAPE_H_ 31 32 #include "db/drObj/drFig.h" 33 #include "db/infra/frSegStyle.h" 34 #include "dr/FlexMazeTypes.h" 35 36 namespace fr { 37 class drNet; 38 class drPin; 39 class frPathSeg; 40 class frPatchWire; 41 class drShape : public drPinFig 42 { 43 public: 44 // setters 45 virtual void setLayerNum(frLayerNum tmpLayerNum) = 0; 46 // getters 47 virtual frLayerNum getLayerNum() const = 0; 48 // others 49 50 /* drom drPinFig 51 * hasPin 52 * getPin 53 * addToPin 54 * removedromPin 55 */ 56 57 /* drom drConnFig 58 * hasNet 59 * getNet 60 * addToNet 61 * removedromNet 62 */ 63 64 /* drom drFig 65 * getBBox 66 * move 67 * overlaps 68 */ 69 protected: 70 // constructors drShape()71 drShape() : drPinFig() {} drShape(const drShape & in)72 drShape(const drShape& in) : drPinFig(in) {} 73 }; 74 75 class drPathSeg : public drShape 76 { 77 public: 78 // constructors drPathSeg()79 drPathSeg() 80 : drShape(), 81 begin_(), 82 end_(), 83 layer_(0), 84 style_(), 85 owner_(nullptr), 86 beginMazeIdx_(), 87 endMazeIdx_(), 88 patchSeg_(false), 89 isTapered_(false) 90 { 91 } drPathSeg(const drPathSeg & in)92 drPathSeg(const drPathSeg& in) 93 : drShape(in), 94 begin_(in.begin_), 95 end_(in.end_), 96 layer_(in.layer_), 97 style_(in.style_), 98 owner_(in.owner_), 99 beginMazeIdx_(in.beginMazeIdx_), 100 endMazeIdx_(in.endMazeIdx_), 101 patchSeg_(in.patchSeg_), 102 isTapered_(in.isTapered_) 103 { 104 } 105 drPathSeg(const frPathSeg& in); 106 // getters getPoints(frPoint & beginIn,frPoint & endIn)107 void getPoints(frPoint& beginIn, frPoint& endIn) const 108 { 109 beginIn.set(begin_); 110 endIn.set(end_); 111 } 112 getBeginPoint()113 const frPoint& getBeginPoint() const { return begin_; } 114 getEndPoint()115 const frPoint& getEndPoint() const { return end_; } 116 getStyle(frSegStyle & styleIn)117 void getStyle(frSegStyle& styleIn) const 118 { 119 styleIn.setBeginStyle(style_.getBeginStyle(), style_.getBeginExt()); 120 styleIn.setEndStyle(style_.getEndStyle(), style_.getEndExt()); 121 styleIn.setWidth(style_.getWidth()); 122 } 123 // setters setPoints(const frPoint & beginIn,const frPoint & endIn)124 void setPoints(const frPoint& beginIn, const frPoint& endIn) 125 { 126 begin_.set(beginIn); 127 end_.set(endIn); 128 } setStyle(const frSegStyle & styleIn)129 void setStyle(const frSegStyle& styleIn) 130 { 131 style_.setBeginStyle(styleIn.getBeginStyle(), styleIn.getBeginExt()); 132 style_.setEndStyle(styleIn.getEndStyle(), styleIn.getEndExt()); 133 style_.setWidth(styleIn.getWidth()); 134 } 135 void setBeginStyle(frEndStyle bs, frUInt4 ext = 0) 136 { 137 style_.setBeginStyle(bs, ext); 138 } 139 void setEndStyle(frEndStyle es, frUInt4 ext = 0) 140 { 141 style_.setEndStyle(es, ext); 142 } getBeginX()143 frCoord getBeginX() const { return begin_.x(); } getBeginY()144 frCoord getBeginY() const { return begin_.y(); } getEndX()145 frCoord getEndX() const { return end_.x(); } getEndY()146 frCoord getEndY() const { return end_.y(); } 147 // others typeId()148 frBlockObjectEnum typeId() const override { return drcPathSeg; } 149 150 /* from drShape 151 * setLayerNum 152 * getLayerNum 153 */ setLayerNum(frLayerNum numIn)154 void setLayerNum(frLayerNum numIn) override { layer_ = numIn; } getLayerNum()155 frLayerNum getLayerNum() const override { return layer_; } 156 157 /* from drPinFig 158 * hasPin 159 * getPin 160 * addToPin 161 * removedromPin 162 */ hasPin()163 bool hasPin() const override 164 { 165 return (owner_) && (owner_->typeId() == drcPin); 166 } 167 getPin()168 drPin* getPin() const override { return reinterpret_cast<drPin*>(owner_); } 169 addToPin(drPin * in)170 void addToPin(drPin* in) override 171 { 172 owner_ = reinterpret_cast<drBlockObject*>(in); 173 } 174 removeFromPin()175 void removeFromPin() override { owner_ = nullptr; } 176 177 /* from drConnFig 178 * hasNet 179 * getNet 180 * addToNet 181 * removedromNet 182 */ hasNet()183 bool hasNet() const override 184 { 185 return (owner_) && (owner_->typeId() == drcNet); 186 } 187 getNet()188 drNet* getNet() const override { return reinterpret_cast<drNet*>(owner_); } 189 addToNet(drNet * in)190 void addToNet(drNet* in) override 191 { 192 owner_ = reinterpret_cast<drBlockObject*>(in); 193 } 194 removeFromNet()195 void removeFromNet() override { owner_ = nullptr; } 196 197 /* from drFig 198 * getBBox 199 * move, in .cpp 200 * overlaps, in .cpp 201 */ 202 // needs to be updated getBBox(frBox & boxIn)203 void getBBox(frBox& boxIn) const override 204 { 205 bool isHorizontal = true; 206 if (begin_.x() == end_.x()) { 207 isHorizontal = false; 208 } 209 auto width = style_.getWidth(); 210 auto beginExt = style_.getBeginExt(); 211 auto endExt = style_.getEndExt(); 212 if (isHorizontal) { 213 boxIn.set(begin_.x() - beginExt, 214 begin_.y() - width / 2, 215 end_.x() + endExt, 216 end_.y() + width / 2); 217 } else { 218 boxIn.set(begin_.x() - width / 2, 219 begin_.y() - beginExt, 220 end_.x() + width / 2, 221 end_.y() + endExt); 222 } 223 } 224 hasMazeIdx()225 bool hasMazeIdx() const { return (!beginMazeIdx_.empty()); } getMazeIdx(FlexMazeIdx & bi,FlexMazeIdx & ei)226 void getMazeIdx(FlexMazeIdx& bi, FlexMazeIdx& ei) const 227 { 228 bi.set(beginMazeIdx_); 229 ei.set(endMazeIdx_); 230 } setMazeIdx(FlexMazeIdx & bi,FlexMazeIdx & ei)231 void setMazeIdx(FlexMazeIdx& bi, FlexMazeIdx& ei) 232 { 233 beginMazeIdx_.set(bi); 234 endMazeIdx_.set(ei); 235 } setPatchSeg(bool in)236 void setPatchSeg(bool in) { patchSeg_ = in; } isPatchSeg()237 bool isPatchSeg() const { return patchSeg_; } isTapered()238 bool isTapered() const { return isTapered_; } setTapered(bool t)239 void setTapered(bool t) { isTapered_ = t; } 240 241 protected: 242 frPoint begin_; // begin always smaller than end, assumed 243 frPoint end_; 244 frLayerNum layer_; 245 frSegStyle style_; 246 drBlockObject* owner_; 247 FlexMazeIdx beginMazeIdx_; 248 FlexMazeIdx endMazeIdx_; 249 bool patchSeg_; 250 bool isTapered_; 251 }; 252 253 class drPatchWire : public drShape 254 { 255 public: 256 // constructors drPatchWire()257 drPatchWire() 258 : drShape(), offsetBox_(), origin_(), layer_(0), owner_(nullptr){}; drPatchWire(const drPatchWire & in)259 drPatchWire(const drPatchWire& in) 260 : drShape(in), 261 offsetBox_(in.offsetBox_), 262 origin_(in.origin_), 263 layer_(in.layer_), 264 owner_(in.owner_){}; 265 drPatchWire(const frPatchWire& in); 266 // others typeId()267 frBlockObjectEnum typeId() const override { return drcPatchWire; } 268 269 /* from drShape 270 * setLayerNum 271 * getLayerNum 272 */ setLayerNum(frLayerNum numIn)273 void setLayerNum(frLayerNum numIn) override { layer_ = numIn; } getLayerNum()274 frLayerNum getLayerNum() const override { return layer_; } 275 276 /* from drPinFig 277 * hasPin 278 * getPin 279 * addToPin 280 * removeFromPin 281 */ hasPin()282 bool hasPin() const override 283 { 284 return (owner_) && (owner_->typeId() == drcPin); 285 } 286 getPin()287 drPin* getPin() const override { return reinterpret_cast<drPin*>(owner_); } 288 addToPin(drPin * in)289 void addToPin(drPin* in) override 290 { 291 owner_ = reinterpret_cast<drBlockObject*>(in); 292 } 293 removeFromPin()294 void removeFromPin() override { owner_ = nullptr; } 295 296 /* from drConnfig 297 * hasNet 298 * getNet 299 * addToNet 300 * removedFromNet 301 */ hasNet()302 bool hasNet() const override 303 { 304 return (owner_) && (owner_->typeId() == drcNet); 305 } 306 getNet()307 drNet* getNet() const override { return reinterpret_cast<drNet*>(owner_); } 308 addToNet(drNet * in)309 void addToNet(drNet* in) override 310 { 311 owner_ = reinterpret_cast<drBlockObject*>(in); 312 } 313 removeFromNet()314 void removeFromNet() override { owner_ = nullptr; } 315 316 /* from drFig 317 * getBBox 318 * setBBox 319 */ getBBox(frBox & boxIn)320 void getBBox(frBox& boxIn) const override 321 { 322 frTransform xform(origin_); 323 boxIn.set(offsetBox_); 324 boxIn.transform(xform); 325 } 326 getOffsetBox(frBox & boxIn)327 void getOffsetBox(frBox& boxIn) const { boxIn = offsetBox_; } setOffsetBox(const frBox & boxIn)328 void setOffsetBox(const frBox& boxIn) { offsetBox_.set(boxIn); } 329 getOrigin(frPoint & in)330 void getOrigin(frPoint& in) const { in.set(origin_); } setOrigin(const frPoint & in)331 void setOrigin(const frPoint& in) { origin_.set(in); } 332 333 protected: 334 frBox offsetBox_; 335 frPoint origin_; 336 frLayerNum layer_; 337 drBlockObject* owner_; 338 }; 339 } // namespace fr 340 341 #endif 342