home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk21 / dir04 / f014300.re_ / f014300.re
Text File  |  1996-04-02  |  16KB  |  576 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/doc/create.mcv  $
  18. |   $Workfile:   create.mc  $
  19. |   $Revision:   5.5  $
  20. |       $Date:   20 Jun 1995 08:49:38  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   create.mc - examples for the mdlXXXX_create functions.        |
  26. |                                    |
  27. |   This file is intended as an adjunct to the MDL manual to        |
  28. |   illustrate MDL built-in function calling conventions and parameter    |
  29. |   values. While it can be compiled, it does NOT, on its own,        |
  30. |   constitute a workable MDL example.                    |
  31. |                                    |
  32. +----------------------------------------------------------------------*/
  33. /*----------------------------------------------------------------------+
  34. |                                    |
  35. |   Include Files                               |
  36. |                                    |
  37. +----------------------------------------------------------------------*/
  38. #include    <mdl.h>        /* system include files */
  39. #include    <global.h>
  40. #include    <mselems.h>
  41. #include    <tcb.h>
  42. #include    <userpref.h>
  43. #include    <widechar.h>
  44. #include    <mselemen.fdf>
  45.  
  46. /*----------------------------------------------------------------------+
  47. |                                    |
  48. | name        placeAShape                         |
  49. |                                    |
  50. | author    BSI                     8/90        |
  51. |                                    |
  52. +----------------------------------------------------------------------*/
  53. Private void    placeAShape 
  54. (
  55. void
  56. )
  57.     {
  58.     Dpoint3d    shapePts[3];
  59.     MSElementUnion    shape;
  60.  
  61.     shapePts[0].x = fc_zero;
  62.     shapePts[0].y = 1.0;
  63.     shapePts[0].z = fc_zero;
  64.     shapePts[1].x = 100.0;
  65.     shapePts[1].y = 200.0;
  66.     shapePts[1].z = fc_zero;
  67.     shapePts[2].x = 300.0;
  68.     shapePts[2].y = 400.0;
  69.     shapePts[2].z = fc_zero;
  70.  
  71.     if (mdlShape_create (&shape, NULL, shapePts, 3, -1) == SUCCESS)
  72.     {
  73.     mdlElement_display (&shape, NORMALDRAW);
  74.     mdlElement_add (&shape);
  75.     }
  76.     }
  77.  
  78. /*----------------------------------------------------------------------+
  79. |                                    |
  80. | name        placeALineString                    |
  81. |                                    |
  82. | author    BSI                     8/90        |
  83. |                                    |
  84. +----------------------------------------------------------------------*/
  85. Private void    placeALineString
  86. (
  87. Dpoint3d    *lsPoints,
  88. int        numVerts
  89. )
  90.     {
  91.     MSElementUnion    lineString;
  92.  
  93.     if (mdlLineString_create (&lineString, NULL, lsPoints, numVerts) 
  94.             == SUCCESS)
  95.     {
  96.     mdlElement_display (&lineString, NORMALDRAW);
  97.     mdlElement_add (&lineString);
  98.     }
  99.     }
  100.  
  101. /*----------------------------------------------------------------------+
  102. |                                    |
  103. | name        placeAnArc                         |
  104. |                                    |
  105. | author    BSI                     8/90        |
  106. |                                    |
  107. +----------------------------------------------------------------------*/
  108. Private void    placeAnArc 
  109. (
  110. MSElementUnion        *existingArc
  111. )    
  112.     {
  113.     Dpoint3d    center;
  114.     MSElementUnion    arc;
  115.     
  116.     center.x = 100.0;
  117.     center.y = 100.0;
  118.     center.z = 100.0;
  119.     
  120.     if (mdlArc_create (&arc, existingArc, ¢er, 100.0, 200.0, 
  121.         NULL, fc_zero, fc_pi) ==  SUCCESS)
  122.     {
  123.     mdlElement_display (&arc, NORMALDRAW);
  124.     mdlElement_add (&arc);
  125.     }
  126.     }
  127.  
  128. /*----------------------------------------------------------------------+
  129. |                                    |
  130. | name        placeAnArcByPoints                     |
  131. |                                    |
  132. | author    BSI                     8/90        |
  133. |                                    |
  134. +----------------------------------------------------------------------*/
  135. Private void    placeAnArcByPoints 
  136. (
  137. void
  138. )
  139.     {
  140.     MSElementUnion    arc;
  141.     Dpoint3d        arcPt[3];
  142.     
  143.     arcPt[0].x = 20.;        /* start point */
  144.     arcPt[0].y = 30.;
  145.     arcPt[0].z = fc_zero;
  146.     arcPt[1].x = 50.;        /* mid point */
  147.     arcPt[1].y = 60.;
  148.     arcPt[1].z = fc_zero;
  149.     arcPt[2].x = 20.;        /* end point */
  150.     arcPt[2].y = 80.;
  151.     arcPt[2].z = fc_zero;
  152.  
  153.     if (mdlArc_createByPoints (&arc, NULL, arcPt) ==  SUCCESS)
  154.     {
  155.     mdlElement_display (&arc, NORMALDRAW);
  156.     mdlElement_add (&arc);
  157.     }
  158.     }
  159.  
  160. /*----------------------------------------------------------------------+
  161. |                                    |
  162. | name        placeAnArcByCenter                     |
  163. |                                    |
  164. | author    BSI                     8/90        |
  165. |                                    |
  166. +----------------------------------------------------------------------*/
  167. Private void    placeAnArcByCenter
  168. (
  169. int    view
  170. )
  171.     {
  172.     MSElementUnion  arc;
  173.     Dpoint3d        arcPt[3];
  174.     
  175.     arcPt[0].x = 20.;        /* start point */
  176.     arcPt[0].y = 30.;
  177.     arcPt[0].z = fc_zero;
  178.     arcPt[1].x = 50.;        /* center */
  179.     arcPt[1].y = 30.;
  180.     arcPt[1].z = fc_zero;
  181.     arcPt[2].x = 80.;        /* end point */
  182.     arcPt[2].y = 30.;
  183.     arcPt[2].z = fc_zero;
  184.  
  185.     /* create an arc with a radius of 44.0 and center at [50,30,0] */
  186.     if (mdlArc_createByCenter (&arc, NULL, arcPt, TRUE, 44.0, view) 
  187.             == SUCCESS)
  188.     {
  189.     mdlElement_display (&arc, NORMALDRAW);
  190.     mdlElement_add (&arc);
  191.     }
  192.     }
  193.  
  194. /*----------------------------------------------------------------------+
  195. |                                    |
  196. | name        placeEllipse                         |
  197. |                                    |
  198. | author    BSI                     8/90        |
  199. |                                    |
  200. +----------------------------------------------------------------------*/
  201. Private void    placeEllipse 
  202. (
  203. void
  204. )
  205.     {
  206.     MSElementUnion  ellipse;
  207.     Dpoint3d        center;
  208.  
  209.     center.x = 100.0;
  210.     center.y = 100.0;
  211.     center.z = 100.0;
  212.  
  213.     if (mdlEllipse_create (&ellipse, NULL, ¢er, 10.0, 15.0, 
  214.                 NULL, -1) ==  SUCCESS)
  215.     {
  216.     mdlElement_display (&ellipse, NORMALDRAW);
  217.     mdlElement_add (&ellipse);
  218.     }
  219.     }
  220.  
  221. /*----------------------------------------------------------------------+
  222. |                                    |
  223. | name        placeCircleByPoints                     |
  224. |                                    |
  225. | author    BSI                     8/90        |
  226. |                                    |
  227. +----------------------------------------------------------------------*/
  228. Private void    placeCircleByPoints 
  229. (
  230. void
  231. )
  232.     {
  233.     MSElementUnion  circle;
  234.     Dpoint3d        circlePt[3];
  235.  
  236.     circlePt[0].x = 200.;
  237.     circlePt[0].y = 300.;
  238.     circlePt[0].z = 000.;
  239.     circlePt[1].x = 500.;
  240.     circlePt[1].y = 600.;
  241.     circlePt[1].z = 000.;
  242.     circlePt[2].x = 200.;
  243.     circlePt[2].y = 800.;
  244.     circlePt[2].z = 000.;
  245.  
  246.     if (mdlCircle_createBy3Pts (&circle, NULL, circlePt, -1) ==  SUCCESS)
  247.     {
  248.     mdlElement_display (&circle, NORMALDRAW);
  249.     mdlElement_add (&circle);
  250.     }
  251.     }
  252.  
  253. /*----------------------------------------------------------------------+
  254. |                                    |
  255. | name        placeText                         |
  256. |                                    |
  257. | author    BSI                     8/90        |
  258. |                                    |
  259. +----------------------------------------------------------------------*/
  260. Private void    placeText 
  261. (
  262. MSElementUnion    *currentText,
  263. long        textPos
  264. )
  265.     {
  266.     MSElementUnion    text;
  267.     Dpoint3d        pt[3];
  268.     TextSizeParam    txtSize;
  269.     TextParam        txtParam;
  270.     TextEDField        edFields[2];
  271.     TextEDParam        edParam;
  272.  
  273.     pt[0].x = 285.;    /* origin of text element */
  274.     pt[0].y = 450.;
  275.     pt[0].z = fc_zero;
  276.  
  277.     txtSize.mode    = TXT_BY_TEXT_SIZE;
  278.     txtSize.size.width    = fc_2;
  279.     txtSize.size.height    = 3.;
  280.     txtParam.font    = 2;
  281.     txtParam.just    = -1;    /* use active justification */
  282.     txtParam.style    = -1;    /* use active style */
  283.     txtParam.viewIndependent = FALSE;
  284.  
  285.     edFields[0].start    = 1;
  286.     edFields[0].len    = 2;
  287.     edFields[0].just    = 2;
  288.     edFields[1].start    = 5;
  289.     edFields[1].len    = 1;
  290.     edFields[1].just    = 3;
  291.  
  292.     edParam.numEDFields    = 2;
  293.     edParam.edField    = edFields;
  294.  
  295.     /* create a new text element */
  296.     if (mdlText_create (&text, NULL, "this text placed in MDL", pt,
  297.             &txtSize, NULL, &txtParam, &edParam) == SUCCESS)
  298.     {
  299.     mdlElement_display (&text, NORMALDRAW);
  300.     mdlElement_add (&text);
  301.     }
  302.  
  303.     /* overwrite an existing text element without changing parameters */
  304.     if (mdlText_create (&text, currentText, "overwritten text",
  305.              NULL, NULL, NULL, NULL, NULL) == SUCCESS)
  306.     {
  307.     mdlElement_rewrite (&text, currentText, textPos);
  308.     mdlElement_display (&text, NORMALDRAW);
  309.     }
  310.     }
  311.  
  312. /*----------------------------------------------------------------------+
  313. |                                    |
  314. | name        placeTextNode                         |
  315. |                                    |
  316. | author    BSI                     8/90        |
  317. |                                    |
  318. +----------------------------------------------------------------------*/
  319. Private void    placeTextNode 
  320. (
  321. void
  322. )
  323.     {
  324.     MSElementUnion  textNode;
  325.     Dpoint3d        origin;
  326.     MSTextSize        nodeSize;
  327.     TextParam        txtParam;
  328.     double        lineSpacing;
  329.  
  330.     origin.x        = 100.;
  331.     origin.y        = 200.;
  332.     origin.z         = 0.;
  333.     nodeSize.width     = 10.;
  334.     nodeSize.height    = 13.;
  335.     lineSpacing     = 1.1;
  336.     txtParam.font    = 2;
  337.     txtParam.just    = -1;    /* use active justification */
  338.     txtParam.style    = -1;    /* use active style */
  339.     txtParam.viewIndependent = FALSE;
  340.  
  341.     if (mdlTextNode_create (&textNode, NULL, &origin, NULL, &lineSpacing,
  342.             &nodeSize, &txtParam) == SUCCESS)
  343.     {
  344.     mdlElement_display (&textNode, NORMALDRAW);
  345.     mdlElement_add (&textNode);
  346.     }
  347.     }
  348.  
  349. /*----------------------------------------------------------------------+
  350. |                                                                       |
  351. | name          text_getExtendedParam                                  |
  352. |                                                                       |
  353. |        sets flags and values for extended text attributes    |
  354. |        (slant, underline, character spacing, and direction)    |
  355. |        according to tcb and userpref                |
  356. |                                    |
  357. | author        BSI                                    4/93            |
  358. |                                                                       |
  359. +----------------------------------------------------------------------*/
  360. Public void    text_setExtendedParam
  361. (
  362. TextParamWide   *textParam    /* <= flags, slant, spacing, etc. */
  363. )
  364.     {
  365.     /* TextDrawFlags tells the existence of slant, inter-character spacing,
  366.        underline, and vertical direction.    Set all flags to zero first. */
  367.     memset (&textParam->flags, 0, sizeof(TextDrawFlags));
  368.  
  369.     /* Convert tcb->textSlant from degree to radian.
  370.        Set flags.slant only if slant value is not zero */
  371.     if (fabs(tcb->textSlant) > fc_epsilon)
  372.     {
  373.     textParam->flags.slant = TRUE;
  374.     textParam->slant = tcb->textSlant * fc_piover180;
  375.     }
  376.  
  377.     if (tcb->textDirection & TXTDIR_VERTICAL)    /* vertical direction */
  378.     textParam->flags.vertical = TRUE;
  379.  
  380.     /* user preference tells if fixed-width mode or inter-character mode */
  381.     if (userPrefsP->extFlags.fixedWidthCharSpace)
  382.     {
  383.     textParam->flags.fixedWidthSpacing = TRUE;
  384.  
  385.     /* if char spacing is 0, igonore it otherwide characters are
  386.        stacked together */
  387.     if (fabs(tcb->textAboveSpacing) < fc_epsilon)
  388.         textParam->characterSpacing =
  389.         textParam->flags.vertical ? tcb->chheight : tcb->chwidth;
  390.     else
  391.         textParam->characterSpacing = tcb->textAboveSpacing;
  392.     }
  393.     else if (fabs(tcb->textAboveSpacing) > fc_epsilon)
  394.     {
  395.     textParam->flags.interCharSpacing = TRUE;
  396.     textParam->characterSpacing = tcb->textAboveSpacing;
  397.     }
  398.  
  399.     if (tcb->textUnderline)
  400.     {
  401.     textParam->flags.underline = TRUE;
  402.     textParam->underlineSpacing = tcb->chheight * 
  403.                 userPrefsP->textUnderlineSpace * fc_p01;
  404.     }
  405.     }
  406.  
  407. /*----------------------------------------------------------------------+
  408. |                                    |
  409. | name        placeTextWide                         |
  410. |                                    |
  411. | author    BSI                     7/93        |
  412. |                                    |
  413. +----------------------------------------------------------------------*/
  414. Private void    placeTextWide
  415. (
  416. MSElementUnion    *currentText,
  417. long        textPos
  418. )
  419.     {
  420.     MSElementUnion    text;
  421.     Dpoint3d        pt[3];
  422.     TextSizeParam    txtSize;
  423.     TextParamWide    txtParam;
  424.     TextEDField        edFields[2];
  425.     TextEDParam        edParam;
  426.     char        *string1 = "this text placed in MDL";
  427.     char        *string2 = "overwritten text";
  428.     MSWideChar        wString1[50], wString2[50];
  429.  
  430.     /* convert to wide-character string - the third argument is the size
  431.        of wString, see "stdlib.h" for details */
  432.     mbstowcs (wString1, string1, 50);
  433.     mbstowcs (wString2, string2, 50);
  434.  
  435.     pt[0].x = 285.;    /* origin of text element */
  436.     pt[0].y = 450.;
  437.     pt[0].z = fc_zero;
  438.  
  439.     txtSize.mode    = TXT_BY_TEXT_SIZE;
  440.     txtSize.size.width    = fc_2;
  441.     txtSize.size.height    = 3.;
  442.     txtParam.font    = 2;
  443.     txtParam.just    = -1;    /* use active justification */
  444.     txtParam.style    = -1;    /* use active style */
  445.     txtParam.viewIndependent = FALSE;
  446.  
  447.     /* set extended params (slant, underline, char spacing, and direction) */
  448.     text_setExtendedParam (&txtParam);
  449.  
  450.     edFields[0].start    = 1;
  451.     edFields[0].len    = 2;
  452.     edFields[0].just    = 2;
  453.     edFields[1].start    = 5;
  454.     edFields[1].len    = 1;
  455.     edFields[1].just    = 3;
  456.  
  457.     edParam.numEDFields    = 2;
  458.     edParam.edField    = edFields;
  459.  
  460.     /* create a new text element */
  461.     if (mdlText_createWide (&text, NULL, wString1, pt, NULL,
  462.             &txtSize, &txtParam, &edParam) == SUCCESS)
  463.     {
  464.     mdlElement_display (&text, NORMALDRAW);
  465.     mdlElement_add (&text);
  466.     }
  467.  
  468.     /* overwrite an existing text element without changing parameters */
  469.     if (mdlText_createWide (&text, currentText, wString2,
  470.              NULL, NULL, NULL, NULL, NULL) == SUCCESS)
  471.     {
  472.     mdlElement_rewrite (&text, currentText, textPos);
  473.     mdlElement_display (&text, NORMALDRAW);
  474.     }
  475.     }
  476.  
  477. /*----------------------------------------------------------------------+
  478. |                                    |
  479. | name        placeTextNodeWide                    |
  480. |                                    |
  481. | author    BSI                     7/93        |
  482. |                                    |
  483. +----------------------------------------------------------------------*/
  484. Private void    placeTextNodeWide
  485. (
  486. void
  487. )
  488.     {
  489.     MSElementUnion  textNode;
  490.     Dpoint3d        origin;
  491.     TextSizeParam   nodeSize;
  492.     TextParamWide   txtParam;
  493.  
  494.     origin.x        = 100.;
  495.     origin.y        = 200.;
  496.     origin.z         = 0.;
  497.     nodeSize.mode    = TXT_BY_TEXT_SIZE;
  498.     nodeSize.size.width    = 10.;
  499.     nodeSize.size.height= 13.;
  500.     txtParam.font    = 2;
  501.     txtParam.just    = -1;    /* use active justification */
  502.     txtParam.style    = -1;    /* use active style */
  503.     txtParam.viewIndependent = FALSE;
  504.     txtParam.lineSpacing = tcb->nodespace;
  505.  
  506.     /* set extended params (slant, underline, char spacing, and direction) */
  507.     text_setExtendedParam (&txtParam);
  508.  
  509.     if (mdlTextNode_createWide (&textNode, NULL, &origin, NULL,
  510.             &nodeSize, &txtParam) == SUCCESS)
  511.     {
  512.     mdlElement_display (&textNode, NORMALDRAW);
  513.     mdlElement_add (&textNode);
  514.     }
  515.     }
  516.  
  517. /*----------------------------------------------------------------------+
  518. |                                    |
  519. | name        placeCone                         |
  520. |                                    |
  521. | author    BSI                     8/90        |
  522. |                                    |
  523. +----------------------------------------------------------------------*/
  524. Private void    placeCone 
  525. (
  526. RotMatrix   *rMatrix
  527. )    
  528.     {
  529.     MSElementUnion  cone;
  530.     Dpoint3d        conePts[2];
  531.  
  532.     conePts[0].x = 100.;
  533.     conePts[0].y = 200.;
  534.     conePts[0].z = 0.;
  535.     conePts[1].x = 100.;
  536.     conePts[1].y = 200.;
  537.     conePts[1].z = 10.;
  538.  
  539.     if (mdlCone_create (&cone, NULL, 2.0, 1.0, &conePts[0], &conePts[1],
  540.             rMatrix) == SUCCESS)
  541.     {
  542.     mdlElement_display (&cone, NORMALDRAW);
  543.     mdlElement_add (&cone);
  544.     }
  545.     }
  546.  
  547. /*----------------------------------------------------------------------+
  548. |                                    |
  549. | name        .                            |
  550. |                                    |
  551. | author    BSI                     8/90        |
  552. |                                    |
  553. +----------------------------------------------------------------------*/
  554. Private void    placeCylinder 
  555. (
  556. void
  557. )
  558.     {
  559.     MSElementUnion  cone;
  560.     Dpoint3d        conePts[2];
  561.  
  562.     conePts[0].x = 100.;
  563.     conePts[0].y = 200.;
  564.     conePts[0].z = 0.;
  565.     conePts[1].x = 100.;
  566.     conePts[1].y = 200.;
  567.     conePts[1].z = 10.;
  568.  
  569.     if (mdlCone_createRightCylinder (&cone, NULL, 2.0, &conePts[0],
  570.                      &conePts[1]) == SUCCESS)
  571.     {
  572.     mdlElement_display (&cone, NORMALDRAW);
  573.     mdlElement_add (&cone);
  574.     }
  575.     }
  576.