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