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* curr_pin = static_cast<LIB_PIN*>( item );
273 VECTOR2I pos = curr_pin->GetPosition();
274
275 toDelete.insert( curr_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[curr_pin->GetUnit()] = true;
284
285 int curr_convert = curr_pin->GetConvert();
286 ELECTRICAL_PINTYPE etype = curr_pin->GetType();
287 wxString name = curr_pin->GetName();
288 std::vector<LIB_PIN*> pins = symbol->GetAllLibPins();
289
290 for( LIB_PIN* pin : pins )
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
322 m_frame->OnModify();
323
324 return 0;
325}
326
327
328#define HITTEST_THRESHOLD_PIXELS 5
329
330
332{
334
336 m_pickerItem = nullptr;
337
338 // Deactivate other tools; particularly important if another PICKER is currently running
339 Activate();
340
341 picker->SetCursor( KICURSOR::REMOVE );
342
343 picker->SetClickHandler(
344 [this]( const VECTOR2D& aPosition ) -> bool
345 {
346 if( m_pickerItem )
347 {
349 selectionTool->UnbrightenItem( m_pickerItem );
350 selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
352 m_pickerItem = nullptr;
353 }
354
355 return true;
356 } );
357
358 picker->SetMotionHandler(
359 [this]( const VECTOR2D& aPos )
360 {
362 EE_COLLECTOR collector;
363
364 selectionTool->CollectHits( collector, aPos, nonFields );
365
366 // Remove unselectable items
367 for( int i = collector.GetCount() - 1; i >= 0; --i )
368 {
369 if( !selectionTool->Selectable( collector[ i ] ) )
370 collector.Remove( i );
371 }
372
373 if( collector.GetCount() > 1 )
374 selectionTool->GuessSelectionCandidates( collector, aPos );
375
376 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
377
378 if( m_pickerItem != item )
379 {
380 if( m_pickerItem )
381 selectionTool->UnbrightenItem( m_pickerItem );
382
383 m_pickerItem = item;
384
385 if( m_pickerItem )
386 selectionTool->BrightenItem( m_pickerItem );
387 }
388 } );
389
390 picker->SetFinalizeHandler(
391 [this]( const int& aFinalState )
392 {
393 if( m_pickerItem )
394 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
395
396 // Wake the selection tool after exiting to ensure the cursor gets updated
398 } );
399
401
402 return 0;
403}
404
405
407{
409
410 if( selection.Empty() || aEvent.IsAction( &EE_ACTIONS::symbolProperties ) )
411 {
412 if( m_frame->GetCurSymbol() )
414 }
415 else if( selection.Size() == 1 )
416 {
417 LIB_ITEM* item = (LIB_ITEM*) selection.Front();
418
419 // Save copy for undo if not in edit (edit command already handle the save copy)
420 if( item->GetEditFlags() == 0 )
422
423 switch( item->Type() )
424 {
425 case LIB_PIN_T:
426 {
428
429 if( pinTool )
430 pinTool->EditPinProperties( (LIB_PIN*) item );
431 }
432 break;
433
434 case LIB_SHAPE_T:
435 editShapeProperties( static_cast<LIB_SHAPE*>( item ) );
436 break;
437
438 case LIB_TEXT_T:
439 editTextProperties( item );
440 break;
441
442 case LIB_TEXTBOX_T:
443 editTextBoxProperties( item );
444 break;
445
446 case LIB_FIELD_T:
448 break;
449
450 default:
451 wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
452 break;
453 }
454 }
455
456 if( selection.IsHover() )
458 else
460
461 return 0;
462}
463
464
466{
468
469 if( dlg.ShowModal() != wxID_OK )
470 return;
471
472 updateItem( aShape, true );
474 m_frame->OnModify();
475
477 drawingTools->SetDrawSpecificConvert( !dlg.GetApplyToAllConversions() );
478 drawingTools->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
479
480 std::vector<MSG_PANEL_ITEM> items;
481 aShape->GetMsgPanelInfo( m_frame, items );
482 m_frame->SetMsgPanel( items );
483}
484
485
487{
488 if ( aItem->Type() != LIB_TEXT_T )
489 return;
490
491 DIALOG_LIB_TEXT_PROPERTIES dlg( m_frame, static_cast<LIB_TEXT*>( aItem ) );
492
493 if( dlg.ShowModal() != wxID_OK )
494 return;
495
496 updateItem( aItem, true );
498 m_frame->OnModify( );
499}
500
501
503{
504 if ( aItem->Type() != LIB_TEXTBOX_T )
505 return;
506
507 DIALOG_LIB_TEXTBOX_PROPERTIES dlg( m_frame, static_cast<LIB_TEXTBOX*>( aItem ) );
508
509 if( dlg.ShowModal() != wxID_OK )
510 return;
511
512 updateItem( aItem, true );
514 m_frame->OnModify( );
515}
516
517
519{
520 if( aField == nullptr )
521 return;
522
523 wxString caption;
524 LIB_SYMBOL* parent = aField->GetParent();
525 wxCHECK( parent, /* void */ );
526
527 if( aField->GetId() < MANDATORY_FIELDS )
528 caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
529 else
530 caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
531
532 DIALOG_LIB_FIELD_PROPERTIES dlg( m_frame, caption, aField );
533
534 // The dialog may invoke a kiway player for footprint fields
535 // so we must use a quasimodal dialog.
536 if( dlg.ShowQuasiModal() != wxID_OK )
537 return;
538
539 wxString newFieldValue = EscapeString( dlg.GetText(), CTX_LIBID );
540 wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
541
543
544 dlg.UpdateField( aField );
545
546 updateItem( aField, true );
548 m_frame->OnModify();
550}
551
552
554{
555 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
556 bool partLocked = symbol->UnitsLocked();
557
560
562
563 // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
564 // frame. Therefore this dialog as a modal frame parent, MUST be run under
565 // quasimodal mode for the quasimodal frame support to work. So don't use
566 // the QUASIMODAL macros here.
567 if( dlg.ShowQuasiModal() != wxID_OK )
568 return;
569
570 m_frame->OnModify();
571
572 // if m_UnitSelectionLocked has changed, set some edit options or defaults
573 // to the best value
574 if( partLocked != symbol->UnitsLocked() )
575 {
577
578 // Enable synchronized pin edit mode for symbols with interchangeable units
579 m_frame->m_SyncPinEdit = !symbol->UnitsLocked();
580
581 // also set default edit options to the better value
582 // Usually if units are locked, graphic items are specific to each unit
583 // and if units are interchangeable, graphic items are common to units
584 tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
585 }
586}
587
589 int& aSymbolLastPinNumber )
590{
591 if( !aNewPin->GetNumber().IsEmpty() )
592 {
593 // when duplicating a pin in symbol editor, assigning identical pin number
594 // to the old one does not makes any sense, so assign the next unassigned number to it
595 aSymbolLastPinNumber++;
596 aNewPin->SetNumber( wxString::Format( wxT( "%i" ), aSymbolLastPinNumber ) );
597 }
598}
599
601{
602 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
603
604 if( !symbol )
605 return 0;
606
608
610
611 DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol );
612
613 if( dlg.ShowModal() == wxID_CANCEL )
614 return -1;
615
617 m_frame->OnModify();
618
619 return 0;
620}
621
622
624{
625 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
626
627 if( !symbol )
628 return 0;
629
630 if( !symbol->IsAlias() )
631 {
632 m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
633 }
634 else
635 {
637
638 if( dlg.ShowModal() == wxID_CANCEL )
639 return -1;
640 }
641
642 return 0;
643}
644
645
647{
648 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
649
650 if( !symbol )
651 return 0;
652
653 int unitid = m_frame->GetUnit();
654
655 if( unitid == 0 )
656 {
657 return -1;
658 }
659
660 wxString promptText = wxString::Format( _( "Enter display name for unit %s" ),
661 symbol->GetUnitReference( unitid ) );
662 wxString currentvalue;
663
664 if( symbol->HasUnitDisplayName( unitid ) )
665 {
666 currentvalue = symbol->GetUnitDisplayName( unitid );
667 }
668
669 wxTextEntryDialog dlg( m_frame, promptText, _( "Set Unit Display Name" ), currentvalue );
670
671 if( dlg.ShowModal() == wxID_OK )
672 {
674 symbol->SetUnitDisplayName( unitid, dlg.GetValue() );
676 m_frame->OnModify();
677 }
678 else
679 {
680 return -1;
681 }
682
683 return 0;
684}
685
686
688{
690
692 selTool->RebuildSelection();
693
694 return 0;
695}
696
697
699{
701
703 selTool->RebuildSelection();
704
705 return 0;
706}
707
708
710{
711 int retVal = Copy( aEvent );
712
713 if( retVal == 0 )
714 retVal = DoDelete( aEvent );
715
716 return retVal;
717}
718
719
721{
722 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
724
725 if( !symbol || !selection.GetSize() )
726 return 0;
727
728 for( LIB_ITEM& item : symbol->GetDrawItems() )
729 {
730 if( item.Type() == LIB_FIELD_T )
731 continue;
732
733 wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
734
735 if( !item.IsSelected() )
736 item.SetFlags( STRUCT_DELETED );
737 }
738
739 LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
740
741 STRING_FORMATTER formatter;
742 SCH_SEXPR_PLUGIN::FormatLibSymbol( partCopy, formatter );
743
744 delete partCopy;
745
746 for( LIB_ITEM& item : symbol->GetDrawItems() )
748
749 if( m_toolMgr->SaveClipboard( formatter.GetString() ) )
750 return 0;
751 else
752 return -1;
753}
754
755
757{
758 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
759
760 if( !symbol || symbol->IsAlias() )
761 return 0;
762
763 std::string text_utf8 = m_toolMgr->GetClipboardUTF8();
764 STRING_LINE_READER reader( text_utf8, "Clipboard" );
765 LIB_SYMBOL* newPart;
766
767 try
768 {
769 newPart = SCH_SEXPR_PLUGIN::ParseLibSymbol( reader );
770 }
771 catch( IO_ERROR& )
772 {
773 // If it's not a symbol then paste as text
774 newPart = new LIB_SYMBOL( "dummy_part" );
775 LIB_TEXT* newText = new LIB_TEXT( newPart );
776 newText->SetText( wxString::FromUTF8( text_utf8.c_str() ) );
777 newPart->AddDrawItem( newText );
778 }
779
780 if( !newPart )
781 return -1;
782
783 m_frame->SaveCopyInUndoList( symbol );
785
786 for( LIB_ITEM& item : symbol->GetDrawItems() )
787 item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
788
789 for( LIB_ITEM& item : newPart->GetDrawItems() )
790 {
791 if( item.Type() == LIB_FIELD_T )
792 continue;
793
794 LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
795 newItem->SetParent( symbol );
796 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
797
798 newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
799 newItem->SetConvert( newItem->GetConvert() ? m_frame->GetConvert() : 0 );
800
801 symbol->AddDrawItem( newItem );
802 getView()->Add( newItem );
803 }
804
805 delete newPart;
806
808
810
811 if( !selection.Empty() )
812 {
813 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
815 }
816
817 return 0;
818}
819
820
822{
823 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
825
826 if( selection.GetSize() == 0 )
827 return 0;
828
829 // Doing a duplicate of a new object doesn't really make any sense; we'd just end
830 // up dragging around a stack of objects...
831 if( selection.Front()->IsNew() )
832 return 0;
833
834 if( !selection.Front()->IsMoving() )
836
837 EDA_ITEMS newItems;
838 int symbolLastPinNumber = -1;
839
840 for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
841 {
842 LIB_ITEM* oldItem = static_cast<LIB_ITEM*>( selection.GetItem( ii ) );
843 LIB_ITEM* newItem = (LIB_ITEM*) oldItem->Clone();
844
845 if( oldItem->Type() == LIB_PIN_T )
846 {
847 if( symbolLastPinNumber == -1 )
848 {
849 symbolLastPinNumber = symbol->GetMaxPinNumber();
850 }
851
852 handlePinDuplication( static_cast<LIB_PIN*>( oldItem ),
853 static_cast<LIB_PIN*>( newItem ), symbolLastPinNumber );
854 }
855
856 oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
857 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
858 newItem->SetParent( symbol );
859 newItems.push_back( newItem );
860
861 symbol->AddDrawItem( newItem );
862 getView()->Add( newItem );
863 }
864
866 m_toolMgr->RunAction( EE_ACTIONS::addItemsToSel, true, &newItems );
867
868 selection.SetReferencePoint( mapCoords( getViewControls()->GetCursorPosition( true ) ) );
870
871 return 0;
872}
873
874
876{
883
890
896}
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:145
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:139
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:141
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:125
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
static TOOL_ACTION properties
Definition: ee_actions.h:128
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:120
static TOOL_ACTION pinTable
Definition: ee_actions.h:155
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:124
static TOOL_ACTION mirrorH
Definition: ee_actions.h:126
static TOOL_ACTION rotateCW
Definition: ee_actions.h:123
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:154
static TOOL_ACTION setUnitDisplayName
Definition: ee_actions.h:194
static TOOL_ACTION updateSymbolFields
Definition: ee_actions.h:193
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:213
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:61
wxString GetClass() const override
Return the class name.
Definition: lib_field.h:71
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: lib_field.cpp:391
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: lib_field.cpp:470
int GetId() const
Definition: lib_field.h:114
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
ELECTRICAL_PINTYPE GetType() const
Definition: lib_pin.h:90
VECTOR2I GetPosition() const override
Definition: lib_pin.h:222
const wxString & GetNumber() const
Definition: lib_pin.h:122
void SetNumber(const wxString &aNumber)
Definition: lib_pin.h:124
const wxString & GetName() const
Definition: lib_pin.h:112
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:456
Define a library symbol object.
Definition: lib_symbol.h:99
void RemoveDrawItem(LIB_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:797
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:258
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:399
bool IsAlias() const
Definition: lib_symbol.h:188
int GetMaxPinNumber() const
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:508
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:823
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:393
wxString GetUnitReference(int aUnit) override
Return an identifier for aUnit for symbols with units.
Definition: lib_symbol.cpp:387
std::vector< LIB_PIN * > GetAllLibPins() const
Return a list of pin pointers for all units / converts.
Definition: lib_symbol.cpp:861
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:421
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:75
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:120
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:93
bool IsHover() const
Definition: selection.h:83
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:99
EDA_ITEM * Front() const
Definition: selection.h:208
int Size() const
Returns the number of selected parts.
Definition: selection.h:115
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:260
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:109
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:215
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:198
@ 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