Code

- try to use more forward declarations for less dependencies on display/curve.h
[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(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a, bool const &at_intersection, NR::Coord const &d2, NR::Coord const &t2, bool const &a2);
46     SnappedPoint(NR::Point const &p, SnapTargetType const &target, NR::Coord const &d, NR::Coord const &t, bool const &a);
47     ~SnappedPoint();
49     NR::Coord getDistance() const;
50     void setDistance(NR::Coord const d) {_distance = d;}
51     NR::Coord getTolerance() const;
52     bool getAlwaysSnap() const;
53     NR::Coord getSecondDistance() const;
54     NR::Coord getSecondTolerance() const;
55     bool getSecondAlwaysSnap() const;
56     NR::Point getPoint() const;
57     bool getAtIntersection() const {return _at_intersection;}
58     bool getSnapped() const {return _distance < NR_HUGE;}
59     NR::Point getTransformation() const {return _transformation;}
60     void setTransformation(NR::Point const t) {_transformation = t;}
61     void setTarget(SnapTargetType const target) {_target = target;}
62     SnapTargetType getTarget() {return _target;}
63     
64 protected:
65     NR::Point _point; // Location of the snapped point
66     SnapTargetType _target; // Describes to what we've snapped to
67     bool _at_intersection; // If true, the snapped point is at an intersection 
68     
69     /* Distance from original point to snapped point. If the snapped point is at
70        an intersection of e.g. two lines, then this is the distance to the closest
71        line */    
72     NR::Coord _distance; 
73     /* The snapping tolerance in screen pixels (depends on zoom)*/  
74     NR::Coord _tolerance;
75     /* If true then "Always snap" is on */
76     bool _always_snap;
77     
78     /* If the snapped point is at an intersection of e.g. two lines, then this is
79        the distance to the fartest line */    
80     NR::Coord _second_distance;
81     /* The snapping tolerance in screen pixels (depends on zoom)*/
82     NR::Coord _second_tolerance;
83     /* If true then "Always snap" is on */
84     bool _second_always_snap;
85     /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
86     NR::Point _transformation;
87 };    
89 }
91 bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
94 #endif /* !SEEN_SNAPPEDPOINT_H */
96 /*
97   Local Variables:
98   mode:c++
99   c-file-style:"stroustrup"
100   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
101   indent-tabs-mode:nil
102   fill-column:99
103   End:
104 */
105 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :