Code

Adding axis detection to new input dialog
[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  *   Diederik van Lierop <mail@diedenrezi.nl>
13  *
14  * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
15  * Copyright (C) 2000-2002 Lauris Kaplinski
16  *
17  * Released under GNU GPL, read the file 'COPYING' for more information
18  */
20 #include <vector>
22 #include <libnr/nr-coord.h>
23 #include <libnr/nr-dim2.h>
24 #include <libnr/nr-forward.h>
25 #include <libnr/nr-scale.h>
27 #include "guide-snapper.h"
28 #include "object-snapper.h"
30 class SPNamedView;
32 /// Class to coordinate snapping operations
34 /**
35  *  Each SPNamedView has one of these.  It offers methods to snap points to whatever
36  *  snappers are defined (e.g. grid, guides etc.).  It also allows callers to snap
37  *  points which have undergone some transformation (e.g. translation, scaling etc.)
38  */
40 class SnapManager
41 {
42 public:
43     SnapManager(SPNamedView const *v);
45     typedef std::list<const Inkscape::Snapper*> SnapperList;
47     bool SomeSnapperMightSnap() const;
49     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
50                                     NR::Point const &p,
51                                     SPItem const *it) const;
52                                     
53     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
54                                     NR::Point const &p,
55                                     SPItem const *it,
56                                     std::vector<NR::Point> *unselected_nodes) const;
57     
58     Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
59                                       NR::Point const &p,
60                                       bool const &first_point,
61                                       std::vector<NR::Point> &points_to_snap,
62                                       std::list<SPItem const *> const &it,
63                                       std::vector<NR::Point> *unselected_nodes) const;
65     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
66                                            NR::Point const &p,
67                                            Inkscape::Snapper::ConstraintLine const &c,
68                                            SPItem const *it) const;
69     
70     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
71                                            NR::Point const &p,
72                                            bool const &first_point,
73                                            std::vector<NR::Point> &points_to_snap,
74                                            Inkscape::Snapper::ConstraintLine const &c,
75                                            std::list<SPItem const *> const &it) const;
76                                            
77     Inkscape::SnappedPoint guideSnap(NR::Point const &p,
78                                      NR::Point const &guide_normal) 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                                                     NR::scale const &s,
101                                                     NR::Point const &o) const;
103     std::pair<NR::Coord, bool> constrainedSnapStretch(Inkscape::Snapper::PointType t,
104                                                std::vector<NR::Point> const &p,
105                                                std::list<SPItem const *> const &it,
106                                                NR::Coord const &s,
107                                                NR::Point const &o,
108                                                NR::Dim2 d,
109                                                bool uniform) const;
111     std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
112                                             std::vector<NR::Point> const &p,
113                                             std::list<SPItem const *> const &it,
114                                             NR::Coord const &s,
115                                             NR::Point const &o,
116                                             NR::Dim2 d) const;
117                                             
118         Inkscape::SnappedPoint guideSnap(NR::Point const &p,
119                            Inkscape::ObjectSnapper::DimensionToSnap const snap_dim) const;
120   
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;
134     
135     void setSnapIntersectionGG(bool enabled) {_intersectionGG = enabled;}
136     void setSnapIntersectionLS(bool enabled) {_intersectionLS = enabled;}
137     bool getSnapIntersectionGG() { return _intersectionGG;}
138     bool getSnapIntersectionLS() { return _intersectionLS;}    
140     void setIncludeItemCenter(bool enabled)    {
141         _include_item_center = enabled;
142         // also store a local copy in the object-snapper instead of passing it through many functions
143         object.setIncludeItemCenter(enabled);
144         }
145     
146     bool getIncludeItemCenter() const {
147         return _include_item_center;
148     }
149     
150     void setSnapEnabledGlobally(bool enabled) {
151         _snap_enabled_globally = enabled;   
152     }
153         
154     bool getSnapEnabledGlobally() const {
155         return _snap_enabled_globally;   
156     }
157     
158     void toggleSnapEnabledGlobally() {
159         _snap_enabled_globally = !_snap_enabled_globally;   
160     }
161         
162 protected:
163     SPNamedView const *_named_view;
165 private:
167     enum Transformation {
168         TRANSLATION,
169         SCALE,
170         STRETCH,
171         SKEW
172     };
173     
174     bool _include_item_center; //If true, snapping nodes will also snap the item's center
175     bool _intersectionGG;
176     bool _intersectionLS;
177     bool _snap_enabled_globally; //Toggles ALL snapping
178     
179     std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
180                                                 std::vector<NR::Point> const &points,
181                                                 std::list<SPItem const *> const &ignore,
182                                                 bool constrained,
183                                                 Inkscape::Snapper::ConstraintLine const &constraint,
184                                                 Transformation transformation_type,
185                                                 NR::Point const &transformation,
186                                                 NR::Point const &origin,
187                                                 NR::Dim2 dim,
188                                                 bool uniform) const;
189                                                 
190     Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const;
191 };
193 #endif /* !SEEN_SNAP_H */
195 /*
196   Local Variables:
197   mode:c++
198   c-file-style:"stroustrup"
199   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
200   indent-tabs-mode:nil
201   fill-column:99
202   End:
203 */
204 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :