class CTioga2::Graphics::Elements::TiogaPrimitiveCall
A TiogaElement
that represents a graphics primitive.
@todo Most of the objects here should rely on getting a BasicStyle object from the options hash and use it to draw. There is no need to make cumbersome and hard to extend hashes.
Constants
- CmdDraw
An emulation of the old ctioga behavior
- DrawingSpecType
- PrimitiveCommands
- PrimitiveGroup
Attributes
An array containing the values of the compulsory arguments
The last curve's style…
A hash containing the values of the optional arguments
A TiogaPrimitive
object describing the current primitive
Public Class Methods
Returns a pair primitive/primitive command for the named primitive, or [ nil, nil ]
# File lib/ctioga2/graphics/elements/primitive.rb, line 225 def self.get_primitive(name) return [@known_primitives[name], PrimitiveCommands[name]] end
Creates a new TiogaPrimitiveCall
object.
# File lib/ctioga2/graphics/elements/primitive.rb, line 81 def initialize(primitive, arguments, options) @primitive = primitive @arguments = arguments @options = options end
Creates a new primitive with the given parameters, and makes it immediately available as a command.
# File lib/ctioga2/graphics/elements/primitive.rb, line 113 def self.primitive(name, long_name, comp, opts = {}, desc = nil, &code) primitive = TiogaPrimitive.new(name, comp, opts, &code) @known_primitives[name] = primitive primitive_class = Class.new(TiogaPrimitiveCall) primitive.primitive_class = primitive_class # Now, create the command cmd_args = comp.map do |x| if x.is_a? CmdArg x else CmdArg.new(x) end end cmd_opts = {} for k,v in opts cmd_opts[k] = if v.is_a? CmdArg v else CmdArg.new(v) end end cmd_opts['clipped'] = CmdArg.new('boolean') cmd_opts['depth'] = CmdArg.new('integer') cmd_opts.merge!(TiogaElement::StyleBaseOptions) cmd = Cmd.new("draw-#{name}",nil,"--draw-#{name}", cmd_args, cmd_opts) do |plotmaker, *rest| options = rest.pop call = primitive_class.new(primitive, rest, options) container = plotmaker.root_object.current_plot call.setup_style(container, options) call.last_curve_style = plotmaker.curve_style_stack.last container.add_element(call) end if ! desc desc = "Directly draws #{long_name} on the current plot" end cmd.describe("Draws #{long_name}", desc, PrimitiveGroup) PrimitiveCommands[name] = cmd return primitive_class end
This creates a primitive base on a style object, given a style_class, the base style_name for the underlying styling system, options to remove and options to add.
The underlying code receives:
-
the FigureMaker object
-
the compulsory arguments
-
the style
-
the raw options
# File lib/ctioga2/graphics/elements/primitive.rb, line 196 def self.styled_primitive(name, long_name, comp, style_class, style_name, without = [], additional_options = {}, set_style_command = nil, &code) options = style_class.options_hash.without(without) options.merge!(additional_options) set_style_command ||= style_name desc = <<"EOD" Draws #{long_name} on the current plot, using the given style. For more information on the available options, see the {command: define-#{set_style_command}-style} command. EOD cls = self.primitive(name, long_name, comp, options, desc) do |*all| opts = all.pop style = get_style() style.set_from_hash(opts) all << style << opts code.call(*all) end cls.define_style(set_style_command, style_class) return cls end
Public Instance Methods
# File lib/ctioga2/graphics/elements/primitive.rb, line 89 def clipped if @options.key? 'clipped' return @options['clipped'] else return true # Defaults to clipped end end
# File lib/ctioga2/graphics/elements/primitive.rb, line 99 def depth @options['depth'] || 50 end
Protected Instance Methods
Draws the primitive
# File lib/ctioga2/graphics/elements/primitive.rb, line 331 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 instance_exec(t, *args, &primitive.funcall) end