KiCad PCB EDA Suite
EDIT_TOOL Class Reference

The interactive edit tool. More...

#include <edit_tool.h>

Inheritance diagram for EDIT_TOOL:
PCB_TOOL_BASE TOOL_INTERACTIVE TOOL_BASE

Public Types

enum  RESET_REASON { RUN, MODEL_RELOAD, GAL_SWITCH }
 Determine the reason of reset for a tool. More...
 

Public Member Functions

 EDIT_TOOL ()
 
void Reset (RESET_REASON aReason) override
 Bring the tool to a known, initial state. More...
 
bool Init () override
 Init() is called once upon a registration of the tool. More...
 
int GetAndPlace (const TOOL_EVENT &aEvent)
 
int Move (const TOOL_EVENT &aEvent)
 Main loop in which events are handled. More...
 
int Drag (const TOOL_EVENT &aEvent)
 Invoke the PNS router to drag tracks or do an offline resizing of an arc track if a single arc track is selected. More...
 
int DragArcTrack (const TOOL_EVENT &aTrack)
 Drag-resize an arc (and change end points of connected straight segments). More...
 
int Properties (const TOOL_EVENT &aEvent)
 Display properties window for the selected object. More...
 
int Rotate (const TOOL_EVENT &aEvent)
 Rotate currently selected items. More...
 
int Flip (const TOOL_EVENT &aEvent)
 Rotate currently selected items. More...
 
int Mirror (const TOOL_EVENT &aEvent)
 Mirror the current selection. More...
 
int ChangeTrackWidth (const TOOL_EVENT &aEvent)
 
int FilletTracks (const TOOL_EVENT &aEvent)
 Fillet (i.e. More...
 
int Remove (const TOOL_EVENT &aEvent)
 Delete currently selected items. More...
 
int Duplicate (const TOOL_EVENT &aEvent)
 Duplicate the current selection and starts a move action. More...
 
int MoveExact (const TOOL_EVENT &aEvent)
 Invoke a dialog box to allow moving of the item by an exact amount. More...
 
int MoveWithReference (const TOOL_EVENT &aEvent)
 Move an item but with a reference point selected first. More...
 
int CreateArray (const TOOL_EVENT &aEvent)
 Create an array of the selected items, invoking the array editor dialog to set the options. More...
 
BOARD_COMMITGetCurrentCommit () const
 
void SetIsFootprintEditor (bool aEnabled)
 Function SetIsFootprintEditor() More...
 
bool IsFootprintEditor () const
 
virtual bool Is45Limited () const
 Should the tool use its 45° mode option? More...
 
void Activate ()
 Run the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Assign a context menu and tells when it should be activated. More...
 
void RunMainStack (std::function< void()> aFunc)
 Call a function using the main stack. More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Define which state (aStateFunc) to go when a certain event arrives (aConditions). More...
 
TOOL_EVENTWait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Suspend execution of the tool until an event specified in aEventList arrives. More...
 
TOOL_TYPE GetType () const
 Return the type of the tool. More...
 
TOOL_ID GetId () const
 Return the unique identifier of the tool. More...
 
const std::string & GetName () const
 Return the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Return the instance of TOOL_MANAGER that takes care of the tool. More...
 
bool IsToolActive () const
 

Static Public Member Functions

static void FootprintFilter (const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
 A selection filter which prunes the selection to contain only items of type #PCB_MODULE_T. More...
 
static void PadFilter (const VECTOR2I &, GENERAL_COLLECTOR &aCollector, PCB_SELECTION_TOOL *sTool)
 A selection filter which prunes the selection to contain only items of type PCB_PAD_T. More...
 

Protected Types

enum  INTERACTIVE_PLACEMENT_OPTIONS { IPO_ROTATE = 0x01, IPO_FLIP = 0x02, IPO_SINGLE_CLICK = 0x04, IPO_REPEAT = 0x08 }
 Options for placing items interactively. More...
 

Protected Member Functions

void doInteractiveItemPlacement (const std::string &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
 Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc. More...
 
KIGFX::PCB_VIEWview () const
 
KIGFX::VIEW_CONTROLScontrols () const
 
PCB_BASE_EDIT_FRAMEframe () const
 
BOARDboard () const
 
FOOTPRINTfootprint () const
 
const PCB_DISPLAY_OPTIONSdisplayOptions () const
 
PCB_DRAW_PANEL_GALcanvas () const
 
const PCB_SELECTIONselection () const
 
PCB_SELECTIONselection ()
 
void attachManager (TOOL_MANAGER *aManager)
 Set the TOOL_MANAGER the tool will belong to. More...
 
KIGFX::VIEWgetView () const
 Returns the instance of #VIEW object used in the application. More...
 
KIGFX::VIEW_CONTROLSgetViewControls () const
 Return the instance of VIEW_CONTROLS object used in the application. More...
 
template<typename T >
T * getEditFrame () const
 Return the application window object, casted to requested user type. More...
 
template<typename T >
T * getModel () const
 Return the model object if it matches the requested type. More...
 

Protected Attributes

bool m_isFootprintEditor
 
TOOL_MENU m_menu
 The functions below are not yet implemented - their interface may change. More...
 
TOOL_TYPE m_type
 Unique identifier for the tool, assigned by a TOOL_MANAGER instance. More...
 
TOOL_ID m_toolId
 Name of the tool. More...
 
std::string m_toolName
 
TOOL_MANAGERm_toolMgr
 

Private Member Functions

void setTransitions () override
 < Set up handlers for various events. More...
 
int copyToClipboard (const TOOL_EVENT &aEvent)
 Send the current selection to the clipboard by formatting it as a fake pcb see #AppendBoardFromClipboard for importing. More...
 
int cutToClipboard (const TOOL_EVENT &aEvent)
 Cut the current selection to the clipboard by formatting it as a fake pcb see #AppendBoardFromClipboard for importing. More...
 
bool updateModificationPoint (PCB_SELECTION &aSelection)
 
bool invokeInlineRouter (int aDragMode)
 
bool isRouterActive () const
 
int doMoveSelection (TOOL_EVENT aEvent, bool aPickReference=false)
 
bool pickReferencePoint (const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
 

Private Attributes

PCB_SELECTION_TOOLm_selectionTool
 
std::unique_ptr< BOARD_COMMITm_commit
 
bool m_dragging
 
VECTOR2I m_cursor
 
std::unique_ptr< STATUS_TEXT_POPUPm_statusPopup
 

Detailed Description

The interactive edit tool.

Allows one to move, rotate, flip and change properties of items selected using the pcbnew.InteractiveSelection tool.

Definition at line 64 of file edit_tool.h.

Member Enumeration Documentation

◆ INTERACTIVE_PLACEMENT_OPTIONS

Options for placing items interactively.

Enumerator
IPO_ROTATE 

Handle the rotate action in the loop by calling the item's rotate method.

IPO_FLIP 

Handle flip action in the loop by calling the item's flip method.

IPO_SINGLE_CLICK 

Create an item immediately on placement starting, otherwise show the pencil cursor until the item is created.

IPO_REPEAT 

Allow repeat placement of the item.

Definition at line 116 of file pcb_tool_base.h.

116  {
118  IPO_ROTATE = 0x01,
119 
121  IPO_FLIP = 0x02,
122 
125  IPO_SINGLE_CLICK = 0x04,
126 
128  IPO_REPEAT = 0x08
129  };
Handle flip action in the loop by calling the item's flip method.
Allow repeat placement of the item.
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
Handle the rotate action in the loop by calling the item's rotate method.

◆ RESET_REASON

enum TOOL_BASE::RESET_REASON
inherited

Determine the reason of reset for a tool.

Enumerator
RUN 

Tool is invoked after being inactive.

MODEL_RELOAD 

Model changes (required full reload)

GAL_SWITCH 

Rendering engine changes.

Definition at line 77 of file tool_base.h.

78  {
79  RUN,
80  MODEL_RELOAD,
81  GAL_SWITCH
82  };
Model changes (required full reload)
Definition: tool_base.h:80
Tool is invoked after being inactive.
Definition: tool_base.h:79
Rendering engine changes.
Definition: tool_base.h:81

Constructor & Destructor Documentation

◆ EDIT_TOOL()

EDIT_TOOL::EDIT_TOOL ( )

Definition at line 68 of file edit_tool.cpp.

68  :
69  PCB_TOOL_BASE( "pcbnew.InteractiveEdit" ),
70  m_selectionTool( nullptr ),
71  m_dragging( false )
72 {
73 }
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
bool m_dragging
Definition: edit_tool.h:191
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool_base.h:77

Member Function Documentation

◆ Activate()

void TOOL_INTERACTIVE::Activate ( )
inherited

Run the tool.

After activation, the tool starts receiving events until it is finished.

Definition at line 51 of file tool_interactive.cpp.

52 {
54 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209
bool InvokeTool(TOOL_ID aToolId)
Call a tool by sending a tool activation event to tool of given ID.

References TOOL_MANAGER::InvokeTool(), TOOL_BASE::m_toolId, and TOOL_BASE::m_toolMgr.

Referenced by AUTOPLACE_TOOL::autoplace(), copyToClipboard(), SYMBOL_EDITOR_EDIT_TOOL::DeleteItemCursor(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), doMoveSelection(), DragArcTrack(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::DrawRectangle(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), BOARD_EDITOR_CONTROL::DrillOrigin(), PAD_TOOL::EnumeratePads(), PCB_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), DRAWING_TOOL::InteractivePlaceWithPreview(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), PCB_PICKER_TOOL::Main(), PL_EDIT_TOOL::Main(), EE_POINT_EDITOR::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), LIB_TREE::onContextMenu(), PCB_POINT_EDITOR::OnSelectionChange(), GROUP_TOOL::PickNewMember(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), DRC_TOOL::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ attachManager()

void TOOL_BASE::attachManager ( TOOL_MANAGER aManager)
protectedinherited

Set the TOOL_MANAGER the tool will belong to.

Called by TOOL_MANAGER::RegisterTool()

Definition at line 60 of file tool_base.cpp.

61 {
62  m_toolMgr = aManager;
63 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214

References TOOL_BASE::m_toolMgr.

Referenced by TOOL_MANAGER::RegisterTool().

◆ board()

BOARD* PCB_TOOL_BASE::board ( ) const
inlineprotectedinherited

Definition at line 165 of file pcb_tool_base.h.

165 { return getModel<BOARD>(); }

Referenced by PCB_CONTROL::AppendBoard(), AUTOPLACE_TOOL::autoplace(), BOARD_INSPECTION_TOOL::calculateSelectionRatsnest(), ChangeTrackWidth(), ZONE_FILLER_TOOL::CheckAllZones(), BOARD_INSPECTION_TOOL::ClearHighlight(), copyToClipboard(), FOOTPRINT_EDITOR_CONTROL::CreateFootprint(), MICROWAVE_TOOL::createInductorBetween(), ROUTER_TOOL::CustomTrackWidthDialog(), PCB_CONTROL::DeleteItemCursor(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportNetlist(), ZONE_FILLER_TOOL::FillAllZones(), FilletTracks(), PCB_SELECTION_TOOL::filterSelection(), PCB_TOOL_BASE::footprint(), PCB_SELECTION_TOOL::GetBoard(), PCB_SELECTION_TOOL::getCollectorsGuide(), GROUP_TOOL::Group(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::highlightNet(), ROUTER_TOOL::InlineDrag(), DRAWING_TOOL::InteractivePlaceWithPreview(), PCB_CONTROL::LayerNext(), PCB_CONTROL::LayerPrev(), BOARD_INSPECTION_TOOL::LocalRatsnestTool(), MoveExact(), FOOTPRINT_EDITOR_CONTROL::NewFootprint(), PCB_CONTROL::Paste(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PAD_TOOL::PlacePad(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), PCB_SELECTION_TOOL::RebuildSelection(), PAD_TOOL::recombinePad(), BOARD_EDITOR_CONTROL::RepairBoard(), FOOTPRINT_EDITOR_CONTROL::RepairFootprint(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), PCB_SELECTION_TOOL::Selectable(), PCB_SELECTION_TOOL::selectAllItemsOnNet(), PCB_SELECTION_TOOL::selectAllItemsOnSheet(), PCB_SELECTION_TOOL::selectConnectedTracks(), PCB_SELECTION_TOOL::selectionContains(), PCB_SELECTION_TOOL::selectPoint(), PCB_CONTROL::TrackDisplayMode(), PCB_CONTROL::unfilledZoneCheck(), GROUP_TOOL::Ungroup(), ROUTER_TOOL::UpdateMessagePanel(), PCB_CONTROL::ViaDisplayMode(), PCB_CONTROL::ZoneDisplayMode(), ZONE_FILLER_TOOL::ZoneFill(), BOARD_EDITOR_CONTROL::ZoneMerge(), and ZONE_FILLER_TOOL::ZoneUnfillAll().

◆ canvas()

◆ ChangeTrackWidth()

int EDIT_TOOL::ChangeTrackWidth ( const TOOL_EVENT aEvent)

Definition at line 1095 of file edit_tool.cpp.

1096 {
1098  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1099  {
1100  // Iterate from the back so we don't have to worry about removals.
1101  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1102  {
1103  BOARD_ITEM* item = aCollector[ i ];
1104 
1105  if( !dynamic_cast<PCB_TRACK*>( item ) )
1106  aCollector.Remove( item );
1107  }
1108  },
1109  true /* prompt user regarding locked items */ );
1110 
1111  for( EDA_ITEM* item : selection )
1112  {
1113  if( item->Type() == PCB_VIA_T )
1114  {
1115  PCB_VIA* via = static_cast<PCB_VIA*>( item );
1116 
1117  m_commit->Modify( via );
1118 
1119  int new_width;
1120  int new_drill;
1121 
1122  if( via->GetViaType() == VIATYPE::MICROVIA )
1123  {
1124  NETCLASS* netClass = via->GetNetClass();
1125 
1126  new_width = netClass->GetuViaDiameter();
1127  new_drill = netClass->GetuViaDrill();
1128  }
1129  else
1130  {
1131  new_width = board()->GetDesignSettings().GetCurrentViaSize();
1132  new_drill = board()->GetDesignSettings().GetCurrentViaDrill();
1133  }
1134 
1135  via->SetDrill( new_drill );
1136  via->SetWidth( new_width );
1137  }
1138  else if( item->Type() == PCB_TRACE_T || item->Type() == PCB_ARC_T )
1139  {
1140  PCB_TRACK* track = dynamic_cast<PCB_TRACK*>( item );
1141 
1142  wxCHECK( track, 0 );
1143 
1144  m_commit->Modify( track );
1145 
1146  int new_width = board()->GetDesignSettings().GetCurrentTrackWidth();
1147  track->SetWidth( new_width );
1148  }
1149  }
1150 
1151  m_commit->Push( _("Edit track width/via size") );
1152 
1153  if( selection.IsHover() )
1154  {
1156 
1157  // Notify other tools of the changes -- This updates the visual ratsnest
1159  }
1160 
1161  return 0;
1162 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
bool IsHover() const
Definition: selection.h:74
BOARD * board() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:590
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
const PCB_SELECTION & selection() const
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
A collection of nets and the parameters used to route or test these nets.
Definition: netclass.h:46
#define _(s)
int GetuViaDiameter() const
Definition: netclass.h:140
void SetWidth(int aWidth)
Definition: pcb_track.h:101
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
int GetuViaDrill() const
Definition: netclass.h:144
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, PCB_TOOL_BASE::board(), COLLECTOR::GetCount(), BOARD_DESIGN_SETTINGS::GetCurrentTrackWidth(), BOARD_DESIGN_SETTINGS::GetCurrentViaDrill(), BOARD_DESIGN_SETTINGS::GetCurrentViaSize(), BOARD::GetDesignSettings(), NETCLASS::GetuViaDiameter(), NETCLASS::GetuViaDrill(), SELECTION::IsHover(), m_commit, m_selectionTool, TOOL_BASE::m_toolMgr, MICROVIA, PCB_ARC_T, PCB_TRACE_T, PCB_VIA_T, TOOL_MANAGER::ProcessEvent(), COLLECTOR::Remove(), PCB_SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_TRACK::SetWidth(), and via.

Referenced by setTransitions().

◆ controls()

◆ copyToClipboard()

int EDIT_TOOL::copyToClipboard ( const TOOL_EVENT aEvent)
private

Send the current selection to the clipboard by formatting it as a fake pcb see #AppendBoardFromClipboard for importing.

Definition at line 2377 of file edit_tool.cpp.

2378 {
2379  std::string tool = "pcbnew.InteractiveEdit.selectReferencePoint";
2380  CLIPBOARD_IO io;
2382  getEditFrame<PCB_BASE_EDIT_FRAME>()->GetMagneticItemsSettings() );
2383 
2384  frame()->PushTool( tool );
2385  Activate();
2386 
2388  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2389  {
2390  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
2391  {
2392  BOARD_ITEM* item = aCollector[i];
2393 
2394  // We can't copy both a footprint and its text in the same operation, so if
2395  // both are selected, remove the text
2396  if( item->Type() == PCB_FP_TEXT_T && aCollector.HasItem( item->GetParent() ) )
2397  aCollector.Remove( item );
2398  }
2399  },
2400 
2401  // Prompt user regarding locked items.
2402  aEvent.IsAction( &ACTIONS::cut ) && !m_isFootprintEditor );
2403 
2404  if( !selection.Empty() )
2405  {
2406  std::vector<BOARD_ITEM*> items;
2407 
2408  for( EDA_ITEM* item : selection )
2409  items.push_back( static_cast<BOARD_ITEM*>( item ) );
2410 
2411  VECTOR2I refPoint;
2412 
2413  if( aEvent.IsAction( &PCB_ACTIONS::copyWithReference ) )
2414  {
2415  if( !pickReferencePoint( _( "Select reference point for the copy..." ),
2416  _( "Selection copied" ),
2417  _( "Copy canceled" ),
2418  refPoint ) )
2419  {
2420  frame()->PopTool( tool );
2421  return 0;
2422  }
2423  }
2424  else
2425  {
2426  refPoint = grid.BestDragOrigin( getViewControls()->GetCursorPosition(), items );
2427  }
2428 
2429  selection.SetReferencePoint( refPoint );
2430 
2431  io.SetBoard( board() );
2433  frame()->SetStatusText( _( "Selection copied" ) );
2434  }
2435 
2436  frame()->PopTool( tool );
2437 
2438  return 0;
2439 }
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
BOARD * board() const
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
void SetBoard(BOARD *aBoard)
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
bool pickReferencePoint(const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
Definition: edit_tool.cpp:2296
PCB_BASE_EDIT_FRAME * frame() const
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:192
const PCB_SELECTION & selection() const
virtual void PopTool(const std::string &actionName)
static TOOL_ACTION cut
Definition: actions.h:66
bool HasItem(const EDA_ITEM *aItem) const
Tests if aItem has already been collected.
Definition: collector.h:196
#define _(s)
static TOOL_ACTION copyWithReference
copy command with manual reference point selection
Definition: pcb_actions.h:98
bool m_isFootprintEditor
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
void Activate()
Run the tool.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
void SaveSelection(const PCB_SELECTION &selected, bool isFootprintEditor)
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:136
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, TOOL_INTERACTIVE::Activate(), PCB_TOOL_BASE::board(), PCB_ACTIONS::copyWithReference, ACTIONS::cut, SELECTION::Empty(), PCB_TOOL_BASE::frame(), COLLECTOR::GetCount(), BOARD_ITEM::GetParent(), TOOL_BASE::getViewControls(), grid, COLLECTOR::HasItem(), TOOL_EVENT::IsAction(), PCB_TOOL_BASE::m_isFootprintEditor, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_FP_TEXT_T, pickReferencePoint(), TOOLS_HOLDER::PopTool(), TOOLS_HOLDER::PushTool(), COLLECTOR::Remove(), PCB_SELECTION_TOOL::RequestSelection(), CLIPBOARD_IO::SaveSelection(), PCB_TOOL_BASE::selection(), CLIPBOARD_IO::SetBoard(), SELECTION::SetReferencePoint(), and EDA_ITEM::Type().

Referenced by cutToClipboard(), and setTransitions().

◆ CreateArray()

int EDIT_TOOL::CreateArray ( const TOOL_EVENT aEvent)

Create an array of the selected items, invoking the array editor dialog to set the options.

Definition at line 2215 of file edit_tool.cpp.

2216 {
2217  if( isRouterActive() )
2218  {
2219  wxBell();
2220  return 0;
2221  }
2222 
2223  // Be sure that there is at least one item that we can modify
2225  []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2226  {
2227  sTool->FilterCollectorForMarkers( aCollector );
2228  sTool->FilterCollectorForHierarchy( aCollector, true );
2229  } );
2230 
2231  if( selection.Empty() )
2232  return 0;
2233 
2234  // we have a selection to work on now, so start the tool process
2235  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
2236  ARRAY_CREATOR array_creator( *editFrame, m_isFootprintEditor, selection, m_toolMgr );
2237  array_creator.Invoke();
2238 
2239  return 0;
2240 }
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
const PCB_SELECTION & selection() const
bool m_isFootprintEditor
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
bool isRouterActive() const
Definition: edit_tool.cpp:266
The selection tool: currently supports:
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.

References SELECTION::Empty(), PCB_SELECTION_TOOL::FilterCollectorForHierarchy(), PCB_SELECTION_TOOL::FilterCollectorForMarkers(), ARRAY_CREATOR::Invoke(), isRouterActive(), PCB_TOOL_BASE::m_isFootprintEditor, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_SELECTION_TOOL::RequestSelection(), and PCB_TOOL_BASE::selection().

Referenced by setTransitions().

◆ cutToClipboard()

int EDIT_TOOL::cutToClipboard ( const TOOL_EVENT aEvent)
private

Cut the current selection to the clipboard by formatting it as a fake pcb see #AppendBoardFromClipboard for importing.

Return the right modification point (e.g. for rotation), depending on the number of selected items.

Definition at line 2442 of file edit_tool.cpp.

2443 {
2444  if( !copyToClipboard( aEvent ) )
2445  {
2446  // N.B. Setting the CUT flag prevents lock filtering as we only want to delete the items
2447  // that were copied to the clipboard, no more, no fewer. Filtering for locked item, if
2448  // any will be done in the copyToClipboard() routine
2449  TOOL_EVENT evt( aEvent.Category(), aEvent.Action(), TOOL_ACTION_SCOPE::AS_GLOBAL );
2451  Remove( evt );
2452  }
2453 
2454  return 0;
2455 }
TOOL_ACTIONS Action() const
These give a tool a method of informing the TOOL_MANAGER that a particular event should be passed on ...
Definition: tool_event.h:230
TOOL_EVENT_CATEGORY Category() const
Returns more specific information about the type of an event.
Definition: tool_event.h:227
void SetParameter(T aParam)
Set a non-standard parameter assigned to the event.
Definition: tool_event.h:450
Generic, UI-independent tool event.
Definition: tool_event.h:152
int Remove(const TOOL_EVENT &aEvent)
Delete currently selected items.
Definition: edit_tool.cpp:1751
Global action (toolbar/main menu event, global shortcut)
int copyToClipboard(const TOOL_EVENT &aEvent)
Send the current selection to the clipboard by formatting it as a fake pcb see #AppendBoardFromClipbo...
Definition: edit_tool.cpp:2377

References TOOL_EVENT::Action(), AS_GLOBAL, TOOL_EVENT::Category(), copyToClipboard(), ACTIONS::CUT, Remove(), and TOOL_EVENT::SetParameter().

Referenced by setTransitions().

◆ displayOptions()

const PCB_DISPLAY_OPTIONS & PCB_TOOL_BASE::displayOptions ( ) const
protectedinherited

◆ doInteractiveItemPlacement()

void PCB_TOOL_BASE::doInteractiveItemPlacement ( const std::string &  aTool,
INTERACTIVE_PLACER_BASE aPlacer,
const wxString &  aCommitMessage,
int  aOptions = IPO_ROTATE | IPO_FLIP | IPO_REPEAT 
)
protectedinherited

Helper function for performing a common interactive idiom: wait for a left click, place an item there (perhaps with a dialog or other user interaction), then have it move with the mouse and respond to rotate/flip, etc.

More complex interactive processes are not supported here, you should implement a customised event loop for those.

Parameters
aItemCreatorthe callable that will attempt to create the item
aCommitMessagethe message used on a successful commit

Definition at line 37 of file pcb_tool_base.cpp.

40 {
41  using namespace std::placeholders;
42  std::unique_ptr<BOARD_ITEM> newItem;
43 
44  frame()->PushTool( aTool );
45 
46  BOARD_COMMIT commit( frame() );
47 
49 
50  Activate();
51  // Must be done after Activate() so that it gets set into the correct context
52  controls()->ShowCursor( true );
53  // do not capture or auto-pan until we start placing an item
54 
55  PCB_GRID_HELPER grid( m_toolMgr, frame()->GetMagneticItemsSettings() );
56 
57  // Add a VIEW_GROUP that serves as a preview for the new item
58  PCB_SELECTION preview;
59  view()->Add( &preview );
60 
61  aPlacer->m_board = board();
62  aPlacer->m_frame = frame();
63  aPlacer->m_modifiers = 0;
64 
65  auto makeNewItem =
66  [&]( VECTOR2I aPosition )
67  {
68  if( frame()->GetModel() )
69  newItem = aPlacer->CreateItem();
70 
71  if( newItem )
72  {
73  newItem->SetPosition( (wxPoint) aPosition );
74  preview.Add( newItem.get() );
75 
76  if( newItem->Type() == PCB_FOOTPRINT_T )
77  {
78  FOOTPRINT* fp = dyn_cast<FOOTPRINT*>( newItem.get() );
79 
80  // footprints have more drawable parts
81  fp->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
82  }
83  }
84  };
85 
86  if( aOptions & IPO_SINGLE_CLICK )
87  makeNewItem( controls()->GetCursorPosition() );
88 
89  auto setCursor =
90  [&]()
91  {
92  if( !newItem )
94  else
96  };
97 
98  // Set initial cursor
99  setCursor();
100 
101  // Main loop: keep receiving events
102  while( TOOL_EVENT* evt = Wait() )
103  {
104  setCursor();
105 
106  grid.SetSnap( false ); // Interactive placement tools need to set their own item snaps
107  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
108  VECTOR2I cursorPos = grid.BestSnapAnchor( controls()->GetMousePosition(), nullptr );
109 
110  aPlacer->m_modifiers = evt->Modifier();
111 
112  auto cleanup =
113  [&] ()
114  {
115  newItem = nullptr;
116  preview.Clear();
117  view()->Update( &preview );
118  controls()->SetAutoPan( false );
119  controls()->CaptureCursor( false );
120  controls()->ShowCursor( true );
121  };
122 
123  if( evt->IsCancelInteractive() )
124  {
125  if( aOptions & IPO_SINGLE_CLICK )
126  {
127  cleanup();
128  frame()->PopTool( aTool );
129  break;
130  }
131  else if( newItem )
132  {
133  cleanup();
134  }
135  else
136  {
137  frame()->PopTool( aTool );
138  break;
139  }
140  }
141  else if( evt->IsActivate() )
142  {
143  if( newItem )
144  cleanup();
145 
146  if( evt->IsPointEditor() )
147  {
148  // don't exit (the point editor runs in the background)
149  }
150  else if( evt->IsMoveTool() )
151  {
152  // leave ourselves on the stack so we come back after the move
153  break;
154  }
155  else
156  {
157  frame()->PopTool( aTool );
158  break;
159  }
160  }
161  else if( evt->IsClick( BUT_LEFT ) || evt->IsDblClick( BUT_LEFT ) )
162  {
163  if( !newItem )
164  {
165  // create the item if possible
166  makeNewItem( cursorPos );
167 
168  // no item created, so wait for another click
169  if( !newItem )
170  continue;
171 
172  controls()->CaptureCursor( true );
173  controls()->SetAutoPan( true );
174  }
175  else
176  {
177  auto oldFlags = newItem->GetFlags();
178  newItem->ClearFlags();
179 
180  if( !aPlacer->PlaceItem( newItem.get(), commit ) )
181  {
182  newItem->SetFlags( oldFlags );
183  continue;
184  }
185 
186  preview.Clear();
187  newItem.release();
188  commit.Push( aCommitMessage );
189 
190  controls()->CaptureCursor( false );
191  controls()->SetAutoPan( false );
192  controls()->ShowCursor( true );
193 
194  if( !( aOptions & IPO_REPEAT ) )
195  break;
196 
197  if( aOptions & IPO_SINGLE_CLICK )
198  makeNewItem( controls()->GetCursorPosition() );
199 
200  setCursor();
201  }
202  }
203  else if( evt->IsClick( BUT_RIGHT ) )
204  {
206  }
207  else if( evt->IsAction( &PCB_ACTIONS::trackViaSizeChanged ) )
208  {
210  }
211  else if( newItem && evt->Category() == TC_COMMAND )
212  {
213  /*
214  * Handle any events that can affect the item as we move it around
215  */
216  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) && ( aOptions & IPO_ROTATE ) )
217  {
218  const int rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *frame(), *evt );
219  newItem->Rotate( newItem->GetPosition(), rotationAngle );
220  view()->Update( &preview );
221  }
222  else if( evt->IsAction( &PCB_ACTIONS::flip ) && ( aOptions & IPO_FLIP ) )
223  {
224  newItem->Flip( newItem->GetPosition(), frame()->Settings().m_FlipLeftRight );
225  view()->Update( &preview );
226  }
227  else if( evt->IsAction( &PCB_ACTIONS::properties ) )
228  {
229  frame()->OnEditItemRequest( newItem.get() );
230 
231  // Notify other tools of the changes
233  }
234  else if( evt->IsAction( &ACTIONS::refreshPreview ) )
235  {
236  preview.Clear();
237  newItem.release();
238 
239  makeNewItem( (wxPoint) cursorPos );
240  aPlacer->SnapItem( newItem.get() );
241  view()->Update( &preview );
242  }
243  else
244  {
245  evt->SetPassEvent();
246  }
247  }
248  else if( newItem && evt->IsMotion() )
249  {
250  // track the cursor
251  newItem->SetPosition( (wxPoint) cursorPos );
252  aPlacer->SnapItem( newItem.get() );
253 
254  // Show a preview of the item
255  view()->Update( &preview );
256  }
257  else
258  {
259  evt->SetPassEvent();
260  }
261  }
262 
263  view()->Remove( &preview );
265  controls()->SetAutoPan( false );
266  controls()->CaptureCursor( false );
267 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
TOOL_MENU m_menu
The functions below are not yet implemented - their interface may change.
virtual void Clear() override
Remove all the stored items from the group.
Definition: selection.h:83
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual bool PlaceItem(BOARD_ITEM *aItem, BOARD_COMMIT &aCommit)
Handle flip action in the loop by calling the item's flip method.
BOARD * board() const
virtual void Add(EDA_ITEM *aItem)
Definition: selection.cpp:32
virtual std::unique_ptr< BOARD_ITEM > CreateItem()=0
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION trackViaSizeChanged
Definition: pcb_actions.h:299
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition: tool_base.h:143
PCB_BASE_EDIT_FRAME * frame() const
virtual void SnapItem(BOARD_ITEM *aItem)
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:92
const PCB_SELECTION & selection() const
Allow repeat placement of the item.
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
virtual void PopTool(const std::string &actionName)
virtual void CaptureCursor(bool aEnabled)
Force the cursor to stay within the drawing panel area.
Generic, UI-independent tool event.
Definition: tool_event.h:152
KIGFX::PCB_VIEW * view() const
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
virtual void Add(VIEW_ITEM *aItem)
Add an item to the group.
Definition: view_group.cpp:57
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
virtual BOARD_ITEM_CONTAINER * GetModel() const =0
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
Handle the rotate action in the loop by calling the item's rotate method.
KIGFX::VIEW_CONTROLS * controls() const
PCBNEW_SETTINGS & Settings()
void Activate()
Run the tool.
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all BOARD_ITEMs that belong to the footprint (pads, drawings,...
Definition: footprint.cpp:1299
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
PCB_BASE_EDIT_FRAME * m_frame
Definition: pcb_tool_base.h:64
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void ShowContextMenu(SELECTION &aSelection)
Helper function to set and immediately show a CONDITIONAL_MENU in concert with the given SELECTION.
Definition: tool_menu.cpp:59
static TOOL_ACTION refreshPreview
Definition: actions.h:106

References TOOL_INTERACTIVE::Activate(), KIGFX::PCB_VIEW::Add(), KIGFX::VIEW_GROUP::Add(), SELECTION::Add(), ARROW, PCB_TOOL_BASE::board(), BUT_LEFT, BUT_RIGHT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), PCB_TOOL_BASE::controls(), INTERACTIVE_PLACER_BASE::CreateItem(), PCB_ACTIONS::flip, PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), PCB_BASE_FRAME::GetModel(), TOOL_BASE::getView(), grid, PCB_TOOL_BASE::IPO_FLIP, PCB_TOOL_BASE::IPO_REPEAT, PCB_TOOL_BASE::IPO_ROTATE, PCB_TOOL_BASE::IPO_SINGLE_CLICK, TOOL_EVT_UTILS::IsRotateToolEvt(), INTERACTIVE_PLACER_BASE::m_board, PCBNEW_SETTINGS::m_FlipLeftRight, INTERACTIVE_PLACER_BASE::m_frame, TOOL_INTERACTIVE::m_menu, INTERACTIVE_PLACER_BASE::m_modifiers, TOOL_BASE::m_toolMgr, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), PCB_FOOTPRINT_T, PENCIL, PLACE, INTERACTIVE_PLACER_BASE::PlaceItem(), TOOLS_HOLDER::PopTool(), TOOL_MANAGER::ProcessEvent(), PCB_ACTIONS::properties, BOARD_COMMIT::Push(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, KIGFX::PCB_VIEW::Remove(), TOOL_MANAGER::RunAction(), FOOTPRINT::RunOnChildren(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), PCB_BASE_FRAME::Settings(), TOOL_MENU::ShowContextMenu(), KIGFX::VIEW_CONTROLS::ShowCursor(), INTERACTIVE_PLACER_BASE::SnapItem(), TC_COMMAND, PCB_ACTIONS::trackViaSizeChanged, KIGFX::PCB_VIEW::Update(), PCB_TOOL_BASE::view(), and TOOL_INTERACTIVE::Wait().

Referenced by MICROWAVE_TOOL::addMicrowaveFootprint(), DRAWING_TOOL::DrawVia(), and PAD_TOOL::PlacePad().

◆ doMoveSelection()

int EDIT_TOOL::doMoveSelection ( TOOL_EVENT  aEvent,
bool  aPickReference = false 
)
private

Definition at line 706 of file edit_tool.cpp.

707 {
708  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
710  VECTOR2I originalCursorPos = controls->GetCursorPosition();
711 
712  // Be sure that there is at least one item that we can modify. If nothing was selected before,
713  // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
715  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
716  {
717  sTool->FilterCollectorForMarkers( aCollector );
718  sTool->FilterCollectorForHierarchy( aCollector, true );
719  },
720  // Prompt user regarding locked items if in board editor and in free-pad-mode (if
721  // we're not in free-pad mode we delay this until the second RequestSelection()).
723 
724  if( m_dragging || selection.Empty() )
725  return 0;
726 
727  LSET item_layers = selection.GetSelectionLayers();
728  bool is_hover = selection.IsHover(); // N.B. This must be saved before the second call
729  // to RequestSelection() below
730  VECTOR2I pickedReferencePoint;
731 
732  // Now filter out pads if not in free pads mode. We cannot do this in the first
733  // RequestSelection() as we need the item_layers when a pad is the selection front.
734  if( !m_isFootprintEditor && !frame()->Settings().m_AllowFreePads )
735  {
737  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
738  {
739  sTool->FilterCollectorForMarkers( aCollector );
740  sTool->FilterCollectorForHierarchy( aCollector, true );
741  sTool->FilterCollectorForFreePads( aCollector );
742  },
743  true /* prompt user regarding locked items */ );
744  }
745 
746  if( selection.Empty() )
747  return 0;
748 
749  std::string tool = aEvent.GetCommandStr().get();
750  editFrame->PushTool( tool );
751 
752  Activate();
753  // Must be done after Activate() so that it gets set into the correct context
754  controls->ShowCursor( true );
755  controls->SetAutoPan( true );
756 
757  if( aPickReference && !pickReferencePoint( _( "Select reference point for move..." ), "", "",
758  pickedReferencePoint ) )
759  {
760  if( is_hover )
762 
763  editFrame->PopTool( tool );
764  return 0;
765  }
766 
767  std::vector<BOARD_ITEM*> sel_items; // All the items operated on by the move below
768  std::vector<BOARD_ITEM*> orig_items; // All the original items in the selection
769 
770  for( EDA_ITEM* item : selection )
771  {
772  BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( item );
773  FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( item );
774 
775  if( boardItem )
776  {
777  orig_items.push_back( boardItem );
778  sel_items.push_back( boardItem );
779  }
780 
781  if( footprint )
782  {
783  for( PAD* pad : footprint->Pads() )
784  sel_items.push_back( pad );
785 
786  // Clear this flag here; it will be set by the netlist updater if the footprint is new
787  // so that it was skipped in the initial connectivity update in OnNetlistChanged
789  }
790  }
791 
792  bool restore_state = false;
793  VECTOR2I originalPos;
794  VECTOR2I totalMovement;
796  TOOL_EVENT* evt = &aEvent;
797  VECTOR2I prevPos;
798 
799  bool lock45 = false;
800  bool eatFirstMouseUp = true;
801  bool hasRedrawn3D = false;
802  bool allowRedraw3D = editFrame->GetDisplayOptions().m_Live3DRefresh;
803 
804  // Prime the pump
806 
807  // Main loop: keep receiving events
808  do
809  {
810  VECTOR2I movement;
812  grid.SetSnap( !evt->Modifier( MD_SHIFT ) );
813  grid.SetUseGrid( getView()->GetGAL()->GetGridSnapping() && !evt->DisableGridSnapping() );
814 
815  if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
816  eatFirstMouseUp = false;
817 
818  if( evt->IsAction( &PCB_ACTIONS::move ) || evt->IsMotion() || evt->IsDrag( BUT_LEFT )
819  || evt->IsAction( &ACTIONS::refreshPreview )
820  || evt->IsAction( &PCB_ACTIONS::moveWithReference ) )
821  {
822  if( m_dragging && evt->Category() == TC_MOUSE )
823  {
824  bool redraw3D = false;
825 
826  VECTOR2I mousePos( controls->GetMousePosition() );
827 
828  m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items );
829 
831  {
833 
834  // The arrow keys are by definition SINGLE AXIS. Do not allow the other
835  // axis to be snapped to the grid.
836  if( action == ACTIONS::CURSOR_LEFT || action == ACTIONS::CURSOR_RIGHT )
837  m_cursor.y = prevPos.y;
838  else if( action == ACTIONS::CURSOR_UP || action == ACTIONS::CURSOR_DOWN )
839  m_cursor.x = prevPos.x;
840  }
841 
843  originalPos = m_cursor;
844 
845  if( lock45 )
846  {
847  VECTOR2I moveVector = m_cursor - originalPos;
848  m_cursor = originalPos + GetVectorSnapped45( moveVector );
849  }
850 
853 
854  movement = m_cursor - prevPos;
855  prevPos = m_cursor;
856  totalMovement += movement;
857 
858  // Drag items to the current cursor position
859  for( EDA_ITEM* item : sel_items )
860  {
861  // Don't double move footprint pads, fields, etc.
862  //
863  // For PCB_GROUP_T, we make sure the selection includes only the top level
864  // group and not its descendants.
865  if( !item->GetParent() || !item->GetParent()->IsSelected() )
866  static_cast<BOARD_ITEM*>( item )->Move( movement );
867 
868  if( !redraw3D && item->Type() == PCB_FOOTPRINT_T )
869  redraw3D = true;
870  }
871 
872  if( redraw3D && allowRedraw3D )
873  {
874  editFrame->Update3DView( false, true );
875  hasRedrawn3D = true;
876  }
877 
879  }
880  else if( !m_dragging && !evt->IsAction( &ACTIONS::refreshPreview ) )
881  {
882  // Prepare to start dragging
883  if( !( evt->IsAction( &PCB_ACTIONS::move )
884  || evt->IsAction( &PCB_ACTIONS::moveWithReference ) )
885  && ( editFrame->Settings().m_TrackDragAction != TRACK_DRAG_ACTION::MOVE ) )
886  {
888  break;
889  }
890 
891  m_dragging = true;
892 
893  // When editing footprints, all items have the same parent
894  if( IsFootprintEditor() )
895  {
896  m_commit->Modify( selection.Front() );
897  }
898  else
899  {
900  // Save items, so changes can be undone
901  for( EDA_ITEM* item : selection )
902  {
903  // Don't double move footprint pads, fields, etc.
904  //
905  // For PCB_GROUP_T, the parent is the board.
906  if( item->GetParent() && item->GetParent()->IsSelected() )
907  continue;
908 
909  m_commit->Modify( item );
910 
911  // If moving a group, record position of all the descendants for undo
912  if( item->Type() == PCB_GROUP_T )
913  {
914  PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
915  group->RunOnDescendants( [&]( BOARD_ITEM* bItem )
916  {
917  m_commit->Modify( bItem );
918  });
919  }
920  }
921  }
922 
923  editFrame->UndoRedoBlock( true );
925 
927  {
928  // start moving with the reference point attached to the cursor
929  grid.SetAuxAxes( false );
930 
931  if( lock45 )
932  {
933  VECTOR2I moveVector = m_cursor - originalPos;
934  m_cursor = originalPos + GetVectorSnapped45( moveVector );
935  }
936 
937  movement = m_cursor - selection.GetReferencePoint();
938 
939  // Drag items to the current cursor position
940  for( EDA_ITEM* item : selection )
941  {
942  // Don't double move footprint pads, fields, etc.
943  if( item->GetParent() && item->GetParent()->IsSelected() )
944  continue;
945 
946  static_cast<BOARD_ITEM*>( item )->Move( movement );
947  }
948 
950  }
951  else
952  {
953  std::vector<BOARD_ITEM*> items;
954 
955  for( EDA_ITEM* item : selection )
956  items.push_back( static_cast<BOARD_ITEM*>( item ) );
957 
958  m_cursor = grid.BestDragOrigin( originalCursorPos, items );
959 
960  // Set the current cursor position to the first dragged item origin, so the
961  // movement vector could be computed later
962  if( aPickReference )
963  {
964  selection.SetReferencePoint( pickedReferencePoint );
965  controls->ForceCursorPosition( true, pickedReferencePoint );
966  m_cursor = pickedReferencePoint;
967  }
968  else
969  {
970  // Check if user wants to warp the mouse to origin of moved object
971  if( !editFrame->GetMoveWarpsCursor() )
972  m_cursor = originalCursorPos; // No, so use original mouse pos instead
973 
975  grid.SetAuxAxes( true, m_cursor );
976  }
977 
978  originalPos = m_cursor;
979 
980  }
981 
983 
984  prevPos = m_cursor;
985  controls->SetAutoPan( true );
987  }
988 
990  new VECTOR2I( movement ) );
991  }
992  else if( evt->IsCancelInteractive() || evt->IsActivate() )
993  {
994  if( m_dragging && evt->IsCancelInteractive() )
995  evt->SetPassEvent( false );
996 
997  restore_state = true; // Canceling the tool means that items have to be restored
998  break; // Finish
999  }
1000  else if( evt->IsAction( &ACTIONS::undo ) )
1001  {
1002  restore_state = true; // Perform undo locally
1003  break; // Finish
1004  }
1005  else if( evt->IsAction( &ACTIONS::doDelete ) || evt->IsAction( &ACTIONS::cut ) )
1006  {
1007  // Dispatch TOOL_ACTIONs
1008  evt->SetPassEvent();
1009  break; // finish -- there is no further processing for removed items
1010  }
1011  else if( evt->IsAction( &ACTIONS::duplicate ) )
1012  {
1013  evt->SetPassEvent();
1014  break; // finish -- Duplicate tool will start a new Move with the dup'ed items
1015  }
1016  else if( evt->IsAction( &PCB_ACTIONS::rotateCw )
1017  || evt->IsAction( &PCB_ACTIONS::rotateCcw )
1018  || evt->IsAction( &PCB_ACTIONS::flip )
1019  || evt->IsAction( &PCB_ACTIONS::mirror ) )
1020  {
1021  eatFirstMouseUp = false;
1022  evt->SetPassEvent();
1023  }
1024  else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
1025  {
1026  // Reset positions so the Move Exactly is from the start.
1027  for( EDA_ITEM* item : selection )
1028  {
1029  BOARD_ITEM* i = static_cast<BOARD_ITEM*>( item );
1030  i->Move( -totalMovement );
1031  }
1032 
1033  break; // finish -- we moved exactly, so we are finished
1034  }
1035  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
1036  {
1037  // Eat mouse-up/-click events that leaked through from the lock dialog
1038  if( eatFirstMouseUp && evt->Parameter<intptr_t>() != ACTIONS::CURSOR_CLICK )
1039  {
1040  eatFirstMouseUp = false;
1041  continue;
1042  }
1043 
1044  break; // finish
1045  }
1046  else if( evt->IsAction( &PCB_ACTIONS::toggle45 ) )
1047  {
1048  lock45 = !lock45;
1049  evt->SetPassEvent( false );
1050  }
1051  else
1052  {
1053  evt->SetPassEvent();
1054  }
1055 
1056  } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional
1057 
1058  controls->ForceCursorPosition( false );
1059  controls->ShowCursor( false );
1060  controls->SetAutoPan( false );
1061 
1062  m_dragging = false;
1063  editFrame->UndoRedoBlock( false );
1064 
1065  if( hasRedrawn3D && restore_state )
1066  editFrame->Update3DView( false, true );
1067 
1068  // Discard reference point when selection is "dropped" onto the board
1070 
1071  // TODO: there's an encapsulation leak here: this commit often has more than just the move
1072  // in it; for instance it might have a paste, append board, etc. as well.
1073  if( restore_state )
1074  m_commit->Revert();
1075  else
1076  m_commit->Push( _( "Drag" ) );
1077 
1078  // Remove the dynamic ratsnest from the screen
1080 
1081  // Unselect all items to update flags
1083 
1084  // Reselect items if they were already selected and we completed the move
1085  if( !is_hover && !restore_state )
1086  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &orig_items );
1087 
1088  editFrame->PopTool( tool );
1089  editFrame->GetCanvas()->SetCurrentCursor( KICURSOR::ARROW );
1090 
1091  return restore_state ? -1 : 0;
1092 }
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: pcb_actions.h:66
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
VECTOR2I GetReferencePoint() const
Definition: selection.h:184
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
VECTOR2I m_cursor
Definition: edit_tool.h:192
void ClearReferencePoint()
Definition: selection.h:197
VECTOR2< T > GetVectorSnapped45(const VECTOR2< T > &aVec, bool only45=false)
Snap a vector onto the nearest 0, 45 or 90 degree line.
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:92
bool IsHover() const
Definition: selection.h:74
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
static TOOL_ACTION doDelete
Definition: actions.h:72
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector) const
Check the "allow free pads" setting and if disabled, upgrade any pad selection to the selection of it...
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void PushTool(const std::string &actionName)
NB: the definition of "tool" is different at the user level.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION mirror
Mirroring of selected items.
Definition: pcb_actions.h:108
virtual void SetCursorPosition(const VECTOR2D &aPosition, bool aWarpView=true, bool aTriggeredByArrows=false, long aArrowCommand=0)=0
Move cursor to the requested position expressed in world coordinates.
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
void UndoRedoBlock(bool aBlock=true)
Enable/disable undo and redo operations.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
const PCB_DISPLAY_OPTIONS & GetDisplayOptions() const
Display options control the way tracks, vias, outlines and other things are shown (for instance solid...
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
void SetAttributes(int aAttributes)
Definition: footprint.h:240
PADS & Pads()
Definition: footprint.h:169
const VC_SETTINGS & GetSettings() const
Apply VIEW_CONTROLS settings from an object.
static TOOL_ACTION moveExact
Activation of the exact move tool.
Definition: pcb_actions.h:120
bool pickReferencePoint(const wxString &aTooltip, const wxString &aSuccessMessage, const wxString &aCanceledMessage, VECTOR2I &aReferencePoint)
Definition: edit_tool.cpp:2296
PCB_BASE_EDIT_FRAME * frame() const
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:192
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:101
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
const PCB_SELECTION & selection() const
TRACK_DRAG_ACTION m_TrackDragAction
bool m_dragging
Definition: edit_tool.h:191
virtual void Move(const wxPoint &aMoveVector)
Move this object.
Definition: board_item.h:233
virtual void PopTool(const std::string &actionName)
Generic, UI-independent tool event.
Definition: tool_event.h:152
FOOTPRINT * footprint() const
static TOOL_ACTION cut
Definition: actions.h:66
An interface for classes handling user events controlling the view behavior such as zooming,...
#define _(s)
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
static const TOOL_EVENT SelectedItemsMoved
Used to inform tools that the selection should temporarily be non-editable.
Definition: actions.h:208
bool m_isFootprintEditor
static TOOL_ACTION hideDynamicRatsnest
Definition: pcb_actions.h:461
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:102
OPT< std::string > GetCommandStr() const
Definition: tool_event.h:460
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
bool invokeInlineRouter(int aDragMode)
Definition: edit_tool.cpp:235
bool HasReferencePoint() const
Definition: selection.h:179
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
KIGFX::VIEW_CONTROLS * controls() const
int GetAttributes() const
Definition: footprint.h:239
Common, abstract interface for edit frames.
long m_lastKeyboardCursorCommand
Position of the above event.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
bool m_Live3DRefresh
If true, 3D viewer will redraw on every modification operation.
virtual void Update3DView(bool aMarkDirty, bool aRefresh, const wxString *aTitle=nullptr)
Update the 3D view, if the viewer is opened by this frame.
bool m_lastKeyboardCursorPositionValid
ACTIONS::CURSOR_UP, ACTIONS::CURSOR_DOWN, etc.
PCBNEW_SETTINGS & Settings()
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
bool IsFootprintEditor() const
bool GetMoveWarpsCursor() const
Indicate that a move operation should warp the mouse pointer to the origin of the move object.
Definition: tools_holder.h:141
void Activate()
Run the tool.
static TOOL_ACTION undo
Definition: actions.h:64
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:462
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
Definition: pad.h:57
static TOOL_ACTION moveWithReference
move with a reference point
Definition: pcb_actions.h:95
void PostEvent(const TOOL_EVENT &aEvent)
Put an event to the event queue to be processed at the end of event processing cycle.
const LSET GetSelectionLayers()
static TOOL_ACTION toggle45
Definition: pcb_actions.h:420
static TOOL_ACTION duplicate
Definition: actions.h:71
static TOOL_ACTION refreshPreview
Definition: actions.h:106
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:145

References _, TOOL_INTERACTIVE::Activate(), ARROW, BUT_LEFT, SELECTION::ClearReferencePoint(), PCB_TOOL_BASE::controls(), ACTIONS::CURSOR_CLICK, ACTIONS::CURSOR_DOWN, ACTIONS::CURSOR_LEFT, ACTIONS::CURSOR_RIGHT, ACTIONS::CURSOR_UP, ACTIONS::cut, PNS::DM_ANY, ACTIONS::doDelete, ACTIONS::duplicate, SELECTION::Empty(), PCB_SELECTION_TOOL::FilterCollectorForFreePads(), PCB_SELECTION_TOOL::FilterCollectorForHierarchy(), PCB_SELECTION_TOOL::FilterCollectorForMarkers(), PCB_ACTIONS::flip, PCB_TOOL_BASE::footprint(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), FP_JUST_ADDED, PCB_TOOL_BASE::frame(), SELECTION::Front(), FOOTPRINT::GetAttributes(), PCB_BASE_FRAME::GetCanvas(), TOOL_EVENT::GetCommandStr(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_BASE_FRAME::GetDisplayOptions(), PCB_BASE_FRAME::GetMagneticItemsSettings(), KIGFX::VIEW_CONTROLS::GetMousePosition(), TOOLS_HOLDER::GetMoveWarpsCursor(), SELECTION::GetReferencePoint(), PCB_SELECTION::GetSelectionLayers(), KIGFX::VIEW_CONTROLS::GetSettings(), GetVectorSnapped45(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), grid, group, SELECTION::HasReferencePoint(), PCB_ACTIONS::hideDynamicRatsnest, invokeInlineRouter(), PCB_TOOL_BASE::IsFootprintEditor(), SELECTION::IsHover(), PCBNEW_SETTINGS::m_AllowFreePads, m_commit, m_cursor, m_dragging, PCB_TOOL_BASE::m_isFootprintEditor, KIGFX::VC_SETTINGS::m_lastKeyboardCursorCommand, KIGFX::VC_SETTINGS::m_lastKeyboardCursorPositionValid, PCB_DISPLAY_OPTIONS::m_Live3DRefresh, m_selectionTool, TOOL_BASE::m_toolMgr, PCBNEW_SETTINGS::m_TrackDragAction, MD_SHIFT, PCB_ACTIONS::mirror, MOVE, PCB_ACTIONS::move, BOARD_ITEM::Move(), PCB_ACTIONS::moveExact, PCB_ACTIONS::moveWithReference, MOVING, pad, FOOTPRINT::Pads(), PCB_FOOTPRINT_T, PCB_GROUP_T, pickReferencePoint(), TOOLS_HOLDER::PopTool(), TOOL_MANAGER::PostEvent(), TOOLS_HOLDER::PushTool(), ACTIONS::refreshPreview, PCB_SELECTION_TOOL::RequestSelection(), PCB_ACTIONS::rotateCcw, PCB_ACTIONS::rotateCw, TOOL_MANAGER::RunAction(), EVENTS::SelectedItemsModified, EVENTS::SelectedItemsMoved, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItems, FOOTPRINT::SetAttributes(), KIGFX::VIEW_CONTROLS::SetAutoPan(), EDA_DRAW_PANEL_GAL::SetCurrentCursor(), KIGFX::VIEW_CONTROLS::SetCursorPosition(), SELECTION::SetReferencePoint(), PCB_BASE_FRAME::Settings(), KIGFX::VIEW_CONTROLS::ShowCursor(), TC_MOUSE, PCB_ACTIONS::toggle45, ACTIONS::undo, PCB_BASE_EDIT_FRAME::UndoRedoBlock(), PCB_BASE_FRAME::Update3DView(), PCB_ACTIONS::updateLocalRatsnest, TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Move(), and MoveWithReference().

◆ Drag()

int EDIT_TOOL::Drag ( const TOOL_EVENT aEvent)

Invoke the PNS router to drag tracks or do an offline resizing of an arc track if a single arc track is selected.

Definition at line 274 of file edit_tool.cpp.

275 {
276  if( !m_toolMgr->GetTool<ROUTER_TOOL>() )
277  return false; // don't drag when no router tool (i.e. fp editor)
278 
280  return false; // don't drag when router is already active
281 
282  int mode = PNS::DM_ANY;
283 
284  if( aEvent.IsAction( &PCB_ACTIONS::dragFreeAngle ) )
285  mode |= PNS::DM_FREE_ANGLE;
286 
288  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
289  {
290  sTool->FilterCollectorForFreePads( aCollector );
291  sTool->FilterCollectorForHierarchy( aCollector, true );
292 
293  // drop a knee between two segments to a single segment
294  if( aCollector.GetCount() == 2 && dynamic_cast<PCB_TRACK*>( aCollector[0] ) )
295  {
296  static KICAD_T types[] = { PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT };
297 
298  PCB_TRACK* a = static_cast<PCB_TRACK*>( aCollector[0] );
299  PCB_TRACK* b = static_cast<PCB_TRACK*>( aCollector[1] );
300  const auto& c = aCollector[0]->GetBoard()->GetConnectivity();
301 
302  int dist = a->GetWidth() / 2;
303  auto connectedItems = c->GetConnectedItemsAtAnchor( a, aPt, types, dist );
304 
305  if( alg::contains( connectedItems, b ) )
306  aCollector.Remove( b );
307  }
308  },
309  true /* prompt user regarding locked items */ );
310 
311  if( selection.Empty() )
312  return 0;
313 
314  if( selection.Size() == 1 && selection.Front()->Type() == PCB_ARC_T )
315  {
316  // TODO: This really should be done in PNS to ensure DRC is maintained, but for now
317  // it allows interactive editing of an arc track
318  return DragArcTrack( aEvent );
319  }
320  else
321  {
322  invokeInlineRouter( mode );
323  }
324 
325  return 0;
326 }
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector) const
Check the "allow free pads" setting and if disabled, upgrade any pad selection to the selection of it...
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:135
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
int GetWidth() const
Definition: pcb_track.h:102
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
const PCB_SELECTION & selection() const
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:99
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
bool invokeInlineRouter(int aDragMode)
Definition: edit_tool.cpp:235
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
bool IsToolActive() const
Definition: tool_base.cpp:31
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
The selection tool: currently supports:
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
EDA_ITEM * Front() const
Definition: selection.h:145
int DragArcTrack(const TOOL_EVENT &aTrack)
Drag-resize an arc (and change end points of connected straight segments).
Definition: edit_tool.cpp:329
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References alg::contains(), PNS::DM_ANY, PNS::DM_FREE_ANGLE, DragArcTrack(), PCB_ACTIONS::dragFreeAngle, SELECTION::Empty(), EOT, PCB_SELECTION_TOOL::FilterCollectorForFreePads(), PCB_SELECTION_TOOL::FilterCollectorForHierarchy(), SELECTION::Front(), COLLECTOR::GetCount(), TOOL_MANAGER::GetTool(), PCB_TRACK::GetWidth(), invokeInlineRouter(), TOOL_EVENT::IsAction(), TOOL_BASE::IsToolActive(), m_selectionTool, TOOL_BASE::m_toolMgr, PCB_ARC_T, PCB_TRACE_T, PCB_VIA_T, COLLECTOR::Remove(), PCB_SELECTION_TOOL::RequestSelection(), PCB_TOOL_BASE::selection(), SELECTION::Size(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ DragArcTrack()

int EDIT_TOOL::DragArcTrack ( const TOOL_EVENT aTrack)

Drag-resize an arc (and change end points of connected straight segments).

Definition at line 329 of file edit_tool.cpp.

330 {
332 
333  if( selection.Size() != 1 || selection.Front()->Type() != PCB_ARC_T )
334  return 0;
335 
336  PCB_ARC* theArc = static_cast<PCB_ARC*>( selection.Front() );
337  double arcAngleDegrees = std::abs( theArc->GetAngle() ) / 10.0;
338 
339  if( arcAngleDegrees + ADVANCED_CFG::GetCfg().m_MaxTangentAngleDeviation >= 180.0 )
340  {
342  wxString::Format( _( "Unable to resize arc tracks %.1f degrees or greater." ),
343  180.0 - ADVANCED_CFG::GetCfg().m_MaxTangentAngleDeviation ) );
344  return 0; // don't bother with > 180 degree arcs
345  }
346 
348 
349  Activate();
350  // Must be done after Activate() so that it gets set into the correct context
351  controls->ShowCursor( true );
352  controls->SetAutoPan( true );
353 
354  bool restore_state = false;
355  VECTOR2I arcCenter = theArc->GetCenter();
356  SEG tanStart = SEG( arcCenter, theArc->GetStart() ).PerpendicularSeg( theArc->GetStart() );
357  SEG tanEnd = SEG( arcCenter, theArc->GetEnd() ).PerpendicularSeg( theArc->GetEnd() );
358 
359  //Ensure the tangent segments are in the correct orientation
360  VECTOR2I tanIntersect = tanStart.IntersectLines( tanEnd ).get();
361  tanStart.A = tanIntersect;
362  tanStart.B = theArc->GetStart();
363  tanEnd.A = tanIntersect;
364  tanEnd.B = theArc->GetEnd();
365 
366  KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT };
367 
368  auto getUniqueTrackAtAnchorCollinear =
369  [&]( const VECTOR2I& aAnchor, const SEG& aCollinearSeg ) -> PCB_TRACK*
370  {
371  auto conn = board()->GetConnectivity();
372 
373  // Allow items at a distance within the width of the arc track
374  int allowedDeviation = theArc->GetWidth();
375 
376  std::vector<BOARD_CONNECTED_ITEM*> itemsOnAnchor;
377 
378  for( int i = 0; i < 3; i++ )
379  {
380  itemsOnAnchor = conn->GetConnectedItemsAtAnchor( theArc, aAnchor, track_types,
381  allowedDeviation );
382  allowedDeviation /= 2;
383 
384  if( itemsOnAnchor.size() == 1 )
385  break;
386  }
387 
388  PCB_TRACK* retval = nullptr;
389 
390  if( itemsOnAnchor.size() == 1 && itemsOnAnchor.front()->Type() == PCB_TRACE_T )
391  {
392  retval = static_cast<PCB_TRACK*>( itemsOnAnchor.front() );
393  SEG trackSeg( retval->GetStart(), retval->GetEnd() );
394 
395  // Allow deviations in colinearity as defined in ADVANCED_CFG
396  if( trackSeg.AngleDegrees( aCollinearSeg )
398  {
399  retval = nullptr;
400  }
401  }
402 
403  if( !retval )
404  {
405  retval = new PCB_TRACK( theArc->GetParent() );
406  retval->SetStart( (wxPoint) aAnchor );
407  retval->SetEnd( (wxPoint) aAnchor );
408  retval->SetNet( theArc->GetNet() );
409  retval->SetLayer( theArc->GetLayer() );
410  retval->SetWidth( theArc->GetWidth() );
411  retval->SetLocked( theArc->IsLocked() );
412  retval->SetFlags( IS_NEW );
413  getView()->Add( retval );
414  }
415 
416  return retval;
417  };
418 
419  PCB_TRACK* trackOnStart = getUniqueTrackAtAnchorCollinear( theArc->GetStart(), tanStart);
420  PCB_TRACK* trackOnEnd = getUniqueTrackAtAnchorCollinear( theArc->GetEnd(), tanEnd );
421 
422  // Make copies of items to be edited
423  PCB_ARC* theArcCopy = new PCB_ARC( *theArc );
424  PCB_TRACK* trackOnStartCopy = new PCB_TRACK( *trackOnStart );
425  PCB_TRACK* trackOnEndCopy = new PCB_TRACK( *trackOnEnd );
426 
427  if( trackOnStart->GetLength() != 0 )
428  {
429  tanStart.A = trackOnStart->GetStart();
430  tanStart.B = trackOnStart->GetEnd();
431  }
432 
433  if( trackOnEnd->GetLength() != 0 )
434  {
435  tanEnd.A = trackOnEnd->GetStart();
436  tanEnd.B = trackOnEnd->GetEnd();
437  }
438 
439  // Recalculate intersection point
440  tanIntersect = tanStart.IntersectLines( tanEnd ).get();
441 
442  auto isTrackStartClosestToArcStart =
443  [&]( PCB_TRACK* aTrack ) -> bool
444  {
445  double trackStartToArcStart = GetLineLength( aTrack->GetStart(), theArc->GetStart() );
446  double trackEndToArcStart = GetLineLength( aTrack->GetEnd(), theArc->GetStart() );
447 
448  return trackStartToArcStart < trackEndToArcStart;
449  };
450 
451  bool isStartTrackOnStartPt = isTrackStartClosestToArcStart( trackOnStart );
452  bool isEndTrackOnStartPt = isTrackStartClosestToArcStart( trackOnEnd );
453 
454  // Calculate constraints
455  //======================
456  // maxTanCircle is the circle with maximum radius that is tangent to the two adjacent straight
457  // tracks and whose tangent points are constrained within the original tracks and their
458  // projected intersection points.
459  //
460  // The cursor will be constrained first within the isosceles triangle formed by the segments
461  // cSegTanStart, cSegTanEnd and cSegChord. After that it will be constrained to be outside
462  // maxTanCircle.
463  //
464  //
465  // ____________ <-cSegTanStart
466  // / * . ' *
467  // cSegTanEnd-> / * . ' *
468  // /* . ' <-cSegChord *
469  // /. '
470  // /* *
471  //
472  // * c * <-maxTanCircle
473  //
474  // * *
475  //
476  // * *
477  // * *
478  // * *
479  //
480 
481  auto getFurthestPointToTanInterstect =
482  [&]( VECTOR2I& aPointA, VECTOR2I& aPointB ) -> VECTOR2I
483  {
484  if( ( aPointA - tanIntersect ).EuclideanNorm()
485  > ( aPointB - tanIntersect ).EuclideanNorm() )
486  {
487  return aPointA;
488  }
489  else
490  {
491  return aPointB;
492  }
493  };
494 
495  CIRCLE maxTanCircle;
496  VECTOR2I tanStartPoint = getFurthestPointToTanInterstect( tanStart.A, tanStart.B );
497  VECTOR2I tanEndPoint = getFurthestPointToTanInterstect( tanEnd.A, tanEnd.B );
498  VECTOR2I tempTangentPoint = tanEndPoint;
499 
500  if( getFurthestPointToTanInterstect( tanStartPoint, tanEndPoint ) == tanEndPoint )
501  tempTangentPoint = tanStartPoint;
502 
503  maxTanCircle.ConstructFromTanTanPt( tanStart, tanEnd, tempTangentPoint );
504  VECTOR2I maxTanPtStart = tanStart.LineProject( maxTanCircle.Center );
505  VECTOR2I maxTanPtEnd = tanEnd.LineProject( maxTanCircle.Center );
506 
507  SEG cSegTanStart( maxTanPtStart, tanIntersect );
508  SEG cSegTanEnd( maxTanPtEnd, tanIntersect );
509  SEG cSegChord( maxTanPtStart, maxTanPtEnd );
510 
511  int cSegTanStartSide = cSegTanStart.Side( theArc->GetMid() );
512  int cSegTanEndSide = cSegTanEnd.Side( theArc->GetMid() );
513  int cSegChordSide = cSegChord.Side( theArc->GetMid() );
514 
515  bool eatFirstMouseUp = true;
516 
517  // Start the tool loop
518  while( TOOL_EVENT* evt = Wait() )
519  {
521 
522  // Constrain cursor within the isosceles triangle
523  if( cSegTanStartSide != cSegTanStart.Side( m_cursor )
524  || cSegTanEndSide != cSegTanEnd.Side( m_cursor )
525  || cSegChordSide != cSegChord.Side( m_cursor ) )
526  {
527  std::vector<VECTOR2I> possiblePoints;
528 
529  possiblePoints.push_back( cSegTanEnd.NearestPoint( m_cursor ) );
530  possiblePoints.push_back( cSegChord.NearestPoint( m_cursor ) );
531 
532  VECTOR2I closest = cSegTanStart.NearestPoint( m_cursor );
533 
534  for( VECTOR2I candidate : possiblePoints )
535  {
536  if( ( candidate - m_cursor ).SquaredEuclideanNorm()
537  < ( closest - m_cursor ).SquaredEuclideanNorm() )
538  {
539  closest = candidate;
540  }
541  }
542 
543  m_cursor = closest;
544  }
545 
546  // Constrain cursor to be outside maxTanCircle
547  if( ( m_cursor - maxTanCircle.Center ).EuclideanNorm() < maxTanCircle.Radius )
548  m_cursor = maxTanCircle.NearestPoint( m_cursor );
549 
551 
552  // Calculate resulting object coordinates
553  CIRCLE circlehelper;
554  circlehelper.ConstructFromTanTanPt( cSegTanStart, cSegTanEnd, m_cursor );
555 
556  VECTOR2I newCenter = circlehelper.Center;
557  VECTOR2I newStart = cSegTanStart.LineProject( newCenter );
558  VECTOR2I newEnd = cSegTanEnd.LineProject( newCenter );
559  VECTOR2I newMid = CalcArcMid( newStart, newEnd, newCenter );
560 
561  // Update objects
562  theArc->SetStart( (wxPoint) newStart );
563  theArc->SetEnd( (wxPoint) newEnd );
564  theArc->SetMid( (wxPoint) newMid );
565 
566  if( isStartTrackOnStartPt )
567  trackOnStart->SetStart( (wxPoint) newStart );
568  else
569  trackOnStart->SetEnd( (wxPoint) newStart );
570 
571  if( isEndTrackOnStartPt )
572  trackOnEnd->SetStart( (wxPoint) newEnd );
573  else
574  trackOnEnd->SetEnd( (wxPoint) newEnd );
575 
576  // Update view
577  getView()->Update( trackOnStart );
578  getView()->Update( trackOnEnd );
579  getView()->Update( theArc );
580 
581  // Handle events
582  if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
583  {
584  eatFirstMouseUp = false;
585  }
586  else if( evt->IsCancelInteractive() || evt->IsActivate() )
587  {
588  restore_state = true; // Canceling the tool means that items have to be restored
589  break; // Finish
590  }
591  else if( evt->IsAction( &ACTIONS::undo ) )
592  {
593  restore_state = true; // Perform undo locally
594  break; // Finish
595  }
596  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT )
597  || evt->IsDblClick( BUT_LEFT ) )
598  {
599  // Eat mouse-up/-click events that leaked through from the lock dialog
600  if( eatFirstMouseUp && evt->Parameter<intptr_t>() != ACTIONS::CURSOR_CLICK )
601  {
602  eatFirstMouseUp = false;
603  continue;
604  }
605 
606  break; // Finish
607  }
608  }
609 
610  // Ensure we only do one commit operation on each object
611  auto processTrack =
612  [&]( PCB_TRACK* aTrack, PCB_TRACK* aTrackCopy, int aMaxLengthIU ) -> bool
613  {
614  if( aTrack->IsNew() )
615  {
616  getView()->Remove( aTrack );
617 
618  if( aTrack->GetLength() <= aMaxLengthIU )
619  {
620  delete aTrack;
621  delete aTrackCopy;
622  aTrack = nullptr;
623  aTrackCopy = nullptr;
624  return false;
625  }
626  else
627  {
628  m_commit->Add( aTrack );
629  delete aTrackCopy;
630  aTrackCopy = nullptr;
631  return true;
632  }
633  }
634  else if( aTrack->GetLength() <= aMaxLengthIU )
635  {
636  aTrack->SwapData( aTrackCopy ); //restore the original before notifying COMMIT
637  m_commit->Remove( aTrack );
638  delete aTrackCopy;
639  aTrackCopy = nullptr;
640  return false;
641  }
642  else
643  {
644  m_commit->Modified( aTrack, aTrackCopy );
645  }
646 
647  return true;
648  };
649 
650  // Amend the end points of the arc if we delete the joining tracks
651  wxPoint newStart = trackOnStart->GetStart();
652  wxPoint newEnd = trackOnEnd->GetStart();
653 
654  if( isStartTrackOnStartPt )
655  newStart = trackOnStart->GetEnd();
656 
657  if( isEndTrackOnStartPt )
658  newEnd = trackOnEnd->GetEnd();
659 
660  int maxLengthIU = KiROUND( ADVANCED_CFG::GetCfg().m_MaxTrackLengthToKeep * IU_PER_MM );
661 
662  if( !processTrack( trackOnStart, trackOnStartCopy, maxLengthIU ) )
663  theArc->SetStart( newStart );
664 
665  if( !processTrack( trackOnEnd, trackOnEndCopy, maxLengthIU ) )
666  theArc->SetEnd( newEnd );
667 
668  processTrack( theArc, theArcCopy, 0 ); // only delete the arc if start and end points coincide
669 
670  // Should we commit?
671  if( restore_state )
672  m_commit->Revert();
673  else
674  m_commit->Push( _( "Drag Arc Track" ) );
675 
676  return 0;
677 }
double EuclideanNorm(const wxPoint &vector)
Euclidean norm of a 2D vector.
Definition: trigo.h:146
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
VECTOR2I m_cursor
Definition: edit_tool.h:192
virtual wxPoint GetCenter() const override
This defaults to the center of the bounding box if not overridden.
Definition: pcb_track.h:281
double GetLineLength(const wxPoint &aPointA, const wxPoint &aPointB)
Return the length of a line segment defined by aPointA and aPointB.
Definition: trigo.h:222
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
BOARD * board() const
const wxPoint & GetEnd() const
Definition: pcb_track.h:105
const VECTOR2I CalcArcMid(const VECTOR2I &aStart, const VECTOR2I &aEnd, const VECTOR2I &aCenter, bool aMinArcAngle=true)
Return the middle point of an arc, half-way between aStart and aEnd.
Definition: trigo.cpp:163
#define IS_NEW
New item, just created.
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:164
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void SetEnd(const wxPoint &aEnd)
Definition: pcb_track.h:104
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
static constexpr double IU_PER_MM
Mock up a conversion function.
virtual double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: pcb_track.cpp:259
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:350
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition: eda_item.h:152
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
OPT_VECTOR2I IntersectLines(const SEG &aSeg) const
Compute the intersection point of lines passing through ends of (this) and aSeg.
Definition: seg.h:209
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:218
int GetWidth() const
Definition: pcb_track.h:102
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
virtual bool IsLocked() const
Definition: board_item.cpp:64
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
CIRCLE & ConstructFromTanTanPt(const SEG &aLineA, const SEG &aLineB, const VECTOR2I &aP)
Construct this circle such that it is tangent to the given segments and passes through the given poin...
Definition: circle.cpp:51
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
bool IsNew() const
Definition: eda_item.h:118
PCB_BASE_EDIT_FRAME * frame() const
void ShowInfoBarError(const wxString &aErrorMsg, bool aShowCloseButton=false, WX_INFOBAR::MESSAGE_TYPE aType=WX_INFOBAR::MESSAGE_TYPE::GENERIC)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an error icon on the left o...
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
VECTOR2I LineProject(const VECTOR2I &aP) const
Compute the perpendicular projection point of aP on a line passing through ends of the segment.
Definition: seg.cpp:301
const PCB_SELECTION & selection() const
void SetMid(const wxPoint &aMid)
Definition: pcb_track.h:271
Generic, UI-independent tool event.
Definition: tool_event.h:152
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:345
void SetStart(const wxPoint &aStart)
Definition: pcb_track.h:107
An interface for classes handling user events controlling the view behavior such as zooming,...
#define _(s)
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
int Radius
Public to make access simpler.
Definition: circle.h:115
Represent basic circle geometry with utility geometry functions.
Definition: circle.h:32
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
virtual void SetAutoPan(bool aEnabled)
Turn on/off auto panning (this feature is used when there is a tool active (eg.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
Definition: seg.h:40
void SetWidth(int aWidth)
Definition: pcb_track.h:101
virtual void SwapData(BOARD_ITEM *aImage) override
Swap data between aItem and aImage.
Definition: pcb_track.cpp:918
double GetAngle() const
Definition: pcb_track.cpp:952
void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
double m_MaxTangentAngleDeviation
Maximum angle between the tangent line of an arc track and a connected straight track in order to com...
KIGFX::VIEW_CONTROLS * controls() const
VECTOR2I A
Definition: seg.h:48
VECTOR2I Center
Public to make access simpler.
Definition: circle.h:116
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:73
void Activate()
Run the tool.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
static TOOL_ACTION undo
Definition: actions.h:64
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:320
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:136
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:143
const wxPoint & GetMid() const
Definition: pcb_track.h:272
const wxPoint & GetStart() const
Definition: pcb_track.h:108
EDA_ITEM * Front() const
Definition: selection.h:145
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1570
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112
VECTOR2I NearestPoint(const VECTOR2I &aP) const
Compute the point on the circumference of the circle that is the closest to aP.
Definition: circle.cpp:197
VECTOR2I B
Definition: seg.h:49

References _, SEG::A, TOOL_INTERACTIVE::Activate(), KIGFX::VIEW::Add(), SEG::B, PCB_TOOL_BASE::board(), BUT_LEFT, CalcArcMid(), CIRCLE::Center, CIRCLE::ConstructFromTanTanPt(), PCB_TOOL_BASE::controls(), ACTIONS::CURSOR_CLICK, EOT, EuclideanNorm(), KIGFX::VIEW_CONTROLS::ForceCursorPosition(), Format(), PCB_TOOL_BASE::frame(), SELECTION::Front(), PCB_ARC::GetAngle(), PCB_ARC::GetCenter(), ADVANCED_CFG::GetCfg(), BOARD::GetConnectivity(), PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayer(), PCB_TRACK::GetLength(), GetLineLength(), PCB_ARC::GetMid(), KIGFX::VIEW_CONTROLS::GetMousePosition(), BOARD_CONNECTED_ITEM::GetNet(), BOARD_ITEM::GetParent(), PCB_SELECTION_TOOL::GetSelection(), PCB_TRACK::GetStart(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), PCB_TRACK::GetWidth(), SEG::IntersectLines(), IS_NEW, BOARD_ITEM::IsLocked(), EDA_ITEM::IsNew(), IU_PER_MM, KiROUND(), SEG::LineProject(), m_commit, m_cursor, ADVANCED_CFG::m_MaxTangentAngleDeviation, m_selectionTool, CIRCLE::NearestPoint(), SEG::NearestPoint(), PCB_ARC_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, CIRCLE::Radius, KIGFX::VIEW::Remove(), PCB_TOOL_BASE::selection(), KIGFX::VIEW_CONTROLS::SetAutoPan(), PCB_TRACK::SetEnd(), EDA_ITEM::SetFlags(), BOARD_ITEM::SetLayer(), BOARD_ITEM::SetLocked(), PCB_ARC::SetMid(), BOARD_CONNECTED_ITEM::SetNet(), PCB_TRACK::SetStart(), PCB_TRACK::SetWidth(), KIGFX::VIEW_CONTROLS::ShowCursor(), EDA_BASE_FRAME::ShowInfoBarError(), SEG::Side(), SELECTION::Size(), PCB_TRACK::SwapData(), EDA_ITEM::Type(), ACTIONS::undo, KIGFX::VIEW::Update(), and TOOL_INTERACTIVE::Wait().

Referenced by Drag().

◆ Duplicate()

int EDIT_TOOL::Duplicate ( const TOOL_EVENT aEvent)

Duplicate the current selection and starts a move action.

Definition at line 2074 of file edit_tool.cpp.

2075 {
2076  if( isRouterActive() )
2077  {
2078  wxBell();
2079  return 0;
2080  }
2081 
2082  bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
2083 
2084  // Be sure that there is at least one item that we can modify
2086  []( const VECTOR2I&, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
2087  {
2088  sTool->FilterCollectorForMarkers( aCollector );
2089  sTool->FilterCollectorForHierarchy( aCollector, true );
2090  } );
2091 
2092  if( selection.Empty() )
2093  return 0;
2094 
2095  // we have a selection to work on now, so start the tool process
2096  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
2097 
2098  // If the selection was given a hover, we do not keep the selection after completion
2099  bool is_hover = selection.IsHover();
2100 
2101  std::vector<BOARD_ITEM*> new_items;
2102  new_items.reserve( selection.Size() );
2103 
2104  // Each selected item is duplicated and pushed to new_items list
2105  // Old selection is cleared, and new items are then selected.
2106  for( EDA_ITEM* item : selection )
2107  {
2108  BOARD_ITEM* dupe_item = nullptr;
2109  BOARD_ITEM* orig_item = static_cast<BOARD_ITEM*>( item );
2110 
2111  if( m_isFootprintEditor )
2112  {
2113  FOOTPRINT* parentFootprint = editFrame->GetBoard()->GetFirstFootprint();
2114  dupe_item = parentFootprint->DuplicateItem( orig_item );
2115 
2116  if( increment && dupe_item->Type() == PCB_PAD_T
2117  && static_cast<PAD*>( dupe_item )->CanHaveNumber() )
2118  {
2119  PAD_TOOL* padTool = m_toolMgr->GetTool<PAD_TOOL>();
2120  wxString padNumber = padTool->GetLastPadNumber();
2121  padNumber = parentFootprint->GetNextPadNumber( padNumber );
2122  padTool->SetLastPadNumber( padNumber );
2123  static_cast<PAD*>( dupe_item )->SetNumber( padNumber );
2124  }
2125  }
2126  else if( orig_item->GetParent() && orig_item->GetParent()->Type() == PCB_FOOTPRINT_T )
2127  {
2128  FOOTPRINT* parentFootprint = static_cast<FOOTPRINT*>( orig_item->GetParent() );
2129 
2130  m_commit->Modify( parentFootprint );
2131  dupe_item = parentFootprint->DuplicateItem( orig_item, true /* add to parent */ );
2132  }
2133  else
2134  {
2135  switch( orig_item->Type() )
2136  {
2137  case PCB_FOOTPRINT_T:
2138  case PCB_TEXT_T:
2139  case PCB_SHAPE_T:
2140  case PCB_TRACE_T:
2141  case PCB_ARC_T:
2142  case PCB_VIA_T:
2143  case PCB_ZONE_T:
2144  case PCB_TARGET_T:
2145  case PCB_DIM_ALIGNED_T:
2146  case PCB_DIM_CENTER_T:
2147  case PCB_DIM_ORTHOGONAL_T:
2148  case PCB_DIM_LEADER_T:
2149  dupe_item = orig_item->Duplicate();
2150  break;
2151 
2152  case PCB_GROUP_T:
2153  dupe_item = static_cast<PCB_GROUP*>( orig_item )->DeepDuplicate();
2154  break;
2155 
2156  default:
2157  wxASSERT_MSG( false, wxString::Format( wxT( "Unhandled item type %d" ),
2158  orig_item->Type() ) );
2159  break;
2160  }
2161  }
2162 
2163  if( dupe_item )
2164  {
2165  if( dupe_item->Type() == PCB_GROUP_T )
2166  {
2167  static_cast<PCB_GROUP*>( dupe_item )->RunOnDescendants(
2168  [&]( BOARD_ITEM* bItem )
2169  {
2170  m_commit->Add( bItem );
2171  });
2172  }
2173 
2174  // Clear the selection flag here, otherwise the PCB_SELECTION_TOOL
2175  // will not properly select it later on
2176  dupe_item->ClearSelected();
2177 
2178  new_items.push_back( dupe_item );
2179  m_commit->Add( dupe_item );
2180  }
2181  }
2182 
2183  // Clear the old selection first
2185 
2186  // Select the new items
2187  m_toolMgr->RunAction( PCB_ACTIONS::selectItems, true, &new_items );
2188 
2189  // record the new items as added
2190  if( !selection.Empty() )
2191  {
2192  editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
2193  (int) new_items.size() ) );
2194 
2195  // TODO(ISM): This line can't be used to activate the tool until we allow multiple
2196  // activations.
2197  // m_toolMgr->RunAction( PCB_ACTIONS::move, true );
2198  // Instead we have to create the event and call the tool's function
2199  // directly
2200 
2201  // If items were duplicated, pick them up
2202  // this works well for "dropping" copies around and pushes the commit
2204  Move( evt );
2205 
2206  // Deslect the duplicated item if we originally started as a hover selection
2207  if( is_hover )
2209  }
2210 
2211  return 0;
2212 }
static TOOL_ACTION selectItems
Select a list of items (specified as the event parameter)
Definition: pcb_actions.h:66
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
BOARD_ITEM * DuplicateItem(const BOARD_ITEM *aItem, bool aAddToFootprint=false)
Duplicate a given item within the footprint, optionally adding it to the board.
Definition: footprint.cpp:1738
void SetLastPadNumber(const wxString &aPadNumber)
Definition: pad_tool.h:65
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:92
class PCB_DIM_ALIGNED, a linear dimension (graphic item)
Definition: typeinfo.h:100
class PCB_DIM_LEADER, a leader dimension (graphic item)
Definition: typeinfo.h:101
bool IsHover() const
Definition: selection.h:74
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void ClearSelected()
Definition: eda_item.h:131
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
class PCB_DIM_CENTER, a center point marking (graphic item)
Definition: typeinfo.h:102
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
Tool relating to pads and pad settings.
Definition: pad_tool.h:35
class PCB_TEXT, text on a layer
Definition: typeinfo.h:91
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
Definition: tool_event.cpp:88
static TOOL_ACTION duplicateIncrement
Activation of the duplication tool with incrementing (e.g. pad number)
Definition: pcb_actions.h:123
const PCB_SELECTION & selection() const
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition: board.h:318
Generic, UI-independent tool event.
Definition: tool_event.h:152
wxString GetLastPadNumber() const
Definition: pad_tool.h:64
#define _(s)
class ZONE, a copper pour area
Definition: typeinfo.h:105
wxString GetNextPadNumber(const wxString &aLastPadName) const
Return the next available pad number in the footprint.
Definition: footprint.cpp:1823
bool m_isFootprintEditor
int Move(const TOOL_EVENT &aEvent)
Main loop in which events are handled.
Definition: edit_tool.cpp:680
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
class PCB_TARGET, a target (graphic item)
Definition: typeinfo.h:104
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Common, abstract interface for edit frames.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
TOOL_EVENT MakeEvent() const
Return the event associated with the action (i.e.
Definition: tool_action.cpp:72
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
bool isRouterActive() const
Definition: edit_tool.cpp:266
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
class PCB_DIM_ORTHOGONAL, a linear dimension constrained to x/y
Definition: typeinfo.h:103
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
BOARD * GetBoard() const
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:136
class PCB_SHAPE, a segment not on copper layers
Definition: typeinfo.h:90
void DisplayToolMsg(const wxString &msg) override
virtual BOARD_ITEM * Duplicate() const
Create a copy of this BOARD_ITEM.
Definition: board_item.cpp:144
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, EDA_ITEM::ClearSelected(), EDA_DRAW_FRAME::DisplayToolMsg(), BOARD_ITEM::Duplicate(), PCB_ACTIONS::duplicateIncrement, FOOTPRINT::DuplicateItem(), SELECTION::Empty(), PCB_SELECTION_TOOL::FilterCollectorForHierarchy(), PCB_SELECTION_TOOL::FilterCollectorForMarkers(), Format(), PCB_BASE_FRAME::GetBoard(), BOARD::GetFirstFootprint(), PAD_TOOL::GetLastPadNumber(), FOOTPRINT::GetNextPadNumber(), BOARD_ITEM::GetParent(), TOOL_MANAGER::GetTool(), TOOL_EVENT::IsAction(), SELECTION::IsHover(), isRouterActive(), m_commit, PCB_TOOL_BASE::m_isFootprintEditor, m_selectionTool, TOOL_BASE::m_toolMgr, TOOL_ACTION::MakeEvent(), Move(), PCB_ACTIONS::move, PCB_ARC_T, PCB_DIM_ALIGNED_T, PCB_DIM_CENTER_T, PCB_DIM_LEADER_T, PCB_DIM_ORTHOGONAL_T, PCB_FOOTPRINT_T, PCB_GROUP_T, PCB_PAD_T, PCB_SHAPE_T, PCB_TARGET_T, PCB_TEXT_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, PCB_SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItems, PAD_TOOL::SetLastPadNumber(), SELECTION::Size(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ FilletTracks()

int EDIT_TOOL::FilletTracks ( const TOOL_EVENT aEvent)

Fillet (i.e.

adds an arc tangent to) all selected straight tracks by a user defined radius.

Definition at line 1165 of file edit_tool.cpp.

1166 {
1167  // Store last used fillet radius to allow pressing "enter" if repeat fillet is required
1168  static long long filletRadiusIU = 0;
1169 
1171  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1172  {
1173  // Iterate from the back so we don't have to worry about removals.
1174  for( int i = aCollector.GetCount() - 1; i >= 0; --i )
1175  {
1176  BOARD_ITEM* item = aCollector[i];
1177 
1178  if( !dynamic_cast<PCB_TRACK*>( item ) )
1179  aCollector.Remove( item );
1180  }
1181  },
1182  true /* prompt user regarding locked items */ );
1183 
1184  if( selection.Size() < 2 )
1185  {
1186  frame()->ShowInfoBarMsg( _( "At least two straight track segments must be selected." ) );
1187  return 0;
1188  }
1189 
1190  WX_UNIT_ENTRY_DIALOG dia( frame(), _( "Enter fillet radius:" ), _( "Fillet Tracks" ),
1191  filletRadiusIU );
1192 
1193  if( dia.ShowModal() == wxID_CANCEL )
1194  return 0;
1195 
1196  filletRadiusIU = dia.GetValue();
1197 
1198  if( filletRadiusIU == 0 )
1199  {
1200  frame()->ShowInfoBarMsg( _( "A radius of zero was entered.\n"
1201  "The fillet operation was not performed." ) );
1202  return 0;
1203  }
1204 
1205  struct FILLET_OP
1206  {
1207  PCB_TRACK* t1;
1208  PCB_TRACK* t2;
1209  // Start point of track is modified after PCB_ARC is added, otherwise the end point:
1210  bool t1Start = true;
1211  bool t2Start = true;
1212  };
1213 
1214  std::vector<FILLET_OP> filletOperations;
1215  KICAD_T track_types[] = { PCB_PAD_T, PCB_VIA_T, PCB_TRACE_T, PCB_ARC_T, EOT };
1216  bool operationPerformedOnAtLeastOne = false;
1217  bool didOneAttemptFail = false;
1218  std::set<PCB_TRACK*> processedTracks;
1219 
1220  for( auto it = selection.begin(); it != selection.end(); it++ )
1221  {
1222  PCB_TRACK* track = dyn_cast<PCB_TRACK*>( *it );
1223 
1224  if( !track || track->Type() != PCB_TRACE_T || track->GetLength() == 0 )
1225  {
1226  continue;
1227  }
1228 
1229  auto processFilletOp =
1230  [&]( bool aStartPoint )
1231  {
1232  std::shared_ptr<CONNECTIVITY_DATA> connectivity = board()->GetConnectivity();
1233  wxPoint anchor = ( aStartPoint ) ? track->GetStart() : track->GetEnd();
1234  auto itemsOnAnchor = connectivity->GetConnectedItemsAtAnchor( track, anchor,
1235  track_types );
1236 
1237  if( itemsOnAnchor.size() > 0
1238  && selection.Contains( itemsOnAnchor.at( 0 ) )
1239  && itemsOnAnchor.at( 0 )->Type() == PCB_TRACE_T )
1240  {
1241  PCB_TRACK* trackOther = dyn_cast<PCB_TRACK*>( itemsOnAnchor.at( 0 ) );
1242 
1243  // Make sure we don't fillet the same pair of tracks twice
1244  if( processedTracks.find( trackOther ) == processedTracks.end() )
1245  {
1246  if( itemsOnAnchor.size() == 1 )
1247  {
1248  FILLET_OP filletOp;
1249  filletOp.t1 = track;
1250  filletOp.t2 = trackOther;
1251  filletOp.t1Start = aStartPoint;
1252  filletOp.t2Start = track->IsPointOnEnds( filletOp.t2->GetStart() );
1253  filletOperations.push_back( filletOp );
1254  }
1255  else
1256  {
1257  // User requested to fillet these two tracks but not possible as
1258  // there are other elements connected at that point
1259  didOneAttemptFail = true;
1260  }
1261  }
1262  }
1263  };
1264 
1265  processFilletOp( true ); // on the start point of track
1266  processFilletOp( false ); // on the end point of track
1267 
1268  processedTracks.insert( track );
1269  }
1270 
1271  std::vector<BOARD_ITEM*> itemsToAddToSelection;
1272 
1273  for( FILLET_OP filletOp : filletOperations )
1274  {
1275  PCB_TRACK* track1 = filletOp.t1;
1276  PCB_TRACK* track2 = filletOp.t2;
1277 
1278  bool trackOnStart = track1->IsPointOnEnds( track2->GetStart() );
1279  bool trackOnEnd = track1->IsPointOnEnds( track2->GetEnd() );
1280 
1281  if( trackOnStart && trackOnEnd )
1282  continue; // Ignore duplicate tracks
1283 
1284  if( ( trackOnStart || trackOnEnd ) && track1->GetLayer() == track2->GetLayer() )
1285  {
1286  SEG t1Seg( track1->GetStart(), track1->GetEnd() );
1287  SEG t2Seg( track2->GetStart(), track2->GetEnd() );
1288 
1289  if( t1Seg.ApproxCollinear( t2Seg ) )
1290  continue;
1291 
1292  SHAPE_ARC sArc( t1Seg, t2Seg, filletRadiusIU );
1293 
1294  wxPoint t1newPoint, t2newPoint;
1295 
1296  auto setIfPointOnSeg =
1297  []( wxPoint& aPointToSet, SEG aSegment, VECTOR2I aVecToTest )
1298  {
1299  VECTOR2I segToVec = aSegment.NearestPoint( aVecToTest ) - aVecToTest;
1300 
1301  // Find out if we are on the segment (minimum precision)
1302  if( segToVec.EuclideanNorm() < SHAPE_ARC::MIN_PRECISION_IU )
1303  {
1304  aPointToSet.x = aVecToTest.x;
1305  aPointToSet.y = aVecToTest.y;
1306  return true;
1307  }
1308 
1309  return false;
1310  };
1311 
1312  //Do not draw a fillet if the end points of the arc are not within the track segments
1313  if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP0() )
1314  && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP0() ) )
1315  {
1316  didOneAttemptFail = true;
1317  continue;
1318  }
1319 
1320  if( !setIfPointOnSeg( t1newPoint, t1Seg, sArc.GetP1() )
1321  && !setIfPointOnSeg( t2newPoint, t2Seg, sArc.GetP1() ) )
1322  {
1323  didOneAttemptFail = true;
1324  continue;
1325  }
1326 
1327  PCB_ARC* tArc = new PCB_ARC( frame()->GetBoard(), &sArc );
1328  tArc->SetLayer( track1->GetLayer() );
1329  tArc->SetWidth( track1->GetWidth() );
1330  tArc->SetNet( track1->GetNet() );
1331  tArc->SetLocked( track1->IsLocked() );
1332  m_commit->Add( tArc );
1333  itemsToAddToSelection.push_back( tArc );
1334 
1335  m_commit->Modify( track1 );
1336  m_commit->Modify( track2 );
1337 
1338  if( filletOp.t1Start )
1339  track1->SetStart( t1newPoint );
1340  else
1341  track1->SetEnd( t1newPoint );
1342 
1343  if( filletOp.t2Start )
1344  track2->SetStart( t2newPoint );
1345  else
1346  track2->SetEnd( t2newPoint );
1347 
1348  operationPerformedOnAtLeastOne = true;
1349  }
1350  }
1351 
1352  m_commit->Push( _( "Fillet Tracks" ) );
1353 
1354  //select the newly created arcs
1355  for( BOARD_ITEM* item : itemsToAddToSelection )
1356  m_selectionTool->AddItemToSel( item );
1357 
1358  if( !operationPerformedOnAtLeastOne )
1359  frame()->ShowInfoBarMsg( _( "Unable to fillet the selected track segments." ) );
1360  else if( didOneAttemptFail )
1361  frame()->ShowInfoBarMsg( _( "Some of the track segments could not be filleted." ) );
1362 
1363  return 0;
1364 }
BOARD * board() const
const wxPoint & GetEnd() const
Definition: pcb_track.h:105
virtual void SetLayer(PCB_LAYER_ID aLayer)
Set the layer this item is on.
Definition: board_item.h:164
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void SetEnd(const wxPoint &aEnd)
Definition: pcb_track.h:104
NETINFO_ITEM * GetNet() const
Return #NET_INFO object for a given item.
virtual double GetLength() const
Function GetLength returns the length of the track using the hypotenuse calculation.
Definition: pcb_track.cpp:259
ITER end()
Definition: selection.h:65
class PCB_ARC, an arc track segment on a copper layer
Definition: typeinfo.h:97
class PAD, a pad in a footprint
Definition: typeinfo.h:89
virtual void SetLocked(bool aLocked)
Modify the 'lock' status for of the item.
Definition: board_item.h:218
int GetWidth() const
Definition: pcb_track.h:102
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
virtual bool IsLocked() const
Definition: board_item.cpp:64
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
search types array terminator (End Of Types)
Definition: typeinfo.h:81
KICAD_T
The set of class identification values stored in EDA_ITEM::m_structType.
Definition: typeinfo.h:77
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PCB_BASE_EDIT_FRAME * frame() const
void ShowInfoBarMsg(const wxString &aMsg, bool aShowCloseButton=false)
Show the WX_INFOBAR displayed on the top of the canvas with a message and an info icon on the left of...
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
ITER begin()
Definition: selection.h:64
const PCB_SELECTION & selection() const
An extension of WX_TEXT_ENTRY_DIALOG that uses UNIT_BINDER to request a dimension (e....
void AddItemToSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Select all items on the board.
static const int MIN_PRECISION_IU
This is the minimum precision for all the points in a shape.
Definition: shape.h:122
bool Contains(EDA_ITEM *aItem) const
Definition: selection.cpp:62
std::shared_ptr< CONNECTIVITY_DATA > GetConnectivity() const
Return a list of missing connections between components/tracks.
Definition: board.h:345
void SetStart(const wxPoint &aStart)
Definition: pcb_track.h:107
#define _(s)
BOARD * GetBoard()
Definition: seg.h:40
void SetWidth(int aWidth)
Definition: pcb_track.h:101
void SetNet(NETINFO_ITEM *aNetInfo)
Set a NET_INFO object for the item.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
EDA_ITEM_FLAGS IsPointOnEnds(const wxPoint &point, int min_dist=0) const
Function IsPointOnEnds returns STARTPOINT if point if near (dist = min_dist) start point,...
Definition: pcb_track.cpp:181
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
The selection tool: currently supports:
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
Definition: vector2d.h:293
virtual PCB_LAYER_ID GetLayer() const
Return the primary layer this item is on.
Definition: board_item.h:143
const wxPoint & GetStart() const
Definition: pcb_track.h:108
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, PCB_SELECTION_TOOL::AddItemToSel(), anchor, SELECTION::begin(), PCB_TOOL_BASE::board(), SELECTION::Contains(), SELECTION::end(), EOT, VECTOR2< T >::EuclideanNorm(), PCB_TOOL_BASE::frame(), GetBoard(), BOARD::GetConnectivity(), COLLECTOR::GetCount(), PCB_TRACK::GetEnd(), BOARD_ITEM::GetLayer(), PCB_TRACK::GetLength(), BOARD_CONNECTED_ITEM::GetNet(), SHAPE_ARC::GetP0(), SHAPE_ARC::GetP1(), PCB_TRACK::GetStart(), WX_UNIT_ENTRY_DIALOG::GetValue(), PCB_TRACK::GetWidth(), BOARD_ITEM::IsLocked(), PCB_TRACK::IsPointOnEnds(), m_commit, m_selectionTool, SHAPE::MIN_PRECISION_IU, PCB_ARC_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, COLLECTOR::Remove(), PCB_SELECTION_TOOL::RequestSelection(), PCB_TOOL_BASE::selection(), PCB_TRACK::SetEnd(), BOARD_ITEM::SetLayer(), BOARD_ITEM::SetLocked(), BOARD_CONNECTED_ITEM::SetNet(), PCB_TRACK::SetStart(), PCB_TRACK::SetWidth(), EDA_BASE_FRAME::ShowInfoBarMsg(), SELECTION::Size(), EDA_ITEM::Type(), and VECTOR2< T >::x.

Referenced by setTransitions().

◆ Flip()

int EDIT_TOOL::Flip ( const TOOL_EVENT aEvent)

Rotate currently selected items.

The rotation point is the current cursor position.

Definition at line 1667 of file edit_tool.cpp.

1668 {
1669  if( isRouterActive() )
1670  {
1671  wxBell();
1672  return 0;
1673  }
1674 
1676  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1677  {
1678  sTool->FilterCollectorForMarkers( aCollector );
1679  sTool->FilterCollectorForHierarchy( aCollector, true );
1680  sTool->FilterCollectorForFreePads( aCollector );
1681  },
1682  !m_dragging /* prompt user regarding locked items */ );
1683 
1684  if( selection.Empty() )
1685  return 0;
1686 
1687  OPT<VECTOR2I> oldRefPt = boost::make_optional<VECTOR2I>( false, VECTOR2I( 0, 0 ) );
1688 
1690  oldRefPt = selection.GetReferencePoint();
1691 
1693 
1694  // Flip around the anchor for footprints, and the bounding box center for board items
1695  VECTOR2I refPt = IsFootprintEditor() ? VECTOR2I( 0, 0 ) : selection.GetCenter();
1696 
1697  // If only one item selected, flip around the selection or item anchor point (instead
1698  // of the bounding box center) to avoid moving the item anchor
1699  if( selection.GetSize() == 1 )
1700  {
1702  refPt = selection.GetReferencePoint();
1703  else
1704  refPt = static_cast<BOARD_ITEM*>( selection.GetItem( 0 ) )->GetPosition();
1705  }
1706 
1707  bool leftRight = frame()->Settings().m_FlipLeftRight;
1708 
1709  // When editing footprints, all items have the same parent
1710  if( IsFootprintEditor() )
1711  m_commit->Modify( selection.Front() );
1712 
1713  for( EDA_ITEM* item : selection )
1714  {
1715  if( !item->IsNew() && !IsFootprintEditor() )
1716  m_commit->Modify( item );
1717 
1718  if( item->Type() == PCB_GROUP_T )
1719  {
1720  static_cast<PCB_GROUP*>( item )->RunOnDescendants( [&]( BOARD_ITEM* bItem )
1721  {
1722  m_commit->Modify( bItem );
1723  });
1724  }
1725 
1726  static_cast<BOARD_ITEM*>( item )->Flip( refPt, leftRight );
1727  }
1728 
1729  if( !m_dragging )
1730  m_commit->Push( _( "Change Side / Flip" ) );
1731 
1732  if( selection.IsHover() && !m_dragging )
1734 
1736 
1737  if( m_dragging )
1739 
1740  // Restore the old reference so any mouse dragging that occurs doesn't make the selection jump
1741  // to this now invalid reference
1742  if( oldRefPt )
1743  selection.SetReferencePoint( *oldRefPt );
1744  else
1746 
1747  return 0;
1748 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
VECTOR2I GetReferencePoint() const
Definition: selection.h:184
void ClearReferencePoint()
Definition: selection.h:197
bool IsHover() const
Definition: selection.h:74
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector) const
Check the "allow free pads" setting and if disabled, upgrade any pad selection to the selection of it...
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
PCB_BASE_EDIT_FRAME * frame() const
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:192
const PCB_SELECTION & selection() const
bool updateModificationPoint(PCB_SELECTION &aSelection)
Definition: edit_tool.cpp:2269
bool m_dragging
Definition: edit_tool.h:191
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
#define _(s)
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
virtual unsigned int GetSize() const override
Return the number of stored items.
Definition: selection.h:88
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
bool HasReferencePoint() const
Definition: selection.h:179
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
virtual KIGFX::VIEW_ITEM * GetItem(unsigned int aIdx) const override
Definition: selection.cpp:53
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
PCBNEW_SETTINGS & Settings()
bool isRouterActive() const
Definition: edit_tool.cpp:266
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
bool IsFootprintEditor() const
boost::optional< T > OPT
Definition: optional.h:7
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:462
EDA_ITEM * Front() const
Definition: selection.h:145

References _, SELECTION::ClearReferencePoint(), SELECTION::Empty(), PCB_SELECTION_TOOL::FilterCollectorForFreePads(), PCB_SELECTION_TOOL::FilterCollectorForHierarchy(), PCB_SELECTION_TOOL::FilterCollectorForMarkers(), PCB_TOOL_BASE::frame(), SELECTION::Front(), SELECTION::GetCenter(), SELECTION::GetItem(), SELECTION::GetReferencePoint(), SELECTION::GetSize(), SELECTION::HasReferencePoint(), PCB_TOOL_BASE::IsFootprintEditor(), SELECTION::IsHover(), isRouterActive(), m_commit, m_dragging, PCBNEW_SETTINGS::m_FlipLeftRight, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_GROUP_T, TOOL_MANAGER::ProcessEvent(), PCB_SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, SELECTION::SetReferencePoint(), PCB_BASE_FRAME::Settings(), PCB_ACTIONS::updateLocalRatsnest, and updateModificationPoint().

Referenced by setTransitions().

◆ footprint()

◆ FootprintFilter()

void EDIT_TOOL::FootprintFilter ( const VECTOR2I ,
GENERAL_COLLECTOR aCollector,
PCB_SELECTION_TOOL sTool 
)
static

A selection filter which prunes the selection to contain only items of type #PCB_MODULE_T.

Definition at line 2256 of file edit_tool.cpp.

2258 {
2259  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
2260  {
2261  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
2262 
2263  if( item->Type() != PCB_FOOTPRINT_T )
2264  aCollector.Remove( i );
2265  }
2266 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References COLLECTOR::GetCount(), PCB_FOOTPRINT_T, COLLECTOR::Remove(), and EDA_ITEM::Type().

Referenced by BOARD_EDITOR_CONTROL::EditFpInFpEditor(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), and BOARD_INSPECTION_TOOL::LocalRatsnestTool().

◆ frame()

PCB_BASE_EDIT_FRAME* PCB_TOOL_BASE::frame ( ) const
inlineprotectedinherited

Definition at line 160 of file pcb_tool_base.h.

161  {
162  return getEditFrame<PCB_BASE_EDIT_FRAME>();
163  }

Referenced by PCB_POINT_EDITOR::addCorner(), AUTOPLACE_TOOL::autoplace(), PCB_TOOL_BASE::canvas(), ZONE_FILLER_TOOL::CheckAllZones(), PNS::TOOL_BASE::checkSnap(), PAD_TOOL::copyPadSettings(), copyToClipboard(), BOARD_INSPECTION_TOOL::CrossProbePcbToSch(), ROUTER_TOOL::CustomTrackWidthDialog(), FOOTPRINT_EDITOR_CONTROL::DeleteFootprint(), PCB_TOOL_BASE::displayOptions(), PCB_TOOL_BASE::doInteractiveItemPlacement(), doMoveSelection(), ROUTER_TOOL::DpDimensionsDialog(), DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::DrawVia(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EditPad(), PAD_TOOL::EnumeratePads(), PAD_TOOL::explodePad(), BOARD_EDITOR_CONTROL::ExportSpecctraDSN(), ZONE_FILLER_TOOL::FillAllZones(), FilletTracks(), PCB_SELECTION_TOOL::FilterCollectorForFreePads(), ROUTER_TOOL::finishInteractive(), Flip(), PCB_CONTROL::FlipPcbView(), GLOBAL_EDIT_TOOL::GlobalDeletions(), ROUTER_TOOL::handleLayerSwitch(), BOARD_INSPECTION_TOOL::HighlightItem(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), BOARD_EDITOR_CONTROL::ImportSpecctraSession(), ROUTER_TOOL::Init(), SCRIPTING_TOOL::Init(), PCB_SELECTION_TOOL::Init(), Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), DRAWING_TOOL::InteractivePlaceWithPreview(), PCB_TOOL_BASE::Is45Limited(), PCB_PICKER_TOOL::Main(), PCB_SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::meanderSettingsDialog(), MoveExact(), PCB_POINT_EDITOR::OnSelectionChange(), PCB_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), GROUP_TOOL::PickNewMember(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), BOARD_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), ROUTER_TOOL::prepareInteractive(), PAD_TOOL::pushPadSettings(), PAD_TOOL::recombinePad(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), SCRIPTING_TOOL::reloadPlugins(), Remove(), PCB_POINT_EDITOR::removeCorner(), PCB_SELECTION_TOOL::RequestSelection(), PAD_TOOL::Reset(), PNS::TOOL_BASE::Reset(), Rotate(), ROUTER_TOOL::SelectCopperLayerPair(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), PCB_POINT_EDITOR::setEditedPoint(), ROUTER_TOOL::SettingsDialog(), GLOBAL_EDIT_TOOL::swapBoardItem(), GLOBAL_EDIT_TOOL::SwapLayers(), ROUTER_TOOL::switchLayerOnViaPlacement(), PCB_CONTROL::unfilledZoneCheck(), ROUTER_TOOL::UpdateMessagePanel(), updateModificationPoint(), BOARD_EDITOR_CONTROL::UpdateSchematicFromPCB(), ZONE_FILLER_TOOL::ZoneFill(), and ZONE_FILLER_TOOL::ZoneFillAll().

◆ GetAndPlace()

int EDIT_TOOL::GetAndPlace ( const TOOL_EVENT aEvent)

Definition at line 212 of file edit_tool.cpp.

213 {
214  // GetAndPlace makes sense only in board editor, although it is also called
215  // in fpeditor, that shares the same EDIT_TOOL list
216  if( !getEditFrame<PCB_BASE_FRAME>()->IsType( FRAME_PCB_EDITOR ) )
217  return 0;
218 
220  FOOTPRINT* fp = getEditFrame<PCB_BASE_FRAME>()->GetFootprintFromBoardByReference();
221 
222  if( fp )
223  {
225  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, (void*) fp );
226 
227  selectionTool->GetSelection().SetReferencePoint( fp->GetPosition() );
229  }
230 
231  return 0;
232 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:92
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:192
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
The selection tool: currently supports:

References FRAME_PCB_EDITOR, PCB_SELECTION_TOOL::GetSelection(), TOOL_MANAGER::GetTool(), TOOL_BASE::m_toolMgr, PCB_ACTIONS::move, TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, and SELECTION::SetReferencePoint().

Referenced by setTransitions().

◆ GetCurrentCommit()

BOARD_COMMIT* EDIT_TOOL::GetCurrentCommit ( ) const
inline

Definition at line 158 of file edit_tool.h.

158 { return m_commit.get(); }
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190

References m_commit.

◆ getEditFrame()

template<typename T >
T* TOOL_BASE::getEditFrame ( ) const
inlineprotectedinherited

Return the application window object, casted to requested user type.

Definition at line 184 of file tool_base.h.

185  {
186 #if !defined( QA_TEST ) // Dynamic casts give the linker a seizure in the test framework
187  wxASSERT( dynamic_cast<T*>( getToolHolderInt() ) );
188 #endif
189  return static_cast<T*>( getToolHolderInt() );
190  }
TOOLS_HOLDER * getToolHolderInt() const
Definition: tool_base.cpp:48

References TOOL_BASE::getToolHolderInt().

Referenced by ZONE_CREATE_HELPER::createNewZone().

◆ GetId()

TOOL_ID TOOL_BASE::GetId ( ) const
inlineinherited

Return the unique identifier of the tool.

The identifier is set by an instance of TOOL_MANAGER.

Returns
Identifier of the tool.

Definition at line 120 of file tool_base.h.

121  {
122  return m_toolId;
123  }
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209

References TOOL_BASE::m_toolId.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::isActive(), TOOL_MANAGER::RegisterTool(), ACTION_MANAGER::RunHotKey(), TOOL_MANAGER::runTool(), TOOL_MANAGER::saveViewControls(), and TOOL_MANAGER::ShutdownTool().

◆ GetManager()

TOOL_MANAGER* TOOL_BASE::GetManager ( ) const
inlineinherited

Return the instance of TOOL_MANAGER that takes care of the tool.

Returns
Instance of the TOOL_MANAGER or NULL if there is no associated tool manager.

Definition at line 143 of file tool_base.h.

144  {
145  return m_toolMgr;
146  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214

References TOOL_BASE::m_toolMgr.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), ZONE_CREATE_HELPER::commitZone(), ZONE_CREATE_HELPER::createNewZone(), PCB_TOOL_BASE::doInteractiveItemPlacement(), ACTION_MENU::getToolManager(), LIB_TREE::onContextMenu(), ZONE_CREATE_HELPER::OnFirstPoint(), ACTION_MENU::OnMenuEvent(), and ZONE_CREATE_HELPER::performZoneCutout().

◆ getModel()

template<typename T >
T* TOOL_BASE::getModel ( ) const
inlineprotectedinherited

Return the model object if it matches the requested type.

Store the type of the tool.

Definition at line 196 of file tool_base.h.

References TOOL_BASE::getModelInt().

Referenced by ZONE_CREATE_HELPER::commitZone(), and ZONE_CREATE_HELPER::createZoneFromExisting().

◆ GetName()

const std::string& TOOL_BASE::GetName ( void  ) const
inlineinherited

Return the name of the tool.

Tool names are expected to obey the format: application.ToolName (eg. pcbnew.InteractiveSelection).

Returns
The name of the tool.

Definition at line 133 of file tool_base.h.

134  {
135  return m_toolName;
136  }
std::string m_toolName
Definition: tool_base.h:213

References TOOL_BASE::m_toolName.

Referenced by TOOL_MANAGER::dispatchInternal(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::invokeTool(), TOOL_MANAGER::RegisterTool(), and TOOL_MANAGER::runTool().

◆ GetToolMenu()

◆ GetType()

TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Return the type of the tool.

Returns
The type of the tool.

Definition at line 108 of file tool_base.h.

109  {
110  return m_type;
111  }
TOOL_TYPE m_type
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:206

References TOOL_BASE::m_type.

Referenced by TOOL_MANAGER::finishTool(), TOOL_MANAGER::InvokeTool(), TOOL_MANAGER::ResetTools(), TOOL_MANAGER::runTool(), and TOOL_MANAGER::ShutdownTool().

◆ getView()

KIGFX::VIEW * TOOL_BASE::getView ( ) const
protectedinherited

Returns the instance of #VIEW object used in the application.

It allows tools to draw.

Returns
The instance of VIEW.

Definition at line 36 of file tool_base.cpp.

37 {
38  return m_toolMgr->GetView();
39 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:283
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214

References TOOL_MANAGER::GetView(), and TOOL_BASE::m_toolMgr.

Referenced by EE_POINT_EDITOR::addCornerCondition(), ALIGN_DISTRIBUTE_TOOL::AlignLeft(), ALIGN_DISTRIBUTE_TOOL::AlignRight(), COMMON_TOOLS::CenterContents(), SCH_EDIT_TOOL::ChangeTextType(), EE_INSPECTION_TOOL::CheckSymbol(), GERBVIEW_CONTROL::ClearAllLayers(), PL_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::ClearSelection(), EE_SELECTION_TOOL::CollectHits(), SCH_LINE_WIRE_BUS_TOOL::computeBreakPoint(), COMMON_TOOLS::CursorControl(), PL_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCB_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), PL_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), doMoveSelection(), PL_SELECTION_TOOL::doSelectionMenu(), EE_SELECTION_TOOL::doSelectionMenu(), PCB_SELECTION_TOOL::doSelectionMenu(), COMMON_TOOLS::doZoomFit(), COMMON_TOOLS::doZoomInOut(), COMMON_TOOLS::doZoomToPreset(), DragArcTrack(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), PL_DRAWING_TOOLS::DrawShape(), DRAWING_TOOL::DrawZone(), BOARD_EDITOR_CONTROL::DrillOrigin(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_EDITOR_CONTROL::FindSymbolAndItem(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), PCB_CONTROL::GridResetOrigin(), PCB_CONTROL::GridSetOrigin(), ROUTER_TOOL::handleCommonEvents(), PL_SELECTION_TOOL::highlight(), EE_SELECTION_TOOL::highlight(), PCB_SELECTION_TOOL::highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), BOARD_INSPECTION_TOOL::highlightNet(), PCB_SELECTION_TOOL::hitTestDistance(), SCH_EDIT_TOOL::Init(), Init(), ROUTER_TOOL::InlineDrag(), PCB_PICKER_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), SCH_EDIT_TOOL::Mirror(), MoveExact(), PL_EDIT_TOOL::moveItem(), SCH_MOVE_TOOL::moveItem(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), PL_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), ROUTER_TOOL::performRouting(), PNS::TOOL_BASE::pickSingleItem(), BOARD_EDITOR_CONTROL::PlaceFootprint(), PL_DRAWING_TOOLS::PlaceItem(), BOARD_EDITOR_CONTROL::PlaceTarget(), ROUTER_TOOL::prepareInteractive(), SCH_EDIT_TOOL::Properties(), Properties(), Remove(), BOARD_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCB_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), DRAWING_TOOL::Reset(), EE_SELECTION_TOOL::Reset(), PCB_SELECTION_TOOL::Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), GERBVIEW_SELECTION_TOOL::selectable(), PCB_SELECTION_TOOL::Selectable(), PCB_SELECTION_TOOL::SelectAll(), EE_SELECTION_TOOL::SelectAll(), PL_SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectionContains(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), PL_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), SCH_EDITOR_CONTROL::ToggleHiddenFields(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), PL_SELECTION_TOOL::unhighlight(), EE_SELECTION_TOOL::unhighlight(), PCB_SELECTION_TOOL::unhighlight(), GERBVIEW_SELECTION_TOOL::unselect(), GERBVIEW_SELECTION_TOOL::unselectVisually(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateEditedPoint(), SCH_EDITOR_CONTROL::UpdateFind(), PL_POINT_EDITOR::updateItem(), PCB_POINT_EDITOR::updateItem(), EE_TOOL_BASE< SCH_BASE_FRAME >::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updatePoints(), PL_POINT_EDITOR::updatePoints(), PCB_POINT_EDITOR::updatePoints(), PCB_SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), PCB_VIEWER_TOOLS::view(), PCB_TOOL_BASE::view(), PCB_SELECTION_TOOL::zoomFitSelection(), EE_SELECTION_TOOL::~EE_SELECTION_TOOL(), GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL(), and PCB_SELECTION_TOOL::~PCB_SELECTION_TOOL().

◆ getViewControls()

KIGFX::VIEW_CONTROLS * TOOL_BASE::getViewControls ( ) const
protectedinherited

Return the instance of VIEW_CONTROLS object used in the application.

It allows tools to read & modify user input and its settings (eg. show cursor, enable snapping to grid, etc.).

Returns
The instance of VIEW_CONTROLS.

Definition at line 42 of file tool_base.cpp.

43 {
44  return m_toolMgr->GetViewControls();
45 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
KIGFX::VIEW_CONTROLS * GetViewControls() const
Definition: tool_manager.h:285

References TOOL_MANAGER::GetViewControls(), and TOOL_BASE::m_toolMgr.

Referenced by EE_POINT_EDITOR::addCorner(), PCB_POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDITOR_CONTROL::AssignNetclass(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), copyToClipboard(), SCH_DRAWING_TOOLS::createSheetPin(), COMMON_TOOLS::CursorControl(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), doMoveSelection(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), COMMON_TOOLS::doZoomToPreset(), DragArcTrack(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::DrawRectangle(), SYMBOL_EDITOR_DRAWING_TOOLS::DrawShape(), PL_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), SYMBOL_EDITOR_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), SCH_DRAWING_TOOLS::GetCanvasFreeAreaPixels(), BOARD_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), FOOTPRINT_EDITOR_CONTROL::ImportFootprint(), SCH_EDIT_TOOL::Init(), Init(), PCB_PICKER_TOOL::Main(), EE_POINT_EDITOR::Main(), PL_EDIT_TOOL::Main(), SYMBOL_EDITOR_MOVE_TOOL::Main(), PL_POINT_EDITOR::Main(), SCH_MOVE_TOOL::Main(), EE_SELECTION_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), GERBVIEW_INSPECTION_TOOL::MeasureTool(), PCB_VIEWER_TOOLS::MeasureTool(), COMMON_TOOLS::OnGridChanged(), PCB_POINT_EDITOR::OnSelectionChange(), SYMBOL_EDITOR_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LENGTH_TUNER_TOOL::performTuning(), SYMBOL_EDITOR_DRAWING_TOOLS::PlaceAnchor(), PCB_CONTROL::placeBoardItems(), BOARD_EDITOR_CONTROL::PlaceFootprint(), SCH_DRAWING_TOOLS::PlaceImage(), PL_DRAWING_TOOLS::PlaceItem(), SCH_DRAWING_TOOLS::PlaceSymbol(), BOARD_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), Properties(), Remove(), SCH_EDIT_TOOL::RepeatDrawItem(), PL_SELECTION_TOOL::RequestSelection(), EE_SELECTION_TOOL::RequestSelection(), PCB_POINT_EDITOR::Reset(), DRAWING_TOOL::Reset(), COMMON_TOOLS::ResetLocalCoords(), GERBVIEW_SELECTION_TOOL::selectCursor(), PCB_SELECTION_TOOL::selectCursor(), PL_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::selectMultiple(), PCB_SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), ALIGN_DISTRIBUTE_TOOL::selectTarget(), PCB_PICKER_TOOL::setControls(), PICKER_TOOL::setControls(), PL_POINT_EDITOR::setEditedPoint(), EE_POINT_EDITOR::setEditedPoint(), PCB_POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), SYMBOL_EDITOR_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), EE_POINT_EDITOR::updateEditedPoint(), PL_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateEditedPoint(), PCB_POINT_EDITOR::updateItem(), PL_EDIT_TOOL::updateModificationPoint(), and COMMON_TOOLS::ZoomCenter().

◆ Go()

template<class T >
void TOOL_INTERACTIVE::Go ( int(T::*)(const TOOL_EVENT &)  aStateFunc,
const TOOL_EVENT_LIST aConditions = TOOL_EVENTTC_ANYTA_ANY ) 
)
inherited

Define which state (aStateFunc) to go when a certain event arrives (aConditions).

No conditions means any event.

Definition at line 147 of file tool_interactive.h.

149 {
150  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
151 
152  goInternal( sptr, aConditions );
153 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)

References TOOL_INTERACTIVE::goInternal().

Referenced by AUTOPLACE_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), LENGTH_TUNER_TOOL::setTransitions(), BOARD_REANNOTATE_TOOL::setTransitions(), GERBVIEW_INSPECTION_TOOL::setTransitions(), PCB_PICKER_TOOL::setTransitions(), SCH_NAVIGATE_TOOL::setTransitions(), SYMBOL_EDITOR_PIN_TOOL::setTransitions(), SYMBOL_EDITOR_MOVE_TOOL::setTransitions(), PL_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), PL_POINT_EDITOR::setTransitions(), ROUTER_TOOL::setTransitions(), SCRIPTING_TOOL::setTransitions(), COMMON_CONTROL::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), CONVERT_TOOL::setTransitions(), SYMBOL_EDITOR_DRAWING_TOOLS::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), PCB_VIEWER_TOOLS::setTransitions(), MICROWAVE_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), PCB_POINT_EDITOR::setTransitions(), GERBVIEW_CONTROL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), PAD_TOOL::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), GROUP_TOOL::setTransitions(), PL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_CONTROL::setTransitions(), SYMBOL_EDITOR_EDIT_TOOL::setTransitions(), PL_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), SCH_EDIT_TOOL::setTransitions(), FOOTPRINT_EDITOR_CONTROL::setTransitions(), ALIGN_DISTRIBUTE_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), DRC_TOOL::setTransitions(), EDA_3D_CONTROLLER::setTransitions(), PCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), BOARD_INSPECTION_TOOL::setTransitions(), BOARD_EDITOR_CONTROL::setTransitions(), PICKER_TOOL::setTransitions(), setTransitions(), PCB_SELECTION_TOOL::setTransitions(), PL_SELECTION_TOOL::setTransitions(), DRAWING_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), and EE_SELECTION_TOOL::setTransitions().

◆ Init()

bool EDIT_TOOL::Init ( )
overridevirtual

Init() is called once upon a registration of the tool.

Returns
True if the initialization went fine, false - otherwise. Find an item and start moving.

Reimplemented from PCB_TOOL_BASE.

Definition at line 100 of file edit_tool.cpp.

101 {
102  // Find the selection tool, so they can cooperate
104 
105  auto propertiesCondition =
106  [&]( const SELECTION& aSel )
107  {
108  if( aSel.GetSize() == 0 )
109  {
111  {
114 
115  if( ds && ds->HitTestDrawingSheetItems( getView(), (wxPoint) cursor ) )
116  return true;
117  }
118 
119  return false;
120  }
121 
122  if( aSel.GetSize() == 1 )
123  return true;
124 
125  for( EDA_ITEM* item : aSel )
126  {
127  if( !dynamic_cast<PCB_TRACK*>( item ) )
128  return false;
129  }
130 
131  return true;
132  };
133 
134  auto inFootprintEditor =
135  [ this ]( const SELECTION& aSelection )
136  {
137  return m_isFootprintEditor;
138  };
139 
140  auto singleFootprintCondition = SELECTION_CONDITIONS::OnlyType( PCB_FOOTPRINT_T )
142 
143  auto noActiveToolCondition =
144  [ this ]( const SELECTION& aSelection )
145  {
146  return frame()->ToolStackIsEmpty();
147  };
148 
149  auto notMovingCondition =
150  [ this ]( const SELECTION& aSelection )
151  {
154  };
155 
156  auto noItemsCondition =
157  [ this ]( const SELECTION& aSelections ) -> bool
158  {
159  return frame()->GetBoard() && !frame()->GetBoard()->IsEmpty();
160  };
161 
162  // Add context menu entries that are displayed when selection tool is active
164 
166  && notMovingCondition );
178  menu.AddItem( PCB_ACTIONS::mirror, inFootprintEditor && SELECTION_CONDITIONS::NotEmpty );
179 
180  menu.AddItem( PCB_ACTIONS::properties, propertiesCondition );
181 
182  // Footprint actions
183  menu.AddSeparator();
184  menu.AddItem( PCB_ACTIONS::editFpInFpEditor, singleFootprintCondition );
185  menu.AddItem( PCB_ACTIONS::updateFootprint, singleFootprintCondition );
186  menu.AddItem( PCB_ACTIONS::changeFootprint, singleFootprintCondition );
187 
188  // Add the submenu for create array and special move
189  auto specialToolsSubMenu = std::make_shared<SPECIAL_TOOLS_CONTEXT_MENU>( this );
190  menu.AddSeparator();
191  m_selectionTool->GetToolMenu().AddSubMenu( specialToolsSubMenu );
192  menu.AddMenu( specialToolsSubMenu.get(), SELECTION_CONDITIONS::NotEmpty, 100 );
193 
194  menu.AddSeparator( 150 );
197 
198  // Selection tool handles the context menu for some other tools, such as the Picker.
199  // Don't add things like Paste when another tool is active.
200  menu.AddItem( ACTIONS::paste, noActiveToolCondition, 150 );
201  menu.AddItem( ACTIONS::pasteSpecial, noActiveToolCondition && !inFootprintEditor, 150 );
204 
205  menu.AddSeparator( 150 );
206  menu.AddItem( ACTIONS::selectAll, noItemsCondition, 150 );
207 
208  return true;
209 }
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Add a submenu to the menu.
bool IsCurrentTool(const TOOL_ACTION &aAction) const
static TOOL_ACTION move
move or drag an item
Definition: pcb_actions.h:92
static const KICAD_T Tracks[]
A scan list for only TRACKs.
Definition: collectors.h:298
static TOOL_ACTION editFpInFpEditor
Definition: pcb_actions.h:344
static TOOL_ACTION doDelete
Definition: actions.h:72
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Create a functor that tests if the selected items are only of given types.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
CONDITIONAL_MENU & GetMenu()
Definition: tool_menu.cpp:46
static TOOL_ACTION dragFreeAngle
Definition: pcb_actions.h:135
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:117
TOOL_MENU & GetToolMenu()
static TOOL_ACTION drag45Degree
Definition: pcb_actions.h:134
static TOOL_ACTION mirror
Mirroring of selected items.
Definition: pcb_actions.h:108
static TOOL_ACTION changeFootprint
Definition: pcb_actions.h:324
bool HitTestDrawingSheetItems(KIGFX::VIEW *aView, const wxPoint &aPosition)
static TOOL_ACTION updateFootprint
Definition: pcb_actions.h:322
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
static bool NotEmpty(const SELECTION &aSelection)
Test if there are any items selected.
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
static TOOL_ACTION filletTracks
Fillet (i.e. adds an arc tangent to) all selected straight tracks by a user defined radius.
Definition: pcb_actions.h:114
PCB_BASE_EDIT_FRAME * frame() const
static TOOL_ACTION copy
Definition: actions.h:67
static TOOL_ACTION rotateCw
Rotation of selected objects.
Definition: pcb_actions.h:101
static TOOL_ACTION cut
Definition: actions.h:66
bool ToolStackIsEmpty()
Definition: tools_holder.h:116
bool m_isFootprintEditor
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
static TOOL_ACTION breakTrack
Break a single track into two segments at the cursor.
Definition: pcb_actions.h:132
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
static TOOL_ACTION pasteSpecial
Definition: actions.h:69
static TOOL_ACTION rotateCcw
Definition: pcb_actions.h:102
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:105
static const KICAD_T DraggableItems[]
A scan list for items that can be dragged.
Definition: collectors.h:313
void AddSubMenu(std::shared_ptr< ACTION_MENU > aSubMenu)
Store a submenu of this menu model.
Definition: tool_menu.cpp:52
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Create a functor that tests if the selected items are only of given type.
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
BOARD * GetBoard() const
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
static TOOL_ACTION moveWithReference
move with a reference point
Definition: pcb_actions.h:95
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
static TOOL_ACTION selectAll
Definition: actions.h:70
bool IsEmpty() const
Definition: board.h:282
static TOOL_ACTION paste
Definition: actions.h:68
static TOOL_ACTION duplicate
Definition: actions.h:71
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405

References CONDITIONAL_MENU::AddItem(), CONDITIONAL_MENU::AddMenu(), CONDITIONAL_MENU::AddSeparator(), TOOL_MENU::AddSubMenu(), PCB_ACTIONS::breakTrack, PCB_ACTIONS::changeFootprint, ACTIONS::copy, SELECTION_CONDITIONS::Count(), cursor, ACTIONS::cut, ACTIONS::doDelete, PCB_ACTIONS::drag45Degree, PCB_ACTIONS::dragFreeAngle, GENERAL_COLLECTOR::DraggableItems, ACTIONS::duplicate, PCB_ACTIONS::editFpInFpEditor, PCB_ACTIONS::filletTracks, PCB_ACTIONS::flip, PCB_TOOL_BASE::frame(), PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCanvas(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_DRAW_PANEL_GAL::GetDrawingSheet(), TOOL_MENU::GetMenu(), TOOL_MANAGER::GetTool(), TOOL_INTERACTIVE::GetToolMenu(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), DS_PROXY_VIEW_ITEM::HitTestDrawingSheetItems(), TOOLS_HOLDER::IsCurrentTool(), BOARD::IsEmpty(), KIGFX::VIEW::IsLayerVisible(), LAYER_SCHEMATIC_DRAWINGSHEET, PCB_TOOL_BASE::m_isFootprintEditor, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_ACTIONS::mirror, PCB_ACTIONS::move, PCB_ACTIONS::moveWithReference, SELECTION_CONDITIONS::NotEmpty(), SELECTION_CONDITIONS::OnlyType(), SELECTION_CONDITIONS::OnlyTypes(), ACTIONS::paste, ACTIONS::pasteSpecial, PCB_FOOTPRINT_T, PCB_ACTIONS::properties, PCB_ACTIONS::rotateCcw, PCB_ACTIONS::rotateCw, ACTIONS::selectAll, TOOLS_HOLDER::ToolStackIsEmpty(), GENERAL_COLLECTOR::Tracks, and PCB_ACTIONS::updateFootprint.

◆ invokeInlineRouter()

bool EDIT_TOOL::invokeInlineRouter ( int  aDragMode)
private

Definition at line 235 of file edit_tool.cpp.

236 {
238 
239  if( !theRouter )
240  return false;
241 
242  // don't allow switch from moving to dragging
243  if( m_dragging )
244  {
245  wxBell();
246  return false;
247  }
248 
249  // make sure we don't accidentally invoke inline routing mode while the router is already
250  // active!
251  if( theRouter->IsToolActive() )
252  return false;
253 
254  if( theRouter->CanInlineDrag( aDragMode ) )
255  {
257  static_cast<intptr_t>( aDragMode ) );
258  return true;
259  }
260 
261  return false;
262 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
bool m_dragging
Definition: edit_tool.h:191
static TOOL_ACTION routerInlineDrag
Activation of the Push and Shove router (inline dragging mode)
Definition: pcb_actions.h:203
static ROUTER * theRouter
Definition: pns_router.cpp:58

References TOOL_MANAGER::GetTool(), m_dragging, TOOL_BASE::m_toolMgr, PCB_ACTIONS::routerInlineDrag, TOOL_MANAGER::RunAction(), and PNS::theRouter.

Referenced by doMoveSelection(), and Drag().

◆ Is45Limited()

bool PCB_TOOL_BASE::Is45Limited ( ) const
virtualinherited

Should the tool use its 45° mode option?

Returns
True if set to use 45°

Definition at line 323 of file pcb_tool_base.cpp.

324 {
325  if( frame()->IsType( FRAME_PCB_EDITOR ) )
327  else
329 }
PCB_BASE_EDIT_FRAME * frame() const
PCBNEW_SETTINGS & Settings()

References PCB_TOOL_BASE::frame(), FRAME_PCB_EDITOR, PCBNEW_SETTINGS::m_FpeditUse45DegreeLimit, PCBNEW_SETTINGS::m_PcbUse45DegreeLimit, and PCB_BASE_FRAME::Settings().

Referenced by DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), and DRAWING_TOOL::DrawZone().

◆ IsFootprintEditor()

◆ isRouterActive()

bool EDIT_TOOL::isRouterActive ( ) const
private

Definition at line 266 of file edit_tool.cpp.

267 {
269 
270  return router && router->IsToolActive();
271 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool IsToolActive() const
Definition: tool_base.cpp:31

References TOOL_MANAGER::GetTool(), TOOL_BASE::IsToolActive(), and TOOL_BASE::m_toolMgr.

Referenced by CreateArray(), Duplicate(), Flip(), Mirror(), Move(), MoveExact(), MoveWithReference(), Remove(), and Rotate().

◆ IsToolActive()

bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 31 of file tool_base.cpp.

32 {
33  return m_toolMgr->IsToolActive( m_toolId );
34 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
TOOL_ID m_toolId
Name of the tool.
Definition: tool_base.h:209
bool IsToolActive(TOOL_ID aId) const
Return true if a tool with given id is active (executing)

References TOOL_MANAGER::IsToolActive(), TOOL_BASE::m_toolId, and TOOL_BASE::m_toolMgr.

Referenced by Drag(), ROUTER_TOOL::handleLayerSwitch(), isRouterActive(), PCB_SELECTION_TOOL::Main(), BOARD_EDITOR_CONTROL::TrackWidthDec(), and BOARD_EDITOR_CONTROL::TrackWidthInc().

◆ Mirror()

int EDIT_TOOL::Mirror ( const TOOL_EVENT aEvent)

Mirror the current selection.

The mirror axis passes through the current point.

Definition at line 1567 of file edit_tool.cpp.

1568 {
1569  if( isRouterActive() )
1570  {
1571  wxBell();
1572  return 0;
1573  }
1574 
1576  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1577  {
1578  sTool->FilterCollectorForMarkers( aCollector );
1579  sTool->FilterCollectorForHierarchy( aCollector, true );
1580  sTool->FilterCollectorForFreePads( aCollector );
1581  },
1582  !m_dragging /* prompt user regarding locked items */ );
1583 
1584  if( selection.Empty() )
1585  return 0;
1586 
1588  auto refPoint = selection.GetReferencePoint();
1589  wxPoint mirrorPoint( refPoint.x, refPoint.y );
1590 
1591  // When editing footprints, all items have the same parent
1592  if( IsFootprintEditor() )
1593  m_commit->Modify( selection.Front() );
1594 
1595  for( EDA_ITEM* item : selection )
1596  {
1597  // only modify items we can mirror
1598  switch( item->Type() )
1599  {
1600  case PCB_FP_SHAPE_T:
1601  case PCB_FP_TEXT_T:
1602  case PCB_FP_ZONE_T:
1603  case PCB_PAD_T:
1604  // Only create undo entry for items on the board
1605  if( !item->IsNew() && !IsFootprintEditor() )
1606  m_commit->Modify( item );
1607 
1608  break;
1609  default:
1610  continue;
1611  }
1612 
1613  // modify each object as necessary
1614  switch( item->Type() )
1615  {
1616  case PCB_FP_SHAPE_T:
1617  {
1618  FP_SHAPE* shape = static_cast<FP_SHAPE*>( item );
1619  shape->Mirror( mirrorPoint, false );
1620  break;
1621  }
1622 
1623  case PCB_FP_ZONE_T:
1624  {
1625  FP_ZONE* zone = static_cast<FP_ZONE*>( item );
1626  zone->Mirror( mirrorPoint, false );
1627  break;
1628  }
1629 
1630  case PCB_FP_TEXT_T:
1631  {
1632  FP_TEXT* text = static_cast<FP_TEXT*>( item );
1633  text->Mirror( mirrorPoint, false );
1634  break;
1635  }
1636 
1637  case PCB_PAD_T:
1638  {
1639  PAD* pad = static_cast<PAD*>( item );
1640  mirrorPadX( *pad, mirrorPoint );
1641  break;
1642  }
1643 
1644  default:
1645  // it's likely the commit object is wrong if you get here
1646  // Unsure if PCB_GROUP_T needs special attention here.
1647  assert( false );
1648  break;
1649  }
1650  }
1651 
1652  if( !m_dragging )
1653  m_commit->Push( _( "Mirror" ) );
1654 
1655  if( selection.IsHover() && !m_dragging )
1657 
1659 
1660  if( m_dragging )
1662 
1663  return 0;
1664 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
VECTOR2I GetReferencePoint() const
Definition: selection.h:184
bool IsHover() const
Definition: selection.h:74
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector) const
Check the "allow free pads" setting and if disabled, upgrade any pad selection to the selection of it...
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static void mirrorPadX(PAD &aPad, const wxPoint &aMirrorPoint)
Mirror a pad in the vertical axis passing through a point (mirror left to right).
Definition: edit_tool.cpp:1545
class FP_SHAPE, a footprint edge
Definition: typeinfo.h:93
class PAD, a pad in a footprint
Definition: typeinfo.h:89
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
const PCB_SELECTION & selection() const
bool updateModificationPoint(PCB_SELECTION &aSelection)
Definition: edit_tool.cpp:2269
bool m_dragging
Definition: edit_tool.h:191
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
#define _(s)
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
void Mirror(const wxPoint &aCentre, bool aMirrorAroundXAxis)
Mirror an edge of the footprint.
Definition: fp_shape.cpp:290
class ZONE, managed by a footprint
Definition: typeinfo.h:94
bool isRouterActive() const
Definition: edit_tool.cpp:266
void Mirror(const wxPoint &aMirrorRef, bool aMirrorLeftRight)
Mirror the outlines relative to a given horizontal axis the layer is not changed.
Definition: zone.cpp:724
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
bool IsFootprintEditor() const
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:462
Definition: pad.h:57
A specialization of ZONE for use in footprints.
Definition: zone.h:947
EDA_ITEM * Front() const
Definition: selection.h:145

References _, SELECTION::Empty(), PCB_SELECTION_TOOL::FilterCollectorForFreePads(), PCB_SELECTION_TOOL::FilterCollectorForHierarchy(), PCB_SELECTION_TOOL::FilterCollectorForMarkers(), SELECTION::Front(), SELECTION::GetReferencePoint(), PCB_TOOL_BASE::IsFootprintEditor(), SELECTION::IsHover(), isRouterActive(), m_commit, m_dragging, m_selectionTool, TOOL_BASE::m_toolMgr, FP_SHAPE::Mirror(), ZONE::Mirror(), mirrorPadX(), pad, PCB_FP_SHAPE_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_PAD_T, TOOL_MANAGER::ProcessEvent(), PCB_SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, text, PCB_ACTIONS::updateLocalRatsnest, and updateModificationPoint().

Referenced by setTransitions().

◆ Move()

int EDIT_TOOL::Move ( const TOOL_EVENT aEvent)

Main loop in which events are handled.

Definition at line 680 of file edit_tool.cpp.

681 {
682  if( isRouterActive() )
683  {
684  wxBell();
685  return 0;
686  }
687 
688  return doMoveSelection( aEvent );
689 }
int doMoveSelection(TOOL_EVENT aEvent, bool aPickReference=false)
Definition: edit_tool.cpp:706
bool isRouterActive() const
Definition: edit_tool.cpp:266

References doMoveSelection(), and isRouterActive().

Referenced by Duplicate(), and setTransitions().

◆ MoveExact()

int EDIT_TOOL::MoveExact ( const TOOL_EVENT aEvent)

Invoke a dialog box to allow moving of the item by an exact amount.

Definition at line 1972 of file edit_tool.cpp.

1973 {
1974  if( isRouterActive() )
1975  {
1976  wxBell();
1977  return 0;
1978  }
1979 
1981  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1982  {
1983  sTool->FilterCollectorForMarkers( aCollector );
1984  sTool->FilterCollectorForHierarchy( aCollector, true );
1985  },
1986  true /* prompt user regarding locked items */ );
1987 
1988  if( selection.Empty() )
1989  return 0;
1990 
1991  wxPoint translation;
1992  double rotation;
1993  ROTATION_ANCHOR rotationAnchor = selection.Size() > 1 ? ROTATE_AROUND_SEL_CENTER
1995 
1996  // TODO: Implement a visible bounding border at the edge
1997  auto sel_box = selection.GetBoundingBox();
1998 
1999  DIALOG_MOVE_EXACT dialog( frame(), translation, rotation, rotationAnchor, sel_box );
2000  int ret = dialog.ShowModal();
2001 
2002  if( ret == wxID_OK )
2003  {
2004  VECTOR2I rp = selection.GetCenter();
2005  wxPoint selCenter( rp.x, rp.y );
2006 
2007  // Make sure the rotation is from the right reference point
2008  selCenter += translation;
2009 
2010  if( !frame()->GetDisplayOptions().m_DisplayInvertYAxis )
2011  rotation *= -1.0;
2012 
2013  // When editing footprints, all items have the same parent
2014  if( IsFootprintEditor() )
2015  m_commit->Modify( selection.Front() );
2016 
2017  for( EDA_ITEM* selItem : selection )
2018  {
2019  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selItem );
2020 
2021  if( !item->IsNew() && !IsFootprintEditor() )
2022  {
2023  m_commit->Modify( item );
2024 
2025  if( item->Type() == PCB_GROUP_T )
2026  {
2027  PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
2028 
2029  group->RunOnDescendants( [&]( BOARD_ITEM* bItem )
2030  {
2031  m_commit->Modify( bItem );
2032  });
2033  }
2034  }
2035 
2036  if( !item->GetParent() || !item->GetParent()->IsSelected() )
2037  item->Move( translation );
2038 
2039  switch( rotationAnchor )
2040  {
2042  item->Rotate( item->GetPosition(), rotation );
2043  break;
2045  item->Rotate( selCenter, rotation );
2046  break;
2048  item->Rotate( (wxPoint) frame()->GetScreen()->m_LocalOrigin, rotation );
2049  break;
2051  item->Rotate( board()->GetDesignSettings().GetAuxOrigin(), rotation );
2052  break;
2053  }
2054 
2055  if( !m_dragging )
2056  getView()->Update( item );
2057  }
2058 
2059  m_commit->Push( _( "Move exact" ) );
2060 
2061  if( selection.IsHover() )
2063 
2065 
2066  if( m_dragging )
2068  }
2069 
2070  return 0;
2071 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
virtual VECTOR2I GetCenter() const
Returns the center point of the selection area bounding box.
Definition: selection.cpp:71
bool IsHover() const
Definition: selection.h:74
BOARD * board() const
bool IsSelected() const
Definition: eda_item.h:122
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
virtual void Rotate(const wxPoint &aRotCentre, double aAngle)
Rotate this object.
Definition: board_item.cpp:202
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
virtual wxPoint GetPosition() const
Definition: eda_item.h:251
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
bool IsNew() const
Definition: eda_item.h:118
PCB_BASE_EDIT_FRAME * frame() const
const PCB_SELECTION & selection() const
bool m_dragging
Definition: edit_tool.h:191
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
virtual void Move(const wxPoint &aMoveVector)
Move this object.
Definition: board_item.h:233
#define _(s)
ROTATION_ANCHOR
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
bool isRouterActive() const
Definition: edit_tool.cpp:266
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
bool IsFootprintEditor() const
static TOOL_ACTION updateLocalRatsnest
Definition: pcb_actions.h:462
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:136
virtual EDA_RECT GetBoundingBox() const
Definition: selection.cpp:112
EDA_ITEM * Front() const
Definition: selection.h:145
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1570
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References _, PCB_TOOL_BASE::board(), SELECTION::Empty(), PCB_SELECTION_TOOL::FilterCollectorForHierarchy(), PCB_SELECTION_TOOL::FilterCollectorForMarkers(), PCB_TOOL_BASE::frame(), SELECTION::Front(), SELECTION::GetBoundingBox(), SELECTION::GetCenter(), BOARD_ITEM::GetParent(), EDA_ITEM::GetPosition(), TOOL_BASE::getView(), group, PCB_TOOL_BASE::IsFootprintEditor(), SELECTION::IsHover(), EDA_ITEM::IsNew(), isRouterActive(), EDA_ITEM::IsSelected(), m_commit, m_dragging, m_selectionTool, TOOL_BASE::m_toolMgr, BOARD_ITEM::Move(), PCB_GROUP_T, TOOL_MANAGER::ProcessEvent(), PCB_SELECTION_TOOL::RequestSelection(), BOARD_ITEM::Rotate(), ROTATE_AROUND_AUX_ORIGIN, ROTATE_AROUND_ITEM_ANCHOR, ROTATE_AROUND_SEL_CENTER, ROTATE_AROUND_USER_ORIGIN, TOOL_MANAGER::RunAction(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, SELECTION::Size(), EDA_ITEM::Type(), KIGFX::VIEW::Update(), PCB_ACTIONS::updateLocalRatsnest, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by setTransitions().

◆ MoveWithReference()

int EDIT_TOOL::MoveWithReference ( const TOOL_EVENT aEvent)

Move an item but with a reference point selected first.

Definition at line 692 of file edit_tool.cpp.

693 {
694  if( isRouterActive() )
695  {
696  wxBell();
697  return 0;
698  }
699 
700  return doMoveSelection( aEvent, true );
701 }
int doMoveSelection(TOOL_EVENT aEvent, bool aPickReference=false)
Definition: edit_tool.cpp:706
bool isRouterActive() const
Definition: edit_tool.cpp:266

References doMoveSelection(), and isRouterActive().

Referenced by setTransitions().

◆ PadFilter()

void EDIT_TOOL::PadFilter ( const VECTOR2I ,
GENERAL_COLLECTOR aCollector,
PCB_SELECTION_TOOL sTool 
)
static

A selection filter which prunes the selection to contain only items of type PCB_PAD_T.

Definition at line 2243 of file edit_tool.cpp.

2245 {
2246  for( int i = aCollector.GetCount() - 1; i >= 0; i-- )
2247  {
2248  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aCollector[i] );
2249 
2250  if( item->Type() != PCB_PAD_T )
2251  aCollector.Remove( i );
2252  }
2253 }
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PAD, a pad in a footprint
Definition: typeinfo.h:89
void Remove(int aIndex)
Remove the item at aIndex (first position is 0).
Definition: collector.h:110
int GetCount() const
Return the number of objects in the list.
Definition: collector.h:82
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:112

References COLLECTOR::GetCount(), PCB_PAD_T, COLLECTOR::Remove(), and EDA_ITEM::Type().

Referenced by BOARD_INSPECTION_TOOL::LocalRatsnestTool().

◆ pickReferencePoint()

bool EDIT_TOOL::pickReferencePoint ( const wxString &  aTooltip,
const wxString &  aSuccessMessage,
const wxString &  aCanceledMessage,
VECTOR2I aReferencePoint 
)
private

This allow the option of snapping in the tool

Definition at line 2296 of file edit_tool.cpp.

2298 {
2300  OPT<VECTOR2I> pickedPoint;
2301  bool done = false;
2302 
2303  m_statusPopup->SetText( aTooltip );
2304 
2306  picker->SetSnapping( true );
2307 
2308  picker->SetClickHandler(
2309  [&]( const VECTOR2D& aPoint ) -> bool
2310  {
2311  pickedPoint = aPoint;
2312 
2313  if( !aSuccessMessage.empty() )
2314  {
2315  m_statusPopup->SetText( aSuccessMessage );
2316  m_statusPopup->Expire( 800 );
2317  }
2318  else
2319  {
2320  m_statusPopup->Hide();
2321  }
2322 
2323  return false; // we don't need any more points
2324  } );
2325 
2326  picker->SetMotionHandler(
2327  [&]( const VECTOR2D& aPos )
2328  {
2329  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
2330  } );
2331 
2332  picker->SetCancelHandler(
2333  [&]()
2334  {
2335  if( !aCanceledMessage.empty() )
2336  {
2337  m_statusPopup->SetText( aCanceledMessage );
2338  m_statusPopup->Expire( 800 );
2339  }
2340  else
2341  {
2342  m_statusPopup->Hide();
2343  }
2344  } );
2345 
2346  picker->SetFinalizeHandler(
2347  [&]( const int& aFinalState )
2348  {
2349  done = true;
2350  } );
2351 
2352  m_statusPopup->Move( wxGetMousePosition() + wxPoint( 20, -50 ) );
2353  m_statusPopup->Popup();
2354 
2355  std::string tool = "";
2356  m_toolMgr->RunAction( ACTIONS::pickerTool, true, &tool );
2357 
2358  while( !done )
2359  {
2360  // Pass events unless we receive a null event, then we must shut down
2361  if( TOOL_EVENT* evt = Wait() )
2362  evt->SetPassEvent();
2363  else
2364  break;
2365  }
2366 
2367  // Ensure statusPopup is hidden after use and before deleting it:
2368  m_statusPopup->Hide();
2369 
2370  if( pickedPoint.is_initialized() )
2371  aReferencePoint = pickedPoint.get();
2372 
2373  return pickedPoint.is_initialized();
2374 }
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
void SetFinalizeHandler(FINALIZE_HANDLER aHandler)
Set a handler for the finalize event.
Definition: picker_tool.h:102
static TOOL_ACTION pickerTool
Definition: actions.h:155
Generic, UI-independent tool event.
Definition: tool_event.h:152
void SetMotionHandler(MOTION_HANDLER aHandler)
Set a handler for mouse motion.
Definition: picker_tool.h:82
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition: edit_tool.h:194
Generic tool for picking an item.
void SetClickHandler(CLICK_HANDLER aHandler)
Set a handler for mouse click event.
Definition: picker_tool.h:71
boost::optional< T > OPT
Definition: optional.h:7
void SetSnapping(bool aSnap)
Definition: picker_tool.h:64
void SetCancelHandler(CANCEL_HANDLER aHandler)
Set a handler for cancel events (ESC or context-menu Cancel).
Definition: picker_tool.h:91

References TOOL_MANAGER::GetTool(), m_statusPopup, TOOL_BASE::m_toolMgr, ACTIONS::pickerTool, TOOL_MANAGER::RunAction(), PICKER_TOOL_BASE::SetCancelHandler(), PICKER_TOOL_BASE::SetClickHandler(), PICKER_TOOL_BASE::SetFinalizeHandler(), PICKER_TOOL_BASE::SetMotionHandler(), PICKER_TOOL_BASE::SetSnapping(), and TOOL_INTERACTIVE::Wait().

Referenced by copyToClipboard(), and doMoveSelection().

◆ Properties()

int EDIT_TOOL::Properties ( const TOOL_EVENT aEvent)

Display properties window for the selected object.

Definition at line 1367 of file edit_tool.cpp.

1368 {
1369  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1371  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1372  {
1373  } );
1374 
1375  // Tracks & vias are treated in a special way:
1377  {
1378  DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection, *m_commit );
1379  dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR
1380  }
1381  else if( selection.Size() == 1 )
1382  {
1383  // Display properties dialog
1384  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
1385 
1386  // Do not handle undo buffer, it is done by the properties dialogs
1387  editFrame->OnEditItemRequest( item );
1388 
1389  // Notify other tools of the changes
1391  }
1392  else if( selection.Size() == 0 && getView()->IsLayerVisible( LAYER_DRAWINGSHEET ) )
1393  {
1394  DS_PROXY_VIEW_ITEM* ds = editFrame->GetCanvas()->GetDrawingSheet();
1395  VECTOR2D cursorPos = getViewControls()->GetCursorPosition( false );
1396 
1397  if( ds && ds->HitTestDrawingSheetItems( getView(), (wxPoint) cursorPos ) )
1399  else
1401  }
1402 
1403  if( selection.IsHover() )
1404  {
1406  }
1407  else
1408  {
1409  // Check for items becoming invisible and drop them from the selection.
1410 
1411  LSET visible = editFrame->GetBoard()->GetVisibleLayers();
1412 
1413  for( EDA_ITEM* eda_item : selection )
1414  {
1415  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( eda_item );
1416 
1417  if( !( item->GetLayerSet() & visible ).any() )
1419  }
1420  }
1421 
1422  return 0;
1423 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
static TOOL_ACTION footprintProperties
Definition: pcb_actions.h:375
bool IsHover() const
Definition: selection.h:74
static const KICAD_T Tracks[]
A scan list for only TRACKs.
Definition: collectors.h:298
static TOOL_ACTION pageSettings
Definition: actions.h:56
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
static SELECTION_CONDITION OnlyTypes(const KICAD_T aTypes[])
Create a functor that tests if the selected items are only of given types.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void OnEditItemRequest(BOARD_ITEM *aItem)=0
Install the corresponding dialog editor for the given item.
LSET GetVisibleLayers() const
A proxy function that calls the correspondent function in m_BoardSettings.
Definition: board.cpp:481
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
bool HitTestDrawingSheetItems(KIGFX::VIEW *aView, const wxPoint &aPosition)
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
DS_PROXY_VIEW_ITEM * GetDrawingSheet() const
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:516
const PCB_SELECTION & selection() const
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
drawingsheet frame and titleblock
Definition: layer_ids.h:224
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Common, abstract interface for edit frames.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
int Size() const
Returns the number of selected parts.
Definition: selection.h:104
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
BOARD * GetBoard() const
void RemoveItemFromSel(BOARD_ITEM *aItem, bool aQuietMode=false)
Multiple item unselection event handler.
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
virtual LSET GetLayerSet() const
Return a std::bitset of all layers on which the item physically resides.
Definition: board_item.h:148
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.
EDA_ITEM * Front() const
Definition: selection.h:145
bool IsLayerVisible(int aLayer) const
Return information about visibility of a particular layer.
Definition: view.h:405

References PCB_ACTIONS::footprintProperties, SELECTION::Front(), PCB_BASE_FRAME::GetBoard(), PCB_BASE_FRAME::GetCanvas(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_DRAW_PANEL_GAL::GetDrawingSheet(), BOARD_ITEM::GetLayerSet(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), BOARD::GetVisibleLayers(), DS_PROXY_VIEW_ITEM::HitTestDrawingSheetItems(), SELECTION::IsHover(), KIGFX::VIEW::IsLayerVisible(), LAYER_DRAWINGSHEET, m_commit, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), SELECTION_CONDITIONS::OnlyTypes(), ACTIONS::pageSettings, TOOL_MANAGER::ProcessEvent(), PCB_SELECTION_TOOL::RemoveItemFromSel(), PCB_SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), EVENTS::SelectedItemsModified, PCB_TOOL_BASE::selection(), PCB_ACTIONS::selectionClear, DIALOG_SHIM::ShowQuasiModal(), SELECTION::Size(), and GENERAL_COLLECTOR::Tracks.

Referenced by setTransitions().

◆ Remove()

int EDIT_TOOL::Remove ( const TOOL_EVENT aEvent)

Delete currently selected items.

Definition at line 1751 of file edit_tool.cpp.

1752 {
1753  if( isRouterActive() )
1754  {
1756  return 0;
1757  }
1758 
1759  std::vector<BOARD_ITEM*> lockedItems;
1760  Activate();
1761 
1762  // get a copy instead of reference (as we're going to clear the selection before removing items)
1763  PCB_SELECTION selectionCopy;
1766 
1767  // If we are in a "Cut" operation, then the copied selection exists already and we want to
1768  // delete exactly that; no more, no fewer. Any filtering for locked items must be done in
1769  // the copyToClipboard() routine.
1770  if( isCut )
1771  {
1772  selectionCopy = m_selectionTool->GetSelection();
1773  }
1774  else
1775  {
1776  // When not in free-pad mode we normally auto-promote selected pads to their parent
1777  // footprints. But this is probably a little too dangerous for a destructive operation,
1778  // so we just do the promotion but not the deletion (allowing for a second delete to do
1779  // it if that's what the user wanted).
1780  selectionCopy = m_selectionTool->RequestSelection(
1781  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1782  {
1783  } );
1784 
1785  size_t beforeFPCount = selectionCopy.CountType( PCB_FOOTPRINT_T );
1786 
1788  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1789  {
1790  sTool->FilterCollectorForFreePads( aCollector );
1791  } );
1792 
1793  if( !selectionCopy.IsHover()
1794  && m_selectionTool->GetSelection().CountType( PCB_FOOTPRINT_T ) > beforeFPCount )
1795  {
1796  wxBell();
1797  canvas()->Refresh();
1798  return 0;
1799  }
1800 
1801  // In "alternative" mode, we expand selected track items to their full connection.
1802  if( isAlt && ( selectionCopy.HasType( PCB_TRACE_T ) || selectionCopy.HasType( PCB_VIA_T ) ) )
1803  {
1805  }
1806 
1807  // Finally run RequestSelection() one more time to find out what user wants to do about
1808  // locked objects.
1809  selectionCopy = m_selectionTool->RequestSelection(
1810  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1811  {
1812  sTool->FilterCollectorForFreePads( aCollector );
1813  },
1814  true /* prompt user regarding locked items */ );
1815  }
1816 
1817  // As we are about to remove items, they have to be removed from the selection first
1819 
1820  for( EDA_ITEM* item : selectionCopy )
1821  {
1822  PCB_GROUP* parentGroup = static_cast<BOARD_ITEM*>( item )->GetParentGroup();
1823 
1824  if( parentGroup )
1825  {
1826  m_commit->Modify( parentGroup );
1827  parentGroup->RemoveItem( static_cast<BOARD_ITEM*>( item ) );
1828  }
1829 
1830  switch( item->Type() )
1831  {
1832  case PCB_FP_TEXT_T:
1833  {
1834  FP_TEXT* text = static_cast<FP_TEXT*>( item );
1835  FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
1836 
1837  if( text->GetType() == FP_TEXT::TEXT_is_DIVERS )
1838  {
1839  m_commit->Modify( parent );
1840  getView()->Remove( text );
1841  parent->Remove( text );
1842  }
1843 
1844  break;
1845  }
1846 
1847  case PCB_PAD_T:
1848  if( IsFootprintEditor() || frame()->Settings().m_AllowFreePads )
1849  {
1850  PAD* pad = static_cast<PAD*>( item );
1851  FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
1852 
1853  m_commit->Modify( parent );
1854  getView()->Remove( pad );
1855  parent->Remove( pad );
1856  }
1857 
1858  break;
1859 
1860  case PCB_FP_ZONE_T:
1861  {
1862  FP_ZONE* zone = static_cast<FP_ZONE*>( item );
1863  FOOTPRINT* parent = static_cast<FOOTPRINT*>( item->GetParent() );
1864 
1865  m_commit->Modify( parent );
1866  getView()->Remove( zone );
1867  parent->Remove( zone );
1868  break;
1869  }
1870 
1871  case PCB_ZONE_T:
1872  // We process the zones special so that cutouts can be deleted when the delete tool
1873  // is called from inside a cutout when the zone is selected.
1874  {
1875  // Only interact with cutouts when deleting and a single item is selected
1876  if( !isCut && selectionCopy.GetSize() == 1 )
1877  {
1879  ZONE* zone = static_cast<ZONE*>( item );
1880 
1881  int outlineIdx, holeIdx;
1882 
1883  if( zone->HitTestCutout( curPos, &outlineIdx, &holeIdx ) )
1884  {
1885  // Remove the cutout
1886  m_commit->Modify( zone );
1887  zone->RemoveCutout( outlineIdx, holeIdx );
1888  zone->UnFill();
1889 
1890  // TODO Refill zone when KiCad supports auto re-fill
1891 
1892  // Update the display
1893  zone->HatchBorder();
1894  canvas()->Refresh();
1895 
1896  // Restore the selection on the original zone
1898 
1899  break;
1900  }
1901  }
1902 
1903  // Remove the entire zone otherwise
1904  m_commit->Remove( item );
1905  break;
1906  }
1907 
1908  case PCB_GROUP_T:
1909  {
1910  PCB_GROUP* group = static_cast<PCB_GROUP*>( item );
1911 
1912  auto removeItem =
1913  [&]( BOARD_ITEM* bItem )
1914  {
1915  if( bItem->GetParent() && bItem->GetParent()->Type() == PCB_FOOTPRINT_T )
1916  {
1917  // Silently ignore delete of Reference or Value if they happen to be
1918  // in group.
1919  if( bItem->Type() == PCB_FP_TEXT_T )
1920  {
1921  FP_TEXT* textItem = static_cast<FP_TEXT*>( bItem );
1922 
1923  if( textItem->GetType() != FP_TEXT::TEXT_is_DIVERS )
1924  return;
1925  }
1926  else if( bItem->Type() == PCB_PAD_T )
1927  {
1929  return;
1930  }
1931 
1932  m_commit->Modify( bItem->GetParent() );
1933  getView()->Remove( bItem );
1934  bItem->GetParent()->Remove( bItem );
1935  }
1936  else
1937  {
1938  m_commit->Remove( bItem );
1939  }
1940  };
1941 
1942  removeItem( group );
1943 
1944  group->RunOnDescendants( [&]( BOARD_ITEM* aDescendant )
1945  {
1946  removeItem( aDescendant );
1947  });
1948  break;
1949  }
1950 
1951  default:
1952  m_commit->Remove( item );
1953  break;
1954  }
1955  }
1956 
1957  // If the entered group has been emptied then leave it.
1958  PCB_GROUP* enteredGroup = m_selectionTool->GetEnteredGroup();
1959 
1960  if( enteredGroup && enteredGroup->GetItems().empty() )
1962 
1963  if( isCut )
1964  m_commit->Push( _( "Cut" ) );
1965  else
1966  m_commit->Push( _( "Delete" ) );
1967 
1968  return 0;
1969 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
PCB_GROUP * GetParentGroup() const
Definition: board_item.h:60
size_t CountType(KICAD_T aType) const
Definition: selection.cpp:135
void RemoveCutout(int aOutlineIdx, int aHoleIdx)
Remove a cutout from the zone.
Definition: zone.cpp:769
bool IsHover() const
Definition: selection.h:74
class FP_TEXT, text in a footprint
Definition: typeinfo.h:92
REMOVE_FLAGS
Definition: actions.h:190
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
bool HasType(KICAD_T aType) const
Checks if there is at least one item of requested kind.
Definition: selection.cpp:123
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector) const
Check the "allow free pads" setting and if disabled, upgrade any pad selection to the selection of it...
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
static TOOL_ACTION routerUndoLastSegment
Definition: pcb_actions.h:189
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:350
void Remove(BOARD_ITEM *aItem, REMOVE_MODE aMode=REMOVE_MODE::NORMAL) override
Removes an item from the container.
Definition: footprint.cpp:566
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
static TOOL_ACTION selectConnection
Select tracks between junctions or expands an existing selection to pads or the entire connection.
Definition: pcb_actions.h:74
class PAD, a pad in a footprint
Definition: typeinfo.h:89
PCB_GROUP * GetEnteredGroup()
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
std::unordered_set< BOARD_ITEM * > & GetItems()
Definition: pcb_group.h:68
class PCB_TRACK, a track segment (segment on a copper layer)
Definition: typeinfo.h:95
PCB_BASE_EDIT_FRAME * frame() const
bool HitTestCutout(const VECTOR2I &aRefPos, int *aOutlineIdx=nullptr, int *aHoleIdx=nullptr) const
Test if the given point is contained within a cutout of the zone.
Definition: zone.cpp:519
PCB_SELECTION & GetSelection()
Return the set of currently selected items.
void HatchBorder()
Compute the hatch lines depending on the hatch parameters and stores it in the zone's attribute m_bor...
Definition: zone.cpp:906
TEXT_TYPE GetType() const
Definition: fp_text.h:141
T Parameter() const
Return a non-standard parameter assigned to the event.
Definition: tool_event.h:432
#define _(s)
bool RemoveItem(BOARD_ITEM *aItem)
Remove item from group.
Definition: pcb_group.cpp:51
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
class ZONE, a copper pour area
Definition: typeinfo.h:105
void ExitGroup(bool aSelectGroup=false)
Leave the currently entered group.
KIGFX::VIEW * getView() const
Returns the instance of #VIEW object used in the application.
Definition: tool_base.cpp:36
class FOOTPRINT, a footprint
Definition: typeinfo.h:88
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
static TOOL_ACTION selectItem
Select an item (specified as the event parameter).
Definition: pcb_actions.h:62
class ZONE, managed by a footprint
Definition: typeinfo.h:94
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
Update the board display after modifying it by a python script (note: it is automatically called by a...
PCBNEW_SETTINGS & Settings()
bool isRouterActive() const
Definition: edit_tool.cpp:266
The selection tool: currently supports:
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:99
bool IsFootprintEditor() const
void Activate()
Run the tool.
class PCB_VIA, a via (like a track segment on a copper layer)
Definition: typeinfo.h:96
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition: tool_base.cpp:42
Definition: pad.h:57
bool UnFill()
Removes the zone filling.
Definition: zone.cpp:192
PCB_DRAW_PANEL_GAL * canvas() const
A specialization of ZONE for use in footprints.
Definition: zone.h:947
VECTOR2D GetCursorPosition() const
Return the current cursor position in world coordinates.

References _, TOOL_INTERACTIVE::Activate(), ACTIONS::ALT, PCB_TOOL_BASE::canvas(), SELECTION::CountType(), ACTIONS::CUT, PCB_SELECTION_TOOL::ExitGroup(), PCB_SELECTION_TOOL::FilterCollectorForFreePads(), PCB_TOOL_BASE::frame(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), PCB_SELECTION_TOOL::GetEnteredGroup(), PCB_GROUP::GetItems(), BOARD_ITEM::GetParentGroup(), PCB_SELECTION_TOOL::GetSelection(), FP_TEXT::GetType(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), group, SELECTION::HasType(), ZONE::HatchBorder(), ZONE::HitTestCutout(), PCB_TOOL_BASE::IsFootprintEditor(), SELECTION::IsHover(), isRouterActive(), PCBNEW_SETTINGS::m_AllowFreePads, m_commit, m_selectionTool, TOOL_BASE::m_toolMgr, pad, TOOL_EVENT::Parameter(), PCB_FOOTPRINT_T, PCB_FP_TEXT_T, PCB_FP_ZONE_T, PCB_GROUP_T, PCB_PAD_T, PCB_TRACE_T, PCB_VIA_T, PCB_ZONE_T, EDA_DRAW_PANEL_GAL::Refresh(), KIGFX::VIEW::Remove(), FOOTPRINT::Remove(), ZONE::RemoveCutout(), PCB_GROUP::RemoveItem(), PCB_SELECTION_TOOL::RequestSelection(), PCB_ACTIONS::routerUndoLastSegment, TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectConnection, PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectItem, PCB_BASE_FRAME::Settings(), text, FP_TEXT::TEXT_is_DIVERS, and ZONE::UnFill().

Referenced by cutToClipboard(), and setTransitions().

◆ Reset()

void EDIT_TOOL::Reset ( RESET_REASON  aReason)
overridevirtual

Bring the tool to a known, initial state.

If the tool claimed anything from the model or the view, it must release it when its reset.

Parameters
aReasoncontains information about the reason of tool reset.

Reimplemented from PCB_TOOL_BASE.

Definition at line 76 of file edit_tool.cpp.

77 {
78  m_dragging = false;
79 
80  m_statusPopup = std::make_unique<STATUS_TEXT_POPUP>( getEditFrame<PCB_BASE_EDIT_FRAME>() );
81 
82  if( aReason != RUN )
83  m_commit.reset( new BOARD_COMMIT( this ) );
84 }
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
Tool is invoked after being inactive.
Definition: tool_base.h:79
bool m_dragging
Definition: edit_tool.h:191
std::unique_ptr< STATUS_TEXT_POPUP > m_statusPopup
Definition: edit_tool.h:194

References m_commit, m_dragging, m_statusPopup, and TOOL_BASE::RUN.

◆ Rotate()

int EDIT_TOOL::Rotate ( const TOOL_EVENT aEvent)

Rotate currently selected items.

Definition at line 1426 of file edit_tool.cpp.

1427 {
1428  if( isRouterActive() )
1429  {
1430  wxBell();
1431  return 0;
1432  }
1433 
1434  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1435 
1436  // Be sure that there is at least one item that we can modify. If nothing was selected before,
1437  // try looking for the stuff under mouse cursor (i.e. KiCad old-style hover selection)
1439  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1440  {
1441  sTool->FilterCollectorForHierarchy( aCollector, true );
1442  sTool->FilterCollectorForMarkers( aCollector );
1443  },
1444  // Prompt user regarding locked items if in board editor and in free-pad-mode (if
1445  // we're not in free-pad mode we delay this until the second RequestSelection()).
1447 
1448  if( selection.Empty() )
1449  return 0;
1450 
1451  OPT<VECTOR2I> oldRefPt = boost::make_optional<VECTOR2I>( false, VECTOR2I( 0, 0 ) );
1452  bool is_hover = selection.IsHover(); // N.B. This must be saved before the second
1453  // call to RequestSelection() below
1454 
1456  oldRefPt = selection.GetReferencePoint();
1457 
1458  // Now filter out pads if not in free pads mode. We cannot do this in the first
1459  // RequestSelection() as we need the reference point when a pad is the selection front.
1460  if( !m_isFootprintEditor && !frame()->Settings().m_AllowFreePads )
1461  {
1463  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* sTool )
1464  {
1465  sTool->FilterCollectorForMarkers( aCollector );
1466  sTool->FilterCollectorForHierarchy( aCollector, true );
1467  sTool->FilterCollectorForFreePads( aCollector );
1468  },
1469  true /* prompt user regarding locked items */ );
1470  }
1471 
1472  // Did we filter everything out? If so, don't try to operate further
1473  if( selection.Empty() )
1474  return 0;
1475 
1477 
1479  const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
1480 
1481  // When editing footprints, all items have the same parent
1482  if( IsFootprintEditor() )
1483  m_commit->Modify( selection.Front() );
1484 
1485  for( EDA_ITEM* item : selection )
1486  {
1487  if( !item->IsNew() && !IsFootprintEditor() )
1488  {
1489  m_commit->Modify( item );
1490 
1491  // If rotating a group, record position of all the descendants for undo
1492  if( item->Type() == PCB_GROUP_T )
1493  {
1494  static_cast<PCB_GROUP*>( item )->RunOnDescendants(
1495  [&]( BOARD_ITEM* bItem )
1496  {
1497  m_commit->Modify( bItem );
1498  });
1499  }
1500  }
1501 
1502  static_cast<BOARD_ITEM*>( item )->Rotate( refPt, rotateAngle );
1503  }
1504 
1505  if( !m_dragging )
1506  m_commit->Push( _( "Rotate" ) );
1507 
1508  if( is_hover && !m_dragging )
1510 
1512 
1513  if( m_dragging )
1515 
1516  // Restore the old reference so any mouse dragging that occurs doesn't make the selection jump
1517  // to this now invalid reference
1518  if( oldRefPt )
1519  selection.SetReferencePoint( *oldRefPt );
1520  else
1522 
1523  return 0;
1524 }
static TOOL_ACTION selectionClear
Clear the current selection.
Definition: pcb_actions.h:59
VECTOR2I GetReferencePoint() const
Definition: selection.h:184
void ClearReferencePoint()
Definition: selection.h:197
bool IsHover() const
Definition: selection.h:74
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:49
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:108
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:190
void FilterCollectorForFreePads(GENERAL_COLLECTOR &aCollector) const
Check the "allow free pads" setting and if disabled, upgrade any pad selection to the selection of it...
void FilterCollectorForMarkers(GENERAL_COLLECTOR &aCollector) const
Apply the SELECTION_FILTER_OPTIONS to a collection of items.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:214
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Run the specified action.
Definition: tool_manager.h:143
PCB_SELECTION_TOOL * m_selectionTool
Definition: edit_tool.h:189
VECTOR2< int > VECTOR2I
Definition: vector2d.h:622
static const TOOL_EVENT SelectedItemsModified
Selected items were moved, this can be very high frequency on the canvas, use with care.
Definition: actions.h:205
PCB_BASE_EDIT_FRAME * frame() const
void SetReferencePoint(const VECTOR2I &aP)
Definition: selection.h:192
const PCB_SELECTION & selection() const
bool updateModificationPoint(PCB_SELECTION &aSelection)
Definition: edit_tool.cpp:2269
bool m_dragging
Definition: edit_tool.h:191
bool ProcessEvent(const TOOL_EVENT &aEvent)
Propagate an event to tools that requested events of matching type(s).
#define _(s)
bool m_isFootprintEditor
bool Empty() const
Checks if there is anything selected.
Definition: selection.h:98
void FilterCollectorForHierarchy(GENERAL_COLLECTOR &aCollector, bool aMultiselect) const
In general we don't want to select both a parent and any of it's children.
bool HasReferencePoint() const
Definition: selection.h:179
PCB_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, bool aConfirmLockedItems=false)
Return the current selection set, filtered according to aFlags and aClientFilter.
Common, abstract interface for edit frames.