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 #include "snap-enums.h"
19 struct SPItem; // forward declaration
21 namespace Inkscape {
23 /// Class to store data for points which are snap candidates, either as a source or as a target
24 class SnapCandidatePoint
25 {
26 public:
27 SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, long const source_num, Inkscape::SnapTargetType const target, Geom::OptRect const &bbox)
28 : _point(point),
29 _source_type(source),
30 _target_type(target),
31 _source_num(source_num),
32 _target_bbox(bbox)
33 {
34 };
36 SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source, Inkscape::SnapTargetType const target)
37 : _point(point),
38 _source_type(source),
39 _target_type(target)
40 {
41 _source_num = -1;
42 _target_bbox = Geom::OptRect();
43 }
45 SnapCandidatePoint(Geom::Point const &point, Inkscape::SnapSourceType const source)
46 : _point(point),
47 _source_type(source),
48 _target_type(Inkscape::SNAPTARGET_UNDEFINED),
49 _source_num(-1)
50 {
51 _target_bbox = Geom::OptRect();
52 }
54 inline Geom::Point const & getPoint() const {return _point;}
55 inline Inkscape::SnapSourceType getSourceType() const {return _source_type;}
56 bool isSingleHandle() const {return (_source_type == SNAPSOURCE_NODE_HANDLE || _source_type == SNAPSOURCE_OTHER_HANDLE) && _source_num == -1;}
57 inline Inkscape::SnapTargetType getTargetType() const {return _target_type;}
58 inline long getSourceNum() const {return _source_num;}
59 void setSourceNum(long num) {_source_num = num;}
60 inline Geom::OptRect const getTargetBBox() const {return _target_bbox;}
62 private:
63 // Coordinates of the point
64 Geom::Point _point;
66 // If this SnapCandidatePoint is a snap source, then _source_type must be defined. If it
67 // is a snap target, then _target_type must be defined. If it's yet unknown whether it will
68 // be a source or target, then both may be defined
69 Inkscape::SnapSourceType _source_type;
70 Inkscape::SnapTargetType _target_type;
72 //Sequence number of the source point within the set of points that is to be snapped.
73 // - Starts counting at zero, but only if there might be more points following (e.g. in the selector tool)
74 // - Minus one (-1) if we're sure that we have only a single point
75 long _source_num;
77 // If this is a target and it belongs to a bounding box, e.g. when the target type is
78 // SNAPTARGET_BBOX_EDGE_MIDPOINT, then _target_bbox stores the relevant bounding box
79 Geom::OptRect _target_bbox;
80 };
82 class SnapCandidateItem
83 {
84 public:
85 SnapCandidateItem(SPItem* item, bool clip_or_mask, Geom::Matrix additional_affine)
86 : item(item), clip_or_mask(clip_or_mask), additional_affine(additional_affine) {}
87 ~SnapCandidateItem() {};
89 SPItem* item; // An item that is to be considered for snapping to
90 bool clip_or_mask; // If true, then item refers to a clipping path or a mask
92 /* To find out the absolute position of a clipping path or mask, we not only need to know
93 * the transformation of the clipping path or mask itself, but also the transformation of
94 * the object to which the clip or mask is being applied; that transformation is stored here
95 */
96 Geom::Matrix additional_affine;
97 }
98 ;
100 class SnapCandidatePath
101 {
103 public:
104 SnapCandidatePath(Geom::PathVector* path, SnapTargetType target, Geom::OptRect bbox, bool edited = false)
105 : path_vector(path), target_type(target), target_bbox(bbox), currently_being_edited(edited) {};
106 ~SnapCandidatePath() {};
108 Geom::PathVector* path_vector;
109 SnapTargetType target_type;
110 Geom::OptRect target_bbox;
111 bool currently_being_edited; // true for the path that's currently being edited in the node tool (if any)
113 };
115 } // end of namespace Inkscape
117 #endif /* !SEEN_SNAP_CANDIDATE_H */