From 0f9ded9563f344cdc0054b286f174ee055d52de1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 13 Sep 2018 22:29:52 +0100 Subject: [PATCH] Space out placed footprints with some padding. Fixes: lp:1788917 * https://bugs.launchpad.net/kicad/+bug/1788917 --- pcbnew/autorouter/spread_footprints.cpp | 7 +++++-- pcbnew/class_module.cpp | 10 ++++++++-- pcbnew/class_module.h | 3 +-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/pcbnew/autorouter/spread_footprints.cpp b/pcbnew/autorouter/spread_footprints.cpp index 3d7410971a..950c09fe43 100644 --- a/pcbnew/autorouter/spread_footprints.cpp +++ b/pcbnew/autorouter/spread_footprints.cpp @@ -65,6 +65,8 @@ typedef std::vector CSubRectArray; // Use 0.01 mm units to calculate placement, to avoid long calculation time const int scale = (int)(0.01 * IU_PER_MM); +const int PADDING = (int)(1 * IU_PER_MM); + // Populates a list of rectangles, from a list of modules void fillRectList( CSubRectArray& vecSubRects, std::vector & aModuleList ) { @@ -73,7 +75,8 @@ void fillRectList( CSubRectArray& vecSubRects, std::vector & aModuleLis for( unsigned ii = 0; ii < aModuleList.size(); ii++ ) { EDA_RECT fpBox = aModuleList[ii]->GetFootprintRect(); - TSubRect fpRect( fpBox.GetWidth()/scale, fpBox.GetHeight()/scale, ii ); + TSubRect fpRect( ( fpBox.GetWidth() + PADDING ) / scale, + ( fpBox.GetHeight() + PADDING ) / scale, ii ); vecSubRects.push_back( fpRect ); } } @@ -284,7 +287,7 @@ void PCB_EDIT_FRAME::SpreadFootprints( std::vector* aFootprints, islastItem = true; footprintListBySheet.push_back( footprint ); - subsurface += footprint->GetArea(); + subsurface += footprint->GetArea( PADDING ); if( islastItem ) { diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 9b388da993..2e39b4100d 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -62,7 +62,6 @@ MODULE::MODULE( BOARD* parent ) : m_ModuleStatus = MODULE_PADS_LOCKED; m_arflag = 0; m_CntRot90 = m_CntRot180 = 0; - m_Surface = 0.0; m_Link = 0; m_LastEditTime = 0; m_LocalClearance = 0; @@ -464,7 +463,14 @@ void MODULE::DrawEdgesOnly( EDA_DRAW_PANEL* panel, wxDC* DC, const wxPoint& offs void MODULE::CalculateBoundingBox() { m_BoundaryBox = GetFootprintRect(); - m_Surface = std::abs( (double) m_BoundaryBox.GetWidth() * m_BoundaryBox.GetHeight() ); +} + + +double MODULE::GetArea( int aPadding ) const +{ + double w = std::abs( m_BoundaryBox.GetWidth() ) + aPadding; + double h = std::abs( m_BoundaryBox.GetHeight() ) + aPadding; + return w * h; } diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 6fe27d1256..73e62489b9 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -569,7 +569,7 @@ public: */ wxString GetNextPadName( bool aFillSequenceGaps ) const; - double GetArea() const { return m_Surface; } + double GetArea( int aPadding = 0 ) const; timestamp_t GetLink() const { return m_Link; } void SetLink( timestamp_t aLink ) { m_Link = aLink; } @@ -746,7 +746,6 @@ private: ZoneConnection m_ZoneConnection; timestamp_t m_LastEditTime; int m_arflag; ///< Use to trace ratsnest and auto routing. - double m_Surface; ///< Bounding box area timestamp_t m_Link; ///< Temporary logical link used during editing int m_CntRot90; ///< Horizontal automatic placement cost ( 0..10 ). int m_CntRot180; ///< Vertical automatic placement cost ( 0..10 ).