b9d90deaec045110fd0ebc63dcc2061b23a94cac
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"
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 {
36 GUIDE_TRANSL_SNAP_X, // For snapping a vertical guide (normal in the X-direction) to objects,
37 GUIDE_TRANSL_SNAP_Y, // For snapping a horizontal guide (normal in the Y-direction) to objects
38 ANGLED_GUIDE_TRANSL_SNAP, // For snapping an angled guide, while translating it accross the desktop
39 ANGLED_GUIDE_ROT_SNAP, // For snapping an angled guide, while rotating it around some pivot point
40 TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides
42 void setSnapToItemNode(bool s) {
43 _snap_to_itemnode = s;
44 }
46 bool getSnapToItemNode() const {
47 return _snap_to_itemnode;
48 }
50 void setSnapToItemPath(bool s) {
51 _snap_to_itempath = s;
52 }
54 bool getSnapToItemPath() const {
55 return _snap_to_itempath;
56 }
58 void setSnapToBBoxNode(bool s) {
59 _snap_to_bboxnode = s;
60 }
62 bool getSnapToBBoxNode() const {
63 return _snap_to_bboxnode;
64 }
66 void setSnapToBBoxPath(bool s) {
67 _snap_to_bboxpath = s;
68 }
70 bool getSnapToBBoxPath() const {
71 return _snap_to_bboxpath;
72 }
74 void setSnapToPageBorder(bool s) {
75 _snap_to_page_border = s;
76 }
78 bool getSnapToPageBorder() const {
79 return _snap_to_page_border;
80 }
82 void setIncludeItemCenter(bool s) {
83 _include_item_center = s;
84 }
86 bool getIncludeItemCenter() const {
87 return _include_item_center;
88 }
90 void setStrictSnapping(bool enabled) {
91 _strict_snapping = enabled;
92 }
94 void guideSnap(SnappedConstraints &sc,
95 NR::Point const &p,
96 NR::Point const &guide_normal) const;
98 bool ThisSnapperMightSnap() const;
99 bool GuidesMightSnap() const;
101 private:
102 //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
103 std::vector<SPItem*> *_candidates;
104 std::vector<NR::Point> *_points_to_snap_to;
105 std::vector<NArtBpath*> *_bpaths_to_snap_to;
106 std::vector<Path*> *_paths_to_snap_to;
108 void _doFreeSnap(SnappedConstraints &sc,
109 Inkscape::Snapper::PointType const &t,
110 NR::Point const &p,
111 bool const &first_point,
112 std::vector<NR::Point> &points_to_snap,
113 std::list<SPItem const *> const &it,
114 std::vector<NR::Point> *unselected_nodes) const;
116 void _doConstrainedSnap(SnappedConstraints &sc,
117 Inkscape::Snapper::PointType const &t,
118 NR::Point const &p,
119 bool const &first_point,
120 std::vector<NR::Point> &points_to_snap,
121 ConstraintLine const &c,
122 std::list<SPItem const *> const &it) const;
124 void _findCandidates(SPObject* r,
125 std::list<SPItem const *> const &it,
126 bool const &first_point,
127 std::vector<NR::Point> &points_to_snap,
128 DimensionToSnap const snap_dim) const;
130 void _snapNodes(SnappedConstraints &sc,
131 Inkscape::Snapper::PointType const &t,
132 NR::Point const &p,
133 bool const &first_point,
134 std::vector<NR::Point> *unselected_nodes) const;
136 void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
137 Inkscape::Snapper::PointType const &t,
138 NR::Point const &p,
139 NR::Point const &guide_normal) const;
141 void _collectNodes(Inkscape::Snapper::PointType const &t,
142 bool const &first_point) const;
144 void _snapPaths(SnappedConstraints &sc,
145 Inkscape::Snapper::PointType const &t,
146 NR::Point const &p,
147 bool const &first_point,
148 std::vector<NR::Point> *unselected_nodes,
149 SPPath const *selected_path,
150 NArtBpath *border_bpath) const;
152 void _snapPathsConstrained(SnappedConstraints &sc,
153 Inkscape::Snapper::PointType const &t,
154 NR::Point const &p,
155 bool const &first_point,
156 ConstraintLine const &c) const;
157 bool isUnselectedNode(NR::Point const &point, std::vector<NR::Point> const *unselected_nodes) const;
159 void _collectPaths(Inkscape::Snapper::PointType const &t,
160 bool const &first_point,
161 NArtBpath *border_bpath = NULL) const;
163 void _clear_paths() const;
164 NArtBpath* _getBorderBPath() const;
166 bool _snap_to_itemnode;
167 bool _snap_to_itempath;
168 bool _snap_to_bboxnode;
169 bool _snap_to_bboxpath;
170 bool _snap_to_page_border;
172 //If enabled, then bbox corners will only snap to bboxes,
173 //and nodes will only snap to nodes and paths. We will not
174 //snap bbox corners to nodes, or nodes to bboxes.
175 //(snapping to grids and guides is not affected by this)
176 bool _strict_snapping;
177 bool _include_item_center;
178 };
180 }
182 #endif