Code

The dialog to panel refactoring:
[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  *
11  * Copyright (C) 2005 Authors 
12  *
13  * Released under GNU GPL, read the file 'COPYING' for more information
14  */
16 #include "snapper.h"
17 #include "sp-path.h"
18 #include "splivarot.h"
20 struct SPNamedView;
21 struct SPItem;
22 struct SPObject;
24 namespace Inkscape
25 {
27 class ObjectSnapper : public Snapper
28 {
30 public:
31   ObjectSnapper(SPNamedView const *nv, NR::Coord const d);
32   ~ObjectSnapper();
34   enum DimensionToSnap {SNAP_X, SNAP_Y, SNAP_XY};
36   void setSnapToItemNode(bool s) {
37     _snap_to_itemnode = s;
38   }
40   bool getSnapToItemNode() const {
41     return _snap_to_itemnode;
42   }
44   void setSnapToItemPath(bool s) {
45     _snap_to_itempath = s;
46   }
48   bool getSnapToItemPath() const {
49     return _snap_to_itempath;
50   }
51   
52   void setSnapToBBoxNode(bool s) {
53     _snap_to_bboxnode = s;
54   }
56   bool getSnapToBBoxNode() const {
57     return _snap_to_bboxnode;
58   }
60   void setSnapToBBoxPath(bool s) {
61     _snap_to_bboxpath = s;
62   }
64   bool getSnapToBBoxPath() const {
65     return _snap_to_bboxpath;
66   }
67   
68   void setIncludeItemCenter(bool s) {
69     _include_item_center = s;
70   }
72   bool getIncludeItemCenter() const {
73     return _include_item_center;
74   }
75   
76   void setStrictSnapping(bool enabled) {
77       _strict_snapping = enabled;
78   }
79   
80   void guideSnap(SnappedConstraints &sc,
81                                  NR::Point const &p,
82                  DimensionToSnap const snap_dim) const;
83   
84   bool ThisSnapperMightSnap() const;
85   
86 private:
87   //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
88   std::vector<SPItem*> *_candidates; 
89   std::vector<NR::Point> *_points_to_snap_to;
90   std::vector<Path*> *_paths_to_snap_to;
91   void _doFreeSnap(SnappedConstraints &sc,
92                       Inkscape::Snapper::PointType const &t,
93                       NR::Point const &p,
94                       bool const &first_point,
95                       std::vector<NR::Point> &points_to_snap,
96                       std::list<SPItem const *> const &it) const;
98   void _doConstrainedSnap(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                       ConstraintLine const &c,
104                       std::list<SPItem const *> const &it) const;
105                        
106   void _findCandidates(SPObject* r,
107                        std::list<SPItem const *> const &it,
108                        bool const &first_point,
109                        std::vector<NR::Point> &points_to_snap,
110                        DimensionToSnap const snap_dim) const;
111   
112   void _snapNodes(SnappedConstraints &sc,
113                       Inkscape::Snapper::PointType const &t,
114                       NR::Point const &p, 
115                       bool const &first_point,
116                       DimensionToSnap const snap_dim) const;
117                       
118   void _snapPaths(SnappedConstraints &sc,
119                       Inkscape::Snapper::PointType const &t, 
120                       NR::Point const &p,
121                       bool const &first_point) const;
122   
123   bool _snap_to_itemnode;
124   bool _snap_to_itempath;
125   bool _snap_to_bboxnode;
126   bool _snap_to_bboxpath;
127   
128   //If enabled, then bbox corners will only snap to bboxes, 
129   //and nodes will only snap to nodes and paths. We will not
130   //snap bbox corners to nodes, or nodes to bboxes.
131   //(snapping to grids and guides is not affected by this)
132   bool _strict_snapping; 
133   bool _include_item_center;
134 };
138 #endif