Fluent中創(chuàng)建自定義用戶界面|03界面元素

譯自:Ansys_Fluent_UDF_Manual_2021R2 ?Part2
本章概述了可以添加到GUI中的各種界面元素。
3.1.整數(shù)條目(CX-CREATE-INTEGER-ENTRY)

本節(jié)介紹如何將整數(shù)輸入字段添加到界面。
3.1.1.描述
本節(jié)討論將整數(shù)輸入字段添加到對(duì)話框的功能。整型字段使用cx-create-integer-entry宏創(chuàng)建。整型字段的值可以使用cx-set-integer-entry宏來(lái)設(shè)置,整型字段的值可以使用cx-show-integer-entry宏來(lái)獲取。
3.1.2.用法
本節(jié)介紹各種整數(shù)輸入字段宏中使用的參數(shù)
3.1.2.1. cx-create-integer-entry
(cx-create-integer-entry parent label row column)

注意:行和列屬性是可選的。如果省略了這兩個(gè)屬性中的一個(gè)或兩個(gè),整數(shù)輸入字段將被添加到父屬性的第一行/第一列,并覆蓋該位置中已有的任何內(nèi)容。
3.1.2.2. cx-set-integer-entry
(cx-set-integer-entry intentry value)

3.1.2.3. cx-show-integer-entry
(cx-show-integer-entry intentry

3.1.3.整數(shù)輸入示例
此示例顯示了 cx-create-integer-entry、cx-set-integer-entry 和 cx-show-integer-entry 宏的工作原理。創(chuàng)建整數(shù)輸入字段后,該字段的初始值將通過(guò)語(yǔ)句 (cx-set-integer-entry intField 1) 設(shè)置為 1。接下來(lái),使用另一個(gè) cx-set-integer-entry 語(yǔ)句將該整數(shù)輸入字段的值增加到 2。該語(yǔ)句還嵌套了一個(gè) cx-show-integer-entry 語(yǔ)句,以便獲取整數(shù)中已有的值輸入字段并將其增加 1。
到 cx-show-panel 語(yǔ)句被讀取時(shí),intField 的值現(xiàn)在是 2,所以當(dāng)打開對(duì)話框時(shí)整數(shù)輸入字段中出現(xiàn)數(shù)字 2。單擊是因?yàn)槲覀円呀?jīng)用布爾值替換了 apply-cb 和 update-cb 參數(shù),這通常是函數(shù)調(diào)用。

(define (apply-cb) #t)
(define update-cb #f)
?(define table)
(define intField)
?(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(set! table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(set! intField (cx-create-integer-entry table "Integer Entry Field"))
(cx-set-integer-entry intField 1)
(cx-set-integer-entry intField (+ 1 (cx-show-integer-entry intField)))
(cx-show-panel my-dialog-box)
3.2.實(shí)數(shù)輸入 (cx-create-real-entry)

本節(jié)介紹如何向界面添加實(shí)數(shù)輸入字段。
3.2.1.描述
本節(jié)討論向?qū)υ捒蛱砑訉?shí)數(shù)輸入字段的能力。使用 cx-create-real-entry 宏創(chuàng)建實(shí)數(shù)字段。實(shí)數(shù)字段的值可以使用 cx-set-real-entry 宏設(shè)置,實(shí)數(shù)字段的值可以使用cx-show-real-entry 宏。
3.2.2.用法
本節(jié)解釋了各種實(shí)數(shù)輸入字段宏中使用的參數(shù)
3.2.2.1. cx-create-real-entry
(cx-create-real-entry parent label row column)

3.2.2.2. cx-set-real-entry
(cx-set-real-entry realentry value)

3.2.2.3. cx-show-real-entry
(cx-show-real-entry realentry)

3.2.3.實(shí)數(shù)輸入示例
此示例顯示 cx-create-real-entry、cx-set-real-entry 和 cx-showreal-entry 宏如何工作。創(chuàng)建實(shí)數(shù)輸入字段后,該字段的初始值將通過(guò)語(yǔ)句 (cx-set-real-entry realField 0.7) 設(shè)置為 0.7。接下來(lái),使用另一個(gè) cx-set-real-entry 語(yǔ)句將該整數(shù)輸入字段的值增加到 1.2。該語(yǔ)句還有一個(gè)嵌套在其中的 cx-show-real-entry 語(yǔ)句,以便獲取整數(shù)輸入字段中已有的值并添加 0.5。
到 cx-show-panel 語(yǔ)句被讀取時(shí),realField 的值現(xiàn)在是 1.2,所以當(dāng)對(duì)話框打開時(shí),實(shí)數(shù)輸入字段中出現(xiàn)數(shù)字 1.2。當(dāng)點(diǎn)擊 OK 按鈕時(shí),這個(gè)對(duì)話框不做任何事情被點(diǎn)擊是因?yàn)槲覀円呀?jīng)用布爾值替換了 apply-cb 和 update-cb 參數(shù),這通常是函數(shù)調(diào)用。

(define (apply-cb) #t)
(define update-cb #f)
?(define table)
(define realField)
?(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(set! table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(set! realField (cx-create-real-entry table "Real Entry Field"))
(cx-set-real-entry realField 0.7)
(cx-set-real-entry realField (+ 0.5 (cx-show-real-entry realField)))
(cx-show-panel my-dialog-box)
3.3.文本輸入(cx-create-text-entry)

本節(jié)介紹如何向界面添加文本輸入字段。
3.3.1.描述
本節(jié)討論向?qū)υ捒蛱砑游谋据斎胱侄蔚哪芰ΑN谋据斎胱侄问褂?cx-create-text-entry 宏創(chuàng)建。文本輸入字段的文本可以使用 cx-set-text-entry 宏設(shè)置,并且可以使用 cx-show-text-entry 宏獲得。
3.3.2.用法
3.3.2.1. cx-create-text-entry
(cx-create-text-entry parent label row column)

3.3.2.2. cx-set-text-entry
(cx-set-text-entry text-var value)

3.3.2.3. cx-show-text-entry
(cx-show-text-entry textentry)

3.3.3. 文本輸入示例
這個(gè)例子展示了 cx-set-text-entry 和 cx-show-text-entry 宏是如何工作的。創(chuàng)建文本輸入字段后,該字段的初始值將通過(guò)語(yǔ)句 (cx-set-text-entry txtField "Starting text") 設(shè)置為起始文本。接下來(lái),通過(guò) (set! isString "This is different text") 語(yǔ)句將隨機(jī)字符串 isString 的值設(shè)置為 This is different text。在將 isString 設(shè)置為 This is different text 之后,接下來(lái)通過(guò)使用 cx-show-text-entry 語(yǔ)句將其設(shè)置為文本輸入字段的值。
最后,將文本輸入字段的值設(shè)置為 isString 的值。由于文本輸入字段在對(duì)話框打開時(shí)顯示Starting text,我們知道 cx-show-text-entry 語(yǔ)句起作用,因?yàn)樗鼘?isString 的值更改為Starting text。

(define (apply-cb) #t)
(define update-cb #f)
?(define table)
(define txtField)
(define isString)
?(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(set! table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(set! txtField (cx-create-text-entry table "Text Entry Field"))
(cx-set-text-entry txtField "Starting text")
(set! isString "This is different text")
(set! isString (cx-show-text-entry txtField))
(cx-set-text-entry txtField isString)
?(cx-show-panel my-dialog-box)
3.4.復(fù)選框和單選按鈕 (cx-create-toggle-button)
本節(jié)介紹如何向界面添加復(fù)選框和單選按鈕。
3.4.1.描述
本節(jié)討論向?qū)υ捒蛱砑訌?fù)選框和單選按鈕的能力。復(fù)選框和單選按鈕通常組合在稱為按鈕框的結(jié)構(gòu)中。按鈕框允許復(fù)選框和單選按鈕以單一間隔格式堆疊在彼此的頂部。按鈕框還控制您添加的按鈕是復(fù)選框還是選項(xiàng)按鈕。復(fù)選框和選項(xiàng)按鈕的區(qū)別在于可以同時(shí)選中一個(gè)按鈕框中的多個(gè)復(fù)選框。單選按鈕是互斥的,因此一次只能選擇按鈕框中的一個(gè)選項(xiàng)按鈕。按鈕框是使用 cx-create-button-box 宏創(chuàng)建的。復(fù)選框和單選按鈕是用 cx-create-toggle-button 宏創(chuàng)建的。復(fù)選框或選項(xiàng)按鈕的狀態(tài)可以用 cx-set-toggle-button 宏設(shè)置,并用 cx-show-toggle-button 查詢按鈕宏。
3.4.2.用法
本節(jié)說(shuō)明各種復(fù)選框/選項(xiàng)按鈕宏中使用的參數(shù)。
3.4.2.1. cx-create-button-box
(cx-create-button-box parent label radio-mode)

3.4.2.2. cx-create-toggle-button
(cx-create-toggle-button parent label row column)

3.4.2.3. cx-set-toggle-button
(cx-set-toggle-button togglebutton value)

3.4.2.4. cx-show-toggle-button
(cx-show-toggle-button togglebutton)

3.4.3.復(fù)選框示例
此示例顯示了 cx-create-button-box、cx-create-toggle-button、cx-set-toggle-button 和 cx-show-toggle-button 宏是如何工作的。在 cx-create-buttonbox 行中,radio-mode 參數(shù)設(shè)置為 #f,這表示正在使用復(fù)選框,而不是單選按鈕。一旦創(chuàng)建了兩個(gè)復(fù)選框,checkBox1 的初始值就會(huì)通過(guò)語(yǔ)句 (cx-set-toggle-button checkBox1 #f) 設(shè)置為 #f。接下來(lái),通過(guò) (set! ?isBool ?#t) 語(yǔ)句將隨機(jī)布爾變量 isBool 的值設(shè)置為 #t。在將 isBool 設(shè)置為 #t 之后,接下來(lái)通過(guò)使用 cx-show-toggle-button 語(yǔ)句將其設(shè)置為 checkBox1 的值。
最后,將 checkBox2 的值設(shè)置為 isBool 的值。由于打開對(duì)話框時(shí)并沒(méi)有勾選checkBox2,所以我們知道cx-show-toggle-button語(yǔ)句起作用了,因?yàn)樗裪sBool的值改成了#f。

(define (apply-cb) #t)
(define update-cb #f)
?(define checkBox1)
(define checkBox2)
?(define isBool)
(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(define table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(define buttonBox (cx-create-button-box table "Button Box" 'radio-mode #f))
(set! checkBox1 (cx-create-toggle-button buttonBox "Check Box 1"))
(set! checkBox2 (cx-create-toggle-button buttonBox "Check Box 2"))
(cx-set-toggle-button checkBox1 #f)
(set! isBool #t)
(set! isBool (cx-show-toggle-button checkBox1))
(cx-set-toggle-button checkBox2 isBool)
?(cx-show-panel my-dialog-box)
3.4.4.選項(xiàng)按鈕示例
此示例顯示了 cx-create-button-box、cx-create-toggle-button 和 cx-set-toggle-button 宏的工作原理。在 cx-create-button-box 語(yǔ)句中,radiomode 參數(shù)設(shè)置為 #t,表示正在使用單選按鈕,而不是復(fù)選框。創(chuàng)建所有四個(gè)單選按鈕后,使用 cx-set-toggle-button 宏將 radioButton2 設(shè)置為 #t,這意味著打開對(duì)話框時(shí)將選擇此選項(xiàng)按鈕。由于這些是單選按鈕而不是復(fù)選框,因此這是按鈕框中唯一可以選擇的按鈕。如果您選擇任何其他按鈕,radioButton2 將自動(dòng)取消選擇。

(define (apply-cb) #t)
(define update-cb #f)
(define radioButton1)
(define radioButton2)
(define radioButton3)
(define radioButton4)
?(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(define table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(define buttonBox (cx-create-button-box table "Button Box" 'radio-mode #t))
(set! radioButton1 (cx-create-toggle-button buttonBox "Radio Button 1"))
(set! radioButton2 (cx-create-toggle-button buttonBox "Radio Button 2"))
(set! radioButton3 (cx-create-toggle-button buttonBox "Radio Button 3"))
(set! radioButton4 (cx-create-toggle-button buttonBox "Radio Button 4"))
(cx-set-toggle-button radioButton2 #t)
(cx-show-panel my-dialog-box)
3.5.按鈕 (cx-create-button)

本節(jié)介紹如何向界面添加按鈕。
3.5.1.描述
雖然對(duì)話框帶有標(biāo)準(zhǔn)的“OK”和“Cancel”按鈕,但添加具有與“OK”按鈕不同功能的其他按鈕有時(shí)會(huì)很有用。要構(gòu)建新按鈕,您必須使用 cx-create-button 宏。
3.5.2.用法
(cx-create-button parent label callback row column

3.5.3.按鈕示例
這個(gè)例子展示了如何使用 cx-create-button 宏來(lái)創(chuàng)建一個(gè)新按鈕,以及回調(diào)參數(shù)是如何工作的。在下面的 cx-create-button 語(yǔ)句中,'activate-callback-button-cb 參數(shù)確保每次單擊按鈕時(shí)都會(huì)調(diào)用 button-cb 過(guò)程。 button-cb 函數(shù)是用行 (define (button- cb . args),這就像如何在功能齊全的對(duì)話框中設(shè)置 apply-cb 和 update-cb 功能一樣(請(qǐng)參閱綜合示例 (p. 759))。一旦您使用此行打開 button-cb 過(guò)程然后,您可以編寫代碼以賦予其功能。
在本例中,每次單擊按鈕時(shí),變量 counter 遞增 1,并將按鈕被單擊的次數(shù)輸出到文本輸入字段 txtField。單擊 OK 按鈕時(shí),此對(duì)話框不執(zhí)行任何操作因?yàn)槲覀円呀?jīng)為 apply-cb 和 update-cb 參數(shù)替換了布爾值,這通常是函數(shù)調(diào)用,就像 cx-create-button 行中的 button-cb 參數(shù)一樣。

(define (apply-cb) #t)
(define update-cb #f)
(define table)
(define txtField)
(define counter 0)
(define (button-cb . args)
?(set! counter (+ counter 1))
?(cx-set-text-entry txtField (string-append "Times Clicked: " (number->string counter)))
)
(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(set! table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(set! txtField (cx-create-text-entry table "" 'row 0 'col 0))
(cx-create-button table "Button" 'activate-callback button-cb 'row 1 'col 0)
(cx-show-panel my-dialog-box)
3.6.列表和下拉列表(cx-create-list)&(cx-create-down-list)

本節(jié)介紹如何將列表或下拉列表添加到界面。
3.6.1.描述
本節(jié)討論將列表和下拉列表添加到對(duì)話框的功能。列表是使用cx-create-list宏創(chuàng)建的,下拉列表是使用cx-create-dropdown-list宏創(chuàng)建的。列表和下拉列表在創(chuàng)建后都使用相同的列表項(xiàng)宏??梢允褂胏x-set-List-Items宏設(shè)置列表項(xiàng)??梢允褂胏x-set-list-seltions宏設(shè)置列表選擇,并使用cx-show-list-seltions宏獲取列表選擇。
3.6.2.用法
本節(jié)介紹各種列表和下拉列表宏中使用的參數(shù)。
3.6.2.1. cx-create-list
(cx-create-list parent label visible-lines multiple-selections row
column)

visible-lines,multiple-selections, row 和column是可選的。如果不包括它們,則可見(jiàn)行數(shù)默認(rèn)為10,多選項(xiàng)為#f,這意味著您一次只能選擇一個(gè)列表項(xiàng)。
3.6.2.2. cx-create-drop-down-list
(cx-create-drop-down-list parent label multiple-selections row column)

3.6.2.3. cx-set-list-items
(cx-set-list-items list items)

3.6.2.4. cx-set-list-selections
(cx-set-list-selections list selections)

3.6.2.5. cx-show-list-selections
(cx-show-list-selections list)

3.6.3.列表示例
此示例顯示了 cx-create-list、cx-set-list-items、cx-set-list-selections 和 cx-show-list-selections 宏的工作原理。這兩個(gè)列表都是通過(guò) cx-create-list 語(yǔ)句創(chuàng)建的。第一個(gè)列表一次只允許顯示三個(gè)可見(jiàn)的列表項(xiàng),而第二個(gè)列表一次允許顯示五個(gè)。這是如何設(shè)置大小的示例您的列表通過(guò)visible-lines參數(shù)。
打開對(duì)話框后,第一個(gè)列表將通過(guò) cx-setlist-items 行自動(dòng)加載所有五個(gè)列表項(xiàng),而第二個(gè)列表開始為空。通過(guò)從第一個(gè)列表中選擇一個(gè)或多個(gè)列表項(xiàng),然后單擊 Button,將從列表 1 中選擇的列表項(xiàng)通過(guò) cx-show-list-selections 語(yǔ)句收集并通過(guò) cx-set-list-items 語(yǔ)句添加到列表 2 .添加到列表 2 的列表項(xiàng)也將通過(guò) cx-set-list-selections 語(yǔ)句自動(dòng)選擇。
在這個(gè)例子中額外的按鈕是必要的,因?yàn)樵O(shè)置 OK 按鈕的功能會(huì)導(dǎo)致它在每次點(diǎn)擊時(shí)關(guān)閉對(duì)話框。要查看這個(gè)例子中的按鈕是如何工作的,請(qǐng)參閱按鈕 (cx-create-button)

(define (apply-cb) #t)
(define update-cb #f)
(define table)
(define myList1)
(define myList2)
(define (button-cb . args)
?(cx-set-list-items myList2 (cx-show-list-selections myList1))
?(cx-set-list-selections myList2 (cx-show-list-selections myList1))
)
(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(set! table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(set! myList1 (cx-create-list table "List 1" 'visible-lines 3 'multiple-selections #t 'row 0))
(cx-set-list-items myList1 (list "Item 1" "Item 2" "Item 3" "Item 4" "Item 5"))
(set! myList2 (cx-create-list table "List 2" 'visible-lines 5 'multiple-selections #t 'row 1))
(cx-create-button table "Button" 'activate-callback button-cb 'row 2)
(cx-show-panel my-dialog-box)
3.6.4.下拉列表示例
此示例顯示了 cx-create-drop-down-list、cx-set-list-items、cx-set-list-selections 和 cx-show-list-selections 宏的工作原理。由于列表和下拉列表都使用相同的列表數(shù)據(jù)類型,因此這個(gè)示例與上面的示例非常相似。與下拉列表的主要區(qū)別在于它們不允許進(jìn)行多項(xiàng)選擇。在示例中,兩個(gè)下拉列表都是通過(guò) cx-create-drop-down-list 語(yǔ)句創(chuàng)建的。
打開對(duì)話框后,第一個(gè)下拉列表將通過(guò) cx-set-list-items 行自動(dòng)加載所有五個(gè)列表項(xiàng),而第二個(gè)下拉列表開始為空。通過(guò)從第一個(gè)下拉列表中選擇一個(gè)列表項(xiàng),然后單擊Button,將從下拉列表 1 中選擇的列表項(xiàng)將通過(guò) cx-show-list-selections 語(yǔ)句收集并通過(guò) cx-set-list-items 語(yǔ)句添加到下拉列表 2 。添加到列表 2 的列表項(xiàng)也將通過(guò) cx-set-list-selections 語(yǔ)句自動(dòng)選擇。
在這個(gè)例子中額外的按鈕是必要的,因?yàn)樵O(shè)置 OK 按鈕的功能會(huì)導(dǎo)致它在每次點(diǎn)擊時(shí)關(guān)閉對(duì)話框。要查看這個(gè)例子中的Button是如何工作的,請(qǐng)參閱Button (cx-create-button) 。當(dāng)單擊 OK 按鈕時(shí),此對(duì)話框不執(zhí)行任何操作。

(define (apply-cb) #t)
(define update-cb #f)
?(define table)
(define myDropList1)
(define myDropList2)
?(define (button-cb . args)
?(cx-set-list-items myDropList2 (cx-show-list-selections myDropList1))
)
(define my-dialog-box (cx-create-panel "My Dialog Box" apply-cb update-cb))
(set! table (cx-create-table my-dialog-box "This is an example Dialog Box"))
(set! myDropList1 (cx-create-drop-down-list table "Drop Down List 1" 'row 0))
(cx-set-list-items myDropList1 (list "Item 1" "Item 2" "Item 3" "Item 4" "Item 5"))
(set! myDropList2 (cx-create-drop-down-list table "Drop Down List 2" 'row 1))
(cx-create-button table "Button" 'activate-callback button-cb 'row 2)
(cx-show-panel my-dialog-box)
?