From 456735f8033c0e35f9bdc3d96c12db568dce9cab Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Mon, 21 Sep 2020 17:03:08 +0200 Subject: [PATCH] VIEW::ViewGetLOD() returns double now instead of int. ViewGetLOD() returns the minimal value of a zoom to show an item. However a zoom is a double, and using int as minimal value does not allows setting a correct value in some cases. --- gerbview/gerber_draw_item.cpp | 8 ++++---- gerbview/gerber_draw_item.h | 2 +- include/class_pcb_group.h | 2 +- include/view/view_item.h | 4 ++-- pcbnew/class_edge_mod.cpp | 6 +++--- pcbnew/class_edge_mod.h | 2 +- pcbnew/class_module.cpp | 7 ++++--- pcbnew/class_module.h | 2 +- pcbnew/class_pad.cpp | 8 ++++---- pcbnew/class_pad.h | 2 +- pcbnew/class_pcb_group.cpp | 6 +++--- pcbnew/class_text_mod.cpp | 8 ++++---- pcbnew/class_text_mod.h | 2 +- pcbnew/class_track.cpp | 16 ++++++++-------- pcbnew/class_track.h | 4 ++-- pcbnew/class_zone.cpp | 12 ++++++------ pcbnew/class_zone.h | 4 ++-- pcbnew/pcb_painter.cpp | 4 ++-- 18 files changed, 50 insertions(+), 49 deletions(-) diff --git a/gerbview/gerber_draw_item.cpp b/gerbview/gerber_draw_item.cpp index f51ce70a11..aaa18da57b 100644 --- a/gerbview/gerber_draw_item.cpp +++ b/gerbview/gerber_draw_item.cpp @@ -951,7 +951,7 @@ const BOX2I GERBER_DRAW_ITEM::ViewBBox() const } -unsigned int GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { // DCodes will be shown only if zoom is appropriate: // Returns the level of detail of the item. @@ -977,12 +977,12 @@ unsigned int GERBER_DRAW_ITEM::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) cons // the level of details is chosen experimentally, to show // only a readable text: - const int level = Millimeter2iu( 4 ); - return ( level / ( size + 1 ) ); + double level = (double)Millimeter2iu( 3 ); + return level / ( size + 1 ); } // Other layers are shown without any conditions - return 0; + return 0.0; } diff --git a/gerbview/gerber_draw_item.h b/gerbview/gerber_draw_item.h index 4ab4ae9eee..5546a97dc5 100644 --- a/gerbview/gerber_draw_item.h +++ b/gerbview/gerber_draw_item.h @@ -292,7 +292,7 @@ public: virtual const BOX2I ViewBBox() const override; /// @copydoc VIEW_ITEM::ViewGetLOD() - virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; ///> @copydoc EDA_ITEM::Visit() SEARCH_RESULT Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] ) override; diff --git a/include/class_pcb_group.h b/include/class_pcb_group.h index fc2ade90aa..69b39e656e 100644 --- a/include/class_pcb_group.h +++ b/include/class_pcb_group.h @@ -151,7 +151,7 @@ public: void ViewGetLayers( int aLayers[], int& aCount ) const override; ///> @copydoc VIEW_ITEM::ViewGetLOD - unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; ///> @copydoc BOARD_ITEM::Move void Move( const wxPoint& aMoveVector ) override; diff --git a/include/view/view_item.h b/include/view/view_item.h index 3ea26fc549..1289f3c5f0 100644 --- a/include/view/view_item.h +++ b/include/view/view_item.h @@ -138,10 +138,10 @@ public: * @return the level of detail. 0 always show the item, because the * actual zoom level (or VIEW scale) is always > 0 */ - virtual unsigned int ViewGetLOD( int aLayer, VIEW* aView ) const + virtual double ViewGetLOD( int aLayer, VIEW* aView ) const { // By default always show the item - return 0; + return 0.0; } public: diff --git a/pcbnew/class_edge_mod.cpp b/pcbnew/class_edge_mod.cpp index bd04756a94..7095a87010 100644 --- a/pcbnew/class_edge_mod.cpp +++ b/pcbnew/class_edge_mod.cpp @@ -313,9 +313,9 @@ void EDGE_MODULE::Move( const wxPoint& aMoveVector ) } -unsigned int EDGE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double EDGE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { - const int HIDE = std::numeric_limits::max(); + constexpr double HIDE = std::numeric_limits::max(); if( !aView ) return 0; @@ -328,7 +328,7 @@ unsigned int EDGE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const return HIDE; // Other layers are shown without any conditions - return 0; + return 0.0; } diff --git a/pcbnew/class_edge_mod.h b/pcbnew/class_edge_mod.h index 141c0a65cf..66e684322d 100644 --- a/pcbnew/class_edge_mod.h +++ b/pcbnew/class_edge_mod.h @@ -148,7 +148,7 @@ public: EDA_ITEM* Clone() const override; - virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double 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_module.cpp b/pcbnew/class_module.cpp index c9aa93d451..ee4ebc973b 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1088,19 +1088,20 @@ void MODULE::ViewGetLayers( int aLayers[], int& aCount ) const } -unsigned int MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { int layer = ( m_Layer == F_Cu ) ? LAYER_MOD_FR : ( m_Layer == B_Cu ) ? LAYER_MOD_BK : LAYER_ANCHOR; // Currently this is only pertinent for the anchor layer; everything else is drawn from the // children. - #define MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY 0.6 + // The "good" value is experimentally chosen. + #define MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY 1.5 if( aView->IsLayerVisible( layer ) ) return MINIMAL_ZOOM_LEVEL_FOR_VISIBILITY; - return std::numeric_limits::max(); + return std::numeric_limits::max(); } diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 2be930bc97..3b3876f324 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -623,7 +623,7 @@ public: virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; - virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; virtual const BOX2I ViewBBox() const override; diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index a1d22bea93..5227cc31de 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -1171,12 +1171,12 @@ void D_PAD::ViewGetLayers( int aLayers[], int& aCount ) const } -unsigned int D_PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double D_PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { if( aView->GetPrintMode() > 0 ) // In printing mode the pad is always drawable - return 0; + return 0.0; - const int HIDE = std::numeric_limits::max(); + constexpr double HIDE = std::numeric_limits::max(); BOARD* board = GetBoard(); // Meta control for hiding all pads @@ -1214,7 +1214,7 @@ unsigned int D_PAD::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const if( divisor == 0 ) return HIDE; - return ( Millimeter2iu( 5 ) / divisor ); + return ( double ) Millimeter2iu( 5 ) / divisor; } // Other layers are shown without any conditions diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 806636b2b3..af137638f9 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -615,7 +615,7 @@ public: virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; - virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; virtual const BOX2I ViewBBox() const override; diff --git a/pcbnew/class_pcb_group.cpp b/pcbnew/class_pcb_group.cpp index 66334730ee..523557fb2e 100644 --- a/pcbnew/class_pcb_group.cpp +++ b/pcbnew/class_pcb_group.cpp @@ -238,12 +238,12 @@ void PCB_GROUP::ViewGetLayers( int aLayers[], int& aCount ) const } -unsigned int PCB_GROUP::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double PCB_GROUP::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { if( aView->IsLayerVisible( LAYER_ANCHOR ) ) - return 0; + return 0.0; - return std::numeric_limits::max(); + return std::numeric_limits::max(); } diff --git a/pcbnew/class_text_mod.cpp b/pcbnew/class_text_mod.cpp index 962322d852..4cd62fd4fa 100644 --- a/pcbnew/class_text_mod.cpp +++ b/pcbnew/class_text_mod.cpp @@ -381,12 +381,12 @@ void TEXTE_MODULE::ViewGetLayers( int aLayers[], int& aCount ) const } -unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { - const int HIDE = std::numeric_limits::max(); + constexpr double HIDE = (double)std::numeric_limits::max(); if( !aView ) - return 0; + return 0.0; // Hidden text gets put on the LAYER_MOD_TEXT_INVISIBLE for rendering, but // should only render if its native layer is visible. @@ -415,7 +415,7 @@ unsigned int TEXTE_MODULE::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const return HIDE; // Other layers are shown without any conditions - return 0; + return 0.0; } diff --git a/pcbnew/class_text_mod.h b/pcbnew/class_text_mod.h index 0c3239609d..220d01ff25 100644 --- a/pcbnew/class_text_mod.h +++ b/pcbnew/class_text_mod.h @@ -228,7 +228,7 @@ public: virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; - virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; #if defined(DEBUG) virtual void Show( int nestLevel, std::ostream& os ) const override { ShowDummy( os ); } diff --git a/pcbnew/class_track.cpp b/pcbnew/class_track.cpp index b963deefb4..422136c327 100644 --- a/pcbnew/class_track.cpp +++ b/pcbnew/class_track.cpp @@ -508,9 +508,9 @@ void TRACK::ViewGetLayers( int aLayers[], int& aCount ) const } -unsigned int TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { - const int HIDE = std::numeric_limits::max(); + constexpr double HIDE = std::numeric_limits::max(); if( !aView->IsLayerVisible( LAYER_TRACKS ) ) return HIDE; @@ -518,11 +518,11 @@ unsigned int TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const // Netnames will be shown only if zoom is appropriate if( IsNetnameLayer( aLayer ) ) { - return ( Millimeter2iu( 4 ) / ( m_Width + 1 ) ); + return ( double ) Millimeter2iu( 4 ) / ( m_Width + 1 ); } // Other layers are shown without any conditions - return 0; + return 0.0; } @@ -569,13 +569,13 @@ void VIA::ViewGetLayers( int aLayers[], int& aCount ) const } -unsigned int VIA::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double VIA::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { - constexpr unsigned int HIDE = std::numeric_limits::max(); + constexpr double HIDE = (double)std::numeric_limits::max(); // Netnames will be shown only if zoom is appropriate if( IsNetnameLayer( aLayer ) ) - return m_Width == 0 ? HIDE : ( Millimeter2iu( 10 ) / m_Width ); + return m_Width == 0 ? HIDE : ( (double)Millimeter2iu( 10 ) / m_Width ); bool onVisibleLayer = false; @@ -599,7 +599,7 @@ unsigned int VIA::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const if( !onVisibleLayer && m_ViaType != VIATYPE::THROUGH ) return HIDE; - return aView->IsLayerVisible( LAYER_VIAS ) ? 0 : HIDE; + return aView->IsLayerVisible( LAYER_VIAS ) ? 0.0 : HIDE; } return HIDE; diff --git a/pcbnew/class_track.h b/pcbnew/class_track.h index 61607915f3..e8acc04c74 100644 --- a/pcbnew/class_track.h +++ b/pcbnew/class_track.h @@ -226,7 +226,7 @@ public: virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; - virtual unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; const BOX2I ViewBBox() const override; @@ -438,7 +438,7 @@ public: void ViewGetLayers( int aLayers[], int& aCount ) const override; - unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; void Flip( const wxPoint& aCentre, bool aFlipLeftRight ) override; diff --git a/pcbnew/class_zone.cpp b/pcbnew/class_zone.cpp index 60a7747e03..37e4883b60 100644 --- a/pcbnew/class_zone.cpp +++ b/pcbnew/class_zone.cpp @@ -301,11 +301,11 @@ void ZONE_CONTAINER::ViewGetLayers( int aLayers[], int& aCount ) const } -unsigned int ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { - constexpr unsigned int HIDE = std::numeric_limits::max(); + constexpr double HIDE = std::numeric_limits::max(); - return aView->IsLayerVisible( LAYER_ZONES ) ? 0 : HIDE; + return aView->IsLayerVisible( LAYER_ZONES ) ? 0.0 : HIDE; } @@ -1298,9 +1298,9 @@ EDA_ITEM* MODULE_ZONE_CONTAINER::Clone() const } -unsigned int MODULE_ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const +double MODULE_ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const { - const int HIDE = std::numeric_limits::max(); + constexpr double HIDE = (double)std::numeric_limits::max(); if( !aView ) return 0; @@ -1315,7 +1315,7 @@ unsigned int MODULE_ZONE_CONTAINER::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) return HIDE; // Other layers are shown without any conditions - return 0; + return 0.0; } diff --git a/pcbnew/class_zone.h b/pcbnew/class_zone.h index d86cdcf13a..d5c428f720 100644 --- a/pcbnew/class_zone.h +++ b/pcbnew/class_zone.h @@ -150,7 +150,7 @@ public: virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; - unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; void SetFillMode( ZONE_FILL_MODE aFillMode ) { m_fillMode = aFillMode; } ZONE_FILL_MODE GetFillMode() const { return m_fillMode; } @@ -951,7 +951,7 @@ public: EDA_ITEM* Clone() const override; - unsigned int ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; + double ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const override; }; #endif // CLASS_ZONE_H_ diff --git a/pcbnew/pcb_painter.cpp b/pcbnew/pcb_painter.cpp index 4b7759497b..44f3d6c71d 100644 --- a/pcbnew/pcb_painter.cpp +++ b/pcbnew/pcb_painter.cpp @@ -1152,7 +1152,7 @@ void PCB_PAINTER::draw( const MODULE* aModule, int aLayer ) // Keep the size and width constant, not related to the scale because the anchor // is just a marker on screen double anchorSize = 5.0 / m_gal->GetWorldScale(); // 5 pixels size - double anchorThickness = 2.0 / m_gal->GetWorldScale(); // 2 pixels width + double anchorThickness = 1.0 / m_gal->GetWorldScale(); // 1 pixels width // Draw anchor m_gal->SetIsFill( false ); @@ -1164,7 +1164,7 @@ void PCB_PAINTER::draw( const MODULE* aModule, int aLayer ) m_gal->DrawLine( center - VECTOR2D( anchorSize, 0 ), center + VECTOR2D( anchorSize, 0 ) ); m_gal->DrawLine( center - VECTOR2D( 0, anchorSize ), center + VECTOR2D( 0, anchorSize ) ); -#if 0 // For debug purpose only: draw the bounding box +#if 0 // For debug purpose only: draw the footing bounding box double bboxThickness = 1.0 / m_gal->GetWorldScale(); m_gal->SetLineWidth( bboxThickness ); EDA_RECT rect = aModule->GetBoundingBoxBase();