Limbo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_writer.cpp
Go to the documentation of this file.
1 
8 #include <vector>
10 
15 int main( int argc, char *argv[] )
16 {
17 
18  int
19  x[5],
20  y[5];
21 
22  if (argc < 2)
23  {
24  printf("need a output file name\n");
25  return 1;
26  }
27  // start the gds library with HEADER, BGNLIB, LIBNAME, and UNITS
28 
29  GdsParser::GdsWriter gw (argv[1]);
30  // two different wrappers
31  //gw.gds_create_lib( "dogs", 0.001 /* um per bit */ );
32  gw.create_lib("dogs", 0.001, 1.0e-9);
33 
34  // create a cell called "hotdogs"
35 
36  gw.gds_write_bgnstr( );
37  gw.gds_write_strname( "hotdogs" );
38 
40  //-----------------------------------------------------------------------------
41  // create a polygon 1
42 
43  gw.gds_write_boundary( ); // write just the token
44  gw.gds_write_layer( 10001 ); // layer 0, for example
45  gw.gds_write_datatype( 0 ); // datatype 1, for example
46 
47  x[0] = 0; y[0] = 0; // signed four-byte integers
48  x[1] = 0; y[1] = 500;
49  x[2] = 1000; y[2] = 500; // in this example 1 integer unit = 1 nm
50  x[3] = 1000; y[3] = 0;
51  x[4] = 0; y[4] = 0; // required repetition of first point (yup, that's stupid)
52 
53  gw.gds_write_xy( x, y, 5 ); // polygon, four vertices, first vertex repeated => 5 points
54  gw.gds_write_endel( ); // end of element
55  //-----------------------------------------------------------------------------
56  // create a polygon 2
57  // use high-level interfaces
58 
59  std::vector<int> vx(4);
60  std::vector<int> vy(4);
61  vx[0] = 0; vy[0] = 0; // signed four-byte integers
62  vx[1] = 0; vy[1] = 500;
63  vx[2] = 1000; vy[2] = 500; // in this example 1 integer unit = 1 nm
64  vx[3] = 1000; vy[3] = 0;
65 
66  gw.write_boundary(10002, 0, vx, vy, false);
67  //-----------------------------------------------------------------------------
68  // create a polygon 3
69  // for rectangles
70  // use high-level interfaces
71 
72  for (int i = 0; i < 1; ++i)
73  gw.write_box(10003, 0, 10, 10, 20, 20);
74 
75  //-----------------------------------------------------------------------------
76  // create some text, reflected about the x axis
77 
78  gw.gds_write_text( );
79  gw.gds_write_layer( 1 );
80  gw.gds_write_texttype( 0 );
81  gw.gds_write_presentation( 0, 1, 1 ); // font, hp, vp
82  gw.gds_write_width( 500 );
83  gw.gds_write_strans( 1, 0, 0 ); // reflect, abs_angle, abs_mag
84  x[0] = 2000;
85  y[0] = 2000;
86  gw.gds_write_xy( x, y, 1 );
87  gw.gds_write_string( "reflected" );
88  gw.gds_write_endel( );
89 
90  //-----------------------------------------------------------------------------
91  // create some text, using the helper function instead.
92  // arguments: file-descriptor, string, x, y, layer, size
93  // where x, y, and size are in database units (nanometers, usually)
94 
95  gw.gds_create_text( "not reflected", 2000, 1500, 2, 500 );
96 
97  //-----------------------------------------------------------------------------
98  // create a path
99 
100  gw.gds_write_path( );
101  gw.gds_write_layer( 3 ); // layer 3
102  gw.gds_write_datatype( 4 ); // datatype 4
103  gw.gds_write_pathtype( 2 ); // extended square ends
104  gw.gds_write_width( 200 ); // 200 nm wide
105  x[0] = 2000; y[0] = 3000;
106  x[1] = 2000; y[1] = 4000;
107  x[2] = 2500; y[2] = 3500;
108  gw.gds_write_xy( x, y, 3 );
109  gw.gds_write_endel( );
110 
111  //-----------------------------------------------------------------------------
112  // create a box, which is stupid
113 
114  gw.gds_write_box( ); // write just the token
115  gw.gds_write_layer( 6 ); // layer 6, for example
116  gw.gds_write_boxtype( 12 ); // boxtype 12, for example same as datatype
117 
118  x[0] = 3000; y[0] = 0; // signed four-byte integers
119  x[1] = 3000; y[1] = 500;
120  x[2] = 4000; y[2] = 500; // in this example 1 integer unit = 1 nm
121  x[3] = 4000; y[3] = 0;
122  x[4] = 3000; y[4] = 0; // required repetition of first point (yup, that's stupid)
123 
124  gw.gds_write_xy( x, y, 5 ); // polygon, four vertices, first vertex repeated => 5 points
125  gw.gds_write_endel( ); // end of element
126 
127 
128  // end the structure (the cell hotdogs)
129 
130  gw.gds_write_endstr( );
131 
132  //-----------------------------------------------------------------------------
133  // Create a new cell, which will contain an instance of the previous cell
134 
135  gw.gds_write_bgnstr( ); // new cell (structure)
136  gw.gds_write_strname( "sausage" ); // called "sausage"
137  gw.gds_write_sref( ); // contains an instance of...
138  gw.gds_write_sname( "hotdogs" ); // the cell hotdogs
139  gw.gds_write_mag( 5.0 ); // which will be 5 times larger
140  gw.gds_write_angle( 15.4 ); // and tilted at some weird angle
141  x[0] = 2000;
142  y[0] = -2000;
143  gw.gds_write_xy( x, y, 1 ); // at these coordinates (database units)
144  gw.gds_write_endel( ); // end of element
145  gw.gds_write_endstr( ); // end of structure (cell)
146 
147  //-----------------------------------------------------------------------------
148  // Create a new cell "meatball" containing an array of the cell "sausage"
149 
150  gw.gds_write_bgnstr( ); // new cell
151  gw.gds_write_strname( "meatball" ); // called "meatball"
152  gw.gds_write_aref( ); // containing an array of...
153  gw.gds_write_sname( "sausage" ); // the cell "sausage"
154  gw.gds_write_colrow( 2, 5 ); // 2 columns, 5 rows
155 
156  x[0] = 5000; y[0] = 5000; // array anchor point
157 
158  x[1] = 85000; y[1] = 5000; // displacement from anchor plus ncols*pitch
159  // which makes the column pitch 40 um
160  x[2] = 5000; y[2] = 205000; // displacement from anchor plus nrows*pitch
161  // which makes the row pitch 40 um
162  gw.gds_write_xy( x, y, 3 ); // See how you could have a diagonal matrix?
163  // That would be so goofy!
164  gw.gds_write_endel( ); // end of element
165  gw.gds_write_endstr( ); // end of structure (cell) "meatball"
166 
167  // end of library
168 
169  gw.gds_write_endlib( );
170 
171  printf( "\nDone. Look at %s\n\n", argv[1] );
172 
173  return 0;
174 }
void gds_write_presentation(int font, int vp, int hp)
write PRESENTATION
void gds_write_endlib()
write ENDLIB
void gds_write_endstr()
write ENDSTR
void gds_write_boxtype(short int dt)
write BOXTYPE
void gds_write_mag(double mag)
write MAG
void gds_write_endel()
write ENDEL
void gds_write_box()
write BOX
write GDSII file
void gds_write_bgnstr()
write BGNSTR
void write_box(int layer, int datatype, int xl, int yl, int xh, int yh)
write a box object
void gds_write_datatype(short int dt)
write DATATYPE
void gds_write_sname(const char *s)
write SNAME
void create_lib(const char *libname, double dbu_uu, double dbu_m)
create GDSII library
void write_boundary(int layer, int datatype, std::vector< int > const &vx, std::vector< int > const &vy, bool has_last=true)
write a boundary object
void gds_write_path()
write PATH
void gds_write_pathtype(short int pt)
write PATHTYPE
void gds_write_width(int width)
write WIDTH
void gds_write_texttype(short int dt)
write TEXTTYPE
void gds_write_xy(const int *x, const int *y, int n, bool has_last=true)
write XY
int main(int argc, char *argv[])
main function
Definition: test_writer.cpp:15
void gds_write_text()
write TEXT
void gds_write_aref()
write AREF
void gds_write_string(const char *s)
write STRING
void gds_write_layer(short int layer)
write LAYER
void gds_create_text(const char *str, int x, int y, int layer, int size)
wrapper to create text
void gds_write_boundary()
write BOUNDARY
void gds_write_strname(const char *name)
write STRNAME
void gds_write_colrow(int ncols, int nrows)
write COLROW
void gds_write_strans(BOOL reflect, BOOL abs_angle, BOOL abs_mag)
write STRANS
void gds_write_sref()
write SREF
void gds_write_angle(double angle)
write ANGLE