home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk22
/
dir03
/
f014330.re_
/
f014330.re
Wrap
Text File
|
1996-04-02
|
8KB
|
269 lines
/*----------------------------------------------------------------------+
| |
| Copyright (1995) Bentley Systems, Inc., All rights reserved. |
| |
| "MicroStation" is a registered trademark and "MDL" and "MicroCSL" |
| are trademarks of Bentley Systems, Inc. |
| |
| Limited permission is hereby granted to reproduce and modify this |
| copyrighted material provided that the resulting code is used only |
| in conjunction with Bentley Systems products under the terms of the |
| license agreement provided therein, and that this notice is retained |
| in its entirety in any such reproduction or modification. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| $Logfile: J:/mdl/examples/doc/element.mcv $
| $Workfile: element.mc $
| $Revision: 5.2 $
| $Date: 20 Jun 1995 08:49:54 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| element.mc - examples for the mdlElement_ functions. |
| |
| This file is intended as an adjunct to the MDL manual to |
| illustrate MDL built-in function calling conventions and parameter |
| values. While it can be compiled, it does NOT, on its own, |
| constitute a workable MDL example. |
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| Include Files |
| |
+----------------------------------------------------------------------*/
#include <mdl.h> /* system include files */
#include <global.h>
#include <mselems.h>
/*----------------------------------------------------------------------+
| |
| local defines |
| |
+----------------------------------------------------------------------*/
#define MASTER_FILE 0
/*----------------------------------------------------------------------+
| |
| name incrementColor |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Public void incrementColor
(
MSElement *element
)
{
int color;
int true=TRUE, false=FALSE;
/* get the current color from the element */
mdlElement_getSymbology (&color, NULL, NULL, element);
/* increment it (wrap if necessary) */
if (++color >= 256)
color = 0;
/* set the new color in the element */
mdlElement_setSymbology (element, &color, NULL, NULL);
/* mark the element as "not-new" and "modified" */
mdlElement_setProperties (element, NULL, NULL, NULL, NULL,
&false, &true, NULL, NULL);
}
/*----------------------------------------------------------------------+
| |
| name incrementLevel |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Public void incrementLevel
(
MSElement *element
)
{
int level, gg, locked;
int true=TRUE, false=FALSE;
/* get the current level from the element */
mdlElement_getProperties (&level, &gg, NULL, &locked, NULL, NULL, NULL,
NULL, element);
/* don't do members of a graphic group or locked elements */
if (gg==0 && !locked)
{
if (++level > 63)
{
/* set the level and mart element as "not-new" and "modified" */
mdlElement_setProperties (element, level, NULL, NULL, NULL,
&false, &true, NULL, NULL);
}
}
}
/*----------------------------------------------------------------------+
| |
| name placeNewLine |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Public void placeNewLine
(
Dpoint3d *linePts, /* => points defining line */
ULong *filePos /* <= filePosition of new element */
)
{
MSElement line;
if (mdlLine_create (&line, NULL, linePts) == SUCCESS)
{
mdlElement_display (&line, NORMALDRAW);
if ((*filePos = mdlElement_add (&line)) == 0L)
{
mdlOutput_printf (MSG_ERROR,"error adding element, %d", mdlErrno);
}
}
}
/*----------------------------------------------------------------------+
| |
| name changeLine |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Public void changeLine
(
Dpoint3d *linePts, /* => points defining line */
MSElement *oldLine, /* => existing line element */
ULong *filePos /* <=> file position of line */
)
{
MSElementUnion line;
/* make sure they passed us a line element */
if (mdlElement_getType (oldLine) != LINE_ELM)
return;
if (mdlLine_create (&line, oldLine, linePts) == SUCCESS)
{
if ((*filePos = mdlElement_rewrite (&line, oldLine, *filePos)) == 0L)
{
mdlOutput_printf (MSG_ERROR, "error changing element, %d",
mdlErrno);
}
else
{
mdlElement_display (oldLine, ERASE);
mdlElement_display (&line, NORMALDRAW);
}
}
}
/*----------------------------------------------------------------------+
| |
| name deletePoints - delete "point" elements |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Public void deletePoints
(
MSElement *oldLine, /* => existing line element */
ULong filePos, /* => file position of line */
int fileNum
)
{
Dpoint3d linePts[MAX_VERTICES];
int numVerts;
/* delete any "point" elements (those with 2 vertices the same) */
if (mdlLinear_extract (linePts, &numVerts, oldLine, fileNum) == SUCCESS)
{
if (numVerts == 2 && mdlVec_pointEqual (linePts, linePts+1))
{
mdlElement_undoableDelete (oldLine, filePos, TRUE);
}
}
}
/*----------------------------------------------------------------------+
| |
| name moveAttributes |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Public void moveAttributes
(
MSElement *oldElem, /* => old element */
MSElement *newElem /* <=> new element */
)
{
short attributes[MAX_ATTRIBSIZE];
int attribLen;
/* copy all of the attributes from the old element to the
new one, appending them to any existing attributes. Then
clear the attributes from the original element. */
mdlElement_extractAttributes (&attribLen, attributes, oldElem);
mdlElement_appendAttributes (newElem, attribLen, attributes);
mdlElement_stripAttributes (oldElem, oldElem);
}
/*----------------------------------------------------------------------+
| |
| name resetWorkingWindow - clear working window (if present) |
| |
| author BSI 7/90 |
| |
+----------------------------------------------------------------------*/
Public int resetWorkingWindow
/* <= returns SUCCESS if WW was set, ERROR otherwise */
(
void
)
{
/* get current "working window" (don't need fileNumber) */
if (mdlElement_getFilePos (FILEPOS_WORKING_WINDOW, NULL) != 0L)
{
mdlElement_setFilePos (FILEPOS_WORKING_WINDOW, MASTER_FILE, 0L);
mdlOutput_message ("Working window cleared");
return SUCCESS;
}
return ERROR;
}
/*----------------------------------------------------------------------+
| |
| name displayOneElementInOneView |
| |
| author BSI 1/91 |
| |
+----------------------------------------------------------------------*/
Private void displayOneElementInOneView
(
int fileNum,
ULong filePos,
int view
)
{
MSElement element;
/* NOTE: This function would probably be better written using the
mdlElmdscr_ functions so that complex elements would work as well. */
if (mdlElement_read (&element, fileNum, filePos) == SUCCESS)
{
if (view>=0 && view<=7)
mdlElement_displayInSelectedViews (&element, NORMALDRAW, 1<<view);
}
}