dgnlib
dgnlib.h
Go to the documentation of this file.
1 /******************************************************************************
2  * $Id: dgnlib.h 10645 2007-01-18 02:22:39Z warmerdam $
3  *
4  * Project: Microstation DGN Access Library
5  * Purpose: Definitions of public structures and API of DGN Library.
6  * Author: Frank Warmerdam, warmerdam@pobox.com
7  *
8  ******************************************************************************
9  * Copyright (c) 2000, Avenza Systems Inc, http://www.avenza.com/
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included
19  * in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  ****************************************************************************/
29 
30 #ifndef _DGNLIB_H_INCLUDED
31 #define _DGNLIB_H_INCLUDED
32 
33 #include "cpl_conv.h"
34 
35 CPL_C_START
36 
37 #define CPLE_DGN_ERROR_BASE
38 #define CPLE_ElementTooBig CPLE_DGN_ERROR_BASE+1
39 
54 typedef struct {
55  double x;
56  double y;
57  double z;
58 } DGNPoint;
59 
66 typedef struct {
67  unsigned char level;
68  unsigned char type;
69  unsigned char stype;
70  unsigned char flags;
71  long offset;
73 
85 typedef struct {
86  int offset;
87  int size;
88 
89  int element_id;
90  int stype;
91  int level;
92  int type;
93  int complex;
94  int deleted;
97  int properties;
98  int color;
99  int weight;
100  int style;
103  unsigned char *attr_data;
105  int raw_bytes;
106  unsigned char *raw_data;
107 } DGNElemCore;
108 
118 typedef struct {
119  DGNElemCore core;
120 
122  DGNPoint vertices[2];
125 
134 typedef struct {
135  DGNElemCore core;
136 
139  double primary_axis;
140  double secondary_axis;
142  double rotation;
143  int quat[4];
144 
145  double startang;
146  double sweepang;
148 } DGNElemArc;
149 
160 typedef struct {
161  DGNElemCore core;
162 
163  int font_id;
165  double length_mult;
166  double height_mult;
167  double rotation;
169  char string[1];
170 } DGNElemText;
171 
183 typedef struct {
184  DGNElemCore core;
185 
186  int totlength;
189  int numelems;
190  int surftype;
193  int boundelms;
196 
206 typedef struct {
207  DGNElemCore core;
208 
209  int screen_flag;
210  GByte color_info[256][3];
212 
213 typedef struct {
214  int flags;
215  unsigned char levels[8];
216  DGNPoint origin;
217  DGNPoint delta;
218  double transmatrx[9];
219  double conversion;
220  unsigned long activez;
221 } DGNViewInfo;
222 
237 typedef struct {
238  DGNElemCore core;
239 
240  int dimension;
242  double origin_x;
243  double origin_y;
244  double origin_z;
247  char sub_units[3];
249  char master_units[3];
251  DGNViewInfo views[8];
252 
253 } DGNElemTCB;
254 
263 typedef struct {
264  DGNElemCore core;
265 
266  int totlength;
269  char name[7];
270  unsigned short cclass;
271  unsigned short levels[4];
276  double trans[9];
279  double xscale;
280  double yscale;
281  double rotation;
282 
284 
293 typedef struct {
294  DGNElemCore core;
295 
296  short celltype;
297  short attindx;
298  char name[7];
300  int numwords;
302  short dispsymb;
303  unsigned short cclass;
304  unsigned short levels[4];
306  char description[28];
309 
318 typedef struct {
319  DGNElemCore core;
320 
321  int totlength;
324  // FIXME: Most of the contents of this element type is currently
325  // unknown. Please get in touch with the authors if you have
326  // information about how to decode this element.
328 
329 typedef union { char *string; GInt32 integer; double real; } tagValueUnion;
330 
339 typedef struct {
340  DGNElemCore core;
341 
342  int tagType;
343  int tagSet;
344  int tagIndex;
345  int tagLength;
349 
355 typedef struct _DGNTagDef {
356  char *name;
357  int id;
358  char *prompt;
359  int type;
361 } DGNTagDef;
362 
363 #define DGNTT_STRING 1
364 #define DGNTT_INTEGER 3
365 #define DGNTT_FLOAT 4
366 
375 typedef struct {
376  DGNElemCore core;
377 
378  int tagCount;
379  int tagSet;
380  int flags;
381  char *tagSetName;
385 } DGNElemTagSet;
386 
394 typedef struct {
395  DGNElemCore core;
396 
397  short unknown;
398  int quat[4];
400  double radius_1;
402  double radius_2;
404 } DGNElemCone;
405 
406 
417 typedef struct {
418  DGNElemCore core;
419 
420  int totlength;
422  int numelems;
424  short max_length;
425  short max_used;
426  short font_id;
429  double length_mult;
430  double height_mult;
431  double rotation;
435 
436 
444 typedef struct {
445  DGNElemCore core;
446 
447  long desc_words;
450  unsigned char curve_type;
451  unsigned char u_order;
452  unsigned short u_properties;
454  short num_poles_u;
455  short num_knots_u;
456  short rule_lines_u;
458  unsigned char v_order;
459  unsigned short v_properties;
461  short num_poles_v;
462  short num_knots_v;
463  short rule_lines_v;
465  short num_bounds;
467 
475 typedef struct {
476  DGNElemCore core;
477 
478  long desc_words;
481  unsigned char order;
482  unsigned char properties;
483  unsigned char curve_type;
484  short num_poles;
485  short num_knots;
487 
495 typedef struct {
496  DGNElemCore core;
497 
498  short number;
499  short numverts;
500  DGNPoint vertices[1];
503 
511 typedef struct {
512  DGNElemCore core;
513 
514  float array[1];
518 
519 
520 /* -------------------------------------------------------------------- */
521 /* Structure types */
522 /* -------------------------------------------------------------------- */
523 
525 #define DGNST_CORE 1
526 
528 #define DGNST_MULTIPOINT 2
529 
531 #define DGNST_COLORTABLE 3
532 
534 #define DGNST_TCB 4
535 
537 #define DGNST_ARC 5
538 
540 #define DGNST_TEXT 6
541 
543 #define DGNST_COMPLEX_HEADER 7
544 
546 #define DGNST_CELL_HEADER 8
547 
549 #define DGNST_TAG_VALUE 9
550 
552 #define DGNST_TAG_SET 10
553 
555 #define DGNST_CELL_LIBRARY 11
556 
558 #define DGNST_CONE 12
559 
561 #define DGNST_TEXT_NODE 13
562 
564 #define DGNST_BSPLINE_SURFACE_HEADER 14
565 
567 #define DGNST_BSPLINE_CURVE_HEADER 15
568 
570 #define DGNST_BSPLINE_SURFACE_BOUNDARY 16
571 
573 #define DGNST_KNOT_WEIGHT 17
574 
576 #define DGNST_SHARED_CELL_DEFN 18
577 
578 
579 /* -------------------------------------------------------------------- */
580 /* Element types */
581 /* -------------------------------------------------------------------- */
582 #define DGNT_CELL_LIBRARY 1
583 #define DGNT_CELL_HEADER 2
584 #define DGNT_LINE 3
585 #define DGNT_LINE_STRING 4
586 #define DGNT_GROUP_DATA 5
587 #define DGNT_SHAPE 6
588 #define DGNT_TEXT_NODE 7
589 #define DGNT_DIGITIZER_SETUP 8
590 #define DGNT_TCB 9
591 #define DGNT_LEVEL_SYMBOLOGY 10
592 #define DGNT_CURVE 11
593 #define DGNT_COMPLEX_CHAIN_HEADER 12
594 #define DGNT_COMPLEX_SHAPE_HEADER 14
595 #define DGNT_ELLIPSE 15
596 #define DGNT_ARC 16
597 #define DGNT_TEXT 17
598 #define DGNT_3DSURFACE_HEADER 18
599 #define DGNT_3DSOLID_HEADER 19
600 #define DGNT_BSPLINE_POLE 21
601 #define DGNT_POINT_STRING 22
602 #define DGNT_BSPLINE_SURFACE_HEADER 24
603 #define DGNT_BSPLINE_SURFACE_BOUNDARY 25
604 #define DGNT_BSPLINE_KNOT 26
605 #define DGNT_BSPLINE_CURVE_HEADER 27
606 #define DGNT_BSPLINE_WEIGHT_FACTOR 28
607 #define DGNT_CONE 23
608 #define DGNT_SHARED_CELL_DEFN 34
609 #define DGNT_SHARED_CELL_ELEM 35
610 #define DGNT_TAG_VALUE 37
611 #define DGNT_APPLICATION_ELEM 66
612 
613 /* -------------------------------------------------------------------- */
614 /* Line Styles */
615 /* -------------------------------------------------------------------- */
616 #define DGNS_SOLID 0
617 #define DGNS_DOTTED 1
618 #define DGNS_MEDIUM_DASH 2
619 #define DGNS_LONG_DASH 3
620 #define DGNS_DOT_DASH 4
621 #define DGNS_SHORT_DASH 5
622 #define DGNS_DASH_DOUBLE_DOT 6
623 #define DGNS_LONG_DASH_SHORT_DASH 7
624 
625 /* -------------------------------------------------------------------- */
626 /* 3D Surface Types */
627 /* -------------------------------------------------------------------- */
628 #define DGNSUT_SURFACE_OF_PROJECTION 0
629 #define DGNSUT_BOUNDED_PLANE 1
630 #define DGNSUT_BOUNDED_PLANE2 2
631 #define DGNSUT_RIGHT_CIRCULAR_CYLINDER 3
632 #define DGNSUT_RIGHT_CIRCULAR_CONE 4
633 #define DGNSUT_TABULATED_CYLINDER 5
634 #define DGNSUT_TABULATED_CONE 6
635 #define DGNSUT_CONVOLUTE 7
636 #define DGNSUT_SURFACE_OF_REVOLUTION 8
637 #define DGNSUT_WARPED_SURFACE 9
638 
639 /* -------------------------------------------------------------------- */
640 /* 3D Solid Types */
641 /* -------------------------------------------------------------------- */
642 #define DGNSOT_VOLUME_OF_PROJECTION 0
643 #define DGNSOT_VOLUME_OF_REVOLUTION 1
644 #define DGNSOT_BOUNDED_VOLUME 2
645 
646 
647 /* -------------------------------------------------------------------- */
648 /* Class */
649 /* -------------------------------------------------------------------- */
650 #define DGNC_PRIMARY 0
651 #define DGNC_PATTERN_COMPONENT 1
652 #define DGNC_CONSTRUCTION_ELEMENT 2
653 #define DGNC_DIMENSION_ELEMENT 3
654 #define DGNC_PRIMARY_RULE_ELEMENT 4
655 #define DGNC_LINEAR_PATTERNED_ELEMENT 5
656 #define DGNC_CONSTRUCTION_RULE_ELEMENT 6
657 
658 /* -------------------------------------------------------------------- */
659 /* Group Data level numbers. */
660 /* */
661 /* These are symbolic values for the typ 5 (DGNT_GROUP_DATA) */
662 /* level values that have special meanings. */
663 /* -------------------------------------------------------------------- */
664 #define DGN_GDL_COLOR_TABLE 1
665 #define DGN_GDL_NAMED_VIEW 3
666 #define DGN_GDL_REF_FILE 9
667 
668 /* -------------------------------------------------------------------- */
669 /* Word 17 property flags. */
670 /* -------------------------------------------------------------------- */
671 #define DGNPF_HOLE 0x8000
672 #define DGNPF_SNAPPABLE 0x4000
673 #define DGNPF_PLANAR 0x2000
674 #define DGNPF_ORIENTATION 0x1000
675 #define DGNPF_ATTRIBUTES 0x0800
676 #define DGNPF_MODIFIED 0x0400
677 #define DGNPF_NEW 0x0200
678 #define DGNPF_LOCKED 0x0100
679 #define DGNPF_CLASS 0x000f
680 
681 /* -------------------------------------------------------------------- */
682 /* DGNElementInfo flag values. */
683 /* -------------------------------------------------------------------- */
684 #define DGNEIF_DELETED 0x01
685 #define DGNEIF_COMPLEX 0x02
686 
687 /* -------------------------------------------------------------------- */
688 /* Justifications */
689 /* -------------------------------------------------------------------- */
690 #define DGNJ_LEFT_TOP 0
691 #define DGNJ_LEFT_CENTER 1
692 #define DGNJ_LEFT_BOTTOM 2
693 #define DGNJ_LEFTMARGIN_TOP 3 /* text node header only */
694 #define DGNJ_LEFTMARGIN_CENTER 4 /* text node header only */
695 #define DGNJ_LEFTMARGIN_BOTTOM 5 /* text node header only */
696 #define DGNJ_CENTER_TOP 6
697 #define DGNJ_CENTER_CENTER 7
698 #define DGNJ_CENTER_BOTTOM 8
699 #define DGNJ_RIGHTMARGIN_TOP 9 /* text node header only */
700 #define DGNJ_RIGHTMARGIN_CENTER 10 /* text node header only */
701 #define DGNJ_RIGHTMARGIN_BOTTOM 11 /* text node header only */
702 #define DGNJ_RIGHT_TOP 12
703 #define DGNJ_RIGHT_CENTER 13
704 #define DGNJ_RIGHT_BOTTOM 14
705 
706 /* -------------------------------------------------------------------- */
707 /* DGN file reading options. */
708 /* -------------------------------------------------------------------- */
709 #define DGNO_CAPTURE_RAW_DATA 0x01
710 
711 /* -------------------------------------------------------------------- */
712 /* Known attribute linkage types, including my synthetic ones. */
713 /* -------------------------------------------------------------------- */
714 #define DGNLT_DMRS 0x0000
715 #define DGNLT_INFORMIX 0x3848
716 #define DGNLT_ODBC 0x5e62
717 #define DGNLT_ORACLE 0x6091
718 #define DGNLT_RIS 0x71FB
719 #define DGNLT_SYBASE 0x4f58
720 #define DGNLT_XBASE 0x1971
721 #define DGNLT_SHAPE_FILL 0x0041
722 #define DGNLT_ASSOC_ID 0x7D2F
723 
724 /* -------------------------------------------------------------------- */
725 /* File creation options. */
726 /* -------------------------------------------------------------------- */
727 
728 #define DGNCF_USE_SEED_UNITS 0x01
729 #define DGNCF_USE_SEED_ORIGIN 0x02
730 #define DGNCF_COPY_SEED_FILE_COLOR_TABLE 0x04
731 #define DGNCF_COPY_WHOLE_SEED_FILE 0x08
732 
733 /* -------------------------------------------------------------------- */
734 /* B-Spline Curve flags. Also used for U-direction of surfaces */
735 /* -------------------------------------------------------------------- */
736 #define DGNBSC_CURVE_DISPLAY 0x10
737 #define DGNBSC_POLY_DISPLAY 0x20
738 #define DGNBSC_RATIONAL 0x40
739 #define DGNBSC_CLOSED 0x80
740 
741 /* -------------------------------------------------------------------- */
742 /* B-Spline Curve flags for V-direction of surfaces. */
743 /* -------------------------------------------------------------------- */
744 #define DGNBSS_ARC_SPACING 0x40
745 #define DGNBSS_CLOSED 0x80
746 
747 /* -------------------------------------------------------------------- */
748 /* API */
749 /* -------------------------------------------------------------------- */
751 typedef void *DGNHandle;
752 
753 DGNHandle CPL_DLL DGNOpen( const char *, int );
754 void CPL_DLL DGNSetOptions( DGNHandle, int );
755 int CPL_DLL DGNTestOpen( GByte *, int );
756 const DGNElementInfo CPL_DLL *DGNGetElementIndex( DGNHandle, int * );
757 int CPL_DLL DGNGetExtents( DGNHandle, double * );
758 int CPL_DLL DGNGetDimension( DGNHandle );
760 void CPL_DLL DGNFreeElement( DGNHandle, DGNElemCore * );
761 void CPL_DLL DGNRewind( DGNHandle );
762 int CPL_DLL DGNGotoElement( DGNHandle, int );
763 void CPL_DLL DGNClose( DGNHandle );
764 int CPL_DLL DGNLoadTCB( DGNHandle );
765 int CPL_DLL DGNLookupColor( DGNHandle, int, int *, int *, int * );
766 int CPL_DLL DGNGetShapeFillInfo( DGNHandle, DGNElemCore *, int * );
767 int CPL_DLL DGNGetAssocID( DGNHandle, DGNElemCore * );
769  DGNPoint *, DGNPoint * );
770 
771 void CPL_DLL DGNDumpElement( DGNHandle, DGNElemCore *, FILE * );
772 const char CPL_DLL *DGNTypeToName( int );
773 
774 void CPL_DLL DGNRotationToQuaternion( double, int * );
775 void CPL_DLL DGNQuaternionToMatrix( int *, float * );
776 int CPL_DLL DGNStrokeArc( DGNHandle, DGNElemArc *, int, DGNPoint * );
777 int CPL_DLL DGNStrokeCurve( DGNHandle, DGNElemMultiPoint*, int, DGNPoint * );
778 void CPL_DLL DGNSetSpatialFilter( DGNHandle hDGN,
779  double dfXMin, double dfYMin,
780  double dfXMax, double dfYMax );
781 int CPL_DLL DGNGetAttrLinkSize( DGNHandle, DGNElemCore *, int );
782 unsigned char CPL_DLL *
783  DGNGetLinkage( DGNHandle hDGN, DGNElemCore *psElement,
784  int iIndex, int *pnLinkageType,
785  int *pnEntityNum, int *pnMSLink, int *pnLinkSize);
786 
787 /* Write API */
788 
789 int CPL_DLL DGNWriteElement( DGNHandle, DGNElemCore * );
790 int CPL_DLL DGNResizeElement( DGNHandle, DGNElemCore *, int );
791 DGNHandle CPL_DLL
792  DGNCreate( const char *pszNewFilename, const char *pszSeedFile,
793  int nCreationFlags,
794  double dfOriginX, double dfOriginY, double dfOriginZ,
795  int nMasterUnitPerSubUnit, int nUORPerSubUnit,
796  const char *pszMasterUnits, const char *pszSubUnits );
797 DGNElemCore CPL_DLL *DGNCloneElement( DGNHandle hDGNSrc, DGNHandle hDGNDst,
798  DGNElemCore *psSrcElement );
799 int CPL_DLL DGNUpdateElemCore( DGNHandle hDGN, DGNElemCore *psElement,
800  int nLevel, int nGraphicGroup, int nColor,
801  int nWeight, int nStyle );
802 int CPL_DLL DGNUpdateElemCoreExtended( DGNHandle hDGN,
803  DGNElemCore *psElement );
804 
805 DGNElemCore CPL_DLL *
806  DGNCreateMultiPointElem( DGNHandle hDGN, int nType,
807  int nPointCount, DGNPoint*pasVertices );
808 DGNElemCore CPL_DLL *
809  DGNCreateArcElem2D( DGNHandle hDGN, int nType,
810  double dfOriginX, double dfOriginY,
811  double dfPrimaryAxis, double dfSecondaryAxis,
812  double dfRotation,
813  double dfStartAngle, double dfSweepAngle );
814 
815 DGNElemCore CPL_DLL *
816  DGNCreateArcElem( DGNHandle hDGN, int nType,
817  double dfOriginX, double dfOriginY,
818  double dfOriginZ,
819  double dfPrimaryAxis, double dfSecondaryAxis,
820  double dfStartAngle, double dfSweepAngle,
821  double dfRotation, int *panQuaternion );
822 
823 DGNElemCore CPL_DLL *
825  double center_1X, double center_1Y,
826  double center_1Z, double radius_1,
827  double center_2X, double center_2Y,
828  double center_2Z, double radius_2,
829  int *panQuaternion );
830 
831 DGNElemCore CPL_DLL *
832  DGNCreateTextElem( DGNHandle hDGN, const char *pszText,
833  int nFontId, int nJustification,
834  double dfLengthMult, double dfHeightMult,
835  double dfRotation, int *panQuaternion,
836  double dfOriginX, double dfOriginY, double dfOriginZ );
837 
838 DGNElemCore CPL_DLL *
839  DGNCreateColorTableElem( DGNHandle hDGN, int nScreenFlag,
840  GByte abyColorInfo[256][3] );
841 DGNElemCore CPL_DLL *
842 DGNCreateComplexHeaderElem( DGNHandle hDGN, int nType,
843  int nTotLength, int nNumElems );
844 DGNElemCore CPL_DLL *
846  int nNumElems, DGNElemCore **papsElems );
847 
848 DGNElemCore CPL_DLL *
849 DGNCreateSolidHeaderElem( DGNHandle hDGN, int nType, int nSurfType,
850  int nBoundElems, int nTotLength, int nNumElems );
851 DGNElemCore CPL_DLL *
852 DGNCreateSolidHeaderFromGroup( DGNHandle hDGN, int nType, int nSurfType,
853  int nBoundElems, int nNumElems,
854  DGNElemCore **papsElems );
855 
856 DGNElemCore CPL_DLL *
857 DGNCreateCellHeaderElem( DGNHandle hDGN, int nTotLength, const char *pszName,
858  short nClass, short *panLevels,
859  DGNPoint *psRangeLow, DGNPoint *psRangeHigh,
860  DGNPoint *psOrigin, double dfXScale, double dfYScale,
861  double dfRotation );
862 
863 DGNElemCore CPL_DLL *
864 DGNCreateCellHeaderFromGroup( DGNHandle hDGN, const char *pszName,
865  short nClass, short *panLevels,
866  int nNumElems, DGNElemCore **papsElems,
867  DGNPoint *psOrigin,
868  double dfXScale, double dfYScale,
869  double dfRotation );
870 
871 int CPL_DLL DGNAddMSLink( DGNHandle hDGN, DGNElemCore *psElement,
872  int nLinkageType, int nEntityNum, int nMSLink );
873 
874 int CPL_DLL DGNAddRawAttrLink( DGNHandle hDGN, DGNElemCore *psElement,
875  int nLinkSize, unsigned char *pabyRawLinkData );
876 
877 int CPL_DLL DGNAddShapeFillInfo( DGNHandle hDGN, DGNElemCore *psElement,
878  int nColor );
879 
880 int CPL_DLL DGNElemTypeHasDispHdr( int nElemType );
881 
882 CPL_C_END
883 
884 #endif /* ndef _DGNLIB_H_INCLUDED */