From 95c2b261e886562fcec5b1d0f51e36cd8e532600 Mon Sep 17 00:00:00 2001 From: Simon Richter Date: Fri, 17 Jan 2020 12:56:07 +0100 Subject: [PATCH] Don't mandate ownership semantics in API This API doesn't transfer ownership, so no smart pointers are required -- this just needlessly tightens requirements on the user of the interface. (Fixes five instances of MSVC C26410 warning) --- common/board_printout.cpp | 17 ++++++++--------- gerbview/gerbview_printout.cpp | 5 ++--- gerbview/gerbview_printout.h | 2 +- include/board_printout.h | 4 ++-- pcbnew/pcbnew_printout.cpp | 35 +++++++++++++++++----------------- pcbnew/pcbnew_printout.h | 4 ++-- 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/common/board_printout.cpp b/common/board_printout.cpp index 0d39dd3fac..b6826ea92a 100644 --- a/common/board_printout.cpp +++ b/common/board_printout.cpp @@ -125,8 +125,8 @@ void BOARD_PRINTOUT::DrawPage( const wxString& aLayerName, int aPageNum, int aPa } } - setupViewLayers( view, m_settings.m_layerSet ); - setupPainter( painter ); + setupViewLayers( *view, m_settings.m_layerSet ); + setupPainter( *painter ); auto sheetSizeMils = m_settings.m_pageInfo.GetSizeMils(); VECTOR2I sheetSizeIU( milsToIU( sheetSizeMils.GetWidth() ), milsToIU( sheetSizeMils.GetHeight() ) ); @@ -181,23 +181,22 @@ void BOARD_PRINTOUT::DrawPage( const wxString& aLayerName, int aPageNum, int aPa } -void BOARD_PRINTOUT::setupViewLayers( const std::unique_ptr& aView, - const LSET& aLayerSet ) +void BOARD_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet ) { // Disable all layers by default, let specific implementions enable required layers for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i ) { - aView->SetLayerVisible( i, false ); - aView->SetTopLayer( i, false ); - aView->SetLayerTarget( i, KIGFX::TARGET_NONCACHED ); + aView.SetLayerVisible( i, false ); + aView.SetTopLayer( i, false ); + aView.SetLayerTarget( i, KIGFX::TARGET_NONCACHED ); } } -void BOARD_PRINTOUT::setupPainter( const std::unique_ptr& aPainter ) +void BOARD_PRINTOUT::setupPainter( KIGFX::PAINTER& aPainter ) { if( !m_settings.m_background ) - aPainter->GetSettings()->SetBackgroundColor( COLOR4D::WHITE ); + aPainter.GetSettings()->SetBackgroundColor( COLOR4D::WHITE ); } diff --git a/gerbview/gerbview_printout.cpp b/gerbview/gerbview_printout.cpp index fc8518d4c2..b1cb063a81 100644 --- a/gerbview/gerbview_printout.cpp +++ b/gerbview/gerbview_printout.cpp @@ -85,13 +85,12 @@ int GERBVIEW_PRINTOUT::milsToIU( double aMils ) const } -void GERBVIEW_PRINTOUT::setupViewLayers( const std::unique_ptr& aView, - const LSET& aLayerSet ) +void GERBVIEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet ) { BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet ); for( LSEQ layerSeq = m_settings.m_layerSet.Seq(); layerSeq; ++layerSeq ) - aView->SetLayerVisible( GERBVIEW_LAYER_ID_START + *layerSeq, true ); + aView.SetLayerVisible( GERBVIEW_LAYER_ID_START + *layerSeq, true ); } diff --git a/gerbview/gerbview_printout.h b/gerbview/gerbview_printout.h index 0c842e0b44..824de6145f 100644 --- a/gerbview/gerbview_printout.h +++ b/gerbview/gerbview_printout.h @@ -35,7 +35,7 @@ public: protected: int milsToIU( double aMils ) const override; - void setupViewLayers( const std::unique_ptr& aView, const LSET& aLayerSet ) override; + void setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet ) override; void setupGal( KIGFX::GAL* aGal ) override; diff --git a/include/board_printout.h b/include/board_printout.h index de4e06e3cb..b406f2904e 100644 --- a/include/board_printout.h +++ b/include/board_printout.h @@ -96,10 +96,10 @@ protected: virtual int milsToIU( double aMils ) const = 0; ///> Enables layers visibility for a printout - virtual void setupViewLayers( const std::unique_ptr& aView, const LSET& aLayerSet ); + virtual void setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet ); ///> Configures PAINTER object for a printout - virtual void setupPainter( const std::unique_ptr& aPainter ); + virtual void setupPainter( KIGFX::PAINTER& aPainter ); ///> Configures GAL object for a printout virtual void setupGal( KIGFX::GAL* aGal ); diff --git a/pcbnew/pcbnew_printout.cpp b/pcbnew/pcbnew_printout.cpp index 2b6564fecc..3c10fe891e 100644 --- a/pcbnew/pcbnew_printout.cpp +++ b/pcbnew/pcbnew_printout.cpp @@ -124,27 +124,26 @@ int PCBNEW_PRINTOUT::milsToIU( double aMils ) const } -void PCBNEW_PRINTOUT::setupViewLayers( const std::unique_ptr& aView, - const LSET& aLayerSet ) +void PCBNEW_PRINTOUT::setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet ) { BOARD_PRINTOUT::setupViewLayers( aView, aLayerSet ); for( LSEQ layerSeq = m_settings.m_layerSet.Seq(); layerSeq; ++layerSeq ) - aView->SetLayerVisible( PCBNEW_LAYER_ID_START + *layerSeq, true ); + aView.SetLayerVisible( PCBNEW_LAYER_ID_START + *layerSeq, true ); // Enable pad layers corresponding to the selected copper layers if( aLayerSet.test( F_Cu ) ) - aView->SetLayerVisible( LAYER_PAD_FR, true ); + aView.SetLayerVisible( LAYER_PAD_FR, true ); if( aLayerSet.test( B_Cu ) ) - aView->SetLayerVisible( LAYER_PAD_BK, true ); + aView.SetLayerVisible( LAYER_PAD_BK, true ); if( ( aLayerSet & LSET::AllCuMask() ).any() ) // Items visible on any copper layer { // Enable items on copper layers, but do not draw holes for( GAL_LAYER_ID item : { LAYER_PADS_TH, LAYER_VIAS } ) { - aView->SetLayerVisible( item, true ); + aView.SetLayerVisible( item, true ); } if( m_pcbnewSettings.m_drillMarks != PCBNEW_PRINTOUT_SETTINGS::NO_DRILL_SHAPE ) @@ -153,8 +152,8 @@ void PCBNEW_PRINTOUT::setupViewLayers( const std::unique_ptr& aView for( GAL_LAYER_ID holeLayer : { LAYER_PADS_PLATEDHOLES, LAYER_NON_PLATEDHOLES, LAYER_VIAS_HOLES } ) { - aView->SetLayerVisible( holeLayer, true ); - aView->SetTopLayer( holeLayer, true ); + aView.SetLayerVisible( holeLayer, true ); + aView.SetTopLayer( holeLayer, true ); } } } @@ -168,37 +167,37 @@ void PCBNEW_PRINTOUT::setupViewLayers( const std::unique_ptr& aView }; for( int item : alwaysEnabled ) - aView->SetLayerVisible( item, true ); + aView.SetLayerVisible( item, true ); } -void PCBNEW_PRINTOUT::setupPainter( const std::unique_ptr& aPainter ) +void PCBNEW_PRINTOUT::setupPainter( KIGFX::PAINTER& aPainter ) { BOARD_PRINTOUT::setupPainter( aPainter ); - KIGFX::PCB_PRINT_PAINTER* painter = static_cast( aPainter.get() ); + KIGFX::PCB_PRINT_PAINTER& painter = dynamic_cast( aPainter ); switch( m_pcbnewSettings.m_drillMarks ) { case PCBNEW_PRINTOUT_SETTINGS::NO_DRILL_SHAPE: - painter->SetDrillMarks( false, 0 ); + painter.SetDrillMarks( false, 0 ); break; case PCBNEW_PRINTOUT_SETTINGS::SMALL_DRILL_SHAPE: - painter->SetDrillMarks( false, Millimeter2iu( 0.3 ) ); + painter.SetDrillMarks( false, Millimeter2iu( 0.3 ) ); break; case PCBNEW_PRINTOUT_SETTINGS::FULL_DRILL_SHAPE: - painter->SetDrillMarks( true ); + painter.SetDrillMarks( true ); break; } - painter->GetSettings()->SetDrawIndividualViaLayers( + painter.GetSettings()->SetDrawIndividualViaLayers( m_pcbnewSettings.m_pagination == PCBNEW_PRINTOUT_SETTINGS::LAYER_PER_PAGE ); - painter->GetSettings()->SetLayerColor( LAYER_PADS_PLATEDHOLES, COLOR4D::WHITE ); - painter->GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::WHITE ); - painter->GetSettings()->SetLayerColor( LAYER_VIAS_HOLES, COLOR4D::WHITE ); + painter.GetSettings()->SetLayerColor( LAYER_PADS_PLATEDHOLES, COLOR4D::WHITE ); + painter.GetSettings()->SetLayerColor( LAYER_NON_PLATEDHOLES, COLOR4D::WHITE ); + painter.GetSettings()->SetLayerColor( LAYER_VIAS_HOLES, COLOR4D::WHITE ); } diff --git a/pcbnew/pcbnew_printout.h b/pcbnew/pcbnew_printout.h index bf15fd9807..4b9c9e4bb8 100644 --- a/pcbnew/pcbnew_printout.h +++ b/pcbnew/pcbnew_printout.h @@ -58,9 +58,9 @@ public: protected: int milsToIU( double aMils ) const override; - void setupViewLayers( const std::unique_ptr& aView, const LSET& aLayerSet ) override; + void setupViewLayers( KIGFX::VIEW& aView, const LSET& aLayerSet ) override; - void setupPainter( const std::unique_ptr& aPainter ) override; + void setupPainter( KIGFX::PAINTER& aPainter ) override; void setupGal( KIGFX::GAL* aGal ) override;