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 &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 &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 &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 getPoint(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
58 */
59 Geom::Point getPoint() const {return _point;}
60 void setPoint(Geom::Point const &p) {_point = p;}
62 bool getAtIntersection() const {return _at_intersection;}
63 bool getFullyConstrained() const {return _fully_constrained;}
64 bool getSnapped() const {return _distance < NR_HUGE;}
65 Geom::Point getTransformation() const {return _transformation;}
66 void setTransformation(Geom::Point const t) {_transformation = t;}
67 void setTarget(SnapTargetType const target) {_target = target;}
68 SnapTargetType getTarget() const {return _target;}
69 void setTargetBBox(Geom::OptRect const target) {_target_bbox = target;}
70 Geom::OptRect const getTargetBBox() const {return _target_bbox;}
71 void setSource(SnapSourceType const source) {_source = source;}
72 SnapSourceType getSource() const {return _source;}
73 long getSourceNum() const {return _source_num;}
75 bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;
77 /*void dump() const {
78 std::cout << "_point = " << _point << std::endl;
79 std::cout << "_source = " << _source << std::endl;
80 std::cout << "_source_num = " << _source_num << std::endl;
81 std::cout << "_target = " << _target << std::endl;
82 std::cout << "_at_intersection = " << _at_intersection << std::endl;
83 std::cout << "_fully_constrained = " << _fully_constrained << std::endl;
84 std::cout << "_distance = " << _distance << std::endl;
85 std::cout << "_tolerance = " << _tolerance << std::endl;
86 std::cout << "_always_snap = " << _always_snap << std::endl;
87 std::cout << "_second_distance = " << _second_distance << std::endl;
88 std::cout << "_second_tolerance = " << _second_tolerance << std::endl;
89 std::cout << "_second_always_snap = " << _second_always_snap << std::endl;
90 std::cout << "_transformation = " << _transformation << std::endl;
91 std::cout << "_pointer_distance = " << _pointer_distance << std::endl;
92 }*/
94 protected:
95 Geom::Point _point; // Location of the snapped point
96 SnapSourceType _source; // Describes what snapped
97 long _source_num; // Sequence number of the source point that snapped, if that point is part of a set of points. (starting at zero)
98 SnapTargetType _target; // Describes to what we've snapped to
99 bool _at_intersection; // If true, the snapped point is at an intersection
100 bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained".
101 // When snapping to a line however, the snap is only partly constrained (i.e. only in one dimension)
103 /* Distance from original point to snapped point. If the snapped point is at
104 an intersection of e.g. two lines, then this is the distance to the closest
105 line */
106 Geom::Coord _distance;
107 /* The snapping tolerance in screen pixels (depends on zoom)*/
108 Geom::Coord _tolerance;
109 /* If true then "Always snap" is on */
110 bool _always_snap;
112 /* If the snapped point is at an intersection of e.g. two lines, then this is
113 the distance to the farthest line */
114 Geom::Coord _second_distance;
115 /* The snapping tolerance in screen pixels (depends on zoom)*/
116 Geom::Coord _second_tolerance;
117 /* If true then "Always snap" is on */
118 bool _second_always_snap;
119 /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
120 Geom::Point _transformation;
121 /* The bounding box we've snapped to (when applicable); will be used by the snapindicator */
122 Geom::OptRect _target_bbox;
123 /* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */
124 Geom::Coord _pointer_distance;
125 };
127 }// end of namespace Inkscape
129 bool getClosestSP(std::list<Inkscape::SnappedPoint> const &list, Inkscape::SnappedPoint &result);
131 #endif /* !SEEN_SNAPPEDPOINT_H */
133 /*
134 Local Variables:
135 mode:c++
136 c-file-style:"stroustrup"
137 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
138 indent-tabs-mode:nil
139 fill-column:99
140 End:
141 */
142 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :