File: SequenceTypeAlign.cpp

package info (click to toggle)
gentle 1.9+cvs20100605+dfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: squeeze
  • size: 12,264 kB
  • ctags: 5,235
  • sloc: cpp: 41,571; ansic: 3,978; sh: 1,420; makefile: 291
file content (189 lines) | stat: -rw-r--r-- 6,474 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/** \file
	\brief Contains the SeqAlign class members
*/
#include "SequenceCanvas.h"

int SeqAlign::arrange ( int n )
    {
    int a , x , y , w , h , l = 0 , bo = can->border , lowy = 0 ;
    int lasta = 0 ;
    
    // Setting basic values
    can->SetFont(*can->font);
    int wx = can->charwidth , wy = can->charheight ;
    int ox = bo + wx + wx * endnumberlength  , oy = n*wy+bo ;
    can->MyGetClientSize ( &w , &h ) ;

    itemsperline = ( w - ox ) / ( ( can->blocksize + 1 ) * wx ) ;
    if ( itemsperline == 0 ) itemsperline = 1 ;
    itemsperline *= can->blocksize ;
    
    pos.cleanup() ;
    pos.reserve ( s.length() * 11 / 10 , s.length() / itemsperline ) ;
    x = ox ;
    y = oy ;
    pos.add ( -(++l) , bo , y , ox-wx-bo , wy-1 ) ; // Line number
    for ( a = 0 ; a < s.length() ; a++ )
        {
        pos.add ( a+1 , x , y , wx-1 , wy-1 ) ;
        can->setLowX ( x + wx*2 ) ;
        lowy = y+wy ;
        x += wx ;
        if ( (a+1) % can->blocksize == 0 )
           {
           x += wx-1 ;
           if ( x+wx*(can->blocksize+1) >= w )
              {
              pos.addline ( lasta , pos.p.GetCount() , y , y+wy-1 ) ;
              lasta = pos.p.GetCount()+1 ;
              x = ox ;
              y += wy * ( can->seq.GetCount() + can->blankline ) ;
              if ( a+1 < s.length() )
                 pos.add ( -(++l) , bo , y , ox-wx-5 , wy-1 ) ; // Line number
              }
           }
        }
    if ( lasta != pos.p.GetCount()+1 ) 
        pos.addline ( lasta , pos.p.GetCount() , y , y+wy-1 ) ;
    pos.r.clear () ;
    return lowy + bo*2 ;
    }
    
void SeqAlign::show ( wxDC& dc )
    {
    can->SetFont(*can->font);
    dc.SetFont(*can->font);
    wxColour tbg = dc.GetTextBackground () ;
    wxColour tfg = dc.GetTextForeground () ;
    int bm = dc.GetBackgroundMode () ;
    int a , b , cnt = offset+1 ;
    wxString t ;
//    TAlignment *win = (TAlignment*) can->child ;
    
    wxColour nbgc ;
    for ( a = 0 ; can->seq[a] != this ; a++ ) ;
    switch ( id%3 )
        {
        case 0 : nbgc = wxColour ( 200 , 200 , 255 ) ; break ;
        case 1 : nbgc = wxColour ( 200 , 255 , 200 ) ; break ;
        case 2 : nbgc = wxColour ( 200 , 255 , 255 ) ; break ;
        }
    
    int first = -1 , me = -1 ;
    for ( a = 0 ; a < can->seq.GetCount() ; a++ )
        {
        if ( can->seq[a]->whatsthis() == _T("ALIGN") && first == -1 )
           first = a ;
        if ( can->seq[a] == this )
           me = a ;
        }
    wxColour fg = *wxBLACK , bg = *wxWHITE ;
    TAlignment *al = (TAlignment*) can->child ;
    dc.SetTextForeground ( fg ) ;
    dc.SetTextBackground ( bg ) ;
    dc.SetBackgroundMode ( wxSOLID ) ;

    int n , bo = can->border ;
    for ( n = 0 ; can->seq[n] != this ; n++ ) ;
    int wx = can->charwidth , wy = can->charheight ;
    int ox = bo + wx + wx * endnumberlength  , oy = n*wy+bo ;
    
    int xa , xb , ya , yb ;
    dc.GetDeviceOrigin ( &xa , &ya ) ;
    ya = -ya ;
    xa = -xa ;
    can->MyGetClientSize ( &xb , &yb ) ;
    yb += ya ;
    xb += xa ;
    int cnol = can->NumberOfLines() ;
    int ppgc = pos.p.GetCount() ;
    bool thisisidentity = ( myname == txt("t_identity") ) ;
    int last_wx = -1 ;

    for ( a = 0 ; a < ppgc ; a++ )
        {
        if ( can->hardstop > -1 && a > can->hardstop ) break ;
        int rax , ray = oy + wy * cnol * ( a / ( itemsperline + 1 ) ) ;
        if ( ray < ya ) continue ;
        b = pos.p[a] ;
        if ( b < 0 ) rax = bo ;
        else 
           {
           int x2 = ( b - 1 ) % itemsperline ;
           rax = ox ;
           rax += x2 * wx ;
           rax += ( x2 / can->blocksize ) * ( wx - 1 ) ;
           }    
        if ( can->isPrinting() ) rax += xa ; // PATCH AS PATCH CAN!!!

        int tx = rax , ty = ray ;
        int tzx = tx + wx ;
        int tzy = ty + wy ;
        bool insight = true ; // Meaning "is this part visible"
        if ( tzy < ya || ty > yb ) insight = false ;
        if ( b > 0 && ( tzx < xa || tx > xb ) ) insight = false ;
        if ( can->getDrawAll() ) insight = true ;
        if ( !insight && ty > yb ) a = ppgc ;
        if ( !insight && tx > xb ) a = ppgc ;
        if ( b > 0 && !insight ) cnt++ ;
        if ( b > 0 && insight ) // Character
           {
           t = s.GetChar(b-1) ;

           // Same as char in first sequence?
           if ( (!thisisidentity) &&
                al->cons &&
                first != me &&
                t.GetChar(0) != '-' &&
                t.GetChar(0) == can->seq[first]->s.GetChar(b-1) )
                   t.SetChar(0,'.') ;

           SequenceCharMarkup scm ;
           int mode = 0 ;
           if ( !thisisidentity )
              {
              al->getCharMarkup ( scm , id , b-1 , first ) ;
              if ( getMark ( a ) ) mode |= SEQUENCECHARMARKUP_MARK ;
              if ( al->mono ) mode |= SEQUENCECHARMARKUP_MONO ;
              if ( can->isPrinting() && !can->getPrintToColor() ) mode |= SEQUENCECHARMARKUP_MONO ;
              if ( al->bold ) mode |= SEQUENCECHARMARKUP_BOLD ;
              }
           
           scm.draw ( dc , wxRect ( rax , ray , wx , wy ) , t , mode , last_wx ) ;
           if ( scm.ignore || getMark ( a ) ) last_wx = -1 ;
           else last_wx = rax + wx ;

           cnt++ ;
           }
        else if ( b < 0 && insight ) // Front number
           {
           last_wx = -1 ;
           dc.SetTextForeground ( *wxBLACK ) ;
           dc.SetTextBackground ( nbgc ) ;
           FILLSTRING ( t , (wxChar)' ' , endnumberlength ) ;
           dc.DrawText ( t , rax, ray ) ;
           dc.SetFont(*can->varFont);
           t = myname ;
           t = _T(" ") + t ;
           int tw , th ;
           do {
              t = t.substr ( 1 , t.length()-1 ) ;
              dc.GetTextExtent ( t , &tw , &th ) ;
              } while ( tw > endnumberlength * wx ) ;
           dc.DrawText ( t , rax, ray ) ;
           dc.SetTextBackground ( *wxWHITE ) ;
           dc.SetFont(*can->font);
           }
        }
    dc.SetBackgroundMode ( bm ) ;
    dc.SetTextBackground ( tbg ) ;
    dc.SetTextForeground ( tfg ) ;
    }
    

void SeqAlign::makeEndnumberLength()
    {
    endnumberlength = myname.length() ;
    while ( endnumberlength > 10 ) endnumberlength-- ;
    }