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 <pcb_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 <profile.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 1014 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().

1015 {
1016  auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
1017  auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
1018  auto guide = frame->GetCollectorsGuide();
1019  BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
1020  GENERAL_COLLECTOR collector;
1021  int net = -1;
1022 
1023  // Find a connected item for which we are going to highlight a net
1025  wxPoint( aPosition.x, aPosition.y ), guide );
1026 
1027  for( int i = 0; i < collector.GetCount(); i++ )
1028  {
1029  if( collector[i]->Type() == PCB_PAD_T )
1030  {
1031  frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
1032  break;
1033  }
1034  }
1035 
1036  bool enableHighlight = ( collector.GetCount() > 0 );
1037 
1038  // Obtain net code for the clicked item
1039  if( enableHighlight )
1040  net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
1041 
1042  // Toggle highlight when the same net was picked
1043  if( net > 0 && net == render->GetHighlightNetCode() )
1044  enableHighlight = !render->IsHighlightEnabled();
1045 
1046  if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
1047  {
1048  render->SetHighlight( enableHighlight, net );
1049  aToolMgr->GetView()->UpdateAllLayersColor();
1050  }
1051 
1052  // Store the highlighted netcode in the current board (for dialogs for instance)
1053  if( enableHighlight && net >= 0 )
1054  board->SetHighLightNet( net );
1055  else
1056  board->ResetHighLight();
1057 
1058  return true;
1059 }
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:266
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: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:372
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:261
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:251
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 782 of file pcb_editor_control.cpp.

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

Referenced by PCB_EDITOR_CONTROL::ZoneMerge().

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

983 {
984  aFrame->SetAuxOrigin( wxPoint( aPosition.x, aPosition.y ) );
985  aItem->SetPosition( aPosition );
986  aView->MarkDirty();
987 
988  return true;
989 }
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:594
static bool showLocalRatsnest ( TOOL_MANAGER aToolMgr,
const VECTOR2D aPosition 
)
static

Definition at line 1099 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().

1100 {
1101  auto selectionTool = aToolMgr->GetTool<SELECTION_TOOL>();
1102 
1103  aToolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
1104  aToolMgr->RunAction( PCB_ACTIONS::selectionCursor, true );
1105 
1106  const SELECTION& selection = selectionTool->GetSelection();
1107 
1108  if( selection.Empty() )
1109  return true;
1110 
1111  for( auto item : selection )
1112  {
1113  if( item->Type() == PCB_MODULE_T )
1114  {
1115  for( auto pad : static_cast<MODULE *> (item)->Pads() )
1116  {
1117  pad->SetLocalRatsnestVisible( true );
1118  }
1119  }
1120  }
1121 
1122  return true;
1123 }
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