小白學(xué)UG二次開發(fā)_第1頁
小白學(xué)UG二次開發(fā)_第2頁
小白學(xué)UG二次開發(fā)_第3頁
小白學(xué)UG二次開發(fā)_第4頁
小白學(xué)UG二次開發(fā)_第5頁
已閱讀5頁,還剩12頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、小白學(xué)UG二次開發(fā)UGOpen UlStlyer對話框設(shè)計本例參考UG/Open API、MFC和COM開發(fā)實例精解黃勇,本例基本參照書 中內(nèi)容操作,沒有做太大修改,能正常運(yùn)行。第一步,準(zhǔn)備工作在UGII_USER_DIR目錄里新建startup,application兩個文件夾。書中是這 么說的,但是我只用到了 application,startup我沒有用到。怎么設(shè)置環(huán)境變量 我就不說了。第二步,設(shè)計UI.UG開始-所有應(yīng)用模塊-NX 6之前版本UI樣式編輯器 選之前的版 本主要為了降低開發(fā)難度。進(jìn)入UIStyler對話框設(shè)計環(huán)境,新建文件。里面有很多控件,自己試著點(diǎn)點(diǎn)看,探索下。里面有對

2、象瀏覽器,對話框和資 源編輯器,對話框的標(biāo)題和提示如下圖所示,前綴名比較重要,直接關(guān)系到后續(xù)程序生成后 的一些參數(shù)名稱,我們這邊設(shè)置為DIALOG_ACCESS。設(shè)置如圖所示的整數(shù)、實數(shù)、字符串 和按鈕控件,導(dǎo)航按鍵中按鈕樣式選項里選擇的不同項會影響到后續(xù)的回調(diào)函數(shù)。這里選擇 關(guān)閉。整數(shù),實數(shù),字符串修改下標(biāo)簽和標(biāo)識符。這個會在對象瀏覽器里反應(yīng)出來。目前我 還不會修改類型,就放著沒管,如果有知道的,請幫忙解釋下類型。另外,我對回調(diào)函數(shù)的名稱生成機(jī)制也不是很清楚,只是知道Back_cb應(yīng)該是關(guān)閉對話框 時觸發(fā)的回調(diào)函數(shù),action_3_act_cb是按鈕空間觸發(fā)的回調(diào)函數(shù),名字和書上不太一樣,

3、 但是能正常實現(xiàn)功能。完成后,另存為對話框到application,語言選C,對話框名稱為access_dialog, 在目錄下會生成 access_dialog.dlg,access_dialog.h,access_dialog_template.c 三個文件,進(jìn)入文件夾,將最后一個文件改成access_dialog.cpp并保存。按之前帖子的方法建立一個DDL工程,注意目錄放在UGII_USER_DIR下,名稱也 為Dialog_Access.將access_dailog.h和access_dialog.cpp復(fù)制到工程中,添加到頭文件和 源文件中。/*=WARNING! This fil

4、e is overwritten by the UIStyler each time the Styler file is saved.Filename: access_dialog_template.cThis file was generated by the NX User Interface StylerCreated by: DanielVersion: NX 8.5Date: 03-23-2015Time: 19:32This template file is overwritten each time the UlStyler dialog is saved. Any modif

5、ications to this file will be lost.*/*Purpose: This TEMPLATE file contains C source and static structures toguide you in the construction of your NX Open application dialog.The generation of your dialog file (.dlg extension) is the first step towardsdialog construction within Unigraphics. You must n

6、ow create aUGOpenapplication that utilizes this file (.dlg).生成對話框文件dig是第一步,然后要利用dlg文件創(chuàng)建一個UGOpen應(yīng) 用The information in this file provides you with the following:Help on the use of thefunctions, UF_MB_add_styler_actions andUF_STYLER_create_dialog in your NX Open application. These functionswill load an

7、d display your UIStyler dialog in Unigraphics.兩個重要函數(shù)An example of the function, UF_MB_add_styler_actions to associate yourdialog to the menubar is shown below (Search on Example.這個example1和2在哪里?誰知道?An example of a invoking a dialog from a callback utilizingUF_STYLER_create_dialog is also shown below

8、 (Search for Example.An example of a user exit utilizing UF_STYLER_create_dialog is also shown below (Search for Example 3).The callback structure (回調(diào)結(jié)構(gòu)體?不知道是不是這么翻譯的):- DIALOG_ACCESS_cbs -This structure is VERY important if you have callbacks associated with your dialog. It correlates the dialog ite

9、ms in your dialog with the callback functions you must supply. You should not modify this structure since it MUST match up to the information stored in your dialog file (.dlg).用以鏈接對話框項目(item)和回調(diào)函數(shù),其必須和dlg 文件匹配,不要修改。Any attempt to do so will cause an error whileconstructing your dialog. If you wish t

10、o modify the association of your callbacks to your dialog, please reload your dialog file (.dlg) into the UIStyler and regenerate your files.You do not need to be concerned about this structure, simply pass it as an argument to the function, UF_STYLER_create_dialog along with yourdialog file (.dlg).

11、Example 1 displays the actual call you may make for this particular dialog.3. The empty callback functions (stubs) associated with your dialog items have also been placed in this file. These empty functions have been created simply to start you along with your coding requirements. The function name,

12、 argument list and possible return values have alreadybeen provided for you.文件中也已經(jīng)生成了空的回調(diào)函數(shù),后續(xù)要實現(xiàn)啥功能,就要在里面編 程。NOTE: Each callback must be wrappered with the functions UF_initialize()and UF_terminate().*/*/* These include files are needed for the following template code.#include #include #include #in

13、clude #include #include #include #include access_dialog.h/ 這里要用引號/* The following definition defines the number of callback entries */* in the callback structure:*/* UF_STYLER_callback_info_t DIALOG_ACCESS_cbs */#define DIALOG_ACCESS_CB_COUNT ( 3 + 1 ) /* Add 1 for the terminator */*The following st

14、ructure defines the callback entries used by the styler file. This structure MUST be passed into the user function,UF_STYLER_create_dialog along with DIALOG_ACCESS_CB_COUNT.static UF_STYLER_callback_info_t DIALOG_ACCESS_cbsDIALOG_ACCESS_CB_COUNT= UF_STYLER_DIALOG_INDEX, UF_STYLER_APPLY_CB, 0,DIALOG_

15、ACCESS_apply_cb, UF_STYLER_DIALOG_INDEX, UF_STYLER_BACK_CB, 0,DIALOG_ACCESS_back_cb, DIALOG_ACCESS_BUTTON , UF_STYLER_ACTIVATE_CB , 0, DIALOG_ACCESS_action_3_act_cb, UF_STYLER_NULL_OBJECT, UF_STYLER_NO_CB, 0, 0 ;這里我還沒怎么搞明白,先不管。不過應(yīng)該是和后續(xù)回調(diào)函數(shù)調(diào)用時需要用到的 一些結(jié)構(gòu)體。/*UF_MB_styler_actions_t contains 4 fields. Th

16、ese are defined as follows:Field 1Field 2Field 3Field 4the name of your dialog that you wish to display.any client data you wish to pass to your callbacks.your callback structure.flag to inform menubar of your dialog location. This flag MUST match the resource set in your dialog! Do NOT ASSUME that

17、changingthis 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 = access_dialog.dlg, NULL, DIALOG_ACCESS_cbs, UF_MB_STYLER_I S_NOT_TOP , NULL, NULL, NULL, 0 /* This is a NULL terminated list */;這個我也沒

18、特別鬧明白,但是應(yīng)該是菜單欄調(diào)用UI需要采用該結(jié)構(gòu)體數(shù)組。/*MENUBAR HOOKUP HELP Example這里是從菜單欄調(diào)用UI的方法,本例忽略,后續(xù)會去試一試To launch this dialog from a Unigraphics menubar, you must follow the steps below.Add the following lines to your MenuScript file in order to associate a menu bar button with your dialog. In this example, a cascade

19、menu will be created and will be located just before the Help button on the main menubar. The button, ACCESS_DIALOG_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 betwee

20、n 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 directoryMove the

21、 contents between the dashed lines to your Menuscript file.VERSION 120EDIT UG_GATEWAY_MAIN_MENUBARBEFORE UG_HELPCASCADE_BUTTON UISTYLER_DLG_CASCADE_BTNLABEL Dialog LauncherEND_OF_BEFOREMENU UISTYLER_DLG_CASCADE_BTN BUTTON ACCESS_DIALOG_BTN LABEL Display access_dialog dialogACTIONS access_dialog.dlgE

22、ND_OF_MENUIssue 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_OUTThe static structure, actions, will allow you to associate ALL of your dialogs and c

23、allback functions to the menubar at once. For example, if youwish 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

24、have separate shared libraries, each with a ufsta user exit for each individual dialog.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

25、 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 matchinorderto bind your d

26、lg file to your MenuScript button.Copy your UlStyler 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_OUTextern void ufsta (char *param, int *retcode,

27、 int rlen)int error_code;if ( (UF_initialize() != 0)return;if ( (error_code = UF_MB_add_styler_actions ( actions ) ) != 0 ) char fail_message133;UF_get_fail_message(error_code, fail_message);printf ( %sn, fail_message );UF_terminate();return;#endif /*MENUBAR_COMMENTED_OUT*/*DIALOG CREATION FROM A CA

28、LLBACK HELP Example 從其他UI對話框調(diào)用這個UI對話框,本例不涉及If you wish to have this dialog displayed from the callback of another UIStyler dialog, you should:Make sure that the callback of your UIStyler dialog is designated as a dialog building callback.Remove the conditional definitions:#ifdef DISPLAY_FROM_CALLBAC

29、K#endif DISPLAY_FROM_CALLBACKYour callback should issue a call to this function.You should also add the funcitonal prototype to your header file (access_dialog.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

30、or$UGII_VENDOR_DIR/application directory*/#ifdef DISPLAY_FROM_CALLBACKextern int ( int *response ) int error_code = 0;if ( ( error_code = UF_initialize() ) != 0 ) return (0);if ( ( error_code = UF_STYLER_create_dialog ( access_dialog.dlg, DIALOG_ACCESS_cbs, /* Callbacks from dialog */ DIALOG_ACCESS_

31、CB_COUNT, /* number of callbacks*/ NULL, /* This is your client data */ response ) )!= 0 )char fail_message133;/* 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 ( %sn, fail_message );UF_terminate();re

32、turn (error_code);#endif /* DISPLAY_FROM_CALLBACK */*DIALOG CREATION FROM A USER EXIT HELP Example從 USER EXIT 生成這個對話框,調(diào)用 NX Open API, UF_STYLER_create_dialog, To create this dialog from a user exit, you must invoke acall to the NX Open API, UF_STYLER_create_dialog. An example is shown below.All dial

33、og files must be located in這個是講LIALOG文件存放路徑的,之前已經(jīng) 存過了,問題不大。$UGII_USER_DIR/application or$UGII_SITE_DIR/application or$UGII_VENDOR_DIR/application directoryRemove the conditional definitions:這個要求把這兩行注釋掉,或者在之前#define DISPLAY_FROM_USER_EXIT#ifdef DISPLAY_FROM_USER_EXIT#endif DISPLAY_FROM_USER_EXITAdd a

34、 user exit to the function name below, for example, ufusr.Consider how your shared library will be unloaded. Take a lookat the generated function ufusr_ask_unload.*/#define DISPLAY_FROM_USER_EXIT 如果這里定義了 DISPLAY_FROM_USER_EXI T,代碼也會有效。/#ifdef DISPLAY_FROM_USER_EXITextern void ufusr (char *param, int

35、 *retcode, int rlen) 這里的 ufusr 是后續(xù)添進(jìn)去的,int response = 0;int error_code = 0;if ( ( UF_initialize() ) != 0 ) return;if ( ( error_code = UF_STYLER_create_dialog ( access_dialog.dlg, DIALOG_ACCESS_cbs, /* Callbacks from dialog */ DIALOG_ACCESS_CB_COUNT, /* number of callbacks*/ NULL, /* This is your cli

36、ent data */ response ) )!= 0 )char fail_message133;/* 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 ( %sn, fail_message );UF_terminate();return;/*This function specifies how a shared image is unloaded

37、 from memory within Unigraphics. This function gives you the capability to unload an internal NX 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

38、 an unload selection dialog, or when Unigraphics terminates terminates. If you choose UF_UNLOAD_SEL_DIALOG, then you have theoption to unload your image by selecting File-Utilities-Unload Shared Image.NOTE: A program which associates NX Open applications with the menubarMUST NOT use this option sinc

39、e it will UNLOAD your NX Open application image from the menubar.*/extern int ufusr_ask_unload (void)/* unload immediately after application exits*/ return ( UF_UNLOAD_IMMEDIATELY );/*via the unload selection dialog. */*return ( UF_UNLOAD_SEL_DIALOG ); */*when UG terminates.*/*return ( UF_UNLOAD_UG_

40、TERMINATE ); */ 這個函數(shù)先不管/*You have the option of coding the cleanup routine to perform any housekeepingchores 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 */這個也不用管,目

41、前我也不是特明白/*/*/*UlStyler Callback Functions*/-*/*/*Callback Name: DIALOG_ACCESS_apply_cbThis is a callback function associated with an action taken from a * UIStyler object.*Input: dialog_id -*client_data -*The dialog id indicate which dialog this callback is associated with. The dialog id is a dynami

42、c, 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_valueClient 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

43、- This structure pointer contains information specific to the UIStyler Object type that invoked this callback and the callback type.*/int DIALOG_ACCESS_apply_cb ( int dialog_id, void * client_data, UF_STYLER_item_value_type_p_t callback_data)/* Make sure User Function is available. */if ( UF_initial

44、ize() != 0)return ( UF_UI_CB_CONTINUE_DIALOG );/* - Enter your callback code here*/UF_terminate ();這個函數(shù)我不知道怎么出來的,目前也不知道有啥用。/* 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 but

45、ton.*/ return (UF_UI_CB_CONTINUE_DIALOG);/*Callback Name: DIALOG_ACCESS_back_cbThis 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

46、 not be stored. It is strictly for the use in the NX Open API:UF_STYLER_ask_value(s) UF_STYLER_set_valueclientdata - Client data is user defined data associatedwith your dialog. Client data may be bound to your dialog with UF_MB_add_styler_actions or UF_STYLER_create_dialog.callback_data - This stru

47、cture pointer contains information specific to the UIStyler Object type that invoked this callback and the callback type.*/int DIALOG_ACCESS_back_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)r

48、eturn ( UF_UI_CB_CONTINUE_DIALOG );/* - Enter your callback code here*/uc1601(Hello, boy, you will exit this dialog!,1);/這句是自己添加的,當(dāng)關(guān)閉對話框時,會運(yùn)行這個函數(shù)UF_terminate ();*/* Callback acknowledged, terminate dialog.*/*/*/* It is STRONGLY recommended that you exit your/* callback with UF_UI_CB_EXIT_DIALOG in a back call/* back rather than UF_UI_CB_CONTINUE_DIALOG. return (UF_UI_CB_EXIT_DIALOG);/*Callback Name: DIALOG_ACCESS_ac

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論