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"
20 #include "snap-candidate.h"
22 struct SPNamedView;
23 struct SPItem;
24 struct SPObject;
26 namespace Inkscape
27 {
29 class ObjectSnapper : public Snapper
30 {
32 public:
33 ObjectSnapper(SnapManager *sm, Geom::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 TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides
42 void guideFreeSnap(SnappedConstraints &sc,
43 Geom::Point const &p,
44 Geom::Point const &guide_normal) const;
46 void guideConstrainedSnap(SnappedConstraints &sc,
47 Geom::Point const &p,
48 Geom::Point const &guide_normal,
49 SnapConstraint const &c) const;
51 bool ThisSnapperMightSnap() const;
53 Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
54 bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance
56 void freeSnap(SnappedConstraints &sc,
57 Inkscape::SnapCandidatePoint const &p,
58 Geom::OptRect const &bbox_to_snap,
59 std::vector<SPItem const *> const *it,
60 std::vector<SnapCandidatePoint> *unselected_nodes) const;
62 void constrainedSnap(SnappedConstraints &sc,
63 Inkscape::SnapCandidatePoint const &p,
64 Geom::OptRect const &bbox_to_snap,
65 SnapConstraint const &c,
66 std::vector<SPItem const *> const *it) const;
68 private:
69 //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
70 std::vector<SnapCandidateItem> *_candidates;
71 std::vector<SnapCandidatePoint> *_points_to_snap_to;
72 std::vector<SnapCandidatePath > *_paths_to_snap_to;
74 void _findCandidates(SPObject* parent,
75 std::vector<SPItem const *> const *it,
76 bool const &first_point,
77 Geom::Rect const &bbox_to_snap,
78 DimensionToSnap snap_dim,
79 bool const _clip_or_mask,
80 Geom::Matrix const additional_affine) const;
82 void _snapNodes(SnappedConstraints &sc,
83 Inkscape::SnapCandidatePoint const &p,
84 std::vector<SnapCandidatePoint> *unselected_nodes) const; // in desktop coordinates
86 void _snapTranslatingGuide(SnappedConstraints &sc,
87 Geom::Point const &p,
88 Geom::Point const &guide_normal) const;
90 void _collectNodes(Inkscape::SnapSourceType const &t,
91 bool const &first_point) const;
93 void _snapPaths(SnappedConstraints &sc,
94 Inkscape::SnapCandidatePoint const &p, // in desktop coordinates
95 std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes, // in desktop coordinates
96 SPPath const *selected_path) const;
98 void _snapPathsConstrained(SnappedConstraints &sc,
99 Inkscape::SnapCandidatePoint const &p, // in desktop coordinates
100 SnapConstraint const &c) const;
102 bool isUnselectedNode(Geom::Point const &point, std::vector<Inkscape::SnapCandidatePoint> const *unselected_nodes) const;
104 void _collectPaths(Inkscape::SnapCandidatePoint const &p,
105 bool const &first_point) const;
107 void _clear_paths() const;
108 Geom::PathVector* _getBorderPathv() const;
109 Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const;
110 void _getBorderNodes(std::vector<SnapCandidatePoint> *points) const;
112 }; // end of ObjectSnapper class
114 void getBBoxPoints(Geom::OptRect const bbox, std::vector<SnapCandidatePoint> *points, bool const isTarget, bool const includeCorners, bool const includeLineMidpoints, bool const includeObjectMidpoints);
116 } // end of namespace Inkscape
118 #endif