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