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 <memory>
27#include <optional>
28#include <wx/log.h>
29#include <trigo.h>
31#include <tool/tool_manager.h>
35#include <sch_actions.h>
36#include <sch_commit.h>
37#include <eda_item.h>
38#include <sch_group.h>
39#include <sch_item.h>
40#include <sch_symbol.h>
41#include <sch_sheet.h>
42#include <sch_sheet_pin.h>
43#include <sch_line.h>
44#include <sch_connection.h>
45#include <sch_junction.h>
46#include <junction_helpers.h>
47#include <sch_edit_frame.h>
48#include <eeschema_id.h>
49#include <pgm_base.h>
50#include <view/view_controls.h>
52#include <math/box2.h>
53#include <base_units.h>
54#include <sch_screen.h>
55#include "sch_move_tool.h"
57
58
59// For adding to or removing from selections
60#define QUIET_MODE true
61
62
63static bool isGraphicItemForDrop( const SCH_ITEM* aItem )
64{
65 switch( aItem->Type() )
66 {
67 case SCH_SHAPE_T:
68 case SCH_BITMAP_T:
69 case SCH_TEXT_T:
70 case SCH_TEXTBOX_T:
71 return true;
72 case SCH_LINE_T:
73 return static_cast<const SCH_LINE*>( aItem )->IsGraphicLine();
74 default:
75 return false;
76 }
77}
78
79
80static void cloneWireConnection( SCH_LINE* aNewLine, SCH_ITEM* aSource, SCH_EDIT_FRAME* aFrame )
81{
82 if( !aNewLine || !aSource || !aFrame )
83 return;
84
85 SCH_LINE* sourceLine = dynamic_cast<SCH_LINE*>( aSource );
86
87 if( !sourceLine )
88 return;
89
90 SCH_SHEET_PATH sheetPath = aFrame->GetCurrentSheet();
91 SCH_CONNECTION* sourceConnection = sourceLine->Connection( &sheetPath );
92
93 if( !sourceConnection )
94 return;
95
96 SCH_CONNECTION* newConnection = aNewLine->InitializeConnection( sheetPath, nullptr );
97
98 if( !newConnection )
99 return;
100
101 newConnection->Clone( *sourceConnection );
102}
103
104
106 SCH_TOOL_BASE<SCH_EDIT_FRAME>( "eeschema.InteractiveMove" ),
107 m_inMoveTool( false ),
108 m_moveInProgress( false ),
109 m_isDrag( false ),
110 m_moveOffset( 0, 0 )
111{
112}
113
114
116{
118
119 auto moveCondition =
120 []( const SELECTION& aSel )
121 {
122 if( aSel.Empty() || SELECTION_CONDITIONS::OnlyTypes( { SCH_MARKER_T } )( aSel ) )
123 return false;
124
126 return false;
127
128 return true;
129 };
130
131 // Add move actions to the selection tool menu
132 //
133 CONDITIONAL_MENU& selToolMenu = m_selectionTool->GetToolMenu().GetMenu();
134
135 selToolMenu.AddItem( SCH_ACTIONS::move, moveCondition, 150 );
136 selToolMenu.AddItem( SCH_ACTIONS::drag, moveCondition, 150 );
137 selToolMenu.AddItem( SCH_ACTIONS::alignToGrid, moveCondition, 150 );
138
139 return true;
140}
141
142
143void SCH_MOVE_TOOL::orthoLineDrag( SCH_COMMIT* aCommit, SCH_LINE* line, const VECTOR2I& splitDelta,
144 int& xBendCount, int& yBendCount, const EE_GRID_HELPER& grid )
145{
146 // If the move is not the same angle as this move, then we need to do something special with
147 // the unselected end to maintain orthogonality. Either drag some connected line that is the
148 // same angle as the move or add two lines to make a 90 degree connection
149 if( !EDA_ANGLE( splitDelta ).IsParallelTo( line->Angle() ) || line->GetLength() == 0 )
150 {
151 VECTOR2I unselectedEnd = line->HasFlag( STARTPOINT ) ? line->GetEndPoint()
152 : line->GetStartPoint();
153 VECTOR2I selectedEnd = line->HasFlag( STARTPOINT ) ? line->GetStartPoint()
154 : line->GetEndPoint();
155
156 // Look for pre-existing lines we can drag with us instead of creating new ones
157 bool foundAttachment = false;
158 bool foundJunction = false;
159 bool foundPin = false;
160 SCH_LINE* foundLine = nullptr;
161
162 for( EDA_ITEM* cItem : m_lineConnectionCache[line] )
163 {
164 foundAttachment = true;
165
166 // If the move is the same angle as a connected line, we can shrink/extend that line
167 // endpoint
168 switch( cItem->Type() )
169 {
170 case SCH_LINE_T:
171 {
172 SCH_LINE* cLine = static_cast<SCH_LINE*>( cItem );
173
174 // A matching angle on a non-zero-length line means lengthen/shorten will work
175 if( EDA_ANGLE( splitDelta ).IsParallelTo( cLine->Angle() )
176 && cLine->GetLength() != 0 )
177 {
178 foundLine = cLine;
179 }
180
181 // Zero length lines are lines that this algorithm has shortened to 0 so they also
182 // work but we should prefer using a segment with length and angle matching when
183 // we can (otherwise the zero length line will draw overlapping segments on them)
184 if( !foundLine && cLine->GetLength() == 0 )
185 foundLine = cLine;
186
187 break;
188 }
189 case SCH_JUNCTION_T:
190 foundJunction = true;
191 break;
192
193 case SCH_PIN_T:
194 foundPin = true;
195 break;
196
197 case SCH_SHEET_T:
198 for( const auto& pair : m_specialCaseSheetPins )
199 {
200 if( pair.first->IsConnected( selectedEnd ) )
201 {
202 foundPin = true;
203 break;
204 }
205 }
206
207 break;
208
209 default:
210 break;
211 }
212 }
213
214 // Ok... what if our original line is length zero from moving in its direction, and the
215 // last added segment of the 90 bend we are connected to is zero from moving it in its
216 // direction after it was added?
217 //
218 // If we are moving in original direction, we should lengthen the original drag wire.
219 // Otherwise we should lengthen the new wire.
220 bool preferOriginalLine = false;
221
222 if( foundLine
223 && foundLine->GetLength() == 0
224 && line->GetLength() == 0
225 && EDA_ANGLE( splitDelta ).IsParallelTo( line->GetStoredAngle() ) )
226 {
227 preferOriginalLine = true;
228 }
229 // If we have found an attachment, but not a line, we want to check if it's a junction.
230 // These are special-cased and get a single line added instead of a 90-degree bend. Except
231 // when we're on a pin, because pins always need bends, and junctions are just added to
232 // pins for visual clarity.
233 else if( !foundLine && foundJunction && !foundPin )
234 {
235 // Create a new wire ending at the unselected end
236 foundLine = new SCH_LINE( unselectedEnd, line->GetLayer() );
237 foundLine->SetFlags( IS_NEW );
238 foundLine->SetLastResolvedState( line );
239 cloneWireConnection( foundLine, line, m_frame );
240 m_frame->AddToScreen( foundLine, m_frame->GetScreen() );
241 m_newDragLines.insert( foundLine );
242
243 // We just broke off of the existing items, so replace all of them with our new
244 // end connection.
246 m_lineConnectionCache[line].clear();
247 m_lineConnectionCache[line].emplace_back( foundLine );
248 }
249
250 // We want to drag our found line if it's in the same angle as the move or zero length,
251 // but if the original drag line is also zero and the same original angle we should extend
252 // that one first
253 if( foundLine && !preferOriginalLine )
254 {
255 // Move the connected line found oriented in the direction of our move.
256 //
257 // Make sure we grab the right endpoint, it's not always STARTPOINT since the user can
258 // draw a box of lines. We need to only move one though, and preferably the start point,
259 // in case we have a zero length line that we are extending (we want the foundLine
260 // start point to be attached to the unselected end of our drag line).
261 //
262 // Also, new lines are added already so they'll be in the undo list, skip adding them.
263
264 if( !foundLine->HasFlag( IS_CHANGED ) && !foundLine->HasFlag( IS_NEW ) )
265 {
266 aCommit->Modify( (SCH_ITEM*) foundLine, m_frame->GetScreen() );
267
268 if( !foundLine->IsSelected() )
269 m_changedDragLines.insert( foundLine );
270 }
271
272 if( foundLine->GetStartPoint() == unselectedEnd )
273 foundLine->MoveStart( splitDelta );
274 else if( foundLine->GetEndPoint() == unselectedEnd )
275 foundLine->MoveEnd( splitDelta );
276
277 updateItem( foundLine, true );
278
279 SCH_LINE* bendLine = nullptr;
280
281 if( m_lineConnectionCache.count( foundLine ) == 1
282 && m_lineConnectionCache[foundLine][0]->Type() == SCH_LINE_T )
283 {
284 bendLine = static_cast<SCH_LINE*>( m_lineConnectionCache[foundLine][0] );
285 }
286
287 // Remerge segments we've created if this is a segment that we've added whose only
288 // other connection is also an added segment
289 //
290 // bendLine is first added segment at the original attachment point, foundLine is the
291 // orthogonal line between bendLine and this line
292 if( foundLine->HasFlag( IS_NEW )
293 && foundLine->GetLength() == 0
294 && bendLine && bendLine->HasFlag( IS_NEW ) )
295 {
296 if( line->HasFlag( STARTPOINT ) )
297 line->SetEndPoint( bendLine->GetEndPoint() );
298 else
299 line->SetStartPoint( bendLine->GetEndPoint() );
300
301 // Update our cache of the connected items.
302
303 // First, re-attach our drag labels to the original line being re-merged.
304 for( EDA_ITEM* candidate : m_lineConnectionCache[bendLine] )
305 {
306 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( candidate );
307
308 if( label && m_specialCaseLabels.count( label ) )
309 m_specialCaseLabels[label].attachedLine = line;
310 }
311
313 m_lineConnectionCache[bendLine].clear();
314 m_lineConnectionCache[foundLine].clear();
315
316 m_frame->RemoveFromScreen( bendLine, m_frame->GetScreen() );
317 m_frame->RemoveFromScreen( foundLine, m_frame->GetScreen() );
318
319 m_newDragLines.erase( bendLine );
320 m_newDragLines.erase( foundLine );
321
322 delete bendLine;
323 delete foundLine;
324 }
325 //Ok, move the unselected end of our item
326 else
327 {
328 if( line->HasFlag( STARTPOINT ) )
329 line->MoveEnd( splitDelta );
330 else
331 line->MoveStart( splitDelta );
332 }
333
334 updateItem( line, true );
335 }
336 else if( line->GetLength() == 0 )
337 {
338 // We didn't find another line to shorten/lengthen, (or we did but it's also zero)
339 // so now is a good time to use our existing zero-length original line
340 }
341 // Either no line was at the "right" angle, or this was a junction, pin, sheet, etc. We
342 // need to add segments to keep the soon-to-move unselected end connected to these items.
343 //
344 // To keep our drag selections all the same, we'll move our unselected end point and then
345 // put wires between it and its original endpoint.
346 else if( foundAttachment && line->IsOrthogonal() )
347 {
348 VECTOR2D lineGrid = grid.GetGridSize( grid.GetItemGrid( line ) );
349
350 // The bend counter handles a group of wires all needing their offset one grid movement
351 // further out from each other to not overlap. The absolute value stuff finds the
352 // direction of the line and hence the the bend increment on that axis
353 unsigned int xMoveBit = splitDelta.x != 0;
354 unsigned int yMoveBit = splitDelta.y != 0;
355 int xLength = abs( unselectedEnd.x - selectedEnd.x );
356 int yLength = abs( unselectedEnd.y - selectedEnd.y );
357 int xMove = ( xLength - ( xBendCount * lineGrid.x ) )
358 * sign( selectedEnd.x - unselectedEnd.x );
359 int yMove = ( yLength - ( yBendCount * lineGrid.y ) )
360 * sign( selectedEnd.y - unselectedEnd.y );
361
362 // Create a new wire ending at the unselected end, we'll move the new wire's start
363 // point to the unselected end
364 SCH_LINE* a = new SCH_LINE( unselectedEnd, line->GetLayer() );
365 a->MoveStart( VECTOR2I( xMove, yMove ) );
366 a->SetFlags( IS_NEW );
367 a->SetConnectivityDirty( true );
368 a->SetLastResolvedState( line );
369 cloneWireConnection( a, line, m_frame );
370 m_frame->AddToScreen( a, m_frame->GetScreen() );
371 m_newDragLines.insert( a );
372
373 SCH_LINE* b = new SCH_LINE( a->GetStartPoint(), line->GetLayer() );
374 b->MoveStart( VECTOR2I( splitDelta.x, splitDelta.y ) );
375 b->SetFlags( IS_NEW | STARTPOINT );
376 b->SetConnectivityDirty( true );
377 b->SetLastResolvedState( line );
378 cloneWireConnection( b, line, m_frame );
379 m_frame->AddToScreen( b, m_frame->GetScreen() );
380 m_newDragLines.insert( b );
381
382 xBendCount += yMoveBit;
383 yBendCount += xMoveBit;
384
385 // Ok move the unselected end of our item
386 if( line->HasFlag( STARTPOINT ) )
387 {
388 line->MoveEnd( VECTOR2I( splitDelta.x ? splitDelta.x : xMove,
389 splitDelta.y ? splitDelta.y : yMove ) );
390 }
391 else
392 {
393 line->MoveStart( VECTOR2I( splitDelta.x ? splitDelta.x : xMove,
394 splitDelta.y ? splitDelta.y : yMove ) );
395 }
396
397 // Update our cache of the connected items. First, attach our drag labels to the line
398 // left behind.
399 for( EDA_ITEM* candidate : m_lineConnectionCache[line] )
400 {
401 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( candidate );
402
403 if( label && m_specialCaseLabels.count( label ) )
404 m_specialCaseLabels[label].attachedLine = a;
405 }
406
407 // We just broke off of the existing items, so replace all of them with our new end
408 // connection.
410 m_lineConnectionCache[b].emplace_back( a );
411 m_lineConnectionCache[line].clear();
412 m_lineConnectionCache[line].emplace_back( b );
413 }
414 // Original line has no attachments, just move the unselected end
415 else if( !foundAttachment )
416 {
417 if( line->HasFlag( STARTPOINT ) )
418 line->MoveEnd( splitDelta );
419 else
420 line->MoveStart( splitDelta );
421 }
422 }
423}
424
425
426int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent )
427{
429
430 if( SCH_COMMIT* commit = dynamic_cast<SCH_COMMIT*>( aEvent.Commit() ) )
431 {
432 bool isSlice = false;
433
434 if( m_isDrag )
435 isSlice = aEvent.Parameter<bool>();
436
437 wxCHECK( aEvent.SynchronousState(), 0 );
438 aEvent.SynchronousState()->store( STS_RUNNING );
439
440 if( doMoveSelection( aEvent, commit, isSlice ) )
441 aEvent.SynchronousState()->store( STS_FINISHED );
442 else
443 aEvent.SynchronousState()->store( STS_CANCELLED );
444 }
445 else
446 {
447 SCH_COMMIT localCommit( m_toolMgr );
448
449 if( doMoveSelection( aEvent, &localCommit, false ) )
450 localCommit.Push( m_isDrag ? _( "Drag" ) : _( "Move" ) );
451 else
452 localCommit.Revert();
453 }
454
455 return 0;
456}
457
458
459bool SCH_MOVE_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, SCH_COMMIT* aCommit, bool aIsSlice )
460{
463 bool wasDragging = m_moveInProgress && m_isDrag;
464 bool isLineModeConstrained = false;
465
467 isLineModeConstrained = cfg->m_Drawing.line_mode != LINE_MODE::LINE_MODE_FREE;
468
469 m_anchorPos.reset();
470
471 if( m_moveInProgress )
472 {
473 if( m_isDrag != wasDragging )
474 {
475 EDA_ITEM* sel = m_selectionTool->GetSelection().Front();
476
477 if( sel && !sel->IsNew() )
478 {
479 // Reset the selected items so we can start again with the current m_isDrag
480 // state.
481 aCommit->Revert();
482
483 m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
485 m_moveInProgress = false;
486 controls->SetAutoPan( false );
487
488 // And give it a kick so it doesn't have to wait for the first mouse movement
489 // to refresh.
490 m_toolMgr->PostAction( SCH_ACTIONS::restartMove );
491 }
492 }
493 else
494 {
495 // The tool hotkey is interpreted as a click when already dragging/moving
496 m_toolMgr->PostAction( ACTIONS::cursorClick );
497 }
498
499 return false;
500 }
501
502 if( m_inMoveTool ) // Must come after m_moveInProgress checks above...
503 return false;
504
506
507 SCH_SELECTION& userSelection = m_selectionTool->GetSelection();
508
509 // If a single pin is selected, promote the move selection to its parent symbol
510 if( userSelection.GetSize() == 1 )
511 {
512 EDA_ITEM* selItem = userSelection.Front();
513
514 if( selItem->Type() == SCH_PIN_T )
515 {
516 EDA_ITEM* parent = selItem->GetParent();
517
518 if( parent->Type() == SCH_SYMBOL_T )
519 {
520 m_selectionTool->ClearSelection();
521 m_selectionTool->AddItemToSel( parent );
522 }
523 }
524 }
525
526 // Be sure that there is at least one item that we can move. If there's no selection try
527 // looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection).
528 SCH_SELECTION& selection = m_selectionTool->RequestSelection( SCH_COLLECTOR::MovableItems,
529 true );
530 bool unselect = selection.IsHover();
531
532 // Keep an original copy of the starting points for cleanup after the move
533 std::vector<DANGLING_END_ITEM> internalPoints;
534
535 bool selectionHasSheetPins = false;
536 bool selectionHasGraphicItems = false;
537 bool selectionHasNonGraphicItems = false;
538 bool selectionIsGraphicsOnly = false;
539
540 std::unique_ptr<SCH_DRAG_NET_COLLISION_MONITOR> netCollisionMonitor;
541
542 auto refreshSelectionTraits = [&]()
543 {
544 selectionHasSheetPins = false;
545 selectionHasGraphicItems = false;
546 selectionHasNonGraphicItems = false;
547
548 for( EDA_ITEM* edaItem : selection )
549 {
550 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( edaItem );
551
552 if( schItem->Type() == SCH_SHEET_PIN_T )
553 selectionHasSheetPins = true;
554
555 if( isGraphicItemForDrop( schItem ) )
556 selectionHasGraphicItems = true;
557 else if( schItem->Type() != SCH_SHEET_T )
558 selectionHasNonGraphicItems = true;
559 }
560
561 selectionIsGraphicsOnly = selectionHasGraphicItems && !selectionHasNonGraphicItems;
562 };
563
564 refreshSelectionTraits();
565
566 if( !selection.Empty() )
567 {
568 netCollisionMonitor = std::make_unique<SCH_DRAG_NET_COLLISION_MONITOR>( m_frame, m_view );
569 netCollisionMonitor->Initialize( selection );
570 }
571
572 bool lastCtrlDown = false;
573
574 Activate();
575
576 // Must be done after Activate() so that it gets set into the correct context
577 controls->ShowCursor( true );
578
579 m_frame->PushTool( aEvent );
580
581 if( selection.Empty() )
582 {
583 // Note that it's important to go through push/pop even when the selection is empty.
584 // This keeps other tools from having to special-case an empty move.
585 m_frame->PopTool( aEvent );
586 return false;
587 }
588
589 bool restore_state = false;
590 TOOL_EVENT copy = aEvent;
591 TOOL_EVENT* evt = &copy;
592 VECTOR2I prevPos;
594 SCH_SHEET* hoverSheet = nullptr;
595 KICURSOR currentCursor = KICURSOR::MOVING;
596 m_cursor = controls->GetCursorPosition();
597
598 // Main loop: keep receiving events
599 do
600 {
601 m_frame->GetCanvas()->SetCurrentCursor( currentCursor );
602 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
603 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
604
605 bool ctrlDown = evt->Modifier( MD_CTRL );
606 lastCtrlDown = ctrlDown;
607
609 || evt->IsAction( &SCH_ACTIONS::move )
610 || evt->IsAction( &SCH_ACTIONS::drag )
611 || evt->IsMotion()
612 || evt->IsDrag( BUT_LEFT )
614 {
615 refreshSelectionTraits();
616
617 if( !m_moveInProgress ) // Prepare to start moving/dragging
618 {
619 SCH_ITEM* sch_item = (SCH_ITEM*) selection.Front();
620 bool placingNewItems = sch_item && sch_item->IsNew();
621
622 //------------------------------------------------------------------------
623 // Setup a drag or a move
624 //
625 m_dragAdditions.clear();
626 m_specialCaseLabels.clear();
628 internalPoints.clear();
630
631 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
632 {
633 it->ClearFlags( SELECTED_BY_DRAG );
634
635 if( !it->IsSelected() )
636 it->ClearFlags( STARTPOINT | ENDPOINT );
637 }
638
639 // Drag of split items start over top of their other segment so
640 // we want to skip grabbing the segments we split from
641 if( m_isDrag && !aIsSlice )
642 {
643 EDA_ITEMS connectedDragItems;
644
645 // Add connections to the selection for a drag.
646 // Do all non-labels/entries first so we don't add junctions to drag
647 // when the line will eventually be drag selected.
648 std::vector<SCH_ITEM*> stageTwo;
649
650 for( EDA_ITEM* edaItem : selection )
651 {
652 SCH_ITEM* item = static_cast<SCH_ITEM*>( edaItem );
653 std::vector<VECTOR2I> connections;
654
655 switch( item->Type() )
656 {
657 case SCH_LABEL_T:
658 case SCH_HIER_LABEL_T:
661 stageTwo.emplace_back(item);
662 break;
663
664 case SCH_LINE_T:
665 static_cast<SCH_LINE*>( item )->GetSelectedPoints( connections );
666 break;
667 default:
668 connections = item->GetConnectionPoints();
669 }
670
671 for( const VECTOR2I& point : connections )
672 getConnectedDragItems( aCommit, item, point, connectedDragItems );
673 }
674
675 // Go back and get all label connections now that we can test for drag-selected
676 // lines the labels might be on
677 for( SCH_ITEM* item : stageTwo )
678 {
679 for( const VECTOR2I& point : item->GetConnectionPoints() )
680 getConnectedDragItems( aCommit, item, point, connectedDragItems );
681 }
682
683 for( EDA_ITEM* item : connectedDragItems )
684 {
685 m_dragAdditions.push_back( item->m_Uuid );
686 m_selectionTool->AddItemToSel( item, QUIET_MODE );
687 }
688
689 // Pre-cache all connections of our selected objects so we can keep track of
690 // what they were originally connected to as we drag them around
691 for( EDA_ITEM* edaItem : selection )
692 {
693 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( edaItem );
694
695 if( schItem->Type() == SCH_LINE_T )
696 {
697 SCH_LINE* line = static_cast<SCH_LINE*>( schItem );
698
699 //Also store the original angle of the line, is needed later to decide
700 //which segment to extend when they've become zero length
701 line->StoreAngle();
702
703 for( const VECTOR2I& point : line->GetConnectionPoints() )
704 getConnectedItems( line, point, m_lineConnectionCache[line] );
705 }
706 }
707 }
708 else
709 {
710 // Mark the edges of the block with dangling flags for a move.
711 for( EDA_ITEM* item : selection )
712 static_cast<SCH_ITEM*>( item )->GetEndPoints( internalPoints );
713
714 std::vector<DANGLING_END_ITEM> endPointsByType = internalPoints;
715 std::vector<DANGLING_END_ITEM> endPointsByPos = endPointsByType;
716 DANGLING_END_ITEM_HELPER::sort_dangling_end_items( endPointsByType, endPointsByPos );
717
718 for( EDA_ITEM* item : selection )
719 static_cast<SCH_ITEM*>( item )->UpdateDanglingState( endPointsByType, endPointsByPos );
720 }
721
722 // Hide junctions connected to line endpoints that are not selected
723 m_hiddenJunctions.clear();
724
725 for( EDA_ITEM* edaItem : selection )
726 {
727 if( edaItem->Type() != SCH_LINE_T )
728 continue;
729
730 SCH_LINE* line = static_cast<SCH_LINE*>( edaItem );
731
732 for( const VECTOR2I& pt : line->GetConnectionPoints() )
733 {
734 SCH_JUNCTION* jct = static_cast<SCH_JUNCTION*>( m_frame->GetScreen()->GetItem( pt, 0, SCH_JUNCTION_T ) );
735
736 if( jct && !jct->IsSelected()
737 && std::find( m_hiddenJunctions.begin(), m_hiddenJunctions.end(), jct ) == m_hiddenJunctions.end() )
738 {
739 jct->SetFlags( STRUCT_DELETED );
740 m_frame->RemoveFromScreen( jct, m_frame->GetScreen() );
741 aCommit->Removed( jct, m_frame->GetScreen() );
742 }
743 }
744 }
745
746 // Generic setup
747 snapLayer = grid.GetSelectionGrid( selection );
748
749 for( EDA_ITEM* item : selection )
750 {
751 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
752
753 if( schItem->IsNew() )
754 {
755 // Item was added to commit in a previous command
756
757 // While SCH_COMMIT::Push() will add any new items to the entered group,
758 // we need to do it earlier so that the previews while moving are correct.
759 if( SCH_GROUP* enteredGroup = m_selectionTool->GetEnteredGroup() )
760 {
761 if( schItem->IsGroupableType() && !schItem->GetParentGroup() )
762 {
763 aCommit->Modify( enteredGroup, m_frame->GetScreen(), RECURSE_MODE::NO_RECURSE );
764 enteredGroup->AddItem( schItem );
765 }
766 }
767 }
768 else if( schItem->GetParent() && schItem->GetParent()->IsSelected() )
769 {
770 // Item will be (or has been) added to commit by parent
771 }
772 else
773 {
774 aCommit->Modify( schItem, m_frame->GetScreen(), RECURSE_MODE::RECURSE );
775 }
776
777 schItem->SetFlags( IS_MOVING );
778
779 if( SCH_SHAPE* shape = dynamic_cast<SCH_SHAPE*>( schItem ) )
780 {
781 shape->SetHatchingDirty();
782 shape->UpdateHatching();
783 }
784
785 schItem->RunOnChildren(
786 [&]( SCH_ITEM* schItem )
787 {
788 item->SetFlags( IS_MOVING );
789 },
791
792 schItem->SetStoredPos( schItem->GetPosition() );
793 }
794
795 // Set up the starting position and move/drag offset
796 //
797 m_cursor = controls->GetCursorPosition();
798
800 {
801 wxASSERT_MSG( m_anchorPos, "Should be already set from previous cmd" );
802 }
803 else if( placingNewItems )
804 {
805 m_anchorPos = selection.GetReferencePoint();
806 }
807
808 if( m_anchorPos )
809 {
810 VECTOR2I delta = m_cursor - (*m_anchorPos);
811 bool isPasted = false;
812
813 // Drag items to the current cursor position
814 for( EDA_ITEM* item : selection )
815 {
816 // Don't double move pins, fields, etc.
817 if( item->GetParent() && item->GetParent()->IsSelected() )
818 continue;
819
820 moveItem( item, delta );
821 updateItem( item, false );
822
823 isPasted |= ( item->GetFlags() & IS_PASTED ) != 0;
824 item->ClearFlags( IS_PASTED );
825 }
826
827 // The first time pasted items are moved we need to store the position of the
828 // cursor so that rotate while moving works as expected (instead of around the
829 // original anchor point
830 if( isPasted )
831 selection.SetReferencePoint( m_cursor );
832
834 }
835 // For some items, moving the cursor to anchor is not good (for instance large
836 // hierarchical sheets or symbols can have the anchor outside the view)
837 else if( selection.Size() == 1 && !sch_item->IsMovableFromAnchorPoint() )
838 {
841 }
842 else
843 {
844 if( m_frame->GetMoveWarpsCursor() )
845 {
846 // User wants to warp the mouse
847 m_cursor = grid.BestDragOrigin( m_cursor, snapLayer, selection );
848 selection.SetReferencePoint( m_cursor );
849 }
850 else
851 {
852 // User does not want to warp the mouse
854 }
855 }
856
857 controls->SetCursorPosition( m_cursor, false );
858
859 prevPos = m_cursor;
860 controls->SetAutoPan( true );
861 m_moveInProgress = true;
862
863 refreshSelectionTraits();
864 }
865
866 //------------------------------------------------------------------------
867 // Follow the mouse
868 //
869 m_view->ClearPreview();
870
871 m_cursor = grid.BestSnapAnchor( controls->GetCursorPosition( false ),
872 snapLayer, selection );
873 // Determine potential target sheet.
874 SCH_SHEET* sheet = dynamic_cast<SCH_SHEET*>( m_frame->GetScreen()->GetItem( m_cursor, 0,
875 SCH_SHEET_T ) );
876 if( sheet && sheet->IsSelected() )
877 sheet = nullptr; // Never target a selected sheet
878
879 if( !sheet )
880 {
881 // Build current selection bounding box in its (already moved) position.
882 BOX2I selBBox;
883 for( EDA_ITEM* it : selection )
884 {
885 if( SCH_ITEM* schIt = dynamic_cast<SCH_ITEM*>( it ) )
886 selBBox.Merge( schIt->GetBoundingBox() );
887 }
888
889 if( selBBox.GetWidth() > 0 && selBBox.GetHeight() > 0 )
890 {
891 VECTOR2I selCenter( selBBox.GetX() + selBBox.GetWidth() / 2,
892 selBBox.GetY() + selBBox.GetHeight() / 2 );
893
894 // Find first non-selected sheet whose body fully contains the selection
895 // or at least contains its center point.
896 for( SCH_ITEM* it : m_frame->GetScreen()->Items().OfType( SCH_SHEET_T ) )
897 {
898 SCH_SHEET* candidate = static_cast<SCH_SHEET*>( it );
899 if( candidate->IsSelected() || candidate->IsRootSheet() )
900 continue;
901
902 BOX2I body = candidate->GetBodyBoundingBox();
903
904 if( body.Contains( selBBox ) || body.Contains( selCenter ) )
905 {
906 sheet = candidate;
907 break;
908 }
909 }
910 }
911 }
912
913 bool dropAllowedBySelection = !selectionHasSheetPins;
914 bool dropAllowedByModifiers = !selectionIsGraphicsOnly || ctrlDown;
915
916 if( sheet && !( dropAllowedBySelection && dropAllowedByModifiers ) )
917 sheet = nullptr;
918
919 if( sheet != hoverSheet )
920 {
921 hoverSheet = sheet;
922
923 if( hoverSheet )
924 {
925 hoverSheet->SetFlags( BRIGHTENED );
926 m_frame->UpdateItem( hoverSheet, false );
927 }
928 }
929
930 currentCursor = hoverSheet ? KICURSOR::PLACE : KICURSOR::MOVING;
931
932 if( netCollisionMonitor )
933 currentCursor = netCollisionMonitor->AdjustCursor( currentCursor );
934
935 VECTOR2I delta( m_cursor - prevPos );
937
938 // We need to check if the movement will change the net offset direction on the
939 // X an Y axes. This is because we remerge added bend lines in realtime, and we
940 // also account for the direction of the move when adding bend lines. So, if the
941 // move direction changes, we need to split it into a move that gets us back to
942 // zero, then the rest of the move.
943 std::vector<VECTOR2I> splitMoves;
944
946 {
947 splitMoves.emplace_back( VECTOR2I( -1 * m_moveOffset.x, 0 ) );
948 splitMoves.emplace_back( VECTOR2I( delta.x + m_moveOffset.x, 0 ) );
949 }
950 else
951 {
952 splitMoves.emplace_back( VECTOR2I( delta.x, 0 ) );
953 }
954
956 {
957 splitMoves.emplace_back( VECTOR2I( 0, -1 * m_moveOffset.y ) );
958 splitMoves.emplace_back( VECTOR2I( 0, delta.y + m_moveOffset.y ) );
959 }
960 else
961 {
962 splitMoves.emplace_back( VECTOR2I( 0, delta.y ) );
963 }
964
965
967 prevPos = m_cursor;
968
969 // Used for tracking how far off a drag end should have its 90 degree elbow added
970 int xBendCount = 1;
971 int yBendCount = 1;
972
973 // Split the move into X and Y moves so we can correctly drag orthogonal lines
974 for( const VECTOR2I& splitDelta : splitMoves )
975 {
976 // Skip non-moves
977 if( splitDelta == VECTOR2I( 0, 0 ) )
978 continue;
979
980 for( EDA_ITEM* item : selection.GetItemsSortedByTypeAndXY( ( delta.x >= 0 ),
981 ( delta.y >= 0 ) ) )
982 {
983 // Don't double move pins, fields, etc.
984 if( item->GetParent() && item->GetParent()->IsSelected() )
985 continue;
986
987 SCH_LINE* line = dynamic_cast<SCH_LINE*>( item );
988
989 // Only partially selected drag lines in orthogonal line mode need special
990 // handling
991 if( m_isDrag && isLineModeConstrained
992 && line && line->HasFlag( STARTPOINT ) != line->HasFlag( ENDPOINT ) )
993 {
994 orthoLineDrag( aCommit, line, splitDelta, xBendCount, yBendCount, grid );
995 }
996
997 // Move all other items normally, including the selected end of partially
998 // selected lines
999 moveItem( item, splitDelta );
1000 updateItem( item, false );
1001
1002 // Update any lines connected to sheet pins to the sheet pin's location
1003 // (which may not exactly follow the splitDelta as the pins are constrained
1004 // along the sheet edges.
1005 for( const auto& [pin, lineEnd] : m_specialCaseSheetPins )
1006 {
1007 if( lineEnd.second && lineEnd.first->HasFlag( STARTPOINT ) )
1008 lineEnd.first->SetStartPoint( pin->GetPosition() );
1009 else if( !lineEnd.second && lineEnd.first->HasFlag( ENDPOINT ) )
1010 lineEnd.first->SetEndPoint( pin->GetPosition() );
1011 }
1012 }
1013 }
1014
1015 if( selection.HasReferencePoint() )
1016 selection.SetReferencePoint( selection.GetReferencePoint() + delta );
1017
1018 std::vector<SCH_ITEM*> previewItems;
1019
1020 for( EDA_ITEM* it : selection )
1021 previewItems.push_back( static_cast<SCH_ITEM*>( it ) );
1022
1023 for( SCH_LINE* line : m_newDragLines )
1024 previewItems.push_back( line );
1025
1026 for( SCH_LINE* line : m_changedDragLines )
1027 previewItems.push_back( line );
1028
1029 std::vector<SCH_JUNCTION*> previewJunctions =
1030 JUNCTION_HELPERS::PreviewJunctions( m_frame->GetScreen(), previewItems );
1031
1032 if( netCollisionMonitor )
1033 netCollisionMonitor->Update( previewJunctions, selection );
1034
1035 for( SCH_JUNCTION* jct : previewJunctions )
1036 {
1037 m_view->AddToPreview( jct, true );
1038 }
1039
1041 }
1042
1043 //------------------------------------------------------------------------
1044 // Handle cancel
1045 //
1046 else if( evt->IsCancelInteractive()
1047 || evt->IsActivate()
1048 || evt->IsAction( &ACTIONS::undo ) )
1049 {
1050 if( evt->IsCancelInteractive() )
1051 m_frame->GetInfoBar()->Dismiss();
1052
1053 if( m_moveInProgress )
1054 {
1055 if( evt->IsActivate() )
1056 {
1057 // Allowing other tools to activate during a move runs the risk of race
1058 // conditions in which we try to spool up both event loops at once.
1059
1060 if( m_isDrag )
1061 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel drag." ) );
1062 else
1063 m_frame->ShowInfoBarMsg( _( "Press <ESC> to cancel move." ) );
1064
1065 evt->SetPassEvent( false );
1066 continue;
1067 }
1068
1069 evt->SetPassEvent( false );
1070 restore_state = true;
1071 }
1072
1074
1075 m_view->ClearPreview();
1076
1077 break;
1078 }
1079 //------------------------------------------------------------------------
1080 // Handle TOOL_ACTION special cases
1081 //
1082 else if( evt->IsAction( &ACTIONS::doDelete ) )
1083 {
1084 evt->SetPassEvent();
1085 // Exit on a delete; there will no longer be anything to drag.
1086 break;
1087 }
1088 else if( evt->IsAction( &ACTIONS::duplicate )
1090 || evt->IsAction( &ACTIONS::redo ) )
1091 {
1092 wxBell();
1093 }
1094 else if( evt->IsAction( &SCH_ACTIONS::rotateCW ) )
1095 {
1096 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::rotateCW, aCommit );
1097 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1098 }
1099 else if( evt->IsAction( &SCH_ACTIONS::rotateCCW ) )
1100 {
1101 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::rotateCCW, aCommit );
1102 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1103 }
1104 else if( evt->IsAction( &ACTIONS::increment ) )
1105 {
1106 if( evt->HasParameter() )
1107 m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, evt->Parameter<ACTIONS::INCREMENT>() );
1108 else
1109 m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, ACTIONS::INCREMENT { 1, 0 } );
1110
1111 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1112 }
1113 else if( evt->IsAction( &SCH_ACTIONS::toDLabel ) )
1114 {
1115 m_toolMgr->RunSynchronousAction(SCH_ACTIONS::toDLabel, aCommit );
1116 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1117 }
1118 else if( evt->IsAction( &SCH_ACTIONS::toGLabel ) )
1119 {
1120 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toGLabel, aCommit );
1121 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1122 }
1123 else if( evt->IsAction( &SCH_ACTIONS::toHLabel ) )
1124 {
1125 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toHLabel, aCommit );
1126 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1127 }
1128 else if( evt->IsAction( &SCH_ACTIONS::toLabel ) )
1129 {
1130 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toLabel, aCommit );
1131 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1132 }
1133 else if( evt->IsAction( &SCH_ACTIONS::toText ) )
1134 {
1135 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toText, aCommit );
1136 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1137 }
1138 else if( evt->IsAction( &SCH_ACTIONS::toTextBox ) )
1139 {
1140 m_toolMgr->RunSynchronousAction( SCH_ACTIONS::toTextBox, aCommit );
1141 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1142 }
1143 else if( evt->Action() == TA_CHOICE_MENU_CHOICE )
1144 {
1147 {
1148 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
1149 int unit = *evt->GetCommandId() - ID_POPUP_SCH_SELECT_UNIT;
1150
1151 if( symbol )
1152 {
1153 m_frame->SelectUnit( symbol, unit );
1154 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1155 }
1156 }
1159 {
1160 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( selection.Front() );
1161 int bodyStyle = ( *evt->GetCommandId() - ID_POPUP_SCH_SELECT_BODY_STYLE ) + 1;
1162
1163 if( symbol && symbol->GetBodyStyle() != bodyStyle )
1164 {
1165 m_frame->SelectBodyStyle( symbol, bodyStyle );
1166 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1167 }
1168 }
1169 }
1170 else if( evt->IsAction( &SCH_ACTIONS::highlightNet )
1172 {
1173 // These don't make any sense during a move. Eat them.
1174 }
1175 //------------------------------------------------------------------------
1176 // Handle context menu
1177 //
1178 else if( evt->IsClick( BUT_RIGHT ) )
1179 {
1180 m_menu->ShowContextMenu( m_selectionTool->GetSelection() );
1181 }
1182 //------------------------------------------------------------------------
1183 // Handle drop
1184 //
1185 else if( evt->IsMouseUp( BUT_LEFT )
1186 || evt->IsClick( BUT_LEFT )
1187 || evt->IsDblClick( BUT_LEFT ) )
1188 {
1189 break; // Finish
1190 }
1191 else
1192 {
1193 evt->SetPassEvent();
1194 }
1195
1196 controls->SetAutoPan( m_moveInProgress );
1197
1198 } while( ( evt = Wait() ) ); //Should be assignment not equality test
1199
1200 SCH_SHEET* targetSheet = hoverSheet;
1201
1202 if( selectionHasSheetPins || ( selectionIsGraphicsOnly && !lastCtrlDown ) )
1203 targetSheet = nullptr;
1204
1205 if( hoverSheet )
1206 {
1207 hoverSheet->ClearFlags( BRIGHTENED );
1208 m_frame->UpdateItem( hoverSheet, false );
1209 }
1210
1211 if( targetSheet )
1212 {
1213 moveSelectionToSheet( selection, targetSheet, aCommit );
1214 m_toolMgr->RunAction( ACTIONS::selectionClear );
1215 m_newDragLines.clear();
1216 m_changedDragLines.clear();
1217 }
1218
1219 // Create a selection of original selection, drag selected/changed items, and new
1220 // bend lines for later before we clear them in the aCommit. We'll need these
1221 // to check for new junctions needed, etc.
1222 SCH_SELECTION selectionCopy( selection );
1223
1224 for( SCH_LINE* line : m_newDragLines )
1225 selectionCopy.Add( line );
1226
1227 for( SCH_LINE* line : m_changedDragLines )
1228 selectionCopy.Add( line );
1229
1230 // Save whatever new bend lines and changed lines survived the drag
1231 for( SCH_LINE* newLine : m_newDragLines )
1232 {
1233 newLine->ClearEditFlags();
1234 aCommit->Added( newLine, m_frame->GetScreen() );
1235 }
1236
1237 // These lines have been changed, but aren't selected. We need
1238 // to manually clear these edit flags or they'll stick around.
1239 for( SCH_LINE* oldLine : m_changedDragLines )
1240 oldLine->ClearEditFlags();
1241
1242 m_newDragLines.clear();
1243 m_changedDragLines.clear();
1244
1245 controls->ForceCursorPosition( false );
1246 controls->ShowCursor( false );
1247 controls->SetAutoPan( false );
1248
1249 m_moveOffset = { 0, 0 };
1250 m_anchorPos.reset();
1251
1252 if( restore_state )
1253 {
1254 m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
1255 }
1256 else
1257 {
1258 // One last update after exiting loop (for slower stuff, such as updating SCREEN's RTree).
1259 for( EDA_ITEM* item : selection )
1260 {
1261 updateItem( item, true );
1262
1263 if( SCH_ITEM* sch_item = dynamic_cast<SCH_ITEM*>( item ) )
1264 sch_item->SetConnectivityDirty( true );
1265 }
1266
1267 if( selection.GetSize() == 1 && selection.Front()->IsNew() )
1268 m_frame->SaveCopyForRepeatItem( static_cast<SCH_ITEM*>( selection.Front() ) );
1269
1270 m_selectionTool->RemoveItemsFromSel( &m_dragAdditions, QUIET_MODE );
1271
1273
1274 // If we move items away from a junction, we _may_ want to add a junction there
1275 // to denote the state.
1276 for( const DANGLING_END_ITEM& it : internalPoints )
1277 {
1278 if( m_frame->GetScreen()->IsExplicitJunctionNeeded( it.GetPosition()) )
1279 lwbTool->AddJunction( aCommit, m_frame->GetScreen(), it.GetPosition() );
1280 }
1281
1282 lwbTool->TrimOverLappingWires( aCommit, &selectionCopy );
1283 lwbTool->AddJunctionsIfNeeded( aCommit, &selectionCopy );
1284
1285 // This needs to run prior to `RecalculateConnections` because we need to identify
1286 // the lines that are newly dangling
1287 if( m_isDrag && !aIsSlice )
1288 trimDanglingLines( aCommit );
1289
1290 // Auto-rotate any moved labels
1291 for( EDA_ITEM* item : selection )
1292 m_frame->AutoRotateItem( m_frame->GetScreen(), static_cast<SCH_ITEM*>( item ) );
1293
1294 m_frame->Schematic().CleanUp( aCommit );
1295 }
1296
1297 for( EDA_ITEM* item : m_frame->GetScreen()->Items() )
1298 item->ClearEditFlags();
1299
1300 // ensure any selected item not in screen main list (for instance symbol fields)
1301 // has its edit flags cleared
1302 for( EDA_ITEM* item : selectionCopy )
1303 item->ClearEditFlags();
1304
1305 if( unselect )
1306 m_toolMgr->RunAction( ACTIONS::selectionClear );
1307 else
1308 m_selectionTool->RebuildSelection(); // Schematic cleanup might have merged lines, etc.
1309
1310 m_dragAdditions.clear();
1311 m_lineConnectionCache.clear();
1312 m_moveInProgress = false;
1313
1314 m_hiddenJunctions.clear();
1315 m_view->ClearPreview();
1316 m_frame->PopTool( aEvent );
1317
1318 return !restore_state;
1319}
1320
1321
1323 SCH_COMMIT* aCommit )
1324{
1325 SCH_SCREEN* destScreen = aTargetSheet->GetScreen();
1326 SCH_SCREEN* srcScreen = m_frame->GetScreen();
1327
1328 BOX2I bbox;
1329
1330 for( EDA_ITEM* item : aSelection )
1331 bbox.Merge( static_cast<SCH_ITEM*>( item )->GetBoundingBox() );
1332
1333 VECTOR2I offset = VECTOR2I( 0, 0 ) - bbox.GetPosition();
1334 int step = schIUScale.MilsToIU( 50 );
1335 bool overlap = false;
1336
1337 do
1338 {
1339 BOX2I moved = bbox;
1340 moved.Move( offset );
1341 overlap = false;
1342
1343 for( SCH_ITEM* existing : destScreen->Items() )
1344 {
1345 if( moved.Intersects( existing->GetBoundingBox() ) )
1346 {
1347 overlap = true;
1348 break;
1349 }
1350 }
1351
1352 if( overlap )
1353 offset += VECTOR2I( step, step );
1354 } while( overlap );
1355
1356 for( EDA_ITEM* item : aSelection )
1357 {
1358 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
1359
1360 // Remove from current screen and view manually
1361 m_frame->RemoveFromScreen( schItem, srcScreen );
1362
1363 // Move the item
1364 schItem->Move( offset );
1365
1366 // Add to destination screen manually (won't add to view since it's not current)
1367 destScreen->Append( schItem );
1368
1369 // Record in commit with CHT_DONE flag to bypass automatic screen/view operations
1370 aCommit->Stage( schItem, CHT_REMOVE | CHT_DONE, srcScreen );
1371 aCommit->Stage( schItem, CHT_ADD | CHT_DONE, destScreen );
1372 }
1373}
1374
1375
1377{
1378 // Need a local cleanup first to ensure we remove unneeded junctions
1379 m_frame->Schematic().CleanUp( aCommit, m_frame->GetScreen() );
1380
1381 std::set<SCH_ITEM*> danglers;
1382
1383 std::function<void( SCH_ITEM* )> changeHandler =
1384 [&]( SCH_ITEM* aChangedItem ) -> void
1385 {
1386 m_toolMgr->GetView()->Update( aChangedItem, KIGFX::REPAINT );
1387
1388 // Delete newly dangling lines:
1389 // Find split segments (one segment is new, the other is changed) that
1390 // we aren't dragging and don't have selected
1391 if( aChangedItem->HasFlag( IS_BROKEN) && aChangedItem->IsDangling()
1392 && !aChangedItem->IsSelected() )
1393 {
1394 danglers.insert( aChangedItem );
1395 }
1396 };
1397
1398 m_frame->GetScreen()->TestDanglingEnds( nullptr, &changeHandler );
1399
1400 for( SCH_ITEM* line : danglers )
1401 {
1402 line->SetFlags( STRUCT_DELETED );
1403 aCommit->Removed( line, m_frame->GetScreen() );
1404 updateItem( line, false ); // Update any cached visuals before commit processes
1405 m_frame->RemoveFromScreen( line, m_frame->GetScreen() );
1406 }
1407}
1408
1409
1410void SCH_MOVE_TOOL::getConnectedItems( SCH_ITEM* aOriginalItem, const VECTOR2I& aPoint,
1411 EDA_ITEMS& aList )
1412{
1413 EE_RTREE& items = m_frame->GetScreen()->Items();
1414 EE_RTREE::EE_TYPE itemsOverlapping = items.Overlapping( aOriginalItem->GetBoundingBox() );
1415 SCH_ITEM* foundJunction = nullptr;
1416 SCH_ITEM* foundSymbol = nullptr;
1417
1418 // If you're connected to a junction, you're only connected to the junction.
1419 //
1420 // But, if you're connected to a junction on a pin, you're only connected to the pin. This
1421 // is because junctions and pins have different logic for how bend lines are generated and
1422 // we need to prioritize the pin version in some cases.
1423 for( SCH_ITEM* item : itemsOverlapping )
1424 {
1425 if( item != aOriginalItem && item->IsConnected( aPoint ) )
1426 {
1427 if( item->Type() == SCH_JUNCTION_T )
1428 foundJunction = item;
1429 else if( item->Type() == SCH_SYMBOL_T )
1430 foundSymbol = item;
1431 }
1432 }
1433
1434 if( foundSymbol && foundJunction )
1435 {
1436 aList.push_back( foundSymbol );
1437 return;
1438 }
1439
1440 if( foundJunction )
1441 {
1442 aList.push_back( foundJunction );
1443 return;
1444 }
1445
1446
1447 for( SCH_ITEM* test : itemsOverlapping )
1448 {
1449 if( test == aOriginalItem || !test->CanConnect( aOriginalItem ) )
1450 continue;
1451
1452 switch( test->Type() )
1453 {
1454 case SCH_LINE_T:
1455 {
1456 SCH_LINE* line = static_cast<SCH_LINE*>( test );
1457
1458 // When getting lines for the connection cache, it's important that we only add
1459 // items at the unselected end, since that is the only end that is handled specially.
1460 // Fully selected lines, and the selected end of a partially selected line, are moved
1461 // around normally and don't care about their connections.
1462 if( ( line->HasFlag( STARTPOINT ) && aPoint == line->GetStartPoint() )
1463 || ( line->HasFlag( ENDPOINT ) && aPoint == line->GetEndPoint() ) )
1464 {
1465 continue;
1466 }
1467
1468 if( test->IsConnected( aPoint ) )
1469 aList.push_back( test );
1470
1471 // Labels can connect to a wire (or bus) anywhere along the length
1472 if( SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( aOriginalItem ) )
1473 {
1474 if( static_cast<SCH_LINE*>( test )->HitTest( label->GetPosition(), 1 ) )
1475 aList.push_back( test );
1476 }
1477
1478 break;
1479 }
1480
1481 case SCH_SHEET_T:
1482 if( aOriginalItem->Type() == SCH_LINE_T )
1483 {
1484 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1485
1486 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
1487 {
1488 if( pin->IsConnected( aPoint ) )
1489 {
1490 if( pin->IsSelected() )
1491 m_specialCaseSheetPins[pin] = { line, line->GetStartPoint() == aPoint };
1492
1493 aList.push_back( pin );
1494 }
1495 }
1496 }
1497
1498 break;
1499
1500 case SCH_SYMBOL_T:
1501 case SCH_JUNCTION_T:
1502 case SCH_NO_CONNECT_T:
1503 if( test->IsConnected( aPoint ) )
1504 aList.push_back( test );
1505
1506 break;
1507
1508 case SCH_LABEL_T:
1509 case SCH_GLOBAL_LABEL_T:
1510 case SCH_HIER_LABEL_T:
1512 // Labels can connect to a wire (or bus) anywhere along the length
1513 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
1514 {
1515 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
1516 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1517
1518 if( line->HitTest( label->GetPosition(), 1 ) )
1519 aList.push_back( label );
1520 }
1521
1522 break;
1523
1526 if( aOriginalItem->Type() == SCH_LINE_T && test->CanConnect( aOriginalItem ) )
1527 {
1528 SCH_TEXT* label = static_cast<SCH_TEXT*>( test );
1529 SCH_LINE* line = static_cast<SCH_LINE*>( aOriginalItem );
1530
1531 if( line->HitTest( aPoint, 1 ) )
1532 aList.push_back( label );
1533 }
1534
1535 break;
1536
1537 default:
1538 break;
1539 }
1540 }
1541}
1542
1543
1545 const VECTOR2I& aPoint, EDA_ITEMS& aList )
1546{
1547 EE_RTREE& items = m_frame->GetScreen()->Items();
1548 EE_RTREE::EE_TYPE itemsOverlappingRTree = items.Overlapping( aSelectedItem->GetBoundingBox() );
1549 std::vector<SCH_ITEM*> itemsConnectable;
1550 bool ptHasUnselectedJunction = false;
1551
1552 auto makeNewWire =
1553 [this]( SCH_COMMIT* commit, SCH_ITEM* fixed, SCH_ITEM* selected, const VECTOR2I& start,
1554 const VECTOR2I& end )
1555 {
1556 SCH_LINE* newWire;
1557
1558 // Add a new newWire between the fixed item and the selected item so the selected
1559 // item can be dragged.
1560 if( fixed->GetLayer() == LAYER_BUS_JUNCTION || fixed->GetLayer() == LAYER_BUS
1561 || selected->GetLayer() == LAYER_BUS )
1562 {
1563 newWire = new SCH_LINE( start, LAYER_BUS );
1564 }
1565 else
1566 {
1567 newWire = new SCH_LINE( start, LAYER_WIRE );
1568 }
1569
1570 newWire->SetFlags( IS_NEW );
1571 newWire->SetConnectivityDirty( true );
1572
1573 SCH_LINE* selectedLine = dynamic_cast<SCH_LINE*>( selected );
1574 SCH_LINE* fixedLine = dynamic_cast<SCH_LINE*>( fixed );
1575
1576 if( selectedLine )
1577 {
1578 newWire->SetLastResolvedState( selected );
1579 cloneWireConnection( newWire, selectedLine, m_frame );
1580 }
1581 else if( fixedLine )
1582 {
1583 newWire->SetLastResolvedState( fixed );
1584 cloneWireConnection( newWire, fixedLine, m_frame );
1585 }
1586
1587 newWire->SetEndPoint( end );
1588 m_frame->AddToScreen( newWire, m_frame->GetScreen() );
1589 commit->Added( newWire, m_frame->GetScreen() );
1590
1591 return newWire;
1592 };
1593
1594 auto makeNewJunction =
1595 [this]( SCH_COMMIT* commit, SCH_LINE* line, const VECTOR2I& pt )
1596 {
1597 SCH_JUNCTION* junction = new SCH_JUNCTION( pt );
1598 junction->SetFlags( IS_NEW );
1599 junction->SetConnectivityDirty( true );
1600 junction->SetLastResolvedState( line );
1601
1602 if( line->IsBus() )
1603 junction->SetLayer( LAYER_BUS_JUNCTION );
1604
1605 m_frame->AddToScreen( junction, m_frame->GetScreen() );
1606 commit->Added( junction, m_frame->GetScreen() );
1607
1608 return junction;
1609 };
1610
1611 for( SCH_ITEM* item : itemsOverlappingRTree )
1612 {
1613 if( item->Type() == SCH_SHEET_T )
1614 {
1615 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
1616
1617 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
1618 {
1619 if( !pin->IsSelected()
1620 && pin->GetPosition() == aSelectedItem->GetPosition()
1621 && pin->CanConnect( aSelectedItem ) )
1622 {
1623 itemsConnectable.push_back( pin );
1624 }
1625 }
1626
1627 continue;
1628 }
1629
1630 // Skip ourselves, skip already selected items (but not lines, they need both ends tested)
1631 // and skip unconnectable items
1632 if( item == aSelectedItem
1633 || ( item->Type() != SCH_LINE_T && item->IsSelected() )
1634 || !item->CanConnect( aSelectedItem ) )
1635 {
1636 continue;
1637 }
1638
1639 itemsConnectable.push_back( item );
1640 }
1641
1642 for( SCH_ITEM* item : itemsConnectable )
1643 {
1644 if( item->Type() == SCH_JUNCTION_T && item->IsConnected( aPoint ) && !item->IsSelected() )
1645 {
1646 ptHasUnselectedJunction = true;
1647 break;
1648 }
1649 }
1650
1651 SCH_LINE* newWire = nullptr;
1652
1653 for( SCH_ITEM* test : itemsConnectable )
1654 {
1655 KICAD_T testType = test->Type();
1656
1657 switch( testType )
1658 {
1659 case SCH_LINE_T:
1660 {
1661 // Select the connected end of wires/bus connections that don't have an unselected
1662 // junction isolating them from the drag
1663 if( ptHasUnselectedJunction )
1664 break;
1665
1666 SCH_LINE* line = static_cast<SCH_LINE*>( test );
1667
1668 if( line->GetStartPoint() == aPoint )
1669 {
1670 // It's possible to manually select one end of a line and get a drag
1671 // connected other end, so we set the flag and then early exit the loop
1672 // later if the other drag items like labels attached to the line have
1673 // already been grabbed during the partial selection process.
1674 line->SetFlags( STARTPOINT );
1675
1676 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG ) )
1677 {
1678 continue;
1679 }
1680 else
1681 {
1682 line->SetFlags( SELECTED_BY_DRAG );
1683 aList.push_back( line );
1684 }
1685 }
1686 else if( line->GetEndPoint() == aPoint )
1687 {
1688 line->SetFlags( ENDPOINT );
1689
1690 if( line->HasFlag( SELECTED ) || line->HasFlag( SELECTED_BY_DRAG ) )
1691 {
1692 continue;
1693 }
1694 else
1695 {
1696 line->SetFlags( SELECTED_BY_DRAG );
1697 aList.push_back( line );
1698 }
1699 }
1700 else
1701 {
1702 switch( aSelectedItem->Type() )
1703 {
1704 // These items can connect anywhere along a line
1707 case SCH_LABEL_T:
1708 case SCH_HIER_LABEL_T:
1709 case SCH_GLOBAL_LABEL_T:
1711 // Only add a line if this line is unselected; if the label and line are both
1712 // selected they'll move together
1713 if( line->HitTest( aPoint, 1 ) && !line->HasFlag( SELECTED )
1714 && !line->HasFlag( SELECTED_BY_DRAG ) )
1715 {
1716 newWire = makeNewWire( aCommit, line, aSelectedItem, aPoint, aPoint );
1717 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1718 newWire->StoreAngle( ( line->Angle() + ANGLE_90 ).Normalize() );
1719 aList.push_back( newWire );
1720
1721 if( aPoint != line->GetStartPoint() && aPoint != line->GetEndPoint() )
1722 {
1723 // Split line in half
1724 aCommit->Modify( line, m_frame->GetScreen() );
1725
1726 VECTOR2I oldEnd = line->GetEndPoint();
1727 line->SetEndPoint( aPoint );
1728
1729 makeNewWire( aCommit, line, line, aPoint, oldEnd );
1730 makeNewJunction( aCommit, line, aPoint );
1731 }
1732 else
1733 {
1734 m_lineConnectionCache[ newWire ] = { line };
1735 m_lineConnectionCache[ line ] = { newWire };
1736 }
1737 }
1738 break;
1739
1740 default:
1741 break;
1742 }
1743
1744 break;
1745 }
1746
1747 // Since only one end is going to move, the movement vector of any labels attached to
1748 // it is scaled by the proportion of the line length the label is from the moving end.
1749 for( SCH_ITEM* item : items.Overlapping( line->GetBoundingBox() ) )
1750 {
1751 SCH_LABEL_BASE* label = dynamic_cast<SCH_LABEL_BASE*>( item );
1752
1753 if( !label || label->IsSelected() )
1754 continue; // These will be moved on their own because they're selected
1755
1756 if( label->HasFlag( SELECTED_BY_DRAG ) )
1757 continue;
1758
1759 if( label->CanConnect( line ) && line->HitTest( label->GetPosition(), 1 ) )
1760 {
1761 label->SetFlags( SELECTED_BY_DRAG );
1762 aList.push_back( label );
1763
1765 info.attachedLine = line;
1766 info.originalLabelPos = label->GetPosition();
1767 m_specialCaseLabels[label] = info;
1768 }
1769 }
1770
1771 break;
1772 }
1773
1774 case SCH_SHEET_T:
1775 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( test )->GetPins() )
1776 {
1777 if( pin->IsConnected( aPoint ) )
1778 {
1779 if( pin->IsSelected() && aSelectedItem->Type() == SCH_LINE_T )
1780 {
1781 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1782 m_specialCaseSheetPins[ pin ] = { line, line->GetStartPoint() == aPoint };
1783 }
1784 else if( !newWire )
1785 {
1786 // Add a new wire between the sheetpin and the selected item so the
1787 // selected item can be dragged.
1788 newWire = makeNewWire( aCommit, pin, aSelectedItem, aPoint, aPoint );
1789 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1790 aList.push_back( newWire );
1791 }
1792 }
1793 }
1794
1795 break;
1796
1797 case SCH_SYMBOL_T:
1798 case SCH_JUNCTION_T:
1799 if( test->IsConnected( aPoint ) && !newWire )
1800 {
1801 // Add a new wire between the symbol or junction and the selected item so
1802 // the selected item can be dragged.
1803 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
1804 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1805 aList.push_back( newWire );
1806 }
1807
1808 break;
1809
1810 case SCH_NO_CONNECT_T:
1811 // Select no-connects that are connected to items being moved.
1812 if( !test->HasFlag( SELECTED_BY_DRAG ) && test->IsConnected( aPoint ) )
1813 {
1814 aList.push_back( test );
1815 test->SetFlags( SELECTED_BY_DRAG );
1816 }
1817
1818 break;
1819
1820 case SCH_LABEL_T:
1821 case SCH_GLOBAL_LABEL_T:
1822 case SCH_HIER_LABEL_T:
1824 case SCH_SHEET_PIN_T:
1825 // Performance optimization:
1826 if( test->HasFlag( SELECTED_BY_DRAG ) )
1827 break;
1828
1829 // Select labels that are connected to a wire (or bus) being moved.
1830 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
1831 {
1832 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( test );
1833 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1834
1835 bool oneEndFixed = !line->HasFlag( STARTPOINT ) || !line->HasFlag( ENDPOINT );
1836
1837 if( line->HitTest( label->GetTextPos(), 1 ) )
1838 {
1839 if( ( !line->HasFlag( STARTPOINT ) && label->GetPosition() == line->GetStartPoint() )
1840 || ( !line->HasFlag( ENDPOINT ) && label->GetPosition() == line->GetEndPoint() ) )
1841 {
1842 //If we have a line selected at only one end, don't grab labels
1843 //connected directly to the unselected endpoint
1844 break;
1845 }
1846 else
1847 {
1848 label->SetFlags( SELECTED_BY_DRAG );
1849 aList.push_back( label );
1850
1851 if( oneEndFixed )
1852 {
1854 info.attachedLine = line;
1855 info.originalLabelPos = label->GetPosition();
1856 m_specialCaseLabels[label] = info;
1857 }
1858 }
1859 }
1860 }
1861 else if( test->IsConnected( aPoint ) && !newWire )
1862 {
1863 // Add a new wire between the label and the selected item so the selected item
1864 // can be dragged.
1865 newWire = makeNewWire( aCommit, test, aSelectedItem, aPoint, aPoint );
1866 newWire->SetFlags( SELECTED_BY_DRAG | STARTPOINT );
1867 aList.push_back( newWire );
1868 }
1869
1870 break;
1871
1874 // Performance optimization:
1875 if( test->HasFlag( SELECTED_BY_DRAG ) )
1876 break;
1877
1878 // Select bus entries that are connected to a bus being moved.
1879 if( aSelectedItem->Type() == SCH_LINE_T && test->CanConnect( aSelectedItem ) )
1880 {
1881 SCH_LINE* line = static_cast<SCH_LINE*>( aSelectedItem );
1882
1883 if( ( !line->HasFlag( STARTPOINT ) && test->IsConnected( line->GetStartPoint() ) )
1884 || ( !line->HasFlag( ENDPOINT ) && test->IsConnected( line->GetEndPoint() ) ) )
1885 {
1886 // If we have a line selected at only one end, don't grab bus entries
1887 // connected directly to the unselected endpoint
1888 continue;
1889 }
1890
1891 for( VECTOR2I& point : test->GetConnectionPoints() )
1892 {
1893 if( line->HitTest( point, 1 ) )
1894 {
1895 test->SetFlags( SELECTED_BY_DRAG );
1896 aList.push_back( test );
1897
1898 // A bus entry needs its wire & label as well
1899 std::vector<VECTOR2I> ends = test->GetConnectionPoints();
1900 VECTOR2I otherEnd;
1901
1902 if( ends[0] == point )
1903 otherEnd = ends[1];
1904 else
1905 otherEnd = ends[0];
1906
1907 getConnectedDragItems( aCommit, test, otherEnd, aList );
1908
1909 // No need to test the other end of the bus entry
1910 break;
1911 }
1912 }
1913 }
1914
1915 break;
1916
1917 default:
1918 break;
1919 }
1920 }
1921}
1922
1923
1924void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
1925{
1926 switch( aItem->Type() )
1927 {
1928 case SCH_LINE_T:
1929 {
1930 SCH_LINE* line = static_cast<SCH_LINE*>( aItem );
1931
1932 if( aItem->HasFlag( STARTPOINT ) || !m_isDrag )
1933 line->MoveStart( aDelta );
1934
1935 if( aItem->HasFlag( ENDPOINT ) || !m_isDrag )
1936 line->MoveEnd( aDelta );
1937
1938 break;
1939 }
1940
1941 case SCH_PIN_T:
1942 case SCH_FIELD_T:
1943 {
1944 SCH_ITEM* parent = (SCH_ITEM*) aItem->GetParent();
1945 VECTOR2I delta( aDelta );
1946
1947 if( parent && parent->Type() == SCH_SYMBOL_T )
1948 {
1949 SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem->GetParent();
1950 TRANSFORM transform = symbol->GetTransform().InverseTransform();
1951
1952 delta = transform.TransformCoordinate( delta );
1953 }
1954
1955 static_cast<SCH_ITEM*>( aItem )->Move( delta );
1956
1957 // If we're moving a field with respect to its parent then it's no longer auto-placed
1958 if( aItem->Type() == SCH_FIELD_T && parent && !parent->IsSelected() )
1960
1961 break;
1962 }
1963
1964 case SCH_SHEET_PIN_T:
1965 {
1966 SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) aItem;
1967
1968 pin->SetStoredPos( pin->GetStoredPos() + aDelta );
1969 pin->ConstrainOnEdge( pin->GetStoredPos(), true );
1970 break;
1971 }
1972
1973 case SCH_LABEL_T:
1975 case SCH_GLOBAL_LABEL_T:
1976 case SCH_HIER_LABEL_T:
1977 {
1978 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( aItem );
1979
1980 if( m_specialCaseLabels.count( label ) )
1981 {
1983 SEG currentLine( info.attachedLine->GetStartPoint(), info.attachedLine->GetEndPoint() );
1984 label->SetPosition( currentLine.NearestPoint( info.originalLabelPos ) );
1985 }
1986 else
1987 {
1988 label->Move( aDelta );
1989 }
1990
1991 break;
1992 }
1993
1994 default:
1995 static_cast<SCH_ITEM*>( aItem )->Move( aDelta );
1996 break;
1997 }
1998
1999 aItem->SetFlags( IS_MOVING );
2000}
2001
2002
2004{
2006 SCH_SELECTION& selection = m_selectionTool->RequestSelection( SCH_COLLECTOR::MovableItems );
2007 GRID_HELPER_GRIDS selectionGrid = grid.GetSelectionGrid( selection );
2008 SCH_COMMIT commit( m_toolMgr );
2009
2010 auto doMoveItem =
2011 [&]( EDA_ITEM* item, const VECTOR2I& delta )
2012 {
2013 commit.Modify( item, m_frame->GetScreen(), RECURSE_MODE::RECURSE );
2014
2015 // Ensure only one end is moved when calling moveItem
2016 // i.e. we are in drag mode
2017 bool tmp_isDrag = m_isDrag;
2018 m_isDrag = true;
2019 moveItem( item, delta );
2020 m_isDrag = tmp_isDrag;
2021
2022 item->ClearFlags( IS_MOVING );
2023 updateItem( item, true );
2024 };
2025
2026 for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
2027 {
2028 if( !it->IsSelected() )
2029 it->ClearFlags( STARTPOINT | ENDPOINT );
2030
2031 if( !selection.IsHover() && it->IsSelected() )
2032 it->SetFlags( STARTPOINT | ENDPOINT );
2033
2034 it->SetStoredPos( it->GetPosition() );
2035
2036 if( it->Type() == SCH_SHEET_T )
2037 {
2038 for( SCH_SHEET_PIN* pin : static_cast<SCH_SHEET*>( it )->GetPins() )
2039 pin->SetStoredPos( pin->GetPosition() );
2040 }
2041 }
2042
2043 for( EDA_ITEM* item : selection )
2044 {
2045 if( item->Type() == SCH_LINE_T )
2046 {
2047 SCH_LINE* line = static_cast<SCH_LINE*>( item );
2048 std::vector<int> flags{ STARTPOINT, ENDPOINT };
2049 std::vector<VECTOR2I> pts{ line->GetStartPoint(), line->GetEndPoint() };
2050
2051 for( int ii = 0; ii < 2; ++ii )
2052 {
2053 EDA_ITEMS drag_items{ item };
2054 line->ClearFlags();
2055 line->SetFlags( SELECTED );
2056 line->SetFlags( flags[ii] );
2057 getConnectedDragItems( &commit, line, pts[ii], drag_items );
2058 std::set<EDA_ITEM*> unique_items( drag_items.begin(), drag_items.end() );
2059
2060 VECTOR2I delta = grid.AlignGrid( pts[ii], selectionGrid ) - pts[ii];
2061
2062 if( delta != VECTOR2I( 0, 0 ) )
2063 {
2064 for( EDA_ITEM* dragItem : unique_items )
2065 {
2066 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
2067 continue;
2068
2069 doMoveItem( dragItem, delta );
2070 }
2071 }
2072 }
2073 }
2074 else if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TEXT_T )
2075 {
2076 VECTOR2I delta = grid.AlignGrid( item->GetPosition(), selectionGrid ) - item->GetPosition();
2077
2078 if( delta != VECTOR2I( 0, 0 ) )
2079 doMoveItem( item, delta );
2080 }
2081 else if( item->Type() == SCH_SHEET_T )
2082 {
2083 SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
2084 VECTOR2I topLeft = sheet->GetPosition();
2085 VECTOR2I bottomRight = topLeft + sheet->GetSize();
2086 VECTOR2I tl_delta = grid.AlignGrid( topLeft, selectionGrid ) - topLeft;
2087 VECTOR2I br_delta = grid.AlignGrid( bottomRight, selectionGrid ) - bottomRight;
2088
2089 if( tl_delta != VECTOR2I( 0, 0 ) || br_delta != VECTOR2I( 0, 0 ) )
2090 {
2091 doMoveItem( sheet, tl_delta );
2092
2093 VECTOR2I newSize = (VECTOR2I) sheet->GetSize() - tl_delta + br_delta;
2094 sheet->SetSize( VECTOR2I( newSize.x, newSize.y ) );
2095 updateItem( sheet, true );
2096 }
2097
2098 for( SCH_SHEET_PIN* pin : sheet->GetPins() )
2099 {
2100 VECTOR2I newPos;
2101
2102 if( pin->GetSide() == SHEET_SIDE::TOP || pin->GetSide() == SHEET_SIDE::LEFT )
2103 newPos = pin->GetPosition() + tl_delta;
2104 else
2105 newPos = pin->GetPosition() + br_delta;
2106
2107 VECTOR2I delta = grid.AlignGrid( newPos - pin->GetPosition(), selectionGrid );
2108
2109 if( delta != VECTOR2I( 0, 0 ) )
2110 {
2111 EDA_ITEMS drag_items;
2112 getConnectedDragItems( &commit, pin, pin->GetConnectionPoints()[0],
2113 drag_items );
2114
2115 doMoveItem( pin, delta );
2116
2117 for( EDA_ITEM* dragItem : drag_items )
2118 {
2119 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
2120 continue;
2121
2122 doMoveItem( dragItem, delta );
2123 }
2124 }
2125 }
2126 }
2127 else
2128 {
2129 SCH_ITEM* schItem = static_cast<SCH_ITEM*>( item );
2130 std::vector<VECTOR2I> connections = schItem->GetConnectionPoints();
2131 EDA_ITEMS drag_items;
2132
2133 for( const VECTOR2I& point : connections )
2134 getConnectedDragItems( &commit, schItem, point, drag_items );
2135
2136 std::map<VECTOR2I, int> shifts;
2137 VECTOR2I most_common( 0, 0 );
2138 int max_count = 0;
2139
2140 for( const VECTOR2I& conn : connections )
2141 {
2142 VECTOR2I gridpt = grid.AlignGrid( conn, selectionGrid ) - conn;
2143
2144 shifts[gridpt]++;
2145
2146 if( shifts[gridpt] > max_count )
2147 {
2148 most_common = gridpt;
2149 max_count = shifts[most_common];
2150 }
2151 }
2152
2153 if( most_common != VECTOR2I( 0, 0 ) )
2154 {
2155 doMoveItem( item, most_common );
2156
2157 for( EDA_ITEM* dragItem : drag_items )
2158 {
2159 if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
2160 continue;
2161
2162 doMoveItem( dragItem, most_common );
2163 }
2164 }
2165 }
2166 }
2167
2169 lwbTool->TrimOverLappingWires( &commit, &selection );
2170 lwbTool->AddJunctionsIfNeeded( &commit, &selection );
2171
2173
2174 m_frame->Schematic().CleanUp( &commit );
2175 commit.Push( _( "Align Items to Grid" ) );
2176 return 0;
2177}
2178
2179
2181{
2182 // Remove new bend lines added during the drag
2183 for( SCH_LINE* newLine : m_newDragLines )
2184 {
2185 m_frame->RemoveFromScreen( newLine, m_frame->GetScreen() );
2186 delete newLine;
2187 }
2188
2189 m_newDragLines.clear();
2190}
2191
2192
2199
2200
constexpr EDA_IU_SCALE schIUScale
Definition base_units.h:114
BOX2< VECTOR2I > BOX2I
Definition box2.h:922
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:179
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:223
static TOOL_ACTION refreshPreview
Definition actions.h:158
constexpr const Vec & GetPosition() const
Definition box2.h:211
constexpr coord_type GetY() const
Definition box2.h:208
constexpr size_type GetWidth() const
Definition box2.h:214
constexpr coord_type GetX() const
Definition box2.h:207
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:658
constexpr size_type GetHeight() const
Definition box2.h:215
constexpr bool Contains(const Vec &aPoint) const
Definition box2.h:168
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition commit.h:84
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
COMMIT & Removed(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Definition commit.h:96
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
static void sort_dangling_end_items(std::vector< DANGLING_END_ITEM > &aItemListByType, std::vector< DANGLING_END_ITEM > &aItemListByPos)
Both contain the same information.
Definition sch_item.cpp:825
Helper class used to store the state of schematic items that can be connected to other schematic item...
Definition sch_item.h:96
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:273
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:356
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.
static TOOL_ACTION rotateCCW
static TOOL_ACTION toText
static TOOL_ACTION restartMove
static TOOL_ACTION toHLabel
static TOOL_ACTION rotateCW
static TOOL_ACTION drag
static TOOL_ACTION toLabel
static TOOL_ACTION alignToGrid
static TOOL_ACTION toDLabel
static TOOL_ACTION toTextBox
static TOOL_ACTION highlightNet
static TOOL_ACTION repeatDrawItem
static TOOL_ACTION toGLabel
static TOOL_ACTION selectOnPCB
static TOOL_ACTION move
static const std::vector< KICAD_T > MovableItems
COMMIT & Stage(EDA_ITEM *aItem, CHANGE_TYPE aChangeType, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE) override
Add a change of the item aItem of type aChangeType to the change list.
virtual void Push(const wxString &aMessage=wxT("A commit"), int aCommitFlags=0) override
Execute the changes.
virtual void Revert() override
Revert the commit by restoring the modified items state.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
void Clone(const SCH_CONNECTION &aOther)
Copies connectivity information (but not parent) from another connection.
Schematic editor (Eeschema) main window.
SCH_SHEET_PATH & GetCurrentSheet() const
A set of SCH_ITEMs (i.e., without duplicates).
Definition sch_group.h:52
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
void SetStoredPos(const VECTOR2I &aPos)
Definition sch_item.h:292
virtual bool CanConnect(const SCH_ITEM *aItem) const
Definition sch_item.h:500
virtual void RunOnChildren(const std::function< void(SCH_ITEM *)> &aFunction, RECURSE_MODE aMode)
Definition sch_item.h:609
int GetBodyStyle() const
Definition sch_item.h:247
SCH_CONNECTION * InitializeConnection(const SCH_SHEET_PATH &aPath, CONNECTION_GRAPH *aGraph)
Create a new connection object associated with this object.
Definition sch_item.cpp:433
virtual void Move(const VECTOR2I &aMoveVector)
Move the item by aMoveVector to a new position.
Definition sch_item.h:377
void SetLayer(SCH_LAYER_ID aLayer)
Definition sch_item.h:322
void SetConnectivityDirty(bool aDirty=true)
Definition sch_item.h:568
void SetFieldsAutoplaced(AUTOPLACE_ALGO aAlgo)
Definition sch_item.h:605
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:289
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition sch_item.cpp:352
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:520
void SetLastResolvedState(const SCH_ITEM *aItem) override
void Move(const VECTOR2I &aMoveVector) override
Move the item by aMoveVector to a new position.
void SetPosition(const VECTOR2I &aPosition) override
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.
SCH_JUNCTION * AddJunction(SCH_COMMIT *aCommit, SCH_SCREEN *aScreen, const VECTOR2I &aPos)
int TrimOverLappingWires(SCH_COMMIT *aCommit, SCH_SELECTION *aSelection)
Logic to remove wires when overlapping correct items.
static bool IsDrawingLineWireOrBus(const SELECTION &aSelection)
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:817
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:717
const BOX2I GetBoundingBox() const override
Return the orthogonal bounding box of this object for display purposes.
Definition sch_line.cpp:233
EDA_ANGLE Angle() const
Get the angle between the start and end lines.
Definition sch_line.h:104
VECTOR2I GetEndPoint() const
Definition sch_line.h:148
VECTOR2I GetStartPoint() const
Definition sch_line.h:139
void MoveEnd(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:178
void SetLastResolvedState(const SCH_ITEM *aItem) override
Definition sch_line.h:163
void MoveStart(const VECTOR2I &aMoveVector)
Definition sch_line.cpp:172
double GetLength() const
Definition sch_line.cpp:249
void SetEndPoint(const VECTOR2I &aPosition)
Definition sch_line.h:149
void moveSelectionToSheet(SCH_SELECTION &aSelection, SCH_SHEET *aTarget, SCH_COMMIT *aCommit)
Clears the new drag lines and removes them from the screen.
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.
void orthoLineDrag(SCH_COMMIT *aCommit, SCH_LINE *line, const VECTOR2I &splitDelta, int &xBendCount, int &yBendCount, const EE_GRID_HELPER &grid)
std::unordered_set< SCH_LINE * > m_newDragLines
Lines changed by drag algorithm that weren't selected.
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.
std::vector< SCH_JUNCTION * > m_hiddenJunctions
bool m_inMoveTool
< Re-entrancy guard
std::vector< KIID > m_dragAdditions
Cache of the line's original connections before dragging started.
void moveItem(EDA_ITEM *aItem, const VECTOR2I &aDelta)
Find additional items for a drag operation.
std::unordered_set< SCH_LINE * > m_changedDragLines
Junctions that were hidden during the move.
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.
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 Append(SCH_ITEM *aItem, bool aUpdateLibSymbol=true)
EE_RTREE & Items()
Get the full RTree, usually for iterating.
Definition sch_screen.h:117
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Define a sheet pin (label) used in sheets to create hierarchical schematics.
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:47
bool IsRootSheet() const
void SetSize(const VECTOR2I &aSize)
Definition sch_sheet.h:119
VECTOR2I GetSize() const
Definition sch_sheet.h:118
SCH_SCREEN * GetScreen() const
Definition sch_sheet.h:116
VECTOR2I GetPosition() const override
Definition sch_sheet.h:443
const BOX2I GetBodyBoundingBox() const
Return a bounding box for the sheet body but not the fields.
std::vector< SCH_SHEET_PIN * > & GetPins()
Definition sch_sheet.h:187
Schematic symbol object.
Definition sch_symbol.h:75
VECTOR2I GetPosition() const override
Definition sch_text.h:150
void updateItem(EDA_ITEM *aItem, bool aUpdateRTree) const
bool Init() override
Init() is called once upon a registration of the tool.
SCH_TOOL_BASE(const std::string &aName)
SCH_SELECTION_TOOL * m_selectionTool
Definition seg.h:42
const VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute a point on the segment (this) that is closest to point aP.
Definition seg.cpp:604
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
virtual void Add(EDA_ITEM *aItem)
Definition selection.cpp:42
VECTOR2I GetReferencePoint() const
bool IsHover() const
Definition selection.h:89
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition selection.h:105
EDA_ITEM * Front() const
Definition selection.h:177
void SetReferencePoint(const VECTOR2I &aP)
bool Empty() const
Checks if there is anything selected.
Definition selection.h:115
std::vector< EDA_ITEM * > GetItemsSortedByTypeAndXY(bool leftBeforeRight=true, bool topBeforeBottom=true) const
Returns a copy of this selection of items sorted by their X then Y position.
bool HasReferencePoint() const
Definition selection.h:216
const TRANSFORM & GetTransform() const
Definition symbol.h:218
KIGFX::VIEW_CONTROLS * getViewControls() const
Definition tool_base.cpp:44
KIGFX::VIEW * getView() const
Definition tool_base.cpp:38
Generic, UI-independent tool event.
Definition tool_event.h:171
bool DisableGridSnapping() const
Definition tool_event.h:371
bool HasParameter() const
Definition tool_event.h:464
bool IsCancelInteractive() const
Indicate the event should restart/end an ongoing interactive tool's event loop (eg esc key,...
TOOL_ACTIONS Action() const
Returns more specific information about the type of an event.
Definition tool_event.h:250
bool IsActivate() const
Definition tool_event.h:345
COMMIT * Commit() const
Definition tool_event.h:283
bool IsClick(int aButtonMask=BUT_ANY) const
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition tool_event.h:315
int Modifier(int aMask=MD_MODIFIER_MASK) const
Return information about key modifiers state (Ctrl, Alt, etc.).
Definition tool_event.h:366
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:473
bool IsDblClick(int aButtonMask=BUT_ANY) const
std::atomic< SYNCRONOUS_TOOL_STATE > * SynchronousState() const
Definition tool_event.h:280
std::optional< int > GetCommandId() const
Definition tool_event.h:533
void SetPassEvent(bool aPass=true)
Definition tool_event.h:256
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition tool_event.h:325
bool IsMotion() const
Definition tool_event.h:330
void Go(int(SCH_EDIT_FRAME::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
std::unique_ptr< TOOL_MENU > m_menu
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
for transforming drawing coordinates for a wxDC device context.
Definition transform.h:46
TRANSFORM InverseTransform() const
Calculate the Inverse mirror/rotation transform.
Definition transform.cpp:59
VECTOR2I TransformCoordinate(const VECTOR2I &aPoint) const
Calculate a new coordinate according to the mirror/rotation transform.
Definition transform.cpp:44
@ CHT_REMOVE
Definition commit.h:43
@ CHT_DONE
Flag to indicate the change is already applied.
Definition commit.h:47
@ CHT_ADD
Definition commit.h:42
KICURSOR
Definition cursors.h:44
@ PLACE
Definition cursors.h:98
@ MOVING
Definition cursors.h:48
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:413
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
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 BRIGHTENED
item is drawn with a bright contour
#define IS_NEW
New item, just created.
#define SELECTED
Item was manually selected by the user.
#define SELECTED_BY_DRAG
Item was algorithmically selected as a dragged item.
#define IS_BROKEN
Is a segment just broken by BreakSegment.
#define STRUCT_DELETED
flag indication structures to be erased
#define ENDPOINT
ends. (Used to support dragging.)
#define IS_MOVING
Item being moved.
#define STARTPOINT
When a line is selected, these flags indicate which.
@ ID_POPUP_SCH_SELECT_UNIT
Definition eeschema_id.h:89
@ ID_POPUP_SCH_SELECT_BODY_STYLE
Definition eeschema_id.h:99
@ ID_POPUP_SCH_SELECT_BODY_STYLE_END
@ ID_POPUP_SCH_SELECT_UNIT_END
Definition eeschema_id.h:93
@ LINE_MODE_FREE
GRID_HELPER_GRIDS
Definition grid_helper.h:44
@ GRID_CURRENT
Definition grid_helper.h:46
@ LAYER_WIRE
Definition layer_ids.h:452
@ LAYER_BUS
Definition layer_ids.h:453
@ LAYER_BUS_JUNCTION
Definition layer_ids.h:498
std::vector< SCH_JUNCTION * > PreviewJunctions(const class SCH_SCREEN *aScreen, const std::vector< class SCH_ITEM * > &aItems)
Determine the points where explicit junctions would be required if the given temporary items were com...
@ 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:69
#define QUIET_MODE
static bool isGraphicItemForDrop(const SCH_ITEM *aItem)
static void cloneWireConnection(SCH_LINE *aNewLine, SCH_ITEM *aSource, SCH_EDIT_FRAME *aFrame)
T * GetAppSettings(const char *aFilename)
The EE_TYPE struct provides a type-specific auto-range iterator to the RTree.
Definition sch_rtree.h:195
bool moved
VECTOR2I end
int delta
@ TA_CHOICE_MENU_CHOICE
Context menu choice.
Definition tool_event.h:98
@ MD_CTRL
Definition tool_event.h:144
@ MD_SHIFT
Definition tool_event.h:143
@ STS_CANCELLED
Definition tool_event.h:164
@ STS_FINISHED
Definition tool_event.h:163
@ STS_RUNNING
Definition tool_event.h:162
@ 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:167
@ SCH_NO_CONNECT_T
Definition typeinfo.h:164
@ SCH_SYMBOL_T
Definition typeinfo.h:176
@ SCH_FIELD_T
Definition typeinfo.h:154
@ SCH_DIRECTIVE_LABEL_T
Definition typeinfo.h:175
@ SCH_LABEL_T
Definition typeinfo.h:171
@ SCH_SHEET_T
Definition typeinfo.h:179
@ SCH_SHAPE_T
Definition typeinfo.h:153
@ SCH_HIER_LABEL_T
Definition typeinfo.h:173
@ SCH_BUS_BUS_ENTRY_T
Definition typeinfo.h:166
@ SCH_SHEET_PIN_T
Definition typeinfo.h:178
@ SCH_TEXT_T
Definition typeinfo.h:155
@ SCH_BUS_WIRE_ENTRY_T
Definition typeinfo.h:165
@ SCH_BITMAP_T
Definition typeinfo.h:168
@ SCH_TEXTBOX_T
Definition typeinfo.h:156
@ SCH_GLOBAL_LABEL_T
Definition typeinfo.h:172
@ SCH_JUNCTION_T
Definition typeinfo.h:163
@ SCH_PIN_T
Definition typeinfo.h:157
constexpr int sign(T val)
Definition util.h:145
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695
VECTOR2< double > VECTOR2D
Definition vector2d.h:694