KiCad PCB EDA Suite
sch_screen.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2008 Wayne Stambaugh <stambaughw@gmail.com>
7  * Copyright (C) 1992-2017 KiCad Developers, see AUTHORS.txt for contributors.
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
32 #include <fctsys.h>
33 #include <gr_basic.h>
34 #include <common.h>
35 #include <kicad_string.h>
36 #include <eeschema_id.h>
37 #include <pgm_base.h>
38 #include <kiway.h>
39 #include <sch_draw_panel.h>
40 #include <sch_item.h>
41 #include <gr_text.h>
42 #include <sch_edit_frame.h>
43 #include <plotter.h>
44 
45 #include <netlist.h>
46 #include <netlist_object.h>
47 #include <class_library.h>
48 #include <sch_junction.h>
49 #include <sch_bus_entry.h>
50 #include <sch_line.h>
51 #include <sch_marker.h>
52 #include <sch_no_connect.h>
53 #include <sch_sheet.h>
54 #include <sch_component.h>
55 #include <sch_text.h>
56 #include <lib_pin.h>
57 #include <symbol_lib_table.h>
58 #include <tool/common_tools.h>
59 
60 #include <thread>
61 #include <algorithm>
62 #include <future>
63 #include <array>
64 
65 // TODO(JE) Debugging only
66 #include <profile.h>
67 
68 #include <boost/foreach.hpp>
69 
70 #define EESCHEMA_FILE_STAMP "EESchema"
71 
72 /* Default zoom values. Limited to these values to keep a decent size
73  * to menus
74  */
75 static double SchematicZoomList[] =
76 {
77  0.5, 0.7, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 11.0,
78  13.0, 16.0, 20.0, 26.0, 32.0, 48.0, 64.0, 80.0, 128.0
79 };
80 
81 /* Default grid sizes for the schematic editor.
82  * Do NOT add others values (mainly grid values in mm), because they
83  * can break the schematic: Because wires and pins are considered as
84  * connected when the are to the same coordinate we cannot mix
85  * coordinates in mils (internal units) and mm (that cannot exactly
86  * converted in mils in many cases). In fact schematic must only use
87  * 50 and 25 mils to place labels, wires and components others values
88  * are useful only for graphic items (mainly in library editor) so use
89  * integer values in mils only. The 100 mil grid is added to help
90  * conform to the KiCad Library Convention. Which states: "Using a
91  * 100mil grid, pin ends and origin must lie on grid nodes IEC-60617"
92 */
94  { ID_POPUP_GRID_LEVEL_100, wxRealPoint( 100, 100 ) },
95  { ID_POPUP_GRID_LEVEL_50, wxRealPoint( 50, 50 ) },
96  { ID_POPUP_GRID_LEVEL_25, wxRealPoint( 25, 25 ) },
97  { ID_POPUP_GRID_LEVEL_10, wxRealPoint( 10, 10 ) },
98  { ID_POPUP_GRID_LEVEL_5, wxRealPoint( 5, 5 ) },
99  { ID_POPUP_GRID_LEVEL_2, wxRealPoint( 2, 2 ) },
100  { ID_POPUP_GRID_LEVEL_1, wxRealPoint( 1, 1 ) },
101 };
102 
103 
106  KIWAY_HOLDER( aKiway, KIWAY_HOLDER::HOLDER_TYPE::SCREEN ),
107  m_paper( wxT( "A4" ) )
108 {
110 
111  SetZoom( 32 );
112 
113  for( unsigned zoom : SchematicZoomList )
114  m_ZoomList.push_back( zoom );
115 
116  for( GRID_TYPE grid : SchematicGridList )
117  AddGrid( grid );
118 
119  // Set the default grid size, now that the grid list is populated
120  SetGrid( wxRealPoint( 50, 50 ) );
121 
122  m_refCount = 0;
123 
124  // Suitable for schematic only. For libedit and viewlib, must be set to true
125  m_Center = false;
126 
127  InitDataPoints( m_paper.GetSizeIU() );
128 }
129 
130 
132 {
134 
135  // Now delete items in draw list. We do that only if the list is not empty,
136  // because if the list was appended to another list (see SCH_SCREEN::Append( SCH_SCREEN* aScreen )
137  // it is empty but as no longer the ownership (m_drawList.meOwner == false) of items, and calling
138  // FreeDrawList() with m_drawList.meOwner == false will generate a debug alert in debug mode
139  if( GetDrawItems() )
140  FreeDrawList();
141 }
142 
143 
145 {
146  m_refCount++;
147 }
148 
149 
151 {
152  wxCHECK_RET( m_refCount != 0,
153  wxT( "Screen reference count already zero. Bad programmer!" ) );
154  m_refCount--;
155 }
156 
157 
159 {
160  wxCHECK_RET( aScreen, "Invalid screen object." );
161 
162  // No need to decend the hierarchy. Once the top level screen is copied, all of it's
163  // children are copied as well.
164  m_drawList.Append( aScreen->m_drawList );
165 
166  // This screen owns the objects now. This prevents the object from being delete when
167  // aSheet is deleted.
168  aScreen->m_drawList.SetOwnership( false );
169 }
170 
171 
173 {
174  FreeDrawList();
175 
176  // Clear the project settings
178 
179  m_titles.Clear();
180 }
181 
182 
184 {
186 }
187 
188 
190 {
191  m_drawList.Remove( aItem );
192 }
193 
194 
196 {
197  wxCHECK_RET( aItem, wxT( "Cannot delete invalid item from screen." ) );
198 
199  SetModify();
200 
201  if( aItem->Type() == SCH_SHEET_PIN_T )
202  {
203  // This structure is attached to a sheet, get the parent sheet object.
204  SCH_SHEET_PIN* sheetPin = (SCH_SHEET_PIN*) aItem;
205  SCH_SHEET* sheet = sheetPin->GetParent();
206  wxCHECK_RET( sheet, wxT( "Sheet label parent not properly set, bad programmer!" ) );
207  sheet->RemovePin( sheetPin );
208  return;
209  }
210  else
211  {
212  m_drawList.Remove( aItem );
213  delete aItem;
214  }
215 }
216 
217 
219 {
220  SCH_ITEM* itemList = m_drawList.begin();
221 
222  while( itemList )
223  {
224  if( itemList == aItem )
225  return true;
226 
227  itemList = itemList->Next();
228  }
229 
230  return false;
231 }
232 
233 
234 SCH_ITEM* SCH_SCREEN::GetItem( const wxPoint& aPosition, int aAccuracy, KICAD_T aType ) const
235 {
236  KICAD_T types[] = { aType, EOT };
237 
238  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
239  {
240  switch( item->Type() )
241  {
242  case SCH_COMPONENT_T:
243  {
244  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
245 
246  for( int i = REFERENCE; i < component->GetFieldCount(); i++ )
247  {
248  SCH_FIELD* field = component->GetField( i );
249 
250  if( field->IsType( types ) && field->HitTest( aPosition, aAccuracy ) )
251  return field;
252  }
253 
254  break;
255  }
256  case SCH_SHEET_T:
257  {
258  SCH_SHEET* sheet = (SCH_SHEET*)item;
259 
260  SCH_SHEET_PIN* pin = sheet->GetPin( aPosition );
261 
262  if( pin && pin->IsType( types ) )
263  return pin;
264 
265  break;
266  }
267  default:
268  break;
269  }
270 
271  if( item->IsType( types ) && item->HitTest( aPosition, aAccuracy ) )
272  return item;
273  }
274 
275  return NULL;
276 }
277 
278 
280 {
281  SCH_ITEM* item;
282  SCH_ITEM* next_item;
283 
284  for( item = m_drawList.begin(); item; item = next_item )
285  {
286  next_item = item->Next();
287 
288  switch( item->Type() )
289  {
290  case SCH_JUNCTION_T:
291  case SCH_LINE_T:
292  Remove( item );
293  delete item;
294  break;
295 
296  default:
297  break;
298  }
299  }
300 
301  m_drawList.Append( aWireList );
302 }
303 
304 
306 {
307  wxCHECK_RET( (aSegment) && (aSegment->Type() == SCH_LINE_T),
308  wxT( "Invalid object pointer." ) );
309 
310  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
311  {
312  if( item->GetFlags() & CANDIDATE )
313  continue;
314 
315  if( item->Type() == SCH_JUNCTION_T )
316  {
317  SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
318 
319  if( aSegment->IsEndPoint( junction->GetPosition() ) )
320  item->SetFlags( CANDIDATE );
321 
322  continue;
323  }
324 
325  if( item->Type() != SCH_LINE_T )
326  continue;
327 
328  SCH_LINE* segment = (SCH_LINE*) item;
329 
330  if( aSegment->IsEndPoint( segment->GetStartPoint() )
331  && !GetPin( segment->GetStartPoint(), NULL, true ) )
332  {
333  item->SetFlags( CANDIDATE );
334  MarkConnections( segment );
335  }
336 
337  if( aSegment->IsEndPoint( segment->GetEndPoint() )
338  && !GetPin( segment->GetEndPoint(), NULL, true ) )
339  {
340  item->SetFlags( CANDIDATE );
341  MarkConnections( segment );
342  }
343  }
344 }
345 
346 
347 bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition, bool aNew )
348 {
349  enum { WIRES, BUSSES } layers;
350 
351  bool has_nonparallel[ sizeof( layers ) ] = { false };
352  int end_count[ sizeof( layers ) ] = { 0 };
353  int pin_count = 0;
354 
355  std::vector<SCH_LINE*> lines[ sizeof( layers ) ];
356 
357  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
358  {
359  if( item->GetEditFlags() & STRUCT_DELETED )
360  continue;
361 
362  if( aNew && ( item->Type() == SCH_JUNCTION_T ) && ( item->HitTest( aPosition ) ) )
363  return false;
364 
365  if( ( item->Type() == SCH_LINE_T ) && ( item->HitTest( aPosition, 0 ) ) )
366  {
367  if( item->GetLayer() == LAYER_WIRE )
368  lines[ WIRES ].push_back( (SCH_LINE*) item );
369  else if( item->GetLayer() == LAYER_BUS )
370  lines[ BUSSES ].push_back( (SCH_LINE*) item );
371  }
372 
373  if( ( item->Type() == SCH_COMPONENT_T ) && ( item->IsConnected( aPosition ) ) )
374  pin_count++;
375  }
376 
377  for( int i : { WIRES, BUSSES } )
378  {
379  bool removed_overlapping = false;
380  end_count[i] = lines[i].size();
381 
382  for( auto line = lines[i].begin(); line < lines[i].end(); line++ )
383  {
384  // Consider ending on a line to be equivalent to two endpoints because
385  // we will want to split the line if anything else connects
386  if( !(*line)->IsEndPoint( aPosition ) )
387  end_count[i]++;
388 
389  for( auto second_line = lines[i].end() - 1; second_line > line; second_line-- )
390  {
391  if( !(*line)->IsParallel( *second_line ) )
392  has_nonparallel[i] = true;
393  else if( !removed_overlapping
394  && (*line)->IsSameQuadrant( *second_line, aPosition ) )
395  {
401  removed_overlapping = true;
402  end_count[i]--;
403  }
404  }
405  }
406  }
407 
408  //
409 
410  // If there are three or more endpoints
411  if( pin_count + end_count[0] > 2 )
412  return true;
413 
414  // If there is at least one segment that ends on a non-parallel line or
415  // junction of two other lines
416  if( has_nonparallel[0] && end_count[0] > 2 )
417  return true;
418 
419  // Check for bus - bus junction requirements
420  if( has_nonparallel[1] && end_count[1] > 2 )
421  return true;
422 
423  return false;
424 }
425 
426 
427 bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer )
428 {
429  wxCHECK_MSG( aLayer == LAYER_NOTES || aLayer == LAYER_BUS || aLayer == LAYER_WIRE, false,
430  wxT( "Invalid layer type passed to SCH_SCREEN::IsTerminalPoint()." ) );
431 
432  SCH_SHEET_PIN* label;
433  SCH_TEXT* text;
434  SCH_CONNECTION conn;
435 
436  switch( aLayer )
437  {
438  case LAYER_BUS:
439 
440  if( GetBus( aPosition ) )
441  return true;
442 
443  label = GetSheetLabel( aPosition );
444 
445  if( label && conn.IsBusLabel( label->GetText() ) && label->IsConnected( aPosition ) )
446  return true;
447 
448  text = GetLabel( aPosition );
449 
450  if( text && conn.IsBusLabel( text->GetText() ) && text->IsConnected( aPosition )
451  && (text->Type() != SCH_LABEL_T) )
452  return true;
453 
454  break;
455 
456  case LAYER_NOTES:
457 
458  if( GetLine( aPosition ) )
459  return true;
460 
461  break;
462 
463  case LAYER_WIRE:
465  return true;
466 
467  if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_BUS_BUS_ENTRY_T) )
468  return true;
469 
470  if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_JUNCTION_T ) )
471  return true;
472 
473  if( GetPin( aPosition, NULL, true ) )
474  return true;
475 
476  if( GetWire( aPosition ) )
477  return true;
478 
479  text = GetLabel( aPosition );
480 
481  if( text && text->IsConnected( aPosition ) && !conn.IsBusLabel( text->GetText() ) )
482  return true;
483 
484  label = GetSheetLabel( aPosition );
485 
486  if( label && label->IsConnected( aPosition ) && !conn.IsBusLabel( label->GetText() ) )
487  return true;
488 
489  break;
490 
491  default:
492  break;
493  }
494 
495  return false;
496 }
497 
498 
499 void SCH_SCREEN::UpdateSymbolLinks( bool aForce )
500 {
501  // Initialize or reinitialize the pointer to the LIB_PART for each component
502  // found in m_drawList, but only if needed (change in lib or schematic)
503  // therefore the calculation time is usually very low.
504  if( m_drawList.GetCount() )
505  {
506  SYMBOL_LIB_TABLE* libs = Prj().SchSymbolLibTable();
507  int mod_hash = libs->GetModifyHash();
509 
511 
512  // Must we resolve?
513  if( (m_modification_sync != mod_hash) || aForce )
514  {
515  SCH_COMPONENT::ResolveAll( c, *libs, Prj().SchLibs()->GetCacheLibrary() );
516 
517  m_modification_sync = mod_hash; // note the last mod_hash
518  }
519  // Resolving will update the pin caches but we must ensure that this happens
520  // even if the libraries don't change.
521  else
523  }
524 }
525 
526 
527 void SCH_SCREEN::Print( wxDC* aDC )
528 {
529  std::vector< SCH_ITEM* > junctions;
530 
531  // Ensure links are up to date, even if a library was reloaded for some reason:
533 
534  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
535  {
536  if( item->IsMoving() || item->IsResized() )
537  continue;
538 
539  if( item->Type() == SCH_JUNCTION_T )
540  junctions.push_back( item );
541  else
542  item->Print( aDC, wxPoint( 0, 0 ) );
543  }
544 
545  for( auto item : junctions )
546  item->Print( aDC, wxPoint( 0, 0 ) );
547 }
548 
549 
550 void SCH_SCREEN::Plot( PLOTTER* aPlotter )
551 {
552  // Ensure links are up to date, even if a library was reloaded for some reason:
553  std::vector< SCH_ITEM* > junctions;
554  std::vector< SCH_ITEM* > bitmaps;
555  std::vector< SCH_ITEM* > other;
556 
557  // Ensure links are up to date, even if a library was reloaded for some reason:
559 
560  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
561  {
562  if( item->IsMoving() || item->IsResized() )
563  continue;
564 
565  if( item->Type() == SCH_JUNCTION_T )
566  junctions.push_back( item );
567  else if( item->Type() == SCH_BITMAP_T )
568  bitmaps.push_back( item );
569  else
570  // uncomment line below when there is a virtual EDA_ITEM::GetBoundingBox()
571  // if( panel->GetClipBox().Intersects( item->GetBoundingBox() ) )
572  other.push_back( item );
573  }
574 
575  // Bitmaps are drawn first to ensure they are in the background
576  // This is particularly important for the wxPostscriptDC (used in *nix printers) as
577  // the bitmap PS command clears the screen
578  for( auto item : bitmaps )
579  {
580  aPlotter->SetCurrentLineWidth( item->GetPenSize() );
581  item->Plot( aPlotter );
582  }
583 
584  for( auto item : other )
585  {
586  aPlotter->SetCurrentLineWidth( item->GetPenSize() );
587  item->Plot( aPlotter );
588  }
589 
590  for( auto item : junctions )
591  {
592  aPlotter->SetCurrentLineWidth( item->GetPenSize() );
593  item->Plot( aPlotter );
594  }
595 }
596 
597 
599 {
600  if( aItemCount == 0 )
601  return;
602 
603  for( auto& command : aList.m_CommandsList )
604  {
605  command->ClearListAndDeleteItems();
606  delete command;
607  }
608 
609  aList.m_CommandsList.clear();
610 }
611 
612 
614 {
615  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
616  item->ClearTempFlags();
617 }
618 
619 
620 LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent,
621  bool aEndPointOnly ) const
622 {
623  SCH_ITEM* item;
624  SCH_COMPONENT* component = NULL;
625  LIB_PIN* pin = NULL;
626 
627  for( item = m_drawList.begin(); item; item = item->Next() )
628  {
629  if( item->Type() != SCH_COMPONENT_T )
630  continue;
631 
632  component = (SCH_COMPONENT*) item;
633 
634  if( aEndPointOnly )
635  {
636  pin = NULL;
637 
638  auto part = component->GetPartRef().lock();
639 
640  if( !part )
641  continue;
642 
643  for( pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
644  {
645  // Skip items not used for this part.
646  if( component->GetUnit() && pin->GetUnit() &&
647  ( pin->GetUnit() != component->GetUnit() ) )
648  continue;
649 
650  if( component->GetConvert() && pin->GetConvert() &&
651  ( pin->GetConvert() != component->GetConvert() ) )
652  continue;
653 
654  if(component->GetPinPhysicalPosition( pin ) == aPosition )
655  break;
656  }
657  if( pin )
658  break;
659  }
660  else
661  {
662  pin = (LIB_PIN*) component->GetDrawItem( aPosition, LIB_PIN_T );
663 
664  if( pin )
665  break;
666  }
667  }
668 
669  if( pin && aComponent )
670  *aComponent = component;
671 
672  return pin;
673 }
674 
675 
676 SCH_SHEET* SCH_SCREEN::GetSheet( const wxString& aName )
677 {
678  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
679  {
680  if( item->Type() != SCH_SHEET_T )
681  continue;
682 
683  SCH_SHEET* sheet = (SCH_SHEET*) item;
684 
685  if( aName.CmpNoCase( sheet->GetName() ) == 0 )
686  return sheet;
687  }
688 
689  return NULL;
690 }
691 
692 
693 SCH_SHEET_PIN* SCH_SCREEN::GetSheetLabel( const wxPoint& aPosition )
694 {
695  SCH_SHEET_PIN* sheetPin = NULL;
696 
697  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
698  {
699  if( item->Type() != SCH_SHEET_T )
700  continue;
701 
702  SCH_SHEET* sheet = (SCH_SHEET*) item;
703  sheetPin = sheet->GetPin( aPosition );
704 
705  if( sheetPin )
706  break;
707  }
708 
709  return sheetPin;
710 }
711 
712 
713 int SCH_SCREEN::CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const
714 {
715  SCH_ITEM* item;
716  int count = 0;
717 
718  for( item = m_drawList.begin(); item; item = item->Next() )
719  {
720  if( item->Type() == SCH_JUNCTION_T && !aTestJunctions )
721  continue;
722 
723  if( item->IsConnected( aPos ) )
724  count++;
725  }
726 
727  return count;
728 }
729 
730 
732 {
733  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
734  {
735  if( item->Type() == SCH_COMPONENT_T )
736  {
737  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
738 
739  component->ClearAnnotation( aSheetPath );
740 
741  // Clear the modified component flag set by component->ClearAnnotation
742  // because we do not use it here and we should not leave this flag set,
743  // when an editing is finished:
744  component->ClearFlags();
745  }
746  }
747 }
748 
749 
751 {
752  if( GetClientSheetPathsCount() <= 1 ) // No need for alternate reference
753  return;
754 
755  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
756  {
757  if( item->Type() != SCH_COMPONENT_T )
758  continue;
759 
760  // Add (when not existing) all sheet path entries
761  for( unsigned int ii = 0; ii < m_clientSheetPathList.GetCount(); ii++ )
762  ((SCH_COMPONENT*)item)->AddSheetPathReferenceEntryIfMissing( m_clientSheetPathList[ii] );
763  }
764 }
765 
766 
768 {
769  SCH_ITEM* item = m_drawList.begin();
770 
771  while( item )
772  {
773  if( ( item->Type() == SCH_SHEET_T ) || ( item->Type() == SCH_COMPONENT_T ) )
774  aItems.push_back( item );
775 
776  item = item->Next();
777  }
778 }
779 
780 
782 {
783  SCH_ITEM* item;
784  std::vector< DANGLING_END_ITEM > endPoints;
785  bool hasStateChanged = false;
786 
787  for( item = m_drawList.begin(); item; item = item->Next() )
788  item->GetEndPoints( endPoints );
789 
790  for( item = m_drawList.begin(); item; item = item->Next() )
791  {
792  if( item->UpdateDanglingState( endPoints ) )
793  {
794  hasStateChanged = true;
795  }
796  }
797 
798  return hasStateChanged;
799 }
800 
801 
802 SCH_LINE* SCH_SCREEN::GetWireOrBus( const wxPoint& aPosition )
803 {
805 
806  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
807  {
808  if( item->IsType( types ) && item->HitTest( aPosition ) )
809  return (SCH_LINE*) item;
810  }
811 
812  return nullptr;
813 }
814 
815 
816 SCH_LINE* SCH_SCREEN::GetLine( const wxPoint& aPosition, int aAccuracy, int aLayer,
817  SCH_LINE_TEST_T aSearchType )
818 {
819  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
820  {
821  if( item->Type() != SCH_LINE_T )
822  continue;
823 
824  if( item->GetLayer() != aLayer )
825  continue;
826 
827  if( !item->HitTest( aPosition, aAccuracy ) )
828  continue;
829 
830  switch( aSearchType )
831  {
832  case ENTIRE_LENGTH_T:
833  return (SCH_LINE*) item;
834 
836  if( !( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
837  return (SCH_LINE*) item;
838  break;
839 
840  case END_POINTS_ONLY_T:
841  if( ( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
842  return (SCH_LINE*) item;
843  }
844  }
845 
846  return NULL;
847 }
848 
849 
850 SCH_TEXT* SCH_SCREEN::GetLabel( const wxPoint& aPosition, int aAccuracy )
851 {
852  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
853  {
854  switch( item->Type() )
855  {
856  case SCH_LABEL_T:
857  case SCH_GLOBAL_LABEL_T:
858  case SCH_HIER_LABEL_T:
859  if( item->HitTest( aPosition, aAccuracy ) )
860  return (SCH_TEXT*) item;
861 
862  default:
863  ;
864  }
865  }
866 
867  return NULL;
868 }
869 
870 
871 bool SCH_SCREEN::SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
872  const wxString& aFootPrint, bool aSetVisible )
873 {
874  SCH_COMPONENT* component;
875  bool found = false;
876 
877  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
878  {
879  if( item->Type() != SCH_COMPONENT_T )
880  continue;
881 
882  component = (SCH_COMPONENT*) item;
883 
884  if( aReference.CmpNoCase( component->GetRef( aSheetPath ) ) == 0 )
885  {
886  // Found: Init Footprint Field
887 
888  /* Give a reasonable value to the field position and
889  * orientation, if the text is empty at position 0, because
890  * it is probably not yet initialized
891  */
892  SCH_FIELD * fpfield = component->GetField( FOOTPRINT );
893  if( fpfield->GetText().IsEmpty()
894  && ( fpfield->GetTextPos() == component->GetPosition() ) )
895  {
896  fpfield->SetTextAngle( component->GetField( VALUE )->GetTextAngle() );
897  fpfield->SetTextPos( component->GetField( VALUE )->GetTextPos() );
898  fpfield->SetTextSize( component->GetField( VALUE )->GetTextSize() );
899 
900  if( fpfield->GetTextAngle() == 0.0 )
901  fpfield->Offset( wxPoint( 0, 100 ) );
902  else
903  fpfield->Offset( wxPoint( 100, 0 ) );
904  }
905 
906  fpfield->SetText( aFootPrint );
907  fpfield->SetVisible( aSetVisible );
908 
909  found = true;
910  }
911  }
912 
913  return found;
914 }
915 
916 
917 void SCH_SCREEN::AddBusAlias( std::shared_ptr<BUS_ALIAS> aAlias )
918 {
919  m_aliases.insert( aAlias );
920 }
921 
922 
923 bool SCH_SCREEN::IsBusAlias( const wxString& aLabel )
924 {
925  SCH_SHEET_LIST aSheets( g_RootSheet );
926  for( unsigned i = 0; i < aSheets.size(); i++ )
927  {
928  for( auto alias : aSheets[i].LastScreen()->GetBusAliases() )
929  {
930  if( alias->GetName() == aLabel )
931  {
932  return true;
933  }
934  }
935  }
936 
937  return false;
938 }
939 
940 
941 std::shared_ptr<BUS_ALIAS> SCH_SCREEN::GetBusAlias( const wxString& aLabel )
942 {
943  SCH_SHEET_LIST aSheets( g_RootSheet );
944  for( unsigned i = 0; i < aSheets.size(); i++ )
945  {
946  for( auto alias : aSheets[i].LastScreen()->GetBusAliases() )
947  {
948  if( alias->GetName() == aLabel )
949  {
950  return alias;
951  }
952  }
953  }
954 
955  return NULL;
956 }
957 
958 
959 #if defined(DEBUG)
960 void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const
961 {
962  // for now, make it look like XML, expand on this later.
963  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << ">\n";
964 
965  for( EDA_ITEM* item = m_drawList.begin(); item; item = item->Next() )
966  {
967  item->Show( nestLevel+1, os );
968  }
969 
970  NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
971 }
972 #endif
973 
974 
978 static bool SortByTimeStamp( const EDA_ITEM* item1, const EDA_ITEM* item2 )
979 {
980  int ii = item1->GetTimeStamp() - item2->GetTimeStamp();
981 
982  /* If the time stamps are the same, compare type in order to have component objects
983  * before sheet object. This is done because changing the sheet time stamp
984  * before the component time stamp could cause the current annotation to be lost.
985  */
986  if( ( ii == 0 && ( item1->Type() != item2->Type() ) ) && ( item1->Type() == SCH_SHEET_T ) )
987  ii = -1;
988 
989  return ii < 0;
990 }
991 
992 
994 {
995  m_index = 0;
996  buildScreenList( ( !aSheet ) ? g_RootSheet : aSheet );
997 }
998 
999 
1001 {
1002 }
1003 
1004 
1006 {
1007  m_index = 0;
1008 
1009  if( m_screens.size() > 0 )
1010  return m_screens[0];
1011 
1012  return NULL;
1013 }
1014 
1015 
1017 {
1018  if( m_index < m_screens.size() )
1019  m_index++;
1020 
1021  return GetScreen( m_index );
1022 }
1023 
1024 
1025 SCH_SCREEN* SCH_SCREENS::GetScreen( unsigned int aIndex ) const
1026 {
1027  if( aIndex < m_screens.size() )
1028  return m_screens[ aIndex ];
1029 
1030  return NULL;
1031 }
1032 
1033 
1035 {
1036  if( aScreen == NULL )
1037  return;
1038 
1039  for( unsigned int i = 0; i < m_screens.size(); i++ )
1040  {
1041  if( m_screens[i] == aScreen )
1042  return;
1043  }
1044 
1045  m_screens.push_back( aScreen );
1046 }
1047 
1048 
1050 {
1051  if( aSheet && aSheet->Type() == SCH_SHEET_T )
1052  {
1053  SCH_SCREEN* screen = aSheet->GetScreen();
1054 
1055  addScreenToList( screen );
1056 
1057  EDA_ITEM* strct = screen->GetDrawItems();
1058 
1059  while( strct )
1060  {
1061  if( strct->Type() == SCH_SHEET_T )
1062  {
1063  buildScreenList( ( SCH_SHEET* )strct );
1064  }
1065 
1066  strct = strct->Next();
1067  }
1068  }
1069 }
1070 
1071 
1073 {
1074  for( size_t i = 0; i < m_screens.size(); i++ )
1075  m_screens[i]->ClearAnnotation( NULL );
1076 }
1077 
1078 
1080 {
1081  // Clear the annotation for the components inside new sheetpaths
1082  // not already in aInitialSheetList
1083  SCH_SCREENS screensList( g_RootSheet ); // The list of screens, shared by sheet paths
1084  screensList.BuildClientSheetPathList(); // build the shared by sheet paths, by screen
1085 
1086  // Search for new sheet paths, not existing in aInitialSheetPathList
1087  // and existing in sheetpathList
1088  SCH_SHEET_LIST sheetpathList( g_RootSheet );
1089 
1090  for( SCH_SHEET_PATH& sheetpath: sheetpathList )
1091  {
1092  bool path_exists = false;
1093 
1094  for( const SCH_SHEET_PATH& existing_sheetpath: aInitialSheetPathList )
1095  {
1096  if( existing_sheetpath.Path() == sheetpath.Path() )
1097  {
1098  path_exists = true;
1099  break;
1100  }
1101  }
1102 
1103  if( !path_exists )
1104  {
1105  // A new sheet path is found: clear the annotation corresponding to this new path:
1106  SCH_SCREEN* curr_screen = sheetpath.LastScreen();
1107 
1108  // Clear annotation and create the AR for this path, if not exists,
1109  // when the screen is shared by sheet paths.
1110  // Otherwise ClearAnnotation do nothing, because the F1 field is used as
1111  // reference default value and takes the latest displayed value
1112  curr_screen->EnsureAlternateReferencesExist();
1113  curr_screen->ClearAnnotation( &sheetpath );
1114  }
1115  }
1116 }
1117 
1118 
1120 {
1121  EDA_ITEMS items;
1122  SCH_ITEM* item;
1123 
1124  for( size_t i = 0; i < m_screens.size(); i++ )
1125  m_screens[i]->GetHierarchicalItems( items );
1126 
1127  if( items.size() < 2 )
1128  return 0;
1129 
1130  sort( items.begin(), items.end(), SortByTimeStamp );
1131 
1132  int count = 0;
1133 
1134  for( size_t ii = 0; ii < items.size() - 1; ii++ )
1135  {
1136  item = (SCH_ITEM*)items[ii];
1137 
1138  SCH_ITEM* nextItem = (SCH_ITEM*)items[ii + 1];
1139 
1140  if( item->GetTimeStamp() == nextItem->GetTimeStamp() )
1141  {
1142  count++;
1143 
1144  // for a component, update its Time stamp and its paths
1145  // (m_PathsAndReferences field)
1146  if( item->Type() == SCH_COMPONENT_T )
1147  ( (SCH_COMPONENT*) item )->SetTimeStamp( GetNewTimeStamp() );
1148 
1149  // for a sheet, update only its time stamp (annotation of its
1150  // components will be lost)
1151  // @todo: see how to change sheet paths for its cmp list (can
1152  // be possible in most cases)
1153  else
1154  item->SetTimeStamp( GetNewTimeStamp() );
1155  }
1156  }
1157 
1158  return count;
1159 }
1160 
1161 
1163 {
1164  SCH_ITEM* item;
1165  SCH_ITEM* nextItem;
1166  SCH_MARKER* marker;
1167  SCH_SCREEN* screen;
1168 
1169  for( screen = GetFirst(); screen; screen = GetNext() )
1170  {
1171  for( item = screen->GetDrawItems(); item; item = nextItem )
1172  {
1173  nextItem = item->Next();
1174 
1175  if( item->Type() != SCH_MARKER_T )
1176  continue;
1177 
1178  marker = (SCH_MARKER*) item;
1179 
1180  if( marker->GetMarkerType() != aMarkerType )
1181  continue;
1182 
1183  screen->DeleteItem( marker );
1184  }
1185  }
1186 }
1187 
1188 
1190  enum MARKER_BASE::MARKER_SEVERITY aSeverity )
1191 {
1192  int count = 0;
1193 
1194  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1195  {
1196  for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
1197  {
1198  if( item->Type() != SCH_MARKER_T )
1199  continue;
1200 
1201  SCH_MARKER* marker = (SCH_MARKER*) item;
1202 
1203  if( ( aMarkerType != MARKER_BASE::MARKER_UNSPEC ) &&
1204  ( marker->GetMarkerType() != aMarkerType ) )
1205  continue;
1206 
1207  if( aSeverity == MARKER_BASE::MARKER_SEVERITY_UNSPEC ||
1208  aSeverity == marker->GetErrorLevel() )
1209  count++;
1210  }
1211  }
1212 
1213  return count;
1214 }
1215 
1216 
1218 {
1219  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1220  screen->UpdateSymbolLinks( aForce );
1221 }
1222 
1223 
1225 {
1226  std::vector<SCH_SCREEN*> screens;
1227  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1228  screens.push_back( screen );
1229 
1230  size_t parallelThreadCount = std::min<size_t>( std::thread::hardware_concurrency(),
1231  screens.size() );
1232 
1233  std::atomic<size_t> nextScreen( 0 );
1234  std::vector<std::future<size_t>> returns( parallelThreadCount );
1235 
1236  auto update_lambda = [&screens, &nextScreen]() -> size_t
1237  {
1238  for( auto i = nextScreen++; i < screens.size(); i = nextScreen++ )
1239  screens[i]->TestDanglingEnds();
1240 
1241  return 1;
1242  };
1243 
1244  if( parallelThreadCount == 1 )
1245  update_lambda();
1246  else
1247  {
1248  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
1249  returns[ii] = std::async( std::launch::async, update_lambda );
1250 
1251  // Finalize the threads
1252  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
1253  returns[ii].wait();
1254  }
1255 
1256 }
1257 
1258 
1260 {
1261  SCH_COMPONENT* symbol;
1262  SCH_ITEM* item;
1263  SCH_ITEM* nextItem;
1264  SCH_SCREEN* screen;
1265  unsigned cnt = 0;
1266 
1267  for( screen = GetFirst(); screen; screen = GetNext() )
1268  {
1269  for( item = screen->GetDrawItems(); item; item = nextItem )
1270  {
1271  nextItem = item->Next();
1272 
1273  if( item->Type() != SCH_COMPONENT_T )
1274  continue;
1275 
1276  cnt += 1;
1277  symbol = dynamic_cast< SCH_COMPONENT* >( item );
1278  wxASSERT( symbol );
1279 
1280  if( !symbol->GetLibId().GetLibNickname().empty() )
1281  return false;
1282  }
1283  }
1284 
1285  if( cnt == 0 )
1286  return false;
1287 
1288  return true;
1289 }
1290 
1291 
1292 size_t SCH_SCREENS::GetLibNicknames( wxArrayString& aLibNicknames )
1293 {
1294  SCH_COMPONENT* symbol;
1295  SCH_ITEM* item;
1296  SCH_ITEM* nextItem;
1297  SCH_SCREEN* screen;
1298  wxString nickname;
1299 
1300  for( screen = GetFirst(); screen; screen = GetNext() )
1301  {
1302  for( item = screen->GetDrawItems(); item; item = nextItem )
1303  {
1304  nextItem = item->Next();
1305 
1306  if( item->Type() != SCH_COMPONENT_T )
1307  continue;
1308 
1309  symbol = dynamic_cast< SCH_COMPONENT* >( item );
1310  wxASSERT( symbol );
1311 
1312  if( !symbol )
1313  continue;
1314 
1315  nickname = symbol->GetLibId().GetLibNickname();
1316 
1317  if( !nickname.empty() && ( aLibNicknames.Index( nickname ) == wxNOT_FOUND ) )
1318  aLibNicknames.Add( nickname );;
1319  }
1320  }
1321 
1322  return aLibNicknames.GetCount();
1323 }
1324 
1325 
1326 int SCH_SCREENS::ChangeSymbolLibNickname( const wxString& aFrom, const wxString& aTo )
1327 {
1328  SCH_COMPONENT* symbol;
1329  SCH_ITEM* item;
1330  SCH_ITEM* nextItem;
1331  SCH_SCREEN* screen;
1332  int cnt = 0;
1333 
1334  for( screen = GetFirst(); screen; screen = GetNext() )
1335  {
1336  for( item = screen->GetDrawItems(); item; item = nextItem )
1337  {
1338  nextItem = item->Next();
1339 
1340  if( item->Type() != SCH_COMPONENT_T )
1341  continue;
1342 
1343  symbol = dynamic_cast< SCH_COMPONENT* >( item );
1344  wxASSERT( symbol );
1345 
1346  if( symbol->GetLibId().GetLibNickname() != aFrom )
1347  continue;
1348 
1349  LIB_ID id = symbol->GetLibId();
1350  id.SetLibNickname( aTo );
1351  symbol->SetLibId( id );
1352  cnt++;
1353  }
1354  }
1355 
1356  return cnt;
1357 }
1358 
1359 
1360 bool SCH_SCREENS::HasSchematic( const wxString& aSchematicFileName )
1361 {
1362  for( const SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1363  {
1364  if( screen->GetFileName() == aSchematicFileName )
1365  return true;
1366  }
1367 
1368  return false;
1369 }
1370 
1371 
1373 {
1374  SCH_SHEET_LIST sheetList( g_RootSheet );
1375 
1376  for( SCH_SCREEN* curr_screen = GetFirst(); curr_screen; curr_screen = GetNext() )
1377  curr_screen->GetClientSheetPaths().Clear();
1378 
1379  for( SCH_SHEET_PATH& sheetpath: sheetList )
1380  {
1381  SCH_SCREEN* used_screen = sheetpath.LastScreen();
1382 
1383  // SEarch for the used_screen in list and add this unique sheet path:
1384  for( SCH_SCREEN* curr_screen = GetFirst(); curr_screen; curr_screen = GetNext() )
1385  {
1386  if( used_screen == curr_screen )
1387  {
1388  curr_screen->GetClientSheetPaths().Add( sheetpath.Path() );
1389  break;
1390  }
1391  }
1392  }
1393 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
Class SCH_SHEET_LIST.
void Collect(EDA_ITEM *aItem, const KICAD_T aScanList[])
Function Collect scans a DLIST using this class's Inspector method, which does the collection.
static void UpdatePins(const EE_COLLECTOR &aComponents)
Update the pin cache for all components in aComponents.
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_holder.h:39
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:235
bool IsType(const KICAD_T aScanTypes[]) override
Function IsType Checks whether the item is one of the listed types.
Definition: sch_field.h:71
SCH_SCREEN * GetNext()
int m_ScreenNumber
Definition: base_screen.h:135
SCH_SHEET_PIN * GetPin(const wxPoint &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:371
PART_REF & GetPartRef()
void DeleteAllMarkers(enum MARKER_BASE::TYPEMARKER aMarkerType)
Delete all electronic rules check markers of aMarkerType from all the screens in the list.
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:153
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
wxPoint GetStartPoint() const
Definition: sch_line.h:90
bool IsJunctionNeeded(const wxPoint &aPosition, bool aNew=false)
Test if a junction is required for the items at aPosition on the screen.
Definition: sch_screen.cpp:347
virtual void GetEndPoints(std::vector< DANGLING_END_ITEM > &aItemList)
Function GetEndPoints adds the schematic item end points to aItemList if the item has end points.
Definition: sch_item.h:273
SCH_ITEM * Next() const
Definition: sch_item.h:153
MARKER_SEVERITY GetErrorLevel() const
Definition: marker_base.h:175
static double SchematicZoomList[]
Definition: sch_screen.cpp:75
SCH_SHEET * GetSheet(const wxString &aName)
Returns a sheet object pointer that is named aName.
Definition: sch_screen.cpp:676
static bool IsBusLabel(const wxString &aLabel)
Test if aLabel has a bus notation.
int GetClientSheetPathsCount()
Definition: sch_screen.h:140
void AddGrid(const GRID_TYPE &aGrid)
void Append(T *aNewElement)
Function Append adds aNewElement to the end of the list.
Definition: dlist.h:177
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in m_drawL...
Definition: sch_screen.cpp:499
wxArrayString & GetClientSheetPaths()
Definition: sch_screen.h:142
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i....
int CountConnectedItems(const wxPoint &aPos, bool aTestJunctions) const
Definition: sch_screen.cpp:713
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:229
void SetVisible(bool aVisible)
Definition: eda_text.h:169
int m_refCount
Number of sheets referencing this screen.
Definition: sch_screen.h:70
int ChangeSymbolLibNickname(const wxString &aFrom, const wxString &aTo)
Change all of the symbol library nicknames.
static std::shared_ptr< BUS_ALIAS > GetBusAlias(const wxString &aLabel)
Returns a pointer to a bus alias object for the given label, or null if one doesn't exist.
Definition: sch_screen.cpp:941
double GetTextAngle() const
Definition: eda_text.h:158
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:104
virtual bool IsType(const KICAD_T aScanTypes[])
Function IsType Checks whether the item is one of the listed types.
Definition: base_struct.h:293
T * begin() const
Definition: dlist.h:218
void Clear()
Definition: title_block.h:127
void Remove(SCH_ITEM *aItem)
Remove aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:189
LIB_ITEM * GetDrawItem(const wxPoint &aPosition, KICAD_T aType=TYPE_NOT_INIT)
Return the component library item at aPosition that is part of this component.
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:220
static const KICAD_T ComponentsOnly[]
Definition: ee_collectors.h:44
void EnsureAlternateReferencesExist()
For screens shared by many sheetpaths (complex hierarchies): to be able to clear or modify any refere...
Definition: sch_screen.cpp:750
SCH_SCREENS(SCH_SHEET *aSheet=NULL)
Definition: sch_screen.cpp:993
#define CANDIDATE
flag indicating that the structure is connected
Definition: base_struct.h:130
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:44
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
int m_modification_sync
inequality with PART_LIBS::GetModificationHash() will trigger ResolveAll().
Definition: sch_screen.h:91
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:271
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
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
LIB_PIN * GetPin(const wxPoint &aPosition, SCH_COMPONENT **aComponent=NULL, bool aEndPointOnly=false) const
Test the screen for a component pin item at aPosition.
Definition: sch_screen.cpp:620
EDA_ITEM * Next() const
Definition: base_struct.h:218
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
static GRID_TYPE SchematicGridList[]
Definition: sch_screen.cpp:93
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:63
SCH_LINE * GetLine(const wxPoint &aPosition, int aAccuracy=0, int aLayer=LAYER_NOTES, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Return a line item located at aPosition.
Definition: sch_screen.cpp:816
unsigned int m_index
Definition: sch_screen.h:490
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
virtual bool UpdateDanglingState(std::vector< DANGLING_END_ITEM > &aItemList)
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
Definition: sch_item.h:288
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
int GetUnit() const
Definition: lib_item.h:301
#define VALUE
void SetLibId(const LIB_ID &aName, PART_LIBS *aLibs=NULL)
int GetUnit() const
void RemovePin(SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:187
TITLE_BLOCK m_titles
Definition: sch_screen.h:84
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
PAGE_INFO m_paper
The size of the paper to print or plot on.
Definition: sch_screen.h:82
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:112
void GetHierarchicalItems(EDA_ITEMS &aItems)
Add all schematic sheet and component objects in the screen to aItems.
Definition: sch_screen.cpp:767
wxString GetName() const
Definition: sch_sheet.h:262
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:95
bool m_Center
Center on screen.
Definition: base_screen.h:121
void DeleteItem(SCH_ITEM *aItem)
Removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:195
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:622
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
SCH_LINE_TEST_T
Definition: sch_screen.h:52
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
Definition: base_screen.h:74
void MarkConnections(SCH_LINE *aSegment)
Add all wires and junctions connected to aSegment which are not connected any component pin to aItemL...
Definition: sch_screen.cpp:305
const wxSize & GetTextSize() const
Definition: eda_text.h:221
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
Definition: sch_screen.cpp:234
void Clear()
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:172
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
timestamp_t GetTimeStamp() const
Definition: base_struct.h:216
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:129
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
bool HasSchematic(const wxString &aSchematicFileName)
Check if one of the schematics in the list of screens is aSchematicFileName.
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:97
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_field.cpp:396
SCH_SHEET_PIN * GetSheetLabel(const wxPoint &aPosition)
Test the screen if aPosition is a sheet label object.
Definition: sch_screen.cpp:693
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:83
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:75
bool HasNoFullyDefinedLibIds()
Test all of the schematic symbols to see if all LIB_ID objects library nickname is not set.
SCH_LINE * GetWire(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:408
virtual bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
Definition: base_screen.cpp:86
Class SCH_SHEET_PATH.
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear exiting component annotation.
int GetConvert() const
Definition: lib_item.h:304
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
int GetFieldCount() const
Return the number of fields in this symbol.
void FreeDrawList()
Free all the items from the schematic associated with the screen.
Definition: sch_screen.cpp:183
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:204
void Plot(PLOTTER *aPlotter)
Plot all the schematic objects to aPlotter.
Definition: sch_screen.cpp:550
int GetMarkerCount(enum MARKER_BASE::TYPEMARKER aMarkerType, enum MARKER_BASE::MARKER_SEVERITY aSeverity)
Return the number of ERC markers of aMarkerType from all of the screens in the list.
int SetLibNickname(const UTF8 &aNickname)
Override the logical library name portion of the LIB_ID to aNickname.
Definition: lib_id.cpp:193
DLIST< SCH_ITEM > m_drawList
Object list for the screen.
Definition: sch_screen.h:89
void buildScreenList(SCH_SHEET *aSheet)
void DecRefCount()
Definition: sch_screen.cpp:150
Base plotter engine class.
Definition: plotter.h:97
void addScreenToList(SCH_SCREEN *aScreen)
bool IsTerminalPoint(const wxPoint &aPosition, int aLayer)
Test if aPosition is a connection point on aLayer.
Definition: sch_screen.cpp:427
see class PGM_BASE
void UpdateSymbolLinks(bool aForce=false)
Initialize or reinitialize the weak reference to the LIB_PART for each SCH_COMPONENT found in the ful...
void TestDanglingEnds()
SCH_TEXT * GetLabel(const wxPoint &aPosition, int aAccuracy=0)
Return a label item located at aPosition.
Definition: sch_screen.cpp:850
void AddBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
Adds a bus alias definition (and transfers ownership of the pointer)
Definition: sch_screen.cpp:917
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
std::vector< SCH_SCREEN * > m_screens
Definition: sch_screen.h:489
Class GRID_TYPE is for grid arrays.
Definition: base_screen.h:43
void Append(SCH_ITEM *aItem)
Definition: sch_screen.h:149
void ClearAnnotation()
Clear the annotation for all components in the hierarchy.
enum TYPEMARKER GetMarkerType() const
Definition: marker_base.h:187
#define max(a, b)
Definition: auxiliary.h:86
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Class EE_TYPE_COLLECTOR merely gathers up all SCH_ITEMs of a given set of KICAD_T type(s).
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
Definition: sch_screen.cpp:781
std::unordered_set< std::shared_ptr< BUS_ALIAS > > m_aliases
List of bus aliases stored in this screen.
Definition: sch_screen.h:95
size_t i
Definition: json11.cpp:597
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
wxPoint GetPosition() const override
Function GetPosition.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
The common library.
SCH_LINE * GetWireOrBus(const wxPoint &aPosition)
Return a wire or bus item located at aPosition.
Definition: sch_screen.cpp:802
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:266
int m_NumberOfScreens
Definition: base_screen.h:136
const wxPoint & GetTextPos() const
Definition: eda_text.h:230
void SetOwnership(bool Iown)
Function SetOwnership controls whether the list owns the objects and is responsible for deleteing the...
Definition: dlist.h:119
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear the annotation for the components in aSheetPath on the screen.
Definition: sch_screen.cpp:731
int ReplaceDuplicateTimeStamps()
Test all sheet and component objects in the schematic for duplicate time stamps and replaces them as ...
void ReplaceWires(DLIST< SCH_ITEM > &aWireList)
Replace all of the wires, buses, and junctions in the screen with aWireList.
Definition: sch_screen.cpp:279
boost::ptr_vector< WIRE > WIRES
Definition: specctra.h:2950
static bool IsBusAlias(const wxString &aLabel)
Returns true if the given string is a valid bus alias in a loaded screen.
Definition: sch_screen.cpp:923
int GetConvert() const
void Print(wxDC *aDC)
Print all the items in the screen to aDC.
Definition: sch_screen.cpp:527
SCH_SCREEN * GetFirst()
SCH_SCREEN * GetScreen(unsigned int aIndex) const
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:613
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Free the undo or redo list from aList element.
Definition: sch_screen.cpp:598
Definition for part library class.
void ClearAnnotationOfNewSheetPaths(SCH_SHEET_LIST &aInitialSheetPathList)
Clear the annotation for the components inside new sheetpaths when a complex hierarchy is modified an...
void SetModify()
Definition: base_screen.h:224
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
Definition of the NETLIST_OBJECT class.
bool CheckIfOnDrawList(SCH_ITEM *st)
Definition: sch_screen.cpp:218
const LIB_ID & GetLibId() const
wxPoint GetPinPhysicalPosition(const LIB_PIN *Pin) const
size_t GetLibNicknames(wxArrayString &aLibNicknames)
Fetch all of the symbol library nickames into aLibNicknames.
static bool SortByTimeStamp(const EDA_ITEM *item1, const EDA_ITEM *item2)
Sort a list of schematic items by time stamp and type.
Definition: sch_screen.cpp:978
static void ResolveAll(const EE_COLLECTOR &aComponents, SYMBOL_LIB_TABLE &aLibTable, PART_LIB *aCacheLib=NULL)
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
Definitions of the SCH_TEXT class and derivatives for Eeschema.
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
bool IsConnected(const wxPoint &aPoint) const
Function IsConnected tests the item to see if it is connected to aPoint.
Definition: sch_item.cpp:119
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:486
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
Definition: base_screen.h:138
wxArrayString m_clientSheetPathList
the list of scheet paths sharing this screen used in some annotation calculations to update alternate...
Definition: sch_screen.h:79
void IncRefCount()
Definition: sch_screen.cpp:144
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
bool empty() const
Definition: utf8.h:108
virtual wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_screen.h:108
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
bool SetComponentFootprint(SCH_SHEET_PATH *aSheetPath, const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
Search this screen for a symbol with aReference and set the footprint field to aFootPrint if found.
Definition: sch_screen.cpp:871
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Definition: sch_screen.h:414
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:147
wxPoint GetEndPoint() const
Definition: sch_line.h:93