Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
SnapManager Class Reference

Class to coordinate snapping operations. More...

#include <snap.h>

Public Types

enum  Transformation {
  TRANSLATE , SCALE , STRETCH , SKEW ,
  ROTATE
}
 
typedef std::list< const Inkscape::Snapper * > SnapperList
 

Public Member Functions

 SnapManager (SPNamedView const *v, Inkscape::SnapPreferences &preferences)
 Construct a SnapManager for a SPNamedView.
 
 ~SnapManager ()
 
bool someSnapperMightSnap (bool immediately=true) const
 Return true if any snapping might occur, whether its to grids, guides or objects.
 
bool gridSnapperMightSnap () const
 
void setup (SPDesktop const *desktop, bool snapindicator=true, SPObject const *item_to_ignore=nullptr, std::vector< Inkscape::SnapCandidatePoint > *unselected_nodes=nullptr)
 Convenience shortcut when there is only one item to ignore.
 
void setup (SPDesktop const *desktop, bool snapindicator, std::vector< SPObject const * > &objects_to_ignore, std::vector< Inkscape::SnapCandidatePoint > *unselected_nodes=nullptr)
 Prepare the snap manager for the actual snapping, which includes building a list of snap targets to ignore and toggling the snap indicator.
 
void setupIgnoreSelection (SPDesktop const *desktop, bool snapindicator=true, std::vector< Inkscape::SnapCandidatePoint > *unselected_nodes=nullptr)
 Setup, taking the list of items to ignore from the desktop's selection.
 
void unSetup ()
 
void setRotationCenterSource (const std::vector< SPItem * > &items)
 
const std::vector< SPItem * > & getRotationCenterSource ()
 
void freeSnapReturnByRef (Geom::Point &p, Inkscape::SnapSourceType const source_type, Geom::OptRect const &bbox_to_snap=Geom::OptRect()) const
 Try to snap a point to grids, guides or objects.
 
Inkscape::SnappedPoint freeSnap (Inkscape::SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap=Geom::OptRect(), bool to_path_only=false) const
 Try to snap a point to grids, guides or objects.
 
void preSnap (Inkscape::SnapCandidatePoint const &p, bool to_path_only=false)
 
Geom::Point multipleOfGridPitch (Geom::Point const &t, Geom::Point const &origin)
 Snap to the closest multiple of a grid pitch.
 
void constrainedSnapReturnByRef (Geom::Point &p, Inkscape::SnapSourceType const source_type, Inkscape::Snapper::SnapConstraint const &constraint, Geom::OptRect const &bbox_to_snap=Geom::OptRect()) const
 Try to snap a point along a constraint line to grids, guides or objects.
 
Inkscape::SnappedPoint constrainedSnap (Inkscape::SnapCandidatePoint const &p, Inkscape::Snapper::SnapConstraint const &constraint, Geom::OptRect const &bbox_to_snap=Geom::OptRect()) const
 Try to snap a point along a constraint line to grids, guides or objects.
 
Inkscape::SnappedPoint multipleConstrainedSnaps (Inkscape::SnapCandidatePoint const &p, std::vector< Inkscape::Snapper::SnapConstraint > const &constraints, bool dont_snap=false, Geom::OptRect const &bbox_to_snap=Geom::OptRect()) const
 
Inkscape::SnappedPoint constrainedAngularSnap (Inkscape::SnapCandidatePoint const &p, std::optional< Geom::Point > const &p_ref, Geom::Point const &o, unsigned const snaps) const
 Try to snap a point to something at a specific angle.
 
void guideFreeSnap (Geom::Point &p, Geom::Point &origin_or_vector, bool origin, bool freeze_angle) const
 Wrapper method to make snapping of the guide origin a bit easier (i.e.
 
void guideConstrainedSnap (Geom::Point &p, SPGuide const &guideline) const
 Wrapper method to make snapping of the guide origin a bit easier (i.e.
 
SnapperList getSnappers () const
 Return a list of snappers.
 
SnapperList getGridSnappers () const
 Return a list of gridsnappers.
 
SPDesktop const * getDesktop () const
 
SPNamedView const * getNamedView () const
 
SPDocumentgetDocument () const
 
SPGuide const * getGuideToIgnore () const
 
SPPage const * getPageToIgnore () const
 
bool getSnapIndicator () const
 
Inkscape::SnappedPoint findBestSnap (Inkscape::SnapCandidatePoint const &p, IntermSnapResults const &isr, bool constrained, bool allowOffScreen=false, bool to_paths_only=false) const
 Given a set of possible snap targets, find the best target (which is not necessarily also the nearest target), and show the snap indicator if requested.
 
void displaySnapsource (Inkscape::SnapCandidatePoint const &p) const
 Mark the location of the snap source (not the snap target!) on the canvas by drawing a symbol.
 
void snapTransformed (std::vector< Inkscape::SnapCandidatePoint > const &points, Geom::Point const &pointer, Inkscape::PureTransform &transform)
 Method for snapping sets of points while they are being transformed.
 

Public Attributes

Inkscape::GuideSnapper guide
 guide snapper
 
Inkscape::ObjectSnapper object
 snapper to other objects
 
Inkscape::AlignmentSnapper alignment
 snapper to align with other objects
 
Inkscape::DistributionSnapper distribution
 
Inkscape::SnapPreferencessnapprefs
 

Protected Attributes

SPNamedView const * _named_view
 

Private Member Functions

void _findCandidates (SPObject *parent, std::vector< SPObject const * > const *it, Geom::Rect const &bbox_to_snap, bool const _clip_or_mask, Geom::Affine const additional_affine)
 Find all items within snapping range.
 

Private Attributes

std::vector< SPObject const * > _objects_to_ignore
 Items that should not be snapped to, for example the items that are currently being dragged. Set using the setup() method.
 
std::vector< SPItem * > _rotation_center_source_items
 
SPDesktop const * _desktop
 
bool _snapindicator
 When true, an indicator will be drawn at the position that was being snapped to.
 
std::vector< Inkscape::SnapCandidatePoint > * _unselected_nodes
 Nodes of the path that is currently being edited and which have not been selected and which will therefore be stationary. Only these nodes will be considered for snapping to. Of each unselected node both the position (Geom::Point) and the type (Inkscape::SnapTargetType) will be stored.
 
bool _findCandidates_already_called
 
std::unique_ptr< std::vector< Inkscape::SnapCandidateItem > > _obj_snapper_candidates
 
std::unique_ptr< std::vector< Inkscape::SnapCandidateItem > > _align_snapper_candidates
 

Friends

class Inkscape::ObjectSnapper
 
class Inkscape::AlignmentSnapper
 
class Inkscape::DistributionSnapper
 

Detailed Description

Class to coordinate snapping operations.

The SnapManager class handles most (if not all) of the interfacing of the snapping mechanisms with the other parts of the code base. It stores the references to the various types of snappers for grid, guides and objects, and it stores most of the snapping preferences. Besides that it provides methods to setup the snapping environment (e.g. keeps a list of the items to ignore when looking for snap target candidates, and toggling of the snap indicator), and it provides many different methods for snapping queries (free snapping vs. constrained snapping, returning the result by reference or through a return statement, etc.)

Each SPNamedView has one of these. It offers methods to snap points to whatever snappers are defined (e.g. grid, guides etc.). It also allows callers to snap points which have undergone some transformation (e.g. translation, scaling etc.)

How snapping is implemented in Inkscape
The snapping system consists of two key elements. The first one is the snap manager (this class), which keeps some data about objects in the document and answers queries of the type "given this point and type of transformation, what is the best place to snap to?".

The second is in event-context.cpp and implements the snapping timeout. Whenever a motion events happens over the canvas, it stores it for later use and initiates a timeout. This timeout is discarded whenever a new motion event occurs. When the timeout expires, a global flag in SnapManager, accessed via getSnapPostponedGlobally(), is set to true and the stored event is replayed, but this time with snapping enabled. This way you can write snapping code directly in your control point's dragged handler as if there was no timeout.

Definition at line 79 of file snap.h.

Member Typedef Documentation

◆ SnapperList

typedef std::list<const Inkscape::Snapper*> SnapManager::SnapperList

Definition at line 97 of file snap.h.

Member Enumeration Documentation

◆ Transformation

Enumerator
TRANSLATE 
SCALE 
STRETCH 
SKEW 
ROTATE 

Definition at line 82 of file snap.h.

Constructor & Destructor Documentation

◆ SnapManager()

SnapManager::SnapManager ( SPNamedView const *  v,
Inkscape::SnapPreferences preferences 
)

Construct a SnapManager for a SPNamedView.

Parameters
v'Owning' SPNamedView.

Definition at line 51 of file snap.cpp.

References _align_snapper_candidates, and _obj_snapper_candidates.

◆ ~SnapManager()

SnapManager::~SnapManager ( )

Definition at line 67 of file snap.cpp.

References _align_snapper_candidates, and _obj_snapper_candidates.

Member Function Documentation

◆ _findCandidates()

void SnapManager::_findCandidates ( SPObject parent,
std::vector< SPObject const * > const *  it,
Geom::Rect const &  bbox_to_snap,
bool const  _clip_or_mask,
Geom::Affine const  additional_affine 
)
private

◆ constrainedAngularSnap()

Inkscape::SnappedPoint SnapManager::constrainedAngularSnap ( Inkscape::SnapCandidatePoint const &  p,
std::optional< Geom::Point > const &  p_ref,
Geom::Point const &  o,
unsigned const  snaps 
) const

Try to snap a point to something at a specific angle.

When drawing a straight line or modifying a gradient, it will snap to specific angle increments if CTRL is being pressed. This method will enforce this angular constraint (even if there is nothing to snap to)

Parameters
pSource point to be snapped.
p_refOptional original point, relative to which the angle should be calculated. If empty then the angle will be calculated relative to the y-axis.
snapsNumber of angular increments per PI radians; E.g. if snaps = 2 then we will snap every PI/2 = 90 degrees.

Definition at line 372 of file snap.cpp.

References Geom::angle_between(), freeSnap(), Inkscape::SnapCandidatePoint::getPoint(), Inkscape::SnappedPoint::getSnapped(), multipleConstrainedSnaps(), Inkscape::SnappedPoint::setTarget(), and Inkscape::SNAPTARGET_CONSTRAINED_ANGLE.

Referenced by Inkscape::UI::Tools::spdc_endpoint_snap_rotation().

◆ constrainedSnap()

Inkscape::SnappedPoint SnapManager::constrainedSnap ( Inkscape::SnapCandidatePoint const &  p,
Inkscape::Snapper::SnapConstraint const &  constraint,
Geom::OptRect const &  bbox_to_snap = Geom::OptRect() 
) const

Try to snap a point along a constraint line to grids, guides or objects.

Try to snap a point to grids, guides or objects, in only one degree-of-freedom, i.e. snap in a specific direction on the two dimensional canvas to the nearest snap target. constrainedSnap is equal in snapping behavior to constrainedSnapReturnByRef(). Please read the comments of the latter for more details.

PS: SnapManager::setup() must have been called before calling this method, although only once for each set of points PS: If there's nothing to snap to or if snapping has been disabled, then this method will still apply the constraint (but without snapping)

Parameters
pSource point to be snapped.
constraintThe direction or line along which snapping must occur.
bbox_to_snapBounding box hulling the set of points, all from the same selection and having the same transformation.

Definition at line 242 of file snap.cpp.

References _desktop, _objects_to_ignore, _snapindicator, _unselected_nodes, findBestSnap(), freeSnap(), Inkscape::Preferences::get(), Inkscape::Preferences::getBool(), Inkscape::SnapCandidatePoint::getPoint(), SPDesktop::getSnapIndicator(), getSnappers(), Inkscape::SnapCandidatePoint::getSourceNum(), Inkscape::SnapCandidatePoint::getSourceType(), Geom::infinity(), Inkscape::SnapCandidatePoint::isSingleHandle(), Inkscape::Snapper::SnapConstraint::projection(), result, Inkscape::Display::SnapIndicator::set_new_snaptarget(), Inkscape::SNAPTARGET_CONSTRAINT, and someSnapperMightSnap().

Referenced by constrainedSnapReturnByRef(), Inkscape::UI::Handle::dragged(), Inkscape::PureTranslateConstrained::snap(), Inkscape::PureScale::snap(), Inkscape::PureScaleConstrained::snap(), Inkscape::PureStretchConstrained::snap(), Inkscape::PureSkewConstrained::snap(), and Inkscape::PureRotateConstrained::snap().

◆ constrainedSnapReturnByRef()

void SnapManager::constrainedSnapReturnByRef ( Geom::Point p,
Inkscape::SnapSourceType const  source_type,
Inkscape::Snapper::SnapConstraint const &  constraint,
Geom::OptRect const &  bbox_to_snap = Geom::OptRect() 
) const

Try to snap a point along a constraint line to grids, guides or objects.

Try to snap a point to grids, guides or objects, in only one degree-of-freedom, i.e. snap in a specific direction on the two dimensional canvas to the nearest snap target.

constrainedSnapReturnByRef() is equal in snapping behavior to constrainedSnap(), but the former returns the snapped point through the referenced parameter p. This parameter p initially contains the position of the snap source and will be overwritten by the target position if snapping has occurred. This makes snapping transparent to the calling code. If this is not desired because either the calling code must know whether snapping has occurred, or because the original position should not be touched, then constrainedSnap() should be called instead. If there's nothing to snap to or if snapping has been disabled, then this method will still apply the constraint (but without snapping)

PS: 1) SnapManager::setup() must have been called before calling this method, although only once for each set of points 2) Only to be used when a single source point is to be snapped; it assumes that source_num = 0, which is inefficient when snapping sets our source points

Parameters
pCurrent position of the snap source; will be overwritten by the position of the snap target if snapping has occurred.
source_typeDetailed description of the source type, will be used by the snap indicator.
constraintThe direction or line along which snapping must occur.
bbox_to_snapBounding box hulling the set of points, all from the same selection and having the same transformation.

Definition at line 233 of file snap.cpp.

References constrainedSnap(), and Inkscape::SnappedPoint::getPoint().

Referenced by Inkscape::UI::Tools::PenTool::_setToNearestHorizVert().

◆ displaySnapsource()

void SnapManager::displaySnapsource ( Inkscape::SnapCandidatePoint const &  p) const

Mark the location of the snap source (not the snap target!) on the canvas by drawing a symbol.

Parameters
point_typeCategory of points to which the source point belongs: node, guide or bounding box.
pThe transformed position of the source point, paired with an identifier of the type of the snap source.
point_typeCategory of points to which the source point belongs: node, guide or bounding box
pThe transformed position of the source point, paired with an identifier of the type of the snap source.

Definition at line 781 of file snap.cpp.

References _desktop, Inkscape::Preferences::get(), Inkscape::Preferences::getBool(), Inkscape::SnapPreferences::getSnapEnabledGlobally(), SPDesktop::getSnapIndicator(), Inkscape::SnapCandidatePoint::getSourceType(), Inkscape::SnapPreferences::isTargetSnappable(), Inkscape::Display::SnapIndicator::remove_snapsource(), Inkscape::Display::SnapIndicator::set_new_snapsource(), snapprefs, Inkscape::SNAPSOURCE_BBOX_CATEGORY, Inkscape::SNAPSOURCE_DATUMS_CATEGORY, Inkscape::SNAPSOURCE_NODE_CATEGORY, Inkscape::SNAPSOURCE_OTHERS_CATEGORY, Inkscape::SNAPTARGET_BBOX_CATEGORY, and Inkscape::SNAPTARGET_NODE_CATEGORY.

Referenced by Inkscape::SelTrans::getNextClosestPoint(), Inkscape::UI::TransformHandle::getNextClosestPoint(), and snapTransformed().

◆ findBestSnap()

Inkscape::SnappedPoint SnapManager::findBestSnap ( Inkscape::SnapCandidatePoint const &  p,
IntermSnapResults const &  isr,
bool  constrained,
bool  allowOffScreen = false,
bool  to_paths_only = false 
) const

Given a set of possible snap targets, find the best target (which is not necessarily also the nearest target), and show the snap indicator if requested.

Parameters
pSource point to be snapped.
isrA structure holding all snap targets that have been found so far.
constrainedTrue if the snap is constrained, e.g. for stretching or for purely horizontal translation.
allowOffScreenIf true, then snapping to points which are off the screen is allowed (needed for example when pasting to the grid).
to_path_onlyOnly snap to points on a path, such as path intersections with itself or with grids/guides. This is used for example when adding nodes to a path. We will not snap for example to grid intersections
Returns
An instance of the SnappedPoint class, which holds data on the snap source, snap target, and various metrics.

Definition at line 505 of file snap.cpp.

References _desktop, _snapindicator, Geom::Parallelogram::contains(), IntermSnapResults::curves, SPDesktop::dt2doc(), SPDesktop::get_display_area(), getClosestCurve(), getClosestIntersectionCL(), getClosestIntersectionCS(), getClosestIntersectionSL(), getClosestSL(), getClosestSP(), Inkscape::SnappedPoint::getOnPath(), Inkscape::SnapCandidatePoint::getPoint(), SPDesktop::getSnapIndicator(), Inkscape::SnappedPoint::getSnapped(), Inkscape::SnapCandidatePoint::getSourceType(), IntermSnapResults::grid_lines, IntermSnapResults::guide_lines, Inkscape::SnappedPoint::isOtherSnapBetter(), Inkscape::SnapPreferences::isTargetSnappable(), IntermSnapResults::points, Inkscape::Display::SnapIndicator::remove_snaptarget(), Inkscape::Display::SnapIndicator::set_new_snaptarget(), Inkscape::SnappedPoint::setSource(), Inkscape::SnappedPoint::setTarget(), snapprefs, Inkscape::SNAPTARGET_GRID_GUIDE_INTERSECTION, Inkscape::SNAPTARGET_GRID_INTERSECTION, Inkscape::SNAPTARGET_GRID_LINE, Inkscape::SNAPTARGET_GUIDE_INTERSECTION, Inkscape::SNAPTARGET_PATH, Inkscape::SNAPTARGET_PATH_GUIDE_INTERSECTION, and Inkscape::SNAPTARGET_PATH_INTERSECTION.

Referenced by constrainedSnap(), freeSnap(), guideConstrainedSnap(), guideFreeSnap(), multipleConstrainedSnaps(), and multipleOfGridPitch().

◆ freeSnap()

Inkscape::SnappedPoint SnapManager::freeSnap ( Inkscape::SnapCandidatePoint const &  p,
Geom::OptRect const &  bbox_to_snap = Geom::OptRect(),
bool  to_path_only = false 
) const

Try to snap a point to grids, guides or objects.

Try to snap a point to grids, guides or objects, in two degrees-of-freedom, i.e. snap in any direction on the two dimensional canvas to the nearest snap target. freeSnap() is equal in snapping behavior to freeSnapReturnByRef(). Please read the comments of the latter for more details

PS: SnapManager::setup() must have been called before calling this method, although only once for each set of points

Parameters
pSource point to be snapped.
bbox_to_snapBounding box hulling the set of points, all from the same selection and having the same transformation.
to_path_onlyOnly snap to points on a path, such as path intersections with itself or with grids/guides. This is used for example when adding nodes to a path. We will not snap for example to grid intersections
Returns
An instance of the SnappedPoint class, which holds data on the snap source, snap target, and various metrics.

Definition at line 143 of file snap.cpp.

References _objects_to_ignore, _unselected_nodes, findBestSnap(), getSnappers(), Geom::infinity(), Inkscape::SNAPTARGET_UNDEFINED, and someSnapperMightSnap().

Referenced by constrainedAngularSnap(), constrainedSnap(), freeSnapReturnByRef(), Inkscape::UI::Tools::PagesTool::getSnappedResizePoint(), Inkscape::UI::Tools::MeasureTool::knotEndMovedHandler(), Inkscape::UI::Tools::MeasureTool::knotStartMovedHandler(), multipleConstrainedSnaps(), preSnap(), Inkscape::PureTranslate::snap(), Inkscape::PureScale::snap(), and Inkscape::UI::Tools::spdc_endpoint_snap_free().

◆ freeSnapReturnByRef()

void SnapManager::freeSnapReturnByRef ( Geom::Point p,
Inkscape::SnapSourceType const  source_type,
Geom::OptRect const &  bbox_to_snap = Geom::OptRect() 
) const

Try to snap a point to grids, guides or objects.

Try to snap a point to grids, guides or objects, in two degrees-of-freedom, i.e. snap in any direction on the two dimensional canvas to the nearest snap target. freeSnapReturnByRef() is equal in snapping behavior to freeSnap(), but the former returns the snapped point through the referenced parameter p. This parameter p initially contains the position of the snap source and will we overwritten by the target position if snapping has occurred. This makes snapping transparent to the calling code. If this is not desired because either the calling code must know whether snapping has occurred, or because the original position should not be touched, then freeSnap() should be called instead.

PS: 1) SnapManager::setup() must have been called before calling this method, although only once for each set of points 2) Only to be used when a single source point is to be snapped; it assumes that source_num = 0, which is inefficient when snapping sets our source points

Parameters
pCurrent position of the snap source; will be overwritten by the position of the snap target if snapping has occurred.
source_typeDetailed description of the source type, will be used by the snap indicator.
bbox_to_snapBounding box hulling the set of points, all from the same selection and having the same transformation.

Definition at line 135 of file snap.cpp.

References freeSnap(), Inkscape::SnappedPoint::getPointIfSnapped(), and Inkscape::SNAPTARGET_PATH.

Referenced by Inkscape::UI::Tools::ConnectorTool::_handleButtonPress(), Inkscape::UI::Tools::ConnectorTool::_handleButtonRelease(), Inkscape::UI::Tools::ConnectorTool::_handleMotionNotify(), Inkscape::SelTrans::centerRequest(), Inkscape::UI::Tools::SpiralTool::drag(), Inkscape::UI::Tools::StarTool::drag(), Inkscape::UI::Handle::dragged(), and Inkscape::UI::Tools::MeshTool::root_handler().

◆ getDesktop()

SPDesktop const * SnapManager::getDesktop ( ) const
inline

◆ getDocument()

SPDocument * SnapManager::getDocument ( ) const

Definition at line 724 of file snap.cpp.

References _named_view, and SPObject::document.

◆ getGridSnappers()

SnapManager::SnapperList SnapManager::getGridSnappers ( ) const

Return a list of gridsnappers.

Each grid has its own instance of the snapper class. This way snapping can be enabled per grid individually. A list will be returned containing the pointers to these instances, but only for grids that are being displayed and for which snapping is enabled.

Returns
List of gridsnappers that we use.

Definition at line 87 of file snap.cpp.

References _desktop, _named_view, SPDesktop::getNamedView(), SPNamedView::getShowGrids(), SPNamedView::grids, Inkscape::SnapPreferences::isTargetSnappable(), snapprefs, and Inkscape::SNAPTARGET_GRID.

Referenced by getSnappers(), and gridSnapperMightSnap().

◆ getGuideToIgnore()

SPGuide const * SnapManager::getGuideToIgnore ( ) const

Definition at line 798 of file snap.cpp.

References _objects_to_ignore, guide, and item.

◆ getNamedView()

◆ getPageToIgnore()

SPPage const * SnapManager::getPageToIgnore ( ) const

Definition at line 807 of file snap.cpp.

References _objects_to_ignore, item, and page.

◆ getRotationCenterSource()

const std::vector< SPItem * > & SnapManager::getRotationCenterSource ( )
inline

Definition at line 157 of file snap.h.

References _rotation_center_source_items.

◆ getSnapIndicator()

bool SnapManager::getSnapIndicator ( ) const
inline

Definition at line 376 of file snap.h.

References _snapindicator.

◆ getSnappers()

SnapManager::SnapperList SnapManager::getSnappers ( ) const

Return a list of snappers.

Inkscape snaps to objects, grids, and guides. For each of these snap targets a separate class is used, which has been derived from the base Snapper class. The getSnappers() method returns a list of pointers to instances of this class. This list contains exactly one instance of the guide snapper and of the object snapper class, but any number of grid snappers (because each grid has its own snapper instance)

Returns
List of snappers that we use.

Definition at line 73 of file snap.cpp.

References alignment, distribution, getGridSnappers(), gs, and guide.

Referenced by constrainedSnap(), freeSnap(), guideConstrainedSnap(), guideFreeSnap(), multipleConstrainedSnaps(), and someSnapperMightSnap().

◆ gridSnapperMightSnap()

bool SnapManager::gridSnapperMightSnap ( ) const
Returns
true if one of the grids might be snapped to.

Definition at line 120 of file snap.cpp.

References getGridSnappers(), Inkscape::SnapPreferences::getSnapEnabledGlobally(), Inkscape::SnapPreferences::getSnapPostponedGlobally(), and snapprefs.

◆ guideConstrainedSnap()

void SnapManager::guideConstrainedSnap ( Geom::Point p,
SPGuide const &  guideline 
) const

Wrapper method to make snapping of the guide origin a bit easier (i.e.

simplifies the calling code).

PS: SnapManager::setup() must have been called before calling this method,

Parameters
pCurrent position of the point on the guide that is to be snapped; will be overwritten by the position of the snap target if snapping has occurred.
guidelineThe guide that is currently being dragged

Definition at line 445 of file snap.cpp.

References findBestSnap(), SPGuide::getNormal(), SPGuide::getPoint(), Inkscape::SnappedPoint::getPointIfSnapped(), Inkscape::SnapPreferences::getSnapEnabledGlobally(), getSnappers(), Inkscape::SnapPreferences::getSnapPostponedGlobally(), Inkscape::SnapPreferences::isTargetSnappable(), Geom::rot90(), snapprefs, Inkscape::SNAPSOURCE_GUIDE_ORIGIN, Inkscape::SNAPTARGET_GUIDE, and Inkscape::SNAPTARGET_UNDEFINED.

◆ guideFreeSnap()

void SnapManager::guideFreeSnap ( Geom::Point p,
Geom::Point origin_or_vector,
bool  origin,
bool  freeze_angle 
) const

Wrapper method to make snapping of the guide origin a bit easier (i.e.

simplifies the calling code).

PS: SnapManager::setup() must have been called before calling this method,

Parameters
pCurrent position of the point on the guide that is to be snapped; will be overwritten by the position of the snap target if snapping has occurred.
origin_or_vectorData used for tangential and perpendicular snapping. When rotating a guide the origin of the rotation is specified here, whereas when dragging a guide its vector is specified here
originIf true then origin_or_vector contains an origin, other it contains a vector
freeze_angleIf true (in which case origin is false), then the vector specified in origin_or_vector will not be touched, i.e. the guide will in all circumstances keep its angle. Otherwise the vector in origin_or_vector can be updated, meaning that the guide might take on the angle of a curve that has been snapped too tangentially or perpendicularly

Definition at line 408 of file snap.cpp.

References Inkscape::SnapCandidatePoint::addOrigin(), Inkscape::SnapCandidatePoint::addVector(), Geom::are_near(), findBestSnap(), Inkscape::SnappedPoint::getPointIfSnapped(), Inkscape::SnapPreferences::getSnapEnabledGlobally(), Inkscape::SnappedPoint::getSnapped(), getSnappers(), Inkscape::SnapPreferences::getSnapPostponedGlobally(), Inkscape::SnappedPoint::getTangent(), Inkscape::SnapPreferences::isTargetSnappable(), origin, Geom::rot90(), snapprefs, Inkscape::SNAPSOURCE_GUIDE, Inkscape::SNAPSOURCE_GUIDE_ORIGIN, and Inkscape::SNAPTARGET_GUIDE.

◆ multipleConstrainedSnaps()

◆ multipleOfGridPitch()

Geom::Point SnapManager::multipleOfGridPitch ( Geom::Point const &  t,
Geom::Point const &  origin 
)

Snap to the closest multiple of a grid pitch.

When pasting, we would like to snap to the grid. Problem is that we don't know which nodes were aligned to the grid at the time of copying, so we don't know which nodes to snap. If we'd snap an unaligned node to the grid, previously aligned nodes would become unaligned. That's undesirable. Instead we will make sure that the offset between the source and its pasted copy is a multiple of the grid pitch. If the source was aligned, then the copy will therefore also be aligned.

PS: Whether we really find a multiple also depends on the snapping range! Most users will have "always snap" enabled though, in which case a multiple will always be found. PS2: When multiple grids are present then the result will become ambiguous. There is no way to control to which grid this method will snap.

Parameters
tVector that represents the offset of the pasted copy with respect to the original.
Returns
Offset vector after snapping to the closest multiple of a grid pitch.

Definition at line 178 of file snap.cpp.

References _desktop, _named_view, _snapindicator, findBestSnap(), Inkscape::Snapper::freeSnap(), SPDesktop::getNamedView(), Inkscape::SnappedPoint::getPoint(), SPNamedView::getShowGrids(), Inkscape::SnappedPoint::getSnapDistance(), Inkscape::SnapPreferences::getSnapEnabledGlobally(), SPDesktop::getSnapIndicator(), Inkscape::SnappedPoint::getSnapped(), Inkscape::SnapPreferences::getSnapPostponedGlobally(), SPNamedView::grids, Geom::infinity(), origin, Inkscape::Display::SnapIndicator::set_new_snaptarget(), Inkscape::SnappedPoint::setPoint(), snapprefs, Inkscape::SNAPSOURCE_GRID_PITCH, and Inkscape::Snapper::ThisSnapperMightSnap().

Referenced by Inkscape::SelTrans::moveTo().

◆ preSnap()

◆ setRotationCenterSource()

void SnapManager::setRotationCenterSource ( const std::vector< SPItem * > &  items)
inline

Definition at line 156 of file snap.h.

References _rotation_center_source_items, and items.

Referenced by Inkscape::SelTrans::centerRequest().

◆ setup() [1/2]

void SnapManager::setup ( SPDesktop const *  desktop,
bool  snapindicator,
std::vector< SPObject const * > &  objects_to_ignore,
std::vector< Inkscape::SnapCandidatePoint > *  unselected_nodes = nullptr 
)

Prepare the snap manager for the actual snapping, which includes building a list of snap targets to ignore and toggling the snap indicator.

There are two overloaded setup() methods, of which the other one only allows for a single item to be ignored whereas this one will take a list of items to ignore

Parameters
desktopReference to the desktop to which this snap manager is attached.
snapindicatorIf true then a snap indicator will be displayed automatically (when enabled in the preferences).
objects_to_ignoreThese items will not be snapped to, e.g. the items that are currently being dragged. This avoids "self-snapping" this includes guides and other non-items.
unselected_nodesStationary nodes of the path that is currently being edited in the node tool and that can be snapped too. Nodes not in this list will not be snapped to, to avoid "self-snapping". Of each unselected node both the position (Geom::Point) and the type (Inkscape::SnapTargetType) will be stored.

Definition at line 683 of file snap.cpp.

References _desktop, _findCandidates_already_called, _objects_to_ignore, _rotation_center_source_items, _snapindicator, _unselected_nodes, and desktop.

◆ setup() [2/2]

void SnapManager::setup ( SPDesktop const *  desktop,
bool  snapindicator = true,
SPObject const *  item_to_ignore = nullptr,
std::vector< Inkscape::SnapCandidatePoint > *  unselected_nodes = nullptr 
)

Convenience shortcut when there is only one item to ignore.

Definition at line 663 of file snap.cpp.

References _desktop, _findCandidates_already_called, _objects_to_ignore, _rotation_center_source_items, _snapindicator, _unselected_nodes, and desktop.

Referenced by Inkscape::UI::Tools::ConnectorTool::_handleButtonPress(), Inkscape::UI::Tools::PenTool::_handleButtonPress(), Inkscape::UI::Tools::PencilTool::_handleButtonPress(), Inkscape::UI::Tools::ConnectorTool::_handleButtonRelease(), Inkscape::UI::Tools::PenTool::_handleMotionNotify(), Inkscape::UI::Tools::PencilTool::_handleMotionNotify(), Inkscape::UI::Tools::ConnectorTool::_handleMotionNotify(), Inkscape::UI::Tools::PenTool::_setToNearestHorizVert(), Inkscape::UI::PathManipulator::_updateDragPoint(), Inkscape::SelTrans::centerRequest(), Inkscape::UI::Tools::SpiralTool::drag(), Inkscape::UI::Tools::StarTool::drag(), Inkscape::UI::Node::dragged(), Inkscape::SelTrans::getNextClosestPoint(), Inkscape::UI::TransformHandle::getNextClosestPoint(), Inkscape::UI::Tools::PagesTool::getSnappedResizePoint(), gr_knot_moved_midpoint_handler(), Inkscape::UI::Tools::MeasureTool::knotEndMovedHandler(), Inkscape::UI::Tools::MeasureTool::knotStartMovedHandler(), Inkscape::SelTrans::moveTo(), Inkscape::UI::Tools::PagesTool::moveTo(), Inkscape::UI::Tools::ArcTool::root_handler(), Inkscape::UI::Tools::Box3dTool::root_handler(), Inkscape::UI::Tools::MeasureTool::root_handler(), Inkscape::UI::Tools::MeshTool::root_handler(), Inkscape::UI::Tools::NodeTool::root_handler(), Inkscape::UI::Tools::RectTool::root_handler(), Inkscape::UI::Tools::SpiralTool::root_handler(), Inkscape::UI::Tools::StarTool::root_handler(), Inkscape::UI::Tools::TextTool::root_handler(), Inkscape::SelTrans::rotateRequest(), Inkscape::UI::Widget::ruler_snap_new_guide(), Inkscape::SelTrans::scaleRequest(), Inkscape::SelTrans::skewRequest(), KnotHolderEntity::snap_knot_position(), KnotHolderEntity::snap_knot_position_constrained(), Inkscape::snap_rectangular_box(), sp_dt_guide_event(), sp_import_document(), Inkscape::UI::Tools::spdc_endpoint_snap_free(), Inkscape::UI::Tools::spdc_endpoint_snap_rotation(), Inkscape::SelTrans::stretchRequest(), and Box3D::vp_knot_moved_handler().

◆ setupIgnoreSelection()

void SnapManager::setupIgnoreSelection ( SPDesktop const *  desktop,
bool  snapindicator = true,
std::vector< Inkscape::SnapCandidatePoint > *  unselected_nodes = nullptr 
)

Setup, taking the list of items to ignore from the desktop's selection.

Definition at line 701 of file snap.cpp.

References _desktop, _findCandidates_already_called, _objects_to_ignore, _rotation_center_source_items, _snapindicator, _unselected_nodes, desktop, SPDesktop::getSelection(), items, and Inkscape::ObjectSet::items().

Referenced by Inkscape::UI::Handle::dragged().

◆ snapTransformed()

void SnapManager::snapTransformed ( std::vector< Inkscape::SnapCandidatePoint > const &  points,
Geom::Point const &  pointer,
Inkscape::PureTransform transform 
)

Method for snapping sets of points while they are being transformed.

Method for snapping sets of points while they are being transformed, when using for example the selector tool.

This is what is being done in this method: transform each point, find out whether a free snap or constrained snap is more appropriate, do the snapping, calculate some metrics to quantify the snap "distance", and see if it's better than the previous snap. Finally, the best ("nearest") snap from all these points is returned. If no snap has occurred and we're asked for a constrained snap then the constraint will be applied nevertheless

Parameters
pointsCollection of points to snap (snap sources), at their untransformed position, all points undergoing the same transformation. Paired with an identifier of the type of the snap source.
pointerLocation of the mouse pointer at the time dragging started (i.e. when the selection was still untransformed).
transformDescribes the type of transformation, it's parameters, and any additional constraints

Definition at line 465 of file snap.cpp.

References _desktop, _snapindicator, Inkscape::PureTransform::best_snapped_point, displaySnapsource(), Inkscape::SnappedPoint::getPoint(), SPDesktop::getSnapIndicator(), Inkscape::SnappedPoint::getSnapped(), Inkscape::Display::SnapIndicator::remove_snaptarget(), Inkscape::Display::SnapIndicator::set_new_snaptarget(), and Inkscape::PureTransform::snap().

Referenced by Inkscape::SelTrans::moveTo(), Inkscape::UI::Tools::PagesTool::moveTo(), Inkscape::SelTrans::rotateRequest(), Inkscape::SelTrans::scaleRequest(), Inkscape::SelTrans::skewRequest(), and Inkscape::SelTrans::stretchRequest().

◆ someSnapperMightSnap()

bool SnapManager::someSnapperMightSnap ( bool  immediately = true) const

Return true if any snapping might occur, whether its to grids, guides or objects.

Each snapper instance handles its own snapping target, e.g. grids, guides or objects. This method iterates through all these snapper instances and returns true if any of the snappers might possible snap, considering only the relevant snapping preferences.

Returns
true if one of the snappers will try to snap to something.

Definition at line 100 of file snap.cpp.

References Inkscape::SnapPreferences::getSnapEnabledGlobally(), getSnappers(), Inkscape::SnapPreferences::getSnapPostponedGlobally(), and snapprefs.

Referenced by constrainedSnap(), Inkscape::UI::Handle::dragged(), freeSnap(), Inkscape::SelTrans::grab(), and multipleConstrainedSnaps().

◆ unSetup()

Friends And Related Symbol Documentation

◆ Inkscape::AlignmentSnapper

friend class Inkscape::AlignmentSnapper
friend

Definition at line 449 of file snap.h.

◆ Inkscape::DistributionSnapper

friend class Inkscape::DistributionSnapper
friend

Definition at line 450 of file snap.h.

◆ Inkscape::ObjectSnapper

friend class Inkscape::ObjectSnapper
friend

Definition at line 448 of file snap.h.

Member Data Documentation

◆ _align_snapper_candidates

std::unique_ptr<std::vector<Inkscape::SnapCandidateItem> > SnapManager::_align_snapper_candidates
private

Definition at line 446 of file snap.h.

Referenced by _findCandidates(), SnapManager(), and ~SnapManager().

◆ _desktop

◆ _findCandidates_already_called

bool SnapManager::_findCandidates_already_called
private

Definition at line 443 of file snap.h.

Referenced by _findCandidates(), setup(), setup(), and setupIgnoreSelection().

◆ _named_view

SPNamedView const* SnapManager::_named_view
protected

Definition at line 422 of file snap.h.

Referenced by getDocument(), getGridSnappers(), getNamedView(), and multipleOfGridPitch().

◆ _obj_snapper_candidates

std::unique_ptr<std::vector<Inkscape::SnapCandidateItem> > SnapManager::_obj_snapper_candidates
private

Definition at line 445 of file snap.h.

Referenced by _findCandidates(), SnapManager(), and ~SnapManager().

◆ _objects_to_ignore

std::vector<SPObject const *> SnapManager::_objects_to_ignore
private

Items that should not be snapped to, for example the items that are currently being dragged. Set using the setup() method.

Definition at line 425 of file snap.h.

Referenced by constrainedSnap(), freeSnap(), getGuideToIgnore(), getPageToIgnore(), multipleConstrainedSnaps(), setup(), setup(), setupIgnoreSelection(), and unSetup().

◆ _rotation_center_source_items

std::vector<SPItem*> SnapManager::_rotation_center_source_items
private

◆ _snapindicator

bool SnapManager::_snapindicator
private

When true, an indicator will be drawn at the position that was being snapped to.

Definition at line 428 of file snap.h.

Referenced by constrainedSnap(), findBestSnap(), getSnapIndicator(), multipleOfGridPitch(), preSnap(), setup(), setup(), setupIgnoreSelection(), and snapTransformed().

◆ _unselected_nodes

std::vector<Inkscape::SnapCandidatePoint>* SnapManager::_unselected_nodes
private

Nodes of the path that is currently being edited and which have not been selected and which will therefore be stationary. Only these nodes will be considered for snapping to. Of each unselected node both the position (Geom::Point) and the type (Inkscape::SnapTargetType) will be stored.

Definition at line 429 of file snap.h.

Referenced by constrainedSnap(), freeSnap(), multipleConstrainedSnaps(), setup(), setup(), setupIgnoreSelection(), and unSetup().

◆ alignment

Inkscape::AlignmentSnapper SnapManager::alignment

snapper to align with other objects

Definition at line 340 of file snap.h.

Referenced by getSnappers().

◆ distribution

Inkscape::DistributionSnapper SnapManager::distribution

Definition at line 341 of file snap.h.

Referenced by getSnappers().

◆ guide

Inkscape::GuideSnapper SnapManager::guide

guide snapper

Definition at line 338 of file snap.h.

Referenced by getGuideToIgnore(), and getSnappers().

◆ object

Inkscape::ObjectSnapper SnapManager::object

snapper to other objects

Definition at line 339 of file snap.h.

◆ snapprefs


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