00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _GDSIO_H
00021 #define _GDSIO_H
00022
00023 #include "a2dprivate.h"
00024
00025 #if wxART2D_USE_GDSIO
00026
00027 #include "wx/canvas/layerinf.h"
00028 #include "wx/canvas/cantext.h"
00029 #include <wx/wfstream.h>
00030
00031 class Strans;
00032 class a2dVpath;
00033
00034 enum TEXT_PATHTYPE {TEXT_PATH_END_SQAURE,TEXT_PATH_END_ROUND,TEXT_PATH_END_SQAURE_EXT};
00035
00036
00037
00038
00039 enum {FONT0,FONT1,FONT2,FONT3};
00040 enum {TOP, MIDDLE, BOTTOM};
00041 enum {LEFT, CENTER, RIGTH};
00042
00043
00044 typedef struct pres_bitflags
00045 {
00046
00047 #if wxBYTE_ORDER == wxBIG_ENDIAN
00048 unsigned reserved : 10;
00049 unsigned _font: 2;
00050 unsigned _vertical: 2;
00051 unsigned _horizontal: 2;
00052 #else
00053 unsigned _horizontal: 2;
00054 unsigned _vertical: 2;
00055 unsigned _font: 2;
00056 unsigned reserved : 10;
00057 #endif
00058 } pres_bitflags;
00059
00060
00061
00062
00063 #define DEFAULT_PRESENTATION_FONT FONT0
00064 #define DEFAULT_PRESENTATION_VERTICAL TOP
00065 #define DEFAULT_PRESENTATION_HORIZONTAL LEFT
00066 #define DEFAULT_FONT_HEIGHT 1
00067
00068
00069
00070
00071 typedef wxByte G_BYTE;
00072
00073
00074 typedef wxUint16 TWO_G_BYTE_UNSIGNED_INTEGER;
00075 typedef wxUint32 FOUR_G_BYTE_UNSIGNED_INTEGER;
00076 typedef wxInt16 TWO_G_BYTE_SIGNED_INTEGER;
00077 typedef wxInt32 FOUR_G_BYTE_SIGNED_INTEGER;
00078 typedef wxFloat32 FOUR_G_BYTE_REAL;
00079 typedef wxFloat64 EIGHT_G_BYTE_REAL;
00080
00081
00082
00083 #define GDS_ERROR -1
00084
00085
00086 #define GDS_DEFAULT_STRING_LENGTH 44 // default size of and GDS-II string
00087 const int GDS_HEADERSIZE = 4;
00088 #define GDSTYPE_TWO_G_BYTE_UNSIGNED_INTEGER 7 // record contains 2 byte unsigned integers
00089 #define GDSTYPE_FOUR_G_BYTE_UNSIGNED_INTEGER 8 // record contains 4 byte unsigned integers
00090
00091
00092 #define GDSTYPE_NO_DATA 0 // no data in record contained
00093 #define GDSTYPE_BIT_ARRAY 1 // record contains bitarray vars
00094 #define GDSTYPE_TWO_G_BYTE_SIGNED_INTEGER 2 // record contains 2 byte integers
00095 #define GDSTYPE_FOUR_G_BYTE_SIGNED_INTEGER 3 // record contains 4 byte integers
00096 #define GDSTYPE_FOUR_G_BYTE_REAL 4 // record contains 4 byte reals
00097 #define GDSTYPE_EIGHT_G_BYTE_REAL 5 // record contains 8 byte reals
00098 #define GDSTYPE_ASCII_STRING 6 // record contains GDSII ASCII-strings
00099
00100
00101
00102 #define GDS_HEADER 0
00103 #define GDS_BGNLIB 1
00104 #define GDS_LIBNAME 2
00105 #define GDS_UNITS 3
00106 #define GDS_ENDLIB 4
00107 #define GDS_BGNSTR 5
00108 #define GDS_STRNAME 6
00109 #define GDS_ENDSTR 7
00110 #define GDS_BOUNDARY 8
00111 #define GDS_PATH 9
00112 #define GDS_SREF 10
00113 #define GDS_AREF 11
00114 #define GDS_TEXT 12
00115 #define GDS_LAYER 13
00116 #define GDS_DATATYPE 14
00117 #define GDS_WIDTH 15
00118 #define GDS_XY 16
00119 #define GDS_ENDEL 17
00120 #define GDS_SNAME 18
00121 #define GDS_COLROW 19
00122 #define GDS_TEXTNODE 20
00123 #define GDS_NODE 21
00124 #define GDS_TEXTTYPE 22
00125 #define GDS_PRESENTATION 23
00126 #define GDS_SPACING 24
00127 #define GDS_STRING 25
00128 #define GDS_STRANS 26
00129 #define GDS_MAG 27
00130 #define GDS_ANGLE 28
00131 #define GDS_UINTEGER 29
00132 #define GDS_USTRING 30
00133 #define GDS_REFLIBS 31
00134 #define GDS_FONTS 32
00135 #define GDS_PATHTYPE 33
00136 #define GDS_GENERATIONS 34
00137 #define GDS_ATTRTABLE 35
00138 #define GDS_STYPTABLE 36
00139 #define GDS_STRTYPE 37
00140 #define GDS_ELFLAGS 38
00141 #define GDS_ELKEY 39
00142 #define GDS_LINKTYPE 40
00143 #define GDS_LINKKEYS 41
00144 #define GDS_NODETYPE 42
00145 #define GDS_PROPATTR 43
00146 #define GDS_PROPVALUE 44
00147 #define GDS_BOX 45
00148 #define GDS_BOXTYPE 46
00149 #define GDS_PLEX 47
00150 #define GDS_BGNEXTN 48
00151 #define GDS_ENDEXTN 49
00152 #define GDS_TAPENUM 50
00153 #define GDS_TAPECODE 51
00154 #define GDS_STRCLASS 52
00155 #define GDS_RESERVED 53
00156 #define GDS_FORMAT 54
00157 #define GDS_MASK 55
00158 #define GDS_ENDMASKS 56
00159
00160
00161 #define GDS_LIBDIRSIZE 57
00162 #define GDS_SRFNAME 58
00163 #define GDS_LIBSECUR 59
00164
00165 class Boundary;
00166 class a2dCanvasObject;
00167 class Path;
00168
00169
00170
00171
00172 #define DEFAULT_STRANS_ANGLE 0
00173 #define DEFAULT_STRANS_SCALE 1.0
00174 #define DEFAULT_STRANS_ABS_ANGLE false
00175 #define DEFAULT_STRANS_ABS_SCALE false
00176 #define DEFAULT_STRANS_REFLECTION false
00177
00178
00179 typedef struct gds_strans_bitflags
00180 {
00181 #if wxBYTE_ORDER == wxBIG_ENDIAN
00182 unsigned reflection: 1;
00183 unsigned reserved1 : 7;
00184 unsigned reserved2 : 5;
00185 unsigned abs_scale : 1;
00186 unsigned abs_angle : 1;
00187 unsigned reserved : 1;
00188 #else
00189 unsigned reserved : 1;
00190 unsigned abs_angle : 1;
00191 unsigned abs_scale : 1;
00192 unsigned reserved2 : 5;
00193 unsigned reserved1 : 7;
00194 unsigned reflection: 1;
00195 #endif
00196 } gds_strans_bitflags ;
00197
00198
00199 class A2DCANVASDLLEXP Strans
00200 {
00201 public:
00202
00203 Strans(double nw_angle=DEFAULT_STRANS_ANGLE,
00204 double nw_scale=DEFAULT_STRANS_SCALE,
00205 bool nw_abs_angle=DEFAULT_STRANS_ABS_ANGLE,
00206 bool nw_abs_scale=DEFAULT_STRANS_ABS_SCALE,
00207 bool nw_reflection=DEFAULT_STRANS_REFLECTION);
00208
00209 Strans& operator=(Strans& a_strans);
00210
00211
00212 void MakeStrans( const a2dAffineMatrix& matrix );
00213
00214 bool GetStrans();
00215 void SetAngle(double);
00216 void SetScale(double);
00217 void SetAbsAngle(bool);
00218 void SetAbsScale(bool);
00219 void SetReflection(bool);
00220 double GetAngle();
00221 double GetScale();
00222 bool GetAbsAngle();
00223 bool GetAbsScale();
00224 bool GetReflection();
00225
00226
00227 union {
00228 short int total;
00229 gds_strans_bitflags bits;
00230 } m_stransflags;
00231
00232 protected:
00233 double m_angle;
00234 double m_scale;
00235 bool m_strans_need;
00236 };
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247 class A2DCANVASDLLEXP a2dTextGDS: public a2dText
00248 {
00249
00250 public:
00251
00252
00253
00254
00255
00256 a2dTextGDS( a2dFontType fontType = a2dFONT_STROKED, const wxString &text = wxT("not specified"), double height = 1.0, short int presentation = 0 );
00257
00258
00259 a2dTextGDS( const a2dTextGDS& ori, CloneOptions options );
00260
00261 virtual a2dObject* Clone( CloneOptions options ) const;
00262
00263 void SetFont(char nw_font = DEFAULT_PRESENTATION_FONT);
00264 void SetVertical(char nw_vertical = DEFAULT_PRESENTATION_VERTICAL);
00265 void SetHorizontal(char nw_horizontal = DEFAULT_PRESENTATION_HORIZONTAL);
00266 short int GetFont();
00267 short int GetVertical();
00268 short int GetHorizontal();
00269
00270 void SetRotation(double rotation);
00271 double GetRotation();
00272
00273
00274
00275 void SetTextType( wxUint16 type ) { m_texttype = type; }
00276
00277
00278
00279 wxUint16 GetTextType() { return m_texttype; }
00280
00281 void SetPresentationFlags( short int total );
00282
00283 short int GetPresentationFlags( );
00284
00285 void SetPathtype( TEXT_PATHTYPE type ) { m_pathtype = type; }
00286
00287 TEXT_PATHTYPE GetPathtype() { return m_pathtype; }
00288
00289
00290 static void SetFontScaleFactor( double fontScaleFactor ) { m_fontScaleFactor = fontScaleFactor; }
00291
00292
00293 static double GetFontScaleFactor() { return m_fontScaleFactor; }
00294
00295 protected:
00296
00297
00298 wxUint16 m_texttype;
00299
00300 a2dFontType m_fontType;
00301
00302 TEXT_PATHTYPE m_pathtype;
00303
00304 float m_width;
00305
00306 bool m_monoSpaced;
00307
00308 static double m_fontScaleFactor;
00309
00310
00311 union
00312 {
00313 short int total;
00314 pres_bitflags bits;
00315 } m_presentationflags;
00316
00317 DECLARE_CLASS(a2dTextGDS)
00318 };
00319
00320 A2DCANVASDLLEXP extern const a2dError a2dError_GDSIIparse;
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 class A2DCANVASDLLEXP a2dIOHandlerGDSIn : public a2dIOHandlerStrIn
00335 {
00336
00337 public:
00338
00339 a2dIOHandlerGDSIn();
00340 ~a2dIOHandlerGDSIn();
00341
00342 bool LinkReferences();
00343
00344 virtual bool CanLoad( a2dDocumentInputStream& stream, const wxObject* obj = NULL, wxClassInfo* docClassInfo = NULL );
00345
00346 virtual bool Load( a2dDocumentInputStream& stream, wxObject* doc );
00347
00348 virtual void InitializeLoad( );
00349
00350 virtual void ResetLoad();
00351
00352
00353 void SetFontType( a2dFontType fontType ) { m_fontType = fontType; }
00354
00355 protected:
00356
00357 void SetDataTypeProperty( a2dCanvasObject* toobject, wxUint16 type );
00358
00359 unsigned int ReadUnsignedInt();
00360
00361 int ReadInt();
00362
00363 long ReadLong();
00364
00365 float ReadFloat();
00366
00367 double ReadDouble();
00368
00369
00370 void gds2double(unsigned char fb[]);
00371
00372 void ReadGdsII();
00373 bool ReadBgnlib();
00374 bool ReadProperty();
00375 bool ReadBoundary( a2dCanvasObject* parent );
00376
00377 bool ReadPath( a2dCanvasObject* parent );
00378 bool ReadText( a2dCanvasObject* parent );
00379 bool ReadStructureReference( a2dCanvasObject* parent );
00380 bool ReadArrayReference( a2dCanvasObject* parent );
00381 bool ReadNode( a2dCanvasObject* parent );
00382 bool ReadBox( a2dCanvasObject* parent );
00383 bool ReadElflags( a2dCanvasObject* object );
00384 bool ReadGdsHeader();
00385 bool ReadLayer( a2dCanvasObject* object );
00386 bool ReadLayer( int& layer );
00387 bool ReadLibraryName();
00388 bool ReadLibrarySettings();
00389 bool Read( a2dPoint2D& _Point );
00390 bool ReadStrans( Strans& _Strans);
00391 bool ReadStructure( a2dCanvasObject* parent );
00392 bool ReadElement( a2dCanvasObject* parent );
00393 bool ReadTextBody();
00394
00395 bool Read( a2dVertexList* segments );
00396
00397 bool Read(a2dPolygonL* polygon);
00398
00399
00400
00401 bool ReadHeader(int type);
00402
00403
00404 void SkipData();
00405
00406
00407 void ReadString(wxString& a_string);
00408
00409
00410 bool m_back;
00411
00412
00413 TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize;
00414
00415
00416 G_BYTE m_recordtype;
00417
00418
00419 G_BYTE m_datatype;
00420
00421
00422 int m_mapping[wxMAXLAYER];
00423
00424
00425 a2dCanvasDocument* m_doc;
00426
00427 double m_userunits_out;
00428
00429 int m_objectFlags;
00430
00431
00432 a2dFontType m_fontType;
00433
00434
00435 wxString m_strucname;
00436
00437 };
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447 class A2DCANVASDLLEXP a2dIOHandlerGDSOut : public a2dIOHandlerStrOut
00448 {
00449
00450 public:
00451
00452 a2dIOHandlerGDSOut();
00453 ~a2dIOHandlerGDSOut();
00454
00455 bool CanSave( const wxObject* obj = NULL );
00456
00457 virtual bool Save( a2dDocumentOutputStream& stream, const wxObject* doc );
00458
00459 virtual void InitializeSave( );
00460
00461 virtual void ResetSave();
00462
00463
00464 void SetSaveTextAsVpath( bool textAsPath ) { m_textAsPath = textAsPath; }
00465
00466
00467 bool GetSaveTextAsVpath() { return m_textAsPath; }
00468
00469
00470 void SetFromViewAsTop( bool fromViewAsTop ) { m_fromViewAsTop = fromViewAsTop; }
00471
00472
00473 bool GetFromViewAsTop() { return m_fromViewAsTop; }
00474
00475 protected:
00476
00477 unsigned int ReadUnsignedInt();
00478
00479 int ReadInt();
00480
00481 long ReadLong();
00482
00483 float ReadFloat();
00484
00485 double ReadDouble();
00486
00487 void WriteByte( G_BYTE ch );
00488
00489 void WriteUnsignedInt( TWO_G_BYTE_UNSIGNED_INTEGER i );
00490
00491 void WriteInt( TWO_G_BYTE_SIGNED_INTEGER i );
00492
00493 void WriteLong( FOUR_G_BYTE_SIGNED_INTEGER i );
00494
00495 void WriteFloat( FOUR_G_BYTE_REAL i );
00496
00497 void WriteDouble( EIGHT_G_BYTE_REAL i );
00498
00499 void Write(Strans* Strans);
00500
00501 void WriteHeader( TWO_G_BYTE_UNSIGNED_INTEGER nw_recordsize, G_BYTE nw_datatype, G_BYTE nw_recordtype);
00502
00503 void WriteString(const wxString& a_string);
00504
00505 void SetFlags( a2dCanvasObject* Element);
00506
00507 void WritePoint( double xi, double yi );
00508
00509 void WriteVpath( const a2dAffineMatrix& lworld, const a2dVpath* path, int layer, int datatype, int pathtype, double width );
00510
00511 void WritePath( const a2dAffineMatrix& lworld, a2dVertexArray* points, int layer, int datatype, int pathtype, double width );
00512
00513 void WritePath( const a2dAffineMatrix& lworld, a2dVertexList* points, int layer, int datatype, int pathtype, double width );
00514
00515 void WriteBoundary( const a2dAffineMatrix& lworld, a2dVertexArray* points, int layer, int datatype );
00516
00517 void WriteBoundary( const a2dAffineMatrix& lworld, a2dVertexList* points, int layer, int datatype, bool spline = false );
00518
00519 void SaveStructure( a2dCanvasObject* object, a2dCanvasObjectList* towrite );
00520
00521 void Save( a2dCanvasObject* object, a2dCanvasObjectList* towrite );
00522
00523 void DoSave( a2dPolylineL* obj, a2dCanvasObjectList* towrite );
00524
00525 void DoSave( a2dPolygonL* obj, a2dCanvasObjectList* towrite );
00526
00527 void DoSave( a2dVectorPath* obj, a2dCanvasObjectList* towrite );
00528
00529 void DoSave( a2dText* obj, a2dCanvasObjectList* towrite );
00530
00531 void DoSave( a2dTextGDS* obj, a2dCanvasObjectList* towrite );
00532
00533 void DoSave( a2dCanvasObjectReference* obj, a2dCanvasObjectList* towrite );
00534
00535 void DoSave( a2dCanvasObjectArrayReference* obj, a2dCanvasObjectList* towrite );
00536
00537
00538 void double2gds(unsigned char fb[]);
00539
00540
00541 bool m_back;
00542
00543
00544 TWO_G_BYTE_UNSIGNED_INTEGER m_recordsize;
00545
00546
00547 G_BYTE m_recordtype;
00548
00549
00550 G_BYTE m_datatype;
00551
00552
00553 int m_mapping[wxMAXLAYER];
00554
00555
00556 a2dCanvasDocument* m_doc;
00557
00558 double m_scale_out;
00559
00560 double m_userunits_out;
00561
00562 int m_objectFlags;
00563
00564
00565 bool m_textAsPath;
00566
00567 bool m_fromViewAsTop;
00568 };
00569
00570 #endif //wxART2D_USE_GDSIO
00571
00572 #endif //_GDSIO_H