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"
20 Spaceable_grob::get_minimum_distances (Grob *me)
22 return me->get_object ("minimum-distances");
25 /*todo: merge code of spring & rod?
28 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
30 // printf ("rod %lf\n", d);
35 programming_error ("infinite rod");
37 SCM mins = get_minimum_distances (me);
38 SCM newdist = scm_make_real (d);
39 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
41 SCM dist = scm_car (s);
42 if (scm_car (dist) == p->self_scm ())
44 scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
50 mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
51 me->set_object ("minimum-distances", mins);
55 Spaceable_grob::add_spring (Grob *me, Grob *p, Real d, Real inverse_strength)
57 if (d <= 0.0 || inverse_strength < 0.0)
59 programming_error ("adding reverse spring, setting to unit");
61 inverse_strength = 1.0;
64 if (isinf (d) || isnan (d)
65 || isnan (inverse_strength))
67 /* strength == INF is possible. It means fixed distance. */
68 programming_error ("insane distance found");
70 inverse_strength = 1.0;
74 SCM mins = me->get_object ("ideal-distances");
75 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
77 Spring_smob *sp = unsmob_spring (scm_car (s));
80 programming_error ("already have that spring");
87 spring.inverse_strength_ = inverse_strength;
91 SCM ideal = me->get_object ("ideal-distances");
92 ideal = scm_cons (spring.smobbed_copy (), ideal);
93 me->set_object ("ideal-distances", ideal);
97 Spaceable_grob::remove_interface (Grob *me)
99 me->set_object ("minimum-distances", SCM_EOL);
100 me->set_object ("spacing-wishes", SCM_EOL);
101 me->set_object ("ideal-distances", SCM_EOL);
104 ADD_INTERFACE (Spaceable_grob, "spaceable-grob-interface",
105 "A layout object that takes part in the spacing problem. ",
106 "measure-length spacing-wishes penalty minimum-distances ideal-distances "
107 "allow-outside-line left-neighbors right-neighbors");