From 83724f4e2624e6d7924d10d75bfba27397519bca Mon Sep 17 00:00:00 2001 From: Andrzej Wolski Date: Sat, 17 Feb 2018 19:03:22 +0100 Subject: [PATCH] Fix pads and footprints rendering switches behavior MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------2.7.4" This is a multi-part message in MIME format. --------------2.7.4 Content-Type: text/plain; charset=UTF-8; format=fixed Content-Transfer-Encoding: 8bit Pads and footprints rendering switches in Render tab were working incorrectly, as described in bug report: https://bugs.launchpad.net/kicad/+bug/1743890 This patch fixes it and makes GAL behave as the legacy canvas. Fixes: lp:1743890 --- pcbnew/class_edge_mod.cpp | 26 ++++++++++++++++++++++++++ pcbnew/class_edge_mod.h | 3 +++ pcbnew/class_pad.cpp | 22 +++++++++++++++++++++- pcbnew/class_text_mod.cpp | 31 ++++++++++++++++++++++--------- pcbnew/class_text_mod.h | 2 ++ pcbnew/pcb_draw_panel_gal.cpp | 14 -------------- 6 files changed, 74 insertions(+), 24 deletions(-) --------------2.7.4 Content-Type: text/x-patch; name="0001-Fix-pads-and-footprints-rendering-switches-behavior.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename="0001-Fix-pads-and-footprints-rendering-switches-behavior.patch" diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index da78be8..6c1ae3e 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -49,6 +49,8 @@ #include #include +#include + #include EDGE_MODULE::EDGE_MODULE( MODULE* parent, STROKE_T aShape ) : @@ -321,6 +323,12 @@ void EDGE_MODULE::Flip( const wxPoint& aCentre ) SetLayer( FlipLayer( GetLayer() ) ); } +bool EDGE_MODULE::IsParentFlipped() const +{ + if( GetParent() && GetParent()->GetLayer() == B_Cu ) + return true; + return false; +} void EDGE_MODULE::Mirror( wxPoint aCentre, bool aMirrorAroundXAxis ) { @@ -394,3 +402,21 @@ void EDGE_MODULE::Move( const wxPoint& aMoveVector ) SetDrawCoord(); } + +unsigned int EDGE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +{ + const int HIDE = std::numeric_limits::max(); + + if( !aView ) + return 0; + + // Handle Render tab switches + if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) ) + return HIDE; + + if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) ) + return HIDE; + + // Other layers are shown without any conditions + return 0; +} diff --git a/pcbnew/class_edge_mod.h b/pcbnew/class_edge_mod.h index 571b692..38dcac1 100644 --- a/pcbnew/class_edge_mod.h +++ b/pcbnew/class_edge_mod.h @@ -88,6 +88,8 @@ public: */ void Flip( const wxPoint& aCentre ) override; + bool IsParentFlipped() const; + void SetStart0( const wxPoint& aPoint ) { m_Start0 = aPoint; } const wxPoint& GetStart0() const { return m_Start0; } @@ -126,6 +128,7 @@ public: EDA_ITEM* Clone() const override; + virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; #if defined(DEBUG) void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index cdbef32..379cf45 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -1274,6 +1275,25 @@ void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const unsigned int D_PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { + const int HIDE = std::numeric_limits::max(); + + // Handle Render tab switches + if( ( GetAttribute() == PAD_ATTRIB_STANDARD || GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ) + && !aView->IsLayerVisible( LAYER_PADS_TH ) ) + return HIDE; + + if( !IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) ) + return HIDE; + + if( IsFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) ) + return HIDE; + + if( IsFrontLayer( ( PCB_LAYER_ID )aLayer ) && !aView->IsLayerVisible( LAYER_PAD_FR ) ) + return HIDE; + + if( IsBackLayer( ( PCB_LAYER_ID )aLayer ) && !aView->IsLayerVisible( LAYER_PAD_BK ) ) + return HIDE; + // Netnames will be shown only if zoom is appropriate if( IsNetnameLayer( aLayer ) ) { @@ -1282,7 +1302,7 @@ unsigned int D_PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const // Pad sizes can be zero briefly when someone is typing a number like "0.5" // in the pad properties dialog if( divisor == 0 ) - return UINT_MAX; + return HIDE; return ( Millimeter2iu( 100 ) / divisor ); } diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index df45cf2..2728d74 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -145,6 +145,13 @@ void TEXTE_MODULE::Flip( const wxPoint& aCentre ) SetLocalCoord(); } +bool TEXTE_MODULE::IsParentFlipped() const +{ + if( GetParent() && GetParent()->GetLayer() == B_Cu ) + return true; + return false; +} + void TEXTE_MODULE::Mirror( const wxPoint& aCentre, bool aMirrorAroundXAxis ) { @@ -473,27 +480,33 @@ void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { - const int MAX = std::numeric_limits::max(); + const int HIDE = std::numeric_limits::max(); if( !aView ) return 0; + // Handle Render tab switches if( ( m_Type == TEXT_is_VALUE || m_Text == wxT( "%V" ) ) && !aView->IsLayerVisible( LAYER_MOD_VALUES ) ) - return MAX; + return HIDE; if( ( m_Type == TEXT_is_REFERENCE || m_Text == wxT( "%R" ) ) && !aView->IsLayerVisible( LAYER_MOD_REFERENCES ) ) - return MAX; + return HIDE; + + if( !IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_FR ) ) + return HIDE; + + if( IsParentFlipped() && !aView->IsLayerVisible( LAYER_MOD_BK ) ) + return HIDE; - if( IsFrontLayer( m_Layer ) && ( !aView->IsLayerVisible( LAYER_MOD_TEXT_FR ) || - !aView->IsLayerVisible( LAYER_MOD_FR ) ) ) - return MAX; + if( IsFrontLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_FR ) ) + return HIDE; - if( IsBackLayer( m_Layer ) && ( !aView->IsLayerVisible( LAYER_MOD_TEXT_BK ) || - !aView->IsLayerVisible( LAYER_MOD_BK ) ) ) - return MAX; + if( IsBackLayer( m_Layer ) && !aView->IsLayerVisible( LAYER_MOD_TEXT_BK ) ) + return HIDE; + // Other layers are shown without any conditions return 0; } diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index eb4318e..11a42e8 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -104,6 +104,8 @@ public: /// Flip entity during module flip void Flip( const wxPoint& aCentre ) override; + bool IsParentFlipped() const; + /// Mirror text position in footprint edition /// the text itself is not mirrored, and the layer not modified, /// only position is mirrored. diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 15ea7c5..d9476fc 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -446,26 +446,12 @@ void PCB_DRAW_PANEL_GAL::setDefaultLayerDeps() m_view->SetRequired( LAYER_PADS_NETNAMES, LAYER_PADS_TH ); // Front modules - m_view->SetRequired( LAYER_PAD_FR, LAYER_MOD_FR ); m_view->SetRequired( LAYER_MOD_TEXT_FR, LAYER_MOD_FR ); m_view->SetRequired( LAYER_PAD_FR_NETNAMES, LAYER_PAD_FR ); - m_view->SetRequired( F_Adhes, LAYER_PAD_FR ); - m_view->SetRequired( F_Paste, LAYER_PAD_FR ); - m_view->SetRequired( F_Mask, LAYER_PAD_FR ); - m_view->SetRequired( F_CrtYd, LAYER_MOD_FR ); - m_view->SetRequired( F_Fab, LAYER_MOD_FR ); - m_view->SetRequired( F_SilkS, LAYER_MOD_FR ); // Back modules - m_view->SetRequired( LAYER_PAD_BK, LAYER_MOD_BK ); m_view->SetRequired( LAYER_MOD_TEXT_BK, LAYER_MOD_BK ); m_view->SetRequired( LAYER_PAD_BK_NETNAMES, LAYER_PAD_BK ); - m_view->SetRequired( B_Adhes, LAYER_PAD_BK ); - m_view->SetRequired( B_Paste, LAYER_PAD_BK ); - m_view->SetRequired( B_Mask, LAYER_PAD_BK ); - m_view->SetRequired( B_CrtYd, LAYER_MOD_BK ); - m_view->SetRequired( B_Fab, LAYER_MOD_BK ); - m_view->SetRequired( B_SilkS, LAYER_MOD_BK ); m_view->SetLayerTarget( LAYER_GP_OVERLAY , KIGFX::TARGET_OVERLAY ); m_view->SetLayerDisplayOnly( LAYER_GP_OVERLAY ) ; --------------2.7.4--