KiCad PCB EDA Suite
class_board.cpp
Go to the documentation of this file.
1 
6 /*
7  * This program source code file is part of KiCad, a free EDA CAD application.
8  *
9  * Copyright (C) 2018 Jean-Pierre Charras, jp.charras at wanadoo.fr
10  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
11  * Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
12  *
13  * Copyright (C) 1992-2019 KiCad Developers, see AUTHORS.txt for contributors.
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, you may find one here:
27  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
28  * or you may search the http://www.gnu.org website for the version 2 license,
29  * or you may write to the Free Software Foundation, Inc.,
30  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
31  */
32 
33 #include <algorithm>
34 #include <iterator>
35 #include <fctsys.h>
36 #include <common.h>
37 #include <kicad_string.h>
38 #include <pcb_base_frame.h>
39 #include <msgpanel.h>
40 #include <reporter.h>
41 #include <ratsnest_data.h>
42 #include <ratsnest_viewitem.h>
43 #include <ws_proxy_view_item.h>
44 #include <pcbnew.h>
45 #include <collectors.h>
46 #include <class_board.h>
47 #include <class_module.h>
48 #include <class_track.h>
49 #include <class_zone.h>
50 #include <class_marker_pcb.h>
51 #include <class_drawsegment.h>
52 #include <class_pcb_target.h>
54 #include <pgm_base.h>
55 
61 {
62 public:
64  BOARD_ITEM( nullptr, NOT_USED )
65  {}
66 
67  wxString GetSelectMenuText( EDA_UNITS_T aUnits ) const override
68  {
69  return _( "(Deleted Item)" );
70  }
71 
72  wxString GetClass() const override
73  {
74  return wxT( "DELETED_BOARD_ITEM" );
75  }
76 
77  // pure virtuals:
78  const wxPoint GetPosition() const override { return wxPoint(); }
79  void SetPosition( const wxPoint& ) override {}
80  void Print( PCB_BASE_FRAME* aFrame, wxDC* DC, const wxPoint& aOffset ) override {}
81 
82 #if defined(DEBUG)
83  void Show( int , std::ostream& ) const override {}
84 #endif
85 };
86 
88 
89 
90 /* This is an odd place for this, but CvPcb won't link if it is
91  * in class_board_item.cpp like I first tried it.
92  */
93 wxPoint BOARD_ITEM::ZeroOffset( 0, 0 );
94 
95 // Dummy general settings (defined colors are the default values) used to initialize the board.
96 // These settings will be overriden later, depending on the draw frame that displays the board.
97 // However, when a board is created by a python script, outside a frame, the colors must be set
98 // so dummyColorsSettings provide this default initialization
100 
103  m_paper( PAGE_INFO::A4 ), m_NetInfo( this )
104 {
105  // we have not loaded a board yet, assume latest until then.
106  m_fileFormatVersionAtLoad = LEGACY_BOARD_FILE_VERSION;
107 
109 
110  m_CurrentZoneContour = NULL; // This ZONE_CONTAINER handle the
111  // zone contour currently in progress
112 
113  BuildListOfNets(); // prepare pad and netlist containers.
114 
115  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
116  {
117  m_Layer[layer].m_name = GetStandardLayerName( ToLAYER_ID( layer ) );
118 
119  if( IsCopperLayer( layer ) )
120  m_Layer[layer].m_type = LT_SIGNAL;
121  else
122  m_Layer[layer].m_type = LT_UNDEFINED;
123  }
124 
125  // Initialize default netclass.
126  NETCLASSPTR defaultClass = m_designSettings.GetDefault();
127  defaultClass->SetDescription( _( "This is the default net class." ) );
128  m_designSettings.SetCurrentNetClass( defaultClass->GetName() );
129 
130  // Set sensible initial values for custom track width & via size
135 
136  // Initialize ratsnest
137  m_connectivity.reset( new CONNECTIVITY_DATA() );
138 }
139 
140 
142 {
143  while( m_ZoneDescriptorList.size() )
144  {
145  ZONE_CONTAINER* area_to_remove = m_ZoneDescriptorList[0];
146  Delete( area_to_remove );
147  }
148 
149  // Clean up the owned elements
150  DeleteMARKERs();
152 
153  // Delete the modules
154  for( auto m : m_modules )
155  delete m;
156 
157  m_modules.clear();
158 
159  // Delete the tracks
160  for( auto t : m_tracks )
161  delete t;
162 
163  m_tracks.clear();
164 
165  // Delete the drawings
166  for (auto d : m_drawings )
167  delete d;
168 
169  m_drawings.clear();
170 
171  delete m_CurrentZoneContour;
172  m_CurrentZoneContour = NULL;
173 }
174 
175 
177 {
178  GetConnectivity()->Build( this );
179 }
180 
181 
182 const wxPoint BOARD::GetPosition() const
183 {
184  return ZeroOffset;
185 }
186 
187 
188 void BOARD::SetPosition( const wxPoint& aPos )
189 {
190  wxLogWarning( wxT( "This should not be called on the BOARD object") );
191 }
192 
193 
194 void BOARD::Move( const wxPoint& aMoveVector ) // overload
195 {
196  // @todo : anything like this elsewhere? maybe put into GENERAL_COLLECTOR class.
197  static const KICAD_T top_level_board_stuff[] = {
198  PCB_MARKER_T,
199  PCB_TEXT_T,
200  PCB_LINE_T,
202  PCB_TARGET_T,
203  PCB_VIA_T,
204  PCB_TRACE_T,
205  // PCB_PAD_T, Can't be at board level
206  // PCB_MODULE_TEXT_T, Can't be at board level
207  PCB_MODULE_T,
209  EOT
210  };
211 
212  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
213  {
214  BOARD_ITEM* brd_item = (BOARD_ITEM*) item;
215 
216  // aMoveVector was snapshotted, don't need "data".
217  brd_item->Move( aMoveVector );
218 
219  return SEARCH_CONTINUE;
220  };
221 
222  Visit( inspector, NULL, top_level_board_stuff );
223 }
224 
225 
226 TRACKS BOARD::TracksInNet( int aNetCode )
227 {
228  TRACKS ret;
229 
230  INSPECTOR_FUNC inspector = [aNetCode,&ret] ( EDA_ITEM* item, void* testData )
231  {
232  TRACK* t = (TRACK*) item;
233 
234  if( t->GetNetCode() == aNetCode )
235  ret.push_back( t );
236 
237  return SEARCH_CONTINUE;
238  };
239 
240  // visit this BOARD's TRACKs and VIAs with above TRACK INSPECTOR which
241  // appends all in aNetCode to ret.
242  Visit( inspector, NULL, GENERAL_COLLECTOR::Tracks );
243 
244  return ret;
245 }
246 
247 
248 bool BOARD::SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer )
249 {
250  if( unsigned( aIndex ) < arrayDim( m_Layer ) )
251  {
252  m_Layer[ aIndex ] = aLayer;
253  return true;
254  }
255 
256  return false;
257 }
258 
259 
260 const PCB_LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
261 {
262 
263  // Look for the BOARD specific copper layer names
264  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
265  {
266  if ( IsCopperLayer( layer ) && ( m_Layer[ layer ].m_name == aLayerName ) )
267  {
268  return ToLAYER_ID( layer );
269  }
270  }
271 
272  // Otherwise fall back to the system standard layer names
273  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
274  {
275  if( GetStandardLayerName( ToLAYER_ID( layer ) ) == aLayerName )
276  {
277  return ToLAYER_ID( layer );
278  }
279  }
280 
281  return UNDEFINED_LAYER;
282 }
283 
284 const wxString BOARD::GetLayerName( PCB_LAYER_ID aLayer ) const
285 {
286  // All layer names are stored in the BOARD.
287  if( IsLayerEnabled( aLayer ) )
288  {
289  // Standard names were set in BOARD::BOARD() but they may be
290  // over-ridden by BOARD::SetLayerName().
291  // For copper layers, return the actual copper layer name,
292  // otherwise return the Standard English layer name.
293  if( IsCopperLayer( aLayer ) )
294  return m_Layer[aLayer].m_name;
295  }
296 
297  return GetStandardLayerName( aLayer );
298 }
299 
300 bool BOARD::SetLayerName( PCB_LAYER_ID aLayer, const wxString& aLayerName )
301 {
302  if( !IsCopperLayer( aLayer ) )
303  return false;
304 
305  if( aLayerName == wxEmptyString )
306  return false;
307 
308  // no quote chars in the name allowed
309  if( aLayerName.Find( wxChar( '"' ) ) != wxNOT_FOUND )
310  return false;
311 
312  wxString nameTemp = aLayerName;
313 
314  // replace any spaces with underscores before we do any comparing
315  nameTemp.Replace( wxT( " " ), wxT( "_" ) );
316 
317  if( IsLayerEnabled( aLayer ) )
318  {
319  m_Layer[aLayer].m_name = nameTemp;
320  return true;
321  }
322 
323  return false;
324 }
325 
326 
328 {
329  if( !IsCopperLayer( aLayer ) )
330  return LT_SIGNAL;
331 
332  //@@IMB: The original test was broken due to the discontinuity
333  // in the layer sequence.
334  if( IsLayerEnabled( aLayer ) )
335  return m_Layer[aLayer].m_type;
336 
337  return LT_SIGNAL;
338 }
339 
340 
341 bool BOARD::SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType )
342 {
343  if( !IsCopperLayer( aLayer ) )
344  return false;
345 
346  //@@IMB: The original test was broken due to the discontinuity
347  // in the layer sequence.
348  if( IsLayerEnabled( aLayer ) )
349  {
350  m_Layer[aLayer].m_type = aLayerType;
351  return true;
352  }
353 
354  return false;
355 }
356 
357 
358 const char* LAYER::ShowType( LAYER_T aType )
359 {
360  const char* cp;
361 
362  switch( aType )
363  {
364  default:
365  case LT_SIGNAL:
366  cp = "signal";
367  break;
368 
369  case LT_POWER:
370  cp = "power";
371  break;
372 
373  case LT_MIXED:
374  cp = "mixed";
375  break;
376 
377  case LT_JUMPER:
378  cp = "jumper";
379  break;
380  }
381 
382  return cp;
383 }
384 
385 
386 LAYER_T LAYER::ParseType( const char* aType )
387 {
388  if( strcmp( aType, "signal" ) == 0 )
389  return LT_SIGNAL;
390  else if( strcmp( aType, "power" ) == 0 )
391  return LT_POWER;
392  else if( strcmp( aType, "mixed" ) == 0 )
393  return LT_MIXED;
394  else if( strcmp( aType, "jumper" ) == 0 )
395  return LT_JUMPER;
396  else
397  return LT_UNDEFINED;
398 }
399 
400 
402 {
404 }
405 
406 
407 void BOARD::SetCopperLayerCount( int aCount )
408 {
410 }
411 
412 
414 {
416 }
417 
418 
420 {
422 }
423 
424 
425 void BOARD::SetEnabledLayers( LSET aLayerSet )
426 {
427  m_designSettings.SetEnabledLayers( aLayerSet );
428 }
429 
430 
431 void BOARD::SetVisibleLayers( LSET aLayerSet )
432 {
433  m_designSettings.SetVisibleLayers( aLayerSet );
434 }
435 
436 
437 void BOARD::SetVisibleElements( int aMask )
438 {
439  // Call SetElementVisibility for each item
440  // to ensure specific calculations that can be needed by some items,
441  // just changing the visibility flags could be not sufficient.
443  {
444  int item_mask = 1 << GAL_LAYER_INDEX( ii );
445  SetElementVisibility( ii, aMask & item_mask );
446  }
447 }
448 
449 
451 {
452  SetVisibleLayers( LSET().set() );
453 
454  // Call SetElementVisibility for each item,
455  // to ensure specific calculations that can be needed by some items
457  SetElementVisibility( ii, true );
458 }
459 
460 
462 {
464 }
465 
466 
468 {
469  return m_designSettings.IsElementVisible( aLayer );
470 }
471 
472 
473 void BOARD::SetElementVisibility( GAL_LAYER_ID aLayer, bool isEnabled )
474 {
475  m_designSettings.SetElementVisibility( aLayer, isEnabled );
476 
477  switch( aLayer )
478  {
479  case LAYER_RATSNEST:
480  {
481  // because we have a tool to show/hide ratsnest relative to a pad or a module
482  // so the hide/show option is a per item selection
483 
484  for( auto track : Tracks() )
485  track->SetLocalRatsnestVisible( isEnabled );
486 
487  for( auto mod : Modules() )
488  {
489  for( auto pad : mod->Pads() )
490  pad->SetLocalRatsnestVisible( isEnabled );
491  }
492 
493  for( int i = 0; i<GetAreaCount(); i++ )
494  {
495  auto zone = GetArea( i );
496  zone->SetLocalRatsnestVisible( isEnabled );
497  }
498 
499  break;
500  }
501 
502  default:
503  ;
504  }
505 }
506 
507 
509 {
510  switch( aLayer )
511  {
512  case F_Cu:
513  return IsElementVisible( LAYER_MOD_FR );
514 
515  case B_Cu:
516  return IsElementVisible( LAYER_MOD_BK );
517 
518  default:
519  wxFAIL_MSG( wxT( "BOARD::IsModuleLayerVisible() param error: bad layer" ) );
520  return true;
521  }
522 }
523 
524 
525 void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
526 {
527  if( aBoardItem == NULL )
528  {
529  wxFAIL_MSG( wxT( "BOARD::Add() param error: aBoardItem NULL" ) );
530  return;
531  }
532 
533  switch( aBoardItem->Type() )
534  {
535  case PCB_NETINFO_T:
536  m_NetInfo.AppendNet( (NETINFO_ITEM*) aBoardItem );
537  break;
538 
539  // this one uses a vector
540  case PCB_MARKER_T:
541  m_markers.push_back( (MARKER_PCB*) aBoardItem );
542  break;
543 
544  // this one uses a vector
545  case PCB_ZONE_AREA_T:
546  m_ZoneDescriptorList.push_back( (ZONE_CONTAINER*) aBoardItem );
547  break;
548 
549  case PCB_TRACE_T:
550  case PCB_VIA_T:
551 
552  // N.B. This inserts a small memory leak as we lose the
553  if( !IsCopperLayer( aBoardItem->GetLayer() ) )
554  {
555  wxFAIL_MSG( wxT( "BOARD::Add() Cannot place Track on non-copper layer" ) );
556  return;
557  }
558 
559  if( aMode == ADD_APPEND )
560  m_tracks.push_back( static_cast<TRACK*>( aBoardItem ) );
561  else
562  m_tracks.push_front( static_cast<TRACK*>( aBoardItem ) );
563 
564  break;
565 
566  case PCB_MODULE_T:
567  if( aMode == ADD_APPEND )
568  m_modules.push_back( (MODULE*) aBoardItem );
569  else
570  m_modules.push_front( (MODULE*) aBoardItem );
571 
572  break;
573 
574  case PCB_DIMENSION_T:
575  case PCB_LINE_T:
576  case PCB_TEXT_T:
577  case PCB_TARGET_T:
578  if( aMode == ADD_APPEND )
579  m_drawings.push_back( aBoardItem );
580  else
581  m_drawings.push_front( aBoardItem );
582 
583  break;
584 
585  // other types may use linked list
586  default:
587  {
588  wxString msg;
589  msg.Printf( wxT( "BOARD::Add() needs work: BOARD_ITEM type (%d) not handled" ),
590  aBoardItem->Type() );
591  wxFAIL_MSG( msg );
592  return;
593  }
594  break;
595  }
596 
597  aBoardItem->SetParent( this );
598  aBoardItem->ClearEditFlags();
599  m_connectivity->Add( aBoardItem );
600 }
601 
602 
603 void BOARD::Remove( BOARD_ITEM* aBoardItem )
604 {
605  // find these calls and fix them! Don't send me no stinking' NULL.
606  wxASSERT( aBoardItem );
607 
608  switch( aBoardItem->Type() )
609  {
610  case PCB_NETINFO_T:
611  {
612  NETINFO_ITEM* item = (NETINFO_ITEM*) aBoardItem;
613  m_NetInfo.RemoveNet( item );
614  break;
615  }
616 
617  case PCB_MARKER_T:
618 
619  // find the item in the vector, then remove it
620  for( unsigned i = 0; i<m_markers.size(); ++i )
621  {
622  if( m_markers[i] == (MARKER_PCB*) aBoardItem )
623  {
624  m_markers.erase( m_markers.begin() + i );
625  break;
626  }
627  }
628 
629  break;
630 
631  case PCB_ZONE_AREA_T: // this one uses a vector
632  // find the item in the vector, then delete then erase it.
633  for( unsigned i = 0; i<m_ZoneDescriptorList.size(); ++i )
634  {
635  if( m_ZoneDescriptorList[i] == (ZONE_CONTAINER*) aBoardItem )
636  {
637  m_ZoneDescriptorList.erase( m_ZoneDescriptorList.begin() + i );
638  break;
639  }
640  }
641  break;
642 
643  case PCB_MODULE_T:
644  m_modules.erase( std::remove_if( m_modules.begin(), m_modules.end(),
645  [aBoardItem]( BOARD_ITEM* aItem ) { return aItem == aBoardItem; } ) );
646  break;
647 
648  case PCB_TRACE_T:
649  case PCB_VIA_T:
650  m_tracks.erase( std::remove_if( m_tracks.begin(), m_tracks.end(),
651  [aBoardItem]( BOARD_ITEM* aItem ) { return aItem == aBoardItem; } ) );
652  break;
653 
654  case PCB_DIMENSION_T:
655  case PCB_LINE_T:
656  case PCB_TEXT_T:
657  case PCB_TARGET_T:
658  m_drawings.erase(
659  std::remove_if( m_drawings.begin(), m_drawings.end(),
660  [aBoardItem](BOARD_ITEM* aItem)
661  { return aItem == aBoardItem;} ) );
662  break;
663 
664  // other types may use linked list
665  default:
666  wxFAIL_MSG( wxT( "BOARD::Remove() needs more ::Type() support" ) );
667  }
668 
669  m_connectivity->Remove( aBoardItem );
670 }
671 
672 
673 wxString BOARD::GetSelectMenuText( EDA_UNITS_T aUnits ) const
674 {
675  return wxString::Format( _( "PCB" ) );
676 }
677 
678 
680 {
681  // the vector does not know how to delete the MARKER_PCB, it holds pointers
682  for( MARKER_PCB* marker : m_markers )
683  delete marker;
684 
685  m_markers.clear();
686 }
687 
688 
690 {
691  // the vector does not know how to delete the ZONE Outlines, it holds pointers
692  for( ZONE_CONTAINER* zone : m_ZoneDescriptorList )
693  delete zone;
694 
695  m_ZoneDescriptorList.clear();
696 }
697 
698 
699 BOARD_ITEM* BOARD::GetItem( void* aWeakReference )
700 {
701  for( TRACK* track : Tracks() )
702  if( track == aWeakReference )
703  return track;
704 
705  for( MODULE* module : Modules() )
706  {
707  if( module == aWeakReference )
708  return module;
709 
710  for( D_PAD* pad : module->Pads() )
711  if( pad == aWeakReference )
712  return pad;
713 
714  if( &module->Reference() == aWeakReference )
715  return &module->Reference();
716 
717  if( &module->Value() == aWeakReference )
718  return &module->Value();
719 
720  for( BOARD_ITEM* drawing : module->GraphicalItems() )
721  if( drawing == aWeakReference )
722  return drawing;
723  }
724 
725  for( ZONE_CONTAINER* zone : Zones() )
726  if( zone == aWeakReference )
727  return zone;
728 
729  for( BOARD_ITEM* drawing : Drawings() )
730  if( drawing == aWeakReference )
731  return drawing;
732 
733  // Not found; weak reference has been deleted.
734  return &g_DeletedItem;
735 }
736 
737 
738 unsigned BOARD::GetNodesCount( int aNet )
739 {
740  unsigned retval = 0;
741  for( auto mod : Modules() )
742  {
743  for( auto pad : mod->Pads() )
744  {
745  if( ( aNet == -1 && pad->GetNetCode() > 0 ) || aNet == pad->GetNetCode() )
746  retval++;
747  }
748  }
749 
750  return retval;
751 }
752 
753 
755 {
756  return m_connectivity->GetUnconnectedCount();
757 }
758 
759 
760 EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
761 {
762  EDA_RECT area;
763  LSET visible = GetVisibleLayers();
764  bool showInvisibleText = IsElementVisible( LAYER_MOD_TEXT_INVISIBLE )
765  && PgmOrNull() && !PgmOrNull()->m_Printing;
766 
767  // Check segments, dimensions, texts, and fiducials
768  for( auto item : m_drawings )
769  {
770  if( aBoardEdgesOnly && ( item->GetLayer() != Edge_Cuts ) )
771  continue;
772 
773  if( ( item->GetLayerSet() & visible ).any() )
774  area.Merge( item->GetBoundingBox() );
775  }
776 
777  // Check modules
778  for( auto module : m_modules )
779  {
780  if( !( module->GetLayerSet() & visible ).any() )
781  continue;
782 
783  if( aBoardEdgesOnly )
784  {
785  for( const auto edge : module->GraphicalItems() )
786  {
787  if( edge->GetLayer() == Edge_Cuts )
788  area.Merge( edge->GetBoundingBox() );
789  }
790  }
791  else
792  {
793  area.Merge( module->GetBoundingBox( showInvisibleText ) );
794  }
795  }
796 
797  if( !aBoardEdgesOnly )
798  {
799  // Check tracks
800  for( auto track : m_tracks )
801  {
802  if( ( track->GetLayerSet() & visible ).any() )
803  area.Merge( track->GetBoundingBox() );
804  }
805 
806  // Check zones
807  for( auto aZone : m_ZoneDescriptorList )
808  {
809  if( ( aZone->GetLayerSet() & visible ).any() )
810  area.Merge( aZone->GetBoundingBox() );
811  }
812  }
813 
814  return area;
815 }
816 
817 
818 void BOARD::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
819 {
820  wxString txt;
821  int viasCount = 0;
822  int trackSegmentsCount = 0;
823 
824  for( auto item : m_tracks )
825  {
826  if( item->Type() == PCB_VIA_T )
827  viasCount++;
828  else
829  trackSegmentsCount++;
830  }
831 
832  txt.Printf( wxT( "%d" ), GetPadCount() );
833  aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
834 
835  txt.Printf( wxT( "%d" ), viasCount );
836  aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, DARKGREEN ) );
837 
838  txt.Printf( wxT( "%d" ), trackSegmentsCount );
839  aList.push_back( MSG_PANEL_ITEM( _( "Track Segments" ), txt, DARKGREEN ) );
840 
841  txt.Printf( wxT( "%d" ), GetNodesCount() );
842  aList.push_back( MSG_PANEL_ITEM( _( "Nodes" ), txt, DARKCYAN ) );
843 
844  txt.Printf( wxT( "%d" ), m_NetInfo.GetNetCount() - 1 /* Don't include "No Net" in count */ );
845  aList.push_back( MSG_PANEL_ITEM( _( "Nets" ), txt, RED ) );
846 
847  txt.Printf( wxT( "%d" ), GetConnectivity()->GetUnconnectedCount() );
848  aList.push_back( MSG_PANEL_ITEM( _( "Unrouted" ), txt, BLUE ) );
849 }
850 
851 
852 SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
853 {
854  KICAD_T stype;
856  const KICAD_T* p = scanTypes;
857  bool done = false;
858 
859 #if 0 && defined(DEBUG)
860  std::cout << GetClass().mb_str() << ' ';
861 #endif
862 
863  while( !done )
864  {
865  stype = *p;
866 
867  switch( stype )
868  {
869  case PCB_T:
870  result = inspector( this, testData ); // inspect me
871  // skip over any types handled in the above call.
872  ++p;
873  break;
874 
875  /* Instances of the requested KICAD_T live in a list, either one
876  * that I manage, or that my modules manage. If it's a type managed
877  * by class MODULE, then simply pass it on to each module's
878  * MODULE::Visit() function by way of the
879  * IterateForward( m_Modules, ... ) call.
880  */
881 
882  case PCB_MODULE_T:
883  case PCB_PAD_T:
884  case PCB_MODULE_TEXT_T:
885  case PCB_MODULE_EDGE_T:
886 
887  // this calls MODULE::Visit() on each module.
888  result = IterateForward<MODULE*>( m_modules, inspector, testData, p );
889 
890  // skip over any types handled in the above call.
891  for( ; ; )
892  {
893  switch( stype = *++p )
894  {
895  case PCB_MODULE_T:
896  case PCB_PAD_T:
897  case PCB_MODULE_TEXT_T:
898  case PCB_MODULE_EDGE_T:
899  continue;
900 
901  default:
902  ;
903  }
904 
905  break;
906  }
907 
908  break;
909 
910  case PCB_LINE_T:
911  case PCB_TEXT_T:
912  case PCB_DIMENSION_T:
913  case PCB_TARGET_T:
914  result = IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, p );
915 
916  // skip over any types handled in the above call.
917  for( ; ; )
918  {
919  switch( stype = *++p )
920  {
921  case PCB_LINE_T:
922  case PCB_TEXT_T:
923  case PCB_DIMENSION_T:
924  case PCB_TARGET_T:
925  continue;
926 
927  default:
928  ;
929  }
930 
931  break;
932  }
933 
934  ;
935  break;
936 
937 #if 0 // both these are on same list, so we must scan it twice in order
938  // to get VIA priority, using new #else code below.
939  // But we are not using separate lists for TRACKs and VIA, because
940  // items are ordered (sorted) in the linked
941  // list by netcode AND by physical distance:
942  // when created, if a track or via is connected to an existing track or
943  // via, it is put in linked list after this existing track or via
944  // So usually, connected tracks or vias are grouped in this list
945  // So the algorithm (used in ratsnest computations) which computes the
946  // track connectivity is faster (more than 100 time regarding to
947  // a non ordered list) because when it searches for a connection, first
948  // it tests the near (near in term of linked list) 50 items
949  // from the current item (track or via) in test.
950  // Usually, because of this sort, a connected item (if exists) is
951  // found.
952  // If not found (and only in this case) an exhaustive (and time
953  // consuming) search is made, but this case is statistically rare.
954  case PCB_VIA_T:
955  case PCB_TRACE_T:
956  result = IterateForward( m_Track, inspector, testData, p );
957 
958  // skip over any types handled in the above call.
959  for( ; ; )
960  {
961  switch( stype = *++p )
962  {
963  case PCB_VIA_T:
964  case PCB_TRACE_T:
965  continue;
966 
967  default:
968  ;
969  }
970 
971  break;
972  }
973 
974  break;
975 
976 #else
977  case PCB_VIA_T:
978  result = IterateForward<TRACK*>( m_tracks, inspector, testData, p );
979  ++p;
980  break;
981 
982  case PCB_TRACE_T:
983  result = IterateForward<TRACK*>( m_tracks, inspector, testData, p );
984  ++p;
985  break;
986 #endif
987 
988  case PCB_MARKER_T:
989 
990  // MARKER_PCBS are in the m_markers std::vector
991  for( unsigned i = 0; i<m_markers.size(); ++i )
992  {
993  result = m_markers[i]->Visit( inspector, testData, p );
994 
995  if( result == SEARCH_QUIT )
996  break;
997  }
998 
999  ++p;
1000  break;
1001 
1002  case PCB_ZONE_AREA_T:
1003 
1004  // PCB_ZONE_AREA_T are in the m_ZoneDescriptorList std::vector
1005  for( unsigned i = 0; i< m_ZoneDescriptorList.size(); ++i )
1006  {
1007  result = m_ZoneDescriptorList[i]->Visit( inspector, testData, p );
1008 
1009  if( result == SEARCH_QUIT )
1010  break;
1011  }
1012 
1013  ++p;
1014  break;
1015 
1016  default: // catch EOT or ANY OTHER type here and return.
1017  done = true;
1018  break;
1019  }
1020 
1021  if( result == SEARCH_QUIT )
1022  break;
1023  }
1024 
1025  return result;
1026 }
1027 
1028 
1029 NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const
1030 {
1031  // the first valid netcode is 1 and the last is m_NetInfo.GetCount()-1.
1032  // zero is reserved for "no connection" and is not actually a net.
1033  // NULL is returned for non valid netcodes
1034 
1035  wxASSERT( m_NetInfo.GetNetCount() > 0 );
1036 
1037  if( aNetcode == NETINFO_LIST::UNCONNECTED && m_NetInfo.GetNetCount() == 0 )
1039  else
1040  return m_NetInfo.GetNetItem( aNetcode );
1041 }
1042 
1043 
1044 NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const
1045 {
1046  return m_NetInfo.GetNetItem( aNetname );
1047 }
1048 
1049 
1050 MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const
1051 {
1052  MODULE* found = nullptr;
1053 
1054  // search only for MODULES
1055  static const KICAD_T scanTypes[] = { PCB_MODULE_T, EOT };
1056 
1057  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1058  {
1059  MODULE* module = (MODULE*) item;
1060 
1061  if( aReference == module->GetReference() )
1062  {
1063  found = module;
1064  return SEARCH_QUIT;
1065  }
1066 
1067  return SEARCH_CONTINUE;
1068  };
1069 
1070  // visit this BOARD with the above inspector
1071  BOARD* nonconstMe = (BOARD*) this;
1072  nonconstMe->Visit( inspector, NULL, scanTypes );
1073 
1074  return found;
1075 }
1076 
1077 
1078 MODULE* BOARD::FindModule( const wxString& aRefOrTimeStamp, bool aSearchByTimeStamp ) const
1079 {
1080  if( aSearchByTimeStamp )
1081  {
1082  for( auto module : m_modules )
1083  {
1084  if( aRefOrTimeStamp.CmpNoCase( module->GetPath() ) == 0 )
1085  return module;
1086  }
1087  }
1088  else
1089  {
1090  return FindModuleByReference( aRefOrTimeStamp );
1091  }
1092 
1093  return NULL;
1094 }
1095 
1096 
1097 
1098 // The pad count for each netcode, stored in a buffer for a fast access.
1099 // This is needed by the sort function sortNetsByNodes()
1100 static std::vector<int> padCountListByNet;
1101 
1102 // Sort nets by decreasing pad count.
1103 // For same pad count, sort by alphabetic names
1104 static bool sortNetsByNodes( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
1105 {
1106  int countA = padCountListByNet[a->GetNet()];
1107  int countB = padCountListByNet[b->GetNet()];
1108 
1109  if( countA == countB )
1110  return a->GetNetname() < b->GetNetname();
1111  else
1112  return countB < countA;
1113 }
1114 
1115 // Sort nets by alphabetic names
1116 static bool sortNetsByNames( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
1117 {
1118  return a->GetNetname() < b->GetNetname();
1119 }
1120 
1121 int BOARD::SortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount )
1122 {
1123  if( m_NetInfo.GetNetCount() == 0 )
1124  return 0;
1125 
1126  // Build the list
1127  std::vector <NETINFO_ITEM*> netBuffer;
1128 
1129  netBuffer.reserve( m_NetInfo.GetNetCount() );
1130  int max_netcode = 0;
1131 
1132  for( NETINFO_ITEM* net : m_NetInfo )
1133  {
1134  auto netcode = net->GetNet();
1135 
1136  if( netcode > 0 && net->IsCurrent() )
1137  {
1138  netBuffer.push_back( net );
1139  max_netcode = std::max( netcode, max_netcode);
1140  }
1141  }
1142 
1143  // sort the list
1144  if( aSortbyPadsCount )
1145  {
1146  // Build the pad count by net:
1147  padCountListByNet.clear();
1148  std::vector<D_PAD*> pads = GetPads();
1149 
1150  padCountListByNet.assign( max_netcode + 1, 0 );
1151 
1152  for( D_PAD* pad : pads )
1153  padCountListByNet[pad->GetNetCode()]++;
1154 
1155  sort( netBuffer.begin(), netBuffer.end(), sortNetsByNodes );
1156  }
1157  else
1158  {
1159  sort( netBuffer.begin(), netBuffer.end(), sortNetsByNames );
1160  }
1161 
1162  for( NETINFO_ITEM* net : netBuffer )
1163  aNames.Add( UnescapeString( net->GetNetname() ) );
1164 
1165  return netBuffer.size();
1166 }
1167 
1168 
1170  PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, int aNetCode )
1171 {
1172  if( aEndLayer < 0 )
1173  aEndLayer = aStartLayer;
1174 
1175  if( aEndLayer < aStartLayer )
1176  std::swap( aEndLayer, aStartLayer );
1177 
1178  for( ZONE_CONTAINER* area : m_ZoneDescriptorList )
1179  {
1180  if( area->GetLayer() < aStartLayer || area->GetLayer() > aEndLayer )
1181  continue;
1182 
1183  // In locate functions we must skip tagged items with BUSY flag set.
1184  if( area->GetState( BUSY ) )
1185  continue;
1186 
1187  if( aNetCode >= 0 && area->GetNetCode() != aNetCode )
1188  continue;
1189 
1190  if( area->HitTestFilledArea( aRefPos ) )
1191  return area;
1192  }
1193 
1194  return NULL;
1195 }
1196 
1197 
1199 {
1200  int error_count = 0;
1201 
1202  for( int ii = 0; ii < GetAreaCount(); ii++ )
1203  {
1204  ZONE_CONTAINER* it = GetArea( ii );
1205 
1206  if( !it->IsOnCopperLayer() )
1207  {
1209  continue;
1210  }
1211 
1212  if( it->GetNetCode() != 0 ) // i.e. if this zone is connected to a net
1213  {
1214  const NETINFO_ITEM* net = it->GetNet();
1215 
1216  if( net )
1217  {
1218  it->SetNetCode( net->GetNet() );
1219  }
1220  else
1221  {
1222  error_count++;
1223 
1224  // keep Net Name and set m_NetCode to -1 : error flag.
1225  it->SetNetCode( -1 );
1226  }
1227  }
1228  }
1229 
1230  return error_count;
1231 }
1232 
1233 
1234 D_PAD* BOARD::GetPad( const wxPoint& aPosition, LSET aLayerSet )
1235 {
1236  if( !aLayerSet.any() )
1237  aLayerSet = LSET::AllCuMask();
1238 
1239  for( auto module : m_modules )
1240  {
1241  D_PAD* pad = NULL;
1242 
1243  if( module->HitTest( aPosition ) )
1244  pad = module->GetPad( aPosition, aLayerSet );
1245 
1246  if( pad )
1247  return pad;
1248  }
1249 
1250  return NULL;
1251 }
1252 
1253 
1254 D_PAD* BOARD::GetPad( TRACK* aTrace, ENDPOINT_T aEndPoint )
1255 {
1256  const wxPoint& aPosition = aTrace->GetEndPoint( aEndPoint );
1257 
1258  LSET lset( aTrace->GetLayer() );
1259 
1260  return GetPad( aPosition, lset );
1261 }
1262 
1263 
1264 D_PAD* BOARD::GetPadFast( const wxPoint& aPosition, LSET aLayerSet )
1265 {
1266  for( auto mod : Modules() )
1267  {
1268  for ( auto pad : mod->Pads() )
1269  {
1270  if( pad->GetPosition() != aPosition )
1271  continue;
1272 
1273  // Pad found, it must be on the correct layer
1274  if( ( pad->GetLayerSet() & aLayerSet ).any() )
1275  return pad;
1276  }
1277  }
1278 
1279  return nullptr;
1280 }
1281 
1282 
1283 D_PAD* BOARD::GetPad( std::vector<D_PAD*>& aPadList, const wxPoint& aPosition, LSET aLayerSet )
1284 {
1285  // Search aPadList for aPosition
1286  // aPadList is sorted by X then Y values, and a fast binary search is used
1287  int idxmax = aPadList.size()-1;
1288 
1289  int delta = aPadList.size();
1290 
1291  int idx = 0; // Starting index is the beginning of list
1292 
1293  while( delta )
1294  {
1295  // Calculate half size of remaining interval to test.
1296  // Ensure the computed value is not truncated (too small)
1297  if( (delta & 1) && ( delta > 1 ) )
1298  delta++;
1299 
1300  delta /= 2;
1301 
1302  D_PAD* pad = aPadList[idx];
1303 
1304  if( pad->GetPosition() == aPosition ) // candidate found
1305  {
1306  // The pad must match the layer mask:
1307  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1308  return pad;
1309 
1310  // More than one pad can be at aPosition
1311  // search for a pad at aPosition that matched this mask
1312 
1313  // search next
1314  for( int ii = idx+1; ii <= idxmax; ii++ )
1315  {
1316  pad = aPadList[ii];
1317 
1318  if( pad->GetPosition() != aPosition )
1319  break;
1320 
1321  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1322  return pad;
1323  }
1324  // search previous
1325  for( int ii = idx-1 ;ii >=0; ii-- )
1326  {
1327  pad = aPadList[ii];
1328 
1329  if( pad->GetPosition() != aPosition )
1330  break;
1331 
1332  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1333  return pad;
1334  }
1335 
1336  // Not found:
1337  return 0;
1338  }
1339 
1340  if( pad->GetPosition().x == aPosition.x ) // Must search considering Y coordinate
1341  {
1342  if( pad->GetPosition().y < aPosition.y ) // Must search after this item
1343  {
1344  idx += delta;
1345 
1346  if( idx > idxmax )
1347  idx = idxmax;
1348  }
1349  else // Must search before this item
1350  {
1351  idx -= delta;
1352 
1353  if( idx < 0 )
1354  idx = 0;
1355  }
1356  }
1357  else if( pad->GetPosition().x < aPosition.x ) // Must search after this item
1358  {
1359  idx += delta;
1360 
1361  if( idx > idxmax )
1362  idx = idxmax;
1363  }
1364  else // Must search before this item
1365  {
1366  idx -= delta;
1367 
1368  if( idx < 0 )
1369  idx = 0;
1370  }
1371  }
1372 
1373  return NULL;
1374 }
1375 
1376 
1382 bool sortPadsByXthenYCoord( D_PAD* const & ref, D_PAD* const & comp )
1383 {
1384  if( ref->GetPosition().x == comp->GetPosition().x )
1385  return ref->GetPosition().y < comp->GetPosition().y;
1386  return ref->GetPosition().x < comp->GetPosition().x;
1387 }
1388 
1389 
1390 void BOARD::GetSortedPadListByXthenYCoord( std::vector<D_PAD*>& aVector, int aNetCode )
1391 {
1392  for ( auto mod : Modules() )
1393  {
1394  for ( auto pad : mod->Pads( ) )
1395  {
1396  if( aNetCode < 0 || pad->GetNetCode() == aNetCode )
1397  {
1398  aVector.push_back( pad );
1399  }
1400  }
1401  }
1402 
1403  std::sort( aVector.begin(), aVector.end(), sortPadsByXthenYCoord );
1404 }
1405 
1406 
1408 {
1409  GetConnectivity()->Remove( aPad );
1410  aPad->DeleteStructure();
1411 }
1412 
1413 
1414 std::tuple<int, double, double> BOARD::GetTrackLength( const TRACK& aTrack ) const
1415 {
1416  int count = 0;
1417  double length = 0.0;
1418  double package_length = 0.0;
1419 
1420  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_PAD_T, EOT };
1421  auto connectivity = GetBoard()->GetConnectivity();
1422 
1423  for( auto item : connectivity->GetConnectedItems(
1424  static_cast<const BOARD_CONNECTED_ITEM*>( &aTrack ), types ) )
1425  {
1426  count++;
1427 
1428  if( auto track = dyn_cast<TRACK*>( item ) )
1429  {
1430  bool inPad = false;
1431 
1432  for( auto pad_it : connectivity->GetConnectedPads( item ) )
1433  {
1434  auto pad = static_cast<D_PAD*>( pad_it );
1435 
1436  if( pad->HitTest( track->GetStart(), track->GetWidth() / 2 )
1437  && pad->HitTest( track->GetEnd(), track->GetWidth() / 2 ) )
1438  {
1439  inPad = true;
1440  break;
1441  }
1442  }
1443 
1444  if( !inPad )
1445  length += track->GetLength();
1446  }
1447  else if( auto pad = dyn_cast<D_PAD*>( item ) )
1448  package_length += pad->GetPadToDieLength();
1449  }
1450 
1451  return std::make_tuple( count, length, package_length );
1452 }
1453 
1454 
1455 MODULE* BOARD::GetFootprint( const wxPoint& aPosition, PCB_LAYER_ID aActiveLayer,
1456  bool aVisibleOnly, bool aIgnoreLocked )
1457 {
1458  MODULE* module = NULL;
1459  MODULE* alt_module = NULL;
1460  int min_dim = 0x7FFFFFFF;
1461  int alt_min_dim = 0x7FFFFFFF;
1462  bool current_layer_back = IsBackLayer( aActiveLayer );
1463 
1464  for( auto pt_module : m_modules )
1465  {
1466  // is the ref point within the module's bounds?
1467  if( !pt_module->HitTest( aPosition ) )
1468  continue;
1469 
1470  // if caller wants to ignore locked modules, and this one is locked, skip it.
1471  if( aIgnoreLocked && pt_module->IsLocked() )
1472  continue;
1473 
1474  PCB_LAYER_ID layer = pt_module->GetLayer();
1475 
1476  // Filter non visible modules if requested
1477  if( !aVisibleOnly || IsModuleLayerVisible( layer ) )
1478  {
1479  EDA_RECT bb = pt_module->GetFootprintRect();
1480 
1481  int offx = bb.GetX() + bb.GetWidth() / 2;
1482  int offy = bb.GetY() + bb.GetHeight() / 2;
1483 
1484  // off x & offy point to the middle of the box.
1485  int dist = ( aPosition.x - offx ) * ( aPosition.x - offx ) +
1486  ( aPosition.y - offy ) * ( aPosition.y - offy );
1487 
1488  if( current_layer_back == IsBackLayer( layer ) )
1489  {
1490  if( dist <= min_dim )
1491  {
1492  // better footprint shown on the active side
1493  module = pt_module;
1494  min_dim = dist;
1495  }
1496  }
1497  else if( aVisibleOnly && IsModuleLayerVisible( layer ) )
1498  {
1499  if( dist <= alt_min_dim )
1500  {
1501  // better footprint shown on the other side
1502  alt_module = pt_module;
1503  alt_min_dim = dist;
1504  }
1505  }
1506  }
1507  }
1508 
1509  if( module )
1510  {
1511  return module;
1512  }
1513 
1514  if( alt_module)
1515  {
1516  return alt_module;
1517  }
1518 
1519  return NULL;
1520 }
1521 
1522 std::list<ZONE_CONTAINER*> BOARD::GetZoneList( bool aIncludeZonesInFootprints )
1523 {
1524  std::list<ZONE_CONTAINER*> zones;
1525 
1526  for( int ii = 0; ii < GetAreaCount(); ii++ )
1527  {
1528  zones.push_back( GetArea( ii ) );
1529  }
1530 
1531  if( aIncludeZonesInFootprints )
1532  {
1533  for( MODULE* mod : m_modules )
1534  {
1535  for( MODULE_ZONE_CONTAINER* zone : mod->Zones() )
1536  {
1537  zones.push_back( zone );
1538  }
1539  }
1540  }
1541 
1542  return zones;
1543 }
1544 
1545 
1546 ZONE_CONTAINER* BOARD::AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode,
1547  PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch )
1548 {
1549  ZONE_CONTAINER* new_area = InsertArea( aNetcode,
1550  m_ZoneDescriptorList.size( ) - 1,
1551  aLayer, aStartPointPosition.x,
1552  aStartPointPosition.y, aHatch );
1553 
1554  if( aNewZonesList )
1555  {
1556  ITEM_PICKER picker( new_area, UR_NEW );
1557  aNewZonesList->PushItem( picker );
1558  }
1559 
1560  return new_area;
1561 }
1562 
1563 
1564 void BOARD::RemoveArea( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_to_remove )
1565 {
1566  if( area_to_remove == NULL )
1567  return;
1568 
1569  if( aDeletedList )
1570  {
1571  ITEM_PICKER picker( area_to_remove, UR_DELETED );
1572  aDeletedList->PushItem( picker );
1573  Remove( area_to_remove ); // remove from zone list, but does not delete it
1574  }
1575  else
1576  {
1577  Delete( area_to_remove );
1578  }
1579 }
1580 
1581 
1582 ZONE_CONTAINER* BOARD::InsertArea( int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer,
1583  int aCornerX, int aCornerY, int aHatch )
1584 {
1585  ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this );
1586 
1587  new_area->SetNetCode( aNetcode );
1588  new_area->SetLayer( aLayer );
1589  new_area->SetTimeStamp( GetNewTimeStamp() );
1590 
1591  if( aAreaIdx < (int) ( m_ZoneDescriptorList.size() - 1 ) )
1592  m_ZoneDescriptorList.insert( m_ZoneDescriptorList.begin() + aAreaIdx + 1, new_area );
1593  else
1594  m_ZoneDescriptorList.push_back( new_area );
1595 
1596  new_area->SetHatchStyle( (ZONE_CONTAINER::HATCH_STYLE) aHatch );
1597 
1598  // Add the first corner to the new zone
1599  new_area->AppendCorner( wxPoint( aCornerX, aCornerY ), -1 );
1600 
1601  return new_area;
1602 }
1603 
1604 
1606 {
1607  // mark all areas as unmodified except this one, if modified
1608  for( ZONE_CONTAINER* zone : m_ZoneDescriptorList )
1609  zone->SetLocalFlags( 0 );
1610 
1611  aCurrArea->SetLocalFlags( 1 );
1612 
1613  if( aCurrArea->Outline()->IsSelfIntersecting() )
1614  {
1615  aCurrArea->UnHatch();
1616 
1617  // Normalize copied area and store resulting number of polygons
1618  int n_poly = aCurrArea->Outline()->NormalizeAreaOutlines();
1619 
1620  // If clipping has created some polygons, we must add these new copper areas.
1621  if( n_poly > 1 )
1622  {
1623  ZONE_CONTAINER* NewArea;
1624 
1625  // Move the newly created polygons to new areas, removing them from the current area
1626  for( int ip = 1; ip < n_poly; ip++ )
1627  {
1628  // Create new copper area and copy poly into it
1629  SHAPE_POLY_SET* new_p = new SHAPE_POLY_SET( aCurrArea->Outline()->UnitSet( ip ) );
1630  NewArea = AddArea( aNewZonesList, aCurrArea->GetNetCode(), aCurrArea->GetLayer(),
1631  wxPoint(0, 0), aCurrArea->GetHatchStyle() );
1632 
1633  // remove the poly that was automatically created for the new area
1634  // and replace it with a poly from NormalizeAreaOutlines
1635  delete NewArea->Outline();
1636  NewArea->SetOutline( new_p );
1637  NewArea->Hatch();
1638  NewArea->SetLocalFlags( 1 );
1639  }
1640 
1641  SHAPE_POLY_SET* new_p = new SHAPE_POLY_SET( aCurrArea->Outline()->UnitSet( 0 ) );
1642  delete aCurrArea->Outline();
1643  aCurrArea->SetOutline( new_p );
1644  }
1645  }
1646 
1647  aCurrArea->Hatch();
1648 
1649  return true;
1650 }
1651 
1652 
1653 BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, bool aAddToBoard )
1654 {
1655  BOARD_ITEM* new_item = NULL;
1656 
1657  switch( aItem->Type() )
1658  {
1659  case PCB_MODULE_T:
1660  case PCB_TEXT_T:
1661  case PCB_LINE_T:
1662  case PCB_TRACE_T:
1663  case PCB_VIA_T:
1664  case PCB_ZONE_AREA_T:
1665  case PCB_TARGET_T:
1666  case PCB_DIMENSION_T:
1667  new_item = static_cast<BOARD_ITEM*>( aItem->Clone() );
1668  break;
1669 
1670  default:
1671  // Un-handled item for duplication
1672  new_item = NULL;
1673  break;
1674  }
1675 
1676  if( new_item && aAddToBoard )
1677  Add( new_item );
1678 
1679  return new_item;
1680 }
1681 
1682 
1683 /* Extracts the board outlines and build a closed polygon
1684  * from lines, arcs and circle items on edge cut layer
1685  * Any closed outline inside the main outline is a hole
1686  * All contours should be closed, i.e. are valid vertices for a closed polygon
1687  * return true if success, false if a contour is not valid
1688  */
1689 extern bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
1690  wxString* aErrorText, unsigned int aTolerance,
1691  wxPoint* aErrorLocation = nullptr );
1692 
1693 
1694 bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, wxString* aErrorText, wxPoint* aErrorLocation )
1695 {
1696 
1697  bool success = BuildBoardPolygonOutlines( this, aOutlines, aErrorText,
1698  GetDesignSettings().m_MaxError, aErrorLocation );
1699 
1700  // Make polygon strictly simple to avoid issues (especially in 3D viewer)
1702 
1703  return success;
1704 
1705 }
1706 
1707 
1708 const std::vector<D_PAD*> BOARD::GetPads()
1709 {
1710  std::vector<D_PAD*> allPads;
1711 
1712  for( MODULE* mod : Modules() )
1713  {
1714  for( D_PAD* pad : mod->Pads() )
1715  allPads.push_back( pad );
1716  }
1717 
1718  return allPads;
1719 }
1720 
1721 
1723 {
1724  unsigned retval = 0;
1725 
1726  for( auto mod : Modules() )
1727  retval += mod->Pads().size();
1728 
1729  return retval;
1730 }
1731 
1732 
1737 D_PAD* BOARD::GetPad( unsigned aIndex ) const
1738 {
1739  unsigned count = 0;
1740 
1741  for( auto mod : m_modules )
1742  {
1743  for( auto pad : mod->Pads() )
1744  {
1745  if( count == aIndex )
1746  return pad;
1747 
1748  count++;
1749  }
1750  }
1751 
1752  return nullptr;
1753 }
1754 
1755 
1756 const std::vector<BOARD_CONNECTED_ITEM*> BOARD::AllConnectedItems()
1757 {
1758  std::vector<BOARD_CONNECTED_ITEM*> items;
1759 
1760  for( auto track : Tracks() )
1761  {
1762  items.push_back( track );
1763  }
1764 
1765  for( auto mod : Modules() )
1766  {
1767  for( auto pad : mod->Pads() )
1768  {
1769  items.push_back( pad );
1770  }
1771  }
1772 
1773  for( int i = 0; i<GetAreaCount(); i++ )
1774  {
1775  auto zone = GetArea( i );
1776  items.push_back( zone );
1777  }
1778 
1779  return items;
1780 }
1781 
1782 
1784 {
1785  for ( BOARD_CONNECTED_ITEM* item : AllConnectedItems() )
1786  item->SetNetCode( 0 );
1787 }
1788 
1789 
1790 void BOARD::MapNets( const BOARD* aDestBoard )
1791 {
1792  for ( BOARD_CONNECTED_ITEM* item : AllConnectedItems() )
1793  {
1794  NETINFO_ITEM* netInfo = aDestBoard->FindNet( item->GetNetname() );
1795 
1796  if( netInfo )
1797  item->SetNetCode( netInfo->GetNet() );
1798  else
1799  item->SetNetCode( 0 );
1800  }
1801 }
1802 
1803 
1805 {
1806  for ( BOARD_CONNECTED_ITEM* item : AllConnectedItems() )
1807  {
1808  if( FindNet( item->GetNetCode() ) == nullptr )
1809  item->SetNetCode( NETINFO_LIST::ORPHANED );
1810  }
1811 }
bool IsElementVisible(GAL_LAYER_ID aElementCategory) const
Function IsElementVisible tests whether a given element category is visible.
MODULES m_modules
MODULES for components on the board, owned by pointer.
Definition: class_board.h:176
Definition: colors.h:57
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:676
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
void SetCopperLayerCount(int aNewLayerCount)
Function SetCopperLayerCount do what its name says...
void BuildListOfNets()
Definition: class_board.h:717
void SetEnabledLayers(LSET aMask)
Function SetEnabledLayers changes the bit-mask of enabled layers.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
const PCB_LAYER_ID GetLayerID(const wxString &aLayerName) const
Function GetLayerID returns the ID of a layer given by aLayerName.
Class that draws missing connections on a PCB.
void DeleteZONEOutlines()
Function DeleteZONEOutlines deletes ALL zone outlines from the board.
int GetNetCode() const
Function GetNetCode.
Definition: typeinfo.h:85
std::function< SEARCH_RESULT(EDA_ITEM *aItem, void *aTestData) > INSPECTOR_FUNC
Typedef INSPECTOR is used to inspect and possibly collect the (search) results of iterating over a li...
Definition: base_struct.h:83
void Merge(const EDA_RECT &aRect)
Function Merge modifies the position and size of the rectangle in order to contain aRect.
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:313
static const int dist[10][10]
Definition: ar_matrix.cpp:320
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
wxString m_name
The name of the layer, there should be no spaces in this name.
Definition: class_board.h:106
void PadDelete(D_PAD *aPad)
Function PadDelete deletes a given bad from the BOARD by removing it from its module and from the m_N...
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it's internal state for displ...
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
void SetVisibleElements(int aMask)
Function SetVisibleElements is a proxy function that calls the correspondent function in m_BoardSetti...
const wxPoint GetPosition() const override
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_board.cpp:72
int GetX() const
Definition: eda_rect.h:111
D_PAD * GetPadFast(const wxPoint &aPosition, LSET aLayerMask)
Function GetPadFast return pad found at aPosition on aLayerMask using the fast search method.
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it's a back layer.
void SetCustomViaDrill(int aDrill)
Function SetCustomViaDrill Sets custom size for via drill (i.e.
Class that computes missing connections on a PCB.
the 3d code uses this value
Definition: typeinfo.h:80
LAYER_T m_type
The type of the layer.
Definition: class_board.h:107
void GetSortedPadListByXthenYCoord(std::vector< D_PAD * > &aVector, int aNetCode=-1)
Function GetSortedPadListByXthenYCoord first empties then fills the vector with all pads and sorts th...
int NormalizeAreaOutlines()
Function NormalizeAreaOutlines Convert a self-intersecting polygon to one (or more) non self-intersec...
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:101
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:203
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:249
int GetWidth() const
Definition: eda_rect.h:119
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:246
void DeleteStructure()
Function DeleteStructure deletes this object after UnLink()ing it from its owner if it has one.
GAL_LAYER_ID
GAL layers are "virtual" layers, i.e.
void SetCopperLayerCount(int aCount)
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
void RemoveArea(PICKED_ITEMS_LIST *aDeletedList, ZONE_CONTAINER *area_to_remove)
Function RemoveArea remove copper area from net, and put it in a deleted list (if exists)
const wxPoint GetPosition() const override
Definition: class_board.cpp:78
DELETED_BOARD_ITEM g_DeletedItem
Definition: class_board.cpp:87
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:531
void SetVisibleAlls()
Function SetVisibleAlls changes the bit-mask of visible element categories and layers.
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:140
void SetPosition(const wxPoint &aPos) override
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
This is the end of the layers used for visibility bitmasks in Pcbnew There can be at most 32 layers a...
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
NETINFO_LIST m_NetInfo
net info list (name, design constraints ..
Definition: class_board.h:199
A singleton item of this class is returned for a weak reference that no longer exists.
Definition: class_board.cpp:60
bool IsLayerEnabled(PCB_LAYER_ID aLayer) const
Function IsLayerEnabled is a proxy function that calls the correspondent function in m_BoardSettings ...
Definition: class_board.h:438
D_PAD * GetPad(unsigned aIndex) const
Function GetPad.
TRACKS m_tracks
TRACKS for traces on the board, owned by pointer.
Definition: class_board.h:179
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
void SetOutline(SHAPE_POLY_SET *aOutline)
Definition: class_zone.h:249
void SetCustomViaSize(int aSize)
Function SetCustomViaSize Sets custom size for via diameter (i.e.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
static wxPoint ZeroOffset
A value of wxPoint(0,0) which can be passed to the Draw() functions.
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
Definitions for tracks, vias and zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:432
static const char * ShowType(LAYER_T aType)
Function ShowType converts a LAYER_T enum to a const char*.
ZONE_CONTAINER * HitTestForAnyFilledArea(const wxPoint &aRefPos, PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, int aNetCode)
Function HitTestForAnyFilledArea tests if the given wxPoint is within the bounds of a filled area of ...
void SetVisibleLayers(LSET aMask)
Function SetVisibleLayers changes the bit-mask of visible layers.
Classes used in Pcbnew, CvPcb and GerbView.
void AppendNet(NETINFO_ITEM *aNewElement)
Function AppendNet adds aNewElement to the end of the net list.
show modules on front
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:108
SEARCH_RESULT Visit(INSPECTOR inspector, void *testData, const KICAD_T scanTypes[]) override
Function Visit may be re-implemented for each derived class in order to handle all the types given by...
class MODULE, a footprint
Definition: typeinfo.h:89
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Markers used to show a drc problem on boards.
PCB_LAYER_ID
A quick note on layer IDs:
const std::vector< BOARD_CONNECTED_ITEM * > AllConnectedItems()
ZONE_CONTAINER * InsertArea(int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer, int aCornerX, int aCornerY, int aHatch)
Add a copper area to net, inserting after m_ZoneDescriptorList[aAreaIdx].
void RemoveNet(NETINFO_ITEM *aNet)
Function RemoveNet Removes a new from the net list.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:949
Class LSET is a set of PCB_LAYER_IDs.
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:519
bool NormalizeAreaPolygon(PICKED_ITEMS_LIST *aNewZonesList, ZONE_CONTAINER *aCurrArea)
Function NormalizeAreaPolygon Process an area that has been modified, by normalizing its polygon agai...
unsigned GetNodesCount(int aNet=-1)
Function GetNodesCount.
MODULES & Modules()
Definition: class_board.h:227
void DeleteMARKERs()
Function DeleteMARKERs deletes ALL MARKERS from the board.
PGM_BASE * PgmOrNull()
similat to PGM_BASE& Pgm(), but return a reference that can be nullptr when running a shared lib from...
Definition: cvpcb.cpp:110
ZONE_CONTAINER * AddArea(PICKED_ITEMS_LIST *aNewZonesList, int aNetcode, PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch)
Function AddArea Add an empty copper area to board areas list.
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:225
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
Class SHAPE_POLY_SET.
void SetVisibleLayers(LSET aLayerMask)
Function SetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
SHAPE_LINE_CHAIN & Outline(int aIndex)
Returns the reference to aIndex-th outline in the set
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:54
bool sortPadsByXthenYCoord(D_PAD *const &ref, D_PAD *const &comp)
Function SortPadsByXCoord is used by GetSortedPadListByXCoord to Sort a pad list by x coordinate valu...
LAYER_T
Enum LAYER_T gives the allowed types of layers, same as Specctra DSN spec.
Definition: class_board.h:66
void Print(PCB_BASE_FRAME *aFrame, wxDC *DC, const wxPoint &aOffset) override
Function Print BOARD_ITEMs have their own color information.
Definition: class_board.cpp:80
void SetNetCode(int aNetCode)
Definition: netinfo.h:227
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:426
unsigned GetUnconnectedNetCount() const
Function GetUnconnectedNetCount.
virtual BOARD * GetBoard() const
Function GetBoard returns the BOARD in which this BOARD_ITEM resides, or NULL if none.
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:301
bool SetLayerDescr(PCB_LAYER_ID aIndex, const LAYER &aLayer)
Function SetLayerDescr returns the type of the copper layer given by aLayer.
int SortedNetnamesList(wxArrayString &aNames, bool aSortbyPadsCount)
Function SortedNetnamesList.
virtual void SetLayer(PCB_LAYER_ID aLayer) override
Function SetLayer sets the layer this item is on.
Definition: class_zone.cpp:230
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:233
ENDPOINT_T
Definition: class_track.h:53
static SEARCH_RESULT IterateForward(EDA_ITEM *listStart, INSPECTOR inspector, void *testData, const KICAD_T scanTypes[])
Function IterateForward walks through the object tree calling the inspector() on each object type req...
Definition: base_struct.h:418
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Sets net using a net code.
Definition: colors.h:60
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
void SetPosition(const wxPoint &) override
Definition: class_board.cpp:79
int SetAreasNetCodesFromNetNames(void)
Function SetAreasNetCodesFromNetNames Set the .m_NetCode member of all copper areas,...
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, wxString *aErrorText=nullptr, wxPoint *aErrorLocation=nullptr)
Function GetBoardPolygonOutlines Extracts the board outlines and build a closed polygon from lines,...
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
MARKERS m_markers
MARKER_PCBs for clearance problems, owned by pointer.
Definition: class_board.h:170
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:65
bool BuildBoardPolygonOutlines(BOARD *aBoard, SHAPE_POLY_SET &aOutlines, wxString *aErrorText, unsigned int aTolerance, wxPoint *aErrorLocation=nullptr)
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
static LAYER_T ParseType(const char *aType)
Function ParseType converts a string to a LAYER_T.
int GetVisibleElements() const
Function GetVisibleElements is a proxy function that calls the correspondent function in m_BoardSetti...
DRAWINGS m_drawings
BOARD_ITEMs for drawings on the board, owned by pointer.
Definition: class_board.h:173
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:99
#define _(s)
unsigned GetPadCount()
Function GetPadCount.
void SetCustomTrackWidth(int aWidth)
Function SetCustomTrackWidth Sets custom width for track (i.e.
int GetHeight() const
Definition: eda_rect.h:120
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:100
MODULE * FindModule(const wxString &aRefOrTimeStamp, bool aSearchByTimeStamp=false) const
Function FindModule searches for a module matching aRefOrTimeStamp depending on the state of aSearchB...
static const int ORPHANED
Constant that forces initialization of a netinfo item to the NETINFO_ITEM ORPHANED (typically -1) whe...
Definition: netinfo.h:467
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
static bool sortNetsByNames(const NETINFO_ITEM *a, const NETINFO_ITEM *b)
constexpr std::size_t arrayDim(T const (&)[N]) noexcept
Definition: macros.h:108
TRACKS TracksInNet(int aNetCode)
Function TrackInNet collects all the TRACKs and VIAs that are members of a net given by aNetCode.
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
wxString GetSelectMenuText(EDA_UNITS_T aUnits) const override
Function GetSelectMenuText returns the text to display to be used in the selection clarification cont...
Definition: class_board.cpp:67
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
const std::vector< D_PAD * > GetPads()
Function GetPads returns a reference to a list of all the pads.
int GetCurrentViaSize() const
Function GetCurrentViaSize.
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
void MapNets(const BOARD *aDestBoard)
Map all nets in the given board to nets with the same name (if any) in the destination board.
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:98
bool m_Printing
wxWidgets on MSW tends to crash if you spool up more than one print job at a time.
Definition: pgm_base.h:368
LSET GetVisibleLayers() const
Function GetVisibleLayers returns a bit-mask of all the layers that are visible.
ZONE_CONTAINERS & Zones()
Definition: class_board.h:241
BOARD_ITEM * GetItem(void *aWeakReference)
bool SetCurrentNetClass(const wxString &aNetClassName)
Function SetCurrentNetClass Must be called after a netclass selection (or after a netclass parameter ...
see class PGM_BASE
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible.
static PCB_GENERAL_SETTINGS dummyGeneralSettings(FRAME_PCB_EDITOR)
void UnHatch()
Function UnHatch clears the zone's hatch.
Definition: class_zone.cpp:990
SHAPE_POLY_SET UnitSet(int aPolygonIndex)
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
NETCLASSPTR GetDefault() const
Function GetDefault.
int m_fileFormatVersionAtLoad
the version loaded from the file
Definition: class_board.h:190
PCB_GENERAL_SETTINGS * m_generalSettings
reference only; I have no ownership
Definition: class_board.h:195
static NETINFO_ITEM ORPHANED_ITEM
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition: netinfo.h:471
int GetNet() const
Function GetNet.
Definition: netinfo.h:225
#define max(a, b)
Definition: auxiliary.h:86
Class LAYER holds information pertinent to a layer of a BOARD.
Definition: class_board.h:80
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:161
LSET GetEnabledLayers() const
Function GetEnabledLayers returns a bit-mask of all the layers that are enabled.
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:131
ZONE_CONTAINERS m_ZoneDescriptorList
edge zone descriptors, owned by pointer.
Definition: class_board.h:182
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:103
size_t i
Definition: json11.cpp:649
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void SanitizeNetcodes()
LAYER m_Layer[PCB_LAYER_ID_COUNT]
Definition: class_board.h:184
std::shared_ptr< CONNECTIVITY_DATA > m_connectivity
Definition: class_board.h:192
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void Hatch()
Function Hatch computes the hatch lines depending on the hatch parameters and stores it in the zone's...
int GetY() const
Definition: eda_rect.h:112
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:524
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
static bool sortNetsByNodes(const NETINFO_ITEM *a, const NETINFO_ITEM *b)
void SetLocalFlags(int aFlags)
Definition: class_zone.h:241
The common library.
MODULE_ZONE_CONTAINER is the same item as ZONE_CONTAINER, but with a specific type id ZONE_CONTAINER ...
Definition: class_zone.h:827
bool IsModuleLayerVisible(PCB_LAYER_ID aLayer)
Function IsModuleLayerVisible expects either of the two layers on which a module can reside,...
MODULE * FindModuleByReference(const wxString &aReference) const
Function FindModuleByReference searches for a MODULE within this board with the given reference desig...
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_board.h:866
void SetElementVisibility(GAL_LAYER_ID aElementCategory, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
unsigned GetNetCount() const
Function GetNetCount.
Definition: netinfo.h:436
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
virtual void Delete(BOARD_ITEM *aItem)
Removes an item from the container and deletes it.
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
Definition: class_zone.cpp:931
PCB_TARGET class definition.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
BOARD_DESIGN_SETTINGS m_designSettings
Definition: class_board.h:194
Module description (excepted pads)
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:914
Abstract interface for BOARD_ITEMs capable of storing other items inside.
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
SEARCH_RESULT
Definition: base_struct.h:54
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
const wxPoint GetPosition() const override
Definition: class_pad.h:225
std::tuple< int, double, double > GetTrackLength(const TRACK &aTrack) const
Returns data on the length and number of track segments connected to a given track.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
void ClearEditFlags()
Definition: base_struct.h:283
Message panel definition file.
const wxPoint & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
Definition: class_track.h:113
MODULE * GetFootprint(const wxPoint &aPosition, PCB_LAYER_ID aActiveLayer, bool aVisibleOnly, bool aIgnoreLocked=false)
Function GetFootprint get a footprint by its bounding rectangle at aPosition on aLayer.
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
static std::vector< int > padCountListByNet
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:463
int GetCopperLayerCount() const
Function GetCopperLayerCount.
DRAWINGS & Drawings()
Definition: class_board.h:236
void ClearAllNetCodes()
Function ClearAllNetCodes() Resets all items' netcodes to 0 (no net).
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:813
void SetEnabledLayers(LSET aLayerMask)
Function SetEnabledLayers is a proxy function that calls the correspondent function in m_BoardSetting...
#define mod(a, n)
Definition: greymap.cpp:24
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
EDA_UNITS_T
Definition: common.h:133
TRACKS & Tracks()
Definition: class_board.h:218
bool IsOnCopperLayer() const override
Function IsOnCopperLayer.
Definition: class_zone.cpp:209
void UseCustomTrackViaSize(bool aEnabled)
Function UseCustomTrackViaSize Enables/disables custom track/via size settings.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
static wxString GetStandardLayerName(PCB_LAYER_ID aLayerId)
Function GetStandardLayerName returns an "English Standard" name of a PCB layer when given aLayerNumb...
Definition: class_board.h:647
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
std::list< ZONE_CONTAINER * > GetZoneList(bool aIncludeZonesInFootprints=false)
Function GetZoneList.
bool IsSelfIntersecting() const
Function IsSelfIntersecting Checks whether any of the polygons in the set is self intersecting.
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aAddToBoard=false)