From 3638efba5bec8a6afc9211aa6bbe289767d20b38 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Fri, 3 Jun 2011 19:45:55 -0700 Subject: Removed outdated/unsafe SP_DOCUMENT_DEFS macro and reduced usage of SP_ROOT() gtk type function/macro. (bzr r10254) --- src/object-snapper.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 1e2f71c95..682c26869 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -36,6 +36,7 @@ #include "sp-mask.h" #include "helper/geom-curves.h" #include "desktop.h" +#include "sp-root.h" Inkscape::ObjectSnapper::ObjectSnapper(SnapManager *sm, Geom::Coord const d) : Snapper(sm, d) -- cgit v1.2.3 From bdf703831ff93438d49324ab842052ccaf390a5d Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 26 Jun 2011 22:00:36 +0200 Subject: =?UTF-8?q?-=20Add=20a=20third=20group=20of=20snap=20sources/targe?= =?UTF-8?q?ts,=20called=20=C2=A8others=C2=A8=20(before=20we=20had=20only?= =?UTF-8?q?=20=C2=A8bounding=20box=C2=A8=20and=20nodes=20(see=20bug=20#788?= =?UTF-8?q?178)=20-=20Fix=20the=20display=20of=20the=20snap=20source=20-?= =?UTF-8?q?=20Fix=20snapping=20of=20guides=20to=20other=20guides=20&=20gri?= =?UTF-8?q?ds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (bzr r10372) --- src/object-snapper.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 682c26869..3088accd2 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -181,7 +181,7 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, bool p_is_a_node = t & Inkscape::SNAPSOURCE_NODE_CATEGORY; bool p_is_a_bbox = t & Inkscape::SNAPSOURCE_BBOX_CATEGORY; - bool p_is_other = t & Inkscape::SNAPSOURCE_OTHER_CATEGORY; + bool p_is_other = t & Inkscape::SNAPSOURCE_OTHERS_CATEGORY; // 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_other) || (p_is_a_node && p_is_other))); @@ -359,7 +359,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX; bool p_is_a_node = source_type & Inkscape::SNAPSOURCE_NODE_CATEGORY; - bool p_is_other = source_type & Inkscape::SNAPSOURCE_OTHER_CATEGORY; + bool p_is_other = source_type & Inkscape::SNAPSOURCE_OTHERS_CATEGORY; if (_snapmanager->snapprefs.getSnapToBBoxPath()) { Inkscape::Preferences *prefs = Inkscape::Preferences::get(); @@ -369,7 +369,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, } // Consider the page border for snapping - if (_snapmanager->snapprefs.getSnapToPageBorder() && _snapmanager->snapprefs.getSnapModeBBoxOrNodes()) { + if (_snapmanager->snapprefs.getSnapToPageBorder() && _snapmanager->snapprefs.getSnapModeAny()) { Geom::PathVector *border_path = _getBorderPathv(); if (border_path != NULL) { _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(border_path, SNAPTARGET_PAGE_BORDER, Geom::OptRect())); @@ -394,7 +394,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, //Build a list of all paths considered for snapping to //Add the item's path to snap to - if (_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapModeNode()) { + if (_snapmanager->snapprefs.getSnapToItemPath() && (_snapmanager->snapprefs.getSnapModeNode() || _snapmanager->snapprefs.getSnapModeOthers())) { if (p_is_other || !(_snapmanager->snapprefs.getStrictSnapping() && !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 @@ -438,7 +438,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, } //Add the item's bounding box to snap to - if (_snapmanager->snapprefs.getSnapToBBoxPath() && _snapmanager->snapprefs.getSnapModeBBox()) { + if (_snapmanager->snapprefs.getSnapToBBoxPath() && (_snapmanager->snapprefs.getSnapModeBBox() || _snapmanager->snapprefs.getSnapModeOthers())) { if (p_is_other || !(_snapmanager->snapprefs.getStrictSnapping() && p_is_a_node)) { // 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 @@ -572,7 +572,6 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, // Now we can finally do the real snapping, using the paths collected above g_assert(_snapmanager->getDesktop() != NULL); - Geom::Point const p_doc = _snapmanager->getDesktop()->dt2doc(p_proj_on_constraint); Geom::Point direction_vector = c.getDirection(); if (!is_zero(direction_vector)) { @@ -674,16 +673,16 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, bool snap_nodes = (_snapmanager->snapprefs.getSnapModeNode() && ( _snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() || - _snapmanager->snapprefs.getSnapLineMidpoints() || - _snapmanager->snapprefs.getSnapObjectMidpoints() + _snapmanager->snapprefs.getSnapLineMidpoints() )) || (_snapmanager->snapprefs.getSnapModeBBox() && ( _snapmanager->snapprefs.getSnapToBBoxNode() || _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeBBoxOrNodes() && ( + )) || (_snapmanager->snapprefs.getSnapModeAny() && ( _snapmanager->snapprefs.getIncludeItemCenter() || - _snapmanager->snapprefs.getSnapToPageBorder() - )); + _snapmanager->snapprefs.getSnapToPageBorder() || + _snapmanager->snapprefs.getSnapObjectMidpoints() + )) ; if (snap_nodes) { _snapNodes(sc, p, unselected_nodes); @@ -691,7 +690,7 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, if ((_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getSnapToItemPath()) || (_snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxPath()) || - (_snapmanager->snapprefs.getSnapModeBBoxOrNodes() && _snapmanager->snapprefs.getSnapToPageBorder())) { + (_snapmanager->snapprefs.getSnapModeAny() && _snapmanager->snapprefs.getSnapToPageBorder())) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); if (n > 0) { /* While editing a path in the node tool, findCandidates must ignore that path because @@ -741,14 +740,14 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, bool snap_nodes = (_snapmanager->snapprefs.getSnapModeNode() && ( _snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() || - _snapmanager->snapprefs.getSnapLineMidpoints() || - _snapmanager->snapprefs.getSnapObjectMidpoints() + _snapmanager->snapprefs.getSnapLineMidpoints() )) || (_snapmanager->snapprefs.getSnapModeBBox() && ( _snapmanager->snapprefs.getSnapToBBoxNode() || _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeBBoxOrNodes() && ( + )) || (_snapmanager->snapprefs.getSnapModeAny() && ( _snapmanager->snapprefs.getIncludeItemCenter() || + _snapmanager->snapprefs.getSnapObjectMidpoints() || _snapmanager->snapprefs.getSnapToPageBorder() )); @@ -800,16 +799,16 @@ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const _snapmanager->snapprefs.getSnapToItemPath() || _snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() || - _snapmanager->snapprefs.getSnapLineMidpoints() || - _snapmanager->snapprefs.getSnapObjectMidpoints() + _snapmanager->snapprefs.getSnapLineMidpoints() )) || (_snapmanager->snapprefs.getSnapModeBBox() && ( _snapmanager->snapprefs.getSnapToBBoxPath() || _snapmanager->snapprefs.getSnapToBBoxNode() || _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeBBoxOrNodes() && ( + )) || (_snapmanager->snapprefs.getSnapModeAny() && ( _snapmanager->snapprefs.getSnapToPageBorder() || - _snapmanager->snapprefs.getIncludeItemCenter() + _snapmanager->snapprefs.getIncludeItemCenter() || + _snapmanager->snapprefs.getSnapObjectMidpoints() )); return (_snap_enabled && snap_to_something); -- cgit v1.2.3 From 8911d9a8ca0c7f4ef1476b2f056adf2afa4e99cd Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Thu, 30 Jun 2011 22:46:15 +0200 Subject: Implement decent snapping to text (baseline & anchor), and provide a toggle button for this (as requested in LP bug #727281 ) (bzr r10392) --- src/object-snapper.cpp | 230 ++++++++++++++++++++++++++++--------------------- 1 file changed, 131 insertions(+), 99 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 3088accd2..1944f7ffa 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -183,7 +183,7 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, bool p_is_a_bbox = t & Inkscape::SNAPSOURCE_BBOX_CATEGORY; bool p_is_other = t & Inkscape::SNAPSOURCE_OTHERS_CATEGORY; - // A point considered for snapping should be either a node, a bbox corner or a guide. Pick only ONE! + // A point considered for snapping should be either a node, a bbox corner or a guide/other. Pick only ONE! g_assert(!((p_is_a_node && p_is_a_bbox) || (p_is_a_bbox && p_is_other) || (p_is_a_node && p_is_other))); if (_snapmanager->snapprefs.getSnapToBBoxNode() || _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints()) { @@ -282,27 +282,30 @@ void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, SnappedPoint s; bool success = false; + bool strict_snapping = _snapmanager->snapprefs.getStrictSnapping(); for (std::vector::const_iterator k = _points_to_snap_to->begin(); k != _points_to_snap_to->end(); k++) { - Geom::Point target_pt = (*k).getPoint(); - Geom::Coord dist = NR_HUGE; - 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 - if (Geom::L2(target_pt - c.projection(target_pt)) > 1e-9) { - // The distance from the target point to its projection on the constraint - // is too large, so this point is not on the constraint. Skip it! - continue; + if (_allowSourceToSnapToTarget(p.getSourceType(), (*k).getTargetType(), strict_snapping)) { + Geom::Point target_pt = (*k).getPoint(); + Geom::Coord dist = NR_HUGE; + 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 + if (Geom::L2(target_pt - c.projection(target_pt)) > 1e-9) { + // The distance from the target point to its projection on the constraint + // is too large, so this point is not on the constraint. Skip it! + continue; + } + dist = Geom::L2(target_pt - p_proj_on_constraint); + } else { + // Free (unconstrained) snapping + dist = Geom::L2(target_pt - p.getPoint()); } - 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()) { - s = SnappedPoint(target_pt, p.getSourceType(), p.getSourceNum(), (*k).getTargetType(), dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, true, (*k).getTargetBBox()); - success = true; + if (dist < getSnapperTolerance() && dist < s.getSnapDistance()) { + s = SnappedPoint(target_pt, p.getSourceType(), p.getSourceNum(), (*k).getTargetType(), dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, true, (*k).getTargetBBox()); + success = true; + } } } @@ -394,44 +397,46 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, //Build a list of all paths considered for snapping to //Add the item's path to snap to - if (_snapmanager->snapprefs.getSnapToItemPath() && (_snapmanager->snapprefs.getSnapModeNode() || _snapmanager->snapprefs.getSnapModeOthers())) { + if ((_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapModeNode()) || + (_snapmanager->snapprefs.getSnapTextBaseline() && (_snapmanager->snapprefs.getSnapModeNode() || _snapmanager->snapprefs.getSnapToItemPath())) ) { if (p_is_other || !(_snapmanager->snapprefs.getStrictSnapping() && !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; if (SP_IS_TEXT(root_item) || SP_IS_FLOWTEXT(root_item)) { - very_lenghty_prose = sp_text_get_length(SP_TEXT(root_item)) > 240; - } - // 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)) { - very_complex_path = sp_nodes_in_path(SP_PATH(root_item)) > 500; - } - - if (!very_lenghty_prose && !very_complex_path && root_item) { - 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)) { - curve = te_get_layout(root_item)->convertToCurves(); + if (_snapmanager->snapprefs.getSnapTextBaseline()) { + // Snap to the text baseline + Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) root_item); + if (layout != NULL && layout->outputExists()) { + Geom::PathVector *pv = new Geom::PathVector(); + pv->push_back(layout->baseline() * root_item->i2d_affine() * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt()); + _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(pv, SNAPTARGET_TEXT_BASELINE, Geom::OptRect())); + } + } + } else { + // Snapping for example to a traced bitmap is 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)) { + very_complex_path = sp_nodes_in_path(SP_PATH(root_item)) > 500; } - if (curve) { - // We will get our own copy of the pathvector, which must be freed at some point - // Geom::PathVector *pv = pathvector_for_curve(root_item, curve, true, true, Geom::identity(), (*i).additional_affine); + if (!very_complex_path && root_item && (_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapModeNode())) { + 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)) { + curve = te_get_layout(root_item)->convertToCurves(); + }*/ + if (curve) { + // We will get our own copy of the pathvector, which must be freed at some point + + // 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) *= root_item->i2d_affine() * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt(); // (_edit_transform * _i2d_transform); + Geom::PathVector *pv = new Geom::PathVector(curve->get_pathvector()); + (*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(); + } } } } @@ -490,54 +495,58 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, int num_path = 0; int num_segm = 0; - for (std::vector::const_iterator it_p = _paths_to_snap_to->begin(); it_p != _paths_to_snap_to->end(); it_p++) { - bool const being_edited = node_tool_active && (*it_p).currently_being_edited; - //if true then this pathvector it_pv is currently being edited in the node tool - - for(Geom::PathVector::iterator it_pv = (it_p->path_vector)->begin(); it_pv != (it_p->path_vector)->end(); ++it_pv) { - // Find a nearest point for each curve within this path - // n curves will return n time values with 0 <= t <= 1 - std::vector anp = (*it_pv).nearestPointPerCurve(p_doc); + bool strict_snapping = _snapmanager->snapprefs.getStrictSnapping(); - std::vector::const_iterator np = anp.begin(); - unsigned int index = 0; - for (; np != anp.end(); np++, index++) { - Geom::Curve const *curve = &((*it_pv).at_index(index)); - Geom::Point const sp_doc = curve->pointAt(*np); - - bool c1 = true; - bool c2 = true; - if (being_edited) { - /* If the path is being edited, then we should only snap though to stationary pieces of the path - * and not to the pieces that are being dragged around. This way we avoid - * self-snapping. For this we check whether the nodes at both ends of the current - * piece are unselected; if they are then this piece must be stationary - */ - g_assert(unselected_nodes != NULL); - Geom::Point start_pt = _snapmanager->getDesktop()->doc2dt(curve->pointAt(0)); - Geom::Point end_pt = _snapmanager->getDesktop()->doc2dt(curve->pointAt(1)); - c1 = isUnselectedNode(start_pt, unselected_nodes); - c2 = isUnselectedNode(end_pt, unselected_nodes); - /* Unfortunately, this might yield false positives for coincident nodes. Inkscape might therefore mistakenly - * snap to path segments that are not stationary. There are at least two possible ways to overcome this: - * - Linking the individual nodes of the SPPath we have here, to the nodes of the NodePath::SubPath class as being - * used in sp_nodepath_selected_nodes_move. This class has a member variable called "selected". For this the nodes - * should be in the exact same order for both classes, so we can index them - * - Replacing the SPPath being used here by the the NodePath::SubPath class; but how? - */ - } + for (std::vector::const_iterator it_p = _paths_to_snap_to->begin(); it_p != _paths_to_snap_to->end(); it_p++) { + if (_allowSourceToSnapToTarget(p.getSourceType(), (*it_p).target_type, strict_snapping)) { + bool const being_edited = node_tool_active && (*it_p).currently_being_edited; + //if true then this pathvector it_pv is currently being edited in the node tool + + for(Geom::PathVector::iterator it_pv = (it_p->path_vector)->begin(); it_pv != (it_p->path_vector)->end(); ++it_pv) { + // Find a nearest point for each curve within this path + // n curves will return n time values with 0 <= t <= 1 + std::vector anp = (*it_pv).nearestPointPerCurve(p_doc); + + std::vector::const_iterator np = anp.begin(); + unsigned int index = 0; + for (; np != anp.end(); np++, index++) { + Geom::Curve const *curve = &((*it_pv).at_index(index)); + Geom::Point const sp_doc = curve->pointAt(*np); + + bool c1 = true; + bool c2 = true; + if (being_edited) { + /* If the path is being edited, then we should only snap though to stationary pieces of the path + * and not to the pieces that are being dragged around. This way we avoid + * self-snapping. For this we check whether the nodes at both ends of the current + * piece are unselected; if they are then this piece must be stationary + */ + g_assert(unselected_nodes != NULL); + Geom::Point start_pt = _snapmanager->getDesktop()->doc2dt(curve->pointAt(0)); + Geom::Point end_pt = _snapmanager->getDesktop()->doc2dt(curve->pointAt(1)); + c1 = isUnselectedNode(start_pt, unselected_nodes); + c2 = isUnselectedNode(end_pt, unselected_nodes); + /* Unfortunately, this might yield false positives for coincident nodes. Inkscape might therefore mistakenly + * snap to path segments that are not stationary. There are at least two possible ways to overcome this: + * - Linking the individual nodes of the SPPath we have here, to the nodes of the NodePath::SubPath class as being + * used in sp_nodepath_selected_nodes_move. This class has a member variable called "selected". For this the nodes + * should be in the exact same order for both classes, so we can index them + * - Replacing the SPPath being used here by the the NodePath::SubPath class; but how? + */ + } - Geom::Point const sp_dt = _snapmanager->getDesktop()->doc2dt(sp_doc); - if (!being_edited || (c1 && c2)) { - Geom::Coord const dist = Geom::distance(sp_doc, p_doc); - if (dist < getSnapperTolerance()) { - sc.curves.push_back(Inkscape::SnappedCurve(sp_dt, num_path, num_segm, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); + Geom::Point const sp_dt = _snapmanager->getDesktop()->doc2dt(sp_doc); + if (!being_edited || (c1 && c2)) { + Geom::Coord const dist = Geom::distance(sp_doc, p_doc); + if (dist < getSnapperTolerance()) { + sc.curves.push_back(Inkscape::SnappedCurve(sp_dt, num_path, num_segm, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); + } } } - } - num_segm++; - } // End of: for (Geom::PathVector::iterator ....) - num_path++; + num_segm++; + } // End of: for (Geom::PathVector::iterator ....) + num_path++; + } } } @@ -599,10 +608,12 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, } // Length of constraint_path will always be one + bool strict_snapping = _snapmanager->snapprefs.getStrictSnapping(); + // Find all intersections of the constrained path with the snap target candidates std::vector intersections; for (std::vector::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) { - if (k->path_vector) { + if (k->path_vector && _allowSourceToSnapToTarget(p.getSourceType(), (*k).target_type, strict_snapping)) { // Do the intersection math Geom::CrossingSet cs = Geom::crossings(constraint_path, *(k->path_vector)); // Store the results as intersection points @@ -681,7 +692,8 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, )) || (_snapmanager->snapprefs.getSnapModeAny() && ( _snapmanager->snapprefs.getIncludeItemCenter() || _snapmanager->snapprefs.getSnapToPageBorder() || - _snapmanager->snapprefs.getSnapObjectMidpoints() + _snapmanager->snapprefs.getSnapObjectMidpoints() || + _snapmanager->snapprefs.getSnapTextBaseline() )) ; if (snap_nodes) { @@ -690,7 +702,7 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, if ((_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getSnapToItemPath()) || (_snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxPath()) || - (_snapmanager->snapprefs.getSnapModeAny() && _snapmanager->snapprefs.getSnapToPageBorder())) { + _snapmanager->snapprefs.getSnapModeAny()) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); if (n > 0) { /* While editing a path in the node tool, findCandidates must ignore that path because @@ -748,7 +760,8 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, )) || (_snapmanager->snapprefs.getSnapModeAny() && ( _snapmanager->snapprefs.getIncludeItemCenter() || _snapmanager->snapprefs.getSnapObjectMidpoints() || - _snapmanager->snapprefs.getSnapToPageBorder() + _snapmanager->snapprefs.getSnapToPageBorder() || + _snapmanager->snapprefs.getSnapTextBaseline() )); if (snap_nodes) { @@ -808,7 +821,8 @@ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const )) || (_snapmanager->snapprefs.getSnapModeAny() && ( _snapmanager->snapprefs.getSnapToPageBorder() || _snapmanager->snapprefs.getIncludeItemCenter() || - _snapmanager->snapprefs.getSnapObjectMidpoints() + _snapmanager->snapprefs.getSnapObjectMidpoints() || + _snapmanager->snapprefs.getSnapTextBaseline() )); return (_snap_enabled && snap_to_something); @@ -873,6 +887,24 @@ void Inkscape::getBBoxPoints(Geom::OptRect const bbox, } } +bool Inkscape::ObjectSnapper::_allowSourceToSnapToTarget(SnapSourceType source, SnapTargetType target, bool strict_snapping) const +{ + bool allow_this_pair_to_snap = false; + + if (strict_snapping) { // bounding boxes will not snap to nodes/paths and vice versa + int source_cat = source & (SNAPSOURCE_BBOX_CATEGORY | SNAPSOURCE_NODE_CATEGORY | SNAPSOURCE_OTHERS_CATEGORY); + int target_cat = target & (SNAPTARGET_BBOX_CATEGORY | SNAPTARGET_NODE_CATEGORY | SNAPTARGET_OTHERS_CATEGORY); + if (source_cat == target_cat || source_cat == SNAPSOURCE_OTHERS_CATEGORY || target_cat == SNAPTARGET_OTHERS_CATEGORY) { + allow_this_pair_to_snap = true; + } + } else { // anything will snap to anything + allow_this_pair_to_snap = true; + } + + return allow_this_pair_to_snap; +} + + /* Local Variables: mode:c++ -- cgit v1.2.3 From 2be2cf32db0668dc64512a98f6c2394152bd10cc Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 16 Jul 2011 00:42:39 -0700 Subject: Cleanup of oudated/redundant SP_ITEM() macro use. (bzr r10461) --- src/object-snapper.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 1944f7ffa..cb0935891 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -483,9 +483,15 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, * manually when applicable. * */ if (node_tool_active) { - SPCurve *curve = curve_for_item(SP_ITEM(selected_path)); + // TODO fix the function to be const correct: + SPCurve *curve = curve_for_item(const_cast(selected_path)); if (curve) { - Geom::PathVector *pathv = pathvector_for_curve(SP_ITEM(selected_path), curve, true, true, Geom::identity(), Geom::identity()); // We will get our own copy of the path, which must be freed at some point + Geom::PathVector *pathv = pathvector_for_curve(const_cast(selected_path), + curve, + true, + true, + Geom::identity(), + Geom::identity()); // We will get our own copy of the path, which must be freed at some point _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(pathv, SNAPTARGET_PATH, Geom::OptRect(), true)); curve->unref(); } -- cgit v1.2.3 From eed6e9c2c229b10911a23976c47da79fc70a5b87 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sun, 17 Jul 2011 21:47:09 +0200 Subject: - rename SPItem::i2d_affine to i2dt_affine, to clarify that it is item-to-desktop, not item-to-document. This should make it easier to spot bugs. - tag some instances where the document-to-desktop transform has been hardcoded (bzr r10466) --- src/object-snapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index cb0935891..1267eda37 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -147,7 +147,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, item->i2doc_affine() * additional_affine * _snapmanager->getDesktop()->doc2dt(), true); } else { - item->invoke_bbox( bbox_of_item, item->i2d_affine(), true); + item->invoke_bbox( bbox_of_item, item->i2dt_affine(), true); } if (bbox_of_item) { // See if the item is within range @@ -406,7 +406,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) root_item); if (layout != NULL && layout->outputExists()) { Geom::PathVector *pv = new Geom::PathVector(); - pv->push_back(layout->baseline() * root_item->i2d_affine() * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt()); + pv->push_back(layout->baseline() * root_item->i2dt_affine() * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt()); _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(pv, SNAPTARGET_TEXT_BASELINE, Geom::OptRect())); } } @@ -432,7 +432,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, // 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) *= root_item->i2d_affine() * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt(); // (_edit_transform * _i2d_transform); + (*pv) *= root_item->i2dt_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(); -- cgit v1.2.3 From 0621c6d7ff695fca923ff3aa3003f25fccf94b32 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Mon, 18 Jul 2011 22:07:56 +0200 Subject: Replace NR_HUGE by Geom:infinity() in some snapping code (bzr r10469) --- 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 1267eda37..389930b57 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -287,7 +287,7 @@ void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, 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 = NR_HUGE; + Geom::Coord dist = Geom::infinity(); 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 -- cgit v1.2.3 From babb7a67749cb691674bdd9758f0568d4b094b56 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Mon, 22 Aug 2011 20:27:53 +0200 Subject: Refactoring of the snapping preferences; mainly about storing all toggles in a single array, instead of each having its own member variable (bzr r10569) --- src/object-snapper.cpp | 231 ++++++++++++++++++++----------------------------- 1 file changed, 94 insertions(+), 137 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 389930b57..da6eca027 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -8,7 +8,7 @@ * Jon A. Cruz * Abhishek Sharma * - * Copyright (C) 2005 - 2010 Authors + * Copyright (C) 2005 - 2011 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -42,8 +42,8 @@ Inkscape::ObjectSnapper::ObjectSnapper(SnapManager *sm, Geom::Coord const d) : Snapper(sm, d) { _candidates = new std::vector; - _points_to_snap_to = new std::vector; - _paths_to_snap_to = new std::vector; + _points_to_snap_to = new std::vector; + _paths_to_snap_to = new std::vector; } Inkscape::ObjectSnapper::~ObjectSnapper() @@ -87,13 +87,9 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, bool const clip_or_mask, Geom::Affine const additional_affine) const // transformation of the item being clipped / masked { - if (!ThisSnapperMightSnap()) { - return; - } - if (_snapmanager->getDesktop() == NULL) { g_warning("desktop == NULL, so we cannot snap; please inform the developpers of this bug"); - // Apparently the etup() method from the SnapManager class hasn't been called before trying to snap. + // Apparently the setup() method from the SnapManager class hasn't been called before trying to snap. } if (first_point) { @@ -152,7 +148,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, if (bbox_of_item) { // See if the item is within range if (bbox_to_snap_incl.intersects(*bbox_of_item) - || (_snapmanager->snapprefs.getIncludeItemCenter() && bbox_to_snap_incl.contains(item->getCenter()))) { // rotation center might be outside of the bounding box + || (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER) && bbox_to_snap_incl.contains(item->getCenter()))) { // rotation center might be outside of the bounding box // This item is within snapping range, so record it as a candidate _candidates->push_back(SnapCandidateItem(item, clip_or_mask, additional_affine)); // For debugging: print the id of the candidate to the console @@ -167,7 +163,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, } -void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, +void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, bool const &first_point) const { // Now, let's first collect all points to snap to. If we have a whole bunch of points to snap, @@ -179,22 +175,24 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, // Determine the type of bounding box we should snap to SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX; - bool p_is_a_node = t & Inkscape::SNAPSOURCE_NODE_CATEGORY; - bool p_is_a_bbox = t & Inkscape::SNAPSOURCE_BBOX_CATEGORY; - bool p_is_other = t & Inkscape::SNAPSOURCE_OTHERS_CATEGORY; + bool p_is_a_node = t & SNAPSOURCE_NODE_CATEGORY; + bool p_is_a_bbox = t & SNAPSOURCE_BBOX_CATEGORY; + bool p_is_other = t & SNAPSOURCE_OTHERS_CATEGORY; // A point considered for snapping should be either a node, a bbox corner or a guide/other. Pick only ONE! - g_assert(!((p_is_a_node && p_is_a_bbox) || (p_is_a_bbox && p_is_other) || (p_is_a_node && p_is_other))); + if (((p_is_a_node && p_is_a_bbox) || (p_is_a_bbox && p_is_other) || (p_is_a_node && p_is_other))) { + g_warning("Snap warning: node type is ambiguous"); + } - if (_snapmanager->snapprefs.getSnapToBBoxNode() || _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints()) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CORNER, SNAPTARGET_BBOX_EDGE_MIDPOINT, SNAPTARGET_BBOX_MIDPOINT)) { + Preferences *prefs = Preferences::get(); bool prefs_bbox = prefs->getBool("/tools/bounding_box"); bbox_type = !prefs_bbox ? SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX; } // Consider the page border for snapping to - if (_snapmanager->snapprefs.getSnapToPageBorder()) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PAGE_CORNER)) { _getBorderNodes(_points_to_snap_to); } @@ -207,7 +205,7 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, g_return_if_fail(root_item); //Collect all nodes so we can snap to them - if (p_is_a_node || !(_snapmanager->snapprefs.getStrictSnapping() && !p_is_a_node) || p_is_other) { + if (p_is_a_node || p_is_other || (p_is_a_bbox && !_snapmanager->snapprefs.getStrictSnapping())) { // Note: there are two ways in which intersections are considered: // Method 1: Intersections are calculated for each shape individually, for both the // snap source and snap target (see sp_shape_snappoints) @@ -227,19 +225,19 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, // go hunting for intersections (but only when asked to in the prefs of course). In that case we can just // temporarily block the intersections in sp_item_snappoints, we don't need duplicates. If we're not snapping to // paths though but only to item nodes then we should still look for the intersections in sp_item_snappoints() - bool old_pref = _snapmanager->snapprefs.getSnapIntersectionCS(); - if (_snapmanager->snapprefs.getSnapToItemPath()) { - _snapmanager->snapprefs.setSnapIntersectionCS(false); + bool old_pref = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH_INTERSECTION); + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH)) { + _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_PATH_INTERSECTION, false); } // We should not snap a transformation center to any of the centers of the items in the // current selection (see the comment in SelTrans::centerRequest()) - bool old_pref2 = _snapmanager->snapprefs.getIncludeItemCenter(); + bool old_pref2 = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_ROTATION_CENTER); if (old_pref2) { for ( GSList const *itemlist = _snapmanager->getRotationCenterSource(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) { if ((*i).item == reinterpret_cast(itemlist->data)) { // don't snap to this item's rotation center - _snapmanager->snapprefs.setIncludeItemCenter(false); + _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, false); break; } } @@ -248,17 +246,20 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, root_item->getSnappoints(*_points_to_snap_to, &_snapmanager->snapprefs); // restore the original snap preferences - _snapmanager->snapprefs.setSnapIntersectionCS(old_pref); - _snapmanager->snapprefs.setIncludeItemCenter(old_pref2); + _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_PATH_INTERSECTION, old_pref); + _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_ROTATION_CENTER, old_pref2); } //Collect the bounding box's corners so we can snap to them - if (p_is_a_bbox || !(_snapmanager->snapprefs.getStrictSnapping() && !p_is_a_bbox) || p_is_other) { + if (p_is_a_bbox || (!_snapmanager->snapprefs.getStrictSnapping() && p_is_a_node) || p_is_other) { // 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 = 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.isTargetSnappable(SNAPTARGET_BBOX_CORNER), + _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE_MIDPOINT), + _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_MIDPOINT)); } } } @@ -266,7 +267,7 @@ void Inkscape::ObjectSnapper::_collectNodes(Inkscape::SnapSourceType const &t, } void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, - Inkscape::SnapCandidatePoint const &p, + SnapCandidatePoint const &p, std::vector *unselected_nodes, SnapConstraint const &c, Geom::Point const &p_proj_on_constraint) const @@ -321,9 +322,9 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuide(SnappedConstraints &sc, // Iterate through all nodes, find out which one is the closest to this guide, and snap to it! _collectNodes(SNAPSOURCE_GUIDE, true); - if (_snapmanager->snapprefs.getSnapToItemPath() || _snapmanager->snapprefs.getSnapToBBoxPath() || _snapmanager->snapprefs.getSnapToPageBorder()) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER)) { _collectPaths(p, SNAPSOURCE_GUIDE, true); - _snapPaths(sc, Inkscape::SnapCandidatePoint(p, SNAPSOURCE_GUIDE), NULL, NULL); + _snapPaths(sc, SnapCandidatePoint(p, SNAPSOURCE_GUIDE), NULL, NULL); } SnappedPoint s; @@ -349,7 +350,7 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuide(SnappedConstraints &sc, */ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, - Inkscape::SnapSourceType const source_type, + SnapSourceType const source_type, bool const &first_point) const { // Now, let's first collect all paths to snap to. If we have a whole bunch of points to snap, @@ -361,21 +362,22 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, // Determine the type of bounding box we should snap to SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX; - bool p_is_a_node = source_type & Inkscape::SNAPSOURCE_NODE_CATEGORY; - bool p_is_other = source_type & Inkscape::SNAPSOURCE_OTHERS_CATEGORY; + bool p_is_a_node = source_type & SNAPSOURCE_NODE_CATEGORY; + bool p_is_a_bbox = source_type & SNAPSOURCE_BBOX_CATEGORY; + bool p_is_other = source_type & SNAPSOURCE_OTHERS_CATEGORY; - if (_snapmanager->snapprefs.getSnapToBBoxPath()) { - Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE)) { + Preferences *prefs = Preferences::get(); int prefs_bbox = prefs->getBool("/tools/bounding_box", 0); bbox_type = !prefs_bbox ? SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX; } // Consider the page border for snapping - if (_snapmanager->snapprefs.getSnapToPageBorder() && _snapmanager->snapprefs.getSnapModeAny()) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PAGE_BORDER) && _snapmanager->snapprefs.getSnapModeAny()) { Geom::PathVector *border_path = _getBorderPathv(); if (border_path != NULL) { - _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(border_path, SNAPTARGET_PAGE_BORDER, Geom::OptRect())); + _paths_to_snap_to->push_back(SnapCandidatePath(border_path, SNAPTARGET_PAGE_BORDER, Geom::OptRect())); } } @@ -397,17 +399,16 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, //Build a list of all paths considered for snapping to //Add the item's path to snap to - if ((_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapModeNode()) || - (_snapmanager->snapprefs.getSnapTextBaseline() && (_snapmanager->snapprefs.getSnapModeNode() || _snapmanager->snapprefs.getSnapToItemPath())) ) { - if (p_is_other || !(_snapmanager->snapprefs.getStrictSnapping() && !p_is_a_node)) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, 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 (_snapmanager->snapprefs.getSnapTextBaseline()) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_TEXT_BASELINE)) { // Snap to the text baseline - Inkscape::Text::Layout const *layout = te_get_layout((SPItem *) root_item); + Text::Layout const *layout = te_get_layout((SPItem *) root_item); if (layout != NULL && layout->outputExists()) { Geom::PathVector *pv = new Geom::PathVector(); pv->push_back(layout->baseline() * root_item->i2dt_affine() * (*i).additional_affine * _snapmanager->getDesktop()->doc2dt()); - _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(pv, SNAPTARGET_TEXT_BASELINE, Geom::OptRect())); + _paths_to_snap_to->push_back(SnapCandidatePath(pv, SNAPTARGET_TEXT_BASELINE, Geom::OptRect())); } } } else { @@ -419,7 +420,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, very_complex_path = sp_nodes_in_path(SP_PATH(root_item)) > 500; } - if (!very_complex_path && root_item && (_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapModeNode())) { + if (!very_complex_path && root_item && _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH)) { SPCurve *curve = NULL; if (SP_IS_SHAPE(root_item)) { curve = SP_SHAPE(root_item)->getCurve(); @@ -434,7 +435,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, Geom::PathVector *pv = new Geom::PathVector(curve->get_pathvector()); (*pv) *= root_item->i2dt_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. + _paths_to_snap_to->push_back(SnapCandidatePath(pv, SNAPTARGET_PATH, Geom::OptRect())); // Perhaps for speed, get a reference to the Geom::pathvector, and store the transformation besides it. curve->unref(); } } @@ -443,8 +444,8 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, } //Add the item's bounding box to snap to - if (_snapmanager->snapprefs.getSnapToBBoxPath() && (_snapmanager->snapprefs.getSnapModeBBox() || _snapmanager->snapprefs.getSnapModeOthers())) { - if (p_is_other || !(_snapmanager->snapprefs.getStrictSnapping() && p_is_a_node)) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE) && (_snapmanager->snapprefs.getSnapModeBBox() || _snapmanager->snapprefs.getSnapModeOthers())) { + if (p_is_other || p_is_a_bbox || (!_snapmanager->snapprefs.getStrictSnapping() && p_is_a_node)) { // 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) { @@ -453,7 +454,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, if (rect) { Geom::PathVector *path = _getPathvFromRect(*rect); 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(SnapCandidatePath(path, SNAPTARGET_BBOX_EDGE, rect)); } } } @@ -463,8 +464,8 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, } void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, - Inkscape::SnapCandidatePoint const &p, - std::vector *unselected_nodes, + SnapCandidatePoint const &p, + std::vector *unselected_nodes, SPPath const *selected_path) const { _collectPaths(p.getPoint(), p.getSourceType(), p.getSourceNum() <= 0); @@ -473,7 +474,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, g_assert(_snapmanager->getDesktop() != NULL); Geom::Point const p_doc = _snapmanager->getDesktop()->dt2doc(p.getPoint()); - bool const node_tool_active = _snapmanager->snapprefs.getSnapToItemPath() && selected_path != NULL; + bool const node_tool_active = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH) && selected_path != NULL; if (p.getSourceNum() <= 0) { /* findCandidates() is used for snapping to both paths and nodes. It ignores the path that is @@ -492,7 +493,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, true, Geom::identity(), Geom::identity()); // We will get our own copy of the path, which must be freed at some point - _paths_to_snap_to->push_back(Inkscape::SnapCandidatePath(pathv, SNAPTARGET_PATH, Geom::OptRect(), true)); + _paths_to_snap_to->push_back(SnapCandidatePath(pathv, SNAPTARGET_PATH, Geom::OptRect(), true)); curve->unref(); } } @@ -503,7 +504,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, bool strict_snapping = _snapmanager->snapprefs.getStrictSnapping(); - for (std::vector::const_iterator it_p = _paths_to_snap_to->begin(); it_p != _paths_to_snap_to->end(); it_p++) { + for (std::vector::const_iterator it_p = _paths_to_snap_to->begin(); it_p != _paths_to_snap_to->end(); it_p++) { if (_allowSourceToSnapToTarget(p.getSourceType(), (*it_p).target_type, strict_snapping)) { bool const being_edited = node_tool_active && (*it_p).currently_being_edited; //if true then this pathvector it_pv is currently being edited in the node tool @@ -545,7 +546,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, if (!being_edited || (c1 && c2)) { Geom::Coord const dist = Geom::distance(sp_doc, p_doc); if (dist < getSnapperTolerance()) { - sc.curves.push_back(Inkscape::SnappedCurve(sp_dt, num_path, num_segm, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); + sc.curves.push_back(SnappedCurve(sp_dt, num_path, num_segm, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); } } } @@ -557,7 +558,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, } /* Returns true if point is coincident with one of the unselected nodes */ -bool Inkscape::ObjectSnapper::isUnselectedNode(Geom::Point const &point, std::vector const *unselected_nodes) const +bool Inkscape::ObjectSnapper::isUnselectedNode(Geom::Point const &point, std::vector const *unselected_nodes) const { if (unselected_nodes == NULL) { return false; @@ -567,7 +568,7 @@ bool Inkscape::ObjectSnapper::isUnselectedNode(Geom::Point const &point, std::ve return false; } - for (std::vector::const_iterator i = unselected_nodes->begin(); i != unselected_nodes->end(); i++) { + for (std::vector::const_iterator i = unselected_nodes->begin(); i != unselected_nodes->end(); i++) { if (Geom::L2(point - (*i).getPoint()) < 1e-4) { return true; } @@ -577,7 +578,7 @@ bool Inkscape::ObjectSnapper::isUnselectedNode(Geom::Point const &point, std::ve } void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, - Inkscape::SnapCandidatePoint const &p, + SnapCandidatePoint const &p, SnapConstraint const &c, Geom::Point const &p_proj_on_constraint) const { @@ -618,7 +619,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, // Find all intersections of the constrained path with the snap target candidates std::vector intersections; - for (std::vector::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) { + for (std::vector::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) { if (k->path_vector && _allowSourceToSnapToTarget(p.getSourceType(), (*k).target_type, strict_snapping)) { // Do the intersection math Geom::CrossingSet cs = Geom::crossings(constraint_path, *(k->path_vector)); @@ -671,12 +672,12 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, - Inkscape::SnapCandidatePoint const &p, + SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap, std::vector const *it, std::vector *unselected_nodes) const { - if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false ) { + if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false || ThisSnapperMightSnap() == false) { return; } @@ -686,29 +687,9 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, _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 - bool snap_nodes = (_snapmanager->snapprefs.getSnapModeNode() && ( - _snapmanager->snapprefs.getSnapToItemNode() || - _snapmanager->snapprefs.getSnapSmoothNodes() || - _snapmanager->snapprefs.getSnapLineMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeBBox() && ( - _snapmanager->snapprefs.getSnapToBBoxNode() || - _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || - _snapmanager->snapprefs.getSnapBBoxMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeAny() && ( - _snapmanager->snapprefs.getIncludeItemCenter() || - _snapmanager->snapprefs.getSnapToPageBorder() || - _snapmanager->snapprefs.getSnapObjectMidpoints() || - _snapmanager->snapprefs.getSnapTextBaseline() - )) ; - - if (snap_nodes) { - _snapNodes(sc, p, unselected_nodes); - } + _snapNodes(sc, p, unselected_nodes); - if ((_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getSnapToItemPath()) || - (_snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxPath()) || - _snapmanager->snapprefs.getSnapModeAny()) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); if (n > 0) { /* While editing a path in the node tool, findCandidates must ignore that path because @@ -731,13 +712,13 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, } void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, - Inkscape::SnapCandidatePoint const &p, + SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap, SnapConstraint const &c, std::vector const *it, std::vector *unselected_nodes) const { - if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false) { + if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false || ThisSnapperMightSnap() == false) { return; } @@ -754,27 +735,9 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, // This is useful for example when scaling an object while maintaining a fixed aspect ratio. It's // nodes are only allowed to move in one direction (i.e. in one degree of freedom). - // TODO: Argh, UGLY! Get rid of this here, move this logic to the snap manager - bool snap_nodes = (_snapmanager->snapprefs.getSnapModeNode() && ( - _snapmanager->snapprefs.getSnapToItemNode() || - _snapmanager->snapprefs.getSnapSmoothNodes() || - _snapmanager->snapprefs.getSnapLineMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeBBox() && ( - _snapmanager->snapprefs.getSnapToBBoxNode() || - _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || - _snapmanager->snapprefs.getSnapBBoxMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeAny() && ( - _snapmanager->snapprefs.getIncludeItemCenter() || - _snapmanager->snapprefs.getSnapObjectMidpoints() || - _snapmanager->snapprefs.getSnapToPageBorder() || - _snapmanager->snapprefs.getSnapTextBaseline() - )); - - if (snap_nodes) { - _snapNodes(sc, p, unselected_nodes, c, pp); - } + _snapNodes(sc, p, unselected_nodes, c, pp); - if (_snapmanager->snapprefs.getSnapToItemPath() || _snapmanager->snapprefs.getSnapToBBoxPath() || _snapmanager->snapprefs.getSnapToPageBorder()) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { _snapPathsConstrained(sc, p, c, pp); } } @@ -785,12 +748,16 @@ void Inkscape::ObjectSnapper::guideFreeSnap(SnappedConstraints &sc, Geom::Point const &p, Geom::Point const &guide_normal) const { - /* Get a list of all the SPItems that we will try to snap to */ - std::vector cand; - std::vector const it; //just an empty list + if (!_snapmanager->snapprefs.getSnapModeOthers()) { + return; + } + - _findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity()); - _snapTranslatingGuide(sc, p, guide_normal); + //std::vector const it; //just an empty list + + freeSnap(sc, SnapCandidatePoint(p, SNAPSOURCE_GUIDE), Geom::Rect(p, p), NULL, NULL); + //_findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity()); + //_snapTranslatingGuide(sc, p, guide_normal); } @@ -804,8 +771,12 @@ void Inkscape::ObjectSnapper::guideConstrainedSnap(SnappedConstraints &sc, std::vector cand; std::vector const it; //just an empty list - _findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity()); - _snapTranslatingGuide(sc, p, guide_normal); + std::cout << "guideConstrainedSnap" << std::endl; + + if (_snapmanager->snapprefs.getSnapModeOthers()) { + _findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity()); + _snapTranslatingGuide(sc, p, guide_normal); + } } @@ -814,29 +785,15 @@ void Inkscape::ObjectSnapper::guideConstrainedSnap(SnappedConstraints &sc, */ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { - bool snap_to_something = (_snapmanager->snapprefs.getSnapModeNode() && ( - _snapmanager->snapprefs.getSnapToItemPath() || - _snapmanager->snapprefs.getSnapToItemNode() || - _snapmanager->snapprefs.getSnapSmoothNodes() || - _snapmanager->snapprefs.getSnapLineMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeBBox() && ( - _snapmanager->snapprefs.getSnapToBBoxPath() || - _snapmanager->snapprefs.getSnapToBBoxNode() || - _snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || - _snapmanager->snapprefs.getSnapBBoxMidpoints() - )) || (_snapmanager->snapprefs.getSnapModeAny() && ( - _snapmanager->snapprefs.getSnapToPageBorder() || - _snapmanager->snapprefs.getIncludeItemCenter() || - _snapmanager->snapprefs.getSnapObjectMidpoints() || - _snapmanager->snapprefs.getSnapTextBaseline() - )); - - return (_snap_enabled && snap_to_something); + return _snapmanager->snapprefs.getSnapModeBBox() + || _snapmanager->snapprefs.getSnapModeNode() + || _snapmanager->snapprefs.getSnapModeOthers() + || _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PAGE_CORNER); } void Inkscape::ObjectSnapper::_clear_paths() const { - for (std::vector::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) { + for (std::vector::const_iterator k = _paths_to_snap_to->begin(); k != _paths_to_snap_to->end(); k++) { delete k->path_vector; } _paths_to_snap_to->clear(); @@ -863,10 +820,10 @@ void Inkscape::ObjectSnapper::_getBorderNodes(std::vector *p { 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(w,0), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); + points->push_back(SnapCandidatePoint(Geom::Point(0,0), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); + points->push_back(SnapCandidatePoint(Geom::Point(0,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); + points->push_back(SnapCandidatePoint(Geom::Point(w,h), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); + points->push_back(SnapCandidatePoint(Geom::Point(w,0), SNAPSOURCE_UNDEFINED, SNAPTARGET_PAGE_CORNER)); } void Inkscape::getBBoxPoints(Geom::OptRect const bbox, @@ -880,15 +837,15 @@ void Inkscape::getBBoxPoints(Geom::OptRect const bbox, // 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, -1, Inkscape::SNAPTARGET_BBOX_CORNER, *bbox)); + points->push_back(SnapCandidatePoint(bbox->corner(k), SNAPSOURCE_BBOX_CORNER, -1, SNAPTARGET_BBOX_CORNER, *bbox)); } // 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, -1, Inkscape::SNAPTARGET_BBOX_EDGE_MIDPOINT, *bbox)); + points->push_back(SnapCandidatePoint((bbox->corner(k) + bbox->corner((k+1) % 4))/2, SNAPSOURCE_BBOX_EDGE_MIDPOINT, -1, SNAPTARGET_BBOX_EDGE_MIDPOINT, *bbox)); } } if (includeObjectMidpoints) { - points->push_back(Inkscape::SnapCandidatePoint(bbox->midpoint(), Inkscape::SNAPSOURCE_BBOX_MIDPOINT, -1, Inkscape::SNAPTARGET_BBOX_MIDPOINT, *bbox)); + points->push_back(SnapCandidatePoint(bbox->midpoint(), SNAPSOURCE_BBOX_MIDPOINT, -1, SNAPTARGET_BBOX_MIDPOINT, *bbox)); } } } -- cgit v1.2.3 From bc41980c93b8627b286daeb51bc29806a6c2b0f0 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Tue, 23 Aug 2011 21:17:19 +0200 Subject: 1) Use the "snap guides" button both for guides being snap sources, as well as for guides being snap targets 2) Remove some redundant guide-snapping code from the object snapper, (bzr r10576) --- src/object-snapper.cpp | 38 -------------------------------------- 1 file changed, 38 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index da6eca027..82114e2c4 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -742,44 +742,6 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, } } - -// This method is used to snap a guide to nodes, while dragging the guide around -void Inkscape::ObjectSnapper::guideFreeSnap(SnappedConstraints &sc, - Geom::Point const &p, - Geom::Point const &guide_normal) const -{ - if (!_snapmanager->snapprefs.getSnapModeOthers()) { - return; - } - - - //std::vector const it; //just an empty list - - freeSnap(sc, SnapCandidatePoint(p, SNAPSOURCE_GUIDE), Geom::Rect(p, p), NULL, NULL); - //_findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity()); - //_snapTranslatingGuide(sc, p, guide_normal); - -} - -// This method is used to snap the origin of a guide to nodes/paths, while dragging the origin along the guide -void Inkscape::ObjectSnapper::guideConstrainedSnap(SnappedConstraints &sc, - Geom::Point const &p, - Geom::Point const &guide_normal, - SnapConstraint const &/*c*/) const -{ - /* Get a list of all the SPItems that we will try to snap to */ - std::vector cand; - std::vector const it; //just an empty list - - std::cout << "guideConstrainedSnap" << std::endl; - - if (_snapmanager->snapprefs.getSnapModeOthers()) { - _findCandidates(_snapmanager->getDocument()->getRoot(), &it, true, Geom::Rect(p, p), false, Geom::identity()); - _snapTranslatingGuide(sc, p, guide_normal); - } - -} - /** * \return true if this Snapper will snap at least one kind of point. */ -- cgit v1.2.3 From 3da0fd8b645937bcdd26d2ab3db716982030fc19 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Thu, 25 Aug 2011 22:08:16 +0200 Subject: Fix "snap guides" toggle Fixed bugs: - https://launchpad.net/bugs/814457 (bzr r10582) --- src/object-snapper.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 82114e2c4..fd8ef0c7c 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -177,7 +177,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, bool p_is_a_node = t & SNAPSOURCE_NODE_CATEGORY; bool p_is_a_bbox = t & SNAPSOURCE_BBOX_CATEGORY; - bool p_is_other = t & SNAPSOURCE_OTHERS_CATEGORY; + bool p_is_other = t & SNAPSOURCE_OTHERS_CATEGORY || t & SNAPSOURCE_DATUMS_CATEGORY; // A point considered for snapping should be either a node, a bbox corner or a guide/other. Pick only ONE! if (((p_is_a_node && p_is_a_bbox) || (p_is_a_bbox && p_is_other) || (p_is_a_node && p_is_other))) { @@ -364,7 +364,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, bool p_is_a_node = source_type & SNAPSOURCE_NODE_CATEGORY; bool p_is_a_bbox = source_type & SNAPSOURCE_BBOX_CATEGORY; - bool p_is_other = source_type & SNAPSOURCE_OTHERS_CATEGORY; + bool p_is_other = source_type & SNAPSOURCE_OTHERS_CATEGORY || source_type & SNAPSOURCE_DATUMS_CATEGORY; if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE)) { Preferences *prefs = Preferences::get(); @@ -444,7 +444,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, } //Add the item's bounding box to snap to - if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE) && (_snapmanager->snapprefs.getSnapModeBBox() || _snapmanager->snapprefs.getSnapModeOthers())) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE)) { if (p_is_other || p_is_a_bbox || (!_snapmanager->snapprefs.getStrictSnapping() && p_is_a_node)) { // 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 @@ -747,10 +747,7 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, */ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { - return _snapmanager->snapprefs.getSnapModeBBox() - || _snapmanager->snapprefs.getSnapModeNode() - || _snapmanager->snapprefs.getSnapModeOthers() - || _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PAGE_CORNER); + return true; } void Inkscape::ObjectSnapper::_clear_paths() const @@ -814,16 +811,13 @@ void Inkscape::getBBoxPoints(Geom::OptRect const bbox, bool Inkscape::ObjectSnapper::_allowSourceToSnapToTarget(SnapSourceType source, SnapTargetType target, bool strict_snapping) const { - bool allow_this_pair_to_snap = false; + bool allow_this_pair_to_snap = true; if (strict_snapping) { // bounding boxes will not snap to nodes/paths and vice versa - int source_cat = source & (SNAPSOURCE_BBOX_CATEGORY | SNAPSOURCE_NODE_CATEGORY | SNAPSOURCE_OTHERS_CATEGORY); - int target_cat = target & (SNAPTARGET_BBOX_CATEGORY | SNAPTARGET_NODE_CATEGORY | SNAPTARGET_OTHERS_CATEGORY); - if (source_cat == target_cat || source_cat == SNAPSOURCE_OTHERS_CATEGORY || target_cat == SNAPTARGET_OTHERS_CATEGORY) { - allow_this_pair_to_snap = true; + if (((source & SNAPSOURCE_BBOX_CATEGORY) && (target & SNAPTARGET_NODE_CATEGORY)) || + ((source & SNAPSOURCE_NODE_CATEGORY) && (target & SNAPTARGET_BBOX_CATEGORY))) { + allow_this_pair_to_snap = false; } - } else { // anything will snap to anything - allow_this_pair_to_snap = true; } return allow_this_pair_to_snap; -- cgit v1.2.3 From 72cc39b9f0b340548f395c7f61ca9662b34aea09 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 27 Aug 2011 11:04:37 +0200 Subject: Refactor SPItem bounding box methods: remove NRRect usage and make code using them more obvious. Fix filter region computation. (bzr r10582.1.1) --- src/object-snapper.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index fd8ef0c7c..07d690ce0 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -135,15 +135,14 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, if (SP_IS_GROUP(o)) { _findCandidates(o, it, false, bbox_to_snap, clip_or_mask, additional_affine); } else { - Geom::OptRect bbox_of_item = Geom::Rect(); + Geom::OptRect bbox_of_item; 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) - item->invoke_bbox(bbox_of_item, - item->i2doc_affine() * additional_affine * _snapmanager->getDesktop()->doc2dt(), - true); + bbox_of_item = item->visualBounds(item->i2doc_affine() * additional_affine * + _snapmanager->getDesktop()->doc2dt()); } else { - item->invoke_bbox( bbox_of_item, item->i2dt_affine(), true); + bbox_of_item = item->desktopVisualBounds(); } if (bbox_of_item) { // See if the item is within range @@ -188,7 +187,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, Preferences *prefs = Preferences::get(); bool prefs_bbox = prefs->getBool("/tools/bounding_box"); bbox_type = !prefs_bbox ? - SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX; + SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; } // Consider the page border for snapping to @@ -255,7 +254,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, // 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 = root_item->getBboxDesktop(bbox_type); + Geom::OptRect b = root_item->desktopBounds(bbox_type); getBBoxPoints(b, _points_to_snap_to, true, _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CORNER), _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE_MIDPOINT), @@ -370,7 +369,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, Preferences *prefs = Preferences::get(); int prefs_bbox = prefs->getBool("/tools/bounding_box", 0); bbox_type = !prefs_bbox ? - SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX; + SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; } // Consider the page border for snapping @@ -449,11 +448,10 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, // 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 rect; - root_item->invoke_bbox( rect, i2doc, TRUE, bbox_type); + Geom::OptRect rect = root_item->bounds(bbox_type, i2doc); if (rect) { Geom::PathVector *path = _getPathvFromRect(*rect); - rect = root_item->getBboxDesktop(bbox_type); + rect = root_item->desktopBounds(bbox_type); _paths_to_snap_to->push_back(SnapCandidatePath(path, SNAPTARGET_BBOX_EDGE, rect)); } } -- cgit v1.2.3 From e5c85aa8478032ebecd8c586dc27afcaf77e4314 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 27 Aug 2011 22:54:42 +0200 Subject: Allow snapping to path intersections without snapping to the paths themselves (bzr r10585) --- src/object-snapper.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index fd8ef0c7c..5bb7f0d00 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -227,6 +227,9 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, // paths though but only to item nodes then we should still look for the intersections in sp_item_snappoints() bool old_pref = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH_INTERSECTION); if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH)) { + // So if we snap to paths, then findBestSnap will find the intersections + // and therefore we temporarily disable SNAPTARGET_PATH_INTERSECTION, which will + // avoid root_item->getSnappoints() below from returning intersections _snapmanager->snapprefs.setTargetSnappable(SNAPTARGET_PATH_INTERSECTION, false); } @@ -322,7 +325,7 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuide(SnappedConstraints &sc, // Iterate through all nodes, find out which one is the closest to this guide, and snap to it! _collectNodes(SNAPSOURCE_GUIDE, true); - if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER)) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER)) { _collectPaths(p, SNAPSOURCE_GUIDE, true); _snapPaths(sc, SnapCandidatePoint(p, SNAPSOURCE_GUIDE), NULL, NULL); } @@ -399,7 +402,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, //Build a list of all paths considered for snapping to //Add the item's path to snap to - if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_TEXT_BASELINE)) { + 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 (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_TEXT_BASELINE)) { @@ -420,7 +423,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, very_complex_path = sp_nodes_in_path(SP_PATH(root_item)) > 500; } - if (!very_complex_path && root_item && _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH)) { + 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(); @@ -474,7 +477,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, g_assert(_snapmanager->getDesktop() != NULL); Geom::Point const p_doc = _snapmanager->getDesktop()->dt2doc(p.getPoint()); - bool const node_tool_active = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH) && selected_path != NULL; + bool const node_tool_active = _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION) && selected_path != NULL; if (p.getSourceNum() <= 0) { /* findCandidates() is used for snapping to both paths and nodes. It ignores the path that is @@ -689,7 +692,7 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, _snapNodes(sc, p, unselected_nodes); - if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); if (n > 0) { /* While editing a path in the node tool, findCandidates must ignore that path because @@ -737,7 +740,7 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, _snapNodes(sc, p, unselected_nodes, c, pp); - if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { _snapPathsConstrained(sc, p, c, pp); } } -- cgit v1.2.3 From f07487e34701b93421a2f92b4ad8d308d5a8bace Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 28 Aug 2011 15:03:49 +0200 Subject: Fix bug related to snapping to path intersections (bzr r10587) --- src/object-snapper.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 5bb7f0d00..987b027b0 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -502,8 +502,9 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, } } - int num_path = 0; - int num_segm = 0; + int num_path = 0; // _paths_to_snap_to contains multiple path_vectors, each containing multiple paths. + // num_path will count the paths, and will not be zeroed for each path_vector. It will + // continue counting bool strict_snapping = _snapmanager->snapprefs.getStrictSnapping(); @@ -549,13 +550,12 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, if (!being_edited || (c1 && c2)) { Geom::Coord const dist = Geom::distance(sp_doc, p_doc); if (dist < getSnapperTolerance()) { - sc.curves.push_back(SnappedCurve(sp_dt, num_path, num_segm, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); + sc.curves.push_back(SnappedCurve(sp_dt, num_path, index, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); } } } - num_segm++; + num_path++; } // End of: for (Geom::PathVector::iterator ....) - num_path++; } } } -- cgit v1.2.3 From 59259f0cabfa0205acc3229c281169e8406570b3 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Fri, 2 Sep 2011 22:14:29 +0200 Subject: Rename the struct "SnappedConstraints" to the more meaningfull "IntermSnapResults" (bzr r10612) --- src/object-snapper.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 7aa8a9c08..fa992a852 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -268,7 +268,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, } } -void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, +void Inkscape::ObjectSnapper::_snapNodes(IntermSnapResults &isr, SnapCandidatePoint const &p, std::vector *unselected_nodes, SnapConstraint const &c, @@ -313,11 +313,11 @@ void Inkscape::ObjectSnapper::_snapNodes(SnappedConstraints &sc, } if (success) { - sc.points.push_back(s); + isr.points.push_back(s); } } -void Inkscape::ObjectSnapper::_snapTranslatingGuide(SnappedConstraints &sc, +void Inkscape::ObjectSnapper::_snapTranslatingGuide(IntermSnapResults &isr, Geom::Point const &p, Geom::Point const &guide_normal) const { @@ -326,7 +326,7 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuide(SnappedConstraints &sc, if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER)) { _collectPaths(p, SNAPSOURCE_GUIDE, true); - _snapPaths(sc, SnapCandidatePoint(p, SNAPSOURCE_GUIDE), NULL, NULL); + _snapPaths(isr, SnapCandidatePoint(p, SNAPSOURCE_GUIDE), NULL, NULL); } SnappedPoint s; @@ -341,7 +341,7 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuide(SnappedConstraints &sc, Geom::Coord dist2 = Geom::L2(p - p_proj); // distance from projection of node on the guide, to the mouse location if ((dist < tol && dist2 < tol) || getSnapperAlwaysSnap()) { s = SnappedPoint(target_pt, SNAPSOURCE_GUIDE, 0, (*k).getTargetType(), dist, tol, getSnapperAlwaysSnap(), false, true, (*k).getTargetBBox()); - sc.points.push_back(s); + isr.points.push_back(s); } } } @@ -464,7 +464,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, } } -void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, +void Inkscape::ObjectSnapper::_snapPaths(IntermSnapResults &isr, SnapCandidatePoint const &p, std::vector *unselected_nodes, SPPath const *selected_path) const @@ -548,7 +548,7 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc, if (!being_edited || (c1 && c2)) { Geom::Coord const dist = Geom::distance(sp_doc, p_doc); if (dist < getSnapperTolerance()) { - sc.curves.push_back(SnappedCurve(sp_dt, num_path, index, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); + isr.curves.push_back(SnappedCurve(sp_dt, num_path, index, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); } } } @@ -578,7 +578,7 @@ bool Inkscape::ObjectSnapper::isUnselectedNode(Geom::Point const &point, std::ve return false; } -void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, +void Inkscape::ObjectSnapper::_snapPathsConstrained(IntermSnapResults &isr, SnapCandidatePoint const &p, SnapConstraint const &c, Geom::Point const &p_proj_on_constraint) const @@ -664,7 +664,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, SnappedPoint s = SnappedPoint(*p_inters, p.getSourceType(), p.getSourceNum(), k->target_type, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), true, k->target_bbox);; // Store the snapped point if (dist <= tolerance) { // If the intersection is within snapping range, then we might snap to it - sc.points.push_back(s); + isr.points.push_back(s); } } } @@ -672,7 +672,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc, } -void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, +void Inkscape::ObjectSnapper::freeSnap(IntermSnapResults &isr, SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap, std::vector const *it, @@ -688,7 +688,7 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, _findCandidates(_snapmanager->getDocument()->getRoot(), it, p.getSourceNum() <= 0, local_bbox_to_snap, false, Geom::identity()); } - _snapNodes(sc, p, unselected_nodes); + _snapNodes(isr, p, unselected_nodes); if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { unsigned n = (unselected_nodes == NULL) ? 0 : unselected_nodes->size(); @@ -705,14 +705,14 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc, } // 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 } - _snapPaths(sc, p, unselected_nodes, path); + _snapPaths(isr, p, unselected_nodes, path); } else { - _snapPaths(sc, p, NULL, NULL); + _snapPaths(isr, p, NULL, NULL); } } } -void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, +void Inkscape::ObjectSnapper::constrainedSnap( IntermSnapResults &isr, SnapCandidatePoint const &p, Geom::OptRect const &bbox_to_snap, SnapConstraint const &c, @@ -736,10 +736,10 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc, // This is useful for example when scaling an object while maintaining a fixed aspect ratio. It's // nodes are only allowed to move in one direction (i.e. in one degree of freedom). - _snapNodes(sc, p, unselected_nodes, c, pp); + _snapNodes(isr, p, unselected_nodes, c, pp); if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { - _snapPathsConstrained(sc, p, c, pp); + _snapPathsConstrained(isr, p, c, pp); } } -- cgit v1.2.3 From f0fa8577f48a7b0ddb285764404be316855d2e83 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 17 Sep 2011 14:08:49 +0200 Subject: Make "snap page border" toggle independent of "snap paths" toggle Fixed bugs: - https://launchpad.net/bugs/850982 (bzr r10635) --- 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 fa992a852..c5b2b7cd7 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -324,7 +324,7 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuide(IntermSnapResults &isr, // Iterate through all nodes, find out which one is the closest to this guide, and snap to it! _collectNodes(SNAPSOURCE_GUIDE, true); - if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER)) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH, SNAPTARGET_PATH_INTERSECTION, SNAPTARGET_BBOX_EDGE, SNAPTARGET_PAGE_BORDER, SNAPTARGET_TEXT_BASELINE)) { _collectPaths(p, SNAPSOURCE_GUIDE, true); _snapPaths(isr, SnapCandidatePoint(p, SNAPSOURCE_GUIDE), NULL, NULL); } -- cgit v1.2.3 From 20097d47e6945bceb57d2335d23fe764f493ab59 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sun, 2 Oct 2011 20:44:17 -0700 Subject: Another minor pass of Doxygen cleanup. (bzr r10659) --- 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 c5b2b7cd7..7e0961c95 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -1,6 +1,6 @@ /** * \file object-snapper.cpp - * \brief Snapping things to objects. + * Snapping things to objects. * * Authors: * Carl Hetherington -- cgit v1.2.3 From f4c59e50df9090a1a4801da06f9a0021b67ce7a2 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 8 Oct 2011 22:00:37 +0200 Subject: 1) make snapping to clip/mask paths optional (see document properties dialog -> snap tab) 2) for debugging purposes: code added for showing all snap candidates 3) groundwork for tangential/perpendicular snapping (bzr r10672) --- src/object-snapper.cpp | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 7e0961c95..b14415c47 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -78,6 +78,7 @@ bool Inkscape::ObjectSnapper::getSnapperAlwaysSnap() const * \param parent Pointer to the document's root, or to a clipped path or mask object * \param it List of items to ignore * \param bbox_to_snap Bounding box hulling the whole bunch of points, all from the same selection and having the same transformation + * \param clip_or_mask The parent object being passed is either a clip or mask */ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, @@ -88,7 +89,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, Geom::Affine const additional_affine) const // transformation of the item being clipped / masked { if (_snapmanager->getDesktop() == NULL) { - g_warning("desktop == NULL, so we cannot snap; please inform the developpers of this bug"); + g_warning("desktop == NULL, so we cannot snap; please inform the developers of this bug"); // Apparently the setup() method from the SnapManager class hasn't been called before trying to snap. } @@ -122,11 +123,11 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // still be the subject of clipping or masking itself ; if so, then // we should also consider that path or mask for snapping to obj = SP_OBJECT(item->clip_ref->getObject()); - if (obj) { + 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->getObject()); - if (obj) { + if (obj && _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PATH_MASK)) { _findCandidates(obj, it, false, bbox_to_snap, true, item->i2doc_affine()); } } @@ -506,6 +507,7 @@ void Inkscape::ObjectSnapper::_snapPaths(IntermSnapResults &isr, bool strict_snapping = _snapmanager->snapprefs.getStrictSnapping(); + //_snapmanager->getDesktop()->snapindicator->remove_debugging_points(); for (std::vector::const_iterator it_p = _paths_to_snap_to->begin(); it_p != _paths_to_snap_to->end(); it_p++) { if (_allowSourceToSnapToTarget(p.getSourceType(), (*it_p).target_type, strict_snapping)) { bool const being_edited = node_tool_active && (*it_p).currently_being_edited; @@ -516,12 +518,14 @@ void Inkscape::ObjectSnapper::_snapPaths(IntermSnapResults &isr, // n curves will return n time values with 0 <= t <= 1 std::vector anp = (*it_pv).nearestPointPerCurve(p_doc); + //std::cout << "#nearest points = " << anp.size() << " | p = " << p.getPoint() << std::endl; + // Now we will examine each of the nearest points, and determine whether it's within snapping range and if we should snap to it std::vector::const_iterator np = anp.begin(); unsigned int index = 0; for (; np != anp.end(); np++, index++) { Geom::Curve const *curve = &((*it_pv).at_index(index)); Geom::Point const sp_doc = curve->pointAt(*np); - + //_snapmanager->getDesktop()->snapindicator->set_new_debugging_point(sp_doc*_snapmanager->getDesktop()->doc2dt()); bool c1 = true; bool c2 = true; if (being_edited) { @@ -546,9 +550,23 @@ void Inkscape::ObjectSnapper::_snapPaths(IntermSnapResults &isr, Geom::Point const sp_dt = _snapmanager->getDesktop()->doc2dt(sp_doc); if (!being_edited || (c1 && c2)) { - Geom::Coord const dist = Geom::distance(sp_doc, p_doc); + Geom::Coord dist = Geom::distance(sp_doc, p_doc); + // std::cout << " dist -> " << dist << std::endl; if (dist < getSnapperTolerance()) { + // Add the curve we have snapped to isr.curves.push_back(SnappedCurve(sp_dt, num_path, index, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, curve, p.getSourceType(), p.getSourceNum(), it_p->target_type, it_p->target_bbox)); + // Find all tangential points +// boost::optional origin = p.getStartingPoint(); +// if (origin) { +// Geom::Point origin_doc = _snapmanager->getDesktop()->dt2doc(*origin); +// std::vector atp = find_tangents(origin_doc, curve->toSBasis()); +// for (std::vector::const_iterator t = atp.begin(); t != atp.end(); t++) { +// Geom::Point const tp_doc = curve->pointAt(*t); +// dist = Geom::distance(tp_doc, p_doc); +// Geom::Point const tp_dt = _snapmanager->getDesktop()->doc2dt(tp_doc); +// isr.points.push_back(SnappedPoint(tp_dt, p.getSourceType(), p.getSourceNum(), it_p->target_type, dist, getSnapperTolerance(), getSnapperAlwaysSnap(), false, true, it_p->target_bbox)); +// } +// } } } } -- cgit v1.2.3 From 5feadccf4874e67e126c5133b3ba06b53c01c609 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Wed, 12 Oct 2011 23:23:51 +0200 Subject: Object snapper: only use the visual bounding box when absolutely needed; otherwise default to geometric bounding box (bzr r10675) --- src/object-snapper.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index b14415c47..68e63a0c1 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -137,13 +137,19 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, _findCandidates(o, it, false, bbox_to_snap, clip_or_mask, additional_affine); } else { Geom::OptRect bbox_of_item; + Preferences *prefs = Preferences::get(); + int prefs_bbox = prefs->getBool("/tools/bounding_box", 0); + // We'll only need to obtain the visual bounding box if the user preferences tell + // us to, AND if we are snapping to the bounding box itself. If we're snapping to + // paths only, then we can just as well use the geometric bounding box (which is faster) + SPItem::BBoxType bbox_type = (!prefs_bbox && _snapmanager->snapprefs.getSnapModeBBox()) ? + SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; 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) - bbox_of_item = item->visualBounds(item->i2doc_affine() * additional_affine * - _snapmanager->getDesktop()->doc2dt()); + bbox_of_item = item->bounds(bbox_type, item->i2doc_affine() * additional_affine * _snapmanager->getDesktop()->doc2dt()); } else { - bbox_of_item = item->desktopVisualBounds(); + bbox_of_item = item->bounds(bbox_type); } if (bbox_of_item) { // See if the item is within range -- cgit v1.2.3 From c3790882a616125eebcd488db9f08e5388b82d9e Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 15 Oct 2011 14:36:28 +0200 Subject: Use desktop coordinates for finding snap candidates (regression introduced in rev. #10675) Fixed bugs: - https://launchpad.net/bugs/874213 (bzr r10677) --- src/object-snapper.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 68e63a0c1..bf8cf166a 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -149,7 +149,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // insert an additional transformation in document coordinates (code copied from sp_item_i2d_affine) bbox_of_item = item->bounds(bbox_type, item->i2doc_affine() * additional_affine * _snapmanager->getDesktop()->doc2dt()); } else { - bbox_of_item = item->bounds(bbox_type); + bbox_of_item = item->desktopBounds(bbox_type); } if (bbox_of_item) { // See if the item is within range @@ -183,7 +183,7 @@ void Inkscape::ObjectSnapper::_collectNodes(SnapSourceType const &t, bool p_is_a_node = t & SNAPSOURCE_NODE_CATEGORY; bool p_is_a_bbox = t & SNAPSOURCE_BBOX_CATEGORY; - bool p_is_other = t & SNAPSOURCE_OTHERS_CATEGORY || t & SNAPSOURCE_DATUMS_CATEGORY; + bool p_is_other = (t & SNAPSOURCE_OTHERS_CATEGORY) || (t & SNAPSOURCE_DATUMS_CATEGORY); // A point considered for snapping should be either a node, a bbox corner or a guide/other. Pick only ONE! if (((p_is_a_node && p_is_a_bbox) || (p_is_a_bbox && p_is_other) || (p_is_a_node && p_is_other))) { @@ -373,7 +373,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, bool p_is_a_node = source_type & SNAPSOURCE_NODE_CATEGORY; bool p_is_a_bbox = source_type & SNAPSOURCE_BBOX_CATEGORY; - bool p_is_other = source_type & SNAPSOURCE_OTHERS_CATEGORY || source_type & SNAPSOURCE_DATUMS_CATEGORY; + bool p_is_other = (source_type & SNAPSOURCE_OTHERS_CATEGORY) || (source_type & SNAPSOURCE_DATUMS_CATEGORY); if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE)) { Preferences *prefs = Preferences::get(); -- cgit v1.2.3 From 2633767789e4264b13ef91a684accf734fb4e94f Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Wed, 26 Oct 2011 21:55:51 -0700 Subject: Fixing more broken and split doc comments. (bzr r10697) --- src/object-snapper.cpp | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index bf8cf166a..e7d9b774d 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -1,5 +1,4 @@ -/** - * \file object-snapper.cpp +/* * Snapping things to objects. * * Authors: @@ -58,9 +57,6 @@ Inkscape::ObjectSnapper::~ObjectSnapper() delete _paths_to_snap_to; } -/** - * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels - */ Geom::Coord Inkscape::ObjectSnapper::getSnapperTolerance() const { SPDesktop const *dt = _snapmanager->getDesktop(); @@ -73,14 +69,6 @@ bool Inkscape::ObjectSnapper::getSnapperAlwaysSnap() const return _snapmanager->snapprefs.getObjectTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp } -/** - * Find all items within snapping range. - * \param parent Pointer to the document's root, or to a clipped path or mask object - * \param it List of items to ignore - * \param bbox_to_snap Bounding box hulling the whole bunch of points, all from the same selection and having the same transformation - * \param clip_or_mask The parent object being passed is either a clip or mask - */ - void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, std::vector const *it, bool const &first_point, @@ -354,10 +342,7 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuide(IntermSnapResults &isr, } -/** - * Returns index of first NR_END bpath in array. - */ - +/// @todo investigate why Geom::Point p is passed in but ignored. void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, SnapSourceType const source_type, bool const &first_point) const @@ -767,9 +752,6 @@ void Inkscape::ObjectSnapper::constrainedSnap( IntermSnapResults &isr, } } -/** - * \return true if this Snapper will snap at least one kind of point. - */ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { return true; -- cgit v1.2.3 From 8f1c271f1e1d226061e9fe63faa40cefdd1dcd81 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 18 Dec 2011 13:45:52 +0100 Subject: Refactor snap-preferences a bit more (bzr r10780) --- src/object-snapper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/object-snapper.cpp') diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index e7d9b774d..b1c118e92 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -130,7 +130,7 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent, // We'll only need to obtain the visual bounding box if the user preferences tell // us to, AND if we are snapping to the bounding box itself. If we're snapping to // paths only, then we can just as well use the geometric bounding box (which is faster) - SPItem::BBoxType bbox_type = (!prefs_bbox && _snapmanager->snapprefs.getSnapModeBBox()) ? + SPItem::BBoxType bbox_type = (!prefs_bbox && _snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CATEGORY)) ? SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; if (clip_or_mask) { // Oh oh, this will get ugly. We cannot use sp_item_i2d_affine directly because we need to @@ -368,7 +368,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Geom::Point /*p*/, } // Consider the page border for snapping - if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PAGE_BORDER) && _snapmanager->snapprefs.getSnapModeAny()) { + if (_snapmanager->snapprefs.isTargetSnappable(SNAPTARGET_PAGE_BORDER) && _snapmanager->snapprefs.isAnyCategorySnappable()) { Geom::PathVector *border_path = _getBorderPathv(); if (border_path != NULL) { _paths_to_snap_to->push_back(SnapCandidatePath(border_path, SNAPTARGET_PAGE_BORDER, Geom::OptRect())); @@ -687,7 +687,7 @@ void Inkscape::ObjectSnapper::freeSnap(IntermSnapResults &isr, std::vector const *it, std::vector *unselected_nodes) const { - if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false || ThisSnapperMightSnap() == false) { + if (_snap_enabled == false || _snapmanager->snapprefs.isSourceSnappable(p.getSourceType()) == false || ThisSnapperMightSnap() == false) { return; } @@ -728,7 +728,7 @@ void Inkscape::ObjectSnapper::constrainedSnap( IntermSnapResults &isr, std::vector const *it, std::vector *unselected_nodes) const { - if (_snap_enabled == false || _snapmanager->snapprefs.getSnapFrom(p.getSourceType()) == false || ThisSnapperMightSnap() == false) { + if (_snap_enabled == false || _snapmanager->snapprefs.isSourceSnappable(p.getSourceType()) == false || ThisSnapperMightSnap() == false) { return; } -- cgit v1.2.3