KiCad PCB EDA Suite
sch_editor_control.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) 2019 CERN
5  * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <symbol_library.h>
26 #include <confirm.h>
27 #include <widgets/infobar.h>
28 #include <connection_graph.h>
34 #include <project_rescue.h>
35 #include <erc.h>
36 #include <invoke_sch_dialog.h>
37 #include <kicad_string.h>
38 #include <kiway.h>
39 #include <kiway_player.h>
41 #include <project/project_file.h>
42 #include <project/net_settings.h>
43 #include <sch_edit_frame.h>
45 #include <sch_line.h>
46 #include <sch_painter.h>
47 #include <sch_sheet.h>
48 #include <sch_sheet_pin.h>
49 #include <sch_view.h>
50 #include <schematic.h>
51 #include <advanced_config.h>
52 #include <sim/sim_plot_frame.h>
53 #include <symbol_viewer_frame.h>
54 #include <status_popup.h>
55 #include <tool/picker_tool.h>
56 #include <tool/tool_manager.h>
57 #include <tools/ee_actions.h>
58 #include <tools/ee_selection.h>
62 #include <dialog_update_from_pcb.h>
63 #include <dialog_helpers.h>
64 
65 
66 int SCH_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
67 {
69  return 0;
70 }
71 
72 
74 {
76  return 0;
77 }
78 
79 
81 {
83  return 0;
84 }
85 
86 
88 {
89  m_frame->Save_File( true );
90  return 0;
91 }
92 
93 
95 {
97  return 0;
98 }
99 
100 
102 {
103  PICKED_ITEMS_LIST undoCmd;
104  DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( m_frame );
105  ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
106 
107  undoCmd.PushItem( wrapper );
109 
112 
113  if( dlg.ShowModal() != wxID_OK )
115 
116  return 0;
117 }
118 
119 
121 {
122  SCH_SCREENS schematic( m_frame->Schematic().Root() );
123 
124  if( schematic.HasNoFullyDefinedLibIds() )
125  RescueLegacyProject( true );
126  else
128 
129  return 0;
130 }
131 
132 
133 bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
134 {
136  m_frame->GetCanvas()->GetBackend() );
137 
138  return rescueProject( rescuer, aRunningOnDemand );
139 }
140 
141 
143 {
146  m_frame->GetCanvas()->GetBackend() );
147 
148  return rescueProject( rescuer, aRunningOnDemand );
149 }
150 
151 
152 bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
153 {
154  if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
155  return false;
156 
157  if( aRescuer.GetCandidateCount() )
158  {
159  KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
160 
161  if( viewer )
162  static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
163 
164  if( aRunningOnDemand )
165  {
166  SCH_SCREENS schematic( m_frame->Schematic().Root() );
167 
168  schematic.UpdateSymbolLinks();
170  }
171 
173  m_frame->SyncView();
174  m_frame->GetCanvas()->Refresh();
175  m_frame->OnModify();
176  }
177 
178  return true;
179 }
180 
181 
183 {
184  DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
185 
186  dlgRemap.ShowQuasiModal();
187 
188  m_frame->GetCanvas()->Refresh( true );
189 
190  return 0;
191 }
192 
193 
195 {
197 
198  wxFileName fn = m_frame->Prj().AbsolutePath( m_frame->Schematic().RootScreen()->GetFileName() );
199 
200  if( fn.GetName() != NAMELESS_PROJECT )
202 
203  return 0;
204 }
205 
206 
208 {
210 
211  dlg.ShowModal();
212 
213  // save project config if the prj config has changed:
214  if( dlg.PrjConfigChanged() )
216 
217  return 0;
218 }
219 
220 
222 {
223  m_frame->Close( false );
224  return 0;
225 }
226 
227 
228 // A dummy wxFindReplaceData signaling any marker should be found
229 static wxFindReplaceData g_markersOnly;
230 
231 
233 {
235  return UpdateFind( aEvent );
236 }
237 
238 
240 {
242  return 0;
243 }
244 
245 
247 {
248  wxFindReplaceData* data = m_frame->GetFindReplaceData();
249 
250  auto visit =
251  [&]( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheet )
252  {
253  if( data && aItem->Matches( *data, aSheet ) )
254  {
255  aItem->SetForceVisible( true );
256  m_selectionTool->BrightenItem( aItem );
257  }
258  else if( aItem->IsBrightened() )
259  {
260  aItem->SetForceVisible( false );
262  }
263  };
264 
265  if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
266  || aEvent.IsAction( &ACTIONS::updateFind ) )
267  {
269 
270  for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
271  {
272  visit( item, &m_frame->GetCurrentSheet() );
273 
274  item->RunOnChildren(
275  [&]( SCH_ITEM* aChild )
276  {
277  visit( aChild, &m_frame->GetCurrentSheet() );
278  } );
279  }
280  }
281  else if( aEvent.Matches( EVENTS::SelectedItemsModified ) )
282  {
283  for( EDA_ITEM* item : m_selectionTool->GetSelection() )
284  visit( item, &m_frame->GetCurrentSheet() );
285  }
286 
287  getView()->UpdateItems();
288  m_frame->GetCanvas()->Refresh();
289  m_frame->UpdateTitle();
290 
291  return 0;
292 }
293 
294 
296  SCH_ITEM* aAfter, wxFindReplaceData* aData )
297 {
298  bool past_item = true;
299 
300  if( aAfter != nullptr )
301  {
302  past_item = false;
303 
304  if( aAfter->Type() == SCH_PIN_T || aAfter->Type() == SCH_FIELD_T )
305  aAfter = static_cast<SCH_ITEM*>( aAfter->GetParent() );
306  }
307 
308 
309  for( SCH_ITEM* item : aScreen->Items() )
310  {
311  if( item == aAfter )
312  {
313  past_item = true;
314  }
315  else if( past_item )
316  {
317  if( aData == &g_markersOnly && item->Type() == SCH_MARKER_T )
318  return item;
319 
320  if( item->Matches( *aData, aSheet ) )
321  return item;
322 
323  if( item->Type() == SCH_SYMBOL_T )
324  {
325  SCH_SYMBOL* cmp = static_cast<SCH_SYMBOL*>( item );
326 
327  for( SCH_FIELD& field : cmp->GetFields() )
328  {
329  if( field.Matches( *aData, aSheet ) )
330  return &field;
331  }
332 
333  for( SCH_PIN* pin : cmp->GetPins() )
334  {
335  if( pin->Matches( *aData, aSheet ) )
336  return pin;
337  }
338  }
339 
340  if( item->Type() == SCH_SHEET_T )
341  {
342  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
343 
344  for( SCH_FIELD& field : sheet->GetFields() )
345  {
346  if( field.Matches( *aData, aSheet ) )
347  return &field;
348  }
349 
350  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
351  {
352  if( pin->Matches( *aData, aSheet ) )
353  return pin;
354  }
355  }
356  }
357  }
358 
359  return nullptr;
360 }
361 
362 
364 {
365  // A timer during which a subsequent FindNext will result in a wrap-around
366  static wxTimer wrapAroundTimer;
367 
368  wxFindReplaceData* data = m_frame->GetFindReplaceData();
369 
370  if( aEvent.IsAction( &ACTIONS::findNextMarker ) )
371  {
372  if( data )
373  g_markersOnly.SetFlags( data->GetFlags() );
374 
375  data = &g_markersOnly;
376  }
377  else if( !data )
378  {
379  return FindAndReplace( ACTIONS::find.MakeEvent() );
380  }
381 
382  bool searchAllSheets = !( data->GetFlags() & FR_CURRENT_SHEET_ONLY );
383  EE_SELECTION& selection = m_selectionTool->GetSelection();
384  SCH_SCREEN* afterScreen = m_frame->GetScreen();
385  SCH_ITEM* afterItem = dynamic_cast<SCH_ITEM*>( selection.Front() );
386  SCH_ITEM* item = nullptr;
387 
388  if( wrapAroundTimer.IsRunning() )
389  {
390  afterScreen = nullptr;
391  afterItem = nullptr;
392  wrapAroundTimer.Stop();
394  }
395 
397 
398  if( afterScreen || !searchAllSheets )
399  item = nextMatch( m_frame->GetScreen(), &m_frame->GetCurrentSheet(), afterItem, data );
400 
401  if( !item && searchAllSheets )
402  {
403  SCH_SHEET_LIST schematic = m_frame->Schematic().GetSheets();
404  SCH_SCREENS screens( m_frame->Schematic().Root() );
405 
406  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
407  {
408  if( afterScreen )
409  {
410  if( afterScreen == screen )
411  afterScreen = nullptr;
412 
413  continue;
414  }
415 
416  SCH_SHEET_PATH* sheet = schematic.FindSheetForScreen( screen );
417 
418  item = nextMatch( screen, sheet, nullptr, data );
419 
420  if( item )
421  {
422  wxCHECK_MSG( sheet, 0, "Sheet not found for " + screen->GetFileName() );
423 
424  m_frame->Schematic().SetCurrentSheet( *sheet );
426 
427  screen->TestDanglingEnds();
428 
429  m_frame->SetScreen( screen );
430  UpdateFind( ACTIONS::updateFind.MakeEvent() );
431 
432  break;
433  }
434  }
435  }
436 
437  if( item )
438  {
439  m_selectionTool->AddItemToSel( item );
440  m_frame->FocusOnLocation( item->GetBoundingBox().GetCenter() );
441  m_frame->GetCanvas()->Refresh();
442  }
443  else
444  {
445  wxString msg = searchAllSheets ? _( "Reached end of schematic." )
446  : _( "Reached end of sheet." );
447 
448  // Show the popup during the time period the user can wrap the search
449  m_frame->ShowFindReplaceStatus( msg + wxS( " " ) +
450  _( "Find again to wrap around to the start." ), 4000 );
451  wrapAroundTimer.StartOnce( 4000 );
452  }
453 
454  return 0;
455 }
456 
457 
459 {
460  wxFindReplaceData* data = m_frame->GetFindReplaceData();
462 
463  return data && item && item->Matches( *data, &m_frame->GetCurrentSheet() );
464 }
465 
466 
468 {
469  wxFindReplaceData* data = m_frame->GetFindReplaceData();
472 
473  if( !data )
474  return FindAndReplace( ACTIONS::find.MakeEvent() );
475 
476  if( item && item->Matches( *data, sheet ) )
477  {
478  if( item->Replace( *data, sheet ) )
479  {
480  m_frame->UpdateItem( item );
482  m_frame->OnModify();
483  }
484 
485  FindNext( ACTIONS::findNext.MakeEvent() );
486  }
487 
488  return 0;
489 }
490 
491 
493 {
494  wxFindReplaceData* data = m_frame->GetFindReplaceData();
495  bool modified = false;
496 
497  if( !data )
498  return FindAndReplace( ACTIONS::find.MakeEvent() );
499 
500  SCH_SHEET_LIST schematic = m_frame->Schematic().GetSheets();
501  SCH_SCREENS screens( m_frame->Schematic().Root() );
502 
503  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
504  {
505  SCH_SHEET_PATH* sheet = schematic.FindSheetForScreen( screen );
506 
507  for( EDA_ITEM* item = nextMatch( screen, sheet, nullptr, data ); item; )
508  {
509  if( item->Replace( *data, sheet ) )
510  {
511  m_frame->UpdateItem( item );
512  modified = true;
513  }
514 
515  item = nextMatch( screen, sheet, dynamic_cast<SCH_ITEM*>( item ), data );
516  }
517  }
518 
519  if( modified )
520  {
522  m_frame->OnModify();
523  }
524 
525  return 0;
526 }
527 
528 
530 {
531  doCrossProbeSchToPcb( aEvent, false );
532  return 0;
533 }
534 
535 
537 {
538  doCrossProbeSchToPcb( aEvent, true );
539  return 0;
540 }
541 
542 
543 void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
544 {
545  // Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
546  if( m_probingPcbToSch )
547  return;
548 
550  SCH_ITEM* item = nullptr;
551  SCH_SYMBOL* symbol = nullptr;
552 
553  if( aForce )
554  {
555  EE_SELECTION& selection = selTool->RequestSelection();
556 
557  if( selection.GetSize() >= 1 )
558  item = (SCH_ITEM*) selection.Front();
559  }
560  else
561  {
562  EE_SELECTION& selection = selTool->GetSelection();
563 
564  if( selection.GetSize() >= 1 )
565  item = (SCH_ITEM*) selection.Front();
566  }
567 
568  if( !item )
569  {
570  if( aForce )
571  m_frame->SendMessageToPCBNEW( nullptr, nullptr );
572 
573  return;
574  }
575 
576 
577  switch( item->Type() )
578  {
579  case SCH_FIELD_T:
580  case LIB_FIELD_T:
581  if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T )
582  {
583  symbol = (SCH_SYMBOL*) item->GetParent();
584  m_frame->SendMessageToPCBNEW( item, symbol );
585  }
586  break;
587 
588  case SCH_SYMBOL_T:
589  symbol = (SCH_SYMBOL*) item;
590  m_frame->SendMessageToPCBNEW( item, symbol );
591  break;
592 
593  case SCH_PIN_T:
594  symbol = (SCH_SYMBOL*) item->GetParent();
595  m_frame->SendMessageToPCBNEW( static_cast<SCH_PIN*>( item ), symbol );
596  break;
597 
598  case SCH_SHEET_T:
599  if( aForce )
600  m_frame->SendMessageToPCBNEW( item, nullptr );
601  break;
602 
603  default:
604  break;
605  }
606 }
607 
608 
609 #ifdef KICAD_SPICE
610 
611 static KICAD_T wires[] = { SCH_LINE_LOCATE_WIRE_T, EOT };
612 static KICAD_T wiresAndPins[] = { SCH_LINE_LOCATE_WIRE_T, SCH_PIN_T, SCH_SHEET_PIN_T, EOT };
613 static KICAD_T fieldsAndSymbols[] = { SCH_SYMBOL_T, SCH_FIELD_T, EOT };
614 
615 #define HITTEST_THRESHOLD_PIXELS 5
616 
617 
618 int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
619 {
621  SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false );
622 
623  if( !simFrame ) // Defensive coding; shouldn't happen.
624  return 0;
625 
626  // Deactivate other tools; particularly important if another PICKER is currently running
627  Activate();
628 
630  picker->SetSnapping( false );
631 
632  picker->SetClickHandler(
633  [this, simFrame]( const VECTOR2D& aPosition )
634  {
636  EDA_ITEM* item = selTool->GetNode( aPosition );
637 
638  if( !item )
639  return false;
640 
641  if( item->IsType( wires ) )
642  {
643  if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
644  simFrame->AddVoltagePlot( UnescapeString( conn->Name() ) );
645  }
646  else if( item->Type() == SCH_PIN_T )
647  {
648  SCH_PIN* pin = (SCH_PIN*) item;
649  SCH_SYMBOL* symbol = (SCH_SYMBOL*) item->GetParent();
650  wxString param;
651  wxString primitive;
652 
653  primitive = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, symbol, 0 );
654  primitive.LowerCase();
655 
656  if( primitive == "c" || primitive == "l" || primitive == "r" )
657  param = wxT( "I" );
658  else if( primitive == "d" )
659  param = wxT( "Id" );
660  else
661  param = wxString::Format( wxT( "I%s" ), pin->GetShownName().Lower() );
662 
663  simFrame->AddCurrentPlot( symbol->GetRef( &m_frame->GetCurrentSheet() ),
664  param );
665  }
666 
667  return true;
668  } );
669 
670  picker->SetMotionHandler(
671  [this, picker]( const VECTOR2D& aPos )
672  {
673  EE_COLLECTOR collector;
674  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
675  collector.Collect( m_frame->GetScreen(), wiresAndPins, (wxPoint) aPos );
676 
678  selectionTool->GuessSelectionCandidates( collector, aPos );
679 
680  EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
681  SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
682 
683  const SCH_CONNECTION* conn = nullptr;
684 
685  if( wire )
686  {
687  item = nullptr;
688  conn = wire->Connection();
689  }
690 
691  if( item && item->Type() == SCH_PIN_T )
693  else
695 
696  if( m_pickerItem != item )
697  {
698 
699  if( m_pickerItem )
700  selectionTool->UnbrightenItem( m_pickerItem );
701 
702  m_pickerItem = item;
703 
704  if( m_pickerItem )
705  selectionTool->BrightenItem( m_pickerItem );
706  }
707 
708  if( m_frame->GetHighlightedConnection() != conn )
709  {
711 
712  TOOL_EVENT dummyEvent;
713  UpdateNetHighlighting( dummyEvent );
714  }
715  } );
716 
717  picker->SetFinalizeHandler(
718  [this]( const int& aFinalState )
719  {
720  if( m_pickerItem )
722 
724  {
725  m_frame->SetHighlightedConnection( nullptr );
726 
727  TOOL_EVENT dummyEvent;
728  UpdateNetHighlighting( dummyEvent );
729  }
730 
731  // Wake the selection tool after exiting to ensure the cursor gets updated
733  } );
734 
735  std::string tool = aEvent.GetCommandStr().get();
736  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
737 
738  return 0;
739 }
740 
741 
742 int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
743 {
745 
746  // Deactivate other tools; particularly important if another PICKER is currently running
747  Activate();
748 
749  picker->SetCursor( KICURSOR::TUNE );
750  picker->SetSnapping( false );
751 
752  picker->SetClickHandler(
753  [this]( const VECTOR2D& aPosition )
754  {
756  EDA_ITEM* item = nullptr;
757  selTool->SelectPoint( aPosition, fieldsAndSymbols, &item );
758 
759  if( !item )
760  return false;
761 
762  if( item->Type() != SCH_SYMBOL_T )
763  {
764  item = item->GetParent();
765 
766  if( item->Type() != SCH_SYMBOL_T )
767  return false;
768  }
769 
770  SIM_PLOT_FRAME* simFrame =
772 
773  if( simFrame )
774  simFrame->AddTuner( static_cast<SCH_SYMBOL*>( item ) );
775 
776  return true;
777  } );
778 
779  picker->SetMotionHandler(
780  [this]( const VECTOR2D& aPos )
781  {
782  EE_COLLECTOR collector;
783  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
784  collector.Collect( m_frame->GetScreen(), fieldsAndSymbols, (wxPoint) aPos );
785 
787  selectionTool->GuessSelectionCandidates( collector, aPos );
788 
789  EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
790 
791  if( m_pickerItem != item )
792  {
793  if( m_pickerItem )
794  selectionTool->UnbrightenItem( m_pickerItem );
795 
796  m_pickerItem = item;
797 
798  if( m_pickerItem )
799  selectionTool->BrightenItem( m_pickerItem );
800  }
801  } );
802 
803  picker->SetFinalizeHandler(
804  [this]( const int& aFinalState )
805  {
806  if( m_pickerItem )
808 
809  // Wake the selection tool after exiting to ensure the cursor gets updated
811  } );
812 
813  std::string tool = aEvent.GetCommandStr().get();
814  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
815 
816  return 0;
817 }
818 #endif /* KICAD_SPICE */
819 
820 
821 // A singleton reference for clearing the highlight
823 
824 
825 static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
826 {
827  SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
828  EE_SELECTION_TOOL* selTool = aToolMgr->GetTool<EE_SELECTION_TOOL>();
829  SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
830  SCH_CONNECTION* conn = nullptr;
831  bool retVal = true;
832 
833  if( aPosition != CLEAR )
834  {
835  ERC_TESTER erc( &editFrame->Schematic() );
836 
837  if( erc.TestDuplicateSheetNames( false ) > 0 )
838  {
839  wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
840  retVal = false;
841  }
842  else
843  {
844  SCH_ITEM* item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
845  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
846 
847  if( item )
848  {
849  if( item->Type() == SCH_FIELD_T )
850  symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
851 
852  if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
853  {
854  std::vector<SCH_PIN*> pins = symbol->GetPins();
855 
856  if( pins.size() == 1 )
857  conn = pins[0]->Connection();
858  }
859  else
860  {
861  conn = item->Connection();
862  }
863  }
864  }
865  }
866 
867  if( !conn )
868  {
869  editFrame->SetStatusText( wxT( "" ) );
870  editFrame->SendCrossProbeClearHighlight();
871  }
872  else
873  {
874  editFrame->SetCrossProbeConnection( conn );
875  }
876 
877  editFrame->SetHighlightedConnection( conn );
878  editFrame->UpdateNetHighlightStatus();
879 
881  editorControl->UpdateNetHighlighting( dummy );
882 
883  return retVal;
884 }
885 
886 
888 {
890  VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
891 
892  highlightNet( m_toolMgr, cursorPos );
893 
894  return 0;
895 }
896 
897 
899 {
901 
902  return 0;
903 }
904 
905 
907 {
910  VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
911 
912  // TODO remove once real-time connectivity is a given
914  // Ensure the netlist data is up to date:
916 
917  // Remove selection in favor of highlighting so the whole net is highlighted
918  selectionTool->ClearSelection();
919  highlightNet( m_toolMgr, cursorPos );
920 
922 
923  if( conn )
924  {
925  if( !conn->IsBus()
926  && ( !conn->Driver()
929  {
930  m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
932  return 0;
933  }
934  else if( conn->IsBus() && conn->Members().size() == 0 )
935  {
937  _( "Bus must have at least one member to assign a netclass to members." ) );
939  return 0;
940  }
941 
942  wxArrayString netNames;
943 
944  if( conn->IsBus() )
945  {
946  for( auto& m : conn->Members() )
947  {
948  netNames.Add( m->Name() );
949  }
950  }
951  else
952  {
953  netNames.Add( conn->Name() );
954  }
955 
957  wxString netclassName = netSettings.GetNetclassName( netNames.front() );
958 
959  wxArrayString headers;
960  std::vector<wxArrayString> items;
961 
962  headers.Add( _( "Netclasses" ) );
963 
964  wxArrayString defaultItem;
965  defaultItem.Add( _( "Default" ) );
966  items.emplace_back( defaultItem );
967 
968  for( const auto& ii : netSettings.m_NetClasses )
969  {
970  wxArrayString item;
971  item.Add( ii.first );
972  items.emplace_back( item );
973  }
974 
975  EDA_LIST_DIALOG dlg( m_frame, _( "Assign Netclass" ), headers, items, netclassName );
976  dlg.SetListLabel( _( "Select netclass:" ) );
977 
978  if( dlg.ShowModal() == wxID_OK )
979  {
980  netclassName = dlg.GetTextSelection();
981 
982  for( auto& netName : netNames )
983  {
984  // Remove from old netclass membership list
985  if( netSettings.m_NetClassAssignments.count( netName ) )
986  {
987  const wxString oldNetclassName = netSettings.m_NetClassAssignments[netName];
988  NETCLASSPTR oldNetclass = netSettings.m_NetClasses.Find( oldNetclassName );
989 
990  if( oldNetclass )
991  oldNetclass->Remove( netName );
992  }
993 
994  // Add to new netclass membership list
995  NETCLASSPTR newNetclass = netSettings.m_NetClasses.Find( netclassName );
996 
997  if( newNetclass )
998  newNetclass->Add( netName );
999 
1000  netSettings.m_NetClassAssignments[netName] = netclassName;
1001  netSettings.ResolveNetClassAssignments();
1002  }
1003  }
1004  }
1005 
1007  return 0;
1008 }
1009 
1010 
1012 {
1014  CONNECTION_GRAPH* connectionGraph = m_frame->Schematic().ConnectionGraph();
1015  std::vector<EDA_ITEM*> itemsToRedraw;
1016  const SCH_CONNECTION* selectedConn = m_frame->GetHighlightedConnection();
1017 
1018  if( !screen )
1019  return 0;
1020 
1021  bool selectedIsBus = selectedConn ? selectedConn->IsBus() : false;
1022  wxString selectedName = selectedConn ? selectedConn->Name() : "";
1023 
1024  bool selectedIsNoNet = false;
1025  CONNECTION_SUBGRAPH* selectedSubgraph = nullptr;
1026 
1027  if( selectedConn && selectedConn->Driver() == nullptr )
1028  {
1029  selectedIsNoNet = true;
1030  selectedSubgraph = connectionGraph->GetSubgraphForItem( selectedConn->Parent() );
1031  }
1032 
1033  for( SCH_ITEM* item : screen->Items() )
1034  {
1035  SCH_CONNECTION* itemConn = nullptr;
1036  SCH_SYMBOL* symbol = nullptr;
1037  bool redraw = item->IsBrightened();
1038  bool highlight = false;
1039 
1040  if( item->Type() == SCH_SYMBOL_T )
1041  symbol = static_cast<SCH_SYMBOL*>( item );
1042 
1043  if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1044  itemConn = symbol->Connection();
1045  else
1046  itemConn = item->Connection();
1047 
1048  if( selectedIsNoNet && selectedSubgraph )
1049  {
1050  for( SCH_ITEM* subgraphItem : selectedSubgraph->m_items )
1051  {
1052  if( item == subgraphItem )
1053  {
1054  highlight = true;
1055  break;
1056  }
1057  }
1058  }
1059  else if( selectedIsBus && itemConn && itemConn->IsNet() )
1060  {
1061  for( const std::shared_ptr<SCH_CONNECTION>& member : selectedConn->Members() )
1062  {
1063  if( member->Name() == itemConn->Name() )
1064  {
1065  highlight = true;
1066  break;
1067  }
1068  else if( member->IsBus() )
1069  {
1070  for( const std::shared_ptr<SCH_CONNECTION>& child_member : member->Members() )
1071  {
1072  if( child_member->Name() == itemConn->Name() )
1073  {
1074  highlight = true;
1075  break;
1076  }
1077  }
1078  }
1079  }
1080  }
1081  else if( selectedConn && itemConn && selectedName == itemConn->Name() )
1082  {
1083  highlight = true;
1084  }
1085 
1086  if( highlight )
1087  item->SetBrightened();
1088  else
1089  item->ClearBrightened();
1090 
1091  redraw |= item->IsBrightened();
1092 
1093  // symbol is only non-null if the item is a SCH_SYMBOL_T
1094  if( symbol )
1095  {
1096  redraw |= symbol->HasBrightenedPins();
1097 
1098  symbol->ClearBrightenedPins();
1099 
1100  for( SCH_PIN* pin : symbol->GetPins() )
1101  {
1102  SCH_CONNECTION* pin_conn = pin->Connection();
1103 
1104  if( pin_conn && pin_conn->Name() == selectedName )
1105  {
1106  pin->SetBrightened();
1107  redraw = true;
1108  }
1109  }
1110 
1111  if( symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1112  {
1113  std::vector<SCH_FIELD>& fields = symbol->GetFields();
1114 
1115  for( int id : { REFERENCE_FIELD, VALUE_FIELD } )
1116  {
1117  if( item->IsBrightened() && fields[id].IsVisible() )
1118  fields[id].SetBrightened();
1119  else
1120  fields[id].ClearBrightened();
1121  }
1122  }
1123  }
1124  else if( item->Type() == SCH_SHEET_T )
1125  {
1126  for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
1127  {
1128  SCH_CONNECTION* pin_conn = pin->Connection();
1129  bool redrawPin = pin->IsBrightened();
1130 
1131  if( pin_conn && pin_conn->Name() == selectedName )
1132  pin->SetBrightened();
1133  else
1134  pin->ClearBrightened();
1135 
1136  redrawPin ^= pin->IsBrightened();
1137  redraw |= redrawPin;
1138  }
1139  }
1140 
1141  if( redraw )
1142  itemsToRedraw.push_back( item );
1143  }
1144 
1145  // Be sure highlight change will be redrawn
1146  KIGFX::VIEW* view = getView();
1147 
1148  for( EDA_ITEM* redrawItem : itemsToRedraw )
1150 
1151  m_frame->GetCanvas()->Refresh();
1152 
1153  return 0;
1154 }
1155 
1156 
1158 {
1159  // TODO(JE) remove once real-time connectivity is a given
1160  if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
1162 
1163  std::string tool = aEvent.GetCommandStr().get();
1164  PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
1165 
1166  // Deactivate other tools; particularly important if another PICKER is currently running
1167  Activate();
1168 
1169  picker->SetCursor( KICURSOR::BULLSEYE );
1170  picker->SetSnapping( false );
1171 
1172  picker->SetClickHandler(
1173  [this] ( const VECTOR2D& aPos )
1174  {
1175  return highlightNet( m_toolMgr, aPos );
1176  } );
1177 
1178  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1179 
1180  return 0;
1181 }
1182 
1183 
1185 {
1186  if( m_frame->GetUndoCommandCount() <= 0 )
1187  return 0;
1188 
1189  // Inform tools that undo command was issued
1191 
1192  /* Get the old list */
1194  size_t num_undos = m_frame->m_undoList.m_CommandsList.size();
1195 
1196  /* Undo the command */
1198 
1202 
1203  // If we modified anything during cleanup we don't want it going on the undolist
1204  while( m_frame->m_undoList.m_CommandsList.size() > num_undos )
1205  delete m_frame->PopCommandFromUndoList();
1206 
1207  // Now push the old command to the RedoList
1208  List->ReversePickersListOrder();
1209  m_frame->PushCommandToRedoList( List );
1210 
1211  m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1212 
1213  m_frame->SyncView();
1214  m_frame->GetCanvas()->Refresh();
1215  m_frame->OnModify();
1216 
1217  return 0;
1218 }
1219 
1220 
1222 {
1223  if( m_frame->GetRedoCommandCount() == 0 )
1224  return 0;
1225 
1226  // Inform tools that undo command was issued
1228 
1229  /* Get the old list */
1231 
1232  /* Redo the command: */
1234 
1235  /* Put the old list in UndoList */
1236  list->ReversePickersListOrder();
1237  m_frame->PushCommandToUndoList( list );
1238 
1242 
1243  m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1244 
1245  m_frame->SyncView();
1246  m_frame->GetCanvas()->Refresh();
1247  m_frame->OnModify();
1248 
1249  return 0;
1250 }
1251 
1252 
1253 bool SCH_EDITOR_CONTROL::doCopy( bool aUseLocalClipboard )
1254 {
1256  EE_SELECTION& selection = selTool->RequestSelection();
1257  SCHEMATIC& schematic = m_frame->Schematic();
1258 
1259  if( !selection.GetSize() )
1260  return false;
1261 
1262  selection.SetScreen( m_frame->GetScreen() );
1263  m_supplementaryClipboard.clear();
1264 
1265  for( EDA_ITEM* item : selection )
1266  {
1267  if( item->Type() == SCH_SHEET_T )
1268  {
1269  SCH_SHEET* sheet = (SCH_SHEET*) item;
1270  m_supplementaryClipboard[ sheet->GetFileName() ] = sheet->GetScreen();
1271  }
1272  }
1273 
1274  STRING_FORMATTER formatter;
1275  SCH_SEXPR_PLUGIN plugin;
1276  SCH_SHEET_LIST hierarchy = schematic.GetSheets();
1277  SCH_SHEET_PATH selPath = m_frame->GetCurrentSheet();
1278 
1279  plugin.Format( &selection, &selPath, &hierarchy, &formatter );
1280 
1281  if( aUseLocalClipboard )
1282  {
1283  m_localClipboard = formatter.GetString();
1284  return true;
1285  }
1286 
1287  return m_toolMgr->SaveClipboard( formatter.GetString() );
1288 }
1289 
1290 
1291 bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename,
1292  SCH_SCREEN** aScreen )
1293 {
1294  if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
1295  {
1296  *aScreen = m_supplementaryClipboard[ aSheetFilename ];
1297  return true;
1298  }
1299 
1300  return false;
1301 }
1302 
1303 
1305 {
1306  doCopy( true ); // Use the local clipboard
1307  Paste( aEvent );
1308 
1309  return 0;
1310 }
1311 
1312 
1314 {
1315  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1316 
1317  if( textEntry )
1318  {
1319  textEntry->Cut();
1320  return 0;
1321  }
1322 
1323  if( doCopy() )
1325 
1326  return 0;
1327 }
1328 
1329 
1331 {
1332  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1333 
1334  if( textEntry )
1335  {
1336  textEntry->Copy();
1337  return 0;
1338  }
1339 
1340  doCopy();
1341 
1342  return 0;
1343 }
1344 
1345 
1347  const SCH_SHEET_PATH& aPastePath,
1348  const KIID_PATH& aClipPath,
1349  bool aForceKeepAnnotations )
1350 {
1351  KIID_PATH clipItemPath = aClipPath;
1352  clipItemPath.push_back( aSymbol->m_Uuid );
1353 
1354  wxString reference, value, footprint;
1355  int unit;
1356 
1357  if( m_clipboardSymbolInstances.count( clipItemPath ) > 0 )
1358  {
1359  SYMBOL_INSTANCE_REFERENCE instance = m_clipboardSymbolInstances.at( clipItemPath );
1360 
1361  unit = instance.m_Unit;
1362  reference = instance.m_Reference;
1363  value = instance.m_Value;
1364  footprint = instance.m_Footprint;
1365  }
1366  else
1367  {
1368  // Pasted from notepad or an older instance of eeschema.
1369  // Use the values in the fields instead
1370  reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
1371  value = aSymbol->GetField( VALUE_FIELD )->GetText();
1372  footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetText();
1373  unit = aSymbol->GetUnit();
1374  }
1375 
1376  if( aForceKeepAnnotations && !reference.IsEmpty() )
1377  {
1378  aSymbol->SetRef( &aPastePath, reference );
1379  aSymbol->SetValue( &aPastePath, value );
1380  aSymbol->SetFootprint( &aPastePath, footprint );
1381  }
1382  else
1383  {
1384  aSymbol->ClearAnnotation( &aPastePath );
1385  }
1386 
1387  // We might clear annotations but always leave the original unit number from the paste
1388  aSymbol->SetUnitSelection( &aPastePath, unit );
1389  aSymbol->SetUnit( unit );
1390 }
1391 
1392 
1394  const KIID_PATH& aClipPath, SCH_SHEET* aSheet,
1395  bool aForceKeepAnnotations,
1396  SCH_SHEET_LIST* aPastedSheetsSoFar,
1397  SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
1398 {
1399  SCH_SHEET_PATH sheetPath = aPastePath;
1400  sheetPath.push_back( aSheet );
1401 
1402  aSheet->AddInstance( sheetPath.Path() );
1403 
1404  wxString pageNum;
1405 
1406  if( m_clipboardSheetInstances.count( aClipPath ) > 0 )
1407  pageNum = m_clipboardSheetInstances.at( aClipPath ).m_PageNumber;
1408  else
1409  pageNum = wxString::Format( "%d", static_cast<int>( aPastedSheetsSoFar->size() ) );
1410 
1411  aSheet->SetPageNumber( sheetPath, pageNum );
1412  aPastedSheetsSoFar->push_back( sheetPath );
1413 
1414  if( aSheet->GetScreen() == nullptr )
1415  return sheetPath; // We can only really set the page number but not load any items
1416 
1417  for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
1418  {
1419  if( item->Type() == SCH_SYMBOL_T )
1420  {
1421  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1422 
1423  updatePastedSymbol( symbol, aSheet->GetScreen(), sheetPath, aClipPath,
1424  aForceKeepAnnotations );
1425  }
1426  else if( item->Type() == SCH_SHEET_T )
1427  {
1428  SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
1429 
1430  KIID_PATH newClipPath = aClipPath;
1431  newClipPath.push_back( subsheet->m_Uuid );
1432 
1433  updatePastedSheet( sheetPath, newClipPath, subsheet, aForceKeepAnnotations,
1434  aPastedSheetsSoFar, aPastedSymbolsSoFar );
1435 
1436  SCH_SHEET_PATH subSheetPath = sheetPath;
1437  subSheetPath.push_back( subsheet );
1438 
1439  subSheetPath.GetSymbols( *aPastedSymbolsSoFar );
1440  }
1441  }
1442 
1443  return sheetPath;
1444 }
1445 
1446 
1448 {
1449  m_clipboardSheetInstances.clear();
1450 
1451  for( const SCH_SHEET_INSTANCE& sheet : aPastedScreen->GetSheetInstances() )
1452  m_clipboardSheetInstances[sheet.m_Path] = sheet;
1453 
1455 
1456  for( const SYMBOL_INSTANCE_REFERENCE& symbol : aPastedScreen->GetSymbolInstances() )
1457  m_clipboardSymbolInstances[symbol.m_Path] = symbol;
1458 }
1459 
1460 
1462 {
1463  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1464 
1465  if( textEntry )
1466  {
1467  textEntry->Paste();
1468  return 0;
1469  }
1470 
1472  std::string text;
1473 
1474  if( aEvent.IsAction( &ACTIONS::duplicate ) )
1476  else
1478 
1479  if( text.empty() )
1480  return 0;
1481 
1482  STRING_LINE_READER reader( text, "Clipboard" );
1483  SCH_SEXPR_PLUGIN plugin;
1484 
1485  SCH_SHEET paste_sheet;
1486  SCH_SCREEN* paste_screen = new SCH_SCREEN( &m_frame->Schematic() );
1487 
1488  // Screen object on heap is owned by the sheet.
1489  paste_sheet.SetScreen( paste_screen );
1490 
1491  try
1492  {
1493  plugin.LoadContent( reader, &paste_sheet );
1494  }
1495  catch( IO_ERROR& )
1496  {
1497  // If it wasn't content, then paste as text
1498  paste_screen->Append( new SCH_TEXT( wxPoint( 0, 0 ), text ) );
1499  }
1500 
1501  // Save loaded screen instances to m_clipboardSheetInstances
1502  setClipboardInstances( paste_screen );
1503 
1505 
1506  if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
1507  {
1508  DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
1509 
1510  if( dlg.ShowModal() == wxID_CANCEL )
1511  return 0;
1512  }
1513 
1514  bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
1515 
1516  // SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
1517  // else. Pull them back out to start with.
1518  //
1519  EDA_ITEMS loadedItems;
1520  bool sheetsPasted = false;
1521  SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
1522  SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
1523  wxFileName destFn = pasteRoot.Last()->GetFileName();
1524 
1525  if( destFn.IsRelative() )
1526  destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1527 
1528  // List of paths in the hierarchy that refer to the destination sheet of the paste
1529  SCH_SHEET_LIST pasteInstances = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
1530  pasteInstances.SortByPageNumbers();
1531 
1532  // Build a list of screens from the current design (to avoid loading sheets that already exist)
1533  std::map<wxString, SCH_SCREEN*> loadedScreens;
1534 
1535  for( const SCH_SHEET_PATH& item : hierarchy )
1536  {
1537  if( item.LastScreen() )
1538  loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
1539  }
1540 
1541  // Build symbol list for reannotation of duplicates
1542  SCH_SHEET_LIST sheets = m_frame->Schematic().GetSheets();
1543  SCH_REFERENCE_LIST existingRefs;
1544  sheets.GetSymbols( existingRefs );
1545  existingRefs.SortByReferenceOnly();
1546 
1547  // Keep track of pasted sheets and symbols for the different
1548  // paths to the hierarchy
1549  std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
1550  std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
1551 
1552  for( SCH_ITEM* item : paste_screen->Items() )
1553  {
1554  loadedItems.push_back( item );
1555 
1556  //@todo: we might want to sort the sheets by page number before adding to loadedItems
1557  if( item->Type() == SCH_SHEET_T )
1558  {
1559  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1560  wxFileName srcFn = sheet->GetFileName();
1561 
1562  if( srcFn.IsRelative() )
1563  srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1564 
1565  SCH_SHEET_LIST sheetHierarchy( sheet );
1566 
1567  if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
1568  {
1569  auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
1570  "was dropped because the destination already has "
1571  "the sheet or one of its subsheets as a parent." ),
1572  sheet->GetFileName() );
1573  DisplayError( m_frame, msg );
1574  loadedItems.pop_back();
1575  }
1576  }
1577  }
1578 
1579  // Remove the references from our temporary screen to prevent freeing on the DTOR
1580  paste_screen->Clear( false );
1581 
1582  for( unsigned i = 0; i < loadedItems.size(); ++i )
1583  {
1584  EDA_ITEM* item = loadedItems[i];
1585  KIID_PATH clipPath( wxT("/") ); // clipboard is at root
1586 
1587  if( item->Type() == SCH_SYMBOL_T )
1588  {
1589  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1590 
1591  // The library symbol gets set from the cached library symbols in the current
1592  // schematic not the symbol libraries. The cached library symbol may have
1593  // changed from the original library symbol which would cause the copy to
1594  // be incorrect.
1595  SCH_SCREEN* currentScreen = m_frame->GetScreen();
1596 
1597  wxCHECK2( currentScreen, continue );
1598 
1599  auto it = currentScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1600  auto end = currentScreen->GetLibSymbols().end();
1601 
1602  if( it == end )
1603  {
1604  // If can't find library definition in the design, use the pasted library
1605  it = paste_screen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1606  end = paste_screen->GetLibSymbols().end();
1607  }
1608 
1609  LIB_SYMBOL* libSymbol = nullptr;
1610 
1611  if( it != end )
1612  {
1613  libSymbol = new LIB_SYMBOL( *it->second );
1614  symbol->SetLibSymbol( libSymbol );
1615  }
1616 
1617  for( SCH_SHEET_PATH& instance : pasteInstances )
1618  {
1619  updatePastedSymbol( symbol, paste_screen, instance, clipPath,
1620  forceKeepAnnotations );
1621  }
1622 
1623  // Assign a new KIID
1624  const_cast<KIID&>( item->m_Uuid ) = KIID();
1625 
1626  // Make sure pins get a new UUID
1627  for( SCH_PIN* pin : symbol->GetPins() )
1628  const_cast<KIID&>( pin->m_Uuid ) = KIID();
1629 
1630  for( SCH_SHEET_PATH& instance : pasteInstances )
1631  {
1632  // Ignore pseudo-symbols (e.g. power symbols) and symbols from a non-existant
1633  // library.
1634  if( libSymbol && symbol->GetRef( &instance )[0] != wxT( '#' ) )
1635  {
1636  SCH_REFERENCE schReference( symbol, libSymbol, instance );
1637  schReference.SetSheetNumber( instance.GetVirtualPageNumber() );
1638  pastedSymbols[instance].AddItem( schReference );
1639  }
1640  }
1641  }
1642  else if( item->Type() == SCH_SHEET_T )
1643  {
1644  SCH_SHEET* sheet = (SCH_SHEET*) item;
1645  SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
1646  wxString baseName = nameField.GetText();
1647  wxString candidateName = baseName;
1648  wxString number;
1649 
1650  while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
1651  {
1652  number = baseName.Last() + number;
1653  baseName.RemoveLast();
1654  }
1655  // Update hierarchy to include any other sheets we already added, avoiding
1656  // duplicate sheet names
1657  hierarchy = m_frame->Schematic().GetSheets();
1658 
1659  //@todo: it might be better to just iterate through the sheet names
1660  // in this screen instead of the whole hierarchy.
1661  int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
1662 
1663  while( hierarchy.NameExists( candidateName ) )
1664  candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
1665 
1666  nameField.SetText( candidateName );
1667 
1668  wxFileName fn = sheet->GetFileName();
1669  SCH_SCREEN* existingScreen = nullptr;
1670 
1671  sheet->SetParent( pasteRoot.Last() );
1672  sheet->SetScreen( nullptr );
1673 
1674  if( !fn.IsAbsolute() )
1675  {
1676  wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
1677  fn.Normalize( wxPATH_NORM_ALL, currentSheetFileName.GetPath() );
1678  }
1679 
1680  // Try to find the screen for the pasted sheet by several means
1681  if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
1682  &existingScreen ) )
1683  {
1684  if( loadedScreens.count( sheet->GetFileName() ) > 0 )
1685  existingScreen = loadedScreens.at( sheet->GetFileName() );
1686  else
1687  searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
1688  }
1689 
1690  if( existingScreen )
1691  {
1692  sheet->SetScreen( existingScreen );
1693  }
1694  else
1695  {
1696  if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
1697  m_frame->InitSheet( sheet, sheet->GetFileName() );
1698  }
1699 
1700  sheetsPasted = true;
1701 
1702  // Push it to the clipboard path while it still has its old KIID
1703  clipPath.push_back( sheet->m_Uuid );
1704 
1705  // Assign a new KIID to the pasted sheet
1706  const_cast<KIID&>( sheet->m_Uuid ) = KIID();
1707 
1708  // Make sure pins get a new UUID
1709  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1710  const_cast<KIID&>( pin->m_Uuid ) = KIID();
1711 
1712  // Once we have our new KIID we can update all pasted instances. This will either
1713  // reset the annotations or copy "kept" annotations from the supplementary clipboard.
1714  for( SCH_SHEET_PATH& instance : pasteInstances )
1715  {
1716  SCH_SHEET_PATH sheetPath = updatePastedSheet( instance, clipPath, sheet,
1717  forceKeepAnnotations,
1718  &pastedSheets[instance],
1719  &pastedSymbols[instance] );
1720 
1721  sheetPath.GetSymbols( pastedSymbols[instance] );
1722  }
1723  }
1724  else
1725  {
1726  // Everything gets a new KIID
1727  const_cast<KIID&>( item->m_Uuid ) = KIID();
1728  }
1729 
1730  item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
1732 
1733  // Reset flags for subsequent move operation
1734  item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
1735  // Start out hidden so the pasted items aren't "ghosted" in their original location
1736  // before being moved to the current location.
1737  getView()->Hide( item, true );
1738  }
1739 
1740  pasteInstances.SortByPageNumbers();
1741 
1742  if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
1743  {
1744  for( SCH_SHEET_PATH& instance : pasteInstances )
1745  {
1746  pastedSymbols[instance].SortByReferenceOnly();
1747  pastedSymbols[instance].ReannotateDuplicates( existingRefs );
1748  pastedSymbols[instance].UpdateAnnotation();
1749 
1750  // Update existing refs for next iteration
1751  for( size_t i = 0; i < pastedSymbols[instance].GetCount(); i++ )
1752  existingRefs.AddItem( pastedSymbols[instance][i] );
1753  }
1754  }
1755 
1757 
1758  if( sheetsPasted )
1759  {
1760  // Update page numbers: Find next free numeric page number
1761  for( SCH_SHEET_PATH& instance : pasteInstances )
1762  {
1763  pastedSheets[instance].SortByPageNumbers();
1764 
1765  for( SCH_SHEET_PATH& pastedSheet : pastedSheets[instance] )
1766  {
1767  int page = 1;
1768  wxString pageNum = wxString::Format( "%d", page );
1769 
1770  while( hierarchy.PageNumberExists( pageNum ) )
1771  pageNum = wxString::Format( "%d", ++page );
1772 
1773  pastedSheet.SetPageNumber( pageNum );
1774  hierarchy.push_back( pastedSheet );
1775  }
1776  }
1777 
1780  }
1781 
1782  // Now clear the previous selection, select the pasted items, and fire up the "move"
1783  // tool.
1784  //
1786  m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &loadedItems );
1787 
1788  EE_SELECTION& selection = selTool->GetSelection();
1789 
1790  if( !selection.Empty() )
1791  {
1792  SCH_ITEM* item = (SCH_ITEM*) selection.GetTopLeftItem();
1793 
1794  selection.SetReferencePoint( item->GetPosition() );
1796  }
1797 
1798  return 0;
1799 }
1800 
1801 
1803 {
1805  EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SymbolsOnly );
1806  SCH_SYMBOL* symbol = nullptr;
1807  SYMBOL_EDIT_FRAME* symbolEditor;
1808 
1809  if( selection.GetSize() >= 1 )
1810  symbol = (SCH_SYMBOL*) selection.Front();
1811 
1812  if( !symbol || symbol->GetEditFlags() != 0 )
1813  return 0;
1814 
1816  symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
1817 
1818  if( symbolEditor )
1819  symbolEditor->LoadSymbolFromSchematic( symbol );
1820 
1821  return 0;
1822 }
1823 
1824 
1826 {
1827  wxCommandEvent dummy;
1828  m_frame->OnAnnotate( dummy );
1829  return 0;
1830 }
1831 
1832 
1834 {
1835  wxCommandEvent dummy;
1837  return 0;
1838 }
1839 
1840 
1842 {
1844  dlg.ShowQuasiModal();
1845  return 0;
1846 }
1847 
1848 
1850 {
1852  m_frame->HardRedraw();
1853 
1854  return 0;
1855 }
1856 
1857 
1859 {
1860  wxCommandEvent dummy;
1862  return 0;
1863 }
1864 
1865 
1867 {
1868  wxCommandEvent dummy;
1870  return 0;
1871 }
1872 
1873 
1875 {
1877  dlg.ShowModal();
1878  return 0;
1879 }
1880 
1881 
1883 {
1884  int result = NET_PLUGIN_CHANGE;
1885 
1886  // If a plugin is removed or added, rebuild and reopen the new dialog
1887  while( result == NET_PLUGIN_CHANGE )
1888  result = InvokeDialogNetList( m_frame );
1889 
1890  return 0;
1891 }
1892 
1893 
1895 {
1897  return 0;
1898 }
1899 
1900 
1902 {
1904  return 0;
1905 }
1906 
1907 
1909 {
1911  return 0;
1912 }
1913 
1914 
1916 {
1918  const EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SheetsOnly );
1919 
1920  if( selection.GetSize() == 1 )
1921  {
1922  SCH_SHEET* sheet = (SCH_SHEET*) selection.Front();
1923 
1926 
1927  // Store the current zoom level into the current screen before switching
1929 
1930  m_frame->GetCurrentSheet().push_back( sheet );
1933  }
1934 
1935  return 0;
1936 }
1937 
1938 
1940 {
1941  if( m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root() )
1942  {
1945 
1946  // Store the current zoom level into the current screen before switching
1948 
1952  }
1953 
1954  return 0;
1955 }
1956 
1957 
1959 {
1962 
1963  KIGFX::SCH_PAINTER* painter = static_cast<KIGFX::SCH_PAINTER*>( getView()->GetPainter() );
1965 
1967  m_frame->GetCanvas()->Refresh();
1968 
1969  return 0;
1970 }
1971 
1972 
1974 {
1977 
1978  KIGFX::SCH_PAINTER* painter = static_cast<KIGFX::SCH_PAINTER*>( getView()->GetPainter() );
1980 
1982  m_frame->GetCanvas()->Refresh();
1983 
1984  return 0;
1985 }
1986 
1987 
1989 {
1991 
1992  return 0;
1993 }
1994 
1995 
1997 {
1998 
2000  return 0;
2001 }
2002 
2003 
2005 {
2006  Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
2007  Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
2008  Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
2012  Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
2013  Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
2014  Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
2015 
2018 
2027 
2032 
2033 #ifdef KICAD_SPICE
2034  Go( &SCH_EDITOR_CONTROL::SimProbe, EE_ACTIONS::simProbe.MakeEvent() );
2035  Go( &SCH_EDITOR_CONTROL::SimTune, EE_ACTIONS::simTune.MakeEvent() );
2036 #endif /* KICAD_SPICE */
2037 
2044 
2046 
2047  Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
2048  Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
2049  Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
2050  Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
2051  Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
2054 
2067 
2069 
2073 
2077 
2079 }
Field Reference of part, i.e. "IC21".
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:247
int TogglePythonConsole(const TOOL_EVENT &aEvent)
int Save(const TOOL_EVENT &aEvent)
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hide the item in the view (e.g.
Definition: view.cpp:1470
void SetSheetNumber(int aSheetNumber)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
bool rescueProject(RESCUER &aRescuer, bool aRunningOnDemand)
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
void ShowFindReplaceStatus(const wxString &aMsg, int aStatusTime)
int EditWithSymbolEditor(const TOOL_EVENT &aEvent)
int FindAndReplace(const TOOL_EVENT &aEvent)
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:49
void OnOpenCvpcb(wxCommandEvent &event)
void Save_File(bool doSaveAs=false)
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:44
const wxString & GetFileName() const
Definition: sch_screen.h:137
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
static TOOL_ACTION rescueSymbols
Definition: ee_actions.h:154
int Copy(const TOOL_EVENT &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:365
void doCrossProbeSchToPcb(const TOOL_EVENT &aEvent, bool aForce)
bool RescueLegacyProject(bool aRunningOnDemand)
static TOOL_ACTION findAndReplace
Definition: actions.h:77
int m_Threshold
Definition: collector.h:248
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:630
void UpdateNetHighlightStatus()
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
static TOOL_ACTION exportNetlist
Definition: ee_actions.h:161
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
wxFindReplaceData * GetFindReplaceData()
Get the find criteria (as set by the dialog).
static TOOL_ACTION navigateHierarchy
Definition: ee_actions.h:182
int ShowSchematicSetup(const TOOL_EVENT &aEvent)
NETCLASSPTR Find(const wxString &aName) const
Search this container for a NETCLASS given by aName.
Definition: netclass.cpp:132
int HighlightNetCursor(const TOOL_EVENT &aEvent)
static TOOL_ACTION assignFootprints
Definition: ee_actions.h:147
static TOOL_ACTION pageSettings
Definition: actions.h:56
void Format(SCH_SHEET *aSheet)
void RecalculateConnections(SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
SCH_SHEET_PATH * FindSheetForScreen(const SCH_SCREEN *aScreen)
Return a pointer to the first SCH_SHEET_PATH object (not necessarily the only one) using a particular...
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:666
void SaveProjectSettings() override
Save changes to the project settings to the project (.pro) file.
void SetUnit(int aUnit)
Change the unit number to aUnit.
Definition: sch_symbol.cpp:322
Holds all the data relating to one schematic.
Definition: schematic.h:59
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:200
const wxString & GetNetclassName(const wxString &aNetName) const
#define IS_NEW
New item, just created.
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Add a SCH_REFERENCE object to aReferences for each symbol in the list of sheets.
CONNECTION_GRAPH * ConnectionGraph() const override
Definition: schematic.h:131
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
This file is part of the common library.
void ReversePickersListOrder()
Reverse the order of pickers stored in this list.
static TOOL_ACTION doDelete
Definition: actions.h:72
Calculates the connectivity of a schematic and generates netlists.
void SetScreen(BASE_SCREEN *aScreen) override
const SCH_CONNECTION * GetHighlightedConnection() const
void Collect(SCH_SCREEN *aScreen, const KICAD_T aFilterList[], const wxPoint &aPos, int aUnit=0, int aConvert=0)
Scan a EDA_ITEM using this class's Inspector method which does the collection.
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:60
UNDO_REDO_CONTAINER m_undoList
static wxFindReplaceData g_markersOnly
bool PrjConfigChanged()
Return true if the project configuration was modified.
int Redo(const TOOL_EVENT &aEvent)
Clipboard support.
int NavigateHierarchy(const TOOL_EVENT &aEvent)
int EditSymbolFields(const TOOL_EVENT &aEvent)
void push_back(SCH_SHEET *aSheet)
Forwarded method from std::vector.
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:145
virtual void PushCommandToRedoList(PICKED_ITEMS_LIST *aItem)
Add a command to redo in the redo list.
const std::vector< SYMBOL_INSTANCE_REFERENCE > & GetSymbolInstances() const
Definition: sch_screen.h:453
KIID_PATH Path() const
Get the sheet path as an KIID_PATH.
void SendCrossProbeClearHighlight()
Tell Pcbnew to clear the existing highlighted net, if one exists.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
double m_LastZoomLevel
last value for the zoom level, useful in Eeschema when changing the current displayed sheet to reuse ...
Definition: sch_screen.h:475
void ClearAnnotation(const SCH_SHEET_PATH *aSheetPath)
Clear exiting symbol annotation.
void SetValue(const SCH_SHEET_PATH *sheet, const wxString &aValue)
Definition: sch_symbol.cpp:585
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:157
static TOOL_ACTION replaceAll
Definition: actions.h:81
int ReplaceAndFindNext(const TOOL_EVENT &aEvent)
static TOOL_ACTION cancelInteractive
Definition: actions.h:62
void UpdateAllItems(int aUpdateFlags)
Update all items in the view according to the given flags.
Definition: view.cpp:1415
void updatePastedSymbol(SCH_SYMBOL *aSymbol, SCH_SCREEN *aPasteScreen, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations)
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:702
void SetWksFileName(const wxString &aFilename)
void LoadSymbolFromSchematic(SCH_SYMBOL *aSymbol)
Load a symbol from the schematic to edit in place.
void SetBrightened()
Definition: eda_item.h:130
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:155
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
#define HITTEST_THRESHOLD_PIXELS
void UpdateTitle()
Set the main window title bar text.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
int New(const TOOL_EVENT &aEvent)
virtual void PushCommandToUndoList(PICKED_ITEMS_LIST *aItem)
Add a command to undo in the undo list.
Definition: erc.h:47
void InitSheet(SCH_SHEET *aSheet, const wxString &aNewFilename)
Definition: sheet.cpp:97
void DrawCurrentSheetToClipboard()
Use the wxWidgets print code to draw an image of the current sheet onto the clipboard.
Definition: sheet.cpp:474
NET_SETTINGS & NetSettings()
Definition: project_file.h:94
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:382
A dialog which shows:
virtual int GetRedoCommandCount() const
bool IsBrightened() const
Definition: eda_item.h:126
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
Schematic editor (Eeschema) main window.
int FindNext(const TOOL_EVENT &aEvent)
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:163
int InvokeDialogCreateBOM(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_BOM and return whatever DIALOG_BOM::ShowModal() returns.
Definition: dialog_bom.cpp:108
int ExplicitCrossProbeToPcb(const TOOL_EVENT &aEvent)
virtual PICKED_ITEMS_LIST * PopCommandFromRedoList()
Return the last command to undo and remove it from list, nothing is deleted.
void OnPageSettingsChange() override
Called when modifying the page settings.
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
void AddItem(const SCH_REFERENCE &aItem)
void ScriptingConsoleEnableDisable()
Toggles the scripting console visibility.
bool searchSupplementaryClipboard(const wxString &aSheetFilename, SCH_SCREEN **aScreen)
static TOOL_ACTION print
Definition: actions.h:57
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:432
int Annotate(const TOOL_EVENT &aEvent)
void DisplayCurrentSheet()
Draw the current sheet on the display.
Definition: hierarch.cpp:285
static const KICAD_T SheetsOnly[]
Definition: ee_collectors.h:46
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
int GenerateBOM(const TOOL_EVENT &aEvent)
void UpdateAllScreenReferences()
Update all the symbol references for this sheet path.
static TOOL_ACTION find
Definition: actions.h:76
int EditSymbolLibraryLinks(const TOOL_EVENT &aEvent)
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:103
Define a library symbol object.
Definition: lib_symbol.h:96
int CrossProbeToPcb(const TOOL_EVENT &aEvent)
Equivalent to the above, but initiated by the user.
void SetFootprint(const SCH_SHEET_PATH *sheet, const wxString &aFootprint)
Definition: sch_symbol.cpp:636
static TOOL_ACTION updateNetHighlighting
Definition: ee_actions.h:216
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:248
A subgraph is a set of items that are electrically connected on a single sheet.
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:122
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
int DrawSheetOnClipboard(const TOOL_EVENT &aEvent)
void SetUnitSelection(const SCH_SHEET_PATH *aSheet, int aUnitSelection)
Set the selected unit of this symbol on one sheet.
Definition: sch_symbol.cpp:538
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1136
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:204
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
void AddTuner(SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
int SaveAs(const TOOL_EVENT &aEvent)
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:164
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:269
Container to create a flattened list of symbols because in a complex hierarchy, a symbol can be used ...
void Clear(bool aFree=true)
Delete all draw items and clears the project settings.
Definition: sch_screen.cpp:215
int ToggleForceHV(const TOOL_EVENT &aEvent)
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
void pop_back()
Forwarded method from std::vector.
int HighlightNet(const TOOL_EVENT &aEvent)
< Highlight net under the cursor.
static TOOL_ACTION leaveSheet
Definition: ee_actions.h:181
void ClearBrightened()
Definition: eda_item.h:133
static TOOL_ACTION pickerTool
Definition: actions.h:155
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:131
EE_SELECTION & GetSelection()
Return the set of currently selected items.
static TOOL_ACTION updateFind
Definition: actions.h:82
EESCHEMA_SETTINGS * eeconfig() const
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Return either an existing selection (filtered), or the selection at the current cursor if the existin...
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:71
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:88
SCH_ITEM * nextMatch(SCH_SCREEN *aScreen, SCH_SHEET_PATH *aSheet, SCH_ITEM *aAfter, wxFindReplaceData *aData)
Advance the search and returns the next matching item after aAfter.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
static TOOL_ACTION annotate
Definition: ee_actions.h:138
Handle actions specific to the schematic editor.
Master controller class:
Definition: tool_manager.h:54
int EnterSheet(const TOOL_EVENT &aEvent)
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:87
int ShowPcbNew(const TOOL_EVENT &aEvent)
std::map< wxString, SCH_SCREEN * > m_supplementaryClipboard
int Paste(const TOOL_EVENT &aEvent)
static bool RescueProject(wxWindow *aParent, RESCUER &aRescuer, bool aRunningOnDemand)
static TOOL_ACTION showPcbNew
Definition: ee_actions.h:159
Definition: kiid.h:44
static TOOL_ACTION copy
Definition: actions.h:67
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:186
int UpdatePCB(const TOOL_EVENT &aEvent)
int ShowCvpcb(const TOOL_EVENT &aEvent)
void BrightenItem(EDA_ITEM *aItem)
static TOOL_ACTION highlightNetTool
Definition: ee_actions.h:217
static TOOL_ACTION showBusManager
Definition: ee_actions.h:149
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:164
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:139
Item needs to be redrawn.
Definition: view_item.h:57
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
int InvokeDialogPrintUsingPrinter(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_PRINT_USING_PRINTER and return whatever DIALOG_PRINT_USING_PRINTER::ShowModal(...
bool LoadSheetFromFile(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, const wxString &aFileName)
Load a the KiCad schematic file aFileName into the sheet aSheet.
Definition: sheet.cpp:105
NETCLASSES m_NetClasses
Definition: net_settings.h:40
#define IS_MOVING
Item being moved.
wxString Name(bool aIgnoreSheet=false) const
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
void TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
virtual int GetUndoCommandCount() const
int LeaveSheet(const TOOL_EVENT &aEvent)
int ToggleHiddenFields(const TOOL_EVENT &aEvent)
static TOOL_ACTION simTune
Definition: ee_actions.h:211
std::vector< PICKED_ITEMS_LIST * > m_CommandsList
int Print(const TOOL_EVENT &aEvent)
void HardRedraw() override
Rebuild the GAL and redraw the screen.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void SyncView()
Mark all items for refresh.
int ReplaceAll(const TOOL_EVENT &aEvent)
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:239
std::string GetClipboardUTF8() const
Return the information currently stored in the system clipboard.
int ShowQuasiModal()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
std::vector< SCH_ITEM * > m_items
static TOOL_ACTION open
Definition: actions.h:50
static TOOL_ACTION explicitCrossProbe
Definition: ee_actions.h:195
void ResolveNetClassAssignments(bool aRebuildFromScratch=false)
Explode the list of netclass assignments to include atomic members of composite labels (buses).
static TOOL_ACTION save
Definition: actions.h:51
void SetForceVisible(bool aEnable)
Set and clear force visible flag used to force the item to be drawn even if it's draw attribute is se...
Definition: eda_item.h:204
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() const
Definition: sch_screen.h:458
static TOOL_ACTION doNew
Definition: actions.h:44
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
int UpdateFind(const TOOL_EVENT &aEvent)
Notifies pcbnew about the selected item.
Generic, UI-independent tool event.
Definition: tool_event.h:152
Contains methods for drawing schematic-specific items.
Definition: sch_painter.h:133
size_t GetCandidateCount()
Return the number of rescue candidates found.
int Plot(const TOOL_EVENT &aEvent)
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:82
static TOOL_ACTION cut
Definition: actions.h:66
SCHEMATIC & Schematic() const
void UpdateHierarchyNavigator(bool aForceUpdate=false)
Run the Hierarchy Navigator dialog.
SCH_ITEM * Driver() const
static TOOL_ACTION showPythonConsole
Definition: ee_actions.h:206
bool doCopy(bool aUseLocalClipboard=false)
< copy selection to clipboard or to m_localClipboard if aUseLocalClipboard is true
Helper dialog and control classes.
int ImportFPAssignments(const TOOL_EVENT &aEvent)
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
A simple container for schematic symbol instance information.
Definition for symbol library class.
EDA_ITEM * GetParent() const
Definition: eda_item.h:115
An interface for classes handling user events controlling the view behavior such as zooming,...
static TOOL_ACTION quit
Definition: actions.h:59
#define _(s)
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:32
Subclass of SIM_PLOT_FRAME_BASE, which is generated by wxFormBuilder.
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:177
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:201
static TOOL_ACTION replaceAndFindNext
Definition: actions.h:80
static bool highlightNet(TOOL_MANAGER *aToolMgr, const VECTOR2D &aPosition)
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:418
static TOOL_ACTION plot
Definition: actions.h:58
void UpdateItems()
Iterate through the list of items that asked for updating and updates them.
Definition: view.cpp:1397
const std::string & GetString()
Definition: richio.h:438
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:43
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition: tool_event.h:357
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:65
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:507
bool DisableGridSnapping() const
Definition: tool_event.h:336
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:53
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:158
int ToggleHiddenPins(const TOOL_EVENT &aEvent)
A holder to handle information on schematic or board items.
wxString GetFileName() const
Return the filename corresponding to this sheet.
Definition: sch_sheet.h:315
int UpdateNetHighlighting(const TOOL_EVENT &aEvent)
Launch a tool to highlight nets.
void setClipboardInstances(const SCH_SCREEN *aPastedScreen)
static bool Replace(const wxFindReplaceData &aSearchData, wxString &aText)
Perform a text replace on aText using the find and replace criteria in aSearchData on items that supp...
Definition: eda_item.cpp:145
void OnUpdatePCB(wxCommandEvent &event)
static VECTOR2D CLEAR
void UnbrightenItem(EDA_ITEM *aItem)
int RemapSymbols(const TOOL_EVENT &aEvent)
std::map< KIID_PATH, SCH_SHEET_INSTANCE > m_clipboardSheetInstances
EDA_ITEM * GetNode(VECTOR2I aPosition)
Select node under cursor.
int Duplicate(const TOOL_EVENT &aEvent)
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format.
std::map< KIID_PATH, SYMBOL_INSTANCE_REFERENCE > m_clipboardSymbolInstances
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:97
Implementing SIM_PLOT_FRAME_BASE.
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:62
bool InvokeDialogEditSymbolsLibId(SCH_EDIT_FRAME *aCaller)
Run a dialog to modify the LIB_ID of symbols for instance when a symbol has moved from a symbol libra...
int AssignNetclass(const TOOL_EVENT &aEvent)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:54
PROJECT & Prj() const override
Return a reference to the project this schematic is part of.
Definition: schematic.h:75
static TOOL_ACTION pasteSpecial
Definition: actions.h:69
const KIID m_Uuid
Definition: eda_item.h:475
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
static wxString GetSpiceField(SPICE_FIELD aField, SCH_SYMBOL *aSymbol, unsigned aCtl)
Retrieve either the requested field value or the default value.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:184
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static bool m_allowRealTime
void OnAnnotate(wxCommandEvent &event)
bool HasBrightenedPins()
virtual SCH_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: sch_painter.h:142
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
TOOLS_HOLDER * GetToolHolder() const
Definition: tool_manager.h:294
int Open(const TOOL_EVENT &aEvent)
EDA_ITEM * GetTopLeftItem(bool onlyModules=false) const override
static TOOL_ACTION findNextMarker
Definition: actions.h:79
void ClearBrightenedPins()
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
SCH_SHEET_LIST GetSheets() const override
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:87
static TOOL_ACTION redo
Definition: actions.h:65
int PageSetup(const TOOL_EVENT &aEvent)
void ClearFindReplaceStatus()
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
bool IsNet() const
void SetHighlightedConnection(const SCH_CONNECTION *aConnection)
std::string m_localClipboard
SCH_SHEET & Root() const
Definition: schematic.h:92
A simple container for sheet instance information.
SCH_SHEET_PATH updatePastedSheet(const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, SCH_SHEET *aSheet, bool aForceKeepAnnotations, SCH_SHEET_LIST *aPastedSheetsSoFar, SCH_REFERENCE_LIST *aPastedSymbolsSoFar)
int Quit(const TOOL_EVENT &aEvent)
void AddItemToScreenAndUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItem, bool aUndoAppend)
Add an item to the schematic and adds the changes to the undo/redo container.
Schematic symbol object.
Definition: sch_symbol.h:78
int AddItemToSel(const TOOL_EVENT &aEvent)
SCH_SCREEN * LastScreen()
static TOOL_ACTION showSymbolEditor
Definition: actions.h:160
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
static TOOL_ACTION saveAs
Definition: actions.h:52
void Append(SCH_ITEM *aItem)
Definition: sch_screen.cpp:144
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
bool SelectPoint(const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems, EDA_ITEM **aItem=nullptr, bool *aSelectionCancelledFlag=nullptr, bool aCheckLocked=false, bool aAdd=false, bool aSubtract=false, bool aExclusiveOr=false)
This overload of SelectPoint will create an EE_COLLECTOR and collect hits at location aWhere before c...
static TOOL_ACTION toggleHiddenPins
Definition: ee_actions.h:191
Global action (toolbar/main menu event, global shortcut)
void SortByReferenceOnly()
Sort the list of references by reference.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
int ShowBusManager(const TOOL_EVENT &aEvent)
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
void SaveCopyInUndoList(SCH_SCREEN *aScreen, SCH_ITEM *aItemToCopy, UNDO_REDO aTypeCommand, bool aAppend)
Create a copy of the current schematic item, and put it in the undo list.
int Cut(const TOOL_EVENT &aEvent)
static TOOL_ACTION importFPAssignments
Definition: ee_actions.h:160
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
static TOOL_ACTION assignNetclass
Definition: ee_actions.h:148
wxString UnescapeString(const wxString &aSource)
Definition: string.cpp:222
void RollbackSchematicFromUndo()
Perform an undo of the last edit WITHOUT logging a corresponding redo.
void SetRef(const SCH_SHEET_PATH *aSheet, const wxString &aReference)
Set the reference for the given sheet path for this symbol.
Definition: sch_symbol.cpp:472
int RescueSymbols(const TOOL_EVENT &aEvent)
Perform rescue operations to recover old projects from before certain changes were made.
#define NAMELESS_PROJECT
default name for nameless projects
Definition: project.h:41
EE_RTREE & Items()
Definition: sch_screen.h:102
void GetSymbols(SCH_REFERENCE_LIST &aReferences, bool aIncludePowerSymbols=true, bool aForceIncludeOrphanSymbols=false) const
Adds SCH_REFERENCE object to aReferences for each symbol in the sheet.
void SortByPageNumbers(bool aUpdateVirtualPageNums=true)
Sort the list of sheets by page number.
int ClearHighlight(const TOOL_EVENT &aEvent)
Update net highlighting after an edit.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
void ShowFindReplaceDialog(bool aReplace)
Run the Find or Find & Replace dialog.
void OnOpenPcbnew(wxCommandEvent &event)
#define NET_PLUGIN_CHANGE
Create and shows NETLIST_DIALOG and returns whatever NETLIST_DIALOG::ShowModal() returns.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
void SetCrossProbeConnection(const SCH_CONNECTION *aConnection)
Send a connection (net or bus) to Pcbnew for highlighting.
void SetCurrentSheet(const SCH_SHEET_PATH &aPath) override
Definition: schematic.h:126
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:203
SCH_ITEM * Parent() const
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
int Undo(const TOOL_EVENT &aEvent)
static TOOL_ACTION enterSheet
Definition: ee_actions.h:180
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
static TOOL_ACTION clearHighlight
Definition: ee_actions.h:215
void Activate()
Run the tool.
SCH_SHEET_PATH & GetCurrentSheet() const
static const KICAD_T SymbolsOnly[]
Definition: ee_collectors.h:45
static TOOL_ACTION editWithLibEdit
Definition: ee_actions.h:158
static TOOL_ACTION move
Definition: ee_actions.h:110
static TOOL_ACTION simProbe
Definition: ee_actions.h:210
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void SetSnapping(bool aSnap)
Definition: picker_tool.h:64
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList)
Restore an undo or redo command to put data pointed by aList in the previous state.
static TOOL_ACTION undo
Definition: actions.h:64
void SendMessageToPCBNEW(EDA_ITEM *aObjectToSync, SCH_SYMBOL *aPart)
Send a message to Pcbnew via a socket connection.
static TOOL_ACTION generateBOM
Definition: ee_actions.h:162
CONNECTION_SUBGRAPH * GetSubgraphForItem(SCH_ITEM *aItem)
GAL_TYPE GetBackend() const
Return the type of backend currently used by GAL canvas.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
static TOOL_ACTION highlightNet
Definition: ee_actions.h:214
#define MAX_PAGE_SIZE_MILS
Definition: page_info.h:41
void InvokeDialogBusManager(SCH_EDIT_FRAME *aCaller)
Create and show DIALOG_BUS_MANAGER.
static TOOL_ACTION schematicSetup
Definition: ee_actions.h:150
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
SCH_SCREEN * RootScreen() const
Helper to retrieve the screen of the root sheet.
Definition: schematic.cpp:117
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:67
int GetUnit() const
Definition: sch_symbol.h:195
bool IsBus() const
double GetScale() const
Definition: view.h:263
void UpdateSymbolLinks(REPORTER *aReporter=nullptr)
Initialize the LIB_SYMBOL reference for each SCH_SYMBOL found in the full schematic.
void ShowSchematicSetupDialog(const wxString &aInitialPage=wxEmptyString)
static TOOL_ACTION editSymbolLibraryLinks
Definition: ee_actions.h:140
static TOOL_ACTION toggleForceHV
Definition: ee_actions.h:202
void FocusOnLocation(const wxPoint &aPos)
Useful to focus on a particular location, in find functions.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:240
int UpdateFromPCB(const TOOL_EVENT &aEvent)
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:414
bool m_RealTimeConnectivity
Do real-time connectivity.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:197
static TOOL_ACTION findNext
Definition: actions.h:78
SCH_SHEET_LIST FindAllSheetsForScreen(const SCH_SCREEN *aScreen) const
Return a SCH_SHEET_LIST with a copy of all the SCH_SHEET_PATH using a particular screen.
virtual void ClearUndoRedoList()
Clear the undo and redo list using ClearUndoORRedoList()
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:133
static TOOL_ACTION paste
Definition: actions.h:68
bool GetShowAllPins() const override
Allow edit frame to show/hide hidden pins.
static TOOL_ACTION duplicate
Definition: actions.h:71
A helper to define a symbol's reference designator in a schematic.
PRIORITY GetDriverPriority()
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
Definition: sch_symbol.cpp:857
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:551
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:144
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1503
int ExportNetlist(const TOOL_EVENT &aEvent)
bool AddInstance(const KIID_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1094
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
Field Name Module PCB, i.e. "16DIP300".
void SetListLabel(const wxString &aLabel)
The symbol library editor main window.
static TOOL_ACTION toggleHiddenFields
Definition: ee_actions.h:192