~ubuntu-branches/ubuntu/oneiric/ctioga2/oneiric

« back to all changes in this revision

Viewing changes to lib/ctioga2/graphics/elements/element.rb

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-01-24 21:36:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110124213606-9ettx0ugl83z0bzp
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# element.rb: base class of all drawable elements
 
2
# copyright (c) 2006, 2007, 2008, 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
 
 
15
require 'ctioga2/utils'
 
16
require 'ctioga2/log'
 
17
 
 
18
# This module contains all the classes used by ctioga
 
19
module CTioga2
 
20
 
 
21
  Version::register_svn_info('$Revision: 151 $', '$Date: 2010-06-19 23:45:20 +0200 (Sat, 19 Jun 2010) $')
 
22
 
 
23
  # This module contains all graphical elements of CTioga2
 
24
  module Graphics
 
25
 
 
26
    # All elements that can be drawn onto a FigureMaker object
 
27
    module Elements
 
28
      
 
29
      # The base class for every single object that is drawn on
 
30
      # Tioga's output.
 
31
      class TiogaElement
 
32
        include Log
 
33
 
 
34
        # The parent Container.
 
35
        attr_accessor :parent
 
36
 
 
37
        # Details pertaining to the location of the object, as a
 
38
        # LocationStyle object
 
39
        attr_writer :location
 
40
 
 
41
        # Makes sure there is a location when one asks for it.
 
42
        def location
 
43
          @location ||= Styles::LocationStyle.new
 
44
          return @location
 
45
        end
 
46
 
 
47
        # This function must be called with a FigureMaker object to
 
48
        # draw the contents of the TiogaElement onto it. It calls
 
49
        # #real_do, which should be redefined by the children. You can
 
50
        # redefine _do_ too if you need another debugging output.
 
51
        def do(f)
 
52
          debug { "plotting #{self.inspect}" }
 
53
          real_do(f)
 
54
        end
 
55
 
 
56
        # We plot everything but parent. If a prefix is given, it is prepended
 
57
        # to all lines but the first (for indentation)
 
58
        def inspect(prefix="")
 
59
          ret = "#<#{self.class.name}:\n"
 
60
          for i in instance_variables
 
61
            next if i == "@parent"
 
62
            var = instance_variable_get(i)
 
63
            ret += "#{prefix}  - #{i} -> "
 
64
            if var.is_a? TiogaElement
 
65
              ret += "#{var.inspect("#{prefix}  ")}\n"
 
66
            else
 
67
              ret += "#{var.inspect}\n"
 
68
            end
 
69
          end
 
70
          ret += "#{prefix}>"
 
71
          return ret
 
72
        end
 
73
 
 
74
        protected
 
75
        
 
76
        def real_do(t)
 
77
          raise "Should be reimplemented by children"
 
78
        end
 
79
      end 
 
80
      
 
81
 
 
82
#       # A unique method call to a FigureMaker object.
 
83
#       class TiogaFuncall < TiogaElement
 
84
 
 
85
#         # _symbol_ is the symbol to be called, and the remainder will
 
86
#         # be used as arguments for the call.
 
87
#         def initialize(symbol, *args)
 
88
#           @symbol = symbol
 
89
#           @args = args
 
90
#         end
 
91
 
 
92
#         protected
 
93
        
 
94
#         def real_do(f)
 
95
#           f.send(@symbol, *@args)
 
96
#         end
 
97
#       end
 
98
    end
 
99
  end
 
100
end