From bb290abe91e7e47596ee93c8a9ec383e82a54816 Mon Sep 17 00:00:00 2001 From: Alexander Date: Tue, 16 Jul 2019 22:34:07 +0300 Subject: [PATCH] added board statistics dialog, which shows info for production and assembly --- pcbnew/CMakeLists.txt | 3 + pcbnew/dialogs/dialog_board_statistics.cpp | 252 ++++++++ pcbnew/dialogs/dialog_board_statistics.h | 121 ++++ .../dialogs/dialog_board_statistics_base.cpp | 183 ++++++ .../dialogs/dialog_board_statistics_base.fbp | 558 ++++++++++++++++++ pcbnew/dialogs/dialog_board_statistics_base.h | 55 ++ pcbnew/menubar_pcb_editor.cpp | 1 + pcbnew/pcb_edit_frame.cpp | 2 + pcbnew/tools/pcb_actions.cpp | 5 + pcbnew/tools/pcb_actions.h | 1 + pcbnew/tools/pcb_inspection_tool.cpp | 45 ++ pcbnew/tools/pcb_inspection_tool.h | 55 ++ 12 files changed, 1281 insertions(+) create mode 100644 pcbnew/dialogs/dialog_board_statistics.cpp create mode 100644 pcbnew/dialogs/dialog_board_statistics.h create mode 100644 pcbnew/dialogs/dialog_board_statistics_base.cpp create mode 100644 pcbnew/dialogs/dialog_board_statistics_base.fbp create mode 100644 pcbnew/dialogs/dialog_board_statistics_base.h create mode 100644 pcbnew/tools/pcb_inspection_tool.cpp create mode 100644 pcbnew/tools/pcb_inspection_tool.h diff --git a/pcbnew/CMakeLists.txt b/pcbnew/CMakeLists.txt index 78da642800..dc4f8d7650 100644 --- a/pcbnew/CMakeLists.txt +++ b/pcbnew/CMakeLists.txt @@ -54,6 +54,8 @@ set( PCBNEW_DIALOGS dialogs/dialog_block_options.cpp dialogs/dialog_block_options_base.cpp dialogs/dialog_board_setup.cpp + dialogs/dialog_board_statistics.cpp + dialogs/dialog_board_statistics_base.cpp dialogs/dialog_choose_footprint.cpp dialogs/dialog_cleanup_tracks_and_vias.cpp dialogs/dialog_cleanup_tracks_and_vias_base.cpp @@ -304,6 +306,7 @@ set( PCBNEW_CLASS_SRCS tools/pcb_actions.cpp tools/pcb_bright_box.cpp tools/pcb_editor_control.cpp + tools/pcb_inspection_tool.cpp tools/pcb_selection_conditions.cpp tools/pcb_tool_base.cpp tools/pcbnew_control.cpp diff --git a/pcbnew/dialogs/dialog_board_statistics.cpp b/pcbnew/dialogs/dialog_board_statistics.cpp new file mode 100644 index 0000000000..dbd6e2856d --- /dev/null +++ b/pcbnew/dialogs/dialog_board_statistics.cpp @@ -0,0 +1,252 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 Alexander Shuklin, jasuramme@gmail.com + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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" + + +DIALOG_BOARD_STATISTICS::DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame ) + : DIALOG_BOARD_STATISTICS_BASE( aParentFrame ) +{ + m_parentFrame = aParentFrame; + + // Remove wxgrid's selection boxes + m_gridComponents->SetCellHighlightPenWidth( 0 ); + m_gridPads->SetCellHighlightPenWidth( 0 ); + m_gridBoard->SetCellHighlightPenWidth( 0 ); + m_gridComponents->SetColMinimalAcceptableWidth( 80 ); + m_gridPads->SetColMinimalAcceptableWidth( 80 ); + m_gridBoard->SetColMinimalAcceptableWidth( 80 ); + + // Make labels for grids + m_gridBoard->SetCellValue( 0, 0, _( "Width" ) ); + m_gridBoard->SetCellValue( 1, 0, _( "Height" ) ); + m_gridBoard->SetCellValue( 2, 0, _( "Area" ) ); + m_gridComponents->SetCellValue( 0, 1, _( "Front Side" ) ); + m_gridComponents->SetCellValue( 0, 2, _( "Bottom Side" ) ); + m_gridComponents->SetCellValue( 0, 3, _( "Total" ) ); +} + +void DIALOG_BOARD_STATISTICS::refreshItemsTypes() +{ + m_componentsTypes.clear(); + + // If you need some more types to be shown, simply add them to the + // corresponding list + m_componentsTypes.push_back( componentsType_t( MOD_CMS, _( "THT" ) ) ); + m_componentsTypes.push_back( componentsType_t( MOD_DEFAULT, _( "SMD" ) ) ); + m_componentsTypes.push_back( componentsType_t( MOD_VIRTUAL, _( "Virtual" ) ) ); + + m_padsTypes.clear(); + m_padsTypes.push_back( padsType_t( PAD_ATTRIB_STANDARD, _( "THT" ) ) ); + 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_HOLE_NOT_PLATED, _( "NPH" ) ) ); + + // If there not enough rows in grids, append some + size_t appendRows = m_componentsTypes.size() + 2 - m_gridComponents->GetNumberRows(); + if( appendRows > 0 ) + m_gridComponents->AppendRows( appendRows ); + + appendRows = m_padsTypes.size() + 1 - m_gridPads->GetNumberRows(); + if( appendRows > 0 ) + m_gridPads->AppendRows( appendRows ); +} + +bool DIALOG_BOARD_STATISTICS::TransferDataToWindow() +{ + refreshItemsTypes(); + getDataFromPCB(); + updateWidets(); + Layout(); + FinishDialogSettings(); + return true; +} + +void DIALOG_BOARD_STATISTICS::getDataFromPCB() +{ + auto board = m_parentFrame->GetBoard(); + + for( MODULE* module : board->Modules() ) + { + auto& pads = module->Pads(); + + // Do not proceed modules with no pads if checkbox checked + if( m_checkBoxExcludeComponentsNoPins->GetValue() && !pads.size() ) + continue; + + // Go through components types list + for( auto& type : m_componentsTypes ) + { + if( module->GetAttributes() == type.attribute ) + { + if( module->IsFlipped() ) + type.frontSideQty++; + else + type.backSideQty++; + break; + } + } + + for( auto& pad : pads ) + { + // Go through pads types list + for( auto& type : m_padsTypes ) + { + if( pad->GetAttribute() == type.attribute ) + { + type.qty++; + break; + } + } + } + } + + 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; + for( auto& drawing : board->Drawings() ) + { + if( drawing->GetLayer() == Edge_Cuts ) + { + edgeCutsExists = true; + break; + } + } + + if( !edgeCutsExists ) + m_hasOutline = false; + + if( m_hasOutline ) + { + m_boardArea = 0; + int outlinesCount = polySet.OutlineCount(); + for( int i = 0; i < outlinesCount; i++ ) + { + auto& outline = polySet.Outline( i ); + m_boardArea += abs( outline.Area() ); + + // If checkbox "subtract holes" is checked + if( m_checkBoxSubtractHoles->GetValue() ) + { + int holesCount = polySet.HoleCount( i ); + for( int j = 0; j < holesCount; j++ ) + { + m_boardArea -= abs( polySet.Hole( i, j ).Area() ); + } + } + + if( boundingBoxCreated ) + { + bbox.Merge( outline.BBox() ); + } + else + { + bbox = outline.BBox(); + boundingBoxCreated = true; + } + } + m_boardWidth = bbox.GetWidth(); + m_boardHeight = bbox.GetHeight(); + } +} + +void DIALOG_BOARD_STATISTICS::updateWidets() +{ + int totalPads = 0; + int currentRow = 0; + for( auto& type : m_padsTypes ) + { + m_gridPads->SetCellValue( currentRow, 0, type.title ); + m_gridPads->SetCellValue( currentRow, 1, wxString::Format( wxT( "%i " ), type.qty ) ); + totalPads += type.qty; + currentRow++; + } + m_gridPads->SetCellValue( currentRow, 0, _( "Total" ) ); + m_gridPads->SetCellValue( currentRow, 1, wxString::Format( wxT( "%i " ), totalPads ) ); + + int totalFront = 0; + int totalBack = 0; + + // We don't use row 0, as there labels are + currentRow = 1; + for( auto& type : m_componentsTypes ) + { + m_gridComponents->SetCellValue( currentRow, 0, type.title ); + m_gridComponents->SetCellValue( + currentRow, 1, wxString::Format( wxT( "%i " ), type.frontSideQty ) ); + m_gridComponents->SetCellValue( + currentRow, 2, wxString::Format( wxT( "%i " ), type.backSideQty ) ); + m_gridComponents->SetCellValue( currentRow, 3, + wxString::Format( wxT( "%i " ), type.frontSideQty + type.backSideQty ) ); + totalFront += type.frontSideQty; + totalBack += type.backSideQty; + currentRow++; + } + m_gridComponents->SetCellValue( currentRow, 0, _( "Total" ) ); + m_gridComponents->SetCellValue( currentRow, 1, wxString::Format( wxT( "%i " ), totalFront ) ); + m_gridComponents->SetCellValue( currentRow, 2, wxString::Format( wxT( "%i " ), totalBack ) ); + m_gridComponents->SetCellValue( + currentRow, 3, wxString::Format( wxT( "%i " ), totalFront + totalBack ) ); + + if( m_hasOutline ) + { + m_gridBoard->SetCellValue( 0, 1, + MessageTextFromValue( m_parentFrame->GetUserUnits(), m_boardWidth, false ) + " " ); + m_gridBoard->SetCellValue( 1, 1, + MessageTextFromValue( m_parentFrame->GetUserUnits(), m_boardHeight, false ) + " " ); + if( GetUserUnits() == INCHES ) + m_boardArea /= ( IU_PER_MILS * IU_PER_MILS * 1000000 ); + else + m_boardArea /= ( IU_PER_MM * IU_PER_MM ); + m_gridBoard->SetCellValue( 2, 1, + wxString::Format( wxT( "%.3f %s²" ), m_boardArea, + GetAbbreviatedUnitsLabel( GetUserUnits(), false ) ) ); + } + else + { + m_gridBoard->SetCellValue( 0, 1, _( "unknown" ) ); + m_gridBoard->SetCellValue( 1, 1, _( "unknown" ) ); + m_gridBoard->SetCellValue( 2, 1, _( "unknown" ) ); + } + + m_gridComponents->AutoSize(); + m_gridPads->AutoSize(); + m_gridBoard->AutoSize(); +} + +// If any checkbox clicked, we have to refresh dialog data +void DIALOG_BOARD_STATISTICS::checkboxClicked( wxCommandEvent& event ) +{ + TransferDataToWindow(); +} + +DIALOG_BOARD_STATISTICS::~DIALOG_BOARD_STATISTICS() +{ +} diff --git a/pcbnew/dialogs/dialog_board_statistics.h b/pcbnew/dialogs/dialog_board_statistics.h new file mode 100644 index 0000000000..5f26cd2808 --- /dev/null +++ b/pcbnew/dialogs/dialog_board_statistics.h @@ -0,0 +1,121 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 Alexander Shuklin, jasuramme@gmail.com + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + + +#ifndef _DIALOG_BOARD_STATISTICS_H +#define _DIALOG_BOARD_STATISTICS_H + + +#include +#include +#include +#include +#include +#include +#include + + +/** + * Class DIALOG_BOARD_STATISTIC + * + * Dialog to show common board info. + */ +class DIALOG_BOARD_STATISTICS : public DIALOG_BOARD_STATISTICS_BASE +{ +public: + /** + * Struct holds information about pad type (such as SMD, THT, NPH + * and so on), which will be shown in the dialog. Also holds quantity + * of pads + */ + struct padsType_t + { + padsType_t( PAD_ATTR_T aAttribute, wxString aTitle ) + : attribute( aAttribute ), + title( aTitle ), + qty( 0 ) + { + } + PAD_ATTR_T attribute; + wxString title; + int qty; + }; + + /** + * Struct holds information about component type (such as SMD, THT, + * Virtual and so on), which will be shown in the dialog. Holds both + * front and bottom components quantities + */ + struct componentsType_t + { + componentsType_t( MODULE_ATTR_T aAttribute, wxString aTitle ) + : attribute( aAttribute ), + title( aTitle ), + frontSideQty( 0 ), + backSideQty( 0 ) + { + } + MODULE_ATTR_T attribute; + wxString title; + int frontSideQty; + int backSideQty; + }; + + using componentsTypeList_t = std::deque; + using padsTypeList_t = std::deque; + + DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame ); + ~DIALOG_BOARD_STATISTICS(); + + ///> Get data from the PCB board and print it to dialog + bool TransferDataToWindow() override; + + ///> Function to fill up all items types to be shown in the dialog. + void inline refreshItemsTypes(); + + ///> Gets data from board + void inline getDataFromPCB(); + + ///> Applies data to dialog widgets + void inline updateWidets(); + + void checkboxClicked( wxCommandEvent& event ) override; + +private: + PCB_EDIT_FRAME* m_parentFrame; + int m_boardWidth; + int m_boardHeight; + double m_boardArea; + + ///> Shows if board outline properly defined + bool m_hasOutline; + + ///> Holds all components types to be shown in the dialog + componentsTypeList_t m_componentsTypes; + + ///> Holds all pads types to be shown in the dialog + padsTypeList_t m_padsTypes; +}; + +#endif // __DIALOG_BOARD_STATISTICS_H diff --git a/pcbnew/dialogs/dialog_board_statistics_base.cpp b/pcbnew/dialogs/dialog_board_statistics_base.cpp new file mode 100644 index 0000000000..2cdf488d03 --- /dev/null +++ b/pcbnew/dialogs/dialog_board_statistics_base.cpp @@ -0,0 +1,183 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 25 2019) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#include "dialog_board_statistics_base.h" + +/////////////////////////////////////////////////////////////////////////// + +DIALOG_BOARD_STATISTICS_BASE::DIALOG_BOARD_STATISTICS_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) ); + + wxBoxSizer* bMainBoxSizer; + bMainBoxSizer = new wxBoxSizer( wxVERTICAL ); + + wxGridBagSizer* gbConentsSizer; + gbConentsSizer = new wxGridBagSizer( 5, 10 ); + gbConentsSizer->SetFlexibleDirection( wxBOTH ); + gbConentsSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); + + wxStaticBoxSizer* sbComponentsSizer; + sbComponentsSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Components") ), wxVERTICAL ); + + m_gridComponents = new wxGrid( sbComponentsSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL ); + + // Grid + m_gridComponents->CreateGrid( 5, 4 ); + m_gridComponents->EnableEditing( false ); + m_gridComponents->EnableGridLines( false ); + m_gridComponents->SetGridLineColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) ); + m_gridComponents->EnableDragGridSize( false ); + m_gridComponents->SetMargins( 0, 0 ); + + // Columns + m_gridComponents->EnableDragColMove( false ); + m_gridComponents->EnableDragColSize( true ); + m_gridComponents->SetColLabelSize( 0 ); + m_gridComponents->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Rows + m_gridComponents->EnableDragRowSize( true ); + m_gridComponents->SetRowLabelSize( 0 ); + m_gridComponents->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Label Appearance + m_gridComponents->SetLabelBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ); + m_gridComponents->SetLabelFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); + + // Cell Defaults + m_gridComponents->SetDefaultCellBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) ); + m_gridComponents->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + m_gridComponents->SetMaxSize( wxSize( -1,400 ) ); + + sbComponentsSizer->Add( m_gridComponents, 0, wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxLEFT|wxRIGHT|wxTOP, 5 ); + + + gbConentsSizer->Add( sbComponentsSizer, wxGBPosition( 0, 0 ), wxGBSpan( 2, 1 ), wxEXPAND, 5 ); + + wxStaticBoxSizer* sbPadsSizer; + sbPadsSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Pads") ), wxVERTICAL ); + + m_gridPads = new wxGrid( sbPadsSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL ); + + // Grid + m_gridPads->CreateGrid( 5, 2 ); + m_gridPads->EnableEditing( false ); + m_gridPads->EnableGridLines( false ); + m_gridPads->SetGridLineColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) ); + m_gridPads->EnableDragGridSize( false ); + m_gridPads->SetMargins( 10, 0 ); + + // Columns + m_gridPads->EnableDragColMove( false ); + m_gridPads->EnableDragColSize( true ); + m_gridPads->SetColLabelSize( 0 ); + m_gridPads->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Rows + m_gridPads->EnableDragRowSize( true ); + m_gridPads->SetRowLabelSize( 0 ); + m_gridPads->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Label Appearance + m_gridPads->SetLabelBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ); + m_gridPads->SetLabelFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); + + // Cell Defaults + m_gridPads->SetDefaultCellBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) ); + m_gridPads->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + m_gridPads->SetMaxSize( wxSize( -1,300 ) ); + + sbPadsSizer->Add( m_gridPads, 0, wxALL, 5 ); + + + gbConentsSizer->Add( sbPadsSizer, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 ); + + wxStaticBoxSizer* sbBoardSizer; + sbBoardSizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Board") ), wxVERTICAL ); + + m_gridBoard = new wxGrid( sbBoardSizer->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL ); + + // Grid + m_gridBoard->CreateGrid( 3, 2 ); + m_gridBoard->EnableEditing( false ); + m_gridBoard->EnableGridLines( false ); + m_gridBoard->SetGridLineColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) ); + m_gridBoard->EnableDragGridSize( false ); + m_gridBoard->SetMargins( 10, 0 ); + + // Columns + m_gridBoard->EnableDragColMove( false ); + m_gridBoard->EnableDragColSize( true ); + m_gridBoard->SetColLabelSize( 0 ); + m_gridBoard->SetColLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Rows + m_gridBoard->EnableDragRowSize( true ); + m_gridBoard->SetRowLabelSize( 0 ); + m_gridBoard->SetRowLabelAlignment( wxALIGN_CENTER, wxALIGN_CENTER ); + + // Label Appearance + m_gridBoard->SetLabelBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ); + m_gridBoard->SetLabelFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString ) ); + + // Cell Defaults + m_gridBoard->SetDefaultCellBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWFRAME ) ); + m_gridBoard->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); + m_gridBoard->SetMaxSize( wxSize( -1,300 ) ); + + sbBoardSizer->Add( m_gridBoard, 0, wxALL, 5 ); + + + gbConentsSizer->Add( sbBoardSizer, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 ); + + + gbConentsSizer->AddGrowableCol( 0 ); + gbConentsSizer->AddGrowableCol( 1 ); + gbConentsSizer->AddGrowableRow( 0 ); + + bMainBoxSizer->Add( gbConentsSizer, 1, wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 10 ); + + wxGridSizer* gOptionsSizer; + gOptionsSizer = new wxGridSizer( 0, 2, 0, 0 ); + + m_checkBoxSubtractHoles = new wxCheckBox( this, wxID_ANY, _("Subtract holes from board area"), wxDefaultPosition, wxDefaultSize, 0 ); + gOptionsSizer->Add( m_checkBoxSubtractHoles, 0, wxALL|wxEXPAND, 5 ); + + m_checkBoxExcludeComponentsNoPins = new wxCheckBox( this, wxID_ANY, _("Exclude components with no pins"), wxDefaultPosition, wxDefaultSize, 0 ); + gOptionsSizer->Add( m_checkBoxExcludeComponentsNoPins, 0, wxALL|wxEXPAND, 5 ); + + + bMainBoxSizer->Add( gOptionsSizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 10 ); + + m_sdbControlSizer = new wxStdDialogButtonSizer(); + m_sdbControlSizerOK = new wxButton( this, wxID_OK ); + m_sdbControlSizer->AddButton( m_sdbControlSizerOK ); + m_sdbControlSizer->Realize(); + + bMainBoxSizer->Add( m_sdbControlSizer, 0, wxALIGN_RIGHT|wxBOTTOM|wxLEFT|wxRIGHT|wxTOP, 10 ); + + + this->SetSizer( bMainBoxSizer ); + this->Layout(); + bMainBoxSizer->Fit( this ); + + this->Centre( wxBOTH ); + + // Connect Events + m_checkBoxSubtractHoles->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_BOARD_STATISTICS_BASE::checkboxClicked ), NULL, this ); + m_checkBoxExcludeComponentsNoPins->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_BOARD_STATISTICS_BASE::checkboxClicked ), NULL, this ); +} + +DIALOG_BOARD_STATISTICS_BASE::~DIALOG_BOARD_STATISTICS_BASE() +{ + // Disconnect Events + m_checkBoxSubtractHoles->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_BOARD_STATISTICS_BASE::checkboxClicked ), NULL, this ); + m_checkBoxExcludeComponentsNoPins->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_BOARD_STATISTICS_BASE::checkboxClicked ), NULL, this ); + +} diff --git a/pcbnew/dialogs/dialog_board_statistics_base.fbp b/pcbnew/dialogs/dialog_board_statistics_base.fbp new file mode 100644 index 0000000000..fe9a222b5a --- /dev/null +++ b/pcbnew/dialogs/dialog_board_statistics_base.fbp @@ -0,0 +1,558 @@ + + + + + ; + C++ + 1 + source_name + 0 + 0 + res + UTF-8 + connect + dialog_board_statistics_base + 1000 + none + + 0 + DIALOG_BOARD_STATISTCS_BASE + + . + + 1 + 1 + 1 + 1 + UI + 0 + 0 + + 0 + wxAUI_MGR_DEFAULT + wxSYS_COLOUR_WINDOWFRAME + wxBOTH + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + DIALOG_BOARD_STATISTICS_BASE + + + wxDEFAULT_DIALOG_STYLE + DIALOG_SHIM; dialog_shim.h; forward_declare + Board Statistics + + + + + + + bMainBoxSizer + wxVERTICAL + none + + 10 + wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxEXPAND|wxLEFT|wxRIGHT|wxTOP + 1 + + + wxBOTH + 0 + 0 + 10 + + gbConentsSizer + wxFLEX_GROWMODE_SPECIFIED + none + 5 + + 5 + 1 + 0 + wxEXPAND + 0 + 2 + + wxID_ANY + Components + + sbComponentsSizer + wxVERTICAL + 1 + none + + 5 + wxALIGN_CENTER|wxALIGN_CENTER_HORIZONTAL|wxBOTTOM|wxLEFT|wxRIGHT|wxTOP + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + 0 + + + + 1 + wxSYS_COLOUR_WINDOWFRAME + + wxALIGN_LEFT + + wxALIGN_TOP + 0 + 1 + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + 4 + + + 1 + 0 + Dock + 0 + Left + 0 + 1 + 0 + 1 + 0 + 1 + + 1 + + wxSYS_COLOUR_WINDOWFRAME + 0 + 0 + 0 + wxID_ANY + wxSYS_COLOUR_BACKGROUND + ,90,90,-1,70,0 + + 0 + 0 + + 0 + -1,400 + + 0 + + 1 + m_gridComponents + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + + 5 + 1 + + ; ; forward_declare + 0 + + + + wxVSCROLL + + + + + + 5 + 1 + 1 + wxEXPAND + 0 + 1 + + wxID_ANY + Pads + + sbPadsSizer + wxVERTICAL + 1 + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + 0 + + + + 1 + wxSYS_COLOUR_WINDOWFRAME + + wxALIGN_LEFT + + wxALIGN_TOP + 0 + 1 + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + 2 + + + 1 + 0 + Dock + 0 + Left + 0 + 1 + 0 + 1 + 0 + 1 + + 1 + + wxSYS_COLOUR_WINDOWFRAME + 0 + 0 + 0 + wxID_ANY + wxSYS_COLOUR_BACKGROUND + ,90,90,-1,70,0 + + 0 + 10 + + 0 + -1,300 + + 0 + + 1 + m_gridPads + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + + 5 + 1 + + ; ; forward_declare + 0 + + + + wxVSCROLL + + + + + + 5 + 1 + 1 + wxEXPAND + 1 + 1 + + wxID_ANY + Board + + sbBoardSizer + wxVERTICAL + 1 + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + 0 + 0 + + + + 1 + wxSYS_COLOUR_WINDOWFRAME + + wxALIGN_LEFT + + wxALIGN_TOP + 0 + 1 + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + 2 + + + 1 + 0 + Dock + 0 + Left + 0 + 1 + 0 + 1 + 0 + 1 + + 1 + + wxSYS_COLOUR_WINDOWFRAME + 0 + 0 + 0 + wxID_ANY + wxSYS_COLOUR_BACKGROUND + ,90,90,-1,70,0 + + 0 + 10 + + 0 + -1,300 + + 0 + + 1 + m_gridBoard + 1 + + + protected + 1 + + Resizable + wxALIGN_CENTER + 0 + + wxALIGN_CENTER + + 3 + 1 + + ; ; forward_declare + 0 + + + + wxVSCROLL + + + + + + + + 10 + wxEXPAND|wxLEFT|wxRIGHT + 0 + + 2 + 0 + + gOptionsSizer + none + 0 + 0 + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Subtract holes from board area + + 0 + + + 0 + + 1 + m_checkBoxSubtractHoles + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + checkboxClicked + + + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + Exclude components with no pins + + 0 + + + 0 + + 1 + m_checkBoxExcludeComponentsNoPins + 1 + + + protected + 1 + + Resizable + 1 + + + ; ; forward_declare + 0 + + + wxFILTER_NONE + wxDefaultValidator + + + + + checkboxClicked + + + + + + 10 + wxALIGN_RIGHT|wxBOTTOM|wxLEFT|wxRIGHT|wxTOP + 0 + + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + + m_sdbControlSizer + protected + + + + + + diff --git a/pcbnew/dialogs/dialog_board_statistics_base.h b/pcbnew/dialogs/dialog_board_statistics_base.h new file mode 100644 index 0000000000..0494adcfe0 --- /dev/null +++ b/pcbnew/dialogs/dialog_board_statistics_base.h @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////// +// C++ code generated with wxFormBuilder (version Jun 25 2019) +// http://www.wxformbuilder.org/ +// +// PLEASE DO *NOT* EDIT THIS FILE! +/////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include +#include +#include "dialog_shim.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +/// Class DIALOG_BOARD_STATISTICS_BASE +/////////////////////////////////////////////////////////////////////////////// +class DIALOG_BOARD_STATISTICS_BASE : public DIALOG_SHIM +{ + private: + + protected: + wxGrid* m_gridComponents; + wxGrid* m_gridPads; + wxGrid* m_gridBoard; + wxCheckBox* m_checkBoxSubtractHoles; + wxCheckBox* m_checkBoxExcludeComponentsNoPins; + wxStdDialogButtonSizer* m_sdbControlSizer; + wxButton* m_sdbControlSizerOK; + + // Virtual event handlers, overide them in your derived class + virtual void checkboxClicked( wxCommandEvent& event ) { event.Skip(); } + + + public: + + DIALOG_BOARD_STATISTICS_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxT("Board Statistics"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); + ~DIALOG_BOARD_STATISTICS_BASE(); + +}; + diff --git a/pcbnew/menubar_pcb_editor.cpp b/pcbnew/menubar_pcb_editor.cpp index af83c60ab8..98b879ea0d 100644 --- a/pcbnew/menubar_pcb_editor.cpp +++ b/pcbnew/menubar_pcb_editor.cpp @@ -436,6 +436,7 @@ void PCB_EDIT_FRAME::ReCreateMenuBar() inspectMenu->AddItem( PCB_ACTIONS::listNets, SELECTION_CONDITIONS::ShowAlways ); inspectMenu->AddItem( ACTIONS::measureTool, SELECTION_CONDITIONS::ShowAlways ); + inspectMenu->AddItem( PCB_ACTIONS::boardStatistics, SELECTION_CONDITIONS::ShowAlways ); inspectMenu->AddSeparator(); inspectMenu->AddItem( PCB_ACTIONS::runDRC, SELECTION_CONDITIONS::ShowAlways ); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index 43ca7e5d20..78b50b81ea 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -74,6 +74,7 @@ #include #include #include +#include #include #include #include @@ -420,6 +421,7 @@ void PCB_EDIT_FRAME::setupTools() m_toolManager->RegisterTool( new POINT_EDITOR ); m_toolManager->RegisterTool( new PCBNEW_CONTROL ); m_toolManager->RegisterTool( new PCB_EDITOR_CONTROL ); + m_toolManager->RegisterTool( new PCB_INSPECTION_TOOL ); m_toolManager->RegisterTool( new ALIGN_DISTRIBUTE_TOOL ); m_toolManager->RegisterTool( new MICROWAVE_TOOL ); m_toolManager->RegisterTool( new POSITION_RELATIVE_TOOL ); diff --git a/pcbnew/tools/pcb_actions.cpp b/pcbnew/tools/pcb_actions.cpp index a1c007cbf2..748638bc5f 100644 --- a/pcbnew/tools/pcb_actions.cpp +++ b/pcbnew/tools/pcb_actions.cpp @@ -909,6 +909,11 @@ TOOL_ACTION PCB_ACTIONS::deleteTool( "pcbnew.Control.deleteTool", _( "Delete Items Tool" ), _( "Click on items to delete them" ), delete_xpm ); +//Show board statistics tool +TOOL_ACTION PCB_ACTIONS::boardStatistics( "pcbnew.InspectionTool.ShowStatisticsDialog", AS_GLOBAL, + 0, LEGACY_HK_NAME( "Show Board Statistics" ), _( "Show Board Statistics" ), + _( "Shows board statistics" ), pcbnew_xpm ); + // PLACEMENT_TOOL // diff --git a/pcbnew/tools/pcb_actions.h b/pcbnew/tools/pcb_actions.h index f87c4b7693..3753958ab0 100644 --- a/pcbnew/tools/pcb_actions.h +++ b/pcbnew/tools/pcb_actions.h @@ -415,6 +415,7 @@ public: static TOOL_ACTION drillOrigin; static TOOL_ACTION appendBoard; static TOOL_ACTION showEeschema; + static TOOL_ACTION boardStatistics; // Ratsnest static TOOL_ACTION localRatsnestTool; diff --git a/pcbnew/tools/pcb_inspection_tool.cpp b/pcbnew/tools/pcb_inspection_tool.cpp new file mode 100644 index 0000000000..8298f27ab9 --- /dev/null +++ b/pcbnew/tools/pcb_inspection_tool.cpp @@ -0,0 +1,45 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 "pcb_inspection_tool.h" + + +PCB_INSPECTION_TOOL::PCB_INSPECTION_TOOL() + : PCB_TOOL_BASE( "pcbnew.InspectionTool.ShowStatisticsDialog" ) +{ +} + +int PCB_INSPECTION_TOOL::ShowStatisticsDialog( const TOOL_EVENT& aEvent ) +{ + auto frame = getEditFrame(); + + DIALOG_BOARD_STATISTICS dialog( frame ); + dialog.ShowModal(); + return 0; +} + +void PCB_INSPECTION_TOOL::setTransitions() +{ + Go( &PCB_INSPECTION_TOOL::ShowStatisticsDialog, PCB_ACTIONS::boardStatistics.MakeEvent() ); +} diff --git a/pcbnew/tools/pcb_inspection_tool.h b/pcbnew/tools/pcb_inspection_tool.h new file mode 100644 index 0000000000..ef49ac0395 --- /dev/null +++ b/pcbnew/tools/pcb_inspection_tool.h @@ -0,0 +1,55 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors. + * + * 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 + */ + +#ifndef __BOARD_STATISTICS_TOOL_H +#define __BOARD_STATISTICS_TOOL_H + + +#include +#include +#include +#include + + +/** + * Class PCB_INSPECTION_TOOL + * + * Tool for pcb inspection. + */ +class PCB_INSPECTION_TOOL : public PCB_TOOL_BASE +{ +public: + PCB_INSPECTION_TOOL(); + + /** + * Function ShowStatisticDialog() + * + * Shows dialog with board statistics + */ + int ShowStatisticsDialog( const TOOL_EVENT& aEvent ); + + ///> Bind handlers to corresponding TOOL_ACTIONs + void setTransitions() override; +}; + +#endif //__BOARD_STATISTICS_TOOL_H