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 SNAPTARGET_PAGE_BORDER
38 };
40 /// Class describing the result of an attempt to snap.
41 class SnappedPoint
42 {
44 public:
45 SnappedPoint();
46 SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, bool const &fully_constrained, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2);
47 SnappedPoint(Geom::Point const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &fully_constrained);
48 ~SnappedPoint();
50 Geom::Coord getSnapDistance() const {return _distance;}
51 void setSnapDistance(Geom::Coord const d) {_distance = d;}
52 Geom::Coord getTolerance() const {return _tolerance;}
53 bool getAlwaysSnap() const {return _always_snap;}
54 Geom::Coord getSecondSnapDistance() const {return _second_distance;}
55 void setSecondSnapDistance(Geom::Coord const d) {_second_distance = d;}
56 Geom::Coord getSecondTolerance() const {return _second_tolerance;}
57 bool getSecondAlwaysSnap() const {return _second_always_snap;}
58 Geom::Coord getPointerDistance() const {return _pointer_distance;}
59 void setPointerDistance(Geom::Coord const d) {_pointer_distance = d;}
61 /* This is the preferred method to find out which point we have snapped
62 * to, because it only returns a point if snapping has actually occurred
63 * (by overwriting p)
64 */
65 void getPoint(Geom::Point &p) const;
67 /* This method however always returns a point, even if no snapping
68 * has occured; A check should be implemented in the calling code
69 * to check for snapping. Use this method only when really needed, e.g.
70 * when the calling code is trying to snap multiple points and must
71 * determine itself which point is most appropriate
72 */
73 Geom::Point getPoint() const {return _point;}
75 bool getAtIntersection() const {return _at_intersection;}
76 bool getFullyConstrained() const {return _fully_constrained;}
77 bool getSnapped() const {return _distance < NR_HUGE;}
78 Geom::Point getTransformation() const {return _transformation;}
79 void setTransformation(Geom::Point const t) {_transformation = t;}
80 void setTarget(SnapTargetType const target) {_target = target;}
81 SnapTargetType getTarget() const {return _target;}
83 bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;
85 /*void dump() const {
86 std::cout << "_point = " << _point << std::endl;
87 std::cout << "_target = " << _target << std::endl;
88 std::cout << "_at_intersection = " << _at_intersection << std::endl;
89 std::cout << "_fully_constrained = " << _fully_constrained << std::endl;
90 std::cout << "_distance = " << _distance << std::endl;
91 std::cout << "_tolerance = " << _tolerance << std::endl;
92 std::cout << "_always_snap = " << _always_snap << std::endl;
93 std::cout << "_second_distance = " << _second_distance << std::endl;
94 std::cout << "_second_tolerance = " << _second_tolerance << std::endl;
95 std::cout << "_second_always_snap = " << _second_always_snap << std::endl;
96 std::cout << "_transformation = " << _transformation << std::endl;
97 std::cout << "_pointer_distance = " << _pointer_distance << std::endl;
98 }*/
100 protected:
101 Geom::Point _point; // Location of the snapped point
102 SnapTargetType _target; // Describes to what we've snapped to
103 bool _at_intersection; // If true, the snapped point is at an intersection
104 bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained".
105 // When snapping to a line however, the snap is only partly constrained (i.e. only in one dimension)
107 /* Distance from original point to snapped point. If the snapped point is at
108 an intersection of e.g. two lines, then this is the distance to the closest
109 line */
110 Geom::Coord _distance;
111 /* The snapping tolerance in screen pixels (depends on zoom)*/
112 Geom::Coord _tolerance;
113 /* If true then "Always snap" is on */
114 bool _always_snap;
116 /* If the snapped point is at an intersection of e.g. two lines, then this is
117 the distance to the fartest line */
118 Geom::Coord _second_distance;
119 /* The snapping tolerance in screen pixels (depends on zoom)*/
120 Geom::Coord _second_tolerance;
121 /* If true then "Always snap" is on */
122 bool _second_always_snap;
123 /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
124 Geom::Point _transformation;
125 /* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */
126 Geom::Coord _pointer_distance;
127 };
129 }// end of namespace Inkscape
131 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
133 #endif /* !SEEN_SNAPPEDPOINT_H */
135 /*
136 Local Variables:
137 mode:c++
138 c-file-style:"stroustrup"
139 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
140 indent-tabs-mode:nil
141 fill-column:99
142 End:
143 */
144 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :