KiCad PCB EDA Suite
pcb_editor_control.cpp File Reference
#include <cstdint>
#include "pcb_editor_control.h"
#include "pcb_actions.h"
#include <tool/tool_manager.h>
#include <wx/progdlg.h>
#include "selection_tool.h"
#include "drawing_tool.h"
#include "picker_tool.h"
#include <painter.h>
#include <project.h>
#include <pcbnew_id.h>
#include <wxPcbStruct.h>
#include <class_board.h>
#include <class_zone.h>
#include <class_draw_panel_gal.h>
#include <class_module.h>
#include <class_mire.h>
#include <connectivity.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 <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 setDrillOrigin (KIGFX::VIEW *aView, PCB_BASE_FRAME *aFrame, KIGFX::ORIGIN_VIEWITEM *aItem, const VECTOR2D &aPosition)
 
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 1008 of file pcb_editor_control.cpp.

References GENERAL_COLLECTOR::Collect(), PCB_BASE_FRAME::GetCollectorsGuide(), COLLECTOR::GetCount(), TOOL_MANAGER::GetEditFrame(), TOOL_MANAGER::GetModel(), KIGFX::VIEW::GetPainter(), KIGFX::PAINTER::GetSettings(), TOOL_MANAGER::GetView(), GENERAL_COLLECTOR::PadsTracksOrZones, PCB_PAD_T, BOARD::ResetHighLight(), BOARD::SetHighLightNet(), KIGFX::VIEW::UpdateAllLayersColor(), VECTOR2< T >::x, and VECTOR2< T >::y.

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

1009 {
1010  auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
1011  auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
1012  auto guide = frame->GetCollectorsGuide();
1013  BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
1014  GENERAL_COLLECTOR collector;
1015  int net = -1;
1016 
1017  // Find a connected item for which we are going to highlight a net
1019  wxPoint( aPosition.x, aPosition.y ), guide );
1020 
1021  for( int i = 0; i < collector.GetCount(); i++ )
1022  {
1023  if( collector[i]->Type() == PCB_PAD_T )
1024  {
1025  frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
1026  break;
1027  }
1028  }
1029 
1030  bool enableHighlight = ( collector.GetCount() > 0 );
1031 
1032  // Obtain net code for the clicked item
1033  if( enableHighlight )
1034  net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
1035 
1036  // Toggle highlight when the same net was picked
1037  if( net > 0 && net == render->GetHighlightNetCode() )
1038  enableHighlight = !render->IsHighlightEnabled();
1039 
1040  if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
1041  {
1042  render->SetHighlight( enableHighlight, net );
1043  aToolMgr->GetView()->UpdateAllLayersColor();
1044  }
1045 
1046  // Store the highlighted netcode in the current board (for dialogs for instance)
1047  if( enableHighlight && net >= 0 )
1048  board->SetHighLightNet( net );
1049  else
1050  board->ResetHighLight();
1051 
1052  return true;
1053 }
int GetCount() const
Function GetCount returns the number of objects in the list.
static const KICAD_T PadsTracksOrZones[]
A scan list for PADs, TRACKs, VIAs, or ZONEs.
Definition: collectors.h:276
void Collect(BOARD_ITEM *aItem, const KICAD_T aScanList[], const wxPoint &aRefPos, const COLLECTORS_GUIDE &aGuide)
Function Collect scans a BOARD_ITEM using this class's Inspector method, which does the collection...
Definition: collectors.cpp:447
wxWindow * GetEditFrame() const
Definition: tool_manager.h:258
void ResetHighLight()
Function ResetHighLight Reset all high light data to the init state.
Definition: class_board.h:348
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
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:364
virtual RENDER_SETTINGS * GetSettings()=0
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
EDA_ITEM * GetModel() const
Definition: tool_manager.h:253
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
Class GENERAL_COLLECTOR is intended for use when the right click button is pressed, or when the plain "arrow" tool is in effect.
Definition: collectors.h:211
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:243
void UpdateAllLayersColor()
Function UpdateAllLayersColor() Applies the new coloring scheme to all layers.
Definition: view.cpp:674
static bool mergeZones ( BOARD_COMMIT aCommit,
std::vector< ZONE_CONTAINER * > &  aOriginZones,
std::vector< ZONE_CONTAINER * > &  aMergedZones 
)
static

Definition at line 776 of file pcb_editor_control.cpp.

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

Referenced by PCB_EDITOR_CONTROL::ZoneMerge().

778 {
779  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
780  {
781  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
783  }
784 
785  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
786 
787  // We should have one polygon with hole
788  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
789  // and therefore cannot be merged (they are dectected as intersecting)
790  // but we should never have more than 2 polys
791  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
792  {
793  wxLogMessage( wxT( "BOARD::CombineAreas error: more than 2 polys after merging" ) );
794  return false;
795  }
796 
797  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
798  {
799  aCommit.Remove( aOriginZones[i] );
800  }
801 
802  aCommit.Modify( aOriginZones[0] );
803  aMergedZones.push_back( aOriginZones[0] );
804 
805  aOriginZones[0]->SetLocalFlags( 1 );
806  aOriginZones[0]->Hatch();
807 
808  return true;
809 }
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 setDrillOrigin ( KIGFX::VIEW aView,
PCB_BASE_FRAME aFrame,
KIGFX::ORIGIN_VIEWITEM aItem,
const VECTOR2D aPosition 
)
static

Definition at line 975 of file pcb_editor_control.cpp.

References KIGFX::VIEW::MarkDirty(), PCB_BASE_FRAME::SetAuxOrigin(), KIGFX::ORIGIN_VIEWITEM::SetPosition(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_EDITOR_CONTROL::DrillOrigin().

977 {
978  aFrame->SetAuxOrigin( wxPoint( aPosition.x, aPosition.y ) );
979  aItem->SetPosition( aPosition );
980  aView->MarkDirty();
981 
982  return true;
983 }
void SetPosition(const VECTOR2D &aPosition)
void SetAuxOrigin(const wxPoint &aPoint) override
void MarkDirty()
Function MarkDirty() Forces redraw of view on the next rendering.
Definition: view.h:602
static bool showLocalRatsnest ( TOOL_MANAGER aToolMgr,
const VECTOR2D aPosition 
)
static

Definition at line 1093 of file pcb_editor_control.cpp.

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

Referenced by PCB_EDITOR_CONTROL::ShowLocalRatsnest().

1094 {
1095  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
1096 
1097  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
1098  aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
1099 
1100  const SELECTION& selection = selectionTool->GetSelection();
1101 
1102  if( selection.Empty() )
1103  return true;
1104 
1105  for( auto item : selection )
1106  {
1107  if( item->Type() == PCB_MODULE_T )
1108  {
1109  for( auto pad : static_cast<MODULE *> (item)->Pads() )
1110  {
1111  pad->SetLocalRatsnestVisible( true );
1112  }
1113  }
1114  }
1115 
1116  return true;
1117 }
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:101
static TOOL_ACTION selectionCursor
Select a single item under the cursor position.
Definition: pcb_actions.h:50