tkar 0.63
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/FAQ.rdoc +39 -0
- data/History.txt +175 -0
- data/README.rdoc +153 -0
- data/TODO +67 -0
- data/bin/tkar +104 -0
- data/examples/dial.rb +172 -0
- data/examples/help.gif +0 -0
- data/examples/home.gif +0 -0
- data/examples/mkgrid.rb +58 -0
- data/examples/ps.rb +47 -0
- data/examples/rotate +26 -0
- data/examples/s +3 -0
- data/examples/sample +14 -0
- data/examples/sample.rb +98 -0
- data/examples/sample2 +48 -0
- data/examples/sample3 +57 -0
- data/examples/server.rb +45 -0
- data/examples/tavis.rb +90 -0
- data/install.rb +1015 -0
- data/lib/tkar.rb +109 -0
- data/lib/tkar/argos.rb +214 -0
- data/lib/tkar/canvas.rb +370 -0
- data/lib/tkar/help-window.rb +168 -0
- data/lib/tkar/primitives.rb +376 -0
- data/lib/tkar/stream.rb +284 -0
- data/lib/tkar/timer.rb +174 -0
- data/lib/tkar/tkaroid.rb +95 -0
- data/lib/tkar/version.rb +5 -0
- data/lib/tkar/window.rb +383 -0
- data/protocol.rdoc +539 -0
- data/rakefile +56 -0
- data/tasks/ann.rake +80 -0
- data/tasks/bones.rake +20 -0
- data/tasks/gem.rake +201 -0
- data/tasks/git.rake +40 -0
- data/tasks/notes.rake +27 -0
- data/tasks/post_load.rake +34 -0
- data/tasks/rdoc.rake +51 -0
- data/tasks/rubyforge.rake +55 -0
- data/tasks/setup.rb +292 -0
- data/tasks/spec.rake +54 -0
- data/tasks/svn.rake +47 -0
- data/tasks/test.rake +40 -0
- data/tasks/zentest.rake +36 -0
- metadata +116 -0
data/FAQ.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
= Design Decisions
|
2
|
+
|
3
|
+
== what is tkar trying to be?
|
4
|
+
|
5
|
+
The gnuplot of animation -- a quick and dirty way to get data (stream or file) into a window to see what is happening.
|
6
|
+
|
7
|
+
== why Tk?
|
8
|
+
|
9
|
+
Tcl/Tk is widely available, and the Ruby/Tk interface is a standard part of ruby.
|
10
|
+
|
11
|
+
== why TkCanvas?
|
12
|
+
|
13
|
+
TkCanvas has easy access to relatively high-level 2D vector graphics constructs, such as groups, layers, splines, fonts, icons, zoom, and scroll. Plus, it supports mouse/keyboard operations, dialogs, and so on.
|
14
|
+
|
15
|
+
== why not just write code in Ruby/Tk instead of stream to tkar?
|
16
|
+
|
17
|
+
1. Because you may not want to write your code in the Tk framework. Maybe you're using a different gui, or not a gui at all.
|
18
|
+
|
19
|
+
2. Tkar handles a lot of window / process complications such as drag-and-drop and following (see canvas.rb and window.rb for details).
|
20
|
+
|
21
|
+
3. You can write upstream code in any language, or even just cat from a file.
|
22
|
+
|
23
|
+
4. You can distribute processing: take advantage of 2 cpus, or even 2 hosts across a network.
|
24
|
+
|
25
|
+
== why not HTML 5 canvas, other gui canvas, or Processing?
|
26
|
+
|
27
|
+
Those are heavyweight and add more dependencies (browser, java), and in some cases still lack some of the features of TkCanvas. Tkar is light enough that you can run several instances at once even on resource limited machines.
|
28
|
+
|
29
|
+
== why not opengl?
|
30
|
+
|
31
|
+
It would be more work to get the diagram and user interaction stuff. Anyway, it's overkill.
|
32
|
+
|
33
|
+
== why a special protocol, rather than ruby/tk method calls serialized as text?
|
34
|
+
|
35
|
+
The protocol is not a programming language: there are no variables, functions, loops, etc. There are only macros. It is very simple, which makes it much easier to emit from other languages than ruby, and less prone to programming errors.
|
36
|
+
|
37
|
+
== why is the protocol so ugly?
|
38
|
+
|
39
|
+
It's not meant to be written by hand. You wouldn't write http headers by hand, would you?
|
data/History.txt
ADDED
@@ -0,0 +1,175 @@
|
|
1
|
+
tkar 0.63
|
2
|
+
|
3
|
+
- Use bones and git.
|
4
|
+
|
5
|
+
tkar 0.62
|
6
|
+
|
7
|
+
- Added window_xy command.
|
8
|
+
|
9
|
+
tkar 0.61
|
10
|
+
|
11
|
+
- Permit CR chars after line continuation backslash.
|
12
|
+
|
13
|
+
tkar 0.60
|
14
|
+
|
15
|
+
- Fixed bug in simulink block: turn off verbose if stderr can't go to
|
16
|
+
either console or file, otherwise rubyw dies without exception.
|
17
|
+
|
18
|
+
- Fixed bug in tkar/window.rb: sometimes drag_start is nil during draw_proc.
|
19
|
+
|
20
|
+
- Performance improvement to simulink block: only wait for update response
|
21
|
+
if simulation is more than one step ahead of animation.
|
22
|
+
|
23
|
+
- Added --version, lib/version.rb, and rake targets for maintaining this file.
|
24
|
+
|
25
|
+
tkar 0.59
|
26
|
+
|
27
|
+
- Minor doc updates for the simulink block.
|
28
|
+
|
29
|
+
tkar 0.58
|
30
|
+
|
31
|
+
- In --persist case, always update canvas on input EOF.
|
32
|
+
|
33
|
+
tkar 0.57
|
34
|
+
|
35
|
+
- Added mkgrid.rb.
|
36
|
+
|
37
|
+
tkar 0.56
|
38
|
+
|
39
|
+
- Updated protocol.txt.
|
40
|
+
|
41
|
+
tkar 0.55
|
42
|
+
|
43
|
+
- Added echo command.
|
44
|
+
|
45
|
+
tkar 0.54
|
46
|
+
|
47
|
+
- Added sample/dial.rb.
|
48
|
+
|
49
|
+
- Option shortcuts: "fill" == "fc", and so on.
|
50
|
+
|
51
|
+
tkar 0.53
|
52
|
+
|
53
|
+
- Fixed problem in scale command.
|
54
|
+
|
55
|
+
- Minor cleanup.
|
56
|
+
|
57
|
+
tkar 0.52
|
58
|
+
|
59
|
+
- Added delete_all and scale commands.
|
60
|
+
|
61
|
+
tkar 0.51
|
62
|
+
|
63
|
+
- Added tkar_period parameter to simulink block and tkar.c.
|
64
|
+
|
65
|
+
- Refectored all state in tkar.c into TkarState struct.
|
66
|
+
|
67
|
+
tkar 0.50
|
68
|
+
|
69
|
+
- No more static data in tkar.c.
|
70
|
+
|
71
|
+
tkar 0.49
|
72
|
+
|
73
|
+
- Added more messages in verbose case.
|
74
|
+
|
75
|
+
tkar 0.48
|
76
|
+
|
77
|
+
- Added the "disable" parameter to tkar block.
|
78
|
+
|
79
|
+
tkar 0.47
|
80
|
+
|
81
|
+
- Fixed a dragging bug (clicking and dragging quickly allowed the mouse to
|
82
|
+
move outside the object).
|
83
|
+
|
84
|
+
tkar 0.46
|
85
|
+
|
86
|
+
- simulink/tkar.c now waits for "update"
|
87
|
+
|
88
|
+
- consolidated docs
|
89
|
+
|
90
|
+
tkar 0.45
|
91
|
+
|
92
|
+
- Merged readme files into tkar.txt
|
93
|
+
|
94
|
+
- Added protocol.txt.
|
95
|
+
|
96
|
+
- Fixed bug in hovering over non-filled shape.
|
97
|
+
|
98
|
+
- Fixed bug in layering code.
|
99
|
+
|
100
|
+
tkar 0.44
|
101
|
+
|
102
|
+
- Added tkarlib.mdl and slblocks.m to simulink/.
|
103
|
+
|
104
|
+
- Added verbose param to tkar block
|
105
|
+
|
106
|
+
tkar 0.43
|
107
|
+
|
108
|
+
- Migrated to argos for argv option parsing.
|
109
|
+
|
110
|
+
tkar 0.42
|
111
|
+
|
112
|
+
- Preprocess floats "1234.00" --> "1234" so floats can be used for colors.
|
113
|
+
|
114
|
+
- Accept backslash for line continuation.
|
115
|
+
|
116
|
+
- Load command tries relative path after trying absolute.
|
117
|
+
|
118
|
+
tkar 0.41
|
119
|
+
|
120
|
+
- Added the simulink dir to project.
|
121
|
+
|
122
|
+
tkar 0.40
|
123
|
+
|
124
|
+
- Added the --persist, --radians, and --flip options.
|
125
|
+
|
126
|
+
- Internally, angles are now stored in radians.
|
127
|
+
|
128
|
+
- Added "load" and "exit" commands.
|
129
|
+
|
130
|
+
tkar 0.39
|
131
|
+
|
132
|
+
- Added --stderr option.
|
133
|
+
|
134
|
+
- Impoved docs.
|
135
|
+
|
136
|
+
tkar 0.38
|
137
|
+
|
138
|
+
- Added help button.
|
139
|
+
|
140
|
+
- Improved help window text.
|
141
|
+
|
142
|
+
- Support for MouseWheel on MSWindows.
|
143
|
+
|
144
|
+
tkar 0.37
|
145
|
+
|
146
|
+
- Added help window.
|
147
|
+
|
148
|
+
tkar 0.36
|
149
|
+
|
150
|
+
- Support for TkcImages.
|
151
|
+
|
152
|
+
tkar 0.35
|
153
|
+
|
154
|
+
- improved dragging and scrolling
|
155
|
+
|
156
|
+
tkar 0.34
|
157
|
+
|
158
|
+
- added "bounds" command
|
159
|
+
|
160
|
+
tkar 0.33
|
161
|
+
|
162
|
+
- improvements to drag and drop
|
163
|
+
|
164
|
+
tkar 0.32
|
165
|
+
|
166
|
+
- added movie creation
|
167
|
+
|
168
|
+
tkar 0.31
|
169
|
+
|
170
|
+
- added -c flag
|
171
|
+
|
172
|
+
tkar 0.30
|
173
|
+
|
174
|
+
- First general release.
|
175
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
= <b>tkar</b> -- Tk-based animation process and protocol
|
2
|
+
|
3
|
+
The Tkar animator aims to do one thing well: listen to an incoming stream of data and animate it in a 2D canvas. User interaction is streamed back out.
|
4
|
+
|
5
|
+
To skip to the protocol documentation: {protocol}[link:files/protocol_rdoc.html].
|
6
|
+
|
7
|
+
Also of interest:
|
8
|
+
{FAQ}[link:files/FAQ_rdoc.html].
|
9
|
+
|
10
|
+
== Overview
|
11
|
+
|
12
|
+
Tkar is a Tk/ruby-based animation program using TkCanvas. It accepts command input from stdin or a socket. Commands may define parametrized shapes, place them on the canvas, move and rotate them, change parameters, etc. User interaction events (click, drag, etc) are sent back on the socket or stdout. The canvas can be resized, scrolled, zoomed, and tracked to an object.
|
13
|
+
|
14
|
+
=== Graphical constructs
|
15
|
+
|
16
|
+
* Shapes include: arc, oval, polygon, line, curve, text, bitmap.
|
17
|
+
|
18
|
+
* Parameters include color/pattern of border/area, arrowheads, splines, line dot/dash/width, text font, etc.
|
19
|
+
|
20
|
+
* Can group, layer, rotate, move, and scale objects
|
21
|
+
|
22
|
+
=== Tkar command summary
|
23
|
+
|
24
|
+
_shape_:: define shape in terms of primitives (Tk Canvas objects). Shape may expose any Tk parameters (e.g, colors, lengths of poly sides)
|
25
|
+
|
26
|
+
_add_:: add object to canvas with specified shape, layer, position, rotation, params
|
27
|
+
|
28
|
+
_move_, _rotate_, _scale_, _delete_:: operate on existing object
|
29
|
+
|
30
|
+
_param_:: change param value of an object (e.g. change color or geometry over time; change arrow shape because endpoint moves)
|
31
|
+
|
32
|
+
utilities:: _wait_ (playback with specified frame rate), _update_ (end of time step), set window _params_ (color, size, zoom), _follow_ a specified object, _load_ file (like #include)
|
33
|
+
|
34
|
+
=== User interaction
|
35
|
+
|
36
|
+
* Use keys and mouse to zoom, pan/scroll, select, double-click, drag, drop, etc.
|
37
|
+
|
38
|
+
* User commands are sent back over stream to controlling process
|
39
|
+
e.g. "drag 2 140.0 259.0" and "drop 2 7" ("2" and "7" are object ids)
|
40
|
+
|
41
|
+
|
42
|
+
== Installation
|
43
|
+
|
44
|
+
=== Prerequisites
|
45
|
+
|
46
|
+
==== Tcl/Tk
|
47
|
+
|
48
|
+
For windows: http://www.activestate.com/Products/ActiveTcl/
|
49
|
+
|
50
|
+
For linux, just use your distribution's package tool to install tcl. However, you may need to make sure that ruby and linux both use (or do not use) the pthread library.
|
51
|
+
|
52
|
+
==== Ruby
|
53
|
+
|
54
|
+
For windows: http://rubyforge.org/projects/rubyinstaller/
|
55
|
+
|
56
|
+
For other platforms: http://www.ruby-lang.org
|
57
|
+
|
58
|
+
=== Gem installation
|
59
|
+
|
60
|
+
gem install tkar
|
61
|
+
|
62
|
+
=== Tarball installation
|
63
|
+
|
64
|
+
Alternately, you can download and unpack the source code tar ball from rubyforge:
|
65
|
+
|
66
|
+
wget ...
|
67
|
+
tar xzvf ...
|
68
|
+
cd ...
|
69
|
+
|
70
|
+
You can then either install it as follows:
|
71
|
+
|
72
|
+
ruby install.rb config
|
73
|
+
ruby install.rb setup
|
74
|
+
ruby install.rb install
|
75
|
+
|
76
|
+
or you can run it in place using the <tt>--local-lib</tt> command line option
|
77
|
+
|
78
|
+
bin/tkar --local-lib
|
79
|
+
|
80
|
+
|
81
|
+
== Usage
|
82
|
+
|
83
|
+
=== Command line
|
84
|
+
|
85
|
+
See the -h command line option for details on running tkar.
|
86
|
+
|
87
|
+
Examples are available with the source code--read the comments to see how to run.
|
88
|
+
|
89
|
+
=== Tkar window
|
90
|
+
|
91
|
+
Press the "h" key for on-line help using the tkar window.
|
92
|
+
|
93
|
+
=== Protocol
|
94
|
+
|
95
|
+
See {protocol}[link:files/protocol_rdoc.html] for details on the protocol and writing shape files.
|
96
|
+
|
97
|
+
=== Integrating tkar with other applications
|
98
|
+
|
99
|
+
There are three transport options:
|
100
|
+
|
101
|
+
1. Over pipe
|
102
|
+
|
103
|
+
cat data | tkar
|
104
|
+
|
105
|
+
or
|
106
|
+
|
107
|
+
program | tkar
|
108
|
+
|
109
|
+
- unidirectional (no mouseclick feedback to program)
|
110
|
+
|
111
|
+
- output messages simply go to stdout
|
112
|
+
|
113
|
+
- easy to write filters this way
|
114
|
+
|
115
|
+
<tt></tt>
|
116
|
+
|
117
|
+
2. Over TCP socket
|
118
|
+
|
119
|
+
tkar [<ipaddr>] <port>
|
120
|
+
|
121
|
+
- bidirectional; client can block waiting for update to finish
|
122
|
+
|
123
|
+
- remote host possible, using ipaddr=="localhost"
|
124
|
+
|
125
|
+
- if port is 0, lets OS choose port and prints it to stderr
|
126
|
+
|
127
|
+
- can still write filters by using netcat
|
128
|
+
|
129
|
+
<tt></tt>
|
130
|
+
|
131
|
+
3. Over unix domain socket
|
132
|
+
|
133
|
+
tkar /path/to/socket
|
134
|
+
|
135
|
+
- bidirectional; client can block waiting for update to finish
|
136
|
+
|
137
|
+
- faster than TCP (but unix/linux only)
|
138
|
+
|
139
|
+
Note that tkar has a -c option which tells it to be the socket client rather than the server. This is useful when your main program needs to choose the port, for example.
|
140
|
+
|
141
|
+
== Tkar and Simulink
|
142
|
+
|
143
|
+
Tkar can be interfaced with Simulink. Tkar appears in a simulink model as a block to which can be wired to any number of data sources that drive objects in the animation. You can have several tkar blocks. Think of tkar as the animation version of the built-in plotting block. (Simulink's built-in animation capabilities are bad.)
|
144
|
+
|
145
|
+
An additional set of C files need to be compiled as a Simulink extension. Contact author for details.
|
146
|
+
|
147
|
+
== Author
|
148
|
+
|
149
|
+
Copyright 2006-2009, Joel VanderWerf, mailto:vjoel@users.sourceforge.org
|
150
|
+
|
151
|
+
== License
|
152
|
+
|
153
|
+
Ruby license, see http://www.ruby-lang.org.
|
data/TODO
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
switch for protocol N, if protocol changes
|
2
|
+
|
3
|
+
make most add arguments optional
|
4
|
+
|
5
|
+
height/width broken after user resizes
|
6
|
+
|
7
|
+
set select/hover colors
|
8
|
+
|
9
|
+
set radian/degrees, flip y
|
10
|
+
|
11
|
+
examples for web site
|
12
|
+
screen shots
|
13
|
+
|
14
|
+
new options:
|
15
|
+
|
16
|
+
--flip-shape --radian-shape
|
17
|
+
|
18
|
+
--flip-gobal --radian-global [ replaces --flip and --radians ]
|
19
|
+
|
20
|
+
--flip --radians [ implies both of above, resp. ]
|
21
|
+
|
22
|
+
OR: do these as commands rather than options !!!
|
23
|
+
|
24
|
+
new kind of object: connector
|
25
|
+
|
26
|
+
connects and moves with n normal objects
|
27
|
+
|
28
|
+
defined in terms of a shape which has 3*n params: x,y,r of each part
|
29
|
+
|
30
|
+
also xdelta and ydelta, in each part's local coord sys?
|
31
|
+
|
32
|
+
instantiated by passing ids of n objects, plus any add'l params
|
33
|
+
|
34
|
+
when objects move, connector's params are changed accordingly, reshaping it
|
35
|
+
|
36
|
+
(even when objects dragged in gui)
|
37
|
+
|
38
|
+
when connector is dragged, objects are dragged with it (?)
|
39
|
+
|
40
|
+
a connector with n==1 is a useful special case (control point, port, etc.)
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
constrained drag motion, drop targets (per individual object)
|
45
|
+
|
46
|
+
constrain by ID(s) of object(s) that drag must stay within
|
47
|
+
|
48
|
+
object flags
|
49
|
+
|
50
|
+
draggable, hoverable, etc
|
51
|
+
|
52
|
+
import shapes from .svg, so you can draw them in Dia, etc.
|
53
|
+
|
54
|
+
documentation
|
55
|
+
|
56
|
+
shape vs global coords
|
57
|
+
|
58
|
+
how to write line labels in simulink
|
59
|
+
|
60
|
+
tutorial
|
61
|
+
|
62
|
+
- simplest possible animation
|
63
|
+
|
64
|
+
- more complex shapes
|
65
|
+
|
66
|
+
- more complex motion
|
67
|
+
|
data/bin/tkar
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
local_lib_dir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
|
4
|
+
|
5
|
+
if ARGV.delete("--local-lib")
|
6
|
+
$LOAD_PATH.unshift local_lib_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'tkar/argos'
|
10
|
+
|
11
|
+
optdef = {
|
12
|
+
"b" => true,
|
13
|
+
"c" => true,
|
14
|
+
"h" => true,
|
15
|
+
"help" => true,
|
16
|
+
"v" => true,
|
17
|
+
"persist" => true,
|
18
|
+
"radians" => true,
|
19
|
+
"flip" => true,
|
20
|
+
"stderr" => proc {|arg| arg},
|
21
|
+
"version" => true
|
22
|
+
}
|
23
|
+
|
24
|
+
opts = Argos.parse_options(ARGV, optdef)
|
25
|
+
|
26
|
+
stderr_file = opts["stderr"]
|
27
|
+
if stderr_file
|
28
|
+
begin
|
29
|
+
$stderr = File.open(stderr_file, "w")
|
30
|
+
rescue
|
31
|
+
$stderr.puts "Warning: could not open #{stderr_file} for writing."
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
$0 = "tkar"
|
36
|
+
|
37
|
+
if opts["h"] or opts["help"]
|
38
|
+
puts <<-END
|
39
|
+
|
40
|
+
#{$0} [options] [addr] [port]
|
41
|
+
|
42
|
+
Start a tkar animation process. Its inputs and outputs are one of:
|
43
|
+
|
44
|
+
stdin/stdout: this is the default
|
45
|
+
|
46
|
+
TCP socket: if port is given (addr default is 127.0.0.1)
|
47
|
+
|
48
|
+
UNIX socket: if addr only is given
|
49
|
+
|
50
|
+
Options:
|
51
|
+
|
52
|
+
-b turns on binary protocol mode, otherwise uses ascii
|
53
|
+
|
54
|
+
-c act as client instead of server [socket cases only];
|
55
|
+
attempts to connect to specified address
|
56
|
+
|
57
|
+
-h this help
|
58
|
+
--help
|
59
|
+
|
60
|
+
-v be verbose
|
61
|
+
|
62
|
+
--version print version information and exit
|
63
|
+
|
64
|
+
--local-lib look for tkar lib files at path relative to this
|
65
|
+
program (currently, #{local_lib_dir})
|
66
|
+
|
67
|
+
--persist keep window open after finishing (even in
|
68
|
+
case of errors)
|
69
|
+
|
70
|
+
--radians accept rotation input in radians instead of degrees;
|
71
|
+
doesn't affect coords inside shapes
|
72
|
+
|
73
|
+
--flip flips the global y axis, affecting both input
|
74
|
+
and output; doesn't affect coords inside shapes
|
75
|
+
|
76
|
+
END
|
77
|
+
exit
|
78
|
+
end
|
79
|
+
|
80
|
+
if opts["version"]
|
81
|
+
require 'tkar/version'
|
82
|
+
puts Tkar::Version
|
83
|
+
exit
|
84
|
+
end
|
85
|
+
|
86
|
+
require 'tkar'
|
87
|
+
|
88
|
+
# so io errors kill the whole process instead of just one thread.
|
89
|
+
Thread.abort_on_exception = true
|
90
|
+
|
91
|
+
if defined?(REQUIRE2LIB) # for rubyscript2exe
|
92
|
+
require 'tk/root'
|
93
|
+
require 'tk/frame'
|
94
|
+
require 'tk/bindtag'
|
95
|
+
require 'tk/pack'
|
96
|
+
require 'tk/grid'
|
97
|
+
require 'tk/scrollbar'
|
98
|
+
require 'tk/virtevent'
|
99
|
+
require 'tk/timer'
|
100
|
+
require 'tk/variable'
|
101
|
+
exit
|
102
|
+
end
|
103
|
+
|
104
|
+
Tkar.run(ARGV, opts)
|