KiCad PCB EDA Suite
pcb_editor_control.cpp File Reference
#include <cstdint>
#include <thread>
#include <mutex>
#include <functional>
#include "pcb_editor_control.h"
#include "pcb_actions.h"
#include <tool/tool_manager.h>
#include <tools/tool_event_utils.h>
#include <wx/progdlg.h>
#include "edit_tool.h"
#include "selection_tool.h"
#include "drawing_tool.h"
#include "picker_tool.h"
#include <painter.h>
#include <project.h>
#include <pcbnew_id.h>
#include <pcb_edit_frame.h>
#include <class_board.h>
#include <class_zone.h>
#include <pcb_draw_panel_gal.h>
#include <class_module.h>
#include <class_pcb_target.h>
#include <connectivity/connectivity_data.h>
#include <collectors.h>
#include <zones_functions_for_undo_redo.h>
#include <board_commit.h>
#include <confirm.h>
#include <bitmaps.h>
#include <hotkeys.h>
#include <view/view_group.h>
#include <view/view_controls.h>
#include <origin_viewitem.h>
#include <profile.h>
#include <widgets/progress_reporter.h>

Go to the source code of this file.

Classes

class  ZONE_CONTEXT_MENU
 
class  LOCK_CONTEXT_MENU
 

Functions

static bool mergeZones (BOARD_COMMIT &aCommit, std::vector< ZONE_CONTAINER * > &aOriginZones, std::vector< ZONE_CONTAINER * > &aMergedZones)
 
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 net. More...
 
static bool showLocalRatsnest (TOOL_MANAGER *aToolMgr, BOARD *aBoard, const VECTOR2D &aPosition)
 

Function Documentation

◆ highlightNet()

static bool highlightNet ( TOOL_MANAGER aToolMgr,
const VECTOR2D aPosition,
bool  aUseSelection = false 
)
static

Look for a BOARD_CONNECTED_ITEM in a given spot and if one is found - it enables highlight for its net.

Parameters
aToolMgris the TOOL_MANAGER currently in use.
aPositionis the point where an item is expected (world coordinates).
aUseSelectionis true if we should use the current selection to pick the netcode

Definition at line 927 of file pcb_editor_control.cpp.

929 {
930  auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
931  auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
932 
933  BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
934 
935  int net = -1;
936  bool enableHighlight = false;
937 
938  if( aUseSelection )
939  {
940  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
941 
942  const SELECTION& selection = selectionTool->GetSelection();
943 
944  for( auto item : selection )
945  {
946  if( BOARD_CONNECTED_ITEM::ClassOf( item ) )
947  {
948  auto ci = static_cast<BOARD_CONNECTED_ITEM*>( item );
949 
950  int item_net = ci->GetNetCode();
951 
952  if( net < 0 )
953  {
954  net = item_net;
955  }
956  else if( net != item_net )
957  {
958  // more than one net selected: do nothing
959  return 0;
960  }
961  }
962  }
963 
964  enableHighlight = ( net >= 0 && net != render->GetHighlightNetCode() );
965  }
966 
967  // If we didn't get a net to highlight from the selection, use the cursor
968  if( net < 0 )
969  {
970  auto guide = frame->GetCollectorsGuide();
971  GENERAL_COLLECTOR collector;
972 
973  // Find a connected item for which we are going to highlight a net
974  collector.Collect( board, GENERAL_COLLECTOR::PadsOrTracks, (wxPoint) aPosition, guide );
975 
976  if( collector.GetCount() == 0 )
977  collector.Collect( board, GENERAL_COLLECTOR::Zones, (wxPoint) aPosition, guide );
978 
979  // Clear the previous highlight
980  frame->SendMessageToEESCHEMA( nullptr );
981 
982  for( int i = 0; i < collector.GetCount(); i++ )
983  {
984  if( ( collector[i]->GetLayerSet() & LSET::AllCuMask() ).none() )
985  collector.Remove( i );
986 
987  if( collector[i]->Type() == PCB_PAD_T )
988  {
989  frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
990  break;
991  }
992  }
993 
994  enableHighlight = ( collector.GetCount() > 0 );
995 
996  // Obtain net code for the clicked item
997  if( enableHighlight )
998  net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
999  }
1000 
1001  // Toggle highlight when the same net was picked
1002  if( net > 0 && net == render->GetHighlightNetCode() )
1003  enableHighlight = !render->IsHighlightEnabled();
1004 
1005  if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
1006  {
1007  render->SetHighlight( enableHighlight, net );
1008  aToolMgr->GetView()->UpdateAllLayersColor();
1009  }
1010 
1011  // Store the highlighted netcode in the current board (for dialogs for instance)
1012  if( enableHighlight && net >= 0 )
1013  {
1014  board->SetHighLightNet( net );
1015 
1016  NETINFO_ITEM* netinfo = board->FindNet( net );
1017 
1018  if( netinfo )
1019  {
1020  MSG_PANEL_ITEMS items;
1021  netinfo->GetMsgPanelInfo( frame->GetUserUnits(), items );
1022  frame->SetMsgPanel( items );
1023  frame->SendCrossProbeNetName( netinfo->GetNetname() );
1024  }
1025  }
1026  else
1027  {
1028  board->ResetHighLight();
1029  frame->SetMsgPanel( board );
1030  frame->SendCrossProbeNetName( "" );
1031  }
1032 
1033  return true;
1034 }
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
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Definition: collectors.cpp:473
Class SELECTION_TOOL.
EDA_DRAW_FRAME * GetEditFrame() const
Definition: tool_manager.h:267
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:298
EDA_ITEM * GetModel() const
Definition: tool_manager.h:262
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:143
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:277
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:235
static bool ClassOf(const EDA_ITEM *aItem)
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
Class NETINFO_ITEM handles the data for a net.
Definition: netinfo.h:65
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:170
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
size_t i
Definition: json11.cpp:597
std::vector< MSG_PANEL_ITEM > MSG_PANEL_ITEMS
Definition: msgpanel.h:102
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...
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:797

References LSET::AllCuMask(), BOARD_CONNECTED_ITEM::ClassOf(), GENERAL_COLLECTOR::Collect(), COLLECTOR::GetCount(), TOOL_MANAGER::GetEditFrame(), TOOL_MANAGER::GetModel(), NETINFO_ITEM::GetMsgPanelInfo(), NETINFO_ITEM::GetNetname(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_MANAGER::GetTool(), TOOL_MANAGER::GetView(), i, GENERAL_COLLECTOR::PadsOrTracks, PCB_PAD_T, COLLECTOR::Remove(), KIGFX::VIEW::UpdateAllLayersColor(), and GENERAL_COLLECTOR::Zones.

Referenced by PCB_EDITOR_CONTROL::HighlightNet(), and PCB_EDITOR_CONTROL::HighlightNetCursor().

◆ mergeZones()

static bool mergeZones ( BOARD_COMMIT aCommit,
std::vector< ZONE_CONTAINER * > &  aOriginZones,
std::vector< ZONE_CONTAINER * > &  aMergedZones 
)
static

Definition at line 685 of file pcb_editor_control.cpp.

687 {
688  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
689  {
690  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
692  }
693 
694  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
695 
696  // We should have one polygon with hole
697  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
698  // and therefore cannot be merged (they are dectected as intersecting)
699  // but we should never have more than 2 polys
700  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
701  {
702  wxLogMessage( "BOARD::CombineAreas error: more than 2 polys after merging" );
703  return false;
704  }
705 
706  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
707  {
708  aCommit.Remove( aOriginZones[i] );
709  }
710 
711  aCommit.Modify( aOriginZones[0] );
712  aMergedZones.push_back( aOriginZones[0] );
713 
714  aOriginZones[0]->SetLocalFlags( 1 );
715  aOriginZones[0]->Hatch();
716  aOriginZones[0]->CacheTriangulation();
717 
718  return true;
719 }
COMMIT & Modify(EDA_ITEM *aItem)
Modifies a given item in the model.
Definition: commit.h:103
COMMIT & Remove(EDA_ITEM *aItem)
Removes a new item from the model
Definition: commit.h:90
size_t i
Definition: json11.cpp:597

References i, COMMIT::Modify(), SHAPE_POLY_SET::PM_FAST, and COMMIT::Remove().

Referenced by PCB_EDITOR_CONTROL::ZoneMerge().

◆ showLocalRatsnest()

static bool showLocalRatsnest ( TOOL_MANAGER aToolMgr,
BOARD aBoard,
const VECTOR2D aPosition 
)
static

Definition at line 1100 of file pcb_editor_control.cpp.

1101 {
1102  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
1103 
1104  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
1106  SELECTION& selection = selectionTool->GetSelection();
1107 
1108  if( selection.Empty() )
1109  {
1111  selection = selectionTool->GetSelection();
1112  }
1113 
1114  if( selection.Empty() )
1115  {
1116  // Clear the previous local ratsnest if we click off all items
1117  for( auto mod : aBoard->Modules() )
1118  {
1119  for( auto pad : mod->Pads() )
1120  pad->SetLocalRatsnestVisible( aBoard->IsElementVisible( LAYER_RATSNEST ) );
1121  }
1122  }
1123  else
1124  {
1125  for( auto item : selection )
1126  {
1127  if( auto pad = dyn_cast<D_PAD*>(item) )
1128  {
1129  pad->SetLocalRatsnestVisible( !pad->GetLocalRatsnestVisible() );
1130  }
1131  else if( auto mod = dyn_cast<MODULE*>(item) )
1132  {
1133  bool enable = !( *( mod->Pads().begin() ) )->GetLocalRatsnestVisible();
1134 
1135  for( auto modpad : mod->Pads() )
1136  {
1137  modpad->SetLocalRatsnestVisible( enable );
1138  }
1139  }
1140  }
1141  }
1142 
1144 
1145  return true;
1146 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
Class SELECTION_TOOL.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:252
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target 'dirty' flag.
Definition: view.h:596
Items that may change while the view stays the same (noncached)
Definition: definitions.h:50
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:119
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
static void PadFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function PadFilter()
Definition: edit_tool.cpp:1222
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function FootprintFilter()
Definition: edit_tool.cpp:1234
#define mod(a, n)
Definition: greymap.cpp:24
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50

References SELECTION::Empty(), EDIT_TOOL::FootprintFilter(), TOOL_MANAGER::GetTool(), TOOL_MANAGER::GetView(), BOARD::IsElementVisible(), LAYER_RATSNEST, KIGFX::VIEW::MarkTargetDirty(), mod, BOARD::Modules(), EDIT_TOOL::PadFilter(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionCursor, and KIGFX::TARGET_OVERLAY.

Referenced by PCB_EDITOR_CONTROL::ShowLocalRatsnest().