KiCad PCB EDA Suite
spread_footprints.cpp File Reference

functions to spread footprints on free areas outside a board. More...

#include <algorithm>
#include <fctsys.h>
#include <convert_to_biu.h>
#include <class_drawpanel.h>
#include <confirm.h>
#include <pcbnew.h>
#include <pcb_edit_frame.h>
#include <class_board.h>
#include <class_module.h>
#include <rect_placement/rect_placement.h>

Go to the source code of this file.

Classes

struct  TSubRect
 

Typedefs

typedef std::vector< TSubRectCSubRectArray
 

Functions

void fillRectList (CSubRectArray &vecSubRects, std::vector< MODULE * > &aModuleList)
 
void fillRectList (CSubRectArray &vecSubRects, std::vector< EDA_RECT > &aRectList)
 
void spreadRectangles (CRectPlacement &aPlacementArea, CSubRectArray &vecSubRects, int areaSizeX, int areaSizeY)
 
void moveFootprintsInArea (CRectPlacement &aPlacementArea, std::vector< MODULE * > &aModuleList, EDA_RECT &aFreeArea, bool aFindAreaOnly)
 
static bool sortFootprintsbySheetPath (MODULE *ref, MODULE *compare)
 

Variables

const int scale = (int)(0.01 * IU_PER_MM)
 
const int PADDING = (int)(1 * IU_PER_MM)
 

Detailed Description

functions to spread footprints on free areas outside a board.

this is usefull after reading a netlist, when new footprints are loaded and stacked at 0,0 coordinate. Often, spread them on a free area near the board being edited make more easy their selection.

Definition in file spread_footprints.cpp.

Typedef Documentation

typedef std::vector<TSubRect> CSubRectArray

Definition at line 63 of file spread_footprints.cpp.

Function Documentation

void fillRectList ( CSubRectArray vecSubRects,
std::vector< MODULE * > &  aModuleList 
)

Definition at line 71 of file spread_footprints.cpp.

References EDA_RECT::GetHeight(), EDA_RECT::GetWidth(), PADDING, and scale.

Referenced by moveFootprintsInArea(), and PCB_EDIT_FRAME::SpreadFootprints().

72 {
73  vecSubRects.clear();
74 
75  for( unsigned ii = 0; ii < aModuleList.size(); ii++ )
76  {
77  EDA_RECT fpBox = aModuleList[ii]->GetFootprintRect();
78  TSubRect fpRect( ( fpBox.GetWidth() + PADDING ) / scale,
79  ( fpBox.GetHeight() + PADDING ) / scale, ii );
80  vecSubRects.push_back( fpRect );
81  }
82 }
int GetHeight() const
Definition: eda_rect.h:118
const int PADDING
const int scale
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetWidth() const
Definition: eda_rect.h:117
void fillRectList ( CSubRectArray vecSubRects,
std::vector< EDA_RECT > &  aRectList 
)

Definition at line 85 of file spread_footprints.cpp.

References EDA_RECT::GetHeight(), EDA_RECT::GetWidth(), and scale.

86 {
87  vecSubRects.clear();
88 
89  for( unsigned ii = 0; ii < aRectList.size(); ii++ )
90  {
91  EDA_RECT& rect = aRectList[ii];
92  TSubRect fpRect( rect.GetWidth()/scale, rect.GetHeight()/scale, ii );
93  vecSubRects.push_back( fpRect );
94  }
95 }
int GetHeight() const
Definition: eda_rect.h:118
const int scale
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetWidth() const
Definition: eda_rect.h:117
void moveFootprintsInArea ( CRectPlacement aPlacementArea,
std::vector< MODULE * > &  aModuleList,
EDA_RECT aFreeArea,
bool  aFindAreaOnly 
)

Definition at line 140 of file spread_footprints.cpp.

References fillRectList(), MODULE::GetFootprintRect(), EDA_RECT::GetHeight(), EDA_RECT::GetOrigin(), MODULE::GetPosition(), EDA_RECT::GetWidth(), MODULE::Move(), scale, sortFootprintsbySheetPath(), spreadRectangles(), CRectPlacement::TPos::x, wxPoint::x, CRectPlacement::TPos::y, and wxPoint::y.

Referenced by PCB_EDIT_FRAME::SpreadFootprints().

144 {
145  CSubRectArray vecSubRects;
146 
147  fillRectList( vecSubRects, aModuleList );
148  spreadRectangles( aPlacementArea, vecSubRects,
149  aFreeArea.GetWidth(), aFreeArea.GetHeight() );
150 
151  if( aFindAreaOnly )
152  return;
153 
154  for( unsigned it = 0; it < vecSubRects.size(); ++it )
155  {
156  wxPoint pos( vecSubRects[it].x, vecSubRects[it].y );
157  pos.x *= scale;
158  pos.y *= scale;
159 
160  MODULE * module = aModuleList[vecSubRects[it].n];
161 
162  EDA_RECT fpBBox = module->GetFootprintRect();
163  wxPoint mod_pos = pos + ( module->GetPosition() - fpBBox.GetOrigin() )
164  + aFreeArea.GetOrigin();
165 
166  module->Move( mod_pos - module->GetPosition() );
167  }
168 }
const wxPoint GetOrigin() const
Definition: eda_rect.h:112
int GetHeight() const
Definition: eda_rect.h:118
void fillRectList(CSubRectArray &vecSubRects, std::vector< MODULE * > &aModuleList)
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text...
std::vector< TSubRect > CSubRectArray
const int scale
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
int GetWidth() const
Definition: eda_rect.h:117
const wxPoint GetPosition() const override
Definition: class_module.h:184
void spreadRectangles(CRectPlacement &aPlacementArea, CSubRectArray &vecSubRects, int areaSizeX, int areaSizeY)
static bool sortFootprintsbySheetPath ( MODULE ref,
MODULE compare 
)
static

Definition at line 375 of file spread_footprints.cpp.

References MODULE::GetPath().

Referenced by moveFootprintsInArea(), and PCB_EDIT_FRAME::SpreadFootprints().

376 {
377  if( ref->GetPath().Length() == compare->GetPath().Length() )
378  return ref->GetPath().BeforeLast( '/' ).Cmp( compare->GetPath().BeforeLast( '/' ) ) < 0;
379 
380  return ref->GetPath().Length() < compare->GetPath().Length();
381 }
const wxString & GetPath() const
Definition: class_module.h:202
void spreadRectangles ( CRectPlacement aPlacementArea,
CSubRectArray vecSubRects,
int  areaSizeX,
int  areaSizeY 
)

Definition at line 100 of file spread_footprints.cpp.

References CRectPlacement::AddAtEmptySpotAutoGrow(), CRectPlacement::TRect::Greater(), CRectPlacement::Init(), scale, CRectPlacement::TPos::x, and CRectPlacement::TPos::y.

Referenced by moveFootprintsInArea(), and PCB_EDIT_FRAME::SpreadFootprints().

103 {
104  areaSizeX/= scale;
105  areaSizeY/= scale;
106 
107  // Sort the subRects based on dimensions, larger dimension goes first.
108  std::sort( vecSubRects.begin(), vecSubRects.end(), CRectPlacement::TRect::Greater );
109 
110  // gives the initial size to the area
111  aPlacementArea.Init( areaSizeX, areaSizeY );
112 
113  // Add all subrects
114  CSubRectArray::iterator it;
115  for( it = vecSubRects.begin(); it != vecSubRects.end(); )
116  {
117  CRectPlacement::TRect r( 0, 0, it->w, it->h );
118 
119  bool bPlaced = aPlacementArea.AddAtEmptySpotAutoGrow( &r, areaSizeX, areaSizeY );
120 
121  if( !bPlaced ) // No room to place the rectangle: enlarge area and retry
122  {
123  areaSizeX = ceil(areaSizeX * 1.1);
124  areaSizeY = ceil(areaSizeY * 1.1);
125  aPlacementArea.Init( areaSizeX, areaSizeY );
126  it = vecSubRects.begin();
127  continue;
128  }
129 
130  // When correctly placed in a placement area, the coords are returned in r.x and r.y
131  // Store them.
132  it->x = r.x;
133  it->y = r.y;
134 
135  it++;
136  }
137 }
void Init(int w=1, int h=1)
static bool Greater(const TRect &a, const TRect &b)
const int scale
bool AddAtEmptySpotAutoGrow(TRect *pRect, int maxW, int maxH)

Variable Documentation

const int PADDING = (int)(1 * IU_PER_MM)

Definition at line 68 of file spread_footprints.cpp.

Referenced by fillRectList().

const int scale = (int)(0.01 * IU_PER_MM)

Definition at line 66 of file spread_footprints.cpp.

Referenced by Clamp_Text_PenSize(), KIGFX::CAIRO_PRINT_GAL::ComputeWorldScreenMatrix(), KIGFX::GAL::ComputeWorldScreenMatrix(), DIALOG_PLOT_SCHEMATIC::createPSFile(), EDA_DRAW_PANEL::DoPrepareDC(), COMMON_TOOLS::doZoomToPreset(), GBR_LAYOUT::Draw(), KIGFX::SCH_PAINTER::draw(), KIGFX::PCB_PAINTER::draw(), KIGFX::CAIRO_GAL_BASE::DrawBitmap(), KIGFX::OPENGL_GAL::DrawBitmap(), BITMAP_BASE::DrawBitmap(), DrawPageOnClipboard(), PCB_EDIT_FRAME::ExecuteRemoteCommand(), PCB_EDIT_FRAME::Export_IDF3(), fillRectList(), SYMBOL_PREVIEW_WIDGET::fitOnDrawArea(), GENDRILL_WRITER_BASE::genDrillMapFile(), C3D_RENDER_OGL_LEGACY::generate_new_3DGrid(), getScaleFromZoom(), DIALOG_PRINT_GENERIC::getScaleValue(), BASE_SCREEN::GetScalingFactor(), idf_export_module(), idf_export_outline(), GERBVIEW_FRAME::Liste_D_Codes(), C3D_RENDER_RAYTRACING::load_3D_models(), moveFootprintsInArea(), PCB_EDIT_FRAME::OnExportVRML(), EDA_DRAW_PANEL::OnMouseEvent(), EDA_DRAW_PANEL::OnMouseWheel(), EDA_3D_CANVAS::OnPaint(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::onPaintPolyPanel(), DIALOG_LIB_EDIT_PIN::OnPaintShowPanel(), DIALOG_PAD_PROPERTIES::OnPaintShowPanel(), EDA_DRAW_PANEL::OnPan(), DIALOG_IMAGE_EDITOR::OnRedrawPanel(), EDA_DRAW_PANEL::OnScroll(), DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG(), SCENEGRAPH::Prepare(), PCB_EDIT_FRAME::PrepareLayerIndicator(), SCH_BASE_FRAME::RedrawScreen(), SCH_BASE_FRAME::RedrawScreen2(), KIGFX::VERTEX_MANAGER::Scale(), ZOOM_TOOL::selectRegion(), WORKSHEET_DATAITEM_BITMAP::SetPixelScaleFactor(), DIALOG_PLOT_SCHEMATIC::setupPlotPagePDF(), PCB_EDIT_FRAME::SpreadFootprints(), spreadRectangles(), LIB_EDIT_FRAME::SVG_PlotComponent(), DIALOG_IMAGE_EDITOR::TransfertToImage(), DIALOG_PAD_PRIMITIVES_TRANSFORM::Transform(), GERBVIEW_FRAME::updateDCodeSelectBox(), SCH_BASE_FRAME::Window_Zoom(), SCH_BASE_FRAME::Zoom_Automatique(), COMMON_TOOLS::ZoomFitScreen(), GERBVIEW_SELECTION_TOOL::zoomFitSelection(), and SELECTION_TOOL::zoomFitSelection().