File: debug.rb

package info (click to toggle)
ctioga 1.10-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,052 kB
  • ctags: 953
  • sloc: ruby: 9,306; sh: 504; makefile: 6
file content (199 lines) | stat: -rw-r--r-- 7,567 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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
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
163
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
191
192
193
194
195
196
197
198
199
# debug.rb, copyright (c) 2006 by Vincent Fourmond: 
# The debugging functions for PlotMaker
  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
  
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details (in the COPYING file).

require 'CTioga/log'


module CTioga

  Version::register_svn_info('$Revision: 653 $', '$Date: 2007-11-15 21:58:42 +0100 (Thu, 15 Nov 2007) $')

  # This module contains code to be included by PlotMaker for debugging.
  # Even if it doesn't deserve a real module of it's own, it makes sense
  # to have it separated anyway.
  module Debug

    include Tioga::FigureConstants
    include Log

    # These variables are scoped at the module level so
    # that they are shared among all bits of code - as they can only be
    # set in one place.
    @@debug = false
    @@debug_indent = 0
    @@debug_indent_string = "  "

    # The function to use to display debugging information.
    # Checks if we are in debug mode.
    def debug_puts(str)
      if @@debug
        debug @@debug_indent_string * @@debug_indent +
          str
      end
    end

    # A function using the hooks defined by Bill to display what is
    # happenning inside Tioga
    def debug_figmaker(t)
      t.def_enter_context_function { 
        debug_puts "Tioga: enter new context\t" + 
        frames_str(t)
        @@debug_indent += 1
      }
      t.def_exit_context_function { 
        @@debug_indent -=1
        debug_puts "Tioga: exit context\t" + frames_str(t)
      }
        
      t.def_enter_show_plot_function { |bounds| 
        debug_puts "Tioga: enter show_plot #{bounds[0]} #{bounds[1]} " +
        "#{bounds[2]} #{bounds[3]}" 
        @@debug_indent += 1
      }
        
      t.def_exit_show_plot_function { |bounds| 
        @@debug_indent -=1
        debug_puts "Tioga: exit show_plot #{bounds[0]} #{bounds[1]} " +
        "#{bounds[2]} #{bounds[3]}" 
      }
        
      t.def_enter_subfigure_function { |margins| 
        debug_puts "Tioga: enter subfigure #{margins[0]} #{margins[1]} " +
        "#{margins[2]} #{margins[3]}" 
        debug_puts "Tioga: frames " + frames_str(t)
      }
        
      t.def_enter_subplot_function { |margins| 
        debug_puts "Tioga: enter subplot #{margins[0]} #{margins[1]} " +
        "#{margins[2]} #{margins[3]}" 
        debug_puts "Tioga: frames " + frames_str(t)
      }
    end

    def debug_patterns(t)
      t.def_figure('Test_patterns') { 
        setup_real_size_bop(t)
        test_pattern(t) 
      }
      t.make_preview_pdf(t.figure_index('Test_patterns'))

      t.def_figure('Test_patterns_right') { 
        setup_real_size_bop(t)
        test_pattern_right(t) 
      }
      t.make_preview_pdf(t.figure_index('Test_patterns_right'))
    end

    # This function is taken from Tioga; it is used to check the alignements
    # of the TeX text and PDF image.
    def test_pattern(t)
      t.line_width = 1
      t.stroke_frame
      # we make it asymmetric to catch other kinds of problems
      t.set_subframe('left' => 0.1 , 'right' => 0.05,
                     'top' => 0.05, 'bottom' => 0.1)
      centerx = t.bounds_xmin + 0.5 * t.bounds_width
      chr_ht = t.default_text_height_dy
      t.stroke_color = Red
      t.line_width = 0.2
      t.stroke_line(t.bounds_xmax, t.bounds_ymin, t.bounds_xmax, t.bounds_ymax)
      t.stroke_line(centerx, t.bounds_ymin, centerx, t.bounds_ymax)
      t.stroke_line(t.bounds_xmin, t.bounds_ymin, t.bounds_xmin, t.bounds_ymax)
      y = t.bounds_ymin; dy = t.bounds_height / 10
      scale = 0.85;
      10.times do
        t.stroke_line(t.bounds_xmin, y, t.bounds_xmax, y)
        t.show_text('text'=>"Left", 'x'=> t.bounds_xmin, 'y' => y,
                    'scale'=>0.5+scale, 'justification' => LEFT_JUSTIFIED)
        t.show_text('text'=>"Center", 'x'=> centerx, 'y' => y,
                    'scale'=>1.8-scale, 'justification' => CENTERED)
        t.show_text('text'=>"Right", 'x'=> t.bounds_xmax, 'y' => y,
                    'scale'=>0.5+scale, 'justification' => RIGHT_JUSTIFIED)
        scale = scale - 0.1
        y = y + dy
      end 
      t.stroke_line(t.bounds_xmin, t.bounds_ymax, t.bounds_xmax, t.bounds_ymax)
      t.justification = CENTERED
      t.show_text('text'=>"TeX and PDF Alignment Test Pattern",
                  'side'=> TOP, 'pos' => 0.5, 'shift'=>0.3)
      t.show_text('text'=>"Check for Proper Registration of Text and Graphics",
                  'side'=>BOTTOM, 'pos' => 0.5, 'shift'=> 1.6, 'scale'=>0.4)
      t.show_text(
                  'text'=>'If needed, adjust by changing ' + 
                  '{\sffamily FigureMaker.tex\_xoffset} ' +
                  'and {\sffamily FigureMaker.tex\_yoffset}.',
                  'side'=>BOTTOM, 'pos' => 0.5, 'shift'=> 3.9, 'scale'=>0.3)
    end

    # This function is taken from Tioga; it is used to check the alignements
    # of the TeX text and PDF image.
    def test_pattern_right(t)
      t.line_width = 1
#       t.stroke_frame
      margin = 0.1
      # we make it asymmetric to catch other kinds of problems
      t.set_subframe('left' => 0.1 , 'right' => 0.05,
                     'top' => 0.05, 'bottom' => 0.1)
      centerx = t.bounds_xmin + 0.5 * t.bounds_width
      chr_ht = t.default_text_height_dy
      t.stroke_color = Red
      t.line_width = 1
      t.stroke_line(t.bounds_xmax, t.bounds_ymin, t.bounds_xmax, t.bounds_ymax)
      t.stroke_line(centerx, t.bounds_ymin, centerx, t.bounds_ymax)

      y = t.bounds_ymin; dy = t.bounds_height / 10
      scale = 0.85;
      10.times do
        t.stroke_line(centerx, y, t.bounds_xmax, y)
        t.show_text('text'=>"Left", 'x'=> t.bounds_xmin, 'y' => y,
                    'scale'=>0.5+scale, 'justification' => LEFT_JUSTIFIED)
        t.show_text('text'=>"Center", 'x'=> centerx, 'y' => y,
                    'scale'=>1.8-scale, 'justification' => CENTERED)
        t.show_text('text'=>"Right", 'x'=> t.bounds_xmax, 'y' => y,
                    'scale'=>0.5+scale, 'justification' => RIGHT_JUSTIFIED)
        scale = scale - 0.1
        y = y + dy
      end 
      t.stroke_line(centerx, t.bounds_ymax, t.bounds_xmax, t.bounds_ymax)
      t.justification = CENTERED
      t.show_text('text'=>"TeX and PDF Alignment Test Pattern",
                  'side'=> TOP, 'pos' => 0.5, 'shift'=>0.3)
      t.show_text('text'=>"Check for Proper Registration of Text and Graphics",
                  'side'=>BOTTOM, 'pos' => 0.5, 'shift'=> 1.6, 'scale'=>0.4)
      t.show_text(
                  'text'=>'If needed, adjust by changing ' + 
                  '{\sffamily FigureMaker.tex\_xoffset} ' +
                  'and {\sffamily FigureMaker.tex\_yoffset}.',
                  'side'=>BOTTOM, 'pos' => 0.5, 'shift'=> 3.9, 'scale'=>0.3)
    end

    # Returns a string representing the 'options' of the FigureMaker object
    # given.
    def figmaker_options(t)
      return '' unless @@debug
      s = ""
      for meth in t.methods.sort
        if t.respond_to?((meth + '=').to_sym)
          begin
            s += "\n#{meth}: " + t.send(meth).to_s
          rescue
            # In case the method did need some arguments...
          end
        end
      end
      return s
    end

  end

end