]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-axis-group.cc
6beccc696110c5ddedd434eca97c58d1df5e6d5e
[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 #if 0
21   /*
22   gcc-2.95: huh? why can't i assign a const value to a var?
23   graphical-axis-group.cc:20: incompatible types in assignment of `const Axis[2]' to `Axis[2]'
24   */
25   axes_ = s.axes_;
26 #else
27   axes_[0] = s.axes_[0];
28   axes_[1] = s.axes_[1];
29 #endif 
30   ordered_b_ = s.ordered_b_;
31 }
32
33 bool 
34 Graphical_axis_group::contains_b (Graphical_element const *e) const
35 {
36   return elem_l_arr_.find_l (e);
37 }
38
39 Interval
40 Graphical_axis_group::extent (Axis axis) const
41 {
42   Interval r;
43   for (int i=0; i < elem_l_arr_.size(); i++) 
44     r.unite (elem_l_arr_[i]->extent (axis));
45   return r;
46 }
47
48 void
49 Graphical_axis_group::add_element (Graphical_element*e)
50 {
51   used_b_ =true;
52   e->used_b_ = true;
53   for (int i = 0; i < 2; i++)
54     {
55       Axis a = axes_[i];
56       assert (a>=0);
57       Dimension_cache * &d = e->dim_cache_[a]->parent_l_;
58       assert (!d || d == dim_cache_[a]);
59       d = dim_cache_[a];
60       d->dependencies_l_arr_.push (dim_cache_[a]);
61     }
62
63   elem_l_arr_.push (e);
64 }
65
66
67
68 void
69 Graphical_axis_group::remove_element (Graphical_element*e)
70 {
71   assert (contains_b (e));
72   if (ordered_b_)
73     elem_l_arr_.substitute (e,0);
74   else
75     elem_l_arr_.unordered_substitute (e,0);
76   
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_.unordered_substitute (dim_cache_[a], 0);
83     }
84 }
85
86 void
87 Graphical_axis_group::remove_all ()
88 {
89   for (int i=0; i < elem_l_arr_.size(); i++) 
90     {
91       Graphical_element*e=elem_l_arr_[i];
92       for (int i=0; i<  2; i++)
93         {
94           Axis a=axes_[i];
95           Dimension_cache * d = e->dim_cache_[a];
96           d->parent_l_ = 0;
97           d->dependencies_l_arr_.clear ();
98         }
99       
100     }
101   elem_l_arr_.clear ();
102 }
103
104
105 void    
106 Graphical_axis_group::do_print() const
107 {
108 #ifndef NPRINT
109   for (int i=0; i < elem_l_arr_.size(); i++) 
110     DOUT << classname(elem_l_arr_[i]) << " ";
111 #endif
112 }
113
114 Graphical_axis_group::Graphical_axis_group ()
115 {
116   ordered_b_ = false;
117   axes_[0] = (Axis)-1 ; 
118   axes_[1] = (Axis)-1 ;
119 }
120
121 void
122 Graphical_axis_group::set_axes (Axis a1, Axis a2)
123 {
124   axes_[0] = a1 ; 
125   axes_[1] = a2 ;
126 }