]> 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!");
50     }
51   
52 #ifndef NDEBUG
53   SCM mins = me->get_grob_property ("ideal-distances");
54   for (SCM s = mins; gh_pair_p (s); s = ly_cdr (s))
55     {
56       Spring_smob * sp = unsmob_spring(ly_car (s));
57       if (sp->other_ == p)
58         {
59           programming_error ("already have that spring");
60           return ;
61         }
62     }
63 #endif
64   
65   Spring_smob spring;
66   spring.strength_f_ = strength;
67   spring.distance_f_ = d;
68   spring.expand_only_b_ = expand_only;
69   spring.other_ = p;
70   
71   Group_interface::add_thing (me, ly_symbol2scm ("ideal-distances"), spring.smobbed_copy ());
72 }
73
74
75 void
76 Spaceable_grob::remove_interface (Grob*me)
77 {
78   me->remove_grob_property ("minimum-distances");
79   me->remove_grob_property ("ideal-distances");
80 }
81
82
83 ADD_INTERFACE (Spaceable,"spaceable-grob-interface",
84   "An grob (a Paper_column) that takes part in the
85 spacing problem. ",
86   "measure-length penalty minimum-distances ideal-distances
87 left-neighbors right-neighbors");
88