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 The 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#include <functional>
24#include <algorithm>
25#include <limits>
26#include <kiplatform/ui.h>
27#include <board.h>
28#include <board_commit.h>
29#include <collectors.h>
30#include <footprint.h>
33#include <pad.h>
34#include <padstack.h>
35#include <pcb_group.h>
36#include <pcb_generator.h>
37#include <pcb_grid_item.h>
38#include <pcb_edit_frame.h>
39#include <spread_footprints.h>
40#include <tool/tool_manager.h>
41#include <tools/pcb_actions.h>
44#include <tools/edit_tool.h>
46#include <tools/drc_tool.h>
49#include <router/router_tool.h>
51#include <zone_filler.h>
52#include <drc/drc_engine.h>
55#include <view/view_controls.h>
56
58#include <wx/richmsgdlg.h>
59#include <wx/choicdlg.h>
60#include <unordered_set>
61#include <unordered_map>
62
63
64static bool PromptConnectedPadDecision( PCB_BASE_EDIT_FRAME* aFrame, const std::vector<PAD*>& aPads,
65 const wxString& aDialogTitle, bool& aIncludeConnectedPads )
66{
67 if( aPads.empty() )
68 {
69 aIncludeConnectedPads = true;
70 return true;
71 }
72
73 std::unordered_set<PAD*> uniquePads( aPads.begin(), aPads.end() );
74
75 wxString msg;
76 msg.Printf( _( "%zu unselected pad(s) are connected to these nets. How do you want to proceed?" ),
77 uniquePads.size() );
78
79 wxString details;
80 details << _( "Connected tracks, vias, and other non-zone copper items will still swap nets"
81 " even if you ignore the unselected pads." )
82 << "\n \n" // Add space so GTK doesn't eat the newlines
83 << _( "Unselected pads:" ) << '\n';
84
85 for( PAD* pad : uniquePads )
86 {
87 const FOOTPRINT* fp = pad->GetParentFootprint();
88 details << wxS( " • " ) << ( fp ? fp->GetReference() : _( "<no reference designator>" ) ) << wxS( ":" )
89 << pad->GetNumber() << '\n';
90 }
91
92
93 wxRichMessageDialog dlg( aFrame, msg, aDialogTitle, wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxICON_WARNING );
94 dlg.SetYesNoLabels( _( "Ignore Unselected Pads" ), _( "Swap All Connected Pads" ) );
95 dlg.SetExtendedMessage( details );
96
97 int ret = dlg.ShowModal();
98
99 if( ret == wxID_CANCEL )
100 return false;
101
102 aIncludeConnectedPads = ( ret == wxID_NO );
103 return true;
104}
105
106
107// Makes sure we don't try to assign two different new nets to an item. Assigning
108// the same net to the item multiples times is fine.
109static bool ScheduleNetSwap( BOARD_CONNECTED_ITEM* aItem, int aNewNet,
110 std::unordered_map<BOARD_CONNECTED_ITEM*, int>& aItemNewNets,
111 wxString& aError )
112{
113 auto [it, inserted] = aItemNewNets.emplace( aItem, aNewNet );
114
115 if( !inserted && it->second != aNewNet )
116 {
117 aError = _( "Cannot swap nets: connected items would receive conflicting nets." );
118 return false;
119 }
120
121 return true;
122}
123
124
125// Make sure everything we're trying to swap is unlocked or we're overriding
127 const std::unordered_map<BOARD_CONNECTED_ITEM*, int>& aItemNewNets,
128 const std::unordered_set<PAD*>& aSwapPads, bool aIncludeConnectedPads )
129{
130 if( aFrame->GetOverrideLocks() )
131 return true;
132
133 for( const auto& [item, newNet] : aItemNewNets )
134 {
135 if( item->GetNetCode() == newNet )
136 continue;
137
138 if( item->Type() == PCB_PAD_T && !aIncludeConnectedPads
139 && !aSwapPads.count( static_cast<PAD*>( item ) ) )
140 continue;
141
142 if( item->IsLocked() )
143 {
144 aFrame->ShowInfoBarError( _( "Cannot swap nets of locked pads or connected copper unless "
145 "Override Locks is enabled." ) );
146 return false;
147 }
148 }
149
150 return true;
151}
152
153
154int EDIT_TOOL::Swap( const TOOL_EVENT& aEvent )
155{
156 if( isRouterActive() )
157 {
158 wxBell();
159 return 0;
160 }
161
162 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
163 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
164 {
165 sTool->FilterCollectorForMarkers( aCollector );
166 sTool->FilterCollectorForHierarchy( aCollector, true );
167 sTool->FilterCollectorForFreePads( aCollector );
168
169 // Iterate from the back so we don't have to worry about removals.
170 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
171 {
172 BOARD_ITEM* item = aCollector[i];
173
174 if( item->Type() == PCB_TRACE_T )
175 aCollector.Remove( item );
176 }
177
178 sTool->FilterCollectorForLockedItems( aCollector );
179 } );
180
181 m_selectionTool->ReportFilteredLockedItems();
182
183 if( selection.Size() < 2 )
184 return 0;
185
187 BOARD_COMMIT localCommit( this );
188 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
189
190 if( !commit )
191 commit = &localCommit;
192
193 std::vector<EDA_ITEM*> sorted = selection.GetItemsSortedBySelectionOrder();
194
195 // Save items, so changes can be undone
196 for( EDA_ITEM* item : selection )
197 commit->Modify( item, nullptr, RECURSE_MODE::RECURSE );
198
199 for( size_t i = 0; i < sorted.size() - 1; i++ )
200 {
201 EDA_ITEM* edaItemA = sorted[i];
202 EDA_ITEM* edaItemB = sorted[( i + 1 ) % sorted.size()];
203
204 if( !edaItemA->IsBOARD_ITEM() || !edaItemB->IsBOARD_ITEM() )
205 continue;
206
207 BOARD_ITEM* a = static_cast<BOARD_ITEM*>( edaItemA );
208 BOARD_ITEM* b = static_cast<BOARD_ITEM*>( edaItemB );
209
210 // Pads may have a copper shape offset from the anchor/hole, so swap visible shape
211 // centers rather than anchor positions. See PAD::SwapShapePositions.
212 if( a->Type() == PCB_PAD_T && b->Type() == PCB_PAD_T )
213 {
214 PAD::SwapShapePositions( static_cast<PAD*>( a ), static_cast<PAD*>( b ), editFrame->GetActiveLayer() );
215
216 PCB_LAYER_ID aLayer = a->GetLayer(), bLayer = b->GetLayer();
217 std::swap( aLayer, bLayer );
218 a->SetLayer( aLayer );
219 b->SetLayer( bLayer );
220
221 continue;
222 }
223
224 // Swap X,Y position
225 VECTOR2I aPos = a->GetPosition(), bPos = b->GetPosition();
226 std::swap( aPos, bPos );
227 a->SetPosition( aPos );
228 b->SetPosition( bPos );
229
230 // Handle footprints specially. They can be flipped to the back of the board which
231 // requires a special transformation.
232 if( a->Type() == PCB_FOOTPRINT_T && b->Type() == PCB_FOOTPRINT_T )
233 {
234 FOOTPRINT* aFP = static_cast<FOOTPRINT*>( a );
235 FOOTPRINT* bFP = static_cast<FOOTPRINT*>( b );
236
237 // Store initial orientation of footprints, before flipping them.
238 EDA_ANGLE aAngle = aFP->GetOrientation();
239 EDA_ANGLE bAngle = bFP->GetOrientation();
240
241 // Flip both if needed
242 if( aFP->IsFlipped() != bFP->IsFlipped() )
243 {
244 aFP->Flip( aPos, FLIP_DIRECTION::TOP_BOTTOM );
245 bFP->Flip( bPos, FLIP_DIRECTION::TOP_BOTTOM );
246 }
247
248 // Set orientation
249 std::swap( aAngle, bAngle );
250 aFP->SetOrientation( aAngle );
251 bFP->SetOrientation( bAngle );
252 }
253 // We can also do a layer swap safely for two objects of the same type,
254 // except groups which don't support layer swaps.
255 else if( a->Type() == b->Type() && a->Type() != PCB_GROUP_T )
256 {
257 // Swap layers
258 PCB_LAYER_ID aLayer = a->GetLayer(), bLayer = b->GetLayer();
259 std::swap( aLayer, bLayer );
260 a->SetLayer( aLayer );
261 b->SetLayer( bLayer );
262 }
263 }
264
265 if( !localCommit.Empty() )
266 localCommit.Push( _( "Swap" ) );
267
269
270 return 0;
271}
272
273
275{
276 if( isRouterActive() )
277 {
278 wxBell();
279 return 0;
280 }
281
283
284 if( selection.Size() < 2 || !selection.OnlyContains( { PCB_PAD_T } ) )
285 return 0;
286
287 // Get selected pads in selection order, because swapping is cyclic and we let the user pick
288 // the rotation order
289 std::vector<EDA_ITEM*> orderedPads = selection.GetItemsSortedBySelectionOrder();
290 std::vector<PAD*> pads;
291 const size_t padsCount = orderedPads.size();
292
293 for( EDA_ITEM* it : orderedPads )
294 pads.push_back( static_cast<PAD*>( static_cast<BOARD_ITEM*>( it ) ) );
295
296 // Record original nets and build selected set for quick membership tests
297 std::vector<int> originalNets( padsCount );
298 std::unordered_set<PAD*> selectedPads;
299
300 for( size_t i = 0; i < padsCount; ++i )
301 {
302 originalNets[i] = pads[i]->GetNetCode();
303 selectedPads.insert( pads[i] );
304 }
305
306 if( std::ranges::all_of( originalNets,
307 [&]( int net )
308 {
309 return net == originalNets.front();
310 } ) )
311 return 0;
312
313 // Desired new nets are a cyclic rotation of original nets (like Swap positions)
314 auto newNetForIndex =
315 [&]( size_t i )
316 {
317 return originalNets[( i + 1 ) % padsCount];
318 };
319
320 // Take an event commit since we will eventually support this while actively routing the board
321 BOARD_COMMIT localCommit( this );
322 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
323
324 if( !commit )
325 commit = &localCommit;
326
327 // Connectivity to find items connected to each pad
328 std::shared_ptr<CONNECTIVITY_DATA> connectivity = board()->GetConnectivity();
329
330 // Accumulate changes: for each item, assign the resulting new net
331 std::unordered_map<BOARD_CONNECTED_ITEM*, int> itemNewNets;
332 std::vector<PAD*> nonSelectedPadsToChange;
333 wxString error;
334
335 // Include the direct pad changes so connectivity cannot assign them a conflicting net.
336 for( size_t i = 0; i < padsCount; ++i )
337 {
338 if( !ScheduleNetSwap( pads[i], newNetForIndex( i ), itemNewNets, error ) )
339 {
340 frame()->ShowInfoBarError( error );
341 return 0;
342 }
343 }
344
345 for( size_t i = 0; i < padsCount; ++i )
346 {
347 PAD* pad = pads[i];
348 int fromNet = originalNets[i];
349 int toNet = newNetForIndex( i );
350
351 // For each connected item, if it matches fromNet, schedule it for toNet
352 // Exclude zones, user probably doesn't want to change zone nets
353 for( BOARD_CONNECTED_ITEM* ci : connectivity->GetConnectedItems( pad, EXCLUDE_ZONES ) )
354 {
355 switch( ci->Type() )
356 {
357 case PCB_TRACE_T:
358 case PCB_ARC_T:
359 case PCB_VIA_T:
360 case PCB_PAD_T:
361 case PCB_SHAPE_T:
362 break;
363 default:
364 continue;
365 }
366
367 if( ci->GetNetCode() != fromNet )
368 continue;
369
370 if( !ScheduleNetSwap( ci, toNet, itemNewNets, error ) )
371 {
372 frame()->ShowInfoBarError( error );
373 return 0;
374 }
375
376 if( ci->Type() == PCB_PAD_T )
377 {
378 PAD* otherPad = static_cast<PAD*>( ci );
379
380 if( !selectedPads.count( otherPad ) )
381 nonSelectedPadsToChange.push_back( otherPad );
382 }
383 }
384 }
385
386 bool includeConnectedPads = true;
387
388 if( !PromptConnectedPadDecision( frame(), nonSelectedPadsToChange, _( "Swap Pad Nets" ), includeConnectedPads ) )
389 return 0;
390
391 if( !ValidateNetSwapLocks( frame(), itemNewNets, selectedPads, includeConnectedPads ) )
392 return 0;
393
394 // Apply changes
395 // 1) Selected pads get their new nets directly
396 for( size_t i = 0; i < padsCount; ++i )
397 {
398 if( pads[i]->GetNetCode() == newNetForIndex( i ) )
399 continue;
400
401 commit->Modify( pads[i] );
402 pads[i]->SetNetCode( newNetForIndex( i ) );
403 }
404
405 // 2) Connected items propagate, depending on user choice
406 for( const auto& itemNewNet : itemNewNets )
407 {
408 BOARD_CONNECTED_ITEM* item = itemNewNet.first;
409 int newNet = itemNewNet.second;
410
411 if( item->Type() == PCB_PAD_T )
412 {
413 PAD* p = static_cast<PAD*>( item );
414
415 if( selectedPads.count( p ) )
416 continue; // already changed above
417
418 if( !includeConnectedPads )
419 continue; // skip non-selected pads if requested
420 }
421
422 if( item->GetNetCode() == newNet )
423 continue;
424
425 commit->Modify( item );
426 item->SetNetCode( newNet );
427 }
428
429 if( !localCommit.Empty() )
430 localCommit.Push( _( "Swap Pad Nets" ) );
431
432 // Ensure connectivity visuals update
435
436 return 0;
437}
438
439
441{
442 if( isRouterActive() )
443 {
444 wxBell();
445 return 0;
446 }
447
448 auto showError =
449 [this]()
450 {
451 frame()->ShowInfoBarError( _( "Gate swapping must be performed on pads within one multi-gate "
452 "footprint." ) );
453 };
454
456
457 // Get our sanity checks out of the way to clean up later loops
458 FOOTPRINT* targetFp = nullptr;
459 bool fail = false;
460
461 for( EDA_ITEM* it : selection )
462 {
463 // This shouldn't happen due to the filter, but just in case
464 if( it->Type() != PCB_PAD_T )
465 {
466 fail = true;
467 break;
468 }
469
470 FOOTPRINT* fp = static_cast<PAD*>( static_cast<BOARD_ITEM*>( it ) )->GetParentFootprint();
471
472 if( !targetFp )
473 {
474 targetFp = fp;
475 }
476 else if( fp && targetFp != fp )
477 {
478 fail = true;
479 break;
480 }
481 }
482
483 if( fail || !targetFp || targetFp->GetUnitInfo().size() < 2 )
484 {
485 showError();
486 return 0;
487 }
488
489
490 const auto& units = targetFp->GetUnitInfo();
491
492 // Collect unit hits and ordered unit list based on selection order
493 std::vector<bool> unitHit( units.size(), false );
494 std::vector<int> unitOrder;
495
496 std::vector<EDA_ITEM*> orderedPads = selection.GetItemsSortedBySelectionOrder();
497
498 for( EDA_ITEM* it : orderedPads )
499 {
500 PAD* pad = static_cast<PAD*>( static_cast<BOARD_ITEM*>( it ) );
501
502 const wxString& padNum = pad->GetNumber();
503 int unitIdx = -1;
504
505 for( size_t i = 0; i < units.size(); ++i )
506 {
507 for( const auto& p : units[i].m_pins )
508 {
509 if( p == padNum )
510 {
511 unitIdx = static_cast<int>( i );
512
513 if( !unitHit[i] )
514 unitOrder.push_back( unitIdx );
515
516 unitHit[i] = true;
517 break;
518 }
519 }
520
521 if( unitIdx >= 0 )
522 break;
523 }
524 }
525
526 // Determine active units from selection order: 0 -> bail, 1 -> single-unit flow, 2+ -> cycle
527 std::vector<int> activeUnitIdx;
528 int sourceIdx = -1;
529
530 if( unitOrder.size() >= 2 )
531 {
532 activeUnitIdx = unitOrder;
533 sourceIdx = unitOrder.front();
534 }
535 // If we only have one gate selected, we must have a target unit name parameter to proceed
536 else if( unitOrder.size() == 1 && aEvent.HasParameter() )
537 {
538 sourceIdx = unitOrder.front();
539 wxString targetUnitByName = aEvent.Parameter<wxString>();
540
541 int targetIdx = -1;
542
543 for( size_t i = 0; i < units.size(); ++i )
544 {
545 if( static_cast<int>( i ) == sourceIdx )
546 continue;
547
548 if( units[i].m_pins.size() == units[sourceIdx].m_pins.size() && units[i].m_unitName == targetUnitByName )
549 targetIdx = static_cast<int>( i );
550 }
551
552 if( targetIdx < 0 )
553 {
554 showError();
555 return 0;
556 }
557
558 activeUnitIdx.push_back( sourceIdx );
559 activeUnitIdx.push_back( targetIdx );
560 }
561 else
562 {
563 showError();
564 return 0;
565 }
566
567 // Verify equal pin counts across all active units
568 const size_t pinCount = units[activeUnitIdx.front()].m_pins.size();
569
570 for( int idx : activeUnitIdx )
571 {
572 if( units[idx].m_pins.size() != pinCount )
573 {
574 frame()->ShowInfoBarError( _( "Gate swapping must be performed on gates with equal pin counts." ) );
575 return 0;
576 }
577 }
578
579 // Build per-unit pad arrays and net vectors
580 const size_t unitCount = activeUnitIdx.size();
581 std::vector<std::vector<PAD*>> unitPads( unitCount );
582 std::vector<std::vector<int>> unitNets( unitCount );
583
584 for( size_t ui = 0; ui < unitCount; ++ui )
585 {
586 int uidx = activeUnitIdx[ui];
587 const auto& pins = units[uidx].m_pins;
588
589 for( size_t pi = 0; pi < pinCount; ++pi )
590 {
591 PAD* p = targetFp->FindPadByNumber( pins[pi] );
592
593 if( !p )
594 {
595 frame()->ShowInfoBarError( _( "Gate swapping failed: pad in unit missing from footprint." ) );
596 return 0;
597 }
598
599 unitPads[ui].push_back( p );
600 unitNets[ui].push_back( p->GetNetCode() );
601 }
602 }
603
604 if( std::ranges::all_of( unitNets,
605 [&]( const auto& nets )
606 {
607 return nets == unitNets.front();
608 } ) )
609 {
610 frame()->ShowInfoBarError( _( "Gate swapping has no effect: all selected gates have identical nets." ) );
611 return 0;
612 }
613
614 // TODO: someday support swapping while routing and take that commit
615 BOARD_COMMIT localCommit( this );
616 BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() );
617
618 if( !commit )
619 commit = &localCommit;
620
621 std::shared_ptr<CONNECTIVITY_DATA> connectivity = board()->GetConnectivity();
622
623 // Accumulate changes: item -> new net
624 std::unordered_map<BOARD_CONNECTED_ITEM*, int> itemNewNets;
625 std::vector<PAD*> nonSelectedPadsToChange;
626 wxString error;
627
628 // Selected pads in the swap (for suppressing re-adding in connected pad handling)
629 std::unordered_set<PAD*> swapPads;
630
631 for( const auto& v : unitPads )
632 swapPads.insert( v.begin(), v.end() );
633
634 for( size_t pi = 0; pi < pinCount; ++pi )
635 {
636 for( size_t ui = 0; ui < unitCount; ++ui )
637 {
638 size_t toIdx = ( ui + 1 ) % unitCount;
639
640 if( !ScheduleNetSwap( unitPads[ui][pi], unitNets[toIdx][pi], itemNewNets, error ) )
641 {
642 frame()->ShowInfoBarError( error );
643 return 0;
644 }
645 }
646 }
647
648 // Schedule net swaps for connectivity-attached items
649 auto scheduleForPad = [&]( PAD* pad, int fromNet, int toNet ) -> bool
650 {
651 for( BOARD_CONNECTED_ITEM* ci : connectivity->GetConnectedItems( pad, EXCLUDE_ZONES ) )
652 {
653 switch( ci->Type() )
654 {
655 case PCB_TRACE_T:
656 case PCB_ARC_T:
657 case PCB_VIA_T:
658 case PCB_PAD_T:
659 case PCB_SHAPE_T:
660 break;
661
662 default:
663 continue;
664 }
665
666 if( ci->GetNetCode() != fromNet )
667 continue;
668
669 if( !ScheduleNetSwap( ci, toNet, itemNewNets, error ) )
670 return false;
671
672 if( ci->Type() == PCB_PAD_T )
673 {
674 PAD* other = static_cast<PAD*>( ci );
675
676 if( !swapPads.count( other ) )
677 nonSelectedPadsToChange.push_back( other );
678 }
679 }
680
681 return true;
682 };
683
684 // For each position, rotate nets among units forward
685 for( size_t pi = 0; pi < pinCount; ++pi )
686 {
687 for( size_t ui = 0; ui < unitCount; ++ui )
688 {
689 size_t fromIdx = ui;
690 size_t toIdx = ( ui + 1 ) % unitCount;
691
692 PAD* padFrom = unitPads[fromIdx][pi];
693 int fromNet = unitNets[fromIdx][pi];
694 int toNet = unitNets[toIdx][pi];
695
696 if( !scheduleForPad( padFrom, fromNet, toNet ) )
697 {
698 frame()->ShowInfoBarError( error );
699 return 0;
700 }
701 }
702 }
703
704 bool includeConnectedPads = true;
705
706 if( !PromptConnectedPadDecision( frame(), nonSelectedPadsToChange, _( "Swap Gate Nets" ), includeConnectedPads ) )
707 {
708 return 0;
709 }
710
711 if( !ValidateNetSwapLocks( frame(), itemNewNets, swapPads, includeConnectedPads ) )
712 return 0;
713
714 // Apply pad net swaps: rotate per position
715 for( size_t pi = 0; pi < pinCount; ++pi )
716 {
717 // First write back nets for each unit's pad at this position
718 for( size_t ui = 0; ui < unitCount; ++ui )
719 {
720 size_t toIdx = ( ui + 1 ) % unitCount;
721 PAD* pad = unitPads[ui][pi];
722 int newNet = unitNets[toIdx][pi];
723
724 if( pad->GetNetCode() == newNet )
725 continue;
726
727 commit->Modify( pad );
728 pad->SetNetCode( newNet );
729 }
730 }
731
732 // Apply connected items
733 for( const auto& kv : itemNewNets )
734 {
735 BOARD_CONNECTED_ITEM* item = kv.first;
736 int newNet = kv.second;
737
738 if( item->Type() == PCB_PAD_T )
739 {
740 PAD* p = static_cast<PAD*>( item );
741
742 if( swapPads.count( p ) )
743 continue;
744
745 if( !includeConnectedPads )
746 continue;
747 }
748
749 if( item->GetNetCode() == newNet )
750 continue;
751
752 commit->Modify( item );
753 item->SetNetCode( newNet );
754 }
755
756 if( !localCommit.Empty() )
757 localCommit.Push( _( "Swap Gate Nets" ) );
758
761
762 return 0;
763}
764
765
767{
768 if( isRouterActive() || m_dragging )
769 {
770 wxBell();
771 return 0;
772 }
773
774 BOARD_COMMIT commit( this );
775 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
776 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
777 {
778 sTool->FilterCollectorForMarkers( aCollector );
779 sTool->FilterCollectorForHierarchy( aCollector, true );
780 sTool->FilterCollectorForFreePads( aCollector, true );
781
782 // Iterate from the back so we don't have to worry about removals.
783 for( int i = aCollector.GetCount() - 1; i >= 0; --i )
784 {
785 BOARD_ITEM* item = aCollector[i];
786
787 if( !dynamic_cast<FOOTPRINT*>( item ) )
788 aCollector.Remove( item );
789 }
790
791 sTool->FilterCollectorForLockedItems( aCollector );
792 } );
793
794 m_selectionTool->ReportFilteredLockedItems();
795
796 std::vector<FOOTPRINT*> footprintsToPack;
797
798 for( EDA_ITEM* item : selection )
799 footprintsToPack.push_back( static_cast<FOOTPRINT*>( item ) );
800
801 if( footprintsToPack.empty() )
802 return 0;
803
804 BOX2I footprintsBbox;
805
806 for( FOOTPRINT* fp : footprintsToPack )
807 {
808 commit.Modify( fp );
809 fp->SetFlags( IS_MOVING );
810 footprintsBbox.Merge( fp->GetBoundingBox( false ) );
811 }
812
813 SpreadFootprints( &footprintsToPack, footprintsBbox.Normalize().GetOrigin(), false );
814
815 if( doMoveSelection( aEvent, &commit, true ) )
816 commit.Push( _( "Pack Footprints" ) );
817 else
818 commit.Revert();
819
820 return 0;
821}
822
823
824int EDIT_TOOL::Move( const TOOL_EVENT& aEvent )
825{
826 if( isRouterActive() || m_dragging )
827 {
828 wxBell();
829 return 0;
830 }
831
832 if( BOARD_COMMIT* commit = dynamic_cast<BOARD_COMMIT*>( aEvent.Commit() ) )
833 {
834 // Most moves will be synchronous unless they are coming from the API. Do not run the
835 // constraint solver here; this path contributes only the requested move to the
836 // caller-owned commit.
837 if( aEvent.SynchronousState() )
838 aEvent.SynchronousState()->store( STS_RUNNING );
839
840 if( doMoveSelection( aEvent, commit, true ) )
841 {
842 if( aEvent.SynchronousState() )
843 aEvent.SynchronousState()->store( STS_FINISHED );
844 }
845 else if( aEvent.SynchronousState() )
846 {
847 aEvent.SynchronousState()->store( STS_CANCELLED );
848 }
849 }
850 else
851 {
852 BOARD_COMMIT localCommit( this );
853
854 // doMoveSelection captures these from live selection before it is cleared
855 // so they stay valid even for a hover move whose selection does not survive the drag
856 std::vector<PCB_SHAPE*> constraintShapes;
857
858 if( doMoveSelection( aEvent, &localCommit, false, &constraintShapes ) )
859 {
860 // The last painted motion frame already contains the validated constrained cluster.
861 // Mouse-up must commit that exact state, including when a newer motion event is pending.
862 localCommit.Push( _( "Move" ) );
863
864 if( !constraintShapes.empty() && BoardHasConstraints( board() ) )
865 {
866 if( CONSTRAINT_EDIT_TOOL* constraintTool = m_toolMgr->GetTool<CONSTRAINT_EDIT_TOOL>() )
867 constraintTool->DiagnoseAfterMove( constraintShapes );
868 }
869 }
870 else
871 {
872 localCommit.Revert();
873 }
874 }
875
876 // Notify point editor. (While doMoveSelection() will re-select the items and post this
877 // event, it's done before the edit flags are cleared in BOARD_COMMIT::Push() so the point
878 // editor doesn't fire up.)
879 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
880
881 return 0;
882}
883
884
885VECTOR2I EDIT_TOOL::getSafeMovement( const VECTOR2I& aMovement, const BOX2I& aSourceBBox,
886 const VECTOR2D& aBBoxOffset )
887{
888 typedef std::numeric_limits<int> coord_limits;
889
890 static const double max = coord_limits::max() - (int) COORDS_PADDING;
891 static const double min = -max;
892
893 BOX2D testBox( aSourceBBox.GetPosition(), aSourceBBox.GetSize() );
894 testBox.Offset( aBBoxOffset );
895
896 // Do not restrict movement if bounding box is already out of bounds
897 if( testBox.GetLeft() < min || testBox.GetTop() < min || testBox.GetRight() > max
898 || testBox.GetBottom() > max )
899 {
900 return aMovement;
901 }
902
903 testBox.Offset( aMovement );
904
905 if( testBox.GetLeft() < min )
906 testBox.Offset( min - testBox.GetLeft(), 0 );
907
908 if( max < testBox.GetRight() )
909 testBox.Offset( -( testBox.GetRight() - max ), 0 );
910
911 if( testBox.GetTop() < min )
912 testBox.Offset( 0, min - testBox.GetTop() );
913
914 if( max < testBox.GetBottom() )
915 testBox.Offset( 0, -( testBox.GetBottom() - max ) );
916
917 return KiROUND( testBox.GetPosition() - aBBoxOffset - aSourceBBox.GetPosition() );
918}
919
920
921bool EDIT_TOOL::doMoveSelection( const TOOL_EVENT& aEvent, BOARD_COMMIT* aCommit, bool aAutoStart,
922 std::vector<PCB_SHAPE*>* aConstraintShapes )
923{
924 const bool moveWithReference = aEvent.IsAction( &PCB_ACTIONS::moveWithReference );
925 const bool moveIndividually = aEvent.IsAction( &PCB_ACTIONS::moveIndividually );
926
928 PCBNEW_SETTINGS* cfg = editFrame->GetPcbNewSettings();
929 BOARD* board = editFrame->GetBoard();
931 VECTOR2I originalCursorPos = controls->GetCursorPosition();
932 VECTOR2I originalMousePos = controls->GetMousePosition();
933 std::unique_ptr<STATUS_TEXT_POPUP> statusPopup;
934 size_t itemIdx = 0;
935
936 // Be sure that there is at least one item that we can modify. If nothing was selected before,
937 // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
938 PCB_SELECTION& selection = m_selectionTool->RequestSelection(
939 []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
940 {
941 sTool->FilterCollectorForMarkers( aCollector );
942 sTool->FilterCollectorForHierarchy( aCollector, true );
943 sTool->FilterCollectorForFreePads( aCollector );
944 sTool->FilterCollectorForTableCells( aCollector );
945 sTool->FilterCollectorForLockedItems( aCollector );
946 } );
947
948 if( m_dragging )
949 return false;
950
951 m_selectionTool->ReportFilteredLockedItems();
952
953 if( selection.Empty() )
954 return false;
955
956 TOOL_EVENT originalEvent = aEvent; // This can change out from under us when the event loop runs
957 SCOPED_TOOL_PUSHER raii( editFrame, originalEvent );
958 Activate();
959
960 // Must be done after Activate() so that it gets set into the correct context
961 controls->ShowCursor( true );
962 controls->SetAutoPan( true );
963 controls->ForceCursorPosition( false );
964
965 auto displayConstraintsMessage =
966 [editFrame]( LEADER_MODE aMode )
967 {
968 wxString msg;
969
970 switch( aMode )
971 {
973 msg = _( "Angle snap lines: 45°" );
974 break;
975
977 msg = _( "Angle snap lines: 90°" );
978 break;
979
980 default:
981 msg.clear();
982 break;
983 }
984
985 editFrame->DisplayConstraintsMsg( msg );
986 };
987
988 auto updateStatusPopup =
989 [&]( EDA_ITEM* item, size_t ii, size_t count )
990 {
991 wxString popuptext = _( "Click to place %s (item %zu of %zu)\n"
992 "Press <esc> to cancel all; double-click to finish" );
993 wxString msg;
994
995 if( item->Type() == PCB_FOOTPRINT_T )
996 {
997 FOOTPRINT* fp = static_cast<FOOTPRINT*>( item );
998 msg = fp->GetReference();
999 }
1000 else if( item->Type() == PCB_PAD_T )
1001 {
1002 PAD* pad = static_cast<PAD*>( item );
1003 FOOTPRINT* fp = pad->GetParentFootprint();
1004
1005 if( fp )
1006 msg = wxString::Format( _( "%s pad %s" ), fp->GetReference(), pad->GetNumber() );
1007 else
1008 msg = pad->GetItemDescription( editFrame, false );
1009 }
1010 else
1011 {
1012 msg = item->GetTypeDesc().Lower();
1013 }
1014
1015 if( !statusPopup )
1016 statusPopup = std::make_unique<STATUS_TEXT_POPUP>( frame() );
1017
1018 statusPopup->SetText( wxString::Format( popuptext, msg, ii, count ) );
1019 };
1020
1021 std::vector<BOARD_ITEM*> sel_items; // All the items operated on by the move below
1022 std::vector<BOARD_ITEM*> orig_items; // All the original items in the selection
1023
1024 // Top-level items being moved. Used instead of selection flags, which can be cleared
1025 // mid-move by the find dialog (issue 24884).
1026 std::unordered_set<EDA_ITEM*> moved_items;
1027
1028 for( EDA_ITEM* item : selection )
1029 {
1030 if( item->IsBOARD_ITEM() )
1031 {
1032 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
1033
1034 if( !selection.IsHover() )
1035 orig_items.push_back( boardItem );
1036
1037 sel_items.push_back( boardItem );
1038 moved_items.insert( boardItem );
1039 }
1040
1041 if( item->Type() == PCB_FOOTPRINT_T )
1042 {
1043 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
1044
1045 for( PAD* pad : footprint->Pads() )
1046 sel_items.push_back( pad );
1047
1048 // Clear this flag here; it will be set by the netlist updater if the footprint is new
1049 // so that it was skipped in the initial connectivity update in OnNetlistChanged
1050 footprint->SetAttributes( footprint->GetAttributes() & ~FP_JUST_ADDED );
1051 }
1052 }
1053
1054 // Selection stays stable for whole drag so gather constrainable shapes once here and reuse them
1055 // each tick and for final settle solve hover moves clear selection before returning so capture now
1056 if( aConstraintShapes )
1057 collectConstraintShapes( selection, *aConstraintShapes );
1058
1059 VECTOR2I pickedReferencePoint;
1060
1061 if( moveWithReference && !pickReferencePoint( _( "Select reference point for move..." ), "", "",
1062 pickedReferencePoint ) )
1063 {
1064 if( selection.IsHover() )
1065 m_toolMgr->RunAction( ACTIONS::selectionClear );
1066
1067 return false;
1068 }
1069
1070 m_inMoveWithReference = moveWithReference;
1071
1072 if( moveIndividually )
1073 {
1074 orig_items.clear();
1075
1076 for( EDA_ITEM* item : selection.GetItemsSortedBySelectionOrder() )
1077 {
1078 if( item->IsBOARD_ITEM() )
1079 orig_items.push_back( static_cast<BOARD_ITEM*>( item ) );
1080 }
1081
1082 updateStatusPopup( orig_items[ itemIdx ], itemIdx + 1, orig_items.size() );
1083 statusPopup->Popup();
1084 statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
1085 canvas()->SetStatusPopup( statusPopup->GetPanel() );
1086
1087 m_selectionTool->ClearSelection();
1088 m_selectionTool->AddItemToSel( orig_items[ itemIdx ] );
1089
1090 sel_items.clear();
1091 sel_items.push_back( orig_items[ itemIdx ] );
1092
1093 moved_items.clear();
1094 moved_items.insert( orig_items[itemIdx] );
1095 }
1096
1097 bool restore_state = false;
1098 VECTOR2I originalPos = originalCursorPos; // Initialize to current cursor position
1099 VECTOR2D bboxMovement;
1100 BOX2I originalBBox;
1101 bool updateBBox = true;
1102 LSET layers( { editFrame->GetActiveLayer() } );
1104 std::shared_ptr<BOARD_CONSTRAINT_MOVE_SESSION> constraintMoveSession;
1105
1106 // Scans every footprint, and cannot change for the duration of the move
1107 const bool boardHasConstraints = BoardHasConstraints( board );
1108
1109 TOOL_EVENT copy = aEvent;
1110 TOOL_EVENT* evt = &copy;
1111 VECTOR2I prevPos;
1112 bool enableLocalRatsnest = true;
1113
1114 // Frame-aware orientation tracking (mirrors BOARD_EDITOR_CONTROL::PlaceFootprint).
1115 // A single footprint (plus, at most, its own pads) rotates about its own position;
1116 // any other selection containing footprints rotates as a whole about the pick-up
1117 // point, just like manual rotation during a move.
1118 auto findSingleFp =
1119 [&]() -> FOOTPRINT*
1120 {
1121 FOOTPRINT* singleFp = nullptr;
1122
1123 for( BOARD_ITEM* it : sel_items )
1124 {
1125 if( it->Type() == PCB_FOOTPRINT_T )
1126 {
1127 if( singleFp )
1128 return nullptr; // more than one footprint
1129
1130 singleFp = static_cast<FOOTPRINT*>( it );
1131 }
1132 else if( it->Type() != PCB_PAD_T )
1133 {
1134 return nullptr; // mixed selection
1135 }
1136 }
1137
1138 for( BOARD_ITEM* it : sel_items )
1139 {
1140 if( it->Type() == PCB_PAD_T && it->GetParentFootprint() != singleFp )
1141 return nullptr; // free pad of another footprint
1142 }
1143
1144 return singleFp;
1145 };
1146
1147 auto selectionHasFp =
1148 [&]()
1149 {
1150 return std::any_of( sel_items.begin(), sel_items.end(),
1151 []( BOARD_ITEM* it )
1152 {
1153 return it->Type() == PCB_FOOTPRINT_T;
1154 } );
1155 };
1156
1157 // Capture the frame angle at the PICK-UP position: a footprint inside a rotated/polar
1158 // grid already carries that frame's orientation, so the first cursor move must
1159 // not rotate it again. frameFp/frameRotate are recomputed whenever sel_items
1160 // changes (moveIndividually item switch).
1161 EDA_ANGLE prevFrameAngle = ANGLE_0;
1162 FOOTPRINT* frameFp = findSingleFp();
1163 bool frameRotate = frameFp || selectionHasFp();
1164
1165 if( frameRotate )
1166 {
1167 prevFrameAngle = GridFrameAngleAt( *board, frameFp ? frameFp->GetPosition() : originalCursorPos,
1169 }
1170
1171 auto applyMoveFrameOrientation =
1172 [&]()
1173 {
1174 if( !frameRotate )
1175 return;
1176
1177 // m_cursor is the pick-up point dragged along with the selection.
1178 VECTOR2I pivot = frameFp ? frameFp->GetPosition() : m_cursor;
1180 EDA_ANGLE delta = GridFrameRotationDelta( prevFrameAngle, newAngle, editFrame->GetRotationAngle() );
1181
1182 prevFrameAngle = newAngle;
1183
1184 if( delta.IsZero() )
1185 return;
1186
1187 if( frameFp )
1188 {
1189 frameFp->Rotate( pivot, delta );
1190 }
1191 else
1192 {
1193 for( BOARD_ITEM* item : sel_items )
1194 {
1195 // Don't double rotate child items.
1196 if( !item->GetParent() || !moved_items.count( item->GetParent() ) )
1197 item->Rotate( pivot, delta );
1198 }
1199 }
1200 };
1201
1202 LEADER_MODE angleSnapMode = GetAngleSnapMode();
1203 bool eatFirstMouseUp = true;
1204 bool allowRedraw3D = cfg->m_Display.m_Live3DRefresh;
1205 bool showCourtyardConflicts = !m_isFootprintEditor && cfg->m_ShowCourtyardCollisions;
1206
1207 const auto buildConstraintMoveSession =
1208 [&]( const VECTOR2I& aReference )
1209 {
1210 grid.SetFeasibilityCallback( {} );
1211 constraintMoveSession.reset();
1212
1213 if( moveIndividually || !aConstraintShapes || aConstraintShapes->empty()
1214 || !boardHasConstraints )
1215 {
1216 return;
1217 }
1218
1219 auto session = std::make_shared<BOARD_CONSTRAINT_MOVE_SESSION>();
1220
1221 if( session->Build( board, *aConstraintShapes, aReference ) )
1222 {
1223 constraintMoveSession = session;
1224 grid.SetFeasibilityCallback(
1225 [session]( const SNAP_SOURCE_CONTEXT& aContext,
1226 const std::vector<SNAP_CANDIDATE>& aCandidates )
1227 {
1228 return session->ResolveCandidates( aContext, aCandidates );
1229 } );
1230 }
1231 };
1232
1233 // Axis locking for arrow key movement
1234 enum class AXIS_LOCK { NONE, HORIZONTAL, VERTICAL };
1235 AXIS_LOCK axisLock = AXIS_LOCK::NONE;
1236 long lastArrowKeyAction = 0;
1237
1238 // The footprint editor has no DRC_TOOL, so the engine may be unavailable.
1239 DRC_TOOL* drcTool = m_toolMgr->GetTool<DRC_TOOL>();
1240 std::shared_ptr<DRC_ENGINE> drcEngine = drcTool ? drcTool->GetDRCEngine() : nullptr;
1241
1242 // Used to test courtyard overlaps
1243 std::unique_ptr<DRC_INTERACTIVE_COURTYARD_CLEARANCE> drc_on_move = nullptr;
1244
1245 if( showCourtyardConflicts )
1246 {
1247 drc_on_move.reset( new DRC_INTERACTIVE_COURTYARD_CLEARANCE( drcEngine ) );
1248 drc_on_move->Init( board );
1249 }
1250
1251 // No-op unless RealtimeCreepage is set and the board has creepage constraints
1252 std::unique_ptr<CREEPAGE_OVERLAY> creepage_on_move = std::make_unique<CREEPAGE_OVERLAY>( board, drcEngine,
1253 m_toolMgr->GetView() );
1254
1255 auto configureAngleSnap =
1256 [&]( LEADER_MODE aMode )
1257 {
1258 std::vector<VECTOR2I> directions;
1259
1260 switch( aMode )
1261 {
1262 case LEADER_MODE::DEG45:
1263 directions = { VECTOR2I( 1, 0 ), VECTOR2I( 0, 1 ), VECTOR2I( 1, 1 ), VECTOR2I( 1, -1 ) };
1264 break;
1265
1266 case LEADER_MODE::DEG90:
1267 directions = { VECTOR2I( 1, 0 ), VECTOR2I( 0, 1 ) };
1268 break;
1269
1270 default:
1271 break;
1272 }
1273
1274 grid.SetSnapLineDirections( directions );
1275
1276 if( directions.empty() )
1277 grid.ClearSnapLine();
1278 else
1279 grid.SetSnapLineOrigin( originalPos );
1280 };
1281
1282 configureAngleSnap( angleSnapMode );
1283 displayConstraintsMessage( angleSnapMode );
1284
1285 // Prime the pump
1286 m_toolMgr->PostAction( ACTIONS::refreshPreview );
1287
1288 // Main loop: keep receiving events
1289 do
1290 {
1291 VECTOR2I movement;
1293 grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
1294 grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
1295
1296 bool isSkip = evt->IsAction( &PCB_ACTIONS::skip ) && moveIndividually;
1297
1298 if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
1299 eatFirstMouseUp = false;
1300
1301 if( evt->IsAction( &PCB_ACTIONS::move )
1302 || evt->IsMotion()
1303 || evt->IsDrag( BUT_LEFT )
1307 {
1308 if( m_dragging && ( evt->IsMotion()
1309 || evt->IsDrag( BUT_LEFT )
1310 || evt->IsAction( &ACTIONS::refreshPreview ) ) )
1311 {
1312 bool redraw3D = false;
1313
1314 GRID_HELPER_GRIDS selectionGrid = grid.GetSelectionGrid( selection );
1315
1316 if( controls->GetSettings().m_lastKeyboardCursorPositionValid )
1317 {
1318 VECTOR2I keyboardPos( controls->GetSettings().m_lastKeyboardCursorPosition );
1319
1320 grid.SetSnap( false );
1321
1322 // Use the keyboard position directly without grid alignment. The position
1323 // was already calculated correctly in CursorControl by adding the grid step
1324 // to the current position. Aligning to grid here would snap to the nearest
1325 // grid point, which causes precision errors when the original position is
1326 // not on a grid point (issue #22805).
1327 m_cursor = keyboardPos;
1328
1329 // Update axis lock based on arrow key press, but skip on refreshPreview
1330 // to avoid double-processing when CursorControl posts refreshPreview after
1331 // handling the arrow key.
1332 if( !evt->IsAction( &ACTIONS::refreshPreview ) )
1333 {
1334 long action = controls->GetSettings().m_lastKeyboardCursorCommand;
1335
1336 if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
1337 {
1338 if( axisLock == AXIS_LOCK::HORIZONTAL )
1339 {
1340 // Check if opposite horizontal key pressed to unlock
1341 if( ( lastArrowKeyAction == ACTIONS::CURSOR_LEFT && action == ACTIONS::CURSOR_RIGHT ) ||
1342 ( lastArrowKeyAction == ACTIONS::CURSOR_RIGHT && action == ACTIONS::CURSOR_LEFT ) )
1343 {
1344 axisLock = AXIS_LOCK::NONE;
1345 }
1346 // Same direction axis, keep locked
1347 }
1348 else
1349 {
1350 axisLock = AXIS_LOCK::HORIZONTAL;
1351 }
1352 }
1353 else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
1354 {
1355 if( axisLock == AXIS_LOCK::VERTICAL )
1356 {
1357 // Check if opposite vertical key pressed to unlock
1358 if( ( lastArrowKeyAction == ACTIONS::CURSOR_UP && action == ACTIONS::CURSOR_DOWN ) ||
1359 ( lastArrowKeyAction == ACTIONS::CURSOR_DOWN && action == ACTIONS::CURSOR_UP ) )
1360 {
1361 axisLock = AXIS_LOCK::NONE;
1362 }
1363 // Same direction axis, keep locked
1364 }
1365 else
1366 {
1367 axisLock = AXIS_LOCK::VERTICAL;
1368 }
1369 }
1370
1371 lastArrowKeyAction = action;
1372 }
1373 }
1374 else
1375 {
1376 VECTOR2I mousePos( controls->GetMousePosition() );
1377
1378 m_cursor = grid.ResolveSnap( mousePos, layers, selectionGrid, sel_items, prevPos ).position;
1379 }
1380
1381 if( axisLock == AXIS_LOCK::HORIZONTAL )
1382 m_cursor.y = prevPos.y;
1383 else if( axisLock == AXIS_LOCK::VERTICAL )
1384 m_cursor.x = prevPos.x;
1385
1386 if( !selection.HasReferencePoint() )
1387 originalPos = m_cursor;
1388
1389 if( updateBBox )
1390 {
1391 originalBBox = BOX2I();
1392 bboxMovement = VECTOR2D();
1393
1394 for( EDA_ITEM* item : sel_items )
1395 originalBBox.Merge( item->ViewBBox() );
1396
1397 updateBBox = false;
1398 }
1399
1400 // Constrain selection bounding box to coordinates limits
1401 VECTOR2I previousCursor = prevPos;
1402 movement = getSafeMovement( m_cursor - prevPos, originalBBox, bboxMovement );
1403
1404 // Apply constrained movement
1405 m_cursor = prevPos + movement;
1406
1407 controls->ForceCursorPosition( true, m_cursor );
1408 selection.SetReferencePoint( m_cursor );
1409
1410 prevPos = m_cursor;
1411 bboxMovement += movement;
1412
1413 // Drag items to the current cursor position
1414 for( BOARD_ITEM* item : sel_items )
1415 {
1416 // Don't double move child items.
1417 if( !item->GetParent() || !moved_items.count( item->GetParent() ) )
1418 {
1419 item->Move( movement );
1420
1421 // Images and grid items are on non-cached layers and will not be updated automatically in
1422 // the overlay, so explicitly tell the view they've moved.
1423 if( item->Type() == PCB_REFERENCE_IMAGE_T || item->Type() == PCB_GRID_ITEM_T
1424 || item->Type() == PCB_DRILL_MAP_T )
1425 view()->Update( item, KIGFX::GEOMETRY );
1426 }
1427
1428 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
1429 {
1430 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genUpdateEdit, aCommit,
1431 static_cast<PCB_GENERATOR*>( item ) );
1432 }
1433
1434 if( item->Type() == PCB_FOOTPRINT_T )
1435 redraw3D = true;
1436 }
1437
1438 // Constrained neighbors sit unselected with no IS_MOVING flag outside the move overlay
1439 // only local commit drag previews them stage touched neighbors so cancel Revert restores them
1440 if( aConstraintShapes && !aConstraintShapes->empty() && movement != VECTOR2I()
1441 && boardHasConstraints )
1442 {
1443 std::vector<PCB_SHAPE*> solved;
1444 std::vector<BOARD_ITEM*> dimensions;
1445
1446 const auto beforeConstraintModify =
1447 [&]( BOARD_ITEM* aItem )
1448 {
1449 aCommit->Modify( aItem );
1450
1451 // A remeasured dimension is not returned in solved so refresh it here
1452 // or it looks frozen until the drag ends
1453 if( aItem->Type() != PCB_SHAPE_T )
1454 dimensions.push_back( aItem );
1455 };
1456
1457 bool solvedConstraints =
1458 constraintMoveSession
1459 ? constraintMoveSession->Solve( m_cursor, &solved, beforeConstraintModify )
1460 : ReSolveShapeClustersHoldingEdited( board, *aConstraintShapes, &solved,
1461 beforeConstraintModify );
1462
1463 if( solvedConstraints )
1464 {
1465 for( PCB_SHAPE* neighbor : solved )
1466 view()->Update( neighbor, KIGFX::GEOMETRY );
1467
1468 for( BOARD_ITEM* dimension : dimensions )
1469 view()->Update( dimension, KIGFX::GEOMETRY );
1470 }
1471 else
1472 {
1473 for( BOARD_ITEM* item : sel_items )
1474 {
1475 if( !item->GetParent() || !moved_items.count( item->GetParent() ) )
1476 item->Move( -movement );
1477 }
1478
1479 m_cursor = previousCursor;
1480 prevPos = previousCursor;
1481 bboxMovement -= movement;
1482 movement = VECTOR2I();
1483 selection.SetReferencePoint( m_cursor );
1484 controls->ForceCursorPosition( true, m_cursor );
1485 grid.ClearSnapFeedback();
1486 }
1487 }
1488
1489 applyMoveFrameOrientation();
1490
1491 if( redraw3D && allowRedraw3D )
1492 editFrame->Update3DView( false, true );
1493
1494 if( showCourtyardConflicts && drc_on_move->m_FpInMove.size() )
1495 {
1496 drc_on_move->Run();
1497 drc_on_move->UpdateConflicts( m_toolMgr->GetView(), true );
1498 }
1499
1500 creepage_on_move->Update();
1501
1503 }
1504 else if( !m_dragging && ( aAutoStart || !evt->IsAction( &ACTIONS::refreshPreview ) ) )
1505 {
1506 // Prepare to start dragging
1507 editFrame->HideSolderMask();
1508
1509 m_dragging = true;
1510
1511 for( BOARD_ITEM* item : sel_items )
1512 {
1513 if( item->GetParent() && moved_items.count( item->GetParent() ) )
1514 continue;
1515
1516 if( !item->IsNew() && !item->IsMoving() )
1517 {
1518 if( item->Type() == PCB_GENERATOR_T && sel_items.size() == 1 )
1519 {
1520 enableLocalRatsnest = false;
1521
1522 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genStartEdit, aCommit,
1523 static_cast<PCB_GENERATOR*>( item ) );
1524 }
1525 else
1526 {
1527 aCommit->Modify( item, nullptr, RECURSE_MODE::RECURSE );
1528 }
1529
1530 item->SetFlags( IS_MOVING );
1531
1532 if( item->Type() == PCB_SHAPE_T )
1533 static_cast<PCB_SHAPE*>( item )->UpdateHatching();
1534
1535 item->RunOnChildren(
1536 [&]( BOARD_ITEM* child )
1537 {
1538 child->SetFlags( IS_MOVING );
1539
1540 if( child->Type() == PCB_SHAPE_T )
1541 static_cast<PCB_SHAPE*>( child )->UpdateHatching();
1542 },
1544 }
1545 }
1546
1547 m_cursor = controls->GetCursorPosition();
1548
1549 if( selection.HasReferencePoint() )
1550 {
1551 // start moving with the reference point attached to the cursor
1552 grid.SetAuxAxes( false );
1553 buildConstraintMoveSession( selection.GetReferencePoint() );
1554
1555 movement = m_cursor - selection.GetReferencePoint();
1556
1557 // Drag items to the current cursor position
1558 for( EDA_ITEM* item : selection )
1559 {
1560 if( !item->IsBOARD_ITEM() )
1561 continue;
1562
1563 // Don't double move footprint pads, fields, etc.
1564 if( item->GetParent() && moved_items.count( item->GetParent() ) )
1565 continue;
1566
1567 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
1568 boardItem->Move( movement );
1569
1570 // Images are on non-cached layers and will not be updated automatically in the overlay, so
1571 // explicitly tell the view they've moved.
1572 if( boardItem->Type() == PCB_REFERENCE_IMAGE_T )
1573 view()->Update( boardItem, KIGFX::GEOMETRY );
1574 }
1575
1576 applyMoveFrameOrientation();
1577 selection.SetReferencePoint( m_cursor );
1578 }
1579 else
1580 {
1581 if( showCourtyardConflicts )
1582 {
1583 std::vector<FOOTPRINT*>& FPs = drc_on_move->m_FpInMove;
1584
1585 for( BOARD_ITEM* item : sel_items )
1586 {
1587 if( item->Type() == PCB_FOOTPRINT_T )
1588 FPs.push_back( static_cast<FOOTPRINT*>( item ) );
1589
1590 item->RunOnChildren(
1591 [&]( BOARD_ITEM* child )
1592 {
1593 if( child->Type() == PCB_FOOTPRINT_T )
1594 FPs.push_back( static_cast<FOOTPRINT*>( child ) );
1595 },
1597 }
1598 }
1599
1600 creepage_on_move->Start( sel_items );
1601
1602 // Use the mouse position over cursor, as otherwise large grids will allow only
1603 // snapping to items that are closest to grid points
1604 m_cursor = grid.BestDragOrigin( originalMousePos, sel_items, grid.GetSelectionGrid( selection ),
1605 &m_selectionTool->GetFilter() );
1606
1607 // Set the current cursor position to the first dragged item origin, so the
1608 // movement vector could be computed later
1609 if( moveWithReference )
1610 {
1611 selection.SetReferencePoint( pickedReferencePoint );
1612
1613 if( angleSnapMode != LEADER_MODE::DIRECT )
1614 grid.SetSnapLineOrigin( selection.GetReferencePoint() );
1615
1616 controls->ForceCursorPosition( true, pickedReferencePoint );
1617 m_cursor = pickedReferencePoint;
1618 }
1619 else
1620 {
1621 VECTOR2I dragOrigin = m_cursor;
1622
1623 selection.SetReferencePoint( dragOrigin );
1624
1625 if( angleSnapMode != LEADER_MODE::DIRECT )
1626 grid.SetSnapLineOrigin( dragOrigin );
1627
1628 grid.SetAuxAxes( true, dragOrigin );
1629
1630 if( !editFrame->GetMoveWarpsCursor() )
1631 m_cursor = originalCursorPos;
1632 else
1633 m_cursor = dragOrigin;
1634 }
1635
1636 originalPos = selection.GetReferencePoint();
1637 buildConstraintMoveSession( originalPos );
1638 }
1639
1640 // Update variables for bounding box collision calculations
1641 updateBBox = true;
1642
1643 controls->SetCursorPosition( m_cursor, false );
1644
1645 prevPos = m_cursor;
1646 controls->SetAutoPan( true );
1648 }
1649
1650 if( statusPopup )
1651 statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
1652
1653 if( enableLocalRatsnest )
1654 m_toolMgr->PostAction( PCB_ACTIONS::updateLocalRatsnest, movement );
1655 }
1656 else if( evt->IsCancelInteractive() || evt->IsActivate() )
1657 {
1658 if( m_dragging && evt->IsCancelInteractive() )
1659 evt->SetPassEvent( false );
1660
1661 restore_state = true; // Canceling the tool means that items have to be restored
1662 break; // Finish
1663 }
1664 else if( evt->IsClick( BUT_RIGHT ) )
1665 {
1666 m_selectionTool->GetToolMenu().ShowContextMenu( selection );
1667 }
1668 else if( evt->IsAction( &ACTIONS::undo ) )
1669 {
1670 restore_state = true; // Perform undo locally
1671 break; // Finish
1672 }
1673 else if( evt->IsAction( &ACTIONS::doDelete ) )
1674 {
1675 evt->SetPassEvent();
1676 // Exit on a delete; there will no longer be anything to drag.
1677 break;
1678 }
1679 else if( evt->IsAction( &ACTIONS::duplicate ) && evt != &copy )
1680 {
1681 wxBell();
1682 }
1683 else if( evt->IsAction( &ACTIONS::cut ) )
1684 {
1685 wxBell();
1686 }
1687 else if( evt->IsAction( &PCB_ACTIONS::rotateCw )
1689 || evt->IsAction( &PCB_ACTIONS::flip )
1690 || evt->IsAction( &PCB_ACTIONS::mirrorH )
1691 || evt->IsAction( &PCB_ACTIONS::mirrorV ) )
1692 {
1693 updateBBox = true;
1694 eatFirstMouseUp = false;
1695 evt->SetPassEvent();
1696 }
1697 else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) || isSkip )
1698 {
1699 // Eat mouse-up/-click events that leaked through from the lock dialog
1700 if( eatFirstMouseUp && !evt->IsAction( &ACTIONS::cursorClick ) )
1701 {
1702 eatFirstMouseUp = false;
1703 continue;
1704 }
1705 else if( moveIndividually && m_dragging )
1706 {
1707 // Put skipped items back where they started
1708 if( isSkip )
1709 orig_items[itemIdx]->SetPosition( originalPos );
1710
1711 view()->Update( orig_items[itemIdx] );
1713
1714 if( ++itemIdx < orig_items.size() )
1715 {
1716 BOARD_ITEM* nextItem = orig_items[itemIdx];
1717
1718 m_selectionTool->ClearSelection();
1719
1720 originalPos = nextItem->GetPosition();
1721 m_selectionTool->AddItemToSel( nextItem );
1722 selection.SetReferencePoint( originalPos );
1723
1724 if( angleSnapMode != LEADER_MODE::DIRECT )
1725 grid.SetSnapLineOrigin( selection.GetReferencePoint() );
1726
1727 sel_items.clear();
1728 sel_items.push_back( nextItem );
1729
1730 moved_items.clear();
1731 moved_items.insert( nextItem );
1732 updateStatusPopup( nextItem, itemIdx + 1, orig_items.size() );
1733
1734 // Re-capture the frame angle at the new item's pick-up position.
1735 frameFp = findSingleFp();
1736 frameRotate = frameFp || selectionHasFp();
1737
1738 if( frameRotate )
1739 {
1740 prevFrameAngle = GridFrameAngleAt( *board, frameFp ? frameFp->GetPosition() : originalPos,
1742 }
1743
1744 // Pick up new item
1745 aCommit->Modify( nextItem, nullptr, RECURSE_MODE::RECURSE );
1746 nextItem->Move( controls->GetCursorPosition( true ) - nextItem->GetPosition() );
1747
1748 // Images are on non-cached layers and will not be updated automatically in the overlay, so
1749 // explicitly tell the view they've moved.
1750 if( nextItem->Type() == PCB_REFERENCE_IMAGE_T )
1751 view()->Update( nextItem, KIGFX::GEOMETRY );
1752
1753 continue;
1754 }
1755 }
1756
1757 break; // finish
1758 }
1759 else if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
1760 {
1761 // The first click will move the new item, so put it back
1762 if( moveIndividually )
1763 orig_items[itemIdx]->SetPosition( originalPos );
1764
1765 break; // finish
1766 }
1768 {
1769 angleSnapMode = GetAngleSnapMode();
1770 configureAngleSnap( angleSnapMode );
1771 displayConstraintsMessage( angleSnapMode );
1772 evt->SetPassEvent( true );
1773 }
1774 else if( evt->IsAction( &ACTIONS::increment ) )
1775 {
1776 if( evt->HasParameter() )
1777 m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, evt->Parameter<ACTIONS::INCREMENT>() );
1778 else
1779 m_toolMgr->RunSynchronousAction( ACTIONS::increment, aCommit, ACTIONS::INCREMENT { 1, 0 } );
1780 }
1787 || evt->IsAction( &ACTIONS::find )
1788 || evt->IsAction( &ACTIONS::findNext )
1790 || evt->IsAction( &ACTIONS::redo ) )
1791 {
1792 wxBell();
1793 }
1794 else
1795 {
1796 evt->SetPassEvent();
1797 }
1798
1799 } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
1800
1801 // A shutdown abandons the move rather than committing it
1802 if( !evt )
1803 restore_state = true;
1804
1805 // Clear temporary COURTYARD_CONFLICT flag and ensure the conflict shadow is cleared
1806 if( showCourtyardConflicts )
1807 drc_on_move->ClearConflicts( m_toolMgr->GetView() );
1808
1809 creepage_on_move->Stop();
1810
1811 controls->ForceCursorPosition( false );
1812 controls->ShowCursor( false );
1813 controls->SetAutoPan( false );
1814
1815 m_dragging = false;
1816
1817 // Discard reference point when selection is "dropped" onto the board
1818 selection.ClearReferencePoint();
1819
1820 // Unselect all items to clear selection flags and then re-select the originally selected
1821 // items.
1822 m_toolMgr->RunAction( ACTIONS::selectionClear );
1823
1824 if( restore_state )
1825 {
1826 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
1827 {
1828 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genCancelEdit, aCommit,
1829 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
1830 }
1831 }
1832 else
1833 {
1834 if( sel_items.size() == 1 && sel_items.back()->Type() == PCB_GENERATOR_T )
1835 {
1836 m_toolMgr->RunSynchronousAction( PCB_ACTIONS::genFinishEdit, aCommit,
1837 static_cast<PCB_GENERATOR*>( sel_items.back() ) );
1838 }
1839
1840 // If any moved item is the child of a generator that allows individual selection
1841 // (e.g. a via-stitch via), regenerate the parent so it can react to the new child
1842 // position (the via stitch generator infers its grid offset from the dragged via).
1843 std::set<PCB_GENERATOR*> regenParents;
1844
1845 for( BOARD_ITEM* item : sel_items )
1846 {
1847 EDA_GROUP* parent = item->GetParentGroup();
1848
1849 if( !parent )
1850 continue;
1851
1852 PCB_GENERATOR* gen = dynamic_cast<PCB_GENERATOR*>( parent->AsEdaItem() );
1853
1854 if( gen && gen->ChildrenAreIndividuallySelectable() )
1855 regenParents.insert( gen );
1856 }
1857
1858 if( !regenParents.empty() )
1859 {
1860 GENERATOR_TOOL* genTool = m_toolMgr->GetTool<GENERATOR_TOOL>();
1861
1862 for( PCB_GENERATOR* gen : regenParents )
1863 {
1864 gen->EditStart( genTool, board, aCommit );
1865 gen->Update( genTool, board, aCommit );
1866 gen->EditFinish( genTool, board, aCommit );
1867 }
1868 }
1869
1870 EDA_ITEMS oItems( orig_items.begin(), orig_items.end() );
1871 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &oItems );
1872 }
1873
1874 // Remove the dynamic ratsnest from the screen
1876
1878
1879 m_inMoveWithReference = false;
1880 return !restore_state;
1881}
bool BoardHasConstraints(BOARD *aBoard)
True if aBoard resolves at least one geometric constraint (see CollectResolvedConstraints()).
bool ReSolveShapeClustersHoldingEdited(BOARD *aBoard, const std::vector< PCB_SHAPE * > &aEditedShapes, std::vector< PCB_SHAPE * > *aModified, const std::function< void(BOARD_ITEM *)> &aBeforeModify)
Re-solve clusters whose new geometry is authoritative holding every edited shape fully fixed so only ...
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
BOX2< VECTOR2D > BOX2D
Definition box2.h:918
static TOOL_ACTION findPrevious
Definition actions.h:117
static TOOL_ACTION findNext
Definition actions.h:116
static TOOL_ACTION cursorDblClick
Definition actions.h:178
@ CURSOR_RIGHT
Definition actions.h:313
@ CURSOR_LEFT
Definition actions.h:311
@ CURSOR_UP
Definition actions.h:307
@ CURSOR_DOWN
Definition actions.h:309
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION duplicate
Definition actions.h:81
static TOOL_ACTION doDelete
Definition actions.h:82
static TOOL_ACTION cursorClick
Definition actions.h:177
static TOOL_ACTION redo
Definition actions.h:73
static TOOL_ACTION increment
Definition actions.h:91
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
static TOOL_ACTION cut
Definition actions.h:74
static TOOL_ACTION refreshPreview
Definition actions.h:156
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:229
static TOOL_ACTION find
Definition actions.h:114
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
void Revert() override
Revert the commit by restoring the modified items state.
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
virtual bool SetNetCode(int aNetCode, bool aNoAssert)
Set net using a net code.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual void Move(const VECTOR2I &aMoveVector)
Move this object.
Definition board_item.h:459
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
constexpr const Vec & GetPosition() const
Definition box2.h:214
constexpr BOX2< Vec > & Normalize()
Ensure that the height and width are positive.
Definition box2.h:149
constexpr BOX2< Vec > & Merge(const BOX2< Vec > &aRect)
Modify the position and size of the rectangle in order to contain aRect.
Definition box2.h:597
constexpr coord_type GetLeft() const
Definition box2.h:231
constexpr const Vec & GetOrigin() const
Definition box2.h:213
constexpr coord_type GetRight() const
Definition box2.h:220
constexpr const SizeVec & GetSize() const
Definition box2.h:209
constexpr coord_type GetTop() const
Definition box2.h:232
constexpr void Offset(coord_type dx, coord_type dy)
Definition box2.h:262
constexpr coord_type GetBottom() const
Definition box2.h:225
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition collector.h:107
bool Empty() const
Definition commit.h:145
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:102
Interactive authoring of geometric constraints (issue #2329).
std::shared_ptr< DRC_ENGINE > GetDRCEngine()
Definition drc_tool.h:79
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, INFOBAR_MESSAGE_TYPE aType=INFOBAR_MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
void DisplayConstraintsMsg(const wxString &msg)
bool GetOverrideLocks() const
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
virtual EDA_ITEM * AsEdaItem()=0
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual VECTOR2I GetPosition() const
Definition eda_item.h:348
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:349
wxString GetTypeDesc() const
Return a translated description of the type for this EDA_ITEM for display in user facing messages.
Definition eda_item.cpp:566
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
EDA_ITEM * GetParent() const
Definition eda_item.h:112
virtual const BOX2I ViewBBox() const override
Return the bounding box of the item covering all its layers.
Definition eda_item.cpp:519
bool IsMoving() const
Definition eda_item.h:132
bool IsNew() const
Definition eda_item.h:131
static void collectConstraintShapes(const SELECTION &aSelection, std::vector< PCB_SHAPE * > &aShapes)
Collect constrainable PCB_SHAPEs in aSelection recursing groups and footprints so contained shapes se...
bool isRouterActive() const
int SwapGateNets(const TOOL_EVENT &aEvent)
int Swap(const TOOL_EVENT &aEvent)
Swap currently selected items' positions.
bool m_inMoveWithReference
Definition edit_tool.h:257
int PackAndMoveFootprints(const TOOL_EVENT &aEvent)
Try to fit selected footprints inside a minimal area and start movement.
bool doMoveSelection(const TOOL_EVENT &aEvent, BOARD_COMMIT *aCommit, bool aAutoStart, std::vector< PCB_SHAPE * > *aConstraintShapes=nullptr)
Runs interactive move drag when aConstraintShapes is non null previews constraint solve live each tic...
bool pickReferencePoint(const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
bool m_dragging
Definition edit_tool.h:256
int Move(const TOOL_EVENT &aEvent)
Main loop in which events are handled.
static const unsigned int COORDS_PADDING
Definition edit_tool.h:262
VECTOR2I getSafeMovement(const VECTOR2I &aMovement, const BOX2I &aSourceBBox, const VECTOR2D &aBBoxOffset)
int SwapPadNets(const TOOL_EVENT &aEvent)
Swap nets between selected pads and propagate to connected copper items (tracks, arcs,...
static void PadFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
A selection filter which prunes the selection to contain only items of type PCB_PAD_T.
VECTOR2I m_cursor
Definition edit_tool.h:258
void rebuildConnectivity()
Rebuilds the ratsnest for operations that require it outside the commit rebuild.
PCB_SELECTION_TOOL * m_selectionTool
Definition edit_tool.h:255
static const TOOL_EVENT SelectedEvent
Definition actions.h:347
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
Definition actions.h:354
static const TOOL_EVENT SelectedItemsMoved
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition actions.h:357
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
void SetOrientation(const EDA_ANGLE &aNewAngle)
const std::vector< FP_UNIT_INFO > & GetUnitInfo() const
Definition footprint.h:909
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
bool IsFlipped() const
Definition footprint.h:620
void Flip(const VECTOR2I &aCentre, FLIP_DIRECTION aFlipDirection) override
Flip this object, i.e.
const wxString & GetReference() const
Definition footprint.h:793
VECTOR2I GetPosition() const override
Definition footprint.h:379
PAD * FindPadByNumber(const wxString &aPadNumber, PAD *aSearchAfterMe=nullptr) const
Return a PAD with a matching number.
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
Handle actions specific to filling copper zones.
An interface for classes handling user events controlling the view behavior such as zooming,...
bool IsBOARD_ITEM() const
Definition view_item.h:98
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
Definition pad.h:61
static void SwapShapePositions(PAD *aLhs, PAD *aRhs, PCB_LAYER_ID aActiveLayer)
Swap the visible shape positions of two pads, preserving each pad's own shape offset.
Definition pad.cpp:1839
DISPLAY_OPTIONS m_Display
static TOOL_ACTION mirrorH
Mirroring of selected items.
static TOOL_ACTION genFinishEdit
static TOOL_ACTION hideLocalRatsnest
static TOOL_ACTION genStartEdit
static TOOL_ACTION moveWithReference
move with a reference point
static TOOL_ACTION angleSnapModeChanged
Notification event when angle mode changes.
static TOOL_ACTION moveExact
Activation of the exact move tool.
static TOOL_ACTION copyWithReference
copy command with manual reference point selection
static TOOL_ACTION genCancelEdit
static TOOL_ACTION genUpdateEdit
static TOOL_ACTION updateLocalRatsnest
static TOOL_ACTION moveIndividually
move items one-by-one
static TOOL_ACTION interactiveOffsetTool
static TOOL_ACTION positionRelative
static TOOL_ACTION skip
static TOOL_ACTION move
move or drag an item
static TOOL_ACTION mirrorV
static TOOL_ACTION flip
Flipping of selected objects.
static TOOL_ACTION rotateCw
Rotation of selected objects.
static TOOL_ACTION rotateCcw
Common, abstract interface for edit frames.
virtual EDA_ANGLE GetRotationAngle() const
Return the angle used for rotate operations.
PCBNEW_SETTINGS * GetPcbNewSettings() const
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual PCB_LAYER_ID GetActiveLayer() const
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.
virtual bool ChildrenAreIndividuallySelectable() const
The selection tool: currently supports:
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Drop any PCB_MARKERs from the collector.
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.
void FilterCollectorForLockedItems(GENERAL_COLLECTOR &aCollector)
In the PCB editor strip out any locked items unless the OverrideLocks checkbox is set.
void FilterCollectorForTableCells(GENERAL_COLLECTOR &aCollector) const
Promote any table cell selections to the whole table.
T * frame() const
KIGFX::PCB_VIEW * view() const
LEADER_MODE GetAngleSnapMode() const
Get the current angle snapping mode.
KIGFX::VIEW_CONTROLS * controls() const
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
bool GetMoveWarpsCursor() const
Indicate that a move operation should warp the mouse pointer to the origin of the move object.
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Return the instance of KIGFX::VIEW object used in the application.
Definition tool_base.cpp:34
Generic, UI-independent tool event.
Definition tool_event.h:167
bool DisableGridSnapping() const
Definition tool_event.h:367
bool HasParameter() const
Definition tool_event.h:460
bool IsCancelInteractive() const
Indicate the event should restart/end an ongoing interactive tool's event loop (eg esc key,...
bool IsActivate() const
Definition tool_event.h:341
COMMIT * Commit() const
Definition tool_event.h:279
bool IsClick(int aButtonMask=BUT_ANY) const
bool IsDrag(int aButtonMask=BUT_ANY) const
Definition tool_event.h:311
int Modifier(int aMask=MD_MODIFIER_MASK) const
Return information about key modifiers state (Ctrl, Alt, etc.).
Definition tool_event.h:362
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
T Parameter() const
Return a parameter assigned to the event.
Definition tool_event.h:484
bool IsDblClick(int aButtonMask=BUT_ANY) const
std::atomic< SYNCRONOUS_TOOL_STATE > * SynchronousState() const
Definition tool_event.h:276
void SetPassEvent(bool aPass=true)
Definition tool_event.h:252
bool IsMouseUp(int aButtonMask=BUT_ANY) const
Definition tool_event.h:321
bool IsMotion() const
Definition tool_event.h:326
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.
static bool IsZoneFillAction(const TOOL_EVENT *aEvent)
#define EXCLUDE_ZONES
@ MOVING
Definition cursors.h:45
@ ARROW
Definition cursors.h:43
#define _(s)
static constexpr EDA_ANGLE ANGLE_0
Definition eda_angle.h:472
@ NONE
Definition eda_fill.h:42
@ RECURSE
Definition eda_item.h:51
#define IS_MOVING
Item being moved.
static bool ScheduleNetSwap(BOARD_CONNECTED_ITEM *aItem, int aNewNet, std::unordered_map< BOARD_CONNECTED_ITEM *, int > &aItemNewNets, wxString &aError)
static bool PromptConnectedPadDecision(PCB_BASE_EDIT_FRAME *aFrame, const std::vector< PAD * > &aPads, const wxString &aDialogTitle, bool &aIncludeConnectedPads)
static bool ValidateNetSwapLocks(PCB_BASE_EDIT_FRAME *aFrame, const std::unordered_map< BOARD_CONNECTED_ITEM *, int > &aItemNewNets, const std::unordered_set< PAD * > &aSwapPads, bool aIncludeConnectedPads)
@ FP_JUST_ADDED
Definition footprint.h:91
a few functions useful in geometry calculations.
LEADER_MODE
The kind of the leader line.
@ DEG45
45 Degree only
@ DIRECT
Unconstrained point-to-point.
@ DEG90
90 Degree only
GRID_HELPER_GRIDS
Definition grid_helper.h:55
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ TOP_BOTTOM
Flip top to bottom (around the X axis)
Definition mirror.h:28
@ GEOMETRY
Position or shape has changed.
Definition view_item.h:51
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
@ VERTICAL
A segment (or two points) is vertical.
@ HORIZONTAL
A segment (or two points) is horizontal.
EDA_ANGLE GridFrameAngleAt(const BOARD &aBoard, const VECTOR2I &aPos, PCB_GRID_ROLE aRole)
World frame angle of the grid active for aRole at aPos; ANGLE_0 when no grid applies.
EDA_ANGLE GridFrameRotationDelta(const EDA_ANGLE &aFrom, const EDA_ANGLE &aTo, const EDA_ANGLE &aRotationStep)
Minimal rotation that re-aligns an item from frame angle aFrom to aTo, reduced modulo min( aRotationS...
Class to handle a set of BOARD_ITEMs.
std::vector< EDA_ITEM * > EDA_ITEMS
void SpreadFootprints(std::vector< FOOTPRINT * > *aFootprints, const 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...
Increment event parameters.
Definition actions.h:330
int delta
@ STS_CANCELLED
Definition tool_event.h:160
@ STS_FINISHED
Definition tool_event.h:159
@ STS_RUNNING
Definition tool_event.h:158
@ MD_SHIFT
Definition tool_event.h:139
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
#define kv
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_GENERATOR_T
class PCB_GENERATOR, generator on a layer
Definition typeinfo.h:83
@ PCB_VIA_T
class PCB_VIA, a via (like a track segment on a copper layer)
Definition typeinfo.h:89
@ PCB_DRILL_MAP_T
class PCB_DRILL_MAP, drill symbols drawn at the holes
Definition typeinfo.h:240
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_GRID_ITEM_T
a subgrid placed on a board
Definition typeinfo.h:238
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
@ PCB_ARC_T
class PCB_ARC, an arc track segment on a copper layer
Definition typeinfo.h:90
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707