← Back to team overview

kicad-developers team mailing list archive

[PATCH] Cleanup: Drop unnecessary casts

 

Hi,

small cleanup: there are a few unnecessary casts because the covariant
return already does the right thing. Where we get the screen object only in
order to get the active layer, use the accessor function directly.

   Simon

---
 include/wxBasePcbFrame.h                              | 4 ++--
 pcbnew/basepcbframe.cpp                               | 4 ++--
 pcbnew/dialogs/dialog_find.cpp                        | 4 ++--
 pcbnew/dialogs/dialog_non_copper_zones_properties.cpp | 2 +-
 pcbnew/edit_pcb_text.cpp                              | 2 +-
 pcbnew/editrack-part2.cpp                             | 6 +++---
 pcbnew/tool_pcb.cpp                                   | 4 ++--
 pcbnew/tracepcb.cpp                                   | 2 +-
 8 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/include/wxBasePcbFrame.h b/include/wxBasePcbFrame.h
index 1545cfd..d860755 100644
--- a/include/wxBasePcbFrame.h
+++ b/include/wxBasePcbFrame.h
@@ -619,7 +619,7 @@ public:
      */
     virtual void SetActiveLayer( LAYER_ID aLayer )
     {
-        ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer = aLayer;
+        GetScreen()->m_Active_Layer = aLayer;
     }
 
     /**
@@ -628,7 +628,7 @@ public:
      */
     virtual LAYER_ID GetActiveLayer() const
     {
-        return ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer;
+        return GetScreen()->m_Active_Layer;
     }
 
     void LoadSettings( wxConfigBase* aCfg );    // override virtual
diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp
index 6b70e6f..a5a5f5f 100644
--- a/pcbnew/basepcbframe.cpp
+++ b/pcbnew/basepcbframe.cpp
@@ -367,7 +367,7 @@ void PCB_BASE_FRAME::Show3D_Frame( wxCommandEvent& event )
 // Note: virtual, overridden in PCB_EDIT_FRAME;
 void PCB_BASE_FRAME::SwitchLayer( wxDC* DC, LAYER_ID layer )
 {
-    LAYER_ID preslayer = ((PCB_SCREEN*)GetScreen())->m_Active_Layer;
+    LAYER_ID preslayer = GetActiveLayer();
     DISPLAY_OPTIONS* displ_opts = (DISPLAY_OPTIONS*)GetDisplayOptions();
 
     // Check if the specified layer matches the present layer
@@ -583,7 +583,7 @@ BOARD_ITEM* PCB_BASE_FRAME::GetCurItem()
 GENERAL_COLLECTORS_GUIDE PCB_BASE_FRAME::GetCollectorsGuide()
 {
     GENERAL_COLLECTORS_GUIDE guide( m_Pcb->GetVisibleLayers(),
-                                    ( (PCB_SCREEN*)GetScreen())->m_Active_Layer );
+                                    GetActiveLayer() );
 
     // account for the globals
     guide.SetIgnoreMTextsMarkedNoShow( ! m_Pcb->IsElementVisible( MOD_TEXT_INVISIBLE ));
diff --git a/pcbnew/dialogs/dialog_find.cpp b/pcbnew/dialogs/dialog_find.cpp
index 559adc8..e3acac2 100644
--- a/pcbnew/dialogs/dialog_find.cpp
+++ b/pcbnew/dialogs/dialog_find.cpp
@@ -74,7 +74,7 @@ void DIALOG_FIND::onButtonCloseClick( wxCommandEvent& aEvent )
 
 void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
 {
-    PCB_SCREEN* screen = (PCB_SCREEN*) ( parent->GetScreen() );
+    PCB_SCREEN* screen = parent->GetScreen();
     wxPoint     pos;
 
     foundItem = NULL;
@@ -144,7 +144,7 @@ void DIALOG_FIND::onButtonFindItemClick( wxCommandEvent& aEvent )
 
 void DIALOG_FIND::onButtonFindMarkerClick( wxCommandEvent& aEvent )
 {
-    PCB_SCREEN* screen = (PCB_SCREEN*) ( parent->GetScreen() );
+    PCB_SCREEN* screen = parent->GetScreen();
     wxPoint     pos;
     foundItem = NULL;
 
diff --git a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp
index 35516e1..b91a3e8 100644
--- a/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp
+++ b/pcbnew/dialogs/dialog_non_copper_zones_properties.cpp
@@ -143,7 +143,7 @@ void DIALOG_NON_COPPER_ZONES_EDITOR::Init()
     wxImageList* imageList = new wxImageList( LAYER_BITMAP_SIZE_X, LAYER_BITMAP_SIZE_Y );
     m_LayerSelectionCtrl->AssignImageList( imageList, wxIMAGE_LIST_SMALL );
 
-    int lyrSelect = ( (PCB_SCREEN*) m_parent->GetScreen() )->m_Active_Layer;
+    LAYER_ID lyrSelect = m_parent->GetActiveLayer();
 
     if( m_zone )
         lyrSelect = m_zone->GetLayer();
diff --git a/pcbnew/edit_pcb_text.cpp b/pcbnew/edit_pcb_text.cpp
index 682db7a..bae9b3a 100644
--- a/pcbnew/edit_pcb_text.cpp
+++ b/pcbnew/edit_pcb_text.cpp
@@ -203,7 +203,7 @@ TEXTE_PCB* PCB_EDIT_FRAME::CreateTextePcb( wxDC* aDC, TEXTE_PCB* aText )
         GetBoard()->Add( textePcb );
         textePcb->SetFlags( IS_NEW );
 
-        LAYER_ID layer = ( (PCB_SCREEN*) GetScreen() )->m_Active_Layer;
+        LAYER_ID layer = GetActiveLayer();
 
         textePcb->SetLayer( layer );
 
diff --git a/pcbnew/editrack-part2.cpp b/pcbnew/editrack-part2.cpp
index c84d9dd..868e5a7 100644
--- a/pcbnew/editrack-part2.cpp
+++ b/pcbnew/editrack-part2.cpp
@@ -50,10 +50,10 @@ bool PCB_EDIT_FRAME::Other_Layer_Route( TRACK* aTrack, wxDC* DC )
 
     if( aTrack == NULL )
     {
-        if( GetActiveLayer() != ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP )
-            SetActiveLayer( ((PCB_SCREEN*)GetScreen())->m_Route_Layer_TOP );
+        if( GetActiveLayer() != GetScreen()->m_Route_Layer_TOP )
+            SetActiveLayer( GetScreen()->m_Route_Layer_TOP );
         else
-            SetActiveLayer(((PCB_SCREEN*)GetScreen())->m_Route_Layer_BOTTOM );
+            SetActiveLayer( GetScreen()->m_Route_Layer_BOTTOM );
 
         UpdateStatusBar();
         return true;
diff --git a/pcbnew/tool_pcb.cpp b/pcbnew/tool_pcb.cpp
index ab14265..1fb73a8 100644
--- a/pcbnew/tool_pcb.cpp
+++ b/pcbnew/tool_pcb.cpp
@@ -110,7 +110,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
     }
 
     Route_Layer_TOP_color =
-        g_ColorsSettings.GetLayerColor( ( ( PCB_SCREEN* ) GetScreen() )->m_Route_Layer_TOP );
+        g_ColorsSettings.GetLayerColor( GetScreen()->m_Route_Layer_TOP );
 
     if( previous_Route_Layer_TOP_color != Route_Layer_TOP_color )
     {
@@ -119,7 +119,7 @@ void PCB_EDIT_FRAME::PrepareLayerIndicator()
     }
 
     Route_Layer_BOTTOM_color =
-        g_ColorsSettings.GetLayerColor( ( (PCB_SCREEN*) GetScreen() )->m_Route_Layer_BOTTOM );
+        g_ColorsSettings.GetLayerColor( GetScreen()->m_Route_Layer_BOTTOM );
 
     if( previous_Route_Layer_BOTTOM_color != Route_Layer_BOTTOM_color )
     {
diff --git a/pcbnew/tracepcb.cpp b/pcbnew/tracepcb.cpp
index f9bf65b..56b3a8b 100644
--- a/pcbnew/tracepcb.cpp
+++ b/pcbnew/tracepcb.cpp
@@ -59,7 +59,7 @@ static void Trace_Pads_Only( EDA_DRAW_PANEL* panel, wxDC* DC, MODULE* Module,
 
 void FOOTPRINT_EDIT_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg )
 {
-    PCB_SCREEN* screen = (PCB_SCREEN*) GetScreen();
+    PCB_SCREEN* screen = GetScreen();
 
     if( !GetBoard() || !screen )
         return;

Follow ups