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