OnLeftClick() test case

This commit is contained in:
dickelbeck 2007-09-26 20:10:12 +00:00
parent b128acfc17
commit b707a8336f
5 changed files with 53 additions and 37 deletions

View File

@ -4,6 +4,19 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2007-Sep-26 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ all
test case for OnLeftClick() handling from a release circumstance.
a few simple changes to void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event ),
but they affect all programs in a subtle way.
+ pcbnew
GENERAL_COLLECTOR::GetCount() returns int, not unsigned. Was tired of the
compiler complaining when using an int ndx.
2007-Sep-25 UPDATE Dick Hollenbeck <dick@softplc.com> 2007-Sep-25 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================ ================================================================================
+ pcbnew + pcbnew

View File

@ -83,9 +83,9 @@ public:
* Function GetCount * Function GetCount
* returns the number of objects in the list * returns the number of objects in the list
*/ */
unsigned GetCount() const int GetCount() const
{ {
return m_List.size(); return (int) m_List.size();
} }
@ -127,7 +127,7 @@ public:
*/ */
EDA_BaseStruct* operator[]( int ndx ) const EDA_BaseStruct* operator[]( int ndx ) const
{ {
if( (unsigned)ndx < GetCount() ) if( (unsigned)ndx < (unsigned)GetCount() ) // (unsigned) excludes ndx<0 also
return m_List[ ndx ]; return m_List[ ndx ];
return NULL; return NULL;
} }

View File

@ -161,14 +161,15 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide(); GENERAL_COLLECTORS_GUIDE guide = GetCollectorsGuide();
// Assign to scanList the proper item types desired based on tool type. // Assign to scanList the proper item types desired based on tool type
// May need to pass a hot key code to this function to support hot keys too. // or hotkey that is in play.
const KICAD_T* scanList; const KICAD_T* scanList;
if( aHotKeyCode ) if( aHotKeyCode )
{ {
// switch here // @todo: add switch here and add calls to PcbGeneralLocateAndDisplay( int aHotKeyCode )
// when searching is needed from a hotkey handler
} }
else if( m_ID_current_state == 0 ) else if( m_ID_current_state == 0 )
{ {
@ -212,7 +213,7 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
#if 0 #if 0
// debugging: print out the collected items, showing their priority order too. // debugging: print out the collected items, showing their priority order too.
for( unsigned i=0; i<m_Collector->GetCount(); ++i ) for( int i=0; i<m_Collector->GetCount(); ++i )
(*m_Collector)[i]->Show( 0, std::cout ); (*m_Collector)[i]->Show( 0, std::cout );
#endif #endif
@ -221,8 +222,7 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
*/ */
unsigned long timestampzone = 0; unsigned long timestampzone = 0;
int limit = m_Collector->GetCount(); for( int ii = 0; ii < m_Collector->GetCount(); ii++ )
for( int ii = 0; ii < limit; ii++ )
{ {
item = (*m_Collector)[ii]; item = (*m_Collector)[ii];
if( item->Type() != TYPEZONE ) if( item->Type() != TYPEZONE )
@ -233,7 +233,6 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
{ {
m_Collector->Remove( ii ); m_Collector->Remove( ii );
ii--; ii--;
limit = m_Collector->GetCount();
} }
else else
timestampzone = item->m_TimeStamp; timestampzone = item->m_TimeStamp;
@ -244,22 +243,23 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
item = (*m_Collector)[0]; item = (*m_Collector)[0];
SetCurItem( item ); SetCurItem( item );
} }
// If the count is 2, and first item is a pad or moduletext, and the 2nd item is its parent module: // If the count is 2, and first item is a pad or moduletext, and the 2nd item is its parent module:
else if( m_Collector->GetCount() == 2 else if( m_Collector->GetCount() == 2
&& ( (*m_Collector)[0]->Type() == TYPEPAD || (*m_Collector)[0]->Type() == && ( (*m_Collector)[0]->Type() == TYPEPAD || (*m_Collector)[0]->Type() == TYPETEXTEMODULE )
TYPETEXTEMODULE ) && (*m_Collector)[1]->Type() == TYPEMODULE && (*m_Collector)[0]->GetParent()== (*m_Collector)[1] )
&& (*m_Collector)[1]->Type() == TYPEMODULE && (*m_Collector)[0]->GetParent()==
(*m_Collector)[1] )
{ {
item = (*m_Collector)[0]; item = (*m_Collector)[0];
SetCurItem( item ); SetCurItem( item );
} }
// if all are modules, find the smallest one amoung the primary choices // if all are modules, find the smallest one amoung the primary choices
else if( ( item = AllAreModulesAndReturnSmallestIfSo( m_Collector ) ) != NULL ) else if( ( item = AllAreModulesAndReturnSmallestIfSo( m_Collector ) ) != NULL )
{ {
SetCurItem( item ); SetCurItem( item );
} }
else // show a popup menu
else // we can't figure out which item user wants, do popup menu so user can choose
{ {
wxMenu itemMenu; wxMenu itemMenu;
@ -280,7 +280,13 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
ADD_MENUITEM( &itemMenu, ID_POPUP_PCB_ITEM_SELECTION_START + i, text, xpm ); ADD_MENUITEM( &itemMenu, ID_POPUP_PCB_ITEM_SELECTION_START + i, text, xpm );
} }
/* @todo: rather than assignment to TRUE, these should be increment and decrement operators throughout _everywhere_.
That way we can handle nesting.
But I tried that and found there cases where the assignment to TRUE (converted to a m_IgnoreMouseEvents++ )
was not balanced with the -- (now m_IgnoreMouseEvents=FALSE), so I had to revert.
Somebody should track down these and make them balanced.
DrawPanel->m_IgnoreMouseEvents = TRUE; DrawPanel->m_IgnoreMouseEvents = TRUE;
*/
// this menu's handler is void WinEDA_BasePcbFrame::ProcessItemSelection() // this menu's handler is void WinEDA_BasePcbFrame::ProcessItemSelection()
// and it calls SetCurItem() which in turn calls Display_Infos() on the item. // and it calls SetCurItem() which in turn calls Display_Infos() on the item.
@ -288,7 +294,7 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
DrawPanel->m_IgnoreMouseEvents = FALSE; // DrawPanel->m_IgnoreMouseEvents = FALSE;
// The function ProcessItemSelection() has set the current item, return it. // The function ProcessItemSelection() has set the current item, return it.
item = GetCurItem(); item = GetCurItem();

View File

@ -89,17 +89,15 @@ void WinEDA_PcbFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
} }
} }
} }
else
{ else /* if( !wxGetKeyState(WXK_SHIFT) && !wxGetKeyState(WXK_ALT) &&
if ( ! wxGetKeyState(WXK_SHIFT) && ! wxGetKeyState(WXK_ALT) && !wxGetKeyState(WXK_CONTROL) && !wxGetKeyState(WXK_TAB) ) */
! wxGetKeyState(WXK_CONTROL) && ! wxGetKeyState(WXK_TAB))
{ {
DrawStruct = PcbGeneralLocateAndDisplay(); DrawStruct = PcbGeneralLocateAndDisplay();
if( DrawStruct ) if( DrawStruct )
SendMessageToEESCHEMA( DrawStruct ); SendMessageToEESCHEMA( DrawStruct );
} }
} }
}
switch( m_ID_current_state ) switch( m_ID_current_state )
{ {
@ -1275,8 +1273,7 @@ void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
} }
else if( DrawStruct->m_Flags == 0 ) else if( DrawStruct->m_Flags == 0 )
{ {
Edit_TrackSegm_Width( DC, Edit_TrackSegm_Width( DC, (TRACK*) DrawStruct );
(TRACK*) DrawStruct );
} }
break; break;
@ -1287,14 +1284,12 @@ void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
break; break;
case TYPEPAD: case TYPEPAD:
InstallPadOptionsFrame( InstallPadOptionsFrame( (D_PAD*) DrawStruct, &dc, pos );
(D_PAD*) DrawStruct, &dc, pos );
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
break; break;
case TYPEMODULE: case TYPEMODULE:
InstallModuleOptionsFrame( (MODULE*) DrawStruct, InstallModuleOptionsFrame( (MODULE*) DrawStruct, &dc, pos );
&dc, pos );
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
break; break;
@ -1304,8 +1299,7 @@ void WinEDA_PcbFrame::OnLeftDClick( wxDC* DC, const wxPoint& MousePos )
break; break;
case TYPETEXTEMODULE: case TYPETEXTEMODULE:
InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, InstallTextModOptionsFrame( (TEXTE_MODULE*) DrawStruct, &dc, pos );
&dc, pos );
DrawPanel->MouseToCursorSchema(); DrawPanel->MouseToCursorSchema();
break; break;

View File

@ -845,7 +845,7 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
if( localbutt == (int) (GR_M_LEFT_DOWN | GR_M_DCLICK) ) if( localbutt == (int) (GR_M_LEFT_DOWN | GR_M_DCLICK) )
m_Parent->OnLeftDClick( &DC, screen->m_MousePositionInPixels ); m_Parent->OnLeftDClick( &DC, screen->m_MousePositionInPixels );
else if( event.LeftDown() ) else if( event.LeftUp() && screen->BlockLocate.m_State==STATE_NO_BLOCK )
m_Parent->OnLeftClick( &DC, screen->m_MousePositionInPixels ); m_Parent->OnLeftClick( &DC, screen->m_MousePositionInPixels );
if( event.ButtonUp( 2 ) && (screen->BlockLocate.m_State == STATE_NO_BLOCK) ) if( event.ButtonUp( 2 ) && (screen->BlockLocate.m_State == STATE_NO_BLOCK) )
@ -902,12 +902,15 @@ void WinEDA_DrawPanel::OnMouseEvent( wxMouseEvent& event )
if( screen->BlockLocate.m_State == STATE_NO_BLOCK ) if( screen->BlockLocate.m_State == STATE_NO_BLOCK )
{ {
int cmd_type = kbstat; int cmd_type = kbstat;
if( event.MiddleIsDown() ) if( event.MiddleIsDown() )
cmd_type |= MOUSE_MIDDLE; cmd_type |= MOUSE_MIDDLE;
if( !m_Parent->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) ) if( !m_Parent->HandleBlockBegin( &DC, cmd_type, m_CursorStartPos ) )
{ // error {
m_Parent->DisplayToolMsg( wxT( "WinEDA_DrawPanel::OnMouseEvent() Block Error" ) // error
); m_Parent->DisplayToolMsg(
wxT( "WinEDA_DrawPanel::OnMouseEvent() Block Error" ) );
} }
else else
{ {