KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_control.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) 2014-2016 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Maciej Suminski <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22#include "pcb_control.h"
23
24#include <wx/hyperlink.h>
25#include <wx/filename.h>
26
28
29#include <advanced_config.h>
30#include <collectors.h>
31#include <kiplatform/ui.h>
32#include <kiway.h>
33#include <tools/edit_tool.h>
34#include <tools/pad_tool.h>
36#include <router/router_tool.h>
37#include <pgm_base.h>
38#include <tools/pcb_actions.h>
43#include <board_commit.h>
44#include <board.h>
46#include <board_item.h>
48#include <clipboard.h>
49#include <design_block.h>
52#include <pcb_dimension.h>
56#include <footprint.h>
58#include <pad.h>
59#include <netinfo.h>
60#include <layer_pairs.h>
61#include <pcb_group.h>
63#include <pcb_reference_image.h>
64#include <pcb_textbox.h>
66#include <pcb_drill_chart.h>
67#include <pcb_stackup_table.h>
69#include <pcb_drill_map.h>
70#include <pcb_table.h>
71#include <pcb_tablecell.h>
72#include <pcb_track.h>
73#include <pcb_generator.h>
75#include <project_pcb.h>
77#include <filename_resolver.h>
78#include <3d_cache/3d_cache.h>
79#include <embedded_files.h>
80#include <zone.h>
81#include <confirm.h>
82#include <kidialog.h>
84#include <core/kicad_algo.h>
87#include <drc/drc_engine.h>
88#include <drc/drc_rule.h>
90#include <kicad_clipboard.h>
91#include <origin_viewitem.h>
92#include <pcb_edit_frame.h>
93#include <pcb_painter.h>
95#include <string>
96#include <tool/tool_manager.h>
104#include <widgets/wx_infobar.h>
105#include <pcb_io/pcb_io.h>
106
107
108using namespace std::placeholders;
109
110
111// files.cpp
112extern bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, wxString* aFileName, int aCtl = 0 );
113
114// board_tables/board_characteristics_table.cpp
115extern PCB_TABLE* Build_Board_Characteristics_Table( BOARD* aBoard, EDA_UNITS aDisplayUnits );
116
117
119 PCB_TOOL_BASE( "pcbnew.Control" ),
120 m_frame( nullptr ),
121 m_pickerItem( nullptr )
122{
124}
125
126
130
131
133{
135
136 if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH || aReason == REDRAW )
137 {
138 m_gridOrigin->SetPosition( board()->GetDesignSettings().GetGridOrigin() );
139
140 double backgroundBrightness = m_frame->GetCanvas()->GetGAL()->GetClearColor().GetBrightness();
141 COLOR4D color = m_frame->GetGridColor();
142
143 if( backgroundBrightness > 0.5 )
144 color.Darken( 0.25 );
145 else
146 color.Brighten( 0.25 );
147
148 m_gridOrigin->SetColor( color );
149
150 getView()->Remove( m_gridOrigin.get() );
151 getView()->Add( m_gridOrigin.get() );
152 }
153}
154
155
157{
158 if( m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) || m_frame->IsType( FRAME_PCB_EDITOR ) )
159 {
160 if( aEvent.IsAction( &ACTIONS::newLibrary ) )
161 static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->CreateNewLibrary( _( "New Footprint Library" ) );
162 else if( aEvent.IsAction( &ACTIONS::addLibrary ) )
163 static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->AddLibrary( _( "Add Footprint Library" ) );
164 }
165
166 return 0;
167}
168
169
171{
172 if( m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
173 static_cast<FOOTPRINT_EDIT_FRAME*>( m_frame )->LoadFootprintFromBoard( nullptr );
174
175 return 0;
176}
177
178
180{
181 if( m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) )
182 static_cast<FOOTPRINT_EDIT_FRAME*>( m_frame )->SaveFootprintToBoard( true );
183 else if( m_frame->IsType( FRAME_FOOTPRINT_VIEWER ) )
184 static_cast<FOOTPRINT_VIEWER_FRAME*>( m_frame )->AddFootprintToPCB();
185
186 return 0;
187}
188
189
191{
192 const wxString fn = *aEvent.Parameter<wxString*>();
193 static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->AddLibrary( _( "Add Footprint Library" ), fn,
195 return 0;
196}
197
198
200{
201 const wxString fn = *aEvent.Parameter<wxString*>();
202 static_cast<FOOTPRINT_EDIT_FRAME*>( m_frame )->ImportFootprint( fn );
203 m_frame->Zoom_Automatique( false );
204 return 0;
205}
206
207
209{
210 if( m_frame->IsType( FRAME_FOOTPRINT_VIEWER ) )
211 static_cast<FOOTPRINT_VIEWER_FRAME*>( m_frame )->SelectAndViewFootprint( aEvent.Parameter<FPVIEWER_CONSTANTS>() );
212
213 return 0;
214}
215
216
217template<class T>
218void Flip( T& aValue )
219{
220 aValue = !aValue;
221}
222
223
225{
226 Flip( displayOptions().m_DisplayPcbTrackFill );
227
228 for( PCB_TRACK* track : board()->Tracks() )
229 {
230 if( track->Type() == PCB_TRACE_T || track->Type() == PCB_ARC_T )
231 view()->Update( track, KIGFX::REPAINT );
232 }
233
234 for( BOARD_ITEM* shape : board()->Drawings() )
235 {
236 if( shape->Type() == PCB_SHAPE_T && static_cast<PCB_SHAPE*>( shape )->IsOnCopperLayer() )
237 view()->Update( shape, KIGFX::REPAINT );
238 }
239
240 canvas()->Refresh();
241
242 return 0;
243}
244
245
247{
248 if( PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
249 {
250 if( aEvent.IsAction( &PCB_ACTIONS::showRatsnest ) )
251 {
252 // N.B. Do not disable the Ratsnest layer here. We use it for local ratsnest
253 Flip( displayOptions().m_ShowGlobalRatsnest );
254 editFrame->SetElementVisibility( LAYER_RATSNEST, displayOptions().m_ShowGlobalRatsnest );
255 }
256 else if( aEvent.IsAction( &PCB_ACTIONS::ratsnestLineMode ) )
257 {
258 Flip( displayOptions().m_DisplayRatsnestLinesCurved );
259 }
260
261 editFrame->OnDisplayOptionsChanged();
262
264 canvas()->Refresh();
265 }
266
267 return 0;
268}
269
270
272{
273 Flip( displayOptions().m_DisplayViaFill );
274
275 for( PCB_TRACK* track : board()->Tracks() )
276 {
277 if( track->Type() == PCB_VIA_T )
278 view()->Update( track, KIGFX::REPAINT );
279 }
280
281 canvas()->Refresh();
282 return 0;
283}
284
285
292{
293 if( Pgm().GetCommonSettings()->m_DoNotShowAgain.zone_fill_warning )
294 return;
295
296 bool unfilledZones = false;
297
298 for( const ZONE* zone : board()->Zones() )
299 {
300 if( !zone->GetIsRuleArea() && !zone->IsFilled() )
301 {
302 unfilledZones = true;
303 break;
304 }
305 }
306
307 if( unfilledZones )
308 {
309 WX_INFOBAR* infobar = m_frame->GetInfoBar();
310
311 infobar->RemoveAllButtons();
312 infobar->AddLink( _( "Don't show again" ),
313 [&]( wxHyperlinkEvent& aEvent )
314 {
316 m_frame->GetInfoBar()->Dismiss();
317 } );
318
319 wxString msg;
320 msg.Printf( _( "Not all zones are filled. Use Edit > Fill All Zones (%s) if you wish to see all fills." ),
322
323 infobar->ShowMessageFor( msg, 5000, wxICON_WARNING );
324 }
325}
326
327
329{
330 PCB_DISPLAY_OPTIONS opts = m_frame->GetDisplayOptions();
331
332 // Apply new display options to the GAL canvas
334 {
336
338 }
339 else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayOutline ) )
340 {
342 }
343 else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayFractured ) )
344 {
346 }
348 {
350 }
351 else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayToggle ) )
352 {
355 else
357 }
358 else
359 {
360 wxFAIL;
361 }
362
363 m_frame->SetDisplayOptions( opts );
364
365 for( ZONE* zone : board()->Zones() )
366 view()->Update( zone, KIGFX::REPAINT );
367
368 canvas()->Refresh();
369
370 return 0;
371}
372
373
375{
376 PCB_DISPLAY_OPTIONS opts = m_frame->GetDisplayOptions();
377
380
381 m_frame->SetDisplayOptions( opts );
382 return 0;
383}
384
385
387{
388 PCB_DISPLAY_OPTIONS opts = m_frame->GetDisplayOptions();
389
390 switch( opts.m_ContrastModeDisplay )
391 {
395 }
396
397 m_frame->SetDisplayOptions( opts );
398
400 return 0;
401}
402
403
405{
406 if( !Pgm().GetCommonSettings()->m_Input.hotkey_feedback )
407 return 0;
408
409 PCB_DISPLAY_OPTIONS opts = m_frame->GetDisplayOptions();
410
411 wxArrayString labels;
412 labels.Add( _( "Normal" ) );
413 labels.Add( _( "Dimmed" ) );
414 labels.Add( _( "Hidden" ) );
415
416 if( !m_frame->GetHotkeyPopup() )
417 m_frame->CreateHotkeyPopup();
418
419 HOTKEY_CYCLE_POPUP* popup = m_frame->GetHotkeyPopup();
420
421 if( popup )
422 {
423 popup->Popup( _( "Inactive Layer Display" ), labels, static_cast<int>( opts.m_ContrastModeDisplay ) );
424 }
425
426 return 0;
427}
428
429
431{
432 PCB_DISPLAY_OPTIONS opts = m_frame->GetDisplayOptions();
433
434 switch( opts.m_NetColorMode )
435 {
439 }
440
441 m_frame->SetDisplayOptions( opts );
442 return 0;
443}
444
445
447{
448 if( PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
449 {
450 if( !displayOptions().m_ShowGlobalRatsnest )
451 {
454 }
455 else if( displayOptions().m_RatsnestMode == RATSNEST_MODE::ALL )
456 {
458 }
459 else
460 {
462 }
463
464 editFrame->SetElementVisibility( LAYER_RATSNEST, displayOptions().m_ShowGlobalRatsnest );
465
466 editFrame->OnDisplayOptionsChanged();
467
469 canvas()->Refresh();
470 }
471
472 return 0;
473}
474
475
477{
478 m_frame->SwitchLayer( aEvent.Parameter<PCB_LAYER_ID>() );
479
480 return 0;
481}
482
483
485{
486 BOARD* brd = board();
487 PCB_LAYER_ID layer = m_frame->GetActiveLayer();
488 bool wraparound = false;
489
490 if( !IsCopperLayer( layer ) )
491 {
492 m_frame->SwitchLayer( B_Cu );
493 return 0;
494 }
495
496 LSET cuMask = LSET::AllCuMask( brd->GetCopperLayerCount() );
497 LSEQ layerStack = cuMask.UIOrder();
498
499 int ii = 0;
500
501 // Find the active layer in list
502 for( ; ii < (int) layerStack.size(); ii++ )
503 {
504 if( layer == layerStack[ii] )
505 break;
506 }
507
508 // Find the next visible layer in list
509 for( ; ii < (int) layerStack.size(); ii++ )
510 {
511 int jj = ii + 1;
512
513 if( jj >= (int) layerStack.size() )
514 jj = 0;
515
516 layer = layerStack[jj];
517
518 if( brd->IsLayerVisible( layer ) )
519 break;
520
521 if( jj == 0 ) // the end of list is reached. Try from the beginning
522 {
523 if( wraparound )
524 {
525 wxBell();
526 return 0;
527 }
528 else
529 {
530 wraparound = true;
531 ii = -1;
532 }
533 }
534 }
535
536 wxCHECK( IsCopperLayer( layer ), 0 );
537 m_frame->SwitchLayer( layer );
538
539 return 0;
540}
541
542
544{
545 BOARD* brd = board();
546 PCB_LAYER_ID layer = m_frame->GetActiveLayer();
547 bool wraparound = false;
548
549 if( !IsCopperLayer( layer ) )
550 {
551 m_frame->SwitchLayer( F_Cu );
552 return 0;
553 }
554
555 LSET cuMask = LSET::AllCuMask( brd->GetCopperLayerCount() );
556 LSEQ layerStack = cuMask.UIOrder();
557
558 int ii = 0;
559
560 // Find the active layer in list
561 for( ; ii < (int) layerStack.size(); ii++ )
562 {
563 if( layer == layerStack[ii] )
564 break;
565 }
566
567 // Find the previous visible layer in list
568 for( ; ii >= 0; ii-- )
569 {
570 int jj = ii - 1;
571
572 if( jj < 0 )
573 jj = (int) layerStack.size() - 1;
574
575 layer = layerStack[jj];
576
577 if( brd->IsLayerVisible( layer ) )
578 break;
579
580 if( ii == 0 ) // the start of list is reached. Try from the last
581 {
582 if( wraparound )
583 {
584 wxBell();
585 return 0;
586 }
587 else
588 {
589 wraparound = true;
590 ii = 1;
591 }
592 }
593 }
594
595 wxCHECK( IsCopperLayer( layer ), 0 );
596 m_frame->SwitchLayer( layer );
597
598 return 0;
599}
600
601
603{
604 int currentLayer = m_frame->GetActiveLayer();
605 PCB_SCREEN* screen = m_frame->GetScreen();
606
607 if( currentLayer == screen->m_Route_Layer_TOP )
608 m_frame->SwitchLayer( screen->m_Route_Layer_BOTTOM );
609 else
610 m_frame->SwitchLayer( screen->m_Route_Layer_TOP );
611
612 return 0;
613}
614
615
616// It'd be nice to share the min/max with the DIALOG_COLOR_PICKER, but those are
617// set in wxFormBuilder.
618#define ALPHA_MIN 0.20
619#define ALPHA_MAX 1.00
620#define ALPHA_STEP 0.05
621
622
624{
625 COLOR_SETTINGS* settings = m_frame->GetColorSettings();
626 int currentLayer = m_frame->GetActiveLayer();
627 KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
628
629 if( currentColor.a <= ALPHA_MAX - ALPHA_STEP )
630 {
631 currentColor.a += ALPHA_STEP;
632 settings->SetColor( currentLayer, currentColor );
633 m_frame->GetCanvas()->UpdateColors();
634
635 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
636 view->UpdateLayerColor( currentLayer );
637 view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
638
639 if( IsCopperLayer( currentLayer ) )
640 view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
641
642 m_frame->GetCanvas()->ForceRefresh();
643 }
644 else
645 {
646 wxBell();
647 }
648
649 return 0;
650}
651
652
654{
655 COLOR_SETTINGS* settings = m_frame->GetColorSettings();
656 int currentLayer = m_frame->GetActiveLayer();
657 KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
658
659 if( currentColor.a >= ALPHA_MIN + ALPHA_STEP )
660 {
661 currentColor.a -= ALPHA_STEP;
662 settings->SetColor( currentLayer, currentColor );
663 m_frame->GetCanvas()->UpdateColors();
664
665 KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
666 view->UpdateLayerColor( currentLayer );
667 view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
668
669 if( IsCopperLayer( currentLayer ) )
670 view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
671
672 m_frame->GetCanvas()->ForceRefresh();
673 }
674 else
675 {
676 wxBell();
677 }
678
679 return 0;
680}
681
682
684{
685 if( PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
686 {
687 LAYER_PAIR_SETTINGS* settings = editFrame->GetLayerPairSettings();
688
689 if( !settings )
690 return 0;
691
692 int currentIndex;
693 std::vector<LAYER_PAIR_INFO> presets = settings->GetEnabledLayerPairs( currentIndex );
694
695 if( presets.size() < 2 )
696 return 0;
697
698 if( currentIndex < 0 )
699 {
700 wxASSERT_MSG( false, "Current layer pair not found in layer settings" );
701 currentIndex = 0;
702 }
703
704 const int nextIndex = ( currentIndex + 1 ) % presets.size();
705 const LAYER_PAIR& nextPair = presets[nextIndex].GetLayerPair();
706
707 settings->SetCurrentLayerPair( nextPair );
708
710 }
711
712 return 0;
713}
714
715
717{
718 if( !Pgm().GetCommonSettings()->m_Input.hotkey_feedback )
719 return 0;
720
721 if( PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame ) )
722 {
723 LAYER_PAIR_SETTINGS* settings = editFrame->GetLayerPairSettings();
724
725 if( !settings )
726 return 0;
727
728 PCB_LAYER_PRESENTATION layerPresentation( editFrame );
729
730 int currentIndex;
731 std::vector<LAYER_PAIR_INFO> presets = settings->GetEnabledLayerPairs( currentIndex );
732
733 wxArrayString labels;
734 for( const LAYER_PAIR_INFO& layerPairInfo : presets )
735 {
736 wxString label = layerPresentation.getLayerPairName( layerPairInfo.GetLayerPair() );
737
738 if( layerPairInfo.GetName() )
739 label += wxT( " (" ) + *layerPairInfo.GetName() + wxT( ")" );
740
741 labels.Add( label );
742 }
743
744 if( !editFrame->GetHotkeyPopup() )
745 editFrame->CreateHotkeyPopup();
746
747 HOTKEY_CYCLE_POPUP* popup = editFrame->GetHotkeyPopup();
748
749 if( popup )
750 {
751 int selection = currentIndex;
752 popup->Popup( _( "Preset Layer Pairs" ), labels, selection );
753 }
754 }
755
756 return 0;
757}
758
759
761 const VECTOR2D& aPoint )
762{
763 aFrame->GetDesignSettings().SetGridOrigin( VECTOR2I( aPoint ) );
764 aView->GetGAL()->SetGridOrigin( aPoint );
765 originViewItem->SetPosition( aPoint );
766 aView->MarkDirty();
767 aFrame->OnModify();
768}
769
770
772{
773 VECTOR2D* origin = aEvent.Parameter<VECTOR2D*>();
774
775 if( origin )
776 {
777 // We can't undo the other grid dialog settings, so no sense undoing just the origin
778 DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), *origin );
779 delete origin;
780 }
781 else
782 {
784 return 0;
785
786 PCB_PICKER_TOOL* picker = m_toolMgr->GetTool<PCB_PICKER_TOOL>();
787
788 if( !picker ) // Happens in footprint wizard
789 return 0;
790
791 // Deactivate other tools; particularly important if another PICKER is currently running
792 Activate();
793
794 picker->SetCursor( KICURSOR::PLACE );
795 picker->ClearHandlers();
796
797 picker->SetClickHandler(
798 [this]( const VECTOR2D& pt ) -> bool
799 {
800 m_frame->SaveCopyInUndoList( m_gridOrigin.get(), UNDO_REDO::GRIDORIGIN );
802 return false; // drill origin is a one-shot; don't continue with tool
803 } );
804
805 m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
806 }
807
808 return 0;
809}
810
811
813{
814 m_frame->SaveCopyInUndoList( m_gridOrigin.get(), UNDO_REDO::GRIDORIGIN );
816 return 0;
817}
818
819
820#define HITTEST_THRESHOLD_PIXELS 5
821
822
824{
825 if( m_isFootprintEditor && !m_frame->GetBoard()->GetFirstFootprint() )
826 return 0;
827
828 PCB_PICKER_TOOL* picker = m_toolMgr->GetTool<PCB_PICKER_TOOL>();
829 EDIT_TOOL* editTool = m_toolMgr->GetTool<EDIT_TOOL>();
830
831 if( !picker || !editTool )
832 return 0;
833
834 m_pickerItem = nullptr;
836
837 // Deactivate other tools; particularly important if another PICKER is currently running
838 Activate();
839
840 picker->SetCursor( KICURSOR::REMOVE );
841 picker->SetSnapping( false );
842 picker->ClearHandlers();
843
844 picker->SetClickHandler(
845 [this, editTool]( const VECTOR2D& aPosition ) -> bool
846 {
847 if( m_pickerItem )
848 {
849 if( m_pickerItem && m_pickerItem->IsLocked() )
850 {
852 m_statusPopup->SetText( _( "Item locked." ) );
853 m_statusPopup->PopupFor( 2000 );
854 m_statusPopup->Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
855 return true;
856 }
857
858 PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
859 selectionTool->UnbrightenItem( m_pickerItem );
860
861 PCB_SELECTION items;
862 items.Add( m_pickerItem );
863
864 editTool->DeleteItems( items, false );
865
866 m_pickerItem = nullptr;
867 }
868
869 return true;
870 } );
871
872 picker->SetMotionHandler(
873 [this]( const VECTOR2D& aPos )
874 {
875 BOARD* board = m_frame->GetBoard();
876 PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
877 GENERAL_COLLECTORS_GUIDE guide = m_frame->GetCollectorsGuide();
878 GENERAL_COLLECTOR collector;
879 collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
880
882 collector.Collect( board, GENERAL_COLLECTOR::FootprintItems, aPos, guide );
883 else
884 collector.Collect( board, GENERAL_COLLECTOR::BoardLevelItems, aPos, guide );
885
886 // Remove unselectable items
887 for( int i = collector.GetCount() - 1; i >= 0; --i )
888 {
889 if( !selectionTool->Selectable( collector[i] ) )
890 collector.Remove( i );
891 }
892
893 selectionTool->FilterCollectorForHierarchy( collector, false );
894 selectionTool->FilterCollectedItems( collector, false, nullptr );
895
896 if( collector.GetCount() > 1 )
897 selectionTool->GuessSelectionCandidates( collector, aPos );
898
899 BOARD_ITEM* item = collector.GetCount() == 1 ? collector[0] : nullptr;
900
901 if( m_pickerItem != item )
902 {
903 if( m_pickerItem )
904 selectionTool->UnbrightenItem( m_pickerItem );
905
906 m_pickerItem = item;
907
908 if( m_pickerItem )
909 selectionTool->BrightenItem( m_pickerItem );
910 }
911 } );
912
913 picker->SetFinalizeHandler(
914 [this]( const int& aFinalState )
915 {
916 if( m_pickerItem )
917 m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->UnbrightenItem( m_pickerItem );
918
919 m_statusPopup.reset();
920
921 // Ensure the cursor gets changed&updated
922 m_frame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
923 m_frame->GetCanvas()->Refresh();
924 } );
925
926 m_toolMgr->RunAction( ACTIONS::pickerTool, &aEvent );
927
928 return 0;
929}
930
931
932static void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBoard,
933 std::vector<BOARD_ITEM*>& aPastedItems )
934{
935 FOOTPRINT* editorFootprint = aBoard->GetFirstFootprint();
936
937 aClipFootprint->SetParent( aBoard );
938
939 for( PAD* pad : aClipFootprint->Pads() )
940 {
941 pad->SetParent( editorFootprint );
942 aPastedItems.push_back( pad );
943 }
944
945 aClipFootprint->Pads().clear();
946
947 // Not all items can be added to the current footprint: mandatory fields are already existing
948 // in the current footprint.
949 //
950 for( PCB_FIELD* field : aClipFootprint->GetFields() )
951 {
952 wxCHECK2( field, continue );
953
954 if( field->IsMandatory() )
955 {
956 if( EDA_GROUP* parentGroup = field->GetParentGroup() )
957 parentGroup->RemoveItem( field );
958 }
959 else
960 {
961 PCB_TEXT* text = static_cast<PCB_TEXT*>( field );
962
963 text->SetTextAngle( text->GetTextAngle() - aClipFootprint->GetOrientation() );
964 text->SetTextAngle( text->GetTextAngle() + editorFootprint->GetOrientation() );
965
966 VECTOR2I pos = field->GetFPRelativePosition();
967 field->SetParent( editorFootprint );
968 field->SetFPRelativePosition( pos );
969
970 aPastedItems.push_back( field );
971 }
972 }
973
974 aClipFootprint->GetFields().clear();
975
976 for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() )
977 {
978 if( item->Type() == PCB_TEXT_T )
979 {
980 PCB_TEXT* text = static_cast<PCB_TEXT*>( item );
981
982 text->SetTextAngle( text->GetTextAngle() - aClipFootprint->GetOrientation() );
983 text->SetTextAngle( text->GetTextAngle() + editorFootprint->GetOrientation() );
984 }
985
986 item->Rotate( item->GetPosition(), -aClipFootprint->GetOrientation() );
987 item->Rotate( item->GetPosition(), editorFootprint->GetOrientation() );
988
989 VECTOR2I pos = item->GetFPRelativePosition();
990 item->SetParent( editorFootprint );
991 item->SetFPRelativePosition( pos );
992
993 aPastedItems.push_back( item );
994 }
995
996 aClipFootprint->GraphicalItems().clear();
997
998 for( ZONE* zone : aClipFootprint->Zones() )
999 {
1000 zone->SetParent( editorFootprint );
1001 aPastedItems.push_back( zone );
1002 }
1003
1004 aClipFootprint->Zones().clear();
1005
1006 for( PCB_GROUP* group : aClipFootprint->Groups() )
1007 {
1008 group->SetParent( editorFootprint );
1009 aPastedItems.push_back( group );
1010 }
1011
1012 aClipFootprint->Groups().clear();
1013
1014 // Constraints ride along like the other containers; the KIID remap in placeBoardItems points
1015 // their members at the pasted copies.
1016 for( PCB_CONSTRAINT* constraint : aClipFootprint->Constraints() )
1017 {
1018 constraint->SetParent( editorFootprint );
1019 aPastedItems.push_back( constraint );
1020 }
1021
1022 aClipFootprint->Constraints().clear();
1023}
1024
1025
1026void PCB_CONTROL::pruneItemLayers( std::vector<BOARD_ITEM*>& aItems )
1027{
1028 // Do not prune items or layers when copying to the FP editor, because all
1029 // layers are accepted, even if they are not enabled in the dummy board
1030 // This is mainly true for internal copper layers: all are allowed but only one
1031 // (In1.cu) is enabled for the GUI.
1033 return;
1034
1035 LSET enabledLayers = board()->GetEnabledLayers();
1036 const int copperLayers = board()->GetCopperLayerCount();
1037 std::vector<BOARD_ITEM*> returnItems;
1038
1039 for( BOARD_ITEM* item : aItems )
1040 {
1041 if( !item->FitsEnabledLayers( enabledLayers, copperLayers ) )
1042 {
1043 if( EDA_GROUP* parentGroup = item->GetParentGroup() )
1044 parentGroup->RemoveItem( item );
1045
1046 continue;
1047 }
1048
1049 // Confine a kept item to the layers this board has; a layer-agnostic one has none to confine
1050 if( !item->IsLayerAgnostic() )
1051 item->SetLayerSet( item->GetLayerSet() & enabledLayers );
1052
1053 returnItems.push_back( item );
1054 }
1055
1056 if( returnItems.size() < aItems.size() )
1057 {
1058 DisplayError( m_frame, _( "Warning: some pasted items were on layers which are not "
1059 "present in the current board.\n"
1060 "These items could not be pasted.\n" ) );
1061 }
1062
1063 aItems = returnItems;
1064}
1065
1066
1071static void recordPastedItems( TOOL_MANAGER* aToolMgr, const std::vector<BOARD_ITEM*>& aItems )
1072{
1073 PAD_TOOL* padTool = aToolMgr->GetTool<PAD_TOOL>();
1074
1075 if( !padTool )
1076 return;
1077
1078 for( BOARD_ITEM* item : aItems )
1079 {
1080 if( PAD* pad = dynamic_cast<PAD*>( item ) )
1081 padTool->RecordMasterPad( *pad );
1082 }
1083}
1084
1085
1086int PCB_CONTROL::Paste( const TOOL_EVENT& aEvent )
1087{
1088 // The viewer frames cannot paste
1089 if( !m_frame->IsType( FRAME_FOOTPRINT_EDITOR ) && !m_frame->IsType( FRAME_PCB_EDITOR ) )
1090 return 0;
1091
1092 bool isFootprintEditor = m_isFootprintEditor || m_frame->IsType( FRAME_FOOTPRINT_EDITOR );
1093
1094 // The clipboard can contain two different things, an entire kicad_pcb or a single footprint
1095 if( isFootprintEditor && ( !board() || !footprint() ) )
1096 return 0;
1097
1098 // We should never get here if a modal dialog is up... but we do on MacOS.
1099 // https://gitlab.com/kicad/code/kicad/-/issues/18912
1100#ifdef __WXMAC__
1101 if( wxDialog::OSXHasModalDialogsOpen() )
1102 {
1103 wxBell();
1104 return 0;
1105 }
1106#endif
1107
1108 BOARD_COMMIT commit( m_frame );
1109
1110 CLIPBOARD_IO pi;
1111 BOARD_ITEM* clipItem = pi.Parse();
1112
1113 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
1114
1115 if( selTool && clipItem )
1116 {
1117 PCB_SELECTION& selection = selTool->GetSelection();
1118
1119 bool hasTableCells = false;
1120
1121 for( EDA_ITEM* item : selection )
1122 {
1123 if( item->Type() == PCB_TABLECELL_T )
1124 {
1125 hasTableCells = true;
1126 break;
1127 }
1128 }
1129
1130 if( hasTableCells )
1131 {
1132 PCB_TABLE* clipboardTable = nullptr;
1133
1134 if( clipItem->Type() == PCB_T )
1135 {
1136 BOARD* clipBoard = static_cast<BOARD*>( clipItem );
1137
1138 for( BOARD_ITEM* item : clipBoard->Drawings() )
1139 {
1140 if( item->Type() == PCB_TABLE_T )
1141 {
1142 clipboardTable = static_cast<PCB_TABLE*>( item );
1143 break;
1144 }
1145 }
1146 }
1147
1148 if( clipboardTable )
1149 {
1150 PCB_EDIT_TABLE_TOOL* tableEditTool = m_toolMgr->GetTool<PCB_EDIT_TABLE_TOOL>();
1151
1152 if( tableEditTool )
1153 {
1154 wxString errorMsg;
1155
1156 if( !tableEditTool->validatePasteIntoSelection( selection, errorMsg ) )
1157 {
1158 DisplayError( m_frame, errorMsg );
1159 return 0;
1160 }
1161
1162 if( tableEditTool->pasteCellsIntoSelection( selection, clipboardTable, commit ) )
1163 {
1164 commit.Push( _( "Paste Cells" ) );
1165 return 0;
1166 }
1167 else
1168 {
1169 DisplayError( m_frame, _( "Failed to paste cells" ) );
1170 return 0;
1171 }
1172 }
1173 }
1174 }
1175 }
1176
1177 if( !clipItem )
1178 {
1179 // When the clipboard doesn't parse, create a PCB item with the clipboard contents
1180 std::vector<BOARD_ITEM*> newItems;
1181
1182 if( std::unique_ptr<wxBitmap> clipImg = GetImageFromClipboard() )
1183 {
1184 auto refImg = std::make_unique<PCB_REFERENCE_IMAGE>( m_frame->GetModel() );
1185
1186 if( refImg->GetReferenceImage().SetImage( clipImg->ConvertToImage() ) )
1187 newItems.push_back( refImg.release() );
1188 }
1189 else
1190 {
1191 const wxString clipText = GetClipboardUTF8();
1192
1193 if( clipText.empty() )
1194 return 0;
1195
1196 // If it wasn't content, then paste as a text object.
1197 if( clipText.size() > static_cast<size_t>( ADVANCED_CFG::GetCfg().m_MaxPastedTextLength ) )
1198 {
1199 int result = IsOK( m_frame, _( "Pasting a long text text string may be very slow. "
1200 "Do you want to continue?" ) );
1201 if( !result )
1202 return 0;
1203 }
1204
1205 std::unique_ptr<PCB_TEXT> item = std::make_unique<PCB_TEXT>( m_frame->GetModel() );
1206 item->SetText( clipText );
1207 item->SetLayer( m_frame->GetActiveLayer() );
1208
1209 newItems.push_back( item.release() );
1210 }
1211
1212 bool cancelled = !placeBoardItems( &commit, newItems, true, false, false, false );
1213
1214 if( cancelled )
1215 commit.Revert();
1216 else
1217 commit.Push( _( "Paste Text" ) );
1218 return 0;
1219 }
1220
1221 // If we get here, we have a parsed board/FP to paste
1222
1224 bool clear_nets = false;
1225 const wxString defaultRef = wxT( "REF**" );
1226
1227 if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
1228 {
1229 DIALOG_PASTE_SPECIAL dlg( m_frame, &mode, defaultRef );
1230
1231 if( clipItem->Type() != PCB_T )
1232 dlg.HideClearNets();
1233
1234 if( dlg.ShowModal() == wxID_CANCEL )
1235 return 0;
1236
1237 clear_nets = dlg.GetClearNets();
1238 }
1239
1240 if( clipItem->Type() == PCB_T )
1241 {
1242 BOARD* clipBoard = static_cast<BOARD*>( clipItem );
1243
1244 if( isFootprintEditor || clear_nets )
1245 {
1246 for( BOARD_CONNECTED_ITEM* item : clipBoard->AllConnectedItems() )
1247 item->SetNet( NETINFO_LIST::OrphanedItem() );
1248 }
1249 else
1250 {
1251 clipBoard->MapNets( m_frame->GetBoard() );
1252 }
1253 }
1254
1255 bool cancelled = false;
1256
1257 switch( clipItem->Type() )
1258 {
1259 case PCB_T:
1260 {
1261 BOARD* clipBoard = static_cast<BOARD*>( clipItem );
1262
1263 if( isFootprintEditor )
1264 {
1265 FOOTPRINT* editorFootprint = board()->GetFirstFootprint();
1266 std::vector<BOARD_ITEM*> pastedItems;
1267
1268 for( PCB_GROUP* group : clipBoard->Groups() )
1269 {
1270 group->SetParent( editorFootprint );
1271 pastedItems.push_back( group );
1272 }
1273
1274 clipBoard->RemoveAll( { PCB_GROUP_T } );
1275
1276 for( FOOTPRINT* clipFootprint : clipBoard->Footprints() )
1277 pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
1278
1279 for( BOARD_ITEM* clipDrawItem : clipBoard->Drawings() )
1280 {
1281 switch( clipDrawItem->Type() )
1282 {
1283 case PCB_TEXT_T:
1284 case PCB_TEXTBOX_T:
1285 case PCB_TABLE_T:
1286 case PCB_SHAPE_T:
1287 case PCB_BARCODE_T:
1288 case PCB_DIM_ALIGNED_T:
1289 case PCB_DIM_CENTER_T:
1290 case PCB_DIM_LEADER_T:
1292 case PCB_DIM_RADIAL_T:
1293 case PCB_POINT_T:
1294 clipDrawItem->SetParent( editorFootprint );
1295 pastedItems.push_back( clipDrawItem );
1296 break;
1297
1298 default:
1299 // Everything we *didn't* put into pastedItems is going to get nuked, so
1300 // make sure it's not still included in its parent group.
1301 if( EDA_GROUP* parentGroup = clipDrawItem->GetParentGroup() )
1302 parentGroup->RemoveItem( clipDrawItem );
1303
1304 break;
1305 }
1306 }
1307
1308 // Board-scoped constraints ride along like the footprint-scoped ones above, so a
1309 // constrained sketch keeps its relations when pasted into a footprint. The clipboard
1310 // only carries a constraint whose every member was copied, and placeBoardItems repoints
1311 // those members at the pasted copies.
1312 for( PCB_CONSTRAINT* constraint : clipBoard->Constraints() )
1313 {
1314 constraint->SetParent( editorFootprint );
1315 pastedItems.push_back( constraint );
1316 }
1317
1318 // NB: PCB_SHAPE_T actually removes everything in Drawings() (including PCB_TEXTs,
1319 // PCB_TABLEs, PCB_BARCODEs, dimensions, etc.), not just PCB_SHAPEs.)
1320 clipBoard->RemoveAll( { PCB_SHAPE_T, PCB_CONSTRAINT_T } );
1321
1322 clipBoard->Visit(
1323 [&]( EDA_ITEM* item, void* testData )
1324 {
1325 if( item->IsBOARD_ITEM() )
1326 {
1327 // Anything still on the clipboard didn't get copied and needs to be
1328 // removed from the pasted groups.
1329 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( item );
1330 EDA_GROUP* parentGroup = boardItem->GetParentGroup();
1331
1332 if( parentGroup )
1333 parentGroup->RemoveItem( boardItem );
1334 }
1335
1337 },
1339
1340 delete clipBoard;
1341
1342 pruneItemLayers( pastedItems );
1343
1344 cancelled = !placeBoardItems( &commit, pastedItems, true, true, mode == PASTE_MODE::UNIQUE_ANNOTATIONS,
1345 false );
1346
1347 if( !cancelled )
1348 recordPastedItems( m_toolMgr, pastedItems );
1349 }
1350 else // isBoardEditor
1351 {
1352 // Fixup footprint component classes
1353 for( FOOTPRINT* fp : clipBoard->Footprints() )
1354 {
1355 fp->ResolveComponentClassNames( board(), fp->GetTransientComponentClassNames() );
1356 fp->ClearTransientComponentClassNames();
1357 }
1358
1359 if( mode == PASTE_MODE::REMOVE_ANNOTATIONS )
1360 {
1361 for( FOOTPRINT* fp : clipBoard->Footprints() )
1362 fp->SetReference( defaultRef );
1363 }
1364
1365 cancelled = !placeBoardItems( &commit, clipBoard, true, mode == PASTE_MODE::UNIQUE_ANNOTATIONS, false );
1366 }
1367
1368 break;
1369 }
1370
1371 case PCB_FOOTPRINT_T:
1372 {
1373 FOOTPRINT* clipFootprint = static_cast<FOOTPRINT*>( clipItem );
1374 std::vector<BOARD_ITEM*> pastedItems;
1375
1376 if( isFootprintEditor )
1377 {
1378 pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
1379 delete clipFootprint;
1380 }
1381 else
1382 {
1383 if( mode == PASTE_MODE::REMOVE_ANNOTATIONS )
1384 clipFootprint->SetReference( defaultRef );
1385
1386 clipFootprint->SetParent( board() );
1387 clipFootprint->ResolveComponentClassNames( board(), clipFootprint->GetTransientComponentClassNames() );
1388 clipFootprint->ClearTransientComponentClassNames();
1389 pastedItems.push_back( clipFootprint );
1390 }
1391
1392 pruneItemLayers( pastedItems );
1393
1394 cancelled = !placeBoardItems( &commit, pastedItems, true, true, mode == PASTE_MODE::UNIQUE_ANNOTATIONS, false );
1395
1396 if( !cancelled )
1397 recordPastedItems( m_toolMgr, pastedItems );
1398
1399 break;
1400 }
1401
1402 default:
1403 m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) );
1404 break;
1405 }
1406
1407 if( cancelled )
1408 commit.Revert();
1409 else
1410 commit.Push( _( "Paste" ) );
1411
1412 return 1;
1413}
1414
1415
1417{
1418 wxString fileName;
1419
1420 PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
1421
1422 if( !editFrame )
1423 return 1;
1424
1425 // Pick a file to append
1426 if( !AskLoadBoardFileName( editFrame, &fileName, KICTL_KICAD_ONLY ) )
1427 return 1;
1428
1430 IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::FindPlugin( pluginType ) );
1431
1432 if( !pi )
1433 return 1;
1434
1435 return AppendBoard( *pi, fileName );
1436}
1437
1438
1440{
1441 PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
1442
1443 if( !editFrame )
1444 return 1;
1445
1446 if( !editFrame->GetDesignBlockPane()->GetSelectedLibId().IsValid() )
1447 return 1;
1448
1449 DESIGN_BLOCK_PANE* designBlockPane = editFrame->GetDesignBlockPane();
1450 const LIB_ID selectedLibId = designBlockPane->GetSelectedLibId();
1451 std::unique_ptr<DESIGN_BLOCK> designBlock( designBlockPane->GetDesignBlock( selectedLibId, true, true ) );
1452
1453 if( !designBlock )
1454 return 1;
1455
1456 if( designBlock->GetBoardFile().IsEmpty() || !wxFileName::FileExists( designBlock->GetBoardFile() ) )
1457 {
1458 editFrame->ShowInfoBarError( _( "Design block has no layout to place." ), true );
1459 return 1;
1460 }
1461
1463 IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::FindPlugin( pluginType ) );
1464
1465 if( !pi )
1466 return 1;
1467
1468 bool repeatPlacement = false;
1469
1470 if( APP_SETTINGS_BASE* cfg = editFrame->config() )
1471 repeatPlacement = cfg->m_DesignBlockChooserPanel.repeated_placement;
1472
1473 int ret = 0;
1474
1475 do
1476 {
1477 ret = AppendBoard( *pi, designBlock->GetBoardFile(), designBlock.get() );
1478 } while( repeatPlacement && ret == 0 );
1479
1480 return ret;
1481}
1482
1484{
1485 PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
1486
1487 if( !editFrame )
1488 return 1;
1489
1490 BOARD* brd = board();
1491
1492 if( !brd )
1493 return 1;
1494
1495 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
1497
1498 std::vector<PCB_GROUP*> linkedGroups;
1499 int skippedNoLink = 0;
1500
1501 for( EDA_ITEM* item : selection )
1502 {
1503 if( item->Type() != PCB_GROUP_T )
1504 continue;
1505
1506 PCB_GROUP* g = static_cast<PCB_GROUP*>( item );
1507
1508 if( g->HasDesignBlockLink() )
1509 linkedGroups.push_back( g );
1510 else
1511 skippedNoLink++;
1512 }
1513
1514 if( linkedGroups.empty() )
1515 {
1516 m_frame->ShowInfoBarError( _( "No groups with a linked design block are selected." ), true );
1517 return 1;
1518 }
1519
1520 if( !editFrame->GetOverrideLocks() )
1521 {
1522 bool hasLocked = false;
1523
1524 for( PCB_GROUP* g : linkedGroups )
1525 {
1526 hasLocked = g->IsLocked();
1527
1528 g->RunOnChildren(
1529 [&]( BOARD_ITEM* item )
1530 {
1531 if( item->IsLocked() )
1532 hasLocked = true;
1533 },
1535
1536 if( hasLocked )
1537 break;
1538 }
1539
1540 if( hasLocked )
1541 {
1542 m_frame->ShowInfoBarWarning( _( "Selection contains locked items. "
1543 "Enable 'Override locks' to operate on them." ),
1544 true );
1545 return 1;
1546 }
1547 }
1548
1550 BOARD_COMMIT sharedCommit( m_frame );
1551
1552 struct Failure
1553 {
1555 wxString reason;
1556 };
1557 std::vector<Failure> failures;
1558 int applied = 0;
1559 bool cancelled = false;
1560 bool netlessCopperPlaced = false;
1561
1562 std::unique_ptr<WX_PROGRESS_REPORTER> progress;
1563
1564 if( linkedGroups.size() > 1 && Pgm().IsGUI() )
1565 {
1566 progress = std::make_unique<WX_PROGRESS_REPORTER>( m_frame, _( "Applying Design Block Layouts" ),
1567 (int) linkedGroups.size(), PR_CAN_ABORT );
1568 }
1569
1570 auto generateBoundingBox = []( const std::unordered_set<EDA_ITEM*>& aItems )
1571 {
1572 std::vector<VECTOR2I> bbCorners;
1573 bbCorners.reserve( aItems.size() * 4 );
1574
1575 for( EDA_ITEM* item : aItems )
1576 {
1577 const BOX2I bb = item->GetBoundingBox().GetInflated( 100000 );
1578 KIGEOM::CollectBoxCorners( bb, bbCorners );
1579 }
1580
1581 std::vector<VECTOR2I> hullVertices;
1582 BuildConvexHull( hullVertices, bbCorners );
1583
1584 SHAPE_LINE_CHAIN hull( hullVertices );
1585 return KIGEOM::RectifyPolygon( hull );
1586 };
1587
1588 // Apply the linked design block's layout to a single group. Returns with a
1589 // human-readable reason on failure.
1590 auto applyOneGroup = [&]( PCB_GROUP* group, wxString& outErr ) -> bool
1591 {
1592 DESIGN_BLOCK_PANE* pane = editFrame->GetDesignBlockPane();
1593 std::unique_ptr<DESIGN_BLOCK> designBlock(
1594 pane->GetDesignBlock( group->GetDesignBlockLibId(), true, false, &outErr ) );
1595
1596 if( !designBlock )
1597 return false;
1598
1599 if( designBlock->GetBoardFile().IsEmpty() )
1600 {
1601 outErr = _( "the design block has no saved board layout" );
1602 return false;
1603 }
1604
1605 brd->Visit(
1606 []( EDA_ITEM* item, void* )
1607 {
1608 item->SetFlags( MCT_SKIP_STRUCT );
1610 },
1612
1613 auto clearFlags = [&]()
1614 {
1615 brd->Visit(
1616 []( EDA_ITEM* item, void* )
1617 {
1618 item->ClearFlags( MCT_SKIP_STRUCT );
1620 },
1622 };
1623
1624 BOARD_COMMIT tempCommit( m_frame );
1625
1627 IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::FindPlugin( pluginType ) );
1628
1629 if( !pi || AppendBoard( *pi, designBlock->GetBoardFile(), designBlock.get(), &tempCommit, true ) != 0 )
1630 {
1631 clearFlags();
1632 outErr = _( "the design block's board file could not be read" );
1633 return false;
1634 }
1635
1636 RULE_AREA dbRA;
1638 dbRA.m_generateEnabled = true;
1639
1640 brd->Visit(
1641 [&]( EDA_ITEM* item, void* )
1642 {
1643 if( !item->HasFlag( MCT_SKIP_STRUCT ) )
1644 {
1645 dbRA.m_designBlockItems.insert( item );
1646
1647 if( item->Type() == PCB_FOOTPRINT_T )
1648 dbRA.m_components.insert( static_cast<FOOTPRINT*>( item ) );
1649 }
1650
1652 },
1654
1655 if( dbRA.m_designBlockItems.empty() )
1656 {
1657 tempCommit.Revert();
1658 clearFlags();
1659 outErr = _( "the design block's board layout is empty" );
1660 return false;
1661 }
1662
1663 // Footprint-free copper has no matched pads to map nets through, so it is copied as no-net.
1664 bool blockHasNetlessCopper = false;
1665
1666 if( dbRA.m_components.empty() )
1667 {
1668 for( EDA_ITEM* item : dbRA.m_designBlockItems )
1669 {
1670 if( BOARD_ITEM* bi = dynamic_cast<BOARD_ITEM*>( item ); bi && bi->IsConnected() )
1671 {
1672 blockHasNetlessCopper = true;
1673 break;
1674 }
1675 }
1676 }
1677
1678 dbRA.m_zone = new ZONE( brd );
1679 dbRA.m_zone->SetZoneName( group->GetDesignBlockLibId().GetUniStringLibId() );
1680 dbRA.m_zone->SetIsRuleArea( true );
1682 dbRA.m_zone->SetPlacementAreaEnabled( true );
1683 dbRA.m_zone->SetDoNotAllowZoneFills( false );
1684 dbRA.m_zone->SetDoNotAllowVias( false );
1685 dbRA.m_zone->SetDoNotAllowTracks( false );
1686 dbRA.m_zone->SetDoNotAllowPads( false );
1687 dbRA.m_zone->SetDoNotAllowFootprints( false );
1689 dbRA.m_zone->SetPlacementAreaSource( group->GetDesignBlockLibId().GetUniStringLibId() );
1691 dbRA.m_zone->AddPolygon( generateBoundingBox( dbRA.m_designBlockItems ) );
1692 dbRA.m_center = dbRA.m_zone->Outline()->COutline( 0 ).Centre();
1693
1694 RULE_AREA destRA;
1696
1697 for( EDA_ITEM* item : group->GetItems() )
1698 {
1699 if( item->Type() == PCB_FOOTPRINT_T )
1700 destRA.m_components.insert( static_cast<FOOTPRINT*>( item ) );
1701 }
1702
1703 destRA.m_group = group;
1704
1705 if( group->GetItems().empty() )
1706 {
1707 tempCommit.Revert();
1708 clearFlags();
1709 delete dbRA.m_zone;
1710 outErr = _( "the group has no items" );
1711 return false;
1712 }
1713
1714 destRA.m_zone = new ZONE( brd );
1715 destRA.m_zone->SetZoneName( group->GetName().IsEmpty() ? _( "(unnamed group)" ) : group->GetName() );
1716 destRA.m_zone->SetIsRuleArea( true );
1717 destRA.m_zone->SetLayerSet( LSET::AllCuMask() );
1718 destRA.m_zone->SetPlacementAreaEnabled( true );
1719 destRA.m_zone->SetDoNotAllowZoneFills( false );
1720 destRA.m_zone->SetDoNotAllowVias( false );
1721 destRA.m_zone->SetDoNotAllowTracks( false );
1722 destRA.m_zone->SetDoNotAllowPads( false );
1723 destRA.m_zone->SetDoNotAllowFootprints( false );
1725 destRA.m_zone->SetPlacementAreaSource( group->GetName() );
1727 destRA.m_zone->AddPolygon( generateBoundingBox( group->GetItems() ) );
1728 destRA.m_center = destRA.m_zone->Outline()->COutline( 0 ).Centre();
1729
1730 REPEAT_LAYOUT_OPTIONS options = { .m_copyRouting = true,
1731 .m_connectedRoutingOnly = false,
1732 .m_copyPlacement = true,
1733 .m_copyOtherItems = true,
1734 .m_groupItems = false,
1735 .m_includeLockedItems = true };
1736
1737 // Give the appended block's auto-generated nets a private namespace so they cannot fuse by
1738 // name with a different part's net on the board, which would corrupt the topology match
1739 // (issue 24767). Record the private nets with the temporary block so rollback removes them.
1740 std::vector<NETINFO_ITEM*> isolatedNets =
1742
1743 for( NETINFO_ITEM* net : isolatedNets )
1744 tempCommit.Added( net );
1745
1746 wxString repeatErr;
1747 int result = mct->RepeatLayout( aEvent, dbRA, destRA, options, &sharedCommit, &repeatErr );
1748
1749 tempCommit.Revert();
1750
1751 clearFlags();
1752 delete dbRA.m_zone;
1753 delete destRA.m_zone;
1754
1755 if( result != 0 )
1756 {
1757 outErr = repeatErr.IsEmpty() ? _( "the layout could not be copied onto the group" ) : repeatErr;
1758 return false;
1759 }
1760
1761 if( blockHasNetlessCopper )
1762 netlessCopperPlaced = true;
1763
1764 return true;
1765 };
1766
1767 for( size_t i = 0; i < linkedGroups.size(); ++i )
1768 {
1769 PCB_GROUP* g = linkedGroups[i];
1770
1771 if( progress )
1772 {
1773 progress->SetCurrentProgress( static_cast<double>( i ) / linkedGroups.size() );
1774 progress->Report(
1775 wxString::Format( _( "Applying layout to group %zu of %zu..." ), i + 1, linkedGroups.size() ) );
1776
1777 if( !progress->KeepRefreshing() )
1778 {
1779 cancelled = true;
1780 break;
1781 }
1782 }
1783
1784 wxString err;
1785
1786 if( applyOneGroup( g, err ) )
1787 applied++;
1788 else
1789 failures.push_back( { g, err } );
1790 }
1791
1792 if( progress )
1793 progress->SetCurrentProgress( 1.0 );
1794
1795 if( cancelled )
1796 {
1797 sharedCommit.Revert();
1798 m_frame->ShowInfoBarMsg( _( "Apply design block layout cancelled." ), true );
1799 return 1;
1800 }
1801
1802 if( applied > 0 )
1803 {
1804 sharedCommit.Push( _( "Apply Design Block Layout" ) );
1805
1806 if( netlessCopperPlaced )
1807 m_frame->ShowInfoBarMsg( _( "Copied copper has no net assigned. Assign nets to connect it." ), true );
1808 }
1809 else
1810 {
1811 sharedCommit.Revert();
1812 }
1813
1814 if( skippedNoLink > 0 || !failures.empty() || linkedGroups.size() > 1 )
1815 {
1816 wxString html;
1817
1818 html << wxT( "<p>" )
1819 << wxString::Format( _( "Applied design block layout to %d of %d group(s)." ), applied,
1820 (int) linkedGroups.size() )
1821 << wxT( "</p>" );
1822
1823 if( skippedNoLink > 0 )
1824 {
1825 html << wxT( "<p>" )
1826 << wxString::Format( _( "Skipped %d selected item(s) that are not groups linked to a "
1827 "design block." ),
1828 skippedNoLink )
1829 << wxT( "</p>" );
1830 }
1831
1832 if( !failures.empty() )
1833 {
1834 html << wxT( "<p>" ) << _( "The following groups could not be processed:" ) << wxT( "</p><ul>" );
1835
1836 for( const Failure& f : failures )
1837 {
1838 wxString name = f.group->GetName().IsEmpty() ? _( "(unnamed group)" ) : f.group->GetName();
1839 wxString reason = f.reason;
1840
1841 reason.Replace( wxT( "\n" ), wxT( "<br>" ) );
1842 html << wxString::Format( wxT( "<li><b>%s</b>: %s</li>" ), name, reason );
1843 }
1844
1845 html << wxT( "</ul>" );
1846 }
1847
1848 HTML_MESSAGE_BOX dlg( m_frame, _( "Apply Design Block Layout" ) );
1849 dlg.SetDialogSizeInDU( 360, 220 );
1850 dlg.AddHTML_Text( html );
1851 dlg.ShowModal();
1852 }
1853
1854 return applied > 0 ? 0 : 1;
1855}
1856
1858{
1859 PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
1860
1861 if( !editFrame )
1862 return 1;
1863
1864 // Need to have a group selected and it needs to have a linked design block
1865 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
1867
1868 if( selection.Size() != 1 || selection[0]->Type() != PCB_GROUP_T )
1869 return 1;
1870
1871 PCB_GROUP* group = static_cast<PCB_GROUP*>( selection[0] );
1872
1873 if( !group->HasDesignBlockLink() )
1874 return 1;
1875
1876 // Get the associated design block
1877 DESIGN_BLOCK_PANE* designBlockPane = editFrame->GetDesignBlockPane();
1878 std::unique_ptr<DESIGN_BLOCK> designBlock( designBlockPane->GetDesignBlock( group->GetDesignBlockLibId(),
1879 true, true ) );
1880
1881 if( !designBlock )
1882 return 1;
1883
1884 if( designBlock->GetBoardFile().IsEmpty() )
1885 {
1886 wxString msg;
1887 msg.Printf( _( "Design block %s does not have a board file." ),
1888 group->GetDesignBlockLibId().GetUniStringLibId() );
1889 m_frame->GetInfoBar()->ShowMessageFor( msg, 5000, wxICON_WARNING );
1890 return 1;
1891 }
1892
1893
1895 IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::FindPlugin( pluginType ) );
1896
1897 if( !pi )
1898 return 1;
1899
1900 if( aEvent.Parameter<bool*>() != nullptr )
1901 return AppendBoard( *pi, designBlock->GetBoardFile(), designBlock.get(),
1902 static_cast<BOARD_COMMIT*>( aEvent.Commit() ), *aEvent.Parameter<bool*>() );
1903 else
1904 return AppendBoard( *pi, designBlock->GetBoardFile(), designBlock.get() );
1905}
1906
1907
1909{
1910 PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
1911
1912 if( !editFrame )
1913 return 1;
1914
1915 // Need to have a group selected and it needs to have a linked design block
1916 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
1918
1919 if( selection.Size() != 1 || selection[0]->Type() != PCB_GROUP_T )
1920 return 1;
1921
1922 PCB_GROUP* group = static_cast<PCB_GROUP*>( selection[0] );
1923
1924 if( !group->HasDesignBlockLink() )
1925 return 1;
1926
1927 // Get the associated design block
1928 DESIGN_BLOCK_PANE* designBlockPane = editFrame->GetDesignBlockPane();
1929 std::unique_ptr<DESIGN_BLOCK> designBlock( designBlockPane->GetDesignBlock( group->GetDesignBlockLibId(),
1930 true, true ) );
1931
1932 if( !designBlock )
1933 return 1;
1934
1935 editFrame->GetDesignBlockPane()->SelectLibId( group->GetDesignBlockLibId() );
1936
1937 return m_toolMgr->RunAction( PCB_ACTIONS::updateDesignBlockFromSelection ) ? 1 : 0;
1938}
1939
1940
1941bool PCB_CONTROL::placeBoardItems( BOARD_COMMIT* aCommit, BOARD* aBoard, bool aAnchorAtOrigin,
1942 bool aReannotateDuplicates, bool aSkipMove )
1943{
1944 // items are new if the current board is not the board source
1945 bool isNew = board() != aBoard;
1946 std::vector<BOARD_ITEM*> items;
1947
1948 for( BOARD_ITEM* item : aBoard->GetItemSet() )
1949 {
1950 // Marker transfer is intentionally not part of append/paste item placement.
1951 if( item->Type() == PCB_MARKER_T )
1952 continue;
1953
1954 bool doCopy = ( item->GetFlags() & SKIP_STRUCT ) == 0;
1955
1956 item->ClearFlags( SKIP_STRUCT );
1957 item->SetFlags( isNew ? IS_NEW : 0 );
1958
1959 if( doCopy )
1960 items.push_back( item );
1961 }
1962
1963 if( isNew )
1964 aBoard->RemoveAll();
1965
1966 // Reparent before calling pruneItemLayers, as SetLayer can have a dependence on the
1967 // item's parent board being set correctly.
1968 if( isNew )
1969 {
1970 for( BOARD_ITEM* item : items )
1971 item->SetParent( board() );
1972 }
1973
1974 pruneItemLayers( items );
1975
1976 return placeBoardItems( aCommit, items, isNew, aAnchorAtOrigin, aReannotateDuplicates, aSkipMove );
1977}
1978
1979
1980bool PCB_CONTROL::placeBoardItems( BOARD_COMMIT* aCommit, std::vector<BOARD_ITEM*>& aItems, bool aIsNew,
1981 bool aAnchorAtOrigin, bool aReannotateDuplicates, bool aSkipMove )
1982{
1983 m_toolMgr->RunAction( ACTIONS::selectionClear );
1984
1985 PCB_SELECTION_TOOL* selectionTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
1986
1987 std::vector<BOARD_ITEM*> itemsToSel;
1988 itemsToSel.reserve( aItems.size() );
1989
1990 // Re-UUIDing pasted items breaks any item that references another by KIID (e.g. a constraint's
1991 // members); record old -> new so those references can be remapped once every item has its new id.
1992 // A grouped shape appears both as a top-level item and as a group child, so reset each item only
1993 // once -- a second reset would record a new->newer entry and corrupt the old->new mapping.
1994 std::map<KIID, KIID> idMap;
1995 std::set<BOARD_ITEM*> resetItems;
1996
1997 auto resetUuidOnce =
1998 [&]( BOARD_ITEM* aItem )
1999 {
2000 if( !resetItems.insert( aItem ).second )
2001 return;
2002
2003 KIID oldUuid = aItem->m_Uuid;
2004 aItem->ResetUuid();
2005 idMap[oldUuid] = aItem->m_Uuid;
2006 };
2007
2008 for( BOARD_ITEM* item : aItems )
2009 {
2010 if( aIsNew )
2011 {
2012 resetUuidOnce( item );
2013
2014 item->RunOnChildren(
2015 [&]( BOARD_ITEM* aChild )
2016 {
2017 resetUuidOnce( aChild );
2018 },
2020
2021 // While BOARD_COMMIT::Push() will add any new items to the entered group,
2022 // we need to do it earlier so that the previews while moving are correct.
2023 if( PCB_GROUP* enteredGroup = selectionTool->GetEnteredGroup() )
2024 {
2025 if( item->IsGroupableType() && !item->GetParentGroup() )
2026 {
2027 aCommit->Modify( enteredGroup, nullptr, RECURSE_MODE::NO_RECURSE );
2028 enteredGroup->AddItem( item );
2029 }
2030 }
2031
2032 item->SetParent( board() );
2033
2034 // A pasted zone must not reuse a name already on the board (issue 23131)
2035 if( item->Type() == PCB_ZONE_T )
2036 {
2037 ZONE* zone = static_cast<ZONE*>( item );
2038
2039 if( !zone->GetZoneName().IsEmpty() )
2040 zone->SetZoneName( board()->GetUniqueZoneName( zone->GetZoneName() ) );
2041 }
2042 }
2043
2044 // Update item attributes if needed
2045 if( BaseType( item->Type() ) == PCB_DIMENSION_T )
2046 {
2047 static_cast<PCB_DIMENSION_BASE*>( item )->UpdateUnits();
2048 }
2049 else if( item->Type() == PCB_FOOTPRINT_T )
2050 {
2051 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( item );
2052
2053 // Update the footprint path with the new KIID path if the footprint is new
2054 if( aIsNew )
2055 footprint->SetPath( KIID_PATH() );
2056
2057 for( BOARD_ITEM* dwg : footprint->GraphicalItems() )
2058 {
2059 if( BaseType( dwg->Type() ) == PCB_DIMENSION_T )
2060 static_cast<PCB_DIMENSION_BASE*>( dwg )->UpdateUnits();
2061 }
2062 }
2063
2064 // We only need to add the items that aren't inside a group currently selected
2065 // to the selection. If an item is inside a group and that group is selected,
2066 // then the selection tool will select it for us.
2067 if( !item->GetParentGroup() || !alg::contains( aItems, item->GetParentGroup()->AsEdaItem() ) )
2068 itemsToSel.push_back( item );
2069 }
2070
2071 // Now that every pasted item has its new UUID, remap KIID references (e.g. constraint members)
2072 // from the old ids to the new ones so they still resolve to the pasted copies.
2073 if( aIsNew && !idMap.empty() )
2074 {
2075 for( BOARD_ITEM* item : aItems )
2076 {
2077 item->RemapKIIDs( idMap );
2078 item->RunOnChildren( [&]( BOARD_ITEM* aChild )
2079 {
2080 aChild->RemapKIIDs( idMap );
2081 },
2083 }
2084 }
2085
2086 // Select the items that should be selected
2087 EDA_ITEMS toSel( itemsToSel.begin(), itemsToSel.end() );
2088 m_toolMgr->RunAction<EDA_ITEMS*>( ACTIONS::selectItems, &toSel );
2089
2090 // Reannotate duplicate footprints (make sense only in board editor )
2091 if( aReannotateDuplicates && m_isBoardEditor )
2092 m_toolMgr->GetTool<BOARD_REANNOTATE_TOOL>()->ReannotateDuplicatesInSelection();
2093
2094 for( BOARD_ITEM* item : aItems )
2095 {
2096 if( aIsNew )
2097 aCommit->Add( item );
2098 else
2099 aCommit->Added( item );
2100 }
2101
2102 PCB_SELECTION& selection = selectionTool->GetSelection();
2103
2104 if( selection.Size() > 0 )
2105 {
2106 if( aAnchorAtOrigin )
2107 {
2108 selection.SetReferencePoint( VECTOR2I( 0, 0 ) );
2109 }
2110 else if( BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( selection.GetTopLeftItem() ) )
2111 {
2112 selection.SetReferencePoint( item->GetPosition() );
2113 }
2114
2115 getViewControls()->SetCursorPosition( getViewControls()->GetMousePosition(), false );
2116
2117 m_toolMgr->ProcessEvent( EVENTS::SelectedEvent );
2118
2119 if( !aSkipMove )
2120 return m_toolMgr->RunSynchronousAction( PCB_ACTIONS::move, aCommit );
2121 }
2122
2123 // An empty selection cannot start interactive placement.
2124 return aSkipMove;
2125}
2126
2127
2128int PCB_CONTROL::AppendBoard( PCB_IO& pi, const wxString& fileName, DESIGN_BLOCK* aDesignBlock, BOARD_COMMIT* aCommit,
2129 bool aSkipMove )
2130{
2131 PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
2132
2133 if( !editFrame )
2134 return 1;
2135
2136 BOARD* brd = board();
2137
2138 if( !brd )
2139 return 1;
2140
2141 // Give ourselves a commit to work with if we weren't provided one
2142 std::unique_ptr<BOARD_COMMIT> tempCommit;
2143 BOARD_COMMIT* commit = aCommit;
2144
2145 if( !commit )
2146 {
2147 tempCommit = std::make_unique<BOARD_COMMIT>( editFrame );
2148 commit = tempCommit.get();
2149 }
2150
2151 // Mark existing items, in order to know what are the new items so we can select only
2152 // the new items after loading
2153 BOARD_ITEM_SET existingItems = brd->GetItemSet();
2154
2155 std::set<NETINFO_ITEM*> existingNets;
2156
2157 for( NETINFO_ITEM* net : brd->GetNetInfo() )
2158 existingNets.insert( net );
2159
2160 for( BOARD_ITEM* item : existingItems )
2161 item->SetFlags( SKIP_STRUCT );
2162
2163 auto clearSkipStructOnExistingItems =
2164 [&existingItems]()
2165 {
2166 for( BOARD_ITEM* item : existingItems )
2167 item->ClearFlags( SKIP_STRUCT );
2168 };
2169
2170 std::map<wxString, wxString> oldProperties = brd->GetProperties();
2171 std::map<wxString, wxString> newProperties;
2172
2173 PAGE_INFO oldPageInfo = brd->GetPageSettings();
2174 TITLE_BLOCK oldTitleBlock = brd->GetTitleBlock();
2175
2176 // Keep also the count of copper layers, to adjust if necessary
2177 int initialCopperLayerCount = brd->GetCopperLayerCount();
2178 LSET initialEnabledLayers = brd->GetEnabledLayers();
2179
2180 // Load the data
2181 try
2182 {
2183 std::map<std::string, UTF8> props;
2184
2185 // PCB_IO_EAGLE can use this info to center the BOARD, but it does not yet.
2186
2187 props["page_width"] = std::to_string( editFrame->GetPageSizeIU().x );
2188 props["page_height"] = std::to_string( editFrame->GetPageSizeIU().y );
2190
2192 [&]( wxString aTitle, int aIcon, wxString aMessage, wxString aAction ) -> bool
2193 {
2194 KIDIALOG dlg( editFrame, aMessage, aTitle, wxOK | wxCANCEL | aIcon );
2195
2196 if( !aAction.IsEmpty() )
2197 dlg.SetOKLabel( aAction );
2198
2199 dlg.DoNotShowCheckbox( aMessage, 0 );
2200
2201 return dlg.ShowModal() == wxID_OK;
2202 } );
2203
2204 // Let the user remap the appended board's layers onto this board when they do not match
2205 if( LAYER_MAPPABLE_PLUGIN* mappable = dynamic_cast<LAYER_MAPPABLE_PLUGIN*>( &pi ) )
2206 {
2207 mappable->RegisterCallback(
2208 [editFrame]( const std::vector<INPUT_LAYER_DESC>& aLayerDescs )
2209 {
2210 return DIALOG_MAP_LAYERS::RunModal( editFrame, aLayerDescs );
2211 } );
2212 }
2213
2214 WX_PROGRESS_REPORTER progressReporter( editFrame, _( "Load PCB" ), 1, PR_CAN_ABORT );
2215
2216 pi.SetProgressReporter( &progressReporter );
2217 pi.LoadAndAppendBoard( fileName, *brd, &props, nullptr );
2218 }
2219 catch( const IO_CANCELLED& )
2220 {
2221 clearSkipStructOnExistingItems();
2222
2223 return 1;
2224 }
2225 catch( const IO_ERROR& ioe )
2226 {
2227 DisplayErrorMessage( editFrame, _( "Error loading board." ), ioe.What() );
2228 clearSkipStructOnExistingItems();
2229
2230 return 1;
2231 }
2232
2233 newProperties = brd->GetProperties();
2234
2235 for( const std::pair<const wxString, wxString>& prop : oldProperties )
2236 newProperties[prop.first] = prop.second;
2237
2238 brd->SetProperties( newProperties );
2239
2240 brd->SetPageSettings( oldPageInfo );
2241 brd->SetTitleBlock( oldTitleBlock );
2242
2243 // rebuild nets and ratsnest before any use of nets
2244 brd->BuildListOfNets();
2245 brd->SynchronizeNetsAndNetClasses( true );
2246 brd->BuildConnectivity();
2247
2248 // GetItemSet omits net definitions. Record new nets before geometry so undo removes the
2249 // geometry first and redo restores its nets first.
2250 for( NETINFO_ITEM* net : brd->GetNetInfo() )
2251 {
2252 if( !existingNets.contains( net ) )
2253 commit->Added( net );
2254 }
2255
2256 // New appended items need to inherit the current global ratsnest state.
2257 // Existing items are marked SKIP_STRUCT and are handled elsewhere.
2258 const bool showGlobalRatsnest = displayOptions().m_ShowGlobalRatsnest;
2259
2260 for( BOARD_ITEM* item : brd->GetItemSet() )
2261 {
2262 if( item->GetFlags() & SKIP_STRUCT )
2263 continue;
2264
2265 if( BOARD_CONNECTED_ITEM* connectedItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
2266 connectedItem->SetLocalRatsnestVisible( showGlobalRatsnest );
2267
2268 if( item->Type() == PCB_FOOTPRINT_T )
2269 {
2270 for( PAD* pad : static_cast<FOOTPRINT*>( item )->Pads() )
2271 pad->SetLocalRatsnestVisible( showGlobalRatsnest );
2272 }
2273 }
2274
2275 // Synchronize layers
2276 // we should not ask PLUGINs to do these items:
2277 int copperLayerCount = brd->GetCopperLayerCount();
2278
2279 if( copperLayerCount > initialCopperLayerCount )
2280 brd->SetCopperLayerCount( copperLayerCount );
2281
2282 // Enable all used layers, and make them visible:
2283 LSET enabledLayers = brd->GetEnabledLayers();
2284 enabledLayers |= initialEnabledLayers;
2285 brd->SetEnabledLayers( enabledLayers );
2286 brd->SetVisibleLayers( enabledLayers );
2288
2289 if( brd->GetCopperLayerCount() != initialCopperLayerCount )
2290 {
2291 WX_INFOBAR* infobar = editFrame->GetInfoBar();
2292 wxString msg = wxString::Format( _( "Board changed from %d to %d copper layers, stackup updated." ),
2293 initialCopperLayerCount,
2294 brd->GetCopperLayerCount() );
2295 infobar->ShowMessageFor( msg, 6000, wxICON_INFORMATION );
2296 }
2297
2298 int ret = 0;
2299
2300 bool placeAsGroup = false;
2301
2302 if( APP_SETTINGS_BASE* cfg = editFrame->config() )
2303 placeAsGroup = cfg->m_DesignBlockChooserPanel.place_as_group;
2304
2305 if( placeBoardItems( commit, brd, false, false /* Don't reannotate dupes on Append Board */, aSkipMove ) )
2306 {
2307 if( placeAsGroup )
2308 {
2309 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
2311
2312 // Count items that would be added to the group
2313 int groupableCount = 0;
2314
2315 for( EDA_ITEM* eda_item : selection )
2316 {
2317 if( eda_item->IsBOARD_ITEM()
2318 && !static_cast<BOARD_ITEM*>( eda_item )->GetParentFootprint() )
2319 {
2320 groupableCount++;
2321 }
2322 }
2323
2324 if( groupableCount >= 2 )
2325 {
2326 PCB_GROUP* group = new PCB_GROUP( brd );
2327
2328 if( aDesignBlock )
2329 {
2330 group->SetName( aDesignBlock->GetLibId().GetLibItemName() );
2331 group->SetDesignBlockLibId( aDesignBlock->GetLibId() );
2332 }
2333 else
2334 {
2335 group->SetName( wxFileName( fileName ).GetName() );
2336 }
2337
2338 for( EDA_ITEM* eda_item : selection )
2339 {
2340 if( eda_item->IsBOARD_ITEM() )
2341 {
2342 if( static_cast<BOARD_ITEM*>( eda_item )->IsLocked() )
2343 group->SetLocked( true );
2344 }
2345 }
2346
2347 commit->Add( group );
2348
2349 for( EDA_ITEM* eda_item : selection )
2350 {
2351 if( eda_item->IsBOARD_ITEM()
2352 && !static_cast<BOARD_ITEM*>( eda_item )->GetParentFootprint() )
2353 {
2354 commit->Modify( eda_item );
2355 group->AddItem( eda_item );
2356 }
2357 }
2358
2359 selTool->ClearSelection();
2360 selTool->select( group );
2361
2363 m_frame->OnModify();
2364 m_frame->Refresh();
2365 }
2366 }
2367
2368 // If we were provided a commit, let the caller control when to push it
2369 if( !aCommit )
2370 commit->Push( aDesignBlock ? _( "Place Design Block" ) : _( "Append Board" ) );
2371
2372 editFrame->GetBoard()->BuildConnectivity();
2373 ret = 0;
2374 }
2375 else
2376 {
2377 // If we were provided a commit, let the caller control when to revert it
2378 if( !aCommit )
2379 commit->Revert();
2380
2381 ret = 1;
2382 }
2383
2384 // Refresh the UI for the updated board properties
2385 editFrame->GetAppearancePanel()->OnBoardChanged();
2386 clearSkipStructOnExistingItems();
2387
2388 return ret;
2389}
2390
2391
2392int PCB_CONTROL::Undo( const TOOL_EVENT& aEvent )
2393{
2394 PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
2395 wxCommandEvent dummy;
2396
2397 if( editFrame )
2398 editFrame->RestoreCopyFromUndoList( dummy );
2399
2400 return 0;
2401}
2402
2403
2404int PCB_CONTROL::Redo( const TOOL_EVENT& aEvent )
2405{
2406 PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
2407 wxCommandEvent dummy;
2408
2409 if( editFrame )
2410 editFrame->RestoreCopyFromRedoList( dummy );
2411
2412 return 0;
2413}
2414
2415
2417{
2418 MAGNETIC_SETTINGS& settings = m_isFootprintEditor ? m_frame->GetFootprintEditorSettings()->m_MagneticItems
2419 : m_frame->GetPcbNewSettings()->m_MagneticItems;
2420 bool& snapMode = settings.allLayers;
2421
2423 snapMode = false;
2424 else if( aEvent.IsAction( &PCB_ACTIONS::magneticSnapAllLayers ) )
2425 snapMode = true;
2426 else
2427 snapMode = !snapMode;
2428
2430
2431 return 0;
2432}
2433
2434
2436{
2437 if( !Pgm().GetCommonSettings()->m_Input.hotkey_feedback )
2438 return 0;
2439
2440 wxArrayString labels;
2441 labels.Add( _( "Active Layer" ) );
2442 labels.Add( _( "All Layers" ) );
2443
2444 if( !m_frame->GetHotkeyPopup() )
2445 m_frame->CreateHotkeyPopup();
2446
2447 HOTKEY_CYCLE_POPUP* popup = m_frame->GetHotkeyPopup();
2448
2449 MAGNETIC_SETTINGS& settings = m_isFootprintEditor ? m_frame->GetFootprintEditorSettings()->m_MagneticItems
2450 : m_frame->GetPcbNewSettings()->m_MagneticItems;
2451
2452 if( popup )
2453 popup->Popup( _( "Object Snapping" ), labels, static_cast<int>( settings.allLayers ) );
2454
2455 return 0;
2456}
2457
2458
2460{
2461 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
2462 ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
2463 PCB_SELECTION& selection = selTool->GetSelection();
2464 PCB_EDIT_FRAME* pcbFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
2465 std::shared_ptr<DRC_ENGINE> drcEngine = m_frame->GetBoard()->GetDesignSettings().m_DRCEngine;
2466 DRC_CONSTRAINT constraint;
2467
2468 std::vector<MSG_PANEL_ITEM> msgItems;
2469
2470 if( routerTool && routerTool->RoutingInProgress() )
2471 {
2472 routerTool->UpdateMessagePanel();
2473 return 0;
2474 }
2475
2476 if( !pcbFrame && !m_frame->GetModel() )
2477 return 0;
2478
2479 if( selection.Empty() )
2480 {
2481 if( !pcbFrame )
2482 {
2483 FOOTPRINT* fp = static_cast<FOOTPRINT*>( m_frame->GetModel() );
2484 fp->GetMsgPanelInfo( m_frame, msgItems );
2485 }
2486 else
2487 {
2488 m_frame->SetMsgPanel( m_frame->GetBoard() );
2489 }
2490 }
2491 else if( selection.GetSize() == 1 )
2492 {
2493 EDA_ITEM* item = selection.Front();
2494
2495 if( std::optional<wxString> uuid = GetMsgPanelDisplayUuid( item->m_Uuid ) )
2496 msgItems.emplace_back( _( "UUID" ), *uuid );
2497
2498 item->GetMsgPanelInfo( m_frame, msgItems );
2499
2500 PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item );
2501 NETINFO_ITEM* net = track ? track->GetNet() : nullptr;
2502 NETINFO_ITEM* coupledNet = net ? m_frame->GetBoard()->DpCoupledNet( net ) : nullptr;
2503
2504 if( coupledNet )
2505 {
2506 SEG trackSeg( track->GetStart(), track->GetEnd() );
2507 PCB_TRACK* coupledItem = nullptr;
2508 SEG::ecoord closestDist_sq = VECTOR2I::ECOORD_MAX;
2509
2510 for( PCB_TRACK* candidate : m_frame->GetBoard()->Tracks() )
2511 {
2512 if( candidate->GetNet() != coupledNet )
2513 continue;
2514
2515 SEG::ecoord dist_sq = trackSeg.SquaredDistance( SEG( candidate->GetStart(), candidate->GetEnd() ) );
2516
2517 if( !coupledItem || dist_sq < closestDist_sq )
2518 {
2519 coupledItem = candidate;
2520 closestDist_sq = dist_sq;
2521 }
2522 }
2523
2524 constraint = drcEngine->EvalRules( DIFF_PAIR_GAP_CONSTRAINT, track, coupledItem, track->GetLayer() );
2525
2526 wxString msg = m_frame->MessageTextFromMinOptMax( constraint.Value() );
2527
2528 if( !msg.IsEmpty() )
2529 {
2530 msgItems.emplace_back( wxString::Format( _( "DP Gap Constraints: %s" ), msg ),
2531 wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
2532 }
2533
2534 constraint = drcEngine->EvalRules( MAX_UNCOUPLED_CONSTRAINT, track, coupledItem, track->GetLayer() );
2535
2536 if( constraint.Value().HasMax() )
2537 {
2538 msg = m_frame->MessageTextFromValue( constraint.Value().Max() );
2539 msgItems.emplace_back( wxString::Format( _( "DP Max Uncoupled-length: %s" ), msg ),
2540 wxString::Format( _( "(from %s)" ), constraint.GetName() ) );
2541 }
2542 }
2543 }
2544 else if( pcbFrame && selection.GetSize() == 2 )
2545 {
2546 // Pair selection broken into multiple, optional data, starting with the selected item
2547 // names
2548
2549 BOARD_ITEM* a = dynamic_cast<BOARD_ITEM*>( selection[0] );
2550 BOARD_ITEM* b = dynamic_cast<BOARD_ITEM*>( selection[1] );
2551
2552 if( a && b )
2553 {
2554 msgItems.emplace_back( MSG_PANEL_ITEM( a->GetItemDescription( m_frame, false ),
2555 b->GetItemDescription( m_frame, false ) ) );
2556 }
2557
2558 BOARD_CONNECTED_ITEM* a_conn = dynamic_cast<BOARD_CONNECTED_ITEM*>( a );
2559 BOARD_CONNECTED_ITEM* b_conn = dynamic_cast<BOARD_CONNECTED_ITEM*>( b );
2560
2561 if( a_conn && b_conn )
2562 {
2563 LSET overlap = a_conn->GetLayerSet() & b_conn->GetLayerSet() & LSET::AllCuMask();
2564 int a_netcode = a_conn->GetNetCode();
2565 int b_netcode = b_conn->GetNetCode();
2566
2567 if( overlap.count() > 0 )
2568 {
2569 PCB_LAYER_ID layer = overlap.CuStack().front();
2570
2571 if( a_netcode != b_netcode || a_netcode < 0 || b_netcode < 0 )
2572 {
2573 constraint = drcEngine->EvalRules( CLEARANCE_CONSTRAINT, a, b, layer );
2574 msgItems.emplace_back( _( "Resolved Clearance" ),
2575 m_frame->MessageTextFromValue( constraint.m_Value.Min() ) );
2576 }
2577
2578 std::shared_ptr<SHAPE> a_shape( a_conn->GetEffectiveShape( layer ) );
2579 std::shared_ptr<SHAPE> b_shape( b_conn->GetEffectiveShape( layer ) );
2580
2581 int actual_clearance = a_shape->GetClearance( b_shape.get() );
2582
2583 if( actual_clearance > -1 && actual_clearance < std::numeric_limits<int>::max() )
2584 {
2585 msgItems.emplace_back( _( "Actual Clearance" ),
2586 m_frame->MessageTextFromValue( actual_clearance ) );
2587 }
2588 }
2589 }
2590
2591 if( a && b && ( a->HasHole() || b->HasHole() ) )
2592 {
2593 PCB_LAYER_ID active = m_frame->GetActiveLayer();
2595
2596 if( b->IsOnLayer( active ) && IsCopperLayer( active ) )
2597 layer = active;
2598 else if( b->HasHole() && a->IsOnLayer( active ) && IsCopperLayer( active ) )
2599 layer = active;
2600 else if( a->HasHole() && b->IsOnCopperLayer() )
2601 layer = b->GetLayer();
2602 else if( b->HasHole() && a->IsOnCopperLayer() )
2603 layer = a->GetLayer();
2604
2605 if( IsCopperLayer( layer ) )
2606 {
2607 int actual = std::numeric_limits<int>::max();
2608
2609 if( a->HasHole() && b->IsOnCopperLayer() )
2610 {
2611 std::shared_ptr<SHAPE_SEGMENT> hole = a->GetEffectiveHoleShape();
2612 std::shared_ptr<SHAPE> other( b->GetEffectiveShape( layer ) );
2613
2614 actual = std::min( actual, hole->GetClearance( other.get() ) );
2615 }
2616
2617 if( b->HasHole() && a->IsOnCopperLayer() )
2618 {
2619 std::shared_ptr<SHAPE_SEGMENT> hole = b->GetEffectiveHoleShape();
2620 std::shared_ptr<SHAPE> other( a->GetEffectiveShape( layer ) );
2621
2622 actual = std::min( actual, hole->GetClearance( other.get() ) );
2623 }
2624
2625 if( actual < std::numeric_limits<int>::max() )
2626 {
2627 constraint = drcEngine->EvalRules( HOLE_CLEARANCE_CONSTRAINT, a, b, layer );
2628 msgItems.emplace_back( _( "Resolved Hole Clearance" ),
2629 m_frame->MessageTextFromValue( constraint.m_Value.Min() ) );
2630
2631 if( actual > -1 && actual < std::numeric_limits<int>::max() )
2632 {
2633 msgItems.emplace_back( _( "Actual Hole Clearance" ),
2634 m_frame->MessageTextFromValue( actual ) );
2635 }
2636 }
2637 }
2638 }
2639
2640 if( a && b )
2641 {
2642 for( PCB_LAYER_ID edgeLayer : { Edge_Cuts, Margin } )
2643 {
2644 PCB_LAYER_ID active = m_frame->GetActiveLayer();
2646
2647 if( a->IsOnLayer( edgeLayer ) && b->Type() != PCB_FOOTPRINT_T )
2648 {
2649 if( b->IsOnLayer( active ) && IsCopperLayer( active ) )
2650 layer = active;
2651 else if( IsCopperLayer( b->GetLayer() ) )
2652 layer = b->GetLayer();
2653 }
2654 else if( b->IsOnLayer( edgeLayer ) && a->Type() != PCB_FOOTPRINT_T )
2655 {
2656 if( a->IsOnLayer( active ) && IsCopperLayer( active ) )
2657 layer = active;
2658 else if( IsCopperLayer( a->GetLayer() ) )
2659 layer = a->GetLayer();
2660 }
2661
2662 if( layer >= 0 )
2663 {
2664 constraint = drcEngine->EvalRules( EDGE_CLEARANCE_CONSTRAINT, a, b, layer );
2665
2666 if( edgeLayer == Edge_Cuts )
2667 {
2668 msgItems.emplace_back( _( "Resolved Edge Clearance" ),
2669 m_frame->MessageTextFromValue( constraint.m_Value.Min() ) );
2670 }
2671 else
2672 {
2673 msgItems.emplace_back( _( "Resolved Margin Clearance" ),
2674 m_frame->MessageTextFromValue( constraint.m_Value.Min() ) );
2675 }
2676 }
2677 }
2678 }
2679 }
2680
2681 if( selection.GetSize() )
2682 {
2683 if( msgItems.empty() )
2684 {
2685 // Count items by type
2686 std::map<KICAD_T, int> typeCounts;
2687
2688 for( EDA_ITEM* item : selection )
2689 typeCounts[item->Type()]++;
2690
2691 // Check if all items are the same type
2692 bool allSameType = ( typeCounts.size() == 1 );
2693 KICAD_T commonType = allSameType ? typeCounts.begin()->first : NOT_USED;
2694
2695 if( allSameType )
2696 {
2697 // Show "Type: N" for homogeneous selections
2698 wxString typeName = selection.Front()->GetFriendlyName();
2699 msgItems.emplace_back( typeName, wxString::Format( wxT( "%d" ), selection.GetSize() ) );
2700
2701 // For pads, show common properties
2702 if( commonType == PCB_PAD_T )
2703 {
2704 std::set<wxString> layers;
2705 std::set<PAD_SHAPE> shapes;
2706 std::set<VECTOR2I> sizes;
2707
2708 for( EDA_ITEM* item : selection )
2709 {
2710 PAD* pad = static_cast<PAD*>( item );
2711
2712 layers.insert( pad->LayerMaskDescribe() );
2713
2714 pad->Padstack().ForEachUniqueLayer(
2715 [&]( PCB_LAYER_ID aLayer )
2716 {
2717 shapes.insert( pad->GetShape( aLayer ) );
2718 sizes.insert( pad->GetSize( aLayer ) );
2719 } );
2720 }
2721
2722 if( layers.size() == 1 )
2723 msgItems.emplace_back( _( "Layer" ), *layers.begin() );
2724
2725 if( shapes.size() == 1 )
2726 msgItems.emplace_back( _( "Pad Shape" ), PAD::ShowPadShape( *shapes.begin() ) );
2727
2728 if( sizes.size() == 1 )
2729 {
2730 msgItems.emplace_back( _( "Pad Size" ),
2731 wxString::Format( wxT( "%s x %s" ),
2732 m_frame->MessageTextFromValue( sizes.begin()->x ),
2733 m_frame->MessageTextFromValue( sizes.begin()->y ) ) );
2734 }
2735 }
2736 }
2737 else
2738 {
2739 // Show type breakdown for mixed selections
2740 wxString breakdown;
2741
2742 for( const auto& [type, count] : typeCounts )
2743 {
2744 if( !breakdown.IsEmpty() )
2745 breakdown += wxT( ", " );
2746
2747 // Get friendly name from first item of this type
2748 wxString typeName;
2749
2750 for( EDA_ITEM* item : selection )
2751 {
2752 if( item->Type() == type )
2753 {
2754 typeName = item->GetFriendlyName();
2755 break;
2756 }
2757 }
2758
2759 breakdown += wxString::Format( wxT( "%s: %d" ), typeName, count );
2760 }
2761
2762 msgItems.emplace_back( _( "Selected Items" ),
2763 wxString::Format( wxT( "%d (%s)" ), selection.GetSize(), breakdown ) );
2764 }
2765
2766 if( m_isBoardEditor )
2767 {
2768 std::set<wxString> netNames;
2769 std::set<wxString> netClasses;
2770
2771 for( EDA_ITEM* item : selection )
2772 {
2773 if( BOARD_CONNECTED_ITEM* bci = dynamic_cast<BOARD_CONNECTED_ITEM*>( item ) )
2774 {
2775 if( !bci->GetNet() || bci->GetNetCode() <= NETINFO_LIST::UNCONNECTED )
2776 continue;
2777
2778 netNames.insert( UnescapeString( bci->GetNetname() ) );
2779 netClasses.insert( UnescapeString( bci->GetEffectiveNetClass()->GetHumanReadableName() ) );
2780
2781 if( netNames.size() > 1 && netClasses.size() > 1 )
2782 break;
2783 }
2784 }
2785
2786 if( netNames.size() == 1 )
2787 msgItems.emplace_back( _( "Net" ), *netNames.begin() );
2788
2789 if( netClasses.size() == 1 )
2790 msgItems.emplace_back( _( "Resolved Netclass" ), *netClasses.begin() );
2791 }
2792 }
2793
2794 if( selection.GetSize() >= 2 )
2795 {
2796 bool lengthValid = true;
2797 double selectedLength = 0;
2798
2799 // Lambda to accumulate track length if item is a track or arc, otherwise mark invalid
2800 std::function<void( EDA_ITEM* )> accumulateTrackLength;
2801
2802 accumulateTrackLength =
2803 [&]( EDA_ITEM* aItem )
2804 {
2805 if( aItem->Type() == PCB_TRACE_T || aItem->Type() == PCB_ARC_T )
2806 {
2807 selectedLength += static_cast<PCB_TRACK*>( aItem )->GetLength();
2808 }
2809 else if( aItem->Type() == PCB_VIA_T )
2810 {
2811 // zero 2D length
2812 }
2813 else if( aItem->Type() == PCB_SHAPE_T )
2814 {
2815 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
2816
2817 if( shape->GetShape() == SHAPE_T::SEGMENT
2818 || shape->GetShape() == SHAPE_T::ARC
2819 || shape->GetShape() == SHAPE_T::BEZIER )
2820 {
2821 selectedLength += shape->GetLength();
2822 }
2823 else
2824 {
2825 lengthValid = false;
2826 }
2827 }
2828 // Use dynamic_cast to include PCB_GENERATORs.
2829 else if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( aItem ) )
2830 {
2831 group->RunOnChildren( accumulateTrackLength, RECURSE_MODE::RECURSE );
2832 }
2833 else
2834 {
2835 lengthValid = false;
2836 }
2837 };
2838
2839 for( EDA_ITEM* item : selection )
2840 {
2841 if( lengthValid )
2842 accumulateTrackLength( item );
2843 }
2844
2845 if( lengthValid )
2846 {
2847 msgItems.emplace_back( _( "Selected 2D Length" ),
2848 m_frame->MessageTextFromValue( selectedLength ) );
2849 }
2850 }
2851
2852 if( selection.GetSize() >= 2 && selection.GetSize() < 100 )
2853 {
2854 LSET enabledLayers = m_frame->GetBoard()->GetEnabledLayers();
2855 LSET enabledCopper = LSET::AllCuMask( m_frame->GetBoard()->GetCopperLayerCount() );
2856 bool areaValid = true;
2857 bool hasCopper = false;
2858 bool hasNonCopper = false;
2859
2860 std::map<PCB_LAYER_ID, SHAPE_POLY_SET> layerPolys;
2861 SHAPE_POLY_SET holes;
2862
2863 std::function<void( EDA_ITEM* )> accumulateArea;
2864
2865 accumulateArea =
2866 [&]( EDA_ITEM* aItem )
2867 {
2868 if( aItem->Type() == PCB_FOOTPRINT_T || aItem->Type() == PCB_MARKER_T )
2869 {
2870 areaValid = false;
2871 return;
2872 }
2873
2874 // An image has no physical area to contribute and no polygon
2875 // representation, so leave it out without invalidating the total.
2876 if( aItem->Type() == PCB_REFERENCE_IMAGE_T )
2877 return;
2878
2879 if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( aItem ) )
2880 {
2881 group->RunOnChildren( accumulateArea, RECURSE_MODE::RECURSE );
2882 return;
2883 }
2884
2885 if( BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem ) )
2886 {
2887 boardItem->RunOnChildren( accumulateArea, RECURSE_MODE::NO_RECURSE );
2888
2889 LSET itemLayers = boardItem->GetLayerSet() & enabledLayers;
2890
2891 for( PCB_LAYER_ID layer : itemLayers )
2892 {
2893 boardItem->TransformShapeToPolySet( layerPolys[layer], layer, 0,
2895
2896 if( enabledCopper.Contains( layer ) )
2897 hasCopper = true;
2898 else
2899 hasNonCopper = true;
2900 }
2901
2902 if( aItem->Type() == PCB_PAD_T && static_cast<PAD*>( aItem )->HasHole() )
2903 {
2904 static_cast<PAD*>( aItem )->TransformHoleToPolygon( holes, 0, ARC_LOW_DEF,
2905 ERROR_OUTSIDE );
2906 }
2907 else if( aItem->Type() == PCB_VIA_T )
2908 {
2909 PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
2910 VECTOR2I center = via->GetPosition();
2911 int R = via->GetDrillValue() / 2;
2912
2914 }
2915 }
2916 };
2917
2918 for( EDA_ITEM* item : selection )
2919 {
2920 if( areaValid )
2921 accumulateArea( item );
2922 }
2923
2924 if( areaValid )
2925 {
2926 double area = 0.0;
2927
2928 for( auto& [layer, layerPoly] : layerPolys )
2929 {
2930 // Only subtract holes from copper layers
2931 if( enabledCopper.Contains( layer ) )
2932 layerPoly.BooleanSubtract( holes );
2933
2934 area += layerPoly.Area();
2935 }
2936
2937 // Choose appropriate label based on what layers are involved
2938 wxString areaLabel;
2939
2940 if( hasCopper && !hasNonCopper )
2941 areaLabel = _( "Selected 2D Copper Area" );
2942 else if( !hasCopper && hasNonCopper )
2943 areaLabel = _( "Selected 2D Area" );
2944 else
2945 areaLabel = _( "Selected 2D Total Area" );
2946
2947 msgItems.emplace_back( areaLabel,
2948 m_frame->MessageTextFromValue( area, true, EDA_DATA_TYPE::AREA ) );
2949 }
2950 }
2951 }
2952 else
2953 {
2954 m_frame->GetBoard()->GetMsgPanelInfo( m_frame, msgItems );
2955 }
2956
2957 m_frame->SetMsgPanel( msgItems );
2958
2959 // Update vertex editor if it exists
2960 PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
2961 if( editFrame )
2962 {
2963 BOARD_ITEM* selectedItem = ( selection.GetSize() == 1 ) ? dynamic_cast<BOARD_ITEM*>( selection.Front() )
2964 : nullptr;
2965 editFrame->UpdateVertexEditorSelection( selectedItem );
2966 }
2967
2968 return 0;
2969}
2970
2971
2973{
2974 wxFileName fileName = wxFileName( *aEvent.Parameter<wxString*>() );
2975
2976 PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
2977
2978 if( !editFrame )
2979 return 1;
2980
2981 wxString filePath = fileName.GetFullPath();
2983 IO_RELEASER<PCB_IO> pi( PCB_IO_MGR::FindPlugin( pluginType ) );
2984
2985 if( !pi )
2986 return 1;
2987
2988 return AppendBoard( *pi, filePath );
2989}
2990
2991
2993{
2994 BOARD_COMMIT commit( this );
2995 EDA_UNITS displayUnit = m_frame->GetUserUnits();
2996 PCB_TABLE* table = Build_Board_Characteristics_Table( m_frame->GetBoard(), displayUnit );
2997 table->SetLayer( m_frame->GetActiveLayer() );
2998
2999 std::vector<BOARD_ITEM*> items;
3000 items.push_back( table );
3001
3002 // Revert rather than delete, since an entered group may already hold the table
3003 if( placeBoardItems( &commit, items, true, true, false, false ) )
3004 commit.Push( _( "Place Board Characteristics" ) );
3005 else
3006 commit.Revert();
3007
3008 return 0;
3009}
3010
3011
3013{
3014 auto table = std::make_unique<PCB_STACKUP_TABLE>( m_frame->GetBoard() );
3015
3016 // Seeded from the user's units once. After that the table keeps its own
3017 table->SetUnits( ToGeneratedTableUnits( m_frame->GetUserUnits() ) );
3018
3019 return placeGeneratedTable( std::move( table ),
3020 _( "No documentation layer is enabled to hold a stackup table." ),
3021 _( "Place Board Stackup Table" ) );
3022}
3023
3024
3026{
3027 return placeGeneratedTable( std::make_unique<PCB_DRILL_CHART>( m_frame->GetBoard() ),
3028 _( "No documentation layer is enabled to hold a drill chart." ),
3029 _( "Place Drill Chart" ) );
3030}
3031
3032
3033PCB_LAYER_ID PCB_CONTROL::pickDocumentationLayer( const std::function<bool( PCB_LAYER_ID )>& aAvailable,
3034 const wxString& aNoLayerMessage )
3035{
3036 BOARD* board = m_frame->GetBoard();
3037 PCB_LAYER_ID layer = m_frame->GetActiveLayer();
3038
3039 if( !aAvailable( layer ) )
3040 {
3042 const auto next = std::find_if( candidates.begin(), candidates.end(), aAvailable );
3043
3044 if( next == candidates.end() )
3045 {
3046 m_frame->ShowInfoBarError( aNoLayerMessage );
3047 return UNDEFINED_LAYER;
3048 }
3049
3050 layer = *next;
3051 m_frame->SetActiveLayer( layer );
3052 }
3053
3054 // Placing onto a hidden layer draws nothing at all, which is indistinguishable from the
3055 // feature being broken
3056 if( !board->IsLayerVisible( layer ) )
3057 {
3058 m_frame->ShowInfoBarWarning( wxString::Format(
3059 _( "Layer '%s' is hidden; nothing will be shown until you make it visible." ),
3060 board->GetLayerName( layer ) ) );
3061 }
3062
3063 return layer;
3064}
3065
3066
3067int PCB_CONTROL::placeGeneratedTable( std::unique_ptr<PCB_GENERATED_TABLE> aTable, const wxString& aNoLayerMessage,
3068 const wxString& aUndoMessage )
3069{
3070 // Generated tables report a board, and FOOTPRINT::Add would refuse one anyway. A user
3071 // hotkey can still reach this action from the footprint editor
3073 return 0;
3074
3075 BOARD* board = m_frame->GetBoard();
3076
3077 // Copper, silk, mask, paste, adhesive, Edge.Cuts, Margin and courtyard are manufacturing
3078 // inputs a table would corrupt. Unlike a map, a table may share a layer with another
3079 const auto available =
3080 [board]( PCB_LAYER_ID aLayer )
3081 {
3082 return DocumentationLayers().Contains( aLayer ) && board->IsLayerEnabled( aLayer );
3083 };
3084
3085 const PCB_LAYER_ID layer = pickDocumentationLayer( available, aNoLayerMessage );
3086
3087 if( layer == UNDEFINED_LAYER )
3088 return 0;
3089
3090 BOARD_COMMIT commit( this );
3092
3093 aTable->SetLayer( layer );
3094 aTable->RebuildCells( *board, &refresh );
3095
3096 // Cascade off any table of the same kind on this layer rather than landing on top of it
3097 int existing = 0;
3098
3099 for( BOARD_ITEM* item : board->Drawings() )
3100 {
3101 if( item->Type() == aTable->Type() && item->GetLayer() == layer )
3102 existing++;
3103 }
3104
3105 if( existing )
3106 {
3107 const BOX2I bbox = aTable->GetBoundingBox();
3108 aTable->Move( VECTOR2I( 0, existing * ( bbox.GetHeight() + pcbIUScale.mmToIU( 5 ) ) ) );
3109 }
3110
3111 std::vector<BOARD_ITEM*> items{ aTable.get() };
3112
3113 // The commit owns the table from here, even on cancel, since an entered group may already
3114 // hold it and only Revert undoes that before deleting it
3115 aTable.release();
3116
3117 if( !placeBoardItems( &commit, items, true, true, false, false ) )
3118 {
3119 commit.Revert();
3120 return 0;
3121 }
3122
3123 // Only now does the refresh's pending state become the board's. The drill profile is
3124 // design settings, which KiCad does not undo, so the board is marked dirty instead
3125 refresh.Commit();
3126 m_frame->OnModify();
3127
3128 commit.Push( aUndoMessage );
3129
3130 return 0;
3131}
3132
3133
3135{
3136 BOARD* board = m_frame->GetBoard();
3137
3138 // Two maps on one layer would overdraw each other's marks, so an occupied layer is no
3139 // more available than one that cannot hold a map at all
3140 const auto available =
3141 [&]( PCB_LAYER_ID aLayer )
3142 {
3143 if( !DocumentationLayers().Contains( aLayer ) || !board->IsLayerEnabled( aLayer ) )
3144 return false;
3145
3146 for( const BOARD_ITEM* item : board->Drawings() )
3147 {
3148 if( item->Type() == PCB_DRILL_MAP_T && item->GetLayer() == aLayer )
3149 return false;
3150 }
3151
3152 return true;
3153 };
3154
3155 const PCB_LAYER_ID layer =
3156 pickDocumentationLayer( available, _( "Every documentation layer already has a drill map." ) );
3157
3158 if( layer == UNDEFINED_LAYER )
3159 return 0;
3160
3161 BOARD_COMMIT commit( this );
3162
3163 // A map draws on the holes, so there is nothing to drag into place. It lands at zero
3164 // offset and the user moves it from there
3165 PCB_DRILL_MAP* map = new PCB_DRILL_MAP( board );
3166 map->SetLayer( layer );
3167
3168 commit.Add( map );
3169 commit.Push( _( "Place Drill Map" ) );
3170
3171 m_toolMgr->RunAction( ACTIONS::selectionClear );
3172 m_toolMgr->RunAction<EDA_ITEM*>( PCB_ACTIONS::selectItem, map );
3173
3174 return 0;
3175}
3176
3177
3179{
3180
3181 PCB_EDIT_FRAME* frame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
3182
3183 if( !frame )
3184 return 0;
3185
3187 {
3188 m_drillGroupsDialog->Raise();
3189 return 0;
3190 }
3191
3193 m_drillGroupsDialog = dialog;
3194 dialog->Show( true );
3195
3196 return 0;
3197}
3198
3199
3201{
3202 PCB_DISPLAY_OPTIONS opts = m_frame->GetDisplayOptions();
3203 opts.m_FlipBoardView = !opts.m_FlipBoardView;
3204 m_frame->SetDisplayOptions( opts );
3205
3206 return 0;
3207}
3208
3209
3211{
3212 if( aItem->Type() != PCB_SHAPE_T )
3213 return;
3214
3215 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( aItem );
3216
3217 // Re-caching every non-hatched shape on each edit stalls commits on dense boards.
3218 if( !shape->IsHatchedFill() )
3219 return;
3220
3221 shape->UpdateHatching();
3222
3223 if( aView )
3224 aView->Update( aItem );
3225}
3226
3227
3229{
3230 KIGFX::VIEW* view = this->view();
3231
3232 for( FOOTPRINT* footprint : board()->Footprints() )
3233 footprint->RunOnChildren( std::bind( &PCB_CONTROL::rehatchBoardItem, view, _1 ), NO_RECURSE );
3234
3235 for( BOARD_ITEM* item : board()->Drawings() )
3236 rehatchBoardItem( view, item );
3237
3238 return 0;
3239}
3240
3241
3243{
3244 BOARD* brd = board();
3245
3246 if( !brd )
3247 return 0;
3248
3249 PROJECT& prj = m_frame->Prj();
3251 FILENAME_RESOLVER* resolver = cache ? cache->GetResolver() : nullptr;
3252
3253 wxString workingPath = prj.GetProjectPath();
3254 std::vector<const EMBEDDED_FILES*> stack;
3255 stack.push_back( brd->GetEmbeddedFiles() );
3256
3257 BOARD_COMMIT commit( m_frame );
3258 int embeddedCount = 0;
3259
3260 for( FOOTPRINT* fp : brd->Footprints() )
3261 {
3262 bool fpModified = false;
3263
3264 for( FP_3DMODEL& model : fp->Models() )
3265 {
3266 if( model.m_Filename.StartsWith( FILEEXT::KiCadUriPrefix ) )
3267 continue;
3268
3269 wxString fullPath =
3270 resolver ? resolver->ResolvePath( model.m_Filename, workingPath, stack )
3271 : model.m_Filename;
3272
3273 wxFileName fname( fullPath );
3274 wxString ext = fname.GetExt().Upper();
3275
3276 if( fname.Exists() )
3277 {
3279 brd->GetEmbeddedFiles()->AddFile( fname, false ) )
3280 {
3281 model.m_Filename = file->GetLink();
3282 fpModified = true;
3283 embeddedCount++;
3284
3285 // Store STEP along with WRL for the OCCT(STEP) exporter.
3286 if( ext == "WRL" || ext == "WRZ" )
3287 {
3288 wxArrayString alts;
3289
3290 // Step files
3291 alts.Add( wxT( "stp" ) );
3292 alts.Add( wxT( "step" ) );
3293 alts.Add( wxT( "STP" ) );
3294 alts.Add( wxT( "STEP" ) );
3295 alts.Add( wxT( "Stp" ) );
3296 alts.Add( wxT( "Step" ) );
3297 alts.Add( wxT( "stpz" ) );
3298 alts.Add( wxT( "stpZ" ) );
3299 alts.Add( wxT( "STPZ" ) );
3300
3301 for( const auto& alt : alts )
3302 {
3303 wxFileName altFile( fname.GetPath(),
3304 fname.GetName() + wxT( "." ) + alt );
3305
3306 if( altFile.IsOk() && altFile.FileExists() )
3307 {
3308 brd->GetEmbeddedFiles()->AddFile( altFile, false );
3309 break;
3310 }
3311 }
3312 }
3313 }
3314 }
3315 }
3316
3317 if( fpModified )
3318 commit.Modify( fp );
3319 }
3320
3321 if( embeddedCount > 0 )
3322 {
3323 commit.Push( _( "Embed 3D Models" ) );
3324 wxString msg = wxString::Format( _( "%d 3D model(s) successfully embedded." ), embeddedCount );
3325 m_frame->GetInfoBar()->ShowMessageFor( msg, 5000 );
3326 }
3327
3328 return 0;
3329}
3330
3331
3332// clang-format off
3334{
3337 Go( &PCB_CONTROL::Print, ACTIONS::print.MakeEvent() );
3338
3339 // Footprint library actions
3344
3345 // Display modes
3362
3363 // Layer control
3401
3404
3405 // Grid control
3408
3409 Go( &PCB_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
3410 Go( &PCB_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
3411
3412 // Snapping control
3417
3418 // Miscellaneous
3421
3422 // Append control
3434
3435 Go( &PCB_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
3437
3444
3445 // Add library by dropping file
3448}
3449// clang-format on
const char * name
@ ERROR_OUTSIDE
@ ERROR_INSIDE
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
constexpr int ARC_LOW_DEF
Definition base_units.h:143
std::set< BOARD_ITEM *, CompareByUuid > BOARD_ITEM_SET
Set of BOARD_ITEMs ordered by UUID.
Definition board.h:395
PCB_TABLE * Build_Board_Characteristics_Table(BOARD *aBoard, EDA_UNITS aDisplayUnits)
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
@ HIDDEN
Inactive layers are hidden.
@ DIMMED
Inactive layers are dimmed (old high-contrast mode)
@ RATSNEST
Net/netclass colors are shown on ratsnest lines only.
@ ALL
Net/netclass colors are shown on all net copper.
@ OFF
Net (and netclass) colors are not shown.
@ VISIBLE
Ratsnest lines are drawn to items on visible layers only.
@ ALL
Ratsnest lines are drawn to items on all layers (default)
BOX2< VECTOR2I > BOX2I
Definition box2.h:917
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:985
static TOOL_ACTION paste
Definition actions.h:77
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition actions.h:224
static TOOL_ACTION addLibrary
Definition actions.h:52
static TOOL_ACTION pickerTool
Definition actions.h:250
static TOOL_ACTION gridResetOrigin
Definition actions.h:193
static TOOL_ACTION pasteSpecial
Definition actions.h:78
static TOOL_ACTION highContrastModeCycle
Definition actions.h:153
static TOOL_ACTION undo
Definition actions.h:72
static TOOL_ACTION highContrastMode
Definition actions.h:152
static TOOL_ACTION redo
Definition actions.h:73
static TOOL_ACTION deleteTool
Definition actions.h:83
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
static TOOL_ACTION print
Definition actions.h:61
static TOOL_ACTION newLibrary
Definition actions.h:51
static TOOL_ACTION gridSetOrigin
Definition actions.h:192
static TOOL_ACTION ddAddLibrary
Definition actions.h:64
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition actions.h:229
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void OnBoardChanged()
Update the panel contents from the application and board models.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
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,...
PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
NETINFO_ITEM * GetNet() const
Return NETINFO_ITEM object for a given item.
void SetGridOrigin(const VECTOR2I &aOrigin)
BOARD_STACKUP & GetStackupDescriptor()
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
virtual bool IsConnected() const
Returns information if the object is derived from BOARD_CONNECTED_ITEM.
Definition board_item.h:187
virtual std::shared_ptr< SHAPE_SEGMENT > GetEffectiveHoleShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
bool IsLocked() const override
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
virtual bool IsOnLayer(PCB_LAYER_ID aLayer) const
Test to see if this object is on the given layer.
Definition board_item.h:432
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition board_item.h:397
FOOTPRINT * GetParentFootprint() const
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition board_item.h:369
virtual bool IsOnCopperLayer() const
Definition board_item.h:204
virtual std::shared_ptr< SHAPE > GetEffectiveShape(PCB_LAYER_ID aLayer=UNDEFINED_LAYER, FLASHING aFlash=FLASHING::DEFAULT, DRC_CONSTRAINT_T aUsage=NULL_CONSTRAINT) const
Some pad shapes can be complex (rounded/chamfered rectangle), even without considering custom shapes.
virtual bool HasHole() const
Definition board_item.h:222
virtual void RemapKIIDs(const std::map< KIID, KIID > &aIdMap)
Remap KIIDs this item stores to reference other items (e.g.
Definition board_item.h:302
bool SynchronizeWithBoard(const BOARD_DESIGN_SETTINGS *aSettings)
Synchronize the BOARD_STACKUP_ITEM* list with the board.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
INSPECT_RESULT Visit(INSPECTOR inspector, void *testData, const std::vector< KICAD_T > &scanTypes) override
May be re-implemented for each derived class in order to handle all the types given by its member dat...
Definition board.cpp:2680
const NETINFO_LIST & GetNetInfo() const
Definition board.h:1241
EMBEDDED_FILES * GetEmbeddedFiles() override
Definition board.cpp:3709
void SetVisibleLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition board.cpp:1235
void MapNets(BOARD *aDestBoard)
Map all nets in the given board to nets with the same name (if any) in the destination board.
Definition board.cpp:3820
void BuildListOfNets()
Definition board.h:1189
const std::vector< BOARD_CONNECTED_ITEM * > AllConnectedItems()
Definition board.cpp:3785
const PAGE_INFO & GetPageSettings() const
Definition board.h:1029
void SetProperties(const std::map< wxString, wxString > &aProps)
Definition board.h:527
const GROUPS & Groups() const
The groups must maintain the following invariants.
Definition board.h:518
bool BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition board.cpp:369
void SynchronizeNetsAndNetClasses(bool aResetTrackAndViaSizes)
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition board.cpp:3268
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:713
TITLE_BLOCK & GetTitleBlock()
Definition board.h:1035
int GetCopperLayerCount() const
Definition board.cpp:1155
const std::map< wxString, wxString > & GetProperties() const
Definition board.h:526
const FOOTPRINTS & Footprints() const
Definition board.h:465
void RemoveAll(std::initializer_list< KICAD_T > aTypes={ PCB_NETINFO_T, PCB_MARKER_T, PCB_GROUP_T, PCB_ZONE_T, PCB_GENERATOR_T, PCB_FOOTPRINT_T, PCB_TRACE_T, PCB_SHAPE_T })
An efficient way to remove all items of a certain type from the board.
Definition board.cpp:1838
const BOARD_ITEM_SET GetItemSet()
Collect every owned item (tracks, zones, generators, footprints, drawings, markers,...
Definition board.cpp:4262
void SetPageSettings(const PAGE_INFO &aPageSettings)
Definition board.h:1030
const CONSTRAINTS & Constraints() const
Geometric constraints (#2329) owned by this board.
Definition board.h:522
void SetCopperLayerCount(int aCount)
Definition board.cpp:1161
bool IsLayerVisible(PCB_LAYER_ID aLayer) const
A proxy function that calls the correspondent function in m_BoardSettings tests whether a given layer...
Definition board.cpp:1208
const LSET & GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition board.cpp:1202
void SetEnabledLayers(const LSET &aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition board.cpp:1222
void SetTitleBlock(const TITLE_BLOCK &aTitleBlock)
Definition board.h:1037
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
const DRAWINGS & Drawings() const
Definition board.h:467
constexpr size_type GetHeight() const
Definition box2.h:218
BOARD_ITEM * Parse()
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
int m_Threshold
Definition collector.h:234
Color settings are a bit different than most of the settings objects in that there can be more than o...
void SetColor(int aLayer, const COLOR4D &aColor)
COLOR4D GetColor(int aLayer) const
COMMIT & Added(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Notify observers that aItem has been added.
Definition commit.h:80
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
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
DO_NOT_SHOW_AGAIN m_DoNotShowAgain
void SelectLibId(const LIB_ID &aLibId)
LIB_ID GetSelectedLibId(int *aUnit=nullptr) const
DESIGN_BLOCK * GetDesignBlock(const LIB_ID &aLibId, bool aUseCacheLib, bool aShowErrorMsg, wxString *aErrorMsg=nullptr)
Load design block from design block library table.
const LIB_ID & GetLibId() const
Modeless inspector for the board's drill groups.
static std::map< wxString, PCB_LAYER_ID > RunModal(wxWindow *aParent, const std::vector< INPUT_LAYER_DESC > &aLayerDesc)
Create and show a dialog (modal) and returns the data from it after completion.
bool Show(bool show) override
int ShowModal() override
wxString GetName() const
Definition drc_rule.h:162
MINOPTMAX< int > & Value()
Definition drc_rule.h:130
MINOPTMAX< int > m_Value
Definition drc_rule.h:206
virtual APP_SETTINGS_BASE * config() const
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
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...
WX_INFOBAR * GetInfoBar()
bool GetOverrideLocks() const
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
A set of EDA_ITEMs (i.e., without duplicates).
Definition eda_group.h:43
bool HasDesignBlockLink() const
Definition eda_group.h:99
void RemoveItem(EDA_ITEM *aItem)
Remove item from group.
Definition eda_group.cpp:77
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:349
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
virtual wxString GetItemDescription(UNITS_PROVIDER *aUnitsProvider, bool aFull) const
Return a user-visible description string of this item.
Definition eda_item.cpp:314
const KIID m_Uuid
Definition eda_item.h:599
virtual EDA_GROUP * GetParentGroup() const
Definition eda_item.h:116
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
void ClearFlags(EDA_ITEM_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition eda_item.h:160
virtual void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList)
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
Definition eda_item.h:296
bool HasFlag(EDA_ITEM_FLAGS aFlag) const
Definition eda_item.h:168
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
SHAPE_T GetShape() const
Definition eda_shape.h:178
bool IsHatchedFill() const
Definition eda_shape.h:133
double GetLength() const
bool validatePasteIntoSelection(const SELECTION &aSel, wxString &aErrorMsg)
Validate if paste-into-cells is possible for the given selection.
bool pasteCellsIntoSelection(const SELECTION &aSel, T_TABLE *aSourceTable, T_COMMIT &aCommit)
Paste text content from source table into selected cells.
The interactive edit tool.
Definition edit_tool.h:54
EMBEDDED_FILE * AddFile(const wxFileName &aName, bool aOverwrite)
Load a file from disk and adds it to the collection.
static const TOOL_EVENT ClearedEvent
Definition actions.h:349
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 PointSelectedEvent
Definition actions.h:346
static const TOOL_EVENT ContrastModeChangedByKeyEvent
Definition actions.h:368
static const TOOL_EVENT ConnectivityChangedEvent
Definition actions.h:351
static const TOOL_EVENT UnselectedEvent
Definition actions.h:348
Provide an extensible class to resolve 3D model paths.
wxString ResolvePath(const wxString &aFileName, const wxString &aWorkingPath, std::vector< const EMBEDDED_FILES * > aEmbeddedFilesStack)
Determine the full path of the given file name.
Component library viewer main window.
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
ZONES & Zones()
Definition footprint.h:361
CONSTRAINTS & Constraints()
Definition footprint.h:367
std::deque< PAD * > & Pads()
Definition footprint.h:355
void ResolveComponentClassNames(BOARD *aBoard, const std::unordered_set< wxString > &aComponentClassNames)
Resolves a set of component class names to this footprint's actual component class.
const std::unordered_set< wxString > & GetTransientComponentClassNames()
Gets the transient component class names.
Definition footprint.h:1335
void SetReference(const wxString &aReference)
Definition footprint.h:799
void ClearTransientComponentClassNames()
Remove the transient component class names.
Definition footprint.h:1341
void GetMsgPanelInfo(EDA_DRAW_FRAME *aFrame, std::vector< MSG_PANEL_ITEM > &aList) override
Populate aList of MSG_PANEL_ITEM objects with it's internal state for display purposes.
GROUPS & Groups()
Definition footprint.h:364
void GetFields(std::vector< PCB_FIELD * > &aVector, bool aVisibleOnly) const
Populate a std::vector with PCB_TEXTs.
DRAWINGS & GraphicalItems()
Definition footprint.h:358
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
static const std::vector< KICAD_T > BoardLevelItems
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition collectors.h:70
static const std::vector< KICAD_T > AllBoardItems
A scan list for all editable board items.
Definition collectors.h:38
void Collect(BOARD_ITEM *aItem, const std::vector< KICAD_T > &aScanList, const VECTOR2I &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
static const std::vector< KICAD_T > FootprintItems
A scan list for primary footprint items.
Definition collectors.h:112
One pass of rebuilding tables.
Similar to EDA_VIEW_SWITCHER, this dialog is a popup that shows feedback when using a hotkey to cycle...
void Popup(const wxString &aTitle, const wxArrayString &aItems, int aSelection)
void SetDialogSizeInDU(int aWidth, int aHeight)
Set the dialog size, using a "logical" value.
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
virtual void SetProgressReporter(PROGRESS_REPORTER *aReporter)
Set an optional progress reporter.
Definition io_base.h:94
An exception saying that the user cancelled an interactive part of a load, import,...
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Helper class to create more flexible dialogs, including 'do not show again' checkbox handling.
Definition kidialog.h:38
void DoNotShowCheckbox(wxString file, int line)
Shows the 'do not show again' checkbox.
Definition kidialog.cpp:51
int ShowModal() override
Definition kidialog.cpp:89
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
COLOR4D & Darken(double aFactor)
Makes the color darker by a given factor.
Definition color4d.h:223
COLOR4D & Brighten(double aFactor)
Makes the color brighter by a given factor.
Definition color4d.h:206
double a
Alpha component.
Definition color4d.h:394
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
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:87
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.
bool IsBOARD_ITEM() const
Definition view_item.h:98
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:365
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition view.cpp:488
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition view.cpp:2630
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
Definition view.h:224
void MarkDirty()
Force redraw of view on the next rendering.
Definition view.h:779
Definition kiid.h:46
Plugin class for import plugins that support remappable layers.
All information about a layer pair as stored in the layer pair store.
Management class for layer pairs in a PCB.
Definition layer_pairs.h:43
std::vector< LAYER_PAIR_INFO > GetEnabledLayerPairs(int &aCurrentIndex) const
Get a vector of all enabled layer pairs, in order.
void SetCurrentLayerPair(const LAYER_PAIR &aPair)
Set the "active" layer pair.
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
bool IsValid() const
Check if this LID_ID is valid.
Definition lib_id.h:168
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
LSEQ is a sequence (and therefore also a set) of PCB_LAYER_IDs.
Definition lseq.h:47
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllCuMask()
return AllCuMask( MAX_CU_LAYERS );
Definition lset.cpp:604
LSEQ UIOrder() const
Return the copper, technical and user layers in the order shown in layer widget.
Definition lset.cpp:739
LSEQ CuStack() const
Return a sequence of copper layers in starting from the front/top and extending to the back/bottom.
Definition lset.cpp:259
LSEQ Seq(const LSEQ &aSequence) const
Return an LSEQ from the union of this LSET and a desired sequence.
Definition lset.cpp:309
static LSET AllCuMask(int aCuLayerCount)
Return a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition lset.cpp:595
bool Contains(PCB_LAYER_ID aLayer) const
See if the layer set contains a PCB layer.
Definition lset.h:63
T Min() const
Definition minoptmax.h:29
bool HasMax() const
Definition minoptmax.h:38
T Max() const
Definition minoptmax.h:30
EDA_MSG_PANEL items for displaying messages.
Definition msgpanel.h:50
static std::vector< NETINFO_ITEM * > IsolateDesignBlockAutoNets(BOARD *aBoard, const std::set< FOOTPRINT * > &aFootprints, const std::unordered_set< EDA_ITEM * > &aItems)
Remap auto-generated nets (Net-(...), unconnected-...) of a design block that was appended for layout...
int RepeatLayout(const TOOL_EVENT &aEvent, ZONE *aRefZone)
Handle the data for a net.
Definition netinfo.h:50
static const int UNCONNECTED
Constant that holds the "unconnected net" number (typically 0) all items "connected" to this net are ...
Definition netinfo.h:281
static NETINFO_ITEM * OrphanedItem()
NETINFO_ITEM meaning that there was no net assigned for an item, as there was no board storing net li...
Definition netinfo.h:289
void RecordMasterPad(const PAD &aPad)
Record aPad as the template for the next pad of its type placed.
Definition pad_tool.cpp:402
Definition pad.h:61
static wxString ShowPadShape(PAD_SHAPE aShape)
Definition pad.cpp:2524
bool HasHole() const override
Definition pad.h:113
Describe the page size and margins of a paper page on which to eventually print or plot.
Definition page_info.h:75
static TOOL_ACTION layerToggle
static TOOL_ACTION layerInner12
static TOOL_ACTION nextFootprint
static TOOL_ACTION layerInner8
static TOOL_ACTION zoneDisplayToggle
static TOOL_ACTION previousFootprint
static TOOL_ACTION layerInner3
static TOOL_ACTION layerPrev
static TOOL_ACTION showRatsnest
static TOOL_ACTION zoneFillAll
static TOOL_ACTION layerInner2
static TOOL_ACTION magneticSnapAllLayers
static TOOL_ACTION collect3DModels
static TOOL_ACTION saveToLinkedDesignBlock
static TOOL_ACTION placeDrillMap
static TOOL_ACTION ddAppendBoard
Drag and drop.
static TOOL_ACTION layerInner25
static TOOL_ACTION magneticSnapActiveLayer
Snapping controls.
static TOOL_ACTION layerAlphaDec
static TOOL_ACTION zoneDisplayFilled
static TOOL_ACTION layerInner24
static TOOL_ACTION viaDisplayMode
static TOOL_ACTION layerInner29
static TOOL_ACTION placeCharacteristics
static TOOL_ACTION layerInner11
static TOOL_ACTION layerAlphaInc
static TOOL_ACTION layerPairPresetsCycle
static TOOL_ACTION layerInner16
static TOOL_ACTION layerInner26
static TOOL_ACTION layerInner18
static TOOL_ACTION layerInner14
static TOOL_ACTION trackDisplayMode
static TOOL_ACTION magneticSnapToggle
static TOOL_ACTION layerInner6
static TOOL_ACTION applyDesignBlockLayout
static TOOL_ACTION ddImportFootprint
static TOOL_ACTION zoneDisplayTriangulated
static TOOL_ACTION rehatchShapes
static TOOL_ACTION layerInner22
static TOOL_ACTION placeDesignBlock
static TOOL_ACTION layerInner5
static TOOL_ACTION zoneDisplayFractured
static TOOL_ACTION ratsnestModeCycle
static TOOL_ACTION layerInner20
static TOOL_ACTION layerInner7
static TOOL_ACTION layerInner27
static TOOL_ACTION loadFpFromBoard
static TOOL_ACTION appendBoard
static TOOL_ACTION netColorModeCycle
static TOOL_ACTION layerInner1
static TOOL_ACTION layerInner10
static TOOL_ACTION layerInner15
static TOOL_ACTION layerInner17
static TOOL_ACTION flipBoard
static TOOL_ACTION layerBottom
static TOOL_ACTION zoneDisplayOutline
static TOOL_ACTION ratsnestLineMode
static TOOL_ACTION layerInner19
static TOOL_ACTION layerInner9
static TOOL_ACTION showDrillGroups
static TOOL_ACTION placeDrillChart
static TOOL_ACTION move
move or drag an item
static TOOL_ACTION layerInner30
static TOOL_ACTION layerTop
static TOOL_ACTION updateDesignBlockFromSelection
static TOOL_ACTION layerInner4
static TOOL_ACTION layerInner13
static TOOL_ACTION layerInner21
static TOOL_ACTION saveFpToBoard
static TOOL_ACTION layerNext
static TOOL_ACTION placeLinkedDesignBlock
static TOOL_ACTION placeStackup
static TOOL_ACTION layerInner23
static TOOL_ACTION layerInner28
Common, abstract interface for edit frames.
void RestoreCopyFromUndoList(wxCommandEvent &aEvent)
Undo the last edit:
APPEARANCE_CONTROLS * GetAppearancePanel()
void RestoreCopyFromRedoList(wxCommandEvent &aEvent)
Redo the last edit:
void UpdateVertexEditorSelection(BOARD_ITEM *aItem)
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
const VECTOR2I GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
void OnModify() override
Must be called after a change in order to set the "modify" flag and update other data structures and ...
BOARD * GetBoard() const
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Return the BOARD_DESIGN_SETTINGS for the open project.
A geometric constraint between board items (issue #2329).
int PlaceDrillChart(const TOOL_EVENT &aEvent)
int RehatchShapes(const TOOL_EVENT &aEvent)
void setTransitions() override
Sets up handlers for various events.
int AppendBoardFromFile(const TOOL_EVENT &aEvent)
int AddLibrary(const TOOL_EVENT &aEvent)
int DdAppendBoard(const TOOL_EVENT &aEvent)
int LoadFpFromBoard(const TOOL_EVENT &aEvent)
int SaveToLinkedDesignBlock(const TOOL_EVENT &aEvent)
int DdImportFootprint(const TOOL_EVENT &aEvent)
int SnapModeFeedback(const TOOL_EVENT &aEvent)
int NetColorModeCycle(const TOOL_EVENT &aEvent)
int SaveFpToBoard(const TOOL_EVENT &aEvent)
int RatsnestModeCycle(const TOOL_EVENT &aEvent)
int TrackDisplayMode(const TOOL_EVENT &aEvent)
int DdAddLibrary(const TOOL_EVENT &aEvent)
int ShowDrillGroups(const TOOL_EVENT &aEvent)
int Redo(const TOOL_EVENT &aEvent)
int PlaceLinkedDesignBlock(const TOOL_EVENT &aEvent)
bool placeBoardItems(BOARD_COMMIT *aCommit, std::vector< BOARD_ITEM * > &aItems, bool aIsNew, bool aAnchorAtOrigin, bool aReannotateDuplicates, bool aSkipMove)
Add and select or just select for move/place command a list of board items.
PCB_LAYER_ID pickDocumentationLayer(const std::function< bool(PCB_LAYER_ID)> &aAvailable, const wxString &aNoLayerMessage)
The active layer when aAvailable accepts it, otherwise the first documentation layer it does,...
int LayerPresetFeedback(const TOOL_EVENT &aEvent)
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
int placeGeneratedTable(std::unique_ptr< PCB_GENERATED_TABLE > aTable, const wxString &aNoLayerMessage, const wxString &aUndoMessage)
Build a generated table on a documentation layer and hand it to the user to place.
int LayerAlphaDec(const TOOL_EVENT &aEvent)
static void rehatchBoardItem(KIGFX::VIEW *aView, BOARD_ITEM *aItem)
Regenerate and redraw an item's hatching, skipping non-hatched shapes. Static for testing.
int LayerNext(const TOOL_EVENT &aEvent)
int PlaceStackup(const TOOL_EVENT &aEvent)
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
int ToggleRatsnest(const TOOL_EVENT &aEvent)
int LayerAlphaInc(const TOOL_EVENT &aEvent)
int HighContrastModeCycle(const TOOL_EVENT &aEvent)
std::unique_ptr< KIGFX::ORIGIN_VIEWITEM > m_gridOrigin
int HighContrastMode(const TOOL_EVENT &aEvent)
int Undo(const TOOL_EVENT &aEvent)
int ViaDisplayMode(const TOOL_EVENT &aEvent)
PCB_BASE_FRAME * m_frame
static void DoSetGridOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, EDA_ITEM *originViewItem, const VECTOR2D &aPoint)
int CollectAndEmbed3DModels(const TOOL_EVENT &aEvent)
void pruneItemLayers(std::vector< BOARD_ITEM * > &aItems)
Helper for pasting.
int GridPlaceOrigin(const TOOL_EVENT &aEvent)
int FlipPcbView(const TOOL_EVENT &aEvent)
int PlaceCharacteristics(const TOOL_EVENT &aEvent)
wxWeakRef< wxDialog > m_drillGroupsDialog
Modeless, so it outlives the action that opened it.
int ApplyDesignBlockLayout(const TOOL_EVENT &aEvent)
int SnapMode(const TOOL_EVENT &aEvent)
int ContrastModeFeedback(const TOOL_EVENT &aEvent)
int LayerToggle(const TOOL_EVENT &aEvent)
int AppendBoard(PCB_IO &pi, const wxString &fileName, DESIGN_BLOCK *aDesignBlock=nullptr, BOARD_COMMIT *aCommit=nullptr, bool aSkipMove=false)
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
int IterateFootprint(const TOOL_EVENT &aEvent)
int Print(const TOOL_EVENT &aEvent)
int ZoneDisplayMode(const TOOL_EVENT &aEvent)
int GridResetOrigin(const TOOL_EVENT &aEvent)
BOARD_ITEM * m_pickerItem
int InteractiveDelete(const TOOL_EVENT &aEvent)
int AppendDesignBlock(const TOOL_EVENT &aEvent)
int LayerPrev(const TOOL_EVENT &aEvent)
int PlaceDrillMap(const TOOL_EVENT &aEvent)
int CycleLayerPresets(const TOOL_EVENT &aEvent)
int Paste(const TOOL_EVENT &aEvent)
void unfilledZoneCheck()
We have bug reports indicating that some new users confuse zone filling/unfilling with the display mo...
int LayerSwitch(const TOOL_EVENT &aEvent)
Abstract dimension API.
bool m_FlipBoardView
true if the board is flipped to show the mirrored view
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
void RedrawRatsnest()
Force refresh of the ratsnest visual representation.
Turns on drill symbols at the holes, for one layer.
The main frame for Pcbnew.
PCB_DESIGN_BLOCK_PANE * GetDesignBlockPane() const
static const TOOL_EVENT & SnappingModeChangedByKeyEvent()
Hotkey feedback.
static const TOOL_EVENT & LayerPairPresetChangedByKeyEvent()
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
PCB_FILE_T
The set of file types that the PCB_IO_MGR knows about, and for which there has been a plugin written,...
Definition pcb_io_mgr.h:52
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a PCB_IO which the caller can use to import, export, save, or load design documents.
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
A base class that BOARD loading and saving plugins should derive from.
Definition pcb_io.h:78
void LoadAndAppendBoard(const wxString &aFileName, BOARD &aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Same as LoadBoard(), but appends the loaded board to an existing board, which must already exist.
Definition pcb_io.cpp:85
virtual void SetQueryUserCallback(std::function< bool(wxString aTitle, int aIcon, wxString aMessage, wxString aAction)> aCallback)
Register a KIDIALOG callback for collecting info from the user.
Definition pcb_io.h:129
Class that manages the presentation of PCB layers in a PCB frame.
wxString getLayerPairName(const LAYER_PAIR &aPair) const
Definition sel_layer.cpp:91
Generic tool for picking an item.
void ClearHandlers()
Handlers only.
PCB_LAYER_ID m_Route_Layer_TOP
Definition pcb_screen.h:39
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition pcb_screen.h:40
The selection tool: currently supports:
void GuessSelectionCandidates(GENERAL_COLLECTOR &aCollector, const VECTOR2I &aWhere) const
Try to guess best selection candidates in case multiple items are clicked, by doing some brain-dead h...
void select(EDA_ITEM *aItem) override
Take necessary action mark an item as selected.
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
PCB_GROUP * GetEnteredGroup()
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.
int ClearSelection(const TOOL_EVENT &aEvent)
Clear current selection event handler.
PCB_SELECTION & GetSelection()
void FilterCollectedItems(GENERAL_COLLECTOR &aCollector, bool aMultiSelect, PCB_SELECTION_FILTER_OPTIONS *aRejected=nullptr)
Apply the SELECTION_FITLER_OPTIONS to the collector.
void UpdateHatching() const override
T * frame() const
KIGFX::PCB_VIEW * view() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
PCBNEW_SETTINGS::DISPLAY_OPTIONS & displayOptions() const
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
const VECTOR2I & GetStart() const
Definition pcb_track.h:100
const VECTOR2I & GetEnd() const
Definition pcb_track.h:97
virtual COMMON_SETTINGS * GetCommonSettings() const
Definition pgm_base.cpp:600
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition picker_tool.h:92
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition picker_tool.h:81
void SetSnapping(bool aSnap)
Definition picker_tool.h:65
void SetCursor(KICURSOR aCursor)
Definition picker_tool.h:63
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
static S3D_CACHE * Get3DCacheManager(PROJECT *aProject, bool updateProjDir=false)
Return a pointer to an instance of the 3D cache manager.
Container for project specific data.
Definition project.h:63
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:277
Cache for storing the 3D shapes.
Definition 3d_cache.h:53
FILENAME_RESOLVER * GetResolver() noexcept
Definition 3d_cache.cpp:548
Definition seg.h:38
ecoord SquaredDistance(const SEG &aSeg) const
Definition seg.cpp:35
VECTOR2I::extended_type ecoord
Definition seg.h:40
void BrightenItem(EDA_ITEM *aItem)
void UnbrightenItem(EDA_ITEM *aItem)
virtual void Add(EDA_ITEM *aItem)
A null aItem is ignored; the selection never holds null members.
Definition selection.cpp:38
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
Represent a set of closed polygons.
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
virtual VECTOR2I Centre() const
Compute a center-of-mass of the shape.
Definition shape.h:242
Extension of STATUS_POPUP for displaying a single line text.
Hold the information shown in the lower right corner of a plot, printout, or editing view.
Definition title_block.h:38
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
const std::string & GetName() const
Return the name of the tool.
Definition tool_base.h:132
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
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
@ REDRAW
Full drawing refresh.
Definition tool_base.h:79
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
@ GAL_SWITCH
Rendering engine changes.
Definition tool_base.h:78
Generic, UI-independent tool event.
Definition tool_event.h:167
COMMIT * Commit() const
Definition tool_event.h:279
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
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
void Activate()
Run the tool.
Master controller class:
T * GetTool()
Return the tool of given type or nullptr if there is no such tool registered.
static constexpr extended_type ECOORD_MAX
Definition vector2d.h:72
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessageFor(const wxString &aMessage, int aTime, int aFlags=wxICON_INFORMATION, MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the infobar with the provided message and icon for a specific period of time.
void AddLink(const wxString &aLinkText, const std::function< void(wxHyperlinkEvent &)> &aFn)
Add a hypertext link to the infobar.
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
Handle a list of polygons defining a copper zone.
Definition zone.h:70
void SetDoNotAllowPads(bool aEnable)
Definition zone.h:860
void AddPolygon(std::vector< VECTOR2I > &aPolygon)
Add a polygon to the zone outline.
Definition zone.cpp:1502
void SetPlacementAreaSource(const wxString &aSource)
Definition zone.h:840
void SetPlacementAreaSourceType(PLACEMENT_SOURCE_T aType)
Definition zone.h:842
SHAPE_POLY_SET * Outline()
Definition zone.h:421
void SetHatchStyle(ZONE_BORDER_DISPLAY_STYLE aStyle)
Definition zone.h:690
void SetIsRuleArea(bool aEnable)
Definition zone.h:835
void SetDoNotAllowTracks(bool aEnable)
Definition zone.h:859
const wxString & GetZoneName() const
Definition zone.h:160
void SetLayerSet(const LSET &aLayerSet) override
Definition zone.cpp:702
void SetDoNotAllowVias(bool aEnable)
Definition zone.h:858
void SetDoNotAllowFootprints(bool aEnable)
Definition zone.h:861
void SetDoNotAllowZoneFills(bool aEnable)
Definition zone.h:857
void SetZoneName(const wxString &aName)
Definition zone.h:161
void SetPlacementAreaEnabled(bool aEnabled)
Definition zone.h:837
std::unique_ptr< wxBitmap > GetImageFromClipboard()
Get image data from the clipboard, if there is any.
std::string GetClipboardUTF8()
Return the information currently stored in the system clipboard.
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition confirm.cpp:274
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
void DisplayError(wxWindow *aParent, const wxString &aText)
Display an error or warning message box with aMessage.
Definition confirm.cpp:192
This file is part of the common library.
void TransformCircleToPolygon(SHAPE_LINE_CHAIN &aBuffer, const VECTOR2I &aCenter, int aRadius, int aError, ERROR_LOC aErrorLoc, int aMinSegCount=0)
Convert a circle to a polygon, using multiple straight lines.
void BuildConvexHull(std::vector< VECTOR2I > &aResult, const std::vector< VECTOR2I > &aPoly)
Calculate the convex hull of a list of points in counter-clockwise order.
@ REMOVE
Definition cursors.h:51
@ PLACE
Definition cursors.h:95
@ ARROW
Definition cursors.h:43
#define ALPHA_MAX
@ DIFF_PAIR_GAP_CONSTRAINT
@ EDGE_CLEARANCE_CONSTRAINT
@ CLEARANCE_CONSTRAINT
@ MAX_UNCOUPLED_CONSTRAINT
@ HOLE_CLEARANCE_CONSTRAINT
#define _(s)
Declaration of the eda_3d_viewer class.
@ RECURSE
Definition eda_item.h:51
@ NO_RECURSE
Definition eda_item.h:52
#define IS_NEW
New item, just created.
#define MCT_SKIP_STRUCT
flag used by the multichannel tool to mark items that should be skipped
#define SKIP_STRUCT
flag indicating that the structure should be ignored
@ SEGMENT
Definition eda_shape.h:57
EDA_UNITS
Definition eda_units.h:45
@ FRAME_PCB_EDITOR
Definition frame_type.h:38
@ FRAME_FOOTPRINT_VIEWER
Definition frame_type.h:41
@ FRAME_FOOTPRINT_EDITOR
Definition frame_type.h:39
GENERATED_TABLE_UNITS ToGeneratedTableUnits(EDA_UNITS aUnits)
The table units a user's display units seed.
LSET DocumentationLayers()
Layers a generated table or drill map may live on.
static const std::string KiCadUriPrefix
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
std::unique_ptr< T > IO_RELEASER
Helper to hold and release an IO_BASE object when exceptions are thrown.
Definition io_mgr.h:33
#define KICTL_KICAD_ONLY
chosen file is from KiCad according to user
int GetNetnameLayer(int aLayer)
Return a netname layer corresponding to the given layer.
Definition layer_ids.h:921
bool IsCopperLayer(int aLayerId)
Test whether a layer is a copper layer.
Definition layer_ids.h:744
@ LAYER_RATSNEST
Definition layer_ids.h:249
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ Edge_Cuts
Definition layer_ids.h:108
@ B_Cu
Definition layer_ids.h:61
@ Margin
Definition layer_ids.h:109
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ F_Cu
Definition layer_ids.h:60
#define ZONE_LAYER_FOR(boardLayer)
Definition layer_ids.h:396
std::optional< wxString > GetMsgPanelDisplayUuid(const KIID &aKiid)
Get a formatted UUID string for display in the message panel, according to the current advanced confi...
Definition msgpanel.cpp:216
SHAPE_LINE_CHAIN RectifyPolygon(const SHAPE_LINE_CHAIN &aPoly)
Take a polygon and 'rectify' it, so that all sides are H/V.
void CollectBoxCorners(const BOX2I &aBox, std::vector< VECTOR2I > &aCorners)
Add the 4 corners of a BOX2I to a vector.
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
constexpr char APPEND_PRESERVE_DESTINATION_STACKUP[]
Definition pcb_io.h:46
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
bool AskLoadBoardFileName(PCB_EDIT_FRAME *aParent, wxString *aFileName, int aCtl=0)
Show a wxFileDialog asking for a BOARD filename to open.
PCB_TABLE * Build_Board_Characteristics_Table(BOARD *aBoard, EDA_UNITS aDisplayUnits)
static void recordPastedItems(TOOL_MANAGER *aToolMgr, const std::vector< BOARD_ITEM * > &aItems)
Handle items that have been pasted.
#define ALPHA_STEP
static void pasteFootprintItemsToFootprintEditor(FOOTPRINT *aClipFootprint, BOARD *aBoard, std::vector< BOARD_ITEM * > &aPastedItems)
#define ALPHA_MIN
void Flip(T &aValue)
Class to handle a set of BOARD_ITEMs.
bool AskLoadBoardFileName(PCB_EDIT_FRAME *aParent, wxString *aFileName, int aCtl=0)
Show a wxFileDialog asking for a BOARD filename to open.
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
CITER next(CITER it)
Definition ptree.cpp:120
#define HITTEST_THRESHOLD_PIXELS
std::vector< EDA_ITEM * > EDA_ITEMS
Utility functions for working with shapes.
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
Options for copying a placement rule area onto the others linked to it.
VECTOR2I m_center
std::unordered_set< EDA_ITEM * > m_designBlockItems
PLACEMENT_SOURCE_T m_sourceType
std::set< FOOTPRINT * > m_components
PCB_GROUP * m_group
const std::string table
KIBIS_MODEL * model
static std::vector< int > candidates(const SEGMENT_INDEX &aIndex, const SEG &aQuery, int aPadding)
VECTOR2I center
int actual
wxString result
Test unit parsing edge cases and error handling.
constexpr KICAD_T BaseType(const KICAD_T aType)
Return the underlying type of the given type.
Definition typeinfo.h:261
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition typeinfo.h:70
@ PCB_T
Definition typeinfo.h:74
@ PCB_CONSTRAINT_T
a geometric constraint between board items
Definition typeinfo.h:237
@ PCB_SHAPE_T
class PCB_SHAPE, a segment not on copper layers
Definition typeinfo.h:80
@ PCB_DIM_ORTHOGONAL_T
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition typeinfo.h:98
@ PCB_DIM_LEADER_T
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition typeinfo.h:95
@ 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_DIM_CENTER_T
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition typeinfo.h:96
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition typeinfo.h:103
@ PCB_TEXTBOX_T
class PCB_TEXTBOX, wrapped text on a layer
Definition typeinfo.h:85
@ PCB_ZONE_T
class ZONE, a copper pour area
Definition typeinfo.h:100
@ PCB_TEXT_T
class PCB_TEXT, text on a layer
Definition typeinfo.h:84
@ PCB_REFERENCE_IMAGE_T
class PCB_REFERENCE_IMAGE, bitmap on a layer
Definition typeinfo.h:81
@ NOT_USED
the 3d code uses this value
Definition typeinfo.h:71
@ PCB_MARKER_T
class PCB_MARKER, a marker used to show something
Definition typeinfo.h:91
@ PCB_BARCODE_T
class PCB_BARCODE, a barcode (graphic item)
Definition typeinfo.h:93
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:87
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:78
@ PCB_DIM_ALIGNED_T
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition typeinfo.h:94
@ 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_DIMENSION_T
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition typeinfo.h:92
@ PCB_TABLE_T
class PCB_TABLE, table of PCB_TABLECELLs
Definition typeinfo.h:86
@ PCB_POINT_T
class PCB_POINT, a 0-dimensional point
Definition typeinfo.h:105
@ PCB_TRACE_T
class PCB_TRACK, a track segment (segment on a copper layer)
Definition typeinfo.h:88
@ PCB_DIM_RADIAL_T
class PCB_DIM_RADIAL, a radius or diameter dimension
Definition typeinfo.h:97
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
Definition of file extensions used in Kicad.
#define PR_CAN_ABORT