diff --git a/src/seltrans.cpp b/src/seltrans.cpp
index 6ae7948f1eee14c2d5d7d3d82c8566f5bcc15ff6..cdfcee7420a3cf84017ca4708553bf43b96ff810 100644 (file)
--- a/src/seltrans.cpp
+++ b/src/seltrans.cpp
-#define __SELTRANS_C__
-
-/*
- * Helper object for transforming selected items
- *
- * Authors:
+/** @file
+ * @brief Helper object for transforming selected items
+ */
+/* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
* Carl Hetherington <inkscape@carlh.net>
#include "verbs.h"
#include <glibmm/i18n.h>
#include "display/sp-ctrlline.h"
-#include "prefs-utils.h"
+#include "preferences.h"
#include "xml/repr.h"
#include "mod360.h"
#include <2geom/angle.h>
_stamp_cache(NULL),
_message_context(desktop->messageStack())
{
- int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
- _snap_bbox_type = (prefs_bbox ==0)?
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ int prefs_bbox = prefs->getBool("/tools/bounding_box");
+ _snap_bbox_type = !prefs_bbox ?
SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
g_return_if_fail(desktop != NULL);
_updateHandles();
}
-void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool show_handles)
+void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool show_handles, bool translating)
{
+ // While dragging a handle, we will either scale, skew, or rotate and the "translating" parameter will be false
+ // When dragging the selected item itself however, we will translate the selection and that parameter will be true
Inkscape::Selection *selection = sp_desktop_selection(_desktop);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
g_return_if_fail(!_grabbed);
@@ -273,10 +275,11 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s
// The selector tool should snap the bbox, special snappoints, and path nodes
// (The special points are the handles, center, rotation axis, font baseline, ends of spiral, etc.)
- // First, determine the bounding box for snapping ...
+ // First, determine the bounding box
_bbox = selection->bounds(_snap_bbox_type);
_approximate_bbox = selection->bounds(SPItem::APPROXIMATE_BBOX); // Used for correctly scaling the strokewidth
_geometric_bbox = selection->bounds(SPItem::GEOMETRIC_BBOX);
+
_point = p;
if (_geometric_bbox) {
_point_geom = _geometric_bbox->min() + _geometric_bbox->dimensions() * Geom::Scale(x, y);
@@ -287,13 +290,17 @@ 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;
_snap_points.clear();
- _snap_points = selection->getSnapPoints(m.getIncludeItemCenter());
- std::vector<Geom::Point> snap_points_hull = selection->getSnapPointsConvexHull();
- if (_snap_points.size() > 100) {
+ _snap_points = selection->getSnapPoints(&m.snapprefs);
+ std::vector<Inkscape::SnapCandidatePoint> 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
(s)he could hardly discern which node would be snapping */
- _snap_points = snap_points_hull;
+ if (prefs->getBool("/options/snapclosestonly/value", false)) {
+ _keepClosestPointOnly(_snap_points, p);
+ } else {
+ _snap_points = snap_points_hull;
+ }
// Unfortunately, by now we will have lost the font-baseline snappoints :-(
}
@@ -302,21 +309,38 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s
// any other special points
Geom::Rect snap_points_bbox;
if ( snap_points_hull.empty() == false ) {
- std::vector<Geom::Point>::iterator i = snap_points_hull.begin();
- snap_points_bbox = Geom::Rect(*i, *i);
+ std::vector<Inkscape::SnapCandidatePoint>::iterator i = snap_points_hull.begin();
+ snap_points_bbox = Geom::Rect((*i).getPoint(), (*i).getPoint());
i++;
while (i != snap_points_hull.end()) {
- snap_points_bbox.expandTo(*i);
+ snap_points_bbox.expandTo((*i).getPoint());
i++;
}
}
_bbox_points.clear();
- if (_bbox) {
- // ... and add the bbox corners to _bbox_points
- for ( unsigned i = 0 ; i < 4 ; i++ ) {
- _bbox_points.push_back(_bbox->corner(i));
+ _bbox_points_for_translating.clear();
+ // Collect the bounding box's corners and midpoints for each selected item
+ if (m.snapprefs.getSnapModeBBox()) {
+ bool mp = m.snapprefs.getSnapBBoxMidpoints();
+ bool emp = m.snapprefs.getSnapBBoxEdgeMidpoints();
+ // Preferably we'd use the bbox of each selected item, instead of the bbox of the selection as a whole; for translations
+ // this is easy to do, but when snapping the visual bbox while scaling we will have to compensate for the scaling of the
+ // stroke width. (see get_scale_transform_with_stroke()). This however is currently only implemented for a single bbox.
+ // That's why we have both _bbox_points_for_translating and _bbox_points.
+ getBBoxPoints(selection->bounds(_snap_bbox_type), &_bbox_points, false, true, emp, mp);
+ if (((_items.size() > 0) && (_items.size() < 50)) || prefs->getBool("/options/snapclosestonly/value", false)) {
+ // More than 50 items will produce at least 200 bbox points, which might make Inkscape crawl
+ // (see the comment a few lines above). In that case we will use the bbox of the selection as a whole
+ for (unsigned i = 0; i < _items.size(); i++) {
+ getBBoxPoints(sp_item_bbox_desktop(_items[i], _snap_bbox_type), &_bbox_points_for_translating, false, true, emp, mp);
+ }
+ } else {
+ _bbox_points_for_translating = _bbox_points; // use the bbox points of the selection as a whole
}
+ }
+
+ if (_bbox) {
// There are two separate "opposites" (i.e. opposite w.r.t. the handle being dragged):
// - one for snapping the boundingbox, which can be either visual or geometric
// - one for snapping the special points
@@ -328,19 +352,56 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s
_opposite = _opposite_for_bboxpoints;
}
- // The lines below are usefull for debugging any snapping issues, as they'll spit out all points that are considered for snapping
+ // When snapping the node closest to the mouse pointer is absolutely preferred over the closest snap
+ // (i.e. when weight == 1), then we will not even try to snap to other points and discard those other
+ // points immediately.
- /*std::cout << "Number of snap points: " << _snap_points.size() << std::endl;
- for (std::vector<Geom::Point>::const_iterator i = _snap_points.begin(); i != _snap_points.end(); i++)
- {
- std::cout << " " << *i << std::endl;
- }
+ if (prefs->getBool("/options/snapclosestonly/value", false)) {
+ if (m.snapprefs.getSnapModeNode()) {
+ _keepClosestPointOnly(_snap_points, p);
+ } else {
+ _snap_points.clear(); // don't keep any point
+ }
- std::cout << "Number of bbox points: " << _bbox_points.size() << std::endl;
- for (std::vector<Geom::Point>::const_iterator i = _bbox_points.begin(); i != _bbox_points.end(); i++)
- {
- std::cout << " " << *i << std::endl;
- }*/
+ if (m.snapprefs.getSnapModeBBox()) {
+ _keepClosestPointOnly(_bbox_points, p);
+ _keepClosestPointOnly(_bbox_points_for_translating, p);
+ } else {
+ _bbox_points.clear(); // don't keep any point
+ _bbox_points_for_translating.clear();
+ }
+
+ // Each of the three vectors of snappoints now contains either one snappoint or none at all.
+ if (_snap_points.size() > 1 || _bbox_points.size() > 1 || _bbox_points_for_translating.size() > 1) {
+ g_warning("Incorrect assumption encountered while finding the snap source; nothing serious, but please report to Diederik");
+ }
+
+ // Now let's reduce this to a single closest snappoint
+ Geom::Coord dsp = _snap_points.size() == 1 ? Geom::L2((_snap_points.at(0)).getPoint() - p) : NR_HUGE;
+ Geom::Coord dbbp = _bbox_points.size() == 1 ? Geom::L2((_bbox_points.at(0)).getPoint() - p) : NR_HUGE;
+ Geom::Coord dbbpft = _bbox_points_for_translating.size() == 1 ? Geom::L2((_bbox_points_for_translating.at(0)).getPoint() - p) : NR_HUGE;
+
+ if (translating) {
+ _bbox_points.clear();
+ if (dsp > dbbpft) {
+ _snap_points.clear();
+ } else {
+ _bbox_points_for_translating.clear();
+ }
+ } else {
+ _bbox_points_for_translating.clear();
+ if (dsp > dbbp) {
+ _snap_points.clear();
+ } else {
+ _bbox_points.clear();
+ }
+ }
+
+ if ((_snap_points.size() + _bbox_points.size() + _bbox_points_for_translating.size()) > 1) {
+ g_warning("Checking number of snap sources failed; nothing serious, but please report to Diederik");
+ }
+
+ }
if ((x != -1) && (y != -1)) {
sp_canvas_item_show(_norm);
_grabbed = false;
_show_handles = true;
+ _desktop->snapindicator->remove_snapsource();
+
Inkscape::Selection *selection = sp_desktop_selection(_desktop);
_updateVolatileState();
if (_current_relative_affine.isTranslation()) {
sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
_("Move"));
- } else if (_current_relative_affine.isScale()) {
+ } else if (_current_relative_affine.without_translation().isScale()) {
sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
_("Scale"));
- } else if (_current_relative_affine.isRotation()) {
+ } else if (_current_relative_affine.without_translation().isRotation()) {
sp_document_done(sp_desktop_document(_desktop), SP_VERB_CONTEXT_SELECT,
_("Rotate"));
} else {
@@ -757,7 +820,7 @@ void Inkscape::SelTrans::handleGrab(SPKnot *knot, guint /*state*/, SPSelTransHan
break;
}
- grab(sp_knot_position(knot), handle.x, handle.y, FALSE);
+ grab(sp_knot_position(knot), handle.x, handle.y, FALSE, FALSE);
}
@@ -805,7 +868,11 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, Geom::Point *position,
if (handle.request(this, handle, *position, state)) {
sp_knot_set_position(knot, *position, state);
SP_CTRL(_grip)->moveto(*position);
- SP_CTRL(_norm)->moveto(_origin);
+ if (&handle == &handle_center) {
+ SP_CTRL(_norm)->moveto(*position);
+ } else {
+ SP_CTRL(_norm)->moveto(_origin);
+ }
}
return TRUE;
@@ -815,9 +882,10 @@ gboolean Inkscape::SelTrans::handleRequest(SPKnot *knot, Geom::Point *position,
void Inkscape::SelTrans::_selChanged(Inkscape::Selection */*selection*/)
{
if (!_grabbed) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// reread in case it changed on the fly:
- int prefs_bbox = prefs_get_int_attribute("tools", "bounding_box", 0);
- _snap_bbox_type = (prefs_bbox ==0)?
+ int prefs_bbox = prefs->getBool("/tools/bounding_box");
+ _snap_bbox_type = !prefs_bbox ?
SPItem::APPROXIMATE_BBOX : SPItem::GEOMETRIC_BBOX;
//SPItem::APPROXIMATE_BBOX will be replaced by SPItem::VISUAL_BBOX, as soon as the latter is implemented properly
m.setup(_desktop, false, _items_const);
Inkscape::SnappedPoint bb, sn;
- Geom::Coord bd(NR_HUGE);
- Geom::Coord sd(NR_HUGE);
if ((state & GDK_CONTROL_MASK) || _desktop->isToolboxButtonActive ("lock")) {
// Scale is locked to a 1:1 aspect ratio, so that s[X] must be made to equal s[Y].
}
// Snap along a suitable constraint vector from the origin.
- bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale, _origin_for_bboxpoints);
- sn = m.constrainedSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale, _origin_for_specpoints);
-
- /* Choose the smaller difference in scale. Since s[X] == s[Y] we can
- ** just compare difference in s[X].
- */
- bd = bb.getSnapped() ? fabs(bb.getTransformation()[Geom::X] - default_scale[Geom::X]) : NR_HUGE;
- sd = sn.getSnapped() ? fabs(sn.getTransformation()[Geom::X] - geom_scale[Geom::X]) : NR_HUGE;
+ bb = m.constrainedSnapScale(_bbox_points, _point, default_scale, _origin_for_bboxpoints);
+ sn = m.constrainedSnapScale(_snap_points, _point, geom_scale, _origin_for_specpoints);
} else {
/* Scale aspect ratio is unlocked */
- bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, default_scale, _origin_for_bboxpoints);
- sn = m.freeSnapScale(Snapper::SNAPPOINT_NODE, _snap_points, geom_scale, _origin_for_specpoints);
-
- /* Pick the snap that puts us closest to the original scale */
- bd = bb.getSnapped() ? fabs(Geom::L2(bb.getTransformation()) - Geom::L2(Geom::Point(default_scale[Geom::X], default_scale[Geom::Y]))) : NR_HUGE;
- sd = sn.getSnapped() ? fabs(Geom::L2(sn.getTransformation()) - Geom::L2(Geom::Point(geom_scale[Geom::X], geom_scale[Geom::Y]))) : NR_HUGE;
+ bb = m.freeSnapScale(_bbox_points, _point, default_scale, _origin_for_bboxpoints);
+ sn = m.freeSnapScale(_snap_points, _point, geom_scale, _origin_for_specpoints);
}
if (!(bb.getSnapped() || sn.getSnapped())) {
// We didn't snap at all! Don't update the handle position, just calculate the new transformation
_calcAbsAffineDefault(default_scale);
- _desktop->snapindicator->remove_snappoint();
- } else if (bd < sd) {
+ _desktop->snapindicator->remove_snaptarget();
+ } else if (bb.getSnapped() && !bb.isOtherSnapBetter(sn, false)) {
// We snapped the bbox (which is either visual or geometric)
- _desktop->snapindicator->set_new_snappoint(bb);
+ _desktop->snapindicator->set_new_snaptarget(bb);
default_scale = Geom::Scale(bb.getTransformation());
// Calculate the new transformation and update the handle position
pt = _calcAbsAffineDefault(default_scale);
} else {
- _desktop->snapindicator->set_new_snappoint(sn);
+ _desktop->snapindicator->set_new_snaptarget(sn);
// We snapped the special points (e.g. nodes), which are not at the visual bbox
// The handle location however (pt) might however be at the visual bbox, so we
// will have to calculate pt taking the stroke width into account
geom_scale = Geom::Scale(sn.getTransformation());
pt = _calcAbsAffineGeom(geom_scale);
}
+ m.unSetup();
}
/* Status text */
@@ -1026,22 +1083,18 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, Geom
Inkscape::SnappedPoint bb, sn;
g_assert(bb.getSnapped() == false); // Check initialization to catch any regression
- Geom::Coord bd(NR_HUGE);
- Geom::Coord sd(NR_HUGE);
bool symmetrical = state & GDK_CONTROL_MASK;
- bb = m.constrainedSnapStretch(Snapper::SNAPPOINT_BBOX, _bbox_points, Geom::Coord(default_scale[axis]), _origin_for_bboxpoints, Geom::Dim2(axis), symmetrical);
- sn = m.constrainedSnapStretch(Snapper::SNAPPOINT_NODE, _snap_points, Geom::Coord(geom_scale[axis]), _origin_for_specpoints, Geom::Dim2(axis), symmetrical);
+ bb = m.constrainedSnapStretch(_bbox_points, _point, Geom::Coord(default_scale[axis]), _origin_for_bboxpoints, Geom::Dim2(axis), symmetrical);
+ sn = m.constrainedSnapStretch(_snap_points, _point, Geom::Coord(geom_scale[axis]), _origin_for_specpoints, Geom::Dim2(axis), symmetrical);
if (bb.getSnapped()) {
// We snapped the bbox (which is either visual or geometric)
- bd = fabs(bb.getTransformation()[axis] - default_scale[axis]);
default_scale[axis] = bb.getTransformation()[axis];
}
if (sn.getSnapped()) {
- sd = fabs(sn.getTransformation()[axis] - geom_scale[axis]);
geom_scale[axis] = sn.getTransformation()[axis];
}
@@ -1055,18 +1108,20 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, Geom
if (!(bb.getSnapped() || sn.getSnapped())) {
// We didn't snap at all! Don't update the handle position, just calculate the new transformation
_calcAbsAffineDefault(default_scale);
- _desktop->snapindicator->remove_snappoint();
- } else if (bd < sd) {
- _desktop->snapindicator->set_new_snappoint(bb);
+ _desktop->snapindicator->remove_snaptarget();
+ } else if (bb.getSnapped() && !bb.isOtherSnapBetter(sn, false)) {
+ _desktop->snapindicator->set_new_snaptarget(bb);
// Calculate the new transformation and update the handle position
pt = _calcAbsAffineDefault(default_scale);
} else {
- _desktop->snapindicator->set_new_snappoint(sn);
+ _desktop->snapindicator->set_new_snaptarget(sn);
// We snapped the special points (e.g. nodes), which are not at the visual bbox
// The handle location however (pt) might however be at the visual bbox, so we
// will have to calculate pt taking the stroke width into account
pt = _calcAbsAffineGeom(geom_scale);
}
+
+ m.unSetup();
}
// status text
@@ -1129,8 +1184,9 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, Geom::P
double radians = atan(skew[dim_a] / scale[dim_a]);
if (state & GDK_CONTROL_MASK) {
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
// Snap to defined angle increments
- int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
+ int snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
if (snaps) {
double sections = floor(radians * snaps / M_PI + .5);
if (fabs(sections) >= snaps / 2) {
@@ -1145,19 +1201,21 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, Geom::P
SnapManager &m = _desktop->namedview->snap_manager;
m.setup(_desktop, false, _items_const);
- Inkscape::Snapper::ConstraintLine const constraint(component_vectors[dim_b]);
+ Inkscape::Snapper::SnapConstraint const constraint(component_vectors[dim_b]);
// When skewing, we cannot snap the corners of the bounding box, see the comment in "constrainedSnapSkew" for details
Geom::Point const s(skew[dim_a], scale[dim_a]);
- Inkscape::SnappedPoint sn = m.constrainedSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, constraint, s, _origin, Geom::Dim2(dim_b));
+ Inkscape::SnappedPoint sn = m.constrainedSnapSkew(_snap_points, _point, constraint, s, _origin, Geom::Dim2(dim_b));
if (sn.getSnapped()) {
// We snapped something, so change the skew to reflect it
Geom::Coord const sd = sn.getSnapped() ? sn.getTransformation()[0] : NR_HUGE;
- _desktop->snapindicator->set_new_snappoint(sn);
+ _desktop->snapindicator->set_new_snaptarget(sn);
skew[dim_a] = sd;
} else {
- _desktop->snapindicator->remove_snappoint();
+ _desktop->snapindicator->remove_snaptarget();
}
+
+ m.unSetup();
}
// Update the handle position
* the handle; otherwise it will be relative to the center as set for the selection
*/
- int snaps = prefs_get_int_attribute("options.rotationsnapsperpi", "value", 12);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ int snaps = prefs->getInt("/options/rotationsnapsperpi/value", 12);
// rotate affine in rotate
Geom::Point const d1 = _point - _origin;
if (fabs(h2) < 1e-15) return FALSE;
Geom::Point q2 = d2 / h2; // normalized new vector to handle
- double radians;
+ Geom::Rotate r1(q1);
+ Geom::Rotate r2(q2);
+
+ double radians = atan2(Geom::dot(Geom::rot90(d1), d2), Geom::dot(d1, d2));;
if (state & GDK_CONTROL_MASK) {
// Snap to defined angle increments
double cos_t = Geom::dot(q1, q2);
if (snaps) {
radians = ( M_PI / snaps ) * floor( radians * snaps / M_PI + .5 );
}
- q1 = Geom::Point(1, 0);
- q2 = Geom::Point(cos(radians), sin(radians));
+ r1 = Geom::Rotate(0); //q1 = Geom::Point(1, 0);
+ r2 = Geom::Rotate(radians); //q2 = Geom::Point(cos(radians), sin(radians));
} else {
- radians = atan2(Geom::dot(Geom::rot90(d1), d2),
- Geom::dot(d1, d2));
+ SnapManager &m = _desktop->namedview->snap_manager;
+ m.setup(_desktop, false, _items_const);
+ // When rotating, we cannot snap the corners of the bounding box, see the comment in "constrainedSnapRotate" for details
+ Inkscape::SnappedPoint sn = m.constrainedSnapRotate(_snap_points, _point, radians, _origin);
+ m.unSetup();
+
+ if (sn.getSnapped()) {
+ _desktop->snapindicator->set_new_snaptarget(sn);
+ // We snapped something, so change the rotation to reflect it
+ radians = sn.getTransformation()[0];
+ r1 = Geom::Rotate(0);
+ r2 = Geom::Rotate(radians);
+ } else {
+ _desktop->snapindicator->remove_snaptarget();
+ }
+
}
- Geom::Rotate const r1(q1);
- Geom::Rotate const r2(q2);
// Calculate the relative affine
_relative_affine = r2 * r1.inverse();
return TRUE;
}
+// Move the item's transformation center
gboolean Inkscape::SelTrans::centerRequest(Geom::Point &pt, guint state)
{
+ // When dragging the transformation center while multiple items have been selected, then those
+ // items will share a single center. While dragging that single center, it should never snap to the
+ // centers of any of the selected objects. Therefore we will have to pass the list of selected items
+ // to the snapper, to avoid self-snapping of the rotation center
+ GSList *items = (GSList *) const_cast<Selection *>(_selection)->itemList();
SnapManager &m = _desktop->namedview->snap_manager;
m.setup(_desktop);
- m.freeSnapReturnByRef(Snapper::SNAPPOINT_NODE, pt);
-
- if (state & GDK_CONTROL_MASK) {
- if ( fabs(_point[Geom::X] - pt[Geom::X]) > fabs(_point[Geom::Y] - pt[Geom::Y]) ) {
- pt[Geom::Y] = _point[Geom::Y];
- } else {
- pt[Geom::X] = _point[Geom::X];
- }
+ m.setRotationCenterSource(items);
+
+ if (state & GDK_CONTROL_MASK) { // with Ctrl, constrain to axes
+ std::vector<Inkscape::Snapper::SnapConstraint> constraints;
+ constraints.push_back(Inkscape::Snapper::SnapConstraint(_point, Geom::Point(1, 0)));
+ constraints.push_back(Inkscape::Snapper::SnapConstraint(_point, Geom::Point(0, 1)));
+ Inkscape::SnappedPoint sp = m.multipleConstrainedSnaps(Inkscape::SnapCandidatePoint(pt, Inkscape::SNAPSOURCE_ROTATION_CENTER), constraints, state & GDK_SHIFT_MASK);
+ pt = sp.getPoint();
}
-
- if ( !(state & GDK_SHIFT_MASK) && _bbox ) {
- // screen pixels to snap center to bbox
-#define SNAP_DIST 5
- // FIXME: take from prefs
- double snap_dist = SNAP_DIST / _desktop->current_zoom();
-
- for (int i = 0; i < 2; i++) {
- if (fabs(pt[i] - _bbox->min()[i]) < snap_dist) {
- pt[i] = _bbox->min()[i];
- }
- if (fabs(pt[i] - _bbox->midpoint()[i]) < snap_dist) {
- pt[i] = _bbox->midpoint()[i];
- }
- if (fabs(pt[i] - _bbox->max()[i]) < snap_dist) {
- pt[i] = _bbox->max()[i];
- }
+ else {
+ if (!(state & GDK_SHIFT_MASK)) { // Shift disables snapping
+ m.freeSnapReturnByRef(pt, Inkscape::SNAPSOURCE_ROTATION_CENTER);
}
}
+ m.unSetup();
+
// status text
GString *xs = SP_PX_TO_METRIC_STRING(pt[Geom::X], _desktop->namedview->getDefaultMetric());
GString *ys = SP_PX_TO_METRIC_STRING(pt[Geom::Y], _desktop->namedview->getDefaultMetric());
@@ -1343,7 +1411,6 @@ void sp_sel_trans_center(Inkscape::SelTrans *seltrans, SPSelTransHandle const &,
void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state)
{
SnapManager &m = _desktop->namedview->snap_manager;
- m.setup(_desktop, true, _items_const);
/* The amount that we've moved by during this drag */
Geom::Point dxy = xy - _point;
if (alt) {
- /* Alt pressed means keep offset: snap the moved distance to the grid.
- ** FIXME: this will snap to more than just the grid, nowadays.
- */
-
- m.freeSnapReturnByRef(Snapper::SNAPPOINT_NODE, dxy);
+ // Alt pressed means: move only by integer multiples of the grid spacing
- } else if (!shift) {
+ if (control) { // ... if also constrained to the orthogonal axes
+ if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) {
+ dxy[Geom::Y] = 0;
+ } else {
+ dxy[Geom::X] = 0;
+ }
+ }
+ m.setup(_desktop, true, _items_const);
+ dxy = m.multipleOfGridPitch(dxy, _point);
+ m.unSetup();
+ } else if (shift) {
+ if (control) { // shift & control: constrained movement without snapping
+ if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) {
+ dxy[Geom::Y] = 0;
+ } else {
+ dxy[Geom::X] = 0;
+ }
+ }
+ } else { //!shift: with snapping
/* We're snapping to things, possibly with a constraint to horizontal or
** vertical movement. Obtain a list of possible translations and then
** pick the smallest.
*/
+ m.setup(_desktop, false, _items_const);
+
/* This will be our list of possible translations */
std::list<Inkscape::SnappedPoint> s;
- if (control) {
+ if (control) { // constrained movement with snapping
/* Snap to things, and also constrain to horizontal or vertical movement */
- for (unsigned int dim = 0; dim < 2; dim++) {
- // When doing a constrained translation, all points will move in the same direction, i.e.
- // either horizontally or vertically. Therefore we only have to specify the direction of
- // the constraint-line once. The constraint lines are parallel, but might not be colinear.
- // Therefore we will have to set the point through which the constraint-line runs
- // individually for each point to be snapped; this will be handled however by _snapTransformed()
- s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX,
- _bbox_points,
- Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
- dxy));
-
- s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAPPOINT_NODE,
- _snap_points,
- Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
- dxy));
- }
-
- } else {
+ unsigned int dim = fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y]) ? Geom::X : Geom::Y;
+ // When doing a constrained translation, all points will move in the same direction, i.e.
+ // either horizontally or vertically. Therefore we only have to specify the direction of
+ // the constraint-line once. The constraint lines are parallel, but might not be colinear.
+ // Therefore we will have to set the point through which the constraint-line runs
+ // individually for each point to be snapped; this will be handled however by _snapTransformed()
+ s.push_back(m.constrainedSnapTranslate(_bbox_points_for_translating,
+ _point,
+ Inkscape::Snapper::SnapConstraint(component_vectors[dim]),
+ dxy));
+
+ s.push_back(m.constrainedSnapTranslate(_snap_points,
+ _point,
+ Inkscape::Snapper::SnapConstraint(component_vectors[dim]),
+ dxy));
+ } else { // !control
// Let's leave this timer code here for a while. I'll probably need it in the near future (Diederik van Lierop)
/* GTimeVal starttime;
GTimeVal endtime;
- g_get_current_time(&starttime); */
+ g_get_current_time(&starttime); */
/* Snap to things with no constraint */
- s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, dxy));
- s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, dxy));
+ s.push_back(m.freeSnapTranslate(_bbox_points_for_translating, _point, dxy));
+ s.push_back(m.freeSnapTranslate(_snap_points, _point, dxy));
- /*g_get_current_time(&endtime);
- double elapsed = ((((double)endtime.tv_sec - starttime.tv_sec) * G_USEC_PER_SEC + (endtime.tv_usec - starttime.tv_usec))) / 1000.0;
- std::cout << "Time spent snapping: " << elapsed << std::endl; */
+ /*g_get_current_time(&endtime);
+ double elapsed = ((((double)endtime.tv_sec - starttime.tv_sec) * G_USEC_PER_SEC + (endtime.tv_usec - starttime.tv_usec))) / 1000.0;
+ std::cout << "Time spent snapping: " << elapsed << std::endl; */
}
+ m.unSetup();
/* Pick one */
Inkscape::SnappedPoint best_snapped_point;
- g_assert(best_snapped_point.getDistance() == NR_HUGE);
for (std::list<Inkscape::SnappedPoint>::const_iterator i = s.begin(); i != s.end(); i++) {
if (i->getSnapped()) {
- if (i->getDistance() < best_snapped_point.getDistance()) {
+ if (best_snapped_point.isOtherSnapBetter(*i, true)) {
best_snapped_point = *i;
dxy = i->getTransformation();
}
}
}
+
if (best_snapped_point.getSnapped()) {
- _desktop->snapindicator->set_new_snappoint(best_snapped_point);
+ _desktop->snapindicator->set_new_snaptarget(best_snapped_point);
} else {
- // We didn't snap, so remove any previous snap indicator
- _desktop->snapindicator->remove_snappoint();
+ // We didn't snap, so remove any previous snap indicator
+ _desktop->snapindicator->remove_snaptarget();
if (control) {
// If we didn't snap, then we should still constrain horizontally or vertically
// (When we did snap, then this constraint has already been enforced by
- // calling constrainedSnapTranslation() above)
+ // calling constrainedSnapTranslate() above)
if (fabs(dxy[Geom::X]) > fabs(dxy[Geom::Y])) {
dxy[Geom::Y] = 0;
} else {
}
}
}
-
+
Geom::Matrix const move((Geom::Translate(dxy)));
Geom::Point const norm(0, 0);
transform(move, norm);
@@ -1471,7 +1553,8 @@ Geom::Point Inkscape::SelTrans::_getGeomHandlePos(Geom::Point const &visual_hand
Geom::Point normalized_handle_pos = (visual_handle_pos - new_bbox.min()) * Geom::Scale(new_bbox.dimensions()).inverse();
// Calculate the absolute affine while taking into account the scaling of the stroke width
- int transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool transform_stroke = prefs->getBool("/options/transform/stroke", true);
Geom::Matrix abs_affine = get_scale_transform_with_stroke (*_bbox, _strokewidth, transform_stroke,
new_bbox.min()[Geom::X], new_bbox.min()[Geom::Y], new_bbox.max()[Geom::X], new_bbox.max()[Geom::Y]);
@@ -1510,11 +1593,12 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineDefault(Geom::Scale const default_
Geom::Point new_bbox_min = _approximate_bbox->min() * abs_affine;
Geom::Point new_bbox_max = _approximate_bbox->max() * abs_affine;
- int transform_stroke = false;
+ bool transform_stroke = false;
gdouble strokewidth = 0;
if ( _snap_bbox_type != SPItem::GEOMETRIC_BBOX) {
- transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ transform_stroke = prefs->getBool("/options/transform/stroke", true);
strokewidth = _strokewidth;
}
@@ -1531,13 +1615,40 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineGeom(Geom::Scale const geom_scale)
_relative_affine = Geom::Matrix(geom_scale);
_absolute_affine = Geom::Translate(-_origin_for_specpoints) * _relative_affine * Geom::Translate(_origin_for_specpoints);
- bool const transform_stroke = prefs_get_int_attribute ("options.transform", "stroke", 1);
- Geom::Rect visual_bbox = get_visual_bbox(_geometric_bbox, _absolute_affine, _strokewidth, transform_stroke);
+ Inkscape::Preferences *prefs = Inkscape::Preferences::get();
+ bool const transform_stroke = prefs->getBool("/options/transform/stroke", true);
+ if (_geometric_bbox) {
+ Geom::Rect visual_bbox = get_visual_bbox(_geometric_bbox, _absolute_affine, _strokewidth, transform_stroke);
+ // return the new handle position
+ return visual_bbox.min() + visual_bbox.dimensions() * Geom::Scale(_handle_x, _handle_y);
+ }
- // return the new handle position
- return visual_bbox.min() + visual_bbox.dimensions() * Geom::Scale(_handle_x, _handle_y);
+ // Fall back scenario, in case we don't have a geometric bounding box at hand;
+ // (Due to some bugs related to bounding boxes having at least one zero dimension; For more details
+ // see https://bugs.launchpad.net/inkscape/+bug/318726)
+ g_warning("No geometric bounding box has been calculated; this is a bug that needs fixing!");
+ return _calcAbsAffineDefault(geom_scale); // this is bogus, but we must return _something_
}
+void Inkscape::SelTrans::_keepClosestPointOnly(std::vector<Inkscape::SnapCandidatePoint> &points, const Geom::Point &reference)
+{
+ if (points.size() < 2) return;
+
+ Inkscape::SnapCandidatePoint closest_point = Inkscape::SnapCandidatePoint(Geom::Point(NR_HUGE, NR_HUGE), SNAPSOURCE_UNDEFINED, SNAPTARGET_UNDEFINED);
+ Geom::Coord closest_dist = NR_HUGE;
+
+ for(std::vector<Inkscape::SnapCandidatePoint>::const_iterator i = points.begin(); i != points.end(); i++) {
+ Geom::Coord dist = Geom::L2((*i).getPoint() - reference);
+ if (i == points.begin() || dist < closest_dist) {
+ closest_point = *i;
+ closest_dist = dist;
+ }
+ }
+
+ closest_point.setSourceNum(-1);
+ points.clear();
+ points.push_back(closest_point);
+}
/*
Local Variables:
@@ -1548,4 +1659,4 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineGeom(Geom::Scale const geom_scale)
fill-column:99
End:
*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :