From: Diederik van Lierop Date: Fri, 21 May 2010 21:46:07 +0000 (+0200) Subject: - "Snap nodes or handles" button now also includes smooth nodes X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ae73b82cf10057153a43afdcb1f3a22deac18ea2;p=inkscape.git - "Snap nodes or handles" button now also includes smooth nodes - Improved snap tooltips --- diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 536affb82..5c0ea419b 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -693,7 +693,7 @@ void Inkscape::ObjectSnapper::guideConstrainedSnap(SnappedConstraints &sc, bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const { bool snap_to_something = _snapmanager->snapprefs.getSnapToItemPath() - || _snapmanager->snapprefs.getSnapToItemNode() + || _snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() || _snapmanager->snapprefs.getSnapToBBoxPath() || _snapmanager->snapprefs.getSnapToBBoxNode() || _snapmanager->snapprefs.getSnapToPageBorder() @@ -706,7 +706,7 @@ bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const bool Inkscape::ObjectSnapper::GuidesMightSnap() const // almost the same as ThisSnapperMightSnap above, but only looking at points (and not paths) { - bool snap_to_something = _snapmanager->snapprefs.getSnapToItemNode() + bool snap_to_something = _snapmanager->snapprefs.getSnapToItemNode() || _snapmanager->snapprefs.getSnapSmoothNodes() || _snapmanager->snapprefs.getSnapToPageBorder() || (_snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxNode()) || (_snapmanager->snapprefs.getSnapModeBBox() && (_snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints())) diff --git a/src/selection.cpp b/src/selection.cpp index 1e14591fa..96c66e0c5 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -424,14 +424,15 @@ boost::optional Selection::center() const { } /** - * Compute the list of points in the selection that are to be considered for snapping. + * Compute the list of points in the selection that are to be considered for snapping from. */ std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { GSList const *items = const_cast(this)->itemList(); SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs snapprefs_dummy.setIncludeItemCenter(false); // locally disable snapping to the item center - + snapprefs_dummy.setSnapToItemNode(true); // consider any type of nodes as a snap source + snapprefs_dummy.setSnapSmoothNodes(true); // i.e. disregard the smooth / cusp node preference std::vector p; for (GSList const *iter = items; iter != NULL; iter = iter->next) { SPItem *this_item = SP_ITEM(iter->data); @@ -446,13 +447,18 @@ std::vector Selection::getSnapPoints(SnapPreferenc return p; } - +// TODO: both getSnapPoints and getSnapPointsConvexHull are called, subsequently. Can we do this more efficient? +// Why do we need to include the transformation center in one case and not the other? std::vector Selection::getSnapPointsConvexHull(SnapPreferences const *snapprefs) const { GSList const *items = const_cast(this)->itemList(); + SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs + snapprefs_dummy.setSnapToItemNode(true); // consider any type of nodes as a snap source + snapprefs_dummy.setSnapSmoothNodes(true); // i.e. disregard the smooth / cusp node preference + std::vector p; for (GSList const *iter = items; iter != NULL; iter = iter->next) { - sp_item_snappoints(SP_ITEM(iter->data), p, snapprefs); + sp_item_snappoints(SP_ITEM(iter->data), p, &snapprefs_dummy); } std::vector pHull; diff --git a/src/seltrans.cpp b/src/seltrans.cpp index aef608420..05f47d4ab 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -289,13 +289,9 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s // Next, get all points to consider for snapping SnapManager const &m = _desktop->namedview->snap_manager; - Inkscape::SnapPreferences local_snapprefs = m.snapprefs; - local_snapprefs.setSnapToItemNode(true); // We should get at least the cusp nodes here. This might - // have been turned off because (for example) the user only want paths as a snap target, not nodes - // but as a snap source we still need some nodes though! _snap_points.clear(); - _snap_points = selection->getSnapPoints(&local_snapprefs); - std::vector snap_points_hull = selection->getSnapPointsConvexHull(&local_snapprefs); + _snap_points = selection->getSnapPoints(&m.snapprefs); + std::vector snap_points_hull = selection->getSnapPointsConvexHull(&m.snapprefs); if (_snap_points.size() > 200) { /* Snapping a huge number of nodes will take way too long, so limit the number of snappable nodes An average user would rarely ever try to snap such a large number of nodes anyway, because diff --git a/src/snap-enums.h b/src/snap-enums.h index cf09ba45b..4e6854054 100644 --- a/src/snap-enums.h +++ b/src/snap-enums.h @@ -58,7 +58,7 @@ enum SnapSourceType { //------------------------------------------------------------------- // For the same reason, nodes will not snap to bbox points SNAPSOURCE_NODE_CATEGORY = 512, // will be used as a flag and must therefore be a power of two - SNAPSOURCE_NODE_SMOOTH, + SNAPSOURCE_NODE_SMOOTH, // Symmetrical nodes are also considered to be smooth; there's no dedicated type for symm. nodes SNAPSOURCE_NODE_CUSP, SNAPSOURCE_LINE_MIDPOINT, SNAPSOURCE_PATH_INTERSECTION, diff --git a/src/sp-shape.cpp b/src/sp-shape.cpp index dadcb5f57..3064341b6 100644 --- a/src/sp-shape.cpp +++ b/src/sp-shape.cpp @@ -1227,7 +1227,24 @@ static void sp_shape_snappoints(SPItem const *item, std::vectorgetSnapSmoothNodes() && (nodetype == Geom::NODE_SMOOTH || nodetype == Geom::NODE_SYMM); if (c1 || c2) { - p.push_back(Inkscape::SnapCandidatePoint(curve_it1->finalPoint() * i2d, Inkscape::SNAPSOURCE_NODE_CUSP, Inkscape::SNAPTARGET_NODE_CUSP)); + Inkscape::SnapSourceType sst; + Inkscape::SnapTargetType stt; + switch (nodetype) { + case Geom::NODE_CUSP: + sst = Inkscape::SNAPSOURCE_NODE_CUSP; + stt = Inkscape::SNAPTARGET_NODE_CUSP; + break; + case Geom::NODE_SMOOTH: + case Geom::NODE_SYMM: + sst = Inkscape::SNAPSOURCE_NODE_SMOOTH; + stt = Inkscape::SNAPTARGET_NODE_SMOOTH; + break; + default: + sst = Inkscape::SNAPSOURCE_UNDEFINED; + stt = Inkscape::SNAPTARGET_UNDEFINED; + break; + } + p.push_back(Inkscape::SnapCandidatePoint(curve_it1->finalPoint() * i2d, sst, stt)); } // Consider midpoints of line segments for snapping