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) 2017 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-2016 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 <limits.h>
34 #include <algorithm>
35 #include <iterator>
36 
37 #include <fctsys.h>
38 #include <common.h>
39 #include <kicad_string.h>
40 #include <pcb_base_frame.h>
41 #include <msgpanel.h>
42 #include <pcb_netlist.h>
43 #include <reporter.h>
44 #include <base_units.h>
45 #include <ratsnest_data.h>
46 #include <ratsnest_viewitem.h>
47 #include <worksheet_viewitem.h>
48 
49 #include <pcbnew.h>
50 #include <collectors.h>
51 
52 #include <class_board.h>
53 #include <class_module.h>
54 #include <class_track.h>
55 #include <class_zone.h>
56 #include <class_marker_pcb.h>
57 #include <class_drawsegment.h>
58 #include <class_pcb_text.h>
59 #include <class_pcb_target.h>
60 #include <class_dimension.h>
61 #include <connectivity_data.h>
62 
63 
64 /* This is an odd place for this, but CvPcb won't link if it is
65  * in class_board_item.cpp like I first tried it.
66  */
68 
69 // this is a dummy colors settings (defined colors are the vdefulat values)
70 // used to initialize the board.
71 // these settings will be overriden later, depending on the draw frame that displays the board.
72 // However, when a board is created by a python script, outside a frame, the colors must be set
73 // so dummyColorsSettings provide this default initialization
75 
78  m_paper( PAGE_INFO::A4 ), m_NetInfo( this )
79 {
80  // we have not loaded a board yet, assume latest until then.
81  m_fileFormatVersionAtLoad = LEGACY_BOARD_FILE_VERSION;
82 
84  m_Status_Pcb = 0; // Status word: bit 1 = calculate.
85  m_CurrentZoneContour = NULL; // This ZONE_CONTAINER handle the
86  // zone contour currently in progress
87 
88  BuildListOfNets(); // prepare pad and netlist containers.
89 
90  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
91  {
92  m_Layer[layer].m_name = GetStandardLayerName( ToLAYER_ID( layer ) );
93 
94  if( IsCopperLayer( layer ) )
95  m_Layer[layer].m_type = LT_SIGNAL;
96  else
97  m_Layer[layer].m_type = LT_UNDEFINED;
98  }
99 
100  // Initialize default netclass.
101  NETCLASSPTR defaultClass = m_designSettings.GetDefault();
102  defaultClass->SetDescription( _( "This is the default net class." ) );
103  m_designSettings.SetCurrentNetClass( defaultClass->GetName() );
104 
105  // Set sensible initial values for custom track width & via size
110 
111  // Initialize ratsnest
112  m_connectivity.reset( new CONNECTIVITY_DATA() );
113 }
114 
115 
117 {
118  while( m_ZoneDescriptorList.size() )
119  {
120  ZONE_CONTAINER* area_to_remove = m_ZoneDescriptorList[0];
121  Delete( area_to_remove );
122  }
123 
124  DeleteMARKERs();
126 
127  delete m_CurrentZoneContour;
128  m_CurrentZoneContour = NULL;
129 }
130 
131 
133 {
134  GetConnectivity()->Build( this );
135 }
136 
137 
139 {
140  wxLogWarning( wxT( "This should not be called on the BOARD object") );
141 
142  return ZeroOffset;
143 }
144 
145 
146 void BOARD::SetPosition( const wxPoint& aPos )
147 {
148  wxLogWarning( wxT( "This should not be called on the BOARD object") );
149 }
150 
151 
152 void BOARD::Move( const wxPoint& aMoveVector ) // overload
153 {
154  // @todo : anything like this elsewhere? maybe put into GENERAL_COLLECTOR class.
155  static const KICAD_T top_level_board_stuff[] = {
156  PCB_MARKER_T,
157  PCB_TEXT_T,
158  PCB_LINE_T,
160  PCB_TARGET_T,
161  PCB_VIA_T,
162  PCB_TRACE_T,
163  // PCB_PAD_T, Can't be at board level
164  // PCB_MODULE_TEXT_T, Can't be at board level
165  PCB_MODULE_T,
167  EOT
168  };
169 
170  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
171  {
172  BOARD_ITEM* brd_item = (BOARD_ITEM*) item;
173 
174  // aMoveVector was snapshotted, don't need "data".
175  brd_item->Move( aMoveVector );
176 
177  return SEARCH_CONTINUE;
178  };
179 
180  Visit( inspector, NULL, top_level_board_stuff );
181 }
182 
183 
184 TRACKS BOARD::TracksInNet( int aNetCode )
185 {
186  TRACKS ret;
187 
188  INSPECTOR_FUNC inspector = [aNetCode,&ret] ( EDA_ITEM* item, void* testData )
189  {
190  TRACK* t = (TRACK*) item;
191 
192  if( t->GetNetCode() == aNetCode )
193  ret.push_back( t );
194 
195  return SEARCH_CONTINUE;
196  };
197 
198  // visit this BOARD's TRACKs and VIAs with above TRACK INSPECTOR which
199  // appends all in aNetCode to ret.
200  Visit( inspector, NULL, GENERAL_COLLECTOR::Tracks );
201 
202  return ret;
203 }
204 
205 
210 static void removeTrack( TRACKS* aList, TRACK* aOneToRemove )
211 {
212  aList->erase( std::remove( aList->begin(), aList->end(), aOneToRemove ), aList->end() );
213 }
214 
215 
216 static void otherEnd( const TRACK& aTrack, const wxPoint& aNotThisEnd, wxPoint* aOtherEnd )
217 {
218  if( aTrack.GetStart() == aNotThisEnd )
219  {
220  *aOtherEnd = aTrack.GetEnd();
221  }
222  else
223  {
224  wxASSERT( aTrack.GetEnd() == aNotThisEnd );
225  *aOtherEnd = aTrack.GetStart();
226  }
227 }
228 
229 
234 static int find_vias_and_tracks_at( TRACKS& at_next, TRACKS& in_net, LSET& lset, const wxPoint& next )
235 {
236  // first find all vias (in this net) at 'next' location, and expand LSET with each
237  for( TRACKS::iterator it = in_net.begin(); it != in_net.end(); )
238  {
239  TRACK* t = *it;
240 
241  if( t->Type() == PCB_VIA_T && (t->GetLayerSet() & lset).any() &&
242  ( t->GetStart() == next || t->GetEnd() == next ) )
243  {
244  lset |= t->GetLayerSet();
245  at_next.push_back( t );
246  it = in_net.erase( it );
247  }
248  else
249  ++it;
250  }
251 
252  int track_count = 0;
253 
254  // with expanded lset, find all tracks with an end on any of the layers in lset
255  for( TRACKS::iterator it = in_net.begin(); it != in_net.end(); /* iterates in the loop body */ )
256  {
257  TRACK* t = *it;
258 
259  if( ( t->GetLayerSet() & lset ).any() && ( t->GetStart() == next || t->GetEnd() == next ) )
260  {
261  at_next.push_back( t );
262  it = in_net.erase( it );
263  ++track_count;
264  }
265  else
266  {
267  ++it;
268  }
269  }
270 
271  return track_count;
272 }
273 
274 
286 static void checkConnectedTo( BOARD* aBoard, TRACKS* aList, const TRACKS& aTracksInNet,
287  const wxPoint& aGoal, const wxPoint& aStart, TRACK* aFirstTrack )
288 {
289  TRACKS in_net = aTracksInNet; // copy source list so the copy can be modified
290  wxPoint next;
291 
292  otherEnd( *aFirstTrack, aStart, &next );
293 
294  aList->push_back( aFirstTrack );
295  removeTrack( &in_net, aFirstTrack );
296 
297  LSET lset( aFirstTrack->GetLayer() );
298 
299  while( in_net.size() )
300  {
301  if( next == aGoal )
302  return; // success
303 
304  // Want an exact match on the position of next, i.e. pad at next,
305  // not a forgiving HitTest() with tolerance type of match, otherwise the overall
306  // algorithm will not work. GetPadFast() is an exact match as I write this.
307  if( aBoard->GetPadFast( next, lset ) )
308  {
309  std::string m = StrPrintf(
310  "intervening pad at:(xy %s) between start:(xy %s) and goal:(xy %s)",
311  BOARD_ITEM::FormatInternalUnits( next ).c_str(),
312  BOARD_ITEM::FormatInternalUnits( aStart ).c_str(),
313  BOARD_ITEM::FormatInternalUnits( aGoal ).c_str()
314  );
315  THROW_IO_ERROR( m );
316  }
317 
318  int track_count = find_vias_and_tracks_at( *aList, in_net, lset, next );
319 
320  if( track_count != 1 )
321  {
322  std::string m = StrPrintf(
323  "found %d tracks intersecting at (xy %s), exactly 2 would be acceptable.",
324  track_count + aList->size() == 1 ? 1 : 0,
325  BOARD_ITEM::FormatInternalUnits( next ).c_str()
326  );
327  THROW_IO_ERROR( m );
328  }
329 
330  // reduce lset down to the layer that the last track at 'next' is on.
331  lset = aList->back()->GetLayerSet();
332 
333  otherEnd( *aList->back(), next, &next );
334  }
335 
336  std::string m = StrPrintf(
337  "not enough tracks connecting start:(xy %s) and goal:(xy %s).",
338  BOARD_ITEM::FormatInternalUnits( aStart ).c_str(),
339  BOARD_ITEM::FormatInternalUnits( aGoal ).c_str()
340  );
341  THROW_IO_ERROR( m );
342 }
343 
344 
345 TRACKS BOARD::TracksInNetBetweenPoints( const wxPoint& aStartPos, const wxPoint& aGoalPos, int aNetCode )
346 {
347  TRACKS in_between_pts;
348  TRACKS on_start_point;
349  TRACKS in_net = TracksInNet( aNetCode ); // a small subset of TRACKs and VIAs
350 
351  for( auto t : in_net )
352  {
353  if( t->Type() == PCB_TRACE_T && ( t->GetStart() == aStartPos || t->GetEnd() == aStartPos ) )
354  on_start_point.push_back( t );
355  }
356 
357  wxString per_path_problem_text;
358 
359  for( auto t : on_start_point ) // explore each trace (path) leaving aStartPos
360  {
361  // checkConnectedTo() fills in_between_pts on every attempt. For failures
362  // this set needs to be cleared.
363  in_between_pts.clear();
364 
365  try
366  {
367  checkConnectedTo( this, &in_between_pts, in_net, aGoalPos, aStartPos, t );
368  }
369  catch( const IO_ERROR& ioe ) // means not connected
370  {
371  per_path_problem_text += "\n\t";
372  per_path_problem_text += ioe.Problem();
373  continue; // keep trying, there may be other paths leaving from aStartPos
374  }
375 
376  // success, no exception means a valid connection,
377  // return this set of TRACKS without throwing.
378  return in_between_pts;
379  }
380 
381  wxString m = wxString::Format(
382  "no clean path connecting start:(xy %s) with goal:(xy %s)",
383  BOARD_ITEM::FormatInternalUnits( aStartPos ).c_str(),
384  BOARD_ITEM::FormatInternalUnits( aGoalPos ).c_str()
385  );
386 
387  THROW_IO_ERROR( m + per_path_problem_text );
388 }
389 
390 
391 void BOARD::chainMarkedSegments( wxPoint aPosition, const LSET& aLayerSet, TRACKS* aList )
392 {
393  LSET layer_set = aLayerSet;
394 
395  if( !m_Track ) // no tracks at all in board
396  return;
397 
398  D_PAD* pad = NULL;
399  double distanceToPadCenter;
400 
401  /* Set the BUSY flag of all connected segments, first search starting at
402  * aPosition. The search ends when a pad is found (end of a track), a
403  * segment end has more than one other segment end connected, or when no
404  * connected item found.
405  *
406  * Vias are a special case because they must look for segments connected
407  * on other layers and they change the layer mask. They can be a track
408  * end or not. They will be analyzer later and vias on terminal points
409  * of the track will be considered as part of this track if they do not
410  * connect segments of a other track together and will be considered as
411  * part of a other track when removing the via, the segments of that other
412  * track are disconnected.
413  */
414  for( ; ; )
415  {
416 
417  if( !pad )
418  pad = GetPad( aPosition, layer_set );
419  if( pad )
420  distanceToPadCenter = GetLineLength( aPosition, pad->GetCenter() );
421 
422  /* Test for a via: a via changes the layer mask and can connect a lot
423  * of segments at location aPosition. When found, the via is just
424  * pushed in list. Vias will be examined later, when all connected
425  * segment are found and push in list. This is because when a via
426  * is found we do not know at this time the number of connected items
427  * and we do not know if this via is on the track or finish the track
428  */
429  TRACK* via = m_Track->GetVia( NULL, aPosition, layer_set );
430 
431  if( via )
432  {
433  layer_set = via->GetLayerSet();
434 
435  aList->push_back( via );
436  }
437 
438  int seg_count = 0;
439  TRACK* candidate = NULL;
440 
441  /* Search all segments connected to point aPosition.
442  * if only 1 segment at aPosition: then this segment is "candidate"
443  * if > 1 segment:
444  * then end of "track" (because more than 2 segments are connected at aPosition)
445  */
446  TRACK* segment = m_Track;
447 
448  while( ( segment = ::GetTrack( segment, NULL, aPosition, layer_set ) ) != NULL )
449  {
450  if( segment->GetState( BUSY ) ) // already found and selected: skip it
451  {
452  segment = segment->Next();
453  continue;
454  }
455 
456  if( segment == via ) // just previously found: skip it
457  {
458  segment = segment->Next();
459  continue;
460  }
461 
462  if( ++seg_count == 1 ) // if first connected item: then segment is candidate
463  {
464  candidate = segment;
465  segment = segment->Next();
466  }
467  else // More than 1 segment connected -> location is end of track
468  {
469  return;
470  }
471  }
472 
473  if( candidate ) // A candidate is found: flag it and push it in list
474  {
475  /* Initialize parameters to search items connected to this
476  * candidate:
477  * we must analyze connections to its other end
478  */
479  if( aPosition == candidate->GetStart() )
480  {
481  aPosition = candidate->GetEnd();
482  }
483  else
484  {
485  aPosition = candidate->GetStart();
486  }
487 
488  /* If we are in a pad, only candidates approaching the pad center
489  * are accepted.
490  */
491  if( pad )
492  {
493  if( GetPad( aPosition, layer_set ) != pad )
494  return;
495  if( GetLineLength( aPosition, pad->GetCenter() ) > distanceToPadCenter )
496  return;
497  }
498 
499  layer_set = candidate->GetLayerSet();
500 
501  // flag this item and push it in list of selected items
502  aList->push_back( candidate );
503  candidate->SetState( BUSY, true );
504  }
505  else
506  {
507  return;
508  }
509  }
510 }
511 
512 
514 {
516 }
517 
518 
520 {
523 }
524 
525 
526 bool BOARD::SetLayerDescr( PCB_LAYER_ID aIndex, const LAYER& aLayer )
527 {
528  if( unsigned( aIndex ) < DIM( m_Layer ) )
529  {
530  m_Layer[ aIndex ] = aLayer;
531  return true;
532  }
533 
534  return false;
535 }
536 
537 #include <stdio.h>
538 
539 const PCB_LAYER_ID BOARD::GetLayerID( const wxString& aLayerName ) const
540 {
541 
542  // Look for the BOARD specific copper layer names
543  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
544  {
545  if ( IsCopperLayer( layer ) && ( m_Layer[ layer ].m_name == aLayerName ) )
546  {
547  return ToLAYER_ID( layer );
548  }
549  }
550 
551  // Otherwise fall back to the system standard layer names
552  for( LAYER_NUM layer = 0; layer < PCB_LAYER_ID_COUNT; ++layer )
553  {
554  if( GetStandardLayerName( ToLAYER_ID( layer ) ) == aLayerName )
555  {
556  return ToLAYER_ID( layer );
557  }
558  }
559 
560  return UNDEFINED_LAYER;
561 }
562 
563 const wxString BOARD::GetLayerName( PCB_LAYER_ID aLayer ) const
564 {
565  // All layer names are stored in the BOARD.
566  if( IsLayerEnabled( aLayer ) )
567  {
568  // Standard names were set in BOARD::BOARD() but they may be
569  // over-ridden by BOARD::SetLayerName().
570  // For copper layers, return the actual copper layer name,
571  // otherwise return the Standard English layer name.
572  if( IsCopperLayer( aLayer ) )
573  return m_Layer[aLayer].m_name;
574  }
575 
576  return GetStandardLayerName( aLayer );
577 }
578 
579 bool BOARD::SetLayerName( PCB_LAYER_ID aLayer, const wxString& aLayerName )
580 {
581  if( !IsCopperLayer( aLayer ) )
582  return false;
583 
584  if( aLayerName == wxEmptyString || aLayerName.Len() > 20 )
585  return false;
586 
587  // no quote chars in the name allowed
588  if( aLayerName.Find( wxChar( '"' ) ) != wxNOT_FOUND )
589  return false;
590 
591  wxString nameTemp = aLayerName;
592 
593  // replace any spaces with underscores before we do any comparing
594  nameTemp.Replace( wxT( " " ), wxT( "_" ) );
595 
596  if( IsLayerEnabled( aLayer ) )
597  {
598 #if 0
599  for( LAYER_NUM i = FIRST_COPPER_LAYER; i < NB_COPPER_LAYERS; ++i )
600  {
601  if( i != aLayer && IsLayerEnabled( i ) && nameTemp == m_Layer[i].m_Name )
602  return false;
603  }
604 #else
605  for( LSEQ cu = GetEnabledLayers().CuStack(); cu; ++cu )
606  {
607  PCB_LAYER_ID id = *cu;
608 
609  // veto changing the name if it exists elsewhere.
610  if( id != aLayer && nameTemp == m_Layer[id].m_name )
611 // if( id != aLayer && nameTemp == wxString( m_Layer[id].m_name ) )
612  return false;
613  }
614 #endif
615 
616  m_Layer[aLayer].m_name = nameTemp;
617 
618  return true;
619  }
620 
621  return false;
622 }
623 
624 
626 {
627  if( !IsCopperLayer( aLayer ) )
628  return LT_SIGNAL;
629 
630  //@@IMB: The original test was broken due to the discontinuity
631  // in the layer sequence.
632  if( IsLayerEnabled( aLayer ) )
633  return m_Layer[aLayer].m_type;
634 
635  return LT_SIGNAL;
636 }
637 
638 
639 bool BOARD::SetLayerType( PCB_LAYER_ID aLayer, LAYER_T aLayerType )
640 {
641  if( !IsCopperLayer( aLayer ) )
642  return false;
643 
644  //@@IMB: The original test was broken due to the discontinuity
645  // in the layer sequence.
646  if( IsLayerEnabled( aLayer ) )
647  {
648  m_Layer[aLayer].m_type = aLayerType;
649  return true;
650  }
651 
652  return false;
653 }
654 
655 
656 const char* LAYER::ShowType( LAYER_T aType )
657 {
658  const char* cp;
659 
660  switch( aType )
661  {
662  default:
663  case LT_SIGNAL:
664  cp = "signal";
665  break;
666 
667  case LT_POWER:
668  cp = "power";
669  break;
670 
671  case LT_MIXED:
672  cp = "mixed";
673  break;
674 
675  case LT_JUMPER:
676  cp = "jumper";
677  break;
678  }
679 
680  return cp;
681 }
682 
683 
684 LAYER_T LAYER::ParseType( const char* aType )
685 {
686  if( strcmp( aType, "signal" ) == 0 )
687  return LT_SIGNAL;
688  else if( strcmp( aType, "power" ) == 0 )
689  return LT_POWER;
690  else if( strcmp( aType, "mixed" ) == 0 )
691  return LT_MIXED;
692  else if( strcmp( aType, "jumper" ) == 0 )
693  return LT_JUMPER;
694  else
695  return LT_UNDEFINED;
696 }
697 
698 
700 {
702 }
703 
704 
705 void BOARD::SetCopperLayerCount( int aCount )
706 {
708 }
709 
710 
712 {
714 }
715 
716 
718 {
720 }
721 
722 
723 void BOARD::SetEnabledLayers( LSET aLayerSet )
724 {
725  m_designSettings.SetEnabledLayers( aLayerSet );
726 }
727 
728 
729 void BOARD::SetVisibleLayers( LSET aLayerSet )
730 {
731  m_designSettings.SetVisibleLayers( aLayerSet );
732 }
733 
734 
735 void BOARD::SetVisibleElements( int aMask )
736 {
737  // Call SetElementVisibility for each item
738  // to ensure specific calculations that can be needed by some items,
739  // just changing the visibility flags could be not sufficient.
741  {
742  int item_mask = 1 << GAL_LAYER_INDEX( ii );
743  SetElementVisibility( ii, aMask & item_mask );
744  }
745 }
746 
747 
749 {
750  SetVisibleLayers( LSET().set() );
751 
752  // Call SetElementVisibility for each item,
753  // to ensure specific calculations that can be needed by some items
755  SetElementVisibility( ii, true );
756 }
757 
758 
760 {
762 }
763 
764 
766 {
767  return m_designSettings.IsElementVisible( aLayer );
768 }
769 
770 
771 void BOARD::SetElementVisibility( GAL_LAYER_ID aLayer, bool isEnabled )
772 {
773  m_designSettings.SetElementVisibility( aLayer, isEnabled );
774 
775  switch( aLayer )
776  {
777  case LAYER_RATSNEST:
778  {
779  bool visible = IsElementVisible( LAYER_RATSNEST );
780  // we must clear or set the CH_VISIBLE flags to hide/show ratsnest
781  // because we have a tool to show/hide ratsnest relative to a pad or a module
782  // so the hide/show option is a per item selection
783 
784  for( unsigned int net = 1; net < GetNetCount(); net++ )
785  {
786  auto rn = GetConnectivity()->GetRatsnestForNet( net );
787  if( rn )
788  rn->SetVisible( visible );
789  }
790 
791  for( auto track : Tracks() )
792  track->SetLocalRatsnestVisible( isEnabled );
793 
794  for( auto mod : Modules() )
795  {
796  for( auto pad : mod->Pads() )
797  pad->SetLocalRatsnestVisible( isEnabled );
798  }
799 
800  for( int i = 0; i<GetAreaCount(); i++ )
801  {
802  auto zone = GetArea( i );
803  zone->SetLocalRatsnestVisible( isEnabled );
804  }
805 
806  m_Status_Pcb = 0;
807 
808  break;
809  }
810 
811  default:
812  ;
813  }
814 }
815 
816 
818 {
819  switch( aLayer )
820  {
821  case F_Cu:
822  return IsElementVisible( LAYER_MOD_FR );
823 
824  case B_Cu:
825  return IsElementVisible( LAYER_MOD_BK );
826 
827  default:
828  wxFAIL_MSG( wxT( "BOARD::IsModuleLayerVisible() param error: bad layer" ) );
829  return true;
830  }
831 }
832 
833 
834 void BOARD::Add( BOARD_ITEM* aBoardItem, ADD_MODE aMode )
835 {
836  if( aBoardItem == NULL )
837  {
838  wxFAIL_MSG( wxT( "BOARD::Add() param error: aBoardItem NULL" ) );
839  return;
840  }
841 
842  switch( aBoardItem->Type() )
843  {
844  case PCB_NETINFO_T:
845  m_NetInfo.AppendNet( (NETINFO_ITEM*) aBoardItem );
846  break;
847 
848  // this one uses a vector
849  case PCB_MARKER_T:
850  m_markers.push_back( (MARKER_PCB*) aBoardItem );
851  break;
852 
853  // this one uses a vector
854  case PCB_ZONE_AREA_T:
855  m_ZoneDescriptorList.push_back( (ZONE_CONTAINER*) aBoardItem );
856  break;
857 
858  case PCB_TRACE_T:
859  case PCB_VIA_T:
860  if( aMode == ADD_APPEND )
861  {
862  m_Track.PushBack( (TRACK*) aBoardItem );
863  }
864  else
865  {
866  TRACK* insertAid;
867  insertAid = ( (TRACK*) aBoardItem )->GetBestInsertPoint( this );
868  m_Track.Insert( (TRACK*) aBoardItem, insertAid );
869  }
870 
871  break;
872 
873  case PCB_ZONE_T:
874  if( aMode == ADD_APPEND )
875  m_Zone.PushBack( (SEGZONE*) aBoardItem );
876  else
877  m_Zone.PushFront( (SEGZONE*) aBoardItem );
878 
879  break;
880 
881  case PCB_MODULE_T:
882  if( aMode == ADD_APPEND )
883  m_Modules.PushBack( (MODULE*) aBoardItem );
884  else
885  m_Modules.PushFront( (MODULE*) aBoardItem );
886 
887  // Because the list of pads has changed, reset the status
888  // This indicate the list of pad and nets must be recalculated before use
889  m_Status_Pcb = 0;
890  break;
891 
892  case PCB_DIMENSION_T:
893  case PCB_LINE_T:
894  case PCB_TEXT_T:
895  case PCB_TARGET_T:
896  if( aMode == ADD_APPEND )
897  m_Drawings.PushBack( aBoardItem );
898  else
899  m_Drawings.PushFront( aBoardItem );
900 
901  break;
902 
903  // other types may use linked list
904  default:
905  {
906  wxString msg;
907  msg.Printf( wxT( "BOARD::Add() needs work: BOARD_ITEM type (%d) not handled" ),
908  aBoardItem->Type() );
909  wxFAIL_MSG( msg );
910  return;
911  }
912  break;
913  }
914 
915  aBoardItem->SetParent( this );
916  m_connectivity->Add( aBoardItem );
917 }
918 
919 
920 void BOARD::Remove( BOARD_ITEM* aBoardItem )
921 {
922  // find these calls and fix them! Don't send me no stinking' NULL.
923  wxASSERT( aBoardItem );
924 
925  switch( aBoardItem->Type() )
926  {
927  case PCB_NETINFO_T:
928  {
929  NETINFO_ITEM* item = (NETINFO_ITEM*) aBoardItem;
930  m_NetInfo.RemoveNet( item );
931  break;
932  }
933 
934  case PCB_MARKER_T:
935 
936  // find the item in the vector, then remove it
937  for( unsigned i = 0; i<m_markers.size(); ++i )
938  {
939  if( m_markers[i] == (MARKER_PCB*) aBoardItem )
940  {
941  m_markers.erase( m_markers.begin() + i );
942  break;
943  }
944  }
945 
946  break;
947 
948  case PCB_ZONE_AREA_T: // this one uses a vector
949  // find the item in the vector, then delete then erase it.
950  for( unsigned i = 0; i<m_ZoneDescriptorList.size(); ++i )
951  {
952  if( m_ZoneDescriptorList[i] == (ZONE_CONTAINER*) aBoardItem )
953  {
954  m_ZoneDescriptorList.erase( m_ZoneDescriptorList.begin() + i );
955  break;
956  }
957  }
958  break;
959 
960  case PCB_MODULE_T:
961  m_Modules.Remove( (MODULE*) aBoardItem );
962  break;
963 
964  case PCB_TRACE_T:
965  case PCB_VIA_T:
966  m_Track.Remove( (TRACK*) aBoardItem );
967  break;
968 
969  case PCB_ZONE_T:
970  m_Zone.Remove( (SEGZONE*) aBoardItem );
971  break;
972 
973  case PCB_DIMENSION_T:
974  case PCB_LINE_T:
975  case PCB_TEXT_T:
976  case PCB_TARGET_T:
977  m_Drawings.Remove( aBoardItem );
978  break;
979 
980  // other types may use linked list
981  default:
982  wxFAIL_MSG( wxT( "BOARD::Remove() needs more ::Type() support" ) );
983  }
984 
985  m_connectivity->Remove( aBoardItem );
986 }
987 
988 
990 {
991  // the vector does not know how to delete the MARKER_PCB, it holds pointers
992  for( unsigned i = 0; i<m_markers.size(); ++i )
993  delete m_markers[i];
994 
995  m_markers.clear();
996 }
997 
998 
1000 {
1001  // the vector does not know how to delete the ZONE Outlines, it holds
1002  // pointers
1003  for( unsigned i = 0; i<m_ZoneDescriptorList.size(); ++i )
1004  delete m_ZoneDescriptorList[i];
1005 
1006  m_ZoneDescriptorList.clear();
1007 }
1008 
1009 
1011 {
1012  return m_Track.GetCount();
1013 }
1014 
1015 
1017 {
1018  return m_Zone.GetCount();
1019 }
1020 
1021 
1022 unsigned BOARD::GetNodesCount() const
1023 {
1024  return m_connectivity->GetPadCount();
1025 }
1026 
1027 
1029 {
1030  return m_connectivity->GetUnconnectedCount();
1031 }
1032 
1033 
1034 EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
1035 {
1036  bool hasItems = false;
1037  EDA_RECT area;
1038 
1039  // Check segments, dimensions, texts, and fiducials
1040  for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
1041  {
1042  if( aBoardEdgesOnly && (item->Type() != PCB_LINE_T || item->GetLayer() != Edge_Cuts ) )
1043  continue;
1044 
1045  if( !hasItems )
1046  area = item->GetBoundingBox();
1047  else
1048  area.Merge( item->GetBoundingBox() );
1049 
1050  hasItems = true;
1051  }
1052 
1053  if( !aBoardEdgesOnly )
1054  {
1055  // Check modules
1056  for( MODULE* module = m_Modules; module; module = module->Next() )
1057  {
1058  if( !hasItems )
1059  area = module->GetBoundingBox();
1060  else
1061  area.Merge( module->GetBoundingBox() );
1062 
1063  hasItems = true;
1064  }
1065 
1066  // Check tracks
1067  for( TRACK* track = m_Track; track; track = track->Next() )
1068  {
1069  if( !hasItems )
1070  area = track->GetBoundingBox();
1071  else
1072  area.Merge( track->GetBoundingBox() );
1073 
1074  hasItems = true;
1075  }
1076 
1077  // Check segment zones
1078  for( TRACK* track = m_Zone; track; track = track->Next() )
1079  {
1080  if( !hasItems )
1081  area = track->GetBoundingBox();
1082  else
1083  area.Merge( track->GetBoundingBox() );
1084 
1085  hasItems = true;
1086  }
1087 
1088  // Check polygonal zones
1089  for( unsigned int i = 0; i < m_ZoneDescriptorList.size(); i++ )
1090  {
1092 
1093  if( !hasItems )
1094  area = aZone->GetBoundingBox();
1095  else
1096  area.Merge( aZone->GetBoundingBox() );
1097 
1098  area.Merge( aZone->GetBoundingBox() );
1099  hasItems = true;
1100  }
1101  }
1102 
1103  return area;
1104 }
1105 
1106 
1107 void BOARD::GetMsgPanelInfo( std::vector< MSG_PANEL_ITEM >& aList )
1108 {
1109  wxString txt;
1110  int viasCount = 0;
1111  int trackSegmentsCount = 0;
1112 
1113  for( BOARD_ITEM* item = m_Track; item; item = item->Next() )
1114  {
1115  if( item->Type() == PCB_VIA_T )
1116  viasCount++;
1117  else
1118  trackSegmentsCount++;
1119  }
1120 
1121  txt.Printf( wxT( "%d" ), GetPadCount() );
1122  aList.push_back( MSG_PANEL_ITEM( _( "Pads" ), txt, DARKGREEN ) );
1123 
1124  txt.Printf( wxT( "%d" ), viasCount );
1125  aList.push_back( MSG_PANEL_ITEM( _( "Vias" ), txt, DARKGREEN ) );
1126 
1127  txt.Printf( wxT( "%d" ), trackSegmentsCount );
1128  aList.push_back( MSG_PANEL_ITEM( _( "Track Segments" ), txt, DARKGREEN ) );
1129 
1130  txt.Printf( wxT( "%d" ), GetNodesCount() );
1131  aList.push_back( MSG_PANEL_ITEM( _( "Nodes" ), txt, DARKCYAN ) );
1132 
1133  txt.Printf( wxT( "%d" ), m_NetInfo.GetNetCount() );
1134  aList.push_back( MSG_PANEL_ITEM( _( "Nets" ), txt, RED ) );
1135 
1136  txt.Printf( wxT( "%d" ), GetConnectivity()->GetUnconnectedCount() );
1137  aList.push_back( MSG_PANEL_ITEM( _( "Unconnected" ), txt, BLUE ) );
1138 }
1139 
1140 
1141 SEARCH_RESULT BOARD::Visit( INSPECTOR inspector, void* testData, const KICAD_T scanTypes[] )
1142 {
1143  KICAD_T stype;
1144  SEARCH_RESULT result = SEARCH_CONTINUE;
1145  const KICAD_T* p = scanTypes;
1146  bool done = false;
1147 
1148 #if 0 && defined(DEBUG)
1149  std::cout << GetClass().mb_str() << ' ';
1150 #endif
1151 
1152  while( !done )
1153  {
1154  stype = *p;
1155 
1156  switch( stype )
1157  {
1158  case PCB_T:
1159  result = inspector( this, testData ); // inspect me
1160  // skip over any types handled in the above call.
1161  ++p;
1162  break;
1163 
1164  /* Instances of the requested KICAD_T live in a list, either one
1165  * that I manage, or that my modules manage. If it's a type managed
1166  * by class MODULE, then simply pass it on to each module's
1167  * MODULE::Visit() function by way of the
1168  * IterateForward( m_Modules, ... ) call.
1169  */
1170 
1171  case PCB_MODULE_T:
1172  case PCB_PAD_T:
1173  case PCB_MODULE_TEXT_T:
1174  case PCB_MODULE_EDGE_T:
1175 
1176  // this calls MODULE::Visit() on each module.
1177  result = IterateForward( m_Modules, inspector, testData, p );
1178 
1179  // skip over any types handled in the above call.
1180  for( ; ; )
1181  {
1182  switch( stype = *++p )
1183  {
1184  case PCB_MODULE_T:
1185  case PCB_PAD_T:
1186  case PCB_MODULE_TEXT_T:
1187  case PCB_MODULE_EDGE_T:
1188  continue;
1189 
1190  default:
1191  ;
1192  }
1193 
1194  break;
1195  }
1196 
1197  break;
1198 
1199  case PCB_LINE_T:
1200  case PCB_TEXT_T:
1201  case PCB_DIMENSION_T:
1202  case PCB_TARGET_T:
1203  result = IterateForward( m_Drawings, inspector, testData, p );
1204 
1205  // skip over any types handled in the above call.
1206  for( ; ; )
1207  {
1208  switch( stype = *++p )
1209  {
1210  case PCB_LINE_T:
1211  case PCB_TEXT_T:
1212  case PCB_DIMENSION_T:
1213  case PCB_TARGET_T:
1214  continue;
1215 
1216  default:
1217  ;
1218  }
1219 
1220  break;
1221  }
1222 
1223  ;
1224  break;
1225 
1226 #if 0 // both these are on same list, so we must scan it twice in order
1227  // to get VIA priority, using new #else code below.
1228  // But we are not using separate lists for TRACKs and VIA, because
1229  // items are ordered (sorted) in the linked
1230  // list by netcode AND by physical distance:
1231  // when created, if a track or via is connected to an existing track or
1232  // via, it is put in linked list after this existing track or via
1233  // So usually, connected tracks or vias are grouped in this list
1234  // So the algorithm (used in ratsnest computations) which computes the
1235  // track connectivity is faster (more than 100 time regarding to
1236  // a non ordered list) because when it searches for a connection, first
1237  // it tests the near (near in term of linked list) 50 items
1238  // from the current item (track or via) in test.
1239  // Usually, because of this sort, a connected item (if exists) is
1240  // found.
1241  // If not found (and only in this case) an exhaustive (and time
1242  // consuming) search is made, but this case is statistically rare.
1243  case PCB_VIA_T:
1244  case PCB_TRACE_T:
1245  result = IterateForward( m_Track, inspector, testData, p );
1246 
1247  // skip over any types handled in the above call.
1248  for( ; ; )
1249  {
1250  switch( stype = *++p )
1251  {
1252  case PCB_VIA_T:
1253  case PCB_TRACE_T:
1254  continue;
1255 
1256  default:
1257  ;
1258  }
1259 
1260  break;
1261  }
1262 
1263  break;
1264 
1265 #else
1266  case PCB_VIA_T:
1267  result = IterateForward( m_Track, inspector, testData, p );
1268  ++p;
1269  break;
1270 
1271  case PCB_TRACE_T:
1272  result = IterateForward( m_Track, inspector, testData, p );
1273  ++p;
1274  break;
1275 #endif
1276 
1277  case PCB_MARKER_T:
1278 
1279  // MARKER_PCBS are in the m_markers std::vector
1280  for( unsigned i = 0; i<m_markers.size(); ++i )
1281  {
1282  result = m_markers[i]->Visit( inspector, testData, p );
1283 
1284  if( result == SEARCH_QUIT )
1285  break;
1286  }
1287 
1288  ++p;
1289  break;
1290 
1291  case PCB_ZONE_AREA_T:
1292 
1293  // PCB_ZONE_AREA_T are in the m_ZoneDescriptorList std::vector
1294  for( unsigned i = 0; i< m_ZoneDescriptorList.size(); ++i )
1295  {
1296  result = m_ZoneDescriptorList[i]->Visit( inspector, testData, p );
1297 
1298  if( result == SEARCH_QUIT )
1299  break;
1300  }
1301 
1302  ++p;
1303  break;
1304 
1305  case PCB_ZONE_T:
1306  result = IterateForward( m_Zone, inspector, testData, p );
1307  ++p;
1308  break;
1309 
1310  default: // catch EOT or ANY OTHER type here and return.
1311  done = true;
1312  break;
1313  }
1314 
1315  if( result == SEARCH_QUIT )
1316  break;
1317  }
1318 
1319  return result;
1320 }
1321 
1322 
1323 NETINFO_ITEM* BOARD::FindNet( int aNetcode ) const
1324 {
1325  // the first valid netcode is 1 and the last is m_NetInfo.GetCount()-1.
1326  // zero is reserved for "no connection" and is not actually a net.
1327  // NULL is returned for non valid netcodes
1328 
1329  wxASSERT( m_NetInfo.GetNetCount() > 0 ); // net zero should exist
1330 
1331  if( aNetcode == NETINFO_LIST::UNCONNECTED && m_NetInfo.GetNetCount() == 0 )
1333  else
1334  return m_NetInfo.GetNetItem( aNetcode );
1335 }
1336 
1337 
1338 NETINFO_ITEM* BOARD::FindNet( const wxString& aNetname ) const
1339 {
1340  return m_NetInfo.GetNetItem( aNetname );
1341 }
1342 
1343 
1344 MODULE* BOARD::FindModuleByReference( const wxString& aReference ) const
1345 {
1346  MODULE* found = nullptr;
1347 
1348  // search only for MODULES
1349  static const KICAD_T scanTypes[] = { PCB_MODULE_T, EOT };
1350 
1351  INSPECTOR_FUNC inspector = [&] ( EDA_ITEM* item, void* testData )
1352  {
1353  MODULE* module = (MODULE*) item;
1354 
1355  if( aReference == module->GetReference() )
1356  {
1357  found = module;
1358  return SEARCH_QUIT;
1359  }
1360 
1361  return SEARCH_CONTINUE;
1362  };
1363 
1364  // visit this BOARD with the above inspector
1365  BOARD* nonconstMe = (BOARD*) this;
1366  nonconstMe->Visit( inspector, NULL, scanTypes );
1367 
1368  return found;
1369 }
1370 
1371 
1372 MODULE* BOARD::FindModule( const wxString& aRefOrTimeStamp, bool aSearchByTimeStamp ) const
1373 {
1374  if( aSearchByTimeStamp )
1375  {
1376  for( MODULE* module = m_Modules; module; module = module->Next() )
1377  {
1378  if( aRefOrTimeStamp.CmpNoCase( module->GetPath() ) == 0 )
1379  return module;
1380  }
1381  }
1382  else
1383  {
1384  return FindModuleByReference( aRefOrTimeStamp );
1385  }
1386 
1387  return NULL;
1388 }
1389 
1390 
1391 // Sort nets by decreasing pad count. For same pad count, sort by alphabetic names
1392 static bool sortNetsByNodes( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
1393 {
1394  auto connectivity = a->GetParent()->GetConnectivity();
1395  int countA = connectivity->GetPadCount( a->GetNet() );
1396  int countB = connectivity->GetPadCount( b->GetNet() );
1397 
1398  if( countA == countB )
1399  return a->GetNetname() < b->GetNetname();
1400  else
1401  return countB < countA;
1402 }
1403 
1404 // Sort nets by alphabetic names
1405 static bool sortNetsByNames( const NETINFO_ITEM* a, const NETINFO_ITEM* b )
1406 {
1407  return a->GetNetname() < b->GetNetname();
1408 }
1409 
1410 int BOARD::SortedNetnamesList( wxArrayString& aNames, bool aSortbyPadsCount )
1411 {
1412  if( m_NetInfo.GetNetCount() == 0 )
1413  return 0;
1414 
1415  // Build the list
1416  std::vector <NETINFO_ITEM*> netBuffer;
1417 
1418  netBuffer.reserve( m_NetInfo.GetNetCount() );
1419 
1420  for( NETINFO_LIST::iterator net( m_NetInfo.begin() ), netEnd( m_NetInfo.end() );
1421  net != netEnd; ++net )
1422  {
1423  if( net->GetNet() > 0 )
1424  netBuffer.push_back( *net );
1425  }
1426 
1427  // sort the list
1428  if( aSortbyPadsCount )
1429  sort( netBuffer.begin(), netBuffer.end(), sortNetsByNodes );
1430  else
1431  sort( netBuffer.begin(), netBuffer.end(), sortNetsByNames );
1432 
1433  for( unsigned ii = 0; ii < netBuffer.size(); ii++ )
1434  aNames.Add( netBuffer[ii]->GetNetname() );
1435 
1436  return netBuffer.size();
1437 }
1438 
1439 
1440 void BOARD::RedrawAreasOutlines( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, PCB_LAYER_ID aLayer )
1441 {
1442  if( !aDC )
1443  return;
1444 
1445  for( int ii = 0; ii < GetAreaCount(); ii++ )
1446  {
1447  ZONE_CONTAINER* edge_zone = GetArea( ii );
1448 
1449  if( (aLayer < 0) || ( aLayer == edge_zone->GetLayer() ) )
1450  edge_zone->Draw( panel, aDC, aDrawMode );
1451  }
1452 }
1453 
1454 
1455 void BOARD::RedrawFilledAreas( EDA_DRAW_PANEL* panel, wxDC* aDC, GR_DRAWMODE aDrawMode, PCB_LAYER_ID aLayer )
1456 {
1457  if( !aDC )
1458  return;
1459 
1460  for( int ii = 0; ii < GetAreaCount(); ii++ )
1461  {
1462  ZONE_CONTAINER* edge_zone = GetArea( ii );
1463 
1464  if( (aLayer < 0) || ( aLayer == edge_zone->GetLayer() ) )
1465  edge_zone->DrawFilledArea( panel, aDC, aDrawMode );
1466  }
1467 }
1468 
1469 
1471  PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer, int aNetCode )
1472 {
1473  if( aEndLayer < 0 )
1474  aEndLayer = aStartLayer;
1475 
1476  if( aEndLayer < aStartLayer )
1477  std::swap( aEndLayer, aStartLayer );
1478 
1479  for( unsigned ia = 0; ia < m_ZoneDescriptorList.size(); ia++ )
1480  {
1482  LAYER_NUM layer = area->GetLayer();
1483 
1484  if( layer < aStartLayer || layer > aEndLayer )
1485  continue;
1486 
1487  // In locate functions we must skip tagged items with BUSY flag set.
1488  if( area->GetState( BUSY ) )
1489  continue;
1490 
1491  if( aNetCode >= 0 && area->GetNetCode() != aNetCode )
1492  continue;
1493 
1494  if( area->HitTestFilledArea( aRefPos ) )
1495  return area;
1496  }
1497 
1498  return NULL;
1499 }
1500 
1501 
1503 {
1504  int error_count = 0;
1505 
1506  for( int ii = 0; ii < GetAreaCount(); ii++ )
1507  {
1508  ZONE_CONTAINER* it = GetArea( ii );
1509 
1510  if( !it->IsOnCopperLayer() )
1511  {
1513  continue;
1514  }
1515 
1516  if( it->GetNetCode() != 0 ) // i.e. if this zone is connected to a net
1517  {
1518  const NETINFO_ITEM* net = it->GetNet();
1519 
1520  if( net )
1521  {
1522  it->SetNetCode( net->GetNet() );
1523  }
1524  else
1525  {
1526  error_count++;
1527 
1528  // keep Net Name and set m_NetCode to -1 : error flag.
1529  it->SetNetCode( -1 );
1530  }
1531  }
1532  }
1533 
1534  return error_count;
1535 }
1536 
1537 
1538 VIA* BOARD::GetViaByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer) const
1539 {
1540  for( VIA *via = GetFirstVia( m_Track); via; via = GetFirstVia( via->Next() ) )
1541  {
1542  if( (via->GetStart() == aPosition) &&
1543  (via->GetState( BUSY | IS_DELETED ) == 0) &&
1544  ((aLayer == UNDEFINED_LAYER) || (via->IsOnLayer( aLayer ))) )
1545  return via;
1546  }
1547 
1548  return NULL;
1549 }
1550 
1551 
1552 D_PAD* BOARD::GetPad( const wxPoint& aPosition, LSET aLayerSet )
1553 {
1554  if( !aLayerSet.any() )
1555  aLayerSet = LSET::AllCuMask();
1556 
1557  for( MODULE* module = m_Modules; module; module = module->Next() )
1558  {
1559  D_PAD* pad = module->GetPad( aPosition, aLayerSet );
1560 
1561  if( pad )
1562  return pad;
1563  }
1564 
1565  return NULL;
1566 }
1567 
1568 
1569 D_PAD* BOARD::GetPad( TRACK* aTrace, ENDPOINT_T aEndPoint )
1570 {
1571  const wxPoint& aPosition = aTrace->GetEndPoint( aEndPoint );
1572 
1573  LSET lset( aTrace->GetLayer() );
1574 
1575  for( MODULE* module = m_Modules; module; module = module->Next() )
1576  {
1577  D_PAD* pad = module->GetPad( aPosition, lset );
1578 
1579  if( pad )
1580  return pad;
1581  }
1582 
1583  return NULL;
1584 
1585 }
1586 
1587 
1588 std::list<TRACK*> BOARD::GetTracksByPosition( const wxPoint& aPosition, PCB_LAYER_ID aLayer ) const
1589 {
1590  std::list<TRACK*> tracks;
1591 
1592  for( TRACK* track = GetFirstTrack( m_Track ); track; track = GetFirstTrack( track->Next() ) )
1593  {
1594  if( ( ( track->GetStart() == aPosition ) || track->GetEnd() == aPosition ) &&
1595  ( track->GetState( BUSY | IS_DELETED ) == 0 ) &&
1596  ( ( aLayer == UNDEFINED_LAYER ) || ( track->IsOnLayer( aLayer ) ) ) )
1597 
1598  tracks.push_back( track );
1599  }
1600 
1601  return tracks;
1602 }
1603 
1604 
1605 D_PAD* BOARD::GetPadFast( const wxPoint& aPosition, LSET aLayerSet )
1606 {
1607  for( auto mod : Modules() )
1608  {
1609  for ( auto pad : mod->Pads() )
1610  {
1611  if( pad->GetPosition() != aPosition )
1612  continue;
1613 
1614  // Pad found, it must be on the correct layer
1615  if( ( pad->GetLayerSet() & aLayerSet ).any() )
1616  return pad;
1617  }
1618 }
1619 
1620  return nullptr;
1621 }
1622 
1623 
1624 D_PAD* BOARD::GetPad( std::vector<D_PAD*>& aPadList, const wxPoint& aPosition, LSET aLayerSet )
1625 {
1626  // Search aPadList for aPosition
1627  // aPadList is sorted by X then Y values, and a fast binary search is used
1628  int idxmax = aPadList.size()-1;
1629 
1630  int delta = aPadList.size();
1631 
1632  int idx = 0; // Starting index is the beginning of list
1633 
1634  while( delta )
1635  {
1636  // Calculate half size of remaining interval to test.
1637  // Ensure the computed value is not truncated (too small)
1638  if( (delta & 1) && ( delta > 1 ) )
1639  delta++;
1640 
1641  delta /= 2;
1642 
1643  D_PAD* pad = aPadList[idx];
1644 
1645  if( pad->GetPosition() == aPosition ) // candidate found
1646  {
1647  // The pad must match the layer mask:
1648  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1649  return pad;
1650 
1651  // More than one pad can be at aPosition
1652  // search for a pad at aPosition that matched this mask
1653 
1654  // search next
1655  for( int ii = idx+1; ii <= idxmax; ii++ )
1656  {
1657  pad = aPadList[ii];
1658 
1659  if( pad->GetPosition() != aPosition )
1660  break;
1661 
1662  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1663  return pad;
1664  }
1665  // search previous
1666  for( int ii = idx-1 ;ii >=0; ii-- )
1667  {
1668  pad = aPadList[ii];
1669 
1670  if( pad->GetPosition() != aPosition )
1671  break;
1672 
1673  if( ( aLayerSet & pad->GetLayerSet() ).any() )
1674  return pad;
1675  }
1676 
1677  // Not found:
1678  return 0;
1679  }
1680 
1681  if( pad->GetPosition().x == aPosition.x ) // Must search considering Y coordinate
1682  {
1683  if( pad->GetPosition().y < aPosition.y ) // Must search after this item
1684  {
1685  idx += delta;
1686 
1687  if( idx > idxmax )
1688  idx = idxmax;
1689  }
1690  else // Must search before this item
1691  {
1692  idx -= delta;
1693 
1694  if( idx < 0 )
1695  idx = 0;
1696  }
1697  }
1698  else if( pad->GetPosition().x < aPosition.x ) // Must search after this item
1699  {
1700  idx += delta;
1701 
1702  if( idx > idxmax )
1703  idx = idxmax;
1704  }
1705  else // Must search before this item
1706  {
1707  idx -= delta;
1708 
1709  if( idx < 0 )
1710  idx = 0;
1711  }
1712  }
1713 
1714  return NULL;
1715 }
1716 
1717 
1723 bool sortPadsByXthenYCoord( D_PAD* const & ref, D_PAD* const & comp )
1724 {
1725  if( ref->GetPosition().x == comp->GetPosition().x )
1726  return ref->GetPosition().y < comp->GetPosition().y;
1727  return ref->GetPosition().x < comp->GetPosition().x;
1728 }
1729 
1730 
1731 void BOARD::GetSortedPadListByXthenYCoord( std::vector<D_PAD*>& aVector, int aNetCode )
1732 {
1733  for ( auto mod : Modules() )
1734  {
1735  for ( auto pad : mod->Pads( ) )
1736  {
1737  if( aNetCode < 0 || pad->GetNetCode() == aNetCode )
1738  {
1739  aVector.push_back( pad );
1740  }
1741  }
1742  }
1743 
1744  std::sort( aVector.begin(), aVector.end(), sortPadsByXthenYCoord );
1745 }
1746 
1747 
1749 {
1750  aPad->DeleteStructure();
1751 }
1752 
1753 
1754 TRACK* BOARD::GetVisibleTrack( TRACK* aStartingTrace, const wxPoint& aPosition,
1755  LSET aLayerSet ) const
1756 {
1757  for( TRACK* track = aStartingTrace; track; track = track->Next() )
1758  {
1759  PCB_LAYER_ID layer = track->GetLayer();
1760 
1761  if( track->GetState( BUSY | IS_DELETED ) )
1762  continue;
1763 
1764  // track's layer is not visible
1765  if( m_designSettings.IsLayerVisible( layer ) == false )
1766  continue;
1767 
1768  if( track->Type() == PCB_VIA_T ) // VIA encountered.
1769  {
1770  if( track->HitTest( aPosition ) )
1771  return track;
1772  }
1773  else
1774  {
1775  if( !aLayerSet[layer] )
1776  continue; // track's layer is not in aLayerSet
1777 
1778  if( track->HitTest( aPosition ) )
1779  return track;
1780  }
1781  }
1782 
1783  return NULL;
1784 }
1785 
1786 
1787 #if defined(DEBUG) && 0
1788 static void dump_tracks( const char* aName, const TRACKS& aList )
1789 {
1790  printf( "%s: count=%zd\n", aName, aList.size() );
1791 
1792  for( unsigned i = 0; i < aList.size(); ++i )
1793  {
1794  TRACK* seg = aList[i];
1795  ::VIA* via = dynamic_cast< ::VIA* >( seg );
1796 
1797  if( via )
1798  printf( " via[%u]: (%d, %d)\n", i, via->GetStart().x, via->GetStart().y );
1799  else
1800  printf( " seg[%u]: (%d, %d) (%d, %d)\n", i,
1801  seg->GetStart().x, seg->GetStart().y,
1802  seg->GetEnd().x, seg->GetEnd().y );
1803  }
1804 }
1805 #endif
1806 
1807 
1808 
1809 
1810 TRACK* BOARD::MarkTrace( TRACK* aTrace, int* aCount,
1811  double* aTraceLength, double* aPadToDieLength,
1812  bool aReorder )
1813 {
1814  TRACKS trackList;
1815 
1816  if( aCount )
1817  *aCount = 0;
1818 
1819  if( aTraceLength )
1820  *aTraceLength = 0;
1821 
1822  if( aTrace == NULL )
1823  return NULL;
1824 
1825  // Ensure the flag BUSY of all tracks of the board is cleared
1826  // because we use it to mark segments of the track
1827  for( TRACK* track = m_Track; track; track = track->Next() )
1828  track->SetState( BUSY, false );
1829 
1830  // Set flags of the initial track segment
1831  aTrace->SetState( BUSY, true );
1832  LSET layer_set = aTrace->GetLayerSet();
1833 
1834  trackList.push_back( aTrace );
1835 
1836  /* Examine the initial track segment : if it is really a segment, this is
1837  * easy.
1838  * If it is a via, one must search for connected segments.
1839  * If <=2, this via connect 2 segments (or is connected to only one
1840  * segment) and this via and these 2 segments are a part of a track.
1841  * If > 2 only this via is flagged (the track has only this via)
1842  */
1843  if( aTrace->Type() == PCB_VIA_T )
1844  {
1845  TRACK* segm1 = ::GetTrack( m_Track, NULL, aTrace->GetStart(), layer_set );
1846  TRACK* segm2 = NULL;
1847  TRACK* segm3 = NULL;
1848 
1849  if( segm1 )
1850  {
1851  segm2 = ::GetTrack( segm1->Next(), NULL, aTrace->GetStart(), layer_set );
1852  }
1853 
1854  if( segm2 )
1855  {
1856  segm3 = ::GetTrack( segm2->Next(), NULL, aTrace->GetStart(), layer_set );
1857  }
1858 
1859  if( segm3 )
1860  {
1861  // More than 2 segments are connected to this via.
1862  // The "track" is only this via.
1863 
1864  if( aCount )
1865  *aCount = 1;
1866 
1867  return aTrace;
1868  }
1869 
1870  if( segm1 ) // search for other segments connected to the initial segment start point
1871  {
1872  layer_set = segm1->GetLayerSet();
1873  chainMarkedSegments( aTrace->GetStart(), layer_set, &trackList );
1874  }
1875 
1876  if( segm2 ) // search for other segments connected to the initial segment end point
1877  {
1878  layer_set = segm2->GetLayerSet();
1879  chainMarkedSegments( aTrace->GetStart(), layer_set, &trackList );
1880  }
1881  }
1882  else // mark the chain using both ends of the initial segment
1883  {
1884  TRACKS from_start;
1885  TRACKS from_end;
1886 
1887  chainMarkedSegments( aTrace->GetStart(), layer_set, &from_start );
1888  chainMarkedSegments( aTrace->GetEnd(), layer_set, &from_end );
1889 
1890  // combine into one trackList:
1891  trackList.insert( trackList.end(), from_start.begin(), from_start.end() );
1892  trackList.insert( trackList.end(), from_end.begin(), from_end.end() );
1893  }
1894 
1895  // Now examine selected vias and flag them if they are on the track
1896  // If a via is connected to only one or 2 segments, it is flagged (is on the track)
1897  // If a via is connected to more than 2 segments, it is a track end, and it
1898  // is removed from the list.
1899  // Go through the list backwards.
1900  for( int i = trackList.size() - 1; i>=0; --i )
1901  {
1902  ::VIA* via = dynamic_cast< ::VIA* >( trackList[i] );
1903 
1904  if( !via )
1905  continue;
1906 
1907  if( via == aTrace )
1908  continue;
1909 
1910  via->SetState( BUSY, true ); // Try to flag it. the flag will be cleared later if needed
1911 
1912  layer_set = via->GetLayerSet();
1913 
1914  TRACK* track = ::GetTrack( m_Track, NULL, via->GetStart(), layer_set );
1915 
1916  // GetTrace does not consider tracks flagged BUSY.
1917  // So if no connected track found, this via is on the current track
1918  // only: keep it
1919  if( track == NULL )
1920  continue;
1921 
1922  /* If a track is found, this via connects also other segments of
1923  * the other track. This case happens when a via ends the selected
1924  * track but must we consider this via is on the selected track, or
1925  * on a other track.
1926  * (this is important when selecting a track for deletion: must this
1927  * via be deleted or not?)
1928  * We consider this via to be on our track if other segments connected
1929  * to this via remain connected when removing this via.
1930  * We search for all other segments connected together:
1931  * if they are on the same layer, then the via is on the selected track;
1932  * if they are on different layers, the via is on a other track.
1933  */
1934  LAYER_NUM layer = track->GetLayer();
1935 
1936  while( ( track = ::GetTrack( track->Next(), NULL, via->GetStart(), layer_set ) ) != NULL )
1937  {
1938  if( layer != track->GetLayer() )
1939  {
1940  // The via connects segments of a other track: it is removed
1941  // from list because it is member of a other track
1942  via->SetState( BUSY, false );
1943  break;
1944  }
1945  }
1946  }
1947 
1948  /* Rearrange the track list in order to have flagged segments linked
1949  * from firstTrack so the NbSegmBusy segments are consecutive segments
1950  * in list, the first item in the full track list is firstTrack, and
1951  * the NbSegmBusy-1 next items (NbSegmBusy when including firstTrack)
1952  * are the flagged segments
1953  */
1954  int busy_count = 0;
1955  TRACK* firstTrack;
1956 
1957  for( firstTrack = m_Track; firstTrack; firstTrack = firstTrack->Next() )
1958  {
1959  // Search for the first flagged BUSY segments
1960  if( firstTrack->GetState( BUSY ) )
1961  {
1962  busy_count = 1;
1963  break;
1964  }
1965  }
1966 
1967  if( firstTrack == NULL )
1968  return NULL;
1969 
1970  // First step: calculate the track length and find the pads (when exist)
1971  // at each end of the trace.
1972  double full_len = 0;
1973  double lenPadToDie = 0;
1974  // Because we have a track (a set of track segments between 2 nodes),
1975  // only 2 pads (maximum) will be taken in account:
1976  // that are on each end of the track, if any.
1977  // keep trace of them, to know the die length and the track length ibside each pad.
1978  D_PAD* s_pad = NULL; // the pad on one end of the trace
1979  D_PAD* e_pad = NULL; // the pad on the other end of the trace
1980  int dist_fromstart = INT_MAX;
1981  int dist_fromend = INT_MAX;
1982 
1983  for( TRACK* track = firstTrack; track; track = track->Next() )
1984  {
1985  if( !track->GetState( BUSY ) )
1986  continue;
1987 
1988  layer_set = track->GetLayerSet();
1989  D_PAD * pad_on_start = GetPad( track->GetStart(), layer_set );
1990  D_PAD * pad_on_end = GetPad( track->GetEnd(), layer_set );
1991 
1992  // a segment fully inside a pad does not contribute to the track len
1993  // (another track end inside this pad will contribute to this lenght)
1994  if( pad_on_start && ( pad_on_start == pad_on_end ) )
1995  continue;
1996 
1997  full_len += track->GetLength();
1998 
1999  if( pad_on_start == NULL && pad_on_end == NULL )
2000  // This most of time the case
2001  continue;
2002 
2003  // At this point, we can have one track end on a pad, or the 2 track ends on
2004  // 2 different pads.
2005  // We don't know what pad (s_pad or e_pad) must be used to store the
2006  // start point and the end point of the track, so if a pad is already set,
2007  // use the other
2008  if( pad_on_start )
2009  {
2010  SEG segm( track->GetStart(), pad_on_start->GetPosition() );
2011  int dist = segm.Length();
2012 
2013  if( s_pad == NULL )
2014  {
2015  dist_fromstart = dist;
2016  s_pad = pad_on_start;
2017  }
2018  else if( e_pad == NULL )
2019  {
2020  dist_fromend = dist;
2021  e_pad = pad_on_start;
2022  }
2023  else // Should not occur, at least for basic pads
2024  {
2025  wxLogWarning( "Unexpected BOARD::MarkTrace: multiple pad_on_start" );
2026  }
2027  }
2028 
2029  if( pad_on_end )
2030  {
2031  SEG segm( track->GetEnd(), pad_on_end->GetPosition() );
2032  int dist = segm.Length();
2033 
2034  if( s_pad == NULL )
2035  {
2036  dist_fromstart = dist;
2037  s_pad = pad_on_end;
2038  }
2039  else if( e_pad == NULL )
2040  {
2041  dist_fromend = dist;
2042  e_pad = pad_on_end;
2043  }
2044  else // Should not occur, at least for basic pads
2045  {
2046  wxLogWarning( "Unexpected BOARD::MarkTrace: multiple pad_on_end" );
2047  }
2048  }
2049  }
2050 
2051  if( aReorder )
2052  {
2053  DLIST<TRACK>* list = (DLIST<TRACK>*)firstTrack->GetList();
2054  wxASSERT( list );
2055 
2056  /* Rearrange the chain starting at firstTrack
2057  * All other BUSY flagged items are moved from their position to the end
2058  * of the flagged list
2059  */
2060  TRACK* next;
2061 
2062  for( TRACK* track = firstTrack->Next(); track; track = next )
2063  {
2064  next = track->Next();
2065 
2066  if( track->GetState( BUSY ) ) // move it!
2067  {
2068  busy_count++;
2069  track->UnLink();
2070  list->Insert( track, firstTrack->Next() );
2071 
2072  }
2073  }
2074  }
2075  else if( aTraceLength )
2076  {
2077  busy_count = 0;
2078 
2079  for( TRACK* track = firstTrack; track; track = track->Next() )
2080  {
2081  if( track->GetState( BUSY ) )
2082  {
2083  busy_count++;
2084  track->SetState( BUSY, false );
2085  }
2086  }
2087  }
2088 
2089  if( s_pad )
2090  {
2091  full_len += dist_fromstart;
2092  lenPadToDie += (double) s_pad->GetPadToDieLength();
2093  }
2094 
2095  if( e_pad )
2096  {
2097  full_len += dist_fromend;
2098  lenPadToDie += (double) e_pad->GetPadToDieLength();
2099  }
2100 
2101  if( aTraceLength )
2102  *aTraceLength = full_len;
2103 
2104  if( aPadToDieLength )
2105  *aPadToDieLength = lenPadToDie;
2106 
2107  if( aCount )
2108  *aCount = busy_count;
2109 
2110  return firstTrack;
2111 }
2112 
2113 
2114 MODULE* BOARD::GetFootprint( const wxPoint& aPosition, PCB_LAYER_ID aActiveLayer,
2115  bool aVisibleOnly, bool aIgnoreLocked )
2116 {
2117  MODULE* pt_module;
2118  MODULE* module = NULL;
2119  MODULE* alt_module = NULL;
2120  int min_dim = 0x7FFFFFFF;
2121  int alt_min_dim = 0x7FFFFFFF;
2122  bool current_layer_back = IsBackLayer( aActiveLayer );
2123 
2124  for( pt_module = m_Modules; pt_module; pt_module = pt_module->Next() )
2125  {
2126  // is the ref point within the module's bounds?
2127  if( !pt_module->HitTest( aPosition ) )
2128  continue;
2129 
2130  // if caller wants to ignore locked modules, and this one is locked, skip it.
2131  if( aIgnoreLocked && pt_module->IsLocked() )
2132  continue;
2133 
2134  PCB_LAYER_ID layer = pt_module->GetLayer();
2135 
2136  // Filter non visible modules if requested
2137  if( !aVisibleOnly || IsModuleLayerVisible( layer ) )
2138  {
2139  EDA_RECT bb = pt_module->GetFootprintRect();
2140 
2141  int offx = bb.GetX() + bb.GetWidth() / 2;
2142  int offy = bb.GetY() + bb.GetHeight() / 2;
2143 
2144  // off x & offy point to the middle of the box.
2145  int dist = ( aPosition.x - offx ) * ( aPosition.x - offx ) +
2146  ( aPosition.y - offy ) * ( aPosition.y - offy );
2147 
2148  if( current_layer_back == IsBackLayer( layer ) )
2149  {
2150  if( dist <= min_dim )
2151  {
2152  // better footprint shown on the active side
2153  module = pt_module;
2154  min_dim = dist;
2155  }
2156  }
2157  else if( aVisibleOnly && IsModuleLayerVisible( layer ) )
2158  {
2159  if( dist <= alt_min_dim )
2160  {
2161  // better footprint shown on the other side
2162  alt_module = pt_module;
2163  alt_min_dim = dist;
2164  }
2165  }
2166  }
2167  }
2168 
2169  if( module )
2170  {
2171  return module;
2172  }
2173 
2174  if( alt_module)
2175  {
2176  return alt_module;
2177  }
2178 
2179  return NULL;
2180 }
2181 
2182 
2183 BOARD_CONNECTED_ITEM* BOARD::GetLockPoint( const wxPoint& aPosition, LSET aLayerSet )
2184 {
2185  for( MODULE* module = m_Modules; module; module = module->Next() )
2186  {
2187  D_PAD* pad = module->GetPad( aPosition, aLayerSet );
2188 
2189  if( pad )
2190  return pad;
2191  }
2192 
2193  // No pad has been located so check for a segment of the trace.
2194  TRACK* segment = ::GetTrack( m_Track, NULL, aPosition, aLayerSet );
2195 
2196  if( !segment )
2197  segment = GetVisibleTrack( m_Track, aPosition, aLayerSet );
2198 
2199  return segment;
2200 }
2201 
2202 
2204 {
2205  /* creates an intermediate point on aSegment and break it into two segments
2206  * at aPosition.
2207  * The new segment starts from aPosition and ends at the end point of
2208  * aSegment. The original segment now ends at aPosition.
2209  */
2210  if( aSegment->GetStart() == aPosition || aSegment->GetEnd() == aPosition )
2211  return NULL;
2212 
2213  // A via is a good lock point
2214  if( aSegment->Type() == PCB_VIA_T )
2215  {
2216  aPosition = aSegment->GetStart();
2217  return aSegment;
2218  }
2219 
2220  // Calculation coordinate of intermediate point relative to the start point of aSegment
2221  wxPoint delta = aSegment->GetEnd() - aSegment->GetStart();
2222 
2223  // calculate coordinates of aPosition relative to aSegment->GetStart()
2224  wxPoint lockPoint = aPosition - aSegment->GetStart();
2225 
2226  // lockPoint must be on aSegment:
2227  // Ensure lockPoint.y/lockPoint.y = delta.y/delta.x
2228  if( delta.x == 0 )
2229  lockPoint.x = 0; // horizontal segment
2230  else
2231  lockPoint.y = KiROUND( ( (double)lockPoint.x * delta.y ) / delta.x );
2232 
2233  /* Create the intermediate point (that is to say creation of a new
2234  * segment, beginning at the intermediate point.
2235  */
2236  lockPoint += aSegment->GetStart();
2237 
2238  TRACK* newTrack = (TRACK*)aSegment->Clone();
2239  // The new segment begins at the new point,
2240  newTrack->SetStart(lockPoint);
2241  newTrack->start = aSegment;
2242  newTrack->SetState( BEGIN_ONPAD, false );
2243 
2244  DLIST<TRACK>* list = (DLIST<TRACK>*)aSegment->GetList();
2245  wxASSERT( list );
2246  list->Insert( newTrack, aSegment->Next() );
2247 
2248  if( aList )
2249  {
2250  // Prepare the undo command for the now track segment
2251  ITEM_PICKER picker( newTrack, UR_NEW );
2252  aList->PushItem( picker );
2253  // Prepare the undo command for the old track segment
2254  // before modifications
2255  picker.SetItem( aSegment );
2256  picker.SetStatus( UR_CHANGED );
2257  picker.SetLink( aSegment->Clone() );
2258  aList->PushItem( picker );
2259  }
2260 
2261  // Old track segment now ends at new point.
2262  aSegment->SetEnd(lockPoint);
2263  aSegment->end = newTrack;
2264  aSegment->SetState( END_ONPAD, false );
2265 
2266  D_PAD * pad = GetPad( newTrack, ENDPOINT_START );
2267 
2268  if( pad )
2269  {
2270  newTrack->start = pad;
2271  newTrack->SetState( BEGIN_ONPAD, true );
2272  aSegment->end = pad;
2273  aSegment->SetState( END_ONPAD, true );
2274  }
2275 
2276  aPosition = lockPoint;
2277  return newTrack;
2278 }
2279 
2280 
2281 ZONE_CONTAINER* BOARD::AddArea( PICKED_ITEMS_LIST* aNewZonesList, int aNetcode,
2282  PCB_LAYER_ID aLayer, wxPoint aStartPointPosition, int aHatch )
2283 {
2284  ZONE_CONTAINER* new_area = InsertArea( aNetcode,
2285  m_ZoneDescriptorList.size( ) - 1,
2286  aLayer, aStartPointPosition.x,
2287  aStartPointPosition.y, aHatch );
2288 
2289  if( aNewZonesList )
2290  {
2291  ITEM_PICKER picker( new_area, UR_NEW );
2292  aNewZonesList->PushItem( picker );
2293  }
2294 
2295  return new_area;
2296 }
2297 
2298 
2299 void BOARD::RemoveArea( PICKED_ITEMS_LIST* aDeletedList, ZONE_CONTAINER* area_to_remove )
2300 {
2301  if( area_to_remove == NULL )
2302  return;
2303 
2304  if( aDeletedList )
2305  {
2306  ITEM_PICKER picker( area_to_remove, UR_DELETED );
2307  aDeletedList->PushItem( picker );
2308  Remove( area_to_remove ); // remove from zone list, but does not delete it
2309  }
2310  else
2311  {
2312  Delete( area_to_remove );
2313  }
2314 }
2315 
2316 
2317 ZONE_CONTAINER* BOARD::InsertArea( int aNetcode, int aAreaIdx, PCB_LAYER_ID aLayer,
2318  int aCornerX, int aCornerY, int aHatch )
2319 {
2320  ZONE_CONTAINER* new_area = new ZONE_CONTAINER( this );
2321 
2322  new_area->SetNetCode( aNetcode );
2323  new_area->SetLayer( aLayer );
2324  new_area->SetTimeStamp( GetNewTimeStamp() );
2325 
2326  if( aAreaIdx < (int) ( m_ZoneDescriptorList.size() - 1 ) )
2327  m_ZoneDescriptorList.insert( m_ZoneDescriptorList.begin() + aAreaIdx + 1, new_area );
2328  else
2329  m_ZoneDescriptorList.push_back( new_area );
2330 
2331  new_area->SetHatchStyle( (ZONE_CONTAINER::HATCH_STYLE) aHatch );
2332 
2333  // Add the first corner to the new zone
2334  new_area->AppendCorner( wxPoint( aCornerX, aCornerY ), -1 );
2335 
2336  return new_area;
2337 }
2338 
2339 
2341 {
2342  // mark all areas as unmodified except this one, if modified
2343  for( unsigned ia = 0; ia < m_ZoneDescriptorList.size(); ia++ )
2344  m_ZoneDescriptorList[ia]->SetLocalFlags( 0 );
2345 
2346  aCurrArea->SetLocalFlags( 1 );
2347 
2348  if( aCurrArea->Outline()->IsSelfIntersecting() )
2349  {
2350  aCurrArea->UnHatch();
2351 
2352  // Normalize copied area and store resulting number of polygons
2353  int n_poly = aCurrArea->Outline()->NormalizeAreaOutlines();
2354 
2355  // If clipping has created some polygons, we must add these new copper areas.
2356  if( n_poly > 1 )
2357  {
2358  ZONE_CONTAINER* NewArea;
2359 
2360  // Move the newly created polygons to new areas, removing them from the current area
2361  for( int ip = 1; ip < n_poly; ip++ )
2362  {
2363  // Create new copper area and copy poly into it
2364  SHAPE_POLY_SET* new_p = new SHAPE_POLY_SET( aCurrArea->Outline()->UnitSet( ip ) );
2365  NewArea = AddArea( aNewZonesList, aCurrArea->GetNetCode(), aCurrArea->GetLayer(),
2366  wxPoint(0, 0), aCurrArea->GetHatchStyle() );
2367 
2368  // remove the poly that was automatically created for the new area
2369  // and replace it with a poly from NormalizeAreaOutlines
2370  delete NewArea->Outline();
2371  NewArea->SetOutline( new_p );
2372  NewArea->Hatch();
2373  NewArea->SetLocalFlags( 1 );
2374  }
2375 
2376  SHAPE_POLY_SET* new_p = new SHAPE_POLY_SET( aCurrArea->Outline()->UnitSet( 0 ) );
2377  delete aCurrArea->Outline();
2378  aCurrArea->SetOutline( new_p );
2379  }
2380  }
2381 
2382  aCurrArea->Hatch();
2383 
2384  return true;
2385 }
2386 
2387 
2388 void BOARD::ReplaceNetlist( NETLIST& aNetlist, bool aDeleteSinglePadNets,
2389  std::vector<MODULE*>* aNewFootprints, REPORTER* aReporter )
2390 {
2391  unsigned i;
2392  wxPoint bestPosition;
2393  wxString msg;
2394  std::vector<MODULE*> newFootprints;
2395 
2396  if( !IsEmpty() )
2397  {
2398  // Position new components below any existing board features.
2400 
2401  if( bbbox.GetWidth() || bbbox.GetHeight() )
2402  {
2403  bestPosition.x = bbbox.Centre().x;
2404  bestPosition.y = bbbox.GetBottom() + Millimeter2iu( 10 );
2405  }
2406  }
2407  else
2408  {
2409  // Position new components in the center of the page when the board is empty.
2410  wxSize pageSize = m_paper.GetSizeIU();
2411 
2412  bestPosition.x = pageSize.GetWidth() / 2;
2413  bestPosition.y = pageSize.GetHeight() / 2;
2414  }
2415 
2416  m_Status_Pcb = 0;
2417 
2418  for( i = 0; i < aNetlist.GetCount(); i++ )
2419  {
2420  COMPONENT* component = aNetlist.GetComponent( i );
2421  MODULE* footprint;
2422 
2423  if( aReporter )
2424  {
2425 
2426  msg.Printf( _( "Checking netlist symbol footprint \"%s:%s:%s\".\n" ),
2427  GetChars( component->GetReference() ),
2428  GetChars( component->GetTimeStamp() ),
2429  GetChars( component->GetFPID().Format() ) );
2430  aReporter->Report( msg, REPORTER::RPT_INFO );
2431  }
2432 
2433  if( aNetlist.IsFindByTimeStamp() )
2434  footprint = FindModule( aNetlist.GetComponent( i )->GetTimeStamp(), true );
2435  else
2436  footprint = FindModule( aNetlist.GetComponent( i )->GetReference() );
2437 
2438  if( footprint == NULL ) // A new footprint.
2439  {
2440  if( aReporter )
2441  {
2442  if( component->GetModule() != NULL )
2443  {
2444  msg.Printf( _( "Adding new symbol \"%s:%s\" footprint \"%s\".\n" ),
2445  GetChars( component->GetReference() ),
2446  GetChars( component->GetTimeStamp() ),
2447  GetChars( component->GetFPID().Format() ) );
2448 
2449  aReporter->Report( msg, REPORTER::RPT_ACTION );
2450  }
2451  else
2452  {
2453  msg.Printf( _( "Cannot add new symbol \"%s:%s\" due to missing "
2454  "footprint \"%s\".\n" ),
2455  GetChars( component->GetReference() ),
2456  GetChars( component->GetTimeStamp() ),
2457  GetChars( component->GetFPID().Format() ) );
2458 
2459  aReporter->Report( msg, REPORTER::RPT_ERROR );
2460  }
2461  }
2462 
2463  if( !aNetlist.IsDryRun() && (component->GetModule() != NULL) )
2464  {
2465  // Owned by NETLIST, can only copy it.
2466  footprint = new MODULE( *component->GetModule() );
2467  footprint->SetParent( this );
2468  footprint->SetPosition( bestPosition );
2469  footprint->SetTimeStamp( GetNewTimeStamp() );
2470  newFootprints.push_back( footprint );
2471  Add( footprint, ADD_APPEND );
2472  m_connectivity->Add( footprint );
2473  }
2474  }
2475  else // An existing footprint.
2476  {
2477  // Test for footprint change.
2478  if( !component->GetFPID().empty() &&
2479  footprint->GetFPID() != component->GetFPID() )
2480  {
2481  if( aNetlist.GetReplaceFootprints() )
2482  {
2483  if( aReporter )
2484  {
2485  if( component->GetModule() != NULL )
2486  {
2487  msg.Printf( _( "Replacing symbol \"%s:%s\" footprint \"%s\" with "
2488  "\"%s\".\n" ),
2489  GetChars( footprint->GetReference() ),
2490  GetChars( footprint->GetPath() ),
2491  GetChars( footprint->GetFPID().Format() ),
2492  GetChars( component->GetFPID().Format() ) );
2493 
2494  aReporter->Report( msg, REPORTER::RPT_ACTION );
2495  }
2496  else
2497  {
2498  msg.Printf( _( "Cannot replace symbol \"%s:%s\" due to missing "
2499  "footprint \"%s\".\n" ),
2500  GetChars( footprint->GetReference() ),
2501  GetChars( footprint->GetPath() ),
2502  GetChars( component->GetFPID().Format() ) );
2503 
2504  aReporter->Report( msg, REPORTER::RPT_ERROR );
2505  }
2506  }
2507 
2508  if( !aNetlist.IsDryRun() && (component->GetModule() != NULL) )
2509  {
2510  wxASSERT( footprint != NULL );
2511  MODULE* newFootprint = new MODULE( *component->GetModule() );
2512 
2513  if( aNetlist.IsFindByTimeStamp() )
2514  newFootprint->SetReference( footprint->GetReference() );
2515  else
2516  newFootprint->SetPath( footprint->GetPath() );
2517 
2518  // Copy placement and pad net names.
2519  // optionally, copy or not local settings (like local clearances)
2520  // if the second parameter is "true", previous values will be used.
2521  // if "false", the default library values of the new footprint
2522  // will be used
2523  footprint->CopyNetlistSettings( newFootprint, false );
2524 
2525  // Compare the footprint name only, in case the nickname is empty or in case
2526  // user moved the footprint to a new library. Chances are if footprint name is
2527  // same then the footprint is very nearly the same and the two texts should
2528  // be kept at same size, position, and rotation.
2529  if( newFootprint->GetFPID().GetLibItemName() == footprint->GetFPID().GetLibItemName() )
2530  {
2531  newFootprint->Reference().SetEffects( footprint->Reference() );
2532  newFootprint->Value().SetEffects( footprint->Value() );
2533  }
2534 
2535  m_connectivity->Remove( footprint );
2536  Remove( footprint );
2537 
2538  Add( newFootprint, ADD_APPEND );
2539  m_connectivity->Add( footprint );
2540 
2541  footprint = newFootprint;
2542  }
2543  }
2544  }
2545 
2546  // Test for reference designator field change.
2547  if( footprint->GetReference() != component->GetReference() )
2548  {
2549  if( aReporter )
2550  {
2551  msg.Printf( _( "Changing footprint \"%s:%s\" reference to \"%s\".\n" ),
2552  GetChars( footprint->GetReference() ),
2553  GetChars( footprint->GetPath() ),
2554  GetChars( component->GetReference() ) );
2555  aReporter->Report( msg, REPORTER::RPT_ACTION );
2556  }
2557 
2558  if( !aNetlist.IsDryRun() )
2559  footprint->SetReference( component->GetReference() );
2560  }
2561 
2562  // Test for value field change.
2563  if( footprint->GetValue() != component->GetValue() )
2564  {
2565  if( aReporter )
2566  {
2567  msg.Printf( _( "Changing footprint \"%s:%s\" value from \"%s\" to \"%s\".\n" ),
2568  GetChars( footprint->GetReference() ),
2569  GetChars( footprint->GetPath() ),
2570  GetChars( footprint->GetValue() ),
2571  GetChars( component->GetValue() ) );
2572  aReporter->Report( msg, REPORTER::RPT_ACTION );
2573  }
2574 
2575  if( !aNetlist.IsDryRun() )
2576  footprint->SetValue( component->GetValue() );
2577  }
2578 
2579  // Test for time stamp change.
2580  if( footprint->GetPath() != component->GetTimeStamp() )
2581  {
2582  if( aReporter )
2583  {
2584  msg.Printf( _( "Changing component path \"%s:%s\" to \"%s\".\n" ),
2585  GetChars( footprint->GetReference() ),
2586  GetChars( footprint->GetPath() ),
2587  GetChars( component->GetTimeStamp() ) );
2588  aReporter->Report( msg, REPORTER::RPT_INFO );
2589  }
2590 
2591  if( !aNetlist.IsDryRun() )
2592  footprint->SetPath( component->GetTimeStamp() );
2593  }
2594  }
2595 
2596  if( footprint == NULL )
2597  continue;
2598 
2599  // At this point, the component footprint is updated. Now update the nets.
2600  for( auto pad : footprint->Pads() )
2601  {
2602  COMPONENT_NET net = component->GetNet( pad->GetName() );
2603 
2604  if( !net.IsValid() ) // Footprint pad had no net.
2605  {
2606  if( aReporter && !pad->GetNetname().IsEmpty() )
2607  {
2608  msg.Printf( _( "Clearing component \"%s:%s\" pin \"%s\" net name.\n" ),
2609  GetChars( footprint->GetReference() ),
2610  GetChars( footprint->GetPath() ),
2611  GetChars( pad->GetName() ) );
2612  aReporter->Report( msg, REPORTER::RPT_ACTION );
2613  }
2614 
2615  if( !aNetlist.IsDryRun() )
2616  {
2617  m_connectivity->Remove( pad );
2618  pad->SetNetCode( NETINFO_LIST::UNCONNECTED );
2619  }
2620  }
2621  else // Footprint pad has a net.
2622  {
2623  if( net.GetNetName() != pad->GetNetname() )
2624  {
2625  if( aReporter )
2626  {
2627  msg.Printf( _( "Changing footprint \"%s:%s\" pad \"%s\" net name from "
2628  "\"%s\" to \"%s\".\n" ),
2629  GetChars( footprint->GetReference() ),
2630  GetChars( footprint->GetPath() ),
2631  GetChars( pad->GetName() ),
2632  GetChars( pad->GetNetname() ),
2633  GetChars( net.GetNetName() ) );
2634  aReporter->Report( msg, REPORTER::RPT_ACTION );
2635  }
2636 
2637  if( !aNetlist.IsDryRun() )
2638  {
2639  NETINFO_ITEM* netinfo = FindNet( net.GetNetName() );
2640 
2641  if( netinfo == NULL )
2642  {
2643  // It is a new net, we have to add it
2644  netinfo = new NETINFO_ITEM( this, net.GetNetName() );
2645  Add( netinfo );
2646  }
2647 
2648  m_connectivity->Remove( pad );
2649  pad->SetNetCode( netinfo->GetNet() );
2650  m_connectivity->Add( pad );
2651  }
2652  }
2653  }
2654  }
2655  }
2656 
2657  // Remove all components not in the netlist.
2658  if( aNetlist.GetDeleteExtraFootprints() )
2659  {
2660  MODULE* nextModule;
2661  const COMPONENT* component;
2662 
2663  for( MODULE* module = m_Modules; module != NULL; module = nextModule )
2664  {
2665  nextModule = module->Next();
2666 
2667  if( module->IsLocked() )
2668  continue;
2669 
2670  if( aNetlist.IsFindByTimeStamp() )
2671  component = aNetlist.GetComponentByTimeStamp( module->GetPath() );
2672  else
2673  component = aNetlist.GetComponentByReference( module->GetReference() );
2674 
2675  if( component == NULL )
2676  {
2677  if( aReporter )
2678  {
2679  msg.Printf( _( "Removing unused footprint \"%s:%s\".\n" ),
2680  GetChars( module->GetReference() ),
2681  GetChars( module->GetPath() ) );
2682  aReporter->Report( msg, REPORTER::RPT_ACTION );
2683  }
2684 
2685  if( !aNetlist.IsDryRun() )
2686  {
2687  m_connectivity->Remove( module );
2688  module->DeleteStructure();
2689  }
2690  }
2691  }
2692  }
2693 
2694  BuildListOfNets();
2695  std::vector<D_PAD*> padlist = GetPads();
2696  auto connAlgo = m_connectivity->GetConnectivityAlgo();
2697 
2698  // If needed, remove the single pad nets:
2699  if( aDeleteSinglePadNets && !aNetlist.IsDryRun() )
2700  {
2701  std::vector<unsigned int> padCount( connAlgo->NetCount() );
2702 
2703  for( const auto cnItem : connAlgo->PadList() )
2704  {
2705  if( !cnItem->Valid() )
2706  continue;
2707 
2708  int net = cnItem->Parent()->GetNetCode();
2709 
2710  if( net > 0 )
2711  ++padCount[net];
2712  }
2713 
2714  for( i = 0; i < (unsigned)connAlgo->NetCount(); ++i )
2715  {
2716  // First condition: only one pad in the net
2717  if( padCount[i] == 1 )
2718  {
2719  // Second condition, no zones attached to the pad
2720  D_PAD* pad = nullptr;
2721  int zoneCount = 0;
2722  const KICAD_T types[] = { PCB_PAD_T, PCB_ZONE_AREA_T, EOT };
2723  auto netItems = m_connectivity->GetNetItems( i, types );
2724 
2725  for( const auto item : netItems )
2726  {
2727  if( item->Type() == PCB_ZONE_AREA_T )
2728  {
2729  wxASSERT( !pad || pad->GetNet() == item->GetNet() );
2730  ++zoneCount;
2731  }
2732  else if( item->Type() == PCB_PAD_T )
2733  {
2734  wxASSERT( !pad );
2735  pad = static_cast<D_PAD*>( item );
2736  }
2737  }
2738 
2739  wxASSERT( pad ); // pad = 0 means the pad list is not up to date
2740 
2741  if( pad && zoneCount == 0 )
2742  {
2743  if( aReporter )
2744  {
2745  msg.Printf( _( "Remove single pad net \"%s\" on \"%s\" pad \"%s\"\n" ),
2746  GetChars( pad->GetNetname() ),
2747  GetChars( pad->GetParent()->GetReference() ),
2748  GetChars( pad->GetName() ) );
2749  aReporter->Report( msg, REPORTER::RPT_ACTION );
2750  }
2751 
2752  m_connectivity->Remove( pad );
2754  }
2755  }
2756  }
2757  }
2758 
2759  // Last step: Some tests:
2760  // verify all pads found in netlist:
2761  // They should exist in footprints, otherwise the footprint is wrong
2762  // note also references or time stamps are updated, so we use only
2763  // the reference to find a footprint
2764  //
2765  // Also verify if zones have acceptable nets, i.e. nets with pads.
2766  // Zone with no pad belongs to a "dead" net which happens after changes in schematic
2767  // when no more pad use this net name.
2768  if( aReporter )
2769  {
2770  wxString padname;
2771  for( i = 0; i < aNetlist.GetCount(); i++ )
2772  {
2773  const COMPONENT* component = aNetlist.GetComponent( i );
2774  MODULE* footprint = FindModuleByReference( component->GetReference() );
2775 
2776  if( footprint == NULL ) // It can be missing in partial designs
2777  continue;
2778 
2779  // Explore all pins/pads in component
2780  for( unsigned jj = 0; jj < component->GetNetCount(); jj++ )
2781  {
2782  const COMPONENT_NET& net = component->GetNet( jj );
2783  padname = net.GetPinName();
2784 
2785  if( footprint->FindPadByName( padname ) )
2786  continue; // OK, pad found
2787 
2788  // not found: bad footprint, report error
2789  msg.Printf( _( "Component \"%s\" pad \"%s\" not found in footprint \"%s\"\n" ),
2790  GetChars( component->GetReference() ),
2791  GetChars( padname ),
2792  GetChars( footprint->GetFPID().Format() ) );
2793  aReporter->Report( msg, REPORTER::RPT_ERROR );
2794  }
2795  }
2796 
2797  // Test copper zones to detect "dead" nets (nets without any pad):
2798  for( int ii = 0; ii < GetAreaCount(); ii++ )
2799  {
2800  ZONE_CONTAINER* zone = GetArea( ii );
2801 
2802  if( !zone->IsOnCopperLayer() || zone->GetIsKeepout() )
2803  continue;
2804 
2805  if( m_connectivity->GetPadCount( zone->GetNetCode() ) == 0 )
2806  {
2807  msg.Printf( _( "Copper zone (net name \"%s\"): net has no pads connected." ),
2808  GetChars( zone->GetNet()->GetNetname() ) );
2809  aReporter->Report( msg, REPORTER::RPT_WARNING );
2810  }
2811  }
2812  }
2813 
2814  m_connectivity->RecalculateRatsnest();
2815 
2816  std::swap( newFootprints, *aNewFootprints );
2817 }
2818 
2819 
2821  bool aAddToBoard )
2822 {
2823  BOARD_ITEM* new_item = NULL;
2824 
2825  switch( aItem->Type() )
2826  {
2827  case PCB_MODULE_T:
2828  case PCB_TEXT_T:
2829  case PCB_LINE_T:
2830  case PCB_TRACE_T:
2831  case PCB_VIA_T:
2832  case PCB_ZONE_AREA_T:
2833  case PCB_TARGET_T:
2834  case PCB_DIMENSION_T:
2835  new_item = static_cast<BOARD_ITEM*>( aItem->Clone() );
2836  break;
2837 
2838  default:
2839  // Un-handled item for duplication
2840  new_item = NULL;
2841  break;
2842  }
2843 
2844  if( new_item && aAddToBoard )
2845  Add( new_item );
2846 
2847  return new_item;
2848 }
2849 
2850 
2851 /* Extracts the board outlines and build a closed polygon
2852  * from lines, arcs and circle items on edge cut layer
2853  * Any closed outline inside the main outline is a hole
2854  * All contours should be closed, i.e. are valid vertices for a closed polygon
2855  * return true if success, false if a contour is not valid
2856  */
2857 extern bool BuildBoardPolygonOutlines( BOARD* aBoard,
2858  SHAPE_POLY_SET& aOutlines,
2859  wxString* aErrorText );
2860 
2861 
2863  wxString* aErrorText )
2864 {
2865  bool success = BuildBoardPolygonOutlines( this, aOutlines, aErrorText );
2866 
2867  // Make polygon strictly simple to avoid issues (especially in 3D viewer)
2869 
2870  return success;
2871 
2872 }
2873 
2874 
2875 const std::vector<D_PAD*> BOARD::GetPads()
2876 {
2877  std::vector<D_PAD*> rv;
2878  for ( auto mod: Modules() )
2879  {
2880  for ( auto pad: mod->Pads() )
2881  rv.push_back ( pad );
2882 
2883  }
2884 
2885  return rv;
2886 }
2887 
2888 
2889 unsigned BOARD::GetPadCount() const
2890 {
2891  return m_connectivity->GetPadCount();
2892 }
2893 
2894 
2899 D_PAD* BOARD::GetPad( unsigned aIndex ) const
2900 {
2901  unsigned count = 0;
2902 
2903  for( MODULE* mod = m_Modules; mod ; mod = mod->Next() ) // FIXME: const DLIST_ITERATOR
2904  {
2905  for( D_PAD* pad = mod->PadsList(); pad; pad = pad->Next() )
2906  {
2907  if( count == aIndex )
2908  return pad;
2909 
2910  count++;
2911  }
2912  }
2913 
2914  return nullptr;
2915 }
2916 
2918 {
2919  for ( auto zone : Zones() )
2920  zone->SetNetCode( 0 );
2921 
2922  for ( auto mod : Modules() )
2923  for ( auto pad : mod->Pads() )
2924  pad->SetNetCode( 0 );
2925 
2926  for ( auto track : Tracks() )
2927  track->SetNetCode( 0 );
2928 
2929 }
Definition: colors.h:57
DHEAD * GetList() const
Definition: base_struct.h:220
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:673
CITER next(CITER it)
Definition: ptree.cpp:130
KICAD_T Type() const
Function Type()
Definition: base_struct.h:209
#define DIM(x)
of elements in an array
Definition: macros.h:98
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString, NETINFO_ITEM*>
Definition: netinfo.h:478
const wxString & GetPinName() const
Definition: pcb_netlist.h:61
void SetCopperLayerCount(int aNewLayerCount)
Function SetCopperLayerCount do what its name says...
void BuildListOfNets()
Definition: class_board.h:722
void Draw(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset) override
Function Draw Draws the zone outline.
Definition: class_zone.cpp:276
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
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...
TRACK * CreateLockPoint(wxPoint &aPosition, TRACK *aSegment, PICKED_ITEMS_LIST *aList)
Function CreateLockPoint creates an intermediate point on aSegment and break it into two segments at ...
TRACK * GetTrack(TRACK *aStartTrace, const TRACK *aEndTrace, const wxPoint &aPosition, LSET aLayerMask)
Function GetTrack is a helper function to locate a trace segment having an end point at aPosition on ...
Definition: class_track.cpp:68
TEXTE_MODULE & Reference()
Definition: class_module.h:502
bool empty() const
Definition: lib_id.h:173
Class that draws missing connections on a PCB.
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
void DeleteZONEOutlines()
Function DeleteZONEOutlines deletes ALL zone outlines from the board.
int GetVisibleElements() const
Function GetVisibleElements returns a bit-mask of all the element categories that are visible...
Definition: typeinfo.h:85
const LIB_ID & GetFPID() const
Definition: pcb_netlist.h:166
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:75
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Function GetLineLength returns the length of a line segment defined by aPointA and aPointB...
Definition: trigo.h:191
NETCLASSPTR GetDefault() const
Function GetDefault.
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.
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
TEXTE_PCB class definition.
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:305
#define END_ONPAD
Pcbnew: flag set for track segment ending on a pad.
Definition: base_struct.h:129
unsigned GetUnconnectedNetCount() const
Function GetUnconnectedNetCount.
virtual LSET GetLayerSet() const override
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
wxString m_name
The name of the layer, there should be no spaces in this name.
Definition: class_board.h:111
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 PushFront(T *aNewElement)
Function PushFront puts aNewElement at front of list sequence.
Definition: dlist.h:240
void SetVisibleElements(int aMask)
Function SetVisibleElements is a proxy function that calls the correspondent function in m_BoardSetti...
virtual const wxPoint GetPosition() const override
Implementation of conversion functions that require both schematic and board internal units...
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
static void removeTrack(TRACKS *aList, TRACK *aOneToRemove)
Function removeTrack removes aOneToRemove from aList, which is a non-owning std::vector.
void SetEnd(const wxPoint &aEnd)
Definition: class_track.h:118
bool GetBoardPolygonOutlines(SHAPE_POLY_SET &aOutlines, wxString *aErrorText=NULL)
Function GetBoardPolygonOutlines Extracts the board outlines and build a closed polygon from lines...
const EDA_RECT GetBoundingBox() const override
Function GetBoundingBox (virtual)
Definition: class_zone.cpp:518
D_PAD * GetPadFast(const wxPoint &aPosition, LSET aLayerMask)
Function GetPadFast return pad found at aPosition on aLayerMask using the fast search method...
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
static void otherEnd(const TRACK &aTrack, const wxPoint &aNotThisEnd, wxPoint *aOtherEnd)
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
PAGE_INFO m_paper
Definition: class_board.h:196
void SetStatus(UNDO_REDO_T aStatus)
EDA_RECT ComputeBoundingBox(bool aBoardEdgesOnly=false) const
Function ComputeBoundingBox calculates the bounding box containing all board items (or board edge seg...
TRACKS TracksInNetBetweenPoints(const wxPoint &aStartPos, const wxPoint &aGoalPos, int aNetCode)
Function TrackInNetBetweenPoints collects all the TRACKs and VIAs that are members of a net given by ...
MODULE * GetModule(bool aRelease=false)
Definition: pcb_netlist.h:186
bool IsBackLayer(PCB_LAYER_ID aLayerId)
Layer classification: check if it&#39;s a back layer.
void SetCustomViaDrill(int aDrill)
Function SetCustomViaDrill Sets custom size for via drill (i.e.
int GetPadToDieLength() const
Definition: class_pad.h:408
Class BOARD to handle a board.
void DrawFilledArea(EDA_DRAW_PANEL *panel, wxDC *DC, GR_DRAWMODE aDrawMode, const wxPoint &offset=ZeroOffset)
Function DrawDrawFilledArea Draws the filled area for this zone (polygon list .m_FilledPolysList) ...
Definition: class_zone.cpp:406
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:439
Class that computes missing connections on a PCB.
LAYER_T m_type
The type of the layer.
Definition: class_board.h:113
D_PAD * FindPadByName(const wxString &aPadName) const
Function FindPadByName returns a D_PAD* with a matching name.
MODULE * Next() const
Definition: class_module.h:121
void GetSortedPadListByXthenYCoord(std::vector< D_PAD * > &aVector, int aNetCode=-1)
Function GetSortedPadListByXthenYCoord first empties then fills the vector with all pads and sorts th...
NETINFO_ITEM * GetNetItem(int aNetCode) const
Function GetItem.
MODULE * GetParent() const
Definition: class_pad.h:162
COLORS_DESIGN_SETTINGS * m_colorsSettings
Definition: class_board.h:195
int NormalizeAreaOutlines()
Function NormalizeAreaOutlines Convert a self-intersecting polygon to one (or more) non self-intersec...
int GetCopperLayerCount() const
Function GetCopperLayerCount.
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
std::list< TRACK * > GetTracksByPosition(const wxPoint &aPosition, PCB_LAYER_ID aLayer=PCB_LAYER_ID(-1)) const
Function GetTracksByPosition finds the list of tracks that starts or ends at aPosition on aLayer...
static const int dist[10][10]
Definition: dist.cpp:57
ZONE_CONTAINER * m_CurrentZoneContour
zone contour currently in progress
Definition: class_board.h:259
show modules on back
DLIST_ITERATOR_WRAPPER< D_PAD > Pads()
Definition: class_module.h:167
unsigned GetNetCount() const
Function GetNetCount.
Definition: netinfo.h:434
int GetHeight() const
Definition: eda_rect.h:118
SHAPE_POLY_SET * Outline()
Definition: class_zone.h:236
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)
virtual EDA_ITEM * Clone() const override
Function Clone creates a duplicate of this item with linked list members set to NULL.
class TEXTE_PCB, text on a layer
Definition: typeinfo.h:92
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) ...
MODULE * FindModuleByReference(const wxString &aReference) const
Function FindModuleByReference searches for a MODULE within this board with the given reference desig...
Classes to handle copper zones.
const wxString & GetValue() const
Function GetValue.
Definition: class_module.h:486
DLIST< SEGZONE > m_Zone
Definition: class_board.h:247
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
D_PAD * GetPad(unsigned aIndex) const
Function GetPad.
#define BUSY
Pcbnew: flag indicating that the structure has.
Definition: base_struct.h:130
virtual void SetPosition(const wxPoint &aPos) override
bool IsValid() const
Definition: pcb_netlist.h:65
This is the end of the layers used for visibility bitmasks in Pcbnew There can be at most 32 layers a...
MODULE * FindModule(const wxString &aRefOrTimeStamp, bool aSearchByTimeStamp=false) const
Function FindModule searches for a module matching aRefOrTimeStamp depending on the state of aSearchB...
bool SetLayerType(PCB_LAYER_ID aLayer, LAYER_T aLayerType)
Function SetLayerType changes the type of the layer given by aLayer.
HIGH_LIGHT_INFO m_highLight
Definition: class_board.h:186
NETINFO_LIST m_NetInfo
net info list (name, design constraints ..
Definition: class_board.h:199
bool IsLayerVisible(PCB_LAYER_ID aLayerId) const
Function IsLayerVisible tests whether a given layer is visible.
Class REPORTER is a pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:61
HIGH_LIGHT_INFO m_highLightPrevious
Definition: class_board.h:187
int GetVisibleElements() const
Function GetVisibleElements is a proxy function that calls the correspondent function in m_BoardSetti...
virtual void UnLink()
Function UnLink detaches this object from its owner.
int GetState(int type) const
Definition: base_struct.h:248
#define cu(a)
Definition: auxiliary.h:88
#define BEGIN_ONPAD
Pcbnew: flag set for track segment starting on a pad.
Definition: base_struct.h:128
int GetCurrentViaSize() const
Function GetCurrentViaSize.
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
LSET GetEnabledLayers() const
Function GetEnabledLayers is a proxy function that calls the corresponding function in m_BoardSetting...
void SetLink(EDA_ITEM *aItem)
wxString GetLayerName() const
Function GetLayerName returns the name of the PCB layer on which the item resides.
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
static COLORS_DESIGN_SETTINGS dummyColorsSettings(FRAME_PCB)
void SetOutline(SHAPE_POLY_SET *aOutline)
Definition: class_zone.h:239
BOARD_CONNECTED_ITEM * GetLockPoint(const wxPoint &aPosition, LSET aLayerMask)
Function GetLockPoint returns the item at the "attachment" point at the end of a trace at aPosition o...
static const int delta[8][2]
Definition: solve.cpp:112
const wxPoint & GetEnd() const
Definition: class_track.h:119
void SetCustomViaSize(int aSize)
Function SetCustomViaSize Sets custom size for via diameter (i.e.
static int find_vias_and_tracks_at(TRACKS &at_next, TRACKS &in_net, LSET &lset, const wxPoint &next)
Function find_vias_and_tracks_at collects TRACKs and VIAs at aPos and returns the track_count which 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.
static std::string FormatInternalUnits(int aValue)
Function FormatInternalUnits converts aValue from board internal units to a string appropriate for wr...
Functions relatives to tracks, vias and segments used to fill zones.
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
ENDPOINT_T
Flag used in locate routines (from which endpoint work)
Definition: pcbnew.h:58
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.
void PushBack(T *aNewElement)
Function PushBack puts aNewElement at the end of the list sequence.
Definition: dlist.h:250
SEGZONE * Next() const
Definition: class_track.h:361
Classes used in Pcbnew, CvPcb and GerbView.
const EDA_RECT GetBoardEdgesBoundingBox() const
Function GetBoardEdgesBoundingBox Returns the board bounding box calculated using exclusively the boa...
Definition: class_board.h:797
void AppendNet(NETINFO_ITEM *aNewElement)
Function AppendNet adds aNewElement to the end of the net list.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:602
show modules on front
int StrPrintf(std::string *result, const char *format,...)
Function StrPrintf is like sprintf() but the output is appended to a std::string instead of to a char...
Definition: richio.cpp:74
const wxString & GetReference() const
Definition: pcb_netlist.h:151
virtual const wxPoint GetCenter() const
Function GetCenter()
BOARD_ITEM * Next() const
Class that handles properties and drawing of worksheet layout.
Class COMPONENT_NET is used to store the component pin name to net name associations stored in a netl...
Definition: pcb_netlist.h:48
const INSPECTOR_FUNC & INSPECTOR
Definition: base_struct.h:100
const LIB_ID & GetFPID() const
Definition: class_module.h:191
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...
const wxString & GetValue() const
Definition: pcb_netlist.h:153
DIMENSION class definition.
VIA * GetVia(const wxPoint &aPosition, PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Function GetVia finds the first VIA object at aPosition on aLayer starting at the trace...
class MODULE, a footprint
Definition: typeinfo.h:89
timestamp_t GetNewTimeStamp()
Definition: common.cpp:167
Markers used to show a drc problem on boards.
PCB_LAYER_ID
A quick note on layer IDs:
bool GetDeleteExtraFootprints() const
Definition: pcb_netlist.h:305
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.
Class LSET is a set of PCB_LAYER_IDs.
void PopHighLight()
Function PopHighLight retrieve a previously saved high light info.
int GetCopperLayerCount() const
Function GetCopperLayerCount.
void ReplaceNetlist(NETLIST &aNetlist, bool aDeleteSinglePadNets, std::vector< MODULE * > *aNewFootprints, REPORTER *aReporter=NULL)
Function ReplaceNetlist updates the BOARD according to aNetlist.
bool GetReplaceFootprints() const
Definition: pcb_netlist.h:320
Class NETLIST stores all of information read from a netlist along with the flags used to update the N...
Definition: pcb_netlist.h:214
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:250
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:49
bool NormalizeAreaPolygon(PICKED_ITEMS_LIST *aNewZonesList, ZONE_CONTAINER *aCurrArea)
Function NormalizeAreaPolygon Process an area that has been modified, by normalizing its polygon agai...
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:224
#define GAL_LAYER_INDEX(x)
Use this macro to convert a GAL layer to a 0-indexed offset from LAYER_VIAS.
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:37
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
Class SHAPE_POLY_SET.
TEXTE_MODULE & Value()
read/write accessors:
Definition: class_module.h:501
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
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text...
#define IS_DELETED
Definition: base_struct.h:112
const UTF8 & GetLibItemName() const
Definition: lib_id.h:118
Class PAGE_INFO describes the page size and margins of a paper page on which to eventually print or p...
Definition: page_info.h:49
bool IsEmpty() const
Definition: class_board.h:268
const wxPoint & GetStart() const
Definition: class_track.h:122
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:71
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:402
bool SetLayerName(PCB_LAYER_ID aLayer, const wxString &aLayerName)
Function SetLayerName changes the name of the layer given by aLayer.
const wxPoint & GetEndPoint(ENDPOINT_T aEndPoint) const
Return the selected endpoint (start or end)
Definition: class_track.h:126
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_INSERT) override
Adds an item to the container.
const wxString & GetNetName() const
Definition: pcb_netlist.h:63
bool SetLayerDescr(PCB_LAYER_ID aIndex, const LAYER &aLayer)
Function SetLayerDescr returns the type of the copper layer given by aLayer.
bool IsFindByTimeStamp() const
Definition: pcb_netlist.h:313
virtual LSET GetLayerSet() const
Function GetLayerSet returns a "layer mask", which is a bitmap of all layers on which the TRACK segme...
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:202
DLIST< BOARD_ITEM > m_Drawings
Definition: class_board.h:241
bool SetNetCode(int aNetCode, bool aNoAssert=false)
Function SetNetCode sets net using a net code.
const wxString & GetName() const
Definition: class_pad.h:190
Definition: colors.h:60
TRACK * GetVisibleTrack(TRACK *aStartingTrace, const wxPoint &aPosition, LSET aLayerSet) const
Function GetVisibleTrack finds the neighboring visible segment of aTrace at aPosition that is on a la...
void Simplify(POLYGON_MODE aFastMode)
Simplifies the polyset (merges overlapping polys, eliminates degeneracy/self-intersections) For aFast...
void SetReference(const wxString &aReference)
Function SetReference.
Definition: class_module.h:468
class SEGZONE, a segment used to fill a zone area (segment on a copper layer)
Definition: typeinfo.h:97
int SetAreasNetCodesFromNetNames(void)
Function SetAreasNetCodesFromNetNames Set the .m_NetCode member of all copper areas, according to the area Net Name The SetNetCodesFromNetNames is an equivalent to net name, for fast comparisons.
int GetAreaCount() const
Function GetAreaCount.
Definition: class_board.h:1011
void BuildConnectivity()
Builds or rebuilds the board connectivity database for the board, especially the list of connected it...
const wxString & GetTimeStamp() const
Definition: pcb_netlist.h:170
MARKERS m_markers
MARKER_PCBs for clearance problems, owned by pointer.
Definition: class_board.h:178
int GetBottom() const
Definition: eda_rect.h:122
HATCH_STYLE
Zone hatch styles.
Definition: class_zone.h:67
wxPoint Centre() const
Definition: eda_rect.h:60
TRACK * MarkTrace(TRACK *aTrace, int *aCount, double *aTraceLength, double *aInPackageLength, bool aReorder)
Function MarkTrace marks a chain of trace segments, connected to aTrace.
void SetPosition(const wxPoint &aPos) override
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
int GetNet() const
Function GetNet.
Definition: netinfo.h:227
static LAYER_T ParseType(const char *aType)
Function ParseType converts a string to a LAYER_T.
void SetItem(EDA_ITEM *aItem)
class DIMENSION, a dimension (graphic item)
Definition: typeinfo.h:100
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:263
unsigned GetPadCount() const
Function GetPadCount.
bool IsElementVisible(GAL_LAYER_ID aElementCategory) const
Function IsElementVisible tests whether a given element category is visible.
int GetNumSegmTrack() const
Functions to get some items count.
void SetCustomTrackWidth(int aWidth)
Function SetCustomTrackWidth Sets custom width for track (i.e.
Class LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
const PCB_LAYER_ID GetLayerID(const wxString &aLayerName) const
Function GetLayerID returns the ID of a layer given by aLayerName.
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:101
int LAYER_NUM
Type LAYER_NUM can be replaced with int and removed.
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
static bool sortNetsByNames(const NETINFO_ITEM *a, const NETINFO_ITEM *b)
TRACKS TracksInNet(int aNetCode)
Function TrackInNet collects all the TRACKs and VIAs that are members of a net given by aNetCode...
int GetNetCode() const
Function GetNetCode.
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:265
Definition: seg.h:36
void Move(const wxPoint &aMoveVector) override
Function Move move this object.
VIA * GetViaByPosition(const wxPoint &aPosition, PCB_LAYER_ID aLayer=PCB_LAYER_ID(-1)) const
Function GetViaByPosition finds the first via at aPosition on aLayer.
const std::vector< D_PAD * > GetPads()
Function GetPads returns a reference to a list of all the pads.
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
bool IsOnCopperLayer() const
Function IsOnCopperLayer.
Definition: class_zone.cpp:181
iterator begin() const
Definition: netinfo.h:524
TRACK * GetBestInsertPoint(BOARD *aPcb)
Function GetBestInsertPoint searches the "best" insertion point within the track linked list...
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
ZONE_CONTAINERS & Zones()
Definition: class_board.h:252
bool SetCurrentNetClass(const wxString &aNetClassName)
Function SetCurrentNetClass Must be called after a netclass selection (or after a netclass parameter ...
TRACK * Next() const
Definition: class_track.h:99
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
const wxString & GetNetname() const
Function GetNetname.
void SetState(int type, int state)
Definition: base_struct.h:253
ZONE_CONTAINER * GetArea(int index) const
Function GetArea returns the Area (Zone Container) at a given index.
Definition: class_board.h:982
void UnHatch()
Function UnHatch clears the zone&#39;s hatch.
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
BOARD * GetParent() const
Definition: netinfo.h:261
int m_fileFormatVersionAtLoad
the version loaded from the file
Definition: class_board.h:189
iterator end() const
Definition: netinfo.h:529
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:469
Class LAYER holds information pertinent to a layer of a BOARD.
Definition: class_board.h:85
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
const wxString & GetReference() const
Function GetReference.
Definition: class_module.h:458
unsigned GetNodesCount() const
Function GetNodesCount.
DLIST< MODULE > m_Modules
Definition: class_board.h:245
void RedrawFilledAreas(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, PCB_LAYER_ID aLayer)
Function RedrawFilledAreas Redraw all filled areas on layer aLayer ( redraw all if aLayer < 0 ) ...
LSET GetVisibleLayers() const
Function GetVisibleLayers is a proxy function that calls the correspondent function in m_BoardSetting...
ZONE_CONTAINERS m_ZoneDescriptorList
edge zone descriptors, owned by pointer.
Definition: class_board.h:181
class NETINFO_ITEM, a description of a net
Definition: typeinfo.h:104
size_t i
Definition: json11.cpp:597
LAYER m_Layer[PCB_LAYER_ID_COUNT]
Definition: class_board.h:183
std::shared_ptr< CONNECTIVITY_DATA > m_connectivity
Definition: class_board.h:191
bool HitTestFilledArea(const wxPoint &aRefPos) const
Function HitTestFilledArea tests if the given wxPoint is within the bounds of a filled area of this z...
Definition: class_zone.cpp:807
int GetNumSegmZone() const
Calculate the zone segment count.
Class EDA_RECT handles the component boundary box.
Definition: eda_rect.h:44
void SetValue(const wxString &aValue)
Function SetValue.
Definition: class_module.h:495
int GetX() const
Definition: eda_rect.h:109
HATCH_STYLE GetHatchStyle() const
Definition: class_zone.h:498
void Hatch()
Function Hatch computes the hatch lines depending on the hatch parameters and stores it in the zone&#39;s...
void chainMarkedSegments(wxPoint aPosition, const LSET &aLayerSet, TRACKS *aList)
Function chainMarkedSegments is used by MarkTrace() to set the BUSY flag of connected segments of the...
void PushHighLight()
Function PushHighLight save current high light info for later use.
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
void SetHatchStyle(HATCH_STYLE aStyle)
Definition: class_zone.h:503
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:162
static bool sortNetsByNodes(const NETINFO_ITEM *a, const NETINFO_ITEM *b)
void SetLocalFlags(int aFlags)
Definition: class_zone.h:231
The common library.
int GetWidth() const
Definition: eda_rect.h:117
bool IsModuleLayerVisible(PCB_LAYER_ID aLayer)
Function IsModuleLayerVisible expects either of the two layers on which a module can reside...
wxString GetClass() const override
Function GetClass returns the class name.
Definition: class_board.h:918
void SetElementVisibility(GAL_LAYER_ID aElementCategory, bool aNewState)
Function SetElementVisibility changes the visibility of an element category.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_UNDEFINED)=0
Function Report is a pure virtual function to override in the derived object.
UTF8 Format() const
Definition: lib_id.cpp:263
int GetY() const
Definition: eda_rect.h:110
#define FIRST_COPPER_LAYER
Class COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
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 containter and deletes it.
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
bool AppendCorner(wxPoint aPosition, int aHoleIdx, bool aAllowDuplication=false)
Add a new corner to the zone outline (to the main outline or a hole)
void SetEffects(const TEXTE_MODULE &aSrc)
Function SetEffects sets the text effects from another instance.
void SetStart(const wxPoint &aStart)
Definition: class_track.h:121
PCB_TARGET class definition.
COMPONENT * GetComponentByReference(const wxString &aReference)
Function GetComponentByReference returns a COMPONENT by aReference.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
const COMPONENT_NET & GetNet(unsigned aIndex) const
Definition: pcb_netlist.h:139
void CopyNetlistSettings(MODULE *aModule, bool aCopyLocalSettings)
Function CopyNetlistSettings copies the netlist settings to aModule.
DLIST_ITERATOR_WRAPPER< TRACK > Tracks()
Definition: class_board.h:249
bool BuildBoardPolygonOutlines(BOARD *aBoard, SHAPE_POLY_SET &aOutlines, wxString *aErrorText)
void RedrawAreasOutlines(EDA_DRAW_PANEL *aPanel, wxDC *aDC, GR_DRAWMODE aDrawMode, PCB_LAYER_ID aLayer)
Function RedrawAreasOutlines Redraw all areas outlines on layer aLayer ( redraw all if aLayer < 0 ) ...
DLIST< TRACK > m_Track
Definition: class_board.h:246
bool IsDryRun() const
Definition: pcb_netlist.h:309
BOARD_DESIGN_SETTINGS m_designSettings
Definition: class_board.h:193
Module description (excepted pads)
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:235
Abstract interface for BOARD_ITEMs capable of storing other items inside.
LSET GetEnabledLayers() const
Function GetEnabledLayers returns a bit-mask of all the layers that are enabled.
static void checkConnectedTo(BOARD *aBoard, TRACKS *aList, const TRACKS &aTracksInNet, const wxPoint &aGoal, const wxPoint &aStart, TRACK *aFirstTrack)
Function checkConnectedTo returns if aTracksInNet contains a copper pathway to aGoal when starting wi...
Class EDA_MSG_ITEM is used EDA_MSG_PANEL as the item type for displaying messages.
Definition: msgpanel.h:53
const wxString & GetPath() const
Definition: class_module.h:200
SEARCH_RESULT
Definition: base_struct.h:64
const wxPoint GetPosition() const override
Definition: class_pad.h:220
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
class DRAWSEGMENT, a segment not on copper layers
Definition: typeinfo.h:91
Message panel definition file.
bool IsSelfIntersecting()
Function IsSelfIntersecting Checks whether any of the polygons in the set is self intersecting...
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.
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:256
LSET GetVisibleLayers() const
Function GetVisibleLayers returns a bit-mask of all the layers that are visible.
BOARD_CONNECTED_ITEM * end
Definition: class_track.h:91
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition: netinfo.h:461
unsigned GetNetCount() const
Definition: pcb_netlist.h:137
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
BOARD_CONNECTED_ITEM * start
Definition: class_track.h:90
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
void ClearAllNetCodes()
Function ClearAllNetCodes() Resets all items&#39; netcodes to 0 (no net).
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:796
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:290
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
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo populates aList of MSG_PANEL_ITEM objects with it&#39;s internal state for displ...
void SetPath(const wxString &aPath)
Definition: class_module.h:201
void Remove(BOARD_ITEM *aBoardItem) override
Removes an item from the container.
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
void UseCustomTrackViaSize(bool aEnabled)
Function UseCustomTrackViaSize Enables/disables custom track/via size settings.
void Insert(T *aNewElement, T *aElementAfterMe)
Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.h:200
COMPONENT * GetComponentByTimeStamp(const wxString &aTimeStamp)
Function GetComponentByTimeStamp returns a COMPONENT by aTimeStamp.
unsigned GetNetCount() const
Function GetNetCount.
Definition: class_board.h:772
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:214
TRACK * GetFirstTrack(TRACK *aTrk, const TRACK *aStopPoint=NULL)
Scan a track list for the first TRACK object. Returns NULL if not found (or NULL passed) ...
Definition: class_track.h:522
int m_Status_Pcb
Flags used in ratsnest calculation and update.
Definition: class_board.h:237
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aAddToBoard=false)
bool HitTest(const wxPoint &aPosition) const override
Function HitTest tests if aPosition is contained within or on the bounding area of an item...
VIA * GetFirstVia(TRACK *aTrk, const TRACK *aStopPoint=NULL)
Scan a track list for the first VIA o NULL if not found (or NULL passed)
Definition: class_track.h:508