Sei sulla pagina 1di 46

DCL Dialog Control Language: Introduo

Joo Manuel R. S. Tavares

Bibliografia
Material disponvel no AfraLisp.net em http://www.afralisp.net Programao em AutoCAD, Curso Completo

Fernando Lus Ferreira, Joo Santos FCA Sistema de ajuda do AutoCAD

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Introduo
A Dialog Control Language permite criar interfaces grficas (caixas de

dilogo e de mensagens) para aplicaes em AutoLISP/Visual Lisp Cada caixa de dilogo deve ser definida (dialog definition) em ficheiros de definio com a extenso dcl Cada controlo de um dilogo necessita ser definido (tile definition) e referenciado no cdigo lisp pelo seu nome (key) Cada propriedade (property) de um controlo (tile) designada por atributo do dilogo (attribute) Cada mtodo de um controlo designado por expresso de aco (action expression) O Visual Lisp Editor possibilita a previso de um dilogo definido num ficheiro dcl (em Tools, Interface Tools)

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Introduo (cont.)
No ficheiro base.dcl do AutoCAD existem definies e estruturas teis que

podem ser usadas (para usar, incluir @include "base.dcl" no ficheiro respectivo) Na definio dos dilogos (ficheiros dcl):
So usados { } em vez de ( ) Para definir propriedades usa-se o sinal = As linhas de atributos terminam com ; Comentrios so indicados com // ou /* As definies so iniciadas com :

*/

Criao de um dilogo:
Sintaxe: nome : dialog { contedo }

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Introduo (cont.)
Exemplo (ficheiro hello.dcl):

// dado o nome "hello" // caixa de dilogo label = "Primeira Caixa de Dilogo"; // ttulo a aparecer na caixa : text { // incio de zona de texto label = "Hello, world"; // texto a aparecer } // fim da zona de texto : button { // criado um boto OK para terminar key = "terminado"; // o valor da tecla label = "OK"; // o nome da tecla is_default = true; // declara que este o boto por omisso } // fim do boto "ok" }
5 CFAC: DCL - Dialog Control Language: Introduo 2009@Joo Tavares

hello : dialog {

Introduo (cont.)
Exemplo (ficheiro hello.lsp):

(Defun c:hello () (setq dcl_id (load_dialog "hello.dcl")) (if (not (new_dialog "hello" dcl_id)) (exit) ) (start_dialog) dialogo (unload_dialog dcl_id) )
6 CFAC: DCL - Dialog Control Language: Introduo 2009@Joo Tavares

; o file carregado ; verifica se existe o ficheiro ; se no existe sa

; mostrada a caixa de ; retira a recm-criada caixa

Introduo (cont.)
Definio de um controlo (tile):
nome : item1 [ : item2 : item3 ]

{ atributo = valor ; }

Referncia a um controlo predefinido:


: nome {

atributo = valor ;

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Introduo (cont.)
Exemplo (ficheiro hello1.dcl):

hello : dialog { label = "Primeira Caixa de Dilogo"; : text { label = "Hello, world"; } ok_only; }

// dado o nome "hello" // caixa de dilogo // ttulo a aparecer na caixa // incio de zona de texto // texto a aparecer // fim da zona de texto // boto "ok" predefinido

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Introduo (cont.)
Exemplo (ok_cancel.dcl)

ex_cancel : dialog {

// dado o nome "ex_cancel" // caixa de dilogo label = "Exemplo Ok_Cancel"; // ttulo a aparecer na caixa spacer_0; // espaamento ok_cancel; // botes "ok" e "cancel" // predefinidos

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Introduo (cont.)
Exemplo (ficheiro hello1.lsp):

(Defun c:hello () (setq dcl_id (load_dialog "hello1.dcl")) (if (not (new_dialog "hello" dcl_id)) (exit) ) (start_dialog) (unload_dialog dcl_id) )

; o ficheiro carregado ; verifica se existe o ficheiro ; se no existe sa

; mostrada a caixa de dilogo ; retira a recm-criada caixa

10

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Controlos Predefinidos
Exit Buttons e Error Tiles ok_only ok_cancel ok_cancel_help ok_cancel_help_errtile ok_cancel_help_info errtile Predefined Active Tiles button edit_box list_box popup_list radio_button toggle slider image_button
11 CFAC: DCL - Dialog Control Language: Introduo

Decorative e Informative Tiles image text spacer spacer_0 spacer_1 Text Clusters ncatenation paragraph text_part

2009@Joo Tavares

Controlos Predefinidos (cont.)


Tile Clusters boxed_column boxed_radio_column boxed_radio_row boxed_row column dialog radio_column radio_row row

12

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Atributos de Controlos
Globais
alignment fixed_height fixed_width height width Aplicam-se a: All Tiles

Action Tiles

action is_enabled is_tab_stop key mnemonic


Aplicam-se a: button; edit_box; image_button; list_box; popup_list;

radio_button; slider; toggle; radio_column; radio_row

13

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Atributos de Controlos (cont.)


Tile Clusters
children_alignment children_fixed_height children_fixed_width Aplicam-se a: row; column; radio_row; radio_column; boxed_row; boxed_column; boxed_radio_row; boxed_radio_column

Specific Tiles
allow_accept Aplicam-se a: edit_box; image_button; list_box aspect_ration Aplicam-se a: image; image_button big_increment Aplicam-se a: slider
14 CFAC: DCL - Dialog Control Language: Introduo 2009@Joo Tavares

Atributos de Controlos (cont.)


Specific Tiles (cont.)
color Aplicam-se a: image; image_button edit_limit Aplicam-se a: edit_box edit_width Aplicam-se a: edit_box; popup_list fixed_width_font Aplicam-se a: edit_box; popup_list initial_focus Aplicam-se a: dialog is_cancel Aplicam-se a: button
15

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Atributos de Controlos (cont.)


Specific Tiles (cont.)
is_default Aplicam-se a: button label Aplicam-se a: boxed_row; boxed_column; boxed_radio_row; boxed_radio_column; button; dialog; edit_box; list_box; popup_list; radio_button; text; toggle layout Aplicam-se a: slider list Aplicam-se a: list_box; popup_list max_value Aplicam-se a: slider min_value Aplicam-se a: slider
16 CFAC: DCL - Dialog Control Language: Introduo 2009@Joo Tavares

Atributos de Controlos (cont.)


Specific Tiles (cont.)
multiple_select Aplicam-se a: list_box password_char Aplicam-se a: edit_box small_increment Aplicam-se a: slider tabs Aplicam-se a: list_box; popup_list tab_truncate Aplicam-se a: list_box; popup_list value Aplicam-se a: text; todos active tiles (excepto buttons e image_buttons)
17

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Funes AutoLISP para dilogos DCL


(load_dialog ficheiro.dcl)

; carrega file (new_dialog nome dcl_id aco ecr) ; carrega dilogo (start_dialog) ; mostra dilogo (done_dialog saida) ; fecha dilogo e retorna sada (term_dialog) ; fecha todos dilogos abertos (unload_dialog dcl_id) ; descarrega dilogo (action_tile key expresso) ; estabelece aco para tile key (get_attr key atributo) ; obter valor do tile key (string) (get_tile key) ; obter valor do tile key (string) (set_tile key valor) ; atribuir valor para o tile key (string) (mode_tile key modo) ; define modo (0 - activa, 1 - desactiva, 2 destaca, 3 - selecciona contedo, 4 - muda destaque de uma imagem)
2009@Joo Tavares

18

CFAC: DCL - Dialog Control Language: Introduo

Funes AutoLISP para dilogos DCL (cont.)


(start_list key operao indice) ; inicia lista (add_list string)
19

; adiciona string numa lista (end_list) ; termina lista (start_image key) ; inicia criao de imagem (dimx_tile key) ; dimenso de imagem em x (dimy_tile key) ; dimenso de imagem em y (vector_image xini yini xfim yfim cor) ; desenha vector (fill_image xini yini larg alt cor) ; desenha rectngulo (slide_image xini yini larg alt nomeslide) ; inserir slide (end_image) ; termina criao de imagem
2009@Joo Tavares

CFAC: DCL - Dialog Control Language: Introduo

Funes AutoLISP para dilogos DCL (cont.)

20

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Funes AutoLISP para dilogos DCL (cont.)

21

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Funes AutoLISP para dilogos DCL (cont.)

22

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Funes AutoLISP para dilogos DCL (cont.)

23

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Funes AutoLISP para dilogos DCL (cont.)

24

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Funes AutoLISP para dilogos DCL (cont.)

25

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Funes AutoLISP para dilogos DCL (cont.)

26

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL1.DCL


//DCL CODING STARTS HERE test_dcl1 : dialog { label = "Test Dialog No 1"; : text { label = "This is a Test Message"; alignment = centered; } : button { key = "accept"; label = "Close"; is_default = true; fixed_width = true; alignment = centered; } } //DCL CODING ENDS HERE 27

// controlo de texto

// definio de um boto // nome do boto // etiqueta do boto // controlo por defeito // alinhamento

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL1.LSP


; AUTOLISP CODING STARTS HERE (prompt "\nType TEST_DCL1 to run.....") (defun C:TEST_DCL1 () (setq dcl_id (load_dialog "test_dcl1.dcl")) (if (not (new_dialog "test_dcl1" dcl_id)) (exit) ) (action_tile "accept" "(done_dialog)") (start_dialog) (unload_dialog dcl_id) (princ) ) (princ) ; AUTOLISP CODING ENDS HERE ; defun ; if ; action_tile quando carrega no boto, fecha o dilogo ; mostrar dilogo ; descarregar o dilogo da memoria ; load do ficheiro de definio ; carregamento do dilogo em memoria ; indicao no prompt do autocad aps load do programa

28

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: Notas
Cada linha de atributo no ficheiro de definio do dilogo

termina com ; Comentrios indicados com // Sensvel a maisculas e a minsculas Sequncia de utilizao:
Load do ficheiro do dilogo Load da definio do dilogo Executar instruo(es) action_tile Iniciar o dilogo Descarregar o dilogo da memria

29

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL2.DCL


//DCL CODING STARTS HERE test_dcl2 : dialog { label = "Test Dialog No 2"; : edit_box { label = "EnterYour Name :"; mnemonic = "N"; // char sublinhado key = "name"; alignment = centered; edit_limit = 30; // max. 30 chars edit_width = 30; // larg. max. 30 chars } : edit_box { label = "EnterYour Age :"; mnemonic = "A"; key = "age";
CFAC: DCL - Dialog Control Language: Introduo

30

} //DCL CODING ENDS HERE

alignment = centered; edit_limit = 3; // input max. 3 chars edit_width = 3; // largura max. 3 chars value = ""; // valor inicial } : button { key = "accept"; label = "OK"; is_default = true; fixed_width = true; alignment = centered; } : errtile // para mensagem de erro { width = 34; }

2009@Joo Tavares

Exemplo: file TEST_DCL2.LSP


; AUTOLISP CODING STARTS HERE (prompt "\nType TEST_DCL2 to run.....") (defun C:TEST_DCL2 (/ dcl_id) (setq dcl_id (load_dialog "test_dcl2.dcl")) (if (not (new_dialog "test_dcl2" dcl_id)) (exit) ) ; if (set_tile "name" "Enter Name Here") ; define contedo em run-time (mode_tile "name" 2) ; permite override (action_tile "name" "(setq name $value)") ; aps seleco atribui valor varivel name (action_tile "age" "(setq age $value)") ; aps seleco atribui valor varivel age (action_tile "accept" "(val1)") ; aps seleco chama subprograma (start_dialog) ; mostra dilogo (unload_dialog dcl_id) (alert (strcat "Your name is " name ; message box "\nand you are " age " years of age." ) )
CFAC: DCL - Dialog Control Language: Introduo 2009@Joo Tavares

31

Exemplo: file TEST_DCL2.LSP (cont.)


) ; defun ;----------------------(defun val1 () (if (= (get_tile "name") "Enter Name Here") ; receber valor no controlo (progn (set_tile "error" "You must enter a name!") ; por valor no controlo (mode_tile "name" 2) ) ; progn (val2) ; chama subprograma ) ; if ) ; defun ;------------------(defun val2 () (if (< (atoi (get_tile "age")) 1) ; receber valor no controlo (progn (set_tile "error" "Invalid Age - Please Try Again!!") ; por valor no controlo (mode_tile "age" 2) )
CFAC: DCL - Dialog Control Language: Introduo 2009@Joo Tavares

(princ)

32

Exemplo: file TEST_DCL2.LSP (cont.)


) (princ) ) (done_dialog) ; progn ; fecha dilogo ; if ; defun ;AUTOLISP CODING ENDS HERE

33

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL3.DCL


afra : dialog { label = "A" ; : column { : row { : button { label = "OK"; key = "accept"; mnemonic = "O"; alignment = centered; width = 12; is_default = true; // tem de existir um // default } : button { label = "Cancel"; key = "cancel"; mnemonic = "C"; alignment = centered; width = 12;
CFAC: DCL - Dialog Control Language: Introduo

} } : row { : button { label = "Save"; key = "save"; mnemonic = "S"; alignment = centered; width = 12; } : button { label = "Load"; key = "load"; mnemonic = "L"; alignment = centered; width = 12; } }
2009@Joo Tavares

34

Exemplo: file TEST_DCL3.DCL (cont.)


: row { : button { label = "Help..."; key = "help"; mnemonic = "H"; alignment = centered; width = 12; } : button { label = "About..."; key = "About"; mnemonic = "H"; alignment = centered; width = 12; } } }

}
35

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL3.LSP


(prompt "\nType TEST_DCL3 to run.....") (defun C:TEST_DCL3 (/ dcl_id) (setq dcl_id (load_dialog " TEST_DCL3.DCL" ) ) (if (not (new_dialog "afra" dcl_id)) (exit) ) ; if (start_dialog) ; sai do dilogo quando seleccionar o boto OK (unload_dialog dcl_id) (princ) ) ; defun ; AUTOLISP CODING STARTS HERE

36

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL4.DCL


samp : dialog { label = "Structural Holes" ; : row { : boxed_radio_column { label = "Type" ; : radio_button { key = "rb1" ; label = "Bolt Holes &Site" ; value = "1" ; } : radio_button { key = "rb2" ; label = "Bolt Holes Sho&p" ; } : radio_button { key = "rb3" ; label = "Bolt Holes &Hidden" ; }
37 CFAC: DCL - Dialog Control Language: Introduo

//dialog name //give it a label //define row //define radio column //give it a label //define radion button //give it a name //give it a label //switch it on //end definition //define radio button //give it a name //give it a label //end definition //define radio button //give it a name //give it a label //end definition
2009@Joo Tavares

Exemplo: file TEST_DCL4.DCL (cont.)


: radio_button { key = "rb4" ; label = "Bolt Holes &Ctsnk" ; } : radio_button { key = "rb5" ; label = "Bolt Holes &Elevation" ; } : radio_button { key = "rb6" ; label = "Bolt Holes &Slotted" ; } } : boxed_column { label = "&Size"; : popup_list { key = "selections"; value = "5; }
CFAC: DCL - Dialog Control Language: Introduo

//define radio button //give it a name //give it a label //end definition //define radio button //give it a name //give it a label //end definition //define radion button //give it a name //give it a label //end definition //end radio column //define boxed column //give it a label //define popup list //give it a name //initial value
2009@Joo Tavares

38

Exemplo: file TEST_DCL4.DCL (cont.)


} } : edit_box { key = "eb1" ; label = "Slot &Length (O/All Slot)" ; edit_width = 6 ; } : slider { key = "myslider" ; max_value = 100; min_value = 0; value = "50"; } : boxed_row { : toggle { key = "tog1"; label = "Ortho On/Off"; }
39 CFAC: DCL - Dialog Control Language: Introduo

//end boxed column //end row //define edit box //give it a name //give it a label //6 characters only //end edit box //defin slider //give it a name //upper value //lower value //initial value //end slider //*define boxed row //*define toggle //*give it a name //*give it a label

2009@Joo Tavares

Exemplo: file TEST_DCL4.DCL (cont.)


: toggle { key = "tog2"; label = "Snap On/Off"; } } ok_cancel ; : row { : image { key = "im" ; height = 1.0 ; width = 1.0 ; } : paragraph { : text_part { label = "Designed and Created"; } : text_part { label = "by Kenny Ramage"; }
CFAC: DCL - Dialog Control Language: Introduo

40

//*define toggle //*give it a name //*give it a label //*end definition //*end boxed row //predifined OK/Cancel //define row //define image tile //give it a name //and a height //and now a width //end image //define paragraph //define text //give it some text //end text //define more text //some more text //end text
2009@Joo Tavares

Exemplo: file TEST_DCL4.DCL (cont.)


} } } //end paragraph //end row //end dialog

41

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL4.LSP


(defun C:samp () ; define function (setq lngth 50.0) ; preset slot length (setq hole "site") ; preset hole type (setq siz "M20") ; preset hole size (setq NAMES '("M6" "M8" "M10" "M12" "M16" "M20" "M24" "M30) ; define list ) (setq ; setq dcl_id (load_dialog " TEST_DCL4.DCL" ) ) ; load dialog (if (not (new_dialog "samp" dcl_id) ; test for dialog ) ; not (exit) ; exit if no dialog ) ; if (setq w (dimx_tile "im") ; get image tile width h (dimy_tile "im") ; get image tile height ) ; setq
42 CFAC: DCL - Dialog Control Language: Introduo 2009@Joo Tavares

Exemplo: file TEST_DCL4.LSP (cont.)


(start_image "im") (fill_image 0 0 w h 5) (end_image) (start_list "selections") (mapcar 'add_list NAMES) (end_list) (set_tile "eb1" "50") (mode_tile "eb1" 1) (mode_tile "myslider" 1) (setq orth (itoa (getvar "orthomode"))) (set_tile "tog1" orth) (setq sna (itoa (getvar "snapmode"))) (set_tile "tog2" sna) (action_tile "myslider" "(slider_action $value $reason)" )
43

; start the image ; fill it with blue ; end image ; start the list box ; fill the list box ; end list ; put dat into edit box ; disable edit box ; disable slider ; *get orthomode value ; *switch toggle on or off ; *get snap value ; *switch toggle on or off ; if user moves slider ; pass arguments to slider_action

CFAC: DCL - Dialog Control Language: Introduo

2009@Joo Tavares

Exemplo: file TEST_DCL4.LSP (cont.)


(action_tile "eb1" "(ebox_action $value $reason)" ) (defun slider_action (val why) (if (or (= why 2) (= why 1)) (set_tile "eb1" val) ) ) (defun ebox_action (val why) (if (or (= why 2) (= why 1)) (set_tile "myslider" val) ) ) (action_tile "tog1" "(setq orth $value)") (action_tile "tog2" "(setq sna $value)") (action_tile "rb1" "(setq hole \"site\")") (action_tile "rb2" "(setq hole \"shop\")")
44 CFAC: DCL - Dialog Control Language: Introduo

; is user enters slot length ; pass arguments to ebox_action ; define function ; check values ; update edit box ; define function ; check values ; update slider ; *get ortho toggle value ; *get snap toggle value ; store hole type ; store hole type
2009@Joo Tavares

Exemplo: file TEST_DCL4.LSP (cont.)


(action_tile "rb3" "(setq hole \"hid\")") (action_tile "rb4" "(setq hole \"ctsk\")") (action_tile "rb5" "(setq hole \"elev\")") (action_tile "rb6" "(setq hole \"slot\") (mode_tile \"eb1\" 0) (mode_tile \"myslider\" 0) (mode_tile \"eb1\" 2)" ) (action_tile "cancel" "(done_dialog) (setq userclick nil)" ) (action_tile "accept" (strcat "(progn
45 CFAC: DCL - Dialog Control Language: Introduo

; store hole type ; store hole type ; store hole type ; store hole type ; enable edit box ; enable slider ; switch focus to edit box ; if cancel button pressed ; close dialog, set flag ; action_tile ; if O.K. pressed ; string 'em together

2009@Joo Tavares

Exemplo: file TEST_DCL4.LSP (cont.)


(setq SIZ (atof (get_tile \"selections\")))" "(setq lngth (atof (get_tile \"eb1\")))" "(setvar \"orthomode\" (atoi orth))" "(setvar \"snapmode\" (atoi sna))" " (done_dialog)(setq userclickT))" ) ; get list selection ; get slot length ; *ortho on/off ; *snap on/off ; close dialog, set flag ; strcat ; action tile ; start dialog ; unload ; check O.K. was selected ; convert to integer ; get the size ; progn ; if userclick ; defun C:samp
2009@Joo Tavares

) (start_dialog) (unload_dialog dcl_id) (if userclick (progn (setq SIZ (fix SIZ)) (setq SIZ (nth SIZ NAMES)) ) ) (princ)

46

) (princ)

CFAC: DCL - Dialog Control Language: Introduo

Potrebbero piacerti anche