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, [email protected]
5  * Copyright (C) 2019-2021 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 <footprint.h>
33 #include <pcb_track.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 
45 {
46 public:
50  template <typename T>
52  {
53  typeContainer_t<T>( T aAttribute, const wxString& aTitle )
54  : attribute( aAttribute ),
55  title( aTitle ),
56  qty( 0 )
57  {
58  }
59 
61  wxString title;
62  int qty;
63  };
64 
67 
73  {
74  componentsType_t( FOOTPRINT_ATTR_T aAttribute, wxString aTitle )
75  : attribute( aAttribute ),
76  title( aTitle ),
77  frontSideQty( 0 ),
78  backSideQty( 0 )
79  {
80  }
81 
83  wxString title;
86  };
87 
88  struct drillType_t
89  {
90  enum COL_ID
91  {
100  };
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 
115  bool operator==( const drillType_t& other )
116  {
117  return xSize == other.xSize && ySize == other.ySize && shape == other.shape
118  && isPlated == other.isPlated && isPad == other.isPad
119  && startLayer == other.startLayer && stopLayer == other.stopLayer;
120  }
121 
122  struct COMPARE
123  {
124  COMPARE( COL_ID aColId, bool aAscending ) : colId( aColId ), ascending( aAscending )
125  {
126  }
127  bool operator()( const drillType_t& aLeft, const drillType_t& aRight )
128  {
129  switch( colId )
130  {
131  case COL_COUNT:
132  return compareDrillParameters( aLeft.qty, aRight.qty );
133  case COL_SHAPE:
134  return compareDrillParameters( aLeft.shape, aRight.shape );
135  case COL_X_SIZE:
136  return compareDrillParameters( aLeft.xSize, aRight.xSize );
137  case COL_Y_SIZE:
138  return compareDrillParameters( aLeft.ySize, aRight.ySize );
139  case COL_PLATED:
140  return ascending ? aLeft.isPlated : aRight.isPlated;
141  case COL_VIA_PAD:
142  return ascending ? aLeft.isPad : aRight.isPad;
143  case COL_START_LAYER:
144  return compareDrillParameters( aLeft.startLayer, aRight.startLayer );
145  case COL_STOP_LAYER:
146  return compareDrillParameters( aLeft.stopLayer, aRight.stopLayer );
147  }
148 
149  return false;
150  }
151 
152  bool compareDrillParameters( int aLeft, int aRight )
153  {
154  return ascending ? aLeft < aRight : aLeft > aRight;
155  }
156 
158  bool ascending;
159  };
160 
161  int xSize;
162  int ySize;
164  bool isPlated;
165  bool isPad;
168  int qty;
169  };
170 
171  using componentsTypeList_t = std::deque<componentsType_t>;
172  using padsTypeList_t = std::deque<padsType_t>;
173  using viasTypeList_t = std::deque<viasType_t>;
174  using drillTypeList_t = std::deque<drillType_t>;
175 
176  DIALOG_BOARD_STATISTICS( PCB_EDIT_FRAME* aParentFrame );
178 
180  bool TransferDataToWindow() override;
181 
182 private:
183 
185  void refreshItemsTypes();
186 
188  void getDataFromPCB();
189 
191  void updateWidets();
192 
194  void updateDrillGrid();
195 
197  void printGridToStringAsTable( wxGrid* aGrid, wxString& aStr, bool aUseRowLabels,
198  bool aUseColLabels, bool aUseFirstColAsLabel );
199 
200  void adjustDrillGridColumns();
201 
202  void checkboxClicked( wxCommandEvent& aEvent ) override;
203 
205  void saveReportClicked( wxCommandEvent& aEvent ) override;
206 
207  void drillGridSize( wxSizeEvent& aEvent ) override;
208 
209  void drillGridSort( wxGridEvent& aEvent );
210 
212 
215  double m_boardArea;
216 
219 
222 
225 
228 
231 };
232 
233 #endif // __DIALOG_BOARD_STATISTICS_H
bool m_hasOutline
Hold all components types to be shown in the dialog.
Implementation of conversion functions that require both schematic and board internal units.
void refreshItemsTypes()
< Function to fill up all items types to be shown in the dialog.
viasTypeList_t m_viasTypes
Hold all drill hole types to be shown in the dialog.
void getDataFromPCB()
Apply data to dialog widgets.
bool operator==(const drillType_t &other)
Footprint attributes (such as SMD, THT, Virtual and so on), which will be shown in the dialog.
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:67
void drillGridSize(wxSizeEvent &aEvent) override
FOOTPRINT_ATTR_T
The set of attributes allowed within a FOOTPRINT, using FOOTPRINT::SetAttributes() and FOOTPRINT::Get...
Definition: footprint.h:66
double m_boardArea
Show if board outline properly defined.
Classes used in Pcbnew, CvPcb and GerbView.
bool operator()(const drillType_t &aLeft, const drillType_t &aRight)
Type information, which will be shown in dialog.
void drillGridSort(wxGridEvent &aEvent)
~DIALOG_BOARD_STATISTICS()
Get data from the PCB board and print it to dialog.
std::deque< viasType_t > viasTypeList_t
std::deque< padsType_t > padsTypeList_t
void updateDrillGrid()
Print grid to string in tabular format.
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)
void updateWidets()
Update drills grid.
Class DIALOG_BOARD_STATISTICS_BASE.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Dialog to show common board info.
The main frame for Pcbnew.
void saveReportClicked(wxCommandEvent &aEvent) override
padsTypeList_t m_padsTypes
Hold all vias types to be shown in the dialog.
void checkboxClicked(wxCommandEvent &aEvent) override
Save board statistics to a file.
componentsTypeList_t m_componentsTypes
Hold all pads types to be shown in the dialog.
componentsType_t(FOOTPRINT_ATTR_T aAttribute, wxString aTitle)
std::deque< componentsType_t > componentsTypeList_t