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;
107 void _doFreeSnap(SnappedConstraints &sc,
108 Inkscape::Snapper::PointType const &t,
109 NR::Point const &p,
110 bool const &first_point,
111 std::vector<NR::Point> &points_to_snap,
112 std::list<SPItem const *> const &it,
113 std::vector<NR::Point> *unselected_nodes) const;
115 void _doConstrainedSnap(SnappedConstraints &sc,
116 Inkscape::Snapper::PointType const &t,
117 NR::Point const &p,
118 bool const &first_point,
119 std::vector<NR::Point> &points_to_snap,
120 ConstraintLine const &c,
121 std::list<SPItem const *> const &it) const;
123 void _findCandidates(SPObject* r,
124 std::list<SPItem const *> const &it,
125 bool const &first_point,
126 std::vector<NR::Point> &points_to_snap,
127 DimensionToSnap const snap_dim) const;
129 void _snapNodes(SnappedConstraints &sc,
130 Inkscape::Snapper::PointType const &t,
131 NR::Point const &p,
132 bool const &first_point,
133 std::vector<NR::Point> *unselected_nodes) const;
135 void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
136 Inkscape::Snapper::PointType const &t,
137 NR::Point const &p,
138 NR::Point const &guide_normal) const;
140 void _collectNodes(Inkscape::Snapper::PointType const &t,
141 bool const &first_point) const;
143 void _snapPaths(SnappedConstraints &sc,
144 Inkscape::Snapper::PointType const &t,
145 NR::Point const &p,
146 bool const &first_point,
147 std::vector<NR::Point> *unselected_nodes,
148 SPPath const *selected_path,
149 NArtBpath *border_bpath) const;
151 void _snapPathsConstrained(SnappedConstraints &sc,
152 Inkscape::Snapper::PointType const &t,
153 NR::Point const &p,
154 bool const &first_point,
155 ConstraintLine const &c) const;
156 bool isUnselectedNode(NR::Point const &point, std::vector<NR::Point> const *unselected_nodes) const;
158 void _collectPaths(Inkscape::Snapper::PointType const &t,
159 bool const &first_point,
160 SPPath const *selected_path = NULL,
161 NArtBpath *border_bpath = NULL) const;
162 void _clear_paths() const;
163 NArtBpath* _getBorderBPath() const;
165 bool _snap_to_itemnode;
166 bool _snap_to_itempath;
167 bool _snap_to_bboxnode;
168 bool _snap_to_bboxpath;
169 bool _snap_to_page_border;
171 //If enabled, then bbox corners will only snap to bboxes,
172 //and nodes will only snap to nodes and paths. We will not
173 //snap bbox corners to nodes, or nodes to bboxes.
174 //(snapping to grids and guides is not affected by this)
175 bool _strict_snapping;
176 bool _include_item_center;
177 };
179 }
181 #endif