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) {_snap_to_itemnode = s;}
44 bool getSnapToItemNode() const {return _snap_to_itemnode;}
45 void setSnapToItemPath(bool s) {_snap_to_itempath = s;}
46 bool getSnapToItemPath() const {return _snap_to_itempath;}
47 void setSnapToBBoxNode(bool s) {_snap_to_bboxnode = s;}
48 bool getSnapToBBoxNode() const {return _snap_to_bboxnode;}
49 void setSnapToBBoxPath(bool s) {_snap_to_bboxpath = s;}
50 bool getSnapToBBoxPath() const {return _snap_to_bboxpath;}
51 void setSnapToPageBorder(bool s) {_snap_to_page_border = s;}
52 bool getSnapToPageBorder() const {return _snap_to_page_border;}
53 void setIncludeItemCenter(bool s) {_include_item_center = s;}
54 bool getIncludeItemCenter() const {return _include_item_center;}
55 void setStrictSnapping(bool enabled) {_strict_snapping = enabled;}
57 void guideSnap(SnappedConstraints &sc,
58 NR::Point const &p,
59 NR::Point const &guide_normal) const;
61 bool ThisSnapperMightSnap() const;
62 bool GuidesMightSnap() const;
64 void freeSnap(SnappedConstraints &sc,
65 Inkscape::Snapper::PointType const &t,
66 NR::Point const &p,
67 bool const &first_point,
68 NR::Maybe<NR::Rect> const &bbox_to_snap,
69 std::vector<SPItem const *> const *it,
70 std::vector<NR::Point> *unselected_nodes) const;
72 void constrainedSnap(SnappedConstraints &sc,
73 Inkscape::Snapper::PointType const &t,
74 NR::Point const &p,
75 bool const &first_point,
76 NR::Maybe<NR::Rect> const &bbox_to_snap,
77 ConstraintLine const &c,
78 std::vector<SPItem const *> const *it) const;
80 private:
81 //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
82 std::vector<SPItem*> *_candidates;
83 std::vector<NR::Point> *_points_to_snap_to;
84 std::vector<NArtBpath*> *_bpaths_to_snap_to;
85 std::vector<Path*> *_paths_to_snap_to;
87 void _findCandidates(SPObject* r,
88 std::vector<SPItem const *> const *it,
89 bool const &first_point,
90 NR::Rect const &bbox_to_snap,
91 DimensionToSnap snap_dim) const;
93 void _snapNodes(SnappedConstraints &sc,
94 Inkscape::Snapper::PointType const &t,
95 NR::Point const &p,
96 bool const &first_point,
97 std::vector<NR::Point> *unselected_nodes) const;
99 void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
100 Inkscape::Snapper::PointType const &t,
101 NR::Point const &p,
102 NR::Point const &guide_normal) const;
104 void _collectNodes(Inkscape::Snapper::PointType const &t,
105 bool const &first_point) const;
107 void _snapPaths(SnappedConstraints &sc,
108 Inkscape::Snapper::PointType const &t,
109 NR::Point const &p,
110 bool const &first_point,
111 std::vector<NR::Point> *unselected_nodes,
112 SPPath const *selected_path,
113 NArtBpath const *border_bpath) const;
115 void _snapPathsConstrained(SnappedConstraints &sc,
116 Inkscape::Snapper::PointType const &t,
117 NR::Point const &p,
118 bool const &first_point,
119 ConstraintLine const &c) const;
121 bool isUnselectedNode(NR::Point const &point, std::vector<NR::Point> const *unselected_nodes) const;
123 void _collectPaths(Inkscape::Snapper::PointType const &t,
124 bool const &first_point,
125 NArtBpath const *border_bpath = NULL) const;
127 void _clear_paths() const;
128 NArtBpath const* _getBorderBPath() const;
130 bool _snap_to_itemnode;
131 bool _snap_to_itempath;
132 bool _snap_to_bboxnode;
133 bool _snap_to_bboxpath;
134 bool _snap_to_page_border;
136 //If enabled, then bbox corners will only snap to bboxes,
137 //and nodes will only snap to nodes and paths. We will not
138 //snap bbox corners to nodes, or nodes to bboxes.
139 //(snapping to grids and guides is not affected by this)
140 bool _strict_snapping;
141 bool _include_item_center;
142 };
144 }
146 #endif