Introduction to Tcl/Tk TraNese Christy U.S. Army Research Laboratory.

Slides:



Advertisements
Similar presentations
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Advertisements

Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Tcl and Otcl Tutorial Part I Internet Computing KUT Youn-Hee Han.
Programming Using Tcl/Tk These slides are based upon u several Tcl/Tk text books u material byDr. Ernest J. Friedman-Hill.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Shell Programming Software Tools. Slide 2 Shells l A shell can be used in one of two ways: n A command interpreter, used interactively n A programming.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Writing Tcl Scripts (cont.) Outline –Variable Scoping –Strings –Eval –File/Channel I/O –Processes –System Info –Errors –Reflection/Debugging –Libraries.
Shell Basics CS465 - Unix. Shell Basics Shells provide: –Command interpretation –Multiple commands on a single line –Expansion of wildcard filenames –Redirection.
Programming for Image Processing/Analysis and Visualization using The Visualization Toolkit Week 2: An Introduction to Tcl Xenios Papademetris
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Writing Tcl Scripts Outline Goal Reading Syntax Data Types
Tcl/Tk 2 CS 414, Software Engineering I Mark Ardis Rose-Hulman Institute December 5, 2002.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Innovation Intelligence ® 1 Chapter 1: Introduction to TCL.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Introduction to Shell Script Programming
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
An Introduction to Unix Shell Scripting
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Nael Alian Introduction to PHP
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Tcl/TK Tutorial. 2 Learning Tcl/TK What is Tcl/TK? –An interpreted programming language Build on-the-fly commands, procedures Platform-independent Easy.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Introduction to Perl Yupu Liang cbio at MSKCC
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Shell Advanced Features. Module 8 Shell Advanced Features ♦ Introduction In Linux systems, the shells are often referred to as command line interfaces.
Chapter 2: Introduction to HyperMesh Process Auomation
CS 330 Programming Languages 10 / 02 / 2007 Instructor: Michael Eckmann.
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
9-Nov-97Tri-Ada '971 TASH An Alternative to the Windows API TRI-Ada ‘97 Terry J. Westley
TCL TK. Tcl/Tk C functions can become Tcl commands that are invoked interactively Tk = scriptable, portable user interface –Windows, X (Unix), MacOS,
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Agenda Positional Parameters / Continued... Command Substitution Bourne Shell / Bash Shell / Korn Shell Mathematical Expressions Bourne Shell / Bash Shell.
Scripting with Ruby What is a scripting language? What is Ruby?
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Innovation Intelligence ® 1 Chapter 4: Using TCL to Control the HyperMesh Session.
Dongsoo S. Kim  Tcl: Tool Command Language Interpreted programming (scripting) language Build on-the-fly commands and procedures Embeddable.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
Haskell Basics CSCE 314 Spring CSCE 314 – Programming Studio Using GHC and GHCi Log in to unix.cse.tamu.edu (or some other server) From a shell.
Scripting.
CSC 110 – Intro to Computing - Programming
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
CS 330 Programming Languages 09 / 30 / 2008 Instructor: Michael Eckmann.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
CGS 3066: Web Programming and Design Spring 2016 PHP.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
An Introduction To Tcl Scripting John Ousterhout Sun Microsystems Laboratories Tcl/Tk Tutorial, Part II.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
Department of Computer Engineering
Shell Scripting March 1st, 2004 Class Meeting 7.
Lecture 9 Shell Programming – Command substitution
Introduction to Scripting
TCL/TK Tool Command Language/Tool Kit.
Presentation transcript:

Introduction to Tcl/Tk TraNese Christy U.S. Army Research Laboratory

225 Oct 02BRL-CAD User’s Group Meeting 2002 What is Tcl/Tk? Tool Command Language/ToolKit. Tcl is an embeddable and extensible interpreted language. Tk is a toolkit for building user interfaces. Combined, they provide a programming system for development and use of GUI applications.

325 Oct 02BRL-CAD User’s Group Meeting 2002 Benefits of Tcl/Tk Rapid development Ease of providing applications with a powerful scripting language An excellent “glue language” User convenience Portability

425 Oct 02BRL-CAD User’s Group Meeting 2002 Tcl/Tk-Based GUI for MGED

525 Oct 02BRL-CAD User’s Group Meeting 2002 Tcl Syntax A command is a list of words. First word on the command line is the command name, any additional words are arguments. –command [arg1 … argn] mged> puts “Hello World” Hello World Words can be grouped with double quotes (“ ”) or curly braces ({}). Commands are terminated with a newline or semicolon.

625 Oct 02BRL-CAD User’s Group Meeting 2002 Variables Variable names are case-sensitive. Declarations are not necessary. set varName [value] –Assigns value to the variable varName. mged> set day Friday Friday mged> set day Friday mged> set day 25 25

725 Oct 02BRL-CAD User’s Group Meeting 2002 Lists An ordered set of strings Specified with curly braces mged> set colors {red yellow green blue} red yellow green blue Sometimes created with “list” command mged> set colors [list red yellow green blue] red yellow green blue Can extract elements from the list using the “lindex” command mged> lindex {red yellow green blue} 2 blue

825 Oct 02BRL-CAD User’s Group Meeting 2002 Arrays Uses associative arrays –Strings used to index the array elements mged> set profit(January) mged> set profit(February) mged> set profit(January) 1500

925 Oct 02BRL-CAD User’s Group Meeting 2002 Special Characters Dollar sign $ –Substitutes the value of the variable Square brackets [ ] –Replaces contents with the result of evaluating the command Backslash \ –Allows special characters such as newlines, [, and $ to be inserted without being treated specially Double quotes “ ” –Allows special characters to be processed normally Curly braces {} –Disables special characters Parentheses () –Delimits key values in arrays Hashmark # –At the beginning of a line, signifies a comment to follow

1025 Oct 02BRL-CAD User’s Group Meeting 2002 Special Character Examples mged> set name Elvis Elvis mged> puts “Hello name” Hello name mged> puts “Hello $name” Hello Elvis mged> set len [string length $name] 5 –string length $name returns 5 –len gets the value 5

1125 Oct 02BRL-CAD User’s Group Meeting 2002 Special Character Examples (cont’d) mged> set price mged> puts “Gasoline: \$ $price/gallon” Gasoline: $1.41/gallon mged> puts {Gasoline: \$ $price/gallon} Gasoline: \$ $price/gallon mged> set product 1; #This is a comment 1

1225 Oct 02BRL-CAD User’s Group Meeting 2002 Special Character Conflicts MGED traditional “name globbing” characters conflict with Tcl/Tk usage: –MGED follows Unix shell filename patterns. –Tcl/Tk has different interpretation of * and []. Users can select which interpretation of special characters: –.mgedrc: set MGED variable glob_compat_mode set glob_compat_mode 0 (for Tcl evaluation) set glob_compat_mode 1 (for object name matching) –Menu: File->Preferences->Special Characters

1325 Oct 02BRL-CAD User’s Group Meeting 2002 Special Character Interpretation

1425 Oct 02BRL-CAD User’s Group Meeting 2002 Expressions The expr command is used to evaluate math expressions. mged> expr mged> expr (3 + 2) * 4 20 mged> in ball.s sph [expr 3 + 4] –A sphere is created with a vertex (0,0,0) and a radius of 7.

1525 Oct 02BRL-CAD User’s Group Meeting 2002 Control Flow if {test} {body1} [else {body2}] mged> set temp mged> if {$temp > 75} { puts “It’s hot” } else { puts “It’s moderate” } It’s hot

1625 Oct 02BRL-CAD User’s Group Meeting 2002 Control Flow (cont’d) while {test} {body} mged> set time 3 3 mged> while {$time > 0} { puts “Time is $time” set time [expr $time - 1] } Time is 3 Time is 2 Time is 1

1725 Oct 02BRL-CAD User’s Group Meeting 2002 Control Flow (cont’d) for {init} {test} {reinit} {body} mged> for {set time 3} {$time > 0} {set time [expr $time - 1]} { puts “Time is $time” } Time is 3 Time is 2 Time is 1

1825 Oct 02BRL-CAD User’s Group Meeting 2002 Control Flow (cont’d) foreach varList list {body} mged> foreach fruit {apples pears peaches} { puts “I like $fruit” } I like apples I like pears I like peaches mged> foreach {key val} {sky blue grass green snow white} { puts “The $key is $val” } The sky is blue The grass is green The snow is white

1925 Oct 02BRL-CAD User’s Group Meeting 2002 MGED Commands get obj [attr] –Returns a list of the object’s attributes. If attr is specified, only the value for that attribute is returned. mged> get foo.r comb region yes id 200 los 100 GIFTmater 2 rgb { } mged> get foo.r rgb mged> get foo.s ell V {0 0 0} A {4 0 0} B {0 4 0} C {0 0 4}

2025 Oct 02BRL-CAD User’s Group Meeting 2002 MGED Commands (cont’d) adjust obj attr value [attr value] –Modifies the object’s attribute(s) by adjusting the value of the attribute(s) to the new value(s). ls [-c -r -s] –Without any options, lists every object in the database. –With the c option, lists all nonhidden combinations; r option lists all nonhidden regions; and s option lists all nonhidden primitives.

2125 Oct 02BRL-CAD User’s Group Meeting 2002 MGED Examples Task: Change the color of all regions to blue. mged> foreach region [ls -r] { adjust $region rgb { } } Task: Print all regions with nonzero air codes. mged> foreach reg [ls -r] { if {[get $reg air] != 0} { puts “$reg” }

2225 Oct 02BRL-CAD User’s Group Meeting 2002 MGED Examples (cont’d) Task: Print all objects with the inherit flag set. mged> foreach obj [ls -c] { if {[get $obj inherit] == “yes”} { puts “$obj” }

2325 Oct 02BRL-CAD User’s Group Meeting 2002 Procedures User-defined commands proc procName {args} {body} mged> proc add {x y} { set answer [expr $x + $y] return $answer } mged> add Create new MGED commands Save in.mgedrc

2425 Oct 02BRL-CAD User’s Group Meeting 2002 Procedure Example Procedure that generates a PART that encompasses two specified SPHs proc sph-part {sph1 sph2 newname} { foreach {vx1 vy1 vz1} [lindex [get $sph1 V] 0] {} foreach {vx2 vy2 vz2} [lindex [get $sph2 V] 0] {} foreach {ax1 ay1 az1} [lindex [get $sph1 A] 0] {} foreach {ax2 ay2 az2} [lindex [get $sph2 A] 0] {} set radius1 [expr sqrt($ax1*$ax1 + $ay1*$ay1 + $az1*$az1)] set radius2 [expr sqrt($ax2*$ax2 + $ay2*$ay2 + $az2*$az2)] set hx [expr $vx2-$vx1] set hy [expr $vy2-$vy1] set hz [expr $vz2-$vz1] in $newname part $vx1 $vy1 $vz1 $hx $hy $hz $radius1 $radius2 }

2525 Oct 02BRL-CAD User’s Group Meeting 2002 Procedure Example (cont’d) mged> sph-part s1.s s2.s part.s

2625 Oct 02BRL-CAD User’s Group Meeting 2002 The “source” Command source fileName –Reads and executes the file as a Tcl script. Create the file with a text editor. Reload the file with “source” if changes are made. The proc or the source command can be placed in.mgedrc.

2725 Oct 02BRL-CAD User’s Group Meeting 2002 MGED Defaults Create the default.mgedrc from inside MGED:

2825 Oct 02BRL-CAD User’s Group Meeting 2002 MGED Customization Placed in the file.mgedrc –In local directory or home ############### MGEDRC_HEADER ############### # You can modify the values below. However, if you want # to add new lines, add them above the MGEDRC_HEADER. # Note - it's not a good idea to set the same variables # above the MGEDRC_HEADER that are set below (i.e. the last # value set wins).... # Determines the maximum number of lines of # output displayed in the command window set mged_default(max_text_lines) 1000

2925 Oct 02BRL-CAD User’s Group Meeting 2002 [incr Tcl/Tk] Object-oriented extension to Tcl. Provides support to build large programs. New applications in BRL-CAD are being written in [incr Tcl/Tk].

3025 Oct 02BRL-CAD User’s Group Meeting 2002 Useful References Raines, Paul. Tcl/Tk Pocket Reference. O’Reilly & Associates, Inc., Sebastopol, CA, Ousterhout, John K. Tcl and the Tk Toolkit. Addison -Wesley, Reading, MA, Welch, Brent B. Practical Programming in Tcl and Tk Second Edition. Prentice Hall, Upper Saddle River, NJ, 1997.

3125 Oct 02BRL-CAD User’s Group Meeting 2002 End of Intro to Tcl/Tk