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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
25#include "pad_tool.h"
26#include "pcb_painter.h"
27#include <kiplatform/ui.h>
28#include <macros.h>
30#include <view/view_controls.h>
31#include <tool/tool_manager.h>
33#include <board_item.h>
34#include <footprint.h>
35#include <pcb_shape.h>
36#include <pad.h>
37#include <pcbnew_settings.h>
38#include <board_commit.h>
40#include <tools/pcb_actions.h>
44#include <tools/edit_tool.h>
46#include <widgets/wx_infobar.h>
47
48
50
51
53 PCB_TOOL_BASE( "pcbnew.PadTool" ),
54 m_previousHighContrastMode( HIGH_CONTRAST_MODE::NORMAL ),
55 m_editPad( niluuid )
56{}
57
58
60{
61 if( aReason == MODEL_RELOAD )
62 m_lastPadNumber = wxT( "1" );
63
64 if( board() && board()->ResolveItem( m_editPad ) == DELETED_BOARD_ITEM::GetInstance() )
65 {
66 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
67
69 {
71 frame()->SetDisplayOptions( opts );
72 }
73
74 frame()->GetInfoBar()->Dismiss();
75
77 }
78}
79
80
82{
83 static const std::vector<KICAD_T> padTypes = { PCB_PAD_T };
84
86
87 if( selTool )
88 {
89 // Add context menu entries that are displayed when selection tool is active
90 CONDITIONAL_MENU& menu = selTool->GetToolMenu().GetMenu();
91
95
96 auto explodeCondition =
97 [&]( const SELECTION& aSel )
98 {
99 return m_editPad == niluuid && aSel.Size() == 1 && aSel[0]->Type() == PCB_PAD_T;
100 };
101
102 auto recombineCondition =
103 [&]( const SELECTION& aSel )
104 {
105 return m_editPad != niluuid;
106 };
107
108 menu.AddSeparator( 400 );
109
111 {
113 menu.AddItem( PCB_ACTIONS::recombinePad, recombineCondition, 400 );
114 menu.AddItem( PCB_ACTIONS::explodePad, explodeCondition, 400 );
115 }
116
117 menu.AddItem( PCB_ACTIONS::copyPadSettings, singlePadSel, 400 );
118 menu.AddItem( PCB_ACTIONS::applyPadSettings, padSel, 400 );
119 menu.AddItem( PCB_ACTIONS::pushPadSettings, singlePadSel, 400 );
120 }
121
122 auto& ctxMenu = m_menu->GetMenu();
123
124 // cancel current tool goes in main context menu at the top if present
126 ctxMenu.AddSeparator( 1 );
127
134
135 // Finally, add the standard zoom/grid items
136 getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( *m_menu.get() );
137
138 return true;
139}
140
141
143{
145 const PCB_SELECTION& selection = selTool->GetSelection();
146 const PAD* masterPad = frame()->GetDesignSettings().m_Pad_Master.get();
147
148 BOARD_COMMIT commit( frame() );
149
150 // for every selected pad, paste global settings
151 for( EDA_ITEM* item : selection )
152 {
153 if( item->Type() == PCB_PAD_T )
154 {
155 commit.Modify( item );
156 static_cast<PAD&>( *item ).ImportSettingsFrom( *masterPad );
157 }
158 }
159
160 commit.Push( _( "Paste Pad Properties" ) );
161
163 frame()->Refresh();
164
165 return 0;
166}
167
168
170{
172 const PCB_SELECTION& selection = selTool->GetSelection();
173
174 // can only copy from a single pad
175 if( selection.Size() == 1 )
176 {
177 EDA_ITEM* item = selection[0];
178
179 if( item->Type() == PCB_PAD_T )
180 {
181 const PAD& selPad = static_cast<const PAD&>( *item );
182 frame()->GetDesignSettings().m_Pad_Master->ImportSettingsFrom( selPad );
183 }
184 }
185
186 return 0;
187}
188
189
190static void doPushPadProperties( BOARD& board, const PAD& aSrcPad, BOARD_COMMIT& commit,
191 bool aSameFootprints, bool aPadShapeFilter, bool aPadOrientFilter,
192 bool aPadLayerFilter, bool aPadTypeFilter )
193{
194 const FOOTPRINT* refFootprint = aSrcPad.GetParentFootprint();
195
196 EDA_ANGLE srcPadAngle = aSrcPad.GetOrientation() - refFootprint->GetOrientation();
197
198 for( FOOTPRINT* footprint : board.Footprints() )
199 {
200 if( !aSameFootprints && ( footprint != refFootprint ) )
201 continue;
202
203 if( footprint->GetFPID() != refFootprint->GetFPID() )
204 continue;
205
206 for( PAD* pad : footprint->Pads() )
207 {
208 // TODO(JE) padstacks
209 if( aPadShapeFilter && pad->GetShape( PADSTACK::ALL_LAYERS ) != aSrcPad.GetShape( PADSTACK::ALL_LAYERS ) )
210 continue;
211
212 EDA_ANGLE padAngle = pad->GetOrientation() - footprint->GetOrientation();
213
214 if( aPadOrientFilter && ( padAngle != srcPadAngle ) )
215 continue;
216
217 if( aPadLayerFilter && ( pad->GetLayerSet() != aSrcPad.GetLayerSet() ) )
218 continue;
219
220 if( aPadTypeFilter && ( pad->GetAttribute() != aSrcPad.GetAttribute() ) )
221 continue;
222
223 // Special-case for aperture pads
224 if( aPadTypeFilter && pad->GetAttribute() == PAD_ATTRIB::CONN )
225 {
226 if( pad->IsAperturePad() != aSrcPad.IsAperturePad() )
227 continue;
228 }
229
230 commit.Modify( pad );
231
232 // Apply source pad settings to this pad
233 pad->ImportSettingsFrom( aSrcPad );
234 }
235 }
236}
237
238
240{
242 const PCB_SELECTION& selection = selTool->GetSelection();
243
244 if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
245 {
246 PAD* srcPad = static_cast<PAD*>( selection[0] );
247
248 if( FOOTPRINT* footprint = srcPad->GetParentFootprint() )
249 {
250 frame()->SetMsgPanel( footprint );
251
253 int dialogRet = dlg.ShowModal();
254
255 if( dialogRet == wxID_CANCEL )
256 return 0;
257
258 const bool edit_Same_Modules = (dialogRet == 1);
259
260 BOARD_COMMIT commit( frame() );
261
262 doPushPadProperties( *getModel<BOARD>(), *srcPad, commit, edit_Same_Modules, dlg.GetPadShapeFilter(),
264
265 commit.Push( _( "Push Pad Settings" ) );
266
268 frame()->Refresh();
269 }
270 }
271
272 return 0;
273}
274
275
282static std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS> GetSequentialPadNumberingParams( wxWindow* aFrame )
283{
284 // Persistent settings for the pad enumeration dialog.
285 static SEQUENTIAL_PAD_ENUMERATION_PARAMS s_lastUsedParams;
286
287 DIALOG_ENUM_PADS settingsDlg( aFrame, s_lastUsedParams );
288
289 if( settingsDlg.ShowModal() != wxID_OK )
290 return std::nullopt;
291
292 return s_lastUsedParams;
293}
294
295
297{
299 return 0;
300
301 if( !board()->GetFirstFootprint() || board()->GetFirstFootprint()->Pads().empty() )
302 return 0;
303
304 GENERAL_COLLECTOR collector;
305 GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide();
306 guide.SetIgnoreFPTextOnBack( true );
307 guide.SetIgnoreFPTextOnFront( true );
308 guide.SetIgnoreFPValues( true );
309 guide.SetIgnoreFPReferences( true );
310
311 const std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS> params = GetSequentialPadNumberingParams( frame() );
312
313 // Cancelled or otherwise failed to get any useful parameters
314 if( !params )
315 return 0;
316
317 int seqPadNum = params->m_start_number;
318
319 std::deque<int> storedPadNumbers;
320 std::map<wxString, std::pair<int, wxString>> oldNumbers;
321
323
324 frame()->PushTool( aEvent );
325
326 VECTOR2I oldMousePos; // store the previous mouse cursor position, during mouse drag
327 std::list<PAD*> selectedPads;
328 BOARD_COMMIT commit( frame() );
329 bool isFirstPoint = true; // make sure oldMousePos is initialized at least once
330 std::deque<PAD*> pads = board()->GetFirstFootprint()->Pads();
331 MAGNETIC_SETTINGS mag_settings;
332
333 mag_settings.graphics = false;
334 mag_settings.tracks = MAGNETIC_OPTIONS::NO_EFFECT;
335 mag_settings.pads = MAGNETIC_OPTIONS::CAPTURE_ALWAYS;
336
337 PCB_GRID_HELPER grid( m_toolMgr, &mag_settings );
338
339 grid.SetSnap( true );
340 grid.SetUseGrid( false );
341
342 auto setCursor =
343 [&]()
344 {
345 canvas()->SetCurrentCursor( KICURSOR::BULLSEYE );
346 };
347
349 RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
350 const std::set<int>& activeLayers = settings->GetHighContrastLayers();
351 bool isHighContrast = settings->GetHighContrast();
352
353 auto checkVisibility =
354 [&]( BOARD_ITEM* item )
355 {
356 if( !view->IsVisible( item ) )
357 return false;
358
359 for( PCB_LAYER_ID layer : item->GetLayerSet() )
360 {
361 if( ( isHighContrast && activeLayers.count( layer ) ) || view->IsLayerVisible( layer ) )
362 {
363 if( item->ViewGetLOD( layer, view ) < view->GetScale() )
364 return true;
365 }
366 }
367
368 return false;
369 };
370
371 for( PAD* pad : board()->GetFirstFootprint()->Pads() )
372 {
373 if( checkVisibility( pad ) )
374 pads.push_back( pad );
375 }
376
377 Activate();
378 // Must be done after Activate() so that it gets set into the correct context
379 getViewControls()->ShowCursor( true );
381 // Set initial cursor
382 setCursor();
383
384 STATUS_TEXT_POPUP statusPopup( frame() );
385
386 // Callable lambda to construct the pad number string for the given value
387 const auto constructPadNumber =
388 [&]( int aValue )
389 {
390 return wxString::Format( wxT( "%s%d" ), params->m_prefix.value_or( "" ), aValue );
391 };
392
393 // Callable lambda to set the popup text for the given pad value
394 const auto setPopupTextForValue =
395 [&]( int aValue )
396 {
397 const wxString msg = _( "Click on pad %s\n"
398 "Press <esc> to cancel all; double-click to finish" );
399 statusPopup.SetText( wxString::Format( msg, constructPadNumber( aValue ) ) );
400 };
401
402 setPopupTextForValue( seqPadNum );
403 statusPopup.Popup();
404 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
405 canvas()->SetStatusPopup( statusPopup.GetPanel() );
406
407 while( TOOL_EVENT* evt = Wait() )
408 {
409 setCursor();
410
412 VECTOR2I cursorPos = grid.SnapToPad( mousePos, pads );
413 getViewControls()->ForceCursorPosition( true, cursorPos );
414
415 if( evt->IsCancelInteractive() )
416 {
418 commit.Revert();
419
420 frame()->PopTool( aEvent );
421 break;
422 }
423 else if( evt->IsActivate() )
424 {
425 commit.Push( _( "Renumber Pads" ) );
426
427 frame()->PopTool( aEvent );
428 break;
429 }
430 else if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
431 {
432 selectedPads.clear();
433
434 // Be sure the old cursor mouse position was initialized:
435 if( isFirstPoint )
436 {
437 oldMousePos = mousePos;
438 isFirstPoint = false;
439 }
440
441 // wxWidgets deliver mouse move events not frequently enough, resulting in skipping
442 // pads if the user moves cursor too fast. To solve it, create a line that approximates
443 // the mouse move and search pads that are on the line.
444 int distance = ( mousePos - oldMousePos ).EuclideanNorm();
445 // Search will be made every 0.1 mm:
446 int segments = distance / int( 0.1 * pcbIUScale.IU_PER_MM ) + 1;
447 const VECTOR2I line_step( ( mousePos - oldMousePos ) / segments );
448
449 collector.Empty();
450
451 for( int j = 0; j < segments; ++j )
452 {
453 VECTOR2I testpoint( mousePos.x - j * line_step.x, mousePos.y - j * line_step.y );
454 collector.Collect( board(), { PCB_PAD_T }, testpoint, guide );
455
456 for( int i = 0; i < collector.GetCount(); ++i )
457 {
458 PAD* pad = static_cast<PAD*>( collector[i] );
459
460 if( !pad->IsAperturePad() && checkVisibility( pad ) )
461 selectedPads.push_back( pad );
462 }
463 }
464
465 selectedPads.unique();
466
467 for( PAD* pad : selectedPads )
468 {
469 // If pad was not selected, then enumerate it
470 if( !pad->IsSelected() )
471 {
472 commit.Modify( pad );
473
474 // Rename pad and store the old name
475 int newval;
476
477 if( storedPadNumbers.size() > 0 )
478 {
479 newval = storedPadNumbers.front();
480 storedPadNumbers.pop_front();
481 }
482 else
483 {
484 newval = seqPadNum;
485 seqPadNum += params->m_step;
486 }
487
488 const wxString newNumber = constructPadNumber( newval );
489 oldNumbers[newNumber] = { newval, pad->GetNumber() };
490 pad->SetNumber( newNumber );
491 SetLastPadNumber( newNumber );
492 pad->SetSelected();
493 getView()->Update( pad );
494
495 // Ensure the popup text shows the correct next value
496 if( storedPadNumbers.size() > 0 )
497 newval = storedPadNumbers.front();
498 else
499 newval = seqPadNum;
500
501 setPopupTextForValue( newval );
502 }
503
504 // ... or restore the old name if it was enumerated and clicked again
505 else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
506 {
507 auto it = oldNumbers.find( pad->GetNumber() );
508 wxASSERT( it != oldNumbers.end() );
509
510 if( it != oldNumbers.end() )
511 {
512 storedPadNumbers.push_back( it->second.first );
513 pad->SetNumber( it->second.second );
514 SetLastPadNumber( it->second.second );
515 oldNumbers.erase( it );
516
517 const int newval = storedPadNumbers.front();
518 setPopupTextForValue( newval );
519 }
520
521 pad->ClearSelected();
522 getView()->Update( pad );
523 }
524 }
525 }
526 else if( evt->IsDblClick( BUT_LEFT ) )
527 {
528 commit.Push( _( "Renumber Pads" ) );
529 frame()->PopTool( aEvent );
530 break;
531 }
532 else if( evt->IsClick( BUT_RIGHT ) )
533 {
534 m_menu->ShowContextMenu( selection() );
535 }
536 else
537 {
538 evt->SetPassEvent();
539 }
540
541 // Prepare the next loop by updating the old cursor mouse position
542 // to this last mouse cursor position
543 oldMousePos = mousePos;
544 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
545 }
546
547 for( PAD* p : board()->GetFirstFootprint()->Pads() )
548 {
549 p->ClearSelected();
550 getView()->Update( p );
551 }
552
553 canvas()->SetStatusPopup( nullptr );
554 statusPopup.Hide();
555
556 canvas()->SetCurrentCursor( KICURSOR::ARROW );
558 return 0;
559}
560
561
562int PAD_TOOL::PlacePad( const TOOL_EVENT& aEvent )
563{
564 // When creating a new pad (in FP editor) we can use a new pad number
565 // or the last entered pad number
566 // neednewPadNumber = true to create a new pad number, false to use the last
567 // entered pad number
568 static bool neednewPadNumber;
569
571 return 0;
572
573 if( !board()->GetFirstFootprint() )
574 return 0;
575
576 struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
577 {
578 PAD_PLACER( PAD_TOOL* aPadTool, PCB_BASE_EDIT_FRAME* aFrame ) :
579 m_padTool( aPadTool ),
580 m_frame( aFrame ),
581 m_gridHelper( aPadTool->GetManager(), aFrame->GetMagneticItemsSettings() )
582 {
583 neednewPadNumber = true; // Use a new pad number when creatin a pad by default
584 }
585
586 virtual ~PAD_PLACER() = default;
587
588 std::unique_ptr<BOARD_ITEM> CreateItem() override
589 {
590 // TODO(JE) padstacks
591 PAD* pad = new PAD( m_board->GetFirstFootprint() );
592 PAD* master = m_frame->GetDesignSettings().m_Pad_Master.get();
593
594 pad->ImportSettingsFrom( *master );
595
596 // If the footprint type and master pad type directly conflict then make some
597 // adjustments. Otherwise assume the user set what they wanted.
598 // Note also a HEATSINK pad (thermal via) is allowed in SMD footprint
599 if( ( m_board->GetFirstFootprint()->GetAttributes() & FP_SMD )
600 && master->GetAttribute() == PAD_ATTRIB::PTH )
601 {
602 if( pad->GetProperty() != PAD_PROP::HEATSINK )
603 {
604 pad->SetAttribute( PAD_ATTRIB::SMD );
605 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::ROUNDRECT );
606 pad->SetSizeX( 1.5 * pad->GetSizeY() );
607 pad->SetLayerSet( PAD::SMDMask() );
608 }
609 }
610 else if( ( m_board->GetFirstFootprint()->GetAttributes() & FP_THROUGH_HOLE )
611 && master->GetAttribute() == PAD_ATTRIB::SMD )
612 {
613 pad->SetAttribute( PAD_ATTRIB::PTH );
614 pad->SetShape( PADSTACK::ALL_LAYERS, PAD_SHAPE::CIRCLE );
615 pad->SetSize( PADSTACK::ALL_LAYERS, VECTOR2I( pad->GetSizeX(), pad->GetSizeX() ) );
616
617 // Gives an acceptable drill size: it cannot be 0, but from pad master
618 // it is currently 0, therefore change it:
619 pad->SetDrillShape( PAD_DRILL_SHAPE::CIRCLE );
620 int hole_size = pad->GetSizeX() / 2;
621 pad->SetDrillSize( VECTOR2I( hole_size, hole_size ) );
622
623 pad->SetLayerSet( PAD::PTHMask() );
624 }
625
626 if( pad->CanHaveNumber() )
627 {
628 wxString padNumber = m_padTool->GetLastPadNumber();
629
630 // Use the last entered pad number when recreating a pad without using the
631 // previously created pad, and a new number when creating a really new pad
632 if( neednewPadNumber )
633 padNumber = m_board->GetFirstFootprint()->GetNextPadNumber( padNumber );
634
635 pad->SetNumber( padNumber );
636 m_padTool->SetLastPadNumber( padNumber );
637
638 // If a pad is recreated and the previously created was not placed, use
639 // the last entered pad number
640 neednewPadNumber = false;
641 }
642
643 return std::unique_ptr<BOARD_ITEM>( pad );
644 }
645
646 bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
647 {
648 PAD* pad = dynamic_cast<PAD*>( aItem );
649 // We are using this pad number.
650 // therefore use a new pad number for a newly created pad
651 neednewPadNumber = true;
652
653 if( pad )
654 {
655 m_frame->GetDesignSettings().m_Pad_Master->ImportSettingsFrom( *pad );
656 aCommit.Add( aItem );
657 return true;
658 }
659
660 return false;
661 }
662
663 void SnapItem( BOARD_ITEM *aItem ) override
664 {
665 m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
666 m_gridHelper.SetUseGrid( !( m_modifiers & MD_CTRL ) );
667
668 if( !m_gridHelper.GetSnap() )
669 return;
670
671 MAGNETIC_SETTINGS* settings = m_frame->GetMagneticItemsSettings();
672 PAD* pad = static_cast<PAD*>( aItem );
673 VECTOR2I position = m_padTool->getViewControls()->GetMousePosition();
674 KIGFX::VIEW_CONTROLS* viewControls = m_padTool->getViewControls();
675 std::vector<BOARD_ITEM*> ignored_items( 1, pad );
676
677 if( settings->pads == MAGNETIC_OPTIONS::NO_EFFECT )
678 {
679 PADS& pads = m_board->GetFirstFootprint()->Pads();
680 ignored_items.insert( ignored_items.end(), pads.begin(), pads.end() );
681 }
682
683 if( !settings->graphics )
684 {
685 DRAWINGS& graphics = m_board->GetFirstFootprint()->GraphicalItems();
686 ignored_items.insert( ignored_items.end(), graphics.begin(), graphics.end() );
687 }
688
689 VECTOR2I cursorPos = m_gridHelper.BestSnapAnchor( position, LSET::AllLayersMask(), GRID_CURRENT, ignored_items );
690 viewControls->ForceCursorPosition( true, cursorPos );
691 aItem->SetPosition( cursorPos );
692 }
693
694 PAD_TOOL* m_padTool;
695 PCB_BASE_EDIT_FRAME* m_frame;
696 PCB_GRID_HELPER m_gridHelper;
697 };
698
699 PAD_PLACER placer( this, frame() );
700
701 doInteractiveItemPlacement( aEvent, &placer, _( "Place pad" ),
703
704 return 0;
705}
706
707
708int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent )
709{
711 return 0;
712
713 Activate();
714
715 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
716 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
718
719 if( m_editPad != niluuid )
720 {
721 if( PAD* pad = dynamic_cast<PAD*>( frame()->ResolveItem( m_editPad ) ) )
722 {
723 BOARD_COMMIT commit( frame() );
724 commit.Modify( pad );
725
726 std::vector<PCB_SHAPE*> mergedShapes = RecombinePad( pad, false );
727
728 for( PCB_SHAPE* shape : mergedShapes )
729 commit.Remove( shape );
730
731 commit.Push( _( "Edit Pad" ) );
732 }
733
735 }
736 else if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
737 {
738 PCB_LAYER_ID layer;
739 PAD* pad = static_cast<PAD*>( selection[0] );
740 BOARD_COMMIT commit( frame() );
741
742 commit.Modify( pad );
743 explodePad( pad, &layer, commit );
744 commit.Push( _( "Edit Pad" ) );
745
747 frame()->SetActiveLayer( layer );
748
749 settings->m_PadEditModePad = pad;
751 }
752
753 if( m_editPad == niluuid )
755
756 return 0;
757}
758
759
761{
762 PAD* flaggedPad = nullptr;
763 KIID flaggedPadId = niluuid;
764
765 for( FOOTPRINT* fp : board()->Footprints() )
766 {
767 for( PAD* pad : fp->Pads() )
768 {
769 if( pad->IsEntered() )
770 {
771 flaggedPad = pad;
772 flaggedPadId = pad->m_Uuid;
773 break;
774 }
775 }
776 }
777
778 if( flaggedPadId != m_editPad )
779 {
780 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
781 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
782
783 m_editPad = flaggedPadId;
784 settings->m_PadEditModePad = flaggedPad;
785
786 if( flaggedPad )
788 else
790 }
791
792 return 0;
793}
794
795
797{
798 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
799 WX_INFOBAR* infoBar = frame()->GetInfoBar();
800 wxString msg;
801
803 [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
804 {
805 return dynamic_cast<PAD*>( aItem ) != nullptr;
806 } );
807
809
810 if( opts.m_ContrastModeDisplay == HIGH_CONTRAST_MODE::NORMAL )
811 {
812 opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::DIMMED;
813 frame()->SetDisplayOptions( opts );
814 }
815
816 if( PCB_ACTIONS::explodePad.GetHotKey() == PCB_ACTIONS::recombinePad.GetHotKey() )
817 {
818 msg.Printf( _( "Pad Edit Mode. Press %s again to exit." ),
820 }
821 else
822 {
823 msg.Printf( _( "Pad Edit Mode. Press %s to exit." ),
825 }
826
827 infoBar->RemoveAllButtons();
828 infoBar->ShowMessage( msg, wxICON_INFORMATION );
829}
830
831
833{
834 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
835 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
836 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
837
838 settings->m_PadEditModePad = nullptr;
839
841 {
843 frame()->SetDisplayOptions( opts );
844 }
845
846 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
847 // they won't be found in the view layer's itemset for re-painting.
849 [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
850 {
851 return dynamic_cast<PAD*>( aItem ) != nullptr;
852 } );
853
854 // Refresh now (otherwise there's an uncomfortably long pause while the infoBar
855 // closes before refresh).
856 canvas()->ForceRefresh();
857
858 frame()->GetInfoBar()->Dismiss();
859}
860
861
862void PAD_TOOL::explodePad( PAD* aPad, PCB_LAYER_ID* aLayer, BOARD_COMMIT& aCommit )
863{
864 if( aPad->IsOnLayer( F_Cu ) )
865 *aLayer = F_Cu;
866 else if( aPad->IsOnLayer( B_Cu ) )
867 *aLayer = B_Cu;
868 else
869 *aLayer = aPad->GetLayerSet().UIOrder().front();
870
871 // TODO(JE) padstacks
872 if( aPad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::CUSTOM )
873 {
874 for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives( PADSTACK::ALL_LAYERS ) )
875 {
876 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( primitive->Duplicate( true, &aCommit ) );
877
878 shape->SetParent( board()->GetFirstFootprint() );
879 shape->Rotate( VECTOR2I( 0, 0 ), aPad->GetOrientation() );
880 shape->Move( aPad->ShapePos( PADSTACK::ALL_LAYERS ) );
881 shape->SetLayer( *aLayer );
882
883 if( shape->IsProxyItem() && shape->GetShape() == SHAPE_T::SEGMENT )
884 {
885 if( aPad->GetLocalThermalSpokeWidthOverride().has_value() )
886 shape->SetWidth( aPad->GetLocalThermalSpokeWidthOverride().value() );
887 else
889 }
890
891 aCommit.Add( shape );
892 }
893
894 // TODO(JE) padstacks
896 aPad->DeletePrimitivesList();
897 }
898
899 aPad->SetFlags( ENTERED );
900 m_editPad = aPad->m_Uuid;
901}
902
903
904std::vector<PCB_SHAPE*> PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun )
905{
906 int maxError = board()->GetDesignSettings().m_MaxError;
907
908 // Don't leave an object in the point editor that might no longer exist after recombining.
910
911 return aPad->Recombine( aIsDryRun, maxError );
912}
913
914
916{
920
923
926
928}
@ NORMAL
Use all material properties from model file.
constexpr EDA_IU_SCALE pcbIUScale
Definition: base_units.h:112
HIGH_CONTRAST_MODE
Determine how inactive layers should be displayed.
static TOOL_ACTION cancelInteractive
Definition: actions.h:72
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: actions.h:221
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:79
FOOTPRINT * GetParentFootprint() const
Definition: board_item.cpp:97
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:317
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:489
const FOOTPRINTS & Footprints() const
Definition: board.h:358
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:1024
void Empty()
Clear the list.
Definition: collector.h:91
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:83
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition: commit.h:91
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:107
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition: commit.h:79
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:490
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:98
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:273
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:142
const KIID m_Uuid
Definition: eda_item.h:516
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:110
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:113
SHAPE_T GetShape() const
Definition: eda_shape.h:168
void SetWidth(int aWidth)
Definition: eda_shape.cpp:2375
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:349
static const TOOL_EVENT UndoRedoPostEvent
Definition: actions.h:366
EDA_ANGLE GetOrientation() const
Definition: footprint.h:230
std::deque< PAD * > & Pads()
Definition: footprint.h:209
const LIB_ID & GetFPID() const
Definition: footprint.h:251
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:324
void SetIgnoreFPTextOnFront(bool ignore)
Definition: collectors.h:416
void SetIgnoreFPTextOnBack(bool ignore)
Definition: collectors.h:410
void SetIgnoreFPReferences(bool ignore)
Definition: collectors.h:458
void SetIgnoreFPValues(bool ignore)
Definition: collectors.h:452
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:207
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.
Definition: collectors.cpp:505
virtual RENDER_SETTINGS * GetSettings()=0
Return a pointer to current settings that are going to be used when drawing items.
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:182
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: pcb_painter.h:187
PCB specific render settings.
Definition: pcb_painter.h:80
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.
bool GetHighContrast() const
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:86
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:66
double GetScale() const
Definition: view.h:276
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:1685
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:422
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:220
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
Definition: view.cpp:1655
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:1571
Definition: kiid.h:49
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition: lset.cpp:733
static const LSET & AllLayersMask()
Definition: lset.cpp:624
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition: padstack.h:145
void Reset(RESET_REASON aReason) override
Basic initialization.
Definition: pad_tool.cpp:59
int OnUndoRedo(const TOOL_EVENT &aEvent)
Definition: pad_tool.cpp:760
HIGH_CONTRAST_MODE m_previousHighContrastMode
Definition: pad_tool.h:95
void explodePad(PAD *aPad, PCB_LAYER_ID *aLayer, BOARD_COMMIT &aCommit)
Definition: pad_tool.cpp:862
void setTransitions() override
< Bind handlers to corresponding TOOL_ACTIONs.
Definition: pad_tool.cpp:915
int EditPad(const TOOL_EVENT &aEvent)
Enter/exit WYSIWYG pad shape editing.
Definition: pad_tool.cpp:708
void ExitPadEditMode()
Definition: pad_tool.cpp:832
KIID m_editPad
Definition: pad_tool.h:96
int copyPadSettings(const TOOL_EVENT &aEvent)
Push pad settings from a pad to other pads on board or footprint.
Definition: pad_tool.cpp:169
void enterPadEditMode()
Definition: pad_tool.cpp:796
int pastePadProperties(const TOOL_EVENT &aEvent)
Copy pad settings from a pad to the board design settings.
Definition: pad_tool.cpp:142
int PlacePad(const TOOL_EVENT &aEvent)
Place a pad in footprint editor.
Definition: pad_tool.cpp:562
int EnumeratePads(const TOOL_EVENT &aEvent)
Tool for quick pad enumeration.
Definition: pad_tool.cpp:296
PAD_TOOL()
Definition: pad_tool.cpp:52
bool Init() override
Init() is called once upon a registration of the tool.
Definition: pad_tool.cpp:81
void SetLastPadNumber(const wxString &aPadNumber)
Definition: pad_tool.h:65
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:904
bool InPadEditMode()
Definition: pad_tool.h:61
wxString m_lastPadNumber
Definition: pad_tool.h:93
int pushPadSettings(const TOOL_EVENT &aEvent)
Definition: pad_tool.cpp:239
Definition: pad.h:54
bool IsAperturePad() const
Definition: pad.h:447
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition: pad.h:437
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:365
bool IsOnLayer(PCB_LAYER_ID aLayer) const override
Test to see if this object is on the given layer.
Definition: pad.h:786
PAD_ATTRIB GetAttribute() const
Definition: pad.h:440
static LSET PTHMask()
layer set for a through hole pad
Definition: pad.cpp:291
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
Definition: pad.h:186
std::vector< PCB_SHAPE * > Recombine(bool aIsDryRun, int aMaxError)
Recombines the pad with other graphical shapes in the footprint.
Definition: pad.cpp:2125
void DeletePrimitivesList(PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Clear the basic shapes list.
Definition: pad.cpp:2664
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition: pad.h:195
void ImportSettingsFrom(const PAD &aMasterPad)
Import the pad settings from aMasterPad.
Definition: pad.cpp:1921
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition: pad.h:408
static LSET SMDMask()
layer set for a SMD pad on Front layer
Definition: pad.cpp:298
std::optional< int > GetLocalThermalSpokeWidthOverride() const
Definition: pad.h:609
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
Definition: pad.cpp:1068
PAD_SHAPE GetAnchorPadShape(PCB_LAYER_ID aLayer) const
Definition: pad.h:213
static TOOL_ACTION recombinePad
Definition: pcb_actions.h:502
static TOOL_ACTION enumeratePads
Tool for quick pad enumeration.
Definition: pcb_actions.h:505
static TOOL_ACTION pushPadSettings
Copy the current pad's settings to other pads in the footprint or on the board.
Definition: pcb_actions.h:525
static TOOL_ACTION mirrorH
Mirroring of selected items.
Definition: pcb_actions.h:125
static TOOL_ACTION copyPadSettings
Copy the selected pad's settings to the board design settings.
Definition: pcb_actions.h:519
static TOOL_ACTION placePad
Activation of the drawing tool (placing a PAD)
Definition: pcb_actions.h:499
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:168
static TOOL_ACTION explodePad
Definition: pcb_actions.h:501
static TOOL_ACTION applyPadSettings
Copy the default pad settings to the selected pad.
Definition: pcb_actions.h:522
static TOOL_ACTION mirrorV
Definition: pcb_actions.h:126
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:122
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:118
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:119
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.
Definition: pcb_shape.cpp:564
bool IsProxyItem() const override
Definition: pcb_shape.h:116
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
Definition: pcb_shape.cpp:176
void Move(const VECTOR2I &aMoveVector) override
Move this object.
Definition: pcb_shape.cpp:471
T * frame() const
KIGFX::PCB_VIEW * view() const
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.
bool m_isFootprintEditor
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.
int Size() const
Returns the number of selected parts.
Definition: selection.h:121
wxWindow * GetPanel()
Definition: status_popup.h:62
virtual void Popup(wxWindow *aFocus=nullptr)
virtual void Move(const wxPoint &aWhere)
Extension of STATUS_POPUP for displaying a single line text.
Definition: status_popup.h:83
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:146
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:44
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:38
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition: tool_base.h:80
Generic, UI-independent tool event.
Definition: tool_event.h:168
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.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:395
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
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.
Definition: wx_infobar.cpp:371
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
Definition: wx_infobar.cpp:156
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
#define ENTERED
indicates a group has been entered
static const std::vector< KICAD_T > padTypes
Definition: edit_tool.cpp:79
@ FP_SMD
Definition: footprint.h:81
@ FP_THROUGH_HOLE
Definition: footprint.h:80
@ GRID_CURRENT
Definition: grid_helper.h:45
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
KIID niluuid(0)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ B_Cu
Definition: layer_ids.h:65
@ F_Cu
Definition: layer_ids.h:64
This file contains miscellaneous commonly used macros and functions.
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:58
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:59
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
Definition: wxgtk/ui.cpp:683
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:190
static std::optional< SEQUENTIAL_PAD_ENUMERATION_PARAMS > GetSequentialPadNumberingParams(wxWindow *aFrame)
Prompts the user for parameters for sequential pad numbering.
Definition: pad_tool.cpp:282
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
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.
const double IU_PER_MM
Definition: base_units.h:76
constexpr int mmToIU(double mm) const
Definition: base_units.h:92
MAGNETIC_OPTIONS tracks
MAGNETIC_OPTIONS pads
Parameters for sequential pad numbering.
@ MD_CTRL
Definition: tool_event.h:144
@ MD_SHIFT
Definition: tool_event.h:143
@ BUT_LEFT
Definition: tool_event.h:132
@ BUT_RIGHT
Definition: tool_event.h:133
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM
Definition: zones.h:34