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.h>
35 #include <board_commit.h>
36 #include <board_design_settings.h>
37 #include <pcb_group.h>
38 #include <footprint.h>
39 #include <pad.h>
40 #include <pcb_target.h>
41 #include <pcb_track.h>
42 #include <zone.h>
43 #include <pcb_marker.h>
44 #include <collectors.h>
45 #include <confirm.h>
46 #include <cstdint>
49 #include <functional>
50 #include <gestfich.h>
51 #include <kiface_i.h>
52 #include <kiway.h>
53 #include <memory>
55 #include <origin_viewitem.h>
56 #include <painter.h>
57 #include <pcb_edit_frame.h>
58 #include <pcbnew_id.h>
59 #include <pcbnew_settings.h>
60 #include <project.h>
61 #include <project/project_file.h> // LAST_PATH_TYPE
62 #include <tool/tool_manager.h>
63 #include <tools/tool_event_utils.h>
64 #include <router/router_tool.h>
65 #include <view/view_controls.h>
66 #include <view/view_group.h>
69 #include <footprint_edit_frame.h>
70 #include <wx/filedlg.h>
71 #include <wx/log.h>
72 
73 using namespace std::placeholders;
74 
75 
77 {
78 public:
80  ACTION_MENU( true )
81  {
82  SetIcon( BITMAPS::add_zone );
83  SetTitle( _( "Zones" ) );
84 
85  Add( PCB_ACTIONS::zoneFill );
89 
90  AppendSeparator();
91 
96  }
97 
98 
99 protected:
100  ACTION_MENU* create() const override
101  {
102  return new ZONE_CONTEXT_MENU();
103  }
104 };
105 
106 
108 {
109 public:
111  ACTION_MENU( true )
112  {
113  SetIcon( BITMAPS::locked );
114  SetTitle( _( "Locking" ) );
115 
116  Add( PCB_ACTIONS::lock );
117  Add( PCB_ACTIONS::unlock );
119  }
120 
121  ACTION_MENU* create() const override
122  {
123  return new LOCK_CONTEXT_MENU();
124  }
125 };
126 
127 
131 class NETLIST_OPTIONS_HELPER : public wxPanel
132 {
133 public:
134  NETLIST_OPTIONS_HELPER( wxWindow* aParent )
135  : wxPanel( aParent )
136  {
137  m_cbOmitExtras = new wxCheckBox( this, wxID_ANY, _( "Omit extra information" ) );
138  m_cbOmitNets = new wxCheckBox( this, wxID_ANY, _( "Omit nets" ) );
139  m_cbOmitFpUuids = new wxCheckBox( this, wxID_ANY,
140  _( "Do not prefix path with footprint UUID." ) );
141 
142  wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL );
143  sizer->Add( m_cbOmitExtras, 0, wxALL, 5 );
144  sizer->Add( m_cbOmitNets, 0, wxALL, 5 );
145  sizer->Add( m_cbOmitFpUuids, 0, wxALL, 5 );
146 
147  SetSizerAndFit( sizer );
148  }
149 
150  int GetNetlistOptions() const
151  {
152  int options = 0;
153 
154  if( m_cbOmitExtras->GetValue() )
155  options |= CTL_OMIT_EXTRA;
156 
157  if( m_cbOmitNets->GetValue() )
158  options |= CTL_OMIT_NETS;
159 
160  if( m_cbOmitFpUuids->GetValue() )
161  options |= CTL_OMIT_FP_UUID;
162 
163  return options;
164  }
165 
166  static wxWindow* Create( wxWindow* aParent )
167  {
168  return new NETLIST_OPTIONS_HELPER( aParent );
169  }
170 
171 protected:
172  wxCheckBox* m_cbOmitExtras;
173  wxCheckBox* m_cbOmitNets;
174  wxCheckBox* m_cbOmitFpUuids;
175 };
176 
177 
179  PCB_TOOL_BASE( "pcbnew.EditorControl" ),
180  m_frame( nullptr ),
181  m_inPlaceFootprint( false ),
182  m_inPlaceTarget( false )
183 {
184  m_placeOrigin = std::make_unique<KIGFX::ORIGIN_VIEWITEM>(
185  KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
187 }
188 
189 
191 {
192 }
193 
194 
196 {
197  m_frame = getEditFrame<PCB_EDIT_FRAME>();
198 
199  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
200  {
201  m_placeOrigin->SetPosition( getModel<BOARD>()->GetDesignSettings().m_AuxOrigin );
202  getView()->Remove( m_placeOrigin.get() );
203  getView()->Add( m_placeOrigin.get() );
204  }
205 }
206 
207 
209 {
210  auto activeToolCondition =
211  [ this ] ( const SELECTION& aSel )
212  {
213  return ( !m_frame->ToolStackIsEmpty() );
214  };
215 
216  auto inactiveStateCondition =
217  [ this ] ( const SELECTION& aSel )
218  {
219  return ( m_frame->ToolStackIsEmpty() && aSel.Size() == 0 );
220  };
221 
222  auto placeModuleCondition =
223  [ this ] ( const SELECTION& aSel )
224  {
225  return m_frame->IsCurrentTool( PCB_ACTIONS::placeFootprint ) && aSel.GetSize() == 0;
226  };
227 
228  auto& ctxMenu = m_menu.GetMenu();
229 
230  // "Cancel" goes at the top of the context menu when a tool is active
231  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1 );
232  ctxMenu.AddSeparator( 1 );
233 
234  // "Get and Place Footprint" should be available for Place Footprint tool
235  ctxMenu.AddItem( PCB_ACTIONS::getAndPlace, placeModuleCondition, 1000 );
236  ctxMenu.AddSeparator( 1000 );
237 
238  // Finally, add the standard zoom & grid items
239  getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( m_menu );
240 
241  auto zoneMenu = std::make_shared<ZONE_CONTEXT_MENU>();
242  zoneMenu->SetTool( this );
243 
244  auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>();
245  lockMenu->SetTool( this );
246 
247  // Add the PCB control menus to relevant other tools
248 
250 
251  if( selTool )
252  {
253  auto& toolMenu = selTool->GetToolMenu();
254  auto& menu = toolMenu.GetMenu();
255 
256  // Add "Get and Place Footprint" when Selection tool is in an inactive state
257  menu.AddItem( PCB_ACTIONS::getAndPlace, inactiveStateCondition );
258  menu.AddSeparator();
259 
260  toolMenu.AddSubMenu( zoneMenu );
261  toolMenu.AddSubMenu( lockMenu );
262 
263  menu.AddMenu( lockMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 );
264 
265  menu.AddMenu( zoneMenu.get(), SELECTION_CONDITIONS::OnlyType( PCB_ZONE_T ), 200 );
266  }
267 
268  DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
269 
270  if( drawingTool )
271  {
272  auto& toolMenu = drawingTool->GetToolMenu();
273  auto& menu = toolMenu.GetMenu();
274 
275  toolMenu.AddSubMenu( zoneMenu );
276 
277  // Functor to say if the PCB_EDIT_FRAME is in a given mode
278  // Capture the tool pointer and tool mode by value
279  auto toolActiveFunctor = [=]( DRAWING_TOOL::MODE aMode )
280  {
281  return [=]( const SELECTION& sel )
282  {
283  return drawingTool->GetDrawingMode() == aMode;
284  };
285  };
286 
287  menu.AddMenu( zoneMenu.get(), toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ), 200 );
288  }
289 
290  return true;
291 }
292 
293 
295 {
297  return 0;
298 }
299 
300 
302 {
304  return 0;
305 }
306 
307 
309 {
311  return 0;
312 }
313 
314 
316 {
318  return 0;
319 }
320 
321 
323 {
325  return 0;
326 }
327 
328 
330 {
331  PICKED_ITEMS_LIST undoCmd;
332  DS_PROXY_UNDO_ITEM* undoItem = new DS_PROXY_UNDO_ITEM( m_frame );
333  ITEM_PICKER wrapper( nullptr, undoItem, UNDO_REDO::PAGESETTINGS );
334 
335  undoCmd.PushItem( wrapper );
337 
341 
342  if( dlg.ShowModal() != wxID_OK )
344 
345  return 0;
346 }
347 
348 
350 {
352  return 0;
353 }
354 
355 
357 {
358  getEditFrame<PCB_EDIT_FRAME>()->ShowBoardSetupDialog();
359  return 0;
360 }
361 
362 
364 {
365  getEditFrame<PCB_EDIT_FRAME>()->InstallNetlistFrame();
366  return 0;
367 }
368 
369 
371 {
372  wxString fullFileName = frame()->GetBoard()->GetFileName();
373  wxString path;
374  wxString name;
375  wxString ext;
376 
377  wxFileName::SplitPath( fullFileName, &path, &name, &ext );
378  name += wxT( ".ses" );
379 
380  fullFileName = EDA_FILE_SELECTOR( _( "Merge Specctra Session file:" ), path, name,
381  wxT( ".ses" ), wxT( "*.ses" ), frame(), wxFD_OPEN, false );
382 
383  if( !fullFileName.IsEmpty() )
384  getEditFrame<PCB_EDIT_FRAME>()->ImportSpecctraSession( fullFileName );
385 
386  return 0;
387 }
388 
389 
391 {
392  wxString fullFileName = m_frame->GetLastPath( LAST_PATH_SPECCTRADSN );
393  wxFileName fn;
394 
395  if( fullFileName.IsEmpty() )
396  {
397  fn = m_frame->GetBoard()->GetFileName();
398  fn.SetExt( SpecctraDsnFileExtension );
399  }
400  else
401  fn = fullFileName;
402 
403  fullFileName = EDA_FILE_SELECTOR( _( "Specctra DSN File" ), fn.GetPath(), fn.GetFullName(),
405  frame(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT, false );
406 
407  if( !fullFileName.IsEmpty() )
408  {
409  m_frame->SetLastPath( LAST_PATH_SPECCTRADSN, fullFileName );
410  getEditFrame<PCB_EDIT_FRAME>()->ExportSpecctraFile( fullFileName );
411  }
412 
413  return 0;
414 }
415 
416 
418 {
419  wxCHECK( m_frame, 0 );
420 
421  wxFileName fn = m_frame->Prj().GetProjectFullName();
422 
423  // Use a different file extension for the board netlist so the schematic netlist file
424  // is accidentally overwritten.
425  fn.SetExt( "pcb_net" );
426 
427  wxFileDialog dlg( m_frame, _( "Export Board Netlist" ), fn.GetPath(), fn.GetFullName(),
428  _( "KiCad board netlist files" ) + wxT( " (*.pcb_net)|*.pcb_net" ),
429  wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
430 
431  dlg.SetExtraControlCreator( &NETLIST_OPTIONS_HELPER::Create );
432 
433  if( dlg.ShowModal() == wxID_CANCEL )
434  return 0;
435 
436  fn = dlg.GetPath();
437 
438  if( !fn.IsDirWritable() )
439  {
440  wxString msg;
441 
442  msg.Printf( _( "Path `%s` is read only." ), fn.GetPath() );
443  wxMessageDialog( m_frame, msg, _( "I/O Error" ), wxOK | wxCENTER | wxICON_EXCLAMATION );
444  return 0;
445  }
446 
447  const NETLIST_OPTIONS_HELPER* noh =
448  dynamic_cast<const NETLIST_OPTIONS_HELPER*>( dlg.GetExtraControl() );
449  wxCHECK( noh, 0 );
450 
452 
453  for( const FOOTPRINT* footprint : board()->Footprints() )
454  {
455  COMPONENT* component = new COMPONENT( footprint->GetFPID(), footprint->GetReference(),
457  { footprint->m_Uuid } );
458 
459  for( const PAD* pad : footprint->Pads() )
460  {
461  const wxString& netname = pad->GetShortNetname();
462 
463  if( !netname.IsEmpty() )
464  {
465  component->AddNet( pad->GetName(), netname, pad->GetPinFunction(),
466  pad->GetPinType() );
467  }
468  }
469 
470  netlist.AddComponent( component );
471  }
472 
473  FILE_OUTPUTFORMATTER formatter( fn.GetFullPath() );
474 
475  netlist.Format( "pcb_netlist", &formatter, 0, noh->GetNetlistOptions() );
476 
477  return 0;
478 }
479 
480 
482 {
483  wxCommandEvent dummy;
484 
485  if( aEvent.IsAction( &PCB_ACTIONS::generateGerbers ) )
487  else if( aEvent.IsAction( &PCB_ACTIONS::generateReportFile ) )
489  else if( aEvent.IsAction( &PCB_ACTIONS::generateD356File ) )
491  else if( aEvent.IsAction( &PCB_ACTIONS::generateBOM ) )
493  else
494  wxFAIL_MSG( "GenerateFabFiles(): unexpected request" );
495 
496  return 0;
497 }
498 
499 
501 {
502  int errors = 0;
503  wxString details;
504  bool quiet = aEvent.Parameter<bool>();
505 
506  // Repair duplicate IDs and missing nets.
507  std::set<KIID> ids;
508  int duplicates = 0;
509 
510  auto processItem =
511  [&]( EDA_ITEM* aItem )
512  {
513  if( ids.count( aItem->m_Uuid ) )
514  {
515  duplicates++;
516  const_cast<KIID&>( aItem->m_Uuid ) = KIID();
517  }
518 
519  ids.insert( aItem->m_Uuid );
520 
521  BOARD_CONNECTED_ITEM* cItem = dynamic_cast<BOARD_CONNECTED_ITEM*>( aItem );
522 
523  if( cItem && cItem->GetNetCode() )
524  {
525  NETINFO_ITEM* netinfo = cItem->GetNet();
526 
527  if( netinfo && !board()->FindNet( netinfo->GetNetname() ) )
528  {
529  board()->Add( netinfo );
530 
531  details += wxString::Format( _( "Orphaned net %s re-parented.\n" ),
532  netinfo->GetNetname() );
533  errors++;
534  }
535  }
536  };
537 
538  // Footprint IDs are the most important, so give them the first crack at "claiming" a
539  // particular KIID.
540 
541  for( FOOTPRINT* footprint : board()->Footprints() )
542  processItem( footprint );
543 
544  // After that the principal use is for DRC marker pointers, which are most likely to pads
545  // or tracks.
546 
547  for( FOOTPRINT* footprint : board()->Footprints() )
548  {
549  for( PAD* pad : footprint->Pads() )
550  processItem( pad );
551  }
552 
553  for( PCB_TRACK* track : board()->Tracks() )
554  processItem( track );
555 
556  // From here out I don't think order matters much.
557 
558  for( FOOTPRINT* footprint : board()->Footprints() )
559  {
560  processItem( &footprint->Reference() );
561  processItem( &footprint->Value() );
562 
563  for( BOARD_ITEM* item : footprint->GraphicalItems() )
564  processItem( item );
565 
566  for( ZONE* zone : footprint->Zones() )
567  processItem( zone );
568 
569  for( PCB_GROUP* group : footprint->Groups() )
570  processItem( group );
571  }
572 
573  for( BOARD_ITEM* drawing : board()->Drawings() )
574  processItem( drawing );
575 
576  for( ZONE* zone : board()->Zones() )
577  processItem( zone );
578 
579  for( PCB_MARKER* marker : board()->Markers() )
580  processItem( marker );
581 
582  for( PCB_GROUP* group : board()->Groups() )
583  processItem( group );
584 
585  if( duplicates )
586  {
587  errors += duplicates;
588  details += wxString::Format( _( "%d duplicate IDs replaced.\n" ), duplicates );
589  }
590 
591  /*******************************
592  * Your test here
593  */
594 
595  /*******************************
596  * Inform the user
597  */
598 
599  if( errors )
600  {
601  m_frame->OnModify();
602 
603  wxString msg = wxString::Format( _( "%d potential problems repaired." ), errors );
604 
605  if( !quiet )
606  DisplayInfoMessage( m_frame, msg, details );
607  }
608  else if( !quiet )
609  {
610  DisplayInfoMessage( m_frame, _( "No board problems found." ) );
611  }
612 
613  return 0;
614 }
615 
616 
618 {
620 
621  if( m_frame->FetchNetlistFromSchematic( netlist, _( "Updating PCB requires a fully annotated "
622  "schematic." ) ) )
623  {
624  DIALOG_UPDATE_PCB updateDialog( m_frame, &netlist );
625  updateDialog.ShowModal();
626  }
627 
628  return 0;
629 }
630 
632 {
633  if( Kiface().IsSingle() )
634  {
636  m_frame, _( "Cannot update schematic because Pcbnew is opened in stand-alone "
637  "mode. In order to create or update PCBs from schematics, you "
638  "must launch the KiCad project manager and create a project." ) );
639  return 0;
640  }
641 
642  m_frame->RunEeschema();
644 
645  if( frame )
646  {
647  std::string payload;
649  }
650  return 0;
651 }
652 
653 
655 {
656  m_frame->RunEeschema();
657  return 0;
658 }
659 
660 
662 {
663  getEditFrame<PCB_EDIT_FRAME>()->ToggleLayersManager();
664  return 0;
665 }
666 
667 
669 {
671  return 0;
672 }
673 
674 
675 // Track & via size control
677 {
678  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
679  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
681 
683  {
684  BOARD_COMMIT commit( this );
685 
686  for( EDA_ITEM* item : selection )
687  {
688  if( item->Type() == PCB_TRACE_T )
689  {
690  PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
691 
692  for( int candidate : designSettings.m_TrackWidthList )
693  {
694  if( candidate > track->GetWidth() )
695  {
696  commit.Modify( track );
697  track->SetWidth( candidate );
698  break;
699  }
700  }
701  }
702  }
703 
704  commit.Push( "Increase Track Width" );
705  return 0;
706  }
707 
708  ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
709 
710  if( routerTool && routerTool->IsToolActive()
711  && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR )
712  {
713  int widthIndex = designSettings.GetDiffPairIndex() + 1;
714 
715  // If we go past the last track width entry in the list, start over at the beginning
716  if( widthIndex >= (int) designSettings.m_DiffPairDimensionsList.size() )
717  widthIndex = 0;
718 
719  designSettings.SetDiffPairIndex( widthIndex );
720  designSettings.UseCustomDiffPairDimensions( false );
721 
723  }
724  else
725  {
726  int widthIndex = designSettings.GetTrackWidthIndex() + 1;
727 
728  // If we go past the last track width entry in the list, start over at the beginning
729  if( widthIndex >= (int) designSettings.m_TrackWidthList.size() )
730  widthIndex = 0;
731 
732  designSettings.SetTrackWidthIndex( widthIndex );
733  designSettings.UseCustomTrackViaSize( false );
734 
736  }
737 
738  return 0;
739 }
740 
741 
743 {
744  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
745  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
747 
749  {
750  BOARD_COMMIT commit( this );
751 
752  for( EDA_ITEM* item : selection )
753  {
754  if( item->Type() == PCB_TRACE_T )
755  {
756  PCB_TRACK* track = static_cast<PCB_TRACK*>( item );
757 
758  for( int i = designSettings.m_TrackWidthList.size() - 1; i >= 0; --i )
759  {
760  int candidate = designSettings.m_TrackWidthList[ i ];
761 
762  if( candidate < track->GetWidth() )
763  {
764  commit.Modify( track );
765  track->SetWidth( candidate );
766  break;
767  }
768  }
769  }
770  }
771 
772  commit.Push( "Decrease Track Width" );
773  return 0;
774  }
775 
776  ROUTER_TOOL* routerTool = m_toolMgr->GetTool<ROUTER_TOOL>();
777 
778  if( routerTool && routerTool->IsToolActive()
779  && routerTool->Router()->Mode() == PNS::PNS_MODE_ROUTE_DIFF_PAIR )
780  {
781  int widthIndex = designSettings.GetDiffPairIndex() - 1;
782 
783  // If we get to the lowest entry start over at the highest
784  if( widthIndex < 0 )
785  widthIndex = designSettings.m_DiffPairDimensionsList.size() - 1;
786 
787  designSettings.SetDiffPairIndex( widthIndex );
788  designSettings.UseCustomDiffPairDimensions( false );
789 
791  }
792  else
793  {
794  int widthIndex = designSettings.GetTrackWidthIndex() - 1;
795 
796  // If we get to the lowest entry start over at the highest
797  if( widthIndex < 0 )
798  widthIndex = designSettings.m_TrackWidthList.size() - 1;
799 
800  designSettings.SetTrackWidthIndex( widthIndex );
801  designSettings.UseCustomTrackViaSize( false );
802 
804  }
805 
806  return 0;
807 }
808 
809 
811 {
812  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
813  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
815 
817  {
818  BOARD_COMMIT commit( this );
819 
820  for( EDA_ITEM* item : selection )
821  {
822  if( item->Type() == PCB_VIA_T )
823  {
824  PCB_VIA* via = static_cast<PCB_VIA*>( item );
825 
826  for( VIA_DIMENSION candidate : designSettings.m_ViasDimensionsList )
827  {
828  if( candidate.m_Diameter > via->GetWidth() )
829  {
830  commit.Modify( via );
831  via->SetWidth( candidate.m_Diameter );
832  via->SetDrill( candidate.m_Drill );
833  break;
834  }
835  }
836  }
837  }
838 
839  commit.Push( "Increase Via Size" );
840  }
841  else
842  {
843  int sizeIndex = designSettings.GetViaSizeIndex() + 1;
844 
845  // If we go past the last via entry in the list, start over at the beginning
846  if( sizeIndex >= (int) designSettings.m_ViasDimensionsList.size() )
847  sizeIndex = 0;
848 
849  designSettings.SetViaSizeIndex( sizeIndex );
850  designSettings.UseCustomTrackViaSize( false );
851 
853  }
854 
855  return 0;
856 }
857 
858 
860 {
861  BOARD_DESIGN_SETTINGS& designSettings = getModel<BOARD>()->GetDesignSettings();
862  constexpr KICAD_T types[] = { PCB_TRACE_T, PCB_VIA_T, EOT };
864 
866  {
867  BOARD_COMMIT commit( this );
868 
869  for( EDA_ITEM* item : selection )
870  {
871  if( item->Type() == PCB_VIA_T )
872  {
873  PCB_VIA* via = static_cast<PCB_VIA*>( item );
874 
875  for( int i = designSettings.m_ViasDimensionsList.size() - 1; i >= 0; --i )
876  {
877  VIA_DIMENSION candidate = designSettings.m_ViasDimensionsList[ i ];
878 
879  if( candidate.m_Diameter < via->GetWidth() )
880  {
881  commit.Modify( via );
882  via->SetWidth( candidate.m_Diameter );
883  via->SetDrill( candidate.m_Drill );
884  break;
885  }
886  }
887  }
888  }
889 
890  commit.Push( "Decrease Via Size" );
891  }
892  else
893  {
894  int sizeIndex = 0; // Assume we only have a single via size entry
895 
896  // If there are more, cycle through them backwards
897  if( designSettings.m_ViasDimensionsList.size() > 0 )
898  {
899  sizeIndex = designSettings.GetViaSizeIndex() - 1;
900 
901  // If we get to the lowest entry start over at the highest
902  if( sizeIndex < 0 )
903  sizeIndex = designSettings.m_ViasDimensionsList.size() - 1;
904  }
905 
906  designSettings.SetViaSizeIndex( sizeIndex );
907  designSettings.UseCustomTrackViaSize( false );
908 
910  }
911 
912  return 0;
913 }
914 
915 
917 {
918  if( m_inPlaceFootprint )
919  return 0;
920  else
921  m_inPlaceFootprint = true;
922 
923  FOOTPRINT* fp = aEvent.Parameter<FOOTPRINT*>();
925  BOARD_COMMIT commit( m_frame );
926  BOARD* board = getModel<BOARD>();
927 
929  controls->ShowCursor( true );
930 
931  std::string tool = aEvent.GetCommandStr().get();
932  m_frame->PushTool( tool );
933  Activate();
934 
935  VECTOR2I cursorPos = controls->GetCursorPosition();
936  bool reselect = false;
937  bool fromOtherCommand = fp != nullptr;
938 
939  // Prime the pump
940  if( fp )
941  {
942  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
945  }
946  else if( !aEvent.IsReactivate() )
948 
949  auto setCursor =
950  [&]()
951  {
953  };
954 
955  // Set initial cursor
956  setCursor();
957 
958  // Main loop: keep receiving events
959  while( TOOL_EVENT* evt = Wait() )
960  {
961  setCursor();
962  cursorPos = controls->GetCursorPosition( !evt->DisableGridSnapping() );
963 
964  if( reselect && fp )
966 
967  auto cleanup =
968  [&] ()
969  {
971  commit.Revert();
972 
973  if( fromOtherCommand )
974  {
976 
977  if( undo )
978  {
980  undo->ClearListAndDeleteItems();
981  delete undo;
982  }
983  }
984 
985  fp = nullptr;
986  };
987 
988  if( evt->IsCancelInteractive() )
989  {
990  if( fp )
991  cleanup();
992  else
993  {
994  m_frame->PopTool( tool );
995  break;
996  }
997  }
998  else if( evt->IsActivate() )
999  {
1000  if( fp )
1001  cleanup();
1002 
1003  if( evt->IsMoveTool() )
1004  {
1005  // leave ourselves on the stack so we come back after the move
1006  break;
1007  }
1008  else
1009  {
1010  frame()->PopTool( tool );
1011  break;
1012  }
1013  }
1014  else if( evt->IsClick( BUT_LEFT ) )
1015  {
1016  if( !fp )
1017  {
1018  // Pick the footprint to be placed
1020 
1021  if( fp == nullptr )
1022  continue;
1023 
1024  fp->SetLink( niluuid );
1025 
1026  fp->SetFlags(IS_NEW ); // whatever
1027 
1028  // Set parent so that clearance can be loaded
1029  fp->SetParent( board );
1030 
1031  for( PAD* pad : fp->Pads() )
1032  {
1033  pad->SetLocalRatsnestVisible( m_frame->GetDisplayOptions().m_ShowGlobalRatsnest );
1034 
1035  // Pads in the library all have orphaned nets. Replace with Default.
1036  pad->SetNetCode( 0 );
1037  }
1038 
1039  // Put it on FRONT layer,
1040  // (Can be stored flipped if the lib is an archive built from a board)
1041  if( fp->IsFlipped() )
1042  fp->Flip( fp->GetPosition(), m_frame->Settings().m_FlipLeftRight );
1043 
1044  fp->SetOrientation( 0 );
1045  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1046 
1047  commit.Add( fp );
1049  controls->SetCursorPosition( cursorPos, false );
1050  }
1051  else
1052  {
1054  commit.Push( _( "Place a footprint" ) );
1055  fp = nullptr; // to indicate that there is no footprint that we currently modify
1056  }
1057  }
1058  else if( evt->IsClick( BUT_RIGHT ) )
1059  {
1061  }
1062  else if( fp && ( evt->IsMotion() || evt->IsAction( &ACTIONS::refreshPreview ) ) )
1063  {
1064  fp->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1065  selection().SetReferencePoint( cursorPos );
1066  getView()->Update( &selection() );
1067  getView()->Update( fp );
1068  }
1069  else if( fp && evt->IsAction( &PCB_ACTIONS::properties ) )
1070  {
1071  // Calling 'Properties' action clears the selection, so we need to restore it
1072  reselect = true;
1073  }
1074  else
1075  {
1076  evt->SetPassEvent();
1077  }
1078 
1079  // Enable autopanning and cursor capture only when there is a footprint to be placed
1080  controls->SetAutoPan( fp != nullptr );
1081  controls->CaptureCursor( fp != nullptr );
1082  }
1083 
1084  controls->SetAutoPan( false );
1085  controls->CaptureCursor( false );
1087 
1088  m_inPlaceFootprint = false;
1089  return 0;
1090 }
1091 
1092 
1094 {
1095  return modifyLockSelected( TOGGLE );
1096 }
1097 
1098 
1100 {
1101  return modifyLockSelected( ON );
1102 }
1103 
1104 
1106 {
1107  return modifyLockSelected( OFF );
1108 }
1109 
1110 
1112 {
1114  const PCB_SELECTION& selection = selTool->GetSelection();
1115  BOARD_COMMIT commit( m_frame );
1116 
1117  if( selection.Empty() )
1119 
1120  // Resolve TOGGLE mode
1121  if( aMode == TOGGLE )
1122  {
1123  aMode = ON;
1124 
1125  for( EDA_ITEM* item : selection )
1126  {
1127  BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
1128 
1129  if( board_item->IsLocked() )
1130  {
1131  aMode = OFF;
1132  break;
1133  }
1134  }
1135  }
1136 
1137  bool modified = false;
1138 
1139  for( EDA_ITEM* item : selection )
1140  {
1141  BOARD_ITEM* board_item = static_cast<BOARD_ITEM*>( item );
1142 
1143  commit.Modify( board_item );
1144 
1145  if( aMode == ON )
1146  {
1147  modified |= !board_item->IsLocked();
1148  board_item->SetLocked( true );
1149  }
1150  else
1151  {
1152  modified |= board_item->IsLocked();
1153  board_item->SetLocked( false );
1154  }
1155  }
1156 
1157  if( modified )
1158  {
1159  commit.Push( aMode == ON ? _( "Lock" ) : _( "Unlock" ) );
1160 
1163  m_frame->OnModify();
1164  }
1165 
1166  return 0;
1167 }
1168 
1169 
1171 {
1172  if( m_inPlaceTarget )
1173  return 0;
1174  else
1175  m_inPlaceTarget = true;
1176 
1177  KIGFX::VIEW* view = getView();
1179  BOARD* board = getModel<BOARD>();
1180  PCB_TARGET* target = new PCB_TARGET( board );
1181 
1182  // Init the new item attributes
1183  target->SetLayer( Edge_Cuts );
1185  target->SetSize( Millimeter2iu( 5 ) );
1186  VECTOR2I cursorPos = controls->GetCursorPosition();
1187  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1188 
1189  // Add a VIEW_GROUP that serves as a preview for the new item
1190  KIGFX::VIEW_GROUP preview( view );
1191  preview.Add( target );
1192  view->Add( &preview );
1193 
1195 
1196  std::string tool = aEvent.GetCommandStr().get();
1197  m_frame->PushTool( tool );
1198  Activate();
1199 
1200  auto setCursor =
1201  [&]()
1202  {
1204  };
1205 
1206  // Set initial cursor
1207  setCursor();
1208 
1209  // Main loop: keep receiving events
1210  while( TOOL_EVENT* evt = Wait() )
1211  {
1212  setCursor();
1213  cursorPos = controls->GetCursorPosition( !evt->DisableGridSnapping() );
1214 
1215  if( evt->IsCancelInteractive() )
1216  {
1217  frame()->PopTool( tool );
1218  break;
1219  }
1220  else if( evt->IsActivate() )
1221  {
1222  if( evt->IsMoveTool() )
1223  {
1224  // leave ourselves on the stack so we come back after the move
1225  break;
1226  }
1227  else
1228  {
1229  frame()->PopTool( tool );
1230  break;
1231  }
1232  }
1233  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
1234  {
1235  target->SetWidth( target->GetWidth() + WIDTH_STEP );
1236  view->Update( &preview );
1237  }
1238  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) )
1239  {
1240  int width = target->GetWidth();
1241 
1242  if( width > WIDTH_STEP )
1243  {
1244  target->SetWidth( width - WIDTH_STEP );
1245  view->Update( &preview );
1246  }
1247  }
1248  else if( evt->IsClick( BUT_LEFT ) )
1249  {
1250  assert( target->GetSize() > 0 );
1251  assert( target->GetWidth() > 0 );
1252 
1253  BOARD_COMMIT commit( m_frame );
1254  commit.Add( target );
1255  commit.Push( "Place a layer alignment target" );
1256 
1257  preview.Remove( target );
1258 
1259  // Create next PCB_TARGET
1260  target = new PCB_TARGET( *target );
1261  preview.Add( target );
1262  }
1263  else if( evt->IsClick( BUT_RIGHT ) )
1264  {
1266  }
1267  else if( evt->IsMotion() )
1268  {
1269  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
1270  view->Update( &preview );
1271  }
1272  else
1273  {
1274  evt->SetPassEvent();
1275  }
1276  }
1277 
1278  preview.Clear();
1279  delete target;
1280  view->Remove( &preview );
1281 
1283 
1284  m_inPlaceTarget = false;
1285  return 0;
1286 }
1287 
1288 
1289 static bool mergeZones( BOARD_COMMIT& aCommit, std::vector<ZONE*>& aOriginZones,
1290  std::vector<ZONE*>& aMergedZones )
1291 {
1292  aCommit.Modify( aOriginZones[0] );
1293 
1294  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
1295  {
1296  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
1298  }
1299 
1300  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
1301 
1302  // We should have one polygon with hole
1303  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
1304  // and therefore cannot be merged (they are detected as intersecting)
1305  // but we should never have more than 2 polys
1306  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
1307  {
1308  wxLogMessage( "BOARD::mergeZones error: more than 2 polys after merging" );
1309  return false;
1310  }
1311 
1312  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
1313  {
1314  aCommit.Remove( aOriginZones[i] );
1315  }
1316 
1317  aMergedZones.push_back( aOriginZones[0] );
1318 
1319  aOriginZones[0]->SetLocalFlags( 1 );
1320  aOriginZones[0]->HatchBorder();
1321  aOriginZones[0]->CacheTriangulation();
1322 
1323  return true;
1324 }
1325 
1326 
1328 {
1329  const PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
1330  BOARD* board = getModel<BOARD>();
1331  BOARD_COMMIT commit( m_frame );
1332 
1333  if( selection.Size() < 2 )
1334  return 0;
1335 
1336  int netcode = -1;
1337 
1338  ZONE* firstZone = nullptr;
1339  std::vector<ZONE*> toMerge, merged;
1340 
1341  for( auto item : selection )
1342  {
1343  ZONE* curr_area = dynamic_cast<ZONE*>( item );
1344 
1345  if( !curr_area )
1346  continue;
1347 
1348  if( !firstZone )
1349  firstZone = curr_area;
1350 
1351  netcode = curr_area->GetNetCode();
1352 
1353  if( firstZone->GetNetCode() != netcode )
1354  continue;
1355 
1356  if( curr_area->GetPriority() != firstZone->GetPriority() )
1357  continue;
1358 
1359  if( curr_area->GetIsRuleArea() != firstZone->GetIsRuleArea() )
1360  continue;
1361 
1362  if( curr_area->GetLayer() != firstZone->GetLayer() )
1363  continue;
1364 
1365  if( !board->TestZoneIntersection( curr_area, firstZone ) )
1366  continue;
1367 
1368  toMerge.push_back( curr_area );
1369  }
1370 
1372 
1373  if( mergeZones( commit, toMerge, merged ) )
1374  {
1375  commit.Push( "Merge zones" );
1376 
1377  for( auto item : merged )
1379  }
1380 
1381  return 0;
1382 }
1383 
1384 
1386 {
1388  const PCB_SELECTION& selection = selTool->GetSelection();
1389 
1390  // because this pops up the zone editor, it would be confusing to handle multiple zones,
1391  // so just handle single selections containing exactly one zone
1392  if( selection.Size() != 1 )
1393  return 0;
1394 
1395  ZONE* oldZone = dyn_cast<ZONE*>( selection[0] );
1396 
1397  if( !oldZone )
1398  return 0;
1399 
1400  ZONE_SETTINGS zoneSettings;
1401  zoneSettings << *oldZone;
1402  int dialogResult;
1403 
1404  if( oldZone->GetIsRuleArea() )
1405  dialogResult = InvokeRuleAreaEditor( m_frame, &zoneSettings );
1406  else if( oldZone->IsOnCopperLayer() )
1407  dialogResult = InvokeCopperZonesEditor( m_frame, &zoneSettings );
1408  else
1409  dialogResult = InvokeNonCopperZonesEditor( m_frame, &zoneSettings );
1410 
1411  if( dialogResult != wxID_OK )
1412  return 0;
1413 
1414  // duplicate the zone
1415  BOARD_COMMIT commit( m_frame );
1416 
1417  std::unique_ptr<ZONE> newZone = std::make_unique<ZONE>( *oldZone );
1418  newZone->ClearSelected();
1419  newZone->UnFill();
1420  zoneSettings.ExportSetting( *newZone );
1421 
1422  // If the new zone is on the same layer(s) as the initial zone,
1423  // offset it a bit so it can more easily be picked.
1424  if( oldZone->GetIsRuleArea() && ( oldZone->GetLayerSet() == zoneSettings.m_Layers ) )
1425  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
1426  else if( !oldZone->GetIsRuleArea() && zoneSettings.m_Layers.test( oldZone->GetLayer() ) )
1427  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
1428 
1429  commit.Add( newZone.release() );
1430  commit.Push( _( "Duplicate zone" ) );
1431 
1432  return 0;
1433 }
1434 
1435 
1437 {
1440 
1441  if( selection.Empty() )
1442  return 0;
1443 
1445 
1446  if( !fp )
1447  return 0;
1448 
1449  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1450 
1451  auto editor = (FOOTPRINT_EDIT_FRAME*) editFrame->Kiway().Player( FRAME_FOOTPRINT_EDITOR, true );
1452 
1453  editor->LoadFootprintFromBoard( fp );
1454 
1455  editor->Show( true );
1456  editor->Raise(); // Iconize( false );
1457 
1458  if( selection.IsHover() )
1460 
1461  return 0;
1462 }
1463 
1464 
1466  EDA_ITEM* originViewItem, const VECTOR2D& aPosition )
1467 {
1468  aFrame->GetDesignSettings().m_AuxOrigin = (wxPoint) aPosition;
1469  originViewItem->SetPosition( (wxPoint) aPosition );
1470  aView->MarkDirty();
1471  aFrame->OnModify();
1472 }
1473 
1474 
1476 {
1477  std::string tool = aEvent.GetCommandStr().get();
1479 
1480  // Deactivate other tools; particularly important if another PICKER is currently running
1481  Activate();
1482 
1483  picker->SetClickHandler(
1484  [this] ( const VECTOR2D& pt ) -> bool
1485  {
1487  DoSetDrillOrigin( getView(), m_frame, m_placeOrigin.get(), pt );
1488  return false; // drill origin is a one-shot; don't continue with tool
1489  } );
1490 
1491  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
1492 
1493  return 0;
1494 }
1495 
1496 
1498 {
1499  Go( &BOARD_EDITOR_CONTROL::New, ACTIONS::doNew.MakeEvent() );
1500  Go( &BOARD_EDITOR_CONTROL::Open, ACTIONS::open.MakeEvent() );
1501  Go( &BOARD_EDITOR_CONTROL::Save, ACTIONS::save.MakeEvent() );
1505  Go( &BOARD_EDITOR_CONTROL::Plot, ACTIONS::plot.MakeEvent() );
1506 
1510  PCB_ACTIONS::importSpecctraSession.MakeEvent() );
1512 
1513  if( ADVANCED_CFG::GetCfg().m_ShowPcbnewExportNetlist && m_frame &&
1516 
1518  PCB_ACTIONS::generateDrillFiles.MakeEvent() );
1522  PCB_ACTIONS::generateReportFile.MakeEvent() );
1525 
1526  // Track & via size control
1531 
1532  // Zone actions
1535 
1536  // Placing tools
1540 
1542 
1543  // Other
1547 
1549  ACTIONS::updatePcbFromSchematic.MakeEvent() );
1551  ACTIONS::updateSchematicFromPcb.MakeEvent() );
1556 }
1557 
1558 
1559 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:422
void RollbackFromUndo()
Perform an undo of the last edit without logging a corresponding redo.
Definition: undo_redo.cpp:580
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: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:424
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:73
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:337
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:443
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:56
int TrackWidthInc(const TOOL_EVENT &aEvent)
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:170
const KIID_PATH & GetPath() const
Definition: footprint.h:194
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: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:192
static TOOL_ACTION lock
Definition: pcb_actions.h:423
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:80
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:306
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:299
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
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:351
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:298
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:467
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:302
static TOOL_ACTION showPythonConsole
Definition: pcb_actions.h:349
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:382
virtual void ExpressMail(FRAME_T aDestination, MAIL_T aCommand, std::string &aPayload, wxWindow *aSource=nullptr)
Send aPayload to aDestination from aSource.
Definition: kiway.cpp:476
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:163
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:252
int GetWidth() const
Definition: pcb_track.h:102
int ImportNetlist(const TOOL_EVENT &aEvent)
void ScriptingConsoleEnableDisable()
Toggles the scripting console visibility.
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:65
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:588
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:305
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:341
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PADS & Pads()
Definition: footprint.h:159
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:173
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:457
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:458
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:71
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:165
static TOOL_ACTION trackWidthInc
Definition: pcb_actions.h:297
void Add(BOARD_ITEM *aItem, ADD_MODE aMode=ADD_MODE::INSERT) override
Adds an item to the container.
Definition: board.cpp:606
Definition: kiid.h:44
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:186
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
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:332
#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:218
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:427
void SetOrientation(double aNewAngle)
Definition: footprint.cpp:1571
static TOOL_ACTION save
Definition: actions.h:51
static TOOL_ACTION doNew
Definition: actions.h:44
FOOTPRINTS & Footprints()
Definition: board.h:233
KIFACE_I & Kiface()
Global KIFACE_I "get" accessor.
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:1381
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:309
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:421
#define _(s)
virtual void Remove(VIEW_ITEM *aItem)
Remove an item from the group.
Definition: view_group.cpp:62
DRAWINGS & GraphicalItems()
Definition: footprint.h:162
int Save(const TOOL_EVENT &aEvent)
static TOOL_ACTION plot
Definition: actions.h:58
const LIB_ID & GetFPID() const
Definition: footprint.h:185
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:116
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: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 SpecctraDsnFileExtension
static TOOL_ACTION zoneUnfillAll
Definition: pcb_actions.h:308
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
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:97
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:307
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: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:455
static TOOL_ACTION zoneDuplicate
Duplicate zone onto another layer.
Definition: pcb_actions.h:312
bool IsFlipped() const
Definition: footprint.h:261
TOOL_ACTION * GetExportNetlistAction()
FP_GROUPS & Groups()
Definition: footprint.h:168
int ImportSpecctraSession(const TOOL_EVENT &aEvent)
void SetWidth(int aWidth)
Definition: pcb_track.h:101
static TOOL_ACTION generateBOM
Definition: pcb_actions.h:342
void SetLink(const KIID &aLink)
Definition: footprint.h:527
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: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
const char * name
Definition: DXF_plotter.cpp:59
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: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: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:103
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: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:177
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:155
bool IsReactivate() const
Definition: tool_event.h:252
void SetWidth(int aWidth)
Definition: pcb_target.h:64
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 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:321
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:2201
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:57
void SetPosition(const wxPoint &aPos) override
Definition: footprint.cpp:1452
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.
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.
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:300
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:596
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: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)
virtual void UpdateMsgPanel()
Redraw the message panel.
#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