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