KiCad PCB EDA Suite
edit_tool.cpp File Reference
#include <limits>
#include <class_module.h>
#include <class_edge_mod.h>
#include <collectors.h>
#include <pcb_edit_frame.h>
#include <ws_proxy_view_item.h>
#include <kiway.h>
#include <array_creator.h>
#include <pcbnew_settings.h>
#include <status_popup.h>
#include <tool/tool_manager.h>
#include <tools/pcb_actions.h>
#include <tools/selection_tool.h>
#include <tools/edit_tool.h>
#include <tools/pcbnew_picker_tool.h>
#include <tools/tool_event_utils.h>
#include <tools/grid_helper.h>
#include <tools/pad_tool.h>
#include <pad_naming.h>
#include <view/view_controls.h>
#include <connectivity/connectivity_data.h>
#include <confirm.h>
#include <bitmaps.h>
#include <cassert>
#include <functional>
#include "kicad_clipboard.h"
#include <router/router_tool.h>
#include <dialogs/dialog_move_exact.h>
#include <dialogs/dialog_track_via_properties.h>
#include <board_commit.h>
#include <zone_filler.h>

Go to the source code of this file.

Classes

class  SPECIAL_TOOLS_CONTEXT_MENU
 

Functions

void EditToolSelectionFilter (GENERAL_COLLECTOR &aCollector, int aFlags)
 
static wxPoint mirrorPointX (const wxPoint &aPoint, const wxPoint &aMirrorPoint)
 
static void mirrorPadX (D_PAD &aPad, const wxPoint &aMirrorPoint)
 Mirror a pad in the vertical axis passing through a point (mirror left to right) More...
 

Function Documentation

◆ EditToolSelectionFilter()

void EditToolSelectionFilter ( GENERAL_COLLECTOR aCollector,
int  aFlags 
)

Definition at line 61 of file edit_tool.cpp.

62 {
63  // Iterate from the back so we don't have to worry about removals.
64  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
65  {
66  BOARD_ITEM* item = aCollector[ i ];
67 
68  if( ( aFlags & EXCLUDE_LOCKED ) && item->IsLocked() )
69  {
70  aCollector.Remove( item );
71  }
72  else if( item->Type() == PCB_MODULE_ZONE_AREA_T )
73  {
74  MODULE* mod = static_cast<MODULE*>( item->GetParent() );
75 
76  // case 1: handle locking
77  if( ( aFlags & EXCLUDE_LOCKED ) && mod && mod->IsLocked() )
78  {
79  aCollector.Remove( item );
80  }
81 
82  // case 2: selection contains both the module and its pads - remove the pads
83  if( !( aFlags & INCLUDE_PADS_AND_MODULES ) && mod && aCollector.HasItem( mod ) )
84  aCollector.Remove( item );
85  }
86  else if( item->Type() == PCB_PAD_T )
87  {
88  MODULE* mod = static_cast<MODULE*>( item->GetParent() );
89 
90  // case 1: handle locking
91  if( ( aFlags & EXCLUDE_LOCKED ) && mod && mod->IsLocked() )
92  {
93  aCollector.Remove( item );
94  }
95  else if( ( aFlags & EXCLUDE_LOCKED_PADS ) && mod && mod->PadsLocked() )
96  {
97  // Pad locking is considerably "softer" than item locking
98  aCollector.Remove( item );
99 
100  if( !mod->IsLocked() && !aCollector.HasItem( mod ) )
101  aCollector.Append( mod );
102  }
103 
104  // case 2: selection contains both the module and its pads - remove the pads
105  if( !( aFlags & INCLUDE_PADS_AND_MODULES ) && mod && aCollector.HasItem( mod ) )
106  aCollector.Remove( item );
107  }
108  else if( ( aFlags & EXCLUDE_TRANSIENTS ) && item->Type() == PCB_MARKER_T )
109  {
110  aCollector.Remove( item );
111  }
112  }
113 }
#define INCLUDE_PADS_AND_MODULES
Definition: edit_tool.h:56
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
void Remove(int aIndex)
Function Remove removes the item at aIndex (first position is 0);.
Definition: collector.h:130
void Append(EDA_ITEM *item)
Function Append adds an item to the end of the list.
Definition: collector.h:120
int GetCount() const
Function GetCount returns the number of objects in the list.
Definition: collector.h:101
bool HasItem(const EDA_ITEM *aItem) const
Function HasItem tests if aItem has already been collected.
Definition: collector.h:229
bool IsLocked() const override
Function IsLocked.
Definition: class_module.h:308
#define EXCLUDE_TRANSIENTS
Definition: edit_tool.h:55
virtual bool IsLocked() const
Function IsLocked.
class MARKER_PCB, a marker used to show something
Definition: typeinfo.h:99
bool PadsLocked() const
Definition: class_module.h:344
#define EXCLUDE_LOCKED
Function EditToolSelectionFilter.
Definition: edit_tool.h:53
class ZONE_CONTAINER, managed by a footprint
Definition: typeinfo.h:95
#define EXCLUDE_LOCKED_PADS
Definition: edit_tool.h:54
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References COLLECTOR::Append(), EXCLUDE_LOCKED, EXCLUDE_LOCKED_PADS, EXCLUDE_TRANSIENTS, COLLECTOR::GetCount(), BOARD_ITEM::GetParent(), COLLECTOR::HasItem(), INCLUDE_PADS_AND_MODULES, BOARD_ITEM::IsLocked(), MODULE::IsLocked(), MODULE::PadsLocked(), PCB_MARKER_T, PCB_MODULE_ZONE_AREA_T, PCB_PAD_T, COLLECTOR::Remove(), and EDA_ITEM::Type().

Referenced by EDIT_TOOL::ChangeTrackWidth(), EDIT_TOOL::copyToClipboard(), EDIT_TOOL::CreateArray(), ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally(), ALIGN_DISTRIBUTE_TOOL::DistributeVertically(), EDIT_TOOL::doMoveSelection(), EDIT_TOOL::Duplicate(), EDIT_TOOL::Flip(), ALIGN_DISTRIBUTE_TOOL::GetSelections(), EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), POSITION_RELATIVE_TOOL::PositionRelative(), EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), EDIT_TOOL::Rotate(), and POSITION_RELATIVE_TOOL::SelectPositionRelativeItem().

◆ mirrorPadX()

static void mirrorPadX ( D_PAD aPad,
const wxPoint aMirrorPoint 
)
static

Mirror a pad in the vertical axis passing through a point (mirror left to right)

Definition at line 791 of file edit_tool.cpp.

792 {
793  if( aPad.GetShape() == PAD_SHAPE_CUSTOM )
794  aPad.FlipPrimitives( true ); // mirror primitives left to right
795 
796  wxPoint tmpPt = mirrorPointX( aPad.GetPosition(), aMirrorPoint );
797  aPad.SetPosition( tmpPt );
798 
799  aPad.SetX0( aPad.GetPosition().x );
800 
801  tmpPt = aPad.GetOffset();
802  tmpPt.x = -tmpPt.x;
803  aPad.SetOffset( tmpPt );
804 
805  auto tmpz = aPad.GetDelta();
806  tmpz.x = -tmpz.x;
807  aPad.SetDelta( tmpz );
808 
809  aPad.SetOrientation( -aPad.GetOrientation() );
810 }
wxPoint GetPosition() const override
Definition: class_pad.h:165
void FlipPrimitives(bool aFlipLeftRight)
Flip (mirror) the primitives left to right or top to bottom, around the anchor position in custom pad...
Definition: class_pad.cpp:553
void SetPosition(const wxPoint &aPos) override
Definition: class_pad.h:159
const wxPoint & GetOffset() const
Definition: class_pad.h:233
const wxSize & GetDelta() const
Definition: class_pad.h:227
double GetOrientation() const
Function GetOrientation returns the rotation angle of the pad in tenths of degrees,...
Definition: class_pad.h:325
static wxPoint mirrorPointX(const wxPoint &aPoint, const wxPoint &aMirrorPoint)
Definition: edit_tool.cpp:776
void SetOrientation(double aAngle)
Function SetOrientation sets the rotation angle of the pad.
Definition: class_pad.cpp:485
void SetX0(int x)
Definition: class_pad.h:221
PAD_SHAPE_T GetShape() const
Definition: class_pad.h:157
void SetOffset(const wxPoint &aOffset)
Definition: class_pad.h:232
void SetDelta(const wxSize &aSize)
Definition: class_pad.h:226

References D_PAD::FlipPrimitives(), D_PAD::GetDelta(), D_PAD::GetOffset(), D_PAD::GetOrientation(), D_PAD::GetPosition(), D_PAD::GetShape(), mirrorPointX(), PAD_SHAPE_CUSTOM, D_PAD::SetDelta(), D_PAD::SetOffset(), D_PAD::SetOrientation(), D_PAD::SetPosition(), D_PAD::SetX0(), and wxPoint::x.

Referenced by EDIT_TOOL::Mirror().

◆ mirrorPointX()

static wxPoint mirrorPointX ( const wxPoint aPoint,
const wxPoint aMirrorPoint 
)
static

Mirror a point about the vertical axis passing through another point

Definition at line 776 of file edit_tool.cpp.

777 {
778  wxPoint mirrored = aPoint;
779 
780  mirrored.x -= aMirrorPoint.x;
781  mirrored.x = -mirrored.x;
782  mirrored.x += aMirrorPoint.x;
783 
784  return mirrored;
785 }

References wxPoint::x.

Referenced by mirrorPadX().