]> git.donarmstrong.com Git - lilypond.git/blob - lily/graphical-axis-group.cc
release: 1.0.1
[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--1998 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   axis1_ = s.axis1_;
19   axis2_ = s.axis2_;
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   Graphical_axis_group *& g1 = e->axis_group_l_a_[axis1_];
41   Graphical_axis_group *& g2 = e->axis_group_l_a_[axis2_];
42   
43   assert (!g1 || g1 == this);
44   assert (!g2 || g2 == this);
45   g1 = this;
46   g2 = this;
47   elem_l_arr_.push (e);
48 }
49
50
51
52 void
53 Graphical_axis_group::remove_element (Graphical_element*e)
54 {
55   assert (contains_b (e));
56   elem_l_arr_.unordered_substitute (e,0);
57   
58   e->axis_group_l_a_[axis1_] = 0;
59   e->axis_group_l_a_[axis2_] = 0;    
60 }
61
62 void
63 Graphical_axis_group::remove_all ()
64 {
65   for (int i=0; i < elem_l_arr_.size(); i++) 
66     {
67       Graphical_element*e=elem_l_arr_[i];
68       e->axis_group_l_a_[axis1_] = 0;
69       e->axis_group_l_a_[axis2_] = 0;  
70     }
71   elem_l_arr_.clear ();
72 }
73
74
75 void    
76 Graphical_axis_group::do_print() const
77 {
78 #ifndef NPRINT
79   for (int i=0; i < elem_l_arr_.size(); i++) 
80     DOUT << elem_l_arr_[i]->name () << " ";
81 #endif
82 }
83
84 Graphical_axis_group::Graphical_axis_group (Axis a1, Axis a2)
85 {
86   axis1_ =a1;
87   axis2_ = a2;
88 }
89
90 IMPLEMENT_IS_TYPE_B1(Graphical_axis_group, Graphical_element);