KiCad PCB EDA Suite
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 (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
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, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include "edit_tool.h"
27 #include <pgm_base.h>
28 #include "pcb_actions.h"
29 #include "pcb_control.h"
30 #include "pcb_picker_tool.h"
31 #include "pcb_selection_tool.h"
32 #include "board_reannotate_tool.h"
34 #include <bitmaps.h>
35 #include <board_commit.h>
36 #include <board.h>
37 #include <board_design_settings.h>
38 #include <board_item.h>
40 #include <pcb_dimension.h>
41 #include <footprint.h>
42 #include <pcb_group.h>
43 #include <pcb_track.h>
44 #include <zone.h>
45 #include <fp_shape.h>
46 #include <confirm.h>
48 #include <core/kicad_algo.h>
49 #include <kicad_clipboard.h>
50 #include <origin_viewitem.h>
51 #include <pcb_edit_frame.h>
52 #include <pcb_painter.h>
53 #include <properties.h>
55 #include <tool/tool_manager.h>
56 #include <footprint_viewer_frame.h>
57 #include <footprint_edit_frame.h>
59 #include <widgets/infobar.h>
60 #include <wx/hyperlink.h>
61 
62 using namespace std::placeholders;
63 
64 
65 // files.cpp
66 extern bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, int* aCtl, wxString* aFileName,
67  bool aKicadFilesOnly = false );
68 extern IO_MGR::PCB_FILE_T plugin_type( const wxString& aFileName, int aCtl );
69 
70 
72  PCB_TOOL_BASE( "pcbnew.Control" ),
73  m_frame( nullptr ),
74  m_pickerItem( nullptr )
75 {
76  m_gridOrigin.reset( new KIGFX::ORIGIN_VIEWITEM() );
77 }
78 
79 
81 {
82 }
83 
84 
86 {
87  m_frame = getEditFrame<PCB_BASE_FRAME>();
88 
89  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
90  {
91  m_gridOrigin->SetPosition( board()->GetDesignSettings().m_GridOrigin );
92  m_gridOrigin->SetColor( m_frame->GetGridColor() );
93  getView()->Remove( m_gridOrigin.get() );
94  getView()->Add( m_gridOrigin.get() );
95  }
96 }
97 
98 
99 int PCB_CONTROL::AddLibrary( const TOOL_EVENT& aEvent )
100 {
102  {
103  if( aEvent.IsAction( &ACTIONS::newLibrary ) )
104  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->CreateNewLibrary();
105  else if( aEvent.IsAction( &ACTIONS::addLibrary ) )
106  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->AddLibrary();
107  }
108 
109  return 0;
110 }
111 
112 
113 int PCB_CONTROL::Quit( const TOOL_EVENT& aEvent )
114 {
115  m_frame->Close( false );
116  return 0;
117 }
118 
119 
120 template<class T> void Flip( T& aValue )
121 {
122  aValue = !aValue;
123 }
124 
125 
127 {
129 
130  Flip( opts.m_DisplayPcbTrackFill );
131  m_frame->SetDisplayOptions( opts );
132 
133  for( PCB_TRACK* track : board()->Tracks() )
134  {
135  if( track->Type() == PCB_TRACE_T || track->Type() == PCB_ARC_T )
136  view()->Update( track, KIGFX::REPAINT );
137  }
138 
139  canvas()->Refresh();
140 
141  return 0;
142 }
143 
144 
146 {
148 
149  if( aEvent.IsAction( &PCB_ACTIONS::showRatsnest ) )
150  {
151  // N.B. Do not disable the Ratsnest layer here. We use it for local ratsnest
152  Flip( opts.m_ShowGlobalRatsnest );
153  m_frame->SetDisplayOptions( opts );
154  getEditFrame<PCB_EDIT_FRAME>()->SetElementVisibility( LAYER_RATSNEST,
155  opts.m_ShowGlobalRatsnest );
156 
157  }
158  else if( aEvent.IsAction( &PCB_ACTIONS::ratsnestLineMode ) )
159  {
161  m_frame->SetDisplayOptions( opts );
162  }
163 
164  canvas()->RedrawRatsnest();
165  canvas()->Refresh();
166 
167  return 0;
168 }
169 
170 
172 {
174 
175  Flip( opts.m_DisplayViaFill );
176  m_frame->SetDisplayOptions( opts );
177 
178  for( PCB_TRACK* track : board()->Tracks() )
179  {
180  if( track->Type() == PCB_TRACE_T || track->Type() == PCB_VIA_T )
181  view()->Update( track, KIGFX::REPAINT );
182  }
183 
184  canvas()->Refresh();
185 
186  return 0;
187 }
188 
189 
196 {
197  if( Pgm().GetCommonSettings()->m_DoNotShowAgain.zone_fill_warning )
198  return;
199 
200  bool unfilledZones = false;
201 
202  for( const ZONE* zone : board()->Zones() )
203  {
204  if( !zone->IsFilled() )
205  {
206  unfilledZones = true;
207  break;
208  }
209  }
210 
211  if( unfilledZones )
212  {
213  WX_INFOBAR* infobar = frame()->GetInfoBar();
214  wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Don't show again" ),
215  wxEmptyString );
216 
217  button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
218  [&]( wxHyperlinkEvent& aEvent )
219  {
220  Pgm().GetCommonSettings()->m_DoNotShowAgain.zone_fill_warning = true;
221  frame()->GetInfoBar()->Dismiss();
222  } ) );
223 
224  infobar->RemoveAllButtons();
225  infobar->AddButton( button );
226 
227  wxString msg;
228  msg.Printf( _( "Not all zones are filled. Use Edit > Fill All Zones (%s) "
229  "if you wish to see all fills." ),
231 
232  infobar->ShowMessageFor( msg, 10000, wxICON_WARNING );
233  }
234 }
235 
236 
238 {
240 
241  // Apply new display options to the GAL canvas
243  {
245 
247  }
248  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayOutline ) )
249  {
251  }
252  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayFractured ) )
253  {
255  }
256  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayTriangulated ) )
257  {
259  }
260  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayToggle ) )
261  {
264  else
266  }
267  else
268  {
269  wxFAIL;
270  }
271 
272  m_frame->SetDisplayOptions( opts );
273 
274  for( ZONE* zone : board()->Zones() )
275  view()->Update( zone, KIGFX::REPAINT );
276 
277  canvas()->Refresh();
278 
279  return 0;
280 }
281 
282 
284 {
286 
287  opts.m_ContrastModeDisplay =
291 
292  m_frame->SetDisplayOptions( opts );
293 
294  return 0;
295 }
296 
297 
299 {
301 
302  switch( opts.m_ContrastModeDisplay )
303  {
307  }
308 
309  m_frame->SetDisplayOptions( opts );
310 
311  return 0;
312 }
313 
314 
316 {
317  m_frame->SwitchLayer( nullptr, aEvent.Parameter<PCB_LAYER_ID>() );
318 
319  return 0;
320 }
321 
322 
323 int PCB_CONTROL::LayerNext( const TOOL_EVENT& aEvent )
324 {
325  PCB_BASE_FRAME* editFrame = m_frame;
326  BOARD* brd = board();
327  LAYER_NUM layer = editFrame->GetActiveLayer();
328  LAYER_NUM startLayer = layer;
329 
330  if( layer < F_Cu || layer > B_Cu )
331  return 0;
332 
333  while( startLayer != ++layer )
334  {
335  if( brd->IsLayerVisible( static_cast<PCB_LAYER_ID>( layer ) ) && IsCopperLayer( layer ) )
336  break;
337 
338  if( layer >= B_Cu )
339  layer = F_Cu - 1;
340  }
341 
342  wxCHECK( IsCopperLayer( layer ), 0 );
343  editFrame->SwitchLayer( nullptr, ToLAYER_ID( layer ) );
344 
345  return 0;
346 }
347 
348 
349 int PCB_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
350 {
351  PCB_BASE_FRAME* editFrame = m_frame;
352  BOARD* brd = board();
353  LAYER_NUM layer = editFrame->GetActiveLayer();
354  LAYER_NUM startLayer = layer;
355 
356  if( layer < F_Cu || layer > B_Cu )
357  return 0;
358 
359  while( startLayer != --layer )
360  {
361  if( IsCopperLayer( layer ) // also test for valid layer id (layer >= F_Cu)
362  && brd->IsLayerVisible( static_cast<PCB_LAYER_ID>( layer ) ) )
363  {
364  break;
365  }
366 
367  if( layer <= F_Cu )
368  layer = B_Cu + 1;
369  }
370 
371 
372  wxCHECK( IsCopperLayer( layer ), 0 );
373  editFrame->SwitchLayer( nullptr, ToLAYER_ID( layer ) );
374 
375  return 0;
376 }
377 
378 
380 {
381  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
382  PCB_SCREEN* screen = m_frame->GetScreen();
383 
384  if( currentLayer == screen->m_Route_Layer_TOP )
385  m_frame->SwitchLayer( nullptr, screen->m_Route_Layer_BOTTOM );
386  else
387  m_frame->SwitchLayer( nullptr, screen->m_Route_Layer_TOP );
388 
389  return 0;
390 }
391 
392 
393 // It'd be nice to share the min/max with the DIALOG_COLOR_PICKER, but those are
394 // set in wxFormBuilder.
395 #define ALPHA_MIN 0.20
396 #define ALPHA_MAX 1.00
397 #define ALPHA_STEP 0.05
398 
399 
401 {
402  COLOR_SETTINGS* settings = m_frame->GetColorSettings();
403  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
404  KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
405 
406  if( currentColor.a <= ALPHA_MAX - ALPHA_STEP )
407  {
408  currentColor.a += ALPHA_STEP;
409  settings->SetColor( currentLayer, currentColor );
411 
413  view->UpdateLayerColor( currentLayer );
414  view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
415 
416  if( IsCopperLayer( currentLayer ) )
417  view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
418 
419  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->OnLayerAlphaChanged();
420  }
421  else
422  {
423  wxBell();
424  }
425 
426  return 0;
427 }
428 
429 
431 {
432  COLOR_SETTINGS* settings = m_frame->GetColorSettings();
433  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
434  KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
435 
436  if( currentColor.a >= ALPHA_MIN + ALPHA_STEP )
437  {
438  currentColor.a -= ALPHA_STEP;
439  settings->SetColor( currentLayer, currentColor );
441 
443  view->UpdateLayerColor( currentLayer );
444  view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
445 
446  if( IsCopperLayer( currentLayer ) )
447  view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
448 
449  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->OnLayerAlphaChanged();
450  }
451  else
452  {
453  wxBell();
454  }
455 
456  return 0;
457 }
458 
459 
461  EDA_ITEM* originViewItem, const VECTOR2D& aPoint )
462 {
463  aFrame->GetDesignSettings().m_GridOrigin = (wxPoint) aPoint;
464  aView->GetGAL()->SetGridOrigin( aPoint );
465  originViewItem->SetPosition( (wxPoint) aPoint );
466  aView->MarkDirty();
467  aFrame->OnModify();
468 }
469 
470 
472 {
473  VECTOR2D* origin = aEvent.Parameter<VECTOR2D*>();
474 
475  if( origin )
476  {
477  // We can't undo the other grid dialog settings, so no sense undoing just the origin
478  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), *origin );
479  delete origin;
480  }
481  else
482  {
483  if( m_isFootprintEditor && !getEditFrame<PCB_BASE_EDIT_FRAME>()->GetModel() )
484  return 0;
485 
486  std::string tool = aEvent.GetCommandStr().get();
488 
489  if( !picker ) // Happens in footprint wizard
490  return 0;
491 
492  // Deactivate other tools; particularly important if another PICKER is currently running
493  Activate();
494 
495  picker->SetClickHandler(
496  [this]( const VECTOR2D& pt ) -> bool
497  {
499  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), pt );
500  return false; // drill origin is a one-shot; don't continue with tool
501  } );
502 
503  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
504  }
505 
506  return 0;
507 }
508 
509 
511 {
513  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), VECTOR2D( 0, 0 ) );
514  return 0;
515 }
516 
517 
518 #define HITTEST_THRESHOLD_PIXELS 5
519 
520 
522 {
524  return 0;
525 
526  std::string tool = aEvent.GetCommandStr().get();
528 
529  m_pickerItem = nullptr;
531 
532  // Deactivate other tools; particularly important if another PICKER is currently running
533  Activate();
534 
535  picker->SetCursor( KICURSOR::REMOVE );
536 
537  picker->SetClickHandler(
538  [this]( const VECTOR2D& aPosition ) -> bool
539  {
540  if( m_pickerItem )
541  {
543  {
544  m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) );
545  m_statusPopup->SetText( _( "Item locked." ) );
546  m_statusPopup->PopupFor( 2000 );
547  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
548  return true;
549  }
550 
552  selectionTool->UnbrightenItem( m_pickerItem );
553  selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
555  m_pickerItem = nullptr;
556  }
557 
558  return true;
559  } );
560 
561  picker->SetMotionHandler(
562  [this]( const VECTOR2D& aPos )
563  {
564  BOARD* board = m_frame->GetBoard();
567  GENERAL_COLLECTOR collector;
568  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
569 
570  if( m_isFootprintEditor )
572  (wxPoint) aPos, guide );
573  else
575  (wxPoint) aPos, guide );
576 
577  // Remove unselectable items
578  for( int i = collector.GetCount() - 1; i >= 0; --i )
579  {
580  if( !selectionTool->Selectable( collector[ i ] ) )
581  collector.Remove( i );
582  }
583 
584  if( collector.GetCount() > 1 )
585  selectionTool->GuessSelectionCandidates( collector, aPos );
586 
587  BOARD_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
588 
589  if( m_pickerItem != item )
590  {
591 
592  if( m_pickerItem )
593  selectionTool->UnbrightenItem( m_pickerItem );
594 
595  m_pickerItem = item;
596 
597  if( m_pickerItem )
598  selectionTool->BrightenItem( m_pickerItem );
599  }
600  } );
601 
602  picker->SetFinalizeHandler(
603  [this]( const int& aFinalState )
604  {
605  if( m_pickerItem )
607 
608  m_statusPopup.reset();
609 
610  // Ensure the cursor gets changed&updated
612  m_frame->GetCanvas()->Refresh();
613  } );
614 
615  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
616 
617  return 0;
618 }
619 
620 
621 static void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBoard,
622  std::vector<BOARD_ITEM*>& aPastedItems )
623 {
624  FOOTPRINT* editorFootprint = aBoard->GetFirstFootprint();
625 
626  aClipFootprint->SetParent( aBoard );
627 
628  for( PAD* pad : aClipFootprint->Pads() )
629  {
630  pad->SetParent( editorFootprint );
631  aPastedItems.push_back( pad );
632  }
633 
634  aClipFootprint->Pads().clear();
635 
636  // Not all graphic items can be added to the current footprint:
637  // Reference and value are already existing in the current footprint, and
638  // must be unique.
639  // So they will be skipped
640  for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() )
641  {
642  if( item->Type() == PCB_FP_SHAPE_T )
643  {
644  FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
645 
646  shape->SetParent( nullptr );
647  shape->SetLocalCoord();
648  }
649  else if( item->Type() == PCB_FP_TEXT_T )
650  {
651  FP_TEXT* text = static_cast<FP_TEXT*>( item );
652 
653  if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
654  continue;
655 
656  text->SetTextAngle( text->GetTextAngle() + aClipFootprint->GetOrientation() );
657 
658  text->SetParent( nullptr );
659  text->SetLocalCoord();
660  }
661 
662  item->SetParent( editorFootprint );
663  aPastedItems.push_back( item );
664  }
665 
666  aClipFootprint->GraphicalItems().clear();
667 
668  for( FP_ZONE* zone : aClipFootprint->Zones() )
669  {
670  zone->SetParent( editorFootprint );
671  aPastedItems.push_back( zone );
672  }
673 
674  aClipFootprint->Zones().clear();
675 
676  for( PCB_GROUP* group : aClipFootprint->Groups() )
677  {
678  group->SetParent( editorFootprint );
679  aPastedItems.push_back( group );
680  }
681 
682  aClipFootprint->Groups().clear();
683 }
684 
685 
686 int PCB_CONTROL::Paste( const TOOL_EVENT& aEvent )
687 {
688  CLIPBOARD_IO pi;
689  BOARD_ITEM* clipItem = pi.Parse();
690 
691  if( !clipItem )
692  return 0;
693 
694  // The viewer frames cannot paste
695  if( !frame()->IsType( FRAME_FOOTPRINT_EDITOR ) && !frame()->IsType( FRAME_PCB_EDITOR ) )
696  return 0;
697 
699  const wxString defaultRef = wxT( "REF**" );
700 
701  if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
702  {
703  DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode, defaultRef );
704 
705  if( dlg.ShowModal() == wxID_CANCEL )
706  return 0;
707  }
708 
709  bool isFootprintEditor = m_isFootprintEditor || frame()->IsType( FRAME_FOOTPRINT_EDITOR );
710 
711  if( clipItem->Type() == PCB_T )
712  {
713  if( isFootprintEditor )
714  {
715  for( BOARD_CONNECTED_ITEM* item : static_cast<BOARD*>( clipItem )->AllConnectedItems() )
716  item->SetNet( NETINFO_LIST::OrphanedItem() );
717  }
718  else
719  {
720  static_cast<BOARD*>( clipItem )->MapNets( m_frame->GetBoard() );
721  }
722  }
723 
724  // The clipboard can contain two different things, an entire kicad_pcb or a single footprint
725  if( isFootprintEditor && ( !board() || !footprint() ) )
726  {
727  return 0;
728  }
729 
730  switch( clipItem->Type() )
731  {
732  case PCB_T:
733  {
734  BOARD* clipBoard = static_cast<BOARD*>( clipItem );
735 
736  if( isFootprintEditor )
737  {
738  FOOTPRINT* editorFootprint = board()->GetFirstFootprint();
739  std::vector<BOARD_ITEM*> pastedItems;
740 
741  for( FOOTPRINT* clipFootprint : clipBoard->Footprints() )
742  pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
743 
744  for( BOARD_ITEM* clipDrawItem : clipBoard->Drawings() )
745  {
746  if( clipDrawItem->Type() == PCB_SHAPE_T )
747  {
748  PCB_SHAPE* clipShape = static_cast<PCB_SHAPE*>( clipDrawItem );
749 
750  // Convert to PCB_FP_SHAPE_T
751  FP_SHAPE* pastedShape = new FP_SHAPE( editorFootprint );
752  static_cast<PCB_SHAPE*>( pastedShape )->SwapData( clipShape );
753  pastedShape->SetLocalCoord();
754 
755  // Replace parent nuked by above call to SwapData()
756  pastedShape->SetParent( editorFootprint );
757  pastedItems.push_back( pastedShape );
758  }
759  else if( clipDrawItem->Type() == PCB_TEXT_T )
760  {
761  PCB_TEXT* clipTextItem = static_cast<PCB_TEXT*>( clipDrawItem );
762 
763  // Convert to PCB_FP_TEXT_T
764  FP_TEXT* pastedTextItem = new FP_TEXT( editorFootprint );
765  static_cast<EDA_TEXT*>( pastedTextItem )->SwapText( *clipTextItem );
766  static_cast<EDA_TEXT*>( pastedTextItem )->SwapEffects( *clipTextItem );
767 
768  pastedTextItem->SetParent( editorFootprint );
769  pastedItems.push_back( pastedTextItem );
770  }
771  }
772 
773  delete clipBoard;
774 
775  placeBoardItems( pastedItems, true, true,
776  pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
777  }
778  else
779  {
780  if( pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS )
781  {
782  for( FOOTPRINT* clipFootprint : clipBoard->Footprints() )
783  clipFootprint->SetReference( defaultRef );
784  }
785 
786  placeBoardItems( clipBoard, true, pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
787 
789  m_frame->Compile_Ratsnest( true );
790  }
791 
792  break;
793  }
794 
795  case PCB_FOOTPRINT_T:
796  {
797  FOOTPRINT* clipFootprint = static_cast<FOOTPRINT*>( clipItem );
798  std::vector<BOARD_ITEM*> pastedItems;
799 
800  if( isFootprintEditor )
801  {
802  pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
803  delete clipFootprint;
804  }
805  else
806  {
807  if( pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS )
808  clipFootprint->SetReference( defaultRef );
809 
810  clipFootprint->SetParent( board() );
811  pastedItems.push_back( clipFootprint );
812  }
813 
814  placeBoardItems( pastedItems, true, true, pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
815  break;
816  }
817 
818  default:
819  m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) );
820  break;
821  }
822 
823  return 1;
824 }
825 
826 
828 {
829  int open_ctl;
830  wxString fileName;
831 
832  PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
833 
834  if( !editFrame )
835  return 1;
836 
837  // Pick a file to append
838  if( !AskLoadBoardFileName( editFrame, &open_ctl, &fileName, true ) )
839  return 1;
840 
841  IO_MGR::PCB_FILE_T pluginType = plugin_type( fileName, open_ctl );
842  PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
843 
844  return AppendBoard( *pi, fileName );
845 }
846 
847 
848 // Helper function for PCB_CONTROL::placeBoardItems()
849 template<typename T>
850 static void moveUnflaggedItems( std::deque<T>& aList, std::vector<BOARD_ITEM*>& aTarget,
851  bool aIsNew )
852 {
853  std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
854  [aIsNew]( T aItem )
855  {
856  bool doCopy = ( aItem->GetFlags() & SKIP_STRUCT ) == 0;
857 
858  aItem->ClearFlags( SKIP_STRUCT );
859  aItem->SetFlags( aIsNew ? IS_NEW : 0 );
860 
861  return doCopy;
862  } );
863 
864  if( aIsNew )
865  aList.clear();
866 }
867 
868 
869 static void moveUnflaggedItems( ZONES& aList, std::vector<BOARD_ITEM*>& aTarget, bool aIsNew )
870 {
871  if( aList.size() == 0 )
872  return;
873 
874  auto obj = aList.front();
875  int idx = 0;
876 
877  if( aIsNew )
878  {
879  obj = aList.back();
880  aList.pop_back();
881  }
882 
883  for( ; obj ; )
884  {
885  if( obj->HasFlag( SKIP_STRUCT ) )
886  obj->ClearFlags( SKIP_STRUCT );
887  else
888  aTarget.push_back( obj );
889 
890  if( aIsNew )
891  {
892  if( aList.size() )
893  {
894  obj = aList.back();
895  aList.pop_back();
896  }
897  else
898  {
899  obj = nullptr;
900  }
901  }
902  else
903  {
904  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
905  }
906  }
907 }
908 
909 
910 
911 int PCB_CONTROL::placeBoardItems( BOARD* aBoard, bool aAnchorAtOrigin, bool aReannotateDuplicates )
912 {
913  // items are new if the current board is not the board source
914  bool isNew = board() != aBoard;
915  std::vector<BOARD_ITEM*> items;
916 
917  moveUnflaggedItems( aBoard->Tracks(), items, isNew );
918  moveUnflaggedItems( aBoard->Footprints(), items, isNew );
919  moveUnflaggedItems( aBoard->Drawings(), items, isNew );
920  moveUnflaggedItems( aBoard->Zones(), items, isNew );
921 
922  // Subtlety: When selecting a group via the mouse,
923  // PCB_SELECTION_TOOL::highlightInternal runs, which does a SetSelected() on all
924  // descendants. In PCB_CONTROL::placeBoardItems, below, we skip that and
925  // mark items non-recursively. That works because the saving of the
926  // selection created aBoard that has the group and all descendants in it.
927  moveUnflaggedItems( aBoard->Groups(), items, isNew );
928 
929  return placeBoardItems( items, isNew, aAnchorAtOrigin, aReannotateDuplicates );
930 }
931 
932 
933 int PCB_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems, bool aIsNew,
934  bool aAnchorAtOrigin, bool aReannotateDuplicates )
935 {
937 
939  EDIT_TOOL* editTool = m_toolMgr->GetTool<EDIT_TOOL>();
940 
941  std::vector<BOARD_ITEM*> itemsToSel;
942  itemsToSel.reserve( aItems.size() );
943 
944  for( BOARD_ITEM* item : aItems )
945  {
946  if( aIsNew )
947  {
948  const_cast<KIID&>( item->m_Uuid ) = KIID();
949 
950  if( selectionTool->GetEnteredGroup() && !item->GetParentGroup() )
951  selectionTool->GetEnteredGroup()->AddItem( item );
952  }
953 
954  // Update item attributes if needed
955  switch( item->Type() )
956  {
957  case PCB_DIMENSION_T:
958  case PCB_DIM_ALIGNED_T:
959  case PCB_DIM_CENTER_T:
961  case PCB_DIM_LEADER_T:
962  {
963  // Dimensions need to have their units updated if they are automatic
964  PCB_DIMENSION_BASE* dim = static_cast<PCB_DIMENSION_BASE*>( item );
965 
967  dim->SetUnits( frame()->GetUserUnits() );
968 
969  break;
970  }
971 
972  case PCB_FOOTPRINT_T:
973  // Update the footprint path with the new KIID path if the footprint is new
974  if( aIsNew )
975  static_cast<FOOTPRINT*>( item )->SetPath( KIID_PATH() );
976 
977  break;
978 
979  default:
980  break;
981  }
982 
983  // We only need to add the items that aren't inside a group currently selected
984  // to the selection. If an item is inside a group and that group is selected,
985  // then the selection tool will select it for us.
986  if( !item->GetParentGroup() || !alg::contains( aItems, item->GetParentGroup() ) )
987  itemsToSel.push_back( item );
988  }
989 
990  // Select the items that should be selected
991  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &itemsToSel );
992 
993  // Reannotate duplicate footprints (make sense only in board editor )
994  if( aReannotateDuplicates && m_frame->IsType( FRAME_PCB_EDITOR ) )
996 
997  for( BOARD_ITEM* item : aItems )
998  {
999  // Commit after reannotation
1000  if( aIsNew )
1001  editTool->GetCurrentCommit()->Add( item );
1002  else
1003  editTool->GetCurrentCommit()->Added( item );
1004  }
1005 
1006  PCB_SELECTION& selection = selectionTool->GetSelection();
1007 
1008  if( selection.Size() > 0 )
1009  {
1010  if( aAnchorAtOrigin )
1011  {
1013  }
1014  else
1015  {
1016  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
1018  }
1019 
1020  getViewControls()->SetCursorPosition( getViewControls()->GetMousePosition(), false );
1021 
1024  }
1025 
1026  return 0;
1027 }
1028 
1029 
1030 int PCB_CONTROL::AppendBoard( PLUGIN& pi, wxString& fileName )
1031 {
1032  PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
1033 
1034  if( !editFrame )
1035  return 1;
1036 
1037  BOARD* brd = board();
1038 
1039  if( !brd )
1040  return 1;
1041 
1042  // Mark existing items, in order to know what are the new items so we can select only
1043  // the new items after loading
1044  for( PCB_TRACK* track : brd->Tracks() )
1045  track->SetFlags( SKIP_STRUCT );
1046 
1047  for( FOOTPRINT* footprint : brd->Footprints() )
1049 
1050  for( PCB_GROUP* group : brd->Groups() )
1051  group->SetFlags( SKIP_STRUCT );
1052 
1053  for( BOARD_ITEM* drawing : brd->Drawings() )
1054  drawing->SetFlags( SKIP_STRUCT );
1055 
1056  for( ZONE* zone : brd->Zones() )
1057  zone->SetFlags( SKIP_STRUCT );
1058 
1059  std::map<wxString, wxString> oldProperties = brd->GetProperties();
1060  std::map<wxString, wxString> newProperties;
1061 
1062  // Keep also the count of copper layers, to adjust if necessary
1063  int initialCopperLayerCount = brd->GetCopperLayerCount();
1064  LSET initialEnabledLayers = brd->GetEnabledLayers();
1065 
1066  // Load the data
1067  try
1068  {
1069  PROPERTIES props;
1070  char xbuf[30];
1071  char ybuf[30];
1072 
1073  // EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet.
1074  sprintf( xbuf, "%d", editFrame->GetPageSizeIU().x );
1075  sprintf( ybuf, "%d", editFrame->GetPageSizeIU().y );
1076 
1077  props["page_width"] = xbuf;
1078  props["page_height"] = ybuf;
1079 
1080  WX_PROGRESS_REPORTER progressReporter( editFrame, _( "Loading PCB" ), 1 );
1081 
1082  editFrame->GetDesignSettings().GetNetClasses().Clear();
1083  pi.Load( fileName, brd, &props, nullptr, &progressReporter );
1084  }
1085  catch( const IO_ERROR& ioe )
1086  {
1087  wxString msg = wxString::Format( _( "Error loading board.\n%s" ), ioe.What() );
1088  DisplayError( editFrame, msg );
1089 
1090  return 0;
1091  }
1092 
1093  newProperties = brd->GetProperties();
1094 
1095  for( const std::pair<const wxString, wxString>& prop : oldProperties )
1096  newProperties[ prop.first ] = prop.second;
1097 
1098  brd->SetProperties( newProperties );
1099 
1100  // rebuild nets and ratsnest before any use of nets
1101  brd->BuildListOfNets();
1103  brd->BuildConnectivity();
1104 
1105  // Synchronize layers
1106  // we should not ask PLUGINs to do these items:
1107  int copperLayerCount = brd->GetCopperLayerCount();
1108 
1109  if( copperLayerCount > initialCopperLayerCount )
1110  brd->SetCopperLayerCount( copperLayerCount );
1111 
1112  // Enable all used layers, and make them visible:
1113  LSET enabledLayers = brd->GetEnabledLayers();
1114  enabledLayers |= initialEnabledLayers;
1115  brd->SetEnabledLayers( enabledLayers );
1116  brd->SetVisibleLayers( enabledLayers );
1117 
1118  return placeBoardItems( brd, false, false ); // Do not reannotate duplicates on Append Board
1119 }
1120 
1121 
1122 int PCB_CONTROL::Undo( const TOOL_EVENT& aEvent )
1123 {
1124  PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
1125  wxCommandEvent dummy;
1126 
1127  if( editFrame )
1128  editFrame->RestoreCopyFromUndoList( dummy );
1129 
1130  return 0;
1131 }
1132 
1133 
1134 int PCB_CONTROL::Redo( const TOOL_EVENT& aEvent )
1135 {
1136  PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
1137  wxCommandEvent dummy;
1138 
1139  if( editFrame )
1140  editFrame->RestoreCopyFromRedoList( dummy );
1141 
1142  return 0;
1143 }
1144 
1145 
1147 {
1149  PCB_SELECTION& selection = selTool->GetSelection();
1150 
1151  if( selection.GetSize() == 1 )
1152  {
1153  EDA_ITEM* item = selection.Front();
1154  MSG_PANEL_ITEMS msgItems;
1155 
1156  item->GetMsgPanelInfo( m_frame, msgItems );
1157  m_frame->SetMsgPanel( msgItems );
1158  }
1159  else if( selection.GetSize() > 1 )
1160  {
1161  MSG_PANEL_ITEMS msgItems;
1162  wxString msg = wxString::Format( wxT( "%d" ), selection.GetSize() );
1163 
1164  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Selected Items" ), msg ) );
1165  m_frame->SetMsgPanel( msgItems );
1166  }
1167  else if( auto editFrame = dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
1168  {
1169  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( editFrame->GetModel() );
1170 
1171  if( !footprint )
1172  return 0;
1173 
1174  MSG_PANEL_ITEMS msgItems;
1175  wxString msg;
1176 
1177  msg = footprint->GetFPID().GetLibNickname().wx_str();
1178  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Library" ), msg ) );
1179 
1180  msg = footprint->GetFPID().GetLibItemName().wx_str();
1181  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Footprint Name" ), msg ) );
1182 
1183  wxDateTime date( static_cast<time_t>( footprint->GetLastEditTime() ) );
1184 
1185  if( footprint->GetLastEditTime() && date.IsValid() )
1186  // Date format: see http://www.cplusplus.com/reference/ctime/strftime
1187  msg = date.Format( wxT( "%b %d, %Y" ) ); // Abbreviated_month_name Day, Year
1188  else
1189  msg = _( "Unknown" );
1190 
1191  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Last Change" ), msg ) );
1192 
1193  msg.Printf( wxT( "%zu" ), (size_t) footprint->GetPadCount( DO_NOT_INCLUDE_NPTH ) );
1194  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Pads" ), msg ) );
1195 
1196  wxString doc, keyword;
1197  doc.Printf( _( "Doc: %s" ), footprint->GetDescription() );
1198  keyword.Printf( _( "Keywords: %s" ), footprint->GetKeywords() );
1199  msgItems.emplace_back( MSG_PANEL_ITEM( doc, keyword ) );
1200 
1201  m_frame->SetMsgPanel( msgItems );
1202  }
1203  else
1204  {
1206  }
1207 
1208  return 0;
1209 }
1210 
1211 
1213 {
1214  view()->SetMirror( !view()->IsMirroredX(), false );
1215  view()->RecacheAllItems();
1216  frame()->GetCanvas()->ForceRefresh();
1218  return 0;
1219 }
1220 
1221 
1223 {
1226  Go( &PCB_CONTROL::Print, ACTIONS::print.MakeEvent() );
1227  Go( &PCB_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
1228 
1229  // Display modes
1242 
1243  // Layer control
1281 
1282  // Grid control
1285 
1286  Go( &PCB_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
1287  Go( &PCB_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
1288 
1289  // Miscellaneous
1291 
1292  // Append control
1294 
1295  Go( &PCB_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
1296  Go( &PCB_CONTROL::Paste, ACTIONS::pasteSpecial.MakeEvent() );
1297 
1302 }
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: pcb_actions.h:66
void SetReference(const wxString &aReference)
Definition: footprint.h:439
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
std::vector< ZONE * > ZONES
Definition: eagle_plugin.h:44
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:91
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:271
static TOOL_ACTION layerBottom
Definition: pcb_actions.h:282
BOARD_ITEM * Parse()
static TOOL_ACTION layerInner26
Definition: pcb_actions.h:277
int ZoneDisplayMode(const TOOL_EVENT &aEvent)
void RestoreCopyFromUndoList(wxCommandEvent &aEvent)
Undo the last edit:
Definition: undo_redo.cpp:315
void BuildListOfNets()
Definition: board.h:663
bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:38
void SetUnits(EDA_UNITS aUnits)
static const KICAD_T FootprintItems[]
A scan list for primary footprint items.
Definition: collectors.h:293
static const KICAD_T BoardLevelItems[]
A scan list for all primary board items, omitting items which are subordinate to a FOOTPRINT,...
Definition: collectors.h:278
const wxString & GetDescription() const
Definition: footprint.h:197
int GridSetOrigin(const TOOL_EVENT &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
const UTF8 & GetLibItemName() const
Definition: lib_id.h:104
void AddButton(wxButton *aButton)
Add an already created button to the infobar.
Definition: infobar.cpp:245
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:92
int m_Threshold
Definition: collector.h:248
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:100
void ForceRefresh()
Force a redraw.
static TOOL_ACTION layerNext
Definition: pcb_actions.h:283
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
Definition: typeinfo.h:84
static TOOL_ACTION layerInner2
Definition: pcb_actions.h:253
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
wxPoint m_GridOrigin
origin for grid offsets
BOARD_ITEM * m_pickerItem
Definition: pcb_control.h:132
ZONES & Zones()
Definition: board.h:239
static NETINFO_ITEM * OrphanedItem()
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:373
BOARD * board() const
int LayerAlphaDec(const TOOL_EVENT &aEvent)
unsigned GetPadCount(INCLUDE_NPTH_T aIncludeNPTH=INCLUDE_NPTH_T(INCLUDE_NPTH)) const
Return the number of pads.
Definition: footprint.cpp:1067
static TOOL_ACTION layerInner5
Definition: pcb_actions.h:256
int GetUserUnits()
Return the currently selected user unit value for the interface.
int Redo(const TOOL_EVENT &aEvent)
Model changes (required full reload)
Definition: tool_base.h:80
int LayerNext(const TOOL_EVENT &aEvent)
static const TOOL_EVENT UnselectedEvent
Definition: actions.h:200
#define IS_NEW
New item, just created.
void Compile_Ratsnest(bool aDisplayStatus)
Create the entire board ratsnest.
Definition: ratsnest.cpp:40
virtual void OnDisplayOptionsChanged()
This file is part of the common library.
static TOOL_ACTION doDelete
Definition: actions.h:72
PCB_BASE_FRAME * m_frame
Grid origin marker.
Definition: pcb_control.h:127
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:253
static TOOL_ACTION layerInner6
Definition: pcb_actions.h:257
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:303
static TOOL_ACTION layerInner7
Definition: pcb_actions.h:258
static TOOL_ACTION layerInner8
Definition: pcb_actions.h:259
void SetProperties(const std::map< wxString, wxString > &aProps)
Definition: board.h:259
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Load information from some input file format that this PLUGIN implementation knows about into either ...
Definition: plugin.cpp:46
static TOOL_ACTION layerInner21
Definition: pcb_actions.h:272
GROUPS & Groups()
The groups must maintain the following invariants.
Definition: board.h:253
static TOOL_ACTION ratsnestLineMode
Definition: pcb_actions.h:239
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
static TOOL_ACTION layerAlphaDec
Definition: pcb_actions.h:286
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:571
static TOOL_ACTION gridResetOrigin
Definition: actions.h:138
int LayerAlphaInc(const TOOL_EVENT &aEvent)
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:102
Extension of STATUS_POPUP for displaying a single line text.
Definition: status_popup.h:79
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
void RecacheAllItems()
Rebuild GAL display lists.
Definition: view.cpp:1395
static TOOL_ACTION layerAlphaInc
Definition: pcb_actions.h:285
int placeBoardItems(std::vector< BOARD_ITEM * > &aItems, bool aIsNew, bool aAnchorAtOrigin, bool aReannotateDuplicates)
Add and select or just select for move/place command a list of board items.
void Flip(T &aValue)
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:353
#define ALPHA_MIN
double GetOrientation() const
Definition: footprint.h:190
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
void SetCopperLayerCount(int aCount)
Definition: board.cpp:460
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
int LAYER_NUM
This can be replaced with int and removed.
Definition: layer_ids.h:40
void SetColor(int aLayer, const COLOR4D &aColor)
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:190
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.
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
Definition: pcb_control.cpp:85
Abstract dimension API.
Definition: pcb_dimension.h:95
PCB_GROUP * GetEnteredGroup()
LSET GetEnabledLayers() const
A proxy function that calls the corresponding function in m_BoardSettings.
Definition: board.cpp:466
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
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.
Definition: infobar.cpp:128
#define ZONE_LAYER_FOR(copperLayer)
Macro for getting the zone layer for a given copper layer.
Definition: layer_ids.h:251
static TOOL_ACTION print
Definition: actions.h:57
virtual wxPoint GetPosition() const
Definition: eda_item.h:252
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
Definition: view.cpp:542
static TOOL_ACTION zoneDisplayFilled
Definition: pcb_actions.h:243
void SetGridOrigin(const VECTOR2D &aGridOrigin)
Set the origin point for the grid.
A name/value tuple with unique names and optional values.
Definition: properties.h:33
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
virtual bool IsLocked() const
Definition: board_item.cpp:78
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:106
static TOOL_ACTION layerInner3
Definition: pcb_actions.h:254
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
static TOOL_ACTION layerInner24
Definition: pcb_actions.h:275
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).
static TOOL_ACTION layerInner11
Definition: pcb_actions.h:262
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:115
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:204
timestamp_t GetLastEditTime() const
Definition: footprint.h:336
void RedrawRatsnest()
Return the bounding box of the view that should be used if model is not valid.
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PADS & Pads()
Definition: footprint.h:168
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
static TOOL_ACTION layerTop
Definition: pcb_actions.h:251
DIM_UNITS_MODE GetUnitsMode() const
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
Definition: layer_ids.h:932
static TOOL_ACTION pickerTool
Definition: actions.h:155
int Undo(const TOOL_EVENT &aEvent)
PCB_BASE_EDIT_FRAME * frame() const
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:72
virtual COLOR_SETTINGS * GetColorSettings() const override
Helper to retrieve the current color settings.
Releases a PLUGIN in the context of a potential thrown exception through its destructor.
Definition: io_mgr.h:555
virtual PCB_LAYER_ID GetActiveLayer() const
#define HITTEST_THRESHOLD_PIXELS
const std::map< wxString, wxString > & GetProperties() const
Definition: board.h:258
static TOOL_ACTION layerInner23
Definition: pcb_actions.h:274
void setTransitions() override
< Sets up handlers for various events.
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:87
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1410
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
FP_ZONES & Zones()
Definition: footprint.h:174
void UnbrightenItem(BOARD_ITEM *aItem)
Definition: kiid.h:44
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:186
static TOOL_ACTION appendBoard
Definition: pcb_actions.h:438
static TOOL_ACTION zoneDisplayToggle
Definition: pcb_actions.h:247
static TOOL_ACTION zoneDisplayFractured
Definition: pcb_actions.h:245
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Updates the current display options from the given options struct.
Container for display options like enable/disable some optional drawings.
Inactive layers are dimmed (old high-contrast mode)
void Dismiss() override
Dismisses the infobar and updates the containing layout and AUI manager (if one is provided).
Definition: infobar.cpp:175
double a
Alpha component.
Definition: color4d.h:374
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:92
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
Item needs to be redrawn.
Definition: view_item.h:57
Multi-thread safe progress reporter dialog, intended for use of tasks that parallel reporting back of...
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:502
static TOOL_ACTION layerInner13
Definition: pcb_actions.h:264
const PCB_SELECTION & selection() const
static TOOL_ACTION layerPrev
Definition: pcb_actions.h:284
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:317
VECTOR2< double > VECTOR2D
Definition: vector2d.h:622
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
static void DoSetGridOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, EDA_ITEM *originViewItem, const VECTOR2D &aPoint)
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
void SetVisibleLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings changes the bit-mask of vis...
Definition: board.cpp:498
static TOOL_ACTION layerInner25
Definition: pcb_actions.h:276
static TOOL_ACTION layerInner18
Definition: pcb_actions.h:269
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:214
void AddItemToSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Select all items on the board.
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
FOOTPRINTS & Footprints()
Definition: board.h:233
Generic, UI-independent tool event.
Definition: tool_event.h:152
Inactive layers are shown normally (no high-contrast mode)
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:82
#define ALPHA_MAX
FOOTPRINT * footprint() const
static TOOL_ACTION layerInner30
Definition: pcb_actions.h:281
KIGFX::PCB_VIEW * view() const
int GridResetOrigin(const TOOL_EVENT &aEvent)
static TOOL_ACTION layerInner29
Definition: pcb_actions.h:280
int DeleteItemCursor(const TOOL_EVENT &aEvent)
static TOOL_ACTION showRatsnest
Definition: pcb_actions.h:238
bool Selectable(const BOARD_ITEM *aItem, bool checkVisibilityOnly=false) const
Check conditions for an item to be selected.
static TOOL_ACTION addLibrary
Definition: actions.h:49
static TOOL_ACTION quit
Definition: actions.h:59
PCB_LAYER_ID m_Route_Layer_BOTTOM
Definition: pcb_screen.h:44
#define _(s)
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition: lib_id.h:90
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
static TOOL_ACTION layerInner10
Definition: pcb_actions.h:261
EDA_ITEM * GetTopLeftItem(bool aFootprintsOnly=false) const override
static const TOOL_EVENT ClearedEvent
Selected item had a property changed (except movement)
Definition: actions.h:201
DRAWINGS & GraphicalItems()
Definition: footprint.h:171
void BrightenItem(BOARD_ITEM *aItem)
NETCLASSES & GetNetClasses() const
const LIB_ID & GetFPID() const
Definition: footprint.h:194
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
void BuildConnectivity()
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:136
static void moveUnflaggedItems(std::deque< T > &aList, std::vector< BOARD_ITEM * > &aTarget, bool aIsNew)
static TOOL_ACTION zoneDisplayTriangulated
Definition: pcb_actions.h:246
void unfilledZoneCheck()
We have bug reports indicating that some new users confuse zone filling/unfilling with the display mo...
virtual COLOR4D GetGridColor()
int HighContrastMode(const TOOL_EVENT &aEvent)
class PCB_DIMENSION_BASE: abstract dimension meta-type
Definition: typeinfo.h:99
const wxString & GetKeywords() const
Definition: footprint.h:200
bool m_isFootprintEditor
static TOOL_ACTION layerInner15
Definition: pcb_actions.h:266
The interactive edit tool.
Definition: edit_tool.h:64
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
static TOOL_ACTION newLibrary
Definition: actions.h:48
static TOOL_ACTION layerInner28
Definition: pcb_actions.h:279
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
Definition: infobar.cpp:286
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
static TOOL_ACTION layerInner27
Definition: pcb_actions.h:278
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
Definition: layer_ids.h:787
void UpdateColors()
Update the color settings in the painter and GAL.
void SetCursor(KICURSOR aCursor)
Definition: picker_tool.h:62
const PCB_DISPLAY_OPTIONS & displayOptions() const
Generic tool for picking an item.
static TOOL_ACTION layerInner17
Definition: pcb_actions.h:268
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
static TOOL_ACTION zoneDisplayOutline
Definition: pcb_actions.h:244
virtual void SwitchLayer(wxDC *DC, PCB_LAYER_ID layer)
static TOOL_ACTION layerInner20
Definition: pcb_actions.h:271
static TOOL_ACTION pasteSpecial
Definition: actions.h:69
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:87
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
static TOOL_ACTION viaDisplayMode
Definition: pcb_actions.h:242
void UpdateLayerColor(int aLayer)
Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
Definition: view.cpp:754
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
FP_GROUPS & Groups()
Definition: footprint.h:177
int Quit(const TOOL_EVENT &aEvent)
A modified version of the wxInfoBar class that allows us to:
Definition: infobar.h:73
static TOOL_ACTION redo
Definition: actions.h:65
#define ALPHA_STEP
COLOR4D GetColor(int aLayer) const
static TOOL_ACTION layerInner22
Definition: pcb_actions.h:273
virtual void OnModify()
Must be called after a change in order to set the "modify" flag of the current screen and update the ...
int LayerSwitch(const TOOL_EVENT &aEvent)
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:472
int Print(const TOOL_EVENT &aEvent)
int Paste(const TOOL_EVENT &aEvent)
int AppendBoard(PLUGIN &pi, wxString &fileName)
void Clear()
Destroy any contained NETCLASS instances except the default one, and clears any members from the defa...
Definition: netclass.h:228
see class PGM_BASE
static void pasteFootprintItemsToFootprintEditor(FOOTPRINT *aClipFootprint, BOARD *aBoard, std::vector< BOARD_ITEM * > &aPastedItems)
#define SKIP_STRUCT
flag indicating that the structure should be ignored
bool IsType(FRAME_T aType) const
Common, abstract interface for edit frames.
bool AskLoadBoardFileName(PCB_EDIT_FRAME *aParent, int *aCtl, wxString *aFileName, bool aKicadFilesOnly=false)
Show a wxFileDialog asking for a BOARD filename to open.
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
int FlipPcbView(const TOOL_EVENT &aEvent)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:64
static PLUGIN * PluginFind(PCB_FILE_T aFileType)
Return a PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: io_mgr.cpp:58
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition: pcb_control.h:134
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
void RestoreCopyFromRedoList(wxCommandEvent &aEvent)
Redo the last edit:
Definition: undo_redo.cpp:345
Definition: layer_ids.h:70
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:269
static TOOL_ACTION layerInner14
Definition: pcb_actions.h:265
static TOOL_ACTION layerInner9
Definition: pcb_actions.h:260
int HighContrastModeCycle(const TOOL_EVENT &aEvent)
int GetCopperLayerCount() const
Definition: board.cpp:454
std::unique_ptr< KIGFX::ORIGIN_VIEWITEM > m_gridOrigin
Definition: pcb_control.h:130
wxString wx_str() const
Definition: utf8.cpp:46
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
ZONE_DISPLAY_MODE m_ZoneDisplayMode
The main frame for Pcbnew.
int Size() const
Returns the number of selected parts.
Definition: selection.h:103
The selection tool: currently supports:
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
PCB_SCREEN * GetScreen() const override
Return a pointer to a BASE_SCREEN or one of its derivatives.
virtual void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand)=0
Create a new entry in undo list of commands.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:97
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
static TOOL_ACTION layerInner16
Definition: pcb_actions.h:267
int AddLibrary(const TOOL_EVENT &aEvent)
Definition: pcb_control.cpp:99
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
int LayerPrev(const TOOL_EVENT &aEvent)
void Activate()
Run the tool.
Color settings are a bit different than most of the settings objects in that there can be more than o...
WX_INFOBAR * GetInfoBar()
static TOOL_ACTION deleteTool
Definition: actions.h:73
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
static TOOL_ACTION highContrastModeCycle
Definition: actions.h:104
void SetLocalCoord()
Set relative coordinates from draw coordinates.
Definition: fp_shape.cpp:54
static TOOL_ACTION layerInner4
Definition: pcb_actions.h:255
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
static TOOL_ACTION undo
Definition: actions.h:64
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:323
int ToggleRatsnest(const TOOL_EVENT &aEvent)
Inactive layers are hidden.
static TOOL_ACTION flipBoard
Definition: pcb_actions.h:291
BOARD * GetBoard() const
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
static TOOL_ACTION gridSetOrigin
Definition: actions.h:137
EDA_MSG_PANEL items for displaying messages.
Definition: msgpanel.h:53
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:377
static TOOL_ACTION layerInner19
Definition: pcb_actions.h:270
Definition: pad.h:57
int LayerToggle(const TOOL_EVENT &aEvent)
PCB_DRAW_PANEL_GAL * canvas() const
PCB_FILE_T
The set of file types that the IO_MGR knows about, and for which there has been a plugin written.
Definition: io_mgr.h:53
static TOOL_ACTION layerInner1
Definition: pcb_actions.h:252
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...
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
static TOOL_ACTION highContrastMode
Definition: actions.h:103
Rendering engine changes.
Definition: tool_base.h:81
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:75
DRAWINGS & Drawings()
Definition: board.h:236
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:905
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:486
static TOOL_ACTION paste
Definition: actions.h:68
A specialization of ZONE for use in footprints.
Definition: zone.h:946
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int AppendBoardFromFile(const TOOL_EVENT &aEvent)
TRACKS & Tracks()
Definition: board.h:230
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:633
static TOOL_ACTION trackDisplayMode
Definition: pcb_actions.h:240
PCB_LAYER_ID m_Route_Layer_TOP
Definition: pcb_screen.h:43
int TrackDisplayMode(const TOOL_EVENT &aEvent)
EDA_ITEM * Front() const
Definition: selection.h:144
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
void DisplayToolMsg(const wxString &msg) override
static TOOL_ACTION layerInner12
Definition: pcb_actions.h:263
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:113
IO_MGR::PCB_FILE_T plugin_type(const wxString &aFileName, int aCtl)
static TOOL_ACTION layerToggle
Definition: pcb_actions.h:287
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
int ViaDisplayMode(const TOOL_EVENT &aEvent)