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 std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
81 std::vector<NR::Point> const &p,
82 std::list<SPItem const *> const &it,
83 NR::Point const &tr) const;
85 std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
86 std::vector<NR::Point> const &p,
87 std::list<SPItem const *> const &it,
88 Inkscape::Snapper::ConstraintLine const &c,
89 NR::Point const &tr) const;
91 std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
92 std::vector<NR::Point> const &p,
93 std::list<SPItem const *> const &it,
94 NR::scale const &s,
95 NR::Point const &o) const;
97 std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
98 std::vector<NR::Point> const &p,
99 std::list<SPItem const *> const &it,
100 Inkscape::Snapper::ConstraintLine const &c,
101 NR::scale const &s,
102 NR::Point const &o) const;
104 std::pair<NR::Coord, bool> freeSnapStretch(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::GuideSnapper guide; ///< guide snapper
120 Inkscape::ObjectSnapper object; ///< snapper to other objects
122 SnapperList getSnappers() const;
123 SnapperList getGridSnappers() const;
125 protected:
126 SPNamedView const *_named_view;
128 private:
130 enum Transformation {
131 TRANSLATION,
132 SCALE,
133 STRETCH,
134 SKEW
135 };
137 std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
138 std::vector<NR::Point> const &points,
139 std::list<SPItem const *> const &ignore,
140 bool constrained,
141 Inkscape::Snapper::ConstraintLine const &constraint,
142 Transformation transformation_type,
143 NR::Point const &transformation,
144 NR::Point const &origin,
145 NR::Dim2 dim,
146 bool uniform) const;
147 };
149 #endif /* !SEEN_SNAP_H */
151 /*
152 Local Variables:
153 mode:c++
154 c-file-style:"stroustrup"
155 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
156 indent-tabs-mode:nil
157 fill-column:99
158 End:
159 */
160 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :