Pro/E之菜單開發:為裝配模型樹中的元件增加右鍵快捷菜單

#define OA_MSGFILE L"Message.txt"
#define MDLTREE_MENU "ActionMenu"
#define CMD_UGASMCOMPCONSTRSHIGHLIGHT "UGAsmcompConstrsHighlight"

/*=============================================*\
Function: UserPopupmenusSetup
Purpose : Setup popup menus for selected examples
\*==================================================*/
int UserPopupmenusSetup()
{
	ProError status;
	uiCmdCmdId cmd_id;

/*-------------------------------------------*\
Create commands for Object/Action wrappers around old-style         examples that aren't setup for Object/Action
\*---------------------------------------*/
	status = ProCmdActionAdd ("UGAsmcompConstrsHighlight",
		(uiCmdCmdActFn)ShowDialoglg,//找不到定義的函數???
		uiProe2ndImmediate, 
		UserAsmcompConstraintsHighlight_TestMdlTree,
		PRO_B_FALSE, PRO_B_FALSE, &cmd_id);
//ERROR_CHECK ("UserPopupmenusSetup", "ProCmdActionAdd()", status);

	/*------------------------------------------------*\
	Add Object/Action commands to the model tree popup menu
	\*--------------------------------------------*/
	status = ProMenubarmenuPushbuttonAdd (MDLTREE_MENU,
		"UGMdlTree.ConstrsHighlight",
		"UGAsmcompConstrsHighlightLabel",
		"UGAsmcompConstrsHighlightHelp",
		NULL, PRO_B_TRUE, 
		cmd_id, OA_MSGFILE);
	//ERROR_CHECK ("UserPopupmenusSetup", //"ProMenubarmenuPushbuttonAdd()", status);

	/*---------------------------------------------*\
	Add the popup menu notification to the session
	\*--------------------------------------------------*/
	status = ProNotificationSet (PRO_POPUPMENU_CREATE_POST,
		(ProFunction)UserPopupmenuNotification);
//ERROR_CHECK ("UserPopupmenusSetup", "ProNotificationSet()", status);

	return(0);
}

/*==============================================*\
Function: UserPopupmenuNotification
Purpose: Add buttons to popup menus when they are created.
\*==================================================*/
ProError UserPopupmenuNotification (ProMenuName name)
{
	ProPopupMenuId menu_id;
	uiCmdCmdId cmd_id;
	ProError status;
	ProLine label;
	ProLine help;

	/*-----------------------------------------*\
	Check if the menu being created matches the menu name we want.
	\*---------------------------------------------*/
	ProPopupmenuIdGet (name, &menu_id);

	if (strcmp (name, "Sel Obj Menu") == 0)
	{
status = ProCmdCmdIdFind ("UGAsmcompConstrsHighlight", &cmd_id);

	/*----------------------------------------------*\
	Extract the button label and helptext from a message file.
	\*------------------------------------------------*/
		status = ProMessageToBuffer (label, OA_MSGFILE,
			"UGAsmcompConstrsHighlightLabel");
		status = ProMessageToBuffer (help, OA_MSGFILE,
			"UGAsmcompConstrsHighlightHelp");

	/*-----------------------------------------------*\
	Add the button to the end of the popup menu.
	\*----------------------------------------------*/
	status = ProPopupmenuButtonAdd (menu_id, PRO_VALUE_UNUSED,
			"UGPM.ConstrsHighlight",
			label, help,
			cmd_id,
			UserAsmcompConstraintsHighlight_TestPM,
			NULL);
//ERROR_CHECK ("UserPopupmenuNotification","ProPopupmenuButtonAdd()", //status);

	}

	return PRO_TK_NO_ERROR;
}



#define OA 1  /* Standard OA in the menu system, typically grays out 
the button when not usable */
#define PM 2 /* OA in a popup menu, typically remove the button when 
not usable */

/*==================================================*\
FUNCTION: UserAsmcompConstraintsHighlight_TestMdlTree
PURPOSE:  Test function for access for constraint highlighting from model tree RMB popup menu.
\*=====================================================*/
uiCmdAccessState UserAsmcompConstraintsHighlight_TestMdlTree(uiCmdAccessMode mode)
{
	return UserAsmcompConstraintsHighlight_TestLow (NULL, PM);
}

/*================================================*\
FUNCTION: UserAsmcompConstraintsHighlight_TestPM
PURPOSE: Test function for access for constraint highlighting from
graphics window RMB popup menu.
\*=====================================================*/
uiCmdAccessState UserAsmcompConstraintsHighlight_TestPM(uiCmdCmdId id,
														ProAppData data,
														ProSelection* sels)
{
	return UserAsmcompConstraintsHighlight_TestLow (sels, PM);
}

/*====================================================*\
FUNCTION: UserAsmcompConstraintsHighlight_TestLow
PURPOSE: Test function for access for constraint highlighting
\*==================================================*/
uiCmdAccessState UserAsmcompConstraintsHighlight_TestLow (ProSelection* sels,
														  int mode)
{
	uiCmdAccessState access_result;
	ProBoolean should_free = PRO_B_FALSE;
	ProError status;
	int size;

	/*-----------------------------------------------*\
	Set the default return if the button is unusable.
	\*-------------------------------------------------*/  
	if (mode == OA)
		access_result = ACCESS_UNAVAILABLE;
	else 
		access_result = ACCESS_REMOVE;

/*------------------------------------------------*\
If called without selections, extract the current selections from
the buffer.
\*----------------------------------------------*/ 
	if (sels == NULL)
	{   
		status = ProSelbufferSelectionsGet (&sels);

		if (status != PRO_TK_NO_ERROR)
			return access_result;

		if (sels == NULL)
			return access_result;

		should_free = PRO_B_TRUE;
	}

	/*-----------------------------------------------*\
	This command allows only one selection.
	\*------------------------------------------------*/   
	status = ProArraySizeGet (sels, &size);

	if (status != PRO_TK_NO_ERROR)
		return access_result;

	if (size == 1)
	{
		ProAsmcomp asmcomp;

		status = ProSelectionModelitemGet (sels [0], &asmcomp);

/*---------------------------------------------------*\
If the selected type is feature,its feature type must be component.
\*--------------------------------------------------*/   
		if (asmcomp.type == PRO_FEATURE)
		{
			ProFeattype ftype;

			status = ProFeatureTypeGet (&asmcomp, &ftype);

			if (ftype == PRO_FEAT_COMPONENT)
			{
				access_result = ACCESS_AVAILABLE;
			}
		}

	/*------------------------------------------------*\
	If the selected type is part or assembly,it must have a parent
	assembly to use to construct the component feature handle.
	\*----------------------------------------------*/  
	if (asmcomp.type == PRO_PART || asmcomp.type == PRO_ASSEMBLY)
		{
			ProAsmcomppath path;

		status = ProSelectionAsmcomppathGet (sels [0], &path);

			if (path.table_num > 0)
			{
				access_result = ACCESS_AVAILABLE;
			}
		}
	}

	if (should_free)
		ProSelectionarrayFree (sels);

	return access_result;
}
/*==============================================================*\
FUNCTION: ShowDialoglg
PURPOSE:  增加的菜單動作函數
\*==============================================================*/
void ShowDialoglg()
{
	AfxMessageBox(L"asdfa");
}

转载于:https://www.cnblogs.com/samyangvs05/archive/2010/04/16/1713915.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值