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-2020 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 "pcb_actions.h"
28 #include "pcb_control.h"
29 #include "pcb_picker_tool.h"
30 #include "pcb_selection_tool.h"
31 #include "board_reannotate_tool.h"
33 #include <bitmaps.h>
34 #include <board_commit.h>
35 #include <board.h>
36 #include <board_design_settings.h>
37 #include <board_item.h>
39 #include <pcb_dimension.h>
40 #include <footprint.h>
41 #include <pcb_group.h>
42 #include <pcb_track.h>
43 #include <zone.h>
44 #include <fp_shape.h>
45 #include <confirm.h>
47 #include <core/kicad_algo.h>
48 #include <kicad_clipboard.h>
49 #include <origin_viewitem.h>
50 #include <pcb_edit_frame.h>
51 #include <pcb_painter.h>
52 #include <properties.h>
54 #include <tool/tool_manager.h>
55 #include <view/view_controls.h>
56 #include <footprint_viewer_frame.h>
57 #include <footprint_edit_frame.h>
58 
59 using namespace std::placeholders;
60 
61 
62 // files.cpp
63 extern bool AskLoadBoardFileName( PCB_EDIT_FRAME* aParent, int* aCtl, wxString* aFileName,
64  bool aKicadFilesOnly = false );
65 extern IO_MGR::PCB_FILE_T plugin_type( const wxString& aFileName, int aCtl );
66 
67 
69  PCB_TOOL_BASE( "pcbnew.Control" ),
70  m_frame( nullptr ),
71  m_pickerItem( nullptr )
72 {
73  m_gridOrigin.reset( new KIGFX::ORIGIN_VIEWITEM() );
74 }
75 
76 
78 {
79 }
80 
81 
83 {
84  m_frame = getEditFrame<PCB_BASE_FRAME>();
85 
86  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
87  {
88  m_gridOrigin->SetPosition( board()->GetDesignSettings().m_GridOrigin );
89  m_gridOrigin->SetColor( m_frame->GetGridColor() );
90  getView()->Remove( m_gridOrigin.get() );
91  getView()->Add( m_gridOrigin.get() );
92  }
93 }
94 
95 
96 int PCB_CONTROL::AddLibrary( const TOOL_EVENT& aEvent )
97 {
99  {
100  if( aEvent.IsAction( &ACTIONS::newLibrary ) )
101  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->CreateNewLibrary();
102  else if( aEvent.IsAction( &ACTIONS::addLibrary ) )
103  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->AddLibrary();
104  }
105 
106  return 0;
107 }
108 
109 
110 int PCB_CONTROL::Quit( const TOOL_EVENT& aEvent )
111 {
112  m_frame->Close( false );
113  return 0;
114 }
115 
116 
117 template<class T> void Flip( T& aValue )
118 {
119  aValue = !aValue;
120 }
121 
122 
124 {
125  auto opts = displayOptions();
126 
127  Flip( opts.m_DisplayPcbTrackFill );
128  m_frame->SetDisplayOptions( opts );
129 
130  for( auto track : board()->Tracks() )
131  {
132  if( track->Type() == PCB_TRACE_T || track->Type() == PCB_ARC_T )
133  view()->Update( track, KIGFX::REPAINT );
134  }
135 
136  canvas()->Refresh();
137 
138  return 0;
139 }
140 
141 
143 {
144  auto opts = displayOptions();
145 
146  if( aEvent.IsAction( &PCB_ACTIONS::showRatsnest ) )
147  {
148  // N.B. Do not disable the Ratsnest layer here. We use it for local ratsnest
149  Flip( opts.m_ShowGlobalRatsnest );
150  m_frame->SetDisplayOptions( opts );
151  getEditFrame<PCB_EDIT_FRAME>()->SetElementVisibility( LAYER_RATSNEST,
152  opts.m_ShowGlobalRatsnest );
153 
154  }
155  else if( aEvent.IsAction( &PCB_ACTIONS::ratsnestLineMode ) )
156  {
157  Flip( opts.m_DisplayRatsnestLinesCurved );
158  m_frame->SetDisplayOptions( opts );
159  }
160 
161  canvas()->RedrawRatsnest();
162  canvas()->Refresh();
163 
164  return 0;
165 }
166 
167 
169 {
170  auto opts = displayOptions();
171 
172  Flip( opts.m_DisplayViaFill );
173  m_frame->SetDisplayOptions( opts );
174 
175  for( auto track : board()->Tracks() )
176  {
177  if( track->Type() == PCB_TRACE_T || track->Type() == PCB_VIA_T )
178  view()->Update( track, KIGFX::REPAINT );
179  }
180 
181  canvas()->Refresh();
182 
183  return 0;
184 }
185 
186 
188 {
189  auto opts = displayOptions();
190 
191  // Apply new display options to the GAL canvas
193  {
194  opts.m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_FILLED;
195  }
196  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayDisable ) )
197  {
198  opts.m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_ZONE_OUTLINE;
199  }
200  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayOutlines ) )
201  {
202  opts.m_ZoneDisplayMode = ZONE_DISPLAY_MODE::SHOW_FILLED_OUTLINE;
203  }
204  else if( aEvent.IsAction( &PCB_ACTIONS::zoneDisplayToggle ) )
205  {
206  int nextMode = ( static_cast<int>( opts.m_ZoneDisplayMode ) + 1 ) % 3;
207  opts.m_ZoneDisplayMode = static_cast<ZONE_DISPLAY_MODE>( nextMode );
208  }
209  else
210  {
211  wxFAIL;
212  }
213 
214  m_frame->SetDisplayOptions( opts );
215 
216  for( ZONE* zone : board()->Zones() )
217  view()->Update( zone, KIGFX::REPAINT );
218 
219  canvas()->Refresh();
220 
221  return 0;
222 }
223 
224 
226 {
227  auto opts = displayOptions();
228 
229  opts.m_ContrastModeDisplay =
230  ( opts.m_ContrastModeDisplay == HIGH_CONTRAST_MODE::NORMAL ) ?
233 
234  m_frame->SetDisplayOptions( opts );
235 
236  return 0;
237 }
238 
239 
241 {
242  auto opts = displayOptions();
243 
244  switch( opts.m_ContrastModeDisplay )
245  {
247  opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::DIMMED;
248  break;
249 
251  opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::HIDDEN;
252  break;
253 
255  opts.m_ContrastModeDisplay = HIGH_CONTRAST_MODE::NORMAL;
256  break;
257  }
258 
259  m_frame->SetDisplayOptions( opts );
260 
261  return 0;
262 }
263 
264 
265 // Layer control
267 {
269 
270  return 0;
271 }
272 
273 
274 int PCB_CONTROL::LayerNext( const TOOL_EVENT& aEvent )
275 {
276  PCB_BASE_FRAME* editFrame = m_frame;
277  BOARD* brd = board();
278  LAYER_NUM layer = editFrame->GetActiveLayer();
279  LAYER_NUM startLayer = layer;
280 
281  if( layer < F_Cu || layer > B_Cu )
282  return 0;
283 
284  while( startLayer != ++layer )
285  {
286  if( brd->IsLayerVisible( static_cast<PCB_LAYER_ID>( layer ) ) && IsCopperLayer( layer ) )
287  break;
288 
289  if( layer >= B_Cu )
290  layer = F_Cu - 1;
291  }
292 
293  wxCHECK( IsCopperLayer( layer ), 0 );
294  editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
295 
296  return 0;
297 }
298 
299 
300 int PCB_CONTROL::LayerPrev( const TOOL_EVENT& aEvent )
301 {
302  PCB_BASE_FRAME* editFrame = m_frame;
303  BOARD* brd = board();
304  LAYER_NUM layer = editFrame->GetActiveLayer();
305  LAYER_NUM startLayer = layer;
306 
307  if( layer < F_Cu || layer > B_Cu )
308  return 0;
309 
310  while( startLayer != --layer )
311  {
312  if( IsCopperLayer( layer ) // also test for valid layer id (layer >= F_Cu)
313  && brd->IsLayerVisible( static_cast<PCB_LAYER_ID>( layer ) ) )
314  break;
315 
316  if( layer <= F_Cu )
317  layer = B_Cu + 1;
318  }
319 
320 
321  wxCHECK( IsCopperLayer( layer ), 0 );
322  editFrame->SwitchLayer( NULL, ToLAYER_ID( layer ) );
323 
324  return 0;
325 }
326 
327 
329 {
330  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
331  PCB_SCREEN* screen = m_frame->GetScreen();
332 
333  if( currentLayer == screen->m_Route_Layer_TOP )
335  else
337 
338  return 0;
339 }
340 
341 
342 // It'd be nice to share the min/max with the DIALOG_COLOR_PICKER, but those are
343 // set in wxFormBuilder.
344 #define ALPHA_MIN 0.20
345 #define ALPHA_MAX 1.00
346 #define ALPHA_STEP 0.05
347 
349 {
350  auto settings = m_frame->GetColorSettings();
351 
352  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
353  KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
354 
355  if( currentColor.a <= ALPHA_MAX - ALPHA_STEP )
356  {
357  currentColor.a += ALPHA_STEP;
358  settings->SetColor( currentLayer, currentColor );
360 
362  view->UpdateLayerColor( currentLayer );
363  view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
364 
365  if( IsCopperLayer( currentLayer ) )
366  view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
367 
368  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->OnLayerAlphaChanged();
369  }
370  else
371  wxBell();
372 
373  return 0;
374 }
375 
376 
378 {
379  auto settings = m_frame->GetColorSettings();
380 
381  LAYER_NUM currentLayer = m_frame->GetActiveLayer();
382  KIGFX::COLOR4D currentColor = settings->GetColor( currentLayer );
383 
384  if( currentColor.a >= ALPHA_MIN + ALPHA_STEP )
385  {
386  currentColor.a -= ALPHA_STEP;
387  settings->SetColor( currentLayer, currentColor );
389 
391  view->UpdateLayerColor( currentLayer );
392  view->UpdateLayerColor( GetNetnameLayer( currentLayer ) );
393 
394  if( IsCopperLayer( currentLayer ) )
395  view->UpdateLayerColor( ZONE_LAYER_FOR( currentLayer ) );
396 
397  static_cast<PCB_BASE_EDIT_FRAME*>( m_frame )->OnLayerAlphaChanged();
398  }
399  else
400  wxBell();
401 
402  return 0;
403 }
404 
405 
406 // Grid control
408  EDA_ITEM* originViewItem, const VECTOR2D& aPoint )
409 {
410  aFrame->GetDesignSettings().m_GridOrigin = (wxPoint) aPoint;
411  aView->GetGAL()->SetGridOrigin( aPoint );
412  originViewItem->SetPosition( (wxPoint) aPoint );
413  aView->MarkDirty();
414  aFrame->OnModify();
415 }
416 
417 
419 {
420  VECTOR2D* origin = aEvent.Parameter<VECTOR2D*>();
421 
422  if( origin )
423  {
424  // We can't undo the other grid dialog settings, so no sense undoing just the origin
425  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), *origin );
426  delete origin;
427  }
428  else
429  {
430  if( m_isFootprintEditor && !getEditFrame<PCB_BASE_EDIT_FRAME>()->GetModel() )
431  return 0;
432 
433  std::string tool = aEvent.GetCommandStr().get();
435 
436  if( !picker ) // Happens in footprint wizard
437  return 0;
438 
439  // Deactivate other tools; particularly important if another PICKER is currently running
440  Activate();
441 
442  picker->SetClickHandler(
443  [this] ( const VECTOR2D& pt ) -> bool
444  {
446  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), pt );
447  return false; // drill origin is a one-shot; don't continue with tool
448  } );
449 
450  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
451  }
452 
453  return 0;
454 }
455 
456 
458 {
460  DoSetGridOrigin( getView(), m_frame, m_gridOrigin.get(), VECTOR2D( 0, 0 ) );
461  return 0;
462 }
463 
464 
465 #define HITTEST_THRESHOLD_PIXELS 5
466 
467 
469 {
471  return 0;
472 
473  std::string tool = aEvent.GetCommandStr().get();
475 
476  m_pickerItem = nullptr;
478 
479  // Deactivate other tools; particularly important if another PICKER is currently running
480  Activate();
481 
482  picker->SetCursor( KICURSOR::REMOVE );
483 
484  picker->SetClickHandler(
485  [this] ( const VECTOR2D& aPosition ) -> bool
486  {
487  if( m_pickerItem )
488  {
490  {
491  m_statusPopup.reset( new STATUS_TEXT_POPUP( m_frame ) );
492  m_statusPopup->SetText( _( "Item locked." ) );
493  m_statusPopup->PopupFor( 2000 );
494  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, 20 ) );
495  return true;
496  }
497 
499  selectionTool->UnbrightenItem( m_pickerItem );
500  selectionTool->AddItemToSel( m_pickerItem, true /*quiet mode*/ );
502  m_pickerItem = nullptr;
503  }
504 
505  return true;
506  } );
507 
508  picker->SetMotionHandler(
509  [this] ( const VECTOR2D& aPos )
510  {
511  BOARD* board = m_frame->GetBoard();
514  GENERAL_COLLECTOR collector;
515  collector.m_Threshold = KiROUND( getView()->ToWorld( HITTEST_THRESHOLD_PIXELS ) );
516 
517  if( m_isFootprintEditor )
518  collector.Collect( board, GENERAL_COLLECTOR::FootprintItems, (wxPoint) aPos, guide );
519  else
520  collector.Collect( board, GENERAL_COLLECTOR::BoardLevelItems, (wxPoint) aPos, guide );
521 
522  // Remove unselectable items
523  for( int i = collector.GetCount() - 1; i >= 0; --i )
524  {
525  if( !selectionTool->Selectable( collector[ i ] ) )
526  collector.Remove( i );
527  }
528 
529  if( collector.GetCount() > 1 )
530  selectionTool->GuessSelectionCandidates( collector, aPos );
531 
532  BOARD_ITEM* item = collector.GetCount() == 1 ? collector[ 0 ] : nullptr;
533 
534  if( m_pickerItem != item )
535  {
536 
537  if( m_pickerItem )
538  selectionTool->UnbrightenItem( m_pickerItem );
539 
540  m_pickerItem = item;
541 
542  if( m_pickerItem )
543  selectionTool->BrightenItem( m_pickerItem );
544  }
545  } );
546 
547  picker->SetFinalizeHandler(
548  [this] ( const int& aFinalState )
549  {
550  if( m_pickerItem )
552 
553  m_statusPopup.reset();
554 
555  // Ensure the cursor gets changed&updated
557  m_frame->GetCanvas()->Refresh();
558  } );
559 
560  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
561 
562  return 0;
563 }
564 
565 
566 static void pasteFootprintItemsToFootprintEditor( FOOTPRINT* aClipFootprint, BOARD* aBoard,
567  std::vector<BOARD_ITEM*>& aPastedItems )
568 {
569  FOOTPRINT* editorFootprint = aBoard->GetFirstFootprint();
570 
571  aClipFootprint->SetParent( aBoard );
572 
573  for( PAD* pad : aClipFootprint->Pads() )
574  {
575  pad->SetParent( editorFootprint );
576  aPastedItems.push_back( pad );
577  }
578 
579  aClipFootprint->Pads().clear();
580 
581  // Not all graphic items can be added to the current footprint:
582  // Reference and value are already existing in the current footprint, and
583  // must be unique.
584  // So they will be skipped
585  for( BOARD_ITEM* item : aClipFootprint->GraphicalItems() )
586  {
587  if( item->Type() == PCB_FP_SHAPE_T )
588  {
589  FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
590 
591  shape->SetParent( nullptr );
592  shape->SetLocalCoord();
593  }
594  else if( item->Type() == PCB_FP_TEXT_T )
595  {
596  FP_TEXT* text = static_cast<FP_TEXT*>( item );
597 
598  if( text->GetType() != FP_TEXT::TEXT_is_DIVERS )
599  continue;
600 
601  text->SetTextAngle( aClipFootprint->GetOrientation() );
602 
603  text->SetParent( nullptr );
604  text->SetLocalCoord();
605  }
606 
607  item->SetParent( editorFootprint );
608  aPastedItems.push_back( item );
609  }
610 
611  aClipFootprint->GraphicalItems().clear();
612 
613  for( FP_ZONE* zone : aClipFootprint->Zones() )
614  {
615  zone->SetParent( editorFootprint );
616  aPastedItems.push_back( zone );
617  }
618 
619  aClipFootprint->Zones().clear();
620 
621  for( PCB_GROUP* group : aClipFootprint->Groups() )
622  {
623  group->SetParent( editorFootprint );
624  aPastedItems.push_back( group );
625  }
626 
627  aClipFootprint->Groups().clear();
628 }
629 
630 
631 int PCB_CONTROL::Paste( const TOOL_EVENT& aEvent )
632 {
633  CLIPBOARD_IO pi;
634  BOARD_ITEM* clipItem = pi.Parse();
635 
636  if( !clipItem )
637  return 0;
638 
639  // The viewer frames cannot paste
640  if( !frame()->IsType( FRAME_FOOTPRINT_EDITOR ) && !frame()->IsType( FRAME_PCB_EDITOR ) )
641  return 0;
642 
644  const wxString defaultRef = wxT( "REF**" );
645 
646  if( aEvent.IsAction( &ACTIONS::pasteSpecial ) )
647  {
648  DIALOG_PASTE_SPECIAL dlg( m_frame, &pasteMode, defaultRef );
649 
650  if( dlg.ShowModal() == wxID_CANCEL )
651  return 0;
652  }
653 
654  bool isFootprintEditor = m_isFootprintEditor || frame()->IsType( FRAME_FOOTPRINT_EDITOR );
655 
656  if( clipItem->Type() == PCB_T )
657  {
658  if( isFootprintEditor )
659  {
660  for( BOARD_CONNECTED_ITEM* item : static_cast<BOARD*>( clipItem )->AllConnectedItems() )
661  item->SetNet( NETINFO_LIST::OrphanedItem() );
662  }
663  else
664  {
665  static_cast<BOARD*>( clipItem )->MapNets( m_frame->GetBoard() );
666  }
667  }
668 
669  // The clipboard can contain two different things, an entire kicad_pcb or a single footprint
670  if( isFootprintEditor && ( !board() || !footprint() ) )
671  {
672  return 0;
673  }
674 
675  switch( clipItem->Type() )
676  {
677  case PCB_T:
678  {
679  BOARD* clipBoard = static_cast<BOARD*>( clipItem );
680 
681  if( isFootprintEditor )
682  {
683  FOOTPRINT* editorFootprint = board()->GetFirstFootprint();
684  std::vector<BOARD_ITEM*> pastedItems;
685 
686  for( FOOTPRINT* clipFootprint : clipBoard->Footprints() )
687  pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
688 
689  for( BOARD_ITEM* clipDrawItem : clipBoard->Drawings() )
690  {
691  if( clipDrawItem->Type() == PCB_SHAPE_T )
692  {
693  PCB_SHAPE* clipShape = static_cast<PCB_SHAPE*>( clipDrawItem );
694 
695  // Convert to PCB_FP_SHAPE_T
696  FP_SHAPE* pastedShape = new FP_SHAPE( editorFootprint );
697  static_cast<PCB_SHAPE*>( pastedShape )->SwapData( clipShape );
698  pastedShape->SetLocalCoord();
699 
700  // Replace parent nuked by above call to SwapData()
701  pastedShape->SetParent( editorFootprint );
702  pastedItems.push_back( pastedShape );
703  }
704  else if( clipDrawItem->Type() == PCB_TEXT_T )
705  {
706  PCB_TEXT* clipTextItem = static_cast<PCB_TEXT*>( clipDrawItem );
707 
708  // Convert to PCB_FP_TEXT_T
709  FP_TEXT* pastedTextItem = new FP_TEXT( editorFootprint );
710  static_cast<EDA_TEXT*>( pastedTextItem )->SwapText( *clipTextItem );
711  static_cast<EDA_TEXT*>( pastedTextItem )->SwapEffects( *clipTextItem );
712 
713  pastedTextItem->SetParent( editorFootprint );
714  pastedItems.push_back( pastedTextItem );
715  }
716  }
717 
718  delete clipBoard;
719 
720  placeBoardItems( pastedItems, true, true,
721  pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
722  }
723  else
724  {
725  if( pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS )
726  {
727  for( FOOTPRINT* clipFootprint : clipBoard->Footprints() )
728  clipFootprint->SetReference( defaultRef );
729  }
730 
731  placeBoardItems( clipBoard, true, pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
732 
734  m_frame->Compile_Ratsnest( true );
735  }
736 
737  break;
738  }
739 
740  case PCB_FOOTPRINT_T:
741  {
742  FOOTPRINT* clipFootprint = static_cast<FOOTPRINT*>( clipItem );
743  std::vector<BOARD_ITEM*> pastedItems;
744 
745  if( isFootprintEditor )
746  {
747  pasteFootprintItemsToFootprintEditor( clipFootprint, board(), pastedItems );
748  delete clipFootprint;
749  }
750  else
751  {
752  if( pasteMode == PASTE_MODE::REMOVE_ANNOTATIONS )
753  clipFootprint->SetReference( defaultRef );
754 
755  clipFootprint->SetParent( board() );
756  pastedItems.push_back( clipFootprint );
757  }
758 
759  placeBoardItems( pastedItems, true, true, pasteMode == PASTE_MODE::UNIQUE_ANNOTATIONS );
760  break;
761  }
762 
763  default:
764  m_frame->DisplayToolMsg( _( "Invalid clipboard contents" ) );
765  break;
766  }
767 
768  return 1;
769 }
770 
771 
773 {
774  int open_ctl;
775  wxString fileName;
776 
777  PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
778 
779  if( !editFrame )
780  return 1;
781 
782  // Pick a file to append
783  if( !AskLoadBoardFileName( editFrame, &open_ctl, &fileName, true ) )
784  return 1;
785 
786  IO_MGR::PCB_FILE_T pluginType = plugin_type( fileName, open_ctl );
787  PLUGIN::RELEASER pi( IO_MGR::PluginFind( pluginType ) );
788 
789  return AppendBoard( *pi, fileName );
790 }
791 
792 
793 // Helper function for PCB_CONTROL::placeBoardItems()
794 template<typename T>
795 static void moveUnflaggedItems( std::deque<T>& aList, std::vector<BOARD_ITEM*>& aTarget,
796  bool aIsNew )
797 {
798  std::copy_if( aList.begin(), aList.end(), std::back_inserter( aTarget ),
799  [aIsNew]( T aItem )
800  {
801  bool doCopy = ( aItem->GetFlags() & SKIP_STRUCT ) == 0;
802 
803  aItem->ClearFlags( SKIP_STRUCT );
804  aItem->SetFlags( aIsNew ? IS_NEW : 0 );
805 
806  return doCopy;
807  } );
808 
809  if( aIsNew )
810  aList.clear();
811 }
812 
813 
814 static void moveUnflaggedItems( ZONES& aList, std::vector<BOARD_ITEM*>& aTarget, bool aIsNew )
815 {
816  if( aList.size() == 0 )
817  return;
818 
819  auto obj = aList.front();
820  int idx = 0;
821 
822  if( aIsNew )
823  {
824  obj = aList.back();
825  aList.pop_back();
826  }
827 
828  for( ; obj ; )
829  {
830  if( obj->HasFlag( SKIP_STRUCT ) )
831  obj->ClearFlags( SKIP_STRUCT );
832  else
833  aTarget.push_back( obj );
834 
835  if( aIsNew )
836  {
837  if( aList.size() )
838  {
839  obj = aList.back();
840  aList.pop_back();
841  }
842  else
843  obj = nullptr;
844  }
845  else
846  obj = idx < int(aList.size()-1) ? aList[++idx] : nullptr;
847  }
848 }
849 
850 
851 
852 int PCB_CONTROL::placeBoardItems( BOARD* aBoard, bool aAnchorAtOrigin, bool aReannotateDuplicates )
853 {
854  // items are new if the current board is not the board source
855  bool isNew = board() != aBoard;
856  std::vector<BOARD_ITEM*> items;
857 
858  moveUnflaggedItems( aBoard->Tracks(), items, isNew );
859  moveUnflaggedItems( aBoard->Footprints(), items, isNew );
860  moveUnflaggedItems( aBoard->Drawings(), items, isNew );
861  moveUnflaggedItems( aBoard->Zones(), items, isNew );
862 
863  // Subtlety: When selecting a group via the mouse,
864  // PCB_SELECTION_TOOL::highlightInternal runs, which does a SetSelected() on all
865  // descendants. In PCB_CONTROL::placeBoardItems, below, we skip that and
866  // mark items non-recursively. That works because the saving of the
867  // selection created aBoard that has the group and all descendents in it.
868  moveUnflaggedItems( aBoard->Groups(), items, isNew );
869 
870  return placeBoardItems( items, isNew, aAnchorAtOrigin, aReannotateDuplicates );
871 }
872 
873 
874 int PCB_CONTROL::placeBoardItems( std::vector<BOARD_ITEM*>& aItems, bool aIsNew,
875  bool aAnchorAtOrigin, bool aReannotateDuplicates )
876 {
878 
880  EDIT_TOOL* editTool = m_toolMgr->GetTool<EDIT_TOOL>();
881 
882  std::vector<BOARD_ITEM*> itemsToSel;
883  itemsToSel.reserve( aItems.size() );
884 
885  for( BOARD_ITEM* item : aItems )
886  {
887  if( aIsNew )
888  {
889  const_cast<KIID&>( item->m_Uuid ) = KIID();
890 
891  if( selectionTool->GetEnteredGroup() && !item->GetParentGroup() )
892  selectionTool->GetEnteredGroup()->AddItem( item );
893  }
894 
895  // Update item attributes if needed
896  switch( item->Type() )
897  {
898  case PCB_DIMENSION_T:
899  case PCB_DIM_ALIGNED_T:
900  case PCB_DIM_CENTER_T:
902  case PCB_DIM_LEADER_T:
903  {
904  // Dimensions need to have their units updated if they are automatic
905  PCB_DIMENSION_BASE* dim = static_cast<PCB_DIMENSION_BASE*>( item );
906 
908  dim->SetUnits( frame()->GetUserUnits() );
909 
910  break;
911  }
912 
913  case PCB_FOOTPRINT_T:
914  // Update the footprint path with the new KIID path if the footprint is new
915  if( aIsNew )
916  static_cast<FOOTPRINT*>( item )->SetPath( KIID_PATH() );
917 
918  break;
919 
920  default:
921  break;
922  }
923 
924  // We only need to add the items that aren't inside a group currently selected
925  // to the selection. If an item is inside a group and that group is selected,
926  // then the selection tool will select it for us.
927  if( !item->GetParentGroup() || !alg::contains( aItems, item->GetParentGroup() ) )
928  itemsToSel.push_back( item );
929  }
930 
931  // Select the items that should be selected
932  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &itemsToSel );
933 
934  // Reannotate duplicate footprints
935  if( aReannotateDuplicates )
936  m_toolMgr->GetTool<BOARD_REANNOTATE_TOOL>()->ReannotateDuplicatesInSelection();
937 
938  for( BOARD_ITEM* item : aItems )
939  {
940  // Commit after reannotation
941  if( aIsNew )
942  editTool->GetCurrentCommit()->Add( item );
943  else
944  editTool->GetCurrentCommit()->Added( item );
945  }
946 
947  PCB_SELECTION& selection = selectionTool->GetSelection();
948 
949  if( selection.Size() > 0 )
950  {
951  if( aAnchorAtOrigin )
952  {
954  }
955  else
956  {
957  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
959  }
960 
961  getViewControls()->SetCursorPosition( getViewControls()->GetMousePosition(), false );
962 
965  }
966 
967  return 0;
968 }
969 
970 
971 int PCB_CONTROL::AppendBoard( PLUGIN& pi, wxString& fileName )
972 {
973  PCB_EDIT_FRAME* editFrame = dynamic_cast<PCB_EDIT_FRAME*>( m_frame );
974 
975  if( !editFrame )
976  return 1;
977 
978  BOARD* brd = board();
979 
980  if( !brd )
981  return 1;
982 
983  // Mark existing items, in order to know what are the new items so we can select only
984  // the new items after loading
985  for( PCB_TRACK* track : brd->Tracks() )
986  track->SetFlags( SKIP_STRUCT );
987 
988  for( FOOTPRINT* footprint : brd->Footprints() )
990 
991  for( PCB_GROUP* group : brd->Groups() )
992  group->SetFlags( SKIP_STRUCT );
993 
994  for( BOARD_ITEM* drawing : brd->Drawings() )
995  drawing->SetFlags( SKIP_STRUCT );
996 
997  for( ZONE* zone : brd->Zones() )
998  zone->SetFlags( SKIP_STRUCT );
999 
1000  std::map<wxString, wxString> oldProperties = brd->GetProperties();
1001  std::map<wxString, wxString> newProperties;
1002 
1003  // Keep also the count of copper layers, to adjust if necessary
1004  int initialCopperLayerCount = brd->GetCopperLayerCount();
1005  LSET initialEnabledLayers = brd->GetEnabledLayers();
1006 
1007  // Load the data
1008  try
1009  {
1010  PROPERTIES props;
1011  char xbuf[30];
1012  char ybuf[30];
1013 
1014  // EAGLE_PLUGIN can use this info to center the BOARD, but it does not yet.
1015  sprintf( xbuf, "%d", editFrame->GetPageSizeIU().x );
1016  sprintf( ybuf, "%d", editFrame->GetPageSizeIU().y );
1017 
1018  props["page_width"] = xbuf;
1019  props["page_height"] = ybuf;
1020 
1021  editFrame->GetDesignSettings().GetNetClasses().Clear();
1022  pi.Load( fileName, brd, &props );
1023  }
1024  catch( const IO_ERROR& ioe )
1025  {
1026  wxString msg = wxString::Format( _( "Error loading board.\n%s" ), ioe.What() );
1027  DisplayError( editFrame, msg );
1028 
1029  return 0;
1030  }
1031 
1032  newProperties = brd->GetProperties();
1033 
1034  for( const std::pair<const wxString, wxString>& prop : oldProperties )
1035  newProperties[ prop.first ] = prop.second;
1036 
1037  brd->SetProperties( newProperties );
1038 
1039  // rebuild nets and ratsnest before any use of nets
1040  brd->BuildListOfNets();
1042  brd->BuildConnectivity();
1043 
1044  // Synchronize layers
1045  // we should not ask PLUGINs to do these items:
1046  int copperLayerCount = brd->GetCopperLayerCount();
1047 
1048  if( copperLayerCount > initialCopperLayerCount )
1049  brd->SetCopperLayerCount( copperLayerCount );
1050 
1051  // Enable all used layers, and make them visible:
1052  LSET enabledLayers = brd->GetEnabledLayers();
1053  enabledLayers |= initialEnabledLayers;
1054  brd->SetEnabledLayers( enabledLayers );
1055  brd->SetVisibleLayers( enabledLayers );
1056 
1057  return placeBoardItems( brd, false, false ); // Do not reannotate duplicates on Append Board
1058 }
1059 
1060 
1061 int PCB_CONTROL::Undo( const TOOL_EVENT& aEvent )
1062 {
1063  PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
1064  wxCommandEvent dummy;
1065 
1066  if( editFrame )
1067  editFrame->RestoreCopyFromUndoList( dummy );
1068 
1069  return 0;
1070 }
1071 
1072 
1073 int PCB_CONTROL::Redo( const TOOL_EVENT& aEvent )
1074 {
1075  PCB_BASE_EDIT_FRAME* editFrame = dynamic_cast<PCB_BASE_EDIT_FRAME*>( m_frame );
1076  wxCommandEvent dummy;
1077 
1078  if( editFrame )
1079  editFrame->RestoreCopyFromRedoList( dummy );
1080 
1081  return 0;
1082 }
1083 
1084 
1086 {
1088  PCB_SELECTION& selection = selTool->GetSelection();
1089 
1090  if( selection.GetSize() == 1 )
1091  {
1092  EDA_ITEM* item = selection.Front();
1093  MSG_PANEL_ITEMS msgItems;
1094 
1095  item->GetMsgPanelInfo( m_frame, msgItems );
1096  m_frame->SetMsgPanel( msgItems );
1097  }
1098  else if( selection.GetSize() > 1 )
1099  {
1100  MSG_PANEL_ITEMS msgItems;
1101  wxString msg = wxString::Format( wxT( "%d" ), selection.GetSize() );
1102 
1103  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Selected Items" ), msg ) );
1104  m_frame->SetMsgPanel( msgItems );
1105  }
1106  else if( auto editFrame = dynamic_cast<FOOTPRINT_EDIT_FRAME*>( m_frame ) )
1107  {
1108  FOOTPRINT* footprint = static_cast<FOOTPRINT*>( editFrame->GetModel() );
1109 
1110  if( !footprint )
1111  return 0;
1112 
1113  MSG_PANEL_ITEMS msgItems;
1114  wxString msg;
1115 
1116  msg = footprint->GetFPID().GetLibNickname().wx_str();
1117  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Library" ), msg ) );
1118 
1119  msg = footprint->GetFPID().GetLibItemName().wx_str();
1120  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Footprint Name" ), msg ) );
1121 
1122  wxDateTime date( static_cast<time_t>( footprint->GetLastEditTime() ) );
1123 
1124  if( footprint->GetLastEditTime() && date.IsValid() )
1125  // Date format: see http://www.cplusplus.com/reference/ctime/strftime
1126  msg = date.Format( wxT( "%b %d, %Y" ) ); // Abbreviated_month_name Day, Year
1127  else
1128  msg = _( "Unknown" );
1129 
1130  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Last Change" ), msg ) );
1131 
1132  msg.Printf( wxT( "%zu" ), (size_t) footprint->GetPadCount( DO_NOT_INCLUDE_NPTH ) );
1133  msgItems.emplace_back( MSG_PANEL_ITEM( _( "Pads" ), msg ) );
1134 
1135  wxString doc, keyword;
1136  doc.Printf( _( "Doc: %s" ), footprint->GetDescription() );
1137  keyword.Printf( _( "Keywords: %s" ), footprint->GetKeywords() );
1138  msgItems.emplace_back( MSG_PANEL_ITEM( doc, keyword ) );
1139 
1140  m_frame->SetMsgPanel( msgItems );
1141  }
1142  else
1143  {
1145  }
1146 
1147  return 0;
1148 }
1149 
1150 
1152 {
1153  view()->SetMirror( !view()->IsMirroredX(), false );
1154  view()->RecacheAllItems();
1155  frame()->GetCanvas()->ForceRefresh();
1157  return 0;
1158 }
1159 
1160 
1162 {
1165  Go( &PCB_CONTROL::Print, ACTIONS::print.MakeEvent() );
1166  Go( &PCB_CONTROL::Quit, ACTIONS::quit.MakeEvent() );
1167 
1168  // Display modes
1180 
1181  // Layer control
1219 
1220  // Grid control
1223 
1224  Go( &PCB_CONTROL::Undo, ACTIONS::undo.MakeEvent() );
1225  Go( &PCB_CONTROL::Redo, ACTIONS::redo.MakeEvent() );
1226 
1227  // Miscellaneous
1229 
1230  // Append control
1232 
1233  Go( &PCB_CONTROL::Paste, ACTIONS::paste.MakeEvent() );
1234  Go( &PCB_CONTROL::Paste, ACTIONS::pasteSpecial.MakeEvent() );
1235 
1240 }
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:430
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
std::vector< ZONE * > ZONES
Definition: eagle_plugin.h:43
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:252
static TOOL_ACTION layerBottom
Definition: pcb_actions.h:285
BOARD_ITEM * Parse()
static TOOL_ACTION layerInner26
Definition: pcb_actions.h:280
int ZoneDisplayMode(const TOOL_EVENT &aEvent)
void RestoreCopyFromUndoList(wxCommandEvent &aEvent)
Undo the last edit:
Definition: undo_redo.cpp:318
Filled polygons are shown.
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:188
int GridSetOrigin(const TOOL_EVENT &aEvent)
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
const UTF8 & GetLibItemName() const
Definition: lib_id.h:106
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:286
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:256
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:125
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:1008
static TOOL_ACTION layerInner5
Definition: pcb_actions.h:259
int GetUserUnits()
Returns 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
int GetNetnameLayer(int aLayer)
Returns a netname layer corresponding to the given layer.
virtual void OnDisplayOptionsChanged()
This file is part of the common library.
#define ZONE_LAYER_FOR(copperLayer)
Macro for getting the zone layer for a given copper layer.
static TOOL_ACTION doDelete
Definition: actions.h:72
PCB_BASE_FRAME * m_frame
Grid origin marker.
Definition: pcb_control.h:120
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:253
static TOOL_ACTION layerInner6
Definition: pcb_actions.h:260
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 layerInner7
Definition: pcb_actions.h:261
static TOOL_ACTION layerInner8
Definition: pcb_actions.h:262
void SetProperties(const std::map< wxString, wxString > &aProps)
Definition: board.h:259
Outlines of filled polygons are shown.
static TOOL_ACTION layerInner21
Definition: pcb_actions.h:275
GROUPS & Groups()
The groups must maintain the following invariants.
Definition: board.h:253
static TOOL_ACTION ratsnestLineMode
Definition: pcb_actions.h:242
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
static TOOL_ACTION layerAlphaDec
Definition: pcb_actions.h:289
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:567
static TOOL_ACTION gridResetOrigin
Definition: actions.h:138
static TOOL_ACTION zoneDisplayOutlines
Definition: pcb_actions.h:248
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:1381
static TOOL_ACTION layerAlphaInc
Definition: pcb_actions.h:288
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:352
static TOOL_ACTION zoneDisplayDisable
Definition: pcb_actions.h:247
#define ALPHA_MIN
double GetOrientation() const
Definition: footprint.h:181
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
void SetCopperLayerCount(int aCount)
Definition: board.cpp:459
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
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
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:82
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:465
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
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:541
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
static TOOL_ACTION layerInner3
Definition: pcb_actions.h:257
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:278
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:265
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:327
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PLUGIN implementation knows about into either ...
Definition: plugin.cpp:46
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:159
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:254
DIM_UNITS_MODE GetUnitsMode() const
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:70
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:550
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:277
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:1488
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
FP_ZONES & Zones()
Definition: footprint.h:165
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:439
static TOOL_ACTION zoneDisplayToggle
Definition: pcb_actions.h:249
void SetDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aRefresh=true)
Updates the current display options from the given options struct.
Inactive layers are dimmed (old high-contrast mode)
PCB_LAYER_ID
A quick note on layer IDs:
double a
Alpha component.
Definition: color4d.h:366
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
LSET is a set of PCB_LAYER_IDs.
static TOOL_ACTION layerInner13
Definition: pcb_actions.h:267
const PCB_SELECTION & selection() const
static TOOL_ACTION layerPrev
Definition: pcb_actions.h:287
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:317
#define NULL
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:497
static TOOL_ACTION layerInner25
Definition: pcb_actions.h:279
static TOOL_ACTION layerInner18
Definition: pcb_actions.h:272
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:427
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:284
KIGFX::PCB_VIEW * view() const
int GridResetOrigin(const TOOL_EVENT &aEvent)
static TOOL_ACTION layerInner29
Definition: pcb_actions.h:283
int DeleteItemCursor(const TOOL_EVENT &aEvent)
static TOOL_ACTION showRatsnest
Definition: pcb_actions.h:241
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:92
static TOOL_ACTION layerInner10
Definition: pcb_actions.h:264
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:162
void BrightenItem(BOARD_ITEM *aItem)
NETCLASSES & GetNetClasses() const
const LIB_ID & GetFPID() const
Definition: footprint.h:185
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
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)
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:191
bool m_isFootprintEditor
static TOOL_ACTION layerInner15
Definition: pcb_actions.h:269
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:282
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:81
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
static TOOL_ACTION layerInner27
Definition: pcb_actions.h:281
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.
int LAYER_NUM
This can be replaced with int and removed.
static TOOL_ACTION layerInner17
Definition: pcb_actions.h:271
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
virtual void SwitchLayer(wxDC *DC, PCB_LAYER_ID layer)
static TOOL_ACTION layerInner20
Definition: pcb_actions.h:274
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:245
void UpdateLayerColor(int aLayer)
Apply the new coloring scheme held by RENDER_SETTINGS in case that it has changed.
Definition: view.cpp:753
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:455
FP_GROUPS & Groups()
Definition: footprint.h:168
int Quit(const TOOL_EVENT &aEvent)
static TOOL_ACTION redo
Definition: actions.h:65
#define ALPHA_STEP
static TOOL_ACTION layerInner22
Definition: pcb_actions.h:276
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:471
virtual bool IsLocked() const
Definition: board_item.h:247
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
Declaration of the eda_3d_viewer class.
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.
Only the zone outline is shown.
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)
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:127
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:348
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:267
static TOOL_ACTION layerInner14
Definition: pcb_actions.h:268
static TOOL_ACTION layerInner9
Definition: pcb_actions.h:263
int HighContrastModeCycle(const TOOL_EVENT &aEvent)
int GetCopperLayerCount() const
Definition: board.cpp:453
std::unique_ptr< KIGFX::ORIGIN_VIEWITEM > m_gridOrigin
Definition: pcb_control.h:123
wxString wx_str() const
Definition: utf8.cpp:51
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:70
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:270
int AddLibrary(const TOOL_EVENT &aEvent)
Definition: pcb_control.cpp:96
const wxSize GetPageSizeIU() const override
Works off of GetPageSettings() to return the size of the paper page in the internal units of this par...
bool IsCopperLayer(LAYER_NUM aLayerId)
Tests whether a layer is a copper layer.
int LayerPrev(const TOOL_EVENT &aEvent)
void Activate()
Run the tool.
static TOOL_ACTION deleteTool
Definition: actions.h:73
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:258
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:322
int ToggleRatsnest(const TOOL_EVENT &aEvent)
Inactive layers are hidden.
static TOOL_ACTION flipBoard
Definition: pcb_actions.h:294
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:67
A general implementation of a COLLECTORS_GUIDE.
Definition: collectors.h:377
static TOOL_ACTION layerInner19
Definition: pcb_actions.h:273
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:52
static TOOL_ACTION layerInner1
Definition: pcb_actions.h:255
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:485
static TOOL_ACTION paste
Definition: actions.h:68
A specialization of ZONE for use in footprints.
Definition: zone.h:943
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:599
static TOOL_ACTION trackDisplayMode
Definition: pcb_actions.h:243
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:266
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:290
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103
static TOOL_ACTION zoneDisplayEnable
Definition: pcb_actions.h:246
int ViaDisplayMode(const TOOL_EVENT &aEvent)