]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-engraver.cc
2796f05ca4272ac18134954e6fea6c42ec9ea4b3
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "axis-group-engraver.hh"
10
11 #include "spanner.hh"
12 #include "axis-group-interface.hh"
13 #include "warn.hh"
14 #include "context.hh"
15
16 #include "translator.icc"
17
18 Axis_group_engraver::Axis_group_engraver ()
19 {
20   must_be_last_ = true;
21   staffline_ = 0;
22 }
23
24 void
25 Axis_group_engraver::process_music ()
26 {
27   if (!staffline_)
28     {
29       staffline_ = get_spanner ();
30       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
31       staffline_->set_bound (LEFT, it);
32     }
33 }
34
35 Spanner *
36 Axis_group_engraver::get_spanner ()
37 {
38   return make_spanner ("VerticalAxisGroup", SCM_EOL);
39 }
40
41 /*
42   TODO: should we junk minimumVerticalExtent/extraVerticalExtent ?
43 */
44
45 void
46 Axis_group_engraver::finalize ()
47 {
48   if (staffline_)
49     {
50       Grob *it = unsmob_grob (get_property ("currentCommandColumn"));
51       staffline_->set_bound (RIGHT, it);
52     }
53 }
54
55 void
56 Axis_group_engraver::acknowledge_grob (Grob_info i)
57 {
58   elts_.push (i.grob ());
59 }
60
61 /*
62   maybe should check if our parent is set, because we now get a
63   cyclic parent relationship if we have two Axis_group_engravers in
64   the context.  */
65 void
66 Axis_group_engraver::process_acknowledged ()
67 {
68   if (!staffline_)
69     return;
70
71   for (int i = 0; i < elts_.size (); i++)
72     {
73       if (!unsmob_grob (elts_[i]->get_object ("axis-group-parent-Y")))
74         {
75           if (staffline_->get_parent (Y_AXIS)
76               && staffline_->get_parent (Y_AXIS) == elts_[i])
77             {
78               staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
79               staffline_->warning (_ ("are there two Axis_group_engravers?"));
80               staffline_->warning (_ ("removing this vertical group"));
81               staffline_->suicide ();
82               staffline_ = 0;
83               break;
84             }
85 #if 0 
86           else if (elts_[i]->is_empty (Y_AXIS))
87             {
88               /*
89                 We have to do _something_, otherwise staff objects will
90                 end up with System as parent.
91
92               */
93               elts_[i]->set_parent (staffline_, Y_AXIS);
94             }
95           else
96 #endif
97             add_element (elts_[i]);
98         }
99     }
100   elts_.clear ();
101 }
102
103 void
104 Axis_group_engraver::add_element (Grob *e)
105 {
106   Axis_group_interface::add_element (staffline_, e);
107 }
108
109 ADD_ACKNOWLEDGER (Axis_group_engraver, grob);
110
111 ADD_TRANSLATOR (Axis_group_engraver,
112                 /* doc */ "Group all objects created in this context in a VerticalAxisGroup spanner.",
113                 /* create */ "VerticalAxisGroup",
114                 /* accept */ "",
115                 /* read */ "verticalExtent minimumVerticalExtent extraVerticalExtent",
116                 /* write */ "");