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