DCL – Dialog Control Language:
Introdução
João Manuel R. S. Tavares
Bibliografia
 Material disponível no AfraLisp.net em http://www.afralisp.net
 Programação em AutoCAD, Curso Completo
Fernando Luís Ferreira, João Santos
FCA
 Sistema de ajuda do AutoCAD
2
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Introdução
 A Dialog Control Language permite criar interfaces gráficas (caixas de





3
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)
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Introdução (cont.)
 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
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Introdução (cont.)
 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 texto
label = "Hello, world";
// texto a aparecer
}
// fim da zona de texto
: button {
// é criado um botão OK para terminar
key = "terminado";
// o valor da tecla
label = "OK";
// o nome da tecla
is_default = true;
// declara que este é o botão por omissão
}
// fim do botão "ok"
}
5
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Introdução (cont.)
 Exemplo (ficheiro hello.lsp):
(Defun c:hello ()
(setq dcl_id (load_dialog "hello.dcl"))
(if (not (new_dialog "hello" dcl_id))
(exit)
)
; o file é carregado
; verifica se existe o ficheiro
; se não existe saí
(start_dialog)
dialogo
(unload_dialog dcl_id)
; é mostrada a caixa de
; retira a recém-criada caixa
)
6
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Introdução (cont.)
 Definição de um controlo (tile):
 nome : item1 [ : item2 : item3 …]
{ atributo = valor ; … }
 Referência a um controlo predefinido:
 : nome {
}
7
atributo = valor ;
…
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Introdução (cont.)
 Exemplo (ficheiro hello1.dcl):
hello : dialog {
label = "Primeira Caixa de Diálogo";
: text {
label = "Hello, world";
}
ok_only;
}
8
CFAC: DCL - Dialog Control Language: Introdução
// é dado o nome "hello" à
// caixa de diálogo
// título a aparecer na caixa
// início de zona de texto
// texto a aparecer
// fim da zona de texto
// botão "ok" predefinido
2009@João Tavares
Introdução (cont.)
 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
}
9
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Introdução (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 não existe saí
; é mostrada a caixa de diálogo
; retira a recém-criada caixa
)
10
CFAC: DCL - Dialog Control Language: Introdução
2009@João 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: Introdução
 Decorative e Informative Tiles
 image
 text
 spacer
 spacer_0
 spacer_1
 Text Clusters
 ncatenation
 paragraph
 text_part
2009@João 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: Introdução
2009@João 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: Introdução
2009@João 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: Introdução
2009@João 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: Introdução
2009@João 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: Introdução
2009@João 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: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL
 (load_dialog ficheiro.dcl)










18
; 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)
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
 (start_list key operação indice) ; inicia lista
 (add_list string)








19
; 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
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
20
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
21
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
22
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
23
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
24
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
25
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Funções AutoLISP para diálogos DCL (cont.)
26
CFAC: DCL - Dialog Control Language: Introdução
2009@João 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
// definição de um botão
// nome do botão
// etiqueta do botão
// controlo por defeito
// alinhamento
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Exemplo: file TEST_DCL1.LSP
; 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
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Exemplo: Notas
 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
29
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Exemplo: file TEST_DCL2.DCL
30
//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: Introdução
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;
}
}
//DCL CODING ENDS HERE
2009@João Tavares
Exemplo: file TEST_DCL2.LSP
31
; 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."
)
)
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Exemplo: file TEST_DCL2.LSP (cont.)
(princ)
32
)
; 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: Introdução
2009@João Tavares
Exemplo: file TEST_DCL2.LSP (cont.)
)
(done_dialog)
)
(princ)
33
; progn
; fecha diálogo
; if
; defun
;AUTOLISP CODING ENDS HERE
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Exemplo: file TEST_DCL3.DCL
34
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: Introdução
}
}
: row {
: button {
label = "Save";
key = "save";
mnemonic = "S";
alignment = centered;
width = 12;
}
: button {
label = "Load";
key = "load";
mnemonic = "L";
alignment = centered;
width = 12;
}
}
2009@João Tavares
Exemplo: file TEST_DCL3.DCL (cont.)
}
35
: row {
: button {
label = "Help...";
key = "help";
mnemonic = "H";
alignment = centered;
width = 12;
}
: button {
label = "About...";
key = "About";
mnemonic = "H";
alignment = centered;
width = 12;
}
}
}
CFAC: DCL - Dialog Control Language: Introdução
2009@João Tavares
Exemplo: file TEST_DCL3.LSP
; AUTOLISP CODING STARTS HERE
(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 diálogo quando seleccionar o botão OK
(unload_dialog dcl_id)
(princ)
)
; defun
36
CFAC: DCL - Dialog Control Language: Introdução
2009@João 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: Introdução
//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@João Tavares
Exemplo: file TEST_DCL4.DCL (cont.)
38
: 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: Introdução
//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@João Tavares
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: Introdução
//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@João Tavares
Exemplo: file TEST_DCL4.DCL (cont.)
40
: 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: Introdução
//*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@João Tavares
Exemplo: file TEST_DCL4.DCL (cont.)
}
}
}
41
CFAC: DCL - Dialog Control Language: Introdução
//end paragraph
//end row
//end dialog
2009@João 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: Introdução
2009@João 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
CFAC: DCL - Dialog Control Language: Introdução
; 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
2009@João 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: Introdução
; 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@João 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: Introdução
; 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@João 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))"
)
)
(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: Introdução
; 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@João Tavares
Download

Introdução ao AutoLISP