KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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
26
27#include <tool/picker_tool.h>
29#include <tools/ee_tool_utils.h>
33#include <clipboard.h>
34#include <ee_actions.h>
35#include <increment.h>
36#include <pin_layout_cache.h>
37#include <string_utils.h>
38#include <symbol_edit_frame.h>
39#include <sch_commit.h>
41#include <dialogs/dialog_text_properties.h>
46#include <view/view_controls.h>
47#include <richio.h>
49#include <sch_textbox.h>
50#include <wx/textdlg.h> // for wxTextEntryDialog
51#include <math/util.h> // for KiROUND
53
55 EE_TOOL_BASE( "eeschema.SymbolEditTool" ),
56 m_pickerItem( nullptr )
57{
58}
59
60
62{
64
67
68 wxASSERT_MSG( drawingTools, "eeschema.SymbolDrawing tool is not available" );
69
70 auto haveSymbolCondition =
71 [&]( const SELECTION& sel )
72 {
74 };
75
76 auto canEdit =
77 [&]( const SELECTION& sel )
78 {
80 return false;
81
82 if( m_frame->IsSymbolAlias() )
83 {
84 for( EDA_ITEM* item : sel )
85 {
86 if( item->Type() != SCH_FIELD_T )
87 return false;
88 }
89 }
90
91 return true;
92 };
93
94 const auto canCopyText = EE_CONDITIONS::OnlyTypes( {
101 } );
102
103 // Add edit actions to the move tool menu
104 if( moveTool )
105 {
106 CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
107
108 moveMenu.AddSeparator( 200 );
109 moveMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
110 moveMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
111 moveMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
112 moveMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
113
114 moveMenu.AddItem( EE_ACTIONS::swap, canEdit && SELECTION_CONDITIONS::MoreThan( 1 ), 200);
115 moveMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
116
117 moveMenu.AddSeparator( 300 );
120 moveMenu.AddItem( ACTIONS::copyAsText, canCopyText && EE_CONDITIONS::IdleSelection, 300 );
121 moveMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
122 moveMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 200 );
123
124 moveMenu.AddSeparator( 400 );
125 moveMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
126 moveMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
127 }
128
129 // Add editing actions to the drawing tool menu
130 CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
131
132 drawMenu.AddSeparator( 200 );
134 drawMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::IdleSelection, 200 );
135 drawMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::IdleSelection, 200 );
136 drawMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::IdleSelection, 200 );
137
138 drawMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
139
140 // Add editing actions to the selection tool menu
142
143 selToolMenu.AddItem( EE_ACTIONS::rotateCCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
144 selToolMenu.AddItem( EE_ACTIONS::rotateCW, canEdit && EE_CONDITIONS::NotEmpty, 200 );
145 selToolMenu.AddItem( EE_ACTIONS::mirrorV, canEdit && EE_CONDITIONS::NotEmpty, 200 );
146 selToolMenu.AddItem( EE_ACTIONS::mirrorH, canEdit && EE_CONDITIONS::NotEmpty, 200 );
147
148 selToolMenu.AddItem( EE_ACTIONS::swap, canEdit && SELECTION_CONDITIONS::MoreThan( 1 ), 200 );
149 selToolMenu.AddItem( EE_ACTIONS::properties, canEdit && EE_CONDITIONS::Count( 1 ), 200 );
150
151 selToolMenu.AddSeparator( 300 );
154 selToolMenu.AddItem( ACTIONS::copyAsText, canCopyText && EE_CONDITIONS::IdleSelection, 300 );
155 selToolMenu.AddItem( ACTIONS::paste, canEdit && EE_CONDITIONS::Idle, 300 );
156 selToolMenu.AddItem( ACTIONS::duplicate, canEdit && EE_CONDITIONS::NotEmpty, 300 );
157 selToolMenu.AddItem( ACTIONS::doDelete, canEdit && EE_CONDITIONS::NotEmpty, 300 );
158
159 selToolMenu.AddSeparator( 400 );
160 selToolMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
161 selToolMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
162
163 return true;
164}
165
166
168{
170
171 if( selection.GetSize() == 0 )
172 return 0;
173
174 VECTOR2I rotPoint;
175 bool ccw = ( aEvent.Matches( EE_ACTIONS::rotateCCW.MakeEvent() ) );
176 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
177 SCH_COMMIT localCommit( m_toolMgr );
178 SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() );
179
180 if( !commit )
181 commit = &localCommit;
182
183 if( !item->IsMoving() )
184 commit->Modify( m_frame->GetCurSymbol(), m_frame->GetScreen() );
185
186 if( selection.GetSize() == 1 )
187 rotPoint = item->GetPosition();
188 else
189 rotPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
190
191 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
192 {
193 item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
194 item->Rotate( rotPoint, ccw );
195 m_frame->UpdateItem( item, false, true );
196 }
197
198 if( item->IsMoving() )
199 {
201 }
202 else
203 {
204 if( selection.IsHover() )
206
207 if( !localCommit.Empty() )
208 localCommit.Push( _( "Rotate" ) );
209 }
210
211 return 0;
212}
213
214
216{
218
219 if( selection.GetSize() == 0 )
220 return 0;
221
222 VECTOR2I mirrorPoint;
223 bool xAxis = ( aEvent.Matches( EE_ACTIONS::mirrorV.MakeEvent() ) );
224 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
225
226 if( !item->IsMoving() )
227 saveCopyInUndoList( m_frame->GetCurSymbol(), UNDO_REDO::LIBEDIT );
228
229 if( selection.GetSize() == 1 )
230 {
231 mirrorPoint = item->GetPosition();
232
233 switch( item->Type() )
234 {
235 case SCH_FIELD_T:
236 {
237 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
238
239 if( xAxis )
241 else
243
244 break;
245 }
246
247 default:
248 if( xAxis )
249 item->MirrorVertically( mirrorPoint.y );
250 else
251 item->MirrorHorizontally( mirrorPoint.x );
252
253 break;
254 }
255
256
257 m_frame->UpdateItem( item, false, true );
258 }
259 else
260 {
261 mirrorPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
262
263 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
264 {
265 item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
266
267 if( xAxis )
268 item->MirrorVertically( mirrorPoint.y );
269 else
270 item->MirrorHorizontally( mirrorPoint.x );
271
272 m_frame->UpdateItem( item, false, true );
273 }
274 }
275
276 if( item->IsMoving() )
277 {
279 }
280 else
281 {
282 if( selection.IsHover() )
284
285 m_frame->OnModify();
286 }
287
288 return 0;
289}
290
291
292const std::vector<KICAD_T> swappableItems = {
293 LIB_SYMBOL_T, // Allows swapping the anchor
294 SCH_PIN_T,
299};
300
301
303{
305 std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
306
307 if( selection.Size() < 2 )
308 return 0;
309
310 EDA_ITEM* front = selection.Front();
311 bool isMoving = front->IsMoving();
312
313 // Save copy for undo if not in edit (edit command already handle the save copy)
314 if( front->GetEditFlags() == 0 )
315 saveCopyInUndoList( front->GetParent(), UNDO_REDO::LIBEDIT );
316
317 for( size_t i = 0; i < sorted.size() - 1; i++ )
318 {
319 SCH_ITEM* a = static_cast<SCH_ITEM*>( sorted[i] );
320 SCH_ITEM* b = static_cast<SCH_ITEM*>( sorted[( i + 1 ) % sorted.size()] );
321
322 VECTOR2I aPos = a->GetPosition(), bPos = b->GetPosition();
323 std::swap( aPos, bPos );
324
325 a->SetPosition( aPos );
326 b->SetPosition( bPos );
327
328 // Special case some common swaps
329 if( a->Type() == b->Type() )
330 {
331 switch( a->Type() )
332 {
333 case SCH_PIN_T:
334 {
335 SCH_PIN* aPin = static_cast<SCH_PIN*>( a );
336 SCH_PIN* bBpin = static_cast<SCH_PIN*>( b );
337
338 PIN_ORIENTATION aOrient = aPin->GetOrientation();
339 PIN_ORIENTATION bOrient = bBpin->GetOrientation();
340
341 aPin->SetOrientation( bOrient );
342 bBpin->SetOrientation( aOrient );
343
344 break;
345 }
346 default: break;
347 }
348 }
349
350 m_frame->UpdateItem( a, false, true );
351 m_frame->UpdateItem( b, false, true );
352 }
353
354 // Update R-Tree for modified items
355 for( EDA_ITEM* selected : selection )
356 updateItem( selected, true );
357
358 if( isMoving )
359 {
361 }
362 else
363 {
364 if( selection.IsHover() )
366
367 m_frame->OnModify();
368 }
369
370 return 0;
371}
372
373
374static std::vector<KICAD_T> nonFields =
375{
381};
382
383
385{
386 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
387 std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection().GetItems();
388 SCH_COMMIT commit( m_frame );
389
390 if( items.empty() )
391 return 0;
392
393 // Don't leave a freed pointer in the selection
395
396 commit.Modify( symbol, m_frame->GetScreen() );
397
398 std::set<SCH_ITEM*> toDelete;
399 int fieldsHidden = 0;
400 int fieldsAlreadyHidden = 0;
401
402 for( EDA_ITEM* item : items )
403 {
404 if( item->Type() == SCH_PIN_T )
405 {
406 SCH_PIN* curr_pin = static_cast<SCH_PIN*>( item );
407 VECTOR2I pos = curr_pin->GetPosition();
408
409 toDelete.insert( curr_pin );
410
411 // when pin editing is synchronized, pins in the same position, with the same name
412 // in different units are also removed. But only one pin per unit (matching)
413 if( m_frame->SynchronizePins() )
414 {
415 std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
416
417 got_unit[curr_pin->GetUnit()] = true;
418
419 for( SCH_PIN* pin : symbol->GetAllLibPins() )
420 {
421 if( got_unit[pin->GetUnit()] )
422 continue;
423
424 if( pin->GetPosition() != pos )
425 continue;
426
427 if( pin->GetBodyStyle() != curr_pin->GetBodyStyle() )
428 continue;
429
430 if( pin->GetType() != curr_pin->GetType() )
431 continue;
432
433 if( pin->GetName() != curr_pin->GetName() )
434 continue;
435
436 toDelete.insert( pin );
437 got_unit[pin->GetUnit()] = true;
438 }
439 }
440 }
441 else if( item->Type() == SCH_FIELD_T )
442 {
443 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
444
445 // Hide "deleted" fields
446 if( field->IsVisible() )
447 {
448 field->SetVisible( false );
449 fieldsHidden++;
450 }
451 else
452 {
453 fieldsAlreadyHidden++;
454 }
455 }
456 else if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
457 {
458 toDelete.insert( schItem );
459 }
460 }
461
462 for( SCH_ITEM* item : toDelete )
463 symbol->RemoveDrawItem( item );
464
465 if( toDelete.size() == 0 )
466 {
467 if( fieldsHidden == 1 )
468 commit.Push( _( "Hide Field" ) );
469 else if( fieldsHidden > 1 )
470 commit.Push( _( "Hide Fields" ) );
471 else if( fieldsAlreadyHidden > 0 )
472 m_frame->ShowInfoBarError( _( "Use the Symbol Properties dialog to remove fields." ) );
473 }
474 else
475 {
476 commit.Push( _( "Delete" ) );
477 }
478
480 return 0;
481}
482
483
484#define HITTEST_THRESHOLD_PIXELS 5
485
486
488{
490
492 m_pickerItem = nullptr;
493
494 // Deactivate other tools; particularly important if another PICKER is currently running
495 Activate();
496
497 picker->SetCursor( KICURSOR::REMOVE );
498
499 picker->SetClickHandler(
500 [this]( const VECTOR2D& aPosition ) -> bool
501 {
502 if( m_pickerItem )
503 {
505 selectionTool->UnbrightenItem( m_pickerItem );
506 selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
508 m_pickerItem = nullptr;
509 }
510
511 return true;
512 } );
513
514 picker->SetMotionHandler(
515 [this]( const VECTOR2D& aPos )
516 {
518 EE_COLLECTOR collector;
519
520 selectionTool->CollectHits( collector, aPos, nonFields );
521
522 // Remove unselectable items
523 for( int i = collector.GetCount() - 1; i >= 0; --i )
524 {
525 if( !selectionTool->Selectable( collector[ i ] ) )
526 collector.Remove( i );
527 }
528
529 if( collector.GetCount() > 1 )
530 selectionTool->GuessSelectionCandidates( collector, aPos );
531
532 EDA_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
533
534 if( m_pickerItem != item )
535 {
536 if( m_pickerItem )
537 selectionTool->UnbrightenItem( m_pickerItem );
538
539 m_pickerItem = item;
540
541 if( m_pickerItem )
542 selectionTool->BrightenItem( m_pickerItem );
543 }
544 } );
545
546 picker->SetFinalizeHandler(
547 [this]( const int& aFinalState )
548 {
549 if( m_pickerItem )
550 m_toolMgr->GetTool<EE_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
551
552 // Wake the selection tool after exiting to ensure the cursor gets updated
554 } );
555
557
558 return 0;
559}
560
561
563{
565
566 if( selection.Empty() || aEvent.IsAction( &EE_ACTIONS::symbolProperties ) )
567 {
568 if( m_frame->GetCurSymbol() )
570 }
571 else if( selection.Size() == 1 )
572 {
573 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
574
575 // Save copy for undo if not in edit (edit command already handle the save copy)
576 if( item->GetEditFlags() == 0 )
577 saveCopyInUndoList( item->GetParent(), UNDO_REDO::LIBEDIT );
578
579 switch( item->Type() )
580 {
581 case SCH_PIN_T:
582 {
583 SCH_PIN& pin = static_cast<SCH_PIN&>( *item );
584
585 // Mouse, not cursor, as grid points may well not be under any text
586 const VECTOR2I& mousePos = m_toolMgr->GetMousePosition();
587 PIN_LAYOUT_CACHE& layout = pin.GetLayoutCache();
588
589 bool mouseOverNumber = false;
590 if( OPT_BOX2I numberBox = layout.GetPinNumberBBox() )
591 {
592 mouseOverNumber = numberBox->Contains( mousePos );
593 }
594
596 pinTool->EditPinProperties( &pin, mouseOverNumber );
597
598 break;
599 }
600 case SCH_SHAPE_T:
601 editShapeProperties( static_cast<SCH_SHAPE*>( item ) );
602 break;
603
604 case SCH_TEXT_T:
605 editTextProperties( item );
606 break;
607
608 case SCH_TEXTBOX_T:
609 editTextBoxProperties( item );
610 break;
611
612 case SCH_FIELD_T:
613 editFieldProperties( static_cast<SCH_FIELD*>( item ) );
614 break;
615
616 default:
617 wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
618 break;
619 }
620 }
621
622 if( selection.IsHover() )
624
625 return 0;
626}
627
628
630{
631 DIALOG_SHAPE_PROPERTIES dlg( m_frame, aShape );
632
633 if( dlg.ShowModal() != wxID_OK )
634 return;
635
636 updateItem( aShape, true );
638 m_frame->OnModify();
639
642 drawingTools->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
643
644 std::vector<MSG_PANEL_ITEM> items;
645 aShape->GetMsgPanelInfo( m_frame, items );
646 m_frame->SetMsgPanel( items );
647}
648
649
651{
652 if ( aItem->Type() != SCH_TEXT_T )
653 return;
654
655 DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_TEXT*>( aItem ) );
656
657 if( dlg.ShowModal() != wxID_OK )
658 return;
659
660 updateItem( aItem, true );
662 m_frame->OnModify( );
663}
664
665
667{
668 if ( aItem->Type() != SCH_TEXTBOX_T )
669 return;
670
671 DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_TEXTBOX*>( aItem ) );
672
673 if( dlg.ShowModal() != wxID_OK )
674 return;
675
676 updateItem( aItem, true );
678 m_frame->OnModify( );
679}
680
681
683{
684 if( aField == nullptr )
685 return;
686
687 wxString caption;
688
689 if( aField->IsMandatory() )
690 caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
691 else
692 caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
693
694 DIALOG_FIELD_PROPERTIES dlg( m_frame, caption, aField );
695
696 // The dialog may invoke a kiway player for footprint fields
697 // so we must use a quasimodal dialog.
698 if( dlg.ShowQuasiModal() != wxID_OK )
699 return;
700
701 wxString newFieldValue = EscapeString( dlg.GetText(), CTX_LIBID );
702 wxString oldFieldValue = aField->GetFullText( m_frame->GetUnit() );
703
704 SCH_COMMIT commit( m_toolMgr );
705 commit.Modify( aField, m_frame->GetScreen() );
706
707 dlg.UpdateField( aField );
708
709 commit.Push( caption );
710
713}
714
715
717{
718 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
719 bool partLocked = symbol->UnitsLocked();
720
723
725
726 // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
727 // frame. Therefore this dialog as a modal frame parent, MUST be run under
728 // quasimodal mode for the quasimodal frame support to work. So don't use
729 // the QUASIMODAL macros here.
730 if( dlg.ShowQuasiModal() != wxID_OK )
731 return;
732
733 m_frame->OnModify();
734
735 // if m_UnitSelectionLocked has changed, set some edit options or defaults
736 // to the best value
737 if( partLocked != symbol->UnitsLocked() )
738 {
740
741 // Enable synchronized pin edit mode for symbols with interchangeable units
742 m_frame->m_SyncPinEdit = !symbol->UnitsLocked();
743
744 // also set default edit options to the better value
745 // Usually if units are locked, graphic items are specific to each unit
746 // and if units are interchangeable, graphic items are common to units
747 tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
748 }
749}
750
752 int& aSymbolLastPinNumber )
753{
754 if( !aNewPin->GetNumber().IsEmpty() )
755 {
756 // when duplicating a pin in symbol editor, assigning identical pin number
757 // to the old one does not makes any sense, so assign the next unassigned number to it
758 aSymbolLastPinNumber++;
759 aNewPin->SetNumber( wxString::Format( wxT( "%i" ), aSymbolLastPinNumber ) );
760 }
761}
762
764{
765 SCH_COMMIT commit( m_frame );
766 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
767
768 if( !symbol )
769 return 0;
770
771 commit.Modify( symbol );
772
774
775 DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol );
776
777 if( dlg.ShowModal() == wxID_CANCEL )
778 return -1;
779
780 commit.Push( _( "Edit Pins" ) );
782
783 return 0;
784}
785
786
788{
789 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
790
791 if( !symbol )
792 return 0;
793
794 if( !symbol->IsAlias() )
795 {
796 m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
797 }
798 else
799 {
801
802 if( dlg.ShowModal() == wxID_CANCEL )
803 return -1;
804 }
805
806 return 0;
807}
808
809
811{
812 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
813
814 if( !symbol )
815 return 0;
816
817 int unitid = m_frame->GetUnit();
818
819 if( unitid == 0 )
820 {
821 return -1;
822 }
823
824 wxString promptText = wxString::Format( _( "Enter display name for unit %s" ),
825 symbol->GetUnitReference( unitid ) );
826 wxString currentvalue;
827
828 if( symbol->HasUnitDisplayName( unitid ) )
829 {
830 currentvalue = symbol->GetUnitDisplayName( unitid );
831 }
832
833 wxTextEntryDialog dlg( m_frame, promptText, _( "Set Unit Display Name" ), currentvalue );
834
835 if( dlg.ShowModal() == wxID_OK )
836 {
837 saveCopyInUndoList( symbol, UNDO_REDO::LIBEDIT );
838 symbol->SetUnitDisplayName( unitid, dlg.GetValue() );
840 m_frame->OnModify();
841 }
842 else
843 {
844 return -1;
845 }
846
847 return 0;
848}
849
850
852{
854
855 // Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
856 // it just clears the SELECTION's reference to them.
857 selTool->GetSelection().Clear();
858 {
860 }
861 selTool->RebuildSelection();
862
863 return 0;
864}
865
866
868{
870
871 // Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
872 // it just clears the SELECTION's reference to them.
873 selTool->GetSelection().Clear();
874 {
876 }
877 selTool->RebuildSelection();
878
879 return 0;
880}
881
882
884{
885 int retVal = Copy( aEvent );
886
887 if( retVal == 0 )
888 retVal = DoDelete( aEvent );
889
890 return retVal;
891}
892
893
895{
896 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
898
899 if( !symbol || !selection.GetSize() )
900 return 0;
901
902 for( SCH_ITEM& item : symbol->GetDrawItems() )
903 {
904 if( item.Type() == SCH_FIELD_T )
905 continue;
906
907 wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
908
909 if( !item.IsSelected() )
910 item.SetFlags( STRUCT_DELETED );
911 }
912
913 LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
914
915 STRING_FORMATTER formatter;
916 SCH_IO_KICAD_SEXPR::FormatLibSymbol( partCopy, formatter );
917
918 delete partCopy;
919
920 for( SCH_ITEM& item : symbol->GetDrawItems() )
922
923 std::string prettyData = formatter.GetString();
924 KICAD_FORMAT::Prettify( prettyData, true );
925
926 if( SaveClipboard( prettyData ) )
927 return 0;
928 else
929 return -1;
930}
931
932
934{
936 EE_SELECTION& selection = selTool->RequestSelection();
937
938 if( selection.Empty() )
939 return 0;
940
941 wxString itemsAsText = GetSelectedItemsAsText( selection );
942
943 if( selection.IsHover() )
945
946 return SaveClipboard( itemsAsText.ToStdString() );
947}
948
949
951{
952 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
953 LIB_SYMBOL* newPart = nullptr;
954
955 if( !symbol || symbol->IsAlias() )
956 return 0;
957
958 std::string clipboardData = GetClipboardUTF8();
959
960 try
961 {
962 std::vector<LIB_SYMBOL*> newParts = SCH_IO_KICAD_SEXPR::ParseLibSymbols( clipboardData, "Clipboard" );
963
964 if( newParts.empty() || !newParts[0] )
965 return -1;
966
967 newPart = newParts[0];
968 }
969 catch( IO_ERROR& )
970 {
971 // If it's not a symbol then paste as text
972 newPart = new LIB_SYMBOL( "dummy_part" );
973
974 wxString pasteText( clipboardData );
975
976 // Limit of 5000 is totally arbitrary. Without a limit, pasting a bitmap image from
977 // eeschema makes KiCad appear to hang.
978 if( pasteText.Length() > 5000 )
979 pasteText = pasteText.Left( 5000 ) + wxT( "..." );
980
981 SCH_TEXT* newText = new SCH_TEXT( { 0, 0 }, pasteText, LAYER_DEVICE );
982 newPart->AddDrawItem( newText );
983 }
984
985 SCH_COMMIT commit( m_toolMgr );
986
987 commit.Modify( symbol );
989
990 for( SCH_ITEM& item : symbol->GetDrawItems() )
991 item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
992
993 for( SCH_ITEM& item : newPart->GetDrawItems() )
994 {
995 if( item.Type() == SCH_FIELD_T )
996 continue;
997
998 SCH_ITEM* newItem = item.Duplicate();
999 newItem->SetParent( symbol );
1000 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
1001
1002 newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
1003 newItem->SetBodyStyle( newItem->GetBodyStyle() ? m_frame->GetBodyStyle() : 0 );
1004
1005 symbol->AddDrawItem( newItem );
1006 getView()->Add( newItem );
1007 }
1008
1009 delete newPart;
1010
1012
1014
1015 if( !selection.Empty() )
1016 {
1017 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
1018
1020 commit.Push( _( "Paste" ) );
1021 else
1022 commit.Revert();
1023 }
1024
1025 return 0;
1026}
1027
1028
1030{
1031 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1033 SCH_COMMIT commit( m_toolMgr );
1034
1035 if( selection.GetSize() == 0 )
1036 return 0;
1037
1038 commit.Modify( symbol, m_frame->GetScreen() );
1039
1040 std::vector<EDA_ITEM*> oldItems;
1041 std::vector<EDA_ITEM*> newItems;
1042
1043 std::copy( selection.begin(), selection.end(), std::back_inserter( oldItems ) );
1044 std::sort( oldItems.begin(), oldItems.end(), []( EDA_ITEM* a, EDA_ITEM* b )
1045 {
1046 int cmp;
1047
1048 if( a->Type() != b->Type() )
1049 return a->Type() < b->Type();
1050
1051 // Create the new pins in the same order as the old pins
1052 if( a->Type() == SCH_PIN_T )
1053 {
1054 const wxString& aNum = static_cast<SCH_PIN*>( a )->GetNumber();
1055 const wxString& bNum = static_cast<SCH_PIN*>( b )->GetNumber();
1056
1057 cmp = StrNumCmp( aNum, bNum );
1058
1059 // If the pin numbers are not numeric, then just number them by their position
1060 // on the screen.
1061 if( aNum.IsNumber() && bNum.IsNumber() && cmp != 0 )
1062 return cmp < 0;
1063 }
1064
1066
1067 if( cmp != 0 )
1068 return cmp < 0;
1069
1070 return a->m_Uuid < b->m_Uuid;
1071 } );
1072
1073 for( EDA_ITEM* item : oldItems )
1074 {
1075 SCH_ITEM* oldItem = static_cast<SCH_ITEM*>( item );
1076 SCH_ITEM* newItem = oldItem->Duplicate();
1077
1078 if( newItem->Type() == SCH_PIN_T )
1079 {
1080 SCH_PIN* newPin = static_cast<SCH_PIN*>( newItem );
1081
1082 if( !newPin->GetNumber().IsEmpty() )
1083 newPin->SetNumber( wxString::Format( wxT( "%i" ), symbol->GetMaxPinNumber() + 1 ) );
1084 }
1085
1086 oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
1087 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
1088 newItem->SetParent( symbol );
1089 newItems.push_back( newItem );
1090
1091 symbol->AddDrawItem( newItem );
1092 getView()->Add( newItem );
1093 }
1094
1095 m_toolMgr->RunAction( EE_ACTIONS::clearSelection );
1096 m_toolMgr->RunAction<EDA_ITEMS*>( EE_ACTIONS::addItemsToSel, &newItems );
1097
1098 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
1099
1100 if( m_toolMgr->RunSynchronousAction( EE_ACTIONS::move, &commit ) )
1101 commit.Push( _( "Duplicate" ) );
1102 else
1103 commit.Revert();
1104
1105 return 0;
1106}
1107
1108
1110{
1111 const ACTIONS::INCREMENT incParam = aEvent.Parameter<ACTIONS::INCREMENT>();
1113
1114 if( selection.Empty() )
1115 return 0;
1116
1117 KICAD_T type = selection.Front()->Type();
1118 bool allSameType = true;
1119 for( EDA_ITEM* item : selection )
1120 {
1121 if( item->Type() != type )
1122 {
1123 allSameType = false;
1124 break;
1125 }
1126 }
1127
1128 // Incrementing multiple types at once seems confusing
1129 // though it would work.
1130 if( !allSameType )
1131 return 0;
1132
1133 const VECTOR2I mousePosition = getViewControls()->GetMousePosition();
1134
1135 STRING_INCREMENTER incrementer;
1136 incrementer.SetSkipIOSQXZ( true );
1137
1138 SCH_COMMIT commit( m_frame );
1139
1140 for( EDA_ITEM* item : selection )
1141 {
1142 switch( item->Type() )
1143 {
1144 case SCH_PIN_T:
1145 {
1146 SCH_PIN& pin = static_cast<SCH_PIN&>( *item );
1147 PIN_LAYOUT_CACHE& layout = pin.GetLayoutCache();
1148
1149 bool found = false;
1150 OPT_BOX2I bbox = layout.GetPinNumberBBox();
1151
1152 if( bbox && bbox->Contains( mousePosition ) )
1153 {
1154 std::optional<wxString> nextNumber =
1155 incrementer.Increment( pin.GetNumber(), incParam.Delta, incParam.Index );
1156 if( nextNumber )
1157 {
1158 commit.Modify( &pin );
1159 pin.SetNumber( *nextNumber );
1160 }
1161 found = true;
1162 }
1163
1164 if( !found )
1165 {
1166 bbox = layout.GetPinNameBBox();
1167
1168 if( bbox && bbox->Contains( mousePosition ) )
1169 {
1170 std::optional<wxString> nextName =
1171 incrementer.Increment( pin.GetName(), incParam.Delta, incParam.Index );
1172 if( nextName )
1173 {
1174 commit.Modify( &pin );
1175 pin.SetName( *nextName );
1176 }
1177 found = true;
1178 }
1179 }
1180 break;
1181 }
1182 case SCH_TEXT_T:
1183 {
1184 SCH_TEXT& label = static_cast<SCH_TEXT&>( *item );
1185
1186 std::optional<wxString> newLabel =
1187 incrementer.Increment( label.GetText(), incParam.Delta, incParam.Index );
1188 if( newLabel )
1189 {
1190 commit.Modify( &label, m_frame->GetScreen() );
1191 label.SetText( *newLabel );
1192 }
1193 break;
1194 }
1195 default:
1196 // No increment for other items
1197 break;
1198 }
1199 }
1200
1201 commit.Push( _( "Increment" ) );
1202
1203 return 0;
1204}
1205
1206
1208{
1209 // clang-format off
1217
1225
1231
1237 // clang-format on
1238}
std::optional< BOX2I > OPT_BOX2I
Definition: box2.h:926
static TOOL_ACTION decrementPrimary
Definition: actions.h:89
static TOOL_ACTION paste
Definition: actions.h:73
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
static TOOL_ACTION unselectAll
Definition: actions.h:76
static TOOL_ACTION decrementSecondary
Definition: actions.h:91
static TOOL_ACTION copy
Definition: actions.h:71
static TOOL_ACTION pickerTool
Definition: actions.h:204
static TOOL_ACTION undo
Definition: actions.h:68
static TOOL_ACTION incrementSecondary
Definition: actions.h:90
static TOOL_ACTION duplicate
Definition: actions.h:77
static TOOL_ACTION incrementPrimary
Definition: actions.h:88
static TOOL_ACTION doDelete
Definition: actions.h:78
static TOOL_ACTION redo
Definition: actions.h:69
static TOOL_ACTION deleteTool
Definition: actions.h:79
static TOOL_ACTION increment
Definition: actions.h:87
static TOOL_ACTION cut
Definition: actions.h:70
static TOOL_ACTION copyAsText
Definition: actions.h:72
static TOOL_ACTION refreshPreview
Definition: actions.h:149
static TOOL_ACTION selectAll
Definition: actions.h:75
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
bool Empty() const
Returns status of an item.
Definition: commit.h:144
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.
This class is setup in expectation of its children possibly using Kiway player so DIALOG_SHIM::ShowQu...
void UpdateField(SCH_FIELD *aField)
const wxString & GetText() const
int ShowQuasiModal()
int ShowModal() override
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
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:244
EDA_ITEM_FLAGS GetEditFlags() const
Definition: eda_item.h:133
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:127
const KIID m_Uuid
Definition: eda_item.h:489
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:129
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:104
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
bool IsMoving() const
Definition: eda_item.h:108
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:98
virtual bool IsVisible() const
Definition: eda_text.h:174
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition: eda_text.cpp:408
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition: eda_text.h:187
virtual void SetVisible(bool aVisible)
Definition: eda_text.cpp:377
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition: eda_text.h:190
virtual void SetText(const wxString &aText)
Definition: eda_text.cpp:269
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition: eda_text.cpp:400
static TOOL_ACTION mirrorV
Definition: ee_actions.h:132
static TOOL_ACTION selectionActivate
Activation of the selection tool.
Definition: ee_actions.h:46
static TOOL_ACTION properties
Definition: ee_actions.h:135
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:127
static TOOL_ACTION pinTable
Definition: ee_actions.h:162
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:131
static TOOL_ACTION mirrorH
Definition: ee_actions.h:133
static TOOL_ACTION rotateCW
Definition: ee_actions.h:130
static TOOL_ACTION symbolProperties
Definition: ee_actions.h:161
static TOOL_ACTION setUnitDisplayName
Definition: ee_actions.h:228
static TOOL_ACTION updateSymbolFields
Definition: ee_actions.h:227
static TOOL_ACTION swap
Definition: ee_actions.h:134
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 }, bool aPromoteCellSelections=false)
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:48
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:109
void saveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aType, bool aAppend=false, bool aDirtyConnectivity=true)
Definition: ee_tool_base.h:143
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:200
bool Init() override
Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:64
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:299
Define a library symbol object.
Definition: lib_symbol.h:78
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition: lib_symbol.h:264
wxString GetUnitDisplayName(int aUnit) override
Return the user-defined display name for aUnit for symbols with units.
Definition: lib_symbol.cpp:260
bool IsAlias() const
Definition: lib_symbol.h:195
std::vector< SCH_PIN * > GetAllLibPins() const
Return a list of pin pointers for all units / converts.
Definition: lib_symbol.cpp:854
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition: lib_symbol.h:499
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
Definition: lib_symbol.cpp:783
bool HasUnitDisplayName(int aUnit) override
Return true if the given unit aUnit has a display name defined.
Definition: lib_symbol.cpp:254
wxString GetUnitReference(int aUnit) override
Return an identifier for aUnit for symbols with units.
Definition: lib_symbol.cpp:248
int GetUnitCount() const override
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:276
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
Definition: lib_symbol.cpp:808
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:84
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:73
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:64
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:104
A pin layout helper is a class that manages the layout of the parts of a pin on a schematic symbol:
OPT_BOX2I GetPinNumberBBox()
Get the bounding box of the pin number, if there is one.
OPT_BOX2I GetPinNameBBox()
Get the bounding box of the pin name, if there is one.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:432
virtual void Revert() override
Definition: sch_commit.cpp:510
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
bool IsMandatory() const
Definition: sch_field.cpp:1508
wxString GetFullText(int unit=1) const
Return the text of a field.
Definition: sch_field.cpp:337
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
Definition: sch_field.cpp:1228
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
static std::vector< LIB_SYMBOL * > ParseLibSymbols(std::string &aSymbolText, std::string aSource, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
virtual void SetBodyStyle(int aBodyStyle)
Definition: sch_item.h:231
int GetBodyStyle() const
Definition: sch_item.h:232
virtual void MirrorHorizontally(int aCenter)
Mirror item horizontally about aCenter.
Definition: sch_item.h:343
int GetUnit() const
Definition: sch_item.h:229
virtual void Rotate(const VECTOR2I &aCenter, bool aRotateCCW)
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition: sch_item.h:359
virtual void SetUnit(int aUnit)
Definition: sch_item.h:228
wxString GetClass() const override
Return the class name.
Definition: sch_item.h:176
SCH_ITEM * Duplicate(bool doClone=false) const
Routine to create a new copy of given item.
Definition: sch_item.cpp:131
virtual void MirrorVertically(int aCenter)
Mirror item vertically about aCenter.
Definition: sch_item.h:351
void SetNumber(const wxString &aNumber)
Definition: sch_pin.cpp:520
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition: sch_pin.h:86
const wxString & GetName() const
Definition: sch_pin.cpp:381
PIN_ORIENTATION GetOrientation() const
Definition: sch_pin.cpp:260
VECTOR2I GetPosition() const override
Definition: sch_pin.cpp:252
const wxString & GetNumber() const
Definition: sch_pin.h:117
ELECTRICAL_PINTYPE GetType() const
Definition: sch_pin.cpp:309
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition: sch_shape.cpp:499
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
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.
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
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
ITER end()
Definition: selection.h:75
const std::deque< EDA_ITEM * > GetItems() const
Definition: selection.h:121
ITER begin()
Definition: selection.h:74
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:93
bool IsHover() const
Definition: selection.h:84
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:100
EDA_ITEM * Front() const
Definition: selection.h:172
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:93
int Size() const
Returns the number of selected parts.
Definition: selection.h:116
std::vector< EDA_ITEM * > GetItemsSortedBySelectionOrder() const
Definition: selection.cpp:265
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:180
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
Implement an OUTPUTFORMATTER to a memory buffer.
Definition: richio.h:449
const std::string & GetString()
Definition: richio.h:472
Heuristically increment a string's n'th part from the right.
Definition: increment.h:48
void SetSkipIOSQXZ(bool aSkip)
If a alphabetic part is found, skip the letters I, O, S, Q, X, Z.
Definition: increment.h:54
std::optional< wxString > Increment(const wxString &aStr, int aDelta, size_t aRightIndex) const
Increment the n-th part from the right of the given string.
Definition: increment.cpp:85
SYMBOL_EDITOR_DRAWING_TOOLS.
void SetDrawSpecificBodyStyle(bool aSpecific)
int Undo(const TOOL_EVENT &aEvent)
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void editTextBoxProperties(SCH_ITEM *aItem)
int PinTable(const TOOL_EVENT &aEvent)
int Increment(const TOOL_EVENT &aEvent)
int Copy(const TOOL_EVENT &aEvent)
int CopyAsText(const TOOL_EVENT &aEvent)
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 editTextProperties(SCH_ITEM *aItem)
int Swap(const TOOL_EVENT &aEvent)
void editFieldProperties(SCH_FIELD *aField)
void handlePinDuplication(SCH_PIN *aOldPin, SCH_PIN *aNewPin, int &aSymbolLastPinNumber)
Set up handlers for various events.
void editShapeProperties(SCH_SHAPE *aShape)
int Duplicate(const TOOL_EVENT &aEvent)
int Mirror(const TOOL_EVENT &aEvent)
int InteractiveDelete(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.
void UpdateItem(EDA_ITEM *aItem, bool isAddOrDelete=false, bool aUpdateRtree=false) override
Mark an item for refresh.
bool IsSymbolAlias() const
Return true if aLibId is an alias for the editor screen symbol.
int GetBodyStyle() const
bool m_SyncPinEdit
Set to true to synchronize pins at the same position when editing symbols with multiple units or mult...
bool IsSymbolEditable() const
Test if a symbol is loaded and can be edited.
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.
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:218
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:167
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition: tool_event.h:384
COMMIT * Commit() const
Returns information about difference between current mouse cursor position and the place where draggi...
Definition: tool_event.h:275
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:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
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.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
VECTOR2D GetMousePosition() const
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
bool RunSynchronousAction(const TOOL_ACTION &aAction, COMMIT *aCommit, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:197
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
Definition: clipboard.cpp:31
std::string GetClipboardUTF8()
Return the information currently stored in the system clipboard.
Definition: clipboard.cpp:51
#define _(s)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:536
#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
wxString GetSelectedItemsAsText(const SELECTION &aSel)
@ LAYER_DEVICE
Definition: layer_ids.h:370
void Prettify(std::string &aSource, bool aCompactSave)
PIN_ORIENTATION
The symbol library pin object orientations.
Definition: pin_type.h:78
const std::vector< KICAD_T > swappableItems
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:54
static std::vector< KICAD_T > nonFields
const std::vector< KICAD_T > swappableItems
constexpr GR_TEXT_H_ALIGN_T GetFlippedAlignment(GR_TEXT_H_ALIGN_T aAlign)
Get the reverse alignment: left-right are swapped, others are unchanged.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_TABLE_T
Definition: typeinfo.h:165
@ LIB_SYMBOL_T
Definition: typeinfo.h:148
@ SCH_TABLECELL_T
Definition: typeinfo.h:166
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_SHAPE_T
Definition: typeinfo.h:149
@ SCH_TEXT_T
Definition: typeinfo.h:151
@ SCH_TEXTBOX_T
Definition: typeinfo.h:152
@ SCH_PIN_T
Definition: typeinfo.h:153
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition: vector2d.h:640