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 <class_zone.h>
32 #include <collectors.h>
33 #include <pcb_edit_frame.h>
34 #include <kiway.h>
35 #include <footprint_edit_frame.h>
36 #include <array_creator.h>
37 #include <pcbnew_id.h>
38 #include <status_popup.h>
39 #include <tool/tool_manager.h>
40 #include <tools/pcb_actions.h>
41 #include <tools/selection_tool.h>
42 #include <tools/edit_tool.h>
44 #include <tools/tool_event_utils.h>
45 #include <tools/grid_helper.h>
46 #include <view/view_controls.h>
48 #include <confirm.h>
49 #include <bitmaps.h>
50 #include <cassert>
51 #include <functional>
52 using namespace std::placeholders;
53 #include "kicad_clipboard.h"
54 #include <router/router_tool.h>
58 #include <board_commit.h>
59 
60 
61 void EditToolSelectionFilter( GENERAL_COLLECTOR& aCollector, int aFlags )
62 {
63  // Iterate from the back so we don't have to worry about removals.
64  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
65  {
66  BOARD_ITEM* item = aCollector[ i ];
67 
68  if( ( aFlags & EXCLUDE_LOCKED ) && item->IsLocked() )
69  {
70  aCollector.Remove( item );
71  }
72  else if( item->Type() == PCB_PAD_T )
73  {
74  MODULE* mod = static_cast<MODULE*>( item->GetParent() );
75 
76  // case 1: handle locking
77  if( ( aFlags & EXCLUDE_LOCKED ) && mod && mod->IsLocked() )
78  {
79  aCollector.Remove( item );
80  }
81  else if( ( aFlags & EXCLUDE_LOCKED_PADS ) && mod && mod->PadsLocked() )
82  {
83  // Pad locking is considerably "softer" than item locking
84  aCollector.Remove( item );
85 
86  if( !mod->IsLocked() && !aCollector.HasItem( mod ) )
87  aCollector.Append( mod );
88  }
89 
90  // case 2: selection contains both the module and its pads - remove the pads
91  if( mod && aCollector.HasItem( mod ) )
92  aCollector.Remove( item );
93  }
94  else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T )
95  {
96  aCollector.Remove( item );
97  }
98  }
99 }
100 
101 
103  PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
104  m_selectionTool( NULL ),
105  m_dragging( false ),
106  m_lockedSelected( false )
107 {
108 }
109 
110 
112 {
113  m_dragging = false;
114 
115  if( aReason != RUN )
116  m_commit.reset( new BOARD_COMMIT( this ) );
117 }
118 
119 
121 {
122  // Find the selection tool, so they can cooperate
123  m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
124  wxASSERT_MSG( m_selectionTool, "pcbnew.InteractiveSelection tool is not available" );
125 
126  auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) {
127  return m_editModules;
128  };
129 
130  auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
132 
133  auto noActiveToolCondition = [ this ] ( const SELECTION& aSelection ) {
134  return frame()->ToolStackIsEmpty();
135  };
136 
137  // Add context menu entries that are displayed when selection tool is active
139 
151 
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  // Mirror only available in modedit
165  menu.AddSeparator();
166  menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
169 
170  // Footprint actions
171  menu.AddSeparator();
172  menu.AddItem( PCB_ACTIONS::editFootprintInFpEditor, singleModuleCondition );
173  menu.AddItem( PCB_ACTIONS::updateFootprint, singleModuleCondition );
174  menu.AddItem( PCB_ACTIONS::changeFootprint, singleModuleCondition );
175 
176  // Populate the context menu displayed during the edit tool (primarily the measure tool)
177  auto activeToolCondition = [ this ] ( const SELECTION& aSel ) {
178  return frame()->ToolStackIsEmpty();
179  };
180 
181  auto frame = getEditFrame<PCB_BASE_FRAME>();
182  auto& ctxMenu = m_menu.GetMenu();
183 
184  // "Cancel" goes at the top of the context menu when a tool is active
185  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
186  ctxMenu.AddSeparator( 1 );
187 
188  if( frame )
190 
191  return true;
192 }
193 
194 
195 int EDIT_TOOL::GetAndPlace( const TOOL_EVENT& aEvent )
196 {
197  SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
198  MODULE* module = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
199 
200  if( module )
201  {
204 
205  selectionTool->GetSelection().SetReferencePoint( module->GetPosition() );
207  }
208 
209  return 0;
210 }
211 
212 
213 bool EDIT_TOOL::invokeInlineRouter( int aDragMode )
214 {
216 
217  if( !theRouter )
218  return false;
219 
220  // make sure we don't accidentally invoke inline routing mode while the router is already active!
221  if( theRouter->IsToolActive() )
222  return false;
223 
224  if( theRouter->CanInlineDrag() )
225  {
227  return true;
228  }
229 
230  return false;
231 }
232 
233 
235 {
236  auto theRouter = static_cast<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
237 
238  return theRouter ? theRouter->Router()->Settings().InlineDragEnabled() : false;
239 }
240 
241 
242 int EDIT_TOOL::Drag( const TOOL_EVENT& aEvent )
243 {
244  int mode = PNS::DM_ANY;
245 
246  if( aEvent.IsAction( &PCB_ACTIONS::dragFreeAngle ) )
247  mode |= PNS::DM_FREE_ANGLE;
248 
249  invokeInlineRouter( mode );
250 
251  return 0;
252 }
253 
254 int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
255 {
257  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
258  VECTOR2I originalCursorPos = controls->GetCursorPosition();
259 
260  // Be sure that there is at least one item that we can modify. If nothing was selected before,
261  // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
263  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
264  {
266  } );
267 
268  if( m_dragging || selection.Empty() )
269  return 0;
270 
271  LSET item_layers = static_cast<BOARD_ITEM*>( selection.Front() )->GetLayerSet();
272  bool unselect = selection.IsHover(); //N.B. This must be saved before the re-selection below
273 
274  // Now filter out locked pads. We cannot do this in the first RequestSelection() as we need
275  // the item_layers when a pad is the selection front (ie: will become curr_tiem).
277  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
278  {
280  } );
281 
282  if( selection.Empty() )
283  return 0;
284 
285  std::string tool = aEvent.GetCommandStr().get();
286  editFrame->PushTool( tool );
287  Activate();
288  controls->ShowCursor( true );
289  controls->SetAutoPan( true );
290 
291  auto curr_item = static_cast<BOARD_ITEM*>( selection.Front() );
292  std::vector<BOARD_ITEM*> sel_items;
293 
294  for( EDA_ITEM* item : selection )
295  {
296  BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
297  MODULE* module = dynamic_cast<MODULE*>( item );
298 
299  if( boardItem )
300  sel_items.push_back( boardItem );
301 
302  if( module )
303  {
304  for( D_PAD* pad : module->Pads() )
305  sel_items.push_back( pad );
306  }
307  }
308 
309  bool restore_state = false;
310  VECTOR2I totalMovement;
311  GRID_HELPER grid( editFrame );
312  TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
313  VECTOR2I prevPos;
314 
315  // Prime the pump
317 
318  // Main loop: keep receiving events
319  do
320  {
321  editFrame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
322  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
323  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
324  controls->SetSnapping( !evt->Modifier( MD_ALT ) );
325 
326  if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ||
328  {
329  if( m_dragging && evt->Category() == TC_MOUSE )
330  {
331  m_cursor = grid.BestSnapAnchor( controls->GetMousePosition(), item_layers,
332  sel_items );
334  VECTOR2I movement( m_cursor - prevPos );
336 
337  totalMovement += movement;
338  prevPos = m_cursor;
339 
340  // Drag items to the current cursor position
341  for( EDA_ITEM* item : selection )
342  {
343  // Don't double move footprint pads, fields, etc.
344  if( item->GetParent() && item->GetParent()->IsSelected() )
345  continue;
346 
347  static_cast<BOARD_ITEM*>( item )->Move( movement );
348  getView()->Update( item );
349  }
350 
351  frame()->UpdateMsgPanel();
352  }
353  else if( !m_dragging ) // Prepare to start dragging
354  {
356  {
358  break;
359  }
360 
361  // deal with locked items (override lock or abort the operation)
363 
364  if( lockFlags == SELECTION_LOCKED )
365  break;
366 
367  m_dragging = true;
368 
369  // When editing modules, all items have the same parent
370  if( EditingModules() )
371  {
372  m_commit->Modify( selection.Front() );
373  }
374  else
375  {
376  // Save items, so changes can be undone
377  for( auto item : selection )
378  {
379  // Don't double move footprint pads, fields, etc.
380  if( item->GetParent() && item->GetParent()->IsSelected() )
381  continue;
382 
383  m_commit->Modify( item );
384  }
385  }
386 
387  editFrame->UndoRedoBlock( true );
389 
391  {
392  // start moving with the reference point attached to the cursor
393  grid.SetAuxAxes( false );
394 
395  auto delta = m_cursor - selection.GetReferencePoint();
396 
397  // Drag items to the current cursor position
398  for( auto item : selection )
399  {
400  // Don't double move footprint pads, fields, etc.
401  if( item->GetParent() && item->GetParent()->IsSelected() )
402  continue;
403 
404  static_cast<BOARD_ITEM*>( item )->Move( delta );
405  getView()->Update( item );
406  }
407 
409  }
410  else if( selection.Size() == 1 )
411  {
412  // Set the current cursor position to the first dragged item origin, so the
413  // movement vector could be computed later
415  m_cursor = grid.BestDragOrigin( originalCursorPos, curr_item );
416  grid.SetAuxAxes( true, m_cursor );
417  }
418  else
419  {
421  m_cursor = grid.Align( m_cursor );
422  }
423 
425 
426  prevPos = m_cursor;
427  controls->SetAutoPan( true );
428  }
429 
432  }
433 
434  else if( evt->IsCancelInteractive() || evt->IsActivate() )
435  {
436  restore_state = true; // Canceling the tool means that items have to be restored
437  break; // Finish
438  }
439 
440  else if( evt->Action() == TA_UNDO_REDO_PRE )
441  {
442  unselect = true;
443  break;
444  }
445 
446  // Dispatch TOOL_ACTIONs
447  else if( evt->Category() == TC_COMMAND )
448  {
449  if( evt->IsAction( &ACTIONS::doDelete ) )
450  {
451  // exit the loop, as there is no further processing for removed items
452  break;
453  }
454  else if( evt->IsAction( &ACTIONS::duplicate ) )
455  {
456  // On duplicate, stop moving this item
457  // The duplicate tool should then select the new item and start
458  // a new move procedure
459  break;
460  }
461  else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
462  {
463  // Can't do this, because the selection will then contain
464  // stale pointers and it will all go horribly wrong...
465  //editFrame->RestoreCopyFromUndoList( dummy );
466  //
467  // So, instead, reset the position manually
468  for( auto item : selection )
469  {
470  BOARD_ITEM* i = static_cast<BOARD_ITEM*>( item );
471  auto delta = VECTOR2I( i->GetPosition() ) - totalMovement;
472  i->SetPosition( wxPoint( delta.x, delta.y ) );
473 
474  // And what about flipping and rotation?
475  // for now, they won't be undone, but maybe that is how
476  // it should be, so you can flip and move exact in the
477  // same action?
478  }
479 
480  // This causes a double event, so we will get the dialogue
481  // correctly, somehow - why does Rotate not?
482  //MoveExact( aEvent );
483  break; // exit the loop - we move exactly, so we have finished moving
484  }
485  }
486 
487  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
488  {
489  break; // Finish
490  }
491 
492  else
493  evt->SetPassEvent();
494 
495  } while( ( evt = Wait() ) ); //Should be assignment not equality test
496 
497  m_lockedSelected = false;
498  controls->ForceCursorPosition( false );
499  controls->ShowCursor( false );
500  controls->SetSnapping( false );
501  controls->SetAutoPan( false );
502 
503  m_dragging = false;
504  editFrame->UndoRedoBlock( false );
505 
506  // Discard reference point when selection is "dropped" onto the board (ie: not dragging anymore)
508 
509  if( unselect )
511 
512  // If canceled, we need to remove the dynamic ratsnest from the screen
513  if( restore_state )
514  {
516  m_commit->Revert();
517  }
518  else
519  {
520  m_commit->Push( _( "Drag" ) );
521  }
522 
523  editFrame->PopTool( tool );
524  return 0;
525 }
526 
528 {
530  {
531  auto item = static_cast<BOARD_ITEM *>( selection[0] );
532 
533  m_commit->Modify( item );
534 
535  if( auto via = dyn_cast<VIA*>( item ) )
536  {
537  int new_width;
538  int new_drill;
539 
540  if( via->GetViaType() == VIA_MICROVIA )
541  {
542  auto net = via->GetNet();
543 
544  new_width = net->GetMicroViaSize();
545  new_drill = net->GetMicroViaDrillSize();
546  }
547  else
548  {
549  new_width = board()->GetDesignSettings().GetCurrentViaSize();
550  new_drill = board()->GetDesignSettings().GetCurrentViaDrill();
551  }
552 
553  via->SetDrill( new_drill );
554  via->SetWidth( new_width );
555  }
556  else if ( auto track = dyn_cast<TRACK*>( item ) )
557  {
558  int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
559  track->SetWidth( new_width );
560  }
561 
562  m_commit->Push( _("Edit track width/via size") );
563  return true;
564  }
565 
566  return false;
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  {
581  {
582  DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
583  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
584  }
585  }
586  else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected
587  {
588  // Display properties dialog
589  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
590 
591  // Do not handle undo buffer, it is done by the properties dialogs
592  editFrame->OnEditItemRequest( item );
593 
594  // Notify other tools of the changes
596  }
597 
598  if( selection.IsHover() )
599  {
601 
602  // Notify other tools of the changes -- This updates the visual ratsnest
604  }
605 
606  return 0;
607 }
608 
609 
610 int EDIT_TOOL::Rotate( const TOOL_EVENT& aEvent )
611 {
612  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
613 
615  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
616  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
617 
618  if( selection.Empty() )
619  return 0;
620 
622  auto refPt = selection.GetReferencePoint();
623  const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
624 
625  // When editing modules, all items have the same parent
626  if( EditingModules() )
627  m_commit->Modify( selection.Front() );
628 
629  for( auto item : selection )
630  {
631  if( !item->IsNew() && !EditingModules() )
632  m_commit->Modify( item );
633 
634  static_cast<BOARD_ITEM*>( item )->Rotate( refPt, rotateAngle );
635  }
636 
637  if( !m_dragging )
638  m_commit->Push( _( "Rotate" ) );
639 
640  if( selection.IsHover() && !m_dragging )
642 
644 
645  if( m_dragging )
647 
648  return 0;
649 }
650 
651 
655 static wxPoint mirrorPointX( const wxPoint& aPoint, const wxPoint& aMirrorPoint )
656 {
657  wxPoint mirrored = aPoint;
658 
659  mirrored.x -= aMirrorPoint.x;
660  mirrored.x = -mirrored.x;
661  mirrored.x += aMirrorPoint.x;
662 
663  return mirrored;
664 }
665 
666 
670 static void mirrorPadX( D_PAD& aPad, const wxPoint& aMirrorPoint )
671 {
672  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
673 
674  if( aPad.GetShape() == PAD_SHAPE_CUSTOM )
675  aPad.MirrorXPrimitives( tmpPt.x );
676 
677  aPad.SetPosition( tmpPt );
678 
679  aPad.SetX0( aPad.GetPosition().x );
680 
681  tmpPt = aPad.GetOffset();
682  tmpPt.x = -tmpPt.x;
683  aPad.SetOffset( tmpPt );
684 
685  auto tmpz = aPad.GetDelta();
686  tmpz.x = -tmpz.x;
687  aPad.SetDelta( tmpz );
688 
689  aPad.SetOrientation( -aPad.GetOrientation() );
690 }
691 
692 
693 int EDIT_TOOL::Mirror( const TOOL_EVENT& aEvent )
694 {
696  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
697  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED_PADS | EXCLUDE_TRANSIENTS ); }, nullptr, ! m_dragging );
698 
699  if( selection.Empty() )
700  return 0;
701 
703  auto refPoint = selection.GetReferencePoint();
704  wxPoint mirrorPoint( refPoint.x, refPoint.y );
705 
706  // When editing modules, all items have the same parent
707  if( EditingModules() )
708  m_commit->Modify( selection.Front() );
709 
710  for( EDA_ITEM* item : selection )
711  {
712  // only modify items we can mirror
713  switch( item->Type() )
714  {
715  case PCB_MODULE_EDGE_T:
716  case PCB_MODULE_TEXT_T:
717  case PCB_PAD_T:
718  // Only create undo entry for items on the board
719  if( !item->IsNew() && !EditingModules() )
720  m_commit->Modify( item );
721 
722  break;
723  default:
724  continue;
725  }
726 
727  // modify each object as necessary
728  switch( item->Type() )
729  {
730  case PCB_MODULE_EDGE_T:
731  {
732  auto& edge = static_cast<EDGE_MODULE&>( *item );
733  edge.Mirror( mirrorPoint, false );
734  break;
735  }
736 
737  case PCB_MODULE_TEXT_T:
738  {
739  auto& modText = static_cast<TEXTE_MODULE&>( *item );
740  modText.Mirror( mirrorPoint, false );
741  break;
742  }
743 
744  case PCB_PAD_T:
745  {
746  auto& pad = static_cast<D_PAD&>( *item );
747  mirrorPadX( pad, mirrorPoint );
748  break;
749  }
750 
751  default:
752  // it's likely the commit object is wrong if you get here
753  assert( false );
754  break;
755  }
756  }
757 
758  if( !m_dragging )
759  m_commit->Push( _( "Mirror" ) );
760 
761  if( selection.IsHover() && !m_dragging )
763 
765 
766  if( m_dragging )
768 
769  return 0;
770 }
771 
772 
773 int EDIT_TOOL::Flip( const TOOL_EVENT& aEvent )
774 {
776  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
778  nullptr, ! m_dragging );
779 
780  if( selection.Empty() )
781  return 0;
782 
784  VECTOR2I modPoint = selection.GetCenter();
785  bool leftRight = frame()->Settings().m_FlipLeftRight;
786 
787  // When editing modules, all items have the same parent
788  if( EditingModules() )
789  m_commit->Modify( selection.Front() );
790 
791  for( EDA_ITEM* item : selection )
792  {
793  if( !item->IsNew() && !EditingModules() )
794  m_commit->Modify( item );
795 
796  static_cast<BOARD_ITEM*>( item )->Flip( modPoint, leftRight );
797  }
798 
799  if( !m_dragging )
800  m_commit->Push( _( "Flip" ) );
801 
802  if( selection.IsHover() && !m_dragging )
804 
806 
807  if( m_dragging )
809 
810  return 0;
811 }
812 
813 
814 int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent )
815 {
816  ROUTER_TOOL* routerTool = static_cast<ROUTER_TOOL*>
817  ( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
818 
819  // Do not delete items while actively routing.
820  if( routerTool && routerTool->Router() && routerTool->Router()->RoutingInProgress() )
821  return 1;
822 
823  std::vector<BOARD_ITEM*> lockedItems;
824  Activate();
825 
826  // get a copy instead of reference (as we're going to clear the selection before removing items)
827  PCBNEW_SELECTION selectionCopy;
830 
831  // If we are in a "Cut" operation, then the copied selection exists already
832  if( isCut )
833  {
834  selectionCopy = m_selectionTool->GetSelection();
835  }
836  else
837  {
838  selectionCopy = m_selectionTool->RequestSelection(
839  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
841  }
842 
843  bool isHover = selectionCopy.IsHover();
844 
845  // in "alternative" mode, deletion is not just a simple list of selected items,
846  // it removes whole tracks, not just segments
847  if( isAlt && isHover
848  && ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
849  {
851  }
852 
853  if( selectionCopy.Empty() )
854  return 0;
855 
856  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
857  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
858  // in the copyToClipboard() routine
859  if( !m_lockedSelected && !isCut )
860  {
861  // Second RequestSelection removes locked items but keeps a copy of their pointers
862  selectionCopy = m_selectionTool->RequestSelection(
863  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
864  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED ); }, &lockedItems );
865  }
866 
867 
868  // As we are about to remove items, they have to be removed from the selection first
870 
871  for( EDA_ITEM* item : selectionCopy )
872  {
873  if( m_editModules )
874  {
875  m_commit->Remove( item );
876  continue;
877  }
878 
879  switch( item->Type() )
880  {
881  case PCB_MODULE_TEXT_T:
882  {
883  auto text = static_cast<TEXTE_MODULE*>( item );
884  auto parent = static_cast<MODULE*>( item->GetParent() );
885 
886  if( text->GetType() == TEXTE_MODULE::TEXT_is_DIVERS )
887  {
888  m_commit->Modify( text );
889  getView()->Remove( text );
890  parent->Remove( text );
891  }
892  }
893  break;
894 
895  default:
896  m_commit->Remove( item );
897  break;
898  }
899  }
900 
901  if( isCut )
902  m_commit->Push( _( "Cut" ) );
903  else
904  m_commit->Push( _( "Delete" ) );
905 
906  if( !m_lockedSelected && !lockedItems.empty() )
907  {
909  STATUS_TEXT_POPUP statusPopup( frame() );
910 
911  m_lockedSelected = true;
912  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &lockedItems );
913  statusPopup.SetText( _( "Delete again to remove locked items" ) );
914  statusPopup.PopupFor( 2000 );
915  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
916 
917  Activate();
918 
919  while( m_lockedSelected && statusPopup.IsShown() )
920  {
921  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
922  Wait();
923  }
924  }
925 
926  m_lockedSelected = false;
927 
928  return 0;
929 }
930 
931 
932 int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
933 {
935  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
937 
938  if( selection.Empty() )
939  return 0;
940 
941  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
942  wxPoint translation;
943  double rotation;
944  ROTATION_ANCHOR rotationAnchor = selection.Size() > 1 ? ROTATE_AROUND_SEL_CENTER
946 
947  // TODO: Implement a visible bounding border at the edge
948  auto sel_box = selection.GetBoundingBox();
949 
950  DIALOG_MOVE_EXACT dialog( editFrame, translation, rotation, rotationAnchor, sel_box );
951  int ret = dialog.ShowModal();
952 
953  if( ret == wxID_OK )
954  {
956  wxPoint selCenter( rp.x, rp.y );
957 
958  // Make sure the rotation is from the right reference point
959  selCenter += translation;
960 
961  // When editing modules, all items have the same parent
962  if( EditingModules() )
963  m_commit->Modify( selection.Front() );
964 
965  for( EDA_ITEM* selItem : selection )
966  {
967  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selItem );
968 
969  if( !item->IsNew() && !EditingModules() )
970  m_commit->Modify( item );
971 
972  item->Move( translation );
973 
974  switch( rotationAnchor )
975  {
977  item->Rotate( item->GetPosition(), rotation );
978  break;
980  item->Rotate( selCenter, rotation );
981  break;
983  item->Rotate( (wxPoint) editFrame->GetScreen()->m_LocalOrigin, rotation );
984  break;
986  item->Rotate( editFrame->GetAuxOrigin(), rotation );
987  break;
988  }
989 
990  if( !m_dragging )
991  getView()->Update( item );
992  }
993 
994  m_commit->Push( _( "Move exact" ) );
995 
996  if( selection.IsHover() )
998 
1000 
1001  if( m_dragging )
1003  }
1004 
1005  return 0;
1006 }
1007 
1008 
1009 int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
1010 {
1011  bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
1012 
1013  // Be sure that there is at least one item that we can modify
1015  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1017 
1018  if( selection.Empty() )
1019  return 0;
1020 
1021  // we have a selection to work on now, so start the tool process
1022  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1023 
1024  std::vector<BOARD_ITEM*> new_items;
1025  new_items.reserve( selection.Size() );
1026 
1027  BOARD_ITEM* orig_item = nullptr;
1028  BOARD_ITEM* dupe_item = nullptr;
1029 
1030  // Each selected item is duplicated and pushed to new_items list
1031  // Old selection is cleared, and new items are then selected.
1032  for( EDA_ITEM* item : selection )
1033  {
1034  if( !item )
1035  continue;
1036 
1037  orig_item = static_cast<BOARD_ITEM*>( item );
1038 
1039  if( m_editModules )
1040  {
1041  dupe_item = editFrame->GetBoard()->GetFirstModule()->Duplicate( orig_item, increment );
1042  }
1043  else
1044  {
1045 #if 0
1046  // @TODO: see if we allow zone duplication here
1047  // Duplicate zones is especially tricky (overlaping zones must be merged)
1048  // so zones are not duplicated
1049  if( item->Type() != PCB_ZONE_AREA_T )
1050 #endif
1051  dupe_item = editFrame->GetBoard()->Duplicate( orig_item );
1052  }
1053 
1054  if( dupe_item )
1055  {
1056  // Clear the selection flag here, otherwise the SELECTION_TOOL
1057  // will not properly select it later on
1058  dupe_item->ClearSelected();
1059 
1060  new_items.push_back( dupe_item );
1061  m_commit->Add( dupe_item );
1062  }
1063  }
1064 
1065  // Clear the old selection first
1067 
1068  // Select the new items
1069  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
1070 
1071  // record the new items as added
1072  if( !selection.Empty() )
1073  {
1074  editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
1075  (int) new_items.size() ) );
1076 
1077  // If items were duplicated, pick them up
1078  // this works well for "dropping" copies around and pushes the commit
1080  Move( evt );
1081  }
1082 
1083  return 0;
1084 }
1085 
1086 
1088 {
1090  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1092 
1093  if( selection.Empty() )
1094  return 0;
1095 
1096  // we have a selection to work on now, so start the tool process
1097  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
1098  ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection );
1099  array_creator.Invoke();
1100 
1101  return 0;
1102 }
1103 
1104 
1106 {
1107  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
1108  {
1109  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
1110 
1111  if( item->Type() != PCB_PAD_T )
1112  aCollector.Remove( i );
1113  }
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_MODULE_T )
1124  aCollector.Remove( i );
1125  }
1126 }
1127 
1128 
1130 {
1131  if( EditingModules() && !frame()->GetModel())
1132  return 0;
1133 
1134  auto& view = *getView();
1135  auto& controls = *getViewControls();
1136 
1137  std::string tool = aEvent.GetCommandStr().get();
1138  frame()->PushTool( tool );
1139  Activate();
1140 
1141  EDA_UNITS_T units = frame()->GetUserUnits();
1143  KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr, units );
1144 
1145  view.Add( &ruler );
1146  view.SetVisible( &ruler, false );
1147 
1148  GRID_HELPER grid( frame() );
1149 
1150  bool originSet = false;
1151 
1152  controls.ShowCursor( true );
1153  controls.SetAutoPan( false );
1154  controls.CaptureCursor( false );
1155 
1156  while( auto evt = Wait() )
1157  {
1158  frame()->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
1159  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1160  grid.SetUseGrid( !evt->Modifier( MD_ALT ) );
1161  controls.SetSnapping( !evt->Modifier( MD_ALT ) );
1162  const VECTOR2I cursorPos = grid.BestSnapAnchor( controls.GetMousePosition(), nullptr );
1163  controls.ForceCursorPosition(true, cursorPos );
1164 
1165  auto clearRuler = [&] () {
1166  view.SetVisible( &ruler, false );
1167  controls.SetAutoPan( false );
1168  controls.CaptureCursor( false );
1169  originSet = false;
1170  };
1171 
1172  if( evt->IsCancelInteractive() )
1173  {
1174  if( originSet )
1175  clearRuler();
1176  else
1177  {
1178  frame()->PopTool( tool );
1179  break;
1180  }
1181  }
1182 
1183  else if( evt->IsActivate() )
1184  {
1185  if( originSet )
1186  clearRuler();
1187 
1188  if( evt->IsMoveTool() )
1189  {
1190  // leave ourselves on the stack so we come back after the move
1191  break;
1192  }
1193  else
1194  {
1195  frame()->PopTool( tool );
1196  break;
1197  }
1198  }
1199 
1200  // click or drag starts
1201  else if( !originSet && ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
1202  {
1203  twoPtMgr.SetOrigin( cursorPos );
1204  twoPtMgr.SetEnd( cursorPos );
1205 
1206  controls.CaptureCursor( true );
1207  controls.SetAutoPan( true );
1208 
1209  originSet = true;
1210  }
1211 
1212  // second click or mouse up after drag ends
1213  else if( originSet && ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
1214  {
1215  originSet = false;
1216 
1217  controls.SetAutoPan( false );
1218  controls.CaptureCursor( false );
1219  }
1220 
1221  // move or drag when origin set updates rules
1222  else if( originSet && ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1223  {
1224  twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1225  twoPtMgr.SetEnd( cursorPos );
1226 
1227  view.SetVisible( &ruler, true );
1228  view.Update( &ruler, KIGFX::GEOMETRY );
1229  }
1230 
1231  else if( evt->IsAction( &ACTIONS::toggleUnits )
1232  || evt->IsAction( &PCB_ACTIONS::updateUnits ) )
1233  {
1234  if( frame()->GetUserUnits() != units )
1235  {
1236  units = frame()->GetUserUnits();
1237  ruler.SwitchUnits();
1238  view.Update( &ruler, KIGFX::GEOMETRY );
1239  }
1240  }
1241 
1242  else if( evt->IsClick( BUT_RIGHT ) )
1243  {
1245  }
1246 
1247  else
1248  evt->SetPassEvent();
1249  }
1250 
1251  view.SetVisible( &ruler, false );
1252  view.Remove( &ruler );
1253  return 0;
1254 }
1255 
1256 
1258 {
1259  if( m_dragging && aSelection.HasReferencePoint() )
1260  return false;
1261 
1262  // When there is only one item selected, the reference point is its position...
1263  if( aSelection.Size() == 1 )
1264  {
1265  auto item = static_cast<BOARD_ITEM*>( aSelection.Front() );
1266  auto pos = item->GetPosition();
1267  aSelection.SetReferencePoint( VECTOR2I( pos.x, pos.y ) );
1268  }
1269  // ...otherwise modify items with regard to the grid-snapped cursor position
1270  else
1271  {
1273  aSelection.SetReferencePoint( m_cursor );
1274  }
1275 
1276  return true;
1277 }
1278 
1279 
1281 {
1283 
1284  if( selection.Empty() )
1285  return 0;
1286 
1288 
1289  if( !mod )
1290  return 0;
1291 
1292  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1293 
1294  if( mod->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
1295  {
1296  mod->SetTimeStamp( GetNewTimeStamp() );
1297  editFrame->OnModify();
1298  }
1299 
1300  auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_PCB_MODULE_EDITOR, true );
1301 
1302  editor->Load_Module_From_BOARD( mod );
1303 
1304  editor->Show( true );
1305  editor->Raise(); // Iconize( false );
1306 
1307  if( selection.IsHover() )
1309 
1310  return 0;
1311 }
1312 
1313 
1315 {
1316  std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
1317  STATUS_TEXT_POPUP statusPopup( frame() );
1319  OPT<VECTOR2I> pickedPoint;
1320  bool done = false;
1321 
1322  statusPopup.SetText( _( "Select reference point for the copy..." ) );
1323 
1324  picker->SetClickHandler(
1325  [&]( const VECTOR2D& aPoint ) -> bool
1326  {
1327  pickedPoint = aPoint;
1328  statusPopup.SetText( _( "Selection copied." ) );
1329  statusPopup.Expire( 800 );
1330  return false; // we don't need any more points
1331  } );
1332 
1333  picker->SetMotionHandler(
1334  [&] ( const VECTOR2D& aPos )
1335  {
1336  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1337  } );
1338 
1339  picker->SetCancelHandler(
1340  [&]()
1341  {
1342  statusPopup.SetText( _( "Copy cancelled." ) );
1343  statusPopup.Expire( 800 );
1344  } );
1345 
1346  picker->SetFinalizeHandler(
1347  [&]( const int& aFinalState )
1348  {
1349  done = true;
1350  } );
1351 
1352  statusPopup.Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
1353  statusPopup.Popup();
1354 
1355  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1356 
1357  while( !done )
1358  Wait();
1359 
1360  if( pickedPoint.is_initialized() )
1361  aReferencePoint = pickedPoint.get();
1362 
1363  return pickedPoint.is_initialized();
1364 }
1365 
1366 
1368 {
1369  CLIPBOARD_IO io;
1370 
1371  Activate();
1372 
1374  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
1376 
1377  if( selection.Empty() )
1378  return 1;
1379 
1380  VECTOR2I refPoint;
1381  bool rv = pickCopyReferencePoint( refPoint );
1382  frame()->SetMsgPanel( board() );
1383 
1384  if( !rv )
1385  return 1;
1386 
1387  selection.SetReferencePoint( refPoint );
1388 
1389  io.SetBoard( board() );
1390  io.SaveSelection( selection );
1391 
1392  return 0;
1393 }
1394 
1395 
1397 {
1398  if( !copyToClipboard( aEvent ) )
1399  {
1400  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items that
1401  // were copied to the clipboard, no more, no fewer. Filtering for locked item, if any will be done
1402  // in the copyToClipboard() routine
1403  TOOL_EVENT evt( aEvent.Category(), aEvent.Action(), TOOL_ACTION_SCOPE::AS_GLOBAL );
1405  Remove( evt );
1406  }
1407 
1408  return 0;
1409 }
1410 
1411 
1413 {
1415  Go( &EDIT_TOOL::Move, PCB_ACTIONS::move.MakeEvent() );
1416  Go( &EDIT_TOOL::Drag, PCB_ACTIONS::drag45Degree.MakeEvent() );
1418  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );
1419  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCcw.MakeEvent() );
1420  Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
1421  Go( &EDIT_TOOL::Remove, ACTIONS::doDelete.MakeEvent() );
1422  Go( &EDIT_TOOL::Remove, PCB_ACTIONS::deleteFull.MakeEvent() );
1425  Go( &EDIT_TOOL::Duplicate, ACTIONS::duplicate.MakeEvent() );
1428  Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
1429 
1432 
1433  Go( &EDIT_TOOL::copyToClipboard, ACTIONS::copy.MakeEvent() );
1434  Go( &EDIT_TOOL::cutToClipboard, ACTIONS::cut.MakeEvent() );
1435 }
1436 
1437 
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
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, BOARD_ITEM *aItem)
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:1412
VECTOR2I m_cursor
Definition: edit_tool.h:191
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:569
int Rotate(const TOOL_EVENT &aEvent)
Function Rotate() Rotates currently selected items.
Definition: edit_tool.cpp:610
static TOOL_ACTION move
move an item
Definition: pcb_actions.h:108
static TOOL_ACTION deleteFull
Definition: pcb_actions.h:134
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:184
int GetCurrentTrackWidth() const
Function GetCurrentTrackWidth.
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:73
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:193
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:247
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:174
Class SELECTION_TOOL.
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:145
Tool is invoked after being inactive.
Definition: tool_base.h:81
static TOOL_ACTION explodePadToShapes
Definition: pcb_actions.h:361
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
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:100
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:121
PADS & Pads()
Definition: class_module.h:163
TOOL_MENU & GetToolMenu()
bool IsMotion() const
Definition: tool_event.h:303
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 getAndPlace
Find an item and start moving.
Definition: pcb_actions.h:424
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:224
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:540
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:144
TOOL_EVENT_CATEGORY Category() const
Returns the category (eg. mouse/keyboard/action) of an event..
Definition: tool_event.h:244
static TOOL_ACTION mirror
Mirroring of selected items.
Definition: pcb_actions.h:118
static TOOL_ACTION changeFootprint
Definition: pcb_actions.h:306
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
static TOOL_ACTION updateFootprint
Definition: pcb_actions.h:304
VECTOR2I BestSnapAnchor(const VECTOR2I &aOrigin, BOARD_ITEM *aDraggedItem)
static TOOL_ACTION updateUnits
Definition: pcb_actions.h:403
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:188
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:200
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
int Mirror(const TOOL_EVENT &aEvent)
Function Mirror Mirrors the current selection.
Definition: edit_tool.cpp:693
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:63
static TOOL_ACTION moveExact
Activation of the exact move tool.
Definition: pcb_actions.h:124
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:1396
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
static TOOL_ACTION pickerTool
Definition: actions.h:144
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:132
PCB_BASE_EDIT_FRAME * frame() const
int EditFpInFpEditor(const TOOL_EVENT &aEvent)
Definition: edit_tool.cpp:1280
bool m_lockedSelected
Definition: edit_tool.h:190
void SetParameter(T aParam)
Function SetParameter() Sets a non-standard parameter assigned to the event.
Definition: tool_event.h:445
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:113
static TOOL_ACTION measureTool
Definition: actions.h:143
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:773
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:130
timestamp_t GetNewTimeStamp()
Definition: common.cpp:217
bool isInteractiveDragEnabled() const
Definition: edit_tool.cpp:234
void SetAuxAxes(bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
Definition: grid_helper.cpp:92
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:293
int GetAndPlace(const TOOL_EVENT &aEvent)
Find an item and start moving.
Definition: edit_tool.cpp:195
Generic tool for picking a point.
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:111
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:321
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:189
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:427
const wxPoint & GetOffset() const
Definition: class_pad.h:293
Class TOOL_EVENT.
Definition: tool_event.h:168
static TOOL_ACTION createArray
Tool for creating an array of objects.
Definition: pcb_actions.h:367
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:285
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:120
void SetPassEvent()
Definition: tool_event.h:253
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:242
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:287
All active tools
Definition: tool_event.h:144
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:298
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:186
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:199
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:417
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:254
#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:142
virtual const wxPoint GetPosition() const =0
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:111
static TOOL_ACTION expandSelectedConnection
Expands the current selection to select a connection between two junctions.
Definition: pcb_actions.h:90
bool EditingModules() const
void AddSeparator(int aOrder=ANY_ORDER)
Function AddSeparator()
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:112
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:1105
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:334
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:932
VECTOR2I Align(const VECTOR2I &aPoint) const
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
int Remove(const TOOL_EVENT &aEvent)
Function Remove() Deletes currently selected items.
Definition: edit_tool.cpp:814
static ROUTER * theRouter
Definition: pns_router.cpp:57
static TOOL_ACTION createPadFromShapes
Definition: pcb_actions.h:360
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:115
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:318
virtual bool IsLocked() const
Function IsLocked.
bool invokeInlineRouter(int aDragMode)
Definition: edit_tool.cpp:213
bool HasReferencePoint() const
Definition: selection.h:233
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:97
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:1087
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:1129
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:325
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:406
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
bool changeTrackWidthOnClick(const PCBNEW_SELECTION &selection)
Definition: edit_tool.cpp:527
size_t i
Definition: json11.cpp:597
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:655
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:220
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:96
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
void SetUseGrid(bool aGrid=true)
Definition: grid_helper.h:71
void SetX0(int x)
Definition: class_pad.h:281
#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:1367
PAD_SHAPE_T GetShape() const
Function GetShape.
Definition: class_pad.h:221
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:418
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:1117
BOARD * GetBoard() const
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
bool RoutingInProgress() const
Definition: pns_router.cpp:110
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:225
#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:292
bool updateModificationPoint(PCBNEW_SELECTION &aSelection)
Returns the right modification point (e.g.
Definition: edit_tool.cpp:1257
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags)
Definition: edit_tool.cpp:61
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:228
int Duplicate(const TOOL_EVENT &aEvent)
Function Duplicate() Duplicates the current selection and starts a move action.
Definition: edit_tool.cpp:1009
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION toggleUnits
Definition: actions.h:137
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:188
ROUTING_SETTINGS & Settings()
Definition: pns_router.h:189
static void mirrorPadX(D_PAD &aPad, const wxPoint &aMirrorPoint)
Mirror a pad in the vertical axis passing through a point.
Definition: edit_tool.cpp:670
void MirrorXPrimitives(int aX)
Mirror the primitives about a coordinate.
Definition: class_pad.cpp:504
#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:154
static TOOL_ACTION duplicate
Definition: actions.h:72
void SetText(const wxString &aText)
Display a text.
static TOOL_ACTION refreshPreview
Definition: actions.h:100
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:286
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false)=0
Moves cursor to the requested position expressed in world coordinates.
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:1314
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)