KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_generated_table.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <algorithm>
21#include <set>
22
23#include <pcb_generated_table.h>
24
25#include <base_units.h>
26#include <font/font.h>
29#include <i18n_utility.h>
30#include <pcb_tablecell.h>
32#include <widgets/msgpanel.h>
33
34
35namespace
36{
37
38GR_TEXT_H_ALIGN_T toHorizJustify( GENERATED_TABLE_ALIGN aAlign )
39{
40 switch( aAlign )
41 {
45 }
46
48}
49
50
51void copyCellStyle( PCB_TABLECELL* aCell, const PCB_TABLECELL* aDonor )
52{
53 aCell->SetAttributes( *aDonor, false );
54 aCell->SetIsKnockout( aDonor->IsKnockout() );
55 aCell->SetMarginLeft( aDonor->GetMarginLeft() );
56 aCell->SetMarginTop( aDonor->GetMarginTop() );
57 aCell->SetMarginRight( aDonor->GetMarginRight() );
58 aCell->SetMarginBottom( aDonor->GetMarginBottom() );
59}
60
61
62// A subclass short of cells for a column shows it blank rather than reading past the end
63const wxString& textAt( const std::vector<wxString>& aCells, int aCol )
64{
65 static const wxString empty;
66
67 return aCol < static_cast<int>( aCells.size() ) ? aCells[aCol] : empty;
68}
69
70} // namespace
71
72
74 PCB_TABLE( aParent, aType, aLineWidth ),
76 m_precision( 3 )
77{
78 // RefreshGeneratedTables finds tables by type, so an unlisted one would never refresh
79 wxASSERT( IsGeneratedTableType( aType ) );
80}
81
82
84 PCB_TABLE( aOther ),
85 m_columns( aOther.m_columns ),
86 m_units( aOther.m_units ),
87 m_precision( aOther.m_precision ),
88 m_rowKeys( aOther.m_rowKeys ),
89 m_hidden( aOther.m_hidden )
90{}
91
92
94{
95 wxCHECK_RET( aImage && aImage->Type() == Type(), wxT( "Cannot swap data with invalid table." ) );
96
97 PCB_TABLE::swapData( aImage );
98
99 PCB_GENERATED_TABLE* other = static_cast<PCB_GENERATED_TABLE*>( aImage );
100
101 std::swap( m_columns, other->m_columns );
102 std::swap( m_units, other->m_units );
103 std::swap( m_precision, other->m_precision );
104 std::swap( m_rowKeys, other->m_rowKeys );
105 std::swap( m_hidden, other->m_hidden );
106}
107
108
110{
111 wxCHECK( aOther && aOther->Type() == Type(), /* void */ );
112
113 // PCB_TABLE's copy only accepts a plain table. swapData covers every member a subclass adds
114 std::unique_ptr<BOARD_ITEM> copy( static_cast<BOARD_ITEM*>( aOther->Clone() ) );
115 SwapItemData( copy.get() );
116}
117
118
120{
121 // Before SetColumns, while both tables still have the same cells to measure from
122 Move( aOther.GetPosition() - GetPosition() );
123
124 SetColumns( aOther.AllColumns() );
125 SetUnits( aOther.GetUnits() );
126 SetPrecision( aOther.GetPrecision() );
127 SetLayer( aOther.GetLayer() );
128 SetLocked( aOther.IsLocked() );
129
133 SetStrokeRows( aOther.StrokeRows() );
136
138}
139
140
142{
143 return m_columns == aOther.m_columns && m_units == aOther.m_units && m_precision == aOther.m_precision
144 && m_rowKeys == aOther.m_rowKeys && m_hidden == aOther.m_hidden
145 && PCB_TABLE::operator==( aOther );
146}
147
148
149double PCB_GENERATED_TABLE::Similarity( const BOARD_ITEM& aOther ) const
150{
151 double similarity = PCB_TABLE::Similarity( aOther );
152
153 if( aOther.Type() != Type() )
154 return similarity;
155
156 const PCB_GENERATED_TABLE& other = static_cast<const PCB_GENERATED_TABLE&>( aOther );
157
158 if( m_columns != other.m_columns || m_hidden != other.m_hidden )
159 similarity *= 0.9;
160
161 return similarity;
162}
163
164
165std::vector<GENERATED_TABLE_COLUMN> PCB_GENERATED_TABLE::AllColumns() const
166{
167 std::vector<GENERATED_TABLE_COLUMN> all;
168 const size_t total = m_columns.size() + m_hidden.size();
169 size_t shown = 0;
170 size_t hidden = 0;
171
172 for( size_t pos = 0; pos < total; ++pos )
173 {
174 const bool hiddenHere = hidden < m_hidden.size()
175 && ( m_hidden[hidden].m_Position == static_cast<int>( pos )
176 || shown == m_columns.size() );
177
178 if( hiddenHere )
179 all.push_back( m_hidden[hidden++].m_Column );
180 else
181 all.push_back( m_columns[shown++] );
182 }
183
184 return all;
185}
186
187
188void PCB_GENERATED_TABLE::RestoreColumns( const std::vector<GENERATED_TABLE_COLUMN>& aColumns )
189{
190 m_columns.clear();
191 m_hidden.clear();
192
193 for( size_t pos = 0; pos < aColumns.size(); ++pos )
194 {
195 GENERATED_TABLE_COLUMN col = aColumns[pos];
196
197 if( col.m_Visible )
198 {
199 m_columns.push_back( col );
200 continue;
201 }
202
203 HIDDEN_COLUMN& entry = m_hidden.emplace_back();
204 entry.m_Column = col;
205 entry.m_Position = static_cast<int>( pos );
206 }
207}
208
209
210std::vector<int> PCB_GENERATED_TABLE::dataRows() const
211{
212 std::vector<int> rows;
213
214 for( int row = 1; row < GetRowCount(); ++row )
215 {
216 if( IsDataRow( row ) )
217 rows.push_back( row );
218 }
219
220 return rows;
221}
222
223
225{
226 const std::vector<int> rows = dataRows();
227
228 return rows.empty() ? 0 : GetRowHeight( rows.front() );
229}
230
231
233{
234 for( int row : dataRows() )
235 SetRowHeight( row, std::max( aHeight, minRowHeight( row ) ) );
236
237 Normalize();
238}
239
240
241void PCB_GENERATED_TABLE::SetRowHeightToFit( int aRow, int aHeight )
242{
243 SetRowHeight( aRow, std::max( aHeight, minRowHeight( aRow ) ) );
244 Normalize();
245}
246
247
249{
250 const int first = GetRowHeightProp();
251
252 return std::ranges::any_of( dataRows(),
253 [&]( int aRow )
254 {
255 return GetRowHeight( aRow ) != first;
256 } );
257}
258
259
260void PCB_GENERATED_TABLE::setAutosizedRowHeights( const std::vector<int>& aNeeded )
261{
262 const int rows = GetRowCount();
263
264 // Cells take Autosize's widths first, or the line metrics below follow the old wrap
265 Normalize();
266
267 // Normalize() stores a missing row as 0, so 0 is no height rather than the user's
268 std::vector<int> held( rows );
269 std::vector<int> fit( rows );
270
271 for( int row = 0; row < rows; ++row )
272 {
273 held[row] = std::max( GetRowHeight( row ), 0 );
274
275 // Glyph outlines differ by character, which splits the Row Height by microns, so data rows
276 // size to line metrics unless a glyph reaches past them
277 fit[row] = IsDataRow( row ) ? std::max( aNeeded[row], metricRowHeight( row ) ) : aNeeded[row];
278 }
279
280 int maxNeed = 0;
281 std::map<int, int> counts;
282
283 for( int row : dataRows() )
284 {
285 maxNeed = std::max( maxNeed, fit[row] );
286
287 if( held[row] > 0 )
288 counts[held[row]]++;
289 }
290
291 // A data row without a height of its own matches most of its siblings, larger on a tie. With
292 // none held, as in a fresh table, all share the tallest need, or glyph descents split the value
293 int common = maxNeed;
294 int commonCount = 0;
295
296 for( const auto& [height, count] : counts )
297 {
298 if( count >= commonCount )
299 {
300 common = height;
301 commonCount = count;
302 }
303 }
304
305 // Rows default to their text plus margins, but keep any height that still holds the text, down to
306 // the text touching its edges. Text that outgrows a height refits it with margins, so one row's
307 // font moves no sibling
308 for( int row = 0; row < rows; ++row )
309 {
310 const int height = IsDataRow( row ) && held[row] == 0 ? common : held[row];
311
312 SetRowHeight( row, height > 0 && height >= minRowHeight( row ) ? height : fit[row] );
313 }
314}
315
316
318{
319 int height = 0;
320
321 for( int col = 0; col < GetColCount(); ++col )
322 {
323 const PCB_TABLECELL* cell = GetCell( aRow, col );
324
325 if( !cell )
326 continue;
327
328 const int lines = static_cast<int>( cell->GetShownText( FOR_CANVAS ).Freq( '\n' ) ) + 1;
329
330 // The pen strokes half its width past the glyph geometry on each side
331 height = std::max( height, lines * cell->GetInterline( nullptr ) + cell->GetEffectiveTextPenWidth()
332 + cell->GetMarginTop() + cell->GetMarginBottom() );
333 }
334
335 return height;
336}
337
338
340{
341 int height = 0;
342
343 for( int col = 0; col < GetColCount(); ++col )
344 {
345 const PCB_TABLECELL* cell = GetCell( aRow, col );
346
347 if( !cell )
348 continue;
349
350 SHAPE_POLY_SET glyphs;
352
353 if( glyphs.IsEmpty() )
354 continue;
355
356 const VECTOR2I anchor = cell->GetDrawPos();
357 glyphs.Rotate( -cell->GetDrawRotation(), anchor );
358
359 const BOX2I box = glyphs.BBox();
360 const int above = anchor.y - box.GetTop();
361 const int below = box.GetBottom() - anchor.y;
362
363 // Centred text ignores the vertical margins, while top and bottom text sits one margin in
364 switch( cell->GetVertJustify() )
365 {
366 case GR_TEXT_V_ALIGN_TOP: height = std::max( height, cell->GetMarginTop() + below ); break;
367 case GR_TEXT_V_ALIGN_BOTTOM: height = std::max( height, cell->GetMarginBottom() + above ); break;
368 default: height = std::max( height, 2 * std::max( above, below ) ); break;
369 }
370 }
371
372 return height;
373}
374
375
376const PCB_TABLECELL* PCB_GENERATED_TABLE::nearestDataCell( int aRow, int aCol, const std::set<KIID>& aStyled ) const
377{
378 const int rows = GetRowCount();
379
380 for( int dist = 1; dist < rows; ++dist )
381 {
382 for( int row : { aRow - dist, aRow + dist } )
383 {
384 if( row < 1 || row >= rows || !IsDataRow( row ) )
385 continue;
386
387 if( const PCB_TABLECELL* cell = GetCell( row, aCol ); cell && aStyled.count( cell->m_Uuid ) )
388 return cell;
389 }
390 }
391
392 return nullptr;
393}
394
395
396void PCB_GENERATED_TABLE::styleFromColumn( PCB_TABLECELL* aCell, int aRow, int aCol, const std::set<KIID>& aStyled )
397{
398 const PCB_TABLECELL* donor = aRow > 0 ? nearestDataCell( aRow, aCol, aStyled ) : nullptr;
399
400 if( !donor )
401 {
402 styleNewCell( aCell, aRow == 0 );
403 return;
404 }
405
406 copyCellStyle( aCell, donor );
407}
408
409
411{
412 const PCB_TABLECELL* first = firstCell();
413
414 return first ? first->GetFontProp() : wxString();
415}
416
417
418void PCB_GENERATED_TABLE::SetFontNameProp( const wxString& aFontName )
419{
421 [&]( PCB_TABLECELL* aCell )
422 {
423 aCell->SetFontProp( aFontName );
424 } );
425}
426
427
429{
430 const wxString first = GetFontNameProp();
431
432 return anyCell(
433 [&]( const PCB_TABLECELL* aCell )
434 {
435 return aCell->GetFontProp() != first;
436 } );
437}
438
439
441{
442 const PCB_TABLECELL* first = firstCell();
443
444 return first ? first->GetFontSize() : 0;
445}
446
447
449{
451 [&]( PCB_TABLECELL* aCell )
452 {
453 aCell->SetFontSize( aSize );
454 } );
455}
456
457
459{
460 const int first = GetFontSizeProp();
461
462 return anyCell(
463 [&]( const PCB_TABLECELL* aCell )
464 {
465 return !aCell->HasSquareFontSize() || aCell->GetFontSize() != first;
466 } );
467}
468
469
470void PCB_GENERATED_TABLE::forEachCell( const std::function<void( PCB_TABLECELL* )>& aFunc )
471{
472 anyCell(
473 [&]( const PCB_TABLECELL* aCell )
474 {
475 aFunc( const_cast<PCB_TABLECELL*>( aCell ) );
476 return false;
477 } );
478}
479
480
481bool PCB_GENERATED_TABLE::anyCell( const std::function<bool( const PCB_TABLECELL* )>& aTest ) const
482{
483 for( const PCB_TABLECELL* cell : m_cells )
484 {
485 if( aTest( cell ) )
486 return true;
487 }
488
489 return false;
490}
491
492
494{
495 const PCB_TABLECELL* first = nullptr;
496
497 anyCell(
498 [&]( const PCB_TABLECELL* aCell )
499 {
500 first = aCell;
501 return true;
502 } );
503
504 return first;
505}
506
507
508void PCB_GENERATED_TABLE::SetColumns( std::vector<GENERATED_TABLE_COLUMN> aColumns )
509{
510 std::vector<GENERATED_TABLE_COLUMN> visible;
511
512 for( const GENERATED_TABLE_COLUMN& col : aColumns )
513 {
514 if( col.m_Visible )
515 visible.push_back( col );
516 }
517
518 const int oldCols = GetColCount();
519 const int newCols = static_cast<int>( visible.size() );
520
521 // The cells were laid out for the old columns, so this is the one place that knows which
522 // column each belongs to. A rebuild only carries cells across by position
523 if( oldCols > 0 && newCols > 0 && oldCols == static_cast<int>( m_columns.size() ) && !m_cells.empty() )
524 {
525 COLUMN_REMAP remap;
526 remap.m_Rows = static_cast<int>( m_cells.size() ) / oldCols;
527 remap.m_OldCols = oldCols;
528 remap.m_NewCols = newCols;
529 remap.m_Cells.assign( static_cast<size_t>( remap.m_Rows ) * newCols, nullptr );
530 remap.m_Origin.assign( remap.m_Cells.size(), CELL_ORIGIN::EMPTY );
531 remap.m_Carried.assign( m_cells.size(), false );
532
533 moveShownCells( visible, remap );
534 placeCells( remap );
535
536 for( size_t ii = 0; ii < m_cells.size(); ++ii )
537 {
538 if( !remap.m_Carried[ii] )
539 delete m_cells[ii];
540 }
541
542 m_cells = std::move( remap.m_Cells );
543 m_colWidths = std::move( remap.m_ColWidths );
544 SetColCount( newCols );
545
547 }
548
549 m_columns = std::move( visible );
550 m_hidden.clear();
551
552 for( size_t pos = 0; pos < aColumns.size(); ++pos )
553 {
554 if( aColumns[pos].m_Visible )
555 continue;
556
557 HIDDEN_COLUMN& hidden = m_hidden.emplace_back();
558 hidden.m_Column = aColumns[pos];
559 hidden.m_Position = static_cast<int>( pos );
560 }
561}
562
563
564void PCB_GENERATED_TABLE::moveShownCells( const std::vector<GENERATED_TABLE_COLUMN>& aShown,
565 COLUMN_REMAP& aRemap ) const
566{
567 for( int col = 0; col < aRemap.m_NewCols; ++col )
568 {
569 int from = -1;
570
571 for( int ii = 0; ii < aRemap.m_OldCols && from < 0; ++ii )
572 {
573 if( m_columns[ii].m_Id == aShown[col].m_Id )
574 from = ii;
575 }
576
577 if( from < 0 )
578 continue;
579
580 for( int row = 0; row < aRemap.m_Rows; ++row )
581 {
582 const size_t source = static_cast<size_t>( row ) * aRemap.m_OldCols + from;
583 const size_t idx = static_cast<size_t>( row ) * aRemap.m_NewCols + col;
584
585 aRemap.m_Cells[idx] = m_cells[source];
586 aRemap.m_Origin[idx] = CELL_ORIGIN::MOVED;
587 aRemap.m_Carried[source] = true;
588 }
589
590 if( const auto it = m_colWidths.find( from ); it != m_colWidths.end() )
591 aRemap.m_ColWidths[col] = it->second;
592 }
593}
594
595
597{
598 struct SLOT
599 {
600 VECTOR2I m_Start;
601 VECTOR2I m_End;
602 VECTOR2I m_Position;
603 EDA_ANGLE m_Angle;
604 bool m_Mirrored;
605 };
606
607 // Taken before any cell moves, since a moved cell takes on its new slot's geometry
608 std::vector<SLOT> slots;
609 slots.reserve( m_cells.size() );
610
611 for( const PCB_TABLECELL* cell : m_cells )
612 {
613 slots.push_back(
614 { cell->GetStart(), cell->GetEnd(), cell->GetPosition(), cell->GetTextAngle(), cell->IsMirrored() } );
615 }
616
617 // A slot past the old last column borrows that column's geometry
618 for( int row = 0; row < aRemap.m_Rows; ++row )
619 {
620 for( int col = 0; col < aRemap.m_NewCols; ++col )
621 {
622 const size_t idx = static_cast<size_t>( row ) * aRemap.m_NewCols + col;
623 const SLOT& slot = slots[static_cast<size_t>( row ) * aRemap.m_OldCols
624 + std::min( col, aRemap.m_OldCols - 1 )];
625 PCB_TABLECELL*& cell = aRemap.m_Cells[idx];
626
627 // Moved rather than given new corners, since a rotated cell can be a polygon
628 if( aRemap.m_Origin[idx] == CELL_ORIGIN::MOVED )
629 {
630 cell->Move( slot.m_Position - cell->GetPosition() );
631 continue;
632 }
633
634 // Styled later, since the rebuild takes a cell that already exists for one it styled
635 if( aRemap.m_Origin[idx] == CELL_ORIGIN::EMPTY )
636 {
637 cell = new PCB_TABLECELL( this );
638 aRemap.m_Origin[idx] = CELL_ORIGIN::CREATED;
639 }
640
641 cell->SetParent( this );
642 cell->SetLayer( GetLayer() );
643 cell->SetTextAngle( slot.m_Angle );
644 cell->SetMirrored( slot.m_Mirrored );
645 cell->SetStart( slot.m_Start );
646 cell->SetEnd( slot.m_End );
647 }
648 }
649}
650
651
652void PCB_GENERATED_TABLE::styleCreatedCells( const std::vector<CELL_ORIGIN>& aOrigin )
653{
654 const int cols = GetColCount();
655
656 for( size_t idx = 0; idx < m_cells.size(); ++idx )
657 {
658 if( aOrigin[idx] != CELL_ORIGIN::CREATED )
659 continue;
660
661 const int row = static_cast<int>( idx ) / cols;
662 const int col = static_cast<int>( idx ) % cols;
663 const PCB_TABLECELL* donor = nullptr;
664
665 for( int dist = 1; dist < cols && !donor; ++dist )
666 {
667 for( int peer : { col - dist, col + dist } )
668 {
669 if( peer >= 0 && peer < cols
670 && aOrigin[static_cast<size_t>( row ) * cols + peer] == CELL_ORIGIN::MOVED )
671 {
672 donor = GetCell( row, peer );
673 break;
674 }
675 }
676 }
677
678 if( donor )
679 copyCellStyle( m_cells[idx], donor );
680 else
681 styleNewCell( m_cells[idx], row == 0 );
682 }
683}
684
685
686void PCB_GENERATED_TABLE::migrateRows( int aRows, int aCols, const std::vector<std::string>& aNewRowKeys )
687{
688 const int oldCols = GetColCount();
689
690 if( oldCols <= 0 || aCols <= 0 || m_cells.empty() )
691 return;
692
693 const int oldRows = static_cast<int>( m_cells.size() ) / oldCols;
694 const int firstDataRow = 1;
695
696 std::map<std::string, int> oldRowByKey;
697 int oldFirstData = oldRows;
698 int oldLastData = -1;
699
700 // A legacy table's data rows have no identity beyond their position. Its trailers still go by
701 // role, or a data row appearing would take over the totals
702 const bool positionalData = m_rowKeys.empty();
703
704 if( positionalData )
705 {
706 oldFirstData = firstDataRow;
707 oldLastData = firstDataRow - 1;
708
709 for( int row = firstDataRow; row < oldRows; ++row )
710 {
711 if( IsDataRow( row ) )
712 oldLastData = row;
713 }
714 }
715 else
716 {
717 for( const auto& [oldRow, key] : m_rowKeys )
718 {
719 if( oldRow < 0 || oldRow >= oldRows )
720 continue;
721
722 oldRowByKey[key] = oldRow;
723 oldFirstData = std::min( oldFirstData, oldRow );
724 oldLastData = std::max( oldLastData, oldRow );
725 }
726
727 if( oldRowByKey.empty() )
728 return;
729 }
730
731 int newDataCount = 0;
732
733 for( const std::string& key : aNewRowKeys )
734 {
735 if( !key.empty() )
736 newDataCount++;
737 }
738
739 std::vector<int> sourceRow( aRows, -1 );
740
741 // The title and heading are matched from the end of their run, so the heading stays the
742 // heading when a title is added or removed
743 for( int ii = 0; ii < firstDataRow; ++ii )
744 {
745 const int oldIdx = oldFirstData - ( firstDataRow - ii );
746
747 if( oldIdx >= 0 )
748 sourceRow[ii] = oldIdx;
749 }
750
751 if( positionalData )
752 {
753 const int count = std::min( newDataCount, oldLastData - oldFirstData + 1 );
754
755 for( int ii = 0; ii < count; ++ii )
756 sourceRow[firstDataRow + ii] = oldFirstData + ii;
757 }
758 else
759 {
760 for( int ii = firstDataRow; ii < aRows; ++ii )
761 {
762 if( aNewRowKeys[ii].empty() )
763 continue;
764
765 const auto it = oldRowByKey.find( aNewRowKeys[ii] );
766
767 if( it != oldRowByKey.end() )
768 sourceRow[ii] = it->second;
769 }
770 }
771
772 const int trailingNewStart = firstDataRow + newDataCount;
773
774 for( int ii = trailingNewStart; ii < aRows; ++ii )
775 {
776 const int oldIdx = oldLastData + 1 + ( ii - trailingNewStart );
777
778 if( oldIdx < oldRows )
779 sourceRow[ii] = oldIdx;
780 }
781
782 std::vector<PCB_TABLECELL*> newCells( static_cast<size_t>( aRows ) * aCols, nullptr );
783 std::vector<bool> carried( m_cells.size(), false );
784 std::map<int, int> newRowHeights;
785
786 for( int ii = 0; ii < aRows; ++ii )
787 {
788 if( sourceRow[ii] < 0 )
789 continue;
790
791 // A column added since the last rebuild has no cell to carry, and one taken away
792 // leaves its cells behind to be deleted with the rest of the uncarried ones
793 for( int col = 0; col < std::min( oldCols, aCols ); ++col )
794 {
795 const size_t from = static_cast<size_t>( sourceRow[ii] ) * oldCols + col;
796
797 newCells[static_cast<size_t>( ii ) * aCols + col] = m_cells[from];
798 carried[from] = true;
799 }
800
801 const auto heightIt = m_rowHeights.find( sourceRow[ii] );
802
803 if( heightIt != m_rowHeights.end() )
804 newRowHeights[ii] = heightIt->second;
805 }
806
807 for( size_t ii = 0; ii < m_cells.size(); ++ii )
808 {
809 if( !carried[ii] )
810 delete m_cells[ii];
811 }
812
813 for( PCB_TABLECELL*& cell : newCells )
814 {
815 if( !cell )
816 {
817 cell = new PCB_TABLECELL( this );
818 cell->SetLayer( GetLayer() );
819 }
820 }
821
822 m_cells = std::move( newCells );
823 m_rowHeights = std::move( newRowHeights );
824}
825
826
827void PCB_GENERATED_TABLE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
828{
829 PCB_TABLE::Flip( aCentre, aFlipDirection );
830
831 // Otherwise the next rebuild lays the columns back out in their old order
832 std::reverse( m_columns.begin(), m_columns.end() );
834
835 // A hidden column keeps its place in the reversed order too
836 const int total = static_cast<int>( m_columns.size() + m_hidden.size() );
837
838 for( HIDDEN_COLUMN& hidden : m_hidden )
839 hidden.m_Position = total - 1 - hidden.m_Position;
840
841 std::reverse( m_hidden.begin(), m_hidden.end() );
842
843 // Trailer rows are laid out by position rather than by column, so their text goes back to
844 // where a rebuild puts it. The cells stay where the flip left them
845 const int cols = GetColCount();
846
847 for( int row = 1; row < GetRowCount(); ++row )
848 {
849 if( IsDataRow( row ) )
850 continue;
851
852 for( int col = 0; col < cols / 2; ++col )
853 {
854 PCB_TABLECELL* left = GetCell( row, col );
855 PCB_TABLECELL* right = GetCell( row, cols - 1 - col );
856 const wxString text = left->GetText();
857
858 left->SetText( right->GetText() );
859 right->SetText( text );
860 }
861 }
862}
863
864
866 const std::vector<KICAD_T>& aScanTypes )
867{
868 // A generated table answers to its own type and to PCB_TABLE_T, so reporting per matching
869 // type would hand it to the inspector twice and list it twice in the disambiguation menu
870 bool wantTable = false;
871 bool wantCells = false;
872
873 for( KICAD_T scanType : aScanTypes )
874 {
875 if( scanType == Type() || scanType == PCB_TABLE_T )
876 wantTable = true;
877 else if( scanType == PCB_TABLECELL_T )
878 wantCells = true;
879 }
880
881 if( wantTable && INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
883
884 if( wantCells )
885 {
886 for( PCB_TABLECELL* cell : GetCells() )
887 {
888 if( INSPECT_RESULT::QUIT == aInspector( cell, aTestData ) )
890 }
891 }
892
894}
895
896
897void PCB_GENERATED_TABLE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
898{
899 aList.emplace_back( GetFriendlyName(), wxEmptyString );
900 aList.emplace_back( _( "Rows" ), wxString::Format( wxT( "%d" ), GetRowCount() ) );
901 aList.emplace_back( _( "Layer" ), GetLayerName() );
902}
903
904
905bool PCB_GENERATED_TABLE::IsStale( const BOARD& aBoard ) const
906{
907 const std::unique_ptr<GENERATED_TABLE_CONTENT> content = generate( aBoard, nullptr );
908
909 const int cols = static_cast<int>( m_columns.size() );
910 const int dataRows = static_cast<int>( content->m_Rows.size() );
911 const int rows = 1 + dataRows + static_cast<int>( content->m_Trailer.size() );
912
913 if( GetColCount() != cols || GetRowCount() != rows )
914 return true;
915
916 const auto differs =
917 [&]( int aRow, int aCol, const wxString& aText )
918 {
919 const PCB_TABLECELL* cell = GetCell( aRow, aCol );
920
921 return !cell || cell->GetText() != aText;
922 };
923
924 for( int col = 0; col < cols; ++col )
925 {
926 if( differs( 0, col, m_columns[col].m_Heading ) )
927 return true;
928 }
929
930 for( int ii = 0; ii < dataRows; ++ii )
931 {
932 const GENERATED_TABLE_ROW& row = content->m_Rows[ii];
933 const auto keyIt = m_rowKeys.find( 1 + ii );
934
935 if( keyIt == m_rowKeys.end() || keyIt->second != row.m_Key )
936 return true;
937
938 for( int col = 0; col < cols; ++col )
939 {
940 if( differs( 1 + ii, col, textAt( row.m_Cells, col ) ) )
941 return true;
942 }
943 }
944
945 for( size_t ii = 0; ii < content->m_Trailer.size(); ++ii )
946 {
947 for( int col = 0; col < cols; ++col )
948 {
949 if( differs( 1 + dataRows + static_cast<int>( ii ), col, textAt( content->m_Trailer[ii], col ) ) )
950 return true;
951 }
952 }
953
954 return false;
955}
956
957
959{
960 std::unique_ptr<GENERATED_TABLE_CONTENT> content = generate( aBoard, aRefresh );
961
962 const int cols = static_cast<int>( m_columns.size() );
963 const int dataRows = static_cast<int>( content->m_Rows.size() );
964
965 // The headings are the header row. A table carries no caption of its own
966 const int rows = 1 + dataRows + static_cast<int>( content->m_Trailer.size() );
967
968 // A new cell carries a half-INT_MAX rectangle and Normalize() anchors on cell 0's centre,
969 // so without holding the old position a rebuild lands the table half a metre off-board
970 const VECTOR2I anchor = GetCells().empty() ? VECTOR2I( 0, 0 ) : GetPosition();
971
972 std::vector<std::string> newRowKeys( rows );
973
974 // What a row reports, so a rebuild hands its formatting to the row still reporting the
975 // same thing rather than to whatever lands on its index
976 for( int ii = 0; ii < dataRows; ++ii )
977 newRowKeys[1 + ii] = content->m_Rows[ii].m_Key;
978
979 // By UUID, not pointer. A cell migrateRows deletes can hand its address to a new one
980 std::set<KIID> existing;
981
982 for( PCB_TABLECELL* cell : GetCells() )
983 existing.insert( cell->m_Uuid );
984
985 migrateRows( rows, cols, newRowKeys );
986
988
989 SetColCount( cols );
990 ResizeCells( rows, cols );
991
992 m_rowKeys.clear();
993
994 for( int ii = 0; ii < rows; ++ii )
995 {
996 if( !newRowKeys[ii].empty() )
997 m_rowKeys[ii] = newRowKeys[ii];
998 }
999
1000 const auto setCell =
1001 [&]( int aRow, int aCol, const wxString& aText )
1002 {
1003 PCB_TABLECELL* cell = GetCell( aRow, aCol );
1004
1005 if( !cell )
1006 return;
1007
1008 if( !existing.count( cell->m_Uuid ) )
1009 styleFromColumn( cell, aRow, aCol, existing );
1010
1011 cell->SetText( aText );
1012
1013 // The column's alignment, which was otherwise editable, serialized and
1014 // ignored
1015 cell->SetHorizJustify( toHorizJustify( m_columns[aCol].m_Align ) );
1016 };
1017
1018 for( int col = 0; col < cols; ++col )
1019 setCell( 0, col, m_columns[col].m_Heading );
1020
1021 for( int ii = 0; ii < dataRows; ++ii )
1022 {
1023 for( int col = 0; col < cols; ++col )
1024 setCell( 1 + ii, col, textAt( content->m_Rows[ii].m_Cells, col ) );
1025 }
1026
1027 for( size_t ii = 0; ii < content->m_Trailer.size(); ++ii )
1028 {
1029 for( int col = 0; col < cols; ++col )
1030 setCell( 1 + dataRows + static_cast<int>( ii ), col, textAt( content->m_Trailer[ii], col ) );
1031 }
1032
1033 // Autosize measures text as wrapped to its cell, so a reused cell narrower than its new text
1034 // would keep the wrap. Widen those to their resolved, unwrapped text, which Autosize then tightens
1035 bool prewidened = false;
1036
1037 for( int col = 0; col < cols; ++col )
1038 {
1039 int width = 0;
1040
1041 for( int row = 0; row < rows; ++row )
1042 {
1043 const PCB_TABLECELL* cell = GetCell( row, col );
1044
1045 if( !cell )
1046 continue;
1047
1048 const int penWidth = cell->GetEffectiveTextPenWidth();
1049 const VECTOR2I extents = cell->GetDrawFont( nullptr )->StringBoundaryLimits(
1050 cell->GetUnwrappedShownText( FOR_CANVAS ), cell->GetTextSize(), penWidth, cell->IsBold(),
1051 cell->IsItalic(), cell->GetFontMetrics() );
1052
1053 // GetShownText breaks at the width less margins, and LinebreakText takes the pen off too
1054 width = std::max( width, extents.x + penWidth + 2 * ( cell->GetMarginLeft() + cell->GetMarginRight() ) );
1055 }
1056
1057 if( width > GetColWidth( col ) )
1058 {
1059 SetColWidth( col, width );
1060 prewidened = true;
1061 }
1062 }
1063
1064 if( prewidened )
1065 Normalize();
1066
1067 Autosize();
1068
1069 // After autosizing or the authored width never shows, and as a minimum so a width
1070 // saved against a narrower board cannot clip its text
1071 bool widened = false;
1072
1073 for( int col = 0; col < cols; ++col )
1074 {
1075 if( m_columns[col].m_Width > GetColWidth( col ) )
1076 {
1077 SetColWidth( col, m_columns[col].m_Width );
1078 widened = true;
1079 }
1080 }
1081
1082 // The widths above are only a map until the cells are placed against them
1083 if( widened )
1084 Normalize();
1085
1086 Move( anchor - GetPosition() );
1087
1088 // Last, so a table is only ever marked fresh once its layout is complete
1089 onRebuilt( aBoard, *content );
1090}
1091
1092
1094{
1096 {
1098
1099 if( unitsEnum.Choices().GetCount() == 0 )
1100 {
1101 unitsEnum.Map( GENERATED_TABLE_UNITS::MM, _HKI( "Millimeters" ) )
1102 .Map( GENERATED_TABLE_UNITS::MILS, _HKI( "Mils" ) )
1103 .Map( GENERATED_TABLE_UNITS::INCH, _HKI( "Inches" ) );
1104 }
1105
1108
1113
1114 const wxString generatorProps = _( "Table Generator" );
1115
1118 generatorProps );
1119
1120 propMgr.AddProperty( new PROPERTY<PCB_GENERATED_TABLE, int>( _HKI( "Decimal Places" ),
1123 generatorProps );
1124
1125 // Scoped here rather than removed from PCB_TABLE so colors saved on plain tables stay editable
1126 propMgr.Mask( TYPE_HASH( PCB_GENERATED_TABLE ), TYPE_HASH( PCB_TABLE ), _HKI( "Border Color" ) );
1127 propMgr.Mask( TYPE_HASH( PCB_GENERATED_TABLE ), TYPE_HASH( PCB_TABLE ), _HKI( "Separators Color" ) );
1128 propMgr.Mask( TYPE_HASH( PCB_GENERATED_TABLE ), TYPE_HASH( PCB_TABLE ), _HKI( "Cell Separators" ) );
1129
1130 // Registered again below so it sits beside Column Separators
1131 propMgr.Mask( TYPE_HASH( PCB_GENERATED_TABLE ), TYPE_HASH( PCB_TABLE ), _HKI( "Row Separators" ) );
1132
1133 auto differs =
1134 []( bool ( PCB_GENERATED_TABLE::*aTest )() const )
1135 {
1136 return [aTest]( INSPECTABLE* aItem ) -> bool
1137 {
1138 PCB_GENERATED_TABLE* table = dynamic_cast<PCB_GENERATED_TABLE*>( aItem );
1139 return table && ( table->*aTest )();
1140 };
1141 };
1142
1143 const wxString tableProps = _( "Table Properties" );
1144
1146 _HKI( "Row Separators" ), &PCB_TABLE::SetStrokeRows, &PCB_TABLE::StrokeRows ),
1147 tableProps )
1148 .SetIsCopyable();
1149
1150 propMgr.AddProperty( new PROPERTY<PCB_GENERATED_TABLE, bool, PCB_TABLE>( _HKI( "Column Separators" ),
1153 tableProps )
1154 .SetIsCopyable();
1155
1159 tableProps )
1160 .SetIsCopyable()
1162
1163 const wxString fontProps = _HKI( "Font" );
1164
1165 propMgr.AddProperty( new PROPERTY<PCB_GENERATED_TABLE, wxString>( _HKI( "Font Name" ),
1168 fontProps )
1170 .SetIsCopyable()
1173
1177 fontProps )
1178 .SetIsCopyable()
1180 }
1182
1183
@ ERROR_INSIDE
constexpr int ARC_LOW_DEF
Definition base_units.h:143
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:101
void SwapItemData(BOARD_ITEM *aImage)
Swap data between aItem and aImage.
void SetLocked(bool aLocked) override
Definition board_item.h:441
virtual bool IsKnockout() const
Definition board_item.h:437
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void SetIsKnockout(bool aKnockout)
Definition board_item.h:438
const KIFONT::METRICS & GetFontMetrics() const
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr coord_type GetBottom() const
Definition box2.h:225
The base class for create windows for drawing purpose.
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void SetCustomProperties(const std::map< wxString, wxString > &aProps)
Definition eda_item.h:247
virtual wxString GetFriendlyName() const
Definition eda_item.cpp:575
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition eda_item.cpp:288
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
const std::map< wxString, wxString > & GetCustomProperties() const
Custom user-defined string key/value properties attached to this item.
Definition eda_item.h:242
void SetFontProp(const wxString &aFontName)
bool IsItalic() const
Definition eda_text.h:200
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition eda_text.h:118
void SetAttributes(const EDA_TEXT &aSrc, bool aSetPosition=true)
Set the text attributes from another instance.
Definition eda_text.cpp:395
void SetMirrored(bool isMirrored)
Definition eda_text.cpp:355
wxString GetFontProp() const
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:425
virtual KIFONT::FONT * GetDrawFont(const RENDER_SETTINGS *aSettings) const
Definition eda_text.cpp:648
int GetEffectiveTextPenWidth(int aDefaultPenWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultPenWidth.
Definition eda_text.cpp:428
bool IsBold() const
Definition eda_text.h:215
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
int GetInterline(const RENDER_SETTINGS *aSettings) const
Return the distance between two lines of text.
Definition eda_text.cpp:748
virtual void SetText(const wxString &aText)
Definition eda_text.cpp:237
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:371
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:817
static ENUM_MAP< T > & Instance()
Definition property.h:811
wxPGChoices & Choices()
Definition property.h:862
One pass of rebuilding tables.
Class that other classes need to inherit from, in order to be inspectable.
Definition inspectable.h:39
VECTOR2I StringBoundaryLimits(const wxString &aText, const VECTOR2I &aSize, int aThickness, bool aBold, bool aItalic, const METRICS &aFontMetrics) const
Compute the boundary limits of aText (the bounding box of all shapes).
Definition font.cpp:442
A table whose cell text is derived from the board and rebuilt whenever it goes stale.
void styleCreatedCells(const std::vector< CELL_ORIGIN > &aOrigin)
Style cells placeCells created from another cell in their row.
void SetFontNameProp(const wxString &aFontName)
void forEachCell(const std::function< void(PCB_TABLECELL *)> &aFunc)
Visit every shown cell.
int GetRowHeightProp() const
The first data row's height, with RowHeightsDiffer saying whether it speaks for every data row.
std::vector< HIDDEN_COLUMN > m_hidden
By position.
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
void migrateRows(int aRows, int aCols, const std::vector< std::string > &aNewRowKeys)
Move each row's cells to the row that reports the same thing.
void SetFontSizeProp(int aSize)
void placeCells(COLUMN_REMAP &aRemap)
Put every cell in the geometry its slot had, so the table stays where it was, creating those nothing ...
std::vector< GENERATED_TABLE_COLUMN > m_columns
const PCB_TABLECELL * nearestDataCell(int aRow, int aCol, const std::set< KIID > &aStyled) const
The nearest data cell in aCol among aStyled, or null when the column has none.
virtual void ApplySettings(const PCB_GENERATED_TABLE &aOther)
Take aOther's settings and placement but keep this table's cells, so formatting applied to them survi...
void setAutosizedRowHeights(const std::vector< int > &aNeeded) override
Row heights are the user's, carried by key through migrateRows.
std::vector< GENERATED_TABLE_COLUMN > AllColumns() const
Every column the table has been given, in order, with hidden ones marked by m_Visible.
virtual void onRebuilt(const BOARD &aBoard, const GENERATED_TABLE_CONTENT &aContent)
Called once the cells are laid out, with the content they were built from.
int metricRowHeight(int aRow) const
The height aRow needs by its cells' line count, line spacing, pen width and margins.
GENERATED_TABLE_UNITS m_units
const PCB_TABLECELL * firstCell() const
The first cell forEachCell visits, which the font getters speak for, or null.
void RestoreColumns(const std::vector< GENERATED_TABLE_COLUMN > &aColumns)
Replace the columns without touching any cell, for a loader whose cells already match the visible one...
void CopyFrom(const BOARD_ITEM *aOther) override
Copy everything a table of this kind holds, including what a subclass adds.
void RebuildCells(const BOARD &aBoard, GENERATED_TABLE_REFRESH *aRefresh=nullptr)
Regenerate the cells from the board.
void styleFromColumn(PCB_TABLECELL *aCell, int aRow, int aCol, const std::set< KIID > &aStyled)
Give a new cell the text formatting of the nearest data cell in its column among aStyled,...
virtual std::unique_ptr< GENERATED_TABLE_CONTENT > generate(const BOARD &aBoard, GENERATED_TABLE_REFRESH *aRefresh) const =0
The rows this table reports.
void moveShownCells(const std::vector< GENERATED_TABLE_COLUMN > &aShown, COLUMN_REMAP &aRemap) const
Carry each shown column's cells and width to its new position.
virtual bool IsDataRow(int aRow) const
True for a row that reports on the board, false for the heading and trailer rows.
virtual bool IsStale(const BOARD &aBoard) const
True when the cells no longer say what the board says.
std::vector< int > dataRows() const
The rows below the heading that IsDataRow accepts, in order.
void SetPrecision(int aPrecision)
Clamped.
virtual void onColumnsReversed()
Called once the columns have been reversed, for any column index a subclass keeps.
virtual void styleNewCell(PCB_TABLECELL *aCell, bool aIsHeading)
Called for each cell a rebuild creates, before its text is set.
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
bool generatedEquals(const PCB_GENERATED_TABLE &aOther) const
Equality of the members this class owns and of the underlying PCB_TABLE.
void swapData(BOARD_ITEM *aImage) override
wxString GetFontNameProp() const
The first cell's font, with FontNamesDiffer saying whether it speaks for every shown cell.
void SetRowHeightProp(int aHeight)
void SetColumns(std::vector< GENERATED_TABLE_COLUMN > aColumns)
Replace the columns of a built table, moving each column's cells to where its id now sits so their fo...
INSPECT_RESULT Visit(INSPECTOR aInspector, void *aTestData, const std::vector< KICAD_T > &aScanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
PCB_GENERATED_TABLE(BOARD_ITEM *aParent, KICAD_T aType, int aLineWidth)
void SetRowHeightToFit(int aRow, int aHeight)
Set one row's height, no shorter than its text.
GENERATED_TABLE_UNITS GetUnits() const
@ MOVED
A shown column's cell, carried to its new column.
@ CREATED
New, including a cell in a column shown again.
@ EMPTY
Nothing filled the slot yet.
bool anyCell(const std::function< bool(const PCB_TABLECELL *)> &aTest) const
True when aTest holds for any cell forEachCell would visit, stopping at the first.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
PCB_TABLE::Flip reverses the columns in either direction, as it does for a plain table's text,...
virtual void onRowsMigrated()
Called once a rebuild has moved the rows to where the new content puts them, before anything asks whi...
int GetFontSizeProp() const
The first cell's text height, with FontSizesDiffer saying whether every shown cell has that size,...
void SetUnits(GENERATED_TABLE_UNITS aUnits)
int minRowHeight(int aRow) const
The smallest height aRow may take with its text still inside it.
std::map< int, std::string > m_rowKeys
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
VECTOR2I GetPosition() const override
Definition pcb_shape.h:78
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
void SetFontSize(int aSize)
bool HasSquareFontSize() const
wxString GetUnwrappedShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const
GetShownText() before it is line-broken to the cell's width, i.e.
int GetFontSize() const
The text height, which speaks for the width too only when HasSquareFontSize.
static wxPGChoices FontChoices(INSPECTABLE *aItem)
The font names EDA_TEXT's Font property offers, for the Font Name a generated table and its cells off...
bool StrokeRows() const
Definition pcb_table.h:110
int GetRowCount() const
Definition pcb_table.h:128
std::vector< PCB_TABLECELL * > m_cells
Definition pcb_table.h:348
void SetColWidth(int aCol, int aWidth)
Definition pcb_table.h:135
void Move(const VECTOR2I &aMoveVector) override
Move this object.
bool StrokeHeaderSeparator() const
Definition pcb_table.h:68
bool StrokeColumns() const
Definition pcb_table.h:107
void SetStrokeHeaderSeparator(bool aDoStroke)
Definition pcb_table.h:67
void ResizeCells(int aRows, int aCols)
Grow or shrink to aRows x aCols, keeping the cells that already exist.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
bool StrokeExternal() const
Definition pcb_table.h:65
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStrokeExternal(bool aDoStroke)
Definition pcb_table.h:64
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition pcb_table.h:155
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:165
void Autosize()
bool operator==(const PCB_TABLE &aOther) const
int GetColCount() const
Definition pcb_table.h:126
void SetStrokeColumns(bool aDoStroke)
Definition pcb_table.h:106
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition pcb_table.h:89
std::map< int, int > m_colWidths
Definition pcb_table.h:346
virtual void swapData(BOARD_ITEM *aImage) override
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
const STROKE_PARAMS & GetBorderStroke() const
Definition pcb_table.h:71
void SetStrokeRows(bool aDoStroke)
Definition pcb_table.h:109
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void SetColCount(int aCount)
Definition pcb_table.h:125
int GetColWidth(int aCol) const
Definition pcb_table.h:137
VECTOR2I GetPosition() const override
PCB_TABLE(BOARD_ITEM *aParent, int aLineWidth)
Definition pcb_table.cpp:57
void SetSeparatorsStroke(const STROKE_PARAMS &aParams)
Definition pcb_table.h:88
void SetRowHeight(int aRow, int aHeight)
Definition pcb_table.h:145
void SetBorderStroke(const STROKE_PARAMS &aParams)
Definition pcb_table.h:70
int GetRowHeight(int aRow) const
Definition pcb_table.h:147
std::map< int, int > m_rowHeights
Definition pcb_table.h:347
int GetMarginBottom() const
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Convert the text to a polygonSet describing the actual character strokes (one per segment).
VECTOR2I GetTextSize() const override
VECTOR2I GetDrawPos() const override
void SetMarginTop(int aTop)
int GetMarginLeft() const
void SetMarginLeft(int aLeft)
void SetMarginBottom(int aBottom)
int GetMarginRight() const
int GetMarginTop() const
void SetTextAngle(const EDA_ANGLE &aAngle) override
void SetMarginRight(int aRight)
void Move(const VECTOR2I &aMoveVector) override
Move this object.
PROPERTY_BASE & SetChoicesFunc(std::function< wxPGChoices(INSPECTABLE *)> aFunc)
Definition property.h:289
PROPERTY_BASE & SetIndeterminateFunc(std::function< bool(INSPECTABLE *)> aFunc)
Set a callback function to determine whether an object's value for this property is mixed.
Definition property.h:322
PROPERTY_BASE & SetIsCopyable(bool aIsCopyable=true)
Definition property.h:388
PROPERTY_BASE & SetIsHiddenFromRulesEditor(bool aHide=true)
Definition property.h:361
Provide class metadata.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
void Mask(TYPE_ID aDerived, TYPE_ID aBase, const wxString &aName)
Sets a base class property as masked in a derived class.
static PROPERTY_MANAGER & Instance()
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
void AddTypeCast(TYPE_CAST_BASE *aCast)
Register a type converter.
Represent a set of closed polygons.
void Rotate(const EDA_ANGLE &aAngle, const VECTOR2I &aCenter={ 0, 0 }) override
Rotate all vertices by a given angle.
bool IsEmpty() const
Return true if the set is empty (no polygons at all)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
@ FOR_CANVAS
Definition common.h:92
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
INSPECT_RESULT
Definition eda_item.h:44
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:91
GENERATED_TABLE_UNITS
GENERATED_TABLE_ALIGN
Some functions to handle hotkeys in KiCad.
std::string source
FLIP_DIRECTION
Definition mirror.h:26
Message panel definition file.
#define _HKI(x)
Definition page_info.cpp:40
static struct PCB_GENERATED_TABLE_DESC _PCB_GENERATED_TABLE_DESC
#define TYPE_HASH(x)
Macro to generate unique identifier for a type.
Definition property.h:74
#define ENUM_TO_WXANY(type)
Definition property.h:918
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
Helper macro to map type hashes to names.
A column as a generated table actually carries it: what a row's cell in that column holds and how it ...
One data row of a generated table, and the identity its formatting follows across rebuilds.
std::vector< wxString > m_Cells
SetColumns' work in progress, laying the old cells out for the new columns.
std::vector< bool > m_Carried
Old cells that went somewhere, by old index.
std::vector< CELL_ORIGIN > m_Origin
Where each of m_Cells came from.
std::map< int, int > m_ColWidths
By new column.
std::vector< PCB_TABLECELL * > m_Cells
The new layout, row by row.
A hidden column and its place among all columns.
const std::string table
std::vector< DATABASE_CONNECTION::ROW > rows
static const long long MM
GR_TEXT_H_ALIGN_T
This is API surface mapped to common.types.HorizontalAlignment.
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ GR_TEXT_V_ALIGN_BOTTOM
@ GR_TEXT_V_ALIGN_TOP
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
constexpr bool IsGeneratedTableType(const KICAD_T aType)
A PCB_TABLE subclass whose cells are generated from the board rather than typed by the user.
Definition typeinfo.h:328
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708