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 (C) 2019-2024 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 <cmath>
26#include <wx/log.h>
27#include <trigo.h>
29#include <tool/tool_manager.h>
33#include <ee_actions.h>
34#include <sch_commit.h>
35#include <eda_item.h>
36#include <sch_item.h>
37#include <sch_symbol.h>
38#include <sch_sheet.h>
39#include <sch_sheet_pin.h>
40#include <sch_line.h>
41#include <sch_junction.h>
42#include <sch_edit_frame.h>
43#include <eeschema_id.h>
44#include <pgm_base.h>
45#include <view/view_controls.h>
47#include "sch_move_tool.h"
48
49
50// For adding to or removing from selections
51#define QUIET_MODE true
52
53
55 EE_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveMove" ),
56 m_inMoveTool( false ),
57 m_moveInProgress( false ),
58 m_isDrag( false ),
59 m_moveOffset( 0, 0 )
60{
61}
62
63
65{
67
68 auto moveCondition =
69 []( const SELECTION& aSel )
70 {
71 if( aSel.Empty() || SELECTION_CONDITIONS::OnlyTypes( { SCH_MARKER_T } )( aSel ) )
72 return false;
73
75 return false;
76
77 return true;
78 };
79
80 // Add move actions to the selection tool menu
81 //
83
84 selToolMenu.AddItem( EE_ACTIONS::move, moveCondition, 150 );
85 selToolMenu.AddItem( EE_ACTIONS::drag, moveCondition, 150 );
86 selToolMenu.AddItem( EE_ACTIONS::alignToGrid, moveCondition, 150 );
87
88 return true;
89}
90
91
92void SCH_MOVE_TOOL::orthoLineDrag( SCH_COMMIT* aCommit, SCH_LINE* line, const VECTOR2I& splitDelta,
93 int& xBendCount, int& yBendCount, const EE_GRID_HELPER& grid )
94{
95 // If the move is not the same angle as this move, then we need to do something special with
96 // the unselected end to maintain orthogonality. Either drag some connected line that is the
97 // same angle as the move or add two lines to make a 90 degree connection
98 if( !EDA_ANGLE( splitDelta ).IsParallelTo( line->Angle() ) || line->GetLength() == 0 )
99 {
100 VECTOR2I unselectedEnd = line->HasFlag( STARTPOINT ) ? line->GetEndPoint()
101 : line->GetStartPoint();
102 VECTOR2I selectedEnd = line->HasFlag( STARTPOINT ) ? line->GetStartPoint()
103 : line->GetEndPoint();
104
105 // Look for pre-existing lines we can drag with us instead of creating new ones
106 bool foundAttachment = false;
107 bool foundJunction = false;
108 bool foundPin = false;
109 SCH_LINE* foundLine = nullptr;
110
111 for( EDA_ITEM* cItem : m_lineConnectionCache[line] )
112 {
113 foundAttachment = true;
114
115 // If the move is the same angle as a connected line, we can shrink/extend that line
116 // endpoint
117 switch( cItem->Type() )
118 {
119 case SCH_LINE_T:
120 {
121 SCH_LINE* cLine = static_cast<SCH_LINE*>( cItem );
122
123 // A matching angle on a non-zero-length line means lengthen/shorten will work
124 if( EDA_ANGLE( splitDelta ).IsParallelTo( cLine->Angle() )
125 && cLine->GetLength() != 0 )
126 {
127 foundLine = cLine;
128 }
129
130 // Zero length lines are lines that this algorithm has shortened to 0 so they also
131 // work but we should prefer using a segment with length and angle matching when
132 // we can (otherwise the zero length line will draw overlapping segments on them)
133 if( !foundLine && cLine->GetLength() == 0 )
134 foundLine = cLine;
135
136 break;
137 }
138 case SCH_JUNCTION_T:
139 foundJunction = true;
140 break;
141
142 case SCH_PIN_T:
143 foundPin = true;
144 break;
145
146 case SCH_SHEET_T:
147 for( const auto& pair : m_specialCaseSheetPins )
148 {
149 if( pair.first->IsConnected( selectedEnd ) )
150 {
151 foundPin = true;
152 break;
153 }
154 }
155
156 break;
157
158 default:
159 break;
160 }
161 }
162
163 // Ok... what if our original line is length zero from moving in its direction, and the
164 // last added segment of the 90 bend we are connected to is zero from moving it in its
165 // direction after it was added?
166 //
167 // If we are moving in original direction, we should lengthen the original drag wire.
168 // Otherwise we should lengthen the new wire.
169 bool preferOriginalLine = false;
170
171 if( foundLine
172 && foundLine->GetLength() == 0
173 && line->GetLength() == 0
174 && EDA_ANGLE( splitDelta ).IsParallelTo( line->GetStoredAngle() ) )
175 {
176 preferOriginalLine = true;
177 }
178 // If we have found an attachment, but not a line, we want to check if it's a junction.
179 // These are special-cased and get a single line added instead of a 90-degree bend. Except
180 // when we're on a pin, because pins always need bends, and junctions are just added to
181 // pins for visual clarity.
182 else if( !foundLine && foundJunction && !foundPin )
183 {
184 // Create a new wire ending at the unselected end
185 foundLine = new SCH_LINE( unselectedEnd, line->GetLayer() );
186 foundLine->SetFlags( IS_NEW );
187 foundLine->SetLastResolvedState( line );
188 m_frame->AddToScreen( foundLine, m_frame->GetScreen() );
189 m_newDragLines.insert( foundLine );
190
191 // We just broke off of the existing items, so replace all of them with our new
192 // end connection.
194 m_lineConnectionCache[line].clear();
195 m_lineConnectionCache[line].emplace_back( foundLine );
196 }
197
198 // We want to drag our found line if it's in the same angle as the move or zero length,
199 // but if the original drag line is also zero and the same original angle we should extend
200 // that one first
201 if( foundLine && !preferOriginalLine )
202 {
203 // Move the connected line found oriented in the direction of our move.
204 //
205 // Make sure we grab the right endpoint, it's not always STARTPOINT since the user can
206 // draw a box of lines. We need to only move one though, and preferably the start point,
207 // in case we have a zero length line that we are extending (we want the foundLine
208 // start point to be attached to the unselected end of our drag line).
209 //
210 // Also, new lines are added already so they'll be in the undo list, skip adding them.
211
212 if( !foundLine->HasFlag( IS_CHANGED ) && !foundLine->HasFlag( IS_NEW ) )
213 {
214 aCommit->Modify( (SCH_ITEM*) foundLine, m_frame->GetScreen() );
215
216 if( !foundLine->IsSelected() )
217 m_changedDragLines.insert( foundLine );
218 }
219
220 if( foundLine->GetStartPoint() == unselectedEnd )
221 foundLine->MoveStart( splitDelta );
222 else if( foundLine->GetEndPoint() == unselectedEnd )
223 foundLine->MoveEnd( splitDelta );
224
225 updateItem( foundLine, true );
226
227 SCH_LINE* bendLine = nullptr;
228
229 if( m_lineConnectionCache.count( foundLine ) == 1
230 && m_lineConnectionCache[foundLine][0]->Type() == SCH_LINE_T )
231 {
232 bendLine = static_cast<SCH_LINE*>( m_lineConnectionCache[foundLine][0] );
233 }
234
235 // Remerge segments we've created if this is a segment that we've added whose only
236 // other connection is also an added segment
237 //
238 // bendLine is first added segment at the original attachment point, foundLine is the
239 // orthogonal line between bendLine and this line
240 if( foundLine->HasFlag( IS_NEW )
241 && foundLine->GetLength() == 0
242 && bendLine && bendLine->HasFlag( IS_NEW ) )
243 {
244 if( line->HasFlag( STARTPOINT ) )
245 line->SetEndPoint( bendLine->GetEndPoint() );
246 else
247 line->SetStartPoint( bendLine->GetEndPoint() );
248
249 // Update our cache of the connected items.
250
251 // First, re-attach our drag labels to the original line being re-merged.
252 for( EDA_ITEM* candidate : m_lineConnectionCache[bendLine] )
253 {
254 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( candidate );
255
256 if( label && m_specialCaseLabels.count( label ) )
257 m_specialCaseLabels[label].attachedLine = line;
258 }
259
261 m_lineConnectionCache[bendLine].clear();
262 m_lineConnectionCache[foundLine].clear();
263
264 m_frame->RemoveFromScreen( bendLine, m_frame->GetScreen() );
265 m_frame->RemoveFromScreen( foundLine, m_frame->GetScreen() );
266
267 m_newDragLines.erase( bendLine );
268 m_newDragLines.erase( foundLine );
269
270 delete bendLine;
271 delete foundLine;
272 }
273 //Ok, move the unselected end of our item
274 else
275 {
276 if( line->HasFlag( STARTPOINT ) )
277 line->MoveEnd( splitDelta );
278 else
279 line->MoveStart( splitDelta );
280 }
281
282 updateItem( line, true );
283 }
284 else if( line->GetLength() == 0 )
285 {
286 // We didn't find another line to shorten/lengthen, (or we did but it's also zero)
287 // so now is a good time to use our existing zero-length original line
288 }
289 // Either no line was at the "right" angle, or this was a junction, pin, sheet, etc. We
290 // need to add segments to keep the soon-to-move unselected end connected to these items.
291 //
292 // To keep our drag selections all the same, we'll move our unselected end point and then
293 // put wires between it and its original endpoint.
294 else if( foundAttachment && line->IsOrthogonal() )
295 {
296 VECTOR2D lineGrid = grid.GetGridSize( grid.GetItemGrid( line ) );
297
298 // The bend counter handles a group of wires all needing their offset one grid movement
299 // further out from each other to not overlap. The absolute value stuff finds the
300 // direction of the line and hence the the bend increment on that axis
301 unsigned int xMoveBit = splitDelta.x != 0;
302 unsigned int yMoveBit = splitDelta.y != 0;
303 int xLength = abs( unselectedEnd.x - selectedEnd.x );
304 int yLength = abs( unselectedEnd.y - selectedEnd.y );
305 int xMove = ( xLength - ( xBendCount * lineGrid.x ) )
306 * sign( selectedEnd.x - unselectedEnd.x );
307 int yMove = ( yLength - ( yBendCount * lineGrid.y ) )
308 * sign( selectedEnd.y - unselectedEnd.y );
309
310 // Create a new wire ending at the unselected end, we'll move the new wire's start
311 // point to the unselected end
312 SCH_LINE* a = new SCH_LINE( unselectedEnd, line->GetLayer() );
313 a->MoveStart( VECTOR2I( xMove, yMove ) );
314 a->SetFlags( IS_NEW );
315 a->SetConnectivityDirty( true );
316 a->SetLastResolvedState( line );
318 m_newDragLines.insert( a );
319
320 SCH_LINE* b = new SCH_LINE( a->GetStartPoint(), line->GetLayer() );
321 b->MoveStart( VECTOR2I( splitDelta.x, splitDelta.y ) );
322 b->SetFlags( IS_NEW | STARTPOINT );
323 b->SetConnectivityDirty( true );
324 b->SetLastResolvedState( line );
326 m_newDragLines.insert( b );
327
328 xBendCount += yMoveBit;
329 yBendCount += xMoveBit;
330
331 // Ok move the unselected end of our item
332 if( line->HasFlag( STARTPOINT ) )
333 {
334 line->MoveEnd( VECTOR2I( splitDelta.x ? splitDelta.x : xMove,
335 splitDelta.y ? splitDelta.y : yMove ) );
336 }
337 else
338 {
339 line->MoveStart( VECTOR2I( splitDelta.x ? splitDelta.x : xMove,
340 splitDelta.y ? splitDelta.y : yMove ) );
341 }
342
343 // Update our cache of the connected items. First, attach our drag labels to the line
344 // left behind.
345 for( EDA_ITEM* candidate : m_lineConnectionCache[line] )
346 {
347 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( candidate );
348
349 if( label && m_specialCaseLabels.count( label ) )
350 m_specialCaseLabels[label].attachedLine = a;
351 }
352
353 // We just broke off of the existing items, so replace all of them with our new end
354 // connection.
356 m_lineConnectionCache[b].emplace_back( a );
357 m_lineConnectionCache[line].clear();
358 m_lineConnectionCache[line].emplace_back( b );
359 }
360 // Original line has no attachments, just move the unselected end
361 else if( !foundAttachment )
362 {
363 if( line->HasFlag( STARTPOINT ) )
364 line->MoveEnd( splitDelta );
365 else
366 line->MoveStart( splitDelta );
367 }
368 }
369}
370
371
372int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
373{
375
376 if( SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() ) )
377 {
378 bool isSlice = false;
379
380 if( m_isDrag )
381 isSlice = aEvent.Parameter<bool>();
382
383 wxCHECK( aEvent.SynchronousState(), 0 );
384 aEvent.SynchronousState()->store( STS_RUNNING );
385
386 if( doMoveSelection( aEvent, commit, isSlice ) )
387 aEvent.SynchronousState()->store( STS_FINISHED );
388 else
389 aEvent.SynchronousState()->store( STS_CANCELLED );
390 }
391 else
392 {
393 SCH_COMMIT localCommit( m_toolMgr );
394
395 if( doMoveSelection( aEvent, &localCommit, false ) )
396 localCommit.Push( m_isDrag ? _( "Drag" ) : _( "Move" ) );
397 else
398 localCommit.Revert();
399 }
400
401 return 0;
402}
403
404
405bool SCH_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit, bool aIsSlice )
406{
407 EESCHEMA_SETTINGS* cfg = nullptr;
408
409 try
410 {
412 }
413 catch( const std::runtime_error& e )
414 {
415 wxCHECK_MSG( false, false, e.what() );
416 }
417
420 bool wasDragging = m_moveInProgress && m_isDrag;
421
422 m_anchorPos.reset();
423
424 if( m_moveInProgress )
425 {
426 if( m_isDrag != wasDragging )
427 {
429
430 if( sel && !sel->IsNew() )
431 {
432 // Reset the selected items so we can start again with the current m_isDrag
433 // state.
434 aCommit->Revert();
435
438 m_moveInProgress = false;
439 controls->SetAutoPan( false );
440
441 // And give it a kick so it doesn't have to wait for the first mouse movement
442 // to refresh.
444 }
445 }
446 else
447 {
448 // The tool hotkey is interpreted as a click when already dragging/moving
450 }
451
452 return false;
453 }
454
455 if( m_inMoveTool ) // Must come after m_moveInProgress checks above...
456 return false;
457
459
460 // Be sure that there is at least one item that we can move. If there's no selection try
461 // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
463 true );
464 bool unselect = selection.IsHover();
465
466 // Keep an original copy of the starting points for cleanup after the move
467 std::vector<DANGLING_END_ITEM> internalPoints;
468
469 Activate();
470
471 // Must be done after Activate() so that it gets set into the correct context
472 controls->ShowCursor( true );
473
474 m_frame->PushTool( aEvent );
475
476 if( selection.Empty() )
477 {
478 // Note that it's important to go through push/pop even when the selection is empty.
479 // This keeps other tools from having to special-case an empty move.
480 m_frame->PopTool( aEvent );
481 return false;
482 }
483
484 bool restore_state = false;
485 TOOL_EVENT copy = aEvent;
486 TOOL_EVENT* evt = &copy;
487 VECTOR2I prevPos;
489
490 m_cursor = controls->GetCursorPosition();
491
492 // Main loop: keep receiving events
493 do
494 {
495 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
496 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
497 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
498
500 || evt->IsAction( &EE_ACTIONS::move )
501 || evt->IsAction( &EE_ACTIONS::drag )
502 || evt->IsMotion()
503 || evt->IsDrag( BUT_LEFT )
505 {
506 if( !m_moveInProgress ) // Prepare to start moving/dragging
507 {
508 SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
509 bool placingNewItems = sch_item && sch_item->IsNew();
510
511 //------------------------------------------------------------------------
512 // Setup a drag or a move
513 //
514 m_dragAdditions.clear();
515 m_specialCaseLabels.clear();
517 internalPoints.clear();
519
520 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
521 {
522 it->ClearFlags( SELECTED_BY_DRAG );
523
524 if( !it->IsSelected() )
525 it->ClearFlags( STARTPOINT | ENDPOINT );
526 }
527
528 // Drag of split items start over top of their other segment so
529 // we want to skip grabbing the segments we split from
530 if( m_isDrag && !aIsSlice )
531 {
532 EDA_ITEMS connectedDragItems;
533
534 // Add connections to the selection for a drag.
535 // Do all non-labels/entries first so we don't add junctions to drag
536 // when the line will eventually be drag selected.
537 std::vector<SCH_ITEM*> stageTwo;
538
539 for( EDA_ITEM* edaItem : selection )
540 {
541 SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
542 std::vector<VECTOR2I> connections;
543
544 switch( item->Type() )
545 {
546 case SCH_LABEL_T:
547 case SCH_HIER_LABEL_T:
550 stageTwo.emplace_back(item);
551 break;
552
553 case SCH_LINE_T:
554 static_cast<SCH_LINE*>( item )->GetSelectedPoints( connections );
555 break;
556 default:
557 connections = item->GetConnectionPoints();
558 }
559
560 for( const VECTOR2I& point : connections )
561 getConnectedDragItems( aCommit, item, point, connectedDragItems );
562 }
563
564 // Go back and get all label connections now that we can test for drag-selected
565 // lines the labels might be on
566 for( SCH_ITEM* item : stageTwo )
567 {
568 for( const VECTOR2I& point : item->GetConnectionPoints() )
569 getConnectedDragItems( aCommit, item, point, connectedDragItems );
570 }
571
572 for( EDA_ITEM* item : connectedDragItems )
573 {
574 m_dragAdditions.push_back( item->m_Uuid );
576 }
577
578 // Pre-cache all connections of our selected objects so we can keep track of
579 // what they were originally connected to as we drag them around
580 for( EDA_ITEM* edaItem : selection )
581 {
582 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( edaItem );
583
584 if( schItem->Type() == SCH_LINE_T )
585 {
586 SCH_LINE* line = static_cast<SCH_LINE*>( schItem );
587
588 //Also store the original angle of the line, is needed later to decide
589 //which segment to extend when they've become zero length
590 line->StoreAngle();
591
592 for( const VECTOR2I& point : line->GetConnectionPoints() )
593 getConnectedItems( line, point, m_lineConnectionCache[line] );
594 }
595 }
596 }
597 else
598 {
599 // Mark the edges of the block with dangling flags for a move.
600 for( EDA_ITEM* item : selection )
601 static_cast<SCH_ITEM*>( item )->GetEndPoints( internalPoints );
602
603 std::vector<DANGLING_END_ITEM> endPointsByType = internalPoints;
604 std::vector<DANGLING_END_ITEM> endPointsByPos = endPointsByType;
606 endPointsByPos );
607
608 for( EDA_ITEM* item : selection )
609 static_cast<SCH_ITEM*>( item )->UpdateDanglingState( endPointsByType,
610 endPointsByPos );
611 }
612
613
614 // Generic setup
615 snapLayer = grid.GetSelectionGrid( selection );
616
617 for( EDA_ITEM* item : selection )
618 {
619 if( item->IsNew() )
620 {
621 // Item was added to commit in a previous command
622 }
623 else if( item->GetParent() && item->GetParent()->IsSelected() )
624 {
625 // Item will be (or has been) added to commit by parent
626 }
627 else
628 {
629 aCommit->Modify( item, m_frame->GetScreen() );
630 }
631
632 item->SetFlags( IS_MOVING );
633
634 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
635 schItem->SetStoredPos( schItem->GetPosition() );
636 }
637
638 // Set up the starting position and move/drag offset
639 //
640 m_cursor = controls->GetCursorPosition();
641
642 if( evt->IsAction( &EE_ACTIONS::restartMove ) )
643 {
644 wxASSERT_MSG( m_anchorPos, "Should be already set from previous cmd" );
645 }
646 else if( placingNewItems )
647 {
648 m_anchorPos = selection.GetReferencePoint();
649 }
650
651 if( m_anchorPos )
652 {
653 VECTOR2I delta = m_cursor - (*m_anchorPos);
654 bool isPasted = false;
655
656 // Drag items to the current cursor position
657 for( EDA_ITEM* item : selection )
658 {
659 // Don't double move pins, fields, etc.
660 if( item->GetParent() && item->GetParent()->IsSelected() )
661 continue;
662
663 moveItem( item, delta );
664 updateItem( item, false );
665
666 isPasted |= ( item->GetFlags() & IS_PASTED ) != 0;
667 item->ClearFlags( IS_PASTED );
668 }
669
670 // The first time pasted items are moved we need to store the position of the
671 // cursor so that rotate while moving works as expected (instead of around the
672 // original anchor point
673 if( isPasted )
674 selection.SetReferencePoint( m_cursor );
675
677 }
678 // For some items, moving the cursor to anchor is not good (for instance large
679 // hierarchical sheets or symbols can have the anchor outside the view)
680 else if( selection.Size() == 1 && !sch_item->IsMovableFromAnchorPoint() )
681 {
684 }
685 else
686 {
688 {
689 // User wants to warp the mouse
690 m_cursor = grid.BestDragOrigin( m_cursor, snapLayer, selection );
691 selection.SetReferencePoint( m_cursor );
692 }
693 else
694 {
695 // User does not want to warp the mouse
697 }
698 }
699
700 controls->SetCursorPosition( m_cursor, false );
701
702 prevPos = m_cursor;
703 controls->SetAutoPan( true );
704 m_moveInProgress = true;
705 }
706
707 //------------------------------------------------------------------------
708 // Follow the mouse
709 //
710 m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ),
711 snapLayer, selection );
712
713 VECTOR2I delta( m_cursor - prevPos );
715
716 // We need to check if the movement will change the net offset direction on the
717 // X an Y axes. This is because we remerge added bend lines in realtime, and we
718 // also account for the direction of the move when adding bend lines. So, if the
719 // move direction changes, we need to split it into a move that gets us back to
720 // zero, then the rest of the move.
721 std::vector<VECTOR2I> splitMoves;
722
724 {
725 splitMoves.emplace_back( VECTOR2I( -1 * m_moveOffset.x, 0 ) );
726 splitMoves.emplace_back( VECTOR2I( delta.x + m_moveOffset.x, 0 ) );
727 }
728 else
729 {
730 splitMoves.emplace_back( VECTOR2I( delta.x, 0 ) );
731 }
732
734 {
735 splitMoves.emplace_back( VECTOR2I( 0, -1 * m_moveOffset.y ) );
736 splitMoves.emplace_back( VECTOR2I( 0, delta.y + m_moveOffset.y ) );
737 }
738 else
739 {
740 splitMoves.emplace_back( VECTOR2I( 0, delta.y ) );
741 }
742
743
745 prevPos = m_cursor;
746
747 // Used for tracking how far off a drag end should have its 90 degree elbow added
748 int xBendCount = 1;
749 int yBendCount = 1;
750
751 // Split the move into X and Y moves so we can correctly drag orthogonal lines
752 for( const VECTOR2I& splitDelta : splitMoves )
753 {
754 // Skip non-moves
755 if( splitDelta == VECTOR2I( 0, 0 ) )
756 continue;
757
758 for( EDA_ITEM* item : selection.GetItemsSortedByTypeAndXY( ( delta.x >= 0 ),
759 ( delta.y >= 0 ) ) )
760 {
761 // Don't double move pins, fields, etc.
762 if( item->GetParent() && item->GetParent()->IsSelected() )
763 continue;
764
765 SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
766
767 // Only partially selected drag lines in orthogonal line mode need special
768 // handling
769 if( m_isDrag
770 && cfg->m_Drawing.line_mode != LINE_MODE::LINE_MODE_FREE
771 && line
772 && line->HasFlag( STARTPOINT ) != line->HasFlag( ENDPOINT ) )
773 {
774 orthoLineDrag( aCommit, line, splitDelta, xBendCount, yBendCount, grid );
775 }
776
777 // Move all other items normally, including the selected end of partially
778 // selected lines
779 moveItem( item, splitDelta );
780 updateItem( item, false );
781
782 // Update any lines connected to sheet pins to the sheet pin's location
783 // (which may not exactly follow the splitDelta as the pins are constrained
784 // along the sheet edges.
785 for( const auto& [pin, lineEnd] : m_specialCaseSheetPins )
786 {
787 if( lineEnd.second && lineEnd.first->HasFlag( STARTPOINT ) )
788 lineEnd.first->SetStartPoint( pin->GetPosition() );
789 else if( !lineEnd.second && lineEnd.first->HasFlag( ENDPOINT ) )
790 lineEnd.first->SetEndPoint( pin->GetPosition() );
791 }
792 }
793 }
794
795 if( selection.HasReferencePoint() )
796 selection.SetReferencePoint( selection.GetReferencePoint() + delta );
797
799 }
800
801 //------------------------------------------------------------------------
802 // Handle cancel
803 //
804 else if( evt->IsCancelInteractive() || evt->IsActivate() )
805 {
806 if( evt->IsCancelInteractive() )
808
809 if( m_moveInProgress )
810 {
811 if( evt->IsActivate() )
812 {
813 // Allowing other tools to activate during a move runs the risk of race
814 // conditions in which we try to spool up both event loops at once.
815
816 if( m_isDrag )
817 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel drag." ) );
818 else
819 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel move." ) );
820
821 evt->SetPassEvent( false );
822 continue;
823 }
824
825 evt->SetPassEvent( false );
826 restore_state = true;
827 }
828
830
831 break;
832 }
833 //------------------------------------------------------------------------
834 // Handle TOOL_ACTION special cases
835 //
836 else if( evt->Action() == TA_UNDO_REDO_PRE )
837 {
838 unselect = true;
839 break;
840 }
841 else if( evt->IsAction( &ACTIONS::doDelete ) )
842 {
843 evt->SetPassEvent();
844 // Exit on a delete; there will no longer be anything to drag.
845 break;
846 }
847 else if( evt->IsAction( &ACTIONS::duplicate ) )
848 {
849 wxBell();
850 }
851 else if( evt->IsAction( &EE_ACTIONS::rotateCW ) )
852 {
854 }
855 else if( evt->IsAction( &EE_ACTIONS::rotateCCW ) )
856 {
858 }
859 else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
860 {
863 {
864 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
865 int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
866
867 if( symbol )
868 {
869 m_frame->SelectUnit( symbol, unit );
871 }
872 }
873 else if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_BASE
875 {
876 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
877 int bodyStyle = ( *evt->GetCommandId() - ID_POPUP_SCH_SELECT_BASE ) + 1;
878
879 if( symbol && symbol->GetBodyStyle() != bodyStyle )
880 {
881 m_frame->FlipBodyStyle( symbol );
883 }
884 }
885 }
886 else if( evt->IsAction( &EE_ACTIONS::highlightNet )
888 {
889 // These don't make any sense during a move. Eat them.
890 }
891 //------------------------------------------------------------------------
892 // Handle context menu
893 //
894 else if( evt->IsClick( BUT_RIGHT ) )
895 {
897 }
898 //------------------------------------------------------------------------
899 // Handle drop
900 //
901 else if( evt->IsMouseUp( BUT_LEFT )
902 || evt->IsClick( BUT_LEFT )
903 || evt->IsDblClick( BUT_LEFT ) )
904 {
905 break; // Finish
906 }
907 else
908 {
909 evt->SetPassEvent();
910 }
911
912 controls->SetAutoPan( m_moveInProgress );
913
914 } while( ( evt = Wait() ) ); //Should be assignment not equality test
915
916 // Create a selection of original selection, drag selected/changed items, and new
917 // bend lines for later before we clear them in the aCommit. We'll need these
918 // to check for new junctions needed, etc.
919 EE_SELECTION selectionCopy( selection );
920
921 for( SCH_LINE* line : m_newDragLines )
922 selectionCopy.Add( line );
923
924 for( SCH_LINE* line : m_changedDragLines )
925 selectionCopy.Add( line );
926
927 // Save whatever new bend lines and changed lines survived the drag
928 for( SCH_LINE* newLine : m_newDragLines )
929 {
930 newLine->ClearEditFlags();
931 aCommit->Added( newLine, m_frame->GetScreen() );
932 }
933
934 // These lines have been changed, but aren't selected. We need
935 // to manually clear these edit flags or they'll stick around.
936 for( SCH_LINE* oldLine : m_changedDragLines )
937 oldLine->ClearEditFlags();
938
939 m_newDragLines.clear();
940 m_changedDragLines.clear();
941
942 controls->ForceCursorPosition( false );
943 controls->ShowCursor( false );
944 controls->SetAutoPan( false );
945
946 m_moveOffset = { 0, 0 };
947 m_anchorPos.reset();
948
949 if( restore_state )
950 {
952 }
953 else
954 {
955 // One last update after exiting loop (for slower stuff, such as updating SCREEN's RTree).
956 for( EDA_ITEM* item : selection )
957 {
958 updateItem( item, true );
959
960 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
961 sch_item->SetConnectivityDirty( true );
962 }
963
964 if( selection.GetSize() == 1 && selection.Front()->IsNew() )
965 m_frame->SaveCopyForRepeatItem( static_cast<SCH_ITEM*>( selection.Front() ) );
966
968
969 // If we move items away from a junction, we _may_ want to add a junction there
970 // to denote the state.
971 for( const DANGLING_END_ITEM& it : internalPoints )
972 {
973 if( m_frame->GetScreen()->IsExplicitJunctionNeeded( it.GetPosition()) )
974 m_frame->AddJunction( aCommit, m_frame->GetScreen(), it.GetPosition() );
975 }
976
978 lwbTool->TrimOverLappingWires( aCommit, &selectionCopy );
979 lwbTool->AddJunctionsIfNeeded( aCommit, &selectionCopy );
980
981 // This needs to run prior to `RecalculateConnections` because we need to identify
982 // the lines that are newly dangling
983 if( m_isDrag && !aIsSlice )
984 trimDanglingLines( aCommit );
985
986 // Auto-rotate any moved labels
987 for( EDA_ITEM* item : selection )
988 m_frame->AutoRotateItem( m_frame->GetScreen(), static_cast<SCH_ITEM*>( item ) );
989
990 m_frame->SchematicCleanUp( aCommit );
991 }
992
993 for( EDA_ITEM* item : m_frame->GetScreen()->Items() )
994 item->ClearEditFlags();
995
996 // ensure any selected item not in screen main list (for instance symbol fields)
997 // has its edit flags cleared
998 for( EDA_ITEM* item : selectionCopy )
999 item->ClearEditFlags();
1000
1001 if( unselect )
1003 else
1004 m_selectionTool->RebuildSelection(); // Schematic cleanup might have merged lines, etc.
1005
1006 m_dragAdditions.clear();
1007 m_lineConnectionCache.clear();
1008 m_moveInProgress = false;
1009 m_frame->PopTool( aEvent );
1010
1011 return !restore_state;
1012}
1013
1014
1016{
1017 // Need a local cleanup first to ensure we remove unneeded junctions
1018 m_frame->SchematicCleanUp( aCommit, m_frame->GetScreen() );
1019
1020 std::set<SCH_ITEM*> danglers;
1021
1022 std::function<void( SCH_ITEM* )> changeHandler =
1023 [&]( SCH_ITEM* aChangedItem ) -> void
1024 {
1025 m_toolMgr->GetView()->Update( aChangedItem, KIGFX::REPAINT );
1026
1027 // Delete newly dangling lines:
1028 // Find split segments (one segment is new, the other is changed) that
1029 // we aren't dragging and don't have selected
1030 if( aChangedItem->HasFlag( IS_BROKEN) && aChangedItem->IsDangling()
1031 && !aChangedItem->IsSelected() )
1032 {
1033 danglers.insert( aChangedItem );
1034 }
1035 };
1036
1037 m_frame->GetScreen()->TestDanglingEnds( nullptr, &changeHandler );
1038
1039 for( SCH_ITEM* line : danglers )
1040 {
1041 line->SetFlags( STRUCT_DELETED );
1042 aCommit->Removed( line, m_frame->GetScreen() );
1043
1044 updateItem( line, false );
1046 }
1047}
1048
1049
1050void SCH_MOVE_TOOL::getConnectedItems( SCH_ITEM* aOriginalItem, const VECTOR2I& aPoint,
1051 EDA_ITEMS& aList )
1052{
1053 EE_RTREE& items = m_frame->GetScreen()->Items();
1054 EE_RTREE::EE_TYPE itemsOverlapping = items.Overlapping( aOriginalItem->GetBoundingBox() );
1055 SCH_ITEM* foundJunction = nullptr;
1056 SCH_ITEM* foundSymbol = nullptr;
1057
1058 // If you're connected to a junction, you're only connected to the junction.
1059 //
1060 // But, if you're connected to a junction on a pin, you're only connected to the pin. This
1061 // is because junctions and pins have different logic for how bend lines are generated and
1062 // we need to prioritize the pin version in some cases.
1063 for( SCH_ITEM* item : itemsOverlapping )
1064 {
1065 if( item != aOriginalItem && item->IsConnected( aPoint ) )
1066 {
1067 if( item->Type() == SCH_JUNCTION_T )
1068 foundJunction = item;
1069 else if( item->Type() == SCH_SYMBOL_T )
1070 foundSymbol = item;
1071 }
1072 }
1073
1074 if( foundSymbol && foundJunction )
1075 {
1076 aList.push_back( foundSymbol );
1077 return;
1078 }
1079
1080 if( foundJunction )
1081 {
1082 aList.push_back( foundJunction );
1083 return;
1084 }
1085
1086
1087 for( SCH_ITEM* test : itemsOverlapping )
1088 {
1089 if( test == aOriginalItem || !test->CanConnect( aOriginalItem ) )
1090 continue;
1091
1092 switch( test->Type() )
1093 {
1094 case SCH_LINE_T:
1095 {
1096 SCH_LINE* line = static_cast<SCH_LINE*>( test );
1097
1098 // When getting lines for the connection cache, it's important that we only add
1099 // items at the unselected end, since that is the only end that is handled specially.
1100 // Fully selected lines, and the selected end of a partially selected line, are moved
1101 // around normally and don't care about their connections.
1102 if( ( line->HasFlag( STARTPOINT ) && aPoint == line->GetStartPoint() )
1103 || ( line->HasFlag( ENDPOINT ) && aPoint == line->GetEndPoint() ) )
1104 {
1105 continue;
1106 }
1107
1108 if( test->IsConnected( aPoint ) )
1109 aList.push_back( test );
1110
1111 // Labels can connect to a wire (or bus) anywhere along the length
1112 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aOriginalItem ) )
1113 {
1114 if( static_cast<SCH_LINE*>( test )->HitTest( label->GetPosition(), 1 ) )
1115 aList.push_back( test );
1116 }
1117
1118 break;
1119 }
1120
1121 case SCH_SHEET_T:
1122 if( aOriginalItem->Type() == SCH_LINE_T )
1123 {
1124 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1125
1126 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
1127 {
1128 if( pin->IsConnected( aPoint ) )
1129 {
1130 if( pin->IsSelected() )
1131 m_specialCaseSheetPins[pin] = { line,
1132 line->GetStartPoint() == aPoint };
1133
1134 aList.push_back( pin );
1135 }
1136 }
1137 }
1138
1139 break;
1140
1141 case SCH_SYMBOL_T:
1142 case SCH_JUNCTION_T:
1143 case SCH_NO_CONNECT_T:
1144 if( test->IsConnected( aPoint ) )
1145 aList.push_back( test );
1146
1147 break;
1148
1149 case SCH_LABEL_T:
1150 case SCH_GLOBAL_LABEL_T:
1151 case SCH_HIER_LABEL_T:
1153 // Labels can connect to a wire (or bus) anywhere along the length
1154 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
1155 {
1156 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
1157 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1158
1159 if( line->HitTest( label->GetPosition(), 1 ) )
1160 aList.push_back( label );
1161 }
1162
1163 break;
1164
1167 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
1168 {
1169 SCH_TEXT* label = static_cast<SCH_TEXT*>( test );
1170 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1171
1172 if( line->HitTest( aPoint, 1 ) )
1173 aList.push_back( label );
1174 }
1175
1176 break;
1177
1178 default:
1179 break;
1180 }
1181 }
1182}
1183
1184
1186 const VECTOR2I& aPoint, EDA_ITEMS& aList )
1187{
1188 EE_RTREE& items = m_frame->GetScreen()->Items();
1189 EE_RTREE::EE_TYPE itemsOverlappingRTree = items.Overlapping( aSelectedItem->GetBoundingBox() );
1190 std::vector<SCH_ITEM*> itemsConnectable;
1191 bool ptHasUnselectedJunction = false;
1192
1193 auto makeNewWire =
1194 [this]( SCH_COMMIT* commit, SCH_ITEM* fixed, SCH_ITEM* selected, const VECTOR2I& start,
1195 const VECTOR2I& end )
1196 {
1197 SCH_LINE* newWire;
1198
1199 // Add a new newWire between the fixed item and the selected item so the selected
1200 // item can be dragged.
1201 if( fixed->GetLayer() == LAYER_BUS_JUNCTION || fixed->GetLayer() == LAYER_BUS
1202 || selected->GetLayer() == LAYER_BUS )
1203 {
1204 newWire = new SCH_LINE( start, LAYER_BUS );
1205 }
1206 else
1207 {
1208 newWire = new SCH_LINE( start, LAYER_WIRE );
1209 }
1210
1211 newWire->SetFlags( IS_NEW );
1212 newWire->SetConnectivityDirty( true );
1213
1214 if( dynamic_cast<const SCH_LINE*>( selected ) )
1215 newWire->SetLastResolvedState( selected );
1216 else if( dynamic_cast<const SCH_LINE*>( fixed ) )
1217 newWire->SetLastResolvedState( fixed );
1218
1219 newWire->SetEndPoint( end );
1220 m_frame->AddToScreen( newWire, m_frame->GetScreen() );
1221 commit->Added( newWire, m_frame->GetScreen() );
1222
1223 return newWire;
1224 };
1225
1226 auto makeNewJunction =
1227 [this]( SCH_COMMIT* commit, SCH_LINE* line, const VECTOR2I& pt )
1228 {
1229 SCH_JUNCTION* junction = new SCH_JUNCTION( pt );
1230 junction->SetFlags( IS_NEW );
1231 junction->SetConnectivityDirty( true );
1232 junction->SetLastResolvedState( line );
1233
1234 if( line->IsBus() )
1235 junction->SetLayer( LAYER_BUS_JUNCTION );
1236
1237 m_frame->AddToScreen( junction, m_frame->GetScreen() );
1238 commit->Added( junction, m_frame->GetScreen() );
1239
1240 return junction;
1241 };
1242
1243 for( SCH_ITEM* item : itemsOverlappingRTree )
1244 {
1245 if( item->Type() == SCH_SHEET_T )
1246 {
1247 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1248
1249 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1250 {
1251 if( !pin->IsSelected() && pin->GetPosition() == aSelectedItem->GetPosition()
1252 && pin->CanConnect( aSelectedItem ) )
1253 {
1254 itemsConnectable.push_back( pin );
1255 }
1256 }
1257
1258 continue;
1259 }
1260
1261 // Skip ourselves, skip already selected items (but not lines, they need both ends tested)
1262 // and skip unconnectable items
1263 if( item == aSelectedItem || ( item->Type() != SCH_LINE_T && item->IsSelected() )
1264 || !item->CanConnect( aSelectedItem ) )
1265 {
1266 continue;
1267 }
1268
1269 itemsConnectable.push_back( item );
1270 }
1271
1272 for( SCH_ITEM* item : itemsConnectable )
1273 {
1274 if( item->Type() == SCH_JUNCTION_T && item->IsConnected( aPoint ) && !item->IsSelected() )
1275 {
1276 ptHasUnselectedJunction = true;
1277 break;
1278 }
1279 }
1280
1281 SCH_LINE* newWire = nullptr;
1282
1283 for( SCH_ITEM* test : itemsConnectable )
1284 {
1285 KICAD_T testType = test->Type();
1286
1287 switch( testType )
1288 {
1289 case SCH_LINE_T:
1290 {
1291 // Select the connected end of wires/bus connections that don't have an unselected
1292 // junction isolating them from the drag
1293 if( ptHasUnselectedJunction )
1294 break;
1295
1296 SCH_LINE* line = static_cast<SCH_LINE*>( test );
1297
1298 if( line->GetStartPoint() == aPoint )
1299 {
1300 // It's possible to manually select one end of a line and get a drag
1301 // connected other end, so we set the flag and then early exit the loop
1302 // later if the other drag items like labels attached to the line have
1303 // already been grabbed during the partial selection process.
1304 line->SetFlags( STARTPOINT );
1305
1306 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG ) )
1307 {
1308 continue;
1309 }
1310 else
1311 {
1312 line->SetFlags( SELECTED_BY_DRAG );
1313 aList.push_back( line );
1314 }
1315 }
1316 else if( line->GetEndPoint() == aPoint )
1317 {
1318 line->SetFlags( ENDPOINT );
1319
1320 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG ) )
1321 {
1322 continue;
1323 }
1324 else
1325 {
1326 line->SetFlags( SELECTED_BY_DRAG );
1327 aList.push_back( line );
1328 }
1329 }
1330 else
1331 {
1332 switch( aSelectedItem->Type() )
1333 {
1334 // These items can connect anywhere along a line
1337 case SCH_LABEL_T:
1338 case SCH_HIER_LABEL_T:
1339 case SCH_GLOBAL_LABEL_T:
1341 // Only add a line if this line is unselected; if the label and line are both
1342 // selected they'll move together
1343 if( line->HitTest( aPoint, 1 ) && !line->HasFlag( SELECTED )
1344 && !line->HasFlag( SELECTED_BY_DRAG ) )
1345 {
1346 newWire = makeNewWire( aCommit, line, aSelectedItem, aPoint, aPoint );
1347 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1348 newWire->StoreAngle( ( line->Angle() + ANGLE_90 ).Normalize() );
1349 aList.push_back( newWire );
1350
1351 if( aPoint != line->GetStartPoint() && aPoint != line->GetEndPoint() )
1352 {
1353 // Split line in half
1354 if( !line->IsNew() )
1355 aCommit->Modify( line, m_frame->GetScreen() );
1356
1357 VECTOR2I oldEnd = line->GetEndPoint();
1358 line->SetEndPoint( aPoint );
1359
1360 makeNewWire( aCommit, line, line, aPoint, oldEnd );
1361 makeNewJunction( aCommit, line, aPoint );
1362 }
1363 else
1364 {
1365 m_lineConnectionCache[ newWire ] = { line };
1366 m_lineConnectionCache[ line ] = { newWire };
1367 }
1368 }
1369 break;
1370
1371 default:
1372 break;
1373 }
1374
1375 break;
1376 }
1377
1378 // Since only one end is going to move, the movement vector of any labels attached to
1379 // it is scaled by the proportion of the line length the label is from the moving end.
1380 for( SCH_ITEM* item : items.Overlapping( line->GetBoundingBox() ) )
1381 {
1382 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item );
1383
1384 if( !label || label->IsSelected() )
1385 continue; // These will be moved on their own because they're selected
1386
1387 if( label->HasFlag( SELECTED_BY_DRAG ) )
1388 continue;
1389
1390 if( label->CanConnect( line ) && line->HitTest( label->GetPosition(), 1 ) )
1391 {
1392 label->SetFlags( SELECTED_BY_DRAG );
1393 aList.push_back( label );
1394
1396 info.attachedLine = line;
1397 info.originalLabelPos = label->GetPosition();
1398 m_specialCaseLabels[label] = info;
1399 }
1400 }
1401
1402 break;
1403 }
1404
1405 case SCH_SHEET_T:
1406 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
1407 {
1408 if( pin->IsConnected( aPoint ) )
1409 {
1410 if( pin->IsSelected() && aSelectedItem->Type() == SCH_LINE_T )
1411 {
1412 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1413 m_specialCaseSheetPins[ pin ] = { line, line->GetStartPoint() == aPoint };
1414 }
1415 else if( !newWire )
1416 {
1417 // Add a new wire between the sheetpin and the selected item so the
1418 // selected item can be dragged.
1419 newWire = makeNewWire( aCommit, pin, aSelectedItem, aPoint, aPoint );
1420 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1421 aList.push_back( newWire );
1422 }
1423 }
1424 }
1425
1426 break;
1427
1428 case SCH_SYMBOL_T:
1429 case SCH_JUNCTION_T:
1430 if( test->IsConnected( aPoint ) && !newWire )
1431 {
1432 // Add a new wire between the symbol or junction and the selected item so
1433 // the selected item can be dragged.
1434 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
1435 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1436 aList.push_back( newWire );
1437 }
1438
1439 break;
1440
1441 case SCH_NO_CONNECT_T:
1442 // Select no-connects that are connected to items being moved.
1443 if( !test->HasFlag( SELECTED_BY_DRAG ) && test->IsConnected( aPoint ) )
1444 {
1445 aList.push_back( test );
1446 test->SetFlags( SELECTED_BY_DRAG );
1447 }
1448
1449 break;
1450
1451 case SCH_LABEL_T:
1452 case SCH_GLOBAL_LABEL_T:
1453 case SCH_HIER_LABEL_T:
1455 case SCH_SHEET_PIN_T:
1456 // Performance optimization:
1457 if( test->HasFlag( SELECTED_BY_DRAG ) )
1458 break;
1459
1460 // Select labels that are connected to a wire (or bus) being moved.
1461 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
1462 {
1463 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
1464 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1465
1466 bool oneEndFixed = !line->HasFlag( STARTPOINT ) || !line->HasFlag( ENDPOINT );
1467
1468 if( line->HitTest( label->GetTextPos(), 1 ) )
1469 {
1470 if( ( !line->HasFlag( STARTPOINT )
1471 && label->GetPosition() == line->GetStartPoint() )
1472 || ( !line->HasFlag( ENDPOINT )
1473 && label->GetPosition() == line->GetEndPoint() ) )
1474 {
1475 //If we have a line selected at only one end, don't grab labels
1476 //connected directly to the unselected endpoint
1477 break;
1478 }
1479 else
1480 {
1481 label->SetFlags( SELECTED_BY_DRAG );
1482 aList.push_back( label );
1483
1484 if( oneEndFixed )
1485 {
1487 info.attachedLine = line;
1488 info.originalLabelPos = label->GetPosition();
1489 m_specialCaseLabels[label] = info;
1490 }
1491 }
1492 }
1493 }
1494 else if( test->IsConnected( aPoint ) && !newWire )
1495 {
1496 // Add a new wire between the label and the selected item so the selected item
1497 // can be dragged.
1498 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
1499 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1500 aList.push_back( newWire );
1501 }
1502
1503 break;
1504
1507 // Performance optimization:
1508 if( test->HasFlag( SELECTED_BY_DRAG ) )
1509 break;
1510
1511 // Select bus entries that are connected to a bus being moved.
1512 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
1513 {
1514 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1515
1516 if( ( !line->HasFlag( STARTPOINT ) && test->IsConnected( line->GetStartPoint() ) )
1517 || ( !line->HasFlag( ENDPOINT ) && test->IsConnected( line->GetEndPoint() ) ) )
1518 {
1519 // If we have a line selected at only one end, don't grab bus entries
1520 // connected directly to the unselected endpoint
1521 continue;
1522 }
1523
1524 for( VECTOR2I& point : test->GetConnectionPoints() )
1525 {
1526 if( line->HitTest( point, 1 ) )
1527 {
1528 test->SetFlags( SELECTED_BY_DRAG );
1529 aList.push_back( test );
1530
1531 // A bus entry needs its wire & label as well
1532 std::vector<VECTOR2I> ends = test->GetConnectionPoints();
1533 VECTOR2I otherEnd;
1534
1535 if( ends[0] == point )
1536 otherEnd = ends[1];
1537 else
1538 otherEnd = ends[0];
1539
1540 getConnectedDragItems( aCommit, test, otherEnd, aList );
1541
1542 // No need to test the other end of the bus entry
1543 break;
1544 }
1545 }
1546 }
1547
1548 break;
1549
1550 default:
1551 break;
1552 }
1553 }
1554}
1555
1556
1557void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
1558{
1559 switch( aItem->Type() )
1560 {
1561 case SCH_LINE_T:
1562 {
1563 SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
1564
1565 if( aItem->HasFlag( STARTPOINT ) || !m_isDrag )
1566 line->MoveStart( aDelta );
1567
1568 if( aItem->HasFlag( ENDPOINT ) || !m_isDrag )
1569 line->MoveEnd( aDelta );
1570
1571 break;
1572 }
1573
1574 case SCH_PIN_T:
1575 case SCH_FIELD_T:
1576 {
1577 SCH_ITEM* parent = (SCH_ITEM*) aItem->GetParent();
1578 VECTOR2I delta( aDelta );
1579
1580 if( parent && parent->Type() == SCH_SYMBOL_T )
1581 {
1582 SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem->GetParent();
1583 TRANSFORM transform = symbol->GetTransform().InverseTransform();
1584
1585 delta = transform.TransformCoordinate( delta );
1586 }
1587
1588 static_cast<SCH_ITEM*>( aItem )->Move( delta );
1589
1590 // If we're moving a field with respect to its parent then it's no longer auto-placed
1591 if( aItem->Type() == SCH_FIELD_T && parent && !parent->IsSelected() )
1592 parent->ClearFieldsAutoplaced();
1593
1594 break;
1595 }
1596
1597 case SCH_SHEET_PIN_T:
1598 {
1599 SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) aItem;
1600
1601 pin->SetStoredPos( pin->GetStoredPos() + aDelta );
1602 pin->ConstrainOnEdge( pin->GetStoredPos(), true );
1603 break;
1604 }
1605
1606 case SCH_LABEL_T:
1608 case SCH_GLOBAL_LABEL_T:
1609 case SCH_HIER_LABEL_T:
1610 {
1611 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
1612
1613 if( m_specialCaseLabels.count( label ) )
1614 {
1616 SEG currentLine( info.attachedLine->GetStartPoint(), info.attachedLine->GetEndPoint() );
1617 label->SetPosition( currentLine.NearestPoint( info.originalLabelPos ) );
1618 }
1619 else
1620 {
1621 label->Move( aDelta );
1622 }
1623
1624 break;
1625 }
1626
1627 default:
1628 static_cast<SCH_ITEM*>( aItem )->Move( aDelta );
1629 break;
1630 }
1631
1632 aItem->SetFlags( IS_MOVING );
1633}
1634
1635
1637{
1640 GRID_HELPER_GRIDS selectionGrid = grid.GetSelectionGrid( selection );
1641 SCH_COMMIT commit( m_toolMgr );
1642
1643 auto doMoveItem =
1644 [&]( EDA_ITEM* item, const VECTOR2I& delta )
1645 {
1646 commit.Modify( item, m_frame->GetScreen() );
1647
1648 // Ensure only one end is moved when calling moveItem
1649 // i.e. we are in drag mode
1650 bool tmp_isDrag = m_isDrag;
1651 m_isDrag = true;
1652 moveItem( item, delta );
1653 m_isDrag = tmp_isDrag;
1654
1655 item->ClearFlags( IS_MOVING );
1656 updateItem( item, true );
1657 };
1658
1659 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
1660 {
1661 if( !it->IsSelected() )
1662 it->ClearFlags( STARTPOINT | ENDPOINT );
1663
1664 if( !selection.IsHover() && it->IsSelected() )
1665 it->SetFlags( STARTPOINT | ENDPOINT );
1666
1667 it->SetStoredPos( it->GetPosition() );
1668
1669 if( it->Type() == SCH_SHEET_T )
1670 {
1671 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( it )->GetPins() )
1672 pin->SetStoredPos( pin->GetPosition() );
1673 }
1674 }
1675
1676 for( EDA_ITEM* item : selection )
1677 {
1678 if( item->Type() == SCH_LINE_T )
1679 {
1680 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1681 std::vector<int> flags{ STARTPOINT, ENDPOINT };
1682 std::vector<VECTOR2I> pts{ line->GetStartPoint(), line->GetEndPoint() };
1683
1684 for( int ii = 0; ii < 2; ++ii )
1685 {
1686 EDA_ITEMS drag_items{ item };
1687 line->ClearFlags();
1688 line->SetFlags( SELECTED );
1689 line->SetFlags( flags[ii] );
1690 getConnectedDragItems( &commit, line, pts[ii], drag_items );
1691 std::set<EDA_ITEM*> unique_items( drag_items.begin(), drag_items.end() );
1692
1693 VECTOR2I delta = grid.AlignGrid( pts[ii], selectionGrid ) - pts[ii];
1694
1695 if( delta != VECTOR2I( 0, 0 ) )
1696 {
1697 for( EDA_ITEM* dragItem : unique_items )
1698 {
1699 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
1700 continue;
1701
1702 doMoveItem( dragItem, delta );
1703 }
1704 }
1705 }
1706 }
1707 else if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TEXT_T )
1708 {
1709 VECTOR2I delta = grid.AlignGrid( item->GetPosition(), selectionGrid ) - item->GetPosition();
1710
1711 if( delta != VECTOR2I( 0, 0 ) )
1712 doMoveItem( item, delta );
1713 }
1714 else if( item->Type() == SCH_SHEET_T )
1715 {
1716 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1717 VECTOR2I topLeft = sheet->GetPosition();
1718 VECTOR2I bottomRight = topLeft + sheet->GetSize();
1719 VECTOR2I tl_delta = grid.AlignGrid( topLeft, selectionGrid ) - topLeft;
1720 VECTOR2I br_delta = grid.AlignGrid( bottomRight, selectionGrid ) - bottomRight;
1721
1722 if( tl_delta != VECTOR2I( 0, 0 ) || br_delta != VECTOR2I( 0, 0 ) )
1723 {
1724 doMoveItem( sheet, tl_delta );
1725
1726 VECTOR2I newSize = (VECTOR2I) sheet->GetSize() - tl_delta + br_delta;
1727 sheet->SetSize( VECTOR2I( newSize.x, newSize.y ) );
1728 updateItem( sheet, true );
1729 }
1730
1731 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1732 {
1733 VECTOR2I newPos;
1734
1735 if( pin->GetSide() == SHEET_SIDE::TOP || pin->GetSide() == SHEET_SIDE::LEFT )
1736 newPos = pin->GetPosition() + tl_delta;
1737 else
1738 newPos = pin->GetPosition() + br_delta;
1739
1740 VECTOR2I delta = grid.AlignGrid( newPos - pin->GetPosition(), selectionGrid );
1741
1742 if( delta != VECTOR2I( 0, 0 ) )
1743 {
1744 EDA_ITEMS drag_items;
1745 getConnectedDragItems( &commit, pin, pin->GetConnectionPoints()[0],
1746 drag_items );
1747
1748 doMoveItem( pin, delta );
1749
1750 for( EDA_ITEM* dragItem : drag_items )
1751 {
1752 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
1753 continue;
1754
1755 doMoveItem( dragItem, delta );
1756 }
1757 }
1758 }
1759 }
1760 else
1761 {
1762 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1763 std::vector<VECTOR2I> connections = schItem->GetConnectionPoints();
1764 EDA_ITEMS drag_items;
1765
1766 for( const VECTOR2I& point : connections )
1767 getConnectedDragItems( &commit, schItem, point, drag_items );
1768
1769 std::map<VECTOR2I, int> shifts;
1770 VECTOR2I most_common( 0, 0 );
1771 int max_count = 0;
1772
1773 for( const VECTOR2I& conn : connections )
1774 {
1775 VECTOR2I gridpt = grid.AlignGrid( conn, selectionGrid ) - conn;
1776
1777 shifts[gridpt]++;
1778
1779 if( shifts[gridpt] > max_count )
1780 {
1781 most_common = gridpt;
1782 max_count = shifts[most_common];
1783 }
1784 }
1785
1786 if( most_common != VECTOR2I( 0, 0 ) )
1787 {
1788 doMoveItem( item, most_common );
1789
1790 for( EDA_ITEM* dragItem : drag_items )
1791 {
1792 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
1793 continue;
1794
1795 doMoveItem( dragItem, most_common );
1796 }
1797 }
1798 }
1799 }
1800
1802 lwbTool->TrimOverLappingWires( &commit, &selection );
1803 lwbTool->AddJunctionsIfNeeded( &commit, &selection );
1804
1806
1807 m_frame->SchematicCleanUp( &commit );
1808 commit.Push( _( "Align Items to Grid" ) );
1809 return 0;
1810}
1811
1812
1814{
1815 // Remove new bend lines added during the drag
1816 for( SCH_LINE* newLine : m_newDragLines )
1817 {
1818 m_frame->RemoveFromScreen( newLine, m_frame->GetScreen() );
1819 delete newLine;
1820 }
1821
1822 m_newDragLines.clear();
1823}
1824
1825
1827{
1828 Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::move.MakeEvent() );
1829 Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::drag.MakeEvent() );
1831}
1832
1833
static TOOL_ACTION duplicate
Definition: actions.h:76
static TOOL_ACTION doDelete
Definition: actions.h:77
static TOOL_ACTION cursorClick
Definition: actions.h:159
static TOOL_ACTION refreshPreview
Definition: actions.h:139
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Create an undo entry for an item that has been already modified.
Definition: commit.h:105
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition: commit.h:86
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
Definition: commit.h:98
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:615
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:95
bool IsParallelTo(EDA_ANGLE aAngle) const
Definition: eda_angle.h:148
void ShowInfoBarMsg(const wxString &aMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an info icon on the left of...
WX_INFOBAR * GetInfoBar()
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:89
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:74
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:127
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: eda_item.h:129
bool IsSelected() const
Definition: eda_item.h:110
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition: eda_item.h:131
bool IsNew() const
Definition: eda_item.h:107
const VECTOR2I & GetTextPos() const
Definition: eda_text.h:230
static TOOL_ACTION alignToGrid
Definition: ee_actions.h:120
static TOOL_ACTION highlightNet
Definition: ee_actions.h:291
static TOOL_ACTION move
Definition: ee_actions.h:121
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION drag
Definition: ee_actions.h:122
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:125
static TOOL_ACTION restartMove
Definition: ee_actions.h:245
static TOOL_ACTION rotateCW
Definition: ee_actions.h:124
static TOOL_ACTION selectOnPCB
Definition: ee_actions.h:246
static const std::vector< KICAD_T > MovableItems
Definition: ee_collectors.h:43
Implements an R-tree for fast spatial and type indexing of schematic items.
Definition: sch_rtree.h:40
EE_TYPE Overlapping(const BOX2I &aRect) const
Definition: sch_rtree.h:243
EE_SELECTION & RequestSelection(const std::vector< KICAD_T > &aScanTypes={ SCH_LOCATE_ANY_T }, bool aPromoteCellSelections=false)
Return either an existing selection (filtered), or the selection at the current cursor position if th...
void RebuildSelection()
Rebuild the selection from the EDA_ITEMs' selection flags.
EE_SELECTION & GetSelection()
A foundation class for a tool operating on a schematic or symbol.
Definition: ee_tool_base.h:48
void updateItem(EDA_ITEM *aItem, bool aUpdateRTree) const
Similar to getView()->Update(), but handles items that are redrawn by their parents and updating the ...
Definition: ee_tool_base.h:109
EE_SELECTION_TOOL * m_selectionTool
Definition: ee_tool_base.h:200
bool Init() override
Init() is called once upon a registration of the tool.
Definition: ee_tool_base.h:64
static const TOOL_EVENT SelectedItemsMoved
Used to inform tools that the selection should temporarily be non-editable.
Definition: actions.h:280
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.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1687
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:142
void AddToScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen=nullptr)
Add an item to the screen (and view) aScreen is the screen the item is located on,...
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
void RemoveFromScreen(EDA_ITEM *aItem, SCH_SCREEN *aScreen)
Remove an item from the screen (and view) aScreen is the screen the item is located on,...
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:406
virtual void Revert() override
Definition: sch_commit.cpp:484
Schematic editor (Eeschema) main window.
SCH_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
void SchematicCleanUp(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen=nullptr)
Perform routine schematic cleaning including breaking wire and buses and deleting identical objects s...
void FlipBodyStyle(SCH_SYMBOL *aSymbol)
Definition: picksymbol.cpp:126
void SelectUnit(SCH_SYMBOL *aSymbol, int aUnit)
Definition: picksymbol.cpp:93
void AutoRotateItem(SCH_SCREEN *aScreen, SCH_ITEM *aItem)
Automatically set the rotation of an item (if the item supports it)
SCH_JUNCTION * AddJunction(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen, const VECTOR2I &aPos)
void SaveCopyForRepeatItem(const SCH_ITEM *aItem)
Clone aItem and owns that clone in this container.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:166
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:444
int GetBodyStyle() const
Definition: sch_item.h:232
void ClearFieldsAutoplaced()
Definition: sch_item.h:551
void SetLayer(SCH_LAYER_ID aLayer)
Definition: sch_item.h:282
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:512
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:212
virtual bool IsMovableFromAnchorPoint() const
Definition: sch_item.h:246
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:464
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_junction.h:57
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
Definition: sch_label.cpp:429
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_label.cpp:422
bool CanConnect(const SCH_ITEM *aItem) const override
Definition: sch_label.h:149
Tool responsible for drawing/placing items (symbols, wires, buses, labels, etc.)
int AddJunctionsIfNeeded(SCH_COMMIT *aCommit, EE_SELECTION *aSelection)
Handle the addition of junctions to a selection of objects.
int TrimOverLappingWires(SCH_COMMIT *aCommit, EE_SELECTION *aSelection)
Logic to remove wires when overlapping correct items.
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
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:809
void StoreAngle()
Saves the current line angle.
Definition: sch_line.h:112
std::vector< VECTOR2I > GetConnectionPoints() const override
Add all the connection points for this item to aPoints.
Definition: sch_line.cpp:709
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:226
EDA_ANGLE Angle() const
Gets the angle between the start and end lines.
Definition: sch_line.h:103
VECTOR2I GetEndPoint() const
Definition: sch_line.h:141
VECTOR2I GetStartPoint() const
Definition: sch_line.h:136
void MoveEnd(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:168
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_line.h:152
void MoveStart(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:162
double GetLength() const
Definition: sch_line.cpp:242
void SetEndPoint(const VECTOR2I &aPosition)
Definition: sch_line.h:142
bool Init() override
Init() is called once upon a registration of the tool.
VECTOR2I m_cursor
void trimDanglingLines(SCH_COMMIT *aCommit)
bool m_isDrag
Items (such as wires) which were added to the selection for a drag.
Definition: sch_move_tool.h:95
void orthoLineDrag(SCH_COMMIT *aCommit, SCH_LINE *line, const VECTOR2I &splitDelta, int &xBendCount, int &yBendCount, const EE_GRID_HELPER &grid)
Clears the new drag lines and removes them from the screen.
std::unordered_set< SCH_LINE * > m_newDragLines
Lines changed by drag algorithm that weren't selected.
bool doMoveSelection(const TOOL_EVENT &aEvent, SCH_COMMIT *aCommit, bool aIsSlice)
OPT_VECTOR2I m_anchorPos
int Main(const TOOL_EVENT &aEvent)
Run an interactive move of the selected items, or the item under the cursor.
bool m_inMoveTool
< Re-entrancy guard
Definition: sch_move_tool.h:91
std::vector< KIID > m_dragAdditions
Cache of the line's original connections before dragging started.
Definition: sch_move_tool.h:98
void moveItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
Find additional items for a drag operation.
std::unordered_set< SCH_LINE * > m_changedDragLines
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.
bool m_moveInProgress
Definition: sch_move_tool.h:94
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.
std::map< SCH_SHEET_PIN *, std::pair< SCH_LINE *, bool > > m_specialCaseSheetPins
void TestDanglingEnds(const SCH_SHEET_PATH *aPath=nullptr, std::function< void(SCH_ITEM *)> *aChangedHandler=nullptr) const
Test all of the connectable objects in the schematic for unused connection points.
EE_RTREE & Items()
Gets the full RTree, usually for iterating.
Definition: sch_screen.h:108
bool IsExplicitJunctionNeeded(const VECTOR2I &aPosition) const
Indicates that a junction dot is necessary at the given location, and does not yet exist.
Definition: sch_screen.cpp:495
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Definition: sch_sheet_pin.h:66
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
void SetSize(const VECTOR2I &aSize)
Definition: sch_sheet.h:113
VECTOR2I GetSize() const
Definition: sch_sheet.h:112
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:400
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:181
Schematic symbol object.
Definition: sch_symbol.h:106
TRANSFORM & GetTransform()
Definition: sch_symbol.h:290
VECTOR2I GetPosition() const override
Definition: sch_text.h:141
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:327
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
int AddItemToSel(const TOOL_EVENT &aEvent)
int RemoveItemsFromSel(const TOOL_EVENT &aEvent)
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:42
VECTOR2I GetReferencePoint() const
Definition: selection.cpp:171
bool IsHover() const
Definition: selection.h:84
EDA_ITEM * Front() const
Definition: selection.h:172
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:180
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
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.
Definition: selection.cpp:223
bool HasReferencePoint() const
Definition: selection.h:211
T * GetAppSettings()
Returns a handle to the a given settings by type If the settings have already been loaded,...
virtual void PopTool(const TOOL_EVENT &aEvent)
Pops a tool from the stack.
bool GetMoveWarpsCursor() const
Indicate that a move operation should warp the mouse pointer to the origin of the move object.
Definition: tools_holder.h:150
virtual void PushTool(const TOOL_EVENT &aEvent)
NB: the definition of "tool" is different at the user level.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:218
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
Generic, UI-independent tool event.
Definition: tool_event.h:167
bool DisableGridSnapping() const
Definition: tool_event.h:363
bool IsCancelInteractive() const
Indicate the event should restart/end an ongoing interactive tool's event loop (eg esc key,...
Definition: tool_event.cpp:221
TOOL_ACTIONS Action() const
These give a tool a method of informing the TOOL_MANAGER that a particular event should be passed on ...
Definition: tool_event.h:246
bool IsActivate() const
Definition: tool_event.h:337
COMMIT * Commit() const
Returns information about difference between current mouse cursor position and the place where draggi...
Definition: tool_event.h:275
bool IsClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:209
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:307
int Modifier(int aMask=MD_MODIFIER_MASK) const
Definition: tool_event.h:358
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:82
T Parameter() const
Return a parameter assigned to the event.
Definition: tool_event.h:460
bool IsDblClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:215
std::atomic< SYNCRONOUS_TOOL_STATE > * SynchronousState() const
Definition: tool_event.h:272
std::optional< int > GetCommandId() const
Definition: tool_event.h:520
void SetPassEvent(bool aPass=true)
Returns if it this event has a valid position (true for mouse events and context-menu or hotkey-based...
Definition: tool_event.h:252
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:317
bool IsMotion() const
Definition: tool_event.h:322
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
TOOL_MENU & GetToolMenu()
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void Activate()
Run the tool.
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
bool RunSynchronousAction(const TOOL_ACTION &aAction, COMMIT *aCommit, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:197
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:391
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:44
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:57
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
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: wx_infobar.cpp:190
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition: eda_angle.h:403
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:536
#define IS_PASTED
Modifier on IS_NEW which indicates it came from clipboard.
#define IS_CHANGED
Item was edited, and modified.
#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.
@ ID_POPUP_SCH_SELECT_UNIT
Definition: eeschema_id.h:82
@ ID_POPUP_SCH_SELECT_BASE
Definition: eeschema_id.h:88
@ ID_POPUP_SCH_SELECT_ALT
Definition: eeschema_id.h:89
@ ID_POPUP_SCH_SELECT_UNIT_END
Definition: eeschema_id.h:86
GRID_HELPER_GRIDS
Definition: grid_helper.h:37
@ GRID_CURRENT
Definition: grid_helper.h:39
@ LAYER_WIRE
Definition: layer_ids.h:357
@ LAYER_BUS
Definition: layer_ids.h:358
@ LAYER_BUS_JUNCTION
Definition: layer_ids.h:400
@ REPAINT
Item needs to be redrawn.
Definition: view_item.h:57
bool signbit(T v)
Integral version of std::signbit that works all compilers.
Definition: kicad_algo.h:198
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
#define QUIET_MODE
The EE_TYPE struct provides a type-specific auto-range iterator to the RTree.
Definition: sch_rtree.h:192
constexpr int delta
@ TA_CHOICE_MENU_CHOICE
Definition: tool_event.h:97
@ TA_UNDO_REDO_PRE
Definition: tool_event.h:105
@ MD_SHIFT
Definition: tool_event.h:142
@ STS_CANCELLED
Definition: tool_event.h:160
@ STS_FINISHED
Definition: tool_event.h:159
@ STS_RUNNING
Definition: tool_event.h:158
@ BUT_LEFT
Definition: tool_event.h:131
@ BUT_RIGHT
Definition: tool_event.h:132
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:78
@ SCH_LINE_T
Definition: typeinfo.h:163
@ SCH_NO_CONNECT_T
Definition: typeinfo.h:160
@ SCH_SYMBOL_T
Definition: typeinfo.h:172
@ SCH_FIELD_T
Definition: typeinfo.h:150
@ SCH_DIRECTIVE_LABEL_T
Definition: typeinfo.h:171
@ SCH_LABEL_T
Definition: typeinfo.h:167
@ SCH_SHEET_T
Definition: typeinfo.h:174
@ SCH_MARKER_T
Definition: typeinfo.h:158
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:169
@ SCH_BUS_BUS_ENTRY_T
Definition: typeinfo.h:162
@ SCH_SHEET_PIN_T
Definition: typeinfo.h:173
@ SCH_TEXT_T
Definition: typeinfo.h:151
@ SCH_BUS_WIRE_ENTRY_T
Definition: typeinfo.h:161
@ SCH_GLOBAL_LABEL_T
Definition: typeinfo.h:168
@ SCH_JUNCTION_T
Definition: typeinfo.h:159
@ SCH_PIN_T
Definition: typeinfo.h:153
int sign(T val)
Definition: util.h:159
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:676