snapper.h revision 1f1db4ce175a4f7109928377193537db929d1202
#ifndef SEEN_SNAPPER_H
#define SEEN_SNAPPER_H
/**
* \brief Snapper class.
*
* Authors:
* Carl Hetherington <inkscape@carlh.net>
* Diederik van Lierop <mail@diedenrezi.nl>
*
* Released under GNU GPL, read the file 'COPYING' for more information.
*/
#include <boost/optional.hpp>
#include <cstdio>
#include <list>
#include "snap-candidate.h"
#include "snapped-point.h"
#include "snapped-line.h"
#include "snapped-curve.h"
struct IntermSnapResults {
};
{
/// Parent for classes that can snap points to something
{
//Snapper() {} //does not seem to be used somewhere
virtual Geom::Coord getSnapperTolerance() const = 0; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom)
virtual bool getSnapperAlwaysSnap() const = 0; //if true, then the snapper will always snap, regardless of its tolerance
/**
* \return true if this Snapper will snap at least one kind of point.
*/
virtual bool ThisSnapperMightSnap() const {return _snap_enabled;} // will likely be overridden by derived classes
// These four methods are only used for grids, for which snapping can be enabled individually
void setEnabled(bool s);
void setSnapVisibleOnly(bool s);
bool getEnabled() const {return _snap_enabled;}
bool getSnapVisibleOnly() const {return _snap_visible_only;}
// Class for storing the constraint for constrained snapping; can be
// - a line (infinite line with origin, running through _point pointing in _direction)
// - a direction (infinite line without origin, i.e. only a direction vector, stored in _direction)
// - a circle (_point denotes the center, _radius doesn't need an explanation, _direction contains
// the vector from the origin to the original untransformed point);
{
// Constructs a direction constraint, e.g. horizontal or vertical but without a specified point
// Constructs a linear constraint
SnapConstraint(Geom::Point const &p, Geom::Point const &d) : _point(p), _direction(d), _radius(0), _type(LINE) {}
// Orthogonal version
SnapConstraint(Geom::Point const &p, Geom::Dim2 const &d) : _point(p), _radius(0), _type(LINE) {_direction = Geom::Point(); _direction[d] = 1.;}
SnapConstraint(Geom::Line const &l) : _point(l.origin()), _direction(l.versor()), _radius(0), _type(LINE) {}
// Constructs a circular constraint
SnapConstraint(Geom::Point const &p, Geom::Point const &d, Geom::Coord const &r) : _point(p), _direction(d), _radius(r), _type(CIRCLE) {}
// Undefined, or empty constraint
return _point;
}
return _direction;
}
return _radius;
}
Geom::Point projection(Geom::Point const &p) const { // returns the projection of p on this constraint
// project on to a circular constraint
if (l > 0) {
} else {
// point to be projected is exactly at the center of the circle, so any point on the circle is a projection
}
// project on to a linear constraint
} else {
printf("WARNING: Bug: trying to find the projection onto an undefined constraint");
}
}
};
SnapConstraint const &/*c*/,
// This is only used for grids, for which snapping can be enabled individually
bool _snap_enabled; ///< true if this snapper is enabled, otherwise false
bool _snap_visible_only;
};
}
#endif /* !SEEN_SNAPPER_H */
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :