📄 placenote.mc
字号:
/*================================================================================
Step by step 之 MDL 快速入门实例十七--十八
================================================================================*/
#include <dlogids.h>
#include <basetype.h>
#include <tcb.h>
#include <mselems.h>
#include <global.h>
#include <scanner.h>
#include <msinputq.h>
#include <userfnc.h>
#include <mdl.h>
#include <cexpr.h>
#include <rscdefs.h>
#include <dlogitem.h>
#include <cmdlist.h>
#include <dbdefs.h>
#include "PlaceNote.h"
#include "PlaceNotecmd.h"
AnnotationInfo chAnnoInfo;
AnnoInfo AnnoTextInfo;
AssoedStruc userAssoedStruc;
int g_LinkageLen; //linage 字段长
short g_maxmslink[16]; //返回的mslink值
Private ULong g_AssoedFilePos;
Private int mFirstP=1, mTextCount=0;
Private Dpoint3d mFirstLPoint, Point[30];
Private MSElementDescr *TextDP = NULL;
char ActiveFcode[50];
void annotateText_init(void);
void annotateText_draw(Dpoint3d* pPoint,int view, int drawMode, int add);
void annotateText_onTarget(Dpoint3d* pPoint,int view);
void annotateText_accept(Dpoint3d* pPoint,int view);
Private void OnSelectAnnoType(void);
Private void annotateText_reset(void);
// drawing point-, line-, discrete- annotations
Private void annotateText_draw(Dpoint3d* pPoint,int view, int drawMode, int add)
{
static directed;
MSElement el, mOut;
Dpoint3d point;
Dpoint3d origin;
Dpoint3d shapep[5];
long cellFilePos;
int done, ret;
char str[128];
int mTextLen,mCTextLen,i,j;
char mSingleText[8];
RotMatrix rm;
if (chAnnoInfo.text[0]==0) return;
switch(chAnnoInfo.Type)
{
case 1: /*Put text to one point*/
mdlOutput_prompt("请输入端点");
mdlText_create(&mOut, NULL, chAnnoInfo.text, pPoint, NULL, NULL, NULL, NULL);
mdlElmdscr_new(&TextDP, NULL, &mOut);
mdlElmdscr_display(TextDP, 0, drawMode);
if(add)
{
mdlElement_appendAttributes(&TextDP->el, g_LinkageLen, g_maxmslink);
mdlElmdscr_add(TextDP);
}
mdlElmdscr_freeAll(&TextDP);
break;
case 2: /*Put text along one line*/
done = 0;
mdlCell_create(&el, NULL, pPoint, FALSE); /* create graphic group */
mdlElmdscr_new(&TextDP, NULL, &el);
if(mFirstP)
{
/*Set first point of text align on one line*/
mdlOutput_prompt("请输入端点");
mFirstLPoint = *pPoint;
done=0;
if (add)
{
mFirstP=0;
mdlOutput_prompt("请输入另一端点");
}
else
{
//annotate_processCHHZ(chAnnoInfo.text, str, 128); /* process the text if any chinese in it */
mdlText_create(&mOut, NULL, chAnnoInfo.text, pPoint, NULL, NULL, NULL, NULL);
mdlElmdscr_appendElement(TextDP, &mOut);
}
}
else
{
mdlOutput_prompt("请输入另一端点");
/*Get the count of the text, the chinese text use double byte*/
mCTextLen = strlen(chAnnoInfo.text);
mTextLen=mCTextLen;
for (i=0; i<mCTextLen; i++)
{
if((unsigned)chAnnoInfo.text[i]<0x80) continue;
mTextLen--; i++;
}
if(mTextLen<=1) break;
i=0; j=0; //"j" is the count of text
mdlRMatrix_from3Points(&rm, &mFirstLPoint, pPoint, NULL);
while(i<mCTextLen)
{
point=mFirstLPoint;
point.x=point.x+(pPoint->x-mFirstLPoint.x)/(mTextLen-1)*j;
point.y=point.y+(pPoint->y-mFirstLPoint.y)/(mTextLen-1)*j++;
mSingleText[0]=chAnnoInfo.text[i];
if ((unsigned)chAnnoInfo.text[i]<0x80)
mSingleText[1] = 0;
else
mSingleText[1] = chAnnoInfo.text[++i], mSingleText[2]=0;
if (chAnnoInfo.Type==4)
mdlText_create(&mOut, NULL, mSingleText, &point, NULL, &rm, NULL, NULL);
else
mdlText_create(&mOut, NULL, mSingleText, &point, NULL, NULL, NULL, NULL);
mdlElmdscr_appendElement(TextDP, &mOut);
i++;
}
if (add)
{
mFirstP=1;
done=1;
mdlOutput_prompt("请输入端点, 或Reset退出");
}
}
mdlElmdscr_display(TextDP, 0, drawMode);
if (add && done==1)
{
mdlElement_appendAttributes(&TextDP->el, g_LinkageLen, g_maxmslink);
mdlCell_setRange(TextDP);
mdlElmdscr_add(TextDP);
}
mdlElmdscr_freeAll(&TextDP);
break;
case 4: /*Put text at any point and at any direction*/
case 3: /*Put text at any point*/
done=1;
mTextLen=strlen(chAnnoInfo.text);
if (mTextLen<=0) break;
if (mTextCount==0 && mFirstP==1)
{
/*if (drawMode!=NORMALDRAW) mdlOutput_prompt("请输入当前字符位置, 或Reset退出");*/
mdlCell_create(&el, NULL, pPoint, FALSE);
mdlElmdscr_new(&TextDP, NULL, &el);
directed=1;
mFirstP=0;
}
else if(mTextCount>=mTextLen)
{
mTextCount=0;
break;
}
mSingleText[0] = chAnnoInfo.text[mTextCount];
if((unsigned)chAnnoInfo.text[mTextCount]<0x80) mSingleText[1]=0;
else
{
mSingleText[1]=chAnnoInfo.text[mTextCount+1];
mSingleText[2]=0;
}
//annotate_processCHHZ(mSingleText, str, 128); /* process the text if any chinese in it */
if (chAnnoInfo.Type==4)
{
tcb->txtjust = TXTJUST_CC;
if (directed==1)
{
mdlText_create(&mOut, NULL, mSingleText, pPoint, NULL, NULL, NULL, NULL);
Point[0]=*pPoint;
}
else
{
mdlRMatrix_from3Points(&rm, Point+0, pPoint, NULL);
mdlText_create(&mOut, NULL, mSingleText, Point+0, NULL, &rm, NULL, NULL);
if (add)
{
mdlElmdscr_appendElement(TextDP, &mOut);
if((unsigned)chAnnoInfo.text[mTextCount]<0x80) mTextCount++;
else mTextCount+=2;
}
mdlElement_display(&mOut, drawMode);
}
if (add) directed=1-directed;
}
else
{
mdlText_create(&mOut, NULL, mSingleText, pPoint, NULL, NULL, NULL, NULL);
if(add){
mdlElmdscr_appendElement(TextDP, &mOut);
if ((unsigned)chAnnoInfo.text[mTextCount]<0x80) mTextCount++;
else mTextCount+=2;
}
else
if (mTextCount==0 && mFirstP==1) mdlElmdscr_freeAll(&TextDP);
mdlElement_display(&mOut, drawMode);
}
if (mTextCount<mTextLen) mdlOutput_prompt("请输入当前字符位置");
else
{
mdlOutput_prompt("请输入当前字符位置, 或Reset退出");
mTextCount=0;
mFirstP=1;
mdlElement_appendAttributes(&TextDP->el, g_LinkageLen, g_maxmslink);
mdlCell_setRange(TextDP);
mdlElmdscr_add(TextDP);
if(TextDP) mdlElmdscr_freeAll(&TextDP);
}
break;
}
}
/*This function get data point and annotate text at certern position*/
/*Added by J. Sun on 1997.1.25*/
Private void annotateText_accept(Dpoint3d* pPoint,int view)
{
annotateText_draw(pPoint, view, NORMALDRAW, 1);
mdlState_setFunction(STATE_RESET, annotateText_reset);
}
Private void annotateText_onTarget(Dpoint3d* pPoint,int view)
{
int currFile, color, weight, style;
MSElement el, mOut;
MSElementDescr *elmDP;
/* get target feature's symbology */
g_AssoedFilePos = mdlElement_getFilePos (FILEPOS_CURRENT, &currFile);
mdlElmdscr_read(&elmDP, g_AssoedFilePos, currFile, 0, &g_AssoedFilePos);
mdlElmdscr_freeAll(elmDP);
mdlState_setFunction(STATE_DATAPOINT,annotateText_accept);
mdlState_setFunction(STATE_RESET, annotateText_reset);
mFirstP=1; mTextCount=0;
mdlState_setFunction(STATE_COMPLEX_DYNAMICS, annotateText_draw);
}
Private void annotateText_targetHook(DialogItemMessage *dimP)
{
dimP->msgUnderstood = FALSE;
switch (dimP->messageType)
{
case DITEM_MESSAGE_BUTTON:
OnSelectAnnoType();
break;
}
}
void annotateText_init(void)
{
if(TextDP) mdlElmdscr_freeAll(&TextDP);
mdlDialog_itemSynch(mdlDialog_find(DIALOGID_ToolSettings, NULL), 4);
OnSelectAnnoType();
}
Private void annotateText_reset(void)
{
if(TextDP) mdlElmdscr_freeAll(&TextDP);
mdlView_updateSingle(tcb->lstvw);
mdlState_startDefaultCommand();
}
void Clear(void)
{
if(TextDP) mdlElmdscr_freeAll(&TextDP);
mdlView_updateSingle(tcb->lstvw);
mdlState_startDefaultCommand();
}
void OnSelectAnnoType(void)
{
switch(chAnnoInfo.target)
{
case 1:
mdlState_setFunction(STATE_DATAPOINT,annotateText_accept);
mdlState_startPrimitive(annotateText_accept, annotateText_reset, 0, 0);
mFirstP=1; mTextCount=0;
mdlState_setFunction(STATE_COMPLEX_DYNAMICS, annotateText_draw);
break;
case 2:
mFirstP=1;
mdlLocate_normal();
mdlState_startModifyCommand(annotateText_init, annotateText_onTarget, NULL,
NULL, NULL, 0, 0, 0, 0);
mdlLocate_init();
break;
}
}
Private void HookDestroyDlg(DialogMessage *dmP)
{
dmP->msgUnderstood=TRUE;
switch (dmP->messageType)
{
case DIALOG_MESSAGE_DESTROY:
{
Clear();
//mdlParse_unloadTable(NULL);
mdlDialog_cmdNumberQueue (FALSE, CMD_MDL_UNLOAD,mdlSystem_getCurrTaskID(), TRUE);
break;
}
default:
dmP->msgUnderstood = FALSE;
break;
}
}
Private DialogHookInfo uHooks[] = {
{IDHOOK_Destroy, HookDestroyDlg},
{HOOKITEMID_annotateTarget, annotateText_targetHook},
};
void main()
{
char *setP; /* a ptr to a "C expression symbol set" */
RscFileHandle rscFileH; /* a resource file handle */
DialogBox *dbP; /* a ptr to a dialog box */
mdlParse_loadCommandTable (NULL);
/* open the resource file that we came out of */
if (mdlResource_openFile (&rscFileH, NULL, 0)!=SUCCESS) {
mdlOutput_error("Cannot open resource file");
}
if (mdlDialog_hookPublish (sizeof(uHooks)/sizeof(DialogHookInfo), uHooks)!=SUCCESS) {
mdlOutput_error("HookPublish error");
}
setP = mdlCExpression_initializeSet (VISIBILITY_DIALOG_BOX, 0, FALSE);
mdlDialog_publishComplexVariable (setP, "annotationinfo", "chAnnoInfo", &chAnnoInfo);
mdlDialog_publishBasicArray (setP, &charType, "ActiveFcode", ActiveFcode, sizeof(ActiveFcode));
chAnnoInfo.Type=1;
chAnnoInfo.target =1;
mdlDialog_open (NULL, DIALOGID_annotation);
if(TextDP) mdlElmdscr_freeAll(&TextDP);
mdlDialog_itemSynch(mdlDialog_find(DIALOGID_ToolSettings, NULL), 4);
OnSelectAnnoType();
}
/*------------------------------------------------------------------------
-------------------------------------------------------------------------*/
Public int SetActiveFeatureEnvironment(char *code)
{
MS_sqlda sqlda;
char SqlSent[450], KeyinStr[500], Mess[60];
LinkProps props;
memset (&props, 0, sizeof (LinkProps));
props.information = 1;
sprintf(SqlSent, "select mslink, flevel, fcolor, fangle, fheight, fwidth, ffont "
"from feature where fcode = '%s'", code);
if(mdlDB_openCursor(SqlSent) != SUCCESS)
{
mdlUtil_beep(1);
mdlDialog_openInfoBox("访问数据库出错,请连接数据库!!");
return -1;
}
if(mdlDB_fetchRow(&sqlda) == QUERY_FINISHED){
sprintf(Mess, "feature表中找不到编码为<%s>的要素", code);
mdlOutput_error(Mess);
mdlUtil_beep(1);
mdlDB_closeCursor();
return -2;
}
AnnoTextInfo.mslink = atoi(sqlda.value[0]);
AnnoTextInfo.flevel = atoi(sqlda.value[1]);
AnnoTextInfo.fcolor = atoi(sqlda.value[2]);
AnnoTextInfo.fangle = atof(sqlda.value[3]);
AnnoTextInfo.fheight = atof(sqlda.value[4]);
AnnoTextInfo.fwidth = atof(sqlda.value[5]);
AnnoTextInfo.ffont = atoi(sqlda.value[6]);
mdlDB_freeSQLDADescriptor(&sqlda);
mdlDB_closeCursor();
if(mdlDB_buildLink(g_maxmslink, &g_LinkageLen, ODBC_LINKAGE, &props, "feature", AnnoTextInfo.mslink, 0) != SUCCESS)
{
mdlDialog_openInfoBox("创建图形的数据库连接失败!");
return -1;
}
sprintf(KeyinStr, "active txheight %lf; active txwidth %lf;",
AnnoTextInfo.fheight, AnnoTextInfo.fwidth);
mdlInput_sendKeyin(KeyinStr, 0, 0, ustnTaskId);
mdlParams_setActive(0, ACTIVEPARAM_LINEWEIGHT);
mdlParams_setActive(0, ACTIVEPARAM_LINESTYLE);
mdlParams_setActive(AnnoTextInfo.fcolor, ACTIVEPARAM_COLOR);
mdlParams_setActive(AnnoTextInfo.flevel, ACTIVEPARAM_LEVEL);
tcb->actangle = AnnoTextInfo.fangle;
tcb->actfont = AnnoTextInfo.ffont;
return SUCCESS;
}
void activefeature(char *unparsedP)
cmdNumber CMD_PLACENOTE
{
char code[20], *pc;
if(unparsedP && unparsedP[0]) strcpy(code, unparsedP);
else return;
pc = strchr(code, ' ');
if(pc) *pc = 0;
if(SetActiveFeatureEnvironment(code) < 0) return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -