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