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