青华模具培训学校

 找回密码
 注册

QQ登录

只需一步,快速开始

青华模具培训学院
楼主: xcb

[分享] 4.如何自动创建一个block.

[复制链接]
发表于 2008-12-29 22:28 | 显示全部楼层
123477559
发表于 2008-12-30 09:13 | 显示全部楼层
这个就用doc里面的example就可以做成功的啊
' N. l! U. G. I7 Y
4 b2 y8 U$ Q" Y+ k* V以下是里面的代码:. @" g6 G& o+ i: s6 z8 `
The following example illustrates the sequence and the use of UF_UI_lock_ug_access, plus various other UF_UI functions.
2 n9 ^3 h) w( X& _- g#include <Xm/XmAll.h>#include <uf.h>#include <uf_ui.h>#include <uf_ui_xt.h>/*  Local Function Declaration */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_lock_cb( Widget w, XtPointer button_state,                            XtPointer client_data);static UF_UI_change_state_fn_t lock_change_state(int new_state);static int initialize_uf( void );static void call_end_dialog_xt ( XtPointer call_data,                                 XtIntervalId *id );static void call_end_dialog ( void );static void clean_up( void );static void create_custom_dialog(Position x, Position y,                                 Widget parent);/*  Local variables used within this file */static Widget custom_dialog;static Widget pushb1_w;/*  Defines */#define UFUN_INITIALIZED (0)#define UFUN_NOT_INITIALIZED (1)extern voidufusr(char *param, int *retcod, int param_len){  int        rcode;  Widget     nx_parent;  Position   x, y;  /*  Check to see if Ufun is initialized and if it isn't then */  /*  initialize it                                            */  if (initialize_uf() == UFUN_NOT_INITIALIZED)      return;  /* Use NX parent and standard area 1 for primary menu. */  nx_parent = (Widget)UF_UI_get_default_parent();  UF_UI_get_DA2_coords(&x, &y);  create_custom_dialog(x,y,nx_parent);  /*  Instantiate the change state function. This is called  */  /*  whenever NX goes from a lock to an unlock state. This  */  /*  does not mean that this is called whenever a new DA2 is */  /*  brought up.                                            */  rcode = UF_UI_register_change_state_fn(         (UF_UI_change_state_fn_t)lock_change_state,         "locktest_change_state");  if (rcode == UF_UI_FAILURE)    UF_UI_set_status("Could not set a change state function");  XtManageChild (custom_dialog);  UF_terminate();}/*  The function to create the custom dialog */static void create_custom_dialog(Position x, Position y,                                 Widget parent){  int        i;  Arg        args[20];  Widget     form_w;  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, XmNcancelLabelString, canstr);   i++;  XtSetArg(args, XmNhelpLabelString, helpstr);   i++;  XtSetArg(args, XmNokLabelString, okstr);   i++;  XtSetArg(args, XmNx, x+200);   i++;  XtSetArg(args, XmNy, y);   i++;  XtSetArg(args, XmNdefaultPosition, False);   i++;  XtSetArg(args, XmNautoUnmanage, False);  i++;  XtSetArg(args, XmNdeleteResponse, XmDO_NOTHING);  i++;  XtSetArg(args, XmNmarginHeight, 10);  i++;  XtSetArg(args, XmNmarginWidth, 0);  i++;  XtSetArg(args, XmNdialogType, XmDIALOG_WORKING);  i++;  custom_dialog = XmCreateMessageDialog (parent,                                         "Lock Example",                                         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_w = XtVaCreateManagedWidget("grp",                                   xmFormWidgetClass,                                   custom_dialog,                                   NULL);  pushb1_w =  XtVaCreateManagedWidget( "Launch Lock Test",                  xmPushButtonWidgetClass, form_w,                  XmNleftAttachment, XmATTACH_FORM,                  XmNrightAttachment, XmATTACH_FORM,                  XmNtopAttachment, XmATTACH_FORM,                  NULL );  XtAddCallback(pushb1_w,                XmNactivateCallback,                (XtCallbackProc) launch_lock_cb,                NULL);}/*********************************************************    Function:    lock_change_state    Description: Called whenever NX locks and unlocks its menubar.                 This is not quite as evident as it used to be                 since NX's menubar doesn't grey out as much as it                 used to, but the state changes are still the same.    Input:       new_state - this is the new lock state of NX.    Output:      N/A    Return:      N/A***********************************************************/static UF_UI_change_state_fn_t lock_change_state(int new_state){   if (custom_dialog != NULL)   {      if (new_state == UF_UI_LOCK)         XtSetSensitive(pushb1_w, FALSE);      else if (new_state == UF_UI_UNLOCK)         XtSetSensitive(pushb1_w, TRUE);      else if (new_state == UF_UI_ERROR)       /*  Do any necessary clean up. This is called when */       /*  UF_UI_set_force_unlock is called.              */           printf("ERROR clean up time \n");   }   return(NULL);} /* end locktest_change_state *//**************************************************************    Function:    launch_lock_cb    Description: Called whenever the user presses the push                 button in the custom dialog. This                 launches a standard Ufun dialog (Point                 Subfunction). It is demonstrating the use of                 the lock and unlock  mechanism.    Input:       w            - the widget with the action                 button_state - call data                 client_data  - any data the user wants to                                pass on.    Output:      N/A    Return:      N/A***************************************************************/static voidlaunch_lock_cb( Widget w,                XtPointer button_state,                XtPointer client_data){    int    rcode;    int    def[2];    double point1[3];    if (initialize_uf() == UFUN_NOT_INITIALIZED)         return;   /*  Call the lock protocol to provide for the correct */   /*  handshaking.                                     */    rcode = UF_UI_lock_ug_access (UF_UI_FROM_CUSTOM);    if (rcode != UF_UI_LOCK_SET)    {        UF_UI_set_status("Could not lock NX");        return;    }    def[0] = 0;    rcode = uc1616("Create Point", def, 0, point1);    rcode = UF_UI_unlock_ug_access (UF_UI_FROM_CUSTOM);    if (rcode != UF_UI_UNLOCK_SET)        UF_UI_set_status("Could not unlock NX");    UF_terminate();}/********************************************************    Function:    ok_cb    Description: This is called whenever the OK button is                 pressed on the custom dialog.    Input:       w            - the widget with the action                 client_data  - any data the user wants to                                pass on.    Output:      N/A    Return:      N/A*********************************************************/static voidok_cb( Widget w, XtPointer client_data, XtPointer call_data){  /*  Do any processing at this point in time and then do */  /*  the necessary clean up.                            */  clean_up( );}/******************************************************    Function:    back_cb    Description: This is called whenever the Back button                 is pressed on the custom dialog.    Input:       w            - the widget with the action                 client_data  - any data the user wants to                                pass on.    Output:      N/A    Return:      N/A*******************************************************/static voidback_cb( Widget w, XtPointer client_data, XtPointer call_data){  /*  Do any necessary clean up to go back to the previous */  /*  state */  clean_up( );}/*******************************************************    Function:    cancel_cb    Description: This is called whenever the Cancel button                 is pressed on the custom dialog.    Input:       w            - the widget with the action                 client_data  - any data the user wants to                                pass on.    Output:      N/A   Return:      N/A*************************************************************/static voidcancel_cb( Widget w, XtPointer client_data,           XtPointer call_data){  /*  Do any necessary clean up to go back to the previous */  /*  state */  clean_up( );}/**************************************************************    Function:    clean_up    Description: This function does the necessary clean up when                 leaving your custom dialog.    Input:       N/A    Output:      N/A    Return:      N/A***************************************************************/static void clean_up( void ){  int rcode;  if (initialize_uf() == UFUN_NOT_INITIALIZED)      return;  if (UF_UI_ask_lock_status() == UF_UI_LOCK)  {      if (rcode == UF_UI_FAILURE)          UF_UI_set_status("Could not call set the change state to NULL");      rcode = UF_UI_cancel_uf_dialog(UF_UI_FROM_CUSTOM);      if (rcode == UF_UI_FAILURE)      {        /*  Even with a failure you want to destroy your custom */        /*  dialog.                                            */        UF_UI_set_status("Could not Cancel the dialog");        call_end_dialog();      }      else           XtAppAddTimeOut(XtWidgetToApplicationContext(custom_dialog),                 10,                 (XtTimerCallbackProc) call_end_dialog_xt,                 (XtPointer) NULL);   }   else      call_end_dialog();}/*  This is called in the XtAppAddTimeOut function in the cancel *//*  callback.                                                   */static void call_end_dialog_xt ( XtPointer call_data,                                 XtIntervalId *id ){    call_end_dialog();}static void call_end_dialog ( void ){  /*  Destroy your custom dialog */      XtDestroyWidget(custom_dialog);  /*  Be sure to unregister your change state function. By  */  /*  passing in a NULL this unregisters the function.  */      UF_UI_register_change_state_fn( NULL,                                      "locktest_change_state");      UF_terminate();}/*  This is used to initialize User Function */static int initialize_uf( void ){  int        uf_is_initialized;  int        initialize_rcode;  /*  Check to see if Ufun is initialized and if it isn't then */  /*  initialize it                                            */  uf_is_initialized = UF_is_initialized();  if( uf_is_initialized == 0 )  {      initialize_rcode = UF_initialize();      if( initialize_rcode != 0 )      {          printf("Could not initialize User Function\n");          return (UFUN_NOT_INITIALIZED);      }  }  return(UFUN_INITIALIZED);}int ufusr_ask_unload(void){   return ( UF_UNLOAD_SEL_DIALOG );}
3 ~5 L, E+ [5 ~& Q5 H: @file:///F:/doc%20install/UGDOC/html_files/ugopen_doc/uf_ui/uf_ui_grf3.gif
- \6 d% q* q/ ~+ Z# k4 }  r
, J/ A7 M$ g0 V2 RFigure This is the dialog created by this user function program
) P; N$ G* i4 `; K4 D' ^( N
( e: k" _. y, A* _+ K$ ~& _file:///F:/doc%20install/UGDOC/html_files/ugopen_doc/uf_ui/uf_ui_grf2.gif
' B; n4 F5 d$ n3 F; @Figure The custom dialog is unmanaged after the Launch Lock Test button has been pressed and the Point Subfunction dialog appears.
发表于 2008-12-30 09:14 | 显示全部楼层
用这个就可以了
6 U; a3 a' j" A( H% }. c1 ?3 ^! h( W; w

) Q8 O2 O% {' l( v* i' k/******************************************************************************4 ~( t1 [% C) f9 ~* G
             Copyright (c) 1999 Unigraphics Solutions, Inc.
. M: w: d6 K$ |4 ~1 v! g" M                       Unpublished - All Rights Reserved$ T$ ~" I+ C8 j5 V3 S

# n+ F9 f5 f# P- x/ l0 X*******************************************************************************/
4 v$ \3 _5 P6 T0 C1 p2 h3 `& L/*4 ]* N2 s- @" |+ o, `* j

7 u5 P6 P7 _* q' N6 BThe following example creates two blocks. The first block is created
4 {% e8 E: Y2 t* X3 Z* B, oas a new solid and the second block is added (unioned) to the first
6 ?! E* K4 t# _. H5 b7 I8 @block.. M! O0 V0 V- }

8 \3 v. A, |& f" Z*/
! O6 ]  D. i1 z8 M0 ^" V: \# ^3 n3 I0 T+ K2 v8 p
#include <stdio.h>
3 \5 F2 _' z* N8 E) B#include <uf.h>
5 ^2 S! y* X' B# [#include <uf_modl.h>
" O0 j1 q* N8 i5 _, q# }#define UF_CALL(X) (report( __FILE__, __LINE__, #X, (X)))
! N3 F1 f1 B! V! q( lstatic int report( char *file, int line, char *call, int irc)6 x9 V4 ?9 S$ B) V
{
6 x$ r7 X! N) O: i4 m# `    if (irc)& m1 m! b4 z5 k% g; i$ b5 Y5 V
    {
0 ~# M' ]$ O, {! d. K- z        char    messg[133];
$ `5 _& Y, L! O# h& b% W2 S        printf("%s, line %d:  %s\n", file, line, call);
3 b3 N4 L' l6 X# I; M        (UF_get_fail_message(irc, messg)) ?
. p4 \5 w) }8 O2 k- |            printf("    returned a %d\n", irc) :
) G- R) ^% t6 G/ J4 _  l# Z/ \            printf("    returned error %d:  %s\n", irc, messg);
$ e1 R: d1 a' i, a; g1 Z9 c    }
3 n9 e' F  P' k% N7 n    return(irc);. A' o! E1 j3 _
}# R0 T+ S( \* B9 l  r
static void do_ugopen_api(void)% i4 l1 Q2 Z. y( Q$ z' H5 k
{. o  g8 r# T6 h; o& F3 p# U7 `! D
  UF_FEATURE_SIGN sign = UF_NULLSIGN;
! Z9 K) y/ s4 j' b2 d+ D& a* w7 T2 q  UF_FEATURE_SIGN sign1 = UF_POSITIVE;
6 H/ @+ l: D1 c* G) X  double block_orig[3] = {0.0,0.0,0.0};/ Z# F' ]2 J" M& d. a
  double block_orig1[3] = {0.0,0.0,2.5};- D( \2 ?; e- c  I$ P/ H
  char *block_len[3] = {"1","2","3"};% l5 b1 Y# I0 p5 _8 y5 g
  char *block_len1[3] = {"1", "1", "1"};  r2 A8 k+ d7 |6 [1 p+ {0 p
  tag_t blk_obj;
6 w3 d, B6 z* d& h  tag_t blk1_obj;
/ A! w4 T; D. x- a1 m  UF_CALL(UF_MODL_create_block1(sign, block_orig, block_len, &blk_obj));
" Y& E- i. }0 t. w$ V  UF_CALL(UF_MODL_create_block1(sign1, block_orig1, block_len1, &blk1_obj));& B! L( k; @5 U/ x9 v
}
: X& m& r: U- W/*ARGSUSED*/
- y3 s+ D3 `0 h1 Fvoid ufusr(char *param, int *retcode, int paramLen)
1 W0 e* c2 r1 W& g1 W! R{: j; r  D6 E4 l$ x: F5 r4 O' l
  if (!UF_CALL(UF_initialize()))  r4 o* F- f2 u/ w; t% I' ^
  {
( z# c5 K. v' m0 r& v; q0 a6 p      do_ugopen_api();$ n: d' D: W9 h" o0 q
      UF_CALL(UF_terminate());
5 B' Y. J. Q8 s- q( ]2 \  }1 w1 \- M4 J! g7 V
}
% z3 ?/ @8 I; O" Cint ufusr_ask_unload(void); \( v3 U0 a' w1 o5 _1 y
{
! T# V% s% a" ?. S8 [( }, t6 x    return (UF_UNLOAD_IMMEDIATELY);  L7 A6 @4 z- |. k0 @; w% H' k
}
发表于 2008-12-30 20:29 | 显示全部楼层

回复 4楼 xcb 的帖子

哈哈!这个沙发我坐定了!
发表于 2009-1-1 14:57 | 显示全部楼层
学习
发表于 2009-1-9 21:29 | 显示全部楼层
d
发表于 2009-1-11 11:43 | 显示全部楼层
有用吧,侃侃看
发表于 2009-1-12 00:40 | 显示全部楼层
dfdfsdfsdaf
发表于 2009-1-15 13:33 | 显示全部楼层
ding...................................
发表于 2009-1-19 10:43 | 显示全部楼层
thank you very much
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|关于我们|sitemap|小黑屋|Archiver|手机版|UG网-UG技术论坛-青华数控模具培训学校 ( 粤ICP备15108561号 )

GMT+8, 2024-7-6 08:58 , Processed in 0.054978 second(s), 18 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2023 Discuz! Team.

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