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_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)
 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, const VECTOR2D &aPosition)
 

Function Documentation

static bool highlightNet ( TOOL_MANAGER aToolMgr,
const VECTOR2D aPosition 
)
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).

Definition at line 919 of file pcb_editor_control.cpp.

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

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

920 {
921  auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
922  auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
923  auto guide = frame->GetCollectorsGuide();
924  BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
925  GENERAL_COLLECTOR collector;
926  int net = -1;
927 
928  // Find a connected item for which we are going to highlight a net
930  wxPoint( aPosition.x, aPosition.y ), guide );
931 
932  for( int i = 0; i < collector.GetCount(); i++ )
933  {
934  if( collector[i]->Type() == PCB_PAD_T )
935  {
936  frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
937  break;
938  }
939  }
940 
941  bool enableHighlight = ( collector.GetCount() > 0 );
942 
943  // Obtain net code for the clicked item
944  if( enableHighlight )
945  net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
946 
947  // Toggle highlight when the same net was picked
948  if( net > 0 && net == render->GetHighlightNetCode() )
949  enableHighlight = !render->IsHighlightEnabled();
950 
951  if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
952  {
953  render->SetHighlight( enableHighlight, net );
954  aToolMgr->GetView()->UpdateAllLayersColor();
955  }
956 
957  // Store the highlighted netcode in the current board (for dialogs for instance)
958  if( enableHighlight && net >= 0 )
959  {
960  board->SetHighLightNet( net );
961 
962  NETINFO_ITEM* netinfo = board->FindNet( net );
963 
964  if( netinfo )
965  {
966  MSG_PANEL_ITEMS items;
967  netinfo->GetMsgPanelInfo( items );
968  frame->SetMsgPanel( items );
969  frame->SendCrossProbeNetName( netinfo->GetNetname() );
970  }
971  }
972  else
973  {
974  board->ResetHighLight();
975  frame->SetMsgPanel( board );
976  frame->SendCrossProbeNetName( "" );
977  }
978 
979  return true;
980 }
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:107
static const KICAD_T PadsTracksOrZones[]
A scan list for PADs, TRACKs, VIAs, or ZONEs.
Definition: collectors.h:285
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:447
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:356
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void GetMsgPanelInfo(std::vector< MSG_PANEL_ITEM > &aList) override
Function GetMsgPanelInfo returns the information about the NETINFO_ITEM in aList to display in the me...
Class BOARD_CONNECTED_ITEM is a base class derived from BOARD_ITEM for items that can be connected an...
GENERAL_COLLECTORS_GUIDE GetCollectorsGuide()
Function GetCollectorsGuide.
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
void SetHighLightNet(int aNetCode)
Function SetHighLightNet.
Definition: class_board.h:372
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:169
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:227
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
const wxString & GetNetname() const
Function GetNetname.
Definition: netinfo.h:235
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:252
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:672
static bool mergeZones ( BOARD_COMMIT aCommit,
std::vector< ZONE_CONTAINER * > &  aOriginZones,
std::vector< ZONE_CONTAINER * > &  aMergedZones 
)
static

Definition at line 665 of file pcb_editor_control.cpp.

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

Referenced by PCB_EDITOR_CONTROL::ZoneMerge().

667 {
668  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
669  {
670  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
672  }
673 
674  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
675 
676  // We should have one polygon with hole
677  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
678  // and therefore cannot be merged (they are dectected as intersecting)
679  // but we should never have more than 2 polys
680  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
681  {
682  wxLogMessage( wxT( "BOARD::CombineAreas error: more than 2 polys after merging" ) );
683  return false;
684  }
685 
686  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
687  {
688  aCommit.Remove( aOriginZones[i] );
689  }
690 
691  aCommit.Modify( aOriginZones[0] );
692  aMergedZones.push_back( aOriginZones[0] );
693 
694  aOriginZones[0]->SetLocalFlags( 1 );
695  aOriginZones[0]->Hatch();
696  aOriginZones[0]->CacheTriangulation();
697 
698  return true;
699 }
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
static bool showLocalRatsnest ( TOOL_MANAGER aToolMgr,
const VECTOR2D aPosition 
)
static

Definition at line 1020 of file pcb_editor_control.cpp.

References SELECTION::Empty(), EDIT_TOOL::FootprintFilter(), TOOL_MANAGER::GetTool(), PCB_MODULE_T, TOOL_MANAGER::RunAction(), PCB_TOOL::selection(), PCB_ACTIONS::selectionClear, and PCB_ACTIONS::selectionCursor.

Referenced by PCB_EDITOR_CONTROL::ShowLocalRatsnest().

1021 {
1022  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
1023 
1024  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
1026 
1027  const SELECTION& selection = selectionTool->GetSelection();
1028 
1029  if( selection.Empty() )
1030  return true;
1031 
1032  for( auto item : selection )
1033  {
1034  if( item->Type() == PCB_MODULE_T )
1035  {
1036  for( auto pad : static_cast<MODULE *> (item)->Pads() )
1037  {
1038  pad->SetLocalRatsnestVisible( true );
1039  }
1040  }
1041  }
1042 
1043  return true;
1044 }
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:106
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
class MODULE, a footprint
Definition: typeinfo.h:89
static void FootprintFilter(const VECTOR2I &, GENERAL_COLLECTOR &aCollector)
Function FootprintFilter()
Definition: edit_tool.cpp:1095
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50