Code

part of bug #339660; can not use Add/Rename dialog to create layer with no proper...
[inkscape.git] / src / guide-snapper.cpp
1 /**
2  *  \file guide-snapper.cpp
3  *  \brief Snapping things to guides.
4  *
5  * Authors:
6  *   Lauris Kaplinski <lauris@kaplinski.com>
7  *   Frank Felfe <innerspace@iname.com>
8  *   Carl Hetherington <inkscape@carlh.net>
9  *
10  * Copyright (C) 1999-2002 Authors
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "libnr/nr-values.h"
16 #include "libnr/nr-point-fns.h"
17 #include "sp-namedview.h"
18 #include "desktop.h"
19 #include "sp-guide.h"
21 Inkscape::GuideSnapper::GuideSnapper(SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d)
22 {
24 }
26 /**
27  *  \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels
28  */
29 Geom::Coord Inkscape::GuideSnapper::getSnapperTolerance() const
30 {
31         SPDesktop const *dt = _snapmanager->getDesktop();
32         double const zoom =  dt ? dt->current_zoom() : 1;
33         return _snapmanager->snapprefs.getGuideTolerance() / zoom;
34 }
36 bool Inkscape::GuideSnapper::getSnapperAlwaysSnap() const
37 {
38     return _snapmanager->snapprefs.getGuideTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp
39 }
41 Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Point const &/*p*/) const
42 {
43     LineList s;
45     if ( NULL == _snapmanager->getNamedView() || ThisSnapperMightSnap() == false) {
46         return s;
47     }
49     SPGuide const *guide_to_ignore = _snapmanager->getGuideToIgnore();
51     for (GSList const *l = _snapmanager->getNamedView()->guides; l != NULL; l = l->next) {
52         SPGuide const *g = SP_GUIDE(l->data);
53         if (g != guide_to_ignore) {
54                 s.push_back(std::make_pair(g->normal_to_line, g->point_on_line));
55         }
56     }
58     return s;
59 }
61 /**
62  *  \return true if this Snapper will snap at least one kind of point.
63  */
64 bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const
65 {
66         if (_snapmanager->getNamedView() == NULL) {
67                 return false;
68         }
70         return (_snap_enabled && _snapmanager->snapprefs.getSnapToGuides() && _snapmanager->getNamedView()->showguides);
71 }
73 void Inkscape::GuideSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, SnapSourceType const &source, SnapTargetType const &target, Geom::Point const normal_to_line, Geom::Point const point_on_line) const
74 {
75     SnappedLine dummy = SnappedLine(snapped_point, snapped_distance, source, target, getSnapperTolerance(), getSnapperAlwaysSnap(), normal_to_line, point_on_line);
76     sc.guide_lines.push_back(dummy);
77 }
79 /*
80   Local Variables:
81   mode:c++
82   c-file-style:"stroustrup"
83   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
84   indent-tabs-mode:nil
85   fill-column:99
86   End:
87 */
88 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :