From 64fb7253a1d2771c4f844d1c2266a90f328895b5 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Wed, 30 Jul 2014 22:47:29 +0200 Subject: Limit the number of paths to be used as snap targets, to keep Inkscape responsive in very complex drawings Fixed bugs: - https://launchpad.net/bugs/1348959 (bzr r13483) --- src/object-snapper.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 3b8956bc8..0f7aa6368 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -147,6 +147,10 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // For debugging: print the id of the candidate to the console // SPObject *obj = (SPObject*)item; // std::cout << "Snap candidate added: " << obj->getId() << std::endl; + if (_candidates->size() > 200) { // This makes Inkscape crawl already + std::cout << "Warning: limit of 200 snap target paths reached, some will be ignored" << std::endl; + break; + } } } } -- cgit v1.2.3 From 991f33ed582722d64ae964986570cd20379a4c56 Mon Sep 17 00:00:00 2001 From: "Liam P. White" Date: Tue, 9 Sep 2014 15:10:27 -0400 Subject: Fix bug #1357411 Fixed bugs: - https://launchpad.net/bugs/1357411 (bzr r13550) --- src/object-snapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 0f7aa6368..9ff6df3bf 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -677,7 +677,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(IntermSnapResults &isr, (*p_inters) = dt->doc2dt(*p_inters); // Construct a snapped point Geom::Coord dist = Geom::L2(p.getPoint() - *p_inters); - SnappedPoint s = SnappedPoint(*p_inters, p.getSourceType(), p.getSourceNum(), k->target_type, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), true, k->target_bbox);; + SnappedPoint s = SnappedPoint(*p_inters, p.getSourceType(), p.getSourceNum(), k->target_type, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), true, false, k->target_bbox); // Store the snapped point if (dist <= tolerance) { // If the intersection is within snapping range, then we might snap to it isr.points.push_back(s); -- cgit v1.2.3 From acb22a496132ae58d7a500b4f92e16786d8a27c9 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 12 Oct 2014 17:59:21 +0200 Subject: object-snapper.cpp : make the logic easier to read (use else-clause as default initialization value) (bzr r13601) --- src/object-snapper.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 9ff6df3bf..2b29814b0 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -289,7 +289,7 @@ void Inkscape::ObjectSnapper::_snapNodes(IntermSnapResults &isr, for (std::vector::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); ++k) { if (_allowSourceToSnapToTarget(p.getSourceType(), (*k).getTargetType(), strict_snapping)) { Geom::Point target_pt = (*k).getPoint(); - Geom::Coord dist = Geom::infinity(); + Geom::Coord dist = Geom::L2(target_pt - p.getPoint()); // Default: free (unconstrained) snapping if (!c.isUndefined()) { // We're snapping to nodes along a constraint only, so find out if this node // is at the constraint, while allowing for a small margin @@ -299,9 +299,6 @@ void Inkscape::ObjectSnapper::_snapNodes(IntermSnapResults &isr, continue; } dist = Geom::L2(target_pt - p_proj_on_constraint); - } else { - // Free (unconstrained) snapping - dist = Geom::L2(target_pt - p.getPoint()); } if (dist < getSnapperTolerance() && dist < s.getSnapDistance()) { -- cgit v1.2.3 From e179290f049d5c34ae2b9c05fdfeab830b7c39e7 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Mon, 10 Nov 2014 09:39:33 -0800 Subject: Removed SP_USE/SP_IS_USE Gtk-ish macros and cleaned affected files. (bzr r13700) --- src/object-snapper.cpp | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 2b29814b0..338f91463 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -91,7 +91,8 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, for ( SPObject *o = parent->firstChild(); o; o = o->getNext() ) { g_assert(dt != NULL); - if (SP_IS_ITEM(o) && !(dt->itemIsHidden(SP_ITEM(o)) && !clip_or_mask)) { + SPItem *item = dynamic_cast(o); + if (item && !(dt->itemIsHidden(item) && !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 /* See if this item is on the ignore list */ @@ -104,23 +105,22 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, } if (it == NULL || i == it->end()) { - SPItem *item = SP_ITEM(o); if (item) { if (!clip_or_mask) { // cannot clip or mask more than once // The current item is not a clipping path or a mask, but might // still be the subject of clipping or masking itself ; if so, then // we should also consider that path or mask for snapping to - SPObject *obj = SP_OBJECT(item->clip_ref ? item->clip_ref->getObject() : NULL); + SPObject *obj = item->clip_ref ? item->clip_ref->getObject() : NULL; if (obj && _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH_CLIP)) { _findCandidates(obj, it, false, bbox_to_snap, true, item->i2doc_affine()); } - obj = SP_OBJECT(item->mask_ref ? item->mask_ref->getObject() : NULL); + obj = item->mask_ref ? item->mask_ref->getObject() : NULL; if (obj && _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH_MASK)) { _findCandidates(obj, it, false, bbox_to_snap, true, item->i2doc_affine()); } } - if (SP_IS_GROUP(o)) { + if (dynamic_cast(item)) { _findCandidates(o, it, false, bbox_to_snap, clip_or_mask, additional_affine); } else { Geom::OptRect bbox_of_item; @@ -197,8 +197,10 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, for (std::vector::const_iterator i = _candidates->begin(); i != _candidates->end(); ++i) { //Geom::Affine i2doc(Geom::identity()); SPItem *root_item = (*i).item; - if (SP_IS_USE((*i).item)) { - root_item = SP_USE((*i).item)->root(); + + SPUse *use = dynamic_cast((*i).item); + if (use) { + root_item = use->root(); } g_return_if_fail(root_item); @@ -382,9 +384,10 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, Geom::Affine i2doc(Geom::identity()); SPItem *root_item = NULL; /* We might have a clone at hand, so make sure we get the root item */ - if (SP_IS_USE((*i).item)) { - i2doc = SP_USE((*i).item)->get_root_transform(); - root_item = SP_USE((*i).item)->root(); + SPUse *use = dynamic_cast((*i).item); + if (use) { + i2doc = use->get_root_transform(); + root_item = use->root(); g_return_if_fail(root_item); } else { i2doc = (*i).item->i2doc_affine(); @@ -396,7 +399,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, //Add the item's path to snap to if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_TEXT_BASELINE)) { if (p_is_other || p_is_a_node || (!_snapmanager->snapprefs.getStrictSnapping() && p_is_a_bbox)) { - if (SP_IS_TEXT(root_item) || SP_IS_FLOWTEXT(root_item)) { + if (dynamic_cast(root_item) || dynamic_cast(root_item)) { if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_TEXT_BASELINE)) { // Snap to the text baseline Text::Layout const *layout = te_get_layout(static_cast(root_item)); @@ -411,15 +414,17 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, // 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)) { - very_complex_path = SP_PATH(root_item)->nodesInPath() > 500; + SPPath *path = dynamic_cast(root_item); + if (path) { + very_complex_path = path->nodesInPath() > 500; } if (!very_complex_path && root_item && _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION)) { SPCurve *curve = NULL; - if (SP_IS_SHAPE(root_item)) { - curve = SP_SHAPE(root_item)->getCurve(); - }/* else if (SP_IS_TEXT(root_item) || SP_IS_FLOWTEXT(root_item)) { + SPShape *shape = dynamic_cast(root_item); + if (shape) { + curve = shape->getCurve(); + }/* else if (dynamic_cast(root_item) || dynamic_cast(root_item)) { curve = te_get_layout(root_item)->convertToCurves(); }*/ if (curve) { @@ -711,10 +716,11 @@ void Inkscape::ObjectSnapper::freeSnap(IntermSnapResults &isr, * That path must not be ignored however when snapping to the paths, so we add it here * manually when applicable */ - SPPath *path = NULL; + SPPath const *path = NULL; if (it != NULL) { - if (it->size() == 1 && SP_IS_PATH(*it->begin())) { - path = SP_PATH(*it->begin()); + SPPath const *tmpPath = dynamic_cast(*it->begin()); + if ((it->size() == 1) && tmpPath) { + path = tmpPath; } // else: *it->begin() might be a SPGroup, e.g. when editing a LPE of text that has been converted to a group of paths // as reported in bug #356743. In that case we can just ignore it, i.e. not snap to this item } -- cgit v1.2.3