Code

b0084c2d77fc0478238a7c73e34563781b1c7dfa
[inkscape.git] / src / object-snapper.h
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;
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::SnapCandidatePoint const &p,
59                   Geom::OptRect const &bbox_to_snap,
60                   std::vector<SPItem const *> const *it,
61                   std::vector<SnapCandidatePoint> *unselected_nodes) const;
63     void constrainedSnap(SnappedConstraints &sc,
64                   Inkscape::SnapCandidatePoint const &p,
65                   Geom::OptRect const &bbox_to_snap,
66                   SnapConstraint const &c,
67                   std::vector<SPItem const *> const *it) const;
69 private:
70     //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
71     std::vector<SnapCandidateItem> *_candidates;
72     std::vector<SnapCandidatePoint> *_points_to_snap_to;
73     std::vector<SnapCandidatePath > *_paths_to_snap_to;
75     void _findCandidates(SPObject* parent,
76                        std::vector<SPItem const *> const *it,
77                        bool const &first_point,
78                        Geom::Rect const &bbox_to_snap,
79                        DimensionToSnap snap_dim,
80                        bool const _clip_or_mask,
81                        Geom::Matrix const additional_affine) const;
83     void _snapNodes(SnappedConstraints &sc,
84                       Inkscape::SnapCandidatePoint const &p,
85                       std::vector<SnapCandidatePoint> *unselected_nodes) const; // in desktop coordinates
87     void _snapTranslatingGuide(SnappedConstraints &sc,
88                      Geom::Point const &p,
89                      Geom::Point const &guide_normal) const;
91     void _collectNodes(Inkscape::SnapSourceType const &t,
92                   bool const &first_point) const;
94     void _snapPaths(SnappedConstraints &sc,
95                       Inkscape::SnapCandidatePoint const &p, // in desktop coordinates
96                       std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes, // in desktop coordinates
97                       SPPath const *selected_path) const;
99     void _snapPathsConstrained(SnappedConstraints &sc,
100                  Inkscape::SnapCandidatePoint const &p, // in desktop coordinates
101                  SnapConstraint const &c) const;
103     bool isUnselectedNode(Geom::Point const &point, std::vector<Inkscape::SnapCandidatePoint> const *unselected_nodes) const;
105     void _collectPaths(Inkscape::SnapCandidatePoint const &p,
106                   bool const &first_point) const;
108     void _clear_paths() const;
109     Geom::PathVector* _getBorderPathv() const;
110     Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const;
111     void _getBorderNodes(std::vector<SnapCandidatePoint> *points) const;
113 }; // end of ObjectSnapper class
115 void getBBoxPoints(Geom::OptRect const bbox, std::vector<SnapCandidatePoint> *points, bool const isTarget, bool const includeCorners, bool const includeLineMidpoints, bool const includeObjectMidpoints);
117 } // end of namespace Inkscape
119 #endif