33#include <wx/filedlg.h>
40#define COL_FRONT_SIDE 1
41#define COL_BOTTOM_SIDE 2
45#define ROW_BOARD_WIDTH 0
46#define ROW_BOARD_HEIGHT 1
47#define ROW_BOARD_AREA 2
79 m_parentFrame(aParentFrame),
83 m_hasOutline( false ),
84 m_startLayerColInitialSize( 1 ),
85 m_stopLayerColInitialSize( 1 )
104 m_gridBoard->SetCellAlignment( 0, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
106 m_gridBoard->SetCellAlignment( 1, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
108 m_gridBoard->SetCellAlignment( 2, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
112 for(
auto&
grid : grids )
115 grid->SetCellHighlightPenWidth( 0 );
116 grid->SetColMinimalAcceptableWidth( 80 );
117 for(
int i = 0; i <
grid->GetNumberRows(); i++ )
118 grid->SetCellAlignment( i,
COL_LABEL, wxALIGN_LEFT, wxALIGN_CENTRE );
126 fn.SetName( fn.GetName() + wxT(
"_report" ) );
127 fn.SetExt( wxT(
"txt" ) );
193 + wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
218 if( ( footprint->GetAttributes() & line.attribute_mask ) == line.attribute_value )
220 switch( footprint->GetSide() )
222 case F_Cu: line.frontSideQty++;
break;
223 case B_Cu: line.backSideQty++;
break;
231 for(
PAD*
pad : footprint->Pads() )
236 if(
pad->GetAttribute() == line.attribute )
243 if(
pad->GetDrillSize().x > 0 &&
pad->GetDrillSize().y > 0 )
247 if(
pad->GetLayerSet().CuStack().empty() )
255 top =
pad->GetLayerSet().CuStack().front();
256 bottom =
pad->GetLayerSet().CuStack().back();
260 pad->GetDrillShape(),
261 pad->GetAttribute() != PAD_ATTRIB::NPTH,
294 if(
via->GetViaType() == line.attribute )
302 PAD_DRILL_SHAPE::CIRCLE,
true,
false,
via->TopLayer(),
303 via->BottomLayer() );
328 bool boundingBoxCreated =
false;
335 bool edgeCutsExists =
false;
341 edgeCutsExists =
true;
346 if( !edgeCutsExists )
361 for(
int j = 0; j < polySet.
HoleCount( i ); j++ )
366 for(
PAD*
pad : fp->Pads() )
368 if( !
pad->HasHole() )
371 auto hole =
pad->GetEffectiveHoleShape();
372 const SEG& seg = hole->GetSeg();
373 double width = hole->GetWidth();
374 double area = seg.
Length() * width;
379 area += M_PI * 0.25 * width * width;
389 double drill =
via->GetDrillValue();
395 if( boundingBoxCreated )
401 bbox = outline.
BBox();
402 boundingBoxCreated =
true;
414 return wxString::Format( wxT(
"%i" ), aCount );
427 totalPads += line.qty;
441 totalVias += line.qty;
461 totalFront += line.frontSideQty;
462 totalBack += line.backSideQty;
479 EDA_DATA_TYPE::AREA ) );
507 wxString startLayerStr;
508 wxString stopLayerStr;
512 case PAD_DRILL_SHAPE::CIRCLE: shapeStr =
_(
"Round" );
break;
513 case PAD_DRILL_SHAPE::OBLONG: shapeStr =
_(
"Slot" );
break;
514 default: shapeStr =
_(
"???" );
break;
518 startLayerStr =
_(
"N/A" );
523 stopLayerStr =
_(
"N/A" );
534 line.isPlated ?
_(
"PTH" ) :
_(
"NPTH" ) );
536 line.isPad ?
_(
"Pad" ) :
_(
"Via" ) );
547 bool aUseFirstColAsLabel )
549 std::vector<int> widths( aGrid->GetNumberCols(), 0 );
550 int rowLabelsWidth = 0;
556 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
557 widths[col] = aGrid->GetColLabelValue( col ).length();
560 for(
int row = 0; row < aGrid->GetNumberRows(); row++ )
562 rowLabelsWidth = std::max<int>( rowLabelsWidth, aGrid->GetRowLabelValue( row ).length() );
564 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
565 widths[col] = std::max<int>( widths[col], aGrid->GetCellValue( row, col ).length() );
576 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
579 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetColLabelValue( col ) );
581 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetCellValue( 0, col ) );
592 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
595 aStr.Append(
'-', widths[col] );
603 int firstRow = 0, firstCol = 0;
608 if( aUseFirstColAsLabel )
611 for(
int row = firstRow; row < aGrid->GetNumberRows(); row++ )
613 if( aUseFirstColAsLabel )
614 tmp.Printf( wxT(
"|%-*s |" ), widths[0], aGrid->GetCellValue( row, 0 ) );
616 tmp.Printf( wxT(
"|" ) );
620 for(
int col = firstCol; col < aGrid->GetNumberCols(); col++ )
622 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetCellValue( row, col ) );
633 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_gridDrills );
640 for(
int i = 0; i <
m_gridDrills->GetNumberCols(); i++ )
646 double scalingFactor = std::max( 1.0,
676 boardName = fn.GetName();
679 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
681 if( dlg.ShowModal() == wxID_CANCEL )
687 outFile = wxFopen( dlg.GetPath(), wxT(
"wt" ) );
689 if( outFile ==
nullptr )
691 msg.Printf(
_(
"Failed to create file '%s'." ), dlg.GetPath() );
696 msg <<
_(
"PCB statistics report\n=====================" ) << wxT(
"\n" );
697 msg << wxS(
"- " ) <<
_(
"Date" ) << wxS(
": " ) << wxDateTime::Now().Format() << wxT(
"\n" );
698 msg << wxS(
"- " ) <<
_(
"Project" ) << wxS(
": " )<<
Prj().
GetProjectName() << wxT(
"\n" );
699 msg << wxS(
"- " ) <<
_(
"Board name" ) << wxS(
": " )<< boardName << wxT(
"\n" );
702 msg <<
_(
"Board" ) << wxT(
"\n-----\n" );
706 msg << wxS(
"- " ) <<
_(
"Width" ) << wxS(
": " )
708 msg << wxS(
"- " ) <<
_(
"Height" ) << wxS(
": " )
710 msg << wxS(
"- " ) <<
_(
"Area" ) + wxS(
": " )
716 msg << wxS(
"- " ) <<
_(
"Width" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
717 msg << wxS(
"- " ) <<
_(
"Height" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
718 msg << wxS(
"- " ) <<
_(
"Area" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
722 msg <<
_(
"Pads" ) << wxT(
"\n----\n" );
725 msg << wxT(
"- " ) << type.title << wxS(
" " ) << type.qty << wxT(
"\n" );
728 msg <<
_(
"Vias" ) << wxT(
"\n----\n" );
731 msg << wxT(
"- " ) << type.title << wxS(
" " ) << type.qty << wxT(
"\n" );
735 std::vector<int> widths;
736 std::vector<wxString> labels{ wxT(
"" ),
_(
"Front Side" ),
_(
"Back Side" ),
_(
"Total" ) };
739 widths.reserve( labels.size() );
741 for(
const wxString& label : labels )
742 widths.push_back( label.size() );
750 widths[0] = std::max<int>( line.title.size(), widths[0] );
751 frontTotal += line.frontSideQty;
752 backTotal += line.backSideQty;
756 tmp.Printf( wxT(
"%i" ), frontTotal );
757 widths[1] = std::max<int>( tmp.size(), widths[1] );
758 tmp.Printf( wxT(
"%i" ), backTotal );
759 widths[2] = std::max<int>( tmp.size(), widths[2] );
760 tmp.Printf( wxT(
"%i" ), frontTotal + backTotal );
761 widths[3] = std::max<int>( tmp.size(), widths[3] );
765 msg <<
_(
"Components" ) << wxT(
"\n----------\n" );
771 msg <<
_(
"Drill holes" ) << wxT(
"\n-----------\n" );
776 if( fprintf( outFile,
"%s",
TO_UTF8( msg ) ) < 0 )
778 msg.Printf(
_(
"Error writing file '%s'." ), dlg.GetPath() );
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Information pertinent to a Pcbnew printed circuit board.
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 & GetFileName() const
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
const DRAWINGS & Drawings() const
size_type GetHeight() const
size_type GetWidth() const
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Class DIALOG_BOARD_STATISTICS_BASE.
wxCheckBox * m_checkBoxSubtractHoles
wxButton * m_sdbControlSizerCancel
wxGrid * m_gridComponents
wxCheckBox * m_checkBoxExcludeComponentsNoPins
void checkboxClicked(wxCommandEvent &aEvent) override
Save board statistics to a file.
void printGridToStringAsTable(wxGrid *aGrid, wxString &aStr, bool aUseColLabels, bool aUseFirstColAsLabel)
std::deque< FP_LINE_ITEM > m_fpTypes
int m_startLayerColInitialSize
Width of the start layer column as calculated by the wxWidgets autosizing algorithm.
void updateWidets()
Update drills grid.
PCB_EDIT_FRAME * m_parentFrame
void saveReportClicked(wxCommandEvent &aEvent) override
std::deque< LINE_ITEM< PAD_ATTRIB > > m_padTypes
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< 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...
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.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a set of closed polygons.
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.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static DIALOG_BOARD_STATISTICS_SAVED_STATE s_savedDialogState
static wxString formatCount(int aCount)
static wxString TextFileWildcard()
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
#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
DIALOG_BOARD_STATISTICS_SAVED_STATE()
wxString saveReportFolder
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition of file extensions used in Kicad.