Class: CTioga2::Graphics::Elements::TiogaPrimitiveCall
- Inherits:
-
TiogaElement
- Object
- TiogaElement
- CTioga2::Graphics::Elements::TiogaPrimitiveCall
- Defined in:
- lib/ctioga2/graphics/elements/primitive.rb
Overview
Most of the objects here should rely on getting a
A TiogaElement that represents a graphics primitive.
BasicStyle object from the options hash and use it to draw. There is no need to make cumbersome and hard to extend hashes.
Defined Under Namespace
Classes: TiogaPrimitive
Constant Summary collapse
- PrimitiveCommands =
{}
- PrimitiveGroup =
CmdGroup.new('tioga-primitives', "Graphics primitives", "Tioga graphics primitives", 3)
Instance Attribute Summary collapse
-
#arguments ⇒ Object
An array containing the values of the compulsory arguments.
-
#last_curve_style ⇒ Object
The last curve’s style…
-
#options ⇒ Object
A hash containing the values of the optional arguments.
-
#primitive ⇒ Object
A TiogaPrimitive object describing the current primitive.
Attributes inherited from TiogaElement
Class Method Summary collapse
-
.get_primitive(name) ⇒ Object
Returns a pair primitive/primitive command for the named primitive, or [ nil, nil ].
-
.primitive(name, long_name, comp, opts = {}, desc = nil, &code) ⇒ Object
Creates a new primitive with the given parameters, and makes it immediately available as a command.
-
.styled_primitive(name, long_name, comp, style_class, style_name, without = [], additional_options = {}, set_style_command = nil, &code) ⇒ Object
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.
Instance Method Summary collapse
- #clipped ⇒ Object
- #depth ⇒ Object
-
#initialize(primitive, arguments, options) ⇒ TiogaPrimitiveCall
constructor
Creates a new TiogaPrimitiveCall object.
Methods inherited from TiogaElement
Methods included from Log
context, debug, error, fatal, #format_exception, #identify, info, init_logger, log_to, logger, set_level, #spawn, warn
Constructor Details
#initialize(primitive, arguments, options) ⇒ TiogaPrimitiveCall
Creates a new TiogaPrimitiveCall object.
78 79 80 81 82 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 78 def initialize(primitive, arguments, ) @primitive = primitive @arguments = arguments @options = end |
Instance Attribute Details
#arguments ⇒ Object
An array containing the values of the compulsory arguments
68 69 70 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 68 def arguments @arguments end |
#last_curve_style ⇒ Object
The last curve’s style…
74 75 76 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 74 def last_curve_style @last_curve_style end |
#options ⇒ Object
A hash containing the values of the optional arguments
71 72 73 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 71 def @options end |
#primitive ⇒ Object
A TiogaPrimitive object describing the current primitive
65 66 67 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 65 def primitive @primitive end |
Class Method Details
.get_primitive(name) ⇒ Object
Returns a pair primitive/primitive command for the named primitive, or [ nil, nil ]
195 196 197 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 195 def self.get_primitive(name) return [@known_primitives[name], PrimitiveCommands[name]] end |
.primitive(name, long_name, comp, opts = {}, desc = nil, &code) ⇒ Object
Creates a new primitive with the given parameters, and makes it immediately available as a command.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 110 def self.primitive(name, long_name, comp, opts = {}, desc = nil, &code) primitive = TiogaPrimitive.new(name, comp, opts, &code) @known_primitives[name] = primitive # 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 = Cmd.new("draw-#{name}",nil,"--draw-#{name}", cmd_args, cmd_opts) do |plotmaker, *rest| = rest.pop call = Elements:: TiogaPrimitiveCall.new(primitive, rest, ) call.last_curve_style = plotmaker.curve_style_stack.last plotmaker.root_object.current_plot. 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 end |
.styled_primitive(name, long_name, comp, style_class, style_name, without = [], additional_options = {}, set_style_command = nil, &code) ⇒ Object
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
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 164 def self.styled_primitive(name, long_name, comp, style_class, style_name, without = [], = {}, set_style_command = nil, # This # could be # removed &code) = style_class..without(without) .merge!() ['base-style'] = 'text' # the base style name 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 self.primitive(name, long_name, comp, , desc) do |*all| opts = all.pop st_name = opts['base-style'] || "base" style = Styles::StyleSheet.style_for(style_class,st_name) style.set_from_hash(opts) all << style << opts code.call(*all) end end |
Instance Method Details
#clipped ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 86 def clipped if @options.key? 'clipped' return @options['clipped'] else return true # Defaults to clipped end end |
#depth ⇒ Object
96 97 98 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 96 def depth @options['depth'] || 50 end |