]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-engraver.cc
7efe7b4874c54e2c7d9426ca2191743fb1d02ac6
[lilypond.git] / lily / axis-group-engraver.cc
1 /*
2   axis-group-engraver.cc -- implement Axis_group_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "axis-group-engraver.hh"
10
11 #include "axis-group-interface.hh"
12 #include "pointer-group-interface.hh"
13 #include "context.hh"
14 #include "international.hh"
15 #include "spanner.hh"
16 #include "warn.hh"
17
18 #include "translator.icc"
19
20 Axis_group_engraver::Axis_group_engraver ()
21 {
22   must_be_last_ = true;
23   staffline_ = 0;
24 }
25
26 void
27 Axis_group_engraver::process_music ()
28 {
29   if (!staffline_)
30     {
31       staffline_ = get_spanner ();
32       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
33       staffline_->set_bound (LEFT, it);
34     }
35 }
36
37 Spanner *
38 Axis_group_engraver::get_spanner ()
39 {
40   return make_spanner ("VerticalAxisGroup", SCM_EOL);
41 }
42
43 /*
44   TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?
45 */
46
47 void
48 Axis_group_engraver::finalize ()
49 {
50   if (staffline_)
51     {
52       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
53       staffline_->set_bound (RIGHT, it);
54
55       Pointer_group_interface::set_ordered (staffline_, ly_symbol2scm ("elements"), false);
56     }
57 }
58
59 void
60 Axis_group_engraver::acknowledge_grob (Grob_info i)
61 {
62   elts_.push_back (i.grob ());
63 }
64
65 /*
66   maybe should check if our parent is set, because we now get a
67   cyclic parent relationship if we have two Axis_group_engravers in
68   the context.  */
69 void
70 Axis_group_engraver::process_acknowledged ()
71 {
72   if (!staffline_)
73     return;
74
75   for (vsize i = 0; i < elts_.size (); i++)
76     {
77       if (!unsmob_grob (elts_[i]->get_object ("axis-group-parent-Y")))
78         {
79           if (staffline_->get_parent (Y_AXIS)
80               && staffline_->get_parent (Y_AXIS) == elts_[i])
81             {
82               staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
83               staffline_->warning (_ ("are there two Axis_group_engravers?"));
84               staffline_->warning (_ ("removing this vertical group"));
85               staffline_->suicide ();
86               staffline_ = 0;
87               break;
88             }
89           add_element (elts_[i]);
90         }
91     }
92   elts_.clear ();
93 }
94
95 void
96 Axis_group_engraver::add_element (Grob *e)
97 {
98   Axis_group_interface::add_element (staffline_, e);
99 }
100
101 ADD_ACKNOWLEDGER (Axis_group_engraver, grob);
102
103 ADD_TRANSLATOR (Axis_group_engraver,
104                 /* doc */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
105                 /* create */ "VerticalAxisGroup",
106                 /* accept */ "",
107                 /* read */
108                 "currentCommandColumn ",
109
110                 /* write */ "");