home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk21 / dir03 / f014790.re_ / f014790.re
Text File  |  1996-04-02  |  19KB  |  714 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. |   $Workfile:   fencscl.mc  $
  18. |   $Revision:   1.5  $
  19. |       $Date:   25 Jul 1995 14:26:24  $
  20. |                                    |
  21. +----------------------------------------------------------------------*/
  22. /*----------------------------------------------------------------------+
  23. |                                    |
  24. |   Function -                                |
  25. |                                    |
  26. |       Fence scale/spin logic                        |
  27. |                                    |
  28. +----------------------------------------------------------------------*/
  29. /*----------------------------------------------------------------------+
  30. |                                    |
  31. |   Include Files                               |
  32. |                                    |
  33. +----------------------------------------------------------------------*/
  34. #include    <mselems.h>
  35. #include    <mdl.h>
  36. #include    <global.h>
  37. #include    <tcb.h>
  38. #include    <userfnc.h>
  39. #include    <math.h>
  40. #include    <string.h>
  41.  
  42. #include    "mdlfence.h"
  43. #include    "fenccmd.h"
  44.  
  45. #include    <msstate.fdf>
  46. #include    <msmisc.fdf>
  47. #include    <msoutput.fdf>
  48. #include    <msrmatrx.fdf>
  49. #include    <mstmatrx.fdf>
  50. #include    <mslocate.fdf>
  51. #include    <msvec.fdf>
  52. #include    <mselemen.fdf>
  53.  
  54. /*----------------------------------------------------------------------+
  55. |                                    |
  56. |   Local defines                            |
  57. |                                    |
  58. +----------------------------------------------------------------------*/
  59. #define SPIN_ORIG            1
  60. #define SPIN_COPY            2
  61. #define ROTATE_ORIG            1
  62. #define ROTATE_COPY            2
  63. #define SCALE_ORIG            1
  64. #define SCALE_COPY            2
  65.  
  66. /*----------------------------------------------------------------------+
  67. |                                    |
  68. |   Local type definitions                        |
  69. |                                    |
  70. +----------------------------------------------------------------------*/
  71. /*----------------------------------------------------------------------+
  72. |                                    |
  73. |   Private Global variables                        |
  74. |                                    |
  75. +----------------------------------------------------------------------*/
  76. static int        fenceCommandView;
  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.  
  97. /*----------------------------------------------------------------------+
  98. |                                    |
  99. |    ROTATE FENCE functions                        |
  100. |                                    |
  101. +----------------------------------------------------------------------*/
  102. /*----------------------------------------------------------------------+
  103. |                                    |
  104. | name        rotateElement_getTransform                 |
  105. |                                    |
  106. | author    BSI                     5/90        |
  107. |                                    |
  108. +----------------------------------------------------------------------*/
  109. Public void    rotateElement_getTransform
  110. (
  111. Transform   *trans,
  112. int        view,
  113. double        angle,
  114. Dpoint3d    *point
  115. )
  116.     {
  117.     Dpoint3d    tPoint;
  118.     RotMatrix    tRMatrix, iRMatrix;
  119.  
  120.     mdlRMatrix_fromView (&tRMatrix, view, FALSE);
  121.     mdlRMatrix_invert (&iRMatrix, &tRMatrix);
  122.     mdlRMatrix_rotate (&tRMatrix, &tRMatrix, fc_zero, fc_zero, angle);
  123.     mdlRMatrix_multiply (&tRMatrix, &iRMatrix, &tRMatrix);
  124.  
  125.     mdlTMatrix_fromRMatrix (trans, &tRMatrix);
  126.     mdlTMatrix_setOrigin (trans, point);
  127.     }
  128.  
  129. /*----------------------------------------------------------------------+
  130. |                                    |
  131. | name        rotateFenceDataFunc                    |
  132. |                                    |
  133. | author    BSI                     6/91        |
  134. |                                    |
  135. +----------------------------------------------------------------------*/
  136. Private void    rotateFenceDataFunc
  137. (
  138. Dpoint3d    *point,
  139. int        view
  140. )
  141.     {
  142.     FenceCopyParams        cp;
  143.  
  144.     /* zero out all copy parameters structure */
  145.     memset (&cp, 0, sizeof(cp));
  146.  
  147.     fenceCommandView = view;
  148.     rotateElement_getTransform (&cp.transform, view, 
  149.                     tcb->actangle * fc_piover180, point);
  150.  
  151.     mdlFence_process (&cp);
  152.  
  153.     /* free memory allocated for graphic group remapping */
  154.     mdlModify_freeGGMap ((MdlCopyParams *)&cp);
  155.     }
  156.  
  157. /*----------------------------------------------------------------------+
  158. |                                    |
  159. | name        rotateElement                       |
  160. |                                    |
  161. | author    BSI                     6/91        |
  162. |                                    |
  163. +----------------------------------------------------------------------*/
  164. Private void    rotateElement
  165. (
  166. MSElementUnion    *el,
  167. Dpoint3d    *point,
  168. int        view
  169. )
  170.     {
  171.     Transform    transform;
  172.     
  173.     rotateElement_getTransform (&transform, view, 
  174.         tcb->actangle * fc_piover180, point);
  175.         
  176.     mdlElement_transform (dgnBuf, dgnBuf, &transform);
  177.     }
  178.  
  179. /*----------------------------------------------------------------------+
  180. |                                    |
  181. | name        rotateDynamics                         |
  182. |                                    |
  183. | author    BSI                     6/91        |
  184. |                                    |
  185. +----------------------------------------------------------------------*/
  186. Public void    rotateDynamics 
  187. (
  188. Dpoint3d    *point,
  189. int        view
  190. )    
  191.     {
  192.     rotateElement (dgnBuf, point, view);
  193.     }
  194.  
  195. /*----------------------------------------------------------------------+
  196. |                                    |
  197. | name        rotateFence                        |
  198. |                                    |
  199. | author    BSI                     6/91        |
  200. |                                    |
  201. +----------------------------------------------------------------------*/
  202. Private void    rotateFence
  203. (
  204. Dpoint3d    *point
  205. )
  206.     {
  207.     eraseFence ();
  208.     rotateElement (dgnBuf, point, fenceCommandView);
  209.     redrawFence();
  210.     }
  211.  
  212. /*----------------------------------------------------------------------+
  213. |                                    |
  214. | name        startFenceRotate                    |
  215. |                                    |
  216. | author    BSI                     6/91        |
  217. |                                    |
  218. +----------------------------------------------------------------------*/
  219. Private void    startFenceRotate
  220. (
  221. void
  222. )
  223.     {
  224.     int        fenceCommand, clipMode, (*contentFunc)();
  225.  
  226.     /* set up proper locate criteria depending on copy mode */
  227.     if (copyMode)
  228.     {
  229.     contentFunc  = fenceModify_transformCopy;
  230.     fenceCommand = 115;
  231.     clipMode     = FENCE_CLIP_COPY;
  232.     mdlLocate_allowLocked ();
  233.     }
  234.     else
  235.     {
  236.     contentFunc  = fenceModify_transformOrig;
  237.     fenceCommand = 114;
  238.     clipMode     = FENCE_CLIP_ORIG;
  239.     mdlLocate_normal ();
  240.     }
  241.  
  242.     mdlState_startFenceCommand
  243.     (
  244.         contentFunc,
  245.         rotateFence,
  246.         rotateFenceDataFunc,
  247.         endFenceCommand,
  248.         -fenceCommand,
  249.         -132,
  250.         clipMode
  251.     );
  252.     
  253.     if (!tcb->wssect)
  254.     {
  255.     mdlFence_toShape (dgnBuf);
  256.     mdlState_dynamicUpdate (rotateDynamics, 1);
  257.     }
  258.     }
  259.  
  260. /*----------------------------------------------------------------------+
  261. |                                    |
  262. | name        fenceRotate                        |
  263. |                                    |
  264. | author    BSI                    7/86        |
  265. |                                    |
  266. +----------------------------------------------------------------------*/
  267. Public void    fenceRotate
  268. (
  269. char     *unparsedP
  270. cmdNumber    CMD_MFENCE_ROTATE_ORIGINAL,
  271.         CMD_MFENCE_ROTATE_COPY
  272.     {
  273.     copyMode   = ((mdlCommandNumber & 0xff00) >> 8) == ROTATE_COPY;
  274.     startFenceRotate ();
  275.     }
  276.  
  277. /*----------------------------------------------------------------------+
  278. |                                    |
  279. |    SCALE FENCE functions                        |
  280. |                                    |
  281. +----------------------------------------------------------------------*/
  282. /*----------------------------------------------------------------------+
  283. |                                    |
  284. | name        scaleRMatrix                        |
  285. |                                    |
  286. | author    BSI                    10/86        |
  287. |                                    |
  288. +----------------------------------------------------------------------*/
  289. Public void    scaleRMatrix
  290. (
  291. RotMatrix        *t,
  292. double            xs,
  293. double            ys,
  294. double            zs
  295. )
  296.     {
  297.     int        i;
  298.  
  299.     if (mgds_modes.three_d)
  300.     {
  301.     for (i=0; i<3; i++)
  302.         {
  303.         t->form3d[0][i] *= xs;
  304.         t->form3d[1][i] *= ys;
  305.         t->form3d[2][i] *= zs;
  306.         }
  307.     }
  308.     else
  309.     {
  310.     for (i=0; i<2; i++)
  311.         {
  312.         t->form2d[0][i] *= xs;
  313.         t->form2d[1][i] *= ys;
  314.         }
  315.     }
  316.     }
  317.  
  318. /*----------------------------------------------------------------------+
  319. |                                    |
  320. | name        scaleElement_getTransform                 |
  321. |                                    |
  322. | author    BSI                     5/90        |
  323. |                                    |
  324. +----------------------------------------------------------------------*/
  325. Public void    scaleElement_getTransform 
  326. (
  327. Transform   *trans,
  328. int        view,
  329. Dpoint3d    *point,
  330. double        xScale, 
  331. double        yScale, 
  332. double        zScale
  333. )
  334.     {
  335.     Dpoint3d    tPoint;
  336.     RotMatrix    tRMatrix, invRMatrix;
  337.  
  338.     mdlRMatrix_fromView (&tRMatrix, view, FALSE);
  339.     mdlRMatrix_invert (&invRMatrix, &tRMatrix);
  340.     
  341.     scaleRMatrix (&tRMatrix, xScale, yScale, zScale);
  342.     mdlRMatrix_multiply (&tRMatrix, &invRMatrix, &tRMatrix);
  343.     mdlTMatrix_fromRMatrix (trans, &tRMatrix);
  344.     mdlTMatrix_setOrigin (trans, point);
  345.     }
  346.  
  347. /*----------------------------------------------------------------------+
  348. |                                    |
  349. | name        scaleElement                        |
  350. |                                    |
  351. | author    BSI                    7/86        |
  352. |                                    |
  353. +----------------------------------------------------------------------*/
  354. Public void    scaleElement 
  355. (
  356. MSElementUnion    *element,        /* <=> element to be scaled */
  357. Dpoint3d    *scalePoint,        /* => point to scale about */
  358. double        xs, 
  359. double        ys, 
  360. double        zs,    
  361. int        view
  362. )
  363.     {
  364.     Transform    transform;
  365.  
  366.     scaleElement_getTransform (&transform, view, scalePoint, xs, ys, zs);
  367.     mdlElement_transform (element, element, &transform);
  368.     }
  369.  
  370. /*----------------------------------------------------------------------+
  371. |                                    |
  372. | name        scaleDynamics                        |
  373. |                                    |
  374. | author    BSI                    1/87        |
  375. |                                    |
  376. +----------------------------------------------------------------------*/
  377. Public void    scaleDynamics 
  378. (
  379. Dpoint3d    *point,
  380. int        view
  381. )            
  382.     {
  383.     scaleElement (dgnBuf, point, tcb->xactscle, tcb->yactscle,
  384.             tcb->zactscle, view);
  385.     }
  386.  
  387. /*----------------------------------------------------------------------+
  388. |                                    |
  389. | name        scaleFenceDataFunc                    |
  390. |                                    |
  391. | author    BSI                     6/91        |
  392. |                                    |
  393. +----------------------------------------------------------------------*/
  394. Private void    scaleFenceDataFunc
  395. (
  396. Dpoint3d    *point,
  397. int        view
  398. )
  399.     {
  400.     FenceCopyParams        cp;
  401.  
  402.     /* zero out all copy parameters structure */
  403.     memset (&cp, 0, sizeof(cp));
  404.     
  405.     fenceCommandView = view;
  406.     scaleElement_getTransform (&cp.transform, view, point,
  407.             tcb->xactscle, tcb->yactscle, tcb->zactscle);
  408.  
  409.     mdlFence_process (&cp);
  410.  
  411.     /* free memory allocated for graphic group remapping */
  412.     mdlModify_freeGGMap ((MdlCopyParams *)&cp);
  413.     }
  414.  
  415. /*----------------------------------------------------------------------+
  416. |                                    |
  417. | name        scaleFence - scale the fence                |
  418. |                                    |
  419. | author    BSI                    7/86        |
  420. |                                    |
  421. +----------------------------------------------------------------------*/
  422. Private void    scaleFence
  423. (
  424. Dpoint3d    *point
  425. )
  426.     {
  427.     eraseFence ();
  428.     scaleElement (dgnBuf, point, tcb->xactscle,
  429.             tcb->yactscle, tcb->zactscle, fenceCommandView);
  430.     redrawFence();
  431.     }
  432.  
  433. /*----------------------------------------------------------------------+
  434. |                                    |
  435. | name        startFenceScale                     |
  436. |                                    |
  437. | author    BSI                     5/90        |
  438. |                                    |
  439. +----------------------------------------------------------------------*/
  440. Private void    startFenceScale
  441. (
  442. void
  443. )
  444.     {
  445.     int        fenceCommand, clipMode, (*contentFunc)();
  446.  
  447.     /* set up proper locate criteria depending on copy mode */
  448.     if (copyMode)
  449.     {
  450.     contentFunc  = fenceModify_transformCopy;
  451.     fenceCommand = 117;
  452.     clipMode     = FENCE_CLIP_COPY;
  453.     mdlLocate_allowLocked ();
  454.     }
  455.     else
  456.     {
  457.     contentFunc  = fenceModify_transformOrig;
  458.     fenceCommand = 116;
  459.     clipMode     = FENCE_CLIP_ORIG;
  460.     mdlLocate_normal ();
  461.     }
  462.  
  463.     mdlState_startFenceCommand
  464.     (
  465.         contentFunc,
  466.         scaleFence,
  467.         scaleFenceDataFunc,
  468.         endFenceCommand,
  469.         -fenceCommand,
  470.         -132,
  471.         clipMode
  472.     );
  473.     
  474.     if (!tcb->wssect)
  475.     {
  476.     mdlFence_toShape (dgnBuf);
  477.     mdlState_dynamicUpdate (scaleDynamics, 1);
  478.     }
  479.     }
  480.  
  481. /*----------------------------------------------------------------------+
  482. |                                    |
  483. | name        fenceScale - parse input for the fence scale cmd    |
  484. |                                    |
  485. | author    BSI                    7/86        |
  486. |                                    |
  487. +----------------------------------------------------------------------*/
  488. Public void    fenceScale
  489. (
  490. void
  491. cmdNumber    CMD_MFENCE_SCALE_ORIGINAL,
  492.         CMD_MFENCE_SCALE_COPY
  493.     {
  494.     copyMode   = ((mdlCommandNumber & 0xff00) >> 8) == SCALE_COPY;
  495.     startFenceScale ();
  496.     }
  497.     
  498. /*----------------------------------------------------------------------+
  499. |                                    |
  500. |    SPIN FENCE functions                        |
  501. |                                    |
  502. +----------------------------------------------------------------------*/
  503. /*----------------------------------------------------------------------+
  504. |                                    |
  505. | name        spinElement_getTransform                 |
  506. |                                    |
  507. | author    BSI                     5/90        |
  508. |                                    |
  509. +----------------------------------------------------------------------*/
  510. Public int    spinElement_getTransform
  511. (
  512. Transform   *trans,
  513. int        view,
  514. Dpoint3d    *point
  515. )
  516.     {
  517.     Dpoint3d    vec;
  518.     double    angle;
  519.     RotMatrix    rMatrix;
  520.  
  521.     if (mdlVec_pointEqual (&anchorPoint, point))
  522.     return    ERROR;
  523.  
  524.     mdlVec_subtractPoint (&vec, point, &anchorPoint);
  525.     mdlRMatrix_fromView (&rMatrix, view, FALSE);
  526.     mdlRMatrix_rotatePoint (&vec, (RotMatrix *)tcb->view[view].transmatrx);
  527.  
  528.     angle = atan2 (vec.y, vec.x);
  529.     rotateElement_getTransform (trans, view, angle, &anchorPoint);
  530.     return  SUCCESS;
  531.     }
  532.  
  533. /*----------------------------------------------------------------------+
  534. |                                    |
  535. | name        spin_element                        |
  536. |                                    |
  537. | author    BSI                    10/87        |
  538. |                                    |
  539. +----------------------------------------------------------------------*/
  540. Public int    spinElement
  541. (
  542. MSElementUnion    *element,        /* <=> element to be spun */
  543. Dpoint3d    *rotPoint        /*  => point to spin about */
  544. )
  545.     {
  546.     Transform    transform;
  547.  
  548.     if (spinElement_getTransform (&transform, fenceCommandView, rotPoint) 
  549.         == ERROR)
  550.     return SUCCESS;
  551.  
  552.     return mdlElement_transform (element, element, &transform);
  553.     }
  554.  
  555. /*----------------------------------------------------------------------+
  556. |                                    |
  557. | name        spinFence - moves the fence to a new position        |
  558. |                                    |
  559. | author    BSI                    10/87        |
  560. |                                    |
  561. +----------------------------------------------------------------------*/
  562. Private void    spinFence
  563. (
  564. Dpoint3d    *point
  565. )
  566.     {
  567.     if (tcb->wssect)
  568.     return;
  569.  
  570.     eraseFence();
  571.  
  572.     if (spinElement (dgnBuf, point))
  573.     {
  574.     mdlOutput_rscPrintf (MSG_ERROR, NULL, MESSAGEID_Messages,
  575.                  MSGID_OffDesignPlane);
  576.     return;
  577.     }
  578.  
  579.     redrawFence();
  580.     }
  581.  
  582. /*----------------------------------------------------------------------+
  583. |                                    |
  584. | name        fenceSpinDataFunc                     |
  585. |                                    |
  586. | author    BSI                     5/90        |
  587. |                                    |
  588. +----------------------------------------------------------------------*/
  589. Private void    fenceSpinDataFunc
  590. (
  591. Dpoint3d    *point,
  592. int        view
  593. )
  594.     {
  595.     FenceCopyParams        cp;
  596.  
  597.     /* zero out all copy parameters structure */
  598.     memset (&cp, 0, sizeof(cp));
  599.  
  600.     spinElement_getTransform (&cp.transform, view, point);
  601.     mdlFence_process (&cp);
  602.  
  603.     /* free memory allocated for graphic group remapping */
  604.     mdlModify_freeGGMap ((MdlCopyParams *)&cp);
  605.     }
  606.  
  607. /*----------------------------------------------------------------------+
  608. |                                    |
  609. | name        spinDynamics                        |
  610. |                                    |
  611. | author    BSI                    10/87        |
  612. |                                    |
  613. +----------------------------------------------------------------------*/
  614. Public void    spinDynamics
  615. (
  616. Dpoint3d    *point
  617. )
  618.     {
  619.     spinElement (dgnBuf, point);
  620.     }
  621.  
  622. /*----------------------------------------------------------------------+
  623. |                                    |
  624. | name        fenceSpin_firstPoint - define point for spin origin    |
  625. |                                    |
  626. | author    BSI                    10/87        |
  627. |                                    |
  628. +----------------------------------------------------------------------*/
  629. Private void    fenceSpin_firstPoint
  630. (
  631. Dpoint3d    *point,
  632. int        view
  633. )
  634.     {
  635.     anchorPoint        = *point;
  636.     fenceCommandView    = view;
  637.  
  638.     if (!tcb->wssect)
  639.     {
  640.     mdlFence_toShape (dgnBuf);
  641.     mdlState_dynamicUpdate (spinDynamics, 1);
  642.     }
  643.  
  644.     /* change data point function to one that processes fence */
  645.     mdlState_setFunction (STATE_DATAPOINT, fenceSpinDataFunc);
  646.  
  647.      mdlOutput_rscPrintf (MSG_PROMPT, NULL, MESSAGEID_Messages,
  648.                  MSGID_ProcessFence);
  649.     }
  650.  
  651. /*----------------------------------------------------------------------+
  652. |                                    |
  653. | name        startFenceSpin                        |
  654. |                                    |
  655. | author    BSI                     6/91        |
  656. |                                    |
  657. +----------------------------------------------------------------------*/
  658. Private void    startFenceSpin
  659. (
  660. void
  661. )
  662.     {
  663.     int        fenceCommand, clipMode, (*contentFunc)();
  664.  
  665.     /* set up proper locate criteria depending on copy mode */
  666.     if (copyMode)
  667.     {
  668.     contentFunc  = fenceModify_transformCopy;
  669.     fenceCommand = 323;
  670.     clipMode     = FENCE_CLIP_COPY;
  671.     mdlLocate_allowLocked ();
  672.     }
  673.     else
  674.     {
  675.     contentFunc  = fenceModify_transformOrig;
  676.     fenceCommand = 322;
  677.     clipMode     = FENCE_CLIP_ORIG;
  678.     mdlLocate_normal ();
  679.     }
  680.  
  681.     mdlState_startFenceCommand
  682.     (
  683.         contentFunc,
  684.         spinFence,
  685.         fenceSpin_firstPoint,
  686.         startFenceSpin,
  687.         -fenceCommand,
  688.         -355,
  689.         clipMode
  690.     );
  691.     }
  692.  
  693. /*----------------------------------------------------------------------+
  694. |                                    |
  695. | name        fenceSpin - parse input for the fence spin cmd        |
  696. |                                    |
  697. | author    BSI                    10/87        |
  698. |                                    |
  699. +----------------------------------------------------------------------*/
  700. Private void    fenceSpin
  701. (
  702. void
  703. ) cmdNumber
  704.         CMD_MFENCE_SPIN_ORIGINAL,
  705.         CMD_MFENCE_SPIN_COPY
  706.     {
  707.     copyMode   = ((mdlCommandNumber & 0xff00) >> 8) == SPIN_COPY;
  708.  
  709.     startFenceSpin ();
  710.     }
  711.  
  712.