KiCad PCB EDA Suite
pcb_editor_control.cpp File Reference
#include <cstdint>
#include <thread>
#include <mutex>
#include "pcb_editor_control.h"
#include "pcb_actions.h"
#include <tool/tool_manager.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>
#include <tools/tool_event_utils.h>
#include <functional>

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)
 Function highlightNet() Looks 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

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

Function highlightNet() Looks 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 907 of file pcb_editor_control.cpp.

References PCB_TOOL::board(), BOARD_CONNECTED_ITEM::ClassOf(), GENERAL_COLLECTOR::Collect(), BOARD::FindNet(), PCB_TOOL::frame(), PCB_BASE_FRAME::GetCollectorsGuide(), COLLECTOR::GetCount(), TOOL_MANAGER::GetEditFrame(), TOOL_MANAGER::GetModel(), NETINFO_ITEM::GetMsgPanelInfo(), BOARD_CONNECTED_ITEM::GetNetCode(), NETINFO_ITEM::GetNetname(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_MANAGER::GetTool(), EDA_DRAW_FRAME::GetUserUnits(), TOOL_MANAGER::GetView(), i, GENERAL_COLLECTOR::PadsOrTracks, PCB_PAD_T, BOARD::ResetHighLight(), PCB_TOOL::selection(), PCB_EDIT_FRAME::SendCrossProbeNetName(), PCB_EDIT_FRAME::SendMessageToEESCHEMA(), BOARD::SetHighLightNet(), EDA_DRAW_FRAME::SetMsgPanel(), KIGFX::VIEW::UpdateAllLayersColor(), VECTOR2< T >::x, VECTOR2< T >::y, and GENERAL_COLLECTOR::Zones.

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

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 );
1006  frame->SendCrossProbeNetName( "" );
1007  }
1008 
1009  return true;
1010 }
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:114
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
Class SELECTION_TOOL.
wxWindow * GetEditFrame() const
Definition: tool_manager.h:267
void ResetHighLight()
Function ResetHighLight Reset all high light data to the init state.
Definition: class_board.h:362
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
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
static const KICAD_T Zones[]
A scan list for zones outlines only.
Definition: collectors.h:282
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
static bool ClassOf(const EDA_ITEM *aItem)
int GetNetCode() const
Function GetNetCode.
void SetHighLightNet(int aNetCode)
Function SetHighLightNet.
Definition: class_board.h:378
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:69
EDA_ITEM * GetModel() const
Definition: tool_manager.h:262
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:245
size_t i
Definition: json11.cpp:597
Class PCB_EDIT_FRAME is the main frame for Pcbnew.
NETINFO_ITEM * FindNet(int aNetcode) const
Function FindNet searches for a net with the given netcode.
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...
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:239
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
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

Definition at line 670 of file pcb_editor_control.cpp.

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

Referenced by PCB_EDITOR_CONTROL::ZoneMerge().

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 }
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
static bool showLocalRatsnest ( TOOL_MANAGER aToolMgr,
BOARD aBoard,
const VECTOR2D aPosition 
)
static

Definition at line 1076 of file pcb_editor_control.cpp.

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

Referenced by PCB_EDITOR_CONTROL::ShowLocalRatsnest().

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 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:116
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
Auxiliary rendering target (noncached)
Definition: definitions.h:42
DLIST_ITERATOR_WRAPPER< MODULE > Modules()
Definition: class_board.h:254
void MarkTargetDirty(int aTarget)
Function MarkTargetDirty() Sets or clears target &#39;dirty&#39; flag.
Definition: view.h:596
bool IsElementVisible(GAL_LAYER_ID aLayer) const
Function IsElementVisible tests whether a given element category is visible.
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function FootprintFilter()
Definition: edit_tool.cpp:1167
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
#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