KiCad PCB EDA Suite
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-2017 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  * Copyright (C) 2017-2020 KiCad Developers, see AUTHORS.txt for contributors.
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 <limits>
28 #include <board.h>
29 #include <footprint.h>
30 #include <fp_shape.h>
31 #include <collectors.h>
32 #include <pcb_edit_frame.h>
34 #include <kiway.h>
35 #include <array_creator.h>
36 #include <pcbnew_settings.h>
37 #include <status_popup.h>
39 #include <tool/tool_manager.h>
40 #include <tools/pcb_actions.h>
41 #include <tools/selection_tool.h>
42 #include <tools/edit_tool.h>
44 #include <tools/tool_event_utils.h>
45 #include <tools/grid_helper.h>
46 #include <tools/pad_tool.h>
47 #include <pad_naming.h>
48 #include <view/view_controls.h>
52 #include <confirm.h>
53 #include <bitmaps.h>
54 #include <cassert>
55 #include <functional>
56 using namespace std::placeholders;
57 #include "kicad_clipboard.h"
58 #include <router/router_tool.h>
62 #include <board_commit.h>
63 #include <zone_filler.h>
64 
65 
66 void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags,
67  SELECTION_TOOL* selectionTool )
68 {
69  // Iterate from the back so we don't have to worry about removals.
70  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
71  {
72  BOARD_ITEM* item = aCollector[ i ];
73 
74  if( ( aFlags & EXCLUDE_LOCKED ) && item->IsLocked() )
75  {
76  aCollector.Remove( item );
77  }
78  else if( item->Type() == PCB_FP_ZONE_T )
79  {
80  FOOTPRINT* fp = static_cast<FOOTPRINT*>( item->GetParent() );
81 
82  // case 1: handle locking
83  if( ( aFlags & EXCLUDE_LOCKED ) && fp && fp->IsLocked() )
84  {
85  aCollector.Remove( item );
86  }
87 
88  // case 2: selection contains both the footprint and its pads - remove the pads
89  if( !( aFlags & INCLUDE_PADS_AND_FOOTPRINTS ) && fp && aCollector.HasItem( fp ) )
90  aCollector.Remove( item );
91  }
92  else if( item->Type() == PCB_PAD_T )
93  {
94  FOOTPRINT* fp = static_cast<FOOTPRINT*>( item->GetParent() );
95 
96  // case 1: handle locking
97  if( ( aFlags & EXCLUDE_LOCKED ) && fp && fp->IsLocked() )
98  {
99  aCollector.Remove( item );
100  }
101  else if( ( aFlags & EXCLUDE_LOCKED_PADS ) && fp && fp->PadsLocked() )
102  {
103  // Pad locking is considerably "softer" than item locking
104  aCollector.Remove( item );
105 
106  if( !fp->IsLocked() && !aCollector.HasItem( fp ) )
107  aCollector.Append( fp );
108  }
109 
110  // case 2: selection contains both the footprint and its pads - remove the pads
111  if( !( aFlags & INCLUDE_PADS_AND_FOOTPRINTS ) && fp && aCollector.HasItem( fp ) )
112  aCollector.Remove( item );
113  }
114  else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T )
115  {
116  aCollector.Remove( item );
117  }
118  }
119 
120  selectionTool->FilterCollectorForGroups( aCollector );
121 }
122 
123 
125  PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
126  m_selectionTool( NULL ),
127  m_dragging( false ),
128  m_lockedSelected( false )
129 {
130 }
131 
132 
134 {
135  m_dragging = false;
136 
137  m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( getEditFrame<PCB_BASE_EDIT_FRAME>() );
138 
139  if( aReason != RUN )
140  m_commit.reset( new BOARD_COMMIT( this ) );
141 }
142 
143 
145  CONDITIONAL_MENU( aTool )
146 {
148  SetTitle( _( "Special Tools..." ) );
149 
154 }
155 
156 
158 {
159  // Find the selection tool, so they can cooperate
160  m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
161  wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
162 
163  auto inFootprintEditor =
164  [ this ] ( const SELECTION& aSelection )
165  {
166  return m_isFootprintEditor;
167  };
168 
169  auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T )
171 
172  auto noActiveToolCondition =
173  [ this ] ( const SELECTION& aSelection )
174  {
175  return frame()->ToolStackIsEmpty();
176  };
177 
178  auto notMovingCondition =
179  [ this ] ( const SELECTION& aSelection )
180  {
183  };
184 
185  auto noItemsCondition =
186  [ this ] ( const SELECTION& aSelections ) -> bool
187  {
188  return frame()->GetBoard() && !frame()->GetBoard()->IsEmpty();
189  };
190 
191  // Add context menu entries that are displayed when selection tool is active
193 
194  menu.AddItem( PCB_ACTIONS::move, SELECTION_CONDITIONS::NotEmpty && notMovingCondition );
203  menu.AddItem( PCB_ACTIONS::mirror, inFootprintEditor && SELECTION_CONDITIONS::NotEmpty );
204 
208 
210 
211  // Add the submenu for create array and special move
212  auto specialToolsSubMenu = std::make_shared<SPECIAL_TOOLS_CONTEXT_MENU>( this );
213  menu.AddSeparator();
214  m_selectionTool->GetToolMenu().AddSubMenu( specialToolsSubMenu );
215  menu.AddMenu( specialToolsSubMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 );
216 
217  menu.AddSeparator( 150 );
220  // Selection tool handles the context menu for some other tools, such as the Picker.
221  // Don't add things like Paste when another tool is active.
222  menu.AddItem( ACTIONS::paste, noActiveToolCondition, 150 );
223  menu.AddItem( ACTIONS::selectAll, noItemsCondition, 150 );
224 
225  // Footprint actions
226  menu.AddSeparator( 150 );
227  menu.AddItem( PCB_ACTIONS::editFpInFpEditor, singleFootprintCondition, 150 );
228  menu.AddItem( PCB_ACTIONS::updateFootprint, singleFootprintCondition, 150 );
229  menu.AddItem( PCB_ACTIONS::changeFootprint, singleFootprintCondition, 150 );
230 
231  return true;
232 }
233 
234 
235 int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
236 {
237  SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
238  FOOTPRINT* fp = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
239 
240  if( fp )
241  {
243  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, (void*) fp );
244 
245  selectionTool->GetSelection().SetReferencePoint( fp->GetPosition() );
247  }
248 
249  return 0;
250 }
251 
252 
253 bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
254 {
256 
257  if( !theRouter )
258  return false;
259 
260  // don't allow switch from moving to dragging
261  if( m_dragging )
262  {
263  wxBell();
264  return false;
265  }
266 
267  // make sure we don't accidentally invoke inline routing mode while the router is already active!
268  if( theRouter->IsToolActive() )
269  return false;
270 
271  if( theRouter->CanInlineDrag() )
272  {
274  return true;
275  }
276 
277  return false;
278 }
279 
280 
282 {
284 
285  return router && router->Router()->Settings().InlineDragEnabled();
286 }
287 
288 
290 {
292 
293  return router && router->IsToolActive();
294 }
295 
296 
297 int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
298 {
299  int mode = PNS::DM_ANY;
300 
301  if( aEvent.IsAction( &PCB_ACTIONS::dragFreeAngle ) )
302  mode |= PNS::DM_FREE_ANGLE;
303 
304  // deal with locked items (override lock or abort the operation)
306 
307  if( lockFlags == SELECTION_LOCKED )
308  return 0;
309 
310  invokeInlineRouter( mode );
311 
312  return 0;
313 }
314 
315 
316 int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
317 {
318  if( isRouterActive() )
319  {
320  wxBell();
321  return 0;
322  }
323 
324  return doMoveSelection( aEvent );
325 }
326 
327 
329 {
330  if( isRouterActive() )
331  {
332  wxBell();
333  return 0;
334  }
335 
336  return doMoveSelection( aEvent, true );
337 }
338 
339 
340 // Note: aEvent MUST NOT be const&; the source will get de-allocated if we go into the picker's
341 // event loop.
342 int EDIT_TOOL::doMoveSelection( TOOL_EVENT aEvent, bool aPickReference )
343 {
344  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
346  VECTOR2I originalCursorPos = controls->GetCursorPosition();
347 
348  // Be sure that there is at least one item that we can modify. If nothing was selected before,
349  // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
351  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
352  {
353  EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool );
354  } );
355 
356  if( m_dragging || selection.Empty() )
357  return 0;
358 
359  LSET item_layers = selection.GetSelectionLayers();
360  bool unselect = selection.IsHover(); // N.B. This must be saved before the re-selection below
361  VECTOR2I pickedReferencePoint;
362 
363  // Now filter out locked pads. We cannot do this in the first RequestSelection() as we need
364  // the item_layers when a pad is the selection front (ie: will become curr_tiem).
366  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
367  {
368  EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS, sTool );
369  } );
370 
371  if( selection.Empty() )
372  return 0;
373 
374  std::string tool = aEvent.GetCommandStr().get();
375  editFrame->PushTool( tool );
376  Activate();
377  controls->ShowCursor( true );
378  controls->SetAutoPan( true );
379 
380  if( aPickReference && !pickReferencePoint( _( "Select reference point for move..." ), "", "",
381  pickedReferencePoint ) )
382  {
383  if( unselect )
385 
386  editFrame->PopTool( tool );
387  return 0;
388  }
389 
390  std::vector<BOARD_ITEM*> sel_items;
391 
392  for( EDA_ITEM* item : selection )
393  {
394  BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
395  FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item );
396 
397  if( boardItem )
398  sel_items.push_back( boardItem );
399 
400  if( footprint )
401  {
402  for( PAD* pad : footprint->Pads() )
403  sel_items.push_back( pad );
404  }
405  }
406 
407  bool restore_state = false;
408  VECTOR2I totalMovement;
409  GRID_HELPER grid( m_toolMgr, editFrame->GetMagneticItemsSettings() );
410  TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
411  VECTOR2I prevPos;
412 
413  // Prime the pump
415 
416  // Main loop: keep receiving events
417  do
418  {
419  VECTOR2I movement;
421  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
422  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
423 
424  if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
425  || evt->IsAction( &ACTIONS::refreshPreview )
426  || evt->IsAction( &PCB_ACTIONS::moveWithReference ) )
427  {
428  if( m_dragging && evt->Category() == TC_MOUSE )
429  {
430  bool requestRedraw3Dview = false;
431 
432  VECTOR2I mousePos( controls->GetMousePosition() );
433 
434  m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items );
435 
437  {
439 
440  // The arrow keys are by definition SINGLE AXIS. Do not allow the other
441  // axis to be snapped to the grid.
442  if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
443  m_cursor.y = prevPos.y;
444  else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
445  m_cursor.x = prevPos.x;
446  }
447 
450 
451  movement = m_cursor - prevPos;
452  prevPos = m_cursor;
453  totalMovement += movement;
454 
455  // Drag items to the current cursor position
456  for( EDA_ITEM* item : sel_items )
457  {
458  // Don't double move footprint pads, fields, etc.
459  //
460  // For PCB_GROUP_T, we make sure the selection includes only the top level
461  // group and not its descendants.
462  if( !item->GetParent() || !item->GetParent()->IsSelected() )
463  static_cast<BOARD_ITEM*>( item )->Move( movement );
464 
465  if( item->Type() == PCB_FOOTPRINT_T )
466  requestRedraw3Dview = true;
467  }
468 
469  if( requestRedraw3Dview )
470  editFrame->Redraw3Dview();
471 
473  }
474  else if( !m_dragging && !evt->IsAction( &ACTIONS::refreshPreview ) )
475  {
476  // Prepare to start dragging
477 
478  // deal with locked items (override lock or abort the operation)
480 
481  if( lockFlags == SELECTION_LOCKED )
482  break;
483 
484  if( !( evt->IsAction( &PCB_ACTIONS::move )
485  || evt->IsAction( &PCB_ACTIONS::moveWithReference ) )
487  {
489  break;
490  }
491 
492  m_dragging = true;
493 
494  // When editing footprints, all items have the same parent
495  if( IsFootprintEditor() )
496  {
497  m_commit->Modify( selection.Front() );
498  }
499  else
500  {
501  // Save items, so changes can be undone
502  for( EDA_ITEM* item : selection )
503  {
504  // Don't double move footprint pads, fields, etc.
505  //
506  // For PCB_GROUP_T, the parent is the board.
507  if( item->GetParent() && item->GetParent()->IsSelected() )
508  continue;
509 
510  m_commit->Modify( item );
511 
512  // If moving a group, record position of all the descendants for undo
513  if( item->Type() == PCB_GROUP_T )
514  {
515  PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
516  group->RunOnDescendants( [&]( BOARD_ITEM* bItem )
517  {
518  m_commit->Modify( bItem );
519  });
520  }
521  }
522  }
523 
524  editFrame->UndoRedoBlock( true );
526 
528  {
529  // start moving with the reference point attached to the cursor
530  grid.SetAuxAxes( false );
531 
532  movement = m_cursor - selection.GetReferencePoint();
533 
534  // Drag items to the current cursor position
535  for( EDA_ITEM* item : selection )
536  {
537  // Don't double move footprint pads, fields, etc.
538  if( item->GetParent() && item->GetParent()->IsSelected() )
539  continue;
540 
541  static_cast<BOARD_ITEM*>( item )->Move( movement );
542  }
543 
545  }
546  else
547  {
548  std::vector<BOARD_ITEM*> items;
549 
550  for( EDA_ITEM* item : selection )
551  items.push_back( static_cast<BOARD_ITEM*>( item ) );
552 
553  m_cursor = grid.BestDragOrigin( originalCursorPos, items );
554 
555  // Set the current cursor position to the first dragged item origin, so the
556  // movement vector could be computed later
557  if( aPickReference )
558  {
559  selection.SetReferencePoint( pickedReferencePoint );
560  controls->ForceCursorPosition( true, pickedReferencePoint );
561  m_cursor = pickedReferencePoint;
562  }
563  else
564  {
565  // Check if user wants to warp the mouse to origin of moved object
566  if( !editFrame->GetMoveWarpsCursor() )
567  m_cursor = originalCursorPos; // No, so use original mouse pos instead
568 
570  grid.SetAuxAxes( true, m_cursor );
571  }
572  }
573 
575 
576  prevPos = m_cursor;
577  controls->SetAutoPan( true );
579  }
580 
581  m_toolMgr->RunAction( PCB_ACTIONS::updateLocalRatsnest, false, new VECTOR2I( movement ) );
582  }
583 
584  else if( evt->IsCancelInteractive() || evt->IsActivate() )
585  {
586  if( m_dragging && evt->IsCancelInteractive() )
587  evt->SetPassEvent( false );
588 
589  restore_state = true; // Canceling the tool means that items have to be restored
590  break; // Finish
591  }
592 
593  else if( evt->IsAction( &ACTIONS::undo ) )
594  {
595  restore_state = true; // Perform undo locally
596  break; // Finish
597  }
598 
599  // Dispatch TOOL_ACTIONs
600  else if( evt->IsAction( &ACTIONS::doDelete ) )
601  {
602  break; // finish -- there is no further processing for removed items
603  }
604  else if( evt->IsAction( &ACTIONS::duplicate ) )
605  {
606  break; // finish -- Duplicate tool will start a new Move with the dup'ed items
607  }
608  else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
609  {
610  // Reset positions so the Move Exactly is from the start.
611  for( EDA_ITEM* item : selection )
612  {
613  BOARD_ITEM* i = static_cast<BOARD_ITEM*>( item );
614  i->Move( -totalMovement );
615  }
616 
617  break; // finish -- we moved exactly, so we are finished
618  }
619 
620  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
621  {
622  break; // finish
623  }
624 
625  else
626  {
627  evt->SetPassEvent();
628  }
629 
630  } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
631 
632  m_lockedSelected = false;
633  controls->ForceCursorPosition( false );
634  controls->ShowCursor( false );
635  controls->SetAutoPan( false );
636 
637  m_dragging = false;
638  editFrame->UndoRedoBlock( false );
639 
640  // Discard reference point when selection is "dropped" onto the board
642 
643  // TODO: there's an ecapsulation leak here: this commit often has more than just the move
644  // in it; for instance it might have a paste, append board, etc. as well.
645  if( restore_state )
646  m_commit->Revert();
647  else
648  m_commit->Push( _( "Drag" ) );
649 
650  // Remove the dynamic ratsnest from the screen
652 
653  if( unselect )
655 
656  editFrame->PopTool( tool );
657  return 0;
658 }
659 
660 
662 {
664  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
665  {
666  EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool );
667  } );
668 
669  for( EDA_ITEM* item : selection )
670  {
671  if( auto via = dyn_cast<VIA*>( item ) )
672  {
673  m_commit->Modify( item );
674 
675  int new_width;
676  int new_drill;
677 
678  if( via->GetViaType() == VIATYPE::MICROVIA )
679  {
680  NETINFO_ITEM* net = via->GetNet();
681 
682  new_width = net->GetMicroViaSize();
683  new_drill = net->GetMicroViaDrillSize();
684  }
685  else
686  {
687  new_width = board()->GetDesignSettings().GetCurrentViaSize();
688  new_drill = board()->GetDesignSettings().GetCurrentViaDrill();
689  }
690 
691  via->SetDrill( new_drill );
692  via->SetWidth( new_width );
693  }
694  else if ( TRACK* track = dyn_cast<TRACK*>( item ) )
695  {
696  m_commit->Modify( item );
697 
698  int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
699  track->SetWidth( new_width );
700  }
701  }
702 
703  m_commit->Push( _("Edit track width/via size") );
704 
705  if( selection.IsHover() )
706  {
708 
709  // Notify other tools of the changes -- This updates the visual ratsnest
711  }
712 
713  return 0;
714 }
715 
716 
718 {
719  // Store last used fillet radius to allow pressing "enter" if repeat fillet is required
720  static long long filletRadiusIU = 0;
721 
723  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
724  {
726  aCollector, EXCLUDE_LOCKED | EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS, sTool );
727  },
728  nullptr, !m_dragging );
729 
730  if( selection.Size() < 2 )
731  {
733  _( "A minimum of two straight track segments must be selected." ) );
734  return 0;
735  }
736 
738  frame(), _( "Enter fillet radius:" ), _( "Fillet Tracks" ), filletRadiusIU );
739 
740  if( dia.ShowModal() == wxID_CANCEL )
741  return 0;
742 
743  filletRadiusIU = dia.GetValue();
744 
745  if( filletRadiusIU == 0 )
746  {
747  frame()->ShowInfoBarMsg( _( "A radius of zero was entered.\n"
748  "The fillet operation was not performed." ) );
749  return 0;
750  }
751 
752 
753  struct FILLET_OP
754  {
755  TRACK* t1;
756  TRACK* t2;
757  //If true, start point of track is modified after ARC is added, otherwise the end point:
758  bool t1Start = true;
759  bool t2Start = true;
760  };
761 
762  std::vector<FILLET_OP> filletOperations;
763  KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT };
764  bool operationPerformedOnAtLeastOne = false;
765  bool didOneAttemptFail = false;
766  std::set<TRACK*> processedTracks;
767 
768  for( auto it = selection.begin(); it != selection.end(); it++ )
769  {
770  TRACK* track = dyn_cast<TRACK*>( *it );
771 
772  if( !track || track->Type() != PCB_TRACE_T || track->IsLocked()
773  || track->GetLength() == 0 )
774  {
775  continue;
776  }
777 
778  auto processFilletOp =
779  [&]( bool aStartPoint )
780  {
781  wxPoint anchor = ( aStartPoint ) ? track->GetStart() : track->GetEnd();
782 
783  std::vector<BOARD_CONNECTED_ITEM*> itemsOnAnchor =
784  board()->GetConnectivity()->GetConnectedItemsAtAnchor( track, VECTOR2I( anchor ),
785  track_types );
786 
787  if( itemsOnAnchor.size() > 0 && selection.Contains( itemsOnAnchor.at( 0 ) )
788  && itemsOnAnchor.at( 0 )->Type() == PCB_TRACE_T )
789  {
790  TRACK* trackOther = dyn_cast<TRACK*>( itemsOnAnchor.at( 0 ) );
791 
792  // Make sure we don't fillet the same pair of tracks twice
793  if( processedTracks.find( trackOther ) == processedTracks.end() )
794  {
795  if( itemsOnAnchor.size() == 1 )
796  {
797  FILLET_OP filletOp;
798  filletOp.t1 = track;
799  filletOp.t2 = trackOther;
800  filletOp.t1Start = aStartPoint;
801  filletOp.t2Start = track->IsPointOnEnds( filletOp.t2->GetStart() );
802  filletOperations.push_back( filletOp );
803  }
804  else
805  {
806  // User requested to fillet these two tracks but not possible as there are other
807  // elements connected at that point
808  didOneAttemptFail = true;
809  }
810  }
811  }
812  };
813 
814  processFilletOp( true ); // on the start point of track
815  processFilletOp( false ); // on the end point of track
816 
817  processedTracks.insert( track );
818  }
819 
820  std::vector<BOARD_ITEM*> itemsToAddToSelection;
821 
822  for( FILLET_OP filletOp : filletOperations )
823  {
824  TRACK* track1 = filletOp.t1;
825  TRACK* track2 = filletOp.t2;
826 
827  bool trackOnStart = track1->IsPointOnEnds( track2->GetStart() );
828  bool trackOnEnd = track1->IsPointOnEnds( track2->GetEnd() );
829 
830  if( trackOnStart && trackOnEnd )
831  continue; // Ignore duplicate tracks
832 
833  if( ( trackOnStart || trackOnEnd ) && track1->GetLayer() == track2->GetLayer() )
834  {
835  SEG t1Seg( track1->GetStart(), track1->GetEnd() );
836  SEG t2Seg( track2->GetStart(), track2->GetEnd() );
837 
838  if( t1Seg.ApproxCollinear( t2Seg ) )
839  continue;
840 
841  SHAPE_ARC sArc( t1Seg, t2Seg, filletRadiusIU );
842 
843  wxPoint t1newPoint, t2newPoint;
844 
845  auto setIfPointOnSeg = []( wxPoint& aPointToSet, SEG aSegment, VECTOR2I aVecToTest )
846  {
847  VECTOR2I segToVec = aSegment.NearestPoint( aVecToTest ) - aVecToTest;
848 
849  // Find out if we are on the segment (minimum precision)
850  if( segToVec.EuclideanNorm() < SHAPE_ARC::MIN_PRECISION_IU )
851  {
852  aPointToSet.x = aVecToTest.x;
853  aPointToSet.y = aVecToTest.y;
854  return true;
855  }
856 
857  return false;
858  };
859 
860  //Do not draw a fillet if the end points of the arc are not within the track segments
861  if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP0() )
862  && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP0() ) )
863  {
864  didOneAttemptFail = true;
865  continue;
866  }
867 
868  if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP1() )
869  && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP1() ) )
870  {
871  didOneAttemptFail = true;
872  continue;
873  }
874 
875  ARC* tArc = new ARC( frame()->GetBoard(), &sArc );
876  tArc->SetLayer( track1->GetLayer() );
877  tArc->SetWidth( track1->GetWidth() );
878  tArc->SetNet( track1->GetNet() );
879  m_commit->Add( tArc );
880  itemsToAddToSelection.push_back( tArc );
881 
882  m_commit->Modify( track1 );
883  m_commit->Modify( track2 );
884 
885  if( filletOp.t1Start )
886  track1->SetStart( t1newPoint );
887  else
888  track1->SetEnd( t1newPoint );
889 
890  if( filletOp.t2Start )
891  track2->SetStart( t2newPoint );
892  else
893  track2->SetEnd( t2newPoint );
894 
895  operationPerformedOnAtLeastOne = true;
896  }
897  }
898 
899  m_commit->Push( _( "Fillet Tracks" ) );
900 
901  //select the newly created arcs
902  for( BOARD_ITEM* item : itemsToAddToSelection )
903  {
904  m_selectionTool->AddItemToSel( item );
905  }
906 
907  if( !operationPerformedOnAtLeastOne )
908  {
909  frame()->ShowInfoBarMsg( _( "Unable to fillet the selected track segments." ) );
910  }
911  else if( didOneAttemptFail )
912  {
913  frame()->ShowInfoBarMsg( _( "Some of the track segments could not be filleted." ) );
914  }
915 
916  return 0;
917 }
918 
919 
920 int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
921 {
922  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
924  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
925  {
926  EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS, sTool );
927  } );
928 
929  // Tracks & vias are treated in a special way:
931  {
932  DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
933  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
934  }
935  else if( selection.Size() == 1 )
936  {
937  // Display properties dialog
938  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
939 
940  // Do not handle undo buffer, it is done by the properties dialogs
941  editFrame->OnEditItemRequest( item );
942 
943  // Notify other tools of the changes
945  }
946  else if( selection.Size() == 0 && getView()->IsLayerVisible( LAYER_WORKSHEET ) )
947  {
948  KIGFX::WS_PROXY_VIEW_ITEM* worksheet = editFrame->GetCanvas()->GetWorksheet();
949  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
950 
951  if( worksheet && worksheet->HitTestWorksheetItems( getView(), (wxPoint) cursorPos ) )
953  }
954 
955  if( selection.IsHover() )
956  {
958 
959  // Notify other tools of the changes -- This updates the visual ratsnest
961  }
962 
963  return 0;
964 }
965 
966 
967 int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
968 {
969  if( isRouterActive() )
970  {
971  wxBell();
972  return 0;
973  }
974 
975  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
976 
978  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
979  {
981  },
982  nullptr, ! m_dragging );
983 
984  if( selection.Empty() )
985  return 0;
986 
988  auto refPt = selection.GetReferencePoint();
989  const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
990 
991  // When editing footprints, all items have the same parent
992  if( IsFootprintEditor() )
993  m_commit->Modify( selection.Front() );
994 
995  for( auto item : selection )
996  {
997  if( !item->IsNew() && !IsFootprintEditor() )
998  {
999  m_commit->Modify( item );
1000 
1001  // If rotating a group, record position of all the descendants for undo
1002  if( item->Type() == PCB_GROUP_T )
1003  {
1004  static_cast<PCB_GROUP*>( item )->RunOnDescendants(
1005  [&]( BOARD_ITEM* bItem )
1006  {
1007  m_commit->Modify( bItem );
1008  });
1009  }
1010  }
1011 
1012  static_cast<BOARD_ITEM*>( item )->Rotate( refPt, rotateAngle );
1013  }
1014 
1015  if( !m_dragging )
1016  m_commit->Push( _( "Rotate" ) );
1017 
1018  if( selection.IsHover() && !m_dragging )
1020 
1022 
1023  if( m_dragging )
1025 
1026  return 0;
1027 }
1028 
1029 
1033 static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint )
1034 {
1035  wxPoint mirrored = aPoint;
1036 
1037  mirrored.x -= aMirrorPoint.x;
1038  mirrored.x = -mirrored.x;
1039  mirrored.x += aMirrorPoint.x;
1040 
1041  return mirrored;
1042 }
1043 
1044 
1048 static void mirrorPadX( PAD& aPad, const wxPoint& aMirrorPoint )
1049 {
1050  if( aPad.GetShape() == PAD_SHAPE_CUSTOM )
1051  aPad.FlipPrimitives( true ); // mirror primitives left to right
1052 
1053  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
1054  aPad.SetPosition( tmpPt );
1055 
1056  aPad.SetX0( aPad.GetPosition().x );
1057 
1058  tmpPt = aPad.GetOffset();
1059  tmpPt.x = -tmpPt.x;
1060  aPad.SetOffset( tmpPt );
1061 
1062  auto tmpz = aPad.GetDelta();
1063  tmpz.x = -tmpz.x;
1064  aPad.SetDelta( tmpz );
1065 
1066  aPad.SetOrientation( -aPad.GetOrientation() );
1067 }
1068 
1069 
1070 int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
1071 {
1072  if( isRouterActive() )
1073  {
1074  wxBell();
1075  return 0;
1076  }
1077 
1079  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1080  {
1082  },
1083  nullptr, !m_dragging );
1084 
1085  if( selection.Empty() )
1086  return 0;
1087 
1089  auto refPoint = selection.GetReferencePoint();
1090  wxPoint mirrorPoint( refPoint.x, refPoint.y );
1091 
1092  // When editing footprints, all items have the same parent
1093  if( IsFootprintEditor() )
1094  m_commit->Modify( selection.Front() );
1095 
1096  for( EDA_ITEM* item : selection )
1097  {
1098  // only modify items we can mirror
1099  switch( item->Type() )
1100  {
1101  case PCB_FP_SHAPE_T:
1102  case PCB_FP_TEXT_T:
1103  case PCB_FP_ZONE_T:
1104  case PCB_PAD_T:
1105  // Only create undo entry for items on the board
1106  if( !item->IsNew() && !IsFootprintEditor() )
1107  m_commit->Modify( item );
1108 
1109  break;
1110  default:
1111  continue;
1112  }
1113 
1114  // modify each object as necessary
1115  switch( item->Type() )
1116  {
1117  case PCB_FP_SHAPE_T:
1118  {
1119  FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
1120  shape->Mirror( mirrorPoint, false );
1121  break;
1122  }
1123 
1124  case PCB_FP_ZONE_T:
1125  {
1126  FP_ZONE* zone = static_cast<FP_ZONE*>( item );
1127  zone->Mirror( mirrorPoint, false );
1128  break;
1129  }
1130 
1131  case PCB_FP_TEXT_T:
1132  {
1133  FP_TEXT* text = static_cast<FP_TEXT*>( item );
1134  text->Mirror( mirrorPoint, false );
1135  break;
1136  }
1137 
1138  case PCB_PAD_T:
1139  {
1140  PAD* pad = static_cast<PAD*>( item );
1141  mirrorPadX( *pad, mirrorPoint );
1142  break;
1143  }
1144 
1145  default:
1146  // it's likely the commit object is wrong if you get here
1147  // Unsure if PCB_GROUP_T needs special attention here.
1148  assert( false );
1149  break;
1150  }
1151  }
1152 
1153  if( !m_dragging )
1154  m_commit->Push( _( "Mirror" ) );
1155 
1156  if( selection.IsHover() && !m_dragging )
1158 
1160 
1161  if( m_dragging )
1163 
1164  return 0;
1165 }
1166 
1167 
1168 int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
1169 {
1170  if( isRouterActive() )
1171  {
1172  wxBell();
1173  return 0;
1174  }
1175 
1177  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1178  {
1180  },
1181  nullptr, !m_dragging );
1182 
1183  if( selection.Empty() )
1184  return 0;
1185 
1187 
1188  // Flip around the anchor for footprints, and the bounding box center for board items
1189  VECTOR2I modPoint = IsFootprintEditor() ? VECTOR2I( 0, 0 ) : selection.GetCenter();
1190 
1191  // If only one item selected, flip around the selection or item anchor point (instead
1192  // of the bounding box center) to avoid moving the item anchor
1193  if( selection.GetSize() == 1 )
1194  {
1196  modPoint = selection.GetReferencePoint();
1197  else
1198  modPoint = static_cast<BOARD_ITEM*>( selection.GetItem( 0 ) )->GetPosition();
1199  }
1200 
1201  bool leftRight = frame()->Settings().m_FlipLeftRight;
1202 
1203  // When editing footprints, all items have the same parent
1204  if( IsFootprintEditor() )
1205  m_commit->Modify( selection.Front() );
1206 
1207  for( EDA_ITEM* item : selection )
1208  {
1209  if( !item->IsNew() && !IsFootprintEditor() )
1210  m_commit->Modify( item );
1211 
1212  if( item->Type() == PCB_GROUP_T )
1213  {
1214  static_cast<PCB_GROUP*>( item )->RunOnDescendants( [&]( BOARD_ITEM* bItem )
1215  {
1216  m_commit->Modify( bItem );
1217  });
1218  }
1219 
1220  static_cast<BOARD_ITEM*>( item )->Flip( modPoint, leftRight );
1221  }
1222 
1223  if( !m_dragging )
1224  m_commit->Push( _( "Flip" ) );
1225 
1226  if( selection.IsHover() && !m_dragging )
1228 
1230 
1231  if( m_dragging )
1233 
1234  return 0;
1235 }
1236 
1237 
1238 int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
1239 {
1240  if( isRouterActive() )
1241  {
1242  wxBell();
1243  return 0;
1244  }
1245 
1246  std::vector<BOARD_ITEM*> lockedItems;
1247  Activate();
1248 
1249  // get a copy instead of reference (as we're going to clear the selection before removing items)
1250  PCBNEW_SELECTION selectionCopy;
1253 
1254  // If we are in a "Cut" operation, then the copied selection exists already
1255  if( isCut )
1256  {
1257  selectionCopy = m_selectionTool->GetSelection();
1258  }
1259  else
1260  {
1261  selectionCopy = m_selectionTool->RequestSelection(
1262  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1263  {
1265  } );
1266  }
1267 
1268  bool isHover = selectionCopy.IsHover();
1269 
1270  // in "alternative" mode, deletion is not just a simple list of selected items,
1271  // it removes whole tracks, not just segments
1272  if( isAlt && isHover
1273  && ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
1274  {
1276  }
1277 
1278  if( selectionCopy.Empty() )
1279  return 0;
1280 
1281  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
1282  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
1283  // in the copyToClipboard() routine
1284  if( !isCut )
1285  {
1286  // Second RequestSelection removes locked items but keeps a copy of their pointers
1287  selectionCopy = m_selectionTool->RequestSelection(
1288  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1289  {
1290  EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED, sTool );
1291  },
1292  &lockedItems );
1293  }
1294 
1295 
1296  // As we are about to remove items, they have to be removed from the selection first
1298 
1299  for( EDA_ITEM* item : selectionCopy )
1300  {
1301  PCB_GROUP* parentGroup = static_cast<BOARD_ITEM*>( item )->GetParentGroup();
1302 
1303  if( parentGroup )
1304  parentGroup->RemoveItem( static_cast<BOARD_ITEM*>( item ) );
1305 
1306  switch( item->Type() )
1307  {
1308  case PCB_FP_TEXT_T:
1309  {
1310  FP_TEXT* text = static_cast<FP_TEXT*>( item );
1311  FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
1312 
1313  if( text->GetType() == FP_TEXT::TEXT_is_DIVERS )
1314  {
1315  m_commit->Modify( parent );
1316  getView()->Remove( text );
1317  parent->Remove( text );
1318  }
1319  }
1320  break;
1321 
1322  case PCB_PAD_T:
1323  {
1324  PAD* pad = static_cast<PAD*>( item );
1325  FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
1326 
1327  m_commit->Modify( parent );
1328  getView()->Remove( pad );
1329  parent->Remove( pad );
1330  }
1331  break;
1332 
1333  case PCB_FP_ZONE_T:
1334  {
1335  FP_ZONE* zone = static_cast<FP_ZONE*>( item );
1336  FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
1337 
1338  m_commit->Modify( parent );
1339  getView()->Remove( zone );
1340  parent->Remove( zone );
1341  }
1342  break;
1343 
1344  case PCB_ZONE_T:
1345  // We process the zones special so that cutouts can be deleted when the delete tool
1346  // is called from inside a cutout when the zone is selected.
1347  {
1348  // Only interact with cutouts when deleting and a single item is selected
1349  if( !isCut && selectionCopy.GetSize() == 1 )
1350  {
1352  ZONE* zone = static_cast<ZONE*>( item );
1353 
1354  int outlineIdx, holeIdx;
1355 
1356  if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) )
1357  {
1358  // Remove the cutout
1359  m_commit->Modify( zone );
1360  zone->RemoveCutout( outlineIdx, holeIdx );
1361 
1362  std::vector<ZONE*> toFill;
1363  toFill.emplace_back( zone );
1364 
1365  // Fill the modified zone
1366  ZONE_FILLER filler( board(), m_commit.get() );
1367  filler.InstallNewProgressReporter( frame(), _( "Fill Zone" ), 4 );
1368 
1369  if( !filler.Fill( toFill ) )
1370  {
1371  m_commit->Revert();
1372  return 1;
1373  }
1374 
1375  // Update the display
1376  zone->HatchBorder();
1377  canvas()->Refresh();
1378 
1379  // Restore the selection on the original zone
1381 
1382  break;
1383  }
1384  }
1385 
1386  // Remove the entire zone otherwise
1387  m_commit->Remove( item );
1388  }
1389  break;
1390 
1391  case PCB_GROUP_T:
1392  {
1393  PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
1394 
1395  auto removeItem = [&]( BOARD_ITEM* bItem )
1396  {
1397  if( bItem->GetParent() && bItem->GetParent()->Type() == PCB_FOOTPRINT_T )
1398  {
1399  m_commit->Modify( bItem->GetParent() );
1400  getView()->Remove( group );
1401  bItem->GetParent()->Remove( group );
1402  }
1403  else
1404  {
1405  m_commit->Remove( bItem );
1406  }
1407  };
1408 
1409  removeItem( group );
1410 
1411  group->RunOnDescendants( [&]( BOARD_ITEM* aDescendant )
1412  {
1413  removeItem( aDescendant );
1414  });
1415  }
1416  break;
1417 
1418  default:
1419  m_commit->Remove( item );
1420  break;
1421  }
1422  }
1423 
1424  // If the entered group has been emptied then leave it.
1425  PCB_GROUP* enteredGroup = m_selectionTool->GetEnteredGroup();
1426 
1427  if( enteredGroup && enteredGroup->GetItems().empty() )
1429 
1430  if( isCut )
1431  m_commit->Push( _( "Cut" ) );
1432  else
1433  m_commit->Push( _( "Delete" ) );
1434 
1435  if( !m_lockedSelected && !lockedItems.empty() )
1436  {
1438  m_lockedSelected = true;
1439  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &lockedItems );
1440  m_statusPopup->SetText( _( "Locked items cannot be deleted" ) );
1441  m_statusPopup->PopupFor( 2000 );
1442  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
1443 
1444  Activate();
1445 
1446  while( m_lockedSelected && m_statusPopup->IsShown() )
1447  {
1448  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
1449  Wait();
1450  }
1451 
1452  // Ensure statusPopup is hidden after use
1453  m_statusPopup->Hide();
1454  }
1455 
1456  m_lockedSelected = false;
1457 
1458  return 0;
1459 }
1460 
1461 
1462 int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
1463 {
1464  if( isRouterActive() )
1465  {
1466  wxBell();
1467  return 0;
1468  }
1469 
1471  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1472  {
1473  EditToolSelectionFilter( aCollector,
1475  } );
1476 
1477  if( selection.Empty() )
1478  return 0;
1479 
1480  wxPoint translation;
1481  double rotation;
1482  ROTATION_ANCHOR rotationAnchor = selection.Size() > 1 ? ROTATE_AROUND_SEL_CENTER
1484 
1485  // TODO: Implement a visible bounding border at the edge
1486  auto sel_box = selection.GetBoundingBox();
1487 
1488  DIALOG_MOVE_EXACT dialog( frame(), translation, rotation, rotationAnchor, sel_box );
1489  int ret = dialog.ShowModal();
1490 
1491  if( ret == wxID_OK )
1492  {
1493  VECTOR2I rp = selection.GetCenter();
1494  wxPoint selCenter( rp.x, rp.y );
1495 
1496  // Make sure the rotation is from the right reference point
1497  selCenter += translation;
1498 
1499  // When editing footprints, all items have the same parent
1500  if( IsFootprintEditor() )
1501  m_commit->Modify( selection.Front() );
1502 
1503  for( EDA_ITEM* selItem : selection )
1504  {
1505  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selItem );
1506 
1507  if( !item->IsNew() && !IsFootprintEditor() )
1508  {
1509  m_commit->Modify( item );
1510 
1511  if( item->Type() == PCB_GROUP_T )
1512  {
1513  PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
1514 
1515  group->RunOnDescendants( [&]( BOARD_ITEM* bItem )
1516  {
1517  m_commit->Modify( bItem );
1518  });
1519  }
1520  }
1521 
1522  item->Move( translation );
1523 
1524  switch( rotationAnchor )
1525  {
1527  item->Rotate( item->GetPosition(), rotation );
1528  break;
1530  item->Rotate( selCenter, rotation );
1531  break;
1533  item->Rotate( (wxPoint) frame()->GetScreen()->m_LocalOrigin, rotation );
1534  break;
1536  item->Rotate( board()->GetDesignSettings().m_AuxOrigin, rotation );
1537  break;
1538  }
1539 
1540  if( !m_dragging )
1541  getView()->Update( item );
1542  }
1543 
1544  m_commit->Push( _( "Move exact" ) );
1545 
1546  if( selection.IsHover() )
1548 
1550 
1551  if( m_dragging )
1553  }
1554 
1555  return 0;
1556 }
1557 
1558 
1559 int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
1560 {
1561  if( isRouterActive() )
1562  {
1563  wxBell();
1564  return 0;
1565  }
1566 
1567  bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
1568 
1569  // Be sure that there is at least one item that we can modify
1571  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1572  {
1574  } );
1575 
1576  if( selection.Empty() )
1577  return 0;
1578 
1579  // we have a selection to work on now, so start the tool process
1580  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1581 
1582  // If the selection was given a hover, we do not keep the selection after completion
1583  bool is_hover = selection.IsHover();
1584 
1585  std::vector<BOARD_ITEM*> new_items;
1586  new_items.reserve( selection.Size() );
1587 
1588 
1589  // Each selected item is duplicated and pushed to new_items list
1590  // Old selection is cleared, and new items are then selected.
1591  for( EDA_ITEM* item : selection )
1592  {
1593  BOARD_ITEM* dupe_item = nullptr;
1594  BOARD_ITEM* orig_item = static_cast<BOARD_ITEM*>( item );
1595 
1596  if( m_isFootprintEditor )
1597  {
1598  FOOTPRINT* parentFootprint = editFrame->GetBoard()->GetFirstFootprint();
1599  dupe_item = parentFootprint->DuplicateItem( orig_item );
1600 
1601  if( increment && item->Type() == PCB_PAD_T
1602  && PAD_NAMING::PadCanHaveName( *static_cast<PAD*>( dupe_item ) ) )
1603  {
1604  PAD_TOOL* padTool = m_toolMgr->GetTool<PAD_TOOL>();
1605  wxString padName = padTool->GetLastPadName();
1606  padName = parentFootprint->GetNextPadName( padName );
1607  padTool->SetLastPadName( padName );
1608  static_cast<PAD*>( dupe_item )->SetName( padName );
1609  }
1610  }
1611  else if( orig_item->GetParent() && orig_item->GetParent()->Type() == PCB_FOOTPRINT_T )
1612  {
1613  FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( orig_item->GetParent() );
1614 
1615  m_commit->Modify( parentFootprint );
1616  dupe_item = parentFootprint->DuplicateItem( orig_item, true /* add to parent */ );
1617  }
1618  else
1619  {
1620  switch( orig_item->Type() )
1621  {
1622  case PCB_FOOTPRINT_T:
1623  case PCB_TEXT_T:
1624  case PCB_SHAPE_T:
1625  case PCB_TRACE_T:
1626  case PCB_VIA_T:
1627  case PCB_ZONE_T:
1628  case PCB_TARGET_T:
1629  case PCB_DIM_ALIGNED_T:
1630  case PCB_DIM_CENTER_T:
1631  case PCB_DIM_ORTHOGONAL_T:
1632  case PCB_DIM_LEADER_T:
1633  dupe_item = orig_item->Duplicate();
1634  break;
1635 
1636  case PCB_GROUP_T:
1637  dupe_item = static_cast<PCB_GROUP*>( orig_item )->DeepDuplicate();
1638  break;
1639 
1640  default:
1641  // Silently drop other items (such as footprint texts) from duplication
1642  break;
1643  }
1644  }
1645 
1646  if( dupe_item )
1647  {
1648  if( dupe_item->Type() == PCB_GROUP_T )
1649  {
1650  static_cast<PCB_GROUP*>( dupe_item )->RunOnDescendants(
1651  [&]( BOARD_ITEM* bItem )
1652  {
1653  m_commit->Add( bItem );
1654  });
1655  }
1656 
1657  // Clear the selection flag here, otherwise the SELECTION_TOOL
1658  // will not properly select it later on
1659  dupe_item->ClearSelected();
1660 
1661  new_items.push_back( dupe_item );
1662  m_commit->Add( dupe_item );
1663  }
1664  }
1665 
1666  // Clear the old selection first
1668 
1669  // Select the new items
1670  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
1671 
1672  // record the new items as added
1673  if( !selection.Empty() )
1674  {
1675  editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
1676  (int) new_items.size() ) );
1677 
1678  // If items were duplicated, pick them up
1679  // this works well for "dropping" copies around and pushes the commit
1681  Move( evt );
1682 
1683  // After moving the new items, we need to refresh the group and view flags
1685 
1686  if( !is_hover )
1687  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
1688  }
1689 
1690  return 0;
1691 }
1692 
1693 
1695 {
1696  if( isRouterActive() )
1697  {
1698  wxBell();
1699  return 0;
1700  }
1701 
1703  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1704  {
1706  } );
1707 
1708  if( selection.Empty() )
1709  return 0;
1710 
1711  // we have a selection to work on now, so start the tool process
1712  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
1713  ARRAY_CREATOR array_creator( *editFrame, m_isFootprintEditor, selection );
1714  array_creator.Invoke();
1715 
1716  return 0;
1717 }
1718 
1719 
1721 {
1722  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1723  {
1724  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
1725 
1726  if( item->Type() != PCB_PAD_T )
1727  aCollector.Remove( i );
1728  }
1729 }
1730 
1731 
1733 {
1734  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1735  {
1736  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
1737 
1738  if( item->Type() != PCB_FOOTPRINT_T )
1739  aCollector.Remove( i );
1740  }
1741 }
1742 
1743 
1745 {
1746  if( m_dragging && aSelection.HasReferencePoint() )
1747  return false;
1748 
1749  // When there is only one item selected, the reference point is its position...
1750  if( aSelection.Size() == 1 )
1751  {
1752  auto item = static_cast<BOARD_ITEM*>( aSelection.Front() );
1753  auto pos = item->GetPosition();
1754  aSelection.SetReferencePoint( VECTOR2I( pos.x, pos.y ) );
1755  }
1756  // ...otherwise modify items with regard to the grid-snapped cursor position
1757  else
1758  {
1760  aSelection.SetReferencePoint( m_cursor );
1761  }
1762 
1763  return true;
1764 }
1765 
1766 
1767 bool EDIT_TOOL::pickReferencePoint( const wxString& aTooltip, const wxString& aSuccessMessage,
1768  const wxString& aCanceledMessage, VECTOR2I& aReferencePoint )
1769 {
1771  OPT<VECTOR2I> pickedPoint;
1772  bool done = false;
1773 
1774  m_statusPopup->SetText( aTooltip );
1775 
1776  picker->SetClickHandler(
1777  [&]( const VECTOR2D& aPoint ) -> bool
1778  {
1779  pickedPoint = aPoint;
1780 
1781  if( !aSuccessMessage.empty() )
1782  {
1783  m_statusPopup->SetText( aSuccessMessage );
1784  m_statusPopup->Expire( 800 );
1785  }
1786  else
1787  {
1788  m_statusPopup->Hide();
1789  }
1790 
1791  return false; // we don't need any more points
1792  } );
1793 
1794  picker->SetMotionHandler(
1795  [&]( const VECTOR2D& aPos )
1796  {
1797  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1798  } );
1799 
1800  picker->SetCancelHandler(
1801  [&]()
1802  {
1803  if( !aCanceledMessage.empty() )
1804  {
1805  m_statusPopup->SetText( aCanceledMessage );
1806  m_statusPopup->Expire( 800 );
1807  }
1808  else
1809  {
1810  m_statusPopup->Hide();
1811  }
1812  } );
1813 
1814  picker->SetFinalizeHandler(
1815  [&]( const int& aFinalState )
1816  {
1817  done = true;
1818  } );
1819 
1820  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1821  m_statusPopup->Popup();
1822 
1823  std::string tool = "";
1824  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1825 
1826  while( !done )
1827  {
1828  // Pass events unless we receive a null event, then we must shut down
1829  if( TOOL_EVENT* evt = Wait() )
1830  evt->SetPassEvent();
1831  else
1832  break;
1833  }
1834 
1835  // Ensure statusPopup is hidden after use and before deleting it:
1836  m_statusPopup->Hide();
1837 
1838  if( pickedPoint.is_initialized() )
1839  aReferencePoint = pickedPoint.get();
1840 
1841  return pickedPoint.is_initialized();
1842 }
1843 
1844 
1846 {
1847  std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
1848  CLIPBOARD_IO io;
1849  GRID_HELPER grid( m_toolMgr, getEditFrame<PCB_BASE_EDIT_FRAME>()->GetMagneticItemsSettings() );
1850 
1851  frame()->PushTool( tool );
1852  Activate();
1853 
1855  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, SELECTION_TOOL* sTool )
1856  {
1858  sTool );
1859  } );
1860 
1861  if( !selection.Empty() )
1862  {
1863  std::vector<BOARD_ITEM*> items;
1864 
1865  for( EDA_ITEM* item : selection )
1866  items.push_back( static_cast<BOARD_ITEM*>( item ) );
1867 
1868  VECTOR2I refPoint;
1869 
1870  if( aEvent.IsAction( &PCB_ACTIONS::copyWithReference ) )
1871  {
1872  if( !pickReferencePoint( _( "Select reference point for the copy..." ),
1873  _( "Selection copied" ),
1874  _( "Copy cancelled" ),
1875  refPoint ) )
1876  return 0;
1877  }
1878  else
1879  {
1880  refPoint = grid.BestDragOrigin( getViewControls()->GetCursorPosition( false ), items );
1881  }
1882 
1883  selection.SetReferencePoint( refPoint );
1884 
1885  io.SetBoard( board() );
1887  frame()->SetStatusText( _( "Selection copied" ) );
1888  }
1889 
1890  frame()->PopTool( tool );
1891 
1892  return 0;
1893 }
1894 
1895 
1897 {
1898  if( !copyToClipboard( aEvent ) )
1899  {
1900  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
1901  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
1902  // in the copyToClipboard() routine
1903  TOOL_EVENT evt( aEvent.Category(), aEvent.Action(), TOOL_ACTION_SCOPE::AS_GLOBAL );
1905  Remove( evt );
1906  }
1907 
1908  return 0;
1909 }
1910 
1911 
1913 {
1915  Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() );
1916  Go( &EDIT_TOOL::Drag, PCB_ACTIONS::drag45Degree.MakeEvent() );
1918  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );
1919  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCcw.MakeEvent() );
1920  Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
1921  Go( &EDIT_TOOL::Remove, ACTIONS::doDelete.MakeEvent() );
1922  Go( &EDIT_TOOL::Remove, PCB_ACTIONS::deleteFull.MakeEvent() );
1926  Go( &EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
1929  Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
1932 
1933  Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() );
1935  Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
1936 }
1937 
1938 
static TOOL_ACTION selectItems
Selects a list of items (specified as the event parameter)
Definition: pcb_actions.h:69
long long GetValue()
Returns the value in internal units.
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:62
bool IsLocked() const override
Function IsLocked.
Definition: track.h:136
VECTOR2I GetReferencePoint() const
Definition: selection.h:257
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:101
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
void setTransitions() override
Sets up handlers for various events.
Definition: edit_tool.cpp:1912
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Adds a submenu to the menu.
BOARD_ITEM * DuplicateItem(const BOARD_ITEM *aItem, bool aAddToFootprint=false)
Function DuplicateItem Duplicate a given item within the footprint, optionally adding it to the board...
Definition: footprint.cpp:1475
VECTOR2I m_cursor
Definition: edit_tool.h:211
void ClearReferencePoint()
Definition: selection.h:267
bool IsLocked() const override
Function IsLocked.
Definition: footprint.h:291
void FlipPrimitives(bool aFlipLeftRight)
Flip (mirror) the primitives left to right or top to bottom, around the anchor position in custom pad...
Definition: pcbnew/pad.cpp:599
bool IsCurrentTool(const TOOL_ACTION &aAction) const
void SetOffset(const wxPoint &aOffset)
Definition: pad.h:242
int Properties(const TOOL_EVENT &aEvent)
Function Properties() Displays properties window for the selected object.
Definition: edit_tool.cpp:920
int Rotate(const TOOL_EVENT &aEvent)
Function Rotate() Rotates currently selected items.
Definition: edit_tool.cpp:967
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:95
static TOOL_ACTION deleteFull
Definition: pcb_actions.h:130
class ALIGNED_DIMENSION, a linear dimension (graphic item)
Definition: typeinfo.h:101
class LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:102
void RemoveCutout(int aOutlineIdx, int aHoleIdx)
Remove a cutout from the zone.
Definition: zone.cpp:787
bool IsHover() const
Definition: selection.h:70
class FP_TEXT, text in a footprint
Definition: typeinfo.h:93
static const KICAD_T Tracks[]
A scan list for only TRACKs.
Definition: collectors.h:299
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Function GetMousePosition() Returns the current mouse pointer position.
BOARD * board() const
static TOOL_ACTION editFpInFpEditor
Definition: pcb_actions.h:340
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
static TOOL_ACTION pageSettings
Definition: actions.h:59
void Redraw3Dview()
Request a redraw of 3D-Viewer canvas.
REMOVE_FLAGS
Remove event modifier flags
Definition: actions.h:196
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
static TOOL_ACTION changeTrackWidth
Updates selected tracks & vias to the current track & via dimensions.
Definition: pcb_actions.h:114
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags, SELECTION_TOOL *selectionTool)
Definition: edit_tool.cpp:66
virtual void SetLayer(PCB_LAYER_ID aLayer)
Function SetLayer sets the layer this item is on.
Definition: board_item.h:206
This file is part of the common library.
static TOOL_ACTION doDelete
Definition: actions.h:75
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
Definition: board_item.h:86
void SetEnd(const wxPoint &aEnd)
Definition: track.h:112
bool HasType(KICAD_T aType) const
Checks if there is at least one item of requested kind.
Definition: selection.h:231
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:109
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:213
void ClearSelected()
Definition: eda_item.h:199
NETINFO_ITEM * GetNet() const
Function GetNet Returns NET_INFO object for a given item.
const wxPoint & GetStart() const
Definition: track.h:116
VIEW_CONTROLS class definition.
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
Definition: pcb_group.h:50
TOOL_ACTIONS Action() const
Returns more specific information about the type of an event.
Definition: tool_event.h:250
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Creates a functor that tests if the selected items are only of given types.
SELECTION_TOOL.
class CENTER_DIMENSION, a center point marking (graphic item)
Definition: typeinfo.h:103
int ChangeTrackWidth(const TOOL_EVENT &aEvent)
Definition: edit_tool.cpp:661
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.h:137
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:141
Tool is invoked after being inactive.
Definition: tool_base.h:81
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
ITER end()
Definition: selection.h:61
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
PAD_TOOL.
Definition: pad_tool.h:37
void ShowInfoBarMsg(const wxString &aMsg)
TOOL_MENU & GetToolMenu()
class PCB_TEXT, text on a layer
Definition: typeinfo.h:92
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION selectConnection
Selects tracks between junctions or expands an existing selection to pads or the entire connection.
Definition: pcb_actions.h:77
class ARC, an arc track segment on a copper layer
Definition: typeinfo.h:98
static TOOL_ACTION getAndPlace
Find an item and start moving.
Definition: pcb_actions.h:459
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:559
void SaveSelection(const PCBNEW_SELECTION &selected, bool isFootprintEditor)
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:140
TOOL_EVENT_CATEGORY Category() const
Returns the category (eg. mouse/keyboard/action) of an event..
Definition: tool_event.h:247
static TOOL_ACTION mirror
Mirroring of selected items.
Definition: pcb_actions.h:111
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Moves cursor to the requested position expressed in world coordinates.
static TOOL_ACTION changeFootprint
Definition: pcb_actions.h:320
static void mirrorPadX(PAD &aPad, const wxPoint &aMirrorPoint)
Mirror a pad in the vertical axis passing through a point (mirror left to right)
Definition: edit_tool.cpp:1048
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:94
class PAD, a pad in a footprint
Definition: typeinfo.h:90
PAD_SHAPE_T GetShape() const
Definition: pad.h:159
static TOOL_ACTION updateFootprint
Definition: pcb_actions.h:318
void UndoRedoBlock(bool aBlock=true)
Function UndoRedoBlock Enables/disable undo and redo operations.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
TOOL_BASE * FindTool(int aId) const
Function FindTool() Searches for a tool with given ID.
virtual wxPoint GetPosition() const
Definition: eda_item.h:325
void SetDelta(const wxSize &aSize)
Definition: pad.h:232
SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:208
static SELECTION_CONDITION Count(int aNumber)
Creates a functor that tests if the number of selected items is equal to the value given as parameter...
const std::unordered_set< BOARD_ITEM * > & GetItems() const
Definition: pcb_group.h:68
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void SetBoard(BOARD *aBoard)
static bool NotEmpty(const SELECTION &aSelection)
Tests if there are any items selected.
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
void Mirror(const wxPoint &aCentre, bool aMirrorAroundXAxis)
Mirror text position in footprint editing the text itself is not mirrored, and the layer not modified...
Definition: fp_text.cpp:172
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Function SetFinalizeHandler() Sets a handler for the finalize event.
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:133
void SetCurrentCursor(KICURSOR cursor)
Function SetCurrentCursor Set the current cursor shape for this panel.
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:213
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:96
int Mirror(const TOOL_EVENT &aEvent)
Function Mirror Mirrors the current selection.
Definition: edit_tool.cpp:1070
PADS & Pads()
Definition: footprint.h:182
void InstallNewProgressReporter(wxWindow *aParent, const wxString &aTitle, int aNumPhases)
Definition: zone_filler.cpp:72
const VC_SETTINGS & GetSettings() const
Returns the current VIEW_CONTROLS settings
bool IsNew() const
Definition: eda_item.h:187
void SetWidth(int aWidth)
Definition: track.h:109
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:67
static TOOL_ACTION moveExact
Activation of the exact move tool.
Definition: pcb_actions.h:123
int cutToClipboard(const TOOL_EVENT &aEvent)
Function cutToClipboard() Cuts the current selection to the clipboard by formatting it as a fake pcb ...
Definition: edit_tool.cpp:1896
bool pickReferencePoint(const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
Definition: edit_tool.cpp:1767
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
static TOOL_ACTION pickerTool
Definition: actions.h:153
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:123
const LSET GetSelectionLayers()
static TOOL_ACTION filletTracks
Fillets (i.e. adds an arc tangent to) all selected straight tracks by a user defined radius.
Definition: pcb_actions.h:117
PCB_BASE_EDIT_FRAME * frame() const
bool m_lockedSelected
Definition: edit_tool.h:210
bool HitTestCutout(const VECTOR2I &aRefPos, int *aOutlineIdx=nullptr, int *aHoleIdx=nullptr) const
Tests if the given point is contained within a cutout of the zone.
Definition: zone.cpp:497
void SetParameter(T aParam)
Function SetParameter() Sets a non-standard parameter assigned to the event.
Definition: tool_event.h:453
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:104
ITER begin()
Definition: selection.h:60
static TOOL_ACTION copy
Definition: actions.h:70
int Flip(const TOOL_EVENT &aEvent)
Function Flip() Rotates currently selected items.
Definition: edit_tool.cpp:1168
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:262
static TOOL_ACTION duplicateIncrement
Activation of the duplication tool with incrementing (e.g. pad number)
Definition: pcb_actions.h:126
bool HitTestWorksheetItems(VIEW *aView, const wxPoint &aPosition)
const wxPoint & GetOffset() const
Definition: pad.h:243
bool isInteractiveDragEnabled() const
Definition: edit_tool.cpp:281
int GetAndPlace(const TOOL_EVENT &aEvent)
Find an item and start moving.
Definition: edit_tool.cpp:235
Generic tool for picking a point.
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:104
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, std::vector< BOARD_ITEM * > &aItem)
LSET is a set of PCB_LAYER_IDs.
const PCBNEW_SELECTION & selection() const
void SetLastPadName(const wxString &aPadName)
Definition: pad_tool.h:67
FOOTPRINT * GetFirstFootprint() const
Gets the first footprint on the board or nullptr.
Definition: board.h:348
#define NULL
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in a variety of units (the basic call r...
Definition: pad.h:334
An extension of WX_TEXT_ENTRY_DIALOG that uses UNIT_BINDER to request a dimension (e....
int doMoveSelection(TOOL_EVENT aEvent, bool aPickReference=false)
Definition: edit_tool.cpp:342
wxString GetLastPadName() const
Definition: pad_tool.h:66
bool m_dragging
Definition: edit_tool.h:209
virtual EDA_RECT GetBoundingBox() const
Definition: selection.h:178
void HatchBorder()
Function HatchBorder computes the hatch lines depending on the hatch parameters and stores it in the ...
Definition: zone.cpp:924
TEXT_TYPE GetType() const
Definition: fp_text.h:139
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, SELECTION_TOOL *sTool)
Function FootprintFilter() A selection filter which prunes the selection to contain only items of typ...
Definition: edit_tool.cpp:1732
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
Definition: board_item.h:292
virtual void PopTool(const std::string &actionName)
int ShowQuasiModal()
SELECTION_LOCK_FLAGS
Definition: selection.h:296
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
bool PadCanHaveName(const PAD &aPad)
Check if a pad should be named.
Definition: pad_naming.cpp:26
const VECTOR2I & GetP0() const
Definition: shape_arc.h:85
void SetIcon(const BITMAP_OPAQUE *aIcon)
Assigns an icon for the entry.
Definition: action_menu.cpp:71
TOOL_EVENT.
Definition: tool_event.h:171
void AddItemToSel(BOARD_ITEM *aItem, bool aQuietMode=false)
static TOOL_ACTION createArray
Tool for creating an array of objects.
Definition: pcb_actions.h:383
bool Contains(EDA_ITEM *aItem) const
Definition: selection.h:112
FOOTPRINT * footprint() const
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:382
static TOOL_ACTION cut
Definition: actions.h:69
void FilterCollectorForGroups(GENERAL_COLLECTOR &aCollector) const
bool ToolStackIsEmpty()
Definition: tools_holder.h:136
bool HasItem(const EDA_ITEM *aItem) const
Function HasItem tests if aItem has already been collected.
Definition: collector.h:219
int FilletTracks(const TOOL_EVENT &aEvent)
Function FilletTracks() Fillets (i.e.
Definition: edit_tool.cpp:717
static const int MIN_PRECISION_IU
This is the minimum precision for all the points in the arc shape.
Definition: shape_arc.h:41
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: edit_tool.cpp:157
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
int MoveWithReference(const TOOL_EVENT &aEvent)
Moves an item but with a reference point selected first.
Definition: edit_tool.cpp:328
int Drag(const TOOL_EVENT &aEvent)
Function Drag() Invoke the PNS router to drag tracks.
Definition: edit_tool.cpp:297
void SetX0(int x)
Definition: pad.h:223
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
bool RemoveItem(BOARD_ITEM *aItem)
Removes item from group.
Definition: pcb_group.cpp:50
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition: edit_tool.h:215
ZONE handles a list of polygons defining a copper zone.
Definition: zone.h:57
class ZONE, a copper pour area
Definition: typeinfo.h:106
static const TOOL_EVENT SelectedItemsMoved
Definition: actions.h:216
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Function Rotate Rotate this object.
Definition: board_item.h:309
void RunOnDescendants(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invokes a function on all descendents of the group.
Definition: pcb_group.cpp:327
All active tools
Definition: tool_event.h:147
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.h:104
static TOOL_ACTION copyWithReference
copy command with manual reference point selection
Definition: pcb_actions.h:101
ROTATION_ANCHOR
bool m_isFootprintEditor
#define INCLUDE_PADS_AND_FOOTPRINTS
Definition: edit_tool.h:56
static TOOL_ACTION routerInlineDrag
Activation of the Push and Shove router (inline dragging mode)
Definition: pcb_actions.h:205
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:452
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
int Move(const TOOL_EVENT &aEvent)
Function Move() Main loop in which events are handled.
Definition: edit_tool.cpp:316
#define EXCLUDE_TRANSIENTS
Definition: edit_tool.h:55
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:105
static TOOL_ACTION inlineBreakTrack
Breaks track when router is not activated.
Definition: pcb_actions.h:138
class FOOTPRINT, a footprint
Definition: typeinfo.h:89
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
Definition: edit_tool.cpp:133
BOARD * GetBoard()
void AddSeparator(int aOrder=ANY_ORDER)
Adds a separator to the menu.
virtual unsigned int GetSize() const override
Function GetSize() Returns the number of stored items.
Definition: selection.h:99
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:105
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
const wxSize & GetDelta() const
Definition: pad.h:233
int MoveExact(const TOOL_EVENT &aEvent)
Function MoveExact() Invokes a dialog box to allow moving of the item by an exact amount.
Definition: edit_tool.cpp:1462
Definition: seg.h:39
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
int Remove(const TOOL_EVENT &aEvent)
Function Remove() Deletes currently selected items.
Definition: edit_tool.cpp:1238
static ROUTER * theRouter
Definition: pns_router.cpp:57
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:108
SPECIAL_TOOLS_CONTEXT_MENU(TOOL_INTERACTIVE *aTool)
Definition: edit_tool.cpp:144
int GetCurrentViaSize() const
Function GetCurrentViaSize.
NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
virtual bool IsLocked() const
Function IsLocked.
Definition: board_item.h:259
bool invokeInlineRouter(int aDragMode)
Definition: edit_tool.cpp:253
void Remove(BOARD_ITEM *aItem) override
Definition: footprint.cpp:495
bool HasReferencePoint() const
Definition: selection.h:252
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
PCB_GROUP * GetEnteredGroup()
void SetNet(NETINFO_ITEM *aNetInfo)
Function SetNet Sets a NET_INFO object for the item.
void SetTitle(const wxString &aTitle) override
Sets title for the menu.
Definition: action_menu.cpp:89
int CreateArray(const TOOL_EVENT &aEvent)
Function CreateArray() Creates an array of the selected items, invoking the array editor dialog to se...
Definition: edit_tool.cpp:1694
KIGFX::WS_PROXY_VIEW_ITEM * GetWorksheet() const
PCBNEW_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=nullptr, bool aConfirmLockedItems=false)
Function RequestSelection()
KIGFX::VIEW_CONTROLS * controls() const
int GetWidth() const
Definition: track.h:110
STATUS_FLAGS IsPointOnEnds(const wxPoint &point, int min_dist=0) const
Function IsPointOnEnds returns STARTPOINT if point if near (dist = min_dist) start point,...
Definition: track.cpp:185
Common, abstract interface for edit frames.
wxPoint GetPosition() const override
Definition: pad.h:167
Definition: track.h:272
int GetNet() const
Function GetNet.
Definition: netinfo.h:223
#define _(s)
Definition: 3d_actions.cpp:33
long m_lastKeyboardCursorCommand
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
wxString GetNextPadName(const wxString &aLastPadName) const
Function GetNextPadName returns the next available pad name in the footprint.
Definition: footprint.cpp:1560
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:241
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Function CreateSubMenu.
Definition: tool_menu.cpp:52
static void PadFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, SELECTION_TOOL *sTool)
Function PadFilter() A selection filter which prunes the selection to contain only items of type PCB_...
Definition: edit_tool.cpp:1720
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
bool IsToolActive() const
Definition: tool_base.cpp:31
void SetPosition(const wxPoint &aPos) override
Definition: pad.h:161
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:65
void Mirror(const wxPoint &aCentre, bool aMirrorAroundXAxis)
Mirror an edge of the footprint.
Definition: fp_shape.cpp:233
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Creates a functor that tests if the selected items are only of given type.
class ZONE, managed by a footprint
Definition: typeinfo.h:95
PCBNEW_SETTINGS & Settings()
TOOL_EVENT MakeEvent() const
Returns the event associated with the action (i.e.
Definition: tool_action.h:113
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
bool isRouterActive() const
Definition: edit_tool.cpp:289
void Mirror(const wxPoint &aMirrorRef, bool aMirrorLeftRight)
Function Mirror Mirror the outlines , relative to a given horizontal axis the layer is not changed.
Definition: zone.cpp:742
EDA_ITEM is a base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:148
bool IsFootprintEditor() const
static wxPoint mirrorPointX(const wxPoint &aPoint, const wxPoint &aMirrorPoint)
Definition: edit_tool.cpp:1033
void SetMotionHandler(MOTION_HANDLER aHandler)
Function SetMotionHandler() Sets a handler for mouse motion.
static TOOL_ACTION positionRelative
Activation of the position relative tool.
Definition: pcb_actions.h:232
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
const wxPoint & GetEnd() const
Definition: track.h:113
int GetMicroViaDrillSize()
Function GetViaDrillSize returns the size of via drills used to route this net.
Definition: netinfo.h:188
boost::optional< T > OPT
Definition: optional.h:7
virtual double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: track.h:151
bool GetMoveWarpsCursor() const
Indicates that a move operation should warp the mouse pointer to the origin of the move object.
Definition: tools_holder.h:159
void Activate()
Function Activate() Runs the tool.
void SetStart(const wxPoint &aStart)
Definition: track.h:115
virtual BOARD_ITEM * Duplicate() const
Function Duplicate creates a copy of a BOARD_ITEM.
Definition: board_item.h:215
class ORTHOGONAL_DIMENSION, a linear dimension constrained to x/y
Definition: typeinfo.h:104
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
T EuclideanNorm() const
Destructor.
Definition: vector2d.h:299
static TOOL_ACTION undo
Definition: actions.h:67
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
#define EXCLUDE_LOCKED
Function EditToolSelectionFilter.
Definition: edit_tool.h:53
int copyToClipboard(const TOOL_EVENT &aEvent)
Function copyToClipboard() Sends the current selection to the clipboard by formatting it as a fake pc...
Definition: edit_tool.cpp:1845
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:453
BOARD * GetBoard() const
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
ROUTER * Router() const
Definition: pad.h:59
bool PadsLocked() const
Definition: footprint.h:327
#define EXCLUDE_LOCKED_PADS
Definition: edit_tool.h:54
PCB_DRAW_PANEL_GAL * canvas() const
int GetMicroViaSize()
Function GetMicroViaSize returns the size of vias used to route this net.
Definition: netinfo.h:168
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:179
static TOOL_ACTION moveWithReference
move with a reference point
Definition: pcb_actions.h:98
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
bool updateModificationPoint(PCBNEW_SELECTION &aSelection)
Returns the right modification point (e.g.
Definition: edit_tool.cpp:1744
void SetCancelHandler(CANCEL_HANDLER aHandler)
Function SetCancelHandler() Sets a handler for cancel events (ESC or context-menu Cancel).
void PostEvent(const TOOL_EVENT &aEvent)
Puts an event to the event queue to be processed at the end of event processing cycle.
Definition: tool_manager.h:274
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:91
int Duplicate(const TOOL_EVENT &aEvent)
Function Duplicate() Duplicates the current selection and starts a move action.
Definition: edit_tool.cpp:1559
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Adds a menu entry to run a TOOL_ACTION on selected items.
virtual PCB_LAYER_ID GetLayer() const
Function GetLayer returns the primary layer this item is on.
Definition: board_item.h:185
static TOOL_ACTION selectAll
Definition: actions.h:73
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:200
bool IsEmpty() const
Definition: board.h:329
const VECTOR2I & GetP1() const
Definition: shape_arc.h:86
static TOOL_ACTION paste
Definition: actions.h:71
FP_ZONE is a specialization of ZONE for use in footprints.
Definition: zone.h:969
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static TOOL_ACTION duplicate
Definition: actions.h:74
Definition: track.h:83
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: pcbnew/pad.cpp:531
static TOOL_ACTION refreshPreview
Definition: actions.h:104
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:201
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
void DisplayToolMsg(const wxString &msg) override
const BITMAP_OPAQUE options_board_xpm[1]
KICAD_T Type() const
Function Type()
Definition: eda_item.h:181
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:402
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.