lilypond-1.5.9
[lilypond.git] / lily / graphical-axis-group.cc
blobe0cfcaf1ef5f7deb2102de7213303bdf5059226a
1 /*
2 axis-group.cc -- implement Graphical_axis_group
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
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"
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)
20 axes_[0] = s.axes_[0];
21 axes_[1] = s.axes_[1];
22 ordered_b_ = s.ordered_b_;
25 bool
26 Graphical_axis_group::contains_b (Graphical_element const *e) const
28 return elem_l_arr_.find_l (e);
31 Interval
32 Graphical_axis_group::extent (Axis axis) const
34 Interval r;
35 for (int i=0; i < elem_l_arr_.size(); i++)
37 r.unite (elem_l_arr_[i]->extent (axis)
38 + elem_l_arr_[i]->relative_coordinate (this, axis)
41 return r;
44 void
45 Graphical_axis_group::add_element (Graphical_element*e, Axis a1 , Axis a2)
47 used_b_ =true;
48 e->used_b_ = true;
50 Axis as[2] = {
51 (a1 == NO_AXES) ? axes_[0] : a1,
52 (a2 == NO_AXES) ? axes_[1] : a2,
57 for (int i = 0; i < 2; i++)
59 if (e->parent_l (as[i]))
60 continue;
62 e->set_parent (this, as[i]);
64 // e->dim_cache_[as[i]]->dependencies_l_arr_.push (dim_cache_[as[i]]);
66 assert (e->parent_l(Y_AXIS) == this || e->parent_l (X_AXIS) == this);
67 elem_l_arr_.push (e);
71 /**
72 ugr. duplication of functionality with remove_all ()
74 void
75 Graphical_axis_group::remove_element (Graphical_element*e)
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);
83 do_remove (e);
86 void
87 Graphical_axis_group::do_remove (Graphical_element *e)
89 for (int i=0; i< 2; i++)
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 ();
99 void
100 Graphical_axis_group::remove_all ()
102 for (int i=0; i < elem_l_arr_.size(); i++)
103 do_remove (elem_l_arr_[i]);
105 elem_l_arr_.clear ();
109 void
110 Graphical_axis_group::do_print() const
112 #ifndef NPRINT
113 for (int i=0; i < elem_l_arr_.size(); i++)
114 DEBUG_OUT << classname(elem_l_arr_[i]) << " ";
115 #endif
118 Graphical_axis_group::Graphical_axis_group ()
120 ordered_b_ = false;
121 axes_[0] = (Axis)-1 ;
122 axes_[1] = (Axis)-1 ;
125 void
126 Graphical_axis_group::set_axes (Axis a1, Axis a2)
128 axes_[0] = a1 ;
129 axes_[1] = a2 ;