13f1d069cc1c6d1c30f04c03bf0149cb15e4c610
1 #ifndef SEEN_SNAP_CANDIDATE_H
2 #define SEEN_SNAP_CANDIDATE_H
4 /**
5 * \file snap-candidate.h
6 * \brief some utility classes to store various kinds of snap candidates.
7 *
8 * Authors:
9 * Diederik van Lierop <mail@diedenrezi.nl>
10 *
11 * Copyright (C) 2010 Authors
12 *
13 * Released under GNU GPL, read the file 'COPYING' for more information
14 */
16 //#include "snapped-point.h"
17 struct SPItem; // forward declaration
19 namespace Inkscape {
21 enum SnapTargetType {
22 SNAPTARGET_UNDEFINED = 0,
23 SNAPTARGET_GRID,
24 SNAPTARGET_GRID_INTERSECTION,
25 SNAPTARGET_GUIDE,
26 SNAPTARGET_GUIDE_INTERSECTION,
27 SNAPTARGET_GUIDE_ORIGIN,
28 SNAPTARGET_GRID_GUIDE_INTERSECTION,
29 SNAPTARGET_NODE_SMOOTH,
30 SNAPTARGET_NODE_CUSP,
31 SNAPTARGET_LINE_MIDPOINT,
32 SNAPTARGET_OBJECT_MIDPOINT,
33 SNAPTARGET_ROTATION_CENTER,
34 SNAPTARGET_HANDLE,
35 SNAPTARGET_PATH,
36 SNAPTARGET_PATH_INTERSECTION,
37 SNAPTARGET_BBOX_CORNER,
38 SNAPTARGET_BBOX_EDGE,
39 SNAPTARGET_BBOX_EDGE_MIDPOINT,
40 SNAPTARGET_BBOX_MIDPOINT,
41 SNAPTARGET_PAGE_BORDER,
42 SNAPTARGET_PAGE_CORNER,
43 SNAPTARGET_CONVEX_HULL_CORNER,
44 SNAPTARGET_ELLIPSE_QUADRANT_POINT,
45 SNAPTARGET_CENTER, // of ellipse
46 SNAPTARGET_CORNER, // of image or of rectangle
47 SNAPTARGET_TEXT_BASELINE,
48 SNAPTARGET_CONSTRAINED_ANGLE
49 };
51 enum SnapSourceType {
52 SNAPSOURCE_UNDEFINED = 0,
53 SNAPSOURCE_BBOX_CORNER,
54 SNAPSOURCE_BBOX_MIDPOINT,
55 SNAPSOURCE_BBOX_EDGE_MIDPOINT,
56 SNAPSOURCE_NODE_SMOOTH,
57 SNAPSOURCE_NODE_CUSP,
58 SNAPSOURCE_LINE_MIDPOINT,
59 SNAPSOURCE_OBJECT_MIDPOINT,
60 SNAPSOURCE_ROTATION_CENTER,
61 SNAPSOURCE_HANDLE,
62 SNAPSOURCE_PATH_INTERSECTION,
63 SNAPSOURCE_GUIDE,
64 SNAPSOURCE_GUIDE_ORIGIN,
65 SNAPSOURCE_CONVEX_HULL_CORNER,
66 SNAPSOURCE_ELLIPSE_QUADRANT_POINT,
67 SNAPSOURCE_CENTER, // of ellipse
68 SNAPSOURCE_CORNER, // of image or of rectangle
69 SNAPSOURCE_TEXT_BASELINE
70 };
72 /// Class to store data for points which are snap candidates, either as a source or as a target
73 class SnapCandidatePoint
74 {
75 public:
76 SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num, Inkscape::SnapTargetType const target, Geom::Rect const &bbox)
77 : _point(point), _source_type(source), _target_type(target), _source_num(source_num), _target_bbox(bbox) {};
79 SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, Inkscape::SnapTargetType const target)
80 : _point(point), _source_type(source), _target_type(target)
81 {
82 _source_num = 0;
83 _target_bbox = Geom::Rect();
84 }
86 SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num = 0)
87 : _point(point), _source_type(source), _target_type(Inkscape::SNAPTARGET_UNDEFINED), _source_num(source_num) {_target_bbox = Geom::Rect();}
89 inline Geom::Point const & getPoint() const {return _point;}
90 inline Inkscape::SnapSourceType getSourceType() const {return _source_type;}
91 inline Inkscape::SnapTargetType getTargetType() const {return _target_type;}
92 inline long getSourceNum() const {return _source_num;}
93 inline Geom::Rect const & getTargetBBox() const {return _target_bbox;}
95 private:
96 // Coordinates of the point
97 Geom::Point _point;
99 // If this SnapCandidatePoint is a snap source, then _source_type must be defined. If it
100 // is a snap target, then _target_type must be defined. If it's yet unknown whether it will
101 // be a source or target, then both may be defined
102 Inkscape::SnapSourceType _source_type;
103 Inkscape::SnapTargetType _target_type;
105 //Sequence number of the source point within the set of points that is to be snapped. Starting at zero
106 long _source_num;
108 // If this is a target and it belongs to a bounding box, e.g. when the target type is
109 // SNAPTARGET_BBOX_EDGE_MIDPOINT, then _target_bbox stores the relevant bounding box
110 Geom::Rect _target_bbox;
111 };
113 class SnapCandidateItem
114 {
115 public:
116 SnapCandidateItem(SPItem* item, bool clip_or_mask, Geom::Matrix additional_affine)
117 : item(item), clip_or_mask(clip_or_mask), additional_affine(additional_affine) {}
118 ~SnapCandidateItem() {};
120 SPItem* item; // An item that is to be considered for snapping to
121 bool clip_or_mask; // If true, then item refers to a clipping path or a mask
123 /* To find out the absolute position of a clipping path or mask, we not only need to know
124 * the transformation of the clipping path or mask itself, but also the transformation of
125 * the object to which the clip or mask is being applied; that transformation is stored here
126 */
127 Geom::Matrix additional_affine;
128 }
129 ;
131 class SnapCandidatePath
132 {
134 public:
135 SnapCandidatePath(Geom::PathVector* path, SnapTargetType target, bool edited = false)
136 : path_vector(path), target_type(target), currently_being_edited(edited) {}
137 ~SnapCandidatePath() {};
139 Geom::PathVector* path_vector;
140 SnapTargetType target_type;
141 bool currently_being_edited; // true for the path that's currently being edited in the node tool (if any)
143 };
145 } // end of namespace Inkscape
147 #endif /* !SEEN_SNAP_CANDIDATE_H */