KiCad PCB EDA Suite
sch_move_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) 2019 CERN
5  * Copyright (C) 2019 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #include <tool/tool_manager.h>
26 #include <tools/ee_grid_helper.h>
29 #include <ee_actions.h>
30 #include <bitmaps.h>
31 #include <base_struct.h>
32 #include <sch_item.h>
33 #include <sch_component.h>
34 #include <sch_sheet.h>
35 #include <sch_view.h>
36 #include <sch_line.h>
37 #include <sch_edit_frame.h>
38 #include <eeschema_id.h>
39 #include <pgm_base.h>
41 #include "sch_move_tool.h"
42 
43 
44 // For adding to or removing from selections
45 #define QUIET_MODE true
46 
47 
49  EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveMove" ),
50  m_moveInProgress( false ),
51  m_isDragOperation( false ),
52  m_moveOffset( 0, 0 )
53 {
54 }
55 
56 
58 {
60 
61  auto moveCondition = [] ( const SELECTION& aSel ) {
62  if( aSel.Empty() )
63  return false;
64 
66  return false;
67 
68  return true;
69  };
70 
71  // Add move actions to the selection tool menu
72  //
74 
75  selToolMenu.AddItem( EE_ACTIONS::move, moveCondition, 150 );
76  selToolMenu.AddItem( EE_ACTIONS::drag, moveCondition, 150 );
77  selToolMenu.AddItem( EE_ACTIONS::alignToGrid, moveCondition, 150 );
78 
79  return true;
80 }
81 
82 
83 static const KICAD_T movableItems[] =
84 {
90  SCH_LINE_T,
92  SCH_TEXT_T,
100  EOT
101 };
102 
103 
104 /* TODO - Tom/Jeff
105  - add preferences option "Move origin: always cursor / item origin"
106  - add preferences option "Default drag action: drag items / move"
107  - add preferences option "Drag always selects"
108  */
109 
110 
111 int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
112 {
113  EESCHEMA_SETTINGS* cfg = Pgm().GetSettingsManager().GetAppSettings<EESCHEMA_SETTINGS>();
115  EE_GRID_HELPER grid( m_toolMgr );
116 
117  m_anchorPos.reset();
118 
119  if( aEvent.IsAction( &EE_ACTIONS::move ) )
120  m_isDragOperation = false;
121  else if( aEvent.IsAction( &EE_ACTIONS::drag ) )
122  m_isDragOperation = true;
123  else if( aEvent.IsAction( &EE_ACTIONS::moveActivate ) )
125  else
126  return 0;
127 
128  if( m_moveInProgress )
129  {
130  auto sel = m_selectionTool->GetSelection().Front();
131 
132  if( sel && !sel->IsNew() )
133  {
134  // User must have switched from move to drag or vice-versa. Reset the selected
135  // items so we can start again with the current m_isDragOperation.
139  m_moveInProgress = false;
140  controls->SetAutoPan( false );
141 
142  // And give it a kick so it doesn't have to wait for the first mouse movement to
143  // refresh.
145  }
146 
147  return 0;
148  }
149 
150  // Be sure that there is at least one item that we can move. If there's no selection try
151  // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
153  bool unselect = selection.IsHover();
154 
155  // Keep an original copy of the starting points for cleanup after the move
156  std::vector<DANGLING_END_ITEM> internalPoints;
157 
158  if( selection.Empty() )
159  return 0;
160 
161  Activate();
162  controls->ShowCursor( true );
163 
164  bool restore_state = false;
165  bool chain_commands = false;
166  TOOL_EVENT* evt = const_cast<TOOL_EVENT*>( &aEvent );
167  VECTOR2I prevPos;
168 
169  std::string tool = aEvent.GetCommandStr().get();
170  m_frame->PushTool( tool );
171  m_cursor = controls->GetCursorPosition();
172 
173  // Main loop: keep receiving events
174  do
175  {
176  m_frame->GetCanvas()->SetCurrentCursor( wxCURSOR_ARROW );
177 
179  || evt->IsAction( &EE_ACTIONS::move ) || evt->IsAction( &EE_ACTIONS::drag )
180  || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
181  || evt->IsAction( &ACTIONS::refreshPreview ) )
182  {
183  if( !m_moveInProgress ) // Prepare to start moving/dragging
184  {
185  SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
186  bool appendUndo = sch_item && sch_item->IsNew();
187  bool placingNewItems = sch_item && sch_item->IsNew();
188 
189  //------------------------------------------------------------------------
190  // Setup a drag or a move
191  //
192  m_dragAdditions.clear();
193  m_specialCaseLabels.clear();
194  internalPoints.clear();
195 
196  for( auto it : m_frame->GetScreen()->Items() )
197  {
198  it->ClearFlags( TEMP_SELECTED );
199 
200  if( !it->IsSelected() )
201  it->ClearFlags( STARTPOINT | ENDPOINT );
202 
203  if( !selection.IsHover() && it->IsSelected() )
204  it->SetFlags( STARTPOINT | ENDPOINT );
205  }
206 
207  if( m_isDragOperation )
208  {
209  // Add connections to the selection for a drag.
210  //
211  for( EDA_ITEM* item : selection )
212  {
213  std::vector<wxPoint> connections;
214 
215  if( item->Type() == SCH_LINE_T )
216  static_cast<SCH_LINE*>( item )->GetSelectedPoints( connections );
217  else
218  connections = static_cast<SCH_ITEM*>( item )->GetConnectionPoints();
219 
220  for( wxPoint point : connections )
221  getConnectedDragItems( static_cast<SCH_ITEM*>( item ), point,
222  m_dragAdditions );
223  }
224 
226  }
227  else
228  {
229  // Mark the edges of the block with dangling flags for a move.
230  for( EDA_ITEM* item : selection )
231  static_cast<SCH_ITEM*>( item )->GetEndPoints( internalPoints );
232 
233  for( EDA_ITEM* item : selection )
234  static_cast<SCH_ITEM*>( item )->UpdateDanglingState( internalPoints );
235  }
236  // Generic setup
237  //
238  for( EDA_ITEM* item : selection )
239  {
240  if( item->IsNew() )
241  {
242  if( item->HasFlag( TEMP_SELECTED ) && m_isDragOperation )
243  {
244  // Item was added in getConnectedDragItems
245  saveCopyInUndoList( (SCH_ITEM*) item, UNDO_REDO::NEWITEM, appendUndo );
246  appendUndo = true;
247  }
248  else
249  {
250  // Item was added in a previous command (and saved to undo by
251  // that command)
252  }
253  }
254  else if( item->GetParent() && item->GetParent()->IsSelected() )
255  {
256  // Item will be (or has been) saved to undo by parent
257  }
258  else
259  {
260  saveCopyInUndoList( (SCH_ITEM*) item, UNDO_REDO::CHANGED, appendUndo );
261  appendUndo = true;
262  }
263 
264  SCH_ITEM* schItem = (SCH_ITEM*) item;
265  schItem->SetStoredPos( schItem->GetPosition() );
266  }
267 
268  // Set up the starting position and move/drag offset
269  //
270  m_cursor = controls->GetCursorPosition();
271 
272  if( evt->IsAction( &EE_ACTIONS::restartMove ) )
273  {
274  wxASSERT_MSG( m_anchorPos, "Should be already set from previous cmd" );
275  }
276  else if( placingNewItems )
277  {
278  m_anchorPos = selection.GetReferencePoint();
279  }
280 
281  if( m_anchorPos )
282  {
283  VECTOR2I delta = m_cursor - (*m_anchorPos);
284 
285  // Drag items to the current cursor position
286  for( EDA_ITEM* item : selection )
287  {
288  // Don't double move pins, fields, etc.
289  if( item->GetParent() && item->GetParent()->IsSelected() )
290  continue;
291 
292  moveItem( item, delta );
293  updateView( item );
294  }
295 
297  }
298  // For some items, moving the cursor to anchor is not good (for instance large
299  // hierarchical sheets or components can have the anchor outside the view)
300  else if( selection.Size() == 1 && !sch_item->IsMovableFromAnchorPoint() )
301  {
304  }
305  else
306  {
307  if( m_frame->GetMoveWarpsCursor() )
308  {
309  // User wants to warp the mouse
310  std::vector<SCH_ITEM*> items;
311 
312  for( EDA_ITEM* item : selection )
313  items.push_back( static_cast<SCH_ITEM*>( item ) );
314 
315  m_cursor = grid.BestDragOrigin( m_cursor, items );
316  }
317  else
318  {
319  // User does not want to warp the mouse
321  }
322  }
323 
324 
325  controls->SetCursorPosition( m_cursor, false );
327 
328  prevPos = m_cursor;
329  controls->SetAutoPan( true );
330  m_moveInProgress = true;
331  }
332 
333  //------------------------------------------------------------------------
334  // Follow the mouse
335  //
336  m_cursor = controls->GetCursorPosition();
337  VECTOR2I delta( m_cursor - prevPos );
339 
340  m_moveOffset += delta;
341  prevPos = m_cursor;
342 
343  for( EDA_ITEM* item : selection )
344  {
345  // Don't double move pins, fields, etc.
346  if( item->GetParent() && item->GetParent()->IsSelected() )
347  continue;
348 
349  moveItem( item, delta );
350  updateView( item );
351  }
352 
354  }
355  //------------------------------------------------------------------------
356  // Handle cancel
357  //
358  else if( evt->IsCancelInteractive() )
359  {
360  if( m_moveInProgress )
361  {
362  evt->SetPassEvent( false );
363  restore_state = true;
364  }
365 
366  break;
367  }
368  //------------------------------------------------------------------------
369  // Handle TOOL_ACTION special cases
370  //
371  else if( evt->Action() == TA_UNDO_REDO_PRE )
372  {
373  unselect = true;
374  break;
375  }
376  else if( evt->IsAction( &ACTIONS::doDelete ) )
377  {
378  // Exit on a remove operation; there is no further processing for removed items.
379  break;
380  }
381  else if( evt->IsAction( &ACTIONS::duplicate ) )
382  {
383  if( selection.Front()->IsNew() )
384  {
385  // This doesn't really make sense; we'll just end up dragging a stack of
386  // objects so Duplicate() is going to ignore this and we'll just carry on.
387  continue;
388  }
389 
390  // Move original back and exit. The duplicate will run in its own loop.
391  restore_state = true;
392  unselect = false;
393  chain_commands = true;
394  break;
395  }
396  else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
397  {
398  if( evt->GetCommandId().get() >= ID_POPUP_SCH_SELECT_UNIT_CMP
400  {
401  SCH_COMPONENT* component = dynamic_cast<SCH_COMPONENT*>( selection.Front() );
402  int unit = evt->GetCommandId().get() - ID_POPUP_SCH_SELECT_UNIT_CMP;
403 
404  if( component )
405  {
406  m_frame->SelectUnit( component, unit );
408  }
409  }
410  }
411  //------------------------------------------------------------------------
412  // Handle context menu
413  //
414  else if( evt->IsClick( BUT_RIGHT ) )
415  {
417  }
418  //------------------------------------------------------------------------
419  // Handle drop
420  //
421  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
422  {
423  break; // Finish
424  }
425  else
426  evt->SetPassEvent();
427 
428  controls->SetAutoPan( m_moveInProgress );
429 
430  } while( ( evt = Wait() ) ); //Should be assignment not equality test
431 
432  controls->ForceCursorPosition( false );
433  controls->ShowCursor( false );
434  controls->SetAutoPan( false );
435 
436  if( !chain_commands )
437  m_moveOffset = { 0, 0 };
438 
439  m_anchorPos.reset();
440 
441  for( EDA_ITEM* item : selection )
442  item->ClearEditFlags();
443 
444  if( restore_state )
445  {
448  }
449  else
450  {
451  // Moving items changes the RTree box bounds.
452  for( auto item : selection )
453  {
454  switch( item->Type() )
455  {
456  // Moving sheet pins does not change the BBox.
457  case SCH_SHEET_PIN_T:
458  break;
459 
460  // Moving fields should update the associated component
461  case SCH_FIELD_T:
462  if( item->GetParent() )
463  m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( item->GetParent() ) );
464 
465  break;
466 
467  default:
468  m_frame->GetScreen()->Update( static_cast<SCH_ITEM*>( item ) );
469  }
470  }
471 
472  // If we move items away from a junction, we _may_ want to add a junction there
473  // to denote the state.
474  for( auto it : internalPoints )
475  {
476  if( m_frame->GetScreen()->IsJunctionNeeded( it.GetPosition(), true ) )
477  m_frame->AddJunction( m_frame->GetScreen(), it.GetPosition(), true, false );
478  }
479 
480  m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &selection );
482 
485 
486  m_frame->OnModify();
487  }
488 
489  if( unselect )
491  else
492  m_selectionTool->RebuildSelection(); // Schematic cleanup might have merged lines, etc.
493 
494  m_dragAdditions.clear();
495  m_moveInProgress = false;
496  m_frame->PopTool( tool );
497  return 0;
498 }
499 
500 
502  EDA_ITEMS& aList )
503 {
504  EE_RTREE& items = m_frame->GetScreen()->Items();
505 
506  for( SCH_ITEM *test : items.Overlapping( aOriginalItem->GetBoundingBox() ) )
507  {
508  if( test == aOriginalItem || test->IsSelected() || !test->CanConnect( aOriginalItem ) )
509  continue;
510 
511  KICAD_T testType = test->Type();
512 
513  switch( testType )
514  {
515  case SCH_LINE_T:
516  {
517  // Select the connected end of wires/bus connections.
518  SCH_LINE* testLine = static_cast<SCH_LINE*>( test );
519  wxPoint otherEnd;
520 
521  if( testLine->GetStartPoint() == aPoint )
522  {
523  if( !testLine->HasFlag( TEMP_SELECTED ) )
524  aList.push_back( testLine );
525 
526  testLine->SetFlags( STARTPOINT | TEMP_SELECTED );
527  otherEnd = testLine->GetEndPoint();
528  }
529  else if( testLine->GetEndPoint() == aPoint )
530  {
531  if( !testLine->HasFlag( TEMP_SELECTED ) )
532  aList.push_back( testLine );
533 
534  testLine->SetFlags( ENDPOINT | TEMP_SELECTED );
535  otherEnd = testLine->GetStartPoint();
536  }
537  else
538  {
539  break;
540  }
541 
542  // Since only one end is going to move, the movement vector of any labels attached
543  // to it is scaled by the proportion of the line length the label is from the moving
544  // end.
545  for( SCH_ITEM* item : m_frame->GetScreen()->Items().OfType( SCH_LABEL_T ) )
546  {
547  if( item->IsSelected() )
548  continue; // These will be moved on their own because they're selected
549 
550  if( item->CanConnect( testLine ) && testLine->HitTest( item->GetPosition(), 1 ) )
551  {
552  SCH_TEXT* label = static_cast<SCH_TEXT*>( item );
553 
554  if( !label->HasFlag( TEMP_SELECTED ) )
555  aList.push_back( label );
556 
558  info.attachedLine = testLine;
559  info.originalLabelPos = label->GetPosition();
560  m_specialCaseLabels[label] = info;
561  }
562  }
563 
564  break;
565  }
566 
567  case SCH_SHEET_T:
568  // Dragging a sheet just because it's connected to something else feels a bit like
569  // the tail wagging the dog, but this could be moved down to the next case.
570  break;
571 
572  case SCH_COMPONENT_T:
573  if( test->IsConnected( aPoint ) )
574  {
575  // Add a new wire between the component and the selected item so the selected
576  // item can be dragged.
577  SCH_LINE* newWire = new SCH_LINE( aPoint, LAYER_WIRE );
578  newWire->SetFlags( IS_NEW );
579  m_frame->AddToScreen( newWire, m_frame->GetScreen() );
580 
581  newWire->SetFlags( TEMP_SELECTED | STARTPOINT );
582  aList.push_back( newWire );
583  }
584  break;
585 
586  case SCH_NO_CONNECT_T:
587  case SCH_JUNCTION_T:
588  // Select no-connects and junctions that are connected to items being moved.
589  if( !test->HasFlag( TEMP_SELECTED ) && test->IsConnected( aPoint ) )
590  {
591  aList.push_back( test );
592  test->SetFlags( TEMP_SELECTED );
593  }
594 
595  break;
596 
597  case SCH_LABEL_T:
598  case SCH_GLOBAL_LABEL_T:
599  case SCH_HIER_LABEL_T:
601  case SCH_BUS_BUS_ENTRY_T:
602  // Performance optimization:
603  if( test->HasFlag( TEMP_SELECTED ) )
604  break;
605 
606  // Select labels and bus entries that are connected to a wire being moved.
607  if( aOriginalItem->Type() == SCH_LINE_T )
608  {
609  std::vector<wxPoint> connections = test->GetConnectionPoints();
610 
611  for( wxPoint& point : connections )
612  {
613  if( aOriginalItem->HitTest( point, 1 ) )
614  {
615  test->SetFlags( TEMP_SELECTED );
616  aList.push_back( test );
617 
618  // A bus entry needs its wire & label as well
619  if( testType == SCH_BUS_WIRE_ENTRY_T || testType == SCH_BUS_BUS_ENTRY_T )
620  {
621  std::vector<wxPoint> ends = test->GetConnectionPoints();
622  wxPoint otherEnd;
623 
624  if( ends[0] == point )
625  otherEnd = ends[1];
626  else
627  otherEnd = ends[0];
628 
629  getConnectedDragItems( test, otherEnd, aList );
630  }
631  break;
632  }
633  }
634  }
635 
636  break;
637 
638  default:
639  break;
640  }
641  }
642 }
643 
644 
645 void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
646 {
647  switch( aItem->Type() )
648  {
649  case SCH_LINE_T:
650  {
651  SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
652 
653  if( aItem->HasFlag( STARTPOINT ) )
654  line->MoveStart( (wxPoint) aDelta );
655 
656  if( aItem->HasFlag( ENDPOINT ) )
657  line->MoveEnd( (wxPoint) aDelta );
658 
659  }
660  break;
661 
662  case SCH_PIN_T:
663  case SCH_FIELD_T:
664  {
665  SCH_ITEM* parent = (SCH_ITEM*) aItem->GetParent();
666  wxPoint delta( aDelta );
667 
668  if( parent && parent->Type() == SCH_COMPONENT_T )
669  {
670  SCH_COMPONENT* component = (SCH_COMPONENT*) aItem->GetParent();
671  TRANSFORM transform = component->GetTransform().InverseTransform();
672 
673  delta = transform.TransformCoordinate( delta );
674  }
675 
676  static_cast<SCH_ITEM*>( aItem )->Move( delta );
677 
678  // If we're moving a field with respect to its parent then it's no longer auto-placed
679  if( aItem->Type() == SCH_FIELD_T && parent && !parent->IsSelected() )
680  parent->ClearFieldsAutoplaced();
681 
682  break;
683  }
684  case SCH_SHEET_PIN_T:
685  {
686  SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) aItem;
687  pin->SetStoredPos( pin->GetStoredPos() + (wxPoint) aDelta );
688  pin->ConstrainOnEdge( pin->GetStoredPos() );
689  break;
690  }
691  case SCH_LABEL_T:
692  {
693  SCH_TEXT* label = static_cast<SCH_TEXT*>( aItem );
694 
695  if( m_specialCaseLabels.count( label ) )
696  {
698  SEG currentLine( info.attachedLine->GetStartPoint(), info.attachedLine->GetEndPoint() );
699  label->SetPosition( (wxPoint) currentLine.NearestPoint( info.originalLabelPos ) );
700  }
701  else
702  label->Move( (wxPoint) aDelta );
703 
704  break;
705  }
706  default:
707  static_cast<SCH_ITEM*>( aItem )->Move( (wxPoint) aDelta );
708  break;
709  }
710 
711  getView()->Hide( aItem, false );
712  aItem->SetFlags( IS_MOVED );
713 }
714 
715 
717 {
718  EE_GRID_HELPER grid( m_toolMgr);
720  bool append_undo = false;
721 
722  for( EDA_ITEM* item : selection )
723  {
724  if( item->Type() == SCH_LINE_T )
725  {
726  SCH_LINE* line = static_cast<SCH_LINE*>( item );
727  std::vector<int> flags{ STARTPOINT, ENDPOINT };
728  std::vector<wxPoint> pts{ line->GetStartPoint(), line->GetEndPoint() };
729 
730  for( int ii = 0; ii < 2; ++ii )
731  {
732  EDA_ITEMS drag_items{ item };
733  line->ClearFlags();
734  line->SetFlags( flags[ii] );
735  getConnectedDragItems( line, pts[ii], drag_items );
736  std::set<EDA_ITEM*> unique_items( drag_items.begin(), drag_items.end() );
737 
738  VECTOR2I gridpt = grid.AlignGrid( pts[ii] ) - pts[ii];
739 
740  if( gridpt != VECTOR2I( 0, 0 ) )
741  {
742  for( auto dritem : unique_items )
743  {
744  if( dritem->GetParent() && dritem->GetParent()->IsSelected() )
745  continue;
746 
747  saveCopyInUndoList( dritem, UNDO_REDO::CHANGED, append_undo );
748  append_undo = true;
749 
750  moveItem( dritem, gridpt );
751  updateView( dritem );
752  }
753  }
754 
755  }
756  }
757  else
758  {
759  std::vector<wxPoint> connections;
760  EDA_ITEMS drag_items{ item };
761  connections = static_cast<SCH_ITEM*>( item )->GetConnectionPoints();
762 
763  for( wxPoint point : connections )
764  getConnectedDragItems( static_cast<SCH_ITEM*>( item ), point, drag_items );
765 
766  std::map<VECTOR2I, int> shifts;
767  VECTOR2I most_common( 0, 0 );
768  int max_count = 0;
769 
770  for( auto& conn : connections )
771  {
772  VECTOR2I gridpt = grid.AlignGrid( conn ) - conn;
773 
774  shifts[gridpt]++;
775 
776  if( shifts[gridpt] > max_count )
777  {
778  most_common = gridpt;
779  max_count = shifts[most_common];
780  }
781  }
782 
783  if( most_common != VECTOR2I( 0, 0 ) )
784  {
785  for( auto dritem : drag_items )
786  {
787  if( dritem->GetParent() && dritem->GetParent()->IsSelected() )
788  continue;
789 
790  saveCopyInUndoList( dritem, UNDO_REDO::CHANGED, append_undo );
791  append_undo = true;
792 
793  moveItem( dritem, most_common );
794  updateView( dritem );
795  }
796  }
797  }
798  }
799 
800 
802  m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &selection );
803 
806 
807  m_frame->OnModify();
808  return 0;
809 }
810 
811 
813 {
815  Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::move.MakeEvent() );
816  Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::drag.MakeEvent() );
818 }
static TOOL_ACTION moveActivate
Definition: ee_actions.h:113
void Hide(VIEW_ITEM *aItem, bool aHide=true)
Temporarily hides the item in the view (e.g.
Definition: view.cpp:1498
OPT< int > GetCommandId() const
Definition: tool_event.h:458
#define TEMP_SELECTED
flag indicating that the structure has already selected
Definition: base_struct.h:125
bool SchematicCleanUp(SCH_SCREEN *aScreen=nullptr)
Performs routine schematic cleaning including breaking wire and buses and deleting identical objects ...
TOOL_MENU m_menu
functions below are not yet implemented - their interface may change
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:104
bool IsHover() const
Definition: selection.h:71
void SetPassEvent(bool aPass=true)
Definition: tool_event.h:256
VECTOR2I BestDragOrigin(const VECTOR2I &aMousePos, std::vector< SCH_ITEM * > &aItem)
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void getConnectedDragItems(SCH_ITEM *aOriginalItem, wxPoint aPoint, EDA_ITEMS &aList)
Finds additional items for a drag operation.
wxPoint GetStartPoint() const
Definition: sch_line.h:94
bool IsSelected() const
Definition: base_struct.h:203
virtual bool IsMovableFromAnchorPoint()
Definition: sch_item.h:248
static TOOL_ACTION doDelete
Definition: actions.h:75
bool IsJunctionNeeded(const wxPoint &aPosition, bool aNew=false)
Test if a junction is required for the items at aPosition on the screen.
Definition: sch_screen.cpp:373
int Main(const TOOL_EVENT &aEvent)
Runs an interactive move of the selected items, or the item under the cursor.
VECTOR2I m_cursor
Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point).
Definition: sch_move_tool.h:88
void SetCurrentCursor(wxStockCursor aStockCursorID)
Function SetCurrentCursor Set the current cursor shape for this panel.
TOOL_ACTIONS Action() const
Returns more specific information about the type of an event.
Definition: tool_event.h:250
bool IsClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:178
VECTOR2I m_moveOffset
Used for chaining commands
Definition: sch_move_tool.h:84
static TOOL_ACTION restartMove
Definition: ee_actions.h:196
void MoveStart(const wxPoint &aMoveVector)
Definition: sch_line.cpp:119
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
EE_TYPE OfType(KICAD_T aType)
Definition: sch_rtree.h:219
EE_TYPE Overlapping(const EDA_RECT &aRect)
Definition: sch_rtree.h:224
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition: transform.cpp:59
TOOL_MENU & GetToolMenu()
bool IsMotion() const
Definition: tool_event.h:306
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:140
int AddItemsToSel(const TOOL_EVENT &aEvent)
Schematic editor (Eeschema) main window.
bool TestDanglingEnds()
Test all of the connectable objects in the schematic for unused connection points.
EE_RTREE - Implements an R-tree for fast spatial and type indexing of schematic items.
Definition: sch_rtree.h:41
bool m_moveInProgress
Flag determining if anything is being dragged right now
Definition: sch_move_tool.h:77
virtual wxPoint GetPosition() const
Definition: base_struct.h:337
VECTOR2< int > VECTOR2I
Definition: vector2d.h:594
static TOOL_ACTION alignToGrid
Definition: ee_actions.h:111
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
EDA_ITEMS m_dragAdditions
Items (such as wires) which were added to the selection for a drag
Definition: sch_move_tool.h:81
search types array terminator (End Of Types)
Definition: typeinfo.h:82
KICAD_T
Enum KICAD_T is the set of class identification values, stored in EDA_ITEM::m_StructType.
Definition: typeinfo.h:78
static const TOOL_EVENT SelectedItemsModified
Definition: actions.h:211
bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const override
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: sch_line.cpp:700
wxPoint TransformCoordinate(const wxPoint &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition: transform.cpp:42
bool IsNew() const
Definition: base_struct.h:199
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
SCH_JUNCTION * AddJunction(SCH_SCREEN *aScreen, const wxPoint &aPos, bool aAppendToUndo, bool aFinal=true)
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:69
EE_SELECTION & GetSelection()
Function GetSelection()
#define IS_NEW
New item, just created.
Definition: base_struct.h:117
EE_SELECTION & RequestSelection(const KICAD_T *aFilterList=EE_COLLECTOR::AllItems)
Function RequestSelection()
virtual bool HitTest(const wxPoint &aPosition, int aAccuracy=0) const
Function HitTest tests if aPosition is contained within or on the bounding box of an item.
Definition: base_struct.h:307
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
wxPoint & GetStoredPos()
Definition: sch_item.h:250
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:296
for transforming drawing coordinates for a wxDC device context.
Definition: transform.h:45
void Move(const wxPoint &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_text.h:278
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:232
std::map< SCH_TEXT *, SPECIAL_CASE_LABEL_INFO > m_specialCaseLabels
Definition: sch_move_tool.h:94
void saveCopyInUndoList(EDA_ITEM *aItem, UNDO_REDO aType, bool aAppend=false)
Similar to m_frame->SaveCopyInUndoList(), but handles items that are owned by their parents.
Definition: ee_tool_base.h:117
virtual void PopTool(const std::string &actionName)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: base_struct.h:588
TRANSFORM & GetTransform() const
boost::optional< VECTOR2I > m_anchorPos
Definition: sch_move_tool.h:90
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_EVENT.
Definition: tool_event.h:171
int AlignElements(const TOOL_EVENT &aEvent)
Aligns selected elements to the grid.
void ClearFieldsAutoplaced()
Set fields automatically placed flag false.
Definition: sch_item.h:447
EDA_ITEM * GetParent() const
Definition: base_struct.h:195
VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (such a...
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:160
static const TOOL_EVENT SelectedItemsMoved
Definition: actions.h:214
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet.h:84
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
bool m_isDragOperation
Definition: sch_move_tool.h:78
static TOOL_ACTION addNeededJunctions
Definition: ee_actions.h:75
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:301
void ConstrainOnEdge(wxPoint Pos)
Adjust label position to edge based on proximity to vertical or horizontal edge of the parent sheet.
wxPoint GetPosition() const override
Definition: sch_text.h:313
bool IsCancelInteractive()
Function IsCancelInteractive()
Definition: tool_event.cpp:190
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36
void SelectUnit(SCH_COMPONENT *aComponent, int aUnit)
Definition: getpart.cpp:196
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:121
Definition: seg.h:39
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:463
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
void updateView(EDA_ITEM *aItem) const
Similar to getView()->Update(), but handles items that are redrawn by their parents.
Definition: ee_tool_base.h:104
see class PGM_BASE
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen)
Add an item to the screen (and view) aScreen is the screen the item is located on,...
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:37
void MoveEnd(const wxPoint &aMoveVector)
Definition: sch_line.cpp:129
void moveItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
static TOOL_ACTION drag
Definition: ee_actions.h:115
void RollbackSchematicFromUndo()
Performs an undo of the last edit WITHOUT logging a corresponding redo.
EE_RTREE & Items()
Definition: sch_screen.h:158
#define ENDPOINT
ends. (Used to support dragging.)
Definition: base_struct.h:123
void RebuildSelection()
Rebuilds the selection from the EDA_ITEMs' selection flags.
VECTOR2I AlignGrid(const VECTOR2I &aPoint) const
Schematic symbol object.
Definition: sch_component.h:80
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:233
bool GetMoveWarpsCursor() const
Indicates that a move operation should warp the mouse pointer to the origin of the move object.
Definition: tools_holder.h:140
void Activate()
Function Activate() Runs the tool.
static TOOL_ACTION move
Definition: ee_actions.h:114
EE_TOOL_BASE.
Definition: ee_tool_base.h:50
static const KICAD_T movableItems[]
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag of the current screen and u...
void Update(SCH_ITEM *aItem)
Updates aItem's bounding box in the tree.
Definition: sch_screen.cpp:236
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes.
Definition: base_struct.cpp:97
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42
bool HasFlag(STATUS_FLAGS aFlag)
Definition: base_struct.h:235
#define QUIET_MODE
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
void setTransitions() override
Sets up handlers for various events.
void SetPosition(const wxPoint &aPosition) override
Definition: sch_text.h:314
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:273
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Adds a menu entry to run a TOOL_ACTION on selected items.
void SetStoredPos(wxPoint aPos)
Definition: sch_item.h:251
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:194
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:59
static TOOL_ACTION duplicate
Definition: actions.h:74
static TOOL_ACTION refreshPreview
Definition: actions.h:104
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:184
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193
#define STARTPOINT
When a line is selected, these flags indicate which.
Definition: base_struct.h:122
#define IS_MOVED
Item being moved.
Definition: base_struct.h:116
wxPoint GetEndPoint() const
Definition: sch_line.h:97