Code

The snap indicator's tooltip now displays "A to B", whereas before it only displayed...
[inkscape.git] / src / snapped-point.h
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 = 0,
26     SNAPTARGET_GRID,
27     SNAPTARGET_GRID_INTERSECTION,
28     SNAPTARGET_GUIDE,
29     SNAPTARGET_GUIDE_INTERSECTION,
30     SNAPTARGET_GRID_GUIDE_INTERSECTION,
31     SNAPTARGET_NODE_SMOOTH,
32     SNAPTARGET_NODE_CUSP,
33     SNAPTARGET_LINE_MIDPOINT,
34     SNAPTARGET_OBJECT_MIDPOINT,
35     SNAPTARGET_ROTATION_CENTER,
36     SNAPTARGET_HANDLE, //e.g. center of ellipse, corner of rectangle
37     SNAPTARGET_PATH,
38     SNAPTARGET_PATH_INTERSECTION,
39     SNAPTARGET_BBOX_CORNER,
40     SNAPTARGET_BBOX_EDGE,
41     SNAPTARGET_BBOX_EDGE_MIDPOINT,
42     SNAPTARGET_BBOX_MIDPOINT,
43     SNAPTARGET_GRADIENT,
44     SNAPTARGET_PAGE_BORDER,
45     SNAPTARGET_PAGE_CORNER,
46     SNAPTARGET_CONVEX_HULL_CORNER,
47     SNAPTARGET_ELLIPSE_QUADRANT_POINT,
48 };
50 enum SnapSourceType {
51     SNAPSOURCE_UNDEFINED = 0,
52     SNAPSOURCE_BBOX_CORNER,
53     SNAPSOURCE_BBOX_MIDPOINT,
54     SNAPSOURCE_BBOX_EDGE_MIDPOINT,
55     SNAPSOURCE_NODE_SMOOTH,
56     SNAPSOURCE_NODE_CUSP,
57     SNAPSOURCE_LINE_MIDPOINT,
58     SNAPSOURCE_OBJECT_MIDPOINT,
59     SNAPSOURCE_ROTATION_CENTER,
60     SNAPSOURCE_HANDLE,
61     SNAPSOURCE_PATH_INTERSECTION,
62     SNAPSOURCE_GUIDE,
63     SNAPSOURCE_CONVEX_HULL_CORNER,
64     SNAPSOURCE_ELLIPSE_QUADRANT_POINT
65 };
68 /// Class describing the result of an attempt to snap.
69 class SnappedPoint
70 {
72 public:
73     SnappedPoint();
74     SnappedPoint(Geom::Point const &p, SnapSourceType const &source, 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);
75     SnappedPoint(Geom::Point const &p, SnapSourceType const &source, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &fully_constrained);
76     ~SnappedPoint();
78     Geom::Coord getSnapDistance() const {return _distance;}
79     void setSnapDistance(Geom::Coord const d) {_distance = d;}
80     Geom::Coord getTolerance() const {return _tolerance;}
81     bool getAlwaysSnap() const {return _always_snap;}
82     Geom::Coord getSecondSnapDistance() const {return _second_distance;}
83     void setSecondSnapDistance(Geom::Coord const d) {_second_distance = d;}
84     Geom::Coord getSecondTolerance() const {return _second_tolerance;}
85     bool getSecondAlwaysSnap() const {return _second_always_snap;}
86     Geom::Coord getPointerDistance() const {return _pointer_distance;}
87     void setPointerDistance(Geom::Coord const d) {_pointer_distance = d;}
89     /* This is the preferred method to find out which point we have snapped
90      * to, because it only returns a point if snapping has actually occurred
91      * (by overwriting p)
92      */
93     void getPoint(Geom::Point &p) const;
95     /* This method however always returns a point, even if no snapping
96      * has occured; A check should be implemented in the calling code
97      * to check for snapping. Use this method only when really needed, e.g.
98      * when the calling code is trying to snap multiple points and must
99      * determine itself which point is most appropriate
100      */
101     Geom::Point getPoint() const {return _point;}
103     bool getAtIntersection() const {return _at_intersection;}
104     bool getFullyConstrained() const {return _fully_constrained;}
105     bool getSnapped() const {return _distance < NR_HUGE;}
106     Geom::Point getTransformation() const {return _transformation;}
107     void setTransformation(Geom::Point const t) {_transformation = t;}
108     void setTarget(SnapTargetType const target) {_target = target;}
109     SnapTargetType getTarget() const {return _target;}
110     void setSource(SnapSourceType const source) {_source = source;}
111         SnapSourceType getSource() const {return _source;}
113     bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;
115     /*void dump() const {
116         std::cout << "_point              = " << _point << std::endl;
117         std::cout << "_source             = " << _source << std::endl;
118         std::cout << "_target             = " << _target << std::endl;
119         std::cout << "_at_intersection    = " << _at_intersection << std::endl;
120         std::cout << "_fully_constrained  = " << _fully_constrained << std::endl;
121         std::cout << "_distance           = " << _distance << std::endl;
122         std::cout << "_tolerance          = " << _tolerance << std::endl;
123         std::cout << "_always_snap        = " << _always_snap << std::endl;
124         std::cout << "_second_distance    = " << _second_distance << std::endl;
125         std::cout << "_second_tolerance   = " << _second_tolerance << std::endl;
126         std::cout << "_second_always_snap = " << _second_always_snap << std::endl;
127         std::cout << "_transformation     = " << _transformation << std::endl;
128         std::cout << "_pointer_distance   = " << _pointer_distance << std::endl;
129     }*/
131 protected:
132     Geom::Point _point; // Location of the snapped point
133     SnapSourceType _source; // Describes what snapped
134     SnapTargetType _target; // Describes to what we've snapped to
135     bool _at_intersection; // If true, the snapped point is at an intersection
136     bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained".
137                             // When snapping to a line however, the snap is only partly constrained (i.e. only in one dimension)
139     /* Distance from original point to snapped point. If the snapped point is at
140        an intersection of e.g. two lines, then this is the distance to the closest
141        line */
142     Geom::Coord _distance;
143     /* The snapping tolerance in screen pixels (depends on zoom)*/
144     Geom::Coord _tolerance;
145     /* If true then "Always snap" is on */
146     bool _always_snap;
148     /* If the snapped point is at an intersection of e.g. two lines, then this is
149        the distance to the fartest line */
150     Geom::Coord _second_distance;
151     /* The snapping tolerance in screen pixels (depends on zoom)*/
152     Geom::Coord _second_tolerance;
153     /* If true then "Always snap" is on */
154     bool _second_always_snap;
155     /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
156     Geom::Point _transformation;
157     /* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */
158     Geom::Coord _pointer_distance;
159 };
161 }// end of namespace Inkscape
163 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
165 #endif /* !SEEN_SNAPPEDPOINT_H */
167 /*
168   Local Variables:
169   mode:c++
170   c-file-style:"stroustrup"
171   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
172   indent-tabs-mode:nil
173   fill-column:99
174   End:
175 */
176 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :