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 - 2008 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"
22 struct SPNamedView;
23 struct SPItem;
24 struct SPObject;
26 namespace Inkscape
27 {
29 class ObjectSnapper : public Snapper
30 {
32 public:
33 ObjectSnapper(SPNamedView const *nv, NR::Coord const d);
34 ~ObjectSnapper();
36 enum DimensionToSnap {
37 GUIDE_TRANSL_SNAP_X, // For snapping a vertical guide (normal in the X-direction) to objects,
38 GUIDE_TRANSL_SNAP_Y, // For snapping a horizontal guide (normal in the Y-direction) to objects
39 ANGLED_GUIDE_TRANSL_SNAP, // For snapping an angled guide, while translating it accross the desktop
40 ANGLED_GUIDE_ROT_SNAP, // For snapping an angled guide, while rotating it around some pivot point
41 TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides
43 void setSnapToItemNode(bool s) {
44 _snap_to_itemnode = s;
45 }
47 bool getSnapToItemNode() const {
48 return _snap_to_itemnode;
49 }
51 void setSnapToItemPath(bool s) {
52 _snap_to_itempath = s;
53 }
55 bool getSnapToItemPath() const {
56 return _snap_to_itempath;
57 }
59 void setSnapToBBoxNode(bool s) {
60 _snap_to_bboxnode = s;
61 }
63 bool getSnapToBBoxNode() const {
64 return _snap_to_bboxnode;
65 }
67 void setSnapToBBoxPath(bool s) {
68 _snap_to_bboxpath = s;
69 }
71 bool getSnapToBBoxPath() const {
72 return _snap_to_bboxpath;
73 }
75 void setSnapToPageBorder(bool s) {
76 _snap_to_page_border = s;
77 }
79 bool getSnapToPageBorder() const {
80 return _snap_to_page_border;
81 }
83 void setIncludeItemCenter(bool s) {
84 _include_item_center = s;
85 }
87 bool getIncludeItemCenter() const {
88 return _include_item_center;
89 }
91 void setStrictSnapping(bool enabled) {
92 _strict_snapping = enabled;
93 }
95 void guideSnap(SnappedConstraints &sc,
96 NR::Point const &p,
97 NR::Point const &guide_normal) const;
99 bool ThisSnapperMightSnap() const;
100 bool GuidesMightSnap() const;
102 private:
103 //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
104 std::vector<SPItem*> *_candidates;
105 std::vector<NR::Point> *_points_to_snap_to;
106 std::vector<NArtBpath*> *_bpaths_to_snap_to;
107 std::vector<Path*> *_paths_to_snap_to;
109 void _doFreeSnap(SnappedConstraints &sc,
110 Inkscape::Snapper::PointType const &t,
111 NR::Point const &p,
112 bool const &first_point,
113 std::vector<NR::Point> &points_to_snap,
114 std::list<SPItem const *> const &it,
115 std::vector<NR::Point> *unselected_nodes) const;
117 void _doConstrainedSnap(SnappedConstraints &sc,
118 Inkscape::Snapper::PointType const &t,
119 NR::Point const &p,
120 bool const &first_point,
121 std::vector<NR::Point> &points_to_snap,
122 ConstraintLine const &c,
123 std::list<SPItem const *> const &it) const;
125 void _findCandidates(SPObject* r,
126 std::list<SPItem const *> const &it,
127 bool const &first_point,
128 std::vector<NR::Point> &points_to_snap,
129 DimensionToSnap snap_dim) const;
131 void _snapNodes(SnappedConstraints &sc,
132 Inkscape::Snapper::PointType const &t,
133 NR::Point const &p,
134 bool const &first_point,
135 std::vector<NR::Point> *unselected_nodes) const;
137 void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
138 Inkscape::Snapper::PointType const &t,
139 NR::Point const &p,
140 NR::Point const &guide_normal) const;
142 void _collectNodes(Inkscape::Snapper::PointType const &t,
143 bool const &first_point) const;
145 void _snapPaths(SnappedConstraints &sc,
146 Inkscape::Snapper::PointType const &t,
147 NR::Point const &p,
148 bool const &first_point,
149 std::vector<NR::Point> *unselected_nodes,
150 SPPath const *selected_path,
151 NArtBpath *border_bpath) const;
153 void _snapPathsConstrained(SnappedConstraints &sc,
154 Inkscape::Snapper::PointType const &t,
155 NR::Point const &p,
156 bool const &first_point,
157 ConstraintLine const &c) const;
158 bool isUnselectedNode(NR::Point const &point, std::vector<NR::Point> const *unselected_nodes) const;
160 void _collectPaths(Inkscape::Snapper::PointType const &t,
161 bool const &first_point,
162 NArtBpath *border_bpath = NULL) const;
164 void _clear_paths() const;
165 NArtBpath* _getBorderBPath() const;
167 bool _snap_to_itemnode;
168 bool _snap_to_itempath;
169 bool _snap_to_bboxnode;
170 bool _snap_to_bboxpath;
171 bool _snap_to_page_border;
173 //If enabled, then bbox corners will only snap to bboxes,
174 //and nodes will only snap to nodes and paths. We will not
175 //snap bbox corners to nodes, or nodes to bboxes.
176 //(snapping to grids and guides is not affected by this)
177 bool _strict_snapping;
178 bool _include_item_center;
179 };
181 }
183 #endif