KiCad PCB EDA Suite
pcb_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-2017 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 <cstdint>
26 #include <thread>
27 #include <mutex>
28 
29 #include "pcb_editor_control.h"
30 #include "pcb_actions.h"
31 #include <tool/tool_manager.h>
32 #include <wx/progdlg.h>
33 
34 #include "edit_tool.h"
35 #include "selection_tool.h"
36 #include "drawing_tool.h"
37 #include "picker_tool.h"
38 
39 #include <painter.h>
40 #include <project.h>
41 #include <pcbnew_id.h>
42 #include <pcb_edit_frame.h>
43 #include <class_board.h>
44 #include <class_zone.h>
45 #include <pcb_draw_panel_gal.h>
46 #include <class_module.h>
47 #include <class_pcb_target.h>
49 #include <collectors.h>
51 #include <board_commit.h>
52 #include <confirm.h>
53 #include <bitmaps.h>
54 #include <hotkeys.h>
55 
56 #include <view/view_group.h>
57 #include <view/view_controls.h>
58 #include <origin_viewitem.h>
59 #include <profile.h>
60 
62 
63 #include <tools/tool_event_utils.h>
64 
65 #include <functional>
66 using namespace std::placeholders;
67 
68 
69 // Track & via size control
70 TOOL_ACTION PCB_ACTIONS::trackWidthInc( "pcbnew.EditorControl.trackWidthInc",
72  "", "" );
73 
74 TOOL_ACTION PCB_ACTIONS::trackWidthDec( "pcbnew.EditorControl.trackWidthDec",
76  "", "" );
77 
78 TOOL_ACTION PCB_ACTIONS::viaSizeInc( "pcbnew.EditorControl.viaSizeInc",
80  "", "" );
81 
82 TOOL_ACTION PCB_ACTIONS::viaSizeDec( "pcbnew.EditorControl.viaSizeDec",
84  "", "" );
85 
86 TOOL_ACTION PCB_ACTIONS::trackViaSizeChanged( "pcbnew.EditorControl.trackViaSizeChanged",
87  AS_GLOBAL, 0,
88  "", "", NULL, AF_NOTIFY );
89 
90 TOOL_ACTION PCB_ACTIONS::zoneMerge( "pcbnew.EditorControl.zoneMerge",
91  AS_GLOBAL, 0,
92  _( "Merge Zones" ), _( "Merge zones" ) );
93 
94 TOOL_ACTION PCB_ACTIONS::zoneDuplicate( "pcbnew.EditorControl.zoneDuplicate",
95  AS_GLOBAL, 0,
96  _( "Duplicate Zone onto Layer..." ), _( "Duplicate zone outline onto a different layer" ),
97  zone_duplicate_xpm );
98 
99 TOOL_ACTION PCB_ACTIONS::placeTarget( "pcbnew.EditorControl.placeTarget",
100  AS_GLOBAL, 0,
101  _( "Add Layer Alignment Target" ), _( "Add a layer alignment target" ), NULL, AF_ACTIVATE );
102 
103 TOOL_ACTION PCB_ACTIONS::placeModule( "pcbnew.EditorControl.placeModule",
105  _( "Add Footprint" ), _( "Add a footprint" ), NULL, AF_ACTIVATE );
106 
107 TOOL_ACTION PCB_ACTIONS::drillOrigin( "pcbnew.EditorControl.drillOrigin",
108  AS_GLOBAL, 0,
109  "", "" );
110 
111 TOOL_ACTION PCB_ACTIONS::crossProbeSchToPcb( "pcbnew.EditorControl.crossProbSchToPcb",
112  AS_GLOBAL, 0,
113  "", "" );
114 
115 TOOL_ACTION PCB_ACTIONS::toggleLock( "pcbnew.EditorControl.toggleLock",
117  "Toggle Lock", "", lock_unlock_xpm );
118 
119 TOOL_ACTION PCB_ACTIONS::lock( "pcbnew.EditorControl.lock",
120  AS_GLOBAL, 0,
121  _( "Lock" ), "", locked_xpm );
122 
123 TOOL_ACTION PCB_ACTIONS::unlock( "pcbnew.EditorControl.unlock",
124  AS_GLOBAL, 0,
125  _( "Unlock" ), "", unlocked_xpm );
126 
127 TOOL_ACTION PCB_ACTIONS::appendBoard( "pcbnew.EditorControl.appendBoard",
128  AS_GLOBAL, 0,
129  "", "" );
130 
131 TOOL_ACTION PCB_ACTIONS::highlightNet( "pcbnew.EditorControl.highlightNet",
132  AS_GLOBAL, 0,
133  "", "" );
134 
135 TOOL_ACTION PCB_ACTIONS::clearHighlight( "pcbnew.EditorControl.clearHighlight",
136  AS_GLOBAL, 0,
137  "", "" );
138 
139 TOOL_ACTION PCB_ACTIONS::highlightNetCursor( "pcbnew.EditorControl.highlightNetCursor",
140  AS_GLOBAL, 0,
141  "", "" );
142 
143 TOOL_ACTION PCB_ACTIONS::highlightNetSelection( "pcbnew.EditorControl.highlightNetSelection",
145  "", "" );
146 
147 TOOL_ACTION PCB_ACTIONS::showLocalRatsnest( "pcbnew.Control.showLocalRatsnest",
148  AS_GLOBAL, 0,
149  "", "" );
150 
152 {
153 public:
155  {
156  SetIcon( add_zone_xpm );
157  SetTitle( _( "Zones" ) );
158 
159  Add( PCB_ACTIONS::zoneFill );
163 
164  AppendSeparator();
165 
166  Add( PCB_ACTIONS::zoneMerge );
170  }
171 
172 
173 protected:
174  CONTEXT_MENU* create() const override
175  {
176  return new ZONE_CONTEXT_MENU();
177  }
178 
179 private:
180  void update() override
181  {
182  SELECTION_TOOL* selTool = getToolManager()->GetTool<SELECTION_TOOL>();
183 
184  // enable zone actions that act on a single zone
185  bool singleZoneActionsEnabled = ( SELECTION_CONDITIONS::Count( 1 )
187  )( selTool->GetSelection() );
188 
189  Enable( getMenuId( PCB_ACTIONS::zoneDuplicate ), singleZoneActionsEnabled );
190  Enable( getMenuId( PCB_ACTIONS::drawZoneCutout ), singleZoneActionsEnabled );
191  Enable( getMenuId( PCB_ACTIONS::drawSimilarZone ), singleZoneActionsEnabled );
192 
193  // enable zone actions that ably to a specific set of zones (as opposed to all of them)
194  bool nonGlobalActionsEnabled = ( SELECTION_CONDITIONS::MoreThan( 0 ) )( selTool->GetSelection() );
195 
196  Enable( getMenuId( PCB_ACTIONS::zoneFill ), nonGlobalActionsEnabled );
197  Enable( getMenuId( PCB_ACTIONS::zoneUnfill ), nonGlobalActionsEnabled );
198 
199  // lines like this make me really think about a better name for SELECTION_CONDITIONS class
200  bool mergeEnabled = ( SELECTION_CONDITIONS::MoreThan( 1 ) &&
201  /*SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) &&*/
204 
205  Enable( getMenuId( PCB_ACTIONS::zoneMerge ), mergeEnabled );
206  }
207 };
208 
209 
211 {
212 public:
214  {
215  SetIcon( locked_xpm );
216  SetTitle( _( "Locking" ) );
217 
218  AppendSeparator();
219  Add( PCB_ACTIONS::lock );
220  Add( PCB_ACTIONS::unlock );
222  }
223 
224  CONTEXT_MENU* create() const override
225  {
226  return new LOCK_CONTEXT_MENU();
227  }
228 };
229 
230 
232  PCB_TOOL( "pcbnew.EditorControl" ),
233  m_frame( nullptr ),
234  m_menu( *this )
235 {
236  m_placeOrigin.reset( new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
238  m_probingSchToPcb = false;
239  m_slowRatsnest = false;
240 }
241 
242 
244 {
245 }
246 
247 
249 {
250  m_frame = getEditFrame<PCB_EDIT_FRAME>();
251 
252  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
253  {
254  m_placeOrigin->SetPosition( getModel<BOARD>()->GetAuxOrigin() );
255  getView()->Remove( m_placeOrigin.get() );
256  getView()->Add( m_placeOrigin.get() );
257  }
258 }
259 
260 
262 {
263  auto activeToolCondition = [ this ] ( const SELECTION& aSel ) {
264  return ( m_frame->GetToolId() != ID_NO_TOOL_SELECTED );
265  };
266 
267  auto inactiveStateCondition = [ this ] ( const SELECTION& aSel ) {
268  return ( m_frame->GetToolId() == ID_NO_TOOL_SELECTED && aSel.Size() == 0 );
269  };
270 
271  auto placeModuleCondition = [ this ] ( const SELECTION& aSel ) {
272  return ( m_frame->GetToolId() == ID_PCB_MODULE_BUTT && aSel.GetSize() == 0 );
273  };
274 
275  auto& ctxMenu = m_menu.GetMenu();
276 
277  // "Cancel" goes at the top of the context menu when a tool is active
278  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1000 );
279  ctxMenu.AddSeparator( activeToolCondition, 1000 );
280 
281  // "Get and Place Footprint" should be available for Place Footprint tool
282  ctxMenu.AddItem( PCB_ACTIONS::findMove, placeModuleCondition, 1000 );
283  ctxMenu.AddSeparator( placeModuleCondition, 1000 );
284 
285  // Finally, add the standard zoom & grid items
286  m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
287 
288  auto zoneMenu = std::make_shared<ZONE_CONTEXT_MENU>();
289  zoneMenu->SetTool( this );
290 
291  auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>();
292  lockMenu->SetTool( this );
293 
294  // Add the PCB control menus to relevant other tools
295 
297 
298  if( selTool )
299  {
300  auto& toolMenu = selTool->GetToolMenu();
301  auto& menu = toolMenu.GetMenu();
302 
303  // Add "Get and Place Footprint" when Selection tool is in an inactive state
304  menu.AddItem( PCB_ACTIONS::findMove, inactiveStateCondition );
305  menu.AddSeparator( inactiveStateCondition );
306 
307  menu.AddItem( PCB_ACTIONS::zoneDeleteSegzone,
309  toolMenu.AddSubMenu( zoneMenu );
310  toolMenu.AddSubMenu( lockMenu );
311 
312  menu.AddMenu( zoneMenu.get(), false,
314 
315  menu.AddMenu( lockMenu.get(), false,
317  }
318 
319  DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
320 
321  if( drawingTool )
322  {
323  auto& toolMenu = drawingTool->GetToolMenu();
324  auto& menu = toolMenu.GetMenu();
325 
326  toolMenu.AddSubMenu( zoneMenu );
327 
328  // Functor to say if the PCB_EDIT_FRAME is in a given mode
329  // Capture the tool pointer and tool mode by value
330  auto toolActiveFunctor = [=]( DRAWING_TOOL::MODE aMode )
331  {
332  return [=]( const SELECTION& sel )
333  {
334  return drawingTool->GetDrawingMode() == aMode;
335  };
336  };
337 
338  menu.AddMenu( zoneMenu.get(), false, toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ), 200 );
339  }
340 
341  m_ratsnestTimer.SetOwner( this );
342  Connect( m_ratsnestTimer.GetId(), wxEVT_TIMER,
343  wxTimerEventHandler( PCB_EDITOR_CONTROL::ratsnestTimer ), NULL, this );
344 
345  return true;
346 }
347 
348 
349 // Track & via size control
351 {
352  BOARD* board = getModel<BOARD>();
353  int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() + 1;
354 
355  if( widthIndex >= (int) board->GetDesignSettings().m_TrackWidthList.size() )
356  widthIndex = board->GetDesignSettings().m_TrackWidthList.size() - 1;
357 
358  board->GetDesignSettings().SetTrackWidthIndex( widthIndex );
359  board->GetDesignSettings().UseCustomTrackViaSize( false );
360 
362 
363  return 0;
364 }
365 
366 
368 {
369  BOARD* board = getModel<BOARD>();
370  int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() - 1;
371 
372  if( widthIndex < 0 )
373  widthIndex = 0;
374 
375  board->GetDesignSettings().SetTrackWidthIndex( widthIndex );
376  board->GetDesignSettings().UseCustomTrackViaSize( false );
377 
379 
380  return 0;
381 }
382 
383 
385 {
386  BOARD* board = getModel<BOARD>();
387  int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() + 1;
388 
389  if( sizeIndex >= (int) board->GetDesignSettings().m_ViasDimensionsList.size() )
390  sizeIndex = board->GetDesignSettings().m_ViasDimensionsList.size() - 1;
391 
392  board->GetDesignSettings().SetViaSizeIndex( sizeIndex );
393  board->GetDesignSettings().UseCustomTrackViaSize( false );
394 
396 
397  return 0;
398 }
399 
400 
402 {
403  BOARD* board = getModel<BOARD>();
404  int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() - 1;
405 
406  if( sizeIndex < 0 )
407  sizeIndex = 0;
408 
409  board->GetDesignSettings().SetViaSizeIndex( sizeIndex );
410  board->GetDesignSettings().UseCustomTrackViaSize( false );
411 
413 
414  return 0;
415 }
416 
417 
419 {
420  MODULE* module = aEvent.Parameter<MODULE*>();
423  SELECTION& selection = selTool->GetSelection();
424  BOARD_COMMIT commit( m_frame );
425 
427  controls->ShowCursor( true );
428  controls->SetSnapping( true );
429 
430  Activate();
431  m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_PENCIL, _( "Add footprint" ) );
432 
433  // Add all the drawable parts to preview
434  VECTOR2I cursorPos = controls->GetCursorPosition();
435 
436  if( module )
437  {
438  module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
439  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
440  }
441 
442  bool reselect = false;
443 
444  // Main loop: keep receiving events
445  while( OPT_TOOL_EVENT evt = Wait() )
446  {
447  cursorPos = controls->GetCursorPosition();
448 
449  if( reselect && module )
450  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
451 
453  {
454  if( module )
455  {
457  commit.Revert();
458  module = NULL;
459  }
460  else // let's have another chance placing a module
461  break;
462 
463  if( evt->IsActivate() ) // now finish unconditionally
464  break;
465  }
466 
467  else if( evt->IsClick( BUT_LEFT ) )
468  {
469  if( !module )
470  {
471  // Pick the module to be placed
473 
474  if( module == NULL )
475  continue;
476 
477  module->SetLink( 0 );
478  m_frame->AddModuleToBoard( module );
479  commit.Added( module );
480  module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
481  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
482  controls->SetCursorPosition( cursorPos, false );
483  }
484  else
485  {
487  commit.Push( _( "Place a module" ) );
488  module = NULL; // to indicate that there is no module that we currently modify
489  }
490  }
491 
492  else if( evt->IsClick( BUT_RIGHT ) )
493  {
494  m_menu.ShowContextMenu( selTool->GetSelection() );
495  }
496 
497  else if( module && evt->IsMotion() )
498  {
499  module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
500  selection.SetReferencePoint( cursorPos );
501  getView()->Update( &selection );
502  }
503 
504  else if( module && evt->IsAction( &PCB_ACTIONS::properties ) )
505  {
506  // Calling 'Properties' action clears the selection, so we need to restore it
507  reselect = true;
508  }
509 
510  // Enable autopanning and cursor capture only when there is a module to be placed
511  controls->SetAutoPan( !!module );
512  controls->CaptureCursor( !!module );
513  }
514 
516 
517  return 0;
518 }
519 
520 
522 {
523  return modifyLockSelected( TOGGLE );
524 }
525 
526 
528 {
529  return modifyLockSelected( ON );
530 }
531 
532 
534 {
535  return modifyLockSelected( OFF );
536 }
537 
538 
540 {
542  const SELECTION& selection = selTool->GetSelection();
543 
544  if( selection.Empty() )
546 
547  bool modified = false;
548 
549  for( auto i : selection )
550  {
551  auto item = static_cast<BOARD_ITEM*>( i );
552  bool prevState = item->IsLocked();
553 
554  switch( aMode )
555  {
556  case ON:
557  item->SetLocked( true );
558  break;
559 
560  case OFF:
561  item->SetLocked( false );
562  break;
563 
564  case TOGGLE:
565  item->SetLocked( !prevState );
566  break;
567  }
568 
569  // Check if we really modified an item
570  if( !modified && prevState != item->IsLocked() )
571  modified = true;
572  }
573 
574  if( modified )
575  m_frame->OnModify();
576 
577  return 0;
578 }
579 
580 
582 {
583  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
584  KIGFX::VIEW* view = getView();
586  BOARD* board = getModel<BOARD>();
587  PCB_TARGET* target = new PCB_TARGET( board );
588 
589  // Init the new item attributes
590  target->SetLayer( Edge_Cuts );
591  target->SetWidth( board->GetDesignSettings().GetLineThickness( Edge_Cuts ) );
592  target->SetSize( Millimeter2iu( 5 ) );
593  VECTOR2I cursorPos = controls->GetCursorPosition();
594  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
595 
596  // Add a VIEW_GROUP that serves as a preview for the new item
597  KIGFX::VIEW_GROUP preview( view );
598  preview.Add( target );
599  view->Add( &preview );
600 
602  controls->SetSnapping( true );
603 
604  Activate();
605  m_frame->SetToolID( ID_PCB_TARGET_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
606 
607  // Main loop: keep receiving events
608  while( OPT_TOOL_EVENT evt = Wait() )
609  {
610  cursorPos = controls->GetCursorPosition();
611 
613  break;
614 
615  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
616  {
617  target->SetWidth( target->GetWidth() + WIDTH_STEP );
618  view->Update( &preview );
619  }
620 
621  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) )
622  {
623  int width = target->GetWidth();
624 
625  if( width > WIDTH_STEP )
626  {
627  target->SetWidth( width - WIDTH_STEP );
628  view->Update( &preview );
629  }
630  }
631 
632  else if( evt->IsClick( BUT_LEFT ) )
633  {
634  assert( target->GetSize() > 0 );
635  assert( target->GetWidth() > 0 );
636 
637  BOARD_COMMIT commit( m_frame );
638  commit.Add( target );
639  commit.Push( _( "Place a layer alignment target" ) );
640 
641  preview.Remove( target );
642 
643  // Create next PCB_TARGET
644  target = new PCB_TARGET( *target );
645  preview.Add( target );
646  }
647 
648  else if( evt->IsClick( BUT_RIGHT ) )
649  {
650  m_menu.ShowContextMenu( selTool->GetSelection() );
651  }
652 
653  else if( evt->IsMotion() )
654  {
655  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
656  view->Update( &preview );
657  }
658  }
659 
660  delete target;
661 
662  controls->SetSnapping( false );
663  view->Remove( &preview );
664 
666 
667  return 0;
668 }
669 
670 static bool mergeZones( BOARD_COMMIT& aCommit, std::vector<ZONE_CONTAINER *>& aOriginZones,
671  std::vector<ZONE_CONTAINER *>& aMergedZones )
672 {
673  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
674  {
675  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
677  }
678 
679  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
680 
681  // We should have one polygon with hole
682  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
683  // and therefore cannot be merged (they are dectected as intersecting)
684  // but we should never have more than 2 polys
685  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
686  {
687  wxLogMessage( wxT( "BOARD::CombineAreas error: more than 2 polys after merging" ) );
688  return false;
689  }
690 
691  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
692  {
693  aCommit.Remove( aOriginZones[i] );
694  }
695 
696  aCommit.Modify( aOriginZones[0] );
697  aMergedZones.push_back( aOriginZones[0] );
698 
699  aOriginZones[0]->SetLocalFlags( 1 );
700  aOriginZones[0]->Hatch();
701  aOriginZones[0]->CacheTriangulation();
702 
703  return true;
704 }
705 
706 
708 {
709  const SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
710  BOARD* board = getModel<BOARD>();
711  BOARD_COMMIT commit( m_frame );
712 
713  if( selection.Size() < 2 )
714  return 0;
715 
716  int netcode = -1;
717 
718  ZONE_CONTAINER* firstZone = nullptr;
719  std::vector<ZONE_CONTAINER*> toMerge, merged;
720 
721  for( auto item : selection )
722  {
723  auto curr_area = dynamic_cast<ZONE_CONTAINER*>( item );
724 
725  if( !curr_area )
726  continue;
727 
728  if( !firstZone )
729  firstZone = curr_area;
730 
731  netcode = curr_area->GetNetCode();
732 
733  if( firstZone->GetNetCode() != netcode )
734  continue;
735 
736  if( curr_area->GetPriority() != firstZone->GetPriority() )
737  continue;
738 
739  if( curr_area->GetIsKeepout() != firstZone->GetIsKeepout() )
740  continue;
741 
742  if( curr_area->GetLayer() != firstZone->GetLayer() )
743  continue;
744 
745  if( !board->TestAreaIntersection( curr_area, firstZone ) )
746  continue;
747 
748  toMerge.push_back( curr_area );
749  }
750 
752 
753  if( mergeZones( commit, toMerge, merged ) )
754  {
755  commit.Push( _( "Merge zones" ) );
756 
757  for( auto item : merged )
759  }
760 
761  return 0;
762 }
763 
764 
766 {
767  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
768  const auto& selection = selTool->GetSelection();
769 
770  // because this pops up the zone editor, it would be confusing to handle multiple zones,
771  // so just handle single selections containing exactly one zone
772  if( selection.Size() != 1 )
773  return 0;
774 
775  auto oldZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
776 
777  if( !oldZone )
778  return 0;
779 
780  ZONE_SETTINGS zoneSettings;
781  zoneSettings << *oldZone;
782  int dialogResult;
783 
784  if( oldZone->GetIsKeepout() )
785  dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneSettings );
786  else if( oldZone->IsOnCopperLayer() )
787  dialogResult = InvokeCopperZonesEditor( m_frame, &zoneSettings );
788  else
789  dialogResult = InvokeNonCopperZonesEditor( m_frame, &zoneSettings );
790 
791  if( dialogResult != wxID_OK )
792  return 0;
793 
794  // duplicate the zone
795  BOARD_COMMIT commit( m_frame );
796 
797  auto newZone = std::make_unique<ZONE_CONTAINER>( *oldZone );
798  newZone->ClearSelected();
799  newZone->UnFill();
800  zoneSettings.ExportSetting( *newZone );
801 
802  // If the new zone is on the same layer(s) as the the initial zone,
803  // offset it a bit so it can more easily be picked.
804  if( oldZone->GetIsKeepout() && ( oldZone->GetLayerSet() == zoneSettings.m_Layers ) )
805  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
806  else if( !oldZone->GetIsKeepout() && ( oldZone->GetLayer() == zoneSettings.m_CurrentZone_Layer ) )
807  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
808 
809  commit.Add( newZone.release() );
810  commit.Push( _( "Duplicate zone" ) );
811 
812  return 0;
813 }
814 
815 
817 {
818  if( m_probingSchToPcb )
819  {
820  m_probingSchToPcb = false;
821  return 0;
822  }
823 
825  const SELECTION& selection = selTool->GetSelection();
826 
827  if( selection.Size() == 1 )
828  m_frame->SendMessageToEESCHEMA( static_cast<BOARD_ITEM*>( selection.Front() ) );
829 
830  return 0;
831 }
832 
833 
835 {
836  BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
837 
838  if( item )
839  {
840  m_probingSchToPcb = true;
841  getView()->SetCenter( VECTOR2D( item->GetPosition() ) );
843 
844  // If it is a pad and the net highlighting tool is enabled, highlight the net
845  if( item->Type() == PCB_PAD_T && m_frame->GetToolId() == ID_PCB_HIGHLIGHT_BUTT )
846  {
847  int net = static_cast<D_PAD*>( item )->GetNetCode();
849  }
850  else
851  // Otherwise simply select the corresponding item
852  {
854  // Ensure the display is refreshed, because in some installs
855  // the refresh is done only when the gal canvas has the focus, and
856  // that is not the case when crossprobing from Eeschema:
858  }
859  }
860 
861  return 0;
862 }
863 
864 
866  BOARD_ITEM* originViewItem, const VECTOR2D& aPosition )
867 {
868  aFrame->SetAuxOrigin( wxPoint( aPosition.x, aPosition.y ) );
869  originViewItem->SetPosition( wxPoint( aPosition.x, aPosition.y ) );
870  aView->MarkDirty();
871  aFrame->OnModify();
872  return true;
873 }
874 
875 
877  BOARD_ITEM* originViewItem, const VECTOR2D& aPosition )
878 {
879  aFrame->SaveCopyInUndoList( originViewItem, UR_DRILLORIGIN );
880  return DoSetDrillOrigin( aView, aFrame, originViewItem, aPosition );
881 }
882 
883 
885 {
886  Activate();
887 
889  assert( picker );
890 
891  m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_HAND, _( "Adjust zero" ) );
892  picker->SetClickHandler( std::bind( SetDrillOrigin, getView(), m_frame, m_placeOrigin.get(), _1 ) );
893  picker->Activate();
894  Wait();
895 
896  return 0;
897 }
898 
907 static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition,
908  bool aUseSelection = false )
909 {
910  auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
911  auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
912 
913  BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
914 
915  int net = -1;
916  bool enableHighlight = false;
917 
918  if( aUseSelection )
919  {
920  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
921 
922  const SELECTION& selection = selectionTool->GetSelection();
923 
924  for( auto item : selection )
925  {
926  if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
927  {
928  auto ci = static_cast<BOARD_CONNECTED_ITEM*>( item );
929 
930  int item_net = ci->GetNetCode();
931 
932  if( net < 0 )
933  {
934  net = item_net;
935  }
936  else if( net != item_net )
937  {
938  // more than one net selected: do nothing
939  return 0;
940  }
941  }
942  }
943 
944  enableHighlight = ( net >= 0 && net != render->GetHighlightNetCode() );
945  }
946 
947  // If we didn't get a net to highlight from the selection, use the cursor
948  if( net < 0 )
949  {
950  auto guide = frame->GetCollectorsGuide();
951  GENERAL_COLLECTOR collector;
952 
953  // Find a connected item for which we are going to highlight a net
954  collector.Collect( board, GENERAL_COLLECTOR::PadsOrTracks,
955  wxPoint( aPosition.x, aPosition.y ), guide );
956 
957  if( collector.GetCount() == 0 )
958  collector.Collect( board, GENERAL_COLLECTOR::Zones,
959  wxPoint( aPosition.x, aPosition.y ), guide );
960 
961  for( int i = 0; i < collector.GetCount(); i++ )
962  {
963  if( collector[i]->Type() == PCB_PAD_T )
964  {
965  frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
966  break;
967  }
968  }
969 
970  enableHighlight = ( collector.GetCount() > 0 );
971 
972  // Obtain net code for the clicked item
973  if( enableHighlight )
974  net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
975  }
976 
977  // Toggle highlight when the same net was picked
978  if( net > 0 && net == render->GetHighlightNetCode() )
979  enableHighlight = !render->IsHighlightEnabled();
980 
981  if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
982  {
983  render->SetHighlight( enableHighlight, net );
984  aToolMgr->GetView()->UpdateAllLayersColor();
985  }
986 
987  // Store the highlighted netcode in the current board (for dialogs for instance)
988  if( enableHighlight && net >= 0 )
989  {
990  board->SetHighLightNet( net );
991 
992  NETINFO_ITEM* netinfo = board->FindNet( net );
993 
994  if( netinfo )
995  {
996  MSG_PANEL_ITEMS items;
997  netinfo->GetMsgPanelInfo( frame->GetUserUnits(), items );
998  frame->SetMsgPanel( items );
999  frame->SendCrossProbeNetName( netinfo->GetNetname() );
1000  }
1001  }
1002  else
1003  {
1004  board->ResetHighLight();
1005  frame->SetMsgPanel( board );
1007  }
1008 
1009  return true;
1010 }
1011 
1012 
1014 {
1015  int netcode = aEvent.Parameter<intptr_t>();
1016 
1017  if( netcode > 0 )
1018  {
1020  render->SetHighlight( true, netcode );
1022  }
1023  else
1024  {
1025  // No net code specified, pick the net code belonging to the item under the cursor
1026  highlightNet( m_toolMgr, getViewControls()->GetMousePosition() );
1027  }
1028 
1029  return 0;
1030 }
1031 
1032 
1034 {
1035  auto frame = static_cast<PCB_EDIT_FRAME*>( m_toolMgr->GetEditFrame() );
1036  auto board = static_cast<BOARD*>( m_toolMgr->GetModel() );
1038 
1039  board->ResetHighLight();
1040  render->SetHighlight( false );
1042  frame->SetMsgPanel( board );
1044  return 0;
1045 }
1046 
1047 
1049 {
1050  // If the keyboard hotkey was triggered, the behavior is as follows:
1051  // If we are already in the highlight tool, behave the same as a left click.
1052  // If we are not, highlight the net of the selected item(s), or if there is
1053  // no selection, then behave like a Ctrl+Left Click.
1055  {
1056  bool use_selection = ( m_frame->GetToolId() != ID_PCB_HIGHLIGHT_BUTT );
1057  highlightNet( m_toolMgr, getViewControls()->GetMousePosition(),
1058  use_selection );
1059  }
1060 
1061  Activate();
1062 
1063  PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
1064  assert( picker );
1065 
1066  m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) );
1067  picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, _1, false ) );
1068  picker->SetLayerSet( LSET::AllCuMask() );
1069  picker->Activate();
1070  Wait();
1071 
1072  return 0;
1073 }
1074 
1075 
1076 static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, const VECTOR2D& aPosition )
1077 {
1078  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
1079  auto modules = aBoard->Modules();
1080 
1081  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
1083 
1084  const SELECTION& selection = selectionTool->GetSelection();
1085 
1086  if( selection.Empty() )
1087  {
1088  // Clear the previous local ratsnest if we click off all items
1089  for( auto mod : modules )
1090  {
1091  for( auto pad : mod->Pads() )
1092  pad->SetLocalRatsnestVisible( aBoard->IsElementVisible( LAYER_RATSNEST ) );
1093  }
1094  }
1095  else
1096  {
1097  for( auto item : selection )
1098  {
1099  if( auto mod = dyn_cast<MODULE*>(item) )
1100  {
1101  for( auto pad : mod->Pads() )
1102  pad->SetLocalRatsnestVisible( !pad->GetLocalRatsnestVisible() );
1103  }
1104  }
1105  }
1106 
1108  return true;
1109 }
1110 
1111 
1113 {
1114  Activate();
1115 
1116  auto picker = m_toolMgr->GetTool<PICKER_TOOL>();
1117  auto board = getModel<BOARD>();
1118  wxASSERT( picker );
1119  wxASSERT( board );
1120 
1121  m_frame->SetToolID( ID_PCB_SHOW_1_RATSNEST_BUTT, wxCURSOR_PENCIL, _( "Pick Components for Local Ratsnest" ) );
1122  picker->SetClickHandler( std::bind( showLocalRatsnest, m_toolMgr, board, _1 ) );
1123  picker->SetSnapping( false );
1124  picker->Activate();
1125  Wait();
1126 
1127  return 0;
1128 }
1129 
1130 
1132 {
1133  auto selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
1134  auto& selection = selectionTool->GetSelection();
1135  auto connectivity = getModel<BOARD>()->GetConnectivity();
1136 
1137  if( selection.Empty() )
1138  {
1139  connectivity->ClearDynamicRatsnest();
1140  }
1141  else if( m_slowRatsnest )
1142  {
1143  // Compute ratsnest only when user stops dragging for a moment
1144  connectivity->HideDynamicRatsnest();
1145  m_ratsnestTimer.Start( 20 );
1146  }
1147  else
1148  {
1149  // Check how much time doest it take to calculate ratsnest
1150  PROF_COUNTER counter;
1152  counter.Stop();
1153 
1154  // If it is too slow, then switch to 'slow ratsnest' mode when
1155  // ratsnest is calculated when user stops dragging items for a moment
1156  if( counter.msecs() > 25 )
1157  {
1158  m_slowRatsnest = true;
1159  connectivity->HideDynamicRatsnest();
1160  }
1161  }
1162 
1163  return 0;
1164 }
1165 
1166 
1168 {
1169  getModel<BOARD>()->GetConnectivity()->ClearDynamicRatsnest();
1170  m_slowRatsnest = false;
1171  return 0;
1172 }
1173 
1174 
1175 void PCB_EDITOR_CONTROL::ratsnestTimer( wxTimerEvent& aEvent )
1176 {
1177  m_ratsnestTimer.Stop();
1179  static_cast<PCB_DRAW_PANEL_GAL*>( m_frame->GetGalCanvas() )->RedrawRatsnest();
1181 }
1182 
1183 
1185 {
1186  auto selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
1187  auto& selection = selectionTool->GetSelection();
1188  auto connectivity = board()->GetConnectivity();
1189 
1190  std::vector<BOARD_ITEM*> items;
1191  items.reserve( selection.Size() );
1192 
1193  for( auto item : selection )
1194  items.push_back( static_cast<BOARD_ITEM*>( item ) );
1195 
1196  connectivity->ComputeDynamicRatsnest( items );
1197 }
1198 
1199 
1201 {
1202  // Track & via size control
1207 
1208  // Zone actions
1211 
1212  // Placing tools
1215 
1216  // Other
1230 }
1231 
1232 
1233 const int PCB_EDITOR_CONTROL::WIDTH_STEP = 100000;
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
static LSET AllCuMask(int aCuLayerCount=MAX_CU_LAYERS)
Function AllCuMask returns a mask holding the requested number of Cu PCB_LAYER_IDs.
Definition: lset.cpp:673
void Stop()
save the time when this function was called, and set the counter stane to stop
Definition: profile.h:82
static TOOL_ACTION toggleLock
Definition: pcb_actions.h:357
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
virtual void OnModify() override
Function OnModify must be called after a board change to set the modified flag.
Class ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
static TOOL_ACTION placeModule
Activation of the drawing tool (placing a MODULE)
Definition: pcb_actions.h:178
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
MODULE * SelectFootprintFromLibTree(bool aUseFootprintViewer=true)
Function SelectFootprintFromLibTree opens a dialog to select a footprint.
void SetTrackWidthIndex(unsigned aIndex)
Function SetTrackWidthIndex sets the current track width list index to aIndex.
COMMIT & Added(EDA_ITEM *aItem)
Notifies observers that aItem has been added
Definition: commit.h:84
int ZoneMerge(const TOOL_EVENT &aEvent)
static TOOL_ACTION unlock
Definition: pcb_actions.h:359
int PlaceModule(const TOOL_EVENT &aEvent)
Function PlaceModule() Displays a dialog to select a module to be added and allows the user to set it...
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Set the tool command ID to aId and sets the cursor to aCursor.
std::unique_ptr< KIGFX::ORIGIN_VIEWITEM > m_placeOrigin
Place & drill origin marker.
void SendCrossProbeNetName(const wxString &aNetName)
Sends a net name to eeschema for highlighting.
int InvokeKeepoutAreaEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeKeepoutAreaEditor invokes up a modal dialog window for copper zone editing...
static TOOL_ACTION incWidth
Increase width of currently drawn line.
Definition: pcb_actions.h:187
virtual void SetPosition(const wxPoint &aPos)=0
Class RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output ...
Definition: painter.h:56
virtual void AddModuleToBoard(MODULE *module)
Adds the given module to the board.
MODE GetDrawingMode() const
Function GetDrawingMode.
Model changes (required full reload)
Definition: tool_base.h:83
static TOOL_ACTION drawSimilarZone
Activation of the drawing tool (drawing a similar ZONE to another one)
Definition: pcb_actions.h:172
static TOOL_ACTION drillOrigin
Definition: pcb_actions.h:374
static TOOL_ACTION lock
Definition: pcb_actions.h:358
This file is part of the common library.
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
static TOOL_ACTION zoneFillAll
Definition: pcb_actions.h:298
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:291
std::vector< int > m_TrackWidthList
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
Definition: picker_tool.h:85
static SELECTION_CONDITION MoreThan(int aNumber)
Function MoreThan Creates a functor that tests if the number of selected items is greater than the va...
COMMIT & Add(EDA_ITEM *aItem)
Adds a new item to the model
Definition: commit.h:78
Class CONTEXT_MENU.
Definition: context_menu.h:44
VIEW_CONTROLS class definition.
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class&#39;s Inspector method, which does the collection. ...
Definition: collectors.cpp:482
int TrackWidthDec(const TOOL_EVENT &aEvent)
Class SELECTION_TOOL.
wxWindow * GetEditFrame() const
Definition: tool_manager.h:267
int InvokeNonCopperZonesEditor(PCB_BASE_FRAME *aParent, ZONE_SETTINGS *aSettings)
Function InvokeNonCopperZonesEditor invokes up a modal dialog window for non-copper zone editing...
Class BOARD to handle a board.
virtual void Revert() override
Revertes the commit by restoring the modifed items state.
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:49
static TOOL_ACTION zoneDeleteSegzone
Definition: pcb_actions.h:302
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:215
int HideSelectionRatsnest(const TOOL_EVENT &aEvent)
Hides ratsnest for selected items. Called when there are no items selected.
static TOOL_ACTION cancelInteractive
Definition: actions.h:45
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:102
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
virtual PCB_LAYER_ID GetLayer() const override
Function GetLayer returns the primary layer this item is on.
Definition: class_zone.cpp:175
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:111
void ResetHighLight()
Function ResetHighLight Reset all high light data to the init state.
Definition: class_board.h:362
static TOOL_ACTION trackWidthDec
Definition: pcb_actions.h:290
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
Action activates a tool
Definition: tool_event.h:152
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
static int LegacyHotKey(int aHotKey)
Creates a hot key code that refers to a legacy hot key setting, instead of a particular key...
Definition: tool_action.h:174
Classes to handle copper zones.
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:54
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:294
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
static const KICAD_T PadsOrTracks[]
A scan list for PADs, TRACKs, or VIAs.
Definition: collectors.h:303
static const TOOL_EVENT ClearedEvent
Event sent after selection is cleared.
int ZoneDuplicate(const TOOL_EVENT &aEvent)
Duplicates a zone onto a layer (prompts for new layer)
static SELECTION_CONDITION Count(int aNumber)
Function Count Creates a functor that tests if the number of selected items is equal to the value giv...
bool TestAreaIntersection(ZONE_CONTAINER *area_ref, ZONE_CONTAINER *area_to_test)
Function TestAreaIntersection Test for intersection of 2 copper areas area_to_test must be after area...
The class PROF_COUNTER is a small class to help profiling.
Definition: profile.h:45
static TOOL_ACTION highlightNetCursor
Definition: pcb_actions.h:372
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
wxTimer m_ratsnestTimer
Timer that start ratsnest calculation when it is slow to compute.
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
static TOOL_ACTION showLocalRatsnest
Definition: pcb_actions.h:378
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:297
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
static TOOL_ACTION selectionModified
Modified selection notification.
Definition: pcb_actions.h:114
static TOOL_ACTION crossProbeSchToPcb
Definition: pcb_actions.h:375
TOOL_MENU & GetToolMenu()
Get the DRAWING_TOOL top-level context menu
Definition: drawing_tool.h:62
Pcbnew hotkeys.
static TOOL_ACTION decWidth
Decrease width of currently drawn line.
Definition: pcb_actions.h:190
Auxiliary rendering target (noncached)
Definition: definitions.h:42
MODIFY_MODE
How to modify a property for selected items.
Generic tool for picking a point.
Definition: picker_tool.h:34
unsigned GetViaSizeIndex() const
Function GetViaSizeIndex.
void ExportSetting(ZONE_CONTAINER &aTarget, bool aFullExport=true) const
Function ExportSetting copy settings to a given zone.
bool GetIsKeepout() const
Accessors to parameters used in Keepout zones:
Definition: class_zone.h:629
int HighlightNet(const TOOL_EVENT &aEvent)
Highlights net belonging to the item under the cursor.
void SetViaSizeIndex(unsigned aIndex)
Function SetViaSizeIndex sets the current via size list index to aIndex.
Class TOOL_MANAGER.
Definition: tool_manager.h:49
KIGFX::VIEW_CONTROLS * controls() const
Definition: pcb_tool.h:138
static TOOL_ACTION trackWidthInc
Definition: pcb_actions.h:289
static TOOL_ACTION appendBoard
Definition: pcb_actions.h:376
static SELECTION_CONDITION SameLayer()
Function SameLayer Creates a functor that tests if selection contains items that belong exclusively t...
void AddStandardSubMenus(EDA_DRAW_FRAME &aFrame)
Function CreateBasicMenu.
Definition: tool_menu.cpp:95
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
Function GetCollectorsGuide.
int ShowLocalRatsnest(const TOOL_EVENT &aEvent)
Shows local ratsnest of a component
void SetCenter(const VECTOR2D &aCenter)
Function SetCenter() Sets the center point of the VIEW (i.e.
Definition: view.cpp:599
int ViaSizeDec(const TOOL_EVENT &aEvent)
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:254
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
int ClearHighlight(const TOOL_EVENT &aEvent)
Clears all board highlights
void SetMsgPanel(const std::vector< MSG_PANEL_ITEM > &aList)
Clear the message panel and populates it with the contents of aList.
void SetLink(timestamp_t aLink)
Definition: class_module.h:578
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target &#39;dirty&#39; flag.
Definition: view.h:596
Class DRAWING_TOOL.
Definition: drawing_tool.h:49
int TrackWidthInc(const TOOL_EVENT &aEvent)
static SELECTION_CONDITION OnlyTypes(const std::vector< KICAD_T > &aTypes)
Function OnlyTypes Creates a functor that tests if the selected items are only of given types...
EDA_UNITS_T GetUserUnits() const override
Return the user units currently in use.
Definition: draw_frame.h:284
VECTOR2D GetCursorPosition() const
Returns the current cursor position in world coordinates.
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:139
Class TOOL_EVENT.
Definition: tool_event.h:168
static TOOL_ACTION zoneMerge
Definition: pcb_actions.h:301
SELECTION & GetSelection()
Function GetSelection()
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:282
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Function GetDesignSettings.
Definition: class_board.h:538
int DrillOrigin(const TOOL_EVENT &aEvent)
Runs the drill origin tool for setting the origin for drill and pick-and-place files.
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
MODULE * module() const
Definition: pcb_tool.h:141
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes an item from the group.
Definition: view_group.cpp:61
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
const SELECTION & selection() const
Definition: pcb_tool.cpp:245
void SetPosition(const wxPoint &aPos) override
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
void ratsnestTimer(wxTimerEvent &aEvent)
Event handler to recalculate dynamic ratsnest
int ViaSizeInc(const TOOL_EVENT &aEvent)
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
All active tools
Definition: tool_event.h:144
static bool DoSetDrillOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, BOARD_ITEM *aItem, const VECTOR2D &aPoint)
Low-level access (below undo) to setting the drill origin
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1530
static TOOL_ACTION drawZoneCutout
Activation of the drawing tool (drawing a ZONE cutout)
Definition: pcb_actions.h:169
static TOOL_ACTION placeTarget
Activation of the drawing tool (placing a TARGET)
Definition: pcb_actions.h:175
int GetLineThickness(PCB_LAYER_ID aLayer) const
Function GetLineThickness Returns the default graphic segment thickness from the layer class for the ...
int LockSelected(const TOOL_EVENT &aEvent)
Locks selected items.
static bool showLocalRatsnest(TOOL_MANAGER *aToolMgr, BOARD *aBoard, const VECTOR2D &aPosition)
static TOOL_ACTION zoneUnfillAll
Definition: pcb_actions.h:300
int UnlockSelected(const TOOL_EVENT &aEvent)
Unlocks selected items.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=NULL) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
static bool ClassOf(const EDA_ITEM *aItem)
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:41
static const TOOL_EVENT SelectedEvent
Event sent after an item is selected.
virtual const wxPoint GetPosition() const =0
int HighlightNetCursor(const TOOL_EVENT &aEvent)
Launches a tool to pick the item whose net is going to be highlighted.
static TOOL_ACTION zoneUnfill
Definition: pcb_actions.h:299
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:35
Class ZONE_SETTINGS handles zones parameters.
Definition: zone_settings.h:48
static TOOL_ACTION clearHighlight
Definition: pcb_actions.h:370
int GetNetCode() const
Function GetNetCode.
void SetHighLightNet(int aNetCode)
Function SetHighLightNet.
Definition: class_board.h:378
static TOOL_ACTION zoneDuplicate
Duplicate zone onto another layer.
Definition: pcb_actions.h:305
CONTEXT_MENU * create() const override
Returns an instance of this class. It has to be overridden in inheriting classes. ...
virtual void SetNoToolSelected()
Select the ID_NO_TOOL_SELECTED id tool (Idle tool)
double msecs() const
Definition: profile.h:124
void SendMessageToEESCHEMA(BOARD_ITEM *objectToSync)
Function SendMessageToEESCHEMA sends a message to the schematic editor so that it may move its cursor...
static const KICAD_T LockableItems[]
A scan list for TRACKS, VIAS, MODULES.
Definition: collectors.h:323
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
void SetLayerSet(LSET aLayerSet)
Function SetLayerSet() Sets the tool&#39;s snap layer set.
Definition: picker_tool.h:78
MODE
The possible drawing modes of DRAWING_TOOL
Definition: drawing_tool.h:68
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:69
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
CONTEXT_MENU * create() const override
Returns an instance of this class. It has to be overridden in inheriting classes. ...
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:387
int UpdateSelectionRatsnest(const TOOL_EVENT &aEvent)
Updates ratsnest for selected items.
static TOOL_ACTION highlightNet
Definition: pcb_actions.h:371
static TOOL_ACTION highlightNetSelection
Definition: pcb_actions.h:373
EDA_ITEM * GetModel() const
Definition: tool_manager.h:262
PCB_EDIT_FRAME * m_frame
Pointer to the currently used edit frame.
int PlaceTarget(const TOOL_EVENT &aEvent)
Function PlaceTarget() Allows user to place a layer alignment target.
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
KIGFX::PCB_VIEW * view() const
Definition: pcb_tool.h:137
static const int WIDTH_STEP
virtual bool IsLocked() const
Function IsLocked.
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddItem()
int modifyLockSelected(MODIFY_MODE aMode)
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:245
int GetToolId() const
Definition: draw_frame.h:519
void update() override
Update menu state stub.
Class TOOL_ACTION.
Definition: tool_action.h:46
size_t i
Definition: json11.cpp:597
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:56
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Function OnlyType Creates a functor that tests if the selected items are only of given type...
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
bool m_probingSchToPcb
Flag to ignore a single crossprobe message from eeschema.
virtual void SaveCopyInUndoList(BOARD_ITEM *aItemToCopy, UNDO_REDO_T aTypeCommand, const wxPoint &aTransformPoint=wxPoint(0, 0))=0
Function SaveCopyInUndoList (virtual pure) Creates a new entry in undo list of commands.
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
virtual void Push(const wxString &aMessage=wxT("A commit"), bool aCreateUndoEntry=true, bool aSetDirtyBit=true) override
Executes the changes.
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
RESET_REASON
Determines the reason of reset for a tool
Definition: tool_base.h:80
std::vector< VIA_DIMENSION > m_ViasDimensionsList
unsigned GetTrackWidthIndex() const
Function GetTrackWidthIndex.
int InvokeCopperZonesEditor(PCB_BASE_FRAME *aCaller, ZONE_SETTINGS *aSettings)
Function InvokeCopperZonesEditor invokes up a modal dialog window for copper zone editing...
void Activate()
Function Activate() Runs the tool.
TOOL_MENU m_menu
Menu model displayed by the tool.
void GetMsgPanelInfo(EDA_UNITS_T aUnits, std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo returns the information about the NETINFO_ITEM in aList to display in the me...
EDA_DRAW_PANEL_GAL * GetGalCanvas() const
Return a pointer to GAL-based canvas of given EDA draw frame.
Definition: draw_frame.h:921
PCB_TARGET class definition.
void SetAuxOrigin(const wxPoint &aPoint) override
int CrossProbePcbToSch(const TOOL_EVENT &aEvent)
Notifies eeschema about the selected item.
int Size() const
Returns the number of selected parts.
Definition: selection.h:122
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
static TOOL_ACTION findMove
Find an item and start moving.
Definition: pcb_actions.h:385
Module description (excepted pads)
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:239
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function FootprintFilter()
Definition: edit_tool.cpp:1167
static bool highlightNet(TOOL_MANAGER *aToolMgr, const VECTOR2D &aPosition, bool aUseSelection=false)
Function highlightNet() Looks for a BOARD_CONNECTED_ITEM in a given spot, and if one is found - it en...
int CrossProbeSchToPcb(const TOOL_EVENT &aEvent)
Reacts to selection change in eeschema.
Class VIEW.
Definition: view.h:61
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
unsigned GetPriority() const
Function GetPriority.
Definition: class_zone.h:107
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:795
static bool mergeZones(BOARD_COMMIT &aCommit, std::vector< ZONE_CONTAINER * > &aOriginZones, std::vector< ZONE_CONTAINER * > &aMergedZones)
static bool SetDrillOrigin(KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, BOARD_ITEM *aItem, const VECTOR2D &aPoint)
UI-level access (including undo) to setting the drill origin
class SEGZONE, a segment used to fill a zone area (segment on a
Definition: typeinfo.h:97
void SetHighlight(bool aEnabled, int aNetcode=-1)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer or the specifie...
Definition: painter.h:140
int ToggleLockSelected(const TOOL_EVENT &aEvent)
Toggles &#39;lock&#39; property for selected items.
Rendering engine changes.
Definition: tool_base.h:84
bool m_slowRatsnest
Flag to indicate whether the current selection ratsnest is slow to calculate.
bool Init() override
Function Init() Init() is called once upon a registration of the tool.
void calculateSelectionRatsnest()
Recalculates dynamic ratsnest for the current selection
void ShowContextMenu(SELECTION &aSelection)
Function ShowContextMenu.
Definition: tool_menu.cpp:62
static TOOL_ACTION viaSizeDec
Definition: pcb_actions.h:292
void setTransitions() override
Sets up handlers for various events.
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Function GetConnectivity() returns list of missing connections between components/tracks.
Definition: class_board.h:296
#define mod(a, n)
Definition: greymap.cpp:24
PCB_LAYER_ID m_CurrentZone_Layer
Layer used to create the current zone.
Definition: zone_settings.h:69
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50
void MarkDirty()
Function MarkDirty() Forces redraw of view on the next rendering.
Definition: view.h:621
void UseCustomTrackViaSize(bool aEnabled)
Function UseCustomTrackViaSize Enables/disables custom track/via size settings.
void Reset(RESET_REASON aReason) override
Function Reset() Brings the tool to a known, initial state.
OPT< TOOL_EVENT > OPT_TOOL_EVENT
Definition: tool_event.h:495
static SELECTION_CONDITION SameNet(bool aAllowUnconnected=false)
Function SameNet Creates a functor that tests if selection contains items belonging to the same net o...
BOARD * board() const
Definition: pcb_tool.h:140
Class COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:39