home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / autocad / acltldv / dxfix.dxt < prev    next >
Text File  |  1995-07-26  |  16KB  |  456 lines

  1.  
  2. \   Rules for translating AutoCAD Release 11 DXF files to Release 10
  3.  
  4. \   Version 1.5  --  May 28, 1992
  5.  
  6. .( "Release 12 -> 10 DXF translator, Version 1.5 (5/28/92)\n"
  7.  
  8. \ ************ START DEBUG-ONLY STUFF ***************
  9.  
  10. \   Initialization routine
  11.  
  12. : dxf:start
  13. \   -1 dumpinput !                    \ Un-comment to dump input items
  14. \   -1 dumpoutput !                   \ Un-comment to dump output items
  15. \    6 outprec !                      \ Un-comment to force ASCII output
  16. \   -1 mbchar !               \ Un-comment to force multibyte char interp
  17. ;
  18.  
  19. \   Manual translation program (equivalent to the standard loop, so it's
  20. \                               commented out).
  21.  
  22. \ : dxf:translate
  23. \     begin
  24. \         readitem while
  25. \         writeitem drop
  26. \     repeat
  27. \ ;
  28.  
  29. \   Print point on stack
  30.  
  31. 80 string edbuf
  32. : point.                              \ x y z --
  33.     2rot
  34.     "(%g," edbuf fstrform edbuf type
  35.     2swap
  36.     "%g" edbuf fstrform edbuf type
  37.     2dup missing_z 2@ f= if
  38.         ")"
  39.     else
  40.         ",%g)" edbuf fstrform edbuf
  41.     then
  42.     type
  43. ;
  44.  
  45. \ ************* END DEBUG-ONLY STUFF **************
  46.  
  47. \   Defining words to make common translation operations easier
  48. \   and more expressive to specify.
  49.  
  50. \   REMOVE DXF:bilge:rat  --  Causes all instances of item RAT in section
  51. \                             BILGE to be removed.  (An explicit section
  52. \                             name is expected; "*" is not valid here)
  53.  
  54. : remove
  55.     create
  56.     does>
  57.         drop
  58.         1 delitem !
  59. ;
  60.  
  61. \  DROP_Z DXF:header:$zilch  --  The Z co-ordinate will be deleted from
  62. \                                header variable ZILCH.
  63.  
  64. : drop_z
  65.     create
  66.     does>
  67.         drop
  68.         10 group 2drop missing_z 2@ 10 setgroup
  69. ;
  70.  
  71. \   bitmask MASKFIELD DXF:*:*:<field>  --  AND a field with a bitmask
  72.  
  73. : maskfield
  74.     create
  75.     ,                                 \ Compile bitmask
  76.     does>
  77.     over                              \ Duplicate group index
  78.     group                             \ Extract value of group
  79.     swap                              \ Move bitmask address to the top
  80.     @                                 \ Get value of bitmask
  81.     and                               \ Mask the value of the field
  82.     swap                              \ Get group code on top
  83.     setgroup                          \ Update group in item
  84. \   stdout printitem
  85. ;
  86.  
  87. \   DITCHGROUP DXF:*:<type>:<group>
  88.  
  89. : ditchgroup
  90.     create
  91.     does>
  92.     drop                              \ Get rid of word's address
  93.     delgroup                          \ Delete this group from item
  94. ;
  95.  
  96. \   ERRAT  --  End an error message by editing the location in the
  97. \              file that the error occurred.
  98.  
  99. : errat
  100.     ." " at "
  101.     itempos
  102.     inbinary @ if
  103.         "byte 0x%lX"
  104.     else
  105.         1+ "line %ld"
  106.     then
  107.     edbuf strform edbuf type
  108.     ." " of input file.\n"
  109. ;
  110.  
  111. \   TEXTVADJ DXF:*:<type>:<group>  --  Translate new-format separate
  112. \                                      horizontal and vertical text
  113. \                                      alignment modes.    
  114.  
  115. : textvadj
  116.     create
  117.     does>
  118.     drop                              \ Get rid of word's address
  119.     dup                               \ Copy vertical alignment group code
  120.     72 group? if
  121.         72 group                      \ Get horizontal alignment
  122.     else
  123.         0                             \ No horizontal alignment, assume Left
  124.     then
  125.     ( Settings for horizontal alignment of 3, 4, and 5 override
  126.       any value present in the vertical alignment field [73 group for
  127.       Text, 74 group for Attdef/Attrib].  It isn't clear how this could
  128.       come to pass except through entmod or DXF, but if we find one, just
  129.       ditch the redundant 73/74 group without complaining.  )
  130.     dup dup 2 > swap 6 < and if
  131.         drop                          \ Drop horizontal alignment
  132.         drop                          \ Drop copy of vertical group code
  133. \       ." "Dropped vert. text alignment, overridden by horiz. alignment.\n"
  134.     else
  135.         ( We translate the new "MCenter" alignment into the old "Middle"
  136.           alignment.  This is usually, but not always, appropriate.  )
  137.         1 = over group 2 = and if
  138.             drop                      \ Drop copy of vertical group code
  139. \           ." "Translated MCenter text alignment.\n"
  140.             4 72 setgroup
  141.         else
  142.             group 0<> if              \ If vertical alignment not Baseline
  143.                 72 group? if
  144.                     72 delgroup       \ Discard horizontal alignment group
  145.                 then
  146.                 11 group? if
  147.                     11 delgroup       \ Drop alignment point
  148.                 then
  149.                 ." "Text alignment lost--changed to baseline/left\n  for "
  150.                 0 group type ." " entity with "
  151.                 0 group "ATTRIB" strcmp 0= if
  152.                     ." "value: \"" 1
  153.                 else
  154.                     0 group "ATTDEF" strcmp 0= if
  155.                         ." "tag: \"" 2
  156.                     else
  157.                         ." "text: \"" 1
  158.                     then
  159.                 then
  160.                 group type ." "\"" errat
  161.             then
  162.         then
  163.     then
  164.     delgroup                          \ Discard vertical alignment group
  165. ;
  166.  
  167. (   Process command line options and set special operating modes   )
  168.  
  169. : modeset
  170.     "d" option if                     \ If -D option is set, turn on trace
  171.         1 dxftrace !
  172.     then
  173. ;
  174.  
  175. \   End of defining words.  Let the fun begin!
  176.  
  177. modeset                               \ Process command line options
  178.  
  179.  
  180. (   Header variables to delete or modify   )
  181.  
  182. remove dxf:header:$dimclrd            \ Dimension line colour
  183. remove dxf:header:$dimclre            \ Dimension extension line colour
  184. remove dxf:header:$dimclrt            \ Dimension text colour
  185. remove dxf:header:$dimgap             \ Dimension block gap
  186. remove dxf:header:$dimstyle           \ Current dimension style
  187. remove dxf:header:$dimtfac            \ Dimension text vertical position
  188. remove dxf:header:$dwgcodepage        \ Drawing code page
  189. remove dxf:header:$maxactvp           \ Maximum active viewports
  190. remove dxf:header:$pelevation         \ Paper elevation
  191. remove dxf:header:$pextmax            \ Paper maximum extents
  192. remove dxf:header:$pextmin            \ Paper minimum extents
  193. remove dxf:header:$pinsbase           \ Paper insertion base
  194. remove dxf:header:$plimcheck          \ Paper limit checking
  195. remove dxf:header:$plimmax            \ Paper maximum limits
  196. remove dxf:header:$plimmin            \ Paper minimum limits
  197. remove dxf:header:$plinegen           \ Polyline linetype generation
  198. remove dxf:header:$psltscale          \ Paper linetype scaling
  199. remove dxf:header:$pucsname           \ Paper UCS name
  200. remove dxf:header:$pucsorg            \ Paper UCS origin
  201. remove dxf:header:$pucsxdir           \ Paper UCS X direction
  202. remove dxf:header:$pucsydir           \ Paper UCS Y direction
  203. remove dxf:header:$shadedge           \ SHADE command edge rendering mode
  204. remove dxf:header:$shadedif           \ Shading diffuse illumination factor
  205. remove dxf:header:$tilemode           \ Tiled viewports mode
  206. remove dxf:header:$treedepth          \ Oct-tree depth limit
  207. remove dxf:header:$unitmode           \ Drawing unit mode bits
  208. remove dxf:header:$visretain          \ Layer/viewport visibility retention
  209.  
  210. drop_z dxf:header:$extmax             \ Flatten maximum extents
  211. drop_z dxf:header:$extmin             \ Flatten minimum extents
  212.  
  213. : dxf:header:$acadver                 \ $ACADVER needs special processing
  214.     "AC1006" 1 setgroup               \ Substitute R10's version code
  215. ;
  216.  
  217. : dxf:header:$dimscale                \ $DIMSCALE needs special processing
  218.     40 group 0.0 f= if                \ If it's zero (for paper space)...
  219.         1.0 40 setgroup               \ ...substitute 1.0
  220.     then
  221. ;
  222.  
  223.  
  224. (   Symbol tables to delete or modify   )
  225.  
  226. remove dxf:tables:appid               \ Registered application table
  227. remove dxf:tables:dimstyle            \ Dimension style table
  228.  
  229. : dxf:tables:layer                    \ For the LAYER table...
  230.     0 group "LAYER" strcmp 0=         \ For each LAYER (but not TABLE/ENDTAB)
  231.     70 group? and if                  \ If there's a 70 (flags) group...
  232.         70 group 48 and if            \ ...and its 16 or 32 bits are set...
  233.             1 delitem !               \ ...drop this dependent layer
  234.         else
  235.             70 group 1 and            \ else zero any new flag bits...
  236.             70 setgroup               \ ...and update the 70 group
  237.         then
  238.     then
  239. ;
  240.  
  241.  
  242. (   Entities to delete   )
  243.  
  244. remove dxf:blocks:viewport            \ Viewport entities in blocks
  245. remove dxf:entities:viewport          \ Viewport entities
  246.  
  247.  
  248. (   Block definition transformations   )
  249.  
  250. : dxf:blocks:block                    \ In block definition...
  251.     70 group? if
  252.         70 group 3 and 70 setgroup    \ ... clear Xref & dependent bits
  253.     then
  254.     1 delgroup                        \ Remove Xref path group...
  255.     3 delgroup                        \ ...and new block name group
  256. ;
  257.  
  258.  
  259. (   Dimension entity transformations   )
  260.  
  261. ditchgroup dxf:*:dimension:3          \ Drop dimension style
  262. ditchgroup dxf:*:dimension:52         \ Drop obliquing angle
  263. ditchgroup dxf:*:dimension:53         \ Drop text rotation angle
  264. ditchgroup dxf:*:dimension:54         \ Drop bogus extra angle if present
  265.  
  266.  
  267. (   Delete extended entity data   )
  268.  
  269. ditchgroup dxf:*:*:1000-1100          \ Drop all Xdata fields
  270.  
  271.  
  272. (   Translate vertical text alignment   )
  273.  
  274. textvadj dxf:*:text:73
  275. textvadj dxf:*:attdef:74
  276. textvadj dxf:*:attrib:74
  277.  
  278.  
  279. (   Delete paper space entities and the space indicator   )
  280.  
  281. : dxf:*:*:67
  282.     group 0= if
  283.         67 delgroup                   \ Model space entity: drop 67 group
  284.     else
  285.         1 delitem !                   \ Paper space entity: drop the entity
  286.     then
  287. ;
  288.  
  289.  
  290. \   Translate polyface meshes into equivalent 3DFACEs
  291.  
  292. variable pfacing                      \ Polyface processing underway
  293. variable pfaced                       \ Polyface temporary file is open
  294. file pfacefile                        \ Polyface temporary file
  295. variable rinvis                       \ Invisibility bits for 3DFACE
  296. variable rogroup                      \ Output vertex point group code
  297. variable rxgroup                      \ Vertex index group code
  298. variable rvcount                      \ Number of vertices in file
  299. 24 constant rvlen                     \ Length of vertex item in temp file
  300. 3 1 8 array vertex                    \ Vertex array for I/O
  301.  
  302. (  Polyline header.  If the 70 group is flagged as introducing a polyface,
  303.    delete it, set the flag to indicate we're translating a polyface, and
  304.    open the temporary file we use to hold vertices.  )
  305.  
  306. : dxf:*:polyline:70
  307.     group 64 and if
  308.         1 delitem !
  309.         1 pfacing !
  310.         0 rvcount !
  311.         pfaced @ 0= if
  312.             "$pface.$ac" 15 pfacefile fopen pfaced !
  313.             pfaced @ not if
  314.                 ." "Cannot open polyface temporary file.\n"
  315.             then
  316.         then
  317.     then
  318. ;
  319.  
  320. (  Sequence end.  If we're in a polyface, delete it and mark
  321.    translation of the polyface complete.  We leave the temporary
  322.    file open so subsequent polyfaces can reuse it.  This eliminates
  323.    the overhead of opening and closing the file for every entity we
  324.    translate.  The file is closed and deleted at DXF:END time.  )
  325.  
  326. : dxf:*:seqend
  327.     drop
  328.     pfacing @ if
  329.         1 delitem !
  330.         0 pfacing !
  331.     then
  332.     1 specialdone !
  333. ;
  334.  
  335. (  Replace a vertex index group [GCODE] with a point-coordinate group
  336.    [VCODE], setting invisibility bit [IBIT] if the vertex index was
  337.    negative.  )
  338.  
  339. : pfacejam                            \ vcode ibit gcode --
  340.     rot 
  341.     rogroup !
  342.     dup rxgroup !
  343.     dup group? if
  344.         group
  345.         dup 0< if
  346.             swap rinvis @ or rinvis !
  347.         else
  348.             swap drop
  349.         then
  350.         abs 1-
  351.         rvlen *
  352.         0 pfacefile fseek
  353.         pfacefile rvlen 0 vertex fread rvlen = if
  354.             rxgroup @ delgroup
  355.             rogroup @ addgroup
  356.             0 vertex 2@
  357.             1 vertex 2@
  358.             2 vertex 2@
  359.             rogroup @ setgroup
  360.         else
  361.             ." "Vertex read error.\n"
  362.         then
  363.     else
  364.         drop
  365.     then
  366. ;
  367.  
  368. (  Process vertex.  If we're in a polyface, the vertex is translated
  369.    into a POINT, LINE, or 3DFACE entity depending upon the number of
  370.    vertices it contains.  Since the entity property fields are left
  371.    unchanged, the replacement entity will correctly inherit the modes
  372.    specified in the VERTEX entity.  )
  373.  
  374. : dxf:*:vertex:70
  375.     drop
  376.     pfacing @ if
  377.         70 group 64 and if
  378.             1 delitem !
  379.             pfaced @ if
  380.                 10 group
  381.                 2 vertex 2!
  382.                 1 vertex 2!
  383.                 0 vertex 2!
  384.                 rvcount @ rvlen * 0 pfacefile fseek
  385.                 1 rvcount +!
  386.                 rvlen 0 vertex pfacefile fwrite
  387.                 rvlen <> if
  388.                     ." "Vertex write error.\n"
  389.                 then
  390.             then
  391.         else
  392.             70 group 128 and if
  393.                 72 group? if
  394.                     73 group? if
  395.                         0 rinvis !
  396.                         "3DFACE" 0 setgroup
  397.                         10 delgroup
  398.                         10 1 71 pfacejam
  399.                         11 2 72 pfacejam
  400.                         12 4 73 pfacejam
  401.                         74 group? if
  402.                             13 8 74 pfacejam
  403.                         else
  404.                             ( Face has 3 vertices.  Represent this in the
  405.                               3DFACE by setting the third and fourth vertices
  406.                               the same and replicating the invisibility bit
  407.                               for the closing edge. )
  408.                             13 addgroup
  409.                             12 group
  410.                             13 setgroup
  411.                             rinvis @ 4 and if
  412.                                 rinvis @ 8 or rinvis !
  413.                             then
  414.                         then
  415.                         rinvis @ 70 setgroup
  416.                     else
  417.                         ( Generate line for 2 vertex face )
  418.                         "LINE" 0 setgroup
  419.                         10 delgroup
  420.                         70 delgroup
  421.                         10 0 71 pfacejam
  422.                         11 0 72 pfacejam
  423.                     then
  424.                 else
  425.                     ( Generate point for 1 vertex face )
  426.                     "POINT" 0 setgroup
  427.                     70 delgroup
  428.                     10 delgroup
  429.                     10 0 71 pfacejam
  430.                 then
  431.             then
  432.         then
  433.     else
  434.         70 group 0x7F and 70 setgroup \ Clear polyface bit
  435.     then
  436. ;
  437.  
  438.  
  439. \   Termination processing
  440.  
  441. : dxf:end
  442.     pfaced @ if
  443.         pfacefile fclose              \ Close the file
  444.         "$pface.$ac" fdelete drop     \ Delete polyface temporary file
  445.         0 pfaced !
  446.     then
  447.     "m" option if                     \ If -M option is set, print memory stats
  448.         memstat
  449.     then
  450.     "End translation.\n" type
  451.     depth if
  452.         .s cr
  453.     then
  454. ;
  455.  
  456.