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