65 wxUnusedVar( aConstructionLayer );
71 [view,
this](
bool aAnythingShown )
75 if( currentlyVisible && aAnythingShown )
84 m_toolMgr->GetToolHolder()->RefreshCanvas();
136 m_snapManager.GetSnapLineManager().SetDirections( aDirections );
142 m_snapManager.GetSnapLineManager().SetSnapLineOrigin( aOrigin );
159 double aSnapRange )
const
167 const VECTOR2I& origin = *snapOrigin;
169 const std::vector<VECTOR2I>& directions = snapLineManager.
GetDirections();
176 std::optional<VECTOR2I> bestPoint;
177 double bestPerp = std::numeric_limits<double>::max();
178 double bestDistance = std::numeric_limits<double>::max();
180 for(
size_t ii = 0; ii < directions.size(); ++ii )
182 const VECTOR2I& dir = directions[ii];
186 if( dirLength == 0.0 )
189 VECTOR2D dirUnit = dirVector / dirLength;
191 double distanceAlong =
delta.Dot( dirUnit );
192 VECTOR2D projection = originVec + dirUnit * distanceAlong;
196 double snapThreshold = aSnapRange;
198 if( activeDirection && *activeDirection ==
static_cast<int>( ii ) )
199 snapThreshold *= 1.5;
201 if( perpDistance > snapThreshold )
208 if( dir.
x == 0 && dir.
y != 0 )
210 candidate.
x = origin.
x;
211 candidate.
y = aNearestGrid.
y;
213 else if( dir.
y == 0 && dir.
x != 0 )
215 candidate.
x = aNearestGrid.
x;
216 candidate.
y = origin.
y;
220 double stepDistance = std::sqrt( aGrid.
x * aGrid.
x + aGrid.
y * aGrid.
y );
222 if( stepDistance == 0.0 )
225 double steps = std::round( distanceAlong / stepDistance );
226 candidate = originVec + dirUnit * ( steps * stepDistance );
235 VECTOR2D candidateDelta( candidateInt.
x - aPoint.
x, candidateInt.
y - aPoint.
y );
238 if( perpDistance < bestPerp
239 || (
std::abs( perpDistance - bestPerp ) < 1e-9 && candidateDistance < bestDistance ) )
241 bestPerp = perpDistance;
242 bestDistance = candidateDistance;
243 bestPoint = candidateInt;
349 KiROUND( (
double) ( aPoint.
y - aOffset.
y ) / aGrid.
y ) * aGrid.
y + aOffset.
y );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
A base class for most all the KiCad significant classes used in schematics and boards.
KIGFX::CONSTRUCTION_GEOM m_constructionGeomPreview
Show construction geometry (if any) on the canvas.
std::optional< VECTOR2I > m_auxAxis
VECTOR2I computeNearest(const VECTOR2I &aPoint, const VECTOR2I &aGrid, const VECTOR2I &aOffset) const
std::optional< VECTOR2I > SnapToConstructionLines(const VECTOR2I &aPoint, const VECTOR2I &aNearestGrid, const VECTOR2D &aGrid, double aSnapRange) const
void SetSnapLineDirections(const std::vector< VECTOR2I > &aDirections)
virtual GRID_HELPER_GRIDS GetItemGrid(const EDA_ITEM *aItem) const
Get the coarsest grid that applies to an item.
void showConstructionGeometry(bool aShow)
SNAP_MANAGER m_snapManager
Manage the construction geometry, snap lines, reference points, etc.
VECTOR2D m_manualVisibleGrid
void SetSnapLineOrigin(const VECTOR2I &aOrigin)
bool m_manualGridSnapping
virtual GRID_HELPER_GRIDS GetSelectionGrid(const SELECTION &aSelection) const
Gets the coarsest grid that applies to a selecion of items.
std::optional< VECTOR2I > GetSnappedPoint() const
void SetAuxAxes(bool aEnable, const VECTOR2I &aOrigin=VECTOR2I(0, 0))
VECTOR2D GetVisibleGrid() const
std::unique_ptr< KIGFX::ANCHOR_DEBUG > m_anchorDebug
#VIEW_ITEM for visualising anchor points, if enabled.
virtual VECTOR2D GetGridSize(GRID_HELPER_GRIDS aGrid) const
Return the size of the specified grid.
VECTOR2I GetOrigin() const
bool canUseGrid() const
Check whether it is possible to use the grid – this depends both on local grid helper settings and gl...
std::optional< ANCHOR > m_snapItem
KIGFX::ANCHOR_DEBUG * enableAndGetAnchorDebug()
Enable the anchor debug if permitted and return it.
void SetSnapLineEnd(const std::optional< VECTOR2I > &aEnd)
KIGFX::SNAP_INDICATOR m_viewSnapPoint
virtual VECTOR2I Align(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
void updateSnapPoint(const TYPED_POINT2I &aPoint)
KIGFX::ORIGIN_VIEWITEM m_viewAxis
virtual VECTOR2I AlignGrid(const VECTOR2I &aPoint, GRID_HELPER_GRIDS aGrid) const
View item to draw debug items for anchors.
const VECTOR2D & GetGridOrigin() const
VECTOR2D GetVisibleGridSize() const
Return the visible grid size in x and y directions.
const VECTOR2D & GetGridSize() const
Return the grid size.
bool GetGridSnapping() const
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
GAL * GetGAL() const
Return the GAL this view is using to draw graphical primitives.
bool IsVisible(const VIEW_ITEM *aItem) const
Return information if the item is visible (or not).
void SetVisible(VIEW_ITEM *aItem, bool aIsVisible=true)
Set the item visibility.
const std::vector< VECTOR2I > & GetDirections() const
std::optional< int > GetActiveDirection() const
const OPT_VECTOR2I & GetSnapLineOrigin() const
T EuclideanNorm() const
Compute the Euclidean norm of the vector, which is defined as sqrt(x ** 2 + y ** 2).
bool m_EnableSnapAnchorsDebug
Enable snap anchors debug visualization.
@ GEOMETRY
Position or shape has changed.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
std::optional< VECTOR2I > OPT_VECTOR2I
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D