Debounce layer visibility buttons and fix issues with FP Editor.

This commit is contained in:
Jeff Young 2022-02-23 17:39:06 +00:00
parent a36bc27e6d
commit cb16ad7557
4 changed files with 32 additions and 43 deletions

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -26,6 +26,7 @@
#include <wx/sizer.h> #include <wx/sizer.h>
#include <wx/statbmp.h> #include <wx/statbmp.h>
#include <wx/timer.h>
wxDEFINE_EVENT( TOGGLE_CHANGED, wxCommandEvent ); wxDEFINE_EVENT( TOGGLE_CHANGED, wxCommandEvent );
@ -35,7 +36,8 @@ BITMAP_TOGGLE::BITMAP_TOGGLE( wxWindow *aParent, wxWindowID aId, const wxBitmap&
wxPanel( aParent, aId ), wxPanel( aParent, aId ),
m_checked( aChecked ), m_checked( aChecked ),
m_unchecked_bitmap( aUncheckedBitmap ), m_unchecked_bitmap( aUncheckedBitmap ),
m_checked_bitmap( aCheckedBitmap ) m_checked_bitmap( aCheckedBitmap ),
m_debounce( 0 )
{ {
wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL ); wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
SetSizer( sizer ); SetSizer( sizer );
@ -47,13 +49,21 @@ BITMAP_TOGGLE::BITMAP_TOGGLE( wxWindow *aParent, wxWindowID aId, const wxBitmap&
sizer->Add( m_bitmap, 0, 0 ); sizer->Add( m_bitmap, 0, 0 );
m_bitmap->Bind( wxEVT_LEFT_UP, m_bitmap->Bind( wxEVT_LEFT_UP,
[&]( wxMouseEvent& ) [&]( wxMouseEvent& event )
{ {
wxLongLong now = wxGetLocalTimeMillis();
if( now - m_debounce < 50 )
return;
else
m_debounce = now;
SetValue( !GetValue() ); SetValue( !GetValue() );
wxCommandEvent event( TOGGLE_CHANGED );
event.SetInt( m_checked ); wxCommandEvent command( TOGGLE_CHANGED );
event.SetEventObject( this ); command.SetInt( m_checked );
wxPostEvent( this, event ); command.SetEventObject( this );
wxPostEvent( this, command );
} ); } );
auto passOnEvent = auto passOnEvent =

View File

@ -1,7 +1,7 @@
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
* @author Jon Evans <jon@craftyjon.com> * @author Jon Evans <jon@craftyjon.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
@ -68,12 +68,10 @@ private:
bool m_checked; bool m_checked;
wxStaticBitmap* m_bitmap; wxStaticBitmap* m_bitmap;
///< Bitmap to display in unchecked state
wxBitmap m_unchecked_bitmap; wxBitmap m_unchecked_bitmap;
///< Bitmap to display in checked state
wxBitmap m_checked_bitmap; wxBitmap m_checked_bitmap;
wxLongLong m_debounce; // Timestamp for debouncing events
}; };
#endif #endif

View File

@ -1498,24 +1498,14 @@ void APPEARANCE_CONTROLS::rebuildLayers()
[&]( wxCommandEvent& aEvent ) [&]( wxCommandEvent& aEvent )
{ {
wxObject* btn = aEvent.GetEventObject(); wxObject* btn = aEvent.GetEventObject();
int layId = static_cast<wxWindow*>( btn )->GetId(); int layerId = static_cast<wxWindow*>( btn )->GetId();
bool isVisible = aEvent.GetInt();
wxASSERT( layId >= 0 && layId < PCB_LAYER_ID_COUNT ); onLayerVisibilityToggled( static_cast<PCB_LAYER_ID>( layerId ) );
if( m_isFpEditor && LSET::ForbiddenFootprintLayers().test( layId ) )
{
static_cast<BITMAP_TOGGLE*>( btn )->SetValue( !isVisible );
return;
}
onLayerVisibilityChanged( static_cast<PCB_LAYER_ID>( layId ),
isVisible, true );
} ); } );
swatch->Bind( COLOR_SWATCH_CHANGED, &APPEARANCE_CONTROLS::OnColorSwatchChanged, swatch->Bind( COLOR_SWATCH_CHANGED, &APPEARANCE_CONTROLS::OnColorSwatchChanged,
this ); this );
swatch->SetReadOnlyCallback(std::bind( &APPEARANCE_CONTROLS::onReadOnlySwatch, swatch->SetReadOnlyCallback( std::bind( &APPEARANCE_CONTROLS::onReadOnlySwatch,
this ) ); this ) );
swatch->SetReadOnly( readOnly ); swatch->SetReadOnly( readOnly );
@ -1927,23 +1917,14 @@ void APPEARANCE_CONTROLS::rightClickHandler( wxMouseEvent& aEvent )
}; };
void APPEARANCE_CONTROLS::onLayerVisibilityChanged( PCB_LAYER_ID aLayer, bool isVisible, void APPEARANCE_CONTROLS::onLayerVisibilityToggled( PCB_LAYER_ID aLayer )
bool isFinal )
{ {
LSET visibleLayers = getVisibleLayers(); LSET visibleLayers = getVisibleLayers();
if( visibleLayers.test( aLayer ) != isVisible ) visibleLayers.set( aLayer, !visibleLayers.test( aLayer ) );
{ m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, visibleLayers.test( aLayer ) );
visibleLayers.set( aLayer, isVisible );
setVisibleLayers( visibleLayers );
m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, isVisible );
}
syncLayerPresetSelection(); syncLayerPresetSelection();
if( isFinal )
m_frame->GetCanvas()->Refresh(); m_frame->GetCanvas()->Refresh();
} }

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application. * This program source code file is part of KiCad, a free EDA CAD application.
* *
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com> * Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the * under the terms of the GNU General Public License as published by the
@ -329,7 +329,7 @@ private:
void rightClickHandler( wxMouseEvent& aEvent ); void rightClickHandler( wxMouseEvent& aEvent );
void onLayerVisibilityChanged( PCB_LAYER_ID aLayer, bool isVisible, bool isFinal ); void onLayerVisibilityToggled( PCB_LAYER_ID aLayer );
void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal ); void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );