KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pad_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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20
21#include "pad_tool.h"
22#include "pcb_painter.h"
23#include <kiplatform/ui.h>
24#include <macros.h>
26#include <view/view_controls.h>
27#include <tool/tool_manager.h>
29#include <board_item.h>
30#include <collectors.h>
31#include <footprint.h>
32#include <pcb_shape.h>
33#include <pad.h>
34#include <pcbnew_settings.h>
35#include <board_commit.h>
38#include <tools/pcb_actions.h>
42#include <tools/edit_tool.h>
44#include <widgets/wx_infobar.h>
45
46
48
49
55
56
58{
59 if( aReason == MODEL_RELOAD )
60 m_lastPadNumber = wxT( "1" );
61
62 if( board() && board()->ResolveItem( m_editPad ) == DELETED_BOARD_ITEM::GetInstance() )
63 {
64 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
65
67 {
69 frame()->SetDisplayOptions( opts );
70 }
71
72 frame()->GetInfoBar()->Dismiss();
73
75 }
76}
77
78
80{
81 static const std::vector<KICAD_T> padTypes = { PCB_PAD_T };
82
83 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
84
85 if( selTool )
86 {
87 // Add context menu entries that are displayed when selection tool is active
88 CONDITIONAL_MENU& menu = selTool->GetToolMenu().GetMenu();
89
93
94 auto explodeCondition =
95 [this]( const SELECTION& aSel )
96 {
97 return m_editPad == niluuid && aSel.Size() == 1 && aSel[0]->Type() == PCB_PAD_T;
98 };
99
100 auto recombineCondition =
101 [this]( const SELECTION& aSel )
102 {
103 return m_editPad != niluuid;
104 };
105
106 menu.AddSeparator( 400 );
107
109 {
112 menu.AddItem( PCB_ACTIONS::recombinePad, recombineCondition, 400 );
113 menu.AddItem( PCB_ACTIONS::explodePad, explodeCondition, 400 );
114 }
115
116 menu.AddItem( PCB_ACTIONS::copyPadSettings, singlePadSel, 400 );
117 menu.AddItem( PCB_ACTIONS::applyPadSettings, padSel, 400 );
118 menu.AddItem( PCB_ACTIONS::pushPadSettings, singlePadSel, 400 );
119 }
120
121 auto& ctxMenu = m_menu->GetMenu();
122
123 // cancel current tool goes in main context menu at the top if present
125 ctxMenu.AddSeparator( 1 );
126
133
134 // Finally, add the standard zoom/grid items
135 getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( *m_menu.get() );
136
137 return true;
138}
139
140
142{
143 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
144 const PCB_SELECTION& selection = selTool->GetSelection();
145 const PAD* masterPad = frame()->GetDesignSettings().m_Pad_Master.get();
146
147 BOARD_COMMIT commit( frame() );
148
149 // for every selected pad, paste global settings
150 for( EDA_ITEM* item : selection )
151 {
152 if( item->Type() == PCB_PAD_T )
153 {
154 commit.Modify( item );
155 static_cast<PAD&>( *item ).ImportSettingsFrom( *masterPad );
156 }
157 }
158
159 commit.Push( _( "Paste Pad Properties" ) );
160
162 frame()->Refresh();
163
164 return 0;
165}
166
167
169{
170 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
171 const PCB_SELECTION& selection = selTool->GetSelection();
172
173 // can only copy from a single pad
174 if( selection.Size() == 1 )
175 {
176 EDA_ITEM* item = selection[0];
177
178 if( item->Type() == PCB_PAD_T )
179 {
180 const PAD& selPad = static_cast<const PAD&>( *item );
181 frame()->GetDesignSettings().m_Pad_Master->ImportSettingsFrom( selPad );
182 }
183 }
184
185 return 0;
186}
187
188
189static void doPushPadProperties( BOARD& board, const PAD& aSrcPad, BOARD_COMMIT& commit,
190 bool aSameFootprints, bool aPadShapeFilter, bool aPadOrientFilter,
191 bool aPadLayerFilter, bool aPadTypeFilter )
192{
193 const FOOTPRINT* refFootprint = aSrcPad.GetParentFootprint();
194
195 EDA_ANGLE srcPadAngle = aSrcPad.GetOrientation() - refFootprint->GetOrientation();
196
197 for( FOOTPRINT* footprint : board.Footprints() )
198 {
199 if( !aSameFootprints && ( footprint != refFootprint ) )
200 continue;
201
202 if( footprint->GetFPID() != refFootprint->GetFPID() )
203 continue;
204
205 for( PAD* pad : footprint->Pads() )
206 {
207 // TODO(JE) padstacks
208 if( aPadShapeFilter && pad->GetShape( PADSTACK::ALL_LAYERS ) != aSrcPad.GetShape( PADSTACK::ALL_LAYERS ) )
209 continue;
210
211 EDA_ANGLE padAngle = pad->GetOrientation() - footprint->GetOrientation();
212
213 if( aPadOrientFilter && ( padAngle != srcPadAngle ) )
214 continue;
215
216 if( aPadLayerFilter && ( pad->GetLayerSet() != aSrcPad.GetLayerSet() ) )
217 continue;
218
219 if( aPadTypeFilter && ( pad->GetAttribute() != aSrcPad.GetAttribute() ) )
220 continue;
221
222 // Special-case for aperture pads
223 if( aPadTypeFilter && pad->GetAttribute() == PAD_ATTRIB::CONN )
224 {
225 if( pad->IsAperturePad() != aSrcPad.IsAperturePad() )
226 continue;
227 }
228
229 commit.Modify( pad );
230
231 // Apply source pad settings to this pad
232 pad->ImportSettingsFrom( aSrcPad );
233 }
234 }
235}
236
237
239{
240 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
241 const PCB_SELECTION& selection = selTool->GetSelection();
242
243 if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
244 {
245 PAD* srcPad = static_cast<PAD*>( selection[0] );
246
247 if( FOOTPRINT* footprint = srcPad->GetParentFootprint() )
248 {
249 frame()->SetMsgPanel( footprint );
250
252 int dialogRet = dlg.ShowModal();
253
254 if( dialogRet == wxID_CANCEL )
255 return 0;
256
257 const bool edit_Same_Modules = (dialogRet == 1);
258
259 BOARD_COMMIT commit( frame() );
260
261 doPushPadProperties( *getModel<BOARD>(), *srcPad, commit, edit_Same_Modules, dlg.GetPadShapeFilter(),
263
264 commit.Push( _( "Push Pad Settings" ) );
265
267 frame()->Refresh();
268 }
269 }
270
271 return 0;
272}
273
274
281static std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS> GetSequentialPadNumberingParams( wxWindow* aFrame )
282{
283 // Persistent settings for the pad enumeration dialog.
284 static SEQUENTIAL_PAD_ENUMERATION_PARAMS s_lastUsedParams;
285
286 DIALOG_ENUM_PADS settingsDlg( aFrame, s_lastUsedParams );
287
288 if( settingsDlg.ShowModal() != wxID_OK )
289 return std::nullopt;
290
291 return s_lastUsedParams;
292}
293
294
296{
298 return 0;
299
300 if( !board()->GetFirstFootprint() || board()->GetFirstFootprint()->Pads().empty() )
301 return 0;
302
303 GENERAL_COLLECTOR collector;
304 GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide();
305 guide.SetIgnoreFPTextOnBack( true );
306 guide.SetIgnoreFPTextOnFront( true );
307 guide.SetIgnoreFPValues( true );
308 guide.SetIgnoreFPReferences( true );
309
310 const std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS> params = GetSequentialPadNumberingParams( frame() );
311
312 // Cancelled or otherwise failed to get any useful parameters
313 if( !params )
314 return 0;
315
316 int seqPadNum = params->m_start_number;
317
318 std::deque<int> storedPadNumbers;
319 std::map<wxString, std::pair<int, wxString>> oldNumbers;
320
322
323 frame()->PushTool( aEvent );
324
325 VECTOR2I oldMousePos; // store the previous mouse cursor position, during mouse drag
326 std::list<PAD*> selectedPads;
327 BOARD_COMMIT commit( frame() );
328 bool isFirstPoint = true; // make sure oldMousePos is initialized at least once
329 std::deque<PAD*> pads = board()->GetFirstFootprint()->Pads();
330 MAGNETIC_SETTINGS mag_settings;
331
332 mag_settings.graphics = false;
333 mag_settings.tracks = MAGNETIC_OPTIONS::NO_EFFECT;
335
336 PCB_GRID_HELPER grid( m_toolMgr, &mag_settings );
337
338 grid.SetSnap( true );
339 grid.SetUseGrid( false );
340
341 auto setCursor =
342 [&]()
343 {
345 };
346
347 KIGFX::VIEW* view = m_toolMgr->GetView();
348 RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
349 const std::set<int>& activeLayers = settings->GetHighContrastLayers();
350 bool isHighContrast = settings->GetHighContrast();
351
352 auto checkVisibility =
353 [&]( BOARD_ITEM* item )
354 {
355 if( !view->IsVisible( item ) )
356 return false;
357
358 for( PCB_LAYER_ID layer : item->GetLayerSet() )
359 {
360 if( ( isHighContrast && activeLayers.count( layer ) ) || view->IsLayerVisible( layer ) )
361 {
362 if( item->ViewGetLOD( layer, view ) < view->GetScale() )
363 return true;
364 }
365 }
366
367 return false;
368 };
369
370 for( PAD* pad : board()->GetFirstFootprint()->Pads() )
371 {
372 if( checkVisibility( pad ) )
373 pads.push_back( pad );
374 }
375
376 Activate();
377 // Must be done after Activate() so that it gets set into the correct context
378 getViewControls()->ShowCursor( true );
380 // Set initial cursor
381 setCursor();
382
383 STATUS_TEXT_POPUP statusPopup( frame() );
384
385 // Callable lambda to construct the pad number string for the given value
386 const auto constructPadNumber =
387 [&]( int aValue )
388 {
389 return wxString::Format( wxT( "%s%d" ), params->m_prefix.value_or( "" ), aValue );
390 };
391
392 // Callable lambda to set the popup text for the given pad value
393 const auto setPopupTextForValue =
394 [&]( int aValue )
395 {
396 const wxString msg = _( "Click on pad %s\n"
397 "Press <esc> to cancel all; double-click to finish" );
398 statusPopup.SetText( wxString::Format( msg, constructPadNumber( aValue ) ) );
399 };
400
401 setPopupTextForValue( seqPadNum );
402 statusPopup.Popup();
403 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
404 canvas()->SetStatusPopup( statusPopup.GetPanel() );
405
406 while( TOOL_EVENT* evt = Wait() )
407 {
408 setCursor();
409
411 VECTOR2I cursorPos = grid.SnapToPad( mousePos, pads );
412 getViewControls()->ForceCursorPosition( true, cursorPos );
413
414 if( evt->IsCancelInteractive() )
415 {
417 commit.Revert();
418
419 frame()->PopTool( aEvent );
420 break;
421 }
422 else if( evt->IsActivate() )
423 {
424 commit.Push( _( "Renumber Pads" ) );
425
426 frame()->PopTool( aEvent );
427 break;
428 }
429 else if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
430 {
431 selectedPads.clear();
432
433 // Be sure the old cursor mouse position was initialized:
434 if( isFirstPoint )
435 {
436 oldMousePos = mousePos;
437 isFirstPoint = false;
438 }
439
440 // wxWidgets deliver mouse move events not frequently enough, resulting in skipping
441 // pads if the user moves cursor too fast. To solve it, create a line that approximates
442 // the mouse move and search pads that are on the line.
443 int distance = ( mousePos - oldMousePos ).EuclideanNorm();
444 // Search will be made every 0.1 mm:
445 int segments = distance / int( 0.1 * pcbIUScale.IU_PER_MM ) + 1;
446 const VECTOR2I line_step( ( mousePos - oldMousePos ) / segments );
447
448 collector.Empty();
449
450 for( int j = 0; j < segments; ++j )
451 {
452 VECTOR2I testpoint( mousePos.x - j * line_step.x, mousePos.y - j * line_step.y );
453 collector.Collect( board(), { PCB_PAD_T }, testpoint, guide );
454
455 for( int i = 0; i < collector.GetCount(); ++i )
456 {
457 PAD* pad = static_cast<PAD*>( collector[i] );
458
459 if( pad->CanHaveNumber() && checkVisibility( pad ) )
460 selectedPads.push_back( pad );
461 }
462 }
463
464 selectedPads.unique();
465
466 for( PAD* pad : selectedPads )
467 {
468 // If pad was not selected, then enumerate it
469 if( !pad->IsSelected() )
470 {
471 commit.Modify( pad );
472
473 // Rename pad and store the old name
474 int newval;
475
476 if( storedPadNumbers.size() > 0 )
477 {
478 newval = storedPadNumbers.front();
479 storedPadNumbers.pop_front();
480 }
481 else
482 {
483 newval = seqPadNum;
484 seqPadNum += params->m_step;
485 }
486
487 const wxString newNumber = constructPadNumber( newval );
488 oldNumbers[newNumber] = { newval, pad->GetNumber() };
489 pad->SetNumber( newNumber );
490 SetLastPadNumber( newNumber );
491 pad->SetSelected();
492 getView()->Update( pad );
493
494 // Ensure the popup text shows the correct next value
495 if( storedPadNumbers.size() > 0 )
496 newval = storedPadNumbers.front();
497 else
498 newval = seqPadNum;
499
500 setPopupTextForValue( newval );
501 }
502
503 // ... or restore the old name if it was enumerated and clicked again
504 else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
505 {
506 auto it = oldNumbers.find( pad->GetNumber() );
507 wxASSERT( it != oldNumbers.end() );
508
509 if( it != oldNumbers.end() )
510 {
511 storedPadNumbers.push_back( it->second.first );
512 pad->SetNumber( it->second.second );
513 SetLastPadNumber( it->second.second );
514 oldNumbers.erase( it );
515
516 const int newval = storedPadNumbers.front();
517 setPopupTextForValue( newval );
518 }
519
520 pad->ClearSelected();
521 getView()->Update( pad );
522 }
523 }
524 }
525 else if( evt->IsDblClick( BUT_LEFT ) )
526 {
527 commit.Push( _( "Renumber Pads" ) );
528 frame()->PopTool( aEvent );
529 break;
530 }
531 else if( evt->IsClick( BUT_RIGHT ) )
532 {
533 m_menu->ShowContextMenu( selection() );
534 }
535 else
536 {
537 evt->SetPassEvent();
538 }
539
540 // Prepare the next loop by updating the old cursor mouse position
541 // to this last mouse cursor position
542 oldMousePos = mousePos;
543 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
544 }
545
546 for( PAD* p : board()->GetFirstFootprint()->Pads() )
547 {
548 p->ClearSelected();
549 getView()->Update( p );
550 }
551
552 canvas()->SetStatusPopup( nullptr );
553 statusPopup.Hide();
554
557 return 0;
558}
559
560
561int PAD_TOOL::PlacePad( const TOOL_EVENT& aEvent )
562{
563 // When creating a new pad (in FP editor) we can use a new pad number or the last entered pad number
564 // neednewPadNumber = true to create a new pad number, false to use the last entered pad number
565 static bool neednewPadNumber;
566
568 return 0;
569
570 if( !board()->GetFirstFootprint() )
571 return 0;
572
573 struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
574 {
575 PAD_PLACER( PAD_TOOL* aPadTool, PCB_BASE_EDIT_FRAME* aFrame ) :
576 m_padTool( aPadTool ),
577 m_frame( aFrame ),
578 m_gridHelper( aPadTool->GetManager(), aFrame->GetMagneticItemsSettings() )
579 {
580 neednewPadNumber = true; // Use a new pad number when creatin a pad by default
581 }
582
583 virtual ~PAD_PLACER() = default;
584
585 std::unique_ptr<BOARD_ITEM> CreateItem() override
586 {
587 // TODO(JE) padstacks
588 PAD* pad = new PAD( m_board->GetFirstFootprint() );
589 PAD* master = m_frame->GetDesignSettings().m_Pad_Master.get();
590
591 pad->ImportSettingsFrom( *master );
592
593 if( pad->CanHaveNumber() )
594 {
595 wxString padNumber = m_padTool->GetLastPadNumber();
596
597 // Use the last entered pad number when recreating a pad without using the
598 // previously created pad, and a new number when creating a really new pad
599 if( neednewPadNumber )
600 padNumber = m_board->GetFirstFootprint()->GetNextPadNumber( padNumber );
601
602 pad->SetNumber( padNumber );
603 m_padTool->SetLastPadNumber( padNumber );
604
605 // If a pad is recreated and the previously created was not placed, use
606 // the last entered pad number
607 neednewPadNumber = false;
608 }
609
610 return std::unique_ptr<BOARD_ITEM>( pad );
611 }
612
613 bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
614 {
615 PAD* pad = dynamic_cast<PAD*>( aItem );
616 // We are using this pad number.
617 // therefore use a new pad number for a newly created pad
618 neednewPadNumber = true;
619
620 if( pad )
621 {
622 m_frame->GetDesignSettings().m_Pad_Master->ImportSettingsFrom( *pad );
623 aCommit.Add( aItem );
624 return true;
625 }
626
627 return false;
628 }
629
630 void SnapItem( BOARD_ITEM *aItem ) override
631 {
632 m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
633 m_gridHelper.SetUseGrid( !( m_modifiers & MD_CTRL ) );
634
635 if( !m_gridHelper.GetSnap() )
636 return;
637
638 MAGNETIC_SETTINGS* settings = m_frame->GetMagneticItemsSettings();
639 PAD* pad = static_cast<PAD*>( aItem );
640 VECTOR2I position = m_padTool->getViewControls()->GetMousePosition();
641 KIGFX::VIEW_CONTROLS* viewControls = m_padTool->getViewControls();
642 std::vector<BOARD_ITEM*> ignored_items( 1, pad );
643
644 if( settings->pads == MAGNETIC_OPTIONS::NO_EFFECT )
645 {
646 PADS& pads = m_board->GetFirstFootprint()->Pads();
647 ignored_items.insert( ignored_items.end(), pads.begin(), pads.end() );
648 }
649
650 if( !settings->graphics )
651 {
652 DRAWINGS& graphics = m_board->GetFirstFootprint()->GraphicalItems();
653 ignored_items.insert( ignored_items.end(), graphics.begin(), graphics.end() );
654 }
655
656 VECTOR2I cursorPos = m_gridHelper.BestSnapAnchor( position, LSET::AllLayersMask(), GRID_CURRENT,
657 ignored_items );
658 viewControls->ForceCursorPosition( true, cursorPos );
659 aItem->SetPosition( cursorPos );
660 }
661
662 PAD_TOOL* m_padTool;
663 PCB_BASE_EDIT_FRAME* m_frame;
664 PCB_GRID_HELPER m_gridHelper;
665 };
666
667 PAD_PLACER placer( this, frame() );
668
669 doInteractiveItemPlacement( aEvent, &placer, _( "Place pad" ),
671
672 return 0;
673}
674
675
676int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent )
677{
679 return 0;
680
681 Activate();
682
683 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
684 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
685 PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
686
687 if( m_editPad != niluuid )
688 {
689 if( PAD* pad = dynamic_cast<PAD*>( frame()->ResolveItem( m_editPad ) ) )
690 {
691 BOARD_COMMIT commit( frame() );
692 commit.Modify( pad );
693
694 std::vector<PCB_SHAPE*> mergedShapes = RecombinePad( pad, false );
695
696 for( PCB_SHAPE* shape : mergedShapes )
697 commit.Remove( shape );
698
699 commit.Push( _( "Edit Pad" ) );
700 }
701
703 }
704 else if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
705 {
706 PCB_LAYER_ID layer;
707 PAD* pad = static_cast<PAD*>( selection[0] );
708 BOARD_COMMIT commit( frame() );
709
710 commit.Modify( pad );
711 explodePad( pad, &layer, commit );
712 commit.Push( _( "Edit Pad" ) );
713
715 frame()->SetActiveLayer( layer );
716
717 settings->m_PadEditModePad = pad;
719 }
720
721 if( m_editPad == niluuid )
723
724 return 0;
725}
726
727
729{
730 PAD* flaggedPad = nullptr;
731 KIID flaggedPadId = niluuid;
732
733 for( FOOTPRINT* fp : board()->Footprints() )
734 {
735 for( PAD* pad : fp->Pads() )
736 {
737 if( pad->IsEntered() )
738 {
739 flaggedPad = pad;
740 flaggedPadId = pad->m_Uuid;
741 break;
742 }
743 }
744 }
745
746 if( flaggedPadId != m_editPad )
747 {
748 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
749 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
750
751 m_editPad = flaggedPadId;
752 settings->m_PadEditModePad = flaggedPad;
753
754 if( flaggedPad )
756 else
758 }
759
760 return 0;
761}
762
763
765{
766 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
767 WX_INFOBAR* infoBar = frame()->GetInfoBar();
768 wxString msg;
769
771 [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
772 {
773 return dynamic_cast<PAD*>( aItem ) != nullptr;
774 } );
775
777
779 {
781 frame()->SetDisplayOptions( opts );
782 }
783
784 if( PCB_ACTIONS::explodePad.GetHotKey() == PCB_ACTIONS::recombinePad.GetHotKey() )
785 {
786 msg.Printf( _( "Pad Edit Mode. Press %s again to exit." ),
788 }
789 else
790 {
791 msg.Printf( _( "Pad Edit Mode. Press %s to exit." ),
793 }
794
795 infoBar->RemoveAllButtons();
796 infoBar->ShowMessage( msg, wxICON_INFORMATION );
797}
798
799
801{
802 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
803 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
804 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
805
806 settings->m_PadEditModePad = nullptr;
807
809 {
811 frame()->SetDisplayOptions( opts );
812 }
813
814 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
815 // they won't be found in the view layer's itemset for re-painting.
817 [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
818 {
819 return dynamic_cast<PAD*>( aItem ) != nullptr;
820 } );
821
822 // Refresh now (otherwise there's an uncomfortably long pause while the infoBar
823 // closes before refresh).
824 canvas()->ForceRefresh();
825
826 frame()->GetInfoBar()->Dismiss();
827}
828
829
830void PAD_TOOL::explodePad( PAD* aPad, PCB_LAYER_ID* aLayer, BOARD_COMMIT& aCommit )
831{
832 if( aPad->IsOnLayer( F_Cu ) )
833 *aLayer = F_Cu;
834 else if( aPad->IsOnLayer( B_Cu ) )
835 *aLayer = B_Cu;
836 else
837 *aLayer = aPad->GetLayerSet().UIOrder().front();
838
839 // TODO(JE) padstacks
841 {
842 for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives( PADSTACK::ALL_LAYERS ) )
843 {
844 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( primitive->Duplicate( true, &aCommit ) );
845
846 shape->SetParent( board()->GetFirstFootprint() );
847 shape->Rotate( VECTOR2I( 0, 0 ), aPad->GetOrientation() );
848 shape->Move( aPad->ShapePos( PADSTACK::ALL_LAYERS ) );
849 shape->SetLayer( *aLayer );
850
851 if( shape->IsProxyItem() && shape->GetShape() == SHAPE_T::SEGMENT )
852 {
853 if( aPad->GetLocalThermalSpokeWidthOverride().has_value() )
854 shape->SetWidth( aPad->GetLocalThermalSpokeWidthOverride().value() );
855 else
857 }
858
859 aCommit.Add( shape );
860 }
861
862 // TODO(JE) padstacks
864 aPad->DeletePrimitivesList();
865 }
866
867 aPad->SetFlags( ENTERED );
868 m_editPad = aPad->m_Uuid;
869}
870
871
872std::vector<PCB_SHAPE*> PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun )
873{
874 int maxError = board()->GetDesignSettings().m_MaxError;
875
876 // Don't leave an object in the point editor that might no longer exist after recombining.
878
879 return aPad->Recombine( aIsDryRun, maxError );
880}
881
882int PAD_TOOL::PadTable( const TOOL_EVENT& aEvent )
883{
885 return 0;
886
888
889 if( !footprint )
890 return 0;
891
893 dlg.ShowQuasiModal();
894
895 return 0;
896}
897
898
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
HIGH_CONTRAST_MODE
Determine how inactive layers should be displayed.
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
@ DIMMED
Inactive layers are dimmed (old high-contrast mode)
static TOOL_ACTION cancelInteractive
Definition actions.h:68
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
FOOTPRINT * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:587
const FOOTPRINTS & Footprints() const
Definition board.h:420
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition board.cpp:1149
void Empty()
Clear the list.
Definition collector.h:87
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
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
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
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.
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:543
Dialog for enumerating pads.
int ShowModal() override
void ForceRefresh()
Force a redraw.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
void SetStatusPopup(wxWindow *aPopup)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:283
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:152
const KIID m_Uuid
Definition eda_item.h:531
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:89
SHAPE_T GetShape() const
Definition eda_shape.h:185
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:348
static const TOOL_EVENT UndoRedoPostEvent
Definition actions.h:365
EDA_ANGLE GetOrientation() const
Definition footprint.h:406
std::deque< PAD * > & Pads()
Definition footprint.h:375
const LIB_ID & GetFPID() const
Definition footprint.h:441
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
void SetIgnoreFPTextOnFront(bool ignore)
Definition collectors.h:412
void SetIgnoreFPTextOnBack(bool ignore)
Definition collectors.h:406
void SetIgnoreFPReferences(bool ignore)
Definition collectors.h:454
void SetIgnoreFPValues(bool ignore)
Definition collectors.h:448
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
void Collect(BOARD_ITEM *aItem, const std::vector< KICAD_T > &aScanList, const VECTOR2I &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:78
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const std::set< int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:63
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition view.cpp:1835
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:225
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition view.cpp:1702
Definition kiid.h:44
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:739
static const LSET & AllLayersMask()
Definition lset.cpp:637
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:177
void Reset(RESET_REASON aReason) override
Basic initialization.
Definition pad_tool.cpp:57
int OnUndoRedo(const TOOL_EVENT &aEvent)
Definition pad_tool.cpp:728
HIGH_CONTRAST_MODE m_previousHighContrastMode
Definition pad_tool.h:93
void explodePad(PAD *aPad, PCB_LAYER_ID *aLayer, BOARD_COMMIT &aCommit)
Definition pad_tool.cpp:830
void setTransitions() override
< Bind handlers to corresponding TOOL_ACTIONs.
Definition pad_tool.cpp:899
int EditPad(const TOOL_EVENT &aEvent)
Enter/exit WYSIWYG pad shape editing.
Definition pad_tool.cpp:676
void ExitPadEditMode()
Definition pad_tool.cpp:800
KIID m_editPad
Definition pad_tool.h:94
int copyPadSettings(const TOOL_EVENT &aEvent)
Push pad settings from a pad to other pads on board or footprint.
Definition pad_tool.cpp:168
void enterPadEditMode()
Definition pad_tool.cpp:764
int pastePadProperties(const TOOL_EVENT &aEvent)
Copy pad settings from a pad to the board design settings.
Definition pad_tool.cpp:141
int PlacePad(const TOOL_EVENT &aEvent)
Place a pad in footprint editor.
Definition pad_tool.cpp:561
int EnumeratePads(const TOOL_EVENT &aEvent)
Tool for quick pad enumeration.
Definition pad_tool.cpp:295
int PadTable(const TOOL_EVENT &aEvent)
Definition pad_tool.cpp:882
bool Init() override
Init() is called once upon a registration of the tool.
Definition pad_tool.cpp:79
void SetLastPadNumber(const wxString &aPadNumber)
Definition pad_tool.h:63
std::vector< PCB_SHAPE * > RecombinePad(PAD *aPad, bool aIsDryRun)
Recombine an exploded pad (or one produced with overlapping polygons in an older version).
Definition pad_tool.cpp:872
bool InPadEditMode()
Definition pad_tool.h:59
wxString m_lastPadNumber
Definition pad_tool.h:91
int pushPadSettings(const TOOL_EVENT &aEvent)
Definition pad_tool.cpp:238
Definition pad.h:61
bool IsAperturePad() const
Definition pad.h:562
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:552
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
Definition pad.h:370
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition pad.h:912
PAD_ATTRIB GetAttribute() const
Definition pad.h:555
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
Definition pad.h:193
std::vector< PCB_SHAPE * > Recombine(bool aIsDryRun, int aMaxError)
Recombines the pad with other graphical shapes in the footprint.
Definition pad.cpp:3051
void DeletePrimitivesList(PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Clear the basic shapes list.
Definition pad.cpp:3606
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:202
void ImportSettingsFrom(const PAD &aMasterPad)
Import the pad settings from aMasterPad.
Definition pad.cpp:2848
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1723
std::optional< int > GetLocalThermalSpokeWidthOverride() const
Definition pad.h:729
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1831
PAD_SHAPE GetAnchorPadShape(PCB_LAYER_ID aLayer) const
Definition pad.h:216
static TOOL_ACTION recombinePad
static TOOL_ACTION enumeratePads
Tool for quick pad enumeration.
static TOOL_ACTION pushPadSettings
Copy the current pad's settings to other pads in the footprint or on the board.
static TOOL_ACTION mirrorH
Mirroring of selected items.
static TOOL_ACTION copyPadSettings
Copy the selected pad's settings to the board design settings.
static TOOL_ACTION placePad
Activation of the drawing tool (placing a PAD)
static TOOL_ACTION padTable
static TOOL_ACTION properties
Activation of the edit tool.
static TOOL_ACTION explodePad
static TOOL_ACTION applyPadSettings
Copy the default pad settings to the selected pad.
static TOOL_ACTION mirrorV
static TOOL_ACTION flip
Flipping of selected objects.
static TOOL_ACTION rotateCw
Rotation of selected objects.
static TOOL_ACTION rotateCcw
Common, abstract interface for edit frames.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetWidth(int aWidth) override
bool IsProxyItem() const override
Definition pcb_shape.h:146
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
T * frame() const
KIGFX::PCB_VIEW * view() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
@ IPO_FLIP
Handle flip action in the loop by calling the item's flip method.
@ IPO_ROTATE
Handle the rotate action in the loop by calling the item's rotate method.
@ IPO_SINGLE_CLICK
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
@ IPO_REPEAT
Allow repeat placement of the item.
void doInteractiveItemPlacement(const TOOL_EVENT &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
Helper function for performing a common interactive idiom: wait for a left click, place an item there...
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
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 bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
wxWindow * GetPanel()
virtual void Popup(wxWindow *aFocus=nullptr)
virtual void Move(const wxPoint &aWhere)
Extension of STATUS_POPUP for displaying a single line text.
void SetText(const wxString &aText)
Display a text.
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition tool_base.h:142
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:195
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition tool_base.cpp:34
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
Generic, UI-independent tool event.
Definition tool_event.h:167
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
TOOL_MENU & GetToolMenu()
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void Activate()
Run the tool.
CONDITIONAL_MENU & GetMenu()
Definition tool_menu.cpp:40
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
@ ARROW
Definition cursors.h:42
@ BULLSEYE
Definition cursors.h:54
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
#define ENTERED
indicates a group has been entered
@ SEGMENT
Definition eda_shape.h:46
static const std::vector< KICAD_T > padTypes
@ GRID_CURRENT
Definition grid_helper.h:42
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
NORMAL
Follows standard pretty-printing rules.
KIID niluuid(0)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ ALL
All except INITIAL_ADD.
Definition view_item.h:55
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
Definition wxgtk/ui.cpp:766
static void doPushPadProperties(BOARD &board, const PAD &aSrcPad, BOARD_COMMIT &commit, bool aSameFootprints, bool aPadShapeFilter, bool aPadOrientFilter, bool aPadLayerFilter, bool aPadTypeFilter)
Definition pad_tool.cpp:189
static std::optional< SEQUENTIAL_PAD_ENUMERATION_PARAMS > GetSequentialPadNumberingParams(wxWindow *aFrame)
Prompts the user for parameters for sequential pad numbering.
Definition pad_tool.cpp:281
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
Definition padstack.h:100
std::deque< PAD * > PADS
std::deque< BOARD_ITEM * > DRAWINGS
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
MAGNETIC_OPTIONS tracks
MAGNETIC_OPTIONS pads
Parameters for sequential pad numbering.
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:80
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM
Definition zones.h:29