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