Code

Groundwork to snap to intersections, e.g. intersections of gridlines with guidelines...
[inkscape.git] / src / object-snapper.h
1 #ifndef SEEN_OBJECT_SNAPPER_H
2 #define SEEN_OBJECT_SNAPPER_H
4 /**
5  *  \file object-snapper.h
6  *  \brief Snapping things to objects.
7  *
8  * Authors:
9  *   Carl Hetherington <inkscape@carlh.net>
10  *
11  * Copyright (C) 2005 Authors 
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #include "snapper.h"
17 #include "sp-path.h"
18 #include "splivarot.h"
20 struct SPNamedView;
21 struct SPItem;
22 struct SPObject;
24 namespace Inkscape
25 {
27 class ObjectSnapper : public Snapper
28 {
30 public:
31   ObjectSnapper(SPNamedView const *nv, NR::Coord const d);
32   ~ObjectSnapper();
34   enum DimensionToSnap {SNAP_X, SNAP_Y, SNAP_XY};
36   void setSnapToItemNode(bool s) {
37     _snap_to_itemnode = s;
38   }
40   bool getSnapToItemNode() const {
41     return _snap_to_itemnode;
42   }
44   void setSnapToItemPath(bool s) {
45     _snap_to_itempath = s;
46   }
48   bool getSnapToItemPath() const {
49     return _snap_to_itempath;
50   }
51   
52   void setSnapToBBoxNode(bool s) {
53     _snap_to_bboxnode = s;
54   }
56   bool getSnapToBBoxNode() const {
57     return _snap_to_bboxnode;
58   }
60   void setSnapToBBoxPath(bool s) {
61     _snap_to_bboxpath = s;
62   }
64   bool getSnapToBBoxPath() const {
65     return _snap_to_bboxpath;
66   }
67   
68   void setIncludeItemCenter(bool s) {
69     _include_item_center = s;
70   }
72   bool getIncludeItemCenter() const {
73     return _include_item_center;
74   }
75   
76   void setStrictSnapping(bool enabled) {
77         _strict_snapping = enabled;
78   }
79   
80   SnappedPoint guideSnap(NR::Point const &p,
81                                                  DimensionToSnap const snap_dim) const;
82   
83   bool ThisSnapperMightSnap() const;
84   
85 private:
86   //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
87   std::vector<SPItem*> *_candidates; 
88   std::vector<NR::Point> *_points_to_snap_to;
89   std::vector<Path*> *_paths_to_snap_to;
90   void _doFreeSnap(SnappedConstraints &sc,
91                                         Inkscape::Snapper::PointType const &t,
92                                         NR::Point const &p,
93                                         bool const &first_point,
94                     std::vector<NR::Point> &points_to_snap,
95                                         std::list<SPItem const *> const &it) const;
97   void _doConstrainedSnap(SnappedConstraints &sc,
98                                         Inkscape::Snapper::PointType const &t,
99                                         NR::Point const &p,
100                                         bool const &first_point,                                                                                
101                                         std::vector<NR::Point> &points_to_snap,
102                                         ConstraintLine const &c,
103                                         std::list<SPItem const *> const &it) const;
104                                 
105   void _findCandidates(SPObject* r,
106                                 std::list<SPItem const *> const &it,
107                                 bool const &first_point,
108                                 std::vector<NR::Point> &points_to_snap,
109                                 DimensionToSnap const snap_dim) const;
110   
111   bool _snapNodes(Inkscape::Snapper::PointType const &t,
112                                         Inkscape::SnappedPoint &s, 
113                                         NR::Point const &p, 
114                                         bool const &first_point,
115                                         DimensionToSnap const snap_dim) const;
116                                         
117   bool _snapPaths(Inkscape::Snapper::PointType const &t, 
118                                         Inkscape::SnappedPoint &s, 
119                                         NR::Point const &p,
120                                         bool const &first_point) const;
121   
122   bool _snap_to_itemnode;
123   bool _snap_to_itempath;
124   bool _snap_to_bboxnode;
125   bool _snap_to_bboxpath;
126   
127   //If enabled, then bbox corners will only snap to bboxes, 
128   //and nodes will only snap to nodes and paths. We will not
129   //snap bbox corners to nodes, or nodes to bboxes.
130   //(snapping to grids and guides is not affected by this)
131   bool _strict_snapping; 
132   bool _include_item_center;
133 };
137 #endif