]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-grob.cc
''
[lilypond.git] / lily / spaceable-grob.cc
1 /*   
2   spaceable-grob.cc --  implement Spaceable_grob
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "spaceable-grob.hh"
11 #include "grob.hh"
12 #include "warn.hh"
13 #include "spring.hh"
14 #include "group-interface.hh"
15
16 SCM
17 Spaceable_grob::get_minimum_distances (Grob*me)
18 {
19   return me->get_grob_property ("minimum-distances");
20 }
21
22 /*todo: merge code of spring & rod?
23  */
24 void
25 Spaceable_grob::add_rod (Grob *me , Grob * p, Real d)
26 {
27   SCM mins = get_minimum_distances (me);
28   SCM newdist = gh_double2scm (d);
29   for (SCM s = mins; gh_pair_p (s); s = ly_cdr (s))
30     {
31       SCM dist = ly_car (s);
32       if (ly_car (dist) == p->self_scm ())
33         {
34           gh_set_cdr_x (dist, scm_max (ly_cdr (dist),
35                                        newdist));
36           return ;
37         }
38     }
39
40   mins = gh_cons (gh_cons (p->self_scm (), newdist), mins);
41   me->set_grob_property ("minimum-distances", mins);
42 }
43
44 void
45 Spaceable_grob::add_spring (Grob*me, Grob * p, Real d, Real strength, bool expand_only)
46 {
47   if (d < 0.0 || strength <= 0.0)
48     {
49       programming_error ("Adding reverse spring! Setting to unit spring");
50       d = 1.0;
51       strength = 1.0;
52     }
53   
54 #ifndef NDEBUG
55   SCM mins = me->get_grob_property ("ideal-distances");
56   for (SCM s = mins; gh_pair_p (s); s = ly_cdr (s))
57     {
58       Spring_smob * sp = unsmob_spring(ly_car (s));
59       if (sp->other_ == p)
60         {
61           programming_error ("already have that spring");
62           return ;
63         }
64     }
65 #endif
66   
67   Spring_smob spring;
68   spring.strength_f_ = strength;
69   spring.distance_f_ = d;
70   spring.expand_only_b_ = expand_only;
71   spring.other_ = p;
72   
73   Group_interface::add_thing (me, ly_symbol2scm ("ideal-distances"), spring.smobbed_copy ());
74 }
75
76
77 void
78 Spaceable_grob::remove_interface (Grob*me)
79 {
80   me->remove_grob_property ("minimum-distances");
81   me->remove_grob_property ("ideal-distances");
82 }
83
84
85 ADD_INTERFACE (Spaceable,"spaceable-grob-interface",
86   "An grob (a Paper_column) that takes part in the
87 spacing problem. ",
88   "measure-length penalty minimum-distances ideal-distances
89 left-neighbors right-neighbors");
90