556ff86def386cea8f02ab3a6facb54e9e6e3627
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 ConstraintLine const &c) const;
51 bool ThisSnapperMightSnap() const;
52 bool GuidesMightSnap() const;
54 Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
55 bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance
57 void freeSnap(SnappedConstraints &sc,
58 Inkscape::SnapPreferences::PointType const &t,
59 Inkscape::SnapCandidatePoint const &p,
60 Geom::OptRect const &bbox_to_snap,
61 std::vector<SPItem const *> const *it,
62 std::vector<SnapCandidatePoint> *unselected_nodes) const;
64 void constrainedSnap(SnappedConstraints &sc,
65 Inkscape::SnapPreferences::PointType const &t,
66 Inkscape::SnapCandidatePoint const &p,
67 Geom::OptRect const &bbox_to_snap,
68 ConstraintLine const &c,
69 std::vector<SPItem const *> const *it) const;
71 private:
72 //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
73 std::vector<SnapCandidateItem> *_candidates;
74 std::vector<SnapCandidatePoint> *_points_to_snap_to;
75 std::vector<SnapCandidatePath > *_paths_to_snap_to;
77 void _findCandidates(SPObject* parent,
78 std::vector<SPItem const *> const *it,
79 bool const &first_point,
80 Geom::Rect const &bbox_to_snap,
81 DimensionToSnap snap_dim,
82 bool const _clip_or_mask,
83 Geom::Matrix const additional_affine) const;
85 void _snapNodes(SnappedConstraints &sc,
86 Inkscape::SnapPreferences::PointType const &t,
87 Inkscape::SnapCandidatePoint const &p,
88 std::vector<SnapCandidatePoint> *unselected_nodes) const; // in desktop coordinates
90 void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
91 Inkscape::SnapPreferences::PointType const &t,
92 Geom::Point const &p,
93 Geom::Point const &guide_normal) const;
95 void _collectNodes(Inkscape::SnapPreferences::PointType const &t,
96 bool const &first_point) const;
98 void _snapPaths(SnappedConstraints &sc,
99 Inkscape::SnapPreferences::PointType const &t,
100 Inkscape::SnapCandidatePoint const &p, // in desktop coordinates
101 std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes, // in desktop coordinates
102 SPPath const *selected_path) const;
104 void _snapPathsConstrained(SnappedConstraints &sc,
105 Inkscape::SnapPreferences::PointType const &t,
106 Inkscape::SnapCandidatePoint const &p, // in desktop coordinates
107 ConstraintLine const &c) const;
109 bool isUnselectedNode(Geom::Point const &point, std::vector<Inkscape::SnapCandidatePoint> const *unselected_nodes) const;
111 void _collectPaths(Inkscape::SnapPreferences::PointType const &t,
112 bool const &first_point) const;
114 void _clear_paths() const;
115 Geom::PathVector* _getBorderPathv() const;
116 Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const;
117 void _getBorderNodes(std::vector<SnapCandidatePoint> *points) const;
119 }; // end of ObjectSnapper class
121 void getBBoxPoints(Geom::OptRect const bbox, std::vector<SnapCandidatePoint> *points, bool const isTarget, bool const includeCorners, bool const includeLineMidpoints, bool const includeObjectMidpoints);
123 } // end of namespace Inkscape
125 #endif