1 #ifndef SEEN_SNAPPER_H
2 #define SEEN_SNAPPER_H
4 /**
5 * \file src/snapper.h
6 * \brief Snapper class.
7 *
8 * Authors:
9 * Carl Hetherington <inkscape@carlh.net>
10 * Diederik van Lierop <mail@diedenrezi.nl>
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information.
13 */
15 #include <map>
16 #include <list>
17 #include <boost/optional.hpp>
19 #include "snapped-point.h"
20 #include "snapped-line.h"
21 #include "snapped-curve.h"
22 #include "snap-preferences.h"
24 struct SnappedConstraints {
25 std::list<Inkscape::SnappedPoint> points;
26 std::list<Inkscape::SnappedLineSegment> lines;
27 std::list<Inkscape::SnappedLine> grid_lines;
28 std::list<Inkscape::SnappedLine> guide_lines;
29 std::list<Inkscape::SnappedCurve> curves;
30 };
32 class SnapManager;
33 struct SPItem;
35 namespace Inkscape
36 {
38 /// Parent for classes that can snap points to something
39 class Snapper
40 {
41 public:
42 Snapper() {}
43 Snapper(SnapManager *sm, ::Geom::Coord const t);
44 virtual ~Snapper() {}
46 virtual Geom::Coord getSnapperTolerance() const = 0; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
47 virtual bool getSnapperAlwaysSnap() const = 0; //if true, then the snapper will always snap, regardless of its tolerance
49 /**
50 * \return true if this Snapper will snap at least one kind of point.
51 */
52 virtual bool ThisSnapperMightSnap() const {return _snap_enabled;} // will likely be overridden by derived classes
54 void setEnabled(bool s); // This is only used for grids, for which snapping can be enabled individually
55 bool getEnabled() const {return _snap_enabled;}
57 virtual void freeSnap(SnappedConstraints &/*sc*/,
58 SnapPreferences::PointType const &/*t*/,
59 Geom::Point const &/*p*/,
60 SnapSourceType const &/*source_type*/,
61 bool const &/*first_point*/,
62 Geom::OptRect const &/*bbox_to_snap*/,
63 std::vector<SPItem const *> const */*it*/,
64 std::vector<std::pair<Geom::Point, int> > */*unselected_nodes*/) const {};
66 class ConstraintLine
67 {
68 public:
69 ConstraintLine(Geom::Point const &d) : _has_point(false), _direction(d) {}
70 ConstraintLine(Geom::Point const &p, Geom::Point const &d) : _has_point(true), _point(p), _direction(d) {}
72 bool hasPoint() const {
73 return _has_point;
74 }
76 Geom::Point getPoint() const {
77 return _point;
78 }
80 Geom::Point getDirection() const {
81 return _direction;
82 }
84 void setPoint(Geom::Point const &p) {
85 _point = p;
86 _has_point = true;
87 }
89 Geom::Point projection(Geom::Point const &p) const { // returns the projection of p on this constraintline
90 Geom::Point const p1_on_cl = _has_point ? _point : p;
91 Geom::Point const p2_on_cl = p1_on_cl + _direction;
92 return Geom::projection(p, Geom::Line(p1_on_cl, p2_on_cl));
93 }
95 private:
97 bool _has_point;
98 Geom::Point _point;
99 Geom::Point _direction;
100 };
102 virtual void constrainedSnap(SnappedConstraints &/*sc*/,
103 SnapPreferences::PointType const &/*t*/,
104 Geom::Point const &/*p*/,
105 SnapSourceType const &/*source_type*/,
106 bool const &/*first_point*/,
107 Geom::OptRect const &/*bbox_to_snap*/,
108 ConstraintLine const &/*c*/,
109 std::vector<SPItem const *> const */*it*/) const {};
111 protected:
112 SnapManager *_snapmanager;
114 bool _snap_enabled; ///< true if this snapper is enabled, otherwise false
115 // This is only used for grids, for which snapping can be enabled individually
116 };
118 }
120 #endif /* !SEEN_SNAPPER_H */
122 /*
123 Local Variables:
124 mode:c++
125 c-file-style:"stroustrup"
126 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
127 indent-tabs-mode:nil
128 fill-column:99
129 End:
130 */
131 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :