ctioga2 0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +339 -0
- data/Changelog +6 -0
- data/bin/ctioga2 +26 -0
- data/lib/ctioga2/commands/arguments.rb +58 -0
- data/lib/ctioga2/commands/commands.rb +258 -0
- data/lib/ctioga2/commands/doc/doc.rb +118 -0
- data/lib/ctioga2/commands/doc/documentation-commands.rb +119 -0
- data/lib/ctioga2/commands/doc/help.rb +95 -0
- data/lib/ctioga2/commands/doc/html.rb +230 -0
- data/lib/ctioga2/commands/doc/introspection.rb +211 -0
- data/lib/ctioga2/commands/doc/man.rb +279 -0
- data/lib/ctioga2/commands/doc/markup.rb +359 -0
- data/lib/ctioga2/commands/general-commands.rb +119 -0
- data/lib/ctioga2/commands/general-types.rb +118 -0
- data/lib/ctioga2/commands/groups.rb +73 -0
- data/lib/ctioga2/commands/interpreter.rb +257 -0
- data/lib/ctioga2/commands/parsers/command-line.rb +187 -0
- data/lib/ctioga2/commands/parsers/file.rb +186 -0
- data/lib/ctioga2/commands/strings.rb +303 -0
- data/lib/ctioga2/commands/type.rb +100 -0
- data/lib/ctioga2/commands/variables.rb +101 -0
- data/lib/ctioga2/data/backends/backend.rb +260 -0
- data/lib/ctioga2/data/backends/backends.rb +39 -0
- data/lib/ctioga2/data/backends/backends/gnuplot.rb +140 -0
- data/lib/ctioga2/data/backends/backends/math.rb +121 -0
- data/lib/ctioga2/data/backends/backends/text.rb +335 -0
- data/lib/ctioga2/data/backends/description.rb +405 -0
- data/lib/ctioga2/data/backends/factory.rb +73 -0
- data/lib/ctioga2/data/backends/parameter.rb +109 -0
- data/lib/ctioga2/data/datacolumn.rb +245 -0
- data/lib/ctioga2/data/dataset.rb +233 -0
- data/lib/ctioga2/data/filters.rb +131 -0
- data/lib/ctioga2/data/merge.rb +43 -0
- data/lib/ctioga2/data/point.rb +72 -0
- data/lib/ctioga2/data/stack.rb +294 -0
- data/lib/ctioga2/graphics/coordinates.rb +73 -0
- data/lib/ctioga2/graphics/elements.rb +111 -0
- data/lib/ctioga2/graphics/elements/containers.rb +111 -0
- data/lib/ctioga2/graphics/elements/curve2d.rb +155 -0
- data/lib/ctioga2/graphics/elements/element.rb +90 -0
- data/lib/ctioga2/graphics/elements/primitive.rb +256 -0
- data/lib/ctioga2/graphics/elements/subplot.rb +140 -0
- data/lib/ctioga2/graphics/generator.rb +68 -0
- data/lib/ctioga2/graphics/legends.rb +108 -0
- data/lib/ctioga2/graphics/legends/area.rb +199 -0
- data/lib/ctioga2/graphics/legends/items.rb +183 -0
- data/lib/ctioga2/graphics/legends/provider.rb +58 -0
- data/lib/ctioga2/graphics/legends/storage.rb +65 -0
- data/lib/ctioga2/graphics/root.rb +209 -0
- data/lib/ctioga2/graphics/styles.rb +30 -0
- data/lib/ctioga2/graphics/styles/axes.rb +247 -0
- data/lib/ctioga2/graphics/styles/background.rb +122 -0
- data/lib/ctioga2/graphics/styles/base.rb +115 -0
- data/lib/ctioga2/graphics/styles/carrays.rb +53 -0
- data/lib/ctioga2/graphics/styles/curve.rb +101 -0
- data/lib/ctioga2/graphics/styles/drawable.rb +87 -0
- data/lib/ctioga2/graphics/styles/factory.rb +351 -0
- data/lib/ctioga2/graphics/styles/legend.rb +63 -0
- data/lib/ctioga2/graphics/styles/plot.rb +410 -0
- data/lib/ctioga2/graphics/styles/sets.rb +64 -0
- data/lib/ctioga2/graphics/styles/texts.rb +277 -0
- data/lib/ctioga2/graphics/subplot-commands.rb +141 -0
- data/lib/ctioga2/graphics/types.rb +188 -0
- data/lib/ctioga2/graphics/types/bijection.rb +79 -0
- data/lib/ctioga2/graphics/types/boundaries.rb +170 -0
- data/lib/ctioga2/graphics/types/boxes.rb +157 -0
- data/lib/ctioga2/graphics/types/dimensions.rb +157 -0
- data/lib/ctioga2/graphics/types/point.rb +247 -0
- data/lib/ctioga2/log.rb +97 -0
- data/lib/ctioga2/metabuilder/type.rb +316 -0
- data/lib/ctioga2/metabuilder/types.rb +39 -0
- data/lib/ctioga2/metabuilder/types/coordinates.rb +124 -0
- data/lib/ctioga2/metabuilder/types/dates.rb +43 -0
- data/lib/ctioga2/metabuilder/types/lists.rb +188 -0
- data/lib/ctioga2/metabuilder/types/numbers.rb +97 -0
- data/lib/ctioga2/metabuilder/types/strings.rb +93 -0
- data/lib/ctioga2/metabuilder/types/styles.rb +178 -0
- data/lib/ctioga2/plotmaker.rb +677 -0
- data/lib/ctioga2/postprocess.rb +115 -0
- data/lib/ctioga2/utils.rb +120 -0
- data/setup.rb +1586 -0
- metadata +144 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# dimensions.rb: various ways to represent a dimension in Tioga
|
|
2
|
+
# copyright (c) 2009 by 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 (in the COPYING file).
|
|
13
|
+
|
|
14
|
+
require 'ctioga2/utils'
|
|
15
|
+
require 'ctioga2/log'
|
|
16
|
+
|
|
17
|
+
module CTioga2
|
|
18
|
+
|
|
19
|
+
Version::register_svn_info('$Revision: 92 $', '$Date: 2009-06-24 01:17:46 +0200 (Wed, 24 Jun 2009) $')
|
|
20
|
+
|
|
21
|
+
module Graphics
|
|
22
|
+
|
|
23
|
+
module Types
|
|
24
|
+
|
|
25
|
+
# A Dimension is an object that represents a dimension in the
|
|
26
|
+
# different ways understood by Tioga:
|
|
27
|
+
# * an "absolute" dimension, ie, in real units (postscript points)
|
|
28
|
+
# * a "text" dimension, in units of the height of the current
|
|
29
|
+
# text object
|
|
30
|
+
# * a frame/page/figure dimension, in units of the *current*
|
|
31
|
+
# frame/page/figure coordinates
|
|
32
|
+
class Dimension
|
|
33
|
+
|
|
34
|
+
include Tioga::Utils
|
|
35
|
+
|
|
36
|
+
# What is the underlying representation of the dimension ?
|
|
37
|
+
# * :bp in postscript points
|
|
38
|
+
# * :dy in text height units
|
|
39
|
+
# * :frame in frame coordinates
|
|
40
|
+
# * :page in page coordinates
|
|
41
|
+
# * :figure in figure coordinates
|
|
42
|
+
attr_accessor :type
|
|
43
|
+
|
|
44
|
+
# The orientation of the dimension: vertical (:y) or
|
|
45
|
+
# horizontal (:x) ?
|
|
46
|
+
attr_accessor :orientation
|
|
47
|
+
|
|
48
|
+
# The actual dimension. The interpretation depends on the
|
|
49
|
+
# value of #type.
|
|
50
|
+
attr_accessor :value
|
|
51
|
+
|
|
52
|
+
# Creates a Dimension object of the given _type_, the given
|
|
53
|
+
# _value_ oriented along the given _orientation_
|
|
54
|
+
def initialize(type, value, orientation = :x)
|
|
55
|
+
@type = type
|
|
56
|
+
@value = value
|
|
57
|
+
@orientation = orientation
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Converts the Dimension to the *figure* coordinates of the
|
|
61
|
+
# *current* figure in _t_.
|
|
62
|
+
def to_figure(t, orientation = nil)
|
|
63
|
+
orientation ||= @orientation
|
|
64
|
+
case @type
|
|
65
|
+
when :bp
|
|
66
|
+
return t.send("convert_output_to_figure_d#{orientation}", @value) * 10
|
|
67
|
+
when :dy
|
|
68
|
+
return t.send("default_text_height_d#{orientation}") * @value
|
|
69
|
+
when :frame
|
|
70
|
+
return t.send("convert_frame_to_figure_d#{orientation}", @value)
|
|
71
|
+
when :page
|
|
72
|
+
return t.send("convert_page_to_figure_d#{orientation}", @value)
|
|
73
|
+
when :figure
|
|
74
|
+
return @value
|
|
75
|
+
else
|
|
76
|
+
raise "Invalid type for Dimension: #{@type}"
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Converts the Dimension to the *frame* coordinates of the
|
|
81
|
+
# *current* frame in _t_.
|
|
82
|
+
def to_frame(t, orientation = nil)
|
|
83
|
+
orientation ||= @orientation
|
|
84
|
+
return t.send("convert_figure_to_frame_d#{orientation}",
|
|
85
|
+
to_figure(t, orientation))
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Replace this Dimension by _dimension_ if the latter is
|
|
89
|
+
# bigger. Conserves the current orientation.
|
|
90
|
+
def replace_if_bigger(t, dimension)
|
|
91
|
+
if self.to_figure(t) < dimension.to_figure(t, @orientation)
|
|
92
|
+
@type = dimension.type
|
|
93
|
+
@value = dimension.value
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Dimension conversion constants taken straight from the
|
|
98
|
+
# TeXbook
|
|
99
|
+
DimensionConversion = {
|
|
100
|
+
"pt" => (72.0/72.27),
|
|
101
|
+
"bp" => 1.0,
|
|
102
|
+
"in" => 72.0,
|
|
103
|
+
"cm" => (72.0/2.54),
|
|
104
|
+
"mm" => (72.0/25.4),
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
# A regular expression that matches all dimensions.
|
|
108
|
+
DimensionRegexp = /^\s*([+-]?\s*[\d.eE+-]+)\s*([a-zA-Z]+)?\s*$/
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
# Creates a Dimension object from a _text_ specification. The
|
|
112
|
+
# text should be in the forms
|
|
113
|
+
#
|
|
114
|
+
# value unit
|
|
115
|
+
#
|
|
116
|
+
# where unit is one of bp, pt, in, mm, cm, dy (the latter
|
|
117
|
+
# being one unit of height) f|figure, F|Frame|frame,
|
|
118
|
+
# p|page. It can be ommitted, in which case it defaults to the
|
|
119
|
+
# _default_ parameter.
|
|
120
|
+
def self.from_text(text, orientation, default = :figure)
|
|
121
|
+
# Absolute or :dy dimension
|
|
122
|
+
if text =~ DimensionRegexp
|
|
123
|
+
value = Float($1)
|
|
124
|
+
unit = $2
|
|
125
|
+
if ! unit
|
|
126
|
+
unit = default
|
|
127
|
+
elsif DimensionConversion.key?(unit.downcase)
|
|
128
|
+
value *= DimensionConversion[unit.downcase]
|
|
129
|
+
unit = :bp
|
|
130
|
+
else
|
|
131
|
+
case unit
|
|
132
|
+
when /^dy$/i
|
|
133
|
+
unit = :dy
|
|
134
|
+
when /^F|(?i:frame)$/
|
|
135
|
+
unit = :frame
|
|
136
|
+
when /^f|(?i:figure)$/
|
|
137
|
+
unit = :figure
|
|
138
|
+
when /^p|(?i:page)$/
|
|
139
|
+
unit = :page
|
|
140
|
+
else
|
|
141
|
+
raise "Unkown dimension unit: #{unit}"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
return Dimension.new(unit, value, orientation)
|
|
145
|
+
else
|
|
146
|
+
raise "Unkown Dimension specification: '#{text}'"
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
end
|
|
157
|
+
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# point.rb: various ways to represent a position in Tioga
|
|
2
|
+
# copyright (c) 2009 by 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 (in the COPYING file).
|
|
13
|
+
|
|
14
|
+
require 'ctioga2/utils'
|
|
15
|
+
require 'ctioga2/log'
|
|
16
|
+
|
|
17
|
+
module CTioga2
|
|
18
|
+
|
|
19
|
+
Version::register_svn_info('$Revision: 53 $', '$Date: 2009-05-20 01:05:32 +0200 (Wed, 20 May 2009) $')
|
|
20
|
+
|
|
21
|
+
module Graphics
|
|
22
|
+
|
|
23
|
+
module Types
|
|
24
|
+
|
|
25
|
+
# This class performs the same function as Dimension, except
|
|
26
|
+
# that it represents a *coordinate*. As such, its #value only
|
|
27
|
+
# makes sense as a page, frame or figure coordinate
|
|
28
|
+
class BaseCoordinate < Dimension
|
|
29
|
+
|
|
30
|
+
# Creates a BaseCoordinate object of the given _type_, the
|
|
31
|
+
# given _value_ and oriented along the given _orientation_
|
|
32
|
+
def initialize(type, value, orientation)
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Converts the Dimension to the *figure* coordinates of the
|
|
37
|
+
# *current* figure in _t_.
|
|
38
|
+
def to_figure(t, orientation = nil)
|
|
39
|
+
orientation ||= @orientation
|
|
40
|
+
case @type
|
|
41
|
+
when :frame
|
|
42
|
+
return t.send("convert_frame_to_figure_#{orientation}", @value)
|
|
43
|
+
when :page
|
|
44
|
+
return t.send("convert_page_to_figure_#{orientation}", @value)
|
|
45
|
+
when :figure
|
|
46
|
+
return @value
|
|
47
|
+
else
|
|
48
|
+
raise "Invalid type for BaseCoordinate: #{@type}"
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Converts the Dimension to the *frame* coordinates of the
|
|
53
|
+
# *current* frame in _t_.
|
|
54
|
+
def to_frame(t, orientation = nil)
|
|
55
|
+
orientation ||= @orientation
|
|
56
|
+
return t.send("convert_figure_to_frame_#{orientation}",
|
|
57
|
+
to_figure(t, orientation))
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Creates a BaseCoordinate object from a text
|
|
61
|
+
# specification. Takes the same argument as
|
|
62
|
+
# Dimension.from_text, except that purely dimension #type
|
|
63
|
+
# won't be accepted.
|
|
64
|
+
def self.from_text(text, orientation, default = :figure)
|
|
65
|
+
dim = Dimension.from_text(text, orientation, default)
|
|
66
|
+
if dim.type == :bp or dim.type == :dy
|
|
67
|
+
raise "Does not accept dimensions only for coordinates"
|
|
68
|
+
end
|
|
69
|
+
return BaseCoordinate.new(dim.type, dim.value, dim.orientation)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
# Represents a given Point for Tioga. Its coordinates are
|
|
76
|
+
# BaseCoordinate objects.
|
|
77
|
+
class Point
|
|
78
|
+
|
|
79
|
+
# The X coordinate, a BaseCoordinate object
|
|
80
|
+
attr_accessor :x
|
|
81
|
+
|
|
82
|
+
# The Y coordinate, a BaseCoordinate object
|
|
83
|
+
attr_accessor :y
|
|
84
|
+
|
|
85
|
+
# Creates a Point with the given coordinates (of type _type_,
|
|
86
|
+
# see BaseCoordinate for more information).
|
|
87
|
+
def initialize(x = nil, y = nil, type = :figure)
|
|
88
|
+
if x && y
|
|
89
|
+
@x = BaseCoordinate.new(type, x, :x)
|
|
90
|
+
@y = BaseCoordinate.new(type, y, :y)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Converts the point to figure coordinates.
|
|
95
|
+
def to_figure_xy(t)
|
|
96
|
+
return [@x.to_figure(t), @y.to_figure(t)]
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Converts the points to frame coordinates.
|
|
100
|
+
def to_frame_xy(t)
|
|
101
|
+
return [@x.to_frame(t), @y.to_frame(t)]
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Creates a Point object from a text specification. Splits up
|
|
105
|
+
# the text at a comma and
|
|
106
|
+
def self.from_text(text, default = :figure)
|
|
107
|
+
vals = text.split(/\s*,\s*/)
|
|
108
|
+
if vals.size != 2
|
|
109
|
+
raise "Should really have two values: #{text}"
|
|
110
|
+
end
|
|
111
|
+
coord = Point.new
|
|
112
|
+
coord.x = BaseCoordinate.from_text(vals[0], :x, default)
|
|
113
|
+
coord.y = BaseCoordinate.from_text(vals[1], :y, default)
|
|
114
|
+
return coord
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# A Point, but with alignment facilities.
|
|
119
|
+
class AlignedPoint < Point
|
|
120
|
+
# Vertical alignement (:top, :center, :bottom)
|
|
121
|
+
attr_accessor :valign
|
|
122
|
+
|
|
123
|
+
# Horizontal alignment (:left, :center, :right)
|
|
124
|
+
attr_accessor :halign
|
|
125
|
+
|
|
126
|
+
# Creates a AlignedPoint
|
|
127
|
+
def initialize(x = nil, y = nil, type = :figure,
|
|
128
|
+
halign = :center, valign = :center)
|
|
129
|
+
super(x,y,type)
|
|
130
|
+
@halign = halign
|
|
131
|
+
@valign = valign
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Returns frame coordinates corresponding to the point, the
|
|
135
|
+
# alignment and the given size in figure coordinates
|
|
136
|
+
def to_frame_coordinates(t, width, height)
|
|
137
|
+
dx = t.convert_figure_to_frame_dx(width).abs
|
|
138
|
+
dy = t.convert_figure_to_frame_dy(height).abs
|
|
139
|
+
x,y = self.to_frame_xy(t)
|
|
140
|
+
|
|
141
|
+
case @valign
|
|
142
|
+
when :top
|
|
143
|
+
yt = y
|
|
144
|
+
yb = y - dy
|
|
145
|
+
when :bottom
|
|
146
|
+
yt = y + dy
|
|
147
|
+
yb = y
|
|
148
|
+
when :center
|
|
149
|
+
yt = y + dy/2
|
|
150
|
+
yb = y - dy/2
|
|
151
|
+
else
|
|
152
|
+
raise "Unknown vertical alignment: #{@valign}"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
case @halign
|
|
156
|
+
when :right
|
|
157
|
+
xl = x - dx
|
|
158
|
+
xr = x
|
|
159
|
+
when :left
|
|
160
|
+
xl = x
|
|
161
|
+
xr = x + dx
|
|
162
|
+
when :center
|
|
163
|
+
xl = x - dx/2
|
|
164
|
+
xr = x + dx/2
|
|
165
|
+
else
|
|
166
|
+
raise "Unknown horizontal alignment: #{@halign}"
|
|
167
|
+
end
|
|
168
|
+
return [xl, yt, xr, yb]
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Returns a frame_margin corresponding to the point, the
|
|
172
|
+
# alignment and the given size in figure coordinates.
|
|
173
|
+
#
|
|
174
|
+
# See #to_frame_coordinates
|
|
175
|
+
def to_frame_margins(t, width, height)
|
|
176
|
+
xl, yt, xr, yb = to_frame_coordinates(t, width, height)
|
|
177
|
+
return [xl,1 - xr, 1 - yt, yb]
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
AlignmentSpecification = {
|
|
181
|
+
'r' => :right,
|
|
182
|
+
'c' => :center,
|
|
183
|
+
'l' => :left,
|
|
184
|
+
't' => :top,
|
|
185
|
+
'b' => :bottom
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
# Creates an AlignedPoint object from a text
|
|
190
|
+
# specification. Splits up the text at a comma and
|
|
191
|
+
def self.from_text(text, default = :figure)
|
|
192
|
+
if not text =~ /^\s*([btlrc]{2})(?::([^,]+),\s*(.*))?\s*$/
|
|
193
|
+
return "Invalid format for #{text}"
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
specs = $1
|
|
197
|
+
specs = specs.chars.map {|x|
|
|
198
|
+
AlignmentSpecification.fetch(x.downcase)
|
|
199
|
+
}
|
|
200
|
+
coord = AlignedPoint.new
|
|
201
|
+
if specs[0] == :center
|
|
202
|
+
specs.reverse!
|
|
203
|
+
end
|
|
204
|
+
case specs[0]
|
|
205
|
+
when :center
|
|
206
|
+
coord.halign = :center
|
|
207
|
+
coord.valign = :center
|
|
208
|
+
when :left, :right
|
|
209
|
+
coord.halign = specs[0]
|
|
210
|
+
coord.valign = specs[1]
|
|
211
|
+
when :top, :bottom
|
|
212
|
+
coord.valign = specs[0]
|
|
213
|
+
coord.halign = specs[1]
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
if $2
|
|
217
|
+
x_spec,y_spec = $2,$3
|
|
218
|
+
coord.x = BaseCoordinate.from_text(x_spec, :x, default)
|
|
219
|
+
coord.y = BaseCoordinate.from_text(y_spec, :y, default)
|
|
220
|
+
else
|
|
221
|
+
case coord.halign
|
|
222
|
+
when :center
|
|
223
|
+
coord.x = BaseCoordinate.new(:frame, 0.5, :x)
|
|
224
|
+
when :left
|
|
225
|
+
coord.x = BaseCoordinate.new(:frame, 0.05, :x)
|
|
226
|
+
when :right
|
|
227
|
+
coord.x = BaseCoordinate.new(:frame, 0.95, :x)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
case coord.valign
|
|
231
|
+
when :center
|
|
232
|
+
coord.y = BaseCoordinate.new(:frame, 0.5, :y)
|
|
233
|
+
when :bottom
|
|
234
|
+
coord.y = BaseCoordinate.new(:frame, 0.05, :y)
|
|
235
|
+
when :top
|
|
236
|
+
coord.y = BaseCoordinate.new(:frame, 0.95, :y)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
return coord
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
end
|
|
247
|
+
|
data/lib/ctioga2/log.rb
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# log.rb, copyright (c) 2006, 2007, 2009 by Vincent Fourmond:
|
|
2
|
+
# The general logging functions for ctioga2
|
|
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 (in the COPYING file).
|
|
13
|
+
|
|
14
|
+
require 'ctioga2/utils'
|
|
15
|
+
require 'logger'
|
|
16
|
+
|
|
17
|
+
module CTioga2
|
|
18
|
+
|
|
19
|
+
Version::register_svn_info('$Revision: 90 $', '$Date: 2009-06-22 23:28:01 +0200 (Mon, 22 Jun 2009) $')
|
|
20
|
+
|
|
21
|
+
# This module should be included (or extended) by every class that
|
|
22
|
+
# need logging/debugging facilities.
|
|
23
|
+
module Log
|
|
24
|
+
|
|
25
|
+
# Prints a debug message, on channel _channel_. Channel handling
|
|
26
|
+
# is not implemented yet.
|
|
27
|
+
def debug(message, channel = nil)
|
|
28
|
+
@@logger.debug(message)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Prints a warning message
|
|
32
|
+
def warn(message)
|
|
33
|
+
@@logger.warn(message)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Prints an informational message
|
|
37
|
+
def info(message)
|
|
38
|
+
@@logger.info(message)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Prints an error message
|
|
42
|
+
def error(message)
|
|
43
|
+
@@logger.error(message)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Prints a fatal error message and initiates program termination.
|
|
47
|
+
def fatal(message)
|
|
48
|
+
@@logger.fatal(message)
|
|
49
|
+
exit 1 # Fatal error.
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# These are module functions:
|
|
53
|
+
module_function :error, :debug, :warn, :info, :fatal
|
|
54
|
+
|
|
55
|
+
# Format an exception for displaying
|
|
56
|
+
def format_exception(e)
|
|
57
|
+
return "#{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.init_logger(stream = STDERR)
|
|
61
|
+
Logger::Formatter::Format.replace("[%4$s] %6$s\n")
|
|
62
|
+
@@logger = Logger.new(stream)
|
|
63
|
+
@@logger.level = Logger::WARN # Warnings and more only by default
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Simple accessor for the @@log class variable.
|
|
67
|
+
def self.logger
|
|
68
|
+
return @@logger
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Sets the logging level.
|
|
72
|
+
def self.set_level(level = Logger::WARN)
|
|
73
|
+
@@logger.level = level
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# A logged replacement for system
|
|
77
|
+
def spawn(cmd, priority = :info)
|
|
78
|
+
retval = system(cmd)
|
|
79
|
+
self.send(priority, "Spawned #{cmd} -> " +
|
|
80
|
+
if retval
|
|
81
|
+
"success"
|
|
82
|
+
else
|
|
83
|
+
"failure"
|
|
84
|
+
end
|
|
85
|
+
)
|
|
86
|
+
return retval
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Returns a string suitable for identification of an object, a bit
|
|
90
|
+
# in the spirit of #inspect, but without displaying instance
|
|
91
|
+
# variables.
|
|
92
|
+
def identify(obj)
|
|
93
|
+
return "#<%s 0x%x>" % [obj.class, obj.object_id]
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
end
|
|
97
|
+
end
|