KiCad PCB EDA Suite
EDIT_TOOL Class Reference

Class EDIT_TOOL. More...

#include <edit_tool.h>

Inheritance diagram for EDIT_TOOL:
PCB_TOOL TOOL_INTERACTIVE TOOL_BASE

Public Types

enum  RESET_REASON { RUN, MODEL_RELOAD, GAL_SWITCH }
 

Determines the reason of reset for a tool

More...
 

Public Member Functions

 EDIT_TOOL ()
 
void Reset (RESET_REASON aReason) override
 Function Reset() Brings the tool to a known, initial state. More...
 
bool Init () override
 Function Init() Init() is called once upon a registration of the tool. More...
 
int Main (const TOOL_EVENT &aEvent)
 Function Main() More...
 
int Properties (const TOOL_EVENT &aEvent)
 Function Edit() More...
 
int Rotate (const TOOL_EVENT &aEvent)
 Function Rotate() More...
 
int Flip (const TOOL_EVENT &aEvent)
 Function Flip() More...
 
int Mirror (const TOOL_EVENT &aEvent)
 Function Mirror. More...
 
int Remove (const TOOL_EVENT &aEvent)
 Function Remove() More...
 
int Duplicate (const TOOL_EVENT &aEvent)
 Function Duplicate() More...
 
int MoveExact (const TOOL_EVENT &aEvent)
 Function MoveExact() More...
 
int CreateArray (const TOOL_EVENT &aEvent)
 Function CreateArray() More...
 
int ExchangeFootprints (const TOOL_EVENT &aEvent)
 Function ExchangeFootprints() More...
 
int MeasureTool (const TOOL_EVENT &aEvent)
 

Launches a tool to measure between points

More...
 
void SetTransitions () override
 

Sets up handlers for various events.

More...
 
void SetEditModules (bool aEnabled)
 Function SetEditModules() More...
 
bool EditingModules () const
 
void Activate ()
 Function Activate() Runs the tool. More...
 
void SetContextMenu (CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger=CMENU_BUTTON)
 Function SetContextMenu() More...
 
void RunMainStack (std::function< void()> aFunc)
 Function RunMainStack() More...
 
template<class T >
void Go (int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Go() More...
 
OPT_TOOL_EVENT Wait (const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
 Function Wait() More...
 
TOOL_TYPE GetType () const
 Function GetType() Returns the type of the tool. More...
 
TOOL_ID GetId () const
 Function GetId() Returns the unique identifier of the tool. More...
 
const std::string & GetName () const
 Function GetName() Returns the name of the tool. More...
 
TOOL_MANAGERGetManager () const
 Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool. More...
 
TOOL_SETTINGSGetSettings ()
 

Protected Types

using ITEM_CREATOR = std::function< std::unique_ptr< BOARD_ITEM >(const TOOL_EVENT &aEvt) >
 Callable that returns a new board item. More...
 

Protected Member Functions

void doInteractiveItemPlacement (ITEM_CREATOR aItemCreator, const wxString &aCommitMessage)
 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::VIEWview () const
 
PCB_EDIT_FRAMEframe () const
 
BOARDboard () const
 
const TOOL_EVENT evActivate (std::string aToolName="")
 functions below are not yet implemented - their interface may change More...
 
const TOOL_EVENT evCommand (int aCommandId=-1)
 
const TOOL_EVENT evCommand (std::string aCommandStr="")
 
const TOOL_EVENT evMotion ()
 
const TOOL_EVENT evClick (int aButton=BUT_ANY)
 
const TOOL_EVENT evDrag (int aButton=BUT_ANY)
 
const TOOL_EVENT evButtonUp (int aButton=BUT_ANY)
 
const TOOL_EVENT evButtonDown (int aButton=BUT_ANY)
 
void attachManager (TOOL_MANAGER *aManager)
 Function attachManager() More...
 
KIGFX::VIEWgetView () const
 Function getView() More...
 
KIGFX::VIEW_CONTROLSgetViewControls () const
 Function getViewControls() More...
 
template<typename T >
T * getEditFrame () const
 Function getEditFrame() More...
 
template<typename T >
T * getModel () const
 Function getModel() More...
 

Protected Attributes

bool m_editModules
 
TOOL_TYPE m_type
 

Stores the type of the tool.

More...
 
TOOL_ID m_toolId
 

Unique identifier for the tool, assigned by a TOOL_MANAGER instance.

More...
 
std::string m_toolName
 

Name of the tool.

More...
 
TOOL_MANAGERm_toolMgr
 
TOOL_SETTINGS m_toolSettings
 

Private Member Functions

wxPoint getModificationPoint (const SELECTION &aSelection)
 

Returns the right modification point (e.g.

More...
 
int editFootprintInFpEditor (const TOOL_EVENT &aEvent)
 
bool invokeInlineRouter ()
 
bool hoverSelection (bool aSanitize=true)
 Function hoverSelection() More...
 
template<class T >
T * uniqueSelected ()
 Function uniqueSelected() More...
 
template<class T >
T * uniqueHoverSelection (bool aSanitize=true)
 Function uniqueHoverSelection() More...
 

Private Attributes

SELECTION_TOOLm_selectionTool
 

Selection tool used for obtaining selected items

More...
 
bool m_dragging
 

Flag determining if anything is being dragged right now

More...
 
wxPoint m_offset
 

Offset from the dragged item's center (anchor)

More...
 
VECTOR2I m_cursor
 

Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point).

More...
 
std::unique_ptr< BOARD_COMMITm_commit
 

Detailed Description

Class EDIT_TOOL.

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

Definition at line 43 of file edit_tool.h.

Member Typedef Documentation

using PCB_TOOL::ITEM_CREATOR = std::function< std::unique_ptr< BOARD_ITEM >( const TOOL_EVENT& aEvt ) >
protectedinherited

Callable that returns a new board item.

The event that triggered it is provided, so you can check modifier keys, position, etc, if required

Definition at line 91 of file pcb_tool.h.

Member Enumeration Documentation

enum TOOL_BASE::RESET_REASON
inherited

Determines 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 80 of file tool_base.h.

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

Constructor & Destructor Documentation

EDIT_TOOL::EDIT_TOOL ( )

Definition at line 161 of file edit_tool.cpp.

161  :
162  PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ),
163  m_dragging( false )
164 {
165 }
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
bool m_dragging
Flag determining if anything is being dragged right now
Definition: edit_tool.h:138
PCB_TOOL(TOOL_ID aId, const std::string &aName)
Constructor.
Definition: pcb_tool.h:52

Member Function Documentation

void TOOL_INTERACTIVE::Activate ( )
inherited

Function Activate() Runs the tool.

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

Definition at line 49 of file tool_interactive.cpp.

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

Referenced by MODULE_EDITOR_TOOLS::CopyItems(), PCBNEW_CONTROL::DeleteItemCursor(), PCB_TOOL::doInteractiveItemPlacement(), ROUTER_TOOL::DpDimensionsDialog(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::drawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineDrag(), Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), MeasureTool(), POINT_EDITOR::OnSelectionChange(), MODULE_EDITOR_TOOLS::PasteItems(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), and ROUTER_TOOL::SettingsDialog().

50 {
52 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:215
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID...
void TOOL_BASE::attachManager ( TOOL_MANAGER aManager)
protectedinherited

Function attachManager()

Sets the TOOL_MANAGER the tool will belong to. Called by TOOL_MANAGER::RegisterTool()

Definition at line 54 of file tool_base.cpp.

References TOOL_BASE::m_toolMgr, TOOL_BASE::m_toolSettings, and TOOL_BASE::TOOL_SETTINGS.

Referenced by TOOL_MANAGER::RegisterTool().

55 {
56  m_toolMgr = aManager;
57  m_toolSettings = TOOL_SETTINGS( this );
58 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:221
friend class TOOL_SETTINGS
Definition: tool_base.h:160
int EDIT_TOOL::CreateArray ( const TOOL_EVENT aEvent)

Function CreateArray()

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

Definition at line 976 of file edit_tool.cpp.

References PCB_TOOL::m_editModules, m_selectionTool, and SELECTION_TOOL::RequestSelection().

Referenced by SetTransitions().

977 {
978  const auto& selection = m_selectionTool->RequestSelection();
979 
980  if( selection.Empty() )
981  return 0;
982 
983  // we have a selection to work on now, so start the tool process
984  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
985  GAL_ARRAY_CREATOR array_creator( *editFrame, m_editModules, selection );
986  array_creator.Invoke();
987 
988  return 0;
989 }
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
bool m_editModules
Definition: pcb_tool.h:112
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
void PCB_TOOL::doInteractiveItemPlacement ( ITEM_CREATOR  aItemCreator,
const wxString &  aCommitMessage 
)
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 39 of file pcb_tool.cpp.

References TOOL_INTERACTIVE::Activate(), KIGFX::VIEW_GROUP::Add(), SELECTION::Add(), COMMIT::Add(), KIGFX::VIEW::Add(), BUT_LEFT, KIGFX::VIEW_CONTROLS::CaptureCursor(), SELECTION::Clear(), dyn_cast(), PCB_ACTIONS::flip, PCB_TOOL::frame(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_EVT_UTILS::GetEventRotationAngle(), TOOL_BASE::GetManager(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_EVT_UTILS::IsCancelInteractive(), TOOL_EVT_UTILS::IsRotateToolEvt(), PCB_MODULE_T, BOARD_COMMIT::Push(), KIGFX::VIEW_GROUP::Remove(), SELECTION::Remove(), KIGFX::VIEW::Remove(), TOOL_MANAGER::RunAction(), MODULE::RunOnChildren(), PCB_ACTIONS::selectionClear, KIGFX::VIEW_CONTROLS::SetAutoPan(), KIGFX::VIEW_CONTROLS::SetSnapping(), KIGFX::VIEW_CONTROLS::ShowCursor(), TC_COMMAND, KIGFX::VIEW::Update(), PCB_TOOL::view(), TOOL_INTERACTIVE::Wait(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by MICROWAVE_TOOL::addMicrowaveFootprint().

41 {
42  using namespace std::placeholders;
43 
44  KIGFX::VIEW& view = *getView();
46  auto& frame = *getEditFrame<PCB_EDIT_FRAME>();
47 
48  std::unique_ptr<BOARD_ITEM> newItem;
49 
50  Activate();
51 
52  BOARD_COMMIT commit( &frame );
53 
55 
56  // do not capture or auto-pan until we start placing an item
57  controls.ShowCursor( true );
58  controls.SetSnapping( true );
59 
60  // Add a VIEW_GROUP that serves as a preview for the new item
61  SELECTION preview;
62  view.Add( &preview );
63 
64  // Main loop: keep receiving events
65  while( OPT_TOOL_EVENT evt = Wait() )
66  {
67  VECTOR2I cursorPos = controls.GetCursorPosition();
68 
70  {
71  if( newItem )
72  {
73  // Delete the old item and have another try
74  newItem = nullptr;
75 
76  preview.Clear();
77 
78  controls.SetAutoPan( false );
79  controls.CaptureCursor( false );
80  controls.ShowCursor( true );
81  }
82  else
83  {
84  break;
85  }
86 
87  if( evt->IsActivate() ) // now finish unconditionally
88  break;
89  }
90 
91  else if( evt->IsClick( BUT_LEFT ) )
92  {
93  if( !newItem )
94  {
95  // create the item if possible
96  newItem = aItemCreator( *evt );
97 
98  // no item created, so wait for another click
99  if( !newItem )
100  continue;
101 
102  controls.CaptureCursor( true );
103  controls.SetAutoPan( true );
104 
105  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
106 
107  preview.Add( newItem.get() );
108 
109  if( newItem->Type() == PCB_MODULE_T )
110  {
111  auto module = dyn_cast<MODULE*>( newItem.get() );
112 
113  // modules have more drawable parts
114  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Add, &preview, _1 ) );
115  }
116  }
117  else
118  {
119  newItem->ClearFlags();
120  preview.Remove( newItem.get() );
121 
122  if( newItem->Type() == PCB_MODULE_T )
123  {
124  auto module = dyn_cast<MODULE*>( newItem.get() );
125  module->RunOnChildren( std::bind( &KIGFX::VIEW_GROUP::Remove, &preview, _1 ) );
126  }
127 
128  commit.Add( newItem.release() );
129  commit.Push( aCommitMessage );
130 
131  controls.CaptureCursor( false );
132  controls.SetAutoPan( false );
133  controls.ShowCursor( true );
134  }
135  }
136 
137  else if( newItem && evt->Category() == TC_COMMAND )
138  {
139  /*
140  * Handle any events that can affect the item as we move
141  * it around, eg rotate and flip
142  */
143 
144  if( TOOL_EVT_UTILS::IsRotateToolEvt( *evt ) )
145  {
146  const auto rotationAngle = TOOL_EVT_UTILS::GetEventRotationAngle(
147  frame, *evt );
148  newItem->Rotate( newItem->GetPosition(), rotationAngle );
149  view.Update( &preview );
150  }
151  else if( evt->IsAction( &PCB_ACTIONS::flip ) )
152  {
153  newItem->Flip( newItem->GetPosition() );
154  view.Update( &preview );
155  }
156  }
157 
158  else if( newItem && evt->IsMotion() )
159  {
160  // track the cursor
161  newItem->SetPosition( wxPoint( cursorPos.x, cursorPos.y ) );
162 
163  // Show a preview of the item
164  view.Update( &preview );
165  }
166  }
167 
168  view.Remove( &preview );
169 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
KIGFX::VIEW * view() const
Definition: pcb_tool.h:108
void RunOnChildren(std::function< void(BOARD_ITEM *)> aFunction)
Function RunOnChildren.
virtual void Clear() override
Function Clear() Removes all the stored items from the group.
Definition: selection.h:81
void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:341
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
bool IsRotateToolEvt(const TOOL_EVENT &aEvt)
Function isRotateToolEvt()
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:73
virtual void Add(EDA_ITEM *aItem)
Definition: selection.h:71
class MODULE, a footprint
Definition: typeinfo.h:101
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
virtual void CaptureCursor(bool aEnabled)
Function CaptureCursor() Forces the cursor to stay within the drawing panel area. ...
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:109
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
Definition: view_controls.h:94
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes an item from the group.
Definition: view_group.cpp:61
bool IsCancelInteractive(const TOOL_EVENT &aEvt)
Function IsCancelInteractive()
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:36
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:90
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool...
Definition: tool_base.h:144
void Activate()
Function Activate() Runs the tool.
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:311
Class VIEW.
Definition: view.h:58
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
virtual void Remove(EDA_ITEM *aItem)
Definition: selection.h:76
int EDIT_TOOL::Duplicate ( const TOOL_EVENT aEvent)

Function Duplicate()

Duplicates a selection and starts a move action

Definition at line 831 of file edit_tool.cpp.

References EDA_DRAW_FRAME::DisplayToolMsg(), BOARD::Duplicate(), MODULE::Duplicate(), PCB_ACTIONS::duplicateIncrement, PCB_ACTIONS::editActivate, Format(), PCB_BASE_FRAME::GetBoard(), TOOL_EVENT::IsAction(), m_commit, PCB_TOOL::m_editModules, BOARD::m_Modules, m_selectionTool, TOOL_BASE::m_toolMgr, Main(), TOOL_ACTION::MakeEvent(), PCB_ZONE_AREA_T, SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), SELECTION_DELETABLE, SELECTION_SANITIZE_PADS, PCB_ACTIONS::selectItem, EDA_ITEM::Type(), and PCB_ACTIONS::unselectItem.

Referenced by SetTransitions().

832 {
833  // Note: original items are no more modified.
834 
835  bool increment = aEvent.IsAction( &PCB_ACTIONS::duplicateIncrement );
836 
837  // Be sure that there is at least one item that we can modify
839 
840  if( selection.Empty() )
841  return 0;
842 
843  // we have a selection to work on now, so start the tool process
844  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
845 
846  std::vector<BOARD_ITEM*> old_items;
847 
848  for( auto item : selection )
849  {
850  if( item )
851  old_items.push_back( static_cast<BOARD_ITEM*>( item ) );
852  }
853 
854  for( unsigned i = 0; i < old_items.size(); ++i )
855  {
856  BOARD_ITEM* item = old_items[i];
857 
858  // Unselect the item, so we won't pick it up again
859  // Do this first, so a single-item duplicate will correctly call
860  // SetCurItem and show the item properties
862 
863  BOARD_ITEM* new_item = NULL;
864 
865  if( m_editModules )
866  {
867  new_item = editFrame->GetBoard()->m_Modules->Duplicate( item, increment );
868  }
869  else
870  {
871 #if 0
872  // @TODO: see if we allow zone duplication here
873  // Duplicate zones is especially tricky (overlaping zones must be merged)
874  // so zones are not duplicated
875  if( item->Type() != PCB_ZONE_AREA_T )
876 #endif
877  new_item = editFrame->GetBoard()->Duplicate( item );
878  }
879 
880  if( new_item )
881  {
882  m_commit->Add( new_item );
883 
884  // Select the new item, so we can pick it up
885  m_toolMgr->RunAction( PCB_ACTIONS::selectItem, true, new_item );
886  }
887  }
888 
889  // record the new items as added
890  if( !selection.Empty() )
891  {
892  editFrame->DisplayToolMsg( wxString::Format( _( "Duplicated %d item(s)" ),
893  (int) old_items.size() ) );
894 
895  // If items were duplicated, pick them up
896  // this works well for "dropping" copies around and pushes the commit
898  Main( evt );
899  }
900 
901  return 0;
902 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
int Main(const TOOL_EVENT &aEvent)
Function Main()
Definition: edit_tool.cpp:247
static TOOL_ACTION editActivate
Activation of the edit tool.
Definition: pcb_actions.h:81
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
static TOOL_ACTION unselectItem
Unselects an item (specified as the event parameter).
Definition: pcb_actions.h:59
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aIncrementPadNumbers, bool aAddToModule=false)
Function Duplicate Duplicate a given item within the module, without adding to the board...
class ZONE_CONTAINER, a zone area
Definition: typeinfo.h:114
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
BOARD * GetBoard() const
bool IsAction(const TOOL_ACTION *aAction) const
Function IsAction() Tests if the event contains an action issued upon activation of the given TOOL_AC...
Definition: tool_event.cpp:54
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
static TOOL_ACTION duplicateIncrement
Activation of the duplication tool with incrementing (e.g. pad number)
Definition: pcb_actions.h:108
Class TOOL_EVENT.
Definition: tool_event.h:162
bool m_editModules
Definition: pcb_tool.h:112
TOOL_EVENT MakeEvent() const
Function HasHotKey() Checks if the action has a hot key assigned.
Definition: tool_action.h:104
void DisplayToolMsg(const wxString &msg)
Definition: draw_frame.cpp:497
Common, abstract interface for edit frames.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
DLIST< MODULE > m_Modules
Definition: class_board.h:243
static TOOL_ACTION selectItem
Selects an item (specified as the event parameter).
Definition: pcb_actions.h:56
BOARD_ITEM * Duplicate(const BOARD_ITEM *aItem, bool aAddToBoard=false)
int EDIT_TOOL::editFootprintInFpEditor ( const TOOL_EVENT aEvent)
private

Definition at line 1154 of file edit_tool.cpp.

References FRAME_PCB_MODULE_EDITOR, PCB_BASE_FRAME::GetCurItem(), GetNewTimeStamp(), EDA_ITEM::GetTimeStamp(), KIWAY_HOLDER::Kiway(), FOOTPRINT_EDIT_FRAME::Load_Module_From_BOARD(), m_selectionTool, TOOL_BASE::m_toolMgr, mod, PCB_BASE_FRAME::OnModify(), KIWAY::Player(), SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, PCB_BASE_FRAME::SetCurItem(), and EDA_ITEM::SetTimeStamp().

Referenced by SetTransitions().

1155 {
1156  const auto& selection = m_selectionTool->RequestSelection();
1157 
1158  if( selection.Empty() )
1159  return 0;
1160 
1161  MODULE* mod = selection.FirstOfKind<MODULE>();
1162 
1163  if( !mod )
1164  return 0;
1165 
1166  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
1167 
1168  editFrame->SetCurItem( mod );
1169 
1170  if( editFrame->GetCurItem()->GetTimeStamp() == 0 ) // Module Editor needs a non null timestamp
1171  {
1172  editFrame->GetCurItem()->SetTimeStamp( GetNewTimeStamp() );
1173  editFrame->OnModify();
1174  }
1175 
1177 
1178  editor->Load_Module_From_BOARD( (MODULE*) editFrame->GetCurItem() );
1179  editFrame->SetCurItem( NULL ); // the current module could be deleted by
1180 
1181  editor->Show( true );
1182  editor->Raise(); // Iconize( false );
1183 
1184  if( selection.IsHover() )
1186 
1187  return 0;
1188 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_player.h:60
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
time_t GetNewTimeStamp()
Definition: common.cpp:166
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
void SetTimeStamp(time_t aNewTimeStamp)
Definition: base_struct.h:203
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, KIWAY_PLAYER *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:302
bool Load_Module_From_BOARD(MODULE *Module)
Function Load_Module_From_BOARD load in Modedit a footprint from the main board.
Definition: loadcmp.cpp:75
time_t GetTimeStamp() const
Definition: base_struct.h:204
virtual void OnModify()
Function OnModify Virtual Must be called after a change in order to set the "modify" flag of the curr...
Common, abstract interface for edit frames.
BOARD_ITEM * GetCurItem()
#define mod(a, n)
Definition: greymap.cpp:24
bool PCB_TOOL::EditingModules ( ) const
inlineinherited

Definition at line 78 of file pcb_tool.h.

References PCB_TOOL::m_editModules.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), PAD_TOOL::Init(), and MeasureTool().

79  {
80  return m_editModules;
81  }
bool m_editModules
Definition: pcb_tool.h:112
const TOOL_EVENT TOOL_INTERACTIVE::evActivate ( std::string  aToolName = "")
protectedinherited

functions below are not yet implemented - their interface may change

const TOOL_EVENT TOOL_INTERACTIVE::evButtonDown ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evButtonUp ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evClick ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( int  aCommandId = -1)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evCommand ( std::string  aCommandStr = "")
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evDrag ( int  aButton = BUT_ANY)
protectedinherited
const TOOL_EVENT TOOL_INTERACTIVE::evMotion ( )
protectedinherited
int EDIT_TOOL::ExchangeFootprints ( const TOOL_EVENT aEvent)

Function ExchangeFootprints()

Invoke the dialog used to change the footprints used for modules and update module footprints based on result

Definition at line 992 of file edit_tool.cpp.

References PCB_TOOL::frame(), m_selectionTool, TOOL_BASE::m_toolMgr, mod, SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectionClear, PCB_BASE_FRAME::SetCurItem(), and DIALOG_SHIM::ShowQuasiModal().

Referenced by SetTransitions().

993 {
994  const auto& selection = m_selectionTool->RequestSelection();
995 
996  if( selection.Empty() )
997  return 0;
998 
999  MODULE* mod = selection.FirstOfKind<MODULE> ();
1000 
1001  if( !mod )
1002  return 0;
1003 
1004  frame()->SetCurItem( mod );
1005 
1006  // Footprint exchange could remove modules, so they have to be
1007  // removed from the selection first
1009 
1010  // invoke the exchange dialog process
1011  {
1012  DIALOG_EXCHANGE_MODULE dialog( frame(), mod );
1013  dialog.ShowQuasiModal();
1014  }
1015 
1016  // The current item can be deleted by exchange module, and the
1017  // selection is emptied, so remove current item from frame info area
1018  frame()->SetCurItem( nullptr );
1019 
1020  return 0;
1021 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void SetCurItem(BOARD_ITEM *aItem, bool aDisplayInfo=true)
Function SetCurItem sets the currently selected item and displays it in the MsgPanel.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:109
#define mod(a, n)
Definition: greymap.cpp:24
int EDIT_TOOL::Flip ( const TOOL_EVENT aEvent)

Function Flip()

Rotates currently selected items. The rotation point is the current cursor position.

Definition at line 632 of file edit_tool.cpp.

References SELECTION_TOOL::CheckLock(), getModificationPoint(), m_commit, m_dragging, m_offset, m_selectionTool, TOOL_BASE::m_toolMgr, SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), SELECTION_LOCKED, PCB_ACTIONS::selectionClear, and PCB_ACTIONS::selectionModified.

Referenced by SetTransitions().

633 {
634  const auto& selection = m_selectionTool->RequestSelection();
635 
637  return 0;
638 
639  if( selection.Empty() )
640  return 0;
641 
642  wxPoint modPoint = getModificationPoint( selection );
643 
644  for( auto item : selection )
645  {
646  m_commit->Modify( item );
647  static_cast<BOARD_ITEM*>( item )->Flip( modPoint );
648  }
649 
650  // Update the dragging point offset
651  m_offset = static_cast<BOARD_ITEM*>( selection.Front() )->GetPosition() - modPoint;
652 
653  if( !m_dragging )
654  m_commit->Push( _( "Flip" ) );
655 
656  if( selection.IsHover() )
658 
660 
661  return 0;
662 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
wxPoint getModificationPoint(const SELECTION &aSelection)
Returns the right modification point (e.g.
Definition: edit_tool.cpp:1137
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
wxPoint m_offset
Offset from the dragged item's center (anchor)
Definition: edit_tool.h:141
static TOOL_ACTION selectionModified
Modified selection notification.
Definition: pcb_actions.h:99
int Flip(const TOOL_EVENT &aEvent)
Function Flip()
Definition: edit_tool.cpp:632
bool m_dragging
Flag determining if anything is being dragged right now
Definition: edit_tool.h:138
template<typename T >
T* TOOL_BASE::getEditFrame ( ) const
inlineprotectedinherited

Function getEditFrame()

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

Definition at line 193 of file tool_base.h.

References TOOL_BASE::getEditFrameInt().

Referenced by ZONE_CREATE_HELPER::commitZone(), ZONE_CREATE_HELPER::createNewZone(), TOOL_SETTINGS::getConfigBase(), and ZONE_CREATE_HELPER::performZoneCutout().

194  {
195  return static_cast<T*>( getEditFrameInt() );
196  }
T
enum T contains all this lexer's tokens.
wxWindow * getEditFrameInt() const
Definition: tool_base.cpp:42
TOOL_ID TOOL_BASE::GetId ( ) const
inlineinherited

Function GetId() Returns the unique identifier of the tool.

The identifier is set by an instance of TOOL_MANAGER.

Returns
Identifier of the tool.

Definition at line 122 of file tool_base.h.

References TOOL_BASE::m_toolId.

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

123  {
124  return m_toolId;
125  }
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:215
TOOL_MANAGER* TOOL_BASE::GetManager ( ) const
inlineinherited

Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool.

Returns
Instance of the TOOL_MANAGER. If there is no TOOL_MANAGER associated, it returns NULL.

Definition at line 144 of file tool_base.h.

References TOOL_BASE::m_toolMgr.

Referenced by BOARD_COMMIT::BOARD_COMMIT(), PCB_TOOL::doInteractiveItemPlacement(), CONTEXT_MENU::getToolManager(), MeasureTool(), and CONTEXT_MENU::onMenuEvent().

145  {
146  return m_toolMgr;
147  }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
template<typename T >
T* TOOL_BASE::getModel ( ) const
inlineprotectedinherited

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 204 of file tool_base.h.

References TOOL_BASE::getModelInt().

Referenced by ZONE_CREATE_HELPER::createNewZone(), ZONE_CREATE_HELPER::createZoneFromExisting(), and ZONE_CREATE_HELPER::performZoneCutout().

205  {
206  EDA_ITEM* m = getModelInt();
207 
208  return static_cast<T*>( m );
209  }
T
enum T contains all this lexer's tokens.
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
EDA_ITEM * getModelInt() const
Definition: tool_base.cpp:48
wxPoint EDIT_TOOL::getModificationPoint ( const SELECTION aSelection)
private

Returns the right modification point (e.g.

for rotation), depending on the number of

selected items.

Definition at line 1137 of file edit_tool.cpp.

References SELECTION::Front(), TOOL_MANAGER::GetCurrentToolId(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), TOOL_BASE::getViewControls(), m_cursor, m_offset, TOOL_BASE::m_toolId, TOOL_BASE::m_toolMgr, SELECTION::Size(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Flip(), Main(), Mirror(), and Rotate().

1138 {
1139  if( aSelection.Size() == 1 )
1140  {
1141  return static_cast<BOARD_ITEM*>( aSelection.Front() )->GetPosition() - m_offset;
1142  }
1143  else
1144  {
1145  // If EDIT_TOOL is not currently active then it means that the cursor position is not
1146  // updated, so we have to fetch the latest value
1147  if( m_toolMgr->GetCurrentToolId() != m_toolId )
1149 
1150  return wxPoint( m_cursor.x, m_cursor.y );
1151  }
1152 }
VECTOR2I m_cursor
Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point)...
Definition: edit_tool.h:145
int GetCurrentToolId() const
Returns id of the tool that is on the top of the active tools stack (was invoked the most recently)...
Definition: tool_manager.h:268
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
EDA_ITEM * Front() const
Definition: selection.h:144
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:215
wxPoint m_offset
Offset from the dragged item's center (anchor)
Definition: edit_tool.h:141
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:36
int Size() const
Returns the number of selected parts.
Definition: selection.h:112
const std::string& TOOL_BASE::GetName ( void  ) const
inlineinherited

Function GetName() Returns 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.

References TOOL_BASE::m_toolName.

Referenced by TOOL_SETTINGS::getKeyName(), TOOL_MANAGER::InitTools(), TOOL_MANAGER::invokeTool(), and TOOL_MANAGER::RegisterTool().

134  {
135  return m_toolName;
136  }
std::string m_toolName
Name of the tool.
Definition: tool_base.h:219
TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 72 of file tool_base.cpp.

References TOOL_BASE::m_toolSettings.

Referenced by ROUTER_TOOL::Init(), SELECTION_TOOL::selectable(), and ROUTER_TOOL::~ROUTER_TOOL().

73 {
74  return m_toolSettings;
75 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:221
TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Function GetType() Returns the type of the tool.

Returns
The type of the tool.

Definition at line 111 of file tool_base.h.

References TOOL_BASE::m_type.

Referenced by TOOL_MANAGER::InvokeTool(), and TOOL_MANAGER::runTool().

112  {
113  return m_type;
114  }
TOOL_TYPE m_type
Stores the type of the tool.
Definition: tool_base.h:212
KIGFX::VIEW * TOOL_BASE::getView ( ) const
protectedinherited

Function getView()

Returns the instance of VIEW object used in the application. It allows tools to draw.

Returns
The instance of VIEW.

Definition at line 30 of file tool_base.cpp.

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

Referenced by PCB_EDITOR_CONTROL::CrossProbeSchToPcb(), PCBNEW_CONTROL::CursorControl(), SELECTION_TOOL::disambiguationMenu(), PCB_TOOL::doInteractiveItemPlacement(), MICROWAVE_TOOL::drawMicrowaveInductor(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), SELECTION_TOOL::findCallback(), ROUTER_TOOL::getStartLayer(), PCBNEW_CONTROL::GridSetOrigin(), PCBNEW_CONTROL::HighContrastMode(), PNS::TOOL_BASE::highlightNet(), PCB_EDITOR_CONTROL::HighlightNet(), PCBNEW_CONTROL::LayerAlphaDec(), PCBNEW_CONTROL::LayerAlphaInc(), Main(), MeasureTool(), MODULE_EDITOR_TOOLS::ModuleEdgeOutlines(), MODULE_EDITOR_TOOLS::ModuleTextOutlines(), MoveExact(), POINT_EDITOR::OnSelectionChange(), PCBNEW_CONTROL::PadDisplayMode(), PCBNEW_CONTROL::PanControl(), PNS::TOOL_BASE::pickSingleItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), PCB_EDITOR_CONTROL::Reset(), PCBNEW_CONTROL::Reset(), MODULE_EDITOR_TOOLS::Reset(), PNS::TOOL_BASE::Reset(), DRAWING_TOOL::Reset(), SELECTION_TOOL::Reset(), SELECTION_TOOL::selectable(), SELECTION_TOOL::selectionContains(), SELECTION_TOOL::selectMultiple(), ZOOM_TOOL::selectRegion(), PCBNEW_CONTROL::TrackDisplayMode(), POINT_EDITOR::updateEditedPoint(), PNS::TOOL_BASE::updateEndItem(), COMMON_TOOLS::updateGrid(), PCBNEW_CONTROL::updateGrid(), POINT_EDITOR::updatePoints(), SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), PCBNEW_CONTROL::ViaDisplayMode(), PCB_TOOL::view(), PCBNEW_CONTROL::ZoneDisplayMode(), PCB_EDITOR_CONTROL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneFillAll(), PCB_EDITOR_CONTROL::ZoneUnfill(), PCB_EDITOR_CONTROL::ZoneUnfillAll(), COMMON_TOOLS::ZoomFitScreen(), SELECTION_TOOL::zoomFitSelection(), COMMON_TOOLS::ZoomInOutCenter(), and SELECTION_TOOL::~SELECTION_TOOL().

31 {
32  return m_toolMgr->GetView();
33 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:243
KIGFX::VIEW_CONTROLS * TOOL_BASE::getViewControls ( ) const
protectedinherited
template<class T >
void TOOL_INTERACTIVE::Go ( int(T::*)(const TOOL_EVENT &)  aStateFunc,
const TOOL_EVENT_LIST aConditions = TOOL_EVENTTC_ANYTA_ANY ) 
)
inherited

Function Go()

Defines which state (aStateFunc) to go when a certain event arrives (aConditions). No conditions means any event.

Definition at line 122 of file tool_interactive.h.

References TOOL_INTERACTIVE::goInternal().

Referenced by LENGTH_TUNER_TOOL::Reset(), ZOOM_TOOL::SetTransitions(), LENGTH_TUNER_TOOL::SetTransitions(), ROUTER_TOOL::SetTransitions(), PAD_TOOL::SetTransitions(), MICROWAVE_TOOL::SetTransitions(), POINT_EDITOR::SetTransitions(), COMMON_TOOLS::SetTransitions(), PLACEMENT_TOOL::SetTransitions(), PCBNEW_CONTROL::SetTransitions(), MODULE_EDITOR_TOOLS::SetTransitions(), PICKER_TOOL::SetTransitions(), PCB_EDITOR_CONTROL::SetTransitions(), SELECTION_TOOL::SetTransitions(), SetTransitions(), and DRAWING_TOOL::SetTransitions().

124 {
125  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
126 
127  goInternal( sptr, aConditions );
128 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:59
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)
bool EDIT_TOOL::hoverSelection ( bool  aSanitize = true)
private

Function hoverSelection()

If there are no items currently selected, it tries to choose the item that is under he cursor or displays a disambiguation menu if there are multiple items.

Parameters
aSanitizesanitize selection using SanitizeSelection()
Returns
true if the eventual selection contains any items, or false if it fails to select any items.

Referenced by uniqueHoverSelection().

bool EDIT_TOOL::Init ( )
overridevirtual

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

Returns
True if the initialization went fine, false - otherwise.

Reimplemented from TOOL_BASE.

Definition at line 177 of file edit_tool.cpp.

References CONDITIONAL_MENU::AddItem(), SELECTION_CONDITIONS::Count(), PCB_ACTIONS::createArray, DisplayError(), PCB_ACTIONS::duplicate, PCB_ACTIONS::editActivate, PCB_ACTIONS::editFootprintInFpEditor, PCB_ACTIONS::exchangeFootprints, TOOL_MANAGER::FindTool(), PCB_ACTIONS::flip, TOOL_MENU::GetMenu(), SELECTION_TOOL::GetToolMenu(), PCB_TOOL::m_editModules, m_offset, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_ACTIONS::mirror, PCB_ACTIONS::moveExact, SELECTION_CONDITIONS::NotEmpty(), SELECTION_CONDITIONS::OnlyType(), SELECTION_CONDITIONS::OnlyTypes(), PCB_MODULE_T, PCB_ACTIONS::properties, PCB_ACTIONS::remove, PCB_ACTIONS::rotateCcw, PCB_ACTIONS::rotateCw, GENERAL_COLLECTOR::Tracks, wxPoint::x, and wxPoint::y.

178 {
179  // Find the selection tool, so they can cooperate
180  m_selectionTool = static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) );
181 
182  if( !m_selectionTool )
183  {
184  DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) );
185  return false;
186  }
187 
188  auto editingModuleCondition = [ this ] ( const SELECTION& aSelection ) {
189  return m_editModules;
190  };
191 
192  auto singleModuleCondition = SELECTION_CONDITIONS::OnlyType( PCB_MODULE_T )
194 
195  // Add context menu entries that are displayed when selection tool is active
207 
208  // Mirror only available in modedit
209  menu.AddItem( PCB_ACTIONS::mirror, editingModuleCondition && SELECTION_CONDITIONS::NotEmpty );
210 
211  // Footprint actions
213  singleModuleCondition );
215  singleModuleCondition );
216 
217  m_offset.x = 0;
218  m_offset.y = 0;
219 
220  return true;
221 }
TOOL_BASE * FindTool(int aId) const
Function FindTool() Searches for a tool with given ID.
static TOOL_ACTION editActivate
Activation of the edit tool.
Definition: pcb_actions.h:81
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:294
Class SELECTION_TOOL.
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:49
TOOL_MENU & GetToolMenu()
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:96
static TOOL_ACTION mirror
Mirroring of selected items.
Definition: pcb_actions.h:93
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
wxPoint m_offset
Offset from the dragged item's center (anchor)
Definition: edit_tool.h:141
static SELECTION_CONDITION Count(int aNumber)
Function Count Creates a functor that tests if the number of selected items is equal to the value giv...
static bool NotEmpty(const SELECTION &aSelection)
Function NotEmpty Tests if there are any items selected.
static TOOL_ACTION moveExact
Activation of the exact move tool.
Definition: pcb_actions.h:102
static TOOL_ACTION duplicate
Activation of the duplication tool.
Definition: pcb_actions.h:105
class MODULE, a footprint
Definition: typeinfo.h:101
static TOOL_ACTION rotateCw
Rotation of selected objects clockwise.
Definition: pcb_actions.h:84
static SELECTION_CONDITION OnlyTypes(const std::vector< KICAD_T > &aTypes)
Function OnlyTypes Creates a functor that tests if the selected items are only of given types...
static TOOL_ACTION createArray
Tool for creating an array of objects.
Definition: pcb_actions.h:273
static TOOL_ACTION exchangeFootprints
Exchange footprints of modules.
Definition: pcb_actions.h:111
bool m_editModules
Definition: pcb_tool.h:112
static TOOL_ACTION rotateCcw
Rotation of selected objects counter-clockwise.
Definition: pcb_actions.h:87
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:90
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddItem()
static TOOL_ACTION editFootprintInFpEditor
Definition: pcb_actions.h:356
static SELECTION_CONDITION OnlyType(KICAD_T aType)
Function OnlyType Creates a functor that tests if the selected items are only of given type...
static TOOL_ACTION remove
Deleting a BOARD_ITEM.
Definition: pcb_actions.h:114
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
bool EDIT_TOOL::invokeInlineRouter ( )
private

Definition at line 224 of file edit_tool.cpp.

References TOOL_MANAGER::FindTool(), PNS::ROUTING_SETTINGS::InlineDragEnabled(), TOOL_BASE::m_toolMgr, PNS::TOOL_BASE::PNSSettings(), PCB_ACTIONS::routerInlineDrag, TOOL_MANAGER::RunAction(), and PNS::theRouter.

Referenced by Main().

227 {
228  TRACK* track = uniqueSelected<TRACK>();
229  VIA* via = uniqueSelected<VIA>();
230 
231  if( track || via )
232  {
233  ROUTER_TOOL* theRouter = static_cast<ROUTER_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveRouter" ) );
234  assert( theRouter );
235 
236  if( !theRouter->PNSSettings().InlineDragEnabled() )
237  return false;
238 
240  return true;
241  }
242 
243  return false;
244 }
TOOL_BASE * FindTool(int aId) const
Function FindTool() Searches for a tool with given ID.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
const ROUTING_SETTINGS & PNSSettings() const
Definition: pns_tool_base.h:54
static TOOL_ACTION routerInlineDrag
Activation of the Push and Shove router (inline dragging mode)
Definition: pcb_actions.h:189
static ROUTER * theRouter
Definition: pns_router.cpp:66
int EDIT_TOOL::Main ( const TOOL_EVENT aEvent)

Function Main()

Main loop in which events are handled.

Parameters
aEventis the handled event.

Definition at line 247 of file edit_tool.cpp.

References TOOL_INTERACTIVE::Activate(), GRID_HELPER::Align(), GRID_HELPER::BestDragOrigin(), GRID_HELPER::BestSnapAnchor(), BUT_LEFT, SELECTION_TOOL::CheckLock(), PCB_ACTIONS::duplicate, PCB_ACTIONS::editActivate, KIGFX::VIEW_CONTROLS::ForceCursorPosition(), KIGFX::VIEW_CONTROLS::GetCursorPosition(), getModificationPoint(), BOARD_ITEM::GetPosition(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), invokeInlineRouter(), SELECTION::IsHover(), m_commit, m_cursor, m_dragging, m_offset, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_ACTIONS::moveExact, PCB_ACTIONS::remove, SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), SELECTION_DEFAULT, SELECTION_DELETABLE, SELECTION_LOCK_OVERRIDE, SELECTION_LOCKED, PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionModified, KIGFX::VIEW_CONTROLS::SetAutoPan(), GRID_HELPER::SetAuxAxes(), BOARD_ITEM::SetPosition(), KIGFX::VIEW_CONTROLS::SetSnapping(), KIGFX::VIEW_CONTROLS::ShowCursor(), TA_UNDO_REDO_PRE, TC_COMMAND, TC_MOUSE, KIGFX::VIEW::Update(), TOOL_INTERACTIVE::Wait(), KIGFX::VIEW_CONTROLS::WarpCursor(), wxPoint::x, VECTOR2< T >::x, wxPoint::y, and VECTOR2< T >::y.

Referenced by Duplicate(), and SetTransitions().

248 {
250  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
251 
252  VECTOR2I originalCursorPos = controls->GetCursorPosition();
253 
254  // Be sure that there is at least one item that we can modify. If nothing was selected before,
255  // try looking for the stuff under mouse cursor (i.e. Kicad old-style hover selection)
257 
258  if( selection.Empty() )
259  return 0;
260 
261  bool unselect = selection.IsHover();
262 
263  Activate();
264 
265  m_dragging = false; // Are selected items being dragged?
266  bool restore = false; // Should items' state be restored when finishing the tool?
267  bool lockOverride = false;
268 
269  controls->ShowCursor( true );
270  controls->SetSnapping( true );
271  controls->SetAutoPan( true );
272 
273  // cumulative translation
274  wxPoint totalMovement( 0, 0 );
275 
276  GRID_HELPER grid( editFrame );
277  OPT_TOOL_EVENT evt = aEvent;
278 
279  // Main loop: keep receiving events
280  do
281  {
282  if( evt->IsAction( &PCB_ACTIONS::editActivate )
283  || evt->IsMotion() || evt->IsDrag( BUT_LEFT ) )
284  {
285  if( selection.Empty() )
286  break;
287 
288  BOARD_ITEM* curr_item = static_cast<BOARD_ITEM*>( selection.Front() );
289 
290  if( m_dragging && evt->Category() == TC_MOUSE )
291  {
292  m_cursor = grid.BestSnapAnchor( evt->Position(), curr_item );
293  controls->ForceCursorPosition( true, m_cursor );
294 
295  wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) - curr_item->GetPosition();
296  totalMovement += movement;
297 
298  // Drag items to the current cursor position
299  for( auto item : selection )
300  static_cast<BOARD_ITEM*>( item )->Move( movement + m_offset );
301  }
302  else if( !m_dragging ) // Prepare to start dragging
303  {
304  if( !invokeInlineRouter() )
305  {
307 
308  if( selection.Empty() )
309  break;
310 
311  // deal with locked items (override lock or abort the operation)
313 
314  if( lockFlags == SELECTION_LOCKED )
315  break;
316  else if( lockFlags == SELECTION_LOCK_OVERRIDE )
317  lockOverride = true;
318 
319  // Save items, so changes can be undone
320  for( auto item : selection )
321  m_commit->Modify( item );
322 
323  m_cursor = controls->GetCursorPosition();
324 
325  if( selection.Size() == 1 )
326  {
327  // Set the current cursor position to the first dragged item origin, so the
328  // movement vector could be computed later
329  m_cursor = grid.BestDragOrigin( originalCursorPos, curr_item );
330  grid.SetAuxAxes( true, m_cursor );
331  }
332  else
333  {
334  m_cursor = grid.Align( m_cursor );
335  }
336 
337  controls->ForceCursorPosition( true, m_cursor );
338  controls->WarpCursor( m_cursor, true );
339 
340  VECTOR2I o = VECTOR2I( curr_item->GetPosition() );
341  m_offset.x = o.x - m_cursor.x;
342  m_offset.y = o.y - m_cursor.y;
343 
344  controls->SetAutoPan( true );
345  m_dragging = true;
346  }
347  }
348 
350  }
351 
352  else if( evt->IsCancel() || evt->IsActivate() )
353  {
354  restore = true; // Cancelling the tool means that items have to be restored
355  break; // Finish
356  }
357 
358  else if( evt->Action() == TA_UNDO_REDO_PRE )
359  {
360  unselect = true;
361  break;
362  }
363 
364  // Dispatch TOOL_ACTIONs
365  else if( evt->Category() == TC_COMMAND )
366  {
367  wxPoint modPoint = getModificationPoint( selection );
368 
369  if( evt->IsAction( &PCB_ACTIONS::remove ) )
370  {
371  // exit the loop, as there is no further processing for removed items
372  break;
373  }
374  else if( evt->IsAction( &PCB_ACTIONS::duplicate ) )
375  {
376  // On duplicate, stop moving this item
377  // The duplicate tool should then select the new item and start
378  // a new move procedure
379  break;
380  }
381  else if( evt->IsAction( &PCB_ACTIONS::moveExact ) )
382  {
383  // Can't do this, because the selection will then contain
384  // stale pointers and it will all go horribly wrong...
385  //editFrame->RestoreCopyFromUndoList( dummy );
386  //
387  // So, instead, reset the position manually
388  for( auto item : selection )
389  {
390  BOARD_ITEM* i = static_cast<BOARD_ITEM*>( item );
391  i->SetPosition( i->GetPosition() - totalMovement );
392 
393  // And what about flipping and rotation?
394  // for now, they won't be undone, but maybe that is how
395  // it should be, so you can flip and move exact in the
396  // same action?
397  }
398 
399  // This causes a double event, so we will get the dialogue
400  // correctly, somehow - why does Rotate not?
401  //MoveExact( aEvent );
402  break; // exit the loop - we move exactly, so we have finished moving
403  }
404 
405  if( m_dragging )
406  {
407  // Update dragging offset (distance between cursor and the first dragged item)
408  m_offset = static_cast<BOARD_ITEM*>( selection.Front() )->GetPosition() - modPoint;
409  getView()->Update( &selection );
410  }
411  }
412 
413  else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
414  {
415  if( !lockOverride )
416  break; // Finish
417 
418  lockOverride = false;
419  }
420  } while( ( evt = Wait() ) ); //Should be assignment not equality test
421 
422  controls->ForceCursorPosition( false );
423  controls->ShowCursor( false );
424  controls->SetSnapping( false );
425  controls->SetAutoPan( false );
426 
427  m_dragging = false;
428  m_offset.x = 0;
429  m_offset.y = 0;
430 
431  if( unselect || restore )
433 
434  if( restore )
435  m_commit->Revert();
436  else
437  m_commit->Push( _( "Drag" ) );
438 
439  return 0;
440 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
wxPoint getModificationPoint(const SELECTION &aSelection)
Returns the right modification point (e.g.
Definition: edit_tool.cpp:1137
virtual void ShowCursor(bool aEnabled)
Function ShowCursor() Enables or disables display of cursor.
VECTOR2I m_cursor
Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point)...
Definition: edit_tool.h:145
static TOOL_ACTION editActivate
Activation of the edit tool.
Definition: pcb_actions.h:81
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
virtual void SetPosition(const wxPoint &aPos)=0
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
virtual const wxPoint & GetPosition() const =0
virtual void SetSnapping(bool aEnabled)
Function SetSnapping() Enables/disables snapping cursor to grid.
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
wxPoint m_offset
Offset from the dragged item's center (anchor)
Definition: edit_tool.h:141
VECTOR2< int > VECTOR2I
Definition: vector2d.h:590
static TOOL_ACTION selectionModified
Modified selection notification.
Definition: pcb_actions.h:99
static TOOL_ACTION moveExact
Activation of the exact move tool.
Definition: pcb_actions.h:102
static TOOL_ACTION duplicate
Activation of the duplication tool.
Definition: pcb_actions.h:105
virtual void WarpCursor(const VECTOR2D &aPosition, bool aWorldCoordinates=false, bool aWarpView=false) const =0
Function WarpCursor() If enabled (.
virtual VECTOR2D GetCursorPosition() const =0
Function GetCursorPosition() Returns the current cursor position in world coordinates.
bool m_dragging
Flag determining if anything is being dragged right now
Definition: edit_tool.h:138
SELECTION_LOCK_FLAGS
Definition: selection.h:184
Class VIEW_CONTROLS is an interface for classes handling user events controlling the view behaviour (...
Definition: view_controls.h:94
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Function ForceCursorPosition() Places the cursor immediately at a given point.
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
bool invokeInlineRouter()
Definition: edit_tool.cpp:224
virtual void SetAutoPan(bool aEnabled)
Function SetAutoPan Turns on/off auto panning (this feature is used when there is a tool active (eg...
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:36
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
Common, abstract interface for edit frames.
bool IsHover() const
Definition: selection.h:66
void Activate()
Function Activate() Runs the tool.
static TOOL_ACTION remove
Deleting a BOARD_ITEM.
Definition: pcb_actions.h:114
int EDIT_TOOL::MeasureTool ( const TOOL_EVENT aEvent)

Launches a tool to measure between points

Definition at line 1024 of file edit_tool.cpp.

References TOOL_INTERACTIVE::Activate(), KIGFX::VIEW::Add(), BUT_LEFT, BUT_RIGHT, PCB_TOOL::EditingModules(), PCB_TOOL::frame(), KIGFX::GEOMETRY, TOOL_BASE::GetManager(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), ID_MODEDIT_MEASUREMENT_TOOL, ID_NO_TOOL_SELECTED, ID_PCB_MEASUREMENT_TOOL, MD_CTRL, TOOL_MANAGER::PassEvent(), KIGFX::VIEW::Remove(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetAngleSnap(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetEnd(), KIGFX::PREVIEW::TWO_POINT_GEOMETRY_MANAGER::SetOrigin(), PCB_BASE_FRAME::SetToolID(), KIGFX::VIEW::SetVisible(), KIGFX::VIEW::Update(), PCB_TOOL::view(), and TOOL_INTERACTIVE::Wait().

Referenced by SetTransitions().

1025 {
1026  auto& view = *getView();
1027  auto& controls = *getViewControls();
1028 
1029  Activate();
1032  wxCURSOR_PENCIL, _( "Measure distance between two points" ) );
1033 
1035 
1036  KIGFX::PREVIEW::RULER_ITEM ruler( twoPtMgr );
1037 
1038  view.Add( &ruler );
1039  view.SetVisible( &ruler, false );
1040 
1041  bool originSet = false;
1042 
1043  controls.ShowCursor( true );
1044  controls.SetSnapping( true );
1045 
1046  while( auto evt = Wait() )
1047  {
1048  const VECTOR2I cursorPos = controls.GetCursorPosition();
1049 
1050  if( evt->IsCancel() || evt->IsActivate() )
1051  {
1052  break;
1053  }
1054 
1055  // click or drag starts
1056  else if( !originSet &&
1057  ( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) )
1058  {
1059  if( !evt->IsDrag( BUT_LEFT ) )
1060  {
1061  twoPtMgr.SetOrigin( cursorPos );
1062  twoPtMgr.SetEnd( cursorPos );
1063  }
1064 
1065  controls.CaptureCursor( true );
1066  controls.SetAutoPan( true );
1067 
1068  originSet = true;
1069  }
1070 
1071  else if( !originSet && evt->IsMotion() )
1072  {
1073  // make sure the origin is set before a drag starts
1074  // otherwise you can miss a step
1075  twoPtMgr.SetOrigin( cursorPos );
1076  twoPtMgr.SetEnd( cursorPos );
1077  }
1078 
1079  // second click or mouse up after drag ends
1080  else if( originSet &&
1081  ( evt->IsClick( BUT_LEFT ) || evt->IsMouseUp( BUT_LEFT ) ) )
1082  {
1083  originSet = false;
1084 
1085  controls.SetAutoPan( false );
1086  controls.CaptureCursor( false );
1087 
1088  view.SetVisible( &ruler, false );
1089  }
1090 
1091  // move or drag when origin set updates rules
1092  else if( originSet &&
1093  ( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) )
1094  {
1095  twoPtMgr.SetAngleSnap( evt->Modifier( MD_CTRL ) );
1096  twoPtMgr.SetEnd( cursorPos );
1097 
1098  view.SetVisible( &ruler, true );
1099  view.Update( &ruler, KIGFX::GEOMETRY );
1100  }
1101 
1102  else if( evt->IsClick( BUT_RIGHT ) )
1103  {
1104  GetManager()->PassEvent();
1105  }
1106  }
1107 
1108  view.SetVisible( &ruler, false );
1109  view.Remove( &ruler );
1110 
1111  frame()->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
1112 
1113  return 0;
1114 }
KIGFX::VIEW * view() const
Definition: pcb_tool.h:108
virtual void SetToolID(int aId, int aCursor, const wxString &aToolMsg) override
Function SetToolID sets the tool command ID to aId and sets the cursor to aCursor.
PCB_EDIT_FRAME::OnResetModuleTextSizes PCB_EDIT_FRAME::OnSelectOptionToolbar PCB_EDIT_FRAME::OnSelectOptionToolbar PCB_EDIT_FRAME::OnSelectOptionToolbar PCB_EDIT_FRAME::OnSelectOptionToolbar ID_PCB_MEASUREMENT_TOOL
Definition: pcbframe.cpp:262
Class TWO_POINT_GEOMETRY_MANAGER.
void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:341
OPT_TOOL_EVENT Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Function Wait()
void PassEvent()
Allows a tool to pass the already handled event to the next tool on the stack.
Definition: tool_manager.h:336
PCB_EDIT_FRAME * frame() const
Definition: pcb_tool.h:109
void SetOrigin(const VECTOR2I &aOrigin)
Set the origin of the ruler (the fixed end)
Class RULER_ITEM.
Definition: ruler_item.h:43
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:36
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
bool EditingModules() const
Definition: pcb_tool.h:78
TOOL_MANAGER * GetManager() const
Function GetManager() Returns the instance of TOOL_MANAGER that takes care of the tool...
Definition: tool_base.h:144
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Function SetVisible() Sets the item visibility.
Definition: view.cpp:1331
void Activate()
Function Activate() Runs the tool.
void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:311
void SetEnd(const VECTOR2I &aEnd)
Set the current end of the rectangle (the end that moves with the cursor.
Color has changed.
Definition: view_item.h:57
int EDIT_TOOL::Mirror ( const TOOL_EVENT aEvent)

Function Mirror.

Mirrors the current selection. The mirror axis passes through the current point.

Definition at line 563 of file edit_tool.cpp.

References SELECTION_TOOL::CheckLock(), getModificationPoint(), m_commit, m_dragging, m_selectionTool, TOOL_BASE::m_toolMgr, EDGE_MODULE::Mirror(), TEXTE_MODULE::Mirror(), mirrorPadX(), PCB_MODULE_EDGE_T, PCB_MODULE_TEXT_T, PCB_PAD_T, SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), SELECTION_LOCKED, PCB_ACTIONS::selectionClear, and PCB_ACTIONS::selectionModified.

Referenced by SetTransitions().

564 {
565  const auto& selection = m_selectionTool->RequestSelection();
566 
568  return 0;
569 
570  if( selection.Empty() )
571  return 0;
572 
573  wxPoint mirrorPoint = getModificationPoint( selection );
574 
575  for( auto item : selection )
576  {
577  // only modify items we can mirror
578  switch( item->Type() )
579  {
580  case PCB_MODULE_EDGE_T:
581  case PCB_MODULE_TEXT_T:
582  case PCB_PAD_T:
583  m_commit->Modify( item );
584  break;
585  default:
586  continue;
587  }
588 
589  // modify each object as necessary
590  switch( item->Type() )
591  {
592  case PCB_MODULE_EDGE_T:
593  {
594  auto& edge = static_cast<EDGE_MODULE&>( *item );
595  edge.Mirror( mirrorPoint, false );
596  break;
597  }
598 
599  case PCB_MODULE_TEXT_T:
600  {
601  auto& modText = static_cast<TEXTE_MODULE&>( *item );
602  modText.Mirror( mirrorPoint, false );
603  break;
604  }
605 
606  case PCB_PAD_T:
607  {
608  auto& pad = static_cast<D_PAD&>( *item );
609  mirrorPadX( pad, mirrorPoint );
610  break;
611  }
612 
613  default:
614  // it's likely the commit object is wrong if you get here
615  assert( false );
616  break;
617  }
618  }
619 
620  if( !m_dragging )
621  m_commit->Push( _( "Mirror" ) );
622 
623  if( selection.IsHover() )
625 
627 
628  return 0;
629 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
wxPoint getModificationPoint(const SELECTION &aSelection)
Returns the right modification point (e.g.
Definition: edit_tool.cpp:1137
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
class EDGE_MODULE, a footprint edge
Definition: typeinfo.h:106
static TOOL_ACTION selectionModified
Modified selection notification.
Definition: pcb_actions.h:99
void Mirror(const wxPoint aCentre, bool aMirrorAroundXAxis)
Mirror an edge of the footprint.
bool m_dragging
Flag determining if anything is being dragged right now
Definition: edit_tool.h:138
class TEXTE_MODULE, text in a footprint
Definition: typeinfo.h:105
void Mirror(const wxPoint &aCentre, bool aMirrorAroundXAxis)
Mirror text position in footprint edition the text itself is not mirrored, and the layer not modified...
static void mirrorPadX(D_PAD &aPad, const wxPoint &aMirrorPoint)
Mirror a pad in the vertical axis passing through a point.
Definition: edit_tool.cpp:543
int EDIT_TOOL::MoveExact ( const TOOL_EVENT aEvent)

Function MoveExact()

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

Definition at line 703 of file edit_tool.cpp.

References ANCHOR_CENTER_FOOTPRINT, ANCHOR_FROM_LIBRARY, ANCHOR_TOP_LEFT_PAD, SELECTION_TOOL::CheckLock(), MOVE_PARAMETERS::editingFootprint, PCB_BASE_FRAME::GetAuxOrigin(), EDA_ITEM::GetBoundingBox(), EDA_RECT::GetCenter(), MODULE::GetFootprintRect(), PCB_BASE_FRAME::GetGridOrigin(), BOARD_ITEM::GetPosition(), EDA_RECT::GetPosition(), MODULE::GetPosition(), PCB_BASE_FRAME::GetScreen(), MODULE::GetTopLeftPad(), TOOL_BASE::getView(), m_commit, m_dragging, PCB_TOOL::m_editModules, BASE_SCREEN::m_O_Curseur, m_selectionTool, TOOL_BASE::m_toolMgr, mod, PAD_ATTRIB_SMD, PCB_MODULE_T, PCB_PAD_T, RELATIVE_TO_CURRENT_POSITION, RELATIVE_TO_DRILL_PLACE_ORIGIN, RELATIVE_TO_GRID_ORIGIN, RELATIVE_TO_SHEET_ORIGIN, RELATIVE_TO_USER_ORIGIN, SELECTION_TOOL::RequestSelection(), Rotate(), TOOL_MANAGER::RunAction(), SELECTION_LOCKED, PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionModified, EDA_ITEM::Type(), KIGFX::VIEW::Update(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by SetTransitions().

704 {
705  const auto& selection = m_selectionTool->RequestSelection();
706 
708  return 0;
709 
710  if( selection.Empty() )
711  return 0;
712 
713  PCB_BASE_FRAME* editFrame = getEditFrame<PCB_BASE_FRAME>();
714 
715  MOVE_PARAMETERS params;
717 
718  DIALOG_MOVE_EXACT dialog( editFrame, params );
719  int ret = dialog.ShowModal();
720 
721  if( ret == wxID_OK )
722  {
723  VECTOR2I rp = selection.GetCenter();
724  wxPoint rotPoint( rp.x, rp.y );
725 
726  // Begin at the center of the selection determined above
727  wxPoint anchorPoint = rotPoint;
728 
729  // If the anchor is not ANCHOR_FROM_LIBRARY then the user applied an override.
730  // Also run through this block if only one item is slected because it may be a module,
731  // in which case we want something different than the center of the selection
732  if( ( params.anchor != ANCHOR_FROM_LIBRARY ) || ( selection.GetSize() == 1 ) )
733  {
734  BOARD_ITEM* topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftModule() );
735 
736  // no module found if the GetTopLeftModule() returns null, retry for
737  if( topLeftItem == nullptr )
738  {
739  topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
740  anchorPoint = topLeftItem->GetPosition();
741  }
742 
743  if( topLeftItem->Type() == PCB_MODULE_T )
744  {
745  // Cast to module to allow access to the pads
746  MODULE* mod = static_cast<MODULE*>( topLeftItem );
747 
748  switch( params.anchor )
749  {
750  case ANCHOR_FROM_LIBRARY:
751  anchorPoint = mod->GetPosition();
752  break;
753  case ANCHOR_TOP_LEFT_PAD:
754  topLeftItem = mod->GetTopLeftPad();
755  break;
757  anchorPoint = mod->GetFootprintRect().GetCenter();
758  break;
759  }
760  }
761 
762  if( topLeftItem->Type() == PCB_PAD_T )
763  {
764  if( static_cast<D_PAD*>( topLeftItem )->GetAttribute() == PAD_ATTRIB_SMD )
765  {
766  // Use the top left corner of SMD pads as an anchor instead of the center
767  anchorPoint = topLeftItem->GetBoundingBox().GetPosition();
768  }
769  else
770  {
771  anchorPoint = topLeftItem->GetPosition();
772  }
773  }
774  }
775 
776  wxPoint origin;
777 
778  switch( params.origin )
779  {
781  origin = editFrame->GetScreen()->m_O_Curseur;
782  break;
783 
785  origin = editFrame->GetGridOrigin();
786  break;
787 
789  origin = editFrame->GetAuxOrigin();
790  break;
791 
793  origin = wxPoint( 0, 0 );
794  break;
795 
797  // relative movement means that only the translation values should be used:
798  // -> set origin and anchor to zero
799  origin = wxPoint( 0, 0 );
800  anchorPoint = wxPoint( 0, 0 );
801  break;
802  }
803 
804  wxPoint finalMoveVector = params.translation + origin - anchorPoint;
805 
806  // Make sure the rotation is from the right reference point
807  rotPoint += finalMoveVector;
808 
809  for( auto item : selection )
810  {
811  m_commit->Modify( item );
812  static_cast<BOARD_ITEM*>( item )->Move( finalMoveVector );
813  static_cast<BOARD_ITEM*>( item )->Rotate( rotPoint, params.rotation );
814 
815  if( !m_dragging )
816  getView()->Update( item );
817  }
818 
819  m_commit->Push( _( "Move exact" ) );
820 
821  if( selection.IsHover() )
823 
825  }
826 
827  return 0;
828 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
virtual const EDA_RECT GetBoundingBox() const
Function GetBoundingBox returns the orthogonal, bounding box of this object for display purposes...
int Rotate(const TOOL_EVENT &aEvent)
Function Rotate()
Definition: edit_tool.cpp:490
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
const wxPoint & GetPosition() const override
Definition: class_module.h:144
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
Smd pad, appears on the solder paste layer (default)
Definition: pad_shapes.h:59
const wxPoint & GetGridOrigin() const override
Function GetGridOrigin returns the absolute coordinates of the origin of the snap grid...
virtual const wxPoint & GetPosition() const =0
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
class D_PAD, a pad in a footprint
Definition: typeinfo.h:102
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
wxPoint m_O_Curseur
Relative Screen cursor coordinate (on grid) in user units.
const wxPoint & GetAuxOrigin() const override
Function GetAuxOrigin returns the origin of the axis used for plotting and various exports...
static TOOL_ACTION selectionModified
Modified selection notification.
Definition: pcb_actions.h:99
class MODULE, a footprint
Definition: typeinfo.h:101
bool m_dragging
Flag determining if anything is being dragged right now
Definition: edit_tool.h:138
EDA_RECT GetFootprintRect() const
Function GetFootprintRect() Returns the area of the module footprint excluding any text...
void Update(VIEW_ITEM *aItem)
Function Update() For dynamic VIEWs, informs the associated VIEW that the graphical representation of...
Definition: view.cpp:1379
D_PAD * GetTopLeftPad()
const wxPoint & GetPosition() const
bool m_editModules
Definition: pcb_tool.h:112
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:30
PCB_SCREEN * GetScreen() const override
Function GetScreen returns a pointer to a BASE_SCREEN or one of its derivatives.
#define mod(a, n)
Definition: greymap.cpp:24
class PCB_BASE_FRAME basic PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer...
const wxPoint GetCenter() const
int EDIT_TOOL::Properties ( const TOOL_EVENT aEvent)

Function Edit()

Displays properties window for the selected object.

Definition at line 443 of file edit_tool.cpp.

References DIALOG_TRACK_VIA_PROPERTIES::Apply(), EDA_ITEM::ClearFlags(), EDA_ITEM::GetFlags(), m_commit, m_selectionTool, TOOL_BASE::m_toolMgr, PCB_BASE_EDIT_FRAME::OnEditItemRequest(), SELECTION_CONDITIONS::OnlyTypes(), SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), SELECTION_DELETABLE, SELECTION_EDITABLE, PCB_ACTIONS::selectionClear, PCB_ACTIONS::selectionModified, EDA_ITEM::SetFlags(), and GENERAL_COLLECTOR::Tracks.

Referenced by SetTransitions().

444 {
445  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
446 
448 
449  if( selection.Empty() )
450  return 0;
451 
452  // Tracks & vias are treated in a special way:
454  {
455  DIALOG_TRACK_VIA_PROPERTIES dlg( editFrame, selection );
456 
457  if( dlg.ShowModal() )
458  {
459  dlg.Apply( *m_commit );
460  m_commit->Push( _( "Edit track/via properties" ) );
461  }
462  }
463  else if( selection.Size() == 1 ) // Properties are displayed when there is only one item selected
464  {
465  // Display properties dialog
466  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( selection.Front() );
467 
468  // Some of properties dialogs alter pointers, so we should deselect them
470 
471  // Store flags, so they can be restored later
472  STATUS_FLAGS flags = item->GetFlags();
473  item->ClearFlags();
474 
475  // Do not handle undo buffer, it is done by the properties dialogs @todo LEGACY
476  // Display properties dialog provided by the legacy canvas frame
477  editFrame->OnEditItemRequest( NULL, item );
478 
480  item->SetFlags( flags );
481  }
482 
483  if( selection.IsHover() )
485 
486  return 0;
487 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
STATUS_FLAGS GetFlags() const
Definition: base_struct.h:255
static const KICAD_T Tracks[]
A scan list for only TRACKS.
Definition: collectors.h:294
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
virtual void OnEditItemRequest(wxDC *aDC, BOARD_ITEM *aItem)=0
Function OnEditItemRequest Install the corresponding dialog editor for the given item.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
static TOOL_ACTION selectionModified
Modified selection notification.
Definition: pcb_actions.h:99
void SetFlags(STATUS_FLAGS aMask)
Definition: base_struct.h:253
static SELECTION_CONDITION OnlyTypes(const std::vector< KICAD_T > &aTypes)
Function OnlyTypes Creates a functor that tests if the selected items are only of given types...
unsigned STATUS_FLAGS
Definition: base_struct.h:144
Common, abstract interface for edit frames.
void ClearFlags(STATUS_FLAGS aMask=EDA_ITEM_ALL_FLAGS)
Definition: base_struct.h:254
int EDIT_TOOL::Remove ( const TOOL_EVENT aEvent)

Function Remove()

Deletes currently selected items. The rotation point is the current cursor position.

Definition at line 665 of file edit_tool.cpp.

References ACTIONS::ALT, SELECTION_TOOL::CheckLock(), m_commit, m_selectionTool, TOOL_BASE::m_toolMgr, TOOL_EVENT::Parameter(), SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), PCB_ACTIONS::selectConnection, SELECTION_DELETABLE, SELECTION_LOCKED, SELECTION_SANITIZE_PADS, and PCB_ACTIONS::selectionClear.

Referenced by SetTransitions().

666 {
667  // get a copy instead of reference (as we're going to clear the selectio before removing items)
669 
671  return 0;
672 
673  if( selection.Empty() )
674  return 0;
675 
676  // is this "alternative" remove?
677  const bool isAlt = aEvent.Parameter<intptr_t>() ==
678  (int) PCB_ACTIONS::REMOVE_FLAGS::ALT;
679 
680  // in "alternative" mode, deletion is not just a simple list
681  // of selected items, it is:
682  // - whole tracks, not just segments
683  if( isAlt && selection.IsHover() )
684  {
687  }
688 
689  // As we are about to remove items, they have to be removed from the selection first
691 
692  for( auto item : selection )
693  {
694  m_commit->Remove( item );
695  }
696 
697  m_commit->Push( _( "Delete" ) );
698 
699  return 0;
700 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
if(dlg.ShowModal()==wxID_OK)
Definition: selcolor.cpp:75
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
static TOOL_ACTION selectConnection
Selects a connection between junctions.
Definition: pcb_actions.h:62
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
T Parameter() const
Function Parameter() Returns a non-standard parameter assigned to the event.
Definition: tool_event.h:373
Class PCB_ACTIONS.
Definition: pcb_actions.h:42
void EDIT_TOOL::Reset ( RESET_REASON  aReason)
overridevirtual

Function Reset() Brings 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.

Implements TOOL_BASE.

Definition at line 168 of file edit_tool.cpp.

References m_commit, m_dragging, and TOOL_BASE::RUN.

169 {
170  m_dragging = false;
171 
172  if( aReason != RUN )
173  m_commit.reset( new BOARD_COMMIT( this ) );
174 }
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
Tool is invoked after being inactive.
Definition: tool_base.h:82
bool m_dragging
Flag determining if anything is being dragged right now
Definition: edit_tool.h:138
int EDIT_TOOL::Rotate ( const TOOL_EVENT aEvent)

Function Rotate()

Rotates currently selected items.

Definition at line 490 of file edit_tool.cpp.

References SELECTION_TOOL::CheckLock(), TOOL_EVT_UTILS::GetEventRotationAngle(), getModificationPoint(), m_commit, m_dragging, m_offset, m_selectionTool, TOOL_BASE::m_toolMgr, SELECTION_TOOL::RequestSelection(), TOOL_MANAGER::RunAction(), SELECTION_LOCKED, PCB_ACTIONS::selectionClear, and PCB_ACTIONS::selectionModified.

Referenced by MoveExact(), and SetTransitions().

491 {
492  PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
493 
494  const auto& selection = m_selectionTool->RequestSelection();
495 
496  if( selection.Empty() )
497  return 0;
498 
500  return 0;
501 
502  wxPoint modPoint = getModificationPoint( selection );
503  const int rotateAngle = TOOL_EVT_UTILS::GetEventRotationAngle( *editFrame, aEvent );
504 
505  for( auto item : selection )
506  {
507  m_commit->Modify( item );
508  static_cast<BOARD_ITEM*>( item )->Rotate( modPoint, rotateAngle );
509  }
510 
511  // Update the dragging point offset
512  m_offset = static_cast<BOARD_ITEM*>( selection.Front() )->GetPosition() - modPoint;
513 
514  if( !m_dragging )
515  m_commit->Push( _( "Rotate" ) );
516 
517  if( selection.IsHover() )
519 
521 
522  return 0;
523 }
static TOOL_ACTION selectionClear
Clears the current selection.
Definition: pcb_actions.h:53
wxPoint getModificationPoint(const SELECTION &aSelection)
Returns the right modification point (e.g.
Definition: edit_tool.cpp:1137
int Rotate(const TOOL_EVENT &aEvent)
Function Rotate()
Definition: edit_tool.cpp:490
SELECTION & RequestSelection(int aFlags=SELECTION_DEFAULT)
Function RequestSelection()
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
std::unique_ptr< BOARD_COMMIT > m_commit
Definition: edit_tool.h:201
SELECTION_LOCK_FLAGS CheckLock()
Checks if the user has agreed to modify locked items for the given selection.
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
bool RunAction(const std::string &aActionName, bool aNow=false, T aParam=NULL)
Function RunAction() Runs the specified action.
Definition: tool_manager.h:125
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
wxPoint m_offset
Offset from the dragged item's center (anchor)
Definition: edit_tool.h:141
static TOOL_ACTION selectionModified
Modified selection notification.
Definition: pcb_actions.h:99
bool m_dragging
Flag determining if anything is being dragged right now
Definition: edit_tool.h:138
Common, abstract interface for edit frames.
int GetEventRotationAngle(const PCB_BASE_EDIT_FRAME &aFrame, const TOOL_EVENT &aEvt)
Function getEventRotationAngle()
void TOOL_INTERACTIVE::RunMainStack ( std::function< void()>  aFunc)
inherited

Function RunMainStack()

Calls a function using the main stack.

Parameters
aFuncis the function to be calls.

Definition at line 78 of file tool_interactive.cpp.

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

Referenced by DRAWING_TOOL::PlaceText().

79 {
80  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
81 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)
void TOOL_INTERACTIVE::SetContextMenu ( CONTEXT_MENU aMenu,
CONTEXT_MENU_TRIGGER  aTrigger = CMENU_BUTTON 
)
inherited

Function SetContextMenu()

Assigns a context menu and tells when it should be activated.

Parameters
aMenuis the menu to be assigned.
aTriggerdetermines conditions upon which the context menu is activated.

Definition at line 67 of file tool_interactive.cpp.

References CMENU_OFF, TOOL_BASE::m_toolMgr, TOOL_MANAGER::ScheduleContextMenu(), and CONTEXT_MENU::SetTool().

Referenced by SELECTION_TOOL::disambiguationMenu(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), and TOOL_MENU::ShowContextMenu().

68 {
69  if( aMenu )
70  aMenu->SetTool( this );
71  else
72  aTrigger = CMENU_OFF;
73 
74  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
75 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
void ScheduleContextMenu(TOOL_BASE *aTool, CONTEXT_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Sets behaviour of the tool's context popup menu.
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
void PCB_TOOL::SetEditModules ( bool  aEnabled)
inlineinherited

Function SetEditModules()

Toggles edit module mode. When enabled, one may select parts of modules individually (graphics, pads, etc.), so they can be modified.

Parameters
aEnableddecides if the mode should be enabled.

Definition at line 73 of file pcb_tool.h.

References PCB_TOOL::m_editModules.

74  {
75  m_editModules = aEnabled;
76  }
bool m_editModules
Definition: pcb_tool.h:112
void EDIT_TOOL::SetTransitions ( )
overridevirtual

Sets up handlers for various events.

Reimplemented from TOOL_BASE.

Definition at line 1117 of file edit_tool.cpp.

References CreateArray(), PCB_ACTIONS::createArray, Duplicate(), PCB_ACTIONS::duplicate, PCB_ACTIONS::duplicateIncrement, PCB_ACTIONS::editActivate, editFootprintInFpEditor(), PCB_ACTIONS::editFootprintInFpEditor, PCB_ACTIONS::exchangeFootprints, ExchangeFootprints(), Flip(), PCB_ACTIONS::flip, TOOL_INTERACTIVE::Go(), Main(), MeasureTool(), PCB_ACTIONS::measureTool, Mirror(), PCB_ACTIONS::mirror, PCB_ACTIONS::moveExact, MoveExact(), Properties(), PCB_ACTIONS::properties, Remove(), PCB_ACTIONS::remove, PCB_ACTIONS::removeAlt, Rotate(), PCB_ACTIONS::rotateCcw, and PCB_ACTIONS::rotateCw.

1118 {
1119  Go( &EDIT_TOOL::Main, PCB_ACTIONS::editActivate.MakeEvent() );
1120  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCw.MakeEvent() );
1121  Go( &EDIT_TOOL::Rotate, PCB_ACTIONS::rotateCcw.MakeEvent() );
1122  Go( &EDIT_TOOL::Flip, PCB_ACTIONS::flip.MakeEvent() );
1123  Go( &EDIT_TOOL::Remove, PCB_ACTIONS::remove.MakeEvent() );
1124  Go( &EDIT_TOOL::Remove, PCB_ACTIONS::removeAlt.MakeEvent() );
1130  Go( &EDIT_TOOL::Mirror, PCB_ACTIONS::mirror.MakeEvent() );
1134 }
int Main(const TOOL_EVENT &aEvent)
Function Main()
Definition: edit_tool.cpp:247
int Properties(const TOOL_EVENT &aEvent)
Function Edit()
Definition: edit_tool.cpp:443
int Rotate(const TOOL_EVENT &aEvent)
Function Rotate()
Definition: edit_tool.cpp:490
int ExchangeFootprints(const TOOL_EVENT &aEvent)
Function ExchangeFootprints()
Definition: edit_tool.cpp:992
static TOOL_ACTION editActivate
Activation of the edit tool.
Definition: pcb_actions.h:81
static TOOL_ACTION properties
Activation of the edit tool.
Definition: pcb_actions.h:96
static TOOL_ACTION removeAlt
Definition: pcb_actions.h:115
static TOOL_ACTION mirror
Mirroring of selected items.
Definition: pcb_actions.h:93
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
int Mirror(const TOOL_EVENT &aEvent)
Function Mirror.
Definition: edit_tool.cpp:563
static TOOL_ACTION moveExact
Activation of the exact move tool.
Definition: pcb_actions.h:102
static TOOL_ACTION duplicate
Activation of the duplication tool.
Definition: pcb_actions.h:105
int Flip(const TOOL_EVENT &aEvent)
Function Flip()
Definition: edit_tool.cpp:632
static TOOL_ACTION duplicateIncrement
Activation of the duplication tool with incrementing (e.g. pad number)
Definition: pcb_actions.h:108
static TOOL_ACTION rotateCw
Rotation of selected objects clockwise.
Definition: pcb_actions.h:84
static TOOL_ACTION createArray
Tool for creating an array of objects.
Definition: pcb_actions.h:273
static TOOL_ACTION exchangeFootprints
Exchange footprints of modules.
Definition: pcb_actions.h:111
static TOOL_ACTION rotateCcw
Rotation of selected objects counter-clockwise.
Definition: pcb_actions.h:87
int MoveExact(const TOOL_EVENT &aEvent)
Function MoveExact()
Definition: edit_tool.cpp:703
int Remove(const TOOL_EVENT &aEvent)
Function Remove()
Definition: edit_tool.cpp:665
static TOOL_ACTION flip
Flipping of selected objects.
Definition: pcb_actions.h:90
int CreateArray(const TOOL_EVENT &aEvent)
Function CreateArray()
Definition: edit_tool.cpp:976
int MeasureTool(const TOOL_EVENT &aEvent)
Launches a tool to measure between points
Definition: edit_tool.cpp:1024
static TOOL_ACTION editFootprintInFpEditor
Definition: pcb_actions.h:356
int editFootprintInFpEditor(const TOOL_EVENT &aEvent)
Definition: edit_tool.cpp:1154
static TOOL_ACTION remove
Deleting a BOARD_ITEM.
Definition: pcb_actions.h:114
int Duplicate(const TOOL_EVENT &aEvent)
Function Duplicate()
Definition: edit_tool.cpp:831
static TOOL_ACTION measureTool
Definition: pcb_actions.h:338
template<class T >
T* EDIT_TOOL::uniqueHoverSelection ( bool  aSanitize = true)
inlineprivate

Function uniqueHoverSelection()

Get a single unique selection of an item, either from the current selection, or from the items under cursor via hoverSelection()

Template Parameters
Ttype of item to select
Returns
pointer to a selected item, or nullptr if none could be found.

Definition at line 191 of file edit_tool.h.

References hoverSelection().

192  {
193  if( !hoverSelection( aSanitize ) )
194  return nullptr;
195 
196  T* item = uniqueSelected<T>();
197 
198  return item;
199  }
T
enum T contains all this lexer's tokens.
bool hoverSelection(bool aSanitize=true)
Function hoverSelection()
template<class T >
T * EDIT_TOOL::uniqueSelected ( )
private

Function uniqueSelected()

Get a single selected item of a certain type

Template Parameters
Ttype of item to select
Returns
pointer to the item (of type T), or nullptr if there isn't a single selected item, or it's not of the right type.

Definition at line 1191 of file edit_tool.cpp.

References dyn_cast(), SELECTION_TOOL::GetSelection(), and m_selectionTool.

1192 {
1193  const auto selection = m_selectionTool->GetSelection();
1194 
1195  if( selection.Size() != 1 )
1196  return nullptr;
1197 
1198  auto item = selection[0];
1199  return dyn_cast<T*>( item );
1200 }
T
enum T contains all this lexer's tokens.
SELECTION_TOOL * m_selectionTool
Selection tool used for obtaining selected items
Definition: edit_tool.h:135
Casted dyn_cast(From aObject)
Function dyn_cast()
Definition: typeinfo.h:73
SELECTION & GetSelection()
Function GetSelection()
OPT_TOOL_EVENT TOOL_INTERACTIVE::Wait ( const TOOL_EVENT_LIST aEventList = TOOL_EVENTTC_ANYTA_ANY ))
inherited

Function Wait()

Suspends execution of the tool until an event specified in aEventList arrives. No parameters means waiting for any event.

Definition at line 55 of file tool_interactive.cpp.

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

Referenced by MODULE_EDITOR_TOOLS::CopyItems(), PCBNEW_CONTROL::DeleteItemCursor(), SELECTION_TOOL::disambiguationMenu(), PCB_TOOL::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), PCB_EDITOR_CONTROL::DrillOrigin(), MODULE_EDITOR_TOOLS::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), PICKER_TOOL::Main(), Main(), SELECTION_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), MeasureTool(), POINT_EDITOR::OnSelectionChange(), MODULE_EDITOR_TOOLS::PasteItems(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::runPolygonEventLoop(), SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectPoint(), ZOOM_TOOL::selectRegion(), and DRAWING_TOOL::SetAnchor().

56 {
57  return m_toolMgr->ScheduleWait( this, aEventList );
58 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:220
boost::optional< TOOL_EVENT > ScheduleWait(TOOL_BASE *aTool, const TOOL_EVENT_LIST &aConditions)
Pauses execution of a given tool until one or more events matching aConditions arrives.

Member Data Documentation

std::unique_ptr<BOARD_COMMIT> EDIT_TOOL::m_commit
private

Definition at line 201 of file edit_tool.h.

Referenced by Duplicate(), Flip(), Main(), Mirror(), MoveExact(), Properties(), Remove(), Reset(), and Rotate().

VECTOR2I EDIT_TOOL::m_cursor
private

Last cursor position (needed for getModificationPoint() to avoid changes of edit reference point).

Definition at line 145 of file edit_tool.h.

Referenced by getModificationPoint(), and Main().

bool EDIT_TOOL::m_dragging
private

Flag determining if anything is being dragged right now

Definition at line 138 of file edit_tool.h.

Referenced by Flip(), Main(), Mirror(), MoveExact(), Reset(), and Rotate().

wxPoint EDIT_TOOL::m_offset
private

Offset from the dragged item's center (anchor)

Definition at line 141 of file edit_tool.h.

Referenced by Flip(), getModificationPoint(), Init(), Main(), and Rotate().

SELECTION_TOOL* EDIT_TOOL::m_selectionTool
private

Selection tool used for obtaining selected items

Definition at line 135 of file edit_tool.h.

Referenced by CreateArray(), Duplicate(), editFootprintInFpEditor(), ExchangeFootprints(), Flip(), Init(), Main(), Mirror(), MoveExact(), Properties(), Remove(), Rotate(), and uniqueSelected().

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

Unique identifier for the tool, assigned by a TOOL_MANAGER instance.

Definition at line 215 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), TOOL_BASE::GetId(), and getModificationPoint().

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 220 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), PCBNEW_CONTROL::AppendBoard(), PAD_TOOL::applyPadSettings(), TOOL_BASE::attachManager(), SELECTION_TOOL::clearSelection(), MODULE_EDITOR_TOOLS::CopyItems(), PAD_TOOL::copyPadSettings(), PCB_EDITOR_CONTROL::CrossProbePcbToSch(), PCB_EDITOR_CONTROL::CrossProbeSchToPcb(), PCBNEW_CONTROL::CursorControl(), ROUTER_TOOL::CustomTrackWidthDialog(), PCBNEW_CONTROL::DeleteItemCursor(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), DRAWING_TOOL::drawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), Duplicate(), editFootprintInFpEditor(), MODULE_EDITOR_TOOLS::EnumeratePads(), ExchangeFootprints(), SELECTION_TOOL::findCallback(), SELECTION_TOOL::findMove(), Flip(), TOOL_BASE::getEditFrameInt(), TOOL_BASE::GetManager(), TOOL_BASE::getModelInt(), getModificationPoint(), DRAWING_TOOL::getSourceZoneForAction(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_INTERACTIVE::goInternal(), PCBNEW_CONTROL::GridSetOrigin(), PCB_EDITOR_CONTROL::HighlightNet(), PCB_EDITOR_CONTROL::HighlightNetCursor(), ROUTER_TOOL::Init(), PLACEMENT_TOOL::Init(), PAD_TOOL::Init(), POINT_EDITOR::Init(), PCB_EDITOR_CONTROL::Init(), Init(), ROUTER_TOOL::InlineDrag(), invokeInlineRouter(), ZOOM_TOOL::Main(), PICKER_TOOL::Main(), Main(), SELECTION_TOOL::Main(), LENGTH_TUNER_TOOL::mainLoop(), ROUTER_TOOL::mainLoop(), Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), MoveExact(), POINT_EDITOR::OnSelectionChange(), MODULE_EDITOR_TOOLS::PasteItems(), DRAWING_TOOL::PlaceDXF(), PCB_EDITOR_CONTROL::PlaceModule(), MODULE_EDITOR_TOOLS::PlacePad(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), Properties(), PAD_TOOL::pushPadSettings(), Remove(), SELECTION_TOOL::RequestSelection(), Rotate(), TOOL_INTERACTIVE::RunMainStack(), SELECTION_TOOL::SanitizeSelection(), SELECTION_TOOL::selectConnection(), SELECTION_TOOL::selectCopper(), SELECTION_TOOL::SelectItem(), SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectNet(), SELECTION_TOOL::selectOnSheetFromEeschema(), SELECTION_TOOL::selectSameSheet(), TOOL_INTERACTIVE::SetContextMenu(), SELECTION_TOOL::toggleSelection(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), SELECTION_TOOL::UnselectItem(), PCB_EDITOR_CONTROL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), TOOL_INTERACTIVE::Wait(), PCB_EDITOR_CONTROL::ZoneDuplicate(), PCB_EDITOR_CONTROL::ZoneFill(), PCB_EDITOR_CONTROL::ZoneMerge(), and PCB_EDITOR_CONTROL::ZoneUnfill().

std::string TOOL_BASE::m_toolName
protectedinherited

Name of the tool.

Names are expected to obey the format application.ToolName

(eg. pcbnew.InteractiveSelection).

Definition at line 219 of file tool_base.h.

Referenced by TOOL_BASE::GetName().

TOOL_SETTINGS TOOL_BASE::m_toolSettings
protectedinherited

Definition at line 221 of file tool_base.h.

Referenced by TOOL_BASE::attachManager(), and TOOL_BASE::GetSettings().

TOOL_TYPE TOOL_BASE::m_type
protectedinherited

Stores the type of the tool.

Definition at line 212 of file tool_base.h.

Referenced by TOOL_BASE::GetType().


The documentation for this class was generated from the following files: