📄 block_dialog.cpp
字号:
#include <stdio.h>
#include <uf.h>
#include <uf_defs.h>
#include <uf_exit.h>
#include <uf_ui.h>
#include <uf_styler.h>
#include <uf_mb.h>
#include <uf_modl.h>
#include "block_dialog.h"
/* The following definition defines the number of callback entries */
/* in the callback structure: */
/* UF_STYLER_callback_info_t BL_cbs */
#define BL_CB_COUNT ( 2 + 1 ) /* Add 1 for the terminator */
/*--------------------------------------------------------------------------
The following structure defines the callback entries used by the
styler file. This structure MUST be passed into the user function,
UF_STYLER_create_dialog along with BL_CB_COUNT.
--------------------------------------------------------------------------*/
static UF_STYLER_callback_info_t BL_cbs[BL_CB_COUNT] =
{
{UF_STYLER_DIALOG_INDEX, UF_STYLER_OK_CB , 0, BL_ok_cb},
{UF_STYLER_DIALOG_INDEX, UF_STYLER_CANCEL_CB , 0, BL_cancel_cb},
{UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 }
};
/*--------------------------------------------------------------------------
UF_MB_styler_actions_t contains 4 fields. These are defined as follows:
Field 1 : the name of your dialog that you wish to display.
Field 2 : any client data you wish to pass to your callbacks.
Field 3 : your callback structure.
Field 4 : flag to inform menubar of your dialog location. This flag MUST
match the resource set in your dialog! Do NOT ASSUME that changing
this field will update the location of your dialog. Please use the
UIStyler to indicate the position of your dialog.
--------------------------------------------------------------------------*/
static UF_MB_styler_actions_t actions[] = {
{ "block_dialog.dlg", NULL, BL_cbs, UF_MB_STYLER_IS_NOT_TOP },
{ NULL, NULL, NULL, 0 } /* This is a NULL terminated list */
};
extern void ufsta (char *param, int *retcode, int rlen)
{
int error_code;
if ( (UF_initialize()) != 0)
return;
if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 )
{
char fail_message[133];
UF_get_fail_message(error_code, fail_message);
printf ( "%s\n", fail_message );
}
UF_terminate();
return;
}
static void create_block( char **block_len )
{
UF_FEATURE_SIGN sign = UF_NULLSIGN;
double block_orig[3] = {0.0,0.0,0.0};
tag_t blk_obj;
UF_MODL_create_block1(sign, block_orig, block_len, &blk_obj);
}
/*-------------------------------------------------------------------------*/
/*---------------------- UIStyler Callback Functions ----------------------*/
/*-------------------------------------------------------------------------*/
/* -------------------------------------------------------------------------
* Callback Name: BL_ok_cb
* This is a callback function associated with an action taken from a
* UIStyler object.
*
* Input: dialog_id - The dialog id indicate which dialog this callback
* is associated with. The dialog id is a dynamic,
* unique id and should not be stored. It is
* strictly for the use in the NX Open API:
* UF_STYLER_ask_value(s)
* UF_STYLER_set_value
* client_data - Client data is user defined data associated
* with your dialog. Client data may be bound
* to your dialog with UF_MB_add_styler_actions
* or UF_STYLER_create_dialog.
* callback_data - This structure pointer contains information
* specific to the UIStyler Object type that
* invoked this callback and the callback type.
* -----------------------------------------------------------------------*/
int BL_ok_cb ( int dialog_id,
void * client_data,
UF_STYLER_item_value_type_p_t callback_data)
{
UF_STYLER_item_value_type_t value;
char **block_edges = NULL;
char height1[132], dia[132], mess[132];
int error_code;
if ( UF_initialize() != 0)
return ( UF_UI_CB_CONTINUE_DIALOG );
value.item_id = BL_REAL_2;
value.item_attr =UF_STYLER_VALUE;
UF_STYLER_ask_value( dialog_id, &value );
double length = value.value.real;
value.item_id = BL_REAL_3;
//value.item_attr =UF_STYLER_VALUE;
UF_STYLER_ask_value( dialog_id, &value );
double width = value.value.real;
value.item_id = BL_REAL_4;
//value.item_attr =UF_STYLER_VALUE;
UF_STYLER_ask_value( dialog_id, &value );
double height = value.value.real;
block_edges = (char**)UF_allocate_memory( 3*sizeof(char*), &error_code);
block_edges[0] = (char*)UF_allocate_memory( 132*sizeof(char), &error_code);
block_edges[1] = (char*)UF_allocate_memory( 132*sizeof(char), &error_code);
block_edges[2] = (char*)UF_allocate_memory( 132*sizeof(char), &error_code);
sprintf(mess, "%f", length);
strcpy( block_edges[0], mess);
sprintf(mess, "%f", width);
strcpy( block_edges[1], mess);
sprintf(mess, "%f", height);
strcpy( block_edges[2], mess);
UF_STYLER_free_value( &value );
create_block(block_edges);
for (int i=0; i<3; i++)
UF_free( block_edges[i] );
UF_free( block_edges );
UF_terminate ();
/* Callback acknowledged, terminate dialog */
/* It is STRONGLY recommended that you exit your */
/* callback with UF_UI_CB_EXIT_DIALOG in a ok callback.*/
/* return ( UF_UI_CB_EXIT_DIALOG ); */
return (UF_UI_CB_EXIT_DIALOG);
}
/* -------------------------------------------------------------------------
* Callback Name: BL_cancel_cb
* This is a callback function associated with an action taken from a
* UIStyler object.
*
* Input: dialog_id - The dialog id indicate which dialog this callback
* is associated with. The dialog id is a dynamic,
* unique id and should not be stored. It is
* strictly for the use in the NX Open API:
* UF_STYLER_ask_value(s)
* UF_STYLER_set_value
* client_data - Client data is user defined data associated
* with your dialog. Client data may be bound
* to your dialog with UF_MB_add_styler_actions
* or UF_STYLER_create_dialog.
* callback_data - This structure pointer contains information
* specific to the UIStyler Object type that
* invoked this callback and the callback type.
* -----------------------------------------------------------------------*/
int BL_cancel_cb ( int dialog_id,
void * client_data,
UF_STYLER_item_value_type_p_t callback_data)
{
/* Make sure User Function is available. */
if ( UF_initialize() != 0)
return ( UF_UI_CB_CONTINUE_DIALOG );
/* ---- Enter your callback code here ----- */
UF_terminate ();
/* Callback acknowledged, terminate dialog */
/* It is STRONGLY recommended that you exit your */
/* callback with UF_UI_CB_EXIT_DIALOG in a cancel call */
/* back rather than UF_UI_CB_CONTINUE_DIALOG. */
return ( UF_UI_CB_EXIT_DIALOG );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -