624f7adac7cc43774d6365d189831806344c577e
1 #ifndef SEEN_SNAP_H
2 #define SEEN_SNAP_H
4 /**
5 * \file snap.h
6 * \brief SnapManager class.
7 *
8 * Authors:
9 * Lauris Kaplinski <lauris@kaplinski.com>
10 * Frank Felfe <innerspace@iname.com>
11 * Carl Hetherington <inkscape@carlh.net>
12 * Diederik van Lierop <mail@diedenrezi.nl>
13 *
14 * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
15 * Copyright (C) 2000-2002 Lauris Kaplinski
16 * Copyright (C) 2000-2008 Authors
17 *
18 * Released under GNU GPL, read the file 'COPYING' for more information
19 */
21 #include <vector>
23 #include <libnr/nr-coord.h>
24 #include <libnr/nr-dim2.h>
25 #include <libnr/nr-forward.h>
26 #include <libnr/nr-scale.h>
28 #include "guide-snapper.h"
29 #include "object-snapper.h"
30 #include "snap-preferences.h"
32 class SPNamedView;
34 /// Class to coordinate snapping operations
36 /**
37 * Each SPNamedView has one of these. It offers methods to snap points to whatever
38 * snappers are defined (e.g. grid, guides etc.). It also allows callers to snap
39 * points which have undergone some transformation (e.g. translation, scaling etc.)
40 */
42 class SnapManager
43 {
44 public:
45 SnapManager(SPNamedView const *v);
47 typedef std::list<const Inkscape::Snapper*> SnapperList;
49 bool someSnapperMightSnap() const;
51 void setup(SPDesktop const *desktop, bool snapindicator = true, SPItem const *item_to_ignore = NULL, std::vector<Geom::Point> *unselected_nodes = NULL);
52 void setup(SPDesktop const *desktop, bool snapindicator, std::vector<SPItem const *> &items_to_ignore, std::vector<Geom::Point> *unselected_nodes = NULL);
54 // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a
55 // point if snapping has occured (by overwriting p); otherwise p is untouched
56 void freeSnapReturnByRef(Inkscape::SnapPreferences::PointType point_type,
57 Geom::Point &p,
58 bool first_point = true,
59 boost::optional<Geom::Rect> const &bbox_to_snap = boost::optional<Geom::Rect>()) const;
61 Inkscape::SnappedPoint freeSnap(Inkscape::SnapPreferences::PointType point_type,
62 Geom::Point const &p,
63 bool first_point = true,
64 boost::optional<Geom::Rect> const &bbox_to_snap = boost::optional<Geom::Rect>() ) const;
66 Geom::Point multipleOfGridPitch(Geom::Point const &t) const;
68 // constrainedSnapReturnByRef() is preferred over constrainedSnap(), because it only returns a
69 // point, by overwriting p, if snapping has occured; otherwise p is untouched
70 void constrainedSnapReturnByRef(Inkscape::SnapPreferences::PointType point_type,
71 Geom::Point &p,
72 Inkscape::Snapper::ConstraintLine const &constraint,
73 bool first_point = true,
74 boost::optional<Geom::Rect> const &bbox_to_snap = boost::optional<Geom::Rect>()) const;
76 Inkscape::SnappedPoint constrainedSnap(Inkscape::SnapPreferences::PointType point_type,
77 Geom::Point const &p,
78 Inkscape::Snapper::ConstraintLine const &constraint,
79 bool first_point = true,
80 boost::optional<Geom::Rect> const &bbox_to_snap = boost::optional<Geom::Rect>()) const;
82 void guideSnap(Geom::Point &p, Geom::Point const &guide_normal) const;
84 Inkscape::SnappedPoint freeSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
85 std::vector<Geom::Point> const &p,
86 Geom::Point const &tr) const;
88 Inkscape::SnappedPoint constrainedSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
89 std::vector<Geom::Point> const &p,
90 Inkscape::Snapper::ConstraintLine const &constraint,
91 Geom::Point const &tr) const;
93 Inkscape::SnappedPoint freeSnapScale(Inkscape::SnapPreferences::PointType point_type,
94 std::vector<Geom::Point> const &p,
95 Geom::Scale const &s,
96 Geom::Point const &o) const;
98 Inkscape::SnappedPoint constrainedSnapScale(Inkscape::SnapPreferences::PointType point_type,
99 std::vector<Geom::Point> const &p,
100 Geom::Scale const &s,
101 Geom::Point const &o) const;
103 Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::SnapPreferences::PointType point_type,
104 std::vector<Geom::Point> const &p,
105 Geom::Coord const &s,
106 Geom::Point const &o,
107 Geom::Dim2 d,
108 bool uniform) const;
110 Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::SnapPreferences::PointType point_type,
111 std::vector<Geom::Point> const &p,
112 Inkscape::Snapper::ConstraintLine const &constraint,
113 Geom::Point const &s, // s[0] = skew factor, s[1] = scale factor
114 Geom::Point const &o,
115 Geom::Dim2 d) const;
117 Inkscape::GuideSnapper guide; ///< guide snapper
118 Inkscape::ObjectSnapper object; ///< snapper to other objects
119 Inkscape::SnapPreferences snapprefs;
121 SnapperList getSnappers() const;
122 SnapperList getGridSnappers() const;
124 SPDesktop const *getDesktop() const {return _desktop;}
125 SPNamedView const *getNamedView() const {return _named_view;}
126 SPDocument *getDocument() const;
128 protected:
129 SPNamedView const *_named_view;
131 private:
132 enum Transformation {
133 TRANSLATION,
134 SCALE,
135 STRETCH,
136 SKEW
137 };
139 std::vector<SPItem const *> *_items_to_ignore;
140 SPItem const *_item_to_ignore;
141 SPDesktop const *_desktop;
142 bool _snapindicator;
143 std::vector<Geom::Point> *_unselected_nodes;
145 Inkscape::SnappedPoint _snapTransformed(Inkscape::SnapPreferences::PointType type,
146 std::vector<Geom::Point> const &points,
147 bool constrained,
148 Inkscape::Snapper::ConstraintLine const &constraint,
149 Transformation transformation_type,
150 Geom::Point const &transformation,
151 Geom::Point const &origin,
152 Geom::Dim2 dim,
153 bool uniform) const;
155 Inkscape::SnappedPoint findBestSnap(Geom::Point const &p, SnappedConstraints &sc, bool constrained) const;
156 };
158 #endif /* !SEEN_SNAP_H */
160 /*
161 Local Variables:
162 mode:c++
163 c-file-style:"stroustrup"
164 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
165 indent-tabs-mode:nil
166 fill-column:99
167 End:
168 */
169 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :