summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1e3c77b)
raw | patch | inline | side by side (parent: 1e3c77b)
author | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Sat, 31 Jan 2009 13:51:52 +0000 (13:51 +0000) | ||
committer | dvlierop2 <dvlierop2@users.sourceforge.net> | |
Sat, 31 Jan 2009 13:51:52 +0000 (13:51 +0000) |
15 files changed:
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 85df3af0450a87286a98f4a99388343fc7507db3..1f2baccbba2ed61559eb7d0ef70362dd9832accf 100644 (file)
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
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.
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);
}
}
-/**
- * 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;
index 283f58a014e576b58d01e7f55fad2dfa2b28d5fb..076dcdd332613e346f8f2c002ce7b090c33f8f6f 100644 (file)
@@ -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
{
index 9067e2e131720742b971229a3dc147abea2a916d..4849f08ad50d025cda018d1840a42134d0f6aec7 100644 (file)
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;
index 0d5cabd8d0e028a9bdbbe78ed04af9ef8f8fd883..49a1211eb9eb45f266489a4847483b48f5b8a72a 100644 (file)
@@ -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
{
index e4bd0141461cf6e4158d89e405c50f35a5631beb..85e890feff84d5bc93d760967c011b2b13bc668a 100644 (file)
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 54a4086a447c311b738530c10c2596a8747f380e..f344d891ff800d0f33fee390c20bf0e3d7f5bb1c 100644 (file)
--- a/src/guide-snapper.cpp
+++ b/src/guide-snapper.cpp
#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)
}
+/**
+ * \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 f36d03499605ed7b0c3ce75ca2e3e085dd3e9a3b..dd55816541a3c773da49ff0b5a8f2eb6a59323a0 100644 (file)
--- a/src/guide-snapper.h
+++ b/src/guide-snapper.h
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 f5021e2088afdc1f6945dc6745909eca9e586f48..7b4a989a8d52c25341ff560d4588aa4178a85267 100644 (file)
--- a/src/object-snapper.cpp
+++ b/src/object-snapper.cpp
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 9c391a90f7623c0c436fd65462f3c5d6ba8f6ec5..74bdec0cef3bad0a2ac04385943b7ea0ce7c6c57 100644 (file)
--- a/src/object-snapper.h
+++ b/src/object-snapper.h
{
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<SPItem const *> const *it,
- std::vector<Geom::Point> *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<SPItem const *> 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<SPItem const *> const *it,
+ std::vector<Geom::Point> *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<SPItem const *> 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 258b1f5edecfb285a89650a16a674c2cf00bae3a..63d7fba15215bffbbf26ac60d7e2f4ff91ff08b4 100644 (file)
--- a/src/snap-preferences.h
+++ b/src/snap-preferences.h
* Released under GNU GPL, read the file 'COPYING' for more information
*/
+#include "helper/units.h"
+
namespace Inkscape
{
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
//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 492e4ca4d019b4da14ac7a72094b470f78fa4504..4a0bfb79127b831965278eb9b8fa260200e6a204 100644 (file)
--- a/src/snapper.cpp
+++ b/src/snapper.cpp
*/
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 7bea9b423ecec6b661984a0a3fee6950ecf6e98b..fc4b30ba0f263f39f6c5846fd811e168b52dafb9 100644 (file)
--- a/src/snapper.h
+++ b/src/snapper.h
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
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 4bde2b191462bdb97dfa6a4bd48488d4a39305ce..793dff561580d3e01480c455bfa32ca0ffa2872a 100644 (file)
--- 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 5a9c2971f392f56073b113ff961ff5442a886737..7eafd124934c5a8113a4e498745fc01deba62951 100644 (file)
--- a/src/sp-namedview.h
+++ b/src/sp-namedview.h
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;
index d472715c4fcba78c4df89d4aa0c10db120ae4141..ae95244cda8504b4a43dc359f7879101210c9511 100644 (file)
//-----------------------------------------------------------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