Code

Make snapping to the item's transformation center optional, but not yet available...
[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>
25 #include "guide-snapper.h"
26 #include "object-snapper.h"
28 class SPNamedView;
30 /// Class to coordinate snapping operations
32 /**
33  *  Each SPNamedView has one of these.  It offers methods to snap points to whatever
34  *  snappers are defined (e.g. grid, guides etc.).  It also allows callers to snap
35  *  points which have undergone some transformation (e.g. translation, scaling etc.)
36  */
38 class SnapManager
39 {
40 public:
41     SnapManager(SPNamedView const *v);
43     typedef std::list<const Inkscape::Snapper*> SnapperList;
45     bool SomeSnapperMightSnap() const;
47     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
48                                     NR::Point const &p,
49                                     SPItem const *it) const;
51     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
52                                     NR::Point const &p,
53                                     std::list<SPItem const *> const &it) const;
55         Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
56                                       NR::Point const &p,
57                                       std::list<SPItem const *> const &it,
58                                       SnapperList const &snappers ) const;
60     Inkscape::SnappedPoint freeSnapAlways( Inkscape::Snapper::PointType t,
61                                            NR::Point const &p,
62                                            SPItem const *it,
63                                            SnapperList &snappers );
65     Inkscape::SnappedPoint freeSnapAlways( Inkscape::Snapper::PointType t,
66                                            NR::Point const &p,
67                                            std::list<SPItem const *> const &it,
68                                            SnapperList &snappers );
70     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
71                                            NR::Point const &p,
72                                            Inkscape::Snapper::ConstraintLine const &c,
73                                            SPItem const *it) const;
74     
75     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
76                                            NR::Point const &p,
77                                            Inkscape::Snapper::ConstraintLine const &c,
78                                            std::list<SPItem const *> const &it) const;
80     std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
81                                                    std::vector<NR::Point> const &p,
82                                                    std::list<SPItem const *> const &it,
83                                                    NR::Point const &tr) const;
85     std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
86                                                           std::vector<NR::Point> const &p,
87                                                           std::list<SPItem const *> const &it,
88                                                           Inkscape::Snapper::ConstraintLine const &c,
89                                                           NR::Point const &tr) const;
91     std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
92                                              std::vector<NR::Point> const &p,
93                                              std::list<SPItem const *> const &it,
94                                              NR::scale const &s,
95                                              NR::Point const &o) const;
97     std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
98                                                     std::vector<NR::Point> const &p,
99                                                     std::list<SPItem const *> const &it,
100                                                     Inkscape::Snapper::ConstraintLine const &c,
101                                                     NR::scale const &s,
102                                                     NR::Point const &o) const;
104     std::pair<NR::Coord, bool> freeSnapStretch(Inkscape::Snapper::PointType t,
105                                                std::vector<NR::Point> const &p,
106                                                std::list<SPItem const *> const &it,
107                                                NR::Coord const &s,
108                                                NR::Point const &o,
109                                                NR::Dim2 d,
110                                                bool uniform) const;
112     std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
113                                             std::vector<NR::Point> const &p,
114                                             std::list<SPItem const *> const &it,
115                                             NR::Coord const &s,
116                                             NR::Point const &o,
117                                             NR::Dim2 d) const;
119     Inkscape::GuideSnapper guide;      ///< guide snapper
120     Inkscape::ObjectSnapper object;    ///< snapper to other objects
122     SnapperList getSnappers() const;
123     SnapperList getGridSnappers() const;
124     
125     void setSnapModeBBox(bool enabled);
126     void setSnapModeNode(bool enabled);
127     bool getSnapModeBBox() const;
128     bool getSnapModeNode() const;
130         void setIncludeItemCenter(bool enabled) {
131                 _include_item_center = enabled;
132         }
133         
134         bool getIncludeItemCenter()     const {
135                 return _include_item_center;
136         }
137                 
138 protected:
139     SPNamedView const *_named_view;
141 private:
143     enum Transformation {
144         TRANSLATION,
145         SCALE,
146         STRETCH,
147         SKEW
148     };
149     
150     bool _include_item_center; //If true, snapping nodes will also snap the item's center
151     
152     std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
153                                                 std::vector<NR::Point> const &points,
154                                                 std::list<SPItem const *> const &ignore,
155                                                 bool constrained,
156                                                 Inkscape::Snapper::ConstraintLine const &constraint,
157                                                 Transformation transformation_type,
158                                                 NR::Point const &transformation,
159                                                 NR::Point const &origin,
160                                                 NR::Dim2 dim,
161                                                 bool uniform) const;
162 };
164 #endif /* !SEEN_SNAP_H */
166 /*
167   Local Variables:
168   mode:c++
169   c-file-style:"stroustrup"
170   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
171   indent-tabs-mode:nil
172   fill-column:99
173   End:
174 */
175 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :