4999a2aaee16b2f121269a1e2c2395e856d7f097
1 #ifndef SEEN_SNAPPEDPOINT_H
2 #define SEEN_SNAPPEDPOINT_H
4 /**
5 * \file src/snapped-point.h
6 * \brief SnappedPoint class.
7 *
8 * Authors:
9 * Mathieu Dimanche <mdimanche@free.fr>
10 * Diederik van Lierop <mail@diedenrezi.nl>
11 *
12 * Released under GNU GPL, read the file 'COPYING' for more information.
13 */
15 #include <vector>
16 #include <list>
17 #include "libnr/nr-coord.h"
18 #include "libnr/nr-point.h"
19 #include <libnr/nr-values.h>
21 namespace Inkscape
22 {
24 enum SnapTargetType {
25 SNAPTARGET_UNDEFINED,
26 SNAPTARGET_GRID,
27 SNAPTARGET_GRID_INTERSECTION,
28 SNAPTARGET_GUIDE,
29 SNAPTARGET_GUIDE_INTERSECTION,
30 SNAPTARGET_GRID_GUIDE_INTERSECTION,
31 SNAPTARGET_NODE,
32 SNAPTARGET_PATH,
33 SNAPTARGET_PATH_INTERSECTION,
34 SNAPTARGET_BBOX_CORNER,
35 SNAPTARGET_BBOX_EDGE,
36 SNAPTARGET_GRADIENT
37 };
39 /// Class describing the result of an attempt to snap.
40 class SnappedPoint
41 {
43 public:
44 SnappedPoint();
45 SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2);
46 SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a);
47 ~SnappedPoint();
49 Geom::Coord getDistance() const;
50 void setDistance(Geom::Coord const d) {_distance = d;}
51 Geom::Coord getTolerance() const;
52 bool getAlwaysSnap() const;
53 Geom::Coord getSecondDistance() const;
54 Geom::Coord getSecondTolerance() const;
55 bool getSecondAlwaysSnap() const;
57 /* This is the preferred method to find out which point we have snapped,
58 * to because it only returns a point if snapping has actually occured
59 * (by overwriting p)
60 */
61 void getPoint(Geom::Point &p) const;
63 /* This method however always returns a point, even if no snapping
64 * has occured; A check should be implemented in the calling code
65 * to check for snapping. Use this method only when really needed, e.g.
66 * when the calling code is trying to snap multiple points and must
67 * determine itself which point is most appropriate
68 */
69 Geom::Point getPoint() const {return _point;}
71 bool getAtIntersection() const {return _at_intersection;}
72 bool getSnapped() const {return _distance < NR_HUGE;}
73 Geom::Point getTransformation() const {return _transformation;}
74 void setTransformation(Geom::Point const t) {_transformation = t;}
75 void setTarget(SnapTargetType const target) {_target = target;}
76 SnapTargetType getTarget() {return _target;}
78 protected:
79 Geom::Point _point; // Location of the snapped point
80 SnapTargetType _target; // Describes to what we've snapped to
81 bool _at_intersection; // If true, the snapped point is at an intersection
83 /* Distance from original point to snapped point. If the snapped point is at
84 an intersection of e.g. two lines, then this is the distance to the closest
85 line */
86 Geom::Coord _distance;
87 /* The snapping tolerance in screen pixels (depends on zoom)*/
88 Geom::Coord _tolerance;
89 /* If true then "Always snap" is on */
90 bool _always_snap;
92 /* If the snapped point is at an intersection of e.g. two lines, then this is
93 the distance to the fartest line */
94 Geom::Coord _second_distance;
95 /* The snapping tolerance in screen pixels (depends on zoom)*/
96 Geom::Coord _second_tolerance;
97 /* If true then "Always snap" is on */
98 bool _second_always_snap;
99 /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
100 Geom::Point _transformation;
101 };
103 }
105 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
108 #endif /* !SEEN_SNAPPEDPOINT_H */
110 /*
111 Local Variables:
112 mode:c++
113 c-file-style:"stroustrup"
114 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
115 indent-tabs-mode:nil
116 fill-column:99
117 End:
118 */
119 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :