]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-axis-group.cc
release: 1.2.4
[lilypond.git] / lily / graphical-axis-group.cc
1 /*
2   axis-group.cc -- implement Graphical_axis_group
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "dimension-cache.hh"
10 #include "interval.hh"
11 #include "graphical-axis-group.hh"
12 #include "axis-group-element.hh"
13 #include "graphical-element.hh"
14 #include "debug.hh"
15
16 /** don't copy anything: an element can only be in one
17   Graphical_axis_group at one time. */
18 Graphical_axis_group::Graphical_axis_group(Graphical_axis_group const&s)
19 {
20   axes_[0] = s.axes_[0];
21   axes_[1] = s.axes_[1];
22   ordered_b_ = s.ordered_b_;
23 }
24
25 bool 
26 Graphical_axis_group::contains_b (Graphical_element const *e) const
27 {
28   return elem_l_arr_.find_l (e);
29 }
30
31 Interval
32 Graphical_axis_group::extent (Axis axis) const
33 {
34   Interval r;
35   for (int i=0; i < elem_l_arr_.size(); i++)
36     {
37       r.unite (elem_l_arr_[i]->extent (axis)
38                + elem_l_arr_[i]->relative_coordinate (this, axis)
39                );
40     }
41   return r;
42 }
43
44 void
45 Graphical_axis_group::add_element (Graphical_element*e)
46 {
47   used_b_ =true;
48   e->used_b_ = true;
49   for (int i = 0; i < 2; i++)
50     {
51       Axis a = axes_[i];
52       assert (a>=0);
53       assert (!e->parent_l (a)  || this  == e->parent_l (a));
54       e->set_parent (this, a);
55
56       e->dim_cache_[a]->dependencies_l_arr_.push (dim_cache_[a]);
57     }
58
59   elem_l_arr_.push (e);
60 }
61
62
63
64 void
65 Graphical_axis_group::remove_element (Graphical_element*e)
66 {
67   assert (contains_b (e));
68   if (ordered_b_)
69     elem_l_arr_.substitute (e,0);
70   else
71     elem_l_arr_.unordered_substitute (e,0);
72   
73   for (int i=0; i<  2; i++)
74     {
75       Axis a=axes_[i];
76       Dimension_cache * d = e->dim_cache_[a];
77       d->parent_l_ = 0;
78       d->dependencies_l_arr_.unordered_substitute (dim_cache_[a], 0);
79     }
80 }
81
82 void
83 Graphical_axis_group::remove_all ()
84 {
85   for (int i=0; i < elem_l_arr_.size(); i++) 
86     {
87       Graphical_element*e=elem_l_arr_[i];
88       for (int i=0; i<  2; i++)
89         {
90           Axis a=axes_[i];
91           Dimension_cache * d = e->dim_cache_[a];
92           d->parent_l_ = 0;
93           d->dependencies_l_arr_.clear ();
94         }
95       
96     }
97   elem_l_arr_.clear ();
98 }
99
100
101 void    
102 Graphical_axis_group::do_print() const
103 {
104 #ifndef NPRINT
105   for (int i=0; i < elem_l_arr_.size(); i++) 
106     DOUT << classname(elem_l_arr_[i]) << " ";
107 #endif
108 }
109
110 Graphical_axis_group::Graphical_axis_group ()
111 {
112   ordered_b_ = false;
113   axes_[0] = (Axis)-1 ; 
114   axes_[1] = (Axis)-1 ;
115 }
116
117 void
118 Graphical_axis_group::set_axes (Axis a1, Axis a2)
119 {
120   axes_[0] = a1 ; 
121   axes_[1] = a2 ;
122 }