Code

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