Code

Store cached icons to disk between runs, and invalidate/purge as needed.
[inkscape.git] / src / snapped-point.h
index f8ef50ff361f873f92c44c6f2ef7986bba62a985..b2a9fa1ce02d7b2698c7beeeccbf9f479b673f69 100644 (file)
 
 #include <vector>
 #include <list>
-#include "libnr/nr-coord.h"
-#include "libnr/nr-point.h"
-#include <libnr/nr-values.h>
+#include <libnr/nr-values.h> //Because of NR_HUGE
+#include <2geom/geom.h>
+#include <snap-candidate.h>
 
 namespace Inkscape
 {
 
-enum SnapTargetType {
-    SNAPTARGET_UNDEFINED = 0,
-    SNAPTARGET_GRID,
-    SNAPTARGET_GRID_INTERSECTION,
-    SNAPTARGET_GUIDE,
-    SNAPTARGET_GUIDE_INTERSECTION,
-    SNAPTARGET_GRID_GUIDE_INTERSECTION,
-    SNAPTARGET_NODE_SMOOTH,
-    SNAPTARGET_NODE_CUSP,
-    SNAPTARGET_LINE_MIDPOINT,
-    SNAPTARGET_OBJECT_MIDPOINT,
-    SNAPTARGET_ROTATION_CENTER,
-    SNAPTARGET_HANDLE, //e.g. center of ellipse, corner of rectangle
-    SNAPTARGET_PATH,
-    SNAPTARGET_PATH_INTERSECTION,
-    SNAPTARGET_BBOX_CORNER,
-    SNAPTARGET_BBOX_EDGE,
-    SNAPTARGET_BBOX_EDGE_MIDPOINT,
-    SNAPTARGET_BBOX_MIDPOINT,
-    SNAPTARGET_GRADIENT,
-    SNAPTARGET_PAGE_BORDER,
-    SNAPTARGET_PAGE_CORNER,
-    SNAPTARGET_CONVEX_HULL_CORNER,
-    SNAPTARGET_ELLIPSE_QUADRANT_POINT,
-};
-
-enum SnapSourceType {
-    SNAPSOURCE_UNDEFINED = 0,
-    SNAPSOURCE_BBOX_CORNER,
-    SNAPSOURCE_BBOX_MIDPOINT,
-    SNAPSOURCE_BBOX_EDGE_MIDPOINT,
-    SNAPSOURCE_NODE_SMOOTH,
-    SNAPSOURCE_NODE_CUSP,
-    SNAPSOURCE_LINE_MIDPOINT,
-    SNAPSOURCE_OBJECT_MIDPOINT,
-    SNAPSOURCE_ROTATION_CENTER,
-    SNAPSOURCE_HANDLE,
-    SNAPSOURCE_PATH_INTERSECTION,
-    SNAPSOURCE_GUIDE,
-    SNAPSOURCE_CONVEX_HULL_CORNER,
-    SNAPSOURCE_ELLIPSE_QUADRANT_POINT
-};
-
-
 /// Class describing the result of an attempt to snap.
 class SnappedPoint
 {
 
 public:
     SnappedPoint();
-    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);
-    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);
+    SnappedPoint(Geom::Point const &p);
+    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 &constrained_snap, bool const &fully_constrained, Geom::Coord const &d2, Geom::Coord const &t2, bool const &a2);
+    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 &constrained_snap, bool const &fully_constrained, Geom::OptRect target_bbox = Geom::OptRect());
+    SnappedPoint(SnapCandidatePoint const &p, SnapTargetType const &target, Geom::Coord const &d, Geom::Coord const &t, bool const &a, bool const &constrained_snap, bool const &fully_constrained);
     ~SnappedPoint();
 
     Geom::Coord getSnapDistance() const {return _distance;}
@@ -90,31 +48,39 @@ public:
      * to, because it only returns a point if snapping has actually occurred
      * (by overwriting p)
      */
-    void getPoint(Geom::Point &p) const;
+    void getPointIfSnapped(Geom::Point &p) const;
 
     /* This method however always returns a point, even if no snapping
-     * has occured; A check should be implemented in the calling code
+     * has occurred; A check should be implemented in the calling code
      * to check for snapping. Use this method only when really needed, e.g.
      * when the calling code is trying to snap multiple points and must
-     * determine itself which point is most appropriate
+     * determine itself which point is most appropriate, or when doing a
+     * constrainedSnap that also enforces projection onto the constraint (in
+     * which case you need the new point anyway, even if we didn't snap)
      */
     Geom::Point getPoint() const {return _point;}
+    void setPoint(Geom::Point const &p) {_point = p;}
 
     bool getAtIntersection() const {return _at_intersection;}
     bool getFullyConstrained() const {return _fully_constrained;}
+    bool getConstrainedSnap() const {return _constrained_snap;}
     bool getSnapped() const {return _distance < NR_HUGE;}
     Geom::Point getTransformation() const {return _transformation;}
     void setTransformation(Geom::Point const t) {_transformation = t;}
     void setTarget(SnapTargetType const target) {_target = target;}
     SnapTargetType getTarget() const {return _target;}
+    void setTargetBBox(Geom::OptRect const target) {_target_bbox = target;}
+    Geom::OptRect const getTargetBBox() const {return _target_bbox;}
     void setSource(SnapSourceType const source) {_source = source;}
-       SnapSourceType getSource() const {return _source;}
+    SnapSourceType getSource() const {return _source;}
+    long getSourceNum() const {return _source_num;}
 
     bool isOtherSnapBetter(SnappedPoint const &other_one, bool weighted) const;
 
     /*void dump() const {
         std::cout << "_point              = " << _point << std::endl;
         std::cout << "_source             = " << _source << std::endl;
+        std::cout << "_source_num         = " << _source_num << std::endl;
         std::cout << "_target             = " << _target << std::endl;
         std::cout << "_at_intersection    = " << _at_intersection << std::endl;
         std::cout << "_fully_constrained  = " << _fully_constrained << std::endl;
@@ -131,8 +97,10 @@ public:
 protected:
     Geom::Point _point; // Location of the snapped point
     SnapSourceType _source; // Describes what snapped
+    long _source_num; // Sequence number of the source point that snapped, if that point is part of a set of points. (starting at zero if we might have a set of points; -1 if we only have a single point)
     SnapTargetType _target; // Describes to what we've snapped to
     bool _at_intersection; // If true, the snapped point is at an intersection
+    bool _constrained_snap; // If true, then the snapped point was found when looking for a constrained snap
     bool _fully_constrained; // When snapping for example to a node, then the snap will be "fully constrained".
                             // When snapping to a line however, the snap is only partly constrained (i.e. only in one dimension)
 
@@ -146,7 +114,7 @@ protected:
     bool _always_snap;
 
     /* If the snapped point is at an intersection of e.g. two lines, then this is
-       the distance to the fartest line */
+       the distance to the farthest line */
     Geom::Coord _second_distance;
     /* The snapping tolerance in screen pixels (depends on zoom)*/
     Geom::Coord _second_tolerance;
@@ -154,13 +122,15 @@ protected:
     bool _second_always_snap;
     /* The transformation (translation, scale, skew, or stretch) from the original point to the snapped point */
     Geom::Point _transformation;
+    /* The bounding box we've snapped to (when applicable); will be used by the snapindicator */
+    Geom::OptRect _target_bbox;
     /* Distance from the un-transformed point to the mouse pointer, measured at the point in time when dragging started */
     Geom::Coord _pointer_distance;
 };
 
 }// end of namespace Inkscape
 
-bool getClosestSP(std::list<Inkscape::SnappedPoint> &list, Inkscape::SnappedPoint &result);
+bool getClosestSP(std::list<Inkscape::SnappedPoint> const &list, Inkscape::SnappedPoint &result);
 
 #endif /* !SEEN_SNAPPEDPOINT_H */