KiCad PCB EDA Suite
Loading...
Searching...
No Matches
CONSTRUCTION_MANAGER Class Reference

A class that mananges "construction" objects and geometry. More...

#include <construction_manager.h>

Classes

struct  CONSTRUCTION_ITEM
 

Public Types

enum class  SOURCE { FROM_ITEMS , FROM_SNAP_LINE }
 Items to be used for the construction of "virtual" anchors, for example, when snapping to a point involving an extension of an existing line or arc. More...
 
using CONSTRUCTION_ITEM_BATCH = std::vector< CONSTRUCTION_ITEM >
 
using GFX_UPDATE_CALLBACK = std::function< void(bool)>
 

Public Member Functions

 CONSTRUCTION_MANAGER (KIGFX::CONSTRUCTION_GEOM &aHelper)
 
void AddConstructionItems (CONSTRUCTION_ITEM_BATCH aBatch, bool aIsPersistent)
 Add a batch of construction items to the helper.
 
bool InvolvesAllGivenRealItems (const std::vector< EDA_ITEM * > &aItems) const
 Check if all 'real' (non-null = constructed) the items in the batch are in the list of items currently 'involved' in an active construction.
 
void SetReferenceOnlyPoints (std::vector< VECTOR2I > aPoints)
 Set the reference-only points - these are points that are not snapped to, but can still be used for connection to the snap line.
 
const std::vector< VECTOR2I > & GetReferenceOnlyPoints () const
 
void SetSnapLineOrigin (const VECTOR2I &aOrigin)
 The snap point is a special point that is located at the last point the cursor snapped to.
 
void SetSnapLineEnd (const OPT_VECTOR2I &aSnapPoint)
 Set the end point of the snap line.
 
void ClearSnapLine ()
 Clear the snap line origin and end points.
 
std::optional< VECTOR2IGetSnapLineOrigin () const
 
void SetSnappedAnchor (const VECTOR2I &aAnchorPos)
 Inform the construction manager that an anchor snap is wanted.
 
std::vector< CONSTRUCTION_ITEM_BATCHGetConstructionItems () const
 
OPT_VECTOR2I GetNearestSnapLinePoint (const VECTOR2I &aCursor, const VECTOR2I &aNearestGrid, std::optional< int > aDistToNearest, int snapRange) const
 If the snap line is active, return the best snap point that is closest to the cursor.
 
void SetUpdateCallback (GFX_UPDATE_CALLBACK aCallback)
 Set the callback to call when the construction geometry changes and a view may need updating.
 

Private Member Functions

void updateView ()
 

Private Attributes

KIGFX::CONSTRUCTION_GEOMm_constructionGeomPreview
 
std::optional< CONSTRUCTION_ITEM_BATCHm_persistentConstructionBatch
 
std::deque< CONSTRUCTION_ITEM_BATCHm_temporaryConstructionBatches
 
std::set< EDA_ITEM * > m_involvedItems
 
std::vector< VECTOR2Im_referenceOnlyPoints
 
OPT_VECTOR2I m_snapLineOrigin
 
OPT_VECTOR2I m_snapLineEnd
 
GFX_UPDATE_CALLBACK m_updateCallback
 

Detailed Description

A class that mananges "construction" objects and geometry.

Probably only used by GRID_HELPERs, but it's neater to keep it separate, as there's quite a bit of state to manage.

Definition at line 40 of file construction_manager.h.

Member Typedef Documentation

◆ CONSTRUCTION_ITEM_BATCH

◆ GFX_UPDATE_CALLBACK

using CONSTRUCTION_MANAGER::GFX_UPDATE_CALLBACK = std::function<void( bool )>

Definition at line 147 of file construction_manager.h.

Member Enumeration Documentation

◆ SOURCE

enum class CONSTRUCTION_MANAGER::SOURCE
strong

Items to be used for the construction of "virtual" anchors, for example, when snapping to a point involving an extension of an existing line or arc.

One item can have multiple construction items (e.g. an arc can have a circle and centre point).

Enumerator
FROM_ITEMS 
FROM_SNAP_LINE 

Definition at line 52 of file construction_manager.h.

Constructor & Destructor Documentation

◆ CONSTRUCTION_MANAGER()

CONSTRUCTION_MANAGER::CONSTRUCTION_MANAGER ( KIGFX::CONSTRUCTION_GEOM aHelper)

Definition at line 27 of file construction_manager.cpp.

Member Function Documentation

◆ AddConstructionItems()

void CONSTRUCTION_MANAGER::AddConstructionItems ( CONSTRUCTION_ITEM_BATCH  aBatch,
bool  aIsPersistent 
)

Add a batch of construction items to the helper.

Parameters
aBatchThe batch of construction items to add.
aIsPersistentIf true, the batch is considered "persistent" and will always be shown (and it will replace any previous persistent batch). If false, the batch is temporary and may be pushed out by other batches.

Definition at line 43 of file construction_manager.cpp.

References KIGFX::CONSTRUCTION_GEOM::AddDrawable(), KIGFX::CONSTRUCTION_GEOM::ClearDrawables(), m_constructionGeomPreview, m_involvedItems, m_persistentConstructionBatch, m_temporaryConstructionBatches, and updateView().

Referenced by PCB_GRID_HELPER::AddConstructionItems().

◆ ClearSnapLine()

void CONSTRUCTION_MANAGER::ClearSnapLine ( )

◆ GetConstructionItems()

◆ GetNearestSnapLinePoint()

OPT_VECTOR2I CONSTRUCTION_MANAGER::GetNearestSnapLinePoint ( const VECTOR2I aCursor,
const VECTOR2I aNearestGrid,
std::optional< int >  aDistToNearest,
int  snapRange 
) const

If the snap line is active, return the best snap point that is closest to the cursor.

If there's no active snap line, return std::nullopt.

If there's a snap very near, use that otherwise, use the grid point. With this point, snap to it on an H/V axis.

Then, if there's a grid point near, snap to it on an H/V axis

Parameters
aCursorThe cursor position
aNearestGridThe nearest grid point to the cursor
aDistToNearestThe distance to the nearest non-grid snap point, if any
snapRangeThe snap range

Allows de-snapping from the line if you are closer to another snap point Or if you have moved far enough away from the line

Definition at line 253 of file construction_manager.cpp.

References DEGREES_T, m_snapLineOrigin, pointHasEscapedSnapLineX(), pointHasEscapedSnapLineY(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_GRID_HELPER::BestSnapAnchor().

◆ GetReferenceOnlyPoints()

const std::vector< VECTOR2I > & CONSTRUCTION_MANAGER::GetReferenceOnlyPoints ( ) const
inline

Definition at line 95 of file construction_manager.h.

References m_referenceOnlyPoints.

Referenced by PCB_GRID_HELPER::BestSnapAnchor().

◆ GetSnapLineOrigin()

std::optional< VECTOR2I > CONSTRUCTION_MANAGER::GetSnapLineOrigin ( ) const
inline

Definition at line 117 of file construction_manager.h.

References m_snapLineOrigin.

Referenced by EE_GRID_HELPER::BestSnapAnchor().

◆ InvolvesAllGivenRealItems()

bool CONSTRUCTION_MANAGER::InvolvesAllGivenRealItems ( const std::vector< EDA_ITEM * > &  aItems) const

Check if all 'real' (non-null = constructed) the items in the batch are in the list of items currently 'involved' in an active construction.

Definition at line 117 of file construction_manager.cpp.

References m_involvedItems.

Referenced by PCB_GRID_HELPER::BestSnapAnchor().

◆ SetReferenceOnlyPoints()

void CONSTRUCTION_MANAGER::SetReferenceOnlyPoints ( std::vector< VECTOR2I aPoints)
inline

Set the reference-only points - these are points that are not snapped to, but can still be used for connection to the snap line.

Definition at line 90 of file construction_manager.h.

References m_referenceOnlyPoints.

Referenced by PCB_GRID_HELPER::AddConstructionItems().

◆ SetSnapLineEnd()

void CONSTRUCTION_MANAGER::SetSnapLineEnd ( const OPT_VECTOR2I aSnapPoint)

Set the end point of the snap line.

Passing std::nullopt will unset the end point, but keep the origin.

Definition at line 138 of file construction_manager.cpp.

References KIGFX::CONSTRUCTION_GEOM::ClearSnapLine(), m_constructionGeomPreview, m_snapLineEnd, m_snapLineOrigin, KIGFX::CONSTRUCTION_GEOM::SetSnapLine(), and updateView().

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

◆ SetSnapLineOrigin()

void CONSTRUCTION_MANAGER::SetSnapLineOrigin ( const VECTOR2I aOrigin)

The snap point is a special point that is located at the last point the cursor snapped to.

If it is set, the construction manager may add extra construction geometry to the helper extending from the snap point origin to the cursor, which is the 'snap line'.

Definition at line 131 of file construction_manager.cpp.

References ClearSnapLine(), and m_snapLineOrigin.

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

◆ SetSnappedAnchor()

void CONSTRUCTION_MANAGER::SetSnappedAnchor ( const VECTOR2I aAnchorPos)

Inform the construction manager that an anchor snap is wanted.

This will also update the snap line if appropriate.

Definition at line 161 of file construction_manager.cpp.

References m_snapLineOrigin, SetSnapLineEnd(), SetSnapLineOrigin(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by PCB_GRID_HELPER::BestSnapAnchor().

◆ SetUpdateCallback()

void CONSTRUCTION_MANAGER::SetUpdateCallback ( GFX_UPDATE_CALLBACK  aCallback)
inline

Set the callback to call when the construction geometry changes and a view may need updating.

Definition at line 151 of file construction_manager.h.

References m_updateCallback.

Referenced by GRID_HELPER::GRID_HELPER().

◆ updateView()

void CONSTRUCTION_MANAGER::updateView ( )
private

Member Data Documentation

◆ m_constructionGeomPreview

KIGFX::CONSTRUCTION_GEOM& CONSTRUCTION_MANAGER::m_constructionGeomPreview
private

Definition at line 158 of file construction_manager.h.

Referenced by AddConstructionItems(), ClearSnapLine(), and SetSnapLineEnd().

◆ m_involvedItems

std::set<EDA_ITEM*> CONSTRUCTION_MANAGER::m_involvedItems
private

Definition at line 169 of file construction_manager.h.

Referenced by AddConstructionItems(), and InvolvesAllGivenRealItems().

◆ m_persistentConstructionBatch

std::optional<CONSTRUCTION_ITEM_BATCH> CONSTRUCTION_MANAGER::m_persistentConstructionBatch
private

Definition at line 163 of file construction_manager.h.

Referenced by AddConstructionItems(), GetConstructionItems(), and updateView().

◆ m_referenceOnlyPoints

std::vector<VECTOR2I> CONSTRUCTION_MANAGER::m_referenceOnlyPoints
private

Definition at line 171 of file construction_manager.h.

Referenced by GetReferenceOnlyPoints(), and SetReferenceOnlyPoints().

◆ m_snapLineEnd

OPT_VECTOR2I CONSTRUCTION_MANAGER::m_snapLineEnd
private

Definition at line 176 of file construction_manager.h.

Referenced by ClearSnapLine(), SetSnapLineEnd(), and updateView().

◆ m_snapLineOrigin

◆ m_temporaryConstructionBatches

std::deque<CONSTRUCTION_ITEM_BATCH> CONSTRUCTION_MANAGER::m_temporaryConstructionBatches
private

Definition at line 166 of file construction_manager.h.

Referenced by AddConstructionItems(), GetConstructionItems(), and updateView().

◆ m_updateCallback

GFX_UPDATE_CALLBACK CONSTRUCTION_MANAGER::m_updateCallback
private

Definition at line 178 of file construction_manager.h.

Referenced by SetUpdateCallback(), and updateView().


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