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 "group-interface.hh"
19 Spaceable_grob::get_minimum_distances (Grob *me)
21 return me->get_property ("minimum-distances");
24 /*todo: merge code of spring & rod?
27 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
29 // printf ("rod %lf\n", d);
34 programming_error ("infinite rod");
36 SCM mins = get_minimum_distances (me);
37 SCM newdist = scm_make_real (d);
38 for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
40 SCM dist = scm_car (s);
41 if (scm_car (dist) == p->self_scm ())
43 scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
49 mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
50 me->set_property ("minimum-distances", mins);
54 Spaceable_grob::add_spring (Grob *me, Grob *p, Real d, Real strength)
56 // printf ("dist %lf, str %lf\n", d, strength);
57 if (d <= 0.0 || strength <= 0.0)
59 programming_error ("adding reverse spring, setting to unit");
64 if (isinf (d) || isnan (d)
67 /* strength == INF is possible. It means fixed distance. */
68 programming_error ("insane distance found");
74 SCM mins = me->get_property ("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.strength_ = strength;
91 Group_interface::add_thing (me, ly_symbol2scm ("ideal-distances"), spring.smobbed_copy ());
95 Spaceable_grob::remove_interface (Grob *me)
97 me->set_property ("minimum-distances", SCM_EOL);
98 me->set_property ("spacing-wishes", SCM_EOL);
99 me->set_property ("ideal-distances", SCM_EOL);
102 ADD_INTERFACE (Spaceable_grob, "spaceable-grob-interface",
103 "A layout object that takes part in the spacing problem. ",
104 "measure-length spacing-wishes penalty minimum-distances ideal-distances "
105 "allow-outside-line left-neighbors right-neighbors");