wxArt2D
keyio.h
Go to the documentation of this file.
1 /*! \file wx/keyio/keyio.h
2  \brief KEY input and output
3 
4  The loader and saver for the KEY format. The KEY format is GDSII in ascii,
5  but extended to be able to contain more types of primitives.
6  It is typically used in the electronic mask industry. For instance Color and line thickness
7  or of no importance, primtives are placed on layers, just to tell which are on the layers is filled.
8 
9  \author Klaas Holwerda
10 
11  Copyright: 2000-2004 (c) Klaas Holwerda
12 
13  Licence: wxWidgets Licence
14 
15  RCS-ID: $Id: keyio.h,v 1.18 2009/05/15 16:34:28 titato Exp $
16 */
17 
18 #ifndef _KEYIO_H
19 #define _KEYIO_H
20 
21 #include <wx/wfstream.h>
22 
23 #include "a2dprivate.h"
24 
25 #if wxART2D_USE_KEYIO
26 
27 #include "wx/canvas/layerinf.h"
28 #include "wx/gdsio/gdsio.h"
29 
30 
31 //!Input driver for KEY format files
32 /*!
33  Every record in the KEY file is read/mapped into the right internal structure
34  The KEY file is parsed according to the BNF of the KEY format.
35  Info on the different record types that are read can be found in the KEY format manual
36  All basic data types are read using a specialized function that now how those types
37  are stored in KEY.
38  For layers settings this handler checks for a file with the same name as the document that is loaded,
39  but with extension ".cvg", if it does exist it will be used to read layers (in CVG format).
40 
41  \ingroup fileio keyfileio
42 */
43 class A2DCANVASDLLEXP a2dIOHandlerKeyIn : public a2dIOHandlerStrIn
44 {
45 
46 public:
47 
50 
51  bool LinkReferences();
52 
53  wxChar PeekNextC();
54 
55  void IncC();
56 
57  virtual bool CanLoad( a2dDocumentInputStream& stream, const wxObject* obj = NULL, wxClassInfo* docClassInfo = NULL );
58 
59  virtual bool Load( a2dDocumentInputStream& stream, wxObject* doc );
60 
61  virtual void InitializeLoad( );
62 
63  virtual void ResetLoad();
64 
65  void SetReadAsCameleon( bool asCameleons ) { m_asCameleons = asCameleons; }
66 
67  bool GetReadAsCameleon() { return m_asCameleons; }
68 
69 protected:
70 
71  bool GetCommand();
72 
73  bool NormalWord();
74  bool QuotedString();
75  bool BracedString();
76  bool Comment();
77 
78  bool Blanks();
79 
80  bool Word();
81 
82  bool ReadItem( const wxString& type );
83 
84  bool SkipXYData();
85 
86  double ReadDouble();
87 
88  //! set datatype of elements as a property
89  void SetDataTypeProperty( a2dCanvasObject* toobject, wxUint16 type );
90 
91  void ReadKey();
92  bool ReadBgnlib();
93  bool ReadProperties( a2dCanvasObject* parent );
94  bool ReadParameters( a2dCanvasObject* parent );
95  bool ReadBoundary( a2dCanvasObject* parent );
96  bool ReadSurface( a2dCanvasObject* parent );
97  bool ReadPath( a2dCanvasObject* parent );
98  bool ReadText( a2dCanvasObject* parent );
99  bool ReadStructureReference( a2dCanvasObject* parent );
100  bool ReadStructureCameleonReference( a2dCanvasObject* parent );
101  bool ReadArrayReference( a2dCanvasObject* parent );
102  bool ReadNode( a2dCanvasObject* parent );
103  bool ReadBox( a2dCanvasObject* parent );
104  bool ReadCircle( a2dCanvasObject* parent );
105  bool ReadArc( a2dCanvasObject* parent );
106  bool ReadLine( a2dCanvasObject* parent );
107  bool ReadImage( a2dCanvasObject* parent );
108 
109  bool ReadElflags( a2dCanvasObject* object );
110  bool ReadGdsHeader();
111  bool ReadLayer( a2dCanvasObject* object );
112  bool ReadLibrarySettings();
113  bool Read( a2dPoint2D& _Point );
114  bool ReadStrans( Strans& _Strans );
115  bool ReadStructure( a2dCanvasObject* parent );
116  bool ReadCameleonStructure( a2dCanvasObject* parent );
117  bool ReadElement( a2dCanvasObject* parent );
118  bool ReadTextBody();
119 
120  bool ReadPolygon( a2dVertexList* segments );
121  bool ReadPolyline( a2dVertexList* segments );
122 
123  void SetFlags( a2dCanvasObject* Element );
124 
125  //!last read record is stored
126  bool m_back;
127 
128  //!keyword for record in KEY data
129  wxString m_keyword;
130  //!value for record in KEY data
131  wxString m_value;
132 
133  //!type of the record in KEY data
135 
136  //!last read line in DATA
137  wxUint32 m_linenumber;
138 
139  wxChar a;
140  wxString m_error_mes;
141  wxString m_b;
142 
143  //!size of the last read record
144  TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize;
145 
146  //!mapping of GDSII layers to internal layers
147  std::vector<int> m_mapping;
148 
149  //! the document to store/load the data found into
151 
152  double m_scale_in;
153 
154  double m_userunits_out;
155 
156  int m_objectFlags;
157 
158  wxUint16 m_lastElementLayer;
159 
160  int m_refMaxx;
161  int m_dx, m_dy;
162 
163  a2dLayers* m_layers;
164 
165  bool m_asCameleons;
166 };
167 
168 //!Output driver for KEY files
169 /*!
170  Every object in the document is written into the right KEY file structure
171  Info on the different record types that are read can be found in the KEY format manual
172 
173  \ingroup fileio keyfileio
174 */
175 class A2DCANVASDLLEXP a2dIOHandlerKeyOut : public a2dIOHandlerStrOut
176 {
177 
178 public:
179 
182 
183  bool LinkReferences();
184 
185  bool CanSave( const wxObject* obj = NULL );
186 
187  virtual bool Save( a2dDocumentOutputStream& stream, const wxObject* doc );
188 
189  virtual void InitializeSave( );
190 
191  virtual void ResetSave();
192 
193  void SetReadAsCameleon( bool asCameleons ) { m_asCameleons = asCameleons; }
194 
195  bool GetReadAsCameleon() { return m_asCameleons; }
196 
197  //! if set text will be converted to a vectorpath, and as polygons and polylines.
198  void SetSaveTextAsVpath( bool textAsPath ) { m_textAsPath = textAsPath; }
199 
200  //! /see SetSaveTextAsVpath()
201  bool GetSaveTextAsVpath() { return m_textAsPath; }
202 
203  //! set the format for double to be this
204  void SetFormat( const wxString& format ) { m_format = format; }
205 
206  //! if set, the current view its ShowObject will be saved top down.
207  void SetFromViewAsTop( bool fromViewAsTop ) { m_fromViewAsTop = fromViewAsTop; }
208 
209  //! /see SetFromViewAsTop()
210  bool GetFromViewAsTop() { return m_fromViewAsTop; }
211 
212 private:
213 
214  wxString m_format;
215 
216 protected:
217 
218  //! write a double number.
219  virtual void WriteDouble( double d )
220  {
221  wxString str;
222  str.Printf( m_format.c_str(), d );
223  WriteString( str );
224  }
225 
226  a2dIOHandlerKeyOut& operator<<( const wxChar* string );
227  a2dIOHandlerKeyOut& operator<<( const wxString& string );
228  a2dIOHandlerKeyOut& operator<<( char c );
229 #if wxUSE_UNICODE && wxWCHAR_T_IS_REAL_TYPE
230  a2dIOHandlerKeyOut& operator<<( wchar_t wc );
231 #endif // wxUSE_UNICODE
232  a2dIOHandlerKeyOut& operator<<( wxInt16 c );
233  a2dIOHandlerKeyOut& operator<<( wxInt32 c );
234  a2dIOHandlerKeyOut& operator<<( wxUint16 c );
235  a2dIOHandlerKeyOut& operator<<( wxUint32 c );
236  a2dIOHandlerKeyOut& operator<<( double f );
237  a2dIOHandlerKeyOut& operator<<( float f );
238 
239  const wxChar Endl();
240 
241  void WriteProperties( const a2dNamedPropertyList& props );
242 
243  void WriteFlags( int i );
244 
245  void Write( Strans* Strans );
246 
247  void SetFlags( a2dCanvasObject* Element );
248 
249  void WritePoint( double xi, double yi );
250 
251  void WriteSegment( const a2dAffineMatrix& lworld, a2dLineSegment* prevSegment, a2dLineSegment* Segment );
252 
253  void WriteVpath( const a2dAffineMatrix& lworld, const a2dVpath* path, int layer, int datatype, int pathtype, double width );
254 
255  void WritePoly( const a2dAffineMatrix& lworld , a2dVertexList* vlist, bool close );
256 
257  void WriteVertexArrayPolyline( const a2dAffineMatrix& lworld, a2dVertexArray* points, int layer, int datatype, int pathtype, double width, bool spline = false, bool close = true );
258 
259  void WriteVertexListPolyline( const a2dAffineMatrix& lworld, a2dVertexList* points, int layer, int datatype, int pathtype, double width, bool spline = false, bool close = true );
260 
261  void WriteVertexArrayPolygon( const a2dAffineMatrix& lworld, a2dVertexArray* points, int layer, int datatype, double width, bool spline = false, bool close = true );
262 
263  void WriteVertexListPolygon( const a2dAffineMatrix& lworld, a2dVertexList* points, int layer, int datatype, double width, bool spline = false, bool close = true );
264 
265  void SaveStructure( a2dCanvasObject* object, a2dCanvasObjectList* towrite );
266 
267  void Save( a2dCanvasObject* object, a2dCanvasObjectList* towrite );
268 
269  void DoSave( a2dPolylineL* obj, a2dCanvasObjectList* towrite );
270 
271  void DoSave( a2dPolygonL* obj, a2dCanvasObjectList* towrite );
272 
273  void DoSave( a2dSurface* surface, a2dCanvasObjectList* towrite );
274 
275  void DoSave( a2dText* obj, a2dCanvasObjectList* towrite );
276 
277  void DoSave( a2dTextGDS* obj, a2dCanvasObjectList* towrite );
278 
279  void DoSave( a2dCanvasObjectReference* obj, a2dCanvasObjectList* towrite );
280 
281  void DoSave( a2dCanvasObjectArrayReference* obj, a2dCanvasObjectList* towrite );
282 
283  void DoSave( a2dCameleonInst* obj, a2dCanvasObjectList* towrite );
284 
285  void DoSave( a2dCameleon* obj, a2dCanvasObjectList* towrite );
286 
287  void DoSave( a2dCircle* Circle, a2dCanvasObjectList* towrite );
288 
289  //!mapping of GDSII layers to internal layers
290  std::vector<int> m_mapping;
291 
292  //! the document to store/load the data found into
294 
295  double m_scale_out;
296 
297  double m_userunits_out;
298 
299  int m_objectFlags;
300 
301  unsigned int m_points_written;
302 
303  wxUint16 m_lastElementLayer;
304 
305  //! if true, vonvert text to a2dVpath
307 
308  bool m_fromViewAsTop;
309 
310  a2dLayers* m_layers;
311 
312  bool m_asCameleons;
313 };
314 
315 #endif //wxART2D_USE_KEYIO
316 
317 
318 #endif //_KEYIO_H
a2dCircle at x,y, and with radius
Definition: canprim.h:554
wxPoint2DDouble a2dPoint2D
this to define if coordinate numbers are integer or doubles
Definition: artglob.h:47
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
wxString m_keyword
keyword for record in KEY data
Definition: keyio.h:129
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...
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
wxOutputStream a2dDocumentOutputStream
output stream based wxStreams
Definition: gen.h:3458
Input driver for KEY format files.
Definition: keyio.h:43
using a file stream for input, stream the file into a a2dDocument or other object ...
Definition: gen.h:3632
list of a2dNamedProperty objects
Definition: gen.h:804
bool GetFromViewAsTop()
/see SetFromViewAsTop()
Definition: keyio.h:210
vertex array of line and arc segments.
Definition: polyver.h:494
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
void SetFromViewAsTop(bool fromViewAsTop)
if set, the current view its ShowObject will be saved top down.
Definition: keyio.h:207
a2dCanvasObjectArrayReference is an array of a reference to any a2dCanvasObject derived class...
Definition: recur.h:131
vertex list of line and arc segments.
Definition: polyver.h:600
a2dCanvasDocument * m_doc
the document to store/load the data found into
Definition: keyio.h:293
wxUint32 m_linenumber
last read line in DATA
Definition: keyio.h:137
a2dText is an abstract base class.
Definition: cantext.h:93
void SetSaveTextAsVpath(bool textAsPath)
if set text will be converted to a vectorpath, and as polygons and polylines.
Definition: keyio.h:198
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
void SetFormat(const wxString &format)
set the format for double to be this
Definition: keyio.h:204
Normal straight line segment in a2dVertexList and a2dVertexArray.
Definition: polyver.h:163
TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize
size of the last read record
Definition: keyio.h:144
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...
std::vector< int > m_mapping
mapping of GDSII layers to internal layers
Definition: keyio.h:290
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
wxInputStream a2dDocumentInputStream
input stream based wxStreams
Definition: gen.h:3456
virtual void WriteDouble(double d)
write a double number.
Definition: keyio.h:219
polygon defined with list of points for outer contour plus a list of hole polygons ...
Definition: polygon.h:502
virtual bool CanSave(const wxObject *obj=NULL)=0
Should return true if the handler can write this document to a stream.
wxString m_value
value for record in KEY data
Definition: keyio.h:131
a2dCanvasDocument * m_doc
the document to store/load the data found into
Definition: keyio.h:150
Output driver for KEY files.
Definition: keyio.h:175
bool m_textAsPath
if true, vonvert text to a2dVpath
Definition: keyio.h:306
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
int m_recordtype
type of the record in KEY data
Definition: keyio.h:134
bool m_back
last read record is stored
Definition: keyio.h:126
Vector Path.
Definition: polyver.h:1211
GdsII format input and output.
virtual bool LinkReferences(bool ignoreNonResolved=false)
link references to their destination
Definition: gen.cpp:4862
bool GetSaveTextAsVpath()
/see SetSaveTextAsVpath()
Definition: keyio.h:201
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
std::vector< int > m_mapping
mapping of GDSII layers to internal layers
Definition: keyio.h:147
keyio.h Source File -- Sun Oct 12 2014 17:04:21 -- Sun Oct 12 2014 -- 1.8.5 -- wxArt2D -- . -- Main Page Reference Documentation