home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk22 / dir02 / f014780.re_ / f014780.re
Text File  |  1996-04-02  |  10KB  |  366 lines

  1. /*----------------------------------------------------------------------+
  2. |                                    |
  3. |  Copyright (1995) Bentley Systems, Inc., All rights reserved.        |
  4. |                                    |
  5. |  "MicroStation" is a registered trademark and "MDL" and "MicroCSL"    |
  6. |  are trademarks of Bentley Systems, Inc.                    |
  7. |                                    |
  8. |  Limited permission is hereby granted to reproduce and modify this    |
  9. |  copyrighted material provided that the resulting code is used only     |
  10. |  in conjunction with Bentley Systems products under the terms of the    |
  11. |  license agreement provided therein, and that this notice is retained    |
  12. |  in its entirety in any such reproduction or modification.        |
  13. |                                    |
  14. +----------------------------------------------------------------------*/
  15. /*----------------------------------------------------------------------+
  16. |                                    |
  17. |    $Logfile:   J:/mdl/examples/fence/fencmir.mcv  $
  18. |   $Workfile:   fencmir.mc  $
  19. |   $Revision:   1.3  $
  20. |       $Date:   25 Jul 1995 14:26:36  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   Function -                                |
  26. |                                    |
  27. |       Fence mirror logic                            |
  28. |                                    |
  29. +----------------------------------------------------------------------*/
  30. /*----------------------------------------------------------------------+
  31. |                                    |
  32. |   Include Files                               |
  33. |                                    |
  34. +----------------------------------------------------------------------*/
  35. #include    <mselems.h>
  36. #include    <mdl.h>
  37. #include    <global.h>
  38. #include    <tcb.h>
  39. #include    <userfnc.h>
  40. #include    <math.h>
  41. #include    <string.h>
  42.  
  43. #include    "mdlfence.h"
  44. #include    "fenccmd.h"
  45.  
  46. #include    <msstate.fdf>
  47. #include    <msmisc.fdf>
  48. #include    <msoutput.fdf>
  49. #include    <msrmatrx.fdf>
  50. #include    <mstmatrx.fdf>
  51. #include    <mslocate.fdf>
  52. #include    <msvec.fdf>
  53.  
  54. /*----------------------------------------------------------------------+
  55. |                                    |
  56. |   Local defines                            |
  57. |                                    |
  58. +----------------------------------------------------------------------*/
  59. #define MIRROR_ORIG            1
  60. #define MIRROR_COPY            2
  61. #define MIRROR_MODE_HORIZONTAL        1
  62. #define MIRROR_MODE_VERTICAL        2
  63. #define MIRROR_MODE_LINE        3
  64.  
  65. /*----------------------------------------------------------------------+
  66. |                                    |
  67. |   Local type definitions                        |
  68. |                                    |
  69. +----------------------------------------------------------------------*/
  70.  
  71. /*----------------------------------------------------------------------+
  72. |                                    |
  73. |   Private Global variables                        |
  74. |                                    |
  75. +----------------------------------------------------------------------*/
  76. static int        mirrorMode;
  77.  
  78. /*----------------------------------------------------------------------+
  79. |                                    |
  80. |   Public Global variables                        |
  81. |                                    |
  82. +----------------------------------------------------------------------*/
  83. /*----------------------------------------------------------------------+
  84. |                                    |
  85. |   External variables                            |
  86. |                                    |
  87. +----------------------------------------------------------------------*/
  88. extern Dpoint3d        anchorPoint;
  89. extern int        copyMode;
  90.  
  91. /*----------------------------------------------------------------------+
  92. |                                    |
  93. |   Local function declarations                     |
  94. |                                    |
  95. +----------------------------------------------------------------------*/
  96. Private void    startFenceMirror
  97. (
  98. void
  99. );
  100.  
  101. /*----------------------------------------------------------------------+
  102. |                                    |
  103. | name        vMirrorRMatrix                        |
  104. |                                    |
  105. | author    BSI                    7/86        |
  106. |                                    |
  107. +----------------------------------------------------------------------*/
  108. Private void vMirrorRMatrix
  109. (
  110. RotMatrix        *utrans
  111. )
  112.     {
  113.     if (mgds_modes.three_d)
  114.     {
  115.     utrans->form3d[0][0] = -utrans->form3d[0][0];
  116.     utrans->form3d[0][1] = -utrans->form3d[0][1];
  117.     utrans->form3d[0][2] = -utrans->form3d[0][2];
  118.     }
  119.     else
  120.     {
  121.     utrans->form2d[0][0] = -utrans->form2d[0][0];
  122.     utrans->form2d[0][1] = -utrans->form2d[0][1];
  123.     }
  124.     }
  125.  
  126. /*----------------------------------------------------------------------+
  127. |                                    |
  128. | name        hMirrorRMatrix                        |
  129. |                                    |
  130. | author    BSI                    7/86        |
  131. |                                    |
  132. +----------------------------------------------------------------------*/
  133. Private void hMirrorRMatrix
  134. (
  135. RotMatrix        *utrans
  136. )
  137.     {
  138.     if (mgds_modes.three_d)
  139.     {
  140.     utrans->form3d[1][0] = -utrans->form3d[1][0];
  141.     utrans->form3d[1][1] = -utrans->form3d[1][1];
  142.     utrans->form3d[1][2] = -utrans->form3d[1][2];
  143.     }
  144.     else
  145.     {
  146.     utrans->form2d[1][0] = -utrans->form2d[1][0];
  147.     utrans->form2d[1][1] = -utrans->form2d[1][1];
  148.     }
  149.     }
  150.  
  151. /*----------------------------------------------------------------------+
  152. |                                    |
  153. | name        mirrorElement_getTransform                 |
  154. |                                    |
  155. | author    BSI                     6/90        |
  156. |                                    |
  157. +----------------------------------------------------------------------*/
  158. Public void mirrorElement_getTransform
  159. (
  160. FenceCopyParams    *mp,
  161. int        view,
  162. Dpoint3d    *point1,
  163. Dpoint3d    *point2
  164. )
  165.     {
  166.     double    rotAngle;
  167.     Dpoint3d    *centerP, tPoint1;
  168.     RotMatrix    invRMatrix, tRMatrix;
  169.  
  170.     mdlRMatrix_fromView (&tRMatrix, view, FALSE);
  171.  
  172.     mdlRMatrix_invert (&invRMatrix, &tRMatrix);
  173.     centerP = point1;
  174.     
  175.     switch (mirrorMode)
  176.     {
  177.     case MIRROR_MODE_VERTICAL:
  178.         vMirrorRMatrix (&tRMatrix);
  179.         break;
  180.  
  181.     case MIRROR_MODE_LINE:
  182.         mdlVec_subtractPoint (&tPoint1, point1, point2);
  183.         mdlRMatrix_rotatePoint (&tPoint1, &tRMatrix);
  184.         rotAngle = atan2 (tPoint1.y, tPoint1.x) * fc_2;
  185.         mdlRMatrix_rotate (&tRMatrix, &tRMatrix, fc_zero, fc_zero, 
  186.                 -rotAngle);
  187.         centerP = point2;
  188.  
  189.     case MIRROR_MODE_HORIZONTAL:
  190.         hMirrorRMatrix (&tRMatrix);
  191.         break;
  192.     }
  193.  
  194.     mdlRMatrix_multiply (&tRMatrix, &invRMatrix, &tRMatrix);
  195.     mdlTMatrix_fromRMatrix (&mp->transform, &tRMatrix);
  196.     mdlTMatrix_setOrigin (&mp->transform, centerP);
  197.     }
  198.  
  199. /*----------------------------------------------------------------------+
  200. |                                    |
  201. | name        mirrorFence - mirror the fence                |
  202. |                                    |
  203. | author    BSI                    7/86        |
  204. |                                    |
  205. +----------------------------------------------------------------------*/
  206. Private void    mirrorFence
  207. (
  208. Dpoint3d    *point,
  209. int        view
  210. )
  211.     {
  212.     FenceCopyParams    mp;
  213.  
  214.     /* erase current fence */
  215.     eraseFence ();
  216.  
  217.     mirrorElement_getTransform (&mp, view, point, &anchorPoint);
  218.     elementModify_transform (dgnBuf, &mp);
  219.  
  220.     /* re-display the new fence */
  221.     redrawFence ();
  222.  
  223.     /* save new anchor point */
  224.     anchorPoint = *point;
  225.     }
  226.  
  227. /*----------------------------------------------------------------------+
  228. |                                    |
  229. | name        mirrorDynamics                        |
  230. |                                    |
  231. | author    BSI                    1/87        |
  232. |                                    |
  233. +----------------------------------------------------------------------*/
  234. Private    void    mirrorDynamics
  235. (
  236. Dpoint3d    *point,
  237. int        view
  238. )
  239.     {
  240.     FenceCopyParams    mp;
  241.  
  242.     mirrorElement_getTransform (&mp, view, point, &anchorPoint);
  243.     elementModify_transform (dgnBuf, &mp);
  244.     }
  245.  
  246. /*----------------------------------------------------------------------+
  247. |                                    |
  248. | name        fenceMirrorDataFunc                    |
  249. |                                    |
  250. | author    BSI                     5/90        |
  251. |                                    |
  252. +----------------------------------------------------------------------*/
  253. Private void    fenceMirrorDataFunc
  254. (
  255. Dpoint3d    *point,
  256. int        view
  257. )
  258.     {
  259.     FenceCopyParams    mp;
  260.  
  261.     /* zero out all copy parameters structure */
  262.     memset (&mp, 0, sizeof(mp));
  263.  
  264.     mirrorElement_getTransform (&mp, view, point, &anchorPoint);
  265.     mdlFence_process (&mp);
  266.  
  267.     /* free memory allocated for graphic group remapping */
  268.     mdlModify_freeGGMap ((MdlCopyParams *)&mp);
  269.     }
  270.  
  271. /*----------------------------------------------------------------------+
  272. |                                    |
  273. | name        mirrorLine_firstPoint - fence mirror about a line    |
  274. |                                    |
  275. | author    BSI                    7/86        |
  276. |                                    |
  277. +----------------------------------------------------------------------*/
  278. Private void    mirrorLine_firstPoint
  279. (
  280. Dpoint3d    *point
  281. )
  282.     {
  283.     /* save anchor point */
  284.     anchorPoint = *point;
  285.  
  286.     mdlOutput_rscPrintf (MSG_PROMPT, NULL, MESSAGEID_Messages,
  287.                 MSGID_MirrorEnter2ndPt);
  288.  
  289.     mdlState_setFunction (STATE_DATAPOINT, fenceMirrorDataFunc);
  290.     mdlState_setFunction (STATE_RESET, startFenceMirror);
  291.  
  292.     if (!tcb->wssect)
  293.     {
  294.     mdlFence_toShape (dgnBuf);
  295.     mdlState_dynamicUpdate (mirrorDynamics, 1);
  296.     }
  297.     }
  298.  
  299. /*----------------------------------------------------------------------+
  300. |                                    |
  301. | name        startFenceMirror                    |
  302. |                                    |
  303. | author    BSI                     6/91        |
  304. |                                    |
  305. +----------------------------------------------------------------------*/
  306. Private void    startFenceMirror
  307. (
  308. void
  309. )
  310.     {
  311.     int        fenceCommand;
  312.     
  313.     /* set up proper locate criteria depending on copy mode */
  314.     if (copyMode)
  315.     mdlLocate_allowLocked ();
  316.     else
  317.     mdlLocate_normal ();
  318.  
  319.     /* set up the Command Number */
  320.     fenceCommand = (copyMode ? 120 : 117) + mirrorMode;
  321.  
  322.     mdlState_startFenceCommand
  323.     (
  324.         (copyMode ? fenceModify_transformCopy: fenceModify_transformOrig),
  325.         mirrorFence,
  326.         ((mirrorMode==MIRROR_MODE_LINE) ? mirrorLine_firstPoint :
  327.                           fenceMirrorDataFunc),
  328.         endFenceCommand,
  329.             -fenceCommand,
  330.         -132,
  331.         (copyMode ? FENCE_CLIP_COPY : FENCE_CLIP_ORIG)
  332.     );
  333.  
  334.     /* start dynamics, if appropriate */
  335.     if ((mirrorMode != MIRROR_MODE_LINE) && !tcb->wssect)
  336.     {
  337.     mdlFence_toShape (dgnBuf);
  338.     mdlState_dynamicUpdate (mirrorDynamics, 1);
  339.     }
  340.     }
  341.     
  342. /*----------------------------------------------------------------------+
  343. |                                    |
  344. | name        fenceMirrorCommand                    |
  345. |                                    |
  346. | author    BSI                    7/86        |
  347. |                                    |
  348. +----------------------------------------------------------------------*/
  349. Private void    fenceMirrorCommand
  350. (
  351. void
  352. cmdNumber
  353.         CMD_MFENCE_MIRROR_ORIGINAL_HORIZONTAL,
  354.         CMD_MFENCE_MIRROR_ORIGINAL_VERTICAL,
  355.         CMD_MFENCE_MIRROR_ORIGINAL_LINE,
  356.         CMD_MFENCE_MIRROR_COPY_HORIZONTAL,
  357.         CMD_MFENCE_MIRROR_COPY_VERTICAL,
  358.         CMD_MFENCE_MIRROR_COPY_LINE
  359.     {
  360.     copyMode   = ((mdlCommandNumber & 0xff00) >> 8) == MIRROR_COPY;
  361.     mirrorMode =  (mdlCommandNumber & 0x00f0) >> 4;
  362.     
  363.     startFenceMirror ();
  364.     }
  365.