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 void setup(SPDesktop const *desktop_for_snapindicator = NULL, SPItem const *item_to_ignore = NULL, std::vector<NR::Point> *unselected_nodes = NULL);
51 void setup(SPDesktop const *desktop_for_snapindicator, std::vector<SPItem const *> &items_to_ignore, std::vector<NR::Point> *unselected_nodes = NULL);
53 Inkscape::SnappedPoint freeSnap(Inkscape::Snapper::PointType point_type,
54 NR::Point const &p,
55 bool first_point = true,
56 NR::Maybe<NR::Rect> const &bbox_to_snap = NR::Nothing()) const;
58 Inkscape::SnappedPoint constrainedSnap(Inkscape::Snapper::PointType point_type,
59 NR::Point const &p,
60 Inkscape::Snapper::ConstraintLine const &constraint,
61 bool first_point = true,
62 NR::Maybe<NR::Rect> const &bbox_to_snap = NR::Nothing()) const;
64 Inkscape::SnappedPoint guideSnap(NR::Point const &p,
65 NR::Point const &guide_normal) const;
67 Inkscape::SnappedPoint freeSnapTranslation(Inkscape::Snapper::PointType point_type,
68 std::vector<NR::Point> const &p,
69 NR::Point const &tr) const;
71 Inkscape::SnappedPoint constrainedSnapTranslation(Inkscape::Snapper::PointType point_type,
72 std::vector<NR::Point> const &p,
73 Inkscape::Snapper::ConstraintLine const &constraint,
74 NR::Point const &tr) const;
76 Inkscape::SnappedPoint freeSnapScale(Inkscape::Snapper::PointType point_type,
77 std::vector<NR::Point> const &p,
78 NR::scale const &s,
79 NR::Point const &o) const;
81 Inkscape::SnappedPoint constrainedSnapScale(Inkscape::Snapper::PointType point_type,
82 std::vector<NR::Point> const &p,
83 NR::scale const &s,
84 NR::Point const &o) const;
86 Inkscape::SnappedPoint constrainedSnapStretch(Inkscape::Snapper::PointType point_type,
87 std::vector<NR::Point> const &p,
88 NR::Coord const &s,
89 NR::Point const &o,
90 NR::Dim2 d,
91 bool uniform) const;
93 Inkscape::SnappedPoint constrainedSnapSkew(Inkscape::Snapper::PointType point_type,
94 std::vector<NR::Point> const &p,
95 Inkscape::Snapper::ConstraintLine const &constraint,
96 NR::Point const &s, // s[0] = skew factor, s[1] = scale factor
97 NR::Point const &o,
98 NR::Dim2 d) const;
100 Inkscape::GuideSnapper guide; ///< guide snapper
101 Inkscape::ObjectSnapper object; ///< snapper to other objects
103 SnapperList getSnappers() const;
104 SnapperList getGridSnappers() const;
106 void setSnapModeBBox(bool enabled);
107 void setSnapModeNode(bool enabled);
108 void setSnapModeGuide(bool enabled);
109 bool getSnapModeBBox() const;
110 bool getSnapModeNode() const;
111 bool getSnapModeGuide() const;
113 void setSnapIntersectionGG(bool enabled) {_intersectionGG = enabled;}
114 void setSnapIntersectionLS(bool enabled) {_intersectionLS = enabled;}
115 bool getSnapIntersectionGG() {return _intersectionGG;}
116 bool getSnapIntersectionLS() {return _intersectionLS;}
118 void setIncludeItemCenter(bool enabled) {
119 _include_item_center = enabled;
120 // also store a local copy in the object-snapper instead of passing it through many functions
121 object.setIncludeItemCenter(enabled);
122 }
124 bool getIncludeItemCenter() const {
125 return _include_item_center;
126 }
128 void setSnapEnabledGlobally(bool enabled) {
129 _snap_enabled_globally = enabled;
130 }
132 bool getSnapEnabledGlobally() const {
133 return _snap_enabled_globally;
134 }
136 void toggleSnapEnabledGlobally() {
137 _snap_enabled_globally = !_snap_enabled_globally;
138 }
140 protected:
141 SPNamedView const *_named_view;
143 private:
145 enum Transformation {
146 TRANSLATION,
147 SCALE,
148 STRETCH,
149 SKEW
150 };
152 bool _include_item_center; //If true, snapping nodes will also snap the item's center
153 bool _intersectionGG;
154 bool _intersectionLS;
155 bool _snap_enabled_globally; //Toggles ALL snapping
157 std::vector<SPItem const *> *_items_to_ignore;
158 SPItem const *_item_to_ignore;
159 SPDesktop const *_desktop_for_snapindicator;
160 std::vector<NR::Point> *_unselected_nodes;
162 Inkscape::SnappedPoint _snapTransformed(Inkscape::Snapper::PointType type,
163 std::vector<NR::Point> const &points,
164 bool constrained,
165 Inkscape::Snapper::ConstraintLine const &constraint,
166 Transformation transformation_type,
167 NR::Point const &transformation,
168 NR::Point const &origin,
169 NR::Dim2 dim,
170 bool uniform) const;
172 Inkscape::SnappedPoint findBestSnap(NR::Point const &p, SnappedConstraints &sc, bool constrained) const;
173 };
175 #endif /* !SEEN_SNAP_H */
177 /*
178 Local Variables:
179 mode:c++
180 c-file-style:"stroustrup"
181 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
182 indent-tabs-mode:nil
183 fill-column:99
184 End:
185 */
186 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :