34 #include <wx/filedlg.h> 41 #define COL_FRONT_SIDE 1 42 #define COL_BOTTOM_SIDE 2 46 #define ROW_BOARD_WIDTH 0 47 #define ROW_BOARD_HEIGHT 1 48 #define ROW_BOARD_AREA 2 80 m_parentFrame(aParentFrame),
84 m_hasOutline( false ),
85 m_startLayerColInitialSize( 1 ),
86 m_stopLayerColInitialSize( 1 )
105 m_gridBoard->SetCellAlignment( 0, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
107 m_gridBoard->SetCellAlignment( 1, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
109 m_gridBoard->SetCellAlignment( 2, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
113 for(
auto&
grid : grids )
116 grid->SetCellHighlightPenWidth( 0 );
117 grid->SetColMinimalAcceptableWidth( 80 );
118 for(
int i = 0; i <
grid->GetNumberRows(); i++ )
119 grid->SetCellAlignment( i,
COL_LABEL, wxALIGN_LEFT, wxALIGN_CENTRE );
127 fn.SetName( fn.GetName() + wxT(
"_report" ) );
128 fn.SetExt( wxT(
"txt" ) );
194 + wxSize( wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ), 0 ) );
218 if(( footprint->GetAttributes() & type.attribute ) > 0 )
220 if( footprint->IsFlipped() )
228 for(
PAD*
pad : footprint->Pads() )
233 if(
pad->GetAttribute() == type.attribute )
240 if(
pad->GetDrillSize().x > 0 &&
pad->GetDrillSize().y > 0 )
244 if(
pad->GetLayerSet().CuStack().empty() )
252 top =
pad->GetLayerSet().CuStack().front();
253 bottom =
pad->GetLayerSet().CuStack().back();
284 if(
PCB_VIA*
via = dyn_cast<PCB_VIA*>( track ) )
288 if(
via->GetViaType() == type.attribute )
296 true,
false,
via->TopLayer(),
via->BottomLayer() );
321 bool boundingBoxCreated =
false;
328 bool edgeCutsExists =
false;
334 edgeCutsExists =
true;
339 if( !edgeCutsExists )
354 for(
int j = 0; j < polySet.
HoleCount( i ); j++ )
358 if( boundingBoxCreated )
364 bbox = outline.
BBox();
365 boundingBoxCreated =
true;
385 totalPads += type.qty;
399 totalVias += type.qty;
422 type.frontSideQty + type.backSideQty ) );
423 totalFront += type.frontSideQty;
424 totalBack += type.backSideQty;
474 wxString startLayerStr;
475 wxString stopLayerStr;
480 shapeStr =
_(
"Round" );
483 shapeStr =
_(
"Slot" );
486 shapeStr =
_(
"???" );
491 startLayerStr =
_(
"N/A" );
496 stopLayerStr =
_(
"N/A" );
520 bool aUseRowLabels,
bool aUseColLabels,
521 bool aUseFirstColAsLabel )
523 std::vector<int> widths( aGrid->GetNumberCols(), 0 );
524 int rowLabelsWidth = 0;
530 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
531 widths[col] = aGrid->GetColLabelValue( col ).length();
534 for(
int row = 0; row < aGrid->GetNumberRows(); row++ )
536 rowLabelsWidth = std::max<int>( rowLabelsWidth, aGrid->GetRowLabelValue( row ).length() );
538 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
539 widths[col] = std::max<int>( widths[col], aGrid->GetCellValue( row, col ).length() );
552 aStr.Append(
' ', rowLabelsWidth );
556 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
559 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetColLabelValue( col ) );
561 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetCellValue( 0, col ) );
574 aStr.Append(
'-', rowLabelsWidth );
578 for(
int col = 0; col < aGrid->GetNumberCols(); col++ )
581 aStr.Append(
'-', widths[col] );
589 int firstRow = 0, firstCol = 0;
594 if( !aUseRowLabels && aUseFirstColAsLabel )
597 for(
int row = firstRow; row < aGrid->GetNumberRows(); row++ )
600 tmp.Printf( wxT(
"|%-*s |" ), rowLabelsWidth, aGrid->GetRowLabelValue( row ) );
601 else if( aUseFirstColAsLabel )
602 tmp.Printf( wxT(
"|%-*s |" ), widths[0], aGrid->GetCellValue( row, 0 ) );
604 tmp.Printf( wxT(
"|" ) );
608 for(
int col = firstCol; col < aGrid->GetNumberCols(); col++ )
610 tmp.Printf( wxT(
" %*s |" ), widths[col], aGrid->GetCellValue( row, col ) );
621 wxGridUpdateLocker deferRepaintsTillLeavingScope(
m_gridDrills );
628 for(
int i = 0; i <
m_gridDrills->GetNumberCols(); i++ )
634 double scalingFactor = std::max(
663 boardName = fn.GetName();
664 wxFileDialog saveFileDialog(
this,
_(
"Save Report File" ),
668 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
670 if( saveFileDialog.ShowModal() == wxID_CANCEL )
676 outFile = wxFopen( saveFileDialog.GetPath(), wxT(
"wt" ) );
678 if( outFile ==
nullptr )
680 msg.Printf(
_(
"Failed to create file '%s'." ), saveFileDialog.GetPath() );
685 msg <<
_(
"PCB statistics report\n=====================" ) << wxT(
"\n" );
686 msg << wxS(
"- " ) <<
_(
"Date" ) << wxS(
": " ) << wxDateTime::Now().Format() << wxT(
"\n" );
687 msg << wxS(
"- " ) <<
_(
"Project" ) << wxS(
": " )<<
Prj().
GetProjectName() << wxT(
"\n" );
688 msg << wxS(
"- " ) <<
_(
"Board name" ) << wxS(
": " )<< boardName << wxT(
"\n" );
691 msg <<
_(
"Board" ) << wxT(
"\n-----\n" );
695 msg << wxS(
"- " ) <<
_(
"Width" ) << wxS(
": " ) <<
697 msg << wxS(
"- " ) <<
_(
"Height" ) << wxS(
": " ) <<
699 msg << wxS(
"- " ) <<
_(
"Area" ) + wxS(
": " ) <<
705 msg << wxS(
"- " ) <<
_(
"Width" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
706 msg << wxS(
"- " ) <<
_(
"Height" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
707 msg << wxS(
"- " ) <<
_(
"Area" ) << wxS(
": " ) <<
_(
"unknown" ) << wxT(
"\n" );
711 msg <<
_(
"Pads" ) << wxT(
"\n----\n" );
714 msg << wxT(
"- " ) << type.title << wxS(
" " ) << type.qty << wxT(
"\n" );
717 msg <<
_(
"Vias" ) << wxT(
"\n----\n" );
720 msg << wxT(
"- " ) << type.title << wxS(
" " ) << type.qty << wxT(
"\n" );
724 std::vector<int> widths;
725 std::vector<wxString> labels{ wxEmptyString,
_(
"Front Side" ),
_(
"Back Side" ),
_(
"Total" ) };
728 widths.reserve( labels.size() );
730 for(
const auto& label : labels )
731 widths.push_back( label.size() );
739 widths[0] = std::max<int>( type.title.size(), widths[0] );
740 frontTotal += type.frontSideQty;
741 backTotal += type.backSideQty;
745 tmp.Printf( wxT(
"%i" ), frontTotal );
746 widths[1] = std::max<int>( tmp.size(), widths[1] );
747 tmp.Printf( wxT(
"%i" ), backTotal );
748 widths[2] = std::max<int>( tmp.size(), widths[2] );
749 tmp.Printf( wxT(
"%i" ), frontTotal + backTotal );
750 widths[3] = std::max<int>( tmp.size(), widths[3] );
754 msg <<
_(
"Components" ) << wxT(
"\n----------\n" );
760 msg <<
_(
"Drill holes" ) << wxT(
"\n-----------\n" );
765 if( fprintf( outFile,
"%s",
TO_UTF8( msg ) ) < 0 )
767 msg.Printf(
_(
"Error writing file '%s'." ), saveFileDialog.GetPath() );
bool m_hasOutline
Hold all components types to be shown in the dialog.
typeContainer_t< VIATYPE > viasType_t
wxString MessageTextFromValue(EDA_UNITS aUnits, int aValue, bool aAddUnitLabel, EDA_DATA_TYPE aType)
Convert a value to a string using double notation.
int OutlineCount() const
Return the number of vertices in a given outline/hole.
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Implementation of conversion functions that require both schematic and board internal units.
This file is part of the common library.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
void refreshItemsTypes()
< Function to fill up all items types to be shown in the dialog.
bool TransferDataToWindow() override
Like smd, does not appear on the solder paste layer (default)
Smd pad, appears on the solder paste layer (default)
wxGrid * m_gridComponents
viasTypeList_t m_viasTypes
Hold all drill hole types to be shown in the dialog.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the aIndex-th subpolygon in the set.
void getDataFromPCB()
Apply data to dialog widgets.
wxButton * m_sdbControlSizerCancel
double Area(bool aAbsolute=true) const
Return the area of this chain.
Footprint attributes (such as SMD, THT, Virtual and so on), which will be shown in the dialog.
const wxString & GetFileName() const
void drillGridSize(wxSizeEvent &aEvent) override
int m_startLayerColInitialSize
Width of the stop layer column as calculated by the wxWidgets autosizing algorithm.
This file contains miscellaneous commonly used macros and functions.
double m_boardArea
Show if board outline properly defined.
EDA_UNITS GetUserUnits() const
wxCheckBox * m_checkBoxSubtractHoles
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
like PAD_PTH, but not plated
void drillGridSort(wxGridEvent &aEvent)
~DIALOG_BOARD_STATISTICS()
Get data from the PCB board and print it to dialog.
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.
SHAPE_LINE_CHAIN & Outline(int aIndex)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
coord_type GetWidth() const
FOOTPRINTS & Footprints()
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
void updateDrillGrid()
Print grid to string in tabular format.
Definition of file extensions used in Kicad.
PCB_EDIT_FRAME * m_parentFrame
DIALOG_BOARD_STATISTICS(PCB_EDIT_FRAME *aParentFrame)
void adjustDrillGridColumns()
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
wxFont GetStatusFont(wxWindow *aWindow)
void printGridToStringAsTable(wxGrid *aGrid, wxString &aStr, bool aUseRowLabels, bool aUseColLabels, bool aUseFirstColAsLabel)
wxString saveReportFolder
void updateWidets()
Update drills grid.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_BOARD_STATISTICS_BASE.
DIALOG_BOARD_STATISTICS_SAVED_STATE()
Information pertinent to a Pcbnew printed circuit board.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
PCB_LAYER_ID
A quick note on layer IDs:
The main frame for Pcbnew.
wxCheckBox * m_checkBoxExcludeComponentsNoPins
coord_type GetHeight() const
wxString TextFileWildcard()
void saveReportClicked(wxCommandEvent &aEvent) override
bool saveReportInitialized
padsTypeList_t m_padsTypes
Hold all vias types to be shown in the dialog.
virtual const wxString GetProjectName() const
Return the short name of the project.
static DIALOG_BOARD_STATISTICS_SAVED_STATE s_savedDialogState
void checkboxClicked(wxCommandEvent &aEvent) override
Save board statistics to a file.
drillTypeList_t m_drillTypes
Width of the start layer column as calculated by the wxWidgets autosizing algorithm.
int m_stopLayerColInitialSize
componentsTypeList_t m_componentsTypes
Hold all pads types to be shown in the dialog.
The dialog last saved state.
typeContainer_t< PAD_ATTRIB > padsType_t