]> git.donarmstrong.com Git - lilypond.git/blob - lily/axis-group-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / axis-group-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21
22 #include "axis-group-interface.hh"
23 #include "hara-kiri-group-spanner.hh"
24 #include "pointer-group-interface.hh"
25 #include "context.hh"
26 #include "international.hh"
27 #include "spanner.hh"
28 #include "warn.hh"
29
30 #include "translator.icc"
31
32 using std::vector;
33
34 /**
35    Put stuff in a Spanner with an Axis_group_interface.
36    Use as last element of a context.
37 */
38 class Axis_group_engraver : public Engraver
39 {
40 protected:
41   bool active_;
42   Spanner *staffline_;
43   SCM interesting_;
44   vector<Grob *> elts_;
45   void process_music ();
46   virtual void initialize ();
47   virtual void finalize ();
48   DECLARE_ACKNOWLEDGER (grob);
49   void process_acknowledged ();
50   virtual Spanner *get_spanner ();
51   virtual void add_element (Grob *);
52   virtual bool must_be_last () const;
53   virtual void derived_mark () const;
54
55 public:
56   TRANSLATOR_DECLARATIONS (Axis_group_engraver);
57 };
58
59
60 Axis_group_engraver::Axis_group_engraver ()
61 {
62   staffline_ = 0;
63   interesting_ = SCM_EOL;
64   active_ = false;
65 }
66
67 void
68 Axis_group_engraver::initialize ()
69 {
70   active_ = !to_boolean (get_property ("hasAxisGroup"));
71   if (active_)
72     context ()->set_property ("hasAxisGroup", SCM_BOOL_T);
73 }
74
75 void
76 Axis_group_engraver::derived_mark () const
77 {
78   scm_gc_mark (interesting_);
79 }
80
81
82 bool
83 Axis_group_engraver::must_be_last () const
84 {
85   return true;
86 }
87
88 void
89 Axis_group_engraver::process_music ()
90 {
91   if (!staffline_ && active_)
92     {
93       staffline_ = get_spanner ();
94       Grob *it = unsmob<Grob> (get_property ("currentCommandColumn"));
95       staffline_->set_bound (LEFT, it);
96     }
97   interesting_ = get_property ("keepAliveInterfaces");
98 }
99
100 Spanner *
101 Axis_group_engraver::get_spanner ()
102 {
103   return make_spanner ("VerticalAxisGroup", SCM_EOL);
104 }
105
106 void
107 Axis_group_engraver::finalize ()
108 {
109   if (staffline_)
110     {
111       Grob *it = unsmob<Grob> (get_property ("currentCommandColumn"));
112       staffline_->set_bound (RIGHT, it);
113
114       Pointer_group_interface::set_ordered (staffline_, ly_symbol2scm ("elements"), false);
115     }
116 }
117
118 void
119 Axis_group_engraver::acknowledge_grob (Grob_info i)
120 {
121   if (staffline_)
122     elts_.push_back (i.grob ());
123
124   if (staffline_ && to_boolean(staffline_->get_property("remove-empty")))
125     {
126       for (SCM s = interesting_; scm_is_pair (s); s = scm_cdr (s))
127         {
128           if (i.grob ()->internal_has_interface (scm_car (s)))
129             Hara_kiri_group_spanner::add_interesting_item (staffline_, i.grob ());
130         }
131     }
132 }
133
134 /*
135   maybe should check if our parent is set, because we now get a
136   cyclic parent relationship if we have two Axis_group_engravers in
137   the context.  */
138 void
139 Axis_group_engraver::process_acknowledged ()
140 {
141   if (!staffline_)
142     return;
143
144   for (vsize i = 0; i < elts_.size (); i++)
145     {
146       if (!unsmob<Grob> (elts_[i]->get_object ("axis-group-parent-Y")))
147         {
148           if (staffline_->get_parent (Y_AXIS)
149               && staffline_->get_parent (Y_AXIS) == elts_[i])
150             {
151               staffline_->warning (_ ("Axis_group_engraver: vertical group already has a parent"));
152               staffline_->warning (_ ("are there two Axis_group_engravers?"));
153               staffline_->warning (_ ("removing this vertical group"));
154               staffline_->suicide ();
155               staffline_ = 0;
156               break;
157             }
158           add_element (elts_[i]);
159         }
160     }
161   elts_.clear ();
162 }
163
164 void
165 Axis_group_engraver::add_element (Grob *e)
166 {
167   Axis_group_interface::add_element (staffline_, e);
168 }
169
170 ADD_ACKNOWLEDGER (Axis_group_engraver, grob);
171
172 ADD_TRANSLATOR (Axis_group_engraver,
173                 /* doc */
174                 "Group all objects created in this context in a"
175                 " @code{VerticalAxisGroup} spanner.",
176
177                 /* create */
178                 "VerticalAxisGroup ",
179
180                 /* read */
181                 "currentCommandColumn "
182                 "keepAliveInterfaces "
183                 "hasAxisGroup ",
184                 
185                 /* write */
186                 "hasAxisGroup "
187                );