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 <wxPcbStruct.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)
 

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 69 of file spread_footprints.cpp.

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

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

70 {
71  vecSubRects.clear();
72 
73  for( unsigned ii = 0; ii < aModuleList.size(); ii++ )
74  {
75  EDA_RECT fpBox = aModuleList[ii]->GetBoundingBox();
76  TSubRect fpRect( fpBox.GetWidth()/scale, fpBox.GetHeight()/scale, ii );
77  vecSubRects.push_back( fpRect );
78  }
79 }
int GetHeight() const
const int scale
Class EDA_RECT handles the component boundary box.
int GetWidth() const
void fillRectList ( CSubRectArray vecSubRects,
std::vector< EDA_RECT > &  aRectList 
)

Definition at line 82 of file spread_footprints.cpp.

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

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

Definition at line 137 of file spread_footprints.cpp.

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

Referenced by PCB_EDIT_FRAME::SpreadFootprints().

141 {
142  CSubRectArray vecSubRects;
143 
144  fillRectList( vecSubRects, aModuleList );
145  spreadRectangles( aPlacementArea, vecSubRects,
146  aFreeArea.GetWidth(), aFreeArea.GetHeight() );
147 
148  if( aFindAreaOnly )
149  return;
150 
151  for( unsigned it = 0; it < vecSubRects.size(); ++it )
152  {
153  wxPoint pos( vecSubRects[it].x, vecSubRects[it].y );
154  pos.x *= scale;
155  pos.y *= scale;
156 
157  MODULE * module = aModuleList[vecSubRects[it].n];
158 
159  EDA_RECT fpBBox = module->GetBoundingBox();
160  wxPoint mod_pos = pos + ( module->GetPosition() - fpBBox.GetOrigin() )
161  + aFreeArea.GetOrigin();
162 
163  module->Move( mod_pos - module->GetPosition() );
164  }
165 }
const wxPoint & GetPosition() const override
Definition: class_module.h:155
int GetHeight() const
void fillRectList(CSubRectArray &vecSubRects, std::vector< MODULE * > &aModuleList)
const wxPoint & GetOrigin() const
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
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.
int GetWidth() const
void spreadRectangles(CRectPlacement &aPlacementArea, CSubRectArray &vecSubRects, int areaSizeX, int areaSizeY)
static bool sortFootprintsbySheetPath ( MODULE ref,
MODULE compare 
)
static

Definition at line 372 of file spread_footprints.cpp.

References MODULE::GetPath().

Referenced by PCB_EDIT_FRAME::SpreadFootprints().

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

Definition at line 97 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().

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

Definition at line 66 of file spread_footprints.cpp.

Referenced by EDA_DRAW_FRAME::AdjustScrollBars(), Clamp_Text_PenSize(), KIGFX::GAL::ComputeWorldScreenMatrix(), DIALOG_PLOT_SCHEMATIC::createPSFile(), EDA_DRAW_PANEL::DoPrepareDC(), GBR_LAYOUT::Draw(), KIGFX::PCB_PAINTER::draw(), BITMAP_BASE::DrawBitmap(), KIGFX::OPENGL_GAL::drawLineQuad(), DrawPageOnClipboard(), PCB_EDIT_FRAME::Export_IDF3(), fillRectList(), GENDRILL_WRITER_BASE::genDrillMapFile(), C3D_RENDER_OGL_LEGACY::generate_new_3DGrid(), BASE_SCREEN::GetScalingFactor(), idf_export_module(), idf_export_outline(), GERBVIEW_FRAME::Liste_D_Codes(), SCH_BITMAP::Load(), C3D_RENDER_RAYTRACING::load_3D_models(), moveFootprintsInArea(), PCB_EDIT_FRAME::OnExportVRML(), EDA_DRAW_PANEL::OnMouseEvent(), 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(), DIALOG_PRINT_USING_PRINTER::OnScaleSelectionClick(), EDA_DRAW_PANEL::OnScroll(), DIALOG_PLOT_SCHEMATIC::plotOneSheetSVG(), SCENEGRAPH::Prepare(), DIALOG_RESCUE_EACH::renderPreview(), DIALOG_CHOOSE_COMPONENT::RenderPreview(), 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(), PANEL_PREV_3D::updateOrientation(), PANEL_PREV_3D::ValidateWithMessage(), COMMON_TOOLS::ZoomFitScreen(), and SELECTION_TOOL::zoomFitSelection().