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>
25 #include "guide-snapper.h"
26 #include "object-snapper.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 SnapManager(SPNamedView const *v);
43 typedef std::list<const Inkscape::Snapper*> SnapperList;
45 bool SomeSnapperMightSnap() const;
47 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
48 NR::Point const &p,
49 SPItem const *it) const;
51 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
52 NR::Point const &p,
53 std::list<SPItem const *> const &it) const;
55 Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
56 NR::Point const &p,
57 std::list<SPItem const *> const &it,
58 SnapperList const &snappers ) const;
60 Inkscape::SnappedPoint freeSnapAlways( Inkscape::Snapper::PointType t,
61 NR::Point const &p,
62 SPItem const *it,
63 SnapperList &snappers );
65 Inkscape::SnappedPoint freeSnapAlways( Inkscape::Snapper::PointType t,
66 NR::Point const &p,
67 std::list<SPItem const *> const &it,
68 SnapperList &snappers );
70 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
71 NR::Point const &p,
72 Inkscape::Snapper::ConstraintLine const &c,
73 SPItem const *it) const;
75 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
76 NR::Point const &p,
77 Inkscape::Snapper::ConstraintLine const &c,
78 std::list<SPItem const *> const &it) const;
80 Inkscape::SnappedPoint guideSnap(NR::Point const &p,
81 SPGuide const &guide) const;
83 std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
84 std::vector<NR::Point> const &p,
85 std::list<SPItem const *> const &it,
86 NR::Point const &tr) const;
88 std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
89 std::vector<NR::Point> const &p,
90 std::list<SPItem const *> const &it,
91 Inkscape::Snapper::ConstraintLine const &c,
92 NR::Point const &tr) const;
94 std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
95 std::vector<NR::Point> const &p,
96 std::list<SPItem const *> const &it,
97 NR::scale const &s,
98 NR::Point const &o) const;
100 std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
101 std::vector<NR::Point> const &p,
102 std::list<SPItem const *> const &it,
103 Inkscape::Snapper::ConstraintLine const &c,
104 NR::scale const &s,
105 NR::Point const &o) const;
107 std::pair<NR::Coord, bool> freeSnapStretch(Inkscape::Snapper::PointType t,
108 std::vector<NR::Point> const &p,
109 std::list<SPItem const *> const &it,
110 NR::Coord const &s,
111 NR::Point const &o,
112 NR::Dim2 d,
113 bool uniform) const;
115 std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
116 std::vector<NR::Point> const &p,
117 std::list<SPItem const *> const &it,
118 NR::Coord const &s,
119 NR::Point const &o,
120 NR::Dim2 d) const;
122 Inkscape::GuideSnapper guide; ///< guide snapper
123 Inkscape::ObjectSnapper object; ///< snapper to other objects
125 SnapperList getSnappers() const;
126 SnapperList getGridSnappers() const;
128 void setSnapModeBBox(bool enabled);
129 void setSnapModeNode(bool enabled);
130 void setSnapModeGuide(bool enabled);
131 bool getSnapModeBBox() const;
132 bool getSnapModeNode() const;
133 bool getSnapModeGuide() const;
135 void setIncludeItemCenter(bool enabled) {
136 _include_item_center = enabled;
137 object.setIncludeItemCenter(enabled); //store a local copy in the object-snapper
138 //instead of passing it through many functions
139 }
141 bool getIncludeItemCenter() const {
142 return _include_item_center;
143 }
145 protected:
146 SPNamedView const *_named_view;
148 private:
150 enum Transformation {
151 TRANSLATION,
152 SCALE,
153 STRETCH,
154 SKEW
155 };
157 bool _include_item_center; //If true, snapping nodes will also snap the item's center
159 std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
160 std::vector<NR::Point> const &points,
161 std::list<SPItem const *> const &ignore,
162 bool constrained,
163 Inkscape::Snapper::ConstraintLine const &constraint,
164 Transformation transformation_type,
165 NR::Point const &transformation,
166 NR::Point const &origin,
167 NR::Dim2 dim,
168 bool uniform) const;
169 };
171 #endif /* !SEEN_SNAP_H */
173 /*
174 Local Variables:
175 mode:c++
176 c-file-style:"stroustrup"
177 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
178 indent-tabs-mode:nil
179 fill-column:99
180 End:
181 */
182 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :