]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-axis-group.cc
c6a6137d3c776a5c7c77ceca1429d1e8c9d1a630
[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 #include "interval.hh"
9 #include "graphical-axis-group.hh"
10 #include "axis-group-element.hh"
11 #include "graphical-element.hh"
12 #include "debug.hh"
13
14 /** don't copy anything: an element can only be in one
15   Graphical_axis_group at one time.  */
16 Graphical_axis_group::Graphical_axis_group (Graphical_axis_group const&s)
17 {
18   axes_[0] = s.axes_[0];
19   axes_[1] = s.axes_[1];
20 }
21
22 bool 
23 Graphical_axis_group::contains_b (Graphical_element const *e) const
24 {
25   return elem_l_arr_.find_l (e);
26 }
27
28 Interval
29 Graphical_axis_group::extent (Axis axis) const
30 {
31   Interval r;
32   for (int i=0; i < elem_l_arr_.size(); i++) 
33     r.unite (elem_l_arr_[i]->extent (axis));
34   return r;
35 }
36
37 void
38 Graphical_axis_group::add_element (Graphical_element*e)
39 {
40   used_b_ =true;
41   e->used_b_ = true;
42   for (int i = 0; i < 2; i++)
43     {
44       Axis a = axes_[i];
45       Dimension_cache * &d = e->dim_cache_[a].parent_l_;
46       assert (!d || d == &dim_cache_[a]);
47       d = &dim_cache_[a];
48       d->dependencies_l_arr_.push (&dim_cache_[a]);
49     }
50
51   elem_l_arr_.push (e);
52 }
53
54
55
56 void
57 Graphical_axis_group::remove_element (Graphical_element*e)
58 {
59   assert (contains_b (e));
60   elem_l_arr_.unordered_substitute (e,0);
61   
62   for (int i=0; i<  2; i++)
63     {
64       Axis a=axes_[i];
65       Dimension_cache * d = &e->dim_cache_[a];
66       d->parent_l_ = 0;
67       d->dependencies_l_arr_.unordered_substitute (&dim_cache_[a], 0);
68     }
69 }
70
71 void
72 Graphical_axis_group::remove_all ()
73 {
74   for (int i=0; i < elem_l_arr_.size(); i++) 
75     {
76       Graphical_element*e=elem_l_arr_[i];
77       for (int i=0; i<  2; i++)
78         {
79           Axis a=axes_[i];
80           Dimension_cache * d = &e->dim_cache_[a];
81           d->parent_l_ = 0;
82           d->dependencies_l_arr_.clear ();
83         }
84       
85     }
86   elem_l_arr_.clear ();
87 }
88
89
90 void    
91 Graphical_axis_group::do_print() const
92 {
93 #ifndef NPRINT
94   for (int i=0; i < elem_l_arr_.size(); i++) 
95     DOUT << classname(elem_l_arr_[i]) << " ";
96 #endif
97 }
98
99 Graphical_axis_group::Graphical_axis_group (Axis a1, Axis a2)
100 {
101   axes_[0] = a1;
102   axes_[1] = a2;
103 }
104
105