home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 1997 January
/
Chip_1997-01_cd.bin
/
ms95
/
disk21
/
dir04
/
f014300.re_
/
f014300.re
Wrap
Text File
|
1996-04-02
|
16KB
|
576 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/create.mcv $
| $Workfile: create.mc $
| $Revision: 5.5 $
| $Date: 20 Jun 1995 08:49:38 $
| |
+----------------------------------------------------------------------*/
/*----------------------------------------------------------------------+
| |
| create.mc - examples for the mdlXXXX_create 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>
#include <tcb.h>
#include <userpref.h>
#include <widechar.h>
#include <mselemen.fdf>
/*----------------------------------------------------------------------+
| |
| name placeAShape |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeAShape
(
void
)
{
Dpoint3d shapePts[3];
MSElementUnion shape;
shapePts[0].x = fc_zero;
shapePts[0].y = 1.0;
shapePts[0].z = fc_zero;
shapePts[1].x = 100.0;
shapePts[1].y = 200.0;
shapePts[1].z = fc_zero;
shapePts[2].x = 300.0;
shapePts[2].y = 400.0;
shapePts[2].z = fc_zero;
if (mdlShape_create (&shape, NULL, shapePts, 3, -1) == SUCCESS)
{
mdlElement_display (&shape, NORMALDRAW);
mdlElement_add (&shape);
}
}
/*----------------------------------------------------------------------+
| |
| name placeALineString |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeALineString
(
Dpoint3d *lsPoints,
int numVerts
)
{
MSElementUnion lineString;
if (mdlLineString_create (&lineString, NULL, lsPoints, numVerts)
== SUCCESS)
{
mdlElement_display (&lineString, NORMALDRAW);
mdlElement_add (&lineString);
}
}
/*----------------------------------------------------------------------+
| |
| name placeAnArc |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeAnArc
(
MSElementUnion *existingArc
)
{
Dpoint3d center;
MSElementUnion arc;
center.x = 100.0;
center.y = 100.0;
center.z = 100.0;
if (mdlArc_create (&arc, existingArc, ¢er, 100.0, 200.0,
NULL, fc_zero, fc_pi) == SUCCESS)
{
mdlElement_display (&arc, NORMALDRAW);
mdlElement_add (&arc);
}
}
/*----------------------------------------------------------------------+
| |
| name placeAnArcByPoints |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeAnArcByPoints
(
void
)
{
MSElementUnion arc;
Dpoint3d arcPt[3];
arcPt[0].x = 20.; /* start point */
arcPt[0].y = 30.;
arcPt[0].z = fc_zero;
arcPt[1].x = 50.; /* mid point */
arcPt[1].y = 60.;
arcPt[1].z = fc_zero;
arcPt[2].x = 20.; /* end point */
arcPt[2].y = 80.;
arcPt[2].z = fc_zero;
if (mdlArc_createByPoints (&arc, NULL, arcPt) == SUCCESS)
{
mdlElement_display (&arc, NORMALDRAW);
mdlElement_add (&arc);
}
}
/*----------------------------------------------------------------------+
| |
| name placeAnArcByCenter |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeAnArcByCenter
(
int view
)
{
MSElementUnion arc;
Dpoint3d arcPt[3];
arcPt[0].x = 20.; /* start point */
arcPt[0].y = 30.;
arcPt[0].z = fc_zero;
arcPt[1].x = 50.; /* center */
arcPt[1].y = 30.;
arcPt[1].z = fc_zero;
arcPt[2].x = 80.; /* end point */
arcPt[2].y = 30.;
arcPt[2].z = fc_zero;
/* create an arc with a radius of 44.0 and center at [50,30,0] */
if (mdlArc_createByCenter (&arc, NULL, arcPt, TRUE, 44.0, view)
== SUCCESS)
{
mdlElement_display (&arc, NORMALDRAW);
mdlElement_add (&arc);
}
}
/*----------------------------------------------------------------------+
| |
| name placeEllipse |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeEllipse
(
void
)
{
MSElementUnion ellipse;
Dpoint3d center;
center.x = 100.0;
center.y = 100.0;
center.z = 100.0;
if (mdlEllipse_create (&ellipse, NULL, ¢er, 10.0, 15.0,
NULL, -1) == SUCCESS)
{
mdlElement_display (&ellipse, NORMALDRAW);
mdlElement_add (&ellipse);
}
}
/*----------------------------------------------------------------------+
| |
| name placeCircleByPoints |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeCircleByPoints
(
void
)
{
MSElementUnion circle;
Dpoint3d circlePt[3];
circlePt[0].x = 200.;
circlePt[0].y = 300.;
circlePt[0].z = 000.;
circlePt[1].x = 500.;
circlePt[1].y = 600.;
circlePt[1].z = 000.;
circlePt[2].x = 200.;
circlePt[2].y = 800.;
circlePt[2].z = 000.;
if (mdlCircle_createBy3Pts (&circle, NULL, circlePt, -1) == SUCCESS)
{
mdlElement_display (&circle, NORMALDRAW);
mdlElement_add (&circle);
}
}
/*----------------------------------------------------------------------+
| |
| name placeText |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeText
(
MSElementUnion *currentText,
long textPos
)
{
MSElementUnion text;
Dpoint3d pt[3];
TextSizeParam txtSize;
TextParam txtParam;
TextEDField edFields[2];
TextEDParam edParam;
pt[0].x = 285.; /* origin of text element */
pt[0].y = 450.;
pt[0].z = fc_zero;
txtSize.mode = TXT_BY_TEXT_SIZE;
txtSize.size.width = fc_2;
txtSize.size.height = 3.;
txtParam.font = 2;
txtParam.just = -1; /* use active justification */
txtParam.style = -1; /* use active style */
txtParam.viewIndependent = FALSE;
edFields[0].start = 1;
edFields[0].len = 2;
edFields[0].just = 2;
edFields[1].start = 5;
edFields[1].len = 1;
edFields[1].just = 3;
edParam.numEDFields = 2;
edParam.edField = edFields;
/* create a new text element */
if (mdlText_create (&text, NULL, "this text placed in MDL", pt,
&txtSize, NULL, &txtParam, &edParam) == SUCCESS)
{
mdlElement_display (&text, NORMALDRAW);
mdlElement_add (&text);
}
/* overwrite an existing text element without changing parameters */
if (mdlText_create (&text, currentText, "overwritten text",
NULL, NULL, NULL, NULL, NULL) == SUCCESS)
{
mdlElement_rewrite (&text, currentText, textPos);
mdlElement_display (&text, NORMALDRAW);
}
}
/*----------------------------------------------------------------------+
| |
| name placeTextNode |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeTextNode
(
void
)
{
MSElementUnion textNode;
Dpoint3d origin;
MSTextSize nodeSize;
TextParam txtParam;
double lineSpacing;
origin.x = 100.;
origin.y = 200.;
origin.z = 0.;
nodeSize.width = 10.;
nodeSize.height = 13.;
lineSpacing = 1.1;
txtParam.font = 2;
txtParam.just = -1; /* use active justification */
txtParam.style = -1; /* use active style */
txtParam.viewIndependent = FALSE;
if (mdlTextNode_create (&textNode, NULL, &origin, NULL, &lineSpacing,
&nodeSize, &txtParam) == SUCCESS)
{
mdlElement_display (&textNode, NORMALDRAW);
mdlElement_add (&textNode);
}
}
/*----------------------------------------------------------------------+
| |
| name text_getExtendedParam |
| |
| sets flags and values for extended text attributes |
| (slant, underline, character spacing, and direction) |
| according to tcb and userpref |
| |
| author BSI 4/93 |
| |
+----------------------------------------------------------------------*/
Public void text_setExtendedParam
(
TextParamWide *textParam /* <= flags, slant, spacing, etc. */
)
{
/* TextDrawFlags tells the existence of slant, inter-character spacing,
underline, and vertical direction. Set all flags to zero first. */
memset (&textParam->flags, 0, sizeof(TextDrawFlags));
/* Convert tcb->textSlant from degree to radian.
Set flags.slant only if slant value is not zero */
if (fabs(tcb->textSlant) > fc_epsilon)
{
textParam->flags.slant = TRUE;
textParam->slant = tcb->textSlant * fc_piover180;
}
if (tcb->textDirection & TXTDIR_VERTICAL) /* vertical direction */
textParam->flags.vertical = TRUE;
/* user preference tells if fixed-width mode or inter-character mode */
if (userPrefsP->extFlags.fixedWidthCharSpace)
{
textParam->flags.fixedWidthSpacing = TRUE;
/* if char spacing is 0, igonore it otherwide characters are
stacked together */
if (fabs(tcb->textAboveSpacing) < fc_epsilon)
textParam->characterSpacing =
textParam->flags.vertical ? tcb->chheight : tcb->chwidth;
else
textParam->characterSpacing = tcb->textAboveSpacing;
}
else if (fabs(tcb->textAboveSpacing) > fc_epsilon)
{
textParam->flags.interCharSpacing = TRUE;
textParam->characterSpacing = tcb->textAboveSpacing;
}
if (tcb->textUnderline)
{
textParam->flags.underline = TRUE;
textParam->underlineSpacing = tcb->chheight *
userPrefsP->textUnderlineSpace * fc_p01;
}
}
/*----------------------------------------------------------------------+
| |
| name placeTextWide |
| |
| author BSI 7/93 |
| |
+----------------------------------------------------------------------*/
Private void placeTextWide
(
MSElementUnion *currentText,
long textPos
)
{
MSElementUnion text;
Dpoint3d pt[3];
TextSizeParam txtSize;
TextParamWide txtParam;
TextEDField edFields[2];
TextEDParam edParam;
char *string1 = "this text placed in MDL";
char *string2 = "overwritten text";
MSWideChar wString1[50], wString2[50];
/* convert to wide-character string - the third argument is the size
of wString, see "stdlib.h" for details */
mbstowcs (wString1, string1, 50);
mbstowcs (wString2, string2, 50);
pt[0].x = 285.; /* origin of text element */
pt[0].y = 450.;
pt[0].z = fc_zero;
txtSize.mode = TXT_BY_TEXT_SIZE;
txtSize.size.width = fc_2;
txtSize.size.height = 3.;
txtParam.font = 2;
txtParam.just = -1; /* use active justification */
txtParam.style = -1; /* use active style */
txtParam.viewIndependent = FALSE;
/* set extended params (slant, underline, char spacing, and direction) */
text_setExtendedParam (&txtParam);
edFields[0].start = 1;
edFields[0].len = 2;
edFields[0].just = 2;
edFields[1].start = 5;
edFields[1].len = 1;
edFields[1].just = 3;
edParam.numEDFields = 2;
edParam.edField = edFields;
/* create a new text element */
if (mdlText_createWide (&text, NULL, wString1, pt, NULL,
&txtSize, &txtParam, &edParam) == SUCCESS)
{
mdlElement_display (&text, NORMALDRAW);
mdlElement_add (&text);
}
/* overwrite an existing text element without changing parameters */
if (mdlText_createWide (&text, currentText, wString2,
NULL, NULL, NULL, NULL, NULL) == SUCCESS)
{
mdlElement_rewrite (&text, currentText, textPos);
mdlElement_display (&text, NORMALDRAW);
}
}
/*----------------------------------------------------------------------+
| |
| name placeTextNodeWide |
| |
| author BSI 7/93 |
| |
+----------------------------------------------------------------------*/
Private void placeTextNodeWide
(
void
)
{
MSElementUnion textNode;
Dpoint3d origin;
TextSizeParam nodeSize;
TextParamWide txtParam;
origin.x = 100.;
origin.y = 200.;
origin.z = 0.;
nodeSize.mode = TXT_BY_TEXT_SIZE;
nodeSize.size.width = 10.;
nodeSize.size.height= 13.;
txtParam.font = 2;
txtParam.just = -1; /* use active justification */
txtParam.style = -1; /* use active style */
txtParam.viewIndependent = FALSE;
txtParam.lineSpacing = tcb->nodespace;
/* set extended params (slant, underline, char spacing, and direction) */
text_setExtendedParam (&txtParam);
if (mdlTextNode_createWide (&textNode, NULL, &origin, NULL,
&nodeSize, &txtParam) == SUCCESS)
{
mdlElement_display (&textNode, NORMALDRAW);
mdlElement_add (&textNode);
}
}
/*----------------------------------------------------------------------+
| |
| name placeCone |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeCone
(
RotMatrix *rMatrix
)
{
MSElementUnion cone;
Dpoint3d conePts[2];
conePts[0].x = 100.;
conePts[0].y = 200.;
conePts[0].z = 0.;
conePts[1].x = 100.;
conePts[1].y = 200.;
conePts[1].z = 10.;
if (mdlCone_create (&cone, NULL, 2.0, 1.0, &conePts[0], &conePts[1],
rMatrix) == SUCCESS)
{
mdlElement_display (&cone, NORMALDRAW);
mdlElement_add (&cone);
}
}
/*----------------------------------------------------------------------+
| |
| name . |
| |
| author BSI 8/90 |
| |
+----------------------------------------------------------------------*/
Private void placeCylinder
(
void
)
{
MSElementUnion cone;
Dpoint3d conePts[2];
conePts[0].x = 100.;
conePts[0].y = 200.;
conePts[0].z = 0.;
conePts[1].x = 100.;
conePts[1].y = 200.;
conePts[1].z = 10.;
if (mdlCone_createRightCylinder (&cone, NULL, 2.0, &conePts[0],
&conePts[1]) == SUCCESS)
{
mdlElement_display (&cone, NORMALDRAW);
mdlElement_add (&cone);
}
}