
UF_UI_exit_dialog() 函数的参数解释说明、函数详细用法,以及实例代码演示
购买与咨询 NX 二次开发视频教程,请联系微信号:13890821008 QQ号:85585969
函数结构:
UF_UI_exit_dialog
函数说明:
使当前执行用户的Motif对话框的事件循环退出,反过来,使UF_UI_run_dialog()(用于启动对话框)执行的回报。这仅涉及用于与UF_UI_run_dialog。经常检查UF_UI_exit_dialog的返回状态以确保退出对话框是成功的。如果使用的是UF_UI_cancel_uf_dialog协议,然后UF_UI_exit_dialog应通过回调调用XtAppAddTimeOut,否则就叫UF_UI_exit_dialog直接。到UF_UI_exit_dialog调用会导致终止事件循环这,反过来,使UF_UI_run_dialog返回到它的调用者。
UF_UI_exit_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]
-
无