Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
snap.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Per-desktop object that handles snapping queries.
4 *
5 * Authors:
6 * Lauris Kaplinski <lauris@kaplinski.com>
7 * Frank Felfe <innerspace@iname.com>
8 * Carl Hetherington <inkscape@carlh.net>
9 * Diederik van Lierop <mail@diedenrezi.nl>
10 *
11 * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
12 * Copyright (C) 2000-2002 Lauris Kaplinski
13 * Copyright (C) 2000-2012 Authors
14 *
15 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
16 */
17
18#ifndef SEEN_SNAP_H
19#define SEEN_SNAP_H
20
21#include <memory>
22#include <vector>
23
24#include "guide-snapper.h"
25#include "object-snapper.h"
26#include "alignment-snapper.h"
27#include "snap-preferences.h"
29
30
31// Guides
32enum SPGuideDragType { // used both here and in desktop-events.cpp
37};
38
39class SPDocument;
40class SPGuide;
41class SPPage;
42class SPNamedView;
43
44namespace Inkscape {
45 class PureTransform;
46}
47
48
80{
81public:
96
97 typedef std::list<const Inkscape::Snapper*> SnapperList;
98
109 bool someSnapperMightSnap(bool immediately = true) const;
110
114 bool gridSnapperMightSnap() const;
115
119 void setup(SPDesktop const *desktop,
120 bool snapindicator = true,
121 SPObject const *item_to_ignore = nullptr,
122 std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes = nullptr);
123
138 void setup(SPDesktop const *desktop,
139 bool snapindicator,
140 std::vector<SPObject const *> &objects_to_ignore,
141 std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes = nullptr);
142
144 bool snapindicator = true,
145 std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes = nullptr);
146
148 _objects_to_ignore.clear();
149 _desktop = nullptr;
150 _unselected_nodes = nullptr;}
151
152 // If we're dragging a rotation center, then setRotationCenterSource() stores the parent item
153 // of this rotation center; this reference is used to make sure that we do not snap a rotation
154 // center to itself
155 // NOTE: Must be called after calling setup(), not before!
157 const std::vector<SPItem*> &getRotationCenterSource() {return _rotation_center_source_items;}
158
159 // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a
160 // point if snapping has occurred (by overwriting p); otherwise p is untouched
161
187 Inkscape::SnapSourceType const source_type,
188 Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
189
208 Geom::OptRect const &bbox_to_snap = Geom::OptRect(),
209 bool to_path_only = false) const;
210
211 void preSnap(Inkscape::SnapCandidatePoint const &p, bool to_path_only = false);
212
232
233 // constrainedSnapReturnByRef() is preferred over constrainedSnap(), because it only returns a
234 // point, by overwriting p, if snapping has occurred; otherwise p is untouched
235
266 Inkscape::SnapSourceType const source_type,
267 Inkscape::Snapper::SnapConstraint const &constraint,
268 Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
269
288 Inkscape::Snapper::SnapConstraint const &constraint,
289 Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
290
292 std::vector<Inkscape::Snapper::SnapConstraint> const &constraints,
293 bool dont_snap = false,
294 Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
295
309 std::optional<Geom::Point> const &p_ref,
310 Geom::Point const &o,
311 unsigned const snaps) const;
312
326 void guideFreeSnap(Geom::Point &p, Geom::Point &origin_or_vector, bool origin, bool freeze_angle) const;
327
336 void guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) const;
337
343
356 SnapperList getSnappers() const;
357
369
370 SPDesktop const *getDesktop() const {return _desktop;}
371 SPNamedView const *getNamedView() const {return _named_view;}
372 SPDocument *getDocument() const;
373 SPGuide const *getGuideToIgnore() const;
374 SPPage const *getPageToIgnore() const;
375
376 bool getSnapIndicator() const {return _snapindicator;}
377
390 Inkscape::SnappedPoint findBestSnap(Inkscape::SnapCandidatePoint const &p, IntermSnapResults const &isr, bool constrained, bool allowOffScreen = false, bool to_paths_only = false) const;
391
399
417 void snapTransformed(std::vector<Inkscape::SnapCandidatePoint> const &points,
418 Geom::Point const &pointer,
419 Inkscape::PureTransform &transform);
420
421protected:
423
424private:
425 std::vector<SPObject const *> _objects_to_ignore;
426 std::vector<SPItem*> _rotation_center_source_items; // to avoid snapping a rotation center to itself
429 std::vector<Inkscape::SnapCandidatePoint> *_unselected_nodes;
430
439 std::vector<SPObject const *> const *it,
440 Geom::Rect const &bbox_to_snap,
441 bool const _clip_or_mask,
442 Geom::Affine const additional_affine);
444
445 std::unique_ptr<std::vector<Inkscape::SnapCandidateItem>> _obj_snapper_candidates;
446 std::unique_ptr<std::vector<Inkscape::SnapCandidateItem>> _align_snapper_candidates;
447
451};
452
453#endif // !SEEN_SNAP_H
454
455/*
456 Local Variables:
457 mode:c++
458 c-file-style:"stroustrup"
459 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
460 indent-tabs-mode:nil
461 fill-column:99
462 End:
463*/
464// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
Point origin
Definition aa.cpp:227
Authors: Parth Pant parthpant4@gmail.com
3x3 matrix representing an affine transformation.
Definition affine.h:70
Axis-aligned rectangle that can be empty.
Definition rect.h:203
Two-dimensional point that doubles as a vector.
Definition point.h:66
Axis aligned, non-empty rectangle.
Definition rect.h:92
Snapping things to on-canvas alignment guides.
Snapping equidistant objects.
Snapping things to objects.
Class to store data for points which are snap candidates, either as a source or as a target.
Storing of snapping preferences.
Class describing the result of an attempt to snap.
To do: update description of desktop.
Definition desktop.h:149
Typed SVG document implementation.
Definition document.h:101
SPObject is an abstract base class of all of the document nodes at the SVG document level.
Definition sp-object.h:160
Class to coordinate snapping operations.
Definition snap.h:80
~SnapManager()
Definition snap.cpp:67
SPDesktop const * _desktop
Definition snap.h:427
SnapperList getGridSnappers() const
Return a list of gridsnappers.
Definition snap.cpp:87
void guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) const
Wrapper method to make snapping of the guide origin a bit easier (i.e.
Definition snap.cpp:445
bool _findCandidates_already_called
Definition snap.h:443
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.
Definition snap.cpp:781
std::vector< SPItem * > _rotation_center_source_items
Definition snap.h:426
bool getSnapIndicator() const
Definition snap.h:376
std::unique_ptr< std::vector< Inkscape::SnapCandidateItem > > _obj_snapper_candidates
Definition snap.h:445
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.
Definition snap.cpp:233
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.
Definition snap.cpp:663
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.
Definition snap.cpp:818
std::unique_ptr< std::vector< Inkscape::SnapCandidateItem > > _align_snapper_candidates
Definition snap.h:446
Inkscape::AlignmentSnapper alignment
snapper to align with other objects
Definition snap.h:340
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.
Definition snap.cpp:408
Geom::Point multipleOfGridPitch(Geom::Point const &t, Geom::Point const &origin)
Snap to the closest multiple of a grid pitch.
Definition snap.cpp:178
SPGuide const * getGuideToIgnore() const
Definition snap.cpp:798
std::vector< SPObject const * > _objects_to_ignore
Items that should not be snapped to, for example the items that are currently being dragged....
Definition snap.h:425
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.
Definition snap.cpp:701
Inkscape::ObjectSnapper object
snapper to other objects
Definition snap.h:339
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...
Definition snap.cpp:505
bool gridSnapperMightSnap() const
Definition snap.cpp:120
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.
Definition snap.cpp:135
std::list< const Inkscape::Snapper * > SnapperList
Definition snap.h:97
const std::vector< SPItem * > & getRotationCenterSource()
Definition snap.h:157
void preSnap(Inkscape::SnapCandidatePoint const &p, bool to_path_only=false)
Definition snap.cpp:161
SPNamedView const * getNamedView() const
Definition snap.h:371
SPDocument * getDocument() const
Definition snap.cpp:724
void setRotationCenterSource(const std::vector< SPItem * > &items)
Definition snap.h:156
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.
Definition snap.cpp:242
bool _snapindicator
When true, an indicator will be drawn at the position that was being snapped to.
Definition snap.h:428
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.
Definition snap.cpp:372
Inkscape::DistributionSnapper distribution
Definition snap.h:341
Transformation
Definition snap.h:82
@ ROTATE
Definition snap.h:87
@ SCALE
Definition snap.h:84
@ STRETCH
Definition snap.h:85
@ TRANSLATE
Definition snap.h:83
SnapperList getSnappers() const
Return a list of snappers.
Definition snap.cpp:73
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.
Definition snap.cpp:465
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
Definition snap.cpp:306
void unSetup()
Definition snap.h:147
Inkscape::SnapPreferences & snapprefs
Definition snap.h:342
SPPage const * getPageToIgnore() const
Definition snap.cpp:807
SPNamedView const * _named_view
Definition snap.h:422
Inkscape::GuideSnapper guide
guide snapper
Definition snap.h:338
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.
Definition snap.cpp:143
bool someSnapperMightSnap(bool immediately=true) const
Return true if any snapping might occur, whether its to grids, guides or objects.
Definition snap.cpp:100
SPDesktop const * getDesktop() const
Definition snap.h:370
std::vector< Inkscape::SnapCandidatePoint > * _unselected_nodes
Nodes of the path that is currently being edited and which have not been selected and which will ther...
Definition snap.h:429
static char const *const parent
Definition dir-util.cpp:70
Authors: Parth Pant parthpant4@gmail.com
Helper class to stream background task notifications as a series of messages.
SnapSourceType
enumerations of snap source types and snap target types.
Definition snap-enums.h:18
GList * items
SPGuideDragType
Definition snap.h:32
@ SP_DRAG_TRANSLATE
Definition snap.h:33
@ SP_DRAG_MOVE_ORIGIN
Definition snap.h:35
@ SP_DRAG_NONE
Definition snap.h:36
@ SP_DRAG_ROTATE
Definition snap.h:34
SPDesktop * desktop