Code

Merge from fe-moved
[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"
30 #include "snap-preferences.h"
32 class SPNamedView;
34 /// Class to coordinate snapping operations
36 /**
37  *  Each SPNamedView has one of these.  It offers methods to snap points to whatever
38  *  snappers are defined (e.g. grid, guides etc.).  It also allows callers to snap
39  *  points which have undergone some transformation (e.g. translation, scaling etc.)
40  */
42 class SnapManager
43 {
44 public:
45     SnapManager(SPNamedView const *v);
47     typedef std::list<const Inkscape::Snapper*> SnapperList;
49     bool someSnapperMightSnap() const;
50     
51     void setup(SPDesktop const *desktop, bool snapindicator = true, SPItem const *item_to_ignore = NULL, std::vector<Geom::Point> *unselected_nodes = NULL);
52     void setup(SPDesktop const *desktop, bool snapindicator, std::vector<SPItem const *> &items_to_ignore, std::vector<Geom::Point> *unselected_nodes = NULL);
54     // freeSnapReturnByRef() is preferred over freeSnap(), because it only returns a 
55     // point if snapping has occured (by overwriting p); otherwise p is untouched    
56     void freeSnapReturnByRef(Inkscape::SnapPreferences::PointType point_type,
57                       Geom::Point &p,
58                       bool first_point = true,
59                       Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
60     
61     Inkscape::SnappedPoint freeSnap(Inkscape::SnapPreferences::PointType point_type,
62                                     Geom::Point const &p,
63                                     bool first_point = true,
64                                     Geom::OptRect const &bbox_to_snap = Geom::OptRect() ) const;
65     
66     Geom::Point multipleOfGridPitch(Geom::Point const &t) const;
67     
68     // constrainedSnapReturnByRef() is preferred over constrainedSnap(), because it only returns a 
69     // point, by overwriting p, if snapping has occured; otherwise p is untouched
70     void constrainedSnapReturnByRef(Inkscape::SnapPreferences::PointType point_type,
71                              Geom::Point &p,
72                              Inkscape::Snapper::ConstraintLine const &constraint,
73                              bool first_point = true,
74                              Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
75     
76     Inkscape::SnappedPoint constrainedSnap(Inkscape::SnapPreferences::PointType point_type,
77                                            Geom::Point const &p,
78                                            Inkscape::Snapper::ConstraintLine const &constraint,
79                                            bool first_point = true,
80                                            Geom::OptRect const &bbox_to_snap = Geom::OptRect()) const;
81                                            
82     void guideSnap(Geom::Point &p, Geom::Point const &guide_normal) const;
84     Inkscape::SnappedPoint freeSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
85                                                std::vector<Geom::Point> const &p,
86                                                Geom::Point const &pointer,
87                                                Geom::Point const &tr) const;
89     Inkscape::SnappedPoint constrainedSnapTranslation(Inkscape::SnapPreferences::PointType point_type,
90                                                       std::vector<Geom::Point> const &p,
91                                                       Geom::Point const &pointer,
92                                                       Inkscape::Snapper::ConstraintLine const &constraint,
93                                                       Geom::Point const &tr) const;
95     Inkscape::SnappedPoint freeSnapScale(Inkscape::SnapPreferences::PointType point_type,
96                                          std::vector<Geom::Point> const &p,
97                                          Geom::Point const &pointer,
98                                          Geom::Scale const &s,
99                                          Geom::Point const &o) const;
101     Inkscape::SnappedPoint constrainedSnapScale(Inkscape::SnapPreferences::PointType point_type,
102                                                 std::vector<Geom::Point> const &p,
103                                                 Geom::Point const &pointer,
104                                                 Geom::Scale const &s,
105                                                 Geom::Point const &o) const;
107     Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::SnapPreferences::PointType point_type,
108                                                   std::vector<Geom::Point> const &p,
109                                                   Geom::Point const &pointer,
110                                                   Geom::Coord const &s,
111                                                   Geom::Point const &o,
112                                                   Geom::Dim2 d,
113                                                   bool uniform) const;
115     Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::SnapPreferences::PointType point_type,
116                                                std::vector<Geom::Point> const &p,
117                                                Geom::Point const &pointer,
118                                                Inkscape::Snapper::ConstraintLine const &constraint,
119                                                Geom::Point const &s, // s[0] = skew factor, s[1] = scale factor
120                                                Geom::Point const &o,
121                                                Geom::Dim2 d) const;
122                                         
123     Inkscape::GuideSnapper guide;      ///< guide snapper
124     Inkscape::ObjectSnapper object;    ///< snapper to other objects
125     Inkscape::SnapPreferences snapprefs;
127     SnapperList getSnappers() const;
128     SnapperList getGridSnappers() const;
129     
130     SPDesktop const *getDesktop() const {return _desktop;}
131     SPNamedView const *getNamedView() const {return _named_view;}
132     SPDocument *getDocument() const;
133     
134 protected:
135     SPNamedView const *_named_view;
137 private:
138         enum Transformation {
139         TRANSLATION,
140         SCALE,
141         STRETCH,
142         SKEW
143     };
144     
145     std::vector<SPItem const *> *_items_to_ignore;
146     SPItem const *_item_to_ignore;
147     SPDesktop const *_desktop;
148     bool _snapindicator;
149     std::vector<Geom::Point> *_unselected_nodes;                                    
150     
151     Inkscape::SnappedPoint _snapTransformed(Inkscape::SnapPreferences::PointType type,
152                                             std::vector<Geom::Point> const &points,
153                                             Geom::Point const &pointer,
154                                             bool constrained,
155                                             Inkscape::Snapper::ConstraintLine const &constraint,
156                                             Transformation transformation_type,
157                                             Geom::Point const &transformation,
158                                             Geom::Point const &origin,
159                                             Geom::Dim2 dim,
160                                             bool uniform) const;
161                                                 
162     Inkscape::SnappedPoint findBestSnap(Geom::Point const &p, SnappedConstraints &sc, bool constrained) const;
163 };
165 #endif /* !SEEN_SNAP_H */
167 /*
168   Local Variables:
169   mode:c++
170   c-file-style:"stroustrup"
171   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
172   indent-tabs-mode:nil
173   fill-column:99
174   End:
175 */
176 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :