点击查看详细介绍

UF_UI_run_dialog() 函数的参数解释说明、函数详细用法,以及实例代码演示

misnn 10年前 1226 0

购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008  QQ号:85585969  


函数结构:
UF_UI_run_dialog
(
Widget dialog_widget
)

函数说明:
处理对话框管理和取消管理。事件的顺序是:管理对话框(dialog_widget)的主要部件。输入Ungraphics事件循环,呆在那里,直到UF_UI_exit_dialog是从对话框回调函数调用。当事件退出循环,对话的主要部件是不受管理。返回给调用者。当创建一个对话框,您必须使用从NX的视觉效果。去做这个您必须使用UF_UI_ask_default_parent_info,来获取信息。对话已被定义之后(即,在必要时创建的所有部件),主要部件被传递到UF_UI_run_dialog。这个功能管理主插件并进入NX事件循环允许对话框“运行”(即,反应以键盘输入和鼠标手势,执行回调等)。直到UF_UI_exit_dialog被称为UF_UI_run_dialog不返回给用户。当UF_UI_run_dialog已经调用,一些NX应用变得抑制。这包括在主菜单栏和各种DA1s非全局的功能。即使获得NX的部分被抑制,NX并不认为自己处于“锁定”状态。这只发生在调用UF_UI_lock_ug_access。推出不同与XtManageChild自定义对话框,与UF_UI_run_dialog你不需要调用API演示时要调用UF_UI_lock_ug_access。但是,如果你不叫UF_UI_lock_ug_access那么你就不允许调用UF_UI_cancel_uf_dialog。当对话框处理开放API计划的一部分(即对话框的回调函数)决定了它是时候终止的对话框(例如,你按确定或在对话框中取消后),UF_UI_exit_dialog应该叫。此功能只能从通过到UF_UI_run_dialog呼叫发起的对话相关联的回调函数调用。始终确保检查UF_UI_run_dialog的状态。如果出了问题,这将返回一个错误消息。您可以使用开放API UF_UI_get_fail_message以确定确切的问题UF_UI_run_dialog和UF_UI_exit_dialog经验。通过UF_UI_run_dialog推出了定制对话框的用户可能无法启动使用锁定和解锁机构或通过UF_UI_run_dialog启动另一个开放的应用。这个例子将推出一个自定义对话框有两个按钮。在推出与UF_UI_run_dialog到UF_UI_lock_ug_access进行调用,自定义对话框。这意味着必要的握手已经完成了整个会话,因此周围的每一个打开对话框或UIStyler对话框呼叫没有必要的。所以已经作出UF_UI_cancel_uf_dialog电话,以确保当用户在自定义对话框中选择另一个按钮,打开对话框,该对话框正确处理自定义对话框中的两个按钮始终保持活跃。另外,为了UF_UI_cancel_uf_dialog呼叫已经从取消按钮导航回调内作出。一直以来,这个自定义对话框始终处于锁定状态,没有必要检查锁定状态调用此函数之前。因为没有开放的API应该叫后立即UF_UI_cancel_uf_dialog,以XtAppAddTimeOut一个调用时,它有一个回调使得以UF_UI_exit_dialog必要的电话。一旦UF_UI_run_dialog已经终止,则自定义对话框的解锁完成,并UF_terminate的调用。

函数参数:
第1个参数为输入:
dialog_widget代表参数变量,Widget 为输入参数类型,Motif的对话框的主要部件。

UF_UI_run_dialog函数实例代码演示:
[quote]
#include <Xm/XmAll.h>
#include <uf.h>
#include <uf_ui_xt.h>
/* Local Function Prototypes */
static void ok_cb( Widget w, XtPointer client_data, XtPointer call_data);
static void back_cb( Widget w, XtPointer client_data, XtPointer call_data);
static void cancel_cb( Widget w, XtPointer client_data, XtPointer call_data);
static void launch_pt_sub_cb( Widget w, XtPointer button_state,
XtPointer client_data);
static void launch_str_cb( Widget w, XtPointer button_state,
XtPointer client_data);
static void call_uc1616 ( XtPointer call_data, XtIntervalId *id );
static void call_uc1600 ( XtPointer call_data, XtIntervalId *id );
static void call_end_event ( XtPointer call_data, XtIntervalId *id);
static void create_custom_dialog(Position x, Position y, Widget parent);
/* Global Variables */
static Widget custom_dialog;
extern void
ufusr(char *param, int *retcod, int param_len)
{
int uf_is_initialized;
int initialize_rcode;
int rcode;
Widget ug_parent;
Position x, y;
uf_is_initialized = UF_is_initialized();
if( uf_is_initialized == 0 )
{
initialize_rcode = UF_initialize();
if( initialize_rcode != 0 )
{
printf("Can not initialize User Function\n");
return;
}
}
/* Use NX parent and standard dialog area 2 location for */
/* the custom dialog location */
ug_parent = UF_UI_get_default_parent();
UF_UI_get_DA2_coords(&x, &y);
/* Create the custom dialog */
create_custom_dialog(x, y, ug_parent);
/* Lock at the start so no need to wrap individual calls */
rcode = UF_UI_lock_ug_access(UF_UI_FROM_CUSTOM);
if (rcode != UF_UI_LOCK_SET)
UF_UI_set_status("Can not lock Unigraphics");
/* Launch custom application into Unigraphics' event loop */
UF_UI_run_dialog (custom_dialog);
XtDestroyWidget(custom_dialog);
rcode = UF_UI_unlock_ug_access(UF_UI_FROM_CUSTOM);
if (rcode != UF_UI_UNLOCK_SET)
UF_UI_set_status("Can not unlock Unigraphics");
UF_terminate();
}
/********************************************************
Function: create_custom_dialog
Description: This is called to create the custom dialog.
*********************************************************/
static void create_custom_dialog(Position x, Position y,
Widget parent)
{
int i;
Arg args[20];
Widget form;
Widget push_button1, push_button2;
XmString canstr, helpstr, okstr;
canstr = XmStringCreate(" Back ", XmSTRING_DEFAULT_CHARSET);
helpstr = XmStringCreate("Cancel", XmSTRING_DEFAULT_CHARSET);
okstr = XmStringCreate(" OK ", XmSTRING_DEFAULT_CHARSET);
/* Create the specified dialog. */
i = 0;
XtSetArg(args[i], XmNcancelLabelString, canstr);i++;
XtSetArg(args[i], XmNhelpLabelString, helpstr);i++;
XtSetArg(args[i], XmNokLabelString, okstr);i++;
XtSetArg(args[i], XmNx, x);i++;
XtSetArg(args[i], XmNy, y);i++;
XtSetArg(args[i], XmNdefaultPosition, False);i++;
XtSetArg(args[i], XmNautoUnmanage, False);i++;
XtSetArg(args[i], XmNdeleteResponse, XmDO_NOTHING);i++;
XtSetArg(args[i], XmNmarginHeight, 10);i++;
XtSetArg(args[i], XmNmarginWidth, 0);i++;
XtSetArg(args[i], XmNdialogType, XmDIALOG_WORKING);i++;
custom_dialog = XmCreateMessageDialog (parent,
"UF_UI_run_dialog",
args, i);
XtUnmanageChild( XmMessageBoxGetChild(custom_dialog,
XmDIALOG_MESSAGE_LABEL) );
XtAddCallback (custom_dialog, XmNcancelCallback, back_cb, NULL);
XtAddCallback (custom_dialog, XmNokCallback, ok_cb, NULL);
XtAddCallback (custom_dialog, XmNhelpCallback, cancel_cb, NULL);
/* Turn the default button off. */
XtVaSetvalues(custom_dialog,
XmNdefaultButton, NULL, NULL);
form = XtVaCreateManagedWidget("grp",
xmFormWidgetClass,
custom_dialog,
NULL);
push_button1 = XtVaCreateManagedWidget( "Launch uc1600",
xmPushButtonWidgetClass, form,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL );
push_button2 = XtVaCreateManagedWidget( "Launch uc1616",
xmPushButtonWidgetClass, form,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, push_button1,
NULL );
XtAddCallback(push_button1,
XmNactivateCallback,
(XtCallbackProc) launch_str_cb,
NULL);
XtAddCallback(push_button2,
XmNactivateCallback,
(XtCallbackProc) launch_pt_sub_cb,
NULL);
}
/* The following three functions are the navigation button */
/* callbacks for the custom dialog */
/********************************************************
Function: ok_cb
Description: This is called whenever the OK button is
pressed on the custom dialog.
*********************************************************/
static void
ok_cb( Widget w, XtPointer client_data, XtPointer call_data)
{
printf("In ok callback... Not doing anything special\n");
}
/**********************************************************
Function: back_cb
Description: This is called whenever the Back button is
pressed on the custom dialog.
***********************************************************/
static void
back_cb( Widget w, XtPointer client_data, XtPointer call_data)
{
printf("In back callback... Not doing anything special\n");
}
/***********************************************************
Function: cancel_cb
Description: This is called whenever the Cancel button is
pressed on the custom dialog.
************************************************************/
static void
cancel_cb( Widget w, XtPointer client_data, XtPointer call_data)
{
int rcode;
/* Because the NX Open dialog or UIStyler dialog maybe */
/* still displayed then you need to send a cancel message */
/* to Unigraphics to cancel this presentation dialog */

rcode = UF_UI_cancel_uf_dialog (UF_UI_FROM_CUSTOM);
if (rcode == UF_UI_FAILURE)
UF_UI_set_status("Could not Cancel the dialog");
XtAppAddTimeOut(XtWidgetToApplicationContext(custom_dialog), 10,
(XtTimerCallbackProc) call_end_event, (XtPointer) NULL);
}
/**************************************************************
Function: launch_str_cb
Description: This is called when the user presses the
Launch uc1600 button in the custom dialog. It
will launch uc1600 - a NX Open dialog that allows
string input.
**************************************************************/
static void
launch_str_cb( Widget w, XtPointer button_state,
XtPointer client_data)
{
int rcode;
/* Cancel the user function dialog. If the currently */
/* displayed DA2 was not brought up by either the */
/* UIStyler or NX Open then you are not allowed to */
/* cancel this DA2 and will receive a UF_UI_FAILURE */
/* from the call to UF_UI_cancel_uf_dialog */
rcode = UF_UI_cancel_uf_dialog(UF_UI_FROM_CUSTOM);
if (rcode == UF_UI_SUCCESS)
/* It is imperative that you call XtAppAddTimeOut */
/* prior to launching a another NX Open dialog */

XtAppAddTimeOut(XtWidgetToApplicationContext(custom_dialog), 10,
(XtTimerCallbackProc) call_uc1600, (XtPointer) NULL);
else
UF_UI_set_status("Can not launch a NX Open dialog in this state");
}
/**************************************************************
Function: call_uc1600
Description: This is called via the XtAppAddTimeOut function
in launch_str_cb. This will launch uc1600 -
a NX Open dialog that allows string input.
**************************************************************/
static void call_uc1600 ( XtPointer call_data, XtIntervalId *id )
{
int rcode, num;
char default_msg[132], prompt[132];
/* Always check the return status of UF_UI_lock_ug_access */
/* to make sure that everything is fine to bring up the */
/* NX Open dialog. */
strcpy(default_msg, "Default String");
strcpy(prompt,"This is the prompt string");
rcode = uc1600(prompt, default_msg, &num);
if (rcode == 8)
UF_UI_set_status("It is not allowed to bring up a dialog in this state");
else
/* To ensure that the dialog does not remain displayed call */
/* dismiss dialog */
UF_UI_dismiss_dialog_area_2();
}
/**************************************************************
Function: launch_pt_sub_cb
Description: This is called when the user selects the
Launch uc1616 button on the custom dialog.
**************************************************************/
static void
launch_pt_sub_cb( Widget w, XtPointer button_state,
XtPointer client_data)
{
int rcode;
/* Cancel the user function dialog. If the currently */
/* displayed DA2 was not brought up by either the */
/* UIStyler or NX Open then you are not allowed to */
/* cancel this DA2 and will receive a UF_UI_FAILURE */
/* from the call to UF_UI_cancel_uf_dialog */
rcode = UF_UI_cancel_uf_dialog(UF_UI_FROM_CUSTOM);
if (rcode == UF_UI_SUCCESS)
/* It is imperative that you call XtAppAddTimeOut prior */
/* to launching a another NX Open dialog */

XtAppAddTimeOut(XtWidgetToApplicationContext(custom_dialog), 10,
(XtTimerCallbackProc) call_uc1616, (XtPointer) NULL);
else
UF_UI_set_status("Can not launch a NX Open dialog in this state");
}

/**************************************************************
* Function: call_uc1616
* Description: This is called via XtAppAddTimeOut. This will
* launch the NX Open dialog Point Subfunction.
**************************************************************/
static void call_uc1616 ( XtPointer call_data, XtIntervalId *id )
{
int def[2],rcode;
double point1[3];
rcode = uc1616("Create Point", def, 0, point1);
if (rcode == 8)
UF_UI_set_status("Not allowed to bring up a NX Open dialog in this state");
else
/* To ensure that the dialog does not remain displayed */
/* call dismiss dialog */
UF_UI_dismiss_dialog_area_2();
}
/* This function is called from the XtAppAddTimeOut function */
/* from within the cancel callback. It will call */
/* UF_UI_exit_dialog. This must be done here and not immed- */
/* iately following the UF_UI_cancel_uf_dialog call. This is */
/* because Unigraphics needs time to process the */
/* UF_UI_cancel_uf_dialog call. If not given this time then */
/* Unigraphics will deny the request to UF_UI_exit_dialog */
static void call_end_event ( XtPointer call_data, XtIntervalId *id)
{
int rcode;
char msg[132];
rcode = UF_UI_exit_dialog();
/* Should always check the return status of UF_UI_exit_dialog */
/* If you haven't cancelled properly prior to calling this */
/* then you will receive an error. */
if (rcode != UF_UI_SUCCESS)
{
UF_get_fail_message(rcode,msg);
UF_UI_set_status(msg);
}
}

int ufusr_ask_unload(void)
{
/* Want to only unregister the callback during the */
/* unloading of the NX Open program */
return ( UF_UNLOAD_SEL_DIALOG );
}


[/quote]

0

最新回复 (0)
请登录后发表新帖