2019-07-16 19:34:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Alexander Shuklin, jasuramme@gmail.com
|
2022-02-26 15:58:30 +00:00
|
|
|
* Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2019-07-16 19:34:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include "dialog_board_statistics.h"
|
2020-10-04 15:30:39 +00:00
|
|
|
#include "base_units.h"
|
2022-02-15 00:39:58 +00:00
|
|
|
#include <kiplatform/ui.h>
|
2021-06-06 23:34:21 +00:00
|
|
|
#include <confirm.h>
|
2021-06-06 19:03:10 +00:00
|
|
|
#include <pad.h>
|
2021-03-20 15:35:37 +00:00
|
|
|
#include <macros.h>
|
2019-08-02 09:17:29 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2021-11-17 12:49:21 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
2019-07-16 19:34:07 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
#define COL_LABEL 0
|
|
|
|
#define COL_AMOUNT 1
|
2019-07-16 19:34:07 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
// Defines for components view
|
|
|
|
#define ROW_LABEL 0
|
2019-07-21 14:45:37 +00:00
|
|
|
#define COL_FRONT_SIDE 1
|
|
|
|
#define COL_BOTTOM_SIDE 2
|
|
|
|
#define COL_TOTAL 3
|
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
// Defines for board view
|
|
|
|
#define ROW_BOARD_WIDTH 0
|
|
|
|
#define ROW_BOARD_HEIGHT 1
|
|
|
|
#define ROW_BOARD_AREA 2
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
/**
|
2021-07-19 23:56:05 +00:00
|
|
|
* The dialog last saved state.
|
2019-07-22 19:04:09 +00:00
|
|
|
*/
|
|
|
|
struct DIALOG_BOARD_STATISTICS_SAVED_STATE
|
|
|
|
{
|
2019-08-20 15:08:31 +00:00
|
|
|
DIALOG_BOARD_STATISTICS_SAVED_STATE() :
|
|
|
|
excludeNoPins( false ),
|
2019-07-22 19:04:09 +00:00
|
|
|
subtractHoles( false ),
|
|
|
|
saveReportInitialized(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// Flags to remember last checkboxes state
|
|
|
|
bool excludeNoPins;
|
|
|
|
bool subtractHoles;
|
|
|
|
|
|
|
|
// Variables to save last report file name and folder
|
2019-08-02 09:17:29 +00:00
|
|
|
bool saveReportInitialized; // true after the 3 next string are initialized
|
|
|
|
wxString saveReportFolder; // last report folder
|
|
|
|
wxString saveReportName; // last report filename
|
|
|
|
wxString m_project; // name of the project used to create the last report
|
|
|
|
// used to reinit last state after a project change
|
2019-07-22 19:04:09 +00:00
|
|
|
};
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
static DIALOG_BOARD_STATISTICS_SAVED_STATE s_savedDialogState;
|
|
|
|
|
2019-08-20 15:08:31 +00:00
|
|
|
DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame ) :
|
2019-08-24 15:10:19 +00:00
|
|
|
DIALOG_BOARD_STATISTICS_BASE( aParentFrame ),
|
2022-02-15 16:17:37 +00:00
|
|
|
m_parentFrame(aParentFrame),
|
2019-08-24 15:10:19 +00:00
|
|
|
m_boardWidth( 0 ),
|
|
|
|
m_boardHeight( 0 ),
|
|
|
|
m_boardArea( 0.0 ),
|
2022-02-15 16:17:37 +00:00
|
|
|
m_hasOutline( false ),
|
|
|
|
m_startLayerColInitialSize( 1 ),
|
|
|
|
m_stopLayerColInitialSize( 1 )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
m_gridDrills->Connect( wxEVT_GRID_COL_SORT,
|
|
|
|
wxGridEventHandler( DIALOG_BOARD_STATISTICS::drillGridSort ),
|
|
|
|
nullptr, this );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
m_checkBoxExcludeComponentsNoPins->SetValue( s_savedDialogState.excludeNoPins );
|
|
|
|
m_checkBoxSubtractHoles->SetValue( s_savedDialogState.subtractHoles );
|
2019-07-16 19:34:07 +00:00
|
|
|
|
|
|
|
// Make labels for grids
|
2021-09-11 19:07:33 +00:00
|
|
|
wxFont headingFont = KIUI::GetStatusFont( this );
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridComponents->SetCellValue( ROW_LABEL, COL_FRONT_SIDE, _( "Front Side" ) );
|
|
|
|
m_gridComponents->SetCellFont( ROW_LABEL, COL_FRONT_SIDE, headingFont );
|
2019-08-02 09:17:29 +00:00
|
|
|
m_gridComponents->SetCellValue( ROW_LABEL, COL_BOTTOM_SIDE, _( "Back Side" ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridComponents->SetCellFont( ROW_LABEL, COL_BOTTOM_SIDE, headingFont );
|
|
|
|
m_gridComponents->SetCellValue( ROW_LABEL, COL_TOTAL, _( "Total" ) );
|
|
|
|
m_gridComponents->SetCellFont( ROW_LABEL, COL_TOTAL, headingFont );
|
2019-07-20 20:38:28 +00:00
|
|
|
|
|
|
|
m_gridBoard->SetCellValue( 0, 0, _( "Width:" ) );
|
2019-07-21 10:01:36 +00:00
|
|
|
m_gridBoard->SetCellAlignment( 0, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
|
2019-07-20 20:38:28 +00:00
|
|
|
m_gridBoard->SetCellValue( 1, 0, _( "Height:" ) );
|
2019-07-21 10:01:36 +00:00
|
|
|
m_gridBoard->SetCellAlignment( 1, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
|
2019-07-20 20:38:28 +00:00
|
|
|
m_gridBoard->SetCellValue( 2, 0, _( "Area:" ) );
|
2019-07-21 10:01:36 +00:00
|
|
|
m_gridBoard->SetCellAlignment( 2, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
|
|
|
wxGrid* grids[] = { m_gridComponents, m_gridPads, m_gridVias, m_gridBoard };
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
for( auto& grid : grids )
|
|
|
|
{
|
|
|
|
// Remove wxgrid's selection boxes
|
|
|
|
grid->SetCellHighlightPenWidth( 0 );
|
|
|
|
grid->SetColMinimalAcceptableWidth( 80 );
|
|
|
|
for( int i = 0; i < grid->GetNumberRows(); i++ )
|
|
|
|
grid->SetCellAlignment( i, COL_LABEL, wxALIGN_LEFT, wxALIGN_CENTRE );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxFileName fn = m_parentFrame->GetBoard()->GetFileName();
|
2019-08-02 09:17:29 +00:00
|
|
|
|
2019-08-20 15:08:31 +00:00
|
|
|
if( !s_savedDialogState.saveReportInitialized
|
|
|
|
|| s_savedDialogState.m_project != Prj().GetProjectFullName() )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
fn.SetName( fn.GetName() + wxT( "_report" ) );
|
|
|
|
fn.SetExt( wxT( "txt" ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
s_savedDialogState.saveReportName = fn.GetFullName();
|
|
|
|
s_savedDialogState.saveReportFolder = wxPathOnly( Prj().GetProjectFullName() );
|
2019-08-02 09:17:29 +00:00
|
|
|
s_savedDialogState.m_project = Prj().GetProjectFullName();
|
2019-07-22 19:04:09 +00:00
|
|
|
s_savedDialogState.saveReportInitialized = true;
|
|
|
|
}
|
2019-08-02 09:17:29 +00:00
|
|
|
|
|
|
|
// The wxStdDialogButtonSizer wxID_CANCLE button is in fact a close button
|
|
|
|
// Nothing to cancel:
|
|
|
|
m_sdbControlSizerCancel->SetLabel( _( "Close" ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::refreshItemsTypes()
|
|
|
|
{
|
|
|
|
m_componentsTypes.clear();
|
|
|
|
|
|
|
|
// If you need some more types to be shown, simply add them to the
|
|
|
|
// corresponding list
|
2020-11-13 02:09:34 +00:00
|
|
|
m_componentsTypes.push_back( componentsType_t( FP_THROUGH_HOLE, _( "THT:" ) ) );
|
|
|
|
m_componentsTypes.push_back( componentsType_t( FP_SMD, _( "SMD:" ) ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
|
|
|
|
m_padsTypes.clear();
|
2021-05-01 14:46:50 +00:00
|
|
|
m_padsTypes.push_back( padsType_t( PAD_ATTRIB::PTH, _( "Through hole:" ) ) );
|
|
|
|
m_padsTypes.push_back( padsType_t( PAD_ATTRIB::SMD, _( "SMD:" ) ) );
|
|
|
|
m_padsTypes.push_back( padsType_t( PAD_ATTRIB::CONN, _( "Connector:" ) ) );
|
|
|
|
m_padsTypes.push_back( padsType_t( PAD_ATTRIB::NPTH, _( "NPTH:" ) ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
m_viasTypes.clear();
|
2019-12-28 00:55:11 +00:00
|
|
|
m_viasTypes.push_back( viasType_t( VIATYPE::THROUGH, _( "Through vias:" ) ) );
|
|
|
|
m_viasTypes.push_back( viasType_t( VIATYPE::BLIND_BURIED, _( "Blind/buried:" ) ) );
|
|
|
|
m_viasTypes.push_back( viasType_t( VIATYPE::MICROVIA, _( "Micro vias:" ) ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
// If there not enough rows in grids, append some
|
2019-07-22 19:04:09 +00:00
|
|
|
int appendRows = m_componentsTypes.size() + 2 - m_gridComponents->GetNumberRows();
|
2019-07-21 14:45:37 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
if( appendRows > 0 )
|
|
|
|
m_gridComponents->AppendRows( appendRows );
|
|
|
|
|
|
|
|
appendRows = m_padsTypes.size() + 1 - m_gridPads->GetNumberRows();
|
2019-07-21 14:45:37 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
if( appendRows > 0 )
|
|
|
|
m_gridPads->AppendRows( appendRows );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
|
|
|
appendRows = m_viasTypes.size() + 1 - m_gridVias->GetNumberRows();
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
if( appendRows )
|
|
|
|
m_gridVias->AppendRows( appendRows );
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
bool DIALOG_BOARD_STATISTICS::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
refreshItemsTypes();
|
|
|
|
getDataFromPCB();
|
|
|
|
updateWidets();
|
2022-02-15 00:39:58 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
Layout();
|
2021-11-17 12:49:21 +00:00
|
|
|
m_drillsPanel->Layout();
|
2022-02-15 16:17:37 +00:00
|
|
|
|
2022-02-15 00:39:58 +00:00
|
|
|
m_gridDrills->AutoSizeColumns();
|
2022-02-15 16:17:37 +00:00
|
|
|
m_startLayerColInitialSize = m_gridDrills->GetColSize( drillType_t::COL_START_LAYER );
|
|
|
|
m_stopLayerColInitialSize = m_gridDrills->GetColSize( drillType_t::COL_STOP_LAYER );
|
|
|
|
|
|
|
|
// Add space for the vertical scrollbar, so that it won't overlap with the cells.
|
|
|
|
m_gridDrills->SetMinSize( m_gridDrills->GetEffectiveMinSize()
|
|
|
|
+ wxSize( wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ), 0 ) );
|
|
|
|
|
|
|
|
adjustDrillGridColumns();
|
2022-02-15 00:39:58 +00:00
|
|
|
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2019-07-16 19:34:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::getDataFromPCB()
|
|
|
|
{
|
2020-08-26 21:43:38 +00:00
|
|
|
BOARD* board = m_parentFrame->GetBoard();
|
2022-02-26 15:58:30 +00:00
|
|
|
m_drillTypes.clear();
|
2019-07-16 19:34:07 +00:00
|
|
|
|
2020-10-21 03:48:06 +00:00
|
|
|
// Get footprints and pads count
|
2020-11-13 15:15:52 +00:00
|
|
|
for( FOOTPRINT* footprint : board->Footprints() )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
2020-10-21 03:48:06 +00:00
|
|
|
// Do not proceed footprints with no pads if checkbox checked
|
2020-11-12 23:50:33 +00:00
|
|
|
if( m_checkBoxExcludeComponentsNoPins->GetValue() && ! footprint->Pads().size() )
|
2019-07-16 19:34:07 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// Go through components types list
|
|
|
|
for( auto& type : m_componentsTypes )
|
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if(( footprint->GetAttributes() & type.attribute ) > 0 )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
2020-11-12 23:50:33 +00:00
|
|
|
if( footprint->IsFlipped() )
|
2019-07-16 19:34:07 +00:00
|
|
|
type.backSideQty++;
|
2019-07-21 14:45:37 +00:00
|
|
|
else
|
|
|
|
type.frontSideQty++;
|
2019-07-16 19:34:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-12 23:50:33 +00:00
|
|
|
for( PAD* pad : footprint->Pads() )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
|
|
|
// Go through pads types list
|
|
|
|
for( auto& type : m_padsTypes )
|
|
|
|
{
|
|
|
|
if( pad->GetAttribute() == type.attribute )
|
|
|
|
{
|
|
|
|
type.qty++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
if( pad->GetDrillSize().x > 0 && pad->GetDrillSize().y > 0 )
|
|
|
|
{
|
|
|
|
PCB_LAYER_ID top, bottom;
|
|
|
|
|
|
|
|
if( pad->GetLayerSet().CuStack().empty() )
|
|
|
|
{
|
|
|
|
// The pad is not on any copper layer
|
|
|
|
top = UNDEFINED_LAYER;
|
|
|
|
bottom = UNDEFINED_LAYER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
top = pad->GetLayerSet().CuStack().front();
|
|
|
|
bottom = pad->GetLayerSet().CuStack().back();
|
|
|
|
}
|
|
|
|
|
|
|
|
drillType_t drill( pad->GetDrillSize().x, pad->GetDrillSize().y,
|
2021-05-01 14:46:50 +00:00
|
|
|
pad->GetDrillShape(), pad->GetAttribute() != PAD_ATTRIB::NPTH,
|
2020-11-12 23:50:33 +00:00
|
|
|
true, top, bottom );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
auto it = m_drillTypes.begin();
|
2020-11-12 23:50:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( ; it != m_drillTypes.end(); ++it )
|
2019-11-10 20:30:58 +00:00
|
|
|
{
|
|
|
|
if( *it == drill )
|
|
|
|
{
|
|
|
|
it->qty++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( it == m_drillTypes.end() )
|
|
|
|
{
|
|
|
|
drill.qty = 1;
|
|
|
|
m_drillTypes.push_back( drill );
|
|
|
|
m_gridDrills->InsertRows();
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
// Get via counts
|
2021-06-11 21:07:02 +00:00
|
|
|
for( PCB_TRACK* track : board->Tracks() )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
2021-06-11 21:07:02 +00:00
|
|
|
if( PCB_VIA* via = dyn_cast<PCB_VIA*>( track ) )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
2019-08-25 15:46:53 +00:00
|
|
|
for( auto& type : m_viasTypes )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
2019-08-25 15:46:53 +00:00
|
|
|
if( via->GetViaType() == type.attribute )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
2019-08-25 15:46:53 +00:00
|
|
|
type.qty++;
|
|
|
|
break;
|
2019-07-22 19:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
drillType_t drill( via->GetDrillValue(), via->GetDrillValue(), PAD_DRILL_SHAPE_CIRCLE,
|
2020-11-12 23:50:33 +00:00
|
|
|
true, false, via->TopLayer(), via->BottomLayer() );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
auto it = m_drillTypes.begin();
|
2020-11-12 23:50:33 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( ; it != m_drillTypes.end(); ++it )
|
2019-11-10 20:30:58 +00:00
|
|
|
{
|
|
|
|
if( *it == drill )
|
|
|
|
{
|
|
|
|
it->qty++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( it == m_drillTypes.end() )
|
|
|
|
{
|
|
|
|
drill.qty = 1;
|
|
|
|
m_drillTypes.push_back( drill );
|
|
|
|
m_gridDrills->InsertRows();
|
|
|
|
}
|
2019-07-22 19:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
sort( m_drillTypes.begin(), m_drillTypes.end(),
|
2020-11-12 23:50:33 +00:00
|
|
|
drillType_t::COMPARE( drillType_t::COL_COUNT, false ) );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
bool boundingBoxCreated = false; //flag if bounding box initialized
|
|
|
|
BOX2I bbox;
|
|
|
|
SHAPE_POLY_SET polySet;
|
|
|
|
m_hasOutline = board->GetBoardPolygonOutlines( polySet );
|
|
|
|
|
|
|
|
// If board has no Edge Cuts lines, board->GetBoardPolygonOutlines will
|
|
|
|
// return small rectangle, so we double check that
|
|
|
|
bool edgeCutsExists = false;
|
2020-08-26 21:43:38 +00:00
|
|
|
|
|
|
|
for( BOARD_ITEM* drawing : board->Drawings() )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
|
|
|
if( drawing->GetLayer() == Edge_Cuts )
|
|
|
|
{
|
|
|
|
edgeCutsExists = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !edgeCutsExists )
|
|
|
|
m_hasOutline = false;
|
|
|
|
|
|
|
|
if( m_hasOutline )
|
|
|
|
{
|
2019-08-25 15:46:53 +00:00
|
|
|
m_boardArea = 0.0;
|
|
|
|
|
|
|
|
for( int i = 0; i < polySet.OutlineCount(); i++ )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
2019-08-20 15:08:31 +00:00
|
|
|
SHAPE_LINE_CHAIN& outline = polySet.Outline( i );
|
2021-05-09 19:01:47 +00:00
|
|
|
m_boardArea += outline.Area();
|
2019-07-16 19:34:07 +00:00
|
|
|
|
|
|
|
// If checkbox "subtract holes" is checked
|
|
|
|
if( m_checkBoxSubtractHoles->GetValue() )
|
|
|
|
{
|
2019-08-24 15:10:19 +00:00
|
|
|
for( int j = 0; j < polySet.HoleCount( i ); j++ )
|
2021-05-09 19:01:47 +00:00
|
|
|
m_boardArea -= polySet.Hole( i, j ).Area();
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( boundingBoxCreated )
|
|
|
|
{
|
|
|
|
bbox.Merge( outline.BBox() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bbox = outline.BBox();
|
|
|
|
boundingBoxCreated = true;
|
|
|
|
}
|
|
|
|
}
|
2019-08-24 15:10:19 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
m_boardWidth = bbox.GetWidth();
|
|
|
|
m_boardHeight = bbox.GetHeight();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::updateWidets()
|
|
|
|
{
|
2021-03-06 09:27:41 +00:00
|
|
|
int totalPads = 0;
|
2019-07-16 19:34:07 +00:00
|
|
|
int currentRow = 0;
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const auto& type : m_padsTypes )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridPads->SetCellValue( currentRow, COL_LABEL, type.title );
|
2021-07-19 23:56:05 +00:00
|
|
|
m_gridPads->SetCellValue( currentRow, COL_AMOUNT,
|
|
|
|
wxString::Format( wxT( "%i " ), type.qty ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
totalPads += type.qty;
|
|
|
|
currentRow++;
|
|
|
|
}
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridPads->SetCellValue( currentRow, COL_LABEL, _( "Total:" ) );
|
2022-02-04 22:44:59 +00:00
|
|
|
m_gridPads->SetCellValue( currentRow, COL_AMOUNT, wxString::Format( wxT( "%i " ), totalPads ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
|
|
|
int totalVias = 0;
|
|
|
|
currentRow = 0;
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const auto& type : m_viasTypes )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
|
|
|
m_gridVias->SetCellValue( currentRow, COL_LABEL, type.title );
|
2022-02-04 22:44:59 +00:00
|
|
|
m_gridVias->SetCellValue( currentRow, COL_AMOUNT, wxString::Format( wxT( "%i " ), type.qty ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
totalVias += type.qty;
|
|
|
|
currentRow++;
|
|
|
|
}
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridVias->SetCellValue( currentRow, COL_LABEL, _( "Total:" ) );
|
2022-02-04 22:44:59 +00:00
|
|
|
m_gridVias->SetCellValue( currentRow, COL_AMOUNT, wxString::Format( wxT( "%i " ), totalVias ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
|
|
|
|
int totalFront = 0;
|
2021-03-06 09:27:41 +00:00
|
|
|
int totalBack = 0;
|
2019-07-16 19:34:07 +00:00
|
|
|
|
|
|
|
// We don't use row 0, as there labels are
|
|
|
|
currentRow = 1;
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const auto& type : m_componentsTypes )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridComponents->SetCellValue( currentRow, COL_LABEL, type.title );
|
2022-02-04 22:44:59 +00:00
|
|
|
m_gridComponents->SetCellValue( currentRow, COL_FRONT_SIDE,
|
|
|
|
wxString::Format( wxT( "%i " ), type.frontSideQty ) );
|
|
|
|
m_gridComponents->SetCellValue( currentRow, COL_BOTTOM_SIDE,
|
|
|
|
wxString::Format( wxT( "%i " ), type.backSideQty ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
m_gridComponents->SetCellValue( currentRow, 3,
|
2022-02-04 22:44:59 +00:00
|
|
|
wxString::Format( wxT( "%i " ),
|
|
|
|
type.frontSideQty + type.backSideQty ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
totalFront += type.frontSideQty;
|
2021-03-06 09:27:41 +00:00
|
|
|
totalBack += type.backSideQty;
|
2019-07-16 19:34:07 +00:00
|
|
|
currentRow++;
|
|
|
|
}
|
2019-11-10 20:30:58 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridComponents->SetCellValue( currentRow, COL_LABEL, _( "Total:" ) );
|
2019-07-21 14:45:37 +00:00
|
|
|
m_gridComponents->SetCellValue( currentRow, COL_FRONT_SIDE,
|
2022-02-04 22:44:59 +00:00
|
|
|
wxString::Format( wxT( "%i " ), totalFront ) );
|
2019-08-02 09:17:29 +00:00
|
|
|
m_gridComponents->SetCellValue( currentRow, COL_BOTTOM_SIDE,
|
2022-02-04 22:44:59 +00:00
|
|
|
wxString::Format( wxT( "%i " ), totalBack ) );
|
2019-08-20 15:08:31 +00:00
|
|
|
m_gridComponents->SetCellValue( currentRow, COL_TOTAL,
|
2022-02-04 22:44:59 +00:00
|
|
|
wxString::Format( wxT( "%i " ), totalFront + totalBack ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
|
|
|
|
if( m_hasOutline )
|
|
|
|
{
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridBoard->SetCellValue( ROW_BOARD_WIDTH, COL_AMOUNT,
|
2022-02-04 22:44:59 +00:00
|
|
|
MessageTextFromValue( GetUserUnits(),
|
|
|
|
m_boardWidth ) + wxS( " " ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridBoard->SetCellValue( ROW_BOARD_HEIGHT, COL_AMOUNT,
|
2022-02-04 22:44:59 +00:00
|
|
|
MessageTextFromValue( GetUserUnits(),
|
|
|
|
m_boardHeight ) + wxS( " " ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridBoard->SetCellValue( ROW_BOARD_AREA, COL_AMOUNT,
|
2021-07-19 23:56:05 +00:00
|
|
|
MessageTextFromValue( GetUserUnits(), m_boardArea, true,
|
|
|
|
EDA_DATA_TYPE::AREA ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridBoard->SetCellValue( ROW_BOARD_WIDTH, COL_AMOUNT, _( "unknown" ) );
|
|
|
|
m_gridBoard->SetCellValue( ROW_BOARD_HEIGHT, COL_AMOUNT, _( "unknown" ) );
|
|
|
|
m_gridBoard->SetCellValue( ROW_BOARD_AREA, COL_AMOUNT, _( "unknown" ) );
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
updateDrillGrid();
|
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
m_gridComponents->AutoSize();
|
|
|
|
m_gridPads->AutoSize();
|
|
|
|
m_gridBoard->AutoSize();
|
2019-07-22 19:04:09 +00:00
|
|
|
m_gridVias->AutoSize();
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
adjustDrillGridColumns();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::updateDrillGrid()
|
|
|
|
{
|
|
|
|
BOARD* board = m_parentFrame->GetBoard();
|
|
|
|
int currentRow = 0;
|
|
|
|
|
2021-03-06 09:27:41 +00:00
|
|
|
for( const auto& type : m_drillTypes )
|
2019-11-10 20:30:58 +00:00
|
|
|
{
|
|
|
|
wxString shapeStr;
|
|
|
|
wxString startLayerStr;
|
|
|
|
wxString stopLayerStr;
|
|
|
|
|
|
|
|
switch( type.shape )
|
|
|
|
{
|
|
|
|
case PAD_DRILL_SHAPE_CIRCLE:
|
|
|
|
shapeStr = _( "Round" );
|
|
|
|
break;
|
|
|
|
case PAD_DRILL_SHAPE_OBLONG:
|
|
|
|
shapeStr = _( "Slot" );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
shapeStr = _( "???" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( type.startLayer == UNDEFINED_LAYER )
|
|
|
|
startLayerStr = _( "N/A" );
|
|
|
|
else
|
|
|
|
startLayerStr = board->GetLayerName( type.startLayer );
|
|
|
|
|
|
|
|
if( type.stopLayer == UNDEFINED_LAYER )
|
|
|
|
stopLayerStr = _( "N/A" );
|
|
|
|
else
|
|
|
|
stopLayerStr = board->GetLayerName( type.stopLayer );
|
|
|
|
|
|
|
|
m_gridDrills->SetCellValue(
|
2022-02-04 22:44:59 +00:00
|
|
|
currentRow, drillType_t::COL_COUNT, wxString::Format( wxT( "%i" ), type.qty ) );
|
2019-11-10 20:30:58 +00:00
|
|
|
m_gridDrills->SetCellValue( currentRow, drillType_t::COL_SHAPE, shapeStr );
|
|
|
|
m_gridDrills->SetCellValue( currentRow, drillType_t::COL_X_SIZE,
|
|
|
|
MessageTextFromValue( GetUserUnits(), type.xSize ) );
|
|
|
|
m_gridDrills->SetCellValue( currentRow, drillType_t::COL_Y_SIZE,
|
|
|
|
MessageTextFromValue( GetUserUnits(), type.ySize ) );
|
|
|
|
m_gridDrills->SetCellValue(
|
|
|
|
currentRow, drillType_t::COL_PLATED, type.isPlated ? _( "PTH" ) : _( "NPTH" ) );
|
|
|
|
m_gridDrills->SetCellValue(
|
|
|
|
currentRow, drillType_t::COL_VIA_PAD, type.isPad ? _( "Pad" ) : _( "Via" ) );
|
|
|
|
m_gridDrills->SetCellValue( currentRow, drillType_t::COL_START_LAYER, startLayerStr );
|
|
|
|
m_gridDrills->SetCellValue( currentRow, drillType_t::COL_STOP_LAYER, stopLayerStr );
|
|
|
|
|
|
|
|
currentRow++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::printGridToStringAsTable( wxGrid* aGrid, wxString& aStr,
|
2021-07-19 23:56:05 +00:00
|
|
|
bool aUseRowLabels, bool aUseColLabels,
|
|
|
|
bool aUseFirstColAsLabel )
|
2019-11-10 20:30:58 +00:00
|
|
|
{
|
|
|
|
std::vector<int> widths( aGrid->GetNumberCols(), 0 );
|
|
|
|
int rowLabelsWidth = 0;
|
|
|
|
|
|
|
|
// Determine column widths.
|
|
|
|
|
|
|
|
if( aUseColLabels )
|
|
|
|
{
|
|
|
|
for( int col = 0; col < aGrid->GetNumberCols(); col++ )
|
|
|
|
widths[col] = aGrid->GetColLabelValue( col ).length();
|
|
|
|
}
|
|
|
|
|
|
|
|
for( int row = 0; row < aGrid->GetNumberRows(); row++ )
|
|
|
|
{
|
|
|
|
rowLabelsWidth = std::max<int>( rowLabelsWidth, aGrid->GetRowLabelValue( row ).length() );
|
|
|
|
|
|
|
|
for( int col = 0; col < aGrid->GetNumberCols(); col++ )
|
|
|
|
widths[col] = std::max<int>( widths[col], aGrid->GetCellValue( row, col ).length() );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print the cells.
|
|
|
|
|
|
|
|
wxString tmp;
|
|
|
|
|
|
|
|
// Print column labels.
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "|" );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
if( aUseRowLabels )
|
|
|
|
{
|
|
|
|
aStr.Append( ' ', rowLabelsWidth );
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( " |" );
|
2019-11-10 20:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( int col = 0; col < aGrid->GetNumberCols(); col++ )
|
|
|
|
{
|
|
|
|
if( aUseColLabels )
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetColLabelValue( col ) );
|
2019-11-10 20:30:58 +00:00
|
|
|
else
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetCellValue( 0, col ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
aStr << tmp;
|
|
|
|
}
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "\n" );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
// Print column label horizontal separators.
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "|" );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
if( aUseRowLabels )
|
|
|
|
{
|
|
|
|
aStr.Append( '-', rowLabelsWidth );
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "-|" );
|
2019-11-10 20:30:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( int col = 0; col < aGrid->GetNumberCols(); col++ )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "-" );
|
2019-11-10 20:30:58 +00:00
|
|
|
aStr.Append( '-', widths[col] );
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "-|" );
|
2019-11-10 20:30:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "\n" );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
// Print regular cells.
|
|
|
|
|
|
|
|
int firstRow = 0, firstCol = 0;
|
|
|
|
|
|
|
|
if( !aUseColLabels )
|
|
|
|
firstRow = 1;
|
|
|
|
|
|
|
|
if( !aUseRowLabels && aUseFirstColAsLabel )
|
|
|
|
firstCol = 1;
|
|
|
|
|
|
|
|
for( int row = firstRow; row < aGrid->GetNumberRows(); row++ )
|
|
|
|
{
|
|
|
|
if( aUseRowLabels )
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( "|%-*s |" ), rowLabelsWidth, aGrid->GetRowLabelValue( row ) );
|
2019-11-10 20:30:58 +00:00
|
|
|
else if( aUseFirstColAsLabel )
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( "|%-*s |" ), widths[0], aGrid->GetCellValue( row, 0 ) );
|
2019-11-10 20:30:58 +00:00
|
|
|
else
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( "|" ) );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
aStr << tmp;
|
|
|
|
|
|
|
|
for( int col = firstCol; col < aGrid->GetNumberCols(); col++ )
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetCellValue( row, col ) );
|
2019-11-10 20:30:58 +00:00
|
|
|
aStr << tmp;
|
|
|
|
}
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
aStr << wxT( "\n" );
|
2019-11-10 20:30:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::adjustDrillGridColumns()
|
|
|
|
{
|
2022-02-15 00:39:58 +00:00
|
|
|
wxGridUpdateLocker deferRepaintsTillLeavingScope( m_gridDrills );
|
|
|
|
|
2022-02-15 16:17:37 +00:00
|
|
|
m_gridDrills->EnsureColLabelsVisible();
|
|
|
|
|
|
|
|
double remainingWidth = KIPLATFORM::UI::GetUnobscuredSize( m_gridDrills ).x;
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
// Find the total current width
|
|
|
|
for( int i = 0; i < m_gridDrills->GetNumberCols(); i++ )
|
|
|
|
{
|
|
|
|
if( i != drillType_t::COL_START_LAYER && i != drillType_t::COL_STOP_LAYER )
|
2022-02-15 16:17:37 +00:00
|
|
|
remainingWidth -= m_gridDrills->GetColSize( i );
|
2019-11-10 20:30:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-15 16:17:37 +00:00
|
|
|
double scalingFactor = std::max(
|
|
|
|
1.0, remainingWidth / ( m_startLayerColInitialSize + m_stopLayerColInitialSize ) );
|
|
|
|
int startLayerColWidth = static_cast<int>( m_startLayerColInitialSize * scalingFactor );
|
|
|
|
int stopLayerColWidth = static_cast<int>( m_stopLayerColInitialSize * scalingFactor );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
2022-02-15 16:17:37 +00:00
|
|
|
m_gridDrills->SetColSize( drillType_t::COL_START_LAYER, startLayerColWidth );
|
|
|
|
m_gridDrills->SetColSize( drillType_t::COL_STOP_LAYER, stopLayerColWidth );
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::checkboxClicked( wxCommandEvent& aEvent )
|
2019-07-16 19:34:07 +00:00
|
|
|
{
|
2019-07-22 19:04:09 +00:00
|
|
|
s_savedDialogState.excludeNoPins = m_checkBoxExcludeComponentsNoPins->GetValue();
|
|
|
|
s_savedDialogState.subtractHoles = m_checkBoxSubtractHoles->GetValue();
|
|
|
|
refreshItemsTypes();
|
|
|
|
getDataFromPCB();
|
|
|
|
updateWidets();
|
|
|
|
Layout();
|
2021-11-17 12:49:21 +00:00
|
|
|
m_drillsPanel->Layout();
|
2019-07-22 19:04:09 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
|
|
|
FILE* outFile;
|
|
|
|
wxString msg;
|
|
|
|
wxString boardName;
|
|
|
|
|
|
|
|
wxFileName fn = m_parentFrame->GetBoard()->GetFileName();
|
|
|
|
boardName = fn.GetName();
|
2019-08-20 15:08:31 +00:00
|
|
|
wxFileDialog saveFileDialog( this, _( "Save Report File" ),
|
|
|
|
s_savedDialogState.saveReportFolder,
|
|
|
|
s_savedDialogState.saveReportName,
|
|
|
|
TextFileWildcard(),
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
|
|
|
if( saveFileDialog.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
s_savedDialogState.saveReportFolder = wxPathOnly( saveFileDialog.GetPath() );
|
|
|
|
s_savedDialogState.saveReportName = saveFileDialog.GetFilename();
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
outFile = wxFopen( saveFileDialog.GetPath(), wxT( "wt" ) );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
if( outFile == nullptr )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
2021-06-28 23:44:07 +00:00
|
|
|
msg.Printf( _( "Failed to create file '%s'." ), saveFileDialog.GetPath() );
|
2019-07-22 19:04:09 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
return;
|
|
|
|
}
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << _( "PCB statistics report\n=====================" ) << wxT( "\n" );
|
|
|
|
msg << wxS( "- " ) << _( "Date" ) << wxS( ": " ) << wxDateTime::Now().Format() << wxT( "\n" );
|
|
|
|
msg << wxS( "- " ) << _( "Project" ) << wxS( ": " )<< Prj().GetProjectName() << wxT( "\n" );
|
|
|
|
msg << wxS( "- " ) << _( "Board name" ) << wxS( ": " )<< boardName << wxT( "\n" );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "\n" );
|
|
|
|
msg << _( "Board" ) << wxT( "\n-----\n" );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
|
|
|
if( m_hasOutline )
|
|
|
|
{
|
2021-07-19 23:56:05 +00:00
|
|
|
msg << wxS( "- " ) << _( "Width" ) << wxS( ": " ) <<
|
2022-02-04 22:44:59 +00:00
|
|
|
MessageTextFromValue( GetUserUnits(), m_boardWidth ) << wxT( "\n" );
|
2021-07-19 23:56:05 +00:00
|
|
|
msg << wxS( "- " ) << _( "Height" ) << wxS( ": " ) <<
|
2022-02-04 22:44:59 +00:00
|
|
|
MessageTextFromValue( GetUserUnits(), m_boardHeight ) << wxT( "\n" );
|
2021-07-19 23:56:05 +00:00
|
|
|
msg << wxS( "- " ) << _( "Area" ) + wxS( ": " ) <<
|
|
|
|
MessageTextFromValue( GetUserUnits(), m_boardArea, true, EDA_DATA_TYPE::AREA );
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "\n" );
|
2019-07-22 19:04:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxS( "- " ) << _( "Width" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
|
|
|
|
msg << wxS( "- " ) << _( "Height" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
|
|
|
|
msg << wxS( "- " ) << _( "Area" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
|
2019-07-22 19:04:09 +00:00
|
|
|
}
|
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "\n" );
|
|
|
|
msg << _( "Pads" ) << wxT( "\n----\n" );
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
for( auto& type : m_padsTypes )
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "- " ) << type.title << wxS( " " ) << type.qty << wxT( "\n" );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "\n" );
|
|
|
|
msg << _( "Vias" ) << wxT( "\n----\n" );
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
for( auto& type : m_viasTypes )
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "- " ) << type.title << wxS( " " ) << type.qty << wxT( "\n" );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
|
|
|
// We will save data about components in the table.
|
|
|
|
// We have to calculate column widths
|
2019-11-10 20:30:58 +00:00
|
|
|
std::vector<int> widths;
|
2022-02-04 22:44:59 +00:00
|
|
|
std::vector<wxString> labels{ wxT( "" ), _( "Front Side" ), _( "Back Side" ), _( "Total" ) };
|
2019-07-22 19:04:09 +00:00
|
|
|
wxString tmp;
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
widths.reserve( labels.size() );
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& label : labels )
|
2019-11-10 20:30:58 +00:00
|
|
|
widths.push_back( label.size() );
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
int frontTotal = 0;
|
|
|
|
int backTotal = 0;
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& type : m_componentsTypes )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
|
|
|
// Get maximum width for left label column
|
2019-11-10 20:30:58 +00:00
|
|
|
widths[0] = std::max<int>( type.title.size(), widths[0] );
|
2019-07-22 19:04:09 +00:00
|
|
|
frontTotal += type.frontSideQty;
|
|
|
|
backTotal += type.backSideQty;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get maximum width for other columns
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( "%i" ), frontTotal );
|
2019-11-10 20:30:58 +00:00
|
|
|
widths[1] = std::max<int>( tmp.size(), widths[1] );
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( "%i" ), backTotal );
|
2019-11-10 20:30:58 +00:00
|
|
|
widths[2] = std::max<int>( tmp.size(), widths[2] );
|
2022-02-04 22:44:59 +00:00
|
|
|
tmp.Printf( wxT( "%i" ), frontTotal + backTotal );
|
2019-11-10 20:30:58 +00:00
|
|
|
widths[3] = std::max<int>( tmp.size(), widths[3] );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
|
|
|
//Write components amount to file
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "\n" );
|
|
|
|
msg << _( "Components" ) << wxT( "\n----------\n" );
|
|
|
|
msg << wxT( "\n" );
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
printGridToStringAsTable( m_gridComponents, msg, false, false, true );
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2022-02-04 22:44:59 +00:00
|
|
|
msg << wxT( "\n" );
|
|
|
|
msg << _( "Drill holes" ) << wxT( "\n-----------\n" );
|
|
|
|
msg << wxT( "\n" );
|
2019-11-10 20:30:58 +00:00
|
|
|
|
|
|
|
printGridToStringAsTable( m_gridDrills, msg, false, true, false );
|
2019-07-22 19:04:09 +00:00
|
|
|
|
2019-08-20 15:08:31 +00:00
|
|
|
if( fprintf( outFile, "%s", TO_UTF8( msg ) ) < 0 )
|
2019-07-22 19:04:09 +00:00
|
|
|
{
|
2021-06-16 22:35:00 +00:00
|
|
|
msg.Printf( _( "Error writing file '%s'." ), saveFileDialog.GetPath() );
|
2019-07-22 19:04:09 +00:00
|
|
|
DisplayErrorMessage( this, msg );
|
|
|
|
}
|
2019-08-20 15:08:31 +00:00
|
|
|
|
2019-07-22 19:04:09 +00:00
|
|
|
fclose( outFile );
|
2019-07-16 19:34:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-11-10 20:30:58 +00:00
|
|
|
void DIALOG_BOARD_STATISTICS::drillGridSize( wxSizeEvent& aEvent )
|
|
|
|
{
|
|
|
|
aEvent.Skip();
|
|
|
|
adjustDrillGridColumns();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DIALOG_BOARD_STATISTICS::drillGridSort( wxGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
drillType_t::COL_ID colId = static_cast<drillType_t::COL_ID>( aEvent.GetCol() );
|
2019-11-12 12:47:35 +00:00
|
|
|
bool ascending =
|
2019-11-10 20:30:58 +00:00
|
|
|
!( m_gridDrills->IsSortingBy( colId ) && m_gridDrills->IsSortOrderAscending() );
|
|
|
|
|
|
|
|
sort( m_drillTypes.begin(), m_drillTypes.end(), drillType_t::COMPARE( colId, ascending ) );
|
|
|
|
|
|
|
|
updateDrillGrid();
|
|
|
|
}
|
|
|
|
|
2021-07-19 23:56:05 +00:00
|
|
|
|
2019-07-16 19:34:07 +00:00
|
|
|
DIALOG_BOARD_STATISTICS::~DIALOG_BOARD_STATISTICS()
|
|
|
|
{
|
|
|
|
}
|