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 std::unique_ptr<STATUS_TEXT_POPUP> statusPopup;
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 if( !statusPopup )
351 statusPopup = std::make_unique<STATUS_TEXT_POPUP>( frame() );
352
353 statusPopup->SetText( wxString::Format( popuptext, msg, ii, count ) );
354 };
355
356 std::vector<BOARD_ITEM*> sel_items; // All the items operated on by the move below
357 std::vector<BOARD_ITEM*> orig_items; // All the original items in the selection
358
359 for( EDA_ITEM* item : selection )
360 {
361 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
362 {
363 if( !selection.IsHover() )
364 orig_items.push_back( boardItem );
365
366 sel_items.push_back( boardItem );
367 }
368
369 if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item ) )
370 {
371 for( PAD* pad : footprint->Pads() )
372 sel_items.push_back( pad );
373
374 // Clear this flag here; it will be set by the netlist updater if the footprint is new
375 // so that it was skipped in the initial connectivity update in OnNetlistChanged
377 }
378 }
379
380 VECTOR2I pickedReferencePoint;
381
382 if( moveWithReference && !pickReferencePoint( _( "Select reference point for move..." ), "", "",
383 pickedReferencePoint ) )
384 {
385 if( selection.IsHover() )
387
388 editFrame->PopTool( aEvent );
389 return false;
390 }
391
392 if( moveIndividually )
393 {
394 orig_items.clear();
395
396 for( EDA_ITEM* item : selection.GetItemsSortedBySelectionOrder() )
397 {
398 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item ) )
399 orig_items.push_back( boardItem );
400 }
401
402 updateStatusPopup( orig_items[ itemIdx ], itemIdx + 1, orig_items.size() );
403 statusPopup->Popup();
404 statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
405 canvas()->SetStatusPopup( statusPopup->GetPanel() );
406
408 m_selectionTool->AddItemToSel( orig_items[ itemIdx ] );
409
410 sel_items.clear();
411 sel_items.push_back( orig_items[ itemIdx ] );
412 }
413
414 bool restore_state = false;
415 VECTOR2I originalPos;
416 VECTOR2D bboxMovement;
417 BOX2I originalBBox;
418 bool updateBBox = true;
419 LSET layers( editFrame->GetActiveLayer() );
421 TOOL_EVENT copy = aEvent;
422 TOOL_EVENT* evt = &copy;
423 VECTOR2I prevPos;
424 bool enableLocalRatsnest = true;
425
426 bool hv45Mode = false;
427 bool eatFirstMouseUp = true;
428 bool allowRedraw3D = cfg->m_Display.m_Live3DRefresh;
429 bool showCourtyardConflicts = !m_isFootprintEditor && cfg->m_ShowCourtyardCollisions;
430
431 // Used to test courtyard overlaps
432 std::unique_ptr<DRC_INTERACTIVE_COURTYARD_CLEARANCE> drc_on_move = nullptr;
433
434 if( showCourtyardConflicts )
435 {
436 std::shared_ptr<DRC_ENGINE> drcEngine = m_toolMgr->GetTool<DRC_TOOL>()->GetDRCEngine();
437 drc_on_move.reset( new DRC_INTERACTIVE_COURTYARD_CLEARANCE( drcEngine ) );
438 drc_on_move->Init( board );
439 }
440
441 displayConstraintsMessage( hv45Mode );
442
443 // Prime the pump
445
446 // Main loop: keep receiving events
447 do
448 {
449 VECTOR2I movement;
450 editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::MOVING );
451 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
452 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
453
454 bool isSkip = evt->IsAction( &PCB_ACTIONS::skip ) && moveIndividually;
455
456 if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
457 eatFirstMouseUp = false;
458
459 if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
463 {
464 if( m_dragging && evt->Category() == TC_MOUSE )
465 {
466 bool redraw3D = false;
467
468 VECTOR2I mousePos( controls->GetMousePosition() );
469
470 m_cursor = grid.BestSnapAnchor( mousePos, layers,
471 grid.GetSelectionGrid( selection ), sel_items );
472
474 {
475 long action = controls->GetSettings().m_lastKeyboardCursorCommand;
476
477 // The arrow keys are by definition SINGLE AXIS. Do not allow the other
478 // axis to be snapped to the grid.
479 if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
480 m_cursor.y = prevPos.y;
481 else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
482 m_cursor.x = prevPos.x;
483 }
484
485 if( !selection.HasReferencePoint() )
486 originalPos = m_cursor;
487
488 if( hv45Mode )
489 {
490 VECTOR2I moveVector = m_cursor - originalPos;
491 m_cursor = originalPos + GetVectorSnapped45( moveVector );
492 }
493
494 if( updateBBox )
495 {
496 originalBBox = BOX2I();
497 bboxMovement = VECTOR2D();
498
499 for( EDA_ITEM* item : sel_items )
500 {
501 originalBBox.Merge( item->ViewBBox() );
502 }
503
504 updateBBox = false;
505 }
506
507 // Constrain selection bounding box to coordinates limits
508 movement = getSafeMovement( m_cursor - prevPos, originalBBox, bboxMovement );
509
510 // Apply constrained movement
511 m_cursor = prevPos + movement;
512
513 controls->ForceCursorPosition( true, m_cursor );
514 selection.SetReferencePoint( m_cursor );
515
516 prevPos = m_cursor;
517 bboxMovement += movement;
518
519 // Drag items to the current cursor position
520 for( EDA_ITEM* item : sel_items )
521 {
522 // Don't double move child items.
523 if( !item->GetParent() || !item->GetParent()->IsSelected() )
524 static_cast<BOARD_ITEM*>( item )->Move( movement );
525
526 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
527 {
529 static_cast<PCB_GENERATOR*>( item ) );
530 }
531
532 if( item->Type() == PCB_FOOTPRINT_T )
533 redraw3D = true;
534 }
535
536 if( redraw3D && allowRedraw3D )
537 editFrame->Update3DView( false, true );
538
539 if( showCourtyardConflicts && drc_on_move->m_FpInMove.size() )
540 {
541 drc_on_move->Run();
542 drc_on_move->UpdateConflicts( m_toolMgr->GetView(), true );
543 }
544
546 }
547 else if( !m_dragging && ( aAutoStart || !evt->IsAction( &ACTIONS::refreshPreview ) ) )
548 {
549 // Prepare to start dragging
550 editFrame->HideSolderMask();
551
552 m_dragging = true;
553
554 for( EDA_ITEM* item : selection )
555 {
556 if( item->GetParent() && item->GetParent()->IsSelected() )
557 continue;
558
559 if( !item->IsNew() && !item->IsMoving() )
560 {
561 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
562 {
563 enableLocalRatsnest = false;
564
566 static_cast<PCB_GENERATOR*>( item ) );
567 }
568 else
569 {
570 aCommit->Modify( item );
571 }
572
573 item->SetFlags( IS_MOVING );
574
575 static_cast<BOARD_ITEM*>( item )->RunOnDescendants(
576 [&]( BOARD_ITEM* bItem )
577 {
578 item->SetFlags( IS_MOVING );
579 } );
580 }
581 }
582
583 m_cursor = controls->GetCursorPosition();
584
585 if( selection.HasReferencePoint() )
586 {
587 // start moving with the reference point attached to the cursor
588 grid.SetAuxAxes( false );
589
590 if( hv45Mode )
591 {
592 VECTOR2I moveVector = m_cursor - originalPos;
593 m_cursor = originalPos + GetVectorSnapped45( moveVector );
594 }
595
596 movement = m_cursor - selection.GetReferencePoint();
597
598 // Drag items to the current cursor position
599 for( EDA_ITEM* item : selection )
600 {
601 // Don't double move footprint pads, fields, etc.
602 if( item->GetParent() && item->GetParent()->IsSelected() )
603 continue;
604
605 static_cast<BOARD_ITEM*>( item )->Move( movement );
606 }
607
608 selection.SetReferencePoint( m_cursor );
609 }
610 else
611 {
612 if( showCourtyardConflicts )
613 {
614 std::vector<FOOTPRINT*>& FPs = drc_on_move->m_FpInMove;
615
616 for( BOARD_ITEM* item : sel_items )
617 {
618 if( item->Type() == PCB_FOOTPRINT_T )
619 FPs.push_back( static_cast<FOOTPRINT*>( item ) );
620
621 item->RunOnDescendants(
622 [&]( BOARD_ITEM* descendent )
623 {
624 if( descendent->Type() == PCB_FOOTPRINT_T )
625 FPs.push_back( static_cast<FOOTPRINT*>( descendent ) );
626 } );
627 }
628 }
629
630 m_cursor = grid.BestDragOrigin( originalCursorPos, sel_items,
631 grid.GetSelectionGrid( selection ),
633
634 // Set the current cursor position to the first dragged item origin, so the
635 // movement vector could be computed later
636 if( moveWithReference )
637 {
638 selection.SetReferencePoint( pickedReferencePoint );
639 controls->ForceCursorPosition( true, pickedReferencePoint );
640 m_cursor = pickedReferencePoint;
641 }
642 else
643 {
644 // Check if user wants to warp the mouse to origin of moved object
645 if( !editFrame->GetMoveWarpsCursor() )
646 m_cursor = originalCursorPos; // No, so use original mouse pos instead
647
648 selection.SetReferencePoint( m_cursor );
649 grid.SetAuxAxes( true, m_cursor );
650 }
651
652 originalPos = m_cursor;
653 }
654
655 // Update variables for bounding box collision calculations
656 updateBBox = true;
657
658 controls->SetCursorPosition( m_cursor, false );
659
660 prevPos = m_cursor;
661 controls->SetAutoPan( true );
663 }
664
665 if( statusPopup )
666 statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
667
668 if( enableLocalRatsnest )
670 }
671 else if( evt->IsCancelInteractive() || evt->IsActivate() )
672 {
673 if( m_dragging && evt->IsCancelInteractive() )
674 evt->SetPassEvent( false );
675
676 restore_state = true; // Canceling the tool means that items have to be restored
677 break; // Finish
678 }
679 else if( evt->IsClick( BUT_RIGHT ) )
680 {
682 }
683 else if( evt->IsAction( &ACTIONS::undo ) || evt->IsAction( &ACTIONS::doDelete ) )
684 {
685 restore_state = true; // Perform undo locally
686 break; // Finish
687 }
688 else if( evt->IsAction( &ACTIONS::duplicate ) || evt->IsAction( &ACTIONS::cut ) )
689 {
690 }
691 else if( evt->IsAction( &PCB_ACTIONS::rotateCw )
693 || evt->IsAction( &PCB_ACTIONS::flip )
695 || evt->IsAction( &PCB_ACTIONS::mirrorV ) )
696 {
697 updateBBox = true;
698 eatFirstMouseUp = false;
699 evt->SetPassEvent();
700 }
701 else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) || isSkip )
702 {
703 // Eat mouse-up/-click events that leaked through from the lock dialog
704 if( eatFirstMouseUp && !evt->IsAction( &ACTIONS::cursorClick ) )
705 {
706 eatFirstMouseUp = false;
707 continue;
708 }
709 else if( moveIndividually && m_dragging )
710 {
711 // Put skipped items back where they started
712 if( isSkip )
713 orig_items[itemIdx]->SetPosition( originalPos );
714
715 view()->Update( orig_items[itemIdx] );
717
718 if( ++itemIdx < orig_items.size() )
719 {
720 BOARD_ITEM* nextItem = orig_items[itemIdx];
721
723
724 originalPos = nextItem->GetPosition();
725 m_selectionTool->AddItemToSel( nextItem );
726 selection.SetReferencePoint( originalPos );
727
728 sel_items.clear();
729 sel_items.push_back( nextItem );
730 updateStatusPopup( nextItem, itemIdx + 1, orig_items.size() );
731
732 // Pick up new item
733 aCommit->Modify( nextItem );
734 nextItem->Move( controls->GetCursorPosition( true ) - nextItem->GetPosition() );
735
736 continue;
737 }
738 }
739
740 break; // finish
741 }
742 else if( evt->IsDblClick( BUT_LEFT ) )
743 {
744 // The first click will move the new item, so put it back
745 if( moveIndividually )
746 orig_items[itemIdx]->SetPosition( originalPos );
747
748 break; // finish
749 }
750 else if( evt->IsAction( &PCB_ACTIONS::toggleHV45Mode ) )
751 {
752 hv45Mode = !hv45Mode;
753 displayConstraintsMessage( hv45Mode );
754 evt->SetPassEvent( false );
755 }
761 || evt->IsAction( &ACTIONS::redo ) )
762 {
763 wxBell();
764 }
765 else
766 {
767 evt->SetPassEvent();
768 }
769
770 } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
771
772 // Clear temporary COURTYARD_CONFLICT flag and ensure the conflict shadow is cleared
773 if( showCourtyardConflicts )
774 drc_on_move->ClearConflicts( m_toolMgr->GetView() );
775
776 controls->ForceCursorPosition( false );
777 controls->ShowCursor( false );
778 controls->SetAutoPan( false );
779
780 m_dragging = false;
781
782 // Discard reference point when selection is "dropped" onto the board
783 selection.ClearReferencePoint();
784
785 // Unselect all items to clear selection flags and then re-select the originally selected
786 // items.
788
789 if( restore_state )
790 {
791 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
792 {
794 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
795 }
796 }
797 else
798 {
799 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
800 {
802 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
803 }
804
805 EDA_ITEMS oItems( orig_items.begin(), orig_items.end() );
807 }
808
809 // Remove the dynamic ratsnest from the screen
811
812 editFrame->PopTool( aEvent );
813 editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
814
815 return !restore_state;
816}
817
BOX2< VECTOR2I > BOX2I
Definition: box2.h:877
@ CURSOR_RIGHT
Definition: actions.h:246
@ CURSOR_LEFT
Definition: actions.h:244
@ CURSOR_UP
Definition: actions.h:240
@ CURSOR_DOWN
Definition: actions.h:242
static TOOL_ACTION undo
Definition: actions.h:68
static TOOL_ACTION duplicate
Definition: actions.h:76
static TOOL_ACTION doDelete
Definition: actions.h:77
static TOOL_ACTION cursorClick
Definition: actions.h:159
static TOOL_ACTION redo
Definition: actions.h:69
static TOOL_ACTION cut
Definition: actions.h:70
static TOOL_ACTION refreshPreview
Definition: actions.h:139
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:79
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:240
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition: board_item.h:330
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:276
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:289
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:89
virtual VECTOR2I GetPosition() const
Definition: eda_item.h:243
virtual void SetPosition(const VECTOR2I &aPos)
Definition: eda_item.h:244
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:127
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
bool IsSelected() const
Definition: eda_item.h:110
EDA_ITEM * GetParent() const
Definition: eda_item.h:103
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:108
bool IsNew() const
Definition: eda_item.h:107
bool isRouterActive() const
Definition: edit_tool.cpp:448
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:2975
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:3154
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:229
static const TOOL_EVENT SelectedEvent
Definition: actions.h:270
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:277
static const TOOL_EVENT SelectedItemsMoved
Used to inform tools that the selection should temporarily be non-editable.
Definition: actions.h:280
EDA_ANGLE GetOrientation() const
Definition: footprint.h:216
void SetOrientation(const EDA_ANGLE &aNewAngle)
Definition: footprint.cpp:2415
void SetAttributes(int aAttributes)
Definition: footprint.h:280
int GetAttributes() const
Definition: footprint.h:279
bool IsFlipped() const
Definition: footprint.h:380
PADS & Pads()
Definition: footprint.h:195
void Flip(const VECTOR2I &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:2284
const wxString & GetReference() const
Definition: footprint.h:591
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:207
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: lset.h:35
Definition: pad.h:54
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:283
static TOOL_ACTION hideLocalRatsnest
Definition: pcb_actions.h:556
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: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: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:265
void ClearReferencePoint()
Definition: selection.cpp:186
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.cpp:180
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:110
bool HasReferencePoint() const
Definition: selection.h:211
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:218
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 & GetToolMenu()
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:536
#define IS_MOVING
Item being moved.
@ FP_JUST_ADDED
Definition: footprint.h:79
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: wxgtk/ui.cpp:611
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:121
VECTOR2< double > VECTOR2D
Definition: vector2d.h:672