Code

Improving the performance of the object snapper
[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"
21 struct SPNamedView;
22 struct SPItem;
23 struct SPObject;
25 namespace Inkscape
26 {
28 class ObjectSnapper : public Snapper
29 {
31 public:
32   ObjectSnapper(SPNamedView const *nv, NR::Coord const d);
33   ~ObjectSnapper();
35   enum DimensionToSnap {SNAP_X, SNAP_Y, SNAP_XY};
37   void setSnapToItemNode(bool s) {
38     _snap_to_itemnode = s;
39   }
41   bool getSnapToItemNode() const {
42     return _snap_to_itemnode;
43   }
45   void setSnapToItemPath(bool s) {
46     _snap_to_itempath = s;
47   }
49   bool getSnapToItemPath() const {
50     return _snap_to_itempath;
51   }
52   
53   void setSnapToBBoxNode(bool s) {
54     _snap_to_bboxnode = s;
55   }
57   bool getSnapToBBoxNode() const {
58     return _snap_to_bboxnode;
59   }
61   void setSnapToBBoxPath(bool s) {
62     _snap_to_bboxpath = s;
63   }
65   bool getSnapToBBoxPath() const {
66     return _snap_to_bboxpath;
67   }
68   
69   void setIncludeItemCenter(bool s) {
70     _include_item_center = s;
71   }
73   bool getIncludeItemCenter() const {
74     return _include_item_center;
75   }
76   
77   void setStrictSnapping(bool enabled) {
78         _strict_snapping = enabled;
79   }
80   
81   SnappedPoint guideSnap(NR::Point const &p,
82                                                  DimensionToSnap const snap_dim) const;
83   
84   bool ThisSnapperMightSnap() const;
85   
86 private:
87   //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
88   std::list<SPItem*> *_candidates; 
89   std::list<NR::Point> *_points_to_snap_to;
90   std::list<Path*> *_paths_to_snap_to;
91   
92   SnappedPoint _doFreeSnap(Inkscape::Snapper::PointType const &t,
93                                         NR::Point const &p,
94                                         bool const &first_point,
95                     std::vector<NR::Point> &points_to_snap,
96                                         std::list<SPItem const *> const &it) const;
98   SnappedPoint _doConstrainedSnap(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   void _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   void _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