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, see <https://www.gnu.org/licenses/>.
19 */
20
22#include "tl/expected.hpp"
23
24#include <optional>
25#include <wx/buffer.h>
26#include <wx/debug.h>
27#include <wx/mstream.h>
28#include <wx/dcmemory.h>
29
30#include <tool/picker_tool.h>
36#include <clipboard.h>
37#include <sch_actions.h>
38#include <increment.h>
39#include <pin_layout_cache.h>
40#include <render_utils.h>
41#include <string_utils.h>
42#include <symbol_edit_frame.h>
43#include <sch_commit.h>
50#include <view/view_controls.h>
51#include <view/view.h>
52#include <richio.h>
54#include <sch_textbox.h>
56#include <widgets/lib_tree.h>
57#include <widgets/wx_infobar.h>
59#include <math/util.h> // for KiROUND
61#include <trace_helpers.h>
62#include <sch_painter.h>
63#include <sch_plotter.h>
64#include <gal/gal_print.h>
66#include <zoom_defines.h>
67
68
69namespace
70{
71constexpr int clipboardMaxBitmapSize = 4096;
72constexpr double clipboardBboxInflation = 0.02;
73
74
75void appendMimeData( std::vector<CLIPBOARD_MIME_DATA>& aMimeData, const wxString& aMimeType,
76 const wxMemoryBuffer& aBuffer )
77{
78 if( aBuffer.GetDataLen() == 0 )
79 return;
80
82 entry.m_mimeType = aMimeType;
83 entry.m_data = aBuffer;
84 aMimeData.push_back( entry );
85}
86
87
88void appendMimeData( std::vector<CLIPBOARD_MIME_DATA>& aMimeData, const wxString& aMimeType,
89 wxImage&& aImage )
90{
91 if( !aImage.IsOk() )
92 return;
93
95 entry.m_mimeType = aMimeType;
96 entry.m_image = std::move( aImage );
97 aMimeData.push_back( std::move( entry ) );
98}
99
100
101bool plotSymbolToSvg( SYMBOL_EDIT_FRAME& aFrame, LIB_SYMBOL& aSymbol, const BOX2I& aBBox,
102 int aUnit, int aBodyStyle, wxMemoryBuffer& aBuffer )
103{
104 SCH_RENDER_SETTINGS renderSettings;
105 renderSettings.LoadColors( aFrame.GetColorSettings() );
106 renderSettings.SetDefaultPenWidth( aFrame.GetRenderSettings()->GetDefaultPenWidth() );
107
108 wxFileName tempFile( wxFileName::CreateTempFileName( wxS( "kicad_symbol_svg" ) ) );
109
110 // The bbox is the bounding box of the selected items only, so it is passed in rather than
111 // computed from the whole (partial) symbol.
112 if( !PlotSymbolToSVG( aSymbol, aSymbol, aUnit, aBodyStyle, aBBox, renderSettings, false,
113 tempFile.GetFullPath() ) )
114 {
115 wxRemoveFile( tempFile.GetFullPath() );
116 return false;
117 }
118
119 bool ok = LoadFileToMemory( tempFile.GetFullPath(), aBuffer );
120 wxRemoveFile( tempFile.GetFullPath() );
121 return ok;
122}
123
124
125wxImage renderSymbolToBitmap( SYMBOL_EDIT_FRAME& aFrame, LIB_SYMBOL& aSymbol, const BOX2I& aBBox,
126 int aUnit, int aBodyStyle, int aWidth, int aHeight,
127 double aViewScale, const wxColour& aBgColor )
128{
129 wxBitmap bitmap( aWidth, aHeight, 24 );
130 wxMemoryDC dc;
131 dc.SelectObject( bitmap );
132 dc.SetBackground( wxBrush( aBgColor ) );
133 dc.Clear();
134
137 std::unique_ptr<KIGFX::GAL_PRINT> galPrint = KIGFX::GAL_PRINT::Create( options, &dc );
138
139 if( !galPrint )
140 return wxImage();
141
142 KIGFX::GAL* gal = galPrint->GetGAL();
143 KIGFX::PRINT_CONTEXT* printCtx = galPrint->GetPrintCtx();
144 std::unique_ptr<KIGFX::SCH_PAINTER> painter = std::make_unique<KIGFX::SCH_PAINTER>( gal );
145 std::unique_ptr<KIGFX::VIEW> view = std::make_unique<KIGFX::VIEW>();
146
147 // For symbol editor, we don't have a full schematic context
148 // but SCH_PAINTER can still work for rendering individual items
149 view->SetGAL( gal );
150 view->SetPainter( painter.get() );
151 view->SetScaleLimits( ZOOM_MAX_LIMIT_EESCHEMA, ZOOM_MIN_LIMIT_EESCHEMA );
152 view->SetScale( 1.0 );
154
155 // Clone items and add to view
156 std::vector<std::unique_ptr<SCH_ITEM>> clonedItems;
157
158 for( SCH_ITEM& item : aSymbol.GetDrawItems() )
159 {
160 if( aUnit && item.GetUnit() && item.GetUnit() != aUnit )
161 continue;
162
163 if( aBodyStyle && item.GetBodyStyle() && item.GetBodyStyle() != aBodyStyle )
164 continue;
165
166 SCH_ITEM* clone = static_cast<SCH_ITEM*>( item.Clone() );
167 clonedItems.emplace_back( clone );
168 view->Add( clone );
169 }
170
171 SCH_RENDER_SETTINGS* dstSettings = painter->GetSettings();
172 dstSettings->LoadColors( aFrame.GetColorSettings() );
173 dstSettings->SetDefaultPenWidth( aFrame.GetRenderSettings()->GetDefaultPenWidth() );
174 dstSettings->SetIsPrinting( true );
175
176 COLOR4D bgColor4D( aBgColor.Red() / 255.0, aBgColor.Green() / 255.0,
177 aBgColor.Blue() / 255.0, 1.0 );
178 dstSettings->SetBackgroundColor( bgColor4D );
179
180 for( int i = 0; i < KIGFX::VIEW::VIEW_MAX_LAYERS; ++i )
181 {
182 view->SetLayerVisible( i, true );
183 view->SetLayerTarget( i, KIGFX::TARGET_NONCACHED );
184 }
185
186 view->SetLayerVisible( LAYER_DRAWINGSHEET, false );
187
188 // Calculate effective output DPI for the print context.
189 // On GTK, Cairo uses device scale 72/4800 and SetSheetSize doubles internal resolution.
190 // On Windows/macOS, there's no device scale, so effective DPI = native DPI * 2.
191#ifdef __WXGTK__
192 double ppi = 144.0;
193#else
194 double ppi = printCtx->GetNativeDPI() * 2.0;
195#endif
196 double inch2Iu = 1000.0 * schIUScale.IU_PER_MILS;
197 VECTOR2D pageSizeIn( (double) aWidth / ppi, (double) aHeight / ppi );
198
199 galPrint->SetSheetSize( pageSizeIn );
200 galPrint->SetNativePaperSize( pageSizeIn, printCtx->HasNativeLandscapeRotation() );
201
202 // SetSheetSize creates an internal canvas at 2× the nominal page size for quality.
203 // The × 2 multiplier ensures content fills this internal canvas.
204 double zoomFactor = 2.0 * aViewScale * inch2Iu / ppi;
205
206 // Set up both the GAL and VIEW to center on the bbox.
207 view->SetCenter( aBBox.Centre() );
208 view->SetScale( aViewScale * zoomFactor );
209
210 gal->SetLookAtPoint( aBBox.Centre() );
211 gal->SetZoomFactor( zoomFactor );
212 gal->SetClearColor( bgColor4D );
213 gal->ClearScreen();
214
215 view->UseDrawPriority( true );
216
217 {
219 view->Redraw();
220 }
221
222 dc.SelectObject( wxNullBitmap );
223 return bitmap.ConvertToImage();
224}
225
226
227tl::expected<wxImage, std::string> renderSymbolToImageWithAlpha( SYMBOL_EDIT_FRAME& aFrame, LIB_SYMBOL aSymbol,
228 const BOX2I& aBBox, int aUnit, int aBodyStyle )
229{
230 VECTOR2I size = aBBox.GetSize();
231
232 if( size.x <= 0 || size.y <= 0 )
233 return tl::make_unexpected( "Invalid image size" + std::to_string( size.x ) + "x" + std::to_string( size.y ) );
234
235 // Use the current view scale to match what the user sees on screen
236 double viewScale = aFrame.GetCanvas()->GetView()->GetScale();
237 int bitmapWidth = KiROUND( size.x * viewScale );
238 int bitmapHeight = KiROUND( size.y * viewScale );
239
240 // Clamp to maximum size while preserving aspect ratio
241 if( bitmapWidth > clipboardMaxBitmapSize || bitmapHeight > clipboardMaxBitmapSize )
242 {
243 double scaleDown = (double) clipboardMaxBitmapSize / std::max( bitmapWidth, bitmapHeight );
244 bitmapWidth = KiROUND( bitmapWidth * scaleDown );
245 bitmapHeight = KiROUND( bitmapHeight * scaleDown );
246 viewScale *= scaleDown;
247 }
248
249 if( bitmapWidth <= 0 || bitmapHeight <= 0 )
250 return tl::make_unexpected( "Invalid image size" + std::to_string( bitmapWidth ) + "x"
251 + std::to_string( bitmapHeight ) );
252
253 // Render twice with different backgrounds for alpha computation
254 wxImage imageOnWhite = renderSymbolToBitmap( aFrame, aSymbol, aBBox, aUnit, aBodyStyle, bitmapWidth, bitmapHeight,
255 viewScale, *wxWHITE );
256 wxImage imageOnBlack = renderSymbolToBitmap( aFrame, aSymbol, aBBox, aUnit, aBodyStyle, bitmapWidth, bitmapHeight,
257 viewScale, *wxBLACK );
258
259 if( !imageOnWhite.IsOk() || !imageOnBlack.IsOk() )
260 return tl::make_unexpected( "Failed to render symbol to white/black bitmaps" );
261
262 return CreateAlphaImageFromTwoRenders( imageOnWhite, imageOnBlack );
263}
264
265} // namespace
266
267
269 SCH_TOOL_BASE( "eeschema.SymbolEditTool" )
270{
271}
272
273
274const std::vector<KICAD_T> SYMBOL_EDITOR_EDIT_TOOL::SwappableItems = {
275 LIB_SYMBOL_T, // Allows swapping the anchor
276 SCH_PIN_T,
281};
282
283
285{
287
290
291 wxASSERT_MSG( drawingTools, "eeschema.SymbolDrawing tool is not available" );
292
293 auto haveSymbolCondition =
294 [&]( const SELECTION& sel )
295 {
296 return m_isSymbolEditor && m_frame->GetCurSymbol();
297 };
298
299 auto canEdit =
300 [&]( const SELECTION& sel )
301 {
302 if( !m_frame->IsSymbolEditable() )
303 return false;
304
305 if( m_frame->IsSymbolAlias() )
306 {
307 for( EDA_ITEM* item : sel )
308 {
309 if( item->Type() != SCH_FIELD_T )
310 return false;
311 }
312 }
313
314 return true;
315 };
316
317 auto swapSelectionCondition =
319
320 const auto canCopyText = SCH_CONDITIONS::OnlyTypes( {
324 SCH_PIN_T,
327 } );
328
329 const auto canConvertStackedPins =
330 [&]( const SELECTION& sel )
331 {
332 // If multiple pins are selected, check they are all at same location
333 if( sel.Size() >= 2 )
334 {
335 std::vector<SCH_PIN*> pins;
336 for( EDA_ITEM* item : sel )
337 {
338 if( item->Type() != SCH_PIN_T )
339 return false;
340 pins.push_back( static_cast<SCH_PIN*>( item ) );
341 }
342
343 // Check that all pins are at the same location
344 VECTOR2I pos = pins[0]->GetPosition();
345 for( size_t i = 1; i < pins.size(); ++i )
346 {
347 if( pins[i]->GetPosition() != pos )
348 return false;
349 }
350 return true;
351 }
352
353 // If single pin is selected, check if there are other pins at same location
354 if( sel.Size() == 1 && sel.Front()->Type() == SCH_PIN_T )
355 {
356 SCH_PIN* selectedPin = static_cast<SCH_PIN*>( sel.Front() );
357 VECTOR2I pos = selectedPin->GetPosition();
358
359 // Get the symbol and check for other pins at same location
360 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
361 if( !symbol )
362 return false;
363
364 int coLocatedCount = 0;
365
366 for( SCH_PIN* pin : symbol->GetPins() )
367 {
368 if( pin->GetPosition() == pos )
369 {
370 coLocatedCount++;
371
372 if( coLocatedCount >= 2 )
373 return true;
374 }
375 }
376 }
377
378 return false;
379 };
380
381 const auto canExplodeStackedPin =
382 [&]( const SELECTION& sel )
383 {
384 if( sel.Size() != 1 || sel.Front()->Type() != SCH_PIN_T )
385 return false;
386
387 SCH_PIN* pin = static_cast<SCH_PIN*>( sel.Front() );
388 bool isValid;
389 std::vector<wxString> stackedNumbers = pin->GetStackedPinNumbers( &isValid );
390 return isValid && stackedNumbers.size() > 1;
391 };
392
393 // clang-format off
394 // Add edit actions to the move tool menu
395 if( moveTool )
396 {
397 CONDITIONAL_MENU& moveMenu = moveTool->GetToolMenu().GetMenu();
398
399 moveMenu.AddSeparator( 200 );
400 moveMenu.AddItem( SCH_ACTIONS::rotateCCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
401 moveMenu.AddItem( SCH_ACTIONS::rotateCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
402 moveMenu.AddItem( SCH_ACTIONS::mirrorV, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
403 moveMenu.AddItem( SCH_ACTIONS::mirrorH, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
404
405 moveMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
406 moveMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
407
408 moveMenu.AddSeparator( 300 );
411 moveMenu.AddItem( ACTIONS::copyAsText, canCopyText && SCH_CONDITIONS::IdleSelection, 300 );
412 moveMenu.AddItem( ACTIONS::duplicate, canEdit && SCH_CONDITIONS::NotEmpty, 300 );
413 moveMenu.AddItem( ACTIONS::doDelete, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
414
415 moveMenu.AddSeparator( 400 );
416 moveMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
417 moveMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
418 }
419
420 // Add editing actions to the drawing tool menu
421 CONDITIONAL_MENU& drawMenu = drawingTools->GetToolMenu().GetMenu();
422
423 drawMenu.AddSeparator( 200 );
428
429 drawMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
430
431 // Add editing actions to the selection tool menu
432 CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
433
434 selToolMenu.AddItem( SCH_ACTIONS::rotateCCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
435 selToolMenu.AddItem( SCH_ACTIONS::rotateCW, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
436 selToolMenu.AddItem( SCH_ACTIONS::mirrorV, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
437 selToolMenu.AddItem( SCH_ACTIONS::mirrorH, canEdit && SCH_CONDITIONS::NotEmpty, 200 );
438
439 selToolMenu.AddItem( SCH_ACTIONS::swap, swapSelectionCondition, 200 );
440 selToolMenu.AddItem( SCH_ACTIONS::properties, canEdit && SCH_CONDITIONS::Count( 1 ), 200 );
441
442 selToolMenu.AddSeparator( 250 );
443 selToolMenu.AddItem( SCH_ACTIONS::convertStackedPins, canEdit && canConvertStackedPins, 250 );
444 selToolMenu.AddItem( SCH_ACTIONS::explodeStackedPin, canEdit && canExplodeStackedPin, 250 );
445
446 selToolMenu.AddSeparator( 300 );
449 selToolMenu.AddItem( ACTIONS::copyAsText, canCopyText && SCH_CONDITIONS::IdleSelection, 300 );
450 selToolMenu.AddItem( ACTIONS::paste, canEdit && SCH_CONDITIONS::Idle, 300 );
451 selToolMenu.AddItem( ACTIONS::duplicate, canEdit && SCH_CONDITIONS::NotEmpty, 300 );
452 selToolMenu.AddItem( ACTIONS::doDelete, canEdit && SCH_CONDITIONS::NotEmpty, 300 );
453
454 selToolMenu.AddSeparator( 400 );
455 selToolMenu.AddItem( ACTIONS::selectAll, haveSymbolCondition, 400 );
456 selToolMenu.AddItem( ACTIONS::unselectAll, haveSymbolCondition, 400 );
457 // clang-format on
458
459 return true;
460}
461
462
464{
465 SCH_SELECTION& selection = m_selectionTool->RequestSelection();
466
467 if( selection.GetSize() == 0 )
468 return 0;
469
470 VECTOR2I rotPoint;
471 bool ccw = ( aEvent.Matches( SCH_ACTIONS::rotateCCW.MakeEvent() ) );
472 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
473 SCH_COMMIT localCommit( m_toolMgr );
474 SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() );
475
476 if( !commit )
477 commit = &localCommit;
478
479 if( !item->IsMoving() )
480 commit->Modify( m_frame->GetCurSymbol(), m_frame->GetScreen(), RECURSE_MODE::RECURSE );
481
482 if( selection.GetSize() == 1 )
483 rotPoint = item->GetPosition();
484 else
485 rotPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
486
487 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
488 {
489 item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
490 item->Rotate( rotPoint, ccw );
491 m_frame->UpdateItem( item, false, true );
492 }
493
494 if( item->IsMoving() )
495 {
497 }
498 else
499 {
500 if( selection.IsHover() )
502
503 if( !localCommit.Empty() )
504 localCommit.Push( _( "Rotate" ) );
505 }
506
507 return 0;
508}
509
510
512{
513 SCH_SELECTION& selection = m_selectionTool->RequestSelection();
514
515 if( selection.GetSize() == 0 )
516 return 0;
517
518 VECTOR2I mirrorPoint;
519 bool xAxis = ( aEvent.Matches( SCH_ACTIONS::mirrorV.MakeEvent() ) );
520 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
521
522 if( !item->IsMoving() )
524
525 if( selection.GetSize() == 1 )
526 {
527 mirrorPoint = item->GetPosition();
528
529 switch( item->Type() )
530 {
531 case SCH_FIELD_T:
532 {
533 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
534
535 if( xAxis )
537 else
539
540 break;
541 }
542
543 default:
544 if( xAxis )
545 item->MirrorVertically( mirrorPoint.y );
546 else
547 item->MirrorHorizontally( mirrorPoint.x );
548
549 break;
550 }
551
552
553 m_frame->UpdateItem( item, false, true );
554 }
555 else
556 {
557 mirrorPoint = m_frame->GetNearestHalfGridPosition( selection.GetCenter() );
558
559 for( unsigned ii = 0; ii < selection.GetSize(); ii++ )
560 {
561 item = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
562
563 if( xAxis )
564 item->MirrorVertically( mirrorPoint.y );
565 else
566 item->MirrorHorizontally( mirrorPoint.x );
567
568 m_frame->UpdateItem( item, false, true );
569 }
570 }
571
572 if( item->IsMoving() )
573 {
575 }
576 else
577 {
578 if( selection.IsHover() )
580
581 m_frame->OnModify();
582 }
583
584 return 0;
585}
587{
588 SCH_SELECTION& selection = m_selectionTool->RequestSelection( SwappableItems );
589 std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
590
591 if( selection.Size() < 2 )
592 return 0;
593
594 EDA_ITEM* front = selection.Front();
595 bool isMoving = front->IsMoving();
596
597 // Save copy for undo if not in edit (edit command already handle the save copy)
598 if( front->GetEditFlags() == 0 )
600
601 for( size_t i = 0; i < sorted.size() - 1; i++ )
602 {
603 SCH_ITEM* a = static_cast<SCH_ITEM*>( sorted[i] );
604 SCH_ITEM* b = static_cast<SCH_ITEM*>( sorted[( i + 1 ) % sorted.size()] );
605
606 VECTOR2I aPos = a->GetPosition(), bPos = b->GetPosition();
607 std::swap( aPos, bPos );
608
609 a->SetPosition( aPos );
610 b->SetPosition( bPos );
611
612 // Special case some common swaps
613 if( a->Type() == b->Type() )
614 {
615 switch( a->Type() )
616 {
617 case SCH_PIN_T:
618 {
619 SCH_PIN* aPin = static_cast<SCH_PIN*>( a );
620 SCH_PIN* bBpin = static_cast<SCH_PIN*>( b );
621
622 PIN_ORIENTATION aOrient = aPin->GetOrientation();
623 PIN_ORIENTATION bOrient = bBpin->GetOrientation();
624
625 aPin->SetOrientation( bOrient );
626 bBpin->SetOrientation( aOrient );
627
628 break;
629 }
630 default: break;
631 }
632 }
633
634 m_frame->UpdateItem( a, false, true );
635 m_frame->UpdateItem( b, false, true );
636 }
637
638 // Update R-Tree for modified items
639 for( EDA_ITEM* selected : selection )
640 updateItem( selected, true );
641
642 if( isMoving )
643 {
644 m_toolMgr->PostAction( ACTIONS::refreshPreview );
645 }
646 else
647 {
648 if( selection.IsHover() )
650
651 m_frame->OnModify();
652 }
653
654 return 0;
655}
656
657
658static std::vector<KICAD_T> nonFields =
659{
665};
666
667
669{
670 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
671 std::deque<EDA_ITEM*> items = m_selectionTool->RequestSelection().GetItems();
672 SCH_COMMIT commit( m_frame );
673
674 if( items.empty() )
675 return 0;
676
677 // Don't leave a freed pointer in the selection
679
680 commit.Modify( symbol, m_frame->GetScreen() );
681
682 std::set<SCH_ITEM*> toDelete;
683 int fieldsHidden = 0;
684 int fieldsAlreadyHidden = 0;
685
686 for( EDA_ITEM* item : items )
687 {
688 if( item->Type() == SCH_PIN_T )
689 {
690 SCH_PIN* curr_pin = static_cast<SCH_PIN*>( item );
691 VECTOR2I pos = curr_pin->GetPosition();
692
693 toDelete.insert( curr_pin );
694
695 // when pin editing is synchronized, pins in the same position, with the same name
696 // in different units are also removed. But only one pin per unit (matching)
697 if( m_frame->SynchronizePins() )
698 {
699 std::vector<bool> got_unit( symbol->GetUnitCount() + 1 );
700
701 got_unit[curr_pin->GetUnit()] = true;
702
703 for( SCH_PIN* pin : symbol->GetPins() )
704 {
705 if( got_unit[pin->GetUnit()] )
706 continue;
707
708 if( pin->GetPosition() != pos )
709 continue;
710
711 if( pin->GetBodyStyle() != curr_pin->GetBodyStyle() )
712 continue;
713
714 if( pin->GetType() != curr_pin->GetType() )
715 continue;
716
717 if( pin->GetName() != curr_pin->GetName() )
718 continue;
719
720 toDelete.insert( pin );
721 got_unit[pin->GetUnit()] = true;
722 }
723 }
724 }
725 else if( item->Type() == SCH_FIELD_T )
726 {
727 SCH_FIELD* field = static_cast<SCH_FIELD*>( item );
728
729 // Hide "deleted" fields
730 if( field->IsVisible() )
731 {
732 field->SetVisible( false );
733 fieldsHidden++;
734 }
735 else
736 {
737 fieldsAlreadyHidden++;
738 }
739 }
740 else if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
741 {
742 toDelete.insert( schItem );
743 }
744 }
745
746 for( SCH_ITEM* item : toDelete )
747 symbol->RemoveDrawItem( item );
748
749 if( toDelete.size() == 0 )
750 {
751 if( fieldsHidden == 1 )
752 commit.Push( _( "Hide Field" ) );
753 else if( fieldsHidden > 1 )
754 commit.Push( _( "Hide Fields" ) );
755 else if( fieldsAlreadyHidden > 0 )
756 m_frame->ShowInfoBarError( _( "Use the Symbol Properties dialog to remove fields." ) );
757 }
758 else
759 {
760 commit.Push( _( "Delete" ) );
761 }
762
763 m_frame->RebuildView();
764 return 0;
765}
766
767
769 bool aCursorMovedByKeyboard )
770{
771 if( aCursorMovedByKeyboard )
772 return false;
773
774 // Mouse, not cursor, as grid points may well not be under any text
775 if( OPT_BOX2I numberBox = aPin.GetLayoutCache().GetPinNumberBBox() )
776 return numberBox->Contains( aMousePos );
777
778 return false;
779}
780
781
783{
784 SCH_SELECTION& selection = m_selectionTool->RequestSelection();
785
786 if( selection.Empty() || aEvent.IsAction( &SCH_ACTIONS::symbolProperties ) )
787 {
788 // If called from tree context menu, edit properties without loading into canvas
790 {
791 LIB_ID treeLibId = m_frame->GetTreeLIBID();
792
793 // Check if the selected symbol in tree is different from the currently loaded one
794 if( treeLibId.IsValid() &&
795 ( !m_frame->GetCurSymbol() || m_frame->GetCurSymbol()->GetLibId() != treeLibId ) )
796 {
797 // Edit properties directly from library buffer without loading to canvas
799 return 0;
800 }
801 }
802
803 if( m_frame->GetCurSymbol() )
805 }
806 else if( selection.Size() == 1 )
807 {
808 SCH_ITEM* item = static_cast<SCH_ITEM*>( selection.Front() );
809
810 // Save copy for undo if not in edit (edit command already handle the save copy)
811 if( item->GetEditFlags() == 0 )
813
814 switch( item->Type() )
815 {
816 case SCH_PIN_T:
817 {
818 SCH_PIN& pin = static_cast<SCH_PIN&>( *item );
819
820 const VECTOR2I& mousePos = m_toolMgr->GetMousePosition();
821 const bool keyboardCursor =
823
824 if( SYMBOL_EDITOR_PIN_TOOL* pinTool = m_toolMgr->GetTool<SYMBOL_EDITOR_PIN_TOOL>() )
825 pinTool->EditPinProperties( &pin, ShouldFocusPinNumber( pin, mousePos, keyboardCursor ) );
826
827 break;
828 }
829 case SCH_SHAPE_T:
830 editShapeProperties( static_cast<SCH_SHAPE*>( item ) );
831 break;
832
833 case SCH_TEXT_T:
834 editTextProperties( item );
835 break;
836
837 case SCH_TEXTBOX_T:
838 editTextBoxProperties( item );
839 break;
840
841 case SCH_FIELD_T:
842 editFieldProperties( static_cast<SCH_FIELD*>( item ) );
843 break;
844
845 default:
846 wxFAIL_MSG( wxT( "Unhandled item <" ) + item->GetClass() + wxT( ">" ) );
847 break;
848 }
849 }
850 else if( selection.Size() > 1 )
851 {
852 WX_INFOBAR* infobar = frame()->GetInfoBar();
853
854 infobar->RemoveAllButtons();
855
856 if( !frame()->GetPropertiesPanel()->IsShownOnScreen() )
857 {
858 infobar->AddLink( _( "Show Properties panel" ),
859 [this]( wxHyperlinkEvent& )
860 {
861 frame()->ToggleProperties();
862 } );
863 }
864
865 infobar->AddCloseButton();
866 infobar->ShowMessageFor( _( "Use Properties panel to edit properties common to selected items." ),
867 8000, wxICON_INFORMATION );
868 }
869
870 if( selection.IsHover() )
872
873 return 0;
874}
875
876
878{
879 DIALOG_SHAPE_PROPERTIES dlg( m_frame, aShape );
880
881 if( dlg.ShowModal() != wxID_OK )
882 return;
883
884 updateItem( aShape, true );
885 m_frame->GetCanvas()->Refresh();
886 m_frame->OnModify();
887
888 m_frame->SetDrawSpecificBodyStyle( !dlg.GetApplyToAllConversions() );
889 m_frame->SetDrawSpecificUnit( !dlg.GetApplyToAllUnits() );
890
891 std::vector<MSG_PANEL_ITEM> items;
892 aShape->GetMsgPanelInfo( m_frame, items );
893 m_frame->SetMsgPanel( items );
894}
895
896
898{
899 if ( aItem->Type() != SCH_TEXT_T )
900 return;
901
902 DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_TEXT*>( aItem ) );
903
904 if( dlg.ShowModal() != wxID_OK )
905 return;
906
907 updateItem( aItem, true );
908 m_frame->GetCanvas()->Refresh();
909 m_frame->OnModify( );
910}
911
912
914{
915 if ( aItem->Type() != SCH_TEXTBOX_T )
916 return;
917
918 DIALOG_TEXT_PROPERTIES dlg( m_frame, static_cast<SCH_TEXTBOX*>( aItem ) );
919
920 if( dlg.ShowModal() != wxID_OK )
921 return;
922
923 updateItem( aItem, true );
924 m_frame->GetCanvas()->Refresh();
925 m_frame->OnModify( );
926}
927
928
930{
931 if( aField == nullptr )
932 return;
933
934 wxString caption;
935
936 if( aField->IsMandatory() )
937 caption.Printf( _( "Edit %s Field" ), TitleCaps( aField->GetName() ) );
938 else
939 caption.Printf( _( "Edit '%s' Field" ), aField->GetName() );
940
941 DIALOG_FIELD_PROPERTIES dlg( m_frame, caption, aField );
942
943 // The dialog may invoke a kiway player for footprint fields
944 // so we must use a quasimodal dialog.
945 if( dlg.ShowQuasiModal() != wxID_OK )
946 return;
947
948 SCH_COMMIT commit( m_toolMgr );
949 commit.Modify( aField, m_frame->GetScreen() );
950
951 dlg.UpdateField( aField );
952
953 commit.Push( caption );
954
955 m_frame->GetCanvas()->Refresh();
956 m_frame->UpdateSymbolMsgPanelInfo();
957}
958
959
961{
962 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = m_frame->GetLibManager();
963 wxString libName = aLibId.GetLibNickname();
964 wxString symbolName = aLibId.GetLibItemName();
965
966 // Get the symbol from the library buffer (without loading it into the editor)
967 LIB_SYMBOL* bufferedSymbol = libMgr.GetBufferedSymbol( symbolName, libName );
968
969 if( !bufferedSymbol )
970 return;
971
972 // Create a copy to work with
973 LIB_SYMBOL tempSymbol( *bufferedSymbol );
974
977
978 DIALOG_LIB_SYMBOL_PROPERTIES dlg( m_frame, &tempSymbol );
979
980 // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
981 // frame. Therefore this dialog as a modal frame parent, MUST be run under
982 // quasimodal mode for the quasimodal frame support to work. So don't use
983 // the QUASIMODAL macros here.
984 if( dlg.ShowQuasiModal() != wxID_OK )
985 return;
986
987 wxString newName = tempSymbol.GetName();
988
989 // Update the buffered symbol with the changes. A rename has to be keyed on the old name so
990 // the existing buffer is renamed in place rather than a duplicate being created under the new
991 // name.
992 if( newName != symbolName )
993 libMgr.UpdateSymbolAfterRename( &tempSymbol, symbolName, libName );
994 else
995 libMgr.UpdateSymbol( &tempSymbol, libName );
996
997 // Mark the library as modified
998 libMgr.SetSymbolModified( newName, libName );
999
1000 // Update the tree view
1001 LIB_ID newLibId( libName, newName );
1002 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( newLibId );
1003 m_frame->UpdateLibraryTree( treeItem, &tempSymbol );
1004 m_frame->GetLibTree()->SelectLibId( newLibId );
1005}
1006
1007
1009{
1010 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1011 bool partLocked = symbol->UnitsLocked();
1012
1014 m_toolMgr->RunAction( ACTIONS::selectionClear );
1015
1017
1018 // This dialog itself subsequently can invoke a KIWAY_PLAYER as a quasimodal
1019 // frame. Therefore this dialog as a modal frame parent, MUST be run under
1020 // quasimodal mode for the quasimodal frame support to work. So don't use
1021 // the QUASIMODAL macros here.
1022 if( dlg.ShowQuasiModal() != wxID_OK )
1023 return;
1024
1025 m_frame->RebuildSymbolUnitAndBodyStyleLists();
1026 m_frame->OnModify();
1027
1028 // Update the library tree node so the description and other metadata reflect the changes
1029 // immediately without requiring the editor to be reopened.
1030 LIB_SYMBOL_LIBRARY_MANAGER& libMgr = m_frame->GetLibManager();
1031 wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( symbol->GetLibId() );
1032 m_frame->UpdateLibraryTree( treeItem, symbol );
1033
1034 // if m_UnitSelectionLocked has changed, set some edit options or defaults
1035 // to the best value
1036 if( partLocked != symbol->UnitsLocked() )
1037 {
1038 // Usually if units are locked, graphic items are specific to each unit
1039 // and if units are interchangeable, graphic items are common to units
1040 m_frame->SetDrawSpecificUnit( symbol->UnitsLocked() );
1041 }
1042}
1043
1044
1046{
1047 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1048
1049 if( !symbol )
1050 {
1051 wxBell();
1052 return 0;
1053 }
1054
1056 m_toolMgr->RunAction( ACTIONS::selectionClear );
1057
1059 dlg.SelectPinMapPage();
1060
1061 // This dialog can subsequently invoke a KIWAY_PLAYER as a quasimodal frame, so it must be run
1062 // quasimodally to keep that support working.
1063 if( dlg.ShowQuasiModal() != wxID_OK )
1064 return 0;
1065
1066 m_frame->RebuildSymbolUnitAndBodyStyleLists();
1067 m_frame->OnModify();
1068
1069 return 0;
1070}
1071
1072
1074{
1075 SCH_COMMIT commit( m_frame );
1076 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1077
1078 if( !symbol )
1079 return 0;
1080
1081 commit.Modify( symbol, m_frame->GetScreen() );
1082
1083 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1084 wxCHECK( selTool, -1 );
1085
1086 std::vector<SCH_PIN*> selectedPins;
1087
1088 SCH_SELECTION& selection = selTool->GetSelection();
1089
1090 for( EDA_ITEM* item : selection )
1091 {
1092 if( item->Type() == SCH_PIN_T )
1093 {
1094 SCH_PIN* pinItem = static_cast<SCH_PIN*>( item );
1095 selectedPins.push_back( pinItem );
1096 }
1097 }
1098
1099 // And now clear the selection so if we change the pins we don't have dangling pointers
1100 // in the selection.
1101 m_toolMgr->RunAction( ACTIONS::selectionClear );
1102
1103 DIALOG_LIB_EDIT_PIN_TABLE dlg( m_frame, symbol, selectedPins );
1104
1105 if( dlg.ShowModal() == wxID_CANCEL )
1106 return -1;
1107
1108 commit.Push( _( "Edit Pins" ) );
1109 m_frame->RebuildView();
1110
1111 return 0;
1112}
1113
1114
1116{
1117 SCH_COMMIT commit( m_frame );
1118 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1119
1120 if( !symbol )
1121 return 0;
1122
1123 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1124 wxCHECK( selTool, -1 );
1125
1126 SCH_SELECTION& selection = selTool->GetSelection();
1127
1128 // Collect pins to convert - accept pins with any number format
1129 std::vector<SCH_PIN*> pinsToConvert;
1130
1131 if( selection.Size() == 1 && selection.Front()->Type() == SCH_PIN_T )
1132 {
1133 // Single pin selected - find all pins at the same location
1134 SCH_PIN* selectedPin = static_cast<SCH_PIN*>( selection.Front() );
1135 VECTOR2I pos = selectedPin->GetPosition();
1136
1137 for( SCH_PIN* pin : symbol->GetPins() )
1138 {
1139 if( pin->GetPosition() == pos )
1140 pinsToConvert.push_back( pin );
1141 }
1142 }
1143 else
1144 {
1145 // Multiple pins selected - use them directly, accepting any pin numbers
1146 for( EDA_ITEM* item : selection )
1147 {
1148 if( item->Type() == SCH_PIN_T )
1149 pinsToConvert.push_back( static_cast<SCH_PIN*>( item ) );
1150 }
1151 }
1152
1153 if( pinsToConvert.size() < 2 )
1154 {
1155 m_frame->ShowInfoBarError( _( "At least two pins are needed to convert to stacked pins" ) );
1156 return 0;
1157 }
1158
1159 // Check that all pins are at the same location
1160 VECTOR2I pos = pinsToConvert[0]->GetPosition();
1161 for( size_t i = 1; i < pinsToConvert.size(); ++i )
1162 {
1163 if( pinsToConvert[i]->GetPosition() != pos )
1164 {
1165 m_frame->ShowInfoBarError( _( "All pins must be at the same location" ) );
1166 return 0;
1167 }
1168 }
1169
1170 commit.Modify( symbol, m_frame->GetScreen() );
1171
1172 // Clear selection before modifying pins, like the Delete command does
1173 m_toolMgr->RunAction( ACTIONS::selectionClear );
1174
1175 // Sort pins for consistent ordering - handle arbitrary pin number formats
1176 std::sort( pinsToConvert.begin(), pinsToConvert.end(),
1177 []( SCH_PIN* a, SCH_PIN* b )
1178 {
1179 wxString numA = a->GetNumber();
1180 wxString numB = b->GetNumber();
1181
1182 // Try to convert to integers for proper numeric sorting
1183 long longA, longB;
1184 bool aIsNumeric = numA.ToLong( &longA );
1185 bool bIsNumeric = numB.ToLong( &longB );
1186
1187 // Both are purely numeric - sort numerically
1188 if( aIsNumeric && bIsNumeric )
1189 return longA < longB;
1190
1191 // Mixed numeric/non-numeric - numeric pins come first
1192 if( aIsNumeric && !bIsNumeric )
1193 return true;
1194 if( !aIsNumeric && bIsNumeric )
1195 return false;
1196
1197 // Both non-numeric or mixed alphanumeric - use lexicographic sorting
1198 return numA < numB;
1199 });
1200
1201 // Build the stacked notation string with range collapsing
1202 wxString stackedNotation = wxT("[");
1203
1204 // Helper function to collapse consecutive numbers into ranges - handles arbitrary pin formats
1205 auto collapseRanges = [&]() -> wxString
1206 {
1207 if( pinsToConvert.empty() )
1208 return wxT("");
1209
1210 wxString result;
1211
1212 // Group pins by their alphanumeric prefix for range collapsing
1213 std::map<wxString, std::vector<long>> prefixGroups;
1214 std::vector<wxString> nonNumericPins;
1215
1216 // Parse each pin number to separate prefix from numeric suffix
1217 for( SCH_PIN* pin : pinsToConvert )
1218 {
1219 wxString pinNumber = pin->GetNumber();
1220
1221 // Skip empty pin numbers (shouldn't happen, but be defensive)
1222 if( pinNumber.IsEmpty() )
1223 {
1224 nonNumericPins.push_back( wxT("(empty)") );
1225 continue;
1226 }
1227
1228 wxString prefix;
1229 wxString numericPart;
1230
1231 // Find where numeric part starts (scan from end)
1232 size_t numStart = pinNumber.length();
1233 for( int i = pinNumber.length() - 1; i >= 0; i-- )
1234 {
1235 if( !wxIsdigit( pinNumber[i] ) )
1236 {
1237 numStart = i + 1;
1238 break;
1239 }
1240 if( i == 0 ) // All digits
1241 numStart = 0;
1242 }
1243
1244 if( numStart < pinNumber.length() ) // Has numeric suffix
1245 {
1246 prefix = pinNumber.Left( numStart );
1247 numericPart = pinNumber.Mid( numStart );
1248
1249 long numValue;
1250 if( numericPart.ToLong( &numValue ) && numValue >= 0 ) // Valid non-negative number
1251 {
1252 prefixGroups[prefix].push_back( numValue );
1253 }
1254 else
1255 {
1256 // Numeric part couldn't be parsed or is negative - treat as non-numeric
1257 nonNumericPins.push_back( pinNumber );
1258 }
1259 }
1260 else // No numeric suffix - consolidate as individual value
1261 {
1262 nonNumericPins.push_back( pinNumber );
1263 }
1264 }
1265
1266 // Process each prefix group
1267 for( auto& [prefix, numbers] : prefixGroups )
1268 {
1269 if( !result.IsEmpty() )
1270 result += wxT(",");
1271
1272 // The prefix may contain characters that are structural in stacked notation (e.g. a pin
1273 // numbered "foo,bar3"); escape it so it round-trips as a single pin number.
1274 wxString escPrefix = EscapeStackedPinItem( prefix );
1275
1276 // Sort numeric values for this prefix
1277 std::sort( numbers.begin(), numbers.end() );
1278
1279 // Collapse consecutive ranges within this prefix
1280 size_t i = 0;
1281 while( i < numbers.size() )
1282 {
1283 if( i > 0 ) // Not first number in this prefix group
1284 result += wxT(",");
1285
1286 long start = numbers[i];
1287 long end = start;
1288
1289 // Find the end of consecutive sequence
1290 while( i + 1 < numbers.size() && numbers[i + 1] == numbers[i] + 1 )
1291 {
1292 i++;
1293 end = numbers[i];
1294 }
1295
1296 // Add range or single number with prefix
1297 if( end > start + 1 ) // Range of 3+ numbers
1298 result += wxString::Format( wxT("%s%ld-%s%ld"), escPrefix, start, escPrefix, end );
1299 else if( end == start + 1 ) // Two consecutive numbers
1300 result += wxString::Format( wxT("%s%ld,%s%ld"), escPrefix, start, escPrefix, end );
1301 else // Single number
1302 result += wxString::Format( wxT("%s%ld"), escPrefix, start );
1303
1304 i++;
1305 }
1306 }
1307
1308 // Add non-numeric pin numbers as individual comma-separated values
1309 for( const wxString& nonNum : nonNumericPins )
1310 {
1311 if( !result.IsEmpty() )
1312 result += wxT(",");
1313 result += EscapeStackedPinItem( nonNum );
1314 }
1315
1316 return result;
1317 };
1318
1319 stackedNotation += collapseRanges();
1320 stackedNotation += wxT("]");
1321
1322 // Keep the first pin and give it the stacked notation
1323 SCH_PIN* masterPin = pinsToConvert[0];
1324 masterPin->SetNumber( stackedNotation );
1325
1326 // Log information about pins being removed before we remove them
1327 wxLogTrace( traceStackedPins,
1328 wxString::Format( "Converting %zu pins to stacked notation '%s'",
1329 pinsToConvert.size(), stackedNotation ) );
1330
1331 // Remove all other pins from the symbol that were consolidated into the stacked notation
1332 // Collect pins to remove first, then remove them all at once like the Delete command
1333 std::vector<SCH_PIN*> pinsToRemove;
1334 for( size_t i = 1; i < pinsToConvert.size(); ++i )
1335 {
1336 SCH_PIN* pinToRemove = pinsToConvert[i];
1337
1338 // Log the pin before removing it
1339 wxLogTrace( traceStackedPins,
1340 wxString::Format( "Will remove pin '%s' at position (%d, %d)",
1341 pinToRemove->GetNumber(),
1342 pinToRemove->GetPosition().x,
1343 pinToRemove->GetPosition().y ) );
1344
1345 pinsToRemove.push_back( pinToRemove );
1346 }
1347
1348 // Remove all pins at once, like the Delete command does
1349 for( SCH_PIN* pin : pinsToRemove )
1350 {
1351 symbol->RemoveDrawItem( pin );
1352 }
1353
1354 commit.Push( wxString::Format( _( "Convert %zu Stacked Pins to '%s'" ),
1355 pinsToConvert.size(), stackedNotation ) );
1356 m_frame->RebuildView();
1357 return 0;
1358}
1359
1360
1362{
1363 SCH_COMMIT commit( m_frame );
1364 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1365
1366 if( !symbol )
1367 return 0;
1368
1369 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1370 wxCHECK( selTool, -1 );
1371
1372 SCH_SELECTION& selection = selTool->GetSelection();
1373
1374 if( selection.GetSize() != 1 || selection.Front()->Type() != SCH_PIN_T )
1375 {
1376 m_frame->ShowInfoBarError( _( "Select a single pin with stacked notation to explode" ) );
1377 return 0;
1378 }
1379
1380 SCH_PIN* pin = static_cast<SCH_PIN*>( selection.Front() );
1381
1382 // Check if the pin has stacked notation
1383 bool isValid;
1384 std::vector<wxString> stackedNumbers = pin->GetStackedPinNumbers( &isValid );
1385
1386 if( !isValid || stackedNumbers.size() <= 1 )
1387 {
1388 m_frame->ShowInfoBarError( _( "Selected pin does not have valid stacked notation" ) );
1389 return 0;
1390 }
1391
1392 commit.Modify( symbol, m_frame->GetScreen() );
1393
1394 // Clear selection before modifying pins
1395 m_toolMgr->RunAction( ACTIONS::selectionClear );
1396
1397 // Sort the stacked numbers to find the smallest one
1398 std::sort( stackedNumbers.begin(), stackedNumbers.end(),
1399 []( const wxString& a, const wxString& b )
1400 {
1401 // Try to convert to integers for proper numeric sorting
1402 long numA, numB;
1403 if( a.ToLong( &numA ) && b.ToLong( &numB ) )
1404 return numA < numB;
1405
1406 // Fall back to string comparison if not numeric
1407 return a < b;
1408 });
1409
1410 // Change the original pin to use the first (smallest) number and make it visible
1411 pin->SetNumber( stackedNumbers[0] );
1412 pin->SetVisible( true );
1413
1414 // Create additional pins for the remaining numbers and make them invisible
1415 for( size_t i = 1; i < stackedNumbers.size(); ++i )
1416 {
1417 SCH_PIN* newPin = new SCH_PIN( symbol );
1418
1419 // Copy all properties from the original pin
1420 newPin->SetPosition( pin->GetPosition() );
1421 newPin->SetOrientation( pin->GetOrientation() );
1422 newPin->SetShape( pin->GetShape() );
1423 newPin->SetLength( pin->GetLength() );
1424 // Hidden power input pins act as global labels, so demote them to passive
1425 if( pin->GetType() == ELECTRICAL_PINTYPE::PT_POWER_IN )
1427 else
1428 newPin->SetType( pin->GetType() );
1429
1430 newPin->SetName( pin->GetName() );
1431 newPin->SetNumber( stackedNumbers[i] );
1432 newPin->SetNameTextSize( pin->GetNameTextSize() );
1433 newPin->SetNumberTextSize( pin->GetNumberTextSize() );
1434 newPin->SetUnit( pin->GetUnit() );
1435 newPin->SetBodyStyle( pin->GetBodyStyle() );
1436 newPin->SetVisible( false );
1437
1438 // Add the new pin to the symbol
1439 symbol->AddDrawItem( newPin );
1440 }
1441
1442 commit.Push( _( "Explode Stacked Pin" ) );
1443 m_frame->RebuildView();
1444 return 0;
1445}
1446
1447
1449{
1450 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1451
1452 if( !symbol )
1453 return 0;
1454
1455 if( !symbol->CanUpdateFieldsFromParent() )
1456 {
1457 m_frame->ShowInfoBarError( _( "Symbol is not derived from another symbol." ) );
1458 }
1459 else
1460 {
1461 DIALOG_UPDATE_SYMBOL_FIELDS dlg( m_frame, symbol );
1462
1463 if( dlg.ShowModal() == wxID_CANCEL )
1464 return -1;
1465 }
1466
1467 return 0;
1468}
1469
1470
1472{
1473 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1474
1475 // Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
1476 // it just clears the SELECTION's reference to them.
1477 selTool->GetSelection().Clear();
1478 {
1479 m_frame->GetSymbolFromUndoList();
1480 }
1481 selTool->RebuildSelection();
1482
1483 return 0;
1484}
1485
1486
1488{
1489 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1490
1491 // Nuke the selection for later rebuilding. This does *not* clear the flags on any items;
1492 // it just clears the SELECTION's reference to them.
1493 selTool->GetSelection().Clear();
1494 {
1495 m_frame->GetSymbolFromRedoList();
1496 }
1497 selTool->RebuildSelection();
1498
1499 return 0;
1500}
1501
1502
1504{
1505 int retVal = Copy( aEvent );
1506
1507 if( retVal == 0 )
1508 retVal = DoDelete( aEvent );
1509
1510 return retVal;
1511}
1512
1513
1515{
1516 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1517 SCH_SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
1518
1519 if( !symbol || !selection.GetSize() )
1520 return 0;
1521
1522 for( SCH_ITEM& item : symbol->GetDrawItems() )
1523 {
1524 if( item.Type() == SCH_FIELD_T )
1525 continue;
1526
1527 wxASSERT( !item.HasFlag( STRUCT_DELETED ) );
1528
1529 if( !item.IsSelected() )
1530 item.SetFlags( STRUCT_DELETED );
1531 }
1532
1533 LIB_SYMBOL* partCopy = new LIB_SYMBOL( *symbol );
1534
1535 STRING_FORMATTER formatter;
1536 SCH_IO_KICAD_SEXPR::FormatLibSymbol( partCopy, formatter );
1537
1538 delete partCopy;
1539
1540 for( SCH_ITEM& item : symbol->GetDrawItems() )
1541 item.ClearFlags( STRUCT_DELETED );
1542
1543 std::string prettyData = formatter.GetString();
1544 KICAD_FORMAT::Prettify( prettyData, KICAD_FORMAT::FORMAT_MODE::COMPACT_TEXT_PROPERTIES );
1545
1546 // Generate SVG and PNG for multi-format clipboard
1547 std::vector<CLIPBOARD_MIME_DATA> mimeData;
1548
1549 // Get the bounding box for just the selected items
1550 BOX2I bbox;
1551
1552 for( EDA_ITEM* item : selection )
1553 {
1554 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1555 if( bbox.GetWidth() == 0 && bbox.GetHeight() == 0 )
1556 bbox = schItem->GetBoundingBox();
1557 else
1558 bbox.Merge( schItem->GetBoundingBox() );
1559 }
1560
1561 if( bbox.GetWidth() > 0 && bbox.GetHeight() > 0 )
1562 {
1563 bbox.Inflate( bbox.GetWidth() * clipboardBboxInflation,
1564 bbox.GetHeight() * clipboardBboxInflation );
1565
1566 // Create a temporary symbol with just the selected items for plotting
1567 std::unique_ptr<LIB_SYMBOL> plotSymbol = std::make_unique<LIB_SYMBOL>( *symbol );
1568
1569 // Mark unselected items as deleted in the plot copy
1570 for( SCH_ITEM& item : plotSymbol->GetDrawItems() )
1571 {
1572 if( item.Type() == SCH_FIELD_T )
1573 continue;
1574
1575 // Find matching item in selection by position/type
1576 bool found = false;
1577
1578 for( EDA_ITEM* selItem : selection )
1579 {
1580 SCH_ITEM* selSchItem = static_cast<SCH_ITEM*>( selItem );
1581
1582 if( selSchItem->Type() == item.Type()
1583 && selSchItem->GetPosition() == item.GetPosition() )
1584 {
1585 found = true;
1586 break;
1587 }
1588 }
1589
1590 if( !found )
1591 item.SetFlags( STRUCT_DELETED );
1592 }
1593
1594 // Now copy only the non-deleted items to a clean symbol for plotting
1595 std::unique_ptr<LIB_SYMBOL> cleanSymbol = std::make_unique<LIB_SYMBOL>( *plotSymbol );
1596 plotSymbol.reset();
1597
1598 int unit = m_frame->GetUnit();
1599 int bodyStyle = m_frame->GetBodyStyle();
1600
1601 wxMemoryBuffer svgBuffer;
1602
1603 if( plotSymbolToSvg( *m_frame, *cleanSymbol, bbox, unit, bodyStyle, svgBuffer ) )
1604 appendMimeData( mimeData, wxS( "image/svg+xml" ), svgBuffer );
1605
1606 tl::expected<wxImage, std::string> pngImage =
1607 renderSymbolToImageWithAlpha( *m_frame, *cleanSymbol, bbox, unit, bodyStyle );
1608
1609 if( pngImage )
1610 {
1611 wxASSERT( pngImage->IsOk() );
1612 appendMimeData( mimeData, wxS( "image/png" ), std::move( *pngImage ) );
1613 }
1614 else
1615 {
1616 wxLogWarning( wxS( "Failed to render symbol to PNG: " ) + wxString::FromUTF8( pngImage.error() ) );
1617 }
1618 }
1619
1620 if( SaveClipboard( prettyData, mimeData ) )
1621 return 0;
1622 else
1623 return -1;
1624}
1625
1626
1628{
1629 SCH_SELECTION_TOOL* selTool = m_toolMgr->GetTool<SCH_SELECTION_TOOL>();
1630 SCH_SELECTION& selection = selTool->RequestSelection();
1631
1632 if( selection.Empty() )
1633 return 0;
1634
1635 wxString itemsAsText = GetSelectedItemsAsText( selection );
1636
1637 if( selection.IsHover() )
1638 m_toolMgr->RunAction( ACTIONS::selectionClear );
1639
1640 return SaveClipboard( itemsAsText.ToStdString() );
1641}
1642
1643
1645{
1646 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1647 LIB_SYMBOL* newPart = nullptr;
1648
1649 if( !symbol || symbol->IsDerived() )
1650 return 0;
1651
1652 std::string clipboardData = GetClipboardUTF8();
1653
1654 try
1655 {
1656 std::vector<LIB_SYMBOL*> newParts = SCH_IO_KICAD_SEXPR::ParseLibSymbols( clipboardData, "Clipboard" );
1657
1658 if( newParts.empty() || !newParts[0] )
1659 return -1;
1660
1661 newPart = newParts[0];
1662 }
1663 catch( IO_ERROR& )
1664 {
1665 // If it's not a symbol then paste as text
1666 newPart = new LIB_SYMBOL( "dummy_part" );
1667
1668 wxString pasteText( clipboardData );
1669
1670 // Limit of 5000 is totally arbitrary. Without a limit, pasting a bitmap image from
1671 // eeschema makes KiCad appear to hang.
1672 if( pasteText.Length() > 5000 )
1673 pasteText = pasteText.Left( 5000 ) + wxT( "..." );
1674
1675 SCH_TEXT* newText = new SCH_TEXT( { 0, 0 }, pasteText, LAYER_DEVICE );
1676 newPart->AddDrawItem( newText );
1677 }
1678
1679 SCH_COMMIT commit( m_toolMgr );
1680
1681 commit.Modify( symbol, m_frame->GetScreen() );
1682 m_selectionTool->ClearSelection();
1683
1684 for( SCH_ITEM& item : symbol->GetDrawItems() )
1685 item.ClearFlags( IS_NEW | IS_PASTED | SELECTED );
1686
1687 for( SCH_ITEM& item : newPart->GetDrawItems() )
1688 {
1689 if( item.Type() == SCH_FIELD_T )
1690 continue;
1691
1692 SCH_ITEM* newItem = item.Duplicate( true, &commit );
1693 newItem->SetParent( symbol );
1694 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
1695
1696 newItem->SetUnit( newItem->GetUnit() ? m_frame->GetUnit() : 0 );
1697 newItem->SetBodyStyle( newItem->GetBodyStyle() ? m_frame->GetBodyStyle() : 0 );
1698
1699 symbol->AddDrawItem( newItem );
1700 getView()->Add( newItem );
1701 }
1702
1703 delete newPart;
1704
1705 m_selectionTool->RebuildSelection();
1706
1707 SCH_SELECTION& selection = m_selectionTool->GetSelection();
1708
1709 if( !selection.Empty() )
1710 {
1711 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
1712
1713 if( m_toolMgr->RunSynchronousAction( SCH_ACTIONS::move, &commit ) )
1714 commit.Push( _( "Paste" ) );
1715 else
1716 commit.Revert();
1717 }
1718
1719 return 0;
1720}
1721
1722
1724{
1725 LIB_SYMBOL* symbol = m_frame->GetCurSymbol();
1726 SCH_SELECTION& selection = m_selectionTool->RequestSelection( nonFields );
1727 SCH_COMMIT commit( m_toolMgr );
1728
1729 if( selection.GetSize() == 0 )
1730 return 0;
1731
1732 commit.Modify( symbol, m_frame->GetScreen() );
1733
1734 std::vector<EDA_ITEM*> oldItems;
1735 std::vector<EDA_ITEM*> newItems;
1736
1737 std::copy( selection.begin(), selection.end(), std::back_inserter( oldItems ) );
1738 std::sort( oldItems.begin(), oldItems.end(), []( EDA_ITEM* a, EDA_ITEM* b )
1739 {
1740 int cmp;
1741
1742 if( a->Type() != b->Type() )
1743 return a->Type() < b->Type();
1744
1745 // Create the new pins in the same order as the old pins
1746 if( a->Type() == SCH_PIN_T )
1747 {
1748 const wxString& aNum = static_cast<SCH_PIN*>( a )->GetNumber();
1749 const wxString& bNum = static_cast<SCH_PIN*>( b )->GetNumber();
1750
1751 cmp = StrNumCmp( aNum, bNum );
1752
1753 // If the pin numbers are not numeric, then just number them by their position
1754 // on the screen.
1755 if( aNum.IsNumber() && bNum.IsNumber() && cmp != 0 )
1756 return cmp < 0;
1757 }
1758
1760
1761 if( cmp != 0 )
1762 return cmp < 0;
1763
1764 return a->m_Uuid < b->m_Uuid;
1765 } );
1766
1767 for( EDA_ITEM* item : oldItems )
1768 {
1769 SCH_ITEM* oldItem = static_cast<SCH_ITEM*>( item );
1770 SCH_ITEM* newItem = oldItem->Duplicate( true, &commit );
1771
1772 if( newItem->Type() == SCH_PIN_T )
1773 {
1774 SCH_PIN* newPin = static_cast<SCH_PIN*>( newItem );
1775
1776 if( !newPin->GetNumber().IsEmpty() )
1777 newPin->SetNumber( wxString::Format( wxT( "%i" ), symbol->GetMaxPinNumber() + 1 ) );
1778 }
1779
1780 oldItem->ClearFlags( IS_NEW | IS_PASTED | SELECTED );
1781 newItem->SetFlags( IS_NEW | IS_PASTED | SELECTED );
1782 newItem->SetParent( symbol );
1783 newItems.push_back( newItem );
1784
1785 symbol->AddDrawItem( newItem );
1786 getView()->Add( newItem );
1787 }
1788
1789 m_toolMgr->RunAction( ACTIONS::selectionClear );
1790 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &newItems );
1791
1792 selection.SetReferencePoint( getViewControls()->GetCursorPosition( true ) );
1793
1794 if( m_toolMgr->RunSynchronousAction( SCH_ACTIONS::move, &commit ) )
1795 commit.Push( _( "Duplicate" ) );
1796 else
1797 commit.Revert();
1798
1799 return 0;
1800}
1801
1802
1804{
1805 // clang-format off
1813
1821
1827
1835 // clang-format on
1836}
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
std::optional< BOX2I > OPT_BOX2I
Definition box2.h:931
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
static TOOL_ACTION decrementPrimary
Definition actions.h:92
static TOOL_ACTION paste
Definition actions.h:76
static TOOL_ACTION cancelInteractive
Definition actions.h:68
static TOOL_ACTION unselectAll
Definition actions.h:79
static TOOL_ACTION decrementSecondary
Definition actions.h:94
static TOOL_ACTION copy
Definition actions.h:74
static TOOL_ACTION undo
Definition actions.h:71
static TOOL_ACTION incrementSecondary
Definition actions.h:93
static TOOL_ACTION duplicate
Definition actions.h:80
static TOOL_ACTION incrementPrimary
Definition actions.h:91
static TOOL_ACTION doDelete
Definition actions.h:81
static TOOL_ACTION redo
Definition actions.h:72
static TOOL_ACTION deleteTool
Definition actions.h:82
static TOOL_ACTION increment
Definition actions.h:90
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
static TOOL_ACTION cut
Definition actions.h:73
static TOOL_ACTION copyAsText
Definition actions.h:75
static TOOL_ACTION refreshPreview
Definition actions.h:155
static TOOL_ACTION selectAll
Definition actions.h:78
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:228
constexpr BOX2< Vec > & Inflate(coord_type dx, coord_type dy)
Inflates the rectangle horizontally by dx and vertically by dy.
Definition box2.h:553
constexpr size_type GetWidth() const
Definition box2.h:211
constexpr Vec Centre() const
Definition box2.h:94
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:653
constexpr size_type GetHeight() const
Definition box2.h:212
constexpr const SizeVec & GetSize() const
Definition box2.h:203
bool Empty() const
Definition commit.h:142
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:102
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)
void SelectPinMapPage()
Switch the notebook to the Pin Map page (issue #2282).
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:348
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:349
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:270
EDA_ITEM_FLAGS GetEditFlags() const
Definition eda_item.h:170
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:597
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:160
EDA_ITEM * GetParent() const
Definition eda_item.h:112
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
bool IsMoving() const
Definition eda_item.h:132
virtual bool IsVisible() const
Definition eda_text.h:226
void SetVertJustify(GR_TEXT_V_ALIGN_T aType)
Definition eda_text.cpp:373
GR_TEXT_H_ALIGN_T GetHorizJustify() const
Definition eda_text.h:239
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:342
GR_TEXT_V_ALIGN_T GetVertJustify() const
Definition eda_text.h:242
void SetHorizJustify(GR_TEXT_H_ALIGN_T aType)
Definition eda_text.cpp:365
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
GAL_ANTIALIASING_MODE antialiasing_mode
The grid style to draw the grid in.
static std::unique_ptr< GAL_PRINT > Create(GAL_DISPLAY_OPTIONS &aOptions, wxDC *aDC)
Abstract interface for drawing on a 2D-surface.
void SetZoomFactor(double aZoomFactor)
void SetLookAtPoint(const VECTOR2D &aPoint)
Get/set the Point in world space to look at.
virtual void ClearScreen()
Clear the screen.
void SetWorldUnitLength(double aWorldUnitLength)
Set the unit length.
void SetClearColor(const COLOR4D &aColor)
virtual double GetNativeDPI() const =0
virtual bool HasNativeLandscapeRotation() const =0
void SetDefaultPenWidth(int aWidth)
void SetIsPrinting(bool isPrinting)
const VC_SETTINGS & GetSettings() const
Return the current VIEW_CONTROLS settings.
double GetScale() const
Definition view.h:281
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:301
static constexpr int VIEW_MAX_LAYERS
Maximum number of layers that may be shown.
Definition view.h:773
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
Symbol library management helper that is specific to the symbol library editor frame.
wxObjectDataPtr< LIB_TREE_MODEL_ADAPTER > & GetAdapter()
Return the adapter object that provides the stored data.
Define a library symbol object.
Definition lib_symbol.h:119
const LIB_ID & GetLibId() const override
Definition lib_symbol.h:188
bool UnitsLocked() const
Check whether symbol units are interchangeable.
bool IsDerived() const
Definition lib_symbol.h:236
bool CanUpdateFieldsFromParent() const
Definition lib_symbol.h:410
LIB_ITEMS_CONTAINER & GetDrawItems()
Return a reference to the draw item list.
Definition lib_symbol.h:832
wxString GetName() const override
Definition lib_symbol.h:181
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.
OPT_BOX2I GetPinNumberBBox()
Get the bounding box of the pin number, if there is one.
static TOOL_ACTION rotateCCW
static TOOL_ACTION editSymbolPinMaps
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
SCH_RENDER_SETTINGS * GetRenderSettings()
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
KIGFX::SCH_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
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:165
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:170
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:411
int GetUnit() const
Definition sch_item.h:237
virtual void Rotate(const VECTOR2I &aCenter, bool aRotateCCW)
Rotate the item around aCenter 90 degrees in the clockwise direction.
Definition sch_item.h:427
virtual void SetUnit(int aUnit)
Definition sch_item.h:236
wxString GetClass() const override
Return the class name.
Definition sch_item.h:175
virtual void MirrorVertically(int aCenter)
Mirror item vertically about aCenter.
Definition sch_item.h:419
void SetNumber(const wxString &aNumber)
Definition sch_pin.cpp:825
void SetVisible(bool aVisible)
Definition sch_pin.h:132
void SetOrientation(PIN_ORIENTATION aOrientation)
Definition sch_pin.h:111
void SetName(const wxString &aName)
Definition sch_pin.cpp:521
void SetPosition(const VECTOR2I &aPos) override
Definition sch_pin.h:314
const wxString & GetName() const
Definition sch_pin.cpp:503
void SetLength(int aLength)
Definition sch_pin.h:117
PIN_ORIENTATION GetOrientation() const
Definition sch_pin.cpp:362
void SetNumberTextSize(int aSize)
Definition sch_pin.cpp:879
void SetShape(GRAPHIC_PINSHAPE aShape)
Definition sch_pin.h:114
VECTOR2I GetPosition() const override
Definition sch_pin.cpp:354
PIN_LAYOUT_CACHE & GetLayoutCache() const
Get the layout cache associated with this pin.
Definition sch_pin.cpp:1782
void SetType(ELECTRICAL_PINTYPE aType)
Definition sch_pin.cpp:431
const wxString & GetNumber() const
Definition sch_pin.h:142
ELECTRICAL_PINTYPE GetType() const
Definition sch_pin.cpp:411
void SetNameTextSize(int aSize)
Definition sch_pin.cpp:853
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
void LoadColors(const COLOR_SETTINGS *aSettings) override
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:76
ITER begin()
Definition selection.h:75
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition selection.cpp:92
bool IsHover() const
Definition selection.h:85
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:104
EDA_ITEM * Front() const
Definition selection.h:176
virtual void Clear() override
Remove all the stored items from the group.
Definition selection.h:97
int Size() const
Returns the number of selected parts.
Definition selection.h:120
std::vector< EDA_ITEM * > GetItemsSortedBySelectionOrder() const
void SetReferencePoint(const VECTOR2I &aP)
bool Empty() const
Checks if there is anything selected.
Definition selection.h:114
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:430
const std::string & GetString()
Definition richio.h:453
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 EditSymbolPinMaps(const TOOL_EVENT &aEvent)
Open the symbol properties dialog directly on its Pin Map page (issue #2282).
void editSymbolPropertiesFromLibrary(const LIB_ID &aLibId)
Set up handlers for various events.
int ConvertStackedPins(const TOOL_EVENT &aEvent)
int UpdateSymbolFields(const TOOL_EVENT &aEvent)
int DoDelete(const TOOL_EVENT &aEvent)
Delete the selected items, or the item under the cursor.
static const std::vector< KICAD_T > SwappableItems
static bool ShouldFocusPinNumber(SCH_PIN &aPin, const VECTOR2I &aMousePos, bool aCursorMovedByKeyboard)
The pointer only says what the user is aiming at while the pointer is the device being steered.
The symbol library editor main window.
COLOR_SETTINGS * GetColorSettings(bool aForceRefresh=false) const override
Returns a pointer to the active color theme settings.
LIB_SYMBOL * GetBufferedSymbol(const wxString &aSymbolName, const wxString &aLibrary)
Return the symbol copy from the buffer.
bool UpdateSymbolAfterRename(LIB_SYMBOL *aSymbol, const wxString &aOldSymbolName, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol when the name has changed.
void SetSymbolModified(const wxString &aSymbolName, const wxString &aLibrary)
bool UpdateSymbol(LIB_SYMBOL *aSymbol, const wxString &aLibrary)
Update the symbol buffer with a new version of the symbol.
KIGFX::VIEW_CONTROLS * getViewControls() const
Definition tool_base.cpp:40
KIGFX::VIEW * getView() const
Definition tool_base.cpp:34
Generic, UI-independent tool event.
Definition tool_event.h:167
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition tool_event.h:388
COMMIT * Commit() const
Definition tool_event.h:279
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:40
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:76
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
void AddLink(const wxString &aLinkText, const std::function< void(wxHyperlinkEvent &)> &aFn)
Add a hypertext link to the infobar.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
Definition clipboard.cpp:32
std::string GetClipboardUTF8()
Return the information currently stored in the system clipboard.
#define _(s)
@ RECURSE
Definition eda_item.h:51
#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.
bool LoadFileToMemory(const wxString &aFileName, wxMemoryBuffer &aBuffer)
Load the contents of a file into a memory buffer.
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_DEVICE
Definition layer_ids.h:488
void Prettify(std::string &aSource, FORMAT_MODE aMode)
Pretty-prints s-expression text according to KiCad format rules.
@ TARGET_NONCACHED
Auxiliary rendering target (noncached)
Definition definitions.h:34
@ PT_POWER_IN
power input (GND, VCC for ICs). Must be connected to a power output.
Definition pin_type.h:42
@ PT_PASSIVE
pin for passive symbols: must be connected, and can be connected to any pin.
Definition pin_type.h:39
PIN_ORIENTATION
The symbol library pin object orientations.
Definition pin_type.h:101
tl::expected< wxImage, std::string > CreateAlphaImageFromTwoRenders(const wxImage &aOnWhite, const wxImage &aOnBlack)
Combine two opaque renders of the same content into a single image with an alpha channel.
std::vector< EDA_ITEM * > EDA_ITEMS
bool PlotSymbolToSVG(LIB_SYMBOL &aDrawSymbol, LIB_SYMBOL &aFieldsSymbol, int aUnit, int aBodyStyle, const BOX2I &aBBox, SCH_RENDER_SETTINGS &aRenderSettings, bool aBlackAndWhite, const wxString &aFileName, REPORTER *aReporter)
Plot a single symbol variant (unit and body style) to an SVG file.
wxString GetSelectedItemsAsText(const SELECTION &aSel)
constexpr double SCH_WORLD_UNIT(1e-7/0.0254)
wxString TitleCaps(const wxString &aString)
Capitalize the first letter in each word.
wxString EscapeStackedPinItem(const wxString &aPinNumber)
Escape the characters that carry structural meaning inside stacked pin notation ('[',...
wxString m_mimeType
Definition clipboard.h:35
wxMemoryBuffer m_data
Definition clipboard.h:36
std::optional< wxBitmap > m_image
Optional bitmap image to add to clipboard via wxBitmapDataObject.
Definition clipboard.h:41
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action.
static std::vector< KICAD_T > nonFields
KIBIS_PIN * pin
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:161
@ LIB_SYMBOL_T
Definition typeinfo.h:144
@ SCH_TABLECELL_T
Definition typeinfo.h:162
@ SCH_FIELD_T
Definition typeinfo.h:146
@ SCH_SHAPE_T
Definition typeinfo.h:145
@ SCH_TEXT_T
Definition typeinfo.h:147
@ SCH_TEXTBOX_T
Definition typeinfo.h:148
@ SCH_PIN_T
Definition typeinfo.h:149
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682
constexpr int LexicographicalCompare(const VECTOR2< T > &aA, const VECTOR2< T > &aB)
Definition vector2d.h:632
#define ZOOM_MIN_LIMIT_EESCHEMA
#define ZOOM_MAX_LIMIT_EESCHEMA