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-values.h> //Because of NR_HUGE
18 #include <2geom/geom.h>
19 #include <snap-candidate.h>
21 namespace Inkscape
22 {
24 /// Class describing the result of an attempt to snap.
25 class SnappedPoint
26 {
28 public:
29 SnappedPoint();
30 SnappedPoint(Geom::Point const &p);
31 SnappedPoint(Geom::Point const &p, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &at_intersection, bool const &constrained_snap, bool const &fully_constrained, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2);
32 SnappedPoint(Geom::Point const &p, SnapSourceType const &source, long source_num, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &constrained_snap, bool const &fully_constrained, Geom::OptRect target_bbox = Geom::OptRect());
33 SnappedPoint(SnapCandidatePoint const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &constrained_snap, bool const &fully_constrained);
34 ~SnappedPoint();
36 Geom::Coord getSnapDistance() const {return _distance;}
37 void setSnapDistance(Geom::Coord const d) {_distance = d;}
38 Geom::Coord getTolerance() const {return _tolerance;}
39 bool getAlwaysSnap() const {return _always_snap;}
40 Geom::Coord getSecondSnapDistance() const {return _second_distance;}
41 void setSecondSnapDistance(Geom::Coord const d) {_second_distance = d;}
42 Geom::Coord getSecondTolerance() const {return _second_tolerance;}
43 bool getSecondAlwaysSnap() const {return _second_always_snap;}
44 Geom::Coord getPointerDistance() const {return _pointer_distance;}
45 void setPointerDistance(Geom::Coord const d) {_pointer_distance = d;}
47 /* This is the preferred method to find out which point we have snapped
48 * to, because it only returns a point if snapping has actually occurred
49 * (by overwriting p)
50 */
51 void getPointIfSnapped(Geom::Point &p) const;
53 /* This method however always returns a point, even if no snapping
54 * has occurred; A check should be implemented in the calling code
55 * to check for snapping. Use this method only when really needed, e.g.
56 * when the calling code is trying to snap multiple points and must
57 * determine itself which point is most appropriate, or when doing a
58 * constrainedSnap that also enforces projection onto the constraint (in
59 * which case you need the new point anyway, even if we didn't snap)
60 */
61 Geom::Point getPoint() const {return _point;}
62 void setPoint(Geom::Point const &p) {_point = p;}
64 bool getAtIntersection() const {return _at_intersection;}
65 bool getFullyConstrained() const {return _fully_constrained;}
66 bool getConstrainedSnap() const {return _constrained_snap;}
67 bool getSnapped() const {return _distance < NR_HUGE;}
68 Geom::Point getTransformation() const {return _transformation;}
69 void setTransformation(Geom::Point const t) {_transformation = t;}
70 void setTarget(SnapTargetType const target) {_target = target;}
71 SnapTargetType getTarget() const {return _target;}
72 void setTargetBBox(Geom::OptRect const target) {_target_bbox = target;}
73 Geom::OptRect const getTargetBBox() const {return _target_bbox;}
74 void setSource(SnapSourceType const source) {_source = source;}
75 SnapSourceType getSource() const {return _source;}
76 long getSourceNum() const {return _source_num;}
78 bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;
80 /*void dump() const {
81 std::cout << "_point = " << _point << std::endl;
82 std::cout << "_source = " << _source << std::endl;
83 std::cout << "_source_num = " << _source_num << std::endl;
84 std::cout << "_target = " << _target << std::endl;
85 std::cout << "_at_intersection = " << _at_intersection << std::endl;
86 std::cout << "_fully_constrained = " << _fully_constrained << std::endl;
87 std::cout << "_distance = " << _distance << std::endl;
88 std::cout << "_tolerance = " << _tolerance << std::endl;
89 std::cout << "_always_snap = " << _always_snap << std::endl;
90 std::cout << "_second_distance = " << _second_distance << std::endl;
91 std::cout << "_second_tolerance = " << _second_tolerance << std::endl;
92 std::cout << "_second_always_snap = " << _second_always_snap << std::endl;
93 std::cout << "_transformation = " << _transformation << std::endl;
94 std::cout << "_pointer_distance = " << _pointer_distance << std::endl;
95 }*/
97 protected:
98 Geom::Point _point; // Location of the snapped point
99 SnapSourceType _source; // Describes what snapped
100 long _source_num; // Sequence number of the source point that snapped, if that point is part of a set of points. (starting at zero if we might have a set of points; -1 if we only have a single point)
101 SnapTargetType _target; // Describes to what we've snapped to
102 bool _at_intersection; // If true, the snapped point is at an intersection
103 bool _constrained_snap; // If true, then the snapped point was found when looking for a constrained snap
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 farthest 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 /* The bounding box we've snapped to (when applicable); will be used by the snapindicator */
126 Geom::OptRect _target_bbox;
127 /* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */
128 Geom::Coord _pointer_distance;
129 };
131 }// end of namespace Inkscape
133 bool getClosestSP(std::list<Inkscape::SnappedPoint> const &list, Inkscape::SnappedPoint &result);
135 #endif /* !SEEN_SNAPPEDPOINT_H */
137 /*
138 Local Variables:
139 mode:c++
140 c-file-style:"stroustrup"
141 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
142 indent-tabs-mode:nil
143 fill-column:99
144 End:
145 */
146 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :