KiCad PCB EDA Suite
Loading...
Searching...
No Matches
edit_tool_move_fct.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) 2013-2017 CERN
5 * Copyright (C) 2017-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 * @author Tomasz Wlostowski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22 * or you may search the http://www.gnu.org website for the version 2 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <functional>
28#include <limits>
29#include <kiplatform/ui.h>
30#include <board.h>
31#include <board_commit.h>
33#include <pad.h>
34#include <pcb_group.h>
35#include <pcb_generator.h>
36#include <pcb_edit_frame.h>
37#include <spread_footprints.h>
38#include <tools/pcb_actions.h>
40#include <tools/edit_tool.h>
42#include <tools/drc_tool.h>
44#include <router/router_tool.h>
46#include <zone_filler.h>
47#include <drc/drc_engine.h>
48#include <drc/drc_item.h>
49#include <drc/drc_rule.h>
51#include <view/view_controls.h>
52
53
54int EDIT_TOOL::Swap( const TOOL_EVENT& aEvent )
55{
56 if( isRouterActive() )
57 {
58 wxBell();
59 return 0;
60 }
61
63 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
64 {
65 sTool->FilterCollectorForMarkers( aCollector );
66 sTool->FilterCollectorForHierarchy( aCollector, true );
67 sTool->FilterCollectorForFreePads( aCollector );
68
69 // Iterate from the back so we don't have to worry about removals.
70 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
71 {
72 BOARD_ITEM* item = aCollector[i];
73
74 if( item->Type() == PCB_TRACE_T )
75 aCollector.Remove( item );
76 }
77 },
78 true /* prompt user regarding locked items */ );
79
80 if( selection.Size() < 2 )
81 return 0;
82
83 BOARD_COMMIT localCommit( this );
84 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
85
86 if( !commit )
87 commit = &localCommit;
88
89 std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
90
91 // Save items, so changes can be undone
92 for( EDA_ITEM* item : selection )
93 {
94 if( !item->IsNew() && !item->IsMoving() )
95 commit->Modify( item );
96 }
97
98 for( size_t i = 0; i < sorted.size() - 1; i++ )
99 {
100 BOARD_ITEM* a = dynamic_cast<BOARD_ITEM*>( sorted[i] );
101 BOARD_ITEM* b = dynamic_cast<BOARD_ITEM*>( sorted[( i + 1 ) % sorted.size()] );
102
103 wxCHECK2( a && b, continue );
104
105 // Swap X,Y position
106 VECTOR2I aPos = a->GetPosition(), bPos = b->GetPosition();
107 std::swap( aPos, bPos );
108 a->SetPosition( aPos );
109 b->SetPosition( bPos );
110
111 // Handle footprints specially. They can be flipped to the back of the board which
112 // requires a special transformation.
113 if( a->Type() == PCB_FOOTPRINT_T && b->Type() == PCB_FOOTPRINT_T )
114 {
115 FOOTPRINT* aFP = static_cast<FOOTPRINT*>( a );
116 FOOTPRINT* bFP = static_cast<FOOTPRINT*>( b );
117
118 // Store initial orientation of footprints, before flipping them.
119 EDA_ANGLE aAngle = aFP->GetOrientation();
120 EDA_ANGLE bAngle = bFP->GetOrientation();
121
122 // Flip both if needed
123 if( aFP->IsFlipped() != bFP->IsFlipped() )
124 {
125 aFP->Flip( aPos, false );
126 bFP->Flip( bPos, false );
127 }
128
129 // Set orientation
130 std::swap( aAngle, bAngle );
131 aFP->SetOrientation( aAngle );
132 bFP->SetOrientation( bAngle );
133 }
134 // We can also do a layer swap safely for two objects of the same type,
135 // except groups which don't support layer swaps.
136 else if( a->Type() == b->Type() && a->Type() != PCB_GROUP_T )
137 {
138 // Swap layers
139 PCB_LAYER_ID aLayer = a->GetLayer(), bLayer = b->GetLayer();
140 std::swap( aLayer, bLayer );
141 a->SetLayer( aLayer );
142 b->SetLayer( bLayer );
143 }
144 }
145
146 if( !localCommit.Empty() )
147 localCommit.Push( _( "Swap" ) );
148
150
151 return 0;
152}
153
154
156{
157 if( isRouterActive() || m_dragging )
158 {
159 wxBell();
160 return 0;
161 }
162
163 BOARD_COMMIT commit( this );
165 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
166 {
167 sTool->FilterCollectorForMarkers( aCollector );
168 sTool->FilterCollectorForHierarchy( aCollector, true );
169 sTool->FilterCollectorForFreePads( aCollector, true );
170
171 // Iterate from the back so we don't have to worry about removals.
172 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
173 {
174 BOARD_ITEM* item = aCollector[i];
175
176 if( !dynamic_cast<FOOTPRINT*>( item ) )
177 aCollector.Remove( item );
178 }
179 },
180 true /* prompt user regarding locked items */ );
181
182 std::vector<FOOTPRINT*> footprintsToPack;
183
184 for( EDA_ITEM* item : selection )
185 footprintsToPack.push_back( static_cast<FOOTPRINT*>( item ) );
186
187 if( footprintsToPack.empty() )
188 return 0;
189
190 BOX2I footprintsBbox;
191
192 for( FOOTPRINT* item : footprintsToPack )
193 {
194 commit.Modify( item );
195 item->SetFlags( IS_MOVING );
196 footprintsBbox.Merge( item->GetBoundingBox( false, false ) );
197 }
198
199 SpreadFootprints( &footprintsToPack, footprintsBbox.Normalize().GetOrigin(), false );
200
201 if( doMoveSelection( aEvent, &commit, true ) )
202 commit.Push( _( "Pack Footprints" ) );
203 else
204 commit.Revert();
205
206 return 0;
207}
208
209
210int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
211{
212 if( isRouterActive() || m_dragging )
213 {
214 wxBell();
215 return 0;
216 }
217
218 if( BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ) )
219 {
220 wxCHECK( aEvent.SynchronousState(), 0 );
221 aEvent.SynchronousState()->store( STS_RUNNING );
222
223 if( doMoveSelection( aEvent, commit, true ) )
224 aEvent.SynchronousState()->store( STS_FINISHED );
225 else
226 aEvent.SynchronousState()->store( STS_CANCELLED );
227 }
228 else
229 {
230 BOARD_COMMIT localCommit( this );
231
232 if( doMoveSelection( aEvent, &localCommit, false ) )
233 localCommit.Push( _( "Move" ) );
234 else
235 localCommit.Revert();
236 }
237
238 // Notify point editor. (While doMoveSelection() will re-select the items and post this
239 // event, it's done before the edit flags are cleared in BOARD_COMMIT::Push() so the point
240 // editor doesn't fire up.)
242
243 return 0;
244}
245
246
247VECTOR2I EDIT_TOOL::getSafeMovement( const VECTOR2I& aMovement, const BOX2I& aSourceBBox,
248 const VECTOR2D& aBBoxOffset )
249{
250 typedef std::numeric_limits<int> coord_limits;
251
252 static const double max = coord_limits::max() - (int) COORDS_PADDING;
253 static const double min = -max;
254
255 BOX2D testBox( aSourceBBox.GetPosition(), aSourceBBox.GetSize() );
256 testBox.Offset( aBBoxOffset );
257
258 // Do not restrict movement if bounding box is already out of bounds
259 if( testBox.GetLeft() < min || testBox.GetTop() < min || testBox.GetRight() > max
260 || testBox.GetBottom() > max )
261 {
262 return aMovement;
263 }
264
265 testBox.Offset( aMovement );
266
267 if( testBox.GetLeft() < min )
268 testBox.Offset( min - testBox.GetLeft(), 0 );
269
270 if( max < testBox.GetRight() )
271 testBox.Offset( -( testBox.GetRight() - max ), 0 );
272
273 if( testBox.GetTop() < min )
274 testBox.Offset( 0, min - testBox.GetTop() );
275
276 if( max < testBox.GetBottom() )
277 testBox.Offset( 0, -( testBox.GetBottom() - max ) );
278
279 return KiROUND( testBox.GetPosition() - aBBoxOffset - aSourceBBox.GetPosition() );
280}
281
282
283bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit, bool aAutoStart )
284{
285 bool moveWithReference = aEvent.IsAction( &PCB_ACTIONS::moveWithReference );
286 bool moveIndividually = aEvent.IsAction( &PCB_ACTIONS::moveIndividually );
287
288 PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
289 PCBNEW_SETTINGS* cfg = editFrame->GetPcbNewSettings();
290 BOARD* board = editFrame->GetBoard();
292 VECTOR2I originalCursorPos = controls->GetCursorPosition();
293 STATUS_TEXT_POPUP statusPopup( frame() );
294 wxString status;
295 size_t itemIdx = 0;
296
297 // Be sure that there is at least one item that we can modify. If nothing was selected before,
298 // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
300 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
301 {
302 sTool->FilterCollectorForMarkers( aCollector );
303 sTool->FilterCollectorForHierarchy( aCollector, true );
304 sTool->FilterCollectorForFreePads( aCollector );
305 sTool->FilterCollectorForTableCells( aCollector );
306 },
307 true /* prompt user regarding locked items */ );
308
309 if( m_dragging || selection.Empty() )
310 return false;
311
312 editFrame->PushTool( aEvent );
313 Activate();
314
315 // Must be done after Activate() so that it gets set into the correct context
316 controls->ShowCursor( true );
317 controls->SetAutoPan( true );
318 controls->ForceCursorPosition( false );
319
320 auto displayConstraintsMessage =
321 [editFrame]( bool constrained )
322 {
323 editFrame->DisplayConstraintsMsg( constrained ? _( "Constrain to H, V, 45" )
324 : wxString( wxT( "" ) ) );
325 };
326
327 auto updateStatusPopup =
328 [&]( EDA_ITEM* item, size_t ii, size_t count )
329 {
330 wxString popuptext = _( "Click to place %s (item %zu of %zu)\n"
331 "Press <esc> to cancel all; double-click to finish" );
332 wxString msg;
333
334 if( item->Type() == PCB_FOOTPRINT_T )
335 {
336 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
337 msg = fp->GetReference();
338 }
339 else if( item->Type() == PCB_PAD_T )
340 {
341 PAD* pad = static_cast<PAD*>( item );
342 FOOTPRINT* fp = pad->GetParentFootprint();
343 msg = wxString::Format( _( "%s pad %s" ), fp->GetReference(), pad->GetNumber() );
344 }
345 else
346 {
347 msg = item->GetTypeDesc().Lower();
348 }
349
350 statusPopup.SetText( wxString::Format( popuptext, msg, ii, count ) );
351 };
352
353 std::vector<BOARD_ITEM*> sel_items; // All the items operated on by the move below
354 std::vector<BOARD_ITEM*> orig_items; // All the original items in the selection
355
356 for( EDA_ITEM* item : selection )
357 {
358 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
359 {
360 if( !selection.IsHover() )
361 orig_items.push_back( boardItem );
362
363 sel_items.push_back( boardItem );
364 }
365
366 if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item ) )
367 {
368 for( PAD* pad : footprint->Pads() )
369 sel_items.push_back( pad );
370
371 // Clear this flag here; it will be set by the netlist updater if the footprint is new
372 // so that it was skipped in the initial connectivity update in OnNetlistChanged
374 }
375 }
376
377 VECTOR2I pickedReferencePoint;
378
379 if( moveWithReference && !pickReferencePoint( _( "Select reference point for move..." ), "", "",
380 pickedReferencePoint ) )
381 {
382 if( selection.IsHover() )
384
385 editFrame->PopTool( aEvent );
386 return false;
387 }
388
389 if( moveIndividually )
390 {
391 orig_items.clear();
392
393 for( EDA_ITEM* item : selection.GetItemsSortedBySelectionOrder() )
394 {
395 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
396 orig_items.push_back( boardItem );
397 }
398
399 updateStatusPopup( orig_items[ itemIdx ], itemIdx + 1, orig_items.size() );
400 statusPopup.Popup();
401 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
402 canvas()->SetStatusPopup( statusPopup.GetPanel() );
403
405 m_selectionTool->AddItemToSel( orig_items[ itemIdx ] );
406
407 sel_items.clear();
408 sel_items.push_back( orig_items[ itemIdx ] );
409 }
410
411 bool restore_state = false;
412 VECTOR2I originalPos;
413 VECTOR2D bboxMovement;
414 BOX2I originalBBox;
415 bool updateBBox = true;
416 LSET layers( editFrame->GetActiveLayer() );
418 TOOL_EVENT copy = aEvent;
419 TOOL_EVENT* evt = &copy;
420 VECTOR2I prevPos;
421 bool enableLocalRatsnest = true;
422
423 bool hv45Mode = false;
424 bool eatFirstMouseUp = true;
425 bool allowRedraw3D = cfg->m_Display.m_Live3DRefresh;
426 bool showCourtyardConflicts = !m_isFootprintEditor && cfg->m_ShowCourtyardCollisions;
427
428 // Used to test courtyard overlaps
429 std::unique_ptr<DRC_INTERACTIVE_COURTYARD_CLEARANCE> drc_on_move = nullptr;
430
431 if( showCourtyardConflicts )
432 {
433 std::shared_ptr<DRC_ENGINE> drcEngine = m_toolMgr->GetTool<DRC_TOOL>()->GetDRCEngine();
434 drc_on_move.reset( new DRC_INTERACTIVE_COURTYARD_CLEARANCE( drcEngine ) );
435 drc_on_move->Init( board );
436 }
437
438 displayConstraintsMessage( hv45Mode );
439
440 // Prime the pump
442
443 // Main loop: keep receiving events
444 do
445 {
446 VECTOR2I movement;
447 editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
448 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
449 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
450
451 bool isSkip = evt->IsAction( &PCB_ACTIONS::skip ) && moveIndividually;
452
453 if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
454 eatFirstMouseUp = false;
455
456 if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
460 {
461 if( m_dragging && evt->Category() == TC_MOUSE )
462 {
463 bool redraw3D = false;
464
465 VECTOR2I mousePos( controls->GetMousePosition() );
466
467 m_cursor = grid.BestSnapAnchor( mousePos, layers,
468 grid.GetSelectionGrid( selection ), sel_items );
469
471 {
472 long action = controls->GetSettings().m_lastKeyboardCursorCommand;
473
474 // The arrow keys are by definition SINGLE AXIS. Do not allow the other
475 // axis to be snapped to the grid.
476 if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
477 m_cursor.y = prevPos.y;
478 else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
479 m_cursor.x = prevPos.x;
480 }
481
482 if( !selection.HasReferencePoint() )
483 originalPos = m_cursor;
484
485 if( hv45Mode )
486 {
487 VECTOR2I moveVector = m_cursor - originalPos;
488 m_cursor = originalPos + GetVectorSnapped45( moveVector );
489 }
490
491 if( updateBBox )
492 {
493 originalBBox = BOX2I();
494 bboxMovement = VECTOR2D();
495
496 for( EDA_ITEM* item : sel_items )
497 {
498 originalBBox.Merge( item->ViewBBox() );
499 }
500
501 updateBBox = false;
502 }
503
504 // Constrain selection bounding box to coordinates limits
505 movement = getSafeMovement( m_cursor - prevPos, originalBBox, bboxMovement );
506
507 // Apply constrained movement
508 m_cursor = prevPos + movement;
509
510 controls->ForceCursorPosition( true, m_cursor );
511 selection.SetReferencePoint( m_cursor );
512
513 prevPos = m_cursor;
514 bboxMovement += movement;
515
516 // Drag items to the current cursor position
517 for( EDA_ITEM* item : sel_items )
518 {
519 // Don't double move child items.
520 if( !item->GetParent() || !item->GetParent()->IsSelected() )
521 static_cast<BOARD_ITEM*>( item )->Move( movement );
522
523 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
524 {
526 static_cast<PCB_GENERATOR*>( item ) );
527 }
528
529 if( item->Type() == PCB_FOOTPRINT_T )
530 redraw3D = true;
531 }
532
533 if( redraw3D && allowRedraw3D )
534 editFrame->Update3DView( false, true );
535
536 if( showCourtyardConflicts && drc_on_move->m_FpInMove.size() )
537 {
538 drc_on_move->Run();
539 drc_on_move->UpdateConflicts( m_toolMgr->GetView(), true );
540 }
541
543 }
544 else if( !m_dragging && ( aAutoStart || !evt->IsAction( &ACTIONS::refreshPreview ) ) )
545 {
546 // Prepare to start dragging
547 editFrame->HideSolderMask();
548
549 m_dragging = true;
550
551 for( EDA_ITEM* item : selection )
552 {
553 if( item->GetParent() && item->GetParent()->IsSelected() )
554 continue;
555
556 if( !item->IsNew() && !item->IsMoving() )
557 {
558 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
559 {
560 enableLocalRatsnest = false;
561
563 static_cast<PCB_GENERATOR*>( item ) );
564 }
565 else
566 {
567 aCommit->Modify( item );
568 }
569
570 item->SetFlags( IS_MOVING );
571
572 static_cast<BOARD_ITEM*>( item )->RunOnDescendants(
573 [&]( BOARD_ITEM* bItem )
574 {
575 item->SetFlags( IS_MOVING );
576 } );
577 }
578 }
579
580 m_cursor = controls->GetCursorPosition();
581
582 if( selection.HasReferencePoint() )
583 {
584 // start moving with the reference point attached to the cursor
585 grid.SetAuxAxes( false );
586
587 if( hv45Mode )
588 {
589 VECTOR2I moveVector = m_cursor - originalPos;
590 m_cursor = originalPos + GetVectorSnapped45( moveVector );
591 }
592
593 movement = m_cursor - selection.GetReferencePoint();
594
595 // Drag items to the current cursor position
596 for( EDA_ITEM* item : selection )
597 {
598 // Don't double move footprint pads, fields, etc.
599 if( item->GetParent() && item->GetParent()->IsSelected() )
600 continue;
601
602 static_cast<BOARD_ITEM*>( item )->Move( movement );
603 }
604
605 selection.SetReferencePoint( m_cursor );
606 }
607 else
608 {
609 if( showCourtyardConflicts )
610 {
611 std::vector<FOOTPRINT*>& FPs = drc_on_move->m_FpInMove;
612
613 for( BOARD_ITEM* item : sel_items )
614 {
615 if( item->Type() == PCB_FOOTPRINT_T )
616 FPs.push_back( static_cast<FOOTPRINT*>( item ) );
617
618 item->RunOnDescendants(
619 [&]( BOARD_ITEM* descendent )
620 {
621 if( descendent->Type() == PCB_FOOTPRINT_T )
622 FPs.push_back( static_cast<FOOTPRINT*>( descendent ) );
623 } );
624 }
625 }
626
627 m_cursor = grid.BestDragOrigin( originalCursorPos, sel_items,
628 grid.GetSelectionGrid( selection ),
630
631 // Set the current cursor position to the first dragged item origin, so the
632 // movement vector could be computed later
633 if( moveWithReference )
634 {
635 selection.SetReferencePoint( pickedReferencePoint );
636 controls->ForceCursorPosition( true, pickedReferencePoint );
637 m_cursor = pickedReferencePoint;
638 }
639 else
640 {
641 // Check if user wants to warp the mouse to origin of moved object
642 if( !editFrame->GetMoveWarpsCursor() )
643 m_cursor = originalCursorPos; // No, so use original mouse pos instead
644
645 selection.SetReferencePoint( m_cursor );
646 grid.SetAuxAxes( true, m_cursor );
647 }
648
649 originalPos = m_cursor;
650 }
651
652 // Update variables for bounding box collision calculations
653 updateBBox = true;
654
655 controls->SetCursorPosition( m_cursor, false );
656
657 prevPos = m_cursor;
658 controls->SetAutoPan( true );
660 }
661
662 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
663
664 if( enableLocalRatsnest )
666 }
667 else if( evt->IsCancelInteractive() || evt->IsActivate() )
668 {
669 if( m_dragging && evt->IsCancelInteractive() )
670 evt->SetPassEvent( false );
671
672 restore_state = true; // Canceling the tool means that items have to be restored
673 break; // Finish
674 }
675 else if( evt->IsClick( BUT_RIGHT ) )
676 {
677 m_menu.ShowContextMenu( selection );
678 }
679 else if( evt->IsAction( &ACTIONS::undo ) || evt->IsAction( &ACTIONS::doDelete ) )
680 {
681 restore_state = true; // Perform undo locally
682 break; // Finish
683 }
684 else if( evt->IsAction( &ACTIONS::duplicate ) || evt->IsAction( &ACTIONS::cut ) )
685 {
686 }
687 else if( evt->IsAction( &PCB_ACTIONS::rotateCw )
689 || evt->IsAction( &PCB_ACTIONS::flip )
691 || evt->IsAction( &PCB_ACTIONS::mirrorV ) )
692 {
693 updateBBox = true;
694 eatFirstMouseUp = false;
695 evt->SetPassEvent();
696 }
697 else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) || isSkip )
698 {
699 // Eat mouse-up/-click events that leaked through from the lock dialog
700 if( eatFirstMouseUp && !evt->IsAction( &ACTIONS::cursorClick ) )
701 {
702 eatFirstMouseUp = false;
703 continue;
704 }
705 else if( moveIndividually && m_dragging )
706 {
707 // Put skipped items back where they started
708 if( isSkip )
709 orig_items[itemIdx]->SetPosition( originalPos );
710
711 view()->Update( orig_items[itemIdx] );
713
714 if( ++itemIdx < orig_items.size() )
715 {
716 BOARD_ITEM* nextItem = orig_items[itemIdx];
717
719
720 originalPos = nextItem->GetPosition();
721 m_selectionTool->AddItemToSel( nextItem );
722 selection.SetReferencePoint( originalPos );
723
724 sel_items.clear();
725 sel_items.push_back( nextItem );
726 updateStatusPopup( nextItem, itemIdx + 1, orig_items.size() );
727
728 // Pick up new item
729 aCommit->Modify( nextItem );
730 nextItem->Move( controls->GetCursorPosition( true ) - nextItem->GetPosition() );
731
732 continue;
733 }
734 }
735
736 break; // finish
737 }
738 else if( evt->IsDblClick( BUT_LEFT ) )
739 {
740 // The first click will move the new item, so put it back
741 if( moveIndividually )
742 orig_items[itemIdx]->SetPosition( originalPos );
743
744 break; // finish
745 }
746 else if( evt->IsAction( &PCB_ACTIONS::toggleHV45Mode ) )
747 {
748 hv45Mode = !hv45Mode;
749 displayConstraintsMessage( hv45Mode );
750 evt->SetPassEvent( false );
751 }
757 || evt->IsAction( &ACTIONS::redo ) )
758 {
759 wxBell();
760 }
761 else
762 {
763 evt->SetPassEvent();
764 }
765
766 } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
767
768 // Clear temporary COURTYARD_CONFLICT flag and ensure the conflict shadow is cleared
769 if( showCourtyardConflicts )
770 drc_on_move->ClearConflicts( m_toolMgr->GetView() );
771
772 controls->ForceCursorPosition( false );
773 controls->ShowCursor( false );
774 controls->SetAutoPan( false );
775
776 m_dragging = false;
777
778 // Discard reference point when selection is "dropped" onto the board
779 selection.ClearReferencePoint();
780
781 // Unselect all items to clear selection flags and then re-select the originally selected
782 // items.
784
785 if( restore_state )
786 {
787 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
788 {
790 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
791 }
792 }
793 else
794 {
795 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
796 {
798 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
799 }
800
801 EDA_ITEMS oItems( orig_items.begin(), orig_items.end() );
803 }
804
805 // Remove the dynamic ratsnest from the screen
807
808 editFrame->PopTool( aEvent );
809 editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
810
811 return !restore_state;
812}
813
BOX2< VECTOR2I > BOX2I
Definition: box2.h:877
@ CURSOR_RIGHT
Definition: actions.h:236
@ CURSOR_LEFT
Definition: actions.h:234
@ CURSOR_UP
Definition: actions.h:230
@ CURSOR_DOWN
Definition: actions.h:232
static TOOL_ACTION undo
Definition: actions.h:66
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 redo
Definition: actions.h:67
static TOOL_ACTION cut
Definition: actions.h:68
static TOOL_ACTION refreshPreview
Definition: actions.h:137
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Revert the commit by restoring the modified items state.
virtual void Revert() override
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:226
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition: board_item.h:314
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:260
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:282
BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition: box2.h:136
const Vec & GetPosition() const
Definition: box2.h:201
const Vec & GetOrigin() const
Definition: box2.h:200
void Offset(coord_type dx, coord_type dy)
Definition: box2.h:249
const SizeVec & GetSize() const
Definition: box2.h:196
coord_type GetTop() const
Definition: box2.h:219
coord_type GetRight() const
Definition: box2.h:207
coord_type GetLeft() const
Definition: box2.h:218
coord_type GetBottom() const
Definition: box2.h:212
BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition: box2.h:623
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:81
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
bool Empty() const
Returns status of an item.
Definition: commit.h:144
void DisplayConstraintsMsg(const wxString &msg)
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
void SetStatusPopup(wxWindow *aPopup)
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 void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:243
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition: eda_item.cpp:320
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
bool IsSelected() const
Definition: eda_item.h:109
EDA_ITEM * GetParent() const
Definition: eda_item.h:102
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition: eda_item.cpp:273
bool IsMoving() const
Definition: eda_item.h:107
bool IsNew() const
Definition: eda_item.h:106
bool isRouterActive() const
Definition: edit_tool.cpp:436
bool doMoveSelection(const TOOL_EVENT &aEvent, BOARD_COMMIT *aCommit, bool aAutoStart)
Rebuilds the ratsnest for operations that require it outside the commit rebuild.
int Swap(const TOOL_EVENT &aEvent)
Swap currently selected items' positions.
int PackAndMoveFootprints(const TOOL_EVENT &aEvent)
Try to fit selected footprints inside a minimal area and start movement.
bool pickReferencePoint(const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
Definition: edit_tool.cpp:2983
bool m_dragging
Definition: edit_tool.h:230
int Move(const TOOL_EVENT &aEvent)
Main loop in which events are handled.
static const unsigned int COORDS_PADDING
Definition: edit_tool.h:235
VECTOR2I getSafeMovement(const VECTOR2I &aMovement, const BOX2I &aSourceBBox, const VECTOR2D &aBBoxOffset)
VECTOR2I m_cursor
Definition: edit_tool.h:231
void rebuildConnectivity()
Removes all items from the set which are children of other PCB_GROUP or PCB_GENERATOR items in the se...
Definition: edit_tool.cpp:3162
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:229
static const TOOL_EVENT SelectedEvent
Definition: actions.h:260
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:267
static const TOOL_EVENT SelectedItemsMoved
Used to inform tools that the selection should temporarily be non-editable.
Definition: actions.h:270
EDA_ANGLE GetOrientation() const
Definition: footprint.h:212
void SetOrientation(const EDA_ANGLE &aNewAngle)
Definition: footprint.cpp:2387
void SetAttributes(int aAttributes)
Definition: footprint.h:277
int GetAttributes() const
Definition: footprint.h:276
bool IsFlipped() const
Definition: footprint.h:377
PADS & Pads()
Definition: footprint.h:191
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:2256
const wxString & GetReference() const
Definition: footprint.h:588
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:206
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:75
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 VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
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.
const VC_SETTINGS & GetSettings() const
Apply VIEW_CONTROLS settings from an object.
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:575
Definition: pad.h:53
DISPLAY_OPTIONS m_Display
bool m_ShowCourtyardCollisions
static TOOL_ACTION toggleHV45Mode
Definition: pcb_actions.h:517
static TOOL_ACTION mirrorH
Mirroring of selected items.
Definition: pcb_actions.h:139
static TOOL_ACTION genPushEdit
Definition: pcb_actions.h:283
static TOOL_ACTION hideLocalRatsnest
Definition: pcb_actions.h:561
static TOOL_ACTION genStartEdit
Definition: pcb_actions.h:281
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:68
static TOOL_ACTION moveWithReference
move with a reference point
Definition: pcb_actions.h:126
static TOOL_ACTION moveExact
Activation of the exact move tool.
Definition: pcb_actions.h:179
static TOOL_ACTION copyWithReference
copy command with manual reference point selection
Definition: pcb_actions.h:129
static TOOL_ACTION genUpdateEdit
Definition: pcb_actions.h:282
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:562
static TOOL_ACTION moveIndividually
move items one-by-one
Definition: pcb_actions.h:123
static TOOL_ACTION positionRelative
Activation of the position relative tool.
Definition: pcb_actions.h:319
static TOOL_ACTION skip
Definition: pcb_actions.h:149
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:120
static TOOL_ACTION mirrorV
Definition: pcb_actions.h:140
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: pcb_actions.h:76
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:136
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:132
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:133
static TOOL_ACTION genRevertEdit
Definition: pcb_actions.h:284
Common, abstract interface for edit frames.
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual PCB_LAYER_ID GetActiveLayer() const
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
BOARD * GetBoard() const
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
The selection tool: currently supports:
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Drop any PCB_MARKERs from the collector.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection, filtered according to aClientFilter.
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector, bool aForcePromotion=false) const
Check the "allow free pads" setting and if disabled, replace any pads in the collector with their par...
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
PCB_SELECTION_FILTER_OPTIONS & GetFilter()
Set up handlers for various events.
int ClearSelection(const TOOL_EVENT &aEvent)
void FilterCollectorForTableCells(GENERAL_COLLECTOR &aCollector) const
Promote any table cell selections to the whole table.
KIGFX::PCB_VIEW * view() const
PCB_BASE_EDIT_FRAME * frame() const
KIGFX::VIEW_CONTROLS * controls() const
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
bool m_isFootprintEditor
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
int AddItemToSel(const TOOL_EVENT &aEvent)
bool IsHover() const
Definition: selection.h:84
int Size() const
Returns the number of selected parts.
Definition: selection.h:116
std::vector< EDA_ITEM * > GetItemsSortedBySelectionOrder() const
Definition: selection.cpp:264
void ClearReferencePoint()
Definition: selection.cpp:185
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:179
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
bool HasReferencePoint() const
Definition: selection.h:211
wxWindow * GetPanel()
Definition: status_popup.h:63
virtual void Popup(wxWindow *aFocus=nullptr)
virtual void Move(const wxPoint &aWhere)
Extension of STATUS_POPUP for displaying a single line text.
Definition: status_popup.h:84
void SetText(const wxString &aText)
Display a text.
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:217
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
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
TOOL_EVENT_CATEGORY Category() const
Returns more specific information about the type of an event.
Definition: tool_event.h:243
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
bool IsDblClick(int aButtonMask=BUT_ANY) const
Definition: tool_event.cpp:215
std::atomic< SYNCRONOUS_TOOL_STATE > * SynchronousState() const
Definition: tool_event.h:272
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
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.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
bool RunAction(const std::string &aActionName, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:150
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:235
bool RunSynchronousAction(const TOOL_ACTION &aAction, COMMIT *aCommit, T aParam)
Run the specified action immediately, pausing the current action to run the new one.
Definition: tool_manager.h:197
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:391
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
static bool IsZoneFillAction(const TOOL_EVENT *aEvent)
#define _(s)
std::vector< EDA_ITEM * > EDA_ITEMS
Define list of drawing items for screens.
Definition: eda_item.h:532
#define IS_MOVING
Item being moved.
@ FP_JUST_ADDED
Definition: footprint.h:77
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
Definition: gtk/ui.cpp:606
Class to handle a set of BOARD_ITEMs.
void SpreadFootprints(std::vector< FOOTPRINT * > *aFootprints, VECTOR2I aTargetBoxPosition, bool aGroupBySheet, int aComponentGap, int aGroupGap)
Footprints (after loaded by reading a netlist for instance) are moved to be in a small free area (out...
bool m_lastKeyboardCursorPositionValid
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
long m_lastKeyboardCursorCommand
Position of the above event.
@ TC_MOUSE
Definition: tool_event.h:54
@ 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
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition: typeinfo.h:91
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:110
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition: typeinfo.h:87
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:118
VECTOR2< double > VECTOR2D
Definition: vector2d.h:601