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 int new_width;
1298 int new_drill;
1299
1300 if( via->GetViaType() == VIATYPE::MICROVIA )
1301 {
1302 NETCLASS* netClass = via->GetEffectiveNetClass();
1303
1304 new_width = netClass->GetuViaDiameter();
1305 new_drill = netClass->GetuViaDrill();
1306 }
1307 else
1308 {
1309 new_width = board()->GetDesignSettings().GetCurrentViaSize();
1310 new_drill = board()->GetDesignSettings().GetCurrentViaDrill();
1311 }
1312
1313 via->SetDrill( new_drill );
1314 via->SetPadstackMode( PADSTACK::MODE::NORMAL );
1315 via->SetWidth( PADSTACK::ALL_LAYERS, new_width );
1316 }
1317 else if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
1318 {
1319 PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item );
1320
1321 wxCHECK( track, 0 );
1322
1323 commit.Modify( track );
1324
1325 int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
1326 track->SetWidth( new_width );
1327 }
1328 }
1329
1330 commit.Push( _( "Edit Track Width/Via Size" ) );
1331
1332 if( selection.IsHover() )
1333 {
1334 m_toolMgr->RunAction( ACTIONS::selectionClear );
1335
1336 // Notify other tools of the changes -- This updates the visual ratsnest
1338 }
1339
1340 return 0;
1341}
1342
1343
1345{
1346 if( m_toolMgr->GetTool<ROUTER_TOOL>() && m_toolMgr->GetTool<ROUTER_TOOL>()->IsToolActive() )
1347 return 0;
1348
1349 bool isNext = aEvent.IsAction( &PCB_ACTIONS::changeTrackLayerNext );
1350
1351 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1352 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1353 {
1354 // Iterate from the back so we don't have to worry about removals.
1355 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1356 {
1357 BOARD_ITEM* item = aCollector[i];
1358
1359 if( !dynamic_cast<PCB_TRACK*>( item ) )
1360 aCollector.Remove( item );
1361 }
1362
1363 sTool->FilterCollectorForLockedItems( aCollector );
1364 } );
1365
1366 m_selectionTool->ReportFilteredLockedItems();
1367
1368 PCB_LAYER_ID origLayer = frame()->GetActiveLayer();
1369
1370 if( isNext )
1371 m_toolMgr->RunAction( PCB_ACTIONS::layerNext );
1372 else
1373 m_toolMgr->RunAction( PCB_ACTIONS::layerPrev );
1374
1375 PCB_LAYER_ID newLayer = frame()->GetActiveLayer();
1376
1377 if( newLayer == origLayer )
1378 return 0;
1379
1380 BOARD_COMMIT commit( this );
1381
1382 for( EDA_ITEM* item : selection )
1383 {
1384 if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
1385 {
1386 PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item );
1387
1388 wxCHECK( track, 0 );
1389
1390 commit.Modify( track );
1391
1392 track->SetLayer( newLayer );
1393 }
1394 }
1395
1396 commit.Push( _( "Edit Track Layer" ) );
1397
1398 if( selection.IsHover() )
1399 {
1400 m_toolMgr->RunAction( ACTIONS::selectionClear );
1401
1402 // Notify other tools of the changes -- This updates the visual ratsnest
1404 }
1405
1406 return 0;
1407}
1408
1409
1411{
1412 // Store last used fillet radius to allow pressing "enter" if repeat fillet is required
1413 static int filletRadius = 0;
1414
1415 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1416 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1417 {
1418 // Iterate from the back so we don't have to worry about removals.
1419 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1420 {
1421 BOARD_ITEM* item = aCollector[i];
1422
1423 if( !dynamic_cast<PCB_TRACK*>( item ) )
1424 aCollector.Remove( item );
1425 }
1426
1427 sTool->FilterCollectorForLockedItems( aCollector );
1428 } );
1429
1430 if( m_selectionTool->ReportFilteredLockedItems() )
1431 return 0;
1432
1433 if( selection.Size() < 2 )
1434 {
1435 frame()->ShowInfoBarMsg( _( "At least two straight track segments must be selected." ) );
1436 return 0;
1437 }
1438
1439 WX_UNIT_ENTRY_DIALOG dlg( frame(), _( "Fillet Tracks" ), _( "Radius:" ), filletRadius );
1440
1441 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == 0 )
1442 return 0;
1443
1444 filletRadius = dlg.GetValue();
1445
1446 struct FILLET_OP
1447 {
1448 PCB_TRACK* t1;
1449 PCB_TRACK* t2;
1450 // Start point of track is modified after PCB_ARC is added, otherwise the end point:
1451 bool t1Start = true;
1452 bool t2Start = true;
1453 };
1454
1455 std::vector<FILLET_OP> filletOperations;
1456 bool operationPerformedOnAtLeastOne = false;
1457 bool didOneAttemptFail = false;
1458 std::set<PCB_TRACK*> processedTracks;
1459
1460 auto processFilletOp =
1461 [&]( PCB_TRACK* aTrack, bool aStartPoint )
1462 {
1463 std::shared_ptr<CONNECTIVITY_DATA> c = board()->GetConnectivity();
1464 VECTOR2I anchor = aStartPoint ? aTrack->GetStart() : aTrack->GetEnd();
1465 std::vector<BOARD_CONNECTED_ITEM*> itemsOnAnchor;
1466
1467 itemsOnAnchor = c->GetConnectedItemsAtAnchor( aTrack, anchor, baseConnectedTypes );
1468
1469 if( itemsOnAnchor.size() > 0 && selection.Contains( itemsOnAnchor.at( 0 ) )
1470 && itemsOnAnchor.at( 0 )->Type() == PCB_TRACE_T )
1471 {
1472 PCB_TRACK* trackOther = static_cast<PCB_TRACK*>( itemsOnAnchor.at( 0 ) );
1473
1474 // Make sure we don't fillet the same pair of tracks twice
1475 if( processedTracks.find( trackOther ) == processedTracks.end() )
1476 {
1477 if( itemsOnAnchor.size() == 1 )
1478 {
1479 FILLET_OP filletOp;
1480 filletOp.t1 = aTrack;
1481 filletOp.t2 = trackOther;
1482 filletOp.t1Start = aStartPoint;
1483 filletOp.t2Start = aTrack->IsPointOnEnds( filletOp.t2->GetStart() );
1484 filletOperations.push_back( filletOp );
1485 }
1486 else
1487 {
1488 // User requested to fillet these two tracks but not possible as
1489 // there are other elements connected at that point
1490 didOneAttemptFail = true;
1491 }
1492 }
1493 }
1494 };
1495
1496 for( EDA_ITEM* item : selection )
1497 {
1498 if( item->Type() == PCB_TRACE_T )
1499 {
1500 PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
1501
1502 if( track->GetLength() > 0 )
1503 {
1504 processFilletOp( track, true ); // on the start point of track
1505 processFilletOp( track, false ); // on the end point of track
1506
1507 processedTracks.insert( track );
1508 }
1509 }
1510 }
1511
1512 BOARD_COMMIT commit( this );
1513 std::vector<BOARD_ITEM*> itemsToAddToSelection;
1514
1515 for( FILLET_OP filletOp : filletOperations )
1516 {
1517 PCB_TRACK* track1 = filletOp.t1;
1518 PCB_TRACK* track2 = filletOp.t2;
1519
1520 bool trackOnStart = track1->IsPointOnEnds( track2->GetStart() );
1521 bool trackOnEnd = track1->IsPointOnEnds( track2->GetEnd() );
1522
1523 if( trackOnStart && trackOnEnd )
1524 continue; // Ignore duplicate tracks
1525
1526 if( ( trackOnStart || trackOnEnd ) && track1->GetLayer() == track2->GetLayer() )
1527 {
1528 SEG t1Seg( track1->GetStart(), track1->GetEnd() );
1529 SEG t2Seg( track2->GetStart(), track2->GetEnd() );
1530
1531 if( t1Seg.ApproxCollinear( t2Seg ) )
1532 continue;
1533
1534 SHAPE_ARC sArc( t1Seg, t2Seg, filletRadius );
1535 VECTOR2I t1newPoint, t2newPoint;
1536
1537 auto setIfPointOnSeg =
1538 []( VECTOR2I& aPointToSet, const SEG& aSegment, const VECTOR2I& aVecToTest )
1539 {
1540 VECTOR2I segToVec = aSegment.NearestPoint( aVecToTest ) - aVecToTest;
1541
1542 // Find out if we are on the segment (minimum precision)
1544 {
1545 aPointToSet.x = aVecToTest.x;
1546 aPointToSet.y = aVecToTest.y;
1547 return true;
1548 }
1549
1550 return false;
1551 };
1552
1553 //Do not draw a fillet if the end points of the arc are not within the track segments
1554 if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP0() )
1555 && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP0() ) )
1556 {
1557 didOneAttemptFail = true;
1558 continue;
1559 }
1560
1561 if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP1() )
1562 && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP1() ) )
1563 {
1564 didOneAttemptFail = true;
1565 continue;
1566 }
1567
1568 PCB_ARC* tArc = new PCB_ARC( frame()->GetBoard(), &sArc );
1569 tArc->SetLayer( track1->GetLayer() );
1570 tArc->SetWidth( track1->GetWidth() );
1571 tArc->SetNet( track1->GetNet() );
1572 tArc->SetLocked( track1->IsLocked() );
1573 tArc->SetHasSolderMask( track1->HasSolderMask() );
1575 commit.Add( tArc );
1576 itemsToAddToSelection.push_back( tArc );
1577
1578 commit.Modify( track1 );
1579 commit.Modify( track2 );
1580
1581 if( filletOp.t1Start )
1582 track1->SetStart( t1newPoint );
1583 else
1584 track1->SetEnd( t1newPoint );
1585
1586 if( filletOp.t2Start )
1587 track2->SetStart( t2newPoint );
1588 else
1589 track2->SetEnd( t2newPoint );
1590
1591 operationPerformedOnAtLeastOne = true;
1592 }
1593 }
1594
1595 commit.Push( _( "Fillet Tracks" ) );
1596
1597 //select the newly created arcs
1598 for( BOARD_ITEM* item : itemsToAddToSelection )
1599 m_selectionTool->AddItemToSel( item );
1600
1601 if( !operationPerformedOnAtLeastOne )
1602 frame()->ShowInfoBarMsg( _( "Unable to fillet the selected track segments." ) );
1603 else if( didOneAttemptFail )
1604 frame()->ShowInfoBarMsg( _( "Some of the track segments could not be filleted." ) );
1605
1606 return 0;
1607}
1608
1609
1619static std::optional<int> GetRadiusParams( PCB_BASE_EDIT_FRAME& aFrame, const wxString& aTitle, int& aPersitentRadius )
1620{
1621 WX_UNIT_ENTRY_DIALOG dlg( &aFrame, aTitle, _( "Radius:" ), aPersitentRadius );
1622
1623 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == 0 )
1624 return std::nullopt;
1625
1626 aPersitentRadius = dlg.GetValue();
1627
1628 return aPersitentRadius;
1629}
1630
1631
1632static std::optional<DOGBONE_CORNER_ROUTINE::PARAMETERS> GetDogboneParams( PCB_BASE_EDIT_FRAME& aFrame )
1633{
1634 // Persistent parameters
1635 static DOGBONE_CORNER_ROUTINE::PARAMETERS s_dogBoneParams{
1636 pcbIUScale.mmToIU( 1 ),
1637 true,
1638 };
1639
1640 std::vector<WX_MULTI_ENTRY_DIALOG::ENTRY> entries{
1641 {
1642 _( "Arc radius:" ),
1643 WX_MULTI_ENTRY_DIALOG::UNIT_BOUND{ s_dogBoneParams.DogboneRadiusIU },
1644 wxEmptyString,
1645 },
1646 {
1647 _( "Add slots in acute corners" ),
1648 WX_MULTI_ENTRY_DIALOG::CHECKBOX{ s_dogBoneParams.AddSlots },
1649 _( "Add slots in acute corners to allow access to a cutter of the given radius" ),
1650 },
1651 };
1652
1653 WX_MULTI_ENTRY_DIALOG dlg( &aFrame, _( "Dogbone Corner Settings" ), entries );
1654
1655 if( dlg.ShowModal() == wxID_CANCEL )
1656 return std::nullopt;
1657
1658 std::vector<WX_MULTI_ENTRY_DIALOG::RESULT> results = dlg.GetValues();
1659 wxCHECK( results.size() == 2, std::nullopt );
1660
1661 try
1662 {
1663 s_dogBoneParams.DogboneRadiusIU = std::get<long long int>( results[0] );
1664 s_dogBoneParams.AddSlots = std::get<bool>( results[1] );
1665 }
1666 catch( const std::bad_variant_access& )
1667 {
1668 wxASSERT( false );
1669 return std::nullopt;
1670 }
1671
1672 return s_dogBoneParams;
1673}
1674
1683static std::optional<CHAMFER_PARAMS> GetChamferParams( PCB_BASE_EDIT_FRAME& aFrame )
1684{
1685 // Non-zero and the KLC default for Fab layer chamfers
1686 const int default_setback = pcbIUScale.mmToIU( 1 );
1687 // Store last used setback to allow pressing "enter" if repeat chamfer is required
1688 static CHAMFER_PARAMS params{ default_setback, default_setback };
1689
1690 WX_UNIT_ENTRY_DIALOG dlg( &aFrame, _( "Chamfer Lines" ), _( "Chamfer setback:" ), params.m_chamfer_setback_a );
1691
1692 if( dlg.ShowModal() == wxID_CANCEL || dlg.GetValue() == 0 )
1693 return std::nullopt;
1694
1695 params.m_chamfer_setback_a = dlg.GetValue();
1696 // It's hard to easily specify an asymmetric chamfer (which line gets the longer setback?),
1697 // so we just use the same setback for each
1698 params.m_chamfer_setback_b = params.m_chamfer_setback_a;
1699
1700 return params;
1701}
1702
1703
1705{
1706 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1707 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1708 {
1709 std::vector<VECTOR2I> pts;
1710
1711 // Iterate from the back so we don't have to worry about removals.
1712 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1713 {
1714 BOARD_ITEM* item = aCollector[i];
1715
1716 // We've converted the polygon and rectangle to segments, so drop everything
1717 // that isn't a segment at this point
1718 if( !item->IsType(
1719 { PCB_SHAPE_LOCATE_SEGMENT_T, PCB_SHAPE_LOCATE_POLY_T, PCB_SHAPE_LOCATE_RECT_T } ) )
1720 {
1721 aCollector.Remove( item );
1722 }
1723 }
1724
1725 sTool->FilterCollectorForLockedItems( aCollector );
1726 } );
1727
1728 m_selectionTool->ReportFilteredLockedItems();
1729
1730 std::set<PCB_SHAPE*> lines_to_add;
1731 std::vector<PCB_SHAPE*> items_to_remove;
1732
1733 for( EDA_ITEM* item : selection )
1734 {
1735 std::vector<VECTOR2I> pts;
1736 PCB_SHAPE* graphic = static_cast<PCB_SHAPE*>( item );
1737 PCB_LAYER_ID layer = graphic->GetLayer();
1738 int width = graphic->GetWidth();
1739
1740 if( graphic->GetShape() == SHAPE_T::RECTANGLE )
1741 {
1742 items_to_remove.push_back( graphic );
1743 VECTOR2I start( graphic->GetStart() );
1744 VECTOR2I end( graphic->GetEnd() );
1745 pts.emplace_back( start );
1746 pts.emplace_back( VECTOR2I( end.x, start.y ) );
1747 pts.emplace_back( end );
1748 pts.emplace_back( VECTOR2I( start.x, end.y ) );
1749 }
1750
1751 if( graphic->GetShape() == SHAPE_T::POLY )
1752 {
1753 items_to_remove.push_back( graphic );
1754
1755 for( int jj = 0; jj < graphic->GetPolyShape().VertexCount(); ++jj )
1756 pts.emplace_back( graphic->GetPolyShape().CVertex( jj ) );
1757 }
1758
1759 for( size_t jj = 1; jj < pts.size(); ++jj )
1760 {
1761 PCB_SHAPE* line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT );
1762
1763 line->SetStart( pts[jj - 1] );
1764 line->SetEnd( pts[jj] );
1765 line->SetWidth( width );
1766 line->SetLayer( layer );
1767 lines_to_add.insert( line );
1768 }
1769
1770 if( pts.size() > 1 )
1771 {
1772 PCB_SHAPE* line = new PCB_SHAPE( frame()->GetModel(), SHAPE_T::SEGMENT );
1773
1774 line->SetStart( pts.back() );
1775 line->SetEnd( pts.front() );
1776 line->SetWidth( width );
1777 line->SetLayer( layer );
1778 lines_to_add.insert( line );
1779 }
1780 }
1781
1782 int segmentCount = selection.CountType( PCB_SHAPE_LOCATE_SEGMENT_T ) + lines_to_add.size();
1783
1784 if( aEvent.IsAction( &PCB_ACTIONS::extendLines ) && segmentCount != 2 )
1785 {
1786 frame()->ShowInfoBarMsg( _( "Exactly two lines must be selected to extend them." ) );
1787
1788 for( PCB_SHAPE* line : lines_to_add )
1789 delete line;
1790
1791 return 0;
1792 }
1793 else if( segmentCount < 2 )
1794 {
1795 frame()->ShowInfoBarMsg( _( "A shape with at least two lines must be selected." ) );
1796
1797 for( PCB_SHAPE* line : lines_to_add )
1798 delete line;
1799
1800 return 0;
1801 }
1802
1803 BOARD_COMMIT commit( this );
1804
1805 // Items created like lines from a rectangle
1806 for( PCB_SHAPE* item : lines_to_add )
1807 {
1808 commit.Add( item );
1809 selection.Add( item );
1810 }
1811
1812 // Remove items like rectangles that we decomposed into lines
1813 for( PCB_SHAPE* item : items_to_remove )
1814 {
1815 selection.Remove( item );
1816 commit.Remove( item );
1817 }
1818
1819 for( EDA_ITEM* item : selection )
1820 item->ClearFlags( STRUCT_DELETED );
1821
1822 // List of thing to select at the end of the operation
1823 // (doing it as we go will invalidate the iterator)
1824 std::vector<BOARD_ITEM*> items_to_select_on_success;
1825
1826 // And same for items to deselect
1827 std::vector<BOARD_ITEM*> items_to_deselect_on_success;
1828
1829 // Handle modifications to existing items by the routine
1830 // How to deal with this depends on whether we're in the footprint editor or not
1831 // and whether the item was conjured up by decomposing a polygon or rectangle
1832 auto item_modification_handler =
1833 [&]( BOARD_ITEM& aItem )
1834 {
1835 // If the item was "conjured up" it will be added later separately
1836 if( !alg::contains( lines_to_add, &aItem ) )
1837 {
1838 commit.Modify( &aItem );
1839 items_to_select_on_success.push_back( &aItem );
1840 }
1841 };
1842
1843 bool any_items_created = !lines_to_add.empty();
1844 auto item_creation_handler =
1845 [&]( std::unique_ptr<BOARD_ITEM> aItem )
1846 {
1847 any_items_created = true;
1848 items_to_select_on_success.push_back( aItem.get() );
1849 commit.Add( aItem.release() );
1850 };
1851
1852 bool any_items_removed = !items_to_remove.empty();
1853 auto item_removal_handler =
1854 [&]( BOARD_ITEM& aItem )
1855 {
1856 aItem.SetFlags( STRUCT_DELETED );
1857 any_items_removed = true;
1858 items_to_deselect_on_success.push_back( &aItem );
1859 commit.Remove( &aItem );
1860 };
1861
1862 // Combine these callbacks into a CHANGE_HANDLER to inject in the ROUTINE
1863 ITEM_MODIFICATION_ROUTINE::CALLABLE_BASED_HANDLER change_handler( item_creation_handler, item_modification_handler,
1864 item_removal_handler );
1865
1866 // Construct an appropriate tool
1867 std::unique_ptr<PAIRWISE_LINE_ROUTINE> pairwise_line_routine;
1868
1869 if( aEvent.IsAction( &PCB_ACTIONS::filletLines ) )
1870 {
1871 static int s_filletRadius = pcbIUScale.mmToIU( 1 );
1872 std::optional<int> filletRadiusIU = GetRadiusParams( *frame(), _( "Fillet Lines" ), s_filletRadius );
1873
1874 if( filletRadiusIU.has_value() )
1875 {
1876 pairwise_line_routine = std::make_unique<LINE_FILLET_ROUTINE>( frame()->GetModel(), change_handler,
1877 *filletRadiusIU );
1878 }
1879 }
1880 else if( aEvent.IsAction( &PCB_ACTIONS::dogboneCorners ) )
1881 {
1882 std::optional<DOGBONE_CORNER_ROUTINE::PARAMETERS> dogboneParams = GetDogboneParams( *frame() );
1883
1884 if( dogboneParams.has_value() )
1885 {
1886 pairwise_line_routine = std::make_unique<DOGBONE_CORNER_ROUTINE>( frame()->GetModel(), change_handler,
1887 *dogboneParams );
1888 }
1889 }
1890 else if( aEvent.IsAction( &PCB_ACTIONS::chamferLines ) )
1891 {
1892 std::optional<CHAMFER_PARAMS> chamfer_params = GetChamferParams( *frame() );
1893
1894 if( chamfer_params.has_value() )
1895 {
1896 pairwise_line_routine = std::make_unique<LINE_CHAMFER_ROUTINE>( frame()->GetModel(), change_handler,
1897 *chamfer_params );
1898 }
1899 }
1900 else if( aEvent.IsAction( &PCB_ACTIONS::extendLines ) )
1901 {
1902 pairwise_line_routine = std::make_unique<LINE_EXTENSION_ROUTINE>( frame()->GetModel(), change_handler );
1903 }
1904
1905 if( !pairwise_line_routine )
1906 {
1907 // Didn't construct any mofication routine - user must have cancelled
1908 commit.Revert();
1909 return 0;
1910 }
1911
1912 // Apply the tool to every line pair
1913 alg::for_all_pairs( selection.begin(), selection.end(),
1914 [&]( EDA_ITEM* a, EDA_ITEM* b )
1915 {
1916 if( ( a->GetFlags() & STRUCT_DELETED ) == 0 && ( b->GetFlags() & STRUCT_DELETED ) == 0 )
1917 {
1918 PCB_SHAPE* line_a = static_cast<PCB_SHAPE*>( a );
1919 PCB_SHAPE* line_b = static_cast<PCB_SHAPE*>( b );
1920
1921 pairwise_line_routine->ProcessLinePair( *line_a, *line_b );
1922 }
1923 } );
1924
1925 // Select added and modified items
1926 for( BOARD_ITEM* item : items_to_select_on_success )
1927 m_selectionTool->AddItemToSel( item, true );
1928
1929 // Deselect removed items
1930 for( BOARD_ITEM* item : items_to_deselect_on_success )
1931 m_selectionTool->RemoveItemFromSel( item, true );
1932
1933 if( any_items_removed )
1934 m_toolMgr->ProcessEvent( EVENTS::UnselectedEvent );
1935
1936 if( any_items_created )
1937 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
1938
1939 // Notify other tools of the changes
1940 m_toolMgr->ProcessEvent( EVENTS::SelectedItemsModified );
1941
1942 commit.Push( pairwise_line_routine->GetCommitDescription() );
1943
1944 if( const std::optional<wxString> msg = pairwise_line_routine->GetStatusMessage( segmentCount ) )
1945 frame()->ShowInfoBarMsg( *msg );
1946
1947 return 0;
1948}
1949
1950
1952{
1953 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
1954 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1955 {
1956 std::vector<VECTOR2I> pts;
1957
1958 // Iterate from the back so we don't have to worry about removals.
1959 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1960 {
1961 BOARD_ITEM* item = aCollector[i];
1962
1963 if( !item->IsType( { PCB_SHAPE_LOCATE_POLY_T, PCB_ZONE_T } ) )
1964 aCollector.Remove( item );
1965
1966 if( ZONE* zone = dyn_cast<ZONE*>( item ) )
1967 {
1968 if( zone->IsTeardropArea() )
1969 aCollector.Remove( item );
1970 }
1971 }
1972
1973 sTool->FilterCollectorForLockedItems( aCollector );
1974 } );
1975
1976 m_selectionTool->ReportFilteredLockedItems();
1977
1978 // Store last used value
1979 static int s_toleranceValue = pcbIUScale.mmToIU( 3 );
1980
1981 WX_UNIT_ENTRY_DIALOG dlg( frame(), _( "Simplify Shapes" ), _( "Tolerance value:" ), s_toleranceValue );
1982
1983 if( dlg.ShowModal() == wxID_CANCEL )
1984 return 0;
1985
1986 s_toleranceValue = dlg.GetValue();
1987
1988 if( s_toleranceValue <= 0 )
1989 return 0;
1990
1991 BOARD_COMMIT commit{ this };
1992
1993 std::vector<PCB_SHAPE*> shapeList;
1994
1995 for( EDA_ITEM* item : selection )
1996 {
1997 commit.Modify( item );
1998
1999 if( PCB_SHAPE* shape = dyn_cast<PCB_SHAPE*>( item ) )
2000 {
2001 SHAPE_POLY_SET& poly = shape->GetPolyShape();
2002
2003 poly.SimplifyOutlines( s_toleranceValue );
2004 }
2005
2006 if( ZONE* zone = dyn_cast<ZONE*>( item ) )
2007 {
2008 SHAPE_POLY_SET* poly = zone->Outline();
2009
2010 poly->SimplifyOutlines( s_toleranceValue );
2011 zone->HatchBorder();
2012 }
2013 }
2014
2015 commit.Push( _( "Simplify Polygons" ) );
2016
2017 // Notify other tools of the changes
2019
2020 return 0;
2021}
2022
2023
2025{
2026 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2027 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2028 {
2029 std::vector<VECTOR2I> pts;
2030
2031 // Iterate from the back so we don't have to worry about removals.
2032 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
2033 {
2034 BOARD_ITEM* item = aCollector[i];
2035
2036 // We've converted the polygon and rectangle to segments, so drop everything
2037 // that isn't a segment at this point
2038 if( !item->IsType( { PCB_SHAPE_LOCATE_SEGMENT_T,
2039 PCB_SHAPE_LOCATE_ARC_T,
2040 PCB_SHAPE_LOCATE_BEZIER_T } ) )
2041 {
2042 aCollector.Remove( item );
2043 }
2044 }
2045
2046 sTool->FilterCollectorForLockedItems( aCollector );
2047 } );
2048
2049 m_selectionTool->ReportFilteredLockedItems();
2050
2051 // Store last used value
2052 static int s_toleranceValue = pcbIUScale.mmToIU( 3 );
2053
2054 WX_UNIT_ENTRY_DIALOG dlg( frame(), _( "Heal Shapes" ), _( "Tolerance value:" ), s_toleranceValue );
2055
2056 if( dlg.ShowModal() == wxID_CANCEL )
2057 return 0;
2058
2059 s_toleranceValue = dlg.GetValue();
2060
2061 if( s_toleranceValue <= 0 )
2062 return 0;
2063
2064 BOARD_COMMIT commit{ this };
2065
2066 std::vector<PCB_SHAPE*> shapeList;
2067
2068 for( EDA_ITEM* item : selection )
2069 {
2070 if( PCB_SHAPE* shape = dynamic_cast<PCB_SHAPE*>( item ) )
2071 {
2072 shapeList.push_back( shape );
2073 commit.Modify( shape );
2074 }
2075 }
2076
2077 ConnectBoardShapes( shapeList, s_toleranceValue );
2078
2079 commit.Push( _( "Heal Shapes" ) );
2080
2081 // Notify other tools of the changes
2083
2084 return 0;
2085}
2086
2087
2089{
2090 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2091 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2092 {
2093 // Iterate from the back so we don't have to worry about removals.
2094 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
2095 {
2096 BOARD_ITEM* item = aCollector[i];
2097
2098 static const std::vector<KICAD_T> polygonBooleanTypes = {
2102 };
2103
2104 if( !item->IsType( polygonBooleanTypes ) )
2105 aCollector.Remove( item );
2106 }
2107
2108 sTool->FilterCollectorForLockedItems( aCollector );
2109 } );
2110
2111 m_selectionTool->ReportFilteredLockedItems();
2112
2113 const EDA_ITEM* const last_item = selection.GetLastAddedItem();
2114
2115 // Gather or construct polygon source shapes to merge
2116 std::vector<PCB_SHAPE*> items_to_process;
2117
2118 for( EDA_ITEM* item : selection )
2119 {
2120 items_to_process.push_back( static_cast<PCB_SHAPE*>( item ) );
2121
2122 // put the last one in the selection at the front of the vector
2123 // so it can be used as the property donor and as the basis for the
2124 // boolean operation
2125 if( item == last_item )
2126 std::swap( items_to_process.back(), items_to_process.front() );
2127 }
2128
2129 BOARD_COMMIT commit{ this };
2130
2131 // Handle modifications to existing items by the routine
2132 auto item_modification_handler =
2133 [&]( BOARD_ITEM& aItem )
2134 {
2135 commit.Modify( &aItem );
2136 };
2137
2138 std::vector<BOARD_ITEM*> items_to_select_on_success;
2139
2140 auto item_creation_handler =
2141 [&]( std::unique_ptr<BOARD_ITEM> aItem )
2142 {
2143 items_to_select_on_success.push_back( aItem.get() );
2144 commit.Add( aItem.release() );
2145 };
2146
2147 auto item_removal_handler =
2148 [&]( BOARD_ITEM& aItem )
2149 {
2150 commit.Remove( &aItem );
2151 };
2152
2153 // Combine these callbacks into a CHANGE_HANDLER to inject in the ROUTINE
2154 ITEM_MODIFICATION_ROUTINE::CALLABLE_BASED_HANDLER change_handler( item_creation_handler, item_modification_handler,
2155 item_removal_handler );
2156
2157 // Construct an appropriate routine
2158 std::unique_ptr<POLYGON_BOOLEAN_ROUTINE> boolean_routine;
2159
2160 const auto create_routine =
2161 [&]() -> std::unique_ptr<POLYGON_BOOLEAN_ROUTINE>
2162 {
2163 // (Re-)construct the boolean routine based on the action
2164 // This is done here so that we can re-init the routine if we need to
2165 // go again in the reverse order.
2166
2167 BOARD_ITEM_CONTAINER* const model = frame()->GetModel();
2168 wxCHECK( model, nullptr );
2169
2170 if( aEvent.IsAction( &PCB_ACTIONS::mergePolygons ) )
2171 {
2172 return std::make_unique<POLYGON_MERGE_ROUTINE>( model, change_handler );
2173 }
2174 else if( aEvent.IsAction( &PCB_ACTIONS::subtractPolygons ) )
2175 {
2176 return std::make_unique<POLYGON_SUBTRACT_ROUTINE>( model, change_handler );
2177 }
2178 else if( aEvent.IsAction( &PCB_ACTIONS::intersectPolygons ) )
2179 {
2180 return std::make_unique<POLYGON_INTERSECT_ROUTINE>( model, change_handler );
2181 }
2182 return nullptr;
2183 };
2184
2185 const auto run_routine =
2186 [&]()
2187 {
2188 // Perform the operation on each polygon
2189 for( PCB_SHAPE* shape : items_to_process )
2190 boolean_routine->ProcessShape( *shape );
2191
2192 boolean_routine->Finalize();
2193 };
2194
2195 boolean_routine = create_routine();
2196
2197 wxCHECK_MSG( boolean_routine, 0, "Could not find a polygon routine for this action" );
2198
2199 // First run the routine and see what we get
2200 run_routine();
2201
2202 // If we are doing a non-commutative operation (e.g. subtract), and we just got null,
2203 // assume the user meant go in a different opposite order
2204 if( !boolean_routine->IsCommutative() && items_to_select_on_success.empty() )
2205 {
2206 // Clear the commit and the selection
2207 commit.Revert();
2208 items_to_select_on_success.clear();
2209
2210 std::map<const PCB_SHAPE*, VECTOR2I::extended_type> items_area;
2211
2212 for( PCB_SHAPE* shape : items_to_process )
2213 {
2214 VECTOR2I::extended_type area = shape->GetBoundingBox().GetArea();
2215 items_area[shape] = area;
2216 }
2217
2218 // Sort the shapes by their bounding box area in descending order
2219 // This way we will start with the largest shape first and subtract the smaller ones
2220 // This may not work perfectly in all cases, but it works well when the larger
2221 // shape completely contains the smaller ones, which is probably the most common case.
2222 // In other cases, the user will need to select the shapes in the correct order (i.e.
2223 // the largest shape last), or do the subtractions in multiple steps.
2224 std::sort( items_to_process.begin(), items_to_process.end(),
2225 [&]( const PCB_SHAPE* a, const PCB_SHAPE* b )
2226 {
2227 return items_area[a] > items_area[b];
2228 } );
2229
2230 // Run the routine again
2231 boolean_routine = create_routine();
2232 run_routine();
2233 }
2234
2235 // Select new items
2236 for( BOARD_ITEM* item : items_to_select_on_success )
2237 m_selectionTool->AddItemToSel( item, true );
2238
2239 // Notify other tools of the changes
2241
2242 commit.Push( boolean_routine->GetCommitDescription() );
2243
2244 if( const std::optional<wxString> msg = boolean_routine->GetStatusMessage() )
2245 frame()->ShowInfoBarMsg( *msg );
2246
2247 return 0;
2248}
2249
2250
2252{
2254
2255 // A constraint selected by clicking its badge has no board selection, so Edit targets it here
2256 // before the normal properties path (mirrors the Delete hook for a badge-selected constraint).
2257 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
2258 constraintTool && constraintTool->TryEditSelectedConstraint() )
2259 {
2260 return 0;
2261 }
2262
2263 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2264 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2265 {
2266 } );
2267
2268 // Snapshot undo depth to detect whether dialog actually committed
2269 // Cancel leaves it unchanged and must not trigger a constraint resolve
2270 const int undoBefore = editFrame->GetUndoCommandCount();
2271
2272 // Detector to reject attempting to edit generated items that may be selectable
2273 // but we don't want to remain read-only to outside-the-generator editing
2274 auto containsReadOnlyGenChild =
2275 []( const SELECTION& aSel ) -> bool
2276 {
2277 for( EDA_ITEM* item : aSel )
2278 {
2279 if( !item->IsBOARD_ITEM() )
2280 continue;
2281
2282 EDA_GROUP* parent = static_cast<BOARD_ITEM*>( item )->GetParentGroup();
2283
2284 if( !parent || parent->AsEdaItem()->Type() != PCB_GENERATOR_T )
2285 continue;
2286
2287 PCB_GENERATOR* gen = static_cast<PCB_GENERATOR*>( parent->AsEdaItem() );
2288
2289 if( gen->ChildrenAreReadOnly() )
2290 return true;
2291 }
2292
2293 return false;
2294 };
2295
2296 if( containsReadOnlyGenChild( selection ) )
2297 {
2298 wxBell();
2299 }
2300 // Tracks & vias are treated in a special way:
2302 {
2303 DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection );
2304 dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
2305 }
2307 {
2308 std::vector<PCB_TABLECELL*> cells;
2309
2310 for( EDA_ITEM* item : selection.Items() )
2311 cells.push_back( static_cast<PCB_TABLECELL*>( item ) );
2312
2313 DIALOG_TABLECELL_PROPERTIES dlg( editFrame, cells );
2314
2315 // QuasiModal required for syntax help and Scintilla auto-complete
2316 dlg.ShowQuasiModal();
2317
2319 {
2320 PCB_TABLE* table = static_cast<PCB_TABLE*>( cells[0]->GetParent() );
2321 DIALOG_TABLE_PROPERTIES tableDlg( frame(), table );
2322
2323 tableDlg.ShowQuasiModal(); // Scintilla's auto-complete requires quasiModal
2324 }
2325 }
2326 else if( selection.Size() == 1 && selection.Front()->IsBOARD_ITEM() )
2327 {
2328 // Display properties dialog
2329 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
2330
2331 // Do not handle undo buffer, it is done by the properties dialogs
2332 editFrame->OnEditItemRequest( item );
2333
2334 // Notify other tools of the changes
2336 }
2337 else if( selection.Size() == 0 && getView()->IsLayerVisible( LAYER_DRAWINGSHEET ) )
2338 {
2339 DS_PROXY_VIEW_ITEM* ds = editFrame->GetCanvas()->GetDrawingSheet();
2340 VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
2341
2342 if( ds && ds->HitTestDrawingSheetItems( getView(), cursorPos ) )
2343 m_toolMgr->PostAction( ACTIONS::pageSettings );
2344 else
2346 }
2347 else if( selection.Size() > 1 )
2348 {
2349 WX_INFOBAR* infobar = frame()->GetInfoBar();
2350
2351 infobar->RemoveAllButtons();
2352
2353 if( !frame()->GetPropertiesPanel()->IsShownOnScreen() )
2354 {
2355 infobar->AddLink( _( "Show Properties panel" ),
2356 [this]( wxHyperlinkEvent& aHyperlinkEvent )
2357 {
2358 frame()->ToggleProperties();
2359 } );
2360 }
2361
2362 infobar->AddCloseButton();
2363 infobar->ShowMessageFor( _( "Use Properties panel to edit properties common to selected items." ),
2364 8000, wxICON_INFORMATION );
2365 }
2366
2367 // Position or geometry edit via these dialogs settles constraints as if item were dragged
2368 // holding edited item and moving neighbors gated on real commit so canceled dialog skips the solve
2369 if( editFrame->GetUndoCommandCount() > undoBefore )
2370 {
2371 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>() )
2372 {
2373 std::vector<PCB_SHAPE*> shapes;
2375 constraintTool->SolveAfterEdit( shapes );
2376 }
2377 }
2378
2379 if( selection.IsHover() )
2380 {
2381 m_toolMgr->RunAction( ACTIONS::selectionClear );
2382 }
2383 else
2384 {
2385 // Check for items becoming invisible and drop them from the selection.
2386
2387 PCB_SELECTION selCopy = selection;
2388 LSET visible = editFrame->GetBoard()->GetVisibleLayers();
2389
2390 for( EDA_ITEM* eda_item : selCopy )
2391 {
2392 if( !eda_item->IsBOARD_ITEM() )
2393 continue;
2394
2395 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( eda_item );
2396
2397 if( !( item->GetLayerSet() & visible ).any() )
2398 m_selectionTool->RemoveItemFromSel( item );
2399 }
2400 }
2401
2402 if( m_dragging )
2403 {
2406 }
2407
2408 return 0;
2409}
2410
2411
2413{
2414 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2415 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2416 {
2417 sTool->FilterCollectorForMarkers( aCollector );
2418 sTool->FilterCollectorForHierarchy( aCollector, true );
2419 sTool->FilterCollectorForTableCells( aCollector );
2420 sTool->FilterCollectorForLockedItems( aCollector );
2421 } );
2422
2423 m_selectionTool->ReportFilteredLockedItems();
2424
2426 {
2427 wxBell();
2428 return 0;
2429 }
2430
2432 BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selection.Front() );
2433
2434 if( editFrame && item )
2435 editFrame->OpenVertexEditor( item );
2436
2437 return 0;
2438}
2439
2440
2441void EDIT_TOOL::collectConstraintShapes( const SELECTION& aSelection, std::vector<PCB_SHAPE*>& aShapes )
2442{
2443 // Recurse so constrained shapes carried inside a transformed footprint or group seed their
2444 // clusters too; a top-level-only walk would leave those constraints silently violated.
2445 // PCB_GROUP::RunOnChildren only descends into groups and generators, so recurse through every
2446 // container ourselves; the visited set guards against overlapping ownership paths.
2447 std::unordered_set<BOARD_ITEM*> visited;
2448
2449 std::function<void( BOARD_ITEM* )> collect =
2450 [&]( BOARD_ITEM* aItem )
2451 {
2452 if( !aItem || !visited.insert( aItem ).second )
2453 return;
2454
2455 if( aItem->Type() == PCB_SHAPE_T )
2456 aShapes.push_back( static_cast<PCB_SHAPE*>( aItem ) );
2457
2458 aItem->RunOnChildren( collect, RECURSE_MODE::NO_RECURSE );
2459 };
2460
2461 for( EDA_ITEM* item : aSelection )
2462 {
2463 if( item->IsBOARD_ITEM() )
2464 collect( static_cast<BOARD_ITEM*>( item ) );
2465 }
2466}
2467
2468
2470{
2471 CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
2472
2473 if( !constraintTool )
2474 return;
2475
2476 std::vector<PCB_SHAPE*> shapes;
2477 collectConstraintShapes( aSelection, shapes );
2478
2479 constraintTool->SolveAfterMove( shapes );
2480}
2481
2482
2483int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
2484{
2485 if( isRouterActive() )
2486 {
2487 wxBell();
2488 return 0;
2489 }
2490
2492 BOARD_COMMIT localCommit( this );
2493 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2494
2495 if( !commit )
2496 commit = &localCommit;
2497
2498 // Be sure that there is at least one item that we can modify. If nothing was selected before,
2499 // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
2500 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2501 [&]( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2502 {
2503 sTool->FilterCollectorForMarkers( aCollector );
2504 sTool->FilterCollectorForHierarchy( aCollector, true );
2505 sTool->FilterCollectorForFreePads( aCollector, false );
2506 sTool->FilterCollectorForTableCells( aCollector );
2507
2508 // Filter locked items if in board editor and in free-pad-mode. (If we're not in
2509 // free-pad mode we delay this until the second RequestSelection().)
2510 if( !m_isFootprintEditor && frame()->GetPcbNewSettings()->m_AllowFreePads )
2511 sTool->FilterCollectorForLockedItems( aCollector );
2512 } );
2513
2514 m_selectionTool->ReportFilteredLockedItems();
2515
2516 if( selection.Empty() )
2517 return 0;
2518
2519 std::optional<VECTOR2I> oldRefPt;
2520 bool is_hover = selection.IsHover(); // N.B. This must be saved before the second
2521 // call to RequestSelection() below
2522
2523 if( selection.HasReferencePoint() )
2524 oldRefPt = selection.GetReferencePoint();
2525
2526 // Now filter out pads if not in free pads mode. We cannot do this in the first
2527 // RequestSelection() as we need the reference point when a pad is the selection front.
2528 if( !m_isFootprintEditor && !frame()->GetPcbNewSettings()->m_AllowFreePads )
2529 {
2530 selection = m_selectionTool->RequestSelection(
2531 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2532 {
2533 sTool->FilterCollectorForMarkers( aCollector );
2534 sTool->FilterCollectorForHierarchy( aCollector, true );
2535 sTool->FilterCollectorForFreePads( aCollector );
2536 sTool->FilterCollectorForTableCells( aCollector );
2537 sTool->FilterCollectorForLockedItems( aCollector );
2538 } );
2539
2540 m_selectionTool->ReportFilteredLockedItems();
2541 }
2542
2543 // Did we filter everything out? If so, don't try to operate further
2544 if( selection.Empty() )
2545 return 0;
2546
2547 // Some PCB_SHAPE must be rotated around their center instead of their start point in
2548 // order to stay to the same place (at least RECT and POLY)
2549 // Note a RECT shape rotated by a not cardinal angle is a POLY shape
2550 bool usePcbShapeCenter = false;
2551
2552 if( selection.Size() == 1 && !m_dragging && dynamic_cast<PCB_SHAPE*>( selection.Front() ) )
2553 {
2554 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( selection.Front() );
2555
2556 if( shape->GetShape() == SHAPE_T::RECTANGLE || shape->GetShape() == SHAPE_T::POLY )
2557 usePcbShapeCenter = true;
2558 }
2559
2560 if( selection.Size() == 1 && !m_dragging && dynamic_cast<PCB_TABLE*>( selection.Front() ) )
2561 usePcbShapeCenter = true;
2562
2563 if( selection.Size() == 1 && !m_dragging && dynamic_cast<PCB_TEXTBOX*>( selection.Front() ) )
2564 {
2565 selection.SetReferencePoint( static_cast<PCB_TEXTBOX*>( selection.Front() )->GetCenter() );
2566 }
2567 else if( usePcbShapeCenter )
2568 {
2569 selection.SetReferencePoint( static_cast<PCB_SHAPE*>( selection.Front() )->GetCenter() );
2570 }
2571 else
2572 {
2574 }
2575
2576 VECTOR2I refPt = selection.GetReferencePoint();
2577 EDA_ANGLE rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
2578
2579 if( frame()->GetCanvas()->GetView()->GetGAL()->IsFlippedX() )
2580 rotateAngle = -rotateAngle;
2581
2582 // Calculate view bounding box
2583 BOX2I viewBBox = selection.Front()->ViewBBox();
2584
2585 for( EDA_ITEM* item : selection )
2586 viewBBox.Merge( item->ViewBBox() );
2587
2588 // Check if the view bounding box will go out of bounds
2589 VECTOR2D rotPos = viewBBox.GetPosition();
2590 VECTOR2D rotEnd = viewBBox.GetEnd();
2591
2592 RotatePoint( &rotPos.x, &rotPos.y, refPt.x, refPt.y, rotateAngle );
2593 RotatePoint( &rotEnd.x, &rotEnd.y, refPt.x, refPt.y, rotateAngle );
2594
2595 typedef std::numeric_limits<int> coord_limits;
2596
2597 int max = coord_limits::max() - COORDS_PADDING;
2598 int min = -max;
2599
2600 bool outOfBounds = rotPos.x < min || rotPos.x > max || rotPos.y < min || rotPos.y > max || rotEnd.x < min
2601 || rotEnd.x > max || rotEnd.y < min || rotEnd.y > max;
2602
2603 if( !outOfBounds )
2604 {
2605 for( EDA_ITEM* item : selection )
2606 {
2607 commit->Modify( item, nullptr, RECURSE_MODE::RECURSE );
2608
2609 if( item->IsBOARD_ITEM() )
2610 {
2611 BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
2612
2613 board_item->Rotate( refPt, rotateAngle );
2614 board_item->Normalize();
2615
2616 if( board_item->Type() == PCB_FOOTPRINT_T )
2617 static_cast<FOOTPRINT*>( board_item )->InvalidateComponentClassCache();
2618 }
2619 }
2620
2621 // Don't push a separate undo entry when we're in the middle of a move operation.
2622 // The parent move will handle the commit.
2623 if( !localCommit.Empty() && !m_dragging )
2624 {
2625 localCommit.Push( _( "Rotate" ) );
2627 }
2628
2629 if( is_hover && !m_dragging )
2630 m_toolMgr->RunAction( ACTIONS::selectionClear );
2631
2633
2634 if( m_dragging )
2635 {
2638 }
2639 }
2640
2641 // Restore the old reference so any mouse dragging that occurs doesn't make the selection jump
2642 // to this now invalid reference
2643 if( oldRefPt )
2644 selection.SetReferencePoint( *oldRefPt );
2645 else
2646 selection.ClearReferencePoint();
2647
2648 return 0;
2649}
2650
2651
2655static void mirrorPad( PAD& aPad, const VECTOR2I& aMirrorPoint, FLIP_DIRECTION aFlipDirection )
2656{
2658 [&]( PCB_LAYER_ID layer )
2659 {
2660 if( aPad.GetShape( layer ) == PAD_SHAPE::CUSTOM )
2661 aPad.FlipPrimitives( aFlipDirection );
2662 } );
2663
2664 VECTOR2I tmpPt = aPad.GetPosition();
2665 MIRROR( tmpPt, aMirrorPoint, aFlipDirection );
2666 aPad.SetPosition( tmpPt );
2667
2669 [&]( PCB_LAYER_ID layer )
2670 {
2671 tmpPt = aPad.GetOffset( layer );
2672 MIRROR( tmpPt, VECTOR2I{ 0, 0 }, aFlipDirection );
2673 aPad.SetOffset( layer, tmpPt );
2674
2675 VECTOR2I tmpz = aPad.GetDelta( layer );
2676 MIRROR( tmpz, VECTOR2I{ 0, 0 }, aFlipDirection );
2677 aPad.SetDelta( layer, tmpz );
2678 } );
2679
2680 aPad.SetOrientation( -aPad.GetOrientation() );
2681}
2682
2683
2684const std::vector<KICAD_T> EDIT_TOOL::MirrorableItems = {
2687 PCB_TEXT_T,
2689 PCB_ZONE_T,
2690 PCB_PAD_T,
2692 PCB_ARC_T,
2693 PCB_VIA_T,
2700};
2701
2702
2703int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
2704{
2705 if( isRouterActive() )
2706 {
2707 wxBell();
2708 return 0;
2709 }
2710
2711 BOARD_COMMIT localCommit( this );
2712 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2713
2714 if( !commit )
2715 commit = &localCommit;
2716
2717 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2718 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2719 {
2720 sTool->FilterCollectorForMarkers( aCollector );
2721 sTool->FilterCollectorForHierarchy( aCollector, true );
2722 sTool->FilterCollectorForFreePads( aCollector );
2723 sTool->FilterCollectorForLockedItems( aCollector );
2724 } );
2725
2726 m_selectionTool->ReportFilteredLockedItems();
2727
2728 if( selection.Empty() )
2729 return 0;
2730
2732 VECTOR2I mirrorPoint = selection.GetReferencePoint();
2733
2736
2737 int skippedFootprints = 0;
2738 int skippedGroups = 0;
2739
2740 for( EDA_ITEM* item : selection )
2741 {
2742 if( !item->IsType( MirrorableItems ) )
2743 {
2744 if( item->Type() == PCB_FOOTPRINT_T )
2745 skippedFootprints++;
2746
2747 continue;
2748 }
2749
2750 // Skip groups that hold non-mirrorable items, else the rest would tear away from them.
2751 if( item->Type() == PCB_GROUP_T && !groupMirrorable( static_cast<PCB_GROUP*>( item ) ) )
2752 {
2753 skippedGroups++;
2754 continue;
2755 }
2756
2757 commit->Modify( item, nullptr, RECURSE_MODE::RECURSE );
2758
2759 // modify each object as necessary
2760 switch( item->Type() )
2761 {
2762 case PCB_SHAPE_T:
2763 static_cast<PCB_SHAPE*>( item )->Mirror( mirrorPoint, flipDirection );
2764 break;
2765
2766 case PCB_ZONE_T:
2767 static_cast<ZONE*>( item )->Mirror( mirrorPoint, flipDirection );
2768 break;
2769
2770 case PCB_FIELD_T:
2771 case PCB_TEXT_T:
2772 static_cast<PCB_TEXT*>( item )->Mirror( mirrorPoint, flipDirection );
2773 break;
2774
2775 case PCB_TEXTBOX_T:
2776 static_cast<PCB_TEXTBOX*>( item )->Mirror( mirrorPoint, flipDirection );
2777 break;
2778
2779 case PCB_TABLE_T:
2780 case PCB_DRILL_CHART_T:
2781 static_cast<PCB_TABLE*>( item )->Mirror( mirrorPoint, flipDirection );
2782 break;
2783
2784 case PCB_PAD_T:
2785 mirrorPad( *static_cast<PAD*>( item ), mirrorPoint, flipDirection );
2786 break;
2787
2788 case PCB_TRACE_T:
2789 case PCB_ARC_T:
2790 case PCB_VIA_T:
2791 static_cast<PCB_TRACK*>( item )->Mirror( mirrorPoint, flipDirection );
2792 break;
2793
2794 case PCB_GROUP_T:
2795 static_cast<PCB_GROUP*>( item )->Mirror( mirrorPoint, flipDirection );
2796 break;
2797
2798 case PCB_GENERATOR_T:
2799 static_cast<PCB_GENERATOR*>( item )->Mirror( mirrorPoint, flipDirection );
2800 break;
2801
2802 case PCB_POINT_T:
2803
2804 static_cast<PCB_POINT*>( item )->Mirror( mirrorPoint, flipDirection ); break;
2805
2807 static_cast<PCB_REFERENCE_IMAGE*>( item )->Mirror( mirrorPoint, flipDirection );
2808 break;
2809
2810 default:
2811 // it's likely the commit object is wrong if you get here
2812 UNIMPLEMENTED_FOR( item->GetClass() );
2813 }
2814 }
2815
2816 // Don't push a separate undo entry when we're in the middle of a move operation.
2817 // The parent move will handle the commit.
2818 if( !localCommit.Empty() && !m_dragging )
2819 {
2820 localCommit.Push( _( "Mirror" ) );
2822 }
2823
2824 if( skippedFootprints > 0 && !m_dragging )
2825 {
2826 frame()->ShowInfoBarMsg( _( "Footprints cannot be mirrored. Use Flip to move them to "
2827 "the other side of the board." ) );
2828 }
2829 else if( skippedGroups > 0 && !m_dragging )
2830 {
2831 frame()->ShowInfoBarMsg( _( "Groups containing footprints or other items that cannot be "
2832 "mirrored were skipped." ) );
2833 }
2834
2835 if( selection.IsHover() && !m_dragging )
2836 m_toolMgr->RunAction( ACTIONS::selectionClear );
2837
2839
2840 if( m_dragging )
2841 {
2844 }
2845
2846 return 0;
2847}
2848
2849
2851{
2852 if( isRouterActive() )
2853 {
2854 wxBell();
2855 return 0;
2856 }
2857
2858 BOARD_COMMIT localCommit( this );
2859 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2860
2861 if( !commit )
2862 commit = &localCommit;
2863
2864 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2865 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2866 {
2867 sTool->FilterCollectorForHierarchy( aCollector, true );
2868 sTool->FilterCollectorForLockedItems( aCollector );
2869 } );
2870
2871 m_selectionTool->ReportFilteredLockedItems();
2872
2873 if( selection.Empty() )
2874 return 0;
2875
2876 auto setJustify =
2877 [&]( EDA_TEXT* aTextItem )
2878 {
2879 if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
2880 aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_LEFT );
2881 else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
2882 aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_CENTER );
2883 else
2884 aTextItem->SetHorizJustify( GR_TEXT_H_ALIGN_RIGHT );
2885 };
2886
2887 for( EDA_ITEM* item : selection )
2888 {
2889 if( item->Type() == PCB_FIELD_T || item->Type() == PCB_TEXT_T )
2890 {
2891 commit->Modify( item );
2892 setJustify( static_cast<PCB_TEXT*>( item ) );
2893 }
2894 else if( item->Type() == PCB_TEXTBOX_T )
2895 {
2896 commit->Modify( item );
2897 setJustify( static_cast<PCB_TEXTBOX*>( item ) );
2898 }
2899 }
2900
2901 if( !localCommit.Empty() )
2902 {
2903 if( aEvent.Matches( ACTIONS::leftJustify.MakeEvent() ) )
2904 localCommit.Push( _( "Left Justify" ) );
2905 else if( aEvent.Matches( ACTIONS::centerJustify.MakeEvent() ) )
2906 localCommit.Push( _( "Center Justify" ) );
2907 else
2908 localCommit.Push( _( "Right Justify" ) );
2909 }
2910
2911 if( selection.IsHover() && !m_dragging )
2912 m_toolMgr->RunAction( ACTIONS::selectionClear );
2913
2915
2916 if( m_dragging )
2917 {
2920 }
2921
2922 return 0;
2923}
2924
2925
2926int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
2927{
2928 if( isRouterActive() )
2929 {
2930 wxBell();
2931 return 0;
2932 }
2933
2934 BOARD_COMMIT localCommit( this );
2935 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
2936
2937 if( !commit )
2938 commit = &localCommit;
2939
2940 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
2941 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2942 {
2943 sTool->FilterCollectorForMarkers( aCollector );
2944 sTool->FilterCollectorForHierarchy( aCollector, true );
2945 sTool->FilterCollectorForFreePads( aCollector );
2946 sTool->FilterCollectorForTableCells( aCollector );
2947 sTool->FilterCollectorForLockedItems( aCollector );
2948 } );
2949
2950 m_selectionTool->ReportFilteredLockedItems();
2951
2952 if( selection.Empty() )
2953 return 0;
2954
2955 std::optional<VECTOR2I> oldRefPt;
2956
2957 if( selection.HasReferencePoint() )
2958 oldRefPt = selection.GetReferencePoint();
2959
2961
2962 // Flip around the anchor for footprints, and the bounding box center for board items
2963 VECTOR2I refPt = IsFootprintEditor() ? VECTOR2I( 0, 0 ) : selection.GetCenter();
2964
2965 if( m_dragging && m_inMoveWithReference && oldRefPt )
2966 {
2967 refPt = *oldRefPt;
2968 }
2969 else if( selection.GetSize() == 1 )
2970 {
2971 // If only one item selected, flip around the selection or item anchor point (instead
2972 // of the bounding box center) to avoid moving the item anchor
2973 // but only if the item is not a PCB_SHAPE with SHAPE_T::RECTANGLE shape, because
2974 // for this shape the flip transform swap start and end coordinates and move the shape.
2975 // So using the center of the shape is better (the shape does not move)
2976 // (Tables are a bunch of rectangles, so exclude them too)
2977 PCB_SHAPE* rect = dynamic_cast<PCB_SHAPE*>( selection.GetItem( 0 ) );
2978 PCB_TABLE* table = dynamic_cast<PCB_TABLE*>( selection.GetItem( 0 ) );
2979
2980 if( !table && ( !rect || rect->GetShape() != SHAPE_T::RECTANGLE ) )
2981 refPt = selection.GetReferencePoint();
2982 }
2983
2984 const FLIP_DIRECTION flipDirection = frame()->GetPcbNewSettings()->m_FlipDirection;
2985
2986 for( EDA_ITEM* item : selection )
2987 {
2988 if( !item->IsBOARD_ITEM() )
2989 continue;
2990
2991 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
2992
2993 commit->Modify( boardItem, nullptr, RECURSE_MODE::RECURSE );
2994
2995 boardItem->Flip( refPt, flipDirection );
2996 boardItem->Normalize();
2997
2998 if( boardItem->Type() == PCB_FOOTPRINT_T )
2999 static_cast<FOOTPRINT*>( boardItem )->InvalidateComponentClassCache();
3000 }
3001
3002 // Don't push a separate undo entry when we're in the middle of a move operation.
3003 // The parent move will handle the commit.
3004 if( !localCommit.Empty() && !m_dragging )
3005 {
3006 localCommit.Push( _( "Change Side / Flip" ) );
3008 }
3009
3010 if( selection.IsHover() && !m_dragging )
3011 m_toolMgr->RunAction( ACTIONS::selectionClear );
3012
3014
3015 if( m_dragging )
3016 {
3019 }
3020
3021 // Restore the old reference so any mouse dragging that occurs doesn't make the selection jump
3022 // to this now invalid reference
3023 if( oldRefPt )
3024 selection.SetReferencePoint( *oldRefPt );
3025 else
3026 selection.ClearReferencePoint();
3027
3028 return 0;
3029}
3030
3031
3032void EDIT_TOOL::DeleteItems( const PCB_SELECTION& aItems, bool aIsCut )
3033{
3035 BOARD_COMMIT commit( this );
3036 int commitFlags = 0;
3037
3038 // As we are about to remove items, they have to be removed from the selection first
3039 m_toolMgr->RunAction( ACTIONS::selectionClear );
3040
3041 int itemsDeleted = 0;
3042 int fieldsHidden = 0;
3043 int fieldsAlreadyHidden = 0;
3044
3045 for( EDA_ITEM* item : aItems )
3046 {
3047 if( !item->IsBOARD_ITEM() )
3048 continue;
3049
3050 BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
3051 FOOTPRINT* parentFP = board_item->GetParentFootprint();
3052
3053 switch( item->Type() )
3054 {
3055 case PCB_FIELD_T:
3056 {
3057 PCB_FIELD* field = static_cast<PCB_FIELD*>( board_item );
3058
3059 wxASSERT( parentFP );
3060 commit.Modify( parentFP );
3061
3062 if( field->IsVisible() )
3063 {
3064 field->SetVisible( false );
3065 fieldsHidden++;
3066 }
3067 else
3068 {
3069 fieldsAlreadyHidden++;
3070 }
3071
3072 getView()->Update( parentFP );
3073 break;
3074 }
3075
3076 case PCB_TEXT_T:
3077 case PCB_SHAPE_T:
3078 case PCB_TEXTBOX_T:
3079 case PCB_BARCODE_T:
3080 case PCB_TABLE_T:
3081 case PCB_DRILL_CHART_T:
3083 case PCB_DIMENSION_T:
3084 case PCB_DIM_ALIGNED_T:
3085 case PCB_DIM_LEADER_T:
3086 case PCB_DIM_CENTER_T:
3087 case PCB_DIM_RADIAL_T:
3089 case PCB_POINT_T:
3090 commit.Remove( board_item );
3091 itemsDeleted++;
3092 break;
3093
3094 case PCB_TABLECELL_T:
3095 // A drill chart's cells report the board, so there is no user text to clear
3096 if( board_item->GetParent() && board_item->GetParent()->Type() == PCB_DRILL_CHART_T )
3097 break;
3098
3099 // Clear contents of table cell
3100 commit.Modify( board_item );
3101 static_cast<PCB_TABLECELL*>( board_item )->SetText( wxEmptyString );
3102 itemsDeleted++;
3103 break;
3104
3105 case PCB_GROUP_T:
3106 board_item->RunOnChildren(
3107 [&commit]( BOARD_ITEM* aItem )
3108 {
3109 commit.Remove( aItem );
3110 },
3112
3113 commit.Remove( board_item );
3114 itemsDeleted++;
3115 break;
3116
3117 case PCB_PAD_T:
3118 if( IsFootprintEditor() || frame()->GetPcbNewSettings()->m_AllowFreePads )
3119 {
3120 commit.Remove( board_item );
3121 itemsDeleted++;
3122 }
3123
3124 break;
3125
3126 case PCB_ZONE_T:
3127 // We process the zones special so that cutouts can be deleted when the delete
3128 // tool is called from inside a cutout when the zone is selected.
3129 // Only interact with cutouts when deleting and a single item is selected
3130 if( !aIsCut && aItems.GetSize() == 1 )
3131 {
3132 VECTOR2I curPos = getViewControls()->GetCursorPosition();
3133 ZONE* zone = static_cast<ZONE*>( board_item );
3134
3135 int outlineIdx, holeIdx;
3136
3137 if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) )
3138 {
3139 // Remove the cutout
3140 commit.Modify( zone );
3141 zone->RemoveCutout( outlineIdx, holeIdx );
3142 zone->UnFill();
3143
3144 // Update the display
3145 zone->HatchBorder();
3146 canvas()->Refresh();
3147
3148 // Restore the selection on the original zone
3149 m_toolMgr->RunAction<EDA_ITEM*>( ACTIONS::selectItem, zone );
3150
3151 break;
3152 }
3153 }
3154
3155 // Remove the entire zone otherwise
3156 commit.Remove( board_item );
3157 itemsDeleted++;
3158 break;
3159
3160 case PCB_VIA_T:
3161 {
3162 if( !aIsCut )
3163 {
3164 EDA_GROUP* parent = board_item->GetParentGroup();
3165 PCB_VIA_STITCH* stitch =
3166 parent ? dynamic_cast<PCB_VIA_STITCH*>( parent->AsEdaItem() ) : nullptr;
3167
3168 if( stitch && !aItems.Contains( stitch ) )
3169 {
3170 // We need to mark the via as excluded on deletion
3171 commit.Modify( stitch );
3172 stitch->ExcludePosition( board_item->GetPosition() );
3173 }
3174 }
3175
3176 commit.Remove( board_item );
3177 itemsDeleted++;
3178 break;
3179 }
3180
3181 case PCB_GENERATOR_T:
3182 {
3183 PCB_GENERATOR* generator = static_cast<PCB_GENERATOR*>( board_item );
3184
3185 if( ( SELECTION_CONDITIONS::OnlyTypes( { PCB_GENERATOR_T } ) )( aItems ) )
3186 {
3187 m_toolMgr->RunSynchronousAction<PCB_GENERATOR*>( PCB_ACTIONS::genRemove, &commit, generator );
3188 commit.Push( _( "Delete" ), commitFlags );
3189 commitFlags |= APPEND_UNDO;
3190 }
3191 else
3192 {
3193 for( EDA_ITEM* member : generator->GetItems() )
3194 commit.Remove( member );
3195
3196 commit.Remove( board_item );
3197 }
3198
3199 itemsDeleted++;
3200 break;
3201 }
3202
3203 default:
3204 commit.Remove( board_item );
3205 itemsDeleted++;
3206 break;
3207 }
3208 }
3209
3210 // If the entered group has been emptied then leave it.
3211 PCB_GROUP* enteredGroup = m_selectionTool->GetEnteredGroup();
3212
3213 if( enteredGroup && enteredGroup->GetItems().empty() )
3214 m_selectionTool->ExitGroup();
3215
3216 if( aIsCut )
3217 {
3218 commit.Push( _( "Cut" ), commitFlags );
3219 }
3220 else if( itemsDeleted == 0 )
3221 {
3222 if( fieldsHidden == 1 )
3223 commit.Push( _( "Hide Field" ), commitFlags );
3224 else if( fieldsHidden > 1 )
3225 commit.Push( _( "Hide Fields" ), commitFlags );
3226 else if( fieldsAlreadyHidden > 0 )
3227 editFrame->ShowInfoBarError( _( "Use the Footprint Properties dialog to remove fields." ) );
3228 }
3229 else
3230 {
3231 commit.Push( _( "Delete" ), commitFlags );
3232 }
3233}
3234
3235
3236int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
3237{
3239
3240 // A geometric constraint selected by clicking its on-canvas badge has no board selection, so a
3241 // plain Delete targets it here before the normal item-removal path. Cut is excluded: the
3242 // constraint is not on the clipboard, so it must not be silently removed (#2329).
3244
3245 if( !isCut )
3246 {
3247 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>();
3248 constraintTool && constraintTool->TryDeleteSelectedConstraint() )
3249 {
3250 return 0;
3251 }
3252 }
3253
3254 SCOPED_TOOL_PUSHER raii( editFrame, aEvent );
3255
3256 std::vector<BOARD_ITEM*> lockedItems;
3257 Activate();
3258
3259 // get a copy instead of reference (as we're going to clear the selection before removing items)
3260 PCB_SELECTION selectionCopy;
3262
3263 // If we are in a "Cut" operation, then the copied selection exists already and we want to
3264 // delete exactly that; no more, no fewer. Any filtering for locked items must be done in
3265 // the copyToClipboard() routine.
3266 if( isCut )
3267 {
3268 selectionCopy = m_selectionTool->GetSelection();
3269 }
3270 else
3271 {
3272 // Hover-pick is only a fallback for an empty selection.
3273 const bool hadInitialSelection = !m_selectionTool->GetSelection().Empty();
3274
3275 // When not in free-pad mode we normally auto-promote selected pads to their parent
3276 // footprints. But this is probably a little too dangerous for a destructive operation,
3277 // so we just do the promotion but not the deletion (allowing for a second delete to do
3278 // it if that's what the user wanted).
3279 selectionCopy = m_selectionTool->RequestSelection(
3280 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3281 {
3282 sTool->FilterCollectorForHierarchy( aCollector, true );
3283 sTool->FilterCollectorForLockedItems( aCollector );
3284 } );
3285
3286 m_selectionTool->ReportFilteredLockedItems();
3287
3288 if( hadInitialSelection && selectionCopy.Empty() )
3289 return 0;
3290
3291 size_t beforeFPCount = selectionCopy.CountType( PCB_FOOTPRINT_T );
3292
3293 selectionCopy = m_selectionTool->RequestSelection(
3294 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3295 {
3296 sTool->FilterCollectorForHierarchy( aCollector, true );
3297 sTool->FilterCollectorForFreePads( aCollector );
3298 sTool->FilterCollectorForLockedItems( aCollector );
3299 } );
3300
3301 if( !selectionCopy.IsHover() && m_selectionTool->GetSelection().CountType( PCB_FOOTPRINT_T ) > beforeFPCount )
3302 {
3303 wxBell();
3304 canvas()->Refresh();
3305 return 0;
3306 }
3307
3308 // In "alternative" mode, we expand selected track items to their full connection.
3309 if( isAlt && ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
3311
3312 selectionCopy = m_selectionTool->GetSelection();
3313
3314 if( selectionCopy.Empty() )
3315 return 0;
3316 }
3317
3318 DeleteItems( selectionCopy, isCut );
3319 canvas()->Refresh();
3320 return 0;
3321}
3322
3323
3325{
3326 if( isRouterActive() )
3327 {
3328 wxBell();
3329 return 0;
3330 }
3331
3332 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3333 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3334 {
3335 sTool->FilterCollectorForMarkers( aCollector );
3336 sTool->FilterCollectorForHierarchy( aCollector, true );
3337 sTool->FilterCollectorForFreePads( aCollector, false );
3338 sTool->FilterCollectorForTableCells( aCollector );
3339 sTool->FilterCollectorForLockedItems( aCollector );
3340 } );
3341
3342 m_selectionTool->ReportFilteredLockedItems();
3343
3344 if( selection.Empty() )
3345 return 0;
3346
3347 VECTOR2I translation;
3348 EDA_ANGLE rotation;
3350
3351 // TODO: Implement a visible bounding border at the edge
3352 BOX2I sel_box = selection.GetBoundingBox();
3353
3354 DIALOG_MOVE_EXACT dialog( frame(), translation, rotation, rotationAnchor, sel_box );
3355 int ret = dialog.ShowModal();
3356
3357 if( ret == wxID_OK )
3358 {
3359 BOARD_COMMIT commit( this );
3360 EDA_ANGLE angle = rotation;
3361 VECTOR2I rp = selection.GetCenter();
3362 VECTOR2I selCenter( rp.x, rp.y );
3363
3364 // Make sure the rotation is from the right reference point
3365 selCenter += translation;
3366
3367 if( !frame()->GetPcbNewSettings()->m_Display.m_DisplayInvertYAxis )
3368 rotation = -rotation;
3369
3370 for( EDA_ITEM* item : selection )
3371 {
3372 if( !item->IsBOARD_ITEM() )
3373 continue;
3374
3375 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
3376
3377 commit.Modify( boardItem, nullptr, RECURSE_MODE::RECURSE );
3378
3379 if( !boardItem->GetParent() || !boardItem->GetParent()->IsSelected() )
3380 boardItem->Move( translation );
3381
3382 switch( rotationAnchor )
3383 {
3385 boardItem->Rotate( boardItem->GetPosition(), angle );
3386 break;
3388 boardItem->Rotate( selCenter, angle );
3389 break;
3391 boardItem->Rotate( frame()->GetScreen()->m_LocalOrigin, angle );
3392 break;
3394 boardItem->Rotate( board()->GetDesignSettings().GetAuxOrigin(), angle );
3395 break;
3396 }
3397
3398 if( !m_dragging )
3399 getView()->Update( boardItem );
3400 }
3401
3402 commit.Push( _( "Move Exactly" ) );
3404
3405 if( selection.IsHover() )
3406 m_toolMgr->RunAction( ACTIONS::selectionClear );
3407
3409
3410 if( m_dragging )
3411 {
3414 }
3415 }
3416
3417 return 0;
3418}
3419
3420
3422{
3423 if( isRouterActive() )
3424 {
3425 wxBell();
3426 return 0;
3427 }
3428
3429 bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
3430
3431 // Be sure that there is at least one item that we can modify
3432 const PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3433 []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3434 {
3435 sTool->FilterCollectorForMarkers( aCollector );
3436 sTool->FilterCollectorForHierarchy( aCollector, true );
3437 sTool->FilterCollectorForFreePads( aCollector, true );
3438 sTool->FilterCollectorForTableCells( aCollector );
3439 } );
3440
3441 if( selection.Empty() )
3442 return 0;
3443
3444 // Some generators cannot be duplicated on their own.
3445 if( selection.Size() == 1 )
3446 {
3447 if( PCB_GENERATOR* generator = dynamic_cast<PCB_GENERATOR*>( selection.Front() ) )
3448 {
3449 if( !generator->CanDuplicate() )
3450 return 0;
3451 }
3452 }
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 if( selection.IsHover() )
3948 m_selectionTool->ClearSelection();
3949
3950 return 0;
3951}
3952
3953
3955{
3956 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
3957 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
3958 {
3959 // Anything unsupported will just be ignored
3960 } );
3961
3962 if( selection.IsHover() )
3963 m_selectionTool->ClearSelection();
3964
3965 const auto getItemText =
3966 [&]( const BOARD_ITEM& aItem ) -> wxString
3967 {
3968 switch( aItem.Type() )
3969 {
3970 case PCB_TEXT_T:
3971 case PCB_FIELD_T:
3972 case PCB_DIM_ALIGNED_T:
3973 case PCB_DIM_LEADER_T:
3974 case PCB_DIM_CENTER_T:
3975 case PCB_DIM_RADIAL_T:
3977 {
3978 // These can all go via the PCB_TEXT class
3979 const PCB_TEXT& text = static_cast<const PCB_TEXT&>( aItem );
3980 return text.GetShownText( FOR_CANVAS );
3981 }
3982 case PCB_TEXTBOX_T:
3983 case PCB_TABLECELL_T:
3984 {
3985 // This one goes via EDA_TEXT
3986 const PCB_TEXTBOX& textBox = static_cast<const PCB_TEXTBOX&>( aItem );
3987 return textBox.GetShownText( FOR_CANVAS );
3988 }
3989 case PCB_TABLE_T:
3990 case PCB_DRILL_CHART_T:
3991 {
3992 const PCB_TABLE& table = static_cast<const PCB_TABLE&>( aItem );
3993 wxString s;
3994
3995 for( int row = 0; row < table.GetRowCount(); ++row )
3996 {
3997 for( int col = 0; col < table.GetColCount(); ++col )
3998 {
3999 const PCB_TABLECELL* cell = table.GetCell( row, col );
4000 s << cell->GetShownText( FOR_CANVAS );
4001
4002 if( col < table.GetColCount() - 1 )
4003 s << '\t';
4004 }
4005
4006 if( row < table.GetRowCount() - 1 )
4007 s << '\n';
4008 }
4009 return s;
4010 }
4011 default:
4012 // No string representation for this item type
4013 break;
4014 }
4015
4016 return wxEmptyString;
4017 };
4018
4019 wxArrayString itemTexts;
4020
4021 for( EDA_ITEM* item : selection )
4022 {
4023 if( item->IsBOARD_ITEM() )
4024 {
4025 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
4026 wxString itemText = getItemText( *boardItem );
4027
4028 itemText.Trim( false ).Trim( true );
4029
4030 if( !itemText.IsEmpty() )
4031 itemTexts.Add( std::move( itemText ) );
4032 }
4033 }
4034
4035 // Send the text to the clipboard
4036 if( !itemTexts.empty() )
4037 SaveClipboard( wxJoin( itemTexts, '\n', '\0' ).ToStdString() );
4038
4039 return 0;
4040}
4041
4042
4044{
4045 if( !copyToClipboard( aEvent ) )
4046 {
4047 // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items
4048 // that were copied to the clipboard, no more, no fewer. Filtering for locked item, if
4049 // any will be done in the copyToClipboard() routine
4050 TOOL_EVENT evt = aEvent;
4052 Remove( evt );
4053 }
4054
4055 return 0;
4056}
4057
4058
4060{
4061 board()->BuildConnectivity();
4063 canvas()->RedrawRatsnest();
4064}
4065
4066
4067// clang-format off
4069{
4071 Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() );
4077 Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
4078 Go( &EDIT_TOOL::Remove, ACTIONS::doDelete.MakeEvent() );
4085 Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirrorH.MakeEvent() );
4086 Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirrorV.MakeEvent() );
4087 Go( &EDIT_TOOL::Swap, PCB_ACTIONS::swap.MakeEvent() );
4105
4111
4115
4119
4123 Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
4124}
4125// clang-format on
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
BOX2< VECTOR2I > BOX2I
Definition box2.h:927
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
Definition actions.h:318
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.
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
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 #NET_INFO 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:417
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:435
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:487
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:409
const LSET & GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1197
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:704
const FOOTPRINTS & Footprints() const
Definition board.h:463
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:653
constexpr const Vec GetCenter() const
Definition box2.h:227
constexpr bool IsValid() const
Definition box2.h:914
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:142
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:64
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:597
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:342
static void collectConstraintShapes(const SELECTION &aSelection, std::vector< PCB_SHAPE * > &aShapes)
< Collect constrainable PCB_SHAPEs in aSelection recursing groups and footprints so contained shapes ...
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:249
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:248
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:254
int JustifyText(const TOOL_EVENT &aEvent)
Set the justification on any text items (or fields) in the current selection.
bool updateModificationPoint(PCB_SELECTION &aSelection)
int ChangeTrackLayer(const TOOL_EVENT &aEvent)
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition edit_tool.h:252
int copyToClipboard(const TOOL_EVENT &aEvent)
Send the current selection to the clipboard by formatting it as a fake pcb see #AppendBoardFromClipbo...
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 see #AppendBoardFromClipboa...
static const std::vector< KICAD_T > MirrorableItems
Definition edit_tool.h:2684
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()
Re-solve the geometric constraints of any shapes in aSelection after a transform.
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)
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)
int FilletTracks(const TOOL_EVENT &aEvent)
Fillet (i.e.
PCB_SELECTION_TOOL * m_selectionTool
Definition edit_tool.h:247
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_MODULE_T.
int Rotate(const TOOL_EVENT &aEvent)
Rotate currently selected items.
static const TOOL_EVENT SelectedEvent
Definition actions.h:343
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:350
static const TOOL_EVENT ConnectivityChangedEvent
Selected item had a property changed (except movement)
Definition actions.h:347
static const TOOL_EVENT UnselectedEvent
Definition actions.h:344
Variant information for a footprint.
Definition footprint.h:227
void SetExcludedFromPosFiles(bool aExclude)
Definition footprint.h:251
void SetExcludedFromSim(bool aExclude)
Definition footprint.h:248
void SetExcludedFromBOM(bool aExclude)
Definition footprint.h:245
bool GetExcludedFromSimForVariant(const wxString &aVariantName) const
Get the exclude-from-simulation status for a specific variant.
void SetExcludedFromSim(bool aExclude=true)
Definition footprint.h:1047
void SetExcludedFromBOM(bool aExclude=true)
Definition footprint.h:1038
const std::vector< FP_UNIT_INFO > & GetUnitInfo() const
Definition footprint.h:1017
void SetExcludedFromPosFiles(bool aExclude=true)
Definition footprint.h:1029
const FOOTPRINT_VARIANT * GetVariant(const wxString &aVariantName) const
Get a variant by name.
CONSTRAINTS & Constraints()
Definition footprint.h:416
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
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:171
int GetuViaDiameter() const
Definition netclass.h:163
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:305
VECTOR2I GetPosition() const override
Definition pad.cpp:246
void SetDelta(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.h:299
VECTOR2I GetOffset(PCB_LAYER_ID aLayer) const
Definition pad.cpp:826
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:1837
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
void SetOffset(PCB_LAYER_ID aLayer, const VECTOR2I &aOffset)
Definition pad.cpp:815
void SetPosition(const VECTOR2I &aPos) override
Definition pad.cpp:235
const PADSTACK & Padstack() const
Definition pad.h:329
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1747
void SetOrientation(const EDA_ANGLE &aAngle)
Set the rotation angle of the pad.
Definition pad.cpp:1720
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:75
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:72
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:78
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:116
virtual double GetLength() const
Get the length of the track using the hypotenuse calculation.
void SetEnd(const VECTOR2I &aEnd)
Definition pcb_track.h:89
bool HasSolderMask() const
Definition pcb_track.h:117
void SetStart(const VECTOR2I &aStart)
Definition pcb_track.h:92
void SetLocalSolderMaskMargin(std::optional< int > aMargin)
Definition pcb_track.h:119
std::optional< int > GetLocalSolderMaskMargin() const
Definition pcb_track.h:120
const VECTOR2I & GetStart() const
Definition pcb_track.h:93
const VECTOR2I & GetEnd() const
Definition pcb_track.h:90
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:86
virtual int GetWidth() const
Definition pcb_track.h:87
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:802
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.
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
Returns the instance of #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:524
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:469
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 EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition vector2d.h:279
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:529
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:1077
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
Definition zone.cpp:1559
void RemoveCutout(int aOutlineIdx, int aHoleIdx)
Remove a cutout from the zone.
Definition zone.cpp:1395
bool IsTeardropArea() const
Definition zone.h:782
bool SaveClipboard(const std::string &aTextUTF8)
Store information to the system clipboard.
Definition clipboard.cpp:32
@ FOR_CANVAS
Definition common.h:88
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:839
@ DM_ANY
Definition pns_router.h:82
@ DM_FREE_ANGLE
Definition pns_router.h:80
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
@ 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.
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:637
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:225
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:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682