From 77dc5f1acd4a6b66b2d6fc5c81f7e5c61ef95785 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Thu, 5 Aug 2010 02:49:51 +0200 Subject: Wholesale cruft removal part 4; fix crash when rendering guides (bzr r9508.1.48) --- src/seltrans.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 05f47d4ab..64c41ea23 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -377,9 +377,9 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s } // 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; + Geom::Coord dsp = _snap_points.size() == 1 ? Geom::L2((_snap_points.at(0)).getPoint() - p) : Geom::infinity(); + Geom::Coord dbbp = _bbox_points.size() == 1 ? Geom::L2((_bbox_points.at(0)).getPoint() - p) : Geom::infinity(); + Geom::Coord dbbpft = _bbox_points_for_translating.size() == 1 ? Geom::L2((_bbox_points_for_translating.at(0)).getPoint() - p) : Geom::infinity(); if (translating) { _bbox_points.clear(); @@ -1216,7 +1216,7 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, Geom::P if (sn.getSnapped()) { // We snapped something, so change the skew to reflect it - Geom::Coord const sd = sn.getSnapped() ? sn.getTransformation()[0] : NR_HUGE; + Geom::Coord const sd = sn.getSnapped() ? sn.getTransformation()[0] : Geom::infinity(); _desktop->snapindicator->set_new_snaptarget(sn); skew[dim_a] = sd; } else { @@ -1630,8 +1630,8 @@ void Inkscape::SelTrans::_keepClosestPointOnly(std::vector::const_iterator i = points.begin(); i != points.end(); i++) { Geom::Coord dist = Geom::L2((*i).getPoint() - reference); -- 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/seltrans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index bb333caca..f95a204a9 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -359,7 +359,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s // points immediately. if (prefs->getBool("/options/snapclosestonly/value", false)) { - if (m.snapprefs.getSnapModeNode()) { + if (m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers()) { m.keepClosestPointOnly(_snap_points, p); } else { _snap_points.clear(); // don't keep any point -- cgit v1.2.3 From dd5da66df059871c546f4d09b9d2eb92e71b74b7 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 10 Jul 2011 21:40:56 +0200 Subject: Selector's toolbar: changing the dimensions of the visual bounding box of selection of multiple objects having different stroke widths has been fixed (bug #212768, #190557, ...) Fixed bugs: - https://launchpad.net/bugs/212768 - https://launchpad.net/bugs/190557 (bzr r10437.1.5) --- src/seltrans.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index f95a204a9..f6a702ed9 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1566,7 +1566,7 @@ Geom::Point Inkscape::SelTrans::_getGeomHandlePos(Geom::Point const &visual_hand // Calculate the absolute affine while taking into account the scaling of the stroke width Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool transform_stroke = prefs->getBool("/options/transform/stroke", true); - Geom::Affine abs_affine = get_scale_transform_with_stroke (*_bbox, _strokewidth, transform_stroke, + Geom::Affine abs_affine = get_scale_transform_with_uniform_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]); // Calculate the scaled geometrical bbox @@ -1613,7 +1613,7 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineDefault(Geom::Scale const default_ strokewidth = _strokewidth; } - _absolute_affine = get_scale_transform_with_stroke (*_approximate_bbox, strokewidth, transform_stroke, + _absolute_affine = get_scale_transform_with_uniform_stroke (*_approximate_bbox, strokewidth, transform_stroke, new_bbox_min[Geom::X], new_bbox_min[Geom::Y], new_bbox_max[Geom::X], new_bbox_max[Geom::Y]); // return the new handle position -- 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/seltrans.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index f6a702ed9..bc8194d48 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -267,7 +267,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s SPItem *it = reinterpret_cast(sp_object_ref(SP_ITEM(l->data), NULL)); _items.push_back(it); _items_const.push_back(it); - _items_affines.push_back(it->i2d_affine()); + _items_affines.push_back(it->i2dt_affine()); _items_centers.push_back(it->getCenter()); // for content-dragging, we need to remember original centers } @@ -586,7 +586,7 @@ void Inkscape::SelTrans::stamp() Geom::Affine const *new_affine; if (_show == SHOW_OUTLINE) { - Geom::Affine const i2d(original_item->i2d_affine()); + Geom::Affine const i2d(original_item->i2dt_affine()); Geom::Affine const i2dnew( i2d * _current_relative_affine ); copy_item->set_i2d_affine(i2dnew); new_affine = ©_item->transform; -- 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/seltrans.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index bc8194d48..7538e15d9 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -324,18 +324,19 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s _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(); + bool c = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CORNER); + bool mp = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_MIDPOINT); + bool emp = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE_MIDPOINT); // 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); + getBBoxPoints(selection->bounds(_snap_bbox_type), &_bbox_points, false, c, 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(_items[i]->getBboxDesktop(_snap_bbox_type), &_bbox_points_for_translating, false, true, emp, mp); + getBBoxPoints(_items[i]->getBboxDesktop(_snap_bbox_type), &_bbox_points_for_translating, false, c, emp, mp); } } else { _bbox_points_for_translating = _bbox_points; // use the bbox points of the selection as a whole -- 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/seltrans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 7538e15d9..3a204a49e 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -360,7 +360,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s // points immediately. if (prefs->getBool("/options/snapclosestonly/value", false)) { - if (m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers()) { + if (m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers() || m.snapprefs.getSnapModeDatums()) { m.keepClosestPointOnly(_snap_points, p); } else { _snap_points.clear(); // don't keep any point -- 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/seltrans.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 3a204a49e..0e5e533fc 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -90,7 +90,7 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : _grabbed(false), _show_handles(true), _bbox(), - _approximate_bbox(), + _visual_bbox(), _absolute_affine(Geom::Scale(1,1)), _opposite(Geom::Point(0,0)), _opposite_for_specpoints(Geom::Point(0,0)), @@ -104,7 +104,7 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : 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; + SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; g_return_if_fail(desktop != NULL); @@ -279,8 +279,8 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s // 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); + _visual_bbox = selection->visualBounds(); // Used for correctly scaling the strokewidth + _geometric_bbox = selection->geometricBounds(); _point = p; if (_geometric_bbox) { @@ -336,7 +336,8 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s // 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(_items[i]->getBboxDesktop(_snap_bbox_type), &_bbox_points_for_translating, false, c, emp, mp); + Geom::OptRect b = _items[i]->desktopBounds(_snap_bbox_type); + getBBoxPoints(b, &_bbox_points_for_translating, false, c, emp, mp); } } else { _bbox_points_for_translating = _bbox_points; // use the bbox points of the selection as a whole @@ -696,7 +697,7 @@ void Inkscape::SelTrans::_updateVolatileState() //Update the bboxes _bbox = selection->bounds(_snap_bbox_type); - _approximate_bbox = selection->bounds(SPItem::APPROXIMATE_BBOX); + _visual_bbox = selection->visualBounds(); if (!_bbox) { _empty = true; @@ -898,8 +899,7 @@ void Inkscape::SelTrans::_selChanged(Inkscape::Selection */*selection*/) // reread in case it changed on the fly: 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 + SPItem::VISUAL_BBOX : SPItem::GEOMETRIC_BBOX; _updateVolatileState(); _current_relative_affine.setIdentity(); @@ -1602,8 +1602,8 @@ Geom::Scale Inkscape::calcScaleFactors(Geom::Point const &initial_point, Geom::P Geom::Point Inkscape::SelTrans::_calcAbsAffineDefault(Geom::Scale const default_scale) { Geom::Affine abs_affine = Geom::Translate(-_origin) * Geom::Affine(default_scale) * Geom::Translate(_origin); - Geom::Point new_bbox_min = _approximate_bbox->min() * abs_affine; - Geom::Point new_bbox_max = _approximate_bbox->max() * abs_affine; + Geom::Point new_bbox_min = _visual_bbox->min() * abs_affine; + Geom::Point new_bbox_max = _visual_bbox->max() * abs_affine; bool transform_stroke = false; gdouble strokewidth = 0; @@ -1614,7 +1614,7 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineDefault(Geom::Scale const default_ strokewidth = _strokewidth; } - _absolute_affine = get_scale_transform_with_uniform_stroke (*_approximate_bbox, strokewidth, transform_stroke, + _absolute_affine = get_scale_transform_with_uniform_stroke (*_visual_bbox, strokewidth, transform_stroke, new_bbox_min[Geom::X], new_bbox_min[Geom::Y], new_bbox_max[Geom::X], new_bbox_max[Geom::Y]); // return the new handle position -- cgit v1.2.3 From d6af1140ee108cc7d7fb6e0ba89ff7e30bb7ad3a Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Sat, 27 Aug 2011 18:05:32 +0200 Subject: Completely remove NRRect, NRRectL, in-svg-plane.h (bzr r10582.1.6) --- src/seltrans.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 0e5e533fc..19c09902b 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1213,7 +1213,8 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, Geom::P SnapManager &m = _desktop->namedview->snap_manager; m.setup(_desktop, false, _items_const); - Inkscape::Snapper::SnapConstraint const constraint(component_vectors[dim_b]); + Geom::Point cvec; cvec[dim_b] = 1.; + Inkscape::Snapper::SnapConstraint const constraint(cvec); // 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(_snap_points, _point, constraint, s, _origin, Geom::Dim2(dim_b)); @@ -1475,14 +1476,15 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) // 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() + Geom::Point cvec; cvec[dim] = 1.; s.push_back(m.constrainedSnapTranslate(_bbox_points_for_translating, _point, - Inkscape::Snapper::SnapConstraint(component_vectors[dim]), + Inkscape::Snapper::SnapConstraint(cvec), dxy)); s.push_back(m.constrainedSnapTranslate(_snap_points, _point, - Inkscape::Snapper::SnapConstraint(component_vectors[dim]), + Inkscape::Snapper::SnapConstraint(cvec), dxy)); } else { // !control -- cgit v1.2.3 From 1c0a4eca434ada5675c6edc476325b7bb64da1a6 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sun, 4 Sep 2011 20:11:51 +0200 Subject: 1) Fix absolute scaling in transform dialog 2) Transform dialog now follows the user prefs for geometric vs. visual bounding box (bzr r10615) --- src/seltrans.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 19c09902b..20013ab0c 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -329,7 +329,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s bool emp = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE_MIDPOINT); // 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. + // stroke width. (see get_scale_transform_for_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, c, emp, mp); if (((_items.size() > 0) && (_items.size() < 50)) || prefs->getBool("/options/snapclosestonly/value", false)) { @@ -1560,7 +1560,7 @@ Geom::Point Inkscape::SelTrans::_getGeomHandlePos(Geom::Point const &visual_hand } // Using the Geom::Rect constructor below ensures that "min() < max()", which is important - // because this will also hold for _bbox, and which is required for get_scale_transform_with_stroke() + // because this will also hold for _bbox, and which is required for get_scale_transform_for_stroke() Geom::Rect new_bbox = Geom::Rect(_origin_for_bboxpoints, visual_handle_pos); // new visual bounding box // Please note that the new_bbox might in fact be just a single line, for example when stretching (in // which case the handle and origin will be aligned vertically or horizontally) @@ -1569,7 +1569,7 @@ Geom::Point Inkscape::SelTrans::_getGeomHandlePos(Geom::Point const &visual_hand // Calculate the absolute affine while taking into account the scaling of the stroke width Inkscape::Preferences *prefs = Inkscape::Preferences::get(); bool transform_stroke = prefs->getBool("/options/transform/stroke", true); - Geom::Affine abs_affine = get_scale_transform_with_uniform_stroke (*_bbox, _strokewidth, transform_stroke, + Geom::Affine abs_affine = get_scale_transform_for_uniform_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]); // Calculate the scaled geometrical bbox @@ -1616,7 +1616,7 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineDefault(Geom::Scale const default_ strokewidth = _strokewidth; } - _absolute_affine = get_scale_transform_with_uniform_stroke (*_visual_bbox, strokewidth, transform_stroke, + _absolute_affine = get_scale_transform_for_uniform_stroke (*_visual_bbox, strokewidth, transform_stroke, new_bbox_min[Geom::X], new_bbox_min[Geom::Y], new_bbox_max[Geom::X], new_bbox_max[Geom::Y]); // return the new handle position -- cgit v1.2.3 From ee17bac8a5d9b6bf840272885c1eda57c45fb4ad Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 17 Sep 2011 01:00:05 +0200 Subject: Node tool, transforming a set of nodes: Fix crashes, and finish implementation of snapping Fixed bugs: - https://launchpad.net/bugs/590261 (bzr r10633) --- src/seltrans.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 20013ab0c..c6dd0a34d 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1221,9 +1221,8 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, Geom::P if (sn.getSnapped()) { // We snapped something, so change the skew to reflect it - Geom::Coord const sd = sn.getSnapped() ? sn.getTransformation()[0] : Geom::infinity(); + skew[dim_a] = sn.getTransformation()[0]; _desktop->snapindicator->set_new_snaptarget(sn); - skew[dim_a] = sd; } else { _desktop->snapindicator->remove_snaptarget(); } -- 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/seltrans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index c6dd0a34d..2d09f393e 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1,5 +1,5 @@ /** @file - * @brief Helper object for transforming selected items + * Helper object for transforming selected items. */ /* Authors: * Lauris Kaplinski -- cgit v1.2.3 From 224a99dc216119d34eb3ed13d12f123158acfe3c Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Fri, 4 Nov 2011 22:30:19 +0100 Subject: 1) Cycle to the next-closest-snap-source when pressing tab, if the snap-closest-point-only-option has been activated. Works for the selector tool, but also when scaling/stretching/skewing a selection of nodes in the node tool 2) Cleanup and simplification of the code that finds the closest snapsource (bzr r10720) --- src/seltrans.cpp | 150 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 64 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 2d09f393e..4889f7dc1 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -163,6 +163,8 @@ Inkscape::SelTrans::SelTrans(SPDesktop *desktop) : _sel_modified_connection = _selection->connectModified( sigc::mem_fun(*this, &Inkscape::SelTrans::_selModified) ); + + _all_snap_sources_iter = _all_snap_sources_sorted.end(); } Inkscape::SelTrans::~SelTrans() @@ -296,13 +298,10 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s 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 - (s)he could hardly discern which node would be snapping */ - if (prefs->getBool("/options/snapclosestonly/value", false)) { - m.keepClosestPointOnly(_snap_points, p); - } else { - _snap_points = snap_points_hull; - } + A typical user would rarely ever try to snap such a large number of nodes anyway, because + (s)he would hardly be able to discern which node would be snapping */ + _snap_points = snap_points_hull; + //} // Unfortunately, by now we will have lost the font-baseline snappoints :-( } @@ -321,26 +320,27 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s } _bbox_points.clear(); - _bbox_points_for_translating.clear(); // Collect the bounding box's corners and midpoints for each selected item if (m.snapprefs.getSnapModeBBox()) { bool c = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CORNER); bool mp = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_MIDPOINT); bool emp = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE_MIDPOINT); - // Preferably we'd use the bbox of each selected item, instead of the bbox of the selection as a whole; for translations + // 1) 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_for_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, c, 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 + // 2) 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 + bool c1 = (_items.size() > 0) && (_items.size() < 50); + bool c2 = prefs->getBool("/options/snapclosestonly/value", false); + if (translating && (c1 || c2)) { + // Get the bounding box points for each item in the selection for (unsigned i = 0; i < _items.size(); i++) { Geom::OptRect b = _items[i]->desktopBounds(_snap_bbox_type); - getBBoxPoints(b, &_bbox_points_for_translating, false, c, emp, mp); + getBBoxPoints(b, &_bbox_points, false, c, emp, mp); } } else { - _bbox_points_for_translating = _bbox_points; // use the bbox points of the selection as a whole + // Only get the bounding box points of the selection as a whole + getBBoxPoints(selection->bounds(_snap_bbox_type), &_bbox_points, false, c, emp, mp); } } @@ -357,54 +357,10 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s } // 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. + // (i.e. when weight == 1), then we will not even try to snap to other points and disregard those other points if (prefs->getBool("/options/snapclosestonly/value", false)) { - if (m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers() || m.snapprefs.getSnapModeDatums()) { - m.keepClosestPointOnly(_snap_points, p); - } else { - _snap_points.clear(); // don't keep any point - } - - if (m.snapprefs.getSnapModeBBox()) { - m.keepClosestPointOnly(_bbox_points, p); - m.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) : Geom::infinity(); - Geom::Coord dbbp = _bbox_points.size() == 1 ? Geom::L2((_bbox_points.at(0)).getPoint() - p) : Geom::infinity(); - Geom::Coord dbbpft = _bbox_points_for_translating.size() == 1 ? Geom::L2((_bbox_points_for_translating.at(0)).getPoint() - p) : Geom::infinity(); - - 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"); - } - + _keepClosestPointOnly(p, translating); } if ((x != -1) && (y != -1)) { @@ -1476,7 +1432,7 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) // 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() Geom::Point cvec; cvec[dim] = 1.; - s.push_back(m.constrainedSnapTranslate(_bbox_points_for_translating, + s.push_back(m.constrainedSnapTranslate(_bbox_points, _point, Inkscape::Snapper::SnapConstraint(cvec), dxy)); @@ -1493,7 +1449,7 @@ void Inkscape::SelTrans::moveTo(Geom::Point const &xy, guint state) g_get_current_time(&starttime); */ /* Snap to things with no constraint */ - s.push_back(m.freeSnapTranslate(_bbox_points_for_translating, _point, dxy)); + s.push_back(m.freeSnapTranslate(_bbox_points, _point, dxy)); s.push_back(m.freeSnapTranslate(_snap_points, _point, dxy)); /*g_get_current_time(&endtime); @@ -1643,6 +1599,72 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineGeom(Geom::Scale const geom_scale) return _calcAbsAffineDefault(geom_scale); // this is bogus, but we must return _something_ } +void Inkscape::SelTrans::_keepClosestPointOnly(Geom::Point const &p, bool const translating) +{ + SnapManager const &m = _desktop->namedview->snap_manager; + + if (!(m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers() || m.snapprefs.getSnapModeDatums())) { + _snap_points.clear(); + } + + if (!m.snapprefs.getSnapModeBBox()) { + _bbox_points.clear(); + } + + _all_snap_sources_sorted = _snap_points; + _all_snap_sources_sorted.insert(_all_snap_sources_sorted.end(), _bbox_points.begin(), _bbox_points.end()); + + // Calculate and store the distance to the reference point for each snap candidate point + for(std::vector::iterator i = _all_snap_sources_sorted.begin(); i != _all_snap_sources_sorted.end(); ++i) { + (*i).setDistance(Geom::L2((*i).getPoint() - p)); + } + + // Sort them ascending, using the distance calculated above as the single criteria + std::sort(_all_snap_sources_sorted.begin(), _all_snap_sources_sorted.end()); + + // Now get the closest snap source + _snap_points.clear(); + _bbox_points.clear(); + if (!_all_snap_sources_sorted.empty()) { + _all_snap_sources_iter = _all_snap_sources_sorted.begin(); + if (_all_snap_sources_sorted.front().getSourceType() & SNAPSOURCE_BBOX_CATEGORY) { + _bbox_points.push_back(_all_snap_sources_sorted.front()); + } else { + _snap_points.push_back(_all_snap_sources_sorted.front()); + } + } + +} + +void Inkscape::SelTrans::getNextClosestPoint(bool reverse) +{ + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + if (prefs->getBool("/options/snapclosestonly/value", false)) { + if (!_all_snap_sources_sorted.empty()) { + if (reverse) { // Shift-tab will find a closer point + if (_all_snap_sources_iter == _all_snap_sources_sorted.begin()) { + _all_snap_sources_iter = _all_snap_sources_sorted.end(); + } + --_all_snap_sources_iter; + } else { // Tab will find a point further away + ++_all_snap_sources_iter; + if (_all_snap_sources_iter == _all_snap_sources_sorted.end()) { + _all_snap_sources_iter = _all_snap_sources_sorted.begin(); + } + } + + _snap_points.clear(); + _bbox_points.clear(); + + if ((*_all_snap_sources_iter).getSourceType() & SNAPSOURCE_BBOX_CATEGORY) { + _bbox_points.push_back(*_all_snap_sources_iter); + } else { + _snap_points.push_back(*_all_snap_sources_iter); + } + } + } +} + /* Local Variables: mode:c++ -- cgit v1.2.3 From b46cc1a396cacef9d38411aa7639518afaebf891 Mon Sep 17 00:00:00 2001 From: "Jon A. Cruz" Date: Sat, 5 Nov 2011 03:04:17 -0700 Subject: Minor code safety and warning cleanup. (bzr r10722) --- src/seltrans.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 4889f7dc1..84cd5574e 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -1599,7 +1599,7 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineGeom(Geom::Scale const geom_scale) return _calcAbsAffineDefault(geom_scale); // this is bogus, but we must return _something_ } -void Inkscape::SelTrans::_keepClosestPointOnly(Geom::Point const &p, bool const translating) +void Inkscape::SelTrans::_keepClosestPointOnly(Geom::Point const &p, bool const /*translating*/) { SnapManager const &m = _desktop->namedview->snap_manager; -- cgit v1.2.3 From 9c742405cf7d906a14ab5003a612b37d4c496849 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 5 Nov 2011 20:53:36 +0100 Subject: Remove unused parameter (bzr r10723) --- src/seltrans.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 84cd5574e..cb8270bf2 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -360,7 +360,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s // (i.e. when weight == 1), then we will not even try to snap to other points and disregard those other points if (prefs->getBool("/options/snapclosestonly/value", false)) { - _keepClosestPointOnly(p, translating); + _keepClosestPointOnly(p); } if ((x != -1) && (y != -1)) { @@ -1599,7 +1599,7 @@ Geom::Point Inkscape::SelTrans::_calcAbsAffineGeom(Geom::Scale const geom_scale) return _calcAbsAffineDefault(geom_scale); // this is bogus, but we must return _something_ } -void Inkscape::SelTrans::_keepClosestPointOnly(Geom::Point const &p, bool const /*translating*/) +void Inkscape::SelTrans::_keepClosestPointOnly(Geom::Point const &p) { SnapManager const &m = _desktop->namedview->snap_manager; -- 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/seltrans.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/seltrans.cpp') diff --git a/src/seltrans.cpp b/src/seltrans.cpp index cb8270bf2..9439ed0ac 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -321,7 +321,7 @@ void Inkscape::SelTrans::grab(Geom::Point const &p, gdouble x, gdouble y, bool s _bbox_points.clear(); // Collect the bounding box's corners and midpoints for each selected item - if (m.snapprefs.getSnapModeBBox()) { + if (m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CATEGORY)) { bool c = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CORNER); bool mp = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_MIDPOINT); bool emp = m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_EDGE_MIDPOINT); @@ -1603,11 +1603,13 @@ void Inkscape::SelTrans::_keepClosestPointOnly(Geom::Point const &p) { SnapManager const &m = _desktop->namedview->snap_manager; - if (!(m.snapprefs.getSnapModeNode() || m.snapprefs.getSnapModeOthers() || m.snapprefs.getSnapModeDatums())) { + // If we're not going to snap nodes, then we might just as well get rid of their snappoints right away + if (!(m.snapprefs.isTargetSnappable(SNAPTARGET_NODE_CATEGORY, SNAPTARGET_OTHERS_CATEGORY) || m.snapprefs.isAnyDatumSnappable())) { _snap_points.clear(); } - if (!m.snapprefs.getSnapModeBBox()) { + // If we're not going to snap bounding boxes, then we might just as well get rid of their snappoints right away + if (!m.snapprefs.isTargetSnappable(SNAPTARGET_BBOX_CATEGORY)) { _bbox_points.clear(); } -- cgit v1.2.3