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