KiCad PCB EDA Suite
GRID_HELPER Class Reference

#include <grid_helper.h>

Inheritance diagram for GRID_HELPER:
EE_GRID_HELPER PCB_GRID_HELPER

Classes

struct  ANCHOR
 

Public Types

enum  ANCHOR_FLAGS {
  CORNER = 1, OUTLINE = 2, SNAPPABLE = 4, ORIGIN = 8,
  VERTICAL = 16, HORIZONTAL = 32, ALL = CORNER | OUTLINE | SNAPPABLE | ORIGIN | VERTICAL | HORIZONTAL
}
 

Public Member Functions

 GRID_HELPER (TOOL_MANAGER *aToolMgr)
 
virtual ~GRID_HELPER ()
 
VECTOR2I GetGrid () const
 
VECTOR2I GetOrigin () const
 
void SetAuxAxes (bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
 
virtual VECTOR2I Align (const VECTOR2I &aPoint) const
 
VECTOR2I AlignGrid (const VECTOR2I &aPoint) const
 
void SetSkipPoint (const VECTOR2I &aPoint)
 
void ClearSkipPoint ()
 We clear the skip point by setting it to an unreachable position, thereby preventing matching. More...
 
void SetSnap (bool aSnap)
 
bool GetSnap () const
 
void SetUseGrid (bool aSnapToGrid)
 
bool GetUseGrid () const
 
void SetSnapLine (bool aSnap)
 
void SetMask (int aMask)
 
void SetMaskFlag (int aFlag)
 
void ClearMaskFlag (int aFlag)
 

Protected Member Functions

void addAnchor (const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem)
 
void clearAnchors ()
 
bool canUseGrid () const
 Check whether it is possible to use the grid – this depends both on local grid helper settings and global (tool manager) KiCad settings. More...
 

Protected Attributes

std::vector< ANCHORm_anchors
 
TOOL_MANAGERm_toolMgr
 
OPT< VECTOR2Im_auxAxis
 
int m_maskTypes
 
bool m_enableSnap
 
bool m_enableGrid
 
bool m_enableSnapLine
 
ANCHORm_snapItem
 
VECTOR2I m_skipPoint
 
KIGFX::ORIGIN_VIEWITEM m_viewSnapPoint
 
KIGFX::ORIGIN_VIEWITEM m_viewSnapLine
 
KIGFX::ORIGIN_VIEWITEM m_viewAxis
 

Detailed Description

Definition at line 36 of file grid_helper.h.

Member Enumeration Documentation

◆ ANCHOR_FLAGS

Enumerator
CORNER 
OUTLINE 
SNAPPABLE 
ORIGIN 
VERTICAL 
HORIZONTAL 
ALL 

Definition at line 76 of file grid_helper.h.

Constructor & Destructor Documentation

◆ GRID_HELPER()

GRID_HELPER::GRID_HELPER ( TOOL_MANAGER aToolMgr)

Definition at line 35 of file grid_helper.cpp.

35  :
36  m_toolMgr( aToolMgr )
37 {
38  m_maskTypes = ALL;
39  m_enableSnap = true;
40  m_enableSnapLine = true;
41  m_enableGrid = true;
42  m_snapItem = nullptr;
43 }
ANCHOR * m_snapItem
Definition: grid_helper.h:137
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
bool m_enableSnap
Definition: grid_helper.h:134
bool m_enableSnapLine
Definition: grid_helper.h:136
bool m_enableGrid
Definition: grid_helper.h:135

References ALL, m_enableGrid, m_enableSnap, m_enableSnapLine, m_maskTypes, and m_snapItem.

◆ ~GRID_HELPER()

GRID_HELPER::~GRID_HELPER ( )
virtual

Definition at line 46 of file grid_helper.cpp.

47 {
48 }

Member Function Documentation

◆ addAnchor()

void GRID_HELPER::addAnchor ( const VECTOR2I aPos,
int  aFlags,
EDA_ITEM aItem 
)
inlineprotected

Definition at line 106 of file grid_helper.h.

107  {
108  if( ( aFlags & m_maskTypes ) == aFlags )
109  m_anchors.emplace_back( ANCHOR( aPos, aFlags, aItem ) );
110  }
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:127

References m_anchors, and m_maskTypes.

Referenced by EE_GRID_HELPER::computeAnchors(), and PCB_GRID_HELPER::computeAnchors().

◆ Align()

VECTOR2I GRID_HELPER::Align ( const VECTOR2I aPoint) const
virtual

Definition at line 95 of file grid_helper.cpp.

96 {
97  if( !canUseGrid() )
98  return aPoint;
99 
100  VECTOR2I nearest = AlignGrid( aPoint );
101 
102  if( !m_auxAxis )
103  return nearest;
104 
105  if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
106  nearest.x = m_auxAxis->x;
107 
108  if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
109  nearest.y = m_auxAxis->y;
110 
111  return nearest;
112 }
OPT< VECTOR2I > m_auxAxis
Definition: grid_helper.h:130
bool canUseGrid() const
Check whether it is possible to use the grid – this depends both on local grid helper settings and gl...
Definition: grid_helper.h:121
VECTOR2I AlignGrid(const VECTOR2I &aPoint) const
Definition: grid_helper.cpp:83

References AlignGrid(), canUseGrid(), m_auxAxis, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by EE_GRID_HELPER::BestSnapAnchor(), PCB_GRID_HELPER::BestSnapAnchor(), EE_GRID_HELPER::computeAnchors(), PNS::TOOL_BASE::snapToItem(), and PNS::TOOL_BASE::updateEndItem().

◆ AlignGrid()

VECTOR2I GRID_HELPER::AlignGrid ( const VECTOR2I aPoint) const

Definition at line 83 of file grid_helper.cpp.

84 {
85  const VECTOR2D gridOffset( GetOrigin() );
86  const VECTOR2D grid( GetGrid() );
87 
88  VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
89  KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
90 
91  return nearest;
92 }
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:59
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References GetGrid(), GetOrigin(), grid, KiROUND(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by Align().

◆ canUseGrid()

bool GRID_HELPER::canUseGrid ( ) const
inlineprotected

Check whether it is possible to use the grid – this depends both on local grid helper settings and global (tool manager) KiCad settings.

Definition at line 121 of file grid_helper.h.

122  {
124  }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
bool GetGridSnapping() const
bool m_enableGrid
Definition: grid_helper.h:135

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridSnapping(), TOOL_MANAGER::GetView(), m_enableGrid, and m_toolMgr.

Referenced by Align(), and EE_GRID_HELPER::BestSnapAnchor().

◆ clearAnchors()

void GRID_HELPER::clearAnchors ( )
inlineprotected

Definition at line 112 of file grid_helper.h.

113  {
114  m_anchors.clear();
115  }
std::vector< ANCHOR > m_anchors
Definition: grid_helper.h:127

References m_anchors.

Referenced by PCB_GRID_HELPER::BestDragOrigin(), EE_GRID_HELPER::BestDragOrigin(), EE_GRID_HELPER::BestSnapAnchor(), and PCB_GRID_HELPER::BestSnapAnchor().

◆ ClearMaskFlag()

void GRID_HELPER::ClearMaskFlag ( int  aFlag)
inline

Definition at line 74 of file grid_helper.h.

74 { m_maskTypes = m_maskTypes & ~aFlag; }

References m_maskTypes.

◆ ClearSkipPoint()

void GRID_HELPER::ClearSkipPoint ( )
inline

We clear the skip point by setting it to an unreachable position, thereby preventing matching.

Definition at line 59 of file grid_helper.h.

60  {
61  m_skipPoint = VECTOR2I( std::numeric_limits<int>::min(), std::numeric_limits<int>::min() );
62  }
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
VECTOR2I m_skipPoint
Definition: grid_helper.h:139

References m_skipPoint.

◆ GetGrid()

VECTOR2I GRID_HELPER::GetGrid ( ) const

Definition at line 51 of file grid_helper.cpp.

52 {
54 
55  return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
56 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const VECTOR2D & GetGridSize() const
Return the grid size.
constexpr ret_type KiROUND(fp_type v)
Round a floating point number to an integer using "round halfway cases away from zero".
Definition: util.h:68

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridSize(), TOOL_MANAGER::GetView(), KiROUND(), m_toolMgr, VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by AlignGrid(), PCB_GRID_HELPER::AlignToArc(), PCB_GRID_HELPER::AlignToSegment(), PCB_GRID_HELPER::BestSnapAnchor(), and PCB_GRID_HELPER::computeAnchors().

◆ GetOrigin()

VECTOR2I GRID_HELPER::GetOrigin ( ) const

Definition at line 59 of file grid_helper.cpp.

60 {
61  VECTOR2D origin = m_toolMgr->GetView()->GetGAL()->GetGridOrigin();
62 
63  return VECTOR2I( origin );
64 }
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:189
VECTOR2< int > VECTOR2I
Definition: vector2d.h:623
const VECTOR2D & GetGridOrigin() const

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridOrigin(), TOOL_MANAGER::GetView(), and m_toolMgr.

Referenced by AlignGrid(), PCB_GRID_HELPER::AlignToArc(), and PCB_GRID_HELPER::AlignToSegment().

◆ GetSnap()

bool GRID_HELPER::GetSnap ( ) const
inline

Definition at line 65 of file grid_helper.h.

65 { return m_enableSnap; }
bool m_enableSnap
Definition: grid_helper.h:134

References m_enableSnap.

Referenced by PNS::TOOL_BASE::updateEndItem().

◆ GetUseGrid()

bool GRID_HELPER::GetUseGrid ( ) const
inline

Definition at line 68 of file grid_helper.h.

68 { return m_enableGrid; }
bool m_enableGrid
Definition: grid_helper.h:135

References m_enableGrid.

Referenced by PNS::TOOL_BASE::updateStartItem().

◆ SetAuxAxes()

void GRID_HELPER::SetAuxAxes ( bool  aEnable,
const VECTOR2I aOrigin = VECTOR2I( 0, 0 ) 
)

Definition at line 67 of file grid_helper.cpp.

68 {
69  if( aEnable )
70  {
71  m_auxAxis = aOrigin;
72  m_viewAxis.SetPosition( wxPoint( aOrigin ) );
73  m_toolMgr->GetView()->SetVisible( &m_viewAxis, true );
74  }
75  else
76  {
78  m_toolMgr->GetView()->SetVisible( &m_viewAxis, false );
79  }
80 }
void SetPosition(const wxPoint &aPosition) override
OPT< VECTOR2I > m_auxAxis
Definition: grid_helper.h:130
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:289
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:129
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:143
boost::optional< T > OPT
Definition: optional.h:7
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1449

References TOOL_MANAGER::GetView(), m_auxAxis, m_toolMgr, m_viewAxis, KIGFX::ORIGIN_VIEWITEM::SetPosition(), and KIGFX::VIEW::SetVisible().

Referenced by ROUTER_TOOL::InlineDrag(), and ROUTER_TOOL::performDragging().

◆ SetMask()

void GRID_HELPER::SetMask ( int  aMask)
inline

Definition at line 72 of file grid_helper.h.

72 { m_maskTypes = aMask; }

References m_maskTypes.

◆ SetMaskFlag()

void GRID_HELPER::SetMaskFlag ( int  aFlag)
inline

Definition at line 73 of file grid_helper.h.

73 { m_maskTypes |= aFlag; }

References m_maskTypes.

◆ SetSkipPoint()

void GRID_HELPER::SetSkipPoint ( const VECTOR2I aPoint)
inline

Definition at line 51 of file grid_helper.h.

52  {
53  m_skipPoint = aPoint;
54  }
VECTOR2I m_skipPoint
Definition: grid_helper.h:139

References m_skipPoint.

◆ SetSnap()

void GRID_HELPER::SetSnap ( bool  aSnap)
inline

◆ SetSnapLine()

void GRID_HELPER::SetSnapLine ( bool  aSnap)
inline

Definition at line 70 of file grid_helper.h.

70 { m_enableSnapLine = aSnap; }
bool m_enableSnapLine
Definition: grid_helper.h:136

References m_enableSnapLine.

◆ SetUseGrid()

void GRID_HELPER::SetUseGrid ( bool  aSnapToGrid)
inline

Member Data Documentation

◆ m_anchors

std::vector<ANCHOR> GRID_HELPER::m_anchors
protected

◆ m_auxAxis

OPT<VECTOR2I> GRID_HELPER::m_auxAxis
protected

Definition at line 130 of file grid_helper.h.

Referenced by Align(), and SetAuxAxes().

◆ m_enableGrid

bool GRID_HELPER::m_enableGrid
protected

Definition at line 135 of file grid_helper.h.

Referenced by canUseGrid(), GetUseGrid(), GRID_HELPER(), and SetUseGrid().

◆ m_enableSnap

◆ m_enableSnapLine

bool GRID_HELPER::m_enableSnapLine
protected

◆ m_maskTypes

int GRID_HELPER::m_maskTypes
protected

Definition at line 132 of file grid_helper.h.

Referenced by addAnchor(), ClearMaskFlag(), GRID_HELPER(), SetMask(), and SetMaskFlag().

◆ m_skipPoint

VECTOR2I GRID_HELPER::m_skipPoint
protected

◆ m_snapItem

◆ m_toolMgr

◆ m_viewAxis

KIGFX::ORIGIN_VIEWITEM GRID_HELPER::m_viewAxis
protected

◆ m_viewSnapLine

◆ m_viewSnapPoint


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