lib/ctioga2/graphics/elements/primitive.rb in ctioga2-0.0 vs lib/ctioga2/graphics/elements/primitive.rb in ctioga2-0.1
- old
+ new
@@ -19,11 +19,11 @@
require 'shellwords'
# This module contains all the classes used by ctioga
module CTioga2
- Version::register_svn_info('$Revision: 101 $', '$Date: 2009-07-21 23:29:59 +0200 (Tue, 21 Jul 2009) $')
+ Version::register_svn_info('$Revision: 151 $', '$Date: 2010-06-19 23:45:20 +0200 (Sat, 19 Jun 2010) $')
module Graphics
module Elements
@@ -52,10 +52,11 @@
@name = name
@compulsory_arguments = comp
@optional_arguments = opts
@funcall = code
end
+
end
# A TiogaPrimitive object describing the current primitive
attr_accessor :primitive
@@ -63,11 +64,14 @@
attr_accessor :arguments
# A hash containing the values of the optional arguments
attr_accessor :options
+ # The last curve's style...
+ attr_accessor :last_curve_style
+
# Creates a new TiogaPrimitiveCall object.
def initialize(primitive, arguments, options)
@primitive = primitive
@arguments = arguments
@options = options
@@ -101,10 +105,11 @@
cmd_args, cmd_opts) do |plotmaker, *rest|
options = rest.pop
call = Elements::
TiogaPrimitiveCall.new(primitive,
rest, options)
+ call.last_curve_style = plotmaker.curve_style_stack.last
plotmaker.root_object.current_plot.
add_element(call)
end
cmd.describe("Draws #{long_name}",
"Directly draws #{long_name} on the current plot", PrimitiveGroup)
@@ -126,20 +131,25 @@
'color' => 'color',
'scale' => 'float',
'angle' => 'float',
'justification' => 'justification',
'alignment' => 'alignment',
+ 'font' => 'latex-font',
}
) do |t, point, string, options|
- # TODO: add a way to specify fonts ???
+ # @todo add a way to specify fonts ???
options ||= {}
+ if options['font']
+ string = options['font'].fontify(string)
+ options.delete('font')
+ end
options['text'] = string
options['at'] = point.to_figure_xy(t)
t.show_text(options)
end
- # TODO: add rendering mode !!
+ # @todo add rendering mode !!
MarkerOptions = {
'color' => 'color',
'stroke_color' => 'color',
'fill_color' => 'color',
'scale' => 'float',
@@ -150,40 +160,44 @@
'alignment' => 'alignment',
}
primitive("marker", "marker", [ 'point', 'marker' ],
MarkerOptions) do |t, point, marker, options|
- # TODO: add a way to specify fonts ???
+ ## \todo add a way to specify fonts ???
options ||= {}
options['marker'] = marker
options['at'] = point.to_figure_xy(t)
t.show_marker(options)
end
primitive("string-marker", "marker", [ 'point', 'text' ],
{'font' => 'pdf-font' }.update(MarkerOptions)
) do |t, point, string, options|
- # TODO: add a way to specify fonts ???
+ ## \todo add a way to specify fonts ???
options ||= {}
options['text'] = string
options['at'] = point.to_figure_xy(t)
t.show_marker(options)
end
- primitive("arrow", "arrow", [ 'point', 'point' ],
- {
- 'color' => 'color',
- 'head_scale' => 'float',
- 'head_marker' => 'marker',
- 'head_color' => 'color',
- 'tail_scale' => 'float',
- 'tail_marker' => 'marker',
- 'tail_color' => 'color',
- 'line_width' => 'float',
- 'line_style' => 'line-style',
- }
- ) do |t, tail,head, options|
+ # options for arrows (and therefore tangents)
+ ArrowOptions = {
+ 'color' => 'color',
+ 'head_scale' => 'float',
+ 'head_marker' => 'marker',
+ 'head_color' => 'color',
+ 'tail_scale' => 'float',
+ 'tail_marker' => 'marker',
+ 'tail_color' => 'color',
+ 'line_width' => 'float',
+ 'line_style' => 'line-style',
+ }
+
+ primitive("arrow", "arrow", [ 'point', 'point' ],
+ ArrowOptions) do |t, tail,head, options|
+ ## \todo a scale or marker_scale option that sets the scale
+ ## of both head and tail
options ||= {}
options['head'] = head.to_figure_xy(t)
options['tail'] = tail.to_figure_xy(t)
t.show_arrow(options)
end
@@ -208,20 +222,22 @@
protected
# Draws the primitive
def real_do(t)
args = @arguments + [@options]
+ ## @todo this is a really ugly hack for passing
+ ## last_curve_style around
+ $last_curve_style = @last_curve_style
primitive.funcall.call(t, *args)
end
DrawingSpecType =
CmdType.new('drawing-spec', :string, <<EOD)
A ctioga 1 --draw specification.
EOD
-
# An emulation of the old ctioga behavior
CmdDraw = Cmd.new('draw', nil, '--draw',
[CmdArg.new('drawing-spec')]) do |plotmaker, spec|
spec =~ /^([^:]+):(.*)/
name = $1
@@ -233,15 +249,15 @@
opts = {}
for a in args
if a =~ /^\s*([^=]+)=(.*)/
opts[$1] = $2
else
- plotmaker.error "Argument found where a option= was expected: #{a}"
+ plotmaker.error { "Argument found where a option= was expected: #{a}" }
end
end
plotmaker.interpreter.run_command(cmd, comp, opts)
else
- plotmaker.error "Unkown graphics primitive: #{name}"
+ plotmaker.error { "Unkown graphics primitive: #{name}" }
end
end
CmdDraw.describe("Draws graphics primitives",
<<EOH, PrimitiveGroup)