object-snapper.h revision 1813949bb185a61d7a363ec4fd3d0374afca9afd
176N/A#ifndef SEEN_OBJECT_SNAPPER_H
176N/A#define SEEN_OBJECT_SNAPPER_H
176N/A
176N/A/**
176N/A * \file object-snapper.h
176N/A * \brief Snapping things to objects.
176N/A *
176N/A * Authors:
176N/A * Carl Hetherington <inkscape@carlh.net>
176N/A * Diederik van Lierop <mail@diedenrezi.nl>
176N/A *
176N/A * Copyright (C) 2005 - 2007 Authors
176N/A *
176N/A * Released under GNU GPL, read the file 'COPYING' for more information
176N/A */
176N/A
176N/A#include "snapper.h"
176N/A#include "sp-path.h"
176N/A#include "splivarot.h"
176N/A
3817N/Astruct SPNamedView;
176N/Astruct SPItem;
176N/Astruct SPObject;
176N/A
176N/Anamespace Inkscape
2134N/A{
618N/A
176N/Aclass ObjectSnapper : public Snapper
2134N/A{
844N/A
2134N/Apublic:
176N/A ObjectSnapper(SPNamedView const *nv, NR::Coord const d);
1258N/A ~ObjectSnapper();
176N/A
2899N/A enum DimensionToSnap {
2899N/A GUIDE_TRANSL_SNAP_X, // For snapping a vertical guide (normal in the X-direction) to objects,
3817N/A GUIDE_TRANSL_SNAP_Y, // For snapping a horizontal guide (normal in the Y-direction) to objects
3817N/A ANGLED_GUIDE_TRANSL_SNAP, // For snapping an angled guide, while translating it accross the desktop
3817N/A ANGLED_GUIDE_ROT_SNAP, // For snapping an angled guide, while rotating it around some pivot point
176N/A TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides
176N/A
176N/A void setSnapToItemNode(bool s) {
176N/A _snap_to_itemnode = s;
176N/A }
176N/A
176N/A bool getSnapToItemNode() const {
176N/A return _snap_to_itemnode;
176N/A }
176N/A
176N/A void setSnapToItemPath(bool s) {
176N/A _snap_to_itempath = s;
176N/A }
176N/A
176N/A bool getSnapToItemPath() const {
176N/A return _snap_to_itempath;
176N/A }
176N/A
176N/A void setSnapToBBoxNode(bool s) {
176N/A _snap_to_bboxnode = s;
176N/A }
176N/A
176N/A bool getSnapToBBoxNode() const {
176N/A return _snap_to_bboxnode;
176N/A }
176N/A
176N/A void setSnapToBBoxPath(bool s) {
703N/A _snap_to_bboxpath = s;
703N/A }
703N/A
703N/A bool getSnapToBBoxPath() const {
176N/A return _snap_to_bboxpath;
519N/A }
2134N/A
176N/A void setIncludeItemCenter(bool s) {
176N/A _include_item_center = s;
176N/A }
176N/A
176N/A bool getIncludeItemCenter() const {
2134N/A return _include_item_center;
2134N/A }
2134N/A
2134N/A void setStrictSnapping(bool enabled) {
1639N/A _strict_snapping = enabled;
1392N/A }
176N/A
2134N/A void guideSnap(SnappedConstraints &sc,
176N/A NR::Point const &p,
176N/A NR::Point const &guide_normal) const;
176N/A
176N/A bool ThisSnapperMightSnap() const;
176N/A
176N/Aprivate:
176N/A //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap
176N/A std::vector<SPItem*> *_candidates;
176N/A std::vector<NR::Point> *_points_to_snap_to;
176N/A std::vector<NArtBpath*> *_bpaths_to_snap_to;
176N/A std::vector<Path*> *_paths_to_snap_to;
176N/A void _doFreeSnap(SnappedConstraints &sc,
176N/A Inkscape::Snapper::PointType const &t,
176N/A NR::Point const &p,
176N/A bool const &first_point,
176N/A std::vector<NR::Point> &points_to_snap,
176N/A std::list<SPItem const *> const &it) const;
176N/A
176N/A void _doConstrainedSnap(SnappedConstraints &sc,
2134N/A Inkscape::Snapper::PointType const &t,
2134N/A NR::Point const &p,
414N/A bool const &first_point,
176N/A std::vector<NR::Point> &points_to_snap,
176N/A ConstraintLine const &c,
414N/A std::list<SPItem const *> const &it) const;
414N/A
414N/A void _findCandidates(SPObject* r,
414N/A std::list<SPItem const *> const &it,
414N/A bool const &first_point,
176N/A std::vector<NR::Point> &points_to_snap,
176N/A DimensionToSnap const snap_dim) const;
414N/A
414N/A void _snapNodes(SnappedConstraints &sc,
414N/A Inkscape::Snapper::PointType const &t,
414N/A NR::Point const &p,
414N/A bool const &first_point) const;
176N/A
176N/A void _snapTranslatingGuideToNodes(SnappedConstraints &sc,
414N/A Inkscape::Snapper::PointType const &t,
414N/A NR::Point const &p,
414N/A NR::Point const &guide_normal) const;
414N/A
414N/A void _collectNodes(Inkscape::Snapper::PointType const &t,
176N/A bool const &first_point) const;
176N/A
414N/A void _snapPaths(SnappedConstraints &sc,
414N/A Inkscape::Snapper::PointType const &t,
176N/A NR::Point const &p,
2134N/A bool const &first_point) const;
2134N/A
2134N/A void _snapPathsConstrained(SnappedConstraints &sc,
2134N/A Inkscape::Snapper::PointType const &t,
2134N/A NR::Point const &p,
414N/A bool const &first_point,
414N/A ConstraintLine const &c) const;
176N/A
176N/A void _collectPaths(Inkscape::Snapper::PointType const &t,
176N/A bool const &first_point) const;
176N/A void _clear_paths() const;
176N/A
414N/A bool _snap_to_itemnode;
176N/A bool _snap_to_itempath;
414N/A bool _snap_to_bboxnode;
414N/A bool _snap_to_bboxpath;
414N/A
414N/A //If enabled, then bbox corners will only snap to bboxes,
414N/A //and nodes will only snap to nodes and paths. We will not
414N/A //snap bbox corners to nodes, or nodes to bboxes.
176N/A //(snapping to grids and guides is not affected by this)
2134N/A bool _strict_snapping;
2134N/A bool _include_item_center;
414N/A};
414N/A
414N/A}
414N/A
414N/A#endif
414N/A