dcl – dialog control language: introduçãotavares/ensino/cfac/downloads/apontamentos/... ·...
TRANSCRIPT
João Manuel R. S. Tavares
DCL – Dialog Control Language: Introdução
Bibliografia
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
Material disponível no AfraLisp.net em http://www.afralisp.net
Programação em AutoCAD, Curso CompletoFernando Luís Ferreira, João SantosFCA
Sistema de ajuda do AutoCAD
2
Introdução
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
A Dialog Control Language permite criar interfaces gráficas (caixas de diálogo e de mensagens) para aplicações em AutoLISP/Visual Lisp
Cada caixa de diálogo deve ser definida (dialog definition) em ficheiros de definição com a extensão dcl
Cada controlo de um diálogo necessita ser definido (tile definition) e é referenciado no código lisp pelo seu nome (key)
Cada propriedade (property) de um controlo (tile) é designada por atributo do diálogo (attribute)
Cada método de um controlo é designado por expressão de acção (action expression)
O Visual Lisp Editor possibilita a previsão de um diálogo definido num ficheiro dcl (em Tools, Interface Tools)
3
Introdução (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
No ficheiro base.dcl do AutoCAD existem definições e estruturas úteis que podem ser usadas (para usar, incluir @include "base.dcl" no ficheiro respectivo)
Na definição dos diálogos (ficheiros dcl): São usados { } em vez de ( ) Para definir propriedades usa-se o sinal = As linhas de atributos terminam com ; Comentários são indicados com // ou /* */ As definições são iniciadas com :
Criação de um diálogo: Sintaxe: nome : dialog { conteúdo }
4
Introdução (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
Exemplo (ficheiro hello.dcl):hello : dialog { // é dado o nome "hello" à
// caixa de diálogo label = "Primeira Caixa de Diálogo"; // título a aparecer na caixa
: text { // início de zona de textolabel = "Hello, world"; // texto a aparecer
} // fim da zona de texto: button { // é criado um botão OK para terminar
key = "terminado"; // o valor da teclalabel = "OK"; // o nome da teclais_default = true; // declara que este é o botão por omissão
} // fim do botão "ok"}
5
Introdução (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
Exemplo (ficheiro hello.lsp):
(Defun c:hello ()
(setq dcl_id (load_dialog "hello.dcl")) ; o file é carregado
(if (not (new_dialog "hello" dcl_id)) ; verifica se existe o ficheiro
(exit) ; se não existe saí
)
(start_dialog) ; é mostrada a caixa de dialogo
(unload_dialog dcl_id) ; retira a recém-criada caixa
)
6
Introdução (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
Definição de um controlo (tile): nome : item1 [ : item2 : item3 …]
{ atributo = valor ; … }
Referência a um controlo predefinido: : nome {
atributo = valor ;…
}
7
Introdução (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
Exemplo (ficheiro hello1.dcl):
hello : dialog { // é dado o nome "hello" à
// caixa de diálogo
label = "Primeira Caixa de Diálogo"; // título a aparecer na caixa
: text { // início de zona de texto
label = "Hello, world"; // texto a aparecer
} // fim da zona de texto
ok_only; // botão "ok" predefinido
}
8
Introdução (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução9
Exemplo (ok_cancel.dcl)ex_cancel : dialog { // é dado o nome "ex_cancel" à
// caixa de diálogo label = "Exemplo Ok_Cancel"; // título a aparecer na caixa spacer_0; // espaçamento
ok_cancel; // botões "ok" e "cancel"// predefinidos
}
Introdução (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
Exemplo (ficheiro hello1.lsp):
(Defun c:hello ()
(setq dcl_id (load_dialog "hello1.dcl")) ; o ficheiro é carregado
(if (not (new_dialog "hello" dcl_id)) ; verifica se existe o ficheiro
(exit) ; se não existe saí
)
(start_dialog) ; é mostrada a caixa de diálogo
(unload_dialog dcl_id) ; retira a recém-criada caixa
)
10
Controlos Predefinidos
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução11
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
Decorative e Informative Tiles image text spacer spacer_0 spacer_1
Text Clusters ncatenation paragraph text_part
Controlos Predefinidos (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução12
Tile Clusters boxed_column boxed_radio_column boxed_radio_row boxed_row column dialog radio_column radio_row row
Atributos de Controlos
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução13
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
Atributos de Controlos (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução14
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
Atributos de Controlos (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução15
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
Atributos de Controlos (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução16
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
Atributos de Controlos (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução17
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)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução18
(load_dialog ficheiro.dcl) ; carrega file (new_dialog nome dcl_id acção ecrã) ; carrega diálogo (start_dialog) ; mostra diálogo (done_dialog saida) ; fecha diálogo e retorna saída (term_dialog) ; fecha todos diálogos abertos (unload_dialog dcl_id) ; descarrega diálogo (action_tile key expressão) ; estabelece acção 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 conteúdo, 4 - muda destaque de uma imagem)
Funções AutoLISP para diálogos DCL
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução19
(start_list key operação indice) ; inicia lista (add_list string) ; adiciona string numa lista (end_list) ; termina lista (start_image key) ; inicia criação de imagem (dimx_tile key) ; dimensão de imagem em x (dimy_tile key) ; dimensão de imagem em y (vector_image xini yini xfim yfim cor) ; desenha vector (fill_image xini yini larg alt cor) ; desenha rectângulo (slide_image xini yini larg alt nomeslide) ; inserir slide (end_image) ; termina criação de imagem
Funções AutoLISP para diálogos DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução20
Funções AutoLISP para diálogos DCL (cont.)
Funções AutoLISP para diálogos DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução21
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução22
Funções AutoLISP para diálogos DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução23
Funções AutoLISP para diálogos DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução24
Funções AutoLISP para diálogos DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução25
Funções AutoLISP para diálogos DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução26
Funções AutoLISP para diálogos DCL (cont.)
Exemplo: file TEST_DCL1.DCL
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
//DCL CODING STARTS HEREtest_dcl1: dialog{
label = "Test Dialog No 1";: text // controlo de texto{label = "This is a Test Message";alignment = centered;}: button // definição de um botão{key = "accept"; // nome do botãolabel = "Close"; // etiqueta do botãois_default = true; // controlo por defeitofixed_width = true;alignment = centered; // alinhamento}
}//DCL CODING ENDS HERE
27
Exemplo: file TEST_DCL1.LSP
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução
; AUTOLISP CODING STARTS HERE
(prompt "\nType TEST_DCL1 to run.....") ; indicação no prompt do autocad após load do programa
(defun C:TEST_DCL1 ()
(setq dcl_id (load_dialog "test_dcl1.dcl")) ; load do ficheiro de definição
(if (not (new_dialog "test_dcl1" dcl_id)) ; carregamento do diálogo em memoria
(exit)
) ; if
(action_tile "accept" "(done_dialog)") ; action_tile – quando carrega no botão, fecha o diálogo
(start_dialog) ; mostrar diálogo
(unload_dialog dcl_id) ; descarregar o diálogo da memoria
(princ)
) ; defun
(princ)
; AUTOLISP CODING ENDS HERE
28
Exemplo: Notas
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução29
Cada linha de atributo no ficheiro de definição do diálogo termina com ;
Comentários indicados com // Sensível a maiúsculas e a minúsculas Sequência de utilização: Load do ficheiro do diálogo Load da definição do diálogo Executar instrução(ões) action_tile Iniciar o diálogo Descarregar o diálogo da memória
Exemplo: file TEST_DCL2.DCL
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução30
//DCL CODING STARTS HEREtest_dcl2: dialog{
label = "Test Dialog No 2";: edit_box{label = "EnterYour Name :";mnemonic = "N"; // char sublinhadokey = "name";alignment = centered;edit_limit = 30; // max. 30 charsedit_width = 30; // larg. max. 30 chars}: edit_box{label = "EnterYour Age :";mnemonic = "A";key = "age";
alignment = centered;edit_limit = 3; // input max. 3 charsedit_width = 3; // largura max. 3 charsvalue = ""; // valor inicial}: button{key = "accept";label = "OK";is_default = true;fixed_width = true;alignment = centered;}: errtile // para mensagem de erro{width = 34;}
}//DCL CODING ENDS HERE
Exemplo: file TEST_DCL2.LSP
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução31
; 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 conteúdo em run-time(mode_tile "name" 2) ; permite override(action_tile "name" "(setq name $value)") ; após selecção atribui valor à variável name(action_tile "age" "(setq age $value)") ; após selecção atribui valor à variável age(action_tile "accept" "(val1)") ; após selecção chama subprograma(start_dialog) ; mostra diálogo(unload_dialog dcl_id)(alert (strcat "Your name is " name ; message box
"\nand you are " age" years of age.")
)
Exemplo: file TEST_DCL2.LSP (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução32
(princ)) ; 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 - PleaseTry Again!!") ; por valor no controlo(mode_tile "age" 2)
)
Exemplo: file TEST_DCL2.LSP (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução33
; progn(done_dialog) ; fecha diálogo
) ; if) ; defun(princ)
;AUTOLISP CODING ENDS HERE
Exemplo: file TEST_DCL3.DCL
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução34
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;
}}: row {: button {label = "Save";key = "save";mnemonic = "S";alignment = centered;width = 12;}: button {label = "Load";key = "load";mnemonic = "L";alignment = centered;width = 12;}}
Exemplo: file TEST_DCL3.DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução35
: row {: button {label = "Help...";key = "help";mnemonic = "H";alignment = centered;width = 12;}: button {label = "About...";key = "About";mnemonic = "H";alignment = centered;width = 12;}}}
}
Exemplo: file TEST_DCL3.LSP
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução36
; AUTOLISP CODING STARTS HERE(prompt "\nType TEST_DCL3 to run.....")(defun C:TEST_DCL3 (/ dcl_id)(setqdcl_id (load_dialog
" TEST_DCL3.DCL")
)(if (not (new_dialog "afra" dcl_id))(exit)
) ; if(start_dialog) ; sai do diálogo quando seleccionar o botão OK(unload_dialog dcl_id)(princ)
) ; defun
Exemplo: file TEST_DCL4.DCL
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução37
samp : dialog { //dialog namelabel = "Structural Holes" ; //give it a label: row { //define row: boxed_radio_column { //define radio columnlabel = "Type" ; //give it a label: radio_button { //define radion buttonkey = "rb1" ; //give it a namelabel = "Bolt Holes &Site" ; //give it a labelvalue = "1" ; //switch it on} //end definition: radio_button { //define radio buttonkey = "rb2" ; //give it a namelabel = "Bolt Holes Sho&p" ; //give it a label
} //end definition: radio_button { //define radio buttonkey = "rb3" ; //give it a namelabel = "Bolt Holes &Hidden" ; //give it a label} //end definition
Exemplo: file TEST_DCL4.DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução38
: radio_button { //define radio buttonkey = "rb4" ; //give it a namelabel = "Bolt Holes &Ctsnk" ; //give it a label} //end definition: radio_button { //define radio buttonkey = "rb5" ; //give it a namelabel = "Bolt Holes &Elevation" ; //give it a label} //end definition: radio_button { //define radion buttonkey = "rb6" ; //give it a namelabel = "Bolt Holes &Slotted" ; //give it a label} //end definition} //end radio column: boxed_column { //define boxed columnlabel = "&Size"; //give it a label: popup_list { //define popup listkey = "selections"; //give it a namevalue = "5”; //initial value
}
Exemplo: file TEST_DCL4.DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução39
} //end boxed column} //end row: edit_box { //define edit boxkey = "eb1" ; //give it a namelabel = "Slot &Length (O/All Slot)" ; //give it a labeledit_width = 6 ; //6 characters only} //end edit box: slider { //defin sliderkey = "myslider" ; //give it a namemax_value = 100; //upper valuemin_value = 0; //lower valuevalue = "50"; //initial value} //end slider: boxed_row { //*define boxed row: toggle { //*define togglekey = "tog1"; //*give it a namelabel = "Ortho On/Off"; //*give it a label}
Exemplo: file TEST_DCL4.DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução40
: toggle { //*define togglekey = "tog2"; //*give it a namelabel = "Snap On/Off"; //*give it a label} //*end definition} //*end boxed rowok_cancel ; //predifined OK/Cancel: row { //define row: image { //define image tilekey = "im" ; //give it a nameheight = 1.0 ; //and a heightwidth = 1.0 ; //and now a width} //end image: paragraph { //define paragraph: text_part { //define textlabel = "Designed and Created"; //give it some text} //end text: text_part { //define more textlabel = "by Kenny Ramage"; //some more text} //end text
Exemplo: file TEST_DCL4.DCL (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução41
} //end paragraph} //end row} //end dialog
Exemplo: file TEST_DCL4.LSP
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução42
(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 ; setqdcl_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
Exemplo: file TEST_DCL4.LSP (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução43
(start_image "im") ; start the image(fill_image 0 0 w h 5) ; fill it with blue(end_image) ; end image(start_list "selections") ; start the list box(mapcar 'add_list NAMES) ; fill the list box(end_list) ; end list(set_tile "eb1" "50") ; put dat into edit box(mode_tile "eb1" 1) ; disable edit box(mode_tile "myslider" 1) ; disable slider(setq orth (itoa (getvar "orthomode"))) ; *get orthomode value(set_tile "tog1" orth) ; *switch toggle on or off(setq sna (itoa (getvar "snapmode"))) ; *get snap value(set_tile "tog2" sna) ; *switch toggle on or off(action_tile"myslider" ; if user moves slider"(slider_action $value $reason)"
) ; pass arguments to slider_action
Exemplo: file TEST_DCL4.LSP (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução44
(action_tile"eb1" ; is user enters slot length"(ebox_action $value $reason)"
) ; pass arguments to ebox_action(defun slider_action (val why) ; define function(if (or (= why 2) (= why 1)) ; check values(set_tile "eb1" val)
)) ; update edit box(defun ebox_action (val why) ; define function(if (or (= why 2) (= why 1)) ; check values(set_tile "myslider" val)
)) ; update slider(action_tile "tog1" "(setq orth $value)") ; *get ortho toggle value(action_tile "tog2" "(setq sna $value)") ; *get snap toggle value(action_tile "rb1" "(setq hole \"site\")") ; store hole type(action_tile "rb2" "(setq hole \"shop\")") ; store hole type
Exemplo: file TEST_DCL4.LSP (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução45
(action_tile "rb3" "(setq hole \"hid\")") ; store hole type(action_tile "rb4" "(setq hole \"ctsk\")") ; store hole type(action_tile "rb5" "(setq hole \"elev\")") ; store hole type(action_tile"rb6""(setq hole \"slot\") ; store hole type
(mode_tile \"eb1\" 0) ; enable edit box(mode_tile \"myslider\" 0) ; enable slider(mode_tile \"eb1\" 2)"
) ; switch focus to edit box(action_tile"cancel" ; if cancel button pressed"(done_dialog) (setq userclick nil)" ; close dialog, set flag
) ; action_tile(action_tile"accept" ; if O.K. pressed(strcat ; string 'em together"(progn
Exemplo: file TEST_DCL4.LSP (cont.)
2009@João TavaresCFAC: DCL - Dialog Control Language: Introdução46
(setq SIZ (atof (get_tile \"selections\")))" ; get list selection"(setq lngth (atof (get_tile \"eb1\")))" ; get slot length"(setvar \"orthomode\" (atoi orth))" ; *ortho on/off"(setvar \"snapmode\" (atoi sna))" ; *snap on/off" (done_dialog)(setq userclickT))" ; close dialog, set flag
) ; strcat) ; action tile(start_dialog) ; start dialog(unload_dialog dcl_id) ; unload(if userclick ; check O.K. was selected(progn(setq SIZ (fix SIZ)) ; convert to integer(setq SIZ (nth SIZ NAMES)) ; get the size
) ; progn
) ; if userclick(princ)
) ; defun C:samp(princ)