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