]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-grob.cc
release: 1.5.38
[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 #ifndef NDEBUG
48   SCM mins = me->get_grob_property ("ideal-distances");
49   for (SCM s = mins; gh_pair_p (s); s = ly_cdr (s))
50     {
51       Spring_smob * sp = unsmob_spring(ly_car (s));
52       if (sp->other_ == p)
53         {
54           programming_error ("already have that spring");
55           return ;
56         }
57     }
58 #endif
59   
60   Spring_smob spring;
61   spring.strength_f_ = strength;
62   spring.distance_f_ = d;
63   spring.expand_only_b_ = expand_only;
64   spring.other_ = p;
65   
66   Group_interface::add_thing (me, ly_symbol2scm ("ideal-distances"), spring.smobbed_copy ());
67 }
68
69
70 void
71 Spaceable_grob::remove_interface (Grob*me)
72 {
73   me->remove_grob_property ("minimum-distances");
74   me->remove_grob_property ("ideal-distances");
75 }
76
77
78 void
79 Spaceable_grob::set_interface (Grob*me)
80 {
81   me->set_interface (ly_symbol2scm ("spaceable-grob-interface"));
82 }