29#include <wx/filedlg.h>
46#define COL_FRONT_SIDE 1
47#define COL_BOTTOM_SIDE 2
51#define ROW_BOARD_DIMS 0
52#define ROW_BOARD_AREA 1
53#define ROW_FRONT_COPPER_AREA 2
54#define ROW_BACK_COPPER_AREA 3
55#define ROW_MIN_CLEARANCE 4
56#define ROW_MIN_TRACK_WIDTH 5
57#define ROW_MIN_DRILL_DIAMETER 6
58#define ROW_BOARD_THICKNESS 7
142 grid->SetCellHighlightPenWidth( 0 );
143 grid->SetColMinimalAcceptableWidth( 80 );
145 for(
int row = 0; row <
grid->GetNumberRows(); row++ )
147 grid->SetCellAlignment( row,
COL_LABEL, wxALIGN_LEFT, wxALIGN_CENTRE );
150 grid->SetCellAlignment( row, col, wxALIGN_RIGHT, wxALIGN_CENTER );
154 wxFileName fn =
m_frame->GetBoard()->GetFileName();
159 fn.SetName( fn.GetName() + wxT(
"_report" ) );
160 fn.SetExt( wxT(
"txt" ) );
231 + wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
262 if( ( footprint->GetAttributes() & line.m_Attribute_mask ) == line.m_Attribute_value )
264 switch( footprint->GetSide() )
266 case F_Cu: line.m_FrontSideQty++;
break;
267 case B_Cu: line.m_BackSideQty++;
break;
275 for(
PAD*
pad : footprint->Pads() )
280 if(
pad->GetAttribute() == line.m_Attribute )
290 if(
pad->GetProperty() == line.m_Attribute )
310 auto layer = track->GetLayer();
311 auto trackShapeA = track->GetEffectiveShape( layer );
315 if( layer != otherTrack->GetLayer() )
318 if( track->GetNetCode() == otherTrack->GetNetCode() )
325 auto trackShapeB = otherTrack->GetEffectiveShape( layer );
338 if(
via->GetViaType() == line.m_Attribute )
351 std::vector<DRILL_LINE_ITEM> drills;
354 for(
const auto& d : drills )
378 for(
int j = 0; j < polySet.
HoleCount( i ); j++ )
383 for(
PAD*
pad : fp->Pads() )
385 if( !
pad->HasHole() )
388 auto hole =
pad->GetEffectiveHoleShape();
389 const SEG& seg = hole->GetSeg();
390 double width = hole->GetWidth();
391 double area = seg.
Length() * width;
396 area +=
M_PI * 0.25 * width * width;
406 double drill =
via->GetDrillValue();
454 int R =
via->GetDrillValue() / 2;
480 return wxString::Format( wxT(
"%i" ), aCount );
493 totalPads += line.m_Qty;
515 totalVias += line.m_Qty;
535 totalFront += line.m_FrontSideQty;
536 totalBack += line.m_BackSideQty;
548 wxString::Format( wxT(
"%s x %s" ),
596 wxString startLayerStr;
597 wxString stopLayerStr;
603 default: shapeStr =
_(
"???" );
break;
610 startLayerStr =
_(
"N/A" );
615 stopLayerStr =
_(
"N/A" );
635 bool aUseFirstColAsLabel )
637 std::vector<int> widths( aGrid->GetNumberCols(), 0 );
638 int rowLabelsWidth = 0;
644 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
645 widths[col] = (
int) aGrid->GetColLabelValue( col ).length();
648 for(
int row = 0; row < aGrid->GetNumberRows(); row++ )
650 rowLabelsWidth = std::max( rowLabelsWidth, (
int) aGrid->GetRowLabelValue( row ).length() );
652 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
653 widths[col] = std::max( widths[col], (
int) aGrid->GetCellValue( row, col ).length() );
664 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
667 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetColLabelValue( col ) );
669 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetCellValue( 0, col ) );
680 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
683 aStr.Append(
'-', widths[col] );
691 int firstRow = 0, firstCol = 0;
696 if( aUseFirstColAsLabel )
699 for(
int row = firstRow; row < aGrid->GetNumberRows(); row++ )
701 if( aUseFirstColAsLabel )
702 tmp.Printf( wxT(
"|%-*s |" ), widths[0], aGrid->GetCellValue( row, 0 ) );
704 tmp.Printf( wxT(
"|" ) );
708 for(
int col = firstCol; col < aGrid->GetNumberCols(); col++ )
710 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetCellValue( row, col ) );
721 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_gridDrills );
728 for(
int i = 0; i <
m_gridDrills->GetNumberCols(); i++ )
734 double scalingFactor = std::max( 1.0,
763 wxFileName fn =
m_frame->GetBoard()->GetFileName();
764 boardName = fn.GetName();
767 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
769 if( dlg.ShowModal() == wxID_CANCEL )
775 outFile = wxFopen( dlg.GetPath(), wxT(
"wt" ) );
777 if( outFile ==
nullptr )
779 msg.Printf(
_(
"Failed to create file '%s'." ), dlg.GetPath() );
784 msg <<
_(
"PCB statistics report\n=====================" ) << wxT(
"\n" );
785 msg << wxS(
"- " ) <<
_(
"Date" ) << wxS(
": " ) << wxDateTime::Now().Format() << wxT(
"\n" );
786 msg << wxS(
"- " ) <<
_(
"Project" ) << wxS(
": " )<<
Prj().
GetProjectName() << wxT(
"\n" );
787 msg << wxS(
"- " ) <<
_(
"Board name" ) << wxS(
": " )<< boardName << wxT(
"\n" );
790 msg <<
_(
"Board" ) << wxT(
"\n-----\n" );
794 msg << wxS(
"- " ) <<
_(
"Width" ) << wxS(
": " )
796 msg << wxS(
"- " ) <<
_(
"Height" ) << wxS(
": " )
798 msg << wxS(
"- " ) <<
_(
"Area" ) + wxS(
": " )
803 msg << wxS(
"- " ) <<
_(
"Dimensions" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
804 msg << wxS(
"- " ) <<
_(
"Area" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
807 msg << wxS(
"- " ) <<
_(
"Front copper area" ) + wxS(
": " )
809 msg << wxS(
"- " ) <<
_(
"Back copper area" ) + wxS(
": " )
812 msg << wxS(
"- " ) <<
_(
"Min track clearance" ) + wxS(
": " )
815 msg << wxS(
"- " ) <<
_(
"Min track width" ) + wxS(
": " )
818 msg << wxS(
"- " ) <<
_(
"Min drill diameter" ) + wxS(
": " )
821 msg << wxS(
"- " ) <<
_(
"Board stackup thickness" ) + wxS(
": " )
825 msg <<
_(
"Pads" ) << wxT(
"\n----\n" );
828 msg << wxT(
"- " ) << type.m_Title << wxS(
" " ) << type.m_Qty << wxT(
"\n" );
831 msg <<
_(
"Vias" ) << wxT(
"\n----\n" );
834 msg << wxT(
"- " ) << type.m_Title << wxS(
" " ) << type.m_Qty << wxT(
"\n" );
838 std::vector<int> widths;
839 std::vector<wxString> labels{ wxT(
"" ),
_(
"Front Side" ),
_(
"Back Side" ),
_(
"Total" ) };
842 widths.reserve( labels.size() );
844 for(
const wxString& label : labels )
845 widths.push_back( (
int) label.size() );
853 widths[0] = std::max( (
int) line.m_Title.size(), widths[0] );
854 frontTotal += line.m_FrontSideQty;
855 backTotal += line.m_BackSideQty;
859 tmp.Printf( wxT(
"%i" ), frontTotal );
860 widths[1] = std::max( (
int) tmp.size(), widths[1] );
861 tmp.Printf( wxT(
"%i" ), backTotal );
862 widths[2] = std::max( (
int) tmp.size(), widths[2] );
863 tmp.Printf( wxT(
"%i" ), frontTotal + backTotal );
864 widths[3] = std::max( (
int) tmp.size(), widths[3] );
868 msg <<
_(
"Components" ) << wxT(
"\n----------\n" );
874 msg <<
_(
"Drill holes" ) << wxT(
"\n-----------\n" );
879 if( fprintf( outFile,
"%s",
TO_UTF8( msg ) ) < 0 )
881 msg.Printf(
_(
"Error writing file '%s'." ), dlg.GetPath() );
constexpr int ARC_LOW_DEF
void CollectDrillLineItems(BOARD *board, std::vector< DRILL_LINE_ITEM > &out)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
virtual void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc) const
Convert the item shape to a polyset.
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
int BuildBoardThicknessFromStackup() const
Information pertinent to a Pcbnew printed circuit board.
BOARD_STACKUP GetStackupOrDefault() const
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, 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 FOOTPRINTS & Footprints() const
const TRACKS & Tracks() const
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.
constexpr size_type GetWidth() const
constexpr size_type GetHeight() const
wxCheckBox * m_checkBoxSubtractHoles
wxStaticText * m_boardLabel
wxButton * m_sdbControlSizerCancel
wxStaticText * m_padsLabel
DIALOG_BOARD_STATISTICS_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Board Statistics"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxGrid * m_gridComponents
wxCheckBox * m_checkBoxExcludeComponentsNoPins
wxStaticText * m_componentsLabel
wxStaticText * m_viasLabel
wxCheckBox * m_checkBoxSubtractHolesFromCopper
void checkboxClicked(wxCommandEvent &aEvent) override
Save board statistics to a file.
void printGridToStringAsTable(wxGrid *aGrid, wxString &aStr, bool aUseColLabels, bool aUseFirstColAsLabel)
std::deque< INFO_LINE_ITEM< PAD_PROP > > m_padFabProps
std::deque< INFO_LINE_ITEM< PAD_ATTRIB > > m_padTypes
std::deque< FP_LINE_ITEM > m_fpTypes
int m_startLayerColInitialSize
Width of the start layer column as calculated by the wxWidgets autosizing algorithm.
int m_minClearanceTrackToTrack
void updateWidgets()
Update drills grid.
void saveReportClicked(wxCommandEvent &aEvent) override
void updateDrillGrid()
Print grid to string in tabular format.
~DIALOG_BOARD_STATISTICS()
Get data from the PCB board and print it to dialog.
int m_stopLayerColInitialSize
Width of the stop layer column.
DIALOG_BOARD_STATISTICS(PCB_EDIT_FRAME *aParentFrame)
void drillGridSort(wxGridEvent &aEvent)
void refreshItemsTypes()
< Function to fill up all items types to be shown in the dialog.
void drillGridSize(wxSizeEvent &aEvent) override
bool m_hasOutline
Show if board outline properly defined.
void adjustDrillGridColumns()
bool TransferDataToWindow() override
std::deque< DRILL_LINE_ITEM > m_drillTypes
std::deque< INFO_LINE_ITEM< VIATYPE > > m_viaTypes
void getDataFromPCB()
Apply data to dialog widgets.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
KICAD_T Type() const
Returns the type of object.
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
The main frame for Pcbnew.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
virtual const wxString GetProjectName() const
Return the short name of the project.
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.
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.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
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.
static DIALOG_BOARD_STATISTICS_SAVED_STATE s_savedDialogState
#define ROW_BOARD_THICKNESS
#define ROW_BACK_COPPER_AREA
#define ROW_MIN_TRACK_WIDTH
#define ROW_MIN_DRILL_DIAMETER
#define ROW_FRONT_COPPER_AREA
static wxString formatCount(int aCount)
#define ROW_MIN_CLEARANCE
static wxString TextFileWildcard()
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
KICOMMON_API wxFont GetSmallInfoFont(wxWindow *aWindow)
@ 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().
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Footprint attributes (such as SMD, THT, Virtual and so on), which will be shown in the dialog.
Type information, which will be shown in dialog.
The dialog last saved state.
bool saveReportInitialized
bool subtractHolesFromCopper
DIALOG_BOARD_STATISTICS_SAVED_STATE()
wxString saveReportFolder
@ 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
Definition of file extensions used in Kicad.