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 <pcbnew_id.h>
37 #include <status_popup.h>
38 #include <tool/tool_manager.h>
39 #include <tools/pcb_actions.h>
40 #include <tools/selection_tool.h>
41 #include <tools/edit_tool.h>
43 #include <tools/tool_event_utils.h>
44 #include <tools/grid_helper.h>
45 #include <view/view_controls.h>
47 #include <confirm.h>
48 #include <bitmaps.h>
49 #include <cassert>
50 #include <functional>
51 using namespace std::placeholders;
52 #include "kicad_clipboard.h"
53 #include <router/router_tool.h>
57 #include <board_commit.h>
58 
59 
60 void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags )
61 {
62  // Iterate from the back so we don't have to worry about removals.
63  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
64  {
65  BOARD_ITEM* item = aCollector[ i ];
66 
67  if( ( aFlags & EXCLUDE_LOCKED ) && item->IsLocked() )
68  {
69  aCollector.Remove( item );
70  }
71  else if( item->Type() == PCB_PAD_T )
72  {
73  MODULE* mod = static_cast<MODULE*>( item->GetParent() );
74 
75  // case 1: handle locking
76  if( ( aFlags & EXCLUDE_LOCKED ) && mod && mod->IsLocked() )
77  {
78  aCollector.Remove( item );
79  }
80  else if( ( aFlags & EXCLUDE_LOCKED_PADS ) && mod && mod->PadsLocked() )
81  {
82  // Pad locking is considerably "softer" than item locking
83  aCollector.Remove( item );
84 
85  if( !mod->IsLocked() && !aCollector.HasItem( mod ) )
86  aCollector.Append( mod );
87  }
88 
89  // case 2: selection contains both the module and its pads - remove the pads
90  if( mod && aCollector.HasItem( mod ) )
91  aCollector.Remove( item );
92  }
93  else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T )
94  {
95  aCollector.Remove( item );
96  }
97  }
98 }
99 
100 
102  PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
103  m_selectionTool( NULL ),
104  m_dragging( false ),
105  m_lockedSelected( false )
106 {
107 }
108 
109 
111 {
112  m_dragging = false;
113 
114  if( aReason != RUN )
115  m_commit.reset( new BOARD_COMMIT( this ) );
116 }
117 
118 
120 {
121  // Find the selection tool, so they can cooperate
122  m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
123  wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
124 
125  auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) {
126  return m_editModules;
127  };
128 
129  auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
131 
132  auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
133  return frame()->ToolStackIsEmpty();
134  };
135 
136  // Add context menu entries that are displayed when selection tool is active
138 
150 
155  menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
156 
157  menu.AddSeparator();
160  // Selection tool handles the context menu for some other tools, such as the Picker.
161  // Don't add things like Paste when another tool is active.
162  menu.AddItem( ACTIONS::paste, noActiveToolCondition );
163 
164  // Footprint actions
165  menu.AddSeparator();
166  menu.AddItem( PCB_ACTIONS::editFootprintInFpEditor, singleModuleCondition );
167  menu.AddItem( PCB_ACTIONS::updateFootprint, singleModuleCondition );
168  menu.AddItem( PCB_ACTIONS::changeFootprint, singleModuleCondition );
169 
170  // Populate the context menu displayed during the edit tool (primarily the measure tool)
171  auto activeToolCondition = [ this ] ( const SELECTION& aSel ) {
172  return frame()->ToolStackIsEmpty();
173  };
174 
175  auto frame = getEditFrame<PCB_BASE_FRAME>();
176  auto& ctxMenu = m_menu.GetMenu();
177 
178  // "Cancel" goes at the top of the context menu when a tool is active
179  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
180  ctxMenu.AddSeparator( 1 );
181 
182  if( frame )
184 
185  return true;
186 }
187 
188 
189 int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
190 {
191  SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
192  MODULE* module = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
193 
194  if( module )
195  {
198 
199  selectionTool->GetSelection().SetReferencePoint( module->GetPosition() );
201  }
202 
203  return 0;
204 }
205 
206 
207 bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
208 {
210 
211  if( !theRouter )
212  return false;
213 
214  // make sure we don't accidentally invoke inline routing mode while the router is already active!
215  if( theRouter->IsToolActive() )
216  return false;
217 
218  if( theRouter->CanInlineDrag() )
219  {
221  return true;
222  }
223 
224  return false;
225 }
226 
227 
229 {
230  auto theRouter = static_cast<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
231 
232  return theRouter ? theRouter->Router()->Settings().InlineDragEnabled() : false;
233 }
234 
235 
236 int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
237 {
238  int mode = PNS::DM_ANY;
239 
240  if( aEvent.IsAction( &PCB_ACTIONS::dragFreeAngle ) )
241  mode |= PNS::DM_FREE_ANGLE;
242 
243  invokeInlineRouter( mode );
244 
245  return 0;
246 }
247 
248 int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
249 {
251  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
252  VECTOR2I originalCursorPos = controls->GetCursorPosition();
253 
254  // Be sure that there is at least one item that we can modify. If nothing was selected before,
255  // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
257  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
258  {
260  } );
261 
262  if( m_dragging || selection.Empty() )
263  return 0;
264 
265  LSET item_layers = selection.GetSelectionLayers();
266  bool unselect = selection.IsHover(); //N.B. This must be saved before the re-selection below
267 
268  // Now filter out locked pads. We cannot do this in the first RequestSelection() as we need
269  // the item_layers when a pad is the selection front (ie: will become curr_tiem).
271  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
272  {
274  } );
275 
276  if( selection.Empty() )
277  return 0;
278 
279  std::string tool = aEvent.GetCommandStr().get();
280  editFrame->PushTool( tool );
281  Activate();
282  controls->ShowCursor( true );
283  controls->SetAutoPan( true );
284 
285  std::vector<BOARD_ITEM*> sel_items;
286 
287  for( EDA_ITEM* item : selection )
288  {
289  BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
290  MODULE* module = dynamic_cast<MODULE*>( item );
291 
292  if( boardItem )
293  sel_items.push_back( boardItem );
294 
295  if( module )
296  {
297  for( D_PAD* pad : module->Pads() )
298  sel_items.push_back( pad );
299  }
300  }
301 
302  bool restore_state = false;
303  VECTOR2I totalMovement;
304  GRID_HELPER grid( editFrame );
305  TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
306  VECTOR2I prevPos;
307 
308  // Prime the pump
310 
311  // Main loop: keep receiving events
312  do
313  {
314  editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
315  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
316  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
317  controls->SetSnapping( !evt->Modifier( MD_ALT ) );
318 
319  if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() ||
320  evt->IsAction( &PCB_ACTIONS::drag ) || evt->IsDrag( BUT_LEFT ) ||
322  {
323  if( m_dragging && evt->Category() == TC_MOUSE )
324  {
325  VECTOR2I mousePos( controls->GetMousePosition() );
326 
327  m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items );
328 
330  {
332 
333  // The arrow keys are by definition SINGLE AXIS. Do not allow the other
334  // axis to be snapped to the grid.
335  if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
336  m_cursor.y = prevPos.y;
337  else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
338  m_cursor.x = prevPos.x;
339  }
340 
343 
344  VECTOR2I movement( m_cursor - prevPos );
345  prevPos = m_cursor;
346  totalMovement += movement;
347 
348  // Drag items to the current cursor position
349  for( EDA_ITEM* item : sel_items )
350  {
351  // Don't double move footprint pads, fields, etc.
352  if( !item->GetParent() || !item->GetParent()->IsSelected() )
353  static_cast<BOARD_ITEM*>( item )->Move( movement );
354  }
355 
356  frame()->UpdateMsgPanel();
357  }
358  else if( !m_dragging ) // Prepare to start dragging
359  {
361  {
363  break;
364  }
365 
366  // deal with locked items (override lock or abort the operation)
368 
369  if( lockFlags == SELECTION_LOCKED )
370  break;
371 
372  m_dragging = true;
373 
374  // When editing modules, all items have the same parent
375  if( EditingModules() )
376  {
377  m_commit->Modify( selection.Front() );
378  }
379  else
380  {
381  // Save items, so changes can be undone
382  for( EDA_ITEM* item : selection )
383  {
384  // Don't double move footprint pads, fields, etc.
385  if( item->GetParent() && item->GetParent()->IsSelected() )
386  continue;
387 
388  m_commit->Modify( item );
389  }
390  }
391 
392  editFrame->UndoRedoBlock( true );
394 
396  {
397  // start moving with the reference point attached to the cursor
398  grid.SetAuxAxes( false );
399 
400  auto delta = m_cursor - selection.GetReferencePoint();
401 
402  // Drag items to the current cursor position
403  for( EDA_ITEM* item : selection )
404  {
405  // Don't double move footprint pads, fields, etc.
406  if( item->GetParent() && item->GetParent()->IsSelected() )
407  continue;
408 
409  static_cast<BOARD_ITEM*>( item )->Move( delta );
410  }
411 
413  }
414  else
415  {
416  std::vector<BOARD_ITEM*> items;
417 
418  for( EDA_ITEM* item : selection )
419  items.push_back( static_cast<BOARD_ITEM*>( item ) );
420 
421  // Set the current cursor position to the first dragged item origin, so the
422  // movement vector could be computed later
423  m_cursor = grid.BestDragOrigin( originalCursorPos, items );
425  grid.SetAuxAxes( true, m_cursor );
426  }
427 
429 
430  prevPos = m_cursor;
431  controls->SetAutoPan( true );
432  }
433 
436  }
437 
438  else if( evt->IsCancelInteractive() || evt->IsActivate() )
439  {
440  restore_state = true; // Canceling the tool means that items have to be restored
441  break; // Finish
442  }
443 
444  else if( evt->IsAction( &ACTIONS::undo ) )
445  {
446  restore_state = true; // Perform undo locally
447  break; // Finish
448  }
449 
450  // Dispatch TOOL_ACTIONs
451  else if( evt->Category() == TC_COMMAND )
452  {
453  if( evt->IsAction( &ACTIONS::doDelete ) )
454  {
455  break; // finish -- there is no further processing for removed items
456  }
457  else if( evt->IsAction( &ACTIONS::duplicate ) )
458  {
459  break; // finish -- Duplicate tool will start a new Move with the dup'ed items
460  }
461  else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
462  {
463  // Reset positions so the Move Exactly is from the start.
464  for( EDA_ITEM* item : selection )
465  {
466  BOARD_ITEM* i = static_cast<BOARD_ITEM*>( item );
467  i->Move( -totalMovement );
468  }
469 
470  break; // finish -- we moved exactly, so we are finished
471  }
472  }
473 
474  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
475  {
476  break; // finish
477  }
478 
479  else
480  {
481  evt->SetPassEvent();
482  }
483 
484  } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
485 
486  m_lockedSelected = false;
487  controls->ForceCursorPosition( false );
488  controls->ShowCursor( false );
489  controls->SetSnapping( false );
490  controls->SetAutoPan( false );
491 
492  m_dragging = false;
493  editFrame->UndoRedoBlock( false );
494 
495  // Discard reference point when selection is "dropped" onto the board (ie: not dragging anymore)
497 
498  if( unselect )
500 
501  // If canceled, we need to remove the dynamic ratsnest from the screen
502  if( restore_state )
503  {
505  m_commit->Revert();
506  }
507  else
508  {
509  m_commit->Push( _( "Drag" ) );
510  }
511 
512  editFrame->PopTool( tool );
513  return 0;
514 }
515 
517 {
519  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
520  { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
521 
522  for( EDA_ITEM* item : selection )
523  {
524  if( auto via = dyn_cast<VIA*>( item ) )
525  {
526  m_commit->Modify( item );
527 
528  int new_width;
529  int new_drill;
530 
531  if( via->GetViaType() == VIA_MICROVIA )
532  {
533  auto net = via->GetNet();
534 
535  new_width = net->GetMicroViaSize();
536  new_drill = net->GetMicroViaDrillSize();
537  }
538  else
539  {
540  new_width = board()->GetDesignSettings().GetCurrentViaSize();
541  new_drill = board()->GetDesignSettings().GetCurrentViaDrill();
542  }
543 
544  via->SetDrill( new_drill );
545  via->SetWidth( new_width );
546  }
547  else if ( auto track = dyn_cast<TRACK*>( item ) )
548  {
549  m_commit->Modify( item );
550 
551  int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
552  track->SetWidth( new_width );
553  }
554  }
555 
556  m_commit->Push( _("Edit track width/via size") );
557 
558  if( selection.IsHover() )
559  {
561 
562  // Notify other tools of the changes -- This updates the visual ratsnest
564  }
565 
566  return 0;
567 }
568 
569 
570 int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
571 {
572  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
573 
575  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
576  { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
577 
578  // Tracks & vias are treated in a special way:
580  {
581  DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
582  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
583  }
584  else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected
585  {
586  // Display properties dialog
587  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
588 
589  // Do not handle undo buffer, it is done by the properties dialogs
590  editFrame->OnEditItemRequest( item );
591 
592  // Notify other tools of the changes
594  }
595 
596  if( selection.IsHover() )
597  {
599 
600  // Notify other tools of the changes -- This updates the visual ratsnest
602  }
603 
604  return 0;
605 }
606 
607 
608 int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
609 {
610  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
611 
613  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
614  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
615 
616  if( selection.Empty() )
617  return 0;
618 
620  auto refPt = selection.GetReferencePoint();
621  const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
622 
623  // When editing modules, all items have the same parent
624  if( EditingModules() )
625  m_commit->Modify( selection.Front() );
626 
627  for( auto item : selection )
628  {
629  if( !item->IsNew() && !EditingModules() )
630  m_commit->Modify( item );
631 
632  static_cast<BOARD_ITEM*>( item )->Rotate( refPt, rotateAngle );
633  }
634 
635  if( !m_dragging )
636  m_commit->Push( _( "Rotate" ) );
637 
638  if( selection.IsHover() && !m_dragging )
640 
642 
643  if( m_dragging )
645 
646  return 0;
647 }
648 
649 
653 static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint )
654 {
655  wxPoint mirrored = aPoint;
656 
657  mirrored.x -= aMirrorPoint.x;
658  mirrored.x = -mirrored.x;
659  mirrored.x += aMirrorPoint.x;
660 
661  return mirrored;
662 }
663 
664 
668 static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
669 {
670  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
671 
672  if( aPad.GetShape() == PAD_SHAPE_CUSTOM )
673  aPad.MirrorXPrimitives( tmpPt.x );
674 
675  aPad.SetPosition( tmpPt );
676 
677  aPad.SetX0( aPad.GetPosition().x );
678 
679  tmpPt = aPad.GetOffset();
680  tmpPt.x = -tmpPt.x;
681  aPad.SetOffset( tmpPt );
682 
683  auto tmpz = aPad.GetDelta();
684  tmpz.x = -tmpz.x;
685  aPad.SetDelta( tmpz );
686 
687  aPad.SetOrientation( -aPad.GetOrientation() );
688 }
689 
690 
691 int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
692 {
694  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
695  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
696 
697  if( selection.Empty() )
698  return 0;
699 
701  auto refPoint = selection.GetReferencePoint();
702  wxPoint mirrorPoint( refPoint.x, refPoint.y );
703 
704  // When editing modules, all items have the same parent
705  if( EditingModules() )
706  m_commit->Modify( selection.Front() );
707 
708  for( EDA_ITEM* item : selection )
709  {
710  // only modify items we can mirror
711  switch( item->Type() )
712  {
713  case PCB_MODULE_EDGE_T:
714  case PCB_MODULE_TEXT_T:
715  case PCB_PAD_T:
716  // Only create undo entry for items on the board
717  if( !item->IsNew() && !EditingModules() )
718  m_commit->Modify( item );
719 
720  break;
721  default:
722  continue;
723  }
724 
725  // modify each object as necessary
726  switch( item->Type() )
727  {
728  case PCB_MODULE_EDGE_T:
729  {
730  auto& edge = static_cast<EDGE_MODULE&>( *item );
731  edge.Mirror( mirrorPoint, false );
732  break;
733  }
734 
735  case PCB_MODULE_TEXT_T:
736  {
737  auto& modText = static_cast<TEXTE_MODULE&>( *item );
738  modText.Mirror( mirrorPoint, false );
739  break;
740  }
741 
742  case PCB_PAD_T:
743  {
744  auto& pad = static_cast<D_PAD&>( *item );
745  mirrorPadX( pad, mirrorPoint );
746  break;
747  }
748 
749  default:
750  // it's likely the commit object is wrong if you get here
751  assert( false );
752  break;
753  }
754  }
755 
756  if( !m_dragging )
757  m_commit->Push( _( "Mirror" ) );
758 
759  if( selection.IsHover() && !m_dragging )
761 
763 
764  if( m_dragging )
766 
767  return 0;
768 }
769 
770 
771 int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
772 {
774  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
776  nullptr, ! m_dragging );
777 
778  if( selection.Empty() )
779  return 0;
780 
782 
783  // Flip around the anchor for footprints, and the bounding box center for board items
784  VECTOR2I modPoint = EditingModules() ? VECTOR2I( 0, 0 ) : selection.GetCenter();
785 
786  // If only one item selected, flip around the item anchor point, instead
787  // of the bounding box center, to avoid moving the item anchor
788  if( selection.GetSize() == 1 )
789  modPoint = static_cast<BOARD_ITEM*>( selection.GetItem( 0 ) )->GetPosition();
790 
791  bool leftRight = frame()->Settings().m_FlipLeftRight;
792 
793  // When editing modules, all items have the same parent
794  if( EditingModules() )
795  m_commit->Modify( selection.Front() );
796 
797  for( EDA_ITEM* item : selection )
798  {
799  if( !item->IsNew() && !EditingModules() )
800  m_commit->Modify( item );
801 
802  static_cast<BOARD_ITEM*>( item )->Flip( modPoint, leftRight );
803  }
804 
805  if( !m_dragging )
806  m_commit->Push( _( "Flip" ) );
807 
808  if( selection.IsHover() && !m_dragging )
810 
812 
813  if( m_dragging )
815 
816  return 0;
817 }
818 
819 
820 int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
821 {
822  ROUTER_TOOL* routerTool = static_cast<ROUTER_TOOL*>
823  ( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
824 
825  // Do not delete items while actively routing.
826  if( routerTool && routerTool->Router() && routerTool->Router()->RoutingInProgress() )
827  return 1;
828 
829  std::vector<BOARD_ITEM*> lockedItems;
830  Activate();
831 
832  // get a copy instead of reference (as we're going to clear the selection before removing items)
833  PCBNEW_SELECTION selectionCopy;
836 
837  // If we are in a "Cut" operation, then the copied selection exists already
838  if( isCut )
839  {
840  selectionCopy = m_selectionTool->GetSelection();
841  }
842  else
843  {
844  selectionCopy = m_selectionTool->RequestSelection(
845  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
847  }
848 
849  bool isHover = selectionCopy.IsHover();
850 
851  // in "alternative" mode, deletion is not just a simple list of selected items,
852  // it removes whole tracks, not just segments
853  if( isAlt && isHover
854  && ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
855  {
857  }
858 
859  if( selectionCopy.Empty() )
860  return 0;
861 
862  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
863  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
864  // in the copyToClipboard() routine
865  if( !m_lockedSelected && !isCut )
866  {
867  // Second RequestSelection removes locked items but keeps a copy of their pointers
868  selectionCopy = m_selectionTool->RequestSelection(
869  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
870  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED ); }, &lockedItems );
871  }
872 
873 
874  // As we are about to remove items, they have to be removed from the selection first
876 
877  for( EDA_ITEM* item : selectionCopy )
878  {
879  if( m_editModules )
880  {
881  m_commit->Remove( item );
882  continue;
883  }
884 
885  switch( item->Type() )
886  {
887  case PCB_MODULE_TEXT_T:
888  {
889  auto text = static_cast<TEXTE_MODULE*>( item );
890  auto parent = static_cast<MODULE*>( item->GetParent() );
891 
892  if( text->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
893  {
894  m_commit->Modify( text );
895  getView()->Remove( text );
896  parent->Remove( text );
897  }
898  }
899  break;
900 
901  case PCB_PAD_T:
902  {
903  auto pad = static_cast<D_PAD*>( item );
904  auto parent = static_cast<MODULE*>( item->GetParent() );
905 
906  m_commit->Modify( parent );
907  getView()->Remove( pad );
908  parent->Remove( pad );
909  }
910  break;
911 
912  default:
913  m_commit->Remove( item );
914  break;
915  }
916  }
917 
918  if( isCut )
919  m_commit->Push( _( "Cut" ) );
920  else
921  m_commit->Push( _( "Delete" ) );
922 
923  if( !m_lockedSelected && !lockedItems.empty() )
924  {
926  STATUS_TEXT_POPUP statusPopup( frame() );
927 
928  m_lockedSelected = true;
929  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &lockedItems );
930  statusPopup.SetText( _( "Delete again to remove locked items" ) );
931  statusPopup.PopupFor( 2000 );
932  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
933 
934  Activate();
935 
936  while( m_lockedSelected && statusPopup.IsShown() )
937  {
938  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
939  Wait();
940  }
941  }
942 
943  m_lockedSelected = false;
944 
945  return 0;
946 }
947 
948 
949 int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
950 {
952  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
954 
955  if( selection.Empty() )
956  return 0;
957 
958  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
959  wxPoint translation;
960  double rotation;
961  ROTATION_ANCHOR rotationAnchor = selection.Size() > 1 ? ROTATE_AROUND_SEL_CENTER
963 
964  // TODO: Implement a visible bounding border at the edge
965  auto sel_box = selection.GetBoundingBox();
966 
967  DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation, rotationAnchor, sel_box );
968  int ret = dialog.ShowModal();
969 
970  if( ret == wxID_OK )
971  {
973  wxPoint selCenter( rp.x, rp.y );
974 
975  // Make sure the rotation is from the right reference point
976  selCenter += translation;
977 
978  // When editing modules, all items have the same parent
979  if( EditingModules() )
980  m_commit->Modify( selection.Front() );
981 
982  for( EDA_ITEM* selItem : selection )
983  {
984  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selItem );
985 
986  if( !item->IsNew() && !EditingModules() )
987  m_commit->Modify( item );
988 
989  item->Move( translation );
990 
991  switch( rotationAnchor )
992  {
994  item->Rotate( item->GetPosition(), rotation );
995  break;
997  item->Rotate( selCenter, rotation );
998  break;
1000  item->Rotate( (wxPoint) editFrame->GetScreen()->m_LocalOrigin, rotation );
1001  break;
1003  item->Rotate( editFrame->GetAuxOrigin(), rotation );
1004  break;
1005  }
1006 
1007  if( !m_dragging )
1008  getView()->Update( item );
1009  }
1010 
1011  m_commit->Push( _( "Move exact" ) );
1012 
1013  if( selection.IsHover() )
1015 
1017 
1018  if( m_dragging )
1020  }
1021 
1022  return 0;
1023 }
1024 
1025 
1026 int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
1027 {
1028  bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
1029 
1030  // Be sure that there is at least one item that we can modify
1032  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1034 
1035  if( selection.Empty() )
1036  return 0;
1037 
1038  // we have a selection to work on now, so start the tool process
1039  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1040 
1041  // If the selection was given a hover, we do not keep the selection after completion
1042  bool is_hover = selection.IsHover();
1043 
1044  std::vector<BOARD_ITEM*> new_items;
1045  new_items.reserve( selection.Size() );
1046 
1047  BOARD_ITEM* orig_item = nullptr;
1048  BOARD_ITEM* dupe_item = nullptr;
1049 
1050  // Each selected item is duplicated and pushed to new_items list
1051  // Old selection is cleared, and new items are then selected.
1052  for( EDA_ITEM* item : selection )
1053  {
1054  orig_item = static_cast<BOARD_ITEM*>( item );
1055 
1056  if( m_editModules )
1057  dupe_item = editFrame->GetBoard()->GetFirstModule()->Duplicate( orig_item, increment );
1058  else
1059  dupe_item = editFrame->GetBoard()->Duplicate( orig_item );
1060 
1061  if( dupe_item )
1062  {
1063  // Clear the selection flag here, otherwise the SELECTION_TOOL
1064  // will not properly select it later on
1065  dupe_item->ClearSelected();
1066 
1067  new_items.push_back( dupe_item );
1068  m_commit->Add( dupe_item );
1069  }
1070  }
1071 
1072  // Clear the old selection first
1074 
1075  // Select the new items
1076  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
1077 
1078  // record the new items as added
1079  if( !selection.Empty() )
1080  {
1081  editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
1082  (int) new_items.size() ) );
1083 
1084  // If items were duplicated, pick them up
1085  // this works well for "dropping" copies around and pushes the commit
1087  Move( evt );
1088 
1089  // After moving the new items, we need to refresh the group and view flags
1091 
1092  if( !is_hover )
1093  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
1094  }
1095 
1096  return 0;
1097 }
1098 
1099 
1101 {
1103  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1105 
1106  if( selection.Empty() )
1107  return 0;
1108 
1109  // we have a selection to work on now, so start the tool process
1110  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
1111  ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection );
1112  array_creator.Invoke();
1113 
1114  return 0;
1115 }
1116 
1117 
1119 {
1120  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1121  {
1122  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
1123 
1124  if( item->Type() != PCB_PAD_T )
1125  aCollector.Remove( i );
1126  }
1127 }
1128 
1129 
1131 {
1132  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1133  {
1134  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
1135 
1136  if( item->Type() != PCB_MODULE_T )
1137  aCollector.Remove( i );
1138  }
1139 }
1140 
1141 
1143 {
1144  if( EditingModules() && !frame()->GetModel())
1145  return 0;
1146 
1147  auto& view = *getView();
1148  auto& controls = *getViewControls();
1149 
1150  std::string tool = aEvent.GetCommandStr().get();
1151  frame()->PushTool( tool );
1152  Activate();
1153 
1154  EDA_UNITS_T units = frame()->GetUserUnits();
1156  KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
1157 
1158  view.Add( &ruler );
1159  view.SetVisible( &ruler, false );
1160 
1161  GRID_HELPER grid( frame() );
1162 
1163  bool originSet = false;
1164 
1165  controls.ShowCursor( true );
1166  controls.SetAutoPan( false );
1167  controls.CaptureCursor( false );
1168 
1169  while( auto evt = Wait() )
1170  {
1171  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
1172  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1173  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1174  controls.SetSnapping( !evt->Modifier( MD_ALT ) );
1175  const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
1176  controls.ForceCursorPosition(true, cursorPos );
1177 
1178  auto clearRuler = [&] () {
1179  view.SetVisible( &ruler, false );
1180  controls.SetAutoPan( false );
1181  controls.CaptureCursor( false );
1182  originSet = false;
1183  };
1184 
1185  if( evt->IsCancelInteractive() )
1186  {
1187  if( originSet )
1188  clearRuler();
1189  else
1190  {
1191  frame()->PopTool( tool );
1192  break;
1193  }
1194  }
1195 
1196  else if( evt->IsActivate() )
1197  {
1198  if( originSet )
1199  clearRuler();
1200 
1201  if( evt->IsMoveTool() )
1202  {
1203  // leave ourselves on the stack so we come back after the move
1204  break;
1205  }
1206  else
1207  {
1208  frame()->PopTool( tool );
1209  break;
1210  }
1211  }
1212 
1213  // click or drag starts
1214  else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
1215  {
1216  twoPtMgr.SetOrigin( cursorPos );
1217  twoPtMgr.SetEnd( cursorPos );
1218 
1219  controls.CaptureCursor( true );
1220  controls.SetAutoPan( true );
1221 
1222  originSet = true;
1223  }
1224 
1225  // second click or mouse up after drag ends
1226  else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
1227  {
1228  originSet = false;
1229 
1230  controls.SetAutoPan( false );
1231  controls.CaptureCursor( false );
1232  }
1233 
1234  // move or drag when origin set updates rules
1235  else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1236  {
1237  twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1238  twoPtMgr.SetEnd( cursorPos );
1239 
1240  view.SetVisible( &ruler, true );
1241  view.Update( &ruler, KIGFX::GEOMETRY );
1242  }
1243 
1244  else if( evt->IsAction( &ACTIONS::toggleUnits )
1245  || evt->IsAction( &PCB_ACTIONS::updateUnits ) )
1246  {
1247  if( frame()->GetUserUnits() != units )
1248  {
1249  units = frame()->GetUserUnits();
1250  ruler.SwitchUnits();
1251  view.Update( &ruler, KIGFX::GEOMETRY );
1252  }
1253  }
1254 
1255  else if( evt->IsClick( BUT_RIGHT ) )
1256  {
1258  }
1259 
1260  else
1261  evt->SetPassEvent();
1262  }
1263 
1264  view.SetVisible( &ruler, false );
1265  view.Remove( &ruler );
1266  return 0;
1267 }
1268 
1269 
1271 {
1272  if( m_dragging && aSelection.HasReferencePoint() )
1273  return false;
1274 
1275  // When there is only one item selected, the reference point is its position...
1276  if( aSelection.Size() == 1 )
1277  {
1278  auto item = static_cast<BOARD_ITEM*>( aSelection.Front() );
1279  auto pos = item->GetPosition();
1280  aSelection.SetReferencePoint( VECTOR2I( pos.x, pos.y ) );
1281  }
1282  // ...otherwise modify items with regard to the grid-snapped cursor position
1283  else
1284  {
1286  aSelection.SetReferencePoint( m_cursor );
1287  }
1288 
1289  return true;
1290 }
1291 
1292 
1294 {
1296 
1297  if( selection.Empty() )
1298  return 0;
1299 
1301 
1302  if( !mod )
1303  return 0;
1304 
1305  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1306 
1307  if( mod->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
1308  {
1309  mod->SetTimeStamp( GetNewTimeStamp() );
1310  editFrame->OnModify();
1311  }
1312 
1313  auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
1314 
1315  editor->Load_Module_From_BOARD( mod );
1316 
1317  editor->Show( true );
1318  editor->Raise(); // Iconize( false );
1319 
1320  if( selection.IsHover() )
1322 
1323  return 0;
1324 }
1325 
1326 
1328 {
1329  std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
1330  STATUS_TEXT_POPUP statusPopup( frame() );
1332  OPT<VECTOR2I> pickedPoint;
1333  bool done = false;
1334 
1335  statusPopup.SetText( _( "Select reference point for the copy..." ) );
1336 
1337  picker->SetClickHandler(
1338  [&]( const VECTOR2D& aPoint ) -> bool
1339  {
1340  pickedPoint = aPoint;
1341  statusPopup.SetText( _( "Selection copied." ) );
1342  statusPopup.Expire( 800 );
1343  return false; // we don't need any more points
1344  } );
1345 
1346  picker->SetMotionHandler(
1347  [&] ( const VECTOR2D& aPos )
1348  {
1349  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1350  } );
1351 
1352  picker->SetCancelHandler(
1353  [&]()
1354  {
1355  statusPopup.SetText( _( "Copy cancelled." ) );
1356  statusPopup.Expire( 800 );
1357  } );
1358 
1359  picker->SetFinalizeHandler(
1360  [&]( const int& aFinalState )
1361  {
1362  done = true;
1363  } );
1364 
1365  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1366  statusPopup.Popup();
1367 
1368  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1369 
1370  while( !done )
1371  Wait();
1372 
1373  if( pickedPoint.is_initialized() )
1374  aReferencePoint = pickedPoint.get();
1375 
1376  return pickedPoint.is_initialized();
1377 }
1378 
1379 
1381 {
1382  CLIPBOARD_IO io;
1383 
1384  Activate();
1385 
1387  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1389 
1390  if( selection.Empty() )
1391  return 1;
1392 
1393  VECTOR2I refPoint;
1394  bool rv = pickCopyReferencePoint( refPoint );
1395  frame()->SetMsgPanel( board() );
1396 
1397  if( !rv )
1398  return 1;
1399 
1400  selection.SetReferencePoint( refPoint );
1401 
1402  io.SetBoard( board() );
1403  io.SaveSelection( selection );
1404 
1405  return 0;
1406 }
1407 
1408 
1410 {
1411  if( !copyToClipboard( aEvent ) )
1412  {
1413  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
1414  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
1415  // in the copyToClipboard() routine
1416  TOOL_EVENT evt( aEvent.Category(), aEvent.Action(), TOOL_ACTION_SCOPE::AS_GLOBAL );
1418  Remove( evt );
1419  }
1420 
1421  return 0;
1422 }
1423 
1424 
1426 {
1428  Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() );
1429  Go( &EDIT_TOOL::Move, PCB_ACTIONS::drag.MakeEvent() );
1430  Go( &EDIT_TOOL::Drag, PCB_ACTIONS::drag45Degree.MakeEvent() );
1432  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );
1433  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCcw.MakeEvent() );
1434  Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
1435  Go( &EDIT_TOOL::Remove, ACTIONS::doDelete.MakeEvent() );
1436  Go( &EDIT_TOOL::Remove, PCB_ACTIONS::deleteFull.MakeEvent() );
1439  Go( &EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
1442  Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
1444 
1447 
1448  Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() );
1449  Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
1450 }
1451 
1452 
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:238
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
void setTransitions() override
Sets up handlers for various events.
Definition: edit_tool.cpp:1425
VECTOR2I m_cursor
Definition: edit_tool.h:192
void ClearReferencePoint()
Definition: selection.h:248
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:570
int Rotate(const TOOL_EVENT &aEvent)
Function Rotate() Rotates currently selected items.
Definition: edit_tool.cpp:608
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:69
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
Class 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:212
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:194
void ClearSelected()
Definition: base_struct.h:243
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
Class SELECTION_TOOL.
int ChangeTrackWidth(const TOOL_EVENT &aEvent)
Definition: edit_tool.cpp:516
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
Class 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:136
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:176
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:423
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:240
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:531
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:402
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:587
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:142
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:691
const VC_SETTINGS & GetSettings() const
Returns the current VIEW_CONTROLS settings
bool IsNew() const
Definition: base_struct.h:228
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:1409
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:132
const LSET GetSelectionLayers()
PCB_BASE_EDIT_FRAME * frame() const
int EditFpInFpEditor(const TOOL_EVENT &aEvent)
Definition: edit_tool.cpp:1293
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:113
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:771
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:243
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:217
bool isInteractiveDragEnabled() const
Definition: edit_tool.cpp:228
void SetAuxAxes(bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
Definition: grid_helper.cpp:93
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:189
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)
Class LSET is a set of PCB_LAYER_IDs.
const PCBNEW_SELECTION & selection() const
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:263
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
Class 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:276
bool HasItem(const EDA_ITEM *aItem) const
Function HasItem tests if aItem has already been collected.
Definition: collector.h:196
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: edit_tool.cpp:119
void SetPassEvent()
Definition: tool_event.h:256
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
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:236
Class RULER_ITEM.
Definition: ruler_item.h:43
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:103
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
#define _(s)
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:416
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:248
#define EXCLUDE_TRANSIENTS
Definition: edit_tool.h:55
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
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:66
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
Definition: edit_tool.cpp:110
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:98
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:1118
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:949
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:820
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:207
bool HasReferencePoint() const
Definition: selection.h:233
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:1100
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:1142
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
EDA_UNITS_T GetUserUnits() const
Return the user units currently in use.
MODULE * module() const
static TOOL_ACTION editFootprintInFpEditor
Definition: pcb_actions.h:324
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
Definition: view_controls.h:97
size_t i
Definition: json11.cpp:649
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:125
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
static wxPoint mirrorPointX(const wxPoint &aPoint, const wxPoint &aMirrorPoint)
Definition: edit_tool.cpp:653
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:193
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:430
virtual void PopTool(const std::string &actionName)
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:71
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:1380
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:237
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:417
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:1130
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:1270
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags)
Definition: edit_tool.cpp:60
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:1026
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:154
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
const wxPoint GetPosition() const override
Definition: class_module.h:213
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:668
void MirrorXPrimitives(int aX)
Mirror the primitives about a coordinate.
Definition: class_pad.cpp:498
#define mod(a, n)
Definition: greymap.cpp:24
static TOOL_ACTION paste
Definition: actions.h:71
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
EDA_UNITS_T
Definition: common.h:133
static TOOL_ACTION duplicate
Definition: actions.h:73
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:182
bool pickCopyReferencePoint(VECTOR2I &aReferencePoint)
Definition: edit_tool.cpp:1327
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:210
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)