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
52
53int EDIT_TOOL::Swap( const TOOL_EVENT& aEvent )
54{
55 if( isRouterActive() )
56 {
57 wxBell();
58 return 0;
59 }
60
62 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
63 {
64 sTool->FilterCollectorForMarkers( aCollector );
65 sTool->FilterCollectorForHierarchy( aCollector, true );
66 sTool->FilterCollectorForFreePads( aCollector );
67
68 // Iterate from the back so we don't have to worry about removals.
69 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
70 {
71 BOARD_ITEM* item = aCollector[i];
72
73 if( item->Type() == PCB_TRACE_T )
74 aCollector.Remove( item );
75 }
76 },
77 true /* prompt user regarding locked items */ );
78
79 if( selection.Size() < 2 )
80 return 0;
81
82 BOARD_COMMIT localCommit( this );
83 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
84
85 if( !commit )
86 commit = &localCommit;
87
88 std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
89
90 // Save items, so changes can be undone
91 for( EDA_ITEM* item : selection )
92 {
93 if( !item->IsNew() && !item->IsMoving() )
94 commit->Modify( item );
95 }
96
97 for( size_t i = 0; i < sorted.size() - 1; i++ )
98 {
99 BOARD_ITEM* a = dynamic_cast<BOARD_ITEM*>( sorted[i] );
100 BOARD_ITEM* b = dynamic_cast<BOARD_ITEM*>( sorted[( i + 1 ) % sorted.size()] );
101
102 wxCHECK2( a && b, continue );
103
104 // Swap X,Y position
105 VECTOR2I aPos = a->GetPosition(), bPos = b->GetPosition();
106 std::swap( aPos, bPos );
107 a->SetPosition( aPos );
108 b->SetPosition( bPos );
109
110 // Handle footprints specially. They can be flipped to the back of the board which
111 // requires a special transformation.
112 if( a->Type() == PCB_FOOTPRINT_T && b->Type() == PCB_FOOTPRINT_T )
113 {
114 FOOTPRINT* aFP = static_cast<FOOTPRINT*>( a );
115 FOOTPRINT* bFP = static_cast<FOOTPRINT*>( b );
116
117 // Store initial orientation of footprints, before flipping them.
118 EDA_ANGLE aAngle = aFP->GetOrientation();
119 EDA_ANGLE bAngle = bFP->GetOrientation();
120
121 // Flip both if needed
122 if( aFP->IsFlipped() != bFP->IsFlipped() )
123 {
124 aFP->Flip( aPos, false );
125 bFP->Flip( bPos, false );
126 }
127
128 // Set orientation
129 std::swap( aAngle, bAngle );
130 aFP->SetOrientation( aAngle );
131 bFP->SetOrientation( bAngle );
132 }
133 // We can also do a layer swap safely for two objects of the same type,
134 // except groups which don't support layer swaps.
135 else if( a->Type() == b->Type() && a->Type() != PCB_GROUP_T )
136 {
137 // Swap layers
138 PCB_LAYER_ID aLayer = a->GetLayer(), bLayer = b->GetLayer();
139 std::swap( aLayer, bLayer );
140 a->SetLayer( aLayer );
141 b->SetLayer( bLayer );
142 }
143 }
144
145 if( !localCommit.Empty() )
146 localCommit.Push( _( "Swap" ) );
147
149
150 return 0;
151}
152
153
155{
156 if( isRouterActive() || m_dragging )
157 {
158 wxBell();
159 return 0;
160 }
161
162 BOARD_COMMIT commit( this );
164 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
165 {
166 sTool->FilterCollectorForMarkers( aCollector );
167 sTool->FilterCollectorForHierarchy( aCollector, true );
168 sTool->FilterCollectorForFreePads( aCollector, true );
169
170 // Iterate from the back so we don't have to worry about removals.
171 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
172 {
173 BOARD_ITEM* item = aCollector[i];
174
175 if( !dynamic_cast<FOOTPRINT*>( item ) )
176 aCollector.Remove( item );
177 }
178 },
179 true /* prompt user regarding locked items */ );
180
181 std::vector<FOOTPRINT*> footprintsToPack;
182
183 for( EDA_ITEM* item : selection )
184 footprintsToPack.push_back( static_cast<FOOTPRINT*>( item ) );
185
186 if( footprintsToPack.empty() )
187 return 0;
188
189 BOX2I footprintsBbox;
190
191 for( FOOTPRINT* item : footprintsToPack )
192 {
193 commit.Modify( item );
194 item->SetFlags( IS_MOVING );
195 footprintsBbox.Merge( item->GetBoundingBox( false, false ) );
196 }
197
198 SpreadFootprints( &footprintsToPack, footprintsBbox.Normalize().GetOrigin(), false );
199
200 if( doMoveSelection( aEvent, &commit, true ) )
201 commit.Push( _( "Pack Footprints" ) );
202 else
203 commit.Revert();
204
205 return 0;
206}
207
208
209int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
210{
211 if( isRouterActive() || m_dragging )
212 {
213 wxBell();
214 return 0;
215 }
216
217 if( BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ) )
218 {
219 wxCHECK( aEvent.SynchronousState(), 0 );
220 aEvent.SynchronousState()->store( STS_RUNNING );
221
222 if( doMoveSelection( aEvent, commit, true ) )
223 aEvent.SynchronousState()->store( STS_FINISHED );
224 else
225 aEvent.SynchronousState()->store( STS_CANCELLED );
226 }
227 else
228 {
229 BOARD_COMMIT localCommit( this );
230
231 if( doMoveSelection( aEvent, &localCommit, false ) )
232 localCommit.Push( _( "Move" ) );
233 else
234 localCommit.Revert();
235 }
236
237 // Notify point editor. (While doMoveSelection() will re-select the items and post this
238 // event, it's done before the edit flags are cleared in BOARD_COMMIT::Push() so the point
239 // editor doesn't fire up.)
241
242 return 0;
243}
244
245
246VECTOR2I EDIT_TOOL::getSafeMovement( const VECTOR2I& aMovement, const BOX2I& aSourceBBox,
247 const VECTOR2D& aBBoxOffset )
248{
249 typedef std::numeric_limits<int> coord_limits;
250
251 static const double max = coord_limits::max() - (int) COORDS_PADDING;
252 static const double min = -max;
253
254 BOX2D testBox( aSourceBBox.GetPosition(), aSourceBBox.GetSize() );
255 testBox.Offset( aBBoxOffset );
256
257 // Do not restrict movement if bounding box is already out of bounds
258 if( testBox.GetLeft() < min || testBox.GetTop() < min || testBox.GetRight() > max
259 || testBox.GetBottom() > max )
260 {
261 return aMovement;
262 }
263
264 testBox.Offset( aMovement );
265
266 if( testBox.GetLeft() < min )
267 testBox.Offset( min - testBox.GetLeft(), 0 );
268
269 if( max < testBox.GetRight() )
270 testBox.Offset( -( testBox.GetRight() - max ), 0 );
271
272 if( testBox.GetTop() < min )
273 testBox.Offset( 0, min - testBox.GetTop() );
274
275 if( max < testBox.GetBottom() )
276 testBox.Offset( 0, -( testBox.GetBottom() - max ) );
277
278 return KiROUND( testBox.GetPosition() - aBBoxOffset - aSourceBBox.GetPosition() );
279}
280
281
282bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit, bool aAutoStart )
283{
284 bool moveWithReference = aEvent.IsAction( &PCB_ACTIONS::moveWithReference );
285 bool moveIndividually = aEvent.IsAction( &PCB_ACTIONS::moveIndividually );
286
287 PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
288 PCBNEW_SETTINGS* cfg = editFrame->GetPcbNewSettings();
289 BOARD* board = editFrame->GetBoard();
291 VECTOR2I originalCursorPos = controls->GetCursorPosition();
292 STATUS_TEXT_POPUP statusPopup( frame() );
293 wxString status;
294 size_t itemIdx = 0;
295
296 // Be sure that there is at least one item that we can modify. If nothing was selected before,
297 // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
299 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
300 {
301 sTool->FilterCollectorForMarkers( aCollector );
302 sTool->FilterCollectorForHierarchy( aCollector, true );
303 sTool->FilterCollectorForFreePads( aCollector );
304 sTool->FilterCollectorForTableCells( aCollector );
305 },
306 true /* prompt user regarding locked items */ );
307
308 if( m_dragging || selection.Empty() )
309 return false;
310
311 editFrame->PushTool( aEvent );
312 Activate();
313
314 // Must be done after Activate() so that it gets set into the correct context
315 controls->ShowCursor( true );
316 controls->SetAutoPan( true );
317 controls->ForceCursorPosition( false );
318
319 auto displayConstraintsMessage =
320 [editFrame]( bool constrained )
321 {
322 editFrame->DisplayConstraintsMsg( constrained ? _( "Constrain to H, V, 45" )
323 : wxString( wxT( "" ) ) );
324 };
325
326 auto updateStatusPopup =
327 [&]( EDA_ITEM* item, size_t ii, size_t count )
328 {
329 wxString popuptext = _( "Click to place %s (item %zu of %zu)\n"
330 "Press <esc> to cancel all; double-click to finish" );
331 wxString msg;
332
333 if( item->Type() == PCB_FOOTPRINT_T )
334 {
335 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
336 msg = fp->GetReference();
337 }
338 else if( item->Type() == PCB_PAD_T )
339 {
340 PAD* pad = static_cast<PAD*>( item );
341 FOOTPRINT* fp = pad->GetParentFootprint();
342 msg = wxString::Format( _( "%s pad %s" ), fp->GetReference(), pad->GetNumber() );
343 }
344 else
345 {
346 msg = item->GetTypeDesc().Lower();
347 }
348
349 statusPopup.SetText( wxString::Format( popuptext, msg, ii, count ) );
350 };
351
352 std::vector<BOARD_ITEM*> sel_items; // All the items operated on by the move below
353 std::vector<BOARD_ITEM*> orig_items; // All the original items in the selection
354
355 for( EDA_ITEM* item : selection )
356 {
357 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
358 {
359 if( !selection.IsHover() )
360 orig_items.push_back( boardItem );
361
362 sel_items.push_back( boardItem );
363 }
364
365 if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item ) )
366 {
367 for( PAD* pad : footprint->Pads() )
368 sel_items.push_back( pad );
369
370 // Clear this flag here; it will be set by the netlist updater if the footprint is new
371 // so that it was skipped in the initial connectivity update in OnNetlistChanged
373 }
374 }
375
376 VECTOR2I pickedReferencePoint;
377
378 if( moveWithReference && !pickReferencePoint( _( "Select reference point for move..." ), "", "",
379 pickedReferencePoint ) )
380 {
381 if( selection.IsHover() )
383
384 editFrame->PopTool( aEvent );
385 return false;
386 }
387
388 if( moveIndividually )
389 {
390 orig_items.clear();
391
392 for( EDA_ITEM* item : selection.GetItemsSortedBySelectionOrder() )
393 {
394 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
395 orig_items.push_back( boardItem );
396 }
397
398 updateStatusPopup( orig_items[ itemIdx ], itemIdx + 1, orig_items.size() );
399 statusPopup.Popup();
400 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
401 canvas()->SetStatusPopup( statusPopup.GetPanel() );
402
404 m_selectionTool->AddItemToSel( orig_items[ itemIdx ] );
405
406 sel_items.clear();
407 sel_items.push_back( orig_items[ itemIdx ] );
408 }
409
410 bool restore_state = false;
411 VECTOR2I originalPos;
412 VECTOR2D bboxMovement;
413 BOX2I originalBBox;
414 bool updateBBox = true;
415 LSET layers( editFrame->GetActiveLayer() );
417 TOOL_EVENT copy = aEvent;
418 TOOL_EVENT* evt = &copy;
419 VECTOR2I prevPos;
420 bool enableLocalRatsnest = true;
421
422 bool hv45Mode = false;
423 bool eatFirstMouseUp = true;
424 bool allowRedraw3D = cfg->m_Display.m_Live3DRefresh;
425 bool showCourtyardConflicts = !m_isFootprintEditor && cfg->m_ShowCourtyardCollisions;
426
427 // Used to test courtyard overlaps
428 std::unique_ptr<DRC_INTERACTIVE_COURTYARD_CLEARANCE> drc_on_move = nullptr;
429
430 if( showCourtyardConflicts )
431 {
432 std::shared_ptr<DRC_ENGINE> drcEngine = m_toolMgr->GetTool<DRC_TOOL>()->GetDRCEngine();
433 drc_on_move.reset( new DRC_INTERACTIVE_COURTYARD_CLEARANCE( drcEngine ) );
434 drc_on_move->Init( board );
435 }
436
437 displayConstraintsMessage( hv45Mode );
438
439 // Prime the pump
441
442 // Main loop: keep receiving events
443 do
444 {
445 VECTOR2I movement;
446 editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
447 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
448 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
449
450 bool isSkip = evt->IsAction( &PCB_ACTIONS::skip ) && moveIndividually;
451
452 if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
453 eatFirstMouseUp = false;
454
455 if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
459 {
460 if( m_dragging && evt->Category() == TC_MOUSE )
461 {
462 bool redraw3D = false;
463
464 VECTOR2I mousePos( controls->GetMousePosition() );
465
466 m_cursor = grid.BestSnapAnchor( mousePos, layers,
467 grid.GetSelectionGrid( selection ), sel_items );
468
470 {
471 long action = controls->GetSettings().m_lastKeyboardCursorCommand;
472
473 // The arrow keys are by definition SINGLE AXIS. Do not allow the other
474 // axis to be snapped to the grid.
475 if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
476 m_cursor.y = prevPos.y;
477 else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
478 m_cursor.x = prevPos.x;
479 }
480
481 if( !selection.HasReferencePoint() )
482 originalPos = m_cursor;
483
484 if( hv45Mode )
485 {
486 VECTOR2I moveVector = m_cursor - originalPos;
487 m_cursor = originalPos + GetVectorSnapped45( moveVector );
488 }
489
490 if( updateBBox )
491 {
492 originalBBox = BOX2I();
493 bboxMovement = VECTOR2D();
494
495 for( EDA_ITEM* item : sel_items )
496 {
497 originalBBox.Merge( item->ViewBBox() );
498 }
499
500 updateBBox = false;
501 }
502
503 // Constrain selection bounding box to coordinates limits
504 movement = getSafeMovement( m_cursor - prevPos, originalBBox, bboxMovement );
505
506 // Apply constrained movement
507 m_cursor = prevPos + movement;
508
509 controls->ForceCursorPosition( true, m_cursor );
510 selection.SetReferencePoint( m_cursor );
511
512 prevPos = m_cursor;
513 bboxMovement += movement;
514
515 // Drag items to the current cursor position
516 for( EDA_ITEM* item : sel_items )
517 {
518 // Don't double move child items.
519 if( !item->GetParent() || !item->GetParent()->IsSelected() )
520 static_cast<BOARD_ITEM*>( item )->Move( movement );
521
522 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
523 {
525 static_cast<PCB_GENERATOR*>( item ) );
526 }
527
528 if( item->Type() == PCB_FOOTPRINT_T )
529 redraw3D = true;
530 }
531
532 if( redraw3D && allowRedraw3D )
533 editFrame->Update3DView( false, true );
534
535 if( showCourtyardConflicts && drc_on_move->m_FpInMove.size() )
536 {
537 drc_on_move->Run();
538 drc_on_move->UpdateConflicts( m_toolMgr->GetView(), true );
539 }
540
542 }
543 else if( !m_dragging && ( aAutoStart || !evt->IsAction( &ACTIONS::refreshPreview ) ) )
544 {
545 // Prepare to start dragging
546 editFrame->HideSolderMask();
547
548 m_dragging = true;
549
550 for( EDA_ITEM* item : selection )
551 {
552 if( item->GetParent() && item->GetParent()->IsSelected() )
553 continue;
554
555 if( !item->IsNew() && !item->IsMoving() )
556 {
557 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
558 {
559 enableLocalRatsnest = false;
560
562 static_cast<PCB_GENERATOR*>( item ) );
563 }
564 else
565 {
566 aCommit->Modify( item );
567 }
568
569 item->SetFlags( IS_MOVING );
570
571 static_cast<BOARD_ITEM*>( item )->RunOnDescendants(
572 [&]( BOARD_ITEM* bItem )
573 {
574 item->SetFlags( IS_MOVING );
575 } );
576 }
577 }
578
579 m_cursor = controls->GetCursorPosition();
580
581 if( selection.HasReferencePoint() )
582 {
583 // start moving with the reference point attached to the cursor
584 grid.SetAuxAxes( false );
585
586 if( hv45Mode )
587 {
588 VECTOR2I moveVector = m_cursor - originalPos;
589 m_cursor = originalPos + GetVectorSnapped45( moveVector );
590 }
591
592 movement = m_cursor - selection.GetReferencePoint();
593
594 // Drag items to the current cursor position
595 for( EDA_ITEM* item : selection )
596 {
597 // Don't double move footprint pads, fields, etc.
598 if( item->GetParent() && item->GetParent()->IsSelected() )
599 continue;
600
601 static_cast<BOARD_ITEM*>( item )->Move( movement );
602 }
603
604 selection.SetReferencePoint( m_cursor );
605 }
606 else
607 {
608 if( showCourtyardConflicts )
609 {
610 std::vector<FOOTPRINT*>& FPs = drc_on_move->m_FpInMove;
611
612 for( BOARD_ITEM* item : sel_items )
613 {
614 if( item->Type() == PCB_FOOTPRINT_T )
615 FPs.push_back( static_cast<FOOTPRINT*>( item ) );
616
617 item->RunOnDescendants(
618 [&]( BOARD_ITEM* descendent )
619 {
620 if( descendent->Type() == PCB_FOOTPRINT_T )
621 FPs.push_back( static_cast<FOOTPRINT*>( descendent ) );
622 } );
623 }
624 }
625
626 m_cursor = grid.BestDragOrigin( originalCursorPos, sel_items,
627 grid.GetSelectionGrid( selection ),
629
630 // Set the current cursor position to the first dragged item origin, so the
631 // movement vector could be computed later
632 if( moveWithReference )
633 {
634 selection.SetReferencePoint( pickedReferencePoint );
635 controls->ForceCursorPosition( true, pickedReferencePoint );
636 m_cursor = pickedReferencePoint;
637 }
638 else
639 {
640 // Check if user wants to warp the mouse to origin of moved object
641 if( !editFrame->GetMoveWarpsCursor() )
642 m_cursor = originalCursorPos; // No, so use original mouse pos instead
643
644 selection.SetReferencePoint( m_cursor );
645 grid.SetAuxAxes( true, m_cursor );
646 }
647
648 originalPos = m_cursor;
649 }
650
651 // Update variables for bounding box collision calculations
652 updateBBox = true;
653
654 controls->SetCursorPosition( m_cursor, false );
655
656 prevPos = m_cursor;
657 controls->SetAutoPan( true );
659 }
660
661 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
662
663 if( enableLocalRatsnest )
665 }
666 else if( evt->IsCancelInteractive() || evt->IsActivate() )
667 {
668 if( m_dragging && evt->IsCancelInteractive() )
669 evt->SetPassEvent( false );
670
671 restore_state = true; // Canceling the tool means that items have to be restored
672 break; // Finish
673 }
674 else if( evt->IsClick( BUT_RIGHT ) )
675 {
676 m_menu.ShowContextMenu( selection );
677 }
678 else if( evt->IsAction( &ACTIONS::undo ) || evt->IsAction( &ACTIONS::doDelete ) )
679 {
680 restore_state = true; // Perform undo locally
681 break; // Finish
682 }
683 else if( evt->IsAction( &ACTIONS::duplicate ) || evt->IsAction( &ACTIONS::cut ) )
684 {
685 }
686 else if( evt->IsAction( &PCB_ACTIONS::rotateCw )
688 || evt->IsAction( &PCB_ACTIONS::flip )
690 || evt->IsAction( &PCB_ACTIONS::mirrorV ) )
691 {
692 updateBBox = true;
693 eatFirstMouseUp = false;
694 evt->SetPassEvent();
695 }
696 else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) || isSkip )
697 {
698 // Eat mouse-up/-click events that leaked through from the lock dialog
699 if( eatFirstMouseUp && !evt->IsAction( &ACTIONS::cursorClick ) )
700 {
701 eatFirstMouseUp = false;
702 continue;
703 }
704 else if( moveIndividually && m_dragging )
705 {
706 // Put skipped items back where they started
707 if( isSkip )
708 orig_items[itemIdx]->SetPosition( originalPos );
709
710 view()->Update( orig_items[itemIdx] );
712
713 if( ++itemIdx < orig_items.size() )
714 {
715 BOARD_ITEM* nextItem = orig_items[itemIdx];
716
718
719 originalPos = nextItem->GetPosition();
720 m_selectionTool->AddItemToSel( nextItem );
721 selection.SetReferencePoint( originalPos );
722
723 sel_items.clear();
724 sel_items.push_back( nextItem );
725 updateStatusPopup( nextItem, itemIdx + 1, orig_items.size() );
726
727 // Pick up new item
728 aCommit->Modify( nextItem );
729 nextItem->Move( controls->GetCursorPosition( true ) - nextItem->GetPosition() );
730
731 continue;
732 }
733 }
734
735 break; // finish
736 }
737 else if( evt->IsDblClick( BUT_LEFT ) )
738 {
739 // The first click will move the new item, so put it back
740 if( moveIndividually )
741 orig_items[itemIdx]->SetPosition( originalPos );
742
743 break; // finish
744 }
745 else if( evt->IsAction( &PCB_ACTIONS::toggleHV45Mode ) )
746 {
747 hv45Mode = !hv45Mode;
748 displayConstraintsMessage( hv45Mode );
749 evt->SetPassEvent( false );
750 }
756 || evt->IsAction( &ACTIONS::redo ) )
757 {
758 wxBell();
759 }
760 else
761 {
762 evt->SetPassEvent();
763 }
764
765 } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
766
767 // Clear temporary COURTYARD_CONFLICT flag and ensure the conflict shadow is cleared
768 if( showCourtyardConflicts )
769 drc_on_move->ClearConflicts( m_toolMgr->GetView() );
770
771 controls->ForceCursorPosition( false );
772 controls->ShowCursor( false );
773 controls->SetAutoPan( false );
774
775 m_dragging = false;
776
777 // Discard reference point when selection is "dropped" onto the board
778 selection.ClearReferencePoint();
779
780 // Unselect all items to clear selection flags and then re-select the originally selected
781 // items.
783
784 if( restore_state )
785 {
786 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
787 {
789 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
790 }
791 }
792 else
793 {
794 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
795 {
797 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
798 }
799
800 EDA_ITEMS oItems( orig_items.begin(), orig_items.end() );
802 }
803
804 // Remove the dynamic ratsnest from the screen
806
807 editFrame->PopTool( aEvent );
808 editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
809
810 return !restore_state;
811}
812
BOX2< VECTOR2I > BOX2I
Definition: box2.h:887
@ 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:435
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:2864
bool m_dragging
Definition: edit_tool.h:225
int Move(const TOOL_EVENT &aEvent)
Main loop in which events are handled.
static const unsigned int COORDS_PADDING
Definition: edit_tool.h:230
VECTOR2I getSafeMovement(const VECTOR2I &aMovement, const BOX2I &aSourceBBox, const VECTOR2D &aBBoxOffset)
VECTOR2I m_cursor
Definition: edit_tool.h:226
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:3043
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:224
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:2369
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:2238
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:59
DISPLAY_OPTIONS m_Display
bool m_ShowCourtyardCollisions
static TOOL_ACTION toggleHV45Mode
Definition: pcb_actions.h:512
static TOOL_ACTION mirrorH
Mirroring of selected items.
Definition: pcb_actions.h:139
static TOOL_ACTION genPushEdit
Definition: pcb_actions.h:281
static TOOL_ACTION hideLocalRatsnest
Definition: pcb_actions.h:556
static TOOL_ACTION genStartEdit
Definition: pcb_actions.h:279
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:177
static TOOL_ACTION copyWithReference
copy command with manual reference point selection
Definition: pcb_actions.h:129
static TOOL_ACTION genUpdateEdit
Definition: pcb_actions.h:280
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:557
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:315
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:282
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)
const std::vector< EDA_ITEM * > GetItemsSortedBySelectionOrder() const
Definition: selection.cpp:222
bool IsHover() const
Definition: selection.h:83
int Size() const
Returns the number of selected parts.
Definition: selection.h:115
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:109
bool HasReferencePoint() const
Definition: selection.h:247
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: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
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: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
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:587