diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp
index d47dc86470fe7cd8b27b42edd1564e8b60715174..af0d9f1a2fb568970d50516c352198fe77d2295d 100644 (file)
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
// This item is within snapping range, so record it as a candidate
_candidates->push_back(SnapCandidate(item, clip_or_mask, additional_affine));
// For debugging: print the id of the candidate to the console
- // SPObject *obj = (SPObject*)item;
- // std::cout << "Snap candidate added: " << obj->id << std::endl;
+ //SPObject *obj = (SPObject*)item;
+ //std::cout << "Snap candidate added: " << obj->id << std::endl;
}
}
}
@@ -296,6 +296,13 @@ void Inkscape::ObjectSnapper::_snapTranslatingGuideToNodes(SnappedConstraints &s
// Iterate through all nodes, find out which one is the closest to this guide, and snap to it!
_collectNodes(t, true);
+ // Although we won't snap to paths here (which would give us under constrained snaps) we can still snap to intersections of paths.
+ if (_snapmanager->snapprefs.getSnapToItemPath() || _snapmanager->snapprefs.getSnapToBBoxPath() || _snapmanager->snapprefs.getSnapToPageBorder()) {
+ _collectPaths(t, true);
+ _snapPaths(sc, t, p, SNAPSOURCE_GUIDE, true, NULL, NULL);
+ // The paths themselves should be discarded in findBestSnap(), as we should only snap to their intersections
+ }
+
SnappedPoint s;
Geom::Coord tol = getSnapperTolerance();
@@ -330,6 +337,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::SnapPreferences::PointType
SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX;
bool p_is_a_node = t & Inkscape::SnapPreferences::SNAPPOINT_NODE;
+ bool p_is_a_guide = t & Inkscape::SnapPreferences::SNAPPOINT_GUIDE;
if (_snapmanager->snapprefs.getSnapToBBoxPath()) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
@@ -365,7 +373,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::SnapPreferences::PointType
//Add the item's path to snap to
if (_snapmanager->snapprefs.getSnapToItemPath()) {
- if (!(_snapmanager->snapprefs.getStrictSnapping() && !p_is_a_node)) {
+ if (p_is_a_guide || !(_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
@@ -399,7 +407,7 @@ void Inkscape::ObjectSnapper::_collectPaths(Inkscape::SnapPreferences::PointType
//Add the item's bounding box to snap to
if (_snapmanager->snapprefs.getSnapToBBoxPath()) {
- if (!(_snapmanager->snapprefs.getStrictSnapping() && p_is_a_node)) {
+ if (p_is_a_guide || !(_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) {
// The intersection point of the constraint line with any path,
// must lie within two points on the constraintline: p_min_on_cl and p_max_on_cl
// The distance between those points is twice the snapping tolerance
- Geom::Point const p_proj_on_cl = c.projection(p);
+ Geom::Point const p_proj_on_cl = p; // projection has already been taken care of in constrainedSnap in the snapmanager;
Geom::Point const p_min_on_cl = _snapmanager->getDesktop()->dt2doc(p_proj_on_cl - getSnapperTolerance() * direction_vector);
Geom::Point const p_max_on_cl = _snapmanager->getDesktop()->dt2doc(p_proj_on_cl + getSnapperTolerance() * direction_vector);
*/
SPPath *path = NULL;
if (it != NULL) {
- g_assert(SP_IS_PATH(*it->begin()));
- g_assert(it->size() == 1);
- path = SP_PATH(*it->begin());
+ if (it->size() == 1 && SP_IS_PATH(*it->begin())) {
+ path = SP_PATH(*it->begin());
+ } // 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, t, p, source_type, first_point, unselected_nodes, path);
} else {
// This method is used to snap a guide to nodes, while dragging the guide around
-void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc,
+void Inkscape::ObjectSnapper::guideFreeSnap(SnappedConstraints &sc,
Geom::Point const &p,
Geom::Point const &guide_normal) const
{
snap_dim = ANGLED_GUIDE_TRANSL_SNAP;
}
- // We don't support ANGLED_GUIDE_ROT_SNAP yet.
+ _findCandidates(sp_document_root(_snapmanager->getDocument()), &it, true, Geom::Rect(p, p), snap_dim, false, Geom::identity());
+ _snapTranslatingGuideToNodes(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, guide_normal);
- // It would be cool to allow the user to rotate a guide by dragging it, instead of
- // only translating it. (For example when CTRL is pressed). We will need an UI part
- // for that first; and some important usability choices need to be made:
- // E.g. which point should be used for pivoting? A previously snapped point,
- // or a transformation center (which can be moved after clicking for the
- // second time on an object; but should this point then be constrained to the
- // line, or can it be located anywhere?)
+}
+
+// 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,
+ ConstraintLine const &c) const
+{
+ /* Get a list of all the SPItems that we will try to snap to */
+ std::vector<SPItem*> cand;
+ std::vector<SPItem const *> const it; //just an empty list
+
+ DimensionToSnap snap_dim;
+ if (guide_normal == to_2geom(component_vectors[Geom::Y])) {
+ snap_dim = GUIDE_TRANSL_SNAP_Y;
+ } else if (guide_normal == to_2geom(component_vectors[Geom::X])) {
+ snap_dim = GUIDE_TRANSL_SNAP_X;
+ } else {
+ snap_dim = ANGLED_GUIDE_TRANSL_SNAP;
+ }
_findCandidates(sp_document_root(_snapmanager->getDocument()), &it, true, Geom::Rect(p, p), snap_dim, false, Geom::identity());
_snapTranslatingGuideToNodes(sc, Inkscape::SnapPreferences::SNAPPOINT_GUIDE, p, guide_normal);
- // _snapRotatingGuideToNodes has not been implemented yet.
+
}
/**
return (_snap_enabled && _snapmanager->snapprefs.getSnapModeBBoxOrNodes() && snap_to_something);
}
-bool Inkscape::ObjectSnapper::GuidesMightSnap() 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() || _snapmanager->snapprefs.getSnapToBBoxNode();
+ bool snap_to_something = _snapmanager->snapprefs.getSnapToItemNode()
+ || _snapmanager->snapprefs.getSnapToPageBorder()
+ || (_snapmanager->snapprefs.getSnapModeBBox() && _snapmanager->snapprefs.getSnapToBBoxNode())
+ || (_snapmanager->snapprefs.getSnapModeBBox() && (_snapmanager->snapprefs.getSnapBBoxEdgeMidpoints() || _snapmanager->snapprefs.getSnapBBoxMidpoints()))
+ || (_snapmanager->snapprefs.getSnapModeNode() && (_snapmanager->snapprefs.getSnapLineMidpoints() || _snapmanager->snapprefs.getSnapObjectMidpoints()))
+ || (_snapmanager->snapprefs.getSnapModeNode() && _snapmanager->snapprefs.getIncludeItemCenter())
+ || (_snapmanager->snapprefs.getSnapModeNode() && (_snapmanager->snapprefs.getSnapToItemPath() && _snapmanager->snapprefs.getSnapIntersectionCS()));
+
return (_snap_enabled && _snapmanager->snapprefs.getSnapModeGuide() && snap_to_something);
}