From dafd62ddba8ff380687e757edbafe57ff7bb408c Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 29 Feb 2024 10:56:04 +0000 Subject: [PATCH] Unflip when going to viewport which isn't flipped. Fixes https://gitlab.com/kicad/code/kicad/-/issues/13773 (cherry picked from commit c23550dc0bd72d2837cf81f4d2019a51751ff688) --- include/project/board_project_settings.h | 18 +++++----- pcbnew/widgets/appearance_controls.cpp | 42 ++++++++++++------------ 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/project/board_project_settings.h b/include/project/board_project_settings.h index 055d203a3a..046e0b7ab1 100644 --- a/include/project/board_project_settings.h +++ b/include/project/board_project_settings.h @@ -139,35 +139,35 @@ struct IP2581_BOM */ struct LAYER_PRESET { - LAYER_PRESET( const wxString& aName = wxEmptyString ) : + LAYER_PRESET( const wxString& aName = wxS( "" ) ) : name( aName ), + layers( LSET::AllLayersMask() ), + renderLayers( GAL_SET::DefaultVisible() ), + flipBoard( false ), activeLayer( UNSELECTED_LAYER ) { - layers = LSET::AllLayersMask(); - renderLayers = GAL_SET::DefaultVisible(); readOnly = false; - flipBoard = false; } - LAYER_PRESET( const wxString& aName, const LSET& aVisibleLayers ) : + LAYER_PRESET( const wxString& aName, const LSET& aVisibleLayers, bool aFlipBoard ) : name( aName ), layers( aVisibleLayers ), + renderLayers( GAL_SET::DefaultVisible() ), + flipBoard( aFlipBoard ), activeLayer( UNSELECTED_LAYER ) { - renderLayers = GAL_SET::DefaultVisible(); readOnly = false; - flipBoard = false; } LAYER_PRESET( const wxString& aName, const LSET& aVisibleLayers, const GAL_SET& aVisibleObjects, - PCB_LAYER_ID aActiveLayer ) : + PCB_LAYER_ID aActiveLayer, bool aFlipBoard ) : name( aName ), layers( aVisibleLayers ), renderLayers( aVisibleObjects ), + flipBoard( aFlipBoard ), activeLayer( aActiveLayer ) { readOnly = false; - flipBoard = false; } bool LayersMatch( const LAYER_PRESET& aOther ) diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index 962ce5434d..b4f61d506a 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -368,27 +368,28 @@ static std::set s_allowedInFpEditor = // These are the built-in layer presets that cannot be deleted -LAYER_PRESET APPEARANCE_CONTROLS::presetNoLayers( _HKI( "No Layers" ), LSET() ); +LAYER_PRESET APPEARANCE_CONTROLS::presetNoLayers( _HKI( "No Layers" ), LSET(), false ); -LAYER_PRESET APPEARANCE_CONTROLS::presetAllLayers( _HKI( "All Layers" ), LSET::AllLayersMask() ); +LAYER_PRESET APPEARANCE_CONTROLS::presetAllLayers( _HKI( "All Layers" ), + LSET::AllLayersMask(), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetAllCopper( _HKI( "All Copper Layers" ), - LSET::AllCuMask().set( Edge_Cuts ) ); + LSET::AllCuMask().set( Edge_Cuts ), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetInnerCopper( _HKI( "Inner Copper Layers" ), - LSET::InternalCuMask().set( Edge_Cuts ) ); + LSET::InternalCuMask().set( Edge_Cuts ), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetFront( _HKI( "Front Layers" ), - LSET::FrontMask().set( Edge_Cuts ) ); + LSET::FrontMask().set( Edge_Cuts ), false ); LAYER_PRESET APPEARANCE_CONTROLS::presetFrontAssembly( _HKI( "Front Assembly View" ), - LSET::FrontAssembly().set( Edge_Cuts ), GAL_SET::DefaultVisible(), F_SilkS ); + LSET::FrontAssembly().set( Edge_Cuts ), GAL_SET::DefaultVisible(), F_SilkS, false ); LAYER_PRESET APPEARANCE_CONTROLS::presetBack( _HKI( "Back Layers" ), - LSET::BackMask().set( Edge_Cuts ) ); + LSET::BackMask().set( Edge_Cuts ), true ); LAYER_PRESET APPEARANCE_CONTROLS::presetBackAssembly( _HKI( "Back Assembly View" ), - LSET::BackAssembly().set( Edge_Cuts ), GAL_SET::DefaultVisible(), B_SilkS ); + LSET::BackAssembly().set( Edge_Cuts ), GAL_SET::DefaultVisible(), B_SilkS, true ); // this one is only used to store the object visibility settings of the last used // built-in layer preset @@ -524,6 +525,7 @@ APPEARANCE_CONTROLS::APPEARANCE_CONTROLS( PCB_BASE_FRAME* aParent, wxWindow* aFo [&]( wxCommandEvent& aEvent ) { m_frame->GetToolManager()->RunAction( PCB_ACTIONS::flipBoard ); + syncLayerPresetSelection(); } ); m_toggleGridRenderer = new GRID_BITMAP_TOGGLE_RENDERER( @@ -2547,12 +2549,14 @@ void APPEARANCE_CONTROLS::syncLayerPresetSelection() { LSET visibleLayers = getVisibleLayers(); GAL_SET visibleObjects = getVisibleObjects(); + bool flipBoard = m_cbFlipBoard->GetValue(); auto it = std::find_if( m_layerPresets.begin(), m_layerPresets.end(), [&]( const std::pair& aPair ) { return ( aPair.second.layers == visibleLayers - && aPair.second.renderLayers == visibleObjects ); + && aPair.second.renderLayers == visibleObjects + && aPair.second.flipBoard == flipBoard ); } ); if( it != m_layerPresets.end() ) @@ -2650,7 +2654,7 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent ) if( !exists ) { m_layerPresets[name] = LAYER_PRESET( name, getVisibleLayers(), getVisibleObjects(), - UNSELECTED_LAYER ); + UNSELECTED_LAYER, m_cbFlipBoard->GetValue() ); } LAYER_PRESET* preset = &m_layerPresets[name]; @@ -2658,7 +2662,6 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent ) if( !exists ) { index = m_cbLayerPresets->Insert( name, index - 1, static_cast( preset ) ); - preset->flipBoard = m_cbFlipBoard->GetValue(); } else if( preset->readOnly ) { @@ -2740,7 +2743,7 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent ) } LAYER_PRESET* preset = static_cast( m_cbLayerPresets->GetClientData( index ) ); - m_currentPreset = preset; + m_currentPreset = preset; m_lastSelectedUserPreset = ( !preset || preset->readOnly ) ? nullptr : preset; @@ -2769,7 +2772,8 @@ void APPEARANCE_CONTROLS::onLayerPresetChanged( wxCommandEvent& aEvent ) void APPEARANCE_CONTROLS::doApplyLayerPreset( const LAYER_PRESET& aPreset ) { - BOARD* board = m_frame->GetBoard(); + BOARD* board = m_frame->GetBoard(); + KIGFX::PCB_VIEW* view = m_frame->GetCanvas()->GetView(); setVisibleLayers( aPreset.layers ); setVisibleObjects( aPreset.renderLayers ); @@ -2791,15 +2795,16 @@ void APPEARANCE_CONTROLS::doApplyLayerPreset( const LAYER_PRESET& aPreset ) if( !m_isFpEditor ) m_frame->GetCanvas()->SyncLayersVisibility( board ); - if( aPreset.flipBoard ) + if( aPreset.flipBoard != view->IsMirroredX() ) { - m_frame->GetCanvas()->GetView()->SetMirror( true, false ); - m_frame->GetCanvas()->GetView()->RecacheAllItems(); + view->SetMirror( !view->IsMirroredX(), view->IsMirroredY() ); + view->RecacheAllItems(); } m_frame->GetCanvas()->Refresh(); syncColorsAndVisibility(); + UpdateDisplayOptions(); } @@ -2943,11 +2948,6 @@ void APPEARANCE_CONTROLS::onViewportChanged( wxCommandEvent& aEvent ) void APPEARANCE_CONTROLS::doApplyViewport( const VIEWPORT& aViewport ) { m_frame->GetCanvas()->GetView()->SetViewport( aViewport.rect ); - if( m_cbFlipBoard->GetValue() ) - { - m_frame->GetCanvas()->GetView()->SetMirror( true, false ); - m_frame->GetCanvas()->GetView()->RecacheAllItems(); - } m_frame->GetCanvas()->Refresh(); }