Class: CTioga2::Graphics::Elements::TiogaPrimitiveCall

Inherits:
TiogaElement
  • Object
show all
Defined in:
lib/ctioga2/graphics/elements/primitive.rb

Overview

A TiogaElement that represents a graphics primitive.

Defined Under Namespace

Classes: TiogaPrimitive

Constant Summary collapse

PrimitiveCommands =
{}
PrimitiveGroup =
CmdGroup.new('tioga-primitives',
"Graphics primitives",
"Tioga graphics primitives", 3)
MarkerOptions =
{
  'color' => 'color',
  'stroke_color' => 'color',
  'fill_color' => 'color',
  'scale' => 'float',
  'horizontal_scale' => 'float',
  'vertical_scale' => 'float',
  'angle' => 'float',
  'justification' => 'justification',
  'alignment' => 'alignment',
}
ArrowOptions =

options for arrows (and therefore tangents)

{
  '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',
}

Instance Attribute Summary collapse

Attributes inherited from TiogaElement

#location, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from TiogaElement

#do, #inspect

Methods included from Log

debug, error, fatal, #format_exception, #identify, info, init_logger, logger, set_level, #spawn, warn

Constructor Details

#initialize(primitive, arguments, options) ⇒ TiogaPrimitiveCall

Creates a new TiogaPrimitiveCall object.



74
75
76
77
78
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 74

def initialize(primitive, arguments, options)
  @primitive = primitive
  @arguments = arguments
  @options = options
end

Instance Attribute Details

#argumentsObject

An array containing the values of the compulsory arguments



64
65
66
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 64

def arguments
  @arguments
end

#last_curve_styleObject

The last curve’s style…



70
71
72
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 70

def last_curve_style
  @last_curve_style
end

#optionsObject

A hash containing the values of the optional arguments



67
68
69
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 67

def options
  @options
end

#primitiveObject

A TiogaPrimitive object describing the current primitive



61
62
63
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 61

def primitive
  @primitive
end

Class Method Details

.get_primitive(name) ⇒ Object

Returns a pair primitive/primitive command for the named primitive, or [ nil, nil ]



123
124
125
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 123

def self.get_primitive(name)
  return [@known_primitives[name], PrimitiveCommands[name]]
end

.primitive(name, long_name, comp, opts = {}, &code) ⇒ Object

Creates a new primitive with the given parameters, and makes it immediately available as a command.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 90

def self.primitive(name, long_name, comp, opts = {}, &code)
  primitive = TiogaPrimitive.new(name, comp, opts, &code)
  @known_primitives[name] = primitive
  
  # Now, create the command
  cmd_args = comp.map do |x|
    CmdArg.new(x)
  end

  cmd_opts = {}
  for k,v in opts
    cmd_opts[k] = CmdArg.new(v)
  end
  
  cmd = Cmd.new("draw-#{name}",nil,"--draw-#{name}", 
                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)

  PrimitiveCommands[name] = cmd
end