Code

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