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 ) && !Pgm().m_Printing;
765 
766  // Check segments, dimensions, texts, and fiducials
767  for( auto item : m_drawings )
768  {
769  if( aBoardEdgesOnly && ( item->GetLayer() != Edge_Cuts ) )
770  continue;
771 
772  if( ( item->GetLayerSet() & visible ).any() )
773  area.Merge( item->GetBoundingBox() );
774  }
775 
776  // Check modules
777  for( auto module : m_modules )
778  {
779  if( !( module->GetLayerSet() & visible ).any() )
780  continue;
781 
782  if( aBoardEdgesOnly )
783  {
784  for( const auto edge : module->GraphicalItems() )
785  {
786  if( edge->GetLayer() == Edge_Cuts )
787  area.Merge( edge->GetBoundingBox() );
788  }
789  }
790  else
791  {
792  area.Merge( module->GetBoundingBox( showInvisibleText ) );
793  }
794  }
795 
796  if( !aBoardEdgesOnly )
797  {
798  // Check tracks
799  for( auto track : m_tracks )
800  {
801  if( ( track->GetLayerSet() & visible ).any() )
802  area.Merge( track->GetBoundingBox() );
803  }
804 
805  // Check zones
806  for( auto aZone : m_ZoneDescriptorList )
807  {
808  if( ( aZone->GetLayerSet() & visible ).any() )
809  area.Merge( aZone->GetBoundingBox() );
810  }
811  }
812 
813  return area;
814 }
815 
816 
817 void BOARD::GetMsgPanelInfo( EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM >& aList )
818 {
819  wxString txt;
820  int viasCount = 0;
821  int trackSegmentsCount = 0;
822 
823  for( auto item : m_tracks )
824  {
825  if( item->Type() == PCB_VIA_T )
826  viasCount++;
827  else
828  trackSegmentsCount++;
829  }
830 
831  txt.Printf( wxT( "%d" ), GetPadCount() );
832  aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
833 
834  txt.Printf( wxT( "%d" ), viasCount );
835  aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, DARKGREEN ) );
836 
837  txt.Printf( wxT( "%d" ), trackSegmentsCount );
838  aList.push_back( MSG_PANEL_ITEM( _( "Track Segments" ), txt, DARKGREEN ) );
839 
840  txt.Printf( wxT( "%d" ), GetNodesCount() );
841  aList.push_back( MSG_PANEL_ITEM( _( "Nodes" ), txt, DARKCYAN ) );
842 
843  txt.Printf( wxT( "%d" ), m_NetInfo.GetNetCount() - 1 /* Don't include "No Net" in count */ );
844  aList.push_back( MSG_PANEL_ITEM( _( "Nets" ), txt, RED ) );
845 
846  txt.Printf( wxT( "%d" ), GetConnectivity()->GetUnconnectedCount() );
847  aList.push_back( MSG_PANEL_ITEM( _( "Unrouted" ), txt, BLUE ) );
848 }
849 
850 
851 SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
852 {
853  KICAD_T stype;
855  const KICAD_T* p = scanTypes;
856  bool done = false;
857 
858 #if 0 && defined(DEBUG)
859  std::cout << GetClass().mb_str() << ' ';
860 #endif
861 
862  while( !done )
863  {
864  stype = *p;
865 
866  switch( stype )
867  {
868  case PCB_T:
869  result = inspector( this, testData ); // inspect me
870  // skip over any types handled in the above call.
871  ++p;
872  break;
873 
874  /* Instances of the requested KICAD_T live in a list, either one
875  * that I manage, or that my modules manage. If it's a type managed
876  * by class MODULE, then simply pass it on to each module's
877  * MODULE::Visit() function by way of the
878  * IterateForward( m_Modules, ... ) call.
879  */
880 
881  case PCB_MODULE_T:
882  case PCB_PAD_T:
883  case PCB_MODULE_TEXT_T:
884  case PCB_MODULE_EDGE_T:
885 
886  // this calls MODULE::Visit() on each module.
887  result = IterateForward<MODULE*>( m_modules, inspector, testData, p );
888 
889  // skip over any types handled in the above call.
890  for( ; ; )
891  {
892  switch( stype = *++p )
893  {
894  case PCB_MODULE_T:
895  case PCB_PAD_T:
896  case PCB_MODULE_TEXT_T:
897  case PCB_MODULE_EDGE_T:
898  continue;
899 
900  default:
901  ;
902  }
903 
904  break;
905  }
906 
907  break;
908 
909  case PCB_LINE_T:
910  case PCB_TEXT_T:
911  case PCB_DIMENSION_T:
912  case PCB_TARGET_T:
913  result = IterateForward<BOARD_ITEM*>( m_drawings, inspector, testData, p );
914 
915  // skip over any types handled in the above call.
916  for( ; ; )
917  {
918  switch( stype = *++p )
919  {
920  case PCB_LINE_T:
921  case PCB_TEXT_T:
922  case PCB_DIMENSION_T:
923  case PCB_TARGET_T:
924  continue;
925 
926  default:
927  ;
928  }
929 
930  break;
931  }
932 
933  ;
934  break;
935 
936 #if 0 // both these are on same list, so we must scan it twice in order
937  // to get VIA priority, using new #else code below.
938  // But we are not using separate lists for TRACKs and VIA, because
939  // items are ordered (sorted) in the linked
940  // list by netcode AND by physical distance:
941  // when created, if a track or via is connected to an existing track or
942  // via, it is put in linked list after this existing track or via
943  // So usually, connected tracks or vias are grouped in this list
944  // So the algorithm (used in ratsnest computations) which computes the
945  // track connectivity is faster (more than 100 time regarding to
946  // a non ordered list) because when it searches for a connection, first
947  // it tests the near (near in term of linked list) 50 items
948  // from the current item (track or via) in test.
949  // Usually, because of this sort, a connected item (if exists) is
950  // found.
951  // If not found (and only in this case) an exhaustive (and time
952  // consuming) search is made, but this case is statistically rare.
953  case PCB_VIA_T:
954  case PCB_TRACE_T:
955  result = IterateForward( m_Track, inspector, testData, p );
956 
957  // skip over any types handled in the above call.
958  for( ; ; )
959  {
960  switch( stype = *++p )
961  {
962  case PCB_VIA_T:
963  case PCB_TRACE_T:
964  continue;
965 
966  default:
967  ;
968  }
969 
970  break;
971  }
972 
973  break;
974 
975 #else
976  case PCB_VIA_T:
977  result = IterateForward<TRACK*>( m_tracks, inspector, testData, p );
978  ++p;
979  break;
980 
981  case PCB_TRACE_T:
982  result = IterateForward<TRACK*>( m_tracks, inspector, testData, p );
983  ++p;
984  break;
985 #endif
986 
987  case PCB_MARKER_T:
988 
989  // MARKER_PCBS are in the m_markers std::vector
990  for( unsigned i = 0; i<m_markers.size(); ++i )
991  {
992  result = m_markers[i]->Visit( inspector, testData, p );
993 
994  if( result == SEARCH_QUIT )
995  break;
996  }
997 
998  ++p;
999  break;
1000 
1001  case PCB_ZONE_AREA_T:
1002 
1003  // PCB_ZONE_AREA_T are in the m_ZoneDescriptorList std::vector
1004  for( unsigned i = 0; i< m_ZoneDescriptorList.size(); ++i )
1005  {
1006  result = m_ZoneDescriptorList[i]->Visit( inspector, testData, p );
1007 
1008  if( result == SEARCH_QUIT )
1009  break;
1010  }
1011 
1012  ++p;
1013  break;
1014 
1015  default: // catch EOT or ANY OTHER type here and return.
1016  done = true;
1017  break;
1018  }
1019 
1020  if( result == SEARCH_QUIT )
1021  break;
1022  }
1023 
1024  return result;
1025 }
1026 
1027 
1028 NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const
1029 {
1030  // the first valid netcode is 1 and the last is m_NetInfo.GetCount()-1.
1031  // zero is reserved for "no connection" and is not actually a net.
1032  // NULL is returned for non valid netcodes
1033 
1034  wxASSERT( m_NetInfo.GetNetCount() > 0 );
1035 
1036  if( aNetcode == NETINFO_LIST::UNCONNECTED && m_NetInfo.GetNetCount() == 0 )
1038  else
1039  return m_NetInfo.GetNetItem( aNetcode );
1040 }
1041 
1042 
1043 NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const
1044 {
1045  return m_NetInfo.GetNetItem( aNetname );
1046 }
1047 
1048 
1049 MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const
1050 {
1051  MODULE* found = nullptr;
1052 
1053  // search only for MODULES
1054  static const KICAD_T scanTypes[] = { PCB_MODULE_T, EOT };
1055 
1056  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1057  {
1058  MODULE* module = (MODULE*) item;
1059 
1060  if( aReference == module->GetReference() )
1061  {
1062  found = module;
1063  return SEARCH_QUIT;
1064  }
1065 
1066  return SEARCH_CONTINUE;
1067  };
1068 
1069  // visit this BOARD with the above inspector
1070  BOARD* nonconstMe = (BOARD*) this;
1071  nonconstMe->Visit( inspector, NULL, scanTypes );
1072 
1073  return found;
1074 }
1075 
1076 
1077 MODULE* BOARD::FindModule( const wxString& aRefOrTimeStamp, bool aSearchByTimeStamp ) const
1078 {
1079  if( aSearchByTimeStamp )
1080  {
1081  for( auto module : m_modules )
1082  {
1083  if( aRefOrTimeStamp.CmpNoCase( module->GetPath() ) == 0 )
1084  return module;
1085  }
1086  }
1087  else
1088  {
1089  return FindModuleByReference( aRefOrTimeStamp );
1090  }
1091 
1092  return NULL;
1093 }
1094 
1095 
1096 
1097 // The pad count for each netcode, stored in a buffer for a fast access.
1098 // This is needed by the sort function sortNetsByNodes()
1099 static std::vector<int> padCountListByNet;
1100 
1101 // Sort nets by decreasing pad count.
1102 // For same pad count, sort by alphabetic names
1103 static bool sortNetsByNodes( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
1104 {
1105  int countA = padCountListByNet[a->GetNet()];
1106  int countB = padCountListByNet[b->GetNet()];
1107 
1108  if( countA == countB )
1109  return a->GetNetname() < b->GetNetname();
1110  else
1111  return countB < countA;
1112 }
1113 
1114 // Sort nets by alphabetic names
1115 static bool sortNetsByNames( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
1116 {
1117  return a->GetNetname() < b->GetNetname();
1118 }
1119 
1120 int BOARD::SortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount )
1121 {
1122  if( m_NetInfo.GetNetCount() == 0 )
1123  return 0;
1124 
1125  // Build the list
1126  std::vector <NETINFO_ITEM*> netBuffer;
1127 
1128  netBuffer.reserve( m_NetInfo.GetNetCount() );
1129  int max_netcode = 0;
1130 
1131  for( NETINFO_ITEM* net : m_NetInfo )
1132  {
1133  auto netcode = net->GetNet();
1134 
1135  if( netcode > 0 && net->IsCurrent() )
1136  {
1137  netBuffer.push_back( net );
1138  max_netcode = std::max( netcode, max_netcode);
1139  }
1140  }
1141 
1142  // sort the list
1143  if( aSortbyPadsCount )
1144  {
1145  // Build the pad count by net:
1146  padCountListByNet.clear();
1147  std::vector<D_PAD*> pads = GetPads();
1148 
1149  padCountListByNet.assign( max_netcode + 1, 0 );
1150 
1151  for( D_PAD* pad : pads )
1152  padCountListByNet[pad->GetNetCode()]++;
1153 
1154  sort( netBuffer.begin(), netBuffer.end(), sortNetsByNodes );
1155  }
1156  else
1157  {
1158  sort( netBuffer.begin(), netBuffer.end(), sortNetsByNames );
1159  }
1160 
1161  for( NETINFO_ITEM* net : netBuffer )
1162  aNames.Add( UnescapeString( net->GetNetname() ) );
1163 
1164  return netBuffer.size();
1165 }
1166 
1167 
1169  PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, int aNetCode )
1170 {
1171  if( aEndLayer < 0 )
1172  aEndLayer = aStartLayer;
1173 
1174  if( aEndLayer < aStartLayer )
1175  std::swap( aEndLayer, aStartLayer );
1176 
1177  for( ZONE_CONTAINER* area : m_ZoneDescriptorList )
1178  {
1179  if( area->GetLayer() < aStartLayer || area->GetLayer() > aEndLayer )
1180  continue;
1181 
1182  // In locate functions we must skip tagged items with BUSY flag set.
1183  if( area->GetState( BUSY ) )
1184  continue;
1185 
1186  if( aNetCode >= 0 && area->GetNetCode() != aNetCode )
1187  continue;
1188 
1189  if( area->HitTestFilledArea( aRefPos ) )
1190  return area;
1191  }
1192 
1193  return NULL;
1194 }
1195 
1196 
1198 {
1199  int error_count = 0;
1200 
1201  for( int ii = 0; ii < GetAreaCount(); ii++ )
1202  {
1203  ZONE_CONTAINER* it = GetArea( ii );
1204 
1205  if( !it->IsOnCopperLayer() )
1206  {
1208  continue;
1209  }
1210 
1211  if( it->GetNetCode() != 0 ) // i.e. if this zone is connected to a net
1212  {
1213  const NETINFO_ITEM* net = it->GetNet();
1214 
1215  if( net )
1216  {
1217  it->SetNetCode( net->GetNet() );
1218  }
1219  else
1220  {
1221  error_count++;
1222 
1223  // keep Net Name and set m_NetCode to -1 : error flag.
1224  it->SetNetCode( -1 );
1225  }
1226  }
1227  }
1228 
1229  return error_count;
1230 }
1231 
1232 
1233 D_PAD* BOARD::GetPad( const wxPoint& aPosition, LSET aLayerSet )
1234 {
1235  if( !aLayerSet.any() )
1236  aLayerSet = LSET::AllCuMask();
1237 
1238  for( auto module : m_modules )
1239  {
1240  D_PAD* pad = NULL;
1241 
1242  if( module->HitTest( aPosition ) )
1243  pad = module->GetPad( aPosition, aLayerSet );
1244 
1245  if( pad )
1246  return pad;
1247  }
1248 
1249  return NULL;
1250 }
1251 
1252 
1253 D_PAD* BOARD::GetPad( TRACK* aTrace, ENDPOINT_T aEndPoint )
1254 {
1255  const wxPoint& aPosition = aTrace->GetEndPoint( aEndPoint );
1256 
1257  LSET lset( aTrace->GetLayer() );
1258 
1259  return GetPad( aPosition, lset );
1260 }
1261 
1262 
1263 D_PAD* BOARD::GetPadFast( const wxPoint& aPosition, LSET aLayerSet )
1264 {
1265  for( auto mod : Modules() )
1266  {
1267  for ( auto pad : mod->Pads() )
1268  {
1269  if( pad->GetPosition() != aPosition )
1270  continue;
1271 
1272  // Pad found, it must be on the correct layer
1273  if( ( pad->GetLayerSet() & aLayerSet ).any() )
1274  return pad;
1275  }
1276  }
1277 
1278  return nullptr;
1279 }
1280 
1281 
1282 D_PAD* BOARD::GetPad( std::vector<D_PAD*>& aPadList, const wxPoint& aPosition, LSET aLayerSet )
1283 {
1284  // Search aPadList for aPosition
1285  // aPadList is sorted by X then Y values, and a fast binary search is used
1286  int idxmax = aPadList.size()-1;
1287 
1288  int delta = aPadList.size();
1289 
1290  int idx = 0; // Starting index is the beginning of list
1291 
1292  while( delta )
1293  {
1294  // Calculate half size of remaining interval to test.
1295  // Ensure the computed value is not truncated (too small)
1296  if( (delta & 1) && ( delta > 1 ) )
1297  delta++;
1298 
1299  delta /= 2;
1300 
1301  D_PAD* pad = aPadList[idx];
1302 
1303  if( pad->GetPosition() == aPosition ) // candidate found
1304  {
1305  // The pad must match the layer mask:
1306  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1307  return pad;
1308 
1309  // More than one pad can be at aPosition
1310  // search for a pad at aPosition that matched this mask
1311 
1312  // search next
1313  for( int ii = idx+1; ii <= idxmax; ii++ )
1314  {
1315  pad = aPadList[ii];
1316 
1317  if( pad->GetPosition() != aPosition )
1318  break;
1319 
1320  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1321  return pad;
1322  }
1323  // search previous
1324  for( int ii = idx-1 ;ii >=0; ii-- )
1325  {
1326  pad = aPadList[ii];
1327 
1328  if( pad->GetPosition() != aPosition )
1329  break;
1330 
1331  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1332  return pad;
1333  }
1334 
1335  // Not found:
1336  return 0;
1337  }
1338 
1339  if( pad->GetPosition().x == aPosition.x ) // Must search considering Y coordinate
1340  {
1341  if( pad->GetPosition().y < aPosition.y ) // Must search after this item
1342  {
1343  idx += delta;
1344 
1345  if( idx > idxmax )
1346  idx = idxmax;
1347  }
1348  else // Must search before this item
1349  {
1350  idx -= delta;
1351 
1352  if( idx < 0 )
1353  idx = 0;
1354  }
1355  }
1356  else if( pad->GetPosition().x < aPosition.x ) // Must search after this item
1357  {
1358  idx += delta;
1359 
1360  if( idx > idxmax )
1361  idx = idxmax;
1362  }
1363  else // Must search before this item
1364  {
1365  idx -= delta;
1366 
1367  if( idx < 0 )
1368  idx = 0;
1369  }
1370  }
1371 
1372  return NULL;
1373 }
1374 
1375 
1381 bool sortPadsByXthenYCoord( D_PAD* const & ref, D_PAD* const & comp )
1382 {
1383  if( ref->GetPosition().x == comp->GetPosition().x )
1384  return ref->GetPosition().y < comp->GetPosition().y;
1385  return ref->GetPosition().x < comp->GetPosition().x;
1386 }
1387 
1388 
1389 void BOARD::GetSortedPadListByXthenYCoord( std::vector<D_PAD*>& aVector, int aNetCode )
1390 {
1391  for ( auto mod : Modules() )
1392  {
1393  for ( auto pad : mod->Pads( ) )
1394  {
1395  if( aNetCode < 0 || pad->GetNetCode() == aNetCode )
1396  {
1397  aVector.push_back( pad );
1398  }
1399  }
1400  }
1401 
1402  std::sort( aVector.begin(), aVector.end(), sortPadsByXthenYCoord );
1403 }
1404 
1405 
1407 {
1408  GetConnectivity()->Remove( aPad );
1409  aPad->DeleteStructure();
1410 }
1411 
1412 
1413 std::tuple<int, double, double> BOARD::GetTrackLength( const TRACK& aTrack ) const
1414 {
1415  int count = 0;
1416  double length = 0.0;
1417  double package_length = 0.0;
1418 
1419  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, PCB_PAD_T, EOT };
1420  auto connectivity = GetBoard()->GetConnectivity();
1421 
1422  for( auto item : connectivity->GetConnectedItems(
1423  static_cast<const BOARD_CONNECTED_ITEM*>( &aTrack ), types ) )
1424  {
1425  count++;
1426 
1427  if( auto track = dyn_cast<TRACK*>( item ) )
1428  {
1429  bool inPad = false;
1430 
1431  for( auto pad_it : connectivity->GetConnectedPads( item ) )
1432  {
1433  auto pad = static_cast<D_PAD*>( pad_it );
1434 
1435  if( pad->HitTest( track->GetStart(), track->GetWidth() / 2 )
1436  && pad->HitTest( track->GetEnd(), track->GetWidth() / 2 ) )
1437  {
1438  inPad = true;
1439  break;
1440  }
1441  }
1442 
1443  if( !inPad )
1444  length += track->GetLength();
1445  }
1446  else if( auto pad = dyn_cast<D_PAD*>( item ) )
1447  package_length += pad->GetPadToDieLength();
1448  }
1449 
1450  return std::make_tuple( count, length, package_length );
1451 }
1452 
1453 
1454 MODULE* BOARD::GetFootprint( const wxPoint& aPosition, PCB_LAYER_ID aActiveLayer,
1455  bool aVisibleOnly, bool aIgnoreLocked )
1456 {
1457  MODULE* module = NULL;
1458  MODULE* alt_module = NULL;
1459  int min_dim = 0x7FFFFFFF;
1460  int alt_min_dim = 0x7FFFFFFF;
1461  bool current_layer_back = IsBackLayer( aActiveLayer );
1462 
1463  for( auto pt_module : m_modules )
1464  {
1465  // is the ref point within the module's bounds?
1466  if( !pt_module->HitTest( aPosition ) )
1467  continue;
1468 
1469  // if caller wants to ignore locked modules, and this one is locked, skip it.
1470  if( aIgnoreLocked && pt_module->IsLocked() )
1471  continue;
1472 
1473  PCB_LAYER_ID layer = pt_module->GetLayer();
1474 
1475  // Filter non visible modules if requested
1476  if( !aVisibleOnly || IsModuleLayerVisible( layer ) )
1477  {
1478  EDA_RECT bb = pt_module->GetFootprintRect();
1479 
1480  int offx = bb.GetX() + bb.GetWidth() / 2;
1481  int offy = bb.GetY() + bb.GetHeight() / 2;
1482 
1483  // off x & offy point to the middle of the box.
1484  int dist = ( aPosition.x - offx ) * ( aPosition.x - offx ) +
1485  ( aPosition.y - offy ) * ( aPosition.y - offy );
1486 
1487  if( current_layer_back == IsBackLayer( layer ) )
1488  {
1489  if( dist <= min_dim )
1490  {
1491  // better footprint shown on the active side
1492  module = pt_module;
1493  min_dim = dist;
1494  }
1495  }
1496  else if( aVisibleOnly && IsModuleLayerVisible( layer ) )
1497  {
1498  if( dist <= alt_min_dim )
1499  {
1500  // better footprint shown on the other side
1501  alt_module = pt_module;
1502  alt_min_dim = dist;
1503  }
1504  }
1505  }
1506  }
1507 
1508  if( module )
1509  {
1510  return module;
1511  }
1512 
1513  if( alt_module)
1514  {
1515  return alt_module;
1516  }
1517 
1518  return NULL;
1519 }
1520 
1521 
1522 ZONE_CONTAINER* BOARD::AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode,
1523  PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch )
1524 {
1525  ZONE_CONTAINER* new_area = InsertArea( aNetcode,
1526  m_ZoneDescriptorList.size( ) - 1,
1527  aLayer, aStartPointPosition.x,
1528  aStartPointPosition.y, aHatch );
1529 
1530  if( aNewZonesList )
1531  {
1532  ITEM_PICKER picker( new_area, UR_NEW );
1533  aNewZonesList->PushItem( picker );
1534  }
1535 
1536  return new_area;
1537 }
1538 
1539 
1540 void BOARD::RemoveArea( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_to_remove )
1541 {
1542  if( area_to_remove == NULL )
1543  return;
1544 
1545  if( aDeletedList )
1546  {
1547  ITEM_PICKER picker( area_to_remove, UR_DELETED );
1548  aDeletedList->PushItem( picker );
1549  Remove( area_to_remove ); // remove from zone list, but does not delete it
1550  }
1551  else
1552  {
1553  Delete( area_to_remove );
1554  }
1555 }
1556 
1557 
1558 ZONE_CONTAINER* BOARD::InsertArea( int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer,
1559  int aCornerX, int aCornerY, int aHatch )
1560 {
1561  ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this );
1562 
1563  new_area->SetNetCode( aNetcode );
1564  new_area->SetLayer( aLayer );
1565  new_area->SetTimeStamp( GetNewTimeStamp() );
1566 
1567  if( aAreaIdx < (int) ( m_ZoneDescriptorList.size() - 1 ) )
1568  m_ZoneDescriptorList.insert( m_ZoneDescriptorList.begin() + aAreaIdx + 1, new_area );
1569  else
1570  m_ZoneDescriptorList.push_back( new_area );
1571 
1572  new_area->SetHatchStyle( (ZONE_CONTAINER::HATCH_STYLE) aHatch );
1573 
1574  // Add the first corner to the new zone
1575  new_area->AppendCorner( wxPoint( aCornerX, aCornerY ), -1 );
1576 
1577  return new_area;
1578 }
1579 
1580 
1582 {
1583  // mark all areas as unmodified except this one, if modified
1584  for( ZONE_CONTAINER* zone : m_ZoneDescriptorList )
1585  zone->SetLocalFlags( 0 );
1586 
1587  aCurrArea->SetLocalFlags( 1 );
1588 
1589  if( aCurrArea->Outline()->IsSelfIntersecting() )
1590  {
1591  aCurrArea->UnHatch();
1592 
1593  // Normalize copied area and store resulting number of polygons
1594  int n_poly = aCurrArea->Outline()->NormalizeAreaOutlines();
1595 
1596  // If clipping has created some polygons, we must add these new copper areas.
1597  if( n_poly > 1 )
1598  {
1599  ZONE_CONTAINER* NewArea;
1600 
1601  // Move the newly created polygons to new areas, removing them from the current area
1602  for( int ip = 1; ip < n_poly; ip++ )
1603  {
1604  // Create new copper area and copy poly into it
1605  SHAPE_POLY_SET* new_p = new SHAPE_POLY_SET( aCurrArea->Outline()->UnitSet( ip ) );
1606  NewArea = AddArea( aNewZonesList, aCurrArea->GetNetCode(), aCurrArea->GetLayer(),
1607  wxPoint(0, 0), aCurrArea->GetHatchStyle() );
1608 
1609  // remove the poly that was automatically created for the new area
1610  // and replace it with a poly from NormalizeAreaOutlines
1611  delete NewArea->Outline();
1612  NewArea->SetOutline( new_p );
1613  NewArea->Hatch();
1614  NewArea->SetLocalFlags( 1 );
1615  }
1616 
1617  SHAPE_POLY_SET* new_p = new SHAPE_POLY_SET( aCurrArea->Outline()->UnitSet( 0 ) );
1618  delete aCurrArea->Outline();
1619  aCurrArea->SetOutline( new_p );
1620  }
1621  }
1622 
1623  aCurrArea->Hatch();
1624 
1625  return true;
1626 }
1627 
1628 
1629 BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, bool aAddToBoard )
1630 {
1631  BOARD_ITEM* new_item = NULL;
1632 
1633  switch( aItem->Type() )
1634  {
1635  case PCB_MODULE_T:
1636  case PCB_TEXT_T:
1637  case PCB_LINE_T:
1638  case PCB_TRACE_T:
1639  case PCB_VIA_T:
1640  case PCB_ZONE_AREA_T:
1641  case PCB_TARGET_T:
1642  case PCB_DIMENSION_T:
1643  new_item = static_cast<BOARD_ITEM*>( aItem->Clone() );
1644  break;
1645 
1646  default:
1647  // Un-handled item for duplication
1648  new_item = NULL;
1649  break;
1650  }
1651 
1652  if( new_item && aAddToBoard )
1653  Add( new_item );
1654 
1655  return new_item;
1656 }
1657 
1658 
1659 /* Extracts the board outlines and build a closed polygon
1660  * from lines, arcs and circle items on edge cut layer
1661  * Any closed outline inside the main outline is a hole
1662  * All contours should be closed, i.e. are valid vertices for a closed polygon
1663  * return true if success, false if a contour is not valid
1664  */
1665 extern bool BuildBoardPolygonOutlines( BOARD* aBoard, SHAPE_POLY_SET& aOutlines,
1666  wxString* aErrorText, unsigned int aTolerance,
1667  wxPoint* aErrorLocation = nullptr );
1668 
1669 
1670 bool BOARD::GetBoardPolygonOutlines( SHAPE_POLY_SET& aOutlines, wxString* aErrorText, wxPoint* aErrorLocation )
1671 {
1672 
1673  bool success = BuildBoardPolygonOutlines( this, aOutlines, aErrorText,
1674  GetDesignSettings().m_MaxError, aErrorLocation );
1675 
1676  // Make polygon strictly simple to avoid issues (especially in 3D viewer)
1678 
1679  return success;
1680 
1681 }
1682 
1683 
1684 const std::vector<D_PAD*> BOARD::GetPads()
1685 {
1686  std::vector<D_PAD*> allPads;
1687 
1688  for( MODULE* mod : Modules() )
1689  {
1690  for( D_PAD* pad : mod->Pads() )
1691  allPads.push_back( pad );
1692  }
1693 
1694  return allPads;
1695 }
1696 
1697 
1699 {
1700  unsigned retval = 0;
1701 
1702  for( auto mod : Modules() )
1703  retval += mod->Pads().size();
1704 
1705  return retval;
1706 }
1707 
1708 
1713 D_PAD* BOARD::GetPad( unsigned aIndex ) const
1714 {
1715  unsigned count = 0;
1716 
1717  for( auto mod : m_modules )
1718  {
1719  for( auto pad : mod->Pads() )
1720  {
1721  if( count == aIndex )
1722  return pad;
1723 
1724  count++;
1725  }
1726  }
1727 
1728  return nullptr;
1729 }
1730 
1732 {
1733  for( auto zone : Zones() )
1734  zone->SetNetCode( 0 );
1735 
1736  for( auto pad : GetPads() )
1737  pad->SetNetCode( 0 );
1738 
1739  for( auto track : Tracks() )
1740  track->SetNetCode( 0 );
1741 }
1742 
1743 const std::vector<BOARD_CONNECTED_ITEM*> BOARD::AllConnectedItems()
1744 {
1745  std::vector<BOARD_CONNECTED_ITEM*> items;
1746 
1747  for( auto track : Tracks() )
1748  {
1749  items.push_back( track );
1750  }
1751 
1752  for( auto mod : Modules() )
1753  {
1754  for( auto pad : mod->Pads() )
1755  {
1756  items.push_back( pad );
1757  }
1758  }
1759 
1760  for( int i = 0; i<GetAreaCount(); i++ )
1761  {
1762  auto zone = GetArea( i );
1763  items.push_back( zone );
1764  }
1765 
1766  return items;
1767 }
1768 
1770 {
1771  for ( auto item : AllConnectedItems() )
1772  {
1773  if( FindNet( item->GetNetCode() ) == nullptr )
1774  item->SetNetCode( NETINFO_LIST::ORPHANED );
1775  }
1776 }
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:729
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:57
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:100
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:190
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:258
int GetWidth() const
Definition: eda_rect.h:119
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:237
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:540
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
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:200
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:447
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 EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
void SetOutline(SHAPE_POLY_SET *aOutline)
Definition: class_zone.h:240
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:95
const wxString GetReference() const
Function GetReference.
Definition: class_module.h:416
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:955
Class LSET is a set of PCB_LAYER_IDs.
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:510
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:236
void DeleteMARKERs()
Function DeleteMARKERs deletes ALL MARKERS from the board.
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
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:310
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:217
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:64
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:98
#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:99
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
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:97
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:250
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:971
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:196
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:102
size_t i
Definition: json11.cpp:597
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...
Definition: class_zone.cpp:985
int GetY() const
Definition: eda_rect.h:112
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:515
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:232
The common library.
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:878
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:912
PCB_TARGET class definition.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
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:926
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:245
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:227
bool IsOnCopperLayer() const override
Function IsOnCopperLayer.
Definition: class_zone.cpp:196
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:659
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
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)