找回密码 注册 QQ登录
一站式解决方案

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?在线3D打印服务,一键上传,自动报价 
查看: 16336|回复: 1
打印 上一主题 下一主题

[原创] UG/Open对话框调用的心得二(含疑问,请ZZZ及各位大侠指点一下)

[复制链接]
跳转到指定楼层
1
发表于 2008-11-16 17:06:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
这次以UG提供的UG\help中的uf_sample_app.c为例进行说明,为了便于理解,仅对程序中的第二项回调函数SAMPLE_APP__action2进行分析,程序段如下:

static void SAMPLE_APP__enter( void );
static void SAMPLE_APP__init( void );
static void SAMPLE_APP__exit( void );


static UF_MB_cb_status_t SAMPLE_APP__action2(
    UF_MB_widget_t             widget,
    UF_MB_data_t               client_data,
    UF_MB_activated_button_p_t call_button );

static int app_id = 0;

static UF_MB_action_t actionTable[] =
{
{ "SAMPLE_APP__action2", SAMPLE_APP__action2, NULL   },
{ NULL, NULL, NULL }
};
static void print_error(char*fun, int status);

extern void ufsta( char *param, int *returnCode, int rlen )
{
    UF_MB_application_t appData;
    char name[] = "SAMPLE_APP";
    int status;
    int ifail=0;
            /* Initialize the API environment */
    ifail= UF_initialize();

    if ( !ifail )
    {
        status = UF_MB_add_actions( actionTable );
        /* TODO: Add your application code here */
        /* Initialize application data */      
        appData.name       = name;
        appData.id         = 0;
        appData.init_proc  = SAMPLE_APP__init;
        appData.exit_proc  = SAMPLE_APP__exit;
        appData.enter_proc = SAMPLE_APP__enter;
         /* Initialize application support flags */
        appData.drawings_supported          = TRUE;
        appData.design_in_context_supported = TRUE;
        /* Register the application with UG */

        status = UF_MB_register_application( &appData );                              
        app_id=appData.id;
        /* Terminate the API environment */
        //errorCode = UF_terminate();
    }

        else
        {
         char message[133];
        UF_get_fail_message( ifail, message );

        /* Print out the message */
        UF_UI_set_status( message );

        fprintf( stderr, "%s\n", message );
                                
        }

    ifail = UF_terminate();   
}
/*****************************************************************************
**  Utilities
*****************************************************************************/

/* Unload Handler
**     This function specifies when to unload your application from Unigraphics.
**     If your application registers a callback (from a MenuScript item or a
**     User Defined Object for example), this function MUST return
**     "UF_UNLOAD_UG_TERMINATE". */
//extern int ufusr_ask_unload( void )
//{
//   return( UF_UNLOAD_IMMEDIATELY );
//}

static void print_error( char *fun, int status )
{
    if ( status != 0 )
    {
        char msg[133];

        UF_get_fail_message( status, msg );
        printf( "%s failed with error = %d\n  %s\n", fun, status, msg );
    }
}

static void SAMPLE_APP__enter( void)
{
    printf( "Entering application\n" );

    /* Place code to enter application here */
}

static void SAMPLE_APP__init( void )
{
    printf( "Initializing application\n" );

    /* Place code to initialize application here */
}

static void SAMPLE_APP__exit( void )
{
    printf( "Exiting application\n" );

    /* Place code to cleanup for application and exit here */
}

/*----------------------------------------------------------------------------*
*  SAMPLE_APP__action2
*
*      Allow the user to specify this function's return value
*----------------------------------------------------------------------------*/
static UF_MB_cb_status_t SAMPLE_APP__action2(
    UF_MB_widget_t             widget,
    UF_MB_data_t               client_data,
    UF_MB_activated_button_p_t call_button )
{
     char options[5][38] = { "UF_MB_CB_CONTINUE",
                                      "UF_MB_CB_CANCEL",
                                      "UF_MB_CB_OVERRIDE_STANDARD",
                                      "UF_MB_CB_WARNING",
                                      "UF_MB_CB_ERROR"
                                    };
    char msg[133];
    int option_number=5;
    int response=0;

    UF_MB_cb_status_t cb_value = UF_MB_CB_CANCEL;
     if(UF_initialize()!=0)
    return (UF_UI_CB_CONTINUE_DIALOG);
    response = uc1603( "Choose value to return", 0, options, option_number );
       switch ( response )
    {
        case 1:
        case 2:
            cb_value = UF_MB_CB_CANCEL;
            printf( "    Response = \"%s\" (%d)\n",
            ( response == 1 ? "Back" : "Cancel" ), response );
             break;

        case 5:
            cb_value = UF_MB_CB_CONTINUE;
            break;

        case 6:
            cb_value = UF_MB_CB_CANCEL;
            break;

        case 7:
            cb_value = UF_MB_CB_OVERRIDE_STANDARD;
            break;

        case 8:
            cb_value = UF_MB_CB_WARNING;
            break;

        case 9:
            cb_value = UF_MB_CB_ERROR;
            break;

        default:
            cb_value = UF_MB_CB_ERROR;
            printf( "    Response = \"%s\" (%d)\n", "Unexpected", response );            
            sprintf(msg, "Response number is %d",response);
            UF_UI_lock_ug_access( UF_UI_FROM_CUSTOM );
            uc1601( msg, 1 );
            UF_UI_unlock_ug_access( UF_UI_FROM_CUSTOM );
            break;
    }

    printf( "Return = %s\n", options[response - 5][0] );   
    return( cb_value );
}

其启动菜单按如下设置:

出了点出问题,后面再接着发,请大家稍微等等了.....

[ 本帖最后由 j_tian 于 2008-11-16 17:35 编辑 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 赞一下!赞一下!
2
发表于 2008-11-17 21:29:48 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2024-9-21 17:35 , Processed in 0.020490 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

快速回复 返回顶部 返回列表