home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk22 / dir02 / f014380.re_ / f014380.re
Text File  |  1996-04-02  |  9KB  |  247 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/locate.mcv  $
  18. |   $Workfile:   locate.mc  $
  19. |   $Revision:   1.2  $
  20. |       $Date:   20 Jun 1995 08:49:52  $
  21. |                                    |
  22. +----------------------------------------------------------------------*/
  23. /*----------------------------------------------------------------------+
  24. |                                    |
  25. |   locate.mc - examples for the mdlLocate_ 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>
  39. #include    <mselems.h>
  40. #include    <userfnc.h>
  41.     
  42. /*----------------------------------------------------------------------+
  43. |                                    |
  44. |   Local function declarations                     |
  45. |                                    |
  46. +----------------------------------------------------------------------*/
  47. int    editText(), replaceComponentDone();
  48.     
  49. /*----------------------------------------------------------------------+
  50. |                                    |
  51. | name        setTextSearchType                     |
  52. |                                    |
  53. | author    BSI                     7/90        |
  54. |                                    |
  55. +----------------------------------------------------------------------*/
  56. Private void    setTextSearchType
  57. (
  58. void
  59. )
  60.     {
  61.     static int  searchType[] = {TEXT_ELM, TEXT_NODE_ELM};
  62.  
  63.     /* set search criteria to find nothing */
  64.     mdlLocate_noElemNoLocked ();
  65.  
  66.     /* then add text elements and text nodes to list */
  67.     mdlLocate_setElemSearchMask (sizeof(searchType)/sizeof(searchType[0]), 
  68.         searchType);
  69.     }
  70.  
  71. /*----------------------------------------------------------------------+
  72. |                                    |
  73. | name        changeText_accept - called for data point on change    |
  74. |                       text single command            |
  75. |                                    |
  76. | author    BSI                     3/89        |
  77. |                                    |
  78. +----------------------------------------------------------------------*/
  79. Private void    changeText_accept
  80. (
  81. void
  82. )
  83.     {
  84.     ULong   filePos, compOffset;
  85.     int        currFile;
  86.  
  87.     filePos = mdlElement_getFilePos (FILEPOS_CURRENT, &currFile);
  88.  
  89.     /*  If there is a selection set active, process all elements in the set.
  90.     Of course, this processes all component text elements of a text node.
  91.     If no selection set is active, process ONLY the identified element.
  92.     This makes this command not apply to graphic groups (by design).
  93.     */
  94.  
  95.     if (mdlSelect_isActive())
  96.     {
  97.     mdlModify_elementMulti (currFile, filePos, MODIFY_REQUEST_NOHEADERS,
  98.             MODIFY_ORIG, editText, NULL, TRUE);
  99.     }
  100.     else
  101.     {
  102.     compOffset = mdlElement_getFilePos(FILEPOS_COMPONENT, NULL) - filePos;
  103.     mdlModify_elementSingle (currFile, filePos, MODIFY_REQUEST_ONLYONE,
  104.             MODIFY_ORIG, editText, NULL, compOffset);
  105.     }
  106.  
  107.     /* restart the element location process */
  108.     mdlLocate_restart (FALSE);
  109.     }
  110.  
  111. /*----------------------------------------------------------------------+
  112. |                                    |
  113. | name        doChangeSingle                        |
  114. |                                    |
  115. | author    BSI                     8/89        |
  116. |                                    |
  117. +----------------------------------------------------------------------*/
  118. Private void    doChangeSingle
  119. (
  120. void
  121. )
  122.     {
  123.     /* set up the MicroStation search mask to find only text elements */
  124.     setTextSearchType();
  125.  
  126.     /* tell MicroStation we want to start a "modification" command */
  127.     mdlState_startModifyCommand (doChangeSingle, changeText_accept, NULL,
  128.             NULL, NULL, 0, 1, TRUE, FALSE);
  129.  
  130.     /* set the internal locate pointers to start at beginning of file */
  131.     mdlLocate_init ();
  132.     }
  133.  
  134. /*----------------------------------------------------------------------+
  135. |                                                                       |
  136. | name          irrigationComponentsFilter                              |
  137. |                                                                       |
  138. |        Locate filter for REPLACE COMPONENT command.  Permits    |
  139. |        only irrigation elements to be selected.  The        |
  140. |        user attribute data on the element is checked to    |
  141. |        see if the element is an irrigation component.        |
  142. |                                                                       |
  143. | author        BSI                                     4/91            |
  144. |                                                                       |
  145. +----------------------------------------------------------------------*/
  146. Private int    irrigationComponentsFilter
  147. (
  148. int            preLocate,        /* => TRUE if pre-locate */
  149. MSElementUnion     *elementP        /* => current element */
  150. )    
  151.     {
  152.     UShort    *wordOffsetP;
  153.     int        componentData;
  154.     
  155.     /* check for irrigation component element */
  156.     if (!irrattr_extractComponentUserData (&componentData, 
  157.                       &wordOffsetP, elementP))
  158.     return    LOCATE_ELEMENT_NEUTRAL;
  159.     
  160.     return  LOCATE_ELEMENT_REJECT;
  161.     }
  162.                 
  163. /*----------------------------------------------------------------------+
  164. |                                                                       |
  165. | name          replaceComponentStart                    |
  166. |                                                                       |
  167. |        Start function for REPLACE COMPONENT command.        |
  168. |                                                                       |
  169. | author        BSI                                     4/91            |
  170. |                                                                       |
  171. +----------------------------------------------------------------------*/
  172. Private void    replaceComponentStart
  173. (
  174. char    *unparsedP    /* => unparsed part of command */
  175. )  
  176.     {
  177.     /* we need to locate any existing irrigation component */
  178.     mdlState_startModifyCommand (replaceComponentStart, replaceComponentDone,
  179.                  NULL, NULL, NULL, 0, 0, TRUE, 0);
  180.     
  181.     initializeComponentLocate ();
  182.     
  183.     /* filter elements based on user attribute data */
  184.     mdlLocate_setFunction (LOCATE_POSTLOCATE, irrigationComponentsFilter);
  185.  
  186.     if (!mdlSelect_isActive ())
  187.     util_displayPrompt (122);
  188.     }
  189.  
  190. /*----------------------------------------------------------------------+
  191. |                                    |
  192. | name        dataButtonHit                         |
  193. |                                    |
  194. | author    BSI                     2/91        |
  195. |                                    |
  196. +----------------------------------------------------------------------*/
  197. Private void    dataButtonHit 
  198. (
  199. Dpoint3d    *point,
  200. int        view
  201. )
  202.     {
  203.     Dpoint3d    closestPoint;
  204.     int        segment;
  205.     
  206.     if (!mdlLocate_findElement (point, view, 0, 0, FALSE))
  207.     mdlOutput_printf (MSG_STATUS, "Element not found");
  208.     else
  209.     {
  210.     mdlOutput_printf (MSG_STATUS, "ELEMENT FOUND: type=%d",
  211.         dgnBuf->ehdr.type);
  212.         
  213.     if (dgnBuf->ehdr.type == LINE_STRING_ELM)
  214.         {
  215.         mdlLocate_getProjectedPoint (&closestPoint, &segment, NULL);
  216.         mdlOutput_printf (MSG_PROMPT, 
  217.             "Locate point=[%d,%d,%d], segment=%d",
  218.             closestPoint.x, closestPoint.y, closestPoint.z, segment);
  219.         }
  220.     }
  221.     }
  222.  
  223. /*----------------------------------------------------------------------+
  224. |                                    |
  225. | name      locateElement - print out element type of elements pointed    |
  226. |        to by user.                        |
  227. |                                    |
  228. | author    BSI                     10/90        |
  229. |                                    |
  230. +----------------------------------------------------------------------*/
  231. cmdName        locateElement
  232. (
  233. void
  234. )
  235.     {
  236.     mdlState_startPrimitive (dataButtonHit, locateElement, 0, 0);
  237.  
  238.     /* reset the location logic */
  239.     mdlLocate_init();
  240.     
  241.     /* allow any element */
  242.     mdlLocate_allowLocked();
  243.     
  244.     /* change the cursor to be the "locate" cursor */
  245.     mdlLocate_setCursor();
  246.     }
  247.