]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-element.cc
release: 1.1.67
[lilypond.git] / lily / axis-group-element.cc
1 /*
2   axis-group-element.cc -- implement Axis_group_element
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 "axis-group-element.hh"
10 #include "graphical-axis-group.hh"
11 #include "dimension-cache.hh"
12
13 Link_array<Score_element>
14 Axis_group_element::get_extra_dependencies() const
15 {
16   Link_array<Score_element> e(elem_l_arr ());
17   return e;
18 }
19
20 Link_array<Score_element>
21 Axis_group_element::elem_l_arr () const
22 {  
23   /*
24     ugh. I know
25   */
26   Link_array<Score_element> r;
27   for (int i=0; i < elem_l_arr_.size (); i++)
28     r.push (dynamic_cast<Score_element*>(elem_l_arr_[i]));
29       
30   return r;
31 }
32
33 Link_array<Score_element> 
34 Axis_group_element::get_children ()
35 {
36   Link_array<Score_element> childs;
37   Link_array<Score_element> elems = elem_l_arr ();
38   elems.concat (extra_elems_ );
39   for (int i=0; i < elems.size (); i++) 
40     {
41       Score_element* e = elems[i];
42       childs.push (e) ;
43       Axis_group_element * axis_group= dynamic_cast <Axis_group_element *> (e);
44       if (axis_group)
45         childs.concat (axis_group->get_children ());      
46     }
47   
48   return childs;
49 }
50
51 void
52 Axis_group_element::do_print() const
53 {
54   Graphical_axis_group::do_print();
55 }
56
57 Axis_group_element::Axis_group_element()
58 {
59   set_elt_property (transparent_scm_sym, SCM_BOOL_T);
60 }
61
62 void
63 Axis_group_element::set_axes (Axis a1, Axis a2)
64 {
65   Graphical_axis_group::set_axes (a1,a2);
66   dim_cache_[X_AXIS]->set_empty ((a1 != X_AXIS && a2 != X_AXIS));
67   dim_cache_[Y_AXIS]->set_empty ((a1 != Y_AXIS && a2 != Y_AXIS));
68 }
69
70
71 void
72 Axis_group_element::do_substitute_element_pointer (Score_element*o,
73                                                    Score_element*n)
74 {
75   int i;
76   Graphical_element * go = o;
77   Graphical_element * gn = n;  
78   
79   while ((i = elem_l_arr_.find_i (go))>=0)
80     elem_l_arr_.substitute (go,gn);
81
82   extra_elems_.substitute (o, n);
83 }
84
85 Interval
86 Axis_group_element::extra_extent (Axis a )const
87 {
88   Interval g;
89   purge_extra ();               // Yeah yeah,  const correctness.
90   for (int i=0;  i < extra_elems_.size (); i++)
91     {
92       Interval ge = extra_elems_[i]->extent (a);
93       ge += extra_elems_[i]->relative_coordinate (dim_cache_[a], a);
94       g.unite (ge);
95     }
96   return g;
97 }
98
99 Interval
100 Axis_group_element::do_height () const
101 {
102   Interval gag = Graphical_axis_group::extent (Y_AXIS);
103   gag.unite (extra_extent (Y_AXIS));
104   return gag;
105 }
106
107 Interval
108 Axis_group_element::do_width () const
109 {
110   Interval gag = Graphical_axis_group::extent (X_AXIS);
111   gag.unite (extra_extent (X_AXIS));
112   return gag;
113 }
114
115
116 /*
117   UGH.
118  */
119 void
120 Axis_group_element::add_extra_element (Score_element *e)
121 {
122   Link_array<Score_element> se;
123   while (e && e != this)
124     {
125       se.push (e);
126       e = dynamic_cast<Score_element*> (e->parent_l (Y_AXIS));
127     }
128
129   if (1)                        // e == this)
130     {
131       for (int i=0; i < se.size( ); i++) 
132         {
133           extra_elems_.push (se[i]);
134           add_dependency (se[i]);
135           se[i]->set_elt_property (ly_symbol ("Axis_group_element::add_extra_element"), SCM_BOOL_T); // UGH GUH.
136         }
137       
138     }
139 }
140
141 /*
142   UGH GUH
143  */
144 void
145 Axis_group_element::purge_extra ()
146 {
147   for (int i=0; i < extra_elems_.size ();)
148     {
149       Score_element *e = extra_elems_[i];
150       while (e && e != this)
151         {
152           e = dynamic_cast<Score_element*> (e->parent_l (Y_AXIS));
153         }
154       if (e != this)
155         extra_elems_.del (i);
156       else
157         i++;
158     }
159 }