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-2016 Wayne Stambaugh <stambaughw@verizon.net>
7  * Copyright (C) 1992-2016 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 <class_drawpanel.h>
40 #include <sch_item_struct.h>
41 #include <schframe.h>
42 #include <plot_common.h>
43 
44 #include <netlist.h>
45 #include <class_netlist_object.h>
46 #include <class_library.h>
47 #include <sch_junction.h>
48 #include <sch_bus_entry.h>
49 #include <sch_line.h>
50 #include <sch_marker.h>
51 #include <sch_no_connect.h>
52 #include <sch_sheet.h>
53 #include <sch_component.h>
54 #include <sch_text.h>
55 #include <lib_pin.h>
56 
57 
58 #define EESCHEMA_FILE_STAMP "EESchema"
59 
60 /* Default zoom values. Limited to these values to keep a decent size
61  * to menus
62  */
63 static double SchematicZoomList[] =
64 {
65  0.5, 0.7, 1.0, 1.5, 2.0, 3.0, 4.0, 6.0, 8.0, 11.0,
66  13.0, 16.0, 20.0, 26.0, 32.0, 48.0, 64.0, 80.0, 128.0
67 };
68 
69 #define MM_TO_SCH_UNITS 1000.0 / 25.4 //schematic internal unites are mils
70 
71 
72 /* Default grid sizes for the schematic editor.
73  * Do NOT add others values (mainly grid values in mm), because they
74  * can break the schematic: Because wires and pins are considered as
75  * connected when the are to the same coordinate we cannot mix
76  * coordinates in mils (internal units) and mm (that cannot exactly
77  * converted in mils in many cases). In fact schematic must only use
78  * 50 and 25 mils to place labels, wires and components others values
79  * are useful only for graphic items (mainly in library editor) so use
80  * integer values in mils only. The 100 mil grid is added to help
81  * conform to the KiCad Library Convention. Which states: "Using a
82  * 100mil grid, pin ends and origin must lie on grid nodes IEC-60617"
83 */
85  { ID_POPUP_GRID_LEVEL_100, wxRealPoint( 100, 100 ) },
86  { ID_POPUP_GRID_LEVEL_50, wxRealPoint( 50, 50 ) },
87  { ID_POPUP_GRID_LEVEL_25, wxRealPoint( 25, 25 ) },
88  { ID_POPUP_GRID_LEVEL_10, wxRealPoint( 10, 10 ) },
89  { ID_POPUP_GRID_LEVEL_5, wxRealPoint( 5, 5 ) },
90  { ID_POPUP_GRID_LEVEL_2, wxRealPoint( 2, 2 ) },
91  { ID_POPUP_GRID_LEVEL_1, wxRealPoint( 1, 1 ) },
92 };
93 
94 
97  KIWAY_HOLDER( aKiway ),
98  m_paper( wxT( "A4" ) )
99 {
101 
102  SetZoom( 32 );
103 
104  for( unsigned i = 0; i < DIM( SchematicZoomList ); i++ )
105  m_ZoomList.push_back( SchematicZoomList[i] );
106 
107  for( unsigned i = 0; i < DIM( SchematicGridList ); i++ )
108  AddGrid( SchematicGridList[i] );
109 
110  SetGrid( wxRealPoint( 50, 50 ) ); // Default grid size.
111  m_refCount = 0;
112 
113  // Suitable for schematic only. For libedit and viewlib, must be set to true
114  m_Center = false;
115 
116  InitDataPoints( m_paper.GetSizeIU() );
117 }
118 
119 
121 {
123  FreeDrawList();
124 }
125 
126 
128 {
129  m_refCount++;
130 }
131 
132 
134 {
135  wxCHECK_RET( m_refCount != 0,
136  wxT( "Screen reference count already zero. Bad programmer!" ) );
137  m_refCount--;
138 }
139 
140 
142 {
143  FreeDrawList();
144 
145  // Clear the project settings
147 
148  m_titles.Clear();
149 }
150 
151 
153 {
155 }
156 
157 
159 {
160  m_drawList.Remove( aItem );
161 }
162 
163 
165 {
166  wxCHECK_RET( aItem, wxT( "Cannot delete invalid item from screen." ) );
167 
168  SetModify();
169 
170  if( aItem->Type() == SCH_SHEET_PIN_T )
171  {
172  // This structure is attached to a sheet, get the parent sheet object.
173  SCH_SHEET_PIN* sheetPin = (SCH_SHEET_PIN*) aItem;
174  SCH_SHEET* sheet = sheetPin->GetParent();
175  wxCHECK_RET( sheet,
176  wxT( "Sheet label parent not properly set, bad programmer!" ) );
177  sheet->RemovePin( sheetPin );
178  return;
179  }
180  else
181  {
182  delete m_drawList.Remove( aItem );
183  }
184 }
185 
186 
188 {
189  SCH_ITEM* itemList = m_drawList.begin();
190 
191  while( itemList )
192  {
193  if( itemList == aItem )
194  return true;
195 
196  itemList = itemList->Next();
197  }
198 
199  return false;
200 }
201 
202 
203 SCH_ITEM* SCH_SCREEN::GetItem( const wxPoint& aPosition, int aAccuracy, KICAD_T aType ) const
204 {
205  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
206  {
207  if( item->HitTest( aPosition, aAccuracy ) && (aType == NOT_USED) )
208  return item;
209 
210  if( (aType == SCH_FIELD_T) && (item->Type() == SCH_COMPONENT_T) )
211  {
212  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
213 
214  for( int i = REFERENCE; i < component->GetFieldCount(); i++ )
215  {
216  SCH_FIELD* field = component->GetField( i );
217 
218  if( field->HitTest( aPosition, aAccuracy ) )
219  return (SCH_ITEM*) field;
220  }
221  }
222  else if( (aType == SCH_SHEET_PIN_T) && (item->Type() == SCH_SHEET_T) )
223  {
224  SCH_SHEET* sheet = (SCH_SHEET*)item;
225 
226  SCH_SHEET_PIN* label = sheet->GetPin( aPosition );
227 
228  if( label )
229  return (SCH_ITEM*) label;
230  }
231  else if( (item->Type() == aType) && item->HitTest( aPosition, aAccuracy ) )
232  {
233  return item;
234  }
235  }
236 
237  return NULL;
238 }
239 
240 
241 void SCH_SCREEN::ExtractWires( DLIST< SCH_ITEM >& aList, bool aCreateCopy )
242 {
243  SCH_ITEM* item;
244  SCH_ITEM* next_item;
245 
246  for( item = m_drawList.begin(); item; item = next_item )
247  {
248  next_item = item->Next();
249 
250  switch( item->Type() )
251  {
252  case SCH_JUNCTION_T:
253  case SCH_LINE_T:
254  m_drawList.Remove( item );
255  aList.Append( item );
256 
257  if( aCreateCopy )
258  m_drawList.Insert( (SCH_ITEM*) item->Clone(), next_item );
259 
260  break;
261 
262  default:
263  break;
264  }
265  }
266 }
267 
268 
270 {
271  SCH_ITEM* item;
272  SCH_ITEM* next_item;
273 
274  for( item = m_drawList.begin(); item; item = next_item )
275  {
276  next_item = item->Next();
277 
278  switch( item->Type() )
279  {
280  case SCH_JUNCTION_T:
281  case SCH_LINE_T:
282  Remove( item );
283  delete item;
284  break;
285 
286  default:
287  break;
288  }
289  }
290 
291  m_drawList.Append( aWireList );
292 }
293 
294 
296 {
297  wxCHECK_RET( (aSegment) && (aSegment->Type() == SCH_LINE_T),
298  wxT( "Invalid object pointer." ) );
299 
300  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
301  {
302  if( item->GetFlags() & CANDIDATE )
303  continue;
304 
305  if( item->Type() == SCH_JUNCTION_T )
306  {
307  SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
308 
309  if( aSegment->IsEndPoint( junction->GetPosition() ) )
310  item->SetFlags( CANDIDATE );
311 
312  continue;
313  }
314 
315  if( item->Type() != SCH_LINE_T )
316  continue;
317 
318  SCH_LINE* segment = (SCH_LINE*) item;
319 
320  if( aSegment->IsEndPoint( segment->GetStartPoint() )
321  && !GetPin( segment->GetStartPoint(), NULL, true ) )
322  {
323  item->SetFlags( CANDIDATE );
324  MarkConnections( segment );
325  }
326 
327  if( aSegment->IsEndPoint( segment->GetEndPoint() )
328  && !GetPin( segment->GetEndPoint(), NULL, true ) )
329  {
330  item->SetFlags( CANDIDATE );
331  MarkConnections( segment );
332  }
333  }
334 }
335 
336 
337 bool SCH_SCREEN::IsJunctionNeeded( const wxPoint& aPosition )
338 {
339  if( GetItem( aPosition, 0, SCH_JUNCTION_T ) )
340  return false;
341 
342  if( GetWire( aPosition, 0, EXCLUDE_END_POINTS_T ) )
343  {
344  if( GetWire( aPosition, 0, END_POINTS_ONLY_T ) )
345  return true;
346 
347  if( GetPin( aPosition, NULL, true ) )
348  return true;
349  }
350 
351  return false;
352 }
353 
354 
355 bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer )
356 {
357  wxCHECK_MSG( aLayer == LAYER_NOTES || aLayer == LAYER_BUS || aLayer == LAYER_WIRE, false,
358  wxT( "Invalid layer type passed to SCH_SCREEN::IsTerminalPoint()." ) );
359 
360  SCH_SHEET_PIN* label;
361  SCH_TEXT* text;
362 
363  switch( aLayer )
364  {
365  case LAYER_BUS:
366 
367  if( GetBus( aPosition ) )
368  return true;
369 
370  label = GetSheetLabel( aPosition );
371 
372  if( label && IsBusLabel( label->GetText() ) && label->IsConnected( aPosition ) )
373  return true;
374 
375  text = GetLabel( aPosition );
376 
377  if( text && IsBusLabel( text->GetText() ) && text->IsConnected( aPosition )
378  && (text->Type() != SCH_LABEL_T) )
379  return true;
380 
381  break;
382 
383  case LAYER_NOTES:
384 
385  if( GetLine( aPosition ) )
386  return true;
387 
388  break;
389 
390  case LAYER_WIRE:
392  return true;
393 
394  if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_BUS_BUS_ENTRY_T) )
395  return true;
396 
397  if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_JUNCTION_T ) )
398  return true;
399 
400  if( GetPin( aPosition, NULL, true ) )
401  return true;
402 
403  if( GetWire( aPosition ) )
404  return true;
405 
406  text = GetLabel( aPosition );
407 
408  if( text && text->IsConnected( aPosition ) && !IsBusLabel( text->GetText() ) )
409  return true;
410 
411  label = GetSheetLabel( aPosition );
412 
413  if( label && label->IsConnected( aPosition ) && !IsBusLabel( label->GetText() ) )
414  return true;
415 
416  break;
417 
418  default:
419  break;
420  }
421 
422  return false;
423 }
424 
425 
427 {
428  bool modified = false;
429 
430  for( SCH_ITEM* item = m_drawList.begin() ; item; item = item->Next() )
431  {
432  if( ( item->Type() != SCH_LINE_T ) && ( item->Type() != SCH_JUNCTION_T ) )
433  continue;
434 
435  bool restart;
436 
437  for( SCH_ITEM* testItem = item->Next(); testItem; testItem = restart ? m_drawList.begin() : testItem->Next() )
438  {
439  restart = false;
440 
441  if( ( item->Type() == SCH_LINE_T ) && ( testItem->Type() == SCH_LINE_T ) )
442  {
443  SCH_LINE* line = (SCH_LINE*) item;
444 
445  if( line->MergeOverlap( (SCH_LINE*) testItem ) )
446  {
447  // Keep the current flags, because the deleted segment can be flagged.
448  item->SetFlags( testItem->GetFlags() );
449  DeleteItem( testItem );
450  restart = true;
451  modified = true;
452  }
453  }
454  else if ( ( ( item->Type() == SCH_JUNCTION_T )
455  && ( testItem->Type() == SCH_JUNCTION_T ) ) && ( testItem != item ) )
456  {
457  if ( testItem->HitTest( item->GetPosition() ) )
458  {
459  // Keep the current flags, because the deleted segment can be flagged.
460  item->SetFlags( testItem->GetFlags() );
461  DeleteItem( testItem );
462  restart = true;
463  modified = true;
464  }
465  }
466  }
467  }
468 
470 
471  return modified;
472 }
473 
474 
475 bool SCH_SCREEN::Save( FILE* aFile ) const
476 {
477  // Creates header
478  if( fprintf( aFile, "%s %s %d\n", EESCHEMA_FILE_STAMP,
480  return false;
481 
482  for( const PART_LIB& lib : *Prj().SchLibs() )
483  {
484  if( fprintf( aFile, "LIBS:%s\n", TO_UTF8( lib.GetName() ) ) < 0 )
485  return false;
486  }
487 
488  // This section is not used, but written for file compatibility
489  if( fprintf( aFile, "EELAYER %d %d\n", SCH_LAYER_ID_COUNT, 0 ) < 0
490  || fprintf( aFile, "EELAYER END\n" ) < 0 )
491  return false;
492 
493  /* Write page info, ScreenNumber and NumberOfScreen; not very meaningful for
494  * SheetNumber and Sheet Count in a complex hierarchy, but useful in
495  * simple hierarchy and flat hierarchy. Used also to search the root
496  * sheet ( ScreenNumber = 1 ) within the files
497  */
498  const TITLE_BLOCK& tb = GetTitleBlock();
499 
500  if( fprintf( aFile, "$Descr %s %d %d%s\n", TO_UTF8( m_paper.GetType() ),
504  " portrait" : ""
505  ) < 0
506  || fprintf( aFile, "encoding utf-8\n") < 0
507  || fprintf( aFile, "Sheet %d %d\n", m_ScreenNumber, m_NumberOfScreens ) < 0
508  || fprintf( aFile, "Title %s\n", EscapedUTF8( tb.GetTitle() ).c_str() ) < 0
509  || fprintf( aFile, "Date %s\n", EscapedUTF8( tb.GetDate() ).c_str() ) < 0
510  || fprintf( aFile, "Rev %s\n", EscapedUTF8( tb.GetRevision() ).c_str() ) < 0
511  || fprintf( aFile, "Comp %s\n", EscapedUTF8( tb.GetCompany() ).c_str() ) < 0
512  || fprintf( aFile, "Comment1 %s\n", EscapedUTF8( tb.GetComment1() ).c_str() ) < 0
513  || fprintf( aFile, "Comment2 %s\n", EscapedUTF8( tb.GetComment2() ).c_str() ) < 0
514  || fprintf( aFile, "Comment3 %s\n", EscapedUTF8( tb.GetComment3() ).c_str() ) < 0
515  || fprintf( aFile, "Comment4 %s\n", EscapedUTF8( tb.GetComment4() ).c_str() ) < 0
516  || fprintf( aFile, "$EndDescr\n" ) < 0 )
517  return false;
518 
519  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
520  {
521  if( !item->Save( aFile ) )
522  return false;
523  }
524 
525  if( fprintf( aFile, "$EndSCHEMATC\n" ) < 0 )
526  return false;
527 
528  return true;
529 }
530 
531 
533 {
534  // Initialize or reinitialize the pointer to the LIB_PART for each component
535  // found in m_drawList, but only if needed (change in lib or schematic)
536  // therefore the calculation time is usually very low.
537 
538  if( m_drawList.GetCount() )
539  {
540  PART_LIBS* libs = Prj().SchLibs();
541  int mod_hash = libs->GetModifyHash();
542 
543  // Must we resolve?
544  if( m_modification_sync != mod_hash )
545  {
547 
549 
550  SCH_COMPONENT::ResolveAll( c, libs );
551 
552  m_modification_sync = mod_hash; // note the last mod_hash
553  }
554  }
555 }
556 
557 
558 void SCH_SCREEN::Draw( EDA_DRAW_PANEL* aCanvas, wxDC* aDC, GR_DRAWMODE aDrawMode, COLOR4D aColor )
559 {
560  /* note: SCH_SCREEN::Draw is useful only for schematic.
561  * library editor and library viewer do not use m_drawList, and therefore
562  * their SCH_SCREEN::Draw() draws nothing
563  */
564 
565  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
566  {
567  if( item->IsMoving() || item->IsResized() )
568  continue;
569 
570  // uncomment line below when there is a virtual
571  // EDA_ITEM::GetBoundingBox()
572  // if( panel->GetClipBox().Intersects( Structs->GetBoundingBox()
573  // ) )
574  item->Draw( aCanvas, aDC, wxPoint( 0, 0 ), aDrawMode, aColor );
575  }
576 }
577 
578 
579 /* note: SCH_SCREEN::Plot is useful only for schematic.
580  * library editor and library viewer do not use a draw list, and therefore
581  * SCH_SCREEN::Plot plots nothing
582  */
583 void SCH_SCREEN::Plot( PLOTTER* aPlotter )
584 {
585  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
586  {
587  aPlotter->SetCurrentLineWidth( item->GetPenSize() );
588  item->Plot( aPlotter );
589  }
590 }
591 
592 
594 {
595  if( aItemCount == 0 )
596  return;
597 
598  unsigned icnt = aList.m_CommandsList.size();
599 
600  if( aItemCount > 0 )
601  icnt = aItemCount;
602 
603  for( unsigned ii = 0; ii < icnt; ii++ )
604  {
605  if( aList.m_CommandsList.size() == 0 )
606  break;
607 
608  PICKED_ITEMS_LIST* curr_cmd = aList.m_CommandsList[0];
609  aList.m_CommandsList.erase( aList.m_CommandsList.begin() );
610 
611  curr_cmd->ClearListAndDeleteItems();
612  delete curr_cmd; // Delete command
613  }
614 }
615 
616 
618 {
619  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
620  item->ClearFlags();
621 }
622 
623 
624 LIB_PIN* SCH_SCREEN::GetPin( const wxPoint& aPosition, SCH_COMPONENT** aComponent,
625  bool aEndPointOnly ) const
626 {
627  SCH_ITEM* item;
628  SCH_COMPONENT* component = NULL;
629  LIB_PIN* pin = NULL;
630 
631  for( item = m_drawList.begin(); item; item = item->Next() )
632  {
633  if( item->Type() != SCH_COMPONENT_T )
634  continue;
635 
636  component = (SCH_COMPONENT*) item;
637 
638  if( aEndPointOnly )
639  {
640  pin = NULL;
641 
642  auto part = component->GetPartRef().lock();
643 
644  if( !part )
645  continue;
646 
647  for( pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) )
648  {
649  // Skip items not used for this part.
650  if( component->GetUnit() && pin->GetUnit() &&
651  ( pin->GetUnit() != component->GetUnit() ) )
652  continue;
653 
654  if( component->GetConvert() && pin->GetConvert() &&
655  ( pin->GetConvert() != component->GetConvert() ) )
656  continue;
657 
658  if(component->GetPinPhysicalPosition( pin ) == aPosition )
659  break;
660  }
661  if( pin )
662  break;
663  }
664  else
665  {
666  pin = (LIB_PIN*) component->GetDrawItem( aPosition, LIB_PIN_T );
667 
668  if( pin )
669  break;
670  }
671  }
672 
673  if( pin && aComponent )
674  *aComponent = component;
675 
676  return pin;
677 }
678 
679 
680 SCH_SHEET* SCH_SCREEN::GetSheet( const wxString& aName )
681 {
682  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
683  {
684  if( item->Type() != SCH_SHEET_T )
685  continue;
686 
687  SCH_SHEET* sheet = (SCH_SHEET*) item;
688 
689  if( aName.CmpNoCase( sheet->GetName() ) == 0 )
690  return sheet;
691  }
692 
693  return NULL;
694 }
695 
696 
698 {
699  SCH_SHEET_PIN* sheetPin = NULL;
700 
701  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
702  {
703  if( item->Type() != SCH_SHEET_T )
704  continue;
705 
706  SCH_SHEET* sheet = (SCH_SHEET*) item;
707  sheetPin = sheet->GetPin( aPosition );
708 
709  if( sheetPin )
710  break;
711  }
712 
713  return sheetPin;
714 }
715 
716 
717 int SCH_SCREEN::CountConnectedItems( const wxPoint& aPos, bool aTestJunctions ) const
718 {
719  SCH_ITEM* item;
720  int count = 0;
721 
722  for( item = m_drawList.begin(); item; item = item->Next() )
723  {
724  if( item->Type() == SCH_JUNCTION_T && !aTestJunctions )
725  continue;
726 
727  if( item->IsConnected( aPos ) )
728  count++;
729  }
730 
731  return count;
732 }
733 
734 
736 {
737  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
738  {
739  if( item->Type() == SCH_COMPONENT_T )
740  {
741  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
742 
743  component->ClearAnnotation( aSheetPath );
744 
745  // Clear the modified component flag set by component->ClearAnnotation
746  // because we do not use it here and we should not leave this flag set,
747  // when an edition is finished:
748  component->ClearFlags();
749  }
750  }
751 }
752 
753 
755 {
756  SCH_ITEM* item = m_drawList.begin();
757 
758  while( item )
759  {
760  if( ( item->Type() == SCH_SHEET_T ) || ( item->Type() == SCH_COMPONENT_T ) )
761  aItems.push_back( item );
762 
763  item = item->Next();
764  }
765 }
766 
767 
769 {
770  PICKED_ITEMS_LIST* pickedlist = &m_BlockLocate.GetItems();
771 
772  if( pickedlist->GetCount() == 0 )
773  return;
774 
776 
777  for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
778  {
779  SCH_ITEM* item = (SCH_ITEM*) pickedlist->GetPickedItem( ii );
780  item->SetFlags( SELECTED );
781  }
782 
783  if( !m_BlockLocate.IsDragging() )
784  return;
785 
786  // Select all the items in the screen connected to the items in the block.
787  // be sure end lines that are on the block limits are seen inside this block
788  m_BlockLocate.Inflate( 1 );
789  unsigned last_select_id = pickedlist->GetCount();
790 
791  for( unsigned ii = 0; ii < last_select_id; ii++ )
792  {
793  SCH_ITEM* item = (SCH_ITEM*)pickedlist->GetPickedItem( ii );
794  item->SetFlags( IS_DRAGGED );
795 
796  if( item->Type() == SCH_LINE_T )
797  {
799 
800  if( !item->IsSelected() )
801  { // This is a special case:
802  // this selected wire has no ends in block.
803  // But it was selected (because it intersects the selecting area),
804  // so we must keep it selected and select items connected to it
805  // Note: an other option could be: remove it from drag list
806  item->SetFlags( SELECTED | SKIP_STRUCT );
807  std::vector< wxPoint > connections;
808  item->GetConnectionPoints( connections );
809 
810  for( size_t i = 0; i < connections.size(); i++ )
811  addConnectedItemsToBlock( connections[i] );
812  }
813 
814  pickedlist->SetPickerFlags( item->GetFlags(), ii );
815  }
816  else if( item->IsConnectable() )
817  {
818  std::vector< wxPoint > connections;
819 
820  item->GetConnectionPoints( connections );
821 
822  for( size_t jj = 0; jj < connections.size(); jj++ )
823  addConnectedItemsToBlock( connections[jj] );
824  }
825  }
826 
827  m_BlockLocate.Inflate( -1 );
828 }
829 
830 
832 {
833  SCH_ITEM* item;
834  ITEM_PICKER picker;
835  bool addinlist = true;
836 
837  for( item = m_drawList.begin(); item; item = item->Next() )
838  {
839  picker.SetItem( item );
840 
841  if( !item->IsConnectable() || !item->IsConnected( position )
842  || (item->GetFlags() & SKIP_STRUCT) )
843  continue;
844 
845  if( item->IsSelected() && item->Type() != SCH_LINE_T )
846  continue;
847 
848  // A line having 2 ends, it can be tested twice: one time per end
849  if( item->Type() == SCH_LINE_T )
850  {
851  if( ! item->IsSelected() ) // First time this line is tested
852  item->SetFlags( SELECTED | STARTPOINT | ENDPOINT );
853  else // second time (or more) this line is tested
854  addinlist = false;
855 
856  SCH_LINE* line = (SCH_LINE*) item;
857 
858  if( line->GetStartPoint() == position )
859  item->ClearFlags( STARTPOINT );
860  else if( line->GetEndPoint() == position )
861  item->ClearFlags( ENDPOINT );
862  }
863  else
864  item->SetFlags( SELECTED );
865 
866  if( addinlist )
867  {
868  picker.SetFlags( item->GetFlags() );
869  m_BlockLocate.GetItems().PushItem( picker );
870  }
871  }
872 }
873 
874 
876 {
877  ITEM_PICKER picker;
878  EDA_RECT area;
879  unsigned count;
880 
882  area.SetSize( m_BlockLocate.GetSize() );
883  area.Normalize();
884 
885  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
886  {
887  // An item is picked if its bounding box intersects the reference area.
888  if( item->HitTest( area ) )
889  {
890  picker.SetItem( item );
891  m_BlockLocate.PushItem( picker );
892  }
893  }
894 
895  // if the block is composed of one item,
896  // select it as the current item
897  count = m_BlockLocate.GetCount();
898  if( count == 1 )
899  {
901  }
902  else
903  {
904  SetCurItem( NULL );
905  }
906 
907  return count;
908 }
909 
910 
912 {
913  SCH_ITEM* item;
914  std::vector< DANGLING_END_ITEM > endPoints;
915  bool hasStateChanged = false;
916 
917  for( item = m_drawList.begin(); item; item = item->Next() )
918  item->GetEndPoints( endPoints );
919 
920  for( item = m_drawList.begin(); item; item = item->Next() )
921  {
922  if( item->IsDanglingStateChanged( endPoints ) )
923  {
924  hasStateChanged = true;
925  }
926  }
927 
928  return hasStateChanged;
929 }
930 
931 
932 bool SCH_SCREEN::BreakSegment( const wxPoint& aPoint )
933 {
934  SCH_LINE* segment;
935  SCH_LINE* newSegment;
936  bool brokenSegments = false;
937 
938  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
939  {
940  if( (item->Type() != SCH_LINE_T) || (item->GetLayer() == LAYER_NOTES) )
941  continue;
942 
943  segment = (SCH_LINE*) item;
944 
945  if( !segment->HitTest( aPoint, 0 ) || segment->IsEndPoint( aPoint ) )
946  continue;
947 
948  // Break the segment at aPoint and create a new segment.
949  newSegment = new SCH_LINE( *segment );
950  newSegment->SetStartPoint( aPoint );
951  segment->SetEndPoint( aPoint );
952  m_drawList.Insert( newSegment, segment->Next() );
953  item = newSegment;
954  brokenSegments = true;
955  }
956 
957  return brokenSegments;
958 }
959 
960 
962 {
963  bool brokenSegments = false;
964 
965  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
966  {
967  if( item->Type() == SCH_JUNCTION_T )
968  {
969  SCH_JUNCTION* junction = ( SCH_JUNCTION* ) item;
970 
971  if( BreakSegment( junction->GetPosition() ) )
972  brokenSegments = true;
973  }
974  else
975  {
976  SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast<SCH_BUS_ENTRY_BASE*>( item );
977  if( busEntry )
978  {
979  if( BreakSegment( busEntry->GetPosition() )
980  || BreakSegment( busEntry->m_End() ) )
981  brokenSegments = true;
982  }
983  }
984  }
985 
986  return brokenSegments;
987 }
988 
989 
990 int SCH_SCREEN::GetNode( const wxPoint& aPosition, EDA_ITEMS& aList )
991 {
992  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
993  {
994  if( item->Type() == SCH_LINE_T && item->HitTest( aPosition )
995  && (item->GetLayer() == LAYER_BUS || item->GetLayer() == LAYER_WIRE) )
996  {
997  aList.push_back( item );
998  }
999  else if( item->Type() == SCH_JUNCTION_T && item->HitTest( aPosition ) )
1000  {
1001  aList.push_back( item );
1002  }
1003  }
1004 
1005  return (int) aList.size();
1006 }
1007 
1008 
1010 {
1011  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
1012  {
1013  if( (item->Type() == SCH_LINE_T) && item->HitTest( aPosition )
1014  && (item->GetLayer() == LAYER_BUS || item->GetLayer() == LAYER_WIRE) )
1015  {
1016  return (SCH_LINE*) item;
1017  }
1018  }
1019 
1020  return NULL;
1021 }
1022 
1023 
1024 SCH_LINE* SCH_SCREEN::GetLine( const wxPoint& aPosition, int aAccuracy, int aLayer,
1025  SCH_LINE_TEST_T aSearchType )
1026 {
1027  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
1028  {
1029  if( item->Type() != SCH_LINE_T )
1030  continue;
1031 
1032  if( item->GetLayer() != aLayer )
1033  continue;
1034 
1035  if( !item->HitTest( aPosition, aAccuracy ) )
1036  continue;
1037 
1038  switch( aSearchType )
1039  {
1040  case ENTIRE_LENGTH_T:
1041  return (SCH_LINE*) item;
1042 
1043  case EXCLUDE_END_POINTS_T:
1044  if( !( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
1045  return (SCH_LINE*) item;
1046  break;
1047 
1048  case END_POINTS_ONLY_T:
1049  if( ( (SCH_LINE*) item )->IsEndPoint( aPosition ) )
1050  return (SCH_LINE*) item;
1051  }
1052  }
1053 
1054  return NULL;
1055 }
1056 
1057 
1058 SCH_TEXT* SCH_SCREEN::GetLabel( const wxPoint& aPosition, int aAccuracy )
1059 {
1060  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
1061  {
1062  switch( item->Type() )
1063  {
1064  case SCH_LABEL_T:
1065  case SCH_GLOBAL_LABEL_T:
1067  if( item->HitTest( aPosition, aAccuracy ) )
1068  return (SCH_TEXT*) item;
1069 
1070  default:
1071  ;
1072  }
1073  }
1074 
1075  return NULL;
1076 }
1077 
1078 
1079 bool SCH_SCREEN::SetComponentFootprint( SCH_SHEET_PATH* aSheetPath, const wxString& aReference,
1080  const wxString& aFootPrint, bool aSetVisible )
1081 {
1082  SCH_COMPONENT* component;
1083  bool found = false;
1084 
1085  for( SCH_ITEM* item = m_drawList.begin(); item; item = item->Next() )
1086  {
1087  if( item->Type() != SCH_COMPONENT_T )
1088  continue;
1089 
1090  component = (SCH_COMPONENT*) item;
1091 
1092  if( aReference.CmpNoCase( component->GetRef( aSheetPath ) ) == 0 )
1093  {
1094  // Found: Init Footprint Field
1095 
1096  /* Give a reasonable value to the field position and
1097  * orientation, if the text is empty at position 0, because
1098  * it is probably not yet initialized
1099  */
1100  SCH_FIELD * fpfield = component->GetField( FOOTPRINT );
1101  if( fpfield->GetText().IsEmpty()
1102  && ( fpfield->GetTextPos() == component->GetPosition() ) )
1103  {
1104  fpfield->SetTextAngle( component->GetField( VALUE )->GetTextAngle() );
1105  fpfield->SetTextPos( component->GetField( VALUE )->GetTextPos() );
1106  fpfield->SetTextSize( component->GetField( VALUE )->GetTextSize() );
1107 
1108  if( fpfield->GetTextAngle() == 0.0 )
1109  fpfield->Offset( wxPoint( 0, 100 ) );
1110  else
1111  fpfield->Offset( wxPoint( 100, 0 ) );
1112  }
1113 
1114  fpfield->SetText( aFootPrint );
1115  fpfield->SetVisible( aSetVisible );
1116 
1117  found = true;
1118  }
1119  }
1120 
1121  return found;
1122 }
1123 
1124 
1126  bool aFullConnection )
1127 {
1128  SCH_ITEM* item;
1129  EDA_ITEM* tmp;
1130  EDA_ITEMS list;
1131 
1132  // Clear flags member for all items.
1135 
1136  if( GetNode( aPosition, list ) == 0 )
1137  return 0;
1138 
1139  for( size_t i = 0; i < list.size(); i++ )
1140  {
1141  item = (SCH_ITEM*) list[ i ];
1143 
1144  /* Put this structure in the picked list: */
1145  ITEM_PICKER picker( item, UR_DELETED );
1146  aList.PushItem( picker );
1147  }
1148 
1149  // Mark all wires, junctions, .. connected to the item(s) found.
1150  if( aFullConnection )
1151  {
1152  SCH_LINE* segment;
1153 
1154  for( item = m_drawList.begin(); item; item = item->Next() )
1155  {
1156  if( !(item->GetFlags() & SELECTEDNODE) )
1157  continue;
1158 
1159  if( item->Type() != SCH_LINE_T )
1160  continue;
1161 
1162  MarkConnections( (SCH_LINE*) item );
1163  }
1164 
1165  // Search all attached wires (i.e wire with one new dangling end )
1166  for( item = m_drawList.begin(); item; item = item->Next() )
1167  {
1168  bool noconnect = false;
1169 
1170  if( item->GetFlags() & STRUCT_DELETED )
1171  continue; // Already seen
1172 
1173  if( !(item->GetFlags() & CANDIDATE) )
1174  continue; // not a candidate
1175 
1176  if( item->Type() != SCH_LINE_T )
1177  continue;
1178 
1179  item->SetFlags( SKIP_STRUCT );
1180 
1181  segment = (SCH_LINE*) item;
1182 
1183  /* If the wire start point is connected to a wire that was already found
1184  * and now is not connected, add the wire to the list. */
1185  for( tmp = m_drawList.begin(); tmp; tmp = tmp->Next() )
1186  {
1187  // Ensure tmp is a previously deleted segment:
1188  if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
1189  continue;
1190 
1191  if( tmp->Type() != SCH_LINE_T )
1192  continue;
1193 
1194  SCH_LINE* testSegment = (SCH_LINE*) tmp;
1195 
1196  // Test for segment connected to the previously deleted segment:
1197  if( testSegment->IsEndPoint( segment->GetStartPoint() ) )
1198  break;
1199  }
1200 
1201  // when tmp != NULL, segment is a new candidate:
1202  // put it in deleted list if
1203  // the start point is not connected to an other item (like pin)
1204  if( tmp && !CountConnectedItems( segment->GetStartPoint(), true ) )
1205  noconnect = true;
1206 
1207  /* If the wire end point is connected to a wire that has already been found
1208  * and now is not connected, add the wire to the list. */
1209  for( tmp = m_drawList.begin(); tmp; tmp = tmp->Next() )
1210  {
1211  // Ensure tmp is a previously deleted segment:
1212  if( ( tmp->GetFlags() & STRUCT_DELETED ) == 0 )
1213  continue;
1214 
1215  if( tmp->Type() != SCH_LINE_T )
1216  continue;
1217 
1218  SCH_LINE* testSegment = (SCH_LINE*) tmp;
1219 
1220  // Test for segment connected to the previously deleted segment:
1221  if( testSegment->IsEndPoint( segment->GetEndPoint() ) )
1222  break;
1223  }
1224 
1225  // when tmp != NULL, segment is a new candidate:
1226  // put it in deleted list if
1227  // the end point is not connected to an other item (like pin)
1228  if( tmp && !CountConnectedItems( segment->GetEndPoint(), true ) )
1229  noconnect = true;
1230 
1231  item->ClearFlags( SKIP_STRUCT );
1232 
1233  if( noconnect )
1234  {
1235  item->SetFlags( STRUCT_DELETED );
1236 
1237  ITEM_PICKER picker( item, UR_DELETED );
1238  aList.PushItem( picker );
1239 
1240  item = m_drawList.begin();
1241  }
1242  }
1243 
1244  // Get redundant junctions (junctions which connect < 3 end wires
1245  // and no pin)
1246  for( item = m_drawList.begin(); item; item = item->Next() )
1247  {
1248  if( item->GetFlags() & STRUCT_DELETED )
1249  continue;
1250 
1251  if( !(item->GetFlags() & CANDIDATE) )
1252  continue;
1253 
1254  if( item->Type() != SCH_JUNCTION_T )
1255  continue;
1256 
1257  SCH_JUNCTION* junction = (SCH_JUNCTION*) item;
1258 
1259  if( CountConnectedItems( junction->GetPosition(), false ) <= 2 )
1260  {
1261  item->SetFlags( STRUCT_DELETED );
1262 
1263  ITEM_PICKER picker( item, UR_DELETED );
1264  aList.PushItem( picker );
1265  }
1266  }
1267 
1268  for( item = m_drawList.begin(); item; item = item->Next() )
1269  {
1270  if( item->GetFlags() & STRUCT_DELETED )
1271  continue;
1272 
1273  if( item->Type() != SCH_LABEL_T )
1274  continue;
1275 
1276  tmp = GetWireOrBus( ( (SCH_TEXT*) item )->GetPosition() );
1277 
1278  if( tmp && tmp->GetFlags() & STRUCT_DELETED )
1279  {
1280  item->SetFlags( STRUCT_DELETED );
1281 
1282  ITEM_PICKER picker( item, UR_DELETED );
1283  aList.PushItem( picker );
1284  }
1285  }
1286  }
1287 
1289 
1290  return aList.GetCount();
1291 }
1292 
1293 
1294 /******************************************************************/
1295 /* Class SCH_SCREENS to handle the list of screens in a hierarchy */
1296 /******************************************************************/
1297 
1302 static bool SortByTimeStamp( const EDA_ITEM* item1, const EDA_ITEM* item2 )
1303 {
1304  int ii = item1->GetTimeStamp() - item2->GetTimeStamp();
1305 
1306  /* If the time stamps are the same, compare type in order to have component objects
1307  * before sheet object. This is done because changing the sheet time stamp
1308  * before the component time stamp could cause the current annotation to be lost.
1309  */
1310  if( ( ii == 0 && ( item1->Type() != item2->Type() ) ) && ( item1->Type() == SCH_SHEET_T ) )
1311  ii = -1;
1312 
1313  return ii < 0;
1314 }
1315 
1316 
1318 {
1319  m_index = 0;
1321 }
1322 
1323 
1325 {
1326 }
1327 
1328 
1330 {
1331  m_index = 0;
1332 
1333  if( m_screens.size() > 0 )
1334  return m_screens[0];
1335 
1336  return NULL;
1337 }
1338 
1339 
1341 {
1342  if( m_index < m_screens.size() )
1343  m_index++;
1344 
1345  return GetScreen( m_index );
1346 }
1347 
1348 
1349 SCH_SCREEN* SCH_SCREENS::GetScreen( unsigned int aIndex ) const
1350 {
1351  if( aIndex < m_screens.size() )
1352  return m_screens[ aIndex ];
1353 
1354  return NULL;
1355 }
1356 
1357 
1359 {
1360  if( aScreen == NULL )
1361  return;
1362 
1363  for( unsigned int i = 0; i < m_screens.size(); i++ )
1364  {
1365  if( m_screens[i] == aScreen )
1366  return;
1367  }
1368 
1369  m_screens.push_back( aScreen );
1370 }
1371 
1372 
1374 {
1375  if( aItem && aItem->Type() == SCH_SHEET_T )
1376  {
1377  SCH_SHEET* ds = (SCH_SHEET*) aItem;
1378  aItem = ds->GetScreen();
1379  }
1380 
1381  if( aItem && aItem->Type() == SCH_SCREEN_T )
1382  {
1383  SCH_SCREEN* screen = (SCH_SCREEN*) aItem;
1384 
1385  AddScreenToList( screen );
1386  EDA_ITEM* strct = screen->GetDrawItems();
1387 
1388  while( strct )
1389  {
1390  if( strct->Type() == SCH_SHEET_T )
1391  {
1392  BuildScreenList( strct );
1393  }
1394 
1395  strct = strct->Next();
1396  }
1397  }
1398 }
1399 
1400 
1402 {
1403  for( size_t i = 0; i < m_screens.size(); i++ )
1404  m_screens[i]->ClearAnnotation( NULL );
1405 }
1406 
1407 
1409 {
1410  for( size_t i = 0; i < m_screens.size(); i++ )
1411  {
1412  // if wire list has changed, delete the undo/redo list to avoid
1413  // pointer problems with deleted data.
1414  if( m_screens[i]->SchematicCleanUp() )
1415  m_screens[i]->ClearUndoRedoList();
1416  }
1417 }
1418 
1419 
1421 {
1422  EDA_ITEMS items;
1423  SCH_ITEM* item;
1424 
1425  for( size_t i = 0; i < m_screens.size(); i++ )
1426  m_screens[i]->GetHierarchicalItems( items );
1427 
1428  if( items.size() < 2 )
1429  return 0;
1430 
1431  sort( items.begin(), items.end(), SortByTimeStamp );
1432 
1433  int count = 0;
1434 
1435  for( size_t ii = 0; ii < items.size() - 1; ii++ )
1436  {
1437  item = (SCH_ITEM*)items[ii];
1438 
1439  SCH_ITEM* nextItem = (SCH_ITEM*)items[ii + 1];
1440 
1441  if( item->GetTimeStamp() == nextItem->GetTimeStamp() )
1442  {
1443  count++;
1444 
1445  // for a component, update its Time stamp and its paths
1446  // (m_PathsAndReferences field)
1447  if( item->Type() == SCH_COMPONENT_T )
1448  ( (SCH_COMPONENT*) item )->SetTimeStamp( GetNewTimeStamp() );
1449 
1450  // for a sheet, update only its time stamp (annotation of its
1451  // components will be lost)
1452  // @todo: see how to change sheet paths for its cmp list (can
1453  // be possible in most cases)
1454  else
1455  item->SetTimeStamp( GetNewTimeStamp() );
1456  }
1457  }
1458 
1459  return count;
1460 }
1461 
1462 
1464 {
1465  SCH_ITEM* item;
1466  SCH_ITEM* nextItem;
1467  SCH_MARKER* marker;
1468  SCH_SCREEN* screen;
1469 
1470  for( screen = GetFirst(); screen; screen = GetNext() )
1471  {
1472  for( item = screen->GetDrawItems(); item; item = nextItem )
1473  {
1474  nextItem = item->Next();
1475 
1476  if( item->Type() != SCH_MARKER_T )
1477  continue;
1478 
1479  marker = (SCH_MARKER*) item;
1480 
1481  if( marker->GetMarkerType() != aMarkerType )
1482  continue;
1483 
1484  screen->DeleteItem( marker );
1485  }
1486  }
1487 }
1488 
1489 
1491  enum MARKER_BASE::MARKER_SEVERITY aSeverity )
1492 {
1493  int count = 0;
1494 
1495  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1496  {
1497  for( SCH_ITEM* item = screen->GetDrawItems(); item; item = item->Next() )
1498  {
1499  if( item->Type() != SCH_MARKER_T )
1500  continue;
1501 
1502  SCH_MARKER* marker = (SCH_MARKER*) item;
1503 
1504  if( ( aMarkerType != MARKER_BASE::MARKER_UNSPEC ) &&
1505  ( marker->GetMarkerType() != aMarkerType ) )
1506  continue;
1507 
1508  if( aSeverity == MARKER_BASE::MARKER_SEVERITY_UNSPEC ||
1509  aSeverity == marker->GetErrorLevel() )
1510  count++;
1511  }
1512  }
1513 
1514  return count;
1515 }
1516 
1517 
1519 {
1520  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1521  screen->CheckComponentsToPartsLinks();
1522 }
1523 
1524 
1526 {
1527  for( SCH_SCREEN* screen = GetFirst(); screen; screen = GetNext() )
1528  screen->TestDanglingEnds();
1529 }
1530 
1531 
1533 {
1534  SCH_COMPONENT* symbol;
1535  SCH_ITEM* item;
1536  SCH_ITEM* nextItem;
1537  SCH_SCREEN* screen;
1538 
1539  for( screen = GetFirst(); screen; screen = GetNext() )
1540  {
1541  for( item = screen->GetDrawItems(); item; item = nextItem )
1542  {
1543  nextItem = item->Next();
1544 
1545  if( item->Type() != SCH_COMPONENT_T )
1546  continue;
1547 
1548  symbol = dynamic_cast< SCH_COMPONENT* >( item );
1549 
1550  if( !symbol->GetLibId().GetLibNickname().empty() )
1551  return false;
1552  }
1553  }
1554 
1555  return true;
1556 }
1557 
1558 
1559 #if defined(DEBUG)
1560 void SCH_SCREEN::Show( int nestLevel, std::ostream& os ) const
1561 {
1562  // for now, make it look like XML, expand on this later.
1563  NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << ">\n";
1564 
1565  for( EDA_ITEM* item = m_drawList.begin(); item; item = item->Next() )
1566  {
1567  item->Show( nestLevel+1, os );
1568  }
1569 
1570  NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
1571 }
1572 #endif
void SetTextAngle(double aAngle)
Definition: eda_text.h:156
Definition of the SCH_SHEET class for Eeschema.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
#define DIM(x)
of elements in an array
Definition: macros.h:98
bool IsBusLabel(const wxString &aLabel)
Function IsBusLabel test if aLabel has a bus notation.
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
Class KIWAY_HOLDER is a mix in class which holds the location of a wxWindow's KIWAY.
Definition: kiway_player.h:48
void Offset(const wxPoint &aOffset)
Definition: eda_text.h:229
int CountConnectedItems(const wxPoint &aPos, bool aTestJunctions) const
Definition: sch_screen.cpp:717
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
SCH_SCREEN * GetNext()
SCH_SHEET_PIN * GetPin(const wxPoint &aPosition)
Return the sheet pin item found at aPosition in the sheet.
Definition: sch_sheet.cpp:528
BLOCK_SELECTOR m_BlockLocate
Block description for block commands.
Class TYPE_COLLECTOR merely gathers up all SCH_ITEMs of a given set of KICAD_T type(s).
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:161
PART_REF & GetPartRef()
void DeleteAllMarkers(enum MARKER_BASE::TYPEMARKER aMarkerType)
Function DeleteAllMarkers deletes all electronic rules check markers of aMarkerType from all the scre...
T * Remove(T *aElement)
Function Remove removes aElement from the list, but does not delete it.
Definition: dlist.h:211
SCH_SCREEN * GetScreen(unsigned int aIndex) const
const wxPoint & GetTextPos() const
Definition: eda_text.h:224
const wxString & GetCompany() const
int GetUnit() const
Base schematic object class definition.
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...
static double SchematicZoomList[]
Definition: sch_screen.cpp:63
SCH_SHEET * GetSheet(const wxString &aName)
Function GetSheet returns a sheet object pointer that is named aName.
Definition: sch_screen.cpp:680
bool BreakSegment(const wxPoint &aPoint)
Function BreakSegment checks every wire and bus for a intersection at aPoint and break into two segme...
Definition: sch_screen.cpp:932
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
SCH_LINE_TEST_T
void Append(T *aNewElement)
Function Append adds aNewElement to the end of the list.
Definition: dlist.h:177
#define SKIP_STRUCT
flag indicating that the structure should be ignored
Definition: base_struct.h:124
the 3d code uses this value
Definition: typeinfo.h:92
int GetDefaultLineThickness()
Default line thickness used to draw/plot items having a default thickness line value (i...
void SetTextPos(const wxPoint &aPoint)
Definition: eda_text.h:223
#define SELECTEDNODE
flag indicating that the structure has already selected
Definition: base_struct.h:121
void SetVisible(bool aVisible)
Definition: eda_text.h:175
int m_refCount
Number of sheets referencing this screen.
time_t GetNewTimeStamp()
Definition: common.cpp:166
int GetModifyHash()
Return the modification hash for all libraries.
bool IsSelected() const
Definition: base_struct.h:221
SCH_SCREEN(KIWAY *aKiway)
Constructor.
Definition: sch_screen.cpp:95
static const KICAD_T ComponentsOnly[]
A scan list for schematic component items only.
void SetOrigin(const wxPoint &pos)
const wxString & GetComment4() const
T * begin() const
Definition: dlist.h:218
void PushItem(const ITEM_PICKER &aItem)
Function PushItem pushes aItem to the top of the list.
wxPoint GetEndPoint() const
Definition: sch_line.h:75
const wxString & GetDate() const
SCH_LINE * Next() const
Definition: sch_line.h:56
void Remove(SCH_ITEM *aItem)
Function Remove removes aItem from the schematic associated with this screen.
Definition: sch_screen.cpp:158
LIB_ITEM * GetDrawItem(const wxPoint &aPosition, KICAD_T aType=TYPE_NOT_INIT)
Function GetDrawItem().
wxPoint m_End() const
void SetTextSize(const wxSize &aNewSize)
Definition: eda_text.h:214
EDA_ITEM * Next() const
Definition: base_struct.h:206
bool BreakSegmentsOnJunctions()
Function BreakSegmentsOnJunctions tests all junctions and bus entries in the schematic for intersecti...
Definition: sch_screen.cpp:961
#define SCH_LAYER_ID_COUNT
EDA_ITEM * GetItem(unsigned aIndex)
#define CANDIDATE
flag indicating that the structure is connected
Definition: base_struct.h:123
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
int m_modification_sync
inequality with PART_LIBS::GetModificationHash() will trigger ResolveAll().
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
SCH_ITEM * Next() const
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:90
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
double GetTextAngle() const
Definition: eda_text.h:164
void SetEndPoint(const wxPoint &aPosition)
Definition: sch_line.h:77
enum TYPEMARKER GetMarkerType() const
wxPoint GetStartPoint() const
Definition: sch_line.h:71
Class SCH_BUS_ENTRY_BASE.
Definition: sch_bus_entry.h:43
static GRID_TYPE SchematicGridList[]
Definition: sch_screen.cpp:84
#define SCHEMATIC_HEAD_STRING
Definition: general.h:41
bool MergeOverlap(SCH_LINE *aLine)
Check line against aLine to see if it overlaps and merge if it does.
Definition: sch_line.cpp:274
void InitDataPoints(const wxSize &aPageSizeInternalUnits)
Definition: base_screen.cpp:69
#define IS_DRAGGED
Item being dragged.
Definition: base_struct.h:115
SCH_LINE * GetLine(const wxPoint &aPosition, int aAccuracy=0, int aLayer=LAYER_NOTES, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
Function GetLine returns a line item located at aPosition.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
const wxPoint & GetOrigin() const
int GetConvert() const
unsigned int m_index
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
Definition: sch_field.cpp:499
const wxString & GetTitle() const
std::string EscapedUTF8(const wxString &aString)
Function EscapedUTF8 returns an 8 bit UTF8 string given aString in unicode form.
Definition: string.cpp:137
#define SELECTED
Definition: base_struct.h:120
Class UNDO_REDO_CONTAINER is a holder to handle alist of undo (or redo) command.
#define EESCHEMA_VERSION
Definition: general.h:40
bool HitTest(const wxPoint &aPosition, int aAccuracy) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item...
Definition: sch_line.cpp:548
void RemovePin(SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:370
MARKER_SEVERITY GetErrorLevel() const
TITLE_BLOCK m_titles
bool IsPortrait() const
int GetConnection(const wxPoint &aPosition, PICKED_ITEMS_LIST &aList, bool aFullConnection)
Functions GetConnection adds all of the wires and junctions to aList that make up a connection to the...
bool Save(FILE *aFile) const
Function Save writes the data structures for this object out to aFile in "*.sch" format.
Definition: sch_screen.cpp:475
void BuildScreenList(EDA_ITEM *aItem)
void addConnectedItemsToBlock(const wxPoint &aPosition)
Function addConnectedItemsToBlock add items connected at aPosition to the block pick list...
Definition: sch_screen.cpp:831
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
PAGE_INFO m_paper
The size of the paper to print or plot on.
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
void GetHierarchicalItems(EDA_ITEMS &aItems)
Function GetHierarchicalItems adds all schematic sheet and component object in the screen to aItems...
Definition: sch_screen.cpp:754
SCH_FIELD * GetField(int aFieldNdx) const
Function GetField returns a field.
int UpdatePickList()
Function UpdatePickList adds all the items in the screen within the block selection rectangle to the ...
Definition: sch_screen.cpp:875
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
bool SchematicCleanUp()
Function SchematicCleanUp performs routine schematic cleaning including breaking wire and buses and d...
Definition: sch_screen.cpp:426
wxPoint GetPosition() const override
Function GetPosition.
Definition: sch_junction.h:92
static void ResolveAll(const SCH_COLLECTOR &aComponents, PART_LIBS *aLibs)
bool m_Center
Center on screen.
void DeleteItem(SCH_ITEM *aItem)
Function DeleteItem removes aItem from the linked list and deletes the object.
Definition: sch_screen.cpp:164
GR_DRAWMODE
Drawmode. Compositing mode plus a flag or two.
Definition: gr_basic.h:41
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:532
const wxString & GetRevision() const
Class BASE_SCREEN handles how to draw a screen (a board, a schematic ...)
void AddScreenToList(SCH_SCREEN *aScreen)
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
void MarkConnections(SCH_LINE *aSegment)
Function MarkConnections add all wires and junctions connected to aSegment which are not connected an...
Definition: sch_screen.cpp:295
void UpdateSymbolLinks()
wxPoint GetPinPhysicalPosition(LIB_PIN *Pin)
virtual bool IsConnectable() const
Function IsConnectable returns true if the schematic item can connect to another schematic item...
void SetStartPoint(const wxPoint &aPosition)
Definition: sch_line.h:73
virtual void ClearUndoRedoList()
Function ClearUndoRedoList clear undo and redo list, using ClearUndoORRedoList() picked items are del...
void SchematicCleanUp()
Function SchematicCleanUp merges and breaks wire segments in the entire schematic hierarchy...
void Clear()
Function Clear deletes all draw items and clears the project settings.
Definition: sch_screen.cpp:141
void Draw(EDA_DRAW_PANEL *aCanvas, wxDC *aDC, GR_DRAWMODE aDrawMode, COLOR4D aColor=COLOR4D::UNSPECIFIED)
Function Draw draws all the items in the screen to aCanvas.
Definition: sch_screen.cpp:558
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:122
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
void SetFlags(STATUS_FLAGS aFlags)
int GetNode(const wxPoint &aPosition, EDA_ITEMS &aList)
Function GetNode returns all the items at aPosition that form a node.
Definition: sch_screen.cpp:990
Common plot library Plot settings, and plotting engines (Postscript, Gerber, HPGL and DXF) ...
const wxString & GetComment3() const
SCH_SHEET_PIN * GetSheetLabel(const wxPoint &aPosition)
Function GetSheetLabel test the screen if aPosition is a sheet label object.
Definition: sch_screen.cpp:697
Class SCH_SHEET_PIN defines a sheet pin (label) used in sheets to create hierarchical schematics...
Definition: sch_sheet.h:62
bool HasNoFullyDefinedLibIds()
Function HasNoFullyDefinedLibIds.
SCH_LINE * GetWire(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)
bool SetZoom(double iu_per_du)
Function SetZoom adjusts the current zoom factor.
int GetUnit() const
Class SCH_SHEET_PATH.
Class PICKED_ITEMS_LIST is a holder to handle information on schematic or board items.
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Function ClearAnnotation clears exiting component annotation ( i.i IC23 changed to IC...
void SetItem(EDA_ITEM *aItem)
bool SetPickerFlags(STATUS_FLAGS aFlags, unsigned aIdx)
Function SetPickerFlags set the flags of the picker (usually to the picked item m_Flags value) ...
void SelectBlockItems()
Function SelectBlockItems creates a list of items found when a block command is initiated.
Definition: sch_screen.cpp:768
int GetWidthMils() const
void FreeDrawList()
Free all the items from the schematic associated with the screen.
Definition: sch_screen.cpp:152
const TITLE_BLOCK & GetTitleBlock() const
const wxString & GetComment2() const
time_t GetTimeStamp() const
Definition: base_struct.h:204
Class SCH_SHEET is the sheet symbol placed in a schematic, and is the entry point for a sub schematic...
Definition: sch_sheet.h:216
unsigned GetCount() const
Function GetCount.
void Plot(PLOTTER *aPlotter)
Function Plot plots all the schematic objects to aPlotter.
Definition: sch_screen.cpp:583
int GetMarkerCount(enum MARKER_BASE::TYPEMARKER aMarkerType, enum MARKER_BASE::MARKER_SEVERITY aSeverity)
Function GetMarkerCount returns the number of ERC markers of aMarkerType from all of the screens in t...
DLIST< SCH_ITEM > m_drawList
Object list for the screen.
Class PART_LIBS is a collection of PART_LIBs.
Definition of the NETLIST_OBJECT class.
void Normalize()
Function Normalize ensures that the height ant width are positive.
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const
Function GetConnectionPoints add all the connection points for this item to aPoints.
Field Value of part, i.e. "3.3K".
bool IsEndPoint(const wxPoint &aPoint) const
Definition: sch_line.h:64
void DecRefCount()
Definition: sch_screen.cpp:133
Base plotter engine class.
Definition: plot_common.h:86
SCH_ITEM * GetDrawItems() const
Function GetDrawItems().
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
void SetSize(const wxSize &size)
Definition the SCH_COMPONENT class for Eeschema.
bool IsCustom() const
Function IsCustom returns true if the type is Custom.
void AddGrid(const GRID_TYPE &grid)
const wxString & GetComment1() const
bool IsTerminalPoint(const wxPoint &aPosition, int aLayer)
Function IsTerminalPoint tests if aPosition is a connection point on aLayer.
Definition: sch_screen.cpp:355
see class PGM_BASE
void TestDanglingEnds()
SCH_TEXT * GetLabel(const wxPoint &aPosition, int aAccuracy=0)
Function GetLabel returns a label item located at aPosition.
Class SCH_LINE is a segment description base class to describe items which have 2 end points (track...
Definition: sch_line.h:42
EDA_ITEM * GetPickedItem(unsigned int aIdx) const
Function GetPickedItem.
std::vector< SCH_SCREEN * > m_screens
int GetFieldCount() const
Function GetFieldCount returns the number of fields in this component.
Class GRID_TYPE is for grid arrays.
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=NOT_USED) const
Function GetItem checks aPosition within a distance of aAccuracy for items of type aFilter...
Definition: sch_screen.cpp:203
void ClearAnnotation()
Function ClearAnnotation clears the annotation for all components in the hierarchy.
#define max(a, b)
Definition: auxiliary.h:86
bool IsConnected(const wxPoint &aPoint) const
Function IsConnected tests the item to see if it is connected to aPoint.
bool TestDanglingEnds()
Function TestDanglingEnds tests all of the connectible objects in the schematic for unused connection...
Definition: sch_screen.cpp:911
void SetCurItem(SCH_ITEM *aItem)
Function SetCurItem sets the currently selected object, m_CurrentItem.
void CheckComponentsToPartsLinks()
Function CheckComponentsToPartsLink initializes or reinitializes the weak reference to the LIB_PART f...
Definition: sch_screen.cpp:532
#define ENDPOINT
Definition: base_struct.h:119
virtual bool IsSelectStateChanged(const wxRect &aRect)
Function IsSelectStateChanged checks if the selection state of an item inside aRect has changed...
Class EDA_RECT handles the component boundary box.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
wxPoint GetPosition() const override
Function GetPosition.
const LIB_ID & GetLibId() const
void Collect(SCH_ITEM *aBoard, const KICAD_T aScanList[])
Function Collect scans a BOARD_ITEM using this class's Inspector method, which does the collection...
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
The common library.
LIB_PIN * GetPin(const wxPoint &aPosition, SCH_COMPONENT **aComponent=NULL, bool aEndPointOnly=false) const
Function GetPin test the screen for a component pin item at aPosition.
Definition: sch_screen.cpp:624
bool IsDragging() const
Function IsDragging returns true if the current block command is a drag operation.
PICKED_ITEMS_LIST & GetItems()
void ExtractWires(DLIST< SCH_ITEM > &aList, bool aCreateCopy)
Function ExtractWires extracts the old wires, junctions and buses.
Definition: sch_screen.cpp:241
virtual bool IsDanglingStateChanged(std::vector< DANGLING_END_ITEM > &aItemList)
Function IsDanglingStateChanged tests the schematic item to aItemList to check if it's dangling state...
SCH_LINE * GetWireOrBus(const wxPoint &aPosition)
Function GetWireOrBus returns a wire or bus item located at aPosition.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
unsigned GetCount() const
Function GetCount returns the number of elements in the list.
Definition: dlist.h:126
#define EESCHEMA_FILE_STAMP
Definition: sch_screen.cpp:58
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Function ClearAnnotation clears the annotation for the components in aSheetPath on the screen...
Definition: sch_screen.cpp:735
int ReplaceDuplicateTimeStamps()
Function ReplaceDuplicateTimeStamps test all sheet and component objects in the schematic for duplica...
void ReplaceWires(DLIST< SCH_ITEM > &aWireList)
Function ReplaceWires replaces all of the wires, buses, and junctions in the screen with aWireList...
Definition: sch_screen.cpp:269
SCH_SCREEN * GetFirst()
void ClearDrawingState()
Clear the state flags of all the items in the screen.
Definition: sch_screen.cpp:617
virtual void ClearUndoORRedoList(UNDO_REDO_CONTAINER &aList, int aItemCount=-1) override
Function ClearUndoORRedoList free the undo or redo list from List element Wrappers are deleted...
Definition: sch_screen.cpp:593
const wxSize & GetTextSize() const
Definition: eda_text.h:215
const wxString & GetType() const
bool IsJunctionNeeded(const wxPoint &aPosition)
Function IsJunctionNeeded tests if a junction is required for the items at aPosition on the screen...
Definition: sch_screen.cpp:337
Definition for part library class.
const UTF8 & GetLibNickname() const
Function GetLibNickname.
Definition: lib_id.h:108
int SetGrid(const wxRealPoint &size)
set the current grid size m_Grid.
bool CheckIfOnDrawList(SCH_ITEM *st)
Definition: sch_screen.cpp:187
wxString GetName() const
Definition: sch_sheet.h:274
const wxSize & GetSize() const
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
static bool SortByTimeStamp(const EDA_ITEM *item1, const EDA_ITEM *item2)
Function SortByTimeStamp sorts a list of schematic items by time stamp and type.
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Implementation of the label properties dialog.
unsigned GetCount() const
int GetHeightMils() const
void ClearListAndDeleteItems()
Function ClearListAndDeleteItems deletes the list of pickers, AND the data pointed by m_PickedItem or...
void Insert(T *aNewElement, T *aElementAfterMe)
Function Insert puts aNewElement just in front of aElementAfterMe in the list sequence.
Definition: dlist.h:200
EDA_RECT & Inflate(wxCoord dx, wxCoord dy)
Function Inflate inflates the rectangle horizontally by dx and vertically by dy.
std::vector< double > m_ZoomList
standard zoom (i.e. scale) coefficients.
void IncRefCount()
Definition: sch_screen.cpp:127
virtual wxString GetClass() const override
Function GetClass returns the class name.
#define STARTPOINT
Definition: base_struct.h:118
virtual void SetText(const wxString &aText)
Definition: eda_text.h:141
int GetConvert() const
virtual void SetCurrentLineWidth(int width, void *aData=NULL)=0
Set the line width for the next drawing.
void PushItem(ITEM_PICKER &aItem)
Function PushItem adds aItem to the list of items.
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39
wxPoint GetPosition() const override
Function GetPosition.
bool SetComponentFootprint(SCH_SHEET_PATH *aSheetPath, const wxString &aReference, const wxString &aFootPrint, bool aSetVisible)
Function SetFootprintField searches screen for a component with aReference and set the footprint fiel...
SCH_LINE * GetBus(const wxPoint &aPosition, int aAccuracy=0, SCH_LINE_TEST_T aSearchType=ENTIRE_LENGTH_T)