KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 , CONSTRUCTED = 64 , ALL = CORNER | OUTLINE | SNAPPABLE | ORIGIN | VERTICAL | HORIZONTAL | CONSTRUCTED
}
 

Public Member Functions

 GRID_HELPER ()
 
 GRID_HELPER (TOOL_MANAGER *aToolMgr, int aConstructionLayer)
 
virtual ~GRID_HELPER ()
 
VECTOR2I GetGrid () const
 
VECTOR2D GetVisibleGrid () const
 
VECTOR2I GetOrigin () const
 
void SetGridSize (const VECTOR2D &aGrid)
 
void SetVisibleGridSize (const VECTOR2D &aGrid)
 
void SetOrigin (const VECTOR2I &aOrigin)
 
void SetGridSnapping (bool aEnable)
 
void SetAuxAxes (bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
 
virtual VECTOR2I Align (const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
 
virtual VECTOR2I AlignGrid (const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
 
virtual VECTOR2I Align (const VECTOR2I &aPoint) const
 
virtual VECTOR2I Align (const VECTOR2I &aPoint, const VECTOR2D &aGrid) const
 
VECTOR2I AlignGrid (const VECTOR2I &aPoint) const
 
VECTOR2I AlignGrid (const VECTOR2I &aPoint, const VECTOR2D &aGrid) const
 
virtual GRID_HELPER_GRIDS GetSelectionGrid (const SELECTION &aSelection) const
 Gets the coarsest grid that applies to a selecion of items.
 
virtual GRID_HELPER_GRIDS GetItemGrid (const EDA_ITEM *aItem) const
 Get the coarsest grid that applies to an item.
 
virtual VECTOR2D GetGridSize (GRID_HELPER_GRIDS aGrid) const
 Return the size of the specified grid.
 
void SetSkipPoint (const VECTOR2I &aPoint)
 
void ClearSkipPoint ()
 Clear the skip point by setting it to an unreachable position, thereby preventing matching.
 
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)
 
std::optional< VECTOR2IGetSnappedPoint () const
 

Protected Member Functions

void addAnchor (const VECTOR2I &aPos, int aFlags, EDA_ITEM *aItem, int aPointTypes=POINT_TYPE::PT_NONE)
 
void addAnchor (const VECTOR2I &aPos, int aFlags, std::vector< EDA_ITEM * > aItems, int aPointTypes)
 
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.
 
VECTOR2I computeNearest (const VECTOR2I &aPoint, const VECTOR2I &aGrid) const
 
void showConstructionGeometry (bool aShow)
 
SNAP_MANAGERgetSnapManager ()
 
void updateSnapPoint (const TYPED_POINT2I &aPoint)
 
KIGFX::ANCHOR_DEBUGenableAndGetAnchorDebug ()
 Enable the anchor debug if permitted and return it.
 

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
 
std::optional< ANCHORm_snapItem
 
VECTOR2I m_skipPoint
 
KIGFX::SNAP_INDICATOR m_viewSnapPoint
 
KIGFX::ORIGIN_VIEWITEM m_viewAxis
 
VECTOR2D m_manualGrid
 
VECTOR2D m_manualVisibleGrid
 
VECTOR2I m_manualOrigin
 
bool m_manualGridSnapping
 

Private Attributes

KIGFX::CONSTRUCTION_GEOM m_constructionGeomPreview
 Show construction geometry (if any) on the canvas.
 
SNAP_MANAGER m_snapManager
 Manage the construction geometry, snap lines, reference points, etc.
 
std::unique_ptr< KIGFX::ANCHOR_DEBUGm_anchorDebug
 #VIEW_ITEM for visualising anchor points, if enabled.
 

Friends

void TEST_CLEAR_ANCHORS (GRID_HELPER &helper)
 

Detailed Description

Definition at line 54 of file grid_helper.h.

Member Enumeration Documentation

◆ ANCHOR_FLAGS

Enumerator
CORNER 
OUTLINE 
SNAPPABLE 
ORIGIN 
VERTICAL 
HORIZONTAL 
CONSTRUCTED 
ALL 

Definition at line 132 of file grid_helper.h.

Constructor & Destructor Documentation

◆ GRID_HELPER() [1/2]

◆ GRID_HELPER() [2/2]

GRID_HELPER::GRID_HELPER ( TOOL_MANAGER aToolMgr,
int  aConstructionLayer 
)

Definition at line 56 of file grid_helper.cpp.

References m_toolMgr.

◆ ~GRID_HELPER()

GRID_HELPER::~GRID_HELPER ( )
virtual

Member Function Documentation

◆ addAnchor() [1/2]

void GRID_HELPER::addAnchor ( const VECTOR2I aPos,
int  aFlags,
EDA_ITEM aItem,
int  aPointTypes = POINT_TYPE::PT_NONE 
)
inlineprotected

◆ addAnchor() [2/2]

void GRID_HELPER::addAnchor ( const VECTOR2I aPos,
int  aFlags,
std::vector< EDA_ITEM * >  aItems,
int  aPointTypes 
)
inlineprotected

Definition at line 191 of file grid_helper.h.

References m_anchors, and m_maskTypes.

◆ Align() [1/3]

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

Reimplemented in PCB_GRID_HELPER.

Definition at line 238 of file grid_helper.cpp.

References Align(), and GetGrid().

◆ Align() [2/3]

VECTOR2I GRID_HELPER::Align ( const VECTOR2I aPoint,
const VECTOR2D aGrid 
) const
virtual

Reimplemented in PCB_GRID_HELPER.

Definition at line 244 of file grid_helper.cpp.

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

◆ Align() [3/3]

virtual VECTOR2I GRID_HELPER::Align ( const VECTOR2I aPoint,
GRID_HELPER_GRIDS  aGrid 
) const
inlinevirtual

◆ AlignGrid() [1/3]

VECTOR2I GRID_HELPER::AlignGrid ( const VECTOR2I aPoint) const

Definition at line 219 of file grid_helper.cpp.

References computeNearest(), and GetGrid().

◆ AlignGrid() [2/3]

VECTOR2I GRID_HELPER::AlignGrid ( const VECTOR2I aPoint,
const VECTOR2D aGrid 
) const

Definition at line 225 of file grid_helper.cpp.

References computeNearest().

◆ AlignGrid() [3/3]

virtual VECTOR2I GRID_HELPER::AlignGrid ( const VECTOR2I aPoint,
GRID_HELPER_GRIDS  aGrid 
) const
inlinevirtual

◆ canUseGrid()

bool GRID_HELPER::canUseGrid ( ) const
protected

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 264 of file grid_helper.cpp.

References KIGFX::VIEW::GetGAL(), KIGFX::GAL::GetGridSnapping(), TOOL_MANAGER::GetView(), m_enableGrid, m_manualGridSnapping, 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 128 of file grid_helper.h.

References m_maskTypes.

Referenced by BOOST_AUTO_TEST_CASE().

◆ ClearSkipPoint()

void GRID_HELPER::ClearSkipPoint ( )
inline

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

Definition at line 113 of file grid_helper.h.

References m_skipPoint.

Referenced by BOOST_AUTO_TEST_CASE().

◆ computeNearest()

VECTOR2I GRID_HELPER::computeNearest ( const VECTOR2I aPoint,
const VECTOR2I aGrid 
) const
protected

Definition at line 231 of file grid_helper.cpp.

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

Referenced by AlignGrid().

◆ enableAndGetAnchorDebug()

KIGFX::ANCHOR_DEBUG * GRID_HELPER::enableAndGetAnchorDebug ( )
protected

Enable the anchor debug if permitted and return it.

Returns nullptr if not permitted by the advancd config

Definition at line 112 of file grid_helper.cpp.

References KIGFX::VIEW::Add(), ADVANCED_CFG::GetCfg(), TOOL_MANAGER::GetView(), m_anchorDebug, ADVANCED_CFG::m_EnableSnapAnchorsDebug, m_toolMgr, and KIGFX::VIEW::SetVisible().

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

◆ GetGrid()

◆ GetGridSize()

VECTOR2D GRID_HELPER::GetGridSize ( GRID_HELPER_GRIDS  aGrid) const
virtual

Return the size of the specified grid.

Reimplemented in EE_GRID_HELPER, and PCB_GRID_HELPER.

Definition at line 195 of file grid_helper.cpp.

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

Referenced by Align(), AlignGrid(), BOOST_AUTO_TEST_CASE(), and GetSelectionGrid().

◆ GetItemGrid()

virtual GRID_HELPER_GRIDS GRID_HELPER::GetItemGrid ( const EDA_ITEM aItem) const
inlinevirtual

Get the coarsest grid that applies to an item.

Reimplemented in EE_GRID_HELPER, and PCB_GRID_HELPER.

Definition at line 98 of file grid_helper.h.

References GRID_CURRENT.

Referenced by GetSelectionGrid().

◆ GetOrigin()

VECTOR2I GRID_HELPER::GetOrigin ( ) const

◆ GetSelectionGrid()

GRID_HELPER_GRIDS GRID_HELPER::GetSelectionGrid ( const SELECTION aSelection) const
virtual

Gets the coarsest grid that applies to a selecion of items.

Reimplemented in EE_GRID_HELPER.

Definition at line 178 of file grid_helper.cpp.

References SELECTION::Front(), GetGridSize(), GetItemGrid(), and grid.

◆ GetSnap()

bool GRID_HELPER::GetSnap ( ) const
inline

◆ getSnapManager()

◆ GetSnappedPoint()

std::optional< VECTOR2I > GRID_HELPER::GetSnappedPoint ( ) const

Definition at line 271 of file grid_helper.cpp.

References m_snapItem.

Referenced by BOOST_AUTO_TEST_CASE(), and PCB_PICKER_TOOL::SelectPointInteractively().

◆ GetUseGrid()

bool GRID_HELPER::GetUseGrid ( ) const
inline

Definition at line 122 of file grid_helper.h.

References m_enableGrid.

Referenced by BOOST_AUTO_TEST_CASE(), and PNS::TOOL_BASE::updateStartItem().

◆ GetVisibleGrid()

◆ SetAuxAxes()

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

◆ SetGridSize()

void GRID_HELPER::SetGridSize ( const VECTOR2D aGrid)
inline

◆ SetGridSnapping()

void GRID_HELPER::SetGridSnapping ( bool  aEnable)
inline

◆ SetMask()

void GRID_HELPER::SetMask ( int  aMask)
inline

Definition at line 126 of file grid_helper.h.

References m_maskTypes.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SetMaskFlag()

void GRID_HELPER::SetMaskFlag ( int  aFlag)
inline

Definition at line 127 of file grid_helper.h.

References m_maskTypes.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SetOrigin()

void GRID_HELPER::SetOrigin ( const VECTOR2I aOrigin)
inline

◆ SetSkipPoint()

void GRID_HELPER::SetSkipPoint ( const VECTOR2I aPoint)
inline

Definition at line 105 of file grid_helper.h.

References m_skipPoint.

Referenced by BOOST_AUTO_TEST_CASE().

◆ SetSnap()

◆ SetSnapLine()

void GRID_HELPER::SetSnapLine ( bool  aSnap)
inline

Definition at line 124 of file grid_helper.h.

References m_enableSnapLine.

◆ SetUseGrid()

void GRID_HELPER::SetUseGrid ( bool  aSnapToGrid)
inline

◆ SetVisibleGridSize()

void GRID_HELPER::SetVisibleGridSize ( const VECTOR2D aGrid)
inline

Definition at line 68 of file grid_helper.h.

References m_manualVisibleGrid.

Referenced by BOOST_AUTO_TEST_CASE().

◆ showConstructionGeometry()

void GRID_HELPER::showConstructionGeometry ( bool  aShow)
protected

◆ updateSnapPoint()

Friends And Related Function Documentation

◆ TEST_CLEAR_ANCHORS

void TEST_CLEAR_ANCHORS ( GRID_HELPER helper)
friend

Definition at line 23 of file test_grid_helper.cpp.

Member Data Documentation

◆ m_anchorDebug

std::unique_ptr<KIGFX::ANCHOR_DEBUG> GRID_HELPER::m_anchorDebug
private

#VIEW_ITEM for visualising anchor points, if enabled.

Definition at line 256 of file grid_helper.h.

Referenced by enableAndGetAnchorDebug(), and ~GRID_HELPER().

◆ m_anchors

◆ m_auxAxis

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

Definition at line 228 of file grid_helper.h.

Referenced by Align(), and SetAuxAxes().

◆ m_constructionGeomPreview

KIGFX::CONSTRUCTION_GEOM GRID_HELPER::m_constructionGeomPreview
private

Show construction geometry (if any) on the canvas.

Definition at line 250 of file grid_helper.h.

Referenced by EE_GRID_HELPER::GetGrid(), showConstructionGeometry(), and ~GRID_HELPER().

◆ m_enableGrid

bool GRID_HELPER::m_enableGrid
protected

◆ m_enableSnap

◆ m_enableSnapLine

bool GRID_HELPER::m_enableSnapLine
protected

◆ m_manualGrid

VECTOR2D GRID_HELPER::m_manualGrid
protected

Definition at line 243 of file grid_helper.h.

Referenced by GetGrid(), GetGridSize(), GRID_HELPER(), and SetGridSize().

◆ m_manualGridSnapping

bool GRID_HELPER::m_manualGridSnapping
protected

Definition at line 246 of file grid_helper.h.

Referenced by canUseGrid(), GRID_HELPER(), and SetGridSnapping().

◆ m_manualOrigin

VECTOR2I GRID_HELPER::m_manualOrigin
protected

Definition at line 245 of file grid_helper.h.

Referenced by GetOrigin(), GRID_HELPER(), and SetOrigin().

◆ m_manualVisibleGrid

VECTOR2D GRID_HELPER::m_manualVisibleGrid
protected

Definition at line 244 of file grid_helper.h.

Referenced by GetVisibleGrid(), GRID_HELPER(), and SetVisibleGridSize().

◆ m_maskTypes

int GRID_HELPER::m_maskTypes
protected

Definition at line 230 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_snapManager

SNAP_MANAGER GRID_HELPER::m_snapManager
private

Manage the construction geometry, snap lines, reference points, etc.

Definition at line 253 of file grid_helper.h.

Referenced by getSnapManager().

◆ m_toolMgr

◆ m_viewAxis

◆ m_viewSnapPoint


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