home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 213b.lha / XCad_DBase_Format / XCAD_DBFORMAT < prev    next >
Text File  |  1996-02-14  |  58KB  |  1,891 lines

  1.  
  2.  
  3. X-CAD Database format
  4. =====================
  5.  
  6. The  following  document describes the X-CAD database format as used in the.
  7. xdr files created by X-CAD versions 1.3  and  1.4  and  X-SKETCH.  The  file
  8. consists  of  a header followed by two or more blocks describing each entity
  9. or object held in the database.  
  10.  
  11. The block descriptions that follow use the  C  language  structure  type  to
  12. define  each element belonging to a block. The space considerations for each
  13. element type are:  
  14.  
  15.    byte     One 8 bit byte.
  16.    short    Two byte integer.
  17.    long     Four byte integer.
  18.    float    Four byte floating point number.
  19.    double   Eight byte floating point number.
  20.  
  21.  
  22. File Header
  23. ===========
  24.  
  25. The file header consists of 5 data elements describing  the  type,  revision
  26. and size of the. xdr file.  
  27.  
  28.    struct HEADER
  29.       {
  30.       long  ID;
  31.       short REV;
  32.       long  ENTS;
  33.       long  MEMREQ;
  34.       short FLAGS;
  35.       }
  36.  
  37. ID       This is the file identifier - a 4 byte code that must be equal to
  38.          the string "ACDR".
  39.  
  40. REV      The drawing file revision number.
  41.  
  42. ENTS     The number of entity blocks that follow this header block.
  43.  
  44. MEMREQ   The total amount of data ( as a number of bytes ) in this file 
  45.          excluding the header block.
  46.  
  47. FLAGS    Bit encoded flags:  
  48.          Bit 0 on = This drawing file contains no graphics information 
  49.                     ( there are no GIBLOCKs or GBBLOCKS in this file ).
  50.          Bit 1 on = This drawing file contains a password. If this bit is
  51.                     set, then the header block is followed by 8 bytes
  52.                     containing a coded password. ( Currently unused ).
  53.  
  54.  
  55. Entity Blocks
  56. =============
  57.  
  58. Following the file header are two or more entity blocks. Each block contains
  59. the total description for an entity.  
  60.  
  61. Entity blocks are formatted as follows:
  62.  
  63.  
  64.    INDEX                      []  denotes optional
  65.    HIBLOCK                    (s) denotes block may be repeated
  66.    EHBLOCK
  67.    EDBLOCK(s)
  68.    [ GIBLOCK(s) ]
  69.    [ GBBLOCK(s) ]
  70.  
  71.  
  72. Entity Index
  73. ============
  74.  
  75. The entity index is a 2 byte unsigned  integer  containg  the  unique  index
  76. number of this entity. The index number is used as a reference throughout an
  77. X-CAD  drawing  file  and  database.  Entity  index  numbers  are  allocated
  78. according to the following criteria:  
  79.  
  80.    Index 1                 The drawing entity.
  81.  
  82.    Index 2                 The SHEET viewport.
  83.  
  84.    Index 3-33              Auxiliary viewports.
  85.  
  86.    Index 34-512            Attribute entities.
  87.  
  88.    Index 513-1024          Reserved.
  89.  
  90.    Index 1025-65535        Drawing entities.
  91.  
  92.  
  93. Entity HIBLOCK
  94. ==============
  95.  
  96. The  entity  HIBLOCK  is  a  data structure containing the basic information
  97. about this entity. An HIBLOCK always follows the entity index.  
  98.  
  99.    struct HIBLOCK
  100.       {
  101.       struct EHBLOCK *EHBLOCK;
  102.       short           FLAGS1;
  103.       short           FLAGS2;
  104.       struct GIBLOCK *GRAPHICS;
  105.       }
  106.  
  107. EHBLOCK     Used as a pointer to an EHBLOCK structure when the .xdr file is
  108.             loaded, but has no meaning within the .xdr file.
  109.  
  110. FLAGS1      Bit encoded word:
  111.             0-4      Entity type
  112.             5        Transient bit used by redraw routines
  113.             6        On if entity is visible
  114.             7        On if entity identified by IDENTS
  115.             8-15     Entity layer
  116.  
  117. FLAGS2      Bit encoded word:
  118.             0-4      Viewport number ( +2 = index number of viewport entity )
  119.             5-8      Entity depth
  120.             9        Non-delete flag
  121.             10       On if entity is tagged by IDENTS
  122.             11       On if entity is highlighted
  123.             12       On if entity is currently displayed
  124.             13-14    Transient bits used by symbols
  125.             15       Transient bit used for family tracing  
  126.  
  127. GRAPHICS    Used internally as a pointer to the first GIBLOCK for this
  128.             entity. If GRAPHICS is non-zero, then a GIBLOCK will follow
  129.             on after the last EDBLOCK. If GRAPHICS is zero then there are
  130.             no GIBLOCKs present.
  131.  
  132.             This element should be ignore if bit 0 is set in the FLAGS
  133.             element of the file header. 
  134.  
  135.  
  136. Entity EHBLOCK
  137. ==============
  138.  
  139. The entity EHBLOCK is a data  structure  containing  additional  information
  140. about each entity. An EHBLOCK always follows the HIBLOCK.  
  141.  
  142.    struct EHBLOCK
  143.       {
  144.       struct EDBLOCK *FIRST;
  145.       short           FLAGS;
  146.       short           AWORD1;
  147.       short           AWORD2;
  148.       short           AWORD3;
  149.       }
  150.  
  151. FIRST       Used internally as a pointer to the first EDBLOCK that follows
  152.             this EHBLOCK. If FIRST is non-zero, then one or more EDBLOCKs
  153.             follow. If FIRST is zero, there are no EDBLOCKs present.
  154.  
  155. FLAGS       Unused.
  156.  
  157. AWORD1/2/3  Three 2 byte words available internally to any application.
  158.  
  159.  
  160. Entity EDBLOCK
  161. ==============
  162.  
  163. An  entity  EDBLOCK  is  a  structure containing a block of data or a set of
  164. parameters relevent to the entity. Each  entity  can  contain  one  or  more
  165. EDBLOCKs that make up the database description of the entity.  
  166.  
  167.    struct EDBLOCK
  168.       {
  169.       struct EDBLOCK *NEXT;
  170.       unsigned char  *BLOCKID;
  171.       unsigned char  *SUBID;
  172.       long            LENGTH;
  173.       }
  174.    DATA
  175.  
  176. NEXT        Used internally as a pointer to the next EDBLOCK. If NEXT is
  177.             non-zero then another EDBLOCK follows on from this one. If
  178.             NEXT is zero then there are no more EDBLOCKs present.
  179.  
  180. BLOCKID     The data block identifier used to determine the type of data
  181.             found after the EDBLOCK.
  182.    
  183. SUBID       The data block sub-identifier.
  184.  
  185. LENGTH      The length of the data block in bytes ( always an even number ).
  186.  
  187. DATA        The actual data. The format of this is dependent on the 
  188.             BLOCKID and SUBID.
  189.  
  190.  
  191. Entity GIBLOCK
  192. ==============
  193.  
  194. The  entity  GIBLOCK  data  structure contains information about the display
  195. list data associated with this entity. GIBLOCKs  are  only  present  if  the
  196. GRAPHICS  element  is non-zero in the entity HIBLOCK, and only then if bit 0
  197. in the FLAGS element of the file header is not set.  
  198.  
  199.    struct GIBLOCK
  200.       {
  201.       struct GIBLOCK *NEXT;
  202.       unsigned char  *LAYOFF;
  203.       unsigned char  *DEPOFF;
  204.       struct GBBLOCK *FIRST;
  205.       }
  206.  
  207. NEXT        Used internally as a pointer to the next GIBLOCK. If NEXT is
  208.             non-zero, then another GIBLOCK follows on after any GBBLOCKs
  209.             associated with this GIBLOCK. If NEXT is zero there are no more
  210.             GIBLOCKs present.
  211.  
  212. LAYOFF      Contains a layer offset to apply to all display list data
  213.             associated with this GIBLOCK. ie the actual layer is
  214.             ( entity layer + LAYOFF ) mod 256 .
  215.  
  216. DEPOFF      Contains a depth offset to apply to all display list data
  217.             associated with this GIBLOCK. ie the actual depth is
  218.             ( entity depth + DEPOFF ) mod 8 .
  219.  
  220. FIRST       Used internally as a pointer to the first GBBLOCK associated
  221.             with this GIBLOCK. Any GBBLOCKs associated with a GIBLOCK
  222.             follow before the next GIBLOCK in the list. If FIRST is non-
  223.             zero a GBBLOCK follows. If FIRST is zero, there are no 
  224.             GBBLOCKs associated with this GIBLOCK.
  225.  
  226.  
  227. Entity GBBLOCK
  228. ==============
  229.  
  230. The entity GBBLOCK contains display  list  data  associated  with  the  last
  231. GIBLOCK.  Display  list data is in the form of a vector list describing what
  232. is actually shown on the screen.  
  233.  
  234.    struct GBBLOCK
  235.       {
  236.       struct GBBLOCK *NEXT;
  237.       unsigned char   TYPE;
  238.       unsigned char   FLAGS;
  239.       long            SIZE;
  240.       }
  241.    DATA
  242.  
  243. NEXT        Used internally as a pointer to the next GBBLOCK in this
  244.             list. If NEXT is non-zero another GBBLOCK follows this one.
  245.             If GBBLOCK is zero there are no more GBBLOCKs in this list.
  246.  
  247. TYPE        The display list data block type.
  248.  
  249.             =1 Stroke vector list
  250.             =2 Filled polygon vector list
  251.             =3 Filled line vector list
  252.             =4 Non-scaled symbol coordinate list
  253.  
  254. FLAGS       Unused.
  255.  
  256. SIZE        The size of the display list data block in bytes.
  257.  
  258. DATA        The display list data block. The contents of this data block are
  259.             dependent on the TYPE element. ( See section on GBBLOCK data ).
  260.  
  261.  
  262. Entity Types
  263. ============
  264.  
  265. Entity types are represented by a number between 0 and  31  encoded  in  the
  266. FLAGS1 element of the HIBLOCK. The entity types current used by X-CAD are as
  267. follows:  
  268.  
  269.    0     Drawing parameters entity
  270.    1     Viewport entity
  271.    2     Attribute entity
  272.    3     String entity
  273.    4     Arc entity
  274.    5     Ellipse entity
  275.    6     Construction point entity
  276.    7     Polygon entity
  277.    8     Line entity
  278.    9     Spline entity
  279.   10     Cross-hatch polygon entity
  280.   11     Text entity
  281.   12     Text-node entity
  282.   13     Dimension entity
  283.   14     Symbol entity
  284.   15     Terminal entity
  285.   16     Netline entity
  286.   17-31  Not allocated
  287.  
  288.  
  289. EDBLOCKS Associated with entity types
  290. =====================================
  291.  
  292. Each entity type must have one or more  EDBLOCKs  associated  with  it.  The
  293. following list shows which EDBLOCK types must be present to correctly define
  294. the entity in the X-CAD drawing database.  
  295.  
  296. Entity type:   0  Drawing parameters entity
  297.  
  298.    BLOCKID  2     Drawing parameters data.
  299.  
  300. Entity type:   1  Viewport entity
  301.  
  302.    BLOCKID  1     Viewport parameters.
  303.  
  304. Entity type:   2  Attribute entity
  305.  
  306.    BLOCKID  12    Text string - contains attribute name.
  307.    BLOCKID  13    Child member list - lists all entities with this
  308.                                       attribute.
  309.  
  310. Entity type:   3  String entity
  311.  
  312.    BLOCKID  3     Coordinate list.
  313.  
  314. Entity type:   4  Arc entity
  315.  
  316.    BLOCKID  3     Coordinate list - describes arc origin.
  317.    BLOCKID  5     Arc parameters.
  318.  
  319. Entity type:   5  Ellipse entity
  320.  
  321.    BLOCKID  3     Coordinate list - describes ellipse origin.
  322.    BLOCKID  6     Ellipse parameters.
  323.  
  324. Entity type:   6  Construction point entity
  325.  
  326.    BLOCKID  3     Coordinate list.
  327.  
  328. Entity type:   7  Polygon entity
  329.  
  330.    BLOCKID  3     Coordinate list - each boundary within the polygon entity
  331.                                     is described with a separate type 3
  332.                                     EDBLOCK.
  333.  
  334. Entity type:   8  Line entity
  335.  
  336.    BLOCKID  3     Coordinate list.
  337.  
  338. Entity type:   9  Spline entity
  339.  
  340.    BLOCKID  3     Coordinate list - describes spline control points.
  341.  
  342. Entity type:  10  Cross-hatch polygon entity
  343.  
  344.    BLOCKID  3     Coordinate list - each boundary within the polygon entity
  345.                                     is described with a separate type 3
  346.                                     EDBLOCK.
  347.    BLOCKID  8     Xhatch parameters.
  348.  
  349. Entity type:  11  Text entity
  350.  
  351.    BLOCKID  3     Coordinate list - represents origin of text.
  352.    BLOCKID  11    Text parameters.
  353.    BLOCKID  12    Text string.
  354.  
  355. Entity type:  12  Text-node entity
  356.  
  357.    BLOCKID  3     Coordinate list - represents origin of text-node.
  358.    BLOCKID  11    Text parameters.
  359.    BLOCKID  13    Child member list - lists index of related text entity.
  360.  
  361. Entity type:  13  Dimension entity
  362.  
  363.    BLOCKID  11    Text parameters.
  364.    BLOCKID  17    Dimension parameters.
  365.    BLOCKID  19    Dimension details.
  366.  
  367. Entity type:  14  Symbol entity
  368.  
  369.    BLOCKID  3     Coordinate list - represents symbol origin.
  370.    BLOCKID  12    Text string - symbol name.
  371.    BLOCKID  16    Symbol parameters.
  372.  
  373. Entity type:  15  Terminal entity.
  374.  
  375.    BLOCKID  3     Coordinate list - represents origin of terminal.
  376.    BLOCKID  21    Terminal type.
  377.  
  378. Entity type:  16  Netline entity.
  379.  
  380.    BLOCKID  3     Coordinate list.
  381.  
  382.  
  383. BLOCKID 1 Viewport Parameters
  384. =============================
  385.  
  386. Each viewport entity in a drawing must have associated with  it  a  Viewport
  387. parameters data structure.  
  388.  
  389.    struct ACViewPort
  390.       {
  391.       char   NAME[22];
  392.       double WIDTH; 
  393.       double HEIGHT;
  394.       short  UNITS;  
  395.       double XORG;  
  396.       double YORG;  
  397.       double SCL;   
  398.       short  XOFF;   
  399.       short  YOFF;   
  400.       short  XMAX;   
  401.       short  YMAX;   
  402.       short  CXMIN;  
  403.       short  CYMIN;  
  404.       short  CXMAX;  
  405.       short  CYMAX;    
  406.       short  VISIBLE;  
  407.       double SHXOFF;  
  408.       double SHYOFF;  
  409.       };
  410.  
  411. NAME     The viewport name as a null terminated character string. The name
  412.          can have a maximum of 20 characters.
  413.  
  414. WIDTH    The width of the viewport in viewport units.
  415.  
  416. HEIGHT   The height of the viewport in viewport units.
  417.  
  418. UNITS    The viewport units:  0 = Millimetres
  419.                               1 = Centimetres
  420.                               2 = Metres
  421.                               3 = Kilometres
  422.                               4 = Inches
  423.                               5 = Feet
  424.                               6 = Miles
  425.  
  426. XORG     X origin of the viewport in viewport units relative to the bottom
  427.          left corner of the viewport.
  428.  
  429. YORG     Y origin of the viewport in viewport units relative to the bottom
  430.          left corner of the viewport.
  431.  
  432. SCL      Scale to apply to viewport coordinates to transform to display
  433.          coordinate system. ( See section on coordinate systems ).
  434.  
  435. XOFF     X offset of viewport in display coordinate system.
  436.  
  437. YOFF     Y offset of viewport in display coordinate system.
  438.  
  439. XMAX     Width of viewport in display coordinate system.
  440.  
  441. YMAX     Height of viewport in display coordinate system.
  442.  
  443. CXMIN    Current minimum x clip for viewport in viewport coordinate system.
  444.          This value is relative to the viewport origin (0,0) at the top left
  445.          corner of the viewport.
  446.  
  447. CYMIN    Current minimum y clip for this viewport.
  448.  
  449. CXMAX    Current maximum x clip for this viewport.
  450.  
  451. CYMAX    Current maximum y clip for this viewport.
  452.  
  453. VISIBLE  Viewport open/close flag. 1 = open, 0 = closed.
  454.  
  455. SHXOFF   X coordinate of the viewport origin ( bottom left corner ) in the
  456.          sheet viewport ( viewport 0 ) coordinates.
  457.  
  458. SHYOFF   Y coordinate of the viewport origin in sheet viewport coordinates.
  459.  
  460.  
  461. BLOCKID 2 Drawing Parameter Data
  462. ================================
  463.  
  464. Each  X-CAD  drawing  has  a  drawing parameters entity. Associated with the
  465. drawing parameters entity is a number of drawing parameters data blocks. The
  466. SUBID of each type 2 BLOCKID defines the type of data found.  
  467.  
  468. A SUBID of 1 defines a layer name data structure:
  469.  
  470.    struct LayerName
  471.       {
  472.       char  NAME[16];
  473.       short LAYER;  
  474.       };
  475.  
  476. NAME     The layer name. A maximum 14 character null terminated text string.
  477.  
  478. LAYER    The actual layer number associated with the layer name.
  479.  
  480. A SUBID of 2 defines a layer list data structure:
  481.  
  482.    struct LayerList  
  483.       {
  484.       char  NAME[16];
  485.       short LAYLIST[16];
  486.       };
  487.  
  488. NAME     The layer name. A maximum 14 character null terminated text string.
  489.  
  490. LAYLIST  A visibility mask for all 255 layers associated with this named
  491.          layer list. Word 1 defines visibility for layers 0-15, word 2 for
  492.          layers 16-32 etc. Each bit on within the word specifies that layer
  493.          is visible.
  494.  
  495. A  SUBID  of 4 defines the current layer colour assignments for the drawing.
  496. The data that follows is 256 bytes each of which use the  first  7  bits  to
  497. define the assigned layer colour. The first byte corresponds to layer 0, the
  498. second byte to layer 1 etc.  
  499.  
  500. A SUBID of 5 defines an image data structure associated with this drawing:
  501.  
  502.    struct ZoomImage
  503.       {
  504.       char  NAME[10];
  505.       short XMIN;
  506.       short YMIN;
  507.       short XMAX;
  508.       short YMAX;
  509.       };
  510.  
  511. NAME     The image name. A maximum 8 character null terminated text string.
  512.  
  513. XMIN     Minimum x clip of window in display coordinate system for sheet
  514.          viewport.
  515.  
  516. YMIN     Minimum y clip of window.
  517.  
  518. XMAX     Maximum x clip of window.
  519.  
  520. YMAX     Maximum y clip of window.
  521.  
  522. A SUBID of 6 defines the colours currectly selected for this drawing. 9  two
  523. byte  integers  follow  this EDBLOCK. The first 8 words define each of the 8
  524. visible colours, the last word defines the colour of the cursor.  Each  word
  525. defines a colour as a combination of 3 nibbles describing the RGB components
  526. of the colour:  
  527.  
  528.    Bits 0-3  blue
  529.    Bits 4-7  green
  530.    Bits 8-11 red
  531.  
  532. A SUBID of 7 defines  the  currently  selected  symbol  directory  for  this
  533. drawing.  The  data  that  follows  is  a  null  terminated character string
  534. containing the directory name.  
  535.  
  536. A SUBID of 8 defines the currently selected patternfill  datafile  for  this
  537. drawing.  The  data  that  follows  is  a  null  terminated character string
  538. containing the patternfill datafile name.  
  539.  
  540. A SUBID of 9 defines the  currently  selected  softfont  datafile  for  this
  541. drawing.  The  data  that  follows  is  a  null  terminated character string
  542. containing the softfont datafile name.  
  543.  
  544.  
  545. BLOCKID 3 Coordinate List
  546. =========================
  547.  
  548. Most entity types within an X-CAD drawing have a type 3  BLOCKID.  The  data
  549. following  this type of EDBLOCK is aways one or sets of xy coordinates. Each
  550. set of xy coordinate points is represented  by  2  doubles.  The  coordinate
  551. points are always relative to the entities viewport.  
  552.  
  553. Most  type  3  BLOCKIDs  have  a SUBID of 0 denoting no special meaning. The
  554. meaning of other SUBIDs are as follows.  
  555.  
  556. A SUBID of 2 occurs on polygon and cross-hatch polygon entities.  This  type
  557. of entity can have one or more type 3 BLOCKIDs, one for each boundary of the
  558. polygon. A SUBID of 2 defines the outer or first  boundary.  A  SUBID  of  3
  559. defines any inner or subsequent boundaries.  
  560.  
  561. A  SUBID  of 4 occurs only on spline entities. This means that the spline is
  562. closed, ie it runs smoothly through the first and last control points.  
  563.  
  564.  
  565. BLOCKID 4 Font Parameters
  566. =========================
  567.  
  568. A type 4 BLOCKID can occur on most entities as it defines the appearance  or
  569. font  of  the  entity. The type of data structure used to define the font is
  570. dependent on the SUBID of the EDBLOCK.  
  571.  
  572. A SUBID of 1 defines a hardfont data structure:
  573.  
  574.    struct HardFont
  575.       {
  576.       char THICK;
  577.       char STYLE;
  578.       };
  579.  
  580. THICK    Line thickness as a value between 1-5.
  581.  
  582. STYLE    Line style as a value between 0-15.
  583.  
  584. If this SUBID is found on a  type  4  BLOCKID  associated  with  a  viewport
  585. entity,  it  defines the default hardfont for the text parameters associated
  586. with this viewport.  
  587.  
  588. A SUBID of 2 defines a named softfont data structure:
  589.  
  590.    struct NamedSoftFont
  591.       {
  592.       char  NAME[16];
  593.       float SCALE;
  594.       };
  595.  
  596. NAME     The softfont name. A maximum 15 character null terminated character
  597.          string containing the softfont name.
  598.  
  599. SCALE    Scale to apply to the font width etc.
  600.  
  601. A SUBID of 3 defines a local softfont data structure:
  602.  
  603.    struct SoftFont
  604.       {
  605.       char  TYPE;
  606.       char  UNITS;
  607.       char  NAME[16];
  608.       char  FLAGS;
  609.       char  COLOUR;
  610.       char  PATNAME[12];
  611.       short HARDSTYLE;
  612.       float WIDTH;
  613.       short DASH_DOT;
  614.       float SP[16];
  615.       };
  616.  
  617. TYPE     Bit flag containing information about font type:
  618.          
  619.          Bit 0 On indicates local font ( used internally ).
  620.              1 On indicates named font ( used internally ).
  621.              2 On indicates fixed scale font, units stored in UNITS.
  622.              3 On indicates patterfilled font.
  623.  
  624. UNITS    The units type of the viewport used to define the font. Units values
  625.          are as in the Viewport Parameters data structure.
  626.  
  627. NAME     The name of the font if TYPE bit 1 is set. ( Used internally ).
  628.  
  629. FLAGS    Bit flag containing additional information about font.
  630.  
  631.          Bit 0 On indicates font has a width.
  632.              1 On indicates font width is left justified.
  633.              2 On indicates font width is right justified.
  634.              3 On indicates width font is open-ended.
  635.              4 On indicates width font has extended ends.
  636.              5 On indicates width font is filled.
  637.              6 On indicates width font is filled with an absolute colour.
  638.              7 On indicates width font has an outline in the layer
  639.                assigned colour.
  640.  
  641. COLOUR   Fill colour if FLAGS bit 6 is set.
  642.  
  643. PATNAME  Patternfill name if TYPE bit 3 is set.
  644.  
  645. WIDTH    Width of the font in UNITS if TYPE bit 1 is set else viewport
  646.          units.
  647.  
  648. DASH_DOT The number of dash/space values in SP. 
  649.  
  650. SP       A list of dash/space pairs for the font in UNITS if TYPE bit 1 is
  651.          set else viewport units.
  652.  
  653. A SUBID of 4 indicates a polygon fill data structure. This SUBID only occurs
  654. on polygon entities.  
  655.  
  656. struct PolyFont 
  657.    {
  658.    char TYPE;
  659.    char DUM;
  660.    char FLAGS;
  661.    char COLOUR;
  662.    char PATNAME;
  663.    };
  664.  
  665. TYPE     Bit flag containing information about font type:
  666.          
  667.          Bit 3 On indicates patterfilled font.
  668.              4 On indicates background of single colour patternfilled
  669.                polygon is rendered in layer assigned colour.
  670.              5 On indicates shadow polygon.
  671.  
  672. DUM      Not used.
  673.  
  674. FLAGS    Bit flag containing additional information about font.
  675.  
  676.          Bit 1 On indicates patternfilled polygon has transparent
  677.                background.
  678.              2 On indicates single colour patternfilled polygon is used
  679.                as a mask.
  680.              3 On indicates colour filled polygon is halftoned.
  681.              5 On indicates polygon is filled.
  682.              6 On indicates polygon is filled with an absolute colour.
  683.              7 On indicates polygon has an outline in the layer assigned
  684.                colour.
  685.  
  686. COLOUR   Fill colour if FLAGS bit 6 is set.
  687.  
  688. PATNAME  Patternfill name if TYPE bit 3 is set.
  689.  
  690. A  SUBID  of 11 defines hardfont data in the same way as SUBID 1. This SUBID
  691. only occurs on viewport entities. It  defines  the  hardfont  used  for  the
  692. default dimension parameters for this viewport.  
  693.  
  694.  
  695. BLOCKID 5 Arc Parameters
  696. ========================
  697.  
  698. A type 5 EDBLOCK is followed by an arc parameters data structure:
  699.  
  700.    struct ArcParameters
  701.       {
  702.       double RADIUS;
  703.       double AGO;
  704.       double AEND;
  705.       };
  706.  
  707. RADIUS   The arc radius in viewport units.
  708.  
  709. AGO      The arc start angle in radians.
  710.  
  711. AEND     The arc end angle in radians.
  712.  
  713.  
  714. BLOCKID 6 Ellipse Parameters
  715. ============================
  716.  
  717. A type 6 EDBLOCK is followed by an ellipse parameters data structure:
  718.  
  719.    struct ElpParameters
  720.       {
  721.       double MAJOR;
  722.       double MINOR;
  723.       double INCL;
  724.       double AGO;
  725.       double AEND;
  726.       };
  727.  
  728. MAJOR    The ellipse major radius in viewport units.
  729.  
  730. MINOR    The ellipse minor radius in viewport units.
  731.  
  732. INCL     The ellipse inclination angle in radians.
  733.  
  734. AGO      The arc start angle in radians.
  735.  
  736. AEND     The arc end angle in radians.
  737.  
  738.  
  739. BLOCKID 8 Xhatch Parameters
  740. ===========================
  741.  
  742. A type 8 EDBLOCK is followed by an xhatch parameters data structure:
  743.  
  744.    struct XhParameters
  745.       {
  746.       double SPACING;
  747.       double ANGLE;
  748.       };
  749.  
  750. SPACING  Parallel distance of lines used for cross-hatch.
  751.  
  752. ANGLE    Angle of cross-hatch in radians.
  753.  
  754.  
  755. BLOCKID 11 Text Parameters
  756. ==========================
  757.  
  758. A type 11 EDBLOCK is followed by a text parameters data structure:
  759.  
  760.    struct TextParams
  761.       {
  762.       char  FONT[10];
  763.       float HEIGHT;
  764.       float WIDTH;
  765.       float ANGLE;
  766.       float CSPACE;
  767.       float SLANT;
  768.       char  JUST;
  769.       char  FLAGS;
  770.       float LNSP;
  771.       };
  772.  
  773. FONT     The text font name. A maximum 8 charater null terminated text
  774.          string.
  775.  
  776. HEIGHT   The height of the text in viewport units.
  777.  
  778. WIDTH    The width of the text in viewport units. The height and width used
  779.          are for the tile size of the letter. The width does not include the
  780.          space between letters, this is defined by the CSPACE variable.
  781.  
  782. ANGLE    The angle of the text in radians.
  783.  
  784. CSPACE   The text character spacing as a proportion of the width. ie, if
  785.          CSPACE is 1.3, the space between each letter is .3 times the 
  786.          letter width.
  787.  
  788. SLANT    The slant of the text in radians.
  789.  
  790. JUST     Text justification flag: -1 = left justified
  791.                                    0 = centre justified
  792.                                    1 = right justified
  793.  
  794. FLAGS    Bit encoded flag: Bit 0 On indicates uniform spacing
  795.                                0 Off indicates proportional spacing
  796.                                1 On indicates filled text
  797.  
  798. LNSP     Text line spacing as a proportion of the text height.
  799.  
  800. If this EDBLOCK is associated with a viewport entity, it defines the default
  801. text parameters associated with the viewport.  
  802.  
  803.  
  804. EDBLOCK 12 Text String
  805. ======================
  806.  
  807. A type 12 EDBLOCK is always followed by a null terminated character  string.
  808. This  is  generally  used as some sort of label, ie. a symbol name or string
  809. associated with a text entity.  
  810.  
  811.  
  812. EDBLOCK 13 Child Member List
  813. ============================
  814.  
  815. A type 13 EDBLOCK is followed by one or more 2 byte integers each  of  which
  816. are  the  index number of an entity. The entities in this list are all child
  817. members in the relationship for which this entity is the parent. Each of the
  818. child  members should have a parent member list containing the index of this
  819. entity.  
  820.  
  821. The SUBIDs used with a type 13  EDBLOCK  define  the  kind  of  relationship
  822. involved.  The  child  member  entities in a type 13 EDBLOCK with a specific
  823. SUBID must also contain a parent member list ( type 15 EDBLOCK  )  with  the
  824. same SUBID.  
  825.  
  826. A SUBID of 0 is found on an attribute entity. The child member list contains
  827. the indexes of all entities  sharing  this  attribute.  This  SUBID  is  the
  828. exception  to  the  rule  in  that  the child entities do not have a type 15
  829. BLOCKID with a SUBID of 0 containing  the  index  of  the  parent  attribute
  830. entity. Instead a type 22 BLOCKID is used to relate the child member back to
  831. its parent.  
  832.  
  833. A SUBID of 1 is found on a text-node or netline entity.  This  block  should
  834. only  contain  a single member which is the text entity related to the text-
  835. node or netline.  
  836.  
  837. A SUBID of 2 is found on an exploded symbol entity. The  child  member  list
  838. contains the indexes of all entities related to the symbol origin except for
  839. any text-node, symbol or terminal entities.  
  840.  
  841. A SUBID of 3 is found on a symbol entity. The child member list contains the
  842. indexes  for  any  text-node,  symbol  or  terminal  entities related to the
  843. symbol.  
  844.  
  845. A SUBID of 6 is found on a symbol entity. The child member list contains the
  846. indexes for any construction point entities related to the symbol.  
  847.  
  848. A  SUBID of 10 is found on a viewport entity. The child member list contains
  849. the indexes for any entities ( usually dimensions ) the are related  to  the
  850. viewport.  
  851.  
  852. A  SUBID of 11 is found on a terminal entity. The child member list contains
  853. the indexes of all netline entities whose origin point is this terminal.  
  854.  
  855. A SUBID of 12 is found on a terminal entity. The child member list  contains
  856. the indexes of all netline entities whose end point is this terminal.  
  857.  
  858. A  SUBID  of 100 is a general relationship with no specific meaning. This is
  859. usually set up using the RELATE ENTITY command.  
  860.  
  861.  
  862. BLOCKID 14 Equal Member List
  863. ============================
  864.  
  865. A type 14 EDBLOCK is followed by one or more 2 byte integers each  of  which
  866. are  the  index number of an entity. The entities in this list are all equal
  867. members in the relationship for which this entity is a member. Each  of  the
  868. equal  members should also have an equal member list containing the index of
  869. this entity.  
  870.  
  871. The only SUBID used on a type 14 EDBLOCK is 100 meaning general relationship.
  872.  
  873.  
  874. BLOCKID 15 Parent Member List
  875. =============================
  876.  
  877. A type 15 EDBLOCK is the exact inverse of a type 13 EDBLOCK.  The  block  is
  878. followed  by  one or more 2 byte integers each of which are the index number
  879. of an entity. The entities in this  list  are  all  parent  members  in  the
  880. relationship for which this entity is a child.  
  881.  
  882. The SUBIDs found are the same as described under the type 13 EDBLOCK.
  883.  
  884.  
  885. BLOCKID 16 Symbol Parameters
  886. ============================
  887.  
  888. A type 16 EDBLOCK is followed by a symbol parameters data structure:
  889.  
  890.    struct SymParams
  891.       {
  892.       double XSCL;
  893.       double YSCL;
  894.       double ANGLE;
  895.       short  FLAGS;
  896.       };
  897.  
  898. XSCL     The x scale to apply to the symbol.
  899.  
  900. YSCL     The y scale to apply to the symbol.
  901.  
  902. ANGLE    The symbol angle in radians.
  903.  
  904. FLAGS    Bit encoded word containing additional information about the symbol.
  905.  
  906.          Bit 0 On indicates the symbol is mirrored about its x axis.
  907.          Bit 2 On indicates no units conversion should take place.
  908.          Bit 3 On indicates symbol text should not be rotated.
  909.          Bit 4 On indicates symbol text should not be scaled.
  910.          Bit 5 On indicates symbol text should not be mirrored.
  911.          Bit 6 On indicates use relative layer.
  912.          Bit 7 On indicates use relative depth.
  913.          Bit 15 On indicates an exploded symbol.
  914.  
  915.  
  916. BLOCKID 17 Dimension Parameters
  917. ===============================
  918.  
  919. A type 17 EDBLOCK is followed by a dimension parameters data structure:
  920.  
  921.    struct DimParams
  922.       {
  923.       long   FLAGS;
  924.       float  GAP;
  925.       float  EXT;
  926.       float  ALENGTH;
  927.       float  ARATIO;
  928.       double SCALE;
  929.       short  FRAC;
  930.       char   PREC;
  931.       char   UNITS;
  932.       float  TOL[2];
  933.       };
  934.  
  935. FLAGS    Bit encoded word containing additional information about dimension.
  936.  
  937.          Bit 0  On indicates suppress first dimension leader line.
  938.          Bit 1  On indicates suppress second dimension leader line.
  939.          Bit 2  On indicates use filled arrowhead.
  940.          Bit 3  On indicates use open arrowhead ( > ).
  941.          Bit 4  On indicates use dash arrowhead ( / ).
  942.          Bit 5  On indicates that dimension text should be aligned to the
  943.                 witness line.
  944.          Bit 6  On indicates that dimension text should be horizontally
  945.                 aligned.
  946.          Bit 7  On indicates that the witness line should be broken to
  947.                 accomodate the dimension text.
  948.          Bit 8  On indicates that the dimension is associative.
  949.          Bit 9  On indicates that the dimension has prefix text.
  950.          Bit 10 On indicates that the dimension has suffix text.
  951.          Bit 11 On indicates that leading zeros should be suppressed when
  952.                 formatting dimension value text.
  953.          Bit 12 On indicates that the dimension value should be in the
  954.                 units type under UNITS.
  955.          Bit 13 On indicates no arrowhead should be used.
  956.          Bit 14 On indicates that decimal notation should be used for
  957.                 imperial units.
  958.          Bit 15 On indicates that trailing zeros should be suppressed when
  959.                 formatting the dimension value text.
  960.          Bit 16 On indicates that fractions should be used for imperial
  961.                 units.
  962.          Bit 17 On indicates that the fraction denominator should be fixed
  963.                 for imperial units.
  964.          Bit 18 On indicates that the dimension value text should include
  965.                 a tolerance for +/-.
  966.          Bit 19 On indicates that the dimension value text should include a
  967.                 separate tolerance for + and -.
  968.          Bit 20 On indicates that the dimension value text should include a
  969.                 tolerance for + only.
  970.          Bit 21 On indicates that the dimension value text should include a
  971.                 tolerance for - only.
  972.          Bit 22 On indicates that the dimension text should consist of 2
  973.                 values, one for the absolute + value, one for the absolute -
  974.                 value.
  975.          Bit 23 On indicates use dot arrowhead.
  976.  
  977. GAP      The size of the gap between the dimensioned object and the start
  978.          of the leader line in viewport units.
  979.  
  980. EXT      The length of the extension of the leader line beyond the dimension
  981.          witness line in viewport units.
  982.  
  983. ALENGTH  The length of the arrowhead in viewport units.
  984.  
  985. ARATIO   The width of the arrowhead as a proportion of its length.
  986.  
  987. SCALE    Scale factor to apply to dimension values.
  988.  
  989. FRAC     Fractional denominator for imperial units.
  990.  
  991. PREC     Number of places of precision for dimension value text.
  992.  
  993. UNITS    Alternative units type to use if FLAGS bit 12 is set. The units
  994.          type value is the same as used in the viewport parameters data
  995.          structure.
  996.  
  997. TOL      Two tolerance values to use if FLAGS bits 18 to 22 are set.
  998.  
  999. If this EDBLOCK is associated with a viewport entity, it defines the default
  1000. dimension parameters associated with the viewport.  
  1001.  
  1002. Note, dimension parameter data structures that occur on X-CAD V1.3  drawings
  1003. do  not  have  the  TOL  element.  The LENGTH value in the EDBLOCK should be
  1004. checked to verify this.  
  1005.  
  1006.  
  1007. BLOCKID 18 Viewport Scale
  1008. =========================
  1009.  
  1010. A type 18 EDBLOCK only appears in viewport entities. It  is  followed  by  a
  1011. single  double  value  specifing the viewport scale. ie, if the viewport was
  1012. defined with a scale of 1 to 100, the value following the EDBLOCK  would  be
  1013. 100.0.  
  1014.  
  1015.  
  1016. BLOCKID 19 Dimension Details
  1017. ============================
  1018.  
  1019. A  type  19  EDBLOCK  is  followed  by  a  dimension  details data structure
  1020. containing additional information about the dimension.  
  1021.  
  1022.    struct DimDetails
  1023.       {
  1024.       char   TYPE;
  1025.       char   FLAGS;
  1026.       double LOCS[10];
  1027.       double RADIUS;
  1028.       char   VPNUM;
  1029.       char   NUM;
  1030.       };
  1031.  
  1032. TYPE     The dimension type: 0 = horizontal
  1033.                              1 = vertical
  1034.                              2 = linear
  1035.                              3 = point
  1036.                              4 = angular
  1037.                              5 = diametric
  1038.                              6 = radial
  1039.  
  1040. FLAGS    Bit encoded word containing additional information about the
  1041.          dimension.
  1042.  
  1043.          Bit 0 On indicates that a fixed text string ( found in a type 11
  1044.                EDBLOCK on the same entity ) is to be used in place of the
  1045.                dimension value.
  1046.              1 On indicates that the dimension value should be calculated
  1047.                for the viewport VPNUM.
  1048.              2 On indicates that the position of the text is specific and
  1049.                contained in LOCS. If this bit is not set, the position of
  1050.                the text is calculated automatically.
  1051.  
  1052. LOCS     A set of up to 5 coordinates used to define the position of the
  1053.          dimension. The coordinates correspond to those used the enter the
  1054.          dimension using DRAW DIMENSION.
  1055.  
  1056. RADIUS   The radius of the selected arc if the dimension type is radial or
  1057.          diametric.
  1058.  
  1059. VPNUM    Viewport number of viewport used to calculate dimension values if
  1060.          FLAGS bit 1 is on.
  1061.  
  1062. NUM      Number of coordinate pairs in LOCS.
  1063.  
  1064.  
  1065. BLOCKID 20 Hide List
  1066. ====================
  1067.  
  1068. A type 20 EDBLOCK is followed by one or more pairs of xy coordinate  points.
  1069. Each  pair  of  xy  points  represent  2 points on a line, string or netline
  1070. entity. These pairs of points on the entity represent  off  and  on  drawing
  1071. positions when the entity is displayed thus generating hidden segments.  
  1072.  
  1073. The  coordinate points in the type 20 EDBLOCK are always sorted with respect
  1074. to the type 3 coordinate list associated with the same entity.  
  1075.  
  1076.  
  1077. BLOCKID 21 Terminal Type
  1078. ========================
  1079.  
  1080. A type 20 EDBLOCK only occurs on a terminal entity.  It  is  followed  by  a
  1081. single  2  byte integer whose value specifies the number of connections that
  1082. can be made to this terminal. The value should be -1 or 1-4.  If  it  is  -1
  1083. then this terminal allows any number of connections.  
  1084.  
  1085.  
  1086. BLOCKID 22 Attribute Value
  1087. ==========================
  1088.  
  1089. A  type  22 BLOCKID can occur on any entity. It contains the parent index of
  1090. the attribute entity plus any attribute  value  used  by  this  entity.  The
  1091. EDBLOCK  is  followed by a 2 byte integer containing the index number of the
  1092. parent attribute entity, followed by an optional set of data items. The type
  1093. of data item is dependent on the SUBID of this EDBLOCK.  
  1094.  
  1095. A  SUBID of 1 indicates that this is a NULL value attribute. Therefore there
  1096. are no data items following the parent index.  
  1097.  
  1098. A SUBID of 2 indicates that this is an INTEGER value attribute.  The  parent
  1099. index  will be followed by one or more 4 byte integer values associated with
  1100. the attribute. The number of  values  can  be  calculated  from  the  LENGTH
  1101. element in the EDBLOCK.  
  1102.  
  1103. A SUBID of 3 indicates that this is a REAL value attribute. The parent index
  1104. will be followed by one or more 8  byte  real  values  associated  with  the
  1105. attribute. The number of values can be calculated from the LENGTH element in
  1106. the EDBLOCK.  
  1107.  
  1108. A SUBID of 4 indicates that this is a TEXT value attribute. The parent index
  1109. will be followed by a null terminated character string.  
  1110.  
  1111.  
  1112. Coordinate Systems
  1113. ==================
  1114.  
  1115. X-CAD  drawings  use  a number of coordinate systems internally to represent
  1116. the drawing database and the graphics display list. All  coordinate  systems
  1117. used are based on the original definition of the sheet viewport ( viewport 0
  1118. ).  
  1119.  
  1120. The initial starting point is a sheet viewport of a given height and  width.
  1121. No  other  viewports can be defined outside of this area and no graphics can
  1122. be created or moved outside of this area. The  sheet  viewport  defines  the
  1123. maximum usable drawing area.  
  1124.  
  1125. The  viewport  coordinate  system  is  based  on  the  units and origin of a
  1126. viewport. For the sheet viewport, the origin is always in  the  bottom  left
  1127. corner  of  the  screen. The positive x axis runs to the right of the origin
  1128. while the positive y axis runs above the  origin.  Other  viewports  defined
  1129. within  the  sheet  viewport  have  the  own  local  origin  and  units. Any
  1130. coordinate values found in an EDBLOCK associated with an entity  are  always
  1131. relative to the viewport in which the entity resides.  
  1132.  
  1133. To  map  a  coordinate  from a secondary viewport to the sheet viewport, the
  1134. following transformation must be made.  
  1135.  
  1136.    coor_2 = ( ( coor_1 + viewport_origin ) * units_sf ) + vp_sheet_origin
  1137.  
  1138. Where:
  1139.  
  1140.    viewport_origin   This is the local origin of the secondary viewport.
  1141.                      The local origin can be found in the XORG and YORG
  1142.                      elements of its viewport parameters data structure.
  1143.  
  1144.    units_sf          This is the scale factor to apply to the coordinate
  1145.                      point to map the point from its local units type and
  1146.                      scale to the sheet viewport units type.
  1147.  
  1148.    vp_sheet_origin   This is the point in the sheet viewport of the bottom
  1149.                      left corner of the secondary viewport. This point can
  1150.                      be found in the SHXOFF and SHYOFF elements of the
  1151.                      secondary viewports viewport parameters data structure.
  1152.  
  1153. The size and  height/width  proportions  are  used  to  define  the  display
  1154. coordinate system. The display coordinate system is used internally by X-CAD
  1155. for drawing purposes and for the construction of the graphics display  list.
  1156. The  longer  of the height or width of the sheet viewport is used to set the
  1157. height or width of the display coordinate system to  32767  arbitary  units.
  1158. The  second  dimension  is  then calculated as the proportion of the longest
  1159. length. ie, a sheet viewport with a width of 22 inches and a  height  of  17
  1160. inches  will  set  a  maximum display coordinate area of 32767 units wide by
  1161. 25319 units high. These values can be found in the XMAX and YMAX elements of
  1162. the sheet viewport parameters structure.  
  1163.  
  1164. The orientation of the display coordinate system has the y axis reversed, ie
  1165. the 0,0 origin point of the display coordinate system is always at  the  top
  1166. left corner of the viewport.  
  1167.  
  1168. Secondary  viewports also use a display coordinate system local to their own
  1169. viewports. The scale of the display coordinate system is always set  by  the
  1170. sheet  viewport,  but  the  origin  is  always  the  top  left corner of the
  1171. secondary viewport. ie, it is offset from the display coordinate  system  of
  1172. the  sheet  viewport  by  the  values  XOFF  and YOFF found in the secondary
  1173. viewport parameters data structure.  
  1174.  
  1175. To map a coordinate from its  viewport  coordinate  system  to  its  display
  1176. coordinate system, the following transformation must be made.  
  1177.  
  1178.    dx = ( viewport_x + viewport_origin ) * viewport_scale
  1179.  
  1180.    dy = viewport_ymax - ( viewport_y + viewport_origin ) * viewport_scale
  1181.  
  1182. Where:
  1183.  
  1184.    viewport_origin   This is the local origin of the secondary viewport.
  1185.                      The local origin can be found in the XORG and YORG
  1186.                      elements of its viewport parameters data structure.
  1187.  
  1188.    viewport_scale    This is the scale factor to apply to the coordinate 
  1189.                      point to map it from its viewport to its display
  1190.                      coordinate system. This value can be found in the
  1191.                      SCL element of the viewport parameters data structure.
  1192.  
  1193.    viewport_ymax     This is the height of the viewport in the display
  1194.                      coordinate system used to reverse the y axis of the
  1195.                      viewport coordinate. This value can be found in the
  1196.                      YMAX element of the viewport parameters data structure.
  1197.  
  1198. To  map  a  coordinate  from  its  viewport  coordinate  system to the sheet
  1199. viewports display coordinate system, the viewport display origin ( XOFF  and
  1200. YOFF ) must be added.  
  1201.  
  1202.  
  1203. X-CAD Display List
  1204. ==================
  1205.  
  1206. The  display  list  associated  with an X-CAD drawing file contains the data
  1207. used when a redraw or zoom is performed on the screen.  These  functions  do
  1208. not  access  the entity coordinate data via EDBLOCKS as this would require a
  1209. large amount of calculation and slow the redraw times. Instead, the GBBLOCKs
  1210. associated  with  an  entity  contain lists of vectors in a third coordinate
  1211. system - the display list coordinate system.  
  1212.  
  1213. This is exactly the same as the display coordinate system  except  that  the
  1214. origin  is  offset  in the x and y by -16384 units. ie, the point 0,0 in the
  1215. display coordinate system is the  point  16384,16384  in  the  display  list
  1216. coordinate system.  
  1217.  
  1218. Although  the  X-CAD  database  contains  objects such as arcs, ellipses and
  1219. splines, the graphics display list holds these objects as a series of  short
  1220. straight  vectors  simplifing  the  clipping and transformation process. The
  1221. most efficient way to access any graphics data from an X-CAD drawing file is
  1222. to  use the display list data held in GBBLOCKS. To map a coordinate from the
  1223. display list coordinate system to real world or sheet viewport  coordinates,
  1224. the following transformation is used.  
  1225.  
  1226.    real_x = ( dx - 16384 + view_doff ) / view_scl 
  1227.  
  1228.    real_y = ( view_ymax - ( dy - 16384 + view_doff ) ) / view_scl 
  1229.  
  1230. Where:
  1231.  
  1232.    view_doff      This is the display offset of the viewport. The offset
  1233.                   can be found in the XOFF and YOFF elements of the
  1234.                   viewport parameters data structure.
  1235.  
  1236.    view_scl       This is the scale factor to apply to the coordinate 
  1237.                   point to map it from the display coordinate system to
  1238.                   the sheet viewport coordinate system. This value can be
  1239.                   found in the SCL element of the viewport parameters data
  1240.                   structure for the sheet viewport.
  1241.  
  1242.    view_ymax      This is the height of the sheet viewport in the display
  1243.                   coordinate system used to reverse the y axis of the
  1244.                   viewport coordinate. This value can be found in the
  1245.                   YMAX element of the viewport parameters data structure
  1246.                   for the sheet viewport.
  1247.  
  1248.  
  1249. GBBLOCK Data
  1250. ============
  1251.  
  1252. The  display  list data found after a GBBLOCK consists of a series of 2 byte
  1253. integers formatted as follows:  
  1254.  
  1255.    [ style data         ]
  1256.    [ extents data       ]
  1257.    [ vector block count ]
  1258.    [ vector blocks      ]
  1259.  
  1260. The contents of each of these blocks are dependent on the display list  type
  1261. found in the TYPE element of the GBBLOCK data structure.  
  1262.  
  1263.    Style Data
  1264.    ----------
  1265.  
  1266. TYPE     1               2                3                 4
  1267.  
  1268. word 1   [line style]    [fill style ]    [fill style ]     [symbol type]
  1269. word 2                   [           ]    [           ]
  1270. word 3                   [           ]    [           ]
  1271. word 4                   [patternfill]    [patternfill]
  1272. word 5                   [name       ]    [name       ]
  1273. word 6                   [           ]    [           ]
  1274. word 7                   [           ]    [           ]
  1275.  
  1276. [line style]   This word contains a copy of the hardfont line style used to
  1277.                render the vector list:
  1278.  
  1279.                Bit 0-7     Hardware line style.
  1280.                Bit 8-15    Line draw thickness.
  1281.  
  1282. [fill style]   A bit encoded word defining the fill type for a polygon.
  1283.  
  1284.                Bit 0-3     Fill colour if bit 4 is set.
  1285.  
  1286.                Bit 1       Only applicable for pattern fills of a single
  1287.                            colour and if bit 4 is not set. This bit on
  1288.                            indicates the patternfill will be used as a
  1289.                            mask.
  1290.  
  1291.                Bit 4       If this bit is set, then the colour used to
  1292.                            fill the polygon is set in bits 0-3. If this
  1293.                            bit is not set, the colour assigned to the layer
  1294.                            of the entity is used.
  1295.  
  1296.                Bit 5       If this bit is set on, the polygon will be
  1297.                            rendered with an outline in the colour assigned
  1298.                            to the layer of the entity.
  1299.  
  1300.                Bit 6       If this bit is on, the polygon if filled with
  1301.                            a pattern as opposed to a solid colour. If the
  1302.                            bit is set off, then words 2-7 are not present.
  1303.  
  1304.                Bit 7       Only applicable for pattern fills of a single
  1305.                            colour. This bit on indicates the background
  1306.                            colour of the patternfill will be the colour
  1307.                            assigned to the layer of the entity.
  1308.  
  1309.                Bit 8       Use a half-tone mask for solid colour fills.
  1310.  
  1311.                Bit 9       Use a mask to create a shadow fill polygon.
  1312.  
  1313. [patternfill]  These 6 words are only present if bit 6 is set in the fill-
  1314. [name       ]  style word. The 6 words contain the null terminated pattern
  1315.                fill name.
  1316.  
  1317. [symbol type]  Contains the id of the bit pattern used to display a non-
  1318.                scalable symbol such as a text-node, construction-point or
  1319.                terminal.
  1320.  
  1321.    Extents Data
  1322.    ------------
  1323.  
  1324. TYPE     1               2                3                 4
  1325.  
  1326. word 1   [xmin]          [xmin]           [xmin]            no data
  1327. word 2   [ymin]          [ymin]           [ymin]
  1328. word 3   [xmax]          [xmax]           [xmax]
  1329. word 4   [ymax]          [ymax]           [ymax]
  1330. word 5                                    [width scale]
  1331.  
  1332. [xmin] etc.    These 4 words represent the bounding extents of all of the
  1333.                vector data described for this display list block. The
  1334.                extents values are in dsplay list coordinates. If word 1 is
  1335.                equal to hex ffff, words 2-4 are not present.
  1336.  
  1337. [width scale]  Contains the width of the filled vector sequence in display
  1338.                values. This word is used to determine if only a vector
  1339.                sequnce and not a polygon is worth drawing.
  1340.  
  1341.    Vector Block Count
  1342.    ------------------
  1343.  
  1344. TYPE     1               2                3                 4
  1345.  
  1346. word 1   [block count]   [block count]    [block count]     no data
  1347.  
  1348. [block count]  This word contains the number of vector blocks that follow.
  1349.                In the case of a TYPE 4 ( Non-scaled sysmbols ), only one
  1350.                vector block follows.
  1351.  
  1352.    Vector Blocks
  1353.    -------------
  1354.  
  1355. TYPE     1               2                3                 4
  1356.  
  1357. word 1   [block extent]  [block extent]   [block extent]    [coor count]
  1358. word 2   [num vectors]   [num vectors]    [num vectors]     [first x]
  1359. word 3   [first x]       [first x]        [first x]         [first y]
  1360. word 4   [first y]       [first y]        [first y]               
  1361.  
  1362. [block extent] The is the diagonal length of the bounding box containing
  1363.                the following vector list. This value is used to determine
  1364.                if only a single pixel is required to render this vector
  1365.                list at the current zoom scale.
  1366.  
  1367. [coor count]   The number of xy coordinate pairs in display list coordinates
  1368.                that follows.
  1369.  
  1370. [num vectors]  The number of vectors represented by xy coordinate pairs in
  1371.                display list coordinates that follows. ie, there will be
  1372.                [num vectors]+1 coordinate pairs.
  1373.  
  1374. [first x]      First coordinate x value in display list coordinates.
  1375.  
  1376. [first y]      First coordinate y value in display list coordinates.
  1377.  
  1378.  
  1379. APPENDIX A  Example C routine
  1380. =============================
  1381.  
  1382. The example program shown below is a simple display routine used to draw  an
  1383. X-CAD  .xdr  file  in  a window set up on the Workbench screen.  The program
  1384. examines the display list data within GBBLOCKs and maps these coordinates to
  1385. a standard non-interlaced high res window.  
  1386.  
  1387. The program will run on an NTSC or PAL machine.
  1388.  
  1389.  
  1390. ----------------------------------------------------------------------------
  1391.                               main.c
  1392. ----------------------------------------------------------------------------
  1393.  
  1394. /*
  1395.  
  1396. G.Osis   6-October-88
  1397.  
  1398. Example routine to read an X-CAD .xdr file and display the graphics to a
  1399. workbench window.
  1400.  
  1401. */
  1402.  
  1403. #include "include.h"
  1404. #include "include/libraries/dos.h"
  1405. #include "include/intuition/intuition.h"
  1406.  
  1407. #define NOGRAPHICS 0x0001
  1408. #define PASSWORD 0x0002
  1409. #define ACDR 0x41434452
  1410. #define SWIDTH 640            /* change these to suit other formats */
  1411. #define SHEIGHT 400
  1412.  
  1413. struct IntuitionBase *IntuitionBase;
  1414. struct GfxBase *GfxBase;
  1415.  
  1416. struct ACViewPort views[32];
  1417. struct Header head;
  1418. struct HeaderIndex hi;
  1419. struct EntityHeader eh;
  1420. struct EntityData ed;
  1421. struct GraphicsInfo gi;
  1422. struct GraphicsBlock gb;
  1423.  
  1424. /* structures for area draws */
  1425.  
  1426. short tmem2[1280];
  1427. struct TmpRas t;
  1428. struct AreaInfo a;
  1429.  
  1430. /* display window definition */
  1431.  
  1432. struct NewWindow nw = {
  1433.  
  1434.    0,0,0,0,0xff,0xff,VANILLAKEY,SMART_REFRESH|ACTIVATE,0,0,0,0,0,0,0,0,0,
  1435.    WBENCHSCREEN };
  1436.  
  1437.  
  1438.  
  1439. main( argc , argv )
  1440.  
  1441. long argc;
  1442. char *argv[];
  1443.  
  1444. {
  1445.  
  1446.    long fh,ents_read,graphics,tmem1,rassize;
  1447.    short index,vpnum,close,code,*display_list;
  1448.    double ratio,scale_fac,rtemp;
  1449.    struct Window *w;
  1450.    struct IntuiMessage *mess;
  1451.    struct RastPort *r;
  1452.  
  1453.  
  1454. /* open the libraries */
  1455.  
  1456.    if ( (IntuitionBase=(struct IntuitionBase *)OpenLibrary(
  1457.                      "intuition.library",0)) == 0 )
  1458.       { 
  1459.       printf(" Failed to open intuition.library\n");
  1460.       Exit(0);
  1461.       }
  1462.  
  1463.    if ( (GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)) == 0 )
  1464.       { 
  1465.       printf(" Failed to open graphics.library\n");
  1466.       Exit(0);
  1467.       }
  1468.  
  1469. /* check a drawing name was entered on the command line */
  1470.  
  1471.    if ( argc != 2 )
  1472.       {
  1473.       printf("\n Command format is: XDR my_drawing.xdr\n");
  1474.       Exit(0);
  1475.       }
  1476.  
  1477. /* open the file */
  1478.  
  1479.    if ( !(fh=Open(argv[1],MODE_OLDFILE)) )
  1480.       {
  1481.       printf("\n Cannot open %s due to error %d\n",argv[1],IoErr());
  1482.       Exit(0);
  1483.       }
  1484.  
  1485. /* read in and check the header */
  1486.  
  1487.    Read(fh,&head,sizeof(struct Header));
  1488.  
  1489.    if ( head.ID != ACDR )
  1490.       {
  1491.       Close(fh);
  1492.       printf("\n %s is not an X-CAD drawing file\n",argv[1]);
  1493.       Exit(0);
  1494.       }
  1495.  
  1496.    if ( head.flags & NOGRAPHICS )
  1497.       {
  1498.       Close(fh);
  1499.       printf("\n Drawing was saved with the NOGRAPHICS option\n");
  1500.       Exit(0);
  1501.       }
  1502.  
  1503. /* skip password if needs be */
  1504.  
  1505.    if ( head.flags & PASSWORD )
  1506.       Seek(fh,8,0);
  1507.  
  1508. /* load all of the viewport data */
  1509.  
  1510.    for(ents_read=0;ents_read<head.ents;ents_read++)
  1511.       {
  1512.  
  1513.       Read(fh,&index,2);
  1514.  
  1515.       if ( index > 33 )
  1516.          break;
  1517.  
  1518.       Seek(fh,HIBLOCK+EHBLOCK,0);
  1519.  
  1520.       do {
  1521.          Read(fh,&ed,EDBLOCK);
  1522.  
  1523.          if ( ed.blockID == 1 )
  1524.             Read(fh,&views[index-2],ed.length);
  1525.          else
  1526.             Seek(fh,ed.length,0);
  1527.  
  1528.          } while( ed.next );
  1529.       }
  1530.  
  1531. /* any more entities ? */
  1532.  
  1533.    if ( ents_read == head.ents )
  1534.       {
  1535.       Close(fh);
  1536.       printf("\n Drawing contains no graphics entities\n");
  1537.       Exit(0);
  1538.       }
  1539.  
  1540.    Seek(fh,-2,0);
  1541.  
  1542. /* set up display window based on sheet viewport proportions */
  1543.  
  1544.    ratio=(double)SHEIGHT/(double)SWIDTH;
  1545.  
  1546.    if ( (rtemp=views[0].height/views[0].width) < ratio )
  1547.       {
  1548.       scale_fac=(double)SWIDTH/(double)views[0].xmax;
  1549.       nw.Width=SWIDTH;
  1550.       nw.Height=(short)((double)SWIDTH*rtemp)>>1;
  1551.       }
  1552.    else
  1553.       {
  1554.       scale_fac=(double)SHEIGHT/(double)views[0].ymax;
  1555.       nw.Height=SHEIGHT>>1;
  1556.       nw.Width=(short)((double)SHEIGHT/rtemp);
  1557.       }
  1558.  
  1559.    rassize=RASSIZE(nw.Width,nw.Height);
  1560.    if ( !(tmem1=AllocMem(rassize,MEMF_CHIP|MEMF_CLEAR)) )
  1561.       {
  1562.       Close(fh);
  1563.       printf("\n Cannot allocate enough TmpRas memory %d\n",rassize);
  1564.       Exit(0);
  1565.       }
  1566.  
  1567. /* open the window */
  1568.  
  1569.    if ( !(w=(struct Window *)OpenWindow(&nw)) )
  1570.       {
  1571.       Close(fh);
  1572.       FreeMem(tmem1,rassize);
  1573.       printf("\n Cannot open display window %d %d\n",
  1574.                               nw.Width,nw.Height);
  1575.       Exit(0);
  1576.       }
  1577.  
  1578.    r=w->RPort;
  1579.    SetAPen(r,3);
  1580.  
  1581. /* add area for polygon draws */
  1582.  
  1583.    w->RPort->TmpRas=(struct TmpRas *)InitTmpRas(&t,tmem1,rassize);
  1584.  
  1585.    InitArea(&a,tmem2,512);
  1586.    w->RPort->AreaInfo=&a;
  1587.  
  1588. /* start loop to read all entities */
  1589.  
  1590.    for( ;ents_read<head.ents;ents_read++)
  1591.       {
  1592.  
  1593. /* save graphics and viewport data from HIBLOCK and skip past all the
  1594.    database stuff */
  1595.  
  1596.       Read(fh,&index,2);
  1597.       Read(fh,&hi,HIBLOCK);
  1598.  
  1599.       graphics=hi.graphics;
  1600.       vpnum=hi.flags2&0x001f;
  1601.  
  1602.       Read(fh,&eh,EHBLOCK);
  1603.  
  1604.       if ( eh.first )
  1605.          do {
  1606.             Read(fh,&ed,EDBLOCK);
  1607.             Seek(fh,ed.length,0);
  1608.             } while( ed.next );
  1609.  
  1610. /* any graphics display data to retrieve ? */
  1611.  
  1612.       if ( graphics )
  1613.          {
  1614.          do {
  1615.             Read(fh,&gi,GIBLOCK);
  1616.             do {
  1617.                Read(fh,&gb,GBBLOCK);
  1618.  
  1619.                if ( !(display_list=(short *)AllocMem(gb.size,0)) )
  1620.                   Seek(fh,gb.size,0);
  1621.                else
  1622.                   {
  1623.                   Read(fh,display_list,gb.size);
  1624.  
  1625.                   render(display_list,gb.type,&views[vpnum],r,scale_fac);
  1626.  
  1627.                   FreeMem(display_list,gb.size);
  1628.                   }
  1629.                } while( gb.next );
  1630.             } while( gi.next );
  1631.          }
  1632.       }
  1633.  
  1634.    FreeMem(tmem1,rassize);
  1635.  
  1636. /* display complete, close file */
  1637.  
  1638.    Close(fh);
  1639.  
  1640. /* wait for return to be pressed then close down */
  1641.  
  1642.    SetAPen(r,2);
  1643.    SetBPen(r,1);
  1644.    Move(r,10,12);
  1645.    Text(r," Press return to end ",21);
  1646.  
  1647.    close=1;   
  1648.  
  1649.    do {
  1650.       Wait(1<<w->UserPort->mp_SigBit);
  1651.  
  1652.       while( mess=(struct IntuiMessage *)GetMsg(w->UserPort) )
  1653.          {
  1654.          code=mess->Code;
  1655.          ReplyMsg(mess);
  1656.  
  1657.          if ( code == 0x000d )
  1658.             {
  1659.             close=0;
  1660.             break;
  1661.             }
  1662.          }
  1663.       } while( close );
  1664.  
  1665.    CloseWindow(w);
  1666.  
  1667.    Exit(0);
  1668.  
  1669. }
  1670.  
  1671. /*
  1672.  
  1673.    Render the display list.
  1674.  
  1675. */
  1676.  
  1677. #define  HARD_VEC_LIST     1
  1678. #define  COLOUR_FILL_POLY  2
  1679. #define  COLOUR_FILL_VEC   3
  1680.  
  1681.  
  1682. render( display_list , type , view , r , scale_fac )
  1683.  
  1684. short *display_list;
  1685. short type;
  1686. struct ACViewPort *view;
  1687. struct RastPort *r;
  1688. double scale_fac;
  1689.  
  1690. {
  1691.  
  1692.    register short vblocks,i,j,*vl;
  1693.    register unsigned short *p=display_list;
  1694.    short vec[2],num_vecs,pd;
  1695.  
  1696.  
  1697. /* switch on type */
  1698.  
  1699.    switch( type )
  1700.       {
  1701.  
  1702. /* vector list */
  1703.  
  1704.       case HARD_VEC_LIST:
  1705.  
  1706.          p++;
  1707.  
  1708.          if ( *p == 0xffff )
  1709.             p++;
  1710.          else
  1711.             p+=4;
  1712.  
  1713.          vblocks=*p++;
  1714.          for(i=0;i<vblocks;i++)
  1715.             {
  1716.             p++;
  1717.  
  1718.             for(num_vecs=(*p)+1,vl=p+1,j=0;j<num_vecs;j++,vl+=2)
  1719.                {
  1720.                map_display_to_screen(vl,vec,view,scale_fac);
  1721.  
  1722.                if ( !j )
  1723.                   Move(r,vec[0],vec[1]);
  1724.                else
  1725.                   Draw(r,vec[0],vec[1]);
  1726.                }
  1727.  
  1728.             p+=(*p<<1)+3;
  1729.             }
  1730.  
  1731.          break;
  1732.  
  1733. /* polygon data */
  1734.  
  1735.       case COLOUR_FILL_POLY:
  1736.       case COLOUR_FILL_VEC:
  1737.  
  1738.          if ( *p & 0x0040 )
  1739.             p+=11;
  1740.          else
  1741.             p+=5;
  1742.  
  1743.          if ( gb.type == COLOUR_FILL_VEC )
  1744.             p++;
  1745.  
  1746.          vblocks=*p++;
  1747.  
  1748.          for(i=0,pd=0;i<vblocks;i++)
  1749.             {
  1750.             p++;
  1751.  
  1752.             for(num_vecs=(*p)+1,vl=p+1,j=0;j<num_vecs;j++,vl+=2)
  1753.                {
  1754.                map_display_to_screen(vl,vec,view,scale_fac);
  1755.  
  1756.                if ( !j )
  1757.                   AreaMove(r,vec[0],vec[1]);
  1758.                else
  1759.                   AreaDraw(r,vec[0],vec[1]);
  1760.                }
  1761.  
  1762.             if ( ++pd == 32 )
  1763.                {
  1764.                AreaEnd(r);
  1765.                pd=0;
  1766.                }
  1767.  
  1768.             p+=(*p<<1)+3;
  1769.  
  1770.             }
  1771.          if ( pd )
  1772.             AreaEnd(r);
  1773.  
  1774.          break;
  1775.  
  1776.       }
  1777.  
  1778. }
  1779.  
  1780. /*
  1781.  
  1782.    Map display list coordinates to screen coordinates.
  1783.  
  1784. */
  1785.  
  1786. map_display_to_screen( vl , vec , view , scale_fac )
  1787.  
  1788. unsigned short *vl;
  1789. short *vec;
  1790. struct ACViewPort *view;
  1791. double scale_fac;
  1792.  
  1793. {
  1794.  
  1795.    register short rx,ry;
  1796.  
  1797.    rx=*vl-16384+view->xoff;
  1798.    ry=*(vl+1)-16384+view->yoff;
  1799.  
  1800.    *vec=(short)((double)rx*scale_fac);
  1801.    *(vec+1)=(short)((double)ry*scale_fac)>>1;
  1802.  
  1803. }
  1804.  
  1805.  
  1806. ---------------------------------------------------------------------------
  1807.                               include.h
  1808. ---------------------------------------------------------------------------
  1809.  
  1810.  
  1811. #include "INCLUDE:exec/types.h"
  1812. #include "INCLUDE:exec/memory.h"
  1813.  
  1814. struct Header
  1815.    {
  1816.    long ID;
  1817.    short rev;
  1818.    long ents;
  1819.    long memreq;
  1820.    short flags;
  1821.    };
  1822.  
  1823. struct HeaderIndex
  1824.    {
  1825.    long head;
  1826.    short flags1;
  1827.    short flags2;
  1828.    long graphics;
  1829.    };
  1830.  
  1831. struct EntityHeader
  1832.    {
  1833.    long first;
  1834.    short flags;
  1835.    short aword1;
  1836.    short aword2; 
  1837.    short aword3;
  1838.    };
  1839.  
  1840. struct EntityData
  1841.    {
  1842.    long next;
  1843.    unsigned char blockID;
  1844.    unsigned char subID;
  1845.    long length;
  1846.    };
  1847.  
  1848. struct GraphicsInfo
  1849.    {
  1850.    long next;
  1851.    unsigned char layoff;
  1852.    unsigned char depoff;
  1853.    long gblock;
  1854.    };
  1855.  
  1856. struct GraphicsBlock
  1857.    {
  1858.    long next;
  1859.    char type;
  1860.    char flags;
  1861.    long size;
  1862.    };
  1863.  
  1864. #define HIBLOCK      sizeof(struct HeaderIndex)
  1865. #define EHBLOCK      sizeof(struct EntityHeader)
  1866. #define EDBLOCK      sizeof(struct EntityData)
  1867. #define GIBLOCK      sizeof(struct GraphicsInfo)
  1868. #define GBBLOCK      sizeof(struct GraphicsBlock)
  1869.  
  1870. struct ACViewPort
  1871.    {
  1872.    char name[22];
  1873.    double width;
  1874.    double height;
  1875.    short units;
  1876.    double xorg;
  1877.    double yorg;
  1878.    double scl;
  1879.    short xoff;
  1880.    short yoff;
  1881.    short xmax;
  1882.    short ymax;
  1883.    short cxmin;
  1884.    short cymin;
  1885.    short cxmax;
  1886.    short cymax;
  1887.    short visible;
  1888.    double shxoff;
  1889.    double shyoff;
  1890.    };
  1891.