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 void freeSnap(SnappedConstraints &sc,
67 Inkscape::SnapPreferences::PointType const &t,
68 Geom::Point const &p,
69 bool const &first_point,
70 Geom::OptRect const &bbox_to_snap,
71 std::vector<SPItem const *> const *it,
72 std::vector<Geom::Point> *unselected_nodes) const;
74 void constrainedSnap(SnappedConstraints &sc,
75 Inkscape::SnapPreferences::PointType const &t,
76 Geom::Point const &p,
77 bool const &first_point,
78 Geom::OptRect const &bbox_to_snap,
79 ConstraintLine const &c,
80 std::vector<SPItem const *> const *it) const;
82 private:
83 //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
84 std::vector<SnapCandidate> *_candidates;
85 std::vector<Geom::Point> *_points_to_snap_to;
86 std::vector<Geom::PathVector*> *_paths_to_snap_to;
88 void _findCandidates(SPObject* parent,
89 std::vector<SPItem const *> const *it,
90 bool const &first_point,
91 Geom::Rect const &bbox_to_snap,
92 DimensionToSnap snap_dim,
93 bool const _clip_or_mask,
94 Geom::Matrix const additional_affine) const;
96 void _snapNodes(SnappedConstraints &sc,
97 Inkscape::SnapPreferences::PointType const &t,
98 Geom::Point const &p, // in desktop coordinates
99 bool const &first_point,
100 std::vector<Geom::Point> *unselected_nodes) const; // in desktop coordinates
102 void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
103 Inkscape::SnapPreferences::PointType const &t,
104 Geom::Point const &p,
105 Geom::Point const &guide_normal) const;
107 void _collectNodes(Inkscape::SnapPreferences::PointType const &t,
108 bool const &first_point) const;
110 void _snapPaths(SnappedConstraints &sc,
111 Inkscape::SnapPreferences::PointType const &t,
112 Geom::Point const &p, // in desktop coordinates
113 bool const &first_point,
114 std::vector<Geom::Point> *unselected_nodes, // in desktop coordinates
115 SPPath const *selected_path) const;
117 void _snapPathsConstrained(SnappedConstraints &sc,
118 Inkscape::SnapPreferences::PointType const &t,
119 Geom::Point const &p, // in desktop coordinates
120 bool const &first_point,
121 ConstraintLine const &c) const;
123 bool isUnselectedNode(Geom::Point const &point, std::vector<Geom::Point> const *unselected_nodes) const;
125 void _collectPaths(Inkscape::SnapPreferences::PointType const &t,
126 bool const &first_point) const;
128 void _clear_paths() const;
129 Geom::PathVector* _getBorderPathv() const;
130 Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const;
131 void _getBorderNodes(std::vector<Geom::Point> *points) const;
133 }; // end of ObjectSnapper class
135 void getBBoxPoints(Geom::OptRect const bbox, std::vector<Geom::Point> *points, bool const includeCorners, bool const includeLineMidpoints, bool const includeObjectMidpoints);
137 } // end of namespace Inkscape
139 #endif