⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chkanlnk.mc

📁 Bentley Microstation的二次开发工具MDL的学习源代码
💻 MC
📖 第 1 页 / 共 2 页
字号:
/*================================================================================
						Step by step 之 MDL 快速入门实例十五
================================================================================*/
#include    <mdl.h>			/* MDL Library funcs structures & constants */
#include    <mselems.h>
#include    <mslstyle.h>
#include    <scanner.h>
#include    <dlogitem.h>    /* Dialog Box Manager structures & constants */
#include    <cexpr.h>	    /* C Expression structures & constants */
#include    <userfnc.h>
#include    <cmdlist.h>	    /* MicroStation command numbers */
#include    <colrname.h>
#include    <stdarg.h>
#include    <dlogids.h>
#include	<dlogitem.h>
#include    <stdlib.h>
#include    <string.h>
#include    <stdio.h>
#include	<tcb.h>
#include    <dlogman.fdf>   /* dialog box manager function prototypes */
#include	<mselemen.fdf>

#include	"chkanlnkr.h"

#define		MAX_NOTE_NUM 2048
#define		CODELEN			12
#define 	COLOR_HEIGHTPOINT	5
#define 	LEVEL_HEIGHTPOINT	37
#define 	COLOR_HEIGHTTEXT 	0
#define 	LEVEL_HEIGHTTEXT 	37

typedef struct tagAnnotationLinkage{
	ULong fpos1, fpos2;
}AnnotationLink;

AnnotationLink annolink[MAX_NOTE_NUM];


void *tEdP=NULL;	/*This pointer will save the transient data*/
Dpoint3d SP1[MAX_NOTE_NUM];
Dpoint3d SP2[MAX_NOTE_NUM];
int number;
unsigned short idd[MAX_NOTE_NUM];

boolean g_bExecUserUpdate;
VIEWLISTTOGGLE g_NoteViewToggle;
long g_ViewMask;

DISPSYMBOLOGY g_Symbology;

int g_NoteType=1;
int g_CurDispType;
int g_CurActiveColor;	/*当前的颜色*/
boolean g_CurViewList[MAX_VIEWS];
ULong g_FilePos;
int		g_CurLevel;				/*current active level*/
int		g_CurColor;				/*current active color*/

UShort	g_MSFCLnkID[8];	/*the MSFC linkage array of one element*/
int		g_MSFCLnkNum;	/*the number of MSFC linkage of one element*/
int		g_CurPos;		/*the current position of ATTRIBUTE file*/

ANOTEPOS g_ANotePos[MAX_NOTE_NUM];	/*the Array of all notes which have linkage*/

int g_MaxNote=0;	/*the number of maximum note*/

void GetNotePos(int fileno);
void HookDispNAsc(DialogItemMessage *dimP);
void HookToggleNAsc(DialogItemMessage *dimP);
void HookExitChkNA(DialogItemMessage *dimP);
void TurnOnAllLevels(short ViewList[],boolean bTurnOn,boolean bUpdate);
void UpdateView(void);
void DisplayHeightPTag(void);
int UnloadFunction(int reasonCode);
void SymbolizeElmdscr(MSElementDescr* elmDP,int type);
void FindElement(double Height_Pointx,double Height_Pointy,ULong id);
void InitData(void);
void DisplayHeightText(void);
void DisplayHeightPTag(void);
void DisplayNonHeightPTag(void);
void RestoreNormal(void);

static DialogHookInfo uHooks[]=  
{
	{IDHOOK_ToggleNA,			HookToggleNAsc},
	{IDHOOK_DispNA,				HookDispNAsc},
	{IDHOOK_ExitChkNA,			HookExitChkNA},
};


Public void main(int argc,char *argv[])
{
    char		   *setP;	/* ptr to "C expression symbol set" */
    RscFileHandle	    rscFileH;	/* a resource file handle */
    char		    buffer[80];

		/* open the resource file that we came out of */
    mdlResource_openFile (&rscFileH, NULL, 0);
	
		/* set up variables that will be evaluated within C expression strings */
    setP = mdlCExpression_initializeSet (VISIBILITY_DIALOG_BOX, 0, FALSE);
	mdlDialog_publishComplexVariable (setP, "tagViewListToggle", "g_NoteViewToggle", &g_NoteViewToggle);
	mdlDialog_publishComplexVariable (setP, "tagDISPSYMBOLOGY", "g_Symbology", &g_Symbology);
	mdlDialog_publishBasicVariable (setP, &intType,"g_NoteType",&g_NoteType);
	mdlSystem_setFunction (SYSTEM_UNLOAD_PROGRAM, UnloadFunction);

    /* publish our hook functions */
	mdlDialog_hookPublish (sizeof(uHooks)/sizeof(DialogHookInfo), uHooks);

	InitData();

	strcpy(g_Symbology.lineweight,"3");
	mdlDialog_open(NULL,DIALOGID_CHKNOTE);
}


/*-------------------- Unload Function --------------------*/
int UnloadFunction(int reasonCode)
{
    return FALSE;
}


void GetFirstPoint(MSElementDescr *emd, Dpoint3d *dp)
{
	switch (emd->el.ehdr.type)
	{
		case 2:
			mdlCell_extract(dp, NULL, NULL, NULL, NULL, &emd->el);
			break;
		case 17:
			mdlText_extract(NULL, dp, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &emd->el);
			break;
		default:
			if (mdlElmdscr_extractEndPoints(dp, NULL, NULL, NULL, emd, 0)!=SUCCESS)
			{
				dp->x=0, dp->y=0, dp->z=0;
			}
	}
}


/*接管系统的刷新函数*/
int UserUpdate(	int	preUpdate,  int eraseMode,  long *fileMask,  int numRegions,
				Asynch_update_view regions[],  Rectangle *coverLists[],
				int numCovers[],  MSDisplayDescr *displayDescr[])
{
	int i,mView;
	if(!g_bExecUserUpdate)
		return 0;
	for(i=0;i<numRegions;i++){
		for(mView=0;mView<MAX_VIEWS;mView++){
			if(regions[i].viewnum==mView){
				if(g_NoteViewToggle.status[mView]){
					if(g_Symbology.dispall==-1)
						return 0;
					g_CurDispType=g_NoteType-1;
					if(g_Symbology.dispheight==-1)
					{
						DisplayHeightText();
						g_CurDispType=g_NoteType;
					}
					else if(g_Symbology.dispnonlink==-1)
					{
						DisplayNonHeightPTag();
						g_CurDispType=g_NoteType;
					}
					if(g_Symbology.displink==-1)
						DisplayHeightPTag();  
					else 
					{
						g_bExecUserUpdate=FALSE;
						UpdateView();
						g_bExecUserUpdate=TRUE;
					}
				}
				else
					return 0;	/*update by MS.*/
			}
		}
	}
	return 1;
}


void InitData(void)
{
	int i;

	g_MaxNote=0;
	for(i=0;i<MAX_VIEWS;i++){
		g_NoteViewToggle.status[i]=FALSE;
		g_CurViewList[i]=FALSE;
	}
	g_NoteViewToggle.status[0]=TRUE;
	g_Symbology.displink=-1;
}


// display all height point and text without linkage
void DisplayNonHeightPTag(void)
{
	int i,mScanWords,mStatus,mElmNum,type;
	Scanlist mScanList;
	ULong mNextFilePos,mRetPos[50],mActualPos;
	MSElementUnion elm;
	unsigned short buff[4];       //add
	MSElementDescr  *elmDP;
	ExtendedAttrBuf attbuf;
	int color,level;
	
		 /*Set scan params.*/
	mdlScan_initScanlist(&mScanList);
	mScanList.scantype = ELEMTYPE | NESTCELL;	
	mScanList.extendedType=FILEPOS;
	mdlScan_noRangeCheck(&mScanList);
	mdlScan_setDrawnElements(&mScanList);
	mdlScan_initialize(0,&mScanList);
		                                //Begin scan 
	do{
		mScanWords=sizeof(mRetPos)/sizeof(UShort);
		mStatus=mdlScan_file(mRetPos, &mScanWords, sizeof(mRetPos), &mNextFilePos);
		mElmNum=mScanWords/sizeof(UShort);
		for(i=0; i<mElmNum; i++)
		{
	                mdlElmdscr_read(&elmDP, mRetPos[i], 0, 0, NULL);
	                if (elmDP->el.ehdr.complex==1) continue;
			if (elmDP->h.firstElem!=NULL)
			{
				mdlElement_getProperties(&level,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&elmDP->h.firstElem->el);
				mdlElement_getSymbology(&color,NULL,NULL,&elmDP->h.firstElem->el);
			}
			else
			{
				mdlElement_getProperties(&level,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&elmDP->el);
				mdlElement_getSymbology(&color,NULL,NULL,&elmDP->el);
			}
			if ((level==LEVEL_HEIGHTPOINT && color==COLOR_HEIGHTPOINT)
			 		|| (level==LEVEL_HEIGHTTEXT && color==COLOR_HEIGHTTEXT) )
			 	if (mdlLinkage_extractUsingDescr(NULL, elmDP, 0x99, 0, NULL, NULL, NULL, TRUE)==NULL)
				 	mdlElmdscr_display(elmDP, 0, NORMALDRAW);
			mdlElmdscr_freeAll(&elmDP);
		}
	}while(mStatus==BUFF_FULL);

}


// display all height point and text with or without linkage
void DisplayHeightText(void)
{
	int i,mScanWords,mStatus,mElmNum,type;
	Scanlist mScanList;
	ULong mNextFilePos,mRetPos[50],mActualPos;
	MSElementUnion elm;
	unsigned short buff[4];       //add
	MSElementDescr  *elmDP;
	ExtendedAttrBuf attbuf;
	int color,level;
	
		 /*Set scan params.*/
	mdlScan_initScanlist(&mScanList);
	mScanList.scantype = ELEMTYPE | NESTCELL;
	mScanList.extendedType=FILEPOS;
	mdlScan_noRangeCheck(&mScanList);
	mdlScan_setDrawnElements(&mScanList);
	mdlScan_initialize(0,&mScanList);
		                                //Begin scan 
	do{
		mScanWords=sizeof(mRetPos)/sizeof(UShort);
		mStatus=mdlScan_file(mRetPos, &mScanWords, sizeof(mRetPos), &mNextFilePos);
		mElmNum=mScanWords/sizeof(UShort);
		for(i=0; i<mElmNum; i++)
		{
	                mdlElmdscr_read(&elmDP, mRetPos[i], 0, 0, NULL);
			if (elmDP->h.firstElem!=NULL)
			{
				mdlElement_getProperties(&level,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&elmDP->h.firstElem->el);
				mdlElement_getSymbology(&color,NULL,NULL,&elmDP->h.firstElem->el);
			}
			else
			{
				mdlElement_getProperties(&level,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&elmDP->el);
				mdlElement_getSymbology(&color,NULL,NULL,&elmDP->el);
			}
			if ((level==LEVEL_HEIGHTPOINT && color==COLOR_HEIGHTPOINT)
			 	|| (level==LEVEL_HEIGHTTEXT && color==COLOR_HEIGHTTEXT) )
			 	mdlElmdscr_display(elmDP, 0, NORMALDRAW);
			mdlElmdscr_freeAll(&elmDP);
		}
	}while(mStatus==BUFF_FULL);

}

			
/*This function show all features which have notes and their notes and draw lines between them*/
void DisplayHeightPTag(void)
{
	int i;

	GetNotePos(0);	//Get all notes which have special linkage

	g_bExecUserUpdate=FALSE;
	UpdateView();
	g_bExecUserUpdate=TRUE;

	for (i=0; i<MAX_NOTE_NUM; i++)
	{
		if (annolink[i].fpos1!=0 && annolink[i].fpos2!=0) FindElement(0, 0, i);
	}
}


/*--------------------------------------------------*/

void HookToggleNAsc(DialogItemMessage *dimP)
{
	if (dimP->messageType==DITEM_MESSAGE_STATECHANGED)
	{
		dimP->messageType=DITEM_MESSAGE_BUTTON;
		HookDispNAsc(dimP);
		g_CurDispType=g_NoteType-1;
	}
	else
		dimP->msgUnderstood=FALSE;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -