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-2018 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 
151 TOOL_ACTION PCB_ACTIONS::hideLocalRatsnest( "pcbnew.Control.hideLocalRatsnest",
152  AS_GLOBAL, 0,
153  "", "" );
154 
155 TOOL_ACTION PCB_ACTIONS::updateLocalRatsnest( "pcbnew.Control.updateLocalRatsnest",
156  AS_GLOBAL, 0,
157  "", "" );
158 
160 {
161 public:
163  {
164  SetIcon( add_zone_xpm );
165  SetTitle( _( "Zones" ) );
166 
167  Add( PCB_ACTIONS::zoneFill );
171 
172  AppendSeparator();
173 
174  Add( PCB_ACTIONS::zoneMerge );
178  }
179 
180 
181 protected:
182  CONTEXT_MENU* create() const override
183  {
184  return new ZONE_CONTEXT_MENU();
185  }
186 
187 private:
188  void update() override
189  {
190  SELECTION_TOOL* selTool = getToolManager()->GetTool<SELECTION_TOOL>();
191 
192  // enable zone actions that act on a single zone
193  bool singleZoneActionsEnabled = ( SELECTION_CONDITIONS::Count( 1 )
195  )( selTool->GetSelection() );
196 
197  Enable( getMenuId( PCB_ACTIONS::zoneDuplicate ), singleZoneActionsEnabled );
198  Enable( getMenuId( PCB_ACTIONS::drawZoneCutout ), singleZoneActionsEnabled );
199  Enable( getMenuId( PCB_ACTIONS::drawSimilarZone ), singleZoneActionsEnabled );
200 
201  // enable zone actions that ably to a specific set of zones (as opposed to all of them)
202  bool nonGlobalActionsEnabled = ( SELECTION_CONDITIONS::MoreThan( 0 ) )( selTool->GetSelection() );
203 
204  Enable( getMenuId( PCB_ACTIONS::zoneFill ), nonGlobalActionsEnabled );
205  Enable( getMenuId( PCB_ACTIONS::zoneUnfill ), nonGlobalActionsEnabled );
206 
207  // lines like this make me really think about a better name for SELECTION_CONDITIONS class
208  bool mergeEnabled = ( SELECTION_CONDITIONS::MoreThan( 1 ) &&
209  /*SELECTION_CONDITIONS::OnlyType( PCB_ZONE_AREA_T ) &&*/
212 
213  Enable( getMenuId( PCB_ACTIONS::zoneMerge ), mergeEnabled );
214  }
215 };
216 
217 
219 {
220 public:
222  {
223  SetIcon( locked_xpm );
224  SetTitle( _( "Locking" ) );
225 
226  AppendSeparator();
227  Add( PCB_ACTIONS::lock );
228  Add( PCB_ACTIONS::unlock );
230  }
231 
232  CONTEXT_MENU* create() const override
233  {
234  return new LOCK_CONTEXT_MENU();
235  }
236 };
237 
238 
240  PCB_TOOL( "pcbnew.EditorControl" ),
241  m_frame( nullptr ),
242  m_menu( *this )
243 {
244  m_placeOrigin.reset( new KIGFX::ORIGIN_VIEWITEM( KIGFX::COLOR4D( 0.8, 0.0, 0.0, 1.0 ),
246  m_probingSchToPcb = false;
247  m_slowRatsnest = false;
248 }
249 
250 
252 {
253 }
254 
255 
257 {
258  m_frame = getEditFrame<PCB_EDIT_FRAME>();
259 
260  if( aReason == MODEL_RELOAD || aReason == GAL_SWITCH )
261  {
262  m_placeOrigin->SetPosition( getModel<BOARD>()->GetAuxOrigin() );
263  getView()->Remove( m_placeOrigin.get() );
264  getView()->Add( m_placeOrigin.get() );
265  }
266 }
267 
268 
270 {
271  auto activeToolCondition = [ this ] ( const SELECTION& aSel ) {
272  return ( m_frame->GetToolId() != ID_NO_TOOL_SELECTED );
273  };
274 
275  auto inactiveStateCondition = [ this ] ( const SELECTION& aSel ) {
276  return ( m_frame->GetToolId() == ID_NO_TOOL_SELECTED && aSel.Size() == 0 );
277  };
278 
279  auto placeModuleCondition = [ this ] ( const SELECTION& aSel ) {
280  return ( m_frame->GetToolId() == ID_PCB_MODULE_BUTT && aSel.GetSize() == 0 );
281  };
282 
283  auto& ctxMenu = m_menu.GetMenu();
284 
285  // "Cancel" goes at the top of the context menu when a tool is active
286  ctxMenu.AddItem( ACTIONS::cancelInteractive, activeToolCondition, 1000 );
287  ctxMenu.AddSeparator( activeToolCondition, 1000 );
288 
289  // "Get and Place Footprint" should be available for Place Footprint tool
290  ctxMenu.AddItem( PCB_ACTIONS::findMove, placeModuleCondition, 1000 );
291  ctxMenu.AddSeparator( placeModuleCondition, 1000 );
292 
293  // Finally, add the standard zoom & grid items
294  m_menu.AddStandardSubMenus( *getEditFrame<PCB_BASE_FRAME>() );
295 
296  auto zoneMenu = std::make_shared<ZONE_CONTEXT_MENU>();
297  zoneMenu->SetTool( this );
298 
299  auto lockMenu = std::make_shared<LOCK_CONTEXT_MENU>();
300  lockMenu->SetTool( this );
301 
302  // Add the PCB control menus to relevant other tools
303 
305 
306  if( selTool )
307  {
308  auto& toolMenu = selTool->GetToolMenu();
309  auto& menu = toolMenu.GetMenu();
310 
311  // Add "Get and Place Footprint" when Selection tool is in an inactive state
312  menu.AddItem( PCB_ACTIONS::findMove, inactiveStateCondition );
313  menu.AddSeparator( inactiveStateCondition );
314 
315  menu.AddItem( PCB_ACTIONS::zoneDeleteSegzone,
317  toolMenu.AddSubMenu( zoneMenu );
318  toolMenu.AddSubMenu( lockMenu );
319 
320  menu.AddMenu( zoneMenu.get(), false,
322 
323  menu.AddMenu( lockMenu.get(), false,
325  }
326 
327  DRAWING_TOOL* drawingTool = m_toolMgr->GetTool<DRAWING_TOOL>();
328 
329  if( drawingTool )
330  {
331  auto& toolMenu = drawingTool->GetToolMenu();
332  auto& menu = toolMenu.GetMenu();
333 
334  toolMenu.AddSubMenu( zoneMenu );
335 
336  // Functor to say if the PCB_EDIT_FRAME is in a given mode
337  // Capture the tool pointer and tool mode by value
338  auto toolActiveFunctor = [=]( DRAWING_TOOL::MODE aMode )
339  {
340  return [=]( const SELECTION& sel )
341  {
342  return drawingTool->GetDrawingMode() == aMode;
343  };
344  };
345 
346  menu.AddMenu( zoneMenu.get(), false, toolActiveFunctor( DRAWING_TOOL::MODE::ZONE ), 200 );
347  }
348 
349  m_ratsnestTimer.SetOwner( this );
350  Connect( m_ratsnestTimer.GetId(), wxEVT_TIMER,
351  wxTimerEventHandler( PCB_EDITOR_CONTROL::ratsnestTimer ), NULL, this );
352 
353  return true;
354 }
355 
356 
357 // Track & via size control
359 {
360  BOARD* board = getModel<BOARD>();
361  int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() + 1;
362 
363  if( widthIndex >= (int) board->GetDesignSettings().m_TrackWidthList.size() )
364  widthIndex = board->GetDesignSettings().m_TrackWidthList.size() - 1;
365 
366  board->GetDesignSettings().SetTrackWidthIndex( widthIndex );
367  board->GetDesignSettings().UseCustomTrackViaSize( false );
368 
370 
371  return 0;
372 }
373 
374 
376 {
377  BOARD* board = getModel<BOARD>();
378  int widthIndex = board->GetDesignSettings().GetTrackWidthIndex() - 1;
379 
380  if( widthIndex < 0 )
381  widthIndex = 0;
382 
383  board->GetDesignSettings().SetTrackWidthIndex( widthIndex );
384  board->GetDesignSettings().UseCustomTrackViaSize( false );
385 
387 
388  return 0;
389 }
390 
391 
393 {
394  BOARD* board = getModel<BOARD>();
395  int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() + 1;
396 
397  if( sizeIndex >= (int) board->GetDesignSettings().m_ViasDimensionsList.size() )
398  sizeIndex = board->GetDesignSettings().m_ViasDimensionsList.size() - 1;
399 
400  board->GetDesignSettings().SetViaSizeIndex( sizeIndex );
401  board->GetDesignSettings().UseCustomTrackViaSize( false );
402 
404 
405  return 0;
406 }
407 
408 
410 {
411  BOARD* board = getModel<BOARD>();
412  int sizeIndex = board->GetDesignSettings().GetViaSizeIndex() - 1;
413 
414  if( sizeIndex < 0 )
415  sizeIndex = 0;
416 
417  board->GetDesignSettings().SetViaSizeIndex( sizeIndex );
418  board->GetDesignSettings().UseCustomTrackViaSize( false );
419 
421 
422  return 0;
423 }
424 
425 
427 {
428  MODULE* module = aEvent.Parameter<MODULE*>();
431  SELECTION& selection = selTool->GetSelection();
432  BOARD_COMMIT commit( m_frame );
433 
435  controls->ShowCursor( true );
436  controls->SetSnapping( true );
437 
438  Activate();
439  m_frame->SetToolID( ID_PCB_MODULE_BUTT, wxCURSOR_PENCIL, _( "Add footprint" ) );
440 
441  // Add all the drawable parts to preview
442  VECTOR2I cursorPos = controls->GetCursorPosition();
443 
444  if( module )
445  {
446  module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
447  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
448  }
449 
450  bool reselect = false;
451 
452  // Main loop: keep receiving events
453  while( OPT_TOOL_EVENT evt = Wait() )
454  {
455  cursorPos = controls->GetCursorPosition();
456 
457  if( reselect && module )
458  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
459 
461  {
462  if( module )
463  {
465  commit.Revert();
466  module = NULL;
467  }
468  else // let's have another chance placing a module
469  break;
470 
471  if( evt->IsActivate() ) // now finish unconditionally
472  break;
473  }
474 
475  else if( evt->IsClick( BUT_LEFT ) )
476  {
477  if( !module )
478  {
479  // Pick the module to be placed
481 
482  if( module == NULL )
483  continue;
484 
485  module->SetLink( 0 );
486  m_frame->AddModuleToBoard( module );
487  commit.Added( module );
488  module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
489  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, module );
490  controls->SetCursorPosition( cursorPos, false );
491  }
492  else
493  {
495  commit.Push( _( "Place a module" ) );
496  module = NULL; // to indicate that there is no module that we currently modify
497  }
498  }
499 
500  else if( evt->IsClick( BUT_RIGHT ) )
501  {
502  m_menu.ShowContextMenu( selTool->GetSelection() );
503  }
504 
505  else if( module && evt->IsMotion() )
506  {
507  module->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
508  selection.SetReferencePoint( cursorPos );
509  getView()->Update( &selection );
510  }
511 
512  else if( module && evt->IsAction( &PCB_ACTIONS::properties ) )
513  {
514  // Calling 'Properties' action clears the selection, so we need to restore it
515  reselect = true;
516  }
517 
518  // Enable autopanning and cursor capture only when there is a module to be placed
519  controls->SetAutoPan( !!module );
520  controls->CaptureCursor( !!module );
521  }
522 
524 
525  return 0;
526 }
527 
528 
530 {
531  return modifyLockSelected( TOGGLE );
532 }
533 
534 
536 {
537  return modifyLockSelected( ON );
538 }
539 
540 
542 {
543  return modifyLockSelected( OFF );
544 }
545 
546 
548 {
550  const SELECTION& selection = selTool->GetSelection();
551 
552  if( selection.Empty() )
554 
555  bool modified = false;
556 
557  for( auto i : selection )
558  {
559  auto item = static_cast<BOARD_ITEM*>( i );
560  bool prevState = item->IsLocked();
561 
562  switch( aMode )
563  {
564  case ON:
565  item->SetLocked( true );
566  break;
567 
568  case OFF:
569  item->SetLocked( false );
570  break;
571 
572  case TOGGLE:
573  item->SetLocked( !prevState );
574  break;
575  }
576 
577  // Check if we really modified an item
578  if( !modified && prevState != item->IsLocked() )
579  modified = true;
580  }
581 
582  if( modified )
583  m_frame->OnModify();
584 
585  return 0;
586 }
587 
588 
590 {
591  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
592  KIGFX::VIEW* view = getView();
594  BOARD* board = getModel<BOARD>();
595  PCB_TARGET* target = new PCB_TARGET( board );
596 
597  // Init the new item attributes
598  target->SetLayer( Edge_Cuts );
599  target->SetWidth( board->GetDesignSettings().GetLineThickness( Edge_Cuts ) );
600  target->SetSize( Millimeter2iu( 5 ) );
601  VECTOR2I cursorPos = controls->GetCursorPosition();
602  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
603 
604  // Add a VIEW_GROUP that serves as a preview for the new item
605  KIGFX::VIEW_GROUP preview( view );
606  preview.Add( target );
607  view->Add( &preview );
608 
610  controls->SetSnapping( true );
611 
612  Activate();
613  m_frame->SetToolID( ID_PCB_TARGET_BUTT, wxCURSOR_PENCIL, _( "Add layer alignment target" ) );
614 
615  // Main loop: keep receiving events
616  while( OPT_TOOL_EVENT evt = Wait() )
617  {
618  cursorPos = controls->GetCursorPosition();
619 
621  break;
622 
623  else if( evt->IsAction( &PCB_ACTIONS::incWidth ) )
624  {
625  target->SetWidth( target->GetWidth() + WIDTH_STEP );
626  view->Update( &preview );
627  }
628 
629  else if( evt->IsAction( &PCB_ACTIONS::decWidth ) )
630  {
631  int width = target->GetWidth();
632 
633  if( width > WIDTH_STEP )
634  {
635  target->SetWidth( width - WIDTH_STEP );
636  view->Update( &preview );
637  }
638  }
639 
640  else if( evt->IsClick( BUT_LEFT ) )
641  {
642  assert( target->GetSize() > 0 );
643  assert( target->GetWidth() > 0 );
644 
645  BOARD_COMMIT commit( m_frame );
646  commit.Add( target );
647  commit.Push( _( "Place a layer alignment target" ) );
648 
649  preview.Remove( target );
650 
651  // Create next PCB_TARGET
652  target = new PCB_TARGET( *target );
653  preview.Add( target );
654  }
655 
656  else if( evt->IsClick( BUT_RIGHT ) )
657  {
658  m_menu.ShowContextMenu( selTool->GetSelection() );
659  }
660 
661  else if( evt->IsMotion() )
662  {
663  target->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
664  view->Update( &preview );
665  }
666  }
667 
668  delete target;
669 
670  controls->SetSnapping( false );
671  view->Remove( &preview );
672 
674 
675  return 0;
676 }
677 
678 
679 static bool mergeZones( BOARD_COMMIT& aCommit, std::vector<ZONE_CONTAINER *>& aOriginZones,
680  std::vector<ZONE_CONTAINER *>& aMergedZones )
681 {
682  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
683  {
684  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
686  }
687 
688  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
689 
690  // We should have one polygon with hole
691  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
692  // and therefore cannot be merged (they are dectected as intersecting)
693  // but we should never have more than 2 polys
694  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
695  {
696  wxLogMessage( "BOARD::CombineAreas error: more than 2 polys after merging" );
697  return false;
698  }
699 
700  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
701  {
702  aCommit.Remove( aOriginZones[i] );
703  }
704 
705  aCommit.Modify( aOriginZones[0] );
706  aMergedZones.push_back( aOriginZones[0] );
707 
708  aOriginZones[0]->SetLocalFlags( 1 );
709  aOriginZones[0]->Hatch();
710  aOriginZones[0]->CacheTriangulation();
711 
712  return true;
713 }
714 
715 
717 {
718  const SELECTION& selection = m_toolMgr->GetTool<SELECTION_TOOL>()->GetSelection();
719  BOARD* board = getModel<BOARD>();
720  BOARD_COMMIT commit( m_frame );
721 
722  if( selection.Size() < 2 )
723  return 0;
724 
725  int netcode = -1;
726 
727  ZONE_CONTAINER* firstZone = nullptr;
728  std::vector<ZONE_CONTAINER*> toMerge, merged;
729 
730  for( auto item : selection )
731  {
732  auto curr_area = dynamic_cast<ZONE_CONTAINER*>( item );
733 
734  if( !curr_area )
735  continue;
736 
737  if( !firstZone )
738  firstZone = curr_area;
739 
740  netcode = curr_area->GetNetCode();
741 
742  if( firstZone->GetNetCode() != netcode )
743  continue;
744 
745  if( curr_area->GetPriority() != firstZone->GetPriority() )
746  continue;
747 
748  if( curr_area->GetIsKeepout() != firstZone->GetIsKeepout() )
749  continue;
750 
751  if( curr_area->GetLayer() != firstZone->GetLayer() )
752  continue;
753 
754  if( !board->TestAreaIntersection( curr_area, firstZone ) )
755  continue;
756 
757  toMerge.push_back( curr_area );
758  }
759 
761 
762  if( mergeZones( commit, toMerge, merged ) )
763  {
764  commit.Push( _( "Merge zones" ) );
765 
766  for( auto item : merged )
768  }
769 
770  return 0;
771 }
772 
773 
775 {
776  auto selTool = m_toolMgr->GetTool<SELECTION_TOOL>();
777  const auto& selection = selTool->GetSelection();
778 
779  // because this pops up the zone editor, it would be confusing to handle multiple zones,
780  // so just handle single selections containing exactly one zone
781  if( selection.Size() != 1 )
782  return 0;
783 
784  auto oldZone = dyn_cast<ZONE_CONTAINER*>( selection[0] );
785 
786  if( !oldZone )
787  return 0;
788 
789  ZONE_SETTINGS zoneSettings;
790  zoneSettings << *oldZone;
791  int dialogResult;
792 
793  if( oldZone->GetIsKeepout() )
794  dialogResult = InvokeKeepoutAreaEditor( m_frame, &zoneSettings );
795  else if( oldZone->IsOnCopperLayer() )
796  dialogResult = InvokeCopperZonesEditor( m_frame, &zoneSettings );
797  else
798  dialogResult = InvokeNonCopperZonesEditor( m_frame, &zoneSettings );
799 
800  if( dialogResult != wxID_OK )
801  return 0;
802 
803  // duplicate the zone
804  BOARD_COMMIT commit( m_frame );
805 
806  auto newZone = std::make_unique<ZONE_CONTAINER>( *oldZone );
807  newZone->ClearSelected();
808  newZone->UnFill();
809  zoneSettings.ExportSetting( *newZone );
810 
811  // If the new zone is on the same layer(s) as the the initial zone,
812  // offset it a bit so it can more easily be picked.
813  if( oldZone->GetIsKeepout() && ( oldZone->GetLayerSet() == zoneSettings.m_Layers ) )
814  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
815  else if( !oldZone->GetIsKeepout() && ( oldZone->GetLayer() == zoneSettings.m_CurrentZone_Layer ) )
816  newZone->Move( wxPoint( IU_PER_MM, IU_PER_MM ) );
817 
818  commit.Add( newZone.release() );
819  commit.Push( _( "Duplicate zone" ) );
820 
821  return 0;
822 }
823 
824 
826 {
827  if( m_probingSchToPcb )
828  {
829  m_probingSchToPcb = false;
830  return 0;
831  }
832 
834  const SELECTION& selection = selTool->GetSelection();
835 
836  if( selection.Size() == 1 )
837  m_frame->SendMessageToEESCHEMA( static_cast<BOARD_ITEM*>( selection.Front() ) );
838  else
839  m_frame->SendMessageToEESCHEMA( nullptr );
840 
841  return 0;
842 }
843 
844 
846 {
847  BOARD_ITEM* item = aEvent.Parameter<BOARD_ITEM*>();
848 
849  if( item )
850  {
851  m_probingSchToPcb = true;
852  getView()->SetCenter( VECTOR2D( item->GetPosition() ) );
854 
855  // If it is a pad and the net highlighting tool is enabled, highlight the net
856  if( item->Type() == PCB_PAD_T && m_frame->GetToolId() == ID_PCB_HIGHLIGHT_BUTT )
857  {
858  int net = static_cast<D_PAD*>( item )->GetNetCode();
860  }
861  else
862  // Otherwise simply select the corresponding item
863  {
865  // Ensure the display is refreshed, because in some installs
866  // the refresh is done only when the gal canvas has the focus, and
867  // that is not the case when crossprobing from Eeschema:
869  }
870  }
871 
872  return 0;
873 }
874 
875 
877  BOARD_ITEM* originViewItem, const VECTOR2D& aPosition )
878 {
879  aFrame->SetAuxOrigin( wxPoint( aPosition.x, aPosition.y ) );
880  originViewItem->SetPosition( wxPoint( aPosition.x, aPosition.y ) );
881  aView->MarkDirty();
882  aFrame->OnModify();
883  return true;
884 }
885 
886 
888  BOARD_ITEM* originViewItem, const VECTOR2D& aPosition )
889 {
890  aFrame->SaveCopyInUndoList( originViewItem, UR_DRILLORIGIN );
891  return DoSetDrillOrigin( aView, aFrame, originViewItem, aPosition );
892 }
893 
894 
896 {
897  Activate();
898 
900  assert( picker );
901 
902  m_frame->SetToolID( ID_PCB_PLACE_OFFSET_COORD_BUTT, wxCURSOR_HAND, _( "Adjust zero" ) );
903  picker->SetClickHandler( std::bind( SetDrillOrigin, getView(), m_frame,
904  m_placeOrigin.get(), _1 ) );
905  picker->Activate();
906  Wait();
907 
908  return 0;
909 }
910 
911 
920 static bool highlightNet( TOOL_MANAGER* aToolMgr, const VECTOR2D& aPosition,
921  bool aUseSelection = false )
922 {
923  auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
924  auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
925 
926  BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
927 
928  int net = -1;
929  bool enableHighlight = false;
930 
931  if( aUseSelection )
932  {
933  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
934 
935  const SELECTION& selection = selectionTool->GetSelection();
936 
937  for( auto item : selection )
938  {
939  if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
940  {
941  auto ci = static_cast<BOARD_CONNECTED_ITEM*>( item );
942 
943  int item_net = ci->GetNetCode();
944 
945  if( net < 0 )
946  {
947  net = item_net;
948  }
949  else if( net != item_net )
950  {
951  // more than one net selected: do nothing
952  return 0;
953  }
954  }
955  }
956 
957  enableHighlight = ( net >= 0 && net != render->GetHighlightNetCode() );
958  }
959 
960  // If we didn't get a net to highlight from the selection, use the cursor
961  if( net < 0 )
962  {
963  auto guide = frame->GetCollectorsGuide();
964  GENERAL_COLLECTOR collector;
965 
966  // Find a connected item for which we are going to highlight a net
967  collector.Collect( board, GENERAL_COLLECTOR::PadsOrTracks,
968  wxPoint( aPosition.x, aPosition.y ), guide );
969 
970  if( collector.GetCount() == 0 )
971  collector.Collect( board, GENERAL_COLLECTOR::Zones,
972  wxPoint( aPosition.x, aPosition.y ), guide );
973 
974  for( int i = 0; i < collector.GetCount(); i++ )
975  {
976  if( collector[i]->Type() == PCB_PAD_T )
977  {
978  frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
979  break;
980  }
981  }
982 
983  enableHighlight = ( collector.GetCount() > 0 );
984 
985  // Obtain net code for the clicked item
986  if( enableHighlight )
987  net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
988  }
989 
990  // Toggle highlight when the same net was picked
991  if( net > 0 && net == render->GetHighlightNetCode() )
992  enableHighlight = !render->IsHighlightEnabled();
993 
994  if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
995  {
996  render->SetHighlight( enableHighlight, net );
997  aToolMgr->GetView()->UpdateAllLayersColor();
998  }
999 
1000  // Store the highlighted netcode in the current board (for dialogs for instance)
1001  if( enableHighlight && net >= 0 )
1002  {
1003  board->SetHighLightNet( net );
1004 
1005  NETINFO_ITEM* netinfo = board->FindNet( net );
1006 
1007  if( netinfo )
1008  {
1009  MSG_PANEL_ITEMS items;
1010  netinfo->GetMsgPanelInfo( frame->GetUserUnits(), items );
1011  frame->SetMsgPanel( items );
1012  frame->SendCrossProbeNetName( netinfo->GetNetname() );
1013  }
1014  }
1015  else
1016  {
1017  board->ResetHighLight();
1018  frame->SetMsgPanel( board );
1020  }
1021 
1022  return true;
1023 }
1024 
1025 
1027 {
1028  int netcode = aEvent.Parameter<intptr_t>();
1029 
1030  if( netcode > 0 )
1031  {
1033  render->SetHighlight( true, netcode );
1035  }
1036  else
1037  {
1038  // No net code specified, pick the net code belonging to the item under the cursor
1039  highlightNet( m_toolMgr, getViewControls()->GetMousePosition() );
1040  }
1041 
1042  return 0;
1043 }
1044 
1045 
1047 {
1048  auto frame = static_cast<PCB_EDIT_FRAME*>( m_toolMgr->GetEditFrame() );
1049  auto board = static_cast<BOARD*>( m_toolMgr->GetModel() );
1051 
1052  board->ResetHighLight();
1053  render->SetHighlight( false );
1055  frame->SetMsgPanel( board );
1057  return 0;
1058 }
1059 
1060 
1062 {
1063  // If the keyboard hotkey was triggered, the behavior is as follows:
1064  // If we are already in the highlight tool, behave the same as a left click.
1065  // If we are not, highlight the net of the selected item(s), or if there is
1066  // no selection, then behave like a Ctrl+Left Click.
1068  {
1069  bool use_selection = ( m_frame->GetToolId() != ID_PCB_HIGHLIGHT_BUTT );
1070  highlightNet( m_toolMgr, getViewControls()->GetMousePosition(),
1071  use_selection );
1072  }
1073 
1074  Activate();
1075 
1076  PICKER_TOOL* picker = m_toolMgr->GetTool<PICKER_TOOL>();
1077  assert( picker );
1078 
1079  m_frame->SetToolID( ID_PCB_HIGHLIGHT_BUTT, wxCURSOR_HAND, _( "Highlight net" ) );
1080  picker->SetClickHandler( std::bind( highlightNet, m_toolMgr, _1, false ) );
1081  picker->SetLayerSet( LSET::AllCuMask() );
1082  picker->Activate();
1083  Wait();
1084 
1085  return 0;
1086 }
1087 
1088 
1089 static bool showLocalRatsnest( TOOL_MANAGER* aToolMgr, BOARD* aBoard, const VECTOR2D& aPosition )
1090 {
1091  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
1092 
1093  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
1095  SELECTION& selection = selectionTool->GetSelection();
1096 
1097  if( selection.Empty() )
1098  {
1100  selection = selectionTool->GetSelection();
1101  }
1102 
1103  if( selection.Empty() )
1104  {
1105  // Clear the previous local ratsnest if we click off all items
1106  for( auto mod : aBoard->Modules() )
1107  {
1108  for( auto pad : mod->Pads() )
1109  pad->SetLocalRatsnestVisible( aBoard->IsElementVisible( LAYER_RATSNEST ) );
1110  }
1111  }
1112  else
1113  {
1114  for( auto item : selection )
1115  {
1116  if( auto pad = dyn_cast<D_PAD*>(item) )
1117  {
1118  pad->SetLocalRatsnestVisible( !pad->GetLocalRatsnestVisible() );
1119  }
1120  else if( auto mod = dyn_cast<MODULE*>(item) )
1121  {
1122  bool enable = !( *( mod->Pads().begin() ) )->GetLocalRatsnestVisible();
1123 
1124  for( auto modpad : mod->Pads() )
1125  {
1126  modpad->SetLocalRatsnestVisible( enable );
1127  }
1128  }
1129  }
1130  }
1131 
1133 
1134  return true;
1135 }
1136 
1137 
1139 {
1140  Activate();
1141 
1142  auto picker = m_toolMgr->GetTool<PICKER_TOOL>();
1143  auto board = getModel<BOARD>();
1144  wxASSERT( picker );
1145  wxASSERT( board );
1146 
1147  m_frame->SetToolID( ID_PCB_SHOW_1_RATSNEST_BUTT, wxCURSOR_PENCIL,
1148  _( "Pick Components for Local Ratsnest" ) );
1149  picker->SetClickHandler( std::bind( showLocalRatsnest, m_toolMgr, board, _1 ) );
1150  picker->SetFinalizeHandler( [ board ]( int aCondition ){
1151  auto vis = board->IsElementVisible( LAYER_RATSNEST );
1152 
1153  if( aCondition != PICKER_TOOL::END_ACTIVATE )
1154  {
1155  for( auto mod : board->Modules() )
1156  for( auto pad : mod->Pads() )
1157  pad->SetLocalRatsnestVisible( vis );
1158  }
1159  } );
1160 
1161  picker->SetSnapping( false );
1162  picker->Activate();
1163  Wait();
1164 
1165  return 0;
1166 }
1167 
1168 
1170 {
1171  auto selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
1172  auto& selection = selectionTool->GetSelection();
1173  auto connectivity = getModel<BOARD>()->GetConnectivity();
1174 
1175  if( selection.Empty() )
1176  {
1177  connectivity->ClearDynamicRatsnest();
1178  }
1179  else if( m_slowRatsnest )
1180  {
1181  // Compute ratsnest only when user stops dragging for a moment
1182  connectivity->HideDynamicRatsnest();
1183  m_ratsnestTimer.Start( 20 );
1184  }
1185  else
1186  {
1187  // Check how much time doest it take to calculate ratsnest
1188  PROF_COUNTER counter;
1190  counter.Stop();
1191 
1192  // If it is too slow, then switch to 'slow ratsnest' mode when
1193  // ratsnest is calculated when user stops dragging items for a moment
1194  if( counter.msecs() > 25 )
1195  {
1196  m_slowRatsnest = true;
1197  connectivity->HideDynamicRatsnest();
1198  }
1199  }
1200 
1201  return 0;
1202 }
1203 
1204 
1206 {
1207  getModel<BOARD>()->GetConnectivity()->ClearDynamicRatsnest();
1208  m_slowRatsnest = false;
1209  return 0;
1210 }
1211 
1212 
1213 void PCB_EDITOR_CONTROL::ratsnestTimer( wxTimerEvent& aEvent )
1214 {
1215  m_ratsnestTimer.Stop();
1217  static_cast<PCB_DRAW_PANEL_GAL*>( m_frame->GetGalCanvas() )->RedrawRatsnest();
1219 }
1220 
1221 
1223 {
1224  auto selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
1225  auto& selection = selectionTool->GetSelection();
1226  auto connectivity = board()->GetConnectivity();
1227 
1228  std::vector<BOARD_ITEM*> items;
1229  items.reserve( selection.Size() );
1230 
1231  for( auto item : selection )
1232  {
1233  auto board_item = static_cast<BOARD_CONNECTED_ITEM*>( item );
1234 
1235  if( board_item->Type() != PCB_MODULE_T && board_item->GetLocalRatsnestVisible() )
1236  {
1237  items.push_back( board_item );
1238  }
1239  else if( board_item->Type() == PCB_MODULE_T )
1240  {
1241  for( auto pad : static_cast<MODULE*>( item )->Pads() )
1242  {
1243  if( pad->GetLocalRatsnestVisible() )
1244  items.push_back( pad );
1245  }
1246  }
1247  }
1248 
1249  connectivity->ComputeDynamicRatsnest( items );
1250 }
1251 
1252 
1254 {
1255  // Track & via size control
1260 
1261  // Zone actions
1264 
1265  // Placing tools
1268 
1269  // Other
1282 
1286 }
1287 
1288 
1289 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:676
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:362
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:59
static TOOL_ACTION placeModule
Activation of the drawing tool (placing a MODULE)
Definition: pcb_actions.h:183
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:364
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:192
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:177
static TOOL_ACTION drillOrigin
Definition: pcb_actions.h:379
static TOOL_ACTION lock
Definition: pcb_actions.h:363
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:303
static TOOL_ACTION viaSizeInc
Definition: pcb_actions.h:296
std::vector< int > m_TrackWidthList
void SetClickHandler(CLICK_HANDLER aHandler)
Function SetClickHandler() Sets a handler for mouse click event.
Definition: picker_tool.h:95
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:307
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:375
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:363
static TOOL_ACTION trackWidthDec
Definition: pcb_actions.h:295
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:299
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:377
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:386
static TOOL_ACTION zoneFill
Definition: pcb_actions.h:302
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:61
static TOOL_ACTION crossProbeSchToPcb
Definition: pcb_actions.h:380
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:195
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:630
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:294
class MODULE, a footprint
Definition: typeinfo.h:89
static TOOL_ACTION appendBoard
Definition: pcb_actions.h:381
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:600
int ViaSizeDec(const TOOL_EVENT &aEvent)
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:255
VECTOR2< double > VECTOR2D
Definition: vector2d.h:586
int ClearHighlight(const TOOL_EVENT &aEvent)
Clears all board highlights
static TOOL_ACTION hideLocalRatsnest
Definition: pcb_actions.h:387
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:577
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:281
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:306
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:539
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 (...
Items that may change while the view stays the same (noncached)
Definition: definitions.h:43
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.
static const TOOL_EVENT UnselectedEvent
Event sent after an item is unselected.
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:1538
static TOOL_ACTION drawZoneCutout
Activation of the drawing tool (drawing a ZONE cutout)
Definition: pcb_actions.h:174
static TOOL_ACTION placeTarget
Activation of the drawing tool (placing a TARGET)
Definition: pcb_actions.h:180
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:305
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:304
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:375
static void PadFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function PadFilter()
Definition: edit_tool.cpp:1218
int GetNetCode() const
Function GetNetCode.
void SetHighLightNet(int aNetCode)
Function SetHighLightNet.
Definition: class_board.h:379
static TOOL_ACTION zoneDuplicate
Duplicate zone onto another layer.
Definition: pcb_actions.h:310
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:88
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:376
static TOOL_ACTION highlightNetSelection
Definition: pcb_actions.h:378
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:171
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:516
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:925
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:345
static TOOL_ACTION findMove
Find an item and start moving.
Definition: pcb_actions.h:394
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:388
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:1230
static bool highlightNet(TOOL_MANAGER *aToolMgr, const VECTOR2D &aPosition, bool aUseSelection=false)
Look for a BOARD_CONNECTED_ITEM in a given spot and if one is found - it enables highlight for its ne...
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:106
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:796
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:297
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:297
#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