Code

08b10e41b30676f6ca390bd57ae898cab09902e6
[inkscape.git] / src / snapper.h
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                           SnapSourceType const &/*source_type*/,
63                           bool const &/*first_point*/,
64                           Geom::OptRect const &/*bbox_to_snap*/,
65                           std::vector<SPItem const *> const */*it*/,
66                           std::vector<std::pair<Geom::Point, int> > */*unselected_nodes*/) const {};
68     class ConstraintLine
69     {
70     public:
71         ConstraintLine(Geom::Point const &d) : _has_point(false), _direction(d) {}
72         ConstraintLine(Geom::Point const &p, Geom::Point const &d) : _has_point(true), _point(p), _direction(d) {}
74         bool hasPoint() const {
75             return _has_point;
76         }
78         Geom::Point getPoint() const {
79             return _point;
80         }
82         Geom::Point getDirection() const {
83             return _direction;
84         }
86         void setPoint(Geom::Point const &p) {
87             _point = p;
88             _has_point = true;
89         }
91     private:
93         bool _has_point;
94         Geom::Point _point;
95         Geom::Point _direction;
96     };
98     virtual void constrainedSnap(SnappedConstraints &/*sc*/,
99                                                          SnapPreferences::PointType const &/*t*/,
100                                  Geom::Point const &/*p*/,
101                                  SnapSourceType const &/*source_type*/,
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
111                                                 // This is only used for grids, for which snapping can be enabled individually
112 };
116 #endif /* !SEEN_SNAPPER_H */
118 /*
119   Local Variables:
120   mode:c++
121   c-file-style:"stroustrup"
122   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
123   indent-tabs-mode:nil
124   fill-column:99
125   End:
126 */
127 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :