Katabatic - Routing Toolbox


AutoContact.h
1 // -*- C++ -*-
2 //
3 // This file is part of the Coriolis Software.
4 // Copyright (c) UPMC 2008-2018, All Rights Reserved
5 //
6 // +-----------------------------------------------------------------+
7 // | C O R I O L I S |
8 // | K a t a b a t i c - Routing Toolbox |
9 // | |
10 // | Author : Jean-Paul CHAPUT |
11 // | E-mail : Jean-Paul.Chaput@lip6.fr |
12 // | =============================================================== |
13 // | C++ Header : "./katabatic/AutoContact.h" |
14 // +-----------------------------------------------------------------+
15 
16 
17 #ifndef KATABATIC_AUTOCONTACT_H
18 #define KATABATIC_AUTOCONTACT_H
19 
20 #include <vector>
21 #include <map>
22 #include "hurricane/Contact.h"
23 #include "hurricane/ExtensionGo.h"
24 #include "katabatic/Constants.h"
25 #include "katabatic/AutoSegment.h"
26 #include "katabatic/GCell.h"
27 
28 
29 namespace Katabatic {
30 
31 
32  using std::cerr;
33  using std::endl;
34  using Hurricane::tab;
35  using Hurricane::Name;
36  using Hurricane::Net;
39  using Hurricane::Layer;
40  using Hurricane::Contact;
41  using Hurricane::ExtensionGo;
42 
43  class GCell;
44  class KatabaticEngine;
45  class AutoHorizontal;
46  class AutoVertical;
47  class AutoContact;
48 
49 
50  typedef std::map<Contact*,AutoContact*> AutoContactLut;
51 
52 
53 // -------------------------------------------------------------------
54 // Class : "Katabatic::AutoContact".
55 
56  enum AutoContactFlag { CntFixed = 0x00000001
57  , CntTerminal = 0x00000002
58  , CntTurn = 0x00000004
59  , CntHTee = 0x00000008
60  , CntVTee = 0x00000010
61  , CntInvalidated = 0x00000020
62  , CntInvalidatedCache = 0x00000040
63  , CntInCreationStage = 0x00000080
64  , CntBadTopology = 0x00000100
65  , CntIgnoreAnchor = 0x00000200
66  , CntWeakTerminal = 0x00000400
67  , CntUserNativeConstraints = 0x00000800
68  };
69 
70  class AutoContact {
71  public:
72  static AutoContact* createFrom ( Contact* );
73  public:
74  // Wrapped Contact Accessors.
75  inline Hook* getBodyHook ();
76  inline Hook* getAnchorHook ();
77  inline Component* getAnchor () const;
78  inline Net* getNet () const;
79  inline const Layer* getLayer () const;
80  inline DbU::Unit getX () const;
81  inline DbU::Unit getY () const;
82  inline DbU::Unit getDx () const;
83  inline DbU::Unit getDy () const;
84  inline Point getCenter () const;
85  inline Point getPosition () const;
86  inline DbU::Unit getWidth () const;
87  inline DbU::Unit getHalfWidth () const;
88  inline DbU::Unit getHeight () const;
89  inline DbU::Unit getHalfHeight () const;
90  inline Components getSlaveComponents () const;
91  // Wrapped Contact Modifiers.
92  inline void setLayer ( const Layer* );
93  inline void setWidth ( DbU::Unit );
94  inline void setHeight ( DbU::Unit );
95  inline void setSizes ( DbU::Unit width, DbU::Unit height );
96  inline void setX ( DbU::Unit );
97  inline void setY ( DbU::Unit );
98  inline void setPosition ( DbU::Unit width, DbU::Unit height );
99  inline void setPosition ( const Point& );
100  inline void setDx ( DbU::Unit );
101  inline void setDy ( DbU::Unit );
102  inline void setOffset ( DbU::Unit dx, DbU::Unit dy );
103  virtual void translate ( const DbU::Unit& tx, const DbU::Unit& ty );
104  // Predicates.
105  inline bool isInCreationStage () const;
106  inline bool isInvalidated () const;
107  inline bool isInvalidatedCache () const;
108  inline bool isTerminal () const;
109  inline bool isTurn () const;
110  bool isTee ( unsigned int direction ) const;
111  inline bool isHTee () const;
112  inline bool isVTee () const;
113  inline bool isFixed () const;
114  inline bool isUserNativeConstraints () const;
115  inline bool hasBadTopology () const;
116  bool canDestroy ( unsigned int flags=0 ) const;
117  bool canMoveUp ( const AutoSegment* moved ) const;
118  // Accessors.
119  inline Contact* base () const;
120  static size_t getAllocateds ();
121  static const Name& getStaticName ();
122  virtual const Name& getName () const;
123  inline size_t getId () const;
124  virtual Box getBoundingBox () const;
125  inline GCell* getGCell () const;
126  virtual AutoSegment* getOpposite ( const AutoSegment* ) const = 0;
127  virtual AutoSegment* getPerpandicular ( const AutoSegment* ) const = 0;
128  virtual AutoSegment* getSegment ( unsigned int ) const = 0;
129  unsigned int getMinDepth () const;
130  unsigned int getMaxDepth () const;
131  void getLengths ( DbU::Unit* lengths, AutoSegment::DepthLengthSet& );
132  virtual Box getNativeConstraintBox () const;
133  Interval getNativeUConstraints ( unsigned int direction ) const;
134  Interval getUConstraints ( unsigned int direction ) const;
135  inline DbU::Unit getCBXMin () const;
136  inline DbU::Unit getCBXMax () const;
137  inline DbU::Unit getCBYMin () const;
138  inline DbU::Unit getCBYMax () const;
139  inline Box getConstraintBox () const;
140  Box& intersectConstraintBox ( Box& box ) const;
141  // Collections.
142  AutoSegments getAutoSegments ();
143  // Modifiers.
144  void invalidate ( unsigned int flags=0 );
145  virtual void cacheDetach ( AutoSegment* ) = 0;
146  virtual void cacheAttach ( AutoSegment* ) = 0;
147  virtual void updateCache () = 0;
148  virtual void updateGeometry () = 0;
149  virtual void updateTopology () = 0;
150  void showTopologyError ( const std::string&, unsigned int flags=0 );
151  virtual void checkTopology ();
152  inline void setFlags ( unsigned int );
153  inline void unsetFlags ( unsigned int );
154  void setGCell ( GCell* );
155  inline void setCBXMin ( DbU::Unit xMin );
156  inline void setCBXMax ( DbU::Unit xMax );
157  inline void setCBYMin ( DbU::Unit yMin );
158  inline void setCBYMax ( DbU::Unit yMax );
159  void setConstraintBox ( const Box& box );
160  bool restrictConstraintBox ( DbU::Unit constraintMin
161  , DbU::Unit constraintMax
162  , unsigned int flags=KbWarnOnError );
163  void restoreNativeConstraintBox ();
164  void migrateConstraintBox ( AutoContact* other );
165  void destroy ();
166  // Inspector Management.
167  Record* _getRecord () const;
168  virtual string _getString () const;
169  virtual string _getTypeName () const;
170 
171  private:
172  // Internal: Attributes.
173  static size_t _maxId;
174  static size_t _allocateds;
175  static const Name _goName;
176 
177  protected:
178  size_t _id;
179  Contact* _contact;
180  GCell* _gcell;
181  unsigned int _flags;
182  int _dxMin:8;
183  int _dxMax:8;
184  int _dyMin:8;
185  int _dyMax:8;
186 
187  protected:
188  // Constructors & Destructors.
189  AutoContact ( GCell*, Contact* );
190  virtual ~AutoContact ();
191  static void _preCreate ( GCell*, Net*, const Layer* );
192  virtual void _postCreate ();
193  virtual void _preDestroy ();
194  private:
195  AutoContact ( const AutoContact& );
196  AutoContact& operator= ( const AutoContact& );
197 
198  protected:
199  inline int _getDeltaMin ( DbU::Unit x, DbU::Unit xMin );
200  inline int _getDeltaMax ( DbU::Unit x, DbU::Unit xMin, DbU::Unit xMax );
201  static void _getTopology ( Contact*, Component*& anchor, Horizontal**&, Vertical**&, size_t );
202  virtual void _invalidate ( unsigned int flags ) = 0;
203  };
204 
205 
206 // Wrapped Contact Inline Functions.
207  inline Hook* AutoContact::getBodyHook () { return _contact->getBodyHook(); }
208  inline Hook* AutoContact::getAnchorHook () { return _contact->getAnchorHook(); }
209  inline Component* AutoContact::getAnchor () const { return _contact->getAnchor(); }
210  inline Net* AutoContact::getNet () const { return _contact->getNet(); }
211  inline const Layer* AutoContact::getLayer () const { return _contact->getLayer(); }
212  inline DbU::Unit AutoContact::getX () const { return _contact->getX(); }
213  inline DbU::Unit AutoContact::getY () const { return _contact->getY(); }
214  inline DbU::Unit AutoContact::getDx () const { return _contact->getDx(); }
215  inline DbU::Unit AutoContact::getDy () const { return _contact->getDy(); }
216  inline Point AutoContact::getCenter () const { return _contact->getCenter(); }
217  inline Point AutoContact::getPosition () const { return _contact->getPosition(); }
218  inline DbU::Unit AutoContact::getWidth () const { return _contact->getWidth(); }
219  inline DbU::Unit AutoContact::getHalfWidth () const { return _contact->getHalfWidth(); }
220  inline DbU::Unit AutoContact::getHeight () const { return _contact->getHeight(); }
221  inline DbU::Unit AutoContact::getHalfHeight () const { return _contact->getHalfHeight(); }
222  inline Components AutoContact::getSlaveComponents () const { return _contact->getSlaveComponents(); }
223  inline void AutoContact::setLayer ( const Layer* layer ) { _contact->setLayer(layer); }
224  inline void AutoContact::setWidth ( DbU::Unit w ) { _contact->setWidth(w); }
225  inline void AutoContact::setHeight ( DbU::Unit h ) { _contact->setHeight(h); }
226  inline void AutoContact::setSizes ( DbU::Unit w, DbU::Unit h ) { _contact->setSizes(w,h); }
227  inline void AutoContact::setX ( DbU::Unit x ) { _contact->setX(x); }
228  inline void AutoContact::setY ( DbU::Unit y ) { _contact->setY(y); }
229  inline void AutoContact::setPosition ( DbU::Unit x, DbU::Unit y ) { _contact->setPosition(x,y); }
230  inline void AutoContact::setPosition ( const Point& p ) { _contact->setPosition(p); }
231  inline void AutoContact::setDx ( DbU::Unit dx ) { _contact->setDx(dx); }
232  inline void AutoContact::setDy ( DbU::Unit dy ) { _contact->setDy(dy); }
233  inline void AutoContact::setOffset ( DbU::Unit dx, DbU::Unit dy ) { _contact->setOffset(dx,dy); }
234 // AutoContact Inline Functions.
235  inline bool AutoContact::isInCreationStage () const { return _flags&CntInCreationStage; }
236  inline bool AutoContact::isInvalidated () const { return _flags&CntInvalidated; }
237  inline bool AutoContact::isInvalidatedCache () const { return _flags&CntInvalidatedCache; }
238  inline bool AutoContact::isTurn () const { return _flags&CntTurn; }
239  inline bool AutoContact::isFixed () const { return _flags&CntFixed; }
240  inline bool AutoContact::isUserNativeConstraints () const { return _flags&CntUserNativeConstraints; }
241  inline bool AutoContact::isTerminal () const { return _flags&CntTerminal; }
242  inline bool AutoContact::isHTee () const { return _flags&CntHTee; }
243  inline bool AutoContact::isVTee () const { return _flags&CntVTee; }
244  inline bool AutoContact::hasBadTopology () const { return _flags&CntBadTopology; }
245  inline size_t AutoContact::getId () const { return _id; }
246  inline Contact* AutoContact::base () const { return _contact; }
247  inline GCell* AutoContact::getGCell () const { return _gcell; }
249  inline void AutoContact::setCBXMin ( DbU::Unit xMin ) { _dxMin = _getDeltaMin(xMin,_gcell->getX()); }
250  inline void AutoContact::setCBXMax ( DbU::Unit xMax ) { _dxMax = _getDeltaMax(xMax,_gcell->getX(),_gcell->getXMax()); }
251  inline void AutoContact::setCBYMin ( DbU::Unit yMin ) { _dyMin = _getDeltaMin(yMin,_gcell->getY()); }
252  inline void AutoContact::setCBYMax ( DbU::Unit yMax ) { _dyMax = _getDeltaMax(yMax,_gcell->getY(),_gcell->getYMax()); }
253  inline void AutoContact::setFlags ( unsigned int flags ) { _flags|= flags; }
254  inline void AutoContact::unsetFlags ( unsigned int flags ) { _flags&=~flags; }
255  inline int AutoContact::_getDeltaMin ( DbU::Unit x, DbU::Unit xMin ) { if (x<xMin) return 0; return (int)DbU::toLambda(x-xMin); }
256  inline int AutoContact::_getDeltaMax ( DbU::Unit x, DbU::Unit xMin, DbU::Unit xMax ) { if (x>xMax) x=xMax; return (int)DbU::toLambda(x-xMin); }
257 
259  { return isFixed() ? _contact->getX() : DbU::fromLambda(_dxMin) + _gcell->getX(); }
260 
262  { return isFixed() ? _contact->getX() : DbU::fromLambda(_dxMax) + _gcell->getX(); }
263 
265  { return isFixed() ? _contact->getY() : DbU::fromLambda(_dyMin) + _gcell->getY(); }
266 
268  { return isFixed() ? _contact->getY() : DbU::fromLambda(_dyMax) + _gcell->getY(); }
269 
270 // -------------------------------------------------------------------
271 // Class : "Katabatic::LocatorHelper".
272 
274  public:
275  inline LocatorHelper ( AutoContact*, unsigned int flags=0 );
276  inline bool isValid () const;
277  inline AutoSegment* getSegment () const;
278  inline void progress ();
279  private:
280  inline unsigned int _min () const;
281  inline unsigned int _max () const;
282  private:
283  unsigned int _flags;
284  unsigned int _index;
285  AutoContact* _contact;
286  };
287 
288 
289  inline LocatorHelper::LocatorHelper ( AutoContact* contact, unsigned int flags )
290  : _flags(flags), _index(_min()), _contact(contact)
291  {
292  cdebug_tabw(145,1);
293  cdebug_log(145,0) << "CTOR LocatorHelper " << contact->_getString() << endl;
294  cdebug_log(145,0) << "+ _min():" << _min() << endl;
295  cdebug_log(145,0) << "+ _max():" << _max() << endl;
296  cdebug_log(145,0) << "+ getSegment(_min()):" << _contact->getSegment(_min()) << endl;
297  if (not _contact->getSegment(_index)) progress();
298  cdebug_tabw(145,-1);
299  }
300 
301  inline bool LocatorHelper::isValid () const
302  { return _index < _max(); }
303 
304  inline unsigned int LocatorHelper::_min () const
305  { return (_flags & (KbHorizontal|KbWithPerpands)) ? 0 : 2; }
306 
307  inline unsigned int LocatorHelper::_max () const
308  { return ((_flags & KbHorizontal) and not (_flags & KbWithPerpands)) ? 2 : 4; }
309 
311  {
312  cdebug_log(145,0) << "LocatorHelper::getSegment(" << _index << ") - " << _contact->getSegment(_index) << endl;
313  return (_index < _max()) ? _contact->getSegment(_index) : NULL;
314  }
315 
316  inline void LocatorHelper::progress ()
317  {
318  cdebug_tabw(145,1);
319  ++_index;
320  cdebug_log(145,0) << "LocatorHelper::progress() [" << _index << "] " << _contact->getSegment(_index) << endl;
321  while ((_index < _max()) and (_contact->getSegment(_index) == NULL)) {
322  ++_index;
323  cdebug_log(145,0) << "LocatorHelper::progress() [" << _index << "] " << _contact->getSegment(_index) << endl;
324  }
325  cdebug_tabw(145,-1);
326  }
327 
328 
329 // -------------------------------------------------------------------
330 // Helper Functions.
331 
332 
333  template<typename Type>inline void order ( Type& a, Type& b ) { if (a>b) std::swap(a,b); }
334 
335  inline DbU::Unit setInBound ( DbU::Unit lower, DbU::Unit upper, DbU::Unit& value )
336  {
337  if ( lower > value ) value = lower;
338  if ( upper < value ) value = upper;
339 
340  return value;
341  }
342 
343  inline size_t abssub ( size_t a, size_t b ) { return (a>b) ? a-b : b-a; }
344 
345 
346 } // Katabatic namespace.
347 
348 
349 INSPECTOR_P_SUPPORT(Katabatic::AutoContact);
350 
351 
352 #endif // KATABATIC_AUTOCONTACT_H
Definition: AutoContact.h:63
Net * getNet() const
Definition: AutoContact.h:210
DbU::Unit getY() const
Definition: GCell.h:245
static size_t getAllocateds()
Definition: AutoContact.cpp:153
static void _getTopology(Contact *, Component *&anchor, Horizontal **&, Vertical **&, size_t)
Definition: AutoContact.cpp:339
Definition: Constants.h:29
bool isInvalidatedCache() const
Definition: AutoContact.h:237
void setDy(DbU::Unit)
Definition: AutoContact.h:232
virtual AutoSegment * getSegment(unsigned int) const =0
DbU::Unit getHalfWidth() const
static const Name & getStaticName()
Definition: AutoContact.cpp:157
virtual void checkTopology()
Definition: AutoContact.cpp:400
void setOffset(DbU::Unit dx, DbU::Unit dy)
Definition: AutoContact.h:233
void setX(const DbU::Unit &x)
Net * getNet() const
AutoContactFlag
Definition: AutoContact.h:56
Hook * getAnchorHook()
Definition: AutoContact.h:208
DbU::Unit getDx() const
Definition: AutoContact.h:214
DbU::Unit getCBXMin() const
Definition: AutoContact.h:258
Definition: AutoContact.h:56
DbU::Unit getWidth() const
Definition: AutoContact.h:218
bool isInCreationStage() const
Definition: AutoContact.h:235
Definition: AutoContact.h:58
DbU::Unit getCBYMax() const
Definition: AutoContact.h:267
void setCBXMax(DbU::Unit xMax)
Definition: AutoContact.h:250
virtual DbU::Unit getX() const=0
bool isFixed() const
Definition: AutoContact.h:239
void setDx(const DbU::Unit &dx)
virtual const Layer * getLayer() const=0
void setPosition(DbU::Unit width, DbU::Unit height)
Definition: AutoContact.h:229
void setConstraintBox(const Box &box)
Definition: AutoContact.cpp:442
static Unit fromLambda(double value)
std::int64_t Unit
Components getSlaveComponents() const
void invalidate(unsigned int flags=0)
Definition: AutoContact.cpp:296
LocatorHelper(AutoContact *, unsigned int flags=0)
Definition: AutoContact.h:289
virtual Box getNativeConstraintBox() const
Definition: AutoContact.cpp:261
Definition: AutoContact.h:59
void setWidth(const DbU::Unit &width)
void setOffset(const DbU::Unit &dx, const DbU::Unit &dy)
Point getCenter() const
Definition: AutoContact.h:216
void setLayer(const Layer *)
Definition: AutoContact.h:223
bool canMoveUp(const AutoSegment *moved) const
Definition: AutoContact.cpp:413
void setY(const DbU::Unit &y)
void setWidth(DbU::Unit)
Definition: AutoContact.h:224
void setDx(DbU::Unit)
Definition: AutoContact.h:231
DbU::Unit getHalfHeight() const
void setCBYMax(DbU::Unit yMax)
Definition: AutoContact.h:252
bool isInvalidated() const
Definition: AutoContact.h:236
virtual void translate(const DbU::Unit &tx, const DbU::Unit &ty)
Definition: AutoContact.cpp:532
Routing Global Cell.
Definition: GCell.h:74
void setSizes(const DbU::Unit &width, const DbU::Unit &height)
bool isHTee() const
Definition: AutoContact.h:242
Component * getAnchor() const
Abstract base class for AutoSegment.
Definition: AutoSegment.h:104
Definition: Constants.h:32
Interval getUConstraints(unsigned int direction) const
Definition: AutoContact.cpp:283
DbU::Unit getHeight() const
Definition: AutoContact.h:220
void migrateConstraintBox(AutoContact *other)
Definition: AutoContact.cpp:511
void setY(DbU::Unit)
Definition: AutoContact.h:228
void setSizes(DbU::Unit width, DbU::Unit height)
Definition: AutoContact.h:226
virtual DbU::Unit getY() const=0
unsigned int getMaxDepth() const
Definition: AutoContact.cpp:205
Box getConstraintBox() const
Definition: AutoContact.h:248
virtual AutoSegment * getPerpandicular(const AutoSegment *) const =0
Definition: AutoContact.cpp:183
virtual Box getBoundingBox() const
Definition: AutoContact.cpp:528
Definition: AutoContact.h:64
The namespace dedicated to Katabatic.
Definition: Katabatic.dox:13
virtual void updateTopology()=0
Locator Helper Collection&#39;s Locators.
Definition: AutoContact.h:273
const DbU::Unit & getWidth() const
Hook * getAnchorHook()
DbU::Unit getY() const
Definition: AutoContact.h:213
Component * getAnchor() const
Definition: AutoContact.h:209
const Layer * getLayer() const
Definition: AutoContact.h:211
DbU::Unit getDy() const
Definition: AutoContact.h:215
DbU::Unit getXMax() const
Definition: GCell.h:246
bool isTurn() const
Definition: AutoContact.h:238
void setHeight(DbU::Unit)
Definition: AutoContact.h:225
Point getPosition() const
Definition: AutoContact.h:217
Definition: AutoContact.h:62
DbU::Unit getHalfHeight() const
Definition: AutoContact.h:221
Definition: Constants.h:27
size_t getId() const
Definition: AutoContact.h:245
unsigned int getMinDepth() const
Definition: AutoContact.cpp:187
bool isVTee() const
Definition: AutoContact.h:243
Definition: AutoContact.h:60
DbU::Unit getYMax() const
Definition: GCell.h:247
bool canDestroy(unsigned int flags=0) const
Definition: AutoContact.cpp:161
void setDy(const DbU::Unit &dy)
Definition: AutoContact.h:57
bool isTee(unsigned int direction) const
Definition: AutoContact.cpp:406
const DbU::Unit & getDy() const
DbU::Unit getX() const
Definition: AutoContact.h:212
DbU::Unit getCBYMin() const
Definition: AutoContact.h:264
bool hasBadTopology() const
Definition: AutoContact.h:244
Box & intersectConstraintBox(Box &box) const
Definition: AutoContact.cpp:507
virtual const Name & getName() const
Definition: AutoContact.cpp:175
Components getSlaveComponents() const
Definition: AutoContact.h:222
const DbU::Unit & getHeight() const
bool restrictConstraintBox(DbU::Unit constraintMin, DbU::Unit constraintMax, unsigned int flags=KbWarnOnError)
Definition: AutoContact.cpp:453
Abstract base class for AutoContact.
Definition: AutoContact.h:70
void setCBYMin(DbU::Unit yMin)
Definition: AutoContact.h:251
void showTopologyError(const std::string &, unsigned int flags=0)
Definition: AutoContact.cpp:363
void getLengths(DbU::Unit *lengths, AutoSegment::DepthLengthSet &)
Definition: AutoContact.cpp:223
void progress()
Definition: AutoContact.h:316
Definition: AutoContact.h:61
DbU::Unit getX() const
Definition: GCell.h:244
AutoSegment * getSegment() const
Definition: AutoContact.h:310
DbU::Unit getCBXMax() const
Definition: AutoContact.h:261
virtual Point getPosition() const
Hook * getBodyHook()
Definition: AutoContact.h:207
void setCBXMin(DbU::Unit xMin)
Definition: AutoContact.h:249
virtual void updateGeometry()=0
void setLayer(const Layer *layer)
void setGCell(GCell *)
Definition: AutoContact.cpp:314
virtual AutoSegment * getOpposite(const AutoSegment *) const =0
DbU::Unit getHalfWidth() const
Definition: AutoContact.h:219
void setX(DbU::Unit)
Definition: AutoContact.h:227
static double toLambda(Unit u)
const DbU::Unit & getDx() const
void setPosition(const DbU::Unit &x, const DbU::Unit &y)
GCell * getGCell() const
Definition: AutoContact.h:247
bool isValid() const
Definition: AutoContact.h:301
Contact * base() const
Definition: AutoContact.h:246
void setHeight(const DbU::Unit &height)


Generated by doxygen 1.8.14 on Thu Oct 18 2018 Return to top of page
Katabatic - Routing Toolbox Copyright © 2008-2016 UPMC. All rights reserved