home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk22 / dir03 / f014330.re_ / f014330.re
Text File  |  1996-04-02  |  8KB  |  269 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/element.mcv  $
  18. |   $Workfile:   element.mc  $
  19. |   $Revision:   5.2  $
  20. |       $Date:   20 Jun 1995 08:49:54  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   element.mc - examples for the mdlElement_ 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.             
  42. /*----------------------------------------------------------------------+
  43. |                                    |
  44. |    local defines                            |
  45. |                                    |
  46. +----------------------------------------------------------------------*/
  47. #define        MASTER_FILE        0
  48.  
  49. /*----------------------------------------------------------------------+
  50. |                                    |
  51. | name        incrementColor                        |
  52. |                                    |
  53. | author    BSI                     8/90        |
  54. |                                    |
  55. +----------------------------------------------------------------------*/
  56. Public void    incrementColor
  57. (
  58. MSElement   *element
  59. )
  60.     {
  61.     int        color;
  62.     int        true=TRUE, false=FALSE;
  63.  
  64.     /* get the current color from the element */
  65.     mdlElement_getSymbology (&color, NULL, NULL, element);
  66.  
  67.     /* increment it (wrap if necessary) */
  68.     if (++color >= 256)
  69.     color = 0;
  70.  
  71.     /* set the new color in the element */
  72.     mdlElement_setSymbology (element, &color, NULL, NULL);
  73.  
  74.     /* mark the element as "not-new" and "modified" */
  75.     mdlElement_setProperties (element, NULL, NULL, NULL, NULL,
  76.             &false, &true, NULL, NULL);
  77.     }
  78.  
  79. /*----------------------------------------------------------------------+
  80. |                                    |
  81. | name        incrementLevel                        |
  82. |                                    |
  83. | author    BSI                     8/90        |
  84. |                                    |
  85. +----------------------------------------------------------------------*/
  86. Public void    incrementLevel
  87. (
  88. MSElement   *element
  89. )
  90.     {
  91.     int        level, gg, locked;
  92.     int        true=TRUE, false=FALSE;
  93.  
  94.     /* get the current level from the element */
  95.     mdlElement_getProperties (&level, &gg, NULL, &locked, NULL, NULL, NULL, 
  96.         NULL, element);
  97.  
  98.     /* don't do members of a graphic group or locked elements */
  99.     if (gg==0 && !locked)
  100.     {
  101.     if (++level > 63)
  102.         {
  103.         /* set the level and mart element as "not-new" and "modified" */
  104.         mdlElement_setProperties (element, level, NULL, NULL, NULL,
  105.             &false, &true, NULL, NULL);
  106.         }
  107.     }
  108.     }
  109.  
  110. /*----------------------------------------------------------------------+
  111. |                                    |
  112. | name        placeNewLine                         |
  113. |                                    |
  114. | author    BSI                     8/90        |
  115. |                                    |
  116. +----------------------------------------------------------------------*/
  117. Public void    placeNewLine
  118. (
  119. Dpoint3d    *linePts,    /* => points defining line */
  120. ULong        *filePos    /* <= filePosition of new element */
  121. )
  122.     {
  123.     MSElement    line;
  124.  
  125.     if (mdlLine_create (&line, NULL, linePts) == SUCCESS)
  126.     {
  127.     mdlElement_display (&line, NORMALDRAW);
  128.     if ((*filePos = mdlElement_add (&line)) == 0L)
  129.         {
  130.         mdlOutput_printf (MSG_ERROR,"error adding element, %d", mdlErrno);
  131.         }
  132.     }
  133.     }
  134.  
  135. /*----------------------------------------------------------------------+
  136. |                                    |
  137. | name        changeLine                        |
  138. |                                    |
  139. | author    BSI                     8/90        |
  140. |                                    |
  141. +----------------------------------------------------------------------*/
  142. Public void    changeLine
  143. (
  144. Dpoint3d    *linePts,    /*  => points defining line */
  145. MSElement   *oldLine,    /*  => existing line element */
  146. ULong        *filePos    /* <=> file position of line */
  147. )
  148.     {
  149.     MSElementUnion  line;
  150.  
  151.     /* make sure they passed us a line element */
  152.     if (mdlElement_getType (oldLine) != LINE_ELM)
  153.     return;
  154.  
  155.     if (mdlLine_create (&line, oldLine, linePts) == SUCCESS)
  156.     {
  157.     if ((*filePos = mdlElement_rewrite (&line, oldLine, *filePos)) == 0L)
  158.         {
  159.         mdlOutput_printf (MSG_ERROR, "error changing element, %d", 
  160.             mdlErrno);
  161.         }
  162.     else
  163.         {
  164.         mdlElement_display (oldLine, ERASE);
  165.         mdlElement_display (&line,   NORMALDRAW);
  166.         }
  167.     }
  168.     }
  169.  
  170. /*----------------------------------------------------------------------+
  171. |                                    |
  172. | name        deletePoints - delete "point" elements          |
  173. |                                    |
  174. | author    BSI                     8/90        |
  175. |                                    |
  176. +----------------------------------------------------------------------*/
  177. Public void    deletePoints 
  178. (
  179. MSElement   *oldLine,    /* => existing line element */
  180. ULong        filePos,    /* => file position of line */
  181. int        fileNum
  182. )
  183.     {
  184.     Dpoint3d    linePts[MAX_VERTICES];
  185.     int        numVerts;
  186.  
  187.     /* delete any "point" elements (those with 2 vertices the same) */
  188.     if (mdlLinear_extract (linePts, &numVerts, oldLine, fileNum) == SUCCESS)
  189.     {
  190.     if (numVerts == 2 && mdlVec_pointEqual (linePts, linePts+1))
  191.         {
  192.         mdlElement_undoableDelete (oldLine, filePos, TRUE);
  193.         }
  194.     }
  195.     }
  196.  
  197. /*----------------------------------------------------------------------+
  198. |                                    |
  199. | name        moveAttributes                         |
  200. |                                    |
  201. | author    BSI                     8/90        |
  202. |                                    |
  203. +----------------------------------------------------------------------*/
  204. Public void    moveAttributes 
  205. (
  206. MSElement    *oldElem,    /*  => old element */
  207. MSElement    *newElem    /* <=> new element */
  208. )
  209.     {
  210.     short    attributes[MAX_ATTRIBSIZE];
  211.     int        attribLen;
  212.  
  213.     /* copy all of the attributes from the old element to the
  214.     new one, appending them to any existing attributes. Then
  215.     clear the attributes from the original element. */
  216.     mdlElement_extractAttributes (&attribLen, attributes, oldElem);
  217.     mdlElement_appendAttributes (newElem, attribLen, attributes);
  218.     
  219.     mdlElement_stripAttributes (oldElem, oldElem);
  220.     }
  221.  
  222. /*----------------------------------------------------------------------+
  223. |                                    |
  224. | name        resetWorkingWindow - clear working window (if present)  |
  225. |                                    |
  226. | author    BSI                     7/90        |
  227. |                                    |
  228. +----------------------------------------------------------------------*/
  229. Public int    resetWorkingWindow  
  230.             /* <= returns SUCCESS if WW was set, ERROR otherwise */
  231. (
  232. void 
  233. )
  234.     {
  235.     /* get current "working window" (don't need fileNumber) */
  236.     if (mdlElement_getFilePos (FILEPOS_WORKING_WINDOW, NULL) != 0L)
  237.     {
  238.     mdlElement_setFilePos (FILEPOS_WORKING_WINDOW, MASTER_FILE, 0L);
  239.     mdlOutput_message ("Working window cleared");
  240.     return        SUCCESS;
  241.     }
  242.     return    ERROR;
  243.     }
  244.  
  245. /*----------------------------------------------------------------------+
  246. |                                    |
  247. | name        displayOneElementInOneView                |
  248. |                                    |
  249. | author    BSI                     1/91        |
  250. |                                    |
  251. +----------------------------------------------------------------------*/
  252. Private void    displayOneElementInOneView
  253. (
  254. int    fileNum,
  255. ULong    filePos,
  256. int    view
  257. )
  258.     {
  259.     MSElement    element;
  260.     
  261.     /* NOTE: This function would probably be better written using the 
  262.     mdlElmdscr_ functions so that complex elements would work as well. */
  263.  
  264.     if (mdlElement_read (&element, fileNum, filePos) == SUCCESS)
  265.     {
  266.     if (view>=0 && view<=7)
  267.         mdlElement_displayInSelectedViews (&element, NORMALDRAW, 1<<view);
  268.     }
  269.     }