KiCad PCB EDA Suite
sch_edit_tool.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) 2019 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 <tool/picker_tool.h>
26 #include <tools/sch_edit_tool.h>
29 #include <tools/sch_move_tool.h>
30 #include <ee_actions.h>
31 #include <bitmaps.h>
32 #include <confirm.h>
33 #include <base_struct.h>
34 #include <sch_item.h>
35 #include <sch_component.h>
36 #include <sch_sheet.h>
37 #include <sch_text.h>
38 #include <sch_bitmap.h>
39 #include <sch_view.h>
40 #include <sch_line.h>
41 #include <sch_bus_entry.h>
42 #include <sch_edit_frame.h>
43 #include <eeschema_id.h>
44 #include <status_popup.h>
45 #include <wx/gdicmn.h>
46 #include <invoke_sch_dialog.h>
52 #include "sch_drawing_tools.h"
53 
54 
56 
57 
59 {
60 public:
62  ACTION_MENU( true )
63  {
64  SetIcon( component_select_unit_xpm );
65  SetTitle( _( "Symbol Unit" ) );
66  }
67 
68 protected:
69  ACTION_MENU* create() const override
70  {
71  return new SYMBOL_UNIT_MENU();
72  }
73 
74 private:
75  void update() override
76  {
78  EE_SELECTION& selection = selTool->GetSelection();
79  SCH_COMPONENT* component = dynamic_cast<SCH_COMPONENT*>( selection.Front() );
80 
81  Clear();
82 
83  if( !component )
84  {
85  Append( ID_POPUP_SCH_UNFOLD_BUS, _( "no symbol selected" ), wxEmptyString );
86  Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
87  return;
88  }
89 
90  int unit = component->GetUnit();
91  auto partRef = component->GetPartRef().lock();
92 
93  if( !partRef || partRef->GetUnitCount() < 2 )
94  {
95  Append( ID_POPUP_SCH_UNFOLD_BUS, _( "symbol is not multi-unit" ), wxEmptyString );
96  Enable( ID_POPUP_SCH_UNFOLD_BUS, false );
97  return;
98  }
99 
100  for( int ii = 0; ii < partRef->GetUnitCount(); ii++ )
101  {
102  wxString num_unit;
103  num_unit.Printf( _( "Unit %s" ), LIB_PART::SubReference( ii + 1, false ) );
104 
105  wxMenuItem * item = Append( ID_POPUP_SCH_SELECT_UNIT1 + ii, num_unit, wxEmptyString,
106  wxITEM_CHECK );
107  if( unit == ii + 1 )
108  item->Check(true);
109 
110  // The ID max for these submenus is ID_POPUP_SCH_SELECT_UNIT_CMP_MAX
111  // See eeschema_id to modify this value.
113  break; // We have used all IDs for these submenus
114  }
115  }
116 };
117 
118 
120  EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveEdit" )
121 {
122 }
123 
124 
126 
128 {
130 
133 
134  wxASSERT_MSG( drawingTools, "eeshema.InteractiveDrawing tool is not available" );
135 
136  auto sheetTool = [ this ] ( const SELECTION& aSel ) {
138  };
139 
140  auto anyTextTool = [ this ] ( const SELECTION& aSel ) {
145  };
146 
147  auto duplicateCondition = [] ( const SELECTION& aSel ) {
149  return false;
150 
151  return true;
152  };
153 
154  auto orientCondition = [] ( const SELECTION& aSel ) {
155  if( aSel.Empty() )
156  return false;
157 
159  return false;
160 
161  SCH_ITEM* item = (SCH_ITEM*) aSel.Front();
162 
163  if( aSel.GetSize() > 1 )
164  return true;
165 
166  switch( item->Type() )
167  {
168  case SCH_MARKER_T:
169  case SCH_JUNCTION_T:
170  case SCH_NO_CONNECT_T:
171  case SCH_LINE_T:
172  case SCH_PIN_T:
173  return false;
174  default:
175  return true;
176  }
177  };
178 
179  auto propertiesCondition = [] ( const SELECTION& aSel ) {
180  if( aSel.GetSize() != 1 )
181  return false;
182 
183  switch( static_cast<EDA_ITEM*>( aSel.Front() )->Type() )
184  {
185  case SCH_MARKER_T:
186  case SCH_JUNCTION_T:
187  case SCH_NO_CONNECT_T:
189  case SCH_BUS_BUS_ENTRY_T:
190  case SCH_LINE_T:
191  case SCH_SHEET_PIN_T:
192  case SCH_PIN_T:
193  return false;
194  default:
195  return true;
196  }
197  };
198 
199  static KICAD_T toLabelTypes[] = { SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT };
200  auto toLabelCondition = E_C::Count( 1 ) && E_C::OnlyTypes( toLabelTypes );
201 
202  static KICAD_T toHLableTypes[] = { SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_TEXT_T, EOT };
203  auto toHLabelCondition = E_C::Count( 1 ) && E_C::OnlyTypes( toHLableTypes );
204 
205  static KICAD_T toGLableTypes[] = { SCH_LABEL_T, SCH_HIER_LABEL_T, SCH_TEXT_T, EOT };
206  auto toGLabelCondition = E_C::Count( 1 ) && E_C::OnlyTypes( toGLableTypes );
207 
208  static KICAD_T toTextTypes[] = { SCH_LABEL_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, EOT };
209  auto toTextlCondition = E_C::Count( 1 ) && E_C::OnlyTypes( toTextTypes );
210 
211  static KICAD_T entryTypes[] = { SCH_BUS_WIRE_ENTRY_T, SCH_BUS_BUS_ENTRY_T, EOT };
212  auto entryCondition = E_C::MoreThan( 0 ) && E_C::OnlyTypes( entryTypes );
213 
214  auto singleComponentCondition = E_C::Count( 1 ) && E_C::OnlyType( SCH_COMPONENT_T );
215  auto wireSelectionCondition = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_WIRE_T );
216  auto busSelectionCondition = E_C::MoreThan( 0 ) && E_C::OnlyType( SCH_LINE_LOCATE_BUS_T );
217  auto singleSheetCondition = E_C::Count( 1 ) && E_C::OnlyType( SCH_SHEET_T );
218 
219  //
220  // Add edit actions to the move tool menu
221  //
222  if( moveTool )
223  {
224  CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
225 
226  moveMenu.AddSeparator();
227  moveMenu.AddItem( EE_ACTIONS::rotateCCW, orientCondition );
228  moveMenu.AddItem( EE_ACTIONS::rotateCW, orientCondition );
229  moveMenu.AddItem( EE_ACTIONS::mirrorX, orientCondition );
230  moveMenu.AddItem( EE_ACTIONS::mirrorY, orientCondition );
232 
233  moveMenu.AddItem( EE_ACTIONS::properties, propertiesCondition );
234  moveMenu.AddItem( EE_ACTIONS::editReference, singleComponentCondition );
235  moveMenu.AddItem( EE_ACTIONS::editValue, singleComponentCondition );
236  moveMenu.AddItem( EE_ACTIONS::editFootprint, singleComponentCondition );
238 
239  std::shared_ptr<SYMBOL_UNIT_MENU> symUnitMenu = std::make_shared<SYMBOL_UNIT_MENU>();
240  symUnitMenu->SetTool( this );
241  m_menu.AddSubMenu( symUnitMenu );
242  moveMenu.AddMenu( symUnitMenu.get(), E_C::SingleMultiUnitSymbol, 1 );
243 
244  moveMenu.AddSeparator();
247  moveMenu.AddItem( ACTIONS::duplicate, duplicateCondition );
248  }
249 
250  //
251  // Add editing actions to the drawing tool menu
252  //
253  CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
254 
255  drawMenu.AddItem( EE_ACTIONS::rotateCCW, orientCondition, 200 );
256  drawMenu.AddItem( EE_ACTIONS::rotateCW, orientCondition, 200 );
257  drawMenu.AddItem( EE_ACTIONS::mirrorX, orientCondition, 200 );
258  drawMenu.AddItem( EE_ACTIONS::mirrorY, orientCondition, 200 );
259 
260  drawMenu.AddItem( EE_ACTIONS::properties, propertiesCondition, 200 );
261  drawMenu.AddItem( EE_ACTIONS::editReference, singleComponentCondition, 200 );
262  drawMenu.AddItem( EE_ACTIONS::editValue, singleComponentCondition, 200 );
263  drawMenu.AddItem( EE_ACTIONS::editFootprint, singleComponentCondition, 200 );
264  drawMenu.AddItem( EE_ACTIONS::autoplaceFields, singleComponentCondition, 200 );
266 
267  std::shared_ptr<SYMBOL_UNIT_MENU> symUnitMenu2 = std::make_shared<SYMBOL_UNIT_MENU>();
268  symUnitMenu2->SetTool( drawingTools );
269  drawingTools->GetToolMenu().AddSubMenu( symUnitMenu2 );
270  drawMenu.AddMenu( symUnitMenu2.get(), E_C::SingleMultiUnitSymbol, 1 );
271 
272  drawMenu.AddItem( EE_ACTIONS::editWithLibEdit, singleComponentCondition && E_C::Idle, 200 );
273 
274  drawMenu.AddItem( EE_ACTIONS::toShapeSlash, entryCondition, 200 );
275  drawMenu.AddItem( EE_ACTIONS::toShapeBackslash, entryCondition, 200 );
276  drawMenu.AddItem( EE_ACTIONS::toLabel, anyTextTool && E_C::Idle, 200 );
277  drawMenu.AddItem( EE_ACTIONS::toHLabel, anyTextTool && E_C::Idle, 200 );
278  drawMenu.AddItem( EE_ACTIONS::toGLabel, anyTextTool && E_C::Idle, 200 );
279  drawMenu.AddItem( EE_ACTIONS::toText, anyTextTool && E_C::Idle, 200 );
280  drawMenu.AddItem( EE_ACTIONS::cleanupSheetPins, sheetTool && E_C::Idle, 250 );
281 
282  //
283  // Add editing actions to the selection tool menu
284  //
286 
287  selToolMenu.AddItem( EE_ACTIONS::rotateCCW, orientCondition, 200 );
288  selToolMenu.AddItem( EE_ACTIONS::rotateCW, orientCondition, 200 );
289  selToolMenu.AddItem( EE_ACTIONS::mirrorX, orientCondition, 200 );
290  selToolMenu.AddItem( EE_ACTIONS::mirrorY, orientCondition, 200 );
291  selToolMenu.AddItem( ACTIONS::doDelete, E_C::NotEmpty, 200 );
292 
293  selToolMenu.AddItem( EE_ACTIONS::properties, propertiesCondition, 200 );
295  selToolMenu.AddItem( EE_ACTIONS::editValue, E_C::SingleSymbol, 200 );
297  selToolMenu.AddItem( EE_ACTIONS::autoplaceFields, singleComponentCondition, 200 );
299 
300  std::shared_ptr<SYMBOL_UNIT_MENU> symUnitMenu3 = std::make_shared<SYMBOL_UNIT_MENU>();
301  symUnitMenu3->SetTool( m_selectionTool );
302  m_selectionTool->GetToolMenu().AddSubMenu( symUnitMenu3 );
303  selToolMenu.AddMenu( symUnitMenu3.get(), E_C::SingleMultiUnitSymbol, 1 );
304 
305  selToolMenu.AddItem( EE_ACTIONS::editWithLibEdit, singleComponentCondition && E_C::Idle, 200 );
306 
307  selToolMenu.AddItem( EE_ACTIONS::toShapeSlash, entryCondition, 200 );
308  selToolMenu.AddItem( EE_ACTIONS::toShapeBackslash, entryCondition, 200 );
309  selToolMenu.AddItem( EE_ACTIONS::toLabel, toLabelCondition, 200 );
310  selToolMenu.AddItem( EE_ACTIONS::toHLabel, toHLabelCondition, 200 );
311  selToolMenu.AddItem( EE_ACTIONS::toGLabel, toGLabelCondition, 200 );
312  selToolMenu.AddItem( EE_ACTIONS::toText, toTextlCondition, 200 );
313  selToolMenu.AddItem( EE_ACTIONS::cleanupSheetPins, singleSheetCondition, 250 );
314 
315  selToolMenu.AddSeparator( 300 );
316  selToolMenu.AddItem( ACTIONS::cut, E_C::IdleSelection, 300 );
317  selToolMenu.AddItem( ACTIONS::copy, E_C::IdleSelection, 300 );
318  selToolMenu.AddItem( ACTIONS::paste, E_C::Idle, 300 );
319  selToolMenu.AddItem( ACTIONS::pasteSpecial, E_C::Idle, 300 );
320  selToolMenu.AddItem( ACTIONS::duplicate, duplicateCondition, 300 );
321 
322  return true;
323 }
324 
325 
327  SCH_TEXT_T,
328  SCH_LABEL_T,
331  SCH_FIELD_T,
334  SCH_SHEET_T,
335  SCH_BITMAP_T,
338  SCH_LINE_T,
340  EOT
341 };
342 
343 
344 int SCH_EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
345 {
347 
348  if( selection.GetSize() == 0 )
349  return 0;
350 
351  wxPoint rotPoint;
352  bool clockwise = ( aEvent.Matches( EE_ACTIONS::rotateCW.MakeEvent() ) );
353  SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
354  bool connections = false;
355  bool moving = item->IsMoving();
356 
357  if( selection.GetSize() == 1 )
358  {
359  if( !moving )
361 
362  for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
363  {
364  switch( item->Type() )
365  {
366  case SCH_COMPONENT_T:
367  {
368  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
369 
370  if( clockwise )
371  component->SetOrientation( CMP_ROTATE_CLOCKWISE );
372  else
374 
375  if( m_frame->GetAutoplaceFields() )
376  component->AutoAutoplaceFields( m_frame->GetScreen() );
377 
378  break;
379  }
380 
381  case SCH_TEXT_T:
382  case SCH_LABEL_T:
383  case SCH_GLOBAL_LABEL_T:
384  case SCH_HIER_LABEL_T:
385  {
386  SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
387  textItem->SetLabelSpinStyle( ( textItem->GetLabelSpinStyle() + 1 ) & 3 );
388  break;
389  }
390 
391  case SCH_SHEET_PIN_T:
392  {
393  // Rotate pin within parent sheet
394  SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
395  SCH_SHEET* sheet = pin->GetParent();
396  pin->Rotate( sheet->GetBoundingBox().GetCenter() );
397  break;
398  }
399 
400  case SCH_BUS_BUS_ENTRY_T:
402  item->Rotate( item->GetPosition() );
403  break;
404 
405  case SCH_FIELD_T:
406  {
407  SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
408 
409  if( field->GetTextAngle() == TEXT_ANGLE_HORIZ )
410  field->SetTextAngle( TEXT_ANGLE_VERT );
411  else
412  field->SetTextAngle( TEXT_ANGLE_HORIZ );
413 
414  // Now that we're moving a field, they're no longer autoplaced.
415  if( item->GetParent()->Type() == SCH_COMPONENT_T )
416  {
417  SCH_COMPONENT *parent = static_cast<SCH_COMPONENT*>( item->GetParent() );
418  parent->ClearFieldsAutoplaced();
419  }
420 
421  break;
422  }
423 
424  case SCH_BITMAP_T:
425  item->Rotate( item->GetPosition() );
426  // The bitmap is cached in Opengl: clear the cache to redraw
428  break;
429 
430  case SCH_SHEET_T:
431  {
432  SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
433 
434  // Rotate the sheet on itself. Sheets do not have an anchor point.
435  rotPoint = m_frame->GetNearestGridPosition( sheet->GetRotationCenter() );
436  sheet->Rotate( rotPoint );
437  break;
438  }
439 
440  default:
441  break;
442  }
443  }
444 
445  connections = item->IsConnectable();
446  m_frame->RefreshItem( item );
447  }
448  else if( selection.GetSize() > 1 )
449  {
450  rotPoint = m_frame->GetNearestGridPosition( (wxPoint)selection.GetCenter() );
451 
452  for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
453  {
454  item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
455 
456  if( !moving )
457  saveCopyInUndoList( item, UR_CHANGED, ii > 0 );
458 
459  for( int i = 0; clockwise ? i < 1 : i < 3; ++i )
460  {
461  if( item->Type() == SCH_LINE_T )
462  {
463  SCH_LINE* line = (SCH_LINE*) item;
464 
465  if( item->HasFlag( STARTPOINT ) )
466  line->RotateStart( rotPoint );
467 
468  if( item->HasFlag( ENDPOINT ) )
469  line->RotateEnd( rotPoint );
470  }
471  else if( item->Type() == SCH_SHEET_PIN_T )
472  {
473  if( item->GetParent()->IsSelected() )
474  {
475  // parent will rotate us
476  }
477  else
478  {
479  // rotate within parent
480  SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
481  SCH_SHEET* sheet = pin->GetParent();
482 
483  pin->Rotate( sheet->GetBoundingBox().GetCenter() );
484  }
485  }
486  else
487  {
488  item->Rotate( rotPoint );
489  }
490  }
491 
492  connections |= item->IsConnectable();
493  m_frame->RefreshItem( item );
494  }
495  }
496 
498 
499  if( item->IsMoving() )
500  {
502  }
503  else
504  {
505  if( selection.IsHover() )
507 
508  if( connections )
510 
511  m_frame->OnModify();
512  }
513 
514  return 0;
515 }
516 
517 
518 int SCH_EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
519 {
521 
522  if( selection.GetSize() == 0 )
523  return 0;
524 
525  wxPoint mirrorPoint;
526  bool xAxis = ( aEvent.Matches( EE_ACTIONS::mirrorX.MakeEvent() ) );
527  SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
528  bool connections = false;
529  bool moving = item->IsMoving();
530 
531  if( selection.GetSize() == 1 )
532  {
533  if( !moving )
535 
536  switch( item->Type() )
537  {
538  case SCH_COMPONENT_T:
539  {
540  SCH_COMPONENT* component = static_cast<SCH_COMPONENT*>( item );
541 
542  if( xAxis )
543  component->SetOrientation( CMP_MIRROR_X );
544  else
545  component->SetOrientation( CMP_MIRROR_Y );
546 
547  if( m_frame->GetAutoplaceFields() )
548  component->AutoAutoplaceFields( m_frame->GetScreen() );
549 
550  break;
551  }
552 
553  case SCH_TEXT_T:
554  case SCH_LABEL_T:
555  case SCH_GLOBAL_LABEL_T:
556  case SCH_HIER_LABEL_T:
557  {
558  SCH_TEXT* textItem = static_cast<SCH_TEXT*>( item );
559  int spin = textItem->GetLabelSpinStyle();
560 
561  if( xAxis && spin % 2 )
562  textItem->SetLabelSpinStyle( ( spin + 2 ) % 4 );
563  else if ( !xAxis && !( spin % 2 ) )
564  textItem->SetLabelSpinStyle( ( spin + 2 ) % 4 );
565  break;
566  }
567 
568  case SCH_SHEET_PIN_T:
569  {
570  // mirror within parent sheet
571  SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
572  SCH_SHEET* sheet = pin->GetParent();
573 
574  if( xAxis )
575  pin->MirrorX( sheet->GetBoundingBox().GetCenter().y );
576  else
577  pin->MirrorY( sheet->GetBoundingBox().GetCenter().x );
578 
579  break;
580  }
581 
582  case SCH_BUS_BUS_ENTRY_T:
584  if( xAxis )
585  item->MirrorX( item->GetPosition().y );
586  else
587  item->MirrorY( item->GetPosition().x );
588  break;
589 
590  case SCH_FIELD_T:
591  {
592  SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
593 
594  if( xAxis )
596  else
598 
599  // Now that we're re-justifying a field, they're no longer autoplaced.
600  if( item->GetParent()->Type() == SCH_COMPONENT_T )
601  {
602  SCH_COMPONENT *parent = static_cast<SCH_COMPONENT*>( item->GetParent() );
603  parent->ClearFieldsAutoplaced();
604  }
605 
606  break;
607  }
608 
609  case SCH_BITMAP_T:
610  if( xAxis )
611  item->MirrorX( item->GetPosition().y );
612  else
613  item->MirrorY( item->GetPosition().x );
614 
615  // The bitmap is cached in Opengl: clear the cache to redraw
617  break;
618 
619  case SCH_SHEET_T:
620  // Mirror the sheet on itself. Sheets do not have a anchor point.
621  mirrorPoint = m_frame->GetNearestGridPosition( item->GetBoundingBox().Centre() );
622 
623  if( xAxis )
624  item->MirrorX( mirrorPoint.y );
625  else
626  item->MirrorY( mirrorPoint.x );
627 
628  break;
629 
630  default:
631  break;
632  }
633 
634  connections = item->IsConnectable();
635  m_frame->RefreshItem( item );
636  }
637  else if( selection.GetSize() > 1 )
638  {
639  mirrorPoint = (wxPoint)selection.GetReferencePoint();
640 
641  for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
642  {
643  item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
644 
645  if( !moving )
646  saveCopyInUndoList( item, UR_CHANGED, ii > 0 );
647 
648  if( item->Type() == SCH_SHEET_PIN_T )
649  {
650  if( item->GetParent()->IsSelected() )
651  {
652  // parent will mirror us
653  }
654  else
655  {
656  // mirror within parent sheet
657  SCH_SHEET_PIN* pin = static_cast<SCH_SHEET_PIN*>( item );
658  SCH_SHEET* sheet = pin->GetParent();
659 
660  if( xAxis )
661  pin->MirrorX( sheet->GetBoundingBox().GetCenter().y );
662  else
663  pin->MirrorY( sheet->GetBoundingBox().GetCenter().x );
664  }
665  }
666  else
667  {
668  if( xAxis )
669  item->MirrorX( mirrorPoint.y );
670  else
671  item->MirrorY( mirrorPoint.x );
672  }
673 
674  connections |= item->IsConnectable();
675  m_frame->RefreshItem( item );
676  }
677  }
678 
680 
681  if( item->IsMoving() )
682  {
684  }
685  else
686  {
687  if( selection.IsHover() )
689 
690  if( connections )
692 
693  m_frame->OnModify();
694  }
695 
696  return 0;
697 }
698 
699 
701 {
703  SCH_LINE_T,
706  SCH_TEXT_T,
707  SCH_LABEL_T,
711  SCH_SHEET_T,
713  EOT
714 };
715 
716 
718 {
720 
721  if( selection.GetSize() == 0 )
722  return 0;
723 
724  // Doing a duplicate of a new object doesn't really make any sense; we'd just end
725  // up dragging around a stack of objects...
726  if( selection.Front()->IsNew() )
727  return 0;
728 
729  EDA_ITEMS newItems;
730 
731  // Keep track of existing sheet paths. Duplicating a selection can modify this list
732  bool copiedSheets = false;
733  SCH_SHEET_LIST initial_sheetpathList( g_RootSheet );
734 
735  for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
736  {
737  SCH_ITEM* oldItem = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
738  SCH_ITEM* newItem = oldItem->Duplicate();
739  newItem->SetFlags( IS_NEW );
740  newItems.push_back( newItem );
741  saveCopyInUndoList( newItem, UR_NEW, ii > 0 );
742 
743  switch( newItem->Type() )
744  {
745  case SCH_JUNCTION_T:
746  case SCH_LINE_T:
747  case SCH_BUS_BUS_ENTRY_T:
749  case SCH_TEXT_T:
750  case SCH_LABEL_T:
751  case SCH_GLOBAL_LABEL_T:
752  case SCH_HIER_LABEL_T:
753  case SCH_NO_CONNECT_T:
754  newItem->SetParent( m_frame->GetScreen() );
755  m_frame->AddToScreen( newItem );
756  break;
757 
758  case SCH_SHEET_T:
759  {
760  SCH_SHEET* sheet = (SCH_SHEET*) newItem;
761  // Duplicate sheet names and sheet time stamps are not valid. Use a time stamp
762  // based sheet name and update the time stamp for each sheet in the block.
763  timestamp_t timeStamp = GetNewTimeStamp();
764 
765  sheet->SetName( wxString::Format( wxT( "sheet%8.8lX" ), (unsigned long)timeStamp ) );
766  sheet->SetTimeStamp( timeStamp );
767 
768  sheet->SetParent( m_frame->GetScreen() );
769  m_frame->AddToScreen( sheet );
770 
771  copiedSheets = true;
772  break;
773  }
774 
775  case SCH_COMPONENT_T:
776  {
777  SCH_COMPONENT* component = (SCH_COMPONENT*) newItem;
778 
779  component->SetTimeStamp( GetNewTimeStamp() );
780  component->ClearAnnotation( NULL );
781 
782  component->SetParent( m_frame->GetScreen() );
783  m_frame->AddToScreen( component );
784  break;
785  }
786 
787  default:
788  break;
789  }
790  }
791 
792  if( copiedSheets )
793  {
794  // We clear annotation of new sheet paths.
795  // Annotation of new components added in current sheet is already cleared.
796  SCH_SCREENS screensList( g_RootSheet );
797  screensList.ClearAnnotationOfNewSheetPaths( initial_sheetpathList );
799  }
800 
802  m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &newItems );
804 
805  return 0;
806 }
807 
808 
810 {
811  SCH_ITEM* sourceItem = m_frame->GetRepeatItem();
812 
813  if( !sourceItem )
814  return 0;
815 
817 
818  SCH_ITEM* newItem = (SCH_ITEM*) sourceItem->Clone();
819  bool performDrag = false;
820 
821  // If cloning a component then put into 'move' mode.
822  if( newItem->Type() == SCH_COMPONENT_T )
823  {
824  ( (SCH_COMPONENT*) newItem )->SetTimeStamp( GetNewTimeStamp() );
825 
826  wxPoint cursorPos = (wxPoint) getViewControls()->GetCursorPosition( true );
827  newItem->Move( cursorPos - newItem->GetPosition() );
828  performDrag = true;
829  }
830  else
831  {
832  if( newItem->CanIncrementLabel() )
833  ( (SCH_TEXT*) newItem )->IncrementLabel( m_frame->GetRepeatDeltaLabel() );
834 
835  newItem->Move( m_frame->GetRepeatStep() );
836  }
837 
838  newItem->SetFlags( IS_NEW );
839  m_frame->AddToScreen( newItem );
840  m_frame->SaveCopyInUndoList( newItem, UR_NEW );
841 
842  m_selectionTool->AddItemToSel( newItem );
843 
844  if( performDrag )
846 
847  newItem->ClearFlags();
848 
849  if( newItem->IsConnectable() )
850  {
851  auto selection = m_selectionTool->GetSelection();
852 
853  m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &selection );
856  }
857 
858  // newItem newItem, now that it has been moved, thus saving new position.
859  m_frame->SaveCopyForRepeatItem( newItem );
860 
861  return 0;
862 }
863 
864 
866 {
867  SCH_MARKER_T,
869  SCH_LINE_T,
872  SCH_TEXT_T,
873  SCH_LABEL_T,
877  SCH_SHEET_T,
880  SCH_BITMAP_T,
881  EOT
882 };
883 
884 
886 {
887  SCH_SCREEN* screen = m_frame->GetScreen();
889  bool appendToUndo = false;
890  std::vector<wxPoint> pts;
891 
892  if( items.empty() )
893  return 0;
894 
895  // Don't leave a freed pointer in the selection
897 
898  for( EDA_ITEM* item : items )
899  item->ClearFlags( STRUCT_DELETED );
900 
901  for( EDA_ITEM* item : items )
902  {
903  SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item );
904 
905  if( !sch_item )
906  continue;
907 
908  if( sch_item->Type() == SCH_JUNCTION_T )
909  {
910  sch_item->SetFlags( STRUCT_DELETED );
911  sch_item->GetConnectionPoints( pts );
912 
913  // clean up junctions at the end
914  }
915  else
916  {
917  sch_item->SetFlags( STRUCT_DELETED );
918  saveCopyInUndoList( item, UR_DELETED, appendToUndo );
919  appendToUndo = true;
920 
921  if( sch_item && sch_item->IsConnectable() )
922  sch_item->GetConnectionPoints( pts );
923 
924  updateView( sch_item );
925 
926  if( sch_item->Type() == SCH_SHEET_PIN_T )
927  {
928  SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) sch_item;
929  SCH_SHEET* sheet = pin->GetParent();
930 
931  sheet->RemovePin( pin );
932  }
933  else
934  m_frame->RemoveFromScreen( sch_item );
935  }
936  }
937 
938  for( auto point : pts )
939  {
940  SCH_ITEM* junction = screen->GetItem( point, 0, SCH_JUNCTION_T );
941 
942  if( !junction )
943  continue;
944 
945  if( junction->HasFlag( STRUCT_DELETED ) || !screen->IsJunctionNeeded( point ) )
946  m_frame->DeleteJunction( junction, appendToUndo );
947  }
948 
950 
951  m_frame->GetCanvas()->Refresh();
952  m_frame->OnModify();
953 
954  return 0;
955 }
956 
957 
958 #define HITTEST_THRESHOLD_PIXELS 5
959 
960 
962 {
963  std::string tool = aEvent.GetCommandStr().get();
965 
967  m_pickerItem = nullptr;
968 
969  // Deactivate other tools; particularly important if another PICKER is currently running
970  Activate();
971 
972  picker->SetCursor( wxStockCursor( wxCURSOR_BULLSEYE ) );
973 
974  picker->SetClickHandler(
975  [this] ( const VECTOR2D& aPosition ) -> bool
976  {
977  if( m_pickerItem )
978  {
979  SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( m_pickerItem );
980 
981  if( sch_item && sch_item->IsLocked() )
982  {
983  STATUS_TEXT_POPUP statusPopup( m_frame );
984  statusPopup.SetText( _( "Item locked." ) );
985  statusPopup.PopupFor( 2000 );
986  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
987  return true;
988  }
989 
991  selectionTool->UnbrightenItem( m_pickerItem );
992  selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
994  m_pickerItem = nullptr;
995  }
996 
997  return true;
998  } );
999 
1000  picker->SetMotionHandler(
1001  [this] ( const VECTOR2D& aPos )
1002  {
1003  EE_COLLECTOR collector;
1004  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
1005  collector.Collect( m_frame->GetScreen()->GetDrawItems(), deletableItems, (wxPoint) aPos );
1006 
1008  selectionTool->GuessSelectionCandidates( collector, aPos );
1009 
1010  EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
1011 
1012  if( m_pickerItem != item )
1013  {
1014  if( m_pickerItem )
1015  selectionTool->UnbrightenItem( m_pickerItem );
1016 
1017  m_pickerItem = item;
1018 
1019  if( m_pickerItem )
1020  selectionTool->BrightenItem( m_pickerItem );
1021  }
1022  } );
1023 
1024  picker->SetFinalizeHandler(
1025  [this] ( const int& aFinalState )
1026  {
1027  if( m_pickerItem )
1029  } );
1030 
1031  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1032 
1033  return 0;
1034 }
1035 
1036 
1038 {
1039  SCH_COMPONENT* component = (SCH_COMPONENT*) aField->GetParent();
1040 
1041  // Save old component in undo list if not already in edit, or moving.
1042  if( aField->GetEditFlags() == 0 ) // i.e. not edited, or moved
1043  m_frame->SaveCopyInUndoList( component, UR_CHANGED );
1044 
1045  wxString title = wxString::Format( _( "Edit %s Field" ), aField->GetName() );
1046 
1047  DIALOG_SCH_EDIT_ONE_FIELD dlg( m_frame, title, aField );
1048 
1049  // The footprint field dialog can invoke a KIWAY_PLAYER so we must use a quasi-modal
1050  if( dlg.ShowQuasiModal() != wxID_OK )
1051  return;
1052 
1053  dlg.UpdateField( aField, g_CurrentSheet );
1054 
1055  if( m_frame->GetAutoplaceFields() )
1056  component->AutoAutoplaceFields( m_frame->GetScreen() );
1057 
1059  m_frame->RefreshItem( aField );
1060  m_frame->OnModify();
1061 }
1062 
1063 
1065 {
1066  static KICAD_T Nothing[] = { EOT };
1067  static KICAD_T CmpOrReference[] = { SCH_FIELD_LOCATE_REFERENCE_T, SCH_COMPONENT_T, EOT };
1068  static KICAD_T CmpOrValue[] = { SCH_FIELD_LOCATE_VALUE_T, SCH_COMPONENT_T, EOT };
1069  static KICAD_T CmpOrFootprint[] = { SCH_FIELD_LOCATE_FOOTPRINT_T, SCH_COMPONENT_T, EOT };
1070 
1071  KICAD_T* filter = Nothing;
1072 
1073  if( aEvent.IsAction( &EE_ACTIONS::editReference ) )
1074  filter = CmpOrReference;
1075  else if( aEvent.IsAction( &EE_ACTIONS::editValue ) )
1076  filter = CmpOrValue;
1077  else if( aEvent.IsAction( &EE_ACTIONS::editFootprint ) )
1078  filter = CmpOrFootprint;
1079 
1080  EE_SELECTION& selection = m_selectionTool->RequestSelection( filter );
1081 
1082  if( selection.Empty() )
1083  return 0;
1084 
1085  SCH_ITEM* item = (SCH_ITEM*) selection.Front();
1086 
1087  if( item->Type() == SCH_COMPONENT_T )
1088  {
1089  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
1090 
1091  if( aEvent.IsAction( &EE_ACTIONS::editReference ) )
1092  editComponentFieldText( component->GetField( REFERENCE ) );
1093  else if( aEvent.IsAction( &EE_ACTIONS::editValue ) )
1094  editComponentFieldText( component->GetField( VALUE ) );
1095  else if( aEvent.IsAction( &EE_ACTIONS::editFootprint ) )
1096  editComponentFieldText( component->GetField( FOOTPRINT ) );
1097  }
1098  else if( item->Type() == SCH_FIELD_T )
1099  {
1100  editComponentFieldText( (SCH_FIELD*) item );
1101  }
1102 
1103  return 0;
1104 }
1105 
1106 
1108 {
1110 
1111  if( selection.Empty() )
1112  return 0;
1113 
1114  SCH_COMPONENT* component = (SCH_COMPONENT*) selection.Front();
1115 
1116  if( !component->IsNew() )
1117  m_frame->SaveCopyInUndoList( component, UR_CHANGED );
1118 
1119  component->AutoplaceFields( m_frame->GetScreen(), /* aManual */ true );
1120 
1121  updateView( component );
1122  m_frame->OnModify();
1123 
1124  return 0;
1125 }
1126 
1127 
1129 {
1130  std::list<SCH_COMPONENT*> components;
1131 
1132  for( SCH_ITEM* item = m_frame->GetScreen()->GetDrawItems(); item; item = item->Next() )
1133  {
1134  if( item->Type() == SCH_COMPONENT_T )
1135  components.push_back( static_cast<SCH_COMPONENT*>( item ) );
1136  }
1137 
1138  if( InvokeDialogUpdateFields( m_frame, components, true ) == wxID_OK )
1139  m_frame->GetCanvas()->Refresh();
1140 
1141  return 0;
1142 }
1143 
1144 
1146 {
1148 
1149  if( selection.Empty() )
1150  return 0;
1151 
1152  SCH_COMPONENT* component = (SCH_COMPONENT*) selection.Front();
1153 
1155  && component->GetConvert() == LIB_ITEM::LIB_CONVERT::BASE )
1156  return 0;
1157 
1159  && component->GetConvert() != LIB_ITEM::LIB_CONVERT::DEMORGAN )
1160  return 0;
1161 
1162  if( !component->IsNew() )
1163  m_frame->SaveCopyInUndoList( component, UR_CHANGED );
1164 
1165  m_frame->ConvertPart( component );
1166 
1167  if( component->IsNew() )
1169 
1170  return 0;
1171 }
1172 
1173 
1175 {
1177 
1178  if( selection.Empty() )
1179  return 0;
1180 
1181  SCH_ITEM* item = (SCH_ITEM*) selection.Front();
1182 
1183  switch( item->Type() )
1184  {
1185  case SCH_COMPONENT_T:
1186  {
1187  SCH_COMPONENT* component = (SCH_COMPONENT*) item;
1188  DIALOG_EDIT_COMPONENT_IN_SCHEMATIC dlg( m_frame, component );
1189 
1190  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
1191  // frame. Therefore this dialog as a modal frame parent, MUST be run under
1192  // quasimodal mode for the quasimodal frame support to work. So don't use
1193  // the QUASIMODAL macros here.
1194  if( dlg.ShowQuasiModal() == wxID_OK )
1195  {
1196  if( m_frame->GetAutoplaceFields() )
1197  component->AutoAutoplaceFields( m_frame->GetScreen() );
1198 
1200  m_frame->OnModify();
1201  }
1202  }
1203  break;
1204 
1205  case SCH_SHEET_T:
1206  {
1207  bool doClearAnnotation;
1208  bool doRefresh = false;
1209  // Keep track of existing sheet paths. EditSheet() can modify this list
1210  SCH_SHEET_LIST initial_sheetpathList( g_RootSheet );
1211 
1212  doRefresh = m_frame->EditSheet( (SCH_SHEET*) item, g_CurrentSheet, &doClearAnnotation );
1213 
1214  if( doClearAnnotation ) // happens when the current sheet load a existing file
1215  { // we must clear "new" components annotation
1216  SCH_SCREENS screensList( g_RootSheet );
1217  // We clear annotation of new sheet paths here:
1218  screensList.ClearAnnotationOfNewSheetPaths( initial_sheetpathList );
1219  // Clear annotation of g_CurrentSheet itself, because its sheetpath
1220  // is not a new path, but components managed by its sheet path must have
1221  // their annotation cleared, because they are new:
1222  ((SCH_SHEET*) item)->GetScreen()->ClearAnnotation( g_CurrentSheet );
1223  }
1224 
1225  if( doRefresh )
1226  {
1228  m_frame->GetCanvas()->Refresh();
1229  }
1230 
1231  break;
1232  }
1233 
1234  case SCH_SHEET_PIN_T:
1235  {
1236  SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) item;
1237  DIALOG_EDIT_SHEET_PIN dlg( m_frame, pin );
1238 
1239  if( dlg.ShowModal() == wxID_OK )
1240  {
1242  m_frame->OnModify();
1243  }
1244  }
1245  break;
1246 
1247  case SCH_TEXT_T:
1248  case SCH_LABEL_T:
1249  case SCH_GLOBAL_LABEL_T:
1250  case SCH_HIER_LABEL_T:
1251  if( InvokeDialogLabelEditor( m_frame, (SCH_TEXT*) item ) == wxID_OK )
1252  {
1254  m_frame->OnModify();
1255  }
1256 
1257  break;
1258 
1259  case SCH_FIELD_T:
1260  editComponentFieldText( (SCH_FIELD*) item );
1261  break;
1262 
1263  case SCH_BITMAP_T:
1264  {
1265  SCH_BITMAP* bitmap = (SCH_BITMAP*) item;
1266  DIALOG_IMAGE_EDITOR dlg( m_frame, bitmap->GetImage() );
1267 
1268  if( dlg.ShowModal() == wxID_OK )
1269  {
1270  // save old image in undo list if not already in edit
1271  if( bitmap->GetEditFlags() == 0 )
1273 
1274  dlg.TransferToImage( bitmap->GetImage() );
1275 
1276  // The bitmap is cached in Opengl: clear the cache in case it has become invalid
1277  getView()->RecacheAllItems();
1279  m_frame->OnModify();
1280  }
1281  }
1282  break;
1283 
1284  case SCH_LINE_T:
1285  {
1286  SCH_LINE* line = (SCH_LINE*) item;
1287 
1288  // We purposely disallow editing everything except graphic lines
1289  if( line->GetLayer() != LAYER_NOTES )
1290  break;
1291 
1292  DIALOG_EDIT_LINE_STYLE dlg( m_frame, line );
1293 
1294  if( dlg.ShowModal() == wxID_OK )
1295  {
1297  m_frame->OnModify();
1298  }
1299  }
1300  break;
1301 
1302  case SCH_MARKER_T: // These items have no properties to edit
1303  case SCH_JUNCTION_T:
1304  case SCH_NO_CONNECT_T:
1305  break;
1306 
1307  default: // Unexpected item
1308  wxFAIL_MSG( wxString( "Cannot edit schematic item type " ) + item->GetClass() );
1309  }
1310 
1311  updateView( item );
1312 
1313  if( selection.IsHover() )
1314  {
1316  }
1317 
1318  return 0;
1319 }
1320 
1321 
1323 {
1324  EE_SELECTION& selection = m_selectionTool->GetSelection();
1325  char shape = aEvent.Parameter<char>();
1326 
1327  for( unsigned int i = 0; i < selection.GetSize(); ++i )
1328  {
1329  SCH_BUS_ENTRY_BASE* entry = dynamic_cast<SCH_BUS_ENTRY_BASE*>( selection.GetItem( i ) );
1330 
1331  if( entry )
1332  {
1333  if( entry->GetEditFlags() == 0 )
1335 
1336  entry->SetBusEntryShape( shape );
1338 
1339  updateView( entry );
1340  m_frame->OnModify( );
1341  }
1342  }
1343 
1344  g_lastBusEntryShape = shape;
1345 
1346  return 0;
1347 }
1348 
1349 
1351 {
1352  KICAD_T convertTo = aEvent.Parameter<KICAD_T>();
1354  EE_SELECTION& selection = m_selectionTool->RequestSelection( allTextTypes );
1355 
1356  for( unsigned int i = 0; i < selection.GetSize(); ++i )
1357  {
1358  SCH_TEXT* text = dynamic_cast<SCH_TEXT*>( selection.GetItem( i ) );
1359 
1360  if( text )
1361  m_frame->ConvertTextType( text, convertTo );
1362  }
1363 
1364  return 0;
1365 }
1366 
1367 
1369 {
1370  auto cursorPos = wxPoint( getViewControls()->GetCursorPosition( !aEvent.Modifier( MD_ALT ) ) );
1371 
1372  if( m_frame->BreakSegments( cursorPos ) )
1373  {
1374  if( m_frame->GetScreen()->IsJunctionNeeded( cursorPos, true ) )
1375  m_frame->AddJunction( cursorPos, true, false );
1376 
1378 
1379  m_frame->OnModify();
1380  m_frame->GetCanvas()->Refresh();
1381  }
1382 
1383  return 0;
1384 }
1385 
1386 
1388 {
1390  SCH_SHEET* sheet = (SCH_SHEET*) selection.Front();
1391 
1392  if( !sheet )
1393  return 0;
1394 
1395  if( !sheet->HasUndefinedPins() )
1396  {
1397  DisplayInfoMessage( m_frame, _( "There are no unreferenced pins in this sheet to remove." ) );
1398  return 0;
1399  }
1400 
1401  if( !IsOK( m_frame, _( "Do you wish to delete the unreferenced pins from this sheet?" ) ) )
1402  return 0;
1403 
1405 
1406  sheet->CleanupSheet();
1407 
1408  updateView( sheet );
1409  m_frame->OnModify();
1410 
1411  return 0;
1412 }
1413 
1414 
1416 {
1421  Go( &SCH_EDIT_TOOL::Mirror, EE_ACTIONS::mirrorX.MakeEvent() );
1422  Go( &SCH_EDIT_TOOL::Mirror, EE_ACTIONS::mirrorY.MakeEvent() );
1423  Go( &SCH_EDIT_TOOL::DoDelete, ACTIONS::doDelete.MakeEvent() );
1425 
1435 
1442 
1445 
1448 }
void SetTextAngle(double aAngle)
Definition: eda_text.h:150
#define TEXT_ANGLE_HORIZ
VECTOR2I GetReferencePoint() const
Definition: selection.h:238
Class SCH_SHEET_LIST.
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
void SetTimeStamp(timestamp_t aNewTimeStamp)
Change the time stamp to aNewTimeStamp and updates the reference path.
static TOOL_ACTION properties
Definition: ee_actions.h:122
Class SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
void SetCursor(const wxCursor &aCursor)
Definition: picker_tool.h:65
bool SchematicCleanUp(SCH_SCREEN *aScreen=nullptr)
Performs routine schematic cleaning including breaking wire and buses and deleting identical objects ...
void AutoAutoplaceFields(SCH_SCREEN *aScreen)
Autoplace fields only if correct to do so automatically.
#define HITTEST_THRESHOLD_PIXELS
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
int m_Threshold
Definition: collector.h:68
virtual bool IsConnectable() const
Function IsConnectable returns true if the schematic item can connect to another schematic item.
Definition: sch_item.h:298
EDA_TEXT_HJUSTIFY_T
Definition: eda_text.h:44
PART_REF & GetPartRef()
EDA_TEXT_VJUSTIFY_T GetVertJustify() const
Definition: eda_text.h:185
bool IsHover() const
Definition: selection.h:69
SCH_SHEET * GetParent() const
Get the parent sheet object of this sheet pin.
Definition: sch_sheet.h:158
SCH_ITEM * Duplicate(bool doClone=false)
Routine to create a new copy of given item.
Definition: sch_item.cpp:75
static TOOL_ACTION toggleDeMorgan
Definition: ee_actions.h:127
void SetMotionHandler(MOTION_HANDLER aHandler)
Function SetMotionHandler() Sets a handler for mouse motion.
Definition: picker_tool.h:82
static TOOL_ACTION breakBus
Definition: ee_actions.h:138
static SELECTION_CONDITION SingleSymbol
static KICAD_T duplicatableItems[]
bool IsSelected() const
Definition: base_struct.h:233
#define TEXT_ANGLE_VERT
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr)
Add an item to the screen (and view) aScreen is the screen the item is located on,...
Class ACTION_MENU.
Definition: action_menu.h:43
This file is part of the common library.
static TOOL_ACTION doDelete
Definition: actions.h:74
bool IsJunctionNeeded(const wxPoint &aPosition, bool aNew=false)
Test if a junction is required for the items at aPosition on the screen.
Definition: sch_screen.cpp:347
SCH_ITEM * Next() const
Definition: sch_item.h:153
Class SCH_DRAWING_TOOLS.
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
Definition: picker_tool.h:72
static TOOL_ACTION toShapeBackslash
Definition: ee_actions.h:132
void MirrorY(int aYaxis_position) override
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
bool BreakSegments(const wxPoint &aPoint, SCH_SCREEN *aScreen=nullptr)
Checks every wire and bus for a intersection at aPoint and break into two segments at aPoint if an in...
static SELECTION_CONDITION MoreThan(int aNumber)
Function MoreThan Creates a functor that tests if the number of selected items is greater than the va...
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:65
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Function OnlyTypes Creates a functor that tests if the selected items are only of given types.
void RotateEnd(wxPoint aPosition)
Definition: sch_line.cpp:366
Class STATUS_TEXT_POPUP.
Definition: status_popup.h:79
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.h:136
virtual void SetLabelSpinStyle(int aSpinStyle)
Set a spin or rotation angle, along with specific horizontal and vertical justification styles with e...
Definition: sch_text.cpp:234
bool IsMoving() const
Definition: base_struct.h:230
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
int Rotate(const TOOL_EVENT &aEvent)
static TOOL_ACTION mirrorY
Definition: ee_actions.h:121
static TOOL_ACTION placeHierLabel
Definition: ee_actions.h:90
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void RecacheAllItems()
Function RecacheAllItems() Rebuilds GAL display lists.
Definition: view.cpp:1402
int BreakWire(const TOOL_EVENT &aEvent)
static SELECTION_CONDITION IdleSelection
virtual void GetConnectionPoints(std::vector< wxPoint > &aPoints) const
Function GetConnectionPoints add all the connection points for this item to aPoints.
Definition: sch_item.h:308
virtual bool CanIncrementLabel() const
Definition: sch_item.h:359
TOOL_MENU & GetToolMenu()
double GetTextAngle() const
Definition: eda_text.h:158
char g_lastBusEntryShape
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
Class EE_COLLECTOR.
Definition: ee_collectors.h:39
static TOOL_ACTION toText
Definition: ee_actions.h:136
static TOOL_ACTION autoplaceFields
Definition: ee_actions.h:126
Schematic editor (Eeschema) main window.
int Properties(const TOOL_EVENT &aEvent)
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
void RemoveFromScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr)
Remove an item from the screen (and view) aScreen is the screen the item is located on,...
int UpdateFields(const TOOL_EVENT &aEvent)
static const KICAD_T ComponentsOnly[]
Definition: ee_collectors.h:44
static SELECTION_CONDITION Idle
static const KICAD_T SheetsOnly[]
Definition: ee_collectors.h:45
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
static SELECTION_CONDITION Count(int aNumber)
Function Count Creates a functor that tests if the number of selected items is equal to the value giv...
void setTransitions() override
Sets up handlers for various events.
void update() override
Update menu state stub.
void MirrorX(int aXaxis_position) override
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
bool GetAutoplaceFields() const
static TOOL_ACTION showDeMorganAlternate
Definition: ee_actions.h:129
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty Tests if there are any items selected.
void editComponentFieldText(SCH_FIELD *aField)
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
bool EditSheet(SCH_SHEET *aSheet, SCH_SHEET_PATH *aHierarchy, bool *aClearAnnotationNewItems)
Edit an existing sheet or add a new sheet to the schematic.
Definition: sheet.cpp:518
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:201
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 RotateStart(wxPoint aPosition)
Definition: sch_line.cpp:360
virtual EDA_ITEM * Clone() const
Function Clone creates a duplicate of this item with linked list members set to NULL.
static TOOL_ACTION breakWire
Definition: ee_actions.h:137
static TOOL_ACTION rotateCW
Definition: ee_actions.h:118
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:67
bool IsNew() const
Definition: base_struct.h:228
void ClearFieldsAutoplaced()
Set fields automatically placed flag false.
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
static TOOL_ACTION pickerTool
Definition: actions.h:145
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:41
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:69
int InvokeDialogLabelEditor(SCH_EDIT_FRAME *aCaller, SCH_TEXT *aTextItem)
Launches the "Edit Text/Label" dialog.
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Function SetFinalizeHandler() Sets a handler for the finalize event.
Definition: picker_tool.h:102
virtual void Rotate(wxPoint aPosition)=0
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
EE_SELECTION & GetSelection()
Function GetSelection()
#define IS_NEW
New item, just created.
Definition: base_struct.h:120
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Function RequestSelection()
int Duplicate(const TOOL_EVENT &aEvent)
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
int GetLabelSpinStyle() const
Definition: sch_text.h:124
static TOOL_ACTION drawSheet
Definition: ee_actions.h:91
static SELECTION_CONDITION SingleDeMorganSymbol
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
static TOOL_ACTION copy
Definition: actions.h:70
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
static TOOL_ACTION cleanupSheetPins
Definition: ee_actions.h:181
#define VALUE
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:119
int GetUnit() const
void BrightenItem(EDA_ITEM *aItem)
void RemovePin(SCH_SHEET_PIN *aSheetPin)
Remove aSheetPin from the sheet.
Definition: sch_sheet.cpp:187
virtual wxPoint GetPosition() const =0
Function GetPosition.
static TOOL_ACTION editFootprint
Definition: ee_actions.h:125
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:265
EDA_TEXT_HJUSTIFY_T GetHorizJustify() const
Definition: eda_text.h:184
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
EDA_RECT const GetBoundingBox() const override
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: sch_sheet.cpp:488
SCH_SHEET_PATH * g_CurrentSheet
With the new connectivity algorithm, many more places than before want to know what the current sheet...
BITMAP_BASE * GetImage()
Definition: sch_bitmap.h:59
void SetName(const wxString &aName)
Definition: sch_sheet.h:273
int ChangeShape(const TOOL_EVENT &aEvent)
void SetParent(EDA_ITEM *aParent)
Definition: base_struct.h:225
STATUS_FLAGS GetEditFlags() const
Definition: base_struct.h:270
int ShowQuasiModal()
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:642
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
void SetVertJustify(EDA_TEXT_VJUSTIFY_T aType)
Definition: eda_text.h:188
static TOOL_ACTION placeSchematicText
Definition: ee_actions.h:94
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:68
Class TOOL_EVENT.
Definition: tool_event.h:171
void SaveCopyInUndoList(SCH_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, bool aAppend=false, const wxPoint &aTransformPoint=wxPoint(0, 0))
Create a copy of the current schematic item, and put it in the undo list.
void Collect(EDA_ITEM *aItem, const KICAD_T aFilterList[], const wxPoint &aPos, int aUnit=0, int aConvert=0)
Function Collect scans a EDA_ITEM using this class's Inspector method, which does the collection.
int AutoplaceFields(const TOOL_EVENT &aEvent)
ACTION_MENU * create() const override
Returns an instance of this class. It has to be overridden in inheriting classes.
static TOOL_ACTION repeatDrawItem
Definition: ee_actions.h:117
SCH_ITEM * GetItem(const wxPoint &aPosition, int aAccuracy=0, KICAD_T aType=SCH_LOCATE_ANY_T) const
Check aPosition within a distance of aAccuracy for items of type aFilter.
Definition: sch_screen.cpp:234
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:130
static TOOL_ACTION cut
Definition: actions.h:69
void SaveCopyForRepeatItem(SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
const wxPoint GetRepeatStep() const
#define STRUCT_DELETED
flag indication structures to be erased
Definition: base_struct.h:129
SCH_JUNCTION * AddJunction(const wxPoint &aPos, bool aAppendToUndo=false, bool aFinal=true)
EDA_ITEM * GetParent() const
Definition: base_struct.h:220
const KICAD_T rotatableItems[]
static TOOL_ACTION mirrorX
Definition: ee_actions.h:120
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:140
bool Matches(const TOOL_EVENT &aEvent) const
Function Matches() Tests whether two events match in terms of category & action or command.
Definition: tool_event.h:364
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:75
virtual void MirrorX(int aXaxis_position)=0
Function MirrorX mirrors item relative to the X axis about aXaxis_position.
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:58
void SetBusEntryShape(char aShape)
function SetBusEntryShape
virtual void Move(const wxPoint &aWhere)
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
static TOOL_ACTION addNeededJunctions
Definition: ee_actions.h:77
int CleanupSheetPins(const TOOL_EVENT &aEvent)
static SELECTION_CONDITION SingleMultiUnitSymbol
virtual void MirrorY(int aYaxis_position)=0
Function MirrorY mirrors item relative to the Y axis about aYaxis_position.
static TOOL_ACTION editTextAndGraphics
Definition: ee_actions.h:182
void ClearAnnotation(SCH_SHEET_PATH *aSheetPath)
Clear exiting component annotation.
void CleanupSheet()
Delete sheet label which do not have a corresponding hierarchical label.
Definition: sch_sheet.cpp:350
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.h:103
virtual void PopupFor(int aMsecs)
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
Definition: sch_sheet.cpp:665
#define _(s)
int DeleteItemCursor(const TOOL_EVENT &aEvent)
Runs the deletion tool.
void UnbrightenItem(EDA_ITEM *aItem)
static TOOL_ACTION showDeMorganStandard
Definition: ee_actions.h:128
Class DIALOG_SCH_EDIT_ONE_FIELD is a the class to handle editing a single component field in the sche...
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:42
int InvokeDialogUpdateFields(SCH_EDIT_FRAME *aCaller, const list< SCH_COMPONENT * > aComponents, bool aCreateUndoEntry)
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
int Mirror(const TOOL_EVENT &aEvent)
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION pasteSpecial
Definition: actions.h:72
EDA_TEXT_VJUSTIFY_T
Definition: eda_text.h:51
EDA_ITEM * m_pickerItem
Definition: sch_edit_tool.h:78
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:98
SCH_LAYER_ID GetLayer() const
Function GetLayer returns the layer this item is on.
Definition: sch_item.h:193
virtual bool IsLocked() const
Function IsLocked.
Definition: sch_item.h:181
int RepeatDrawItem(const TOOL_EVENT &aEvent)
int Modifier(int aMask=MD_MODIFIER_MASK) const
Returns information about key modifiers state (Ctrl, Alt, etc.)
Definition: tool_event.h:342
static TOOL_ACTION updateFieldsFromLibrary
Definition: ee_actions.h:151
static TOOL_ACTION placeLabel
Definition: ee_actions.h:88
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
bool HasUndefinedPins()
Check all sheet labels against schematic for undefined hierarchical labels.
Definition: sch_sheet.cpp:242
static TOOL_ACTION editValue
Definition: ee_actions.h:124
static KICAD_T deletableItems[]
SCH_ITEM * GetRepeatItem() const
Return the item which is to be repeated with the insert key.
void updateView(EDA_ITEM *aItem) const
Similar to getView()->Update(), but handles items that are redrawn by their parents.
Definition: ee_tool_base.h:104
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
void ConvertTextType(SCH_TEXT *aText, KICAD_T aNewType)
Change a text type to another one.
Definition: edit_label.cpp:191
void AutoplaceFields(SCH_SCREEN *aScreen, bool aManual)
Automatically orient all the fields in the component.
int AddItemToSel(const TOOL_EVENT &aEvent)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
void SetSheetNumberAndCount()
Set the m_ScreenNumber and m_NumberOfScreens members for screens.
void RefreshItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
void SetHorizJustify(EDA_TEXT_HJUSTIFY_T aType)
Definition: eda_text.h:187
TOOL_MANAGER * getToolManager() const
Returns an instance of TOOL_MANAGER class.
void DeleteJunction(SCH_ITEM *aItem, bool aAppend=false)
Removes a given junction and heals any wire segments under the junction.
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52
Dialog used to edit SCH_COMPONENT objects in a schematic.
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:370
size_t i
Definition: json11.cpp:649
#define ENDPOINT
ends. (Used to support dragging.)
Definition: base_struct.h:126
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Function OnlyType Creates a functor that tests if the selected items are only of given type.
static wxString SubReference(int aUnit, bool aAddSeparator=true)
int EditField(const TOOL_EVENT &aEvent)
void Clear()
Function Clear() Removes all the entries from the menu (as well as its title).
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
int GetRepeatDeltaLabel() const
void saveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO_T aType, bool aAppend=false)
Similar to m_frame->SaveCopyInUndoList(), but handles items that are owned by their parents.
Definition: ee_tool_base.h:117
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
wxString GetClass() const override
Function GetClass returns the class name.
Definition: sch_field.h:71
wxPoint Centre() const
Definition: eda_rect.h:62
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:266
void Activate()
Function Activate() Runs the tool.
wxPoint GetRotationCenter() const
Rotating around the boundingBox's center can cause walking when the sheetname or filename is longer t...
Definition: sch_sheet.cpp:522
void Rotate(wxPoint aPosition) override
Function Rotate rotates the item around aPosition 90 degrees in the clockwise direction.
static TOOL_ACTION deleteTool
Definition: actions.h:75
static TOOL_ACTION editWithLibEdit
Definition: ee_actions.h:156
static TOOL_ACTION move
Definition: ee_actions.h:115
Class EE_TOOL_BASE.
Definition: ee_tool_base.h:50
static TOOL_ACTION toLabel
Definition: ee_actions.h:133
int GetConvert() const
uint32_t timestamp_t
timestamp_t is our type to represent unique IDs for all kinds of elements; historically simply the ti...
Definition: common.h:53
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 toHLabel
Definition: ee_actions.h:134
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
static TOOL_ACTION editReference
Definition: ee_actions.h:123
void ClearAnnotationOfNewSheetPaths(SCH_SHEET_LIST &aInitialSheetPathList)
Clear the annotation for the components inside new sheetpaths when a complex hierarchy is modified an...
bool HasFlag(STATUS_FLAGS aFlag)
Definition: base_struct.h:268
const wxPoint GetCenter() const
Definition: eda_rect.h:117
static TOOL_ACTION placeGlobalLabel
Definition: ee_actions.h:89
int DoDelete(const TOOL_EVENT &aEvent)
Deletes the selected items, or the item under the cursor.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:265
void PostEvent(const TOOL_EVENT &aEvent)
Puts an event to the event queue to be processed at the end of event processing cycle.
Definition: tool_manager.h:237
void ConvertPart(SCH_COMPONENT *aComponent)
Definition: getpart.cpp:248
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
bool IsCurrentTool(const TOOL_ACTION &aAction) const
Class SCH_ITEM is a base class for any item which can be embedded within the SCHEMATIC container clas...
Definition: sch_item.h:114
static TOOL_ACTION toGLabel
Definition: ee_actions.h:135
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:281
Definitions of the SCH_TEXT class and derivatives for Eeschema.
int ConvertDeMorgan(const TOOL_EVENT &aEvent)
static TOOL_ACTION paste
Definition: actions.h:71
static const KICAD_T EditableItems[]
Definition: ee_collectors.h:43
static TOOL_ACTION duplicate
Definition: actions.h:73
int ChangeTextType(const TOOL_EVENT &aEvent)
void SetText(const wxString &aText)
Display a text.
static TOOL_ACTION toShapeSlash
Definition: ee_actions.h:131
Container class that holds multiple SCH_SCREEN objects in a hierarchy.
Definition: sch_screen.h:491
static TOOL_ACTION refreshPreview
Definition: actions.h:101
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:182
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: common.h:114
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:215
#define STARTPOINT
When a line is selected, these flags indicate which.
Definition: base_struct.h:125
void SetOrientation(int aOrientation)
Compute the new transform matrix based on aOrientation for the symbol which is applied to the current...
SCH_ITEM * GetDrawItems() const
Definition: sch_screen.h:152
virtual void Move(const wxPoint &aMoveVector)=0
Function Move moves the item by aMoveVector to a new position.