Code

noop: address ‘no newline at end of file’ warning
[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  * Copyright (C) 2000-2008 Authors
17  *
18  * Released under GNU GPL, read the file 'COPYING' for more information
19  */
21 #include <vector>
23 #include <libnr/nr-coord.h>
24 #include <libnr/nr-dim2.h>
25 #include <libnr/nr-forward.h>
26 #include <libnr/nr-scale.h>
28 #include "guide-snapper.h"
29 #include "object-snapper.h"
31 class SPNamedView;
33 /// Class to coordinate snapping operations
35 /**
36  *  Each SPNamedView has one of these.  It offers methods to snap points to whatever
37  *  snappers are defined (e.g. grid, guides etc.).  It also allows callers to snap
38  *  points which have undergone some transformation (e.g. translation, scaling etc.)
39  */
41 class SnapManager
42 {
43 public:
44     SnapManager(SPNamedView const *v);
46     typedef std::list<const Inkscape::Snapper*> SnapperList;
48     bool SomeSnapperMightSnap() const;
50     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
51                                     NR::Point const &p,
52                                     SPItem const *it,
53                                     NR::Maybe<NR::Point> point_not_to_snap_to = NR::Nothing()) const;
54                                     
55     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
56                                     NR::Point const &p,
57                                     SPItem const *it,
58                                     std::vector<NR::Point> *unselected_nodes) const;
59     
60     Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType t,
61                                     NR::Point const &p,
62                                     bool const &first_point,
63                                     std::vector<NR::Point> &points_to_snap,
64                                     std::vector<SPItem const *> const &it,
65                                     std::vector<NR::Point> *unselected_nodes) const;
67     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
68                                            NR::Point const &p,
69                                            Inkscape::Snapper::ConstraintLine const &c,
70                                            SPItem const *it) const;
71     
72     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
73                                            NR::Point const &p,
74                                            bool const &first_point,
75                                            std::vector<NR::Point> &points_to_snap,
76                                            Inkscape::Snapper::ConstraintLine const &c,
77                                            std::vector<SPItem const *> const &it) const;
78                                            
79     Inkscape::SnappedPoint guideSnap(NR::Point const &p,
80                                      NR::Point const &guide_normal) const;
82     Inkscape::SnappedPoint freeSnapTranslation(Inkscape::Snapper::PointType t,
83                                                std::vector<NR::Point> const &p,
84                                                std::vector<SPItem const *> const &it,
85                                                NR::Point const &tr) const;
87     Inkscape::SnappedPoint constrainedSnapTranslation(Inkscape::Snapper::PointType t,
88                                                       std::vector<NR::Point> const &p,
89                                                       std::vector<SPItem const *> const &it,
90                                                       Inkscape::Snapper::ConstraintLine const &c,
91                                                       NR::Point const &tr) const;
93     Inkscape::SnappedPoint freeSnapScale(Inkscape::Snapper::PointType t,
94                                          std::vector<NR::Point> const &p,
95                                          std::vector<SPItem const *> const &it,
96                                          NR::scale const &s,
97                                          NR::Point const &o) const;
99     Inkscape::SnappedPoint constrainedSnapScale(Inkscape::Snapper::PointType t,
100                                                 std::vector<NR::Point> const &p,
101                                                 std::vector<SPItem const *> const &it,
102                                                 NR::scale const &s,
103                                                 NR::Point const &o) const;
105     Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::Snapper::PointType t,
106                                                    std::vector<NR::Point> const &p,
107                                                    std::vector<SPItem const *> const &it,
108                                                    NR::Coord const &s,
109                                                    NR::Point const &o,
110                                                    NR::Dim2 d,
111                                                    bool uniform) const;
113     Inkscape::SnappedPoint freeSnapSkew(Inkscape::Snapper::PointType t,
114                                         std::vector<NR::Point> const &p,
115                                         std::vector<SPItem const *> const &it,
116                                         NR::Coord const &s,
117                                         NR::Point const &o,
118                                         NR::Dim2 d) const;
119                                             
120         Inkscape::SnappedPoint guideSnap(NR::Point const &p,
121                            Inkscape::ObjectSnapper::DimensionToSnap const snap_dim) const;
122   
124     Inkscape::GuideSnapper guide;      ///< guide snapper
125     Inkscape::ObjectSnapper object;    ///< snapper to other objects
127     SnapperList getSnappers() const;
128     SnapperList getGridSnappers() const;
129     
130     void setSnapModeBBox(bool enabled);
131     void setSnapModeNode(bool enabled);
132     void setSnapModeGuide(bool enabled);
133     bool getSnapModeBBox() const;
134     bool getSnapModeNode() const;
135     bool getSnapModeGuide() const;
136     
137     void setSnapIntersectionGG(bool enabled) {_intersectionGG = enabled;}
138     void setSnapIntersectionLS(bool enabled) {_intersectionLS = enabled;}
139     bool getSnapIntersectionGG() { return _intersectionGG;}
140     bool getSnapIntersectionLS() { return _intersectionLS;}    
142     void setIncludeItemCenter(bool enabled)    {
143         _include_item_center = enabled;
144         // also store a local copy in the object-snapper instead of passing it through many functions
145         object.setIncludeItemCenter(enabled);
146         }
147     
148     bool getIncludeItemCenter() const {
149         return _include_item_center;
150     }
151     
152     void setSnapEnabledGlobally(bool enabled) {
153         _snap_enabled_globally = enabled;   
154     }
155         
156     bool getSnapEnabledGlobally() const {
157         return _snap_enabled_globally;   
158     }
159     
160     void toggleSnapEnabledGlobally() {
161         _snap_enabled_globally = !_snap_enabled_globally;   
162     }
163         
164 protected:
165     SPNamedView const *_named_view;
167 private:
169     enum Transformation {
170         TRANSLATION,
171         SCALE,
172         STRETCH,
173         SKEW
174     };
175     
176     bool _include_item_center; //If true, snapping nodes will also snap the item's center
177     bool _intersectionGG;
178     bool _intersectionLS;
179     bool _snap_enabled_globally; //Toggles ALL snapping
180     
181     Inkscape::SnappedPoint _snapTransformed(Inkscape::Snapper::PointType type,
182                                             std::vector<NR::Point> const &points,
183                                             std::vector<SPItem const *> const &ignore,
184                                             bool constrained,
185                                             Inkscape::Snapper::ConstraintLine const &constraint,
186                                             Transformation transformation_type,
187                                             NR::Point const &transformation,
188                                             NR::Point const &origin,
189                                             NR::Dim2 dim,
190                                             bool uniform) const;
191                                                 
192     Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const;
193 };
195 #endif /* !SEEN_SNAP_H */
197 /*
198   Local Variables:
199   mode:c++
200   c-file-style:"stroustrup"
201   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
202   indent-tabs-mode:nil
203   fill-column:99
204   End:
205 */
206 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :