c16b42580fdf692d2d3c3776e1aedcb8a1fda350
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 * Diederik van Lierop <mail@diedenrezi.nl>
11 *
12 * Copyright (C) 2005 - 2007 Authors
13 *
14 * Released under GNU GPL, read the file 'COPYING' for more information
15 */
17 #include "snapper.h"
18 #include "sp-path.h"
19 #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 void guideSnap(SnappedConstraints &sc,
82 NR::Point const &p,
83 DimensionToSnap const snap_dim) const;
85 bool ThisSnapperMightSnap() const;
87 private:
88 //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
89 std::vector<SPItem*> *_candidates;
90 std::vector<NR::Point> *_points_to_snap_to;
91 std::vector<NArtBpath*> *_bpaths_to_snap_to;
92 std::vector<Path*> *_paths_to_snap_to;
93 void _doFreeSnap(SnappedConstraints &sc,
94 Inkscape::Snapper::PointType const &t,
95 NR::Point const &p,
96 bool const &first_point,
97 std::vector<NR::Point> &points_to_snap,
98 std::list<SPItem const *> const &it) const;
100 void _doConstrainedSnap(SnappedConstraints &sc,
101 Inkscape::Snapper::PointType const &t,
102 NR::Point const &p,
103 bool const &first_point,
104 std::vector<NR::Point> &points_to_snap,
105 ConstraintLine const &c,
106 std::list<SPItem const *> const &it) const;
108 void _findCandidates(SPObject* r,
109 std::list<SPItem const *> const &it,
110 bool const &first_point,
111 std::vector<NR::Point> &points_to_snap,
112 DimensionToSnap const snap_dim) const;
114 void _snapNodes(SnappedConstraints &sc,
115 Inkscape::Snapper::PointType const &t,
116 NR::Point const &p,
117 bool const &first_point,
118 DimensionToSnap const snap_dim) const;
120 void _collectNodes(Inkscape::Snapper::PointType const &t,
121 bool const &first_point) const;
123 void _snapPaths(SnappedConstraints &sc,
124 Inkscape::Snapper::PointType const &t,
125 NR::Point const &p,
126 bool const &first_point) const;
128 void _snapPathsConstrained(SnappedConstraints &sc,
129 Inkscape::Snapper::PointType const &t,
130 NR::Point const &p,
131 bool const &first_point,
132 ConstraintLine const &c) const;
134 void _collectPaths(Inkscape::Snapper::PointType const &t,
135 bool const &first_point) const;
136 void _clear_paths() const;
138 bool _snap_to_itemnode;
139 bool _snap_to_itempath;
140 bool _snap_to_bboxnode;
141 bool _snap_to_bboxpath;
143 //If enabled, then bbox corners will only snap to bboxes,
144 //and nodes will only snap to nodes and paths. We will not
145 //snap bbox corners to nodes, or nodes to bboxes.
146 //(snapping to grids and guides is not affected by this)
147 bool _strict_snapping;
148 bool _include_item_center;
149 };
151 }
153 #endif