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 The 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>
33#include <clipboard.h>
34#include <sch_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#include <trace_helpers.h>
54
56 SCH_TOOL_BASE( "eeschema.SymbolEditTool" )
57{
58}
59
60
61const std::vector<KICAD_T> SYMBOL_EDITOR_EDIT_TOOL::SwappableItems = {
62 LIB_SYMBOL_T, // Allows swapping the anchor
68};
69
70
72{
74
77
78 wxASSERT_MSG( drawingTools, "eeschema.SymbolDrawing tool is not available" );
79
80 auto haveSymbolCondition =
81 [&]( const SELECTION& sel )
82 {
83 return m_isSymbolEditor && m_frame->GetCurSymbol();
84 };
85
86 auto canEdit =
87 [&]( const SELECTION& sel )
88 {
89 if( !m_frame->IsSymbolEditable() )
90 return false;
91
92 if( m_frame->IsSymbolAlias() )
93 {
94 for( EDA_ITEM* item : sel )
95 {
96 if( item->Type() != SCH_FIELD_T )
97 return false;
98 }
99 }
100
101 return true;
102 };
103
104 auto swapSelectionCondition =
106
107 const auto canCopyText = SCH_CONDITIONS::OnlyTypes( {
111 SCH_PIN_T,
114 } );
115
116 const auto canConvertStackedPins =
117 [&]( const SELECTION& sel )
118 {
119 // If multiple pins are selected, check they are all at same location
120 if( sel.Size() >= 2 )
121 {
122 std::vector<SCH_PIN*> pins;
123 for( EDA_ITEM* item : sel )
124 {
125 if( item->Type() != SCH_PIN_T )
126 return false;
127 pins.push_back( static_cast<SCH_PIN*>( item ) );
128 }
129
130 // Check that all pins are at the same location
131 VECTOR2I pos = pins[0]->GetPosition();
132 for( size_t i = 1; i < pins.size(); ++i )
133 {
134 if( pins[i]->GetPosition() != pos )
135 return false;
136 }
137 return true;
138 }
139
140 // If single pin is selected, check if there are other pins at same location
141 if( sel.Size() == 1 && sel.Front()->Type() == SCH_PIN_T )
142 {
143 SCH_PIN* selectedPin = static_cast<SCH_PIN*>( sel.Front() );
144 VECTOR2I pos = selectedPin->GetPosition();
145
146 // Get the symbol and check for other pins at same location
147 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
148 if( !symbol )
149 return false;
150
151 int coLocatedCount = 0;
152
153 for( SCH_PIN* pin : symbol->GetPins() )
154 {
155 if( pin->GetPosition() == pos )
156 {
157 coLocatedCount++;
158
159 if( coLocatedCount >= 2 )
160 return true;
161 }
162 }
163 }
164
165 return false;
166 };
167
168 const auto canExplodeStackedPin =
169 [&]( const SELECTION& sel )
170 {
171 if( sel.Size() != 1 || sel.Front()->Type() != SCH_PIN_T )
172 return false;
173
174 SCH_PIN* pin = static_cast<SCH_PIN*>( sel.Front() );
175 bool isValid;
176 std::vector<wxString> stackedNumbers = pin->GetStackedPinNumbers( &isValid );
177 return isValid && stackedNumbers.size() > 1;
178 };
179
180 // clang-format off
181 // Add edit actions to the move tool menu
182 if( moveTool )
183 {
184 CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
185
186 moveMenu.AddSeparator( 200 );
187 moveMenu.AddItem( SCH_ACTIONS::rotateCCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
188 moveMenu.AddItem( SCH_ACTIONS::rotateCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
189 moveMenu.AddItem( SCH_ACTIONS::mirrorV, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
190 moveMenu.AddItem( SCH_ACTIONS::mirrorH, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
191
192 moveMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
193 moveMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
194
195 moveMenu.AddSeparator( 300 );
198 moveMenu.AddItem( ACTIONS::copyAsText, canCopyText && SCH_CONDITIONS::IdleSelection, 300 );
199 moveMenu.AddItem( ACTIONS::duplicate, canEdit && SCH_CONDITIONS::NotEmpty, 300 );
200 moveMenu.AddItem( ACTIONS::doDelete, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
201
202 moveMenu.AddSeparator( 400 );
203 moveMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
204 moveMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
205 }
206
207 // Add editing actions to the drawing tool menu
208 CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
209
210 drawMenu.AddSeparator( 200 );
215
216 drawMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
217
218 // Add editing actions to the selection tool menu
219 CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
220
221 selToolMenu.AddItem( SCH_ACTIONS::rotateCCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
222 selToolMenu.AddItem( SCH_ACTIONS::rotateCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
223 selToolMenu.AddItem( SCH_ACTIONS::mirrorV, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
224 selToolMenu.AddItem( SCH_ACTIONS::mirrorH, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
225
226 selToolMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
227 selToolMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
228
229 selToolMenu.AddSeparator( 250 );
230 selToolMenu.AddItem( SCH_ACTIONS::convertStackedPins, canEdit && canConvertStackedPins, 250 );
231 selToolMenu.AddItem( SCH_ACTIONS::explodeStackedPin, canEdit && canExplodeStackedPin, 250 );
232
233 selToolMenu.AddSeparator( 300 );
236 selToolMenu.AddItem( ACTIONS::copyAsText, canCopyText && SCH_CONDITIONS::IdleSelection, 300 );
237 selToolMenu.AddItem( ACTIONS::paste, canEdit && SCH_CONDITIONS::Idle, 300 );
238 selToolMenu.AddItem( ACTIONS::duplicate, canEdit && SCH_CONDITIONS::NotEmpty, 300 );
239 selToolMenu.AddItem( ACTIONS::doDelete, canEdit && SCH_CONDITIONS::NotEmpty, 300 );
240
241 selToolMenu.AddSeparator( 400 );
242 selToolMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
243 selToolMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
244 // clang-format on
245
246 return true;
247}
248
249
251{
252 SCH_SELECTION& selection = m_selectionTool->RequestSelection();
253
254 if( selection.GetSize() == 0 )
255 return 0;
256
257 VECTOR2I rotPoint;
258 bool ccw = ( aEvent.Matches( SCH_ACTIONS::rotateCCW.MakeEvent() ) );
259 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
260 SCH_COMMIT localCommit( m_toolMgr );
261 SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() );
262
263 if( !commit )
264 commit = &localCommit;
265
266 if( !item->IsMoving() )
267 commit->Modify( m_frame->GetCurSymbol(), m_frame->GetScreen(), RECURSE_MODE::RECURSE );
268
269 if( selection.GetSize() == 1 )
270 rotPoint = item->GetPosition();
271 else
272 rotPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
273
274 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
275 {
276 item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
277 item->Rotate( rotPoint, ccw );
278 m_frame->UpdateItem( item, false, true );
279 }
280
281 if( item->IsMoving() )
282 {
284 }
285 else
286 {
287 if( selection.IsHover() )
289
290 if( !localCommit.Empty() )
291 localCommit.Push( _( "Rotate" ) );
292 }
293
294 return 0;
295}
296
297
299{
300 SCH_SELECTION& selection = m_selectionTool->RequestSelection();
301
302 if( selection.GetSize() == 0 )
303 return 0;
304
305 VECTOR2I mirrorPoint;
306 bool xAxis = ( aEvent.Matches( SCH_ACTIONS::mirrorV.MakeEvent() ) );
307 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
308
309 if( !item->IsMoving() )
311
312 if( selection.GetSize() == 1 )
313 {
314 mirrorPoint = item->GetPosition();
315
316 switch( item->Type() )
317 {
318 case SCH_FIELD_T:
319 {
320 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
321
322 if( xAxis )
324 else
326
327 break;
328 }
329
330 default:
331 if( xAxis )
332 item->MirrorVertically( mirrorPoint.y );
333 else
334 item->MirrorHorizontally( mirrorPoint.x );
335
336 break;
337 }
338
339
340 m_frame->UpdateItem( item, false, true );
341 }
342 else
343 {
344 mirrorPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
345
346 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
347 {
348 item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
349
350 if( xAxis )
351 item->MirrorVertically( mirrorPoint.y );
352 else
353 item->MirrorHorizontally( mirrorPoint.x );
354
355 m_frame->UpdateItem( item, false, true );
356 }
357 }
358
359 if( item->IsMoving() )
360 {
362 }
363 else
364 {
365 if( selection.IsHover() )
367
368 m_frame->OnModify();
369 }
370
371 return 0;
372}
374{
375 SCH_SELECTION& selection = m_selectionTool->RequestSelection( SwappableItems );
376 std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
377
378 if( selection.Size() < 2 )
379 return 0;
380
381 EDA_ITEM* front = selection.Front();
382 bool isMoving = front->IsMoving();
383
384 // Save copy for undo if not in edit (edit command already handle the save copy)
385 if( front->GetEditFlags() == 0 )
387
388 for( size_t i = 0; i < sorted.size() - 1; i++ )
389 {
390 SCH_ITEM* a = static_cast<SCH_ITEM*>( sorted[i] );
391 SCH_ITEM* b = static_cast<SCH_ITEM*>( sorted[( i + 1 ) % sorted.size()] );
392
393 VECTOR2I aPos = a->GetPosition(), bPos = b->GetPosition();
394 std::swap( aPos, bPos );
395
396 a->SetPosition( aPos );
397 b->SetPosition( bPos );
398
399 // Special case some common swaps
400 if( a->Type() == b->Type() )
401 {
402 switch( a->Type() )
403 {
404 case SCH_PIN_T:
405 {
406 SCH_PIN* aPin = static_cast<SCH_PIN*>( a );
407 SCH_PIN* bBpin = static_cast<SCH_PIN*>( b );
408
409 PIN_ORIENTATION aOrient = aPin->GetOrientation();
410 PIN_ORIENTATION bOrient = bBpin->GetOrientation();
411
412 aPin->SetOrientation( bOrient );
413 bBpin->SetOrientation( aOrient );
414
415 break;
416 }
417 default: break;
418 }
419 }
420
421 m_frame->UpdateItem( a, false, true );
422 m_frame->UpdateItem( b, false, true );
423 }
424
425 // Update R-Tree for modified items
426 for( EDA_ITEM* selected : selection )
427 updateItem( selected, true );
428
429 if( isMoving )
430 {
431 m_toolMgr->PostAction( ACTIONS::refreshPreview );
432 }
433 else
434 {
435 if( selection.IsHover() )
437
438 m_frame->OnModify();
439 }
440
441 return 0;
442}
443
444
445static std::vector<KICAD_T> nonFields =
446{
452};
453
454
456{
457 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
458 std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection().GetItems();
459 SCH_COMMIT commit( m_frame );
460
461 if( items.empty() )
462 return 0;
463
464 // Don't leave a freed pointer in the selection
466
467 commit.Modify( symbol, m_frame->GetScreen() );
468
469 std::set<SCH_ITEM*> toDelete;
470 int fieldsHidden = 0;
471 int fieldsAlreadyHidden = 0;
472
473 for( EDA_ITEM* item : items )
474 {
475 if( item->Type() == SCH_PIN_T )
476 {
477 SCH_PIN* curr_pin = static_cast<SCH_PIN*>( item );
478 VECTOR2I pos = curr_pin->GetPosition();
479
480 toDelete.insert( curr_pin );
481
482 // when pin editing is synchronized, pins in the same position, with the same name
483 // in different units are also removed. But only one pin per unit (matching)
484 if( m_frame->SynchronizePins() )
485 {
486 std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
487
488 got_unit[curr_pin->GetUnit()] = true;
489
490 for( SCH_PIN* pin : symbol->GetPins() )
491 {
492 if( got_unit[pin->GetUnit()] )
493 continue;
494
495 if( pin->GetPosition() != pos )
496 continue;
497
498 if( pin->GetBodyStyle() != curr_pin->GetBodyStyle() )
499 continue;
500
501 if( pin->GetType() != curr_pin->GetType() )
502 continue;
503
504 if( pin->GetName() != curr_pin->GetName() )
505 continue;
506
507 toDelete.insert( pin );
508 got_unit[pin->GetUnit()] = true;
509 }
510 }
511 }
512 else if( item->Type() == SCH_FIELD_T )
513 {
514 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
515
516 // Hide "deleted" fields
517 if( field->IsVisible() )
518 {
519 field->SetVisible( false );
520 fieldsHidden++;
521 }
522 else
523 {
524 fieldsAlreadyHidden++;
525 }
526 }
527 else if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
528 {
529 toDelete.insert( schItem );
530 }
531 }
532
533 for( SCH_ITEM* item : toDelete )
534 symbol->RemoveDrawItem( item );
535
536 if( toDelete.size() == 0 )
537 {
538 if( fieldsHidden == 1 )
539 commit.Push( _( "Hide Field" ) );
540 else if( fieldsHidden > 1 )
541 commit.Push( _( "Hide Fields" ) );
542 else if( fieldsAlreadyHidden > 0 )
543 m_frame->ShowInfoBarError( _( "Use the Symbol Properties dialog to remove fields." ) );
544 }
545 else
546 {
547 commit.Push( _( "Delete" ) );
548 }
549
550 m_frame->RebuildView();
551 return 0;
552}
553
554
556{
557 SCH_SELECTION& selection = m_selectionTool->RequestSelection();
558
559 if( selection.Empty() || aEvent.IsAction( &SCH_ACTIONS::symbolProperties ) )
560 {
561 if( m_frame->GetCurSymbol() )
563 }
564 else if( selection.Size() == 1 )
565 {
566 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
567
568 // Save copy for undo if not in edit (edit command already handle the save copy)
569 if( item->GetEditFlags() == 0 )
571
572 switch( item->Type() )
573 {
574 case SCH_PIN_T:
575 {
576 SCH_PIN& pin = static_cast<SCH_PIN&>( *item );
577
578 // Mouse, not cursor, as grid points may well not be under any text
579 const VECTOR2I& mousePos = m_toolMgr->GetMousePosition();
580 PIN_LAYOUT_CACHE& layout = pin.GetLayoutCache();
581
582 bool mouseOverNumber = false;
583 if( OPT_BOX2I numberBox = layout.GetPinNumberBBox() )
584 {
585 mouseOverNumber = numberBox->Contains( mousePos );
586 }
587
588 if( SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() )
589 pinTool->EditPinProperties( &pin, mouseOverNumber );
590
591 break;
592 }
593 case SCH_SHAPE_T:
594 editShapeProperties( static_cast<SCH_SHAPE*>( item ) );
595 break;
596
597 case SCH_TEXT_T:
598 editTextProperties( item );
599 break;
600
601 case SCH_TEXTBOX_T:
602 editTextBoxProperties( item );
603 break;
604
605 case SCH_FIELD_T:
606 editFieldProperties( static_cast<SCH_FIELD*>( item ) );
607 break;
608
609 default:
610 wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
611 break;
612 }
613 }
614
615 if( selection.IsHover() )
617
618 return 0;
619}
620
621
623{
624 DIALOG_SHAPE_PROPERTIES dlg( m_frame, aShape );
625
626 if( dlg.ShowModal() != wxID_OK )
627 return;
628
629 updateItem( aShape, true );
630 m_frame->GetCanvas()->Refresh();
631 m_frame->OnModify();
632
635 drawingTools->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
636
637 std::vector<MSG_PANEL_ITEM> items;
638 aShape->GetMsgPanelInfo( m_frame, items );
639 m_frame->SetMsgPanel( items );
640}
641
642
644{
645 if ( aItem->Type() != SCH_TEXT_T )
646 return;
647
648 DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_TEXT*>( aItem ) );
649
650 if( dlg.ShowModal() != wxID_OK )
651 return;
652
653 updateItem( aItem, true );
654 m_frame->GetCanvas()->Refresh();
655 m_frame->OnModify( );
656}
657
658
660{
661 if ( aItem->Type() != SCH_TEXTBOX_T )
662 return;
663
664 DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_TEXTBOX*>( aItem ) );
665
666 if( dlg.ShowModal() != wxID_OK )
667 return;
668
669 updateItem( aItem, true );
670 m_frame->GetCanvas()->Refresh();
671 m_frame->OnModify( );
672}
673
674
676{
677 if( aField == nullptr )
678 return;
679
680 wxString caption;
681
682 if( aField->IsMandatory() )
683 caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
684 else
685 caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
686
687 DIALOG_FIELD_PROPERTIES dlg( m_frame, caption, aField );
688
689 // The dialog may invoke a kiway player for footprint fields
690 // so we must use a quasimodal dialog.
691 if( dlg.ShowQuasiModal() != wxID_OK )
692 return;
693
694 SCH_COMMIT commit( m_toolMgr );
695 commit.Modify( aField, m_frame->GetScreen() );
696
697 dlg.UpdateField( aField );
698
699 commit.Push( caption );
700
701 m_frame->GetCanvas()->Refresh();
702 m_frame->UpdateSymbolMsgPanelInfo();
703}
704
705
707{
708 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
709 bool partLocked = symbol->UnitsLocked();
710
713
715
716 // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
717 // frame. Therefore this dialog as a modal frame parent, MUST be run under
718 // quasimodal mode for the quasimodal frame support to work. So don't use
719 // the QUASIMODAL macros here.
720 if( dlg.ShowQuasiModal() != wxID_OK )
721 return;
722
723 m_frame->RebuildSymbolUnitAndBodyStyleLists();
724 m_frame->OnModify();
725
726 // if m_UnitSelectionLocked has changed, set some edit options or defaults
727 // to the best value
728 if( partLocked != symbol->UnitsLocked() )
729 {
731
732 // Enable synchronized pin edit mode for symbols with interchangeable units
733 m_frame->m_SyncPinEdit = !symbol->UnitsLocked();
734
735 // also set default edit options to the better value
736 // Usually if units are locked, graphic items are specific to each unit
737 // and if units are interchangeable, graphic items are common to units
738 tools->SetDrawSpecificUnit( symbol->UnitsLocked() );
739 }
740}
741
742
744{
745 SCH_COMMIT commit( m_frame );
746 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
747
748 if( !symbol )
749 return 0;
750
751 commit.Modify( symbol, m_frame->GetScreen() );
752
753 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
754 wxCHECK( selTool, -1 );
755
756 std::vector<SCH_PIN*> selectedPins;
757
758 SCH_SELECTION& selection = selTool->GetSelection();
759
760 for( EDA_ITEM* item : selection )
761 {
762 if( item->Type() == SCH_PIN_T )
763 {
764 SCH_PIN* pinItem = static_cast<SCH_PIN*>( item );
765 selectedPins.push_back( pinItem );
766 }
767 }
768
769 // And now clear the selection so if we change the pins we don't have dangling pointers
770 // in the selection.
772
773 DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol, selectedPins );
774
775 if( dlg.ShowModal() == wxID_CANCEL )
776 return -1;
777
778 commit.Push( _( "Edit Pins" ) );
779 m_frame->RebuildView();
780
781 return 0;
782}
783
784
786{
787 SCH_COMMIT commit( m_frame );
788 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
789
790 if( !symbol )
791 return 0;
792
793 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
794 wxCHECK( selTool, -1 );
795
796 SCH_SELECTION& selection = selTool->GetSelection();
797
798 // Collect pins to convert - accept pins with any number format
799 std::vector<SCH_PIN*> pinsToConvert;
800
801 if( selection.Size() == 1 && selection.Front()->Type() == SCH_PIN_T )
802 {
803 // Single pin selected - find all pins at the same location
804 SCH_PIN* selectedPin = static_cast<SCH_PIN*>( selection.Front() );
805 VECTOR2I pos = selectedPin->GetPosition();
806
807 for( SCH_PIN* pin : symbol->GetPins() )
808 {
809 if( pin->GetPosition() == pos )
810 pinsToConvert.push_back( pin );
811 }
812 }
813 else
814 {
815 // Multiple pins selected - use them directly, accepting any pin numbers
816 for( EDA_ITEM* item : selection )
817 {
818 if( item->Type() == SCH_PIN_T )
819 pinsToConvert.push_back( static_cast<SCH_PIN*>( item ) );
820 }
821 }
822
823 if( pinsToConvert.size() < 2 )
824 {
825 m_frame->ShowInfoBarError( _( "At least two pins are needed to convert to stacked pins" ) );
826 return 0;
827 }
828
829 // Check that all pins are at the same location
830 VECTOR2I pos = pinsToConvert[0]->GetPosition();
831 for( size_t i = 1; i < pinsToConvert.size(); ++i )
832 {
833 if( pinsToConvert[i]->GetPosition() != pos )
834 {
835 m_frame->ShowInfoBarError( _( "All pins must be at the same location" ) );
836 return 0;
837 }
838 }
839
840 commit.Modify( symbol, m_frame->GetScreen() );
841
842 // Clear selection before modifying pins, like the Delete command does
844
845 // Sort pins for consistent ordering - handle arbitrary pin number formats
846 std::sort( pinsToConvert.begin(), pinsToConvert.end(),
847 []( SCH_PIN* a, SCH_PIN* b )
848 {
849 wxString numA = a->GetNumber();
850 wxString numB = b->GetNumber();
851
852 // Try to convert to integers for proper numeric sorting
853 long longA, longB;
854 bool aIsNumeric = numA.ToLong( &longA );
855 bool bIsNumeric = numB.ToLong( &longB );
856
857 // Both are purely numeric - sort numerically
858 if( aIsNumeric && bIsNumeric )
859 return longA < longB;
860
861 // Mixed numeric/non-numeric - numeric pins come first
862 if( aIsNumeric && !bIsNumeric )
863 return true;
864 if( !aIsNumeric && bIsNumeric )
865 return false;
866
867 // Both non-numeric or mixed alphanumeric - use lexicographic sorting
868 return numA < numB;
869 });
870
871 // Build the stacked notation string with range collapsing
872 wxString stackedNotation = wxT("[");
873
874 // Helper function to collapse consecutive numbers into ranges - handles arbitrary pin formats
875 auto collapseRanges = [&]() -> wxString
876 {
877 if( pinsToConvert.empty() )
878 return wxT("");
879
880 wxString result;
881
882 // Group pins by their alphanumeric prefix for range collapsing
883 std::map<wxString, std::vector<long>> prefixGroups;
884 std::vector<wxString> nonNumericPins;
885
886 // Parse each pin number to separate prefix from numeric suffix
887 for( SCH_PIN* pin : pinsToConvert )
888 {
889 wxString pinNumber = pin->GetNumber();
890
891 // Skip empty pin numbers (shouldn't happen, but be defensive)
892 if( pinNumber.IsEmpty() )
893 {
894 nonNumericPins.push_back( wxT("(empty)") );
895 continue;
896 }
897
898 wxString prefix;
899 wxString numericPart;
900
901 // Find where numeric part starts (scan from end)
902 size_t numStart = pinNumber.length();
903 for( int i = pinNumber.length() - 1; i >= 0; i-- )
904 {
905 if( !wxIsdigit( pinNumber[i] ) )
906 {
907 numStart = i + 1;
908 break;
909 }
910 if( i == 0 ) // All digits
911 numStart = 0;
912 }
913
914 if( numStart < pinNumber.length() ) // Has numeric suffix
915 {
916 prefix = pinNumber.Left( numStart );
917 numericPart = pinNumber.Mid( numStart );
918
919 long numValue;
920 if( numericPart.ToLong( &numValue ) && numValue >= 0 ) // Valid non-negative number
921 {
922 prefixGroups[prefix].push_back( numValue );
923 }
924 else
925 {
926 // Numeric part couldn't be parsed or is negative - treat as non-numeric
927 nonNumericPins.push_back( pinNumber );
928 }
929 }
930 else // No numeric suffix - consolidate as individual value
931 {
932 nonNumericPins.push_back( pinNumber );
933 }
934 }
935
936 // Process each prefix group
937 for( auto& [prefix, numbers] : prefixGroups )
938 {
939 if( !result.IsEmpty() )
940 result += wxT(",");
941
942 // Sort numeric values for this prefix
943 std::sort( numbers.begin(), numbers.end() );
944
945 // Collapse consecutive ranges within this prefix
946 size_t i = 0;
947 while( i < numbers.size() )
948 {
949 if( i > 0 ) // Not first number in this prefix group
950 result += wxT(",");
951
952 long start = numbers[i];
953 long end = start;
954
955 // Find the end of consecutive sequence
956 while( i + 1 < numbers.size() && numbers[i + 1] == numbers[i] + 1 )
957 {
958 i++;
959 end = numbers[i];
960 }
961
962 // Add range or single number with prefix
963 if( end > start + 1 ) // Range of 3+ numbers
964 result += wxString::Format( wxT("%s%ld-%s%ld"), prefix, start, prefix, end );
965 else if( end == start + 1 ) // Two consecutive numbers
966 result += wxString::Format( wxT("%s%ld,%s%ld"), prefix, start, prefix, end );
967 else // Single number
968 result += wxString::Format( wxT("%s%ld"), prefix, start );
969
970 i++;
971 }
972 }
973
974 // Add non-numeric pin numbers as individual comma-separated values
975 for( const wxString& nonNum : nonNumericPins )
976 {
977 if( !result.IsEmpty() )
978 result += wxT(",");
979 result += nonNum;
980 }
981
982 return result;
983 };
984
985 stackedNotation += collapseRanges();
986 stackedNotation += wxT("]");
987
988 // Keep the first pin and give it the stacked notation
989 SCH_PIN* masterPin = pinsToConvert[0];
990 masterPin->SetNumber( stackedNotation );
991
992 // Log information about pins being removed before we remove them
993 wxLogTrace( traceStackedPins,
994 wxString::Format( "Converting %zu pins to stacked notation '%s'",
995 pinsToConvert.size(), stackedNotation ) );
996
997 // Remove all other pins from the symbol that were consolidated into the stacked notation
998 // Collect pins to remove first, then remove them all at once like the Delete command
999 std::vector<SCH_PIN*> pinsToRemove;
1000 for( size_t i = 1; i < pinsToConvert.size(); ++i )
1001 {
1002 SCH_PIN* pinToRemove = pinsToConvert[i];
1003
1004 // Log the pin before removing it
1005 wxLogTrace( traceStackedPins,
1006 wxString::Format( "Will remove pin '%s' at position (%d, %d)",
1007 pinToRemove->GetNumber(),
1008 pinToRemove->GetPosition().x,
1009 pinToRemove->GetPosition().y ) );
1010
1011 pinsToRemove.push_back( pinToRemove );
1012 }
1013
1014 // Remove all pins at once, like the Delete command does
1015 for( SCH_PIN* pin : pinsToRemove )
1016 {
1017 symbol->RemoveDrawItem( pin );
1018 }
1019
1020 commit.Push( wxString::Format( _( "Convert %zu Stacked Pins to '%s'" ),
1021 pinsToConvert.size(), stackedNotation ) );
1022 m_frame->RebuildView();
1023 return 0;
1024}
1025
1026
1028{
1029 SCH_COMMIT commit( m_frame );
1030 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1031
1032 if( !symbol )
1033 return 0;
1034
1035 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1036 wxCHECK( selTool, -1 );
1037
1038 SCH_SELECTION& selection = selTool->GetSelection();
1039
1040 if( selection.GetSize() != 1 || selection.Front()->Type() != SCH_PIN_T )
1041 {
1042 m_frame->ShowInfoBarError( _( "Select a single pin with stacked notation to explode" ) );
1043 return 0;
1044 }
1045
1046 SCH_PIN* pin = static_cast<SCH_PIN*>( selection.Front() );
1047
1048 // Check if the pin has stacked notation
1049 bool isValid;
1050 std::vector<wxString> stackedNumbers = pin->GetStackedPinNumbers( &isValid );
1051
1052 if( !isValid || stackedNumbers.size() <= 1 )
1053 {
1054 m_frame->ShowInfoBarError( _( "Selected pin does not have valid stacked notation" ) );
1055 return 0;
1056 }
1057
1058 commit.Modify( symbol, m_frame->GetScreen() );
1059
1060 // Clear selection before modifying pins
1061 m_toolMgr->RunAction( ACTIONS::selectionClear );
1062
1063 // Sort the stacked numbers to find the smallest one
1064 std::sort( stackedNumbers.begin(), stackedNumbers.end(),
1065 []( const wxString& a, const wxString& b )
1066 {
1067 // Try to convert to integers for proper numeric sorting
1068 long numA, numB;
1069 if( a.ToLong( &numA ) && b.ToLong( &numB ) )
1070 return numA < numB;
1071
1072 // Fall back to string comparison if not numeric
1073 return a < b;
1074 });
1075
1076 // Change the original pin to use the first (smallest) number and make it visible
1077 pin->SetNumber( stackedNumbers[0] );
1078 pin->SetVisible( true );
1079
1080 // Create additional pins for the remaining numbers and make them invisible
1081 for( size_t i = 1; i < stackedNumbers.size(); ++i )
1082 {
1083 SCH_PIN* newPin = new SCH_PIN( symbol );
1084
1085 // Copy all properties from the original pin
1086 newPin->SetPosition( pin->GetPosition() );
1087 newPin->SetOrientation( pin->GetOrientation() );
1088 newPin->SetShape( pin->GetShape() );
1089 newPin->SetLength( pin->GetLength() );
1090 newPin->SetType( pin->GetType() );
1091 newPin->SetName( pin->GetName() );
1092 newPin->SetNumber( stackedNumbers[i] );
1093 newPin->SetNameTextSize( pin->GetNameTextSize() );
1094 newPin->SetNumberTextSize( pin->GetNumberTextSize() );
1095 newPin->SetUnit( pin->GetUnit() );
1096 newPin->SetBodyStyle( pin->GetBodyStyle() );
1097 newPin->SetVisible( false ); // Make all other pins invisible
1098
1099 // Add the new pin to the symbol
1100 symbol->AddDrawItem( newPin );
1101 }
1102
1103 commit.Push( _( "Explode Stacked Pin" ) );
1104 m_frame->RebuildView();
1105 return 0;
1106}
1107
1108
1110{
1111 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1112
1113 if( !symbol )
1114 return 0;
1115
1116 if( !symbol->IsDerived() )
1117 {
1118 m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
1119 }
1120 else
1121 {
1122 DIALOG_UPDATE_SYMBOL_FIELDS dlg( m_frame, symbol );
1123
1124 if( dlg.ShowModal() == wxID_CANCEL )
1125 return -1;
1126 }
1127
1128 return 0;
1129}
1130
1131
1133{
1134 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1135
1136 // Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
1137 // it just clears the SELECTION's reference to them.
1138 selTool->GetSelection().Clear();
1139 {
1140 m_frame->GetSymbolFromUndoList();
1141 }
1142 selTool->RebuildSelection();
1143
1144 return 0;
1145}
1146
1147
1149{
1150 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1151
1152 // Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
1153 // it just clears the SELECTION's reference to them.
1154 selTool->GetSelection().Clear();
1155 {
1156 m_frame->GetSymbolFromRedoList();
1157 }
1158 selTool->RebuildSelection();
1159
1160 return 0;
1161}
1162
1163
1165{
1166 int retVal = Copy( aEvent );
1167
1168 if( retVal == 0 )
1169 retVal = DoDelete( aEvent );
1170
1171 return retVal;
1172}
1173
1174
1176{
1177 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1178 SCH_SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
1179
1180 if( !symbol || !selection.GetSize() )
1181 return 0;
1182
1183 for( SCH_ITEM& item : symbol->GetDrawItems() )
1184 {
1185 if( item.Type() == SCH_FIELD_T )
1186 continue;
1187
1188 wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
1189
1190 if( !item.IsSelected() )
1191 item.SetFlags( STRUCT_DELETED );
1192 }
1193
1194 LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
1195
1196 STRING_FORMATTER formatter;
1197 SCH_IO_KICAD_SEXPR::FormatLibSymbol( partCopy, formatter );
1198
1199 delete partCopy;
1200
1201 for( SCH_ITEM& item : symbol->GetDrawItems() )
1202 item.ClearFlags( STRUCT_DELETED );
1203
1204 std::string prettyData = formatter.GetString();
1205 KICAD_FORMAT::Prettify( prettyData, KICAD_FORMAT::FORMAT_MODE::COMPACT_TEXT_PROPERTIES );
1206
1207 if( SaveClipboard( prettyData ) )
1208 return 0;
1209 else
1210 return -1;
1211}
1212
1213
1215{
1216 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1217 SCH_SELECTION& selection = selTool->RequestSelection();
1218
1219 if( selection.Empty() )
1220 return 0;
1221
1222 wxString itemsAsText = GetSelectedItemsAsText( selection );
1223
1224 if( selection.IsHover() )
1225 m_toolMgr->RunAction( ACTIONS::selectionClear );
1226
1227 return SaveClipboard( itemsAsText.ToStdString() );
1228}
1229
1230
1232{
1233 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1234 LIB_SYMBOL* newPart = nullptr;
1235
1236 if( !symbol || symbol->IsDerived() )
1237 return 0;
1238
1239 std::string clipboardData = GetClipboardUTF8();
1240
1241 try
1242 {
1243 std::vector<LIB_SYMBOL*> newParts = SCH_IO_KICAD_SEXPR::ParseLibSymbols( clipboardData, "Clipboard" );
1244
1245 if( newParts.empty() || !newParts[0] )
1246 return -1;
1247
1248 newPart = newParts[0];
1249 }
1250 catch( IO_ERROR& )
1251 {
1252 // If it's not a symbol then paste as text
1253 newPart = new LIB_SYMBOL( "dummy_part" );
1254
1255 wxString pasteText( clipboardData );
1256
1257 // Limit of 5000 is totally arbitrary. Without a limit, pasting a bitmap image from
1258 // eeschema makes KiCad appear to hang.
1259 if( pasteText.Length() > 5000 )
1260 pasteText = pasteText.Left( 5000 ) + wxT( "..." );
1261
1262 SCH_TEXT* newText = new SCH_TEXT( { 0, 0 }, pasteText, LAYER_DEVICE );
1263 newPart->AddDrawItem( newText );
1264 }
1265
1266 SCH_COMMIT commit( m_toolMgr );
1267
1268 commit.Modify( symbol, m_frame->GetScreen() );
1269 m_selectionTool->ClearSelection();
1270
1271 for( SCH_ITEM& item : symbol->GetDrawItems() )
1272 item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
1273
1274 for( SCH_ITEM& item : newPart->GetDrawItems() )
1275 {
1276 if( item.Type() == SCH_FIELD_T )
1277 continue;
1278
1279 SCH_ITEM* newItem = item.Duplicate( true, &commit );
1280 newItem->SetParent( symbol );
1281 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
1282
1283 newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
1284 newItem->SetBodyStyle( newItem->GetBodyStyle() ? m_frame->GetBodyStyle() : 0 );
1285
1286 symbol->AddDrawItem( newItem );
1287 getView()->Add( newItem );
1288 }
1289
1290 delete newPart;
1291
1292 m_selectionTool->RebuildSelection();
1293
1294 SCH_SELECTION& selection = m_selectionTool->GetSelection();
1295
1296 if( !selection.Empty() )
1297 {
1298 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
1299
1300 if( m_toolMgr->RunSynchronousAction( SCH_ACTIONS::move, &commit ) )
1301 commit.Push( _( "Paste" ) );
1302 else
1303 commit.Revert();
1304 }
1305
1306 return 0;
1307}
1308
1309
1311{
1312 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1313 SCH_SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
1314 SCH_COMMIT commit( m_toolMgr );
1315
1316 if( selection.GetSize() == 0 )
1317 return 0;
1318
1319 commit.Modify( symbol, m_frame->GetScreen() );
1320
1321 std::vector<EDA_ITEM*> oldItems;
1322 std::vector<EDA_ITEM*> newItems;
1323
1324 std::copy( selection.begin(), selection.end(), std::back_inserter( oldItems ) );
1325 std::sort( oldItems.begin(), oldItems.end(), []( EDA_ITEM* a, EDA_ITEM* b )
1326 {
1327 int cmp;
1328
1329 if( a->Type() != b->Type() )
1330 return a->Type() < b->Type();
1331
1332 // Create the new pins in the same order as the old pins
1333 if( a->Type() == SCH_PIN_T )
1334 {
1335 const wxString& aNum = static_cast<SCH_PIN*>( a )->GetNumber();
1336 const wxString& bNum = static_cast<SCH_PIN*>( b )->GetNumber();
1337
1338 cmp = StrNumCmp( aNum, bNum );
1339
1340 // If the pin numbers are not numeric, then just number them by their position
1341 // on the screen.
1342 if( aNum.IsNumber() && bNum.IsNumber() && cmp != 0 )
1343 return cmp < 0;
1344 }
1345
1347
1348 if( cmp != 0 )
1349 return cmp < 0;
1350
1351 return a->m_Uuid < b->m_Uuid;
1352 } );
1353
1354 for( EDA_ITEM* item : oldItems )
1355 {
1356 SCH_ITEM* oldItem = static_cast<SCH_ITEM*>( item );
1357 SCH_ITEM* newItem = oldItem->Duplicate( true, &commit );
1358
1359 if( newItem->Type() == SCH_PIN_T )
1360 {
1361 SCH_PIN* newPin = static_cast<SCH_PIN*>( newItem );
1362
1363 if( !newPin->GetNumber().IsEmpty() )
1364 newPin->SetNumber( wxString::Format( wxT( "%i" ), symbol->GetMaxPinNumber() + 1 ) );
1365 }
1366
1367 oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
1368 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
1369 newItem->SetParent( symbol );
1370 newItems.push_back( newItem );
1371
1372 symbol->AddDrawItem( newItem );
1373 getView()->Add( newItem );
1374 }
1375
1376 m_toolMgr->RunAction( ACTIONS::selectionClear );
1377 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &newItems );
1378
1379 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
1380
1381 if( m_toolMgr->RunSynchronousAction( SCH_ACTIONS::move, &commit ) )
1382 commit.Push( _( "Duplicate" ) );
1383 else
1384 commit.Revert();
1385
1386 return 0;
1387}
1388
1389
1391{
1392 // clang-format off
1400
1408
1414
1421 // clang-format on
1422}
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:926
static TOOL_ACTION decrementPrimary
Definition actions.h:96
static TOOL_ACTION paste
Definition actions.h:80
static TOOL_ACTION cancelInteractive
Definition actions.h:72
static TOOL_ACTION unselectAll
Definition actions.h:83
static TOOL_ACTION decrementSecondary
Definition actions.h:98
static TOOL_ACTION copy
Definition actions.h:78
static TOOL_ACTION undo
Definition actions.h:75
static TOOL_ACTION incrementSecondary
Definition actions.h:97
static TOOL_ACTION duplicate
Definition actions.h:84
static TOOL_ACTION incrementPrimary
Definition actions.h:95
static TOOL_ACTION doDelete
Definition actions.h:85
static TOOL_ACTION redo
Definition actions.h:76
static TOOL_ACTION deleteTool
Definition actions.h:86
static TOOL_ACTION increment
Definition actions.h:94
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:223
static TOOL_ACTION cut
Definition actions.h:77
static TOOL_ACTION copyAsText
Definition actions.h:79
static TOOL_ACTION refreshPreview
Definition actions.h:158
static TOOL_ACTION selectAll
Definition actions.h:82
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:231
bool Empty() const
Definition commit.h:137
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
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)
int ShowModal() override
Dialog to update or change schematic library symbols.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual VECTOR2I GetPosition() const
Definition eda_item.h:272
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:273
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:148
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:142
const KIID m_Uuid
Definition eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:144
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.h:113
EDA_ITEM * GetParent() const
Definition eda_item.h:112
bool IsMoving() const
Definition eda_item.h:125
virtual bool IsVisible() const
Definition eda_text.h:187
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:428
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:200
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:397
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:203
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:420
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:298
Define a library symbol object.
Definition lib_symbol.h:85
bool UnitsLocked() const
Check whether symbol units are interchangeable.
Definition lib_symbol.h:291
bool IsDerived() const
Definition lib_symbol.h:206
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:688
void RemoveDrawItem(SCH_ITEM *aItem)
Remove draw aItem from list.
std::vector< SCH_PIN * > GetPins() const override
int GetUnitCount() const override
void AddDrawItem(SCH_ITEM *aItem, bool aSort=true)
Add a new draw aItem to the draw object list and sort according to aSort.
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.
static TOOL_ACTION rotateCCW
static TOOL_ACTION mirrorV
static TOOL_ACTION swap
static TOOL_ACTION convertStackedPins
static TOOL_ACTION pinTable
static TOOL_ACTION properties
static TOOL_ACTION rotateCW
static TOOL_ACTION mirrorH
static TOOL_ACTION symbolProperties
static TOOL_ACTION explodeStackedPin
static TOOL_ACTION updateSymbolFields
static TOOL_ACTION move
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
bool IsMandatory() const
wxString GetName(bool aUseDefaultName=true) const
Return the field name (not translated).
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:167
SCH_ITEM * Duplicate(bool addToParentGroup, SCH_COMMIT *aCommit=nullptr, bool doClone=false) const
Routine to create a new copy of given item.
Definition sch_item.cpp:137
virtual void SetBodyStyle(int aBodyStyle)
Definition sch_item.h:246
int GetBodyStyle() const
Definition sch_item.h:247
virtual void MirrorHorizontally(int aCenter)
Mirror item horizontally about aCenter.
Definition sch_item.h:387
int GetUnit() const
Definition sch_item.h:238
virtual void Rotate(const VECTOR2I &aCenter, bool aRotateCCW)
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition sch_item.h:403
virtual void SetUnit(int aUnit)
Definition sch_item.h:237
wxString GetClass() const override
Return the class name.
Definition sch_item.h:177
virtual void MirrorVertically(int aCenter)
Mirror item vertically about aCenter.
Definition sch_item.h:395
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:642
void SetVisible(bool aVisible)
Definition sch_pin.h:114
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition sch_pin.h:93
void SetName(const wxString &aName)
Definition sch_pin.cpp:419
void SetPosition(const VECTOR2I &aPos) override
Definition sch_pin.h:251
const wxString & GetName() const
Definition sch_pin.cpp:401
void SetLength(int aLength)
Definition sch_pin.h:99
PIN_ORIENTATION GetOrientation() const
Definition sch_pin.cpp:264
void SetNumberTextSize(int aSize)
Definition sch_pin.cpp:693
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition sch_pin.h:96
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:256
void SetType(ELECTRICAL_PINTYPE aType)
Definition sch_pin.cpp:333
const wxString & GetNumber() const
Definition sch_pin.h:124
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:313
void SetNameTextSize(int aSize)
Definition sch_pin.cpp:669
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
SCH_SELECTION & GetSelection()
SCH_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false, bool aPromoteGroups=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
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.
void updateItem(EDA_ITEM *aItem, bool aUpdateRTree) const
int Increment(const TOOL_EVENT &aEvent)
void saveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aType, bool aAppend=false, bool aDirtyConnectivity=true)
int InteractiveDelete(const TOOL_EVENT &aEvent)
bool Init() override
Init() is called once upon a registration of the tool.
SCH_TOOL_BASE(const std::string &aName)
SCH_SELECTION_TOOL * m_selectionTool
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.
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition selection.cpp:75
ITER end()
Definition selection.h:80
ITER begin()
Definition selection.h:79
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition selection.cpp:92
bool IsHover() const
Definition selection.h:89
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:105
EDA_ITEM * Front() const
Definition selection.h:177
virtual void Clear() override
Remove all the stored items from the group.
Definition selection.h:98
int Size() const
Returns the number of selected parts.
Definition selection.h:121
std::vector< EDA_ITEM * > GetItemsSortedBySelectionOrder() const
void SetReferencePoint(const VECTOR2I &aP)
bool Empty() const
Checks if there is anything selected.
Definition selection.h:115
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:450
const std::string & GetString()
Definition richio.h:473
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 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 editShapeProperties(SCH_SHAPE *aShape)
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 ExplodeStackedPin(const TOOL_EVENT &aEvent)
int ConvertStackedPins(const TOOL_EVENT &aEvent)
void editSymbolProperties()
Set up handlers for various events.
int UpdateSymbolFields(const TOOL_EVENT &aEvent)
int DoDelete(const TOOL_EVENT &aEvent)
Delete the selected items, or the item under the cursor.
static const std::vector< KICAD_T > SwappableItems
KIGFX::VIEW_CONTROLS * getViewControls() const
Definition tool_base.cpp:44
KIGFX::VIEW * getView() const
Definition tool_base.cpp:38
Generic, UI-independent tool event.
Definition tool_event.h:171
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition tool_event.h:392
COMMIT * Commit() const
Definition tool_event.h:283
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
void Go(int(SYMBOL_EDIT_FRAME::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
TOOL_MENU & GetToolMenu()
CONDITIONAL_MENU & GetMenu()
Definition tool_menu.cpp:44
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
Definition clipboard.cpp:38
std::string GetClipboardUTF8()
Return the information currently stored in the system clipboard.
Definition clipboard.cpp:58
#define _(s)
@ RECURSE
Definition eda_item.h:51
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition eda_item.h:566
#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
const wxChar *const traceStackedPins
Flag to enable debug output for stacked pins handling in symbol/pin code.
@ LAYER_DEVICE
Definition layer_ids.h:466
void Prettify(std::string &aSource, FORMAT_MODE aMode)
Pretty-prints s-expression text according to KiCad format rules.
PIN_ORIENTATION
The symbol library pin object orientations.
Definition pin_type.h:105
wxString GetSelectedItemsAsText(const SELECTION &aSel)
wxString TitleCaps(const wxString &aString)
Capitalize the first letter in each word.
static std::vector< KICAD_T > nonFields
VECTOR2I end
wxString result
Test unit parsing edge cases and error handling.
constexpr GR_TEXT_H_ALIGN_T GetFlippedAlignment(GR_TEXT_H_ALIGN_T aAlign)
Get the reverse alignment: left-right are swapped, others are unchanged.
wxLogTrace helper definitions.
@ SCH_TABLE_T
Definition typeinfo.h:169
@ LIB_SYMBOL_T
Definition typeinfo.h:152
@ SCH_TABLECELL_T
Definition typeinfo.h:170
@ SCH_FIELD_T
Definition typeinfo.h:154
@ SCH_SHAPE_T
Definition typeinfo.h:153
@ SCH_TEXT_T
Definition typeinfo.h:155
@ SCH_TEXTBOX_T
Definition typeinfo.h:156
@ SCH_PIN_T
Definition typeinfo.h:157
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition vector2d.h:644