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 virtual Geom::Coord getSnapperTolerance() const = 0; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
49 virtual bool getSnapperAlwaysSnap() const = 0; //if true, then the snapper will always snap, regardless of its tolerance
51 /**
52 * \return true if this Snapper will snap at least one kind of point.
53 */
54 virtual bool ThisSnapperMightSnap() const {return _snap_enabled;} // will likely be overridden by derived classes
56 void setEnabled(bool s); // This is only used for grids, for which snapping can be enabled individually
57 bool getEnabled() const {return _snap_enabled;}
59 virtual void freeSnap(SnappedConstraints &/*sc*/,
60 SnapPreferences::PointType const &/*t*/,
61 Geom::Point const &/*p*/,
62 bool const &/*first_point*/,
63 Geom::OptRect const &/*bbox_to_snap*/,
64 std::vector<SPItem const *> const */*it*/,
65 std::vector<Geom::Point> */*unselected_nodes*/) const {};
67 class ConstraintLine
68 {
69 public:
70 ConstraintLine(Geom::Point const &d) : _has_point(false), _direction(d) {}
71 ConstraintLine(Geom::Point const &p, Geom::Point const &d) : _has_point(true), _point(p), _direction(d) {}
73 bool hasPoint() const {
74 return _has_point;
75 }
77 Geom::Point getPoint() const {
78 return _point;
79 }
81 Geom::Point getDirection() const {
82 return _direction;
83 }
85 void setPoint(Geom::Point const &p) {
86 _point = p;
87 _has_point = true;
88 }
90 private:
92 bool _has_point;
93 Geom::Point _point;
94 Geom::Point _direction;
95 };
97 virtual void constrainedSnap(SnappedConstraints &/*sc*/,
98 SnapPreferences::PointType const &/*t*/,
99 Geom::Point const &/*p*/,
100 bool const &/*first_point*/,
101 Geom::OptRect const &/*bbox_to_snap*/,
102 ConstraintLine const &/*c*/,
103 std::vector<SPItem const *> const */*it*/) const {};
105 protected:
106 SnapManager *_snapmanager;
108 bool _snap_enabled; ///< true if this snapper is enabled, otherwise false
109 // This is only used for grids, for which snapping can be enabled individually
110 };
112 }
114 #endif /* !SEEN_SNAPPER_H */
116 /*
117 Local Variables:
118 mode:c++
119 c-file-style:"stroustrup"
120 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
121 indent-tabs-mode:nil
122 fill-column:99
123 End:
124 */
125 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :