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 <[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, 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 <tools/edit_tool.h>
27 #include <router/router_tool.h>
28 #include <pgm_base.h>
29 #include <tools/pcb_actions.h>
30 #include <tools/pcb_control.h>
31 #include <tools/pcb_picker_tool.h>
35 #include <bitmaps.h>
36 #include <board_commit.h>
37 #include <board.h>
38 #include <board_design_settings.h>
39 #include <board_item.h>
41 #include <pcb_dimension.h>
42 #include <footprint.h>
43 #include <pcb_group.h>
44 #include <pcb_track.h>
45 #include <zone.h>
46 #include <fp_shape.h>
47 #include <confirm.h>
49 #include <core/kicad_algo.h>
50 #include <kicad_clipboard.h>
51 #include <origin_viewitem.h>
52 #include <pcb_edit_frame.h>
53 #include <pcb_painter.h>
54 #include <properties.h>
56 #include <tool/tool_manager.h>
57 #include <footprint_viewer_frame.h>
58 #include <footprint_edit_frame.h>
60 #include <widgets/infobar.h>
61 #include <wx/hyperlink.h>
62 
63 using namespace std::placeholders;
64 
65 
66 // files.cpp
67 extern bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, int* aCtl, wxString* aFileName,
68  bool aKicadFilesOnly = false );
69 extern IO_MGR::PCB_FILE_T plugin_type( const wxString& aFileName, int aCtl );
70 
71 
73  PCB_TOOL_BASE( "pcbnew.Control" ),
74  m_frame( nullptr ),
75  m_pickerItem( nullptr )
76 {
77  m_gridOrigin.reset( new KIGFX::ORIGIN_VIEWITEM() );
78 }
79 
80 
82 {
83 }
84 
85 
87 {
88  m_frame = getEditFrame<PCB_BASE_FRAME>();
89 
90  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
91  {
92  m_gridOrigin->SetPosition( board()->GetDesignSettings().GetGridOrigin() );
93  m_gridOrigin->SetColor( m_frame->GetGridColor() );
94  getView()->Remove( m_gridOrigin.get() );
95  getView()->Add( m_gridOrigin.get() );
96  }
97 }
98 
99 
101 {
103  {
104  if( aEvent.IsAction( &ACTIONS::newLibrary ) )
105  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->CreateNewLibrary();
106  else if( aEvent.IsAction( &ACTIONS::addLibrary ) )
107  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->AddLibrary();
108  }
109 
110  return 0;
111 }
112 
113 
114 int PCB_CONTROL::Quit( const TOOL_EVENT& aEvent )
115 {
116  m_frame->Close( false );
117  return 0;
118 }
119 
120 
121 template<class T> void Flip( T& aValue )
122 {
123  aValue = !aValue;
124 }
125 
126 
128 {
130 
131  Flip( opts.m_DisplayPcbTrackFill );
132  m_frame->SetDisplayOptions( opts );
133 
134  for( PCB_TRACK* track : board()->Tracks() )
135  {
136  if( track->Type() == PCB_TRACE_T || track->Type() == PCB_ARC_T )
137  view()->Update( track, KIGFX::REPAINT );
138  }
139 
140  canvas()->Refresh();
141 
142  return 0;
143 }
144 
145 
147 {
149 
150  if( aEvent.IsAction( &PCB_ACTIONS::showRatsnest ) )
151  {
152  // N.B. Do not disable the Ratsnest layer here. We use it for local ratsnest
153  Flip( opts.m_ShowGlobalRatsnest );
154  m_frame->SetDisplayOptions( opts );
155  getEditFrame<PCB_EDIT_FRAME>()->SetElementVisibility( LAYER_RATSNEST,
156  opts.m_ShowGlobalRatsnest );
157 
158  }
159  else if( aEvent.IsAction( &PCB_ACTIONS::ratsnestLineMode ) )
160  {
162  m_frame->SetDisplayOptions( opts );
163  }
164 
165  canvas()->RedrawRatsnest();
166  canvas()->Refresh();
167 
168  return 0;
169 }
170 
171 
173 {
175 
176  Flip( opts.m_DisplayViaFill );
177  m_frame->SetDisplayOptions( opts );
178 
179  for( PCB_TRACK* track : board()->Tracks() )
180  {
181  if( track->Type() == PCB_TRACE_T || track->Type() == PCB_VIA_T )
182  view()->Update( track, KIGFX::REPAINT );
183  }
184 
185  canvas()->Refresh();
186 
187  return 0;
188 }
189 
190 
197 {
198  if( Pgm().GetCommonSettings()->m_DoNotShowAgain.zone_fill_warning )
199  return;
200 
201  bool unfilledZones = false;
202 
203  for( const ZONE* zone : board()->Zones() )
204  {
205  if( !zone->GetIsRuleArea() && !zone->IsFilled() )
206  {
207  unfilledZones = true;
208  break;
209  }
210  }
211 
212  if( unfilledZones )
213  {
214  WX_INFOBAR* infobar = frame()->GetInfoBar();
215  wxHyperlinkCtrl* button = new wxHyperlinkCtrl( infobar, wxID_ANY, _( "Don't show again" ),
216  wxEmptyString );
217 
218  button->Bind( wxEVT_COMMAND_HYPERLINK, std::function<void( wxHyperlinkEvent& aEvent )>(
219  [&]( wxHyperlinkEvent& aEvent )
220  {
221  Pgm().GetCommonSettings()->m_DoNotShowAgain.zone_fill_warning = true;
222  frame()->GetInfoBar()->Dismiss();
223  } ) );
224 
225  infobar->RemoveAllButtons();
226  infobar->AddButton( button );
227 
228  wxString msg;
229  msg.Printf( _( "Not all zones are filled. Use Edit > Fill All Zones (%s) "
230  "if you wish to see all fills." ),
232 
233  infobar->ShowMessageFor( msg, 5000, wxICON_WARNING );
234  }
235 }
236 
237 
239 {
241 
242  // Apply new display options to the GAL canvas
244  {
246 
248  }
249  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayOutline ) )
250  {
252  }
253  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayFractured ) )
254  {
256  }
257  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayTriangulated ) )
258  {
260  }
261  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayToggle ) )
262  {
265  else
267  }
268  else
269  {
270  wxFAIL;
271  }
272 
273  m_frame->SetDisplayOptions( opts );
274 
275  for( ZONE* zone : board()->Zones() )
276  view()->Update( zone, KIGFX::REPAINT );
277 
278  canvas()->Refresh();
279 
280  return 0;
281 }
282 
283 
285 {
287 
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 {
318 
319  switch( opts.m_NetColorMode )
320  {
324  }
325 
326  m_frame->SetDisplayOptions( opts );
327 
328  return 0;
329 }
330 
331 
333 {
335 
336  if( !opts.m_ShowGlobalRatsnest )
337  {
338  opts.m_ShowGlobalRatsnest = true;
340  }
341  else if( opts.m_RatsnestMode == RATSNEST_MODE::ALL )
342  {
344  }
345  else
346  {
347  opts.m_ShowGlobalRatsnest = false;
348  }
349 
350  m_frame->SetDisplayOptions( opts );
351 
352  return 0;
353 }
354 
355 
357 {
359 
360  return 0;
361 }
362 
363 
364 int PCB_CONTROL::LayerNext( const TOOL_EVENT& aEvent )
365 {
366  PCB_BASE_FRAME* editFrame = m_frame;
367  BOARD* brd = board();
368  LAYER_NUM layer = editFrame->GetActiveLayer();
369  LAYER_NUM startLayer = layer;
370 
371  if( layer < F_Cu || layer > B_Cu )
372  return 0;
373 
374  while( startLayer != ++layer )
375  {
376  if( brd->IsLayerVisible( static_cast<PCB_LAYER_ID>( layer ) ) && IsCopperLayer( layer ) )
377  break;
378 
379  if( layer >= B_Cu )
380  layer = F_Cu - 1;
381  }
382 
383  wxCHECK( IsCopperLayer( layer ), 0 );
384  editFrame->SwitchLayer( ToLAYER_ID( layer ) );
385 
386  return 0;
387 }
388 
389 
390 int PCB_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
391 {
392  PCB_BASE_FRAME* editFrame = m_frame;
393  BOARD* brd = board();
394  LAYER_NUM layer = editFrame->GetActiveLayer();
395  LAYER_NUM startLayer = layer;
396 
397  if( layer < F_Cu || layer > B_Cu )
398  return 0;
399 
400  while( startLayer != --layer )
401  {
402  if( IsCopperLayer( layer ) // also test for valid layer id (layer >= F_Cu)
403  && brd->IsLayerVisible( static_cast<PCB_LAYER_ID>( layer ) ) )
404  {
405  break;
406  }
407 
408  if( layer <= F_Cu )
409  layer = B_Cu + 1;
410  }
411 
412 
413  wxCHECK( IsCopperLayer( layer ), 0 );
414  editFrame->SwitchLayer( ToLAYER_ID( layer ) );
415 
416  return 0;
417 }
418 
419 
421 {
422  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
423  PCB_SCREEN* screen = m_frame->GetScreen();
424 
425  if( currentLayer == screen->m_Route_Layer_TOP )
427  else
429 
430  return 0;
431 }
432 
433 
434 // It'd be nice to share the min/max with the DIALOG_COLOR_PICKER, but those are
435 // set in wxFormBuilder.
436 #define ALPHA_MIN 0.20
437 #define ALPHA_MAX 1.00
438 #define ALPHA_STEP 0.05
439 
440 
442 {
443  COLOR_SETTINGS* settings = m_frame->GetColorSettings();
444  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
445  KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
446 
447  if( currentColor.a <= ALPHA_MAX - ALPHA_STEP )
448  {
449  currentColor.a += ALPHA_STEP;
450  settings->SetColor( currentLayer, currentColor );
452 
454  view->UpdateLayerColor( currentLayer );
455  view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
456 
457  if( IsCopperLayer( currentLayer ) )
458  view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
459 
460  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->OnLayerAlphaChanged();
461  }
462  else
463  {
464  wxBell();
465  }
466 
467  return 0;
468 }
469 
470 
472 {
473  COLOR_SETTINGS* settings = m_frame->GetColorSettings();
474  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
475  KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
476 
477  if( currentColor.a >= ALPHA_MIN + ALPHA_STEP )
478  {
479  currentColor.a -= ALPHA_STEP;
480  settings->SetColor( currentLayer, currentColor );
482 
484  view->UpdateLayerColor( currentLayer );
485  view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
486 
487  if( IsCopperLayer( currentLayer ) )
488  view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
489 
490  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->OnLayerAlphaChanged();
491  }
492  else
493  {
494  wxBell();
495  }
496 
497  return 0;
498 }
499 
500 
502  EDA_ITEM* originViewItem, const VECTOR2D& aPoint )
503 {
504  aFrame->GetDesignSettings().SetGridOrigin( wxPoint( aPoint ) );
505  aView->GetGAL()->SetGridOrigin( aPoint );
506  originViewItem->SetPosition( (wxPoint) aPoint );
507  aView->MarkDirty();
508  aFrame->OnModify();
509 }
510 
511 
513 {
514  VECTOR2D* origin = aEvent.Parameter<VECTOR2D*>();
515 
516  if( origin )
517  {
518  // We can't undo the other grid dialog settings, so no sense undoing just the origin
519  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), *origin );
520  delete origin;
521  }
522  else
523  {
524  if( m_isFootprintEditor && !getEditFrame<PCB_BASE_EDIT_FRAME>()->GetModel() )
525  return 0;
526 
527  std::string tool = aEvent.GetCommandStr().get();
529 
530  if( !picker ) // Happens in footprint wizard
531  return 0;
532 
533  // Deactivate other tools; particularly important if another PICKER is currently running
534  Activate();
535 
536  picker->SetClickHandler(
537  [this]( const VECTOR2D& pt ) -> bool
538  {
540  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), pt );
541  return false; // drill origin is a one-shot; don't continue with tool
542  } );
543 
544  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
545  }
546 
547  return 0;
548 }
549 
550 
552 {
554  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), VECTOR2D( 0, 0 ) );
555  return 0;
556 }
557 
558 
559 #define HITTEST_THRESHOLD_PIXELS 5
560 
561 
563 {
565  return 0;
566 
567  std::string tool = aEvent.GetCommandStr().get();
569 
570  m_pickerItem = nullptr;
572 
573  // Deactivate other tools; particularly important if another PICKER is currently running
574  Activate();
575 
576  picker->SetCursor( KICURSOR::REMOVE );
577 
578  picker->SetClickHandler(
579  [this]( const VECTOR2D& aPosition ) -> bool
580  {
581  if( m_pickerItem )
582  {
584  {
585  m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) );
586  m_statusPopup->SetText( _( "Item locked." ) );
587  m_statusPopup->PopupFor( 2000 );
588  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
589  return true;
590  }
591 
593  selectionTool->UnbrightenItem( m_pickerItem );
594  selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
596  m_pickerItem = nullptr;
597  }
598 
599  return true;
600  } );
601 
602  picker->SetMotionHandler(
603  [this]( const VECTOR2D& aPos )
604  {
605  BOARD* board = m_frame->GetBoard();
608  GENERAL_COLLECTOR collector;
609  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
610 
611  if( m_isFootprintEditor )
613  (wxPoint) aPos, guide );
614  else
616  (wxPoint) aPos, guide );
617 
618  // Remove unselectable items
619  for( int i = collector.GetCount() - 1; i >= 0; --i )
620  {
621  if( !selectionTool->Selectable( collector[ i ] ) )
622  collector.Remove( i );
623  }
624 
625  if( collector.GetCount() > 1 )
626  selectionTool->GuessSelectionCandidates( collector, aPos );
627 
628  BOARD_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
629 
630  if( m_pickerItem != item )
631  {
632 
633  if( m_pickerItem )
634  selectionTool->UnbrightenItem( m_pickerItem );
635 
636  m_pickerItem = item;
637 
638  if( m_pickerItem )
639  selectionTool->BrightenItem( m_pickerItem );
640  }
641  } );
642 
643  picker->SetFinalizeHandler(
644  [this]( const int& aFinalState )
645  {
646  if( m_pickerItem )
648 
649  m_statusPopup.reset();
650 
651  // Ensure the cursor gets changed&updated
653  m_frame->GetCanvas()->Refresh();
654  } );
655 
656  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
657 
658  return 0;
659 }
660 
661 
662 static void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBoard,
663  std::vector<BOARD_ITEM*>& aPastedItems )
664 {
665  FOOTPRINT* editorFootprint = aBoard->GetFirstFootprint();
666 
667  aClipFootprint->SetParent( aBoard );
668 
669  for( PAD* pad : aClipFootprint->Pads() )
670  {
671  pad->SetParent( editorFootprint );
672  aPastedItems.push_back( pad );
673  }
674 
675  aClipFootprint->Pads().clear();
676 
677  // Not all graphic items can be added to the current footprint:
678  // Reference and value are already existing in the current footprint, and
679  // must be unique.
680  // So they will be skipped
681  for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() )
682  {
683  if( item->Type() == PCB_FP_SHAPE_T )
684  {
685  FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
686 
687  shape->SetParent( nullptr );
688  shape->SetLocalCoord();
689  }
690  else if( item->Type() == PCB_FP_TEXT_T )
691  {
692  FP_TEXT* text = static_cast<FP_TEXT*>( item );
693 
694  if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
695  continue;
696 
697  text->SetTextAngle( text->GetTextAngle() + aClipFootprint->GetOrientation() );
698 
699  text->SetParent( nullptr );
700  text->SetLocalCoord();
701  }
702 
703  item->SetParent( editorFootprint );
704  aPastedItems.push_back( item );
705  }
706 
707  aClipFootprint->GraphicalItems().clear();
708 
709  for( FP_ZONE* zone : aClipFootprint->Zones() )
710  {
711  zone->SetParent( editorFootprint );
712  aPastedItems.push_back( zone );
713  }
714 
715  aClipFootprint->Zones().clear();
716 
717  for( PCB_GROUP* group : aClipFootprint->Groups() )
718  {
719  group->SetParent( editorFootprint );
720  aPastedItems.push_back( group );
721  }
722 
723  aClipFootprint->Groups().clear();
724 }
725 
726 
727 int PCB_CONTROL::Paste( const TOOL_EVENT& aEvent )
728 {
729  CLIPBOARD_IO pi;
730  BOARD_ITEM* clipItem = pi.Parse();
731 
732  if( !clipItem )
733  return 0;
734 
735  // The viewer frames cannot paste
736  if( !frame()->IsType( FRAME_FOOTPRINT_EDITOR ) && !frame()->IsType( FRAME_PCB_EDITOR ) )
737  return 0;
738 
740  const wxString defaultRef = wxT( "REF**" );
741 
742  if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
743  {
744  DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode, defaultRef );
745 
746  if( dlg.ShowModal() == wxID_CANCEL )
747  return 0;
748  }
749 
750  bool isFootprintEditor = m_isFootprintEditor || frame()->IsType( FRAME_FOOTPRINT_EDITOR );
751 
752  if( clipItem->Type() == PCB_T )
753  {
754  if( isFootprintEditor )
755  {
756  for( BOARD_CONNECTED_ITEM* item : static_cast<BOARD*>( clipItem )->AllConnectedItems() )
757  item->SetNet( NETINFO_LIST::OrphanedItem() );
758  }
759  else
760  {
761  static_cast<BOARD*>( clipItem )->MapNets( m_frame->GetBoard() );
762  }
763  }
764 
765  // The clipboard can contain two different things, an entire kicad_pcb or a single footprint
766  if( isFootprintEditor && ( !board() || !footprint() ) )
767  {
768  return 0;
769  }
770 
771  switch( clipItem->Type() )
772  {
773  case PCB_T:
774  {
775  BOARD* clipBoard = static_cast<BOARD*>( clipItem );
776 
777  if( isFootprintEditor )
778  {
779  FOOTPRINT* editorFootprint = board()->GetFirstFootprint();
780  std::vector<BOARD_ITEM*> pastedItems;
781 
782  for( FOOTPRINT* clipFootprint : clipBoard->Footprints() )
783  pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
784 
785  for( BOARD_ITEM* clipDrawItem : clipBoard->Drawings() )
786  {
787  if( clipDrawItem->Type() == PCB_SHAPE_T )
788  {
789  PCB_SHAPE* clipShape = static_cast<PCB_SHAPE*>( clipDrawItem );
790 
791  // Convert to PCB_FP_SHAPE_T
792  FP_SHAPE* pastedShape = new FP_SHAPE( editorFootprint );
793  static_cast<PCB_SHAPE*>( pastedShape )->SwapData( clipShape );
794  pastedShape->SetLocalCoord();
795 
796  // Replace parent nuked by above call to SwapData()
797  pastedShape->SetParent( editorFootprint );
798  pastedItems.push_back( pastedShape );
799  }
800  else if( clipDrawItem->Type() == PCB_TEXT_T )
801  {
802  PCB_TEXT* clipTextItem = static_cast<PCB_TEXT*>( clipDrawItem );
803 
804  // Convert to PCB_FP_TEXT_T
805  FP_TEXT* pastedTextItem = new FP_TEXT( editorFootprint );
806  static_cast<EDA_TEXT*>( pastedTextItem )->SwapText( *clipTextItem );
807  static_cast<EDA_TEXT*>( pastedTextItem )->SwapEffects( *clipTextItem );
808 
809  pastedTextItem->SetParent( editorFootprint );
810  pastedItems.push_back( pastedTextItem );
811  }
812  }
813 
814  delete clipBoard;
815 
816  placeBoardItems( pastedItems, true, true,
817  pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
818  }
819  else
820  {
822  board()->IsElementVisible( LAYER_RATSNEST ) );
823 
824  if( pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS )
825  {
826  for( FOOTPRINT* clipFootprint : clipBoard->Footprints() )
827  clipFootprint->SetReference( defaultRef );
828  }
829 
830  placeBoardItems( clipBoard, true, pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
831 
833  m_frame->Compile_Ratsnest( true );
834  }
835 
836  break;
837  }
838 
839  case PCB_FOOTPRINT_T:
840  {
841  FOOTPRINT* clipFootprint = static_cast<FOOTPRINT*>( clipItem );
842  std::vector<BOARD_ITEM*> pastedItems;
843 
844  if( isFootprintEditor )
845  {
846  pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
847  delete clipFootprint;
848  }
849  else
850  {
851 
852  for( PAD* pad : clipFootprint->Pads() )
853  pad->SetLocalRatsnestVisible( board()->IsElementVisible( LAYER_RATSNEST ) );
854 
855  if( pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS )
856  clipFootprint->SetReference( defaultRef );
857 
858  clipFootprint->SetParent( board() );
859  pastedItems.push_back( clipFootprint );
860  }
861 
862  placeBoardItems( pastedItems, true, true, pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
863  break;
864  }
865 
866  default:
867  m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) );
868  break;
869  }
870 
871  return 1;
872 }
873 
874 
876 {
877  int open_ctl;
878  wxString fileName;
879 
880  PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
881 
882  if( !editFrame )
883  return 1;
884 
885  // Pick a file to append
886  if( !AskLoadBoardFileName( editFrame, &open_ctl, &fileName, true ) )
887  return 1;
888 
889  IO_MGR::PCB_FILE_T pluginType = plugin_type( fileName, open_ctl );
890  PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
891 
892  return AppendBoard( *pi, fileName );
893 }
894 
895 
896 // Helper function for PCB_CONTROL::placeBoardItems()
897 template<typename T>
898 static void moveUnflaggedItems( std::deque<T>& aList, std::vector<BOARD_ITEM*>& aTarget,
899  bool aIsNew )
900 {
901  std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
902  [aIsNew]( T aItem )
903  {
904  bool doCopy = ( aItem->GetFlags() & SKIP_STRUCT ) == 0;
905 
906  aItem->ClearFlags( SKIP_STRUCT );
907  aItem->SetFlags( aIsNew ? IS_NEW : 0 );
908 
909  return doCopy;
910  } );
911 
912  if( aIsNew )
913  aList.clear();
914 }
915 
916 
917 static void moveUnflaggedItems( ZONES& aList, std::vector<BOARD_ITEM*>& aTarget, bool aIsNew )
918 {
919  if( aList.size() == 0 )
920  return;
921 
922  auto obj = aList.front();
923  int idx = 0;
924 
925  if( aIsNew )
926  {
927  obj = aList.back();
928  aList.pop_back();
929  }
930 
931  for( ; obj ; )
932  {
933  if( obj->HasFlag( SKIP_STRUCT ) )
934  obj->ClearFlags( SKIP_STRUCT );
935  else
936  aTarget.push_back( obj );
937 
938  if( aIsNew )
939  {
940  if( aList.size() )
941  {
942  obj = aList.back();
943  aList.pop_back();
944  }
945  else
946  {
947  obj = nullptr;
948  }
949  }
950  else
951  {
952  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
953  }
954  }
955 }
956 
957 
958 
959 int PCB_CONTROL::placeBoardItems( BOARD* aBoard, bool aAnchorAtOrigin, bool aReannotateDuplicates )
960 {
961  // items are new if the current board is not the board source
962  bool isNew = board() != aBoard;
963  std::vector<BOARD_ITEM*> items;
964 
965  moveUnflaggedItems( aBoard->Tracks(), items, isNew );
966  moveUnflaggedItems( aBoard->Footprints(), items, isNew );
967  moveUnflaggedItems( aBoard->Drawings(), items, isNew );
968  moveUnflaggedItems( aBoard->Zones(), items, isNew );
969 
970  // Subtlety: When selecting a group via the mouse,
971  // PCB_SELECTION_TOOL::highlightInternal runs, which does a SetSelected() on all
972  // descendants. In PCB_CONTROL::placeBoardItems, below, we skip that and
973  // mark items non-recursively. That works because the saving of the
974  // selection created aBoard that has the group and all descendants in it.
975  moveUnflaggedItems( aBoard->Groups(), items, isNew );
976 
977  return placeBoardItems( items, isNew, aAnchorAtOrigin, aReannotateDuplicates );
978 }
979 
980 
981 int PCB_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems, bool aIsNew,
982  bool aAnchorAtOrigin, bool aReannotateDuplicates )
983 {
985 
987  EDIT_TOOL* editTool = m_toolMgr->GetTool<EDIT_TOOL>();
988 
989  std::vector<BOARD_ITEM*> itemsToSel;
990  itemsToSel.reserve( aItems.size() );
991 
992  for( BOARD_ITEM* item : aItems )
993  {
994  if( aIsNew )
995  {
996  const_cast<KIID&>( item->m_Uuid ) = KIID();
997 
998  if( selectionTool->GetEnteredGroup() && !item->GetParentGroup() )
999  selectionTool->GetEnteredGroup()->AddItem( item );
1000  }
1001 
1002  // Update item attributes if needed
1003  switch( item->Type() )
1004  {
1005  case PCB_DIMENSION_T:
1006  case PCB_DIM_ALIGNED_T:
1007  case PCB_DIM_CENTER_T:
1008  case PCB_DIM_ORTHOGONAL_T:
1009  case PCB_DIM_LEADER_T:
1010  {
1011  // Dimensions need to have their units updated if they are automatic
1012  PCB_DIMENSION_BASE* dim = static_cast<PCB_DIMENSION_BASE*>( item );
1013 
1014  if( dim->GetUnitsMode() == DIM_UNITS_MODE::AUTOMATIC )
1015  dim->SetUnits( frame()->GetUserUnits() );
1016 
1017  break;
1018  }
1019 
1020  case PCB_FOOTPRINT_T:
1021  // Update the footprint path with the new KIID path if the footprint is new
1022  if( aIsNew )
1023  static_cast<FOOTPRINT*>( item )->SetPath( KIID_PATH() );
1024 
1025  break;
1026 
1027  default:
1028  break;
1029  }
1030 
1031  // We only need to add the items that aren't inside a group currently selected
1032  // to the selection. If an item is inside a group and that group is selected,
1033  // then the selection tool will select it for us.
1034  if( !item->GetParentGroup() || !alg::contains( aItems, item->GetParentGroup() ) )
1035  itemsToSel.push_back( item );
1036  }
1037 
1038  // Select the items that should be selected
1039  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &itemsToSel );
1040 
1041  // Reannotate duplicate footprints (make sense only in board editor )
1042  if( aReannotateDuplicates && m_frame->IsType( FRAME_PCB_EDITOR ) )
1044 
1045  for( BOARD_ITEM* item : aItems )
1046  {
1047  // Commit after reannotation
1048  if( aIsNew )
1049  editTool->GetCurrentCommit()->Add( item );
1050  else
1051  editTool->GetCurrentCommit()->Added( item );
1052  }
1053 
1054  PCB_SELECTION& selection = selectionTool->GetSelection();
1055 
1056  if( selection.Size() > 0 )
1057  {
1058  if( aAnchorAtOrigin )
1059  {
1061  }
1062  else
1063  {
1064  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
1066  }
1067 
1068  getViewControls()->SetCursorPosition( getViewControls()->GetMousePosition(), false );
1069 
1072  }
1073 
1074  return 0;
1075 }
1076 
1077 
1078 int PCB_CONTROL::AppendBoard( PLUGIN& pi, wxString& fileName )
1079 {
1080  PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
1081 
1082  if( !editFrame )
1083  return 1;
1084 
1085  BOARD* brd = board();
1086 
1087  if( !brd )
1088  return 1;
1089 
1090  // Mark existing items, in order to know what are the new items so we can select only
1091  // the new items after loading
1092  for( PCB_TRACK* track : brd->Tracks() )
1093  track->SetFlags( SKIP_STRUCT );
1094 
1095  for( FOOTPRINT* footprint : brd->Footprints() )
1097 
1098  for( PCB_GROUP* group : brd->Groups() )
1099  group->SetFlags( SKIP_STRUCT );
1100 
1101  for( BOARD_ITEM* drawing : brd->Drawings() )
1102  drawing->SetFlags( SKIP_STRUCT );
1103 
1104  for( ZONE* zone : brd->Zones() )
1105  zone->SetFlags( SKIP_STRUCT );
1106 
1107  std::map<wxString, wxString> oldProperties = brd->GetProperties();
1108  std::map<wxString, wxString> newProperties;
1109 
1110  // Keep also the count of copper layers, to adjust if necessary
1111  int initialCopperLayerCount = brd->GetCopperLayerCount();
1112  LSET initialEnabledLayers = brd->GetEnabledLayers();
1113 
1114  // Load the data
1115  try
1116  {
1117  PROPERTIES props;
1118  char xbuf[30];
1119  char ybuf[30];
1120 
1121  // EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet.
1122  sprintf( xbuf, "%d", editFrame->GetPageSizeIU().x );
1123  sprintf( ybuf, "%d", editFrame->GetPageSizeIU().y );
1124 
1125  props["page_width"] = xbuf;
1126  props["page_height"] = ybuf;
1127 
1128  WX_PROGRESS_REPORTER progressReporter( editFrame, _( "Loading PCB" ), 1 );
1129 
1130  editFrame->GetDesignSettings().GetNetClasses().Clear();
1131  pi.Load( fileName, brd, &props, nullptr, &progressReporter );
1132  }
1133  catch( const IO_ERROR& ioe )
1134  {
1135  wxString msg = wxString::Format( _( "Error loading board.\n%s" ), ioe.What() );
1136  DisplayError( editFrame, msg );
1137 
1138  return 0;
1139  }
1140 
1141  newProperties = brd->GetProperties();
1142 
1143  for( const std::pair<const wxString, wxString>& prop : oldProperties )
1144  newProperties[ prop.first ] = prop.second;
1145 
1146  brd->SetProperties( newProperties );
1147 
1148  // rebuild nets and ratsnest before any use of nets
1149  brd->BuildListOfNets();
1151  brd->BuildConnectivity();
1152 
1153  // Synchronize layers
1154  // we should not ask PLUGINs to do these items:
1155  int copperLayerCount = brd->GetCopperLayerCount();
1156 
1157  if( copperLayerCount > initialCopperLayerCount )
1158  brd->SetCopperLayerCount( copperLayerCount );
1159 
1160  // Enable all used layers, and make them visible:
1161  LSET enabledLayers = brd->GetEnabledLayers();
1162  enabledLayers |= initialEnabledLayers;
1163  brd->SetEnabledLayers( enabledLayers );
1164  brd->SetVisibleLayers( enabledLayers );
1165 
1166  return placeBoardItems( brd, false, false ); // Do not reannotate duplicates on Append Board
1167 }
1168 
1169 
1170 int PCB_CONTROL::Undo( const TOOL_EVENT& aEvent )
1171 {
1172  PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
1173  wxCommandEvent dummy;
1174 
1175  if( editFrame )
1176  editFrame->RestoreCopyFromUndoList( dummy );
1177 
1178  return 0;
1179 }
1180 
1181 
1182 int PCB_CONTROL::Redo( const TOOL_EVENT& aEvent )
1183 {
1184  PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
1185  wxCommandEvent dummy;
1186 
1187  if( editFrame )
1188  editFrame->RestoreCopyFromRedoList( dummy );
1189 
1190  return 0;
1191 }
1192 
1193 
1195 {
1197  ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
1198  PCB_SELECTION& selection = selTool->GetSelection();
1199 
1200  if( routerTool && routerTool->RoutingInProgress() )
1201  {
1202  routerTool->UpdateMessagePanel();
1203  return 0;
1204  }
1205 
1206  if( selection.GetSize() == 1 )
1207  {
1208  EDA_ITEM* item = selection.Front();
1209  std::vector<MSG_PANEL_ITEM> msgItems;
1210 
1211  item->GetMsgPanelInfo( m_frame, msgItems );
1212  m_frame->SetMsgPanel( msgItems );
1213  }
1214  else if( selection.GetSize() > 1 )
1215  {
1216  std::vector<MSG_PANEL_ITEM> msgItems;
1217  wxString msg = wxString::Format( wxT( "%d" ), selection.GetSize() );
1218 
1219  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Selected Items" ), msg ) );
1220  m_frame->SetMsgPanel( msgItems );
1221  }
1222  else if( auto editFrame = dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
1223  {
1224  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( editFrame->GetModel() );
1225 
1226  if( !footprint )
1227  return 0;
1228 
1229  std::vector<MSG_PANEL_ITEM> msgItems;
1230  wxString msg;
1231 
1232  msg = footprint->GetFPID().GetLibNickname().wx_str();
1233  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Library" ), msg ) );
1234 
1235  msg = footprint->GetFPID().GetLibItemName().wx_str();
1236  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Footprint Name" ), msg ) );
1237 
1238  msg.Printf( wxT( "%zu" ), (size_t) footprint->GetPadCount( DO_NOT_INCLUDE_NPTH ) );
1239  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Pads" ), msg ) );
1240 
1241  wxString doc, keyword;
1242  doc.Printf( _( "Doc: %s" ), footprint->GetDescription() );
1243  keyword.Printf( _( "Keywords: %s" ), footprint->GetKeywords() );
1244  msgItems.emplace_back( MSG_PANEL_ITEM( doc, keyword ) );
1245 
1246  m_frame->SetMsgPanel( msgItems );
1247  }
1248  else
1249  {
1251  }
1252 
1253  return 0;
1254 }
1255 
1256 
1258 {
1259  view()->SetMirror( !view()->IsMirroredX(), false );
1260  view()->RecacheAllItems();
1261  frame()->GetCanvas()->ForceRefresh();
1263  return 0;
1264 }
1265 
1266 
1268 {
1271  Go( &PCB_CONTROL::Print, ACTIONS::print.MakeEvent() );
1272  Go( &PCB_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
1273 
1274  // Display modes
1289 
1290  // Layer control
1328 
1329  // Grid control
1332 
1333  Go( &PCB_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
1334  Go( &PCB_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
1335 
1336  // Miscellaneous
1338 
1339  // Append control
1341 
1342  Go( &PCB_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
1343  Go( &PCB_CONTROL::Paste, ACTIONS::pasteSpecial.MakeEvent() );
1344 
1349 }
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:475
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:60
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:279
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:313
void BuildListOfNets()
Definition: board.h:659
bool AddItem(BOARD_ITEM *aItem)
Add item to group.
Definition: pcb_group.cpp:39
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:201
int GridSetOrigin(const TOOL_EVENT &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:200
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:241
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
void SetElementVisibility(GAL_LAYER_ID aLayer, bool aNewState)
Change the visibility of an element category.
Definition: board.cpp:539
BOARD_ITEM * m_pickerItem
Definition: pcb_control.h:134
int NetColorModeCycle(const TOOL_EVENT &aEvent)
ZONES & Zones()
Definition: board.h:240
static NETINFO_ITEM * OrphanedItem()
Wrapper class, so you can iterate through NETINFO_ITEM*s, not std::pair<int/wxString,...
Definition: netinfo.h:380
BOARD * board() const
int LayerAlphaDec(const TOOL_EVENT &aEvent)
Ratsnest lines are drawn to items on visible layers only.
unsigned GetPadCount(INCLUDE_NPTH_T aIncludeNPTH=INCLUDE_NPTH_T(INCLUDE_NPTH)) const
Return the number of pads.
Definition: footprint.cpp:1130
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:201
#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:129
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:252
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:49
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:260
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:254
static TOOL_ACTION ratsnestLineMode
Definition: pcb_actions.h:237
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:1385
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:350
Net/netclass colors are shown on all net copper.
Net/netclass colors are shown on ratsnest lines only.
#define ALPHA_MIN
double GetOrientation() const
Definition: footprint.h:191
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
void SetCopperLayerCount(int aCount)
Definition: board.cpp:461
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:41
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
int RatsnestModeCycle(const TOOL_EVENT &aEvent)
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:86
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:467
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:263
static TOOL_ACTION print
Definition: actions.h:57
virtual wxPoint GetPosition() const
Definition: eda_item.h:251
void SetMirror(bool aMirrorX, bool aMirrorY)
Control the mirroring of the VIEW.
Definition: view.cpp:539
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:622
virtual bool IsLocked() const
Definition: board_item.cpp:64
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:110
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
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:115
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PADS & Pads()
Definition: footprint.h:169
Ratsnest lines are drawn to items on all layers (default)
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:953
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:259
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:82
void SynchronizeNetsAndNetClasses()
Copy NETCLASS info to each NET, based on NET membership in a NETCLASS.
Definition: board.cpp:1394
virtual void SwitchLayer(PCB_LAYER_ID aLayer)
Change the active layer in the frame.
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
FP_ZONES & Zones()
Definition: footprint.h:175
void UnbrightenItem(BOARD_ITEM *aItem)
Definition: kiid.h:44
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:192
RATSNEST_MODE m_RatsnestMode
Ratsnest draw mode (all layers vs only visible layers)
static TOOL_ACTION appendBoard
Definition: pcb_actions.h:440
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:387
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:52
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:516
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:318
VECTOR2< double > VECTOR2D
Definition: vector2d.h:621
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:499
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:213
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:234
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:236
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:202
DRAWINGS & GraphicalItems()
Definition: footprint.h:172
void BrightenItem(BOARD_ITEM *aItem)
NETCLASSES & GetNetClasses() const
const LIB_ID & GetFPID() const
Definition: footprint.h:195
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
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:204
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:808
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
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:88
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 BuildConnectivity(PROGRESS_REPORTER *aReporter=nullptr)
Build or rebuild the board connectivity database for the board, especially the list of connected item...
Definition: board.cpp:137
void UpdateLayerColor(int aLayer)
Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
Definition: view.cpp:741
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
FP_GROUPS & Groups()
Definition: footprint.h:178
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:473
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:191
int FlipPcbView(const TOOL_EVENT &aEvent)
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
Net (and netclass) colors are not shown.
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:136
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:343
Definition: layer_ids.h:71
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:455
std::unique_ptr< KIGFX::ORIGIN_VIEWITEM > m_gridOrigin
Definition: pcb_control.h:132
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:104
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:99
void SetGridOrigin(const wxPoint &aOrigin)
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.
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)
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:52
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:320
int ToggleRatsnest(const TOOL_EVENT &aEvent)
Inactive layers are hidden.
static TOOL_ACTION ratsnestModeCycle
Definition: pcb_actions.h:239
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:237
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:914
void SetEnabledLayers(LSET aLayerMask)
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:487
static TOOL_ACTION paste
Definition: actions.h:68
A specialization of ZONE for use in footprints.
Definition: zone.h:947
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
int AppendBoardFromFile(const TOOL_EVENT &aEvent)
static TOOL_ACTION netColorModeCycle
Definition: pcb_actions.h:238
TRACKS & Tracks()
Definition: board.h:231
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:145
int UpdateMessagePanel(const TOOL_EVENT &aEvent)
void DisplayToolMsg(const wxString &msg) override
static TOOL_ACTION layerInner12
Definition: pcb_actions.h:263
NET_COLOR_MODE m_NetColorMode
How to use color overrides on specific nets and netclasses.
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
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)