Code

Fix LP #181020: When snapping a guide, now only the part of the guide near the pointe...
[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   bool GuidesMightSnap() const;
92   
93 private:
94   //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
95   std::vector<SPItem*> *_candidates; 
96   std::vector<NR::Point> *_points_to_snap_to;
97   std::vector<NArtBpath*> *_bpaths_to_snap_to;
98   std::vector<Path*> *_paths_to_snap_to;
99   void _doFreeSnap(SnappedConstraints &sc,
100                       Inkscape::Snapper::PointType const &t,
101                       NR::Point const &p,
102                       bool const &first_point,
103                       std::vector<NR::Point> &points_to_snap,
104                       std::list<SPItem const *> const &it) const;
106   void _doConstrainedSnap(SnappedConstraints &sc,
107                       Inkscape::Snapper::PointType const &t,
108                       NR::Point const &p,
109                       bool const &first_point,                                                                   
110                       std::vector<NR::Point> &points_to_snap,
111                       ConstraintLine const &c,
112                       std::list<SPItem const *> const &it) const;
113                        
114   void _findCandidates(SPObject* r,
115                        std::list<SPItem const *> const &it,
116                        bool const &first_point,
117                        std::vector<NR::Point> &points_to_snap,
118                        DimensionToSnap const snap_dim) const;
119   
120   void _snapNodes(SnappedConstraints &sc,
121                       Inkscape::Snapper::PointType const &t,
122                       NR::Point const &p, 
123                       bool const &first_point) const;
124                       
125   void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
126                      Inkscape::Snapper::PointType const &t,
127                      NR::Point const &p,
128                      NR::Point const &guide_normal) const;
129                      
130   void _collectNodes(Inkscape::Snapper::PointType const &t,
131                   bool const &first_point) const;
132   
133   void _snapPaths(SnappedConstraints &sc,
134                       Inkscape::Snapper::PointType const &t, 
135                       NR::Point const &p,
136                       bool const &first_point) const;
137                       
138   void _snapPathsConstrained(SnappedConstraints &sc,
139                  Inkscape::Snapper::PointType const &t,
140                  NR::Point const &p,
141                  bool const &first_point,
142                  ConstraintLine const &c) const;
143   
144   void _collectPaths(Inkscape::Snapper::PointType const &t, 
145                   bool const &first_point) const;
146   void _clear_paths() const;
147   
148   bool _snap_to_itemnode;
149   bool _snap_to_itempath;
150   bool _snap_to_bboxnode;
151   bool _snap_to_bboxpath;
152   
153   //If enabled, then bbox corners will only snap to bboxes, 
154   //and nodes will only snap to nodes and paths. We will not
155   //snap bbox corners to nodes, or nodes to bboxes.
156   //(snapping to grids and guides is not affected by this)
157   bool _strict_snapping; 
158   bool _include_item_center;
159 };
163 #endif