Code

When dragging a knot along a constraint line, then allow snapping the position of...
authordvlierop2 <dvlierop2@users.sourceforge.net>
Sun, 23 Aug 2009 13:55:47 +0000 (13:55 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Sun, 23 Aug 2009 13:55:47 +0000 (13:55 +0000)
src/knot-holder-entity.cpp
src/object-snapper.cpp
src/snap.cpp
src/ui/dialog/inkscape-preferences.cpp
src/ui/dialog/inkscape-preferences.h

index 4225dd9e3b19eb15292f8865bc967e527ce6db3a..bf7505f3c0afc64c6003f62d30bbf83906929107 100644 (file)
@@ -91,9 +91,12 @@ KnotHolderEntity::snap_knot_position(Geom::Point const &p)
 {
     Geom::Matrix const i2d (sp_item_i2d_affine(item));
     Geom::Point s = p * i2d;
+
     SnapManager &m = desktop->namedview->snap_manager;
     m.setup(desktop, true, item);
+
     m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE);
+
     return s * i2d.inverse();
 }
 
@@ -102,10 +105,28 @@ KnotHolderEntity::snap_knot_position_constrained(Geom::Point const &p, Inkscape:
 {
     Geom::Matrix const i2d (sp_item_i2d_affine(item));
     Geom::Point s = p * i2d;
-    Inkscape::Snapper::ConstraintLine transformed_constraint = Inkscape::Snapper::ConstraintLine(constraint.getPoint() * i2d, (constraint.getPoint() + constraint.getDirection()) * i2d - constraint.getPoint() * i2d);
+
     SnapManager &m = desktop->namedview->snap_manager;
     m.setup(desktop, true, item);
-    m.constrainedSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE, transformed_constraint);
+
+    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+    if ((prefs->getBool("/options/snapmousepointer/value", false))) { // legacy behavior (pre v0.47)
+        // Snapping the mouse pointer instead of the constrained position of the knot allows to snap to
+        // things which don't intersect with the constraint line. This should be handled by the
+        // smart dynamic guides which are yet to be implemented, making this behavior more clean and
+        // transparent. With the current implementation it leads to unexpected results, and it doesn't
+        // allow accurately controlling what is being snapped to.
+
+        // freeSnap() will try snapping point p. This will not take into account the constraint, which
+        // is therefore to be enforced after snap_knot_position_constrained() has finished
+        m.freeSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE);
+    } else {
+        // constrainedSnap() will first project the point p onto the constraint line and then try to snap along that line.
+        // This way the constraint is already enforced, no need to worry about that later on
+        Inkscape::Snapper::ConstraintLine transformed_constraint = Inkscape::Snapper::ConstraintLine(constraint.getPoint() * i2d, (constraint.getPoint() + constraint.getDirection()) * i2d - constraint.getPoint() * i2d);
+        m.constrainedSnapReturnByRef(Inkscape::SnapPreferences::SNAPPOINT_NODE, s, Inkscape::SNAPSOURCE_HANDLE, transformed_constraint);
+    }
+
     return s * i2d.inverse();
 }
 
index aece2e9ec42be1153f9b583d886689d765e0ead0..af0d9f1a2fb568970d50516c352198fe77d2295d 100644 (file)
@@ -161,8 +161,8 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent,
                             // 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;
                         }
                     }
                 }
@@ -554,7 +554,7 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc,
     // 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);
 
index f0769e0a1ad1903326446d38f50986fa7d4bc5f1..c03f2e1e628e09b7d9108a450b94b261080063a7 100644 (file)
@@ -378,7 +378,10 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapPreferences::P
         items_to_ignore = _items_to_ignore;
     }
 
+
+    // First project the mouse pointer onto the constraint
     Geom::Point pp = constraint.projection(p);
+    // Then try to snap the projected point
 
     SnappedConstraints sc;
     SnapperList const snappers = getSnappers();
index ba07597e71819b472ee42a1b8ff5b461249cd63d..9b6d9e0847bde98e24e5ba718af1d4971f4fa91f 100644 (file)
@@ -230,6 +230,10 @@ void InkscapePreferences::initPageSnapping()
     _page_snapping.add_line( false, _("Weight factor:"), _snap_weight, "",
                              _("When multiple snap solutions are found, then Inkscape can either prefer the closest transformation (when set to 0), or prefer the node that was initially the closest to the pointer (when set to 1)"), true);
 
+    _snap_mouse_pointer.init( _("Snap the mouse pointer when dragging a constrained knot"), "/options/snapmousepointer/value", false);
+    _page_snapping.add_line( false, "", _snap_mouse_pointer, "",
+                             _("When dragging a knot along a constraint line, then snap the position of the mouse pointer instead of snapping the projection of the knot onto the constraint line"));
+
     this->AddPage(_page_snapping, _("Snapping"), PREFS_PAGE_SNAPPING);
 }
 
index 7bcbe7d498c9b7554278db642457d509fdfcf3ec..aa0da3a370b9d381ace4585ec2e47ba6e62d389c 100644 (file)
@@ -131,7 +131,7 @@ protected:
     PrefCheckButton _wheel_zoom;
 
     Gtk::HScale     *_slider_snapping_delay;
-    PrefCheckButton _snap_indicator, _snap_closest_only;
+    PrefCheckButton _snap_indicator, _snap_closest_only, _snap_mouse_pointer;
 
     PrefCombo       _steps_rot_snap;
     PrefCheckButton _steps_compass;