]> git.donarmstrong.com Git - lilypond.git/blob - lily/spaceable-grob.cc
* lily/time-signature-performer.cc (derived_mark): new function.
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "spaceable-grob.hh"
10
11 #include <cstdio>
12 #include <math.h>
13
14 #include "warn.hh"
15 #include "spring.hh"
16 #include "group-interface.hh"
17
18 SCM
19 Spaceable_grob::get_minimum_distances (Grob *me)
20 {
21   return me->get_property ("minimum-distances");
22 }
23
24 /*todo: merge code of spring & rod?
25  */
26 void
27 Spaceable_grob::add_rod (Grob *me, Grob *p, Real d)
28 {
29   //  printf ("rod %lf\n", d);
30   if (d < 0)
31     return ;
32   
33   if (isinf (d))
34     {
35       programming_error ("Infinite rod");
36     }
37
38   SCM mins = get_minimum_distances (me);
39   SCM newdist = scm_make_real (d);
40   for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
41     {
42       SCM dist = scm_car (s);
43       if (scm_car (dist) == p->self_scm ())
44         {
45           scm_set_cdr_x (dist, scm_max (scm_cdr (dist),
46                                         newdist));
47           return;
48         }
49     }
50
51   mins = scm_cons (scm_cons (p->self_scm (), newdist), mins);
52   me->set_property ("minimum-distances", mins);
53 }
54
55 void
56 Spaceable_grob::add_spring (Grob *me, Grob *p, Real d, Real strength)
57 {
58   //  printf ("dist %lf, str %lf\n", d, strength); 
59   if (d <= 0.0 || strength <= 0.0)
60     {
61       programming_error ("Adding reverse spring! Setting to unit spring");
62       d = 1.0;
63       strength = 1.0;
64     }
65
66   if (isinf (d) || isnan (d)
67       || isnan (strength))
68     {
69       /*
70         strength == INF is possible. It means fixed distance.
71       */
72       programming_error ("Insane distance found.");
73       d = 1.0;
74       strength = 1.0;
75     }
76
77 #ifndef NDEBUG
78   SCM mins = me->get_property ("ideal-distances");
79   for (SCM s = mins; scm_is_pair (s); s = scm_cdr (s))
80     {
81       Spring_smob *sp = unsmob_spring (scm_car (s));
82       if (sp->other_ == p)
83         {
84           programming_error ("already have that spring");
85           return;
86         }
87     }
88 #endif
89
90   Spring_smob spring;
91   spring.strength_ = strength;
92   spring.distance_ = d;
93   spring.other_ = p;
94
95   Group_interface::add_thing (me, ly_symbol2scm ("ideal-distances"), spring.smobbed_copy ());
96 }
97
98 void
99 Spaceable_grob::remove_interface (Grob *me)
100 {
101   me->set_property ("minimum-distances", SCM_EOL);
102   me->set_property ("spacing-wishes", SCM_EOL);
103   me->set_property ("ideal-distances", SCM_EOL);
104 }
105
106 ADD_INTERFACE (Spaceable_grob, "spaceable-grob-interface",
107                "A layout object that takes part in the spacing problem. ",
108                "measure-length spacing-wishes penalty minimum-distances ideal-distances "
109                "allow-outside-line left-neighbors right-neighbors");
110