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)
Constants inherited from TiogaElement
CTioga2::Graphics::Elements::TiogaElement::StyleBaseOptions
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
#hidden, #location, #object_classes, #object_id, #object_parent, #parent
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
all_styles, base_style, #check_styled, define_style, #do, find_object, find_objects, #get_style, #has_style?, inherited, #inspect, register_object, register_style, #setup_style, #style_class, style_class, style_name, #style_name, styled_classes, #update_style
Methods included from Log
context, counts, 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.
81 82 83 84 85 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 81 def initialize(primitive, arguments, ) @primitive = primitive @arguments = arguments @options = end |
Instance Attribute Details
#arguments ⇒ Object
An array containing the values of the compulsory arguments
71 72 73 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 71 def arguments @arguments end |
#last_curve_style ⇒ Object
The last curve’s style…
77 78 79 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 77 def last_curve_style @last_curve_style end |
#options ⇒ Object
A hash containing the values of the optional arguments
74 75 76 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 74 def @options end |
#primitive ⇒ Object
A TiogaPrimitive object describing the current primitive
68 69 70 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 68 def primitive @primitive end |
Class Method Details
.get_primitive(name) ⇒ Object
Returns a pair primitive/primitive command for the named primitive, or [ nil, nil ]
225 226 227 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 225 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.
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 154 155 156 157 158 159 160 161 162 |
# 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| = rest.pop call = primitive_class.new(primitive, rest, ) container = plotmaker.root_object.current_plot call.setup_style(container, ) 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 |
.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
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 196 def self.styled_primitive(name, long_name, comp, style_class, style_name, without = [], = {}, set_style_command = nil, &code) = style_class..without(without) .merge!() 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, , 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 |
Instance Method Details
#clipped ⇒ Object
89 90 91 92 93 94 95 |
# 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 |
#depth ⇒ Object
99 100 101 |
# File 'lib/ctioga2/graphics/elements/primitive.rb', line 99 def depth @options['depth'] || 50 end |