wxArt2D
gdsio.h
Go to the documentation of this file.
1 /*! \file wx/gdsio/gdsio.h
2  \brief GdsII format input and output
3 
4  GDSII is an important mask industry interfacing format.
5  Primitives on layers, stored in structures. This format was one of the main sources of
6  insperation for the design of wxCanvasDocument's. The most important feature is that
7  a group/structure can be placed at several location in a drawing without duplicating the data.
8  So multiple reference to a drawing, which lead to reference counted objects (a2dObject)
9  and smart pointers.
10 
11  \author Klaas Holwerda
12 
13  Copyright: 2000-2004 (c) Klaas Holwerda
14 
15  Licence: wxWidgets Licence
16 
17  RCS-ID: $Id: gdsio.h,v 1.25 2009/06/07 13:28:08 titato Exp $
18 */
19 
20 #ifndef _GDSIO_H
21 #define _GDSIO_H
22 
23 #include "a2dprivate.h"
24 
25 #if wxART2D_USE_GDSIO
26 
27 #include "wx/canvas/layerinf.h"
28 #include "wx/canvas/cantext.h"
29 #include <wx/wfstream.h>
30 
31 class Strans;
32 class a2dVpath;
33 class a2dCanvasDocument;
34 
35 // when creating a 16 or 32 bits application, the size of the values must be
36 // the same size
37 
38 typedef wxByte G_BYTE; // 8 bits -127 128
39 
40 // 32 bits application definition
41 typedef wxUint16 TWO_G_BYTE_UNSIGNED_INTEGER;
42 typedef wxUint32 FOUR_G_BYTE_UNSIGNED_INTEGER;
43 typedef wxInt16 TWO_G_BYTE_SIGNED_INTEGER;
44 typedef wxInt32 FOUR_G_BYTE_SIGNED_INTEGER;
45 typedef wxFloat32 FOUR_G_BYTE_REAL;
46 typedef wxFloat64 EIGHT_G_BYTE_REAL;
47 
48 
49 // constants for file i/o used by the written routines
50 #define GDS_ERROR -1
51 
52 // definition gdsii record constants:
53 #define GDS_DEFAULT_STRING_LENGTH 44 // default size of and GDS-II string
54 const int GDS_HEADERSIZE = 4; // size of header
55 #define GDSTYPE_TWO_G_BYTE_UNSIGNED_INTEGER 7 // record contains 2 byte unsigned integers
56 #define GDSTYPE_FOUR_G_BYTE_UNSIGNED_INTEGER 8 // record contains 4 byte unsigned integers
57 
58 // gdsii data type constants:
59 #define GDSTYPE_NO_DATA 0 // no data in record contained
60 #define GDSTYPE_BIT_ARRAY 1 // record contains bitarray vars
61 #define GDSTYPE_TWO_G_BYTE_SIGNED_INTEGER 2 // record contains 2 byte integers
62 #define GDSTYPE_FOUR_G_BYTE_SIGNED_INTEGER 3 // record contains 4 byte integers
63 #define GDSTYPE_FOUR_G_BYTE_REAL 4 // record contains 4 byte reals
64 #define GDSTYPE_EIGHT_G_BYTE_REAL 5 // record contains 8 byte reals
65 #define GDSTYPE_ASCII_STRING 6 // record contains GDSII ASCII-strings
66 
67 // gdsiifile recordtype constants:
68 // see calma document
69 #define GDS_HEADER 0
70 #define GDS_BGNLIB 1
71 #define GDS_LIBNAME 2
72 #define GDS_UNITS 3
73 #define GDS_ENDLIB 4
74 #define GDS_BGNSTR 5
75 #define GDS_STRNAME 6
76 #define GDS_ENDSTR 7
77 #define GDS_BOUNDARY 8
78 #define GDS_PATH 9
79 #define GDS_SREF 10
80 #define GDS_AREF 11
81 #define GDS_TEXT 12
82 #define GDS_LAYER 13
83 #define GDS_DATATYPE 14
84 #define GDS_WIDTH 15
85 #define GDS_XY 16
86 #define GDS_ENDEL 17
87 #define GDS_SNAME 18
88 #define GDS_COLROW 19
89 #define GDS_TEXTNODE 20
90 #define GDS_NODE 21
91 #define GDS_TEXTTYPE 22
92 #define GDS_PRESENTATION 23
93 #define GDS_SPACING 24
94 #define GDS_STRING 25
95 #define GDS_STRANS 26
96 #define GDS_MAG 27
97 #define GDS_ANGLE 28
98 #define GDS_UINTEGER 29
99 #define GDS_USTRING 30
100 #define GDS_REFLIBS 31
101 #define GDS_FONTS 32
102 #define GDS_PATHTYPE 33
103 #define GDS_GENERATIONS 34
104 #define GDS_ATTRTABLE 35
105 #define GDS_STYPTABLE 36
106 #define GDS_STRTYPE 37
107 #define GDS_ELFLAGS 38
108 #define GDS_ELKEY 39
109 #define GDS_LINKTYPE 40
110 #define GDS_LINKKEYS 41
111 #define GDS_NODETYPE 42
112 #define GDS_PROPATTR 43
113 #define GDS_PROPVALUE 44
114 #define GDS_BOX 45
115 #define GDS_BOXTYPE 46
116 #define GDS_PLEX 47
117 #define GDS_BGNEXTN 48
118 #define GDS_ENDEXTN 49
119 #define GDS_TAPENUM 50
120 #define GDS_TAPECODE 51
121 #define GDS_STRCLASS 52
122 #define GDS_RESERVED 53
123 #define GDS_FORMAT 54
124 #define GDS_MASK 55
125 #define GDS_ENDMASKS 56
126 // The following 3 items are from the Cadence Construct v4.0 GDS-extention
127 // and not part of the original GDS-II format (added for read compatibility)
128 #define GDS_LIBDIRSIZE 57
129 #define GDS_SRFNAME 58
130 #define GDS_LIBSECUR 59
131 
132 class Boundary;
133 class a2dCanvasObject;
134 class Path;
135 class a2dCameleonInst;
136 class a2dCameleon;
137 
138 //
139 // defaults for Strans
140 //
141 #define DEFAULT_STRANS_ANGLE 0
142 #define DEFAULT_STRANS_SCALE 1.0
143 #define DEFAULT_STRANS_ABS_ANGLE false
144 #define DEFAULT_STRANS_ABS_SCALE false
145 #define DEFAULT_STRANS_REFLECTION false
146 
147 //! holds GDS-II info for reflection and positioning
148 typedef struct gds_strans_bitflags
149 {
150 #if wxBYTE_ORDER == wxBIG_ENDIAN
151  unsigned reflection: 1;
152  unsigned reserved1 : 7;
153  unsigned reserved2 : 5;
154  unsigned abs_scale : 1;
155  unsigned abs_angle : 1;
156  unsigned reserved : 1;
157 #else
158  unsigned reserved : 1;
159  unsigned abs_angle : 1;
160  unsigned abs_scale : 1;
161  unsigned reserved2 : 5;
162  unsigned reserved1 : 7;
163  unsigned reflection: 1;
164 #endif
166 
167 //! class to hold GDS-II transformation info, only used within the GDSII reader
168 class A2DCANVASDLLEXP Strans
169 {
170 public:
171  //! constructor
172  Strans( double nw_angle = DEFAULT_STRANS_ANGLE,
173  double nw_scale = DEFAULT_STRANS_SCALE,
174  bool nw_abs_angle = DEFAULT_STRANS_ABS_ANGLE,
175  bool nw_abs_scale = DEFAULT_STRANS_ABS_SCALE,
176  bool nw_reflection = DEFAULT_STRANS_REFLECTION );
177 
178  Strans& operator=( Strans& a_strans );
179 
180  //! create an Strans record for GDSII file
181  void MakeStrans( const a2dAffineMatrix& matrix );
182 
183  bool GetStrans();
184  void SetAngle( double );
185  void SetScale( double );
186  void SetAbsAngle( bool );
187  void SetAbsScale( bool );
188  void SetReflection( bool );
189  double GetAngle();
190  double GetScale();
191  bool GetAbsAngle();
192  bool GetAbsScale();
193  bool GetReflection();
194 
195  //! Strans bit flags for reading and writing to binary file
196  union
197  {
198  short int total;
199  gds_strans_bitflags bits;
200  } m_stransflags;
201 
202 protected:
203  double m_angle;
204  double m_scale;
205  bool m_strans_need;
206 };
207 
208 
209 A2DCANVASDLLEXP extern const a2dError a2dError_GDSIIparse; /*!< GDSII parsing error*/
210 
211 //!Input driver for GDSII files
212 /*!
213  Every record in the GDSII file is read/mapped into the right internal structure
214  The GDSII file is parsed according to the BNF of the GDSII format.
215  Info on the different record types that are read can be found in the GDSII format manual
216  All basic data types are read using a specialized function that now how those types
217  are stored in GDSII.
218  For layers settings this handler checks for a file with the same name as the document that is loaded,
219  but with extension ".cvg", if it does exist it will be used to read layers (in CVG format).
220 
221  \ingroup fileio gdsfileio
222 */
223 class A2DCANVASDLLEXP a2dIOHandlerGDSIn : public a2dIOHandlerStrIn
224 {
225 
226 public:
227 
230 
231  bool LinkReferences();
232 
233  virtual bool CanLoad( a2dDocumentInputStream& stream, const wxObject* obj = NULL, wxClassInfo* docClassInfo = NULL );
234 
235  virtual bool Load( a2dDocumentInputStream& stream, wxObject* doc );
236 
237  virtual void InitializeLoad( );
238 
239  virtual void ResetLoad();
240 
241  //type of font to use for text
242  void SetFontType( a2dFontType fontType ) { m_fontType = fontType; }
243 
244  void SetReadAsCameleon( bool asCameleons ) { m_asCameleons = asCameleons; }
245 
246  bool GetReadAsCameleon() { return m_asCameleons; }
247 
248 protected:
249 
250  void SetDataTypeProperty( a2dCanvasObject* toobject, wxUint16 type );
251 
252  unsigned int ReadUnsignedInt();
253 
254  int ReadInt();
255 
256  long ReadLong();
257 
258  float ReadFloat();
259 
260  double ReadDouble();
261 
262  //! convert a gdsii real to a machine real
263  void gds2double( unsigned char fb[] );
264 
265  void ReadGdsII();
266  bool ReadBgnlib();
267  bool ReadProperty();
268  bool ReadBoundary( a2dCanvasObject* parent );
269 
270  bool ReadPath( a2dCanvasObject* parent );
271  bool ReadText( a2dCanvasObject* parent );
272  bool ReadStructureReference( a2dCanvasObject* parent );
273  bool ReadStructureCameleonReference( a2dCanvasObject* parent );
274  bool ReadArrayReference( a2dCanvasObject* parent );
275  bool ReadNode( a2dCanvasObject* parent );
276  bool ReadBox( a2dCanvasObject* parent );
277  bool ReadElflags( a2dCanvasObject* object );
278  bool ReadGdsHeader();
279  bool ReadLayer( a2dCanvasObject* object );
280  bool ReadLayer( int& layer );
281  bool ReadLibraryName();
282  bool ReadLibrarySettings();
283  bool Read( a2dPoint2D& _Point );
284  bool ReadStrans( Strans& _Strans );
285  bool ReadStructure( a2dCanvasObject* parent );
286  bool ReadCameleonStructure( a2dCanvasObject* parent );
287  bool ReadElement( a2dCanvasObject* parent );
288  bool ReadTextBody();
289 
290  bool Read( a2dVertexList* segments );
291 
292  bool Read( a2dPolygonL* polygon );
293 
294  //!read the specified record type from the GDSII file
295  //!if the last record is not this type, it is stored for the next read
296  bool ReadHeader( int type );
297 
298  //!skip the date of the last read record
299  void SkipData();
300 
301  //!read string data for Text element, structure names etc.
302  void ReadString( wxString& a_string );
303 
304  //!last read record is stored
305  bool m_back;
306 
307  //!size of the last read record
308  TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize;
309 
310  //!recordtype of last read record
311  G_BYTE m_recordtype;
312 
313  //!the type of the data in the last read record
314  G_BYTE m_datatype;
315 
316  //!mapping of GDSII layers to internal layers
317  std::vector<int> m_mapping;
318 
319  //! the document to store/load the data found into
321 
322  double m_userunits_out;
323 
324  int m_objectFlags;
325 
326  //type of font to use for text
327  a2dFontType m_fontType;
328 
329  //! structure that is being read at the moment
330  wxString m_strucname;
331 
332  int m_refMaxx;
333  int m_dx, m_dy;
334 
335  bool m_asCameleons;
336 
337 };
338 
339 
340 //!Output driver for GDSII files
341 /*!
342  Every record in the GDSII file is read/mapped into the right gds file structure
343  Info on the different record types that are read can be found in the GDSII format manual
344 
345  \ingroup fileio gdsfileio
346 */
347 class A2DCANVASDLLEXP a2dIOHandlerGDSOut : public a2dIOHandlerStrOut
348 {
349 
350 public:
351 
354 
355  bool CanSave( const wxObject* obj = NULL );
356 
357  virtual bool Save( a2dDocumentOutputStream& stream, const wxObject* doc );
358 
359  virtual void InitializeSave( );
360 
361  virtual void ResetSave();
362 
363  void SetReadAsCameleon( bool asCameleons ) { m_asCameleons = asCameleons; }
364 
365  bool GetReadAsCameleon() { return m_asCameleons; }
366 
367  //! if set text will be converted to a vectorpath, and as polygons and polylines.
368  void SetSaveTextAsVpath( bool textAsPath ) { m_textAsPath = textAsPath; }
369 
370  //! /see SetSaveTextAsVpath()
371  bool GetSaveTextAsVpath() { return m_textAsPath; }
372 
373  //! if set, the current view its ShowObject will be saved top down.
374  void SetFromViewAsTop( bool fromViewAsTop ) { m_fromViewAsTop = fromViewAsTop; }
375 
376  //! /see SetFromViewAsTop()
377  bool GetFromViewAsTop() { return m_fromViewAsTop; }
378 
379 protected:
380 
381  unsigned int ReadUnsignedInt();
382 
383  int ReadInt();
384 
385  long ReadLong();
386 
387  float ReadFloat();
388 
389  double ReadDouble();
390 
391  void WriteByte( G_BYTE ch );
392 
393  void WriteUnsignedInt( TWO_G_BYTE_UNSIGNED_INTEGER i );
394 
395  void WriteInt( TWO_G_BYTE_SIGNED_INTEGER i );
396 
397  void WriteLong( FOUR_G_BYTE_SIGNED_INTEGER i );
398 
399  void WriteFloat( FOUR_G_BYTE_REAL i );
400 
401  void WriteDouble( EIGHT_G_BYTE_REAL i );
402 
403  void Write( Strans* Strans );
404 
405  void WriteHeader( TWO_G_BYTE_UNSIGNED_INTEGER nw_recordsize, G_BYTE nw_datatype, G_BYTE nw_recordtype );
406 
407  void WriteString( const wxString& a_string );
408 
409  void SetFlags( a2dCanvasObject* Element );
410 
411  void WritePoint( double xi, double yi );
412 
413  void WriteVpath( const a2dAffineMatrix& lworld, const a2dVpath* path, int layer, int datatype, int pathtype, double width );
414 
415  void WritePath( const a2dAffineMatrix& lworld, a2dVertexArray* points, int layer, int datatype, int pathtype, double width );
416 
417  void WritePath( const a2dAffineMatrix& lworld, a2dVertexList* points, int layer, int datatype, int pathtype, double width );
418 
419  void WriteBoundary( const a2dAffineMatrix& lworld, a2dVertexArray* points, int layer, int datatype );
420 
421  void WriteBoundary( const a2dAffineMatrix& lworld, a2dVertexList* points, int layer, int datatype, bool spline = false );
422 
423  void SaveStructure( a2dCanvasObject* object, a2dCanvasObjectList* towrite );
424 
425  void Save( a2dCanvasObject* object, a2dCanvasObjectList* towrite );
426 
427  void DoSave( a2dPolylineL* obj, a2dCanvasObjectList* towrite );
428 
429  void DoSave( a2dPolygonL* obj, a2dCanvasObjectList* towrite );
430 
431  void DoSave( a2dVectorPath* obj, a2dCanvasObjectList* towrite );
432 
433  void DoSave( a2dText* obj, a2dCanvasObjectList* towrite );
434 
435  void DoSave( a2dTextGDS* obj, a2dCanvasObjectList* towrite );
436 
437  void DoSave( a2dCanvasObjectReference* obj, a2dCanvasObjectList* towrite );
438 
439  void DoSave( a2dCameleonInst* obj, a2dCanvasObjectList* towrite );
440 
441  void DoSave( a2dCameleon* obj, a2dCanvasObjectList* towrite );
442 
443  void DoSave( a2dCanvasObjectArrayReference* obj, a2dCanvasObjectList* towrite );
444 
445  //! convert a machine real to a gdsii real
446  void double2gds( unsigned char fb[] );
447 
448  //!last read record is stored
449  bool m_back;
450 
451  //!size of the last read record
452  TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize;
453 
454  //!recordtype of last read record
455  G_BYTE m_recordtype;
456 
457  //!the type of the data in the last read record
458  G_BYTE m_datatype;
459 
460  //!mapping of GDSII layers to internal layers
461  std::vector<int> m_mapping;
462 
463  //! the document to store/load the data found into
465 
466  double m_scale_out;
467 
468  double m_userunits_out;
469 
470  int m_objectFlags;
471 
472  //! if true, convert text to a2dVpath
474 
475  bool m_fromViewAsTop;
476 
477  a2dLayers* m_layers;
478 
479  bool m_asCameleons;
480 };
481 
482 #endif //wxART2D_USE_GDSIO
483 
484 #endif //_GDSIO_H
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
Definition: artglob.h:47
a2dText derived from a2dCanvasObject, holds multiline text
a2dCanvasObjectReference is a reference to any a2dCanvasObject derived class.
Definition: recur.h:53
virtual void InitializeLoad()
Inits the handler for reading.
Definition: gen.cpp:4971
holds GDS-II info for reflection and positioning
Definition: gdsio.h:148
a2dTextGDS text based on wxDC text drawing.
Definition: cantext.h:467
virtual bool Load(a2dDocumentInputStream &stream, wxObject *obj)=0
override to read the stream and store (part of) the contents in to a specific a2dDocument or othere o...
TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize
size of the last read record
Definition: gdsio.h:308
virtual void InitializeSave()
Inits the handler for writing.
Definition: gen.cpp:5095
virtual void ResetSave()
Reset the object after saving.
Definition: gen.cpp:5101
polygon defined with list of points.
Definition: polygon.h:45
wxString m_strucname
structure that is being read at the moment
Definition: gdsio.h:330
wxOutputStream a2dDocumentOutputStream
output stream based wxStreams
Definition: gen.h:3458
a2dCanvasDocument * m_doc
the document to store/load the data found into
Definition: gdsio.h:320
Input driver for GDSII files.
Definition: gdsio.h:223
using a file stream for input, stream the file into a a2dDocument or other object ...
Definition: gen.h:3632
vertex array of line and arc segments.
Definition: polyver.h:494
bool m_textAsPath
if true, convert text to a2dVpath
Definition: gdsio.h:473
object to show several appearance views on what it contains
Definition: cameleon.h:630
virtual bool CanLoad(a2dDocumentInputStream &stream, const wxObject *obj=NULL, wxClassInfo *docClassInfo=NULL)=0
Should return true if the handler can read from the stream.
a2dCanvasObject is the base class for Canvas Objects.
Definition: canobj.h:371
bool GetSaveTextAsVpath()
/see SetSaveTextAsVpath()
Definition: gdsio.h:371
a2dCanvasObjectArrayReference is an array of a reference to any a2dCanvasObject derived class...
Definition: recur.h:131
std::vector< int > m_mapping
mapping of GDSII layers to internal layers
Definition: gdsio.h:317
vertex list of line and arc segments.
Definition: polyver.h:600
bool m_back
last read record is stored
Definition: gdsio.h:305
struct gds_strans_bitflags gds_strans_bitflags
holds GDS-II info for reflection and positioning
void SetFromViewAsTop(bool fromViewAsTop)
if set, the current view its ShowObject will be saved top down.
Definition: gdsio.h:374
a2dText is an abstract base class.
Definition: cantext.h:93
polyline defined with list of points.
Definition: polygon.h:332
a2dCameleonInst to show one appearance of an a2dCameleon.
Definition: cameleon.h:272
layer settings for a a2dCanvasDocument Holds layers settings classes
G_BYTE m_recordtype
recordtype of last read record
Definition: gdsio.h:455
G_BYTE m_datatype
the type of the data in the last read record
Definition: gdsio.h:314
void SetSaveTextAsVpath(bool textAsPath)
if set text will be converted to a vectorpath, and as polygons and polylines.
Definition: gdsio.h:368
bool m_back
last read record is stored
Definition: gdsio.h:449
virtual bool Save(a2dDocumentOutputStream &stream, const wxObject *obj)=0
Override to write to the stream and store (part of) of the document contents in the stream...
using a file stream for output, stream a a2dDocument or other wxObject into a stream.
Definition: gen.h:3751
A 2x3 affine matrix class for 2D transformations.
Definition: afmatrix.h:53
a2dCanvasDocument * m_doc
the document to store/load the data found into
Definition: gdsio.h:464
TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize
size of the last read record
Definition: gdsio.h:452
std::vector< int > m_mapping
mapping of GDSII layers to internal layers
Definition: gdsio.h:461
wxInputStream a2dDocumentInputStream
input stream based wxStreams
Definition: gen.h:3456
virtual bool CanSave(const wxObject *obj=NULL)=0
Should return true if the handler can write this document to a stream.
G_BYTE m_datatype
the type of the data in the last read record
Definition: gdsio.h:458
Each a2dCanvasView needs to have a a2dCanvasDocument set in order to render data. ...
Definition: candoc.h:374
class to hold GDS-II transformation info, only used within the GDSII reader
Definition: gdsio.h:168
Output driver for GDSII files.
Definition: gdsio.h:347
G_BYTE m_recordtype
recordtype of last read record
Definition: gdsio.h:311
bool GetFromViewAsTop()
/see SetFromViewAsTop()
Definition: gdsio.h:377
a2dCanvasObject for a Vector Path
Definition: vpath.h:55
holds one error report.
Definition: gen.h:623
Vector Path.
Definition: polyver.h:1211
virtual void WriteDouble(double d)
write a double
Definition: gen.cpp:5199
virtual bool LinkReferences(bool ignoreNonResolved=false)
link references to their destination
Definition: gen.cpp:4862
virtual void WriteString(const wxString &string)
write a string
Definition: gen.cpp:5107
virtual void ResetLoad()
Reset the handler after loading.
Definition: gen.cpp:4977
const a2dError a2dError_GDSIIparse
gdsio.h Source File -- Sun Oct 12 2014 17:04:20 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation