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 _TA_SHAPE_H_ 30 #define _TA_SHAPE_H_ 31 32 #include "db/infra/frSegStyle.h" 33 #include "db/taObj/taFig.h" 34 35 namespace fr { 36 class frNet; 37 class taPin; 38 class frPathSeg; 39 class taShape : public taPinFig 40 { 41 public: 42 // setters 43 virtual void setLayerNum(frLayerNum tmpLayerNum) = 0; 44 // getters 45 virtual frLayerNum getLayerNum() const = 0; 46 // others 47 48 /* from frPinFig 49 * hasPin 50 * getPin 51 * addToPin 52 * removeFromPin 53 */ 54 55 /* from frConnFig 56 * hasNet 57 * getNet 58 * addToNet 59 * removeFromNet 60 */ 61 62 /* from frFig 63 * getBBox 64 * move 65 * overlaps 66 */ 67 protected: 68 // constructors taShape()69 taShape() : taPinFig() {} 70 }; 71 72 class taPathSeg : public taShape 73 { 74 public: 75 // constructors taPathSeg()76 taPathSeg() 77 : taShape(), begin_(), end_(), layer_(0), style_(), owner_(nullptr) 78 { 79 } taPathSeg(const taPathSeg & in)80 taPathSeg(const taPathSeg& in) 81 : begin_(in.begin_), 82 end_(in.end_), 83 layer_(in.layer_), 84 style_(in.style_), 85 owner_(in.owner_) 86 { 87 } 88 taPathSeg(const frPathSeg& in); 89 // getters getPoints(frPoint & beginIn,frPoint & endIn)90 void getPoints(frPoint& beginIn, frPoint& endIn) const 91 { 92 beginIn.set(begin_); 93 endIn.set(end_); 94 } getStyle(frSegStyle & styleIn)95 void getStyle(frSegStyle& styleIn) const 96 { 97 styleIn.setBeginStyle(style_.getBeginStyle(), style_.getBeginExt()); 98 styleIn.setEndStyle(style_.getEndStyle(), style_.getEndExt()); 99 styleIn.setWidth(style_.getWidth()); 100 } 101 // setters setPoints(const frPoint & beginIn,const frPoint & endIn)102 void setPoints(const frPoint& beginIn, const frPoint& endIn) 103 { 104 begin_.set(beginIn); 105 end_.set(endIn); 106 } setStyle(const frSegStyle & styleIn)107 void setStyle(const frSegStyle& styleIn) 108 { 109 style_.setBeginStyle(styleIn.getBeginStyle(), styleIn.getBeginExt()); 110 style_.setEndStyle(styleIn.getEndStyle(), styleIn.getEndExt()); 111 style_.setWidth(styleIn.getWidth()); 112 } 113 // others typeId()114 frBlockObjectEnum typeId() const override { return tacPathSeg; } 115 116 /* from frShape 117 * setLayerNum 118 * getLayerNum 119 */ setLayerNum(frLayerNum numIn)120 void setLayerNum(frLayerNum numIn) override { layer_ = numIn; } getLayerNum()121 frLayerNum getLayerNum() const override { return layer_; } 122 123 /* from frPinFig 124 * hasPin 125 * getPin 126 * addToPin 127 * removeFromPin 128 */ hasPin()129 bool hasPin() const override 130 { 131 return (owner_) && (owner_->typeId() == tacPin); 132 } 133 getPin()134 taPin* getPin() const override { return reinterpret_cast<taPin*>(owner_); } 135 addToPin(taPin * in)136 void addToPin(taPin* in) override 137 { 138 owner_ = reinterpret_cast<frBlockObject*>(in); 139 } 140 removeFromPin()141 void removeFromPin() override { owner_ = nullptr; } 142 143 /* from frConnFig 144 * hasNet 145 * getNet 146 * addToNet 147 * removeFromNet 148 */ hasNet()149 bool hasNet() const override 150 { 151 return (owner_) && (owner_->typeId() == frcNet); 152 } 153 addToNet(frNet * in)154 void addToNet(frNet* in) override 155 { 156 owner_ = reinterpret_cast<frBlockObject*>(in); 157 } 158 removeFromNet()159 void removeFromNet() override { owner_ = nullptr; } 160 161 /* from frFig 162 * getBBox 163 * move, in .cpp 164 * overlaps, in .cpp 165 */ 166 // needs to be updated getBBox(frBox & boxIn)167 void getBBox(frBox& boxIn) const override 168 { 169 bool isHorizontal = true; 170 if (begin_.x() == end_.x()) { 171 isHorizontal = false; 172 } 173 auto width = style_.getWidth(); 174 auto beginExt = style_.getBeginExt(); 175 auto endExt = style_.getEndExt(); 176 if (isHorizontal) { 177 boxIn.set(begin_.x() - beginExt, 178 begin_.y() - width / 2, 179 end_.x() + endExt, 180 end_.y() + width / 2); 181 } else { 182 boxIn.set(begin_.x() - width / 2, 183 begin_.y() - beginExt, 184 end_.x() + width / 2, 185 end_.y() + endExt); 186 } 187 } move(const frTransform & xform)188 void move(const frTransform& xform) override 189 { 190 begin_.transform(xform); 191 end_.transform(xform); 192 } overlaps(const frBox & box)193 bool overlaps(const frBox& box) const override { return false; } 194 195 protected: 196 frPoint begin_; // begin always smaller than end, assumed 197 frPoint end_; 198 frLayerNum layer_; 199 frSegStyle style_; 200 frBlockObject* owner_; 201 }; 202 } // namespace fr 203 204 #endif 205