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 *
17 * Released under GNU GPL, read the file 'COPYING' for more information
18 */
20 #include <vector>
22 #include <libnr/nr-coord.h>
23 #include <libnr/nr-dim2.h>
24 #include <libnr/nr-forward.h>
25 #include <libnr/nr-scale.h>
27 #include "guide-snapper.h"
28 #include "object-snapper.h"
30 class SPNamedView;
32 /// Class to coordinate snapping operations
34 /**
35 * Each SPNamedView has one of these. It offers methods to snap points to whatever
36 * snappers are defined (e.g. grid, guides etc.). It also allows callers to snap
37 * points which have undergone some transformation (e.g. translation, scaling etc.)
38 */
40 class SnapManager
41 {
42 public:
43 SnapManager(SPNamedView const *v);
45 typedef std::list<const Inkscape::Snapper*> SnapperList;
47 bool SomeSnapperMightSnap() const;
49 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
50 NR::Point const &p,
51 SPItem const *it,
52 NR::Maybe<NR::Point> point_not_to_snap_to = NR::Nothing()) const;
54 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
55 NR::Point const &p,
56 SPItem const *it,
57 std::vector<NR::Point> *unselected_nodes) const;
59 Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
60 NR::Point const &p,
61 bool const &first_point,
62 std::vector<NR::Point> &points_to_snap,
63 std::list<SPItem const *> const &it,
64 std::vector<NR::Point> *unselected_nodes) const;
66 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
67 NR::Point const &p,
68 Inkscape::Snapper::ConstraintLine const &c,
69 SPItem const *it) const;
71 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
72 NR::Point const &p,
73 bool const &first_point,
74 std::vector<NR::Point> &points_to_snap,
75 Inkscape::Snapper::ConstraintLine const &c,
76 std::list<SPItem const *> const &it) const;
78 Inkscape::SnappedPoint guideSnap(NR::Point const &p,
79 NR::Point const &guide_normal) const;
81 std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
82 std::vector<NR::Point> const &p,
83 std::list<SPItem const *> const &it,
84 NR::Point const &tr) const;
86 std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
87 std::vector<NR::Point> const &p,
88 std::list<SPItem const *> const &it,
89 Inkscape::Snapper::ConstraintLine const &c,
90 NR::Point const &tr) const;
92 std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
93 std::vector<NR::Point> const &p,
94 std::list<SPItem const *> const &it,
95 NR::scale const &s,
96 NR::Point const &o) const;
98 std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
99 std::vector<NR::Point> const &p,
100 std::list<SPItem const *> const &it,
101 NR::scale const &s,
102 NR::Point const &o) const;
104 std::pair<NR::Coord, bool> constrainedSnapStretch(Inkscape::Snapper::PointType t,
105 std::vector<NR::Point> const &p,
106 std::list<SPItem const *> const &it,
107 NR::Coord const &s,
108 NR::Point const &o,
109 NR::Dim2 d,
110 bool uniform) const;
112 std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
113 std::vector<NR::Point> const &p,
114 std::list<SPItem const *> const &it,
115 NR::Coord const &s,
116 NR::Point const &o,
117 NR::Dim2 d) const;
119 Inkscape::SnappedPoint guideSnap(NR::Point const &p,
120 Inkscape::ObjectSnapper::DimensionToSnap const snap_dim) const;
123 Inkscape::GuideSnapper guide; ///< guide snapper
124 Inkscape::ObjectSnapper object; ///< snapper to other objects
126 SnapperList getSnappers() const;
127 SnapperList getGridSnappers() const;
129 void setSnapModeBBox(bool enabled);
130 void setSnapModeNode(bool enabled);
131 void setSnapModeGuide(bool enabled);
132 bool getSnapModeBBox() const;
133 bool getSnapModeNode() const;
134 bool getSnapModeGuide() const;
136 void setSnapIntersectionGG(bool enabled) {_intersectionGG = enabled;}
137 void setSnapIntersectionLS(bool enabled) {_intersectionLS = enabled;}
138 bool getSnapIntersectionGG() { return _intersectionGG;}
139 bool getSnapIntersectionLS() { return _intersectionLS;}
141 void setIncludeItemCenter(bool enabled) {
142 _include_item_center = enabled;
143 // also store a local copy in the object-snapper instead of passing it through many functions
144 object.setIncludeItemCenter(enabled);
145 }
147 bool getIncludeItemCenter() const {
148 return _include_item_center;
149 }
151 void setSnapEnabledGlobally(bool enabled) {
152 _snap_enabled_globally = enabled;
153 }
155 bool getSnapEnabledGlobally() const {
156 return _snap_enabled_globally;
157 }
159 void toggleSnapEnabledGlobally() {
160 _snap_enabled_globally = !_snap_enabled_globally;
161 }
163 protected:
164 SPNamedView const *_named_view;
166 private:
168 enum Transformation {
169 TRANSLATION,
170 SCALE,
171 STRETCH,
172 SKEW
173 };
175 bool _include_item_center; //If true, snapping nodes will also snap the item's center
176 bool _intersectionGG;
177 bool _intersectionLS;
178 bool _snap_enabled_globally; //Toggles ALL snapping
180 std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
181 std::vector<NR::Point> const &points,
182 std::list<SPItem const *> const &ignore,
183 bool constrained,
184 Inkscape::Snapper::ConstraintLine const &constraint,
185 Transformation transformation_type,
186 NR::Point const &transformation,
187 NR::Point const &origin,
188 NR::Dim2 dim,
189 bool uniform) const;
191 Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const;
192 };
194 #endif /* !SEEN_SNAP_H */
196 /*
197 Local Variables:
198 mode:c++
199 c-file-style:"stroustrup"
200 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
201 indent-tabs-mode:nil
202 fill-column:99
203 End:
204 */
205 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :