ctioga2 0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/COPYING +339 -0
  2. data/Changelog +6 -0
  3. data/bin/ctioga2 +26 -0
  4. data/lib/ctioga2/commands/arguments.rb +58 -0
  5. data/lib/ctioga2/commands/commands.rb +258 -0
  6. data/lib/ctioga2/commands/doc/doc.rb +118 -0
  7. data/lib/ctioga2/commands/doc/documentation-commands.rb +119 -0
  8. data/lib/ctioga2/commands/doc/help.rb +95 -0
  9. data/lib/ctioga2/commands/doc/html.rb +230 -0
  10. data/lib/ctioga2/commands/doc/introspection.rb +211 -0
  11. data/lib/ctioga2/commands/doc/man.rb +279 -0
  12. data/lib/ctioga2/commands/doc/markup.rb +359 -0
  13. data/lib/ctioga2/commands/general-commands.rb +119 -0
  14. data/lib/ctioga2/commands/general-types.rb +118 -0
  15. data/lib/ctioga2/commands/groups.rb +73 -0
  16. data/lib/ctioga2/commands/interpreter.rb +257 -0
  17. data/lib/ctioga2/commands/parsers/command-line.rb +187 -0
  18. data/lib/ctioga2/commands/parsers/file.rb +186 -0
  19. data/lib/ctioga2/commands/strings.rb +303 -0
  20. data/lib/ctioga2/commands/type.rb +100 -0
  21. data/lib/ctioga2/commands/variables.rb +101 -0
  22. data/lib/ctioga2/data/backends/backend.rb +260 -0
  23. data/lib/ctioga2/data/backends/backends.rb +39 -0
  24. data/lib/ctioga2/data/backends/backends/gnuplot.rb +140 -0
  25. data/lib/ctioga2/data/backends/backends/math.rb +121 -0
  26. data/lib/ctioga2/data/backends/backends/text.rb +335 -0
  27. data/lib/ctioga2/data/backends/description.rb +405 -0
  28. data/lib/ctioga2/data/backends/factory.rb +73 -0
  29. data/lib/ctioga2/data/backends/parameter.rb +109 -0
  30. data/lib/ctioga2/data/datacolumn.rb +245 -0
  31. data/lib/ctioga2/data/dataset.rb +233 -0
  32. data/lib/ctioga2/data/filters.rb +131 -0
  33. data/lib/ctioga2/data/merge.rb +43 -0
  34. data/lib/ctioga2/data/point.rb +72 -0
  35. data/lib/ctioga2/data/stack.rb +294 -0
  36. data/lib/ctioga2/graphics/coordinates.rb +73 -0
  37. data/lib/ctioga2/graphics/elements.rb +111 -0
  38. data/lib/ctioga2/graphics/elements/containers.rb +111 -0
  39. data/lib/ctioga2/graphics/elements/curve2d.rb +155 -0
  40. data/lib/ctioga2/graphics/elements/element.rb +90 -0
  41. data/lib/ctioga2/graphics/elements/primitive.rb +256 -0
  42. data/lib/ctioga2/graphics/elements/subplot.rb +140 -0
  43. data/lib/ctioga2/graphics/generator.rb +68 -0
  44. data/lib/ctioga2/graphics/legends.rb +108 -0
  45. data/lib/ctioga2/graphics/legends/area.rb +199 -0
  46. data/lib/ctioga2/graphics/legends/items.rb +183 -0
  47. data/lib/ctioga2/graphics/legends/provider.rb +58 -0
  48. data/lib/ctioga2/graphics/legends/storage.rb +65 -0
  49. data/lib/ctioga2/graphics/root.rb +209 -0
  50. data/lib/ctioga2/graphics/styles.rb +30 -0
  51. data/lib/ctioga2/graphics/styles/axes.rb +247 -0
  52. data/lib/ctioga2/graphics/styles/background.rb +122 -0
  53. data/lib/ctioga2/graphics/styles/base.rb +115 -0
  54. data/lib/ctioga2/graphics/styles/carrays.rb +53 -0
  55. data/lib/ctioga2/graphics/styles/curve.rb +101 -0
  56. data/lib/ctioga2/graphics/styles/drawable.rb +87 -0
  57. data/lib/ctioga2/graphics/styles/factory.rb +351 -0
  58. data/lib/ctioga2/graphics/styles/legend.rb +63 -0
  59. data/lib/ctioga2/graphics/styles/plot.rb +410 -0
  60. data/lib/ctioga2/graphics/styles/sets.rb +64 -0
  61. data/lib/ctioga2/graphics/styles/texts.rb +277 -0
  62. data/lib/ctioga2/graphics/subplot-commands.rb +141 -0
  63. data/lib/ctioga2/graphics/types.rb +188 -0
  64. data/lib/ctioga2/graphics/types/bijection.rb +79 -0
  65. data/lib/ctioga2/graphics/types/boundaries.rb +170 -0
  66. data/lib/ctioga2/graphics/types/boxes.rb +157 -0
  67. data/lib/ctioga2/graphics/types/dimensions.rb +157 -0
  68. data/lib/ctioga2/graphics/types/point.rb +247 -0
  69. data/lib/ctioga2/log.rb +97 -0
  70. data/lib/ctioga2/metabuilder/type.rb +316 -0
  71. data/lib/ctioga2/metabuilder/types.rb +39 -0
  72. data/lib/ctioga2/metabuilder/types/coordinates.rb +124 -0
  73. data/lib/ctioga2/metabuilder/types/dates.rb +43 -0
  74. data/lib/ctioga2/metabuilder/types/lists.rb +188 -0
  75. data/lib/ctioga2/metabuilder/types/numbers.rb +97 -0
  76. data/lib/ctioga2/metabuilder/types/strings.rb +93 -0
  77. data/lib/ctioga2/metabuilder/types/styles.rb +178 -0
  78. data/lib/ctioga2/plotmaker.rb +677 -0
  79. data/lib/ctioga2/postprocess.rb +115 -0
  80. data/lib/ctioga2/utils.rb +120 -0
  81. data/setup.rb +1586 -0
  82. metadata +144 -0
@@ -0,0 +1,316 @@
1
+ # type.rb : a framework for type-to-string-to-type conversion
2
+ # Copyright (C) 2006-2009 Vincent Fourmond
3
+
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful, but
10
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
17
+ # USA
18
+
19
+ require 'ctioga2/utils'
20
+
21
+ module CTioga2
22
+
23
+ Version::register_svn_info('$Revision: 18 $', '$Date: 2009-04-28 23:43:54 +0200 (Tue, 28 Apr 2009) $')
24
+
25
+
26
+ # The MetaBuilder module contains a framework to perform
27
+ # string-to-type conversion and other stuff that can be useful for backends.
28
+ module MetaBuilder
29
+
30
+ # An exception that must be raised when
31
+ # Type#string_to_type is given incorrect input.
32
+ class IncorrectInput < Exception
33
+ end
34
+
35
+ # An exception raised when an invalid type is given to the
36
+ class InvalidType < Exception
37
+ end
38
+
39
+
40
+ # A class that handles a parameter type. It has to be subclassed to
41
+ # actually provide a parameter. The subclasses must provide the
42
+ # following:
43
+ #
44
+ # * a #string_to_type function to convert from string to the type;
45
+ # * a #type_to_string to convert back from type to string
46
+ # * an instance #type_name that returns a really small description
47
+ # of the type, to be used for instance to name command-line parameters.
48
+ # * a #type_name statement that registers the current class to the
49
+ # Type system.
50
+ #
51
+ # Moerover, it is a good idea to reimplement the
52
+ # #qt4_create_input_widget method; the default implementation works,
53
+ # but you probably wish it would look better.
54
+ #
55
+ # Types are implemented using hashes: this way, additionnal
56
+ # parameters can easily be added. The hash *must* have a :type key
57
+ # that will be interpreted by the children of Type. Examples:
58
+ #
59
+ # { :type => :integer}
60
+ # { :type => :file, :filter => "Text Files (*.txt)}
61
+ #
62
+ # And so on. You definitely should document your type and it's
63
+ # attributes properly, if you ever want that someone uses it.
64
+ #
65
+ # The list of currently recognised types is here:
66
+ #
67
+ # <tt>:integer</tt> :: Types::IntegerParameter
68
+ # <tt>:float</tt> :: Types::FloatParameter
69
+ # <tt>:string</tt> :: Types::StringParameter
70
+ # <tt>:file</tt> :: Types::FileParameter
71
+ # <tt>:boolean</tt> :: Types::BooleanParameter
72
+ # <tt>:list</tt> :: Types::ListParameter
73
+ #
74
+ # Additionally to the parameters the given type is requiring, you can
75
+ # pass some other kind of information using this hash, such as option
76
+ # parser short argument, aliases, and so on. This has nothing to do
77
+ # with type conversion, but it is the best place where to put this kind
78
+ # of things, in my humble opinion. The currently recognized such additional
79
+ # parameters are:
80
+ # * :option_parser_short: a short option name for option_parser.
81
+ # * :namespace: a ruby module that will be searched by #string_to_type
82
+ # for a constant. If one of the given name is found, its value is
83
+ # returned.
84
+ # * :shortctus: a hash specifiying strings shortcuts for given values.
85
+ # Elements of this hash that are regular expressions are taken
86
+ class Type
87
+
88
+ # A hash that makes the :type value of the _type_ argument correspond
89
+ # to a Type child
90
+ @@types = { }
91
+
92
+ # The initial type specification that was given to the Type
93
+ attr_accessor :type
94
+
95
+ # A hash shortcut -> value. Can be _nil_
96
+ attr_accessor :shortcuts
97
+
98
+ # A hash Regexp -> value. All elements will be looked for
99
+ # matches for every single string conversion, so don't dump too
100
+ # many of them here.
101
+ attr_accessor :re_shortcuts
102
+
103
+ # A default constructor. It should be safe to use it directly for
104
+ # children, unless something more specific is needed. Any descendent
105
+ # should *always* register _type_ as @type - or, even better, call
106
+ # super.
107
+ def initialize(type)
108
+ if type.is_a?(Symbol)
109
+ type = {:type => type}
110
+ end
111
+ @type = type
112
+ if @type[:shortcuts]
113
+ @shortcuts = @type[:shortcuts]
114
+ @re_shortcuts = {}
115
+ for k,v in @shortcuts
116
+ if k.is_a? Regexp
117
+ @re_shortcuts[k] = v
118
+ end
119
+ end
120
+ end
121
+ end
122
+
123
+ # This class function actually registers the current type
124
+ # to the Type ancestor. _name_ should be a symbol.
125
+ # Moreover, if the second argument is provided, it automatically
126
+ # creates a #type_name instance method returning this value.
127
+ def self.type_name(name, public_name = nil, default_value = nil)
128
+ if @@types.has_key?(name)
129
+ warn "Redefining type #{name} " +
130
+ "from #{@@types[name]} to #{self}"
131
+ end
132
+ @@types[name] = self
133
+ self.send(:define_method,:type_name) do
134
+ public_name
135
+ end
136
+ self.send(:define_method,:default_value) do
137
+ default_value
138
+ end
139
+ end
140
+
141
+ # This function converts a 'description' (see the Type) of the
142
+ # type wanted into a Type child. As a special treat, a lone
143
+ # symbol is converted into {:type => :symbol}
144
+ def self.get_param_type(type)
145
+ if type.is_a?(Symbol)
146
+ type = {:type => type}
147
+ end
148
+ raise InvalidType,"The type argument must be a Hash" unless
149
+ type.is_a?(Hash)
150
+ begin
151
+ return @@types.fetch(type[:type])
152
+ rescue
153
+ raise InvalidType, "Type #{type[:type]} unknown to the type system"
154
+ end
155
+ end
156
+
157
+ # Shortcut to convert directly a string to the given type specification.
158
+ # Handy shortcut.
159
+ def self.from_string(type, string)
160
+ return get_type(type).string_to_type(string)
161
+ end
162
+
163
+ # Returns a Type child instance suitable for conversion
164
+ # of the given type specification
165
+ def self.get_type(type)
166
+ if type.is_a? Type
167
+ return type
168
+ end
169
+ return get_param_type(type).new(type)
170
+ end
171
+
172
+
173
+
174
+ # This function converts the given string to the appropriate
175
+ # type. It is a wrapper around the #string_to_type_internal
176
+ # function that can take advantage of a few general features. It
177
+ # is recommanded to define a #string_to_type_internal function
178
+ # rather to redefine #string_to_type
179
+ def string_to_type(string)
180
+ # First, shortcuts:
181
+ if @shortcuts and @shortcuts.key? string
182
+ return stt_run_hook(@shortcuts[string])
183
+ end
184
+ if @re_shortcuts
185
+ for k, v in @re_shortcuts
186
+ if string =~ k
187
+ return stt_run_hook(v)
188
+ end
189
+ end
190
+ end
191
+ # Then, constants lookup.
192
+ if @type.key?(:namespace)
193
+ begin
194
+ return stt_run_hook(lookup_const(string))
195
+ rescue Exception
196
+ end
197
+ end
198
+ return stt_run_hook(string_to_type_internal(string))
199
+ end
200
+
201
+ # This function does the exact opposite of the #string_to_type
202
+ # one. It defaults to using the to_s methods of the
203
+ # parameter. Be careful: it is absolutely important that for any
204
+ # valid type,
205
+ #
206
+ # string_to_type(type_to_string(type)) == type
207
+ def type_to_string(type)
208
+ return type_to_string_internal(type)
209
+ end
210
+
211
+
212
+ # Returns a default value for the given type. This is
213
+ # reimplemented systematically from children, with the
214
+ # Type::type_name statement.
215
+ def default_value
216
+ end
217
+
218
+
219
+ # Returns a type name suitable for displaying, for instance, in
220
+ # an option parser, or inside a dialog box, and so on. Has to be
221
+ # one word (not to confuse the option parser, for instance); it
222
+ # is better if it is lowercase.
223
+ def type_name
224
+ return 'notype'
225
+ end
226
+
227
+
228
+ # Creates an option for the OptionParser _parser_. The block is
229
+ # fed with the converted value. The default implementation
230
+ # should be fine for most classes, but this still leaves the
231
+ # room for reimplementation if necessary. The parameters are:
232
+ #
233
+ # * _parser_: the OptionParser;
234
+ # * _name_: the name of the option;
235
+ # * _desc_: it description,
236
+ # * _block_: the block used to set the data.
237
+ def option_parser_option(parser, name, desc, &block)
238
+ args = [option_parser_long_option(name), desc]
239
+ if @type.has_key?(:option_parser_short)
240
+ args.unshift(@type[:option_parser_short])
241
+ end
242
+ option_parser_raw(parser, *args, &block)
243
+ end
244
+
245
+ # Returns a value to be fed to OptionParser#on as a 'long'
246
+ # option. It is separated from the rest to allow easy
247
+ # redefinition (in special cases). _name_ is the name of the
248
+ # option.
249
+ def option_parser_long_option(name, param = nil)
250
+ param ||= type_name
251
+ param = param.gsub(/\s+/, '_')
252
+ return "--#{name} #{param.upcase}"
253
+ end
254
+
255
+ # Whether the type is a boolean. Booleans are special cased for
256
+ # their use in the command-line.
257
+ def boolean?
258
+ return false
259
+ end
260
+
261
+ ############################################################
262
+ # Part of the internal implementation of Types. This should be
263
+ # used/redefined in children
264
+
265
+ protected
266
+
267
+ # Looks for the value as a constant specified in the :namespace
268
+ # modules. Raises IncorrectInput if not found.
269
+ def lookup_const(str)
270
+ for mod in [@type[:namespace]].flatten
271
+ begin
272
+ return mod.const_get(str)
273
+ rescue
274
+ # Nothing, we still look up
275
+ end
276
+ end
277
+ raise IncorrectInput, "Constant #{str} not found"
278
+ end
279
+
280
+ # The internal function for converting type to a string. Used by
281
+ # #type_to_string, children should only reimplement this
282
+ # function and leave #type_to_string
283
+ def type_to_string_internal(type)
284
+ return type.to_s
285
+ end
286
+
287
+
288
+ # Runs the string_to_type conversion hook
289
+ def stt_run_hook(val)
290
+ if @type.key?(:stt_hook)
291
+ return @type[:stt_hook].call(val)
292
+ else
293
+ val
294
+ end
295
+ end
296
+
297
+ # Does the actual conversion from a _string_ to the
298
+ # type. Redefine this in children.
299
+ def string_to_type_internal(string)
300
+ raise "The class #{self.class} should not be used by itself for conversion"
301
+ end
302
+
303
+ # Creates on option for the OptionParser _parser_. The _args_
304
+ # will be fed directly to OptionParser#on. The _block_ is called
305
+ # with the value in the target type.
306
+ def option_parser_raw(parser, *args, &block)
307
+ b = block # For safe-keeping.
308
+ c = proc do |str|
309
+ b.call(string_to_type(str))
310
+ end
311
+ parser.on(*args, &c)
312
+ end
313
+
314
+ end
315
+ end
316
+ end
@@ -0,0 +1,39 @@
1
+ # types.rb: the whole type framework
2
+
3
+ # This program is free software; you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation; either version 2 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful, but
9
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
+ # General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program; if not, write to the Free Software
15
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
16
+ # USA
17
+
18
+
19
+ require 'ctioga2/metabuilder/type'
20
+
21
+ # We try to look for all files under a ctioga2/metabuilder/types
22
+ # directory anywhere on the $: path
23
+
24
+ files = []
25
+ for dir in $:
26
+ Dir[dir + '/ctioga2/metabuilder/types/**/*'].each do |f|
27
+ f =~ /ctioga2\/metabuilder\/types\/(.*)\.[^.]+$/
28
+ files << $1
29
+ end
30
+ end
31
+
32
+ for file in files.uniq
33
+ begin
34
+ require "ctioga2/metabuilder/types/#{file}"
35
+ rescue Exception => e
36
+ warn "There was a problem trying to load 'ctioga2/metabuilder/types/#{file}'"
37
+ warn "#{e.inspect}"
38
+ end
39
+ end
@@ -0,0 +1,124 @@
1
+ # coordinates.rb : input of coordinates and dimensions in general
2
+ # Copyright (C) 2006, 2009 Vincent Fourmond
3
+ #
4
+ # This program is free software; you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation; either version 2 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program; if not, write to the Free Software
16
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
+
18
+
19
+ require 'ctioga2/utils'
20
+
21
+ module CTioga2
22
+
23
+ Version::register_svn_info('$Revision: 67 $', '$Date: 2009-05-30 23:38:00 +0200 (Sat, 30 May 2009) $')
24
+
25
+ module MetaBuilder
26
+ module Types
27
+
28
+ # Handles a dimension, either relative or absolute
29
+ class DimensionType < Type
30
+
31
+ type_name :dimension, 'dimension'
32
+
33
+ def string_to_type_internal(str)
34
+ default = @type[:default] || :dy
35
+ orient = @type[:orient] || :x
36
+ return Graphics::Types::Dimension::from_text(str, orient, default)
37
+ end
38
+ end
39
+
40
+
41
+
42
+ # A class that produces a Graphics::Types::MarginsBox. It takes
43
+ # one optional argument : a :default (:frame, :figure or :page),
44
+ # see Graphics::Types::Dimensions::from_text for more information.
45
+ class MarginsType < Type
46
+
47
+ type_name :frame_margins, 'frame_margins'
48
+
49
+ def string_to_type_internal(str)
50
+ default = @type[:default] || :frame
51
+ specs = str.split(/\s*,\s*/)
52
+ if specs.size == 1
53
+ specs = specs * 4
54
+ elsif specs.size == 2
55
+ specs = [specs[0], specs[0], specs[1], specs[1]]
56
+ end
57
+ if specs.size != 4
58
+ raise IncorrectInput, "You need either 1, 2 or 4 elements to make up a margin specification"
59
+ end
60
+ return Graphics::Types::MarginsBox.new(*specs.map {|x|
61
+ Graphics::Types::Dimension::from_text(x, :x, default )})
62
+ end
63
+ end
64
+
65
+ # A class that produces a Graphics::Types::Point. It takes one
66
+ # optional argument: a :default (:frame, :figure or :page), see
67
+ # Graphics::Types::Dimensions::from_text for more information.
68
+ class PointType < Type
69
+
70
+ type_name :point, 'point'
71
+
72
+ def string_to_type_internal(str)
73
+ default = @type[:default] || :figure
74
+ return Graphics::Types::Point::from_text(str, default)
75
+ end
76
+ end
77
+
78
+
79
+ # A class that produces a Graphics::Types::AlignedPoint. It
80
+ # takes one optional argument : a :default (:frame, :figure or
81
+ # :page), see Graphics::Types::Dimensions::from_text for more
82
+ # information.
83
+ class AlignedPointType < Type
84
+
85
+ type_name :aligned_point, 'aligned_point'
86
+
87
+ def string_to_type_internal(str)
88
+ default = @type[:default] || :frame
89
+ return Graphics::Types::AlignedPoint::from_text(str, default)
90
+ end
91
+ end
92
+
93
+
94
+ # A generic class that interfaces known types of boxes. Much fun
95
+ # in perspective.
96
+ class BoxType < Type
97
+
98
+ type_name :box, 'box'
99
+
100
+ def string_to_type_internal(str)
101
+ default = @type[:default] || :frame
102
+ case str
103
+ when Graphics::Types::PointBasedBox::PointBasedBoxRE
104
+ return Graphics::Types::PointBasedBox::from_text(str, default)
105
+ else
106
+ raise "Unknown box specification: '#{str}'"
107
+ end
108
+ end
109
+ end
110
+
111
+ # A general bidirectional coordinate transformation.
112
+ class BijectionType < Type
113
+
114
+ type_name :bijection, 'bijection'
115
+
116
+ def string_to_type_internal(str)
117
+ return Graphics::Types::Bijection.from_text(str)
118
+ end
119
+
120
+ end
121
+
122
+ end
123
+ end
124
+ end