KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <algorithm>
22#include <cmath>
23#include <memory>
24#include <optional>
25#include <set>
26#include <wx/log.h>
27#include <wx/utils.h>
28#include <trigo.h>
30#include <tool/tool_manager.h>
35#include <tools/sch_move_tool.h>
36
37#include <sch_actions.h>
38#include <sch_commit.h>
39#include <eda_item.h>
40#include <sch_group.h>
41#include <sch_item.h>
42#include <sch_symbol.h>
43#include <sch_sheet.h>
44#include <sch_sheet_pin.h>
45#include <sch_line.h>
46#include <sch_connection.h>
47#include <sch_junction.h>
48#include <junction_helpers.h>
49#include <sch_edit_frame.h>
50#include <widgets/wx_infobar.h>
51#include <eeschema_id.h>
52#include <pgm_base.h>
53#include <view/view_controls.h>
55#include <math/box2.h>
56#include <base_units.h>
57#include <sch_screen.h>
58#include <sch_item_alignment.h>
59#include <trace_helpers.h>
60
61
62// For adding to or removing from selections
63#define QUIET_MODE true
64
65
66static bool isGraphicItemForDrop( const SCH_ITEM* aItem )
67{
68 switch( aItem->Type() )
69 {
70 case SCH_SHAPE_T:
71 case SCH_BITMAP_T:
72 case SCH_TEXT_T:
73 case SCH_TEXTBOX_T:
74 return true;
75 case SCH_LINE_T:
76 return static_cast<const SCH_LINE*>( aItem )->IsGraphicLine();
77 default:
78 return false;
79 }
80}
81
82
83static void cloneWireConnection( SCH_LINE* aNewLine, SCH_ITEM* aSource, SCH_EDIT_FRAME* aFrame )
84{
85 if( !aNewLine || !aSource || !aFrame )
86 return;
87
88 SCH_LINE* sourceLine = dynamic_cast<SCH_LINE*>( aSource );
89
90 if( !sourceLine )
91 return;
92
93 SCH_SHEET_PATH sheetPath = aFrame->GetCurrentSheet();
94 SCH_CONNECTION* sourceConnection = sourceLine->Connection( &sheetPath );
95
96 if( !sourceConnection )
97 return;
98
99 SCH_CONNECTION* newConnection = aNewLine->InitializeConnection( sheetPath, nullptr );
100
101 if( !newConnection )
102 return;
103
104 newConnection->Clone( *sourceConnection );
105}
106
107
109 SCH_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveMove" ),
110 m_inMoveTool( false ),
111 m_moveInProgress( false ),
112 m_mode( MOVE ),
113 m_moveOffset( 0, 0 )
114{
115}
116
117
119{
121
122 auto moveCondition =
123 []( const SELECTION& aSel )
124 {
125 if( aSel.Empty() || SELECTION_CONDITIONS::OnlyTypes( { SCH_MARKER_T } )( aSel ) )
126 return false;
127
129 return false;
130
131 return true;
132 };
133
134 // Add move actions to the selection tool menu
135 //
136 CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
137
138 selToolMenu.AddItem( SCH_ACTIONS::move, moveCondition, 150 );
139 selToolMenu.AddItem( SCH_ACTIONS::drag, moveCondition, 150 );
140 selToolMenu.AddItem( SCH_ACTIONS::alignToGrid, moveCondition, 150 );
141
142 return true;
143}
144
145
147{
148 SCH_TOOL_BASE::Reset( aReason );
149
150 if( aReason == MODEL_RELOAD || aReason == SUPERMODEL_RELOAD )
151 {
152 // If we were in the middle of a move/drag operation and the model changes (e.g., sheet
153 // switch), we need to clean up our state to avoid blocking future move/drag operations
154 if( m_moveInProgress )
155 {
156 // Clear the move state
157 m_moveInProgress = false;
158 m_mode = MOVE;
159 m_moveOffset = VECTOR2I( 0, 0 );
160 m_anchorPos.reset();
161 m_breakPos.reset();
162
163 // Clear cached data that references items from the previous sheet
164 m_dragAdditions.clear();
165 m_lineConnectionCache.clear();
166 m_newDragLines.clear();
167 m_changedDragLines.clear();
168 m_specialCaseLabels.clear();
170 m_hiddenJunctions.clear();
171
172 // Clear any preview
173 if( m_view )
174 m_view->ClearPreview();
175 }
176 }
177}
178
179
180void SCH_MOVE_TOOL::orthoLineDrag( SCH_COMMIT* aCommit, SCH_LINE* line, const VECTOR2I& splitDelta,
181 int& xBendCount, int& yBendCount, const EE_GRID_HELPER& grid )
182{
183 // If the move is not the same angle as this move, then we need to do something special with
184 // the unselected end to maintain orthogonality. Either drag some connected line that is the
185 // same angle as the move or add two lines to make a 90 degree connection
186 if( !EDA_ANGLE( splitDelta ).IsParallelTo( line->Angle() ) || line->GetLength() == 0 )
187 {
188 VECTOR2I unselectedEnd = line->HasFlag( STARTPOINT ) ? line->GetEndPoint()
189 : line->GetStartPoint();
190 VECTOR2I selectedEnd = line->HasFlag( STARTPOINT ) ? line->GetStartPoint()
191 : line->GetEndPoint();
192
193 // Look for pre-existing lines we can drag with us instead of creating new ones
194 bool foundAttachment = false;
195 bool foundJunction = false;
196 bool foundPin = false;
197 SCH_LINE* foundLine = nullptr;
198
199 for( EDA_ITEM* cItem : m_lineConnectionCache[line] )
200 {
201 foundAttachment = true;
202
203 // If the move is the same angle as a connected line, we can shrink/extend that line
204 // endpoint
205 switch( cItem->Type() )
206 {
207 case SCH_LINE_T:
208 {
209 SCH_LINE* cLine = static_cast<SCH_LINE*>( cItem );
210
211 // A matching angle on a non-zero-length line means lengthen/shorten will work
212 if( EDA_ANGLE( splitDelta ).IsParallelTo( cLine->Angle() )
213 && cLine->GetLength() != 0 )
214 {
215 foundLine = cLine;
216 }
217
218 // Zero length lines are lines that this algorithm has shortened to 0 so they also
219 // work but we should prefer using a segment with length and angle matching when
220 // we can (otherwise the zero length line will draw overlapping segments on them)
221 if( !foundLine && cLine->GetLength() == 0 )
222 foundLine = cLine;
223
224 break;
225 }
226 case SCH_JUNCTION_T:
227 foundJunction = true;
228 break;
229
230 case SCH_PIN_T:
231 foundPin = true;
232 break;
233
234 case SCH_SHEET_T:
235 for( const auto& pair : m_specialCaseSheetPins )
236 {
237 if( pair.first->IsConnected( selectedEnd ) )
238 {
239 foundPin = true;
240 break;
241 }
242 }
243
244 break;
245
246 default:
247 break;
248 }
249 }
250
251 // Ok... what if our original line is length zero from moving in its direction, and the
252 // last added segment of the 90 bend we are connected to is zero from moving it in its
253 // direction after it was added?
254 //
255 // If we are moving in original direction, we should lengthen the original drag wire.
256 // Otherwise we should lengthen the new wire.
257 bool preferOriginalLine = false;
258
259 if( foundLine
260 && foundLine->GetLength() == 0
261 && line->GetLength() == 0
262 && EDA_ANGLE( splitDelta ).IsParallelTo( line->GetStoredAngle() ) )
263 {
264 preferOriginalLine = true;
265 }
266 // If we have found an attachment, but not a line, we want to check if it's a junction.
267 // These are special-cased and get a single line added instead of a 90-degree bend. Except
268 // when we're on a pin, because pins always need bends, and junctions are just added to
269 // pins for visual clarity.
270 else if( !foundLine && foundJunction && !foundPin )
271 {
272 // Create a new wire ending at the unselected end
273 foundLine = new SCH_LINE( unselectedEnd, line->GetLayer() );
274 foundLine->SetFlags( IS_NEW );
275 foundLine->SetLastResolvedState( line );
276 cloneWireConnection( foundLine, line, m_frame );
277 m_frame->AddToScreen( foundLine, m_frame->GetScreen() );
278 m_newDragLines.insert( foundLine );
279
280 // We just broke off of the existing items, so replace all of them with our new
281 // end connection.
283 m_lineConnectionCache[line].clear();
284 m_lineConnectionCache[line].emplace_back( foundLine );
285 }
286
287 // We want to drag our found line if it's in the same angle as the move or zero length,
288 // but if the original drag line is also zero and the same original angle we should extend
289 // that one first
290 if( foundLine && !preferOriginalLine )
291 {
292 // Move the connected line found oriented in the direction of our move.
293 //
294 // Make sure we grab the right endpoint, it's not always STARTPOINT since the user can
295 // draw a box of lines. We need to only move one though, and preferably the start point,
296 // in case we have a zero length line that we are extending (we want the foundLine
297 // start point to be attached to the unselected end of our drag line).
298 //
299 // Also, new lines are added already so they'll be in the undo list, skip adding them.
300
301 if( !foundLine->HasFlag( IS_CHANGED ) && !foundLine->HasFlag( IS_NEW ) )
302 {
303 aCommit->Modify( (SCH_ITEM*) foundLine, m_frame->GetScreen() );
304
305 if( !foundLine->IsSelected() )
306 m_changedDragLines.insert( foundLine );
307 }
308
309 if( foundLine->GetStartPoint() == unselectedEnd )
310 foundLine->MoveStart( splitDelta );
311 else if( foundLine->GetEndPoint() == unselectedEnd )
312 foundLine->MoveEnd( splitDelta );
313
314 updateItem( foundLine, true );
315
316 SCH_LINE* bendLine = nullptr;
317
318 if( m_lineConnectionCache.count( foundLine ) == 1
319 && m_lineConnectionCache[foundLine][0]->Type() == SCH_LINE_T )
320 {
321 bendLine = static_cast<SCH_LINE*>( m_lineConnectionCache[foundLine][0] );
322 }
323
324 // Remerge segments we've created if this is a segment that we've added whose only
325 // other connection is also an added segment
326 //
327 // bendLine is first added segment at the original attachment point, foundLine is the
328 // orthogonal line between bendLine and this line
329 if( foundLine->HasFlag( IS_NEW )
330 && foundLine->GetLength() == 0
331 && bendLine && bendLine->HasFlag( IS_NEW ) )
332 {
333 if( line->HasFlag( STARTPOINT ) )
334 line->SetEndPoint( bendLine->GetEndPoint() );
335 else
336 line->SetStartPoint( bendLine->GetEndPoint() );
337
338 // Update our cache of the connected items.
339
340 // Re-attach drag labels from lines being deleted to the surviving line.
341 // This prevents dangling pointers when bendLine/foundLine are deleted below.
342 for( auto& [label, info] : m_specialCaseLabels )
343 {
344 if( info.attachedLine == bendLine || info.attachedLine == foundLine )
345 {
346 info.attachedLine = line;
347 info.originalLineStart = line->GetStartPoint();
348 info.originalLineEnd = line->GetEndPoint();
349 }
350 }
351
353 m_lineConnectionCache[bendLine].clear();
354 m_lineConnectionCache[foundLine].clear();
355
356 m_frame->RemoveFromScreen( bendLine, m_frame->GetScreen() );
357 m_frame->RemoveFromScreen( foundLine, m_frame->GetScreen() );
358
359 m_newDragLines.erase( bendLine );
360 m_newDragLines.erase( foundLine );
361
362 delete bendLine;
363 delete foundLine;
364 }
365 //Ok, move the unselected end of our item
366 else
367 {
368 if( line->HasFlag( STARTPOINT ) )
369 line->MoveEnd( splitDelta );
370 else
371 line->MoveStart( splitDelta );
372 }
373
374 updateItem( line, true );
375 }
376 else if( line->GetLength() == 0 )
377 {
378 // We didn't find another line to shorten/lengthen, (or we did but it's also zero)
379 // so now is a good time to use our existing zero-length original line
380 }
381 // Either no line was at the "right" angle, or this was a junction, pin, sheet, etc. We
382 // need to add segments to keep the soon-to-move unselected end connected to these items.
383 //
384 // To keep our drag selections all the same, we'll move our unselected end point and then
385 // put wires between it and its original endpoint.
386 else if( foundAttachment && line->IsOrthogonal() )
387 {
388 VECTOR2D lineGrid = grid.GetGridSize( grid.GetItemGrid( line ) );
389
390 // The bend counter handles a group of wires all needing their offset one grid movement
391 // further out from each other to not overlap. The absolute value stuff finds the
392 // direction of the line and hence the the bend increment on that axis
393 unsigned int xMoveBit = splitDelta.x != 0;
394 unsigned int yMoveBit = splitDelta.y != 0;
395 int xLength = abs( unselectedEnd.x - selectedEnd.x );
396 int yLength = abs( unselectedEnd.y - selectedEnd.y );
397 int xMove = ( xLength - ( xBendCount * lineGrid.x ) )
398 * sign( selectedEnd.x - unselectedEnd.x );
399 int yMove = ( yLength - ( yBendCount * lineGrid.y ) )
400 * sign( selectedEnd.y - unselectedEnd.y );
401
402 // Create a new wire ending at the unselected end, we'll move the new wire's start
403 // point to the unselected end
404 SCH_LINE* a = new SCH_LINE( unselectedEnd, line->GetLayer() );
405 a->MoveStart( VECTOR2I( xMove, yMove ) );
406 a->SetFlags( IS_NEW );
407 a->SetConnectivityDirty( true );
408 a->SetLastResolvedState( line );
409 cloneWireConnection( a, line, m_frame );
410 m_frame->AddToScreen( a, m_frame->GetScreen() );
411 m_newDragLines.insert( a );
412
413 SCH_LINE* b = new SCH_LINE( a->GetStartPoint(), line->GetLayer() );
414 b->MoveStart( VECTOR2I( splitDelta.x, splitDelta.y ) );
415 b->SetFlags( IS_NEW | STARTPOINT );
416 b->SetConnectivityDirty( true );
417 b->SetLastResolvedState( line );
418 cloneWireConnection( b, line, m_frame );
419 m_frame->AddToScreen( b, m_frame->GetScreen() );
420 m_newDragLines.insert( b );
421
422 xBendCount += yMoveBit;
423 yBendCount += xMoveBit;
424
425 // Ok move the unselected end of our item
426 if( line->HasFlag( STARTPOINT ) )
427 {
428 line->MoveEnd( VECTOR2I( splitDelta.x ? splitDelta.x : xMove,
429 splitDelta.y ? splitDelta.y : yMove ) );
430 }
431 else
432 {
433 line->MoveStart( VECTOR2I( splitDelta.x ? splitDelta.x : xMove,
434 splitDelta.y ? splitDelta.y : yMove ) );
435 }
436
437 // Update our cache of the connected items. First, attach our drag labels to the line
438 // left behind.
439 for( EDA_ITEM* candidate : m_lineConnectionCache[line] )
440 {
441 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( candidate );
442
443 if( !label || !m_specialCaseLabels.count( label ) )
444 continue;
445
446 if( label->GetPosition() == selectedEnd )
447 {
448 m_specialCaseLabels[label].trackMovingEnd = true;
449 }
450 else
451 {
452 m_specialCaseLabels[label].attachedLine = a;
453 m_specialCaseLabels[label].originalLineStart = a->GetStartPoint();
454 m_specialCaseLabels[label].originalLineEnd = a->GetEndPoint();
455 }
456 }
457
458 // We just broke off of the existing items, so replace all of them with our new end
459 // connection.
461 m_lineConnectionCache[b].emplace_back( a );
462 m_lineConnectionCache[line].clear();
463 m_lineConnectionCache[line].emplace_back( b );
464 }
465 // Original line has no attachments, just move the unselected end
466 else if( !foundAttachment )
467 {
468 if( line->HasFlag( STARTPOINT ) )
469 line->MoveEnd( splitDelta );
470 else
471 line->MoveStart( splitDelta );
472 }
473 }
474}
475
476
477int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
478{
479 if( aEvent.IsAction( &SCH_ACTIONS::drag ) )
480 m_mode = DRAG;
481 else if( aEvent.IsAction( &SCH_ACTIONS::breakWire ) )
482 m_mode = BREAK;
483 else if( aEvent.IsAction( &SCH_ACTIONS::slice ) )
484 m_mode = SLICE;
485 else
486 m_mode = MOVE;
487
488 if( SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() ) )
489 {
490 wxCHECK( aEvent.SynchronousState(), 0 );
491 aEvent.SynchronousState()->store( STS_RUNNING );
492
493 if( doMoveSelection( aEvent, commit ) )
494 aEvent.SynchronousState()->store( STS_FINISHED );
495 else
496 aEvent.SynchronousState()->store( STS_CANCELLED );
497 }
498 else
499 {
500 SCH_COMMIT localCommit( m_toolMgr );
501
502 if( doMoveSelection( aEvent, &localCommit ) )
503 {
504 switch( m_mode )
505 {
506 case MOVE: localCommit.Push( _( "Move" ) ); break;
507 case DRAG: localCommit.Push( _( "Drag" ) ); break;
508 case BREAK: localCommit.Push( _( "Break Wire" ) ); break;
509 case SLICE: localCommit.Push( _( "Slice Wire" ) ); break;
510 }
511 }
512 else
513 {
514 localCommit.Revert();
515 }
516 }
517
518 return 0;
519}
520
521
523{
524 if( m_mode != BREAK && m_mode != SLICE )
525 return;
526
527 if( !aCommit )
528 return;
529
531
532 if( !lwbTool )
533 return;
534
535 SCH_SELECTION& selection = m_selectionTool->GetSelection();
536
537 if( selection.Empty() )
538 return;
539
540 std::vector<SCH_LINE*> lines;
541
542 for( EDA_ITEM* item : selection )
543 {
544 if( item->Type() == SCH_LINE_T )
545 {
546 // This function gets called every time segments are broken, which can also be for subsequent
547 // breaks in a loop without leaving the current move tool.
548 // Skip already placed segments (segment keeps IS_BROKEN but will have IS_NEW cleared below)
549 // so that only the actively placed tail segment gets split again.
550 if( item->HasFlag( IS_BROKEN ) && !item->HasFlag( IS_NEW ) )
551 continue;
552
553 lines.push_back( static_cast<SCH_LINE*>( item ) );
554 }
555 }
556
557 if( lines.empty() )
558 return;
559
561 SCH_SCREEN* screen = m_frame->GetScreen();
562 VECTOR2I cursorPos = controls->GetCursorPosition( !aEvent.DisableGridSnapping() );
563
564 bool useCursorForSingleLine = false;
565
566 if( lines.size() == 1 )
567 useCursorForSingleLine = true;
568
569 m_selectionTool->ClearSelection();
570 m_breakPos.reset();
571
572 for( SCH_LINE* line : lines )
573 {
574 VECTOR2I breakPos = useCursorForSingleLine ? cursorPos : line->GetMidPoint();
575
576 if( m_mode == BREAK && !m_breakPos )
577 m_breakPos = breakPos;
578
579 SCH_LINE* newLine = nullptr;
580
581 lwbTool->BreakSegment( aCommit, line, breakPos, &newLine, screen );
582
583 if( !newLine )
584 continue;
585
586 // If this is a second+ round break, we need to get rid of the IS_NEW flag since the new segment
587 // is now an existing segment we are breaking from, this will be checked for in the line selection
588 // gathering above
589 line->ClearFlags( STARTPOINT | IS_NEW );
590 line->SetFlags( ENDPOINT );
591 m_selectionTool->AddItemToSel( line );
592
593 newLine->ClearFlags( ENDPOINT | STARTPOINT );
594
595 if( m_mode == BREAK )
596 {
597 m_selectionTool->AddItemToSel( newLine );
598 newLine->SetFlags( STARTPOINT );
599 }
600 }
601}
602
603
605{
608 bool currentModeIsDragLike = ( m_mode != MOVE );
609 bool wasDragging = m_moveInProgress && currentModeIsDragLike;
610 bool didAtLeastOneBreak = false;
611
612 m_anchorPos.reset();
613
614 // Check if already in progress and handle state transitions
615 if( checkMoveInProgress( aEvent, aCommit, currentModeIsDragLike, wasDragging ) )
616 return false;
617
618 if( m_inMoveTool ) // Must come after m_moveInProgress checks above...
619 return false;
620
622
623 preprocessBreakOrSliceSelection( aCommit, aEvent );
624
625 // Prepare selection (promote pins to symbols, request selection)
626 bool unselect = false;
627 SCH_SELECTION& selection = prepareSelection( unselect );
628
629 // Keep an original copy of the starting points for cleanup after the move
630 std::vector<DANGLING_END_ITEM> internalPoints;
631
632 // Track selection characteristics
633 bool selectionHasSheetPins = false;
634 bool selectionHasGraphicItems = false;
635 bool selectionHasNonGraphicItems = false;
636 bool selectionIsGraphicsOnly = false;
637
638 std::unique_ptr<SCH_DRAG_NET_COLLISION_MONITOR> netCollisionMonitor;
639
640 auto refreshTraits =
641 [&]()
642 {
643 refreshSelectionTraits( selection, selectionHasSheetPins, selectionHasGraphicItems,
644 selectionHasNonGraphicItems, selectionIsGraphicsOnly );
645 };
646
647 refreshTraits();
648
649 if( !selection.Empty() )
650
651 {
652 netCollisionMonitor = std::make_unique<SCH_DRAG_NET_COLLISION_MONITOR>( m_frame, m_view );
653 netCollisionMonitor->Initialize( selection );
654 }
655
656 bool lastCtrlDown = false;
657
658 // When items are pasted via Ctrl+V, the Ctrl key is still held when the move tool
659 // starts. Ctrl disables grid snapping, so the pasted items would track off-grid.
660 // The synthetic move action event carries no modifier bits, so query the live
661 // keyboard state and ignore Ctrl until the user releases and re-presses it.
662 bool pasteHoldingCtrl = false;
663
664 for( EDA_ITEM* item : selection )
665 {
666 if( item->HasFlag( IS_PASTED ) )
667 {
668 pasteHoldingCtrl = wxGetKeyState( WXK_CONTROL );
669 break;
670 }
671 }
672
673 Activate();
674
675 // Must be done after Activate() so that it gets set into the correct context
676 controls->ShowCursor( true );
677
678 m_frame->PushTool( aEvent );
679
680 if( selection.Empty() )
681 {
682 // Note that it's important to go through push/pop even when the selection is empty.
683 // This keeps other tools from having to special-case an empty move.
684 m_frame->PopTool( aEvent );
685 return false;
686 }
687
688 bool restore_state = false;
689 TOOL_EVENT copy = aEvent;
690 TOOL_EVENT* evt = &copy;
691 VECTOR2I prevPos = controls->GetCursorPosition();
693 SCH_SHEET* hoverSheet = nullptr;
694 KICURSOR currentCursor = KICURSOR::MOVING;
695 m_cursor = controls->GetCursorPosition();
696
697 // Axis locking for arrow key movement
698 enum class AXIS_LOCK { NONE, HORIZONTAL, VERTICAL };
699 AXIS_LOCK axisLock = AXIS_LOCK::NONE;
700 long lastArrowKeyAction = 0;
701
702 // Main loop: keep receiving events
703 do
704 {
705 wxLogTrace( traceSchMove, "doMoveSelection: event loop iteration, evt=%s, action=%s",
706 evt->Category() == TC_MOUSE ? "MOUSE" :
707 evt->Category() == TC_KEYBOARD ? "KEYBOARD" :
708 evt->Category() == TC_COMMAND ? "COMMAND" : "OTHER",
709 evt->Format().c_str() );
710
711 m_frame->GetCanvas()->SetCurrentCursor( currentCursor );
712 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
713
714 bool ctrlDown = evt->Modifier( MD_CTRL );
715
716 // Only real input events carry modifier state; the synthetic move action does not.
717 bool hasModifierState = evt->Category() == TC_MOUSE || evt->Category() == TC_KEYBOARD;
718
719 if( pasteHoldingCtrl && hasModifierState && !ctrlDown )
720 pasteHoldingCtrl = false;
721
722 // The paste-held Ctrl only masks grid snapping. Ctrl also forces a graphics-only drop
723 // into a sheet, and that gesture must still honor a physically-held key.
724 bool gridSnapDisabled = ctrlDown && !pasteHoldingCtrl;
725
726 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !gridSnapDisabled );
727
728 lastCtrlDown = ctrlDown;
729
731 || evt->IsAction( &SCH_ACTIONS::move )
732 || evt->IsAction( &SCH_ACTIONS::drag )
733 || evt->IsMotion()
734 || evt->IsDrag( BUT_LEFT )
736 {
737 refreshTraits();
738
739 if( !m_moveInProgress ) // Prepare to start moving/dragging
740 {
741 initializeMoveOperation( aEvent, selection, aCommit, internalPoints, snapLayer );
742 prevPos = m_cursor;
743 refreshTraits();
744 }
745
746 //------------------------------------------------------------------------
747 // Follow the mouse
748 //
749 m_view->ClearPreview();
750
751 // We need to bypass refreshPreview action here because it is triggered by the move, so we were
752 // getting double-key events that toggled the axis locking if you pressed them in a certain order.
754 {
755 VECTOR2I keyboardPos( controls->GetSettings().m_lastKeyboardCursorPosition );
756 long action = controls->GetSettings().m_lastKeyboardCursorCommand;
757
758 grid.SetSnap( false );
759 m_cursor = grid.Align( keyboardPos, snapLayer );
760
761 // Update axis lock based on arrow key press
762 if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
763 {
764 if( axisLock == AXIS_LOCK::HORIZONTAL )
765 {
766 // Check if opposite horizontal key pressed to unlock
767 if( ( lastArrowKeyAction == ACTIONS::CURSOR_LEFT && action == ACTIONS::CURSOR_RIGHT ) ||
768 ( lastArrowKeyAction == ACTIONS::CURSOR_RIGHT && action == ACTIONS::CURSOR_LEFT ) )
769 {
770 axisLock = AXIS_LOCK::NONE;
771 }
772 // Same direction axis, keep locked
773 }
774 else
775 {
776 axisLock = AXIS_LOCK::HORIZONTAL;
777 }
778 }
779 else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
780 {
781 if( axisLock == AXIS_LOCK::VERTICAL )
782 {
783 // Check if opposite vertical key pressed to unlock
784 if( ( lastArrowKeyAction == ACTIONS::CURSOR_UP && action == ACTIONS::CURSOR_DOWN ) ||
785 ( lastArrowKeyAction == ACTIONS::CURSOR_DOWN && action == ACTIONS::CURSOR_UP ) )
786 {
787 axisLock = AXIS_LOCK::NONE;
788 }
789 // Same direction axis, keep locked
790 }
791 else
792 {
793 axisLock = AXIS_LOCK::VERTICAL;
794 }
795 }
796
797 lastArrowKeyAction = action;
798 }
799 else
800 {
801 m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ), snapLayer, selection );
802 }
803
804 if( axisLock == AXIS_LOCK::HORIZONTAL )
805 m_cursor.y = prevPos.y;
806 else if( axisLock == AXIS_LOCK::VERTICAL )
807 m_cursor.x = prevPos.x;
808
809 // Find potential target sheet for dropping. This relocation is only meaningful for a
810 // plain move; drag/break/slice reshape existing connections in place and must never
811 // pull items onto a sub-sheet's screen.
812 SCH_SHEET* sheet = nullptr;
813
814 if( m_mode == MOVE )
815 sheet = findTargetSheet( selection, m_cursor, selectionHasSheetPins, selectionIsGraphicsOnly,
816 ctrlDown );
817
818 if( sheet != hoverSheet )
819 {
820 hoverSheet = sheet;
821
822 if( hoverSheet )
823 {
824 hoverSheet->SetFlags( BRIGHTENED );
825 m_frame->UpdateItem( hoverSheet, false );
826 }
827 }
828
829 currentCursor = hoverSheet ? KICURSOR::PLACE : KICURSOR::MOVING;
830
831 if( netCollisionMonitor )
832 currentCursor = netCollisionMonitor->AdjustCursor( currentCursor );
833
834 VECTOR2I delta( m_cursor - prevPos );
836
837 // Used for tracking how far off a drag end should have its 90 degree elbow added
838 int xBendCount = 1;
839 int yBendCount = 1;
840
841 performItemMove( selection, delta, aCommit, xBendCount, yBendCount, grid );
842 prevPos = m_cursor;
843
844 std::vector<SCH_ITEM*> previewItems;
845
846 for( EDA_ITEM* it : selection )
847 previewItems.push_back( static_cast<SCH_ITEM*>( it ) );
848
849 for( SCH_LINE* line : m_newDragLines )
850 previewItems.push_back( line );
851
852 for( SCH_LINE* line : m_changedDragLines )
853 previewItems.push_back( line );
854
855 std::vector<SCH_JUNCTION*> previewJunctions =
856 JUNCTION_HELPERS::PreviewJunctions( m_frame->GetScreen(), previewItems );
857
858 if( netCollisionMonitor )
859 netCollisionMonitor->Update( previewJunctions, selection );
860
861 for( SCH_JUNCTION* jct : previewJunctions )
862 m_view->AddToPreview( jct, true );
863
865 }
866
867 //------------------------------------------------------------------------
868 // Handle cancel
869 //
870 else if( evt->IsCancelInteractive()
871 || evt->IsActivate()
872 || evt->IsAction( &ACTIONS::undo ) )
873 {
874 if( evt->IsCancelInteractive() )
875 {
876 m_frame->GetInfoBar()->Dismiss();
877
878 // When breaking, the user can cancel after multiple breaks to keep all but the last
879 // break, so exit normally if we have done at least one break
880 if( didAtLeastOneBreak && m_mode == BREAK )
881 break;
882 }
883
884 if( m_moveInProgress )
885 {
886 if( evt->IsActivate() )
887 {
888 // Allowing other tools to activate during a move runs the risk of race
889 // conditions in which we try to spool up both event loops at once.
890
891 switch( m_mode )
892 {
893 case MOVE: m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel move." ) ); break;
894 case DRAG: m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel drag." ) ); break;
895 case BREAK: m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel break." ) ); break;
896 case SLICE: m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel slice." ) ); break;
897 }
898
899 evt->SetPassEvent( false );
900 continue;
901 }
902
903 evt->SetPassEvent( false );
904 restore_state = true;
905 }
906 else if( m_mode == BREAK || m_mode == SLICE )
907 {
908 // preprocessBreakOrSliceSelection() split the wire before any motion arrived,
909 // so cancel must roll those edits back. Activations still pass through so the
910 // requested tool starts.
911 if( !evt->IsActivate() )
912 evt->SetPassEvent( false );
913
914 restore_state = true;
915 }
916
918
919 m_view->ClearPreview();
920
921 break;
922 }
923 //------------------------------------------------------------------------
924 // Handle TOOL_ACTION special cases
925 //
926 else if( !handleMoveToolActions( evt, aCommit, selection ) )
927 {
928 wxLogTrace( traceSchMove, "doMoveSelection: handleMoveToolActions returned false, exiting" );
929 break; // Exit if told to by handler
930 }
931 //------------------------------------------------------------------------
932 // Handle context menu
933 //
934 else if( evt->IsClick( BUT_RIGHT ) )
935 {
936 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
937 }
938 //------------------------------------------------------------------------
939 // Handle drop
940 //
941 else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
942 {
943 if( m_mode != BREAK )
944 break; // Finish
945 else
946 {
947 didAtLeastOneBreak = true;
948 preprocessBreakOrSliceSelection( aCommit, *evt );
949 selection = m_selectionTool->RequestSelection( SCH_COLLECTOR::MovableItems, true );
950
951 if( m_breakPos )
952 {
955 selection.SetReferencePoint( m_cursor );
956 m_moveOffset = VECTOR2I( 0, 0 );
957 m_breakPos.reset();
958
959 controls->SetCursorPosition( m_cursor, false );
960 prevPos = m_cursor;
961 }
962 }
963 }
964 else if( evt->IsDblClick( BUT_LEFT ) )
965 {
966 // Double click always finishes, even breaks
967 break;
968 }
969 // Don't call SetPassEvent() for events we've handled - let them be consumed
970 else if( evt->IsAction( &SCH_ACTIONS::rotateCW )
972 || evt->IsAction( &ACTIONS::increment )
977 || evt->IsAction( &SCH_ACTIONS::toText )
981 || evt->IsAction( &ACTIONS::duplicate )
983 || evt->IsAction( &ACTIONS::redo ) )
984 {
985 // Event was already handled by handleMoveToolActions, don't pass it on
986 wxLogTrace( traceSchMove, "doMoveSelection: event handled, not passing" );
987 }
988 else
989 {
990 evt->SetPassEvent();
991 }
992
993 controls->SetAutoPan( m_moveInProgress );
994
995 } while( ( evt = Wait() ) ); //Should be assignment not equality test
996
997 SCH_SHEET* targetSheet = hoverSheet;
998
999 if( selectionHasSheetPins || ( selectionIsGraphicsOnly && !lastCtrlDown ) )
1000 targetSheet = nullptr;
1001
1002 if( hoverSheet )
1003 {
1004 hoverSheet->ClearFlags( BRIGHTENED );
1005 m_frame->UpdateItem( hoverSheet, false );
1006 }
1007
1008 if( restore_state )
1009 {
1010 m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
1011
1012 // Clear the split-segment selection that preprocessBreakOrSliceSelection() built
1013 // before the caller's Revert() runs. Revert() rebuilds selection from the screen,
1014 // so leaving the splits selected keeps the restored wire hidden until the next
1015 // selection refresh.
1016 if( m_mode == BREAK || m_mode == SLICE )
1017 m_toolMgr->RunAction( ACTIONS::selectionClear );
1018 }
1019 else
1020 {
1021 // Only drop into a sheet when the move is committed, not when canceled.
1022 if( targetSheet )
1023 {
1024 moveSelectionToSheet( selection, targetSheet, aCommit );
1025 m_toolMgr->RunAction( ACTIONS::selectionClear );
1026 m_newDragLines.clear();
1027 m_changedDragLines.clear();
1028 }
1029
1030 finalizeMoveOperation( selection, aCommit, unselect, internalPoints );
1031 }
1032
1033 m_dragAdditions.clear();
1034 m_lineConnectionCache.clear();
1035 m_moveInProgress = false;
1036 m_breakPos.reset();
1037
1038 m_hiddenJunctions.clear();
1039 m_view->ClearPreview();
1040 m_frame->PopTool( aEvent );
1041
1042 return !restore_state;
1043}
1044
1045
1046bool SCH_MOVE_TOOL::checkMoveInProgress( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit, bool aCurrentModeIsDragLike,
1047 bool aWasDragging )
1048{
1050
1051 if( !m_moveInProgress )
1052 return false;
1053
1054 if( aCurrentModeIsDragLike != aWasDragging )
1055 {
1056 EDA_ITEM* sel = m_selectionTool->GetSelection().Front();
1057
1058 if( sel && !sel->IsNew() )
1059 {
1060 // Reset the selected items so we can start again with the current drag mode state
1061 aCommit->Revert();
1062
1063 m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
1065 m_moveInProgress = false;
1066 controls->SetAutoPan( false );
1067
1068 // Give it a kick so it doesn't have to wait for the first mouse movement to refresh
1069 m_toolMgr->PostAction( SCH_ACTIONS::restartMove );
1070 }
1071 }
1072 else
1073 {
1074 // The tool hotkey is interpreted as a click when already dragging/moving
1075 m_toolMgr->PostAction( ACTIONS::cursorClick );
1076 }
1077
1078 return true;
1079}
1080
1081
1083{
1084 SCH_SELECTION& userSelection = m_selectionTool->GetSelection();
1085
1086 // If a single pin is selected, promote the move selection to its parent symbol
1087 if( userSelection.GetSize() == 1 )
1088 {
1089 EDA_ITEM* selItem = userSelection.Front();
1090
1091 if( selItem->Type() == SCH_PIN_T )
1092 {
1093 EDA_ITEM* parent = selItem->GetParent();
1094
1095 if( parent->Type() == SCH_SYMBOL_T )
1096 {
1097 m_selectionTool->ClearSelection();
1098 m_selectionTool->AddItemToSel( parent );
1099 }
1100 }
1101 }
1102
1103 // Be sure that there is at least one item that we can move. If there's no selection try
1104 // looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection).
1105 SCH_SELECTION& selection = m_selectionTool->RequestSelection( SCH_COLLECTOR::MovableItems, true );
1106 aUnselect = selection.IsHover();
1107
1108 m_selectionTool->FilterSelectionForLockedItems();
1109
1110 return selection;
1111}
1112
1113
1114void SCH_MOVE_TOOL::refreshSelectionTraits( const SCH_SELECTION& aSelection, bool& aHasSheetPins,
1115 bool& aHasGraphicItems, bool& aHasNonGraphicItems,
1116 bool& aIsGraphicsOnly )
1117{
1118 aHasSheetPins = false;
1119 aHasGraphicItems = false;
1120 aHasNonGraphicItems = false;
1121
1122 for( EDA_ITEM* edaItem : aSelection )
1123 {
1124 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( edaItem );
1125
1126 if( schItem->Type() == SCH_SHEET_PIN_T )
1127 aHasSheetPins = true;
1128
1129 if( isGraphicItemForDrop( schItem ) )
1130 aHasGraphicItems = true;
1131 else if( schItem->Type() != SCH_SHEET_T )
1132 aHasNonGraphicItems = true;
1133 }
1134
1135 aIsGraphicsOnly = aHasGraphicItems && !aHasNonGraphicItems;
1136}
1137
1138
1140{
1141 // Drag of split items start over top of their other segment, so we want to skip grabbing
1142 // the segments we split from
1143 if( m_mode != DRAG && m_mode != BREAK )
1144 return;
1145
1146 EDA_ITEMS connectedDragItems;
1147
1148 // Add connections to the selection for a drag.
1149 // Do all non-labels/entries first so we don't add junctions to drag when the line will
1150 // eventually be drag selected.
1151 std::vector<SCH_ITEM*> stageTwo;
1152
1153 for( EDA_ITEM* edaItem : aSelection )
1154 {
1155 SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
1156 std::vector<VECTOR2I> connections;
1157
1158 switch( item->Type() )
1159 {
1160 case SCH_LABEL_T:
1161 case SCH_HIER_LABEL_T:
1162 case SCH_GLOBAL_LABEL_T:
1164 stageTwo.emplace_back( item );
1165 break;
1166
1167 case SCH_LINE_T:
1168 static_cast<SCH_LINE*>( item )->GetSelectedPoints( connections );
1169 break;
1170
1171 default:
1172 connections = item->GetConnectionPoints();
1173 }
1174
1175 for( const VECTOR2I& point : connections )
1176 getConnectedDragItems( aCommit, item, point, connectedDragItems );
1177 }
1178
1179 // Go back and get all label connections now that we can test for drag-selected lines
1180 // the labels might be on
1181 for( SCH_ITEM* item : stageTwo )
1182 {
1183 for( const VECTOR2I& point : item->GetConnectionPoints() )
1184 getConnectedDragItems( aCommit, item, point, connectedDragItems );
1185 }
1186
1187 for( EDA_ITEM* item : connectedDragItems )
1188 {
1189 m_dragAdditions.push_back( item->m_Uuid );
1190 m_selectionTool->AddItemToSel( item, QUIET_MODE );
1191 }
1192
1193 // Pre-cache all connections of our selected objects so we can keep track of what they
1194 // were originally connected to as we drag them around
1195 for( EDA_ITEM* edaItem : aSelection )
1196 {
1197 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( edaItem );
1198
1199 if( schItem->Type() == SCH_LINE_T )
1200 {
1201 SCH_LINE* line = static_cast<SCH_LINE*>( schItem );
1202
1203 // Store the original angle of the line; needed later to decide which segment
1204 // to extend when they've become zero length
1205 line->StoreAngle();
1206
1207 for( const VECTOR2I& point : line->GetConnectionPoints() )
1208 getConnectedItems( line, point, m_lineConnectionCache[line] );
1209 }
1210 }
1211}
1212
1213
1214void SCH_MOVE_TOOL::setupItemsForMove( SCH_SELECTION& aSelection, std::vector<DANGLING_END_ITEM>& aInternalPoints )
1215{
1216 // Mark the edges of the block with dangling flags for a move
1217 for( EDA_ITEM* item : aSelection )
1218 static_cast<SCH_ITEM*>( item )->GetEndPoints( aInternalPoints );
1219
1220 std::vector<DANGLING_END_ITEM> endPointsByType = aInternalPoints;
1221 std::vector<DANGLING_END_ITEM> endPointsByPos = endPointsByType;
1222 DANGLING_END_ITEM_HELPER::sort_dangling_end_items( endPointsByType, endPointsByPos );
1223
1224 for( EDA_ITEM* item : aSelection )
1225 static_cast<SCH_ITEM*>( item )->UpdateDanglingState( endPointsByType, endPointsByPos );
1226}
1227
1228
1230 std::vector<DANGLING_END_ITEM>& aInternalPoints,
1231 GRID_HELPER_GRIDS& aSnapLayer )
1232{
1235 SCH_ITEM* sch_item = static_cast<SCH_ITEM*>( aSelection.Front() );
1236 bool placingNewItems = sch_item && sch_item->IsNew();
1237
1238 //------------------------------------------------------------------------
1239 // Setup a drag or a move
1240 //
1241 m_dragAdditions.clear();
1242 m_specialCaseLabels.clear();
1243 m_specialCaseSheetPins.clear();
1244 aInternalPoints.clear();
1246
1247 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
1248 {
1249 it->ClearFlags( SELECTED_BY_DRAG );
1250
1251 if( !it->IsSelected() )
1252 it->ClearFlags( STARTPOINT | ENDPOINT );
1253 }
1254
1255 setupItemsForDrag( aSelection, aCommit );
1256 setupItemsForMove( aSelection, aInternalPoints );
1257
1258 // Hide junctions connected to line endpoints that are not selected
1259 m_hiddenJunctions.clear();
1260
1261 for( EDA_ITEM* item : aSelection )
1262 item->SetFlags( STRUCT_DELETED );
1263
1264 for( EDA_ITEM* edaItem : aSelection )
1265 {
1266 if( edaItem->Type() != SCH_LINE_T )
1267 continue;
1268
1269 SCH_LINE* line = static_cast<SCH_LINE*>( edaItem );
1270
1271 for( const VECTOR2I& pt : line->GetConnectionPoints() )
1272 {
1273 SCH_JUNCTION* jct = static_cast<SCH_JUNCTION*>( m_frame->GetScreen()->GetItem( pt, 0, SCH_JUNCTION_T ) );
1274
1275 if( jct && !jct->IsSelected()
1276 && std::find( m_hiddenJunctions.begin(), m_hiddenJunctions.end(), jct ) == m_hiddenJunctions.end() )
1277 {
1279 pt, false );
1280
1281 if( !info.isJunction )
1282 {
1283 jct->SetFlags( STRUCT_DELETED );
1284 m_frame->RemoveFromScreen( jct, m_frame->GetScreen() );
1285 aCommit->Removed( jct, m_frame->GetScreen() );
1286 }
1287 }
1288 }
1289 }
1290
1291 for( EDA_ITEM* item : aSelection )
1292 item->ClearFlags( STRUCT_DELETED );
1293
1294 // Generic setup
1295 aSnapLayer = grid.GetSelectionGrid( aSelection );
1296
1297 for( EDA_ITEM* item : aSelection )
1298 {
1299 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1300
1301 if( schItem->IsNew() )
1302 {
1303 // Item was added to commit in a previous command
1304
1305 // While SCH_COMMIT::Push() will add any new items to the entered group, we need
1306 // to do it earlier so that the previews while moving are correct.
1307 if( SCH_GROUP* enteredGroup = m_selectionTool->GetEnteredGroup() )
1308 {
1309 if( schItem->IsGroupableType() && !schItem->GetParentGroup() )
1310 {
1311 aCommit->Modify( enteredGroup, m_frame->GetScreen(), RECURSE_MODE::NO_RECURSE );
1312 enteredGroup->AddItem( schItem );
1313 }
1314 }
1315 }
1316 else if( schItem->GetParent() && schItem->GetParent()->IsSelected() )
1317 {
1318 // Item will be (or has been) added to commit by parent
1319 }
1320 else
1321 {
1322 aCommit->Modify( schItem, m_frame->GetScreen(), RECURSE_MODE::RECURSE );
1323 }
1324
1325 schItem->SetFlags( IS_MOVING );
1326
1327 if( SCH_SHAPE* shape = dynamic_cast<SCH_SHAPE*>( schItem ) )
1328 {
1329 shape->SetHatchingDirty();
1330 shape->UpdateHatching();
1331 }
1332
1333 schItem->RunOnChildren(
1334 [&]( SCH_ITEM* aChild )
1335 {
1336 aChild->SetFlags( IS_MOVING );
1337 },
1339
1340 schItem->SetStoredPos( schItem->GetPosition() );
1341 }
1342
1343 // Set up the starting position and move/drag offset
1344 m_cursor = controls->GetCursorPosition();
1345
1346 if( m_mode == BREAK && m_breakPos )
1347 {
1350 aSelection.SetReferencePoint( m_cursor );
1351 m_moveOffset = VECTOR2I( 0, 0 );
1352 m_breakPos.reset();
1353 }
1354
1355 if( aEvent.IsAction( &SCH_ACTIONS::restartMove ) )
1356 {
1357 wxASSERT_MSG( m_anchorPos, "Should be already set from previous cmd" );
1358 }
1359 else if( placingNewItems )
1360 {
1361 m_anchorPos = aSelection.GetReferencePoint();
1362 }
1363
1364 if( m_anchorPos )
1365 {
1366 VECTOR2I delta = m_cursor - ( *m_anchorPos );
1367 bool isPasted = false;
1368
1369 // Drag items to the current cursor position
1370 for( EDA_ITEM* item : aSelection )
1371 {
1372 // Don't double move pins, fields, etc.
1373 if( item->GetParent() && item->GetParent()->IsSelected() )
1374 continue;
1375
1376 moveItem( item, delta );
1377 updateItem( item, false );
1378
1379 isPasted |= ( item->GetFlags() & IS_PASTED ) != 0;
1380 }
1381
1382 // The first time pasted items are moved we need to store the position of the cursor
1383 // so that rotate while moving works as expected (instead of around the original
1384 // anchor point)
1385 if( isPasted )
1386 aSelection.SetReferencePoint( m_cursor );
1387
1389 }
1390 // For some items, moving the cursor to anchor is not good (for instance large
1391 // hierarchical sheets or symbols can have the anchor outside the view)
1392 else if( aSelection.Size() == 1 && !sch_item->IsMovableFromAnchorPoint() )
1393 {
1396 }
1397 else
1398 {
1399 if( m_frame->GetMoveWarpsCursor() )
1400 {
1401 // User wants to warp the mouse
1402 m_cursor = grid.BestDragOrigin( m_cursor, aSnapLayer, aSelection );
1403 aSelection.SetReferencePoint( m_cursor );
1404 }
1405 else
1406 {
1407 // User does not want to warp the mouse
1409 }
1410 }
1411
1412 controls->SetCursorPosition( m_cursor, false );
1413 controls->SetAutoPan( true );
1414 m_moveInProgress = true;
1415}
1416
1417
1419 bool aHasSheetPins, bool aIsGraphicsOnly, bool aCtrlDown )
1420{
1421 // Fields are children of their parent item and must not be dropped into a sheet
1422 for( EDA_ITEM* it : aSelection )
1423 {
1424 if( it->Type() == SCH_FIELD_T )
1425 return nullptr;
1426 }
1427
1428 // Determine potential target sheet
1429 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_frame->GetScreen()->GetItem( aCursorPos, 0, SCH_SHEET_T ) );
1430
1431 if( sheet && ( sheet->IsSelected() || sheet->HasFlag( IS_MOVING ) ) )
1432 sheet = nullptr; // Never target a selected sheet
1433
1434 if( !sheet )
1435 {
1436 // Build current selection bounding box in its (already moved) position
1437 BOX2I selBBox;
1438
1439 for( EDA_ITEM* it : aSelection )
1440 {
1441 if( SCH_ITEM* schIt = dynamic_cast<SCH_ITEM*>( it ) )
1442 selBBox.Merge( schIt->GetBoundingBox() );
1443 }
1444
1445 if( selBBox.GetWidth() > 0 && selBBox.GetHeight() > 0 )
1446 {
1447 VECTOR2I selCenter( selBBox.GetX() + selBBox.GetWidth() / 2,
1448 selBBox.GetY() + selBBox.GetHeight() / 2 );
1449
1450 // Find first non-selected sheet whose body fully contains the selection or at
1451 // least contains its center point
1452 for( SCH_ITEM* it : m_frame->GetScreen()->Items().OfType( SCH_SHEET_T ) )
1453 {
1454 SCH_SHEET* candidate = static_cast<SCH_SHEET*>( it );
1455
1456 if( candidate->IsSelected() || candidate->IsTopLevelSheet() || candidate->HasFlag( IS_MOVING ) )
1457 continue;
1458
1459 BOX2I body = candidate->GetBodyBoundingBox();
1460
1461 if( body.Contains( selBBox ) || body.Contains( selCenter ) )
1462 {
1463 sheet = candidate;
1464 break;
1465 }
1466 }
1467 }
1468 }
1469
1470 // Don't drop into a sheet if any connection point of the selection lands on a sheet pin.
1471 // This indicates the user is trying to connect to the pin, not drop into the sheet.
1472 if( sheet )
1473 {
1474 for( EDA_ITEM* it : aSelection )
1475 {
1476 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( it );
1477
1478 if( !schItem )
1479 continue;
1480
1481 for( const VECTOR2I& pt : schItem->GetConnectionPoints() )
1482 {
1483 if( sheet->GetPin( pt ) )
1484 {
1485 sheet = nullptr;
1486 break;
1487 }
1488 }
1489
1490 if( !sheet )
1491 break;
1492 }
1493 }
1494
1495 bool dropAllowedBySelection = !aHasSheetPins;
1496 bool dropAllowedByModifiers = !aIsGraphicsOnly || aCtrlDown;
1497
1498 if( sheet && !( dropAllowedBySelection && dropAllowedByModifiers ) )
1499 sheet = nullptr;
1500
1501 return sheet;
1502}
1503
1504
1506 SCH_COMMIT* aCommit, int& aXBendCount, int& aYBendCount,
1507 const EE_GRID_HELPER& aGrid )
1508{
1509 wxLogTrace( traceSchMove, "performItemMove: delta=(%d,%d), moveOffset=(%d,%d), selection size=%u",
1510 aDelta.x, aDelta.y, m_moveOffset.x, m_moveOffset.y, aSelection.GetSize() );
1511
1512 // We need to check if the movement will change the net offset direction on the X and Y
1513 // axes. This is because we remerge added bend lines in realtime, and we also account for
1514 // the direction of the move when adding bend lines. So, if the move direction changes,
1515 // we need to split it into a move that gets us back to zero, then the rest of the move.
1516 std::vector<VECTOR2I> splitMoves;
1517
1518 if( alg::signbit( m_moveOffset.x ) != alg::signbit( ( m_moveOffset + aDelta ).x ) )
1519 {
1520 splitMoves.emplace_back( VECTOR2I( -1 * m_moveOffset.x, 0 ) );
1521 splitMoves.emplace_back( VECTOR2I( aDelta.x + m_moveOffset.x, 0 ) );
1522 }
1523 else
1524 {
1525 splitMoves.emplace_back( VECTOR2I( aDelta.x, 0 ) );
1526 }
1527
1528 if( alg::signbit( m_moveOffset.y ) != alg::signbit( ( m_moveOffset + aDelta ).y ) )
1529 {
1530 splitMoves.emplace_back( VECTOR2I( 0, -1 * m_moveOffset.y ) );
1531 splitMoves.emplace_back( VECTOR2I( 0, aDelta.y + m_moveOffset.y ) );
1532 }
1533 else
1534 {
1535 splitMoves.emplace_back( VECTOR2I( 0, aDelta.y ) );
1536 }
1537
1538 m_moveOffset += aDelta;
1539
1540 // Split the move into X and Y moves so we can correctly drag orthogonal lines
1541 for( const VECTOR2I& splitDelta : splitMoves )
1542 {
1543 // Skip non-moves
1544 if( splitDelta == VECTOR2I( 0, 0 ) )
1545 continue;
1546
1547 for( EDA_ITEM* item : aSelection.GetItemsSortedByTypeAndXY( ( aDelta.x >= 0 ),
1548 ( aDelta.y >= 0 ) ) )
1549 {
1550 // Don't double move pins, fields, etc.
1551 if( item->GetParent() && item->GetParent()->IsSelected() )
1552 continue;
1553
1554 SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
1555 bool isLineModeConstrained = false;
1556
1557 if( EESCHEMA_SETTINGS* cfg = GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" ) )
1558 isLineModeConstrained = cfg->m_Drawing.line_mode != LINE_MODE::LINE_MODE_FREE;
1559
1560 // Only partially selected drag lines in orthogonal line mode need special handling.
1561 // Skip newly-created connectivity wires added to maintain connectivity at junctions:
1562 // these are marked with both IS_NEW and SELECTED_BY_DRAG; they already have the
1563 // correct endpoint constraint and don't need orthogonal bending
1564 if( ( m_mode == DRAG ) && isLineModeConstrained && line
1565 && line->HasFlag( STARTPOINT ) != line->HasFlag( ENDPOINT )
1566 && !line->HasFlag( SELECTED_BY_DRAG | IS_NEW ) )
1567 {
1568 orthoLineDrag( aCommit, line, splitDelta, aXBendCount, aYBendCount, aGrid );
1569 }
1570
1571 // Move all other items normally, including the selected end of partially selected
1572 // lines
1573 moveItem( item, splitDelta );
1574 updateItem( item, false );
1575
1576 // Update any lines connected to sheet pins to the sheet pin's location (which may
1577 // not exactly follow the splitDelta as the pins are constrained along the sheet
1578 // edges)
1579 for( const auto& [pin, lineEnd] : m_specialCaseSheetPins )
1580 {
1581 if( lineEnd.second && lineEnd.first->HasFlag( STARTPOINT ) )
1582 lineEnd.first->SetStartPoint( pin->GetPosition() );
1583 else if( !lineEnd.second && lineEnd.first->HasFlag( ENDPOINT ) )
1584 lineEnd.first->SetEndPoint( pin->GetPosition() );
1585 }
1586 }
1587
1588 // Needed to keep labels attached to a line when dragging a sheet/wire combo with a label
1589 // on the line. The label moves by splitDelta for each part of the split move, but the
1590 // line endpoints may not follow splitDelta due to orthogonal drag or sheet pin constraints,
1591 // which can put the label off the line.
1592 for( auto& [label, info] : m_specialCaseLabels )
1593 {
1594 if( !label || !info.attachedLine )
1595 continue;
1596
1597 if( info.trackMovingEnd )
1598 {
1599 label->Move( splitDelta );
1600
1601 VECTOR2I start = info.attachedLine->GetStartPoint();
1602 VECTOR2I end = info.attachedLine->GetEndPoint();
1603
1604 if( info.attachedLine->GetLength() > 0
1605 && info.attachedLine->HitTest( info.originalLabelPos, 1 )
1606 && info.originalLabelPos != start
1607 && info.originalLabelPos != end )
1608 {
1609 info.trackMovingEnd = false;
1610 label->SetPosition( info.originalLabelPos );
1611 info.originalLineStart = start;
1612 info.originalLineEnd = end;
1613 }
1614
1615 updateItem( label, false );
1616 continue;
1617 }
1618
1619 VECTOR2I start = info.attachedLine->GetStartPoint();
1620 VECTOR2I end = info.attachedLine->GetEndPoint();
1621 VECTOR2I deltaStart = start - info.originalLineStart;
1622 VECTOR2I deltaEnd = end - info.originalLineEnd;
1623
1624 // TODO: this could be improved by positioning the label based on the new line geometry,
1625 // bends are involved.
1626 //
1627 // For now, special casing the equal delta case and using splitDelta should work in most
1628 // cases as the user would expect.
1629 if( deltaStart == deltaEnd )
1630 {
1631 label->SetPosition( info.originalLabelPos + deltaStart );
1632 }
1633 else
1634 {
1635 bool startDrags = info.attachedLine->HasFlag( STARTPOINT );
1636 VECTOR2I fixedEndDelta = startDrags ? deltaEnd : deltaStart;
1637
1638 label->SetPosition( info.originalLabelPos + fixedEndDelta );
1639
1640 // If the line shrank while dragging, keep the label on the line,
1641 // otherwise the label can drift off the end of the line, and change connectivity
1642 if( !info.attachedLine->HitTest( label->GetPosition(), 1 ) )
1643 {
1644 SEG seg( start, end );
1645 label->SetPosition( seg.NearestPoint( label->GetPosition() ) );
1646
1647 VECTOR2I movingEnd = startDrags ? start : end;
1648
1649 if( label->GetPosition() == movingEnd )
1650 info.trackMovingEnd = true;
1651 }
1652 }
1653
1654 updateItem( label, false );
1655 }
1656 }
1657
1658 if( aSelection.HasReferencePoint() )
1659 aSelection.SetReferencePoint( aSelection.GetReferencePoint() + aDelta );
1660}
1661
1662
1664 const SCH_SELECTION& aSelection )
1665{
1666 wxLogTrace( traceSchMove, "handleMoveToolActions: received event, action=%s",
1667 aEvent->Format().c_str() );
1668
1669 if( aEvent->IsAction( &ACTIONS::doDelete ) )
1670 {
1671 wxLogTrace( traceSchMove, "handleMoveToolActions: doDelete, exiting move" );
1672 const_cast<TOOL_EVENT*>( aEvent )->SetPassEvent();
1673 return false; // Exit on delete; there will no longer be anything to drag
1674 }
1675 else if( aEvent->IsAction( &ACTIONS::duplicate )
1677 || aEvent->IsAction( &ACTIONS::redo ) )
1678 {
1679 wxBell();
1680 }
1681 else if( aEvent->IsAction( &SCH_ACTIONS::rotateCW ) )
1682 {
1683 wxLogTrace( traceSchMove, "handleMoveToolActions: rotateCW event received, selection size=%u",
1684 aSelection.GetSize() );
1685 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::rotateCW, aCommit );
1686 wxLogTrace( traceSchMove, "handleMoveToolActions: rotateCW RunSynchronousAction completed" );
1687 updateStoredPositions( aSelection );
1688 wxLogTrace( traceSchMove, "handleMoveToolActions: rotateCW updateStoredPositions completed" );
1689 // Note: SCH_EDIT_TOOL::Rotate already posts refreshPreview when moving
1690 }
1691 else if( aEvent->IsAction( &SCH_ACTIONS::rotateCCW ) )
1692 {
1693 wxLogTrace( traceSchMove, "handleMoveToolActions: rotateCCW event received, selection size=%u",
1694 aSelection.GetSize() );
1695 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::rotateCCW, aCommit );
1696 wxLogTrace( traceSchMove, "handleMoveToolActions: rotateCCW RunSynchronousAction completed" );
1697 updateStoredPositions( aSelection );
1698 wxLogTrace( traceSchMove, "handleMoveToolActions: rotateCCW updateStoredPositions completed" );
1699 // Note: SCH_EDIT_TOOL::Rotate already posts refreshPreview when moving
1700 }
1701 else if( aEvent->IsAction( &ACTIONS::increment ) )
1702 {
1703 if( aEvent->HasParameter() )
1704 m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, aEvent->Parameter<ACTIONS::INCREMENT>() );
1705 else
1706 m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, ACTIONS::INCREMENT{ 1, 0 } );
1707
1708 updateStoredPositions( aSelection );
1709 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1710 }
1711 else if( aEvent->IsAction( &SCH_ACTIONS::toDLabel ) )
1712 {
1713 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toDLabel, aCommit );
1714 updateStoredPositions( aSelection );
1715 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1716 }
1717 else if( aEvent->IsAction( &SCH_ACTIONS::toGLabel ) )
1718 {
1719 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toGLabel, aCommit );
1720 updateStoredPositions( aSelection );
1721 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1722 }
1723 else if( aEvent->IsAction( &SCH_ACTIONS::toHLabel ) )
1724 {
1725 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toHLabel, aCommit );
1726 updateStoredPositions( aSelection );
1727 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1728 }
1729 else if( aEvent->IsAction( &SCH_ACTIONS::toLabel ) )
1730 {
1731 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toLabel, aCommit );
1732 updateStoredPositions( aSelection );
1733 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1734 }
1735 else if( aEvent->IsAction( &SCH_ACTIONS::toText ) )
1736 {
1737 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toText, aCommit );
1738 updateStoredPositions( aSelection );
1739 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1740 }
1741 else if( aEvent->IsAction( &SCH_ACTIONS::toTextBox ) )
1742 {
1743 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toTextBox, aCommit );
1744 updateStoredPositions( aSelection );
1745 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1746 }
1747 else if( aEvent->Action() == TA_CHOICE_MENU_CHOICE )
1748 {
1749 if( *aEvent->GetCommandId() >= ID_POPUP_SCH_SELECT_UNIT
1751 {
1752 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selectionTool->GetSelection().Front() );
1753 int unit = *aEvent->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
1754
1755 if( symbol )
1756 {
1757 m_frame->SelectUnit( symbol, unit );
1758 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1759 }
1760 }
1761 else if( *aEvent->GetCommandId() >= ID_POPUP_SCH_SELECT_BODY_STYLE
1763 {
1764 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( m_selectionTool->GetSelection().Front() );
1765 int bodyStyle = ( *aEvent->GetCommandId() - ID_POPUP_SCH_SELECT_BODY_STYLE ) + 1;
1766
1767 if( symbol && symbol->GetBodyStyle() != bodyStyle )
1768 {
1769 m_frame->SelectBodyStyle( symbol, bodyStyle );
1770 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1771 }
1772 }
1773 }
1774 else if( aEvent->IsAction( &SCH_ACTIONS::highlightNet )
1775 || aEvent->IsAction( &SCH_ACTIONS::selectOnPCB ) )
1776 {
1777 // These don't make any sense during a move. Eat them.
1778 }
1779 else
1780 {
1781 return true; // Continue processing
1782 }
1783
1784 return true; // Continue processing
1785}
1786
1787
1789{
1790 wxLogTrace( traceSchMove, "updateStoredPositions: start, selection size=%u",
1791 aSelection.GetSize() );
1792
1793 // After transformations like rotation during a move, we need to update the stored
1794 // positions that moveItem() uses, particularly for sheet pins which rely on them
1795 // for constraint calculations.
1796 int itemCount = 0;
1797
1798 for( EDA_ITEM* item : aSelection )
1799 {
1800 SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item );
1801
1802 if( !schItem )
1803 continue;
1804
1805 VECTOR2I oldPos = schItem->GetStoredPos();
1806 VECTOR2I newPos = schItem->GetPosition();
1807 schItem->SetStoredPos( newPos );
1808
1809 wxLogTrace( traceSchMove, " item[%d] type=%d: stored pos updated (%d,%d) -> (%d,%d)",
1810 itemCount++, (int) schItem->Type(), oldPos.x, oldPos.y, newPos.x, newPos.y );
1811
1812 // Also update stored positions for sheet pins
1813 if( schItem->Type() == SCH_SHEET_T )
1814 {
1815 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( schItem );
1816 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1817 {
1818 VECTOR2I pinOldPos = pin->GetStoredPos();
1819 VECTOR2I pinNewPos = pin->GetPosition();
1820 pin->SetStoredPos( pinNewPos );
1821 wxLogTrace( traceSchMove, " sheet pin: stored pos updated (%d,%d) -> (%d,%d)",
1822 pinOldPos.x, pinOldPos.y, pinNewPos.x, pinNewPos.y );
1823 }
1824 }
1825 }
1826
1827 wxLogTrace( traceSchMove, "updateStoredPositions: complete, updated %d items", itemCount );
1828}
1829
1830
1831void SCH_MOVE_TOOL::finalizeMoveOperation( SCH_SELECTION& aSelection, SCH_COMMIT* aCommit, bool aUnselect,
1832 const std::vector<DANGLING_END_ITEM>& aInternalPoints )
1833{
1835 const bool isSlice = ( m_mode == SLICE );
1836 const bool isDragLike = ( m_mode == DRAG || m_mode == BREAK );
1837
1838 // Save whatever new bend lines and changed lines survived the drag
1839 for( SCH_LINE* newLine : m_newDragLines )
1840 {
1841 newLine->ClearEditFlags();
1842 aCommit->Added( newLine, m_frame->GetScreen() );
1843 }
1844
1845 // These lines have been changed, but aren't selected. We need to manually clear these
1846 // edit flags or they'll stick around.
1847 for( SCH_LINE* oldLine : m_changedDragLines )
1848 oldLine->ClearEditFlags();
1849
1850 controls->ForceCursorPosition( false );
1851 controls->ShowCursor( false );
1852 controls->SetAutoPan( false );
1853
1854 m_moveOffset = { 0, 0 };
1855 m_anchorPos.reset();
1856
1857 // One last update after exiting loop (for slower stuff, such as updating SCREEN's RTree)
1858 for( EDA_ITEM* item : aSelection )
1859 {
1860 updateItem( item, true );
1861
1862 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
1863 sch_item->SetConnectivityDirty( true );
1864 }
1865
1866 if( aSelection.GetSize() == 1 && aSelection.Front()->IsNew() )
1867 m_frame->SaveCopyForRepeatItem( static_cast<SCH_ITEM*>( aSelection.Front() ) );
1868
1869 m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
1870
1872
1873 // If we move items away from a junction, we _may_ want to add a junction there
1874 // to denote the state
1875 for( const DANGLING_END_ITEM& it : aInternalPoints )
1876 {
1877 if( m_frame->GetScreen()->IsExplicitJunctionNeeded( it.GetPosition() ) )
1878 lwbTool->AddJunction( aCommit, m_frame->GetScreen(), it.GetPosition() );
1879 }
1880
1881 // Create a selection of original selection, drag selected/changed items, and new bend
1882 // lines for later before we clear them in the aCommit. We'll need these to check for new
1883 // junctions needed, etc.
1884 SCH_SELECTION selectionCopy( aSelection );
1885
1886 for( SCH_LINE* line : m_newDragLines )
1887 selectionCopy.Add( line );
1888
1889 for( SCH_LINE* line : m_changedDragLines )
1890 selectionCopy.Add( line );
1891
1892 lwbTool->TrimOverLappingWires( aCommit, &selectionCopy );
1893 lwbTool->AddJunctionsIfNeeded( aCommit, &selectionCopy );
1894
1895 // This needs to run prior to `RecalculateConnections` because we need to identify the
1896 // lines that are newly dangling
1897 if( isDragLike && !isSlice )
1898 trimDanglingLines( aCommit );
1899
1900 // Auto-rotate any moved labels
1901 for( EDA_ITEM* item : aSelection )
1902 m_frame->AutoRotateItem( m_frame->GetScreen(), static_cast<SCH_ITEM*>( item ) );
1903
1904 // Clear SELECTED_BY_DRAG and other temp flags before CleanUp so that cleanup can properly
1905 // process all items, including removing zero-length wires and unwanted stubs
1906 for( EDA_ITEM* item : m_frame->GetScreen()->Items() )
1907 item->ClearTempFlags();
1908
1909 for( EDA_ITEM* item : selectionCopy )
1910 item->ClearTempFlags();
1911
1912 m_frame->Schematic().CleanUp( aCommit );
1913
1914 // Mirror the IS_MOVING flag propagation done at the start of the move so that child items
1915 // (e.g. label fields, symbol pins/fields) don't keep their edit flags after the move ends.
1916 auto clearChildEditFlags =
1917 []( SCH_ITEM* aItem )
1918 {
1919 aItem->RunOnChildren(
1920 []( SCH_ITEM* aChild )
1921 {
1922 aChild->ClearEditFlags();
1923 },
1925 };
1926
1927 for( EDA_ITEM* item : m_frame->GetScreen()->Items() )
1928 {
1929 item->ClearEditFlags();
1930
1931 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
1932 clearChildEditFlags( schItem );
1933 }
1934
1935 // Ensure any selected item not in screen main list (for instance symbol fields) has its
1936 // edit flags cleared
1937 for( EDA_ITEM* item : selectionCopy )
1938 {
1939 item->ClearEditFlags();
1940
1941 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
1942 clearChildEditFlags( schItem );
1943 }
1944
1945 m_newDragLines.clear();
1946 m_changedDragLines.clear();
1947
1948 if( aUnselect )
1949 m_toolMgr->RunAction( ACTIONS::selectionClear );
1950 else
1951 m_selectionTool->RebuildSelection(); // Schematic cleanup might have merged lines, etc.
1952}
1953
1954
1956 SCH_COMMIT* aCommit )
1957{
1958 SCH_SCREEN* destScreen = aTargetSheet->GetScreen();
1959 SCH_SCREEN* srcScreen = m_frame->GetScreen();
1960
1961 BOX2I bbox;
1962
1963 for( EDA_ITEM* item : aSelection )
1964 bbox.Merge( static_cast<SCH_ITEM*>( item )->GetBoundingBox() );
1965
1966 VECTOR2I offset = VECTOR2I( 0, 0 ) - bbox.GetPosition();
1967 int step = schIUScale.MilsToIU( 50 );
1968 bool overlap = false;
1969
1970 do
1971 {
1972 BOX2I moved = bbox;
1973 moved.Move( offset );
1974 overlap = false;
1975
1976 for( SCH_ITEM* existing : destScreen->Items() )
1977 {
1978 if( moved.Intersects( existing->GetBoundingBox() ) )
1979 {
1980 overlap = true;
1981 break;
1982 }
1983 }
1984
1985 if( overlap )
1986 offset += VECTOR2I( step, step );
1987 } while( overlap );
1988
1989 for( EDA_ITEM* item : aSelection )
1990 {
1991 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1992
1993 // Remove from current screen and view manually
1994 m_frame->RemoveFromScreen( schItem, srcScreen );
1995
1996 // Move the item
1997 schItem->Move( offset );
1998
1999 // Add to destination screen manually (won't add to view since it's not current)
2000 destScreen->Append( schItem );
2001
2002 // Record in commit with CHT_DONE flag to bypass automatic screen/view operations
2003 aCommit->Stage( schItem, CHT_REMOVE | CHT_DONE, srcScreen );
2004 aCommit->Stage( schItem, CHT_ADD | CHT_DONE, destScreen );
2005 }
2006}
2007
2008
2010{
2011 // Need a local cleanup first to ensure we remove unneeded junctions
2012 m_frame->Schematic().CleanUp( aCommit, m_frame->GetScreen() );
2013
2014 std::set<SCH_ITEM*> danglers;
2015
2016 std::function<void( SCH_ITEM* )> changeHandler =
2017 [&]( SCH_ITEM* aChangedItem ) -> void
2018 {
2019 m_toolMgr->GetView()->Update( aChangedItem, KIGFX::REPAINT );
2020
2021 if( aChangedItem->IsSelected() )
2022 return;
2023
2024 SCH_LINE* line = dynamic_cast<SCH_LINE*>( aChangedItem );
2025
2026 if( !line )
2027 return;
2028
2029 // Split segments that are dangling get trimmed back since they extend
2030 // past the break point.
2031 if( line->HasFlag( IS_BROKEN ) && line->IsDangling() )
2032 {
2033 danglers.insert( aChangedItem );
2034 }
2035 // Drag wires that are completely disconnected (both ends dangling) are
2036 // stubs that should be removed. Wires with only one connected end are
2037 // still providing connectivity and must be preserved.
2038 else if( line->HasFlag( IS_NEW ) && !line->HasFlag( IS_BROKEN )
2039 && line->IsStartDangling() && line->IsEndDangling() )
2040 {
2041 danglers.insert( aChangedItem );
2042 }
2043 };
2044
2045 m_frame->GetScreen()->TestDanglingEnds( nullptr, &changeHandler );
2046
2047 for( SCH_ITEM* line : danglers )
2048 {
2049 line->SetFlags( STRUCT_DELETED );
2050 aCommit->Removed( line, m_frame->GetScreen() );
2051 updateItem( line, false ); // Update any cached visuals before commit processes
2052 m_frame->RemoveFromScreen( line, m_frame->GetScreen() );
2053 }
2054}
2055
2056
2057void SCH_MOVE_TOOL::getConnectedItems( SCH_ITEM* aOriginalItem, const VECTOR2I& aPoint, EDA_ITEMS& aList )
2058{
2059 EE_RTREE& items = m_frame->GetScreen()->Items();
2060 EE_RTREE::EE_TYPE itemsOverlapping = items.Overlapping( aOriginalItem->GetBoundingBox() );
2061 SCH_ITEM* foundJunction = nullptr;
2062 SCH_ITEM* foundSymbol = nullptr;
2063
2064 // If you're connected to a junction, you're only connected to the junction.
2065 //
2066 // But, if you're connected to a junction on a pin, you're only connected to the pin. This
2067 // is because junctions and pins have different logic for how bend lines are generated and
2068 // we need to prioritize the pin version in some cases.
2069 for( SCH_ITEM* item : itemsOverlapping )
2070 {
2071 if( item != aOriginalItem && item->IsConnected( aPoint ) )
2072 {
2073 if( item->Type() == SCH_JUNCTION_T )
2074 foundJunction = item;
2075 else if( item->Type() == SCH_SYMBOL_T )
2076 foundSymbol = item;
2077 }
2078 }
2079
2080 if( foundSymbol && foundJunction )
2081 {
2082 aList.push_back( foundSymbol );
2083 return;
2084 }
2085
2086 if( foundJunction )
2087 {
2088 aList.push_back( foundJunction );
2089 return;
2090 }
2091
2092
2093 for( SCH_ITEM* test : itemsOverlapping )
2094 {
2095 if( test == aOriginalItem || !test->CanConnect( aOriginalItem ) )
2096 continue;
2097
2098 switch( test->Type() )
2099 {
2100 case SCH_LINE_T:
2101 {
2102 SCH_LINE* line = static_cast<SCH_LINE*>( test );
2103
2104 // When getting lines for the connection cache, it's important that we only add
2105 // items at the unselected end, since that is the only end that is handled specially.
2106 // Fully selected lines, and the selected end of a partially selected line, are moved
2107 // around normally and don't care about their connections.
2108 if( ( line->HasFlag( STARTPOINT ) && aPoint == line->GetStartPoint() )
2109 || ( line->HasFlag( ENDPOINT ) && aPoint == line->GetEndPoint() ) )
2110 {
2111 continue;
2112 }
2113
2114 if( test->IsConnected( aPoint ) )
2115 aList.push_back( test );
2116
2117 // Labels can connect to a wire (or bus) anywhere along the length
2118 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aOriginalItem ) )
2119 {
2120 if( static_cast<SCH_LINE*>( test )->HitTest( label->GetPosition(), 1 ) )
2121 aList.push_back( test );
2122 }
2123
2124 break;
2125 }
2126
2127 case SCH_SHEET_T:
2128 if( aOriginalItem->Type() == SCH_LINE_T )
2129 {
2130 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
2131
2132 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
2133 {
2134 if( pin->IsConnected( aPoint ) )
2135 {
2136 if( pin->IsSelected() )
2137 m_specialCaseSheetPins[pin] = { line, line->GetStartPoint() == aPoint };
2138
2139 aList.push_back( pin );
2140 }
2141 }
2142 }
2143
2144 break;
2145
2146 case SCH_SYMBOL_T:
2147 case SCH_JUNCTION_T:
2148 case SCH_NO_CONNECT_T:
2149 if( test->IsConnected( aPoint ) )
2150 aList.push_back( test );
2151
2152 break;
2153
2154 case SCH_LABEL_T:
2155 case SCH_GLOBAL_LABEL_T:
2156 case SCH_HIER_LABEL_T:
2158 // Labels can connect to a wire (or bus) anywhere along the length
2159 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
2160 {
2161 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
2162 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
2163
2164 if( line->HitTest( label->GetPosition(), 1 ) )
2165 aList.push_back( label );
2166 }
2167
2168 break;
2169
2172 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
2173 {
2174 SCH_TEXT* label = static_cast<SCH_TEXT*>( test );
2175 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
2176
2177 if( line->HitTest( aPoint, 1 ) )
2178 aList.push_back( label );
2179 }
2180
2181 break;
2182
2183 default:
2184 break;
2185 }
2186 }
2187}
2188
2189
2190void SCH_MOVE_TOOL::getConnectedDragItems( SCH_COMMIT* aCommit, SCH_ITEM* aSelectedItem, const VECTOR2I& aPoint,
2191 EDA_ITEMS& aList )
2192{
2193 EE_RTREE& items = m_frame->GetScreen()->Items();
2194 std::set<SCH_ITEM*> connectableCandidates;
2195 std::vector<SCH_ITEM*> itemsConnectable;
2196 bool ptHasUnselectedJunction = false;
2197
2198 for( SCH_ITEM* item : items.Overlapping( aSelectedItem->GetBoundingBox() ) )
2199 connectableCandidates.insert( item );
2200
2201 // Labels can connect at their anchor even if the label bbox doesn't overlap the target, e.g.
2202 // sheet pins can do this sometimes with just net labels and no wires.
2203 if( dynamic_cast<SCH_LABEL_BASE*>( aSelectedItem ) )
2204 {
2205 for( SCH_ITEM* item : items.Overlapping( aPoint, 1 ) )
2206 connectableCandidates.insert( item );
2207 }
2208
2209 auto makeNewWire =
2210 [this]( SCH_COMMIT* commit, SCH_ITEM* fixed, SCH_ITEM* selected, const VECTOR2I& start,
2211 const VECTOR2I& end )
2212 {
2213 SCH_LINE* newWire;
2214 bool isBusLabel = false;
2215
2216 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( fixed ) )
2217 isBusLabel |= SCH_CONNECTION::IsBusLabel( label->GetText() );
2218
2219 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( selected ) )
2220 isBusLabel |= SCH_CONNECTION::IsBusLabel( label->GetText() );
2221
2222 // Add a new newWire between the fixed item and the selected item so the selected
2223 // item can be dragged.
2224 if( fixed->GetLayer() == LAYER_BUS_JUNCTION || fixed->GetLayer() == LAYER_BUS
2225 || selected->GetLayer() == LAYER_BUS || isBusLabel )
2226 {
2227 newWire = new SCH_LINE( start, LAYER_BUS );
2228 }
2229 else
2230 {
2231 newWire = new SCH_LINE( start, LAYER_WIRE );
2232 }
2233
2234 newWire->SetFlags( IS_NEW );
2235 newWire->SetConnectivityDirty( true );
2236
2237 SCH_LINE* selectedLine = dynamic_cast<SCH_LINE*>( selected );
2238 SCH_LINE* fixedLine = dynamic_cast<SCH_LINE*>( fixed );
2239
2240 if( selectedLine )
2241 {
2242 newWire->SetLastResolvedState( selected );
2243 cloneWireConnection( newWire, selectedLine, m_frame );
2244 }
2245 else if( fixedLine )
2246 {
2247 newWire->SetLastResolvedState( fixed );
2248 cloneWireConnection( newWire, fixedLine, m_frame );
2249 }
2250
2251 newWire->SetEndPoint( end );
2252 m_frame->AddToScreen( newWire, m_frame->GetScreen() );
2253 commit->Added( newWire, m_frame->GetScreen() );
2254
2255 return newWire;
2256 };
2257
2258 auto makeNewJunction =
2259 [this]( SCH_COMMIT* commit, SCH_LINE* line, const VECTOR2I& pt )
2260 {
2261 SCH_JUNCTION* junction = new SCH_JUNCTION( pt );
2262 junction->SetFlags( IS_NEW );
2263 junction->SetConnectivityDirty( true );
2264 junction->SetLastResolvedState( line );
2265
2266 if( line->IsBus() )
2267 junction->SetLayer( LAYER_BUS_JUNCTION );
2268
2269 m_frame->AddToScreen( junction, m_frame->GetScreen() );
2270 commit->Added( junction, m_frame->GetScreen() );
2271
2272 return junction;
2273 };
2274
2275 for( SCH_ITEM* item : connectableCandidates )
2276 {
2277 if( item->Type() == SCH_SHEET_T )
2278 {
2279 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
2280
2281 // A sheet inside a selected group moves with the group, so its pins should not be
2282 // treated as fixed connection anchors.
2283 if( sheet->HasSelectedAncestorGroup() )
2284 continue;
2285
2286 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
2287 {
2288 if( !pin->IsSelected()
2289 && pin->GetPosition() == aPoint
2290 && pin->CanConnect( aSelectedItem ) )
2291 {
2292 itemsConnectable.push_back( pin );
2293 }
2294 }
2295
2296 continue;
2297 }
2298
2299 // Skip ourselves, skip already selected items (but not lines, they need both ends tested)
2300 // and skip unconnectable items. Items inside a selected group are also moving with the
2301 // selection even though they do not carry the SELECTED flag themselves; treating them as
2302 // fixed anchors causes spurious stub wires to be created at the group boundary.
2303 if( item == aSelectedItem
2304 || ( item->Type() != SCH_LINE_T && ( item->IsSelected() || item->HasSelectedAncestorGroup() ) )
2305 || !item->CanConnect( aSelectedItem ) )
2306 {
2307 continue;
2308 }
2309
2310 itemsConnectable.push_back( item );
2311 }
2312
2313 for( SCH_ITEM* item : itemsConnectable )
2314 {
2315 if( item->Type() == SCH_JUNCTION_T && item->IsConnected( aPoint ) && !item->IsSelected() )
2316 {
2317 ptHasUnselectedJunction = true;
2318 break;
2319 }
2320 }
2321
2322 SCH_LINE* newWire = nullptr;
2323
2324 for( SCH_ITEM* test : itemsConnectable )
2325 {
2326 KICAD_T testType = test->Type();
2327
2328 switch( testType )
2329 {
2330 case SCH_LINE_T:
2331 {
2332 // Select the connected end of wires/bus connections that don't have an unselected
2333 // junction isolating them from the drag
2334 if( ptHasUnselectedJunction )
2335 break;
2336
2337 SCH_LINE* line = static_cast<SCH_LINE*>( test );
2338
2339 // A line that is itself a member of a selected group is already moving with that
2340 // group; do not add it as a drag attachment or it will move twice.
2341 bool lineInSelectedGroup = line->HasSelectedAncestorGroup();
2342
2343 if( line->GetStartPoint() == aPoint )
2344 {
2345 // It's possible to manually select one end of a line and get a drag
2346 // connected other end, so we set the flag and then early exit the loop
2347 // later if the other drag items like labels attached to the line have
2348 // already been grabbed during the partial selection process.
2349 if( !lineInSelectedGroup )
2350 line->SetFlags( STARTPOINT );
2351
2352 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG )
2353 || lineInSelectedGroup )
2354 {
2355 continue;
2356 }
2357 else
2358 {
2359 line->SetFlags( SELECTED_BY_DRAG );
2360 aList.push_back( line );
2361 }
2362 }
2363 else if( line->GetEndPoint() == aPoint )
2364 {
2365 if( !lineInSelectedGroup )
2366 line->SetFlags( ENDPOINT );
2367
2368 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG )
2369 || lineInSelectedGroup )
2370 {
2371 continue;
2372 }
2373 else
2374 {
2375 line->SetFlags( SELECTED_BY_DRAG );
2376 aList.push_back( line );
2377 }
2378 }
2379 else
2380 {
2381 switch( aSelectedItem->Type() )
2382 {
2383 // These items can connect anywhere along a line
2386 case SCH_LABEL_T:
2387 case SCH_HIER_LABEL_T:
2388 case SCH_GLOBAL_LABEL_T:
2390 // Only add a line if this line is unselected; if the label and line are both
2391 // selected they'll move together
2392 if( line->HitTest( aPoint, 1 ) && !line->HasFlag( SELECTED )
2393 && !line->HasFlag( SELECTED_BY_DRAG ) )
2394 {
2395 newWire = makeNewWire( aCommit, line, aSelectedItem, aPoint, aPoint );
2396 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
2397 newWire->StoreAngle( ( line->Angle() + ANGLE_90 ).Normalize() );
2398 aList.push_back( newWire );
2399
2400 if( aPoint != line->GetStartPoint() && aPoint != line->GetEndPoint() )
2401 {
2402 // Split line in half
2403 aCommit->Modify( line, m_frame->GetScreen() );
2404
2405 VECTOR2I oldEnd = line->GetEndPoint();
2406 line->SetEndPoint( aPoint );
2407
2408 makeNewWire( aCommit, line, line, aPoint, oldEnd );
2409 makeNewJunction( aCommit, line, aPoint );
2410 }
2411 else
2412 {
2413 m_lineConnectionCache[ newWire ] = { line };
2414 m_lineConnectionCache[ line ] = { newWire };
2415 }
2416 }
2417 break;
2418
2419 default:
2420 break;
2421 }
2422
2423 break;
2424 }
2425
2426 // When only one end moves, keep attached labels tracking the moving end so they stay
2427 // connected to the line.
2428 for( SCH_ITEM* item : items.Overlapping( line->GetBoundingBox() ) )
2429 {
2430 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item );
2431
2432 if( !label || label->IsSelected() )
2433 continue; // These will be moved on their own because they're selected
2434
2435 if( label->HasFlag( SELECTED_BY_DRAG ) )
2436 continue;
2437
2438 if( label->CanConnect( line ) && line->HitTest( label->GetPosition(), 1 ) )
2439 {
2440 label->SetFlags( SELECTED_BY_DRAG );
2441 aList.push_back( label );
2442
2444 info.attachedLine = line;
2445 info.originalLabelPos = label->GetPosition();
2446 info.originalLineStart = line->GetStartPoint();
2447 info.originalLineEnd = line->GetEndPoint();
2448 m_specialCaseLabels[label] = info;
2449 }
2450 }
2451
2452 break;
2453 }
2454
2455 case SCH_SHEET_T:
2456 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
2457 {
2458 if( pin->IsConnected( aPoint ) )
2459 {
2460 if( pin->IsSelected() && aSelectedItem->Type() == SCH_LINE_T )
2461 {
2462 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
2463 m_specialCaseSheetPins[ pin ] = { line, line->GetStartPoint() == aPoint };
2464 }
2465 else if( !newWire )
2466 {
2467 // Add a new wire between the sheetpin and the selected item so the
2468 // selected item can be dragged.
2469 newWire = makeNewWire( aCommit, pin, aSelectedItem, aPoint, aPoint );
2470 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
2471 aList.push_back( newWire );
2472 }
2473 }
2474 }
2475
2476 break;
2477
2478 case SCH_SYMBOL_T:
2479 case SCH_JUNCTION_T:
2480 if( test->IsConnected( aPoint ) && !newWire )
2481 {
2482 // Add a new wire between the symbol or junction and the selected item so
2483 // the selected item can be dragged.
2484 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
2485 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
2486 aList.push_back( newWire );
2487 }
2488
2489 break;
2490
2491 case SCH_NO_CONNECT_T:
2492 // Select no-connects that are connected to items being moved.
2493 if( !test->HasFlag( SELECTED_BY_DRAG ) && test->IsConnected( aPoint ) )
2494 {
2495 aList.push_back( test );
2496 test->SetFlags( SELECTED_BY_DRAG );
2497 }
2498
2499 break;
2500
2501 case SCH_LABEL_T:
2502 case SCH_GLOBAL_LABEL_T:
2503 case SCH_HIER_LABEL_T:
2505 case SCH_SHEET_PIN_T:
2506 // Performance optimization:
2507 if( test->HasFlag( SELECTED_BY_DRAG ) )
2508 break;
2509
2510 // Select labels that are connected to a wire (or bus) being moved.
2511 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
2512 {
2513 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
2514 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
2515
2516 bool oneEndFixed = !line->HasFlag( STARTPOINT ) || !line->HasFlag( ENDPOINT );
2517
2518 if( line->HitTest( label->GetTextPos(), 1 ) )
2519 {
2520 if( ( !line->HasFlag( STARTPOINT ) && label->GetPosition() == line->GetStartPoint() )
2521 || ( !line->HasFlag( ENDPOINT ) && label->GetPosition() == line->GetEndPoint() ) )
2522 {
2523 //If we have a line selected at only one end, don't grab labels
2524 //connected directly to the unselected endpoint
2525 break;
2526 }
2527 else
2528 {
2529 label->SetFlags( SELECTED_BY_DRAG );
2530 aList.push_back( label );
2531
2532 if( oneEndFixed )
2533 {
2535 info.attachedLine = line;
2536 info.originalLabelPos = label->GetPosition();
2537 info.originalLineStart = line->GetStartPoint();
2538 info.originalLineEnd = line->GetEndPoint();
2539 m_specialCaseLabels[label] = info;
2540 }
2541 }
2542 }
2543 }
2544 else if( test->IsConnected( aPoint ) && !newWire )
2545 {
2546 // Add a new wire between the label and the selected item so the selected item
2547 // can be dragged.
2548 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
2549 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
2550 aList.push_back( newWire );
2551 }
2552
2553 break;
2554
2557 // Performance optimization:
2558 if( test->HasFlag( SELECTED_BY_DRAG ) )
2559 break;
2560
2561 // Select bus entries that are connected to a bus being moved.
2562 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
2563 {
2564 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
2565
2566 if( ( !line->HasFlag( STARTPOINT ) && test->IsConnected( line->GetStartPoint() ) )
2567 || ( !line->HasFlag( ENDPOINT ) && test->IsConnected( line->GetEndPoint() ) ) )
2568 {
2569 // If we have a line selected at only one end, don't grab bus entries
2570 // connected directly to the unselected endpoint
2571 continue;
2572 }
2573
2574 for( VECTOR2I& point : test->GetConnectionPoints() )
2575 {
2576 if( line->HitTest( point, 1 ) )
2577 {
2578 test->SetFlags( SELECTED_BY_DRAG );
2579 aList.push_back( test );
2580
2581 // A bus entry needs its wire & label as well
2582 std::vector<VECTOR2I> ends = test->GetConnectionPoints();
2583 VECTOR2I otherEnd;
2584
2585 if( ends[0] == point )
2586 otherEnd = ends[1];
2587 else
2588 otherEnd = ends[0];
2589
2590 getConnectedDragItems( aCommit, test, otherEnd, aList );
2591
2592 // No need to test the other end of the bus entry
2593 break;
2594 }
2595 }
2596 }
2597
2598 break;
2599
2600 default:
2601 break;
2602 }
2603 }
2604}
2605
2606
2607void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
2608{
2609 static int moveCallCount = 0;
2610 wxLogTrace( traceSchMove, "moveItem[%d]: type=%d, delta=(%d,%d)",
2611 ++moveCallCount, aItem->Type(), aDelta.x, aDelta.y );
2612
2613 switch( aItem->Type() )
2614 {
2615 case SCH_LINE_T:
2616 if( m_mode == MOVE )
2617 {
2618 // In MOVE mode, both endpoints always move
2619 static_cast<SCH_LINE*>( aItem )->Move( aDelta );
2620 }
2621 else
2622 {
2623 // In DRAG mode, only flagged endpoints move - use shared function
2624 MoveSchematicItem( aItem, aDelta );
2625 }
2626
2627 break;
2628
2629 case SCH_PIN_T:
2630 case SCH_FIELD_T:
2631 {
2632 SCH_ITEM* parent = (SCH_ITEM*) aItem->GetParent();
2633 VECTOR2I delta( aDelta );
2634
2635 if( parent && parent->Type() == SCH_SYMBOL_T )
2636 {
2637 SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem->GetParent();
2638 TRANSFORM transform = symbol->GetTransform().InverseTransform();
2639
2640 delta = transform.TransformCoordinate( delta );
2641 }
2642
2643 static_cast<SCH_ITEM*>( aItem )->Move( delta );
2644
2645 // If we're moving a field with respect to its parent then it's no longer auto-placed
2646 if( aItem->Type() == SCH_FIELD_T && parent && !parent->IsSelected() )
2648
2649 break;
2650 }
2651
2652 case SCH_SHEET_PIN_T:
2653 // Use shared function for sheet pin movement
2654 MoveSchematicItem( aItem, aDelta );
2655 break;
2656
2657 case SCH_LABEL_T:
2659 case SCH_GLOBAL_LABEL_T:
2660 case SCH_HIER_LABEL_T:
2661 {
2662 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
2663 if( !m_specialCaseLabels.count( label ) )
2664 label->Move( aDelta );
2665
2666 break;
2667 }
2668
2669 default:
2670 static_cast<SCH_ITEM*>( aItem )->Move( aDelta );
2671 break;
2672 }
2673
2674 aItem->SetFlags( IS_MOVING );
2675}
2676
2677
2679{
2681 SCH_SELECTION& selection = m_selectionTool->RequestSelection( SCH_COLLECTOR::MovableItems );
2682
2683 m_selectionTool->FilterSelectionForLockedItems();
2684
2685 GRID_HELPER_GRIDS selectionGrid = grid.GetSelectionGrid( selection );
2686 SCH_COMMIT commit( m_toolMgr );
2687
2688 auto doMoveItem =
2689 [&]( EDA_ITEM* item, const VECTOR2I& delta )
2690 {
2691 commit.Modify( item, m_frame->GetScreen(), RECURSE_MODE::RECURSE );
2692
2693 // Ensure only one end is moved when calling moveItem
2694 // i.e. we are in drag mode
2695 MOVE_MODE tmpMode = m_mode;
2696 m_mode = DRAG;
2697 moveItem( item, delta );
2698 m_mode = tmpMode;
2699
2700 item->ClearFlags( IS_MOVING );
2701 updateItem( item, true );
2702 };
2703
2704 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
2705 {
2706 if( !it->IsSelected() )
2707 it->ClearFlags( STARTPOINT | ENDPOINT );
2708
2709 if( !selection.IsHover() && it->IsSelected() )
2710 it->SetFlags( STARTPOINT | ENDPOINT );
2711
2712 it->SetStoredPos( it->GetPosition() );
2713
2714 if( it->Type() == SCH_SHEET_T )
2715 {
2716 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( it )->GetPins() )
2717 pin->SetStoredPos( pin->GetPosition() );
2718 }
2719 }
2720
2721 SCH_ALIGNMENT_CALLBACKS callbacks;
2722
2723 callbacks.m_doMoveItem = doMoveItem;
2724
2725 callbacks.m_getConnectedDragItems =
2726 [&]( SCH_ITEM* aItem, const VECTOR2I& aPoint, EDA_ITEMS& aList )
2727 {
2728 getConnectedDragItems( &commit, aItem, aPoint, aList );
2729 };
2730
2731 callbacks.m_updateItem =
2732 [&]( EDA_ITEM* aItem )
2733 {
2734 updateItem( aItem, true );
2735 };
2736
2737 std::vector<EDA_ITEM*> items( selection.begin(), selection.end() );
2738 AlignSchematicItemsToGrid( m_frame->GetScreen(), items, grid, selectionGrid, callbacks );
2739
2741 lwbTool->TrimOverLappingWires( &commit, &selection );
2742 lwbTool->AddJunctionsIfNeeded( &commit, &selection );
2743
2745
2746 m_frame->Schematic().CleanUp( &commit );
2747 commit.Push( _( "Align Items to Grid" ) );
2748 return 0;
2749}
2750
2751
2753{
2754 // Remove new bend lines added during the drag
2755 for( SCH_LINE* newLine : m_newDragLines )
2756 {
2757 m_frame->RemoveFromScreen( newLine, m_frame->GetScreen() );
2758 delete newLine;
2759 }
2760
2761 m_newDragLines.clear();
2762}
2763
2764
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:123
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
@ CURSOR_RIGHT
Definition actions.h:307
@ CURSOR_LEFT
Definition actions.h:305
@ CURSOR_UP
Definition actions.h:301
@ CURSOR_DOWN
Definition actions.h:303
static TOOL_ACTION undo
Definition actions.h:71
static TOOL_ACTION duplicate
Definition actions.h:80
static TOOL_ACTION doDelete
Definition actions.h:81
static TOOL_ACTION cursorClick
Definition actions.h:176
static TOOL_ACTION redo
Definition actions.h:72
static TOOL_ACTION increment
Definition actions.h:90
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:220
static TOOL_ACTION refreshPreview
Definition actions.h:155
constexpr const Vec & GetPosition() const
Definition box2.h:207
constexpr coord_type GetY() const
Definition box2.h:204
constexpr size_type GetWidth() const
Definition box2.h:210
constexpr coord_type GetX() const
Definition box2.h:203
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:654
constexpr size_type GetHeight() const
Definition box2.h:211
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:164
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition commit.h:80
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Definition commit.h:92
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
static void sort_dangling_end_items(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos)
Both contain the same information.
Definition sch_item.cpp:980
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:93
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:96
virtual VECTOR2I GetPosition() const
Definition eda_item.h:282
virtual void ClearEditFlags()
Definition eda_item.h:166
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:135
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:152
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:114
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:154
bool IsSelected() const
Definition eda_item.h:132
EDA_ITEM * GetParent() const
Definition eda_item.h:110
bool HasSelectedAncestorGroup() const
Definition eda_item.cpp:106
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:156
bool IsNew() const
Definition eda_item.h:129
virtual VECTOR2I GetTextPos() const
Definition eda_text.h:294
Implement an R-tree for fast spatial and type indexing of schematic items.
Definition sch_rtree.h:34
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition sch_rtree.h:226
static const TOOL_EVENT SelectedItemsMoved
Used to inform tools that the selection should temporarily be non-editable.
Definition actions.h:351
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
const VC_SETTINGS & GetSettings() const
Return the current VIEW_CONTROLS settings.
static TOOL_ACTION rotateCCW
static TOOL_ACTION breakWire
static TOOL_ACTION toText
static TOOL_ACTION restartMove
static TOOL_ACTION toHLabel
static TOOL_ACTION rotateCW
static TOOL_ACTION drag
static TOOL_ACTION toLabel
static TOOL_ACTION alignToGrid
static TOOL_ACTION toDLabel
static TOOL_ACTION slice
static TOOL_ACTION toTextBox
static TOOL_ACTION highlightNet
static TOOL_ACTION repeatDrawItem
static TOOL_ACTION toGLabel
static TOOL_ACTION selectOnPCB
static TOOL_ACTION move
static const std::vector< KICAD_T > MovableItems
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE) override
Add a change of the item aItem of type aChangeType to the change list.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void Clone(const SCH_CONNECTION &aOther)
Copies connectivity information (but not parent) from another connection.
static bool IsBusLabel(const wxString &aLabel)
Test if aLabel has a bus notation.
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:48
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:162
void SetStoredPos(const VECTOR2I &aPos)
Definition sch_item.h:302
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition sch_item.h:519
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition sch_item.h:628
int GetBodyStyle() const
Definition sch_item.h:242
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition sch_item.cpp:580
virtual void Move(const VECTOR2I &aMoveVector)
Move the item by aMoveVector to a new position.
Definition sch_item.h:396
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:339
void SetConnectivityDirty(bool aDirty=true)
Definition sch_item.h:587
void SetFieldsAutoplaced(AUTOPLACE_ALGO aAlgo)
Definition sch_item.h:624
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Definition sch_item.cpp:478
virtual bool IsMovableFromAnchorPoint() const
Check if object is movable from the anchor point.
Definition sch_item.h:299
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:487
VECTOR2I & GetStoredPos()
Definition sch_item.h:301
bool IsGroupableType() const
Definition sch_item.cpp:113
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition sch_item.h:539
void SetLastResolvedState(const SCH_ITEM *aItem) override
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
bool CanConnect(const SCH_ITEM *aItem) const override
Definition sch_label.h:146
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
int AddJunctionsIfNeeded(SCH_COMMIT *aCommit, SCH_SELECTION *aSelection)
Handle the addition of junctions to a selection of objects.
SCH_JUNCTION * AddJunction(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen, const VECTOR2I &aPos)
int TrimOverLappingWires(SCH_COMMIT *aCommit, SCH_SELECTION *aSelection)
Logic to remove wires when overlapping correct items.
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
void BreakSegment(SCH_COMMIT *aCommit, SCH_LINE *aSegment, const VECTOR2I &aPoint, SCH_LINE **aNewSegment, SCH_SCREEN *aScreen)
Break a single segment into two at the specified point.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition sch_line.h:38
bool HitTest(const VECTOR2I &aPosition, int aAccuracy=0) const override
Test if aPosition is inside or on the boundary of this item.
Definition sch_line.cpp:855
void StoreAngle()
Save the current line angle.
Definition sch_line.h:111
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition sch_line.cpp:755
bool IsStartDangling() const
Definition sch_line.h:299
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_line.cpp:272
EDA_ANGLE Angle() const
Get the angle between the start and end lines.
Definition sch_line.h:100
VECTOR2I GetEndPoint() const
Definition sch_line.h:144
VECTOR2I GetStartPoint() const
Definition sch_line.h:135
bool IsEndDangling() const
Definition sch_line.h:300
void MoveEnd(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:217
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition sch_line.h:159
void MoveStart(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:211
double GetLength() const
Definition sch_line.cpp:288
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:145
bool IsDangling() const override
Definition sch_line.h:301
void moveSelectionToSheet(SCH_SELECTION &aSelection, SCH_SHEET *aTarget, SCH_COMMIT *aCommit)
Clears the new drag lines and removes them from the screen.
void refreshSelectionTraits(const SCH_SELECTION &aSelection, bool &aHasSheetPins, bool &aHasGraphicItems, bool &aHasNonGraphicItems, bool &aIsGraphicsOnly)
Initialize the move/drag operation, setting up flags and connections.
bool Init() override
Init() is called once upon a registration of the tool.
VECTOR2I m_cursor
void trimDanglingLines(SCH_COMMIT *aCommit)
Break or slice the current selection before initiating a move, if required.
void orthoLineDrag(SCH_COMMIT *aCommit, SCH_LINE *line, const VECTOR2I &splitDelta, int &xBendCount, int &yBendCount, const EE_GRID_HELPER &grid)
std::unordered_set< SCH_LINE * > m_newDragLines
Lines changed by drag algorithm that weren't selected.
SCH_SHEET * findTargetSheet(const SCH_SELECTION &aSelection, const VECTOR2I &aCursorPos, bool aHasSheetPins, bool aIsGraphicsOnly, bool aCtrlDown)
Perform the actual move of items by delta, handling split moves and orthogonal dragging.
bool handleMoveToolActions(const TOOL_EVENT *aEvent, SCH_COMMIT *aCommit, const SCH_SELECTION &aSelection)
Update stored positions after transformations (rotation, mirroring, etc.) during move.
bool checkMoveInProgress(const TOOL_EVENT &aEvent, SCH_COMMIT *aCommit, bool aCurrentModeIsDragLike, bool aWasDragging)
< Check if a move is already in progress and handle state transitions
void initializeMoveOperation(const TOOL_EVENT &aEvent, SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, std::vector< DANGLING_END_ITEM > &aInternalPoints, GRID_HELPER_GRIDS &aSnapLayer)
Setup items for drag operation, collecting connected items.
OPT_VECTOR2I m_anchorPos
void performItemMove(SCH_SELECTION &aSelection, const VECTOR2I &aDelta, SCH_COMMIT *aCommit, int &aXBendCount, int &aYBendCount, const EE_GRID_HELPER &aGrid)
Handle tool action events during the move operation.
int Main(const TOOL_EVENT &aEvent)
Run an interactive move of the selected items, or the item under the cursor.
SCH_SELECTION & prepareSelection(bool &aUnselect)
Refresh selection traits (sheet pins, graphic items, etc.)
std::vector< SCH_JUNCTION * > m_hiddenJunctions
void setupItemsForMove(SCH_SELECTION &aSelection, std::vector< DANGLING_END_ITEM > &aInternalPoints)
Find the target sheet for dropping items (if any)
bool m_inMoveTool
< Re-entrancy guard
std::vector< KIID > m_dragAdditions
Cache of the line's original connections before dragging started.
void moveItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
Find additional items for a drag operation.
void setupItemsForDrag(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit)
Setup items for move operation, marking dangling ends.
std::unordered_set< SCH_LINE * > m_changedDragLines
Junctions that were hidden during the move.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
void finalizeMoveOperation(SCH_SELECTION &aSelection, SCH_COMMIT *aCommit, bool aUnselect, const std::vector< DANGLING_END_ITEM > &aInternalPoints)
void setTransitions() override
Cleanup dangling lines left after a drag.
void getConnectedItems(SCH_ITEM *aOriginalItem, const VECTOR2I &aPoint, EDA_ITEMS &aList)
std::map< SCH_LINE *, EDA_ITEMS > m_lineConnectionCache
Lines added at bend points dynamically during the move.
OPT_VECTOR2I m_breakPos
void updateStoredPositions(const SCH_SELECTION &aSelection)
Finalize the move operation, updating junctions and cleaning up.
bool doMoveSelection(const TOOL_EVENT &aEvent, SCH_COMMIT *aCommit)
void getConnectedDragItems(SCH_COMMIT *aCommit, SCH_ITEM *fixed, const VECTOR2I &selected, EDA_ITEMS &aList)
VECTOR2I m_moveOffset
Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point).
std::map< SCH_LABEL_BASE *, SPECIAL_CASE_LABEL_INFO > m_specialCaseLabels
int AlignToGrid(const TOOL_EVENT &aEvent)
Align selected elements to the grid.
void clearNewDragLines()
Set up handlers for various events.
MOVE_MODE m_mode
Items (such as wires) which were added to the selection for a drag.
void preprocessBreakOrSliceSelection(SCH_COMMIT *aCommit, const TOOL_EVENT &aEvent)
std::map< SCH_SHEET_PIN *, std::pair< SCH_LINE *, bool > > m_specialCaseSheetPins
void Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:115
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:44
bool IsTopLevelSheet() const
Check if this sheet is a top-level sheet.
SCH_SHEET_PIN * GetPin(const VECTOR2I &aPosition)
Return the sheet pin item found at aPosition in the sheet.
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:139
const BOX2I GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:227
Schematic symbol object.
Definition sch_symbol.h:69
VECTOR2I GetPosition() const override
Definition sch_text.h:146
void updateItem(EDA_ITEM *aItem, bool aUpdateRTree) const
bool Init() override
Init() is called once upon a registration of the tool.
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
SCH_TOOL_BASE(const std::string &aName)
SCH_SELECTION_TOOL * m_selectionTool
Definition seg.h:38
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition seg.cpp:629
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
virtual void Add(EDA_ITEM *aItem)
Definition selection.cpp:38
ITER end()
Definition selection.h:76
ITER begin()
Definition selection.h:75
VECTOR2I GetReferencePoint() const
bool IsHover() const
Definition selection.h:85
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:101
EDA_ITEM * Front() const
Definition selection.h:173
int Size() const
Returns the number of selected parts.
Definition selection.h:117
void SetReferencePoint(const VECTOR2I &aP)
bool Empty() const
Checks if there is anything selected.
Definition selection.h:111
std::vector< EDA_ITEM * > GetItemsSortedByTypeAndXY(bool leftBeforeRight=true, bool topBeforeBottom=true) const
Returns a copy of this selection of items sorted by their X then Y position.
bool HasReferencePoint() const
Definition selection.h:212
const TRANSFORM & GetTransform() const
Definition symbol.h:243
KIGFX::VIEW_CONTROLS * getViewControls() const
Definition tool_base.cpp:40
KIGFX::VIEW * getView() const
Definition tool_base.cpp:34
Generic, UI-independent tool event.
Definition tool_event.h:167
bool DisableGridSnapping() const
Definition tool_event.h:367
bool HasParameter() const
Definition tool_event.h:460
bool IsCancelInteractive() const
Indicate the event should restart/end an ongoing interactive tool's event loop (eg esc key,...
TOOL_ACTIONS Action() const
Returns more specific information about the type of an event.
Definition tool_event.h:246
bool IsActivate() const
Definition tool_event.h:341
COMMIT * Commit() const
Definition tool_event.h:279
bool IsClick(int aButtonMask=BUT_ANY) const
TOOL_EVENT_CATEGORY Category() const
Return the category (eg. mouse/keyboard/action) of an event.
Definition tool_event.h:243
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition tool_event.h:311
int Modifier(int aMask=MD_MODIFIER_MASK) const
Return information about key modifiers state (Ctrl, Alt, etc.).
Definition tool_event.h:362
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:469
bool IsDblClick(int aButtonMask=BUT_ANY) const
std::atomic< SYNCRONOUS_TOOL_STATE > * SynchronousState() const
Definition tool_event.h:276
std::optional< int > GetCommandId() const
Definition tool_event.h:529
void SetPassEvent(bool aPass=true)
Definition tool_event.h:252
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition tool_event.h:321
bool IsMotion() const
Definition tool_event.h:326
const std::string Format() const
Return information about event in form of a human-readable string.
void Go(int(SCH_EDIT_FRAME::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
std::unique_ptr< TOOL_MENU > m_menu
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:42
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition transform.cpp:55
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition transform.cpp:40
@ CHT_REMOVE
Definition commit.h:39
@ CHT_DONE
Flag to indicate the change is already applied.
Definition commit.h:43
@ CHT_ADD
Definition commit.h:38
KICURSOR
Definition cursors.h:40
@ PLACE
Definition cursors.h:94
@ MOVING
Definition cursors.h:44
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
@ RECURSE
Definition eda_item.h:49
@ NO_RECURSE
Definition eda_item.h:50
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
#define IS_CHANGED
Item was edited, and modified.
#define BRIGHTENED
item is drawn with a bright contour
#define IS_NEW
New item, just created.
#define SELECTED
Item was manually selected by the user.
#define SELECTED_BY_DRAG
Item was algorithmically selected as a dragged item.
#define IS_BROKEN
Is a segment just broken by BreakSegment.
#define STRUCT_DELETED
flag indication structures to be erased
#define ENDPOINT
ends. (Used to support dragging.)
#define IS_MOVING
Item being moved.
#define STARTPOINT
When a line is selected, these flags indicate which.
@ NONE
Definition eda_shape.h:72
@ ID_POPUP_SCH_SELECT_UNIT
Definition eeschema_id.h:81
@ ID_POPUP_SCH_SELECT_BODY_STYLE
Definition eeschema_id.h:91
@ ID_POPUP_SCH_SELECT_BODY_STYLE_END
Definition eeschema_id.h:93
@ ID_POPUP_SCH_SELECT_UNIT_END
Definition eeschema_id.h:85
@ LINE_MODE_FREE
GRID_HELPER_GRIDS
Definition grid_helper.h:40
@ GRID_CURRENT
Definition grid_helper.h:42
const wxChar *const traceSchMove
Flag to watch how schematic move tool actions are handled.
@ LAYER_WIRE
Definition layer_ids.h:450
@ LAYER_BUS
Definition layer_ids.h:451
@ LAYER_BUS_JUNCTION
Definition layer_ids.h:496
std::vector< SCH_JUNCTION * > PreviewJunctions(const class SCH_SCREEN *aScreen, const std::vector< class SCH_ITEM * > &aItems)
Determine the points where explicit junctions would be required if the given temporary items were com...
POINT_INFO AnalyzePoint(const EE_RTREE &aItem, const VECTOR2I &aPosition, bool aBreakCrossings)
Check a tree of items for a confluence at a given point and work out what kind of junction it is,...
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
bool signbit(T v)
Integral version of std::signbit that works all compilers.
Definition kicad_algo.h:172
see class PGM_BASE
Class to handle a set of SCH_ITEMs.
@ AUTOPLACE_NONE
Definition sch_item.h:66
void MoveSchematicItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
Move a schematic item by a delta.
void AlignSchematicItemsToGrid(SCH_SCREEN *aScreen, const std::vector< EDA_ITEM * > &aItems, EE_GRID_HELPER &aGrid, GRID_HELPER_GRIDS aSelectionGrid, const SCH_ALIGNMENT_CALLBACKS &aCallbacks)
Align a set of schematic items to the grid.
std::vector< EDA_ITEM * > EDA_ITEMS
#define QUIET_MODE
static bool isGraphicItemForDrop(const SCH_ITEM *aItem)
static void cloneWireConnection(SCH_LINE *aNewLine, SCH_ITEM *aSource, SCH_EDIT_FRAME *aFrame)
T * GetAppSettings(const char *aFilename)
The EE_TYPE struct provides a type-specific auto-range iterator to the RTree.
Definition sch_rtree.h:171
A selection of information about a point in the schematic that might be eligible for turning into a j...
VECTOR2D m_lastKeyboardCursorPosition
Position of the above event.
bool m_lastKeyboardCursorPositionValid
Is last cursor motion event coming from keyboard arrow cursor motion action.
long m_lastKeyboardCursorCommand
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
Callbacks for alignment operations.
std::function< void(SCH_ITEM *aItem, const VECTOR2I &aPoint, EDA_ITEMS &aList)> m_getConnectedDragItems
Callback to get items connected to a given item at a specific point.
std::function< void(EDA_ITEM *aItem, const VECTOR2I &aDelta)> m_doMoveItem
Callback to move an item by a delta.
std::function< void(EDA_ITEM *aItem)> m_updateItem
Optional callback to update an item's display after modification.
bool moved
KIBIS_PIN * pin
VECTOR2I end
int delta
@ TA_CHOICE_MENU_CHOICE
Context menu choice.
Definition tool_event.h:94
@ STS_CANCELLED
Definition tool_event.h:160
@ STS_FINISHED
Definition tool_event.h:159
@ STS_RUNNING
Definition tool_event.h:158
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ TC_COMMAND
Definition tool_event.h:53
@ TC_MOUSE
Definition tool_event.h:51
@ TC_KEYBOARD
Definition tool_event.h:52
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
wxLogTrace helper definitions.
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:71
@ SCH_LINE_T
Definition typeinfo.h:160
@ SCH_NO_CONNECT_T
Definition typeinfo.h:157
@ SCH_SYMBOL_T
Definition typeinfo.h:169
@ SCH_FIELD_T
Definition typeinfo.h:147
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:168
@ SCH_LABEL_T
Definition typeinfo.h:164
@ SCH_SHEET_T
Definition typeinfo.h:172
@ SCH_SHAPE_T
Definition typeinfo.h:146
@ SCH_HIER_LABEL_T
Definition typeinfo.h:166
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:159
@ SCH_SHEET_PIN_T
Definition typeinfo.h:171
@ SCH_TEXT_T
Definition typeinfo.h:148
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:158
@ SCH_BITMAP_T
Definition typeinfo.h:161
@ SCH_TEXTBOX_T
Definition typeinfo.h:149
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:165
@ SCH_JUNCTION_T
Definition typeinfo.h:156
@ SCH_PIN_T
Definition typeinfo.h:150
constexpr int sign(T val)
Definition util.h:141
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683
VECTOR2< double > VECTOR2D
Definition vector2d.h:682