KiCad PCB EDA Suite
dialog_board_statistics.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2019 Alexander Shuklin, jasuramme@gmail.com
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 
26 #ifndef _DIALOG_BOARD_STATISTICS_H
27 #define _DIALOG_BOARD_STATISTICS_H
28 
29 
30 #include <base_units.h>
31 #include <board.h>
32 #include <track.h>
33 #include <confirm.h>
35 #include <pad_shapes.h>
36 #include <pcb_base_frame.h>
37 #include <pcb_edit_frame.h>
38 #include <project.h>
39 #include <wx/datetime.h>
40 
47 {
48 public:
52  template <typename T>
54  {
55  typeContainer_t<T>( T aAttribute, wxString aTitle )
56  : attribute( aAttribute ),
57  title( aTitle ),
58  qty( 0 )
59  {
60  }
62  wxString title;
63  int qty;
64  };
65 
68 
75  {
76  componentsType_t( FOOTPRINT_ATTR_T aAttribute, wxString aTitle )
77  : attribute( aAttribute ),
78  title( aTitle ),
79  frontSideQty( 0 ),
80  backSideQty( 0 )
81  {
82  }
84  wxString title;
87  };
88 
89  struct drillType_t
90  {
91  enum COL_ID
92  {
101  };
102  drillType_t( int aXSize, int aYSize, PAD_DRILL_SHAPE_T aShape, bool aIsPlated, bool aIsPad,
103  PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aStopLayer, int aQty = 0 )
104  : xSize( aXSize ),
105  ySize( aYSize ),
106  shape( aShape ),
107  isPlated( aIsPlated ),
108  isPad( aIsPad ),
109  startLayer( aStartLayer ),
110  stopLayer( aStopLayer ),
111  qty( aQty )
112  {
113  }
114  bool operator==( const drillType_t& other )
115  {
116  return xSize == other.xSize && ySize == other.ySize && shape == other.shape
117  && isPlated == other.isPlated && isPad == other.isPad
118  && startLayer == other.startLayer && stopLayer == other.stopLayer;
119  }
120  struct COMPARE
121  {
122  COMPARE( COL_ID aColId, bool aAscending ) : colId( aColId ), ascending( aAscending )
123  {
124  }
125  bool operator()( const drillType_t& aLeft, const drillType_t& aRight )
126  {
127  switch( colId )
128  {
129  case COL_COUNT:
130  return compareDrillParameters( aLeft.qty, aRight.qty );
131  case COL_SHAPE:
132  return compareDrillParameters( aLeft.shape, aRight.shape );
133  case COL_X_SIZE:
134  return compareDrillParameters( aLeft.xSize, aRight.xSize );
135  case COL_Y_SIZE:
136  return compareDrillParameters( aLeft.ySize, aRight.ySize );
137  case COL_PLATED:
138  return ascending ? aLeft.isPlated : aRight.isPlated;
139  case COL_VIA_PAD:
140  return ascending ? aLeft.isPad : aRight.isPad;
141  case COL_START_LAYER:
142  return compareDrillParameters( aLeft.startLayer, aRight.startLayer );
143  case COL_STOP_LAYER:
144  return compareDrillParameters( aLeft.stopLayer, aRight.stopLayer );
145  }
146 
147  return false;
148  }
149  bool compareDrillParameters( int aLeft, int aRight )
150  {
151  return ascending ? aLeft < aRight : aLeft > aRight;
152  }
154  bool ascending;
155  };
156  int xSize;
157  int ySize;
159  bool isPlated;
160  bool isPad;
163  int qty;
164  };
165 
166  using componentsTypeList_t = std::deque<componentsType_t>;
167  using padsTypeList_t = std::deque<padsType_t>;
168  using viasTypeList_t = std::deque<viasType_t>;
169  using drillTypeList_t = std::deque<drillType_t>;
170 
171  DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame );
173 
175  bool TransferDataToWindow() override;
176 
177 private:
179 
182  double m_boardArea;
183 
186 
189 
192 
195 
198 
200  void refreshItemsTypes();
201 
203  void getDataFromPCB();
204 
206  void updateWidets();
207 
209  void updateDrillGrid();
210 
212  void printGridToStringAsTable( wxGrid* aGrid, wxString& aStr, bool aUseRowLabels,
213  bool aUseColLabels, bool aUseFirstColAsLabel );
214 
215  void adjustDrillGridColumns();
216 
217  void checkboxClicked( wxCommandEvent& aEvent ) override;
218 
220  void saveReportClicked( wxCommandEvent& aEvent ) override;
221 
222  void drillGridSize( wxSizeEvent& aEvent ) override;
223 
224  void drillGridSort( wxGridEvent& aEvent );
225 };
226 
227 #endif // __DIALOG_BOARD_STATISTICS_H
bool m_hasOutline
Shows if board outline properly defined
Implementation of conversion functions that require both schematic and board internal units.
This file is part of the common library.
void refreshItemsTypes()
Function to fill up all items types to be shown in the dialog.
bool TransferDataToWindow() override
Get data from the PCB board and print it to dialog
viasTypeList_t m_viasTypes
Holds all vias types to be shown in the dialog
void getDataFromPCB()
Gets data from board
bool operator==(const drillType_t &other)
Struct holds information about component type (such as SMD, THT, Virtual and so on),...
std::deque< drillType_t > drillTypeList_t
PAD_DRILL_SHAPE_T
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition: pad_shapes.h:66
void drillGridSize(wxSizeEvent &aEvent) override
FOOTPRINT_ATTR_T
Enum FOOTPRINT_ATTR_T is the set of attributes allowed within a FOOTPRINT, using FOOTPRINT::SetAttrib...
Definition: footprint.h:67
Classes used in Pcbnew, CvPcb and GerbView.
bool operator()(const drillType_t &aLeft, const drillType_t &aRight)
Struct to hold type information, which will be shown in dialog.
PCB_LAYER_ID
A quick note on layer IDs:
void drillGridSort(wxGridEvent &aEvent)
std::deque< viasType_t > viasTypeList_t
std::deque< padsType_t > padsTypeList_t
void updateDrillGrid()
Updates drills grid
DIALOG_BOARD_STATISTICS(PCB_EDIT_FRAME *aParentFrame)
drillType_t(int aXSize, int aYSize, PAD_DRILL_SHAPE_T aShape, bool aIsPlated, bool aIsPad, PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aStopLayer, int aQty=0)
void printGridToStringAsTable(wxGrid *aGrid, wxString &aStr, bool aUseRowLabels, bool aUseColLabels, bool aUseFirstColAsLabel)
Prints grid to string in tabular format
void updateWidets()
Applies data to dialog widgets
Class DIALOG_BOARD_STATISTICS_BASE.
DIALOG_BOARD_STATISTIC.
PCB_EDIT_FRAME is the main frame for Pcbnew.
void saveReportClicked(wxCommandEvent &aEvent) override
Save board statistics to a file
padsTypeList_t m_padsTypes
Holds all pads types to be shown in the dialog
void checkboxClicked(wxCommandEvent &aEvent) override
drillTypeList_t m_drillTypes
Holds all drill hole types to be shown in the dialog
componentsTypeList_t m_componentsTypes
Holds all components types to be shown in the dialog
componentsType_t(FOOTPRINT_ATTR_T aAttribute, wxString aTitle)
std::deque< componentsType_t > componentsTypeList_t