KiCad PCB EDA Suite
board_editor_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 CERN
5  * Copyright (C) 2014-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #include <functional>
27 #include <memory>
28 
29 #include <advanced_config.h>
30 #include "board_editor_control.h"
31 #include <bitmaps.h>
32 #include <board.h>
33 #include <board_commit.h>
34 #include <board_design_settings.h>
35 #include <pcb_group.h>
36 #include <footprint.h>
37 #include <pad.h>
38 #include <pcb_target.h>
39 #include <pcb_track.h>
40 #include <zone.h>
41 #include <pcb_marker.h>
42 #include <confirm.h>
45 #include <kiface_base.h>
46 #include <kiway.h>
48 #include <origin_viewitem.h>
49 #include <pcb_edit_frame.h>
50 #include <pcbnew_id.h>
51 #include <pcbnew_settings.h>
52 #include <project.h>
53 #include <project/project_file.h> // LAST_PATH_TYPE
54 #include <tool/tool_manager.h>
55 #include <tool/tool_event.h>
56 #include <tools/drawing_tool.h>
57 #include <tools/pcb_actions.h>
58 #include <tools/pcb_picker_tool.h>
60 #include <tools/edit_tool.h>
61 #include <tools/tool_event_utils.h>
62 #include <router/router_tool.h>
63 #include <view/view_controls.h>
64 #include <view/view_group.h>
67 #include <footprint_edit_frame.h>
68 #include <wx/filedlg.h>
69 #include <wx/log.h>
70 
71 using namespace std::placeholders;
72 
73 
75 {
76 public:
78  ACTION_MENU( true )
79  {
80  SetIcon( BITMAPS::add_zone );
81  SetTitle( _( "Zones" ) );
82 
83  Add( PCB_ACTIONS::zoneFill );
87 
88  AppendSeparator();
89 
94  }
95 
96 
97 protected:
98  ACTION_MENU* create() const override
99  {
100  return new ZONE_CONTEXT_MENU();
101  }
102 };
103 
104 
106 {
107 public:
109  ACTION_MENU( true )
110  {
111  SetIcon( BITMAPS::locked );
112  SetTitle( _( "Locking" ) );
113 
114  Add( PCB_ACTIONS::lock );
115  Add( PCB_ACTIONS::unlock );
117  }
118 
119  ACTION_MENU* create() const override
120  {
121  return new LOCK_CONTEXT_MENU();
122  }
123 };
124 
125 
129 class NETLIST_OPTIONS_HELPER : public wxPanel
130 {
131 public:
132  NETLIST_OPTIONS_HELPER( wxWindow* aParent )
133  : wxPanel( aParent )
134  {
135  m_cbOmitExtras = new wxCheckBox( this, wxID_ANY, _( "Omit extra information" ) );
136  m_cbOmitNets = new wxCheckBox( this, wxID_ANY, _( "Omit nets" ) );
137  m_cbOmitFpUuids = new wxCheckBox( this, wxID_ANY,
138  _( "Do not prefix path with footprint UUID." ) );
139 
140  wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
141  sizer->Add( m_cbOmitExtras, 0, wxALL, 5 );
142  sizer->Add( m_cbOmitNets, 0, wxALL, 5 );
143  sizer->Add( m_cbOmitFpUuids, 0, wxALL, 5 );
144 
145  SetSizerAndFit( sizer );
146  }
147 
148  int GetNetlistOptions() const
149  {
150  int options = 0;
151 
152  if( m_cbOmitExtras->GetValue() )
153  options |= CTL_OMIT_EXTRA;
154 
155  if( m_cbOmitNets->GetValue() )
156  options |= CTL_OMIT_NETS;
157 
158  if( m_cbOmitFpUuids->GetValue() )
159  options |= CTL_OMIT_FP_UUID;
160 
161  return options;
162  }
163 
164  static wxWindow* Create( wxWindow* aParent )
165  {
166  return new NETLIST_OPTIONS_HELPER( aParent );
167  }
168 
169 protected:
170  wxCheckBox* m_cbOmitExtras;
171  wxCheckBox* m_cbOmitNets;
172  wxCheckBox* m_cbOmitFpUuids;
173 };
174 
175 
177  PCB_TOOL_BASE( "pcbnew.EditorControl" ),
178  m_frame( nullptr ),
179  m_inPlaceFootprint( false ),
180  m_placingFootprint( false ),
181  m_inPlaceTarget( false )
182 {
183  m_placeOrigin = std::make_unique<KIGFX::ORIGIN_VIEWITEM>( KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
185 }
186 
187 
189 {
190 }
191 
192 
194 {
195  m_frame = getEditFrame<PCB_EDIT_FRAME>();
196 
197  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
198  {
199  m_placeOrigin->SetPosition( getModel<BOARD>()->GetDesignSettings().m_AuxOrigin );
200  getView()->Remove( m_placeOrigin.get() );
201  getView()->Add( m_placeOrigin.get() );
202  }
203 }
204 
205 
207 {
208  auto activeToolCondition =
209  [this]( const SELECTION& aSel )
210  {
211  return ( !m_frame->ToolStackIsEmpty() );
212  };
213 
214  auto inactiveStateCondition =
215  [this]( const SELECTION& aSel )
216  {
217  return ( m_frame->ToolStackIsEmpty() && aSel.Size() == 0 );
218  };
219 
220  auto placeModuleCondition =
221  [this]( const SELECTION& aSel )
222  {
223  return m_frame->IsCurrentTool( PCB_ACTIONS::placeFootprint ) && aSel.GetSize() == 0;
224  };
225 
226  auto& ctxMenu = m_menu.GetMenu();
227 
228  // "Cancel" goes at the top of the context menu when a tool is active
229  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
230  ctxMenu.AddSeparator( 1 );
231 
232  // "Get and Place Footprint" should be available for Place Footprint tool
233  ctxMenu.AddItem( PCB_ACTIONS::getAndPlace, placeModuleCondition, 1000 );
234  ctxMenu.AddSeparator( 1000 );
235 
236  // Finally, add the standard zoom & grid items
237  getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
238 
239  auto zoneMenu = std::make_shared<ZONE_CONTEXT_MENU>();
240  zoneMenu->SetTool( this );
241 
242  auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>();
243  lockMenu->SetTool( this );
244 
245  // Add the PCB control menus to relevant other tools
246 
248 
249  if( selTool )
250  {
251  auto& toolMenu = selTool->GetToolMenu();
252  auto& menu = toolMenu.GetMenu();
253 
254  // Add "Get and Place Footprint" when Selection tool is in an inactive state
255  menu.AddItem( PCB_ACTIONS::getAndPlace, inactiveStateCondition );
256  menu.AddSeparator();
257 
258  toolMenu.AddSubMenu( zoneMenu );
259  toolMenu.AddSubMenu( lockMenu );
260 
261  menu.AddMenu( lockMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 );
262 
263  menu.AddMenu( zoneMenu.get(), SELECTION_CONDITIONS::OnlyType( PCB_ZONE_T ), 200 );
264  }
265 
266  DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
267 
268  if( drawingTool )
269  {
270  auto& toolMenu = drawingTool->GetToolMenu();
271  auto& menu = toolMenu.GetMenu();
272 
273  toolMenu.AddSubMenu( zoneMenu );
274 
275  // Functor to say if the PCB_EDIT_FRAME is in a given mode
276  // Capture the tool pointer and tool mode by value
277  auto toolActiveFunctor =
278  [=]( DRAWING_TOOL::MODE aMode )
279  {
280  return [=]( const SELECTION& sel )
281  {
282  return drawingTool->GetDrawingMode() == aMode;
283  };
284  };
285 
286  menu.AddMenu( zoneMenu.get(), toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ), 200 );
287  }
288 
289  return true;
290 }
291 
292 
294 {
296  return 0;
297 }
298 
299 
301 {
303  return 0;
304 }
305 
306 
308 {
310  return 0;
311 }
312 
313 
315 {
317  return 0;
318 }
319 
320 
322 {
324  return 0;
325 }
326 
327 
329 {
330  PICKED_ITEMS_LIST undoCmd;
331  DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( m_frame );
332  ITEM_PICKER wrapper( nullptr, undoItem, UNDO_REDO::PAGESETTINGS );
333 
334  undoCmd.PushItem( wrapper );
336 
340 
341  if( dlg.ShowModal() != wxID_OK )
343 
344  return 0;
345 }
346 
347 
349 {
351  return 0;
352 }
353 
354 
356 {
358  return 0;
359 }
360 
361 
363 {
364  m_frame->FindNext();
365  return 0;
366 }
367 
368 
370 {
371  getEditFrame<PCB_EDIT_FRAME>()->ShowBoardSetupDialog();
372  return 0;
373 }
374 
375 
377 {
378  getEditFrame<PCB_EDIT_FRAME>()->InstallNetlistFrame();
379  return 0;
380 }
381 
382 
384 {
385  wxString fullFileName = frame()->GetBoard()->GetFileName();
386  wxString path;
387  wxString name;
388  wxString ext;
389 
390  wxFileName::SplitPath( fullFileName, &path, &name, &ext );
391  name += wxT( "." ) + SpecctraSessionFileExtension;
392 
393  fullFileName = wxFileSelector( _( "Specctra Session File" ), path, name,
394  wxT( "." ) + SpecctraSessionFileExtension,
395  SpecctraSessionFileWildcard(), wxFD_OPEN | wxFD_CHANGE_DIR,
396  frame() );
397 
398  if( !fullFileName.IsEmpty() )
399  getEditFrame<PCB_EDIT_FRAME>()->ImportSpecctraSession( fullFileName );
400 
401  return 0;
402 }
403 
404 
406 {
407  wxString fullFileName = m_frame->GetLastPath( LAST_PATH_SPECCTRADSN );
408  wxFileName fn;
409 
410  if( fullFileName.IsEmpty() )
411  {
412  fn = m_frame->GetBoard()->GetFileName();
413  fn.SetExt( SpecctraDsnFileExtension );
414  }
415  else
416  {
417  fn = fullFileName;
418  }
419 
420  fullFileName = wxFileSelector( _( "Specctra DSN File" ), fn.GetPath(), fn.GetFullName(),
422  wxFD_SAVE | wxFD_OVERWRITE_PROMPT | wxFD_CHANGE_DIR, frame() );
423 
424  if( !fullFileName.IsEmpty() )
425  {
426  m_frame->SetLastPath( LAST_PATH_SPECCTRADSN, fullFileName );
427  getEditFrame<PCB_EDIT_FRAME>()->ExportSpecctraFile( fullFileName );
428  }
429 
430  return 0;
431 }
432 
433 
435 {
436  wxCHECK( m_frame, 0 );
437 
438  wxFileName fn = m_frame->Prj().GetProjectFullName();
439 
440  // Use a different file extension for the board netlist so the schematic netlist file
441  // is accidentally overwritten.
442  fn.SetExt( "pcb_net" );
443 
444  wxFileDialog dlg( m_frame, _( "Export Board Netlist" ), fn.GetPath(), fn.GetFullName(),
445  _( "KiCad board netlist files" ) + AddFileExtListToFilter( { "pcb_net" } ),
446  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
447 
448  dlg.SetExtraControlCreator( &NETLIST_OPTIONS_HELPER::Create );
449 
450  if( dlg.ShowModal() == wxID_CANCEL )
451  return 0;
452 
453  fn = dlg.GetPath();
454 
455  if( !fn.IsDirWritable() )
456  {
457  wxString msg;
458 
459  msg.Printf( _( "Path `%s` is read only." ), fn.GetPath() );
460  wxMessageDialog( m_frame, msg, _( "I/O Error" ), wxOK | wxCENTER | wxICON_EXCLAMATION );
461  return 0;
462  }
463 
464  const NETLIST_OPTIONS_HELPER* noh =
465  dynamic_cast<const NETLIST_OPTIONS_HELPER*>( dlg.GetExtraControl() );
466  wxCHECK( noh, 0 );
467 
469 
470  for( const FOOTPRINT* footprint : board()->Footprints() )
471  {
472  COMPONENT* component = new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
474  { footprint->m_Uuid } );
475 
476  for( const PAD* pad : footprint->Pads() )
477  {
478  const wxString& netname = pad->GetShortNetname();
479 
480  if( !netname.IsEmpty() )
481  {
482  component->AddNet( pad->GetNumber(), netname, pad->GetPinFunction(),
483  pad->GetPinType() );
484  }
485  }
486 
487  netlist.AddComponent( component );
488  }
489 
490  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
491 
492  netlist.Format( "pcb_netlist", &formatter, 0, noh->GetNetlistOptions() );
493 
494  return 0;
495 }
496 
497 
499 {
500  wxCommandEvent dummy;
501 
502  if( aEvent.IsAction( &PCB_ACTIONS::generateGerbers ) )
504  else if( aEvent.IsAction( &PCB_ACTIONS::generateReportFile ) )
506  else if( aEvent.IsAction( &PCB_ACTIONS::generateD356File ) )
508  else if( aEvent.IsAction( &PCB_ACTIONS::generateBOM ) )
510  else
511  wxFAIL_MSG( "GenerateFabFiles(): unexpected request" );
512 
513  return 0;
514 }
515 
516 
518 {
519  int errors = 0;
520  wxString details;
521  bool quiet = aEvent.Parameter<bool>();
522 
523  // Repair duplicate IDs and missing nets.
524  std::set<KIID> ids;
525  int duplicates = 0;
526 
527  auto processItem =
528  [&]( EDA_ITEM* aItem )
529  {
530  if( ids.count( aItem->m_Uuid ) )
531  {
532  duplicates++;
533  const_cast<KIID&>( aItem->m_Uuid ) = KIID();
534  }
535 
536  ids.insert( aItem->m_Uuid );
537 
538  BOARD_CONNECTED_ITEM* cItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem );
539 
540  if( cItem && cItem->GetNetCode() )
541  {
542  NETINFO_ITEM* netinfo = cItem->GetNet();
543 
544  if( netinfo && !board()->FindNet( netinfo->GetNetname() ) )
545  {
546  board()->Add( netinfo );
547 
548  details += wxString::Format( _( "Orphaned net %s re-parented.\n" ),
549  netinfo->GetNetname() );
550  errors++;
551  }
552  }
553  };
554 
555  // Footprint IDs are the most important, so give them the first crack at "claiming" a
556  // particular KIID.
557 
558  for( FOOTPRINT* footprint : board()->Footprints() )
559  processItem( footprint );
560 
561  // After that the principal use is for DRC marker pointers, which are most likely to pads
562  // or tracks.
563 
564  for( FOOTPRINT* footprint : board()->Footprints() )
565  {
566  for( PAD* pad : footprint->Pads() )
567  processItem( pad );
568  }
569 
570  for( PCB_TRACK* track : board()->Tracks() )
571  processItem( track );
572 
573  // From here out I don't think order matters much.
574 
575  for( FOOTPRINT* footprint : board()->Footprints() )
576  {
577  processItem( &footprint->Reference() );
578  processItem( &footprint->Value() );
579 
580  for( BOARD_ITEM* item : footprint->GraphicalItems() )
581  processItem( item );
582 
583  for( ZONE* zone : footprint->Zones() )
584  processItem( zone );
585 
586  for( PCB_GROUP* group : footprint->Groups() )
587  processItem( group );
588  }
589 
590  for( BOARD_ITEM* drawing : board()->Drawings() )
591  processItem( drawing );
592 
593  for( ZONE* zone : board()->Zones() )
594  processItem( zone );
595 
596  for( PCB_MARKER* marker : board()->Markers() )
597  processItem( marker );
598 
599  for( PCB_GROUP* group : board()->Groups() )
600  processItem( group );
601 
602  if( duplicates )
603  {
604  errors += duplicates;
605  details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
606  }
607 
608  /*******************************
609  * Your test here
610  */
611 
612  /*******************************
613  * Inform the user
614  */
615 
616  if( errors )
617  {
618  m_frame->OnModify();
619 
620  wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
621 
622  if( !quiet )
623  DisplayInfoMessage( m_frame, msg, details );
624  }
625  else if( !quiet )
626  {
627  DisplayInfoMessage( m_frame, _( "No board problems found." ) );
628  }
629 
630  return 0;
631 }
632 
633 
635 {
637 
638  if( m_frame->FetchNetlistFromSchematic( netlist, _( "Updating PCB requires a fully annotated "
639  "schematic." ) ) )
640  {
641  DIALOG_UPDATE_PCB updateDialog( m_frame, &netlist );
642  updateDialog.ShowModal();
643  }
644 
645  return 0;
646 }
647 
649 {
650  if( Kiface().IsSingle() )
651  {
653  m_frame, _( "Cannot update schematic because Pcbnew is opened in stand-alone "
654  "mode. In order to create or update PCBs from schematics, you "
655  "must launch the KiCad project manager and create a project." ) );
656  return 0;
657  }
658 
659  m_frame->RunEeschema();
661 
662  if( frame )
663  {
664  std::string payload;
666  }
667  return 0;
668 }
669 
670 
672 {
673  m_frame->RunEeschema();
674  return 0;
675 }
676 
677 
679 {
680  getEditFrame<PCB_EDIT_FRAME>()->ToggleLayersManager();
681  return 0;
682 }
683 
684 
686 {
688  return 0;
689 }
690 
691 
692 // Track & via size control
694 {
695  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
696  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
698 
700  {
701  BOARD_COMMIT commit( this );
702 
703  for( EDA_ITEM* item : selection )
704  {
705  if( item->Type() == PCB_TRACE_T )
706  {
707  PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
708 
709  for( int candidate : designSettings.m_TrackWidthList )
710  {
711  if( candidate > track->GetWidth() )
712  {
713  commit.Modify( track );
714  track->SetWidth( candidate );
715  break;
716  }
717  }
718  }
719  }
720 
721  commit.Push( "Increase Track Width" );
722  return 0;
723  }
724 
725  ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
726 
727  if( routerTool && routerTool->IsToolActive()
728  && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR )
729  {
730  int widthIndex = designSettings.GetDiffPairIndex() + 1;
731 
732  // If we go past the last track width entry in the list, start over at the beginning
733  if( widthIndex >= (int) designSettings.m_DiffPairDimensionsList.size() )
734  widthIndex = 0;
735 
736  designSettings.SetDiffPairIndex( widthIndex );
737  designSettings.UseCustomDiffPairDimensions( false );
738 
740  }
741  else
742  {
743  int widthIndex = designSettings.GetTrackWidthIndex() + 1;
744 
745  // If we go past the last track width entry in the list, start over at the beginning
746  if( widthIndex >= (int) designSettings.m_TrackWidthList.size() )
747  widthIndex = 0;
748 
749  designSettings.SetTrackWidthIndex( widthIndex );
750  designSettings.UseCustomTrackViaSize( false );
751 
753  }
754 
755  return 0;
756 }
757 
758 
760 {
761  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
762  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
764 
766  {
767  BOARD_COMMIT commit( this );
768 
769  for( EDA_ITEM* item : selection )
770  {
771  if( item->Type() == PCB_TRACE_T )
772  {
773  PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
774 
775  for( int i = designSettings.m_TrackWidthList.size() - 1; i >= 0; --i )
776  {
777  int candidate = designSettings.m_TrackWidthList[ i ];
778 
779  if( candidate < track->GetWidth() )
780  {
781  commit.Modify( track );
782  track->SetWidth( candidate );
783  break;
784  }
785  }
786  }
787  }
788 
789  commit.Push( "Decrease Track Width" );
790  return 0;
791  }
792 
793  ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
794 
795  if( routerTool && routerTool->IsToolActive()
796  && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR )
797  {
798  int widthIndex = designSettings.GetDiffPairIndex() - 1;
799 
800  // If we get to the lowest entry start over at the highest
801  if( widthIndex < 0 )
802  widthIndex = designSettings.m_DiffPairDimensionsList.size() - 1;
803 
804  designSettings.SetDiffPairIndex( widthIndex );
805  designSettings.UseCustomDiffPairDimensions( false );
806 
808  }
809  else
810  {
811  int widthIndex = designSettings.GetTrackWidthIndex() - 1;
812 
813  // If we get to the lowest entry start over at the highest
814  if( widthIndex < 0 )
815  widthIndex = designSettings.m_TrackWidthList.size() - 1;
816 
817  designSettings.SetTrackWidthIndex( widthIndex );
818  designSettings.UseCustomTrackViaSize( false );
819 
821  }
822 
823  return 0;
824 }
825 
826 
828 {
829  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
830  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
832 
834  {
835  BOARD_COMMIT commit( this );
836 
837  for( EDA_ITEM* item : selection )
838  {
839  if( item->Type() == PCB_VIA_T )
840  {
841  PCB_VIA* via = static_cast<PCB_VIA*>( item );
842 
843  for( VIA_DIMENSION candidate : designSettings.m_ViasDimensionsList )
844  {
845  if( candidate.m_Diameter > via->GetWidth() )
846  {
847  commit.Modify( via );
848  via->SetWidth( candidate.m_Diameter );
849  via->SetDrill( candidate.m_Drill );
850  break;
851  }
852  }
853  }
854  }
855 
856  commit.Push( "Increase Via Size" );
857  }
858  else
859  {
860  int sizeIndex = designSettings.GetViaSizeIndex() + 1;
861 
862  // If we go past the last via entry in the list, start over at the beginning
863  if( sizeIndex >= (int) designSettings.m_ViasDimensionsList.size() )
864  sizeIndex = 0;
865 
866  designSettings.SetViaSizeIndex( sizeIndex );
867  designSettings.UseCustomTrackViaSize( false );
868 
870  }
871 
872  return 0;
873 }
874 
875 
877 {
878  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
879  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
881 
883  {
884  BOARD_COMMIT commit( this );
885 
886  for( EDA_ITEM* item : selection )
887  {
888  if( item->Type() == PCB_VIA_T )
889  {
890  PCB_VIA* via = static_cast<PCB_VIA*>( item );
891 
892  for( int i = designSettings.m_ViasDimensionsList.size() - 1; i >= 0; --i )
893  {
894  VIA_DIMENSION candidate = designSettings.m_ViasDimensionsList[ i ];
895 
896  if( candidate.m_Diameter < via->GetWidth() )
897  {
898  commit.Modify( via );
899  via->SetWidth( candidate.m_Diameter );
900  via->SetDrill( candidate.m_Drill );
901  break;
902  }
903  }
904  }
905  }
906 
907  commit.Push( "Decrease Via Size" );
908  }
909  else
910  {
911  int sizeIndex = 0; // Assume we only have a single via size entry
912 
913  // If there are more, cycle through them backwards
914  if( designSettings.m_ViasDimensionsList.size() > 0 )
915  {
916  sizeIndex = designSettings.GetViaSizeIndex() - 1;
917 
918  // If we get to the lowest entry start over at the highest
919  if( sizeIndex < 0 )
920  sizeIndex = designSettings.m_ViasDimensionsList.size() - 1;
921  }
922 
923  designSettings.SetViaSizeIndex( sizeIndex );
924  designSettings.UseCustomTrackViaSize( false );
925 
927  }
928 
929  return 0;
930 }
931 
932 
934 {
935  if( m_inPlaceFootprint )
936  return 0;
937 
939 
940  FOOTPRINT* fp = aEvent.Parameter<FOOTPRINT*>();
942  BOARD_COMMIT commit( m_frame );
943  BOARD* board = getModel<BOARD>();
944 
946 
947  std::string tool = aEvent.GetCommandStr().get();
948  m_frame->PushTool( tool );
949 
950  auto setCursor =
951  [&]()
952  {
954  };
955 
956  Activate();
957  // Must be done after Activate() so that it gets set into the correct context
958  controls->ShowCursor( true );
959  // Set initial cursor
960  setCursor();
961 
962  VECTOR2I cursorPos = controls->GetCursorPosition();
963  bool reselect = false;
964  bool fromOtherCommand = fp != nullptr;
965 
966  // Prime the pump
967  if( fp )
968  {
969  m_placingFootprint = true;
970  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
973  }
974  else if( !aEvent.IsReactivate() )
975  {
977  }
978 
979  // Main loop: keep receiving events
980  while( TOOL_EVENT* evt = Wait() )
981  {
982  setCursor();
983  cursorPos = controls->GetCursorPosition( !evt->DisableGridSnapping() );
984 
985  if( reselect && fp )
987 
988  auto cleanup =
989  [&] ()
990  {
992  commit.Revert();
993 
994  if( fromOtherCommand )
995  {
997 
998  if( undo )
999  {
1001  undo->ClearListAndDeleteItems();
1002  delete undo;
1003  }
1004  }
1005 
1006  fp = nullptr;
1007  m_placingFootprint = false;
1008  };
1009 
1010  if( evt->IsCancelInteractive() )
1011  {
1012  if( fp )
1013  {
1014  cleanup();
1015  }
1016  else
1017  {
1018  m_frame->PopTool( tool );
1019  break;
1020  }
1021  }
1022  else if( evt->IsActivate() )
1023  {
1024  if( fp )
1025  cleanup();
1026 
1027  if( evt->IsMoveTool() )
1028  {
1029  // leave ourselves on the stack so we come back after the move
1030  break;
1031  }
1032  else
1033  {
1034  frame()->PopTool( tool );
1035  break;
1036  }
1037  }
1038  else if( evt->IsClick( BUT_LEFT ) )
1039  {
1040  if( !fp )
1041  {
1042  // Pick the footprint to be placed
1044 
1045  if( fp == nullptr )
1046  continue;
1047 
1048  m_placingFootprint = true;
1049 
1050  fp->SetLink( niluuid );
1051 
1052  fp->SetFlags(IS_NEW ); // whatever
1053 
1054  // Set parent so that clearance can be loaded
1055  fp->SetParent( board );
1056 
1057  for( PAD* pad : fp->Pads() )
1058  {
1059  pad->SetLocalRatsnestVisible( m_frame->GetDisplayOptions().m_ShowGlobalRatsnest );
1060 
1061  // Pads in the library all have orphaned nets. Replace with Default.
1062  pad->SetNetCode( 0 );
1063  }
1064 
1065  // Put it on FRONT layer,
1066  // (Can be stored flipped if the lib is an archive built from a board)
1067  if( fp->IsFlipped() )
1068  fp->Flip( fp->GetPosition(), m_frame->Settings().m_FlipLeftRight );
1069 
1070  fp->SetOrientation( 0 );
1071  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1072 
1073  commit.Add( fp );
1075  controls->SetCursorPosition( cursorPos, false );
1076  }
1077  else
1078  {
1080  commit.Push( _( "Place a footprint" ) );
1081  fp = nullptr; // to indicate that there is no footprint that we currently modify
1082  m_placingFootprint = false;
1083  }
1084  }
1085  else if( evt->IsClick( BUT_RIGHT ) )
1086  {
1088  }
1089  else if( fp && ( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) ) )
1090  {
1091  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1092  selection().SetReferencePoint( cursorPos );
1093  getView()->Update( &selection() );
1094  getView()->Update( fp );
1095  }
1096  else if( fp && evt->IsAction( &PCB_ACTIONS::properties ) )
1097  {
1098  // Calling 'Properties' action clears the selection, so we need to restore it
1099  reselect = true;
1100  }
1101  else
1102  {
1103  evt->SetPassEvent();
1104  }
1105 
1106  // Enable autopanning and cursor capture only when there is a footprint to be placed
1107  controls->SetAutoPan( fp != nullptr );
1108  controls->CaptureCursor( fp != nullptr );
1109  }
1110 
1111  controls->SetAutoPan( false );
1112  controls->CaptureCursor( false );
1114 
1115  return 0;
1116 }
1117 
1118 
1120 {
1121  return modifyLockSelected( TOGGLE );
1122 }
1123 
1124 
1126 {
1127  return modifyLockSelected( ON );
1128 }
1129 
1130 
1132 {
1133  return modifyLockSelected( OFF );
1134 }
1135 
1136 
1138 {
1140  const PCB_SELECTION& selection = selTool->GetSelection();
1141  BOARD_COMMIT commit( m_frame );
1142 
1143  if( selection.Empty() )
1145 
1146  // Resolve TOGGLE mode
1147  if( aMode == TOGGLE )
1148  {
1149  aMode = ON;
1150 
1151  for( EDA_ITEM* item : selection )
1152  {
1153  BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
1154 
1155  if( board_item->IsLocked() )
1156  {
1157  aMode = OFF;
1158  break;
1159  }
1160  }
1161  }
1162 
1163  bool modified = false;
1164 
1165  for( EDA_ITEM* item : selection )
1166  {
1167  BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
1168 
1169  commit.Modify( board_item );
1170 
1171  if( aMode == ON )
1172  {
1173  modified |= !board_item->IsLocked();
1174  board_item->SetLocked( true );
1175  }
1176  else
1177  {
1178  modified |= board_item->IsLocked();
1179  board_item->SetLocked( false );
1180  }
1181  }
1182 
1183  if( modified )
1184  {
1185  commit.Push( aMode == ON ? _( "Lock" ) : _( "Unlock" ) );
1186 
1189  m_frame->OnModify();
1190  }
1191 
1192  return 0;
1193 }
1194 
1195 
1197 {
1198  if( m_inPlaceTarget )
1199  return 0;
1200 
1202 
1203  KIGFX::VIEW* view = getView();
1205  BOARD* board = getModel<BOARD>();
1206  PCB_TARGET* target = new PCB_TARGET( board );
1207 
1208  // Init the new item attributes
1209  target->SetLayer( Edge_Cuts );
1211  target->SetSize( Millimeter2iu( 5 ) );
1212  VECTOR2I cursorPos = controls->GetCursorPosition();
1213  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1214 
1215  // Add a VIEW_GROUP that serves as a preview for the new item
1216  KIGFX::VIEW_GROUP preview( view );
1217  preview.Add( target );
1218  view->Add( &preview );
1219 
1221 
1222  std::string tool = aEvent.GetCommandStr().get();
1223  m_frame->PushTool( tool );
1224  Activate();
1225 
1226  auto setCursor =
1227  [&]()
1228  {
1230  };
1231 
1232  // Set initial cursor
1233  setCursor();
1234 
1235  // Main loop: keep receiving events
1236  while( TOOL_EVENT* evt = Wait() )
1237  {
1238  setCursor();
1239  cursorPos = controls->GetCursorPosition( !evt->DisableGridSnapping() );
1240 
1241  if( evt->IsCancelInteractive() )
1242  {
1243  frame()->PopTool( tool );
1244  break;
1245  }
1246  else if( evt->IsActivate() )
1247  {
1248  if( evt->IsMoveTool() )
1249  {
1250  // leave ourselves on the stack so we come back after the move
1251  break;
1252  }
1253  else
1254  {
1255  frame()->PopTool( tool );
1256  break;
1257  }
1258  }
1259  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1260  {
1261  target->SetWidth( target->GetWidth() + WIDTH_STEP );
1262  view->Update( &preview );
1263  }
1264  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) )
1265  {
1266  int width = target->GetWidth();
1267 
1268  if( width > WIDTH_STEP )
1269  {
1270  target->SetWidth( width - WIDTH_STEP );
1271  view->Update( &preview );
1272  }
1273  }
1274  else if( evt->IsClick( BUT_LEFT ) )
1275  {
1276  assert( target->GetSize() > 0 );
1277  assert( target->GetWidth() > 0 );
1278 
1279  BOARD_COMMIT commit( m_frame );
1280  commit.Add( target );
1281  commit.Push( "Place a layer alignment target" );
1282 
1283  preview.Remove( target );
1284 
1285  // Create next PCB_TARGET
1286  target = new PCB_TARGET( *target );
1287  preview.Add( target );
1288  }
1289  else if( evt->IsClick( BUT_RIGHT ) )
1290  {
1292  }
1293  else if( evt->IsMotion() )
1294  {
1295  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1296  view->Update( &preview );
1297  }
1298  else
1299  {
1300  evt->SetPassEvent();
1301  }
1302  }
1303 
1304  preview.Clear();
1305  delete target;
1306  view->Remove( &preview );
1307 
1309 
1310  return 0;
1311 }
1312 
1313 
1314 static bool mergeZones( BOARD_COMMIT& aCommit, std::vector<ZONE*>& aOriginZones,
1315  std::vector<ZONE*>& aMergedZones )
1316 {
1317  aCommit.Modify( aOriginZones[0] );
1318 
1319  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
1320  {
1321  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
1323  }
1324 
1325  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
1326 
1327  // We should have one polygon with hole
1328  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
1329  // and therefore cannot be merged (they are detected as intersecting)
1330  // but we should never have more than 2 polys
1331  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
1332  {
1333  wxLogMessage( "BOARD::mergeZones error: more than 2 polys after merging" );
1334  return false;
1335  }
1336 
1337  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
1338  aCommit.Remove( aOriginZones[i] );
1339 
1340  aMergedZones.push_back( aOriginZones[0] );
1341 
1342  aOriginZones[0]->SetLocalFlags( 1 );
1343  aOriginZones[0]->HatchBorder();
1344  aOriginZones[0]->CacheTriangulation();
1345 
1346  return true;
1347 }
1348 
1349 
1351 {
1352  const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
1353  BOARD* board = getModel<BOARD>();
1354  BOARD_COMMIT commit( m_frame );
1355 
1356  if( selection.Size() < 2 )
1357  return 0;
1358 
1359  int netcode = -1;
1360 
1361  ZONE* firstZone = nullptr;
1362  std::vector<ZONE*> toMerge, merged;
1363 
1364  for( EDA_ITEM* item : selection )
1365  {
1366  ZONE* curr_area = dynamic_cast<ZONE*>( item );
1367 
1368  if( !curr_area )
1369  continue;
1370 
1371  if( !firstZone )
1372  firstZone = curr_area;
1373 
1374  netcode = curr_area->GetNetCode();
1375 
1376  if( firstZone->GetNetCode() != netcode )
1377  continue;
1378 
1379  if( curr_area->GetPriority() != firstZone->GetPriority() )
1380  continue;
1381 
1382  if( curr_area->GetIsRuleArea() != firstZone->GetIsRuleArea() )
1383  continue;
1384 
1385  if( curr_area->GetLayer() != firstZone->GetLayer() )
1386  continue;
1387 
1388  if( !board->TestZoneIntersection( curr_area, firstZone ) )
1389  continue;
1390 
1391  toMerge.push_back( curr_area );
1392  }
1393 
1395 
1396  if( mergeZones( commit, toMerge, merged ) )
1397  {
1398  commit.Push( "Merge zones" );
1399 
1400  for( EDA_ITEM* item : merged )
1402  }
1403 
1404  return 0;
1405 }
1406 
1407 
1409 {
1411  const PCB_SELECTION& selection = selTool->GetSelection();
1412 
1413  // because this pops up the zone editor, it would be confusing to handle multiple zones,
1414  // so just handle single selections containing exactly one zone
1415  if( selection.Size() != 1 )
1416  return 0;
1417 
1418  ZONE* oldZone = dyn_cast<ZONE*>( selection[0] );
1419 
1420  if( !oldZone )
1421  return 0;
1422 
1423  ZONE_SETTINGS zoneSettings;
1424  zoneSettings << *oldZone;
1425  int dialogResult;
1426 
1427  if( oldZone->GetIsRuleArea() )
1428  dialogResult = InvokeRuleAreaEditor( m_frame, &zoneSettings );
1429  else if( oldZone->IsOnCopperLayer() )
1430  dialogResult = InvokeCopperZonesEditor( m_frame, &zoneSettings );
1431  else
1432  dialogResult = InvokeNonCopperZonesEditor( m_frame, &zoneSettings );
1433 
1434  if( dialogResult != wxID_OK )
1435  return 0;
1436 
1437  // duplicate the zone
1438  BOARD_COMMIT commit( m_frame );
1439 
1440  std::unique_ptr<ZONE> newZone = std::make_unique<ZONE>( *oldZone );
1441  newZone->ClearSelected();
1442  newZone->UnFill();
1443  zoneSettings.ExportSetting( *newZone );
1444 
1445  // If the new zone is on the same layer(s) as the initial zone,
1446  // offset it a bit so it can more easily be picked.
1447  if( oldZone->GetIsRuleArea() && ( oldZone->GetLayerSet() == zoneSettings.m_Layers ) )
1448  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
1449  else if( !oldZone->GetIsRuleArea() && zoneSettings.m_Layers.test( oldZone->GetLayer() ) )
1450  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
1451 
1452  commit.Add( newZone.release() );
1453  commit.Push( _( "Duplicate zone" ) );
1454 
1455  return 0;
1456 }
1457 
1458 
1460 {
1463 
1464  if( selection.Empty() )
1465  return 0;
1466 
1468 
1469  if( !fp )
1470  return 0;
1471 
1472  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1473 
1474  auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
1475 
1476  editor->LoadFootprintFromBoard( fp );
1477 
1478  editor->Show( true );
1479  editor->Raise(); // Iconize( false );
1480 
1481  if( selection.IsHover() )
1483 
1484  return 0;
1485 }
1486 
1487 
1489  EDA_ITEM* originViewItem, const VECTOR2D& aPosition )
1490 {
1491  aFrame->GetDesignSettings().m_AuxOrigin = (wxPoint) aPosition;
1492  originViewItem->SetPosition( (wxPoint) aPosition );
1493  aView->MarkDirty();
1494  aFrame->OnModify();
1495 }
1496 
1497 
1499 {
1500  std::string tool = aEvent.GetCommandStr().get();
1502 
1503  // Deactivate other tools; particularly important if another PICKER is currently running
1504  Activate();
1505 
1506  picker->SetClickHandler(
1507  [this] ( const VECTOR2D& pt ) -> bool
1508  {
1510  DoSetDrillOrigin( getView(), m_frame, m_placeOrigin.get(), pt );
1511  return false; // drill origin is a one-shot; don't continue with tool
1512  } );
1513 
1514  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1515 
1516  return 0;
1517 }
1518 
1519 
1521 {
1522  Go( &BOARD_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
1523  Go( &BOARD_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
1524  Go( &BOARD_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
1528  Go( &BOARD_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
1529 
1530  Go( &BOARD_EDITOR_CONTROL::Find, ACTIONS::find.MakeEvent() );
1532 
1536  PCB_ACTIONS::importSpecctraSession.MakeEvent() );
1538 
1539  if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist && m_frame &&
1542 
1544  PCB_ACTIONS::generateDrillFiles.MakeEvent() );
1548  PCB_ACTIONS::generateReportFile.MakeEvent() );
1551 
1552  // Track & via size control
1557 
1558  // Zone actions
1561 
1562  // Placing tools
1566 
1568 
1569  // Other
1573 
1575  ACTIONS::updatePcbFromSchematic.MakeEvent() );
1577  ACTIONS::updateSchematicFromPcb.MakeEvent() );
1582 }
1583 
1584 
1585 const int BOARD_EDITOR_CONTROL::WIDTH_STEP = 100000;
int Open(const TOOL_EVENT &aEvent)
int LockSelected(const TOOL_EVENT &aEvent)
Unlock selected items.
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
static TOOL_ACTION toggleLock
Definition: pcb_actions.h:423
void RollbackFromUndo()
Perform an undo of the last edit without logging a corresponding redo.
Definition: undo_redo.cpp:578
Container to handle a stock of specific vias each with unique diameter and drill sizes in the BOARD c...
void OnModify() override
Must be called after a board change to set the modified flag.
int Find(const TOOL_EVENT &aEvent)
bool IsCurrentTool(const TOOL_ACTION &aAction) const
#define CTL_OMIT_FP_UUID
Don't prefix the footprint UUID to the sheet path.
Definition: pcb_netlist.h:283
COMMIT & Modify(EDA_ITEM *aItem)
Create an undo entry for an item that has been already modified.
Definition: commit.h:103
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
static const TOOL_EVENT SelectedEvent
Definition: actions.h:199
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
void SetTrackWidthIndex(unsigned aIndex)
Set the current track width list index to aIndex.
int New(const TOOL_EVENT &aEvent)
static TOOL_ACTION unlock
Definition: pcb_actions.h:425
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
KIID niluuid(0)
bool IsHover() const
Definition: selection.h:74
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
NETLIST_OPTIONS_HELPER(wxWindow *aParent)
void SaveCopyInUndoList(EDA_ITEM *aItemToCopy, UNDO_REDO aTypeCommand) override
Create a new entry in undo list of commands.
Definition: undo_redo.cpp:179
static TOOL_ACTION generateGerbers
Definition: pcb_actions.h:336
ZONES & Zones()
Definition: board.h:239
int ExportSpecctraDSN(const TOOL_EVENT &aEvent)
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
const wxString & GetValue() const
Definition: footprint.h:485
BOARD * board() const
static TOOL_ACTION editFpInFpEditor
Definition: pcb_actions.h:346
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:292
static TOOL_ACTION pageSettings
Definition: actions.h:56
int TrackWidthInc(const TOOL_EVENT &aEvent)
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:167
const KIID_PATH & GetPath() const
Definition: footprint.h:203
Model changes (required full reload)
Definition: tool_base.h:80
unsigned GetPriority() const
Definition: zone.h:122
static TOOL_ACTION drawSimilarZone
Definition: pcb_actions.h:156
#define IS_NEW
New item, just created.
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:733
static TOOL_ACTION drillOrigin
Definition: pcb_actions.h:438
bool Init() override
Init() is called once upon a registration of the tool.
FOOTPRINT * SelectFootprintFromLibTree(LIB_ID aPreselect=LIB_ID())
Open a dialog to select a footprint.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:161
static TOOL_ACTION lock
Definition: pcb_actions.h:424
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:48
This file is part of the common library.
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:253
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:305
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:298
std::vector< int > m_TrackWidthList
void ToPlotter(int aID)
Open a dialog frame to create plot and drill files relative to the current board.
static void DoSetDrillOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, EDA_ITEM *aItem, const VECTOR2D &aPoint)
void SetSize(int aSize)
Definition: pcb_target.h:61
KIFACE_BASE & Kiface()
Global KIFACE_BASE "get" accessor.
COMMIT & Add(EDA_ITEM *aItem)
Notify observers that aItem has been added.
Definition: commit.h:78
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
static constexpr double IU_PER_MM
Mock up a conversion function.
GROUPS & Groups()
The groups must maintain the following invariants.
Definition: board.h:253
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
int GetSize() const
Definition: pcb_target.h:62
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Create a functor that tests if the selected items are only of given types.
#define CTL_OMIT_NETS
Definition: pcb_netlist.h:281
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing.
int Plot(const TOOL_EVENT &aEvent)
virtual void Revert() override
MARKERS & Markers()
Definition: board.h:242
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:46
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
void UseCustomDiffPairDimensions(bool aEnabled)
Enables/disables custom differential pair dimensions.
static TOOL_ACTION cancelInteractive
Definition: actions.h:62
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:348
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
void SetWksFileName(const wxString &aFilename)
int GeneratePosFile(const TOOL_EVENT &aEvent)
void RecreateBOMFileFromBoard(wxCommandEvent &aEvent)
Create a BOM file from the current loaded board.
static TOOL_ACTION trackWidthDec
Definition: pcb_actions.h:297
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:153
TOOL_MENU & GetToolMenu()
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION getAndPlace
Find an item and start moving.
Definition: pcb_actions.h:468
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:301
static TOOL_ACTION showPythonConsole
Definition: pcb_actions.h:348
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:383
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:477
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.
void PushItem(const ITEM_PICKER &aItem)
Push aItem to the top of the list.
static TOOL_ACTION showLayersManager
Definition: pcb_actions.h:347
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:163
virtual void Clear()
Remove all the stored items from the group.
Definition: view_group.cpp:69
bool FetchNetlistFromSchematic(NETLIST &aNetlist, const wxString &aAnnotateMessage)
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:221
int GetWidth() const
Definition: pcb_track.h:102
int ImportNetlist(const TOOL_EVENT &aEvent)
void ScriptingConsoleEnableDisable()
Toggles the scripting console visibility.
static TOOL_ACTION find
Definition: actions.h:76
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList)
Used in undo or redo command.
Definition: undo_redo.cpp:375
virtual bool IsLocked() const
Definition: board_item.cpp:64
const wxString & GetFileName() const
Definition: board.h:228
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
A base class derived from BOARD_ITEM for items that can be connected and have a net,...
bool TestZoneIntersection(ZONE *aZone1, ZONE *aZone2)
Test for intersection of 2 copper areas.
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
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 generateReportFile
Definition: pcb_actions.h:339
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:304
wxString GetLastPath(LAST_PATH_TYPE aType)
Get the last path for a particular type.
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
int PageSettings(const TOOL_EVENT &aEvent)
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:116
static TOOL_ACTION generateD356File
Definition: pcb_actions.h:340
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PADS & Pads()
Definition: footprint.h:168
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:170
static TOOL_ACTION saveCopyAs
Definition: actions.h:53
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
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:499
int modifyLockSelected(MODIFY_MODE aMode)
Set up handlers for various events.
std::unique_ptr< KIGFX::ORIGIN_VIEWITEM > m_placeOrigin
static TOOL_ACTION pickerTool
Definition: actions.h:155
FP_TEXT & Reference()
Definition: footprint.h:500
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
int GetLineThickness(PCB_LAYER_ID aLayer) const
Return the default graphic segment thickness from the layer class for the given layer.
void SetViaSizeIndex(unsigned aIndex)
Set the current via size list index to aIndex.
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
FP_ZONES & Zones()
Definition: footprint.h:174
static TOOL_ACTION trackWidthInc
Definition: pcb_actions.h:296
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:608
Definition: kiid.h:44
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:187
int GetWidth() const
Definition: pcb_target.h:65
int DrillOrigin(const TOOL_EVENT &aEvent)
Low-level access (below undo) to setting the drill origin.
int ZoneDuplicate(const TOOL_EVENT &aEvent)
void GenFootprintsReport(wxCommandEvent &event)
Call DoGenFootprintsReport to create a footprint report file.
static TOOL_ACTION updateSchematicFromPcb
Definition: actions.h:164
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
wxString SpecctraSessionFileWildcard()
int EditFpInFpEditor(const TOOL_EVENT &aEvent)
const PCB_SELECTION & selection() const
int ViaSizeInc(const TOOL_EVENT &aEvent)
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:206
int UpdatePCBFromSchematic(const TOOL_EVENT &aEvent)
static TOOL_ACTION importNetlist
Definition: pcb_actions.h:331
#define MAX_PAGE_SIZE_PCBNEW_MILS
Definition: page_info.h:40
int UnlockSelected(const TOOL_EVENT &aEvent)
Run the drill origin tool for setting the origin for drill and pick-and-place files.
void ExportSetting(ZONE &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
Tool responsible for drawing graphical elements like lines, arcs, circles, etc.
Definition: drawing_tool.h:50
unsigned GetViaSizeIndex() const
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
virtual PCB_LAYER_ID GetLayer() const override
Return the primary layer this item is on.
Definition: zone.cpp:222
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static TOOL_ACTION open
Definition: actions.h:50
static const int WIDTH_STEP
How does line width change after one -/+ key press.
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
void SetOrientation(double aNewAngle)
Definition: footprint.cpp:1662
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION doNew
Definition: actions.h:44
FOOTPRINTS & Footprints()
Definition: board.h:233
void SetPosition(const wxPoint &aPos) override
Definition: pcb_target.h:55
Generic, UI-independent tool event.
Definition: tool_event.h:152
int BoardSetup(const TOOL_EVENT &aEvent)
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:1472
static TOOL_ACTION zoneMerge
Definition: pcb_actions.h:308
FOOTPRINT * footprint() const
unsigned GetTrackWidthIndex() const
KIGFX::PCB_VIEW * view() const
Definition of file extensions used in Kicad.
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
const wxString & GetNetname() const
Definition: netinfo.h:119
virtual PICKED_ITEMS_LIST * PopCommandFromUndoList()
Return the last command to undo and remove it from list, nothing is deleted.
Extend VIEW_ITEM by possibility of grouping items into a single object.
Definition: view_group.h:46
An interface for classes handling user events controlling the view behavior such as zooming,...
int SaveAs(const TOOL_EVENT &aEvent)
const wxString & GetReference() const
Definition: footprint.h:463
#define _(s)
virtual void Remove(VIEW_ITEM *aItem)
Remove an item from the group.
Definition: view_group.cpp:63
DRAWINGS & GraphicalItems()
Definition: footprint.h:171
int Save(const TOOL_EVENT &aEvent)
static TOOL_ACTION plot
Definition: actions.h:58
const LIB_ID & GetFPID() const
Definition: footprint.h:194
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
COMMIT & Remove(EDA_ITEM *aItem)
Notify observers that aItem has been removed.
Definition: commit.h:90
int RepairBoard(const TOOL_EVENT &aEvent)
void SetDiffPairIndex(unsigned aIndex)
virtual const wxString GetProjectFullName() const
Return the full path and name of the project.
Definition: project.cpp:116
A holder to handle information on schematic or board items.
static TOOL_ACTION showEeschema
Definition: pcb_actions.h:441
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:57
int FindNext(const TOOL_EVENT &aEvent)
static TOOL_ACTION generatePosFile
Definition: pcb_actions.h:338
static TOOL_ACTION drawZoneCutout
Definition: pcb_actions.h:155
MODIFY_MODE
< How to modify a property for selected items.
static TOOL_ACTION placeTarget
Definition: pcb_actions.h:158
int ShowEeschema(const TOOL_EVENT &aEvent)
const std::string SpecctraSessionFileExtension
const std::string SpecctraDsnFileExtension
static TOOL_ACTION zoneUnfillAll
Definition: pcb_actions.h:307
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
int InvokeRuleAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeRuleAreaEditor invokes up a modal dialog window for copper zone editing.
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
static TOOL_ACTION boardSetup
Definition: pcb_actions.h:318
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
Generic tool for picking an item.
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:84
static TOOL_ACTION zoneUnfill
Definition: pcb_actions.h:306
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
const KIID m_Uuid
Definition: eda_item.h:475
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
static TOOL_ACTION importSpecctraSession
Definition: pcb_actions.h:333
int ExportNetlist(const TOOL_EVENT &aEvent)
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
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
static TOOL_ACTION zoneDuplicate
Duplicate zone onto another layer.
Definition: pcb_actions.h:311
bool IsFlipped() const
Definition: footprint.h:277
TOOL_ACTION * GetExportNetlistAction()
FP_GROUPS & Groups()
Definition: footprint.h:177
int ImportSpecctraSession(const TOOL_EVENT &aEvent)
void SetWidth(int aWidth)
Definition: pcb_track.h:101
static TOOL_ACTION generateBOM
Definition: pcb_actions.h:341
void SetLink(const KIID &aLink)
Definition: footprint.h:576
void Reset(RESET_REASON aReason) override
Bring the tool to a known, initial state.
virtual void OnModify()
Must be called after a change in order to set the "modify" flag of the current screen and update the ...
Handle the data for a net.
Definition: netinfo.h:64
int ZoneMerge(const TOOL_EVENT &aEvent)
Duplicate a zone onto a layer (prompts for new layer)
static TOOL_ACTION placeFootprint
Definition: pcb_actions.h:160
static TOOL_ACTION exportSpecctraDSN
Definition: pcb_actions.h:334
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
KIGFX::VIEW_CONTROLS * controls() const
const char * name
Definition: DXF_plotter.cpp:56
Common, abstract interface for edit frames.
static TOOL_ACTION saveAs
Definition: actions.h:52
void GenD356File(wxCommandEvent &event)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
static wxString m_DrawingSheetFileName
the name of the drawing sheet file, or empty to use the default drawing sheet
Definition: base_screen.h:85
static TOOL_ACTION repairBoard
Definition: pcb_actions.h:444
bool IsToolActive() const
Definition: tool_base.cpp:31
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
int PlaceFootprint(const TOOL_EVENT &aEvent)
Display a dialog to select a footprint to be added and allows the user to set its position.
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Create a functor that tests if the selected items are only of given type.
int ToggleLockSelected(const TOOL_EVENT &aEvent)
Lock selected items.
PCBNEW_SETTINGS & Settings()
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.cpp:72
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
The selection tool: currently supports:
#define IU_PER_MILS
Definition: plotter.cpp:136
int TogglePythonConsole(const TOOL_EVENT &aEvent)
static bool mergeZones(BOARD_COMMIT &aCommit, std::vector< ZONE * > &aOriginZones, std::vector< ZONE * > &aMergedZones)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:103
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Revert the commit by restoring the modified items state.
wxPoint GetPosition() const override
Definition: footprint.h:186
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:77
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Used for text file output.
Definition: richio.h:456
T * FirstOfKind() const
Definition: selection.h:156
bool IsReactivate() const
Definition: tool_event.h:252
void SetWidth(int aWidth)
Definition: pcb_target.h:64
void ShowFindDialog()
Show the Find dialog.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing.
bool Files_io_from_id(int aId)
Read and write board files according to aId.
void Activate()
Run the tool.
Definition: id.h:96
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void FindNext()
Find the next item using our existing search parameters.
wxString SpecctraDsnFileWildcard()
ACTION_MENU * create() const override
< Return an instance of this class. It has to be overridden in inheriting classes.
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
unsigned GetDiffPairIndex() const
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
int GenerateDrillFiles(const TOOL_EVENT &aEvent)
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:318
int ToggleLayersManager(const TOOL_EVENT &aEvent)
ACTION_MENU * create() const override
< Return an instance of this class. It has to be overridden in inheriting classes.
int ViaSizeDec(const TOOL_EVENT &aEvent)
static wxWindow * Create(wxWindow *aParent)
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
A selection filter which prunes the selection to contain only items of type #PCB_MODULE_T.
Definition: edit_tool.cpp:2303
BOARD * GetBoard() const
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
ROUTER * Router() const
Definition: pad.h:57
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1543
MODE GetDrawingMode() const
Return the current drawing mode of the DRAWING_TOOL or #MODE::NONE if not currently in any drawing mo...
int GenerateFabFiles(const TOOL_EVENT &aEvent)
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
Definition: confirm.cpp:307
ROUTER_MODE Mode() const
Definition: pns_router.h:131
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
int TrackWidthDec(const TOOL_EVENT &aEvent)
static constexpr int Millimeter2iu(double mm)
Rendering engine changes.
Definition: tool_base.h:81
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
static TOOL_ACTION findNext
Definition: actions.h:78
int UpdateSchematicFromPCB(const TOOL_EVENT &aEvent)
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:299
DRAWINGS & Drawings()
Definition: board.h:236
wxPoint m_AuxOrigin
origin for plot exports
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
TRACKS & Tracks()
Definition: board.h:230
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:56
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:633
int PlaceTarget(const TOOL_EVENT &aEvent)
Allow user to place a layer alignment target.
Helper widget to add controls to a wxFileDialog to set netlist configuration options.
static TOOL_ACTION refreshPreview
Definition: actions.h:106
void UseCustomTrackViaSize(bool aEnabled)
Enables/disables custom track/via size settings.
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
static TOOL_ACTION cursorClick
Definition: actions.h:123
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1512
void SetLastPath(LAST_PATH_TYPE aType, const wxString &aLastPath)
Set the path of the last file successfully read.
static TOOL_ACTION generateDrillFiles
Definition: pcb_actions.h:337
int SaveCopyAs(const TOOL_EVENT &aEvent)
virtual void UpdateMsgPanel()
Redraw the message panel.
wxString AddFileExtListToFilter(const std::vector< std::string > &aExts)
Build the wildcard extension file dialog wildcard filter to add to the base message dialog.
#define CTL_OMIT_EXTRA
Definition: pcb_netlist.h:280
Container for design settings for a BOARD object.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103