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 "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 <ratsnest_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 <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...
 

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
aPositionis the point where an item is expected (world coordinates).

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

975 {
976  auto render = aToolMgr->GetView()->GetPainter()->GetSettings();
977  auto frame = static_cast<PCB_EDIT_FRAME*>( aToolMgr->GetEditFrame() );
978  auto guide = frame->GetCollectorsGuide();
979  BOARD* board = static_cast<BOARD*>( aToolMgr->GetModel() );
980  GENERAL_COLLECTOR collector;
981  int net = -1;
982 
983  // Find a connected item for which we are going to highlight a net
985  wxPoint( aPosition.x, aPosition.y ), guide );
986 
987  for( int i = 0; i < collector.GetCount(); i++ )
988  {
989  if( collector[i]->Type() == PCB_PAD_T )
990  {
991  frame->SendMessageToEESCHEMA( static_cast<BOARD_CONNECTED_ITEM*>( collector[i] ) );
992  break;
993  }
994  }
995 
996  bool enableHighlight = ( collector.GetCount() > 0 );
997 
998  // Obtain net code for the clicked item
999  if( enableHighlight )
1000  net = static_cast<BOARD_CONNECTED_ITEM*>( collector[0] )->GetNetCode();
1001 
1002  // Toggle highlight when the same net was picked
1003  if( net > 0 && net == render->GetHighlightNetCode() )
1004  enableHighlight = !render->IsHighlightEnabled();
1005 
1006  if( enableHighlight != render->IsHighlightEnabled() || net != render->GetHighlightNetCode() )
1007  {
1008  render->SetHighlight( enableHighlight, net );
1009  aToolMgr->GetView()->UpdateAllLayersColor();
1010  }
1011 
1012  // Store the highlighted netcode in the current board (for dialogs for instance)
1013  if( enableHighlight && net >= 0 )
1014  board->SetHighLightNet( net );
1015  else
1016  board->ResetHighLight();
1017 
1018  return true;
1019 }
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:343
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:359
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:166
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 750 of file pcb_editor_control.cpp.

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

Referenced by PCB_EDITOR_CONTROL::ZoneMerge().

752 {
753  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
754  {
755  aOriginZones[0]->Outline()->BooleanAdd( *aOriginZones[i]->Outline(),
757  }
758 
759  aOriginZones[0]->Outline()->Simplify( SHAPE_POLY_SET::PM_FAST );
760 
761  // We should have one polygon with hole
762  // We can have 2 polygons with hole, if the 2 initial polygons have only one common corner
763  // and therefore cannot be merged (they are dectected as intersecting)
764  // but we should never have more than 2 polys
765  if( aOriginZones[0]->Outline()->OutlineCount() > 1 )
766  {
767  wxLogMessage( wxT( "BOARD::CombineAreas error: more than 2 polys after merging" ) );
768  return false;
769  }
770 
771  for( unsigned int i = 1; i < aOriginZones.size(); i++ )
772  {
773  aCommit.Remove( aOriginZones[i] );
774  }
775 
776  aCommit.Modify( aOriginZones[0] );
777  aMergedZones.push_back( aOriginZones[0] );
778 
779  aOriginZones[0]->SetLocalFlags( 1 );
780  aOriginZones[0]->Hatch();
781 
782  return true;
783 }
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 942 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().

944 {
945  aFrame->SetAuxOrigin( wxPoint( aPosition.x, aPosition.y ) );
946  aItem->SetPosition( aPosition );
947  aView->MarkDirty();
948 
949  return true;
950 }
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