KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <pcb_edit_frame.h>
25#include <footprint.h>
26#include <pcb_table.h>
27#include <board.h>
33#include <pcb_painter.h> // for PCB_RENDER_SETTINGS
34#include <properties/property.h>
36
37
38PCB_TABLE::PCB_TABLE( BOARD_ITEM* aParent, int aLineWidth ) :
40 m_strokeExternal( true ),
43 m_strokeRows( true ),
44 m_strokeColumns( true ),
46 m_colCount( 0 )
47{
48}
49
50
68
69
71{
72 // We own our cells; delete them
73 for( PCB_TABLECELL* cell : m_cells )
74 delete cell;
75}
76
77
79{
80 wxCHECK_RET( aImage != nullptr && aImage->Type() == PCB_TABLE_T, wxT( "Cannot swap data with invalid table." ) );
81
82 PCB_TABLE* table = static_cast<PCB_TABLE*>( aImage );
83
84 std::swap( m_layer, table->m_layer );
85 std::swap( m_isLocked, table->m_isLocked );
86
87 std::swap( m_strokeExternal, table->m_strokeExternal );
88 std::swap( m_StrokeHeaderSeparator, table->m_StrokeHeaderSeparator );
89 std::swap( m_borderStroke, table->m_borderStroke );
90 std::swap( m_strokeRows, table->m_strokeRows );
91 std::swap( m_strokeColumns, table->m_strokeColumns );
92 std::swap( m_separatorsStroke, table->m_separatorsStroke );
93
94 std::swap( m_colCount, table->m_colCount );
95 std::swap( m_colWidths, table->m_colWidths );
96 std::swap( m_rowHeights, table->m_rowHeights );
97
98 std::swap( m_cells, table->m_cells );
99
100 for( PCB_TABLECELL* cell : m_cells )
101 cell->SetParent( this );
102
103 for( PCB_TABLECELL* cell : table->m_cells )
104 cell->SetParent( table );
105}
106
107
109{
110 Move( aPos - GetPosition() );
111}
112
113
115{
116 if( m_cells.empty() )
117 return VECTOR2I( 0, 0 ); // Return origin if table has no cells
118
119 return m_cells[0]->GetPosition();
120}
121
122
124{
125 VECTOR2I tableSize;
126
127 for( int ii = 0; ii < GetColCount(); ++ii )
128 tableSize.x += GetColWidth( ii );
129
130 for( int ii = 0; ii < GetRowCount(); ++ii )
131 tableSize.y += GetRowHeight( ii );
132
133 return GetPosition() + tableSize;
134}
135
136
138{
139 if( m_cells.empty() )
140 return;
141
142 EDA_ANGLE cellAngle = m_cells[0]->GetTextAngle();
143
144 BOX2I cell0BBox = m_cells[0]->GetBoundingBox();
145 VECTOR2I stableCenter = cell0BBox.GetCenter();
146
147 int cell0Width = m_colWidths[0];
148 int cell0Height = m_rowHeights[0];
149
150 if( m_cells[0]->GetColSpan() > 1 )
151 {
152 for( int ii = 1; ii < m_cells[0]->GetColSpan(); ++ii )
153 cell0Width += m_colWidths[ii];
154 }
155
156 if( m_cells[0]->GetRowSpan() > 1 )
157 {
158 for( int ii = 1; ii < m_cells[0]->GetRowSpan(); ++ii )
159 cell0Height += m_rowHeights[ii];
160 }
161
162 VECTOR2I localCell0Center( cell0Width / 2, cell0Height / 2 );
163 RotatePoint( localCell0Center, cellAngle );
164
165 if( cellAngle != ANGLE_0 )
166 {
167 for( PCB_TABLECELL* cell : m_cells )
168 cell->Rotate( stableCenter, -cellAngle );
169 }
170
171 VECTOR2I unrotatedOrigin = stableCenter - VECTOR2I( cell0Width / 2, cell0Height / 2 );
172
173 int y = unrotatedOrigin.y;
174
175 for( int row = 0; row < GetRowCount(); ++row )
176 {
177 int x = unrotatedOrigin.x;
178 int rowHeight = m_rowHeights[row];
179
180 for( int col = 0; col < GetColCount(); ++col )
181 {
182 int colWidth = m_colWidths[col];
183
184 PCB_TABLECELL* cell = GetCell( row, col );
185
186 if( !cell )
187 continue;
188
189 int cellWidth = colWidth;
190 int cellHeight = rowHeight;
191
192 if( cell->GetColSpan() > 1 || cell->GetRowSpan() > 1 )
193 {
194 for( int ii = col + 1; ii < col + cell->GetColSpan(); ++ii )
195 cellWidth += m_colWidths[ii];
196
197 for( int ii = row + 1; ii < row + cell->GetRowSpan(); ++ii )
198 cellHeight += m_rowHeights[ii];
199 }
200
201 VECTOR2I pos( x, y );
202 VECTOR2I end( x + cellWidth, y + cellHeight );
203
204 if( cell->GetPosition() != pos )
205 {
206 cell->SetPosition( pos );
207 cell->ClearRenderCache();
208 }
209
210 if( cell->GetEnd() != end )
211 {
212 cell->SetEnd( end );
213 cell->ClearRenderCache();
214 }
215
216 x += colWidth;
217 }
218
219 y += rowHeight;
220 }
221
222 if( cellAngle != ANGLE_0 )
223 {
224 for( PCB_TABLECELL* cell : m_cells )
225 cell->Rotate( stableCenter, cellAngle );
226 }
227
228 BOX2I newCell0BBox = m_cells[0]->GetBoundingBox();
229 VECTOR2I newCenter = newCell0BBox.GetCenter();
230
231 if( newCenter != stableCenter )
232 {
233 VECTOR2I correction = stableCenter - newCenter;
234
235 for( PCB_TABLECELL* cell : m_cells )
236 cell->Move( correction );
237 }
238}
239
240
242{
243 std::vector<std::vector<BOX2I>> extents;
244
245 for( int row = 0; row < GetRowCount(); ++row )
246 {
247 extents.push_back( std::vector<BOX2I>() );
248
249 for( int col = 0; col < GetColCount(); ++col )
250 {
251 SHAPE_POLY_SET textPoly;
252 GetCell( row, col )->TransformTextToPolySet( textPoly, 0, ARC_LOW_DEF, ERROR_INSIDE );
253 extents[row].push_back( textPoly.BBox() );
254 }
255 }
256
257 for( int col = 0; col < GetColCount(); ++col )
258 {
259 int colWidth = 0;
260
261 for( int row = 0; row < GetRowCount(); ++row )
262 {
263 PCB_TABLECELL* cell = GetCell( row, col );
264 int margins = cell->GetMarginLeft() + cell->GetMarginRight();
265 colWidth = std::max<int>( colWidth, extents[row][col].GetWidth() + ( margins * 1.5 ) );
266 }
267
268 SetColWidth( col, colWidth );
269 }
270
271 for( int row = 0; row < GetRowCount(); ++row )
272 {
273 int rowHeight = 0;
274
275 for( int col = 0; col < GetColCount(); ++col )
276 {
277 PCB_TABLECELL* cell = GetCell( row, col );
278 int margins = cell->GetMarginLeft() + cell->GetMarginRight();
279 rowHeight = std::max( rowHeight, (int) extents[row][col].GetHeight() + margins );
280 }
281
282 SetRowHeight( row, rowHeight );
283 }
284
285 Normalize();
286}
287
288
289void PCB_TABLE::Move( const VECTOR2I& aMoveVector )
290{
291 for( PCB_TABLECELL* cell : m_cells )
292 cell->Move( aMoveVector );
293}
294
295
296void PCB_TABLE::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
297{
298 if( GetCells().empty() )
299 return;
300
301 for( PCB_TABLECELL* cell : m_cells )
302 cell->Rotate( aRotCentre, aAngle );
303
304 Normalize();
305}
306
307
308void PCB_TABLE::Flip( const VECTOR2I& aCentre, FLIP_DIRECTION aFlipDirection )
309{
310 BOX2I originalBBox = GetBoundingBox();
311
312 VECTOR2I targetPos;
313
314 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
315 {
316 targetPos.x = 2 * aCentre.x - originalBBox.GetRight();
317 targetPos.y = originalBBox.GetTop();
318 }
319 else
320 {
321 targetPos.x = originalBBox.GetLeft();
322 targetPos.y = 2 * aCentre.y - originalBBox.GetBottom();
323 }
324
325 EDA_ANGLE originalAngle = m_cells[0]->GetTextAngle();
326
327 if( originalAngle != ANGLE_0 )
328 Rotate( GetPosition(), -originalAngle );
329
330 VECTOR2I tableOrigin = GetPosition();
331
332 for( PCB_TABLECELL* cell : m_cells )
333 cell->Flip( tableOrigin, aFlipDirection );
334
335 std::vector<PCB_TABLECELL*> oldCells = m_cells;
336
337 if( aFlipDirection == FLIP_DIRECTION::LEFT_RIGHT )
338 {
339 int rowOffset = 0;
340
341 for( int row = 0; row < GetRowCount(); ++row )
342 {
343 for( int col = 0; col < GetColCount(); ++col )
344 m_cells[rowOffset + col] = oldCells[rowOffset + GetColCount() - 1 - col];
345
346 rowOffset += GetColCount();
347 }
348
349 std::map<int, int> newColWidths;
350
351 for( int col = 0; col < GetColCount(); ++col )
352 newColWidths[col] = m_colWidths[GetColCount() - 1 - col];
353
354 m_colWidths = std::move( newColWidths );
355 }
356 else // TOP_BOTTOM
357 {
358 for( int row = 0; row < GetRowCount(); ++row )
359 {
360 for( int col = 0; col < GetColCount(); ++col )
361 {
362 int oldRow = GetRowCount() - 1 - row;
363 m_cells[row * GetColCount() + col] = oldCells[oldRow * GetColCount() + col];
364 }
365 }
366
367 std::map<int, int> newRowHeights;
368
369 for( int row = 0; row < GetRowCount(); ++row )
370 newRowHeights[row] = m_rowHeights[GetRowCount() - 1 - row];
371
372 m_rowHeights = std::move( newRowHeights );
373 }
374
376 Normalize();
377
378 if( originalAngle != ANGLE_0 )
379 Rotate( GetPosition(), originalAngle );
380
381 BOX2I newBBox = GetBoundingBox();
382 Move( targetPos - newBBox.GetPosition() );
383
384 int localWidth = 0;
385 for( int col = 0; col < GetColCount(); ++col )
386 localWidth += m_colWidths[col];
387
388 int localHeight = 0;
389 for( int row = 0; row < GetRowCount(); ++row )
390 localHeight += m_rowHeights[row];
391
392 bool isNowOnFrontSide = IsFrontLayer( GetLayer() );
393
394 VECTOR2I translation( 0, 0 );
395
396 if( aFlipDirection == FLIP_DIRECTION::TOP_BOTTOM )
397 {
398 translation.y = -localHeight;
399 }
400 else // LEFT_RIGHT
401 {
402 if( isNowOnFrontSide )
403 translation.x = localWidth;
404 else
405 translation.x = -localWidth;
406 }
407
408 RotatePoint( translation, originalAngle );
409
410 Move( translation );
411}
412
413
414void PCB_TABLE::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFunction, RECURSE_MODE aMode ) const
415{
416 for( PCB_TABLECELL* cell : m_cells )
417 {
418 aFunction( cell );
419
420 if( aMode == RECURSE_MODE::RECURSE )
421 cell->RunOnChildren( aFunction, aMode );
422 }
423}
424
425
427{
428 // Note: a table with no cells is not allowed
429 BOX2I bbox = m_cells[0]->GetBoundingBox();
430
431 bbox.Merge( m_cells[m_cells.size() - 1]->GetBoundingBox() );
432
433 return bbox;
434}
435
436
437void PCB_TABLE::DrawBorders( const std::function<void( const VECTOR2I& aPt1, const VECTOR2I& aPt2,
438 const STROKE_PARAMS& aStroke )>& aCallback ) const
439{
440 EDA_ANGLE drawAngle = GetCell( 0, 0 )->GetDrawRotation();
441 std::vector<VECTOR2I> topLeft = GetCell( 0, 0 )->GetCornersInSequence( drawAngle );
442 std::vector<VECTOR2I> bottomLeft = GetCell( GetRowCount() - 1, 0 )->GetCornersInSequence( drawAngle );
443 std::vector<VECTOR2I> topRight = GetCell( 0, GetColCount() - 1 )->GetCornersInSequence( drawAngle );
444 std::vector<VECTOR2I> bottomRight =
445 GetCell( GetRowCount() - 1, GetColCount() - 1 )->GetCornersInSequence( drawAngle );
446 STROKE_PARAMS stroke;
447
448 for( int col = 0; col < GetColCount() - 1; ++col )
449 {
450 for( int row = 0; row < GetRowCount(); ++row )
451 {
452 if( row == 0 && StrokeHeaderSeparator() )
453 stroke = GetBorderStroke();
454 else if( StrokeColumns() )
455 stroke = GetSeparatorsStroke();
456 else
457 continue;
458
459 PCB_TABLECELL* cell = GetCell( row, col );
460
461 if( cell->GetColSpan() == 0 )
462 continue;
463
464 if( col + cell->GetColSpan() == GetColCount() )
465 continue;
466
467 std::vector<VECTOR2I> corners = cell->GetCornersInSequence( drawAngle );
468
469 if( corners.size() == 4 )
470 aCallback( corners[1], corners[2], stroke );
471 }
472 }
473
474 for( int row = 0; row < GetRowCount() - 1; ++row )
475 {
476 if( row == 0 && StrokeHeaderSeparator() )
477 stroke = GetBorderStroke();
478 else if( StrokeRows() )
479 stroke = GetSeparatorsStroke();
480 else
481 continue;
482
483 for( int col = 0; col < GetColCount(); ++col )
484 {
485 PCB_TABLECELL* cell = GetCell( row, col );
486
487 if( cell->GetRowSpan() == 0 )
488 continue;
489
490 if( row + cell->GetRowSpan() == GetRowCount() )
491 continue;
492
493 std::vector<VECTOR2I> corners = cell->GetCornersInSequence( drawAngle );
494
495 if( corners.size() == 4 )
496 aCallback( corners[2], corners[3], stroke );
497 }
498 }
499
500 if( StrokeExternal() && GetBorderStroke().GetWidth() >= 0 )
501 {
502 aCallback( topLeft[0], topRight[1], GetBorderStroke() );
503 aCallback( topRight[1], bottomRight[2], GetBorderStroke() );
504 aCallback( bottomRight[2], bottomLeft[3], GetBorderStroke() );
505 aCallback( bottomLeft[3], topLeft[0], GetBorderStroke() );
506 }
507}
508
509
510std::shared_ptr<SHAPE> PCB_TABLE::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
511{
512 EDA_ANGLE angle = GetCell( 0, 0 )->GetDrawRotation();
513 std::vector<VECTOR2I> topLeft = GetCell( 0, 0 )->GetCornersInSequence( angle );
514 std::vector<VECTOR2I> bottomLeft = GetCell( GetRowCount() - 1, 0 )->GetCornersInSequence( angle );
515 std::vector<VECTOR2I> topRight = GetCell( 0, GetColCount() - 1 )->GetCornersInSequence( angle );
516 std::vector<VECTOR2I> bottomRight = GetCell( GetRowCount() - 1, GetColCount() - 1 )->GetCornersInSequence( angle );
517
518 std::shared_ptr<SHAPE_COMPOUND> shape = std::make_shared<SHAPE_COMPOUND>();
519
520 std::vector<VECTOR2I> pts;
521
522 pts.emplace_back( topLeft[3] );
523 pts.emplace_back( topRight[2] );
524 pts.emplace_back( bottomRight[2] );
525 pts.emplace_back( bottomLeft[3] );
526
527 shape->AddShape( new SHAPE_SIMPLE( pts ) );
528
530 [&shape]( const VECTOR2I& ptA, const VECTOR2I& ptB, const STROKE_PARAMS& stroke )
531 {
532 shape->AddShape( new SHAPE_SEGMENT( ptA, ptB, stroke.GetWidth() ) );
533 } );
534
535 return shape;
536}
537
538
539void PCB_TABLE::TransformShapeToPolygon( SHAPE_POLY_SET& aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError,
540 ERROR_LOC aErrorLoc, bool aIgnoreLineWidth ) const
541{
542 int gap = aClearance;
543
544 if( StrokeColumns() || StrokeRows() )
545 gap = std::max( gap, aClearance + GetSeparatorsStroke().GetWidth() / 2 );
546
548 gap = std::max( gap, aClearance + GetBorderStroke().GetWidth() / 2 );
549
550 for( PCB_TABLECELL* cell : m_cells )
551 cell->TransformShapeToPolygon( aBuffer, aLayer, gap, aMaxError, aErrorLoc, false );
552}
553
554
556 KIGFX::RENDER_SETTINGS* aRenderSettings ) const
557{
558 // Convert graphic items (segments and texts) to a set of polygonal shapes
559 // aRenderSettings is used to draw lines when line style != LINE_STYLE::SOLID, so
560 // if nullptr line style will be ignored
562 [&aBuffer, aMaxError, aErrorLoc, aRenderSettings]( const VECTOR2I& ptA, const VECTOR2I& ptB,
563 const STROKE_PARAMS& stroke )
564 {
565 int lineWidth = stroke.GetWidth();
566 LINE_STYLE lineStyle = stroke.GetLineStyle();
567
568 if( lineStyle <= LINE_STYLE::FIRST_TYPE || aRenderSettings == nullptr )
569 TransformOvalToPolygon( aBuffer, ptA, ptB, lineWidth, aMaxError, aErrorLoc );
570 else
571 {
572 SHAPE_SEGMENT seg( ptA, ptB );
573 KIGFX::PCB_RENDER_SETTINGS defaultRenderSettings;
574
575 KIGFX::RENDER_SETTINGS* currSettings = aRenderSettings;
576
577 if( currSettings == nullptr )
578 currSettings = &defaultRenderSettings;
579
580 STROKE_PARAMS::Stroke( &seg, lineStyle, lineWidth, currSettings,
581 [&]( VECTOR2I a, VECTOR2I b )
582 {
583 if( a == b )
584 TransformCircleToPolygon( aBuffer, a, lineWidth / 2, aMaxError, aErrorLoc );
585 else
586 TransformOvalToPolygon( aBuffer, a + 1, b, lineWidth, aMaxError, aErrorLoc );
587 } );
588 }
589 } );
590
591 for( PCB_TABLECELL* cell : m_cells )
592 {
593 cell->TransformTextToPolySet( aBuffer, 0, aMaxError, ERROR_INSIDE );
594 }
595}
596
597
599 int aClearance, int aMaxError, ERROR_LOC aErrorLoc,
600 KIGFX::RENDER_SETTINGS* aRenderSettings ) const
601{
602 if( aClearance <= 0 )
603 TransformGraphicItemsToPolySet( aBuffer, aMaxError, aErrorLoc, aRenderSettings );
604 else
605 {
606 SHAPE_POLY_SET tmp;
607 TransformGraphicItemsToPolySet( tmp, aMaxError, aErrorLoc, aRenderSettings );
608 tmp.Inflate( aClearance, CORNER_STRATEGY::CHAMFER_ALL_CORNERS, aMaxError );
609 aBuffer.Append( tmp );
610 }
611}
612
613
614INSPECT_RESULT PCB_TABLE::Visit( INSPECTOR aInspector, void* aTestData, const std::vector<KICAD_T>& aScanTypes )
615{
616 for( KICAD_T scanType : aScanTypes )
617 {
618 if( scanType == PCB_TABLE_T )
619 {
620 if( INSPECT_RESULT::QUIT == aInspector( this, aTestData ) )
622 }
623
624 if( scanType == PCB_TABLECELL_T )
625 {
626 for( PCB_TABLECELL* cell : m_cells )
627 {
628 if( INSPECT_RESULT::QUIT == aInspector( cell, (void*) this ) )
630 }
631 }
632 }
633
635}
636
637
638wxString PCB_TABLE::GetItemDescription( UNITS_PROVIDER* aUnitsProvider, bool aFull ) const
639{
640 return wxString::Format( _( "%d column table" ), m_colCount );
641}
642
643
645{
646 return BITMAPS::table;
647}
648
649
650bool PCB_TABLE::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
651{
652 BOX2I rect = GetBoundingBox();
653
654 rect.Inflate( aAccuracy );
655
656 return rect.Contains( aPosition );
657}
658
659
660bool PCB_TABLE::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
661{
662 BOX2I rect = aRect;
663
664 rect.Inflate( aAccuracy );
665
666 if( aContained )
667 return rect.Contains( GetBoundingBox() );
668
669 return rect.Intersects( GetBoundingBox() );
670}
671
672
673bool PCB_TABLE::HitTest( const SHAPE_LINE_CHAIN& aPoly, bool aContained ) const
674{
675 return KIGEOM::ShapeHitTest( aPoly, *GetEffectiveShape(), aContained );
676}
677
678
679void PCB_TABLE::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
680{
681 // Don't use GetShownText() here; we want to show the user the variable references
682 aList.emplace_back( _( "Table" ), wxString::Format( _( "%d Columns" ), m_colCount ) );
683}
684
685
686int PCB_TABLE::Compare( const PCB_TABLE* aTable, const PCB_TABLE* aOther )
687{
688 int diff;
689
690 if( ( diff = (int) aTable->GetCells().size() - (int) aOther->GetCells().size() ) != 0 )
691 return diff;
692
693 if( ( diff = aTable->GetColCount() - aOther->GetColCount() ) != 0 )
694 return diff;
695
696 for( int col = 0; col < aTable->GetColCount(); ++col )
697 {
698 if( ( diff = aTable->GetColWidth( col ) - aOther->GetColWidth( col ) ) != 0 )
699 return diff;
700 }
701
702 for( int row = 0; row < aTable->GetRowCount(); ++row )
703 {
704 if( ( diff = aTable->GetRowHeight( row ) - aOther->GetRowHeight( row ) ) != 0 )
705 return diff;
706 }
707
708 for( int row = 0; row < aTable->GetRowCount(); ++row )
709 {
710 for( int col = 0; col < aTable->GetColCount(); ++col )
711 {
712 PCB_TABLECELL* cell = aTable->GetCell( row, col );
713 PCB_TABLECELL* other = aOther->GetCell( row, col );
714
715 if( ( diff = cell->PCB_SHAPE::Compare( other ) ) != 0 )
716 return diff;
717
718 if( ( diff = cell->EDA_TEXT::Compare( other ) ) != 0 )
719 return diff;
720 }
721 }
722
723 return 0;
724}
725
726
727bool PCB_TABLE::operator==( const BOARD_ITEM& aBoardItem ) const
728{
729 if( Type() != aBoardItem.Type() )
730 return false;
731
732 const PCB_TABLE& other = static_cast<const PCB_TABLE&>( aBoardItem );
733
734 return *this == other;
735}
736
737
738bool PCB_TABLE::operator==( const PCB_TABLE& aOther ) const
739{
740 if( m_cells.size() != aOther.m_cells.size() )
741 return false;
742
743 if( m_strokeExternal != aOther.m_strokeExternal )
744 return false;
745
747 return false;
748
749 if( m_borderStroke != aOther.m_borderStroke )
750 return false;
751
752 if( m_strokeRows != aOther.m_strokeRows )
753 return false;
754
755 if( m_strokeColumns != aOther.m_strokeColumns )
756 return false;
757
759 return false;
760
761 if( m_colWidths != aOther.m_colWidths )
762 return false;
763
764 if( m_rowHeights != aOther.m_rowHeights )
765 return false;
766
767 for( int ii = 0; ii < (int) m_cells.size(); ++ii )
768 {
769 if( !( *m_cells[ii] == *aOther.m_cells[ii] ) )
770 return false;
771 }
772
773 return true;
774}
775
776
777double PCB_TABLE::Similarity( const BOARD_ITEM& aOther ) const
778{
779 if( aOther.Type() != Type() )
780 return 0.0;
781
782 const PCB_TABLE& other = static_cast<const PCB_TABLE&>( aOther );
783
784 if( m_cells.size() != other.m_cells.size() )
785 return 0.1;
786
787 double similarity = 1.0;
788
790 similarity *= 0.9;
791
793 similarity *= 0.9;
794
795 if( m_borderStroke != other.m_borderStroke )
796 similarity *= 0.9;
797
798 if( m_strokeRows != other.m_strokeRows )
799 similarity *= 0.9;
800
801 if( m_strokeColumns != other.m_strokeColumns )
802 similarity *= 0.9;
803
805 similarity *= 0.9;
806
807 if( m_colWidths != other.m_colWidths )
808 similarity *= 0.9;
809
810 if( m_rowHeights != other.m_rowHeights )
811 similarity *= 0.9;
812
813 for( int ii = 0; ii < (int) m_cells.size(); ++ii )
814 similarity *= m_cells[ii]->Similarity( *other.m_cells[ii] );
815
816 return similarity;
817}
818
819
820static struct PCB_TABLE_DESC
821{
823 {
825
826 if( lineStyleEnum.Choices().GetCount() == 0 )
827 {
828 lineStyleEnum.Map( LINE_STYLE::SOLID, _HKI( "Solid" ) )
829 .Map( LINE_STYLE::DASH, _HKI( "Dashed" ) )
830 .Map( LINE_STYLE::DOT, _HKI( "Dotted" ) )
831 .Map( LINE_STYLE::DASHDOT, _HKI( "Dash-Dot" ) )
832 .Map( LINE_STYLE::DASHDOTDOT, _HKI( "Dash-Dot-Dot" ) );
833 }
834
837
842
843 propMgr.AddProperty( new PROPERTY<PCB_TABLE, int>( _HKI( "Start X" ),
846 propMgr.AddProperty( new PROPERTY<PCB_TABLE, int>( _HKI( "Start Y" ),
849
850 const wxString tableProps = _( "Table Properties" );
851
852 propMgr.AddProperty( new PROPERTY<PCB_TABLE, bool>( _HKI( "External Border" ),
854 tableProps );
855
856 propMgr.AddProperty( new PROPERTY<PCB_TABLE, bool>( _HKI( "Header Border" ),
858 tableProps );
859
860 propMgr.AddProperty( new PROPERTY<PCB_TABLE, int>( _HKI( "Border Width" ),
863 tableProps );
864
865 propMgr.AddProperty( new PROPERTY_ENUM<PCB_TABLE, LINE_STYLE>( _HKI( "Border Style" ),
867 tableProps );
868
869 propMgr.AddProperty( new PROPERTY<PCB_TABLE, COLOR4D>( _HKI( "Border Color" ),
871 tableProps );
872
873 propMgr.AddProperty( new PROPERTY<PCB_TABLE, bool>( _HKI( "Row Separators" ),
875 tableProps );
876
877 propMgr.AddProperty( new PROPERTY<PCB_TABLE, bool>( _HKI( "Cell Separators" ),
879 tableProps );
880
881 propMgr.AddProperty( new PROPERTY<PCB_TABLE, int>( _HKI( "Separators Width" ),
884 tableProps );
885
886 propMgr.AddProperty( new PROPERTY_ENUM<PCB_TABLE, LINE_STYLE>( _HKI( "Separators Style" ),
888 tableProps );
889
890 propMgr.AddProperty( new PROPERTY<PCB_TABLE, COLOR4D>( _HKI( "Separators Color" ),
892 tableProps );
893 }
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
@ ERROR_INSIDE
constexpr int ARC_LOW_DEF
Definition base_units.h:128
BITMAPS
A list of all bitmap identifiers.
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
Abstract interface for BOARD_ITEMs capable of storing other items inside.
BOARD_ITEM_CONTAINER(BOARD_ITEM *aParent, KICAD_T aType)
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
BOARD_ITEM(BOARD_ITEM *aParent, KICAD_T idtype, PCB_LAYER_ID aLayer=F_Cu)
Definition board_item.h:86
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition board_item.h:237
PCB_LAYER_ID m_layer
Definition board_item.h:459
bool m_isLocked
Definition board_item.h:462
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:285
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
constexpr const Vec & GetPosition() const
Definition box2.h:211
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:558
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:658
constexpr const Vec GetCenter() const
Definition box2.h:230
constexpr coord_type GetLeft() const
Definition box2.h:228
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:168
constexpr coord_type GetRight() const
Definition box2.h:217
constexpr coord_type GetTop() const
Definition box2.h:229
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:311
constexpr coord_type GetBottom() const
Definition box2.h:222
The base class for create windows for drawing purpose.
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:111
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:93
std::vector< VECTOR2I > GetCornersInSequence(EDA_ANGLE angle) const
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:216
void SetEnd(const VECTOR2I &aEnd)
Definition eda_shape.h:220
virtual EDA_ANGLE GetDrawRotation() const
Definition eda_text.h:379
virtual void ClearRenderCache()
Definition eda_text.cpp:683
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition property.h:727
static ENUM_MAP< T > & Instance()
Definition property.h:721
wxPGChoices & Choices()
Definition property.h:770
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:105
PCB specific render settings.
Definition pcb_painter.h:82
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetPosition(const VECTOR2I &aPos) override
Definition pcb_shape.h:78
VECTOR2I GetPosition() const override
Definition pcb_shape.h:79
int GetRowSpan() const
int GetColSpan() const
VECTOR2I GetEnd() const
STROKE_PARAMS m_separatorsStroke
Definition pcb_table.h:300
bool StrokeRows() const
Definition pcb_table.h:107
int GetRowCount() const
Definition pcb_table.h:124
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
void TransformGraphicItemsToPolySet(SHAPE_POLY_SET &aBuffer, int aMaxError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings) const
Convert graphic items (segments and texts) to a set of polygonal shapes.
std::vector< PCB_TABLECELL * > m_cells
Definition pcb_table.h:305
void SetColWidth(int aCol, int aWidth)
Definition pcb_table.h:129
int m_colCount
Definition pcb_table.h:302
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
bool m_strokeRows
Definition pcb_table.h:298
void Move(const VECTOR2I &aMoveVector) override
Move this object.
int GetPositionY() const
Definition pcb_table.h:119
bool StrokeHeaderSeparator() const
Definition pcb_table.h:65
bool StrokeColumns() const
Definition pcb_table.h:104
void SetBorderStyle(const LINE_STYLE aStyle)
Definition pcb_table.h:73
void SetStrokeHeaderSeparator(bool aDoStroke)
Definition pcb_table.h:64
void SetSeparatorsColor(const COLOR4D &aColor)
Definition pcb_table.h:100
bool m_strokeExternal
Definition pcb_table.h:295
STROKE_PARAMS m_borderStroke
Definition pcb_table.h:297
bool m_strokeColumns
Definition pcb_table.h:299
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const override
Return a user-visible description string of this item.
std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT) const override
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
bool StrokeExternal() const
Definition pcb_table.h:62
int GetSeparatorsWidth() const
Definition pcb_table.h:89
void SetPositionX(int x)
Definition pcb_table.h:116
void SetStrokeExternal(bool aDoStroke)
Definition pcb_table.h:61
PCB_TABLECELL * GetCell(int aRow, int aCol) const
Definition pcb_table.h:149
std::vector< PCB_TABLECELL * > GetCells() const
Definition pcb_table.h:159
void Autosize()
int GetBorderWidth() const
Definition pcb_table.h:71
COLOR4D GetBorderColor() const
Definition pcb_table.h:83
void TransformShapeToPolySet(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, KIGFX::RENDER_SETTINGS *aRenderSettings=nullptr) const override
Convert the TABLE shape to a polyset.
bool operator==(const PCB_TABLE &aOther) const
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, 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...
int GetColCount() const
Definition pcb_table.h:122
void SetStrokeColumns(bool aDoStroke)
Definition pcb_table.h:103
const STROKE_PARAMS & GetSeparatorsStroke() const
Definition pcb_table.h:86
std::map< int, int > m_colWidths
Definition pcb_table.h:303
virtual void swapData(BOARD_ITEM *aImage) override
Definition pcb_table.cpp:78
int GetPositionX() const
Definition pcb_table.h:118
void Normalize() override
Perform any normalization required after a user rotate and/or flip.
void AddCell(PCB_TABLECELL *aCell)
Definition pcb_table.h:164
const STROKE_PARAMS & GetBorderStroke() const
Definition pcb_table.h:68
void SetPositionY(int y)
Definition pcb_table.h:117
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
void SetStrokeRows(bool aDoStroke)
Definition pcb_table.h:106
bool m_StrokeHeaderSeparator
Definition pcb_table.h:296
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc, bool aIgnoreLineWidth=false) const override
Convert the item shape to a closed polygon.
void DrawBorders(const std::function< void(const VECTOR2I &aPt1, const VECTOR2I &aPt2, const STROKE_PARAMS &aStroke)> &aCallback) const
LINE_STYLE GetBorderStyle() const
Definition pcb_table.h:74
static int Compare(const PCB_TABLE *aTable, const PCB_TABLE *aOther)
int GetColWidth(int aCol) const
Definition pcb_table.h:131
VECTOR2I GetPosition() const override
void SetSeparatorsWidth(int aWidth)
Definition pcb_table.h:88
COLOR4D GetSeparatorsColor() const
Definition pcb_table.h:101
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
LINE_STYLE GetSeparatorsStyle() const
Definition pcb_table.h:92
void SetBorderColor(const COLOR4D &aColor)
Definition pcb_table.h:82
PCB_TABLE(BOARD_ITEM *aParent, int aLineWidth)
Definition pcb_table.cpp:38
void SetSeparatorsStyle(const LINE_STYLE aStyle)
Definition pcb_table.h:91
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 SetRowHeight(int aRow, int aHeight)
Definition pcb_table.h:139
void SetPosition(const VECTOR2I &aPos) override
void SetBorderWidth(int aWidth)
Definition pcb_table.h:70
int GetRowHeight(int aRow) const
Definition pcb_table.h:141
std::map< int, int > m_rowHeights
Definition pcb_table.h:304
void TransformTextToPolySet(SHAPE_POLY_SET &aBuffer, int aClearance, int aMaxError, ERROR_LOC aErrorLoc) const
Function TransformTextToPolySet Convert the text to a polygonSet describing the actual character stro...
int GetMarginLeft() const
Definition pcb_textbox.h:96
int GetMarginRight() const
Definition pcb_textbox.h:98
Provide class metadata.Helper macro to map type hashes to names.
void InheritsAfter(TYPE_ID aDerived, TYPE_ID aBase)
Declare an inheritance relationship between types.
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 polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
void Inflate(int aAmount, CORNER_STRATEGY aCornerStrategy, int aMaxError, bool aSimplify=false)
Perform outline inflation/deflation.
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
const BOX2I BBox(int aClearance=0) const override
Compute a bounding box of the shape, with a margin of aClearance a collision.
Represent a simple polygon consisting of a zero-thickness closed chain of connected line segments.
Simple container to manage line stroke parameters.
int GetWidth() const
LINE_STYLE GetLineStyle() const
static void Stroke(const SHAPE *aShape, LINE_STYLE aLineStyle, int aWidth, const KIGFX::RENDER_SETTINGS *aRenderSettings, const std::function< void(const VECTOR2I &a, const VECTOR2I &b)> &aStroker)
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void TransformOvalToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a oblong shape to a polygon, using multiple segments.
@ CHAMFER_ALL_CORNERS
All angles are chamfered.
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:411
RECURSE_MODE
Definition eda_item.h:51
@ RECURSE
Definition eda_item.h:52
INSPECT_RESULT
Definition eda_item.h:45
const INSPECTOR_FUNC & INSPECTOR
std::function passed to nested users by ref, avoids copying std::function.
Definition eda_item.h:92
a few functions useful in geometry calculations.
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition layer_id.cpp:172
bool IsFrontLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a front layer.
Definition layer_ids.h:780
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition layer_ids.h:184
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
FLIP_DIRECTION
Definition mirror.h:27
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:28
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:29
bool ShapeHitTest(const SHAPE_LINE_CHAIN &aHitter, const SHAPE &aHittee, bool aHitteeContained)
Perform a shape-to-shape hit test.
#define _HKI(x)
Definition page_info.cpp:44
static struct PCB_TABLE_DESC _PCB_TABLE_DESC
#define TYPE_HASH(x)
Definition property.h:74
@ PT_COORD
Coordinate expressed in distance units (mm/inch)
Definition property.h:65
@ PT_SIZE
Size expressed in distance units (mm/inch)
Definition property.h:63
#define REGISTER_TYPE(x)
constexpr double correction
LINE_STYLE
Dashed line types.
VECTOR2I end
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:229
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:78
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:95
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:94
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695