]> git.donarmstrong.com Git - lilypond.git/blob - src/pcol.cc
release: 0.0.21
[lilypond.git] / src / pcol.cc
1 #include "pcol.hh"
2 #include "pscore.hh"
3 #include "pstaff.hh"
4 #include "debug.hh"
5
6 Interval
7 PCol::width() const
8 {
9     Interval w;
10
11     for (iter_top(its,i); i.ok(); i++)
12         w.unite(i->width());
13     if (w.empty())
14         w.unite(Interval(0,0));
15     return w;
16 }
17
18 int
19 PCol::rank() const
20 {
21     if(!pscore_)
22         return -1;
23     PCursor<PCol*> me=pscore_->find_col( (PCol*)this);
24     if (!me.ok())
25         return -1;
26     PCursor<PCol*> bot(pscore_->cols.top());
27     return me - bot;
28 }
29
30 void
31 PCol::print() const
32 {
33 #ifndef NPRINT
34     mtor << "PCol {";
35
36     if (rank() >= 0)
37         mtor << "rank: " << rank() << '\n';
38
39     mtor << "# symbols: " << its.size() ;
40     if (breakable()){
41         mtor << "\npre,post: ";
42         prebreak->print();
43         postbreak->print();
44     } else if (daddy) {
45         mtor<<'\n' << ((this == daddy->prebreak) ? "prebreak" : "postbreak");
46     }
47     mtor << "extent: " << width().str() << "\n";
48     mtor << "}\n";
49 #endif 
50 }
51
52 int
53 PCol::compare(const PCol &c1, const PCol &c2)
54 {
55     return c1.pscore_->compare_pcols((PCol*)&c1,(PCol*)&c2);
56 }
57
58 void
59 PCol::OK () const
60 {
61     if (prebreak || postbreak ) {
62         assert(prebreak&&postbreak);
63         assert(prebreak->daddy == this);
64         assert(postbreak->daddy == this);
65     }    
66 }
67
68 void
69 PCol::set_breakable()
70 {
71     if (breakable())
72         return;
73
74     prebreak = new PCol(this);
75     postbreak = new PCol(this);
76     prebreak->pscore_ = pscore_;
77     postbreak->pscore_ = pscore_;
78     
79  
80 }
81
82 bool
83 PCol::breakable() const
84 {
85     return prebreak||postbreak;
86 }
87
88 PCol::PCol(PCol *parent)
89 {
90     daddy = parent;
91     prebreak=0;
92     postbreak=0;
93     line=0;
94  
95     pscore_ = 0;
96 }
97
98 PCol::~PCol()
99 {
100     delete prebreak;
101     delete postbreak;   
102 }
103
104 void
105 PCol::add( Item *i)
106 {
107     its.bottom().add(i);
108     i->pcol_ = this;
109  
110 }
111
112 bool
113 PCol::used()const
114 {
115     return breakable() || its.size();
116 }