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 <string_utils.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, wxT( "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->GetNearestHalfGridPosition( 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, false, true );
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, false, true );
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_SHAPE_T,
244  LIB_TEXT_T,
245  LIB_PIN_T,
246  EOT
247 };
248 
249 
251 {
252  LIB_SYMBOL *symbol = m_frame->GetCurSymbol();
253  std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection( nonFields ).GetItems();
254 
255  if( items.empty() )
256  return 0;
257 
258  // Don't leave a freed pointer in the selection
260 
262 
263  std::set<LIB_ITEM *> toDelete;
264 
265  for( EDA_ITEM* item : items )
266  {
267  if( item->Type() == LIB_PIN_T )
268  {
269  LIB_PIN* pin = static_cast<LIB_PIN*>( item );
270  wxPoint pos = pin->GetPosition();
271 
272  toDelete.insert( pin );
273 
274  // when pin editing is synchronized, pins in the same position, with the same name
275  // in different units are also removed. But only one pin per unit (matching)
276  if( m_frame->SynchronizePins() )
277  {
278  std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
279 
280  got_unit[pin->GetUnit()] = true;
281 
282  int curr_convert = pin->GetConvert();
283  ELECTRICAL_PINTYPE etype = pin->GetType();
284  wxString name = pin->GetName();
285  LIB_PIN* next_pin = symbol->GetNextPin();
286 
287  while( next_pin != nullptr )
288  {
289  pin = next_pin;
290  next_pin = symbol->GetNextPin( pin );
291 
292  if( got_unit[pin->GetUnit()] )
293  continue;
294 
295  if( pin->GetPosition() != pos )
296  continue;
297 
298  if( pin->GetConvert() != curr_convert )
299  continue;
300 
301  if( pin->GetType() != etype )
302  continue;
303 
304  if( pin->GetName() != name )
305  continue;
306 
307  toDelete.insert( pin );
308  got_unit[pin->GetUnit()] = true;
309  }
310  }
311  }
312  else
313  {
314  toDelete.insert( (LIB_ITEM*) item );
315  }
316  }
317 
318  for( LIB_ITEM* item : toDelete )
319  symbol->RemoveDrawItem( item );
320 
321  m_frame->RebuildView();
322  m_frame->OnModify();
323 
324  return 0;
325 }
326 
327 
328 #define HITTEST_THRESHOLD_PIXELS 5
329 
330 
332 {
333  std::string tool = aEvent.GetCommandStr().get();
335 
337  m_pickerItem = nullptr;
338 
339  // Deactivate other tools; particularly important if another PICKER is currently running
340  Activate();
341 
342  picker->SetCursor( KICURSOR::REMOVE );
343 
344  picker->SetClickHandler(
345  [this]( const VECTOR2D& aPosition ) -> bool
346  {
347  if( m_pickerItem )
348  {
350  selectionTool->UnbrightenItem( m_pickerItem );
351  selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
353  m_pickerItem = nullptr;
354  }
355 
356  return true;
357  } );
358 
359  picker->SetMotionHandler(
360  [this]( const VECTOR2D& aPos )
361  {
363  EE_COLLECTOR collector;
364 
365  selectionTool->CollectHits( collector, aPos, nonFields );
366 
367  // Remove unselectable items
368  for( int i = collector.GetCount() - 1; i >= 0; --i )
369  {
370  if( !selectionTool->Selectable( collector[ i ] ) )
371  collector.Remove( i );
372  }
373 
374  if( collector.GetCount() > 1 )
375  selectionTool->GuessSelectionCandidates( collector, aPos );
376 
377  EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
378 
379  if( m_pickerItem != item )
380  {
381  if( m_pickerItem )
382  selectionTool->UnbrightenItem( m_pickerItem );
383 
384  m_pickerItem = item;
385 
386  if( m_pickerItem )
387  selectionTool->BrightenItem( m_pickerItem );
388  }
389  } );
390 
391  picker->SetFinalizeHandler(
392  [this]( const int& aFinalState )
393  {
394  if( m_pickerItem )
396 
397  // Wake the selection tool after exiting to ensure the cursor gets updated
399  } );
400 
401  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
402 
403  return 0;
404 }
405 
406 
408 {
410 
411  if( selection.Empty() || aEvent.IsAction( &EE_ACTIONS::symbolProperties ) )
412  {
413  if( m_frame->GetCurSymbol() )
415  }
416  else if( selection.Size() == 1 )
417  {
418  LIB_ITEM* item = (LIB_ITEM*) selection.Front();
419 
420  // Save copy for undo if not in edit (edit command already handle the save copy)
421  if( item->GetEditFlags() == 0 )
423 
424  switch( item->Type() )
425  {
426  case LIB_PIN_T:
427  {
429 
430  if( pinTool )
431  pinTool->EditPinProperties( (LIB_PIN*) item );
432  }
433  break;
434 
435  case LIB_SHAPE_T:
436  editShapeProperties( item );
437  break;
438 
439  case LIB_TEXT_T:
440  editTextProperties( item );
441  break;
442 
443  case LIB_FIELD_T:
444  editFieldProperties( (LIB_FIELD*) item );
445  break;
446 
447  default:
448  wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
449  break;
450  }
451  }
452 
453  if( selection.IsHover() )
455  else
457 
458  return 0;
459 }
460 
461 
463 {
464  DIALOG_LIB_SHAPE_PROPERTIES dlg( m_frame, aItem );
465 
466  if( dlg.ShowModal() != wxID_OK )
467  return;
468 
469  updateItem( aItem, true );
470  m_frame->GetCanvas()->Refresh();
471  m_frame->OnModify();
472 
474  drawingTools->SetDrawSpecificConvert( !dlg.GetApplyToAllConversions() );
475  drawingTools->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
476 
477  std::vector<MSG_PANEL_ITEM> items;
478  aItem->GetMsgPanelInfo( m_frame, items );
479  m_frame->SetMsgPanel( items );
480 }
481 
482 
484 {
485  if ( aItem->Type() != LIB_TEXT_T )
486  return;
487 
489 
490  if( dlg.ShowModal() != wxID_OK )
491  return;
492 
493  updateItem( aItem, true );
494  m_frame->GetCanvas()->Refresh();
495  m_frame->OnModify( );
496 }
497 
498 
500 {
501  if( aField == nullptr )
502  return;
503 
504  wxString caption;
505  LIB_SYMBOL* parent = aField->GetParent();
506  wxCHECK( parent, /* void */ );
507 
508  // Editing the symbol value field is equivalent to creating a new symbol based on the
509  // current symbol. Set the dialog message to inform the user.
510  if( aField->GetId() == VALUE_FIELD )
511  caption = _( "Edit Symbol Name" );
512  else if( aField->GetId() < MANDATORY_FIELDS )
513  caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
514  else
515  caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
516 
517  DIALOG_LIB_FIELD_PROPERTIES dlg( m_frame, caption, aField );
518 
519  // The dialog may invoke a kiway player for footprint fields
520  // so we must use a quasimodal dialog.
521  if( dlg.ShowQuasiModal() != wxID_OK )
522  return;
523 
524  wxString newFieldValue = EscapeString( dlg.GetText(), CTX_LIBID );
525  wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
526  bool renamed = aField->GetId() == VALUE_FIELD && newFieldValue != oldFieldValue;
527 
528  if( renamed )
530  else
532 
533  dlg.UpdateField( aField );
534 
535  if( renamed )
536  {
537  parent->SetName( newFieldValue );
538  m_frame->UpdateAfterSymbolProperties( &oldFieldValue );
539  }
540  else
541  {
542  updateItem( aField, true );
543  m_frame->GetCanvas()->Refresh();
544  m_frame->OnModify();
546  }
547 }
548 
549 
551 {
552  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
553  bool partLocked = symbol->UnitsLocked();
554 
557 
558  DIALOG_LIB_SYMBOL_PROPERTIES dlg( m_frame, symbol );
559 
560  // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
561  // frame. Therefore this dialog as a modal frame parent, MUST be run under
562  // quasimodal mode for the quasimodal frame support to work. So don't use
563  // the QUASIMODAL macros here.
564  if( dlg.ShowQuasiModal() != wxID_OK )
565  return;
566 
567  m_frame->OnModify();
568 
569  // if m_UnitSelectionLocked has changed, set some edit options or defaults
570  // to the best value
571  if( partLocked != symbol->UnitsLocked() )
572  {
574 
575  // Enable synchronized pin edit mode for symbols with interchangeable units
576  m_frame->m_SyncPinEdit = !symbol->UnitsLocked();
577 
578  // also set default edit options to the better value
579  // Usually if units are locked, graphic items are specific to each unit
580  // and if units are interchangeable, graphic items are common to units
581  tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
582  }
583 }
584 
585 
587 {
588  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
589 
590  if( !symbol )
591  return 0;
592 
594 
596 
597  DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol );
598 
599  if( dlg.ShowModal() == wxID_CANCEL )
600  return -1;
601 
602  m_frame->RebuildView();
603  m_frame->OnModify();
604 
605  return 0;
606 }
607 
608 
610 {
611  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
612 
613  if( !symbol )
614  return 0;
615 
616  if( !symbol->IsAlias() )
617  {
618  m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
619  }
620  else
621  {
622  DIALOG_UPDATE_SYMBOL_FIELDS dlg( m_frame, symbol );
623 
624  if( dlg.ShowModal() == wxID_CANCEL )
625  return -1;
626  }
627 
628  return 0;
629 }
630 
631 
633 {
635 
637  selTool->RebuildSelection();
638 
639  return 0;
640 }
641 
642 
644 {
646 
648  selTool->RebuildSelection();
649 
650  return 0;
651 }
652 
653 
655 {
656  int retVal = Copy( aEvent );
657 
658  if( retVal == 0 )
659  retVal = DoDelete( aEvent );
660 
661  return retVal;
662 }
663 
664 
666 {
667  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
669 
670  if( !symbol || !selection.GetSize() )
671  return 0;
672 
673  for( LIB_ITEM& item : symbol->GetDrawItems() )
674  {
675  if( item.Type() == LIB_FIELD_T )
676  continue;
677 
678  wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
679 
680  if( !item.IsSelected() )
681  item.SetFlags( STRUCT_DELETED );
682  }
683 
684  LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
685 
686  STRING_FORMATTER formatter;
687  SCH_SEXPR_PLUGIN::FormatLibSymbol( partCopy, formatter );
688 
689  delete partCopy;
690 
691  for( LIB_ITEM& item : symbol->GetDrawItems() )
692  item.ClearFlags( STRUCT_DELETED );
693 
694  if( m_toolMgr->SaveClipboard( formatter.GetString() ) )
695  return 0;
696  else
697  return -1;
698 }
699 
700 
702 {
703  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
704 
705  if( !symbol || symbol->IsAlias() )
706  return 0;
707 
708  std::string text_utf8 = m_toolMgr->GetClipboardUTF8();
709  STRING_LINE_READER reader( text_utf8, wxT( "Clipboard" ) );
710  LIB_SYMBOL* newPart;
711 
712  try
713  {
714  newPart = SCH_SEXPR_PLUGIN::ParseLibSymbol( reader );
715  }
716  catch( IO_ERROR& )
717  {
718  // If it's not a symbol then paste as text
719  newPart = new LIB_SYMBOL( wxT( "dummy_part" ) );
720  LIB_TEXT* newText = new LIB_TEXT( newPart );
721  newText->SetText( wxString::FromUTF8( text_utf8.c_str() ) );
722  newPart->AddDrawItem( newText );
723  }
724 
725  if( !newPart )
726  return -1;
727 
728  m_frame->SaveCopyInUndoList( symbol );
730 
731  for( LIB_ITEM& item : symbol->GetDrawItems() )
732  item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
733 
734  for( LIB_ITEM& item : newPart->GetDrawItems() )
735  {
736  if( item.Type() == LIB_FIELD_T )
737  continue;
738 
739  LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
740  newItem->SetParent( symbol );
741  newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
742 
743  newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
744  newItem->SetConvert( newItem->GetConvert() ? m_frame->GetConvert() : 0 );
745 
746  symbol->AddDrawItem( newItem );
747  getView()->Add( newItem );
748  }
749 
750  delete newPart;
751 
753 
754  EE_SELECTION& selection = m_selectionTool->GetSelection();
755 
756  if( !selection.Empty() )
757  {
758  selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
760  }
761 
762  return 0;
763 }
764 
765 
767 {
768  LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
770 
771  if( selection.GetSize() == 0 )
772  return 0;
773 
774  // Doing a duplicate of a new object doesn't really make any sense; we'd just end
775  // up dragging around a stack of objects...
776  if( selection.Front()->IsNew() )
777  return 0;
778 
779  if( !selection.Front()->IsMoving() )
781 
782  EDA_ITEMS newItems;
783 
784  for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
785  {
786  LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
787  LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
788  oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
789  newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
790  newItem->SetParent( symbol );
791  newItems.push_back( newItem );
792 
793  symbol->AddDrawItem( newItem );
794  getView()->Add( newItem );
795  }
796 
798  m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &newItems );
799 
800  selection.SetReferencePoint( mapCoords( getViewControls()->GetCursorPosition( true ) ) );
802 
803  return 0;
804 }
805 
806 
808 {
815 
822 
827 }
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:146
static TOOL_ACTION properties
Definition: ee_actions.h:121
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:71
int UpdateSymbolFields(const TOOL_EVENT &aEvent)
bool IsHover() const
Definition: selection.h:74
void editSymbolProperties()
Set up handlers for various events.
#define IS_NEW
New item, just created.
static TOOL_ACTION doDelete
Definition: actions.h:72
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:63
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:119
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:46
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
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
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:152
TOOL_MENU & GetToolMenu()
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
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:251
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:690
static TOOL_ACTION mirrorH
Definition: ee_actions.h:120
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.
Dialog to edit library component graphic items.
static TOOL_ACTION updateSymbolFields
Definition: ee_actions.h:182
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:205
static KICAD_T nonFields[]
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:115
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
wxString GetName(bool aUseDefaultName=true) const
Return the field name.
Definition: lib_field.cpp:393
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:119
static TOOL_ACTION rotateCW
Definition: ee_actions.h:117
bool IsNew() const
Definition: eda_item.h:118
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...
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
static TOOL_ACTION copy
Definition: actions.h:67
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:192
int GetUnit() const
Definition: lib_item.h:266
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:118
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void BrightenItem(EDA_ITEM *aItem)
static LIB_SYMBOL * ParseLibSymbol(LINE_READER &aReader, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
#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:124
int Redo(const TOOL_EVENT &aEvent)
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
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.
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:362
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:145
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
void UpdateField(LIB_FIELD *aField)
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:109
static TOOL_ACTION cut
Definition: actions.h:66
#define STRUCT_DELETED
flag indication structures to be erased
#define _(s)
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false)
Mark an item for refresh.
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:153
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:179
#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:716
const std::string & GetString()
Definition: richio.h:438
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition: tool_event.h:362
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:506
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:56
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:157
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.
void editShapeProperties(LIB_ITEM *aItem)
static VECTOR2D mapCoords(const wxPoint &aCoord)
int GetConvert() const
Definition: lib_item.h:269
int DeleteItemCursor(const TOOL_EVENT &aEvent)
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:484
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:43
void UpdateSymbolMsgPanelInfo()
Display the documentation of the selected symbol.
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
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:268
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:88
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:164
void SetUnit(int aUnit)
Definition: lib_item.h:265
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:56
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:53
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.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:325
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
const wxString & GetText() const
int Rotate(const TOOL_EVENT &aEvent)
void Activate()
Run the tool.
LIB_PIN * GetNextPin(LIB_PIN *aItem=nullptr)
Return the next pin object from the draw list.
Definition: lib_symbol.h:383
void editTextProperties(LIB_ITEM *aItem)
static TOOL_ACTION deleteTool
Definition: actions.h:73
static TOOL_ACTION move
Definition: ee_actions.h:114
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:320
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
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)
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
Handle editing a single symbol field in the symbol editor.
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:145
SYMBOL_EDITOR_DRAWING_TOOLS.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
int DoDelete(const TOOL_EVENT &aEvent)
Delete the selected items, or the item under the cursor.
The symbol library editor main window.