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-2024 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();
208
209 // Get footprints and pads count
210 for( FOOTPRINT* footprint : board->Footprints() )
211 {
212 // Do not proceed footprints with no pads if checkbox checked
213 if( m_checkBoxExcludeComponentsNoPins->GetValue() && ! footprint->Pads().size() )
214 continue;
215
216 // Go through components types list
217 for( FP_LINE_ITEM& line : m_fpTypes )
218 {
219 if( ( footprint->GetAttributes() & line.attribute_mask ) == line.attribute_value )
220 {
221 switch( footprint->GetSide() )
222 {
223 case F_Cu: line.frontSideQty++; break;
224 case B_Cu: line.backSideQty++; break;
225 default: /* unsided: user-layers only, etc. */ break;
226 }
227
228 break;
229 }
230 }
231
232 for( PAD* pad : footprint->Pads() )
233 {
234 // Go through pads types list
235 for( LINE_ITEM<PAD_ATTRIB>& line : m_padTypes )
236 {
237 if( pad->GetAttribute() == line.attribute )
238 {
239 line.qty++;
240 break;
241 }
242 }
243
244 if( pad->GetDrillSize().x > 0 && pad->GetDrillSize().y > 0 )
245 {
246 PCB_LAYER_ID top, bottom;
247
248 if( pad->GetLayerSet().CuStack().empty() )
249 {
250 // The pad is not on any copper layer
251 top = UNDEFINED_LAYER;
252 bottom = UNDEFINED_LAYER;
253 }
254 else
255 {
256 top = pad->GetLayerSet().CuStack().front();
257 bottom = pad->GetLayerSet().CuStack().back();
258 }
259
260 DRILL_LINE_ITEM drill( pad->GetDrillSize().x, pad->GetDrillSize().y,
261 pad->GetDrillShape(),
262 pad->GetAttribute() != PAD_ATTRIB::NPTH,
263 true, top, bottom );
264
265 auto it = m_drillTypes.begin();
266
267 for( ; it != m_drillTypes.end(); ++it )
268 {
269 if( *it == drill )
270 {
271 it->qty++;
272 break;
273 }
274 }
275
276 if( it == m_drillTypes.end() )
277 {
278 drill.qty = 1;
279 m_drillTypes.push_back( drill );
280 m_gridDrills->InsertRows();
281 }
282 }
283 }
284 }
285
286 // Get via counts
287 for( PCB_TRACK* track : board->Tracks() )
288 {
289 if( track->Type() == PCB_VIA_T )
290 {
291 PCB_VIA* via = static_cast<PCB_VIA*>( track );
292
293 for( LINE_ITEM<VIATYPE>& line : m_viaTypes )
294 {
295 if( via->GetViaType() == line.attribute )
296 {
297 line.qty++;
298 break;
299 }
300 }
301
302 DRILL_LINE_ITEM drill( via->GetDrillValue(), via->GetDrillValue(),
303 PAD_DRILL_SHAPE::CIRCLE, true, false, via->TopLayer(),
304 via->BottomLayer() );
305
306 auto it = m_drillTypes.begin();
307
308 for( ; it != m_drillTypes.end(); ++it )
309 {
310 if( *it == drill )
311 {
312 it->qty++;
313 break;
314 }
315 }
316
317 if( it == m_drillTypes.end() )
318 {
319 drill.qty = 1;
320 m_drillTypes.push_back( drill );
321 m_gridDrills->InsertRows();
322 }
323 }
324 }
325
326 sort( m_drillTypes.begin(), m_drillTypes.end(),
328
329 SHAPE_POLY_SET polySet;
330 m_hasOutline = board->GetBoardPolygonOutlines( polySet );
331
332 if( m_hasOutline )
333 {
334 m_boardArea = 0.0;
335
336 for( int i = 0; i < polySet.OutlineCount(); i++ )
337 {
338 SHAPE_LINE_CHAIN& outline = polySet.Outline( i );
339 m_boardArea += outline.Area();
340
341 // If checkbox "subtract holes" is checked
342 if( m_checkBoxSubtractHoles->GetValue() )
343 {
344 for( int j = 0; j < polySet.HoleCount( i ); j++ )
345 m_boardArea -= polySet.Hole( i, j ).Area();
346
347 for( FOOTPRINT* fp : board->Footprints() )
348 {
349 for( PAD* pad : fp->Pads() )
350 {
351 if( !pad->HasHole() )
352 continue;
353
354 auto hole = pad->GetEffectiveHoleShape();
355 const SEG& seg = hole->GetSeg();
356 double width = hole->GetWidth();
357 double area = seg.Length() * width;
358
359 // Each end of the hole is a half-circle, so together, we have one
360 // full circle. The area of a circle is pi * r^2, so the area of the
361 // hole is pi * (d/2)^2 = pi * 1/4 * d^2.
362 area += M_PI * 0.25 * width * width;
363 m_boardArea -= area;
364 }
365 }
366
367 for( PCB_TRACK* track : board->Tracks() )
368 {
369 if( track->Type() == PCB_VIA_T )
370 {
371 PCB_VIA* via = static_cast<PCB_VIA*>( track );
372 double drill = via->GetDrillValue();
373 m_boardArea -= M_PI * 0.25 * drill * drill;
374 }
375 }
376 }
377 }
378
379 // Compute the bounding box to get a rectangular size
380 // We use the polySet bounding box, not the board bounding box, because
381 // we do not want the thickness of graphic items defining the board outlines
382 // to be taken in account to calculate the physical board bbox
383 BOX2I bbox = polySet.BBox();
384
385 m_boardWidth = bbox.GetWidth();
386 m_boardHeight = bbox.GetHeight();
387 }
388}
389
390
391static wxString formatCount( int aCount )
392{
393 return wxString::Format( wxT( "%i" ), aCount );
394};
395
396
398{
399 int totalPads = 0;
400 int row = 0;
401
402 for( const LINE_ITEM<PAD_ATTRIB>& line : m_padTypes )
403 {
404 m_gridPads->SetCellValue( row, COL_LABEL, line.title );
405 m_gridPads->SetCellValue( row, COL_AMOUNT, formatCount( line.qty ) );
406 totalPads += line.qty;
407 row++;
408 }
409
410 m_gridPads->SetCellValue( row, COL_LABEL, _( "Total:" ) );
411 m_gridPads->SetCellValue( row, COL_AMOUNT, formatCount( totalPads ) );
412
413 int totalVias = 0;
414 row = 0;
415
416 for( const LINE_ITEM<VIATYPE>& line : m_viaTypes )
417 {
418 m_gridVias->SetCellValue( row, COL_LABEL, line.title );
419 m_gridVias->SetCellValue( row, COL_AMOUNT, formatCount( line.qty ) );
420 totalVias += line.qty;
421 row++;
422 }
423
424 m_gridVias->SetCellValue( row, COL_LABEL, _( "Total:" ) );
425 m_gridVias->SetCellValue( row, COL_AMOUNT, formatCount( totalVias ) );
426
427
428 int totalFront = 0;
429 int totalBack = 0;
430
431 // We don't use row 0, as there labels are
432 row = 1;
433
434 for( const FP_LINE_ITEM& line : m_fpTypes )
435 {
436 m_gridComponents->SetCellValue( row, COL_LABEL, line.title );
437 m_gridComponents->SetCellValue( row, COL_FRONT_SIDE, formatCount( line.frontSideQty ) );
438 m_gridComponents->SetCellValue( row, COL_BOTTOM_SIDE, formatCount( line.backSideQty ) );
439 m_gridComponents->SetCellValue( row, 3, formatCount( line.frontSideQty + line.backSideQty ) );
440 totalFront += line.frontSideQty;
441 totalBack += line.backSideQty;
442 row++;
443 }
444
445 m_gridComponents->SetCellValue( row, COL_LABEL, _( "Total:" ) );
446 m_gridComponents->SetCellValue( row, COL_FRONT_SIDE, formatCount( totalFront ) );
447 m_gridComponents->SetCellValue( row, COL_BOTTOM_SIDE, formatCount( totalBack ) );
448 m_gridComponents->SetCellValue( row, COL_TOTAL, formatCount( totalFront + totalBack ) );
449
450 if( m_hasOutline )
451 {
452 m_gridBoard->SetCellValue( ROW_BOARD_WIDTH, COL_AMOUNT,
456 m_gridBoard->SetCellValue( ROW_BOARD_AREA, COL_AMOUNT,
458 EDA_DATA_TYPE::AREA ) );
459 }
460 else
461 {
462 m_gridBoard->SetCellValue( ROW_BOARD_WIDTH, COL_AMOUNT, _( "unknown" ) );
463 m_gridBoard->SetCellValue( ROW_BOARD_HEIGHT, COL_AMOUNT, _( "unknown" ) );
464 m_gridBoard->SetCellValue( ROW_BOARD_AREA, COL_AMOUNT, _( "unknown" ) );
465 }
466
468
469 m_gridComponents->AutoSize();
470 m_gridPads->AutoSize();
471 m_gridBoard->AutoSize();
472 m_gridVias->AutoSize();
473
475}
476
477
479{
480 BOARD* board = m_parentFrame->GetBoard();
481 int row = 0;
482
483 for( const DRILL_LINE_ITEM& line : m_drillTypes )
484 {
485 wxString shapeStr;
486 wxString startLayerStr;
487 wxString stopLayerStr;
488
489 switch( line.shape )
490 {
491 case PAD_DRILL_SHAPE::CIRCLE: shapeStr = _( "Round" ); break;
492 case PAD_DRILL_SHAPE::OBLONG: shapeStr = _( "Slot" ); break;
493 default: shapeStr = _( "???" ); break;
494 }
495
496 if( line.startLayer == UNDEFINED_LAYER )
497 startLayerStr = _( "N/A" );
498 else
499 startLayerStr = board->GetLayerName( line.startLayer );
500
501 if( line.stopLayer == UNDEFINED_LAYER )
502 stopLayerStr = _( "N/A" );
503 else
504 stopLayerStr = board->GetLayerName( line.stopLayer );
505
506 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_COUNT, formatCount( line.qty ) );
507 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_SHAPE, shapeStr );
508 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_X_SIZE,
509 m_parentFrame->MessageTextFromValue( line.xSize ) );
510 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_Y_SIZE,
511 m_parentFrame->MessageTextFromValue( line.ySize ) );
512 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_PLATED,
513 line.isPlated ? _( "PTH" ) : _( "NPTH" ) );
514 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_VIA_PAD,
515 line.isPad ? _( "Pad" ) : _( "Via" ) );
516 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_START_LAYER, startLayerStr );
517 m_gridDrills->SetCellValue( row, DRILL_LINE_ITEM::COL_STOP_LAYER, stopLayerStr );
518
519 row++;
520 }
521}
522
523
524void DIALOG_BOARD_STATISTICS::printGridToStringAsTable( wxGrid* aGrid, wxString& aStr,
525 bool aUseColLabels,
526 bool aUseFirstColAsLabel )
527{
528 std::vector<int> widths( aGrid->GetNumberCols(), 0 );
529 int rowLabelsWidth = 0;
530
531 // Determine column widths.
532
533 if( aUseColLabels )
534 {
535 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
536 widths[col] = aGrid->GetColLabelValue( col ).length();
537 }
538
539 for( int row = 0; row < aGrid->GetNumberRows(); row++ )
540 {
541 rowLabelsWidth = std::max<int>( rowLabelsWidth, aGrid->GetRowLabelValue( row ).length() );
542
543 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
544 widths[col] = std::max<int>( widths[col], aGrid->GetCellValue( row, col ).length() );
545 }
546
547 // Print the cells.
548
549 wxString tmp;
550
551 // Print column labels.
552
553 aStr << wxT( "|" );
554
555 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
556 {
557 if( aUseColLabels )
558 tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetColLabelValue( col ) );
559 else
560 tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetCellValue( 0, col ) );
561
562 aStr << tmp;
563 }
564
565 aStr << wxT( "\n" );
566
567 // Print column label horizontal separators.
568
569 aStr << wxT( "|" );
570
571 for( int col = 0; col < aGrid->GetNumberCols(); col++ )
572 {
573 aStr << wxT( "-" );
574 aStr.Append( '-', widths[col] );
575 aStr << wxT( "-|" );
576 }
577
578 aStr << wxT( "\n" );
579
580 // Print regular cells.
581
582 int firstRow = 0, firstCol = 0;
583
584 if( !aUseColLabels )
585 firstRow = 1;
586
587 if( aUseFirstColAsLabel )
588 firstCol = 1;
589
590 for( int row = firstRow; row < aGrid->GetNumberRows(); row++ )
591 {
592 if( aUseFirstColAsLabel )
593 tmp.Printf( wxT( "|%-*s |" ), widths[0], aGrid->GetCellValue( row, 0 ) );
594 else
595 tmp.Printf( wxT( "|" ) );
596
597 aStr << tmp;
598
599 for( int col = firstCol; col < aGrid->GetNumberCols(); col++ )
600 {
601 tmp.Printf( wxT( " %*s |" ), widths[col], aGrid->GetCellValue( row, col ) );
602 aStr << tmp;
603 }
604
605 aStr << wxT( "\n" );
606 }
607}
608
609
611{
612 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_gridDrills );
613
615
616 double remainingWidth = KIPLATFORM::UI::GetUnobscuredSize( m_gridDrills ).x;
617
618 // Find the total current width
619 for( int i = 0; i < m_gridDrills->GetNumberCols(); i++ )
620 {
622 remainingWidth -= m_gridDrills->GetColSize( i );
623 }
624
625 double scalingFactor = std::max( 1.0,
626 remainingWidth
628 int startLayerColWidth = static_cast<int>( m_startLayerColInitialSize * scalingFactor );
629 int stopLayerColWidth = static_cast<int>( m_stopLayerColInitialSize * scalingFactor );
630
631 m_gridDrills->SetColSize( DRILL_LINE_ITEM::COL_START_LAYER, startLayerColWidth );
632 m_gridDrills->SetColSize( DRILL_LINE_ITEM::COL_STOP_LAYER, stopLayerColWidth );
633}
634
635
636void DIALOG_BOARD_STATISTICS::checkboxClicked( wxCommandEvent& aEvent )
637{
642 updateWidets();
643 Layout();
644 m_drillsPanel->Layout();
645}
646
647
648void DIALOG_BOARD_STATISTICS::saveReportClicked( wxCommandEvent& aEvent )
649{
650 FILE* outFile;
651 wxString msg;
652 wxString boardName;
653
654 wxFileName fn = m_parentFrame->GetBoard()->GetFileName();
655 boardName = fn.GetName();
656 wxFileDialog dlg( this, _( "Save Report File" ), s_savedDialogState.saveReportFolder,
658 wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
659
660 if( dlg.ShowModal() == wxID_CANCEL )
661 return;
662
663 s_savedDialogState.saveReportFolder = wxPathOnly( dlg.GetPath() );
664 s_savedDialogState.saveReportName = dlg.GetFilename();
665
666 outFile = wxFopen( dlg.GetPath(), wxT( "wt" ) );
667
668 if( outFile == nullptr )
669 {
670 msg.Printf( _( "Failed to create file '%s'." ), dlg.GetPath() );
671 DisplayErrorMessage( this, msg );
672 return;
673 }
674
675 msg << _( "PCB statistics report\n=====================" ) << wxT( "\n" );
676 msg << wxS( "- " ) << _( "Date" ) << wxS( ": " ) << wxDateTime::Now().Format() << wxT( "\n" );
677 msg << wxS( "- " ) << _( "Project" ) << wxS( ": " )<< Prj().GetProjectName() << wxT( "\n" );
678 msg << wxS( "- " ) << _( "Board name" ) << wxS( ": " )<< boardName << wxT( "\n" );
679
680 msg << wxT( "\n" );
681 msg << _( "Board" ) << wxT( "\n-----\n" );
682
683 if( m_hasOutline )
684 {
685 msg << wxS( "- " ) << _( "Width" ) << wxS( ": " )
686 << m_parentFrame->MessageTextFromValue( m_boardWidth ) << wxT( "\n" );
687 msg << wxS( "- " ) << _( "Height" ) << wxS( ": " )
689 msg << wxS( "- " ) << _( "Area" ) + wxS( ": " )
690 << m_parentFrame->MessageTextFromValue( m_boardArea, true, EDA_DATA_TYPE::AREA );
691 msg << wxT( "\n" );
692 }
693 else
694 {
695 msg << wxS( "- " ) << _( "Width" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
696 msg << wxS( "- " ) << _( "Height" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
697 msg << wxS( "- " ) << _( "Area" ) << wxS( ": " ) << _( "unknown" ) << wxT( "\n" );
698 }
699
700 msg << wxT( "\n" );
701 msg << _( "Pads" ) << wxT( "\n----\n" );
702
703 for( auto& type : m_padTypes )
704 msg << wxT( "- " ) << type.title << wxS( " " ) << type.qty << wxT( "\n" );
705
706 msg << wxT( "\n" );
707 msg << _( "Vias" ) << wxT( "\n----\n" );
708
709 for( auto& type : m_viaTypes )
710 msg << wxT( "- " ) << type.title << wxS( " " ) << type.qty << wxT( "\n" );
711
712 // We will save data about components in the table.
713 // We have to calculate column widths
714 std::vector<int> widths;
715 std::vector<wxString> labels{ wxT( "" ), _( "Front Side" ), _( "Back Side" ), _( "Total" ) };
716 wxString tmp;
717
718 widths.reserve( labels.size() );
719
720 for( const wxString& label : labels )
721 widths.push_back( label.size() );
722
723 int frontTotal = 0;
724 int backTotal = 0;
725
726 for( const FP_LINE_ITEM& line : m_fpTypes )
727 {
728 // Get maximum width for left label column
729 widths[0] = std::max<int>( line.title.size(), widths[0] );
730 frontTotal += line.frontSideQty;
731 backTotal += line.backSideQty;
732 }
733
734 // Get maximum width for other columns
735 tmp.Printf( wxT( "%i" ), frontTotal );
736 widths[1] = std::max<int>( tmp.size(), widths[1] );
737 tmp.Printf( wxT( "%i" ), backTotal );
738 widths[2] = std::max<int>( tmp.size(), widths[2] );
739 tmp.Printf( wxT( "%i" ), frontTotal + backTotal );
740 widths[3] = std::max<int>( tmp.size(), widths[3] );
741
742 //Write components amount to file
743 msg << wxT( "\n" );
744 msg << _( "Components" ) << wxT( "\n----------\n" );
745 msg << wxT( "\n" );
746
747 printGridToStringAsTable( m_gridComponents, msg, false, true );
748
749 msg << wxT( "\n" );
750 msg << _( "Drill holes" ) << wxT( "\n-----------\n" );
751 msg << wxT( "\n" );
752
753 printGridToStringAsTable( m_gridDrills, msg, true, false );
754
755 if( fprintf( outFile, "%s", TO_UTF8( msg ) ) < 0 )
756 {
757 msg.Printf( _( "Error writing file '%s'." ), dlg.GetPath() );
758 DisplayErrorMessage( this, msg );
759 }
760
761 fclose( outFile );
762}
763
764
765void DIALOG_BOARD_STATISTICS::drillGridSize( wxSizeEvent& aEvent )
766{
767 aEvent.Skip();
769}
770
771void DIALOG_BOARD_STATISTICS::drillGridSort( wxGridEvent& aEvent )
772{
773 DRILL_LINE_ITEM::COL_ID colId = static_cast<DRILL_LINE_ITEM::COL_ID>( aEvent.GetCol() );
774 bool ascending = !( m_gridDrills->IsSortingBy( colId )
775 && m_gridDrills->IsSortOrderAscending() );
776
777 sort( m_drillTypes.begin(), m_drillTypes.end(), DRILL_LINE_ITEM::COMPARE( colId, ascending ) );
778
780}
781
782
784{
785}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
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:2493
const FOOTPRINTS & Footprints() const
Definition: board.h:331
const TRACKS & Tracks() const
Definition: board.h:329
const wxString & GetFileName() const
Definition: board.h:327
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:579
constexpr size_type GetWidth() const
Definition: box2.h:214
constexpr size_type GetHeight() const
Definition: box2.h:215
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:54
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
Definition: seg.h:42
int Length() const
Return the length (this).
Definition: seg.h:333
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.
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.
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
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:809
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
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:76
@ FP_THROUGH_HOLE
Definition: footprint.h:75
static wxString TextFileWildcard()
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Cu
Definition: layer_ids.h:65
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
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: wxgtk/ui.cpp:195
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
Definition: ui_common.cpp:130
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: string_utils.h:398
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.