Code

Oops, don't use tabs! (replace tabs by 4 spaces)
[inkscape.git] / src / snap.h
1 #ifndef SEEN_SNAP_H
2 #define SEEN_SNAP_H
4 /**
5  * \file snap.h
6  * \brief SnapManager class.
7  *
8  * Authors:
9  *   Lauris Kaplinski <lauris@kaplinski.com>
10  *   Frank Felfe <innerspace@iname.com>
11  *   Carl Hetherington <inkscape@carlh.net>
12  *
13  * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
14  * Copyright (C) 2000-2002 Lauris Kaplinski
15  *
16  * Released under GNU GPL, read the file 'COPYING' for more information
17  */
19 #include <vector>
21 #include <libnr/nr-coord.h>
22 #include <libnr/nr-dim2.h>
23 #include <libnr/nr-forward.h>
24 #include <libnr/nr-scale.h>
26 #include "guide-snapper.h"
27 #include "object-snapper.h"
29 class SPNamedView;
31 /// Class to coordinate snapping operations
33 /**
34  *  Each SPNamedView has one of these.  It offers methods to snap points to whatever
35  *  snappers are defined (e.g. grid, guides etc.).  It also allows callers to snap
36  *  points which have undergone some transformation (e.g. translation, scaling etc.)
37  */
39 class SnapManager
40 {
41 public:
42     SnapManager(SPNamedView const *v);
44     typedef std::list<const Inkscape::Snapper*> SnapperList;
46     bool SomeSnapperMightSnap() const;
48     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
49                                     NR::Point const &p,
50                                     SPItem const *it) const;
52     Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
53                                       NR::Point const &p,
54                                       bool const &first_point,
55                                       std::vector<NR::Point> &points_to_snap,
56                                       std::list<SPItem const *> const &it) const;
58     Inkscape::SnappedPoint freeSnapAlways( Inkscape::Snapper::PointType t,
59                                            NR::Point const &p,
60                                            SPItem const *it,
61                                            SnapperList &snappers );
63     Inkscape::SnappedPoint freeSnapAlways( Inkscape::Snapper::PointType t,
64                                            NR::Point const &p,
65                                            std::list<SPItem const *> const &it,
66                                            SnapperList &snappers );
68     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
69                                            NR::Point const &p,
70                                            Inkscape::Snapper::ConstraintLine const &c,
71                                            SPItem const *it) const;
72     
73     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
74                                            NR::Point const &p,
75                                            bool const &first_point,
76                                            std::vector<NR::Point> &points_to_snap,
77                                            Inkscape::Snapper::ConstraintLine const &c,
78                                            std::list<SPItem const *> const &it) const;
79                                            
80     Inkscape::SnappedPoint guideSnap(NR::Point const &p,
81                                      NR::Point const &guide_normal) const;
83     std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
84                                                    std::vector<NR::Point> const &p,
85                                                    std::list<SPItem const *> const &it,
86                                                    NR::Point const &tr) const;
88     std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
89                                                           std::vector<NR::Point> const &p,
90                                                           std::list<SPItem const *> const &it,
91                                                           Inkscape::Snapper::ConstraintLine const &c,
92                                                           NR::Point const &tr) const;
94     std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
95                                              std::vector<NR::Point> const &p,
96                                              std::list<SPItem const *> const &it,
97                                              NR::scale const &s,
98                                              NR::Point const &o) const;
100     std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
101                                                     std::vector<NR::Point> const &p,
102                                                     std::list<SPItem const *> const &it,
103                                                     Inkscape::Snapper::ConstraintLine const &c,
104                                                     NR::scale const &s,
105                                                     NR::Point const &o) const;
107     std::pair<NR::Coord, bool> freeSnapStretch(Inkscape::Snapper::PointType t,
108                                                std::vector<NR::Point> const &p,
109                                                std::list<SPItem const *> const &it,
110                                                NR::Coord const &s,
111                                                NR::Point const &o,
112                                                NR::Dim2 d,
113                                                bool uniform) const;
115     std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
116                                             std::vector<NR::Point> const &p,
117                                             std::list<SPItem const *> const &it,
118                                             NR::Coord const &s,
119                                             NR::Point const &o,
120                                             NR::Dim2 d) const;
122     Inkscape::GuideSnapper guide;      ///< guide snapper
123     Inkscape::ObjectSnapper object;    ///< snapper to other objects
125     SnapperList getSnappers() const;
126     SnapperList getGridSnappers() const;
127     
128     void setSnapModeBBox(bool enabled);
129     void setSnapModeNode(bool enabled);
130     void setSnapModeGuide(bool enabled);
131     bool getSnapModeBBox() const;
132     bool getSnapModeNode() const;
133     bool getSnapModeGuide() const;
135     void setIncludeItemCenter(bool enabled)    {
136         _include_item_center = enabled;
137         object.setIncludeItemCenter(enabled);     //store a local copy in the object-snapper
138                                                 //instead of passing it through many functions 
139     }
140     
141     bool getIncludeItemCenter() const {
142         return _include_item_center;
143     }
144         
145 protected:
146     SPNamedView const *_named_view;
148 private:
150     enum Transformation {
151         TRANSLATION,
152         SCALE,
153         STRETCH,
154         SKEW
155     };
156     
157     bool _include_item_center; //If true, snapping nodes will also snap the item's center
158     
159     std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
160                                                 std::vector<NR::Point> const &points,
161                                                 std::list<SPItem const *> const &ignore,
162                                                 bool constrained,
163                                                 Inkscape::Snapper::ConstraintLine const &constraint,
164                                                 Transformation transformation_type,
165                                                 NR::Point const &transformation,
166                                                 NR::Point const &origin,
167                                                 NR::Dim2 dim,
168                                                 bool uniform) const;
169                                                 
170     Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc) const;
171 };
173 #endif /* !SEEN_SNAP_H */
175 /*
176   Local Variables:
177   mode:c++
178   c-file-style:"stroustrup"
179   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
180   indent-tabs-mode:nil
181   fill-column:99
182   End:
183 */
184 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :