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 <connection_graph.h>
33 #include <project_rescue.h>
34 #include <erc.h>
35 #include <invoke_sch_dialog.h>
36 #include <string_utils.h>
37 #include <kiway.h>
38 #include <kiway_player.h>
40 #include <project/project_file.h>
41 #include <project/net_settings.h>
42 #include <sch_edit_frame.h>
44 #include <sch_line.h>
45 #include <sch_painter.h>
46 #include <sch_sheet.h>
47 #include <sch_sheet_pin.h>
48 #include <sch_view.h>
49 #include <schematic.h>
50 #include <advanced_config.h>
51 #include <sim/sim_plot_frame.h>
52 #include <symbol_viewer_frame.h>
53 #include <status_popup.h>
54 #include <tool/picker_tool.h>
55 #include <tool/tool_manager.h>
56 #include <tools/ee_actions.h>
57 #include <tools/ee_selection.h>
61 #include <dialog_update_from_pcb.h>
62 #include <eda_list_dialog.h>
63 
65 #include <sch_sheet_path.h>
66 #include <wx/filedlg.h>
67 
68 
69 int SCH_EDITOR_CONTROL::New( const TOOL_EVENT& aEvent )
70 {
72  return 0;
73 }
74 
75 
77 {
79  return 0;
80 }
81 
82 
84 {
86  return 0;
87 }
88 
89 
91 {
92  m_frame->SaveProject( true );
93  return 0;
94 }
95 
96 
98 {
99  SCH_SHEET* curr_sheet = m_frame->GetCurrentSheet().Last();
100  wxFileName curr_fn = curr_sheet->GetFileName();
101  wxFileDialog dlg( m_frame, _( "Schematic Files" ), curr_fn.GetPath(),
102  curr_fn.GetFullName(), KiCadSchematicFileWildcard(),
103  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
104 
105  if( dlg.ShowModal() == wxID_CANCEL )
106  return false;
107 
108  wxFileName newFileName = dlg.GetPath();
109  newFileName.SetExt( KiCadSchematicFileExtension );
110 
111  m_frame->saveSchematicFile( curr_sheet, newFileName.GetFullPath() );
112  return 0;
113 }
114 
115 
117 {
119  return 0;
120 }
121 
122 
124 {
125  PICKED_ITEMS_LIST undoCmd;
126  DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( m_frame );
127  ITEM_PICKER wrapper( m_frame->GetScreen(), undoItem, UNDO_REDO::PAGESETTINGS );
128 
129  undoCmd.PushItem( wrapper );
131 
134 
135  if( dlg.ShowModal() )
136  m_frame->OnModify();
137  else
139 
140  return 0;
141 }
142 
143 
145 {
146  SCH_SCREENS schematic( m_frame->Schematic().Root() );
147 
148  if( schematic.HasNoFullyDefinedLibIds() )
149  RescueLegacyProject( true );
150  else
152 
153  return 0;
154 }
155 
156 
157 bool SCH_EDITOR_CONTROL::RescueLegacyProject( bool aRunningOnDemand )
158 {
160  m_frame->GetCanvas()->GetBackend() );
161 
162  return rescueProject( rescuer, aRunningOnDemand );
163 }
164 
165 
167 {
170  m_frame->GetCanvas()->GetBackend() );
171 
172  return rescueProject( rescuer, aRunningOnDemand );
173 }
174 
175 
176 bool SCH_EDITOR_CONTROL::rescueProject( RESCUER& aRescuer, bool aRunningOnDemand )
177 {
178  if( !RESCUER::RescueProject( m_frame, aRescuer, aRunningOnDemand ) )
179  return false;
180 
181  if( aRescuer.GetCandidateCount() )
182  {
183  KIWAY_PLAYER* viewer = m_frame->Kiway().Player( FRAME_SCH_VIEWER, false );
184 
185  if( viewer )
186  static_cast<SYMBOL_VIEWER_FRAME*>( viewer )->ReCreateLibList();
187 
188  if( aRunningOnDemand )
189  {
190  SCH_SCREENS schematic( m_frame->Schematic().Root() );
191 
192  schematic.UpdateSymbolLinks();
194  }
195 
197  m_frame->SyncView();
198  m_frame->GetCanvas()->Refresh();
199  m_frame->OnModify();
200  }
201 
202  return true;
203 }
204 
205 
207 {
208  DIALOG_SYMBOL_REMAP dlgRemap( m_frame );
209 
210  dlgRemap.ShowQuasiModal();
211 
212  m_frame->GetCanvas()->Refresh( true );
213 
214  return 0;
215 }
216 
217 
219 {
220  if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
222 
224 
225  wxFileName fn = m_frame->Prj().AbsolutePath( m_frame->Schematic().RootScreen()->GetFileName() );
226 
227  if( fn.GetName() != NAMELESS_PROJECT )
229 
230  return 0;
231 }
232 
233 
235 {
236  if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
238 
240 
241  dlg.ShowModal();
242 
243  // save project config if the prj config has changed:
244  if( dlg.PrjConfigChanged() )
246 
247  return 0;
248 }
249 
250 
252 {
253  m_frame->Close( false );
254  return 0;
255 }
256 
257 
258 // A dummy wxFindReplaceData signaling any marker should be found
259 static wxFindReplaceData g_markersOnly;
260 
261 
263 {
265  return UpdateFind( aEvent );
266 }
267 
268 
270 {
272  return 0;
273 }
274 
275 
277 {
278  wxFindReplaceData& data = m_frame->GetFindReplaceData();
279 
280  auto visit =
281  [&]( EDA_ITEM* aItem, SCH_SHEET_PATH* aSheet )
282  {
283  // We may get triggered when the dialog is not opened due to binding
284  // SelectedItemsModified we also get triggered when the find dialog is
285  // closed....so we need to double check the dialog is open.
286  if( m_frame->m_findReplaceDialog != nullptr
287  && !data.GetFindString().IsEmpty()
288  && aItem->Matches( data, aSheet ) )
289  {
290  aItem->SetForceVisible( true );
291  m_selectionTool->BrightenItem( aItem );
292  }
293  else if( aItem->IsBrightened() )
294  {
295  aItem->SetForceVisible( false );
297  }
298  };
299 
300  if( aEvent.IsAction( &ACTIONS::find ) || aEvent.IsAction( &ACTIONS::findAndReplace )
301  || aEvent.IsAction( &ACTIONS::updateFind ) )
302  {
304 
305  for( SCH_ITEM* item : m_frame->GetScreen()->Items() )
306  {
307  visit( item, &m_frame->GetCurrentSheet() );
308 
309  item->RunOnChildren(
310  [&]( SCH_ITEM* aChild )
311  {
312  visit( aChild, &m_frame->GetCurrentSheet() );
313  } );
314  }
315  }
316  else if( aEvent.Matches( EVENTS::SelectedItemsModified ) )
317  {
318  for( EDA_ITEM* item : m_selectionTool->GetSelection() )
319  visit( item, &m_frame->GetCurrentSheet() );
320  }
321 
322  getView()->UpdateItems();
323  m_frame->GetCanvas()->Refresh();
324  m_frame->UpdateTitle();
325 
326  return 0;
327 }
328 
329 
331  SCH_ITEM* aAfter, wxFindReplaceData& aData )
332 {
333  bool past_item = true;
334 
335  if( aAfter != nullptr )
336  {
337  past_item = false;
338 
339  if( aAfter->Type() == SCH_PIN_T || aAfter->Type() == SCH_FIELD_T )
340  aAfter = static_cast<SCH_ITEM*>( aAfter->GetParent() );
341  }
342 
343  std::vector<SCH_ITEM*> sorted_items;
344 
345  for( SCH_ITEM* item : aScreen->Items() )
346  sorted_items.push_back( item );
347 
348  std::sort( sorted_items.begin(), sorted_items.end(),
349  [&]( SCH_ITEM* a, SCH_ITEM* b )
350  {
351  if( a->GetPosition().x == b->GetPosition().x )
352  {
353  // Ensure deterministic sort
354  if( a->GetPosition().y == b->GetPosition().y )
355  return a->m_Uuid < b->m_Uuid;
356 
357  return a->GetPosition().y < b->GetPosition().y;
358  }
359  else
360  return a->GetPosition().x < b->GetPosition().x;
361  }
362  );
363 
364  for( SCH_ITEM* item : sorted_items )
365  {
366  if( item == aAfter )
367  {
368  past_item = true;
369  }
370  else if( past_item )
371  {
372  if( &aData == &g_markersOnly && item->Type() == SCH_MARKER_T )
373  return item;
374 
375  if( item->Matches( aData, aSheet ) )
376  return item;
377 
378  if( item->Type() == SCH_SYMBOL_T )
379  {
380  SCH_SYMBOL* cmp = static_cast<SCH_SYMBOL*>( item );
381 
382  for( SCH_FIELD& field : cmp->GetFields() )
383  {
384  if( field.Matches( aData, aSheet ) )
385  return &field;
386  }
387 
388  for( SCH_PIN* pin : cmp->GetPins() )
389  {
390  if( pin->Matches( aData, aSheet ) )
391  return pin;
392  }
393  }
394 
395  if( item->Type() == SCH_SHEET_T )
396  {
397  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
398 
399  for( SCH_FIELD& field : sheet->GetFields() )
400  {
401  if( field.Matches( aData, aSheet ) )
402  return &field;
403  }
404 
405  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
406  {
407  if( pin->Matches( aData, aSheet ) )
408  return pin;
409  }
410  }
411  }
412  }
413 
414  return nullptr;
415 }
416 
417 
419 {
420  // A timer during which a subsequent FindNext will result in a wrap-around
421  static wxTimer wrapAroundTimer;
422 
423  wxFindReplaceData& data = m_frame->GetFindReplaceData();
424 
425  if( aEvent.IsAction( &ACTIONS::findNextMarker ) )
426  {
427  g_markersOnly.SetFlags( data.GetFlags() );
428 
429  data = g_markersOnly;
430  }
431  else if( data.GetFindString().IsEmpty() )
432  {
433  return FindAndReplace( ACTIONS::find.MakeEvent() );
434  }
435 
436  bool searchAllSheets = !( data.GetFlags() & FR_CURRENT_SHEET_ONLY );
437  EE_SELECTION& selection = m_selectionTool->GetSelection();
438  SCH_ITEM* afterItem = dynamic_cast<SCH_ITEM*>( selection.Front() );
439  SCH_ITEM* item = nullptr;
440 
441  SCH_SHEET_PATH* afterSheet = &m_frame->GetCurrentSheet();
442 
443  if( wrapAroundTimer.IsRunning() )
444  {
445  afterSheet = nullptr;
446  afterItem = nullptr;
447  wrapAroundTimer.Stop();
449  }
450 
452 
453  if( afterSheet || !searchAllSheets )
454  item = nextMatch( m_frame->GetScreen(), &m_frame->GetCurrentSheet(), afterItem, data );
455 
456  if( !item && searchAllSheets )
457  {
458  SCH_SCREENS screens( m_frame->Schematic().Root() );
459  std::vector<SCH_SHEET_PATH*> paths;
460 
461  screens.BuildClientSheetPathList();
462 
463  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
464  {
465  for( SCH_SHEET_PATH& sheet : screen->GetClientSheetPaths() )
466  paths.push_back( &sheet );
467  }
468 
469  std::sort( paths.begin(), paths.end(), [] ( const SCH_SHEET_PATH* lhs,
470  const SCH_SHEET_PATH* rhs ) -> bool
471  {
472  int retval = lhs->ComparePageNum( *rhs );
473 
474  if( retval < 0 )
475  return true;
476  else if( retval > 0 )
477  return false;
478  else
479  return lhs->GetCurrentHash() < rhs->GetCurrentHash();
480  } );
481 
482  for( SCH_SHEET_PATH* sheet : paths )
483  {
484  if( afterSheet )
485  {
486  if( afterSheet->GetPageNumber() == sheet->GetPageNumber() )
487  afterSheet = nullptr;
488 
489  continue;
490  }
491 
492  SCH_SCREEN* screen = sheet->LastScreen();
493 
494  item = nextMatch( screen, sheet, nullptr, data );
495 
496  if( item )
497  {
498  m_frame->Schematic().SetCurrentSheet( *sheet );
500 
501  screen->TestDanglingEnds();
502 
503  m_frame->SetScreen( screen );
505  UpdateFind( ACTIONS::updateFind.MakeEvent() );
506 
507  break;
508  }
509  }
510  }
511 
512  if( item )
513  {
514  m_selectionTool->AddItemToSel( item );
515  m_frame->FocusOnLocation( item->GetBoundingBox().GetCenter() );
516  m_frame->GetCanvas()->Refresh();
517  }
518  else
519  {
520  wxString msg = searchAllSheets ? _( "Reached end of schematic." )
521  : _( "Reached end of sheet." );
522 
523  // Show the popup during the time period the user can wrap the search
524  m_frame->ShowFindReplaceStatus( msg + wxS( " " ) +
525  _( "Find again to wrap around to the start." ), 4000 );
526  wrapAroundTimer.StartOnce( 4000 );
527  }
528 
529  return 0;
530 }
531 
532 
534 {
535  wxFindReplaceData& data = m_frame->GetFindReplaceData();
537 
538  return item && item->Matches( data, &m_frame->GetCurrentSheet() );
539 }
540 
541 
543 {
544  wxFindReplaceData& data = m_frame->GetFindReplaceData();
547 
548  if( data.GetFindString().IsEmpty() )
549  return FindAndReplace( ACTIONS::find.MakeEvent() );
550 
551  if( item && item->Matches( data, sheet ) )
552  {
553  if( item->Replace( data, sheet ) )
554  {
555  m_frame->UpdateItem( item, false, true );
557  m_frame->OnModify();
558  }
559 
560  FindNext( ACTIONS::findNext.MakeEvent() );
561  }
562 
563  return 0;
564 }
565 
566 
568 {
569  wxFindReplaceData& data = m_frame->GetFindReplaceData();
570  bool currentSheetOnly = ( data.GetFlags() & FR_CURRENT_SHEET_ONLY ) > 0;
571  bool modified = false;
572 
573  if( data.GetFindString().IsEmpty() )
574  return FindAndReplace( ACTIONS::find.MakeEvent() );
575 
576  auto doReplace =
577  [&]( SCH_ITEM* aItem, SCH_SHEET_PATH* aSheet, wxFindReplaceData& aData )
578  {
579  if( aItem->Replace( aData, aSheet ) )
580  {
581  m_frame->UpdateItem( aItem, false, true );
582  modified = true;
583  }
584  };
585 
586  if( currentSheetOnly )
587  {
588  SCH_SHEET_PATH* currentSheet = &m_frame->GetCurrentSheet();
589 
590  SCH_ITEM* item = nextMatch( m_frame->GetScreen(), currentSheet, nullptr, data );
591 
592  while( item )
593  {
594  doReplace( item, currentSheet, data );
595  item = nextMatch( m_frame->GetScreen(), currentSheet, item, data );
596  }
597  }
598  else
599  {
600  SCH_SHEET_LIST allSheets = m_frame->Schematic().GetSheets();
601  SCH_SCREENS screens( m_frame->Schematic().Root() );
602 
603  for( SCH_SCREEN* screen = screens.GetFirst(); screen; screen = screens.GetNext() )
604  {
605  SCH_SHEET_LIST sheets = allSheets.FindAllSheetsForScreen( screen );
606 
607  for( unsigned ii = 0; ii < sheets.size(); ++ii )
608  {
609  SCH_ITEM* item = nextMatch( screen, &sheets[ii], nullptr, data );
610 
611  while( item )
612  {
613  if( ii == 0 )
614  {
615  doReplace( item, &sheets[0], data );
616  }
617  else if( item->Type() == SCH_FIELD_T )
618  {
619  SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
620 
621  if( field->GetParent() && field->GetParent()->Type() == SCH_SYMBOL_T )
622  {
623  switch( field->GetId() )
624  {
625  case REFERENCE_FIELD:
626  case VALUE_FIELD:
627  case FOOTPRINT_FIELD:
628  // must be handled for each distinct sheet
629  doReplace( field, &sheets[ii], data );
630  break;
631 
632  default:
633  // handled in first iteration
634  break;
635  }
636  }
637  }
638 
639  item = nextMatch( screen, &sheets[ii], item, data );
640  }
641  }
642  }
643  }
644 
645  if( modified )
646  {
648  m_frame->OnModify();
649  }
650 
651  return 0;
652 }
653 
654 
656 {
657  doCrossProbeSchToPcb( aEvent, false );
658  return 0;
659 }
660 
661 
663 {
664  doCrossProbeSchToPcb( aEvent, true );
665  return 0;
666 }
667 
668 
669 void SCH_EDITOR_CONTROL::doCrossProbeSchToPcb( const TOOL_EVENT& aEvent, bool aForce )
670 {
671  // Don't get in an infinite loop SCH -> PCB -> SCH -> PCB -> SCH -> ...
672  if( m_probingPcbToSch )
673  return;
674 
676  SCH_ITEM* item = nullptr;
677  SCH_SYMBOL* symbol = nullptr;
678 
679  if( aForce )
680  {
681  EE_SELECTION& selection = selTool->RequestSelection();
682 
683  if( selection.GetSize() >= 1 )
684  item = (SCH_ITEM*) selection.Front();
685  }
686  else
687  {
688  EE_SELECTION& selection = selTool->GetSelection();
689 
690  if( selection.GetSize() >= 1 )
691  item = (SCH_ITEM*) selection.Front();
692  }
693 
694  if( !item )
695  {
696  if( aForce )
697  m_frame->SendMessageToPCBNEW( nullptr, nullptr );
698 
699  return;
700  }
701 
702 
703  switch( item->Type() )
704  {
705  case SCH_FIELD_T:
706  case LIB_FIELD_T:
707  if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T )
708  {
709  symbol = (SCH_SYMBOL*) item->GetParent();
710  m_frame->SendMessageToPCBNEW( item, symbol );
711  }
712  break;
713 
714  case SCH_SYMBOL_T:
715  symbol = (SCH_SYMBOL*) item;
716  m_frame->SendMessageToPCBNEW( item, symbol );
717  break;
718 
719  case SCH_PIN_T:
720  symbol = (SCH_SYMBOL*) item->GetParent();
721  m_frame->SendMessageToPCBNEW( static_cast<SCH_PIN*>( item ), symbol );
722  break;
723 
724  case SCH_SHEET_T:
725  if( aForce )
726  m_frame->SendMessageToPCBNEW( item, nullptr );
727  break;
728 
729  default:
730  break;
731  }
732 }
733 
734 
735 #ifdef KICAD_SPICE
736 
737 static KICAD_T wires[] = { SCH_LINE_LOCATE_WIRE_T, EOT };
738 static KICAD_T wiresAndPins[] = { SCH_LINE_LOCATE_WIRE_T, SCH_PIN_T, SCH_SHEET_PIN_T, EOT };
739 static KICAD_T fieldsAndSymbols[] = { SCH_SYMBOL_T, SCH_FIELD_T, EOT };
740 
741 #define HITTEST_THRESHOLD_PIXELS 5
742 
743 
744 int SCH_EDITOR_CONTROL::SimProbe( const TOOL_EVENT& aEvent )
745 {
747  SIM_PLOT_FRAME* simFrame = (SIM_PLOT_FRAME*) m_frame->Kiway().Player( FRAME_SIMULATOR, false );
748 
749  if( !simFrame ) // Defensive coding; shouldn't happen.
750  return 0;
751 
752  // Deactivate other tools; particularly important if another PICKER is currently running
753  Activate();
754 
756  picker->SetSnapping( false );
757 
758  picker->SetClickHandler(
759  [this, simFrame]( const VECTOR2D& aPosition )
760  {
762  EDA_ITEM* item = selTool->GetNode( aPosition );
763 
764  if( !item )
765  return false;
766 
767  if( item->IsType( wires ) )
768  {
769  if( SCH_CONNECTION* conn = static_cast<SCH_ITEM*>( item )->Connection() )
770  simFrame->AddVoltagePlot( UnescapeString( conn->Name() ) );
771  }
772  else if( item->Type() == SCH_PIN_T )
773  {
774  SCH_PIN* pin = (SCH_PIN*) item;
775  SCH_SYMBOL* symbol = (SCH_SYMBOL*) item->GetParent();
776  wxString ref = symbol->GetRef( &m_frame->GetCurrentSheet() );
777  wxString param;
778  wxString primitive;
779 
780  primitive = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, symbol, 0 );
781  primitive.LowerCase();
782 
783  if( primitive == "c" || primitive == "l" || primitive == "r" )
784  param = wxT( "I" );
785  else if( primitive == "d" )
786  param = wxT( "Id" );
787  else
788  param = wxString::Format( wxT( "I%s" ), pin->GetShownName().Lower() );
789 
790  simFrame->AddCurrentPlot( ref, param );
791  }
792 
793  return true;
794  } );
795 
796  picker->SetMotionHandler(
797  [this, picker]( const VECTOR2D& aPos )
798  {
799  EE_COLLECTOR collector;
800  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
801  collector.Collect( m_frame->GetScreen(), wiresAndPins, (wxPoint) aPos );
802 
804  selectionTool->GuessSelectionCandidates( collector, aPos );
805 
806  EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
807  SCH_LINE* wire = dynamic_cast<SCH_LINE*>( item );
808 
809  const SCH_CONNECTION* conn = nullptr;
810 
811  if( wire )
812  {
813  item = nullptr;
814  conn = wire->Connection();
815  }
816 
817  if( item && item->Type() == SCH_PIN_T )
819  else
821 
822  if( m_pickerItem != item )
823  {
824  if( m_pickerItem )
825  selectionTool->UnbrightenItem( m_pickerItem );
826 
827  m_pickerItem = item;
828 
829  if( m_pickerItem )
830  selectionTool->BrightenItem( m_pickerItem );
831  }
832 
833  if( m_frame->GetHighlightedConnection() != conn )
834  {
836 
837  TOOL_EVENT dummyEvent;
838  UpdateNetHighlighting( dummyEvent );
839  }
840  } );
841 
842  picker->SetFinalizeHandler(
843  [this]( const int& aFinalState )
844  {
845  if( m_pickerItem )
847 
849  {
850  m_frame->SetHighlightedConnection( nullptr );
851 
852  TOOL_EVENT dummyEvent;
853  UpdateNetHighlighting( dummyEvent );
854  }
855 
856  // Wake the selection tool after exiting to ensure the cursor gets updated
858  } );
859 
860  std::string tool = aEvent.GetCommandStr().get();
861  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
862 
863  return 0;
864 }
865 
866 
867 int SCH_EDITOR_CONTROL::SimTune( const TOOL_EVENT& aEvent )
868 {
870 
871  // Deactivate other tools; particularly important if another PICKER is currently running
872  Activate();
873 
874  picker->SetCursor( KICURSOR::TUNE );
875  picker->SetSnapping( false );
876 
877  picker->SetClickHandler(
878  [this]( const VECTOR2D& aPosition )
879  {
881  EDA_ITEM* item = nullptr;
882  selTool->SelectPoint( aPosition, fieldsAndSymbols, &item );
883 
884  if( !item )
885  return false;
886 
887  if( item->Type() != SCH_SYMBOL_T )
888  {
889  item = item->GetParent();
890 
891  if( item->Type() != SCH_SYMBOL_T )
892  return false;
893  }
894 
895  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
896  KIWAY_PLAYER* simFrame = m_frame->Kiway().Player( FRAME_SIMULATOR, false );
897 
898  if( simFrame )
899  static_cast<SIM_PLOT_FRAME*>( simFrame )->AddTuner( symbol );
900 
901  // We do not really want to keep a symbol selected in schematic,
902  // so clear the current selection
903  selTool->ClearSelection();
904  return true;
905  } );
906 
907  picker->SetMotionHandler(
908  [this]( const VECTOR2D& aPos )
909  {
910  EE_COLLECTOR collector;
911  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
912  collector.Collect( m_frame->GetScreen(), fieldsAndSymbols, (wxPoint) aPos );
913 
915  selectionTool->GuessSelectionCandidates( collector, aPos );
916 
917  EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
918 
919  if( m_pickerItem != item )
920  {
921  if( m_pickerItem )
922  selectionTool->UnbrightenItem( m_pickerItem );
923 
924  m_pickerItem = item;
925 
926  if( m_pickerItem )
927  selectionTool->BrightenItem( m_pickerItem );
928  }
929  } );
930 
931  picker->SetFinalizeHandler(
932  [this]( const int& aFinalState )
933  {
934  if( m_pickerItem )
936 
937  // Wake the selection tool after exiting to ensure the cursor gets updated
938  // and deselect previous selection from simulator to avoid any issue
939  // ( avoid crash in some cases when the SimTune tool is deselected )
941  selectionTool->ClearSelection();
943  } );
944 
945  std::string tool = aEvent.GetCommandStr().get();
946  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
947 
948  return 0;
949 }
950 #endif /* KICAD_SPICE */
951 
952 
953 // A singleton reference for clearing the highlight
955 
956 
957 static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition )
958 {
959  SCH_EDIT_FRAME* editFrame = static_cast<SCH_EDIT_FRAME*>( aToolMgr->GetToolHolder() );
960  EE_SELECTION_TOOL* selTool = aToolMgr->GetTool<EE_SELECTION_TOOL>();
961  SCH_EDITOR_CONTROL* editorControl = aToolMgr->GetTool<SCH_EDITOR_CONTROL>();
962  SCH_CONNECTION* conn = nullptr;
963  bool retVal = true;
964 
965  if( aPosition != CLEAR )
966  {
967  ERC_TESTER erc( &editFrame->Schematic() );
968 
969  if( erc.TestDuplicateSheetNames( false ) > 0 )
970  {
971  wxMessageBox( _( "Error: duplicate sub-sheet names found in current sheet." ) );
972  retVal = false;
973  }
974  else
975  {
976  SCH_ITEM* item = static_cast<SCH_ITEM*>( selTool->GetNode( aPosition ) );
977  SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
978 
979  if( item )
980  {
981  if( item->Type() == SCH_FIELD_T )
982  symbol = dynamic_cast<SCH_SYMBOL*>( item->GetParent() );
983 
984  if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
985  {
986  std::vector<SCH_PIN*> pins = symbol->GetPins();
987 
988  if( pins.size() == 1 )
989  conn = pins[0]->Connection();
990  }
991  else
992  {
993  conn = item->Connection();
994  }
995  }
996  }
997  }
998 
999  if( !conn )
1000  {
1001  editFrame->SetStatusText( wxT( "" ) );
1002  editFrame->SendCrossProbeClearHighlight();
1003  }
1004  else
1005  {
1006  editFrame->SetCrossProbeConnection( conn );
1007  }
1008 
1009  editFrame->SetHighlightedConnection( conn );
1010  editFrame->UpdateNetHighlightStatus();
1011 
1012  TOOL_EVENT dummy;
1013  editorControl->UpdateNetHighlighting( dummy );
1014 
1015  return retVal;
1016 }
1017 
1018 
1020 {
1021  KIGFX::VIEW_CONTROLS* controls = getViewControls();
1022  VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
1023 
1024  highlightNet( m_toolMgr, cursorPos );
1025 
1026  return 0;
1027 }
1028 
1029 
1031 {
1033 
1034  return 0;
1035 }
1036 
1037 
1039 {
1041  KIGFX::VIEW_CONTROLS* controls = getViewControls();
1042  VECTOR2D cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
1043 
1044  // TODO remove once real-time connectivity is a given
1046  // Ensure the netlist data is up to date:
1048 
1049  // Remove selection in favor of highlighting so the whole net is highlighted
1050  selectionTool->ClearSelection();
1051  highlightNet( m_toolMgr, cursorPos );
1052 
1054 
1055  if( conn )
1056  {
1057  if( !conn->IsBus()
1058  && ( !conn->Driver()
1061  {
1062  m_frame->ShowInfoBarError( _( "Net must be labeled to assign a netclass." ) );
1064  return 0;
1065  }
1066  else if( conn->IsBus() && conn->Members().size() == 0 )
1067  {
1068  m_frame->ShowInfoBarError( _( "Bus has no members to assign netclass to." ) );
1070  return 0;
1071  }
1072 
1073  wxArrayString netNames;
1074 
1075  if( conn->IsBus() )
1076  {
1077  for( const std::shared_ptr<SCH_CONNECTION>& member : conn->Members() )
1078  {
1079  if( member->IsBus() )
1080  {
1081  for( const std::shared_ptr<SCH_CONNECTION>& subMember : member->Members() )
1082  netNames.Add( subMember->Name() );
1083  }
1084  else
1085  {
1086  netNames.Add( member->Name() );
1087  }
1088  }
1089  }
1090  else
1091  {
1092  netNames.Add( conn->Name() );
1093  }
1094 
1095  NET_SETTINGS& netSettings = m_frame->Schematic().Prj().GetProjectFile().NetSettings();
1096  wxString netclassName = netSettings.GetNetclassName( netNames.front() );
1097 
1098  wxArrayString headers;
1099  std::vector<wxArrayString> items;
1100 
1101  headers.Add( _( "Netclasses" ) );
1102 
1103  wxArrayString defaultItem;
1104  defaultItem.Add( _( "Default" ) );
1105  items.emplace_back( defaultItem );
1106 
1107  for( const std::pair<const wxString, NETCLASSPTR>& ii : netSettings.m_NetClasses )
1108  {
1109  wxArrayString item;
1110  item.Add( ii.first );
1111  items.emplace_back( item );
1112  }
1113 
1114  EDA_LIST_DIALOG dlg( m_frame, _( "Assign Netclass" ), headers, items, netclassName );
1115  dlg.SetListLabel( _( "Select netclass:" ) );
1116 
1117  if( dlg.ShowModal() == wxID_OK )
1118  {
1119  netclassName = dlg.GetTextSelection();
1120 
1121  for( const wxString& netName : netNames )
1122  {
1123  // Remove from old netclass membership list
1124  if( netSettings.m_NetClassAssignments.count( netName ) )
1125  {
1126  const wxString oldNetclassName = netSettings.m_NetClassAssignments[netName];
1127  NETCLASSPTR oldNetclass = netSettings.m_NetClasses.Find( oldNetclassName );
1128 
1129  if( oldNetclass )
1130  oldNetclass->Remove( netName );
1131  }
1132 
1133  // Add to new netclass membership list
1134  NETCLASSPTR newNetclass = netSettings.m_NetClasses.Find( netclassName );
1135 
1136  if( newNetclass )
1137  newNetclass->Add( netName );
1138 
1139  netSettings.m_NetClassAssignments[netName] = netclassName;
1140  }
1141  }
1142  }
1143 
1145  return 0;
1146 }
1147 
1148 
1150 {
1152  CONNECTION_GRAPH* connectionGraph = m_frame->Schematic().ConnectionGraph();
1153  std::vector<EDA_ITEM*> itemsToRedraw;
1154  const SCH_CONNECTION* selectedConn = m_frame->GetHighlightedConnection();
1155 
1156  if( !screen )
1157  return 0;
1158 
1159  bool selectedIsBus = selectedConn ? selectedConn->IsBus() : false;
1160  wxString selectedName = selectedConn ? selectedConn->Name() : "";
1161 
1162  bool selectedIsNoNet = false;
1163  CONNECTION_SUBGRAPH* selectedSubgraph = nullptr;
1164 
1165  if( selectedConn && selectedConn->Driver() == nullptr )
1166  {
1167  selectedIsNoNet = true;
1168  selectedSubgraph = connectionGraph->GetSubgraphForItem( selectedConn->Parent() );
1169  }
1170 
1171  for( SCH_ITEM* item : screen->Items() )
1172  {
1173  SCH_CONNECTION* itemConn = nullptr;
1174  SCH_SYMBOL* symbol = nullptr;
1175  bool redraw = item->IsBrightened();
1176  bool highlight = false;
1177 
1178  if( item->Type() == SCH_SYMBOL_T )
1179  symbol = static_cast<SCH_SYMBOL*>( item );
1180 
1181  if( symbol && symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1182  itemConn = symbol->Connection();
1183  else
1184  itemConn = item->Connection();
1185 
1186  if( selectedIsNoNet && selectedSubgraph )
1187  {
1188  for( SCH_ITEM* subgraphItem : selectedSubgraph->m_items )
1189  {
1190  if( item == subgraphItem )
1191  {
1192  highlight = true;
1193  break;
1194  }
1195  }
1196  }
1197  else if( selectedIsBus && itemConn && itemConn->IsNet() )
1198  {
1199  for( const std::shared_ptr<SCH_CONNECTION>& member : selectedConn->Members() )
1200  {
1201  if( member->Name() == itemConn->Name() )
1202  {
1203  highlight = true;
1204  break;
1205  }
1206  else if( member->IsBus() )
1207  {
1208  for( const std::shared_ptr<SCH_CONNECTION>& child_member : member->Members() )
1209  {
1210  if( child_member->Name() == itemConn->Name() )
1211  {
1212  highlight = true;
1213  break;
1214  }
1215  }
1216  }
1217  }
1218  }
1219  else if( selectedConn && itemConn && selectedName == itemConn->Name() )
1220  {
1221  highlight = true;
1222  }
1223 
1224  if( highlight )
1225  item->SetBrightened();
1226  else
1227  item->ClearBrightened();
1228 
1229  redraw |= item->IsBrightened();
1230 
1231  // symbol is only non-null if the item is a SCH_SYMBOL_T
1232  if( symbol )
1233  {
1234  redraw |= symbol->HasBrightenedPins();
1235 
1236  symbol->ClearBrightenedPins();
1237 
1238  for( SCH_PIN* pin : symbol->GetPins() )
1239  {
1240  SCH_CONNECTION* pin_conn = pin->Connection();
1241 
1242  if( pin_conn && pin_conn->Name() == selectedName )
1243  {
1244  pin->SetBrightened();
1245  redraw = true;
1246  }
1247  }
1248 
1249  if( symbol->GetLibSymbolRef() && symbol->GetLibSymbolRef()->IsPower() )
1250  {
1251  std::vector<SCH_FIELD>& fields = symbol->GetFields();
1252 
1253  for( int id : { REFERENCE_FIELD, VALUE_FIELD } )
1254  {
1255  if( item->IsBrightened() && fields[id].IsVisible() )
1256  fields[id].SetBrightened();
1257  else
1258  fields[id].ClearBrightened();
1259  }
1260  }
1261  }
1262  else if( item->Type() == SCH_SHEET_T )
1263  {
1264  for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( item )->GetPins() )
1265  {
1266  SCH_CONNECTION* pin_conn = pin->Connection();
1267  bool redrawPin = pin->IsBrightened();
1268 
1269  if( pin_conn && pin_conn->Name() == selectedName )
1270  pin->SetBrightened();
1271  else
1272  pin->ClearBrightened();
1273 
1274  redrawPin ^= pin->IsBrightened();
1275  redraw |= redrawPin;
1276  }
1277  }
1278 
1279  if( redraw )
1280  itemsToRedraw.push_back( item );
1281  }
1282 
1283  // Be sure highlight change will be redrawn
1284  KIGFX::VIEW* view = getView();
1285 
1286  for( EDA_ITEM* redrawItem : itemsToRedraw )
1288 
1289  m_frame->GetCanvas()->Refresh();
1290 
1291  return 0;
1292 }
1293 
1294 
1296 {
1297  // TODO(JE) remove once real-time connectivity is a given
1298  if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
1300 
1301  std::string tool = aEvent.GetCommandStr().get();
1302  PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
1303 
1304  // Deactivate other tools; particularly important if another PICKER is currently running
1305  Activate();
1306 
1307  picker->SetCursor( KICURSOR::BULLSEYE );
1308  picker->SetSnapping( false );
1309 
1310  picker->SetClickHandler(
1311  [this] ( const VECTOR2D& aPos )
1312  {
1313  return highlightNet( m_toolMgr, aPos );
1314  } );
1315 
1316  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1317 
1318  return 0;
1319 }
1320 
1321 
1323 {
1324  if( m_frame->GetUndoCommandCount() <= 0 )
1325  return 0;
1326 
1327  // Inform tools that undo command was issued
1329 
1330  // Get the old list
1332  size_t num_undos = m_frame->m_undoList.m_CommandsList.size();
1333 
1334  // The cleanup routines normally run after an operation and so attempt to append their
1335  // undo items onto the operation's list. However, in this case that's going be the list
1336  // under us, which we don't want, so we push a dummy list onto the stack.
1339 
1341 
1345 
1346  // The cleanup routines *should* have appended to our dummy list, but just to be doubly
1347  // sure pop any other new lists off the stack as well
1348  while( m_frame->m_undoList.m_CommandsList.size() > num_undos )
1349  delete m_frame->PopCommandFromUndoList();
1350 
1351  // Now push the old command to the RedoList
1352  List->ReversePickersListOrder();
1353  m_frame->PushCommandToRedoList( List );
1354 
1355  m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1356 
1357  m_frame->SyncView();
1358  m_frame->GetCanvas()->Refresh();
1359  m_frame->OnModify();
1360 
1361  return 0;
1362 }
1363 
1364 
1366 {
1367  if( m_frame->GetRedoCommandCount() == 0 )
1368  return 0;
1369 
1370  // Inform tools that undo command was issued
1372 
1373  /* Get the old list */
1375 
1376  /* Redo the command: */
1378 
1379  /* Put the old list in UndoList */
1380  list->ReversePickersListOrder();
1381  m_frame->PushCommandToUndoList( list );
1382 
1386 
1387  m_toolMgr->GetTool<EE_SELECTION_TOOL>()->RebuildSelection();
1388 
1389  m_frame->SyncView();
1390  m_frame->GetCanvas()->Refresh();
1391  m_frame->OnModify();
1392 
1393  return 0;
1394 }
1395 
1396 
1397 bool SCH_EDITOR_CONTROL::doCopy( bool aUseLocalClipboard )
1398 {
1400  EE_SELECTION& selection = selTool->RequestSelection();
1401  SCHEMATIC& schematic = m_frame->Schematic();
1402 
1403  if( !selection.GetSize() )
1404  return false;
1405 
1406  selection.SetScreen( m_frame->GetScreen() );
1407  m_supplementaryClipboard.clear();
1408 
1409  for( EDA_ITEM* item : selection )
1410  {
1411  if( item->Type() == SCH_SHEET_T )
1412  {
1413  SCH_SHEET* sheet = (SCH_SHEET*) item;
1414  m_supplementaryClipboard[ sheet->GetFileName() ] = sheet->GetScreen();
1415  }
1416  }
1417 
1418  STRING_FORMATTER formatter;
1419  SCH_SEXPR_PLUGIN plugin;
1420  SCH_SHEET_LIST hierarchy = schematic.GetSheets();
1421  SCH_SHEET_PATH selPath = m_frame->GetCurrentSheet();
1422 
1423  plugin.Format( &selection, &selPath, &hierarchy, &formatter );
1424 
1425  if( aUseLocalClipboard )
1426  {
1427  m_localClipboard = formatter.GetString();
1428  return true;
1429  }
1430 
1431  return m_toolMgr->SaveClipboard( formatter.GetString() );
1432 }
1433 
1434 
1435 bool SCH_EDITOR_CONTROL::searchSupplementaryClipboard( const wxString& aSheetFilename,
1436  SCH_SCREEN** aScreen )
1437 {
1438  if( m_supplementaryClipboard.count( aSheetFilename ) > 0 )
1439  {
1440  *aScreen = m_supplementaryClipboard[ aSheetFilename ];
1441  return true;
1442  }
1443 
1444  return false;
1445 }
1446 
1447 
1449 {
1450  doCopy( true ); // Use the local clipboard
1451  Paste( aEvent );
1452 
1453  return 0;
1454 }
1455 
1456 
1458 {
1459  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1460 
1461  if( textEntry )
1462  {
1463  textEntry->Cut();
1464  return 0;
1465  }
1466 
1467  if( doCopy() )
1469 
1470  return 0;
1471 }
1472 
1473 
1475 {
1476  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1477 
1478  if( textEntry )
1479  {
1480  textEntry->Copy();
1481  return 0;
1482  }
1483 
1484  doCopy();
1485 
1486  return 0;
1487 }
1488 
1489 
1491  const SCH_SHEET_PATH& aPastePath,
1492  const KIID_PATH& aClipPath,
1493  bool aForceKeepAnnotations )
1494 {
1495  KIID_PATH clipItemPath = aClipPath;
1496  clipItemPath.push_back( aSymbol->m_Uuid );
1497 
1498  wxString reference, value, footprint;
1499  int unit;
1500 
1501  if( m_clipboardSymbolInstances.count( clipItemPath ) > 0 )
1502  {
1503  SYMBOL_INSTANCE_REFERENCE instance = m_clipboardSymbolInstances.at( clipItemPath );
1504 
1505  unit = instance.m_Unit;
1506  reference = instance.m_Reference;
1507  value = instance.m_Value;
1508  footprint = instance.m_Footprint;
1509  }
1510  else
1511  {
1512  // Pasted from notepad or an older instance of eeschema.
1513  // Use the values in the fields instead
1514  reference = aSymbol->GetField( REFERENCE_FIELD )->GetText();
1515  value = aSymbol->GetField( VALUE_FIELD )->GetText();
1516  footprint = aSymbol->GetField( FOOTPRINT_FIELD )->GetText();
1517  unit = aSymbol->GetUnit();
1518  }
1519 
1520  if( aForceKeepAnnotations && !reference.IsEmpty() )
1521  {
1522  aSymbol->SetRef( &aPastePath, reference );
1523  aSymbol->SetValue( &aPastePath, value );
1524  aSymbol->SetFootprint( &aPastePath, footprint );
1525  }
1526  else
1527  {
1528  aSymbol->ClearAnnotation( &aPastePath );
1529  }
1530 
1531  // We might clear annotations but always leave the original unit number from the paste
1532  aSymbol->SetUnitSelection( &aPastePath, unit );
1533  aSymbol->SetUnit( unit );
1534 }
1535 
1536 
1538  const KIID_PATH& aClipPath, SCH_SHEET* aSheet,
1539  bool aForceKeepAnnotations,
1540  SCH_SHEET_LIST* aPastedSheetsSoFar,
1541  SCH_REFERENCE_LIST* aPastedSymbolsSoFar )
1542 {
1543  SCH_SHEET_PATH sheetPath = aPastePath;
1544  sheetPath.push_back( aSheet );
1545 
1546  aSheet->AddInstance( sheetPath );
1547 
1548  wxString pageNum;
1549 
1550  if( m_clipboardSheetInstances.count( aClipPath ) > 0 )
1551  pageNum = m_clipboardSheetInstances.at( aClipPath ).m_PageNumber;
1552  else
1553  pageNum = wxString::Format( "%d", static_cast<int>( aPastedSheetsSoFar->size() ) );
1554 
1555  aSheet->SetPageNumber( sheetPath, pageNum );
1556  aPastedSheetsSoFar->push_back( sheetPath );
1557 
1558  if( aSheet->GetScreen() == nullptr )
1559  return sheetPath; // We can only really set the page number but not load any items
1560 
1561  for( SCH_ITEM* item : aSheet->GetScreen()->Items() )
1562  {
1563  if( item->Type() == SCH_SYMBOL_T )
1564  {
1565  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1566 
1567  updatePastedSymbol( symbol, aSheet->GetScreen(), sheetPath, aClipPath,
1568  aForceKeepAnnotations );
1569  }
1570  else if( item->Type() == SCH_SHEET_T )
1571  {
1572  SCH_SHEET* subsheet = static_cast<SCH_SHEET*>( item );
1573 
1574  KIID_PATH newClipPath = aClipPath;
1575  newClipPath.push_back( subsheet->m_Uuid );
1576 
1577  updatePastedSheet( sheetPath, newClipPath, subsheet, aForceKeepAnnotations,
1578  aPastedSheetsSoFar, aPastedSymbolsSoFar );
1579 
1580  SCH_SHEET_PATH subSheetPath = sheetPath;
1581  subSheetPath.push_back( subsheet );
1582 
1583  subSheetPath.GetSymbols( *aPastedSymbolsSoFar );
1584  }
1585  }
1586 
1587  return sheetPath;
1588 }
1589 
1590 
1592 {
1593  m_clipboardSheetInstances.clear();
1594 
1595  for( const SCH_SHEET_INSTANCE& sheet : aPastedScreen->GetSheetInstances() )
1596  m_clipboardSheetInstances[sheet.m_Path] = sheet;
1597 
1599 
1600  for( const SYMBOL_INSTANCE_REFERENCE& symbol : aPastedScreen->GetSymbolInstances() )
1601  m_clipboardSymbolInstances[symbol.m_Path] = symbol;
1602 }
1603 
1604 
1606 {
1607  wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wxWindow::FindFocus() );
1608 
1609  if( textEntry )
1610  {
1611  textEntry->Paste();
1612  return 0;
1613  }
1614 
1616  std::string content;
1617 
1618  if( aEvent.IsAction( &ACTIONS::duplicate ) )
1619  content = m_localClipboard;
1620  else
1621  content = m_toolMgr->GetClipboardUTF8();
1622 
1623  if( content.empty() )
1624  return 0;
1625 
1626  STRING_LINE_READER reader( content, "Clipboard" );
1627  SCH_SEXPR_PLUGIN plugin;
1628 
1629  SCH_SHEET tempSheet;
1630  SCH_SCREEN* tempScreen = new SCH_SCREEN( &m_frame->Schematic() );
1631 
1632  // Screen object on heap is owned by the sheet.
1633  tempSheet.SetScreen( tempScreen );
1634 
1635  try
1636  {
1637  plugin.LoadContent( reader, &tempSheet );
1638  }
1639  catch( IO_ERROR& )
1640  {
1641  // If it wasn't content, then paste as content
1642  SCH_TEXT* text_item = new SCH_TEXT( wxPoint( 0, 0 ), content );
1643  text_item->SetLabelSpinStyle( LABEL_SPIN_STYLE::RIGHT ); // Left alignment
1644  tempScreen->Append( text_item );
1645  }
1646 
1647  // Save loaded screen instances to m_clipboardSheetInstances
1648  setClipboardInstances( tempScreen );
1649 
1651 
1652  if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
1653  {
1654  DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode );
1655 
1656  if( dlg.ShowModal() == wxID_CANCEL )
1657  return 0;
1658  }
1659 
1660  bool forceKeepAnnotations = pasteMode != PASTE_MODE::REMOVE_ANNOTATIONS;
1661 
1662  // SCH_SEXP_PLUGIN added the items to the paste screen, but not to the view or anything
1663  // else. Pull them back out to start with.
1664  //
1665  EDA_ITEMS loadedItems;
1666  bool sheetsPasted = false;
1667  SCH_SHEET_LIST hierarchy = m_frame->Schematic().GetSheets();
1668  SCH_SHEET_PATH& pasteRoot = m_frame->GetCurrentSheet();
1669  wxFileName destFn = pasteRoot.Last()->GetFileName();
1670 
1671  if( destFn.IsRelative() )
1672  destFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1673 
1674  // List of paths in the hierarchy that refer to the destination sheet of the paste
1675  SCH_SHEET_LIST pasteInstances = hierarchy.FindAllSheetsForScreen( pasteRoot.LastScreen() );
1676  pasteInstances.SortByPageNumbers();
1677 
1678  // Build a list of screens from the current design (to avoid loading sheets that already exist)
1679  std::map<wxString, SCH_SCREEN*> loadedScreens;
1680 
1681  for( const SCH_SHEET_PATH& item : hierarchy )
1682  {
1683  if( item.LastScreen() )
1684  loadedScreens[item.Last()->GetFileName()] = item.LastScreen();
1685  }
1686 
1687  // Build symbol list for reannotation of duplicates
1688  SCH_REFERENCE_LIST existingRefs;
1689  hierarchy.GetSymbols( existingRefs );
1690  existingRefs.SortByReferenceOnly();
1691 
1692  // Build UUID map for fetching last-resolved-properties
1693  std::map<KIID, EDA_ITEM*> itemMap;
1694  hierarchy.FillItemMap( itemMap );
1695 
1696  // Keep track of pasted sheets and symbols for the different
1697  // paths to the hierarchy
1698  std::map<SCH_SHEET_PATH, SCH_REFERENCE_LIST> pastedSymbols;
1699  std::map<SCH_SHEET_PATH, SCH_SHEET_LIST> pastedSheets;
1700 
1701  for( SCH_ITEM* item : tempScreen->Items() )
1702  {
1703  loadedItems.push_back( item );
1704 
1705  //@todo: we might want to sort the sheets by page number before adding to loadedItems
1706  if( item->Type() == SCH_SHEET_T )
1707  {
1708  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1709  wxFileName srcFn = sheet->GetFileName();
1710 
1711  if( srcFn.IsRelative() )
1712  srcFn.MakeAbsolute( m_frame->Prj().GetProjectPath() );
1713 
1714  SCH_SHEET_LIST sheetHierarchy( sheet );
1715 
1716  if( hierarchy.TestForRecursion( sheetHierarchy, destFn.GetFullPath( wxPATH_UNIX ) ) )
1717  {
1718  auto msg = wxString::Format( _( "The pasted sheet '%s'\n"
1719  "was dropped because the destination already has "
1720  "the sheet or one of its subsheets as a parent." ),
1721  sheet->GetFileName() );
1722  DisplayError( m_frame, msg );
1723  loadedItems.pop_back();
1724  }
1725  }
1726  }
1727 
1728  // Remove the references from our temporary screen to prevent freeing on the DTOR
1729  tempScreen->Clear( false );
1730 
1731  for( unsigned i = 0; i < loadedItems.size(); ++i )
1732  {
1733  EDA_ITEM* item = loadedItems[i];
1734  KIID_PATH clipPath( wxT("/") ); // clipboard is at root
1735 
1736  if( item->Type() == SCH_SYMBOL_T )
1737  {
1738  SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( item );
1739 
1740  // The library symbol gets set from the cached library symbols in the current
1741  // schematic not the symbol libraries. The cached library symbol may have
1742  // changed from the original library symbol which would cause the copy to
1743  // be incorrect.
1744  SCH_SCREEN* currentScreen = m_frame->GetScreen();
1745 
1746  wxCHECK2( currentScreen, continue );
1747 
1748  auto it = currentScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1749  auto end = currentScreen->GetLibSymbols().end();
1750 
1751  if( it == end )
1752  {
1753  // If can't find library definition in the design, use the pasted library
1754  it = tempScreen->GetLibSymbols().find( symbol->GetSchSymbolLibraryName() );
1755  end = tempScreen->GetLibSymbols().end();
1756  }
1757 
1758  LIB_SYMBOL* libSymbol = nullptr;
1759 
1760  if( it != end )
1761  {
1762  libSymbol = new LIB_SYMBOL( *it->second );
1763  symbol->SetLibSymbol( libSymbol );
1764  }
1765 
1766  for( SCH_SHEET_PATH& instance : pasteInstances )
1767  updatePastedSymbol( symbol, tempScreen, instance, clipPath, forceKeepAnnotations );
1768 
1769  // Assign a new KIID
1770  const_cast<KIID&>( item->m_Uuid ) = KIID();
1771 
1772  // Make sure pins get a new UUID
1773  for( SCH_PIN* pin : symbol->GetPins() )
1774  const_cast<KIID&>( pin->m_Uuid ) = KIID();
1775 
1776  for( SCH_SHEET_PATH& instance : pasteInstances )
1777  {
1778  // Ignore pseudo-symbols (e.g. power symbols) and symbols from a non-existant
1779  // library.
1780  if( libSymbol && symbol->GetRef( &instance )[0] != wxT( '#' ) )
1781  {
1782  SCH_REFERENCE schReference( symbol, libSymbol, instance );
1783  schReference.SetSheetNumber( instance.GetVirtualPageNumber() );
1784  pastedSymbols[instance].AddItem( schReference );
1785  }
1786  }
1787  }
1788  else if( item->Type() == SCH_SHEET_T )
1789  {
1790  SCH_SHEET* sheet = (SCH_SHEET*) item;
1791  SCH_FIELD& nameField = sheet->GetFields()[SHEETNAME];
1792  wxString baseName = nameField.GetText();
1793  wxString candidateName = baseName;
1794  wxString number;
1795 
1796  while( !baseName.IsEmpty() && wxIsdigit( baseName.Last() ) )
1797  {
1798  number = baseName.Last() + number;
1799  baseName.RemoveLast();
1800  }
1801  // Update hierarchy to include any other sheets we already added, avoiding
1802  // duplicate sheet names
1803  hierarchy = m_frame->Schematic().GetSheets();
1804 
1805  //@todo: it might be better to just iterate through the sheet names
1806  // in this screen instead of the whole hierarchy.
1807  int uniquifier = std::max( 0, wxAtoi( number ) ) + 1;
1808 
1809  while( hierarchy.NameExists( candidateName ) )
1810  candidateName = wxString::Format( wxT( "%s%d" ), baseName, uniquifier++ );
1811 
1812  nameField.SetText( candidateName );
1813 
1814  wxFileName fn = sheet->GetFileName();
1815  SCH_SCREEN* existingScreen = nullptr;
1816 
1817  sheet->SetParent( pasteRoot.Last() );
1818  sheet->SetScreen( nullptr );
1819 
1820  if( !fn.IsAbsolute() )
1821  {
1822  wxFileName currentSheetFileName = pasteRoot.LastScreen()->GetFileName();
1823  fn.Normalize( wxPATH_NORM_ALL, currentSheetFileName.GetPath() );
1824  }
1825 
1826  // Try to find the screen for the pasted sheet by several means
1827  if( !m_frame->Schematic().Root().SearchHierarchy( fn.GetFullPath( wxPATH_UNIX ),
1828  &existingScreen ) )
1829  {
1830  if( loadedScreens.count( sheet->GetFileName() ) > 0 )
1831  existingScreen = loadedScreens.at( sheet->GetFileName() );
1832  else
1833  searchSupplementaryClipboard( sheet->GetFileName(), &existingScreen );
1834  }
1835 
1836  if( existingScreen )
1837  {
1838  sheet->SetScreen( existingScreen );
1839  }
1840  else
1841  {
1842  if( !m_frame->LoadSheetFromFile( sheet, &pasteRoot, fn.GetFullPath() ) )
1843  m_frame->InitSheet( sheet, sheet->GetFileName() );
1844  }
1845 
1846  sheetsPasted = true;
1847 
1848  // Push it to the clipboard path while it still has its old KIID
1849  clipPath.push_back( sheet->m_Uuid );
1850 
1851  // Assign a new KIID to the pasted sheet
1852  const_cast<KIID&>( sheet->m_Uuid ) = KIID();
1853 
1854  // Make sure pins get a new UUID
1855  for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1856  const_cast<KIID&>( pin->m_Uuid ) = KIID();
1857 
1858  // Once we have our new KIID we can update all pasted instances. This will either
1859  // reset the annotations or copy "kept" annotations from the supplementary clipboard.
1860  for( SCH_SHEET_PATH& instance : pasteInstances )
1861  {
1862  SCH_SHEET_PATH sheetPath = updatePastedSheet( instance, clipPath, sheet,
1863  forceKeepAnnotations,
1864  &pastedSheets[instance],
1865  &pastedSymbols[instance] );
1866 
1867  sheetPath.GetSymbols( pastedSymbols[instance] );
1868  }
1869  }
1870  else
1871  {
1872  SCH_ITEM* srcItem = dynamic_cast<SCH_ITEM*>( itemMap[ item->m_Uuid ] );
1873  SCH_ITEM* destItem = dynamic_cast<SCH_ITEM*>( item );
1874 
1875  // Everything gets a new KIID
1876  const_cast<KIID&>( item->m_Uuid ) = KIID();
1877 
1878  if( srcItem && destItem )
1879  {
1880  destItem->SetConnectivityDirty( true );
1881  destItem->SetLastResolvedState( srcItem );
1882  }
1883  }
1884 
1885  item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
1887 
1888  // Reset flags for subsequent move operation
1889  item->SetFlags( IS_NEW | IS_PASTED | IS_MOVING );
1890  // Start out hidden so the pasted items aren't "ghosted" in their original location
1891  // before being moved to the current location.
1892  getView()->Hide( item, true );
1893  }
1894 
1895  pasteInstances.SortByPageNumbers();
1896 
1897  if( pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS )
1898  {
1899  for( SCH_SHEET_PATH& instance : pasteInstances )
1900  {
1901  pastedSymbols[instance].SortByReferenceOnly();
1902  pastedSymbols[instance].ReannotateDuplicates( existingRefs );
1903  pastedSymbols[instance].UpdateAnnotation();
1904 
1905  // Update existing refs for next iteration
1906  for( size_t i = 0; i < pastedSymbols[instance].GetCount(); i++ )
1907  existingRefs.AddItem( pastedSymbols[instance][i] );
1908  }
1909  }
1910 
1912 
1913  if( sheetsPasted )
1914  {
1915  // Update page numbers: Find next free numeric page number
1916  for( SCH_SHEET_PATH& instance : pasteInstances )
1917  {
1918  pastedSheets[instance].SortByPageNumbers();
1919 
1920  for( SCH_SHEET_PATH& pastedSheet : pastedSheets[instance] )
1921  {
1922  int page = 1;
1923  wxString pageNum = wxString::Format( "%d", page );
1924 
1925  while( hierarchy.PageNumberExists( pageNum ) )
1926  pageNum = wxString::Format( "%d", ++page );
1927 
1928  pastedSheet.SetPageNumber( pageNum );
1929  hierarchy.push_back( pastedSheet );
1930  }
1931  }
1932 
1935  }
1936 
1937  // Now clear the previous selection, select the pasted items, and fire up the "move"
1938  // tool.
1939  //
1941  m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &loadedItems );
1942 
1943  EE_SELECTION& selection = selTool->GetSelection();
1944 
1945  if( !selection.Empty() )
1946  {
1947  SCH_ITEM* item = (SCH_ITEM*) selection.GetTopLeftItem();
1948 
1949  selection.SetReferencePoint( item->GetPosition() );
1950 
1952  }
1953 
1954  return 0;
1955 }
1956 
1957 
1959 {
1961  EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SymbolsOnly );
1962  SCH_SYMBOL* symbol = nullptr;
1963  SYMBOL_EDIT_FRAME* symbolEditor;
1964 
1965  if( selection.GetSize() >= 1 )
1966  symbol = (SCH_SYMBOL*) selection.Front();
1967 
1968  if( !symbol || symbol->GetEditFlags() != 0 )
1969  return 0;
1970 
1972  symbolEditor = (SYMBOL_EDIT_FRAME*) m_frame->Kiway().Player( FRAME_SCH_SYMBOL_EDITOR, false );
1973 
1974  if( symbolEditor )
1975  {
1976  if( aEvent.IsAction( &EE_ACTIONS::editWithLibEdit ) )
1977  symbolEditor->LoadSymbolFromSchematic( symbol );
1978  else if( aEvent.IsAction( &EE_ACTIONS::editLibSymbolWithLibEdit ) )
1979  {
1980  symbolEditor->LoadSymbol( symbol->GetLibId(), symbol->GetUnit(), symbol->GetConvert() );
1981 
1982  if( !symbolEditor->IsSymbolTreeShown() )
1983  {
1984  wxCommandEvent evt;
1985  symbolEditor->OnToggleSymbolTree( evt );
1986  }
1987  }
1988  }
1989 
1990  return 0;
1991 }
1992 
1993 
1995 {
1996  wxCommandEvent dummy;
1997  m_frame->OnAnnotate( dummy );
1998  return 0;
1999 }
2000 
2001 
2003 {
2004  wxCommandEvent dummy;
2006  return 0;
2007 }
2008 
2009 
2011 {
2013  dlg.ShowQuasiModal();
2014  return 0;
2015 }
2016 
2017 
2019 {
2021  m_frame->HardRedraw();
2022 
2023  return 0;
2024 }
2025 
2026 
2028 {
2029  wxCommandEvent dummy;
2031  return 0;
2032 }
2033 
2034 
2036 {
2037  wxCommandEvent dummy;
2039  return 0;
2040 }
2041 
2042 
2044 {
2046  dlg.ShowModal();
2047  return 0;
2048 }
2049 
2050 
2052 {
2053  int result = NET_PLUGIN_CHANGE;
2054 
2055  // If a plugin is removed or added, rebuild and reopen the new dialog
2056  while( result == NET_PLUGIN_CHANGE )
2057  result = InvokeDialogNetList( m_frame );
2058 
2059  return 0;
2060 }
2061 
2062 
2064 {
2066  return 0;
2067 }
2068 
2069 
2071 {
2072  if( !ADVANCED_CFG::GetCfg().m_RealTimeConnectivity || !CONNECTION_GRAPH::m_allowRealTime )
2074 
2076  return 0;
2077 }
2078 
2079 
2081 {
2083  return 0;
2084 }
2085 
2086 
2088 {
2090  const EE_SELECTION& selection = selTool->RequestSelection( EE_COLLECTOR::SheetsOnly );
2091 
2092  if( selection.GetSize() == 1 )
2093  {
2094  SCH_SHEET* sheet = (SCH_SHEET*) selection.Front();
2095 
2098 
2099  // Store the current zoom level into the current screen before switching
2101 
2102  m_frame->GetCurrentSheet().push_back( sheet );
2104  }
2105 
2106  return 0;
2107 }
2108 
2109 
2111 {
2112  if( m_frame->GetCurrentSheet().Last() != &m_frame->Schematic().Root() )
2113  {
2116 
2117  // Store the current zoom level into the current screen before switching
2119 
2122  }
2123 
2124  return 0;
2125 }
2126 
2127 
2129 {
2132 
2133  KIGFX::SCH_PAINTER* painter = static_cast<KIGFX::SCH_PAINTER*>( getView()->GetPainter() );
2135 
2137  m_frame->GetCanvas()->Refresh();
2138 
2139  return 0;
2140 }
2141 
2142 
2144 {
2147 
2148  KIGFX::SCH_PAINTER* painter = static_cast<KIGFX::SCH_PAINTER*>( getView()->GetPainter() );
2150 
2152  m_frame->GetCanvas()->Refresh();
2153 
2154  return 0;
2155 }
2156 
2157 
2159 {
2161 
2162  return 0;
2163 }
2164 
2165 
2167 {
2168 
2170  return 0;
2171 }
2172 
2173 
2175 {
2176  int errors = 0;
2177  wxString details;
2178  bool quiet = aEvent.Parameter<bool>();
2179 
2180  // Repair duplicate IDs.
2181  std::map<KIID, EDA_ITEM*> ids;
2182  int duplicates = 0;
2183 
2184  auto processItem =
2185  [&]( EDA_ITEM* aItem )
2186  {
2187  auto it = ids.find( aItem->m_Uuid );
2188 
2189  if( it != ids.end() && it->second != aItem )
2190  {
2191  duplicates++;
2192  const_cast<KIID&>( aItem->m_Uuid ) = KIID();
2193  }
2194 
2195  ids[ aItem->m_Uuid ] = aItem;
2196  };
2197 
2198  // Symbol IDs are the most important, so give them the first crack at "claiming" a
2199  // particular KIID.
2200 
2201  for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2202  {
2203  SCH_SCREEN* screen = sheet.LastScreen();
2204 
2205  for( SCH_ITEM* item : screen->Items().OfType( SCH_SYMBOL_T ) )
2206  {
2207  processItem( item );
2208 
2209  for( SCH_PIN* pin : static_cast<SCH_SYMBOL*>( item )->GetPins( &sheet ) )
2210  processItem( pin );
2211  }
2212  }
2213 
2214  for( const SCH_SHEET_PATH& sheet : m_frame->Schematic().GetSheets() )
2215  {
2216  SCH_SCREEN* screen = sheet.LastScreen();
2217 
2218  for( SCH_ITEM* item : screen->Items() )
2219  {
2220  processItem( item );
2221 
2222  item->RunOnChildren(
2223  [&]( SCH_ITEM* aChild )
2224  {
2225  processItem( item );
2226  } );
2227  }
2228  }
2229 
2230  /*******************************
2231  * Your test here
2232  */
2233 
2234  /*******************************
2235  * Inform the user
2236  */
2237 
2238  if( duplicates )
2239  {
2240  errors += duplicates;
2241  details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
2242  }
2243 
2244  if( errors )
2245  {
2246  m_frame->OnModify();
2247 
2248  wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
2249 
2250  if( !quiet )
2251  DisplayInfoMessage( m_frame, msg, details );
2252  }
2253  else if( !quiet )
2254  {
2255  DisplayInfoMessage( m_frame, _( "No errors found." ) );
2256  }
2257 
2258  return 0;
2259 }
2260 
2261 
2263 {
2264  Go( &SCH_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
2265  Go( &SCH_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
2266  Go( &SCH_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
2268  //Go( &SCH_EDITOR_CONTROL::SaveAs, ACTIONS::saveCopyAs.MakeEvent() );
2272  Go( &SCH_EDITOR_CONTROL::Print, ACTIONS::print.MakeEvent() );
2273  Go( &SCH_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
2274  Go( &SCH_EDITOR_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
2275 
2278 
2287 
2292 
2293 #ifdef KICAD_SPICE
2294  Go( &SCH_EDITOR_CONTROL::SimProbe, EE_ACTIONS::simProbe.MakeEvent() );
2295  Go( &SCH_EDITOR_CONTROL::SimTune, EE_ACTIONS::simTune.MakeEvent() );
2296 #endif /* KICAD_SPICE */
2297 
2303 
2305 
2306  Go( &SCH_EDITOR_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
2307  Go( &SCH_EDITOR_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
2308  Go( &SCH_EDITOR_CONTROL::Cut, ACTIONS::cut.MakeEvent() );
2309  Go( &SCH_EDITOR_CONTROL::Copy, ACTIONS::copy.MakeEvent() );
2310  Go( &SCH_EDITOR_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
2313 
2327 
2329 
2333 
2337 
2339 
2341 }
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:279
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:1537
void SetSheetNumber(int aSheetNumber)
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
EE_TYPE OfType(KICAD_T aType) const
Definition: sch_rtree.h:230
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)
std::map< wxString, wxString > m_NetClassAssignments
Definition: net_settings.h:44
const wxString & GetFileName() const
Definition: sch_screen.h:145
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:157
int Copy(const TOOL_EVENT &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:200
virtual void SetLastResolvedState(const SCH_ITEM *aItem)
Definition: sch_item.h:417
virtual bool Matches(const wxFindReplaceData &aSearchData, void *aAuxData) const
Compare the item against the search criteria in aSearchData.
Definition: eda_item.h:364
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:241
bool SearchHierarchy(const wxString &aFilename, SCH_SCREEN **aScreen)
Search the existing hierarchy for an instance of screen loaded from aFileName.
Definition: sch_sheet.cpp:666
void UpdateNetHighlightStatus()
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:165
wxString GetTextSelection(int aColumn=0)
Return the selected text from aColumn in the wxListCtrl in the dialog.
static TOOL_ACTION navigateHierarchy
Definition: ee_actions.h:186
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:150
int ComparePageNum(const SCH_SHEET_PATH &aSheetPathToTest) const
Compare sheets by their page number.
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_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Return a mandatory field in this symbol.
Definition: sch_symbol.cpp:677
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:333
Holds all the data relating to one schematic.
Definition: schematic.h:59
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:201
const wxString & GetNetclassName(const wxString &aNetName) const
#define IS_NEW
New item, just created.
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:63
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:486
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:508
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:596
void SetScreen(SCH_SCREEN *aScreen)
Set the SCH_SCREEN associated with this sheet to aScreen.
Definition: sch_sheet.cpp:172
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:1482
void updatePastedSymbol(SCH_SYMBOL *aSymbol, SCH_SCREEN *aPasteScreen, const SCH_SHEET_PATH &aPastePath, const KIID_PATH &aClipPath, bool aForceKeepAnnotations)
wxString KiCadSchematicFileWildcard()
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:713
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:129
static TOOL_ACTION remapSymbols
Definition: ee_actions.h:158
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
void TestDanglingEnds(const SCH_SHEET_PATH *aPath=nullptr, std::function< void(SCH_ITEM *)> *aChangedHandler=nullptr) const
Test all of the connectable objects in the schematic for unused connection points.
int GetId() const
Definition: sch_field.h:113
#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:96
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:383
A dialog which shows:
virtual int GetRedoCommandCount() const
bool IsBrightened() const
Definition: eda_item.h:125
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:109
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:251
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:443
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:76
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)
static TOOL_ACTION saveCurrSheetCopyAs
Definition: ee_actions.h:42
SCH_SCREEN * GetScreen() const
Definition: sch_sheet.h:105
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:647
static TOOL_ACTION updateNetHighlighting
Definition: ee_actions.h:221
void SetLibSymbol(LIB_SYMBOL *aLibSymbol)
Set this schematic symbol library symbol reference to aLibSymbol.
Definition: sch_symbol.cpp:259
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:549
void SetPageNumber(const SCH_SHEET_PATH &aInstance, const wxString &aPageNumber)
Set the page number for the sheet instance aInstance.
Definition: sch_sheet.cpp:1183
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:205
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
bool IsSymbolTreeShown() const
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
wxFindReplaceData & GetFindReplaceData()
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:228
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:185
void ClearBrightened()
Definition: eda_item.h:132
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:138
bool SaveProject(bool aSaveAs=false)
Save the currently-open schematic (including its hierarchy) and associated project.
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:72
std::vector< SCH_FIELD > & GetFields()
Definition: sch_sheet.h:90
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
bool RescueSymbolLibTableProject(bool aRunningOnDemand)
static TOOL_ACTION annotate
Definition: ee_actions.h:141
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:82
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.
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:163
Definition: kiid.h:44
static TOOL_ACTION copy
Definition: actions.h:67
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:189
int UpdatePCB(const TOOL_EVENT &aEvent)
int ShowCvpcb(const TOOL_EVENT &aEvent)
void LoadSymbol(const wxString &aLibrary, const wxString &aSymbol, int Unit)
void BrightenItem(EDA_ITEM *aItem)
static TOOL_ACTION highlightNetTool
Definition: ee_actions.h:222
static TOOL_ACTION showBusManager
Definition: ee_actions.h:152
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:164
static TOOL_ACTION editSymbolFields
Definition: ee_actions.h:142
Item needs to be redrawn.
Definition: view_item.h:52
#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:124
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:216
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:250
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
bool saveSchematicFile(SCH_SHEET *aSheet, const wxString &aSavePath)
Save aSheet to a schematic file.
static TOOL_ACTION explicitCrossProbe
Definition: ee_actions.h:199
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
wxString GetPageNumber() const
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:203
const std::vector< SCH_SHEET_INSTANCE > & GetSheetInstances() const
Definition: sch_screen.h:491
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:130
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.
void BuildClientSheetPathList()
built the list of sheet paths sharing a screen for each screen in use
Definition of file extensions used in Kicad.
SCH_ITEM * Driver() const
static TOOL_ACTION showPythonConsole
Definition: ee_actions.h:210
bool doCopy(bool aUseLocalClipboard=false)
< copy selection to clipboard or to m_localClipboard if aUseLocalClipboard is true
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:114
An interface for classes handling user events controlling the view behavior such as zooming,...
static TOOL_ACTION quit
Definition: actions.h:59
#define _(s)
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
DIALOG_SCH_FIND * m_findReplaceDialog
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:202
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:451
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:1402
const std::string & GetString()
Definition: richio.h:438
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition: tool_event.h:362
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:506
bool DisableGridSnapping() const
Definition: tool_event.h:341
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
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:157
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:317
int UpdateNetHighlighting(const TOOL_EVENT &aEvent)
Launch a tool to highlight nets.
void setClipboardInstances(const SCH_SCREEN *aPastedScreen)
int SaveCurrSheetCopyAs(const TOOL_EVENT &aEvent)
Saves the currently-open schematic sheet to an other name.
void OnToggleSymbolTree(wxCommandEvent &event)
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:170
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
wxString UnescapeString(const wxString &aSource)
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
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:474
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:88
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:186
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:139
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
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:146
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:195
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:164
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:151
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:483
int RescueSymbols(const TOOL_EVENT &aEvent)
Perform rescue operations to recover old projects from before certain changes were made.
size_t GetCurrentHash() const
#define NAMELESS_PROJECT
default name for nameless projects
Definition: project.h:41
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:110
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...
const std::string KiCadSchematicFileExtension
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:99
static TOOL_ACTION drawSheetOnClipboard
Definition: ee_actions.h:207
SCH_ITEM * Parent() const
static TOOL_ACTION repairSchematic
Definition: ee_actions.h:211
int Undo(const TOOL_EVENT &aEvent)
static TOOL_ACTION enterSheet
Definition: ee_actions.h:184
std::vector< std::shared_ptr< SCH_CONNECTION > > & Members()
static TOOL_ACTION clearHighlight
Definition: ee_actions.h:220
void Activate()
Run the tool.
SCH_SHEET_PATH & GetCurrentSheet() const
int RepairSchematic(const TOOL_EVENT &aEvent)
static const KICAD_T SymbolsOnly[]
Definition: ee_collectors.h:45
static TOOL_ACTION editWithLibEdit
Definition: ee_actions.h:161
static TOOL_ACTION move
Definition: ee_actions.h:113
static TOOL_ACTION simProbe
Definition: ee_actions.h:215
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
static TOOL_ACTION editLibSymbolWithLibEdit
Definition: ee_actions.h:162
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:166
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:219
#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:153
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:68
int GetUnit() const
Definition: sch_symbol.h:195
virtual void SetLabelSpinStyle(LABEL_SPIN_STYLE aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:330
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
bool IsBus() const
double GetScale() const
Definition: view.h:264
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:143
static TOOL_ACTION toggleForceHV
Definition: ee_actions.h:206
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
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:307
int UpdateFromPCB(const TOOL_EVENT &aEvent)
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:414
bool m_RealTimeConnectivity
Do real-time connectivity.
int GetConvert() const
Definition: sch_symbol.h:223
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:182
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:154
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:868
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:593
int InvokeDialogNetList(SCH_EDIT_FRAME *aCaller)
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:145
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:1570
int ExportNetlist(const TOOL_EVENT &aEvent)
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:415
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
bool AddInstance(const SCH_SHEET_PATH &aInstance)
Add a new instance aSheetPath to the instance list.
Definition: sch_sheet.cpp:1138
const LIB_ID & GetLibId() const
Definition: sch_symbol.h:147
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:196