Manual Surpac SCL & TCL
Manual Surpac SCL & TCL
Manual Surpac SCL & TCL
Manual SURPAC
SCL & TCL
Setembro de 2005
ndice
1
Manual SURPAC
1 SCL
1.1
1.2
1.3
2
2
4
1 SCL
1.1 SCL Viso Geral
A SURPAC Command Language (SCL) substitui a antiga Macro Language
que era includa nos produtos da SURPAC Software International
previamente na verso 4.0.
SCL baseada na Tool Command Language (TCL) e inclui um nmero de
extenses para torn-la especialmente compatvel s exigncias dos
usurios de produtos da SSI.
The following links will be useful in learning and using TCL and the
SCL extensions to TCL:
1.
2.
3.
4.
5.
6.
TCL Syntax
A tutorial on TCL & SCL
SCL extensions to TCL
Conversion guide from Macros to SCL
Frequently Asked Questions about SCL
Complete TCL reference manual
Manual SURPAC
SCL ir substituir a velha SURPAC macro language command futuramente.
SCL fundamentalmente uma extenso linguagem script TCL e
consequentemente ir fornecer aos usurios SURPAC o poder desenvolver
scripts em TCL especficos para o SURPAC.
Quais extenses da SCL estaro disponveis?
SCL ir suportar todas as funcionalidades atualmente disponveis na
velha macro command language do SURPAC tanto implicitamente pelos
comandos TCL sublinhados our por extenses SCL especficas. O Playback
os scripts de ambas SCL e macro command language sero suportados,
mas ser possvel gravar macros apenas na nova SCL. Usurios sero
encorajados a migrar suas macros existentes para a nova linguagem assim
eles se beneficiaro da nova funcionalidade.
O que TK?
Tk um Toolkit (kit de ferramentas) TCL que fornece uma interface
com o X Windows e interfaces toolkit Microsoft Windows (dependendo da
plataforma naturalmente). Referncia http://www.scriptics.com para maiores
informaes.
O TK toolkit ser suportado no SURPAC Vision?
O Tk Toolkit no incluso na SCL. Mesmo assim qualquer
desenvolvimento de scripts necessitando da capacidade GUI (Graphical User
Interface) ir usar o mdulo SURPAC Graphical User Interface Desing
Objects (Guido).
Ter uma ferramenta debugadora disponvel?
O TCL ProDebugger ser suportado, porm o TCLPro no estar
includo. O TCL ProDebugger e outras solues TCL comerciais podem ser
adquiridas do Scriptics WWW site. O TCLPro debugger foi testado com SCL e
foi provado ser um dae (dispositivo automtico de entrada) valioso em
eliminar erros de scripts complexos.
O que TCLPro e isto ser includo na distribuio do SURPAC ?
O TCLPro no ser includo na distribuio do SURPAC Vision neste
estgio. TCLPro um ambiente de desenvolvimento fornece ferramentas
integradas tais como debugador, compilador, checador de script, extenses
e interpretadores implementados.
Manual SURPAC
A velha macro command language ser suportada?
Ser suportado rodar a velha SURPAC macro command language,
mas ser possvel apenas gravar macros na nova SCL.
SCL/TCL Equivalente
Retorno de valores de
comandos SCL
Detalhes de implementao
Todo comando de extenso SCL
retorna um valor para indicar o status
de concluso do comando. O status
de concluso pode ser atribudo a
qualquer varivel usando o comando
set.
Exemplos
if {[SclRangeExpand range
"1,10,1"] == $SCL_OK} {
puts "Range expanded
OK"
} else {
puts "Range expansion
failed range =
$SCL_UNDEFINED_HANDLE"
}
unset range
Manual SURPAC
# Tudo que
procedido do # um
comentrio.
puts "Comentrio ao
final da linha de
comentrio"; #
Comentrios so comumente
encontrados com o caractere # no
incio de uma nova linha.
Comentrios podem ser includos
no final de um comando usando o
caractere ; para terminar um
comando.
Veja o exemplo.
\
for {set i 0} \
Como ultimo caractere na linha o \
{i < 10} \
serve como um caractere de
{incr i} \
continuao de linha para permitir
{puts "i = $i"}
comandos em linhas mltiplas como
um dae (dispositivo automtico de
entrada) como formatao do script.
Manual SURPAC
Variveis
Variveis
nomeDaVarivel,
nomeDaVarivel,
@(nomeDaVarivel) $nomeDaVarivel
set i 0
puts $i
set names(1) "John Smith"
set names(2) "Mary Smith"
puts "names1=$names(1),
names2=$names(2)"
set name(first) "John" set name(last)
"Smith" puts "First
name=$name(first), Last
name=$name(last)"
Os valores de variveis so
obtidos prefixando o nome da
varivel pela operao substituta
de varivel, $.
Nome de variveis, so case
sensitive (identificador de
maiscula e minscula).
@assign
set
set varivel 5
set varivel "to this value"
unset
unset varivel
Manual SURPAC
@function
SclFunction nome_daFuno
parmetros_daFuno
Descrio do comando.
O commando SCLFunction
usado para executar funes no
software que so normalmente
acessadas escolhendo um item do
menu, por exemplo, CREATE
DTM ou RECALL FILE.
Manual SURPAC
@form
No h equivalente em TCL.
@macro
package
pkg_mkIndex
proc
Manual SURPAC
set y [expr $y + 2]
}
set a 1
set b 2
set status [externproc a
b]
puts "a is now $a, b is
now $b"
a is now 2, b is now 3
Procedure Example
proc sum_proc {a b} {
return [expr $a + $b]
}
proc magnitude {num} {
if {$num > 0} {
return $num
}
set num [expr $num *
(-1)]
return $num
}
set num1 12
set num2 14
set sum [sum_proc $num1
$num2]
puts "The sum is $sum"
puts "The magnitude of 3
is [magnitude 3]"
puts "The magnitude of -2
is [magnitude -2]"
Output:
The sum is 26
The magnitude of 3 is 3
The magnitude of -2 is 2
@pause
SclPause perodo
Comando de extenso.
SclPause 5
puts
Manual SURPAC
Comando de extenso.
return
return 0
return $var
Manual SURPAC
$guido_object
SclGetGuidoValue
"location" location
$guido_object
SclGetGuidoValue "id" id
$guido_object
SclGetGuidoValue
"breaklines" breaklines
}
# Clean up - this
destroys the Guido object
unset guido_object
}
The Guido user interface script inputs.tcl
GuidoForm inputs {
-default_buttons
-label "User Interface
Example"
-layout BoxLayout
Y_AXIS
-tip "Help that is
displayed with the
pointer over the form"
GuidoPanel panel1 {
-border etched true
-label "User inputs"
-layout
CentreLineLayout
GuidoFileBrowserField
location {
-display_length 26
-file_mask *.dtm
-link id
-label Location
-max_length 252
-tip "select the
file to be processed"
}
GuidoField id {
-display_length 16
-format real_8
-label "ID number"
-max_length 16
}
GuidoCheckBox
breaklines {
-default true
-font_style bold
-label "Breaklines
"
-selected_value Y
11
Manual SURPAC
-unselected_value N
-tip "Tick the
checkbox to use
breaklines"
}
}
}
@while
@endwhile
while
set x 0
while {$x<10} {
puts "x is $x"
incr x
}
SclRangeExpand handle
range_expression
Comando de extenso.
set status
[SclRangeExpand handle
"1,16,2"]
if {$handle ==
SCL_UNDEFINED_HANDLE} {
puts "Undefined range
handle"
} else {
# Loop through the
range
set count
[ SclRangeGetCount
$handle ]
for { set i 0 } { $i
< $count } { incr i } {
set status
[ SclRangeGet $handle $i
value ]
if {$status ==
$SCL_OK} {
# Do some
processing with $value
} else {
puts "Error
getting range value"
break
}
12
Manual SURPAC
}
# destroy the range
object by unsetting the
handle variable
unset handle
}
@goto
@label
N/A
No h equivalente em TCL.
Prticas de Programao estruturada
while, for, if, switch, etc, so
necessrias para lidar com
execues condicionais do cdigo
para scripts TCL/SCL.
@if
@elseif
@else
@endif
if {expr} {
} elseif {expr} {
} else {
}
switch
@isset
info exists
set temp 95
if {$temp < 80} {
puts "It's a little
chilly."
} else {
puts "Warm enough for
me."
}
set num_legs 4
switch $num_legs {
2 {puts "It could be a
human."}
4 {puts "It could be a
cow."}
6 {puts "It could be an
ant."}
8 {puts "It could be a
spider."}
default {puts "It could
be anything."}
}
13
Manual SURPAC
@(0), @(1), etc.
came
slow_motion="N"
macro_name="b.tcl"
arg1="This input
via arg1"
arg2="This input
via arg2"
arg3="This input
via arg3"
arg4="This input
via arg4"
arg5="This input
via arg5"
arg6="This input
via arg6"
arg7="This input
via arg7"
arg8="This input
via arg8"
arg9="This input
via arg9"
arg10="This input
via arg10"
came
came
came
came
}]
Llength para pegar o nmero de The script sample below exists in the
argumentos de uma lista
file b.tcl. It shows how the optional
Lindex para pegar um item da lista arguments are passed to the argv list
foreach para interagir com cada variable and how each value can be
obtained.
elemento da lista
for {set i 0} {$i <
[llength $argv]} {incr i}
14
Manual SURPAC
{
puts "argument
$i=[lindex $argv $i]"
}
1.3.1.3
Variable length
argument list example
proc testproc {arg1 arg2
args} {
puts "arg1=$arg1"
puts "arg2=$arg2"
set numargs [llength
$args]
if {numargs > 0} {
puts "$numargs
optional arguments to the
procedure"
set count 1
foreach optarg $args
{
puts "Optional
argument #$1=$optarg"
incr count
}
} else {
puts "No optional
arguments to the
procedure"
}
}
gui_digitise
15
Manual SURPAC
{
gui_rect_center_corn SclDragRectCentreCorner
Extension command.
set status
16
Manual SURPAC
er
"prompt text" x1 y1 z1 x2 y2 z2
gui_drag_rect_center
_corner
[SclDragRectCenterCorner
"prompt text" x1 y1 z1 x2 y2 z2]
Extension command.
set status
[SclDragRectCornerCorner
"prompt text" x1 y1 z1 x2 y2 z2]
SclDragLine $prompt x1 y1 z1
x2 y2 z2
Extension command.
Gui_drag_string
SclDragString string_handle
Extension commands.
Manual SURPAC
Gui_drag_segment
Gui_drag_point
SclDragSegment
segment_handle $prompt
delx dely delz
SclDragPoint point_handle
$prompt delx dely delz
Gui_drag_string_Con SclDragStringConstrained
Extension commands.
strained
string_handle $prompt
Gui_drag_segment_ $constraint delx dely delz
Prompt the user to select and drag
Constrained
Gui_drag_point_Cons SclDragSegmentConstrained a string, segment or point from its
current location to a new location
trained
segment_handle $prompt
$constraint delx dely delz
SclDragPointConstrained
point_handle $prompt
$constraint delx dely delz
set string
[SclDragStringConstrained
"prompt text" $constraint delx dely
delz]
set segment
Manual SURPAC
Y and Z.
XYZ = 3 degrees of freedom
XY = 2 degrees of freedom and
movement in the XY plane only,
etc.
File_access
file exists
open
eof
gets
read
puts
eof
close
close $file
19
Manual SURPAC
expr
20