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