Code

Fixed signed/unsigned problem with precision calc. Fixes bug #399604.
[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                 TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides
58         void guideFreeSnap(SnappedConstraints &sc,
59                                    Geom::Point const &p,
60                                    Geom::Point const &guide_normal) const;
62         void guideConstrainedSnap(SnappedConstraints &sc,
63                                            Geom::Point const &p,
64                                            Geom::Point const &guide_normal,
65                                            ConstraintLine const &c) const;
67         bool ThisSnapperMightSnap() const;
68         bool GuidesMightSnap() const;
70         Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
71         bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance
73         void freeSnap(SnappedConstraints &sc,
74                                   Inkscape::SnapPreferences::PointType const &t,
75                                   Geom::Point const &p,
76                                   SnapSourceType const &source_type,
77                                   bool const &first_point,
78                                   Geom::OptRect const &bbox_to_snap,
79                                   std::vector<SPItem const *> const *it,
80                                   std::vector<std::pair<Geom::Point, int> > *unselected_nodes) const;
82         void constrainedSnap(SnappedConstraints &sc,
83                                   Inkscape::SnapPreferences::PointType const &t,
84                                   Geom::Point const &p,
85                                   SnapSourceType const &source_type,
86                                   bool const &first_point,
87                                   Geom::OptRect const &bbox_to_snap,
88                                   ConstraintLine const &c,
89                                   std::vector<SPItem const *> const *it) const;
91 private:
92     //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
93     std::vector<SnapCandidate> *_candidates;
94     std::vector<std::pair<Geom::Point, int> > *_points_to_snap_to;
95     std::vector<std::pair<Geom::PathVector*, SnapTargetType> > *_paths_to_snap_to;
97     void _findCandidates(SPObject* parent,
98                        std::vector<SPItem const *> const *it,
99                        bool const &first_point,
100                        Geom::Rect const &bbox_to_snap,
101                        DimensionToSnap snap_dim,
102                        bool const _clip_or_mask,
103                        Geom::Matrix const additional_affine) const;
105     void _snapNodes(SnappedConstraints &sc,
106                       Inkscape::SnapPreferences::PointType const &t,
107                       Geom::Point const &p, // in desktop coordinates
108                       SnapSourceType const &source_type,
109                       bool const &first_point,
110                       std::vector<std::pair<Geom::Point, int> > *unselected_nodes) const; // in desktop coordinates
112     void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
113                      Inkscape::SnapPreferences::PointType const &t,
114                      Geom::Point const &p,
115                      Geom::Point const &guide_normal) const;
117     void _collectNodes(Inkscape::SnapPreferences::PointType const &t,
118                   bool const &first_point) const;
120     void _snapPaths(SnappedConstraints &sc,
121                       Inkscape::SnapPreferences::PointType const &t,
122                       Geom::Point const &p,     // in desktop coordinates
123                       SnapSourceType const &source_type,
124                       bool const &first_point,
125                       std::vector<std::pair<Geom::Point, int> > *unselected_nodes, // in desktop coordinates
126                       SPPath const *selected_path) const;
128     void _snapPathsConstrained(SnappedConstraints &sc,
129                  Inkscape::SnapPreferences::PointType const &t,
130                  Geom::Point const &p, // in desktop coordinates
131                  SnapSourceType const source_type,
132                                  bool const &first_point,
133                  ConstraintLine const &c) const;
135     bool isUnselectedNode(Geom::Point const &point, std::vector<std::pair<Geom::Point, int> > const *unselected_nodes) const;
137     void _collectPaths(Inkscape::SnapPreferences::PointType const &t,
138                   bool const &first_point) const;
140     void _clear_paths() const;
141     Geom::PathVector* _getBorderPathv() const;
142     Geom::PathVector* _getPathvFromRect(Geom::Rect const rect) const;
143     void _getBorderNodes(std::vector<std::pair<Geom::Point, int> > *points) const;
145 }; // end of ObjectSnapper class
147 void getBBoxPoints(Geom::OptRect const bbox, std::vector<std::pair<Geom::Point, int> > *points, bool const isTarget, bool const includeCorners, bool const includeLineMidpoints, bool const includeObjectMidpoints);
149 } // end of namespace Inkscape
151 #endif