KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_track.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) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright (C) 2012 Wayne Stambaugh <[email protected]>
7 * Copyright (C) 1992-2024 KiCad Developers, see AUTHORS.txt for contributors.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26#include <pcb_base_frame.h>
27#include <core/mirror.h>
29#include <board.h>
32#include <pcb_track.h>
33#include <base_units.h>
34#include <string_utils.h>
35#include <view/view.h>
38#include <geometry/seg.h>
41#include <geometry/shape_arc.h>
42#include <drc/drc_engine.h>
43#include <pcb_painter.h>
44#include <trigo.h>
45
46#include <google/protobuf/any.pb.h>
47#include <api/api_enums.h>
48#include <api/api_utils.h>
49#include <api/api_pcb_utils.h>
50#include <api/board/board_types.pb.h>
51
54
56 BOARD_CONNECTED_ITEM( aParent, idtype )
57{
58 m_Width = pcbIUScale.mmToIU( 0.2 ); // Gives a reasonable default width
59 m_CachedScale = -1.0; // Set invalid to force update
60 m_CachedLOD = 0.0; // Set to always display
61}
62
63
65{
66 return new PCB_TRACK( *this );
67}
68
69
70PCB_ARC::PCB_ARC( BOARD_ITEM* aParent, const SHAPE_ARC* aArc ) :
71 PCB_TRACK( aParent, PCB_ARC_T )
72{
73 m_Start = aArc->GetP0();
74 m_End = aArc->GetP1();
75 m_Mid = aArc->GetArcMid();
76}
77
78
80{
81 return new PCB_ARC( *this );
82}
83
84
86 PCB_TRACK( aParent, PCB_VIA_T )
87{
88 SetViaType( VIATYPE::THROUGH );
90 Padstack().Drill().end = B_Cu;
92
94
96
97 m_isFree = false;
98}
99
100
101PCB_VIA::PCB_VIA( const PCB_VIA& aOther ) :
102 PCB_TRACK( aOther.GetParent(), PCB_VIA_T )
103{
104 PCB_VIA::operator=( aOther );
105
106 const_cast<KIID&>( m_Uuid ) = aOther.m_Uuid;
108}
109
110
112{
114
115 m_Width = aOther.m_Width;
116 m_Start = aOther.m_Start;
117 m_End = aOther.m_End;
118 m_CachedLOD = aOther.m_CachedLOD;
120
121 m_viaType = aOther.m_viaType;
122 m_padStack = aOther.m_padStack;
123 m_isFree = aOther.m_isFree;
124
125 return *this;
126}
127
128
130{
131 return new PCB_VIA( *this );
132}
133
134
135wxString PCB_VIA::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
136{
137 wxString formatStr;
138
139 switch( GetViaType() )
140 {
141 case VIATYPE::BLIND_BURIED: formatStr = _( "Blind/Buried Via %s on %s" ); break;
142 case VIATYPE::MICROVIA: formatStr = _( "Micro Via %s on %s" ); break;
143 default: formatStr = _( "Via %s on %s" ); break;
144 }
145
146 return wxString::Format( formatStr, GetNetnameMsg(), layerMaskDescribe() );
147}
148
149
151{
152 return BITMAPS::via;
153}
154
155
156bool PCB_TRACK::operator==( const BOARD_ITEM& aOther ) const
157{
158 if( aOther.Type() != Type() )
159 return false;
160
161 const PCB_TRACK& other = static_cast<const PCB_TRACK&>( aOther );
162
163 return *this == other;
164}
165
166
167bool PCB_TRACK::operator==( const PCB_TRACK& aOther ) const
168{
169 return m_Start == aOther.m_Start
170 && m_End == aOther.m_End
171 && m_layer == aOther.m_layer
172 && m_Width == aOther.m_Width;
173}
174
175
176double PCB_TRACK::Similarity( const BOARD_ITEM& aOther ) const
177{
178 if( aOther.Type() != Type() )
179 return 0.0;
180
181 const PCB_TRACK& other = static_cast<const PCB_TRACK&>( aOther );
182
183 double similarity = 1.0;
184
185 if( m_layer != other.m_layer )
186 similarity *= 0.9;
187
188 if( m_Width != other.m_Width )
189 similarity *= 0.9;
190
191 if( m_Start != other.m_Start )
192 similarity *= 0.9;
193
194 if( m_End != other.m_End )
195 similarity *= 0.9;
196
197 return similarity;
198}
199
200
201bool PCB_ARC::operator==( const BOARD_ITEM& aOther ) const
202{
203 if( aOther.Type() != Type() )
204 return false;
205
206 const PCB_ARC& other = static_cast<const PCB_ARC&>( aOther );
207
208 return m_Start == other.m_Start && m_End == other.m_End && m_Mid == other.m_Mid &&
209 m_layer == other.m_layer && m_Width == other.m_Width;
210}
211
212
213double PCB_ARC::Similarity( const BOARD_ITEM& aOther ) const
214{
215 if( aOther.Type() != Type() )
216 return 0.0;
217
218 const PCB_ARC& other = static_cast<const PCB_ARC&>( aOther );
219
220 double similarity = 1.0;
221
222 if( m_layer != other.m_layer )
223 similarity *= 0.9;
224
225 if( m_Width != other.m_Width )
226 similarity *= 0.9;
227
228 if( m_Start != other.m_Start )
229 similarity *= 0.9;
230
231 if( m_End != other.m_End )
232 similarity *= 0.9;
233
234 if( m_Mid != other.m_Mid )
235 similarity *= 0.9;
236
237 return similarity;
238}
239
240
241bool PCB_VIA::operator==( const BOARD_ITEM& aOther ) const
242{
243 if( aOther.Type() != Type() )
244 return false;
245
246 const PCB_VIA& other = static_cast<const PCB_VIA&>( aOther );
247
248 return m_Start == other.m_Start && m_End == other.m_End && m_layer == other.m_layer &&
249 m_padStack == other.m_padStack && m_Width == other.m_Width &&
250 m_viaType == other.m_viaType &&
252}
253
254
255double PCB_VIA::Similarity( const BOARD_ITEM& aOther ) const
256{
257 if( aOther.Type() != Type() )
258 return 0.0;
259
260 const PCB_VIA& other = static_cast<const PCB_VIA&>( aOther );
261
262 double similarity = 1.0;
263
264 if( m_layer != other.m_layer )
265 similarity *= 0.9;
266
267 if( m_Width != other.m_Width )
268 similarity *= 0.9;
269
270 if( m_Start != other.m_Start )
271 similarity *= 0.9;
272
273 if( m_End != other.m_End )
274 similarity *= 0.9;
275
276 if( m_padStack != other.m_padStack )
277 similarity *= 0.9;
278
279 if( m_viaType != other.m_viaType )
280 similarity *= 0.9;
281
283 similarity *= 0.9;
284
285 return similarity;
286}
287
288
289void PCB_TRACK::Serialize( google::protobuf::Any &aContainer ) const
290{
291 kiapi::board::types::Track track;
292
293 track.mutable_id()->set_value( m_Uuid.AsStdString() );
294 track.mutable_start()->set_x_nm( GetStart().x );
295 track.mutable_start()->set_y_nm( GetStart().y );
296 track.mutable_end()->set_x_nm( GetEnd().x );
297 track.mutable_end()->set_y_nm( GetEnd().y );
298 track.mutable_width()->set_value_nm( GetWidth() );
299 track.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
300 track.set_locked( IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
301 : kiapi::common::types::LockedState::LS_UNLOCKED );
302 track.mutable_net()->mutable_code()->set_value( GetNetCode() );
303 track.mutable_net()->set_name( GetNetname() );
304
305 aContainer.PackFrom( track );
306}
307
308
309bool PCB_TRACK::Deserialize( const google::protobuf::Any &aContainer )
310{
311 kiapi::board::types::Track track;
312
313 if( !aContainer.UnpackTo( &track ) )
314 return false;
315
316 const_cast<KIID&>( m_Uuid ) = KIID( track.id().value() );
317 SetStart( VECTOR2I( track.start().x_nm(), track.start().y_nm() ) );
318 SetEnd( VECTOR2I( track.end().x_nm(), track.end().y_nm() ) );
319 SetWidth( track.width().value_nm() );
320 SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( track.layer() ) );
321 SetNetCode( track.net().code().value() );
322 SetLocked( track.locked() == kiapi::common::types::LockedState::LS_LOCKED );
323
324 return true;
325}
326
327
328void PCB_ARC::Serialize( google::protobuf::Any &aContainer ) const
329{
330 kiapi::board::types::Arc arc;
331
332 arc.mutable_id()->set_value( m_Uuid.AsStdString() );
333 arc.mutable_start()->set_x_nm( GetStart().x );
334 arc.mutable_start()->set_y_nm( GetStart().y );
335 arc.mutable_mid()->set_x_nm( GetMid().x );
336 arc.mutable_mid()->set_y_nm( GetMid().y );
337 arc.mutable_end()->set_x_nm( GetEnd().x );
338 arc.mutable_end()->set_y_nm( GetEnd().y );
339 arc.mutable_width()->set_value_nm( GetWidth() );
340 arc.set_layer( ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( GetLayer() ) );
341 arc.set_locked( IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
342 : kiapi::common::types::LockedState::LS_UNLOCKED );
343 arc.mutable_net()->mutable_code()->set_value( GetNetCode() );
344 arc.mutable_net()->set_name( GetNetname() );
345
346 aContainer.PackFrom( arc );
347}
348
349
350bool PCB_ARC::Deserialize( const google::protobuf::Any &aContainer )
351{
352 kiapi::board::types::Arc arc;
353
354 if( !aContainer.UnpackTo( &arc ) )
355 return false;
356
357 const_cast<KIID&>( m_Uuid ) = KIID( arc.id().value() );
358 SetStart( VECTOR2I( arc.start().x_nm(), arc.start().y_nm() ) );
359 SetMid( VECTOR2I( arc.mid().x_nm(), arc.mid().y_nm() ) );
360 SetEnd( VECTOR2I( arc.end().x_nm(), arc.end().y_nm() ) );
361 SetWidth( arc.width().value_nm() );
362 SetLayer( FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( arc.layer() ) );
363 SetNetCode( arc.net().code().value() );
364 SetLocked( arc.locked() == kiapi::common::types::LockedState::LS_LOCKED );
365
366 return true;
367}
368
369
370void PCB_VIA::Serialize( google::protobuf::Any &aContainer ) const
371{
372 kiapi::board::types::Via via;
373
374 via.mutable_id()->set_value( m_Uuid.AsStdString() );
375 via.mutable_position()->set_x_nm( GetPosition().x );
376 via.mutable_position()->set_y_nm( GetPosition().y );
377
378 const PADSTACK& stack = Padstack();
379
380 kiapi::board::types::PadStack* padstack = via.mutable_pad_stack();
381 padstack->set_type( GetViaType() == VIATYPE::BLIND_BURIED
382 ? kiapi::board::types::PadStackType::PST_BLIND_BURIED
383 : kiapi::board::types::PadStackType::PST_THROUGH );
384 padstack->set_start_layer(
385 ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( stack.Drill().start ) );
386 padstack->set_end_layer(
387 ToProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>( stack.Drill().end ) );
388 kiapi::common::PackVector2( *padstack->mutable_drill_diameter(),
389 { GetDrillValue(), GetDrillValue() } );
390
391 kiapi::board::types::PadStackLayer* stackLayer = padstack->add_layers();
392 kiapi::board::PackLayerSet( *stackLayer->mutable_layers(), GetLayerSet() );
393 kiapi::common::PackVector2( *stackLayer->mutable_size(),
394 { GetWidth(), GetWidth() } );
395
396 // TODO: Microvia status is ignored here. Do we still need it?
397
398 padstack->set_unconnected_layer_removal(
400 kiapi::board::types::UnconnectedLayerRemoval>(
401 Padstack().UnconnectedLayerMode() ) );
402
403 via.set_locked( IsLocked() ? kiapi::common::types::LockedState::LS_LOCKED
404 : kiapi::common::types::LockedState::LS_UNLOCKED );
405 via.mutable_net()->mutable_code()->set_value( GetNetCode() );
406 via.mutable_net()->set_name( GetNetname() );
407
408 aContainer.PackFrom( via );
409}
410
411
412bool PCB_VIA::Deserialize( const google::protobuf::Any &aContainer )
413{
414 kiapi::board::types::Via via;
415
416 if( !aContainer.UnpackTo( &via ) )
417 return false;
418
419 const_cast<KIID&>( m_Uuid ) = KIID( via.id().value() );
420 SetStart( VECTOR2I( via.position().x_nm(), via.position().y_nm() ) );
421 SetEnd( GetStart() );
422 SetDrill( via.pad_stack().drill_diameter().x_nm() );
423
424 const kiapi::board::types::PadStack& padstack = via.pad_stack();
425
426 // We don't yet support complex padstacks for vias
427 if( padstack.layers_size() == 1 )
428 {
429 const kiapi::board::types::PadStackLayer& layer = padstack.layers( 0 );
430 SetWidth( layer.size().x_nm() );
431 }
432
433 switch( padstack.type() )
434 {
435 case kiapi::board::types::PadStackType::PST_BLIND_BURIED:
436 SetViaType( VIATYPE::BLIND_BURIED );
437 break;
438
439 default:
440 SetViaType( VIATYPE::THROUGH );
441 break;
442 }
443
444 if( GetViaType() != VIATYPE::THROUGH )
445 {
446 Padstack().Drill().start = FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>(
447 padstack.start_layer() );
448
449 Padstack().Drill().end = FromProtoEnum<PCB_LAYER_ID, kiapi::board::types::BoardLayer>(
450 padstack.end_layer() );
451 }
452 else
453 {
454 Padstack().Drill().start = F_Cu;
455 Padstack().Drill().end = B_Cu;
456 }
457 Padstack().SetUnconnectedLayerMode( FromProtoEnum<PADSTACK::UNCONNECTED_LAYER_MODE>(
458 padstack.unconnected_layer_removal() ) );
459
460 SetNetCode( via.net().code().value() );
461 SetLocked( via.locked() == kiapi::common::types::LockedState::LS_LOCKED );
462
463 return true;
464}
465
466
468{
469 SEG a( m_Start, m_End );
470 SEG b( aTrack.GetStart(), aTrack.GetEnd() );
471 return a.ApproxCollinear( b );
472}
473
474
476{
477 DRC_CONSTRAINT constraint;
478
479 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
480 {
482
483 constraint = bds.m_DRCEngine->EvalRules( TRACK_WIDTH_CONSTRAINT, this, nullptr, m_layer );
484 }
485
486 if( aSource )
487 *aSource = constraint.GetName();
488
489 return constraint.Value();
490}
491
492
494{
495 DRC_CONSTRAINT constraint;
496
497 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
498 {
500
501 constraint = bds.m_DRCEngine->EvalRules( VIA_DIAMETER_CONSTRAINT, this, nullptr, m_layer );
502 }
503
504 if( aSource )
505 *aSource = constraint.GetName();
506
507 return constraint.Value();
508}
509
510
512{
513 DRC_CONSTRAINT constraint;
514
515 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
516 {
518
519 constraint = bds.m_DRCEngine->EvalRules( HOLE_SIZE_CONSTRAINT, this, nullptr, m_layer );
520 }
521
522 if( aSource )
523 *aSource = constraint.GetName();
524
525 return constraint.Value();
526}
527
528
529int PCB_VIA::GetMinAnnulus( PCB_LAYER_ID aLayer, wxString* aSource ) const
530{
531 if( !FlashLayer( aLayer ) )
532 {
533 if( aSource )
534 *aSource = _( "removed annular ring" );
535
536 return 0;
537 }
538
539 DRC_CONSTRAINT constraint;
540
541 if( GetBoard() && GetBoard()->GetDesignSettings().m_DRCEngine )
542 {
544
545 constraint = bds.m_DRCEngine->EvalRules( ANNULAR_WIDTH_CONSTRAINT, this, nullptr, aLayer );
546 }
547
548 if( constraint.Value().HasMin() )
549 {
550 if( aSource )
551 *aSource = constraint.GetName();
552
553 return constraint.Value().Min();
554 }
555
556 return 0;
557}
558
559
561{
562 if( m_padStack.Drill().size.x > 0 ) // Use the specific value.
563 return m_padStack.Drill().size.x;
564
565 // Use the default value from the Netclass
566 NETCLASS* netclass = GetEffectiveNetClass();
567
568 if( GetViaType() == VIATYPE::MICROVIA )
569 return netclass->GetuViaDrill();
570
571 return netclass->GetViaDrill();
572}
573
574
575EDA_ITEM_FLAGS PCB_TRACK::IsPointOnEnds( const VECTOR2I& point, int min_dist ) const
576{
577 EDA_ITEM_FLAGS result = 0;
578
579 if( min_dist < 0 )
580 min_dist = m_Width / 2;
581
582 if( min_dist == 0 )
583 {
584 if( m_Start == point )
585 result |= STARTPOINT;
586
587 if( m_End == point )
588 result |= ENDPOINT;
589 }
590 else
591 {
592 double dist = GetLineLength( m_Start, point );
593
594 if( min_dist >= KiROUND( dist ) )
595 result |= STARTPOINT;
596
597 dist = GetLineLength( m_End, point );
598
599 if( min_dist >= KiROUND( dist ) )
600 result |= ENDPOINT;
601 }
602
603 return result;
604}
605
606
608{
609 // end of track is round, this is its radius, rounded up
610 int radius = ( m_Width + 1 ) / 2;
611 int ymax, xmax, ymin, xmin;
612
613 if( Type() == PCB_VIA_T )
614 {
615 ymax = m_Start.y;
616 xmax = m_Start.x;
617
618 ymin = m_Start.y;
619 xmin = m_Start.x;
620 }
621 else if( Type() == PCB_ARC_T )
622 {
623 std::shared_ptr<SHAPE> arc = GetEffectiveShape();
624 BOX2I bbox = arc->BBox();
625
626 xmin = bbox.GetLeft();
627 xmax = bbox.GetRight();
628 ymin = bbox.GetTop();
629 ymax = bbox.GetBottom();
630 }
631 else
632 {
633 ymax = std::max( m_Start.y, m_End.y );
634 xmax = std::max( m_Start.x, m_End.x );
635
636 ymin = std::min( m_Start.y, m_End.y );
637 xmin = std::min( m_Start.x, m_End.x );
638 }
639
640 ymax += radius;
641 xmax += radius;
642
643 ymin -= radius;
644 xmin -= radius;
645
646 // return a rectangle which is [pos,dim) in nature. therefore the +1
647 return BOX2ISafe( VECTOR2I( xmin, ymin ),
648 VECTOR2L( (int64_t) xmax - xmin + 1, (int64_t) ymax - ymin + 1 ) );
649}
650
651
653{
654 return GetLineLength( m_Start, m_End );
655}
656
657
658void PCB_TRACK::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
659{
660 RotatePoint( m_Start, aRotCentre, aAngle );
661 RotatePoint( m_End, aRotCentre, aAngle );
662}
663
664
665void PCB_ARC::Rotate( const VECTOR2I& aRotCentre, const EDA_ANGLE& aAngle )
666{
667 RotatePoint( m_Start, aRotCentre, aAngle );
668 RotatePoint( m_End, aRotCentre, aAngle );
669 RotatePoint( m_Mid, aRotCentre, aAngle );
670}
671
672
673void PCB_TRACK::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
674{
675 if( aMirrorAroundXAxis )
676 {
677 MIRROR( m_Start.y, aCentre.y );
678 MIRROR( m_End.y, aCentre.y );
679 }
680 else
681 {
682 MIRROR( m_Start.x, aCentre.x );
683 MIRROR( m_End.x, aCentre.x );
684 }
685}
686
687
688void PCB_ARC::Mirror( const VECTOR2I& aCentre, bool aMirrorAroundXAxis )
689{
690 if( aMirrorAroundXAxis )
691 {
692 MIRROR( m_Start.y, aCentre.y );
693 MIRROR( m_End.y, aCentre.y );
694 MIRROR( m_Mid.y, aCentre.y );
695 }
696 else
697 {
698 MIRROR( m_Start.x, aCentre.x );
699 MIRROR( m_End.x, aCentre.x );
700 MIRROR( m_Mid.x, aCentre.x );
701 }
702}
703
704
705void PCB_TRACK::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
706{
707 if( aFlipLeftRight )
708 {
709 m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
710 m_End.x = aCentre.x - ( m_End.x - aCentre.x );
711 }
712 else
713 {
714 m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
715 m_End.y = aCentre.y - ( m_End.y - aCentre.y );
716 }
717
718 int copperLayerCount = GetBoard()->GetCopperLayerCount();
719 SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
720}
721
722
723void PCB_ARC::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
724{
725 if( aFlipLeftRight )
726 {
727 m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
728 m_End.x = aCentre.x - ( m_End.x - aCentre.x );
729 m_Mid.x = aCentre.x - ( m_Mid.x - aCentre.x );
730 }
731 else
732 {
733 m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
734 m_End.y = aCentre.y - ( m_End.y - aCentre.y );
735 m_Mid.y = aCentre.y - ( m_Mid.y - aCentre.y );
736 }
737
738 int copperLayerCount = GetBoard()->GetCopperLayerCount();
739 SetLayer( FlipLayer( GetLayer(), copperLayerCount ) );
740}
741
742
743bool PCB_ARC::IsCCW() const
744{
745 VECTOR2I start_end = m_End - m_Start;
746 VECTOR2I start_mid = m_Mid - m_Start;
747
748 return start_end.Cross( start_mid ) < 0;
749}
750
751
752void PCB_VIA::Flip( const VECTOR2I& aCentre, bool aFlipLeftRight )
753{
754 if( aFlipLeftRight )
755 {
756 m_Start.x = aCentre.x - ( m_Start.x - aCentre.x );
757 m_End.x = aCentre.x - ( m_End.x - aCentre.x );
758 }
759 else
760 {
761 m_Start.y = aCentre.y - ( m_Start.y - aCentre.y );
762 m_End.y = aCentre.y - ( m_End.y - aCentre.y );
763 }
764
765 if( GetViaType() != VIATYPE::THROUGH )
766 {
767 int copperLayerCount = GetBoard()->GetCopperLayerCount();
768 PCB_LAYER_ID top_layer;
769 PCB_LAYER_ID bottom_layer;
770 LayerPair( &top_layer, &bottom_layer );
771 top_layer = FlipLayer( top_layer, copperLayerCount );
772 bottom_layer = FlipLayer( bottom_layer, copperLayerCount );
773 SetLayerPair( top_layer, bottom_layer );
774 }
775}
776
777
778INSPECT_RESULT PCB_TRACK::Visit( INSPECTOR inspector, void* testData,
779 const std::vector<KICAD_T>& aScanTypes )
780{
781 for( KICAD_T scanType : aScanTypes )
782 {
783 if( scanType == Type() )
784 {
785 if( INSPECT_RESULT::QUIT == inspector( this, testData ) )
786 return INSPECT_RESULT::QUIT;
787 }
788 }
789
790 return INSPECT_RESULT::CONTINUE;
791}
792
793
794std::shared_ptr<SHAPE_SEGMENT> PCB_VIA::GetEffectiveHoleShape() const
795{
796 return std::make_shared<SHAPE_SEGMENT>( SEG( m_Start, m_Start ), Padstack().Drill().size.x );
797}
798
799
801{
802 if( const BOARD* board = GetBoard() )
803 return board->GetTentVias();
804 else
805 return true;
806}
807
808
810{
811 if( const BOARD* board = GetBoard() )
812 return board->GetDesignSettings().m_SolderMaskExpansion;
813 else
814 return 0;
815}
816
817
819{
820#if 0
821 // Nice and simple, but raises its ugly head in performance profiles....
822 return GetLayerSet().test( aLayer );
823#endif
824
825 if( aLayer >= Padstack().Drill().start && aLayer <= Padstack().Drill().end )
826 return true;
827
828 if( !IsTented() )
829 {
830 if( aLayer == F_Mask )
831 return IsOnLayer( F_Cu );
832 else if( aLayer == B_Mask )
833 return IsOnLayer( B_Cu );
834 }
835
836 return false;
837}
838
839
841{
842 return Padstack().Drill().start;
843}
844
845
847{
848 Padstack().Drill().start = aLayer;
849}
850
851
853{
854 LSET layermask;
855
856 if( Padstack().Drill().start < PCBNEW_LAYER_ID_START )
857 return layermask;
858
859 if( GetViaType() == VIATYPE::THROUGH )
860 layermask = LSET::AllCuMask();
861 else
862 wxASSERT( Padstack().Drill().start <= Padstack().Drill().end );
863
864 // PCB_LAYER_IDs are numbered from front to back, this is top to bottom.
865 for( int id = Padstack().Drill().start; id <= Padstack().Drill().end; ++id )
866 layermask.set( id );
867
868 if( !IsTented() )
869 {
870 if( layermask.test( F_Cu ) )
871 layermask.set( F_Mask );
872
873 if( layermask.test( B_Cu ) )
874 layermask.set( B_Mask );
875 }
876
877 return layermask;
878}
879
880
881void PCB_VIA::SetLayerSet( LSET aLayerSet )
882{
883 bool first = true;
884
885 for( PCB_LAYER_ID layer : aLayerSet.Seq() )
886 {
887 // m_layer and m_bottomLayer are copper layers, so consider only copper layers in aLayerSet
888 if( !IsCopperLayer( layer ) )
889 continue;
890
891 if( first )
892 {
893 Padstack().Drill().start = layer;
894 first = false;
895 }
896
897 Padstack().Drill().end = layer;
898 }
899}
900
901
902void PCB_VIA::SetLayerPair( PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer )
903{
904
905 Padstack().Drill().start = aTopLayer;
906 Padstack().Drill().end = aBottomLayer;
908}
909
910
912{
913 Padstack().Drill().start = aLayer;
914}
915
916
918{
919 Padstack().Drill().end = aLayer;
920}
921
922
923void PCB_VIA::LayerPair( PCB_LAYER_ID* top_layer, PCB_LAYER_ID* bottom_layer ) const
924{
925 PCB_LAYER_ID t_layer = F_Cu;
926 PCB_LAYER_ID b_layer = B_Cu;
927
928 if( GetViaType() != VIATYPE::THROUGH )
929 {
930 b_layer = Padstack().Drill().end;
931 t_layer = Padstack().Drill().start;
932
933 if( b_layer < t_layer )
934 std::swap( b_layer, t_layer );
935 }
936
937 if( top_layer )
938 *top_layer = t_layer;
939
940 if( bottom_layer )
941 *bottom_layer = b_layer;
942}
943
944
946{
947 return Padstack().Drill().start;
948}
949
950
952{
953 return Padstack().Drill().end;
954}
955
956
958{
959 if( GetViaType() == VIATYPE::THROUGH )
960 {
961 Padstack().Drill().start = F_Cu;
962 Padstack().Drill().end = B_Cu;
963 }
964
965 if( Padstack().Drill().end < Padstack().Drill().start )
966 std::swap( Padstack().Drill().end, Padstack().Drill().start );
967}
968
969
970bool PCB_VIA::FlashLayer( LSET aLayers ) const
971{
972 for( PCB_LAYER_ID layer : aLayers.Seq() )
973 {
974 if( FlashLayer( layer ) )
975 return true;
976 }
977
978 return false;
979}
980
981
982bool PCB_VIA::FlashLayer( int aLayer ) const
983{
984 // Return the "normal" shape if the caller doesn't specify a particular layer
985 if( aLayer == UNDEFINED_LAYER )
986 return true;
987
988 const BOARD* board = GetBoard();
989
990 if( !board )
991 return true;
992
993 if( !IsOnLayer( static_cast<PCB_LAYER_ID>( aLayer ) ) )
994 return false;
995
996 if( !IsCopperLayer( aLayer ) )
997 return true;
998
999 switch( Padstack().UnconnectedLayerMode() )
1000 {
1002 return true;
1003
1005 {
1006 if( aLayer == Padstack().Drill().start || aLayer == Padstack().Drill().end )
1007 return true;
1008
1009 // Check for removal below
1010 break;
1011 }
1012
1014 // Check for removal below
1015 break;
1016 }
1017
1018 // Must be static to keep from raising its ugly head in performance profiles
1019 static std::initializer_list<KICAD_T> connectedTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
1020 PCB_PAD_T };
1021
1022 if( m_zoneLayerOverrides[ aLayer ] == ZLO_FORCE_FLASHED )
1023 return true;
1024 else
1025 return board->GetConnectivity()->IsConnectedOnLayer( this, aLayer, connectedTypes );
1026}
1027
1028
1030 PCB_LAYER_ID* aBottommost ) const
1031{
1032 *aTopmost = UNDEFINED_LAYER;
1033 *aBottommost = UNDEFINED_LAYER;
1034
1035 static std::initializer_list<KICAD_T> connectedTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T,
1036 PCB_PAD_T };
1037
1038 for( int layer = TopLayer(); layer <= BottomLayer(); ++layer )
1039 {
1040 bool connected = false;
1041
1042 if( m_zoneLayerOverrides[ layer ] == ZLO_FORCE_FLASHED )
1043 connected = true;
1044 else if( GetBoard()->GetConnectivity()->IsConnectedOnLayer( this, layer, connectedTypes ) )
1045 connected = true;
1046
1047 if( connected )
1048 {
1049 if( *aTopmost == UNDEFINED_LAYER )
1050 *aTopmost = ToLAYER_ID( layer );
1051
1052 *aBottommost = ToLAYER_ID( layer );
1053 }
1054 }
1055
1056}
1057
1058
1059void PCB_TRACK::ViewGetLayers( int aLayers[], int& aCount ) const
1060{
1061 // Show the track and its netname on different layers
1062 aLayers[0] = GetLayer();
1063 aLayers[1] = GetNetnameLayer( aLayers[0] );
1064 aCount = 2;
1065
1066 if( IsLocked() )
1067 aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
1068}
1069
1070
1071double PCB_TRACK::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
1072{
1073 constexpr double HIDE = std::numeric_limits<double>::max();
1074
1075 PCB_PAINTER* painter = static_cast<PCB_PAINTER*>( aView->GetPainter() );
1076 PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
1077
1078 if( !aView->IsLayerVisible( LAYER_TRACKS ) )
1079 return HIDE;
1080
1081 if( IsNetnameLayer( aLayer ) )
1082 {
1084 return HIDE;
1085
1086 // Hide netnames on dimmed tracks
1087 if( renderSettings->GetHighContrast() )
1088 {
1089 if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
1090 return HIDE;
1091 }
1092
1093 // Pick the approximate size of the netname (square chars)
1094 wxString netName = GetUnescapedShortNetname();
1095 size_t num_chars = netName.size();
1096
1097 if( GetLength() < num_chars * GetWidth() )
1098 return HIDE;
1099
1100 // When drawing netnames, clip the track to the viewport
1101 VECTOR2I start( GetStart() );
1102 VECTOR2I end( GetEnd() );
1103 BOX2D viewport = aView->GetViewport();
1104 BOX2I clipBox = BOX2ISafe( viewport );
1105
1106 ClipLine( &clipBox, start.x, start.y, end.x, end.y );
1107
1108 VECTOR2I line = ( end - start );
1109
1110 if( line.EuclideanNorm() == 0 )
1111 return HIDE;
1112
1113 // Netnames will be shown only if zoom is appropriate
1114 return ( double ) pcbIUScale.mmToIU( 4 ) / ( m_Width + 1 );
1115 }
1116
1117 if( aLayer == LAYER_LOCKED_ITEM_SHADOW )
1118 {
1119 // Hide shadow if the main layer is not shown
1120 if( !aView->IsLayerVisible( m_layer ) )
1121 return HIDE;
1122
1123 // Hide shadow on dimmed tracks
1124 if( renderSettings->GetHighContrast() )
1125 {
1126 if( m_layer != renderSettings->GetPrimaryHighContrastLayer() )
1127 return HIDE;
1128 }
1129 }
1130
1131 // Other layers are shown without any conditions
1132 return 0.0;
1133}
1134
1135
1137{
1138 BOX2I bbox = GetBoundingBox();
1139
1140 if( const BOARD* board = GetBoard() )
1141 bbox.Inflate( 2 * board->GetDesignSettings().GetBiggestClearanceValue() );
1142 else
1143 bbox.Inflate( GetWidth() ); // Add a bit extra for safety
1144
1145 return bbox;
1146}
1147
1148
1149void PCB_VIA::ViewGetLayers( int aLayers[], int& aCount ) const
1150{
1151 aLayers[0] = LAYER_VIA_HOLES;
1152 aLayers[1] = LAYER_VIA_HOLEWALLS;
1153 aLayers[2] = LAYER_VIA_NETNAMES;
1154
1155 // Just show it on common via & via holes layers
1156 switch( GetViaType() )
1157 {
1158 case VIATYPE::THROUGH: aLayers[3] = LAYER_VIA_THROUGH; break;
1159 case VIATYPE::BLIND_BURIED: aLayers[3] = LAYER_VIA_BBLIND; break;
1160 case VIATYPE::MICROVIA: aLayers[3] = LAYER_VIA_MICROVIA; break;
1161 default: aLayers[3] = LAYER_GP_OVERLAY; break;
1162 }
1163
1164 aCount = 4;
1165
1166 if( IsLocked() )
1167 aLayers[ aCount++ ] = LAYER_LOCKED_ITEM_SHADOW;
1168
1169 // Vias can also be on a solder mask layer. They are on these layers or not,
1170 // depending on the plot and solder mask options
1171 if( IsOnLayer( F_Mask ) )
1172 aLayers[ aCount++ ] = F_Mask;
1173
1174 if( IsOnLayer( B_Mask ) )
1175 aLayers[ aCount++ ] = B_Mask;
1176}
1177
1178
1179double PCB_VIA::ViewGetLOD( int aLayer, KIGFX::VIEW* aView ) const
1180{
1181 constexpr double HIDE = (double)std::numeric_limits<double>::max();
1182
1183 PCB_PAINTER* painter = static_cast<PCB_PAINTER*>( aView->GetPainter() );
1184 PCB_RENDER_SETTINGS* renderSettings = painter->GetSettings();
1185 LSET visible = LSET::AllLayersMask();
1186
1187 // Meta control for hiding all vias
1188 if( !aView->IsLayerVisible( LAYER_VIAS ) )
1189 return HIDE;
1190
1191 // Handle board visibility
1192 if( const BOARD* board = GetBoard() )
1193 visible = board->GetVisibleLayers() & board->GetEnabledLayers();
1194
1195 // In high contrast mode don't show vias that don't cross the high-contrast layer
1196 if( renderSettings->GetHighContrast() )
1197 {
1198 PCB_LAYER_ID highContrastLayer = renderSettings->GetPrimaryHighContrastLayer();
1199
1200 if( LSET::FrontTechMask().Contains( highContrastLayer ) )
1201 highContrastLayer = F_Cu;
1202 else if( LSET::BackTechMask().Contains( highContrastLayer ) )
1203 highContrastLayer = B_Cu;
1204
1205 if( !GetLayerSet().Contains( highContrastLayer ) )
1206 return HIDE;
1207 }
1208
1209 if( IsHoleLayer( aLayer ) )
1210 {
1211 if( m_viaType == VIATYPE::BLIND_BURIED || m_viaType == VIATYPE::MICROVIA )
1212 {
1213 // Show a blind or micro via's hole if it crosses a visible layer
1214 if( !( visible & GetLayerSet() ).any() )
1215 return HIDE;
1216 }
1217 else
1218 {
1219 // Show a through via's hole if any physical layer is shown
1220 if( !( visible & LSET::PhysicalLayersMask() ).any() )
1221 return HIDE;
1222 }
1223 }
1224 else if( IsNetnameLayer( aLayer ) )
1225 {
1226 if( renderSettings->GetHighContrast() )
1227 {
1228 // Hide netnames unless via is flashed to a high-contrast layer
1229 if( !FlashLayer( renderSettings->GetPrimaryHighContrastLayer() ) )
1230 return HIDE;
1231 }
1232 else
1233 {
1234 // Hide netnames unless pad is flashed to a visible layer
1235 if( !FlashLayer( visible ) )
1236 return HIDE;
1237 }
1238
1239 // Netnames will be shown only if zoom is appropriate
1240 return m_Width == 0 ? HIDE : ( (double)pcbIUScale.mmToIU( 10 ) / m_Width );
1241 }
1242
1243 // Passed all tests; show.
1244 return 0.0;
1245}
1246
1247
1249{
1250 switch( Type() )
1251 {
1252 case PCB_ARC_T: return _( "Track (arc)" );
1253 case PCB_VIA_T: return _( "Via" );
1254 case PCB_TRACE_T:
1255 default: return _( "Track" );
1256 }
1257}
1258
1259
1260void PCB_TRACK::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1261{
1262 wxString msg;
1263 BOARD* board = GetBoard();
1264
1265 aList.emplace_back( _( "Type" ), GetFriendlyName() );
1266
1267 GetMsgPanelInfoBase_Common( aFrame, aList );
1268
1269 aList.emplace_back( _( "Layer" ), layerMaskDescribe() );
1270
1271 aList.emplace_back( _( "Width" ), aFrame->MessageTextFromValue( m_Width ) );
1272
1273 if( Type() == PCB_ARC_T )
1274 {
1275 double radius = static_cast<PCB_ARC*>( this )->GetRadius();
1276 aList.emplace_back( _( "Radius" ), aFrame->MessageTextFromValue( radius ) );
1277 }
1278
1279 aList.emplace_back( _( "Segment Length" ), aFrame->MessageTextFromValue( GetLength() ) );
1280
1281 // Display full track length (in Pcbnew)
1282 if( board && GetNetCode() > 0 )
1283 {
1284 int count;
1285 double trackLen;
1286 double lenPadToDie;
1287
1288 std::tie( count, trackLen, lenPadToDie ) = board->GetTrackLength( *this );
1289
1290 aList.emplace_back( _( "Routed Length" ), aFrame->MessageTextFromValue( trackLen ) );
1291
1292 if( lenPadToDie != 0 )
1293 {
1294 msg = aFrame->MessageTextFromValue( lenPadToDie );
1295 aList.emplace_back( _( "Pad To Die Length" ), msg );
1296
1297 msg = aFrame->MessageTextFromValue( trackLen + lenPadToDie );
1298 aList.emplace_back( _( "Full Length" ), msg );
1299 }
1300 }
1301
1302 wxString source;
1303 int clearance = GetOwnClearance( GetLayer(), &source );
1304
1305 aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
1306 aFrame->MessageTextFromValue( clearance ) ),
1307 wxString::Format( _( "(from %s)" ), source ) );
1308
1309 MINOPTMAX<int> constraintValue = GetWidthConstraint( &source );
1310 msg = aFrame->MessageTextFromMinOptMax( constraintValue );
1311
1312 if( !msg.IsEmpty() )
1313 {
1314 aList.emplace_back( wxString::Format( _( "Width Constraints: %s" ), msg ),
1315 wxString::Format( _( "(from %s)" ), source ) );
1316 }
1317}
1318
1319
1320void PCB_VIA::GetMsgPanelInfo( EDA_DRAW_FRAME* aFrame, std::vector<MSG_PANEL_ITEM>& aList )
1321{
1322 wxString msg;
1323
1324 switch( GetViaType() )
1325 {
1326 case VIATYPE::MICROVIA: msg = _( "Micro Via" ); break;
1327 case VIATYPE::BLIND_BURIED: msg = _( "Blind/Buried Via" ); break;
1328 case VIATYPE::THROUGH: msg = _( "Through Via" ); break;
1329 default: msg = _( "Via" ); break;
1330 }
1331
1332 aList.emplace_back( _( "Type" ), msg );
1333
1334 GetMsgPanelInfoBase_Common( aFrame, aList );
1335
1336 aList.emplace_back( _( "Layer" ), layerMaskDescribe() );
1337 aList.emplace_back( _( "Diameter" ), aFrame->MessageTextFromValue( m_Width ) );
1338 aList.emplace_back( _( "Hole" ), aFrame->MessageTextFromValue( GetDrillValue() ) );
1339
1340 wxString source;
1341 int clearance = GetOwnClearance( GetLayer(), &source );
1342
1343 aList.emplace_back( wxString::Format( _( "Min Clearance: %s" ),
1344 aFrame->MessageTextFromValue( clearance ) ),
1345 wxString::Format( _( "(from %s)" ), source ) );
1346
1347 int minAnnulus = GetMinAnnulus( GetLayer(), &source );
1348
1349 aList.emplace_back( wxString::Format( _( "Min Annular Width: %s" ),
1350 aFrame->MessageTextFromValue( minAnnulus ) ),
1351 wxString::Format( _( "(from %s)" ), source ) );
1352}
1353
1354
1356 std::vector<MSG_PANEL_ITEM>& aList ) const
1357{
1358 aList.emplace_back( _( "Net" ), UnescapeString( GetNetname() ) );
1359
1360 aList.emplace_back( _( "Resolved Netclass" ),
1361 UnescapeString( GetEffectiveNetClass()->GetName() ) );
1362
1363#if 0 // Enable for debugging
1364 if( GetBoard() )
1365 aList.emplace_back( _( "NetCode" ), wxString::Format( wxT( "%d" ), GetNetCode() ) );
1366
1367 aList.emplace_back( wxT( "Flags" ), wxString::Format( wxT( "0x%08X" ), m_flags ) );
1368
1369 aList.emplace_back( wxT( "Start pos" ), wxString::Format( wxT( "%d %d" ),
1370 m_Start.x,
1371 m_Start.y ) );
1372 aList.emplace_back( wxT( "End pos" ), wxString::Format( wxT( "%d %d" ),
1373 m_End.x,
1374 m_End.y ) );
1375#endif
1376
1377 if( aFrame->GetName() == PCB_EDIT_FRAME_NAME && IsLocked() )
1378 aList.emplace_back( _( "Status" ), _( "Locked" ) );
1379}
1380
1381
1383{
1384 const BOARD* board = GetBoard();
1385 PCB_LAYER_ID top_layer;
1386 PCB_LAYER_ID bottom_layer;
1387
1388 LayerPair( &top_layer, &bottom_layer );
1389
1390 return board->GetLayerName( top_layer ) + wxT( " - " ) + board->GetLayerName( bottom_layer );
1391}
1392
1393
1394bool PCB_TRACK::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1395{
1396 return TestSegmentHit( aPosition, m_Start, m_End, aAccuracy + ( m_Width / 2 ) );
1397}
1398
1399
1400bool PCB_ARC::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1401{
1402 int max_dist = aAccuracy + ( m_Width / 2 );
1403
1404 // Short-circuit common cases where the arc is connected to a track or via at an endpoint
1405 if( EuclideanNorm( GetStart() - aPosition ) <= max_dist ||
1406 EuclideanNorm( GetEnd() - aPosition ) <= max_dist )
1407 {
1408 return true;
1409 }
1410
1411 VECTOR2I center = GetPosition();
1412 VECTOR2I relpos = aPosition - center;
1413 double dist = EuclideanNorm( relpos );
1414 double radius = GetRadius();
1415
1416 if( std::abs( dist - radius ) > max_dist )
1417 return false;
1418
1419 EDA_ANGLE arc_angle = GetAngle();
1420 EDA_ANGLE arc_angle_start = GetArcAngleStart(); // Always 0.0 ... 360 deg
1421 EDA_ANGLE arc_hittest( relpos );
1422
1423 // Calculate relative angle between the starting point of the arc, and the test point
1424 arc_hittest -= arc_angle_start;
1425
1426 // Normalise arc_hittest between 0 ... 360 deg
1427 arc_hittest.Normalize();
1428
1429 if( arc_angle < ANGLE_0 )
1430 return arc_hittest >= ANGLE_360 + arc_angle;
1431
1432 return arc_hittest <= arc_angle;
1433}
1434
1435
1436bool PCB_VIA::HitTest( const VECTOR2I& aPosition, int aAccuracy ) const
1437{
1438 int max_dist = aAccuracy + ( m_Width / 2 );
1439
1440 // rel_pos is aPosition relative to m_Start (or the center of the via)
1441 VECTOR2I rel_pos = aPosition - m_Start;
1442 double dist = (double) rel_pos.x * rel_pos.x + (double) rel_pos.y * rel_pos.y;
1443 return dist <= (double) max_dist * max_dist;
1444}
1445
1446
1447bool PCB_TRACK::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1448{
1449 BOX2I arect = aRect;
1450 arect.Inflate( aAccuracy );
1451
1452 if( aContained )
1453 return arect.Contains( GetStart() ) && arect.Contains( GetEnd() );
1454 else
1455 return arect.Intersects( GetStart(), GetEnd() );
1456}
1457
1458
1459bool PCB_ARC::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1460{
1461 BOX2I arect = aRect;
1462 arect.Inflate( aAccuracy );
1463
1464 BOX2I box( GetStart() );
1465 box.Merge( GetMid() );
1466 box.Merge( GetEnd() );
1467
1468 box.Inflate( GetWidth() / 2 );
1469
1470 if( aContained )
1471 return arect.Contains( box );
1472 else
1473 return arect.Intersects( box );
1474}
1475
1476
1477bool PCB_VIA::HitTest( const BOX2I& aRect, bool aContained, int aAccuracy ) const
1478{
1479 BOX2I arect = aRect;
1480 arect.Inflate( aAccuracy );
1481
1482 BOX2I box( GetStart() );
1483 box.Inflate( GetWidth() / 2 );
1484
1485 if( aContained )
1486 return arect.Contains( box );
1487 else
1488 return arect.IntersectsCircle( GetStart(), GetWidth() / 2 );
1489}
1490
1491
1492wxString PCB_TRACK::GetItemDescription( UNITS_PROVIDER* aUnitsProvider ) const
1493{
1494 return wxString::Format( Type() == PCB_ARC_T ? _("Track (arc) %s on %s, length %s" )
1495 : _("Track %s on %s, length %s" ),
1496 GetNetnameMsg(),
1497 GetLayerName(),
1498 aUnitsProvider->MessageTextFromValue( GetLength() ) );
1499}
1500
1501
1503{
1504 return BITMAPS::add_tracks;
1505}
1506
1508{
1509 assert( aImage->Type() == PCB_TRACE_T );
1510
1511 std::swap( *((PCB_TRACK*) this), *((PCB_TRACK*) aImage) );
1512}
1513
1515{
1516 assert( aImage->Type() == PCB_ARC_T );
1517
1518 std::swap( *this, *static_cast<PCB_ARC*>( aImage ) );
1519}
1520
1522{
1523 assert( aImage->Type() == PCB_VIA_T );
1524
1525 std::swap( *((PCB_VIA*) this), *((PCB_VIA*) aImage) );
1526}
1527
1528
1530{
1532 return center;
1533}
1534
1535
1537{
1538 auto center = CalcArcCenter( m_Start, m_Mid , m_End );
1539 return GetLineLength( center, m_Start );
1540}
1541
1542
1544{
1545 VECTOR2I center = GetPosition();
1546 EDA_ANGLE angle1 = EDA_ANGLE( m_Mid - center ) - EDA_ANGLE( m_Start - center );
1547 EDA_ANGLE angle2 = EDA_ANGLE( m_End - center ) - EDA_ANGLE( m_Mid - center );
1548
1549 return angle1.Normalize180() + angle2.Normalize180();
1550}
1551
1552
1554{
1555 VECTOR2I pos( GetPosition() );
1556 VECTOR2D dir( (double) m_Start.x - pos.x, (double) m_Start.y - pos.y );
1557
1558 EDA_ANGLE angleStart( dir );
1559 return angleStart.Normalize();
1560}
1561
1562
1563// Note: used in python tests. Ignore CLion's claim that it's unused....
1565{
1566 VECTOR2I pos( GetPosition() );
1567 VECTOR2D dir( (double) m_End.x - pos.x, (double) m_End.y - pos.y );
1568
1569 EDA_ANGLE angleEnd( dir );
1570 return angleEnd.Normalize();
1571}
1572
1573bool PCB_ARC::IsDegenerated( int aThreshold ) const
1574{
1575 // Too small arcs cannot be really handled: arc center (and arc radius)
1576 // cannot be safely computed if the distance between mid and end points
1577 // is too small (a few internal units)
1578
1579 // len of both segments must be < aThreshold to be a very small degenerated arc
1580 return ( GetMid() - GetStart() ).EuclideanNorm() < aThreshold
1581 && ( GetMid() - GetEnd() ).EuclideanNorm() < aThreshold;
1582}
1583
1584
1586{
1587 if( a->GetNetCode() != b->GetNetCode() )
1588 return a->GetNetCode() < b->GetNetCode();
1589
1590 if( a->GetLayer() != b->GetLayer() )
1591 return a->GetLayer() < b->GetLayer();
1592
1593 if( a->Type() != b->Type() )
1594 return a->Type() < b->Type();
1595
1596 if( a->m_Uuid != b->m_Uuid )
1597 return a->m_Uuid < b->m_Uuid;
1598
1599 return a < b;
1600}
1601
1602
1603std::shared_ptr<SHAPE> PCB_TRACK::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
1604{
1605 return std::make_shared<SHAPE_SEGMENT>( m_Start, m_End, m_Width );
1606}
1607
1608
1609std::shared_ptr<SHAPE> PCB_VIA::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
1610{
1611 if( aFlash == FLASHING::ALWAYS_FLASHED
1612 || ( aFlash == FLASHING::DEFAULT && FlashLayer( aLayer ) ) )
1613 {
1614 return std::make_shared<SHAPE_CIRCLE>( m_Start, m_Width / 2 );
1615 }
1616 else
1617 {
1618 return std::make_shared<SHAPE_CIRCLE>( m_Start, GetDrillValue() / 2 );
1619 }
1620}
1621
1622
1623std::shared_ptr<SHAPE> PCB_ARC::GetEffectiveShape( PCB_LAYER_ID aLayer, FLASHING aFlash ) const
1624{
1625 return std::make_shared<SHAPE_ARC>( GetStart(), GetMid(), GetEnd(), GetWidth() );
1626}
1627
1628
1630 int aClearance, int aError, ERROR_LOC aErrorLoc,
1631 bool ignoreLineWidth ) const
1632{
1633 wxASSERT_MSG( !ignoreLineWidth, wxT( "IgnoreLineWidth has no meaning for tracks." ) );
1634
1635
1636 switch( Type() )
1637 {
1638 case PCB_VIA_T:
1639 {
1640 int radius = ( m_Width / 2 ) + aClearance;
1641 TransformCircleToPolygon( aBuffer, m_Start, radius, aError, aErrorLoc );
1642 break;
1643 }
1644
1645 case PCB_ARC_T:
1646 {
1647 const PCB_ARC* arc = static_cast<const PCB_ARC*>( this );
1648 int width = m_Width + ( 2 * aClearance );
1649
1650 TransformArcToPolygon( aBuffer, arc->GetStart(), arc->GetMid(), arc->GetEnd(), width,
1651 aError, aErrorLoc );
1652 break;
1653 }
1654
1655 default:
1656 {
1657 int width = m_Width + ( 2 * aClearance );
1658
1659 TransformOvalToPolygon( aBuffer, m_Start, m_End, width, aError, aErrorLoc );
1660 break;
1661 }
1662 }
1663}
1664
1665
1666static struct TRACK_VIA_DESC
1667{
1669 {
1671 .Undefined( VIATYPE::NOT_DEFINED )
1672 .Map( VIATYPE::THROUGH, _HKI( "Through" ) )
1673 .Map( VIATYPE::BLIND_BURIED, _HKI( "Blind/buried" ) )
1674 .Map( VIATYPE::MICROVIA, _HKI( "Micro" ) );
1675
1677
1678 if( layerEnum.Choices().GetCount() == 0 )
1679 {
1680 layerEnum.Undefined( UNDEFINED_LAYER );
1681
1682 for( LSEQ seq = LSET::AllLayersMask().Seq(); seq; ++seq )
1683 layerEnum.Map( *seq, LSET::Name( *seq ) );
1684 }
1685
1687
1688 // Track
1691
1692 propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "Width" ),
1693 &PCB_TRACK::SetWidth, &PCB_TRACK::GetWidth, PROPERTY_DISPLAY::PT_SIZE ) );
1694 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position X" ),
1696 &PCB_TRACK::SetX, &PCB_TRACK::GetX, PROPERTY_DISPLAY::PT_COORD,
1698 propMgr.ReplaceProperty( TYPE_HASH( BOARD_ITEM ), _HKI( "Position Y" ),
1700 &PCB_TRACK::SetY, &PCB_TRACK::GetY, PROPERTY_DISPLAY::PT_COORD,
1702 propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "End X" ),
1703 &PCB_TRACK::SetEndX, &PCB_TRACK::GetEndX, PROPERTY_DISPLAY::PT_COORD,
1705 propMgr.AddProperty( new PROPERTY<PCB_TRACK, int>( _HKI( "End Y" ),
1706 &PCB_TRACK::SetEndY, &PCB_TRACK::GetEndY, PROPERTY_DISPLAY::PT_COORD,
1708
1709 // Arc
1712
1713 // Via
1716
1717 // TODO test drill, use getdrillvalue?
1718 const wxString groupVia = _HKI( "Via Properties" );
1719
1720 propMgr.Mask( TYPE_HASH( PCB_VIA ), TYPE_HASH( BOARD_CONNECTED_ITEM ), _HKI( "Layer" ) );
1721
1722 propMgr.ReplaceProperty( TYPE_HASH( PCB_TRACK ), _HKI( "Width" ),
1723 new PROPERTY<PCB_VIA, int, PCB_TRACK>( _HKI( "Diameter" ),
1724 &PCB_VIA::SetWidth, &PCB_VIA::GetWidth, PROPERTY_DISPLAY::PT_SIZE ) );
1725 propMgr.AddProperty( new PROPERTY<PCB_VIA, int>( _HKI( "Hole" ),
1726 &PCB_VIA::SetDrill, &PCB_VIA::GetDrillValue, PROPERTY_DISPLAY::PT_SIZE ), groupVia );
1727 propMgr.AddProperty( new PROPERTY_ENUM<PCB_VIA, PCB_LAYER_ID>( _HKI( "Layer Top" ),
1728 &PCB_VIA::SetLayer, &PCB_VIA::GetLayer ), groupVia );
1729 propMgr.AddProperty( new PROPERTY_ENUM<PCB_VIA, PCB_LAYER_ID>( _HKI( "Layer Bottom" ),
1731 propMgr.AddProperty( new PROPERTY_ENUM<PCB_VIA, VIATYPE>( _HKI( "Via Type" ),
1733 }
1735
types::KiCadObjectType ToProtoEnum(KICAD_T aValue)
Definition: api_enums.cpp:94
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:108
BITMAPS
A list of all bitmap identifiers.
Definition: bitmaps_list.h:33
@ ZLO_NONE
Definition: board_item.h:65
@ ZLO_FORCE_FLASHED
Definition: board_item.h:66
BOX2I BOX2ISafe(const BOX2D &aInput)
Definition: box2.h:883
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
wxString GetNetnameMsg() const
virtual NETCLASS * GetEffectiveNetClass() const
Return the NETCLASS for this item.
bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
virtual int GetOwnClearance(PCB_LAYER_ID aLayer, wxString *aSource=nullptr) const
Return an item's "own" clearance in internal units.
wxString GetUnescapedShortNetname() const
Container for design settings for a BOARD object.
std::shared_ptr< DRC_ENGINE > m_DRCEngine
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
int GetY() const
Definition: board_item.h:101
virtual void SetLocked(bool aLocked)
Definition: board_item.h:300
PCB_LAYER_ID m_layer
Definition: board_item.h:393
int GetX() const
Definition: board_item.h:95
void SetX(int aX)
Definition: board_item.h:117
void SetY(int aY)
Definition: board_item.h:123
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
virtual const BOARD * GetBoard() const
Return the BOARD in which this BOARD_ITEM resides, or NULL if none.
Definition: board_item.cpp:46
virtual bool IsLocked() const
Definition: board_item.cpp:74
virtual wxString layerMaskDescribe() const
Return a string (to be shown to the user) describing a layer mask.
Definition: board_item.cpp:115
wxString GetLayerName() const
Return the name of the PCB layer on which the item resides.
Definition: board_item.cpp:103
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
int GetCopperLayerCount() const
Definition: board.cpp:653
const wxString GetLayerName(PCB_LAYER_ID aLayer) const
Return the name of a aLayer.
Definition: board.cpp:564
std::tuple< int, double, double > GetTrackLength(const PCB_TRACK &aTrack) const
Return data on the length and number of track segments connected to a given track.
Definition: board.cpp:2181
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:794
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:460
bool Intersects(const BOX2< Vec > &aRect) const
Definition: box2.h:294
coord_type GetTop() const
Definition: box2.h:219
bool IntersectsCircle(const Vec &aCenter, const int aRadius) const
Definition: box2.h:487
bool Contains(const Vec &aPoint) const
Definition: box2.h:158
BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition: box2.h:541
coord_type GetRight() const
Definition: box2.h:207
coord_type GetLeft() const
Definition: box2.h:218
coord_type GetBottom() const
Definition: box2.h:212
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:623
wxString GetName() const
Definition: drc_rule.h:149
MINOPTMAX< int > & Value()
Definition: drc_rule.h:142
EDA_ANGLE Normalize()
Definition: eda_angle.h:255
EDA_ANGLE Normalize180()
Definition: eda_angle.h:294
The base class for create windows for drawing purpose.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:88
EDA_ITEM & operator=(const EDA_ITEM &aItem)
Assign the members of aItem to another object.
Definition: eda_item.cpp:258
const KIID m_Uuid
Definition: eda_item.h:485
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:100
EDA_ITEM_FLAGS m_flags
Definition: eda_item.h:490
ENUM_MAP & Map(T aValue, const wxString &aName)
Definition: property.h:669
static ENUM_MAP< T > & Instance()
Definition: property.h:663
ENUM_MAP & Undefined(T aValue)
Definition: property.h:676
wxPGChoices & Choices()
Definition: property.h:712
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:165
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: pcb_painter.h:170
PCB specific render settings.
Definition: pcb_painter.h:78
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
bool GetHighContrast() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
BOX2D GetViewport() const
Return the current viewport visible area rectangle.
Definition: view.cpp:512
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:412
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:215
Definition: kiid.h:49
std::string AsStdString() const
Definition: kiid.cpp:263
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition: layer_ids.h:521
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
static LSET AllLayersMask()
Definition: lset.cpp:898
LSEQ Seq(const PCB_LAYER_ID *aWishListSequence, unsigned aCount) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition: lset.cpp:418
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:863
static LSET PhysicalLayersMask()
Return a mask holding all layers which are physically realized.
Definition: lset.cpp:960
static const wxChar * Name(PCB_LAYER_ID aLayerId)
Return the fixed name association with aLayerId.
Definition: lset.cpp:89
static LSET FrontTechMask()
Return a mask holding all technical layers (no CU layer) on front side.
Definition: lset.cpp:917
static LSET BackTechMask()
Return a mask holding all technical layers (no CU layer) on back side.
Definition: lset.cpp:905
T Min() const
Definition: minoptmax.h:33
bool HasMin() const
Definition: minoptmax.h:37
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:44
int GetViaDrill() const
Definition: netclass.h:81
int GetuViaDrill() const
Definition: netclass.h:89
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:375
A PADSTACK defines the characteristics of a single or multi-layer pad, in the IPC sense of the word.
Definition: padstack.h:115
void SetUnconnectedLayerMode(UNCONNECTED_LAYER_MODE aMode)
Definition: padstack.h:254
DRILL_PROPS & Drill()
Definition: padstack.h:247
UNCONNECTED_LAYER_MODE
! Whether or not to remove the copper shape for unconnected layers
Definition: padstack.h:135
bool operator==(const BOARD_ITEM &aOther) const override
Definition: pcb_track.cpp:201
virtual VECTOR2I GetPosition() const override
Definition: pcb_track.cpp:1529
bool IsDegenerated(int aThreshold=5) const
Definition: pcb_track.cpp:1573
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_track.cpp:1514
bool IsCCW() const
Definition: pcb_track.cpp:743
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_track.cpp:328
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:79
EDA_ANGLE GetArcAngleStart() const
Definition: pcb_track.cpp:1553
virtual bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: pcb_track.cpp:1400
EDA_ANGLE GetArcAngleEnd() const
Definition: pcb_track.cpp:1564
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_track.cpp:350
void SetMid(const VECTOR2I &aMid)
Definition: pcb_track.h:315
double GetRadius() const
Definition: pcb_track.cpp:1536
EDA_ANGLE GetAngle() const
Definition: pcb_track.cpp:1543
const VECTOR2I & GetMid() const
Definition: pcb_track.h:316
PCB_ARC(BOARD_ITEM *aParent)
Definition: pcb_track.h:291
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_track.cpp:723
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: pcb_track.cpp:213
VECTOR2I m_Mid
Arc mid point, halfway between start and end.
Definition: pcb_track.h:376
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_track.cpp:665
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.
Definition: pcb_track.cpp:1623
void Mirror(const VECTOR2I &aCentre, bool aMirrorAroundXAxis) override
Definition: pcb_track.cpp:688
double m_CachedScale
Last zoom scale used to draw this track's net.
Definition: pcb_track.h:284
double m_CachedLOD
Last LOD used to draw this track's net.
Definition: pcb_track.h:283
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
Definition: pcb_track.cpp:658
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: pcb_track.cpp:1059
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_track.cpp:289
void SetEndY(int aY)
Definition: pcb_track.h:117
void SetWidth(int aWidth)
Definition: pcb_track.h:107
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: pcb_track.cpp:1071
virtual double GetLength() const
Get the length of the track using the hypotenuse calculation.
Definition: pcb_track.cpp:652
int GetWidth() const
Definition: pcb_track.h:108
virtual void swapData(BOARD_ITEM *aImage) override
Definition: pcb_track.cpp:1507
void SetEnd(const VECTOR2I &aEnd)
Definition: pcb_track.h:110
void SetStart(const VECTOR2I &aStart)
Definition: pcb_track.h:113
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: pcb_track.cpp:1492
const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: pcb_track.cpp:1136
int GetEndX() const
Definition: pcb_track.h:119
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_track.cpp:309
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...
Definition: pcb_track.cpp:778
bool ApproxCollinear(const PCB_TRACK &aTrack)
Definition: pcb_track.cpp:467
VECTOR2I m_End
Line end point.
Definition: pcb_track.h:281
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.
Definition: pcb_track.cpp:1260
virtual EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:64
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: pcb_track.cpp:607
void TransformShapeToPolygon(SHAPE_POLY_SET &aBuffer, PCB_LAYER_ID aLayer, int aClearance, int aError, ERROR_LOC aErrorLoc, bool ignoreLineWidth=false) const override
Convert the track shape to a closed polygon.
Definition: pcb_track.cpp:1629
const VECTOR2I & GetStart() const
Definition: pcb_track.h:114
virtual bool operator==(const BOARD_ITEM &aOther) const override
Definition: pcb_track.cpp:156
VECTOR2I m_Start
Line start point.
Definition: pcb_track.h:280
int GetEndY() const
Definition: pcb_track.h:120
wxString GetFriendlyName() const override
Definition: pcb_track.cpp:1248
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_track.cpp:1502
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_track.cpp:705
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: pcb_track.cpp:1394
virtual double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: pcb_track.cpp:176
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.
Definition: pcb_track.cpp:1603
const VECTOR2I & GetEnd() const
Definition: pcb_track.h:111
PCB_TRACK(BOARD_ITEM *aParent, KICAD_T idtype=PCB_TRACE_T)
Definition: pcb_track.cpp:55
int m_Width
Thickness of track, or via diameter.
Definition: pcb_track.h:279
virtual MINOPTMAX< int > GetWidthConstraint(wxString *aSource=nullptr) const
Definition: pcb_track.cpp:475
void SetEndX(int aX)
Definition: pcb_track.h:116
virtual void Mirror(const VECTOR2I &aCentre, bool aMirrorAroundXAxis)
Definition: pcb_track.cpp:673
EDA_ITEM_FLAGS IsPointOnEnds(const VECTOR2I &point, int min_dist=0) const
Return STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if point if near (dist = m...
Definition: pcb_track.cpp:575
void GetMsgPanelInfoBase_Common(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) const
Definition: pcb_track.cpp:1355
bool IsTented() const override
Definition: pcb_track.cpp:800
PCB_LAYER_ID BottomLayer() const
Definition: pcb_track.cpp:951
BITMAPS GetMenuImage() const override
Return a pointer to an image to be used in menus.
Definition: pcb_track.cpp:150
VECTOR2I GetPosition() const override
Definition: pcb_track.h:473
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.
Definition: pcb_track.cpp:1609
bool Deserialize(const google::protobuf::Any &aContainer) override
Deserializes the given protobuf message into this object.
Definition: pcb_track.cpp:412
bool FlashLayer(int aLayer) const
Check to see whether the via should have a pad on the specific layer.
Definition: pcb_track.cpp:982
void SetDrillDefault()
Set the drill value for vias to the default value UNDEFINED_DRILL_DIAMETER.
Definition: pcb_track.h:610
const PADSTACK & Padstack() const
Definition: pcb_track.h:414
bool m_isFree
"Free" vias don't get their nets auto-updated
Definition: pcb_track.h:662
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition: pcb_track.cpp:1436
virtual void SetLayerSet(LSET aLayers) override
Note SetLayerSet() initialize the first and last copper layers connected by the via.
Definition: pcb_track.cpp:881
void SetBottomLayer(PCB_LAYER_ID aLayer)
Definition: pcb_track.cpp:917
std::array< ZONE_LAYER_OVERRIDE, MAX_CU_LAYERS > m_zoneLayerOverrides
Definition: pcb_track.h:665
int GetSolderMaskExpansion() const
Definition: pcb_track.cpp:809
void SetDrill(int aDrill)
Set the drill value for vias.
Definition: pcb_track.h:588
MINOPTMAX< int > GetDrillConstraint(wxString *aSource=nullptr) const
Definition: pcb_track.cpp:511
bool operator==(const BOARD_ITEM &aOther) const override
Definition: pcb_track.cpp:241
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.
Definition: pcb_track.cpp:1320
EDA_ITEM * Clone() const override
Create a duplicate of this item with linked list members set to NULL.
Definition: pcb_track.cpp:129
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: pcb_track.cpp:840
double ViewGetLOD(int aLayer, KIGFX::VIEW *aView) const override
Return the level of detail (LOD) of the item.
Definition: pcb_track.cpp:1179
void SetTopLayer(PCB_LAYER_ID aLayer)
Definition: pcb_track.cpp:911
std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape() const override
Definition: pcb_track.cpp:794
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
For a via m_layer contains the top layer, the other layer is in m_bottomLayer/.
Definition: pcb_track.cpp:902
double Similarity(const BOARD_ITEM &aOther) const override
Return a measure of how likely the other object is to represent the same object.
Definition: pcb_track.cpp:255
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_track.cpp:846
void GetOutermostConnectedLayers(PCB_LAYER_ID *aTopmost, PCB_LAYER_ID *aBottommost) const
Return the top-most and bottom-most connected layers.
Definition: pcb_track.cpp:1029
void ViewGetLayers(int aLayers[], int &aCount) const override
Return the all the layers within the VIEW the object is painted on.
Definition: pcb_track.cpp:1149
void SanitizeLayers()
Check so that the layers are correct depending on the type of via, and so that the top actually is on...
Definition: pcb_track.cpp:957
PCB_VIA & operator=(const PCB_VIA &aOther)
Definition: pcb_track.cpp:111
void swapData(BOARD_ITEM *aImage) override
Definition: pcb_track.cpp:1521
void Serialize(google::protobuf::Any &aContainer) const override
Serializes this object to the given Any message.
Definition: pcb_track.cpp:370
PCB_VIA(BOARD_ITEM *aParent)
Definition: pcb_track.cpp:85
wxString layerMaskDescribe() const override
Return a string (to be shown to the user) describing a layer mask.
Definition: pcb_track.cpp:1382
void SetViaType(VIATYPE aViaType)
Definition: pcb_track.h:412
int GetMinAnnulus(PCB_LAYER_ID aLayer, wxString *aSource) const
Definition: pcb_track.cpp:529
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition: pcb_track.cpp:818
PCB_LAYER_ID TopLayer() const
Definition: pcb_track.cpp:945
wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider) const override
Return a user-visible description string of this item.
Definition: pcb_track.cpp:135
VIATYPE m_viaType
through, blind/buried or micro
Definition: pcb_track.h:658
PADSTACK m_padStack
Definition: pcb_track.h:660
int GetDrillValue() const
Calculate the drill value for vias (m_drill if > 0, or default drill value for the board).
Definition: pcb_track.cpp:560
VIATYPE GetViaType() const
Definition: pcb_track.h:411
MINOPTMAX< int > GetWidthConstraint(wxString *aSource=nullptr) const override
Definition: pcb_track.cpp:493
virtual LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pcb_track.cpp:852
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Return the 2 layers used by the via (the via actually uses all layers between these 2 layers)
Definition: pcb_track.cpp:923
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: pcb_track.cpp:752
Provide class metadata.Helper macro to map type hashes to names.
Definition: property_mgr.h:85
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()
Definition: property_mgr.h:87
PROPERTY_BASE & AddProperty(PROPERTY_BASE *aProperty, const wxString &aGroup=wxEmptyString)
Register a property.
PROPERTY_BASE & ReplaceProperty(size_t aBase, const wxString &aName, PROPERTY_BASE *aNew, const wxString &aGroup=wxEmptyString)
Replace an existing property for a specific type.
Definition: seg.h:42
bool ApproxCollinear(const SEG &aSeg, int aDistanceThreshold=1) const
Definition: seg.cpp:390
const VECTOR2I & GetArcMid() const
Definition: shape_arc.h:115
const VECTOR2I & GetP1() const
Definition: shape_arc.h:114
const VECTOR2I & GetP0() const
Definition: shape_arc.h:113
Represent a set of closed polygons.
wxString MessageTextFromMinOptMax(const MINOPTMAX< int > &aValue) const
wxString MessageTextFromValue(double aValue, bool aAddUnitLabel=true, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
A lower-precision version of StringFromValue().
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:265
extended_type Cross(const VECTOR2< T > &aVector) const
Compute cross product of self with aVector.
Definition: vector2d.h:471
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 TransformArcToPolygon(SHAPE_POLY_SET &aBuffer, const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd, int aWidth, int aError, ERROR_LOC aErrorLoc)
Convert arc to multiple straight segments.
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.
#define _HKI(x)
@ ANNULAR_WIDTH_CONSTRAINT
Definition: drc_rule.h:57
@ VIA_DIAMETER_CONSTRAINT
Definition: drc_rule.h:63
@ TRACK_WIDTH_CONSTRAINT
Definition: drc_rule.h:56
@ HOLE_SIZE_CONSTRAINT
Definition: drc_rule.h:51
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition: eda_angle.h:435
static constexpr EDA_ANGLE ANGLE_360
Definition: eda_angle.h:441
#define PCB_EDIT_FRAME_NAME
INSPECT_RESULT
Definition: eda_item.h:43
const INSPECTOR_FUNC & INSPECTOR
Definition: eda_item.h:81
#define ENDPOINT
ends. (Used to support dragging.)
std::uint32_t EDA_ITEM_FLAGS
#define STARTPOINT
When a line is selected, these flags indicate which.
static std::vector< KICAD_T > connectedTypes
ERROR_LOC
When approximating an arc or circle, should the error be placed on the outside or inside of the curve...
bool ClipLine(const BOX2I *aClipBox, int &x1, int &y1, int &x2, int &y2)
Test if any part of a line falls within the bounds of a rectangle.
@ LAYER_VIA_NETNAMES
Definition: layer_ids.h:170
constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START
Definition: layer_ids.h:140
FLASHING
Enum used during connectivity building to ensure we do not query connectivity while building the data...
Definition: layer_ids.h:149
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
Definition: layer_ids.h:1022
bool IsCopperLayer(int aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:881
@ LAYER_LOCKED_ITEM_SHADOW
shadow layer for locked items
Definition: layer_ids.h:243
@ LAYER_VIA_HOLEWALLS
Definition: layer_ids.h:238
@ LAYER_GP_OVERLAY
general purpose overlay
Definition: layer_ids.h:222
@ LAYER_TRACKS
Definition: layer_ids.h:216
@ LAYER_VIA_HOLES
to draw via holes (pad holes do not use this layer)
Definition: layer_ids.h:219
@ LAYER_VIA_MICROVIA
to draw micro vias
Definition: layer_ids.h:198
@ LAYER_VIA_THROUGH
to draw usual through hole vias
Definition: layer_ids.h:200
@ LAYER_VIAS
Meta control for all vias opacity/visibility.
Definition: layer_ids.h:197
@ LAYER_VIA_BBLIND
to draw blind/buried vias
Definition: layer_ids.h:199
bool IsNetnameLayer(int aLayer)
Test whether a layer is a netname layer.
Definition: layer_ids.h:1045
bool IsHoleLayer(int aLayer)
Definition: layer_ids.h:920
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Mask
Definition: layer_ids.h:106
@ B_Cu
Definition: layer_ids.h:95
@ F_Mask
Definition: layer_ids.h:107
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ F_Cu
Definition: layer_ids.h:64
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:1022
PCB_LAYER_ID FlipLayer(PCB_LAYER_ID aLayerId, int aCopperLayersCount)
Definition: lset.cpp:634
void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition: mirror.h:40
void PackLayerSet(google::protobuf::RepeatedField< int > &aOutput, const LSET &aLayerSet)
void PackVector2(kiapi::common::types::Vector2 &aOutput, const VECTOR2I aInput)
Definition: api_utils.cpp:69
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:424
static struct TRACK_VIA_DESC _TRACK_VIA_DESC
VIATYPE
Definition: pcb_track.h:65
#define TYPE_HASH(x)
Definition: property.h:71
#define ENUM_TO_WXANY(type)
Macro to define read-only fields (no setter method available)
Definition: property.h:765
#define REGISTER_TYPE(x)
Definition: property_mgr.h:371
wxString UnescapeString(const wxString &aSource)
constexpr int mmToIU(double mm) const
Definition: base_units.h:88
PCB_LAYER_ID start
Definition: padstack.h:222
PCB_LAYER_ID end
Definition: padstack.h:223
VECTOR2I size
Drill diameter (x == y) or slot dimensions (x != y)
Definition: padstack.h:220
bool operator()(const PCB_TRACK *aFirst, const PCB_TRACK *aSecond) const
Definition: pcb_track.cpp:1585
bool TestSegmentHit(const VECTOR2I &aRefPoint, const VECTOR2I &aStart, const VECTOR2I &aEnd, int aDist)
Test if aRefPoint is with aDistance on the line defined by aStart and aEnd.
Definition: trigo.cpp:174
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:228
const VECTOR2I CalcArcCenter(const VECTOR2I &aStart, const VECTOR2I &aMid, const VECTOR2I &aEnd)
Determine the center of an arc or circle given three points on its circumference.
Definition: trigo.cpp:520
double GetLineLength(const VECTOR2I &aPointA, const VECTOR2I &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:194
double EuclideanNorm(const VECTOR2I &vector)
Definition: trigo.h:128
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118
VECTOR2< long long int > VECTOR2L
Definition: vector2d.h:603
VECTOR2< int > VECTOR2I
Definition: vector2d.h:602