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