2 spaceable-grob.cc -- implement Spaceable_grob
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "spaceable-grob.hh"
16 #include "pointer-group-interface.hh"
18 #include "paper-column.hh"
21 Spaceable_grob::get_minimum_distances (Grob *me)
23 return me->get_object ("minimum-distances");
26 /*todo: merge code of spring & rod?
29 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
31 // printf ("rod %lf\n", d);
36 programming_error ("infinite rod");
38 SCM mins = get_minimum_distances (me);
39 SCM newdist = scm_from_double (d);
40 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
42 SCM dist = scm_car (s);
43 if (scm_car (dist) == p->self_scm ())
45 scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
51 if (Paper_column::get_rank (p) < Paper_column::get_rank (me))
53 programming_error ("Adding reverse rod");
56 mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
57 me->set_object ("minimum-distances", mins);
61 Spaceable_grob::add_spring (Grob *me, Grob *p, Real d, Real inverse_strength)
63 if (d <= 0.0 || inverse_strength < 0.0)
65 programming_error ("adding reverse spring, setting to unit");
67 inverse_strength = 1.0;
70 if (isinf (d) || isnan (d)
71 || isnan (inverse_strength))
73 /* strength == INF is possible. It means fixed distance. */
74 programming_error ("insane distance found");
76 inverse_strength = 1.0;
80 SCM mins = me->get_object ("ideal-distances");
81 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
83 Spring_smob *sp = unsmob_spring (scm_car (s));
86 programming_error ("already have that spring");
93 spring.inverse_strength_ = inverse_strength;
97 SCM ideal = me->get_object ("ideal-distances");
98 ideal = scm_cons (spring.smobbed_copy (), ideal);
99 me->set_object ("ideal-distances", ideal);
103 Spaceable_grob::get_spring (Grob *me, Grob *other, Real *dist, Real *inv_strength)
105 for (SCM s = me->get_object ("ideal-distances");
106 scm_is_pair (s); s = scm_cdr (s))
108 Spring_smob *spring = unsmob_spring (scm_car (s));
109 if (spring && spring->other_ == other)
111 *dist = spring->distance_;
112 *inv_strength = spring->inverse_strength_;
118 Spaceable_grob::remove_interface (Grob *me)
120 me->set_object ("minimum-distances", SCM_EOL);
121 me->set_object ("spacing-wishes", SCM_EOL);
122 me->set_object ("ideal-distances", SCM_EOL);
125 ADD_INTERFACE (Spaceable_grob, "spaceable-grob-interface",
126 "A layout object that takes part in the spacing problem. ",
127 "measure-length spacing-wishes penalty minimum-distances ideal-distances "
128 "keep-inside-line left-neighbors right-neighbors");