KiCad PCB EDA Suite
ALIGN_DISTRIBUTE_TOOL Class Reference

#include <placement_tool.h>

Inheritance diagram for ALIGN_DISTRIBUTE_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

 ALIGN_DISTRIBUTE_TOOL ()
 
virtual ~ALIGN_DISTRIBUTE_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 AlignTop (const TOOL_EVENT &aEvent)
 Function AlignTop() Sets Y coordinate of the selected items to the value of the top-most selected item Y coordinate. More...
 
int AlignBottom (const TOOL_EVENT &aEvent)
 Function AlignBottom() Sets Y coordinate of the selected items to the value of the bottom-most selected item Y coordinate. More...
 
int AlignLeft (const TOOL_EVENT &aEvent)
 Function AlignLeft() Sets X coordinate of the selected items to the value of the left-most selected item X coordinate. More...
 
int AlignRight (const TOOL_EVENT &aEvent)
 Function AlignRight() Sets X coordinate of the selected items to the value of the right-most selected item X coordinate. More...
 
int AlignCenterX (const TOOL_EVENT &aEvent)
 Function AlignCenterX() Sets the x coordinate of the midpoint of each of the selected items to the value of the x coordinate of the center of the middle selected item. More...
 
int AlignCenterY (const TOOL_EVENT &aEvent)
 Function AlignCenterX() Sets the y coordinate of the midpoint of each of the selected items to the value of the y coordinate of the center of the middle selected item. More...
 
int DistributeHorizontally (const TOOL_EVENT &aEvent)
 Function DistributeHorizontally() Distributes the selected items along the X axis. More...
 
int DistributeVertically (const TOOL_EVENT &aEvent)
 Function DistributeVertically() Distributes the selected items along the Y axis. More...
 
void setTransitions () override
 

Sets up handlers for various events.

More...
 
void Activate ()
 Function Activate() Runs the tool. More...
 
TOOL_MENUGetToolMenu ()
 
void SetContextMenu (ACTION_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...
 
TOOL_EVENTWait (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 ()
 
bool IsToolActive () const
 

Protected Member Functions

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

TOOL_MENU m_menu
 functions below are not yet implemented - their interface may change More...
 
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

template<typename T >
size_t GetSelections (ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
 Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Returns the size of aItems() More...
 
template<typename T >
int selectTarget (ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
 
int doAlignLeft ()
 Sets X coordinate of the selected items to the value of the left-most selected item X coordinate. More...
 
int doAlignRight ()
 Aligns selected items using the right edge of their bounding boxes to the right-most item. More...
 
int checkLockedStatus (const PCBNEW_SELECTION &selection) const
 Check a selection to ensure locks are valid for alignment. More...
 
void doDistributeCentersHorizontally (ALIGNMENT_RECTS &itemsToDistribute) const
 Distributes selected items using an even spacing between the centers of their bounding boxes. More...
 
void doDistributeCentersVertically (ALIGNMENT_RECTS &itemsToDistribute) const
 Distributes selected items using an even spacing between the centers of their bounding boxes. More...
 
void doDistributeGapsHorizontally (ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
 Distributes selected items using an even spacing between their bounding boxes. More...
 
void doDistributeGapsVertically (ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
 Distributes selected items using an even spacing between their bounding boxes. More...
 

Private Attributes

SELECTION_TOOLm_selectionTool
 
ACTION_MENUm_placementMenu
 
PCB_BASE_FRAMEm_frame
 

Detailed Description

Definition at line 38 of file placement_tool.h.

Member Enumeration Documentation

◆ RESET_REASON

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

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

Constructor & Destructor Documentation

◆ ALIGN_DISTRIBUTE_TOOL()

ALIGN_DISTRIBUTE_TOOL::ALIGN_DISTRIBUTE_TOOL ( )

Definition at line 41 of file placement_tool.cpp.

41  :
42  TOOL_INTERACTIVE( "pcbnew.Placement" ), m_selectionTool( NULL ), m_placementMenu( NULL ),
43  m_frame( NULL )
44 {
45 }
ACTION_MENU * m_placementMenu
TOOL_INTERACTIVE(TOOL_ID aId, const std::string &aName)
Constructor.
#define NULL
PCB_BASE_FRAME * m_frame
SELECTION_TOOL * m_selectionTool

◆ ~ALIGN_DISTRIBUTE_TOOL()

ALIGN_DISTRIBUTE_TOOL::~ALIGN_DISTRIBUTE_TOOL ( )
virtual

Definition at line 47 of file placement_tool.cpp.

48 {
49  delete m_placementMenu;
50 }
ACTION_MENU * m_placementMenu

References m_placementMenu.

Member Function Documentation

◆ Activate()

void TOOL_INTERACTIVE::Activate ( )
inherited

Function Activate() Runs the tool.

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

Definition at line 51 of file tool_interactive.cpp.

52 {
54 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214
bool InvokeTool(TOOL_ID aToolId)
Function InvokeTool() Calls a tool by sending a tool activation event to tool of given ID.

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

Referenced by AUTOPLACE_TOOL::autoplace(), EDIT_TOOL::copyToClipboard(), LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), PAD_TOOL::EnumeratePads(), PCBNEW_CONTROL::GridSetOrigin(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), LIB_TREE::onContextMenu(), POINT_EDITOR::OnSelectionChange(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), DRAWING_TOOL::SetAnchor(), DRC::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ AlignBottom()

int ALIGN_DISTRIBUTE_TOOL::AlignBottom ( const TOOL_EVENT aEvent)

Function AlignBottom() Sets Y coordinate of the selected items to the value of the bottom-most selected item Y coordinate.

Definition at line 196 of file placement_tool.cpp.

197 {
198  ALIGNMENT_RECTS itemsToAlign;
199  ALIGNMENT_RECTS locked_items;
200 
201  if( !GetSelections( itemsToAlign, locked_items, []( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
202  { return ( left.second.GetBottom() < right.second.GetBottom() ); } ) )
203  return 0;
204 
205  BOARD_COMMIT commit( m_frame );
206  commit.StageItems( m_selectionTool->GetSelection(), CHT_MODIFY );
207  auto targetBottom = selectTarget( itemsToAlign, locked_items, []( const ALIGNMENT_RECT& aVal )
208  { return aVal.second.GetBottom(); } );
209 
210  // Move the selected items
211  for( auto& i : itemsToAlign )
212  {
213  int difference = targetBottom - i.second.GetBottom();
214  BOARD_ITEM* item = i.first;
215 
216  // Don't move a pad by itself unless editing the footprint
217  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
218  item = item->GetParent();
219 
220  item->Move( wxPoint( 0, difference ) );
221  }
222 
223  commit.Push( _( "Align to bottom" ) );
224 
225  return 0;
226 }
int selectTarget(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
std::vector< ALIGNMENT_RECT > ALIGNMENT_RECTS
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
size_t GetSelections(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Retu...
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
SELECTION_TOOL * m_selectionTool
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References _, CHT_MODIFY, FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), SELECTION_TOOL::GetSelection(), GetSelections(), EDA_BASE_FRAME::IsType(), m_frame, m_selectionTool, BOARD_ITEM::Move(), PCB_PAD_T, BOARD_COMMIT::Push(), selectTarget(), COMMIT::StageItems(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ AlignCenterX()

int ALIGN_DISTRIBUTE_TOOL::AlignCenterX ( const TOOL_EVENT aEvent)

Function AlignCenterX() Sets the x coordinate of the midpoint of each of the selected items to the value of the x coordinate of the center of the middle selected item.

Definition at line 325 of file placement_tool.cpp.

326 {
327  ALIGNMENT_RECTS itemsToAlign;
328  ALIGNMENT_RECTS locked_items;
329 
330  if( !GetSelections( itemsToAlign, locked_items, []( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
331  { return ( left.second.GetCenter().x < right.second.GetCenter().x ); } ) )
332  return 0;
333 
334  BOARD_COMMIT commit( m_frame );
335  commit.StageItems( m_selectionTool->GetSelection(), CHT_MODIFY );
336  auto targetX = selectTarget( itemsToAlign, locked_items, []( const ALIGNMENT_RECT& aVal )
337  { return aVal.second.GetCenter().x; } );
338 
339  // Move the selected items
340  for( auto& i : itemsToAlign )
341  {
342  int difference = targetX - i.second.GetCenter().x;
343  BOARD_ITEM* item = i.first;
344 
345  // Don't move a pad by itself unless editing the footprint
346  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
347  item = item->GetParent();
348 
349  item->Move( wxPoint( difference, 0 ) );
350  }
351 
352  commit.Push( _( "Align to middle" ) );
353 
354  return 0;
355 }
int selectTarget(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
std::vector< ALIGNMENT_RECT > ALIGNMENT_RECTS
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
size_t GetSelections(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Retu...
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
SELECTION_TOOL * m_selectionTool
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References _, CHT_MODIFY, FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), SELECTION_TOOL::GetSelection(), GetSelections(), EDA_BASE_FRAME::IsType(), m_frame, m_selectionTool, BOARD_ITEM::Move(), PCB_PAD_T, BOARD_COMMIT::Push(), selectTarget(), COMMIT::StageItems(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ AlignCenterY()

int ALIGN_DISTRIBUTE_TOOL::AlignCenterY ( const TOOL_EVENT aEvent)

Function AlignCenterX() Sets the y coordinate of the midpoint of each of the selected items to the value of the y coordinate of the center of the middle selected item.

Definition at line 358 of file placement_tool.cpp.

359 {
360  ALIGNMENT_RECTS itemsToAlign;
361  ALIGNMENT_RECTS locked_items;
362 
363  if( !GetSelections( itemsToAlign, locked_items, []( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
364  { return ( left.second.GetCenter().y < right.second.GetCenter().y ); } ) )
365  return 0;
366 
367  BOARD_COMMIT commit( m_frame );
368  commit.StageItems( m_selectionTool->GetSelection(), CHT_MODIFY );
369  auto targetY = selectTarget( itemsToAlign, locked_items, []( const ALIGNMENT_RECT& aVal )
370  { return aVal.second.GetCenter().y; } );
371 
372  // Move the selected items
373  for( auto& i : itemsToAlign )
374  {
375  int difference = targetY - i.second.GetCenter().y;
376  BOARD_ITEM* item = i.first;
377 
378  // Don't move a pad by itself unless editing the footprint
379  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
380  item = item->GetParent();
381 
382  item->Move( wxPoint( 0, difference ) );
383  }
384 
385  commit.Push( _( "Align to center" ) );
386 
387  return 0;
388 }
int selectTarget(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
std::vector< ALIGNMENT_RECT > ALIGNMENT_RECTS
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
size_t GetSelections(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Retu...
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
SELECTION_TOOL * m_selectionTool
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References _, CHT_MODIFY, FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), SELECTION_TOOL::GetSelection(), GetSelections(), EDA_BASE_FRAME::IsType(), m_frame, m_selectionTool, BOARD_ITEM::Move(), PCB_PAD_T, BOARD_COMMIT::Push(), selectTarget(), COMMIT::StageItems(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ AlignLeft()

int ALIGN_DISTRIBUTE_TOOL::AlignLeft ( const TOOL_EVENT aEvent)

Function AlignLeft() Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.

Definition at line 229 of file placement_tool.cpp.

230 {
231  // Because this tool uses bounding boxes and they aren't mirrored even when
232  // the view is mirrored, we need to call the other one if mirrored.
233  if( getView()->IsMirroredX() )
234  {
235  return doAlignRight();
236  }
237  else
238  {
239  return doAlignLeft();
240  }
241 }
int doAlignRight()
Aligns selected items using the right edge of their bounding boxes to the right-most item.
int doAlignLeft()
Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36

References doAlignLeft(), doAlignRight(), and TOOL_BASE::getView().

Referenced by setTransitions().

◆ AlignRight()

int ALIGN_DISTRIBUTE_TOOL::AlignRight ( const TOOL_EVENT aEvent)

Function AlignRight() Sets X coordinate of the selected items to the value of the right-most selected item X coordinate.

Definition at line 277 of file placement_tool.cpp.

278 {
279  // Because this tool uses bounding boxes and they aren't mirrored even when
280  // the view is mirrored, we need to call the other one if mirrored.
281  if( getView()->IsMirroredX() )
282  {
283  return doAlignLeft();
284  }
285  else
286  {
287  return doAlignRight();
288  }
289 }
int doAlignRight()
Aligns selected items using the right edge of their bounding boxes to the right-most item.
int doAlignLeft()
Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.
KIGFX::VIEW * getView() const
Function getView()
Definition: tool_base.cpp:36

References doAlignLeft(), doAlignRight(), and TOOL_BASE::getView().

Referenced by setTransitions().

◆ AlignTop()

int ALIGN_DISTRIBUTE_TOOL::AlignTop ( const TOOL_EVENT aEvent)

Function AlignTop() Sets Y coordinate of the selected items to the value of the top-most selected item Y coordinate.

Definition at line 163 of file placement_tool.cpp.

164 {
165  ALIGNMENT_RECTS itemsToAlign;
166  ALIGNMENT_RECTS locked_items;
167 
168  if( !GetSelections( itemsToAlign, locked_items, []( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
169  { return ( left.second.GetTop() < right.second.GetTop() ); } ) )
170  return 0;
171 
172  BOARD_COMMIT commit( m_frame );
173  commit.StageItems( m_selectionTool->GetSelection(), CHT_MODIFY );
174  auto targetTop = selectTarget( itemsToAlign, locked_items, []( const ALIGNMENT_RECT& aVal )
175  { return aVal.second.GetTop(); } );
176 
177  // Move the selected items
178  for( auto& i : itemsToAlign )
179  {
180  int difference = targetTop - i.second.GetTop();
181  BOARD_ITEM* item = i.first;
182 
183  // Don't move a pad by itself unless editing the footprint
184  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
185  item = item->GetParent();
186 
187  item->Move( wxPoint( 0, difference ) );
188  }
189 
190  commit.Push( _( "Align to top" ) );
191 
192  return 0;
193 }
int selectTarget(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
std::vector< ALIGNMENT_RECT > ALIGNMENT_RECTS
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
size_t GetSelections(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Retu...
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
SELECTION_TOOL * m_selectionTool
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References _, CHT_MODIFY, FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), SELECTION_TOOL::GetSelection(), GetSelections(), EDA_BASE_FRAME::IsType(), m_frame, m_selectionTool, BOARD_ITEM::Move(), PCB_PAD_T, BOARD_COMMIT::Push(), selectTarget(), COMMIT::StageItems(), and EDA_ITEM::Type().

Referenced by setTransitions().

◆ attachManager()

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 60 of file tool_base.cpp.

61 {
62  m_toolMgr = aManager;
63  m_toolSettings = TOOL_SETTINGS( this );
64 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:220
friend class TOOL_SETTINGS
Definition: tool_base.h:154

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

Referenced by TOOL_MANAGER::RegisterTool().

◆ checkLockedStatus()

int ALIGN_DISTRIBUTE_TOOL::checkLockedStatus ( const PCBNEW_SELECTION selection) const
private

Check a selection to ensure locks are valid for alignment.

This is slightly different from the standard lock checking in that we ignore the lock of the first element in the selection as this is meant to be our anchor. We also check the lock of a pad's parent as we will not move pads independently of the parent module

◆ DistributeHorizontally()

int ALIGN_DISTRIBUTE_TOOL::DistributeHorizontally ( const TOOL_EVENT aEvent)

Function DistributeHorizontally() Distributes the selected items along the X axis.

Definition at line 391 of file placement_tool.cpp.

392 {
394  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
396 
397  if( selection.Size() <= 1 )
398  return 0;
399 
400  BOARD_COMMIT commit( m_frame );
401  commit.StageItems( selection, CHT_MODIFY );
402 
403  auto itemsToDistribute = GetBoundingBoxes( selection );
404 
405  // find the last item by reverse sorting
406  std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
407  [] ( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
408  { return ( left.second.GetRight() > right.second.GetRight() ); } );
409  const auto lastItem = itemsToDistribute.begin()->first;
410 
411  const auto maxRight = itemsToDistribute.begin()->second.GetRight();
412 
413  // sort to get starting order
414  std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
415  [] ( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
416  { return ( left.second.GetX() < right.second.GetX() ); } );
417  const auto minX = itemsToDistribute.begin()->second.GetX();
418  auto totalGap = maxRight - minX;
419  int totalWidth = 0;
420 
421  for( auto& i : itemsToDistribute )
422  {
423  totalWidth += i.second.GetWidth();
424  }
425 
426  if( totalGap < totalWidth )
427  {
428  // the width of the items exceeds the gap (overlapping items) -> use center point spacing
429  doDistributeCentersHorizontally( itemsToDistribute );
430  }
431  else
432  {
433  totalGap -= totalWidth;
434  doDistributeGapsHorizontally( itemsToDistribute, lastItem, totalGap );
435  }
436 
437  commit.Push( _( "Distribute horizontally" ) );
438 
439  return 0;
440 }
void doDistributeGapsHorizontally(ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
ALIGNMENT_RECTS GetBoundingBoxes(const T &sel)
void doDistributeCentersHorizontally(ALIGNMENT_RECTS &itemsToDistribute) const
Distributes selected items using an even spacing between the centers of their bounding boxes.
#define EXCLUDE_TRANSIENTS
Definition: edit_tool.h:55
PCBNEW_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=nullptr, bool aConfirmLockedItems=false)
Function RequestSelection()
PCB_BASE_FRAME * m_frame
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
SELECTION_TOOL * m_selectionTool
#define EXCLUDE_LOCKED
Function EditToolSelectionFilter.
Definition: edit_tool.h:53
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags)
Definition: edit_tool.cpp:59

References _, CHT_MODIFY, doDistributeCentersHorizontally(), doDistributeGapsHorizontally(), EditToolSelectionFilter(), EXCLUDE_LOCKED, EXCLUDE_TRANSIENTS, GetBoundingBoxes(), m_frame, m_selectionTool, BOARD_COMMIT::Push(), SELECTION_TOOL::RequestSelection(), SELECTION::Size(), and COMMIT::StageItems().

Referenced by setTransitions().

◆ DistributeVertically()

int ALIGN_DISTRIBUTE_TOOL::DistributeVertically ( const TOOL_EVENT aEvent)

Function DistributeVertically() Distributes the selected items along the Y axis.

Definition at line 493 of file placement_tool.cpp.

494 {
496  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
498 
499  if( selection.Size() <= 1 )
500  return 0;
501 
502  BOARD_COMMIT commit( m_frame );
503  commit.StageItems( selection, CHT_MODIFY );
504 
505  auto itemsToDistribute = GetBoundingBoxes( selection );
506 
507  // find the last item by reverse sorting
508  std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
509  [] ( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
510  { return ( left.second.GetBottom() > right.second.GetBottom() ); } );
511  const auto maxBottom = itemsToDistribute.begin()->second.GetBottom();
512  const auto lastItem = itemsToDistribute.begin()->first;
513 
514  // sort to get starting order
515  std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
516  [] ( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
517  { return ( left.second.GetCenter().y < right.second.GetCenter().y ); } );
518  auto minY = itemsToDistribute.begin()->second.GetY();
519 
520  auto totalGap = maxBottom - minY;
521  int totalHeight = 0;
522 
523  for( auto& i : itemsToDistribute )
524  {
525  totalHeight += i.second.GetHeight();
526  }
527 
528  if( totalGap < totalHeight )
529  {
530  // the width of the items exceeds the gap (overlapping items) -> use center point spacing
531  doDistributeCentersVertically( itemsToDistribute );
532  }
533  else
534  {
535  totalGap -= totalHeight;
536  doDistributeGapsVertically( itemsToDistribute, lastItem, totalGap );
537  }
538 
539  commit.Push( _( "Distribute vertically" ) );
540 
541  return 0;
542 }
void doDistributeCentersVertically(ALIGNMENT_RECTS &itemsToDistribute) const
Distributes selected items using an even spacing between the centers of their bounding boxes.
ALIGNMENT_RECTS GetBoundingBoxes(const T &sel)
#define EXCLUDE_TRANSIENTS
Definition: edit_tool.h:55
PCBNEW_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=nullptr, bool aConfirmLockedItems=false)
Function RequestSelection()
PCB_BASE_FRAME * m_frame
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
void doDistributeGapsVertically(ALIGNMENT_RECTS &itemsToDistribute, const BOARD_ITEM *lastItem, int totalGap) const
Distributes selected items using an even spacing between their bounding boxes.
SELECTION_TOOL * m_selectionTool
#define EXCLUDE_LOCKED
Function EditToolSelectionFilter.
Definition: edit_tool.h:53
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags)
Definition: edit_tool.cpp:59

References _, CHT_MODIFY, doDistributeCentersVertically(), doDistributeGapsVertically(), EditToolSelectionFilter(), EXCLUDE_LOCKED, EXCLUDE_TRANSIENTS, GetBoundingBoxes(), m_frame, m_selectionTool, BOARD_COMMIT::Push(), SELECTION_TOOL::RequestSelection(), SELECTION::Size(), and COMMIT::StageItems().

Referenced by setTransitions().

◆ doAlignLeft()

int ALIGN_DISTRIBUTE_TOOL::doAlignLeft ( )
private

Sets X coordinate of the selected items to the value of the left-most selected item X coordinate.

NOTE: Uses the bounding box of items, which do not get mirrored even when the view is mirrored!

Definition at line 244 of file placement_tool.cpp.

245 {
246  ALIGNMENT_RECTS itemsToAlign;
247  ALIGNMENT_RECTS locked_items;
248 
249  if( !GetSelections( itemsToAlign, locked_items, []( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
250  { return ( left.second.GetLeft() < right.second.GetLeft() ); } ) )
251  return 0;
252 
253  BOARD_COMMIT commit( m_frame );
254  commit.StageItems( m_selectionTool->GetSelection(), CHT_MODIFY );
255  auto targetLeft = selectTarget( itemsToAlign, locked_items, []( const ALIGNMENT_RECT& aVal )
256  { return aVal.second.GetLeft(); } );
257 
258  // Move the selected items
259  for( auto& i : itemsToAlign )
260  {
261  int difference = targetLeft - i.second.GetLeft();
262  BOARD_ITEM* item = i.first;
263 
264  // Don't move a pad by itself unless editing the footprint
265  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
266  item = item->GetParent();
267 
268  item->Move( wxPoint( difference, 0 ) );
269  }
270 
271  commit.Push( _( "Align to left" ) );
272 
273  return 0;
274 }
int selectTarget(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
std::vector< ALIGNMENT_RECT > ALIGNMENT_RECTS
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
size_t GetSelections(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Retu...
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
SELECTION_TOOL * m_selectionTool
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References _, CHT_MODIFY, FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), SELECTION_TOOL::GetSelection(), GetSelections(), EDA_BASE_FRAME::IsType(), m_frame, m_selectionTool, BOARD_ITEM::Move(), PCB_PAD_T, BOARD_COMMIT::Push(), selectTarget(), COMMIT::StageItems(), and EDA_ITEM::Type().

Referenced by AlignLeft(), and AlignRight().

◆ doAlignRight()

int ALIGN_DISTRIBUTE_TOOL::doAlignRight ( )
private

Aligns selected items using the right edge of their bounding boxes to the right-most item.

NOTE: Uses the bounding box of items, which do not get mirrored even when the view is mirrored!

Definition at line 292 of file placement_tool.cpp.

293 {
294  ALIGNMENT_RECTS itemsToAlign;
295  ALIGNMENT_RECTS locked_items;
296 
297  if( !GetSelections( itemsToAlign, locked_items, []( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
298  { return ( left.second.GetRight() < right.second.GetRight() ); } ) )
299  return 0;
300 
301  BOARD_COMMIT commit( m_frame );
302  commit.StageItems( m_selectionTool->GetSelection(), CHT_MODIFY );
303  auto targetRight = selectTarget( itemsToAlign, locked_items, []( const ALIGNMENT_RECT& aVal )
304  { return aVal.second.GetRight(); } );
305 
306  // Move the selected items
307  for( auto& i : itemsToAlign )
308  {
309  int difference = targetRight - i.second.GetRight();
310  BOARD_ITEM* item = i.first;
311 
312  // Don't move a pad by itself unless editing the footprint
313  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
314  item = item->GetParent();
315 
316  item->Move( wxPoint( difference, 0 ) );
317  }
318 
319  commit.Push( _( "Align to right" ) );
320 
321  return 0;
322 }
int selectTarget(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aGetValue)
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
PCBNEW_SELECTION & GetSelection()
Function GetSelection()
std::vector< ALIGNMENT_RECT > ALIGNMENT_RECTS
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
size_t GetSelections(ALIGNMENT_RECTS &aItems, ALIGNMENT_RECTS &aLocked, T aCompare)
Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Retu...
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
#define _(s)
Definition: 3d_actions.cpp:31
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
SELECTION_TOOL * m_selectionTool
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References _, CHT_MODIFY, FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), SELECTION_TOOL::GetSelection(), GetSelections(), EDA_BASE_FRAME::IsType(), m_frame, m_selectionTool, BOARD_ITEM::Move(), PCB_PAD_T, BOARD_COMMIT::Push(), selectTarget(), COMMIT::StageItems(), and EDA_ITEM::Type().

Referenced by AlignLeft(), and AlignRight().

◆ doDistributeCentersHorizontally()

void ALIGN_DISTRIBUTE_TOOL::doDistributeCentersHorizontally ( ALIGNMENT_RECTS itemsToDistribute) const
private

Distributes selected items using an even spacing between the centers of their bounding boxes.

NOTE: Using the centers of bounding box of items can give unsatisfactory visual results since items of differing widths will be placed with different gaps. Is only used if items overlap

Definition at line 468 of file placement_tool.cpp.

469 {
470  std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
471  [] ( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
472  { return ( left.second.GetCenter().x < right.second.GetCenter().x ); } );
473  const auto totalGap = ( itemsToDistribute.end()-1 )->second.GetCenter().x
474  - itemsToDistribute.begin()->second.GetCenter().x;
475  const auto itemGap = totalGap / ( itemsToDistribute.size() - 1 );
476  auto targetX = itemsToDistribute.begin()->second.GetCenter().x;
477 
478  for( auto& i : itemsToDistribute )
479  {
480  BOARD_ITEM* item = i.first;
481 
482  // Don't move a pad by itself unless editing the footprint
483  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
484  item = item->GetParent();
485 
486  int difference = targetX - i.second.GetCenter().x;
487  item->Move( wxPoint( difference, 0 ) );
488  targetX += ( itemGap );
489  }
490 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
virtual const wxPoint GetCenter() const
Function GetCenter()
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References FRAME_PCB_EDITOR, BOARD_ITEM::GetCenter(), BOARD_ITEM::GetParent(), EDA_BASE_FRAME::IsType(), m_frame, BOARD_ITEM::Move(), PCB_PAD_T, EDA_ITEM::Type(), and wxPoint::x.

Referenced by DistributeHorizontally().

◆ doDistributeCentersVertically()

void ALIGN_DISTRIBUTE_TOOL::doDistributeCentersVertically ( ALIGNMENT_RECTS itemsToDistribute) const
private

Distributes selected items using an even spacing between the centers of their bounding boxes.

NOTE: Using the centers of bounding box of items can give unsatisfactory visual results since items of differing widths will be placed with different gaps. Is only used if items overlap

Definition at line 570 of file placement_tool.cpp.

571 {
572  std::sort( itemsToDistribute.begin(), itemsToDistribute.end(),
573  [] ( const ALIGNMENT_RECT left, const ALIGNMENT_RECT right)
574  { return ( left.second.GetCenter().y < right.second.GetCenter().y ); } );
575  const auto totalGap = ( itemsToDistribute.end()-1 )->second.GetCenter().y
576  - itemsToDistribute.begin()->second.GetCenter().y;
577  const auto itemGap = totalGap / ( itemsToDistribute.size() - 1 );
578  auto targetY = itemsToDistribute.begin()->second.GetCenter().y;
579 
580  for( auto& i : itemsToDistribute )
581  {
582  BOARD_ITEM* item = i.first;
583 
584  // Don't move a pad by itself unless editing the footprint
585  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
586  item = item->GetParent();
587 
588  int difference = targetY - i.second.GetCenter().y;
589  item->Move( wxPoint( 0, difference ) );
590  targetY += ( itemGap );
591  }
592 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
std::pair< BOARD_ITEM *, EDA_RECT > ALIGNMENT_RECT
virtual const wxPoint GetCenter() const
Function GetCenter()
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References FRAME_PCB_EDITOR, BOARD_ITEM::GetCenter(), BOARD_ITEM::GetParent(), EDA_BASE_FRAME::IsType(), m_frame, BOARD_ITEM::Move(), PCB_PAD_T, EDA_ITEM::Type(), and wxPoint::y.

Referenced by DistributeVertically().

◆ doDistributeGapsHorizontally()

void ALIGN_DISTRIBUTE_TOOL::doDistributeGapsHorizontally ( ALIGNMENT_RECTS itemsToDistribute,
const BOARD_ITEM lastItem,
int  totalGap 
) const
private

Distributes selected items using an even spacing between their bounding boxes.

NOTE: Using the edges of bounding box of items is only possible if there is enough space between them. If this is not the case, use the center spacing method

Definition at line 443 of file placement_tool.cpp.

445 {
446  const auto itemGap = totalGap / ( itemsToDistribute.size() - 1 );
447  auto targetX = itemsToDistribute.begin()->second.GetX();
448 
449  for( auto& i : itemsToDistribute )
450  {
451  BOARD_ITEM* item = i.first;
452 
453  // cover the corner case where the last item is wider than the previous item and gap
454  if( lastItem == item )
455  continue;
456 
457  // Don't move a pad by itself unless editing the footprint
458  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
459  item = item->GetParent();
460 
461  int difference = targetX - i.second.GetX();
462  item->Move( wxPoint( difference, 0 ) );
463  targetX += ( i.second.GetWidth() + itemGap );
464  }
465 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), EDA_BASE_FRAME::IsType(), m_frame, BOARD_ITEM::Move(), PCB_PAD_T, and EDA_ITEM::Type().

Referenced by DistributeHorizontally().

◆ doDistributeGapsVertically()

void ALIGN_DISTRIBUTE_TOOL::doDistributeGapsVertically ( ALIGNMENT_RECTS itemsToDistribute,
const BOARD_ITEM lastItem,
int  totalGap 
) const
private

Distributes selected items using an even spacing between their bounding boxes.

NOTE: Using the edges of bounding box of items is only possible if there is enough space between them. If this is not the case, use the center spacing method

Definition at line 545 of file placement_tool.cpp.

547 {
548  const auto itemGap = totalGap / ( itemsToDistribute.size() - 1 );
549  auto targetY = itemsToDistribute.begin()->second.GetY();
550 
551  for( auto& i : itemsToDistribute )
552  {
553  BOARD_ITEM* item = i.first;
554 
555  // cover the corner case where the last item is wider than the previous item and gap
556  if( lastItem == item )
557  continue;
558 
559  // Don't move a pad by itself unless editing the footprint
560  if( item->Type() == PCB_PAD_T && m_frame->IsType( FRAME_PCB_EDITOR ) )
561  item = item->GetParent();
562 
563  int difference = targetY - i.second.GetY();
564  i.first->Move( wxPoint( 0, difference ) );
565  targetY += ( i.second.GetHeight() + itemGap );
566  }
567 }
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
class D_PAD, a pad in a footprint
Definition: typeinfo.h:90
virtual void Move(const wxPoint &aMoveVector)
Function Move move this object.
PCB_BASE_FRAME * m_frame
bool IsType(FRAME_T aType) const
BOARD_ITEM_CONTAINER * GetParent() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:207

References FRAME_PCB_EDITOR, BOARD_ITEM::GetParent(), EDA_BASE_FRAME::IsType(), m_frame, BOARD_ITEM::Move(), PCB_PAD_T, and EDA_ITEM::Type().

Referenced by DistributeVertically().

◆ getEditFrame()

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

Function getEditFrame()

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

Definition at line 187 of file tool_base.h.

188  {
189 #if !defined( QA_TEST ) // Dynamic casts give the linker a siezure in the test framework
190  wxASSERT( dynamic_cast<T*>( getEditFrameInt() ) );
191 #endif
192  return static_cast<T*>( getEditFrameInt() );
193  }
EDA_BASE_FRAME * getEditFrameInt() const
Definition: tool_base.cpp:48

References TOOL_BASE::getEditFrameInt().

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

◆ GetId()

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

122  {
123  return m_toolId;
124  }
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214

References TOOL_BASE::m_toolId.

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

◆ GetManager()

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

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

References TOOL_BASE::m_toolMgr.

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

◆ getModel()

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

Function getModel()

Returns the model object if it matches the requested type.

Definition at line 201 of file tool_base.h.

202  {
203  EDA_ITEM* m = getModelInt();
204 #if !defined( QA_TEST ) // Dynamic casts give the linker a siezure in the test framework
205  wxASSERT( dynamic_cast<T*>( m ) );
206 #endif
207  return static_cast<T*>( m );
208  }
EDA_ITEM * getModelInt() const
Definition: tool_base.cpp:54
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:163

References TOOL_BASE::getModelInt().

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

◆ GetName()

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

133  {
134  return m_toolName;
135  }
std::string m_toolName
Name of the tool.
Definition: tool_base.h:218

References TOOL_BASE::m_toolName.

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

◆ GetSelections()

template<typename T >
size_t ALIGN_DISTRIBUTE_TOOL::GetSelections ( ALIGNMENT_RECTS aItems,
ALIGNMENT_RECTS aLocked,
aCompare 
)
private

Function GetSelections() Populates two vectors with the sorted selection and sorted locked items Returns the size of aItems()

Definition at line 139 of file placement_tool.cpp.

140 {
141 
143  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
144  { EditToolSelectionFilter( aCollector, EXCLUDE_TRANSIENTS ); } );
145 
146  if( selection.Size() <= 1 )
147  return 0;
148 
149  std::vector<BOARD_ITEM*> lockedItems;
150  selection = m_selectionTool->RequestSelection(
151  []( const VECTOR2I& aPt, GENERAL_COLLECTOR& aCollector )
152  { EditToolSelectionFilter( aCollector, EXCLUDE_LOCKED ); }, &lockedItems );
153 
154  aItems = GetBoundingBoxes( selection );
155  aLocked = GetBoundingBoxes( lockedItems );
156  std::sort( aItems.begin(), aItems.end(), aCompare );
157  std::sort( aLocked.begin(), aLocked.end(), aCompare );
158 
159  return aItems.size();
160 }
ALIGNMENT_RECTS GetBoundingBoxes(const T &sel)
#define EXCLUDE_TRANSIENTS
Definition: edit_tool.h:55
PCBNEW_SELECTION & RequestSelection(CLIENT_SELECTION_FILTER aClientFilter, std::vector< BOARD_ITEM * > *aFiltered=nullptr, bool aConfirmLockedItems=false)
Function RequestSelection()
Used when the right click button is pressed, or when the select tool is in effect.
Definition: collectors.h:240
int Size() const
Returns the number of selected parts.
Definition: selection.h:126
SELECTION_TOOL * m_selectionTool
#define EXCLUDE_LOCKED
Function EditToolSelectionFilter.
Definition: edit_tool.h:53
void EditToolSelectionFilter(GENERAL_COLLECTOR &aCollector, int aFlags)
Definition: edit_tool.cpp:59

References EditToolSelectionFilter(), EXCLUDE_LOCKED, EXCLUDE_TRANSIENTS, GetBoundingBoxes(), m_selectionTool, SELECTION_TOOL::RequestSelection(), and SELECTION::Size().

Referenced by AlignBottom(), AlignCenterX(), AlignCenterY(), AlignTop(), doAlignLeft(), and doAlignRight().

◆ GetSettings()

TOOL_SETTINGS & TOOL_BASE::GetSettings ( )
inherited

Definition at line 78 of file tool_base.cpp.

79 {
80  return m_toolSettings;
81 }
TOOL_SETTINGS m_toolSettings
Definition: tool_base.h:220

References TOOL_BASE::m_toolSettings.

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

◆ GetToolMenu()

◆ GetType()

TOOL_TYPE TOOL_BASE::GetType ( ) const
inlineinherited

Function GetType() Returns the type of the tool.

Returns
The type of the tool.

Definition at line 110 of file tool_base.h.

111  {
112  return m_type;
113  }
TOOL_TYPE m_type
Stores the type of the tool.
Definition: tool_base.h:211

References TOOL_BASE::m_type.

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

◆ getView()

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 36 of file tool_base.cpp.

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

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

Referenced by EE_POINT_EDITOR::addCornerCondition(), AlignLeft(), AlignRight(), COMMON_TOOLS::CenterContents(), EE_SELECTION_TOOL::ClearSelection(), COMMON_TOOLS::CursorControl(), LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), GERBVIEW_SELECTION_TOOL::disambiguationMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), MICROWAVE_TOOL::drawMicrowaveInductor(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), EE_SELECTION_TOOL::GetNode(), ROUTER_TOOL::getStartLayer(), COMMON_TOOLS::GridPreset(), PCBNEW_CONTROL::GridResetOrigin(), PCBNEW_CONTROL::GridSetOrigin(), SELECTION_TOOL::GuessSelectionCandidates(), EE_SELECTION_TOOL::highlight(), SELECTION_TOOL::highlight(), GERBVIEW_CONTROL::HighlightControl(), PNS::TOOL_BASE::highlightNet(), PCB_INSPECTION_TOOL::highlightNet(), EE_POINT_EDITOR::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::MoveExact(), SCH_MOVE_TOOL::moveItem(), POINT_EDITOR::OnSelectionChange(), COMMON_TOOLS::PanControl(), LIB_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PNS::TOOL_BASE::pickSingleItem(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Remove(), PCB_EDITOR_CONTROL::Reset(), PNS::TOOL_BASE::Reset(), PCBNEW_CONTROL::Reset(), GERBVIEW_SELECTION_TOOL::Reset(), DRAWING_TOOL::Reset(), EE_SELECTION_TOOL::Reset(), SELECTION_TOOL::Reset(), EE_TOOL_BASE< SCH_BASE_FRAME >::Reset(), SCH_EDIT_TOOL::Rotate(), GERBVIEW_SELECTION_TOOL::select(), GERBVIEW_SELECTION_TOOL::selectable(), SELECTION_TOOL::Selectable(), EE_SELECTION_TOOL::selectionContains(), SELECTION_TOOL::selectionContains(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::SelectPoint(), ZOOM_TOOL::selectRegion(), GERBVIEW_SELECTION_TOOL::selectVisually(), COMMON_TOOLS::ToggleGrid(), SCH_EDITOR_CONTROL::ToggleHiddenPins(), EE_SELECTION_TOOL::unhighlight(), SELECTION_TOOL::unhighlight(), GERBVIEW_SELECTION_TOOL::unselect(), GERBVIEW_SELECTION_TOOL::unselectVisually(), EE_POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateEditedPoint(), SCH_EDITOR_CONTROL::UpdateFind(), PCBNEW_CONTROL::updateGrid(), EE_POINT_EDITOR::updateItem(), SCH_EDITOR_CONTROL::UpdateNetHighlighting(), EE_POINT_EDITOR::updatePoints(), POINT_EDITOR::updatePoints(), SELECTION_TOOL::updateSelection(), PNS::TOOL_BASE::updateStartItem(), EE_TOOL_BASE< SCH_BASE_FRAME >::updateView(), PCB_TOOL_BASE::view(), COMMON_TOOLS::ZoomFitScreen(), SELECTION_TOOL::zoomFitSelection(), EE_SELECTION_TOOL::~EE_SELECTION_TOOL(), GERBVIEW_SELECTION_TOOL::~GERBVIEW_SELECTION_TOOL(), and SELECTION_TOOL::~SELECTION_TOOL().

◆ getViewControls()

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

Function getViewControls()

Returns the instance of VIEW_CONTROLS object used in the application. It allows tools to read & modify user input and its settings (eg. show cursor, enable snapping to grid, etc.)

Returns
The instance of VIEW_CONTROLS.

Definition at line 42 of file tool_base.cpp.

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

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

Referenced by EE_POINT_EDITOR::addCorner(), POINT_EDITOR::addCorner(), EE_POINT_EDITOR::addCornerCondition(), SCH_EDIT_TOOL::BreakWire(), PCB_TOOL_BASE::controls(), COMMON_TOOLS::CursorControl(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), COMMON_TOOLS::doZoomToPreset(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawLine(), MICROWAVE_TOOL::drawMicrowaveInductor(), SCH_LINE_WIRE_BUS_TOOL::DrawSegments(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), LIB_EDIT_TOOL::Duplicate(), PAD_TOOL::EnumeratePads(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), COMMON_TOOLS::GridPreset(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), LIB_EDIT_TOOL::Paste(), ROUTER_TOOL::performDragging(), LIB_DRAWING_TOOLS::PlaceAnchor(), PCBNEW_CONTROL::placeBoardItems(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), SCH_EDIT_TOOL::RepeatDrawItem(), EE_SELECTION_TOOL::RequestSelection(), POINT_EDITOR::Reset(), DRAWING_TOOL::Reset(), COMMON_TOOLS::ResetLocalCoords(), GERBVIEW_SELECTION_TOOL::selectCursor(), SELECTION_TOOL::selectCursor(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), EE_SELECTION_TOOL::SelectNode(), ZOOM_TOOL::selectRegion(), selectTarget(), PICKER_TOOL::setControls(), PCBNEW_PICKER_TOOL::setControls(), EE_POINT_EDITOR::setEditedPoint(), POINT_EDITOR::setEditedPoint(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), EE_POINT_EDITOR::updateEditedPoint(), POINT_EDITOR::updateEditedPoint(), LIB_MOVE_TOOL::updateModificationPoint(), EDIT_TOOL::updateModificationPoint(), and COMMON_TOOLS::ZoomCenter().

◆ Go()

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

Function Go()

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

Definition at line 129 of file tool_interactive.h.

131 {
132  TOOL_STATE_FUNC sptr = std::bind( aStateFunc, static_cast<T*>( this ), std::placeholders::_1 );
133 
134  goInternal( sptr, aConditions );
135 }
std::function< int(const TOOL_EVENT &)> TOOL_STATE_FUNC
Definition: tool_base.h:58
void goInternal(TOOL_STATE_FUNC &aState, const TOOL_EVENT_LIST &aConditions)

References TOOL_INTERACTIVE::goInternal().

Referenced by LENGTH_TUNER_TOOL::setTransitions(), ZOOM_TOOL::setTransitions(), AUTOPLACE_TOOL::setTransitions(), MICROWAVE_TOOL::setTransitions(), ROUTER_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_CONTROL::setTransitions(), LIB_PIN_TOOL::setTransitions(), PAD_TOOL::setTransitions(), EE_INSPECTION_TOOL::setTransitions(), ZONE_FILLER_TOOL::setTransitions(), COMMON_CONTROL::setTransitions(), LIB_DRAWING_TOOLS::setTransitions(), EE_POINT_EDITOR::setTransitions(), KICAD_MANAGER_CONTROL::setTransitions(), SCH_MOVE_TOOL::setTransitions(), LIB_MOVE_TOOL::setTransitions(), GERBVIEW_CONTROL::setTransitions(), SCH_DRAWING_TOOLS::setTransitions(), POINT_EDITOR::setTransitions(), GLOBAL_EDIT_TOOL::setTransitions(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::setTransitions(), LIB_CONTROL::setTransitions(), LIB_EDIT_TOOL::setTransitions(), SCH_EDIT_TOOL::setTransitions(), POSITION_RELATIVE_TOOL::setTransitions(), GERBVIEW_SELECTION_TOOL::setTransitions(), COMMON_TOOLS::setTransitions(), PCB_INSPECTION_TOOL::setTransitions(), PCBNEW_CONTROL::setTransitions(), setTransitions(), MODULE_EDITOR_TOOLS::setTransitions(), SCH_LINE_WIRE_BUS_TOOL::setTransitions(), CVPCB_CONTROL::setTransitions(), CVPCB_ASSOCIATION_TOOL::setTransitions(), PCBNEW_PICKER_TOOL::setTransitions(), PICKER_TOOL::setTransitions(), PCB_EDITOR_CONTROL::setTransitions(), DRAWING_TOOL::setTransitions(), EDIT_TOOL::setTransitions(), SELECTION_TOOL::setTransitions(), SCH_EDITOR_CONTROL::setTransitions(), EE_SELECTION_TOOL::setTransitions(), and DRC::setTransitions().

◆ Init()

bool ALIGN_DISTRIBUTE_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 53 of file placement_tool.cpp.

54 {
55  // Find the selection tool, so they can cooperate
57 
58  wxASSERT_MSG( m_selectionTool, _( "pcbnew.InteractiveSelection tool is not available" ) );
59 
60  m_frame = getEditFrame<PCB_BASE_FRAME>();
61 
62  // Create a context menu and make it available through selection tool
63  m_placementMenu = new ACTION_MENU( true );
64  m_placementMenu->SetTool( this );
66  m_placementMenu->SetTitle( _( "Align/Distribute" ) );
67 
68  // Add all align/distribute commands
75 
76  m_placementMenu->AppendSeparator();
79 
82 
83  return true;
84 }
static TOOL_ACTION alignRight
Definition: pcb_actions.h:211
void AddMenu(ACTION_MENU *aMenu, const SELECTION_CONDITION &aCondition=SELECTION_CONDITIONS::ShowAlways, int aOrder=ANY_ORDER)
Function AddMenu()
wxMenuItem * Add(const wxString &aLabel, int aId, const BITMAP_OPAQUE *aIcon)
Function Add() Adds a wxWidgets-style entry to the menu.
ACTION_MENU.
Definition: action_menu.h:43
static SELECTION_CONDITION MoreThan(int aNumber)
Function MoreThan Creates a functor that tests if the number of selected items is greater than the va...
ACTION_MENU * m_placementMenu
SELECTION_TOOL.
CONDITIONAL_MENU & GetMenu()
Function GetMenu.
Definition: tool_menu.cpp:46
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
static TOOL_ACTION alignCenterY
Definition: pcb_actions.h:213
TOOL_MENU & GetToolMenu()
static TOOL_ACTION distributeVertically
Definition: pcb_actions.h:215
static TOOL_ACTION alignBottom
Definition: pcb_actions.h:209
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
static TOOL_ACTION distributeHorizontally
Definition: pcb_actions.h:214
const BITMAP_OPAQUE align_items_xpm[1]
Definition: align_items.cpp:21
void SetIcon(const BITMAP_OPAQUE *aIcon)
Function SetIcon() Assigns an icon for the entry.
Definition: action_menu.cpp:68
static TOOL_ACTION alignLeft
Definition: pcb_actions.h:210
static TOOL_ACTION alignTop
Definition: pcb_actions.h:208
void SetTitle(const wxString &aTitle) override
Function SetTitle() Sets title for the menu.
Definition: action_menu.cpp:86
PCB_BASE_FRAME * m_frame
#define _(s)
Definition: 3d_actions.cpp:31
SELECTION_TOOL * m_selectionTool
static TOOL_ACTION alignCenterX
Definition: pcb_actions.h:212

References _, ACTION_MENU::Add(), CONDITIONAL_MENU::AddMenu(), align_items_xpm, PCB_ACTIONS::alignBottom, PCB_ACTIONS::alignCenterX, PCB_ACTIONS::alignCenterY, PCB_ACTIONS::alignLeft, PCB_ACTIONS::alignRight, PCB_ACTIONS::alignTop, PCB_ACTIONS::distributeHorizontally, PCB_ACTIONS::distributeVertically, TOOL_MENU::GetMenu(), TOOL_MANAGER::GetTool(), TOOL_INTERACTIVE::GetToolMenu(), m_frame, m_placementMenu, m_selectionTool, TOOL_BASE::m_toolMgr, SELECTION_CONDITIONS::MoreThan(), ACTION_MENU::SetIcon(), ACTION_MENU::SetTitle(), and ACTION_MENU::SetTool().

◆ IsToolActive()

bool TOOL_BASE::IsToolActive ( ) const
inherited

Definition at line 31 of file tool_base.cpp.

32 {
33  return m_toolMgr->IsToolActive( m_toolId );
34 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
TOOL_ID m_toolId
Unique identifier for the tool, assigned by a TOOL_MANAGER instance.
Definition: tool_base.h:214
bool IsToolActive(TOOL_ID aId) const
Function IsToolActive() Returns true if a tool with given id is active (executing)

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

◆ Reset()

void ALIGN_DISTRIBUTE_TOOL::Reset ( RESET_REASON  aReason)
inlineoverridevirtual

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 45 of file placement_tool.h.

45 {}

◆ RunMainStack()

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 87 of file tool_interactive.cpp.

88 {
89  m_toolMgr->RunMainStack( this, std::move( aFunc ) );
90 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void RunMainStack(TOOL_BASE *aTool, std::function< void()> aFunc)

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

Referenced by DRAWING_TOOL::PlaceText().

◆ selectTarget()

template<typename T >
int ALIGN_DISTRIBUTE_TOOL::selectTarget ( ALIGNMENT_RECTS aItems,
ALIGNMENT_RECTS aLocked,
aGetValue 
)
private

Definition at line 107 of file placement_tool.cpp.

108 {
109  wxPoint curPos( getViewControls()->GetCursorPosition().x, getViewControls()->GetCursorPosition().y );
110 
111  // after sorting, the fist item acts as the target for all others
112  // unless we have a locked item, in which case we use that for the target
113  int target = !aLocked.size() ? aGetValue( aItems.front() ): aGetValue( aLocked.front() );
114 
115  // We take the first target that overlaps our cursor.
116  // This is deterministic because we assume sorted arrays
117  for( auto item : aLocked )
118  {
119  if( item.second.Contains( curPos ) )
120  return aGetValue( item );
121  }
122 
123  // If there are locked items, prefer aligning to them over
124  // aligning to the cursor as they do not move
125  if( aLocked.empty() )
126  {
127  for( auto item : aItems )
128  {
129  if( item.second.Contains( curPos ) )
130  return aGetValue( item );
131  }
132  }
133 
134  return target;
135 }
KIGFX::VIEW_CONTROLS * getViewControls() const
Function getViewControls()
Definition: tool_base.cpp:42

References TOOL_BASE::getViewControls().

Referenced by AlignBottom(), AlignCenterX(), AlignCenterY(), AlignTop(), doAlignLeft(), and doAlignRight().

◆ SetContextMenu()

void TOOL_INTERACTIVE::SetContextMenu ( ACTION_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 76 of file tool_interactive.cpp.

77 {
78  if( aMenu )
79  aMenu->SetTool( this );
80  else
81  aTrigger = CMENU_OFF;
82 
83  m_toolMgr->ScheduleContextMenu( this, aMenu, aTrigger );
84 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
void SetTool(TOOL_INTERACTIVE *aTool)
Function SetTool() Sets a tool that is the creator of the menu.
void ScheduleContextMenu(TOOL_BASE *aTool, ACTION_MENU *aMenu, CONTEXT_MENU_TRIGGER aTrigger)
Sets behaviour of the tool's context popup menu.

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

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), TOOL_MENU::ShowContextMenu(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

◆ setTransitions()

void ALIGN_DISTRIBUTE_TOOL::setTransitions ( )
overridevirtual

Sets up handlers for various events.

Implements TOOL_INTERACTIVE.

Definition at line 595 of file placement_tool.cpp.

596 {
603 
606 }
static TOOL_ACTION alignRight
Definition: pcb_actions.h:211
int AlignLeft(const TOOL_EVENT &aEvent)
Function AlignLeft() Sets X coordinate of the selected items to the value of the left-most selected i...
int AlignCenterY(const TOOL_EVENT &aEvent)
Function AlignCenterX() Sets the y coordinate of the midpoint of each of the selected items to the va...
int AlignCenterX(const TOOL_EVENT &aEvent)
Function AlignCenterX() Sets the x coordinate of the midpoint of each of the selected items to the va...
static TOOL_ACTION alignCenterY
Definition: pcb_actions.h:213
int AlignBottom(const TOOL_EVENT &aEvent)
Function AlignBottom() Sets Y coordinate of the selected items to the value of the bottom-most select...
static TOOL_ACTION distributeVertically
Definition: pcb_actions.h:215
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Function Go()
static TOOL_ACTION alignBottom
Definition: pcb_actions.h:209
static TOOL_ACTION distributeHorizontally
Definition: pcb_actions.h:214
int DistributeHorizontally(const TOOL_EVENT &aEvent)
Function DistributeHorizontally() Distributes the selected items along the X axis.
int AlignTop(const TOOL_EVENT &aEvent)
Function AlignTop() Sets Y coordinate of the selected items to the value of the top-most selected ite...
int DistributeVertically(const TOOL_EVENT &aEvent)
Function DistributeVertically() Distributes the selected items along the Y axis.
static TOOL_ACTION alignLeft
Definition: pcb_actions.h:210
static TOOL_ACTION alignTop
Definition: pcb_actions.h:208
int AlignRight(const TOOL_EVENT &aEvent)
Function AlignRight() Sets X coordinate of the selected items to the value of the right-most selected...
static TOOL_ACTION alignCenterX
Definition: pcb_actions.h:212

References AlignBottom(), PCB_ACTIONS::alignBottom, AlignCenterX(), PCB_ACTIONS::alignCenterX, AlignCenterY(), PCB_ACTIONS::alignCenterY, AlignLeft(), PCB_ACTIONS::alignLeft, AlignRight(), PCB_ACTIONS::alignRight, AlignTop(), PCB_ACTIONS::alignTop, DistributeHorizontally(), PCB_ACTIONS::distributeHorizontally, DistributeVertically(), PCB_ACTIONS::distributeVertically, and TOOL_INTERACTIVE::Go().

◆ Wait()

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 57 of file tool_interactive.cpp.

58 {
59  return m_toolMgr->ScheduleWait( this, aEventList );
60 }
TOOL_MANAGER * m_toolMgr
Definition: tool_base.h:219
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.

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

Referenced by GERBVIEW_SELECTION_TOOL::disambiguationMenu(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), EE_SELECTION_TOOL::doSelectionMenu(), SELECTION_TOOL::doSelectionMenu(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), ROUTER_TOOL::InlineDrag(), ZOOM_TOOL::Main(), CVPCB_CONTROL::Main(), SCH_MOVE_TOOL::Main(), EE_POINT_EDITOR::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), EDIT_TOOL::Move(), POINT_EDITOR::OnSelectionChange(), ROUTER_TOOL::performDragging(), ROUTER_TOOL::performRouting(), LENGTH_TUNER_TOOL::performTuning(), EDIT_TOOL::pickCopyReferencePoint(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), EDIT_TOOL::Remove(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), GERBVIEW_SELECTION_TOOL::selectPoint(), SELECTION_TOOL::selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), ZOOM_TOOL::selectRegion(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), and SCH_LINE_WIRE_BUS_TOOL::UnfoldBus().

Member Data Documentation

◆ m_frame

◆ m_menu

TOOL_MENU TOOL_INTERACTIVE::m_menu
protectedinherited

functions below are not yet implemented - their interface may change

Definition at line 108 of file tool_interactive.h.

Referenced by SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawDimension(), MICROWAVE_TOOL::drawMicrowaveInductor(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PAD_TOOL::EnumeratePads(), TOOL_INTERACTIVE::GetToolMenu(), PICKER_TOOL::Init(), SCH_EDIT_TOOL::Init(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Init(), LIB_DRAWING_TOOLS::Init(), MODULE_EDITOR_TOOLS::Init(), LIB_CONTROL::Init(), PCB_EDITOR_CONTROL::Init(), SCH_DRAWING_TOOLS::Init(), GERBVIEW_SELECTION_TOOL::Init(), DRAWING_TOOL::Init(), EE_SELECTION_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), SELECTION_TOOL::Init(), SCH_LINE_WIRE_BUS_TOOL::Init(), EDIT_TOOL::Init(), PCB_TOOL_BASE::Init(), SCH_MOVE_TOOL::Main(), LIB_MOVE_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::Main(), PCBNEW_PICKER_TOOL::Main(), PICKER_TOOL::Main(), GERBVIEW_SELECTION_TOOL::Main(), EE_SELECTION_TOOL::Main(), SELECTION_TOOL::Main(), CVPCB_FOOTPRINT_VIEWER_SELECTION_TOOL::MeasureTool(), GERBVIEW_SELECTION_TOOL::MeasureTool(), EDIT_TOOL::MeasureTool(), LIB_DRAWING_TOOLS::PlaceAnchor(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), DRAWING_TOOL::SetAnchor(), SCH_DRAWING_TOOLS::SingleClickPlace(), LIB_DRAWING_TOOLS::TwoClickPlace(), and SCH_DRAWING_TOOLS::TwoClickPlace().

◆ m_placementMenu

ACTION_MENU* ALIGN_DISTRIBUTE_TOOL::m_placementMenu
private

Definition at line 134 of file placement_tool.h.

Referenced by Init(), and ~ALIGN_DISTRIBUTE_TOOL().

◆ m_selectionTool

◆ m_toolId

TOOL_ID TOOL_BASE::m_toolId
protectedinherited

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

Definition at line 214 of file tool_base.h.

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

◆ m_toolMgr

TOOL_MANAGER* TOOL_BASE::m_toolMgr
protectedinherited

Definition at line 219 of file tool_base.h.

Referenced by TOOL_INTERACTIVE::Activate(), EE_SELECTION_TOOL::AddItemsToSel(), EE_SELECTION_TOOL::AddItemToSel(), SELECTION_TOOL::AddItemToSel(), CVPCB_ASSOCIATION_TOOL::Associate(), TOOL_BASE::attachManager(), PCB_INSPECTION_TOOL::calculateSelectionRatsnest(), ROUTER_TOOL::CanInlineDrag(), EDIT_TOOL::ChangeTrackWidth(), PCB_INSPECTION_TOOL::ClearHighlight(), SCH_EDITOR_CONTROL::ClearHighlight(), SELECTION_TOOL::ClearSelection(), GERBVIEW_SELECTION_TOOL::clearSelection(), EE_SELECTION_TOOL::ClearSelection(), SCH_EDIT_TOOL::ConvertDeMorgan(), LIB_EDIT_TOOL::Copy(), PAD_TOOL::copyPadSettings(), MICROWAVE_TOOL::createInductorBetween(), MODULE_EDITOR_TOOLS::CreatePadFromShapes(), PCB_INSPECTION_TOOL::CrossProbePcbToSch(), COMMON_TOOLS::CursorControl(), ROUTER_TOOL::CustomTrackWidthDialog(), SCH_EDITOR_CONTROL::Cut(), LIB_EDIT_TOOL::DeleteItemCursor(), SCH_EDIT_TOOL::DeleteItemCursor(), PCBNEW_CONTROL::DeleteItemCursor(), SCH_EDITOR_CONTROL::doCopy(), SCH_EDITOR_CONTROL::doCrossProbeSchToPcb(), LIB_EDIT_TOOL::DoDelete(), SCH_EDIT_TOOL::DoDelete(), SCH_LINE_WIRE_BUS_TOOL::doDrawSegments(), PCB_TOOL_BASE::doInteractiveItemPlacement(), SCH_LINE_WIRE_BUS_TOOL::doUnfoldBus(), DRAWING_TOOL::DrawArc(), DRAWING_TOOL::drawArc(), DRAWING_TOOL::DrawCircle(), DRAWING_TOOL::DrawDimension(), DRAWING_TOOL::drawSegment(), LIB_DRAWING_TOOLS::DrawShape(), SCH_DRAWING_TOOLS::DrawSheet(), DRAWING_TOOL::DrawZone(), PCB_EDITOR_CONTROL::DrillOrigin(), LIB_EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::Duplicate(), EDIT_TOOL::Duplicate(), SCH_EDIT_TOOL::editComponentFieldText(), EDIT_TOOL::EditFpInFpEditor(), LIB_EDIT_TOOL::editSymbolProperties(), SCH_EDITOR_CONTROL::EditWithLibEdit(), SCH_EDITOR_CONTROL::EnterSheet(), PAD_TOOL::EnumeratePads(), GLOBAL_EDIT_TOOL::ExchangeFootprints(), SELECTION_TOOL::expandConnection(), MODULE_EDITOR_TOOLS::ExplodePadToShapes(), SELECTION_TOOL::filterSelection(), SELECTION_TOOL::findCallback(), SCH_EDITOR_CONTROL::FindComponentAndItem(), POINT_EDITOR::finishItem(), SCH_LINE_WIRE_BUS_TOOL::finishSegments(), EDIT_TOOL::Flip(), EDIT_TOOL::GetAndPlace(), TOOL_BASE::getEditFrameInt(), TOOL_BASE::GetManager(), TOOL_BASE::getModelInt(), DRAWING_TOOL::getSourceZoneForAction(), TOOL_BASE::getView(), TOOL_BASE::getViewControls(), TOOL_INTERACTIVE::goInternal(), PCBNEW_CONTROL::GridSetOrigin(), GERBVIEW_CONTROL::HighlightControl(), PCB_INSPECTION_TOOL::HighlightItem(), PCB_INSPECTION_TOOL::HighlightNet(), SCH_EDITOR_CONTROL::HighlightNet(), PCB_INSPECTION_TOOL::highlightNet(), SCH_EDITOR_CONTROL::HighlightNetCursor(), PCB_INSPECTION_TOOL::HighlightNetTool(), MODULE_EDITOR_TOOLS::ImportFootprint(), LIB_EDIT_TOOL::Init(), SCH_EDIT_TOOL::Init(), PAD_TOOL::Init(), GLOBAL_EDIT_TOOL::Init(), Init(), LIB_CONTROL::Init(), PCB_EDITOR_CONTROL::Init(), POINT_EDITOR::Init(), POSITION_RELATIVE_TOOL::Init(), EE_TOOL_BASE< SCH_BASE_FRAME >::Init(), EDIT_TOOL::Init(), ROUTER_TOOL::InlineBreakTrack(), ROUTER_TOOL::InlineDrag(), EDIT_TOOL::invokeInlineRouter(), EDIT_TOOL::isInteractiveDragEnabled(), TOOL_BASE::IsToolActive(), SCH_EDITOR_CONTROL::LeaveSheet(), COMMON_CONTROL::ListHotKeys(), PCB_INSPECTION_TOOL::LocalRatsnestTool(), SCH_MOVE_TOOL::Main(), CVPCB_CONTROL::Main(), LIB_MOVE_TOOL::Main(), EE_SELECTION_TOOL::Main(), SELECTION_TOOL::Main(), ROUTER_TOOL::MainLoop(), LENGTH_TUNER_TOOL::MainLoop(), LIB_EDIT_TOOL::Mirror(), SCH_EDIT_TOOL::Mirror(), EDIT_TOOL::Mirror(), PCB_EDITOR_CONTROL::modifyLockSelected(), EDIT_TOOL::Move(), EDIT_TOOL::MoveExact(), LIB_CONTROL::OnDeMorgan(), LIB_EDIT_TOOL::Paste(), SCH_EDITOR_CONTROL::Paste(), PAD_TOOL::pastePadProperties(), EDIT_TOOL::pickCopyReferencePoint(), LIB_EDIT_TOOL::PinTable(), PCBNEW_CONTROL::placeBoardItems(), SCH_DRAWING_TOOLS::PlaceComponent(), SCH_DRAWING_TOOLS::PlaceImage(), DRAWING_TOOL::PlaceImportedGraphics(), PCB_EDITOR_CONTROL::PlaceModule(), PCB_EDITOR_CONTROL::PlaceTarget(), DRAWING_TOOL::PlaceText(), PCBNEW_CONTROL::Print(), GERBVIEW_CONTROL::Print(), LIB_EDIT_TOOL::Properties(), SCH_EDIT_TOOL::Properties(), EDIT_TOOL::Properties(), PAD_TOOL::pushPadSettings(), EE_SELECTION_TOOL::RebuildSelection(), LIB_EDIT_TOOL::Redo(), SCH_EDITOR_CONTROL::Redo(), POSITION_RELATIVE_TOOL::RelativeItemSelectionMove(), EDIT_TOOL::Remove(), POINT_EDITOR::removeCorner(), EE_SELECTION_TOOL::RemoveItemFromSel(), SELECTION_TOOL::RemoveItemFromSel(), EE_SELECTION_TOOL::RemoveItemsFromSel(), SCH_EDIT_TOOL::RepeatDrawItem(), LIB_DRAWING_TOOLS::RepeatDrawItem(), EE_SELECTION_TOOL::RequestSelection(), SELECTION_TOOL::RequestSelection(), COMMON_TOOLS::ResetLocalCoords(), TOOL_INTERACTIVE::resetTransitions(), LIB_EDIT_TOOL::Rotate(), SCH_EDIT_TOOL::Rotate(), EDIT_TOOL::Rotate(), TOOL_INTERACTIVE::RunMainStack(), DRC::RunTests(), EE_SELECTION_TOOL::SelectConnection(), PCB_TOOL_BASE::selection(), COMMON_TOOLS::SelectionTool(), GERBVIEW_SELECTION_TOOL::SelectItem(), GERBVIEW_SELECTION_TOOL::SelectItems(), SELECTION_TOOL::SelectItems(), EE_SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectMultiple(), SELECTION_TOOL::selectNet(), GERBVIEW_SELECTION_TOOL::selectPoint(), EE_SELECTION_TOOL::SelectPoint(), SELECTION_TOOL::selectPoint(), POSITION_RELATIVE_TOOL::SelectPositionRelativeItem(), SELECTION_TOOL::selectSameSheet(), SELECTION_TOOL::selectSheetContents(), DRAWING_TOOL::SetAnchor(), TOOL_INTERACTIVE::SetContextMenu(), DRC::ShowDRCDialog(), SCH_DRAWING_TOOLS::SingleClickPlace(), PCB_EDITOR_CONTROL::TrackWidthDec(), PCB_EDITOR_CONTROL::TrackWidthInc(), LIB_DRAWING_TOOLS::TwoClickPlace(), SCH_DRAWING_TOOLS::TwoClickPlace(), LIB_EDIT_TOOL::Undo(), SCH_EDITOR_CONTROL::Undo(), GERBVIEW_SELECTION_TOOL::UnselectItem(), GERBVIEW_SELECTION_TOOL::UnselectItems(), SELECTION_TOOL::UnselectItems(), EE_INSPECTION_TOOL::UpdateMessagePanel(), GERBVIEW_CONTROL::UpdateMessagePanel(), PCBNEW_CONTROL::UpdateMessagePanel(), PCB_INSPECTION_TOOL::UpdateSelectionRatsnest(), PCB_EDITOR_CONTROL::ViaSizeDec(), PCB_EDITOR_CONTROL::ViaSizeInc(), TOOL_INTERACTIVE::Wait(), PCB_EDITOR_CONTROL::ZoneDuplicate(), and PCB_EDITOR_CONTROL::ZoneMerge().

◆ m_toolName

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

Referenced by TOOL_BASE::GetName().

◆ m_toolSettings

TOOL_SETTINGS TOOL_BASE::m_toolSettings
protectedinherited

Definition at line 220 of file tool_base.h.

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

◆ m_type

TOOL_TYPE TOOL_BASE::m_type
protectedinherited

Stores the type of the tool.

Definition at line 211 of file tool_base.h.

Referenced by TOOL_BASE::GetType(), and BOARD_COMMIT::Push().


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