1 /**********************************************************************
2  * $Id: mitab.h,v 1.121 2010-10-08 18:38:13 aboudreault Exp $
3  *
4  * Name:     mitab.h
5  * Project:  MapInfo TAB Read/Write library
6  * Language: C++
7  * Purpose:  Header file containing public definitions for the library.
8  * Author:   Daniel Morissette, dmorissette@dmsolutions.ca
9  *
10  **********************************************************************
11  * Copyright (c) 1999-2005, Daniel Morissette
12  * Copyright (c) 2014, Even Rouault <even.rouault at spatialys.com>
13  *
14  * Permission is hereby granted, free of charge, to any person obtaining a
15  * copy of this software and associated documentation files (the "Software"),
16  * to deal in the Software without restriction, including without limitation
17  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18  * and/or sell copies of the Software, and to permit persons to whom the
19  * Software is furnished to do so, subject to the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be included
22  * in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
27  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30  * DEALINGS IN THE SOFTWARE.
31  **********************************************************************
32  *
33  * $Log: mitab.h,v $
34  * Revision 1.121  2010-10-08 18:38:13  aboudreault
35  * Added attribute index support for the sql queries in mapinfo tab format (GDAL bug #3687)
36  *
37  * Revision 1.120  2010-01-07 20:39:11  aboudreault
38  * Added support to handle duplicate field names, Added validation to check if a field name start with a number (bug 2141)
39  *
40  * Revision 1.119  2009-07-28 21:35:29  aboudreault
41  * Added functions to get the file version (bug 1961)
42  *
43  * Revision 1.118  2009-03-10 13:50:02  aboudreault
44  * Fixed Overflow of FIDs in Seamless tables (bug 2015)
45  *
46  * Revision 1.117  2008-10-29 12:55:10  dmorissette
47  * Update version to 2.0.0-dev (2008-10) for GDAL 1.6.0 release
48  *
49  * Revision 1.116  2008/08/22 16:14:19  fwarmerdam
50  * export spatialref/coordsys transformers
51  *
52  * Revision 1.115  2008/07/21 14:09:41  aboudreault
53  * Add font text styles support (bold, italic, etc.) (bug 1922)
54  *
55  * Revision 1.114  2008/07/17 14:09:30  aboudreault
56  * Add text outline color support (halo background in MapInfo)
57  *
58  * Revision 1.113  2008/07/01 14:33:17  aboudreault
59  * * Fixed deprecated warnings generated by mitab.h by moving SetFontName to
60  *   mitab_feature.cpp.
61  *
62  * Revision 1.112  2008/03/05 20:35:39  dmorissette
63  * Replace MITAB 1.x SetFeature() with a CreateFeature() for V2.x (bug 1859)
64  *
65  * Revision 1.111  2008/02/29 21:27:41  dmorissette
66  * Update to v1.7.0-beta1
67  *
68  * Revision 1.110  2008/02/20 21:35:30  dmorissette
69  * Added support for V800 COLLECTION of large objects (bug 1496)
70  *
71  * Revision 1.109  2008/02/13 21:10:43  dmorissette
72  * Fixed error in TAB_GEOM_GET_VERSION() macro logic
73  *
74  * Revision 1.108  2008/02/05 22:21:59  dmorissette
75  * Added macro TAB_GEOM_GET_VERSION()
76  *
77  * Revision 1.107  2008/02/01 19:55:55  dmorissette
78  * Set version to 1.7.0-dev
79  *
80  * Revision 1.106  2008/02/01 19:36:31  dmorissette
81  * Initial support for V800 REGION and MULTIPLINE (bug 1496)
82  *
83  * Revision 1.105  2008/01/29 21:56:39  dmorissette
84  * Update dataset version properly for Date/Time/DateTime field types (#1754)
85  *
86  * Revision 1.104  2007/12/11 04:26:29  dmorissette
87  * Update for 1.6.4 release
88  *
89  * Revision 1.103  2007/10/12 15:47:48  dmorissette
90  * Updated for 1.6.3 release
91  *
92  * Revision 1.102  2007/09/18 18:13:42  dmorissette
93  * Updated for 1.6.3-beta2
94  *
95  * Revision 1.101  2007/09/14 20:03:08  dmorissette
96  * Removed stray ReadGeometryFromMAPFile() declaration
97  *
98  * Revision 1.100  2007/09/14 19:42:39  dmorissette
99  * Updated for 1.6.3-beta1
100  *
101  * Revision 1.99  2007/09/14 18:30:18  dmorissette
102  * Fixed the splitting of object blocks with the optimized spatial
103  * index mode that was producing files with misaligned bytes that
104  * confused MapInfo (bug 1732)
105  *
106  * Revision 1.98  2007/09/12 20:22:31  dmorissette
107  * Added TABFeature::CreateFromMapInfoType()
108  *
109  * ...
110  *
111  * Revision 1.1  1999/07/12 04:18:23  daniel
112  * Initial checkin
113  *
114  **********************************************************************/
115 
116 #ifndef _MITAB_H_INCLUDED_
117 #define _MITAB_H_INCLUDED_
118 
119 #include "mitab_priv.h"
120 #include "ogr_feature.h"
121 #include "ogr_featurestyle.h"
122 #include "ogrsf_frmts.h"
123 
124 /*---------------------------------------------------------------------
125  * Current version of the MITAB library... always useful!
126  *--------------------------------------------------------------------*/
127 #define MITAB_VERSION      "2.0.0-dev (2008-10)"
128 #define MITAB_VERSION_INT  2000000  /* version x.y.z -> xxxyyyzzz */
129 
130 #ifndef PI
131 #  define PI 3.14159265358979323846
132 #endif
133 
134 #ifndef ROUND_INT
135 #  define ROUND_INT(dX) ((int)((dX) < 0.0 ? (dX)-0.5 : (dX)+0.5 ))
136 #endif
137 
138 
139 #define MITAB_AREA(x1, y1, x2, y2)  ((double)((x2)-(x1))*(double)((y2)-(y1)))
140 
141 class TABFeature;
142 
143 /*---------------------------------------------------------------------
144  * Codes for the GetFileClass() in the IMapInfoFile-derived  classes
145  *--------------------------------------------------------------------*/
146 typedef enum
147 {
148     TABFC_IMapInfoFile = 0,
149     TABFC_TABFile,
150     TABFC_TABView,
151     TABFC_TABSeamless,
152     TABFC_MIFFile
153 } TABFileClass;
154 
155 
156 /*---------------------------------------------------------------------
157  *                      class IMapInfoFile
158  *
159  * Virtual base class for the TABFile and MIFFile classes.
160  *
161  * This is the definition of the public interface methods that should
162  * be available for any type of MapInfo dataset.
163  *--------------------------------------------------------------------*/
164 
165 class IMapInfoFile : public OGRLayer
166 {
167   private:
168 
169   protected:
170     GIntBig             m_nCurFeatureId;
171     TABFeature         *m_poCurFeature;
172     GBool               m_bBoundsSet;
173 
174     char                *m_pszCharset;
175 
176     TABFeature*         CreateTABFeature(OGRFeature *poFeature);
177 
178   public:
179     IMapInfoFile() ;
180     virtual ~IMapInfoFile();
181 
GetFileClass()182     virtual TABFileClass GetFileClass() {return TABFC_IMapInfoFile;}
183 
184     virtual int Open(const char *pszFname, const char* pszAccess,
185                      GBool bTestOpenNoError = FALSE );
186 
187     virtual int Open(const char *pszFname, TABAccess eAccess,
188                      GBool bTestOpenNoError = FALSE ) = 0;
189     virtual int Close() = 0;
190 
191     virtual int SetQuickSpatialIndexMode(CPL_UNUSED GBool bQuickSpatialIndexMode=TRUE) {return -1;}
192 
193     virtual const char *GetTableName() = 0;
194 
195     ///////////////
196     // Static method to detect file type, create an object to read that
197     // file and open it.
198     static IMapInfoFile *SmartOpen(const char *pszFname,
199                                    GBool bUpdate = FALSE,
200                                    GBool bTestOpenNoError = FALSE);
201 
202     ///////////////
203     //  OGR methods for read support
204     virtual void        ResetReading() = 0;
205     virtual GIntBig     GetFeatureCount (int bForce) = 0;
206     virtual OGRFeature *GetNextFeature();
207     virtual OGRFeature *GetFeature(GIntBig nFeatureId);
208     virtual OGRErr      ICreateFeature(OGRFeature *poFeature);
209     virtual int         TestCapability( const char * pszCap ) =0;
210     virtual int         GetExtent(OGREnvelope *psExtent, int bForce) =0;
211 
212     ///////////////
213     // Read access specific stuff
214     //
215     virtual GIntBig GetNextFeatureId(GIntBig nPrevId) = 0;
216     virtual TABFeature *GetFeatureRef(GIntBig nFeatureId) = 0;
217     virtual OGRFeatureDefn *GetLayerDefn() = 0;
218 
219     virtual TABFieldType GetNativeFieldType(int nFieldId) = 0;
220 
221     virtual int GetBounds(double &dXMin, double &dYMin,
222                           double &dXMax, double &dYMax,
223                           GBool bForce = TRUE ) = 0;
224 
225     virtual OGRSpatialReference *GetSpatialRef() = 0;
226 
227     virtual int GetFeatureCountByType(int &numPoints, int &numLines,
228                                       int &numRegions, int &numTexts,
229                                       GBool bForce = TRUE ) = 0;
230 
231     virtual GBool IsFieldIndexed(int nFieldId) = 0;
232     virtual GBool IsFieldUnique(int nFieldId) = 0;
233 
234     ///////////////
235     // Write access specific stuff
236     //
IsBoundsSet()237     GBool       IsBoundsSet()            {return m_bBoundsSet;}
238     virtual int SetBounds(double dXMin, double dYMin,
239                           double dXMax, double dYMax) = 0;
240     virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
241                             TABFieldType *paeMapInfoNativeFieldTypes = NULL)=0;
242     virtual int AddFieldNative(const char *pszName, TABFieldType eMapInfoType,
243                                int nWidth=0, int nPrecision=0,
244                                GBool bIndexed=FALSE, GBool bUnique=FALSE,
245                                int bApproxOK = TRUE) = 0;
246     virtual OGRErr CreateField( OGRFieldDefn *poField, int bApproxOK = TRUE );
247 
248     virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef) = 0;
249 
250     virtual OGRErr CreateFeature(TABFeature *poFeature) = 0;
251 
252     virtual int SetFieldIndexed(int nFieldId) = 0;
253 
254     virtual int SetCharset(const char* charset);
255 
256     ///////////////
257     // semi-private.
258     virtual int  GetProjInfo(TABProjInfo *poPI) = 0;
259     virtual int  SetProjInfo(TABProjInfo *poPI) = 0;
260     virtual int  SetMIFCoordSys(const char *pszMIFCoordSys) = 0;
261 
262     static int GetTABType( OGRFieldDefn *poField, TABFieldType* peTABType,
263                            int *pnWidth);
264 
265 #ifdef DEBUG
266     virtual void Dump(FILE *fpOut = NULL) = 0;
267 #endif
268 };
269 
270 /*---------------------------------------------------------------------
271  *                      class TABFile
272  *
273  * The main class for TAB datasets.  External programs should use this
274  * class to open a TAB dataset and read/write features from/to it.
275  *
276  *--------------------------------------------------------------------*/
277 class TABFile: public IMapInfoFile
278 {
279   private:
280     char        *m_pszFname;
281     TABAccess   m_eAccessMode;
282     char        **m_papszTABFile;
283     int         m_nVersion;
284     int         *m_panIndexNo;
285     TABTableType m_eTableType;  // NATIVE (.DAT) or DBF
286 
287     TABDATFile  *m_poDATFile;   // Attributes file
288     TABMAPFile  *m_poMAPFile;   // Object Geometry file
289     TABINDFile  *m_poINDFile;   // Attributes index file
290 
291     OGRFeatureDefn *m_poDefn;
292     OGRSpatialReference *m_poSpatialRef;
293     int         bUseSpatialTraversal;
294 
295     int         m_nLastFeatureId;
296 
297     GIntBig    *m_panMatchingFIDs;
298     int         m_iMatchingFID;
299 
300     int         m_bNeedTABRewrite;
301 
302     int         m_bLastOpWasRead;
303     int         m_bLastOpWasWrite;
304     ///////////////
305     // Private Read access specific stuff
306     //
307     int         ParseTABFileFirstPass(GBool bTestOpenNoError);
308     int         ParseTABFileFields();
309 
310      ///////////////
311     // Private Write access specific stuff
312     //
313     int         WriteTABFile();
314 
315   public:
316     TABFile();
317     virtual ~TABFile();
318 
GetFileClass()319     virtual TABFileClass GetFileClass() {return TABFC_TABFile;}
320 
321     virtual int Open(const char *pszFname, const char* pszAccess,
322                      GBool bTestOpenNoError = FALSE ) { return IMapInfoFile::Open(pszFname, pszAccess, bTestOpenNoError); }
323     virtual int Open(const char *pszFname, TABAccess eAccess,
324                      GBool bTestOpenNoError = FALSE );
325     virtual int Close();
326 
327     virtual int SetQuickSpatialIndexMode(GBool bQuickSpatialIndexMode=TRUE);
328 
GetTableName()329     virtual const char *GetTableName()
330                             {return m_poDefn?m_poDefn->GetName():"";};
331 
332     virtual void        ResetReading();
333     virtual int         TestCapability( const char * pszCap );
334     virtual GIntBig     GetFeatureCount (int bForce);
335     virtual int         GetExtent(OGREnvelope *psExtent, int bForce);
336 
337     /* Implement OGRLayer's SetFeature() for random write, only with TABFile */
338     virtual OGRErr      ISetFeature( OGRFeature * );
339     virtual OGRErr      DeleteFeature(GIntBig nFeatureId);
340 
341     virtual OGRErr      DeleteField( int iField );
342     virtual OGRErr      ReorderFields( int* panMap );
343     virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
344 
345     virtual OGRErr      SyncToDisk();
346 
347     ///////////////
348     // Read access specific stuff
349     //
350 
351     int         GetNextFeatureId_Spatial( int nPrevId );
352 
353     virtual GIntBig GetNextFeatureId(GIntBig nPrevId);
354     virtual TABFeature *GetFeatureRef(GIntBig nFeatureId);
355     virtual OGRFeatureDefn *GetLayerDefn();
356 
357     virtual TABFieldType GetNativeFieldType(int nFieldId);
358 
359     virtual int GetBounds(double &dXMin, double &dYMin,
360                           double &dXMax, double &dYMax,
361                           GBool bForce = TRUE );
362 
363     virtual OGRSpatialReference *GetSpatialRef();
364 
365     static OGRSpatialReference* GetSpatialRefFromTABProj(const TABProjInfo& sTABProj);
366     static int                  GetTABProjFromSpatialRef(const OGRSpatialReference* poSpatialRef,
367                                                          TABProjInfo& sTABProj, int& nParmCount);
368 
369     virtual int GetFeatureCountByType(int &numPoints, int &numLines,
370                                       int &numRegions, int &numTexts,
371                                       GBool bForce = TRUE);
372 
373     virtual GBool IsFieldIndexed(int nFieldId);
IsFieldUnique(int)374     virtual GBool IsFieldUnique(int /*nFieldId*/)   {return FALSE;};
375 
GetVersion()376     virtual int GetVersion() { return m_nVersion; };
377 
378     ///////////////
379     // Write access specific stuff
380     //
381     virtual int SetBounds(double dXMin, double dYMin,
382                           double dXMax, double dYMax);
383     virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
384                             TABFieldType *paeMapInfoNativeFieldTypes = NULL);
385     virtual int AddFieldNative(const char *pszName, TABFieldType eMapInfoType,
386                                int nWidth=0, int nPrecision=0,
387                                GBool bIndexed=FALSE, GBool bUnique=FALSE,
388                                int bApproxOK = TRUE);
389     virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef);
390 
391     virtual OGRErr CreateFeature(TABFeature *poFeature);
392 
393     virtual int SetFieldIndexed(int nFieldId);
394 
395     ///////////////
396     // semi-private.
GetProjInfo(TABProjInfo * poPI)397     virtual int  GetProjInfo(TABProjInfo *poPI)
398             { return m_poMAPFile->GetHeaderBlock()->GetProjInfo( poPI ); }
399     virtual int  SetProjInfo(TABProjInfo *poPI);
400     virtual int  SetMIFCoordSys(const char *pszMIFCoordSys);
401 
402     int         GetFieldIndexNumber(int nFieldId);
403     TABINDFile  *GetINDFileRef();
404 
GetMAPFileRef()405     TABMAPFile  *GetMAPFileRef() { return m_poMAPFile; }
406 
407     int         WriteFeature(TABFeature *poFeature);
408 
409 #ifdef DEBUG
410     virtual void Dump(FILE *fpOut = NULL);
411 #endif
412 };
413 
414 
415 /*---------------------------------------------------------------------
416  *                      class TABView
417  *
418  * TABView is used to handle special type of .TAB files that are
419  * composed of a number of .TAB datasets linked through some indexed
420  * fields.
421  *
422  * NOTE: The current implementation supports only TABViews composed
423  *       of 2 TABFiles linked through an indexed field of integer type.
424  *       It is unclear if any other type of views could exist anyways.
425  *--------------------------------------------------------------------*/
426 class TABView: public IMapInfoFile
427 {
428   private:
429     char        *m_pszFname;
430     TABAccess   m_eAccessMode;
431     char        **m_papszTABFile;
432     char        *m_pszVersion;
433 
434     char        **m_papszTABFnames;
435     TABFile     **m_papoTABFiles;
436     int         m_numTABFiles;
437     int         m_nMainTableIndex; // The main table is the one that also
438                                    // contains the geometries
439     char        **m_papszFieldNames;
440     char        **m_papszWhereClause;
441 
442     TABRelation *m_poRelation;
443     GBool       m_bRelFieldsCreated;
444 
445     ///////////////
446     // Private Read access specific stuff
447     //
448     int         ParseTABFile(const char *pszDatasetPath,
449                              GBool bTestOpenNoError = FALSE);
450 
451     int         OpenForRead(const char *pszFname,
452                             GBool bTestOpenNoError = FALSE );
453 
454     ///////////////
455     // Private Write access specific stuff
456     //
457     int         OpenForWrite(const char *pszFname );
458     int         WriteTABFile();
459 
460 
461   public:
462     TABView();
463     virtual ~TABView();
464 
GetFileClass()465     virtual TABFileClass GetFileClass() {return TABFC_TABView;}
466 
467     virtual int Open(const char *pszFname, const char* pszAccess,
468                      GBool bTestOpenNoError = FALSE ) { return IMapInfoFile::Open(pszFname, pszAccess, bTestOpenNoError); }
469     virtual int Open(const char *pszFname, TABAccess eAccess,
470                      GBool bTestOpenNoError = FALSE );
471     virtual int Close();
472 
473     virtual int SetQuickSpatialIndexMode(GBool bQuickSpatialIndexMode=TRUE);
474 
GetTableName()475     virtual const char *GetTableName()
476            {return m_poRelation?m_poRelation->GetFeatureDefn()->GetName():"";};
477 
478     virtual void        ResetReading();
479     virtual int         TestCapability( const char * pszCap );
480     virtual GIntBig     GetFeatureCount (int bForce);
481     virtual int         GetExtent(OGREnvelope *psExtent, int bForce);
482 
483     ///////////////
484     // Read access specific stuff
485     //
486 
487     virtual GIntBig GetNextFeatureId(GIntBig nPrevId);
488     virtual TABFeature *GetFeatureRef(GIntBig nFeatureId);
489     virtual OGRFeatureDefn *GetLayerDefn();
490 
491     virtual TABFieldType GetNativeFieldType(int nFieldId);
492 
493     virtual int GetBounds(double &dXMin, double &dYMin,
494                           double &dXMax, double &dYMax,
495                           GBool bForce = TRUE );
496 
497     virtual OGRSpatialReference *GetSpatialRef();
498 
499     virtual int GetFeatureCountByType(int &numPoints, int &numLines,
500                                       int &numRegions, int &numTexts,
501                                       GBool bForce = TRUE);
502 
503     virtual GBool IsFieldIndexed(int nFieldId);
504     virtual GBool IsFieldUnique(int nFieldId);
505 
506     ///////////////
507     // Write access specific stuff
508     //
509     virtual int SetBounds(double dXMin, double dYMin,
510                           double dXMax, double dYMax);
511     virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
512                            TABFieldType *paeMapInfoNativeFieldTypes=NULL);
513     virtual int AddFieldNative(const char *pszName,
514                                TABFieldType eMapInfoType,
515                                int nWidth=0, int nPrecision=0,
516                                GBool bIndexed=FALSE, GBool bUnique=FALSE,
517                                int bApproxOK = TRUE);
518     virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef);
519 
520     virtual OGRErr CreateFeature(TABFeature *poFeature);
521 
522     virtual int SetFieldIndexed(int nFieldId);
523 
524     ///////////////
525     // semi-private.
GetProjInfo(TABProjInfo * poPI)526     virtual int  GetProjInfo(TABProjInfo *poPI)
527             { return m_nMainTableIndex!=-1?
528                      m_papoTABFiles[m_nMainTableIndex]->GetProjInfo(poPI):-1; }
SetProjInfo(TABProjInfo * poPI)529     virtual int  SetProjInfo(TABProjInfo *poPI)
530             { return m_nMainTableIndex!=-1?
531                      m_papoTABFiles[m_nMainTableIndex]->SetProjInfo(poPI):-1; }
SetMIFCoordSys(const char *)532     virtual int  SetMIFCoordSys(const char * /*pszMIFCoordSys*/) {return -1;};
533 
534 #ifdef DEBUG
535     virtual void Dump(FILE *fpOut = NULL);
536 #endif
537 };
538 
539 
540 /*---------------------------------------------------------------------
541  *                      class TABSeamless
542  *
543  * TABSeamless is used to handle seamless .TAB files that are
544  * composed of a main .TAB file in which each feature is the MBR of
545  * a base table.
546  *
547  * TABSeamless are supported for read access only.
548  *--------------------------------------------------------------------*/
549 class TABSeamless: public IMapInfoFile
550 {
551   private:
552     char        *m_pszFname;
553     char        *m_pszPath;
554     TABAccess   m_eAccessMode;
555     OGRFeatureDefn *m_poFeatureDefnRef;
556 
557     TABFile     *m_poIndexTable;
558     int         m_nTableNameField;
559     int         m_nCurBaseTableId;
560     TABFile     *m_poCurBaseTable;
561     GBool       m_bEOF;
562 
563     ///////////////
564     // Private Read access specific stuff
565     //
566     int         OpenForRead(const char *pszFname,
567                             GBool bTestOpenNoError = FALSE );
568     int         OpenBaseTable(TABFeature *poIndexFeature,
569                               GBool bTestOpenNoError = FALSE);
570     int         OpenBaseTable(int nTableId, GBool bTestOpenNoError = FALSE);
571     int         OpenNextBaseTable(GBool bTestOpenNoError =FALSE);
572     GIntBig     EncodeFeatureId(int nTableId, int nBaseFeatureId);
573     int         ExtractBaseTableId(GIntBig nEncodedFeatureId);
574     int         ExtractBaseFeatureId(GIntBig nEncodedFeatureId);
575 
576   public:
577     TABSeamless();
578     virtual ~TABSeamless();
579 
GetFileClass()580     virtual TABFileClass GetFileClass() {return TABFC_TABSeamless;}
581 
582     virtual int Open(const char *pszFname, const char* pszAccess,
583                      GBool bTestOpenNoError = FALSE ) { return IMapInfoFile::Open(pszFname, pszAccess, bTestOpenNoError); }
584     virtual int Open(const char *pszFname, TABAccess eAccess,
585                      GBool bTestOpenNoError = FALSE );
586     virtual int Close();
587 
GetTableName()588     virtual const char *GetTableName()
589            {return m_poFeatureDefnRef?m_poFeatureDefnRef->GetName():"";};
590 
591     virtual void        SetSpatialFilter( OGRGeometry * );
592 
593     virtual void        ResetReading();
594     virtual int         TestCapability( const char * pszCap );
595     virtual GIntBig     GetFeatureCount (int bForce);
596     virtual int         GetExtent(OGREnvelope *psExtent, int bForce);
597 
598     ///////////////
599     // Read access specific stuff
600     //
601 
602     virtual GIntBig GetNextFeatureId(GIntBig nPrevId);
603     virtual TABFeature *GetFeatureRef(GIntBig nFeatureId);
604     virtual OGRFeatureDefn *GetLayerDefn();
605 
606     virtual TABFieldType GetNativeFieldType(int nFieldId);
607 
608     virtual int GetBounds(double &dXMin, double &dYMin,
609                           double &dXMax, double &dYMax,
610                           GBool bForce = TRUE );
611 
612     virtual OGRSpatialReference *GetSpatialRef();
613 
614     virtual int GetFeatureCountByType(int &numPoints, int &numLines,
615                                       int &numRegions, int &numTexts,
616                                       GBool bForce = TRUE);
617 
618     virtual GBool IsFieldIndexed(int nFieldId);
619     virtual GBool IsFieldUnique(int nFieldId);
620 
621     ///////////////
622     // Write access specific stuff
623     //
SetBounds(CPL_UNUSED double dXMin,CPL_UNUSED double dYMin,CPL_UNUSED double dXMax,CPL_UNUSED double dYMax)624     virtual int SetBounds(CPL_UNUSED double dXMin, CPL_UNUSED double dYMin,
625                           CPL_UNUSED double dXMax, CPL_UNUSED double dYMax)   {return -1;}
626     virtual int SetFeatureDefn(CPL_UNUSED OGRFeatureDefn *poFeatureDefn,
627                                CPL_UNUSED TABFieldType *paeMapInfoNativeFieldTypes=NULL)
628                                                         {return -1;}
629     virtual int AddFieldNative(CPL_UNUSED const char *pszName,
630                                CPL_UNUSED TABFieldType eMapInfoType,
631                                CPL_UNUSED int nWidth=0,
632                                CPL_UNUSED int nPrecision=0,
633                                CPL_UNUSED GBool bIndexed=FALSE,
634                                CPL_UNUSED GBool bUnique=FALSE,
635                                CPL_UNUSED int bApproxOK = TRUE) {return -1;}
636 
SetSpatialRef(CPL_UNUSED OGRSpatialReference * poSpatialRef)637     virtual int SetSpatialRef(CPL_UNUSED OGRSpatialReference *poSpatialRef) {return -1;}
638 
CreateFeature(CPL_UNUSED TABFeature * poFeature)639     virtual OGRErr CreateFeature(CPL_UNUSED TABFeature *poFeature)
640                                         {return OGRERR_UNSUPPORTED_OPERATION;}
641 
SetFieldIndexed(CPL_UNUSED int nFieldId)642     virtual int SetFieldIndexed(CPL_UNUSED int nFieldId) {return -1;}
643 
644     ///////////////
645     // semi-private.
GetProjInfo(TABProjInfo * poPI)646     virtual int  GetProjInfo(TABProjInfo *poPI)
647             { return m_poIndexTable?m_poIndexTable->GetProjInfo(poPI):-1; }
SetProjInfo(CPL_UNUSED TABProjInfo * poPI)648     virtual int SetProjInfo(CPL_UNUSED TABProjInfo *poPI)         { return -1; }
SetMIFCoordSys(const char *)649     virtual int SetMIFCoordSys(const char * /*pszMIFCoordSys*/) {return -1;};
650 
651 #ifdef DEBUG
652     virtual void Dump(FILE *fpOut = NULL);
653 #endif
654 };
655 
656 
657 /*---------------------------------------------------------------------
658  *                      class MIFFile
659  *
660  * The main class for (MID/MIF) datasets.  External programs should use this
661  * class to open a (MID/MIF) dataset and read/write features from/to it.
662  *
663  *--------------------------------------------------------------------*/
664 class MIFFile: public IMapInfoFile
665 {
666   private:
667     char        *m_pszFname;
668     TABAccess    m_eAccessMode;
669     int          m_nVersion;   /* Dataset version: 300, 450, 600, 900, etc. */
670     char        *m_pszDelimiter;
671     char        *m_pszUnique;
672     char        *m_pszIndex;
673     char        *m_pszCoordSys;
674 
675     TABFieldType *m_paeFieldType;
676     GBool       *m_pabFieldIndexed;
677     GBool       *m_pabFieldUnique;
678 
679     double       m_dfXMultiplier;
680     double       m_dfYMultiplier;
681     double       m_dfXDisplacement;
682     double       m_dfYDisplacement;
683 
684     /* these are the projection bounds, possibly much broader than extents */
685     double      m_dXMin;
686     double      m_dYMin;
687     double      m_dXMax;
688     double      m_dYMax;
689 
690     /* extents, as cached by MIFFile::PreParseFile() */
691     int         m_bExtentsSet;
692     OGREnvelope m_sExtents;
693 
694     int         m_nPoints;
695     int         m_nLines;
696     int         m_nRegions;
697     int         m_nTexts;
698 
699     int         m_nPreloadedId;  // preloaded mif line is for this feature id
700     MIDDATAFile  *m_poMIDFile;   // Mid file
701     MIDDATAFile  *m_poMIFFile;   // Mif File
702 
703     OGRFeatureDefn *m_poDefn;
704     OGRSpatialReference *m_poSpatialRef;
705 
706     int         m_nFeatureCount;
707     int         m_nWriteFeatureId;
708     int         m_nAttribut;
709 
710     ///////////////
711     // Private Read access specific stuff
712     //
713     int         ReadFeatureDefn();
714     int         ParseMIFHeader(int* pbIsEmpty);
715     void        PreParseFile();
716     int         AddFields(const char *pszLine);
717     int         GotoFeature(int nFeatureId);
718     int         NextFeature();
719 
720     ///////////////
721     // Private Write access specific stuff
722     //
723     GBool       m_bPreParsed;
724     GBool       m_bHeaderWrote;
725 
726     int         WriteMIFHeader();
727     void UpdateExtents(double dfX,double dfY);
728 
729   public:
730     MIFFile();
731     virtual ~MIFFile();
732 
GetFileClass()733     virtual TABFileClass GetFileClass() {return TABFC_MIFFile;}
734 
735     virtual int Open(const char *pszFname, const char* pszAccess,
736                      GBool bTestOpenNoError = FALSE ) { return IMapInfoFile::Open(pszFname, pszAccess, bTestOpenNoError); }
737     virtual int Open(const char *pszFname, TABAccess eAccess,
738                      GBool bTestOpenNoError = FALSE );
739     virtual int Close();
740 
GetTableName()741     virtual const char *GetTableName()
742                            {return m_poDefn?m_poDefn->GetName():"";};
743 
744     virtual int         TestCapability( const char * pszCap ) ;
745     virtual GIntBig     GetFeatureCount (int bForce);
746     virtual void        ResetReading();
747     virtual int         GetExtent(OGREnvelope *psExtent, int bForce);
748 
749     ///////////////
750     // Read access specific stuff
751     //
752 
753     virtual GIntBig GetNextFeatureId(GIntBig nPrevId);
754     virtual TABFeature *GetFeatureRef(GIntBig nFeatureId);
755     virtual OGRFeatureDefn *GetLayerDefn();
756 
757     virtual TABFieldType GetNativeFieldType(int nFieldId);
758 
759     virtual int GetBounds(double &dXMin, double &dYMin,
760                           double &dXMax, double &dYMax,
761                           GBool bForce = TRUE );
762 
763     virtual OGRSpatialReference *GetSpatialRef();
764 
765     virtual int GetFeatureCountByType(int &numPoints, int &numLines,
766                                       int &numRegions, int &numTexts,
767                                       GBool bForce = TRUE);
768 
769     virtual GBool IsFieldIndexed(int nFieldId);
770     virtual GBool IsFieldUnique(int nFieldId);
771 
GetVersion()772     virtual int GetVersion() { return m_nVersion; };
773 
774     ///////////////
775     // Write access specific stuff
776     //
777     virtual int SetBounds(double dXMin, double dYMin,
778                           double dXMax, double dYMax);
779     virtual int SetFeatureDefn(OGRFeatureDefn *poFeatureDefn,
780                             TABFieldType *paeMapInfoNativeFieldTypes = NULL);
781     virtual int AddFieldNative(const char *pszName, TABFieldType eMapInfoType,
782                                int nWidth=0, int nPrecision=0,
783                                GBool bIndexed=FALSE, GBool bUnique=FALSE,
784                                int bApproxOK = TRUE);
785     /* TODO */
786     virtual int SetSpatialRef(OGRSpatialReference *poSpatialRef);
787 
788     virtual OGRErr CreateFeature(TABFeature *poFeature);
789 
790     virtual int SetFieldIndexed(int nFieldId);
791 
792     ///////////////
793     // semi-private.
GetProjInfo(TABProjInfo *)794     virtual int  GetProjInfo(TABProjInfo * /*poPI*/){return -1;}
795     /*  { return m_poMAPFile->GetHeaderBlock()->GetProjInfo( poPI ); }*/
SetProjInfo(TABProjInfo *)796     virtual int  SetProjInfo(TABProjInfo * /*poPI*/){return -1;}
797     /*  { return m_poMAPFile->GetHeaderBlock()->SetProjInfo( poPI ); }*/
798     virtual int  SetMIFCoordSys(const char * pszMIFCoordSys);
799 
800 #ifdef DEBUG
801     virtual void Dump(FILE * /*fpOut*/ = NULL) {};
802 #endif
803 };
804 
805 /*---------------------------------------------------------------------
806  * Define some error codes specific to this lib.
807  *--------------------------------------------------------------------*/
808 #define TAB_WarningFeatureTypeNotSupported     501
809 #define TAB_WarningInvalidFieldName            502
810 #define TAB_WarningBoundsOverflow              503
811 
812 /*---------------------------------------------------------------------
813  * Codes for the feature classes
814  *--------------------------------------------------------------------*/
815 typedef enum
816 {
817     TABFCNoGeomFeature = 0,
818     TABFCPoint = 1,
819     TABFCFontPoint = 2,
820     TABFCCustomPoint = 3,
821     TABFCText = 4,
822     TABFCPolyline = 5,
823     TABFCArc = 6,
824     TABFCRegion = 7,
825     TABFCRectangle = 8,
826     TABFCEllipse = 9,
827     TABFCMultiPoint = 10,
828     TABFCCollection = 11,
829     TABFCDebugFeature
830 } TABFeatureClass;
831 
832 /*---------------------------------------------------------------------
833  * Definitions for text attributes
834  *--------------------------------------------------------------------*/
835 typedef enum TABTextJust_t
836 {
837     TABTJLeft = 0,      // Default: Left Justification
838     TABTJCenter,
839     TABTJRight
840 } TABTextJust;
841 
842 typedef enum TABTextSpacing_t
843 {
844     TABTSSingle = 0,    // Default: Single spacing
845     TABTS1_5,           // 1.5
846     TABTSDouble
847 } TABTextSpacing;
848 
849 typedef enum TABTextLineType_t
850 {
851     TABTLNoLine = 0,    // Default: No line
852     TABTLSimple,
853     TABTLArrow
854 } TABTextLineType;
855 
856 typedef enum TABFontStyle_t     // Can be OR'ed
857 {                               // except box and halo are mutually exclusive
858     TABFSNone       = 0,
859     TABFSBold       = 0x0001,
860     TABFSItalic     = 0x0002,
861     TABFSUnderline  = 0x0004,
862     TABFSStrikeout  = 0x0008,
863     TABFSOutline    = 0x0010,
864     TABFSShadow     = 0x0020,
865     TABFSInverse    = 0x0040,
866     TABFSBlink      = 0x0080,
867     TABFSBox        = 0x0100,   // See note about box vs halo below.
868     TABFSHalo       = 0x0200,   // MIF uses 256, see MIF docs, App.A
869     TABFSAllCaps    = 0x0400,   // MIF uses 512
870     TABFSExpanded   = 0x0800    // MIF uses 1024
871 } TABFontStyle;
872 
873 /* TABFontStyle enum notes:
874  *
875  * The enumeration values above correspond to the values found in a .MAP
876  * file. However, they differ a little from what is found in a MIF file:
877  * Values 0x01 to 0x80 are the same in .MIF and .MAP files.
878  * Values 0x200 to 0x800 in .MAP are 0x100 to 0x400 in .MIF
879  *
880  * What about TABFSBox (0x100) ?
881  * TABFSBox is stored just like the other styles in .MAP files but it is not
882  * explicitly stored in a MIF file.
883  * If a .MIF FONT() clause contains the optional BG color, then this implies
884  * that either Halo or Box was set.  Thus if TABFSHalo (value 256 in MIF)
885  * is not set in the style, then this implies that TABFSBox should be set.
886  */
887 
888 typedef enum TABCustSymbStyle_t // Can be OR'ed
889 {
890     TABCSNone       = 0,        // Transparent BG, use default colors
891     TABCSBGOpaque   = 0x01,     // White pixels are opaque
892     TABCSApplyColor = 0x02      // non-white pixels drawn using symbol color
893 } TABCustSymbStyle;
894 
895 /*=====================================================================
896   Base classes to be used to add supported drawing tools to each feature type
897  =====================================================================*/
898 
899 class ITABFeaturePen
900 {
901   protected:
902     int         m_nPenDefIndex;
903     TABPenDef   m_sPenDef;
904   public:
905     ITABFeaturePen();
~ITABFeaturePen()906     ~ITABFeaturePen() {};
GetPenDefIndex()907     int         GetPenDefIndex() {return m_nPenDefIndex;};
GetPenDefRef()908     TABPenDef  *GetPenDefRef() {return &m_sPenDef;};
909 
910     GByte       GetPenWidthPixel();
911     double      GetPenWidthPoint();
912     int         GetPenWidthMIF();
GetPenPattern()913     GByte       GetPenPattern() {return m_sPenDef.nLinePattern;};
GetPenColor()914     GInt32      GetPenColor()   {return m_sPenDef.rgbColor;};
915 
916     void        SetPenWidthPixel(GByte val);
917     void        SetPenWidthPoint(double val);
918     void        SetPenWidthMIF(int val);
919 
SetPenPattern(GByte val)920     void        SetPenPattern(GByte val) {m_sPenDef.nLinePattern=val;};
SetPenColor(GInt32 clr)921     void        SetPenColor(GInt32 clr)  {m_sPenDef.rgbColor = clr;};
922 
923     const char *GetPenStyleString();
924     void        SetPenFromStyleString(const char *pszStyleString);
925 
926     void        DumpPenDef(FILE *fpOut = NULL);
927 };
928 
929 class ITABFeatureBrush
930 {
931   protected:
932     int         m_nBrushDefIndex;
933     TABBrushDef m_sBrushDef;
934   public:
935     ITABFeatureBrush();
~ITABFeatureBrush()936     ~ITABFeatureBrush() {};
GetBrushDefIndex()937     int         GetBrushDefIndex() {return m_nBrushDefIndex;};
GetBrushDefRef()938     TABBrushDef *GetBrushDefRef() {return &m_sBrushDef;};
939 
GetBrushFGColor()940     GInt32      GetBrushFGColor()     {return m_sBrushDef.rgbFGColor;};
GetBrushBGColor()941     GInt32      GetBrushBGColor()     {return m_sBrushDef.rgbBGColor;};
GetBrushPattern()942     GByte       GetBrushPattern()     {return m_sBrushDef.nFillPattern;};
GetBrushTransparent()943     GByte       GetBrushTransparent() {return m_sBrushDef.bTransparentFill;};
944 
SetBrushFGColor(GInt32 clr)945     void        SetBrushFGColor(GInt32 clr)  { m_sBrushDef.rgbFGColor = clr;};
SetBrushBGColor(GInt32 clr)946     void        SetBrushBGColor(GInt32 clr)  { m_sBrushDef.rgbBGColor = clr;};
SetBrushPattern(GByte val)947     void        SetBrushPattern(GByte val)   { m_sBrushDef.nFillPattern=val;};
SetBrushTransparent(GByte val)948     void        SetBrushTransparent(GByte val)
949                                           {m_sBrushDef.bTransparentFill=val;};
950 
951     const char *GetBrushStyleString();
952     void        SetBrushFromStyleString(const char *pszStyleString);
953 
954     void        DumpBrushDef(FILE *fpOut = NULL);
955 };
956 
957 class ITABFeatureFont
958 {
959   protected:
960     int         m_nFontDefIndex;
961     TABFontDef  m_sFontDef;
962   public:
963     ITABFeatureFont();
~ITABFeatureFont()964     ~ITABFeatureFont() {};
GetFontDefIndex()965     int         GetFontDefIndex() {return m_nFontDefIndex;};
GetFontDefRef()966     TABFontDef *GetFontDefRef() {return &m_sFontDef;};
967 
GetFontNameRef()968     const char *GetFontNameRef() {return m_sFontDef.szFontName;};
969 
970     void        SetFontName(const char *pszName);
971 
972     void        DumpFontDef(FILE *fpOut = NULL);
973 };
974 
975 class ITABFeatureSymbol
976 {
977   protected:
978     int         m_nSymbolDefIndex;
979     TABSymbolDef m_sSymbolDef;
980   public:
981     ITABFeatureSymbol();
~ITABFeatureSymbol()982     ~ITABFeatureSymbol() {};
GetSymbolDefIndex()983     int         GetSymbolDefIndex() {return m_nSymbolDefIndex;};
GetSymbolDefRef()984     TABSymbolDef *GetSymbolDefRef() {return &m_sSymbolDef;};
985 
GetSymbolNo()986     GInt16      GetSymbolNo()    {return m_sSymbolDef.nSymbolNo;};
GetSymbolSize()987     GInt16      GetSymbolSize()  {return m_sSymbolDef.nPointSize;};
GetSymbolColor()988     GInt32      GetSymbolColor() {return m_sSymbolDef.rgbColor;};
989 
SetSymbolNo(GInt16 val)990     void        SetSymbolNo(GInt16 val)     { m_sSymbolDef.nSymbolNo = val;};
SetSymbolSize(GInt16 val)991     void        SetSymbolSize(GInt16 val)   { m_sSymbolDef.nPointSize = val;};
SetSymbolColor(GInt32 clr)992     void        SetSymbolColor(GInt32 clr)  { m_sSymbolDef.rgbColor = clr;};
993 
994     const char *GetSymbolStyleString(double dfAngle = 0.0);
995     void        SetSymbolFromStyleString(const char *pszStyleString);
996 
997     void        DumpSymbolDef(FILE *fpOut = NULL);
998 };
999 
1000 
1001 /*=====================================================================
1002                         Feature Classes
1003  =====================================================================*/
1004 
1005 /*---------------------------------------------------------------------
1006  *                      class TABFeature
1007  *
1008  * Extend the OGRFeature to support MapInfo specific extensions related
1009  * to geometry types, representation strings, etc.
1010  *
1011  * TABFeature will be used as a base class for all the feature classes.
1012  *
1013  * This class will also be used to instanciate objects with no Geometry
1014  * (i.e. type TAB_GEOM_NONE) which is a valid case in MapInfo.
1015  *
1016  * The logic to read/write the object from/to the .DAT and .MAP files is also
1017  * implemented as part of this class and derived classes.
1018  *--------------------------------------------------------------------*/
1019 class TABFeature: public OGRFeature
1020 {
1021   protected:
1022     TABGeomType m_nMapInfoType;
1023 
1024     double      m_dXMin;
1025     double      m_dYMin;
1026     double      m_dXMax;
1027     double      m_dYMax;
1028 
1029     GBool       m_bDeletedFlag;
1030 
1031     void        CopyTABFeatureBase(TABFeature *poDestFeature);
1032 
1033     // Compr. Origin is set for TAB files by ValidateCoordType()
1034     GInt32      m_nXMin;
1035     GInt32      m_nYMin;
1036     GInt32      m_nXMax;
1037     GInt32      m_nYMax;
1038     GInt32      m_nComprOrgX;
1039     GInt32      m_nComprOrgY;
1040 
1041     virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1042 
1043   public:
1044              TABFeature(OGRFeatureDefn *poDefnIn );
1045     virtual ~TABFeature();
1046 
1047     static  TABFeature     *CreateFromMapInfoType(int nMapInfoType,
1048                                                   OGRFeatureDefn *poDefn);
1049 
1050     virtual TABFeature     *CloneTABFeature(OGRFeatureDefn *pNewDefn = NULL);
GetFeatureClass()1051     virtual TABFeatureClass GetFeatureClass() { return TABFCNoGeomFeature; };
GetMapInfoType()1052     virtual TABGeomType     GetMapInfoType()  { return m_nMapInfoType; };
1053     virtual TABGeomType     ValidateMapInfoType(CPL_UNUSED TABMAPFile *poMapFile = NULL)
1054                                                 {m_nMapInfoType=TAB_GEOM_NONE;
1055                                                  return m_nMapInfoType;};
IsRecordDeleted()1056     GBool       IsRecordDeleted() { return m_bDeletedFlag; };
SetRecordDeleted(GBool bDeleted)1057     void        SetRecordDeleted(GBool bDeleted) { m_bDeletedFlag=bDeleted; };
1058 
1059     /*-----------------------------------------------------------------
1060      * TAB Support
1061      *----------------------------------------------------------------*/
1062 
1063     virtual int ReadRecordFromDATFile(TABDATFile *poDATFile);
1064     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1065                                         GBool bCoordDataOnly=FALSE,
1066                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1067 
1068     virtual int WriteRecordToDATFile(TABDATFile *poDATFile,
1069                                      TABINDFile *poINDFile, int *panIndexNo);
1070     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1071                                        GBool bCoordDataOnly=FALSE,
1072                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1073     GBool       ValidateCoordType(TABMAPFile * poMapFile);
1074     void        ForceCoordTypeAndOrigin(TABGeomType nMapInfoType, GBool bCompr,
1075                                         GInt32 nComprOrgX, GInt32 nComprOrgY,
1076                                         GInt32 nXMin, GInt32 nYMin,
1077                                         GInt32 nXMax, GInt32 nYMax);
1078 
1079     /*-----------------------------------------------------------------
1080      * Mid/Mif Support
1081      *----------------------------------------------------------------*/
1082 
1083     virtual int ReadRecordFromMIDFile(MIDDATAFile *fp);
1084     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1085 
1086     virtual int WriteRecordToMIDFile(MIDDATAFile *fp);
1087     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1088 
1089     void ReadMIFParameters(MIDDATAFile *fp);
1090     void WriteMIFParameters(MIDDATAFile *fp);
1091 
1092     /*-----------------------------------------------------------------
1093      *----------------------------------------------------------------*/
1094 
1095     void        SetMBR(double dXMin, double dYMin,
1096                        double dXMax, double dYMax);
1097     void        GetMBR(double &dXMin, double &dYMin,
1098                        double &dXMax, double &dYMax);
1099     void        SetIntMBR(GInt32 nXMin, GInt32 nYMin,
1100                           GInt32 nXMax, GInt32 nYMax);
1101     void        GetIntMBR(GInt32 &nXMin, GInt32 &nYMin,
1102                           GInt32 &nXMax, GInt32 &nYMax);
1103 
1104     virtual void DumpMID(FILE *fpOut = NULL);
1105     virtual void DumpMIF(FILE *fpOut = NULL);
1106 
1107 };
1108 
1109 
1110 /*---------------------------------------------------------------------
1111  *                      class TABPoint
1112  *
1113  * Feature class to handle old style MapInfo point symbols:
1114  *
1115  *     TAB_GEOM_SYMBOL_C        0x01
1116  *     TAB_GEOM_SYMBOL          0x02
1117  *
1118  * Feature geometry will be a OGRPoint
1119  *
1120  * The symbol number is in the range [31..67], with 31=None and corresponds
1121  * to one of the 35 predefined "Old MapInfo Symbols"
1122  *
1123  * NOTE: This class is also used as a base class for the other point
1124  * symbol types TABFontPoint and TABCustomPoint.
1125  *--------------------------------------------------------------------*/
1126 class TABPoint: public TABFeature,
1127                 public ITABFeatureSymbol
1128 {
1129   public:
1130              TABPoint(OGRFeatureDefn *poDefnIn);
1131     virtual ~TABPoint();
1132 
GetFeatureClass()1133     virtual TABFeatureClass GetFeatureClass() { return TABFCPoint; };
1134     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1135 
1136     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1137 
1138     double      GetX();
1139     double      GetY();
1140 
1141     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1142                                         GBool bCoordDataOnly=FALSE,
1143                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1144     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1145                                        GBool bCoordDataOnly=FALSE,
1146                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1147 
1148     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1149     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1150 
1151     virtual const char *GetStyleString();
1152 
1153     virtual void DumpMIF(FILE *fpOut = NULL);
1154 };
1155 
1156 
1157 /*---------------------------------------------------------------------
1158  *                      class TABFontPoint
1159  *
1160  * Feature class to handle MapInfo Font Point Symbol types:
1161  *
1162  *     TAB_GEOM_FONTSYMBOL_C    0x28
1163  *     TAB_GEOM_FONTSYMBOL      0x29
1164  *
1165  * Feature geometry will be a OGRPoint
1166  *
1167  * The symbol number refers to a character code in the specified Windows
1168  * Font (e.g. "Windings").
1169  *--------------------------------------------------------------------*/
1170 class TABFontPoint: public TABPoint,
1171                     public ITABFeatureFont
1172 {
1173   protected:
1174     double      m_dAngle;
1175     GInt16      m_nFontStyle;           // Bold/shadow/halo/etc.
1176 
1177   public:
1178              TABFontPoint(OGRFeatureDefn *poDefnIn);
1179     virtual ~TABFontPoint();
1180 
GetFeatureClass()1181     virtual TABFeatureClass GetFeatureClass() { return TABFCFontPoint; };
1182 
1183     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1184 
1185     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1186                                         GBool bCoordDataOnly=FALSE,
1187                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1188     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1189                                        GBool bCoordDataOnly=FALSE,
1190                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1191 
1192     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1193     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1194 
1195     virtual const char *GetStyleString();
1196 
1197     GBool       QueryFontStyle(TABFontStyle eStyleToQuery);
1198     void        ToggleFontStyle(TABFontStyle eStyleToToggle, GBool bStatus);
1199 
1200     int         GetFontStyleMIFValue();
1201     void        SetFontStyleMIFValue(int nStyle);
GetFontStyleTABValue()1202     int         GetFontStyleTABValue()           {return m_nFontStyle;};
SetFontStyleTABValue(int nStyle)1203     void        SetFontStyleTABValue(int nStyle){m_nFontStyle=(GInt16)nStyle;};
1204 
1205     // GetSymbolAngle(): Return angle in degrees counterclockwise
GetSymbolAngle()1206     double      GetSymbolAngle()        {return m_dAngle;};
1207     void        SetSymbolAngle(double dAngle);
1208 };
1209 
1210 
1211 /*---------------------------------------------------------------------
1212  *                      class TABCustomPoint
1213  *
1214  * Feature class to handle MapInfo Custom Point Symbol (Bitmap) types:
1215  *
1216  *     TAB_GEOM_CUSTOMSYMBOL_C  0x2b
1217  *     TAB_GEOM_CUSTOMSYMBOL    0x2c
1218  *
1219  * Feature geometry will be a OGRPoint
1220  *
1221  * The symbol name is the name of a BMP file stored in the "CustSymb"
1222  * directory (e.g. "arrow.BMP").  The symbol number has no meaning for
1223  * this symbol type.
1224  *--------------------------------------------------------------------*/
1225 class TABCustomPoint: public TABPoint,
1226                       public ITABFeatureFont
1227 {
1228   protected:
1229     GByte       m_nCustomStyle;         // Show BG/Apply Color
1230 
1231   public:
1232     GByte       m_nUnknown_;
1233 
1234   public:
1235              TABCustomPoint(OGRFeatureDefn *poDefnIn);
1236     virtual ~TABCustomPoint();
1237 
GetFeatureClass()1238     virtual TABFeatureClass GetFeatureClass() { return TABFCCustomPoint; };
1239 
1240     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1241 
1242     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1243                                         GBool bCoordDataOnly=FALSE,
1244                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1245     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1246                                        GBool bCoordDataOnly=FALSE,
1247                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1248 
1249     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1250     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1251 
1252     virtual const char *GetStyleString();
1253 
GetSymbolNameRef()1254     const char *GetSymbolNameRef()      { return GetFontNameRef(); };
SetSymbolName(const char * pszName)1255     void        SetSymbolName(const char *pszName) {SetFontName(pszName);};
1256 
GetCustomSymbolStyle()1257     GByte       GetCustomSymbolStyle()              {return m_nCustomStyle;}
SetCustomSymbolStyle(GByte nStyle)1258     void        SetCustomSymbolStyle(GByte nStyle)  {m_nCustomStyle = nStyle;}
1259 };
1260 
1261 
1262 /*---------------------------------------------------------------------
1263  *                      class TABPolyline
1264  *
1265  * Feature class to handle the various MapInfo line types:
1266  *
1267  *     TAB_GEOM_LINE_C         0x04
1268  *     TAB_GEOM_LINE           0x05
1269  *     TAB_GEOM_PLINE_C        0x07
1270  *     TAB_GEOM_PLINE          0x08
1271  *     TAB_GEOM_MULTIPLINE_C   0x25
1272  *     TAB_GEOM_MULTIPLINE     0x26
1273  *     TAB_GEOM_V450_MULTIPLINE_C 0x31
1274  *     TAB_GEOM_V450_MULTIPLINE   0x32
1275  *
1276  * Feature geometry can be either a OGRLineString or a OGRMultiLineString
1277  *--------------------------------------------------------------------*/
1278 class TABPolyline: public TABFeature,
1279                    public ITABFeaturePen
1280 {
1281   private:
1282     GBool       m_bCenterIsSet;
1283     double      m_dCenterX, m_dCenterY;
1284     GBool       m_bWriteTwoPointLineAsPolyline;
1285 
1286   public:
1287              TABPolyline(OGRFeatureDefn *poDefnIn);
1288     virtual ~TABPolyline();
1289 
GetFeatureClass()1290     virtual TABFeatureClass GetFeatureClass() { return TABFCPolyline; };
1291     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1292 
1293     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1294 
1295     /* 2 methods to simplify access to rings in a multiple polyline
1296      */
1297     int                 GetNumParts();
1298     OGRLineString      *GetPartRef(int nPartIndex);
1299 
1300     GBool       TwoPointLineAsPolyline();
1301     void        TwoPointLineAsPolyline(GBool bTwoPointLineAsPolyline);
1302 
1303     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1304                                         GBool bCoordDataOnly=FALSE,
1305                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1306     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1307                                        GBool bCoordDataOnly=FALSE,
1308                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1309 
1310     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1311     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1312 
1313     virtual const char *GetStyleString();
1314 
1315     virtual void DumpMIF(FILE *fpOut = NULL);
1316 
1317     int         GetCenter(double &dX, double &dY);
1318     void        SetCenter(double dX, double dY);
1319 
1320     // MapInfo-specific attributes... made available through public vars
1321     // for now.
1322     GBool       m_bSmooth;
1323 
1324 };
1325 
1326 /*---------------------------------------------------------------------
1327  *                      class TABRegion
1328  *
1329  * Feature class to handle the MapInfo region types:
1330  *
1331  *     TAB_GEOM_REGION_C         0x0d
1332  *     TAB_GEOM_REGION           0x0e
1333  *     TAB_GEOM_V450_REGION_C    0x2e
1334  *     TAB_GEOM_V450_REGION      0x2f
1335  *
1336  * Feature geometry will be returned as OGRPolygon (with a single ring)
1337  * or OGRMultiPolygon (for multiple rings).
1338  *
1339  * REGIONs with multiple rings are returned as OGRMultiPolygon instead of
1340  * as OGRPolygons since OGRPolygons require that the first ring be the
1341  * outer ring, and the other all be inner rings, but this is not guaranteed
1342  * inside MapInfo files.  However, when writing features, OGRPolygons with
1343  * multiple rings will be accepted without problem.
1344  *--------------------------------------------------------------------*/
1345 class TABRegion: public TABFeature,
1346                  public ITABFeaturePen,
1347                  public ITABFeatureBrush
1348 {
1349     GBool       m_bSmooth;
1350   private:
1351     GBool       m_bCenterIsSet;
1352     double      m_dCenterX, m_dCenterY;
1353 
1354     int     ComputeNumRings(TABMAPCoordSecHdr **ppasSecHdrs,
1355                             TABMAPFile *poMAPFile);
1356     int     AppendSecHdrs(OGRPolygon *poPolygon,
1357                           TABMAPCoordSecHdr * &pasSecHdrs,
1358                           TABMAPFile *poMAPFile,
1359                           int &iLastRing);
1360 
1361   public:
1362              TABRegion(OGRFeatureDefn *poDefnIn);
1363     virtual ~TABRegion();
1364 
GetFeatureClass()1365     virtual TABFeatureClass GetFeatureClass() { return TABFCRegion; };
1366     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1367 
1368     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1369 
1370     /* 2 methods to make the REGION's geometry look like a single collection
1371      * of OGRLinearRings
1372      */
1373     int                 GetNumRings();
1374     OGRLinearRing      *GetRingRef(int nRequestedRingIndex);
1375     GBool               IsInteriorRing(int nRequestedRingIndex);
1376 
1377     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1378                                         GBool bCoordDataOnly=FALSE,
1379                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1380     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1381                                        GBool bCoordDataOnly=FALSE,
1382                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1383 
1384     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1385     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1386 
1387     virtual const char *GetStyleString();
1388 
1389     virtual void DumpMIF(FILE *fpOut = NULL);
1390 
1391     int         GetCenter(double &dX, double &dY);
1392     void        SetCenter(double dX, double dY);
1393 };
1394 
1395 
1396 /*---------------------------------------------------------------------
1397  *                      class TABRectangle
1398  *
1399  * Feature class to handle the MapInfo rectangle types:
1400  *
1401  *     TAB_GEOM_RECT_C         0x13
1402  *     TAB_GEOM_RECT           0x14
1403  *     TAB_GEOM_ROUNDRECT_C    0x16
1404  *     TAB_GEOM_ROUNDRECT      0x17
1405  *
1406  * A rectangle is defined by the coords of its 2 opposite corners (the MBR)
1407  * Its corners can optionaly be rounded, in which case a X and Y rounding
1408  * radius will be defined.
1409  *
1410  * Feature geometry will be OGRPolygon
1411  *--------------------------------------------------------------------*/
1412 class TABRectangle: public TABFeature,
1413                     public ITABFeaturePen,
1414                     public ITABFeatureBrush
1415 {
1416   private:
1417     virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1418 
1419   public:
1420              TABRectangle(OGRFeatureDefn *poDefnIn);
1421     virtual ~TABRectangle();
1422 
GetFeatureClass()1423     virtual TABFeatureClass GetFeatureClass() { return TABFCRectangle; };
1424     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1425 
1426     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1427 
1428     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1429                                         GBool bCoordDataOnly=FALSE,
1430                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1431     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1432                                        GBool bCoordDataOnly=FALSE,
1433                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1434 
1435     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1436     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1437 
1438     virtual const char *GetStyleString();
1439 
1440     virtual void DumpMIF(FILE *fpOut = NULL);
1441 
1442     // MapInfo-specific attributes... made available through public vars
1443     // for now.
1444     GBool       m_bRoundCorners;
1445     double      m_dRoundXRadius;
1446     double      m_dRoundYRadius;
1447 
1448 };
1449 
1450 
1451 /*---------------------------------------------------------------------
1452  *                      class TABEllipse
1453  *
1454  * Feature class to handle the MapInfo ellipse types:
1455  *
1456  *     TAB_GEOM_ELLIPSE_C      0x19
1457  *     TAB_GEOM_ELLIPSE        0x1a
1458  *
1459  * An ellipse is defined by the coords of its 2 opposite corners (the MBR)
1460  *
1461  * Feature geometry can be either an OGRPoint defining the center of the
1462  * ellipse, or an OGRPolygon defining the ellipse itself.
1463  *
1464  * When an ellipse is read, the returned geometry is a OGRPolygon representing
1465  * the ellipse with 2 degrees line segments.
1466  *
1467  * In the case of the OGRPoint, then the X/Y Radius MUST be set, but.
1468  * However with an OGRPolygon, if the X/Y radius are not set (== 0) then
1469  * the MBR of the polygon will be used to define the ellipse parameters
1470  * and the center of the MBR is used as the center of the ellipse...
1471  * (i.e. the polygon vertices themselves will be ignored).
1472  *--------------------------------------------------------------------*/
1473 class TABEllipse: public TABFeature,
1474                   public ITABFeaturePen,
1475                   public ITABFeatureBrush
1476 {
1477   private:
1478     virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1479 
1480   public:
1481              TABEllipse(OGRFeatureDefn *poDefnIn);
1482     virtual ~TABEllipse();
1483 
GetFeatureClass()1484     virtual TABFeatureClass GetFeatureClass() { return TABFCEllipse; };
1485     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1486 
1487     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1488 
1489     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1490                                         GBool bCoordDataOnly=FALSE,
1491                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1492     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1493                                        GBool bCoordDataOnly=FALSE,
1494                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1495 
1496     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1497     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1498 
1499     virtual const char *GetStyleString();
1500 
1501     virtual void DumpMIF(FILE *fpOut = NULL);
1502 
1503     // MapInfo-specific attributes... made available through public vars
1504     // for now.
1505     double      m_dCenterX;
1506     double      m_dCenterY;
1507     double      m_dXRadius;
1508     double      m_dYRadius;
1509 
1510 };
1511 
1512 
1513 /*---------------------------------------------------------------------
1514  *                      class TABArc
1515  *
1516  * Feature class to handle the MapInfo arc types:
1517  *
1518  *     TAB_GEOM_ARC_C      0x0a
1519  *     TAB_GEOM_ARC        0x0b
1520  *
1521  * In MapInfo, an arc is defined by the coords of the MBR corners of its
1522  * defining ellipse, which in this case is different from the arc's MBR,
1523  * and a start and end angle in degrees.
1524  *
1525  * Feature geometry can be either an OGRLineString or an OGRPoint.
1526  *
1527  * In any case, X/Y radius X/Y center, and start/end angle (in degrees
1528  * counterclockwise) MUST be set.
1529  *
1530  * When an arc is read, the returned geometry is an OGRLineString
1531  * representing the arc with 2 degrees line segments.
1532  *--------------------------------------------------------------------*/
1533 class TABArc: public TABFeature,
1534               public ITABFeaturePen
1535 {
1536   private:
1537     double      m_dStartAngle;  // In degrees, counterclockwise,
1538     double      m_dEndAngle;    // starting at 3 o'clock
1539 
1540     virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1541 
1542   public:
1543              TABArc(OGRFeatureDefn *poDefnIn);
1544     virtual ~TABArc();
1545 
GetFeatureClass()1546     virtual TABFeatureClass GetFeatureClass() { return TABFCArc; };
1547     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1548 
1549     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1550 
1551     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1552                                         GBool bCoordDataOnly=FALSE,
1553                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1554     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1555                                        GBool bCoordDataOnly=FALSE,
1556                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1557 
1558     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1559     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1560 
1561     virtual const char *GetStyleString();
1562 
1563     virtual void DumpMIF(FILE *fpOut = NULL);
1564 
GetStartAngle()1565     double      GetStartAngle() { return m_dStartAngle; };
GetEndAngle()1566     double      GetEndAngle()   { return m_dEndAngle; };
1567     void        SetStartAngle(double dAngle);
1568     void        SetEndAngle(double dAngle);
1569 
1570     // MapInfo-specific attributes... made available through public vars
1571     // for now.
1572     double      m_dCenterX;
1573     double      m_dCenterY;
1574     double      m_dXRadius;
1575     double      m_dYRadius;
1576 };
1577 
1578 
1579 /*---------------------------------------------------------------------
1580  *                      class TABText
1581  *
1582  * Feature class to handle the MapInfo text types:
1583  *
1584  *     TAB_GEOM_TEXT_C         0x10
1585  *     TAB_GEOM_TEXT           0x11
1586  *
1587  * Feature geometry is an OGRPoint corresponding to the lower-left
1588  * corner of the text MBR BEFORE ROTATION.
1589  *
1590  * Text string, and box height/width (box before rotation is applied)
1591  * are required in a valid text feature and MUST be set.
1592  * Text angle and other styles are optional.
1593  *--------------------------------------------------------------------*/
1594 class TABText: public TABFeature,
1595                public ITABFeatureFont,
1596                public ITABFeaturePen
1597 {
1598   protected:
1599     char        *m_pszString;
1600 
1601     double      m_dAngle;
1602     double      m_dHeight;
1603     double      m_dWidth;
1604     double      m_dfLineEndX;
1605     double      m_dfLineEndY;
1606     GBool       m_bLineEndSet;
1607     void        UpdateTextMBR();
1608 
1609     GInt32      m_rgbForeground;
1610     GInt32      m_rgbBackground;
1611     GInt32      m_rgbOutline;
1612     GInt32      m_rgbShadow;
1613 
1614     GInt16      m_nTextAlignment;       // Justification/Vert.Spacing/arrow
1615     GInt16      m_nFontStyle;           // Bold/italic/underlined/shadow/...
1616 
1617     const char *GetLabelStyleString();
1618 
1619     virtual int UpdateMBR(TABMAPFile *poMapFile = NULL);
1620 
1621   public:
1622              TABText(OGRFeatureDefn *poDefnIn);
1623     virtual ~TABText();
1624 
GetFeatureClass()1625     virtual TABFeatureClass GetFeatureClass() { return TABFCText; };
1626     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1627 
1628     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1629 
1630     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1631                                         GBool bCoordDataOnly=FALSE,
1632                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1633     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1634                                        GBool bCoordDataOnly=FALSE,
1635                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1636 
1637     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1638     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1639 
1640     virtual const char *GetStyleString();
1641 
1642     virtual void DumpMIF(FILE *fpOut = NULL);
1643 
1644     const char *GetTextString();
1645     double      GetTextAngle();
1646     double      GetTextBoxHeight();
1647     double      GetTextBoxWidth();
1648     GInt32      GetFontFGColor();
1649     GInt32      GetFontBGColor();
1650     GInt32      GetFontOColor();
1651     GInt32      GetFontSColor();
1652     void        GetTextLineEndPoint(double &dX, double &dY);
1653 
1654     TABTextJust GetTextJustification();
1655     TABTextSpacing  GetTextSpacing();
1656     TABTextLineType GetTextLineType();
1657     GBool       QueryFontStyle(TABFontStyle eStyleToQuery);
1658 
1659     void        SetTextString(const char *pszStr);
1660     void        SetTextAngle(double dAngle);
1661     void        SetTextBoxHeight(double dHeight);
1662     void        SetTextBoxWidth(double dWidth);
1663     void        SetFontFGColor(GInt32 rgbColor);
1664     void        SetFontBGColor(GInt32 rgbColor);
1665     void        SetFontOColor(GInt32 rgbColor);
1666     void        SetFontSColor(GInt32 rgbColor);
1667     void        SetTextLineEndPoint(double dX, double dY);
1668 
1669     void        SetTextJustification(TABTextJust eJust);
1670     void        SetTextSpacing(TABTextSpacing eSpacing);
1671     void        SetTextLineType(TABTextLineType eLineType);
1672     void        ToggleFontStyle(TABFontStyle eStyleToToggle, GBool bStatus);
1673 
1674     int         GetFontStyleMIFValue();
1675     void        SetFontStyleMIFValue(int nStyle, GBool bBGColorSet=FALSE);
1676     GBool       IsFontBGColorUsed();
1677     GBool       IsFontOColorUsed();
1678     GBool       IsFontSColorUsed();
1679     GBool       IsFontBold();
1680     GBool       IsFontItalic();
1681     GBool       IsFontUnderline();
GetFontStyleTABValue()1682     int         GetFontStyleTABValue()           {return m_nFontStyle;};
SetFontStyleTABValue(int nStyle)1683     void        SetFontStyleTABValue(int nStyle){m_nFontStyle=(GInt16)nStyle;};
1684 
1685 };
1686 
1687 
1688 /*---------------------------------------------------------------------
1689  *                      class TABMultiPoint
1690  *
1691  * Feature class to handle MapInfo Multipoint features:
1692  *
1693  *     TAB_GEOM_MULTIPOINT_C        0x34
1694  *     TAB_GEOM_MULTIPOINT          0x35
1695  *
1696  * Feature geometry will be a OGRMultiPoint
1697  *
1698  * The symbol number is in the range [31..67], with 31=None and corresponds
1699  * to one of the 35 predefined "Old MapInfo Symbols"
1700  *--------------------------------------------------------------------*/
1701 class TABMultiPoint: public TABFeature,
1702                      public ITABFeatureSymbol
1703 {
1704   private:
1705     // We call it center, but it's more like a label point
1706     // Its value default to be the location of the first point
1707     GBool       m_bCenterIsSet;
1708     double      m_dCenterX, m_dCenterY;
1709 
1710   public:
1711              TABMultiPoint(OGRFeatureDefn *poDefnIn);
1712     virtual ~TABMultiPoint();
1713 
GetFeatureClass()1714     virtual TABFeatureClass GetFeatureClass() { return TABFCMultiPoint; };
1715     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1716 
1717     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1718 
1719     int         GetXY(int i, double &dX, double &dY);
1720     int         GetNumPoints();
1721 
1722     int         GetCenter(double &dX, double &dY);
1723     void        SetCenter(double dX, double dY);
1724 
1725     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1726                                         GBool bCoordDataOnly=FALSE,
1727                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1728     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1729                                        GBool bCoordDataOnly=FALSE,
1730                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1731 
1732     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1733     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1734 
1735     virtual const char *GetStyleString();
1736 
1737     virtual void DumpMIF(FILE *fpOut = NULL);
1738 };
1739 
1740 /*---------------------------------------------------------------------
1741  *
1742  *                      class TABCollection
1743  *
1744  * Feature class to handle MapInfo Collection features:
1745  *
1746  *     TAB_GEOM_COLLECTION_C        0x37
1747  *     TAB_GEOM_COLLECTION          0x38
1748  *
1749  * Feature geometry will be a OGRCollection
1750  *
1751  * **** IMPORTANT NOTE: ****
1752  *
1753  * The current implementation does not allow setting the Geometry via
1754  * OGRFeature::SetGeometry*(). The geometries must be set via the
1755  * TABCollection::SetRegion/Pline/MpointDirectly() methods which will take
1756  * care of keeping the OGRFeature's geometry in sync.
1757  *
1758  * If we ever want to support creating collections via the OGR interface then
1759  * something should be added in TABCollection::WriteGeometryToMapFile(), or
1760  * perhaps in ValidateMapInfoType(), or even better in a custom
1761  * TABCollection::SetGeometry*()... but then this last option may not work
1762  * unless OGRFeature::SetGeometry*() are made virtual in OGR.
1763  *
1764  *--------------------------------------------------------------------*/
1765 class TABCollection: public TABFeature,
1766                      public ITABFeatureSymbol
1767 {
1768   private:
1769     TABRegion       *m_poRegion;
1770     TABPolyline     *m_poPline;
1771     TABMultiPoint   *m_poMpoint;
1772 
1773     void    EmptyCollection();
1774     int     ReadLabelAndMBR(TABMAPCoordBlock *poCoordBlock,
1775                             GBool bComprCoord,
1776                             GInt32 nComprOrgX, GInt32 nComprOrgY,
1777                             GInt32 &pnMinX, GInt32 &pnMinY,
1778                             GInt32 &pnMaxX, GInt32 &pnMaxY,
1779                             GInt32 &pnLabelX, GInt32 &pnLabelY );
1780     int     WriteLabelAndMBR(TABMAPCoordBlock *poCoordBlock,
1781                              GBool bComprCoord,
1782                              GInt32 nMinX, GInt32 nMinY,
1783                              GInt32 nMaxX, GInt32 nMaxY,
1784                              GInt32 nLabelX, GInt32 nLabelY );
1785     int     SyncOGRGeometryCollection(GBool bSyncRegion,
1786                                       GBool bSyncPline,
1787                                       GBool bSyncMpoint);
1788 
1789   public:
1790              TABCollection(OGRFeatureDefn *poDefnIn);
1791     virtual ~TABCollection();
1792 
GetFeatureClass()1793     virtual TABFeatureClass GetFeatureClass() { return TABFCCollection; };
1794     virtual TABGeomType     ValidateMapInfoType(TABMAPFile *poMapFile = NULL);
1795 
1796     virtual TABFeature *CloneTABFeature(OGRFeatureDefn *poNewDefn = NULL );
1797 
1798     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1799                                         GBool bCoordDataOnly=FALSE,
1800                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1801     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1802                                        GBool bCoordDataOnly=FALSE,
1803                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1804 
1805     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1806     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1807 
1808     virtual const char *GetStyleString();
1809 
1810     virtual void DumpMIF(FILE *fpOut = NULL);
1811 
GetRegionRef()1812     TABRegion           *GetRegionRef()         {return m_poRegion; };
GetPolylineRef()1813     TABPolyline         *GetPolylineRef()       {return m_poPline; };
GetMultiPointRef()1814     TABMultiPoint       *GetMultiPointRef()     {return m_poMpoint; };
1815 
1816     int                 SetRegionDirectly(TABRegion *poRegion);
1817     int                 SetPolylineDirectly(TABPolyline *poPline);
1818     int                 SetMultiPointDirectly(TABMultiPoint *poMpoint);
1819 };
1820 
1821 
1822 /*---------------------------------------------------------------------
1823  *                      class TABDebugFeature
1824  *
1825  * Feature class to use for testing purposes... this one does not
1826  * correspond to any MapInfo type... it's just used to dump info about
1827  * feature types that are not implemented yet.
1828  *--------------------------------------------------------------------*/
1829 class TABDebugFeature: public TABFeature
1830 {
1831   private:
1832     GByte       m_abyBuf[512];
1833     int         m_nSize;
1834     int         m_nCoordDataPtr;  // -1 if none
1835     int         m_nCoordDataSize;
1836 
1837   public:
1838              TABDebugFeature(OGRFeatureDefn *poDefnIn);
1839     virtual ~TABDebugFeature();
1840 
GetFeatureClass()1841     virtual TABFeatureClass GetFeatureClass() { return TABFCDebugFeature; };
1842 
1843     virtual int ReadGeometryFromMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1844                                         GBool bCoordDataOnly=FALSE,
1845                                         TABMAPCoordBlock **ppoCoordBlock=NULL);
1846     virtual int WriteGeometryToMAPFile(TABMAPFile *poMapFile, TABMAPObjHdr *,
1847                                        GBool bCoordDataOnly=FALSE,
1848                                        TABMAPCoordBlock **ppoCoordBlock=NULL);
1849 
1850     virtual int ReadGeometryFromMIFFile(MIDDATAFile *fp);
1851     virtual int WriteGeometryToMIFFile(MIDDATAFile *fp);
1852 
1853     virtual void DumpMIF(FILE *fpOut = NULL);
1854 };
1855 
1856 /* -------------------------------------------------------------------- */
1857 /*      Some stuff related to spatial reference system handling.        */
1858 /*                                                                      */
1859 /*      In GDAL we make use of the coordsys transformation from         */
1860 /*      other places (sometimes even from plugins), so we               */
1861 /*      deliberately export these two functions from the DLL.           */
1862 /* -------------------------------------------------------------------- */
1863 
1864 char CPL_DLL *MITABSpatialRef2CoordSys( OGRSpatialReference * );
1865 OGRSpatialReference CPL_DLL * MITABCoordSys2SpatialRef( const char * );
1866 
1867 GBool MITABExtractCoordSysBounds( const char * pszCoordSys,
1868                                   double &dXMin, double &dYMin,
1869                                   double &dXMax, double &dYMax );
1870 int MITABCoordSys2TABProjInfo(const char * pszCoordSys, TABProjInfo *psProj);
1871 
1872 typedef struct {
1873     int         nDatumEPSGCode;
1874     int         nMapInfoDatumID;
1875     const char  *pszOGCDatumName;
1876     int         nEllipsoid;
1877     double      dfShiftX;
1878     double      dfShiftY;
1879     double      dfShiftZ;
1880     double      dfDatumParm0; /* RotX */
1881     double      dfDatumParm1; /* RotY */
1882     double      dfDatumParm2; /* RotZ */
1883     double      dfDatumParm3; /* Scale Factor */
1884     double      dfDatumParm4; /* Prime Meridian */
1885 } MapInfoDatumInfo;
1886 
1887 typedef struct
1888 {
1889     int         nMapInfoId;
1890     const char *pszMapinfoName;
1891     double      dfA; /* semi major axis in meters */
1892     double      dfInvFlattening; /* Inverse flattening */
1893 } MapInfoSpheroidInfo;
1894 
1895 
1896 /*---------------------------------------------------------------------
1897  * The following are used for coordsys bounds lookup
1898  *--------------------------------------------------------------------*/
1899 
1900 GBool   MITABLookupCoordSysBounds(TABProjInfo *psCS,
1901                                   double &dXMin, double &dYMin,
1902                                   double &dXMax, double &dYMax,
1903                                   int bOnlyUserTable = FALSE);
1904 int     MITABLoadCoordSysTable(const char *pszFname);
1905 void    MITABFreeCoordSysTable();
1906 GBool   MITABCoordSysTableLoaded();
1907 
1908 #endif /* _MITAB_H_INCLUDED_ */
1909