Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GdsObjects.h
Go to the documentation of this file.
1 
8 #ifndef LIMBO_PARSERS_GDSII_GDSDB_GDSOBJECTS_H
9 #define LIMBO_PARSERS_GDSII_GDSDB_GDSOBJECTS_H
10 
11 #include <boost/geometry.hpp>
12 // use adapted boost.polygon in boost.geometry, which is compatible to rtree
13 #include <boost/geometry/geometries/adapted/boost_polygon.hpp>
14 #include <boost/geometry/geometries/geometries.hpp>
16 
18 namespace GdsParser
19 {
21 namespace GdsDB
22 {
23 
24 // some shortcuts for namespace
25 namespace gtl = boost::polygon;
26 namespace bg = boost::geometry;
27 
28 // forward declaration
29 class GdsCell;
30 class GdsDB;
31 
36 class GdsObject
37 {
38  public:
40  typedef int coordinate_type;
44  typedef gtl::point_data<coordinate_type> point_type;
46  typedef gtl::interval_data<coordinate_type> interval_type;
48  typedef gtl::rectangle_data<coordinate_type> rectangle_type;
50  typedef gtl::polygon_data<coordinate_type> polygon_type;
52  typedef gtl::polygon_90_set_data<coordinate_type> polygon_set_type;
54 
56  GdsObject();
59  GdsObject(GdsObject const& rhs);
62  GdsObject& operator=(GdsObject const& rhs);
67  virtual ~GdsObject();
68 };
69 
73 class GdsShape : public GdsObject
74 {
75  public:
78 
80  GdsShape();
83  GdsShape(GdsShape const& rhs);
86  GdsShape& operator=(GdsShape const& rhs);
88  ~GdsShape();
89 
90  // accessors
92  int layer() const {return m_layer;}
94  void setLayer(int l) {m_layer = l;}
95 
97  int datatype() const {return m_datatype;}
99  void setDatatype(int d) {m_datatype = d;}
100  protected:
101  int m_layer;
103 };
104 
124 class GdsRectangle : public GdsShape, public gtl::rectangle_data<int>
125 {
126  public:
128  typedef GdsShape base_type;
130  typedef gtl::rectangle_data<int> base_ext_type;
131 
133  GdsRectangle();
136  GdsRectangle(GdsRectangle const& rhs);
139  GdsRectangle& operator=(GdsRectangle const& rhs);
141  ~GdsRectangle();
142 };
143 
173 class GdsPolygon : public GdsShape, public gtl::polygon_data<GdsShape::coordinate_type>
174 {
175  public:
177  typedef GdsShape base_type;
179  typedef gtl::polygon_data<GdsShape::coordinate_type> base_ext_type;
182  typedef base_type::point_type point_type;
184 
186  GdsPolygon();
189  GdsPolygon(GdsPolygon const& rhs);
192  GdsPolygon& operator=(GdsPolygon const& rhs);
194  ~GdsPolygon();
195 };
196 
230 class GdsPath : public GdsShape, public bg::model::linestring<GdsShape::point_type>
231 {
232  public:
234  typedef GdsShape base_type;
236  typedef bg::model::linestring<GdsShape::point_type> base_ext_type;
237 
239  GdsPath();
242  GdsPath(GdsPath const& rhs);
245  GdsPath& operator=(GdsPath const& rhs);
247  ~GdsPath();
248 
249  // accessors
251  int pathtype() const {return m_pathtype;}
253  void setPathtype(int p) {m_pathtype = p;}
254 
256  coordinate_type width() const {return m_width;}
259 
263  template <typename Iterator>
264  void set(Iterator first, Iterator last) {this->assign(first, last);}
265 
268  GdsPolygon toPolygon() const;
269  protected:
272 };
273 
306 class GdsText : public GdsShape
307 {
308  public:
310  typedef GdsShape base_type;
311 
313  GdsText();
316  GdsText(GdsText const& rhs);
319  GdsText& operator=(GdsText const& rhs);
321  ~GdsText();
322 
323  // accessors
325  int texttype() const {return m_texttype;}
327  void setTexttype(int t) {m_texttype = t;}
328 
330  std::string const& text() const {return m_text;}
332  void setText(std::string const& t) {m_text = t;}
333 
335  int width() const {return m_width;}
337  void setWidth(int w) {m_width = w;}
338 
340  point_type const& position() const {return m_position;}
342  void setPosition(point_type const& p) {m_position = p;}
343 
345  int presentation() const {return m_presentation;}
347  void setPresentation(int p) {m_presentation = p;}
348 
350  double angle() const {return m_angle;}
352  void setAngle(double a) {m_angle = a;}
353 
355  double magnification() const {return m_magnification;}
357  void setMagnification(double m) {m_magnification = m;}
358 
360  int strans() const {return m_strans;}
362  void setStrans(int s) {m_strans = s;}
363  protected:
365  std::string m_text;
366  point_type m_position;
367  int m_width;
369  double m_angle;
371  int m_strans;
372 };
373 
392 {
393  public:
396 
398  GdsCellReference();
401  GdsCellReference(GdsCellReference const& rhs);
407 
408  // accessors
410  std::string const& refCell() const {return m_refCell;}
412  void setRefCell(std::string const& r) {m_refCell = r;}
413 
415  point_type const& position() const {return m_position;}
417  void setPosition(point_type const& p) {m_position = p;}
418 
420  double angle() const {return m_angle;}
422  void setAngle(double a) {m_angle = a;}
423 
425  double magnification() const {return m_magnification;}
427  void setMagnification(double m) {m_magnification = m;}
428 
430  int strans() const {return m_strans;}
432  void setStrans(int s) {m_strans = s;}
433 
439  GdsCell extractCellRef(GdsDB const& gdsDB, GdsCell const& srcCell) const;
440  protected:
441  std::string m_refCell;
442  point_type m_position;
443  double m_angle;
445  int m_strans;
446 };
447 
471 class GdsCellArray : public GdsObject
472 {
473  public:
476 
478  GdsCellArray();
481  GdsCellArray(GdsCellArray const& rhs);
484  GdsCellArray& operator=(GdsCellArray const& rhs);
486  ~GdsCellArray();
487 
488  // accessors
490  std::string const& refCell() const {return m_refCell;}
492  void setRefCell(std::string const& r) {m_refCell = r;}
493 
495  int columns() const {return m_columns;}
497  void setColumns(int c) {m_columns = c;}
498 
500  int rows() const {return m_rows;}
502  void setRows(int r) {m_rows = r;}
503 
506  coordinate_type spacing(unsigned int idx) const {return m_spacing[idx];}
509  void setSpacing(unsigned int idx, coordinate_type s) {m_spacing[idx] = s;}
510 
512  std::vector<point_type> const& positions() const {return m_vPosition;}
514  std::vector<point_type>& positions() {return m_vPosition;}
515 
517  double angle() const {return m_angle;}
519  void setAngle(double a) {m_angle = a;}
520 
522  double magnification() const {return m_magnification;}
524  void setMagnification(double m) {m_magnification = m;}
525 
527  int strans() const {return m_strans;}
529  void setStrans(int s) {m_strans = s;}
530  protected:
531  std::string m_refCell;
532  int m_columns;
533  int m_rows;
535  std::vector<point_type> m_vPosition;
536  double m_angle;
538  int m_strans;
539 };
540 
553 class GdsCell : public GdsObject
554 {
555  public:
559  typedef std::pair< ::GdsParser::GdsRecords::EnumType, GdsObject*> object_entry_type;
560 
562  GdsCell();
565  GdsCell(GdsCell const& rhs);
568  GdsCell& operator=(GdsCell const& rhs);
570  ~GdsCell();
571 
575  void addPolygon(int layer, int datatype, std::vector<point_type> const& vPoint);
581  void addPath(int layer, int datatype, int pathtype, int width, std::vector<point_type> const& vPoint);
592  void addText(int layer, int datatype, int texttype, std::string const& str, point_type const& position, int width, int presentation, double angle, double magnification, int strans);
598  void addCellReference(std::string const& sname, point_type const& position, double angle, double magnification, int strans);
607  void addCellArray(std::string const& sname, int columns, int rows, int spacing[2], std::vector<point_type> const& vPosition, double angle, double magnification, int strans);
608 
609  // accessors
611  std::string const& name() const {return m_name;}
613  void setName(std::string const& n) {m_name = n;}
614 
616  std::vector<std::pair< ::GdsParser::GdsRecords::EnumType, GdsObject*> > const& objects() const {return m_vObject;}
618  std::vector<std::pair< ::GdsParser::GdsRecords::EnumType, GdsObject*> >& objects() {return m_vObject;}
619  protected:
622  void copy(GdsCell const& rhs);
624  void destroy();
625 
626  std::string m_name;
627  std::vector<object_entry_type> m_vObject;
628 };
629 
644 class GdsDB : public GdsObject
645 {
646  public:
649 
651  GdsDB();
654  GdsDB(GdsDB const& rhs);
657  GdsDB& operator=(GdsDB const& rhs);
659  ~GdsDB();
660 
663  GdsCell& addCell(std::string const& name = "");
666  GdsCell& addCell(GdsCell const& cell);
667 
668  // accessors
670  std::string const& header() const {return m_header;}
672  void setHeader(std::string const& h) {m_header = h;}
674  void setHeader(int h);
675 
677  std::string const& libname() const {return m_libname;}
679  void setLibname(std::string const& n) {m_libname = n;}
680 
682  double unit() const {return m_unit;}
684  void setUnit(double u) {m_unit = u;}
685 
687  double precision() const {return m_precision;}
689  void setPrecision(double p) {m_precision = p;}
690 
692  std::vector<GdsCell> const& cells() const {return m_vCell;}
694  std::vector<GdsCell>& cells() {return m_vCell;}
695 
700  GdsCell const* getCell(std::string const& cellName) const;
705  GdsCell* getCell(std::string const& cellName);
706 
709  GdsCell extractCell(std::string const& cellName) const;
710  protected:
711  std::string m_header;
712  std::string m_libname;
713  double m_unit;
714  double m_precision;
715  std::vector<GdsCell> m_vCell;
716  std::map<std::string, unsigned int> m_mCellName2Idx;
717 };
718 
719 } // namespace GdsDB
720 } // namespace GdsParser
721 
722 
724 namespace boost { namespace geometry { namespace traits {
725 
728 
730 template <>
731 struct tag<GdsParser::GdsDB::GdsRectangle > : public tag<GdsParser::GdsDB::GdsRectangle::base_ext_type>
732 {
733 };
735 template <>
736 struct point_type<GdsParser::GdsDB::GdsRectangle >
737 {
739  typedef GdsParser::GdsDB::GdsRectangle::point_type type;
741 };
743 
746 
748 template <>
749 struct tag<GdsParser::GdsDB::GdsPolygon > : public tag<GdsParser::GdsDB::GdsPolygon::base_ext_type>
750 {
751 };
753 template <>
754 struct point_type<GdsParser::GdsDB::GdsPolygon >
755 {
757  typedef GdsParser::GdsDB::GdsObject::point_type type;
759 };
761 
762 }}} // namespace boost // namespace geometry // namespace traits
763 
765 namespace boost { namespace polygon {
766 
768 template <>
769 struct geometry_concept<GdsParser::GdsDB::GdsRectangle>
770 {
772  typedef rectangle_concept type;
774 };
775 
777 template <>
778 struct geometry_concept<GdsParser::GdsDB::GdsPolygon>
779 {
781  typedef polygon_concept type;
783 };
784 
785 }} // namespace boost // namespace polygon
786 
787 #endif
coordinate_type m_width
path width
Definition: GdsObjects.h:271
void setHeader(std::string const &h)
Definition: GdsObjects.h:672
std::string const & refCell() const
Definition: GdsObjects.h:490
std::string m_refCell
string to reference cell
Definition: GdsObjects.h:441
gtl::rectangle_data< int > base_ext_type
rectangle type
Definition: GdsObjects.h:130
coordinate_type m_spacing[2]
spacing of x and y
Definition: GdsObjects.h:534
GdsObject()
default constructor
void addPolygon(int layer, int datatype, std::vector< point_type > const &vPoint)
void setPosition(point_type const &p)
Definition: GdsObjects.h:417
gtl::rectangle_data< coordinate_type > rectangle_type
rectangle type
Definition: GdsObjects.h:48
double m_magnification
magnification
Definition: GdsObjects.h:444
Boost.Geometry.
Definition: GdsObjects.h:724
void addText(int layer, int datatype, int texttype, std::string const &str, point_type const &position, int width, int presentation, double angle, double magnification, int strans)
std::string m_text
text string
Definition: GdsObjects.h:365
std::vector< point_type > & positions()
Definition: GdsObjects.h:514
GdsCell extractCellRef(GdsDB const &gdsDB, GdsCell const &srcCell) const
void setWidth(coordinate_type w)
Definition: GdsObjects.h:258
void setRefCell(std::string const &r)
Definition: GdsObjects.h:492
GdsObject base_type
base type
Definition: GdsObjects.h:557
void setAngle(double a)
Definition: GdsObjects.h:352
point_type const & position() const
Definition: GdsObjects.h:415
std::string const & header() const
Definition: GdsObjects.h:670
gtl::polygon_data< coordinate_type > polygon_type
polygon type
Definition: GdsObjects.h:50
bg::model::linestring< GdsShape::point_type > base_ext_type
use a linestring to describe path
Definition: GdsObjects.h:236
double magnification() const
Definition: GdsObjects.h:355
std::string const & libname() const
Definition: GdsObjects.h:677
double precision() const
Definition: GdsObjects.h:687
GdsPath()
default constructor
void setRefCell(std::string const &r)
Definition: GdsObjects.h:412
GdsShape base_type
base type
Definition: GdsObjects.h:128
GdsObject base_type
base type
Definition: GdsObjects.h:648
double m_magnification
magnification
Definition: GdsObjects.h:537
std::string m_libname
name of library
Definition: GdsObjects.h:712
double m_magnification
magnification
Definition: GdsObjects.h:370
int presentation() const
Definition: GdsObjects.h:345
int m_datatype
data type
Definition: GdsObjects.h:102
GdsCellArray & operator=(GdsCellArray const &rhs)
void setSpacing(unsigned int idx, coordinate_type s)
Definition: GdsObjects.h:509
GdsRectangle & operator=(GdsRectangle const &rhs)
GdsPolygon toPolygon() const
convert from path to polygon description
GdsShape()
default constructor
GdsObject base_type
base type
Definition: GdsObjects.h:475
int m_rows
number of rows
Definition: GdsObjects.h:533
std::pair< ::GdsParser::GdsRecords::EnumType, GdsObject * > object_entry_type
use pair of GDSII record and GDSII object to describe each object entry
Definition: GdsObjects.h:559
void addPath(int layer, int datatype, int pathtype, int width, std::vector< point_type > const &vPoint)
GdsCellArray()
default constructor
std::vector< std::pair< ::GdsParser::GdsRecords::EnumType, GdsObject * > > const & objects() const
Definition: GdsObjects.h:616
point_type m_position
position
Definition: GdsObjects.h:442
GdsCellReference & operator=(GdsCellReference const &rhs)
void addCellArray(std::string const &sname, int columns, int rows, int spacing[2], std::vector< point_type > const &vPosition, double angle, double magnification, int strans)
GdsCell extractCell(std::string const &cellName) const
extract a cell into a new cell with flatten hierarchies
GdsCell & addCell(std::string const &name="")
add a cell and return the reference to the new cell
GdsShape base_type
base type
Definition: GdsObjects.h:177
void addCellReference(std::string const &sname, point_type const &position, double angle, double magnification, int strans)
int m_texttype
text type
Definition: GdsObjects.h:364
GdsDB & operator=(GdsDB const &rhs)
std::string m_refCell
reference cell
Definition: GdsObjects.h:531
coordinate_type spacing(unsigned int idx) const
Definition: GdsObjects.h:506
GdsCellReference()
default constructor
void setPresentation(int p)
Definition: GdsObjects.h:347
double unit() const
Definition: GdsObjects.h:682
gtl::polygon_data< GdsShape::coordinate_type > base_ext_type
use polygon_data as polygon type
Definition: GdsObjects.h:179
std::vector< GdsCell > const & cells() const
Definition: GdsObjects.h:692
void set(Iterator first, Iterator last)
set path
Definition: GdsObjects.h:264
void setUnit(double u)
Definition: GdsObjects.h:684
void setPosition(point_type const &p)
Definition: GdsObjects.h:342
void setPrecision(double p)
Definition: GdsObjects.h:689
std::vector< point_type > const & positions() const
Definition: GdsObjects.h:512
std::vector< GdsCell > & cells()
Definition: GdsObjects.h:694
GdsShape & operator=(GdsShape const &rhs)
double magnification() const
Definition: GdsObjects.h:522
point_type m_position
position
Definition: GdsObjects.h:366
std::map< std::string, unsigned int > m_mCellName2Idx
map from cell name to index
Definition: GdsObjects.h:716
void destroy()
destroy objects in m_vObject
void setName(std::string const &n)
Definition: GdsObjects.h:613
namespace for Limbo.GdsParser
Definition: GdsIO.h:19
coordinate_type width() const
Definition: GdsObjects.h:256
GdsText & operator=(GdsText const &rhs)
void setText(std::string const &t)
Definition: GdsObjects.h:332
void setLibname(std::string const &n)
Definition: GdsObjects.h:679
void setMagnification(double m)
Definition: GdsObjects.h:357
GdsPath & operator=(GdsPath const &rhs)
GdsPolygon()
default constructor
std::vector< GdsCell > m_vCell
cell array
Definition: GdsObjects.h:715
gtl::interval_data< coordinate_type > interval_type
interval type
Definition: GdsObjects.h:46
GdsShape base_type
base type
Definition: GdsObjects.h:234
GdsRectangle()
default constructor
std::vector< object_entry_type > m_vObject
gdsii objects with types
Definition: GdsObjects.h:627
gtl::polygon_90_set_data< coordinate_type > polygon_set_type
polygon set type
Definition: GdsObjects.h:52
std::vector< point_type > m_vPosition
array of positions
Definition: GdsObjects.h:535
GdsText()
default constructor
void setMagnification(double m)
Definition: GdsObjects.h:524
double m_precision
precision
Definition: GdsObjects.h:714
void copy(GdsCell const &rhs)
GdsPolygon & operator=(GdsPolygon const &rhs)
int m_columns
number of columns
Definition: GdsObjects.h:532
std::vector< std::pair< ::GdsParser::GdsRecords::EnumType, GdsObject * > > & objects()
Definition: GdsObjects.h:618
GdsObject & operator=(GdsObject const &rhs)
assignment
read GDSII file
std::string m_header
header
Definition: GdsObjects.h:711
int m_pathtype
path type
Definition: GdsObjects.h:270
virtual ~GdsObject()
destructor
GdsCell()
default constructor
double angle() const
Definition: GdsObjects.h:350
GdsObject base_type
base type
Definition: GdsObjects.h:395
GdsObject base_type
base type
Definition: GdsObjects.h:77
std::string m_name
cell name
Definition: GdsObjects.h:626
GdsShape base_type
base type
Definition: GdsObjects.h:310
GdsCell const * getCell(std::string const &cellName) const
given cell name and return the pointer to the cell, return NULL if not found
GdsCell & operator=(GdsCell const &rhs)
int m_presentation
presentation
Definition: GdsObjects.h:368
int coordinate_type
coordinate types
Definition: GdsObjects.h:40
std::string const & refCell() const
Definition: GdsObjects.h:410
point_type const & position() const
Definition: GdsObjects.h:340
std::string const & text() const
Definition: GdsObjects.h:330
std::string const & name() const
Definition: GdsObjects.h:611