Code

* [INTL: es] Spanish translation update by Lucas Vieites (closes: #180399)
[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;
53     Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
54                                       NR::Point const &p,
55                                       bool const &first_point,
56                                       std::vector<NR::Point> &points_to_snap,
57                                       std::list<SPItem const *> const &it) const;
59     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
60                                            NR::Point const &p,
61                                            Inkscape::Snapper::ConstraintLine const &c,
62                                            SPItem const *it) const;
63     
64     Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType t,
65                                            NR::Point const &p,
66                                            bool const &first_point,
67                                            std::vector<NR::Point> &points_to_snap,
68                                            Inkscape::Snapper::ConstraintLine const &c,
69                                            std::list<SPItem const *> const &it) const;
70                                            
71     Inkscape::SnappedPoint guideSnap(NR::Point const &p,
72                                      NR::Point const &guide_normal) const;
74     std::pair<NR::Point, bool> freeSnapTranslation(Inkscape::Snapper::PointType t,
75                                                    std::vector<NR::Point> const &p,
76                                                    std::list<SPItem const *> const &it,
77                                                    NR::Point const &tr) const;
79     std::pair<NR::Point, bool> constrainedSnapTranslation(Inkscape::Snapper::PointType t,
80                                                           std::vector<NR::Point> const &p,
81                                                           std::list<SPItem const *> const &it,
82                                                           Inkscape::Snapper::ConstraintLine const &c,
83                                                           NR::Point const &tr) const;
85     std::pair<NR::scale, bool> freeSnapScale(Inkscape::Snapper::PointType t,
86                                              std::vector<NR::Point> const &p,
87                                              std::list<SPItem const *> const &it,
88                                              NR::scale const &s,
89                                              NR::Point const &o) const;
91     std::pair<NR::scale, bool> constrainedSnapScale(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::Coord, bool> freeSnapStretch(Inkscape::Snapper::PointType t,
98                                                std::vector<NR::Point> const &p,
99                                                std::list<SPItem const *> const &it,
100                                                NR::Coord const &s,
101                                                NR::Point const &o,
102                                                NR::Dim2 d,
103                                                bool uniform) const;
105     std::pair<NR::Coord, bool> freeSnapSkew(Inkscape::Snapper::PointType t,
106                                             std::vector<NR::Point> const &p,
107                                             std::list<SPItem const *> const &it,
108                                             NR::Coord const &s,
109                                             NR::Point const &o,
110                                             NR::Dim2 d) const;
111                                             
112         Inkscape::SnappedPoint guideSnap(NR::Point const &p,
113                            Inkscape::ObjectSnapper::DimensionToSnap const snap_dim) const;
114   
116     Inkscape::GuideSnapper guide;      ///< guide snapper
117     Inkscape::ObjectSnapper object;    ///< snapper to other objects
119     SnapperList getSnappers() const;
120     SnapperList getGridSnappers() const;
121     
122     void setSnapModeBBox(bool enabled);
123     void setSnapModeNode(bool enabled);
124     void setSnapModeGuide(bool enabled);
125     bool getSnapModeBBox() const;
126     bool getSnapModeNode() const;
127     bool getSnapModeGuide() const;
128     
129     void setSnapIntersectionGG(bool enabled) {_intersectionGG = enabled;}
130     void setSnapIntersectionLS(bool enabled) {_intersectionLS = enabled;}
131     bool getSnapIntersectionGG() { return _intersectionGG;}
132     bool getSnapIntersectionLS() { return _intersectionLS;}    
134     void setIncludeItemCenter(bool enabled)    {
135         _include_item_center = enabled;
136         // also store a local copy in the object-snapper instead of passing it through many functions
137         object.setIncludeItemCenter(enabled);
138         }
139     
140     bool getIncludeItemCenter() const {
141         return _include_item_center;
142     }
143     
144     void setSnapEnabledGlobally(bool enabled) {
145         _snap_enabled_globally = enabled;   
146     }
147         
148     bool getSnapEnabledGlobally() const {
149         return _snap_enabled_globally;   
150     }
151     
152     void toggleSnapEnabledGlobally() {
153         _snap_enabled_globally = !_snap_enabled_globally;   
154     }
155         
156 protected:
157     SPNamedView const *_named_view;
159 private:
161     enum Transformation {
162         TRANSLATION,
163         SCALE,
164         STRETCH,
165         SKEW
166     };
167     
168     bool _include_item_center; //If true, snapping nodes will also snap the item's center
169     bool _intersectionGG;
170     bool _intersectionLS;
171     bool _snap_enabled_globally; //Toggles ALL snapping
172     
173     std::pair<NR::Point, bool> _snapTransformed(Inkscape::Snapper::PointType type,
174                                                 std::vector<NR::Point> const &points,
175                                                 std::list<SPItem const *> const &ignore,
176                                                 bool constrained,
177                                                 Inkscape::Snapper::ConstraintLine const &constraint,
178                                                 Transformation transformation_type,
179                                                 NR::Point const &transformation,
180                                                 NR::Point const &origin,
181                                                 NR::Dim2 dim,
182                                                 bool uniform) const;
183                                                 
184     Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const;
185 };
187 #endif /* !SEEN_SNAP_H */
189 /*
190   Local Variables:
191   mode:c++
192   c-file-style:"stroustrup"
193   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
194   indent-tabs-mode:nil
195   fill-column:99
196   End:
197 */
198 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :