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 "guide-snapper.h"
24 #include "object-snapper.h"
25 #include "snap-preferences.h"
26 //#include "sp-guide.h"
28 class SPNamedView;
30 /// Class to coordinate snapping operations
32 /**
33 * Each SPNamedView has one of these. It offers methods to snap points to whatever
34 * snappers are defined (e.g. grid, guides etc.). It also allows callers to snap
35 * points which have undergone some transformation (e.g. translation, scaling etc.)
36 */
38 class SnapManager
39 {
40 public:
41 enum Transformation {
42 TRANSLATION,
43 SCALE,
44 STRETCH,
45 SKEW
46 };
48 SnapManager(SPNamedView const *v);
50 typedef std::list<const Inkscape::Snapper*> SnapperList;
52 bool someSnapperMightSnap() const;
53 bool gridSnapperMightSnap() const;
55 void setup(SPDesktop const *desktop,
56 bool snapindicator = true,
57 SPItem const *item_to_ignore = NULL,
58 std::vector<std::pair<Geom::Point, int> > *unselected_nodes = NULL,
59 SPGuide *guide_to_ignore = NULL);
61 void setup(SPDesktop const *desktop,
62 bool snapindicator,
63 std::vector<SPItem const *> &items_to_ignore,
64 std::vector<std::pair<Geom::Point, int> > *unselected_nodes = NULL,
65 SPGuide *guide_to_ignore = NULL);
67 // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a
68 // point if snapping has occurred (by overwriting p); otherwise p is untouched
69 void freeSnapReturnByRef(Inkscape::SnapPreferences::PointType point_type,
70 Geom::Point &p,
71 Inkscape::SnapSourceType const source_type,
72 bool first_point = true,
73 Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
76 Inkscape::SnappedPoint freeSnap(Inkscape::SnapPreferences::PointType point_type,
77 Geom::Point const &p,
78 Inkscape::SnapSourceType const &source_type,
79 bool first_point = true,
80 Geom::OptRect const &bbox_to_snap = Geom::OptRect() ) const;
82 Geom::Point multipleOfGridPitch(Geom::Point const &t) const;
84 // constrainedSnapReturnByRef() is preferred over constrainedSnap(), because it only returns a
85 // point, by overwriting p, if snapping has occurred; otherwise p is untouched
86 void constrainedSnapReturnByRef(Inkscape::SnapPreferences::PointType point_type,
87 Geom::Point &p,
88 Inkscape::SnapSourceType const source_type,
89 Inkscape::Snapper::ConstraintLine const &constraint,
90 bool snap_projection, //try snapping the projection of p onto the constraint line, not p itself
91 bool first_point = true,
92 Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
94 Inkscape::SnappedPoint constrainedSnap(Inkscape::SnapPreferences::PointType point_type,
95 Geom::Point const &p,
96 Inkscape::SnapSourceType const &source_type,
97 Inkscape::Snapper::ConstraintLine const &constraint,
98 bool const snap_projection,
99 bool first_point = true,
100 Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
102 void guideFreeSnap(Geom::Point &p, Geom::Point const &guide_normal) const;
103 void guideConstrainedSnap(Geom::Point &p, SPGuide const &guideline) const;
105 Inkscape::SnappedPoint freeSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
106 std::vector<std::pair<Geom::Point, int> > const &p,
107 Geom::Point const &pointer,
108 Geom::Point const &tr) const;
110 Inkscape::SnappedPoint constrainedSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
111 std::vector<std::pair<Geom::Point, int> > const &p,
112 Geom::Point const &pointer,
113 Inkscape::Snapper::ConstraintLine const &constraint,
114 Geom::Point const &tr) const;
116 Inkscape::SnappedPoint freeSnapScale(Inkscape::SnapPreferences::PointType point_type,
117 std::vector<std::pair<Geom::Point, int> > const &p,
118 Geom::Point const &pointer,
119 Geom::Scale const &s,
120 Geom::Point const &o) const;
122 Inkscape::SnappedPoint constrainedSnapScale(Inkscape::SnapPreferences::PointType point_type,
123 std::vector<std::pair<Geom::Point, int> > const &p,
124 Geom::Point const &pointer,
125 Geom::Scale const &s,
126 Geom::Point const &o) const;
128 Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::SnapPreferences::PointType point_type,
129 std::vector<std::pair<Geom::Point, int> > const &p,
130 Geom::Point const &pointer,
131 Geom::Coord const &s,
132 Geom::Point const &o,
133 Geom::Dim2 d,
134 bool uniform) const;
136 Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::SnapPreferences::PointType point_type,
137 std::vector<std::pair<Geom::Point, int> > const &p,
138 Geom::Point const &pointer,
139 Inkscape::Snapper::ConstraintLine const &constraint,
140 Geom::Point const &s, // s[0] = skew factor, s[1] = scale factor
141 Geom::Point const &o,
142 Geom::Dim2 d) const;
144 Inkscape::GuideSnapper guide; ///< guide snapper
145 Inkscape::ObjectSnapper object; ///< snapper to other objects
146 Inkscape::SnapPreferences snapprefs;
148 SnapperList getSnappers() const;
149 SnapperList getGridSnappers() const;
151 SPDesktop const *getDesktop() const {return _desktop;}
152 SPNamedView const *getNamedView() const {return _named_view;}
153 SPDocument *getDocument() const;
154 SPGuide const *getGuideToIgnore() const {return _guide_to_ignore;}
156 bool getSnapIndicator() const {return _snapindicator;}
158 protected:
159 SPNamedView const *_named_view;
161 private:
162 std::vector<SPItem const *> *_items_to_ignore;
163 SPItem const *_item_to_ignore;
164 SPGuide *_guide_to_ignore;
165 SPDesktop const *_desktop;
166 bool _snapindicator;
167 std::vector<std::pair<Geom::Point, int> > *_unselected_nodes;
169 Inkscape::SnappedPoint _snapTransformed(Inkscape::SnapPreferences::PointType type,
170 std::vector<std::pair<Geom::Point, int> > const &points,
171 Geom::Point const &pointer,
172 bool constrained,
173 Inkscape::Snapper::ConstraintLine const &constraint,
174 Transformation transformation_type,
175 Geom::Point const &transformation,
176 Geom::Point const &origin,
177 Geom::Dim2 dim,
178 bool uniform) const;
180 Geom::Point _transformPoint(std::pair<Geom::Point, int> const &p,
181 Transformation const transformation_type,
182 Geom::Point const &transformation,
183 Geom::Point const &origin,
184 Geom::Dim2 const dim,
185 bool const uniform) const;
187 void _displaySnapsource(Inkscape::SnapPreferences::PointType point_type, std::pair<Geom::Point, int> const &p) const;
189 Inkscape::SnappedPoint findBestSnap(Geom::Point const &p, Inkscape::SnapSourceType const source_type, SnappedConstraints &sc, bool constrained) const;
190 };
192 #endif /* !SEEN_SNAP_H */
194 /*
195 Local Variables:
196 mode:c++
197 c-file-style:"stroustrup"
198 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
199 indent-tabs-mode:nil
200 fill-column:99
201 End:
202 */
203 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :