SpatiaLite  4.1.0
 All Data Structures Files Functions Variables Typedefs Macros Pages
gg_dxf.h
Go to the documentation of this file.
1 /*
2  gg_dxf.h -- Gaia common support for DXF files
3 
4  version 4.1, 2013 May 14
5 
6  Author: Sandro Furieri a.furieri@lqt.it
7 
8  ------------------------------------------------------------------------------
9 
10  Version: MPL 1.1/GPL 2.0/LGPL 2.1
11 
12  The contents of this file are subject to the Mozilla Public License Version
13  1.1 (the "License"); you may not use this file except in compliance with
14  the License. You may obtain a copy of the License at
15  http://www.mozilla.org/MPL/
16 
17 Software distributed under the License is distributed on an "AS IS" basis,
18 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
19 for the specific language governing rights and limitations under the
20 License.
21 
22 The Original Code is the SpatiaLite library
23 
24 The Initial Developer of the Original Code is Alessandro Furieri
25 
26 Portions created by the Initial Developer are Copyright (C) 2008-2013
27 the Initial Developer. All Rights Reserved.
28 
29 Contributor(s):
30 
31 Alternatively, the contents of this file may be used under the terms of
32 either the GNU General Public License Version 2 or later (the "GPL"), or
33 the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
34 in which case the provisions of the GPL or the LGPL are applicable instead
35 of those above. If you wish to allow use of your version of this file only
36 under the terms of either the GPL or the LGPL, and not to allow others to
37 use your version of this file under the terms of the MPL, indicate your
38 decision by deleting the provisions above and replace them with the notice
39 and other provisions required by the GPL or the LGPL. If you do not delete
40 the provisions above, a recipient may use your version of this file under
41 the terms of any one of the MPL, the GPL or the LGPL.
42 
43 */
44 
45 
52 #ifndef _GG_DXF_H
53 #ifndef DOXYGEN_SHOULD_SKIP_THIS
54 #define _GG_DXF_H
55 #endif
56 
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 /* constant values for DXF */
63 
65 #define GAIA_DXF_IMPORT_BY_LAYER 1
66 
67 #define GAIA_DXF_IMPORT_MIXED 2
68 
69 #define GAIA_DXF_AUTO_2D_3D 3
70 
71 #define GAIA_DXF_FORCE_2D 4
72 
73 #define GAIA_DXF_FORCE_3D 5
74 
75 #define GAIA_DXF_RING_NONE 6
76 
77 #define GAIA_DXF_RING_LINKED 7
78 
79 #define GAIA_DXF_RING_UNLINKED 8
80 
81 
83 #define GAIA_DXF_V12 1000
84 
85 /* data structs */
86 
87 
91  typedef struct gaia_dxf_extra_attr
92  {
94  char *key;
96  char *value;
106 
110  typedef struct gaia_dxf_insert
111  {
113  char *block_id;
115  double x;
117  double y;
119  double z;
121  double scale_x;
123  double scale_y;
125  double scale_z;
127  double angle;
129  int hasText;
131  int hasPoint;
133  int hasLine;
135  int hasPolyg;
137  int hasHatch;
139  int is3Dtext;
143  int is3Dline;
147  gaiaDxfExtraAttrPtr first;
149  gaiaDxfExtraAttrPtr last;
152  } gaiaDxfInsert;
159 
163  typedef struct gaia_dxf_text
164  {
166  char *label;
168  double x;
170  double y;
172  double z;
174  double angle;
176  gaiaDxfExtraAttrPtr first;
178  gaiaDxfExtraAttrPtr last;
181  } gaiaDxfText;
188 
192  typedef struct gaia_dxf_point
193  {
195  double x;
197  double y;
199  double z;
201  gaiaDxfExtraAttrPtr first;
203  gaiaDxfExtraAttrPtr last;
206  } gaiaDxfPoint;
213 
217  typedef struct gaia_dxf_circle
218  {
220  double cx;
222  double cy;
224  double cz;
226  double radius;
227  } gaiaDxfCircle;
234 
238  typedef struct gaia_dxf_arc
239  {
241  double cx;
243  double cy;
245  double cz;
247  double radius;
249  double start;
251  double stop;
252  } gaiaDxfArc;
259 
263  typedef struct gaia_dxf_hole
264  {
266  int points;
268  double *x;
270  double *y;
272  double *z;
275  } gaiaDxfHole;
282 
287  typedef struct gaia_dxf_polyline
288  {
292  int points;
294  double *x;
296  double *y;
298  double *z;
300  gaiaDxfHolePtr first_hole;
302  gaiaDxfHolePtr last_hole;
304  gaiaDxfExtraAttrPtr first;
306  gaiaDxfExtraAttrPtr last;
309  } gaiaDxfPolyline;
319  typedef struct gaia_dxf_hatch_segm
320  {
322  double x0;
324  double y0;
326  double x1;
328  double y1;
338 
342  typedef struct gaia_dxf_boundary_path
343  {
345  gaiaDxfHatchSegmPtr first;
347  gaiaDxfHatchSegmPtr last;
357 
361  typedef struct gaia_dxf_hatch
362  {
364  double spacing;
366  double angle;
368  double base_x;
370  double base_y;
372  double offset_x;
374  double offset_y;
376  gaiaDxfBoundaryPathPtr first;
378  gaiaDxfBoundaryPathPtr last;
382  gaiaDxfHatchSegmPtr first_out;
384  gaiaDxfHatchSegmPtr last_out;
387  } gaiaDxfHatch;
394 
398  typedef struct gaia_dxf_block
399  {
403  char *layer_name;
405  char *block_id;
407  gaiaDxfTextPtr first_text;
409  gaiaDxfTextPtr last_text;
411  gaiaDxfPointPtr first_point;
413  gaiaDxfPointPtr last_point;
415  gaiaDxfPolylinePtr first_line;
417  gaiaDxfPolylinePtr last_line;
419  gaiaDxfPolylinePtr first_polyg;
421  gaiaDxfPolylinePtr last_polyg;
423  gaiaDxfHatchPtr first_hatch;
425  gaiaDxfHatchPtr last_hatch;
427  int is3Dtext;
431  int is3Dline;
436  } gaiaDxfBlock;
443 
447  typedef struct gaia_dxf_layer
448  {
450  char *layer_name;
452  gaiaDxfTextPtr first_text;
454  gaiaDxfTextPtr last_text;
456  gaiaDxfPointPtr first_point;
458  gaiaDxfPointPtr last_point;
460  gaiaDxfPolylinePtr first_line;
462  gaiaDxfPolylinePtr last_line;
464  gaiaDxfPolylinePtr first_polyg;
466  gaiaDxfPolylinePtr last_polyg;
468  gaiaDxfHatchPtr first_hatch;
470  gaiaDxfHatchPtr last_hatch;
472  gaiaDxfInsertPtr first_ins_text;
474  gaiaDxfInsertPtr last_ins_text;
476  gaiaDxfInsertPtr first_ins_point;
478  gaiaDxfInsertPtr last_ins_point;
480  gaiaDxfInsertPtr first_ins_line;
482  gaiaDxfInsertPtr last_ins_line;
484  gaiaDxfInsertPtr first_ins_polyg;
486  gaiaDxfInsertPtr last_ins_polyg;
488  gaiaDxfInsertPtr first_ins_hatch;
490  gaiaDxfInsertPtr last_ins_hatch;
492  int is3Dtext;
496  int is3Dline;
525  } gaiaDxfLayer;
532 
536  typedef struct gaia_dxf_parser
537  {
539  char *filename;
541  gaiaDxfLayerPtr first_layer;
543  gaiaDxfLayerPtr last_layer;
545  gaiaDxfBlockPtr first_block;
547  gaiaDxfBlockPtr last_block;
551  int srid;
553  const char *selected_layer;
555  const char *prefix;
561  int line_no;
565  int op_code;
567  int section;
569  int tables;
571  int blocks;
573  int entities;
575  int is_layer;
577  int is_block;
579  int is_text;
581  int is_point;
587  int is_line;
591  int is_arc;
595  int is_hatch;
601  int eof;
603  int error;
623  gaiaDxfPointPtr first_pt;
625  gaiaDxfPointPtr last_pt;
627  char *extra_key;
629  char *extra_value;
631  gaiaDxfExtraAttrPtr first_ext;
633  gaiaDxfExtraAttrPtr last_ext;
635  gaiaDxfHatchPtr curr_hatch;
638  } gaiaDxfParser;
645 
649  typedef struct gaia_dxf_write
650  {
652  FILE *out;
656  int version;
658  int count;
660  int error;
661  } gaiaDxfWriter;
666 
667 
668 /* function prototypes */
669 
670 
692  GAIAGEO_DECLARE gaiaDxfParserPtr gaiaCreateDxfParser (int srid,
693  int force_dims,
694  const char *prefix,
695  const char
696  *selected_layer,
697  int special_rings);
698 
709  GAIAGEO_DECLARE void gaiaDestroyDxfParser (gaiaDxfParserPtr parser);
710 
725  GAIAGEO_DECLARE int gaiaParseDxfFile (gaiaDxfParserPtr parser,
726  const char *dxf_path);
727 
746  GAIAGEO_DECLARE int gaiaLoadFromDxfParser (sqlite3 * db_handle,
747  gaiaDxfParserPtr parser,
748  int mode, int append);
749 
762  GAIAGEO_DECLARE int gaiaDxfWriterInit (gaiaDxfWriterPtr dxf,
763  FILE * out, int precision,
764  int version);
765 
781  GAIAGEO_DECLARE int
782  gaiaDxfWriteHeader (gaiaDxfWriterPtr dxf, double minx, double miny,
783  double minz, double maxx, double maxy, double maxz);
784 
794  GAIAGEO_DECLARE int gaiaDxfWriteFooter (gaiaDxfWriterPtr dxf);
795 
805  GAIAGEO_DECLARE int gaiaDxfWriteTables (gaiaDxfWriterPtr dxf);
806 
817  GAIAGEO_DECLARE int gaiaDxfWriteLayer (gaiaDxfWriterPtr dxf,
818  const char *layer_name);
819 
830  GAIAGEO_DECLARE int gaiaDxfWriteEntities (gaiaDxfWriterPtr dxf);
831 
841  GAIAGEO_DECLARE int gaiaDxfWriteEndSection (gaiaDxfWriterPtr dxf);
842 
857  GAIAGEO_DECLARE int gaiaDxfWritePoint (gaiaDxfWriterPtr dxf,
858  const char *layer_name, double x,
859  double y, double z);
860 
878  GAIAGEO_DECLARE int gaiaDxfWriteText (gaiaDxfWriterPtr dxf,
879  const char *layer_name, double x,
880  double y, double z, const char *label,
881  double text_height, double angle);
882 
895  GAIAGEO_DECLARE int
896  gaiaDxfWriteLine (gaiaDxfWriterPtr dxf, const char *layer_name,
897  gaiaLinestringPtr line);
898 
911  GAIAGEO_DECLARE int
912  gaiaDxfWriteRing (gaiaDxfWriterPtr dxf, const char *layer_name,
913  gaiaRingPtr ring);
914 
930  GAIAGEO_DECLARE int
931  gaiaDxfWriteGeometry (gaiaDxfWriterPtr dxf, const char *layer_name,
932  const char *label, double text_height,
933  double text_rotation, gaiaGeomCollPtr geometry);
934 
957  GAIAGEO_DECLARE int
958  gaiaExportDxf (gaiaDxfWriterPtr dxf, sqlite3 * db_handle,
959  const char *sql, const char *layer_col_name,
960  const char *geom_col_name, const char *label_col_name,
961  const char *text_height_col_name,
962  const char *text_rotation_col_name,
963  gaiaGeomCollPtr geom_filter);
964 
965 #ifdef __cplusplus
966 }
967 #endif
968 
969 #endif /* _GG_DXF_H */