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