Skip to content

Commit

Permalink
Fix: by incomplete spec of const methods
Browse files Browse the repository at this point in the history
Fixes annoying crash upon selection of nucleotides.
Also some indenting.
  • Loading branch information
smoe committed Apr 5, 2024
1 parent f316904 commit d15d404
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 49 deletions.
109 changes: 63 additions & 46 deletions src/SequenceCanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ END_EVENT_TABLE()
// Define a constructor for my canvas
SequenceCanvas::SequenceCanvas(wxWindow * const parent, const wxPoint& pos, const wxSize& size)
: wxScrolledWindow(parent, -1, pos, size, wxSUNKEN_BORDER|wxHSCROLL|wxFULL_REPAINT_ON_RESIZE)
{
{
SetBackgroundColour(wxColour(_T("WHITE")));
set_font_size ( 12 ) ;
mark_firstrow = mark_lastrow = -1 ;
Expand Down Expand Up @@ -249,14 +249,14 @@ void SequenceCanvas::MyGetSize ( int *w , int *h ) const
void SequenceCanvas::MyGetViewStart ( int *x , int *y )
{
if ( printing )
{
*x = 0 ;
*y = 0 ;
}
{
*x = 0 ;
*y = 0 ;
}
else
{
GetViewStart ( x , y ) ;
}
{
GetViewStart ( x , y ) ;
}
}

void SequenceCanvas::updateEdit ( TVector *v , wxString id , int from )
Expand Down Expand Up @@ -370,8 +370,13 @@ void SequenceCanvas::editSpecialKeyPressed ( const int k , TVector * const v , w
mark ( id , from+1 , from+1 , 2 ) ;
}
else if ( from < the_sequence->length() )
{
mark ( id , from+1 , from+1 , 2 ) ;
else mark ( id , the_sequence->length() , the_sequence->length() , 2 ) ;
}
else
{
mark ( id , the_sequence->length() , the_sequence->length() , 2 ) ;
}
}
else if ( k == WXK_LEFT )
{
Expand Down Expand Up @@ -487,7 +492,9 @@ void SequenceCanvas::editCharPressed ( const int _k , TVector * const v , wxStri
if ( doOverwrite() ) the_sequence->erase ( from-1 , 1 ) ;
the_sequence->insert( from-1 , dummy ) ;
if ( forceoverwrite && from == the_sequence->length() )
{
new_from = from ;
}
}
else
{
Expand Down Expand Up @@ -596,7 +603,7 @@ void SequenceCanvas::OnCut ( wxCommandEvent &ev )
if ( !getAA() || _from == -1 ) return ;
wxString s = getSelection () ;
if ( s.IsEmpty() ) return ;
if (!wxTheClipboard->Open()) return ;
if ( !wxTheClipboard->Open() ) return ;

wxTheClipboard->SetData( new wxTextDataObject(s) );
wxTheClipboard->Close();
Expand Down Expand Up @@ -729,7 +736,7 @@ void SequenceCanvas::OnPrint ( wxCommandEvent &ev )
beginning += _f ;

_t -= charheight * ( lastmarked ) ;
_t += charheight * ( seq.GetCount() + blankline + 1 ) ;
_t += charheight * ( seq.GetCount() + blankline + 1 ) ;
lowy = _t ;

hardstop = _fin ;
Expand Down Expand Up @@ -1001,26 +1008,28 @@ void SequenceCanvas::mark ( const SeqBasic * const where , const int from , cons
{
if ( seq[a] != where ) continue ;
if ( !getAln() )
{
mark ( seq[a]->whatsthis() , from , to , value , a ) ;
return ;
}
int b , last = -1 ;
{
mark ( seq[a]->whatsthis() , from , to , value , a ) ;
return ;
}
preventUpdate = true ;
for ( int c = 0 ; c < seq.size() ; c++ )
{
for ( b = 0 ; b < seq[c]->s.length() ; b++ )
for ( int b = 0 ; b < seq[c]->s.length() ; b++ )
{
if ( seq[c]->takesMouseActions )
seq[c]->setMark ( b , 0 ) ;
}
}
preventUpdate = false ;
int b ;
for ( b = 0 ; b < seq.size() && seq[b] != getLastWhere() ; b++ ) ;
if ( b == seq.size() ) b = a ;
if ( b < a ) { const int c = a ; a = b ; b = c ; }
preventUpdate = true ;
mark_firstrow = mark_lastrow = -1 ;

int last = -1 ;
for ( int c = 0 ; c < seq.size() ; c++ )
{
if ( !seq[c]->takesMouseActions ) continue ;
Expand Down Expand Up @@ -1110,14 +1119,20 @@ void SequenceCanvas::mark ( /* not const, but should be */ wxString /* & */ id
for ( int a = 0 ; a < seq[b]->getMarkSize() ; a++ )
{
if ( inMarkRange ( seq[b]->getPos(a) , from , to , l ) )
{
seq[b]->setMark ( a , value ) ;
cnt += value ;
if ( vpx == -1 ) vpx = seq[b]->getRect(a).x / charwidth ;
if ( vpy == -1 ) vpy = seq[b]->getRect(a).y / charheight ;
}
{
//wxPrintf("I: seq[%d]->getPos(%d): %d\n", b, a, seq[b]->getPos(a) ) ;
seq[b]->setMark ( a , value ) ;
cnt += value ;
if (-1 == vpx || -1 == vpy )
{
//wxPrintf("I: Invoking getRect at %d for seq[%d] (%s): %s\n", a , b , seq[b]->whatsthis() , seq[b]->s ) ;
wxRect seq_b_rect_a = seq[b]->getRect(a) ;
if ( vpx == -1 ) vpx = seq_b_rect_a.x / charwidth ;
if ( vpy == -1 ) vpy = seq_b_rect_a.y / charheight ;
}
}
else
seq[b]->setMark ( a , 0 ) ;
seq[b]->setMark ( a , 0 ) ;
}

// Unmark all other lines
Expand Down Expand Up @@ -1338,7 +1353,9 @@ void SequenceCanvas::OnDraw(wxDC& dc)
{
mylog ( "SequenceCanvas::OnDraw" , "2b1 COUNT" ) ;
if ( seq[a]->getRect(b).GetRight() > print_maxx )
print_maxx = seq[a]->getRect(b).GetRight() ;
{
print_maxx = seq[a]->getRect(b).GetRight() ;
}
}
}
mylog ( "SequenceCanvas::OnDraw" , "2b2" ) ;
Expand Down Expand Up @@ -2594,28 +2611,28 @@ void SeqPos::mark ( const int where , const int value )
if ( value < 1 )
{
for ( int a = 0 ; a < mark_from.GetCount() ; a++ )
{
if ( where >= mark_from[a] && where <= mark_to[a] )
{
if ( where == mark_from[a] ) mark_from[a]++ ;
else if ( where == mark_to[a] ) mark_to[a]-- ;
else
{
mark_from.Add ( where + 1 ) ;
mark_to.Add ( mark_to[a] ) ;
mark_to[a] = where - 1 ;
}
}
}
{
if ( where >= mark_from[a] && where <= mark_to[a] )
{
if ( where == mark_from[a] ) mark_from[a]++ ;
else if ( where == mark_to[a] ) mark_to[a]-- ;
else
{
mark_from.Add ( where + 1 ) ;
mark_to.Add ( mark_to[a] ) ;
mark_to[a] = where - 1 ;
}
}
}
for ( int a = 0 ; a < mark_from.GetCount() ; a++ )
{
if ( mark_from[a] > mark_to[a] )
{
mark_from.RemoveAt ( a ) ;
mark_to.RemoveAt ( a ) ;
a-- ;
}
}
{
if ( mark_from[a] > mark_to[a] )
{
mark_from.RemoveAt ( a ) ;
mark_to.RemoveAt ( a ) ;
a-- ;
}
}
return ;
}
mark_value = value ;
Expand Down
4 changes: 2 additions & 2 deletions src/SequenceCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class SeqBasic
virtual void initFromTVector ( TVector * const v ) {} ///< Set from a TVector class
virtual int arrange ( const int n ) { return 0 ; } ; ///< Arrange "chars" as line n
virtual void show ( wxDC& dc ) {} ; ///< Show
virtual wxPoint showText ( int ystart , wxArrayString &tout ) const
virtual wxPoint showText ( const int ystart , const wxArrayString &tout ) const
{ return wxPoint ( -1 , -1 ) ; } ; ///< Show as text (rarely used)
virtual wxString whatsthis () const { return _T("BASIC") ; } ///< Returns the linetype
virtual void makeEndnumberLength() { endnumberlength = 0 ; } ; ///< Calculates the width needed for the leading numbers
Expand Down Expand Up @@ -232,7 +232,7 @@ class SeqDNA : public SeqBasic
virtual bool useDirectRoutines () const ; ///< Do we draw directly (or do we use SeqPos)?
virtual int getMarkSize () const ; ///< Returns the length of the SeqPos marked part of the sequence
virtual int getRectSize () const ; ///< Returns the number of SeqPos rectangles
virtual wxRect getRect ( const int i ) ; ///< Returns the SeqPos rect for a "char"
virtual wxRect getRect ( const int i ) const ; ///< Returns the SeqPos rect for a "char"
virtual int getMark ( const int i ) const ; ///< Returns the mark value for a "char"
virtual void setMark ( const int i , const int v ) ; ///< Sets the marking of a "char"
virtual int getPos ( const int i ) const ; ///< Returns the internal ID of the "char"
Expand Down
2 changes: 1 addition & 1 deletion src/SequenceTypeDNA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ int SeqDNA::getRectSize () const
return 0 ;
}

wxRect SeqDNA::getRect ( const int i )
wxRect SeqDNA::getRect ( const int i ) const
{
if ( !useDirectRoutines() ) return pos.r[i] ;

Expand Down

0 comments on commit d15d404

Please sign in to comment.