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 }
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 }
69 void setIncludeItemCenter(bool s) {
70 _include_item_center = s;
71 }
73 bool getIncludeItemCenter() const {
74 return _include_item_center;
75 }
77 void setStrictSnapping(bool enabled) {
78 _strict_snapping = enabled;
79 }
81 SnappedPoint guideSnap(NR::Point const &p,
82 DimensionToSnap const snap_dim) const;
84 bool ThisSnapperMightSnap() const;
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::vector<SPItem*> *_candidates;
89 std::vector<NR::Point> *_points_to_snap_to;
90 std::vector<Path*> *_paths_to_snap_to;
91 SnappedPoint _doFreeSnap(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 SnappedPoint _doConstrainedSnap(Inkscape::Snapper::PointType const &t,
98 NR::Point const &p,
99 bool const &first_point,
100 std::vector<NR::Point> &points_to_snap,
101 ConstraintLine const &c,
102 std::list<SPItem const *> const &it) const;
104 void _findCandidates(SPObject* r,
105 std::list<SPItem const *> const &it,
106 bool const &first_point,
107 std::vector<NR::Point> &points_to_snap,
108 DimensionToSnap const snap_dim) const;
110 void _snapNodes(Inkscape::Snapper::PointType const &t,
111 Inkscape::SnappedPoint &s,
112 NR::Point const &p,
113 bool const &first_point,
114 DimensionToSnap const snap_dim) const;
116 void _snapPaths(Inkscape::Snapper::PointType const &t,
117 Inkscape::SnappedPoint &s,
118 NR::Point const &p,
119 bool const &first_point) const;
121 bool _snap_to_itemnode;
122 bool _snap_to_itempath;
123 bool _snap_to_bboxnode;
124 bool _snap_to_bboxpath;
126 //If enabled, then bbox corners will only snap to bboxes,
127 //and nodes will only snap to nodes and paths. We will not
128 //snap bbox corners to nodes, or nodes to bboxes.
129 //(snapping to grids and guides is not affected by this)
130 bool _strict_snapping;
131 bool _include_item_center;
132 };
134 }
136 #endif