40#include <wx/datetime.h>
181 switch( footprint->GetSide() )
205 if( track->GetNetCode() == otherTrack->GetNetCode() )
216 auto trackShapeA = track->GetEffectiveShape( layer );
217 auto trackShapeB = otherTrack->GetEffectiveShape( layer );
241 std::vector<DRILL_LINE_ITEM> drills;
272 for(
int j = 0; j < polySet.
HoleCount( i ); ++j )
281 for(
PAD*
pad : footprint->Pads() )
283 if( !
pad->HasHole() )
286 std::shared_ptr<SHAPE_SEGMENT> hole =
pad->GetEffectiveHoleShape();
291 const SEG& seg = hole->GetSeg();
292 double width = hole->GetWidth();
293 double area = seg.
Length() * width;
295 area +=
M_PI * 0.25 * width * width;
305 double drill =
via->GetDrillValue();
325 int minPadClearanceOuter = netSettings->GetDefaultNetclass()->GetClearance();
333 frontShapesForArea.
Append( frontA );
336 backShapesForArea.
Append( backA );
340 for(
PAD*
pad : fp->Pads() )
342 if( !
pad->HasHole() )
347 pad->TransformShapeToPolygon( frontShapesForArea,
F_Cu,
348 std::min( minPadClearanceOuter,
pad->GetOwnClearance(
F_Cu ) ),
350 pad->TransformShapeToPolygon( backShapesForArea,
B_Cu,
351 std::min( minPadClearanceOuter,
pad->GetOwnClearance(
B_Cu ) ),
440 return wxString::Format( wxT(
"%i" ), aCount );
444static void appendTable(
const std::vector<std::vector<wxString>>& aRows,
bool aUseFirstColAsLabel, wxString& aOut )
449 size_t columnCount = 0;
451 for(
const std::vector<wxString>& row : aRows )
453 if( row.size() > columnCount )
454 columnCount = row.size();
457 if( columnCount == 0 )
460 std::vector<int> widths( columnCount, 0 );
462 for(
const std::vector<wxString>& row : aRows )
464 for(
size_t col = 0; col < columnCount; ++col )
466 if( col >= row.size() )
469 int cellWidth =
static_cast<int>( row[col].length() );
471 if( cellWidth > widths[col] )
472 widths[col] = cellWidth;
477 [&](
const std::vector<wxString>& row,
bool treatFirstAsLabel )
479 if( treatFirstAsLabel && aUseFirstColAsLabel )
482 wxString firstColumn;
485 firstColumn = row[0];
487 formatted.Printf( wxS(
"|%-*s |" ), widths[0], firstColumn );
490 for(
size_t col = 1; col < columnCount; ++col )
493 if( col < row.size() )
496 formatted.Printf( wxS(
" %*s |" ), widths[col], value );
504 for(
size_t col = 0; col < columnCount; ++col )
507 if( col < row.size() )
511 formatted.Printf( wxS(
" %*s |" ), widths[col], value );
519 appendDataRow( aRows.front(),
false );
523 for(
size_t col = 0; col < columnCount; ++col )
525 int dashCount = widths[col] + 2;
532 for(
int i = 0; i < dashCount; ++i )
533 dashes << wxS(
"-" );
535 aOut << dashes << wxS(
"|" );
540 for(
size_t rowIdx = 1; rowIdx < aRows.size(); ++rowIdx )
541 appendDataRow( aRows[rowIdx],
true );
547 if( aValue == std::numeric_limits<int>::max() )
548 return _(
"unknown" );
555 const UNITS_PROVIDER& aUnitsProvider,
const wxString& aProjectName,
556 const wxString& aBoardName )
560 report <<
_(
"PCB statistics report\n=====================" ) << wxS(
"\n" );
561 report << wxS(
"- " ) <<
_(
"Date" ) << wxS(
": " ) << wxDateTime::Now().Format() << wxS(
"\n" );
562 report << wxS(
"- " ) <<
_(
"Project" ) << wxS(
": " ) << aProjectName << wxS(
"\n" );
563 report << wxS(
"- " ) <<
_(
"Board name" ) << wxS(
": " ) << aBoardName << wxS(
"\n\n" );
565 report <<
_(
"Board" ) << wxS(
"\n-----\n" );
571 report << wxS(
"- " ) <<
_(
"Height" ) << wxS(
": " )
573 report << wxS(
"- " ) <<
_(
"Area" ) << wxS(
": " )
578 report << wxS(
"- " ) <<
_(
"Dimensions" ) << wxS(
": " ) <<
_(
"unknown" ) << wxS(
"\n" );
579 report << wxS(
"- " ) <<
_(
"Area" ) << wxS(
": " ) <<
_(
"unknown" ) << wxS(
"\n" );
582 report << wxS(
"- " ) <<
_(
"Front copper area" ) << wxS(
": " )
584 report << wxS(
"- " ) <<
_(
"Back copper area" ) << wxS(
": " )
587 report << wxS(
"- " ) <<
_(
"Min track clearance" ) << wxS(
": " )
590 report << wxS(
"- " ) <<
_(
"Min track width" ) << wxS(
": " )
593 report << wxS(
"- " ) <<
_(
"Min drill diameter" ) << wxS(
": " )
596 report << wxS(
"- " ) <<
_(
"Board stackup thickness" ) << wxS(
": " )
600 report << wxS(
"- " ) <<
_(
"Front footprint area" ) << wxS(
": " )
602 report << wxS(
"- " ) <<
_(
"Back footprint area" ) << wxS(
": " )
605 report << wxS(
"- " ) <<
_(
"Front component density" ) << wxS(
": " );
610 report <<
_(
"unknown" );
612 report << wxS(
"\n" );
614 report << wxS(
"- " ) <<
_(
"Back component density" ) << wxS(
": " );
619 report <<
_(
"unknown" );
621 report << wxS(
"\n" );
623 report <<
_(
"Pads" ) << wxS(
"\n----\n" );
626 report << wxS(
"- " ) << padEntry.
title << wxS(
" " ) << padEntry.
quantity << wxS(
"\n" );
629 report << wxS(
"- " ) << propEntry.
title << wxS(
" " ) << propEntry.
quantity << wxS(
"\n" );
631 report << wxS(
"\n" );
632 report <<
_(
"Vias" ) << wxS(
"\n----\n" );
635 report << wxS(
"- " ) << viaEntry.
title << wxS(
" " ) << viaEntry.
quantity << wxS(
"\n" );
637 report << wxS(
"\n" );
638 report <<
_(
"Components" ) << wxS(
"\n----------\n\n" );
640 std::vector<std::vector<wxString>> componentRows;
641 std::vector<wxString> header;
642 header.push_back( wxString() );
643 header.push_back(
_(
"Front Side" ) );
644 header.push_back(
_(
"Back Side" ) );
645 header.push_back(
_(
"Total" ) );
646 componentRows.push_back( std::move( header ) );
653 std::vector<wxString> row;
654 row.push_back( fpEntry.
title );
658 componentRows.push_back( std::move( row ) );
664 std::vector<wxString> totalRow;
665 totalRow.push_back(
_(
"Total:" ) );
668 totalRow.push_back(
formatCount( frontTotal + backTotal ) );
669 componentRows.push_back( std::move( totalRow ) );
673 report << wxS(
"\n" );
674 report <<
_(
"Drill holes" ) << wxS(
"\n-----------\n\n" );
676 std::vector<std::vector<wxString>> drillRows;
677 std::vector<wxString> drillHeader;
678 drillHeader.push_back(
_(
"Count" ) );
679 drillHeader.push_back(
_(
"Shape" ) );
680 drillHeader.push_back(
_(
"X Size" ) );
681 drillHeader.push_back(
_(
"Y Size" ) );
682 drillHeader.push_back(
_(
"Plated" ) );
683 drillHeader.push_back(
_(
"Via/Pad" ) );
684 drillHeader.push_back(
_(
"Start Layer" ) );
685 drillHeader.push_back(
_(
"Stop Layer" ) );
686 drillRows.push_back( std::move( drillHeader ) );
692 switch( drill.
shape )
696 default: shapeStr =
_(
"???" );
break;
699 wxString platedStr = drill.
isPlated ?
_(
"PTH" ) :
_(
"NPTH" );
700 wxString itemStr = drill.
isPad ?
_(
"Pad" ) :
_(
"Via" );
702 wxString startLayerStr;
703 wxString stopLayerStr;
706 startLayerStr =
_(
"N/A" );
710 startLayerStr =
_(
"N/A" );
713 stopLayerStr =
_(
"N/A" );
717 stopLayerStr =
_(
"N/A" );
719 std::vector<wxString> row;
721 row.push_back( shapeStr );
724 row.push_back( platedStr );
725 row.push_back( itemStr );
726 row.push_back( startLayerStr );
727 row.push_back( stopLayerStr );
728 drillRows.push_back( std::move( row ) );
738 const UNITS_PROVIDER& aUnitsProvider,
const wxString& aProjectName,
739 const wxString& aBoardName )
741 const auto formatMinimum = [&aUnitsProvider](
int aValue ) -> nlohmann::json
743 if( aValue == std::numeric_limits<int>::max() )
744 return nlohmann::json();
749 nlohmann::ordered_json root;
751 nlohmann::ordered_json metadata;
754 metadata[
"project"] = aProjectName;
755 metadata[
"board_name"] = aBoardName;
756 root[
"metadata"] = metadata;
758 nlohmann::ordered_json board;
771 board[
"width"] = nlohmann::json();
772 board[
"height"] = nlohmann::json();
773 board[
"area"] = nlohmann::json();
774 board[
"front_component_density"] = nlohmann::json();
775 board[
"back_component_density"] = nlohmann::json();
783 board[
"min_track_width"] = formatMinimum( aData.
minTrackWidth );
784 board[
"min_drill_diameter"] = formatMinimum( aData.
minDrillSize );
798 board[
"front_footprint_density"] = nlohmann::json();
799 board[
"back_footprint_density"] = nlohmann::json();
802 root[
"board"] = board;
804 nlohmann::ordered_json pads = nlohmann::ordered_json::object();
814 nlohmann::ordered_json vias = nlohmann::ordered_json::object();
823 nlohmann::ordered_json components = nlohmann::ordered_json::object();
827 nlohmann::ordered_json component;
831 components[fpEntry.
jsonKey] = component;
837 nlohmann::ordered_json totals;
838 totals[
"front"] = frontTotal;
839 totals[
"back"] = backTotal;
840 totals[
"total"] = frontTotal + backTotal;
841 components[
"total"] = totals;
843 root[
"components"] = components;
845 nlohmann::ordered_json drillHoles = nlohmann::ordered_json::array();
849 nlohmann::ordered_json drillJson;
853 switch( drill.
shape )
857 default: shapeStr =
_(
"???" );
break;
860 wxString sourceStr = drill.
isPad ?
_(
"Pad" ) :
_(
"Via" );
861 wxString startLayerStr =
_(
"N/A" );
862 wxString stopLayerStr =
_(
"N/A" );
870 drillJson[
"count"] = drill.
m_Qty;
871 drillJson[
"shape"] = shapeStr;
874 drillJson[
"plated"] = drill.
isPlated;
875 drillJson[
"source"] = sourceStr;
876 drillJson[
"start_layer"] = startLayerStr;
877 drillJson[
"stop_layer"] = stopLayerStr;
878 drillHoles.push_back( std::move( drillJson ) );
881 root[
"drill_holes"] = drillHoles;
883 std::string jsonText = root.dump( 2 );
884 return wxString::FromUTF8( jsonText.c_str() );
constexpr int ARC_LOW_DEF
void CollectDrillLineItems(BOARD *board, std::vector< DRILL_LINE_ITEM > &out)
static void updatePadCounts(FOOTPRINT *aFootprint, BOARD_STATISTICS_DATA &aData)
wxString FormatBoardStatisticsJson(const BOARD_STATISTICS_DATA &aData, BOARD *aBoard, const UNITS_PROVIDER &aUnitsProvider, const wxString &aProjectName, const wxString &aBoardName)
void ComputeBoardStatistics(BOARD *aBoard, const BOARD_STATISTICS_OPTIONS &aOptions, BOARD_STATISTICS_DATA &aData)
static wxString formatCount(int aCount)
wxString FormatBoardStatisticsReport(const BOARD_STATISTICS_DATA &aData, BOARD *aBoard, const UNITS_PROVIDER &aUnitsProvider, const wxString &aProjectName, const wxString &aBoardName)
wxString FormatBoardStatisticsMinimum(int aValue, const UNITS_PROVIDER &aUnitsProvider)
Format a minimum distance, or "unknown" when no qualifying measurement was found.
void InitializeBoardStatisticsData(BOARD_STATISTICS_DATA &aData)
static void appendTable(const std::vector< std::vector< wxString > > &aRows, bool aUseFirstColAsLabel, wxString &aOut)
wxString GetBuildVersion()
Get the full KiCad version string.
std::shared_ptr< NET_SETTINGS > m_NetSettings
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
virtual void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const
Convert the item shape to a polyset.
int BuildBoardThicknessFromStackup() const
Information pertinent to a Pcbnew printed circuit board.
BOARD_STACKUP GetStackupOrDefault() const
const FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, bool aInferOutlineIfNecessary, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
KICAD_T Type() const
Returns the type of object.
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
int Length() const
Return the length (this).
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
double Area(bool aAbsolute=true) const
Return the area of this chain.
Represent a set of closed polygons.
double Area()
Return the area of this poly set.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
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)
void Simplify()
Simplify the polyset (merges overlapping polys, eliminates degeneracy/self-intersections)
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the reference to aHole-th hole in the aIndex-th outline.
int OutlineCount() const
Return the number of outlines in the set.
void BooleanSubtract(const SHAPE_POLY_SET &b)
Perform boolean polyset difference.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
Some functions to handle hotkeys in KiCad.
PCB_LAYER_ID
A quick note on layer IDs:
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
@ PRESSFIT
a PTH with a hole diameter with tight tolerances for press fit pin
@ CASTELLATED
a pad with a castellated through hole
bool collide(T aObject, U aAnotherObject, int aLayer, int aMinDistance)
Used by SHAPE_INDEX to implement Query().
wxString GetISO8601CurrentDateTime()
int minClearanceTrackToTrack
std::vector< BOARD_STATISTICS_INFO_ENTRY< PAD_ATTRIB > > padEntries
double backFootprintCourtyardArea
double frontFootprintDensity
std::vector< BOARD_STATISTICS_FP_ENTRY > footprintEntries
std::vector< BOARD_STATISTICS_INFO_ENTRY< VIATYPE > > viaEntries
double backFootprintDensity
double frontFootprintCourtyardArea
std::vector< BOARD_STATISTICS_INFO_ENTRY< PAD_PROP > > padPropertyEntries
std::vector< DRILL_LINE_ITEM > drillEntries
bool subtractHolesFromCopperAreas
bool subtractHolesFromBoardArea
bool excludeFootprintsWithoutPads
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
@ PCB_PAD_T
class PAD, a pad in a footprint
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
VECTOR2< int32_t > VECTOR2I