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 <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{
408 EESCHEMA_SETTINGS* cfg = mgr.GetAppSettings<EESCHEMA_SETTINGS>( "eeschema" );
411 bool wasDragging = m_moveInProgress && m_isDrag;
412
413 m_anchorPos.reset();
414
415 if( m_moveInProgress )
416 {
417 if( m_isDrag != wasDragging )
418 {
420
421 if( sel && !sel->IsNew() )
422 {
423 // Reset the selected items so we can start again with the current m_isDrag
424 // state.
425 aCommit->Revert();
426
429 m_moveInProgress = false;
430 controls->SetAutoPan( false );
431
432 // And give it a kick so it doesn't have to wait for the first mouse movement
433 // to refresh.
435 }
436 }
437 else
438 {
439 // The tool hotkey is interpreted as a click when already dragging/moving
441 }
442
443 return false;
444 }
445
446 if( m_inMoveTool ) // Must come after m_moveInProgress checks above...
447 return false;
448
450
451 EE_SELECTION& userSelection = m_selectionTool->GetSelection();
452
453 // If a single pin is selected, promote the move selection to its parent symbol
454 if( userSelection.GetSize() == 1 )
455 {
456 EDA_ITEM* selItem = userSelection.Front();
457
458 if( selItem->Type() == SCH_PIN_T )
459 {
460 EDA_ITEM* parent = selItem->GetParent();
461
462 if( parent->Type() == SCH_SYMBOL_T )
463 {
465 m_selectionTool->AddItemToSel( parent );
466 }
467 }
468 }
469
470 // Be sure that there is at least one item that we can move. If there's no selection try
471 // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
473 true );
474 bool unselect = selection.IsHover();
475
476 // Keep an original copy of the starting points for cleanup after the move
477 std::vector<DANGLING_END_ITEM> internalPoints;
478
479 Activate();
480
481 // Must be done after Activate() so that it gets set into the correct context
482 controls->ShowCursor( true );
483
484 m_frame->PushTool( aEvent );
485
486 if( selection.Empty() )
487 {
488 // Note that it's important to go through push/pop even when the selection is empty.
489 // This keeps other tools from having to special-case an empty move.
490 m_frame->PopTool( aEvent );
491 return false;
492 }
493
494 bool restore_state = false;
495 TOOL_EVENT copy = aEvent;
496 TOOL_EVENT* evt = &copy;
497 VECTOR2I prevPos;
499
500 m_cursor = controls->GetCursorPosition();
501
502 // Main loop: keep receiving events
503 do
504 {
505 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
506 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
507 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
508
510 || evt->IsAction( &EE_ACTIONS::move )
511 || evt->IsAction( &EE_ACTIONS::drag )
512 || evt->IsMotion()
513 || evt->IsDrag( BUT_LEFT )
515 {
516 if( !m_moveInProgress ) // Prepare to start moving/dragging
517 {
518 SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
519 bool placingNewItems = sch_item && sch_item->IsNew();
520
521 //------------------------------------------------------------------------
522 // Setup a drag or a move
523 //
524 m_dragAdditions.clear();
525 m_specialCaseLabels.clear();
527 internalPoints.clear();
529
530 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
531 {
532 it->ClearFlags( SELECTED_BY_DRAG );
533
534 if( !it->IsSelected() )
535 it->ClearFlags( STARTPOINT | ENDPOINT );
536 }
537
538 // Drag of split items start over top of their other segment so
539 // we want to skip grabbing the segments we split from
540 if( m_isDrag && !aIsSlice )
541 {
542 EDA_ITEMS connectedDragItems;
543
544 // Add connections to the selection for a drag.
545 // Do all non-labels/entries first so we don't add junctions to drag
546 // when the line will eventually be drag selected.
547 std::vector<SCH_ITEM*> stageTwo;
548
549 for( EDA_ITEM* edaItem : selection )
550 {
551 SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
552 std::vector<VECTOR2I> connections;
553
554 switch( item->Type() )
555 {
556 case SCH_LABEL_T:
557 case SCH_HIER_LABEL_T:
560 stageTwo.emplace_back(item);
561 break;
562
563 case SCH_LINE_T:
564 static_cast<SCH_LINE*>( item )->GetSelectedPoints( connections );
565 break;
566 default:
567 connections = item->GetConnectionPoints();
568 }
569
570 for( const VECTOR2I& point : connections )
571 getConnectedDragItems( aCommit, item, point, connectedDragItems );
572 }
573
574 // Go back and get all label connections now that we can test for drag-selected
575 // lines the labels might be on
576 for( SCH_ITEM* item : stageTwo )
577 {
578 for( const VECTOR2I& point : item->GetConnectionPoints() )
579 getConnectedDragItems( aCommit, item, point, connectedDragItems );
580 }
581
582 for( EDA_ITEM* item : connectedDragItems )
583 {
584 m_dragAdditions.push_back( item->m_Uuid );
586 }
587
588 // Pre-cache all connections of our selected objects so we can keep track of
589 // what they were originally connected to as we drag them around
590 for( EDA_ITEM* edaItem : selection )
591 {
592 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( edaItem );
593
594 if( schItem->Type() == SCH_LINE_T )
595 {
596 SCH_LINE* line = static_cast<SCH_LINE*>( schItem );
597
598 //Also store the original angle of the line, is needed later to decide
599 //which segment to extend when they've become zero length
600 line->StoreAngle();
601
602 for( const VECTOR2I& point : line->GetConnectionPoints() )
603 getConnectedItems( line, point, m_lineConnectionCache[line] );
604 }
605 }
606 }
607 else
608 {
609 // Mark the edges of the block with dangling flags for a move.
610 for( EDA_ITEM* item : selection )
611 static_cast<SCH_ITEM*>( item )->GetEndPoints( internalPoints );
612
613 std::vector<DANGLING_END_ITEM> endPointsByType = internalPoints;
614 std::vector<DANGLING_END_ITEM> endPointsByPos = endPointsByType;
616 endPointsByPos );
617
618 for( EDA_ITEM* item : selection )
619 static_cast<SCH_ITEM*>( item )->UpdateDanglingState( endPointsByType,
620 endPointsByPos );
621 }
622
623
624 // Generic setup
625 snapLayer = grid.GetSelectionGrid( selection );
626
627 for( EDA_ITEM* item : selection )
628 {
629 if( item->IsNew() )
630 {
631 // Item was added to commit in a previous command
632 }
633 else if( item->GetParent() && item->GetParent()->IsSelected() )
634 {
635 // Item will be (or has been) added to commit by parent
636 }
637 else
638 {
639 aCommit->Modify( item, m_frame->GetScreen() );
640 }
641
642 item->SetFlags( IS_MOVING );
643
644 if( SCH_ITEM* schItem = dynamic_cast<SCH_ITEM*>( item ) )
645 schItem->SetStoredPos( schItem->GetPosition() );
646 }
647
648 // Set up the starting position and move/drag offset
649 //
650 m_cursor = controls->GetCursorPosition();
651
652 if( evt->IsAction( &EE_ACTIONS::restartMove ) )
653 {
654 wxASSERT_MSG( m_anchorPos, "Should be already set from previous cmd" );
655 }
656 else if( placingNewItems )
657 {
658 m_anchorPos = selection.GetReferencePoint();
659 }
660
661 if( m_anchorPos )
662 {
663 VECTOR2I delta = m_cursor - (*m_anchorPos);
664 bool isPasted = false;
665
666 // Drag items to the current cursor position
667 for( EDA_ITEM* item : selection )
668 {
669 // Don't double move pins, fields, etc.
670 if( item->GetParent() && item->GetParent()->IsSelected() )
671 continue;
672
673 moveItem( item, delta );
674 updateItem( item, false );
675
676 isPasted |= ( item->GetFlags() & IS_PASTED ) != 0;
677 item->ClearFlags( IS_PASTED );
678 }
679
680 // The first time pasted items are moved we need to store the position of the
681 // cursor so that rotate while moving works as expected (instead of around the
682 // original anchor point
683 if( isPasted )
684 selection.SetReferencePoint( m_cursor );
685
687 }
688 // For some items, moving the cursor to anchor is not good (for instance large
689 // hierarchical sheets or symbols can have the anchor outside the view)
690 else if( selection.Size() == 1 && !sch_item->IsMovableFromAnchorPoint() )
691 {
694 }
695 else
696 {
698 {
699 // User wants to warp the mouse
700 m_cursor = grid.BestDragOrigin( m_cursor, snapLayer, selection );
701 selection.SetReferencePoint( m_cursor );
702 }
703 else
704 {
705 // User does not want to warp the mouse
707 }
708 }
709
710 controls->SetCursorPosition( m_cursor, false );
711
712 prevPos = m_cursor;
713 controls->SetAutoPan( true );
714 m_moveInProgress = true;
715 }
716
717 //------------------------------------------------------------------------
718 // Follow the mouse
719 //
720 m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ),
721 snapLayer, selection );
722
723 VECTOR2I delta( m_cursor - prevPos );
725
726 // We need to check if the movement will change the net offset direction on the
727 // X an Y axes. This is because we remerge added bend lines in realtime, and we
728 // also account for the direction of the move when adding bend lines. So, if the
729 // move direction changes, we need to split it into a move that gets us back to
730 // zero, then the rest of the move.
731 std::vector<VECTOR2I> splitMoves;
732
734 {
735 splitMoves.emplace_back( VECTOR2I( -1 * m_moveOffset.x, 0 ) );
736 splitMoves.emplace_back( VECTOR2I( delta.x + m_moveOffset.x, 0 ) );
737 }
738 else
739 {
740 splitMoves.emplace_back( VECTOR2I( delta.x, 0 ) );
741 }
742
744 {
745 splitMoves.emplace_back( VECTOR2I( 0, -1 * m_moveOffset.y ) );
746 splitMoves.emplace_back( VECTOR2I( 0, delta.y + m_moveOffset.y ) );
747 }
748 else
749 {
750 splitMoves.emplace_back( VECTOR2I( 0, delta.y ) );
751 }
752
753
755 prevPos = m_cursor;
756
757 // Used for tracking how far off a drag end should have its 90 degree elbow added
758 int xBendCount = 1;
759 int yBendCount = 1;
760
761 // Split the move into X and Y moves so we can correctly drag orthogonal lines
762 for( const VECTOR2I& splitDelta : splitMoves )
763 {
764 // Skip non-moves
765 if( splitDelta == VECTOR2I( 0, 0 ) )
766 continue;
767
768 for( EDA_ITEM* item : selection.GetItemsSortedByTypeAndXY( ( delta.x >= 0 ),
769 ( delta.y >= 0 ) ) )
770 {
771 // Don't double move pins, fields, etc.
772 if( item->GetParent() && item->GetParent()->IsSelected() )
773 continue;
774
775 SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
776
777 // Only partially selected drag lines in orthogonal line mode need special
778 // handling
779 if( m_isDrag
780 && cfg->m_Drawing.line_mode != LINE_MODE::LINE_MODE_FREE
781 && line
782 && line->HasFlag( STARTPOINT ) != line->HasFlag( ENDPOINT ) )
783 {
784 orthoLineDrag( aCommit, line, splitDelta, xBendCount, yBendCount, grid );
785 }
786
787 // Move all other items normally, including the selected end of partially
788 // selected lines
789 moveItem( item, splitDelta );
790 updateItem( item, false );
791
792 // Update any lines connected to sheet pins to the sheet pin's location
793 // (which may not exactly follow the splitDelta as the pins are constrained
794 // along the sheet edges.
795 for( const auto& [pin, lineEnd] : m_specialCaseSheetPins )
796 {
797 if( lineEnd.second && lineEnd.first->HasFlag( STARTPOINT ) )
798 lineEnd.first->SetStartPoint( pin->GetPosition() );
799 else if( !lineEnd.second && lineEnd.first->HasFlag( ENDPOINT ) )
800 lineEnd.first->SetEndPoint( pin->GetPosition() );
801 }
802 }
803 }
804
805 if( selection.HasReferencePoint() )
806 selection.SetReferencePoint( selection.GetReferencePoint() + delta );
807
809 }
810
811 //------------------------------------------------------------------------
812 // Handle cancel
813 //
814 else if( evt->IsCancelInteractive() || evt->IsActivate() )
815 {
816 if( evt->IsCancelInteractive() )
818
819 if( m_moveInProgress )
820 {
821 if( evt->IsActivate() )
822 {
823 // Allowing other tools to activate during a move runs the risk of race
824 // conditions in which we try to spool up both event loops at once.
825
826 if( m_isDrag )
827 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel drag." ) );
828 else
829 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel move." ) );
830
831 evt->SetPassEvent( false );
832 continue;
833 }
834
835 evt->SetPassEvent( false );
836 restore_state = true;
837 }
838
840
841 break;
842 }
843 //------------------------------------------------------------------------
844 // Handle TOOL_ACTION special cases
845 //
846 else if( evt->Action() == TA_UNDO_REDO_PRE )
847 {
848 unselect = true;
849 break;
850 }
851 else if( evt->IsAction( &ACTIONS::doDelete ) )
852 {
853 evt->SetPassEvent();
854 // Exit on a delete; there will no longer be anything to drag.
855 break;
856 }
857 else if( evt->IsAction( &ACTIONS::duplicate ) )
858 {
859 wxBell();
860 }
861 else if( evt->IsAction( &EE_ACTIONS::rotateCW ) )
862 {
864 }
865 else if( evt->IsAction( &EE_ACTIONS::rotateCCW ) )
866 {
868 }
869 else if( evt->IsAction( &ACTIONS::increment ) )
870 {
873 }
874 else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
875 {
878 {
879 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
880 int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
881
882 if( symbol )
883 {
884 m_frame->SelectUnit( symbol, unit );
886 }
887 }
888 else if( *evt->GetCommandId() >= ID_POPUP_SCH_SELECT_BASE
890 {
891 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
892 int bodyStyle = ( *evt->GetCommandId() - ID_POPUP_SCH_SELECT_BASE ) + 1;
893
894 if( symbol && symbol->GetBodyStyle() != bodyStyle )
895 {
896 m_frame->FlipBodyStyle( symbol );
898 }
899 }
900 }
901 else if( evt->IsAction( &EE_ACTIONS::highlightNet )
903 {
904 // These don't make any sense during a move. Eat them.
905 }
906 //------------------------------------------------------------------------
907 // Handle context menu
908 //
909 else if( evt->IsClick( BUT_RIGHT ) )
910 {
911 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
912 }
913 //------------------------------------------------------------------------
914 // Handle drop
915 //
916 else if( evt->IsMouseUp( BUT_LEFT )
917 || evt->IsClick( BUT_LEFT )
918 || evt->IsDblClick( BUT_LEFT ) )
919 {
920 break; // Finish
921 }
922 else
923 {
924 evt->SetPassEvent();
925 }
926
927 controls->SetAutoPan( m_moveInProgress );
928
929 } while( ( evt = Wait() ) ); //Should be assignment not equality test
930
931 // Create a selection of original selection, drag selected/changed items, and new
932 // bend lines for later before we clear them in the aCommit. We'll need these
933 // to check for new junctions needed, etc.
934 EE_SELECTION selectionCopy( selection );
935
936 for( SCH_LINE* line : m_newDragLines )
937 selectionCopy.Add( line );
938
939 for( SCH_LINE* line : m_changedDragLines )
940 selectionCopy.Add( line );
941
942 // Save whatever new bend lines and changed lines survived the drag
943 for( SCH_LINE* newLine : m_newDragLines )
944 {
945 newLine->ClearEditFlags();
946 aCommit->Added( newLine, m_frame->GetScreen() );
947 }
948
949 // These lines have been changed, but aren't selected. We need
950 // to manually clear these edit flags or they'll stick around.
951 for( SCH_LINE* oldLine : m_changedDragLines )
952 oldLine->ClearEditFlags();
953
954 m_newDragLines.clear();
955 m_changedDragLines.clear();
956
957 controls->ForceCursorPosition( false );
958 controls->ShowCursor( false );
959 controls->SetAutoPan( false );
960
961 m_moveOffset = { 0, 0 };
962 m_anchorPos.reset();
963
964 if( restore_state )
965 {
967 }
968 else
969 {
970 // One last update after exiting loop (for slower stuff, such as updating SCREEN's RTree).
971 for( EDA_ITEM* item : selection )
972 {
973 updateItem( item, true );
974
975 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
976 sch_item->SetConnectivityDirty( true );
977 }
978
979 if( selection.GetSize() == 1 && selection.Front()->IsNew() )
980 m_frame->SaveCopyForRepeatItem( static_cast<SCH_ITEM*>( selection.Front() ) );
981
983
984 // If we move items away from a junction, we _may_ want to add a junction there
985 // to denote the state.
986 for( const DANGLING_END_ITEM& it : internalPoints )
987 {
988 if( m_frame->GetScreen()->IsExplicitJunctionNeeded( it.GetPosition()) )
989 m_frame->AddJunction( aCommit, m_frame->GetScreen(), it.GetPosition() );
990 }
991
993 lwbTool->TrimOverLappingWires( aCommit, &selectionCopy );
994 lwbTool->AddJunctionsIfNeeded( aCommit, &selectionCopy );
995
996 // This needs to run prior to `RecalculateConnections` because we need to identify
997 // the lines that are newly dangling
998 if( m_isDrag && !aIsSlice )
999 trimDanglingLines( aCommit );
1000
1001 // Auto-rotate any moved labels
1002 for( EDA_ITEM* item : selection )
1003 m_frame->AutoRotateItem( m_frame->GetScreen(), static_cast<SCH_ITEM*>( item ) );
1004
1005 m_frame->SchematicCleanUp( aCommit );
1006 }
1007
1008 for( EDA_ITEM* item : m_frame->GetScreen()->Items() )
1009 item->ClearEditFlags();
1010
1011 // ensure any selected item not in screen main list (for instance symbol fields)
1012 // has its edit flags cleared
1013 for( EDA_ITEM* item : selectionCopy )
1014 item->ClearEditFlags();
1015
1016 if( unselect )
1018 else
1019 m_selectionTool->RebuildSelection(); // Schematic cleanup might have merged lines, etc.
1020
1021 m_dragAdditions.clear();
1022 m_lineConnectionCache.clear();
1023 m_moveInProgress = false;
1024 m_frame->PopTool( aEvent );
1025
1026 return !restore_state;
1027}
1028
1029
1031{
1032 // Need a local cleanup first to ensure we remove unneeded junctions
1033 m_frame->SchematicCleanUp( aCommit, m_frame->GetScreen() );
1034
1035 std::set<SCH_ITEM*> danglers;
1036
1037 std::function<void( SCH_ITEM* )> changeHandler =
1038 [&]( SCH_ITEM* aChangedItem ) -> void
1039 {
1040 m_toolMgr->GetView()->Update( aChangedItem, KIGFX::REPAINT );
1041
1042 // Delete newly dangling lines:
1043 // Find split segments (one segment is new, the other is changed) that
1044 // we aren't dragging and don't have selected
1045 if( aChangedItem->HasFlag( IS_BROKEN) && aChangedItem->IsDangling()
1046 && !aChangedItem->IsSelected() )
1047 {
1048 danglers.insert( aChangedItem );
1049 }
1050 };
1051
1052 m_frame->GetScreen()->TestDanglingEnds( nullptr, &changeHandler );
1053
1054 for( SCH_ITEM* line : danglers )
1055 {
1056 line->SetFlags( STRUCT_DELETED );
1057 aCommit->Removed( line, m_frame->GetScreen() );
1058
1059 updateItem( line, false );
1061 }
1062}
1063
1064
1065void SCH_MOVE_TOOL::getConnectedItems( SCH_ITEM* aOriginalItem, const VECTOR2I& aPoint,
1066 EDA_ITEMS& aList )
1067{
1068 EE_RTREE& items = m_frame->GetScreen()->Items();
1069 EE_RTREE::EE_TYPE itemsOverlapping = items.Overlapping( aOriginalItem->GetBoundingBox() );
1070 SCH_ITEM* foundJunction = nullptr;
1071 SCH_ITEM* foundSymbol = nullptr;
1072
1073 // If you're connected to a junction, you're only connected to the junction.
1074 //
1075 // But, if you're connected to a junction on a pin, you're only connected to the pin. This
1076 // is because junctions and pins have different logic for how bend lines are generated and
1077 // we need to prioritize the pin version in some cases.
1078 for( SCH_ITEM* item : itemsOverlapping )
1079 {
1080 if( item != aOriginalItem && item->IsConnected( aPoint ) )
1081 {
1082 if( item->Type() == SCH_JUNCTION_T )
1083 foundJunction = item;
1084 else if( item->Type() == SCH_SYMBOL_T )
1085 foundSymbol = item;
1086 }
1087 }
1088
1089 if( foundSymbol && foundJunction )
1090 {
1091 aList.push_back( foundSymbol );
1092 return;
1093 }
1094
1095 if( foundJunction )
1096 {
1097 aList.push_back( foundJunction );
1098 return;
1099 }
1100
1101
1102 for( SCH_ITEM* test : itemsOverlapping )
1103 {
1104 if( test == aOriginalItem || !test->CanConnect( aOriginalItem ) )
1105 continue;
1106
1107 switch( test->Type() )
1108 {
1109 case SCH_LINE_T:
1110 {
1111 SCH_LINE* line = static_cast<SCH_LINE*>( test );
1112
1113 // When getting lines for the connection cache, it's important that we only add
1114 // items at the unselected end, since that is the only end that is handled specially.
1115 // Fully selected lines, and the selected end of a partially selected line, are moved
1116 // around normally and don't care about their connections.
1117 if( ( line->HasFlag( STARTPOINT ) && aPoint == line->GetStartPoint() )
1118 || ( line->HasFlag( ENDPOINT ) && aPoint == line->GetEndPoint() ) )
1119 {
1120 continue;
1121 }
1122
1123 if( test->IsConnected( aPoint ) )
1124 aList.push_back( test );
1125
1126 // Labels can connect to a wire (or bus) anywhere along the length
1127 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aOriginalItem ) )
1128 {
1129 if( static_cast<SCH_LINE*>( test )->HitTest( label->GetPosition(), 1 ) )
1130 aList.push_back( test );
1131 }
1132
1133 break;
1134 }
1135
1136 case SCH_SHEET_T:
1137 if( aOriginalItem->Type() == SCH_LINE_T )
1138 {
1139 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1140
1141 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
1142 {
1143 if( pin->IsConnected( aPoint ) )
1144 {
1145 if( pin->IsSelected() )
1146 m_specialCaseSheetPins[pin] = { line,
1147 line->GetStartPoint() == aPoint };
1148
1149 aList.push_back( pin );
1150 }
1151 }
1152 }
1153
1154 break;
1155
1156 case SCH_SYMBOL_T:
1157 case SCH_JUNCTION_T:
1158 case SCH_NO_CONNECT_T:
1159 if( test->IsConnected( aPoint ) )
1160 aList.push_back( test );
1161
1162 break;
1163
1164 case SCH_LABEL_T:
1165 case SCH_GLOBAL_LABEL_T:
1166 case SCH_HIER_LABEL_T:
1168 // Labels can connect to a wire (or bus) anywhere along the length
1169 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
1170 {
1171 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
1172 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1173
1174 if( line->HitTest( label->GetPosition(), 1 ) )
1175 aList.push_back( label );
1176 }
1177
1178 break;
1179
1182 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
1183 {
1184 SCH_TEXT* label = static_cast<SCH_TEXT*>( test );
1185 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1186
1187 if( line->HitTest( aPoint, 1 ) )
1188 aList.push_back( label );
1189 }
1190
1191 break;
1192
1193 default:
1194 break;
1195 }
1196 }
1197}
1198
1199
1201 const VECTOR2I& aPoint, EDA_ITEMS& aList )
1202{
1203 EE_RTREE& items = m_frame->GetScreen()->Items();
1204 EE_RTREE::EE_TYPE itemsOverlappingRTree = items.Overlapping( aSelectedItem->GetBoundingBox() );
1205 std::vector<SCH_ITEM*> itemsConnectable;
1206 bool ptHasUnselectedJunction = false;
1207
1208 auto makeNewWire =
1209 [this]( SCH_COMMIT* commit, SCH_ITEM* fixed, SCH_ITEM* selected, const VECTOR2I& start,
1210 const VECTOR2I& end )
1211 {
1212 SCH_LINE* newWire;
1213
1214 // Add a new newWire between the fixed item and the selected item so the selected
1215 // item can be dragged.
1216 if( fixed->GetLayer() == LAYER_BUS_JUNCTION || fixed->GetLayer() == LAYER_BUS
1217 || selected->GetLayer() == LAYER_BUS )
1218 {
1219 newWire = new SCH_LINE( start, LAYER_BUS );
1220 }
1221 else
1222 {
1223 newWire = new SCH_LINE( start, LAYER_WIRE );
1224 }
1225
1226 newWire->SetFlags( IS_NEW );
1227 newWire->SetConnectivityDirty( true );
1228
1229 if( dynamic_cast<const SCH_LINE*>( selected ) )
1230 newWire->SetLastResolvedState( selected );
1231 else if( dynamic_cast<const SCH_LINE*>( fixed ) )
1232 newWire->SetLastResolvedState( fixed );
1233
1234 newWire->SetEndPoint( end );
1235 m_frame->AddToScreen( newWire, m_frame->GetScreen() );
1236 commit->Added( newWire, m_frame->GetScreen() );
1237
1238 return newWire;
1239 };
1240
1241 auto makeNewJunction =
1242 [this]( SCH_COMMIT* commit, SCH_LINE* line, const VECTOR2I& pt )
1243 {
1244 SCH_JUNCTION* junction = new SCH_JUNCTION( pt );
1245 junction->SetFlags( IS_NEW );
1246 junction->SetConnectivityDirty( true );
1247 junction->SetLastResolvedState( line );
1248
1249 if( line->IsBus() )
1250 junction->SetLayer( LAYER_BUS_JUNCTION );
1251
1252 m_frame->AddToScreen( junction, m_frame->GetScreen() );
1253 commit->Added( junction, m_frame->GetScreen() );
1254
1255 return junction;
1256 };
1257
1258 for( SCH_ITEM* item : itemsOverlappingRTree )
1259 {
1260 if( item->Type() == SCH_SHEET_T )
1261 {
1262 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1263
1264 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1265 {
1266 if( !pin->IsSelected() && pin->GetPosition() == aSelectedItem->GetPosition()
1267 && pin->CanConnect( aSelectedItem ) )
1268 {
1269 itemsConnectable.push_back( pin );
1270 }
1271 }
1272
1273 continue;
1274 }
1275
1276 // Skip ourselves, skip already selected items (but not lines, they need both ends tested)
1277 // and skip unconnectable items
1278 if( item == aSelectedItem || ( item->Type() != SCH_LINE_T && item->IsSelected() )
1279 || !item->CanConnect( aSelectedItem ) )
1280 {
1281 continue;
1282 }
1283
1284 itemsConnectable.push_back( item );
1285 }
1286
1287 for( SCH_ITEM* item : itemsConnectable )
1288 {
1289 if( item->Type() == SCH_JUNCTION_T && item->IsConnected( aPoint ) && !item->IsSelected() )
1290 {
1291 ptHasUnselectedJunction = true;
1292 break;
1293 }
1294 }
1295
1296 SCH_LINE* newWire = nullptr;
1297
1298 for( SCH_ITEM* test : itemsConnectable )
1299 {
1300 KICAD_T testType = test->Type();
1301
1302 switch( testType )
1303 {
1304 case SCH_LINE_T:
1305 {
1306 // Select the connected end of wires/bus connections that don't have an unselected
1307 // junction isolating them from the drag
1308 if( ptHasUnselectedJunction )
1309 break;
1310
1311 SCH_LINE* line = static_cast<SCH_LINE*>( test );
1312
1313 if( line->GetStartPoint() == aPoint )
1314 {
1315 // It's possible to manually select one end of a line and get a drag
1316 // connected other end, so we set the flag and then early exit the loop
1317 // later if the other drag items like labels attached to the line have
1318 // already been grabbed during the partial selection process.
1319 line->SetFlags( STARTPOINT );
1320
1321 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG ) )
1322 {
1323 continue;
1324 }
1325 else
1326 {
1327 line->SetFlags( SELECTED_BY_DRAG );
1328 aList.push_back( line );
1329 }
1330 }
1331 else if( line->GetEndPoint() == aPoint )
1332 {
1333 line->SetFlags( ENDPOINT );
1334
1335 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG ) )
1336 {
1337 continue;
1338 }
1339 else
1340 {
1341 line->SetFlags( SELECTED_BY_DRAG );
1342 aList.push_back( line );
1343 }
1344 }
1345 else
1346 {
1347 switch( aSelectedItem->Type() )
1348 {
1349 // These items can connect anywhere along a line
1352 case SCH_LABEL_T:
1353 case SCH_HIER_LABEL_T:
1354 case SCH_GLOBAL_LABEL_T:
1356 // Only add a line if this line is unselected; if the label and line are both
1357 // selected they'll move together
1358 if( line->HitTest( aPoint, 1 ) && !line->HasFlag( SELECTED )
1359 && !line->HasFlag( SELECTED_BY_DRAG ) )
1360 {
1361 newWire = makeNewWire( aCommit, line, aSelectedItem, aPoint, aPoint );
1362 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1363 newWire->StoreAngle( ( line->Angle() + ANGLE_90 ).Normalize() );
1364 aList.push_back( newWire );
1365
1366 if( aPoint != line->GetStartPoint() && aPoint != line->GetEndPoint() )
1367 {
1368 // Split line in half
1369 if( !line->IsNew() )
1370 aCommit->Modify( line, m_frame->GetScreen() );
1371
1372 VECTOR2I oldEnd = line->GetEndPoint();
1373 line->SetEndPoint( aPoint );
1374
1375 makeNewWire( aCommit, line, line, aPoint, oldEnd );
1376 makeNewJunction( aCommit, line, aPoint );
1377 }
1378 else
1379 {
1380 m_lineConnectionCache[ newWire ] = { line };
1381 m_lineConnectionCache[ line ] = { newWire };
1382 }
1383 }
1384 break;
1385
1386 default:
1387 break;
1388 }
1389
1390 break;
1391 }
1392
1393 // Since only one end is going to move, the movement vector of any labels attached to
1394 // it is scaled by the proportion of the line length the label is from the moving end.
1395 for( SCH_ITEM* item : items.Overlapping( line->GetBoundingBox() ) )
1396 {
1397 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item );
1398
1399 if( !label || label->IsSelected() )
1400 continue; // These will be moved on their own because they're selected
1401
1402 if( label->HasFlag( SELECTED_BY_DRAG ) )
1403 continue;
1404
1405 if( label->CanConnect( line ) && line->HitTest( label->GetPosition(), 1 ) )
1406 {
1407 label->SetFlags( SELECTED_BY_DRAG );
1408 aList.push_back( label );
1409
1411 info.attachedLine = line;
1412 info.originalLabelPos = label->GetPosition();
1413 m_specialCaseLabels[label] = info;
1414 }
1415 }
1416
1417 break;
1418 }
1419
1420 case SCH_SHEET_T:
1421 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
1422 {
1423 if( pin->IsConnected( aPoint ) )
1424 {
1425 if( pin->IsSelected() && aSelectedItem->Type() == SCH_LINE_T )
1426 {
1427 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1428 m_specialCaseSheetPins[ pin ] = { line, line->GetStartPoint() == aPoint };
1429 }
1430 else if( !newWire )
1431 {
1432 // Add a new wire between the sheetpin and the selected item so the
1433 // selected item can be dragged.
1434 newWire = makeNewWire( aCommit, pin, aSelectedItem, aPoint, aPoint );
1435 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1436 aList.push_back( newWire );
1437 }
1438 }
1439 }
1440
1441 break;
1442
1443 case SCH_SYMBOL_T:
1444 case SCH_JUNCTION_T:
1445 if( test->IsConnected( aPoint ) && !newWire )
1446 {
1447 // Add a new wire between the symbol or junction and the selected item so
1448 // the selected item can be dragged.
1449 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
1450 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1451 aList.push_back( newWire );
1452 }
1453
1454 break;
1455
1456 case SCH_NO_CONNECT_T:
1457 // Select no-connects that are connected to items being moved.
1458 if( !test->HasFlag( SELECTED_BY_DRAG ) && test->IsConnected( aPoint ) )
1459 {
1460 aList.push_back( test );
1461 test->SetFlags( SELECTED_BY_DRAG );
1462 }
1463
1464 break;
1465
1466 case SCH_LABEL_T:
1467 case SCH_GLOBAL_LABEL_T:
1468 case SCH_HIER_LABEL_T:
1470 case SCH_SHEET_PIN_T:
1471 // Performance optimization:
1472 if( test->HasFlag( SELECTED_BY_DRAG ) )
1473 break;
1474
1475 // Select labels that are connected to a wire (or bus) being moved.
1476 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
1477 {
1478 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
1479 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1480
1481 bool oneEndFixed = !line->HasFlag( STARTPOINT ) || !line->HasFlag( ENDPOINT );
1482
1483 if( line->HitTest( label->GetTextPos(), 1 ) )
1484 {
1485 if( ( !line->HasFlag( STARTPOINT )
1486 && label->GetPosition() == line->GetStartPoint() )
1487 || ( !line->HasFlag( ENDPOINT )
1488 && label->GetPosition() == line->GetEndPoint() ) )
1489 {
1490 //If we have a line selected at only one end, don't grab labels
1491 //connected directly to the unselected endpoint
1492 break;
1493 }
1494 else
1495 {
1496 label->SetFlags( SELECTED_BY_DRAG );
1497 aList.push_back( label );
1498
1499 if( oneEndFixed )
1500 {
1502 info.attachedLine = line;
1503 info.originalLabelPos = label->GetPosition();
1504 m_specialCaseLabels[label] = info;
1505 }
1506 }
1507 }
1508 }
1509 else if( test->IsConnected( aPoint ) && !newWire )
1510 {
1511 // Add a new wire between the label and the selected item so the selected item
1512 // can be dragged.
1513 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
1514 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1515 aList.push_back( newWire );
1516 }
1517
1518 break;
1519
1522 // Performance optimization:
1523 if( test->HasFlag( SELECTED_BY_DRAG ) )
1524 break;
1525
1526 // Select bus entries that are connected to a bus being moved.
1527 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
1528 {
1529 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1530
1531 if( ( !line->HasFlag( STARTPOINT ) && test->IsConnected( line->GetStartPoint() ) )
1532 || ( !line->HasFlag( ENDPOINT ) && test->IsConnected( line->GetEndPoint() ) ) )
1533 {
1534 // If we have a line selected at only one end, don't grab bus entries
1535 // connected directly to the unselected endpoint
1536 continue;
1537 }
1538
1539 for( VECTOR2I& point : test->GetConnectionPoints() )
1540 {
1541 if( line->HitTest( point, 1 ) )
1542 {
1543 test->SetFlags( SELECTED_BY_DRAG );
1544 aList.push_back( test );
1545
1546 // A bus entry needs its wire & label as well
1547 std::vector<VECTOR2I> ends = test->GetConnectionPoints();
1548 VECTOR2I otherEnd;
1549
1550 if( ends[0] == point )
1551 otherEnd = ends[1];
1552 else
1553 otherEnd = ends[0];
1554
1555 getConnectedDragItems( aCommit, test, otherEnd, aList );
1556
1557 // No need to test the other end of the bus entry
1558 break;
1559 }
1560 }
1561 }
1562
1563 break;
1564
1565 default:
1566 break;
1567 }
1568 }
1569}
1570
1571
1572void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
1573{
1574 switch( aItem->Type() )
1575 {
1576 case SCH_LINE_T:
1577 {
1578 SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
1579
1580 if( aItem->HasFlag( STARTPOINT ) || !m_isDrag )
1581 line->MoveStart( aDelta );
1582
1583 if( aItem->HasFlag( ENDPOINT ) || !m_isDrag )
1584 line->MoveEnd( aDelta );
1585
1586 break;
1587 }
1588
1589 case SCH_PIN_T:
1590 case SCH_FIELD_T:
1591 {
1592 SCH_ITEM* parent = (SCH_ITEM*) aItem->GetParent();
1593 VECTOR2I delta( aDelta );
1594
1595 if( parent && parent->Type() == SCH_SYMBOL_T )
1596 {
1597 SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem->GetParent();
1598 TRANSFORM transform = symbol->GetTransform().InverseTransform();
1599
1600 delta = transform.TransformCoordinate( delta );
1601 }
1602
1603 static_cast<SCH_ITEM*>( aItem )->Move( delta );
1604
1605 // If we're moving a field with respect to its parent then it's no longer auto-placed
1606 if( aItem->Type() == SCH_FIELD_T && parent && !parent->IsSelected() )
1608
1609 break;
1610 }
1611
1612 case SCH_SHEET_PIN_T:
1613 {
1614 SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) aItem;
1615
1616 pin->SetStoredPos( pin->GetStoredPos() + aDelta );
1617 pin->ConstrainOnEdge( pin->GetStoredPos(), true );
1618 break;
1619 }
1620
1621 case SCH_LABEL_T:
1623 case SCH_GLOBAL_LABEL_T:
1624 case SCH_HIER_LABEL_T:
1625 {
1626 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
1627
1628 if( m_specialCaseLabels.count( label ) )
1629 {
1631 SEG currentLine( info.attachedLine->GetStartPoint(), info.attachedLine->GetEndPoint() );
1632 label->SetPosition( currentLine.NearestPoint( info.originalLabelPos ) );
1633 }
1634 else
1635 {
1636 label->Move( aDelta );
1637 }
1638
1639 break;
1640 }
1641
1642 default:
1643 static_cast<SCH_ITEM*>( aItem )->Move( aDelta );
1644 break;
1645 }
1646
1647 aItem->SetFlags( IS_MOVING );
1648}
1649
1650
1652{
1655 GRID_HELPER_GRIDS selectionGrid = grid.GetSelectionGrid( selection );
1656 SCH_COMMIT commit( m_toolMgr );
1657
1658 auto doMoveItem =
1659 [&]( EDA_ITEM* item, const VECTOR2I& delta )
1660 {
1661 commit.Modify( item, m_frame->GetScreen() );
1662
1663 // Ensure only one end is moved when calling moveItem
1664 // i.e. we are in drag mode
1665 bool tmp_isDrag = m_isDrag;
1666 m_isDrag = true;
1667 moveItem( item, delta );
1668 m_isDrag = tmp_isDrag;
1669
1670 item->ClearFlags( IS_MOVING );
1671 updateItem( item, true );
1672 };
1673
1674 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
1675 {
1676 if( !it->IsSelected() )
1677 it->ClearFlags( STARTPOINT | ENDPOINT );
1678
1679 if( !selection.IsHover() && it->IsSelected() )
1680 it->SetFlags( STARTPOINT | ENDPOINT );
1681
1682 it->SetStoredPos( it->GetPosition() );
1683
1684 if( it->Type() == SCH_SHEET_T )
1685 {
1686 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( it )->GetPins() )
1687 pin->SetStoredPos( pin->GetPosition() );
1688 }
1689 }
1690
1691 for( EDA_ITEM* item : selection )
1692 {
1693 if( item->Type() == SCH_LINE_T )
1694 {
1695 SCH_LINE* line = static_cast<SCH_LINE*>( item );
1696 std::vector<int> flags{ STARTPOINT, ENDPOINT };
1697 std::vector<VECTOR2I> pts{ line->GetStartPoint(), line->GetEndPoint() };
1698
1699 for( int ii = 0; ii < 2; ++ii )
1700 {
1701 EDA_ITEMS drag_items{ item };
1702 line->ClearFlags();
1703 line->SetFlags( SELECTED );
1704 line->SetFlags( flags[ii] );
1705 getConnectedDragItems( &commit, line, pts[ii], drag_items );
1706 std::set<EDA_ITEM*> unique_items( drag_items.begin(), drag_items.end() );
1707
1708 VECTOR2I delta = grid.AlignGrid( pts[ii], selectionGrid ) - pts[ii];
1709
1710 if( delta != VECTOR2I( 0, 0 ) )
1711 {
1712 for( EDA_ITEM* dragItem : unique_items )
1713 {
1714 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
1715 continue;
1716
1717 doMoveItem( dragItem, delta );
1718 }
1719 }
1720 }
1721 }
1722 else if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TEXT_T )
1723 {
1724 VECTOR2I delta = grid.AlignGrid( item->GetPosition(), selectionGrid ) - item->GetPosition();
1725
1726 if( delta != VECTOR2I( 0, 0 ) )
1727 doMoveItem( item, delta );
1728 }
1729 else if( item->Type() == SCH_SHEET_T )
1730 {
1731 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1732 VECTOR2I topLeft = sheet->GetPosition();
1733 VECTOR2I bottomRight = topLeft + sheet->GetSize();
1734 VECTOR2I tl_delta = grid.AlignGrid( topLeft, selectionGrid ) - topLeft;
1735 VECTOR2I br_delta = grid.AlignGrid( bottomRight, selectionGrid ) - bottomRight;
1736
1737 if( tl_delta != VECTOR2I( 0, 0 ) || br_delta != VECTOR2I( 0, 0 ) )
1738 {
1739 doMoveItem( sheet, tl_delta );
1740
1741 VECTOR2I newSize = (VECTOR2I) sheet->GetSize() - tl_delta + br_delta;
1742 sheet->SetSize( VECTOR2I( newSize.x, newSize.y ) );
1743 updateItem( sheet, true );
1744 }
1745
1746 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1747 {
1748 VECTOR2I newPos;
1749
1750 if( pin->GetSide() == SHEET_SIDE::TOP || pin->GetSide() == SHEET_SIDE::LEFT )
1751 newPos = pin->GetPosition() + tl_delta;
1752 else
1753 newPos = pin->GetPosition() + br_delta;
1754
1755 VECTOR2I delta = grid.AlignGrid( newPos - pin->GetPosition(), selectionGrid );
1756
1757 if( delta != VECTOR2I( 0, 0 ) )
1758 {
1759 EDA_ITEMS drag_items;
1760 getConnectedDragItems( &commit, pin, pin->GetConnectionPoints()[0],
1761 drag_items );
1762
1763 doMoveItem( pin, delta );
1764
1765 for( EDA_ITEM* dragItem : drag_items )
1766 {
1767 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
1768 continue;
1769
1770 doMoveItem( dragItem, delta );
1771 }
1772 }
1773 }
1774 }
1775 else
1776 {
1777 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1778 std::vector<VECTOR2I> connections = schItem->GetConnectionPoints();
1779 EDA_ITEMS drag_items;
1780
1781 for( const VECTOR2I& point : connections )
1782 getConnectedDragItems( &commit, schItem, point, drag_items );
1783
1784 std::map<VECTOR2I, int> shifts;
1785 VECTOR2I most_common( 0, 0 );
1786 int max_count = 0;
1787
1788 for( const VECTOR2I& conn : connections )
1789 {
1790 VECTOR2I gridpt = grid.AlignGrid( conn, selectionGrid ) - conn;
1791
1792 shifts[gridpt]++;
1793
1794 if( shifts[gridpt] > max_count )
1795 {
1796 most_common = gridpt;
1797 max_count = shifts[most_common];
1798 }
1799 }
1800
1801 if( most_common != VECTOR2I( 0, 0 ) )
1802 {
1803 doMoveItem( item, most_common );
1804
1805 for( EDA_ITEM* dragItem : drag_items )
1806 {
1807 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
1808 continue;
1809
1810 doMoveItem( dragItem, most_common );
1811 }
1812 }
1813 }
1814 }
1815
1817 lwbTool->TrimOverLappingWires( &commit, &selection );
1818 lwbTool->AddJunctionsIfNeeded( &commit, &selection );
1819
1821
1822 m_frame->SchematicCleanUp( &commit );
1823 commit.Push( _( "Align Items to Grid" ) );
1824 return 0;
1825}
1826
1827
1829{
1830 // Remove new bend lines added during the drag
1831 for( SCH_LINE* newLine : m_newDragLines )
1832 {
1833 m_frame->RemoveFromScreen( newLine, m_frame->GetScreen() );
1834 delete newLine;
1835 }
1836
1837 m_newDragLines.clear();
1838}
1839
1840
1842{
1843 Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::move.MakeEvent() );
1844 Go( &SCH_MOVE_TOOL::Main, EE_ACTIONS::drag.MakeEvent() );
1846}
1847
1848
static TOOL_ACTION duplicate
Definition: actions.h:77
static TOOL_ACTION doDelete
Definition: actions.h:78
static TOOL_ACTION cursorClick
Definition: actions.h:169
static TOOL_ACTION increment
Definition: actions.h:87
static TOOL_ACTION refreshPreview
Definition: actions.h:149
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Modify a given item in the model.
Definition: commit.h:108
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition: commit.h:86
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
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:613
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition: sch_item.h:96
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:244
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition: eda_item.cpp:77
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:260
static TOOL_ACTION alignToGrid
Definition: ee_actions.h:126
static TOOL_ACTION highlightNet
Definition: ee_actions.h:308
static TOOL_ACTION move
Definition: ee_actions.h:127
static TOOL_ACTION clearSelection
Clears the current selection.
Definition: ee_actions.h:56
static TOOL_ACTION drag
Definition: ee_actions.h:128
static TOOL_ACTION rotateCCW
Definition: ee_actions.h:131
static TOOL_ACTION restartMove
Definition: ee_actions.h:260
static TOOL_ACTION rotateCW
Definition: ee_actions.h:130
static TOOL_ACTION selectOnPCB
Definition: ee_actions.h:261
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...
int ClearSelection(const TOOL_EVENT &aEvent)
Select all visible items in sheet.
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:302
An interface for classes handling user events controlling the view behavior such as zooming,...
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
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:1673
virtual SETTINGS_MANAGER & GetSettingsManager() const
Definition: pgm_base.h:125
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
Execute the changes.
Definition: sch_commit.cpp:432
virtual void Revert() override
Revert the commit by restoring the modified items state.
Definition: sch_commit.cpp:510
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:181
void SelectUnit(SCH_SYMBOL *aSymbol, int aUnit)
Definition: picksymbol.cpp:95
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:167
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition: sch_item.h:445
int GetBodyStyle() const
Definition: sch_item.h:233
void SetLayer(SCH_LAYER_ID aLayer)
Definition: sch_item.h:283
void SetConnectivityDirty(bool aDirty=true)
Definition: sch_item.h:513
void SetFieldsAutoplaced(AUTOPLACE_ALGO aAlgo)
Definition: sch_item.h:550
bool IsConnected(const VECTOR2I &aPoint) const
Test the item to see if it is connected to aPoint.
Definition: sch_item.cpp:209
virtual bool IsMovableFromAnchorPoint() const
Definition: sch_item.h:247
virtual std::vector< VECTOR2I > GetConnectionPoints() const
Add all the connection points for this item to aPoints.
Definition: sch_item.h:465
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:377
void SetPosition(const VECTOR2I &aPosition) override
Definition: sch_label.cpp:370
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:789
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:689
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition: sch_line.cpp:221
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:169
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition: sch_line.h:152
void MoveStart(const VECTOR2I &aMoveVector)
Definition: sch_line.cpp:163
double GetLength() const
Definition: sch_line.cpp:237
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:496
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:112
VECTOR2I GetSize() const
Definition: sch_sheet.h:111
VECTOR2I GetPosition() const override
Definition: sch_sheet.h:399
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition: sch_sheet.h:180
Schematic symbol object.
Definition: sch_symbol.h:77
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:169
bool IsHover() const
Definition: selection.h:84
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:100
EDA_ITEM * Front() const
Definition: selection.h:172
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:178
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:221
bool HasReferencePoint() const
Definition: selection.h:211
T * GetAppSettings(const wxString &aFilename)
Return a handle to the a given settings by type.
const TRANSFORM & GetTransform() const
Definition: symbol.h:191
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:44
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:38
Generic, UI-independent tool event.
Definition: tool_event.h:168
bool DisableGridSnapping() const
Definition: tool_event.h:368
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
Returns more specific information about the type of an event.
Definition: tool_event.h:247
bool IsActivate() const
Definition: tool_event.h:342
COMMIT * Commit() const
Definition: tool_event.h:280
bool IsClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:209
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:312
int Modifier(int aMask=MD_MODIFIER_MASK) const
Return information about key modifiers state (Ctrl, Alt, etc.).
Definition: tool_event.h:363
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:465
bool IsDblClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:215
std::atomic< SYNCRONOUS_TOOL_STATE > * SynchronousState() const
Definition: tool_event.h:277
std::optional< int > GetCommandId() const
Definition: tool_event.h:525
void SetPassEvent(bool aPass=true)
Definition: tool_event.h:253
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition: tool_event.h:322
bool IsMotion() const
Definition: tool_event.h:327
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()
std::unique_ptr< 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
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:189
#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:538
#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:42
@ GRID_CURRENT
Definition: grid_helper.h:44
@ LAYER_WIRE
Definition: layer_ids.h:404
@ LAYER_BUS
Definition: layer_ids.h:405
@ LAYER_BUS_JUNCTION
Definition: layer_ids.h:449
@ 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:198
PGM_BASE & Pgm()
The global program "get" accessor.
Definition: pgm_base.cpp:1073
see class PGM_BASE
@ AUTOPLACE_NONE
Definition: sch_item.h:69
#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
Context menu choice.
Definition: tool_event.h:98
@ TA_UNDO_REDO_PRE
This event is sent before undo/redo command is performed.
Definition: tool_event.h:106
@ MD_SHIFT
Definition: tool_event.h:143
@ STS_CANCELLED
Definition: tool_event.h:161
@ STS_FINISHED
Definition: tool_event.h:160
@ STS_RUNNING
Definition: tool_event.h:159
@ BUT_LEFT
Definition: tool_event.h:132
@ BUT_RIGHT
Definition: tool_event.h:133
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
constexpr int sign(T val)
Definition: util.h:159
VECTOR2< int32_t > VECTOR2I
Definition: vector2d.h:695