Code

a2d199c875d63d9528dd3b9596d96a03a244f59b
[inkscape.git] / src / object-snapper.h
1 #ifndef SEEN_OBJECT_SNAPPER_H
2 #define SEEN_OBJECT_SNAPPER_H
4 /**
5  *  \file object-snapper.h
6  *  \brief Snapping things to objects.
7  *
8  * Authors:
9  *   Carl Hetherington <inkscape@carlh.net>
10  *   Diederik van Lierop <mail@diedenrezi.nl>
11  *
12  * Copyright (C) 2005 - 2007 Authors 
13  *
14  * Released under GNU GPL, read the file 'COPYING' for more information
15  */
17 #include "snapper.h"
18 #include "sp-path.h"
19 #include "splivarot.h"
21 struct SPNamedView;
22 struct SPItem;
23 struct SPObject;
25 namespace Inkscape
26 {
28 class ObjectSnapper : public Snapper
29 {
31 public:
32   ObjectSnapper(SPNamedView const *nv, NR::Coord const d);
33   ~ObjectSnapper();
35   enum DimensionToSnap {
36     GUIDE_TRANSL_SNAP_X, // For snapping a vertical guide (normal in the X-direction) to objects, 
37     GUIDE_TRANSL_SNAP_Y, // For snapping a horizontal guide (normal in the Y-direction) to objects
38     ANGLED_GUIDE_TRANSL_SNAP, // For snapping an angled guide, while translating it accross the desktop
39     ANGLED_GUIDE_ROT_SNAP, // For snapping an angled guide, while rotating it around some pivot point
40     TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides
42   void setSnapToItemNode(bool s) {
43     _snap_to_itemnode = s;
44   }
46   bool getSnapToItemNode() const {
47     return _snap_to_itemnode;
48   }
50   void setSnapToItemPath(bool s) {
51     _snap_to_itempath = s;
52   }
54   bool getSnapToItemPath() const {
55     return _snap_to_itempath;
56   }
57   
58   void setSnapToBBoxNode(bool s) {
59     _snap_to_bboxnode = s;
60   }
62   bool getSnapToBBoxNode() const {
63     return _snap_to_bboxnode;
64   }
66   void setSnapToBBoxPath(bool s) {
67     _snap_to_bboxpath = s;
68   }
70   bool getSnapToBBoxPath() const {
71     return _snap_to_bboxpath;
72   }
73   
74   void setIncludeItemCenter(bool s) {
75     _include_item_center = s;
76   }
78   bool getIncludeItemCenter() const {
79     return _include_item_center;
80   }
81   
82   void setStrictSnapping(bool enabled) {
83       _strict_snapping = enabled;
84   }
85   
86   void guideSnap(SnappedConstraints &sc,
87                                  NR::Point const &p,
88                  NR::Point const &guide_normal) const;
89   
90   bool ThisSnapperMightSnap() const;
91   
92 private:
93   //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
94   std::vector<SPItem*> *_candidates; 
95   std::vector<NR::Point> *_points_to_snap_to;
96   std::vector<NArtBpath*> *_bpaths_to_snap_to;
97   std::vector<Path*> *_paths_to_snap_to;
98   void _doFreeSnap(SnappedConstraints &sc,
99                       Inkscape::Snapper::PointType const &t,
100                       NR::Point const &p,
101                       bool const &first_point,
102                       std::vector<NR::Point> &points_to_snap,
103                       std::list<SPItem const *> const &it) const;
105   void _doConstrainedSnap(SnappedConstraints &sc,
106                       Inkscape::Snapper::PointType const &t,
107                       NR::Point const &p,
108                       bool const &first_point,                                                                   
109                       std::vector<NR::Point> &points_to_snap,
110                       ConstraintLine const &c,
111                       std::list<SPItem const *> const &it) const;
112                        
113   void _findCandidates(SPObject* r,
114                        std::list<SPItem const *> const &it,
115                        bool const &first_point,
116                        std::vector<NR::Point> &points_to_snap,
117                        DimensionToSnap const snap_dim) const;
118   
119   void _snapNodes(SnappedConstraints &sc,
120                       Inkscape::Snapper::PointType const &t,
121                       NR::Point const &p, 
122                       bool const &first_point) const;
123                       
124   void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
125                      Inkscape::Snapper::PointType const &t,
126                      NR::Point const &p,
127                      NR::Point const &guide_normal) const;
128                      
129   void _collectNodes(Inkscape::Snapper::PointType const &t,
130                   bool const &first_point) const;
131   
132   void _snapPaths(SnappedConstraints &sc,
133                       Inkscape::Snapper::PointType const &t, 
134                       NR::Point const &p,
135                       bool const &first_point) const;
136                       
137   void _snapPathsConstrained(SnappedConstraints &sc,
138                  Inkscape::Snapper::PointType const &t,
139                  NR::Point const &p,
140                  bool const &first_point,
141                  ConstraintLine const &c) const;
142   
143   void _collectPaths(Inkscape::Snapper::PointType const &t, 
144                   bool const &first_point) const;
145   void _clear_paths() const;
146   
147   bool _snap_to_itemnode;
148   bool _snap_to_itempath;
149   bool _snap_to_bboxnode;
150   bool _snap_to_bboxpath;
151   
152   //If enabled, then bbox corners will only snap to bboxes, 
153   //and nodes will only snap to nodes and paths. We will not
154   //snap bbox corners to nodes, or nodes to bboxes.
155   //(snapping to grids and guides is not affected by this)
156   bool _strict_snapping; 
157   bool _include_item_center;
158 };
162 #endif