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 #include <advanced_config.h>
26 #include "board_editor_control.h"
27 #include "drawing_tool.h"
28 #include "pcb_actions.h"
29 #include "pcb_picker_tool.h"
30 #include "pcb_selection_tool.h"
31 #include "edit_tool.h"
32 #include "tool/tool_event.h"
33 #include <bitmaps.h>
34 #include <board_commit.h>
35 #include <board.h>
36 #include <pcb_group.h>
37 #include <footprint.h>
38 #include <pcb_target.h>
39 #include <track.h>
40 #include <zone.h>
41 #include <pcb_marker.h>
42 #include <collectors.h>
43 #include <confirm.h>
44 #include <cstdint>
47 #include <functional>
48 #include <gestfich.h>
49 #include <kiface_i.h>
50 #include <kiway.h>
51 #include <memory>
53 #include <origin_viewitem.h>
54 #include <painter.h>
55 #include <pcb_edit_frame.h>
56 #include <pcbnew_id.h>
57 #include <pcbnew_settings.h>
58 #include <project.h>
59 #include <project/project_file.h> // LAST_PATH_TYPE
60 #include <tool/tool_manager.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 
70 using namespace std::placeholders;
71 
72 
74 {
75 public:
77  ACTION_MENU( true )
78  {
79  SetIcon( BITMAPS::add_zone );
80  SetTitle( _( "Zones" ) );
81 
82  Add( PCB_ACTIONS::zoneFill );
86 
87  AppendSeparator();
88 
93  }
94 
95 
96 protected:
97  ACTION_MENU* create() const override
98  {
99  return new ZONE_CONTEXT_MENU();
100  }
101 };
102 
103 
105 {
106 public:
108  ACTION_MENU( true )
109  {
110  SetIcon( BITMAPS::locked );
111  SetTitle( _( "Locking" ) );
112 
113  Add( PCB_ACTIONS::lock );
114  Add( PCB_ACTIONS::unlock );
116  }
117 
118  ACTION_MENU* create() const override
119  {
120  return new LOCK_CONTEXT_MENU();
121  }
122 };
123 
124 
128 class NETLIST_OPTIONS_HELPER : public wxPanel
129 {
130 public:
131  NETLIST_OPTIONS_HELPER( wxWindow* aParent )
132  : wxPanel( aParent )
133  {
134  m_cbOmitExtras = new wxCheckBox( this, wxID_ANY, _( "Omit extra information" ) );
135  m_cbOmitNets = new wxCheckBox( this, wxID_ANY, _( "Omit nets" ) );
136  m_cbOmitFpUuids = new wxCheckBox( this, wxID_ANY,
137  _( "Do not prefix path with footprint UUID." ) );
138 
139  wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
140  sizer->Add( m_cbOmitExtras, 0, wxALL, 5 );
141  sizer->Add( m_cbOmitNets, 0, wxALL, 5 );
142  sizer->Add( m_cbOmitFpUuids, 0, wxALL, 5 );
143 
144  SetSizerAndFit( sizer );
145  }
146 
147  int GetNetlistOptions() const
148  {
149  int options = 0;
150 
151  if( m_cbOmitExtras->GetValue() )
152  options |= CTL_OMIT_EXTRA;
153 
154  if( m_cbOmitNets->GetValue() )
155  options |= CTL_OMIT_NETS;
156 
157  if( m_cbOmitFpUuids->GetValue() )
158  options |= CTL_OMIT_FP_UUID;
159 
160  return options;
161  }
162 
163  static wxWindow* Create( wxWindow* aParent )
164  {
165  return new NETLIST_OPTIONS_HELPER( aParent );
166  }
167 
168 protected:
169  wxCheckBox* m_cbOmitExtras;
170  wxCheckBox* m_cbOmitNets;
171  wxCheckBox* m_cbOmitFpUuids;
172 };
173 
174 
176  PCB_TOOL_BASE( "pcbnew.EditorControl" ),
177  m_frame( nullptr )
178 {
179  m_placeOrigin = std::make_unique<KIGFX::ORIGIN_VIEWITEM>(
180  KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
182 }
183 
184 
186 {
187 }
188 
189 
191 {
192  m_frame = getEditFrame<PCB_EDIT_FRAME>();
193 
194  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
195  {
196  m_placeOrigin->SetPosition( getModel<BOARD>()->GetDesignSettings().m_AuxOrigin );
197  getView()->Remove( m_placeOrigin.get() );
198  getView()->Add( m_placeOrigin.get() );
199  }
200 }
201 
202 
204 {
205  auto activeToolCondition =
206  [ this ] ( const SELECTION& aSel )
207  {
208  return ( !m_frame->ToolStackIsEmpty() );
209  };
210 
211  auto inactiveStateCondition =
212  [ this ] ( const SELECTION& aSel )
213  {
214  return ( m_frame->ToolStackIsEmpty() && aSel.Size() == 0 );
215  };
216 
217  auto placeModuleCondition =
218  [ this ] ( const SELECTION& aSel )
219  {
220  return m_frame->IsCurrentTool( PCB_ACTIONS::placeFootprint ) && aSel.GetSize() == 0;
221  };
222 
223  auto& ctxMenu = m_menu.GetMenu();
224 
225  // "Cancel" goes at the top of the context menu when a tool is active
226  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
227  ctxMenu.AddSeparator( 1 );
228 
229  // "Get and Place Footprint" should be available for Place Footprint tool
230  ctxMenu.AddItem( PCB_ACTIONS::getAndPlace, placeModuleCondition, 1000 );
231  ctxMenu.AddSeparator( 1000 );
232 
233  // Finally, add the standard zoom & grid items
234  getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
235 
236  auto zoneMenu = std::make_shared<ZONE_CONTEXT_MENU>();
237  zoneMenu->SetTool( this );
238 
239  auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>();
240  lockMenu->SetTool( this );
241 
242  // Add the PCB control menus to relevant other tools
243 
245 
246  if( selTool )
247  {
248  auto& toolMenu = selTool->GetToolMenu();
249  auto& menu = toolMenu.GetMenu();
250 
251  // Add "Get and Place Footprint" when Selection tool is in an inactive state
252  menu.AddItem( PCB_ACTIONS::getAndPlace, inactiveStateCondition );
253  menu.AddSeparator();
254 
255  toolMenu.AddSubMenu( zoneMenu );
256  toolMenu.AddSubMenu( lockMenu );
257 
258  menu.AddMenu( lockMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 );
259 
260  menu.AddMenu( zoneMenu.get(), SELECTION_CONDITIONS::OnlyType( PCB_ZONE_T ), 200 );
261  }
262 
263  DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
264 
265  if( drawingTool )
266  {
267  auto& toolMenu = drawingTool->GetToolMenu();
268  auto& menu = toolMenu.GetMenu();
269 
270  toolMenu.AddSubMenu( zoneMenu );
271 
272  // Functor to say if the PCB_EDIT_FRAME is in a given mode
273  // Capture the tool pointer and tool mode by value
274  auto toolActiveFunctor = [=]( DRAWING_TOOL::MODE aMode )
275  {
276  return [=]( const SELECTION& sel )
277  {
278  return drawingTool->GetDrawingMode() == aMode;
279  };
280  };
281 
282  menu.AddMenu( zoneMenu.get(), toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ), 200 );
283  }
284 
285  return true;
286 }
287 
288 
290 {
292  return 0;
293 }
294 
295 
297 {
299  return 0;
300 }
301 
302 
304 {
306  return 0;
307 }
308 
309 
311 {
313  return 0;
314 }
315 
316 
318 {
320  return 0;
321 }
322 
323 
325 {
326  PICKED_ITEMS_LIST undoCmd;
327  DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( m_frame );
328  ITEM_PICKER wrapper( nullptr, undoItem, UNDO_REDO::PAGESETTINGS );
329 
330  undoCmd.PushItem( wrapper );
332 
336 
337  if( dlg.ShowModal() != wxID_OK )
339 
340  return 0;
341 }
342 
343 
345 {
347  return 0;
348 }
349 
350 
352 {
353  getEditFrame<PCB_EDIT_FRAME>()->ShowBoardSetupDialog();
354  return 0;
355 }
356 
357 
359 {
360  getEditFrame<PCB_EDIT_FRAME>()->InstallNetlistFrame();
361  return 0;
362 }
363 
364 
366 {
367  wxString fullFileName = frame()->GetBoard()->GetFileName();
368  wxString path;
369  wxString name;
370  wxString ext;
371 
372  wxFileName::SplitPath( fullFileName, &path, &name, &ext );
373  name += wxT( ".ses" );
374 
375  fullFileName = EDA_FILE_SELECTOR( _( "Merge Specctra Session file:" ), path, name,
376  wxT( ".ses" ), wxT( "*.ses" ), frame(), wxFD_OPEN, false );
377 
378  if( !fullFileName.IsEmpty() )
379  getEditFrame<PCB_EDIT_FRAME>()->ImportSpecctraSession( fullFileName );
380 
381  return 0;
382 }
383 
384 
386 {
387  wxString fullFileName = m_frame->GetLastPath( LAST_PATH_SPECCTRADSN );
388  wxFileName fn;
389 
390  if( fullFileName.IsEmpty() )
391  {
392  fn = m_frame->GetBoard()->GetFileName();
393  fn.SetExt( SpecctraDsnFileExtension );
394  }
395  else
396  fn = fullFileName;
397 
398  fullFileName = EDA_FILE_SELECTOR( _( "Specctra DSN File" ), fn.GetPath(), fn.GetFullName(),
400  frame(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT, false );
401 
402  if( !fullFileName.IsEmpty() )
403  {
404  m_frame->SetLastPath( LAST_PATH_SPECCTRADSN, fullFileName );
405  getEditFrame<PCB_EDIT_FRAME>()->ExportSpecctraFile( fullFileName );
406  }
407 
408  return 0;
409 }
410 
411 
413 {
414  wxCHECK( m_frame, 0 );
415 
416  wxFileName fn = m_frame->Prj().GetProjectFullName();
417 
418  // Use a different file extension for the board netlist so the schematic netlist file
419  // is accidently overwritten.
420  fn.SetExt( "pcb_net" );
421 
422  wxFileDialog dlg( m_frame, _( "Export Board Netlist" ), fn.GetPath(), fn.GetFullName(),
423  _( "KiCad board netlist files" ) + wxT( " (*.pcb_net)|*.pcb_net" ),
424  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
425 
426  dlg.SetExtraControlCreator( &NETLIST_OPTIONS_HELPER::Create );
427 
428  if( dlg.ShowModal() == wxID_CANCEL )
429  return 0;
430 
431  fn = dlg.GetPath();
432 
433  if( !fn.IsDirWritable() )
434  {
435  wxString msg;
436 
437  msg.Printf( _( "Path `%s` is read only." ), fn.GetPath() );
438  wxMessageDialog( m_frame, msg, _( "I/O Error" ), wxOK | wxCENTER | wxICON_EXCLAMATION );
439  return 0;
440  }
441 
442  const NETLIST_OPTIONS_HELPER* noh =
443  dynamic_cast<const NETLIST_OPTIONS_HELPER*>( dlg.GetExtraControl() );
444  wxCHECK( noh, 0 );
445 
447 
448  for( const FOOTPRINT* footprint : board()->Footprints() )
449  {
450  COMPONENT* component = new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
452  { footprint->m_Uuid } );
453 
454  for( const PAD* pad : footprint->Pads() )
455  {
456  const wxString& netname = pad->GetShortNetname();
457 
458  if( !netname.IsEmpty() )
459  {
460  component->AddNet( pad->GetName(), netname, pad->GetPinFunction(),
461  pad->GetPinType() );
462  }
463  }
464 
465  netlist.AddComponent( component );
466  }
467 
468  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
469 
470  netlist.Format( "pcb_netlist", &formatter, 0, noh->GetNetlistOptions() );
471 
472  return 0;
473 }
474 
475 
477 {
478  wxCommandEvent dummy;
479 
480  if( aEvent.IsAction( &PCB_ACTIONS::generateGerbers ) )
482  else if( aEvent.IsAction( &PCB_ACTIONS::generateReportFile ) )
484  else if( aEvent.IsAction( &PCB_ACTIONS::generateD356File ) )
486  else if( aEvent.IsAction( &PCB_ACTIONS::generateBOM ) )
488  else
489  wxFAIL_MSG( "GenerateFabFiles(): unexpected request" );
490 
491  return 0;
492 }
493 
494 
496 {
497  int errors = 0;
498  wxString details;
499 
500  /*******************************
501  * Repair duplicate IDs and missing nets
502  */
503 
504  std::set<KIID> ids;
505  int duplicates = 0;
506 
507  auto processItem =
508  [&]( EDA_ITEM* aItem )
509  {
510  if( ids.count( aItem->m_Uuid ) )
511  {
512  duplicates++;
513  const_cast<KIID&>( aItem->m_Uuid ) = KIID();
514  }
515 
516  ids.insert( aItem->m_Uuid );
517 
518  BOARD_CONNECTED_ITEM* cItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem );
519 
520  if( cItem && cItem->GetNetCode() )
521  {
522  NETINFO_ITEM* netinfo = cItem->GetNet();
523 
524  if( netinfo && !board()->FindNet( netinfo->GetNetname() ) )
525  {
526  board()->Add( netinfo );
527 
528  details += wxString::Format( _( "Orphaned net %s re-parented.\n" ),
529  netinfo->GetNetname() );
530  errors++;
531  }
532  }
533  };
534 
535  // Footprint IDs are the most important, so give them the first crack at "claiming" a
536  // particular KIID.
537 
538  for( FOOTPRINT* footprint : board()->Footprints() )
539  processItem( footprint );
540 
541  // After that the principal use is for DRC marker pointers, which are most likely to pads
542  // or tracks.
543 
544  for( FOOTPRINT* footprint : board()->Footprints() )
545  {
546  for( PAD* pad : footprint->Pads() )
547  processItem( pad );
548  }
549 
550  for( TRACK* track : board()->Tracks() )
551  processItem( track );
552 
553  // From here out I don't think order matters much.
554 
555  for( FOOTPRINT* footprint : board()->Footprints() )
556  {
557  processItem( &footprint->Reference() );
558  processItem( &footprint->Value() );
559 
560  for( BOARD_ITEM* item : footprint->GraphicalItems() )
561  processItem( item );
562 
563  for( ZONE* zone : footprint->Zones() )
564  processItem( zone );
565 
566  for( PCB_GROUP* group : footprint->Groups() )
567  processItem( group );
568  }
569 
570  for( BOARD_ITEM* drawing : board()->Drawings() )
571  processItem( drawing );
572 
573  for( ZONE* zone : board()->Zones() )
574  processItem( zone );
575 
576  for( PCB_MARKER* marker : board()->Markers() )
577  processItem( marker );
578 
579  for( PCB_GROUP* group : board()->Groups() )
580  processItem( group );
581 
582  if( duplicates )
583  {
584  errors += duplicates;
585  details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
586  }
587 
588  /*******************************
589  * Your test here
590  */
591 
592  /*******************************
593  * Inform the user
594  */
595 
596  if( errors )
597  {
598  m_frame->OnModify();
599 
600  wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
601  DisplayInfoMessage( m_frame, msg, details );
602  }
603  else
604  {
605  DisplayInfoMessage( m_frame, _( "No board problems found." ) );
606  }
607 
608  return 0;
609 }
610 
611 
613 {
615 
616  if( m_frame->FetchNetlistFromSchematic( netlist, _( "Updating PCB requires a fully annotated "
617  "schematic." ) ) )
618  {
619  DIALOG_UPDATE_PCB updateDialog( m_frame, &netlist );
620  updateDialog.ShowModal();
621  }
622 
623  return 0;
624 }
625 
627 {
628  if( Kiface().IsSingle() )
629  {
631  m_frame, _( "Cannot update schematic because Pcbnew is opened in stand-alone "
632  "mode. In order to create or update PCBs from schematics, you "
633  "must launch the KiCad project manager and create a project." ) );
634  return 0;
635  }
636 
637  m_frame->RunEeschema();
639 
640  if( frame )
641  {
642  std::string payload;
644  }
645  return 0;
646 }
647 
648 
650 {
651  m_frame->RunEeschema();
652  return 0;
653 }
654 
655 
657 {
658  getEditFrame<PCB_EDIT_FRAME>()->ToggleLayersManager();
659  return 0;
660 }
661 
662 
664 {
665 #if defined( KICAD_SCRIPTING_WXPYTHON )
666  m_frame->ScriptingConsoleEnableDisable();
667 #endif
668  return 0;
669 }
670 
671 
672 // Track & via size control
674 {
675  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
676  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
678 
680  {
681  BOARD_COMMIT commit( this );
682 
683  for( EDA_ITEM* item : selection )
684  {
685  if( item->Type() == PCB_TRACE_T )
686  {
687  TRACK* track = (TRACK*) item;
688 
689  for( int candidate : designSettings.m_TrackWidthList )
690  {
691  if( candidate > track->GetWidth() )
692  {
693  commit.Modify( track );
694  track->SetWidth( candidate );
695  break;
696  }
697  }
698  }
699  }
700 
701  commit.Push( "Increase Track Width" );
702  return 0;
703  }
704 
705  ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
706 
707  if( routerTool && routerTool->IsToolActive()
708  && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR )
709  {
710  int widthIndex = designSettings.GetDiffPairIndex() + 1;
711 
712  // If we go past the last track width entry in the list, start over at the beginning
713  if( widthIndex >= (int) designSettings.m_DiffPairDimensionsList.size() )
714  widthIndex = 0;
715 
716  designSettings.SetDiffPairIndex( widthIndex );
717  designSettings.UseCustomDiffPairDimensions( false );
718 
720  }
721  else
722  {
723  int widthIndex = designSettings.GetTrackWidthIndex() + 1;
724 
725  // If we go past the last track width entry in the list, start over at the beginning
726  if( widthIndex >= (int) designSettings.m_TrackWidthList.size() )
727  widthIndex = 0;
728 
729  designSettings.SetTrackWidthIndex( widthIndex );
730  designSettings.UseCustomTrackViaSize( false );
731 
733  }
734 
735  return 0;
736 }
737 
738 
740 {
741  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
742  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
744 
746  {
747  BOARD_COMMIT commit( this );
748 
749  for( EDA_ITEM* item : selection )
750  {
751  if( item->Type() == PCB_TRACE_T )
752  {
753  TRACK* track = (TRACK*) item;
754 
755  for( int i = designSettings.m_TrackWidthList.size() - 1; i >= 0; --i )
756  {
757  int candidate = designSettings.m_TrackWidthList[ i ];
758 
759  if( candidate < track->GetWidth() )
760  {
761  commit.Modify( track );
762  track->SetWidth( candidate );
763  break;
764  }
765  }
766  }
767  }
768 
769  commit.Push( "Decrease Track Width" );
770  return 0;
771  }
772 
773  ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
774 
775  if( routerTool && routerTool->IsToolActive()
776  && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR )
777  {
778  int widthIndex = designSettings.GetDiffPairIndex() - 1;
779 
780  // If we get to the lowest entry start over at the highest
781  if( widthIndex < 0 )
782  widthIndex = designSettings.m_DiffPairDimensionsList.size() - 1;
783 
784  designSettings.SetDiffPairIndex( widthIndex );
785  designSettings.UseCustomDiffPairDimensions( false );
786 
788  }
789  else
790  {
791  int widthIndex = designSettings.GetTrackWidthIndex() - 1;
792 
793  // If we get to the lowest entry start over at the highest
794  if( widthIndex < 0 )
795  widthIndex = designSettings.m_TrackWidthList.size() - 1;
796 
797  designSettings.SetTrackWidthIndex( widthIndex );
798  designSettings.UseCustomTrackViaSize( false );
799 
801  }
802 
803  return 0;
804 }
805 
806 
808 {
809  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
810  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
812 
814  {
815  BOARD_COMMIT commit( this );
816 
817  for( EDA_ITEM* item : selection )
818  {
819  if( item->Type() == PCB_VIA_T )
820  {
821  VIA* via = (VIA*) item;
822 
823  for( VIA_DIMENSION candidate : designSettings.m_ViasDimensionsList )
824  {
825  if( candidate.m_Diameter > via->GetWidth() )
826  {
827  commit.Modify( via );
828  via->SetWidth( candidate.m_Diameter );
829  via->SetDrill( candidate.m_Drill );
830  break;
831  }
832  }
833  }
834  }
835 
836  commit.Push( "Increase Via Size" );
837  }
838  else
839  {
840  int sizeIndex = designSettings.GetViaSizeIndex() + 1;
841 
842  // If we go past the last via entry in the list, start over at the beginning
843  if( sizeIndex >= (int) designSettings.m_ViasDimensionsList.size() )
844  sizeIndex = 0;
845 
846  designSettings.SetViaSizeIndex( sizeIndex );
847  designSettings.UseCustomTrackViaSize( false );
848 
850  }
851 
852  return 0;
853 }
854 
855 
857 {
858  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
859  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
861 
863  {
864  BOARD_COMMIT commit( this );
865 
866  for( EDA_ITEM* item : selection )
867  {
868  if( item->Type() == PCB_VIA_T )
869  {
870  VIA* via = (VIA*) item;
871 
872  for( int i = designSettings.m_ViasDimensionsList.size() - 1; i >= 0; --i )
873  {
874  VIA_DIMENSION candidate = designSettings.m_ViasDimensionsList[ i ];
875 
876  if( candidate.m_Diameter < via->GetWidth() )
877  {
878  commit.Modify( via );
879  via->SetWidth( candidate.m_Diameter );
880  via->SetDrill( candidate.m_Drill );
881  break;
882  }
883  }
884  }
885  }
886 
887  commit.Push( "Decrease Via Size" );
888  }
889  else
890  {
891  int sizeIndex = 0; // Assume we only have a single via size entry
892 
893  // If there are more, cycle through them backwards
894  if( designSettings.m_ViasDimensionsList.size() > 0 )
895  {
896  sizeIndex = designSettings.GetViaSizeIndex() - 1;
897 
898  // If we get to the lowest entry start over at the highest
899  if( sizeIndex < 0 )
900  sizeIndex = designSettings.m_ViasDimensionsList.size() - 1;
901  }
902 
903  designSettings.SetViaSizeIndex( sizeIndex );
904  designSettings.UseCustomTrackViaSize( false );
905 
907  }
908 
909  return 0;
910 }
911 
912 
914 {
915  FOOTPRINT* fp = aEvent.Parameter<FOOTPRINT*>();
917  BOARD_COMMIT commit( m_frame );
918  BOARD* board = getModel<BOARD>();
919 
921  controls->ShowCursor( true );
922 
923  std::string tool = aEvent.GetCommandStr().get();
924  m_frame->PushTool( tool );
925  Activate();
926 
927  VECTOR2I cursorPos = controls->GetCursorPosition();
928  bool reselect = false;
929  bool fromOtherCommand = fp != nullptr;
930 
931  // Prime the pump
932  if( fp )
933  {
934  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
937  }
938  else if( !aEvent.IsReactivate() )
940 
941  auto setCursor =
942  [&]()
943  {
945  };
946 
947  // Set initial cursor
948  setCursor();
949 
950  // Main loop: keep receiving events
951  while( TOOL_EVENT* evt = Wait() )
952  {
953  setCursor();
954  cursorPos = controls->GetCursorPosition( !evt->DisableGridSnapping() );
955 
956  if( reselect && fp )
958 
959  auto cleanup =
960  [&] ()
961  {
963  commit.Revert();
964 
965  if( fromOtherCommand )
966  {
968 
969  if( undo )
970  {
972  undo->ClearListAndDeleteItems();
973  delete undo;
974  }
975  }
976 
977  fp = NULL;
978  };
979 
980  if( evt->IsCancelInteractive() )
981  {
982  if( fp )
983  cleanup();
984  else
985  {
986  m_frame->PopTool( tool );
987  break;
988  }
989  }
990  else if( evt->IsActivate() )
991  {
992  if( fp )
993  cleanup();
994 
995  if( evt->IsMoveTool() )
996  {
997  // leave ourselves on the stack so we come back after the move
998  break;
999  }
1000  else
1001  {
1002  frame()->PopTool( tool );
1003  break;
1004  }
1005  }
1006  else if( evt->IsClick( BUT_LEFT ) )
1007  {
1008  if( !fp )
1009  {
1010  // Pick the footprint to be placed
1012 
1013  if( fp == NULL )
1014  continue;
1015 
1016  fp->SetLink( niluuid );
1017 
1018  fp->SetFlags(IS_NEW ); // whatever
1019 
1020  // Set parent so that clearance can be loaded
1021  fp->SetParent( board );
1022 
1023  for( PAD* pad : fp->Pads() )
1024  {
1025  pad->SetLocalRatsnestVisible( m_frame->GetDisplayOptions().m_ShowGlobalRatsnest );
1026 
1027  // Pads in the library all have orphaned nets. Replace with Default.
1028  pad->SetNetCode( 0 );
1029  }
1030 
1031  // Put it on FRONT layer,
1032  // (Can be stored flipped if the lib is an archive built from a board)
1033  if( fp->IsFlipped() )
1034  fp->Flip( fp->GetPosition(), m_frame->Settings().m_FlipLeftRight );
1035 
1036  fp->SetOrientation( 0 );
1037  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1038 
1039  commit.Add( fp );
1041  controls->SetCursorPosition( cursorPos, false );
1042  }
1043  else
1044  {
1046  commit.Push( _( "Place a footprint" ) );
1047  fp = NULL; // to indicate that there is no footprint that we currently modify
1048  }
1049  }
1050  else if( evt->IsClick( BUT_RIGHT ) )
1051  {
1053  }
1054  else if( fp && ( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) ) )
1055  {
1056  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1057  selection().SetReferencePoint( cursorPos );
1058  getView()->Update( &selection() );
1059  getView()->Update( fp );
1060  }
1061  else if( fp && evt->IsAction( &PCB_ACTIONS::properties ) )
1062  {
1063  // Calling 'Properties' action clears the selection, so we need to restore it
1064  reselect = true;
1065  }
1066  else
1067  {
1068  evt->SetPassEvent();
1069  }
1070 
1071  // Enable autopanning and cursor capture only when there is a footprint to be placed
1072  controls->SetAutoPan( !!fp );
1073  controls->CaptureCursor( !!fp );
1074  }
1075 
1077  return 0;
1078 }
1079 
1080 
1082 {
1083  return modifyLockSelected( TOGGLE );
1084 }
1085 
1086 
1088 {
1089  return modifyLockSelected( ON );
1090 }
1091 
1092 
1094 {
1095  return modifyLockSelected( OFF );
1096 }
1097 
1098 
1100 {
1102  const PCB_SELECTION& selection = selTool->GetSelection();
1103  BOARD_COMMIT commit( m_frame );
1104 
1105  if( selection.Empty() )
1107 
1108  // Resolve TOGGLE mode
1109  if( aMode == TOGGLE )
1110  {
1111  aMode = ON;
1112 
1113  for( EDA_ITEM* item : selection )
1114  {
1115  BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
1116 
1117  if( board_item->IsLocked() )
1118  {
1119  aMode = OFF;
1120  break;
1121  }
1122  }
1123  }
1124 
1125  bool modified = false;
1126 
1127  for( EDA_ITEM* item : selection )
1128  {
1129  BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
1130 
1131  commit.Modify( board_item );
1132 
1133  if( aMode == ON )
1134  {
1135  modified |= !board_item->IsLocked();
1136  board_item->SetLocked( true );
1137  }
1138  else
1139  {
1140  modified |= board_item->IsLocked();
1141  board_item->SetLocked( false );
1142  }
1143  }
1144 
1145  if( modified )
1146  {
1147  commit.Push( aMode == ON ? _( "Lock" ) : _( "Unlock" ) );
1149  m_frame->OnModify();
1150  }
1151 
1152  return 0;
1153 }
1154 
1155 
1157 {
1158  KIGFX::VIEW* view = getView();
1160  BOARD* board = getModel<BOARD>();
1161  PCB_TARGET* target = new PCB_TARGET( board );
1162 
1163  // Init the new item attributes
1164  target->SetLayer( Edge_Cuts );
1166  target->SetSize( Millimeter2iu( 5 ) );
1167  VECTOR2I cursorPos = controls->GetCursorPosition();
1168  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1169 
1170  // Add a VIEW_GROUP that serves as a preview for the new item
1171  KIGFX::VIEW_GROUP preview( view );
1172  preview.Add( target );
1173  view->Add( &preview );
1174 
1176 
1177  std::string tool = aEvent.GetCommandStr().get();
1178  m_frame->PushTool( tool );
1179  Activate();
1180 
1181  auto setCursor =
1182  [&]()
1183  {
1185  };
1186 
1187  // Set initial cursor
1188  setCursor();
1189 
1190  // Main loop: keep receiving events
1191  while( TOOL_EVENT* evt = Wait() )
1192  {
1193  setCursor();
1194  cursorPos = controls->GetCursorPosition( !evt->DisableGridSnapping() );
1195 
1196  if( evt->IsCancelInteractive() )
1197  {
1198  frame()->PopTool( tool );
1199  break;
1200  }
1201  else if( evt->IsActivate() )
1202  {
1203  if( evt->IsMoveTool() )
1204  {
1205  // leave ourselves on the stack so we come back after the move
1206  break;
1207  }
1208  else
1209  {
1210  frame()->PopTool( tool );
1211  break;
1212  }
1213  }
1214  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1215  {
1216  target->SetWidth( target->GetWidth() + WIDTH_STEP );
1217  view->Update( &preview );
1218  }
1219  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) )
1220  {
1221  int width = target->GetWidth();
1222 
1223  if( width > WIDTH_STEP )
1224  {
1225  target->SetWidth( width - WIDTH_STEP );
1226  view->Update( &preview );
1227  }
1228  }
1229  else if( evt->IsClick( BUT_LEFT ) )
1230  {
1231  assert( target->GetSize() > 0 );
1232  assert( target->GetWidth() > 0 );
1233 
1234  BOARD_COMMIT commit( m_frame );
1235  commit.Add( target );
1236  commit.Push( "Place a layer alignment target" );
1237 
1238  preview.Remove( target );
1239 
1240  // Create next PCB_TARGET
1241  target = new PCB_TARGET( *target );
1242  preview.Add( target );
1243  }
1244  else if( evt->IsClick( BUT_RIGHT ) )
1245  {
1247  }
1248  else if( evt->IsMotion() )
1249  {
1250  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1251  view->Update( &preview );
1252  }
1253  else
1254  {
1255  evt->SetPassEvent();
1256  }
1257  }
1258 
1259  preview.Clear();
1260  delete target;
1261  view->Remove( &preview );
1262 
1264  return 0;
1265 }
1266 
1267 
1268 static bool mergeZones( BOARD_COMMIT& aCommit, std::vector<ZONE*>& aOriginZones,
1269  std::vector<ZONE*>& aMergedZones )
1270 {
1271  aCommit.Modify( aOriginZones[0] );
1272 
1273  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
1274  {
1275  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
1277  }
1278 
1279  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
1280 
1281  // We should have one polygon with hole
1282  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
1283  // and therefore cannot be merged (they are dectected as intersecting)
1284  // but we should never have more than 2 polys
1285  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
1286  {
1287  wxLogMessage( "BOARD::mergeZones error: more than 2 polys after merging" );
1288  return false;
1289  }
1290 
1291  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
1292  {
1293  aCommit.Remove( aOriginZones[i] );
1294  }
1295 
1296  aMergedZones.push_back( aOriginZones[0] );
1297 
1298  aOriginZones[0]->SetLocalFlags( 1 );
1299  aOriginZones[0]->HatchBorder();
1300  aOriginZones[0]->CacheTriangulation();
1301 
1302  return true;
1303 }
1304 
1305 
1307 {
1308  const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
1309  BOARD* board = getModel<BOARD>();
1310  BOARD_COMMIT commit( m_frame );
1311 
1312  if( selection.Size() < 2 )
1313  return 0;
1314 
1315  int netcode = -1;
1316 
1317  ZONE* firstZone = nullptr;
1318  std::vector<ZONE*> toMerge, merged;
1319 
1320  for( auto item : selection )
1321  {
1322  ZONE* curr_area = dynamic_cast<ZONE*>( item );
1323 
1324  if( !curr_area )
1325  continue;
1326 
1327  if( !firstZone )
1328  firstZone = curr_area;
1329 
1330  netcode = curr_area->GetNetCode();
1331 
1332  if( firstZone->GetNetCode() != netcode )
1333  continue;
1334 
1335  if( curr_area->GetPriority() != firstZone->GetPriority() )
1336  continue;
1337 
1338  if( curr_area->GetIsRuleArea() != firstZone->GetIsRuleArea() )
1339  continue;
1340 
1341  if( curr_area->GetLayer() != firstZone->GetLayer() )
1342  continue;
1343 
1344  if( !board->TestZoneIntersection( curr_area, firstZone ) )
1345  continue;
1346 
1347  toMerge.push_back( curr_area );
1348  }
1349 
1351 
1352  if( mergeZones( commit, toMerge, merged ) )
1353  {
1354  commit.Push( "Merge zones" );
1355 
1356  for( auto item : merged )
1358  }
1359 
1360  return 0;
1361 }
1362 
1363 
1365 {
1367  const PCB_SELECTION& selection = selTool->GetSelection();
1368 
1369  // because this pops up the zone editor, it would be confusing to handle multiple zones,
1370  // so just handle single selections containing exactly one zone
1371  if( selection.Size() != 1 )
1372  return 0;
1373 
1374  ZONE* oldZone = dyn_cast<ZONE*>( selection[0] );
1375 
1376  if( !oldZone )
1377  return 0;
1378 
1379  ZONE_SETTINGS zoneSettings;
1380  zoneSettings << *oldZone;
1381  int dialogResult;
1382 
1383  if( oldZone->GetIsRuleArea() )
1384  dialogResult = InvokeRuleAreaEditor( m_frame, &zoneSettings );
1385  else if( oldZone->IsOnCopperLayer() )
1386  dialogResult = InvokeCopperZonesEditor( m_frame, &zoneSettings );
1387  else
1388  dialogResult = InvokeNonCopperZonesEditor( m_frame, &zoneSettings );
1389 
1390  if( dialogResult != wxID_OK )
1391  return 0;
1392 
1393  // duplicate the zone
1394  BOARD_COMMIT commit( m_frame );
1395 
1396  std::unique_ptr<ZONE> newZone = std::make_unique<ZONE>( *oldZone );
1397  newZone->ClearSelected();
1398  newZone->UnFill();
1399  zoneSettings.ExportSetting( *newZone );
1400 
1401  // If the new zone is on the same layer(s) as the the initial zone,
1402  // offset it a bit so it can more easily be picked.
1403  if( oldZone->GetIsRuleArea() && ( oldZone->GetLayerSet() == zoneSettings.m_Layers ) )
1404  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
1405  else if( !oldZone->GetIsRuleArea() && zoneSettings.m_Layers.test( oldZone->GetLayer() ) )
1406  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
1407 
1408  commit.Add( newZone.release() );
1409  commit.Push( _( "Duplicate zone" ) );
1410 
1411  return 0;
1412 }
1413 
1414 
1416 {
1419 
1420  if( selection.Empty() )
1421  return 0;
1422 
1424 
1425  if( !fp )
1426  return 0;
1427 
1428  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1429 
1430  auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
1431 
1432  editor->LoadFootprintFromBoard( fp );
1433 
1434  editor->Show( true );
1435  editor->Raise(); // Iconize( false );
1436 
1437  if( selection.IsHover() )
1439 
1440  return 0;
1441 }
1442 
1443 
1445  EDA_ITEM* originViewItem, const VECTOR2D& aPosition )
1446 {
1447  aFrame->GetDesignSettings().m_AuxOrigin = (wxPoint) aPosition;
1448  originViewItem->SetPosition( (wxPoint) aPosition );
1449  aView->MarkDirty();
1450  aFrame->OnModify();
1451 }
1452 
1453 
1455 {
1456  std::string tool = aEvent.GetCommandStr().get();
1458 
1459  // Deactivate other tools; particularly important if another PICKER is currently running
1460  Activate();
1461 
1462  picker->SetClickHandler(
1463  [this] ( const VECTOR2D& pt ) -> bool
1464  {
1466  DoSetDrillOrigin( getView(), m_frame, m_placeOrigin.get(), pt );
1467  return false; // drill origin is a one-shot; don't continue with tool
1468  } );
1469 
1470  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1471 
1472  return 0;
1473 }
1474 
1475 
1477 {
1478  Go( &BOARD_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
1479  Go( &BOARD_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
1480  Go( &BOARD_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
1484  Go( &BOARD_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
1485 
1490 
1491  if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist && m_frame &&
1494 
1501 
1502  // Track & via size control
1507 
1508  // Zone actions
1511 
1512  // Placing tools
1516 
1518 
1519  // Other
1523 
1530 }
1531 
1532 
1533 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:63
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
static TOOL_ACTION toggleLock
Definition: pcb_actions.h:422
void RollbackFromUndo()
Perform an undo of the last edit without logging a corresponding redo.
Definition: undo_redo.cpp:579
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.
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:282
Definition: track.h:343
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:61
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:424
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:56
virtual BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Returns the BOARD_DESIGN_SETTINGS for the open project.
KIID niluuid(0)
bool IsHover() const
Definition: selection.h:72
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:177
static TOOL_ACTION generateGerbers
Definition: pcb_actions.h:337
ZONES & Zones()
Definition: board.h:311
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:448
BOARD * board() const
static TOOL_ACTION editFpInFpEditor
Definition: pcb_actions.h:347
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:265
This file is part of the common library TODO brief description.
static TOOL_ACTION pageSettings
Definition: actions.h:59
int TrackWidthInc(const TOOL_EVENT &aEvent)
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:174
const KIID_PATH & GetPath() const
Definition: footprint.h:199
Model changes (required full reload)
Definition: tool_base.h:81
unsigned GetPriority() const
Definition: zone.h:122
static TOOL_ACTION drawSimilarZone
Definition: pcb_actions.h:160
bool GetIsRuleArea() const
Accessors to parameters used in Rule Area zones:
Definition: zone.h:730
static TOOL_ACTION drillOrigin
Definition: pcb_actions.h:437
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:194
static TOOL_ACTION lock
Definition: pcb_actions.h:423
Defines the structure of a menu based on ACTIONs.
Definition: action_menu.h:47
This file is part of the common library.
virtual void SetPosition(const wxPoint &aPos)
Definition: eda_item.h:303
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:82
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:310
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:303
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:66
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:325
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:67
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:280
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:314
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:215
void UseCustomDiffPairDimensions(bool aEnabled)
Enables/disables custom differential pair dimensions.
static TOOL_ACTION cancelInteractive
Definition: actions.h:65
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:352
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:121
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:302
void setTransitions() override
This method is meant to be overridden in order to specify handlers for events.
TOOL_MENU & GetToolMenu()
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:141
static TOOL_ACTION getAndPlace
Find an item and start moving.
Definition: pcb_actions.h:467
static LIB_PART * dummy()
Used to draw a dummy shape when a LIB_PART is not found in library.
Definition: sch_symbol.cpp:69
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:306
static TOOL_ACTION showPythonConsole
Definition: pcb_actions.h:349
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.h:593
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:368
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:462
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:348
static TOOL_ACTION updatePcbFromSchematic
Definition: actions.h:166
virtual void Clear()
Remove all the stored items from the group.
Definition: view_group.cpp:75
bool FetchNetlistFromSchematic(NETLIST &aNetlist, const wxString &aAnnotateMessage)
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:257
int ImportNetlist(const TOOL_EVENT &aEvent)
void PutDataInPreviousState(PICKED_ITEMS_LIST *aList)
Used in undo or redo command.
Definition: undo_redo.cpp:375
const wxString & GetFileName() const
Definition: board.h:300
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.
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:340
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:309
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
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:206
virtual void SetParent(EDA_ITEM *aParent)
Definition: eda_item.h:166
static TOOL_ACTION generateD356File
Definition: pcb_actions.h:341
class TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PADS & Pads()
Definition: footprint.h:164
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:177
static TOOL_ACTION saveCopyAs
Definition: actions.h:56
void SetWidth(int aWidth)
Definition: track.h:109
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:70
FP_TEXT & Value()
read/write accessors:
Definition: footprint.h:462
int modifyLockSelected(MODIFY_MODE aMode)
Set up handlers for various events.
std::unique_ptr< KIGFX::ORIGIN_VIEWITEM > m_placeOrigin
Place & drill origin marker.
static TOOL_ACTION pickerTool
Definition: actions.h:158
FP_TEXT & Reference()
Definition: footprint.h:463
PCB_BASE_EDIT_FRAME * frame() const
static wxString m_PageLayoutDescrFileName
the name of the page layout descr file, or emty to used the default pagelayout
Definition: base_screen.h:89
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:170
static TOOL_ACTION trackWidthInc
Definition: pcb_actions.h:301
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:563
Definition: kiid.h:44
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:264
int GetWidth() const
Definition: pcb_target.h:70
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:167
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
int EditFpInFpEditor(const TOOL_EVENT &aEvent)
const PCB_SELECTION & selection() const
int ViaSizeInc(const TOOL_EVENT &aEvent)
void SetFlags(STATUS_FLAGS aMask)
Definition: eda_item.h:203
Store information read from a netlist along with the flags used to update the NETLIST in the BOARD.
Definition: pcb_netlist.h:205
int UpdatePCBFromSchematic(const TOOL_EVENT &aEvent)
static TOOL_ACTION importNetlist
Definition: pcb_actions.h:332
#define NULL
#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:216
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
static TOOL_ACTION open
Definition: actions.h:53
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:448
void SetOrientation(double aNewAngle)
Definition: footprint.cpp:1557
static TOOL_ACTION save
Definition: actions.h:54
static TOOL_ACTION doNew
Definition: actions.h:47
FOOTPRINTS & Footprints()
Definition: board.h:305
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
void SetPosition(const wxPoint &aPos) override
Definition: pcb_target.h:60
Generic, UI-independent tool event.
Definition: tool_event.h:173
int BoardSetup(const TOOL_EVENT &aEvent)
void Flip(const wxPoint &aCentre, bool aFlipLeftRight) override
Flip this object, i.e.
Definition: footprint.cpp:1367
wxString EDA_FILE_SELECTOR(const wxString &aTitle, const wxString &aPath, const wxString &aFileName, const wxString &aExtension, const wxString &aWildcard, wxWindow *aParent, int aStyle, const bool aKeepWorkingDirectory, const wxPoint &aPosition, wxString *aMruPath)
A helper function that wraps a call to wxFileSelector.
Definition: gestfich.cpp:52
static TOOL_ACTION zoneMerge
Definition: pcb_actions.h:313
FOOTPRINT * footprint() const
unsigned GetTrackWidthIndex() const
KIGFX::PCB_VIEW * view() const
Definition of file extensions used in Kicad.
bool ToolStackIsEmpty()
Definition: tools_holder.h:117
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:426
virtual void Remove(VIEW_ITEM *aItem)
Remove an item from the group.
Definition: view_group.cpp:62
DRAWINGS & GraphicalItems()
Definition: footprint.h:167
int Save(const TOOL_EVENT &aEvent)
static TOOL_ACTION plot
Definition: actions.h:61
const LIB_ID & GetFPID() const
Definition: footprint.h:190
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
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:117
A holder to handle information on schematic or board items.
static TOOL_ACTION showEeschema
Definition: pcb_actions.h:440
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:56
static TOOL_ACTION generatePosFile
Definition: pcb_actions.h:339
static TOOL_ACTION drawZoneCutout
Definition: pcb_actions.h:159
MODIFY_MODE
< How to modify a property for selected items.
static TOOL_ACTION placeTarget
Definition: pcb_actions.h:162
int ShowEeschema(const TOOL_EVENT &aEvent)
const std::string SpecctraDsnFileExtension
static TOOL_ACTION zoneUnfillAll
Definition: pcb_actions.h:312
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:319
PCB_EDIT_FRAME * m_frame
Pointer to the currently used edit frame.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:122
Generic tool for picking an item.
Store all of the related footprint information found in a netlist.
Definition: pcb_netlist.h:83
static TOOL_ACTION zoneUnfill
Definition: pcb_actions.h:311
ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:67
const KIID m_Uuid
Definition: eda_item.h:525
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:334
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:476
static TOOL_ACTION zoneDuplicate
Duplicate zone onto another layer.
Definition: pcb_actions.h:316
bool IsFlipped() const
Definition: footprint.h:266
TOOL_ACTION * GetExportNetlistAction()
FP_GROUPS & Groups()
Definition: footprint.h:173
int ImportSpecctraSession(const TOOL_EVENT &aEvent)
static TOOL_ACTION generateBOM
Definition: pcb_actions.h:342
void SetLink(const KIID &aLink)
Definition: footprint.h:532
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
virtual bool IsLocked() const
Definition: board_item.h:249
int ZoneMerge(const TOOL_EVENT &aEvent)
Duplicate a zone onto a layer (prompts for new layer)
static TOOL_ACTION placeFootprint
Definition: pcb_actions.h:164
static TOOL_ACTION exportSpecctraDSN
Definition: pcb_actions.h:335
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
int GetWidth() const
Definition: track.h:110
const char * name
Definition: DXF_plotter.cpp:59
Common, abstract interface for edit frames.
static TOOL_ACTION saveAs
Definition: actions.h:55
void GenD356File(wxCommandEvent &event)
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
#define _(s)
Definition: 3d_actions.cpp:33
static TOOL_ACTION repairBoard
Definition: pcb_actions.h:443
bool IsToolActive() const
Definition: tool_base.cpp:31
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:66
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.h:123
int Size() const
Returns the number of selected parts.
Definition: selection.h:128
The selection tool: currently supports:
#define IU_PER_MILS
Definition: plotter.cpp:137
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:150
void AddNet(const wxString &aPinName, const wxString &aNetName, const wxString &aPinFunction, const wxString &aPinType)
Definition: pcb_netlist.h:102
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:182
RESET_REASON
Determine the reason of reset for a tool.
Definition: tool_base.h:78
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Used for text file output.
Definition: richio.h:453
T * FirstOfKind() const
Definition: selection.h:214
bool IsReactivate() const
Definition: tool_event.h:273
void SetWidth(int aWidth)
Definition: pcb_target.h:69
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.
wxString SpecctraDsnFileWildcard()
ACTION_MENU * create() const override
< Return an instance of this class. It has to be overridden in inheriting classes.
class 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:322
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:2188
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:67
ROUTER * Router() const
Definition: pad.h:60
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1438
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:280
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.
Definition: tool_manager.h:267
int TrackWidthDec(const TOOL_EVENT &aEvent)
static constexpr int Millimeter2iu(double mm)
Rendering engine changes.
Definition: tool_base.h:82
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.
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:304
DRAWINGS & Drawings()
Definition: board.h:308
#define IS_NEW
New item, just created.
Definition: eda_item.h:107
wxPoint m_AuxOrigin
origin for plot exports
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
TRACKS & Tracks()
Definition: board.h:302
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:60
void MarkDirty()
Force redraw of view on the next rendering.
Definition: view.h:598
int PlaceTarget(const TOOL_EVENT &aEvent)
Allow user to place a layer alignment target.
Definition: track.h:83
Helper widget to add controls to a wxFileDialog to set netlist configuration options.
static TOOL_ACTION refreshPreview
Definition: actions.h:109
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:126
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:1503
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:338
int SaveCopyAs(const TOOL_EVENT &aEvent)
#define CTL_OMIT_EXTRA
Definition: pcb_netlist.h:279
Container for design settings for a BOARD object.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:98