KiCad PCB EDA Suite
pns_kicad_iface.cpp
Go to the documentation of this file.
1 /*
2  * KiRouter - a push-and-(sometimes-)shove PCB router
3  *
4  * Copyright (C) 2013-2016 CERN
5  * Copyright (C) 2016-2020 KiCad Developers, see AUTHORS.txt for contributors.
6  * Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  *
8  * This program is free software: you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation, either version 3 of the License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <undo_redo_container.h>
23 #include <class_board.h>
24 #include <board_connected_item.h>
25 #include <fp_text.h>
26 #include <class_module.h>
27 #include <class_track.h>
28 #include <class_zone.h>
29 #include <pcb_shape.h>
30 #include <pcb_text.h>
31 #include <board_commit.h>
33 #include <geometry/convex_hull.h>
34 #include <confirm.h>
35 
36 #include <view/view.h>
37 #include <view/view_item.h>
38 #include <view/view_group.h>
39 
40 #include <pcb_painter.h>
41 
42 #include <geometry/shape.h>
44 #include <geometry/shape_arc.h>
45 #include <geometry/shape_simple.h>
46 
47 #include <drc/drc_rule.h>
48 #include <drc/drc_engine.h>
49 
50 #include <memory>
51 
52 #include <advanced_config.h>
53 
54 #include "tools/pcb_tool_base.h"
55 
56 #include "pns_kicad_iface.h"
57 
58 #include "pns_arc.h"
59 #include "pns_routing_settings.h"
60 #include "pns_sizes_settings.h"
61 #include "pns_item.h"
62 #include "pns_solid.h"
63 #include "pns_segment.h"
64 #include "pns_node.h"
65 #include "pns_router.h"
66 #include "pns_debug_decorator.h"
67 #include "router_preview_item.h"
68 
70 
72 {
73 public:
74  PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER_IFACE* aRouterIface );
75  virtual ~PNS_PCBNEW_RULE_RESOLVER();
76 
77  virtual bool CollideHoles( const PNS::ITEM* aA, const PNS::ITEM* aB,
78  bool aNeedMTV, VECTOR2I* aMTV ) const override;
79 
80  virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) override;
81  virtual int DpCoupledNet( int aNet ) override;
82  virtual int DpNetPolarity( int aNet ) override;
83  virtual bool DpNetPair( const PNS::ITEM* aItem, int& aNetP, int& aNetN ) override;
84  virtual bool IsDiffPair( const PNS::ITEM* aA, const PNS::ITEM* aB ) override;
85 
86  virtual bool QueryConstraint( PNS::CONSTRAINT_TYPE aType, const PNS::ITEM* aItemA, const PNS::ITEM* aItemB, int aLayer, PNS::CONSTRAINT* aConstraint ) override;
87  virtual wxString NetName( int aNet ) override;
88 
89 private:
91  {
94  int clearance;
95  };
96 
97  int holeRadius( const PNS::ITEM* aItem ) const;
98  int matchDpSuffix( const wxString& aNetName, wxString& aComplementNet, wxString& aBaseDpName );
99 
102 };
103 
104 
106  m_routerIface( aRouterIface ),
107  m_board( aBoard )
108 {
109 }
110 
111 
113 {
114 }
115 
116 
118 {
119  if( aItem->Kind() == PNS::ITEM::SOLID_T )
120  {
121  const D_PAD* pad = dynamic_cast<const D_PAD*>( aItem->Parent() );
122 
123  if( pad && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
124  return pad->GetDrillSize().x / 2;
125  }
126  else if( aItem->Kind() == PNS::ITEM::VIA_T )
127  {
128  const ::VIA* via = dynamic_cast<const ::VIA*>( aItem->Parent() );
129 
130  if( via )
131  return via->GetDrillValue() / 2;
132  }
133 
134  return 0;
135 }
136 
137 
139  bool aNeedMTV, VECTOR2I* aMTV ) const
140 {
141  VECTOR2I pos_a = aA->Shape()->Centre();
142  VECTOR2I pos_b = aB->Shape()->Centre();
143 
144  // Holes with identical locations are allowable
145  if( pos_a == pos_b )
146  return false;
147 
148  int radius_a = holeRadius( aA );
149  int radius_b = holeRadius( aB );
150 
151  // Do both objects have holes?
152  if( radius_a > 0 && radius_b > 0 )
153  {
154  int holeToHoleMin = m_board->GetDesignSettings().m_HoleToHoleMin;
155 
156  ecoord min_dist = holeToHoleMin + radius_a + radius_b;
157  ecoord min_dist_sq = min_dist * min_dist;
158 
159  const VECTOR2I delta = pos_b - pos_a;
160 
161  ecoord dist_sq = delta.SquaredEuclideanNorm();
162 
163  if( dist_sq == 0 || dist_sq < min_dist_sq )
164  {
165  if( aNeedMTV )
166  *aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
167 
168  return true;
169  }
170  }
171 
172  return false;
173 }
174 
175 
177 {
178  int net_p, net_n;
179 
180  if( !DpNetPair( aA, net_p, net_n ) )
181  return false;
182 
183  if( aA->Net() == net_p && aB->Net() == net_n )
184  return true;
185  if( aB->Net() == net_p && aA->Net() == net_n )
186  return true;
187 
188  return false;
189 }
190 
191 
192 
194  const PNS::ITEM* aItemA, const PNS::ITEM* aItemB,
195  int aLayer, PNS::CONSTRAINT* aConstraint )
196 {
197  std::shared_ptr<DRC_ENGINE> drcEngine = m_board->GetDesignSettings().m_DRCEngine;
198 
199  if( !drcEngine )
200  return false;
201 
202  DRC_CONSTRAINT_TYPE_T hostRuleType;
203 
204  switch ( aType )
205  {
207  hostRuleType = DRC_CONSTRAINT_TYPE_CLEARANCE;
208  break;
210  hostRuleType = DRC_CONSTRAINT_TYPE_TRACK_WIDTH;
211  break;
213  hostRuleType = DRC_CONSTRAINT_TYPE_DIFF_PAIR_GAP;
214  break;
216  hostRuleType = DRC_CONSTRAINT_TYPE_LENGTH;
217  break;
219  hostRuleType = DRC_CONSTRAINT_TYPE_VIA_DIAMETER;
220  break;
222  hostRuleType = DRC_CONSTRAINT_TYPE_HOLE_SIZE;
223  break;
224  default:
225  return false; // should not happen
226  }
227 
228  // A track being routed may not have a BOARD_ITEM associated yet.
229  static TRACK dummyTrack( m_board );
230  static ARC dummyArc( m_board );
231  static VIA dummyVia( m_board );
232 
233  const BOARD_ITEM* parentA = aItemA ? aItemA->Parent() : nullptr;
234  const BOARD_ITEM* parentB = aItemB ? aItemB->Parent() : nullptr;
235  DRC_CONSTRAINT hostConstraint;
236 
237  if( !parentA )
238  {
239  switch( aItemA->Kind() )
240  {
241  case PNS::ITEM::ARC_T:
242  dummyArc.SetLayer( (PCB_LAYER_ID) aLayer );
243  dummyArc.SetNetCode( aItemA->Net() );
244  parentA = &dummyArc;
245  break;
246  case PNS::ITEM::VIA_T:
247  dummyVia.SetLayer( (PCB_LAYER_ID) aLayer );
248  dummyVia.SetNetCode( aItemA->Net() );
249  parentA = &dummyVia;
250  break;
251  default:
252  dummyTrack.SetLayer( (PCB_LAYER_ID) aLayer );
253  dummyTrack.SetNetCode( aItemA->Net() );
254  parentA = &dummyTrack;
255  break;
256  }
257  }
258 
259  if( parentA )
260  {
261  hostConstraint = drcEngine->EvalRulesForItems( hostRuleType, parentA, parentB,
262  (PCB_LAYER_ID) aLayer );
263  }
264 
265  if( hostConstraint.IsNull() )
266  return false;
267 
268  switch ( aType )
269  {
275  aConstraint->m_Value = hostConstraint.GetValue();
276  aConstraint->m_RuleName = hostConstraint.GetName();
277  aConstraint->m_Type = aType;
278  return true;
279 
280  default:
281  return false;
282  }
283 }
284 
285 
287 {
288  PNS::CONSTRAINT constraint;
289  bool ok = false;
290  int rv = 0;
291 
292  if( aB && IsDiffPair( aA, aB ) )
293  {
294  // for diff pairs, we use the gap value for shoving/dragging
296  &constraint ) )
297  {
298  rv = constraint.m_Value.Opt();
299  ok = true;
300  }
301  }
302 
303  if( !ok )
304  {
306  &constraint ) )
307  {
308  rv = constraint.m_Value.Min();
309  ok = true;
310  }
311  }
312 
313  // still no valid clearance rule? fall back to global minimum.
314  if( !ok )
315  {
317  }
318 
319  return rv;
320 }
321 
322 
323 bool PNS_KICAD_IFACE_BASE::inheritTrackWidth( PNS::ITEM* aItem, int* aInheritedWidth )
324 {
325  VECTOR2I p;
326 
327  assert( aItem->Owner() != NULL );
328 
329  switch( aItem->Kind() )
330  {
331  case PNS::ITEM::VIA_T:
332  p = static_cast<PNS::VIA*>( aItem )->Pos();
333  break;
334 
335  case PNS::ITEM::SOLID_T:
336  p = static_cast<PNS::SOLID*>( aItem )->Pos();
337  break;
338 
340  *aInheritedWidth = static_cast<PNS::SEGMENT*>( aItem )->Width();
341  return true;
342 
343  default:
344  return false;
345  }
346 
347  PNS::JOINT* jt = static_cast<PNS::NODE*>( aItem->Owner() )->FindJoint( p, aItem );
348 
349  assert( jt != NULL );
350 
351  int mval = INT_MAX;
352 
353  PNS::ITEM_SET linkedSegs = jt->Links();
354  linkedSegs.ExcludeItem( aItem ).FilterKinds( PNS::ITEM::SEGMENT_T );
355 
356  for( PNS::ITEM* item : linkedSegs.Items() )
357  {
358  int w = static_cast<PNS::SEGMENT*>( item )->Width();
359  mval = std::min( w, mval );
360  }
361 
362  if( mval == INT_MAX )
363  return false;
364 
365  *aInheritedWidth = mval;
366  return true;
367 }
368 
369 
371 {
373  PNS::CONSTRAINT constraint;
374 
375  int trackWidth = bds.m_TrackMinWidth;
376  bool found = false;
377 
378  if( bds.m_UseConnectedTrackWidth && aStartItem != nullptr )
379  {
380  found = inheritTrackWidth( aStartItem, &trackWidth );
381  }
382 
383  if( !found && bds.UseNetClassTrack() && aStartItem )
384  {
386  aStartItem->Layer(), &constraint ) )
387  {
388  trackWidth = constraint.m_Value.OptThenMin();
389  found = true; // Note: allowed to override anything, including bds.m_TrackMinWidth
390  }
391  }
392 
393  if( !found )
394  {
395  trackWidth = bds.GetCurrentTrackWidth();
396  }
397 
398  aSizes.SetTrackWidth( trackWidth );
399 
400  int viaDiameter = bds.m_ViasMinSize;
401  int viaDrill = bds.m_MinThroughDrill;
402 
403  if( bds.UseNetClassVia() && aStartItem ) // netclass value
404  {
406  nullptr, aStartItem->Layer(), &constraint ) )
407  {
408  viaDiameter = constraint.m_Value.OptThenMin();
409  }
410 
412  nullptr, aStartItem->Layer(), &constraint ) )
413  {
414  viaDrill = constraint.m_Value.OptThenMin();
415  }
416  }
417  else
418  {
419  viaDiameter = bds.GetCurrentViaSize();
420  viaDrill = bds.GetCurrentViaDrill();
421  }
422 
423  aSizes.SetViaDiameter( viaDiameter );
424  aSizes.SetViaDrill( viaDrill );
425 
426  int diffPairWidth = bds.m_TrackMinWidth;
427  int diffPairGap = bds.m_MinClearance;
428  int diffPairViaGap = bds.m_MinClearance;
429 
430  if( bds.UseNetClassDiffPair() && aStartItem )
431  {
433  nullptr, aStartItem->Layer(), &constraint ) )
434  {
435  diffPairWidth = constraint.m_Value.OptThenMin();
436  }
437 
439  nullptr, aStartItem->Layer(), &constraint ) )
440  {
441  diffPairGap = constraint.m_Value.OptThenMin();
442  diffPairViaGap = constraint.m_Value.OptThenMin();
443  }
444  }
445  else if( bds.UseCustomDiffPairDimensions() )
446  {
447  diffPairWidth = bds.GetCustomDiffPairWidth();
448  diffPairGap = bds.GetCustomDiffPairGap();
449  diffPairViaGap = bds.GetCustomDiffPairViaGap();
450  }
451 
452  //printf( "DPWidth: %d gap %d\n", diffPairWidth, diffPairGap );
453 
454  aSizes.SetDiffPairWidth( diffPairWidth );
455  aSizes.SetDiffPairGap( diffPairGap );
456  aSizes.SetDiffPairViaGap( diffPairViaGap );
457 
458  aSizes.ClearLayerPairs();
459 
460  return true;
461 }
462 
463 
464 int PNS_PCBNEW_RULE_RESOLVER::matchDpSuffix( const wxString& aNetName, wxString& aComplementNet,
465  wxString& aBaseDpName )
466 {
467  int rv = 0;
468 
469  if( aNetName.EndsWith( "+" ) )
470  {
471  aComplementNet = "-";
472  rv = 1;
473  }
474  else if( aNetName.EndsWith( "P" ) )
475  {
476  aComplementNet = "N";
477  rv = 1;
478  }
479  else if( aNetName.EndsWith( "-" ) )
480  {
481  aComplementNet = "+";
482  rv = -1;
483  }
484  else if( aNetName.EndsWith( "N" ) )
485  {
486  aComplementNet = "P";
487  rv = -1;
488  }
489  // Match P followed by 2 digits
490  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
491  {
492  aComplementNet = "N" + aNetName.Right( 2 );
493  rv = 1;
494  }
495  // Match P followed by 1 digit
496  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
497  {
498  aComplementNet = "N" + aNetName.Right( 1 );
499  rv = 1;
500  }
501  // Match N followed by 2 digits
502  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
503  {
504  aComplementNet = "P" + aNetName.Right( 2 );
505  rv = -1;
506  }
507  // Match N followed by 1 digit
508  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
509  {
510  aComplementNet = "P" + aNetName.Right( 1 );
511  rv = -1;
512  }
513  if( rv != 0 )
514  {
515  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
516  aComplementNet = aBaseDpName + aComplementNet;
517  }
518 
519  return rv;
520 }
521 
522 
524 {
525  wxString refName = m_board->FindNet( aNet )->GetNetname();
526  wxString dummy, coupledNetName;
527 
528  if( matchDpSuffix( refName, coupledNetName, dummy ) )
529  {
530  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
531 
532  if( !net )
533  return -1;
534 
535  return net->GetNet();
536  }
537 
538  return -1;
539 }
540 
541 
543 {
544  return m_board->FindNet( aNet )->GetNetname();
545 }
546 
547 
549 {
550  wxString refName = m_board->FindNet( aNet )->GetNetname();
551  wxString dummy1, dummy2;
552 
553  return matchDpSuffix( refName, dummy1, dummy2 );
554 }
555 
556 
557 bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( const PNS::ITEM* aItem, int& aNetP, int& aNetN )
558 {
559  if( !aItem || !aItem->Parent() || !aItem->Parent()->IsConnected() )
560  return false;
561 
562  BOARD_CONNECTED_ITEM* cItem = static_cast<BOARD_CONNECTED_ITEM*>( aItem->Parent() );
563  NETINFO_ITEM* netInfo = cItem->GetNet();
564 
565  if( !netInfo )
566  return false;
567 
568  wxString netNameP = netInfo->GetNetname();
569  wxString netNameN, netNameCoupled, netNameBase;
570 
571  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
572 
573  if( r == 0 )
574  {
575  return false;
576  }
577  else if( r == 1 )
578  {
579  netNameN = netNameCoupled;
580  }
581  else
582  {
583  netNameN = netNameP;
584  netNameP = netNameCoupled;
585  }
586 
587 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
588 
589  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
590  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
591 
592  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
593 
594  if( !netInfoP || !netInfoN )
595  return false;
596 
597  aNetP = netInfoP->GetNet();
598  aNetN = netInfoN->GetNet();
599 
600  return true;
601 }
602 
603 
605 {
606 public:
608  m_view( NULL ), m_items( NULL )
609  {
610  SetView( aView );
611  }
612 
614  {
615  Clear();
616  delete m_items;
617  }
618 
619  void SetView( KIGFX::VIEW* aView )
620  {
621  Clear();
622  delete m_items;
623  m_items = NULL;
624  m_view = aView;
625 
626  if( m_view == NULL )
627  return;
628 
631  m_view->Add( m_items );
632  }
633 
634  void AddPoint( VECTOR2I aP, int aColor, const std::string aName = "") override
635  {
637 
638  l.Append( aP - VECTOR2I( -50000, -50000 ) );
639  l.Append( aP + VECTOR2I( -50000, -50000 ) );
640 
641  AddLine( l, aColor, 10000 );
642 
643  l.Clear();
644  l.Append( aP - VECTOR2I( 50000, -50000 ) );
645  l.Append( aP + VECTOR2I( 50000, -50000 ) );
646 
647  AddLine( l, aColor, 10000 );
648  }
649 
650  void AddBox( BOX2I aB, int aColor, const std::string aName = "" ) override
651  {
653 
654  VECTOR2I o = aB.GetOrigin();
655  VECTOR2I s = aB.GetSize();
656 
657  l.Append( o );
658  l.Append( o.x + s.x, o.y );
659  l.Append( o.x + s.x, o.y + s.y );
660  l.Append( o.x, o.y + s.y );
661  l.Append( o );
662 
663  AddLine( l, aColor, 10000 );
664  }
665 
666  void AddSegment( SEG aS, int aColor, const std::string aName = "") override
667  {
669 
670  l.Append( aS.A );
671  l.Append( aS.B );
672 
673  AddLine( l, aColor, 10000 );
674  }
675 
676  void AddDirections( VECTOR2D aP, int aMask, int aColor, const std::string aName = "") override
677  {
678  BOX2I b( aP - VECTOR2I( 10000, 10000 ), VECTOR2I( 20000, 20000 ) );
679 
680  AddBox( b, aColor );
681  for( int i = 0; i < 8; i++ )
682  {
683  if( ( 1 << i ) & aMask )
684  {
685  VECTOR2I v = DIRECTION_45( ( DIRECTION_45::Directions ) i ).ToVector() * 100000;
686  AddSegment( SEG( aP, aP + v ), aColor );
687  }
688  }
689  }
690 
691  void AddLine( const SHAPE_LINE_CHAIN& aLine, int aType, int aWidth, const std::string aName = "" ) override
692  {
693  if( !m_view )
694  return;
695 
697 
698  pitem->Line( aLine, aWidth, aType );
699  m_items->Add( pitem ); // Should not be needed, as m_items has been passed as a parent group in alloc;
700  m_view->Update( m_items );
701  }
702 
703  void Clear() override
704  {
705  if( m_view && m_items )
706  {
707  m_items->FreeItems();
708  m_view->Update( m_items );
709  }
710  }
711 
712 private:
715 };
716 
717 
719 {
720  return m_debugDecorator;
721 }
722 
723 
725 {
726  m_ruleResolver = nullptr;
727  m_board = nullptr;
728  m_world = nullptr;
729  m_debugDecorator = nullptr;
730 }
731 
732 
734 {
735  m_tool = nullptr;
736  m_view = nullptr;
737  m_previewItems = nullptr;
738  m_dispOptions = nullptr;
739 }
740 
741 
743 {
744 }
745 
746 
748 {
749  delete m_ruleResolver;
750  delete m_debugDecorator;
751 
752  if( m_previewItems )
753  {
755  delete m_previewItems;
756  }
757 }
758 
759 
760 std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( D_PAD* aPad )
761 {
762  LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 );
763 
764  // ignore non-copper pads except for those with holes
765  if( ( aPad->GetLayerSet() & LSET::AllCuMask() ).none() && aPad->GetDrillSize().x == 0 )
766  return NULL;
767 
768  switch( aPad->GetAttribute() )
769  {
770  case PAD_ATTRIB_PTH:
771  case PAD_ATTRIB_NPTH:
772  break;
773 
774  case PAD_ATTRIB_CONN:
775  case PAD_ATTRIB_SMD:
776  {
777  LSET lmsk = aPad->GetLayerSet();
778  bool is_copper = false;
779 
780  for( int i = 0; i < MAX_CU_LAYERS; i++ )
781  {
782  if( lmsk[i] )
783  {
784  is_copper = true;
785 
786  if( aPad->GetAttribute() != PAD_ATTRIB_NPTH )
787  layers = LAYER_RANGE( i );
788 
789  break;
790  }
791  }
792 
793  if( !is_copper )
794  return NULL;
795  }
796  break;
797 
798  default:
799  wxLogTrace( "PNS", "unsupported pad type 0x%x", aPad->GetAttribute() );
800  return NULL;
801  }
802 
803  std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
804 
805  if( aPad->GetDrillSize().x > 0 )
806  {
808 
809  if( aPad->GetAttribute() != PAD_ATTRIB_NPTH )
810  {
812  slot->SetWidth( slot->GetWidth() + bds.GetHolePlatingThickness() * 2 );
813  }
814 
815  solid->SetAlternateShape( slot );
816  }
817 
818  if( aPad->GetAttribute() == PAD_ATTRIB_NPTH )
819  solid->SetRoutable( false );
820 
821  solid->SetLayers( layers );
822  solid->SetNet( aPad->GetNetCode() );
823  solid->SetParent( aPad );
824  solid->SetPadToDie( aPad->GetPadToDieLength() );
825 
826  wxPoint wx_c = aPad->ShapePos();
827  wxPoint offset = aPad->GetOffset();
828 
829  VECTOR2I c( wx_c.x, wx_c.y );
830 
831  RotatePoint( &offset, aPad->GetOrientation() );
832 
833  solid->SetPos( VECTOR2I( c.x - offset.x, c.y - offset.y ) );
834  solid->SetOffset( VECTOR2I( offset.x, offset.y ) );
835 
836 
837  auto shapes = std::dynamic_pointer_cast<SHAPE_COMPOUND>( aPad->GetEffectiveShape() );
838 
839  if( shapes && shapes->Size() == 1 )
840  {
841  solid->SetShape( shapes->Clone() );
842  }
843  else
844  {
845  // Fixme (but not urgent). For complex pad shapes, we pass a single simple polygon to the
846  // router, otherwise it won't know how to correctly build walkaround 'hulls' for the pad
847  // primitives - it can recognize only simple shapes, but not COMPOUNDs made of multiple shapes.
848  // The proper way to fix this would be to implement SHAPE_COMPOUND::ConvertToSimplePolygon(),
849  // but the complexity of pad polygonization code (see D_PAD::GetEffectivePolygon), including approximation
850  // error handling makes me slightly scared to do it right now.
851 
852  const std::shared_ptr<SHAPE_POLY_SET>& outline = aPad->GetEffectivePolygon();
853  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
854 
855  for( auto iter = outline->CIterate( 0 ); iter; iter++ )
856  shape->Append( *iter );
857 
858  solid->SetShape( shape );
859  }
860 
861  return solid;
862 }
863 
864 
865 std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( TRACK* aTrack )
866 {
867  auto segment = std::make_unique<PNS::SEGMENT>( SEG( aTrack->GetStart(), aTrack->GetEnd() ),
868  aTrack->GetNetCode() );
869 
870  segment->SetWidth( aTrack->GetWidth() );
871  segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) );
872  segment->SetParent( aTrack );
873 
874  if( aTrack->IsLocked() )
875  segment->Mark( PNS::MK_LOCKED );
876 
877  return segment;
878 }
879 
880 
881 std::unique_ptr<PNS::ARC> PNS_KICAD_IFACE_BASE::syncArc( ARC* aArc )
882 {
883  auto arc = std::make_unique<PNS::ARC>( SHAPE_ARC( aArc->GetStart(), aArc->GetMid(), aArc->GetEnd(),
884  aArc->GetWidth() ),
885  aArc->GetNetCode() );
886 
887  arc->SetLayers( LAYER_RANGE( aArc->GetLayer() ) );
888  arc->SetParent( aArc );
889 
890  if( aArc->IsLocked() )
891  arc->Mark( PNS::MK_LOCKED );
892 
893  return arc;
894 }
895 
896 
897 std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE_BASE::syncVia( VIA* aVia )
898 {
899  std::vector<std::unique_ptr<PNS::VIA>> retval;
900 
901  PCB_LAYER_ID top, bottom;
902  aVia->LayerPair( &top, &bottom );
903 
904  auto via = std::make_unique<PNS::VIA>( aVia->GetPosition(),
905  LAYER_RANGE( aVia->TopLayer(), aVia->BottomLayer() ),
906  aVia->GetWidth(),
907  aVia->GetDrillValue(),
908  aVia->GetNetCode(),
909  aVia->GetViaType() );
910 
911  via->SetParent( aVia );
912 
913  if( aVia->IsLocked() )
914  via->Mark( PNS::MK_LOCKED );
915 
916  return std::move( via );
917 }
918 
919 
921  SHAPE_POLY_SET* aBoardOutline )
922 {
923  SHAPE_POLY_SET poly;
924 
925  // TODO handle no-via restriction
926  if( !aZone->GetIsRuleArea() || !aZone->GetDoNotAllowTracks() )
927  return false;
928 
929  LSET layers = aZone->GetLayerSet();
930  EDA_UNITS units = EDA_UNITS::MILLIMETRES; // TODO: get real units
931 
932  for( int layer = F_Cu; layer <= B_Cu; layer++ )
933  {
934  if( ! layers[ layer ] )
935  continue;
936 
937  aZone->BuildSmoothedPoly( poly, ToLAYER_ID( layer ), aBoardOutline );
938  poly.CacheTriangulation();
939 
940  if( !poly.IsTriangulationUpToDate() )
941  {
942  KIDIALOG dlg( nullptr, wxString::Format( _( "%s is malformed." ),
943  aZone->GetSelectMenuText( units ) ),
945  dlg.ShowDetailedText( wxString::Format( _( "This zone cannot be handled by the track "
946  "layout tool.\n"
947  "Please verify it is not a "
948  "self-intersecting polygon." ) ) );
949  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
950  dlg.ShowModal();
951 
952  return false;
953  }
954 
955  for( int outline = 0; outline < poly.OutlineCount(); outline++ )
956  {
957  const SHAPE_POLY_SET::TRIANGULATED_POLYGON* tri = poly.TriangulatedPolygon( outline );
958 
959  for( size_t i = 0; i < tri->GetTriangleCount(); i++)
960  {
961  VECTOR2I a, b, c;
962  tri->GetTriangle( i, a, b, c );
963  SHAPE_SIMPLE* triShape = new SHAPE_SIMPLE;
964 
965  triShape->Append( a );
966  triShape->Append( b );
967  triShape->Append( c );
968 
969  std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
970 
971  solid->SetLayer( layer );
972  solid->SetNet( -1 );
973  solid->SetParent( aZone );
974  solid->SetShape( triShape );
975  solid->SetRoutable( false );
976 
977  aWorld->Add( std::move( solid ) );
978  }
979  }
980  }
981 
982  return true;
983 }
984 
985 
987 {
988  if( !IsCopperLayer( aLayer ) )
989  return false;
990 
991  int textWidth = aText->GetEffectiveTextPenWidth();
992  std::vector<wxPoint> textShape;
993 
994  aText->TransformTextShapeToSegmentList( textShape );
995 
996  if( textShape.size() < 2 )
997  return false;
998 
999  for( size_t jj = 0; jj < textShape.size(); jj += 2 )
1000  {
1001  VECTOR2I start( textShape[jj] );
1002  VECTOR2I end( textShape[jj+1] );
1003  std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
1004 
1005  solid->SetLayer( aLayer );
1006  solid->SetNet( -1 );
1007  solid->SetParent( dynamic_cast<BOARD_ITEM*>( aText ) );
1008  solid->SetShape( new SHAPE_SEGMENT( start, end, textWidth ) );
1009  solid->SetRoutable( false );
1010 
1011  aWorld->Add( std::move( solid ) );
1012  }
1013 
1014  return true;
1015 
1016  /* A coarser (but faster) method:
1017  *
1018  SHAPE_POLY_SET outline;
1019  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
1020 
1021  aText->TransformBoundingBoxWithClearanceToPolygon( &outline, 0 );
1022 
1023  for( auto iter = outline.CIterate( 0 ); iter; iter++ )
1024  shape->Append( *iter );
1025 
1026  solid->SetShape( shape );
1027 
1028  solid->SetLayer( aLayer );
1029  solid->SetNet( -1 );
1030  solid->SetParent( nullptr );
1031  solid->SetRoutable( false );
1032  aWorld->Add( std::move( solid ) );
1033  return true;
1034  */
1035 }
1036 
1037 
1039 {
1040  if( aItem->GetLayer() != Edge_Cuts && !IsCopperLayer( aItem->GetLayer() ) )
1041  return false;
1042 
1043  // TODO: where do we handle filled polygons on copper layers?
1044  if( aItem->GetShape() == S_POLYGON && aItem->IsPolygonFilled() )
1045  return false;
1046 
1047  for( SHAPE* shape : aItem->MakeEffectiveShapes() )
1048  {
1049  std::unique_ptr<PNS::SOLID> solid = std::make_unique<PNS::SOLID>();
1050 
1051  if( aItem->GetLayer() == Edge_Cuts )
1052  solid->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
1053  else
1054  solid->SetLayer( aItem->GetLayer() );
1055 
1056  solid->SetNet( -1 );
1057  solid->SetParent( aItem );
1058  solid->SetShape( shape );
1059  solid->SetRoutable( false );
1060 
1061  aWorld->Add( std::move( solid ) );
1062  }
1063 
1064  return true;
1065 }
1066 
1067 
1069 {
1070  m_board = aBoard;
1071  wxLogTrace( "PNS", "m_board = %p", m_board );
1072 }
1073 
1074 
1076 {
1077  if( !m_view )
1078  return false;
1079 
1080  for( int i = aLayer.Start(); i <= aLayer.End(); i++ )
1081  if( m_view->IsLayerVisible( i ) )
1082  return true;
1083 
1084  return false;
1085 }
1086 
1087 
1088 bool PNS_KICAD_IFACE::IsOnLayer( const PNS::ITEM* aItem, int aLayer ) const
1089 {
1091  if( aLayer < 0 )
1092  return true;
1093 
1094  if( aItem->Parent() )
1095  {
1096  switch( aItem->Parent()->Type() )
1097  {
1098  case PCB_VIA_T:
1099  {
1100  const VIA* via = static_cast<const VIA*>( aItem->Parent() );
1101 
1102  return via->FlashLayer( static_cast<PCB_LAYER_ID>( aLayer ));
1103  }
1104 
1105  case PCB_PAD_T:
1106  {
1107  const D_PAD* pad = static_cast<const D_PAD*>( aItem->Parent() );
1108 
1109  return pad->FlashLayer( static_cast<PCB_LAYER_ID>( aLayer ));
1110  }
1111 
1112  default:
1113  break;
1114  }
1115  }
1116 
1117  return aItem->Layers().Overlaps( aLayer );
1118 }
1119 
1120 
1121 bool PNS_KICAD_IFACE::IsItemVisible( const PNS::ITEM* aItem ) const
1122 {
1123  // by default, all items are visible (new ones created by the router have parent == NULL
1124  // as they have not been committed yet to the BOARD)
1125  if( !m_view || !aItem->Parent() )
1126  return true;
1127 
1128  BOARD_ITEM* item = aItem->Parent();
1129  bool isOnVisibleLayer = true;
1130 
1132  {
1133  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
1134  int layers_count;
1135  auto activeLayers = m_view->GetPainter()->GetSettings()->GetHighContrastLayers();
1136 
1137  isOnVisibleLayer = false;
1138  item->ViewGetLayers( layers, layers_count );
1139 
1140  for( int i = 0; i < layers_count; ++i )
1141  {
1142  // Item is on at least one of the active layers
1143  if( activeLayers.count( layers[i] ) > 0 )
1144  {
1145  isOnVisibleLayer = true;
1146  break;
1147  }
1148  }
1149  }
1150 
1151  if( m_view->IsVisible( item ) && isOnVisibleLayer
1152  && item->ViewGetLOD( item->GetLayer(), m_view ) < m_view->GetScale() )
1153  return true;
1154 
1155  // Items hidden in the router are not hidden on the board
1156  if( m_hiddenItems.find( item ) != m_hiddenItems.end() )
1157  return true;
1158 
1159  return false;
1160 }
1161 
1162 
1164 {
1165  int worstPadClearance = 0;
1166 
1167  m_world = aWorld;
1168 
1169  if( !m_board )
1170  {
1171  wxLogTrace( "PNS", "No board attached, aborting sync." );
1172  return;
1173  }
1174 
1175  for( BOARD_ITEM* gitem : m_board->Drawings() )
1176  {
1177  if ( gitem->Type() == PCB_SHAPE_T )
1178  {
1179  syncGraphicalItem( aWorld, static_cast<PCB_SHAPE*>( gitem ) );
1180  }
1181  else if( gitem->Type() == PCB_TEXT_T )
1182  {
1183  syncTextItem( aWorld, static_cast<PCB_TEXT*>( gitem ), gitem->GetLayer() );
1184  }
1185  }
1186 
1187  SHAPE_POLY_SET buffer;
1188  SHAPE_POLY_SET* boardOutline = nullptr;
1189 
1190  if( m_board->GetBoardPolygonOutlines( buffer ) )
1191  boardOutline = &buffer;
1192 
1193  for( ZONE_CONTAINER* zone : m_board->Zones() )
1194  {
1195  syncZone( aWorld, zone, boardOutline );
1196  }
1197 
1198  for( MODULE* module : m_board->Modules() )
1199  {
1200  for( D_PAD* pad : module->Pads() )
1201  {
1202  if( std::unique_ptr<PNS::SOLID> solid = syncPad( pad ) )
1203  aWorld->Add( std::move( solid ) );
1204 
1205  worstPadClearance = std::max( worstPadClearance, pad->GetLocalClearance() );
1206  }
1207 
1208  syncTextItem( aWorld, &module->Reference(), module->Reference().GetLayer() );
1209  syncTextItem( aWorld, &module->Value(), module->Value().GetLayer() );
1210 
1211  for( MODULE_ZONE_CONTAINER* zone : module->Zones() )
1212  syncZone( aWorld, zone, boardOutline );
1213 
1214  if( module->IsNetTie() )
1215  continue;
1216 
1217  for( BOARD_ITEM* mgitem : module->GraphicalItems() )
1218  {
1219  if( mgitem->Type() == PCB_FP_SHAPE_T )
1220  {
1221  syncGraphicalItem( aWorld, static_cast<PCB_SHAPE*>( mgitem ) );
1222  }
1223  else if( mgitem->Type() == PCB_FP_TEXT_T )
1224  {
1225  syncTextItem( aWorld, static_cast<FP_TEXT*>( mgitem ), mgitem->GetLayer() );
1226  }
1227  }
1228  }
1229 
1230  for( TRACK* t : m_board->Tracks() )
1231  {
1232  KICAD_T type = t->Type();
1233 
1234  if( type == PCB_TRACE_T )
1235  {
1236  if( auto segment = syncTrack( t ) )
1237  aWorld->Add( std::move( segment ) );
1238  }
1239  else if( type == PCB_ARC_T )
1240  {
1241  if( auto arc = syncArc( static_cast<ARC*>( t ) ) )
1242  aWorld->Add( std::move( arc ) );
1243  }
1244  else if( type == PCB_VIA_T )
1245  {
1246  if( auto via = syncVia( static_cast<VIA*>( t ) ) )
1247  aWorld->Add( std::move( via ) );
1248  }
1249  }
1250 
1251  int worstRuleClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
1252 
1253  delete m_ruleResolver;
1255 
1256  aWorld->SetRuleResolver( m_ruleResolver );
1257  aWorld->SetMaxClearance( 4 * std::max(worstPadClearance, worstRuleClearance ) );
1258 }
1259 
1260 
1262 {
1263  for( auto item : m_hiddenItems )
1264  m_view->SetVisible( item, true );
1265 
1266  m_hiddenItems.clear();
1267 
1268  if( m_previewItems )
1269  {
1272  }
1273 
1274  if( m_debugDecorator )
1276 }
1277 
1279 {
1280  m_debugDecorator = aDec;
1281 }
1282 
1283 void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aColor, int aClearance, bool aEdit )
1284 {
1285  wxLogTrace( "PNS", "DisplayItem %p", aItem );
1286 
1287  ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view );
1288 
1289  if( aColor >= 0 )
1290  pitem->SetColor( KIGFX::COLOR4D( aColor ) );
1291 
1292  if( aClearance >= 0 )
1293  {
1294  pitem->SetClearance( aClearance );
1295 
1297  {
1299  pitem->ShowTrackClearance( false );
1300  pitem->ShowViaClearance( false );
1301  break;
1304  pitem->ShowTrackClearance( true );
1305  pitem->ShowViaClearance( true );
1306  break;
1307 
1309  pitem->ShowTrackClearance( !aEdit );
1310  pitem->ShowViaClearance( !aEdit );
1311  break;
1312 
1314  pitem->ShowTrackClearance( !aEdit );
1315  pitem->ShowViaClearance( false );
1316  break;
1317  }
1318  }
1319 
1320 
1321  m_previewItems->Add( pitem );
1323 }
1324 
1325 
1326 void PNS_KICAD_IFACE::DisplayRatline( const SHAPE_LINE_CHAIN& aRatline, int aColor )
1327 {
1328  ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( nullptr, m_view );
1329  pitem->Line( aRatline, 10000, aColor );
1330  m_previewItems->Add( pitem );
1332 }
1333 
1334 
1336 {
1337  BOARD_ITEM* parent = aItem->Parent();
1338 
1339  if( parent )
1340  {
1341  if( m_view->IsVisible( parent ) )
1342  m_hiddenItems.insert( parent );
1343 
1344  m_view->SetVisible( parent, false );
1345  m_view->Update( parent, KIGFX::APPEARANCE );
1346  }
1347 }
1348 
1349 
1351 {
1352 
1353 }
1354 
1355 
1357 {
1358  BOARD_ITEM* parent = aItem->Parent();
1359 
1360  if ( aItem->OfKind(PNS::ITEM::SOLID_T) )
1361  {
1362  D_PAD* pad = static_cast<D_PAD*>( parent );
1363  VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1364 
1365  m_moduleOffsets[ pad ].p_old = pos;
1366  return;
1367  }
1368 
1369  if( parent )
1370  {
1371  m_commit->Remove( parent );
1372  }
1373 }
1374 
1375 
1377 {
1378 
1379 }
1380 
1381 
1383 {
1384  BOARD_CONNECTED_ITEM* newBI = NULL;
1385 
1386  switch( aItem->Kind() )
1387  {
1388  case PNS::ITEM::ARC_T:
1389  {
1390  auto arc = static_cast<PNS::ARC*>( aItem );
1391  ARC* new_arc = new ARC( m_board, static_cast<const SHAPE_ARC*>( arc->Shape() ) );
1392  new_arc->SetWidth( arc->Width() );
1393  new_arc->SetLayer( ToLAYER_ID( arc->Layers().Start() ) );
1394  new_arc->SetNetCode( std::max<int>( 0, arc->Net() ) );
1395  newBI = new_arc;
1396  break;
1397  }
1398 
1399  case PNS::ITEM::SEGMENT_T:
1400  {
1401  PNS::SEGMENT* seg = static_cast<PNS::SEGMENT*>( aItem );
1402  TRACK* track = new TRACK( m_board );
1403  const SEG& s = seg->Seg();
1404  track->SetStart( wxPoint( s.A.x, s.A.y ) );
1405  track->SetEnd( wxPoint( s.B.x, s.B.y ) );
1406  track->SetWidth( seg->Width() );
1407  track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) );
1408  track->SetNetCode( seg->Net() > 0 ? seg->Net() : 0 );
1409  newBI = track;
1410  break;
1411  }
1412 
1413  case PNS::ITEM::VIA_T:
1414  {
1415  VIA* via_board = new VIA( m_board );
1416  PNS::VIA* via = static_cast<PNS::VIA*>( aItem );
1417  via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
1418  via_board->SetWidth( via->Diameter() );
1419  via_board->SetDrill( via->Drill() );
1420  via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
1421  via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
1422  via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
1423  ToLAYER_ID( via->Layers().End() ) );
1424  newBI = via_board;
1425  break;
1426  }
1427 
1428  case PNS::ITEM::SOLID_T:
1429  {
1430  D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
1431  VECTOR2I pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1432 
1433  m_moduleOffsets[ pad ].p_new = pos;
1434  return;
1435  }
1436 
1437  default:
1438  break;
1439  }
1440 
1441  if( newBI )
1442  {
1443  //newBI->SetLocalRatsnestVisible( m_dispOptions->m_ShowGlobalRatsnest );
1444  aItem->SetParent( newBI );
1445  newBI->ClearFlags();
1446 
1447  m_commit->Add( newBI );
1448  }
1449 }
1450 
1451 
1453 {
1454  std::set<MODULE*> processedMods;
1455 
1456  EraseView();
1457 
1458  for( auto mo : m_moduleOffsets )
1459  {
1460  auto offset = mo.second.p_new - mo.second.p_old;
1461  auto mod = mo.first->GetParent();
1462 
1463  VECTOR2I p_orig = mod->GetPosition();
1464  VECTOR2I p_new = p_orig + offset;
1465 
1466  if( processedMods.find( mod ) != processedMods.end() )
1467  continue;
1468 
1469  processedMods.insert( mod );
1470  m_commit->Modify( mod );
1471  mod->SetPosition( wxPoint( p_new.x, p_new.y ));
1472  }
1473 
1474  m_moduleOffsets.clear();
1475 
1476  m_commit->Push( _( "Interactive Router" ) );
1477  m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1478 }
1479 
1480 
1482 {
1483  wxLogTrace( "PNS", "SetView %p", aView );
1484 
1485  if( m_previewItems )
1486  {
1488  delete m_previewItems;
1489  }
1490 
1491  m_view = aView;
1494 
1495  if(m_view)
1497 
1498  delete m_debugDecorator;
1499 
1500  auto dec = new PNS_PCBNEW_DEBUG_DECORATOR();
1501  m_debugDecorator = dec;
1502 
1503  if( ADVANCED_CFG::GetCfg().m_ShowRouterDebugGraphics )
1504  dec->SetView( m_view );
1505 }
1506 
1507 
1508 void PNS_KICAD_IFACE::UpdateNet( int aNetCode )
1509 {
1510  wxLogTrace( "PNS", "Update-net %d", aNetCode );
1511 
1512 }
1513 
1515 {
1516  return m_ruleResolver;
1517 }
1518 
1519 
1521 {
1522  m_tool = aTool;
1523  m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1524 }
1525 
1527 {
1528  m_dispOptions = aDispOptions;
1529 }
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:136
Directions
Enum Directions Represents available directions - there are 8 of them, as on a rectilinear map (north...
Definition: direction45.h:46
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:749
VECTOR2_TRAITS< int >::extended_type extended_type
Definition: vector2d.h:77
void SetHostTool(PCB_TOOL_BASE *aTool)
std::unique_ptr< PNS::VIA > syncVia(VIA *aVia)
ITEM.
Definition: pns_item.h:54
void DisplayRatline(const SHAPE_LINE_CHAIN &aRatline, int aColor=-1) override
void AddSegment(SEG aS, int aColor, const std::string aName="") override
const std::set< unsigned int > GetHighContrastLayers() const
Function GetHighContrastLayers() Returns the set of currently high-contrast layers.
bool syncTextItem(PNS::NODE *aWorld, EDA_TEXT *aText, PCB_LAYER_ID aLayer)
NETINFO_ITEM * FindNet(int aNetcode) const
Search for a net with the given netcode.
void AddDirections(VECTOR2D aP, int aMask, int aColor, const std::string aName="") override
bool UseNetClassTrack() const
Function UseNetClassTrack returns true if netclass values should be used to obtain appropriate track ...
bool IsPolygonFilled() const
Polygonal shape is not always filled.
Definition: pcb_shape.h:97
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
int holeRadius(const PNS::ITEM *aItem) const
void LayerPair(PCB_LAYER_ID *top_layer, PCB_LAYER_ID *bottom_layer) const
Function LayerPair Return the 2 layers used by the via (the via actually uses all layers between thes...
SHAPE_SIMPLE.
Definition: shape_simple.h:43
void SetView(KIGFX::VIEW *aView)
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:54
int GetNetCode() const
Function GetNetCode.
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly, PCB_LAYER_ID aLayer, SHAPE_POLY_SET *aBoardOutline, SHAPE_POLY_SET *aSmoothedPolyWithApron=nullptr) const
Function GetSmoothedPoly.
virtual int Layer() const
Definition: pns_item.h:156
int OutlineCount() const
Returns the number of outlines in the set
PNS::RULE_RESOLVER * GetRuleResolver() override
std::unique_ptr< PNS::SOLID > syncPad(D_PAD *aPad)
NODE.
Definition: pns_node.h:169
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
bool syncGraphicalItem(PNS::NODE *aWorld, PCB_SHAPE *aItem)
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
bool FlashLayer(int aLayer) const
Definition: class_pad.cpp:193
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:424
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
This file is part of the common library.
bool syncZone(PNS::NODE *aWorld, ZONE_CONTAINER *aZone, SHAPE_POLY_SET *aBoardOutline)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:112
int GetBiggestClearanceValue()
Function GetBiggestClearanceValue.
void GetTriangle(int index, VECTOR2I &a, VECTOR2I &b, VECTOR2I &c) const
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
const wxPoint & GetStart() const
Definition: class_track.h:116
const SHAPE_SEGMENT * GetEffectiveHoleShape() const
Function GetEffectiveHoleShape Returns a SHAPE object representing the pad's hole.
Definition: class_pad.cpp:270
bool inheritTrackWidth(PNS::ITEM *aItem, int *aInheritedWidth)
bool UseNetClassDiffPair() const
Function UseNetClassDiffPair returns true if netclass values should be used to obtain appropriate dif...
VIATYPE ViaType() const
Definition: pns_via.h:106
PNS::DEBUG_DECORATOR * m_debugDecorator
int GetHolePlatingThickness() const
Pad & via drills are finish size.
const VECTOR2I ToVector() const
Function ToVector()
Definition: direction45.h:269
int Width() const override
Definition: pns_segment.h:78
ENTRIES & Items()
Definition: pns_itemset.h:140
void UpdateNet(int aNetCode) override
ITEM_SET & FilterKinds(int aKindMask, bool aInvert=false)
Definition: pns_itemset.cpp:70
void UseCustomDiffPairDimensions(bool aEnabled)
Function UseCustomDiffPairDimensions Enables/disables custom differential pair dimensions.
int GetPadToDieLength() const
Definition: class_pad.h:362
void SetParent(BOARD_ITEM *aParent)
Definition: pns_item.h:146
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:81
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns the all the layers within the VIEW the object is painted on.
void SetClearance(int aClearance)
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
bool SetNetCode(int aNetCode, bool aNoAssert)
Sets net using a net code.
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
bool Overlaps(const LAYER_RANGE &aOther) const
Definition: pns_layerset.h:68
T Opt() const
Definition: minoptmax.h:33
extended_type SquaredEuclideanNorm() const
Function Squared Euclidean Norm computes the squared euclidean norm of the vector,...
Definition: vector2d.h:306
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: class_board.h:558
wxString m_RuleName
Definition: pns_node.h:73
BOARD_ITEM * Parent() const
Definition: pns_item.h:147
void SetDebugDecorator(PNS::DEBUG_DECORATOR *aDec)
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
No updates are required.
Definition: view_item.h:57
PNS_PCBNEW_DEBUG_DECORATOR(KIGFX::VIEW *aView=NULL)
void Line(const SHAPE_LINE_CHAIN &aLine, int aWidth=0, int aStyle=0)
const SEG & Seg() const
Definition: pns_segment.h:83
const std::shared_ptr< SHAPE_POLY_SET > & GetEffectivePolygon(PCB_LAYER_ID=UNDEFINED_LAYER) const
Definition: class_pad.cpp:252
void ShowTrackClearance(bool aEnabled)
virtual VECTOR2I Centre() const
Function Centre()
Definition: shape.h:232
ITEM_SET & ExcludeItem(const ITEM *aItem)
void SetViaDrill(int aDrill)
T Min() const
Definition: minoptmax.h:31
PNS_PCBNEW_RULE_RESOLVER(BOARD *aBoard, PNS::ROUTER_IFACE *aRouterIface)
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:85
void SetRuleResolver(RULE_RESOLVER *aFunc)
Assigns a clerance resolution function object
Definition: pns_node.h:195
void HideItem(PNS::ITEM *aItem) override
void AddBox(BOX2I aB, int aColor, const std::string aName="") override
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
const VECTOR2I & Pos() const
Definition: pns_via.h:95
PNS::ROUTER_IFACE * m_routerIface
bool IsTriangulationUpToDate() const
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
wxString GetName() const
Definition: drc_rule.h:127
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:352
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:694
int GetCustomDiffPairWidth()
Function GetCustomDiffPairWidth.
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
std::unordered_set< BOARD_ITEM * > m_hiddenItems
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
int GetEffectiveTextPenWidth(int aDefaultWidth=0) const
The EffectiveTextPenWidth uses the text thickness if > 1 or aDefaultWidth.
Definition: eda_text.cpp:156
void Append(int aX, int aY, bool aAllowDuplication=false)
Function Append()
KIGFX::VIEW_GROUP * m_items
TRACE_CLEARANCE_DISPLAY_MODE_T m_ShowTrackClearanceMode
How trace clearances are displayed.
void SetWidth(int aWidth)
Definition: class_track.h:109
int Start() const
Definition: pns_layerset.h:83
void SetTrackWidth(int aWidth)
virtual int DpNetPolarity(int aNet) override
int End() const
Definition: pns_layerset.h:88
void SetMaxClearance(int aClearance)
Sets the worst-case clerance between any pair of items
Definition: pns_node.h:189
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:119
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_zone.cpp:287
ITEM_SET & Links()
Definition: pns_joint.h:206
JOINT.
Definition: pns_joint.h:43
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
PCB_LAYER_ID
A quick note on layer IDs:
int Diameter() const
Definition: pns_via.h:116
void SetDiffPairViaGap(int aGap)
void FreeItems()
Function FreeItems() Frees all the items that were added to the group.
Definition: view_group.cpp:197
LSET is a set of PCB_LAYER_IDs.
VIEW_ITEM class definition.
const wxPoint & GetMid() const
Definition: class_track.h:302
virtual bool DpNetPair(const PNS::ITEM *aItem, int &aNetP, int &aNetN) override
#define NULL
int GetDrillValue() const
Function GetDrillValue "calculates" the drill value for vias (m-Drill if > 0, or default drill value ...
MODULES & Modules()
Definition: class_board.h:284
bool IsVisible(const VIEW_ITEM *aItem) const
Returns information if the item is visible (or not).
Definition: view.cpp:1499
SHAPE_POLY_SET.
bool FlashLayer(int aLayer) const
Checks to see whether the via should have a pad on the specific layer.
std::unique_ptr< BOARD_COMMIT > m_commit
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:215
int Net() const
Definition: pns_item.h:150
DIRECTION_45.
Definition: direction45.h:37
bool IsItemVisible(const PNS::ITEM *aItem) const override
bool UseNetClassVia() const
Function UseNetClassVia returns true if netclass values should be used to obtain appropriate via size...
const wxPoint & GetOffset() const
Definition: class_pad.h:248
VECTOR2I::extended_type ecoord
virtual int DpCoupledNet(int aNet) override
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:343
LSET GetLayerSet() const override
Function GetLayerSet returns a std::bitset of all layers on which the item physically resides.
Definition: class_pad.h:349
PNS::DEBUG_DECORATOR * GetDebugDecorator() override
void TransformTextShapeToSegmentList(std::vector< wxPoint > &aCornerBuffer) const
Convert the text shape to a list of segment.
Definition: eda_text.cpp:583
void ShowViaClearance(bool aEnabled)
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
KIGFX::VIEW_GROUP * m_previewItems
void SetLayerPair(PCB_LAYER_ID aTopLayer, PCB_LAYER_ID aBottomLayer)
Function SetLayerPair For a via m_Layer contains the top layer, the other layer is in m_BottomLayer.
SHAPE.
Definition: shape.h:122
void SyncWorld(PNS::NODE *aWorld) override
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER) const override
Function GetEffectiveShape Some pad shapes can be complex (rounded/chamfered rectangle),...
Definition: class_pad.cpp:261
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:82
void SetColor(const KIGFX::COLOR4D &aColor)
virtual void SetLayer(int aLayer)
Function SetLayer() Sets layer used to draw the group.
Definition: view_group.h:115
void AddItem(PNS::ITEM *aItem) override
const PCB_DISPLAY_OPTIONS * m_dispOptions
void Commit() override
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: class_zone.h:729
bool IsNull() const
Definition: drc_rule.h:116
void SetBoard(BOARD *aBoard)
void EraseView() override
wxString GetSelectMenuText(EDA_UNITS aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_zone.cpp:851
Definition: seg.h:39
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, wxString *aErrorText=nullptr, std::vector< wxPoint > *aDiscontinuities=nullptr, std::vector< wxPoint > *aIntersections=nullptr)
Extract the board outlines and build a closed polygon from lines, arcs and circle items on edge cut l...
virtual int Clearance(const PNS::ITEM *aA, const PNS::ITEM *aB) override
EDA_UNITS
Definition: eda_units.h:38
virtual bool IsDiffPair(const PNS::ITEM *aA, const PNS::ITEM *aB) override
bool GetHighContrast() const
VECTOR2< T > Resize(T aNewLength) const
Function Resize returns a vector of the same direction, but length specified in aNewLength.
Definition: vector2d.h:392
virtual RENDER_SETTINGS * GetSettings()=0
Function GetAdapter Returns pointer to current settings that are going to be used when drawing items.
std::vector< SHAPE * > MakeEffectiveShapes() const
Makes a set of SHAPE objects representing the PCB_SHAPE.
Definition: pcb_shape.cpp:1067
std::unique_ptr< PNS::ARC > syncArc(ARC *aArc)
int GetCurrentViaSize() const
Function GetCurrentViaSize.
KIGFX::VIEW * m_view
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
bool IsOnLayer(const PNS::ITEM *aItem, int aLayer) const override
ZONE_CONTAINERS & Zones()
Definition: class_board.h:290
int GetWidth() const
Definition: class_track.h:110
Board layer functions and definitions.
const MINOPTMAX< int > & GetValue() const
Definition: drc_rule.h:121
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:201
DRC_CONSTRAINT_TYPE_T
Definition: drc_rule.h:41
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
SHAPE * Clone() const override
Function Clone()
Definition: shape_segment.h:49
void SetDiffPairGap(int aGap)
polygon (not yet used for tracks, but could be in microwave apps)
void AddPoint(VECTOR2I aP, int aColor, const std::string aName="") override
#define _(s)
Definition: 3d_actions.cpp:33
int GetCustomDiffPairViaGap()
Function GetCustomDiffPairViaGap.
SHAPE_LINE_CHAIN.
void RemoveItem(PNS::ITEM *aItem) override
virtual wxString NetName(int aNet) override
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in a variety of units (the basic call r...
Definition: class_pad.h:338
const wxSize & GetDrillSize() const
Definition: class_pad.h:241
VECTOR2I A
Definition: seg.h:47
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:134
wxPoint ShapePos() const
Definition: class_pad.cpp:609
Plated through hole pad.
Definition: pad_shapes.h:80
void AddItem(PNS::ITEM *aItem) override
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:486
void SetView(KIGFX::VIEW *aView)
int matchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
VIATYPE GetViaType() const
Definition: class_track.h:384
currently selected items overlay
virtual bool QueryConstraint(PNS::CONSTRAINT_TYPE aType, const PNS::ITEM *aItemA, const PNS::ITEM *aItemB, int aLayer, PNS::CONSTRAINT *aConstraint) override
MODULE_ZONE_CONTAINER is the same item as ZONE_CONTAINER, but with a specific type id ZONE_CONTAINER ...
Definition: class_zone.h:958
PCB_TOOL_BASE * m_tool
PCB_LAYER_ID TopLayer() const
VECTOR2I::extended_type ecoord
const wxPoint & GetEnd() const
Definition: class_track.h:113
bool GetDoNotAllowTracks() const
Definition: class_zone.h:732
int ShowModal() override
Definition: confirm.cpp:96
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:124
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:222
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1459
void Clear()
Function Clear() Removes all points from the line chain.
void SetStart(const wxPoint &aStart)
Definition: class_track.h:115
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers of advanced config.
virtual bool IsConnected() const
Function IsConnected() Returns information if the object is derived from BOARD_CONNECTED_ITEM.
void CacheTriangulation(bool aPartition=true)
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
const Vec & GetSize() const
Definition: box2.h:189
MINOPTMAX< int > m_Value
Definition: pns_node.h:71
PCB_SHAPE_TYPE_T GetShape() const
Definition: pcb_shape.h:114
std::map< D_PAD *, OFFSET > m_moduleOffsets
PNS_PCBNEW_RULE_RESOLVER * m_ruleResolver
T OptThenMin() const
Definition: minoptmax.h:45
const Vec & GetOrigin() const
Definition: box2.h:193
VIEW.
Definition: view.h:63
NODE * Owner() const
Function Owner()
Definition: pns_item.h:174
wxPoint GetPosition() const override
Definition: class_track.h:423
void SetViaDiameter(int aDiameter)
double GetScale() const
Function GetScale()
Definition: view.h:259
int Drill() const
Definition: pns_via.h:127
Push and Shove diff pair dimensions (gap) settings dialog.
bool ImportSizes(PNS::SIZES_SETTINGS &aSizes, PNS::ITEM *aStartItem, int aNet) override
void SetViaType(VIATYPE aViaType)
Definition: class_track.h:385
int GetWidth() const
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:91
PCB_LAYER_ID BottomLayer() const
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS *aDispOptions)
const TRIANGULATED_POLYGON * TriangulatedPolygon(int aIndex) const
void DisplayItem(const PNS::ITEM *aItem, int aColor=0, int aClearance=0, bool aEdit=false) override
DRAWINGS & Drawings()
Definition: class_board.h:287
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:621
void Append(int aX, int aY)
Function Append()
Definition: shape_simple.h:145
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:897
CONSTRAINT_TYPE m_Type
Definition: pns_node.h:70
TRACKS & Tracks()
Definition: class_board.h:281
std::shared_ptr< DRC_ENGINE > m_DRCEngine
std::unique_ptr< PNS::SEGMENT > syncTrack(TRACK *aTrack)
int GetCustomDiffPairGap()
Function GetCustomDiffPairGap.
LAYER_RANGE.
Definition: pns_layerset.h:32
const LAYER_RANGE & Layers() const
Definition: pns_item.h:152
void SetWidth(int aWidth)
virtual double ViewGetLOD(int aLayer, VIEW *aView) const
Function ViewGetLOD() Returns the level of detail (LOD) of the item.
Definition: view_item.h:141
virtual bool CollideHoles(const PNS::ITEM *aA, const PNS::ITEM *aB, bool aNeedMTV, VECTOR2I *aMTV) const override
void AddLine(const SHAPE_LINE_CHAIN &aLine, int aType, int aWidth, const std::string aName="") override
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
void RemoveItem(PNS::ITEM *aItem) override
CONSTRAINT_TYPE
RULE_RESOLVER.
Definition: pns_node.h:58
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182
void SetDiffPairWidth(int aWidth)
bool IsAnyLayerVisible(const LAYER_RANGE &aLayer) const override
BOARD_DESIGN_SETTINGS contains design settings for a BOARD object.
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:402
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100
VECTOR2I B
Definition: seg.h:48