]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-grob.cc
patch::: 1.5.11.jcn2
[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--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "spaceable-grob.hh"
11 #include "grob.hh"
12 #include "warn.hh"
13
14 SCM
15 Spaceable_grob::get_minimum_distances (Grob*me)
16 {
17   return me->get_grob_property ("minimum-distances");
18 }
19
20 /*todo: merge code of spring & rod?
21  */
22 void
23 Spaceable_grob::add_rod (Grob *me , Grob * p, Real d)
24 {
25   SCM mins = get_minimum_distances (me);
26   SCM newdist = gh_double2scm (d);
27   for (SCM s = mins; gh_pair_p (s); s = ly_cdr (s))
28     {
29       SCM dist = ly_car (s);
30       if (ly_car (dist) == p->self_scm ())
31         {
32           gh_set_cdr_x (dist, scm_max (ly_cdr (dist),
33                                        newdist));
34           return ;
35         }
36     }
37
38   mins = gh_cons (gh_cons (p->self_scm (), newdist), mins);
39   me->set_grob_property ("minimum-distances", mins);
40 }
41
42 void
43 Spaceable_grob::add_spring (Grob*me, Grob * p, Real d, Real strength)
44 {
45   SCM mins = me->get_grob_property ("ideal-distances");
46   
47   
48   SCM newdist= gh_double2scm (d);
49   for (SCM s = mins; gh_pair_p (s); s = ly_cdr (s))
50     {
51       SCM dist = ly_car (s);
52       if (ly_car (dist) == p->self_scm ())
53         {
54           programming_error ("already have that spring");
55           return ;
56         }
57     }
58   SCM newstrength= gh_double2scm (strength);  
59   
60   mins = gh_cons (gh_cons (p->self_scm (), gh_cons (newdist, newstrength)), mins);
61   me->set_grob_property ("ideal-distances", mins);
62 }
63
64
65 void
66 Spaceable_grob::remove_interface (Grob*me)
67 {
68   me->remove_grob_property ("minimum-distances");
69   me->remove_grob_property ("ideal-distances");
70   me->remove_grob_property ("dir-list");
71 }
72
73
74 void
75 Spaceable_grob::set_interface (Grob*me)
76 {
77   me->set_interface (ly_symbol2scm ("spaceable-grob-interface"));
78 }