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-2019 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 <class_board.h>
29 #include <class_module.h>
30 #include <class_edge_mod.h>
31 #include <collectors.h>
32 #include <pcb_edit_frame.h>
33 #include <kiway.h>
34 #include <footprint_edit_frame.h>
35 #include <array_creator.h>
36 #include <status_popup.h>
37 #include <tool/tool_manager.h>
38 #include <tools/pcb_actions.h>
39 #include <tools/selection_tool.h>
40 #include <tools/edit_tool.h>
42 #include <tools/tool_event_utils.h>
43 #include <tools/grid_helper.h>
44 #include <view/view_controls.h>
46 #include <confirm.h>
47 #include <bitmaps.h>
48 #include <cassert>
49 #include <functional>
50 using namespace std::placeholders;
51 #include "kicad_clipboard.h"
52 #include <router/router_tool.h>
56 #include <board_commit.h>
57 
58 
59 void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags )
60 {
61  // Iterate from the back so we don't have to worry about removals.
62  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
63  {
64  BOARD_ITEM* item = aCollector[ i ];
65 
66  if( ( aFlags & EXCLUDE_LOCKED ) && item->IsLocked() )
67  {
68  aCollector.Remove( item );
69  }
70  else if( item->Type() == PCB_PAD_T )
71  {
72  MODULE* mod = static_cast<MODULE*>( item->GetParent() );
73 
74  // case 1: handle locking
75  if( ( aFlags & EXCLUDE_LOCKED ) && mod && mod->IsLocked() )
76  {
77  aCollector.Remove( item );
78  }
79  else if( ( aFlags & EXCLUDE_LOCKED_PADS ) && mod && mod->PadsLocked() )
80  {
81  // Pad locking is considerably "softer" than item locking
82  aCollector.Remove( item );
83 
84  if( !mod->IsLocked() && !aCollector.HasItem( mod ) )
85  aCollector.Append( mod );
86  }
87 
88  // case 2: selection contains both the module and its pads - remove the pads
89  if( mod && aCollector.HasItem( mod ) )
90  aCollector.Remove( item );
91  }
92  else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T )
93  {
94  aCollector.Remove( item );
95  }
96  }
97 }
98 
99 
101  PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
102  m_selectionTool( NULL ),
103  m_dragging( false ),
104  m_lockedSelected( false )
105 {
106 }
107 
108 
110 {
111  m_dragging = false;
112 
113  if( aReason != RUN )
114  m_commit.reset( new BOARD_COMMIT( this ) );
115 }
116 
117 
119 {
120  // Find the selection tool, so they can cooperate
121  m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
122  wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
123 
124  auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) {
125  return m_editModules;
126  };
127 
128  auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
130 
131  auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
132  return frame()->ToolStackIsEmpty();
133  };
134 
135  // Add context menu entries that are displayed when selection tool is active
137 
149 
154  menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
155 
156  menu.AddSeparator();
159  // Selection tool handles the context menu for some other tools, such as the Picker.
160  // Don't add things like Paste when another tool is active.
161  menu.AddItem( ACTIONS::paste, noActiveToolCondition );
162 
163  // Footprint actions
164  menu.AddSeparator();
165  menu.AddItem( PCB_ACTIONS::editFootprintInFpEditor, singleModuleCondition );
166  menu.AddItem( PCB_ACTIONS::updateFootprint, singleModuleCondition );
167  menu.AddItem( PCB_ACTIONS::changeFootprint, singleModuleCondition );
168 
169  // Populate the context menu displayed during the edit tool (primarily the measure tool)
170  auto activeToolCondition = [ this ] ( const SELECTION& aSel ) {
171  return frame()->ToolStackIsEmpty();
172  };
173 
174  auto frame = getEditFrame<PCB_BASE_FRAME>();
175  auto& ctxMenu = m_menu.GetMenu();
176 
177  // "Cancel" goes at the top of the context menu when a tool is active
178  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
179  ctxMenu.AddSeparator( 1 );
180 
181  if( frame )
183 
184  return true;
185 }
186 
187 
188 int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
189 {
190  SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
191  MODULE* module = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
192 
193  if( module )
194  {
197 
198  selectionTool->GetSelection().SetReferencePoint( module->GetPosition() );
200  }
201 
202  return 0;
203 }
204 
205 
206 bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
207 {
209 
210  if( !theRouter )
211  return false;
212 
213  // make sure we don't accidentally invoke inline routing mode while the router is already active!
214  if( theRouter->IsToolActive() )
215  return false;
216 
217  if( theRouter->CanInlineDrag() )
218  {
220  return true;
221  }
222 
223  return false;
224 }
225 
226 
228 {
229  auto theRouter = static_cast<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
230 
231  return theRouter ? theRouter->Router()->Settings().InlineDragEnabled() : false;
232 }
233 
234 
235 int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
236 {
237  int mode = PNS::DM_ANY;
238 
239  if( aEvent.IsAction( &PCB_ACTIONS::dragFreeAngle ) )
240  mode |= PNS::DM_FREE_ANGLE;
241 
242  invokeInlineRouter( mode );
243 
244  return 0;
245 }
246 
247 int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
248 {
250  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
251  VECTOR2I originalCursorPos = controls->GetCursorPosition();
252 
253  // Be sure that there is at least one item that we can modify. If nothing was selected before,
254  // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
256  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
257  {
259  } );
260 
261  if( m_dragging || selection.Empty() )
262  return 0;
263 
264  LSET item_layers = selection.GetSelectionLayers();
265  bool unselect = selection.IsHover(); //N.B. This must be saved before the re-selection below
266 
267  // Now filter out locked pads. We cannot do this in the first RequestSelection() as we need
268  // the item_layers when a pad is the selection front (ie: will become curr_tiem).
270  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
271  {
273  } );
274 
275  if( selection.Empty() )
276  return 0;
277 
278  std::string tool = aEvent.GetCommandStr().get();
279  editFrame->PushTool( tool );
280  Activate();
281  controls->ShowCursor( true );
282  controls->SetAutoPan( true );
283 
284  std::vector<BOARD_ITEM*> sel_items;
285 
286  for( EDA_ITEM* item : selection )
287  {
288  BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
289  MODULE* module = dynamic_cast<MODULE*>( item );
290 
291  if( boardItem )
292  sel_items.push_back( boardItem );
293 
294  if( module )
295  {
296  for( D_PAD* pad : module->Pads() )
297  sel_items.push_back( pad );
298  }
299  }
300 
301  bool restore_state = false;
302  VECTOR2I totalMovement;
303  GRID_HELPER grid( editFrame );
304  TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
305  VECTOR2I prevPos;
306 
307  // Prime the pump
309 
310  // Main loop: keep receiving events
311  do
312  {
313  editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
314  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
315  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
316  controls->SetSnapping( !evt->Modifier( MD_ALT ) );
317 
318  if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() ||
319  evt->IsAction( &PCB_ACTIONS::drag ) || evt->IsDrag( BUT_LEFT ) ||
321  {
322  if( m_dragging && evt->Category() == TC_MOUSE )
323  {
324  VECTOR2I mousePos( controls->GetMousePosition() );
325 
326  m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items );
327 
329  {
331 
332  // The arrow keys are by definition SINGLE AXIS. Do not allow the other
333  // axis to be snapped to the grid.
334  if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
335  m_cursor.y = prevPos.y;
336  else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
337  m_cursor.x = prevPos.x;
338  }
339 
342 
343  VECTOR2I movement( m_cursor - prevPos );
344  prevPos = m_cursor;
345  totalMovement += movement;
346 
347  // Drag items to the current cursor position
348  for( EDA_ITEM* item : sel_items )
349  {
350  // Don't double move footprint pads, fields, etc.
351  if( !item->GetParent() || !item->GetParent()->IsSelected() )
352  static_cast<BOARD_ITEM*>( item )->Move( movement );
353  }
354 
355  frame()->UpdateMsgPanel();
356  }
357  else if( !m_dragging ) // Prepare to start dragging
358  {
360  {
362  break;
363  }
364 
365  // deal with locked items (override lock or abort the operation)
367 
368  if( lockFlags == SELECTION_LOCKED )
369  break;
370 
371  m_dragging = true;
372 
373  // When editing modules, all items have the same parent
374  if( EditingModules() )
375  {
376  m_commit->Modify( selection.Front() );
377  }
378  else
379  {
380  // Save items, so changes can be undone
381  for( EDA_ITEM* item : selection )
382  {
383  // Don't double move footprint pads, fields, etc.
384  if( item->GetParent() && item->GetParent()->IsSelected() )
385  continue;
386 
387  m_commit->Modify( item );
388  }
389  }
390 
391  editFrame->UndoRedoBlock( true );
393 
395  {
396  // start moving with the reference point attached to the cursor
397  grid.SetAuxAxes( false );
398 
399  auto delta = m_cursor - selection.GetReferencePoint();
400 
401  // Drag items to the current cursor position
402  for( EDA_ITEM* item : selection )
403  {
404  // Don't double move footprint pads, fields, etc.
405  if( item->GetParent() && item->GetParent()->IsSelected() )
406  continue;
407 
408  static_cast<BOARD_ITEM*>( item )->Move( delta );
409  }
410 
412  }
413  else
414  {
415  std::vector<BOARD_ITEM*> items;
416 
417  for( EDA_ITEM* item : selection )
418  items.push_back( static_cast<BOARD_ITEM*>( item ) );
419 
420  // Set the current cursor position to the first dragged item origin, so the
421  // movement vector could be computed later
422  m_cursor = grid.BestDragOrigin( originalCursorPos, items );
424  grid.SetAuxAxes( true, m_cursor );
425  }
426 
428 
429  prevPos = m_cursor;
430  controls->SetAutoPan( true );
431  }
432 
435  }
436 
437  else if( evt->IsCancelInteractive() || evt->IsActivate() )
438  {
439  restore_state = true; // Canceling the tool means that items have to be restored
440  break; // Finish
441  }
442 
443  else if( evt->IsAction( &ACTIONS::undo ) )
444  {
445  restore_state = true; // Perform undo locally
446  break; // Finish
447  }
448 
449  // Dispatch TOOL_ACTIONs
450  else if( evt->Category() == TC_COMMAND )
451  {
452  if( evt->IsAction( &ACTIONS::doDelete ) )
453  {
454  break; // finish -- there is no further processing for removed items
455  }
456  else if( evt->IsAction( &ACTIONS::duplicate ) )
457  {
458  break; // finish -- Duplicate tool will start a new Move with the dup'ed items
459  }
460  else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
461  {
462  // Reset positions so the Move Exactly is from the start.
463  for( EDA_ITEM* item : selection )
464  {
465  BOARD_ITEM* i = static_cast<BOARD_ITEM*>( item );
466  i->Move( -totalMovement );
467  }
468 
469  break; // finish -- we moved exactly, so we are finished
470  }
471  }
472 
473  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
474  {
475  break; // finish
476  }
477 
478  else
479  {
480  evt->SetPassEvent();
481  }
482 
483  } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
484 
485  m_lockedSelected = false;
486  controls->ForceCursorPosition( false );
487  controls->ShowCursor( false );
488  controls->SetSnapping( false );
489  controls->SetAutoPan( false );
490 
491  m_dragging = false;
492  editFrame->UndoRedoBlock( false );
493 
494  // Discard reference point when selection is "dropped" onto the board (ie: not dragging anymore)
496 
497  if( unselect )
499 
500  // If canceled, we need to remove the dynamic ratsnest from the screen
501  if( restore_state )
502  {
504  m_commit->Revert();
505  }
506  else
507  {
508  m_commit->Push( _( "Drag" ) );
509  }
510 
511  editFrame->PopTool( tool );
512  return 0;
513 }
514 
516 {
518  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
519  { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
520 
521  for( EDA_ITEM* item : selection )
522  {
523  if( auto via = dyn_cast<VIA*>( item ) )
524  {
525  m_commit->Modify( item );
526 
527  int new_width;
528  int new_drill;
529 
530  if( via->GetViaType() == VIATYPE::MICROVIA )
531  {
532  auto net = via->GetNet();
533 
534  new_width = net->GetMicroViaSize();
535  new_drill = net->GetMicroViaDrillSize();
536  }
537  else
538  {
539  new_width = board()->GetDesignSettings().GetCurrentViaSize();
540  new_drill = board()->GetDesignSettings().GetCurrentViaDrill();
541  }
542 
543  via->SetDrill( new_drill );
544  via->SetWidth( new_width );
545  }
546  else if ( auto track = dyn_cast<TRACK*>( item ) )
547  {
548  m_commit->Modify( item );
549 
550  int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
551  track->SetWidth( new_width );
552  }
553  }
554 
555  m_commit->Push( _("Edit track width/via size") );
556 
557  if( selection.IsHover() )
558  {
560 
561  // Notify other tools of the changes -- This updates the visual ratsnest
563  }
564 
565  return 0;
566 }
567 
568 
569 int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
570 {
571  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
572 
574  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
575  { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
576 
577  // Tracks & vias are treated in a special way:
579  {
580  DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
581  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
582  }
583  else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected
584  {
585  // Display properties dialog
586  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
587 
588  // Do not handle undo buffer, it is done by the properties dialogs
589  editFrame->OnEditItemRequest( item );
590 
591  // Notify other tools of the changes
593  }
594 
595  if( selection.IsHover() )
596  {
598 
599  // Notify other tools of the changes -- This updates the visual ratsnest
601  }
602 
603  return 0;
604 }
605 
606 
607 int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
608 {
609  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
610 
612  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
613  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
614 
615  if( selection.Empty() )
616  return 0;
617 
619  auto refPt = selection.GetReferencePoint();
620  const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
621 
622  // When editing modules, all items have the same parent
623  if( EditingModules() )
624  m_commit->Modify( selection.Front() );
625 
626  for( auto item : selection )
627  {
628  if( !item->IsNew() && !EditingModules() )
629  m_commit->Modify( item );
630 
631  static_cast<BOARD_ITEM*>( item )->Rotate( refPt, rotateAngle );
632  }
633 
634  if( !m_dragging )
635  m_commit->Push( _( "Rotate" ) );
636 
637  if( selection.IsHover() && !m_dragging )
639 
641 
642  if( m_dragging )
644 
645  return 0;
646 }
647 
648 
652 static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint )
653 {
654  wxPoint mirrored = aPoint;
655 
656  mirrored.x -= aMirrorPoint.x;
657  mirrored.x = -mirrored.x;
658  mirrored.x += aMirrorPoint.x;
659 
660  return mirrored;
661 }
662 
663 
667 static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
668 {
669  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
670 
671  if( aPad.GetShape() == PAD_SHAPE_CUSTOM )
672  aPad.MirrorXPrimitives( tmpPt.x );
673 
674  aPad.SetPosition( tmpPt );
675 
676  aPad.SetX0( aPad.GetPosition().x );
677 
678  tmpPt = aPad.GetOffset();
679  tmpPt.x = -tmpPt.x;
680  aPad.SetOffset( tmpPt );
681 
682  auto tmpz = aPad.GetDelta();
683  tmpz.x = -tmpz.x;
684  aPad.SetDelta( tmpz );
685 
686  aPad.SetOrientation( -aPad.GetOrientation() );
687 }
688 
689 
690 int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
691 {
693  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
694  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
695 
696  if( selection.Empty() )
697  return 0;
698 
700  auto refPoint = selection.GetReferencePoint();
701  wxPoint mirrorPoint( refPoint.x, refPoint.y );
702 
703  // When editing modules, all items have the same parent
704  if( EditingModules() )
705  m_commit->Modify( selection.Front() );
706 
707  for( EDA_ITEM* item : selection )
708  {
709  // only modify items we can mirror
710  switch( item->Type() )
711  {
712  case PCB_MODULE_EDGE_T:
713  case PCB_MODULE_TEXT_T:
714  case PCB_PAD_T:
715  // Only create undo entry for items on the board
716  if( !item->IsNew() && !EditingModules() )
717  m_commit->Modify( item );
718 
719  break;
720  default:
721  continue;
722  }
723 
724  // modify each object as necessary
725  switch( item->Type() )
726  {
727  case PCB_MODULE_EDGE_T:
728  {
729  auto& edge = static_cast<EDGE_MODULE&>( *item );
730  edge.Mirror( mirrorPoint, false );
731  break;
732  }
733 
734  case PCB_MODULE_TEXT_T:
735  {
736  auto& modText = static_cast<TEXTE_MODULE&>( *item );
737  modText.Mirror( mirrorPoint, false );
738  break;
739  }
740 
741  case PCB_PAD_T:
742  {
743  auto& pad = static_cast<D_PAD&>( *item );
744  mirrorPadX( pad, mirrorPoint );
745  break;
746  }
747 
748  default:
749  // it's likely the commit object is wrong if you get here
750  assert( false );
751  break;
752  }
753  }
754 
755  if( !m_dragging )
756  m_commit->Push( _( "Mirror" ) );
757 
758  if( selection.IsHover() && !m_dragging )
760 
762 
763  if( m_dragging )
765 
766  return 0;
767 }
768 
769 
770 int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
771 {
773  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
775  nullptr, ! m_dragging );
776 
777  if( selection.Empty() )
778  return 0;
779 
781 
782  // Flip around the anchor for footprints, and the bounding box center for board items
783  VECTOR2I modPoint = EditingModules() ? VECTOR2I( 0, 0 ) : selection.GetCenter();
784 
785  // If only one item selected, flip around the item anchor point, instead
786  // of the bounding box center, to avoid moving the item anchor
787  if( selection.GetSize() == 1 )
788  modPoint = static_cast<BOARD_ITEM*>( selection.GetItem( 0 ) )->GetPosition();
789 
790  bool leftRight = frame()->Settings().m_FlipLeftRight;
791 
792  // When editing modules, all items have the same parent
793  if( EditingModules() )
794  m_commit->Modify( selection.Front() );
795 
796  for( EDA_ITEM* item : selection )
797  {
798  if( !item->IsNew() && !EditingModules() )
799  m_commit->Modify( item );
800 
801  static_cast<BOARD_ITEM*>( item )->Flip( modPoint, leftRight );
802  }
803 
804  if( !m_dragging )
805  m_commit->Push( _( "Flip" ) );
806 
807  if( selection.IsHover() && !m_dragging )
809 
811 
812  if( m_dragging )
814 
815  return 0;
816 }
817 
818 
819 int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
820 {
821  ROUTER_TOOL* routerTool = static_cast<ROUTER_TOOL*>
822  ( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
823 
824  // Do not delete items while actively routing.
825  if( routerTool && routerTool->Router() && routerTool->Router()->RoutingInProgress() )
826  return 1;
827 
828  std::vector<BOARD_ITEM*> lockedItems;
829  Activate();
830 
831  // get a copy instead of reference (as we're going to clear the selection before removing items)
832  PCBNEW_SELECTION selectionCopy;
835 
836  // If we are in a "Cut" operation, then the copied selection exists already
837  if( isCut )
838  {
839  selectionCopy = m_selectionTool->GetSelection();
840  }
841  else
842  {
843  selectionCopy = m_selectionTool->RequestSelection(
844  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
846  }
847 
848  bool isHover = selectionCopy.IsHover();
849 
850  // in "alternative" mode, deletion is not just a simple list of selected items,
851  // it removes whole tracks, not just segments
852  if( isAlt && isHover
853  && ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
854  {
856  }
857 
858  if( selectionCopy.Empty() )
859  return 0;
860 
861  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
862  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
863  // in the copyToClipboard() routine
864  if( !m_lockedSelected && !isCut )
865  {
866  // Second RequestSelection removes locked items but keeps a copy of their pointers
867  selectionCopy = m_selectionTool->RequestSelection(
868  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
869  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED ); }, &lockedItems );
870  }
871 
872 
873  // As we are about to remove items, they have to be removed from the selection first
875 
876  for( EDA_ITEM* item : selectionCopy )
877  {
878  if( m_editModules )
879  {
880  m_commit->Remove( item );
881  continue;
882  }
883 
884  switch( item->Type() )
885  {
886  case PCB_MODULE_TEXT_T:
887  {
888  auto text = static_cast<TEXTE_MODULE*>( item );
889  auto parent = static_cast<MODULE*>( item->GetParent() );
890 
891  if( text->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
892  {
893  m_commit->Modify( text );
894  getView()->Remove( text );
895  parent->Remove( text );
896  }
897  }
898  break;
899 
900  case PCB_PAD_T:
901  {
902  auto pad = static_cast<D_PAD*>( item );
903  auto parent = static_cast<MODULE*>( item->GetParent() );
904 
905  m_commit->Modify( parent );
906  getView()->Remove( pad );
907  parent->Remove( pad );
908  }
909  break;
910 
911  default:
912  m_commit->Remove( item );
913  break;
914  }
915  }
916 
917  if( isCut )
918  m_commit->Push( _( "Cut" ) );
919  else
920  m_commit->Push( _( "Delete" ) );
921 
922  if( !m_lockedSelected && !lockedItems.empty() )
923  {
925  STATUS_TEXT_POPUP statusPopup( frame() );
926 
927  m_lockedSelected = true;
928  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &lockedItems );
929  statusPopup.SetText( _( "Delete again to remove locked items" ) );
930  statusPopup.PopupFor( 2000 );
931  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
932 
933  Activate();
934 
935  while( m_lockedSelected && statusPopup.IsShown() )
936  {
937  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
938  Wait();
939  }
940  }
941 
942  m_lockedSelected = false;
943 
944  return 0;
945 }
946 
947 
948 int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
949 {
951  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
953 
954  if( selection.Empty() )
955  return 0;
956 
957  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
958  wxPoint translation;
959  double rotation;
960  ROTATION_ANCHOR rotationAnchor = selection.Size() > 1 ? ROTATE_AROUND_SEL_CENTER
962 
963  // TODO: Implement a visible bounding border at the edge
964  auto sel_box = selection.GetBoundingBox();
965 
966  DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation, rotationAnchor, sel_box );
967  int ret = dialog.ShowModal();
968 
969  if( ret == wxID_OK )
970  {
972  wxPoint selCenter( rp.x, rp.y );
973 
974  // Make sure the rotation is from the right reference point
975  selCenter += translation;
976 
977  // When editing modules, all items have the same parent
978  if( EditingModules() )
979  m_commit->Modify( selection.Front() );
980 
981  for( EDA_ITEM* selItem : selection )
982  {
983  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selItem );
984 
985  if( !item->IsNew() && !EditingModules() )
986  m_commit->Modify( item );
987 
988  item->Move( translation );
989 
990  switch( rotationAnchor )
991  {
993  item->Rotate( item->GetPosition(), rotation );
994  break;
996  item->Rotate( selCenter, rotation );
997  break;
999  item->Rotate( (wxPoint) editFrame->GetScreen()->m_LocalOrigin, rotation );
1000  break;
1002  item->Rotate( editFrame->GetAuxOrigin(), rotation );
1003  break;
1004  }
1005 
1006  if( !m_dragging )
1007  getView()->Update( item );
1008  }
1009 
1010  m_commit->Push( _( "Move exact" ) );
1011 
1012  if( selection.IsHover() )
1014 
1016 
1017  if( m_dragging )
1019  }
1020 
1021  return 0;
1022 }
1023 
1024 
1025 int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
1026 {
1027  bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
1028 
1029  // Be sure that there is at least one item that we can modify
1031  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1033 
1034  if( selection.Empty() )
1035  return 0;
1036 
1037  // we have a selection to work on now, so start the tool process
1038  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1039 
1040  // If the selection was given a hover, we do not keep the selection after completion
1041  bool is_hover = selection.IsHover();
1042 
1043  std::vector<BOARD_ITEM*> new_items;
1044  new_items.reserve( selection.Size() );
1045 
1046  BOARD_ITEM* orig_item = nullptr;
1047  BOARD_ITEM* dupe_item = nullptr;
1048 
1049  // Each selected item is duplicated and pushed to new_items list
1050  // Old selection is cleared, and new items are then selected.
1051  for( EDA_ITEM* item : selection )
1052  {
1053  orig_item = static_cast<BOARD_ITEM*>( item );
1054 
1055  if( m_editModules )
1056  dupe_item = editFrame->GetBoard()->GetFirstModule()->Duplicate( orig_item, increment );
1057  else
1058  dupe_item = editFrame->GetBoard()->Duplicate( orig_item );
1059 
1060  if( dupe_item )
1061  {
1062  // Clear the selection flag here, otherwise the SELECTION_TOOL
1063  // will not properly select it later on
1064  dupe_item->ClearSelected();
1065 
1066  new_items.push_back( dupe_item );
1067  m_commit->Add( dupe_item );
1068  }
1069  }
1070 
1071  // Clear the old selection first
1073 
1074  // Select the new items
1075  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
1076 
1077  // record the new items as added
1078  if( !selection.Empty() )
1079  {
1080  editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
1081  (int) new_items.size() ) );
1082 
1083  // If items were duplicated, pick them up
1084  // this works well for "dropping" copies around and pushes the commit
1086  Move( evt );
1087 
1088  // After moving the new items, we need to refresh the group and view flags
1090 
1091  if( !is_hover )
1092  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
1093  }
1094 
1095  return 0;
1096 }
1097 
1098 
1100 {
1102  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1104 
1105  if( selection.Empty() )
1106  return 0;
1107 
1108  // we have a selection to work on now, so start the tool process
1109  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
1110  ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection );
1111  array_creator.Invoke();
1112 
1113  return 0;
1114 }
1115 
1116 
1118 {
1119  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1120  {
1121  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
1122 
1123  if( item->Type() != PCB_PAD_T )
1124  aCollector.Remove( i );
1125  }
1126 }
1127 
1128 
1130 {
1131  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1132  {
1133  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
1134 
1135  if( item->Type() != PCB_MODULE_T )
1136  aCollector.Remove( i );
1137  }
1138 }
1139 
1140 
1142 {
1143  if( EditingModules() && !frame()->GetModel())
1144  return 0;
1145 
1146  auto& view = *getView();
1147  auto& controls = *getViewControls();
1148 
1149  std::string tool = aEvent.GetCommandStr().get();
1150  frame()->PushTool( tool );
1151  Activate();
1152 
1153  EDA_UNITS units = frame()->GetUserUnits();
1155  KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
1156 
1157  view.Add( &ruler );
1158  view.SetVisible( &ruler, false );
1159 
1160  GRID_HELPER grid( frame() );
1161 
1162  bool originSet = false;
1163 
1164  controls.ShowCursor( true );
1165  controls.SetAutoPan( false );
1166  controls.CaptureCursor( false );
1167 
1168  while( auto evt = Wait() )
1169  {
1170  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
1171  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1172  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1173  controls.SetSnapping( !evt->Modifier( MD_ALT ) );
1174  const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
1175  controls.ForceCursorPosition(true, cursorPos );
1176 
1177  auto clearRuler = [&] () {
1178  view.SetVisible( &ruler, false );
1179  controls.SetAutoPan( false );
1180  controls.CaptureCursor( false );
1181  originSet = false;
1182  };
1183 
1184  if( evt->IsCancelInteractive() )
1185  {
1186  if( originSet )
1187  clearRuler();
1188  else
1189  {
1190  frame()->PopTool( tool );
1191  break;
1192  }
1193  }
1194 
1195  else if( evt->IsActivate() )
1196  {
1197  if( originSet )
1198  clearRuler();
1199 
1200  if( evt->IsMoveTool() )
1201  {
1202  // leave ourselves on the stack so we come back after the move
1203  break;
1204  }
1205  else
1206  {
1207  frame()->PopTool( tool );
1208  break;
1209  }
1210  }
1211 
1212  // click or drag starts
1213  else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
1214  {
1215  twoPtMgr.SetOrigin( cursorPos );
1216  twoPtMgr.SetEnd( cursorPos );
1217 
1218  controls.CaptureCursor( true );
1219  controls.SetAutoPan( true );
1220 
1221  originSet = true;
1222  }
1223 
1224  // second click or mouse up after drag ends
1225  else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
1226  {
1227  originSet = false;
1228 
1229  controls.SetAutoPan( false );
1230  controls.CaptureCursor( false );
1231  }
1232 
1233  // move or drag when origin set updates rules
1234  else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1235  {
1236  twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1237  twoPtMgr.SetEnd( cursorPos );
1238 
1239  view.SetVisible( &ruler, true );
1240  view.Update( &ruler, KIGFX::GEOMETRY );
1241  }
1242 
1243  else if( evt->IsAction( &ACTIONS::toggleUnits )
1244  || evt->IsAction( &PCB_ACTIONS::updateUnits ) )
1245  {
1246  if( frame()->GetUserUnits() != units )
1247  {
1248  units = frame()->GetUserUnits();
1249  ruler.SwitchUnits();
1250  view.Update( &ruler, KIGFX::GEOMETRY );
1251  }
1252  }
1253 
1254  else if( evt->IsClick( BUT_RIGHT ) )
1255  {
1257  }
1258 
1259  else
1260  evt->SetPassEvent();
1261  }
1262 
1263  view.SetVisible( &ruler, false );
1264  view.Remove( &ruler );
1265  return 0;
1266 }
1267 
1268 
1270 {
1271  if( m_dragging && aSelection.HasReferencePoint() )
1272  return false;
1273 
1274  // When there is only one item selected, the reference point is its position...
1275  if( aSelection.Size() == 1 )
1276  {
1277  auto item = static_cast<BOARD_ITEM*>( aSelection.Front() );
1278  auto pos = item->GetPosition();
1279  aSelection.SetReferencePoint( VECTOR2I( pos.x, pos.y ) );
1280  }
1281  // ...otherwise modify items with regard to the grid-snapped cursor position
1282  else
1283  {
1285  aSelection.SetReferencePoint( m_cursor );
1286  }
1287 
1288  return true;
1289 }
1290 
1291 
1293 {
1295 
1296  if( selection.Empty() )
1297  return 0;
1298 
1299  MODULE* mod = selection.FirstOfKind<MODULE>();
1300 
1301  if( !mod )
1302  return 0;
1303 
1304  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1305 
1306  if( mod->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
1307  {
1308  mod->SetTimeStamp( GetNewTimeStamp() );
1309  editFrame->OnModify();
1310  }
1311 
1312  auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
1313 
1314  editor->Load_Module_From_BOARD( mod );
1315 
1316  editor->Show( true );
1317  editor->Raise(); // Iconize( false );
1318 
1319  if( selection.IsHover() )
1321 
1322  return 0;
1323 }
1324 
1325 
1327 {
1328  std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
1329  STATUS_TEXT_POPUP statusPopup( frame() );
1331  OPT<VECTOR2I> pickedPoint;
1332  bool done = false;
1333 
1334  statusPopup.SetText( _( "Select reference point for the copy..." ) );
1335 
1336  picker->SetClickHandler(
1337  [&]( const VECTOR2D& aPoint ) -> bool
1338  {
1339  pickedPoint = aPoint;
1340  statusPopup.SetText( _( "Selection copied." ) );
1341  statusPopup.Expire( 800 );
1342  return false; // we don't need any more points
1343  } );
1344 
1345  picker->SetMotionHandler(
1346  [&] ( const VECTOR2D& aPos )
1347  {
1348  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1349  } );
1350 
1351  picker->SetCancelHandler(
1352  [&]()
1353  {
1354  statusPopup.SetText( _( "Copy cancelled." ) );
1355  statusPopup.Expire( 800 );
1356  } );
1357 
1358  picker->SetFinalizeHandler(
1359  [&]( const int& aFinalState )
1360  {
1361  done = true;
1362  } );
1363 
1364  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1365  statusPopup.Popup();
1366 
1367  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1368 
1369  while( !done )
1370  Wait();
1371 
1372  if( pickedPoint.is_initialized() )
1373  aReferencePoint = pickedPoint.get();
1374 
1375  return pickedPoint.is_initialized();
1376 }
1377 
1378 
1380 {
1381  CLIPBOARD_IO io;
1382 
1383  Activate();
1384 
1386  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1388 
1389  if( selection.Empty() )
1390  return 1;
1391 
1392  VECTOR2I refPoint;
1393  bool rv = pickCopyReferencePoint( refPoint );
1394  frame()->SetMsgPanel( board() );
1395 
1396  if( !rv )
1397  return 1;
1398 
1399  selection.SetReferencePoint( refPoint );
1400 
1401  io.SetBoard( board() );
1402  io.SaveSelection( selection );
1403 
1404  return 0;
1405 }
1406 
1407 
1409 {
1410  if( !copyToClipboard( aEvent ) )
1411  {
1412  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
1413  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
1414  // in the copyToClipboard() routine
1415  TOOL_EVENT evt( aEvent.Category(), aEvent.Action(), TOOL_ACTION_SCOPE::AS_GLOBAL );
1417  Remove( evt );
1418  }
1419 
1420  return 0;
1421 }
1422 
1423 
1425 {
1427  Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() );
1428  Go( &EDIT_TOOL::Move, PCB_ACTIONS::drag.MakeEvent() );
1429  Go( &EDIT_TOOL::Drag, PCB_ACTIONS::drag45Degree.MakeEvent() );
1431  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );
1432  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCcw.MakeEvent() );
1433  Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
1434  Go( &EDIT_TOOL::Remove, ACTIONS::doDelete.MakeEvent() );
1435  Go( &EDIT_TOOL::Remove, PCB_ACTIONS::deleteFull.MakeEvent() );
1438  Go( &EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
1441  Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
1443 
1446 
1447  Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() );
1448  Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
1449 }
1450 
1451 
static TOOL_ACTION selectItems
Selects a list of items (specified as the event parameter)
Definition: pcb_actions.h:80
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:73
VECTOR2I GetReferencePoint() const
Definition: selection.h:239
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
EDA_UNITS
Definition: common.h:72
void setTransitions() override
Sets up handlers for various events.
Definition: edit_tool.cpp:1424
VECTOR2I m_cursor
Definition: edit_tool.h:192
void ClearReferencePoint()
Definition: selection.h:249
void AddStandardSubMenus(TOOL_MENU &aMenu)
Function CreateBasicMenu.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
int Properties(const TOOL_EVENT &aEvent)
Function Properties() Displays properties window for the selected object.
Definition: edit_tool.cpp:569
int Rotate(const TOOL_EVENT &aEvent)
Function Rotate() Rotates currently selected items.
Definition: edit_tool.cpp:607
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:103
static TOOL_ACTION deleteFull
Definition: pcb_actions.h:133
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
bool IsHover() const
Definition: selection.h:70
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:313
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
int GetCurrentViaDrill() const
Function GetCurrentViaDrill.
REMOVE_FLAGS
Remove event modifier flags
Definition: actions.h:185
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
static TOOL_ACTION changeTrackWidth
Updates selected tracks & vias to the current track & via dimensions.
Definition: pcb_actions.h:117
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
This file is part of the common library.
static TOOL_ACTION doDelete
Definition: actions.h:74
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
bool HasType(KICAD_T aType) const
Checks if there is at least one item of requested kind.
Definition: selection.h:213
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:194
void ClearSelected()
Definition: base_struct.h:233
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
VIEW_CONTROLS class definition.
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[])
Function OnlyTypes Creates a functor that tests if the selected items are only of given types.
bool IsClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:178
SELECTION_TOOL.
int ChangeTrackWidth(const TOOL_EVENT &aEvent)
Definition: edit_tool.cpp:515
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
STATUS_TEXT_POPUP.
Definition: status_popup.h:79
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:144
Tool is invoked after being inactive.
Definition: tool_base.h:81
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aIncrementPadNumbers, bool aAddToModule=false)
Function Duplicate Duplicate a given item within the module, without adding to the board.
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:376
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:120
PADS & Pads()
Definition: class_module.h:173
TOOL_MENU & GetToolMenu()
bool IsMotion() const
Definition: tool_event.h:306
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:109
static TOOL_ACTION selectConnection
Selects tracks between junctions or expands an existing selection to pads or the entire connection.
Definition: pcb_actions.h:88
static TOOL_ACTION getAndPlace
Find an item and start moving.
Definition: pcb_actions.h:426
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:240
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:530
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:143
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:114
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:305
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
static TOOL_ACTION updateFootprint
Definition: pcb_actions.h:303
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aDraggedItem)
static TOOL_ACTION updateUnits
Definition: pcb_actions.h:405
void UndoRedoBlock(bool aBlock=true)
Function UndoRedoBlock Enables/disable undo and redo operations.
TOOL_BASE * FindTool(int aId) const
Function FindTool() Searches for a tool with given ID.
SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
static SELECTION_CONDITION Count(int aNumber)
Function Count Creates a functor that tests if the number of selected items is equal to the value giv...
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
void SetBoard(BOARD *aBoard)
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty 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()
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:94
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:145
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
const wxPoint & GetAuxOrigin() const override
Return the origin of the axis used for plotting and various exports.
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:201
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:690
const VC_SETTINGS & GetSettings() const
Returns the current VIEW_CONTROLS settings
bool IsNew() const
Definition: base_struct.h:218
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:1408
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
static TOOL_ACTION pickerTool
Definition: actions.h:145
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:135
const LSET GetSelectionLayers()
PCB_BASE_EDIT_FRAME * frame() const
int EditFpInFpEditor(const TOOL_EVENT &aEvent)
Definition: edit_tool.cpp:1292
bool m_lockedSelected
Definition: edit_tool.h:191
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:116
static TOOL_ACTION measureTool
Definition: actions.h:144
class MODULE, a footprint
Definition: typeinfo.h:89
static TOOL_ACTION copy
Definition: actions.h:70
int Flip(const TOOL_EVENT &aEvent)
Function Flip() Rotates currently selected items.
Definition: edit_tool.cpp:770
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:244
static TOOL_ACTION duplicateIncrement
Activation of the duplication tool with incrementing (e.g. pad number)
Definition: pcb_actions.h:129
timestamp_t GetNewTimeStamp()
Definition: common.cpp:215
bool isInteractiveDragEnabled() const
Definition: edit_tool.cpp:227
void SetAuxAxes(bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:296
int GetAndPlace(const TOOL_EVENT &aEvent)
Find an item and start moving.
Definition: edit_tool.cpp:188
Generic tool for picking a point.
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:107
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, std::vector< BOARD_ITEM * > &aItem)
LSET is a set of PCB_LAYER_IDs.
const PCBNEW_SELECTION & selection() const
#define NULL
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:341
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool m_dragging
Definition: edit_tool.h:190
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagates an event to tools that requested events of matching type(s).
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area.
PCB_GENERAL_SETTINGS & Settings()
int ShowQuasiModal()
SELECTION_LOCK_FLAGS
Definition: selection.h:278
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:435
const wxPoint & GetOffset() const
Definition: class_pad.h:309
TOOL_EVENT.
Definition: tool_event.h:171
static TOOL_ACTION createArray
Tool for creating an array of objects.
Definition: pcb_actions.h:366
void SetOrigin(const VECTOR2I &aOrigin)
Set the origin of the ruler (the fixed end)
static TOOL_ACTION cut
Definition: actions.h:69
KIGFX::PCB_VIEW * view() const
MODULE * GetFirstModule() const
Gets the first module in the list (used in footprint viewer/editor) or NULL if none.
Definition: class_board.h:275
timestamp_t GetTimeStamp() const
Definition: base_struct.h:213
bool HasItem(const EDA_ITEM *aItem) const
Function HasItem tests if aItem has already been collected.
Definition: collector.h:199
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: edit_tool.cpp:118
void SetPassEvent()
Definition: tool_event.h:256
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
virtual void Popup(wxWindow *aFocus=nullptr)
int Drag(const TOOL_EVENT &aEvent)
Function Drag() Invoke the PNS router to drag tracks.
Definition: edit_tool.cpp:235
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Function Rotate Rotate this object.
virtual void Move(const wxPoint &aWhere)
const wxSize & GetDelta() const
Definition: class_pad.h:303
All active tools
Definition: tool_event.h:147
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:301
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.h:104
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1540
void Expire(int aMsecs)
Hides the popup after a specified time.
bool IsCancelInteractive()
Function IsCancelInteractive()
Definition: tool_event.cpp:190
virtual void PopupFor(int aMsecs)
ROTATION_ANCHOR
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:301
static TOOL_ACTION routerInlineDrag
Activation of the Push and Shove router (inline dragging mode)
Definition: pcb_actions.h:198
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:419
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.
int Move(const TOOL_EVENT &aEvent)
Function Move() Main loop in which events are handled.
Definition: edit_tool.cpp:247
#define EXCLUDE_TRANSIENTS
Definition: edit_tool.h:55
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:120
static TOOL_ACTION inlineBreakTrack
Breaks track when router is not activated.
Definition: pcb_actions.h:141
virtual const wxPoint GetPosition() const =0
static TOOL_ACTION drag
Definition: pcb_actions.h:104
void SetSnap(bool aSnap)
Definition: grid_helper.h:80
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
Definition: edit_tool.cpp:109
bool EditingModules() const
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
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:108
static void PadFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function PadFilter() A selection filter which prunes the selection to contain only items of type PCB_...
Definition: edit_tool.cpp:1117
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:93
int Modifier(int aMask=MD_MODIFIER_MASK) const
Returns information about key modifiers state (Ctrl, Alt, etc.)
Definition: tool_event.h:342
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:948
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:819
static ROUTER * theRouter
Definition: pns_router.cpp:58
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:111
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
int GetCurrentViaSize() const
Function GetCurrentViaSize.
void SaveSelection(const PCBNEW_SELECTION &selected)
bool IsActivate() const
Definition: tool_event.h:321
virtual bool IsLocked() const
Function IsLocked.
bool invokeInlineRouter(int aDragMode)
Definition: edit_tool.cpp:206
bool HasReferencePoint() const
Definition: selection.h:234
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:98
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:1099
PCBNEW_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=nullptr, bool aConfirmLockedItems=false)
Function RequestSelection()
KIGFX::VIEW_CONTROLS * controls() const
bool ToolStackIsEmpty()
Common, abstract interface for edit frames.
int MeasureTool(const TOOL_EVENT &aEvent)
Launches a tool to measure between points
Definition: edit_tool.cpp:1141
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
MODULE * module() const
static TOOL_ACTION editFootprintInFpEditor
Definition: pcb_actions.h:324
#define _(s)
Definition: 3d_actions.cpp:31
long m_lastKeyboardCursorCommand
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:422
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:76
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Function OnlyType Creates a functor that tests if the selected items are only of given type.
TOOL_EVENT MakeEvent() const
Function MakeEvent() Returns the event associated with the action (i.e.
Definition: tool_action.h:107
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163
static wxPoint mirrorPointX(const wxPoint &aPoint, const wxPoint &aMirrorPoint)
Definition: edit_tool.cpp:652
void SetMotionHandler(MOTION_HANDLER aHandler)
Function SetMotionHandler() Sets a handler for mouse motion.
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
static TOOL_ACTION positionRelative
Activation of the position relative tool.
Definition: pcb_actions.h:219
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:79
boost::optional< T > OPT
Definition: optional.h:7
T * FirstOfKind() const
Definition: selection.h:194
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:438
virtual void PopTool(const std::string &actionName)
bool PadsLocked() const
Definition: class_module.h:337
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Sets the item visibility.
Definition: view.cpp:1486
void Activate()
Function Activate() Runs the tool.
class VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:97
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
static TOOL_ACTION undo
Definition: actions.h:67
void SetUseGrid(bool aGrid=true)
Definition: grid_helper.h:90
void SetX0(int x)
Definition: class_pad.h:297
#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:1379
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:237
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:420
Module description (excepted pads)
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function FootprintFilter() A selection filter which prunes the selection to contain only items of typ...
Definition: edit_tool.cpp:1129
BOARD * GetBoard() const
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
bool RoutingInProgress() const
Definition: pns_router.cpp:111
SGLIB_API S3DMODEL * GetModel(SCENEGRAPH *aNode)
Function GetModel creates an S3DMODEL representation of aNode (raw data, no transforms)
Definition: ifsg_api.cpp:471
ROUTER * Router() const
const wxPoint GetPosition() const override
Definition: class_pad.h:241
#define EXCLUDE_LOCKED_PADS
Definition: edit_tool.h:54
EDGE_MODULE class definition.
BOARD_ITEM_CONTAINER * GetParent() const
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:308
bool updateModificationPoint(PCBNEW_SELECTION &aSelection)
Returns the right modification point (e.g.
Definition: edit_tool.cpp:1269
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags)
Definition: edit_tool.cpp:59
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:237
int Duplicate(const TOOL_EVENT &aEvent)
Function Duplicate() Duplicates the current selection and starts a move action.
Definition: edit_tool.cpp:1025
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION toggleUnits
Definition: actions.h:138
EDA_RECT GetBoundingBox() const
Definition: selection.h:155
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
const wxPoint GetPosition() const override
Definition: class_module.h:210
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:190
static void mirrorPadX(D_PAD &aPad, const wxPoint &aMirrorPoint)
Mirror a pad in the vertical axis passing through a point.
Definition: edit_tool.cpp:667
void MirrorXPrimitives(int aX)
Mirror the primitives about a coordinate.
Definition: class_pad.cpp:506
static TOOL_ACTION paste
Definition: actions.h:71
PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
static TOOL_ACTION duplicate
Definition: actions.h:73
EDA_UNITS GetUserUnits() const
Return the user units currently in use.
void SetText(const wxString &aText)
Display a text.
static TOOL_ACTION refreshPreview
Definition: actions.h:101
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:302
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:183
bool pickCopyReferencePoint(VECTOR2I &aReferencePoint)
Definition: edit_tool.cpp:1326
VECTOR2D m_LocalOrigin
Relative Screen cursor coordinate (on grid) in user units.
Definition: base_screen.h:114
void DisplayToolMsg(const wxString &msg) override
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the end that moves with the cursor.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207
void SetTimeStamp(timestamp_t aNewTimeStamp)
Definition: base_struct.h:212
Color has changed.
Definition: view_item.h:57
virtual void UpdateMsgPanel()
Redraw the message panel.
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aAddToBoard=false)