iCAx开思工具箱

标题: 请大虾一语惊醒菜鸟。。。 [打印本页]

作者: openi    时间: 2004-10-11 15:14
标题: 请大虾一语惊醒菜鸟。。。
我为了看一下如何编辑已存在的part的表达式如何用,在对话框赋一个值,就是没反应,不知为何?请大虾一语惊醒菜鸟。。。请看下面的代码:。
   /---------------------/
//  uu.cpp
//
//  Description:
//      Contains Unigraphics entry points for the application.
//
//////////////////////////////////////////////////////////////////////////////
  
/* These include files are needed for the following template code.            */
#include <string.h>
#include <windows.h>
  
#include <stdio.h>  
#include <uf.h>
#include <uf_defs.h>
#include <uf_exit.h>
#include <uf_ui.h>
#include <uf_styler.h>
#include <uf_part.h>
#include <uf_object_types.h>
#include <uf_mb.h>  
#include <UF_MODL.h>
#include "uu.h"
  
/* The following definition defines the number of callback entries */
/* in the callback structure:                                      */
/* UF_STYLER_callback_info_t CHANGE_cbs */
#define CHANGE_CB_COUNT ( 1 + 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 CHANGE_CB_COUNT.                        
--------------------------------------------------------------------------*/
static UF_STYLER_callback_info_t CHANGE_cbs[CHANGE_CB_COUNT] =  
{
  {UF_STYLER_DIALOG_INDEX, UF_STYLER_APPLY_CB        , 0, CHANGE_apply_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[] = {
     { "uu.dlg",  NULL,   CHANGE_cbs,  UF_MB_STYLER_IS_NOT_TOP },
     { NULL,  NULL,  NULL,  0 } /* This is a NULL terminated list */
};
  
extern "C" DllExport void ufusr( char *param, int *returnCode, int rlen )
{
     /* Initialize the API environment */
     int errorCode = UF_initialize();
  
     if ( 0 == errorCode )
     {
         /* TODO: Add your application code here */
   /* Terminate the API environment */
         errorCode = UF_terminate();
     }
  
     /* Print out any error messages */
}
extern "C" int ufusr_ask_unload( void )
{
     return( UF_UNLOAD_UG_TERMINATE );
}
        
  
/*---------------- MENUBAR HOOKUP HELP Example -------------------
To launch this dialog from a Unigraphics menubar, you must follow  
the steps below.
1)  Add the following lines to your MenuScript file in order to  
     associate a menu bar button with your dialog.  In this      
     example, a cascade menu will be created and will be         
     located just before the Help button on the main menubar.   
     The button, UU_BTN is set up to launch your dialog and  
     will be positioned as the first button on your pulldown menu.
     If you wish to add the button to an existing cascade, simply  
     add the 3 lines between MENU LAUNCH_CASCADE and END_OF_MENU   
     to your menuscript file.   
      
     The MenuScript file requires an extension of ".men".
     Make sure that you add the extension to the file and place   
     the file in your startup directory:
       $UGII_USER_DIR/startup or  
       $UGII_SITE_DIR/startup or  
       $UGII_VENDOR_DIR/startup directory
  
     Move the contents between the dashed lines to your Menuscript file.
!   ----------------------------------------------------------------
     VERSION 120
  
     EDIT UG_GATEWAY_MAIN_MENUBAR
  
     BEFORE UG_HELP
       CASCADE_BUTTON UISTYLER_DLG_CASCADE_BTN
       LABEL Dialog Launcher
     END_OF_BEFORE
   
     MENU UISTYLER_DLG_CASCADE_BTN
       BUTTON UU_BTN
       LABEL Display uu dialog
       ACTIONS uu.dlg
     END_OF_MENU
!   ---------------------------------------------------------------
  
2) Issue a call to the function, UF_MB_add_styler_actions from the ufsta
    user exit as shown below.  To use this call, remove the conditional  
    definitions:  #ifdef MENUBAR_COMMENTED_OUT  
                  #endif MENUBAR_COMMENTED_OUT  
     
    The static structure, actions, will allow you to associate ALL of your
    dialogs and callback functions to the  menubar at once.  For example, if you  
    wish to have 10 dialogs associated to 10 different buttons on the menubar,
    you may enter each dialog and callback list into the actions structure. Make
    sure that you have created a corresponding button in your MenuScript file.
     
    You may also have separate shared libraries, each with a ufsta user exit
    for each individual dialog.
  
3) Place your compiled and linked ufsta user function in  
    $UGII_USER_DIR/startup or   
    $UGII_SITE_DIR/startup or  
    $UGII_VENDOR_DIR/startup directory.      
   
    NOTE:  The user function must contain the proper extension .so, .sl or .dll  
    to make ensure that it is recognized by the MenuScript.  If it does not
    have the proper extension, it will NOT be recognized by MenuScript.     
  
    The action name you have provided in your MenuScript must correspond to
    to the dialog name provided in the action structure.  This MUST match inorder
    to bind your dlg file to your MenuScript button.                             
  
4) Copy your UIStyler dialog file to the proper directory.
    All dialog files (.dlg) must be located in  
       $UGII_USER_DIR/application or  
       $UGII_SITE_DIR/application or  
       $UGII_VENDOR_DIR/application directory
  
------------------------------------------------------------*/
#ifdef MENUBAR_COMMENTED_OUT
extern void ufusr (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;
}
#endif /*MENUBAR_COMMENTED_OUT*/
  
/*-------DIALOG CREATION FROM A CALLBACK HELP Example ----------
If you wish to have this dialog displayed from the callback of  
another UIStyler dialog, you should:                           
  
1) Make sure that the callback of your UIStyler dialog is  
    designated as a dialog building callback.               
2) Remove the conditional definitions:
    #ifdef DISPLAY_FROM_CALLBACK  
    #endif DISPLAY_FROM_CALLBACK
3) Your callback should issue a call to this function.
4) You should also add the funcitonal prototype to your header file  
    (uu.h) and ensure that the file is properly included.
  
All dialog files must be located in  
       $UGII_USER_DIR/application or  
       $UGII_SITE_DIR/application or  
       $UGII_VENDOR_DIR/application directory
--------------------------------------------------------------*/
  
#ifdef DISPLAY_FROM_CALLBACK
extern int ufusr ( int *response )
{
     int  error_code = 0;
   
     if ( ( error_code = UF_initialize() ) != 0 )  
            return (0) ;
  
     if ( ( error_code = UF_STYLER_create_dialog ( "uu.dlg",
            CHANGE_cbs,      /* Callbacks from dialog */
            CHANGE_CB_COUNT, /* number of callbacks*/
            NULL,        /* This is your client data */
            response ) ) != 0 )
     {
           char fail_message[133];
  
           /* Get the user function fail message based on the fail code.*/
           UF_get_fail_message(error_code, fail_message);
           UF_UI_set_status (fail_message);
           printf ( "%s\n", fail_message );  
     }
  
     UF_terminate();                              
     return (error_code);
}
#endif /* DISPLAY_FROM_CALLBACK */  
  
/*-------DIALOG CREATION FROM A USER EXIT HELP Example --------
To create this dialog from a user exit, you must invoke a      
call to the UG/Open API, UF_STYLER_create_dialog.  An example  
is shown below.                                                
  
All dialog files must be located in  
       $UGII_USER_DIR/application or  
       $UGII_SITE_DIR/application or  
       $UGII_VENDOR_DIR/application directory
  
1) Remove the conditional definitions:
    #ifdef DISPLAY_FROM_USER_EXIT  
    #endif DISPLAY_FROM_USER_EXIT  
2) Add a user exit to the function name below, for example, ufusr.
3) Consider how your shared library will be unloaded.  Take a look
    at the generated function ufusr_ask_unload.
--------------------------------------------------------------*/
  
#ifdef DISPLAY_FROM_USER_EXIT
extern void ufusr (char *param, int *retcode, int rlen)
{
     int  response   = 0;
     int  error_code = 0;
   
     if ( ( UF_initialize() ) != 0 )  
            return;
  
     if ( ( error_code = UF_STYLER_create_dialog ( "uu.dlg",
            CHANGE_cbs,      /* Callbacks from dialog */
            CHANGE_CB_COUNT, /* number of callbacks*/
            NULL,        /* This is your client data */
            &response ) ) != 0 )
     {
           char fail_message[133];
  
           /* Get the user function fail message based on the fail code.*/
           UF_get_fail_message(error_code, fail_message);
           UF_UI_set_status (fail_message);
           printf ( "%s\n", fail_message );  
     }
  
     UF_terminate();                              
}
  
/*--------------------------------------------------------------------------
This function specifies how a shared image is unloaded from memory           
within Unigraphics. This function gives you the capability to unload an      
internal UG/Open application or user  exit from Unigraphics.  You can        
specify any one of the three constants as a return value to determine        
the type of unload to perform:  immediately after user function              
execution, via an unload selection dialog, or when Unigraphics terminates   
terminates.  If you choose UF_UNLOAD_SEL_DIALOG, then you have the           
option to unload your image by selecting  File->Utilities->Unload Shared     
Image.  
  
NOTE:  A program which associates UG/Open applications with the menubar      
MUST NOT use this option since it will UNLOAD your UG/Open application image
--------
from the menubar.
--------------------------------------------------------------------------*/
  
/*--------------------------------------------------------------------------
You have the option of coding the cleanup routine to perform any housekeeping
chores that may need to be performed.  If you code the cleanup routine, it is
automatically called by Unigraphics.
--------------------------------------------------------------------------*/
extern void ufusr_cleanup (void)
{
     return;
}
#endif /* DISPLAY_FROM_USER_EXIT */  
  
/*-------------------------------------------------------------------------*/
/*---------------------- UIStyler Callback Functions ----------------------*/
/*-------------------------------------------------------------------------*/
  
/* -------------------------------------------------------------------------
  * Callback Name: CHANGE_apply_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 UG/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 CHANGE_apply_cb ( int dialog_id,
              void * client_data,
              UF_STYLER_item_value_type_p_t callback_data)
{
char aa[133];  /*设置的参数类型*/
char string1[256];  
int number_of_exps=0,i;
tag_t *exps;
char *string;
int part_tag;
/*---------------------------------*/
      /* Make sure User Function is available. */   
      if ( UF_initialize() != 0)  
           return ( UF_UI_CB_CONTINUE_DIALOG );
UF_STYLER_item_value_type_t data;
data.item_attr = UF_STYLER_VALUE;
data.item_id = CHANGE_INT_0; /*控件的标识*/
UF_STYLER_ask_value(dialog_id, [$data)]
      /* ---- Enter your callback code here ----- */
   part_tag=UF_PART_ask_display_part();  
   if (part_tag != 0)
       uc1601("成功获得标识",1);
   UF_MODL_ask_exps_of_part( part_tag,[$number_of_exps,&exps)]  
   for(i=0;i<number_of_exps;i++)  
   {  
   UF_MODL_ask_exp_tag_string(exps,[$string)]  
    UF_free(string);  
   if (data.value.integer != 0)
       uc1601("aa赋值成功",1);
   }  
   UF_free(exps);  
  sprintf(aa,"%f",data.value.integer);  
  strcpy(string1,"p0=");  
  strcat(string1,aa);  
  UF_MODL_edit_exp(string1);
   UF_MODL_update();  
  
      UF_terminate ();
  
     /* Callback acknowledged, do not terminate dialog                 */
     /* A return value of UF_UI_CB_EXIT_DIALOG will not be accepted    */
     /* for this callback type.  You must respond to your apply button.*/
     return (UF_UI_CB_CONTINUE_DIALOG);  
  
}
请大虾赐教!!!!!!
作者: leechongqing    时间: 2004-10-11 15:22
同情,我也是刚开始农这个,也看不懂
作者: tari    时间: 2004-10-11 16:56
好像你没有去掉预编译语句
作者: mizzle    时间: 2004-10-11 17:02
//#ifdef MENUBAR_COMMENTED_OUT  
extern void ufusr (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;  
}  
//#endif /*MENUBAR_COMMENTED_OUT*/  
  
对注释掉上面两句
作者: huashanyjj    时间: 2004-10-11 21:43
你下面这几句,似乎没有什么用处。
    UF_MODL_ask_exps_of_part( part_tag,[$number_of_exps,&exps)]  
    for(i=0;i<number_of_exps;i++)  
    {  
      UF_MODL_ask_exp_tag_string(exps,[$string)]  
      UF_free(string);  
      if (data.value.integer != 0)  
        uc1601("aa赋值成功",1);  
    }  
    UF_free(exps);  
如果你已经知道表达式名称p0,直接使用:
    sprintf(aa,"%f",data.value.integer);  
    strcpy(string1,"p0=");  
    strcat(string1,aa);  
    UF_MODL_edit_exp(string1);  
    UF_MODL_update();  
应该就可以了。应该保证表达式p0存在。
作者: openi    时间: 2004-10-12 13:43
我先画了一个立方体,有一个表达式是p0的,我把那两行去掉了,还是不行啊。在ug里的模型还是没变??你们哪位高人做过用读对话框的值来改变part模型的表达式。进而模型也跟着变了。给菜鸟点指导!!不胜感激!!!
作者: 深夜摔键盘    时间: 2004-10-12 16:13
-----------------------------
作者: huashanyjj    时间: 2004-10-12 16:24
忘了告诉你啊:
sprintf(aa,"%f",data.value.integer);  
换成
  sprintf(aa,"%d",data.value.integer);  
  
int 要用%d,否则得到的是0.000
或者:
sprintf(aa,"%f",(double)data.value.integer);
作者: 深夜摔键盘    时间: 2004-10-13 09:07
以前也没有用过表达式,现学现卖了。昨晚试着写了个,程序结构不太合理,仅做参考。
基于清华的表达式的教程,添加了一个对话框,在对话框的构造函数里创建了一个长方体,然后对表达式进行改名,将原来的表达式的左值由默认地,改成l,w,h.
譬如:
l=10
w=20
h=30
打开菜单:信息 |表达式 ,在弹出的窗口中,观察一下是否存在这3个表达式
然后修改对话框的值,表达式的右值被程序修改。
确定退出对话框时,更新模型。。
  
估计楼主兄弟是对UISTYLE和C语言字串操作有些陌生。
作者: wflying    时间: 2004-10-13 11:20
按照mizzle 说的方法打开入口,然后将sprintf(aa,"%f",data.value.integer);  
改成 sprintf(aa,"%d",data.value.integer); 应该没有问题了的。或者按照深夜摔键盘兄 说的方法做!!
作者: openi    时间: 2004-10-13 12:23
   感谢楼上的兄弟们!!!仔细一想,确实是你们说的那些问题,讲一个笑话,以示感谢!!
“鼓捣猫呢!”
  
  我老公家是内蒙古农村的,有一对外国老夫妇到这里住了下来。因为村  
里的人无法和他们交流,老夫妇很寂寞,就养了一只猫。一天早上,老夫妇  
正梳理猫毛,一个人从旁边过来,冲着俩人说“鼓捣猫呢”。夫妇俩随即冲  
着来人说:“Good morning.”傍晚时分,二人正在把晾在外边的衣服收起来,  
路过的一个村民冲着他们说:“鼓捣衣服呢!”二人这回反应很快说:“  
Good evening.”私下里老夫妇俩感叹,合着他们这里的人都会说英语呀!
作者: openi    时间: 2004-10-14 10:14
@@@@@@@@@@




欢迎光临 iCAx开思工具箱 (https://t.icax.org/) Powered by Discuz! X3.3