diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index 7e7e2592194627c298b790c2280530b7eb127b71..43651f002405e12ced35ea1743a6862668ec5bfb 100644 (file)
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
* Authors:
* Carl Hetherington <inkscape@carlh.net>
* Diederik van Lierop <mail@diedenrezi.nl>
* Authors:
* Carl Hetherington <inkscape@carlh.net>
* Diederik van Lierop <mail@diedenrezi.nl>
+ * Jon A. Cruz <jon@joncruz.org>
+ * Abhishek Sharma
*
* Copyright (C) 2005 - 2010 Authors
*
*
* Copyright (C) 2005 - 2010 Authors
*
Geom::Rect bbox_to_snap_incl = bbox_to_snap; // _incl means: will include the snapper tolerance
bbox_to_snap_incl.expandBy(getSnapperTolerance()); // see?
Geom::Rect bbox_to_snap_incl = bbox_to_snap; // _incl means: will include the snapper tolerance
bbox_to_snap_incl.expandBy(getSnapperTolerance()); // see?
- for (SPObject* o = sp_object_first_child(parent); o != NULL; o = SP_OBJECT_NEXT(o)) {
+ for ( SPObject *o = parent->firstChild(); o; o = o->getNext() ) {
+ g_assert(_snapmanager->getDesktop() != NULL);
if (SP_IS_ITEM(o) && !(_snapmanager->getDesktop()->itemIsHidden(SP_ITEM(o)) && !clip_or_mask)) {
// Snapping to items in a locked layer is allowed
// Don't snap to hidden objects, unless they're a clipped path or a mask
if (SP_IS_ITEM(o) && !(_snapmanager->getDesktop()->itemIsHidden(SP_ITEM(o)) && !clip_or_mask)) {
// Snapping to items in a locked layer is allowed
// Don't snap to hidden objects, unless they're a clipped path or a mask
// we should also consider that path or mask for snapping to
obj = SP_OBJECT(item->clip_ref->getObject());
if (obj) {
// we should also consider that path or mask for snapping to
obj = SP_OBJECT(item->clip_ref->getObject());
if (obj) {
- _findCandidates(obj, it, false, bbox_to_snap, true, sp_item_i2doc_affine(item));
+ _findCandidates(obj, it, false, bbox_to_snap, true, item->i2doc_affine());
}
obj = SP_OBJECT(item->mask_ref->getObject());
if (obj) {
}
obj = SP_OBJECT(item->mask_ref->getObject());
if (obj) {
- _findCandidates(obj, it, false, bbox_to_snap, true, sp_item_i2doc_affine(item));
+ _findCandidates(obj, it, false, bbox_to_snap, true, item->i2doc_affine());
}
}
}
}
}
}
if (clip_or_mask) {
// Oh oh, this will get ugly. We cannot use sp_item_i2d_affine directly because we need to
// insert an additional transformation in document coordinates (code copied from sp_item_i2d_affine)
if (clip_or_mask) {
// Oh oh, this will get ugly. We cannot use sp_item_i2d_affine directly because we need to
// insert an additional transformation in document coordinates (code copied from sp_item_i2d_affine)
- sp_item_invoke_bbox(item,
- bbox_of_item,
- sp_item_i2doc_affine(item) * additional_affine * _snapmanager->getDesktop()->doc2dt(),
+ item->invoke_bbox(bbox_of_item,
+ item->i2doc_affine() * additional_affine * _snapmanager->getDesktop()->doc2dt(),
true);
} else {
true);
} else {
- sp_item_invoke_bbox(item, bbox_of_item, sp_item_i2d_affine(item), true);
+ item->invoke_bbox( bbox_of_item, item->i2d_affine(), true);
}
if (bbox_of_item) {
// See if the item is within range
}
if (bbox_of_item) {
// See if the item is within range
}
}
}
}
- sp_item_snappoints(root_item, *_points_to_snap_to, &_snapmanager->snapprefs);
+ root_item->getSnappoints(*_points_to_snap_to, &_snapmanager->snapprefs);
// restore the original snap preferences
_snapmanager->snapprefs.setSnapIntersectionCS(old_pref);
// restore the original snap preferences
_snapmanager->snapprefs.setSnapIntersectionCS(old_pref);
// Discard the bbox of a clipped path / mask, because we don't want to snap to both the bbox
// of the item AND the bbox of the clipping path at the same time
if (!(*i).clip_or_mask) {
// Discard the bbox of a clipped path / mask, because we don't want to snap to both the bbox
// of the item AND the bbox of the clipping path at the same time
if (!(*i).clip_or_mask) {
- Geom::OptRect b = sp_item_bbox_desktop(root_item, bbox_type);
+ Geom::OptRect b = root_item->getBboxDesktop(bbox_type);
getBBoxPoints(b, _points_to_snap_to, true, _snapmanager->snapprefs.getSnapToBBoxNode(), _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints(), _snapmanager->snapprefs.getSnapBBoxMidpoints());
}
}
getBBoxPoints(b, _points_to_snap_to, true, _snapmanager->snapprefs.getSnapToBBoxNode(), _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints(), _snapmanager->snapprefs.getSnapBBoxMidpoints());
}
}
{
// Iterate through all nodes, find out which one is the closest to p, and snap to it!
{
// Iterate through all nodes, find out which one is the closest to p, and snap to it!
- _collectNodes(p.getSourceType(), p.getSourceNum() == 0);
+ _collectNodes(p.getSourceType(), p.getSourceNum() <= 0);
if (unselected_nodes != NULL && unselected_nodes->size() > 0) {
g_assert(_points_to_snap_to != NULL);
if (unselected_nodes != NULL && unselected_nodes->size() > 0) {
g_assert(_points_to_snap_to != NULL);
* Returns index of first NR_END bpath in array.
*/
* Returns index of first NR_END bpath in array.
*/
-void Inkscape::ObjectSnapper::_collectPaths(Geom::Point p,
+void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/,
Inkscape::SnapSourceType const source_type,
bool const &first_point) const
{
Inkscape::SnapSourceType const source_type,
bool const &first_point) const
{
root_item = sp_use_root(SP_USE((*i).item));
g_return_if_fail(root_item);
} else {
root_item = sp_use_root(SP_USE((*i).item));
g_return_if_fail(root_item);
} else {
- i2doc = sp_item_i2doc_affine((*i).item);
+ i2doc = (*i).item->i2doc_affine();
root_item = (*i).item;
}
root_item = (*i).item;
}
// Geom::PathVector *pv = pathvector_for_curve(root_item, curve, true, true, Geom::identity(), (*i).additional_affine);
Geom::PathVector *pv = new Geom::PathVector(curve->get_pathvector());
// Geom::PathVector *pv = pathvector_for_curve(root_item, curve, true, true, Geom::identity(), (*i).additional_affine);
Geom::PathVector *pv = new Geom::PathVector(curve->get_pathvector());
- (*pv) *= sp_item_i2d_affine(root_item) * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt(); // (_edit_transform * _i2d_transform);
+ (*pv) *= root_item->i2d_affine() * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt(); // (_edit_transform * _i2d_transform);
_paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(pv, SNAPTARGET_PATH, Geom::OptRect())); // Perhaps for speed, get a reference to the Geom::pathvector, and store the transformation besides it.
curve->unref();
_paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(pv, SNAPTARGET_PATH, Geom::OptRect())); // Perhaps for speed, get a reference to the Geom::pathvector, and store the transformation besides it.
curve->unref();
// of the item AND the bbox of the clipping path at the same time
if (!(*i).clip_or_mask) {
Geom::OptRect rect;
// of the item AND the bbox of the clipping path at the same time
if (!(*i).clip_or_mask) {
Geom::OptRect rect;
- sp_item_invoke_bbox(root_item, rect, i2doc, TRUE, bbox_type);
+ root_item->invoke_bbox( rect, i2doc, TRUE, bbox_type);
if (rect) {
Geom::PathVector *path = _getPathvFromRect(*rect);
if (rect) {
Geom::PathVector *path = _getPathvFromRect(*rect);
- rect = sp_item_bbox_desktop(root_item, bbox_type);
+ rect = root_item->getBboxDesktop(bbox_type);
_paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(path, SNAPTARGET_BBOX_EDGE, rect));
}
}
_paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(path, SNAPTARGET_BBOX_EDGE, rect));
}
}
std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes,
SPPath const *selected_path) const
{
std::vector<Inkscape::SnapCandidatePoint> *unselected_nodes,
SPPath const *selected_path) const
{
- _collectPaths(p.getPoint(), p.getSourceType(), p.getSourceNum() == 0);
+ _collectPaths(p.getPoint(), p.getSourceType(), p.getSourceNum() <= 0);
// Now we can finally do the real snapping, using the paths collected above
g_assert(_snapmanager->getDesktop() != NULL);
// Now we can finally do the real snapping, using the paths collected above
g_assert(_snapmanager->getDesktop() != NULL);
bool const node_tool_active = _snapmanager->snapprefs.getSnapToItemPath() && selected_path != NULL;
bool const node_tool_active = _snapmanager->snapprefs.getSnapToItemPath() && selected_path != NULL;
- if (p.getSourceNum() == 0) {
+ if (p.getSourceNum() <= 0) {
/* findCandidates() is used for snapping to both paths and nodes. It ignores the path that is
* currently being edited, because that path requires special care: when snapping to nodes
* only the unselected nodes of that path should be considered, and these will be passed on separately.
/* findCandidates() is used for snapping to both paths and nodes. It ignores the path that is
* currently being edited, because that path requires special care: when snapping to nodes
* only the unselected nodes of that path should be considered, and these will be passed on separately.
Geom::Point const &p_proj_on_constraint) const
{
Geom::Point const &p_proj_on_constraint) const
{
- _collectPaths(p_proj_on_constraint, p.getSourceType(), p.getSourceNum() == 0);
+ _collectPaths(p_proj_on_constraint, p.getSourceType(), p.getSourceNum() <= 0);
// Now we can finally do the real snapping, using the paths collected above
// Now we can finally do the real snapping, using the paths collected above
}
//Geom::crossings will not consider the closing segment apparently, so we'll handle that separately here
}
//Geom::crossings will not consider the closing segment apparently, so we'll handle that separately here
+ //TODO: This should have been fixed in rev. #9859, which makes this workaround obsolete
for(Geom::PathVector::iterator it_pv = k->path_vector->begin(); it_pv != k->path_vector->end(); ++it_pv) {
if (it_pv->closed()) {
// Get the closing linesegment and convert it to a path
for(Geom::PathVector::iterator it_pv = k->path_vector->begin(); it_pv != k->path_vector->end(); ++it_pv) {
if (it_pv->closed()) {
// Get the closing linesegment and convert it to a path
}
/* Get a list of all the SPItems that we will try to snap to */
}
/* Get a list of all the SPItems that we will try to snap to */
- if (p.getSourceNum() == 0) {
+ if (p.getSourceNum() <= 0) {
Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(p.getPoint(), p.getPoint());
Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(p.getPoint(), p.getPoint());
- _findCandidates(sp_document_root(_snapmanager->getDocument()), it, p.getSourceNum() == 0, local_bbox_to_snap, false, Geom::identity());
+ _findCandidates(_snapmanager->getDocument()->getRoot(), it, p.getSourceNum() <= 0, local_bbox_to_snap, false, Geom::identity());
}
// TODO: Argh, UGLY! Get rid of this here, move this logic to the snap manager
}
// TODO: Argh, UGLY! Get rid of this here, move this logic to the snap manager
Geom::Point pp = c.projection(p.getPoint());
/* Get a list of all the SPItems that we will try to snap to */
Geom::Point pp = c.projection(p.getPoint());
/* Get a list of all the SPItems that we will try to snap to */
- if (p.getSourceNum() == 0) {
+ if (p.getSourceNum() <= 0) {
Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(pp, pp);
Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(pp, pp);
- _findCandidates(sp_document_root(_snapmanager->getDocument()), it, p.getSourceNum() == 0, local_bbox_to_snap, false, Geom::identity());
+ _findCandidates(_snapmanager->getDocument()->getRoot(), it, p.getSourceNum() <= 0, local_bbox_to_snap, false, Geom::identity());
}
// A constrained snap, is a snap in only one degree of freedom (specified by the constraint line).
}
// A constrained snap, is a snap in only one degree of freedom (specified by the constraint line).
std::vector<SPItem*> cand;
std::vector<SPItem const *> const it; //just an empty list
std::vector<SPItem*> cand;
std::vector<SPItem const *> const it; //just an empty list
- _findCandidates(sp_document_root(_snapmanager->getDocument()), &it, true, Geom::Rect(p, p), false, Geom::identity());
+ _findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity());
_snapTranslatingGuide(sc, p, guide_normal);
}
_snapTranslatingGuide(sc, p, guide_normal);
}
std::vector<SPItem*> cand;
std::vector<SPItem const *> const it; //just an empty list
std::vector<SPItem*> cand;
std::vector<SPItem const *> const it; //just an empty list
- _findCandidates(sp_document_root(_snapmanager->getDocument()), &it, true, Geom::Rect(p, p), false, Geom::identity());
+ _findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity());
_snapTranslatingGuide(sc, p, guide_normal);
}
_snapTranslatingGuide(sc, p, guide_normal);
}
Geom::PathVector* Inkscape::ObjectSnapper::_getBorderPathv() const
{
Geom::PathVector* Inkscape::ObjectSnapper::_getBorderPathv() const
{
- Geom::Rect const border_rect = Geom::Rect(Geom::Point(0,0), Geom::Point(sp_document_width(_snapmanager->getDocument()),sp_document_height(_snapmanager->getDocument())));
+ Geom::Rect const border_rect = Geom::Rect(Geom::Point(0,0), Geom::Point((_snapmanager->getDocument())->getWidth(),(_snapmanager->getDocument())->getHeight()));
return _getPathvFromRect(border_rect);
}
return _getPathvFromRect(border_rect);
}
@@ -833,8 +836,8 @@ Geom::PathVector* Inkscape::ObjectSnapper::_getPathvFromRect(Geom::Rect const re
void Inkscape::ObjectSnapper::_getBorderNodes(std::vector<SnapCandidatePoint> *points) const
{
void Inkscape::ObjectSnapper::_getBorderNodes(std::vector<SnapCandidatePoint> *points) const
{
- Geom::Coord w = sp_document_width(_snapmanager->getDocument());
- Geom::Coord h = sp_document_height(_snapmanager->getDocument());
+ Geom::Coord w = (_snapmanager->getDocument())->getWidth();
+ Geom::Coord h = (_snapmanager->getDocument())->getHeight();
points->push_back(Inkscape::SnapCandidatePoint(Geom::Point(0,0), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER));
points->push_back(Inkscape::SnapCandidatePoint(Geom::Point(0,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER));
points->push_back(Inkscape::SnapCandidatePoint(Geom::Point(w,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER));
points->push_back(Inkscape::SnapCandidatePoint(Geom::Point(0,0), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER));
points->push_back(Inkscape::SnapCandidatePoint(Geom::Point(0,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER));
points->push_back(Inkscape::SnapCandidatePoint(Geom::Point(w,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER));
// collect the corners of the bounding box
for ( unsigned k = 0 ; k < 4 ; k++ ) {
if (includeCorners) {
// collect the corners of the bounding box
for ( unsigned k = 0 ; k < 4 ; k++ ) {
if (includeCorners) {
- points->push_back(Inkscape::SnapCandidatePoint(bbox->corner(k), Inkscape::SNAPSOURCE_BBOX_CORNER, 0, Inkscape::SNAPTARGET_BBOX_CORNER, *bbox));
+ points->push_back(Inkscape::SnapCandidatePoint(bbox->corner(k), Inkscape::SNAPSOURCE_BBOX_CORNER, -1, Inkscape::SNAPTARGET_BBOX_CORNER, *bbox));
}
// optionally, collect the midpoints of the bounding box's edges too
if (includeLineMidpoints) {
}
// optionally, collect the midpoints of the bounding box's edges too
if (includeLineMidpoints) {
- points->push_back(Inkscape::SnapCandidatePoint((bbox->corner(k) + bbox->corner((k+1) % 4))/2, Inkscape::SNAPSOURCE_BBOX_EDGE_MIDPOINT, 0, Inkscape::SNAPTARGET_BBOX_EDGE_MIDPOINT, *bbox));
+ points->push_back(Inkscape::SnapCandidatePoint((bbox->corner(k) + bbox->corner((k+1) % 4))/2, Inkscape::SNAPSOURCE_BBOX_EDGE_MIDPOINT, -1, Inkscape::SNAPTARGET_BBOX_EDGE_MIDPOINT, *bbox));
}
}
if (includeObjectMidpoints) {
}
}
if (includeObjectMidpoints) {
- points->push_back(Inkscape::SnapCandidatePoint(bbox->midpoint(), Inkscape::SNAPSOURCE_BBOX_MIDPOINT, 0, Inkscape::SNAPTARGET_BBOX_MIDPOINT, *bbox));
+ points->push_back(Inkscape::SnapCandidatePoint(bbox->midpoint(), Inkscape::SNAPSOURCE_BBOX_MIDPOINT, -1, Inkscape::SNAPTARGET_BBOX_MIDPOINT, *bbox));
}
}
}
}
}
}