/*--------------------------------------------------------------------------------------+
|
|    $RCSfile: tcb.h,v $
|   $Revision: 7.128 $
|       $Date: 2009/02/18 12:01:18 $
|
|  $Copyright: (c) 2009 Bentley Systems, Incorporated. All rights reserved. $
|
+--------------------------------------------------------------------------------------*/
#pragma once
#define __tcbH__

#include    <basetype.h>
#include    <basedefs.h>
#include    <msdefs.h>
#include    <mstypes.h>
#include    <toolset.h>
#include    <3dtools.h>

BEGIN_EXTERN_C

typedef struct autodim1
    {
    struct
        {
        UInt16    adres2:8;
        UInt16    ref_mastersub:2;
        UInt16    ref_decfract:1;
        UInt16    accuracyFlags:2;  /* 0- use ref_decfract; 1- scientific accuracy; 2- fractional zero */
        UInt16    reserved:3;
        } format;
    } Autodim1;

typedef struct
    {
    Int32       deprecated;         /* Formerly Active style number;                            */
    UInt32      modifiers;          /* Modifier flags (see mslstyle.h)                          */
    UInt32      reserved[4];
    double      scale;              /* Scale used at placement                                  */
    double      shift;              /* Shift value (distance or fraction)                       */
    double      startWidth;         /* Start width override                                     */
    double      endWidth;           /* End width override                                       */
    } LineStyleInfo;

typedef struct cntrlwd
    {
    UInt32          grid_lock_deprecated:1;     /* deprecated after v8beta2 - do not use */
    UInt32          unit_lock_deprecated:1;     /* deprecated after v8beta2 - do not use */
    UInt32          reserve1:6;                 /* keep inh_msg and inh_err in same position as V7 */
    UInt32          inh_msg:1;                  /* inhibit CF, ST and PR messages */
    UInt32          inh_err:1;                  /* inhibit err msgs (except fatal) */
    UInt32          reserve2:22;
    } Cntrlwd;

typedef struct      cntrl1
    {
    UInt16          reserve1:1;
    UInt16          boresite_deprecated:1;  /* deprecated after xmrc1 - do not use */
    UInt16          prj_key:1;              /* project or keypoint snap */
    UInt16          cnstplane:1;            /* enable construction aide */
    UInt16          stackfract:1;           /* enable stacked fractions */
    UInt16          cellgg:1;               /* reserved */
    UInt16          capsurf:1;              /* capped surface placement mode */
    UInt16          reserve2:9;
    } Cntrl1;                               /* miscellaneous control flags */

typedef struct      fbfdcn
    {
    UInt16          solidhole:1;    /* solid/hole flag */
    UInt16          scalelk:1;      /* scale lock on */
    UInt16          txnodelk:1;     /* text node lock */
    UInt16          anglelk:1;      /* angle lock */
    UInt16          snaplk:1;       /* snap lock */
    UInt16          mirrorch:1;     /* mirror characters */
    UInt16          unused:2;       /* unused */
    UInt16          linewidth:1;    /* lines with width */
    UInt16          fenceclip:1;    /* fence clip mode */
    UInt16          gglk:1;         /* graphic group lock */
    UInt16          levellk:1;      /* level lock */
    UInt16          reserved:3;     /* reserved for future use */
    UInt16          overlap:1;      /* overlap or inside fence lock */
    } Fbfdcn;                       /* fb/fd control word */

typedef struct
    {
    UInt32          dragen:1;
    UInt32          dragact:1;
    UInt32          unused:1;
    UInt32          allowuc:1;
    UInt32          noele:1;
    UInt32          inflin:1;
    UInt32          noout:1;
    UInt32          unused2:1;
    UInt32          prompt_uc:1;        /* prompt even though in UC */
    UInt32          uc_messages:1;      /* use user cmd msg field */
    UInt32          inhibit_parse:1;    /* inhibit T,E and keyin parse */
    UInt32          spare:21;
    } Outflg;

typedef struct      dCompFlags
    {
    UInt32          sheetViews:1;
    UInt32          hiddenLine:1;
    UInt32          displayHidden:1;
    UInt32          attachNested:1;
    UInt32          storeCompletePath:1;
    UInt32          incrementalHLine:1;
    UInt32          unused:26;
    } DCompFlags;

typedef struct      dCompSettings
    {
    double          marginPercent;
    double          modelScale;
    double          sheetScale;
    DCompFlags      flags;
    Int16           refMerge;
    Int16           viewAnnotationLevel;
    Int16           sheetAnnotationLevel;
    Int16           modelLevels[4];
    } DCompSettings;

typedef struct      smartGeomSettings
    {
    Int32           nIsoparametrics;
    struct
        {
        UInt32  representAsSurfaces:1;
        UInt32  unused:31;
        } flags;
    } SmartGeomSettings;

typedef struct      transformFlags
    {
    UInt16          ignoreScaleForDimValues:1;
    UInt16          ignoreScaleForAnnotations:1;
    UInt16          unused:14;
    } TransformFlags;

typedef struct
    {
    short           len;
    char            c[42];
    } Ucm_register;

typedef struct      aux_tool_flags
    {
    UInt16          aux_rotation_viewInd:1;
    UInt16          aux_rotation_absolute:1;
    UInt16          aux_apply_all_views:1;
    UInt16          aux_settings_reserved:13;
    } AuxToolFlags;

/*----------------------------------------------------------------------+
|                                                                       |
|   Hidden Line Removal Settings                                        |
|                                                                       |
+----------------------------------------------------------------------*/
#define DRAWCOMP_REFMERGE_HiddenLine            2

#define EDGES_METHOD_MicroStation               0
#define EDGES_METHOD_Modeler                    1
#define EDGES_METHOD_RasterHybrid               2

#define EDGES_ANNOTATION_Hide                   0
#define EDGES_ANNOTATION_Always                 1
#define EDGES_ANNOTATION_Never                  2

#define EDGES_ExactAccuracy_Low                 1000
#define EDGES_ExactAccuracy_Medium              2000
#define EDGES_ExactAccuracy_High                10000
#define MDLHVIEW_DEFAULT_ZBUFFER_RESOLUTION     1000
#define MDLHVIEW_DEFAULT_WORKING_MEMORY         4096

typedef struct  hLineFlags
    {
    UInt32          includeHidden:1;
    UInt32          includeRules:1;
    UInt32          calculateIntersections:1;
    UInt32          outputToMaster:1;
    UInt32          threeD:1;
    UInt32          boundary:3;
    UInt32          masterHiddenLine:1;
    UInt32          masterDisplayHidden:1;
    UInt32          method:3;
    UInt32          annotations:3;
    UInt32          smoothEdges:1;
    UInt32          expandCustomLinestyles:1;
    UInt32          expandHatch:1;
    UInt32          autoOpenOutputFile:1;
    UInt32          facetAllSurfaces:1;
    UInt32          colorFromMaterial:1;
    UInt32          ignoreTransparency:1; 
    UInt32          transparencyThreshold:7;
    UInt32          exactMode:1;
    UInt32          plotExactMode:1;
    } HLineFlags;

typedef struct      hLineSettings
    {
    HLineFlags      flags;
    HLineSymbology  visible;
    HLineSymbology  hidden;
    UInt32          zbResolution;
    UInt32          zbWorkingMemory;
    UInt32          reserved;
    } HLineSettings;

typedef struct      activeCellSettings
    {
    UInt16          isAnnotation:1;
    UInt16          reserved:15;
    } ActiveCellSettings;

typedef struct      dirFormat
    {
    UInt16          mode;
    UInt16          unused[2];
    struct
        {
        UInt16  clockwise:1;
        UInt16  unused:15;
        } flags;
    double          baseDir;
    } DirFormat;

typedef byte DrawingScaleName[32];

#if !defined (resource)

/*----------------------------------------------------------------------+
|                                                                       |
|   This structure defines the portion of the TCB which is stored in    |
|   the design file.                                                    |
|                                                                       |
+----------------------------------------------------------------------*/
typedef struct tcbTag
    {
    UInt32          majorVersion;               /* major version number                     */
    UInt32          minorVersion;               /* minor version number                     */
    Cntrlwd         control;                    /* control word                             */
    Cntrl1          cntrl1;                     /* miscellaneous control flags              */
    Fbfdcn          fbfdcn;                     /* fb/fd control word                       */
    Ext_locks       ext_locks;                  /* extended locks                           */
    Ext_locks2      ext_locks2;                 /* additional locks           */
    double          rndunit_deprecated;         /* deprecated - do not use    */
    UInt32          uorgrid_deprecated;         /* deprecated - do not use    */
    UInt32          refgrid_deprecated;         /* deprecated - do not use    */
    double          grid_ratio_deprecated;      /* deprecated - do not use    */
    double          uorpermast_deprecated;      /* deprecated - do not use    */
    double          actangle;                   /* active angle                             */
    double          anglernd;                   /* angle round-off                          */
    double          xactscle;                   /* active scale in x-axis                   */
    double          yactscle;                   /* active scale in y-axis                   */
    double          zactscle;                   /* active scale in z-axis                   */
    double          rndscle;                    /* scale lock roundoff value                */
    double          azimuth_deprecated;         /* deprecated - do not use                  */
    double          reservedGeneral[4];         /* deprecated - do not use                  */

    DPoint3d        low;                        /* range - lo                               */
    DPoint3d        high;                       /* range - high                             */

    LevelID         activeLevel;                /* active level                             */
    Symbology       symbology;                  /* element symbology word                   */
    UInt32          fillColor;                  /* Color for filled elements */
    Int16           props;                      /* element properties word                  */
    TransformFlags  transformFlags;             /* Flags used by transform tools            */
    LineStyleInfo   lineStyle;                  /* Active line style info                   */
    double          lineStyleScale_deprecated;  /* deprecated - do not use */
    MlineTcbFlags   mlineFlags;                 /* Multiline flags */
    Int16           reservedSymb16;             /* deprecated - do not use   */
    Int32           reservedSymb32;             /* deprecated - do not use   */
    double          reservedSymbology[3];       /* deprecated - do not use   */

    TextStyle       textStyle_deprecated;       /* deprecated - do not use                  */
    UInt32          textStyleID_deprecated;     /* deprecated - do not use                  */
    UInt16          textScaleLock;              /* lock for text scale                      */
    UInt16          reservedTextShort;          /* deprecated - do not use */
    UInt32          reservedTextLong[2];        /* deprecated - do not use */
    double          reservedText[4];            /* deprecated - do not use */

    ElementID       activeViewGroup;            /* active view group id or zero (0) for none */
    ModelID         activeModel;                /* current active model                     */
    UInt16          anglefmt;                   /* angle readout format                     */
    UInt16          angleReadoutPrec;           /* control angle-to-string conversion. */
    UInt16          tentmode;                   /* tentative point mode flag                */
    UInt16          tentsubmode_deprecated;     /* replaced by directionFormat              */
    UInt16          keypnt_divd;                /* divisor for keypoint snapping */
    UInt16          defaultSnapMode;            /* default mode for snapping */
    UInt16          sysclass;                   /* system class bit map                     */
    byte            dmrsflg;                    /* deprecated - do not use                  */
    byte            reserveByte;                // deprecated - do not use
    Int16           linkgen;                    /* deprecated - do not use                  */
    UInt16          obsolete_tutvw;             /* deprecated - do not use                  */

    Autodim1        ad1;                        /* automatic dimensioning flags             */
    UInt16          assocLockMask;              /* elements to make associations for        */
    UInt16          reservedDimShort[2];        /* reserved for future dimension settings   */
    double          reservedDim[14];            /* reserved for future dimension settings   */
    DirFormat       directionFormat;            /* formatting of direction strings */

    MSWChar         activeCell[MAX_CELLNAME_LENGTH];        /* active cell                  */
    MSWChar         activeTermCell[MAX_CELLNAME_LENGTH];    /* active line terminator cell name, if cell */
    double          actterm_scale;                          /* active line terminator scale */
    MSWChar         activePatternCell[MAX_CELLNAME_LENGTH]; /* active patterning cell       */
    double          actpat_scale;               /* active patterning scale                  */
    double          actpat_angle;               /* active patterning angle                  */
    double          actpat_angle2;              /* second pattern angle (for x-hatch) */
    double          actpat_rowspc;              /* active patterning row spacing */
    double          actpat_colspc;              /* active patterning column spacing */
    double          patternTolerance;           /* Stroke tol for patterns (uors) */
    Int32           activePointType;                        /* active point type. 0 = none, 1 = symbol, 2 = cell */
    UInt16          activePointSymbol;                      /* active point character, if symbol */
    MSWChar         activePointCell[MAX_CELLNAME_LENGTH];   /* active point cell name */
    ActiveCellSettings activeCellSettings;      /* active cell settings (UInt16) */
    double          areapat_angle;              /* active area patterning angle */
    double          areapat_rowspc;             /* active area patterning row spacing */
    double          areapat_colspc;             /* active area patterning column spacing */
    double          reservedCell;               /* reserved for future cell settings */

    Transform       digtrans;
    double          zRange2dLow;                /* set Z range of 2d elements to this value */
    double          zRange2dHigh;               /* set Z range of 3d elements to this value */
    double          streamDelta;                /* stream delta */
    double          streamTol;                  /* stream tolerance */
    double          angleTol;                   /* angle threshold (radians) */
    double          areaTol;                    /* area threshold (uors **2 ) */
    UInt32          digTransformSet;            /* digitizing transform has been set for this file */
    UInt32          reservedDigInt;             /* reserved for future integer digitizing setting */
    double          reservedDig[2];             /* reserved for future digitizing settings */

    UInt32          hiliteColor;                /* hilite color */
    UInt32          xorColor;                   /* xor color */

    double          axlock_angle;
    double          axlock_origin;

    /* ---------- default (last entered) values for commands that require input ----------- */
    double          chamfer_dist1;
    double          chamfer_dist2;
    double          autochain_tolerance;
    double          consline_distance;
    double          arc_radius;                 /* for circles and arcs */
    double          arc_length;
    double          cone_radius1;               /* used for cones only */
    double          cone_radius2;
    double          polygon_radius;
    double          surrev_angle;
    double          extend_distance;
    double          fillet_radius;
    double          coppar_distance;
    double          array_row_distance;
    double          array_column_distance;
    double          array_fillangle;
    double          point_distance;
    Int16           polygon_edges;
    Int16           points_between;
    Int16           array_numitems;
    Int16           array_numrows;
    Int16           array_numcols;
    byte            array_rotate;

    byte            bspline_order;
    byte            disp_attr_type;             /* displayable attribute type # */
    byte            aux_coord_def;              /* type of aux coord being def'd */
    AuxToolFlags    aux_tool_flags;             // deprecated - do not use
    DPoint3d        auxOrigin_deprecated;       // deprecated - do not use
    RotMatrix       auxMatrix_deprecated;       // deprecated - do not use
    double          reservedMisc[16];           // deprecated - do not use

    /* rendering information saved to file */
    RenderFlags     renderFlags;
    Latitude        latitude;
    Longitude       longitude;
    SolarTime       solarTime;
    UInt32          solarYear;                  /* Year for solar light calculations */
    double          gmtOffset;                  /* Offset to greenwich mean time */
    DPoint3d        solarDirection;
    DPoint3d        solarVectorOverride;        /* solar direction vector override */
    RGBFactor       solarIntensity;
    double          solarIntensityScale;        /* Scale for solar intensity */
    RGBFactor       ambientIntensity;
    double          ambientIntensityScale;      /* Scale for ambient intensity */
    RGBFactor       flashIntensity;
    double          flashIntensityScale;        /* Scale for for flash intensity */

    /* Render Settings Part Two */
    double          nearDepthDensity;           /* Degree of distance cueing at near clip plane */
    double          farDepthDensity;            /* Degree of distance cueing at far clip plane */
    double          nearDepthDistance;          /* Distance to begin distance cueing */
    RGBFactor       hazeColor;                  /* Color of fog */
    double          shadowTolerance;
    double          strokeTolerance;

    Int16           maxPolygonSize;
    Int16           arcMinimum;

    Int32           exactHLineAccuracy;
    double          exactHLineTolerance;        /* Tolerance for exact hidden line removal */
    double          reserveRender[20];          /* doubles reserved for rendering parameters */

    UInt32          selectionHiliteOverride;    /* FALSE means use hilite color... */
    UInt32          selectionHiliteColor;       /* ...otherwise use this.          */

    char            celfilenm[MAXFILELENGTH];   /* cell library name */
    char            backgroundFile[MAXFILELENGTH];

    MSToolSettings      msToolSettings;
    MS3DToolSettings    ms3DToolSettings;
    HLineSettings       hiddenLine;
    SmartGeomSettings   smartGeomSettings;      /* Smart Geometry Settings */
    DrawingScaleName    msDrawingScaleName;
    UInt32              plotAutoInvertColor;    /* Index of color which will be auto. switched from white to black for plot */
    UInt32              plotReservedUInt32;     /* reserved for plot */
    ElementID           mainDictionaryId;       /* ID Of main dictionary */
    HLineSymbology      hlineSmooth;            /* Smooth edge settings for hidden line */

    char                defaultFontType_deprecated;        // deprecated - do not use
    char                defaultFontName_deprecated[63];    // deprecated - do not use

    UInt32              gridOrientation;        /* Grid Orientation */
    UInt32              invisGeomDisplayMode;   /* 0=display by element, 1=always display, 2=never display */
    UInt16              designCenterUnits;      /* AutoCAD Design Center Unit setting (0 == unspecified) */
    UInt16              reservedSetting16;      /* reserved for settings */
    DRange3d            userDefinedLimits;      /* user defined design plane limits */
    UInt32              activeColorRGB;         /* RGB portion of active color */
    UInt32              activeFillColorRGB;      /* RGB portion of active fill color */
    double              longitudeSecondsFraction; // Additional precision for (integer) longitude seconds.
    double              latitudeSecondsFraction;  // Additional precision for (integer) latitude seconds.
    double              reservedSettings[68];   /* reserved for settings */

    /*--------- FROM HERE ON, NOT SAVED IN FILE -------------*/
    byte            firstNonPersistentMember;   /* just in here so that we can tell the persistent size */


    /*--------- these are stored in the design file header so that they don't have to wait for a "save settings"  ----- */
    UInt32          graphic;                    /* next graphics group number               */
    UInt32          canode;                     /* next node number                         */

    DCompSettings   drawingComposition;

    UInt32          fenceAllocated;             /* number of fence points allocated  -  new for V8 */
    UInt32          fence;                      /* number of fence points */
    DPoint2d        *fenpts;                    /* fence points */
    ScanRange       fenceRange;                 /* fence range (x,y,z lo-hi range) */
    Int16           fenvw;                      /* view number containing fence */

    /*--------- Set up on startup -------------*/
    Int16           dctchs;                     /* type (15=MicroStation, 16=Review, 17=Draft) */
    Int16           ustn_version;               /* MicroStation version */
    Int16           platform;                   /* so UC's can tell what platform */
    byte            numScreens;

    /*--------- Set up on entry to each design file --------- */
    Int16           ndices;                     /* deprecated - do not use */
    Int32           graphicsFileType;
    char            graphicsFileName[MAXFILELENGTH];
    char            dgnfilenm[MAXFILELENGTH];   /* design file name */
    Int32           unused;                     /* deprecated - do not use*/

    /*--------- derived from user preferences ------------ */
    Int16           dittol;                     /* locate tolerance */
    double          arcTolerance;
    Int16           arcVectors;
    Int16           deprecated_1;               /* deprecated - do not use */
    Int16           max_grdpnts;
    Int16           max_grdrefs;
    Int16           deprecated_2;               // deprecated - do not use
    byte            EDFieldChar;                /* enter data field character */

    /*--------- derived from configuration variable ------------ */
    Int16           workmode;                   /* how DGN is created (DGN, DWG, etc)       */

    /*--------- State information set by various commands and operations ----------- */
    Int16           acorgf;                     /* add cell origin flag */
    DPoint3d        celor;                      /* add cell origin */

    DgnFileObjP     activeCellLibObj;           /* library where active cell found */
    DgnFileObjP     activeTermLibObj;           /* library where active terminator found */
    DgnFileObjP     activePointLibObj;          /* library where active point cell found */
    DgnFileObjP     activePatternLibObj;        /* library where active pattern cell found */

    Outflg          outflg;

    double          smobuf[9];                  /* floating point scratch area */
    double          tmatrx[9];                  /* view transformation matrix */

    DPoint3d        lstpnt;                     /* last data point entered */
    Int16           lstvw;                      /* view for last point */

    Int16           tpnpts;                     /* number of tentative points in table */
    DPoint3d        tptabl[2];                  /* tentative point table */
    Int16           tptvw[2];                   /* views for tentative points in table */
    Int16           tagdel;                     /* tag increment binary delta */
    Int16           relerr;                     /* error number for last command */
    UInt32          cugraf;                     // deprecated - do not use

    /* ----------- Database state information ------------ */
    Int16           formsMode;                  /* database screen forms mode */
    Int16           confirmMode;                /* database multi-row confirmation */
    UInt32          lastMslink;                 /* last mslink number added to database */
    UInt16          ae;                         /* active entity database */
    UInt32          mslink;                     /* MSLINK key field of ae record */
    char            *db_cntrl;                  /* database descriptors */
    UInt32          record;                     /* basis for ae, last record written */
    char            schema[MAXFILELENGTH];      /* database master control file */

    Int32           msgkey;                     /* indfpi message key for fb_only */
    Int16           window_mode;                /* saves funcname in window command */
    byte            currentScreen;

    struct
        {
        double  reference;
        double  master;
        double  rescaleFactor;
        } refScale;

    DPoint3d        refAngle;

    byte            streamAccept;               /* show acceptance criteria for stream */
    byte            enableMultiLevels;          /* enable multiple level checks */
    byte            inDynamics;                 /* we are in dynamics */

    UInt16          assemblyAssocType;
    byte            rasterRefFlags;             /* raster ref bitflags (see rastref.h) */

    /* -------------- information about the currently parsed command ----------------- */
    Int32               last_parsed_command;
    Int32               current_command;
    Int16               last_parsed_class;
    Int16               command_class;
    Int16               last_parsed_source;
    Int16               command_source;

    Int32               ucmget_command;         /* command number (in GET statement) */
    Int16               ucmget_class;           /* command class (in GET statement) */
    Int16               ucmget_source;          /* command source (in GET statement) */

    /* --------------- stuff having to do with hilighting, snapping, and locating -------------- */
    Int16               propmsk;                /* properties mask */
    Int16               propval;                /* properties value */
    Int16               noLocked;               /* nonzero means don't allow selection of locked elements */

    UInt16              searchType[8];          /* element locate type mask */
    DgnModelRefListP    searchModelList;        /* model locate list */

    BoolInt             restartLocate;          // TRUE = continue last search, FALSE = start new search.
    Int32               snapOverride;           /* current snap override */
    double              snapTolerance;          /* tolerance for snap/locate, world coordinate representation
                                                   of locate circle */

    ModelRefIteratorP   fenceLocateIterator;    /* used for fence_locate command */

    /* ----------- Rendering information not saved to file -------- */
    Int16           stereoSeparation;
    Int16           filledEdgeColor;            /* Filled edge color (-1 = no edges) */
    double          renderVectorShift;          /* moves rendered vectors to eye */

    /* ----------- User command data -------- */
    short           uc_r[32];   /* R0, R1, ... R31 */
    short           uc_err;     /* ERR */
    short           uc_num;     /* NUM */
    long            uc_i[16];   /* I0, I1, ... I15 */
    short           uc_xdt;     /* XDT */
    short           uc_ydt;     /* YDT */
    double          uc_xur;     /* XUR */
    double          uc_yur;     /* YUR */
    double          uc_zur;     /* ZUR */
    short           uc_vno;     /* VNO */
    double          uc_a[16];   /* A0, A1, ... A15 */
    Ucm_register    uc_c[18];   /* C0, C1, ... C15, KEY, MSG */
    short           uc_fno;     /* FNO */
    short           ucdata[16]; /* user command data                    705 */
    short           angbyt;     /* # of bytes in orientation (8 or 32) */
    short           trabyt;     /* cell xform matrix (32 or 72) */
    short           pntbyt;     /* bytes in a point (16 or 24) */
    DPoint3d        iuor[4];    /* scratch */
    } Tcb;
#endif /* !defined (resource) */

END_EXTERN_C
