]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-axis-group.cc
release: 1.2.12
[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, Axis a1 , Axis a2)
46 {
47   used_b_ =true;
48   e->used_b_ = true;
49
50   Axis as[2] = {
51     (a1 == NO_AXES) ? axes_[0] : a1,
52     (a2 == NO_AXES) ? axes_[1] : a2,    
53   };
54
55     
56   
57   for (int i = 0; i < 2; i++)
58     {
59       if (e->parent_l (as[i]))
60         continue;
61       
62       e->set_parent (this, as[i]);
63
64       e->dim_cache_[as[i]]->dependencies_l_arr_.push (dim_cache_[as[i]]);
65     }
66   assert (e->parent_l(Y_AXIS) == this || e->parent_l (X_AXIS) == this);
67   elem_l_arr_.push (e);
68 }
69
70
71 /**
72    ugr. duplication of functionality with remove_all ()
73  */
74 void
75 Graphical_axis_group::remove_element (Graphical_element*e)
76 {
77   assert (contains_b (e));
78   if (ordered_b_)
79     elem_l_arr_.substitute (e,0);
80   else
81     elem_l_arr_.unordered_substitute (e,0);
82
83   do_remove (e);
84 }
85
86 void
87 Graphical_axis_group::do_remove (Graphical_element *e)
88 {
89   for (int i=0; i<  2; i++)
90     {
91       Axis a=axes_[i];
92       if (e->parent_l (a) != this)
93         continue;
94       e->set_parent (0, a);
95       e->dim_cache_[a]->dependencies_l_arr_.clear ();
96     }
97 }
98
99 void
100 Graphical_axis_group::remove_all ()
101 {
102   for (int i=0; i < elem_l_arr_.size(); i++) 
103     do_remove (elem_l_arr_[i]);
104
105   elem_l_arr_.clear ();
106 }
107
108
109 void    
110 Graphical_axis_group::do_print() const
111 {
112 #ifndef NPRINT
113   for (int i=0; i < elem_l_arr_.size(); i++) 
114     DEBUG_OUT << classname(elem_l_arr_[i]) << " ";
115 #endif
116 }
117
118 Graphical_axis_group::Graphical_axis_group ()
119 {
120   ordered_b_ = false;
121   axes_[0] = (Axis)-1 ; 
122   axes_[1] = (Axis)-1 ;
123 }
124
125 void
126 Graphical_axis_group::set_axes (Axis a1, Axis a2)
127 {
128   axes_[0] = a1 ; 
129   axes_[1] = a2 ;
130 }