KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_board_statistics.cpp
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-2023 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
27#include <kiplatform/ui.h>
28#include <confirm.h>
29#include <pad.h>
30#include <macros.h>
32#include <widgets/wx_grid.h>
33#include <wx/filedlg.h>
34
35#define COL_LABEL 0
36#define COL_AMOUNT 1
37
38// Defines for components view
39#define ROW_LABEL 0
40#define COL_FRONT_SIDE 1
41#define COL_BOTTOM_SIDE 2
42#define COL_TOTAL 3
43
44// Defines for board view
45#define ROW_BOARD_WIDTH 0
46#define ROW_BOARD_HEIGHT 1
47#define ROW_BOARD_AREA 2
48
49
54{
56 excludeNoPins( false ),
57 subtractHoles( false ),
59 {
60 }
61
62 // Flags to remember last checkboxes state
65
66 // Variables to save last report file name and folder
67 bool saveReportInitialized; // true after the 3 next string are initialized
68 wxString saveReportFolder; // last report folder
69 wxString saveReportName; // last report filename
70 wxString m_project; // name of the project used to create the last report
71 // used to reinit last state after a project change
72};
73
74
76
78 DIALOG_BOARD_STATISTICS_BASE( aParentFrame ),
79 m_parentFrame(aParentFrame),
80 m_boardWidth( 0 ),
81 m_boardHeight( 0 ),
82 m_boardArea( 0.0 ),
83 m_hasOutline( false ),
84 m_startLayerColInitialSize( 1 ),
85 m_stopLayerColInitialSize( 1 )
86{
87 m_gridDrills->Connect( wxEVT_GRID_COL_SORT,
88 wxGridEventHandler( DIALOG_BOARD_STATISTICS::drillGridSort ),
89 nullptr, this );
90
93
94 // Make labels for grids
95 wxFont headingFont = KIUI::GetStatusFont( this );
96 m_gridComponents->SetCellValue( ROW_LABEL, COL_FRONT_SIDE, _( "Front Side" ) );
97 m_gridComponents->SetCellFont( ROW_LABEL, COL_FRONT_SIDE, headingFont );
98 m_gridComponents->SetCellValue( ROW_LABEL, COL_BOTTOM_SIDE, _( "Back Side" ) );
99 m_gridComponents->SetCellFont( ROW_LABEL, COL_BOTTOM_SIDE, headingFont );
100 m_gridComponents->SetCellValue( ROW_LABEL, COL_TOTAL, _( "Total" ) );
101 m_gridComponents->SetCellFont( ROW_LABEL, COL_TOTAL, headingFont );
102
103 m_gridBoard->SetCellValue( 0, 0, _( "Width:" ) );
104 m_gridBoard->SetCellAlignment( 0, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
105 m_gridBoard->SetCellValue( 1, 0, _( "Height:" ) );
106 m_gridBoard->SetCellAlignment( 1, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
107 m_gridBoard->SetCellValue( 2, 0, _( "Area:" ) );
108 m_gridBoard->SetCellAlignment( 2, 0, wxALIGN_LEFT, wxALIGN_CENTRE );
109
110 wxGrid* grids[] = { m_gridComponents, m_gridPads, m_gridVias, m_gridBoard };
111
112 for( auto& grid : grids )
113 {
114 // Remove wxgrid's selection boxes
115 grid->SetCellHighlightPenWidth( 0 );
116 grid->SetColMinimalAcceptableWidth( 80 );
117 for( int i = 0; i < grid->GetNumberRows(); i++ )
118 grid->SetCellAlignment( i, COL_LABEL, wxALIGN_LEFT, wxALIGN_CENTRE );
119 }
120
121 wxFileName fn = m_parentFrame->GetBoard()->GetFileName();
122
124 || s_savedDialogState.m_project != Prj().GetProjectFullName() )
125 {
126 fn.SetName( fn.GetName() + wxT( "_report" ) );
127 fn.SetExt( wxT( "txt" ) );
128 s_savedDialogState.saveReportName = fn.GetFullName();
129 s_savedDialogState.saveReportFolder = wxPathOnly( Prj().GetProjectFullName() );
132 }
133
134 // The wxStdDialogButtonSizer wxID_CANCLE button is in fact a close button
135 // Nothing to cancel:
136 m_sdbControlSizerCancel->SetLabel( _( "Close" ) );
137}
138
139
141{
142 m_fpTypes.clear();
143
144 // If you need some more types to be shown, simply add them to the corresponding list
145 m_fpTypes.push_back( FP_LINE_ITEM( FP_THROUGH_HOLE, FP_THROUGH_HOLE, _( "THT:" ) ) );
146 m_fpTypes.push_back( FP_LINE_ITEM( FP_SMD, FP_SMD, _( "SMD:" ) ) );
147 m_fpTypes.push_back( FP_LINE_ITEM( FP_THROUGH_HOLE|FP_SMD, 0, _( "Unspecified:" ) ) );
148
149 m_padTypes.clear();
150 m_padTypes.push_back( LINE_ITEM<PAD_ATTRIB>( PAD_ATTRIB::PTH, _( "Through hole:" ) ) );
151 m_padTypes.push_back( LINE_ITEM<PAD_ATTRIB>( PAD_ATTRIB::SMD, _( "SMD:" ) ) );
152 m_padTypes.push_back( LINE_ITEM<PAD_ATTRIB>( PAD_ATTRIB::CONN, _( "Connector:" ) ) );
153 m_padTypes.push_back( LINE_ITEM<PAD_ATTRIB>( PAD_ATTRIB::NPTH, _( "NPTH:" ) ) );
154
155 m_viaTypes.clear();
156 m_viaTypes.push_back( LINE_ITEM<VIATYPE>( VIATYPE::THROUGH, _( "Through vias:" ) ) );
157 m_viaTypes.push_back( LINE_ITEM<VIATYPE>( VIATYPE::BLIND_BURIED, _( "Blind/buried:" ) ) );
158 m_viaTypes.push_back( LINE_ITEM<VIATYPE>( VIATYPE::MICROVIA, _( "Micro vias:" ) ) );
159
160 // If there not enough rows in grids, append some
161 int appendRows = m_fpTypes.size() + 2 - m_gridComponents->GetNumberRows();
162
163 if( appendRows > 0 )
164 m_gridComponents->AppendRows( appendRows );
165
166 appendRows = m_padTypes.size() + 1 - m_gridPads->GetNumberRows();
167
168 if( appendRows > 0 )
169 m_gridPads->AppendRows( appendRows );
170
171 appendRows = m_viaTypes.size() + 1 - m_gridVias->GetNumberRows();
172
173 if( appendRows )
174 m_gridVias->AppendRows( appendRows );
175}
176
177
179{
182 updateWidets();
183
184 Layout();
185 m_drillsPanel->Layout();
186
187 m_gridDrills->AutoSizeColumns();
190
191 // Add space for the vertical scrollbar, so that it won't overlap with the cells.
192 m_gridDrills->SetMinSize( wxSize( m_gridDrills->GetEffectiveMinSize().x
193 + wxSystemSettings::GetMetric( wxSYS_VSCROLL_X ),
194 60 ) );
195
197
199 return true;
200}
201
202
204{
205 BOARD* board = m_parentFrame->GetBoard();
206 m_drillTypes.clear();
207
208 // Get footprints and pads count
209 for( FOOTPRINT* footprint : board->Footprints() )
210 {
211 // Do not proceed footprints with no pads if checkbox checked
212 if( m_checkBoxExcludeComponentsNoPins->GetValue() && ! footprint->Pads().size() )
213 continue;
214
215 // Go through components types list
216 for( FP_LINE_ITEM& line : m_fpTypes )
217 {
218 if( ( footprint->GetAttributes() & line.attribute_mask ) == line.attribute_value )
219 {
220 switch( footprint->GetSide() )
221 {
222 case F_Cu: line.frontSideQty++; break;
223 case B_Cu: line.backSideQty++; break;
224 default: /* unsided: user-layers only, etc. */ break;
225 }
226
227 break;
228 }
229 }
230
231 for( PAD* pad : footprint->Pads() )
232 {
233 // Go through pads types list
234 for( LINE_ITEM<PAD_ATTRIB>& line : m_padTypes )
235 {
236 if( pad->GetAttribute() == line.attribute )
237 {
238 line.qty++;
239 break;
240 }
241 }
242
243 if( pad->GetDrillSize().x > 0 && pad->GetDrillSize().y > 0 )
244 {
245 PCB_LAYER_ID top, bottom;
246
247 if( pad->GetLayerSet().CuStack().empty() )
248 {
249 // The pad is not on any copper layer
250 top = UNDEFINED_LAYER;
251 bottom = UNDEFINED_LAYER;
252 }
253 else
254 {
255 top = pad->GetLayerSet().CuStack().front();
256 bottom = pad->GetLayerSet().CuStack().back();
257 }
258
259 DRILL_LINE_ITEM drill( pad->GetDrillSize().x, pad->GetDrillSize().y,
260 pad->GetDrillShape(),
261 pad->GetAttribute() != PAD_ATTRIB::NPTH,
262 true, top, bottom );
263
264 auto it = m_drillTypes.begin();
265
266 for( ; it != m_drillTypes.end(); ++it )
267 {
268 if( *it == drill )
269 {
270 it->qty++;
271 break;
272 }
273 }
274
275 if( it == m_drillTypes.end() )
276 {
277 drill.qty = 1;
278 m_drillTypes.push_back( drill );
279 m_gridDrills->InsertRows();
280 }
281 }
282 }
283 }
284
285 // Get via counts
286 for( PCB_TRACK* track : board->Tracks() )
287 {
288 if( track->Type() == PCB_VIA_T )
289 {
290 PCB_VIA* via = static_cast<PCB_VIA*>( track );
291
292 for( LINE_ITEM<VIATYPE>& line : m_viaTypes )
293 {
294 if( via->GetViaType() == line.attribute )
295 {
296 line.qty++;
297 break;
298 }
299 }
300
301 DRILL_LINE_ITEM drill( via->GetDrillValue(), via->GetDrillValue(),
302 PAD_DRILL_SHAPE_CIRCLE, true, false, via->TopLayer(),
303 via->BottomLayer() );
304
305 auto it = m_drillTypes.begin();
306
307 for( ; it != m_drillTypes.end(); ++it )
308 {
309 if( *it == drill )
310 {
311 it->qty++;
312 break;
313 }
314 }
315
316 if( it == m_drillTypes.end() )
317 {
318 drill.qty = 1;
319 m_drillTypes.push_back( drill );
320 m_gridDrills->InsertRows();
321 }
322 }
323 }
324
325 sort( m_drillTypes.begin(), m_drillTypes.end(),
327
328 bool boundingBoxCreated = false; //flag if bounding box initialized
329 BOX2I bbox;
330 SHAPE_POLY_SET polySet;
331 m_hasOutline = board->GetBoardPolygonOutlines( polySet );
332
333 // If board has no Edge Cuts lines, board->GetBoardPolygonOutlines will
334 // return small rectangle, so we double check that
335 bool edgeCutsExists = false;
336
337 for( BOARD_ITEM* drawing : board->Drawings() )
338 {
339 if( drawing->GetLayer() == Edge_Cuts )
340 {
341 edgeCutsExists = true;
342 break;
343 }
344 }
345
346 if( !edgeCutsExists )
347 m_hasOutline = false;
348
349 if( m_hasOutline )
350 {
351 m_boardArea = 0.0;
352
353 for( int i = 0; i < polySet.OutlineCount(); i++ )
354 {
355 SHAPE_LINE_CHAIN& outline = polySet.Outline( i );
356 m_boardArea += outline.Area();
357
358 // If checkbox "subtract holes" is checked
359 if( m_checkBoxSubtractHoles->GetValue() )
360 {
361 for( int j = 0; j < polySet.HoleCount( i ); j++ )
362 m_boardArea -= polySet.Hole( i, j ).Area();
363 }
364
365 if( boundingBoxCreated )
366 {
367 bbox.Merge( outline.BBox() );
368 }
369 else
370 {
371 bbox = outline.BBox();
372 boundingBoxCreated = true;
373 }
374 }
375
376 m_boardWidth = bbox.GetWidth();
377 m_boardHeight = bbox.GetHeight();
378 }
379}
380
381
382static wxString formatCount( int aCount )
383{
384 return wxString::Format( wxT( "%i" ), aCount );
385};
386
387
389{
390 int totalPads = 0;
391 int row = 0;
392
393 for( const LINE_ITEM<PAD_ATTRIB>& line : m_padTypes )
394 {
395 m_gridPads->SetCellValue( row, COL_LABEL, line.title );
396 m_gridPads->SetCellValue( row, COL_AMOUNT, formatCount( line.qty ) );
397 totalPads += line.qty;
398 row++;
399 }
400
401 m_gridPads->SetCellValue( row, COL_LABEL, _( "Total:" ) );
402 m_gridPads->SetCellValue( row, COL_AMOUNT, formatCount( totalPads ) );
403
404 int totalVias = 0;
405 row = 0;
406
407 for( const LINE_ITEM<VIATYPE>& line : m_viaTypes )
408 {
409 m_gridVias->SetCellValue( row, COL_LABEL, line.title );
410 m_gridVias->SetCellValue( row, COL_AMOUNT, formatCount( line.qty ) );
411 totalVias += line.qty;
412 row++;
413 }
414
415 m_gridVias->SetCellValue( row, COL_LABEL, _( "Total:" ) );
416 m_gridVias->SetCellValue( row, COL_AMOUNT, formatCount( totalVias ) );
417
418
419 int totalFront = 0;
420 int totalBack = 0;
421
422 // We don't use row 0, as there labels are
423 row = 1;
424
425 for( const FP_LINE_ITEM& line : m_fpTypes )
426 {
427 m_gridComponents->SetCellValue( row, COL_LABEL, line.title );
428 m_gridComponents->SetCellValue( row, COL_FRONT_SIDE, formatCount( line.frontSideQty ) );
429 m_gridComponents->SetCellValue( row, COL_BOTTOM_SIDE, formatCount( line.backSideQty ) );
430 m_gridComponents->SetCellValue( row, 3, formatCount( line.frontSideQty + line.backSideQty ) );
431 totalFront += line.frontSideQty;
432 totalBack += line.backSideQty;
433 row++;
434 }
435
436 m_gridComponents->SetCellValue( row, COL_LABEL, _( "Total:" ) );
437 m_gridComponents->SetCellValue( row, COL_FRONT_SIDE, formatCount( totalFront ) );
438 m_gridComponents->SetCellValue( row, COL_BOTTOM_SIDE, formatCount( totalBack ) );
439 m_gridComponents->SetCellValue( row, COL_TOTAL, formatCount( totalFront + totalBack ) );
440
441 if( m_hasOutline )
442 {
443 m_gridBoard->SetCellValue( ROW_BOARD_WIDTH, COL_AMOUNT,
447 m_gridBoard->SetCellValue( ROW_BOARD_AREA, COL_AMOUNT,
449 EDA_DATA_TYPE::AREA ) );
450 }
451 else
452 {
453 m_gridBoard->SetCellValue( ROW_BOARD_WIDTH, COL_AMOUNT, _( "unknown" ) );
454 m_gridBoard->SetCellValue( ROW_BOARD_HEIGHT, COL_AMOUNT, _( "unknown" ) );
455 m_gridBoard->SetCellValue( ROW_BOARD_AREA, COL_AMOUNT, _( "unknown" ) );
456 }
457
459
460 m_gridComponents->AutoSize();
461 m_gridPads->AutoSize();
462 m_gridBoard->AutoSize();
463 m_gridVias->AutoSize();
464
466}
467
468
470{
471 BOARD* board = m_parentFrame->GetBoard();
472 int row = 0;
473
474 for( const DRILL_LINE_ITEM& line : m_drillTypes )
475 {
476 wxString shapeStr;
477 wxString startLayerStr;
478 wxString stopLayerStr;
479
480 switch( line.shape )
481 {
482 case PAD_DRILL_SHAPE_CIRCLE: shapeStr = _( "Round" ); break;
483 case PAD_DRILL_SHAPE_OBLONG: shapeStr = _( "Slot" ); break;
484 default: shapeStr = _( "???" ); break;
485 }
486
487 if( line.startLayer == UNDEFINED_LAYER )
488 startLayerStr = _( "N/A" );
489 else
490 startLayerStr = board->GetLayerName( line.startLayer );
491
492 if( line.stopLayer == UNDEFINED_LAYER )
493 stopLayerStr = _( "N/A" );
494 else
495 stopLayerStr = board->GetLayerName( line.stopLayer );
496
497 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_COUNT, formatCount( line.qty ) );
498 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_SHAPE, shapeStr );
499 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_X_SIZE,
500 m_parentFrame->MessageTextFromValue( line.xSize ) );
501 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_Y_SIZE,
502 m_parentFrame->MessageTextFromValue( line.ySize ) );
503 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_PLATED,
504 line.isPlated ? _( "PTH" ) : _( "NPTH" ) );
505 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_VIA_PAD,
506 line.isPad ? _( "Pad" ) : _( "Via" ) );
507 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_START_LAYER, startLayerStr );
508 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_STOP_LAYER, stopLayerStr );
509
510 row++;
511 }
512}
513
514
515void DIALOG_BOARD_STATISTICS::printGridToStringAsTable( wxGrid* aGrid, wxString& aStr,
516 bool aUseColLabels,
517 bool aUseFirstColAsLabel )
518{
519 std::vector<int> widths( aGrid->GetNumberCols(), 0 );
520 int rowLabelsWidth = 0;
521
522 // Determine column widths.
523
524 if( aUseColLabels )
525 {
526 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
527 widths[col] = aGrid->GetColLabelValue( col ).length();
528 }
529
530 for( int row = 0; row < aGrid->GetNumberRows(); row++ )
531 {
532 rowLabelsWidth = std::max<int>( rowLabelsWidth, aGrid->GetRowLabelValue( row ).length() );
533
534 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
535 widths[col] = std::max<int>( widths[col], aGrid->GetCellValue( row, col ).length() );
536 }
537
538 // Print the cells.
539
540 wxString tmp;
541
542 // Print column labels.
543
544 aStr << wxT( "|" );
545
546 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
547 {
548 if( aUseColLabels )
549 tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetColLabelValue( col ) );
550 else
551 tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetCellValue( 0, col ) );
552
553 aStr << tmp;
554 }
555
556 aStr << wxT( "\n" );
557
558 // Print column label horizontal separators.
559
560 aStr << wxT( "|" );
561
562 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
563 {
564 aStr << wxT( "-" );
565 aStr.Append( '-', widths[col] );
566 aStr << wxT( "-|" );
567 }
568
569 aStr << wxT( "\n" );
570
571 // Print regular cells.
572
573 int firstRow = 0, firstCol = 0;
574
575 if( !aUseColLabels )
576 firstRow = 1;
577
578 if( aUseFirstColAsLabel )
579 firstCol = 1;
580
581 for( int row = firstRow; row < aGrid->GetNumberRows(); row++ )
582 {
583 if( aUseFirstColAsLabel )
584 tmp.Printf( wxT( "|%-*s |" ), widths[0], aGrid->GetCellValue( row, 0 ) );
585 else
586 tmp.Printf( wxT( "|" ) );
587
588 aStr << tmp;
589
590 for( int col = firstCol; col < aGrid->GetNumberCols(); col++ )
591 {
592 tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetCellValue( row, col ) );
593 aStr << tmp;
594 }
595
596 aStr << wxT( "\n" );
597 }
598}
599
600
602{
603 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_gridDrills );
604
606
607 double remainingWidth = KIPLATFORM::UI::GetUnobscuredSize( m_gridDrills ).x;
608
609 // Find the total current width
610 for( int i = 0; i < m_gridDrills->GetNumberCols(); i++ )
611 {
613 remainingWidth -= m_gridDrills->GetColSize( i );
614 }
615
616 double scalingFactor = std::max( 1.0,
617 remainingWidth
619 int startLayerColWidth = static_cast<int>( m_startLayerColInitialSize * scalingFactor );
620 int stopLayerColWidth = static_cast<int>( m_stopLayerColInitialSize * scalingFactor );
621
622 m_gridDrills->SetColSize( DRILL_LINE_ITEM::COL_START_LAYER, startLayerColWidth );
623 m_gridDrills->SetColSize( DRILL_LINE_ITEM::COL_STOP_LAYER, stopLayerColWidth );
624}
625
626
627void DIALOG_BOARD_STATISTICS::checkboxClicked( wxCommandEvent& aEvent )
628{
633 updateWidets();
634 Layout();
635 m_drillsPanel->Layout();
636}
637
638
639void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
640{
641 FILE* outFile;
642 wxString msg;
643 wxString boardName;
644
645 wxFileName fn = m_parentFrame->GetBoard()->GetFileName();
646 boardName = fn.GetName();
647 wxFileDialog dlg( this, _( "Save Report File" ), s_savedDialogState.saveReportFolder,
649 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
650
651 if( dlg.ShowModal() == wxID_CANCEL )
652 return;
653
654 s_savedDialogState.saveReportFolder = wxPathOnly( dlg.GetPath() );
655 s_savedDialogState.saveReportName = dlg.GetFilename();
656
657 outFile = wxFopen( dlg.GetPath(), wxT( "wt" ) );
658
659 if( outFile == nullptr )
660 {
661 msg.Printf( _( "Failed to create file '%s'." ), dlg.GetPath() );
662 DisplayErrorMessage( this, msg );
663 return;
664 }
665
666 msg << _( "PCB statistics report\n=====================" ) << wxT( "\n" );
667 msg << wxS( "- " ) << _( "Date" ) << wxS( ": " ) << wxDateTime::Now().Format() << wxT( "\n" );
668 msg << wxS( "- " ) << _( "Project" ) << wxS( ": " )<< Prj().GetProjectName() << wxT( "\n" );
669 msg << wxS( "- " ) << _( "Board name" ) << wxS( ": " )<< boardName << wxT( "\n" );
670
671 msg << wxT( "\n" );
672 msg << _( "Board" ) << wxT( "\n-----\n" );
673
674 if( m_hasOutline )
675 {
676 msg << wxS( "- " ) << _( "Width" ) << wxS( ": " )
677 << m_parentFrame->MessageTextFromValue( m_boardWidth ) << wxT( "\n" );
678 msg << wxS( "- " ) << _( "Height" ) << wxS( ": " )
680 msg << wxS( "- " ) << _( "Area" ) + wxS( ": " )
681 << m_parentFrame->MessageTextFromValue( m_boardArea, true, EDA_DATA_TYPE::AREA );
682 msg << wxT( "\n" );
683 }
684 else
685 {
686 msg << wxS( "- " ) << _( "Width" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
687 msg << wxS( "- " ) << _( "Height" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
688 msg << wxS( "- " ) << _( "Area" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
689 }
690
691 msg << wxT( "\n" );
692 msg << _( "Pads" ) << wxT( "\n----\n" );
693
694 for( auto& type : m_padTypes )
695 msg << wxT( "- " ) << type.title << wxS( " " ) << type.qty << wxT( "\n" );
696
697 msg << wxT( "\n" );
698 msg << _( "Vias" ) << wxT( "\n----\n" );
699
700 for( auto& type : m_viaTypes )
701 msg << wxT( "- " ) << type.title << wxS( " " ) << type.qty << wxT( "\n" );
702
703 // We will save data about components in the table.
704 // We have to calculate column widths
705 std::vector<int> widths;
706 std::vector<wxString> labels{ wxT( "" ), _( "Front Side" ), _( "Back Side" ), _( "Total" ) };
707 wxString tmp;
708
709 widths.reserve( labels.size() );
710
711 for( const wxString& label : labels )
712 widths.push_back( label.size() );
713
714 int frontTotal = 0;
715 int backTotal = 0;
716
717 for( const FP_LINE_ITEM& line : m_fpTypes )
718 {
719 // Get maximum width for left label column
720 widths[0] = std::max<int>( line.title.size(), widths[0] );
721 frontTotal += line.frontSideQty;
722 backTotal += line.backSideQty;
723 }
724
725 // Get maximum width for other columns
726 tmp.Printf( wxT( "%i" ), frontTotal );
727 widths[1] = std::max<int>( tmp.size(), widths[1] );
728 tmp.Printf( wxT( "%i" ), backTotal );
729 widths[2] = std::max<int>( tmp.size(), widths[2] );
730 tmp.Printf( wxT( "%i" ), frontTotal + backTotal );
731 widths[3] = std::max<int>( tmp.size(), widths[3] );
732
733 //Write components amount to file
734 msg << wxT( "\n" );
735 msg << _( "Components" ) << wxT( "\n----------\n" );
736 msg << wxT( "\n" );
737
738 printGridToStringAsTable( m_gridComponents, msg, false, true );
739
740 msg << wxT( "\n" );
741 msg << _( "Drill holes" ) << wxT( "\n-----------\n" );
742 msg << wxT( "\n" );
743
744 printGridToStringAsTable( m_gridDrills, msg, true, false );
745
746 if( fprintf( outFile, "%s", TO_UTF8( msg ) ) < 0 )
747 {
748 msg.Printf( _( "Error writing file '%s'." ), dlg.GetPath() );
749 DisplayErrorMessage( this, msg );
750 }
751
752 fclose( outFile );
753}
754
755
756void DIALOG_BOARD_STATISTICS::drillGridSize( wxSizeEvent& aEvent )
757{
758 aEvent.Skip();
760}
761
762void DIALOG_BOARD_STATISTICS::drillGridSort( wxGridEvent& aEvent )
763{
764 DRILL_LINE_ITEM::COL_ID colId = static_cast<DRILL_LINE_ITEM::COL_ID>( aEvent.GetCol() );
765 bool ascending = !( m_gridDrills->IsSortingBy( colId )
766 && m_gridDrills->IsSortOrderAscending() );
767
768 sort( m_drillTypes.begin(), m_drillTypes.end(), DRILL_LINE_ITEM::COMPARE( colId, ascending ) );
769
771}
772
773
775{
776}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:276
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, OUTLINE_ERROR_HANDLER *aErrorHandler=nullptr, bool aAllowUseArcsInPolygons=false, bool aIncludeNPTHAsOutlines=false)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
Definition: board.cpp:2194
FOOTPRINTS & Footprints()
Definition: board.h:318
TRACKS & Tracks()
Definition: board.h:315
const wxString & GetFileName() const
Definition: board.h:313
DRAWINGS & Drawings()
Definition: board.h:321
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:539
coord_type GetHeight() const
Definition: box2.h:189
coord_type GetWidth() const
Definition: box2.h:188
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:589
Class DIALOG_BOARD_STATISTICS_BASE.
void checkboxClicked(wxCommandEvent &aEvent) override
Save board statistics to a file.
void printGridToStringAsTable(wxGrid *aGrid, wxString &aStr, bool aUseColLabels, bool aUseFirstColAsLabel)
std::deque< FP_LINE_ITEM > m_fpTypes
int m_startLayerColInitialSize
Width of the start layer column as calculated by the wxWidgets autosizing algorithm.
void updateWidets()
Update drills grid.
void saveReportClicked(wxCommandEvent &aEvent) override
std::deque< LINE_ITEM< PAD_ATTRIB > > m_padTypes
void updateDrillGrid()
Print grid to string in tabular format.
~DIALOG_BOARD_STATISTICS()
Get data from the PCB board and print it to dialog.
int m_stopLayerColInitialSize
Width of the stop layer column.
DIALOG_BOARD_STATISTICS(PCB_EDIT_FRAME *aParentFrame)
void drillGridSort(wxGridEvent &aEvent)
void refreshItemsTypes()
< Function to fill up all items types to be shown in the dialog.
void drillGridSize(wxSizeEvent &aEvent) override
bool m_hasOutline
Show if board outline properly defined.
std::deque< DRILL_LINE_ITEM > m_drillTypes
std::deque< LINE_ITEM< VIATYPE > > m_viaTypes
void getDataFromPCB()
Apply data to dialog widgets.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Definition: pad.h:59
BOARD * GetBoard() const
The main frame for Pcbnew.
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:129
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:147
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
double Area(bool aAbsolute=true) const
Return the area of this chain.
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.
int HoleCount(int aOutline) const
Returns the number of holes in a given outline.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
SHAPE_LINE_CHAIN & Hole(int aOutline, int aHole)
Return the reference to aHole-th hole in the aIndex-th outline.
int OutlineCount() const
Return the number of outlines in the set.
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:599
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
This file is part of the common library.
static DIALOG_BOARD_STATISTICS_SAVED_STATE s_savedDialogState
#define ROW_BOARD_AREA
#define COL_AMOUNT
#define ROW_LABEL
#define COL_BOTTOM_SIDE
#define ROW_BOARD_WIDTH
#define COL_LABEL
#define COL_TOTAL
static wxString formatCount(int aCount)
#define COL_FRONT_SIDE
#define ROW_BOARD_HEIGHT
#define _(s)
@ FP_SMD
Definition: footprint.h:73
@ FP_THROUGH_HOLE
Definition: footprint.h:72
static wxString TextFileWildcard()
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ Edge_Cuts
Definition: layer_ids.h:114
@ B_Cu
Definition: layer_ids.h:96
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:65
This file contains miscellaneous commonly used macros and functions.
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition: gtk/ui.cpp:195
wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:127
@ PAD_DRILL_SHAPE_CIRCLE
Definition: pad_shapes.h:70
@ PAD_DRILL_SHAPE_OBLONG
Definition: pad_shapes.h:71
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:391
Footprint attributes (such as SMD, THT, Virtual and so on), which will be shown in the dialog.
Type information, which will be shown in dialog.
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
Definition of file extensions used in Kicad.