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 "libnr/nr-coord.h"
18 #include "libnr/nr-point.h"
19 #include <boost/optional.hpp>
21 #include "snapped-point.h"
22 #include "snapped-line.h"
23 #include "snapped-curve.h"
24 #include "snap-preferences.h"
26 struct SnappedConstraints {
27 std::list<Inkscape::SnappedPoint> points;
28 std::list<Inkscape::SnappedLineSegment> lines;
29 std::list<Inkscape::SnappedLine> grid_lines;
30 std::list<Inkscape::SnappedLine> guide_lines;
31 std::list<Inkscape::SnappedCurve> curves;
32 };
34 class SnapManager;
35 struct SPItem;
37 namespace Inkscape
38 {
40 /// Parent for classes that can snap points to something
41 class Snapper
42 {
43 public:
44 Snapper() {}
45 Snapper(SnapManager *sm, ::Geom::Coord const t);
46 virtual ~Snapper() {}
48 void setSnapperTolerance(Geom::Coord t);
49 Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
50 bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance
52 /**
53 * \return true if this Snapper will snap at least one kind of point.
54 */
55 //virtual bool ThisSnapperMightSnap() const;
56 virtual bool ThisSnapperMightSnap() const {return _snap_enabled;} // will likely be overridden by derived classes
58 void setEnabled(bool s);
59 bool getEnabled() const {return _snap_enabled;}
61 virtual void freeSnap(SnappedConstraints &/*sc*/,
62 SnapPreferences::PointType const &/*t*/,
63 Geom::Point const &/*p*/,
64 bool const &/*first_point*/,
65 Geom::OptRect const &/*bbox_to_snap*/,
66 std::vector<SPItem const *> const */*it*/,
67 std::vector<Geom::Point> */*unselected_nodes*/) const {};
69 class ConstraintLine
70 {
71 public:
72 ConstraintLine(Geom::Point const &d) : _has_point(false), _direction(d) {}
73 ConstraintLine(Geom::Point const &p, Geom::Point const &d) : _has_point(true), _point(p), _direction(d) {}
75 bool hasPoint() const {
76 return _has_point;
77 }
79 Geom::Point getPoint() const {
80 return _point;
81 }
83 Geom::Point getDirection() const {
84 return _direction;
85 }
87 void setPoint(Geom::Point const &p) {
88 _point = p;
89 _has_point = true;
90 }
92 private:
94 bool _has_point;
95 Geom::Point _point;
96 Geom::Point _direction;
97 };
99 virtual void constrainedSnap(SnappedConstraints &/*sc*/,
100 SnapPreferences::PointType const &/*t*/,
101 Geom::Point const &/*p*/,
102 bool const &/*first_point*/,
103 Geom::OptRect const &/*bbox_to_snap*/,
104 ConstraintLine const &/*c*/,
105 std::vector<SPItem const *> const */*it*/) const {};
107 protected:
108 SnapManager *_snapmanager;
110 bool _snap_enabled; ///< true if this snapper is enabled, otherwise false
112 private:
113 Geom::Coord _snapper_tolerance; ///< snap tolerance in desktop coordinates
114 // must be private to enforce the usage of getTolerance(), which retrieves
115 // the tolerance in screen pixels (making it zoom independent)
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 :