KiCad PCB EDA Suite
symbol_editor_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-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 <tool/picker_tool.h>
30 #include <ee_actions.h>
31 #include <bitmaps.h>
32 #include <kicad_string.h>
33 #include <symbol_edit_frame.h>
41 #include <lib_text.h>
43 #include <math/util.h> // for KiROUND
44 
46  EE_TOOL_BASE( "eeschema.SymbolEditTool" ),
47  m_pickerItem( nullptr )
48 {
49 }
50 
51 
53 {
55 
58 
59  wxASSERT_MSG( drawingTools, "eeschema.SymbolDrawing tool is not available" );
60 
61  auto haveSymbolCondition =
62  [&]( const SELECTION& sel )
63  {
64  return m_isSymbolEditor &&
65  static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
66  };
67 
68  auto canEdit =
69  [&]( const SELECTION& sel )
70  {
71  SYMBOL_EDIT_FRAME* editor = static_cast<SYMBOL_EDIT_FRAME*>( m_frame );
72  wxCHECK( editor, false );
73 
74  if( !editor->IsSymbolEditable() )
75  return false;
76 
77  if( editor->IsSymbolAlias() )
78  {
79  for( EDA_ITEM* item : sel )
80  {
81  if( item->Type() != LIB_FIELD_T )
82  return false;
83  }
84  }
85 
86  return true;
87  };
88 
89  // Add edit actions to the move tool menu
90  if( moveTool )
91  {
92  CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
93 
94  moveMenu.AddSeparator( 200 );
95  moveMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
96  moveMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
97  moveMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
98  moveMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
99 
100  moveMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
101 
102  moveMenu.AddSeparator( 300 );
105  moveMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
106  moveMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 200 );
107 
108  moveMenu.AddSeparator( 400 );
109  moveMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
110  }
111 
112  // Add editing actions to the drawing tool menu
113  CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
114 
115  drawMenu.AddSeparator( 200 );
116  drawMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::IdleSelection, 200 );
117  drawMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::IdleSelection, 200 );
118  drawMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::IdleSelection, 200 );
119  drawMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::IdleSelection, 200 );
120 
121  drawMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
122 
123  // Add editing actions to the selection tool menu
125 
126  selToolMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
127  selToolMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
128  selToolMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
129  selToolMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
130 
131  selToolMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
132 
133  selToolMenu.AddSeparator( 300 );
136  selToolMenu.AddItem( ACTIONS::paste, canEdit && EE_CONDITIONS::Idle, 300 );
137  selToolMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
138  selToolMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 300 );
139 
140  selToolMenu.AddSeparator( 400 );
141  selToolMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
142 
143  return true;
144 }
145 
146 
148 {
150 
151  if( selection.GetSize() == 0 )
152  return 0;
153 
154  wxPoint rotPoint;
155  bool ccw = ( aEvent.Matches( EE_ACTIONS::rotateCCW.MakeEvent() ) );
156  LIB_ITEM* item = static_cast<LIB_ITEM*>( selection.Front() );
157 
158  if( !item->IsMoving() )
160 
161  if( selection.GetSize() == 1 )
162  rotPoint = item->GetPosition();
163  else
164  rotPoint = m_frame->GetNearestGridPosition( mapCoords( selection.GetCenter() ) );
165 
166  for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
167  {
168  item = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
169  item->Rotate( rotPoint, ccw );
170  m_frame->UpdateItem( item );
171  }
172 
173  if( item->IsMoving() )
174  {
176  }
177  else
178  {
180 
181  if( selection.IsHover() )
183 
184  m_frame->OnModify();
185  }
186 
187  return 0;
188 }
189 
190 
192 {
194 
195  if( selection.GetSize() == 0 )
196  return 0;
197 
198  wxPoint mirrorPoint;
199  bool xAxis = ( aEvent.Matches( EE_ACTIONS::mirrorV.MakeEvent() ) );
200  LIB_ITEM* item = static_cast<LIB_ITEM*>( selection.Front() );
201 
202  if( !item->IsMoving() )
204 
205  if( selection.GetSize() == 1 )
206  mirrorPoint = item->GetPosition();
207  else
208  mirrorPoint = m_frame->GetNearestHalfGridPosition( mapCoords( selection.GetCenter() ) );
209 
210  for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
211  {
212  item = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
213 
214  if( xAxis )
215  item->MirrorVertical( mirrorPoint );
216  else
217  item->MirrorHorizontal( mirrorPoint );
218 
219  m_frame->UpdateItem( item );
220  }
221 
223 
224  if( item->IsMoving() )
225  {
227  }
228  else
229  {
230  if( selection.IsHover() )
232 
233  m_frame->OnModify();
234  }
235 
236  return 0;
237 }
238 
239 
240 static KICAD_T nonFields[] =
241 {
242  LIB_SYMBOL_T,
243  LIB_ARC_T,
244  LIB_CIRCLE_T,
245  LIB_TEXT_T,
248  LIB_BEZIER_T,
249  LIB_PIN_T,
250  EOT
251 };
252 
253 
255 {
256  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
258 
259  if( items.empty() )
260  return 0;
261 
262  // Don't leave a freed pointer in the selection
264 
266 
267  std::set<LIB_ITEM *> toDelete;
268 
269  for( EDA_ITEM* item : items )
270  {
271  if( item->Type() == LIB_PIN_T )
272  {
273  LIB_PIN* pin = static_cast<LIB_PIN*>( item );
274  wxPoint pos = pin->GetPosition();
275 
276  toDelete.insert( pin );
277 
278  // when pin editing is synchronized, pins in the same position, with the same name
279  // in different units are also removed. But only one pin per unit (matching)
280  if( m_frame->SynchronizePins() )
281  {
282  std::vector<bool> got_unit( symbol->GetUnitCount() );
283 
284  got_unit[pin->GetUnit()] = true;
285 
286  int curr_convert = pin->GetConvert();
287  ELECTRICAL_PINTYPE etype = pin->GetType();
288  wxString name = pin->GetName();
289  LIB_PIN* next_pin = symbol->GetNextPin();
290 
291  while( next_pin != NULL )
292  {
293  pin = next_pin;
294  next_pin = symbol->GetNextPin( pin );
295 
296  if( got_unit[pin->GetUnit()] )
297  continue;
298 
299  if( pin->GetPosition() != pos )
300  continue;
301 
302  if( pin->GetConvert() != curr_convert )
303  continue;
304 
305  if( pin->GetType() != etype )
306  continue;
307 
308  if( pin->GetName() != name )
309  continue;
310 
311  toDelete.insert( pin );
312  got_unit[pin->GetUnit()] = true;
313  }
314  }
315  }
316  else
317  {
318  toDelete.insert( (LIB_ITEM*) item );
319  }
320  }
321 
322  for( LIB_ITEM* item : toDelete )
323  symbol->RemoveDrawItem( item );
324 
325  m_frame->RebuildView();
326  m_frame->OnModify();
327 
328  return 0;
329 }
330 
331 
332 #define HITTEST_THRESHOLD_PIXELS 5
333 
334 
336 {
337  std::string tool = aEvent.GetCommandStr().get();
339 
341  m_pickerItem = nullptr;
342 
343  // Deactivate other tools; particularly important if another PICKER is currently running
344  Activate();
345 
346  picker->SetCursor( KICURSOR::REMOVE );
347 
348  picker->SetClickHandler(
349  [this]( const VECTOR2D& aPosition ) -> bool
350  {
351  if( m_pickerItem )
352  {
354  selectionTool->UnbrightenItem( m_pickerItem );
355  selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
357  m_pickerItem = nullptr;
358  }
359 
360  return true;
361  } );
362 
363  picker->SetMotionHandler(
364  [this]( const VECTOR2D& aPos )
365  {
367  EE_COLLECTOR collector;
368 
369  selectionTool->CollectHits( collector, aPos, nonFields );
370 
371  // Remove unselectable items
372  for( int i = collector.GetCount() - 1; i >= 0; --i )
373  {
374  if( !selectionTool->Selectable( collector[ i ] ) )
375  collector.Remove( i );
376  }
377 
378  if( collector.GetCount() > 1 )
379  selectionTool->GuessSelectionCandidates( collector, aPos );
380 
381  EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
382 
383  if( m_pickerItem != item )
384  {
385  if( m_pickerItem )
386  selectionTool->UnbrightenItem( m_pickerItem );
387 
388  m_pickerItem = item;
389 
390  if( m_pickerItem )
391  selectionTool->BrightenItem( m_pickerItem );
392  }
393  } );
394 
395  picker->SetFinalizeHandler(
396  [this]( const int& aFinalState )
397  {
398  if( m_pickerItem )
400 
401  // Wake the selection tool after exiting to ensure the cursor gets updated
403  } );
404 
405  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
406 
407  return 0;
408 }
409 
410 
412 {
414 
415  if( selection.Empty() || aEvent.IsAction( &EE_ACTIONS::symbolProperties ) )
416  {
417  if( m_frame->GetCurSymbol() )
419  }
420  else if( selection.Size() == 1 )
421  {
422  LIB_ITEM* item = (LIB_ITEM*) selection.Front();
423 
424  // Save copy for undo if not in edit (edit command already handle the save copy)
425  if( item->GetEditFlags() == 0 )
427 
428  switch( item->Type() )
429  {
430  case LIB_PIN_T:
431  {
433 
434  if( pinTool )
435  pinTool->EditPinProperties( (LIB_PIN*) item );
436 
437  break;
438  }
439  case LIB_ARC_T:
440  case LIB_CIRCLE_T:
441  case LIB_RECTANGLE_T:
442  case LIB_POLYLINE_T:
443  editGraphicProperties( item );
444  break;
445 
446  case LIB_TEXT_T:
447  editTextProperties( item );
448  break;
449 
450  case LIB_FIELD_T:
451  editFieldProperties( (LIB_FIELD*) item );
452  break;
453 
454  default:
455  wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
456  break;
457  }
458  }
459 
460  if( selection.IsHover() )
462  else
464 
465  return 0;
466 }
467 
468 
470 {
471  if( aItem == NULL )
472  return;
473 
474  DIALOG_LIB_EDIT_DRAW_ITEM dlg( m_frame, aItem );
475 
476  if( dlg.ShowModal() != wxID_OK )
477  return;
478 
479  updateItem( aItem, true );
480  m_frame->GetCanvas()->Refresh();
481  m_frame->OnModify();
482 
484  drawingTools->SetDrawSpecificConvert( !dlg.GetApplyToAllConversions() );
485  drawingTools->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
486 
487  MSG_PANEL_ITEMS items;
488  aItem->GetMsgPanelInfo( m_frame, items );
489  m_frame->SetMsgPanel( items );
490 }
491 
492 
494 {
495  if ( ( aItem == NULL ) || ( aItem->Type() != LIB_TEXT_T ) )
496  return;
497 
498  DIALOG_LIB_EDIT_TEXT dlg( m_frame, (LIB_TEXT*) aItem );
499 
500  if( dlg.ShowModal() != wxID_OK )
501  return;
502 
503  updateItem( aItem, true );
504  m_frame->GetCanvas()->Refresh();
505  m_frame->OnModify( );
506 }
507 
508 
510 {
511  if( aField == NULL )
512  return;
513 
514  wxString caption;
515  LIB_SYMBOL* parent = aField->GetParent();
516  wxCHECK( parent, /* void */ );
517 
518  // Editing the symbol value field is equivalent to creating a new symbol based on the
519  // current symbol. Set the dialog message to inform the user.
520  if( aField->GetId() == VALUE_FIELD )
521  caption = _( "Edit Symbol Name" );
522  else
523  caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
524 
525  DIALOG_LIB_EDIT_ONE_FIELD dlg( m_frame, caption, aField );
526 
527  // The dialog may invoke a kiway player for footprint fields
528  // so we must use a quasimodal dialog.
529  if( dlg.ShowQuasiModal() != wxID_OK )
530  return;
531 
532  wxString newFieldValue = LIB_ID::FixIllegalChars( dlg.GetText() );
533  wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
534  bool renamed = aField->GetId() == VALUE_FIELD && newFieldValue != oldFieldValue;
535 
536  if( renamed )
538  else
540 
541  dlg.UpdateField( aField );
542 
543  if( renamed )
544  {
545  parent->SetName( newFieldValue );
546  m_frame->UpdateAfterSymbolProperties( &oldFieldValue );
547  }
548  else
549  {
550  updateItem( aField, true );
551  m_frame->GetCanvas()->Refresh();
552  m_frame->OnModify();
554  }
555 }
556 
557 
559 {
560  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
561  bool partLocked = symbol->UnitsLocked();
562  wxString oldName = symbol->GetName();
563 
566 
567  DIALOG_LIB_SYMBOL_PROPERTIES dlg( m_frame, symbol );
568 
569  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
570  // frame. Therefore this dialog as a modal frame parent, MUST be run under
571  // quasimodal mode for the quasimodal frame support to work. So don't use
572  // the QUASIMODAL macros here.
573  if( dlg.ShowQuasiModal() != wxID_OK )
574  return;
575 
576  m_frame->OnModify();
577 
578  // if m_UnitSelectionLocked has changed, set some edit options or defaults
579  // to the best value
580  if( partLocked != symbol->UnitsLocked() )
581  {
583 
584  // Enable synchronized pin edit mode for symbols with interchangeable units
585  m_frame->m_SyncPinEdit = !symbol->UnitsLocked();
586 
587  // also set default edit options to the better value
588  // Usually if units are locked, graphic items are specific to each unit
589  // and if units are interchangeable, graphic items are common to units
590  tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
591  }
592 }
593 
594 
596 {
597  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
598 
599  if( !symbol )
600  return 0;
601 
603 
605 
606  DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol );
607 
608  if( dlg.ShowModal() == wxID_CANCEL )
609  return -1;
610 
611  m_frame->RebuildView();
612  m_frame->OnModify();
613 
614  return 0;
615 }
616 
617 
619 {
620  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
621 
622  if( !symbol )
623  return 0;
624 
625  if( !symbol->IsAlias() )
626  {
627  m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
628  }
629  else
630  {
631  DIALOG_UPDATE_SYMBOL_FIELDS dlg( m_frame, symbol );
632 
633  if( dlg.ShowModal() == wxID_CANCEL )
634  return -1;
635  }
636 
637  return 0;
638 }
639 
640 
642 {
644 
646  selTool->RebuildSelection();
647 
648  return 0;
649 }
650 
651 
653 {
655 
657  selTool->RebuildSelection();
658 
659  return 0;
660 }
661 
662 
664 {
665  int retVal = Copy( aEvent );
666 
667  if( retVal == 0 )
668  retVal = DoDelete( aEvent );
669 
670  return retVal;
671 }
672 
673 
675 {
676  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
678 
679  if( !symbol || !selection.GetSize() )
680  return 0;
681 
682  for( LIB_ITEM& item : symbol->GetDrawItems() )
683  {
684  if( item.Type() == LIB_FIELD_T )
685  continue;
686 
687  wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
688 
689  if( !item.IsSelected() )
690  item.SetFlags( STRUCT_DELETED );
691  }
692 
693  LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
694 
695  STRING_FORMATTER formatter;
696  SCH_SEXPR_PLUGIN::FormatLibSymbol( partCopy, formatter );
697 
698  delete partCopy;
699 
700  for( LIB_ITEM& item : symbol->GetDrawItems() )
701  item.ClearFlags( STRUCT_DELETED );
702 
703  if( m_toolMgr->SaveClipboard( formatter.GetString() ) )
704  return 0;
705  else
706  return -1;
707 }
708 
709 
711 {
712  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
713 
714  if( !symbol || symbol->IsAlias() )
715  return 0;
716 
717  std::string text_utf8 = m_toolMgr->GetClipboardUTF8();
718  STRING_LINE_READER reader( text_utf8, "Clipboard" );
719  LIB_SYMBOL* newPart;
720 
721  try
722  {
723  newPart = SCH_SEXPR_PLUGIN::ParseLibSymbol( reader );
724  }
725  catch( IO_ERROR& )
726  {
727  // If it's not a symbol then paste as text
728  newPart = new LIB_SYMBOL( "dummy_part" );
729  LIB_TEXT* newText = new LIB_TEXT( newPart );
730  newText->SetText( wxString::FromUTF8( text_utf8.c_str() ) );
731  newPart->AddDrawItem( newText );
732  }
733 
734  if( !newPart )
735  return -1;
736 
737  m_frame->SaveCopyInUndoList( symbol );
739 
740  for( LIB_ITEM& item : symbol->GetDrawItems() )
741  item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
742 
743  for( LIB_ITEM& item : newPart->GetDrawItems() )
744  {
745  if( item.Type() == LIB_FIELD_T )
746  continue;
747 
748  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
749  newItem->SetParent( symbol );
750  newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
751 
752  newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
753  newItem->SetConvert( newItem->GetConvert() ? m_frame->GetConvert() : 0 );
754 
755  symbol->AddDrawItem( newItem );
756  getView()->Add( newItem );
757  }
758 
759  delete newPart;
760 
762 
763  EE_SELECTION& selection = m_selectionTool->GetSelection();
764 
765  if( !selection.Empty() )
766  {
767  selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
769  }
770 
771  return 0;
772 }
773 
774 
776 {
777  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
779 
780  if( selection.GetSize() == 0 )
781  return 0;
782 
783  // Doing a duplicate of a new object doesn't really make any sense; we'd just end
784  // up dragging around a stack of objects...
785  if( selection.Front()->IsNew() )
786  return 0;
787 
788  if( !selection.Front()->IsMoving() )
790 
791  EDA_ITEMS newItems;
792 
793  for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
794  {
795  LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
796  LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
797  oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
798  newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
799  newItem->SetParent( symbol );
800  newItems.push_back( newItem );
801 
802  symbol->AddDrawItem( newItem );
803  getView()->Add( newItem );
804  }
805 
807  m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &newItems );
808 
809  selection.SetReferencePoint( mapCoords( getViewControls()->GetCursorPosition( true ) ) );
811 
812  return 0;
813 }
814 
815 
817 {
824 
831 
836 }
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
static TOOL_ACTION pinTable
Definition: ee_actions.h:142
static TOOL_ACTION properties
Definition: ee_actions.h:117
void editGraphicProperties(LIB_ITEM *aItem)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
static UTF8 FixIllegalChars(const UTF8 &aLibItemName, bool aLib=false)
Replace illegal LIB_ID item name characters with underscores '_'.
Definition: lib_id.cpp:347
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false)
Mark an item for refresh.
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:70
int UpdateSymbolFields(const TOOL_EVENT &aEvent)
bool IsHover() const
Definition: selection.h:73
void editSymbolProperties()
Set up handlers for various events.
#define IS_NEW
New item, just created.
static TOOL_ACTION doDelete
Definition: actions.h:72
wxString GetName() const override
Definition: lib_symbol.h:133
Define a symbol library graphical text item.
Definition: lib_text.h:39
int Copy(const TOOL_EVENT &aEvent)
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:60
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
void editFieldProperties(LIB_FIELD *aField)
bool IsMoving() const
Definition: eda_item.h:120
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:46
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
Field object used in symbol libraries.
Definition: lib_field.h:59
bool IsAlias() const
Definition: lib_symbol.h:172
void UpdateField(LIB_FIELD *aField)
static TOOL_ACTION cancelInteractive
Definition: actions.h:62
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
TOOL_MENU & GetToolMenu()
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
EE_COLLECTOR.
Definition: ee_collectors.h:42
bool Selectable(const EDA_ITEM *aItem, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
wxPoint GetNearestHalfGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize / 2 location to aPosition.
virtual void MirrorHorizontal(const wxPoint &aCenter)=0
Mirror the draw object along the horizontal (X) axis about aCenter point.
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
int GetId() const
Definition: lib_field.h:115
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:629
static TOOL_ACTION mirrorH
Definition: ee_actions.h:116
wxPoint GetNearestGridPosition(const wxPoint &aPosition) const
Return the nearest aGridSize location to aPosition.
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
static TOOL_ACTION updateSymbolFields
Definition: ee_actions.h:177
Define a library symbol object.
Definition: lib_symbol.h:96
static bool IdleSelection(const SELECTION &aSelection)
Test if all selected items are not being edited.
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
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).
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:204
static KICAD_T nonFields[]
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: lib_field.cpp:363
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:83
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
static TOOL_ACTION mirrorV
Definition: ee_actions.h:115
static TOOL_ACTION rotateCW
Definition: ee_actions.h:113
bool IsNew() const
Definition: eda_item.h:119
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
static TOOL_ACTION pickerTool
Definition: actions.h:155
void UpdateAfterSymbolProperties(wxString *aOldName=nullptr)
bool Init() override
Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:66
EE_SELECTION & GetSelection()
Return the set of currently selected items.
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 TOOL_ACTION copy
Definition: actions.h:67
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:186
int GetUnit() const
Definition: lib_item.h:259
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:114
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void BrightenItem(EDA_ITEM *aItem)
Handle editing a single symbol field in the library editor.
static LIB_SYMBOL * ParseLibSymbol(LINE_READER &aReader, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
void DisplaySymbolDatasheet()
Display the documentation of the selected symbol.
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
Field Value of part, i.e. "3.3K".
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:114
int Redo(const TOOL_EVENT &aEvent)
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
#define NULL
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void saveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aType, bool aAppend=false)
Definition: ee_tool_base.h:134
Dialog to update or change schematic library symbols.
wxString TitleCaps(const wxString &aString)
Capitalize the first letter in each word.
Definition: string.cpp:279
std::string GetClipboardUTF8() const
Return the information currently stored in the system clipboard.
int ShowQuasiModal()
int Properties(const TOOL_EVENT &aEvent)
virtual void SetName(const wxString &aName)
Definition: lib_symbol.cpp:314
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:141
int GetUnitCount() const override
For items with units, return the number of units.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void SaveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aUndoType=UNDO_REDO::LIBEDIT, bool aAppend=false)
Create a copy of the current symbol, and save it in the undo list.
wxString GetClass() const override
Return the class name.
Definition: lib_field.h:72
Generic, UI-independent tool event.
Definition: tool_event.h:152
virtual void Rotate(const wxPoint &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:82
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:108
static TOOL_ACTION cut
Definition: actions.h:66
#define STRUCT_DELETED
flag indication structures to be erased
#define _(s)
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:154
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:177
#define SELECTED
void AddDrawItem(LIB_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:655
const std::string & GetString()
Definition: richio.h:438
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:43
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition: tool_event.h:357
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:507
virtual void MirrorVertical(const wxPoint &aCenter)=0
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:53
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:158
bool CollectHits(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Select one or more items at the location given by parameter aWhere.
static VECTOR2D mapCoords(const wxPoint &aCoord)
const wxString & GetText() const
int GetConvert() const
Definition: lib_item.h:262
int DeleteItemCursor(const TOOL_EVENT &aEvent)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:473
void UnbrightenItem(EDA_ITEM *aItem)
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Display basic info (type, part and convert) about the current item in message panel.
Definition: lib_item.cpp:50
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
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:97
int Mirror(const TOOL_EVENT &aEvent)
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:241
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:62
void updateItem(EDA_ITEM *aItem, bool aUpdateRTree) const
Similar to getView()->Update(), but handles items that are redrawn by their parents and updating the ...
Definition: ee_tool_base.h:103
int Duplicate(const TOOL_EVENT &aEvent)
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
void SetConvert(int aConvert)
Definition: lib_item.h:261
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
Dialog to edit library component graphic items.
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:146
void SetUnit(int aUnit)
Definition: lib_item.h:258
static TOOL_ACTION redo
Definition: actions.h:65
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
int AddItemToSel(const TOOL_EVENT &aEvent)
const char * name
Definition: DXF_plotter.cpp:59
int PinTable(const TOOL_EVENT &aEvent)
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:35
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:52
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
bool Init() override
Init() is called once upon a registration of the tool.
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:295
int Size() const
Returns the number of selected parts.
Definition: selection.h:103
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
int Rotate(const TOOL_EVENT &aEvent)
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
void Activate()
Run the tool.
void editTextProperties(LIB_ITEM *aItem)
static TOOL_ACTION deleteTool
Definition: actions.h:73
static TOOL_ACTION move
Definition: ee_actions.h:110
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:49
int Paste(const TOOL_EVENT &aEvent)
static TOOL_ACTION undo
Definition: actions.h:64
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:322
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
int Undo(const TOOL_EVENT &aEvent)
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
Definition: lib_symbol.h:372
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:240
bool EditPinProperties(LIB_PIN *aPin)
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:414
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
static TOOL_ACTION selectAll
Definition: actions.h:70
static TOOL_ACTION paste
Definition: actions.h:68
static TOOL_ACTION duplicate
Definition: actions.h:71
int Cut(const TOOL_EVENT &aEvent)
static TOOL_ACTION refreshPreview
Definition: actions.h:106
EDA_ITEM * Front() const
Definition: selection.h:144
SYMBOL_EDITOR_DRAWING_TOOLS.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
int DoDelete(const TOOL_EVENT &aEvent)
Delete the selected items, or the item under the cursor.
The symbol library editor main window.