?? tclsyntax.html
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Synopsis of Tcl syntax</title>
</head>
<body BGCOLOR="#E0FFE0" TEXT="#000000" LINK = "#0080C0" VLINK = "#004060" ALINK = "#FF0000" >
<center>
<table>
<tr>
<td>
<a href="qmg2_0_home.html"><img src=logo1.jpg alt="QMG logo"></a></td>
<td>
<h1>
A brief synopsis of Tcl syntax
</h1>
</td>
</table>
</center>
Tcl is an interactive scripting language used to control
QMG. Tcl is partnered with Tk, a set of functions for
creating windows and GUI's. QMG 2.0 uses Tcl/Tk version 8.0.
Tcl/Tk is a free software product originally written
by J. Ousterhout and currently written and maintained
by <a href="http://www.scriptics.com">Scriptics, Inc.</a>
<p>
The user of Tcl enters commands after the prompt sign
<strong>%</strong> on the console.
The result of each command is displayed on the console
window. The format of commands is:
<blockquote>
<strong>
<em>
funcname arg1 ... argn
</em>
</strong>
</blockquote>
In other words a command is separated from its arguments by spaces, and
the arguments are separated from each other by spaces. The end
of the argument list is signaled by the end of the line. To continue
a command onto a new line, use a backslash as the last character
of the line.
<p>
Here is an example of a Tcl/Tk command:
<blockquote>
<code>
set a 4
</code>
</blockquote>
This command creates a variable <code>a</code> and sets it to
<strong>4</strong>. This could be either the integer 4
or the string 4.
In Tcl, the user does not declare the types of variables, and
there is no type system visible to the user.
Internally, an object may have a certain type. The type
is always convertible to and from a printable string.
<p>
The name of the
variable (in this case "a") in Tcl can be fairly arbitrary strings,
but you should probably stick to letters, digits, and underscores.
<p>
If an argument itself has a space character in it, then you have
to enclose the argument in quotation marks or curly braces:
<blockquote>
<code>
set a "p 4"
</code>
</blockquote>
or
<blockquote>
<code>
set a {p 4}
</code>
</blockquote>
These commands are completely equivalent. In both cases, the result
is that <code>a</code> is set to either a string with three characters
or a list with two entries (p and 4). It is indistinguishable to the
console user whether <code>a</code> is a 3-character string or a
2-entry list, since Tcl internally converts back and forth as needed.
<p>
Note that, unlike other languages,
quotation marks do not differentiate string-literals
from non-literals.
The two commands <code>set b a</code> and <code>set b "a"</code> have
identical meaning in Tcl/Tk.
<p>
To access the value of a variable, you must precede the name with
a dollar-sign. Thus, after the commands
<blockquote>
<code>
set a 4<br>
set b $a
</code>
</blockquote>
both a and b are assigned the value 4.
The set command has the property
that in addition to setting the variable to the value, it also returns
its value, converted to a string, and prints it on your console.
<p>
In QMG, variables are used to stand for meshes and breps. It is
often not desirable to convert them to string representation
because the string representation can be huge if the mesh or brep
is large. For this reason,
QMG defines a
variant of the "set" command
called <a href="ref.html#gmset"><code>gmset</code></a>
which suppresses the conversion of the variable to a string
and its subsequent display on your console.
<p>
Another example of a command is the <code>expr</code> command that
causes a string to be evaluated as an arithmetic expression, and the
value of that expression is returned. For example if you typed
<blockquote>
<code>
set a 4<br>
expr "$a + 19"
</code>
</blockquote>
then the second line would return 23.
<p>
A second syntactic feature of Tcl/Tk is square-brackets. Square
brackets invoke a function. Thus,
<blockquote>
<code>
set a 4<br>
set b [expr $a+19]
</code>
</blockquote>
will set b to 23.
A final major syntactic feature is curly-braces. Curly braces
have several properties: like quotes, they suppress spaces as
separators. Unlike quotes, they can be nested.
In addition, unlike quotes, they also prevent
square brackets from being evaluated and dollar-sign substitution.
<p>
You need curly braces to denote matrices and vectors to QMG.
Here is an example.
Suppose you want to set <code>t</code> to be a regular triangle,
and t1 to be a skewed version of that triangle with the matrix
[1,1,0;0,1,0] applied to it (this transformation applies a skew
but no translation). The command in QMG
to define a regular polygon is
<a href="ref.html#gmpolygon"><code>gmpolygon</code></a> and to
apply a transformation
<a href="ref.html#gmapply"><code>gmapply</code></a>. Thus,
you would type:
<blockquote>
<code>
gmset t [gmpolygon 3]<br>
gmset t1 [gmapply {{1 1 0} {0 1 0}} $t]
</code>
</blockquote>
Unforunately, the following will not work:
<blockquote>
<code>
gmset t [gmpolygon 3]<br>
set skewamount 1<br>
gmset t1 [gmapply {{1 $skewamount 0} {0 1 0}} $t]
</code>
</blockquote>
The reason this fails is that (as mentioned above) curly braces
prevent dollar-sign substitution, so this
statement would cause the string literal $skewamount to be passed
to the gmapply routine. This will result in an error, because
gmapply will be unable to convert its argument
to a numbers. How do
you get around this problem? You need to use the <code>list</code>
instruction in Tcl:
<blockquote>
<code>
gmset t [gmpolygon 3]<br>
set skewamount 1<br>
gmset t1 [gmapply [list [list 1 $skewamount 0] [list 0 1 0]] $t]
</code>
</blockquote>
At this point you probably should get
a book to learn more! There is also information on the web.
<p>
Tcl include procedure and looping constructs to build
arbitrarily complex programs. In addition, Tk makes it easy to
attach a graphical user interface to Tcl scripts.
QMG uses Tk for several features: the
<a href="ref.html#gmviz"><code>gmviz</code></a> function
will plot a 2D brep or mesh in a window, and the
<a href="meshgen.html">mesh generator</a> optionally displays
a window indicating its progress.
<hr>
<p>
This documentation is written by
<a href="http://www.cs.cornell.edu/home/vavasis/vavasis.html">Stephen A.
Vavasis</a> and is
copyright ©1999 by
<a href="http://www.info.cornell.edu/CUHomePage.html">Cornell
University</a>.
Permission to reproduce this documentation is granted provided this
notice remains attached. There is no warranty of any kind on
this software or its documentation. See the accompanying file
<a href="copyright.html">'copyright'</a>
for a full statement of the copyright.
<p>
<address>
Stephen A. Vavasis, Computer Science Department, Cornell University,
Ithaca, NY 14853, vavasis@cs.cornell.edu
</address>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -