1
# region.rb: draw curves-delimited fills
2
# copyright (c) 2010 by Vincent Fourmond
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.
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).
15
require 'ctioga2/utils'
20
Version::register_svn_info('$Revision: 139 $', '$Date: 2010-01-22 00:12:17 +0100 (Fri, 22 Jan 2010) $')
26
# A Region is an object that draws filled regions among its
27
# "elements". It is a fake container in the sense that all the
28
# elements are actually forwarded to the parent.
29
class Region < Container
34
# The curves which delimit the region
38
attr_accessor :fill_style
40
# The fill style for reversed polarity
41
attr_accessor :reversed_fill_style
43
# Creates a new empty region
44
def initialize(parent = nil, root = nil)
47
# elements to be given to tioga
54
@fill_style = Styles::FillStyle.new
55
@fill_style.color = [0.7,0.7,0.7]
57
# For reversed polarity
58
@reversed_fill_style = Styles::FillStyle.new
61
# Adds an element. Actually forwards it to the parent.
62
def add_element(element)
63
parent.add_element(element)
64
if element.respond_to?(:curve_style) &&
65
element.curve_style.region_position
70
# Sets the various things from hash.
71
def set_from_hash(hash)
72
@fill_style.set_from_hash(hash)
73
# Reversed isn't what I want...
74
@reversed_fill_style.set_from_hash(hash, 'reversed_%s')
77
# Redirects to the parent's style
79
return parent.style(*a)
84
# Creates the appropriate subfigure and draws all its elements
87
# \todo: attempt to work fine while mixing curves with
88
# different axes. That won't be easy.
90
# \todo: enable to do positive and negative. The only thing to
91
# do is to swap above for below and call again.
93
# This function will be called with the proper figure
98
@fill_style.setup_fill(t)
100
@fill_style.do_fill(t)
104
if @reversed_fill_style.color
106
@reversed_fill_style.setup_fill(t)
107
prepare_path(t, :reversed)
108
@reversed_fill_style.do_fill(t)
114
# Prepares the path that will be filled, according to the
116
def prepare_path(t, polarity = :normal)
117
# We clip the path for the given
130
# We clip for the first ones...
131
for c in @curves[0..-2]
132
c.make_closed_path(t, conversion[c.curve_style.region_position])
135
# We don't clip on the last one !
137
c.make_closed_path(t, conversion[c.curve_style.region_position])