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 SnapCandidate
30 {
31 public:
32 SnapCandidate(SPItem* item, bool clip_or_mask, Geom::Matrix _additional_affine);
33 ~SnapCandidate();
35 SPItem* item; // An item that is to be considered for snapping to
36 bool clip_or_mask; // If true, then item refers to a clipping path or a mask
38 /* To find out the absolute position of a clipping path or mask, we not only need to know
39 * the transformation of the clipping path or mask itself, but also the transformation of
40 * the object to which the clip or mask is being applied; that transformation is stored here
41 */
42 Geom::Matrix additional_affine;
43 };
45 class ObjectSnapper : public Snapper
46 {
48 public:
49 ObjectSnapper(SnapManager *sm, Geom::Coord const d);
50 ~ObjectSnapper();
52 enum DimensionToSnap {
53 GUIDE_TRANSL_SNAP_X, // For snapping a vertical guide (normal in the X-direction) to objects,
54 GUIDE_TRANSL_SNAP_Y, // For snapping a horizontal guide (normal in the Y-direction) to objects
55 ANGLED_GUIDE_TRANSL_SNAP, // For snapping an angled guide, while translating it accross the desktop
56 ANGLED_GUIDE_ROT_SNAP, // For snapping an angled guide, while rotating it around some pivot point
57 TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides
59 void guideSnap(SnappedConstraints &sc,
60 Geom::Point const &p,
61 Geom::Point const &guide_normal) const;
63 bool ThisSnapperMightSnap() const;
64 bool GuidesMightSnap() const;
66 Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
67 bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance
69 void freeSnap(SnappedConstraints &sc,
70 Inkscape::SnapPreferences::PointType const &t,
71 Geom::Point const &p,
72 SnapSourceType const &source_type,
73 bool const &first_point,
74 Geom::OptRect const &bbox_to_snap,
75 std::vector<SPItem const *> const *it,
76 std::vector<std::pair<Geom::Point, int> > *unselected_nodes) const;
78 void constrainedSnap(SnappedConstraints &sc,
79 Inkscape::SnapPreferences::PointType const &t,
80 Geom::Point const &p,
81 SnapSourceType const &source_type,
82 bool const &first_point,
83 Geom::OptRect const &bbox_to_snap,
84 ConstraintLine const &c,
85 std::vector<SPItem const *> const *it) 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<SnapCandidate> *_candidates;
90 std::vector<std::pair<Geom::Point, int> > *_points_to_snap_to;
91 std::vector<std::pair<Geom::PathVector*, SnapTargetType> > *_paths_to_snap_to;
93 void _findCandidates(SPObject* parent,
94 std::vector<SPItem const *> const *it,
95 bool const &first_point,
96 Geom::Rect const &bbox_to_snap,
97 DimensionToSnap snap_dim,
98 bool const _clip_or_mask,
99 Geom::Matrix const additional_affine) const;
101 void _snapNodes(SnappedConstraints &sc,
102 Inkscape::SnapPreferences::PointType const &t,
103 Geom::Point const &p, // in desktop coordinates
104 SnapSourceType const &source_type,
105 bool const &first_point,
106 std::vector<std::pair<Geom::Point, int> > *unselected_nodes) const; // in desktop coordinates
108 void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
109 Inkscape::SnapPreferences::PointType const &t,
110 Geom::Point const &p,
111 Geom::Point const &guide_normal) const;
113 void _collectNodes(Inkscape::SnapPreferences::PointType const &t,
114 bool const &first_point) const;
116 void _snapPaths(SnappedConstraints &sc,
117 Inkscape::SnapPreferences::PointType const &t,
118 Geom::Point const &p, // in desktop coordinates
119 SnapSourceType const &source_type,
120 bool const &first_point,
121 std::vector<std::pair<Geom::Point, int> > *unselected_nodes, // in desktop coordinates
122 SPPath const *selected_path) const;
124 void _snapPathsConstrained(SnappedConstraints &sc,
125 Inkscape::SnapPreferences::PointType const &t,
126 Geom::Point const &p, // in desktop coordinates
127 SnapSourceType const source_type,
128 bool const &first_point,
129 ConstraintLine const &c) const;
131 bool isUnselectedNode(Geom::Point const &point, std::vector<std::pair<Geom::Point, int> > const *unselected_nodes) const;
133 void _collectPaths(Inkscape::SnapPreferences::PointType const &t,
134 bool const &first_point) const;
136 void _clear_paths() const;
137 Geom::PathVector* _getBorderPathv() const;
138 Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const;
139 void _getBorderNodes(std::vector<std::pair<Geom::Point, int> > *points) const;
141 }; // end of ObjectSnapper class
143 void getBBoxPoints(Geom::OptRect const bbox, std::vector<std::pair<Geom::Point, int> > *points, bool const isTarget, bool const includeCorners, bool const includeLineMidpoints, bool const includeObjectMidpoints);
145 } // end of namespace Inkscape
147 #endif