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 *
13 * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
14 * Copyright (C) 2000-2002 Lauris Kaplinski
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
19 #include <vector>
21 #include <libnr/nr-coord.h>
22 #include <libnr/nr-dim2.h>
23 #include <libnr/nr-forward.h>
24 #include <libnr/nr-scale.h>
26 #include "guide-snapper.h"
27 #include "object-snapper.h"
29 class SPNamedView;
31 /// Class to coordinate snapping operations
33 /**
34 * Each SPNamedView has one of these. It offers methods to snap points to whatever
35 * snappers are defined (e.g. grid, guides etc.). It also allows callers to snap
36 * points which have undergone some transformation (e.g. translation, scaling etc.)
37 */
39 class SnapManager
40 {
41 public:
42 SnapManager(SPNamedView const *v);
44 typedef std::list<const Inkscape::Snapper*> SnapperList;
46 bool SomeSnapperMightSnap() const;
48 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
49 NR::Point const &p,
50 SPItem const *it) const;
52 Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
53 NR::Point const &p,
54 bool const &first_point,
55 std::vector<NR::Point> &points_to_snap,
56 std::list<SPItem const *> const &it) const;
58 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
59 NR::Point const &p,
60 Inkscape::Snapper::ConstraintLine const &c,
61 SPItem const *it) const;
63 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
64 NR::Point const &p,
65 bool const &first_point,
66 std::vector<NR::Point> &points_to_snap,
67 Inkscape::Snapper::ConstraintLine const &c,
68 std::list<SPItem const *> const &it) const;
70 Inkscape::SnappedPoint guideSnap(NR::Point const &p,
71 NR::Point const &guide_normal) const;
73 std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
74 std::vector<NR::Point> const &p,
75 std::list<SPItem const *> const &it,
76 NR::Point const &tr) const;
78 std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
79 std::vector<NR::Point> const &p,
80 std::list<SPItem const *> const &it,
81 Inkscape::Snapper::ConstraintLine const &c,
82 NR::Point const &tr) const;
84 std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
85 std::vector<NR::Point> const &p,
86 std::list<SPItem const *> const &it,
87 NR::scale const &s,
88 NR::Point const &o) const;
90 std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
91 std::vector<NR::Point> const &p,
92 std::list<SPItem const *> const &it,
93 Inkscape::Snapper::ConstraintLine const &c,
94 NR::scale const &s,
95 NR::Point const &o) const;
97 std::pair<NR::Coord, bool> freeSnapStretch(Inkscape::Snapper::PointType t,
98 std::vector<NR::Point> const &p,
99 std::list<SPItem const *> const &it,
100 NR::Coord const &s,
101 NR::Point const &o,
102 NR::Dim2 d,
103 bool uniform) const;
105 std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
106 std::vector<NR::Point> const &p,
107 std::list<SPItem const *> const &it,
108 NR::Coord const &s,
109 NR::Point const &o,
110 NR::Dim2 d) const;
112 Inkscape::SnappedPoint guideSnap(NR::Point const &p,
113 Inkscape::ObjectSnapper::DimensionToSnap const snap_dim) const;
116 Inkscape::GuideSnapper guide; ///< guide snapper
117 Inkscape::ObjectSnapper object; ///< snapper to other objects
119 SnapperList getSnappers() const;
120 SnapperList getGridSnappers() const;
122 void setSnapModeBBox(bool enabled);
123 void setSnapModeNode(bool enabled);
124 void setSnapModeGuide(bool enabled);
125 bool getSnapModeBBox() const;
126 bool getSnapModeNode() const;
127 bool getSnapModeGuide() const;
129 void setSnapIntersectionGG(bool enabled) {_intersectionGG = enabled;}
130 void setSnapIntersectionLS(bool enabled) {_intersectionLS = enabled;}
131 bool getSnapIntersectionGG() { return _intersectionGG;}
132 bool getSnapIntersectionLS() { return _intersectionLS;}
134 void setIncludeItemCenter(bool enabled) {
135 _include_item_center = enabled;
136 // also store a local copy in the object-snapper instead of passing it through many functions
137 object.setIncludeItemCenter(enabled);
138 }
140 bool getIncludeItemCenter() const {
141 return _include_item_center;
142 }
144 protected:
145 SPNamedView const *_named_view;
147 private:
149 enum Transformation {
150 TRANSLATION,
151 SCALE,
152 STRETCH,
153 SKEW
154 };
156 bool _include_item_center; //If true, snapping nodes will also snap the item's center
157 bool _intersectionGG;
158 bool _intersectionLS;
160 std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
161 std::vector<NR::Point> const &points,
162 std::list<SPItem const *> const &ignore,
163 bool constrained,
164 Inkscape::Snapper::ConstraintLine const &constraint,
165 Transformation transformation_type,
166 NR::Point const &transformation,
167 NR::Point const &origin,
168 NR::Dim2 dim,
169 bool uniform) const;
171 Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc) const;
172 };
174 #endif /* !SEEN_SNAP_H */
176 /*
177 Local Variables:
178 mode:c++
179 c-file-style:"stroustrup"
180 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
181 indent-tabs-mode:nil
182 fill-column:99
183 End:
184 */
185 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :