KiCad PCB EDA Suite
class_board.cpp File Reference
#include <algorithm>
#include <iterator>
#include <fctsys.h>
#include <pcb_base_frame.h>
#include <reporter.h>
#include <ws_proxy_view_item.h>
#include <class_board.h>
#include <class_module.h>
#include <class_track.h>
#include <class_zone.h>
#include <class_marker_pcb.h>
#include <class_drawsegment.h>
#include <class_pcb_target.h>
#include <connectivity/connectivity_data.h>
#include <pgm_base.h>
#include <pcbnew_settings.h>
#include <project.h>
#include <project/net_settings.h>
#include <project/project_file.h>
#include <project/project_local_settings.h>
#include <ratsnest/ratsnest_data.h>
#include <ratsnest/ratsnest_viewitem.h>

Go to the source code of this file.

Functions

static bool sortNetsByNodes (const NETINFO_ITEM *a, const NETINFO_ITEM *b)
 
static bool sortNetsByNames (const NETINFO_ITEM *a, const NETINFO_ITEM *b)
 
bool sortPadsByXthenYCoord (D_PAD *const &ref, D_PAD *const &comp)
 Function SortPadsByXCoord is used by GetSortedPadListByXCoord to Sort a pad list by x coordinate value. More...
 
bool BuildBoardPolygonOutlines (BOARD *aBoard, SHAPE_POLY_SET &aOutlines, wxString *aErrorText, unsigned int aTolerance, wxPoint *aErrorLocation=nullptr)
 

Variables

static std::vector< int > padCountListByNet
 

Function Documentation

◆ BuildBoardPolygonOutlines()

bool BuildBoardPolygonOutlines ( BOARD aBoard,
SHAPE_POLY_SET aOutlines,
wxString *  aErrorText,
unsigned int  aTolerance,
wxPoint aErrorLocation = nullptr 
)

Definition at line 768 of file convert_drawsegment_list_to_polygon.cpp.

770 {
771  PCB_TYPE_COLLECTOR items;
772  bool success = false;
773 
774  // Get all the DRAWSEGMENTS and module graphics into 'items',
775  // then keep only those on layer == Edge_Cuts.
776  static const KICAD_T scan_graphics[] = { PCB_LINE_T, PCB_MODULE_EDGE_T, EOT };
777  items.Collect( aBoard, scan_graphics );
778 
779  // Make a working copy of aSegList, because the list is modified during calculations
780  std::vector< DRAWSEGMENT* > segList;
781 
782  for( int ii = 0; ii < items.GetCount(); ii++ )
783  {
784  if( items[ii]->GetLayer() == Edge_Cuts )
785  segList.push_back( static_cast< DRAWSEGMENT* >( items[ii] ) );
786  }
787 
788  if( segList.size() )
789  {
790  success = ConvertOutlineToPolygon( segList, aOutlines, aErrorText, aTolerance,
791  aErrorLocation );
792  }
793 
794  if( !success || !aOutlines.OutlineCount() )
795  {
796  // Couldn't create a valid polygon outline. Use the board edge cuts bounding box to
797  // create a rectangular outline, or, failing that, the bounding box of the items on
798  // the board.
799 
800  EDA_RECT bbbox = aBoard->GetBoardEdgesBoundingBox();
801 
802  // If null area, uses the global bounding box.
803  if( ( bbbox.GetWidth() ) == 0 || ( bbbox.GetHeight() == 0 ) )
804  bbbox = aBoard->ComputeBoundingBox();
805 
806  // Ensure non null area. If happen, gives a minimal size.
807  if( ( bbbox.GetWidth() ) == 0 || ( bbbox.GetHeight() == 0 ) )
808  bbbox.Inflate( Millimeter2iu( 1.0 ) );
809 
810  aOutlines.RemoveAllContours();
811  aOutlines.NewOutline();
812 
813  wxPoint corner;
814  aOutlines.Append( bbbox.GetOrigin() );
815 
816  corner.x = bbbox.GetOrigin().x;
817  corner.y = bbbox.GetEnd().y;
818  aOutlines.Append( corner );
819 
820  aOutlines.Append( bbbox.GetEnd() );
821 
822  corner.x = bbbox.GetEnd().x;
823  corner.y = bbbox.GetOrigin().y;
824  aOutlines.Append( corner );
825  }
826 
827  return success;
828 }
int OutlineCount() const
Returns the number of outlines in the set
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:798
int GetWidth() const
Definition: eda_rect.h:119
bool ConvertOutlineToPolygon(std::vector< DRAWSEGMENT * > &aSegList, SHAPE_POLY_SET &aPolygons, wxString *aErrorText, unsigned int aTolerance, wxPoint *aErrorLocation)
Function ConvertOutlineToPolygon build a polygon (with holes) from a DRAWSEGMENT list,...
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101
const wxPoint GetEnd() const
Definition: eda_rect.h:116
const wxPoint GetOrigin() const
Definition: eda_rect.h:114
int NewOutline()
Creates a new empty polygon in the set and returns its index
void Collect(BOARD_ITEM *aBoard, const KICAD_T aScanList[])
Collect BOARD_ITEM objects using this class's Inspector method, which does the collection.
Definition: collectors.cpp:577
int GetHeight() const
Definition: eda_rect.h:120
void RemoveAllContours()
Removes all outlines & holes (clears) the polygon set.
EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
static bool GetLayer(MODEL_VRML &aModel, LAYER_NUM layer, VRML_LAYER **vlayer)
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
Collect all BOARD_ITEM objects of a given set of KICAD_T type(s).
Definition: collectors.h:621
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
static constexpr int Millimeter2iu(double mm)
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)

Referenced by BOARD::GetBoardPolygonOutlines().

◆ sortNetsByNames()

static bool sortNetsByNames ( const NETINFO_ITEM a,
const NETINFO_ITEM b 
)
static

Definition at line 1182 of file class_board.cpp.

1183 {
1184  return a->GetNetname() < b->GetNetname();
1185 }
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231

References NETINFO_ITEM::GetNetname().

Referenced by BOARD::SortedNetnamesList().

◆ sortNetsByNodes()

static bool sortNetsByNodes ( const NETINFO_ITEM a,
const NETINFO_ITEM b 
)
static

Definition at line 1170 of file class_board.cpp.

1171 {
1172  int countA = padCountListByNet[a->GetNet()];
1173  int countB = padCountListByNet[b->GetNet()];
1174 
1175  if( countA == countB )
1176  return a->GetNetname() < b->GetNetname();
1177  else
1178  return countB < countA;
1179 }
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
static std::vector< int > padCountListByNet

References NETINFO_ITEM::GetNet(), NETINFO_ITEM::GetNetname(), and padCountListByNet.

Referenced by BOARD::SortedNetnamesList().

◆ sortPadsByXthenYCoord()

bool sortPadsByXthenYCoord ( D_PAD *const &  ref,
D_PAD *const &  comp 
)

Function SortPadsByXCoord is used by GetSortedPadListByXCoord to Sort a pad list by x coordinate value.

This function is used to build ordered pads lists

Definition at line 1483 of file class_board.cpp.

1484 {
1485  if( ref->GetPosition().x == comp->GetPosition().x )
1486  return ref->GetPosition().y < comp->GetPosition().y;
1487  return ref->GetPosition().x < comp->GetPosition().x;
1488 }
wxPoint GetPosition() const override
Definition: class_pad.h:165

References D_PAD::GetPosition(), wxPoint::x, and wxPoint::y.

Referenced by BOARD::GetSortedPadListByXthenYCoord().

Variable Documentation

◆ padCountListByNet

std::vector<int> padCountListByNet
static

Definition at line 1166 of file class_board.cpp.

Referenced by BOARD::SortedNetnamesList(), and sortNetsByNodes().