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  m_router = nullptr;
536 }
537 
538 
540 {
541  m_tool = nullptr;
542  m_view = nullptr;
543  m_previewItems = nullptr;
544  m_dispOptions = nullptr;
545 }
546 
547 
549 {
550  delete m_ruleResolver;
551  delete m_debugDecorator;
552 }
553 
554 
556 {
557  if( m_previewItems )
558  {
560  delete m_previewItems;
561  }
562 }
563 
564 
565 std::unique_ptr<PNS::SOLID> PNS_KICAD_IFACE_BASE::syncPad( D_PAD* aPad )
566 {
567  LAYER_RANGE layers( 0, MAX_CU_LAYERS - 1 );
568 
569  // ignore non-copper pads
570  if( ( aPad->GetLayerSet() & LSET::AllCuMask()).none() )
571  return NULL;
572 
573  switch( aPad->GetAttribute() )
574  {
575  case PAD_ATTRIB_STANDARD:
576  break;
577 
578  case PAD_ATTRIB_SMD:
580  case PAD_ATTRIB_CONN:
581  {
582  LSET lmsk = aPad->GetLayerSet();
583  bool is_copper = false;
584 
585  for( int i = 0; i < MAX_CU_LAYERS; i++ )
586  {
587  if( lmsk[i] )
588  {
589  is_copper = true;
590 
592  layers = LAYER_RANGE( i );
593 
594  break;
595  }
596  }
597 
598  if( !is_copper )
599  return NULL;
600  }
601  break;
602 
603  default:
604  wxLogTrace( "PNS", "unsupported pad type 0x%x", aPad->GetAttribute() );
605  return NULL;
606  }
607 
608  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
609 
610  solid->SetLayers( layers );
611  solid->SetNet( aPad->GetNetCode() );
612  solid->SetParent( aPad );
613  solid->SetPadToDie( aPad->GetPadToDieLength() );
614 
615  wxPoint wx_c = aPad->ShapePos();
616  wxSize wx_sz = aPad->GetSize();
617  wxPoint offset = aPad->GetOffset();
618 
619  VECTOR2I c( wx_c.x, wx_c.y );
620  VECTOR2I sz( wx_sz.x, wx_sz.y );
621 
622  RotatePoint( &offset, aPad->GetOrientation() );
623 
624  solid->SetPos( VECTOR2I( c.x - offset.x, c.y - offset.y ) );
625  solid->SetOffset( VECTOR2I( offset.x, offset.y ) );
626 
627  double orient = aPad->GetOrientation() / 10.0;
628 
629  if( aPad->GetShape() == PAD_SHAPE_CIRCLE )
630  {
631  solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
632  }
633  else if( aPad->GetShape() == PAD_SHAPE_CUSTOM )
634  {
635  SHAPE_POLY_SET outline;
636  outline.Append( aPad->GetCustomShapeAsPolygon() );
637  aPad->CustomShapeAsPolygonToBoardPosition( &outline, wx_c, aPad->GetOrientation() );
638 
639  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
640 
641  for( auto iter = outline.CIterate( 0 ); iter; iter++ )
642  shape->Append( *iter );
643 
644  solid->SetShape( shape );
645  }
646  else
647  {
648  if( orient == 0.0 || orient == 90.0 || orient == 180.0 || orient == 270.0 )
649  {
650  if( orient == 90.0 || orient == 270.0 )
651  sz = VECTOR2I( sz.y, sz.x );
652 
653  switch( aPad->GetShape() )
654  {
655  case PAD_SHAPE_OVAL:
656  if( sz.x == sz.y )
657  solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
658  else
659  {
660  VECTOR2I delta;
661 
662  if( sz.x > sz.y )
663  delta = VECTOR2I( ( sz.x - sz.y ) / 2, 0 );
664  else
665  delta = VECTOR2I( 0, ( sz.y - sz.x ) / 2 );
666 
667  SHAPE_SEGMENT* shape = new SHAPE_SEGMENT( c - delta, c + delta,
668  std::min( sz.x, sz.y ) );
669  solid->SetShape( shape );
670  }
671  break;
672 
673  case PAD_SHAPE_RECT:
674  solid->SetShape( new SHAPE_RECT( c - sz / 2, sz.x, sz.y ) );
675  break;
676 
677  case PAD_SHAPE_TRAPEZOID:
678  {
679  wxPoint coords[4];
680  aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
681  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
682 
683  for( int ii = 0; ii < 4; ii++ )
684  {
685  shape->Append( wx_c + coords[ii] );
686  }
687 
688  solid->SetShape( shape );
689  break;
690  }
691 
693  case PAD_SHAPE_ROUNDRECT:
694  {
695  SHAPE_POLY_SET outline;
696  aPad->BuildPadShapePolygon( outline, wxSize( 0, 0 ) );
697 
698  // TransformRoundRectToPolygon creates only one convex polygon
699  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
700  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
701 
702  for( int ii = 0; ii < poly.PointCount(); ++ii )
703  shape->Append( poly.CPoint( ii ) );
704 
705  solid->SetShape( shape );
706  }
707  break;
708 
709  default:
710  wxLogTrace( "PNS", "unsupported pad shape" );
711  return nullptr;
712  }
713  }
714  else
715  {
716  switch( aPad->GetShape() )
717  {
718  // PAD_SHAPE_CIRCLE and PAD_SHAPE_CUSTOM already handled above
719 
720  case PAD_SHAPE_OVAL:
721  if( sz.x == sz.y )
722  solid->SetShape( new SHAPE_CIRCLE( c, sz.x / 2 ) );
723  else
724  {
725  wxPoint start;
726  wxPoint end;
727  wxPoint corner;
728 
729  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
730 
731  int w = aPad->BuildSegmentFromOvalShape( start, end, 0.0, wxSize( 0, 0 ) );
732 
733  if( start.y == 0 )
734  corner = wxPoint( start.x, -( w / 2 ) );
735  else
736  corner = wxPoint( w / 2, start.y );
737 
738  RotatePoint( &start, aPad->GetOrientation() );
739  RotatePoint( &corner, aPad->GetOrientation() );
740  shape->Append( wx_c + corner );
741 
742  for( int rot = 100; rot <= 1800; rot += 100 )
743  {
744  wxPoint p( corner );
745  RotatePoint( &p, start, rot );
746  shape->Append( wx_c + p );
747  }
748 
749  if( end.y == 0 )
750  corner = wxPoint( end.x, w / 2 );
751  else
752  corner = wxPoint( -( w / 2 ), end.y );
753 
754  RotatePoint( &end, aPad->GetOrientation() );
755  RotatePoint( &corner, aPad->GetOrientation() );
756  shape->Append( wx_c + corner );
757 
758  for( int rot = 100; rot <= 1800; rot += 100 )
759  {
760  wxPoint p( corner );
761  RotatePoint( &p, end, rot );
762  shape->Append( wx_c + p );
763  }
764 
765  solid->SetShape( shape );
766  }
767  break;
768 
769  case PAD_SHAPE_RECT:
770  case PAD_SHAPE_TRAPEZOID:
771  {
772  wxPoint coords[4];
773  aPad->BuildPadPolygon( coords, wxSize( 0, 0 ), aPad->GetOrientation() );
774 
775  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
776  for( int ii = 0; ii < 4; ii++ )
777  {
778  shape->Append( wx_c + coords[ii] );
779  }
780 
781  solid->SetShape( shape );
782  break;
783  }
784 
786  case PAD_SHAPE_ROUNDRECT:
787  {
788  SHAPE_POLY_SET outline;
789  aPad->BuildPadShapePolygon( outline, wxSize( 0, 0 ) );
790 
791  // TransformRoundRectToPolygon creates only one convex polygon
792  SHAPE_LINE_CHAIN& poly = outline.Outline( 0 );
793  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
794 
795  for( int ii = 0; ii < poly.PointCount(); ++ii )
796  {
797  shape->Append( wxPoint( poly.CPoint( ii ).x, poly.CPoint( ii ).y ) );
798  }
799 
800  solid->SetShape( shape );
801  break;
802  }
803 
804  default:
805  wxLogTrace( "PNS", "unsupported pad shape" );
806  return nullptr;
807  }
808  }
809  }
810  return solid;
811 }
812 
813 
814 std::unique_ptr<PNS::SEGMENT> PNS_KICAD_IFACE_BASE::syncTrack( TRACK* aTrack )
815 {
816  std::unique_ptr< PNS::SEGMENT > segment(
817  new PNS::SEGMENT( SEG( aTrack->GetStart(), aTrack->GetEnd() ), aTrack->GetNetCode() )
818  );
819 
820  segment->SetWidth( aTrack->GetWidth() );
821  segment->SetLayers( LAYER_RANGE( aTrack->GetLayer() ) );
822  segment->SetParent( aTrack );
823 
824  if( aTrack->IsLocked() )
825  segment->Mark( PNS::MK_LOCKED );
826 
827  return segment;
828 }
829 
830 
831 std::unique_ptr<PNS::ARC> PNS_KICAD_IFACE_BASE::syncArc( ARC* aArc )
832 {
833  std::unique_ptr< PNS::ARC > arc(
834  new PNS::ARC( SHAPE_ARC( aArc->GetCenter(), aArc->GetStart(),
835  aArc->GetAngle(), aArc->GetWidth() ),
836  aArc->GetNetCode() )
837  );
838 
839  arc->SetLayers( LAYER_RANGE( aArc->GetLayer() ) );
840  arc->SetParent( aArc );
841 
842  if( aArc->IsLocked() )
843  arc->Mark( PNS::MK_LOCKED );
844 
845  return arc;
846 }
847 
848 
849 std::unique_ptr<PNS::VIA> PNS_KICAD_IFACE_BASE::syncVia( VIA* aVia )
850 {
851  PCB_LAYER_ID top, bottom;
852  aVia->LayerPair( &top, &bottom );
853  std::unique_ptr<PNS::VIA> via( new PNS::VIA(
854  aVia->GetPosition(),
855  LAYER_RANGE( top, bottom ),
856  aVia->GetWidth(),
857  aVia->GetDrillValue(),
858  aVia->GetNetCode(),
859  aVia->GetViaType() )
860  );
861 
862  via->SetParent( aVia );
863 
864  if( aVia->IsLocked() )
865  via->Mark( PNS::MK_LOCKED );
866 
867  return via;
868 }
869 
870 
872 {
873  SHAPE_POLY_SET poly;
874 
875  // TODO handle no-via restriction
876  if( !aZone->GetIsKeepout() || !aZone->GetDoNotAllowTracks() )
877  return false;
878 
879  // Some intersecting zones, despite being on the same layer with the same net, cannot be
880  // merged due to other parameters such as fillet radius. The copper pour will end up
881  // effectively merged though, so we want to keep the corners of such intersections sharp.
882  std::set<VECTOR2I> colinearCorners;
883  aZone->GetColinearCorners( m_board, colinearCorners );
884 
885  aZone->BuildSmoothedPoly( poly, &colinearCorners );
886  poly.CacheTriangulation();
887 
888  if( !poly.IsTriangulationUpToDate() )
889  {
890  KIDIALOG dlg( nullptr, wxString::Format( _( "Malformed keep-out zone at (%d, %d)" ),
891  aZone->GetPosition().x, aZone->GetPosition().y ), KIDIALOG::KD_WARNING );
892  dlg.ShowDetailedText(
893  wxString::Format( _( "%s\nThis zone cannot be handled by the track layout tool.\n"
894  "Please verify it is not a self-intersecting polygon." ),
896  dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
897  dlg.ShowModal();
898 
899  return false;
900  }
901 
902  LSET layers = aZone->GetLayerSet();
903 
904  for( int layer = F_Cu; layer <= B_Cu; layer++ )
905  {
906  if ( ! layers[layer] )
907  continue;
908 
909  for( int outline = 0; outline < poly.OutlineCount(); outline++ )
910  {
911  auto tri = poly.TriangulatedPolygon( outline );
912 
913  for( size_t i = 0; i < tri->GetTriangleCount(); i++)
914  {
915  VECTOR2I a, b, c;
916  tri->GetTriangle( i, a, b, c );
917  auto triShape = new SHAPE_SIMPLE;
918 
919  triShape->Append( a );
920  triShape->Append( b );
921  triShape->Append( c );
922 
923  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
924 
925  solid->SetLayer( layer );
926  solid->SetNet( -1 );
927  solid->SetParent( aZone );
928  solid->SetShape( triShape );
929  solid->SetRoutable( false );
930 
931  aWorld->Add( std::move( solid ) );
932  }
933  }
934  }
935 
936  return true;
937 }
938 
939 
941 {
942  if( !IsCopperLayer( aLayer ) )
943  return false;
944 
945  int textWidth = aText->GetEffectiveTextPenWidth();
946  std::vector<wxPoint> textShape;
947 
948  aText->TransformTextShapeToSegmentList( textShape );
949 
950  if( textShape.size() < 2 )
951  return false;
952 
953  for( size_t jj = 0; jj < textShape.size(); jj += 2 )
954  {
955  VECTOR2I start( textShape[jj] );
956  VECTOR2I end( textShape[jj+1] );
957  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
958 
959  solid->SetLayer( aLayer );
960  solid->SetNet( -1 );
961  solid->SetParent( nullptr );
962  solid->SetShape( new SHAPE_SEGMENT( start, end, textWidth ) );
963  solid->SetRoutable( false );
964 
965  aWorld->Add( std::move( solid ) );
966  }
967 
968  return true;
969 
970  /* A coarser (but faster) method:
971  *
972  SHAPE_POLY_SET outline;
973  SHAPE_SIMPLE* shape = new SHAPE_SIMPLE();
974 
975  aText->TransformBoundingBoxWithClearanceToPolygon( &outline, 0 );
976 
977  for( auto iter = outline.CIterate( 0 ); iter; iter++ )
978  shape->Append( *iter );
979 
980  solid->SetShape( shape );
981 
982  solid->SetLayer( aLayer );
983  solid->SetNet( -1 );
984  solid->SetParent( nullptr );
985  solid->SetRoutable( false );
986  aWorld->Add( std::move( solid ) );
987  return true;
988  */
989 }
990 
991 
993 {
994  std::vector<SHAPE_SEGMENT*> segs;
995 
996  if( aItem->GetLayer() != Edge_Cuts && !IsCopperLayer( aItem->GetLayer() ) )
997  return false;
998 
999  switch( aItem->GetShape() )
1000  {
1001  case S_ARC:
1002  {
1003  SHAPE_ARC arc( aItem->GetCenter(), aItem->GetArcStart(), aItem->GetAngle() / 10.0 );
1004  auto l = arc.ConvertToPolyline();
1005 
1006  for( int i = 0; i < l.SegmentCount(); i++ )
1007  {
1008  SHAPE_SEGMENT* seg = new SHAPE_SEGMENT( l.CSegment( i ), aItem->GetWidth() );
1009  segs.push_back( seg );
1010  }
1011 
1012  break;
1013  }
1014 
1015  case S_SEGMENT:
1016  segs.push_back(
1017  new SHAPE_SEGMENT( aItem->GetStart(), aItem->GetEnd(), aItem->GetWidth() ) );
1018 
1019  break;
1020 
1021  case S_CIRCLE:
1022  {
1023  // SHAPE_CIRCLE has no ConvertToPolyline() method, so use a 360.0 SHAPE_ARC
1024  SHAPE_ARC circle( aItem->GetCenter(), aItem->GetEnd(), 360.0 );
1025  auto l = circle.ConvertToPolyline();
1026 
1027  for( int i = 0; i < l.SegmentCount(); i++ )
1028  segs.push_back( new SHAPE_SEGMENT( l.CSegment( i ), aItem->GetWidth() ) );
1029 
1030  break;
1031  }
1032 
1033  case S_CURVE:
1034  {
1035  aItem->RebuildBezierToSegmentsPointsList( aItem->GetWidth() );
1036  auto pts = aItem->GetBezierPoints();
1037 
1038  for( size_t ii = 1; ii < pts.size(); ii++ )
1039  {
1040  segs.push_back( new SHAPE_SEGMENT(
1041  VECTOR2I( pts[ii - 1] ), VECTOR2I( pts[ii] ), aItem->GetWidth() ) );
1042  }
1043  break;
1044  }
1045 
1046  case S_POLYGON:
1047  if( !aItem->IsPolygonFilled() )
1048  {
1049  auto poly = aItem->BuildPolyPointsList();
1050  for( size_t ii = 1; ii < poly.size(); ii++ )
1051  {
1052  segs.push_back( new SHAPE_SEGMENT(
1053  VECTOR2I( poly[ii - 1] ), VECTOR2I( poly[ii] ), aItem->GetWidth() ) );
1054  }
1055 
1056  segs.push_back( new SHAPE_SEGMENT(
1057  VECTOR2I( poly.back() ), VECTOR2I( poly.front() ), aItem->GetWidth() ) );
1058  }
1059  break;
1060 
1061  default:
1062  break;
1063  }
1064 
1065  for( auto seg : segs )
1066  {
1067  std::unique_ptr< PNS::SOLID > solid( new PNS::SOLID );
1068 
1069  if( aItem->GetLayer() == Edge_Cuts )
1070  solid->SetLayers( LAYER_RANGE( F_Cu, B_Cu ) );
1071  else
1072  solid->SetLayer( aItem->GetLayer() );
1073 
1074  solid->SetNet( -1 );
1075  solid->SetParent( nullptr );
1076  solid->SetShape( seg );
1077  solid->SetRoutable( false );
1078 
1079  aWorld->Add( std::move( solid ) );
1080  }
1081 
1082  return true;
1083 }
1084 
1085 
1087 {
1088  m_board = aBoard;
1089  wxLogTrace( "PNS", "m_board = %p", m_board );
1090 }
1091 
1092 
1094 {
1095  if( !m_view )
1096  return false;
1097 
1098  for( int i = aLayer.Start(); i <= aLayer.End(); i++ )
1099  if( m_view->IsLayerVisible( i ) )
1100  return true;
1101 
1102  return false;
1103 }
1104 
1105 
1107 {
1108  // by default, all items are visible (new ones created by the router have parent == NULL as they have not been
1109  // committed yet to the BOARD)
1110  if( !m_view || !aItem->Parent() )
1111  return true;
1112 
1113  auto item = aItem->Parent();
1114  bool isOnVisibleLayer = true;
1115 
1117  {
1118  int layers[KIGFX::VIEW::VIEW_MAX_LAYERS];
1119  int layers_count;
1120  auto activeLayers = m_view->GetPainter()->GetSettings()->GetActiveLayers();
1121 
1122  isOnVisibleLayer = false;
1123  item->ViewGetLayers( layers, layers_count );
1124 
1125  for( int i = 0; i < layers_count; ++i )
1126  {
1127  // Item is on at least one of the active layers
1128  if( activeLayers.count( layers[i] ) > 0 )
1129  {
1130  isOnVisibleLayer = true;
1131  break;
1132  }
1133  }
1134  }
1135 
1136  if( m_view->IsVisible( item ) && isOnVisibleLayer
1137  && item->ViewGetLOD( item->GetLayer(), m_view ) < m_view->GetScale() )
1138  return true;
1139 
1140  // Items hidden in the router are not hidden on the board
1141  if( m_hiddenItems.find( item ) != m_hiddenItems.end() )
1142  return true;
1143 
1144  return false;
1145 }
1146 
1147 
1149 {
1150  int worstPadClearance = 0;
1151 
1152  if( !m_board )
1153  {
1154  wxLogTrace( "PNS", "No board attached, aborting sync." );
1155  return;
1156  }
1157 
1158  for( auto gitem : m_board->Drawings() )
1159  {
1160  if ( gitem->Type() == PCB_LINE_T )
1161  {
1162  syncGraphicalItem( aWorld, static_cast<DRAWSEGMENT*>( gitem ) );
1163  }
1164  else if( gitem->Type() == PCB_TEXT_T )
1165  {
1166  syncTextItem( aWorld, static_cast<TEXTE_PCB*>( gitem ), gitem->GetLayer() );
1167  }
1168  }
1169 
1170  for( auto zone : m_board->Zones() )
1171  {
1172  syncZone( aWorld, zone );
1173  }
1174 
1175  for( auto module : m_board->Modules() )
1176  {
1177  for( auto pad : module->Pads() )
1178  {
1179  if( auto solid = syncPad( pad ) )
1180  aWorld->Add( std::move( solid ) );
1181 
1182  worstPadClearance = std::max( worstPadClearance, pad->GetLocalClearance() );
1183  }
1184 
1185  syncTextItem( aWorld, &module->Reference(), module->Reference().GetLayer() );
1186  syncTextItem( aWorld, &module->Value(), module->Value().GetLayer() );
1187 
1188  for( MODULE_ZONE_CONTAINER* zone : module->Zones() )
1189  syncZone( aWorld, zone );
1190 
1191  if( module->IsNetTie() )
1192  continue;
1193 
1194  for( auto mgitem : module->GraphicalItems() )
1195  {
1196  if( mgitem->Type() == PCB_MODULE_EDGE_T )
1197  {
1198  syncGraphicalItem( aWorld, static_cast<DRAWSEGMENT*>( mgitem ) );
1199  }
1200  else if( mgitem->Type() == PCB_MODULE_TEXT_T )
1201  {
1202  syncTextItem( aWorld, static_cast<TEXTE_MODULE*>( mgitem ), mgitem->GetLayer() );
1203  }
1204  }
1205  }
1206 
1207  for( auto t : m_board->Tracks() )
1208  {
1209  KICAD_T type = t->Type();
1210 
1211  if( type == PCB_TRACE_T )
1212  {
1213  if( auto segment = syncTrack( t ) )
1214  aWorld->Add( std::move( segment ) );
1215  }
1216  else if( type == PCB_ARC_T )
1217  {
1218  if( auto arc = syncArc( static_cast<ARC*>( t ) ) )
1219  aWorld->Add( std::move( arc ) );
1220  }
1221  else if( type == PCB_VIA_T )
1222  {
1223  if( auto via = syncVia( static_cast<VIA*>( t ) ) )
1224  aWorld->Add( std::move( via ) );
1225  }
1226  }
1227 
1228  int worstRuleClearance = m_board->GetDesignSettings().GetBiggestClearanceValue();
1229 
1230  delete m_ruleResolver;
1232 
1233  aWorld->SetRuleResolver( m_ruleResolver );
1234  aWorld->SetMaxClearance( 4 * std::max(worstPadClearance, worstRuleClearance ) );
1235 }
1236 
1237 
1239 {
1240  for( auto item : m_hiddenItems )
1241  m_view->SetVisible( item, true );
1242 
1243  m_hiddenItems.clear();
1244 
1245  if( m_previewItems )
1246  {
1249  }
1250 
1251  if( m_debugDecorator )
1253 }
1254 
1256 {
1257  m_debugDecorator = aDec;
1258 }
1259 
1260 void PNS_KICAD_IFACE::DisplayItem( const PNS::ITEM* aItem, int aColor, int aClearance, bool aEdit )
1261 {
1262  wxLogTrace( "PNS", "DisplayItem %p", aItem );
1263 
1264  ROUTER_PREVIEW_ITEM* pitem = new ROUTER_PREVIEW_ITEM( aItem, m_view );
1265 
1266  if( aColor >= 0 )
1267  pitem->SetColor( KIGFX::COLOR4D( aColor ) );
1268 
1269  if( aClearance >= 0 )
1270  {
1271  pitem->SetClearance( aClearance );
1272 
1274  {
1276  pitem->ShowTrackClearance( false );
1277  pitem->ShowViaClearance( false );
1278  break;
1281  pitem->ShowTrackClearance( true );
1282  pitem->ShowViaClearance( true );
1283  break;
1284 
1286  pitem->ShowTrackClearance( !aEdit );
1287  pitem->ShowViaClearance( !aEdit );
1288  break;
1289 
1291  pitem->ShowTrackClearance( !aEdit );
1292  pitem->ShowViaClearance( false );
1293  break;
1294  }
1295  }
1296 
1297 
1298  m_previewItems->Add( pitem );
1300 }
1301 
1302 
1304 {
1305  BOARD_CONNECTED_ITEM* parent = aItem->Parent();
1306 
1307  if( parent )
1308  {
1309  if( m_view->IsVisible( parent ) )
1310  m_hiddenItems.insert( parent );
1311 
1312  m_view->SetVisible( parent, false );
1313  m_view->Update( parent, KIGFX::APPEARANCE );
1314  }
1315 }
1316 
1317 
1319 {
1320 
1321 }
1322 
1323 
1325 {
1326  BOARD_CONNECTED_ITEM* parent = aItem->Parent();
1327 
1328  if ( aItem->OfKind(PNS::ITEM::SOLID_T) )
1329  {
1330  auto pad = static_cast<D_PAD*>( parent );
1331  auto pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1332 
1333  m_moduleOffsets[ pad ].p_old = pos;
1334  return;
1335  }
1336 
1337  if( parent )
1338  {
1339  m_commit->Remove( parent );
1340  }
1341 }
1342 
1343 
1345 {
1346 
1347 }
1348 
1349 
1351 {
1352  BOARD_CONNECTED_ITEM* newBI = NULL;
1353 
1354  switch( aItem->Kind() )
1355  {
1356  case PNS::ITEM::ARC_T:
1357  {
1358  auto arc = static_cast<PNS::ARC*>( aItem );
1359  ARC* new_arc = new ARC( m_board, static_cast<const SHAPE_ARC*>( arc->Shape() ) );
1360  new_arc->SetWidth( arc->Width() );
1361  new_arc->SetLayer( ToLAYER_ID( arc->Layers().Start() ) );
1362  new_arc->SetNetCode( std::max<int>( 0, arc->Net() ) );
1363  newBI = new_arc;
1364  break;
1365  }
1366 
1367  case PNS::ITEM::SEGMENT_T:
1368  {
1369  PNS::SEGMENT* seg = static_cast<PNS::SEGMENT*>( aItem );
1370  TRACK* track = new TRACK( m_board );
1371  const SEG& s = seg->Seg();
1372  track->SetStart( wxPoint( s.A.x, s.A.y ) );
1373  track->SetEnd( wxPoint( s.B.x, s.B.y ) );
1374  track->SetWidth( seg->Width() );
1375  track->SetLayer( ToLAYER_ID( seg->Layers().Start() ) );
1376  track->SetNetCode( seg->Net() > 0 ? seg->Net() : 0 );
1377  newBI = track;
1378  break;
1379  }
1380 
1381  case PNS::ITEM::VIA_T:
1382  {
1383  VIA* via_board = new VIA( m_board );
1384  PNS::VIA* via = static_cast<PNS::VIA*>( aItem );
1385  via_board->SetPosition( wxPoint( via->Pos().x, via->Pos().y ) );
1386  via_board->SetWidth( via->Diameter() );
1387  via_board->SetDrill( via->Drill() );
1388  via_board->SetNetCode( via->Net() > 0 ? via->Net() : 0 );
1389  via_board->SetViaType( via->ViaType() ); // MUST be before SetLayerPair()
1390  via_board->SetLayerPair( ToLAYER_ID( via->Layers().Start() ),
1391  ToLAYER_ID( via->Layers().End() ) );
1392  newBI = via_board;
1393  break;
1394  }
1395 
1396  case PNS::ITEM::SOLID_T:
1397  {
1398  auto pad = static_cast<D_PAD*>( aItem->Parent() );
1399  auto pos = static_cast<PNS::SOLID*>( aItem )->Pos();
1400 
1401  m_moduleOffsets[ pad ].p_new = pos;
1402  return;
1403  }
1404 
1405  default:
1406  break;
1407  }
1408 
1409  if( newBI )
1410  {
1411  //newBI->SetLocalRatsnestVisible( m_dispOptions->m_ShowGlobalRatsnest );
1412  aItem->SetParent( newBI );
1413  newBI->ClearFlags();
1414 
1415  m_commit->Add( newBI );
1416  }
1417 }
1418 
1419 
1421 {
1422  std::set<MODULE*> processedMods;
1423 
1424  EraseView();
1425 
1426  for( auto mo : m_moduleOffsets )
1427  {
1428  auto offset = mo.second.p_new - mo.second.p_old;
1429  auto mod = mo.first->GetParent();
1430 
1431  VECTOR2I p_orig = mod->GetPosition();
1432  VECTOR2I p_new = p_orig + offset;
1433 
1434  if( processedMods.find( mod ) != processedMods.end() )
1435  continue;
1436 
1437  processedMods.insert( mod );
1438  m_commit->Modify( mod );
1439  mod->SetPosition( wxPoint( p_new.x, p_new.y ));
1440  }
1441 
1442  m_moduleOffsets.clear();
1443 
1444  m_commit->Push( _( "Interactive Router" ) );
1445  m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1446 }
1447 
1448 
1450 {
1451  wxLogTrace( "PNS", "SetView %p", aView );
1452 
1453  if( m_previewItems )
1454  {
1456  delete m_previewItems;
1457  }
1458 
1459  m_view = aView;
1462 
1463  if(m_view)
1465 
1466  delete m_debugDecorator;
1467 
1468  auto dec = new PNS_PCBNEW_DEBUG_DECORATOR();
1469  dec->SetView( m_view );
1470 
1471  m_debugDecorator = dec;
1472 }
1473 
1474 
1475 void PNS_KICAD_IFACE::UpdateNet( int aNetCode )
1476 {
1477  wxLogTrace( "PNS", "Update-net %d", aNetCode );
1478 
1479 }
1480 
1482 {
1483  return m_ruleResolver;
1484 }
1485 
1486 
1488 {
1489  m_router = aRouter;
1490 }
1491 
1492 
1494 {
1495  m_tool = aTool;
1496  m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
1497 }
1498 
1500 {
1501  m_dispOptions = aDispOptions;
1502 }
bool IsLocked() const override
Function IsLocked.
Definition: class_track.h:133
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:712
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:405
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:114
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:118
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...
Definition: class_pad.cpp:226
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:448
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:542
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:213
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:438
static constexpr int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:701
A single base class (TRACK) represents both tracks and vias, with subclasses for curved tracks (ARC) ...
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:152
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:111
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:112
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:283
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:760
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:256
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:294
VECTOR2I::extended_type ecoord
virtual int DpCoupledNet(int aNet) override
PAD_DRILL_SHAPE_T GetDrillShape() const
Definition: class_pad.h:417
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:435
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:578
void ShowViaClearance(bool aEnabled)
std::vector< CLEARANCE_ENT > m_netClearanceCache
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:231
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:404
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:661
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:846
void BuildPadPolygon(wxPoint aCoord[4], wxSize aInflateValue, double aRotation) const
Function BuildPadPolygon Has meaning only for polygonal pads (trapezoid and rectangular) Build the Co...
Definition: class_pad.cpp:771
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
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.
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:270
int GetWidth() const
Definition: class_track.h:112
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:223
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:181
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:411
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:291
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:601
const SHAPE_POLY_SET & GetCustomShapeAsPolygon() const
Accessor to the custom shape as one polygon.
Definition: class_pad.h:363
void AddItem(PNS::ITEM *aItem) override
void SetDrill(int aDrill)
Function SetDrill sets the drill value for vias.
Definition: class_track.h:440
void SetView(KIGFX::VIEW *aView)
int matchDpSuffix(const wxString &aNetName, wxString &aComplementNet, wxString &aBaseDpName)
VIATYPE GetViaType() const
Definition: class_track.h:366
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:875
PCB_TOOL_BASE * m_tool
VECTOR2I::extended_type ecoord
const wxPoint & GetEnd() const
Definition: class_track.h:115
bool GetDoNotAllowTracks() const
Definition: class_zone.h:664
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:240
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:117
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:222
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:285
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:137
Push and Shove diff pair dimensions (gap) settings dialog.
void SetViaType(VIATYPE aViaType)
Definition: class_track.h:367
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:265
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:849
PNS_PCBNEW_RULE_RESOLVER(BOARD *aBoard, PNS::ROUTER *aRouter)
TRACKS & Tracks()
Definition: class_board.h:247
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:197
const std::set< unsigned int > GetActiveLayers()
Function GetActiveLayers() Returns the set of currently active layers.
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