Code

hack*ahum*infrastructure to implement axonometric grid snapping. horizontal snapping...
[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      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 "grid-snapper.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);
43     
44     bool willSnapSomething() const;
46     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
47                                     NR::Point const &p,
48                                     SPItem const *it) const;
50     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
51                                     NR::Point const &p,
52                                     std::list<SPItem const *> const &it) const;
53     
54     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
55                                            NR::Point const &p,
56                                            Inkscape::Snapper::ConstraintLine const &c,
57                                            SPItem const *it) const;
58     
59     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
60                                            NR::Point const &p,
61                                            Inkscape::Snapper::ConstraintLine const &c,
62                                            std::list<SPItem const *> const &it) const;
64     std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
65                                                    std::vector<NR::Point> const &p,
66                                                    std::list<SPItem const *> const &it,
67                                                    NR::Point const &tr) const;
69     std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
70                                                           std::vector<NR::Point> const &p,
71                                                           std::list<SPItem const *> const &it,
72                                                           Inkscape::Snapper::ConstraintLine const &c,
73                                                           NR::Point const &tr) const;
75     std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
76                                              std::vector<NR::Point> const &p,
77                                              std::list<SPItem const *> const &it,
78                                              NR::scale const &s,
79                                              NR::Point const &o) const;
81     std::pair<NR::scale, bool> constrainedSnapScale(Inkscape::Snapper::PointType t,
82                                                     std::vector<NR::Point> const &p,
83                                                     std::list<SPItem const *> const &it,
84                                                     Inkscape::Snapper::ConstraintLine const &c,
85                                                     NR::scale const &s,
86                                                     NR::Point const &o) const;
88     std::pair<NR::Coord, bool> freeSnapStretch(Inkscape::Snapper::PointType t,
89                                                std::vector<NR::Point> const &p,
90                                                std::list<SPItem const *> const &it,
91                                                NR::Coord const &s,
92                                                NR::Point const &o,
93                                                NR::Dim2 d,
94                                                bool uniform) const;
96     std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
97                                             std::vector<NR::Point> const &p,
98                                             std::list<SPItem const *> const &it,
99                                             NR::Coord const &s,
100                                             NR::Point const &o,
101                                             NR::Dim2 d) const;
103     Inkscape::GridSnapper grid;        ///< grid snapper
104     Inkscape::AxonomGridSnapper axonomgrid;  ///< axonometricgrid snapper
105     Inkscape::GuideSnapper guide;      ///< guide snapper
106     Inkscape::ObjectSnapper object;    ///< snapper to other objects
108     typedef std::list<const Inkscape::Snapper*> SnapperList;
109     SnapperList getSnappers() const;
111 protected:
112     SPNamedView const *_named_view;
114 private:
116     enum Transformation {
117         TRANSLATION,
118         SCALE,
119         STRETCH,
120         SKEW
121     };
122     
123     std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
124                                                 std::vector<NR::Point> const &points,
125                                                 std::list<SPItem const *> const &ignore,
126                                                 bool constrained,
127                                                 Inkscape::Snapper::ConstraintLine const &constraint,
128                                                 Transformation transformation_type,
129                                                 NR::Point const &transformation,
130                                                 NR::Point const &origin,
131                                                 NR::Dim2 dim,
132                                                 bool uniform) const;
133 };
135 #endif /* !SEEN_SNAP_H */
137 /*
138   Local Variables:
139   mode:c++
140   c-file-style:"stroustrup"
141   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
142   indent-tabs-mode:nil
143   fill-column:99
144   End:
145 */
146 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :