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 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 "grid-snapper.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 bool willSnapSomething() const;
46 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
47 NR::Point const &p,
48 SPItem const *it) const;
50 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
51 NR::Point const &p,
52 std::list<SPItem const *> const &it) const;
54 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
55 NR::Point const &p,
56 Inkscape::Snapper::ConstraintLine const &c,
57 SPItem const *it) const;
59 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
60 NR::Point const &p,
61 Inkscape::Snapper::ConstraintLine const &c,
62 std::list<SPItem const *> const &it) const;
64 std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
65 std::vector<NR::Point> const &p,
66 std::list<SPItem const *> const &it,
67 NR::Point const &tr) const;
69 std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
70 std::vector<NR::Point> const &p,
71 std::list<SPItem const *> const &it,
72 Inkscape::Snapper::ConstraintLine const &c,
73 NR::Point const &tr) const;
75 std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
76 std::vector<NR::Point> const &p,
77 std::list<SPItem const *> const &it,
78 NR::scale const &s,
79 NR::Point const &o) const;
81 std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
82 std::vector<NR::Point> const &p,
83 std::list<SPItem const *> const &it,
84 Inkscape::Snapper::ConstraintLine const &c,
85 NR::scale const &s,
86 NR::Point const &o) const;
88 std::pair<NR::Coord, bool> freeSnapStretch(Inkscape::Snapper::PointType t,
89 std::vector<NR::Point> const &p,
90 std::list<SPItem const *> const &it,
91 NR::Coord const &s,
92 NR::Point const &o,
93 NR::Dim2 d,
94 bool uniform) const;
96 std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
97 std::vector<NR::Point> const &p,
98 std::list<SPItem const *> const &it,
99 NR::Coord const &s,
100 NR::Point const &o,
101 NR::Dim2 d) const;
103 Inkscape::GridSnapper grid; ///< grid snapper
104 Inkscape::AxonomGridSnapper axonomgrid; ///< axonometricgrid snapper
105 Inkscape::GuideSnapper guide; ///< guide snapper
106 Inkscape::ObjectSnapper object; ///< snapper to other objects
108 typedef std::list<const Inkscape::Snapper*> SnapperList;
109 SnapperList getSnappers() const;
110 SnapperList gridSnappers; ///< List of grid snappers to enable multiple grids
112 protected:
113 SPNamedView const *_named_view;
115 private:
117 enum Transformation {
118 TRANSLATION,
119 SCALE,
120 STRETCH,
121 SKEW
122 };
124 std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
125 std::vector<NR::Point> const &points,
126 std::list<SPItem const *> const &ignore,
127 bool constrained,
128 Inkscape::Snapper::ConstraintLine const &constraint,
129 Transformation transformation_type,
130 NR::Point const &transformation,
131 NR::Point const &origin,
132 NR::Dim2 dim,
133 bool uniform) const;
134 };
136 #endif /* !SEEN_SNAP_H */
138 /*
139 Local Variables:
140 mode:c++
141 c-file-style:"stroustrup"
142 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
143 indent-tabs-mode:nil
144 fill-column:99
145 End:
146 */
147 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :