home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 January / Chip_1997-01_cd.bin / ms95 / disk21 / dir04 / f017370.re_ / f017370.re
Text File  |  1996-04-02  |  14KB  |  397 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:   tagdisp.mc  $
  18. |   $Revision:   6.3  $
  19. |       $Date:   03 Oct 1995 10:54:16  $
  20. |                                    |
  21. +----------------------------------------------------------------------*/
  22. /*----------------------------------------------------------------------+
  23. |                                                                       |
  24. |   tagdisp.mc - Tag display source code.                               |
  25. |              Illustrates basic tag element manipulation concepts.     | 
  26. |                                    |
  27. +----------------------------------------------------------------------*/
  28. /*----------------------------------------------------------------------+
  29. |                                                                       |
  30. |   Include Files                                                       |
  31. |                                                                       |
  32. +----------------------------------------------------------------------*/
  33. #include <mdl.h>    /* MDL Library funcs structures & constants */
  34. #include <dlogitem.h>    /* Dialog Box Manager structures & constants */
  35. #include <mselems.h>    /* structures that define MicroStation elements */
  36. #include <rscdefs.h>    /* resource mgr structure definitions & constants */
  37. #include <scanner.h>    /* typedefs and defines for design file scanner */
  38. #include <mdlio.h>    /* File I/O definitions and data structs for MDL */
  39. #include <stdlib.h>
  40.  
  41. #include <dlogman.fdf>  /* Dialog Box Manager Function Prototypes */
  42. #include <mstagdat.fdf> /* Tag data function prototypes           */
  43. #include <mselemen.fdf>
  44. #include <mselmdsc.fdf>
  45. #include <msmisc.fdf>
  46. #include <msoutput.fdf>
  47. #include <mslocate.fdf>
  48. #include <msstate.fdf>
  49.  
  50.  
  51. #include "tagexmpl.h"    /* Contains Dialog Box IDs for this app */
  52. #include "tagexcmd.h"   /* Contains Command numbers for this app */
  53.  
  54. /*----------------------------------------------------------------------+
  55. |                                                                       |
  56. |   Local Function Declarations                                         |
  57. |                                                                       |
  58. +----------------------------------------------------------------------*/
  59. /*----------------------------------------------------------------------+
  60. |                                    |
  61. |   Private Global variables                        |
  62. |                                    |
  63. +----------------------------------------------------------------------*/
  64. /*-----------------------------------------------------------------------
  65.     The following variable is referenced in C expression strings used
  66.     by the toggle button item defined in tagdata.r.
  67. -----------------------------------------------------------------------*/
  68. extern DlogBoxInfo     *dlogBoxInfo;
  69.  
  70. /*----------------------------------------------------------------------+
  71. |                                    |
  72. |   Tagddisp Code Section                          |
  73. |                                    |
  74. +----------------------------------------------------------------------*/
  75. /*----------------------------------------------------------------------+
  76. |                                    |
  77. |   Functions for Locate logic                      |
  78. |                                    |
  79. +----------------------------------------------------------------------*/
  80. /*----------------------------------------------------------------------+
  81. |                                    |
  82. | name          tagdisp_setElmSearchType                        |
  83. |                                    |
  84. | author    BSI                     8/94        |
  85. |                                    |
  86. +----------------------------------------------------------------------*/
  87. Private void tagdisp_setElmSearchType 
  88. (
  89. void
  90. )
  91.     {
  92.     mdlLocate_normal ();
  93.     }
  94.  
  95. /*----------------------------------------------------------------------+
  96. |                                    |
  97. | name          tagdisp_changeDisplay                        |
  98. |                                    |
  99. | author    BSI                     8/94        |
  100. |                                    |
  101. +----------------------------------------------------------------------*/
  102. Private int tagdisp_changeDisplay
  103. (
  104. MSElementDescr *tagElmDescrP
  105. )
  106.     {
  107.     char     buf[100];
  108.     UShort     tagProps;
  109.     int     status = SUCCESS;
  110.     MSElement     newTagElm;
  111.     TagValue     value;
  112.     TagSpec     tagSpec;
  113.     boolean     displayable, createTag;
  114.  
  115.     createTag = FALSE;
  116.  
  117.     /*
  118.     //    Extract the tag specification, tag value, and displayable flag. 
  119.     //    I have extracted the tag value because I want to check the data
  120.     //    type of the tag to determine whether or not it should be 
  121.     //    displayed.  For example, I don't want to display binary data.
  122.     //
  123.     //    If I did not extract the value here, I could have also called
  124.     //    mdlTag_getTagDef() to get the tag's type from the tag definition.
  125.     */
  126.     if (SUCCESS != mdlTag_extract(
  127.                 NULL,           /* <= origin of associated element */
  128.                 NULL,           /* <= snap point */
  129.                 NULL,           /* <= tag specification */
  130.                 &displayable,   /* <= TRUE for displayable tag */
  131.                 &value,           /* <= value for the tag */
  132.                 NULL,           /* <= target element's assocation id */
  133.                 NULL,           /* <= offset */
  134.             NULL,        /* <= size for the text */
  135.             NULL,           /* <= rotation matrix */
  136.             NULL,           /* <= text parameters */
  137.             &tagElmDescrP->el, /* => tag element */
  138.             MASTERFILE))    /* => file number for the tag */
  139.     {
  140.     mdlOutput_rscPrintf(MSG_ERROR, NULL, MESSAGELISTID_Messages, 
  141.         MESSAGEID_TagExtractErr);
  142.     return ERROR;
  143.     }
  144.  
  145.     /*  
  146.     //    Note:
  147.     //    The only tag property that is stored with the tag element is
  148.     //    the display flag.  Therefore, there is no need to retrieve the
  149.     //    existing property mask for the tag definition using
  150.     //    mdlTag_getTagDef() before modifying the tag properties.
  151.     //    When I recreate the tag using mdlTag_create(), I can simply
  152.     //    pass the display flag for the property parameter.
  153.     */
  154.  
  155.     /*
  156.     //    If the tag is currently displayed and the user wants to
  157.     //    turn the display OFF then (display toggle is OFF)
  158.     */
  159.     if ((TRUE == displayable) && (0 == dlogBoxInfo->display))
  160.     {
  161.         /* Turn OFF the display of this tag */
  162.         tagProps = TAG_PROP_DISPOFF;
  163.  
  164.     createTag = TRUE;
  165.     }
  166.  
  167.     /*
  168.     //    Else if the tag is NOT currently displayed and the user
  169.     //    wants to turn ON the display then (display toggle is ON) 
  170.     */
  171.     else if ((FALSE == displayable) && (-1 == dlogBoxInfo->display))
  172.     {
  173.  
  174.         /* Turn ON the display of the flag */
  175.         tagProps = ~TAG_PROP_DISPOFF;
  176.  
  177.     createTag = TRUE;
  178.     }
  179.  
  180.     /*******************************************************************
  181.     //
  182.     //  When the value parameter is returned from mdlTag_extract(),
  183.     //  MicroStation has allocated memory for the stringVal and binaryVal
  184.     //  members of the TagValue structure.  You are responsible for
  185.     //  freeing this memory.
  186.     //
  187.     ********************************************************************/
  188.     switch (value.type)
  189.     {
  190.     case MS_TAGTYPE_CHAR:
  191.         {
  192.         /* Free the memory allocated by mdlTag_extract() */
  193.           free(value.val.stringVal);
  194.  
  195.         break;
  196.         }
  197.         case MS_TAGTYPE_BINARY:
  198.         {
  199.  
  200.         /* Free the memory allocated by mdlTag_extract() */
  201.           free(value.val.binaryVal);
  202.  
  203.         /*
  204.         //    Do not change the display flag for the binary type since
  205.         //    the data is not readable anyway 
  206.         */
  207.         createTag = FALSE;
  208.  
  209.         break;
  210.         }
  211.  
  212.     default:
  213.         break;
  214.     }
  215.  
  216.  
  217.     if (TRUE == createTag)
  218.     {
  219.         status = mdlTag_create(
  220.         &newTagElm,        /* output area for new tag element */
  221.         &tagElmDescrP->el,     /* template element */
  222.         NULL,            /* specification for tag definition */
  223.         &tagProps,        /* display flag */
  224.         NULL,            /* value extracted from text element */
  225.          NULL,            /* tag id from mdlAssoc_tagElement */
  226.         NULL,            /* computed location offset */
  227.         NULL,            /* rest are special text properties */
  228.         NULL,            /* ...                    */
  229.         NULL,
  230.         NULL
  231.             );
  232.     if (SUCCESS != status)
  233.             {
  234.         mdlOutput_rscPrintf(MSG_ERROR, NULL, MESSAGELISTID_Messages, 
  235.                     MESSAGEID_TagCreateErr);
  236.         }
  237.     else
  238.         {
  239.  
  240.         /*******************************************************************
  241.         //    The file position of the tag element is contained in the
  242.         //    userData1 member in the element descriptor header.
  243.         //
  244.         //    For example:
  245.         //
  246.         //    MSElementDescr *tagElmDescrP;
  247.         //
  248.         //    tagElmDescrP->h.userData1  contains the file position of the tag
  249.         //
  250.         //    This file position is needed since I intend to modify the tag 
  251.         //    element and rewrite the element to the design file at the file
  252.         //    position contained in tagElmDescrP->h.userData1
  253.         //
  254.         //********************************************************************/
  255.  
  256.         mdlElement_rewrite(&newTagElm, &tagElmDescrP->el, tagElmDescrP->h.userData1);
  257.  
  258.         mdlElement_display(&tagElmDescrP->el, ERASE);
  259.  
  260.         mdlElement_display(&newTagElm, NORMALDRAW);
  261.         }
  262.     } /* if (TRUE == createTag) */
  263.  
  264.     return status;
  265.  
  266.     }
  267.  
  268.  
  269. /*----------------------------------------------------------------------+
  270. |                                    |
  271. | name          tagdisp_modElm                                          |
  272. |                                    |
  273. | author    BSI                     8/94        |
  274. |                                    |
  275. +----------------------------------------------------------------------*/
  276. Private int     tagdisp_modElm
  277. (
  278. MSElementUnion  *elP
  279. )        
  280.     {
  281.     int            numTags, status;
  282.     MSElementDescr  *elmDescrP, *tempP, *prevP;
  283.  
  284.     /* Extract all tag elements from the selected element */
  285.     if ((status = mdlTag_getElementTags( 
  286.                 &elmDescrP, /* <= linked list of tags   */
  287.                 &numTags,     /* <= number of tags        */
  288.                 elP,        /* => element to get tags for*/
  289.                 MASTERFILE, /* => file number        */
  290.                 0))         /* => future arg, always 0  */
  291.             != SUCCESS)
  292.     {
  293.     mdlOutput_rscPrintf(MSG_ERROR, NULL, MESSAGELISTID_Messages, 
  294.         MESSAGEID_GetTagsErr);
  295.     }
  296.     else
  297.     {
  298.     tempP = elmDescrP;
  299.     while (tempP != NULL)
  300.         {
  301.  
  302.         /* change the display of this tag if necessary */
  303.         tagdisp_changeDisplay(tempP);
  304.  
  305.  
  306.         /*******************************************************************
  307.         //    After successfully calling mdlTag_getElementTags(), MicroStation
  308.         //    has allocated memory for a linked list of element descriptors 
  309.         //    and has returned a pointer to that list in the first parameter
  310.         //    to this function.
  311.         //
  312.         //    You need to call mdlElmdscr_freeAll() to deallocate this memory.
  313.         *******************************************************************/
  314.     
  315.         prevP = tempP;
  316.         tempP = tempP->h.next;
  317.         mdlElmdscr_freeAll(&prevP);
  318.         }
  319.     }
  320.  
  321. /*  Do not change the select element */
  322.     return  MODIFY_STATUS_NOCHANGE;
  323.     }
  324.  
  325. /*----------------------------------------------------------------------+
  326. |                                    |
  327. | name          tagdisp_acceptElm                                       |
  328. |                                                                       |
  329. | author    BSI                     8/94        |
  330. |                                    |
  331. +----------------------------------------------------------------------*/
  332. Private void     tagdisp_acceptElm
  333. (
  334. Dpoint3d    *ptP,
  335. int         view
  336. )
  337.     {
  338.     ULong   filePos;
  339.     int        currFile;
  340.  
  341. /*-----------------------------------------------------------------------
  342.     The located element was accepted using a data point so get the
  343.     accepted element and call mdlModify_elementMulti to change the
  344.     display of any tags associated to this element.
  345. -----------------------------------------------------------------------*/
  346.     filePos = mdlElement_getFilePos (FILEPOS_CURRENT, &currFile);
  347.  
  348.     mdlModify_elementMulti (currFile, filePos, MODIFY_REQUEST_HEADERS,
  349.                             MODIFY_ORIG, tagdisp_modElm, NULL, TRUE);
  350.  
  351. /*-----------------------------------------------------------------------
  352.     Restart the locate logic
  353. -----------------------------------------------------------------------*/
  354.     mdlLocate_restart (FALSE);
  355.     }
  356.  
  357. /*----------------------------------------------------------------------+
  358. |                                    |
  359. |   Command Functions                            |
  360. |                                    |
  361. +----------------------------------------------------------------------*/
  362. /*----------------------------------------------------------------------+
  363. |                                    |
  364. | name          tagdisp_changeDisplayCmd                                |
  365. |                                    |
  366. | author    BSI                     8/94        |
  367. |                                    |
  368. +----------------------------------------------------------------------*/
  369. Private void tagdisp_changeDisplayCmd
  370. (
  371. char    *unparsedP    /* => unparsed part of command */
  372. )
  373. cmdNumber   CMD_CHANGE_TAG_DISPLAY
  374.     {
  375.  
  376.     /* Setup search mask with the type of elements we are looking for */
  377.     tagdisp_setElmSearchType();
  378.  
  379.     mdlState_startModifyCommand (tagdisp_changeDisplayCmd, /*reset func */
  380.                 tagdisp_acceptElm,  /* datapoint func */
  381.                 NULL,            /* dynamics func */
  382.                 NULL,            /* show func */
  383.                         NULL,            /* clean func */
  384.                 MESSAGEID_TagDisplay, /* command field message */
  385.                 0,                /* accept prompt message */
  386.                 TRUE,            /* use selection sets */
  387.                 0);                   /* pts required for accept */
  388.  
  389.     /* output a prompt asking user to select a graphic element */
  390.     mdlOutput_rscPrintf(MSG_PROMPT, NULL, 
  391.             MESSAGELISTID_Messages, MESSAGEID_SelectElement);
  392.  
  393.     /* Start search at beginning of file */
  394.     mdlLocate_init ();
  395.     }
  396.  
  397.