Code

Store the snapper tolerances in the snap-preferences instead of in each snapper indiv...
[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"
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                                   bool const &first_point,
73                                   Geom::OptRect const &bbox_to_snap,
74                                   std::vector<SPItem const *> const *it,
75                                   std::vector<Geom::Point> *unselected_nodes) const;
77         void constrainedSnap(SnappedConstraints &sc,
78                                   Inkscape::SnapPreferences::PointType const &t,
79                                   Geom::Point const &p,
80                                   bool const &first_point,
81                                   Geom::OptRect const &bbox_to_snap,
82                                   ConstraintLine const &c,
83                                   std::vector<SPItem const *> const *it) const;
85 private:
86     //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
87     std::vector<SnapCandidate> *_candidates;
88     std::vector<Geom::Point> *_points_to_snap_to;
89     std::vector<Geom::PathVector*> *_paths_to_snap_to;
91     void _findCandidates(SPObject* parent,
92                        std::vector<SPItem const *> const *it,
93                        bool const &first_point,
94                        Geom::Rect const &bbox_to_snap,
95                        DimensionToSnap snap_dim,
96                        bool const _clip_or_mask,
97                        Geom::Matrix const additional_affine) const;
99     void _snapNodes(SnappedConstraints &sc,
100                       Inkscape::SnapPreferences::PointType const &t,
101                       Geom::Point const &p, // in desktop coordinates
102                       bool const &first_point,
103                       std::vector<Geom::Point> *unselected_nodes) const; // in desktop coordinates
105     void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
106                      Inkscape::SnapPreferences::PointType const &t,
107                      Geom::Point const &p,
108                      Geom::Point const &guide_normal) const;
110     void _collectNodes(Inkscape::SnapPreferences::PointType const &t,
111                   bool const &first_point) const;
113     void _snapPaths(SnappedConstraints &sc,
114                       Inkscape::SnapPreferences::PointType const &t,
115                       Geom::Point const &p,     // in desktop coordinates
116                       bool const &first_point,
117                       std::vector<Geom::Point> *unselected_nodes, // in desktop coordinates
118                       SPPath const *selected_path) const;
120     void _snapPathsConstrained(SnappedConstraints &sc,
121                  Inkscape::SnapPreferences::PointType const &t,
122                  Geom::Point const &p, // in desktop coordinates
123                  bool const &first_point,
124                  ConstraintLine const &c) const;
126     bool isUnselectedNode(Geom::Point const &point, std::vector<Geom::Point> const *unselected_nodes) const;
128     void _collectPaths(Inkscape::SnapPreferences::PointType const &t,
129                   bool const &first_point) const;
131     void _clear_paths() const;
132     Geom::PathVector* _getBorderPathv() const;
133     Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const;
134     void _getBorderNodes(std::vector<Geom::Point> *points) const;
136 }; // end of ObjectSnapper class
138 void getBBoxPoints(Geom::OptRect const bbox, std::vector<Geom::Point> *points, bool const includeCorners, bool const includeLineMidpoints, bool const includeObjectMidpoints);
140 } // end of namespace Inkscape
142 #endif