#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");
}