KiCad PCB EDA Suite
Loading...
Searching...
No Matches
edit_tool.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2013-2023 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <macros.h>
24#include <advanced_config.h>
25#include <clipboard.h>
26#include <limits>
27#include <kiplatform/ui.h>
29#include <board.h>
31#include <collectors.h>
32#include <footprint.h>
33#include <increment.h>
34#include <pcb_shape.h>
35#include <pcb_group.h>
38#include <pcb_point.h>
39#include <pcb_reference_image.h>
40#include <pcb_target.h>
41#include <pcb_textbox.h>
42#include <pcb_table.h>
43#include <pcb_generator.h>
45#include <zone.h>
46#include <pad.h>
47#include <pcb_edit_frame.h>
49#include <kiway.h>
50#include <status_popup.h>
51#include <tool/action_manager.h>
53#include <tool/tool_manager.h>
54#include <tools/pcb_actions.h>
57#include <tools/edit_tool.h>
58#include <tools/graphic_edit.h>
64#include <tools/pad_tool.h>
65#include <view/view_controls.h>
67#include <pcbnew_id.h>
68#include <core/kicad_algo.h>
69#include <fix_board_shape.h>
70#include <bitmaps.h>
71#include <functional>
72using namespace std::placeholders;
73#include "kicad_clipboard.h"
74#include <wx/hyperlink.h>
75#include <router/router_tool.h>
77#include <widgets/wx_infobar.h>
85#include <pcb_reference_image.h>
86
87const unsigned int EDIT_TOOL::COORDS_PADDING = pcbIUScale.mmToIU( 20 );
88
90{
91 if( !aItem )
92 return false;
93
94 if( aItem->Type() == PCB_SHAPE_T )
95 {
96 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
97 return shape->GetShape() == SHAPE_T::POLY;
98 }
99
100 if( aItem->Type() == PCB_ZONE_T )
101 {
102 ZONE* zone = static_cast<ZONE*>( aItem );
103
104 if( zone->IsTeardropArea() )
105 return false;
106
107 return true;
108 }
109
110 return false;
111}
112
113static bool selectionHasEditableCorners( const SELECTION& aSelection )
114{
115 if( aSelection.GetSize() != 1 )
116 return false;
117
118 BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( aSelection.Front() );
119 return itemHasEditableCorners( item );
120}
121
122static const std::vector<KICAD_T> padTypes = { PCB_PAD_T };
123
124static const std::vector<KICAD_T> footprintTypes = { PCB_FOOTPRINT_T };
125
126static const std::vector<KICAD_T> groupTypes = { PCB_GROUP_T };
127
128static const std::vector<KICAD_T> trackTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T };
129
130static const std::vector<KICAD_T> baseConnectedTypes = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T };
131
132static const std::vector<KICAD_T> connectedTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_ZONE_T };
133
134static const std::vector<KICAD_T> routableTypes = { PCB_TRACE_T, PCB_ARC_T, PCB_VIA_T, PCB_PAD_T, PCB_FOOTPRINT_T };
135
136
137// Types with no Mirror() override, which would fall through to the warning-dialog
138// BOARD_ITEM::Mirror. Free pads are handled specially by the tool but not by PCB_GROUP::Mirror.
139static const std::vector<KICAD_T> nonMirrorableTypes = {
141};
142
143
144// A group is mirrorable only if none of its members hit BOARD_ITEM::Mirror.
145static bool groupMirrorable( const PCB_GROUP* aGroup )
146{
147 bool ok = true;
148
149 aGroup->RunOnChildren(
150 [&]( BOARD_ITEM* aChild )
151 {
152 if( aChild->IsType( nonMirrorableTypes ) )
153 ok = false;
154 },
156
157 return ok;
158}
159
160
161// True if at least one selected item can be mirrored. A group counts only if all its members can.
162static bool selectionMirrorable( const SELECTION& aSelection )
163{
164 for( EDA_ITEM* item : aSelection )
165 {
166 if( item->Type() == PCB_GROUP_T )
167 {
168 if( groupMirrorable( static_cast<PCB_GROUP*>( item ) ) )
169 return true;
170 }
171 else if( item->IsType( EDIT_TOOL::MirrorableItems ) )
172 {
173 return true;
174 }
175 }
176
177 return false;
178}
179
180
182 PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
183 m_selectionTool( nullptr ),
184 m_dragging( false ),
185 m_inMoveWithReference( false )
186{
187}
188
189
191{
192 m_dragging = false;
193 m_inMoveWithReference = false;
194
195 m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( getEditFrame<PCB_BASE_EDIT_FRAME>() );
196}
197
198
199static std::shared_ptr<CONDITIONAL_MENU> makeMirrorRotateMenu( EDIT_TOOL* aEditTool )
200{
201 std::shared_ptr<CONDITIONAL_MENU> menu = std::make_shared<CONDITIONAL_MENU>( aEditTool );
202
203 menu->SetIcon( BITMAPS::special_tools );
204 menu->SetUntranslatedTitle( _HKI( "Mirror / Rotate" ) );
205
206 bool isBoardEditor = aEditTool && aEditTool->IsBoardEditor();
207
208 auto canMirror =
209 [isBoardEditor]( const SELECTION& aSelection )
210 {
211 if( isBoardEditor && SELECTION_CONDITIONS::OnlyTypes( padTypes )( aSelection ) )
212 return false;
213
214 return selectionMirrorable( aSelection );
215 };
216
219 menu->AddItem( PCB_ACTIONS::mirrorH, canMirror );
220 menu->AddItem( PCB_ACTIONS::mirrorV, canMirror );
221
222 return menu;
223}
224
225
226static std::shared_ptr<CONDITIONAL_MENU> makeRoutingToolsMenu( TOOL_INTERACTIVE* aTool )
227{
228 std::shared_ptr<CONDITIONAL_MENU> menu = std::make_shared<CONDITIONAL_MENU>( aTool );
229
230 menu->SetIcon( BITMAPS::special_tools );
231 menu->SetUntranslatedTitle( _HKI( "Routing" ) );
232
233 auto notMovingCondition =
234 []( const SELECTION& aSelection )
235 {
236 return aSelection.Empty() || !aSelection.Front()->IsMoving();
237 };
238
241 && notMovingCondition;
242
243 menu->AddItem( PCB_ACTIONS::routerRouteSelected, isRoutable );
244 menu->AddItem( PCB_ACTIONS::routerRouteSelectedFromEnd, isRoutable );
245 menu->AddItem( PCB_ACTIONS::unrouteSelected, isRoutable );
246 menu->AddItem( PCB_ACTIONS::unrouteSegment, isRoutable );
247 menu->AddItem( PCB_ACTIONS::routerAutorouteSelected, isRoutable );
248
249 const SELECTION_CONDITION isOptimizable = SELECTION_CONDITIONS::HasTypes( trackTypes ) && notMovingCondition;
250 menu->AddItem( PCB_ACTIONS::routerOptimizeSelected, isOptimizable );
251
252 return menu;
253}
254
255
256static std::shared_ptr<CONDITIONAL_MENU> makePositioningToolsMenu( TOOL_INTERACTIVE* aTool )
257{
258 std::shared_ptr<CONDITIONAL_MENU> menu = std::make_shared<CONDITIONAL_MENU>( aTool );
259
260 menu->SetIcon( BITMAPS::special_tools );
261 menu->SetUntranslatedTitle( _HKI( "Position" ) );
262
263 auto notMovingCondition =
264 []( const SELECTION& aSelection )
265 {
266 return aSelection.Empty() || !aSelection.Front()->IsMoving();
267 };
268
269 menu->AddItem( PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
270 menu->AddItem( PCB_ACTIONS::moveWithReference, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
271 menu->AddItem( PCB_ACTIONS::moveIndividually, SELECTION_CONDITIONS::MoreThan( 1 ) && notMovingCondition );
272 menu->AddItem( PCB_ACTIONS::positionRelative, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
273 menu->AddItem( PCB_ACTIONS::interactiveOffsetTool, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
274 return menu;
275};
276
277
278static std::shared_ptr<CONDITIONAL_MENU> makeShapeModificationMenu( TOOL_INTERACTIVE* aTool )
279{
280 std::shared_ptr<CONDITIONAL_MENU> menu = std::make_shared<CONDITIONAL_MENU>( aTool );
281
282 menu->SetUntranslatedTitle( _HKI( "Shape Modification" ) );
283
284 static const std::vector<KICAD_T> filletChamferTypes = { PCB_SHAPE_LOCATE_POLY_T, PCB_SHAPE_LOCATE_RECT_T,
286
287 static const std::vector<KICAD_T> healShapesTypes = { PCB_SHAPE_LOCATE_SEGMENT_T, PCB_SHAPE_LOCATE_ARC_T,
289
290 static const std::vector<KICAD_T> lineExtendTypes = { PCB_SHAPE_LOCATE_SEGMENT_T };
291
292 static const std::vector<KICAD_T> polygonBooleanTypes = { PCB_SHAPE_LOCATE_RECT_T, PCB_SHAPE_LOCATE_POLY_T,
294
295 static const std::vector<KICAD_T> polygonSimplifyTypes = { PCB_SHAPE_LOCATE_POLY_T, PCB_ZONE_T };
296
297 auto hasCornerCondition =
298 [aTool]( const SELECTION& aSelection )
299 {
300 PCB_POINT_EDITOR* pt_tool = aTool->GetManager()->GetTool<PCB_POINT_EDITOR>();
301
302 return pt_tool && pt_tool->HasCorner();
303 };
304
305 auto hasMidpointCondition =
306 [aTool]( const SELECTION& aSelection )
307 {
308 PCB_POINT_EDITOR* pt_tool = aTool->GetManager()->GetTool<PCB_POINT_EDITOR>();
309
310 return pt_tool && pt_tool->HasMidpoint();
311 };
312
313 auto canAddCornerCondition =
314 []( const SELECTION& aSelection )
315 {
316 const EDA_ITEM* item = aSelection.Front();
317
318 return item && PCB_POINT_EDITOR::CanAddCorner( *item );
319 };
320
321 auto canChamferCornerCondition =
322 []( const SELECTION& aSelection )
323 {
324 const EDA_ITEM* item = aSelection.Front();
325
326 return item && PCB_POINT_EDITOR::CanChamferCorner( *item );
327 };
328
329 auto canRemoveCornerCondition =
330 [aTool]( const SELECTION& aSelection )
331 {
332 PCB_POINT_EDITOR* pt_tool = aTool->GetManager()->GetTool<PCB_POINT_EDITOR>();
333
334 return pt_tool && pt_tool->CanRemoveCorner( aSelection );
335 };
336
337 // clang-format off
338
339 // Shape cleanup
340 menu->AddItem( PCB_ACTIONS::healShapes, SELECTION_CONDITIONS::HasTypes( healShapesTypes ) );
341 menu->AddItem( PCB_ACTIONS::simplifyPolygons, SELECTION_CONDITIONS::HasTypes( polygonSimplifyTypes ) );
342
343 menu->AddSeparator( SELECTION_CONDITIONS::OnlyTypes( filletChamferTypes ) );
344
345 // Shape corner modifications
346 menu->AddItem( PCB_ACTIONS::filletLines, SELECTION_CONDITIONS::OnlyTypes( filletChamferTypes ) );
347 menu->AddItem( PCB_ACTIONS::chamferLines, SELECTION_CONDITIONS::OnlyTypes( filletChamferTypes ) );
348 menu->AddItem( PCB_ACTIONS::dogboneCorners, SELECTION_CONDITIONS::OnlyTypes( filletChamferTypes ) );
349 menu->AddItem( PCB_ACTIONS::extendLines, SELECTION_CONDITIONS::OnlyTypes( lineExtendTypes )
351 // Both pick their own shape from under the pointer, so the selection says nothing about them.
354
355 menu->AddSeparator( SELECTION_CONDITIONS::Count( 1 ) );
356
357 // Point editor corner operations
358 menu->AddItem( PCB_ACTIONS::pointEditorMoveCorner, hasCornerCondition );
359 menu->AddItem( PCB_ACTIONS::pointEditorMoveMidpoint, hasMidpointCondition );
360 menu->AddItem( PCB_ACTIONS::pointEditorAddCorner, SELECTION_CONDITIONS::Count( 1 ) && canAddCornerCondition );
361 menu->AddItem( PCB_ACTIONS::pointEditorRemoveCorner, SELECTION_CONDITIONS::Count( 1 ) && canRemoveCornerCondition );
362 menu->AddItem( PCB_ACTIONS::pointEditorChamferCorner, SELECTION_CONDITIONS::Count( 1 ) && canChamferCornerCondition );
364
365 menu->AddSeparator( SELECTION_CONDITIONS::OnlyTypes( polygonBooleanTypes )
367
368 // Polygon boolean operations
369 menu->AddItem( PCB_ACTIONS::mergePolygons, SELECTION_CONDITIONS::OnlyTypes( polygonBooleanTypes )
371 menu->AddItem( PCB_ACTIONS::subtractPolygons, SELECTION_CONDITIONS::OnlyTypes( polygonBooleanTypes )
373 menu->AddItem( PCB_ACTIONS::intersectPolygons, SELECTION_CONDITIONS::OnlyTypes( polygonBooleanTypes )
375 // clang-format on
376
377 return menu;
378};
379
380
381// Gate-swap submenu and helpers
383{
384public:
386 ACTION_MENU( true )
387 {
389 SetTitle( _( "Swap Gate Nets..." ) );
390 }
391
392
393 // We're looking for a selection of pad(s) that belong to a single footprint with multiple units.
394 // Ignore non-pad items since we might have grabbed some traces inside the pad, etc.
395 static const FOOTPRINT* GetSingleEligibleFootprint( const SELECTION& aSelection )
396 {
397 const FOOTPRINT* single = nullptr;
398
399 for( const EDA_ITEM* it : aSelection )
400 {
401 if( it->Type() != PCB_PAD_T )
402 continue;
403
404 const PAD* pad = static_cast<const PAD*>( static_cast<const BOARD_ITEM*>( it ) );
405 const FOOTPRINT* fp = pad->GetParentFootprint();
406
407 if( !fp )
408 continue;
409
410 const std::vector<FOOTPRINT::FP_UNIT_INFO>& units = fp->GetUnitInfo();
411
412 if( units.size() < 2 )
413 continue;
414
415 const wxString& padNum = pad->GetNumber();
416 bool inAnyUnit = false;
417
418 for( const FOOTPRINT::FP_UNIT_INFO& u : units )
419 {
420 for( const wxString& pnum : u.m_pins )
421 {
422 if( pnum == padNum )
423 {
424 inAnyUnit = true;
425 break;
426 }
427 }
428
429 if( inAnyUnit )
430 break;
431 }
432
433 if( !inAnyUnit )
434 continue;
435
436 if( !single )
437 single = fp;
438 else if( single != fp )
439 return nullptr;
440 }
441
442 return single;
443 }
444
445
446 static std::unordered_set<wxString> CollectSelectedPadNumbers( const SELECTION& aSelection,
447 const FOOTPRINT* aFootprint )
448 {
449 std::unordered_set<wxString> padNums;
450
451 for( const EDA_ITEM* it : aSelection )
452 {
453 if( it->Type() != PCB_PAD_T )
454 continue;
455
456 const PAD* pad = static_cast<const PAD*>( static_cast<const BOARD_ITEM*>( it ) );
457
458 if( pad->GetParentFootprint() != aFootprint )
459 continue;
460
461 padNums.insert( pad->GetNumber() );
462 }
463
464 return padNums;
465 }
466
467
468 // Make a list of the unit names that have any pad selected
469 static std::vector<int> GetUnitsHitIndices( const FOOTPRINT* aFootprint,
470 const std::unordered_set<wxString>& aSelPadNums )
471 {
472 std::vector<int> indices;
473
474 const std::vector<FOOTPRINT::FP_UNIT_INFO>& units = aFootprint->GetUnitInfo();
475
476 for( size_t i = 0; i < units.size(); ++i )
477 {
478 bool hasAny = false;
479
480 for( const wxString& pn : units[i].m_pins )
481 {
482 if( aSelPadNums.count( pn ) )
483 {
484 hasAny = true;
485 break;
486 }
487 }
488
489 if( hasAny )
490 indices.push_back( static_cast<int>( i ) );
491 }
492
493 return indices;
494 }
495
496
497 // Gate swapping requires the swapped units to have equal pin counts
498 static bool EqualPinCounts( const FOOTPRINT* aFootprint, const std::vector<int>& aUnitIndices )
499 {
500 if( aUnitIndices.empty() )
501 return false;
502
503 const std::vector<FOOTPRINT::FP_UNIT_INFO>& units = aFootprint->GetUnitInfo();
504 const size_t cnt = units[static_cast<size_t>( aUnitIndices.front() )].m_pins.size();
505
506 for( int idx : aUnitIndices )
507 {
508 if( units[static_cast<size_t>( idx )].m_pins.size() != cnt )
509 return false;
510 }
511
512 return true;
513 }
514
515
516 // Used when we have exactly one source unit selected; find all other units with equal pin counts
517 static std::vector<int> GetCompatibleTargets( const FOOTPRINT* aFootprint, int aSourceIdx )
518 {
519 std::vector<int> targets;
520
521 const std::vector<FOOTPRINT::FP_UNIT_INFO>& units = aFootprint->GetUnitInfo();
522 const size_t pinCount = units[static_cast<size_t>( aSourceIdx )].m_pins.size();
523
524 for( size_t i = 0; i < units.size(); ++i )
525 {
526 if( static_cast<int>( i ) == aSourceIdx )
527 continue;
528
529 if( units[i].m_pins.size() != pinCount )
530 continue;
531
532 targets.push_back( static_cast<int>( i ) );
533 }
534
535 return targets;
536 }
537
538protected:
539 ACTION_MENU* create() const override { return new GATE_SWAP_MENU(); }
540
541 // The gate swap menu dynamically populates itself based on current selection of pads
542 // on a single multi-unit footprint.
543 //
544 // If there is exactly one unit with any pad selected, we build a menu of available swaps
545 // with all other units with equal pin counts.
546 void update() override
547 {
548 Clear();
549
551 const SELECTION& sel = selTool->GetSelection();
552
553 const FOOTPRINT* fp = GetSingleEligibleFootprint( sel );
554
555 if( !fp )
556 return;
557
558 std::unordered_set<wxString> selPadNums = CollectSelectedPadNumbers( sel, fp );
559
560 std::vector<int> unitsHit = GetUnitsHitIndices( fp, selPadNums );
561
562 if( unitsHit.size() != 1 )
563 return;
564
565 const int sourceIdx = unitsHit.front();
566 std::vector<int> targets = GetCompatibleTargets( fp, sourceIdx );
567
568 for( int idx : targets )
569 {
570 wxString label;
571 label.Printf( _( "Swap with %s" ), fp->GetUnitInfo()[static_cast<size_t>( idx )].m_unitName );
572 Append( ID_POPUP_PCB_SWAP_UNIT_BASE + idx, label );
573 }
574 }
575
576
577 OPT_TOOL_EVENT eventHandler( const wxMenuEvent& aEvent ) override
578 {
579 int id = aEvent.GetId();
580
582 {
584 const SELECTION& sel = selTool->GetSelection();
585
586 const FOOTPRINT* fp = GetSingleEligibleFootprint( sel );
587
588 if( !fp )
589 return OPT_TOOL_EVENT();
590
591 const std::vector<FOOTPRINT::FP_UNIT_INFO>& units = fp->GetUnitInfo();
592 const int targetIdx = id - ID_POPUP_PCB_SWAP_UNIT_BASE;
593
594 if( targetIdx < 0 || targetIdx >= static_cast<int>( units.size() ) )
595 return OPT_TOOL_EVENT();
596
597 TOOL_EVENT evt = PCB_ACTIONS::swapGateNets.MakeEvent();
598 evt.SetParameter( units[targetIdx].m_unitName );
599
600 return OPT_TOOL_EVENT( evt );
601 }
602
603 return OPT_TOOL_EVENT();
604 }
605};
606
607
608static std::shared_ptr<ACTION_MENU> makeGateSwapMenu( TOOL_INTERACTIVE* aTool )
609{
610 std::shared_ptr<GATE_SWAP_MENU> menu = std::make_shared<GATE_SWAP_MENU>();
611 menu->SetTool( aTool );
612 return menu;
613};
614
615
617{
618 // Find the selection tool, so they can cooperate
620
621 std::shared_ptr<CONDITIONAL_MENU> routingSubMenu = makeRoutingToolsMenu( this );
622 m_selectionTool->GetToolMenu().RegisterSubMenu( routingSubMenu );
623
624 std::shared_ptr<CONDITIONAL_MENU> positioningToolsSubMenu = makePositioningToolsMenu( this );
625 m_selectionTool->GetToolMenu().RegisterSubMenu( positioningToolsSubMenu );
626
627 std::shared_ptr<CONDITIONAL_MENU> mirrorRotateSubMenu = makeMirrorRotateMenu( this );
628 m_selectionTool->GetToolMenu().RegisterSubMenu( mirrorRotateSubMenu );
629
630 std::shared_ptr<CONDITIONAL_MENU> shapeModificationSubMenu = makeShapeModificationMenu( this );
631 m_selectionTool->GetToolMenu().RegisterSubMenu( shapeModificationSubMenu );
632
633 std::shared_ptr<ACTION_MENU> gateSwapSubMenu = makeGateSwapMenu( this );
634 m_selectionTool->GetToolMenu().RegisterSubMenu( gateSwapSubMenu );
635
636 std::shared_ptr<CONDITIONAL_MENU> fpAttributesMenu = std::make_shared<CONDITIONAL_MENU>( this );
637 fpAttributesMenu->SetUntranslatedTitle( _HKI( "Attributes" ) );
641 m_selectionTool->GetToolMenu().RegisterSubMenu( fpAttributesMenu );
642
643 auto positioningToolsCondition =
644 [this]( const SELECTION& aSel )
645 {
646 std::shared_ptr<CONDITIONAL_MENU> subMenu = makePositioningToolsMenu( this );
647 subMenu->Evaluate( aSel );
648 return subMenu->GetMenuItemCount() > 0;
649 };
650
651 auto shapeModificationCondition =
652 [this]( const SELECTION& aSel )
653 {
654 std::shared_ptr<CONDITIONAL_MENU> subMenu = makeShapeModificationMenu( this );
655 subMenu->Evaluate( aSel );
656 return subMenu->GetMenuItemCount() > 0;
657 };
658
659 // Does selection map to a single eligible footprint and exactly one unit?
660 auto gateSwapSingleUnitOnOneFootprint =
661 []( const SELECTION& aSelection )
662 {
664
665 if( !fp )
666 return false;
667
668 std::unordered_set<wxString> selPadNums = GATE_SWAP_MENU::CollectSelectedPadNumbers( aSelection, fp );
669
670 std::vector<int> unitsHit = GATE_SWAP_MENU::GetUnitsHitIndices( fp, selPadNums );
671
672 if( unitsHit.size() != 1 )
673 return false;
674
675 const int sourceIdx = unitsHit.front();
676 std::vector<int> targets = GATE_SWAP_MENU::GetCompatibleTargets( fp, sourceIdx );
677 return !targets.empty();
678 };
679
680 // Does selection map to a single eligible footprint and more than one unit with equal pin counts?
681 auto gateSwapMultipleUnitsOnOneFootprint =
682 []( const SELECTION& aSelection )
683 {
685
686 if( !fp )
687 return false;
688
689 std::unordered_set<wxString> selPadNums = GATE_SWAP_MENU::CollectSelectedPadNumbers( aSelection, fp );
690
691 std::vector<int> unitsHit = GATE_SWAP_MENU::GetUnitsHitIndices( fp, selPadNums );
692
693 if( unitsHit.size() < 2 )
694 return false;
695
696 return GATE_SWAP_MENU::EqualPinCounts( fp, unitsHit );
697 };
698
699 auto propertiesCondition =
700 [this]( const SELECTION& aSel )
701 {
702 if( aSel.GetSize() == 0 )
703 {
704 if( getView()->IsLayerVisible( LAYER_SCHEMATIC_DRAWINGSHEET ) )
705 {
706 DS_PROXY_VIEW_ITEM* ds = canvas()->GetDrawingSheet();
707 VECTOR2D cursor = getViewControls()->GetCursorPosition( false );
708
709 if( ds && ds->HitTestDrawingSheetItems( getView(), cursor ) )
710 return true;
711 }
712
713 return false;
714 }
715
716 if( aSel.GetSize() == 1 )
717 return true;
718
719 for( EDA_ITEM* item : aSel )
720 {
721 if( !dynamic_cast<PCB_TRACK*>( item ) )
722 return false;
723 }
724
725 return true;
726 };
727
728 auto inFootprintEditor =
729 [this]( const SELECTION& aSelection )
730 {
731 return m_isFootprintEditor;
732 };
733
734 auto canMirror =
735 [this]( const SELECTION& aSelection )
736 {
738 {
739 return false;
740 }
741
742 // Gates the whole "Mirror / Rotate" submenu, so keep it open for any group. Rotate works
743 // on a group with footprints, only the mirror items inside disable (see makeMirrorRotateMenu).
744 if( SELECTION_CONDITIONS::HasTypes( groupTypes )( aSelection ) )
745 return true;
746
748 };
749
750 auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyTypes( footprintTypes )
752
753 auto multipleFootprintsCondition =
754 []( const SELECTION& aSelection )
755 {
756 bool foundFirst = false;
757
758 for( EDA_ITEM* item : aSelection )
759 {
760 if( item->Type() == PCB_FOOTPRINT_T )
761 {
762 if( foundFirst )
763 return true;
764 else
765 foundFirst = true;
766 }
767 }
768
769 return false;
770 };
771
772 auto excludeFromBOMCond =
773 [this]( const SELECTION& aSel )
774 {
775 wxString variantName;
776 int checked = 0, unchecked = 0;
777
778 if( BOARD* board = frame()->GetBoard() )
779 variantName = board->GetCurrentVariant();
780
781 for( const EDA_ITEM* item : aSel )
782 {
783 if( item->Type() == PCB_FOOTPRINT_T )
784 {
785 if( static_cast<const FOOTPRINT*>( item )->GetExcludedFromBOMForVariant( variantName ) )
786 checked++;
787 else
788 unchecked++;
789 }
790 }
791
792 return checked > 0 && unchecked == 0;
793 };
794
795 auto excludeFromPosFilesCond =
796 [this]( const SELECTION& aSel )
797 {
798 wxString variantName;
799 int checked = 0, unchecked = 0;
800
801 if( BOARD* board = frame()->GetBoard() )
802 variantName = board->GetCurrentVariant();
803
804 for( const EDA_ITEM* item : aSel )
805 {
806 if( item->Type() == PCB_FOOTPRINT_T )
807 {
808 if( static_cast<const FOOTPRINT*>( item )->GetExcludedFromPosFilesForVariant( variantName ) )
809 checked++;
810 else
811 unchecked++;
812 }
813 }
814
815 return checked > 0 && unchecked == 0;
816 };
817
818 auto excludeFromSimCond =
819 [this]( const SELECTION& aSel )
820 {
821 wxString variantName;
822 int checked = 0, unchecked = 0;
823
824 if( BOARD* board = frame()->GetBoard() )
825 variantName = board->GetCurrentVariant();
826
827 for( const EDA_ITEM* item : aSel )
828 {
829 if( item->Type() == PCB_FOOTPRINT_T )
830 {
831 if( static_cast<const FOOTPRINT*>( item )->GetExcludedFromSimForVariant( variantName ) )
832 checked++;
833 else
834 unchecked++;
835 }
836 }
837
838 return checked > 0 && unchecked == 0;
839 };
840
841 auto noActiveToolCondition =
842 [this]( const SELECTION& aSelection )
843 {
844 return frame()->ToolStackIsEmpty();
845 };
846
847 auto notMovingCondition =
848 []( const SELECTION& aSelection )
849 {
850 return aSelection.Empty() || !aSelection.Front()->IsMoving();
851 };
852
853 auto noItemsCondition =
854 [this]( const SELECTION& aSelections ) -> bool
855 {
856 return frame()->GetBoard() && !frame()->GetBoard()->IsEmpty();
857 };
858
859 auto isSkippable =
860 [this]( const SELECTION& aSelection )
861 {
862 return frame()->IsCurrentTool( PCB_ACTIONS::moveIndividually );
863 };
864
867 && notMovingCondition && !inFootprintEditor;
868
869 const auto canCopyAsText = SELECTION_CONDITIONS::NotEmpty
882 } );
883
884 // Add context menu entries that are displayed when selection tool is active
885 CONDITIONAL_MENU& menu = m_selectionTool->GetToolMenu().GetMenu();
886
887 // clang-format off
888 menu.AddItem( ACTIONS::selectAll, noItemsCondition );
889 menu.AddItem( ACTIONS::unselectAll, noItemsCondition );
890 menu.AddSeparator();
891
892 menu.AddItem( PCB_ACTIONS::skip, isSkippable );
893 menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
894
901
905 menu.AddItem( PCB_ACTIONS::swapGateNets, gateSwapMultipleUnitsOnOneFootprint );
906 menu.AddMenu( gateSwapSubMenu.get(), gateSwapSingleUnitOnOneFootprint );
907
908 menu.AddSeparator();
909
912
914
915 menu.AddSeparator();
916
919
921 && !inFootprintEditor );
923
924 // Footprint actions
925 menu.AddSeparator();
926 menu.AddItem( PCB_ACTIONS::editFpInFpEditor, singleFootprintCondition );
927 menu.AddItem( PCB_ACTIONS::updateFootprint, singleFootprintCondition );
928 menu.AddItem( PCB_ACTIONS::updateFootprints, multipleFootprintsCondition );
929 menu.AddItem( PCB_ACTIONS::changeFootprint, singleFootprintCondition );
930 menu.AddItem( PCB_ACTIONS::changeFootprints, multipleFootprintsCondition );
931 menu.AddMenu( fpAttributesMenu.get(), singleFootprintCondition || multipleFootprintsCondition );
932
933 // Add the submenu for the special tools: modfiers and positioning tools
934 menu.AddSeparator( 100 );
935 menu.AddMenu( routingSubMenu.get(), isRoutable, 100 );
936 menu.AddMenu( mirrorRotateSubMenu.get(), canMirror, 100 );
937 menu.AddMenu( shapeModificationSubMenu.get(), shapeModificationCondition, 100 );
938 menu.AddMenu( positioningToolsSubMenu.get(), positioningToolsCondition, 100 );
939
940 menu.AddSeparator( 150 );
941 menu.AddItem( ACTIONS::cut, SELECTION_CONDITIONS::NotEmpty, 150 );
942 menu.AddItem( ACTIONS::copy, SELECTION_CONDITIONS::NotEmpty, 150 );
943 menu.AddItem( PCB_ACTIONS::copyWithReference, SELECTION_CONDITIONS::NotEmpty && notMovingCondition, 150 );
944 menu.AddItem( ACTIONS::copyAsText, canCopyAsText, 150 );
945
946 // Selection tool handles the context menu for some other tools, such as the Picker.
947 // Don't add things like Paste when another tool is active.
948 menu.AddItem( ACTIONS::paste, noActiveToolCondition, 150 );
949 menu.AddItem( ACTIONS::pasteSpecial, noActiveToolCondition && !inFootprintEditor, 150 );
952
953 menu.AddSeparator( 2000 );
954 menu.AddItem( PCB_ACTIONS::properties, propertiesCondition, 2000 );
955 // clang-format on
956
957 ACTION_MANAGER* mgr = m_toolMgr->GetActionManager();
958 mgr->SetConditions( PCB_ACTIONS::toggleExcludeFromBOM, ACTION_CONDITIONS().Check( excludeFromBOMCond ) );
959 mgr->SetConditions( PCB_ACTIONS::toggleExcludeFromSim, ACTION_CONDITIONS().Check( excludeFromSimCond ) );
960 mgr->SetConditions( PCB_ACTIONS::toggleExcludeFromPosFiles, ACTION_CONDITIONS().Check( excludeFromPosFilesCond ) );
961
962 return true;
963}
964
965
972{
973 wxString footprintName;
974 wxArrayString fplist;
975 const FOOTPRINTS& footprints = aFrame.GetBoard()->Footprints();
976
977 // Build list of available fp references, to display them in dialog
978 for( FOOTPRINT* fp : footprints )
979 fplist.Add( fp->GetReference() + wxT( " ( " ) + fp->GetValue() + wxT( " )" ) );
980
981 fplist.Sort();
982
983 DIALOG_GET_FOOTPRINT_BY_NAME dlg( &aFrame, fplist );
984
985 if( dlg.ShowModal() != wxID_OK ) //Aborted by user
986 return nullptr;
987
988 footprintName = dlg.GetValue();
989 footprintName.Trim( true );
990 footprintName.Trim( false );
991
992 if( !footprintName.IsEmpty() )
993 {
994 for( FOOTPRINT* fp : footprints )
995 {
996 if( fp->GetReference().CmpNoCase( footprintName ) == 0 )
997 return fp;
998 }
999 }
1000
1001 return nullptr;
1002}
1003
1004
1006{
1007 // GetAndPlace makes sense only in board editor, although it is also called
1008 // in fpeditor, that shares the same EDIT_TOOL list
1009 if( IsFootprintEditor() )
1010 return 0;
1011
1012 PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
1014
1015 if( fp )
1016 {
1017 m_toolMgr->RunAction( ACTIONS::selectionClear );
1018 m_toolMgr->RunAction<EDA_ITEM*>( ACTIONS::selectItem, fp );
1019
1020 selectionTool->GetSelection().SetReferencePoint( fp->GetPosition() );
1021 m_toolMgr->PostAction( PCB_ACTIONS::move );
1022 }
1023
1024 return 0;
1025}
1026
1027
1029{
1030 ROUTER_TOOL* theRouter = m_toolMgr->GetTool<ROUTER_TOOL>();
1031
1032 if( !theRouter )
1033 return false;
1034
1035 // don't allow switch from moving to dragging
1036 if( m_dragging )
1037 {
1038 wxBell();
1039 return false;
1040 }
1041
1042 // make sure we don't accidentally invoke inline routing mode while the router is already
1043 // active!
1044 if( theRouter->IsToolActive() )
1045 return false;
1046
1047 if( theRouter->CanInlineDrag( aDragMode ) )
1048 {
1049 m_toolMgr->RunAction( PCB_ACTIONS::routerInlineDrag, aDragMode );
1050 return true;
1051 }
1052
1053 return false;
1054}
1055
1056
1058{
1059 ROUTER_TOOL* router = m_toolMgr->GetTool<ROUTER_TOOL>();
1060
1061 return router && router->RoutingInProgress();
1062}
1063
1064
1065int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
1066{
1067 if( !m_toolMgr->GetTool<ROUTER_TOOL>() )
1068 {
1069 wxBell();
1070 return false; // don't drag when no router tool (i.e. fp editor)
1071 }
1072
1073 if( m_toolMgr->GetTool<ROUTER_TOOL>()->IsToolActive() )
1074 {
1075 wxBell();
1076 return false; // don't drag when router is already active
1077 }
1078
1079 if( m_dragging )
1080 {
1081 wxBell();
1082 return false; // don't do a router drag when already in an EDIT_TOOL drag
1083 }
1084
1085 int mode = PNS::DM_ANY;
1086
1087 if( aEvent.IsAction( &PCB_ACTIONS::dragFreeAngle ) )
1088 mode |= PNS::DM_FREE_ANGLE;
1089
1090 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1091 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1092 {
1093 sTool->FilterCollectorForFreePads( aCollector );
1094 sTool->FilterCollectorForHierarchy( aCollector, true );
1095
1096 std::vector<PCB_TRACK*> tracks;
1097 std::vector<PCB_TRACK*> vias;
1098 std::vector<FOOTPRINT*> footprints;
1099
1100 // Gather items from the collector into per-type vectors
1101 const auto gatherItemsByType =
1102 [&]()
1103 {
1104 for( EDA_ITEM* item : aCollector )
1105 {
1106 if( PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item ) )
1107 {
1108 if( track->Type() == PCB_VIA_T )
1109 vias.push_back( track );
1110 else
1111 tracks.push_back( track );
1112 }
1113 else if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item ) )
1114 {
1115 footprints.push_back( footprint );
1116 }
1117 }
1118 };
1119
1120 // Initial gathering of items
1121 gatherItemsByType();
1122
1123 if( !sTool->GetSelection().IsHover() && footprints.size() )
1124 {
1125 // Remove non-footprints so box-selection will drag footprints.
1126 for( int ii = aCollector.GetCount() - 1; ii >= 0; --ii )
1127 {
1128 if( aCollector[ii]->Type() != PCB_FOOTPRINT_T )
1129 aCollector.Remove( ii );
1130 }
1131 }
1132 else if( tracks.size() || vias.size() )
1133 {
1134 /*
1135 * First trim down selection to active layer, tracks vs zones, etc.
1136 */
1137 if( aCollector.GetCount() > 1 )
1138 {
1139 sTool->GuessSelectionCandidates( aCollector, aPt );
1140
1141 // Re-gather items after trimming to update counts
1142 tracks.clear();
1143 vias.clear();
1144 footprints.clear();
1145
1146 gatherItemsByType();
1147 }
1148
1149 /*
1150 * If we have a knee between two tracks, or a via attached to two tracks,
1151 * then drop the selection to a single item. We don't want a selection
1152 * disambiguation menu when it doesn't matter which items is picked.
1153 */
1154 auto connected =
1155 []( PCB_TRACK* track, const VECTOR2I& pt )
1156 {
1157 return track->GetStart() == pt || track->GetEnd() == pt;
1158 };
1159
1160 if( tracks.size() == 2 && vias.size() == 0 )
1161 {
1162 if( connected( tracks[0], tracks[1]->GetStart() )
1163 || connected( tracks[0], tracks[1]->GetEnd() ) )
1164 {
1165 aCollector.Remove( tracks[1] );
1166 }
1167 }
1168 else if( tracks.size() == 2 && vias.size() == 1 )
1169 {
1170 if( connected( tracks[0], vias[0]->GetPosition() )
1171 && connected( tracks[1], vias[0]->GetPosition() ) )
1172 {
1173 aCollector.Remove( tracks[0] );
1174 aCollector.Remove( tracks[1] );
1175 }
1176 }
1177 }
1178
1179 sTool->FilterCollectorForLockedItems( aCollector );
1180 } );
1181
1182 m_selectionTool->ReportFilteredLockedItems();
1183
1184 if( selection.Empty() )
1185 return 0;
1186
1187 invokeInlineRouter( mode );
1188
1189 return 0;
1190}
1191
1192
1194{
1196
1197 if( selection.Empty() )
1198 return 0;
1199
1200 wxString variantName;
1201
1202 if( BOARD* board = frame()->GetBoard() )
1203 variantName = board->GetCurrentVariant();
1204
1205 bool new_state = false;
1206
1207 for( const EDA_ITEM* item : selection )
1208 {
1209 const FOOTPRINT* fp = static_cast<const FOOTPRINT*>( item );
1210
1212 && !fp->GetExcludedFromBOMForVariant( variantName ) )
1214 && !fp->GetExcludedFromSimForVariant( variantName ) )
1216 && !fp->GetExcludedFromPosFilesForVariant( variantName ) ) )
1217 {
1218 new_state = true;
1219 break;
1220 }
1221 }
1222
1223 BOARD_COMMIT commit( this );
1224
1225 for( EDA_ITEM* item : selection )
1226 {
1227 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
1228 commit.Modify( fp );
1229
1230 if( !variantName.IsEmpty() )
1231 {
1232 FOOTPRINT_VARIANT* variant = fp->GetVariant( variantName );
1233
1234 if( !variant )
1235 variant = fp->AddVariant( variantName );
1236
1237 if( variant )
1238 {
1240 variant->SetExcludedFromBOM( new_state );
1241 else if( aEvent.IsAction( &PCB_ACTIONS::toggleExcludeFromSim ) )
1242 variant->SetExcludedFromSim( new_state );
1244 variant->SetExcludedFromPosFiles( new_state );
1245
1246 continue;
1247 }
1248 }
1249
1251 fp->SetExcludedFromBOM( new_state );
1252 else if( aEvent.IsAction( &PCB_ACTIONS::toggleExcludeFromSim ) )
1253 fp->SetExcludedFromSim( new_state );
1255 fp->SetExcludedFromPosFiles( new_state );
1256 }
1257
1258 if( !commit.Empty() )
1259 commit.Push( _( "Toggle Attribute" ) );
1260
1261 if( selection.IsHover() )
1262 m_toolMgr->RunAction( ACTIONS::selectionClear );
1263
1264 return 0;
1265}
1266
1267
1269{
1270 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1271 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1272 {
1273 // Iterate from the back so we don't have to worry about removals.
1274 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1275 {
1276 BOARD_ITEM* item = aCollector[i];
1277
1278 if( !dynamic_cast<PCB_TRACK*>( item ) )
1279 aCollector.Remove( item );
1280 }
1281
1282 sTool->FilterCollectorForLockedItems( aCollector );
1283 } );
1284
1285 m_selectionTool->ReportFilteredLockedItems();
1286
1287 BOARD_COMMIT commit( this );
1288
1289 for( EDA_ITEM* item : selection )
1290 {
1291 if( item->Type() == PCB_VIA_T )
1292 {
1293 PCB_VIA* via = static_cast<PCB_VIA*>( item );
1294
1295 commit.Modify( via );
1296
1297 if( via->GetViaType() == VIATYPE::MICROVIA )
1298 {
1299 NETCLASS* netClass = via->GetEffectiveNetClass();
1300
1301 via->SetSizeFromRules( netClass->GetuViaDiameter(), netClass->GetuViaDrill() );
1302 }
1303 else
1304 {
1305 via->SetDrill( board()->GetDesignSettings().GetCurrentViaDrill() );
1306 via->SetPadstackMode( PADSTACK::MODE::NORMAL );
1307 via->SetWidth( PADSTACK::ALL_LAYERS, board()->GetDesignSettings().GetCurrentViaSize() );
1308 }
1309 }
1310 else if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
1311 {
1312 PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item );
1313
1314 wxCHECK( track, 0 );
1315
1316 commit.Modify( track );
1317
1318 int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
1319 track->SetWidth( new_width );
1320 }
1321 }
1322
1323 commit.Push( _( "Edit Track Width/Via Size" ) );
1324
1325 if( selection.IsHover() )
1326 {
1327 m_toolMgr->RunAction( ACTIONS::selectionClear );
1328
1329 // Notify other tools of the changes -- This updates the visual ratsnest
1331 }
1332
1333 return 0;
1334}
1335
1336
1338{
1339 if( m_toolMgr->GetTool<ROUTER_TOOL>() && m_toolMgr->GetTool<ROUTER_TOOL>()->IsToolActive() )
1340 return 0;
1341
1342 bool isNext = aEvent.IsAction( &PCB_ACTIONS::changeTrackLayerNext );
1343
1344 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1345 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1346 {
1347 // Iterate from the back so we don't have to worry about removals.
1348 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1349 {
1350 BOARD_ITEM* item = aCollector[i];
1351
1352 if( !dynamic_cast<PCB_TRACK*>( item ) )
1353 aCollector.Remove( item );
1354 }
1355
1356 sTool->FilterCollectorForLockedItems( aCollector );
1357 } );
1358
1359 m_selectionTool->ReportFilteredLockedItems();
1360
1361 PCB_LAYER_ID origLayer = frame()->GetActiveLayer();
1362
1363 if( isNext )
1364 m_toolMgr->RunAction( PCB_ACTIONS::layerNext );
1365 else
1366 m_toolMgr->RunAction( PCB_ACTIONS::layerPrev );
1367
1368 PCB_LAYER_ID newLayer = frame()->GetActiveLayer();
1369
1370 if( newLayer == origLayer )
1371 return 0;
1372
1373 BOARD_COMMIT commit( this );
1374
1375 for( EDA_ITEM* item : selection )
1376 {
1377 if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
1378 {
1379 PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item );
1380
1381 wxCHECK( track, 0 );
1382
1383 commit.Modify( track );
1384
1385 track->SetLayer( newLayer );
1386 }
1387 }
1388
1389 commit.Push( _( "Edit Track Layer" ) );
1390
1391 if( selection.IsHover() )
1392 {
1393 m_toolMgr->RunAction( ACTIONS::selectionClear );
1394
1395 // Notify other tools of the changes -- This updates the visual ratsnest
1397 }
1398
1399 return 0;
1400}
1401
1402
1404{
1405 // Store last used fillet radius to allow pressing "enter" if repeat fillet is required
1406 static int filletRadius = 0;
1407
1408 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1409 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1410 {
1411 // Iterate from the back so we don't have to worry about removals.
1412 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1413 {
1414 BOARD_ITEM* item = aCollector[i];
1415
1416 if( !dynamic_cast<PCB_TRACK*>( item ) )
1417 aCollector.Remove( item );
1418 }
1419
1420 sTool->FilterCollectorForLockedItems( aCollector );
1421 } );
1422
1423 if( m_selectionTool->ReportFilteredLockedItems() )
1424 return 0;
1425
1426 if( selection.Size() < 2 )
1427 {
1428 frame()->ShowInfoBarMsg( _( "At least two straight track segments must be selected." ) );
1429 return 0;
1430 }
1431
1432 WX_UNIT_ENTRY_DIALOG dlg( frame(), _( "Fillet Tracks" ), _( "Radius:" ), filletRadius );
1433
1434 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == 0 )
1435 return 0;
1436
1437 filletRadius = dlg.GetValue();
1438
1439 struct FILLET_OP
1440 {
1441 PCB_TRACK* t1;
1442 PCB_TRACK* t2;
1443 // Start point of track is modified after PCB_ARC is added, otherwise the end point:
1444 bool t1Start = true;
1445 bool t2Start = true;
1446 };
1447
1448 std::vector<FILLET_OP> filletOperations;
1449 bool operationPerformedOnAtLeastOne = false;
1450 bool didOneAttemptFail = false;
1451 std::set<PCB_TRACK*> processedTracks;
1452
1453 auto processFilletOp =
1454 [&]( PCB_TRACK* aTrack, bool aStartPoint )
1455 {
1456 std::shared_ptr<CONNECTIVITY_DATA> c = board()->GetConnectivity();
1457 VECTOR2I anchor = aStartPoint ? aTrack->GetStart() : aTrack->GetEnd();
1458 std::vector<BOARD_CONNECTED_ITEM*> itemsOnAnchor;
1459
1460 itemsOnAnchor = c->GetConnectedItemsAtAnchor( aTrack, anchor, baseConnectedTypes );
1461
1462 if( itemsOnAnchor.size() > 0 && selection.Contains( itemsOnAnchor.at( 0 ) )
1463 && itemsOnAnchor.at( 0 )->Type() == PCB_TRACE_T )
1464 {
1465 PCB_TRACK* trackOther = static_cast<PCB_TRACK*>( itemsOnAnchor.at( 0 ) );
1466
1467 // Make sure we don't fillet the same pair of tracks twice
1468 if( processedTracks.find( trackOther ) == processedTracks.end() )
1469 {
1470 if( itemsOnAnchor.size() == 1 )
1471 {
1472 FILLET_OP filletOp;
1473 filletOp.t1 = aTrack;
1474 filletOp.t2 = trackOther;
1475 filletOp.t1Start = aStartPoint;
1476 filletOp.t2Start = aTrack->IsPointOnEnds( filletOp.t2->GetStart() );
1477 filletOperations.push_back( filletOp );
1478 }
1479 else
1480 {
1481 // User requested to fillet these two tracks but not possible as
1482 // there are other elements connected at that point
1483 didOneAttemptFail = true;
1484 }
1485 }
1486 }
1487 };
1488
1489 for( EDA_ITEM* item : selection )
1490 {
1491 if( item->Type() == PCB_TRACE_T )
1492 {
1493 PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
1494
1495 if( track->GetLength() > 0 )
1496 {
1497 processFilletOp( track, true ); // on the start point of track
1498 processFilletOp( track, false ); // on the end point of track
1499
1500 processedTracks.insert( track );
1501 }
1502 }
1503 }
1504
1505 BOARD_COMMIT commit( this );
1506 std::vector<BOARD_ITEM*> itemsToAddToSelection;
1507
1508 for( FILLET_OP filletOp : filletOperations )
1509 {
1510 PCB_TRACK* track1 = filletOp.t1;
1511 PCB_TRACK* track2 = filletOp.t2;
1512
1513 bool trackOnStart = track1->IsPointOnEnds( track2->GetStart() );
1514 bool trackOnEnd = track1->IsPointOnEnds( track2->GetEnd() );
1515
1516 if( trackOnStart && trackOnEnd )
1517 continue; // Ignore duplicate tracks
1518
1519 if( ( trackOnStart || trackOnEnd ) && track1->GetLayer() == track2->GetLayer() )
1520 {
1521 SEG t1Seg( track1->GetStart(), track1->GetEnd() );
1522 SEG t2Seg( track2->GetStart(), track2->GetEnd() );
1523
1524 if( t1Seg.ApproxCollinear( t2Seg ) )
1525 continue;
1526
1527 SHAPE_ARC sArc( t1Seg, t2Seg, filletRadius );
1528 VECTOR2I t1newPoint, t2newPoint;
1529
1530 auto setIfPointOnSeg =
1531 []( VECTOR2I& aPointToSet, const SEG& aSegment, const VECTOR2I& aVecToTest )
1532 {
1533 VECTOR2I segToVec = aSegment.NearestPoint( aVecToTest ) - aVecToTest;
1534
1535 // Find out if we are on the segment (minimum precision)
1537 {
1538 aPointToSet.x = aVecToTest.x;
1539 aPointToSet.y = aVecToTest.y;
1540 return true;
1541 }
1542
1543 return false;
1544 };
1545
1546 //Do not draw a fillet if the end points of the arc are not within the track segments
1547 if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP0() )
1548 && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP0() ) )
1549 {
1550 didOneAttemptFail = true;
1551 continue;
1552 }
1553
1554 if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP1() )
1555 && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP1() ) )
1556 {
1557 didOneAttemptFail = true;
1558 continue;
1559 }
1560
1561 PCB_ARC* tArc = new PCB_ARC( frame()->GetBoard(), &sArc );
1562 tArc->SetLayer( track1->GetLayer() );
1563 tArc->SetWidth( track1->GetWidth() );
1564 tArc->SetNet( track1->GetNet() );
1565 tArc->SetLocked( track1->IsLocked() );
1566 tArc->SetHasSolderMask( track1->HasSolderMask() );
1568 commit.Add( tArc );
1569 itemsToAddToSelection.push_back( tArc );
1570
1571 commit.Modify( track1 );
1572 commit.Modify( track2 );
1573
1574 if( filletOp.t1Start )
1575 track1->SetStart( t1newPoint );
1576 else
1577 track1->SetEnd( t1newPoint );
1578
1579 if( filletOp.t2Start )
1580 track2->SetStart( t2newPoint );
1581 else
1582 track2->SetEnd( t2newPoint );
1583
1584 operationPerformedOnAtLeastOne = true;
1585 }
1586 }
1587
1588 commit.Push( _( "Fillet Tracks" ) );
1589
1590 //select the newly created arcs
1591 for( BOARD_ITEM* item : itemsToAddToSelection )
1592 m_selectionTool->AddItemToSel( item );
1593
1594 if( !operationPerformedOnAtLeastOne )
1595 frame()->ShowInfoBarMsg( _( "Unable to fillet the selected track segments." ) );
1596 else if( didOneAttemptFail )
1597 frame()->ShowInfoBarMsg( _( "Some of the track segments could not be filleted." ) );
1598
1599 return 0;
1600}
1601
1602
1612static std::optional<int> GetRadiusParams( PCB_BASE_EDIT_FRAME& aFrame, const wxString& aTitle, int& aPersitentRadius )
1613{
1614 WX_UNIT_ENTRY_DIALOG dlg( &aFrame, aTitle, _( "Radius:" ), aPersitentRadius );
1615
1616 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == 0 )
1617 return std::nullopt;
1618
1619 aPersitentRadius = dlg.GetValue();
1620
1621 return aPersitentRadius;
1622}
1623
1624
1625static std::optional<DOGBONE_CORNER_ROUTINE::PARAMETERS> GetDogboneParams( PCB_BASE_EDIT_FRAME& aFrame )
1626{
1627 // Persistent parameters
1628 static DOGBONE_CORNER_ROUTINE::PARAMETERS s_dogBoneParams{
1629 pcbIUScale.mmToIU( 1 ),
1630 true,
1631 };
1632
1633 std::vector<WX_MULTI_ENTRY_DIALOG::ENTRY> entries{
1634 {
1635 _( "Arc radius:" ),
1636 WX_MULTI_ENTRY_DIALOG::UNIT_BOUND{ s_dogBoneParams.DogboneRadiusIU },
1637 wxEmptyString,
1638 },
1639 {
1640 _( "Add slots in acute corners" ),
1641 WX_MULTI_ENTRY_DIALOG::CHECKBOX{ s_dogBoneParams.AddSlots },
1642 _( "Add slots in acute corners to allow access to a cutter of the given radius" ),
1643 },
1644 };
1645
1646 WX_MULTI_ENTRY_DIALOG dlg( &aFrame, _( "Dogbone Corner Settings" ), entries );
1647
1648 if( dlg.ShowModal() == wxID_CANCEL )
1649 return std::nullopt;
1650
1651 std::vector<WX_MULTI_ENTRY_DIALOG::RESULT> results = dlg.GetValues();
1652 wxCHECK( results.size() == 2, std::nullopt );
1653
1654 try
1655 {
1656 s_dogBoneParams.DogboneRadiusIU = std::get<long long int>( results[0] );
1657 s_dogBoneParams.AddSlots = std::get<bool>( results[1] );
1658 }
1659 catch( const std::bad_variant_access& )
1660 {
1661 wxASSERT( false );
1662 return std::nullopt;
1663 }
1664
1665 return s_dogBoneParams;
1666}
1667
1674static std::optional<CHAMFER_PARAMS> GetChamferParams( PCB_BASE_EDIT_FRAME& aFrame )
1675{
1676 // Non-zero and the KLC default for Fab layer chamfers
1677 const int default_setback = pcbIUScale.mmToIU( 1 );
1678 // Store last used setback to allow pressing "enter" if repeat chamfer is required
1679 static CHAMFER_PARAMS params{ default_setback, default_setback };
1680
1681 WX_UNIT_ENTRY_DIALOG dlg( &aFrame, _( "Chamfer Lines" ), _( "Chamfer setback:" ), params.m_chamfer_setback_a );
1682
1683 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == 0 )
1684 return std::nullopt;
1685
1686 params.m_chamfer_setback_a = dlg.GetValue();
1687 // It's hard to easily specify an asymmetric chamfer (which line gets the longer setback?),
1688 // so we just use the same setback for each
1689 params.m_chamfer_setback_b = params.m_chamfer_setback_a;
1690
1691 return params;
1692}
1693
1694
1696{
1697 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1698 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1699 {
1700 std::vector<VECTOR2I> pts;
1701
1702 // Iterate from the back so we don't have to worry about removals.
1703 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1704 {
1705 BOARD_ITEM* item = aCollector[i];
1706
1707 // We've converted the polygon and rectangle to segments, so drop everything
1708 // that isn't a segment at this point
1709 if( !item->IsType(
1710 { PCB_SHAPE_LOCATE_SEGMENT_T, PCB_SHAPE_LOCATE_POLY_T, PCB_SHAPE_LOCATE_RECT_T } ) )
1711 {
1712 aCollector.Remove( item );
1713 }
1714 }
1715
1716 sTool->FilterCollectorForLockedItems( aCollector );
1717 } );
1718
1719 m_selectionTool->ReportFilteredLockedItems();
1720
1721 std::set<PCB_SHAPE*> lines_to_add;
1722 std::vector<PCB_SHAPE*> items_to_remove;
1723
1724 for( EDA_ITEM* item : selection )
1725 {
1726 std::vector<VECTOR2I> pts;
1727 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( item );
1728 PCB_LAYER_ID layer = graphic->GetLayer();
1729 int width = graphic->GetWidth();
1730
1731 if( graphic->GetShape() == SHAPE_T::RECTANGLE )
1732 {
1733 items_to_remove.push_back( graphic );
1734 VECTOR2I start( graphic->GetStart() );
1735 VECTOR2I end( graphic->GetEnd() );
1736 pts.emplace_back( start );
1737 pts.emplace_back( VECTOR2I( end.x, start.y ) );
1738 pts.emplace_back( end );
1739 pts.emplace_back( VECTOR2I( start.x, end.y ) );
1740 }
1741
1742 if( graphic->GetShape() == SHAPE_T::POLY )
1743 {
1744 items_to_remove.push_back( graphic );
1745
1746 for( int jj = 0; jj < graphic->GetPolyShape().VertexCount(); ++jj )
1747 pts.emplace_back( graphic->GetPolyShape().CVertex( jj ) );
1748 }
1749
1750 for( size_t jj = 1; jj < pts.size(); ++jj )
1751 {
1752 PCB_SHAPE* line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT );
1753
1754 line->SetStart( pts[jj - 1] );
1755 line->SetEnd( pts[jj] );
1756 line->SetWidth( width );
1757 line->SetLayer( layer );
1758 lines_to_add.insert( line );
1759 }
1760
1761 if( pts.size() > 1 )
1762 {
1763 PCB_SHAPE* line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT );
1764
1765 line->SetStart( pts.back() );
1766 line->SetEnd( pts.front() );
1767 line->SetWidth( width );
1768 line->SetLayer( layer );
1769 lines_to_add.insert( line );
1770 }
1771 }
1772
1773 int segmentCount = selection.CountType( PCB_SHAPE_LOCATE_SEGMENT_T ) + lines_to_add.size();
1774
1775 if( aEvent.IsAction( &PCB_ACTIONS::extendLines ) && segmentCount != 2 )
1776 {
1777 frame()->ShowInfoBarMsg( _( "Exactly two lines must be selected to extend them." ) );
1778
1779 for( PCB_SHAPE* line : lines_to_add )
1780 delete line;
1781
1782 return 0;
1783 }
1784 else if( segmentCount < 2 )
1785 {
1786 frame()->ShowInfoBarMsg( _( "A shape with at least two lines must be selected." ) );
1787
1788 for( PCB_SHAPE* line : lines_to_add )
1789 delete line;
1790
1791 return 0;
1792 }
1793
1794 BOARD_COMMIT commit( this );
1795
1796 // Items created like lines from a rectangle
1797 for( PCB_SHAPE* item : lines_to_add )
1798 {
1799 commit.Add( item );
1800 selection.Add( item );
1801 }
1802
1803 // Remove items like rectangles that we decomposed into lines
1804 for( PCB_SHAPE* item : items_to_remove )
1805 {
1806 selection.Remove( item );
1807 commit.Remove( item );
1808 }
1809
1810 for( EDA_ITEM* item : selection )
1811 item->ClearFlags( STRUCT_DELETED );
1812
1813 // List of thing to select at the end of the operation
1814 // (doing it as we go will invalidate the iterator)
1815 std::vector<BOARD_ITEM*> items_to_select_on_success;
1816
1817 // And same for items to deselect
1818 std::vector<BOARD_ITEM*> items_to_deselect_on_success;
1819
1820 // Handle modifications to existing items by the routine
1821 // How to deal with this depends on whether we're in the footprint editor or not
1822 // and whether the item was conjured up by decomposing a polygon or rectangle
1823 auto item_modification_handler =
1824 [&]( BOARD_ITEM& aItem )
1825 {
1826 // If the item was "conjured up" it will be added later separately
1827 if( !alg::contains( lines_to_add, &aItem ) )
1828 {
1829 commit.Modify( &aItem );
1830 items_to_select_on_success.push_back( &aItem );
1831 }
1832 };
1833
1834 bool any_items_created = !lines_to_add.empty();
1835 auto item_creation_handler =
1836 [&]( std::unique_ptr<BOARD_ITEM> aItem )
1837 {
1838 any_items_created = true;
1839 items_to_select_on_success.push_back( aItem.get() );
1840 commit.Add( aItem.release() );
1841 };
1842
1843 bool any_items_removed = !items_to_remove.empty();
1844 auto item_removal_handler =
1845 [&]( BOARD_ITEM& aItem )
1846 {
1847 aItem.SetFlags( STRUCT_DELETED );
1848 any_items_removed = true;
1849 items_to_deselect_on_success.push_back( &aItem );
1850 commit.Remove( &aItem );
1851 };
1852
1853 // Combine these callbacks into a CHANGE_HANDLER to inject in the ROUTINE
1854 ITEM_MODIFICATION_ROUTINE::CALLABLE_BASED_HANDLER change_handler( item_creation_handler, item_modification_handler,
1855 item_removal_handler );
1856
1857 // Construct an appropriate tool
1858 std::unique_ptr<PAIRWISE_LINE_ROUTINE> pairwise_line_routine;
1859
1860 if( aEvent.IsAction( &PCB_ACTIONS::filletLines ) )
1861 {
1862 static int s_filletRadius = pcbIUScale.mmToIU( 1 );
1863 std::optional<int> filletRadiusIU = GetRadiusParams( *frame(), _( "Fillet Lines" ), s_filletRadius );
1864
1865 if( filletRadiusIU.has_value() )
1866 {
1867 pairwise_line_routine = std::make_unique<LINE_FILLET_ROUTINE>( frame()->GetModel(), change_handler,
1868 *filletRadiusIU );
1869 }
1870 }
1871 else if( aEvent.IsAction( &PCB_ACTIONS::dogboneCorners ) )
1872 {
1873 std::optional<DOGBONE_CORNER_ROUTINE::PARAMETERS> dogboneParams = GetDogboneParams( *frame() );
1874
1875 if( dogboneParams.has_value() )
1876 {
1877 pairwise_line_routine = std::make_unique<DOGBONE_CORNER_ROUTINE>( frame()->GetModel(), change_handler,
1878 *dogboneParams );
1879 }
1880 }
1881 else if( aEvent.IsAction( &PCB_ACTIONS::chamferLines ) )
1882 {
1883 std::optional<CHAMFER_PARAMS> chamfer_params = GetChamferParams( *frame() );
1884
1885 if( chamfer_params.has_value() )
1886 {
1887 pairwise_line_routine = std::make_unique<LINE_CHAMFER_ROUTINE>( frame()->GetModel(), change_handler,
1888 *chamfer_params );
1889 }
1890 }
1891 else if( aEvent.IsAction( &PCB_ACTIONS::extendLines ) )
1892 {
1893 pairwise_line_routine = std::make_unique<LINE_EXTENSION_ROUTINE>( frame()->GetModel(), change_handler );
1894 }
1895
1896 if( !pairwise_line_routine )
1897 {
1898 // Didn't construct any mofication routine - user must have cancelled
1899 commit.Revert();
1900 return 0;
1901 }
1902
1903 // Apply the tool to every line pair
1904 alg::for_all_pairs( selection.begin(), selection.end(),
1905 [&]( EDA_ITEM* a, EDA_ITEM* b )
1906 {
1907 if( ( a->GetFlags() & STRUCT_DELETED ) == 0 && ( b->GetFlags() & STRUCT_DELETED ) == 0 )
1908 {
1909 PCB_SHAPE* line_a = static_cast<PCB_SHAPE*>( a );
1910 PCB_SHAPE* line_b = static_cast<PCB_SHAPE*>( b );
1911
1912 pairwise_line_routine->ProcessLinePair( *line_a, *line_b );
1913 }
1914 } );
1915
1916 // Select added and modified items
1917 for( BOARD_ITEM* item : items_to_select_on_success )
1918 m_selectionTool->AddItemToSel( item, true );
1919
1920 // Deselect removed items
1921 for( BOARD_ITEM* item : items_to_deselect_on_success )
1922 m_selectionTool->RemoveItemFromSel( item, true );
1923
1924 if( any_items_removed )
1925 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1926
1927 if( any_items_created )
1928 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
1929
1930 // Notify other tools of the changes
1931 m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
1932
1933 commit.Push( pairwise_line_routine->GetCommitDescription() );
1934
1935 if( const std::optional<wxString> msg = pairwise_line_routine->GetStatusMessage( segmentCount ) )
1936 frame()->ShowInfoBarMsg( *msg );
1937
1938 return 0;
1939}
1940
1941
1943{
1944 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1945 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1946 {
1947 std::vector<VECTOR2I> pts;
1948
1949 // Iterate from the back so we don't have to worry about removals.
1950 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1951 {
1952 BOARD_ITEM* item = aCollector[i];
1953
1954 if( !item->IsType( { PCB_SHAPE_LOCATE_POLY_T, PCB_ZONE_T } ) )
1955 aCollector.Remove( item );
1956
1957 if( ZONE* zone = dyn_cast<ZONE*>( item ) )
1958 {
1959 if( zone->IsTeardropArea() )
1960 aCollector.Remove( item );
1961 }
1962 }
1963
1964 sTool->FilterCollectorForLockedItems( aCollector );
1965 } );
1966
1967 m_selectionTool->ReportFilteredLockedItems();
1968
1969 // Store last used value
1970 static int s_toleranceValue = pcbIUScale.mmToIU( 3 );
1971
1972 WX_UNIT_ENTRY_DIALOG dlg( frame(), _( "Simplify Shapes" ), _( "Tolerance value:" ), s_toleranceValue );
1973
1974 if( dlg.ShowModal() == wxID_CANCEL )
1975 return 0;
1976
1977 s_toleranceValue = dlg.GetValue();
1978
1979 if( s_toleranceValue <= 0 )
1980 return 0;
1981
1982 BOARD_COMMIT commit{ this };
1983
1984 std::vector<PCB_SHAPE*> shapeList;
1985
1986 for( EDA_ITEM* item : selection )
1987 {
1988 commit.Modify( item );
1989
1990 if( PCB_SHAPE* shape = dyn_cast<PCB_SHAPE*>( item ) )
1991 {
1992 SHAPE_POLY_SET& poly = shape->GetPolyShape();
1993
1994 poly.SimplifyOutlines( s_toleranceValue );
1995 }
1996
1997 if( ZONE* zone = dyn_cast<ZONE*>( item ) )
1998 {
1999 SHAPE_POLY_SET* poly = zone->Outline();
2000
2001 poly->SimplifyOutlines( s_toleranceValue );
2002 zone->HatchBorder();
2003 }
2004 }
2005
2006 commit.Push( _( "Simplify Polygons" ) );
2007
2008 // Notify other tools of the changes
2010
2011 return 0;
2012}
2013
2014
2016{
2017 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2018 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2019 {
2020 std::vector<VECTOR2I> pts;
2021
2022 // Iterate from the back so we don't have to worry about removals.
2023 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
2024 {
2025 BOARD_ITEM* item = aCollector[i];
2026
2027 // We've converted the polygon and rectangle to segments, so drop everything
2028 // that isn't a segment at this point
2029 if( !item->IsType( { PCB_SHAPE_LOCATE_SEGMENT_T,
2030 PCB_SHAPE_LOCATE_ARC_T,
2031 PCB_SHAPE_LOCATE_BEZIER_T } ) )
2032 {
2033 aCollector.Remove( item );
2034 }
2035 }
2036
2037 sTool->FilterCollectorForLockedItems( aCollector );
2038 } );
2039
2040 m_selectionTool->ReportFilteredLockedItems();
2041
2042 // Store last used value
2043 static int s_toleranceValue = pcbIUScale.mmToIU( 3 );
2044
2045 WX_UNIT_ENTRY_DIALOG dlg( frame(), _( "Heal Shapes" ), _( "Tolerance value:" ), s_toleranceValue );
2046
2047 if( dlg.ShowModal() == wxID_CANCEL )
2048 return 0;
2049
2050 s_toleranceValue = dlg.GetValue();
2051
2052 if( s_toleranceValue <= 0 )
2053 return 0;
2054
2055 BOARD_COMMIT commit{ this };
2056
2057 std::vector<PCB_SHAPE*> shapeList;
2058
2059 for( EDA_ITEM* item : selection )
2060 {
2061 if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item ) )
2062 {
2063 shapeList.push_back( shape );
2064 commit.Modify( shape );
2065 }
2066 }
2067
2068 ConnectBoardShapes( shapeList, s_toleranceValue );
2069
2070 commit.Push( _( "Heal Shapes" ) );
2071
2072 // Notify other tools of the changes
2074
2075 return 0;
2076}
2077
2078
2080{
2081 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2082 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2083 {
2084 // Iterate from the back so we don't have to worry about removals.
2085 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
2086 {
2087 BOARD_ITEM* item = aCollector[i];
2088
2089 static const std::vector<KICAD_T> polygonBooleanTypes = {
2093 };
2094
2095 if( !item->IsType( polygonBooleanTypes ) )
2096 aCollector.Remove( item );
2097 }
2098
2099 sTool->FilterCollectorForLockedItems( aCollector );
2100 } );
2101
2102 m_selectionTool->ReportFilteredLockedItems();
2103
2104 const EDA_ITEM* const last_item = selection.GetLastAddedItem();
2105
2106 // Gather or construct polygon source shapes to merge
2107 std::vector<PCB_SHAPE*> items_to_process;
2108
2109 for( EDA_ITEM* item : selection )
2110 {
2111 items_to_process.push_back( static_cast<PCB_SHAPE*>( item ) );
2112
2113 // put the last one in the selection at the front of the vector
2114 // so it can be used as the property donor and as the basis for the
2115 // boolean operation
2116 if( item == last_item )
2117 std::swap( items_to_process.back(), items_to_process.front() );
2118 }
2119
2120 BOARD_COMMIT commit{ this };
2121
2122 // Handle modifications to existing items by the routine
2123 auto item_modification_handler =
2124 [&]( BOARD_ITEM& aItem )
2125 {
2126 commit.Modify( &aItem );
2127 };
2128
2129 std::vector<BOARD_ITEM*> items_to_select_on_success;
2130
2131 auto item_creation_handler =
2132 [&]( std::unique_ptr<BOARD_ITEM> aItem )
2133 {
2134 items_to_select_on_success.push_back( aItem.get() );
2135 commit.Add( aItem.release() );
2136 };
2137
2138 auto item_removal_handler =
2139 [&]( BOARD_ITEM& aItem )
2140 {
2141 commit.Remove( &aItem );
2142 };
2143
2144 // Combine these callbacks into a CHANGE_HANDLER to inject in the ROUTINE
2145 ITEM_MODIFICATION_ROUTINE::CALLABLE_BASED_HANDLER change_handler( item_creation_handler, item_modification_handler,
2146 item_removal_handler );
2147
2148 // Construct an appropriate routine
2149 std::unique_ptr<POLYGON_BOOLEAN_ROUTINE> boolean_routine;
2150
2151 const auto create_routine =
2152 [&]() -> std::unique_ptr<POLYGON_BOOLEAN_ROUTINE>
2153 {
2154 // (Re-)construct the boolean routine based on the action
2155 // This is done here so that we can re-init the routine if we need to
2156 // go again in the reverse order.
2157
2158 BOARD_ITEM_CONTAINER* const model = frame()->GetModel();
2159 wxCHECK( model, nullptr );
2160
2161 if( aEvent.IsAction( &PCB_ACTIONS::mergePolygons ) )
2162 {
2163 return std::make_unique<POLYGON_MERGE_ROUTINE>( model, change_handler );
2164 }
2165 else if( aEvent.IsAction( &PCB_ACTIONS::subtractPolygons ) )
2166 {
2167 return std::make_unique<POLYGON_SUBTRACT_ROUTINE>( model, change_handler );
2168 }
2169 else if( aEvent.IsAction( &PCB_ACTIONS::intersectPolygons ) )
2170 {
2171 return std::make_unique<POLYGON_INTERSECT_ROUTINE>( model, change_handler );
2172 }
2173 return nullptr;
2174 };
2175
2176 const auto run_routine =
2177 [&]()
2178 {
2179 // Perform the operation on each polygon
2180 for( PCB_SHAPE* shape : items_to_process )
2181 boolean_routine->ProcessShape( *shape );
2182
2183 boolean_routine->Finalize();
2184 };
2185
2186 boolean_routine = create_routine();
2187
2188 wxCHECK_MSG( boolean_routine, 0, "Could not find a polygon routine for this action" );
2189
2190 // First run the routine and see what we get
2191 run_routine();
2192
2193 // If we are doing a non-commutative operation (e.g. subtract), and we just got null,
2194 // assume the user meant go in a different opposite order
2195 if( !boolean_routine->IsCommutative() && items_to_select_on_success.empty() )
2196 {
2197 // Clear the commit and the selection
2198 commit.Revert();
2199 items_to_select_on_success.clear();
2200
2201 std::map<const PCB_SHAPE*, VECTOR2I::extended_type> items_area;
2202
2203 for( PCB_SHAPE* shape : items_to_process )
2204 {
2205 VECTOR2I::extended_type area = shape->GetBoundingBox().GetArea();
2206 items_area[shape] = area;
2207 }
2208
2209 // Sort the shapes by their bounding box area in descending order
2210 // This way we will start with the largest shape first and subtract the smaller ones
2211 // This may not work perfectly in all cases, but it works well when the larger
2212 // shape completely contains the smaller ones, which is probably the most common case.
2213 // In other cases, the user will need to select the shapes in the correct order (i.e.
2214 // the largest shape last), or do the subtractions in multiple steps.
2215 std::sort( items_to_process.begin(), items_to_process.end(),
2216 [&]( const PCB_SHAPE* a, const PCB_SHAPE* b )
2217 {
2218 return items_area[a] > items_area[b];
2219 } );
2220
2221 // Run the routine again
2222 boolean_routine = create_routine();
2223 run_routine();
2224 }
2225
2226 // Select new items
2227 for( BOARD_ITEM* item : items_to_select_on_success )
2228 m_selectionTool->AddItemToSel( item, true );
2229
2230 // Notify other tools of the changes
2232
2233 commit.Push( boolean_routine->GetCommitDescription() );
2234
2235 if( const std::optional<wxString> msg = boolean_routine->GetStatusMessage() )
2236 frame()->ShowInfoBarMsg( *msg );
2237
2238 return 0;
2239}
2240
2241
2243{
2245
2246 // A constraint selected by clicking its badge has no board selection, so Edit targets it here
2247 // before the normal properties path (mirrors the Delete hook for a badge-selected constraint).
2248 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
2249 constraintTool && constraintTool->TryEditSelectedConstraint() )
2250 {
2251 return 0;
2252 }
2253
2254 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2255 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2256 {
2257 } );
2258
2259 // Snapshot undo depth to detect whether dialog actually committed
2260 // Cancel leaves it unchanged and must not trigger a constraint resolve
2261 const int undoBefore = editFrame->GetUndoCommandCount();
2262
2263 // Detector to reject attempting to edit generated items that may be selectable
2264 // but we don't want to remain read-only to outside-the-generator editing
2265 auto containsReadOnlyGenChild =
2266 []( const SELECTION& aSel ) -> bool
2267 {
2268 for( EDA_ITEM* item : aSel )
2269 {
2270 if( !item->IsBOARD_ITEM() )
2271 continue;
2272
2273 EDA_GROUP* parent = static_cast<BOARD_ITEM*>( item )->GetParentGroup();
2274
2275 if( !parent || parent->AsEdaItem()->Type() != PCB_GENERATOR_T )
2276 continue;
2277
2278 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( parent->AsEdaItem() );
2279
2280 if( gen->ChildrenAreReadOnly() )
2281 return true;
2282 }
2283
2284 return false;
2285 };
2286
2287 if( containsReadOnlyGenChild( selection ) )
2288 {
2289 wxBell();
2290 }
2291 // Tracks & vias are treated in a special way:
2293 {
2294 DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection );
2295 dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
2296 }
2298 {
2299 std::vector<PCB_TABLECELL*> cells;
2300
2301 for( EDA_ITEM* item : selection.Items() )
2302 cells.push_back( static_cast<PCB_TABLECELL*>( item ) );
2303
2304 DIALOG_TABLECELL_PROPERTIES dlg( editFrame, cells );
2305
2306 // QuasiModal required for syntax help and Scintilla auto-complete
2307 dlg.ShowQuasiModal();
2308
2310 {
2311 PCB_TABLE* table = static_cast<PCB_TABLE*>( cells[0]->GetParent() );
2312 DIALOG_TABLE_PROPERTIES tableDlg( frame(), table );
2313
2314 tableDlg.ShowQuasiModal(); // Scintilla's auto-complete requires quasiModal
2315 }
2316 }
2317 else if( selection.Size() == 1 && selection.Front()->IsBOARD_ITEM() )
2318 {
2319 // Display properties dialog
2320 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
2321
2322 // Do not handle undo buffer, it is done by the properties dialogs
2323 editFrame->OnEditItemRequest( item );
2324
2325 // Notify other tools of the changes
2327 }
2328 else if( selection.Size() == 0 && getView()->IsLayerVisible( LAYER_DRAWINGSHEET ) )
2329 {
2330 DS_PROXY_VIEW_ITEM* ds = editFrame->GetCanvas()->GetDrawingSheet();
2331 VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
2332
2333 if( ds && ds->HitTestDrawingSheetItems( getView(), cursorPos ) )
2334 m_toolMgr->PostAction( ACTIONS::pageSettings );
2335 else
2337 }
2338 else if( selection.Size() > 1 )
2339 {
2340 WX_INFOBAR* infobar = frame()->GetInfoBar();
2341
2342 infobar->RemoveAllButtons();
2343
2344 if( !frame()->GetPropertiesPanel()->IsShownOnScreen() )
2345 {
2346 infobar->AddLink( _( "Show Properties panel" ),
2347 [this]( wxHyperlinkEvent& aHyperlinkEvent )
2348 {
2349 frame()->ToggleProperties();
2350 } );
2351 }
2352
2353 infobar->AddCloseButton();
2354 infobar->ShowMessageFor( _( "Use Properties panel to edit properties common to selected items." ),
2355 8000, wxICON_INFORMATION );
2356 }
2357
2358 // Position or geometry edit via these dialogs settles constraints as if item were dragged
2359 // holding edited item and moving neighbors gated on real commit so canceled dialog skips the solve
2360 if( editFrame->GetUndoCommandCount() > undoBefore )
2361 {
2362 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>() )
2363 {
2364 std::vector<PCB_SHAPE*> shapes;
2366 constraintTool->SolveAfterEdit( shapes );
2367 }
2368 }
2369
2370 if( selection.IsHover() )
2371 {
2372 m_toolMgr->RunAction( ACTIONS::selectionClear );
2373 }
2374 else
2375 {
2376 // Check for items becoming invisible and drop them from the selection.
2377
2378 PCB_SELECTION selCopy = selection;
2379 LSET visible = editFrame->GetBoard()->GetVisibleLayers();
2380
2381 for( EDA_ITEM* eda_item : selCopy )
2382 {
2383 if( !eda_item->IsBOARD_ITEM() )
2384 continue;
2385
2386 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( eda_item );
2387
2388 if( !( item->GetLayerSet() & visible ).any() )
2389 m_selectionTool->RemoveItemFromSel( item );
2390 }
2391 }
2392
2393 if( m_dragging )
2394 {
2397 }
2398
2399 return 0;
2400}
2401
2402
2404{
2405 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2406 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2407 {
2408 sTool->FilterCollectorForMarkers( aCollector );
2409 sTool->FilterCollectorForHierarchy( aCollector, true );
2410 sTool->FilterCollectorForTableCells( aCollector );
2411 sTool->FilterCollectorForLockedItems( aCollector );
2412 } );
2413
2414 m_selectionTool->ReportFilteredLockedItems();
2415
2417 {
2418 wxBell();
2419 return 0;
2420 }
2421
2423 BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selection.Front() );
2424
2425 if( editFrame && item )
2426 editFrame->OpenVertexEditor( item );
2427
2428 return 0;
2429}
2430
2431
2432void EDIT_TOOL::collectConstraintShapes( const SELECTION& aSelection, std::vector<PCB_SHAPE*>& aShapes )
2433{
2434 // Recurse so constrained shapes carried inside a transformed footprint or group seed their
2435 // clusters too; a top-level-only walk would leave those constraints silently violated.
2436 // PCB_GROUP::RunOnChildren only descends into groups and generators, so recurse through every
2437 // container ourselves; the visited set guards against overlapping ownership paths.
2438 std::unordered_set<BOARD_ITEM*> visited;
2439
2440 std::function<void( BOARD_ITEM* )> collect =
2441 [&]( BOARD_ITEM* aItem )
2442 {
2443 if( !aItem || !visited.insert( aItem ).second )
2444 return;
2445
2446 if( aItem->Type() == PCB_SHAPE_T )
2447 aShapes.push_back( static_cast<PCB_SHAPE*>( aItem ) );
2448
2449 aItem->RunOnChildren( collect, RECURSE_MODE::NO_RECURSE );
2450 };
2451
2452 for( EDA_ITEM* item : aSelection )
2453 {
2454 if( item->IsBOARD_ITEM() )
2455 collect( static_cast<BOARD_ITEM*>( item ) );
2456 }
2457}
2458
2459
2461{
2462 CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
2463
2464 if( !constraintTool )
2465 return;
2466
2467 std::vector<PCB_SHAPE*> shapes;
2468 collectConstraintShapes( aSelection, shapes );
2469
2470 constraintTool->SolveAfterMove( shapes );
2471}
2472
2473
2474int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
2475{
2476 if( isRouterActive() )
2477 {
2478 wxBell();
2479 return 0;
2480 }
2481
2483 BOARD_COMMIT localCommit( this );
2484 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2485
2486 if( !commit )
2487 commit = &localCommit;
2488
2489 // Be sure that there is at least one item that we can modify. If nothing was selected before,
2490 // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
2491 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2492 [&]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2493 {
2494 sTool->FilterCollectorForMarkers( aCollector );
2495 sTool->FilterCollectorForHierarchy( aCollector, true );
2496 sTool->FilterCollectorForFreePads( aCollector, false );
2497 sTool->FilterCollectorForTableCells( aCollector );
2498
2499 // Filter locked items if in board editor and in free-pad-mode. (If we're not in
2500 // free-pad mode we delay this until the second RequestSelection().)
2501 if( !m_isFootprintEditor && frame()->GetPcbNewSettings()->m_AllowFreePads )
2502 sTool->FilterCollectorForLockedItems( aCollector );
2503 } );
2504
2505 if( m_selectionTool->ReportFilteredLockedItems() )
2506 return 0;
2507
2508 if( selection.Empty() )
2509 return 0;
2510
2511 std::optional<VECTOR2I> oldRefPt;
2512 bool is_hover = selection.IsHover(); // N.B. This must be saved before the second
2513 // call to RequestSelection() below
2514
2515 if( selection.HasReferencePoint() )
2516 oldRefPt = selection.GetReferencePoint();
2517
2518 // Now filter out pads if not in free pads mode. We cannot do this in the first
2519 // RequestSelection() as we need the reference point when a pad is the selection front.
2520 if( !m_isFootprintEditor && !frame()->GetPcbNewSettings()->m_AllowFreePads )
2521 {
2522 PCB_SELECTION& filtered = m_selectionTool->RequestSelection(
2523 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2524 {
2525 sTool->FilterCollectorForMarkers( aCollector );
2526 sTool->FilterCollectorForHierarchy( aCollector, true );
2527 sTool->FilterCollectorForFreePads( aCollector );
2528 sTool->FilterCollectorForTableCells( aCollector );
2529 sTool->FilterCollectorForLockedItems( aCollector );
2530 } );
2531
2532 if( m_selectionTool->ReportFilteredLockedItems() )
2533 return 0;
2534
2535 selection = filtered;
2536 }
2537
2538 // Did we filter everything out? If so, don't try to operate further
2539 if( selection.Empty() )
2540 return 0;
2541
2542 // Some PCB_SHAPE must be rotated around their center instead of their start point in
2543 // order to stay to the same place (at least RECT and POLY)
2544 // Note a RECT shape rotated by a not cardinal angle is a POLY shape
2545 bool usePcbShapeCenter = false;
2546
2547 if( selection.Size() == 1 && !m_dragging && dynamic_cast<PCB_SHAPE*>( selection.Front() ) )
2548 {
2549 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( selection.Front() );
2550
2551 if( shape->GetShape() == SHAPE_T::RECTANGLE || shape->GetShape() == SHAPE_T::POLY )
2552 usePcbShapeCenter = true;
2553 }
2554
2555 if( selection.Size() == 1 && !m_dragging && dynamic_cast<PCB_TABLE*>( selection.Front() ) )
2556 usePcbShapeCenter = true;
2557
2558 if( selection.Size() == 1 && !m_dragging && dynamic_cast<PCB_TEXTBOX*>( selection.Front() ) )
2559 {
2560 selection.SetReferencePoint( static_cast<PCB_TEXTBOX*>( selection.Front() )->GetCenter() );
2561 }
2562 else if( usePcbShapeCenter )
2563 {
2564 selection.SetReferencePoint( static_cast<PCB_SHAPE*>( selection.Front() )->GetCenter() );
2565 }
2566 else
2567 {
2569 }
2570
2571 VECTOR2I refPt = selection.GetReferencePoint();
2572 EDA_ANGLE rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
2573
2574 if( frame()->GetCanvas()->GetView()->GetGAL()->IsFlippedX() )
2575 rotateAngle = -rotateAngle;
2576
2577 // Calculate view bounding box
2578 BOX2I viewBBox = selection.Front()->ViewBBox();
2579
2580 for( EDA_ITEM* item : selection )
2581 viewBBox.Merge( item->ViewBBox() );
2582
2583 // Check if the view bounding box will go out of bounds
2584 VECTOR2D rotPos = viewBBox.GetPosition();
2585 VECTOR2D rotEnd = viewBBox.GetEnd();
2586
2587 RotatePoint( &rotPos.x, &rotPos.y, refPt.x, refPt.y, rotateAngle );
2588 RotatePoint( &rotEnd.x, &rotEnd.y, refPt.x, refPt.y, rotateAngle );
2589
2590 typedef std::numeric_limits<int> coord_limits;
2591
2592 int max = coord_limits::max() - COORDS_PADDING;
2593 int min = -max;
2594
2595 bool outOfBounds = rotPos.x < min || rotPos.x > max || rotPos.y < min || rotPos.y > max || rotEnd.x < min
2596 || rotEnd.x > max || rotEnd.y < min || rotEnd.y > max;
2597
2598 if( !outOfBounds )
2599 {
2600 for( EDA_ITEM* item : selection )
2601 {
2602 commit->Modify( item, nullptr, RECURSE_MODE::RECURSE );
2603
2604 if( item->IsBOARD_ITEM() )
2605 {
2606 BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
2607
2608 board_item->Rotate( refPt, rotateAngle );
2609 board_item->Normalize();
2610
2611 if( board_item->Type() == PCB_FOOTPRINT_T )
2612 static_cast<FOOTPRINT*>( board_item )->InvalidateComponentClassCache();
2613 }
2614 }
2615
2616 // Don't push a separate undo entry when we're in the middle of a move operation.
2617 // The parent move will handle the commit.
2618 if( !localCommit.Empty() && !m_dragging )
2619 {
2620 localCommit.Push( _( "Rotate" ) );
2622 }
2623
2624 if( is_hover && !m_dragging )
2625 m_toolMgr->RunAction( ACTIONS::selectionClear );
2626
2628
2629 if( m_dragging )
2630 {
2633 }
2634 }
2635
2636 // Restore the old reference so any mouse dragging that occurs doesn't make the selection jump
2637 // to this now invalid reference
2638 if( oldRefPt )
2639 selection.SetReferencePoint( *oldRefPt );
2640 else
2641 selection.ClearReferencePoint();
2642
2643 return 0;
2644}
2645
2646
2650static void mirrorPad( PAD& aPad, const VECTOR2I& aMirrorPoint, FLIP_DIRECTION aFlipDirection )
2651{
2653 [&]( PCB_LAYER_ID layer )
2654 {
2655 if( aPad.GetShape( layer ) == PAD_SHAPE::CUSTOM )
2656 aPad.FlipPrimitives( aFlipDirection );
2657 } );
2658
2659 VECTOR2I tmpPt = aPad.GetPosition();
2660 MIRROR( tmpPt, aMirrorPoint, aFlipDirection );
2661 aPad.SetPosition( tmpPt );
2662
2664 [&]( PCB_LAYER_ID layer )
2665 {
2666 tmpPt = aPad.GetOffset( layer );
2667 MIRROR( tmpPt, VECTOR2I{ 0, 0 }, aFlipDirection );
2668 aPad.SetOffset( layer, tmpPt );
2669
2670 VECTOR2I tmpz = aPad.GetDelta( layer );
2671 MIRROR( tmpz, VECTOR2I{ 0, 0 }, aFlipDirection );
2672 aPad.SetDelta( layer, tmpz );
2673 } );
2674
2675 aPad.SetOrientation( -aPad.GetOrientation() );
2676}
2677
2678
2679const std::vector<KICAD_T> EDIT_TOOL::MirrorableItems = {
2682 PCB_TEXT_T,
2684 PCB_ZONE_T,
2685 PCB_PAD_T,
2687 PCB_ARC_T,
2688 PCB_VIA_T,
2695};
2696
2697
2698int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
2699{
2700 if( isRouterActive() )
2701 {
2702 wxBell();
2703 return 0;
2704 }
2705
2706 BOARD_COMMIT localCommit( this );
2707 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2708
2709 if( !commit )
2710 commit = &localCommit;
2711
2712 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2713 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2714 {
2715 sTool->FilterCollectorForMarkers( aCollector );
2716 sTool->FilterCollectorForHierarchy( aCollector, true );
2717 sTool->FilterCollectorForFreePads( aCollector );
2718 sTool->FilterCollectorForLockedItems( aCollector );
2719 } );
2720
2721 m_selectionTool->ReportFilteredLockedItems();
2722
2723 if( selection.Empty() )
2724 return 0;
2725
2727 VECTOR2I mirrorPoint = selection.GetReferencePoint();
2728
2731
2732 int skippedFootprints = 0;
2733 int skippedGroups = 0;
2734
2735 for( EDA_ITEM* item : selection )
2736 {
2737 if( !item->IsType( MirrorableItems ) )
2738 {
2739 if( item->Type() == PCB_FOOTPRINT_T )
2740 skippedFootprints++;
2741
2742 continue;
2743 }
2744
2745 // Skip groups that hold non-mirrorable items, else the rest would tear away from them.
2746 if( item->Type() == PCB_GROUP_T && !groupMirrorable( static_cast<PCB_GROUP*>( item ) ) )
2747 {
2748 skippedGroups++;
2749 continue;
2750 }
2751
2752 commit->Modify( item, nullptr, RECURSE_MODE::RECURSE );
2753
2754 // modify each object as necessary
2755 switch( item->Type() )
2756 {
2757 case PCB_SHAPE_T:
2758 static_cast<PCB_SHAPE*>( item )->Mirror( mirrorPoint, flipDirection );
2759 break;
2760
2761 case PCB_ZONE_T:
2762 static_cast<ZONE*>( item )->Mirror( mirrorPoint, flipDirection );
2763 break;
2764
2765 case PCB_FIELD_T:
2766 case PCB_TEXT_T:
2767 static_cast<PCB_TEXT*>( item )->Mirror( mirrorPoint, flipDirection );
2768 break;
2769
2770 case PCB_TEXTBOX_T:
2771 static_cast<PCB_TEXTBOX*>( item )->Mirror( mirrorPoint, flipDirection );
2772 break;
2773
2774 case PCB_TABLE_T:
2775 case PCB_DRILL_CHART_T:
2776 static_cast<PCB_TABLE*>( item )->Mirror( mirrorPoint, flipDirection );
2777 break;
2778
2779 case PCB_PAD_T:
2780 mirrorPad( *static_cast<PAD*>( item ), mirrorPoint, flipDirection );
2781 break;
2782
2783 case PCB_TRACE_T:
2784 case PCB_ARC_T:
2785 case PCB_VIA_T:
2786 static_cast<PCB_TRACK*>( item )->Mirror( mirrorPoint, flipDirection );
2787 break;
2788
2789 case PCB_GROUP_T:
2790 static_cast<PCB_GROUP*>( item )->Mirror( mirrorPoint, flipDirection );
2791 break;
2792
2793 case PCB_GENERATOR_T:
2794 static_cast<PCB_GENERATOR*>( item )->Mirror( mirrorPoint, flipDirection );
2795 break;
2796
2797 case PCB_POINT_T:
2798
2799 static_cast<PCB_POINT*>( item )->Mirror( mirrorPoint, flipDirection ); break;
2800
2802 static_cast<PCB_REFERENCE_IMAGE*>( item )->Mirror( mirrorPoint, flipDirection );
2803 break;
2804
2805 default:
2806 // it's likely the commit object is wrong if you get here
2807 UNIMPLEMENTED_FOR( item->GetClass() );
2808 }
2809 }
2810
2811 // Don't push a separate undo entry when we're in the middle of a move operation.
2812 // The parent move will handle the commit.
2813 if( !localCommit.Empty() && !m_dragging )
2814 {
2815 localCommit.Push( _( "Mirror" ) );
2817 }
2818
2819 if( skippedFootprints > 0 && !m_dragging )
2820 {
2821 frame()->ShowInfoBarMsg( _( "Footprints cannot be mirrored. Use Flip to move them to "
2822 "the other side of the board." ) );
2823 }
2824 else if( skippedGroups > 0 && !m_dragging )
2825 {
2826 frame()->ShowInfoBarMsg( _( "Groups containing footprints or other items that cannot be "
2827 "mirrored were skipped." ) );
2828 }
2829
2830 if( selection.IsHover() && !m_dragging )
2831 m_toolMgr->RunAction( ACTIONS::selectionClear );
2832
2834
2835 if( m_dragging )
2836 {
2839 }
2840
2841 return 0;
2842}
2843
2844
2846{
2847 if( isRouterActive() )
2848 {
2849 wxBell();
2850 return 0;
2851 }
2852
2853 BOARD_COMMIT localCommit( this );
2854 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2855
2856 if( !commit )
2857 commit = &localCommit;
2858
2859 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2860 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2861 {
2862 sTool->FilterCollectorForHierarchy( aCollector, true );
2863 sTool->FilterCollectorForLockedItems( aCollector );
2864 } );
2865
2866 m_selectionTool->ReportFilteredLockedItems();
2867
2868 if( selection.Empty() )
2869 return 0;
2870
2871 auto setJustify =
2872 [&]( EDA_TEXT* aTextItem )
2873 {
2874 if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
2875 aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
2876 else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
2877 aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
2878 else
2879 aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
2880 };
2881
2882 for( EDA_ITEM* item : selection )
2883 {
2884 if( item->Type() == PCB_FIELD_T || item->Type() == PCB_TEXT_T )
2885 {
2886 commit->Modify( item );
2887 setJustify( static_cast<PCB_TEXT*>( item ) );
2888 }
2889 else if( item->Type() == PCB_TEXTBOX_T )
2890 {
2891 commit->Modify( item );
2892 setJustify( static_cast<PCB_TEXTBOX*>( item ) );
2893 }
2894 }
2895
2896 if( !localCommit.Empty() )
2897 {
2898 if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
2899 localCommit.Push( _( "Left Justify" ) );
2900 else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
2901 localCommit.Push( _( "Center Justify" ) );
2902 else
2903 localCommit.Push( _( "Right Justify" ) );
2904 }
2905
2906 if( selection.IsHover() && !m_dragging )
2907 m_toolMgr->RunAction( ACTIONS::selectionClear );
2908
2910
2911 if( m_dragging )
2912 {
2915 }
2916
2917 return 0;
2918}
2919
2920
2921int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
2922{
2923 if( isRouterActive() )
2924 {
2925 wxBell();
2926 return 0;
2927 }
2928
2929 BOARD_COMMIT localCommit( this );
2930 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2931
2932 if( !commit )
2933 commit = &localCommit;
2934
2935 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2936 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2937 {
2938 sTool->FilterCollectorForMarkers( aCollector );
2939 sTool->FilterCollectorForHierarchy( aCollector, true );
2940 sTool->FilterCollectorForFreePads( aCollector );
2941 sTool->FilterCollectorForTableCells( aCollector );
2942 sTool->FilterCollectorForLockedItems( aCollector );
2943 } );
2944
2945 m_selectionTool->ReportFilteredLockedItems();
2946
2947 if( selection.Empty() )
2948 return 0;
2949
2950 std::optional<VECTOR2I> oldRefPt;
2951
2952 if( selection.HasReferencePoint() )
2953 oldRefPt = selection.GetReferencePoint();
2954
2956
2957 // Flip around the anchor for footprints, and the bounding box center for board items
2958 VECTOR2I refPt = IsFootprintEditor() ? VECTOR2I( 0, 0 ) : selection.GetCenter();
2959
2960 if( m_dragging && m_inMoveWithReference && oldRefPt )
2961 {
2962 refPt = *oldRefPt;
2963 }
2964 else if( selection.GetSize() == 1 )
2965 {
2966 // If only one item selected, flip around the selection or item anchor point (instead
2967 // of the bounding box center) to avoid moving the item anchor
2968 // but only if the item is not a PCB_SHAPE with SHAPE_T::RECTANGLE shape, because
2969 // for this shape the flip transform swap start and end coordinates and move the shape.
2970 // So using the center of the shape is better (the shape does not move)
2971 // (Tables are a bunch of rectangles, so exclude them too)
2972 PCB_SHAPE* rect = dynamic_cast<PCB_SHAPE*>( selection.GetItem( 0 ) );
2973 PCB_TABLE* table = dynamic_cast<PCB_TABLE*>( selection.GetItem( 0 ) );
2974
2975 if( !table && ( !rect || rect->GetShape() != SHAPE_T::RECTANGLE ) )
2976 refPt = selection.GetReferencePoint();
2977 }
2978
2979 const FLIP_DIRECTION flipDirection = frame()->GetPcbNewSettings()->m_FlipDirection;
2980
2981 for( EDA_ITEM* item : selection )
2982 {
2983 if( !item->IsBOARD_ITEM() )
2984 continue;
2985
2986 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
2987
2988 commit->Modify( boardItem, nullptr, RECURSE_MODE::RECURSE );
2989
2990 boardItem->Flip( refPt, flipDirection );
2991 boardItem->Normalize();
2992
2993 if( boardItem->Type() == PCB_FOOTPRINT_T )
2994 static_cast<FOOTPRINT*>( boardItem )->InvalidateComponentClassCache();
2995 }
2996
2997 // Don't push a separate undo entry when we're in the middle of a move operation.
2998 // The parent move will handle the commit.
2999 if( !localCommit.Empty() && !m_dragging )
3000 {
3001 localCommit.Push( _( "Change Side / Flip" ) );
3003 }
3004
3005 if( selection.IsHover() && !m_dragging )
3006 m_toolMgr->RunAction( ACTIONS::selectionClear );
3007
3009
3010 if( m_dragging )
3011 {
3014 }
3015
3016 // Restore the old reference so any mouse dragging that occurs doesn't make the selection jump
3017 // to this now invalid reference
3018 if( oldRefPt )
3019 selection.SetReferencePoint( *oldRefPt );
3020 else
3021 selection.ClearReferencePoint();
3022
3023 return 0;
3024}
3025
3026
3027void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
3028{
3030 BOARD_COMMIT commit( this );
3031 int commitFlags = 0;
3032
3033 // As we are about to remove items, they have to be removed from the selection first
3034 m_toolMgr->RunAction( ACTIONS::selectionClear );
3035
3036 int itemsDeleted = 0;
3037 int fieldsHidden = 0;
3038 int fieldsAlreadyHidden = 0;
3039
3040 for( EDA_ITEM* item : aItems )
3041 {
3042 if( !item->IsBOARD_ITEM() )
3043 continue;
3044
3045 BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
3046 FOOTPRINT* parentFP = board_item->GetParentFootprint();
3047
3048 switch( item->Type() )
3049 {
3050 case PCB_FIELD_T:
3051 {
3052 PCB_FIELD* field = static_cast<PCB_FIELD*>( board_item );
3053
3054 wxASSERT( parentFP );
3055 commit.Modify( parentFP );
3056
3057 if( field->IsVisible() )
3058 {
3059 field->SetVisible( false );
3060 fieldsHidden++;
3061 }
3062 else
3063 {
3064 fieldsAlreadyHidden++;
3065 }
3066
3067 getView()->Update( parentFP );
3068 break;
3069 }
3070
3071 case PCB_TEXT_T:
3072 case PCB_SHAPE_T:
3073 case PCB_TEXTBOX_T:
3074 case PCB_BARCODE_T:
3075 case PCB_TABLE_T:
3076 case PCB_DRILL_CHART_T:
3078 case PCB_DIMENSION_T:
3079 case PCB_DIM_ALIGNED_T:
3080 case PCB_DIM_LEADER_T:
3081 case PCB_DIM_CENTER_T:
3082 case PCB_DIM_RADIAL_T:
3084 case PCB_POINT_T:
3085 commit.Remove( board_item );
3086 itemsDeleted++;
3087 break;
3088
3089 case PCB_TABLECELL_T:
3090 // A generated table's cells report the board, so there is no user text to clear
3091 if( IsGeneratedTableCell( board_item ) )
3092 break;
3093
3094 // Clear contents of table cell
3095 commit.Modify( board_item );
3096 static_cast<PCB_TABLECELL*>( board_item )->SetText( wxEmptyString );
3097 itemsDeleted++;
3098 break;
3099
3100 case PCB_GROUP_T:
3101 board_item->RunOnChildren(
3102 [&commit]( BOARD_ITEM* aItem )
3103 {
3104 commit.Remove( aItem );
3105 },
3107
3108 commit.Remove( board_item );
3109 itemsDeleted++;
3110 break;
3111
3112 case PCB_PAD_T:
3113 if( IsFootprintEditor() || frame()->GetPcbNewSettings()->m_AllowFreePads )
3114 {
3115 commit.Remove( board_item );
3116 itemsDeleted++;
3117 }
3118
3119 break;
3120
3121 case PCB_ZONE_T:
3122 // We process the zones special so that cutouts can be deleted when the delete
3123 // tool is called from inside a cutout when the zone is selected.
3124 // Only interact with cutouts when deleting and a single item is selected
3125 if( !aIsCut && aItems.GetSize() == 1 )
3126 {
3127 VECTOR2I curPos = getViewControls()->GetCursorPosition();
3128 ZONE* zone = static_cast<ZONE*>( board_item );
3129
3130 int outlineIdx, holeIdx;
3131
3132 if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) )
3133 {
3134 // Remove the cutout
3135 commit.Modify( zone );
3136 zone->RemoveCutout( outlineIdx, holeIdx );
3137 zone->UnFill();
3138
3139 // Update the display
3140 zone->HatchBorder();
3141 canvas()->Refresh();
3142
3143 // Restore the selection on the original zone
3144 m_toolMgr->RunAction<EDA_ITEM*>( ACTIONS::selectItem, zone );
3145
3146 break;
3147 }
3148 }
3149
3150 // Remove the entire zone otherwise
3151 commit.Remove( board_item );
3152 itemsDeleted++;
3153 break;
3154
3155 case PCB_VIA_T:
3156 {
3157 if( !aIsCut )
3158 {
3159 EDA_GROUP* parent = board_item->GetParentGroup();
3160 PCB_VIA_STITCH* stitch =
3161 parent ? dynamic_cast<PCB_VIA_STITCH*>( parent->AsEdaItem() ) : nullptr;
3162
3163 if( stitch && !aItems.Contains( stitch ) )
3164 {
3165 // We need to mark the via as excluded on deletion
3166 commit.Modify( stitch );
3167 stitch->ExcludePosition( board_item->GetPosition() );
3168 }
3169 }
3170
3171 commit.Remove( board_item );
3172 itemsDeleted++;
3173 break;
3174 }
3175
3176 case PCB_GENERATOR_T:
3177 {
3178 PCB_GENERATOR* generator = static_cast<PCB_GENERATOR*>( board_item );
3179
3180 if( ( SELECTION_CONDITIONS::OnlyTypes( { PCB_GENERATOR_T } ) )( aItems ) )
3181 {
3182 m_toolMgr->RunSynchronousAction<PCB_GENERATOR*>( PCB_ACTIONS::genRemove, &commit, generator );
3183 commit.Push( _( "Delete" ), commitFlags );
3184 commitFlags |= APPEND_UNDO;
3185 }
3186 else
3187 {
3188 for( EDA_ITEM* member : generator->GetItems() )
3189 commit.Remove( member );
3190
3191 commit.Remove( board_item );
3192 }
3193
3194 itemsDeleted++;
3195 break;
3196 }
3197
3198 default:
3199 commit.Remove( board_item );
3200 itemsDeleted++;
3201 break;
3202 }
3203 }
3204
3205 // If the entered group has been emptied then leave it.
3206 PCB_GROUP* enteredGroup = m_selectionTool->GetEnteredGroup();
3207
3208 if( enteredGroup && enteredGroup->GetItems().empty() )
3209 m_selectionTool->ExitGroup();
3210
3211 if( aIsCut )
3212 {
3213 commit.Push( _( "Cut" ), commitFlags );
3214 }
3215 else if( itemsDeleted == 0 )
3216 {
3217 if( fieldsHidden == 1 )
3218 commit.Push( _( "Hide Field" ), commitFlags );
3219 else if( fieldsHidden > 1 )
3220 commit.Push( _( "Hide Fields" ), commitFlags );
3221 else if( fieldsAlreadyHidden > 0 )
3222 editFrame->ShowInfoBarError( _( "Use the Footprint Properties dialog to remove fields." ) );
3223 }
3224 else
3225 {
3226 commit.Push( _( "Delete" ), commitFlags );
3227 }
3228}
3229
3230
3231int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
3232{
3234
3235 // A geometric constraint selected by clicking its on-canvas badge has no board selection, so a
3236 // plain Delete targets it here before the normal item-removal path. Cut is excluded: the
3237 // constraint is not on the clipboard, so it must not be silently removed (#2329).
3239
3240 if( !isCut )
3241 {
3242 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
3243 constraintTool && constraintTool->TryDeleteSelectedConstraint() )
3244 {
3245 return 0;
3246 }
3247 }
3248
3249 SCOPED_TOOL_PUSHER raii( editFrame, aEvent );
3250
3251 std::vector<BOARD_ITEM*> lockedItems;
3252 Activate();
3253
3254 // get a copy instead of reference (as we're going to clear the selection before removing items)
3255 PCB_SELECTION selectionCopy;
3257
3258 // If we are in a "Cut" operation, then the copied selection exists already and we want to
3259 // delete exactly that; no more, no fewer. Any filtering for locked items must be done in
3260 // the copyToClipboard() routine.
3261 if( isCut )
3262 {
3263 selectionCopy = m_selectionTool->GetSelection();
3264 }
3265 else
3266 {
3267 // Hover-pick is only a fallback for an empty selection.
3268 const bool hadInitialSelection = !m_selectionTool->GetSelection().Empty();
3269
3270 // When not in free-pad mode we normally auto-promote selected pads to their parent
3271 // footprints. But this is probably a little too dangerous for a destructive operation,
3272 // so we just do the promotion but not the deletion (allowing for a second delete to do
3273 // it if that's what the user wanted).
3274 selectionCopy = m_selectionTool->RequestSelection(
3275 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3276 {
3277 sTool->FilterCollectorForHierarchy( aCollector, true );
3278 sTool->FilterCollectorForLockedItems( aCollector );
3279 } );
3280
3281 m_selectionTool->ReportFilteredLockedItems();
3282
3283 if( hadInitialSelection && selectionCopy.Empty() )
3284 return 0;
3285
3286 size_t beforeFPCount = selectionCopy.CountType( PCB_FOOTPRINT_T );
3287
3288 selectionCopy = m_selectionTool->RequestSelection(
3289 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3290 {
3291 sTool->FilterCollectorForHierarchy( aCollector, true );
3292 sTool->FilterCollectorForFreePads( aCollector );
3293 sTool->FilterCollectorForLockedItems( aCollector );
3294 } );
3295
3296 if( !selectionCopy.IsHover() && m_selectionTool->GetSelection().CountType( PCB_FOOTPRINT_T ) > beforeFPCount )
3297 {
3298 wxBell();
3299 canvas()->Refresh();
3300 return 0;
3301 }
3302
3303 // In "alternative" mode, we expand selected track items to their full connection.
3304 if( isAlt && ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
3306
3307 selectionCopy = m_selectionTool->GetSelection();
3308
3309 if( selectionCopy.Empty() )
3310 return 0;
3311 }
3312
3313 DeleteItems( selectionCopy, isCut );
3314 canvas()->Refresh();
3315 return 0;
3316}
3317
3318
3320{
3321 if( isRouterActive() )
3322 {
3323 wxBell();
3324 return 0;
3325 }
3326
3327 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3328 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3329 {
3330 sTool->FilterCollectorForMarkers( aCollector );
3331 sTool->FilterCollectorForHierarchy( aCollector, true );
3332 sTool->FilterCollectorForFreePads( aCollector, false );
3333 sTool->FilterCollectorForTableCells( aCollector );
3334 sTool->FilterCollectorForLockedItems( aCollector );
3335 } );
3336
3337 m_selectionTool->ReportFilteredLockedItems();
3338
3339 if( selection.Empty() )
3340 return 0;
3341
3342 VECTOR2I translation;
3343 EDA_ANGLE rotation;
3345
3346 // TODO: Implement a visible bounding border at the edge
3347 BOX2I sel_box = selection.GetBoundingBox();
3348
3349 DIALOG_MOVE_EXACT dialog( frame(), translation, rotation, rotationAnchor, sel_box );
3350 int ret = dialog.ShowModal();
3351
3352 if( ret == wxID_OK )
3353 {
3354 BOARD_COMMIT commit( this );
3355 EDA_ANGLE angle = rotation;
3356 VECTOR2I rp = selection.GetCenter();
3357 VECTOR2I selCenter( rp.x, rp.y );
3358
3359 // Make sure the rotation is from the right reference point
3360 selCenter += translation;
3361
3362 if( !frame()->GetPcbNewSettings()->m_Display.m_DisplayInvertYAxis )
3363 rotation = -rotation;
3364
3365 for( EDA_ITEM* item : selection )
3366 {
3367 if( !item->IsBOARD_ITEM() )
3368 continue;
3369
3370 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
3371
3372 commit.Modify( boardItem, nullptr, RECURSE_MODE::RECURSE );
3373
3374 if( !boardItem->GetParent() || !boardItem->GetParent()->IsSelected() )
3375 boardItem->Move( translation );
3376
3377 switch( rotationAnchor )
3378 {
3380 boardItem->Rotate( boardItem->GetPosition(), angle );
3381 break;
3383 boardItem->Rotate( selCenter, angle );
3384 break;
3386 boardItem->Rotate( frame()->GetScreen()->m_LocalOrigin, angle );
3387 break;
3389 boardItem->Rotate( board()->GetDesignSettings().GetAuxOrigin(), angle );
3390 break;
3391 }
3392
3393 if( !m_dragging )
3394 getView()->Update( boardItem );
3395 }
3396
3397 commit.Push( _( "Move Exactly" ) );
3399
3400 if( selection.IsHover() )
3401 m_toolMgr->RunAction( ACTIONS::selectionClear );
3402
3404
3405 if( m_dragging )
3406 {
3409 }
3410 }
3411
3412 return 0;
3413}
3414
3415
3417{
3418 // Some generators cannot be duplicated on their own, and neither can several of them
3419 return std::any_of( aSelection.begin(), aSelection.end(),
3420 []( EDA_ITEM* aItem )
3421 {
3422 PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( aItem );
3423 return !generator || generator->CanDuplicate();
3424 } );
3425}
3426
3427
3429{
3430 if( isRouterActive() )
3431 {
3432 wxBell();
3433 return 0;
3434 }
3435
3436 bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
3437
3438 // Be sure that there is at least one item that we can modify
3439 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3440 []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3441 {
3442 sTool->FilterCollectorForMarkers( aCollector );
3443 sTool->FilterCollectorForHierarchy( aCollector, true );
3444 sTool->FilterCollectorForFreePads( aCollector, true );
3445 sTool->FilterCollectorForTableCells( aCollector );
3446 } );
3447
3448 if( selection.Empty() )
3449 return 0;
3450
3452 return 0;
3453
3454 // we have a selection to work on now, so start the tool process
3456 BOARD_COMMIT commit( this );
3457 FOOTPRINT* parentFootprint = nullptr;
3458
3460 parentFootprint = editFrame->GetBoard()->GetFirstFootprint();
3461
3462 // If the selection was given a hover, we do not keep the selection after completion
3463 bool is_hover = selection.IsHover();
3464
3465 std::vector<BOARD_ITEM*> new_items;
3466 new_items.reserve( selection.Size() );
3467
3468 // Maps each duplicated original KIID to its duplicate so constraints between them
3469 // can be repointed at the copies once duplication finishes
3470 std::map<KIID, KIID> idMap;
3471
3472 // Each selected item is duplicated and pushed to new_items list
3473 // Old selection is cleared, and new items are then selected.
3474 for( EDA_ITEM* item : selection )
3475 {
3476 if( !item->IsBOARD_ITEM() )
3477 continue;
3478
3479 BOARD_ITEM* dupe_item = nullptr;
3480 BOARD_ITEM* orig_item = static_cast<BOARD_ITEM*>( item );
3481
3482 if( !m_isFootprintEditor && orig_item->GetParentFootprint() )
3483 {
3484 // No sub-footprint modifications allowed outside of footprint editor
3485 }
3486 else
3487 {
3488 switch( orig_item->Type() )
3489 {
3490 case PCB_FOOTPRINT_T:
3491 case PCB_TEXT_T:
3492 case PCB_TEXTBOX_T:
3493 case PCB_TABLE_T:
3494 case PCB_BARCODE_T:
3496 case PCB_SHAPE_T:
3497 case PCB_TRACE_T:
3498 case PCB_ARC_T:
3499 case PCB_VIA_T:
3500 case PCB_ZONE_T:
3501 case PCB_TARGET_T:
3502 case PCB_POINT_T:
3503 case PCB_DIM_ALIGNED_T:
3504 case PCB_DIM_CENTER_T:
3505 case PCB_DIM_RADIAL_T:
3507 case PCB_DIM_LEADER_T:
3508 case PCB_GRID_ITEM_T:
3510 dupe_item = parentFootprint->DuplicateItem( true, &commit, orig_item );
3511 else
3512 dupe_item = orig_item->Duplicate( true, &commit );
3513
3514 // Clear the selection flag here, otherwise the PCB_SELECTION_TOOL
3515 // will not properly select it later on
3516 dupe_item->ClearSelected();
3517
3518 if( dupe_item->Type() == PCB_SHAPE_T && static_cast<PCB_SHAPE*>( dupe_item )->IsHatchedFill() )
3519 dupe_item->SetFlags( IS_NEW );
3520
3521 idMap[orig_item->m_Uuid] = dupe_item->m_Uuid;
3522 new_items.push_back( dupe_item );
3523 commit.Add( dupe_item );
3524 break;
3525
3526 case PCB_FIELD_T:
3527 // PCB_FIELD items are specific items (not only graphic, but are properies)
3528 // and cannot be duplicated like other footprint items. So skip it:
3529 orig_item->ClearSelected();
3530 break;
3531
3532 case PCB_PAD_T:
3533 dupe_item = parentFootprint->DuplicateItem( true, &commit, orig_item );
3534
3535 if( increment && static_cast<PAD*>( dupe_item )->CanHaveNumber() )
3536 {
3537 PAD_TOOL* padTool = m_toolMgr->GetTool<PAD_TOOL>();
3538 wxString padNumber = padTool->GetLastPadNumber();
3539 padNumber = parentFootprint->GetNextPadNumber( padNumber );
3540 padTool->SetLastPadNumber( padNumber );
3541 static_cast<PAD*>( dupe_item )->SetNumber( padNumber );
3542 }
3543
3544 // Clear the selection flag here, otherwise the PCB_SELECTION_TOOL
3545 // will not properly select it later on
3546 dupe_item->ClearSelected();
3547
3548 idMap[orig_item->m_Uuid] = dupe_item->m_Uuid;
3549 new_items.push_back( dupe_item );
3550 commit.Add( dupe_item );
3551 break;
3552
3553 case PCB_DRILL_CHART_T:
3554 // A second chart of the same holes says nothing the first does not, and it
3555 // would land on top of it
3556 break;
3557
3558 case PCB_GENERATOR_T:
3559 case PCB_GROUP_T:
3560 {
3561 // DeepDuplicate maps original to duplicate KIID per descendant while cloning the group
3562 // so grouped constraints can be repointed unordered iteration blocks a later pairing
3563 dupe_item = static_cast<PCB_GROUP*>( orig_item )->DeepDuplicate( true, &commit, &idMap );
3564
3565 dupe_item->RunOnChildren(
3566 [&]( BOARD_ITEM* aItem )
3567 {
3568 aItem->ClearSelected();
3569 new_items.push_back( aItem );
3570 commit.Add( aItem );
3571 },
3573
3574 dupe_item->ClearSelected();
3575 new_items.push_back( dupe_item );
3576 commit.Add( dupe_item );
3577 break;
3578 }
3579
3580 default:
3581 UNIMPLEMENTED_FOR( orig_item->GetClass() );
3582 break;
3583 }
3584 }
3585 }
3586
3587 // Carry constraints whose members were all duplicated repointed at the copies
3588 // constraints are not selectable so add them to commit but keep them out of new selection
3589 const CONSTRAINTS& sourceConstraints = parentFootprint ? parentFootprint->Constraints()
3590 : board()->Constraints();
3591
3592 for( PCB_CONSTRAINT* clone : CloneFullySelectedConstraints( sourceConstraints, idMap ) )
3593 commit.Add( clone );
3594
3595 // Clear the old selection first
3596 m_toolMgr->RunAction( ACTIONS::selectionClear );
3597
3598 // Select the new items
3599 EDA_ITEMS nItems( new_items.begin(), new_items.end() );
3600 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &nItems );
3601
3602 // record the new items as added
3603 if( !selection.Empty() )
3604 {
3605 editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ), (int) new_items.size() ) );
3606
3607 // If items were duplicated, pick them up
3608 if( doMoveSelection( aEvent, &commit, true ) )
3609 commit.Push( _( "Duplicate" ) );
3610 else
3611 commit.Revert();
3612
3613 // Deselect the duplicated item if we originally started as a hover selection
3614 if( is_hover )
3615 m_toolMgr->RunAction( ACTIONS::selectionClear );
3616 }
3617
3618 return 0;
3619}
3620
3621
3623{
3624 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3625 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3626 {
3627 for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
3628 {
3629 switch( aCollector[i]->Type() )
3630 {
3631 case PCB_PAD_T:
3632 case PCB_TEXT_T: break;
3633 default: aCollector.Remove( i ); break;
3634 }
3635 }
3636
3637 sTool->FilterCollectorForLockedItems( aCollector );
3638 } );
3639
3640 m_selectionTool->ReportFilteredLockedItems();
3641
3642 if( selection.Empty() )
3643 return 0;
3644
3645 ACTIONS::INCREMENT param = { 1, 0 };
3646
3647 if( aEvent.HasParameter() )
3648 param = aEvent.Parameter<ACTIONS::INCREMENT>();
3649
3651 incrementer.SetSkipIOSQXZ( true );
3652
3653 // If we're coming via another action like 'Move', use that commit
3654 BOARD_COMMIT localCommit( m_toolMgr );
3655 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
3656
3657 if( !commit )
3658 commit = &localCommit;
3659
3660 for( EDA_ITEM* item : selection )
3661 {
3662 switch( item->Type() )
3663 {
3664 case PCB_PAD_T:
3665 {
3666 // Only increment pad numbers in the footprint editor
3667 if( !m_isFootprintEditor )
3668 break;
3669
3670 PAD& pad = static_cast<PAD&>( *item );
3671
3672 if( !pad.CanHaveNumber() )
3673 continue;
3674
3675 // Increment on the pad numbers
3676 std::optional<wxString> newNumber = incrementer.Increment( pad.GetNumber(), param.Delta, param.Index );
3677
3678 if( newNumber )
3679 {
3680 commit->Modify( &pad );
3681 pad.SetNumber( *newNumber );
3682 }
3683
3684 break;
3685 }
3686 case PCB_TEXT_T:
3687 {
3688 PCB_TEXT& text = static_cast<PCB_TEXT&>( *item );
3689
3690 std::optional<wxString> newText = incrementer.Increment( text.GetText(), param.Delta, param.Index );
3691
3692 if( newText )
3693 {
3694 commit->Modify( &text );
3695 text.SetText( *newText );
3696 }
3697
3698 break;
3699 }
3700 default: break;
3701 }
3702 }
3703
3704 if( selection.Front()->IsMoving() )
3705 m_toolMgr->PostAction( ACTIONS::refreshPreview );
3706
3707 commit->Push( _( "Increment" ) );
3708
3709 return 0;
3710}
3711
3712
3714{
3715 for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
3716 {
3717 if( aCollector[i]->Type() != PCB_PAD_T )
3718 aCollector.Remove( i );
3719 }
3720}
3721
3722
3724{
3725 for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
3726 {
3727 if( aCollector[i]->Type() != PCB_FOOTPRINT_T )
3728 aCollector.Remove( i );
3729 }
3730}
3731
3732
3734{
3735 // Can't modify an empty group
3736 if( aSelection.Empty() )
3737 return false;
3738
3739 if( ( m_dragging || aSelection[0]->IsMoving() ) && aSelection.HasReferencePoint() )
3740 return false;
3741
3742 // When there is only one item selected, the reference point is its position...
3743 if( aSelection.Size() == 1 && BaseType( aSelection.Front()->Type() ) != PCB_TABLE_T )
3744 {
3745 if( aSelection.Front()->IsBOARD_ITEM() )
3746 {
3747 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aSelection.Front() );
3748 aSelection.SetReferencePoint( item->GetPosition() );
3749 }
3750 }
3751 // ...otherwise modify items with regard to the grid-snapped center position
3752 else
3753 {
3754 PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
3755 VECTOR2I refPt = aSelection.GetCenter();
3756
3757 // Exclude text in the footprint editor if there's anything else selected
3759 {
3760 BOX2I nonFieldsBBox;
3761
3762 for( EDA_ITEM* item : aSelection.Items() )
3763 {
3764 if( !item->IsType( { PCB_TEXT_T, PCB_FIELD_T } ) )
3765 nonFieldsBBox.Merge( item->GetBoundingBox() );
3766 }
3767
3768 if( nonFieldsBBox.IsValid() )
3769 refPt = nonFieldsBBox.GetCenter();
3770 }
3771
3772 aSelection.SetReferencePoint( grid.ResolveSnap( refPt, nullptr ).position );
3773 }
3774
3775 return true;
3776}
3777
3778
3779bool EDIT_TOOL::pickReferencePoint( const wxString& aTooltip, const wxString& aSuccessMessage,
3780 const wxString& aCanceledMessage, VECTOR2I& aReferencePoint )
3781{
3782 PCB_PICKER_TOOL* picker = m_toolMgr->GetTool<PCB_PICKER_TOOL>();
3784 std::optional<VECTOR2I> pickedPoint;
3785 bool done = false;
3786
3787 m_statusPopup->SetText( aTooltip );
3788
3790 picker->SetSnapping( true );
3791 picker->SetCursor( KICURSOR::PLACE );
3792 picker->ClearHandlers();
3793
3794 const auto setPickerLayerSet =
3795 [&]()
3796 {
3797 MAGNETIC_SETTINGS* magSettings = editFrame->GetMagneticItemsSettings();
3798 LSET layerFilter;
3799
3800 if( !magSettings->allLayers )
3801 layerFilter = LSET( { editFrame->GetActiveLayer() } );
3802 else
3803 layerFilter = LSET::AllLayersMask();
3804
3805 picker->SetLayerSet( layerFilter );
3806 };
3807
3808 // Initial set
3809 setPickerLayerSet();
3810
3811 picker->SetClickHandler(
3812 [&]( const VECTOR2D& aPoint ) -> bool
3813 {
3814 pickedPoint = aPoint;
3815
3816 if( !aSuccessMessage.empty() )
3817 {
3818 m_statusPopup->SetText( aSuccessMessage );
3819 m_statusPopup->Expire( 800 );
3820 }
3821 else
3822 {
3823 m_statusPopup->Hide();
3824 }
3825
3826 return false; // we don't need any more points
3827 } );
3828
3829 picker->SetMotionHandler(
3830 [&]( const VECTOR2D& aPos )
3831 {
3832 m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
3833 } );
3834
3835 picker->SetCancelHandler(
3836 [&]()
3837 {
3838 if( !aCanceledMessage.empty() )
3839 {
3840 m_statusPopup->SetText( aCanceledMessage );
3841 m_statusPopup->Expire( 800 );
3842 }
3843 else
3844 {
3845 m_statusPopup->Hide();
3846 }
3847 } );
3848
3849 picker->SetFinalizeHandler(
3850 [&]( const int& aFinalState )
3851 {
3852 done = true;
3853 } );
3854
3855 m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, -50 ) );
3856 m_statusPopup->Popup();
3857 canvas()->SetStatusPopup( m_statusPopup->GetPanel() );
3858
3859 m_toolMgr->RunAction( ACTIONS::pickerSubTool );
3860
3861 while( !done )
3862 {
3863 // Pass events unless we receive a null event, then we must shut down
3864 if( TOOL_EVENT* evt = Wait() )
3865 {
3866 if( evt->Matches( PCB_EVENTS::SnappingModeChangedByKeyEvent() ) )
3867 {
3868 // Update the layer set when the snapping mode changes
3869 setPickerLayerSet();
3870 }
3871
3872 evt->SetPassEvent();
3873 }
3874 else
3875 {
3876 break;
3877 }
3878 }
3879
3880 picker->ClearHandlers();
3881
3882 // Ensure statusPopup is hidden after use and before deleting it:
3883 canvas()->SetStatusPopup( nullptr );
3884 m_statusPopup->Hide();
3885
3886 if( pickedPoint )
3887 aReferencePoint = *pickedPoint;
3888
3889 return pickedPoint.has_value();
3890}
3891
3892
3894{
3895 CLIPBOARD_IO io;
3896 PCB_GRID_HELPER grid( m_toolMgr, getEditFrame<PCB_BASE_EDIT_FRAME>()->GetMagneticItemsSettings() );
3897 TOOL_EVENT selectReferencePoint( aEvent.Category(), aEvent.Action(), "pcbnew.InteractiveEdit.selectReferencePoint",
3899
3900 SCOPED_TOOL_PUSHER raii( frame(), selectReferencePoint );
3901 Activate();
3902
3903 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3904 [&]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3905 {
3906 sTool->FilterCollectorForHierarchy( aCollector, true );
3907 sTool->FilterCollectorForMarkers( aCollector );
3908
3909 if( aEvent.IsAction( &ACTIONS::cut ) )
3910 sTool->FilterCollectorForLockedItems( aCollector );
3911 } );
3912
3913 m_selectionTool->ReportFilteredLockedItems();
3914
3915 if( !selection.Empty() )
3916 {
3917 std::vector<BOARD_ITEM*> items;
3918
3919 for( EDA_ITEM* item : selection )
3920 {
3921 if( item->IsBOARD_ITEM() )
3922 items.push_back( static_cast<BOARD_ITEM*>( item ) );
3923 }
3924
3925 VECTOR2I refPoint;
3926
3928 {
3929 if( !pickReferencePoint( _( "Select reference point for the copy..." ), _( "Selection copied" ),
3930 _( "Copy canceled" ), refPoint ) )
3931 {
3932 return 0;
3933 }
3934 }
3935 else
3936 {
3937 refPoint = grid.BestDragOrigin( getViewControls()->GetCursorPosition(), items );
3938 }
3939
3940 selection.SetReferencePoint( refPoint );
3941
3942 io.SetBoard( board() );
3944 frame()->SetStatusText( _( "Selection copied" ) );
3945 }
3946
3947 // Cut needs this selection to delete exactly the items copied to the clipboard.
3948 if( selection.IsHover() && !aEvent.IsAction( &ACTIONS::cut ) )
3949 m_selectionTool->ClearSelection();
3950
3951 return 0;
3952}
3953
3954
3956{
3957 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3958 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3959 {
3960 // Anything unsupported will just be ignored
3961 } );
3962
3963 if( selection.IsHover() )
3964 m_selectionTool->ClearSelection();
3965
3966 const auto getItemText =
3967 [&]( const BOARD_ITEM& aItem ) -> wxString
3968 {
3969 switch( aItem.Type() )
3970 {
3971 case PCB_TEXT_T:
3972 case PCB_FIELD_T:
3973 case PCB_DIM_ALIGNED_T:
3974 case PCB_DIM_LEADER_T:
3975 case PCB_DIM_CENTER_T:
3976 case PCB_DIM_RADIAL_T:
3978 {
3979 // These can all go via the PCB_TEXT class
3980 const PCB_TEXT& text = static_cast<const PCB_TEXT&>( aItem );
3981 return text.GetShownText( FOR_CANVAS );
3982 }
3983 case PCB_TEXTBOX_T:
3984 case PCB_TABLECELL_T:
3985 {
3986 // This one goes via EDA_TEXT
3987 const PCB_TEXTBOX& textBox = static_cast<const PCB_TEXTBOX&>( aItem );
3988 return textBox.GetShownText( FOR_CANVAS );
3989 }
3990 case PCB_TABLE_T:
3991 case PCB_DRILL_CHART_T:
3992 {
3993 const PCB_TABLE& table = static_cast<const PCB_TABLE&>( aItem );
3994 wxString s;
3995
3996 for( int row = 0; row < table.GetRowCount(); ++row )
3997 {
3998 for( int col = 0; col < table.GetColCount(); ++col )
3999 {
4000 const PCB_TABLECELL* cell = table.GetCell( row, col );
4001 s << cell->GetShownText( FOR_CANVAS );
4002
4003 if( col < table.GetColCount() - 1 )
4004 s << '\t';
4005 }
4006
4007 if( row < table.GetRowCount() - 1 )
4008 s << '\n';
4009 }
4010 return s;
4011 }
4012 default:
4013 // No string representation for this item type
4014 break;
4015 }
4016
4017 return wxEmptyString;
4018 };
4019
4020 wxArrayString itemTexts;
4021
4022 for( EDA_ITEM* item : selection )
4023 {
4024 if( item->IsBOARD_ITEM() )
4025 {
4026 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
4027 wxString itemText = getItemText( *boardItem );
4028
4029 itemText.Trim( false ).Trim( true );
4030
4031 if( !itemText.IsEmpty() )
4032 itemTexts.Add( std::move( itemText ) );
4033 }
4034 }
4035
4036 // Send the text to the clipboard
4037 if( !itemTexts.empty() )
4038 SaveClipboard( wxJoin( itemTexts, '\n', '\0' ).ToStdString() );
4039
4040 return 0;
4041}
4042
4043
4045{
4046 if( !copyToClipboard( aEvent ) )
4047 {
4048 // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items
4049 // that were copied to the clipboard, no more, no fewer. Filtering for locked item, if
4050 // any will be done in the copyToClipboard() routine
4051 TOOL_EVENT evt = aEvent;
4053 Remove( evt );
4054 }
4055
4056 return 0;
4057}
4058
4059
4061{
4062 board()->BuildConnectivity();
4064 canvas()->RedrawRatsnest();
4065}
4066
4067
4068// clang-format off
4070{
4072 Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() );
4078 Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
4079 Go( &EDIT_TOOL::Remove, ACTIONS::doDelete.MakeEvent() );
4086 Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirrorH.MakeEvent() );
4087 Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirrorV.MakeEvent() );
4088 Go( &EDIT_TOOL::Swap, PCB_ACTIONS::swap.MakeEvent() );
4106
4112
4116
4120
4124 Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
4125}
4126// clang-format on
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
BOX2< VECTOR2I > BOX2I
Definition box2.h:914
static TOOL_ACTION decrementPrimary
Definition actions.h:92
static TOOL_ACTION paste
Definition actions.h:76
static TOOL_ACTION pickerSubTool
Definition actions.h:250
static TOOL_ACTION unselectAll
Definition actions.h:79
static TOOL_ACTION decrementSecondary
Definition actions.h:94
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition actions.h:223
static TOOL_ACTION copy
Definition actions.h:74
static TOOL_ACTION pasteSpecial
Definition actions.h:77
static TOOL_ACTION rightJustify
Definition actions.h:85
static TOOL_ACTION pageSettings
Definition actions.h:59
static TOOL_ACTION incrementSecondary
Definition actions.h:93
static TOOL_ACTION duplicate
Definition actions.h:80
static TOOL_ACTION incrementPrimary
Definition actions.h:91
static TOOL_ACTION doDelete
Definition actions.h:81
REMOVE_FLAGS
Remove event modifier flags.
Definition actions.h:320
static TOOL_ACTION increment
Definition actions.h:90
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
static TOOL_ACTION leftJustify
Definition actions.h:83
static TOOL_ACTION cut
Definition actions.h:73
static TOOL_ACTION copyAsText
Definition actions.h:75
static TOOL_ACTION refreshPreview
Definition actions.h:155
static TOOL_ACTION selectAll
Definition actions.h:78
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:228
static TOOL_ACTION centerJustify
Definition actions.h:84
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
ACTION_MENU(bool isContextMenu, TOOL_INTERACTIVE *aTool=nullptr)
Default constructor.
TOOL_MANAGER * getToolManager() const
Return an instance of TOOL_MANAGER class.
void Clear()
Remove all the entries from the menu (as well as its title).
void SetTitle(const wxString &aTitle) override
Set title for the menu.
void SetIcon(BITMAPS aIcon)
Assign an icon for the entry.
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
void Revert() override
Revert the commit by restoring the modified items state.
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
virtual void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
NETINFO_ITEM * GetNet() const
Return NETINFO_ITEM object for a given item.
Abstract interface for BOARD_ITEMs capable of storing other items inside.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:84
virtual BOARD_ITEM * Duplicate(bool addToParentGroup, BOARD_COMMIT *aCommit=nullptr) const
Create a copy of this BOARD_ITEM.
void SetLocked(bool aLocked) override
Definition board_item.h:418
bool IsLocked() const override
virtual void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle)
Rotate this object.
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:436
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:346
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition board_item.h:264
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:266
virtual void Normalize()
Perform any normalization required after a user rotate and/or flip.
Definition board_item.h:489
virtual void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection)
Flip this object, i.e.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:410
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1199
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:712
const FOOTPRINTS & Footprints() const
Definition board.h:464
constexpr const Vec & GetPosition() const
Definition box2.h:208
constexpr const Vec GetEnd() const
Definition box2.h:209
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:594
constexpr const Vec GetCenter() const
Definition box2.h:227
constexpr bool IsValid() const
Definition box2.h:857
void SaveSelection(const PCB_SELECTION &selected, bool isFootprintEditor)
void SetBoard(BOARD *aBoard)
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition collector.h:107
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
bool Empty() const
Definition commit.h:145
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
Interactive authoring of geometric constraints (issue #2329).
bool TryDeleteSelectedConstraint()
Delete the currently badge-selected constraint; returns true if one was selected and removed.
bool TryEditSelectedConstraint()
Edit the currently badge-selected constraint's value; returns true if one was selected.
void SolveAfterMove(const std::vector< PCB_SHAPE * > &aShapes)
Re-solve the clusters of aShapes after a whole-shape edit, folded into that edit's undo.
DIALOG_GET_FOOTPRINT_BY_NAME is a helper dialog to select a footprint by its reference One can enter ...
int ShowModal() override
bool HitTestDrawingSheetItems(KIGFX::VIEW *aView, const VECTOR2I &aPosition)
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, INFOBAR_MESSAGE_TYPE aType=INFOBAR_MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
virtual int GetUndoCommandCount() const
void DisplayToolMsg(const wxString &msg) override
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
std::unordered_set< EDA_ITEM * > & GetItems()
Definition eda_group.h:78
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:599
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearSelected()
Definition eda_item.h:153
bool IsSelected() const
Definition eda_item.h:134
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:214
SHAPE_POLY_SET & GetPolyShape()
SHAPE_T GetShape() const
Definition eda_shape.h:175
bool IsHatchedFill() const
Definition eda_shape.h:130
const VECTOR2I & GetEnd() const
Return the ending point of the graphic.
Definition eda_shape.h:325
const VECTOR2I & GetStart() const
Return the starting point of the graphic.
Definition eda_shape.h:275
A mix-in class (via multiple inheritance) that handles texts such as labels, parts,...
Definition eda_text.h:94
virtual bool IsVisible() const
Definition eda_text.h:226
virtual void SetVisible(bool aVisible)
Definition eda_text.cpp:347
static void collectConstraintShapes(const SELECTION &aSelection, std::vector< PCB_SHAPE * > &aShapes)
Collect constrainable PCB_SHAPEs in aSelection recursing groups and footprints so contained shapes se...
bool isRouterActive() const
int Duplicate(const TOOL_EVENT &aItem)
Duplicate the current selection and starts a move action.
int Drag(const TOOL_EVENT &aEvent)
Invoke the PNS router to drag tracks or do an offline resizing of an arc track if a single arc track ...
int Flip(const TOOL_EVENT &aEvent)
Rotate currently selected items.
int SwapGateNets(const TOOL_EVENT &aEvent)
int Swap(const TOOL_EVENT &aEvent)
Swap currently selected items' positions.
bool m_inMoveWithReference
Definition edit_tool.h:252
int PackAndMoveFootprints(const TOOL_EVENT &aEvent)
Try to fit selected footprints inside a minimal area and start movement.
int Mirror(const TOOL_EVENT &aEvent)
Mirror the current selection.
int Increment(const TOOL_EVENT &aEvent)
Increment some aspect of the selected items.q.
bool doMoveSelection(const TOOL_EVENT &aEvent, BOARD_COMMIT *aCommit, bool aAutoStart, std::vector< PCB_SHAPE * > *aConstraintShapes=nullptr)
Runs interactive move drag when aConstraintShapes is non null previews constraint solve live each tic...
bool pickReferencePoint(const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
bool Init() override
Init() is called once upon a registration of the tool.
int EditVertices(const TOOL_EVENT &aEvent)
int ToggleFootprintAttribute(const TOOL_EVENT &aEvent)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int ModifyLines(const TOOL_EVENT &aEvent)
"Modify" graphical lines.
bool m_dragging
Definition edit_tool.h:251
int MoveExact(const TOOL_EVENT &aEvent)
Invoke a dialog box to allow moving of the item by an exact amount.
int Move(const TOOL_EVENT &aEvent)
Main loop in which events are handled.
static const unsigned int COORDS_PADDING
Definition edit_tool.h:257
int JustifyText(const TOOL_EVENT &aEvent)
Set the justification on any text items (or fields) in the current selection.
bool updateModificationPoint(PCB_SELECTION &aSelection)
Return the right modification point (e.g.
static bool CanDuplicateSelection(const SELECTION &aSelection)
int ChangeTrackLayer(const TOOL_EVENT &aEvent)
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition edit_tool.h:255
int copyToClipboard(const TOOL_EVENT &aEvent)
Send the current selection to the clipboard by formatting it as a fake pcb.
int SwapPadNets(const TOOL_EVENT &aEvent)
Swap nets between selected pads and propagate to connected copper items (tracks, arcs,...
int Remove(const TOOL_EVENT &aEvent)
Delete currently selected items.
int cutToClipboard(const TOOL_EVENT &aEvent)
Cut the current selection to the clipboard by formatting it as a fake pcb.
static const std::vector< KICAD_T > MirrorableItems
Definition edit_tool.h:2679
void DeleteItems(const PCB_SELECTION &aItem, bool aIsCut)
static void PadFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
A selection filter which prunes the selection to contain only items of type PCB_PAD_T.
bool invokeInlineRouter(int aDragMode)
void rebuildConnectivity()
Rebuilds the ratsnest for operations that require it outside the commit rebuild.
void setTransitions() override
Set up handlers for various events.
int HealShapes(const TOOL_EVENT &aEvent)
Make ends of selected shapes meet by extending or cutting them, or adding extra geometry.
void reSolveConstraintsAfterEdit(const PCB_SELECTION &aSelection)
Re-solve the geometric constraints of any shapes in aSelection after a transform.
int ChangeTrackWidth(const TOOL_EVENT &aEvent)
int BooleanPolygons(const TOOL_EVENT &aEvent)
Modify selected polygons into a single polygon using boolean operations such as merge (union) or subt...
int copyToClipboardAsText(const TOOL_EVENT &aEvent)
Send the current selection to the clipboard as text.
int GetAndPlace(const TOOL_EVENT &aEvent)
Find an item and start moving.
int FilletTracks(const TOOL_EVENT &aEvent)
Fillet (i.e.
PCB_SELECTION_TOOL * m_selectionTool
Definition edit_tool.h:250
int SimplifyPolygons(const TOOL_EVENT &aEvent)
Simplify the outlines of selected polygon objects.
int Properties(const TOOL_EVENT &aEvent)
Display properties window for the selected object.
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
A selection filter which prunes the selection to contain only items of type PCB_FOOTPRINT_T.
int Rotate(const TOOL_EVENT &aEvent)
Rotate currently selected items.
static const TOOL_EVENT SelectedEvent
Definition actions.h:345
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
Definition actions.h:352
static const TOOL_EVENT ConnectivityChangedEvent
Definition actions.h:349
static const TOOL_EVENT UnselectedEvent
Definition actions.h:346
Variant information for a footprint.
Definition footprint.h:228
void SetExcludedFromPosFiles(bool aExclude)
Definition footprint.h:252
void SetExcludedFromSim(bool aExclude)
Definition footprint.h:249
void SetExcludedFromBOM(bool aExclude)
Definition footprint.h:246
bool GetExcludedFromSimForVariant(const wxString &aVariantName) const
Get the exclude-from-simulation status for a specific variant.
void SetExcludedFromSim(bool aExclude=true)
Definition footprint.h:1055
void SetExcludedFromBOM(bool aExclude=true)
Definition footprint.h:1046
const std::vector< FP_UNIT_INFO > & GetUnitInfo() const
Definition footprint.h:1025
void SetExcludedFromPosFiles(bool aExclude=true)
Definition footprint.h:1037
const FOOTPRINT_VARIANT * GetVariant(const wxString &aVariantName) const
Get a variant by name.
CONSTRAINTS & Constraints()
Definition footprint.h:417
BOARD_ITEM * DuplicateItem(bool addToParentGroup, BOARD_COMMIT *aCommit, const BOARD_ITEM *aItem, bool addToFootprint=false)
Duplicate a given item within the footprint, optionally adding it to the board.
bool GetExcludedFromPosFilesForVariant(const wxString &aVariantName) const
Get the exclude-from-position-files status for a specific variant.
FOOTPRINT_VARIANT * AddVariant(const wxString &aVariantName)
Add a new variant with the given name.
bool GetExcludedFromBOMForVariant(const wxString &aVariantName) const
Get the exclude-from-BOM status for a specific variant.
wxString GetNextPadNumber(const wxString &aLastPadName) const
Return the next available pad number in the footprint.
ACTION_MENU * create() const override
Return an instance of this class. It has to be overridden in inheriting classes.
static bool EqualPinCounts(const FOOTPRINT *aFootprint, const std::vector< int > &aUnitIndices)
void update() override
Update menu state stub.
static std::vector< int > GetCompatibleTargets(const FOOTPRINT *aFootprint, int aSourceIdx)
OPT_TOOL_EVENT eventHandler(const wxMenuEvent &aEvent) override
Event handler stub.
static std::unordered_set< wxString > CollectSelectedPadNumbers(const SELECTION &aSelection, const FOOTPRINT *aFootprint)
static const FOOTPRINT * GetSingleEligibleFootprint(const SELECTION &aSelection)
static std::vector< int > GetUnitsHitIndices(const FOOTPRINT *aFootprint, const std::unordered_set< wxString > &aSelPadNums)
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
static const std::vector< KICAD_T > DraggableItems
A scan list for items that can be dragged.
Definition collectors.h:148
A handler that is based on a set of callbacks provided by the user of the ITEM_MODIFICATION_ROUTINE.
bool IsBOARD_ITEM() const
Definition view_item.h:98
virtual wxString GetClass() const =0
Return the class name.
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllLayersMask()
Definition lset.cpp:637
A collection of nets and the parameters used to route or test these nets.
Definition netclass.h:43
int GetuViaDrill() const
Definition netclass.h:174
int GetuViaDiameter() const
Definition netclass.h:166
void ForEachUniqueLayer(const std::function< void(PCB_LAYER_ID)> &aMethod) const
Runs the given callable for each active unique copper layer in this padstack, meaning F_Cu for MODE::...
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:170
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:179
void SetLastPadNumber(const wxString &aPadNumber)
Definition pad_tool.h:62
wxString GetLastPadNumber() const
Definition pad_tool.h:61
Definition pad.h:61
const VECTOR2I & GetDelta(PCB_LAYER_ID aLayer) const
Definition pad.h:307
VECTOR2I GetPosition() const override
Definition pad.cpp:256
void SetDelta(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.h:301
VECTOR2I GetOffset(PCB_LAYER_ID aLayer) const
Definition pad.cpp:838
void FlipPrimitives(FLIP_DIRECTION aFlipDirection)
Flip (mirror) the primitives left to right or top to bottom, around the anchor position in custom pad...
Definition pad.cpp:1850
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
void SetOffset(PCB_LAYER_ID aLayer, const VECTOR2I &aOffset)
Definition pad.cpp:827
void SetPosition(const VECTOR2I &aPos) override
Definition pad.cpp:245
const PADSTACK & Padstack() const
Definition pad.h:331
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1757
void SetOrientation(const EDA_ANGLE &aAngle)
Set the rotation angle of the pad.
Definition pad.cpp:1732
static TOOL_ACTION drag45Degree
static TOOL_ACTION duplicateIncrement
Activation of the duplication tool with incrementing (e.g. pad number)
static TOOL_ACTION layerPrev
static TOOL_ACTION changeTrackWidth
Update selected tracks & vias to the current track & via dimensions.
static TOOL_ACTION unrouteSelected
Removes all tracks from the selected items to the first pad.
Definition pcb_actions.h:76
static TOOL_ACTION mirrorH
Mirroring of selected items.
static TOOL_ACTION updateFootprint
static TOOL_ACTION breakTrack
Break a single track into two segments at the cursor.
static TOOL_ACTION pointEditorMoveMidpoint
static TOOL_ACTION getAndPlace
Find an item and start moving.
static TOOL_ACTION routerRouteSelectedFromEnd
static TOOL_ACTION toggleExcludeFromSim
static TOOL_ACTION swapPadNets
Swap nets between selected pads/gates (and connected copper)
static TOOL_ACTION properties
Activation of the edit tool.
static TOOL_ACTION editFpInFpEditor
static TOOL_ACTION moveWithReference
move with a reference point
static TOOL_ACTION changeTrackLayerPrev
static TOOL_ACTION swap
Swapping of selected items.
static TOOL_ACTION routerOptimizeSelected
static TOOL_ACTION routerAutorouteSelected
static TOOL_ACTION moveExact
Activation of the exact move tool.
static TOOL_ACTION intersectPolygons
Intersection of multiple polygons.
static TOOL_ACTION pointEditorMoveCorner
static TOOL_ACTION genRemove
static TOOL_ACTION selectConnection
Select tracks between junctions or expands an existing selection to pads or the entire connection.
Definition pcb_actions.h:73
static TOOL_ACTION assignNetClass
static TOOL_ACTION packAndMoveFootprints
Pack and start moving selected footprints.
static TOOL_ACTION copyWithReference
copy command with manual reference point selection
static TOOL_ACTION healShapes
Connect selected shapes, possibly extending or cutting them, or adding extra geometry.
static TOOL_ACTION toggleExcludeFromBOM
static TOOL_ACTION extendGraphic
Extend one graphical line or arc to the nearest boundary.
static TOOL_ACTION dragFreeAngle
static TOOL_ACTION inspectClearance
static TOOL_ACTION updateLocalRatsnest
static TOOL_ACTION updateFootprints
static TOOL_ACTION deleteFull
static TOOL_ACTION unrouteSegment
Removes track segment from the selected item to the next segment.
Definition pcb_actions.h:79
static TOOL_ACTION moveIndividually
move items one-by-one
static TOOL_ACTION changeFootprints
static TOOL_ACTION toggleExcludeFromPosFiles
static TOOL_ACTION chamferLines
Chamfer (i.e. adds a straight line) all selected straight lines by a user defined setback.
static TOOL_ACTION dogboneCorners
Add "dogbone" corners to selected lines to allow routing with a cutter radius.
static TOOL_ACTION filletTracks
Fillet (i.e. adds an arc tangent to) all selected straight tracks by a user defined radius.
static TOOL_ACTION simplifyPolygons
Simplify polygon outlines.
static TOOL_ACTION interactiveOffsetTool
static TOOL_ACTION footprintProperties
static TOOL_ACTION pointEditorChamferCorner
static TOOL_ACTION filletLines
Fillet (i.e. adds an arc tangent to) all selected straight lines by a user defined radius.
static TOOL_ACTION changeFootprint
static TOOL_ACTION routerInlineDrag
Activation of the Push and Shove router (inline dragging mode)
static TOOL_ACTION pointEditorRemoveCorner
static TOOL_ACTION positionRelative
static TOOL_ACTION skip
static TOOL_ACTION move
move or drag an item
static TOOL_ACTION mirrorV
static TOOL_ACTION mergePolygons
Merge multiple polygons into a single polygon.
static TOOL_ACTION subtractPolygons
Subtract polygons from other polygons.
static TOOL_ACTION changeTrackLayerNext
static TOOL_ACTION flip
Flipping of selected objects.
static TOOL_ACTION pointEditorAddCorner
static TOOL_ACTION editVertices
Edit polygon vertices in a table.
static TOOL_ACTION swapGateNets
static TOOL_ACTION layerNext
static TOOL_ACTION extendLines
Extend selected lines to meet at a point.
static TOOL_ACTION routerRouteSelected
static TOOL_ACTION rotateCw
Rotation of selected objects.
static TOOL_ACTION rotateCcw
static TOOL_ACTION trimGraphic
Trim a section from one graphical line or arc.
Common, abstract interface for edit frames.
virtual void OnEditItemRequest(BOARD_ITEM *aItem)
Install the corresponding dialog editor for the given item.
void OpenVertexEditor(BOARD_ITEM *aItem)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
A geometric constraint between board items (issue #2329).
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
static const TOOL_EVENT & SnappingModeChangedByKeyEvent()
Hotkey feedback.
virtual bool ChildrenAreReadOnly() const
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const override
Invoke a function on all children.
Generic tool for picking an item.
void SetLayerSet(const LSET &aLayerSet)
Set the tool's snap layer set.
void ClearHandlers()
Handlers only.
Tool that displays edit points allowing to modify items by dragging the points.
bool CanRemoveCorner(const SELECTION &aSelection)
Condition to display "Remove Corner" context menu entry.
static bool CanChamferCorner(const EDA_ITEM &aItem)
Check if a corner of the given item can be chamfered (zones, polys only).
static bool CanAddCorner(const EDA_ITEM &aItem)
Check if a corner can be added to the given item (zones, polys, segments, arcs).
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Definition pcb_point.h:39
Object to handle a bitmap image that can be inserted in a PCB.
The selection tool: currently supports:
void GuessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Try to guess best selection candidates in case multiple items are clicked, by doing some brain-dead h...
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Drop any PCB_MARKERs from the collector.
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector, bool aForcePromotion=false) const
Check the "allow free pads" setting and if disabled, replace any pads in the collector with their par...
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
PCB_SELECTION & GetSelection()
void FilterCollectorForLockedItems(GENERAL_COLLECTOR &aCollector)
In the PCB editor strip out any locked items unless the OverrideLocks checkbox is set.
void FilterCollectorForTableCells(GENERAL_COLLECTOR &aCollector) const
Promote any table cell selections to the whole table.
VECTOR2I GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition pcb_shape.h:78
void SetWidth(int aWidth) override
int GetWidth() const override
void SetEnd(const VECTOR2I &aEnd) override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void SetStart(const VECTOR2I &aStart) override
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition pcb_shape.h:68
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
wxString GetShownText(RESOLUTION_CONTEXT aContext, int aDepth=0) const override
Return the string actually shown after processing of the base text.
T * frame() const
bool IsFootprintEditor() const
bool IsBoardEditor() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
void SetHasSolderMask(bool aVal)
Definition pcb_track.h:121
virtual double GetLength() const
Get the length of the track using the hypotenuse calculation.
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:94
bool HasSolderMask() const
Definition pcb_track.h:122
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:97
void SetLocalSolderMaskMargin(std::optional< int > aMargin)
Definition pcb_track.h:124
std::optional< int > GetLocalSolderMaskMargin() const
Definition pcb_track.h:125
const VECTOR2I & GetStart() const
Definition pcb_track.h:98
const VECTOR2I & GetEnd() const
Definition pcb_track.h:95
EDA_ITEM_FLAGS IsPointOnEnds(const VECTOR2I &point, int min_dist=0) const
Return STARTPOINT if point if near (dist = min_dist) start point, ENDPOINT if point if near (dist = m...
virtual void SetWidth(int aWidth)
Definition pcb_track.h:91
virtual int GetWidth() const
Definition pcb_track.h:92
void ExcludePosition(const VECTOR2I &aPos)
Add a board position to the exclusion set so the next Update() skips it.
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition picker_tool.h:92
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition picker_tool.h:81
void SetSnapping(bool aSnap)
Definition picker_tool.h:65
void SetCursor(KICURSOR aCursor)
Definition picker_tool.h:63
void SetCancelHandler(CANCEL_HANDLER aHandler)
Set a handler for cancel events (ESC or context-menu Cancel).
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
bool RoutingInProgress()
Returns whether routing is currently active.
bool CanInlineDrag(int aDragMode)
Definition seg.h:38
bool ApproxCollinear(const SEG &aSeg, int aDistanceThreshold=1) const
Definition seg.cpp:759
static SELECTION_CONDITION HasTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if among the selected items there is at least one of a given types.
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 bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
static SELECTION_CONDITION MoreThan(int aNumber)
Create a functor that tests if the number of selected items is greater than the value given as parame...
static 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.
ITER end()
Definition selection.h:76
ITER begin()
Definition selection.h:75
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition selection.cpp:92
bool IsHover() const
Definition selection.h:85
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:104
EDA_ITEM * Front() const
Definition selection.h:176
bool HasType(KICAD_T aType) const
Checks if there is at least one item of requested kind.
int Size() const
Returns the number of selected parts.
Definition selection.h:120
std::deque< EDA_ITEM * > & Items()
Definition selection.h:181
void SetReferencePoint(const VECTOR2I &aP)
bool Empty() const
Checks if there is anything selected.
Definition selection.h:114
bool HasReferencePoint() const
Definition selection.h:215
size_t CountType(KICAD_T aType) const
bool Contains(EDA_ITEM *aItem) const
Definition selection.cpp:84
const VECTOR2I & GetP1() const
Definition shape_arc.h:115
const VECTOR2I & GetP0() const
Definition shape_arc.h:114
Represent a set of closed polygons.
SHAPE_LINE_CHAIN & Outline(int aIndex)
Return the reference to aIndex-th outline in the set.
void SimplifyOutlines(int aMaxError=0)
Simplifies the lines in the polyset.
const VECTOR2I & CVertex(int aIndex, int aOutline, int aHole) const
Return the index-th vertex in a given hole outline within a given outline.
static const int MIN_PRECISION_IU
This is the minimum precision for all the points in a shape.
Definition shape.h:129
Heuristically increment a string's n'th part from the right.
Definition increment.h:44
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition tool_base.h:142
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Return the instance of KIGFX::VIEW object used in the application.
Definition tool_base.cpp:34
bool IsToolActive() const
Definition tool_base.cpp:28
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
Generic, UI-independent tool event.
Definition tool_event.h:167
bool HasParameter() const
Definition tool_event.h:460
TOOL_ACTIONS Action() const
Returns more specific information about the type of an event.
Definition tool_event.h:246
bool Matches(const TOOL_EVENT &aEvent) const
Test whether two events match in terms of category & action or command.
Definition tool_event.h:388
COMMIT * Commit() const
Definition tool_event.h:279
void SetParameter(T aParam)
Set a non-standard parameter assigned to the event.
Definition tool_event.h:539
TOOL_EVENT_CATEGORY Category() const
Return the category (eg. mouse/keyboard/action) of an event.
Definition tool_event.h:243
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:484
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_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.
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:281
VECTOR2_TRAITS< int32_t >::extended_type extended_type
Definition vector2d.h:69
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:76
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
void AddLink(const wxString &aLinkText, const std::function< void(wxHyperlinkEvent &)> &aFn)
Add a hypertext link to the infobar.
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
A dialog like WX_UNIT_ENTRY_DIALOG, but with multiple entries.
std::vector< RESULT > GetValues() const
Returns the values in the order they were added.
An extension of WX_TEXT_ENTRY_DIALOG that uses UNIT_BINDER to request a dimension (e....
int GetValue()
Return the value in internal units.
Handle a list of polygons defining a copper zone.
Definition zone.h:70
bool UnFill()
Removes the zone filling.
Definition zone.cpp:528
bool HitTestCutout(const VECTOR2I &aRefPos, int *aOutlineIdx=nullptr, int *aHoleIdx=nullptr) const
Test if the given point is contained within a cutout of the zone.
Definition zone.cpp:1097
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
Definition zone.cpp:1582
void RemoveCutout(int aOutlineIdx, int aHoleIdx)
Remove a cutout from the zone.
Definition zone.cpp:1418
bool IsTeardropArea() const
Definition zone.h:807
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
Definition clipboard.cpp:32
@ FOR_CANVAS
Definition common.h:90
std::vector< PCB_CONSTRAINT * > CloneFullySelectedConstraints(const CONSTRAINTS &aSource, const std::map< KIID, KIID > &aIdMap)
Clone the constraints in aSource that a duplicate should carry.
@ PLACE
Definition cursors.h:94
ROTATION_ANCHOR
@ ROTATE_AROUND_USER_ORIGIN
@ ROTATE_AROUND_SEL_CENTER
@ ROTATE_AROUND_AUX_ORIGIN
@ ROTATE_AROUND_ITEM_ANCHOR
static std::string ToStdString(const wxString &aStr)
#define _(s)
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
#define IS_NEW
New item, just created.
#define STRUCT_DELETED
flag indication structures to be erased
@ SEGMENT
Definition eda_shape.h:56
@ RECTANGLE
Use RECTANGLE instead of RECT to avoid collision in a Windows header.
Definition eda_shape.h:57
static const std::vector< KICAD_T > baseConnectedTypes
static std::shared_ptr< ACTION_MENU > makeGateSwapMenu(TOOL_INTERACTIVE *aTool)
static const std::vector< KICAD_T > routableTypes
static std::shared_ptr< CONDITIONAL_MENU > makePositioningToolsMenu(TOOL_INTERACTIVE *aTool)
static FOOTPRINT * GetFootprintFromBoardByReference(PCB_BASE_FRAME &aFrame)
static std::shared_ptr< CONDITIONAL_MENU > makeShapeModificationMenu(TOOL_INTERACTIVE *aTool)
static std::optional< CHAMFER_PARAMS > GetChamferParams(PCB_BASE_EDIT_FRAME &aFrame)
Prompt the user for chamfer parameters.
static std::shared_ptr< CONDITIONAL_MENU > makeMirrorRotateMenu(EDIT_TOOL *aEditTool)
static bool itemHasEditableCorners(BOARD_ITEM *aItem)
Definition edit_tool.cpp:89
static bool groupMirrorable(const PCB_GROUP *aGroup)
static const std::vector< KICAD_T > footprintTypes
static std::shared_ptr< CONDITIONAL_MENU > makeRoutingToolsMenu(TOOL_INTERACTIVE *aTool)
static const std::vector< KICAD_T > groupTypes
static const std::vector< KICAD_T > padTypes
static const std::vector< KICAD_T > nonMirrorableTypes
static bool selectionMirrorable(const SELECTION &aSelection)
static std::optional< int > GetRadiusParams(PCB_BASE_EDIT_FRAME &aFrame, const wxString &aTitle, int &aPersitentRadius)
Prompt the user for a radius and return it.
static void mirrorPad(PAD &aPad, const VECTOR2I &aMirrorPoint, FLIP_DIRECTION aFlipDirection)
Mirror a pad in the H/V axis passing through a point.
static bool selectionHasEditableCorners(const SELECTION &aSelection)
static const std::vector< KICAD_T > trackTypes
static std::optional< DOGBONE_CORNER_ROUTINE::PARAMETERS > GetDogboneParams(PCB_BASE_EDIT_FRAME &aFrame)
void ConnectBoardShapes(std::vector< PCB_SHAPE * > &aShapeList, int aChainingEpsilon)
Connects shapes to each other, making continious contours (adjacent shapes will have a common vertex)...
@ LAYER_DRAWINGSHEET
Sheet frame and title block.
Definition layer_ids.h:274
@ LAYER_SCHEMATIC_DRAWINGSHEET
Definition layer_ids.h:518
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
This file contains miscellaneous commonly used macros and functions.
#define UNIMPLEMENTED_FOR(type)
Definition macros.h:92
constexpr void MIRROR(T &aPoint, const T &aMirrorRef)
Updates aPoint with the mirror of aPoint relative to the aMirrorRef.
Definition mirror.h:41
FLIP_DIRECTION
Definition mirror.h:23
@ LEFT_RIGHT
Flip left to right (around the Y axis)
Definition mirror.h:24
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:25
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
Definition wxgtk/ui.cpp:851
@ DM_ANY
Definition pns_router.h:83
@ DM_FREE_ANGLE
Definition pns_router.h:81
EDA_ANGLE GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvent)
Function getEventRotationAngle()
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
void for_all_pairs(_InputIterator __first, _InputIterator __last, _Function __f)
Apply a function to every possible pair of elements of a sequence.
Definition kicad_algo.h:80
#define _HKI(x)
Definition page_info.cpp:40
Class to handle a set of BOARD_ITEMs.
std::deque< FOOTPRINT * > FOOTPRINTS
std::deque< PCB_CONSTRAINT * > CONSTRAINTS
bool IsGeneratedTableCell(const EDA_ITEM *aItem)
True for a cell whose text is generated from the board, so only its formatting is the user's.
Definition pcb_table.h:348
@ ID_POPUP_PCB_SWAP_UNIT_LAST
Definition pcbnew_id.h:59
@ ID_POPUP_PCB_SWAP_UNIT_BASE
Definition pcbnew_id.h:58
#define APPEND_UNDO
Definition sch_commit.h:39
std::vector< EDA_ITEM * > EDA_ITEMS
static std::vector< KICAD_T > connectedTypes
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
Increment event parameters.
Definition actions.h:328
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
Parameters that define a simple chamfer operation.
#define EDIT_TOOL(tool)
STRING_INCREMENTER incrementer
KIBIS_MODEL * model
VECTOR2I end
@ GR_TEXT_H_ALIGN_CENTER
@ GR_TEXT_H_ALIGN_RIGHT
@ GR_TEXT_H_ALIGN_LEFT
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition tool_action.h:45
std::optional< TOOL_EVENT > OPT_TOOL_EVENT
Definition tool_event.h:652
void RotatePoint(int *pX, int *pY, const EDA_ANGLE &aAngle)
Calculate the new point of coord coord pX, pY, for a rotation center 0, 0.
Definition trigo.cpp:227
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition typeinfo.h:259
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ PCB_FIELD_T
class PCB_FIELD, text associated with a footprint property
Definition typeinfo.h:82
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TARGET_T
class PCB_TARGET, a target (graphic item)
Definition typeinfo.h:99
@ PCB_SHAPE_LOCATE_CIRCLE_T
Definition typeinfo.h:131
@ PCB_SHAPE_LOCATE_SEGMENT_T
Definition typeinfo.h:129
@ PCB_SHAPE_LOCATE_RECT_T
Definition typeinfo.h:130
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ PCB_SHAPE_LOCATE_BEZIER_T
Definition typeinfo.h:134
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_SHAPE_LOCATE_POLY_T
Definition typeinfo.h:133
@ PCB_SHAPE_LOCATE_ARC_T
Definition typeinfo.h:132
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition typeinfo.h:92
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:105
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
@ PCB_DRILL_CHART_T
class PCB_DRILL_CHART, a live drill chart derived from PCB_TABLE
Definition typeinfo.h:239
Casted dyn_cast(From aObject)
A lightweight dynamic downcast.
Definition typeinfo.h:55
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707