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>
44#include "lib_textbox.h"
45#include <wx/textdlg.h> // for wxTextEntryDialog
46#include <math/util.h> // for KiROUND
47
49 EE_TOOL_BASE( "eeschema.SymbolEditTool" ),
50 m_pickerItem( nullptr )
51{
52}
53
54
56{
58
61
62 wxASSERT_MSG( drawingTools, "eeschema.SymbolDrawing tool is not available" );
63
64 auto haveSymbolCondition =
65 [&]( const SELECTION& sel )
66 {
67 return m_isSymbolEditor &&
68 static_cast<SYMBOL_EDIT_FRAME*>( m_frame )->GetCurSymbol();
69 };
70
71 auto canEdit =
72 [&]( const SELECTION& sel )
73 {
75 wxCHECK( editor, false );
76
77 if( !editor->IsSymbolEditable() )
78 return false;
79
80 if( editor->IsSymbolAlias() )
81 {
82 for( EDA_ITEM* item : sel )
83 {
84 if( item->Type() != LIB_FIELD_T )
85 return false;
86 }
87 }
88
89 return true;
90 };
91
92 // Add edit actions to the move tool menu
93 if( moveTool )
94 {
95 CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
96
97 moveMenu.AddSeparator( 200 );
98 moveMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
99 moveMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
100 moveMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
101 moveMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
102
103 moveMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
104
105 moveMenu.AddSeparator( 300 );
108 moveMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
109 moveMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 200 );
110
111 moveMenu.AddSeparator( 400 );
112 moveMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
113 }
114
115 // Add editing actions to the drawing tool menu
116 CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
117
118 drawMenu.AddSeparator( 200 );
120 drawMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::IdleSelection, 200 );
121 drawMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::IdleSelection, 200 );
122 drawMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::IdleSelection, 200 );
123
124 drawMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
125
126 // Add editing actions to the selection tool menu
128
129 selToolMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
130 selToolMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
131 selToolMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
132 selToolMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
133
134 selToolMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
135
136 selToolMenu.AddSeparator( 300 );
139 selToolMenu.AddItem( ACTIONS::paste, canEdit && EE_CONDITIONS::Idle, 300 );
140 selToolMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
141 selToolMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 300 );
142
143 selToolMenu.AddSeparator( 400 );
144 selToolMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
145
146 return true;
147}
148
149
151{
153
154 if( selection.GetSize() == 0 )
155 return 0;
156
157 VECTOR2I rotPoint;
158 bool ccw = ( aEvent.Matches( EE_ACTIONS::rotateCCW.MakeEvent() ) );
159 LIB_ITEM* item = static_cast<LIB_ITEM*>( selection.Front() );
160
161 if( !item->IsMoving() )
163
164 if( selection.GetSize() == 1 )
165 rotPoint = item->GetPosition();
166 else
167 rotPoint = m_frame->GetNearestHalfGridPosition( mapCoords( selection.GetCenter() ) );
168
169 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
170 {
171 item = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
172 item->Rotate( rotPoint, ccw );
173 m_frame->UpdateItem( item, false, true );
174 }
175
176 if( item->IsMoving() )
177 {
179 }
180 else
181 {
183
184 if( selection.IsHover() )
186
187 m_frame->OnModify();
188 }
189
190 return 0;
191}
192
193
195{
197
198 if( selection.GetSize() == 0 )
199 return 0;
200
201 VECTOR2I mirrorPoint;
202 bool xAxis = ( aEvent.Matches( EE_ACTIONS::mirrorV.MakeEvent() ) );
203 LIB_ITEM* item = static_cast<LIB_ITEM*>( selection.Front() );
204
205 if( !item->IsMoving() )
207
208 if( selection.GetSize() == 1 )
209 mirrorPoint = item->GetPosition();
210 else
211 mirrorPoint = m_frame->GetNearestHalfGridPosition( mapCoords( selection.GetCenter() ) );
212
213 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
214 {
215 item = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
216
217 if( xAxis )
218 item->MirrorVertical( mirrorPoint );
219 else
220 item->MirrorHorizontal( mirrorPoint );
221
222 m_frame->UpdateItem( item, false, true );
223 }
224
226
227 if( item->IsMoving() )
228 {
230 }
231 else
232 {
233 if( selection.IsHover() )
235
236 m_frame->OnModify();
237 }
238
239 return 0;
240}
241
242
243static std::vector<KICAD_T> nonFields =
244{
250};
251
252
254{
255 LIB_SYMBOL *symbol = m_frame->GetCurSymbol();
256 std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection( nonFields ).GetItems();
257
258 if( items.empty() )
259 return 0;
260
261 // Don't leave a freed pointer in the selection
263
265
266 std::set<LIB_ITEM *> toDelete;
267
268 for( EDA_ITEM* item : items )
269 {
270 if( item->Type() == LIB_PIN_T )
271 {
272 LIB_PIN* pin = static_cast<LIB_PIN*>( item );
273 VECTOR2I pos = pin->GetPosition();
274
275 toDelete.insert( pin );
276
277 // when pin editing is synchronized, pins in the same position, with the same name
278 // in different units are also removed. But only one pin per unit (matching)
279 if( m_frame->SynchronizePins() )
280 {
281 std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
282
283 got_unit[pin->GetUnit()] = true;
284
285 int curr_convert = pin->GetConvert();
286 ELECTRICAL_PINTYPE etype = pin->GetType();
287 wxString name = pin->GetName();
288 LIB_PIN* next_pin = symbol->GetNextPin();
289
290 while( next_pin != nullptr )
291 {
292 pin = next_pin;
293 next_pin = symbol->GetNextPin( pin );
294
295 if( got_unit[pin->GetUnit()] )
296 continue;
297
298 if( pin->GetPosition() != pos )
299 continue;
300
301 if( pin->GetConvert() != curr_convert )
302 continue;
303
304 if( pin->GetType() != etype )
305 continue;
306
307 if( pin->GetName() != name )
308 continue;
309
310 toDelete.insert( pin );
311 got_unit[pin->GetUnit()] = true;
312 }
313 }
314 }
315 else
316 {
317 toDelete.insert( (LIB_ITEM*) item );
318 }
319 }
320
321 for( LIB_ITEM* item : toDelete )
322 symbol->RemoveDrawItem( item );
323
325 m_frame->OnModify();
326
327 return 0;
328}
329
330
331#define HITTEST_THRESHOLD_PIXELS 5
332
333
335{
337
339 m_pickerItem = nullptr;
340
341 // Deactivate other tools; particularly important if another PICKER is currently running
342 Activate();
343
344 picker->SetCursor( KICURSOR::REMOVE );
345
346 picker->SetClickHandler(
347 [this]( const VECTOR2D& aPosition ) -> bool
348 {
349 if( m_pickerItem )
350 {
352 selectionTool->UnbrightenItem( m_pickerItem );
353 selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
355 m_pickerItem = nullptr;
356 }
357
358 return true;
359 } );
360
361 picker->SetMotionHandler(
362 [this]( const VECTOR2D& aPos )
363 {
365 EE_COLLECTOR collector;
366
367 selectionTool->CollectHits( collector, aPos, nonFields );
368
369 // Remove unselectable items
370 for( int i = collector.GetCount() - 1; i >= 0; --i )
371 {
372 if( !selectionTool->Selectable( collector[ i ] ) )
373 collector.Remove( i );
374 }
375
376 if( collector.GetCount() > 1 )
377 selectionTool->GuessSelectionCandidates( collector, aPos );
378
379 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
380
381 if( m_pickerItem != item )
382 {
383 if( m_pickerItem )
384 selectionTool->UnbrightenItem( m_pickerItem );
385
386 m_pickerItem = item;
387
388 if( m_pickerItem )
389 selectionTool->BrightenItem( m_pickerItem );
390 }
391 } );
392
393 picker->SetFinalizeHandler(
394 [this]( const int& aFinalState )
395 {
396 if( m_pickerItem )
397 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
398
399 // Wake the selection tool after exiting to ensure the cursor gets updated
401 } );
402
404
405 return 0;
406}
407
408
410{
412
413 if( selection.Empty() || aEvent.IsAction( &EE_ACTIONS::symbolProperties ) )
414 {
415 if( m_frame->GetCurSymbol() )
417 }
418 else if( selection.Size() == 1 )
419 {
420 LIB_ITEM* item = (LIB_ITEM*) selection.Front();
421
422 // Save copy for undo if not in edit (edit command already handle the save copy)
423 if( item->GetEditFlags() == 0 )
425
426 switch( item->Type() )
427 {
428 case LIB_PIN_T:
429 {
431
432 if( pinTool )
433 pinTool->EditPinProperties( (LIB_PIN*) item );
434 }
435 break;
436
437 case LIB_SHAPE_T:
438 editShapeProperties( static_cast<LIB_SHAPE*>( item ) );
439 break;
440
441 case LIB_TEXT_T:
442 editTextProperties( item );
443 break;
444
445 case LIB_TEXTBOX_T:
446 editTextBoxProperties( item );
447 break;
448
449 case LIB_FIELD_T:
451 break;
452
453 default:
454 wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
455 break;
456 }
457 }
458
459 if( selection.IsHover() )
461 else
463
464 return 0;
465}
466
467
469{
471
472 if( dlg.ShowModal() != wxID_OK )
473 return;
474
475 updateItem( aShape, true );
477 m_frame->OnModify();
478
480 drawingTools->SetDrawSpecificConvert( !dlg.GetApplyToAllConversions() );
481 drawingTools->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
482
483 std::vector<MSG_PANEL_ITEM> items;
484 aShape->GetMsgPanelInfo( m_frame, items );
485 m_frame->SetMsgPanel( items );
486}
487
488
490{
491 if ( aItem->Type() != LIB_TEXT_T )
492 return;
493
494 DIALOG_LIB_TEXT_PROPERTIES dlg( m_frame, static_cast<LIB_TEXT*>( aItem ) );
495
496 if( dlg.ShowModal() != wxID_OK )
497 return;
498
499 updateItem( aItem, true );
501 m_frame->OnModify( );
502}
503
504
506{
507 if ( aItem->Type() != LIB_TEXTBOX_T )
508 return;
509
510 DIALOG_LIB_TEXTBOX_PROPERTIES dlg( m_frame, static_cast<LIB_TEXTBOX*>( aItem ) );
511
512 if( dlg.ShowModal() != wxID_OK )
513 return;
514
515 updateItem( aItem, true );
517 m_frame->OnModify( );
518}
519
520
522{
523 if( aField == nullptr )
524 return;
525
526 wxString caption;
527 LIB_SYMBOL* parent = aField->GetParent();
528 wxCHECK( parent, /* void */ );
529
530 if( aField->GetId() < MANDATORY_FIELDS )
531 caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
532 else
533 caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
534
535 DIALOG_LIB_FIELD_PROPERTIES dlg( m_frame, caption, aField );
536
537 // The dialog may invoke a kiway player for footprint fields
538 // so we must use a quasimodal dialog.
539 if( dlg.ShowQuasiModal() != wxID_OK )
540 return;
541
542 wxString newFieldValue = EscapeString( dlg.GetText(), CTX_LIBID );
543 wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
544
546
547 dlg.UpdateField( aField );
548
549 updateItem( aField, true );
551 m_frame->OnModify();
553}
554
555
557{
558 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
559 bool partLocked = symbol->UnitsLocked();
560
563
565
566 // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
567 // frame. Therefore this dialog as a modal frame parent, MUST be run under
568 // quasimodal mode for the quasimodal frame support to work. So don't use
569 // the QUASIMODAL macros here.
570 if( dlg.ShowQuasiModal() != wxID_OK )
571 return;
572
573 m_frame->OnModify();
574
575 // if m_UnitSelectionLocked has changed, set some edit options or defaults
576 // to the best value
577 if( partLocked != symbol->UnitsLocked() )
578 {
580
581 // Enable synchronized pin edit mode for symbols with interchangeable units
582 m_frame->m_SyncPinEdit = !symbol->UnitsLocked();
583
584 // also set default edit options to the better value
585 // Usually if units are locked, graphic items are specific to each unit
586 // and if units are interchangeable, graphic items are common to units
587 tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
588 }
589}
590
592 int& aSymbolLastPinNumber )
593{
594 if( !aNewPin->GetNumber().IsEmpty() )
595 {
596 // when duplicating a pin in symbol editor, assigning identical pin number
597 // to the old one does not makes any sense, so assign the next unassigned number to it
598 aSymbolLastPinNumber++;
599 aNewPin->SetNumber( wxString::Format( wxT( "%i" ), aSymbolLastPinNumber ) );
600 }
601}
602
604{
605 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
606
607 if( !symbol )
608 return 0;
609
611
613
614 DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol );
615
616 if( dlg.ShowModal() == wxID_CANCEL )
617 return -1;
618
620 m_frame->OnModify();
621
622 return 0;
623}
624
625
627{
628 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
629
630 if( !symbol )
631 return 0;
632
633 if( !symbol->IsAlias() )
634 {
635 m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
636 }
637 else
638 {
640
641 if( dlg.ShowModal() == wxID_CANCEL )
642 return -1;
643 }
644
645 return 0;
646}
647
648
650{
651 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
652
653 if( !symbol )
654 return 0;
655
656 int unitid = m_frame->GetUnit();
657
658 if( unitid == 0 )
659 {
660 return -1;
661 }
662
663 wxString promptText = wxString::Format( _( "Enter display name for unit %s" ),
664 symbol->GetUnitReference( unitid ) );
665 wxString currentvalue;
666
667 if( symbol->HasUnitDisplayName( unitid ) )
668 {
669 currentvalue = symbol->GetUnitDisplayName( unitid );
670 }
671
672 wxTextEntryDialog dlg( m_frame, promptText, _( "Set Unit Display Name" ), currentvalue );
673
674 if( dlg.ShowModal() == wxID_OK )
675 {
677 symbol->SetUnitDisplayName( unitid, dlg.GetValue() );
679 m_frame->OnModify();
680 }
681 else
682 {
683 return -1;
684 }
685
686 return 0;
687}
688
689
691{
693
695 selTool->RebuildSelection();
696
697 return 0;
698}
699
700
702{
704
706 selTool->RebuildSelection();
707
708 return 0;
709}
710
711
713{
714 int retVal = Copy( aEvent );
715
716 if( retVal == 0 )
717 retVal = DoDelete( aEvent );
718
719 return retVal;
720}
721
722
724{
725 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
727
728 if( !symbol || !selection.GetSize() )
729 return 0;
730
731 for( LIB_ITEM& item : symbol->GetDrawItems() )
732 {
733 if( item.Type() == LIB_FIELD_T )
734 continue;
735
736 wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
737
738 if( !item.IsSelected() )
739 item.SetFlags( STRUCT_DELETED );
740 }
741
742 LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
743
744 STRING_FORMATTER formatter;
745 SCH_SEXPR_PLUGIN::FormatLibSymbol( partCopy, formatter );
746
747 delete partCopy;
748
749 for( LIB_ITEM& item : symbol->GetDrawItems() )
751
752 if( m_toolMgr->SaveClipboard( formatter.GetString() ) )
753 return 0;
754 else
755 return -1;
756}
757
758
760{
761 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
762
763 if( !symbol || symbol->IsAlias() )
764 return 0;
765
766 std::string text_utf8 = m_toolMgr->GetClipboardUTF8();
767 STRING_LINE_READER reader( text_utf8, "Clipboard" );
768 LIB_SYMBOL* newPart;
769
770 try
771 {
772 newPart = SCH_SEXPR_PLUGIN::ParseLibSymbol( reader );
773 }
774 catch( IO_ERROR& )
775 {
776 // If it's not a symbol then paste as text
777 newPart = new LIB_SYMBOL( "dummy_part" );
778 LIB_TEXT* newText = new LIB_TEXT( newPart );
779 newText->SetText( wxString::FromUTF8( text_utf8.c_str() ) );
780 newPart->AddDrawItem( newText );
781 }
782
783 if( !newPart )
784 return -1;
785
786 m_frame->SaveCopyInUndoList( symbol );
788
789 for( LIB_ITEM& item : symbol->GetDrawItems() )
790 item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
791
792 for( LIB_ITEM& item : newPart->GetDrawItems() )
793 {
794 if( item.Type() == LIB_FIELD_T )
795 continue;
796
797 LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
798 newItem->SetParent( symbol );
799 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
800
801 newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
802 newItem->SetConvert( newItem->GetConvert() ? m_frame->GetConvert() : 0 );
803
804 symbol->AddDrawItem( newItem );
805 getView()->Add( newItem );
806 }
807
808 delete newPart;
809
811
813
814 if( !selection.Empty() )
815 {
816 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
818 }
819
820 return 0;
821}
822
823
825{
826 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
828
829 if( selection.GetSize() == 0 )
830 return 0;
831
832 // Doing a duplicate of a new object doesn't really make any sense; we'd just end
833 // up dragging around a stack of objects...
834 if( selection.Front()->IsNew() )
835 return 0;
836
837 if( !selection.Front()->IsMoving() )
839
840 EDA_ITEMS newItems;
841 int symbolLastPinNumber = -1;
842
843 for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
844 {
845 LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
846 LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
847
848 if( oldItem->Type() == LIB_PIN_T )
849 {
850 if( symbolLastPinNumber == -1 )
851 {
852 symbolLastPinNumber = symbol->GetMaxPinNumber();
853 }
854
855 handlePinDuplication( static_cast<LIB_PIN*>( oldItem ),
856 static_cast<LIB_PIN*>( newItem ), symbolLastPinNumber );
857 }
858
859 oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
860 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
861 newItem->SetParent( symbol );
862 newItems.push_back( newItem );
863
864 symbol->AddDrawItem( newItem );
865 getView()->Add( newItem );
866 }
867
869 m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &newItems );
870
871 selection.SetReferencePoint( mapCoords( getViewControls()->GetCursorPosition( true ) ) );
873
874 return 0;
875}
876
877
879{
886
893
899}
const char * name
Definition: DXF_plotter.cpp:56
VECTOR2D mapCoords(const VECTOR2D &aSource)
Definition: PS_plotter.cpp:568
static TOOL_ACTION paste
Definition: actions.h:69
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION copy
Definition: actions.h:68
static TOOL_ACTION pickerTool
Definition: actions.h:158
static TOOL_ACTION undo
Definition: actions.h:65
static TOOL_ACTION duplicate
Definition: actions.h:72
static TOOL_ACTION doDelete
Definition: actions.h:73
static TOOL_ACTION redo
Definition: actions.h:66
static TOOL_ACTION deleteTool
Definition: actions.h:74
static TOOL_ACTION cut
Definition: actions.h:67
static TOOL_ACTION refreshPreview
Definition: actions.h:109
static TOOL_ACTION selectAll
Definition: actions.h:71
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.
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
const wxString & GetText() const
Handle editing a single symbol field in the symbol editor.
Dialog to edit library component graphic items.
int ShowQuasiModal()
Dialog to update or change schematic library symbols.
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...
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
VECTOR2I GetNearestHalfGridPosition(const VECTOR2I &aPosition) const
Return the nearest aGridSize / 2 location to aPosition.
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...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:249
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:147
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:143
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:100
virtual EDA_ITEM * Clone() const
Create a duplicate of this item with linked list members set to NULL.
Definition: eda_item.cpp:82
bool IsMoving() const
Definition: eda_item.h:104
bool IsNew() const
Definition: eda_item.h:103
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:163
static TOOL_ACTION mirrorV
Definition: ee_actions.h:128
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
static TOOL_ACTION properties
Definition: ee_actions.h:131
static TOOL_ACTION addItemsToSel
Selects a list of items (specified as the event parameter)
Definition: ee_actions.h:63
static TOOL_ACTION move
Definition: ee_actions.h:123
static TOOL_ACTION pinTable
Definition: ee_actions.h:158
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:127
static TOOL_ACTION mirrorH
Definition: ee_actions.h:129
static TOOL_ACTION rotateCW
Definition: ee_actions.h:126
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:157
static TOOL_ACTION setUnitDisplayName
Definition: ee_actions.h:197
static TOOL_ACTION updateSymbolFields
Definition: ee_actions.h:196
bool Selectable(const EDA_ITEM *aItem, const VECTOR2I *aPos=nullptr, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
void GuessSelectionCandidates(EE_COLLECTOR &collector, const VECTOR2I &aPos)
Apply heuristics to try and determine a single object when multiple are found under the cursor.
bool CollectHits(EE_COLLECTOR &aCollector, const VECTOR2I &aWhere, const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Collect one or more items at a given point.
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T })
Return either an existing selection (filtered), or the selection at the current cursor position if th...
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
EE_SELECTION & GetSelection()
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:50
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
void saveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aType, bool aAppend=false, bool aDirtyConnectivity=true)
Definition: ee_tool_base.h:134
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:184
bool Init() override
Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:66
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:210
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
Field object used in symbol libraries.
Definition: lib_field.h:60
wxString GetClass() const override
Return the class name.
Definition: lib_field.h:72
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:380
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:459
int GetId() const
Definition: lib_field.h:115
The base class for drawable items used by schematic library symbols.
Definition: lib_item.h:61
int GetUnit() const
Definition: lib_item.h:273
virtual void MirrorHorizontal(const VECTOR2I &aCenter)=0
Mirror the draw object along the horizontal (X) axis about aCenter point.
virtual void Rotate(const VECTOR2I &aCenter, bool aRotateCCW=true)=0
Rotate the object about aCenter point.
virtual void MirrorVertical(const VECTOR2I &aCenter)=0
Mirror the draw object along the MirrorVertical (Y) axis about aCenter point.
int GetConvert() const
Definition: lib_item.h:276
LIB_SYMBOL * GetParent() const
Definition: lib_item.h:168
void SetConvert(int aConvert)
Definition: lib_item.h:275
void SetUnit(int aUnit)
Definition: lib_item.h:272
const wxString & GetNumber() const
Definition: lib_pin.h:122
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:124
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_shape.cpp:444
Define a library symbol object.
Definition: lib_symbol.h:98
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:784
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:253
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:403
bool IsAlias() const
Definition: lib_symbol.h:183
int GetMaxPinNumber() const
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:507
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:810
LIB_PIN * GetNextPin(LIB_PIN *aItem=nullptr)
Return the next pin object from the draw list.
Definition: lib_symbol.h:400
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:397
wxString GetUnitReference(int aUnit) override
Return an identifier for aUnit for symbols with units.
Definition: lib_symbol.cpp:391
int GetUnitCount() const override
For items with units, return the number of units.
void SetUnitDisplayName(int aUnit, const wxString &aName)
Set the user-defined display name for aUnit to aName for symbols with units.
Definition: lib_symbol.cpp:425
Define a symbol library graphical text item.
Definition: lib_text.h:40
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:82
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:62
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
static LIB_SYMBOL * ParseLibSymbol(LINE_READER &aReader, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static bool Idle(const SELECTION &aSelection)
Test if there no items selected or being edited.
static bool IdleSelection(const SELECTION &aSelection)
Test if all selected items are not being edited.
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.
void BrightenItem(EDA_ITEM *aItem)
int AddItemToSel(const TOOL_EVENT &aEvent)
void UnbrightenItem(EDA_ITEM *aItem)
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:65
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:118
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:83
bool IsHover() const
Definition: selection.h:81
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:97
EDA_ITEM * Front() const
Definition: selection.h:200
int Size() const
Returns the number of selected parts.
Definition: selection.h:113
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:252
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:107
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:415
const std::string & GetString()
Definition: richio.h:438
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:241
SYMBOL_EDITOR_DRAWING_TOOLS.
int Undo(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
int PinTable(const TOOL_EVENT &aEvent)
void handlePinDuplication(LIB_PIN *aOldPin, LIB_PIN *aNewPin, int &aSymbolLastPinNumber)
Set up handlers for various events.
int Copy(const TOOL_EVENT &aEvent)
void editShapeProperties(LIB_SHAPE *aShape)
int Paste(const TOOL_EVENT &aEvent)
int Cut(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
int Redo(const TOOL_EVENT &aEvent)
void editFieldProperties(LIB_FIELD *aField)
void editTextProperties(LIB_ITEM *aItem)
int Duplicate(const TOOL_EVENT &aEvent)
int Mirror(const TOOL_EVENT &aEvent)
int Rotate(const TOOL_EVENT &aEvent)
int Properties(const TOOL_EVENT &aEvent)
int SetUnitDisplayName(const TOOL_EVENT &aEvent)
int UpdateSymbolFields(const TOOL_EVENT &aEvent)
int DoDelete(const TOOL_EVENT &aEvent)
Delete the selected items, or the item under the cursor.
int DeleteItemCursor(const TOOL_EVENT &aEvent)
void editTextBoxProperties(LIB_ITEM *aItem)
bool EditPinProperties(LIB_PIN *aPin)
The symbol library editor main window.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
LIB_SYMBOL * GetCurSymbol() const
Return the current symbol being edited or NULL if none selected.
void UpdateSymbolMsgPanelInfo()
Display the documentation of the selected symbol.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current symbol.
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.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
Generic, UI-independent tool event.
Definition: tool_event.h:156
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition: tool_event.h:365
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
void 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).
TOOL_MENU & GetToolMenu()
void Activate()
Run the tool.
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:142
std::string GetClipboardUTF8() const
Return the information currently stored in the system clipboard.
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
#define _(s)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:524
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
#define IS_NEW
New item, just created.
#define SELECTED
Item was manually selected by the user.
#define STRUCT_DELETED
flag indication structures to be erased
ELECTRICAL_PINTYPE
The symbol library pin object electrical types used in ERC tests.
Definition: pin_type.h:36
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
wxString TitleCaps(const wxString &aString)
Capitalize the first letter in each word.
wxString EscapeString(const wxString &aSource, ESCAPE_CONTEXT aContext)
The Escape/Unescape routines use HTML-entity-reference-style encoding to handle characters which are:...
@ CTX_LIBID
Definition: string_utils.h:55
static std::vector< KICAD_T > nonFields
@ MANDATORY_FIELDS
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
@ LIB_SYMBOL_T
Definition: typeinfo.h:197
@ LIB_TEXT_T
Definition: typeinfo.h:200
@ LIB_TEXTBOX_T
Definition: typeinfo.h:201
@ LIB_SHAPE_T
Definition: typeinfo.h:199
@ LIB_PIN_T
Definition: typeinfo.h:202
@ LIB_FIELD_T
Definition: typeinfo.h:208