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 GetVisibleGrid () 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
 
std::optional< 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 77 of file grid_helper.h.

77 {
78 CORNER = 1,
79 OUTLINE = 2,
80 SNAPPABLE = 4,
81 ORIGIN = 8,
82 VERTICAL = 16,
83 HORIZONTAL = 32,
85 };

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{
39 m_enableSnap = true;
40 m_enableSnapLine = true;
41 m_enableGrid = true;
42 m_snapItem = nullptr;
43}
bool m_enableGrid
Definition: grid_helper.h:137
TOOL_MANAGER * m_toolMgr
Definition: grid_helper.h:131
ANCHOR * m_snapItem
Definition: grid_helper.h:139
bool m_enableSnapLine
Definition: grid_helper.h:138
bool m_enableSnap
Definition: grid_helper.h:136

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 107 of file grid_helper.h.

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

References m_anchors, and m_maskTypes.

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

◆ Align()

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

Definition at line 103 of file grid_helper.cpp.

104{
105 if( !canUseGrid() )
106 return aPoint;
107
108 VECTOR2I nearest = AlignGrid( aPoint );
109
110 if( !m_auxAxis )
111 return nearest;
112
113 if( std::abs( m_auxAxis->x - aPoint.x ) < std::abs( nearest.x - aPoint.x ) )
114 nearest.x = m_auxAxis->x;
115
116 if( std::abs( m_auxAxis->y - aPoint.y ) < std::abs( nearest.y - aPoint.y ) )
117 nearest.y = m_auxAxis->y;
118
119 return nearest;
120}
std::optional< VECTOR2I > m_auxAxis
Definition: grid_helper.h:132
VECTOR2I AlignGrid(const VECTOR2I &aPoint) const
Definition: grid_helper.cpp:91
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:123
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Definition: eda_angle.h:401

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

Referenced by PCB_GRID_HELPER::AlignToArc(), PCB_GRID_HELPER::AlignToSegment(), PCB_GRID_HELPER::BestSnapAnchor(), EE_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 91 of file grid_helper.cpp.

92{
93 const VECTOR2D gridOffset( GetOrigin() );
94 const VECTOR2D grid( GetGrid() );
95
96 VECTOR2I nearest( KiROUND( ( aPoint.x - gridOffset.x ) / grid.x ) * grid.x + gridOffset.x,
97 KiROUND( ( aPoint.y - gridOffset.y ) / grid.y ) * grid.y + gridOffset.y );
98
99 return nearest;
100}
VECTOR2I GetGrid() const
Definition: grid_helper.cpp:51
VECTOR2I GetOrigin() const
Definition: grid_helper.cpp:67
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:85

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

Referenced by Align(), EC_VERTICAL::Apply(), EC_HORIZONTAL::Apply(), EC_45DEGREE::Apply(), EC_LINE::Apply(), and EE_POINT_EDITOR::pinEditedCorner().

◆ 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 123 of file grid_helper.h.

124 {
126 }
bool GetGridSnapping() const
GAL * GetGAL() const
Return the #GAL this view is using to draw graphical primitives.
Definition: view.h:195
KIGFX::VIEW * GetView() const
Definition: tool_manager.h:285

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

◆ ClearMaskFlag()

void GRID_HELPER::ClearMaskFlag ( int  aFlag)
inline

Definition at line 75 of file grid_helper.h.

75{ 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 60 of file grid_helper.h.

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

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}
const VECTOR2D & GetGridSize() const
Return the grid size.

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

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

◆ GetOrigin()

VECTOR2I GRID_HELPER::GetOrigin ( ) const

Definition at line 67 of file grid_helper.cpp.

68{
70
71 return VECTOR2I( origin );
72}
const VECTOR2D & GetGridOrigin() const

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

Referenced by AlignGrid().

◆ GetSnap()

bool GRID_HELPER::GetSnap ( ) const
inline

◆ GetUseGrid()

bool GRID_HELPER::GetUseGrid ( ) const
inline

Definition at line 69 of file grid_helper.h.

69{ return m_enableGrid; }

References m_enableGrid.

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

◆ GetVisibleGrid()

VECTOR2I GRID_HELPER::GetVisibleGrid ( ) const

Definition at line 59 of file grid_helper.cpp.

60{
62
63 return VECTOR2I( KiROUND( size.x ), KiROUND( size.y ) );
64}
VECTOR2D GetVisibleGridSize() const
Return the visible grid size in x and y directions.

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

Referenced by PCB_GRID_HELPER::BestSnapAnchor().

◆ SetAuxAxes()

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

Definition at line 75 of file grid_helper.cpp.

76{
77 if( aEnable )
78 {
79 m_auxAxis = aOrigin;
80 m_viewAxis.SetPosition( wxPoint( aOrigin ) );
82 }
83 else
84 {
85 m_auxAxis = std::optional<VECTOR2I>();
87 }
88}
KIGFX::ORIGIN_VIEWITEM m_viewAxis
Definition: grid_helper.h:145
void SetPosition(const VECTOR2I &aPosition) override
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
Definition: view.cpp:1529

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 73 of file grid_helper.h.

73{ m_maskTypes = aMask; }

References m_maskTypes.

◆ SetMaskFlag()

void GRID_HELPER::SetMaskFlag ( int  aFlag)
inline

Definition at line 74 of file grid_helper.h.

74{ m_maskTypes |= aFlag; }

References m_maskTypes.

◆ SetSkipPoint()

void GRID_HELPER::SetSkipPoint ( const VECTOR2I aPoint)
inline

Definition at line 52 of file grid_helper.h.

53 {
54 m_skipPoint = aPoint;
55 }

References m_skipPoint.

◆ SetSnap()

◆ SetSnapLine()

void GRID_HELPER::SetSnapLine ( bool  aSnap)
inline

Definition at line 71 of file grid_helper.h.

71{ m_enableSnapLine = aSnap; }

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

std::optional<VECTOR2I> GRID_HELPER::m_auxAxis
protected

Definition at line 132 of file grid_helper.h.

Referenced by Align(), and SetAuxAxes().

◆ m_enableGrid

bool GRID_HELPER::m_enableGrid
protected

◆ m_enableSnap

◆ m_enableSnapLine

bool GRID_HELPER::m_enableSnapLine
protected

◆ m_maskTypes

int GRID_HELPER::m_maskTypes
protected

Definition at line 134 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: