?? plcirc.mc
字號:
/*-------------------------------------------------------------------+
| Copyright (c) 1991, Mach N. Dinh-Vu, All Rights Reserved |
| Program : plcirc.mc |
| Revision : 1.0.a |
| UpgradeToV8 : MicroStationFan 2006/05 |
+--------------------------------------------------------------------+
| Example MDL function to place a circle around |
| a text string with a leader line and an arrowhead |
+-------------------------------------------------------------------*/
/*-------------------------------------------------------------------+
| Include Files |
+-------------------------------------------------------------------*/
#include <mdl.h> /* system include files */
#include <msrmgr.h>
#include <stdlib/math.h>
#include <stdlib/string.h>
#include <mscell.fdf>
#include <mscnv.fdf>
#include <mscurrtr.fdf>
#include <mselemen.fdf>
#include <mselmdsc.fdf>
#include <msmisc.fdf>
#include <msoutput.fdf>
#include <msparse.fdf>
#include <msstate.fdf>
#include <msvec.fdf>
#include "plcirc.h"
/*-------------------------------------------------------------------+
| Private Global variables |
+-------------------------------------------------------------------*/
static char textin[128];
Dpoint3d pntP[3];
/*-------------------------------------------------------------------+
| name main |
+-------------------------------------------------------------------*/
Private void main ( void )
{
RscFileHandle rfHandle;
/* load our command tabla */
if (mdlParse_loadCommandTable (NULL) == NULL)
mdlOutput_error ("Unable to load command table.");
mdlResource_openFile (&rfHandle, NULL, FALSE);
mdlOutput_error ("Enter PLACE TCIRC to start");
}
/*-------------------------------------------------------------------+
| name constIntersectionPoint |
+-------------------------------------------------------------------*/
Private void constIntersectionPoint
(
Dpoint3d *intersectionPt, /* intersection point on circle */
double *radius, /* radius of circle */
Dpoint3d *centerPt, /* center of circle */
Dpoint3d *directionPt /* end point of arrowhead */
)
{
Dpoint3d dirVector;
mdlVec_subtractPoint (&dirVector, directionPt, centerPt);
mdlVec_normalize (&dirVector);
mdlVec_scale (&dirVector, &dirVector, *radius);
mdlVec_addPoint (intersectionPt, centerPt, &dirVector);
}
/*-------------------------------------------------------------------+
| name generateImage - dynamic function for complex case. |
+-------------------------------------------------------------------*/
Private int generateImage
(
Dpoint3d *pt,
int view,
int drawMode
)
{
MSElementDescr *elmDP;
MSElementUnion el;
Dpoint3d origin;
Dpoint3d tPts[3];
double zangle, radius, txtHeight;
ULong arrowsize, chheight;
mdlParams_getActive ((double *)&txtHeight, ACTIVEPARAM_TEXTHEIGHT);
chheight = (ULong)txtHeight;
arrowsize = chheight / 2;
radius = chheight * 2;
pntP[1] = *pt;
mdlCurrTrans_begin ();
mdlCurrTrans_identity ();
mdlCurrTrans_translateOrigin (&pntP[0]);
mdlCurrTrans_invtransPointArray(tPts, pntP, 2);
origin = tPts[1]; /* origin of text */
mdlCell_create (&el, L"plcirc", &origin, FALSE);
mdlElmdscr_new (&elmDP, NULL, &el);
mdlText_create (&el, NULL, textin, &tPts[1], NULL, NULL, NULL, NULL);
mdlElmdscr_appendElement (elmDP, &el);
constIntersectionPoint (&tPts[1], &radius, &origin, &tPts[0]);
mdlLine_create (&el, NULL, tPts);
mdlElmdscr_appendElement (elmDP, &el);
/* Create arrowhead */
mdlEllipse_create (&el, NULL, &origin, radius, radius, NULL, 0);
mdlElmdscr_appendElement (elmDP, &el);
/* calculate angle of line */
zangle = atan2 ((tPts[0].y-tPts[1].y), (tPts[0].x-tPts[1].x));
mdlCurrTrans_rotateByAngles (0.0, 0.0, zangle);
/* Create arrowhead */
tPts[1] = tPts[0];
tPts[2].x = tPts[0].x - arrowsize;
tPts[2].y = tPts[0].y - (arrowsize/2);
tPts[0].x -= arrowsize;
tPts[0].y += arrowsize/2;
mdlLineString_create (&el, NULL, tPts, 3);
mdlElmdscr_appendElement (elmDP, &el);
mdlElmdscr_display (elmDP, 0, drawMode);
if (drawMode == NORMALDRAW)
{
mdlElmdscr_add (elmDP);
}
mdlElmdscr_freeAll (&elmDP);
mdlCurrTrans_end( );
return SUCCESS;
}
/*-------------------------------------------------------------------+
| name keyinText |
+-------------------------------------------------------------------*/
Private void keyinText (char *cmdStrP)
{
if (!*statedata.cmdstring)
return;
strncpy (textin, statedata.cmdstring, sizeof(textin));
}
/*-------------------------------------------------------------------+
| name placeCirc_secondPoint |
+-------------------------------------------------------------------*/
Private void placeCirc_secondPoint
(
Dpoint3d *pt,
int view
)
{
generateImage (pt, view, NORMALDRAW);
}
/*--------------------------------------------------------------------------+
| name placeCirc_done |
+--------------------------------------------------------------------------*/
Private void placeCirc_done (void)
{
mdlState_restartCurrentCommand ();
}
/*--------------------------------------------------------------------------+
| name placeCirc_firstPoint |
+--------------------------------------------------------------------------*/
Private void placeCirc_firstPoint
(
Dpoint3d *pt,
int view
)
{
pntP[0] = *pt; /* save first point */
/* Set the datapoint state function for the second point. */
mdlState_setFunction (STATE_KEYIN, keyinText);
mdlState_setFunction (STATE_DATAPOINT, placeCirc_secondPoint);
mdlOutput_rscPrintf (MSG_PROMPT, NULL, 0, 3);
/* setup dynamics for the second point */
mdlState_setFunction (STATE_COMPLEX_DYNAMICS, generateImage);
}
/*--------------------------------------------------------------------------+
| name placeCirc_start |
+--------------------------------------------------------------------------*/
cmdName placeCirc_start (void)
cmdNumber CMD_PLACE_TCIRC
{
mdlState_startPrimitive (placeCirc_firstPoint, placeCirc_start, 1, 2);
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -