object-snapper.cpp revision dbc3752b9b883da019fd06b3a458dd8b21c560f0
/**
* \file object-snapper.cpp
* \brief Snapping things to objects.
*
* Authors:
* Carl Hetherington <inkscape@carlh.net>
*
* Copyright (C) 2005 Authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "libnr/n-art-bpath.h"
#include "libnr/nr-rect-ops.h"
#include "document.h"
#include "sp-namedview.h"
#include "sp-image.h"
#include "sp-item-group.h"
#include "sp-item.h"
#include "sp-use.h"
#include "desktop.h"
#include "inkscape.h"
#include "prefs-utils.h"
#include "sp-text.h"
#include "sp-flowtext.h"
#include "text-editing.h"
_include_item_center(false)
{
}
{
delete _candidates;
delete _points_to_snap_to;
for (std::list<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
delete *k;
}
delete _paths_to_snap_to;
}
/**
* Find all items within snapping range.
* \param r Pointer to the current document
* \param it List of items to ignore
* \param first_point If true then this point is the first one from a whole bunch of points
* \param points_to_snap The whole bunch of points, all from the same selection and having the same transformation
* \param DimensionToSnap Snap in X, Y, or both directions.
*/
bool const &first_point,
DimensionToSnap const snap_dim) const
{
if (ThisSnapperMightSnap()) {
if (first_point) {
_candidates->clear();
}
/* See if this item is on the ignore list */
i++;
}
/* See if the item is within range */
if (SP_IS_GROUP(o)) {
} else {
// Now let's see if any of the snapping points is within
// snapping range of this object
if (b) {
for (std::vector<NR::Point>::const_iterator i = points_to_snap.begin(); i != points_to_snap.end(); i++) {
double d = getDistance();
if (snap_dim == SNAP_X && withinX || snap_dim == SNAP_Y && withinY || snap_dim == SNAP_XY && withinX && withinY) {
//We've found a point that is within snapping range
//of this object, so record it as a candidate
break;
}
}
}
}
}
}
}
}
}
Inkscape::SnappedPoint &s,
bool const &first_point,
DimensionToSnap const snap_dim) const
{
/* FIXME: this seems like a hack. Perhaps Snappers should be
** in SPDesktop rather than SPNamedView?
*/
// Determine the type of bounding box we should snap to
if (_snap_to_bboxnode) {
bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
}
// A point considered for snapping should be either a node, a bbox corner or a guide. Pick only ONE!
g_assert(!(p_is_a_node && p_is_a_bbox || p_is_a_bbox && p_is_a_guide || p_is_a_node && p_is_a_guide));
// Now, let's first collect all points to snap to. If we have a whole bunch of points to snap,
// e.g. when translating an item using the selector tool, then we will only do this for the
// first point and store the collection for later use. This dramatically improves the performance
if (first_point) {
if (SP_IS_USE(*i)) {
} else {
i2doc = sp_item_i2doc_affine(*i);
root_item = *i;
}
if (SP_IS_SHAPE(root_item)) {
} else if (SP_IS_IMAGE(root_item)) {
}
//Collect all nodes so we can snap to them
if (_snap_to_itemnode) {
if (curve) {
int j = 0;
/* Get this node in desktop coordinates */
j++;
}
if (_include_item_center) {
}
}
}
}
//Collect the bounding box's corners so we can snap to them
if (_snap_to_bboxnode) {
if (b) {
for ( unsigned k = 0 ; k < 4 ; k++ ) {
}
}
}
}
}
}
//Do the snapping, using all the nodes and corners collected above
for (std::list<NR::Point>::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) {
/* Try to snap to this node of the path */
switch (snap_dim) {
case SNAP_X:
break;
case SNAP_Y:
break;
case SNAP_XY:
snapped_point = *k;
break;
}
}
}
}
Inkscape::SnappedPoint &s,
bool const &first_point) const
{
/* FIXME: this seems like a hack. Perhaps Snappers should be
** in SPDesktop rather than SPNamedView?
*/
// Determine the type of bounding box we should snap to
if (_snap_to_bboxpath) {
bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
}
// Now, let's first collect all paths to snap to. If we have a whole bunch of points to snap,
// e.g. when translating an item using the selector tool, then we will only do this for the
// first point and store the collection for later use. This dramatically improves the performance
if (first_point) {
for (std::list<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
delete *k;
}
/* Transform the requested snap point to this item's coordinates */
/* We might have a clone at hand, so make sure we get the root item */
if (SP_IS_USE(*i)) {
} else {
i2doc = sp_item_i2doc_affine(*i);
root_item = *i;
}
//Build a list of all paths considered for snapping to
//Add the item's path to snap to
if (_snap_to_itempath) {
if (!(_strict_snapping && !p_is_a_node)) {
// Snapping to the path of characters is very cool, but for a large
// chunk of text this will take ages! So limit snapping to text paths
// containing max. 240 characters. Snapping the bbox will not be affected
bool very_lenghty_prose = false;
}
// On my AMD 3000+, the snapping lag becomes annoying at approx. 240 chars
// which corresponds to a lag of 500 msec. This is for snapping a rect
// to a single line of text.
// Snapping for example to a traced bitmap is also very stressing for
// the CPU, so we'll only snap to paths having no more than 500 nodes
// This also leads to a lag of approx. 500 msec (in my lousy test set-up).
bool very_complex_path = false;
if (SP_IS_PATH(root_item)) {
}
if (!very_lenghty_prose && !very_complex_path) {
}
}
}
//Add the item's bounding box to snap to
if (_snap_to_bboxpath) {
if (!(_strict_snapping && p_is_a_node)) {
//This will get ugly... rect -> curve -> bpath
if (curve) {
if (bpath) {
if (path) {
}
delete bpath;
}
delete curve;
}
}
}
}
}
//Now we can finally do the real snapping, using the paths collected above
for (std::list<Path*>::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) {
if (*k) {
if (first_point) {
}
/* Look for the nearest position on this SPItem to our snap point */
if (o && o->t >= 0 && o->t <= 1) {
/* Convert the nearest point back to desktop coordinates */
}
}
}
}
}
bool const &first_point,
{
if ( NULL == _named_view ) {
return SnappedPoint(p, NR_HUGE);
}
/* Get a list of all the SPItems that we will try to snap to */
if (first_point) {
}
SnappedPoint s(p, NR_HUGE);
if (_snap_to_itemnode || _snap_to_bboxnode) {
}
if (_snap_to_itempath || _snap_to_bboxpath) {
_snapPaths(t, s, p, first_point);
}
return s;
}
Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doConstrainedSnap(Inkscape::Snapper::PointType const &t,
bool const &first_point,
ConstraintLine const &c,
{
/* FIXME: this needs implementing properly; I think we have to do the
** intersection of c with the objects.
*/
}
DimensionToSnap const snap_dim) const
{
if ( NULL == _named_view ) {
return SnappedPoint(p, NR_HUGE);
}
/* Get a list of all the SPItems that we will try to snap to */
SnappedPoint s(p, NR_HUGE);
return s;
}
/**
* \return true if this Snapper will snap at least one kind of point.
*/
{
bool snap_to_something = _snap_to_itempath || _snap_to_itemnode || _snap_to_bboxpath || _snap_to_bboxnode;
}
/*
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 :