From: dvlierop2 Date: Sat, 31 Jan 2009 13:51:52 +0000 (+0000) Subject: Store the snapper tolerances in the snap-preferences instead of in each snapper indiv... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6debf70683e9b0f2787a5341a9e186903962d54e;p=inkscape.git Store the snapper tolerances in the snap-preferences instead of in each snapper individualy. This way we don't have to update all snappers when the namedview has been updated (and we can get rid of the _update_snap_distances() call) --- diff --git a/src/desktop.cpp b/src/desktop.cpp index 85df3af04..1f2baccbb 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -104,7 +104,6 @@ static void _layer_hierarchy_changed(SPObject *top, SPObject *bottom, SPDesktop static void _reconstruction_start(SPDesktop * desktop); static void _reconstruction_finish(SPDesktop * desktop); static void _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop); -static void _update_snap_distances (SPDesktop *desktop); /** * Return new desktop object. @@ -1698,12 +1697,6 @@ _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop) if (flags & SP_OBJECT_MODIFIED_FLAG) { - /* Recalculate snap distances */ - /* FIXME: why is the desktop getting involved in setting up something - ** that is entirely to do with the namedview? - */ - _update_snap_distances (desktop); - /* Show/hide page background */ if (nv->pagecolor & 0xff) { sp_canvas_item_show (desktop->table); @@ -1758,33 +1751,6 @@ _namedview_modified (SPObject *obj, guint flags, SPDesktop *desktop) } } -/** - * Callback to reset snapper's distances. - */ -static void -_update_snap_distances (SPDesktop *desktop) -{ - SPUnit const &px = sp_unit_get_by_id(SP_UNIT_PX); - - SPNamedView &nv = *desktop->namedview; - - //tell all grid snappers - for ( GSList const *l = nv.grids; l != NULL; l = l->next) { - Inkscape::CanvasGrid *grid = (Inkscape::CanvasGrid*) l->data; - grid->snapper->setSnapperTolerance(sp_convert_distance_full(nv.gridtolerance, - *nv.gridtoleranceunit, - px)); - } - - nv.snap_manager.guide.setSnapperTolerance(sp_convert_distance_full(nv.guidetolerance, - *nv.guidetoleranceunit, - px)); - nv.snap_manager.object.setSnapperTolerance(sp_convert_distance_full(nv.objecttolerance, - *nv.objecttoleranceunit, - px)); -} - - Geom::Matrix SPDesktop::w2d() const { return _w2d; diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 283f58a01..076dcdd33 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -661,6 +661,21 @@ CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapMan this->grid = grid; } +/** + * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels + */ +Geom::Coord CanvasAxonomGridSnapper::getSnapperTolerance() const +{ + SPDesktop const *dt = _snapmanager->getDesktop(); + double const zoom = dt ? dt->current_zoom() : 1; + return _snapmanager->snapprefs.getGridTolerance() / zoom; +} + +bool CanvasAxonomGridSnapper::getSnapperAlwaysSnap() const +{ + return _snapmanager->snapprefs.getGridTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp +} + LineSnapper::LineList CanvasAxonomGridSnapper::_getSnapLines(Geom::Point const &p) const { diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index 9067e2e13..4849f08ad 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -73,6 +73,9 @@ public: CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager *sm, Geom::Coord const d); bool ThisSnapperMightSnap() const; + Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) + bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance + private: LineList _getSnapLines(Geom::Point const &p) const; void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, const Geom::Point point_on_line) const; diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 0d5cabd8d..49a1211eb 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -953,6 +953,21 @@ CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager *sm, Ge this->grid = grid; } +/** + * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels + */ +Geom::Coord CanvasXYGridSnapper::getSnapperTolerance() const +{ + SPDesktop const *dt = _snapmanager->getDesktop(); + double const zoom = dt ? dt->current_zoom() : 1; + return _snapmanager->snapprefs.getGridTolerance() / zoom; +} + +bool CanvasXYGridSnapper::getSnapperAlwaysSnap() const +{ + return _snapmanager->snapprefs.getGridTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp +} + LineSnapper::LineList CanvasXYGridSnapper::_getSnapLines(Geom::Point const &p) const { diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index e4bd01414..85e890fef 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -161,6 +161,9 @@ public: CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager *sm, Geom::Coord const d); bool ThisSnapperMightSnap() const; + Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) + bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance + private: LineList _getSnapLines(Geom::Point const &p) const; void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, const Geom::Point point_on_line) const; diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index 54a4086a4..f344d891f 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -15,6 +15,7 @@ #include "libnr/nr-values.h" #include "libnr/nr-point-fns.h" #include "sp-namedview.h" +#include "desktop.h" #include "sp-guide.h" Inkscape::GuideSnapper::GuideSnapper(SnapManager *sm, Geom::Coord const d) : LineSnapper(sm, d) @@ -22,6 +23,21 @@ Inkscape::GuideSnapper::GuideSnapper(SnapManager *sm, Geom::Coord const d) : Lin } +/** + * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels + */ +Geom::Coord Inkscape::GuideSnapper::getSnapperTolerance() const +{ + SPDesktop const *dt = _snapmanager->getDesktop(); + double const zoom = dt ? dt->current_zoom() : 1; + return _snapmanager->snapprefs.getGuideTolerance() / zoom; +} + +bool Inkscape::GuideSnapper::getSnapperAlwaysSnap() const +{ + return _snapmanager->snapprefs.getGuideTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp +} + Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Point const &/*p*/) const { LineList s; diff --git a/src/guide-snapper.h b/src/guide-snapper.h index f36d03499..dd5581654 100644 --- a/src/guide-snapper.h +++ b/src/guide-snapper.h @@ -31,6 +31,9 @@ public: GuideSnapper(SnapManager *sm, Geom::Coord const d); bool ThisSnapperMightSnap() const; + Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) + bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance + private: LineList _getSnapLines(Geom::Point const &p) const; void _addSnappedLine(SnappedConstraints &sc, Geom::Point const snapped_point, Geom::Coord const snapped_distance, Geom::Point const normal_to_line, Geom::Point const point_on_line) const; diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index f5021e208..7b4a989a8 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -63,6 +63,21 @@ Inkscape::ObjectSnapper::~ObjectSnapper() delete _paths_to_snap_to; } +/** + * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels + */ +Geom::Coord Inkscape::ObjectSnapper::getSnapperTolerance() const +{ + SPDesktop const *dt = _snapmanager->getDesktop(); + double const zoom = dt ? dt->current_zoom() : 1; + return _snapmanager->snapprefs.getObjectTolerance() / zoom; +} + +bool Inkscape::ObjectSnapper::getSnapperAlwaysSnap() const +{ + return _snapmanager->snapprefs.getObjectTolerance() == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp +} + /** * Find all items within snapping range. * \param parent Pointer to the document's root, or to a clipped path or mask object diff --git a/src/object-snapper.h b/src/object-snapper.h index 9c391a90f..74bdec0ce 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -46,38 +46,41 @@ class ObjectSnapper : public Snapper { public: - ObjectSnapper(SnapManager *sm, Geom::Coord const d); + ObjectSnapper(SnapManager *sm, Geom::Coord const d); ~ObjectSnapper(); - enum DimensionToSnap { - GUIDE_TRANSL_SNAP_X, // For snapping a vertical guide (normal in the X-direction) to objects, - GUIDE_TRANSL_SNAP_Y, // For snapping a horizontal guide (normal in the Y-direction) to objects - ANGLED_GUIDE_TRANSL_SNAP, // For snapping an angled guide, while translating it accross the desktop - ANGLED_GUIDE_ROT_SNAP, // For snapping an angled guide, while rotating it around some pivot point - TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides - - void guideSnap(SnappedConstraints &sc, - Geom::Point const &p, - Geom::Point const &guide_normal) const; - - bool ThisSnapperMightSnap() const; - bool GuidesMightSnap() const; - - void freeSnap(SnappedConstraints &sc, - Inkscape::SnapPreferences::PointType const &t, - Geom::Point const &p, - bool const &first_point, - Geom::OptRect const &bbox_to_snap, - std::vector const *it, - std::vector *unselected_nodes) const; - - void constrainedSnap(SnappedConstraints &sc, - Inkscape::SnapPreferences::PointType const &t, - Geom::Point const &p, - bool const &first_point, - Geom::OptRect const &bbox_to_snap, - ConstraintLine const &c, - std::vector const *it) const; + enum DimensionToSnap { + GUIDE_TRANSL_SNAP_X, // For snapping a vertical guide (normal in the X-direction) to objects, + GUIDE_TRANSL_SNAP_Y, // For snapping a horizontal guide (normal in the Y-direction) to objects + ANGLED_GUIDE_TRANSL_SNAP, // For snapping an angled guide, while translating it accross the desktop + ANGLED_GUIDE_ROT_SNAP, // For snapping an angled guide, while rotating it around some pivot point + TRANSL_SNAP_XY}; // All other cases; for snapping to objects, other than guides + + void guideSnap(SnappedConstraints &sc, + Geom::Point const &p, + Geom::Point const &guide_normal) const; + + bool ThisSnapperMightSnap() const; + bool GuidesMightSnap() const; + + Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) + bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance + + void freeSnap(SnappedConstraints &sc, + Inkscape::SnapPreferences::PointType const &t, + Geom::Point const &p, + bool const &first_point, + Geom::OptRect const &bbox_to_snap, + std::vector const *it, + std::vector *unselected_nodes) const; + + void constrainedSnap(SnappedConstraints &sc, + Inkscape::SnapPreferences::PointType const &t, + Geom::Point const &p, + bool const &first_point, + Geom::OptRect const &bbox_to_snap, + ConstraintLine const &c, + std::vector const *it) const; private: //store some lists of candidates, points and paths, so we don't have to rebuild them for each point we want to snap diff --git a/src/snap-preferences.h b/src/snap-preferences.h index 258b1f5ed..63d7fba15 100644 --- a/src/snap-preferences.h +++ b/src/snap-preferences.h @@ -13,6 +13,8 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ +#include "helper/units.h" + namespace Inkscape { @@ -82,6 +84,15 @@ public: bool getSnapToPageBorder() const {return _snap_to_page_border;} bool getStrictSnapping() const {return _strict_snapping;} + gdouble getGridTolerance() const {return _grid_tolerance;} + gdouble getGuideTolerance() const {return _guide_tolerance;} + gdouble getObjectTolerance() const {return _object_tolerance;} + + void setGridTolerance(gdouble val) {_grid_tolerance = val;} + void setGuideTolerance(gdouble val) {_guide_tolerance = val;} + void setObjectTolerance(gdouble val) {_object_tolerance = val;} + + private: bool _include_item_center; //If true, snapping nodes will also snap the item's center bool _intersectionGG; //Consider snapping to intersections of grid and guides @@ -108,6 +119,10 @@ private: //snap bbox corners to nodes, or nodes to bboxes. //(snapping to grids and guides is not affected by this) bool _strict_snapping; + + gdouble _grid_tolerance; + gdouble _guide_tolerance; + gdouble _object_tolerance; }; } diff --git a/src/snapper.cpp b/src/snapper.cpp index 492e4ca4d..4a0bfb791 100644 --- a/src/snapper.cpp +++ b/src/snapper.cpp @@ -21,36 +21,11 @@ */ Inkscape::Snapper::Snapper(SnapManager *sm, Geom::Coord const t) : _snapmanager(sm), - _snap_enabled(true), - _snapper_tolerance(std::max(t, 1.0)) + _snap_enabled(true) { g_assert(_snapmanager != NULL); } -/** - * Set snap tolerance. - * \param d New snap tolerance (desktop coordinates) - */ -void Inkscape::Snapper::setSnapperTolerance(Geom::Coord const d) -{ - _snapper_tolerance = std::max(d, 1.0); -} - -/** - * \return Snap tolerance (desktop coordinates); depends on current zoom so that it's always the same in screen pixels - */ -Geom::Coord Inkscape::Snapper::getSnapperTolerance() const -{ - SPDesktop const *dt = _snapmanager->getDesktop(); - double const zoom = dt ? dt->current_zoom() : 1; - return _snapper_tolerance / zoom; -} - -bool Inkscape::Snapper::getSnapperAlwaysSnap() const -{ - return _snapper_tolerance == 10000; //TODO: Replace this threshold of 10000 by a constant; see also tolerance-slider.cpp -} - /** * \param s true to enable this snapper, otherwise false. */ diff --git a/src/snapper.h b/src/snapper.h index 7bea9b423..fc4b30ba0 100644 --- a/src/snapper.h +++ b/src/snapper.h @@ -45,14 +45,12 @@ public: Snapper(SnapManager *sm, ::Geom::Coord const t); virtual ~Snapper() {} - void setSnapperTolerance(Geom::Coord t); - Geom::Coord getSnapperTolerance() const; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) - bool getSnapperAlwaysSnap() const; //if true, then the snapper will always snap, regardless of its tolerance + virtual Geom::Coord getSnapperTolerance() const {}; //returns the tolerance of the snapper in screen pixels (i.e. independent of zoom) + virtual bool getSnapperAlwaysSnap() const {}; //if true, then the snapper will always snap, regardless of its tolerance /** * \return true if this Snapper will snap at least one kind of point. */ - //virtual bool ThisSnapperMightSnap() const; virtual bool ThisSnapperMightSnap() const {return _snap_enabled;} // will likely be overridden by derived classes void setEnabled(bool s); // This is only used for grids, for which snapping can be enabled individually @@ -109,11 +107,6 @@ protected: bool _snap_enabled; ///< true if this snapper is enabled, otherwise false // This is only used for grids, for which snapping can be enabled individually - -private: - Geom::Coord _snapper_tolerance; ///< snap tolerance in desktop coordinates - // must be private to enforce the usage of getTolerance(), which retrieves - // the tolerance in screen pixels (making it zoom independent) }; } diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 4bde2b191..793dff561 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -328,27 +328,15 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_GRIDTOLERANCE: - nv->gridtoleranceunit = &px; - nv->gridtolerance = 10000; - if (value) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &nv->gridtolerance, &nv->gridtoleranceunit); - } - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; + nv->snap_manager.snapprefs.setGridTolerance(value ? g_ascii_strtod(value, NULL) : 10000); + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; case SP_ATTR_GUIDETOLERANCE: - nv->guidetoleranceunit = &px; - nv->guidetolerance = 20; - if (value) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &nv->guidetolerance, &nv->guidetoleranceunit); - } + nv->snap_manager.snapprefs.setGuideTolerance(value ? g_ascii_strtod(value, NULL) : 20); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_OBJECTTOLERANCE: - nv->objecttoleranceunit = &px; - nv->objecttolerance = 20; - if (value) { - sp_nv_read_length(value, SP_UNIT_ABSOLUTE | SP_UNIT_DEVICE, &nv->objecttolerance, &nv->objecttoleranceunit); - } + nv->snap_manager.snapprefs.setObjectTolerance(value ? g_ascii_strtod(value, NULL) : 20); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_GUIDECOLOR: diff --git a/src/sp-namedview.h b/src/sp-namedview.h index 5a9c2971f..7eafd1249 100644 --- a/src/sp-namedview.h +++ b/src/sp-namedview.h @@ -51,17 +51,8 @@ struct SPNamedView : public SPObjectGroup { SnapManager snap_manager; GSList * grids; bool grids_visible; - - SPUnit const *doc_units; - - SPUnit const *gridtoleranceunit; - gdouble gridtolerance; - SPUnit const *guidetoleranceunit; - gdouble guidetolerance; - - SPUnit const *objecttoleranceunit; - gdouble objecttolerance; + SPUnit const *doc_units; GQuark default_layer_id; diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index d472715c4..ae95244cd 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -794,9 +794,9 @@ DocumentProperties::update() //-----------------------------------------------------------snap page - _rsu_sno.setValue (nv->objecttolerance); - _rsu_sn.setValue (nv->gridtolerance); - _rsu_gusn.setValue (nv->guidetolerance); + _rsu_sno.setValue (nv->snap_manager.snapprefs.getObjectTolerance()); + _rsu_sn.setValue (nv->snap_manager.snapprefs.getGridTolerance()); + _rsu_gusn.setValue (nv->snap_manager.snapprefs.getGuideTolerance()); //-----------------------------------------------------------grids page