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 <class_text_mod.h>
26 #include <class_edge_mod.h>
27 #include <class_module.h>
28 #include <class_track.h>
29 #include <class_zone.h>
30 #include <class_drawsegment.h>
31 #include <class_pcb_text.h>
32 #include <board_commit.h>
34 #include <geometry/convex_hull.h>
35 #include <confirm.h>
36 
37 #include <view/view.h>
38 #include <view/view_item.h>
39 #include <view/view_group.h>
41 
42 #include <pcb_painter.h>
43 
44 #include <geometry/shape.h>
46 #include <geometry/shape_rect.h>
47 #include <geometry/shape_circle.h>
48 #include <geometry/shape_arc.h>
49 #include <geometry/shape_simple.h>
50 
51 #include <memory>
52 
53 #include "tools/pcb_tool_base.h"
54 
55 #include "pns_kicad_iface.h"
56 
57 #include "pns_arc.h"
58 #include "pns_routing_settings.h"
59 #include "pns_item.h"
60 #include "pns_solid.h"
61 #include "pns_segment.h"
62 #include "pns_node.h"
63 #include "pns_topology.h"
64 #include "pns_router.h"
65 #include "pns_debug_decorator.h"
66 #include "router_preview_item.h"
67 
69 
71 {
72 public:
73  PNS_PCBNEW_RULE_RESOLVER( BOARD* aBoard, PNS::ROUTER* aRouter );
74  virtual ~PNS_PCBNEW_RULE_RESOLVER();
75 
76  virtual bool CollideHoles( const PNS::ITEM* aA, const PNS::ITEM* aB,
77  bool aNeedMTV, VECTOR2I* aMTV ) const override;
78 
79  virtual int Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const override;
80  virtual int Clearance( int aNetCode ) const override;
81  virtual int DpCoupledNet( int aNet ) override;
82  virtual int DpNetPolarity( int aNet ) override;
83  virtual bool DpNetPair( PNS::ITEM* aItem, int& aNetP, int& aNetN ) override;
84 
85  virtual wxString NetName( int aNet ) override;
86 
87 private:
89  {
92  int clearance;
93  };
94 
95  int holeRadius( const PNS::ITEM* aItem ) const;
96  int localPadClearance( const PNS::ITEM* aItem ) const;
97  int matchDpSuffix( const wxString& aNetName, wxString& aComplementNet, wxString& aBaseDpName );
98 
101 
102  std::vector<CLEARANCE_ENT> m_netClearanceCache;
103  std::unordered_map<const D_PAD*, int> m_localClearanceCache;
105 };
106 
107 
109  m_router( aRouter ),
110  m_board( aBoard )
111 {
112  PNS::NODE* world = m_router->GetWorld();
113 
114  PNS::TOPOLOGY topo( world );
116 
117  // Build clearance cache for net classes
118  for( unsigned int i = 0; i < m_board->GetNetCount(); i++ )
119  {
120  NETINFO_ITEM* ni = m_board->FindNet( i );
121 
122  if( ni == NULL )
123  continue;
124 
125  CLEARANCE_ENT ent;
126  ent.coupledNet = DpCoupledNet( i );
127 
128  wxString netClassName = ni->GetClassName();
129  NETCLASSPTR nc = m_board->GetDesignSettings().m_NetClasses.Find( netClassName );
130 
131  int clearance = nc->GetClearance();
132  ent.clearance = clearance;
133  ent.dpClearance = nc->GetDiffPairGap();
134  m_netClearanceCache[i] = ent;
135 
136  wxLogTrace( "PNS", "Add net %u netclass %s clearance %d Diff Pair clearance %d",
137  i, netClassName.mb_str(), clearance, ent.dpClearance );
138  }
139 
140  // Build clearance cache for pads
141  for( auto mod : m_board->Modules() )
142  {
143  auto moduleClearance = mod->GetLocalClearance();
144 
145  for( auto pad : mod->Pads() )
146  {
147  int padClearance = pad->GetLocalClearance();
148 
149  if( padClearance > 0 )
150  m_localClearanceCache[ pad ] = padClearance;
151 
152  else if( moduleClearance > 0 )
153  m_localClearanceCache[ pad ] = moduleClearance;
154  }
155  }
156 
157  auto defaultRule = m_board->GetDesignSettings().m_NetClasses.Find ("Default");
158 
159  if( defaultRule )
160  {
161  m_defaultClearance = defaultRule->GetClearance();
162  }
163  else
164  {
165  m_defaultClearance = Millimeter2iu(0.254);
166  }
167 }
168 
169 
171 {
172 }
173 
174 
176 {
177  if( aItem->Kind() == PNS::ITEM::SOLID_T )
178  {
179  const D_PAD* pad = dynamic_cast<const D_PAD*>( aItem->Parent() );
180 
181  if( pad && pad->GetDrillShape() == PAD_DRILL_SHAPE_CIRCLE )
182  return pad->GetDrillSize().x / 2;
183  }
184  else if( aItem->Kind() == PNS::ITEM::VIA_T )
185  {
186  const ::VIA* via = dynamic_cast<const ::VIA*>( aItem->Parent() );
187 
188  if( via )
189  return via->GetDrillValue() / 2;
190  }
191 
192  return 0;
193 }
194 
195 
197  bool aNeedMTV, VECTOR2I* aMTV ) const
198 {
199  VECTOR2I pos_a = aA->Shape()->Centre();
200  VECTOR2I pos_b = aB->Shape()->Centre();
201 
202  // Holes with identical locations are allowable
203  if( pos_a == pos_b )
204  return false;
205 
206  int radius_a = holeRadius( aA );
207  int radius_b = holeRadius( aB );
208 
209  // Do both objects have holes?
210  if( radius_a > 0 && radius_b > 0 )
211  {
212  int holeToHoleMin = m_board->GetDesignSettings().m_HoleToHoleMin;
213 
214  ecoord min_dist = holeToHoleMin + radius_a + radius_b;
215  ecoord min_dist_sq = min_dist * min_dist;
216 
217  const VECTOR2I delta = pos_b - pos_a;
218 
219  ecoord dist_sq = delta.SquaredEuclideanNorm();
220 
221  if( dist_sq < min_dist_sq )
222  {
223  if( aNeedMTV )
224  *aMTV = delta.Resize( min_dist - sqrt( dist_sq ) + 3 ); // fixme: apparent rounding error
225 
226  return true;
227  }
228  }
229 
230  return false;
231 }
232 
233 
235 {
236  if( !aItem->Parent() || aItem->Parent()->Type() != PCB_PAD_T )
237  return 0;
238 
239  const D_PAD* pad = static_cast<D_PAD*>( aItem->Parent() );
240 
241  auto i = m_localClearanceCache.find( pad );
242 
243  if( i == m_localClearanceCache.end() )
244  return 0;
245 
246  return i->second;
247 }
248 
249 
250 int PNS_PCBNEW_RULE_RESOLVER::Clearance( const PNS::ITEM* aA, const PNS::ITEM* aB ) const
251 {
252  int net_a = aA->Net();
253  int cl_a = ( net_a >= 0 ? m_netClearanceCache[net_a].clearance : m_defaultClearance );
254  int net_b = aB->Net();
255  int cl_b = ( net_b >= 0 ? m_netClearanceCache[net_b].clearance : m_defaultClearance );
256 
257  // Pad clearance is 0 if the ITEM* is not a pad
258  int pad_a = localPadClearance( aA );
259  int pad_b = localPadClearance( aB );
260 
261  if( pad_a > 0 )
262  cl_a = pad_a;
263 
264  if( pad_b > 0 )
265  cl_b = pad_b;
266 
267  return std::max( cl_a, cl_b );
268 }
269 
270 
271 int PNS_PCBNEW_RULE_RESOLVER::Clearance( int aNetCode ) const
272 {
273  if( aNetCode > 0 && aNetCode < (int) m_netClearanceCache.size() )
274  return m_netClearanceCache[aNetCode].clearance;
275 
276  return m_defaultClearance;
277 }
278 
279 
280 int PNS_PCBNEW_RULE_RESOLVER::matchDpSuffix( const wxString& aNetName, wxString& aComplementNet,
281  wxString& aBaseDpName )
282 {
283  int rv = 0;
284 
285  if( aNetName.EndsWith( "+" ) )
286  {
287  aComplementNet = "-";
288  rv = 1;
289  }
290  else if( aNetName.EndsWith( "P" ) )
291  {
292  aComplementNet = "N";
293  rv = 1;
294  }
295  else if( aNetName.EndsWith( "-" ) )
296  {
297  aComplementNet = "+";
298  rv = -1;
299  }
300  else if( aNetName.EndsWith( "N" ) )
301  {
302  aComplementNet = "P";
303  rv = -1;
304  }
305  // Match P followed by 2 digits
306  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "P" )
307  {
308  aComplementNet = "N" + aNetName.Right( 2 );
309  rv = 1;
310  }
311  // Match P followed by 1 digit
312  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "P" )
313  {
314  aComplementNet = "N" + aNetName.Right( 1 );
315  rv = 1;
316  }
317  // Match N followed by 2 digits
318  else if( aNetName.Right( 2 ).IsNumber() && aNetName.Right( 3 ).Left( 1 ) == "N" )
319  {
320  aComplementNet = "P" + aNetName.Right( 2 );
321  rv = -1;
322  }
323  // Match N followed by 1 digit
324  else if( aNetName.Right( 1 ).IsNumber() && aNetName.Right( 2 ).Left( 1 ) == "N" )
325  {
326  aComplementNet = "P" + aNetName.Right( 1 );
327  rv = -1;
328  }
329  if( rv != 0 )
330  {
331  aBaseDpName = aNetName.Left( aNetName.Length() - aComplementNet.Length() );
332  aComplementNet = aBaseDpName + aComplementNet;
333  }
334 
335  return rv;
336 }
337 
338 
340 {
341  wxString refName = m_board->FindNet( aNet )->GetNetname();
342  wxString dummy, coupledNetName;
343 
344  if( matchDpSuffix( refName, coupledNetName, dummy ) )
345  {
346  NETINFO_ITEM* net = m_board->FindNet( coupledNetName );
347 
348  if( !net )
349  return -1;
350 
351  return net->GetNet();
352  }
353 
354  return -1;
355 }
356 
357 
359 {
360  return m_board->FindNet( aNet )->GetNetname();
361 }
362 
363 
365 {
366  wxString refName = m_board->FindNet( aNet )->GetNetname();
367  wxString dummy1, dummy2;
368 
369  return matchDpSuffix( refName, dummy1, dummy2 );
370 }
371 
372 
373 bool PNS_PCBNEW_RULE_RESOLVER::DpNetPair( PNS::ITEM* aItem, int& aNetP, int& aNetN )
374 {
375  if( !aItem || !aItem->Parent() || !aItem->Parent()->GetNet() )
376  return false;
377 
378  wxString netNameP = aItem->Parent()->GetNet()->GetNetname();
379  wxString netNameN, netNameCoupled, netNameBase;
380 
381  int r = matchDpSuffix( netNameP, netNameCoupled, netNameBase );
382 
383  if( r == 0 )
384  return false;
385  else if( r == 1 )
386  {
387  netNameN = netNameCoupled;
388  }
389  else
390  {
391  netNameN = netNameP;
392  netNameP = netNameCoupled;
393  }
394 
395 // wxLogTrace( "PNS","p %s n %s base %s\n", (const char *)netNameP.c_str(), (const char *)netNameN.c_str(), (const char *)netNameBase.c_str() );
396 
397  NETINFO_ITEM* netInfoP = m_board->FindNet( netNameP );
398  NETINFO_ITEM* netInfoN = m_board->FindNet( netNameN );
399 
400  //wxLogTrace( "PNS","ip %p in %p\n", netInfoP, netInfoN);
401 
402  if( !netInfoP || !netInfoN )
403  return false;
404 
405  aNetP = netInfoP->GetNet();
406  aNetN = netInfoN->GetNet();
407 
408  return true;
409 }
410 
411 
413 {
414 public:
416  m_view( NULL ), m_items( NULL )
417  {
418  SetView( aView );
419  }
420 
422  {
423  Clear();
424  delete m_items;
425  }
426 
427  void SetView( KIGFX::VIEW* aView )
428  {
429  Clear();
430  delete m_items;
431  m_items = NULL;
432  m_view = aView;
433 
434  if( m_view == NULL )
435  return;
436 
439  m_view->Add( m_items );
440  }
441 
442  void AddPoint( VECTOR2I aP, int aColor, const std::string aName = "") override
443  {
445 
446  l.Append( aP - VECTOR2I( -50000, -50000 ) );
447  l.Append( aP + VECTOR2I( -50000, -50000 ) );
448 
449  AddLine( l, aColor, 10000 );
450 
451  l.Clear();
452  l.Append( aP - VECTOR2I( 50000, -50000 ) );
453  l.Append( aP + VECTOR2I( 50000, -50000 ) );
454 
455  AddLine( l, aColor, 10000 );
456  }
457 
458  void AddBox( BOX2I aB, int aColor, const std::string aName = "" ) override
459  {
461 
462  VECTOR2I o = aB.GetOrigin();
463  VECTOR2I s = aB.GetSize();
464 
465  l.Append( o );
466  l.Append( o.x + s.x, o.y );
467  l.Append( o.x + s.x, o.y + s.y );
468  l.Append( o.x, o.y + s.y );
469  l.Append( o );
470 
471  AddLine( l, aColor, 10000 );
472  }
473 
474  void AddSegment( SEG aS, int aColor, const std::string aName = "") override
475  {
477 
478  l.Append( aS.A );
479  l.Append( aS.B );
480 
481  AddLine( l, aColor, 10000 );
482  }
483 
484  void AddDirections( VECTOR2D aP, int aMask, int aColor, const std::string aName = "") override
485  {
486  BOX2I b( aP - VECTOR2I( 10000, 10000 ), VECTOR2I( 20000, 20000 ) );
487 
488  AddBox( b, aColor );
489  for( int i = 0; i < 8; i++ )
490  {
491  if( ( 1 << i ) & aMask )
492  {
493  VECTOR2I v = DIRECTION_45( ( DIRECTION_45::Directions ) i ).ToVector() * 100000;
494  AddSegment( SEG( aP, aP + v ), aColor );
495  }
496  }
497  }
498 
499  void AddLine( const SHAPE_LINE_CHAIN& aLine, int aType, int aWidth, const std::string aName = "" ) override
500  {
502 
503  pitem->Line( aLine, aWidth, aType );
504  m_items->Add( pitem ); // Should not be needed, as m_items has been passed as a parent group in alloc;
505  m_view->Update( m_items );
506  }
507 
508  void Clear() override
509  {
510  if( m_view && m_items )
511  {
512  m_items->FreeItems();
513  m_view->Update( m_items );
514  }
515  }
516 
517 private:
520 };
521 
522 
524 {
525  return m_debugDecorator;
526 }
527 
528 
530 {
531  m_ruleResolver = nullptr;
532  m_board = nullptr;
533  m_router = nullptr;
534  m_debugDecorator = nullptr;
535 }
536 
537 
539 {
540  m_tool = nullptr;
541  m_view = nullptr;
542  m_previewItems = nullptr;
543  m_dispOptions = nullptr;
544 }
545 
546 
548 {
549  delete m_ruleResolver;
550  delete m_debugDecorator;
551 }
552 
553 
555 {
556  if( m_previewItems )
557  {
559  delete m_previewItems;
560  }
561 }
562 
563 
564 std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( D_PAD* aPad )
565 {
566  LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 );
567 
568  // ignore non-copper pads
569  if( ( aPad->GetLayerSet() & LSET::AllCuMask()).none() )
570  return NULL;
571 
572  switch( aPad->GetAttribute() )
573  {
574  case PAD_ATTRIB_STANDARD:
575  break;
576 
577  case PAD_ATTRIB_SMD:
579  case PAD_ATTRIB_CONN:
580  {
581  LSET lmsk = aPad->GetLayerSet();
582  bool is_copper = false;
583 
584  for( int i = 0; i < MAX_CU_LAYERS; i++ )
585  {
586  if( lmsk[i] )
587  {
588  is_copper = true;
589 
591  layers = LAYER_RANGE( i );
592 
593  break;
594  }
595  }
596 
597  if( !is_copper )
598  return NULL;
599  }
600  break;
601 
602  default:
603  wxLogTrace( "PNS", "unsupported pad type 0x%x", aPad->GetAttribute() );
604  return NULL;
605  }
606 
607  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
608 
609  solid->SetLayers( layers );
610  solid->SetNet( aPad->GetNetCode() );
611  solid->SetParent( aPad );
612  solid->SetPadToDie( aPad->GetPadToDieLength() );
613 
614  wxPoint wx_c = aPad->ShapePos();
615  wxSize wx_sz = aPad->GetSize();
616  wxPoint offset = aPad->GetOffset();
617 
618  VECTOR2I c( wx_c.x, wx_c.y );
619  VECTOR2I sz( wx_sz.x, wx_sz.y );
620 
621  RotatePoint( &offset, aPad->GetOrientation() );
622 
623  solid->SetPos( VECTOR2I( c.x - offset.x, c.y - offset.y ) );
624  solid->SetOffset( VECTOR2I( offset.x, offset.y ) );
625 
626  double orient = aPad->GetOrientation() / 10.0;
627 
628  if( aPad->GetShape() == PAD_SHAPE_CIRCLE )
629  {
630  solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
631  }
632  else if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
633  {
634  SHAPE_POLY_SET outline;
635  outline.Append( aPad->GetCustomShapeAsPolygon() );
636  aPad->CustomShapeAsPolygonToBoardPosition( &outline, wx_c, aPad->GetOrientation() );
637 
638  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
639 
640  for( auto iter = outline.CIterate( 0 ); iter; iter++ )
641  shape->Append( *iter );
642 
643  solid->SetShape( shape );
644  }
645  else
646  {
647  if( orient == 0.0 || orient == 90.0 || orient == 180.0 || orient == 270.0 )
648  {
649  if( orient == 90.0 || orient == 270.0 )
650  sz = VECTOR2I( sz.y, sz.x );
651 
652  switch( aPad->GetShape() )
653  {
654  case PAD_SHAPE_OVAL:
655  if( sz.x == sz.y )
656  solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
657  else
658  {
659  VECTOR2I delta;
660 
661  if( sz.x > sz.y )
662  delta = VECTOR2I( ( sz.x - sz.y ) / 2, 0 );
663  else
664  delta = VECTOR2I( 0, ( sz.y - sz.x ) / 2 );
665 
666  SHAPE_SEGMENT* shape = new SHAPE_SEGMENT( c - delta, c + delta,
667  std::min( sz.x, sz.y ) );
668  solid->SetShape( shape );
669  }
670  break;
671 
672  case PAD_SHAPE_RECT:
673  solid->SetShape( new SHAPE_RECT( c - sz / 2, sz.x, sz.y ) );
674  break;
675 
676  case PAD_SHAPE_TRAPEZOID:
677  {
678  wxPoint coords[4];
679  aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
680  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
681 
682  for( int ii = 0; ii < 4; ii++ )
683  {
684  shape->Append( wx_c + coords[ii] );
685  }
686 
687  solid->SetShape( shape );
688  break;
689  }
690 
692  case PAD_SHAPE_ROUNDRECT:
693  {
694  SHAPE_POLY_SET outline;
695  aPad->BuildPadShapePolygon( outline, wxSize( 0, 0 ) );
696 
697  // TransformRoundRectToPolygon creates only one convex polygon
698  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
699  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
700 
701  for( int ii = 0; ii < poly.PointCount(); ++ii )
702  shape->Append( poly.CPoint( ii ) );
703 
704  solid->SetShape( shape );
705  }
706  break;
707 
708  default:
709  wxLogTrace( "PNS", "unsupported pad shape" );
710  return nullptr;
711  }
712  }
713  else
714  {
715  switch( aPad->GetShape() )
716  {
717  // PAD_SHAPE_CIRCLE and PAD_SHAPE_CUSTOM already handled above
718 
719  case PAD_SHAPE_OVAL:
720  if( sz.x == sz.y )
721  solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
722  else
723  {
724  wxPoint start;
725  wxPoint end;
726  wxPoint corner;
727 
728  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
729 
730  int w = aPad->BuildSegmentFromOvalShape( start, end, 0.0, wxSize( 0, 0 ) );
731 
732  if( start.y == 0 )
733  corner = wxPoint( start.x, -( w / 2 ) );
734  else
735  corner = wxPoint( w / 2, start.y );
736 
737  RotatePoint( &start, aPad->GetOrientation() );
738  RotatePoint( &corner, aPad->GetOrientation() );
739  shape->Append( wx_c + corner );
740 
741  for( int rot = 100; rot <= 1800; rot += 100 )
742  {
743  wxPoint p( corner );
744  RotatePoint( &p, start, rot );
745  shape->Append( wx_c + p );
746  }
747 
748  if( end.y == 0 )
749  corner = wxPoint( end.x, w / 2 );
750  else
751  corner = wxPoint( -( w / 2 ), end.y );
752 
753  RotatePoint( &end, aPad->GetOrientation() );
754  RotatePoint( &corner, aPad->GetOrientation() );
755  shape->Append( wx_c + corner );
756 
757  for( int rot = 100; rot <= 1800; rot += 100 )
758  {
759  wxPoint p( corner );
760  RotatePoint( &p, end, rot );
761  shape->Append( wx_c + p );
762  }
763 
764  solid->SetShape( shape );
765  }
766  break;
767 
768  case PAD_SHAPE_RECT:
769  case PAD_SHAPE_TRAPEZOID:
770  {
771  wxPoint coords[4];
772  aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
773 
774  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
775  for( int ii = 0; ii < 4; ii++ )
776  {
777  shape->Append( wx_c + coords[ii] );
778  }
779 
780  solid->SetShape( shape );
781  break;
782  }
783 
785  case PAD_SHAPE_ROUNDRECT:
786  {
787  SHAPE_POLY_SET outline;
788  aPad->BuildPadShapePolygon( outline, wxSize( 0, 0 ) );
789 
790  // TransformRoundRectToPolygon creates only one convex polygon
791  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
792  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
793 
794  for( int ii = 0; ii < poly.PointCount(); ++ii )
795  {
796  shape->Append( wxPoint( poly.CPoint( ii ).x, poly.CPoint( ii ).y ) );
797  }
798 
799  solid->SetShape( shape );
800  break;
801  }
802 
803  default:
804  wxLogTrace( "PNS", "unsupported pad shape" );
805  return nullptr;
806  }
807  }
808  }
809  return solid;
810 }
811 
812 
813 std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( TRACK* aTrack )
814 {
815  std::unique_ptr< PNS::SEGMENT > segment(
816  new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() )
817  );
818 
819  segment->SetWidth( aTrack->GetWidth() );
820  segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) );
821  segment->SetParent( aTrack );
822 
823  if( aTrack->IsLocked() )
824  segment->Mark( PNS::MK_LOCKED );
825 
826  return segment;
827 }
828 
829 
830 std::unique_ptr<PNS::ARC> PNS_KICAD_IFACE_BASE::syncArc( ARC* aArc )
831 {
832  std::unique_ptr< PNS::ARC > arc(
833  new PNS::ARC( SHAPE_ARC( aArc->GetCenter(), aArc->GetStart(),
834  aArc->GetAngle(), aArc->GetWidth() ),
835  aArc->GetNetCode() )
836  );
837 
838  arc->SetLayers( LAYER_RANGE( aArc->GetLayer() ) );
839  arc->SetParent( aArc );
840 
841  if( aArc->IsLocked() )
842  arc->Mark( PNS::MK_LOCKED );
843 
844  return arc;
845 }
846 
847 
848 std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE_BASE::syncVia( VIA* aVia )
849 {
850  PCB_LAYER_ID top, bottom;
851  aVia->LayerPair( &top, &bottom );
852  std::unique_ptr<PNS::VIA> via( new PNS::VIA(
853  aVia->GetPosition(),
854  LAYER_RANGE( top, bottom ),
855  aVia->GetWidth(),
856  aVia->GetDrillValue(),
857  aVia->GetNetCode(),
858  aVia->GetViaType() )
859  );
860 
861  via->SetParent( aVia );
862 
863  if( aVia->IsLocked() )
864  via->Mark( PNS::MK_LOCKED );
865 
866  return via;
867 }
868 
869 
871 {
872  SHAPE_POLY_SET poly;
873 
874  // TODO handle no-via restriction
875  if( !aZone->GetIsKeepout() || !aZone->GetDoNotAllowTracks() )
876  return false;
877 
878  // Some intersecting zones, despite being on the same layer with the same net, cannot be
879  // merged due to other parameters such as fillet radius. The copper pour will end up
880  // effectively merged though, so we want to keep the corners of such intersections sharp.
881  std::set<VECTOR2I> colinearCorners;
882  aZone->GetColinearCorners( m_board, colinearCorners );
883 
884  aZone->BuildSmoothedPoly( poly, &colinearCorners );
885  poly.CacheTriangulation();
886 
887  if( !poly.IsTriangulationUpToDate() )
888  {
889  KIDIALOG dlg( nullptr, wxString::Format( _( "Malformed keep-out zone at (%d, %d)" ),
890  aZone->GetPosition().x, aZone->GetPosition().y ), KIDIALOG::KD_WARNING );
891  dlg.ShowDetailedText(
892  wxString::Format( _( "%s\nThis zone cannot be handled by the track layout tool.\n"
893  "Please verify it is not a self-intersecting polygon." ),
895  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
896  dlg.ShowModal();
897 
898  return false;
899  }
900 
901  LSET layers = aZone->GetLayerSet();
902 
903  for( int layer = F_Cu; layer <= B_Cu; layer++ )
904  {
905  if ( ! layers[layer] )
906  continue;
907 
908  for( int outline = 0; outline < poly.OutlineCount(); outline++ )
909  {
910  auto tri = poly.TriangulatedPolygon( outline );
911 
912  for( size_t i = 0; i < tri->GetTriangleCount(); i++)
913  {
914  VECTOR2I a, b, c;
915  tri->GetTriangle( i, a, b, c );
916  auto triShape = new SHAPE_SIMPLE;
917 
918  triShape->Append( a );
919  triShape->Append( b );
920  triShape->Append( c );
921 
922  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
923 
924  solid->SetLayer( layer );
925  solid->SetNet( -1 );
926  solid->SetParent( aZone );
927  solid->SetShape( triShape );
928  solid->SetRoutable( false );
929 
930  aWorld->Add( std::move( solid ) );
931  }
932  }
933  }
934 
935  return true;
936 }
937 
938 
940 {
941  if( !IsCopperLayer( aLayer ) )
942  return false;
943 
944  int textWidth = aText->GetThickness();
945  std::vector<wxPoint> textShape;
946 
947  aText->TransformTextShapeToSegmentList( textShape );
948 
949  if( textShape.size() < 2 )
950  return false;
951 
952  for( size_t jj = 0; jj < textShape.size(); jj += 2 )
953  {
954  VECTOR2I start( textShape[jj] );
955  VECTOR2I end( textShape[jj+1] );
956  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
957 
958  solid->SetLayer( aLayer );
959  solid->SetNet( -1 );
960  solid->SetParent( nullptr );
961  solid->SetShape( new SHAPE_SEGMENT( start, end, textWidth ) );
962  solid->SetRoutable( false );
963 
964  aWorld->Add( std::move( solid ) );
965  }
966 
967  return true;
968 
969  /* A coarser (but faster) method:
970  *
971  SHAPE_POLY_SET outline;
972  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
973 
974  aText->TransformBoundingBoxWithClearanceToPolygon( &outline, 0 );
975 
976  for( auto iter = outline.CIterate( 0 ); iter; iter++ )
977  shape->Append( *iter );
978 
979  solid->SetShape( shape );
980 
981  solid->SetLayer( aLayer );
982  solid->SetNet( -1 );
983  solid->SetParent( nullptr );
984  solid->SetRoutable( false );
985  aWorld->Add( std::move( solid ) );
986  return true;
987  */
988 }
989 
990 
992 {
993  std::vector<SHAPE_SEGMENT*> segs;
994 
995  if( aItem->GetLayer() != Edge_Cuts && !IsCopperLayer( aItem->GetLayer() ) )
996  return false;
997 
998  switch( aItem->GetShape() )
999  {
1000  case S_ARC:
1001  {
1002  SHAPE_ARC arc( aItem->GetCenter(), aItem->GetArcStart(), aItem->GetAngle() / 10.0 );
1003  auto l = arc.ConvertToPolyline();
1004 
1005  for( int i = 0; i < l.SegmentCount(); i++ )
1006  {
1007  SHAPE_SEGMENT* seg = new SHAPE_SEGMENT( l.CSegment( i ), aItem->GetWidth() );
1008  segs.push_back( seg );
1009  }
1010 
1011  break;
1012  }
1013 
1014  case S_SEGMENT:
1015  segs.push_back(
1016  new SHAPE_SEGMENT( aItem->GetStart(), aItem->GetEnd(), aItem->GetWidth() ) );
1017 
1018  break;
1019 
1020  case S_CIRCLE:
1021  {
1022  // SHAPE_CIRCLE has no ConvertToPolyline() method, so use a 360.0 SHAPE_ARC
1023  SHAPE_ARC circle( aItem->GetCenter(), aItem->GetEnd(), 360.0 );
1024  auto l = circle.ConvertToPolyline();
1025 
1026  for( int i = 0; i < l.SegmentCount(); i++ )
1027  segs.push_back( new SHAPE_SEGMENT( l.CSegment( i ), aItem->GetWidth() ) );
1028 
1029  break;
1030  }
1031 
1032  case S_CURVE:
1033  {
1034  aItem->RebuildBezierToSegmentsPointsList( aItem->GetWidth() );
1035  auto pts = aItem->GetBezierPoints();
1036 
1037  for( size_t ii = 1; ii < pts.size(); ii++ )
1038  {
1039  segs.push_back( new SHAPE_SEGMENT(
1040  VECTOR2I( pts[ii - 1] ), VECTOR2I( pts[ii] ), aItem->GetWidth() ) );
1041  }
1042  break;
1043  }
1044 
1045  case S_POLYGON:
1046  if( !aItem->IsPolygonFilled() )
1047  {
1048  auto poly = aItem->BuildPolyPointsList();
1049  for( size_t ii = 1; ii < poly.size(); ii++ )
1050  {
1051  segs.push_back( new SHAPE_SEGMENT(
1052  VECTOR2I( poly[ii - 1] ), VECTOR2I( poly[ii] ), aItem->GetWidth() ) );
1053  }
1054 
1055  segs.push_back( new SHAPE_SEGMENT(
1056  VECTOR2I( poly.back() ), VECTOR2I( poly.front() ), aItem->GetWidth() ) );
1057  }
1058  break;
1059 
1060  default:
1061  break;
1062  }
1063 
1064  for( auto seg : segs )
1065  {
1066  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
1067 
1068  if( aItem->GetLayer() == Edge_Cuts )
1069  solid->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
1070  else
1071  solid->SetLayer( aItem->GetLayer() );
1072 
1073  solid->SetNet( -1 );
1074  solid->SetParent( nullptr );
1075  solid->SetShape( seg );
1076  solid->SetRoutable( false );
1077 
1078  aWorld->Add( std::move( solid ) );
1079  }
1080 
1081  return true;
1082 }
1083 
1084 
1086 {
1087  m_board = aBoard;
1088  wxLogTrace( "PNS", "m_board = %p", m_board );
1089 }
1090 
1091 
1093 {
1094  if( !m_view )
1095  return false;
1096 
1097  for( int i = aLayer.Start(); i <= aLayer.End(); i++ )
1098  if( m_view->IsLayerVisible( i ) )
1099  return true;
1100 
1101  return false;
1102 }
1103 
1104 
1106 {
1107  // by default, all items are visible (new ones created by the router have parent == NULL as they have not been
1108  // committed yet to the BOARD)
1109  if( !m_view || !aItem->Parent() )
1110  return true;
1111 
1112  auto item = aItem->Parent();
1113  bool isOnVisibleLayer = true;
1114 
1116  {
1117  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
1118  int layers_count;
1119  auto activeLayers = m_view->GetPainter()->GetSettings()->GetActiveLayers();
1120 
1121  isOnVisibleLayer = false;
1122  item->ViewGetLayers( layers, layers_count );
1123 
1124  for( int i = 0; i < layers_count; ++i )
1125  {
1126  // Item is on at least one of the active layers
1127  if( activeLayers.count( layers[i] ) > 0 )
1128  {
1129  isOnVisibleLayer = true;
1130  break;
1131  }
1132  }
1133  }
1134 
1135  if( m_view->IsVisible( item ) && isOnVisibleLayer
1136  && item->ViewGetLOD( item->GetLayer(), m_view ) < m_view->GetScale() )
1137  return true;
1138 
1139  // Items hidden in the router are not hidden on the board
1140  if( m_hiddenItems.find( item ) != m_hiddenItems.end() )
1141  return true;
1142 
1143  return false;
1144 }
1145 
1146 
1148 {
1149  int worstPadClearance = 0;
1150 
1151  if( !m_board )
1152  {
1153  wxLogTrace( "PNS", "No board attached, aborting sync." );
1154  return;
1155  }
1156 
1157  for( auto gitem : m_board->Drawings() )
1158  {
1159  if ( gitem->Type() == PCB_LINE_T )
1160  {
1161  syncGraphicalItem( aWorld, static_cast<DRAWSEGMENT*>( gitem ) );
1162  }
1163  else if( gitem->Type() == PCB_TEXT_T )
1164  {
1165  syncTextItem( aWorld, static_cast<TEXTE_PCB*>( gitem ), gitem->GetLayer() );
1166  }
1167  }
1168 
1169  for( auto zone : m_board->Zones() )
1170  {
1171  syncZone( aWorld, zone );
1172  }
1173 
1174  for( auto module : m_board->Modules() )
1175  {
1176  for( auto pad : module->Pads() )
1177  {
1178  if( auto solid = syncPad( pad ) )
1179  aWorld->Add( std::move( solid ) );
1180 
1181  worstPadClearance = std::max( worstPadClearance, pad->GetLocalClearance() );
1182  }
1183 
1184  syncTextItem( aWorld, &module->Reference(), module->Reference().GetLayer() );
1185  syncTextItem( aWorld, &module->Value(), module->Value().GetLayer() );
1186 
1187  for( MODULE_ZONE_CONTAINER* zone : module->Zones() )
1188  syncZone( aWorld, zone );
1189 
1190  if( module->IsNetTie() )
1191  continue;
1192 
1193  for( auto mgitem : module->GraphicalItems() )
1194  {
1195  if( mgitem->Type() == PCB_MODULE_EDGE_T )
1196  {
1197  syncGraphicalItem( aWorld, static_cast<DRAWSEGMENT*>( mgitem ) );
1198  }
1199  else if( mgitem->Type() == PCB_MODULE_TEXT_T )
1200  {
1201  syncTextItem( aWorld, static_cast<TEXTE_MODULE*>( mgitem ), mgitem->GetLayer() );
1202  }
1203  }
1204  }
1205 
1206  for( auto t : m_board->Tracks() )
1207  {
1208  KICAD_T type = t->Type();
1209 
1210  if( type == PCB_TRACE_T )
1211  {
1212  if( auto segment = syncTrack( t ) )
1213  aWorld->Add( std::move( segment ) );
1214  }
1215  else if( type == PCB_ARC_T )
1216  {
1217  if( auto arc = syncArc( static_cast<ARC*>( t ) ) )
1218  aWorld->Add( std::move( arc ) );
1219  }
1220  else if( type == PCB_VIA_T )
1221  {
1222  if( auto via = syncVia( static_cast<VIA*>( t ) ) )
1223  aWorld->Add( std::move( via ) );
1224  }
1225  }
1226 
1227  int worstRuleClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
1228 
1229  delete m_ruleResolver;
1231 
1232  aWorld->SetRuleResolver( m_ruleResolver );
1233  aWorld->SetMaxClearance( 4 * std::max(worstPadClearance, worstRuleClearance ) );
1234 }
1235 
1236 
1238 {
1239  for( auto item : m_hiddenItems )
1240  m_view->SetVisible( item, true );
1241 
1242  m_hiddenItems.clear();
1243 
1244  if( m_previewItems )
1245  {
1248  }
1249 
1250  if( m_debugDecorator )
1252 }
1253 
1255 {
1256  m_debugDecorator = aDec;
1257 }
1258 
1259 void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aColor, int aClearance, bool aEdit )
1260 {
1261  wxLogTrace( "PNS", "DisplayItem %p", aItem );
1262 
1263  ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view );
1264 
1265  if( aColor >= 0 )
1266  pitem->SetColor( KIGFX::COLOR4D( aColor ) );
1267 
1268  if( aClearance >= 0 )
1269  {
1270  pitem->SetClearance( aClearance );
1271 
1273  {
1275  pitem->ShowTrackClearance( false );
1276  pitem->ShowViaClearance( false );
1277  break;
1280  pitem->ShowTrackClearance( true );
1281  pitem->ShowViaClearance( true );
1282  break;
1283 
1285  pitem->ShowTrackClearance( !aEdit );
1286  pitem->ShowViaClearance( !aEdit );
1287  break;
1288 
1290  pitem->ShowTrackClearance( !aEdit );
1291  pitem->ShowViaClearance( false );
1292  break;
1293  }
1294  }
1295 
1296 
1297  m_previewItems->Add( pitem );
1299 }
1300 
1301 
1303 {
1304  BOARD_CONNECTED_ITEM* parent = aItem->Parent();
1305 
1306  if( parent )
1307  {
1308  if( m_view->IsVisible( parent ) )
1309  m_hiddenItems.insert( parent );
1310 
1311  m_view->SetVisible( parent, false );
1312  m_view->Update( parent, KIGFX::APPEARANCE );
1313  }
1314 }
1315 
1316 
1318 {
1319 
1320 }
1321 
1322 
1324 {
1325  BOARD_CONNECTED_ITEM* parent = aItem->Parent();
1326 
1327  if ( aItem->OfKind(PNS::ITEM::SOLID_T) )
1328  {
1329  auto pad = static_cast<D_PAD*>( parent );
1330  auto pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1331 
1332  m_moduleOffsets[ pad ].p_old = pos;
1333  return;
1334  }
1335 
1336  if( parent )
1337  {
1338  m_commit->Remove( parent );
1339  }
1340 }
1341 
1342 
1344 {
1345 
1346 }
1347 
1348 
1350 {
1351  BOARD_CONNECTED_ITEM* newBI = NULL;
1352 
1353  switch( aItem->Kind() )
1354  {
1355  case PNS::ITEM::ARC_T:
1356  {
1357  auto arc = static_cast<PNS::ARC*>( aItem );
1358  ARC* new_arc = new ARC( m_board, static_cast<const SHAPE_ARC*>( arc->Shape() ) );
1359  new_arc->SetWidth( arc->Width() );
1360  new_arc->SetLayer( ToLAYER_ID( arc->Layers().Start() ) );
1361  new_arc->SetNetCode( std::max<int>( 0, arc->Net() ) );
1362  newBI = new_arc;
1363  break;
1364  }
1365 
1366  case PNS::ITEM::SEGMENT_T:
1367  {
1368  PNS::SEGMENT* seg = static_cast<PNS::SEGMENT*>( aItem );
1369  TRACK* track = new TRACK( m_board );
1370  const SEG& s = seg->Seg();
1371  track->SetStart( wxPoint( s.A.x, s.A.y ) );
1372  track->SetEnd( wxPoint( s.B.x, s.B.y ) );
1373  track->SetWidth( seg->Width() );
1374  track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) );
1375  track->SetNetCode( seg->Net() > 0 ? seg->Net() : 0 );
1376  newBI = track;
1377  break;
1378  }
1379 
1380  case PNS::ITEM::VIA_T:
1381  {
1382  VIA* via_board = new VIA( m_board );
1383  PNS::VIA* via = static_cast<PNS::VIA*>( aItem );
1384  via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
1385  via_board->SetWidth( via->Diameter() );
1386  via_board->SetDrill( via->Drill() );
1387  via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
1388  via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
1389  via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
1390  ToLAYER_ID( via->Layers().End() ) );
1391  newBI = via_board;
1392  break;
1393  }
1394 
1395  case PNS::ITEM::SOLID_T:
1396  {
1397  auto pad = static_cast<D_PAD*>( aItem->Parent() );
1398  auto pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1399 
1400  m_moduleOffsets[ pad ].p_new = pos;
1401  return;
1402  }
1403 
1404  default:
1405  break;
1406  }
1407 
1408  if( newBI )
1409  {
1410  //newBI->SetLocalRatsnestVisible( m_dispOptions->m_ShowGlobalRatsnest );
1411  aItem->SetParent( newBI );
1412  newBI->ClearFlags();
1413 
1414  m_commit->Add( newBI );
1415  }
1416 }
1417 
1418 
1420 {
1421  std::set<MODULE*> processedMods;
1422 
1423  EraseView();
1424 
1425  for( auto mo : m_moduleOffsets )
1426  {
1427  auto offset = mo.second.p_new - mo.second.p_old;
1428  auto mod = mo.first->GetParent();
1429 
1430  VECTOR2I p_orig = mod->GetPosition();
1431  VECTOR2I p_new = p_orig + offset;
1432 
1433  if( processedMods.find( mod ) != processedMods.end() )
1434  continue;
1435 
1436  processedMods.insert( mod );
1437  m_commit->Modify( mod );
1438  mod->SetPosition( wxPoint( p_new.x, p_new.y ));
1439  }
1440 
1441  m_moduleOffsets.clear();
1442 
1443  m_commit->Push( _( "Interactive Router" ) );
1444  m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1445 }
1446 
1447 
1449 {
1450  wxLogTrace( "PNS", "SetView %p", aView );
1451 
1452  if( m_previewItems )
1453  {
1455  delete m_previewItems;
1456  }
1457 
1458  m_view = aView;
1461 
1462  if(m_view)
1464 
1465  delete m_debugDecorator;
1466 
1467  auto dec = new PNS_PCBNEW_DEBUG_DECORATOR();
1468  dec->SetView( m_view );
1469 
1470  m_debugDecorator = dec;
1471 }
1472 
1473 
1474 void PNS_KICAD_IFACE::UpdateNet( int aNetCode )
1475 {
1476  wxLogTrace( "PNS", "Update-net %d", aNetCode );
1477 
1478 }
1479 
1481 {
1482  return m_ruleResolver;
1483 }
1484 
1485 
1487 {
1488  m_router = aRouter;
1489 }
1490 
1491 
1493 {
1494  m_tool = aTool;
1495  m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1496 }
1497 
1499 {
1500  m_dispOptions = aDispOptions;
1501 }
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:126
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)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:686
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:53
int localPadClearance(const PNS::ITEM *aItem) const
void AddSegment(SEG aS, int aColor, const std::string aName="") override
bool syncTextItem(PNS::NODE *aWorld, EDA_TEXT *aText, PCB_LAYER_ID aLayer)
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
void AddDirections(VECTOR2D aP, int aMask, int aColor, const std::string aName="") override
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
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:42
BOARD_CONNECTED_ITEM * Parent() const
Definition: pns_item.h:146
void SetView(KIGFX::VIEW *aView)
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox
Definition: confirm.cpp:53
void SetRouter(PNS::ROUTER *aRouter) override
int GetNetCode() const
Function GetNetCode.
virtual bool DpNetPair(PNS::ITEM *aItem, int &aNetP, int &aNetN) override
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:145
NETCLASSPTR Find(const wxString &aName) const
Function Find searches this container for a NETCLASS given by aName.
Definition: netclass.cpp:141
TEXTE_PCB class definition.
like PAD_STANDARD, but not plated mechanical use only, no connection allowed
Definition: pad_shapes.h:66
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition: confirm.h:44
void SetPosition(const wxPoint &aPoint) override
Definition: class_track.h:390
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
This file is part of the common library.
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:107
const wxPoint GetCenter() const override
Function GetCenter()
int GetBiggestClearanceValue()
Function GetBiggestClearanceValue.
bool syncGraphicalItem(PNS::NODE *aWorld, DRAWSEGMENT *aItem)
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
const wxPoint & GetStart() const
Definition: class_track.h:111
STROKE_T GetShape() const
VIATYPE ViaType() const
Definition: pns_via.h:111
PNS::DEBUG_DECORATOR * m_debugDecorator
const VECTOR2I ToVector() const
Function ToVector()
Definition: direction45.h:269
int BuildSegmentFromOvalShape(wxPoint &aSegStart, wxPoint &aSegEnd, double aRotation, const wxSize &aMargin) const
Function BuildSegmentFromOvalShape Has meaning only for OVAL (and ROUND) pads Build an equivalent seg...
int Width() const override
Definition: pns_segment.h:78
std::unordered_set< BOARD_CONNECTED_ITEM * > m_hiddenItems
void UpdateNet(int aNetCode) override
polygon (not yet used for tracks, but could be in microwave apps)
void RebuildBezierToSegmentsPointsList(int aMinSegLen)
Rebuild the m_BezierPoints vertex list that approximate the Bezier curve by a list of segments Has me...
int GetPadToDieLength() const
Definition: class_pad.h:459
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:62
void BuildPadShapePolygon(SHAPE_POLY_SET &aCornerBuffer, wxSize aInflateValue, int aError=ARC_HIGH_DEF) const
Function BuildPadShapePolygon Build the Corner list of the polygonal shape, depending on shape,...
void SetClearance(int aClearance)
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
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
Function GetDesignSettings.
Definition: class_board.h:512
int GetThickness() const
Return the pen width.
Definition: eda_text.h:148
void SetDebugDecorator(PNS::DEBUG_DECORATOR *aDec)
usual segment : line with rounded ends
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
bool IsAnyLayerVisible(const LAYER_RANGE &aLayer) override
const std::vector< wxPoint > & GetBezierPoints() const
No updates are required.
Definition: view_item.h:55
RULE_RESOLVER.
Definition: pns_node.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
void ShowTrackClearance(bool aEnabled)
virtual VECTOR2I Centre() const
Function Centre()
Definition: shape.h:153
void RotatePoint(int *pX, int *pY, double angle)
Definition: trigo.cpp:208
const std::vector< wxPoint > BuildPolyPointsList() const
Build and return the list of corners in a std::vector<wxPoint> It must be used only to convert the SH...
void SetRuleResolver(RULE_RESOLVER *aFunc)
Assigns a clerance resolution function object
Definition: pns_node.h:171
void HideItem(PNS::ITEM *aItem) override
void AddBox(BOX2I aB, int aColor, const std::string aName="") override
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
const wxPoint & GetEnd() const
Function GetEnd returns the ending point of the graphic.
int PointCount() const
Function PointCount()
const wxPoint GetPosition() const override
Definition: class_zone.cpp:207
BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected and have...
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
const VECTOR2I & Pos() const
Definition: pns_via.h:100
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
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
PAD_ATTR_T GetAttribute() const
Definition: class_pad.h:449
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:701
Definitions for tracks, vias and zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
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:104
int Start() const
Definition: pns_layerset.h:83
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:165
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition: eda_text.h:109
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_zone.cpp:277
void GetColinearCorners(BOARD *aBoard, std::set< VECTOR2I > &colinearCorners)
Some intersecting zones, despite being on the same layer with the same net, cannot be merged due to o...
const VECTOR2I & CPoint(int aIndex) const
Function Point()
void SetParent(BOARD_CONNECTED_ITEM *aParent)
Definition: pns_item.h:145
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:121
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.
Footprint text class description.
#define NULL
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:742
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:229
bool IsVisible(const VIEW_ITEM *aItem) const
Returns information if the item is visible (or not).
Definition: view.cpp:1526
SHAPE_POLY_SET.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
std::unique_ptr< BOARD_COMMIT > m_commit
virtual const SHAPE * Shape() const
Function Shape()
Definition: pns_item.h:214
int Net() const
Definition: pns_item.h:149
DIRECTION_45.
Definition: direction45.h:37
bool BuildSmoothedPoly(SHAPE_POLY_SET &aSmoothedPoly, std::set< VECTOR2I > *aPreserveCorners) const
Function GetSmoothedPoly returns a pointer to the corner-smoothed version of m_Poly.
Arcs (with rounded ends)
const wxPoint & GetOffset() const
Definition: class_pad.h:309
VECTOR2I::extended_type ecoord
virtual int DpCoupledNet(int aNet) override
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:432
LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
Definition: class_pad.h:446
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:544
void ShowViaClearance(bool aEnabled)
std::vector< CLEARANCE_ENT > m_netClearanceCache
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:232
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
KIGFX::VIEW_GROUP * m_previewItems
const wxPoint & GetArcStart() const
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.
bool syncZone(PNS::NODE *aWorld, ZONE_CONTAINER *aZone)
void SyncWorld(PNS::NODE *aWorld) override
Bezier Curve.
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1540
Like smd, does not appear on the solder paste layer (default) note also has a special attribute in Ge...
Definition: pad_shapes.h:63
void SetColor(const KIGFX::COLOR4D &aColor)
const wxPoint GetPosition() const override
Definition: class_track.h:389
virtual void SetLayer(int aLayer)
Function SetLayer() Sets layer used to draw the group.
Definition: view_group.h:115
CONST_ITERATOR CIterate(int aFirst, int aLast, bool aIterateHoles=false) const
void AddItem(PNS::ITEM *aItem) override
const PCB_DISPLAY_OPTIONS * m_dispOptions
void Commit() override
PNS::ROUTER * m_router
int GetWidth() const
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:649
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:947
void BuildPadPolygon(wxPoint aCoord[4], wxSize aInflateValue, double aRotation) const
Function BuildPadPolygon Has meaning only for polygonal pads (trapezoid and rectangular) Build the Co...
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
Definition: seg.h:39
bool IsItemVisible(const PNS::ITEM *aItem) override
double GetAngle() const
bool GetHighContrast() const
Function GetHighContrast Returns information about high contrast display mode.
Definition: painter.h:158
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 GetSettings Returns pointer to current settings that are going to be used when drawing items...
double GetAngle() const
std::unique_ptr< PNS::ARC > syncArc(ARC *aArc)
KIGFX::VIEW * m_view
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
ZONE_CONTAINERS & Zones()
Definition: class_board.h:243
int GetWidth() const
Definition: class_track.h:105
Board layer functions and definitions.
Class to handle a graphic segment.
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:205
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:224
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
void AddPoint(VECTOR2I aP, int aColor, const std::string aName="") override
#define _(s)
Definition: 3d_actions.cpp:33
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 tenths of degrees,...
Definition: class_pad.h:426
void CustomShapeAsPolygonToBoardPosition(SHAPE_POLY_SET *aMergedPolygon, wxPoint aPosition, double aRotation) const
When created, the corners coordinates are relative to the pad position, orientation 0,...
const wxSize & GetDrillSize() const
Definition: class_pad.h:306
VECTOR2I A
Definition: seg.h:47
bool OfKind(int aKindMask) const
Function OfKind()
Definition: pns_item.h:133
wxPoint ShapePos() const
Definition: class_pad.cpp:570
const SHAPE_POLY_SET & GetCustomShapeAsPolygon() const
Accessor to the custom shape as one polygon.
Definition: class_pad.h:378
void AddItem(PNS::ITEM *aItem) override
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:431
void SetView(KIGFX::VIEW *aView)
int matchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
VIATYPE GetViaType() const
Definition: class_track.h:416
currently selected items overlay
MODULE_ZONE_CONTAINER is the same item as ZONE_CONTAINER, but with a specific type id ZONE_CONTAINER ...
Definition: class_zone.h:848
PCB_TOOL_BASE * m_tool
VECTOR2I::extended_type ecoord
const wxPoint & GetEnd() const
Definition: class_track.h:108
bool GetDoNotAllowTracks() const
Definition: class_zone.h:652
int ShowModal() override
Definition: confirm.cpp:95
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
PnsKind Kind() const
Function Kind()
Definition: pns_item.h:123
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:258
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1486
void Clear()
Function Clear() Removes all points from the line chain.
virtual const wxPoint GetCenter() const
Function GetCenter()
void SetStart(const wxPoint &aStart)
Definition: class_track.h:110
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
const wxPoint & GetStart() const
Function GetStart returns the starting point of the graphic.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:346
const Vec & GetSize() const
Definition: box2.h:188
std::map< D_PAD *, OFFSET > m_moduleOffsets
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:237
Module description (excepted pads)
PNS_PCBNEW_RULE_RESOLVER * m_ruleResolver
virtual int Clearance(const PNS::ITEM *aA, const PNS::ITEM *aB) const override
const Vec & GetOrigin() const
Definition: box2.h:192
VIEW.
Definition: view.h:61
const wxSize & GetSize() const
Definition: class_pad.h:300
double GetScale() const
Function GetScale()
Definition: view.h:257
EDGE_MODULE class definition.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
int Drill() const
Definition: pns_via.h:132
wxString GetClassName() const
Function GetClassName returns the class name.
Definition: netinfo.h:131
Push and Shove diff pair dimensions (gap) settings dialog.
void SetViaType(VIATYPE aViaType)
Definition: class_track.h:421
const SHAPE_LINE_CHAIN ConvertToPolyline(double aAccuracy=500.0) const
Constructs a SHAPE_LINE_CHAIN of segments from a given arc.
Definition: shape_arc.cpp:274
NODE * GetWorld() const
Definition: pns_router.h:152
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
bool IsPolygonFilled() const
Polygonal shape is not always filled.
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
std::unordered_map< const D_PAD *, int > m_localClearanceCache
DRAWINGS & Drawings()
Definition: class_board.h:238
bool Add(std::unique_ptr< SEGMENT > aSegment, bool aAllowRedundant=false)
Function Add()
Definition: pns_node.cpp:620
void Append(int aX, int aY)
Function Append()
Definition: shape_simple.h:137
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:823
PNS_PCBNEW_RULE_RESOLVER(BOARD *aBoard, PNS::ROUTER *aRouter)
TRACKS & Tracks()
Definition: class_board.h:220
std::unique_ptr< PNS::SEGMENT > syncTrack(TRACK *aTrack)
LAYER_RANGE.
Definition: pns_layerset.h:32
const LAYER_RANGE & Layers() const
Definition: pns_item.h:151
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
void RemoveItem(PNS::ITEM *aItem) override
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
const std::set< unsigned int > GetActiveLayers()
Function GetActiveLayers() Returns the set of currently active layers.
Definition: painter.h:84
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:416
int Append(int x, int y, int aOutline=-1, int aHole=-1, bool aAllowDuplication=false)
Appends a vertex at the end of the given outline/hole (default: the last outline)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:40
VECTOR2I B
Definition: seg.h:48