From cf96255ae53ef0a036392c6f22cb9cc277c66aea Mon Sep 17 00:00:00 2001 From: johanengelen Date: Mon, 16 Oct 2006 09:40:03 +0000 Subject: [PATCH] hack*ahum*infrastructure to implement axonometric grid snapping. horizontal snapping already implemented. --- src/desktop.cpp | 4 +++ src/grid-snapper.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++-- src/grid-snapper.h | 15 +++++++++- src/snap.cpp | 9 ++++-- src/snap.h | 11 +++++-- src/sp-namedview.cpp | 3 ++ 6 files changed, 102 insertions(+), 8 deletions(-) diff --git a/src/desktop.cpp b/src/desktop.cpp index 47dbe1bec..d7a081faf 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -10,6 +10,7 @@ * Ralf Stephan * John Bintz * + * Copyright (C) 2006 Johan Engelen * Copyright (C) 2006 John Bintz * Copyright (C) 2004 MenTaLguY * Copyright (C) 1999-2002 Lauris Kaplinski @@ -1363,6 +1364,9 @@ _update_snap_distances (SPDesktop *desktop) nv.snap_manager.grid.setDistance(sp_convert_distance_full(nv.gridtolerance, *nv.gridtoleranceunit, px)); + nv.snap_manager.axonomgrid.setDistance(sp_convert_distance_full(nv.gridtolerance, + *nv.gridtoleranceunit, + px)); nv.snap_manager.guide.setDistance(sp_convert_distance_full(nv.guidetolerance, *nv.guidetoleranceunit, px)); diff --git a/src/grid-snapper.cpp b/src/grid-snapper.cpp index 5c94b9a97..03f6c9d3a 100644 --- a/src/grid-snapper.cpp +++ b/src/grid-snapper.cpp @@ -7,6 +7,7 @@ * Frank Felfe * Carl Hetherington * + * Copyright (C) 2006 Johan Engelen * Copyright (C) 1999-2002 Authors * * Released under GNU GPL, read the file 'COPYING' for more information @@ -16,6 +17,7 @@ #include "inkscape.h" #include "desktop.h" #include "display/canvas-grid.h" +#include "display/canvas-axonomgrid.h" /** * \return x rounded to the nearest multiple of c1 plus c0. @@ -37,7 +39,8 @@ Inkscape::GridSnapper::GridSnapper(SPNamedView const *nv, NR::Coord const d) : L } -Inkscape::LineSnapper::LineList Inkscape::GridSnapper::_getSnapLines(NR::Point const &p) const +Inkscape::LineSnapper::LineList +Inkscape::GridSnapper::_getSnapLines(NR::Point const &p) const { LineList s; @@ -52,7 +55,9 @@ Inkscape::LineSnapper::LineList Inkscape::GridSnapper::_getSnapLines(NR::Point c // must be rethought and maybe only the current view // should give back it's SHOWN lines to snap to // For now, the last SPCGrid in _named_view->gridviews will be used. - griditem = SP_CGRID(l->data); + if ( SP_IS_CGRID(GTK_OBJECT(l->data)) ) { + griditem = SP_CGRID(l->data); + } } g_assert(griditem != NULL); @@ -78,6 +83,65 @@ Inkscape::LineSnapper::LineList Inkscape::GridSnapper::_getSnapLines(NR::Point c return s; } + + +Inkscape::AxonomGridSnapper::AxonomGridSnapper(SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d) +{ + +} + + +Inkscape::LineSnapper::LineList +Inkscape::AxonomGridSnapper::_getSnapLines(NR::Point const &p) const +{ + LineList s; + + if ( NULL == _named_view ) { + return s; + } + + SPCAxonomGrid *griditem = NULL; + for (GSList *l = _named_view->gridviews; l != NULL; l = l->next) { + // FIXME : this is a hack since there is only one view for now + // but when we'll handle multiple views, snapping should + // must be rethought and maybe only the current view + // should give back it's SHOWN lines to snap to + // For now, the last SPCAxonomGrid in _named_view->gridviews will be used. + if ( SP_IS_CAXONOMGRID(GTK_OBJECT(l->data)) ) { + griditem = SP_CAXONOMGRID(l->data); + } + } + + g_assert(griditem != NULL); + + // add vertical line. + + + // This is to make sure we snap to only visible grid lines + double scaled_spacing = griditem->spacing_ylines; // this is spacing of visible lines if screen pixels + // convert screen pixels to px + // FIXME: after we switch to snapping dist in screen pixels, this will be unnecessary + if (SP_ACTIVE_DESKTOP) { + scaled_spacing /= SP_ACTIVE_DESKTOP->current_zoom(); + } + + NR::Coord const rounded = round_to_nearest_multiple_plus(p[0], scaled_spacing, griditem->origin[0]); + + int a = round(scaled_spacing); + int b = round(p[0]); + int c = round(rounded); + + g_message("hier %d; %d; %d",a,b,c); + + + s.push_back(std::make_pair(NR::Dim2(0), rounded)); + + + return s; +} + + + /* Local Variables: mode:c++ diff --git a/src/grid-snapper.h b/src/grid-snapper.h index 247823ac7..c664c5f9b 100644 --- a/src/grid-snapper.h +++ b/src/grid-snapper.h @@ -10,6 +10,7 @@ * Frank Felfe * Carl Hetherington * + * Copyright (C) 2006 Johan Engelen * Copyright (C) 1999-2002 Authors * * Released under GNU GPL, read the file 'COPYING' for more information @@ -28,7 +29,19 @@ public: private: LineList _getSnapLines(NR::Point const &p) const; -}; +}; + + +class AxonomGridSnapper : public LineSnapper +{ +public: + AxonomGridSnapper(SPNamedView const *nv, NR::Coord const d); + +private: + LineList _getSnapLines(NR::Point const &p) const; +}; + + } diff --git a/src/snap.cpp b/src/snap.cpp index 9e41603de..de74d6cc6 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -9,6 +9,7 @@ * Frank Felfe * Carl Hetherington * + * Copyright (C) 2006 Johan Engelen * Copyright (C) 1999-2002 Authors * * Released under GNU GPL, read the file 'COPYING' for more information @@ -26,7 +27,7 @@ * \param v `Owning' SPNamedView. */ -SnapManager::SnapManager(SPNamedView const *v) : grid(v, 0), guide(v, 0), object(v, 0) +SnapManager::SnapManager(SPNamedView const *v) : _named_view(v), grid(v, 0), axonomgrid(v, 0), guide(v, 0), object(v, 0) { } @@ -39,7 +40,11 @@ SnapManager::SnapManager(SPNamedView const *v) : grid(v, 0), guide(v, 0), object SnapManager::SnapperList SnapManager::getSnappers() const { SnapManager::SnapperList s; - s.push_back(&grid); + if (_named_view->gridtype == 0) { + s.push_back(&grid); + } else { + s.push_back(&axonomgrid); + } s.push_back(&guide); s.push_back(&object); return s; diff --git a/src/snap.h b/src/snap.h index ea833b0ec..ff3da3adb 100644 --- a/src/snap.h +++ b/src/snap.h @@ -10,6 +10,7 @@ * Frank Felfe * Carl Hetherington * + * Copyright (C) 2006 Johan Engelen * Copyright (C) 2000-2002 Lauris Kaplinski * * Released under GNU GPL, read the file 'COPYING' for more information @@ -99,13 +100,17 @@ public: NR::Point const &o, NR::Dim2 d) const; - Inkscape::GridSnapper grid; ///< grid snapper - Inkscape::GuideSnapper guide; ///< guide snapper - Inkscape::ObjectSnapper object; ///< snapper to other objects + Inkscape::GridSnapper grid; ///< grid snapper + Inkscape::AxonomGridSnapper axonomgrid; ///< axonometricgrid snapper + Inkscape::GuideSnapper guide; ///< guide snapper + Inkscape::ObjectSnapper object; ///< snapper to other objects typedef std::list SnapperList; SnapperList getSnappers() const; +protected: + SPNamedView const *_named_view; + private: enum Transformation { diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 27b19fee6..da95a8ab7 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -230,6 +230,7 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va sp_namedview_setup_grid(nv); /* Disable grid snaps if the grid is turned off */ nv->snap_manager.grid.setEnabled(nv->showgrid); + nv->snap_manager.axonomgrid.setEnabled(nv->showgrid); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_GRIDTYPE: @@ -459,10 +460,12 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va break; case SP_ATTR_INKSCAPE_GRID_BBOX: nv->snap_manager.grid.setSnapTo(Inkscape::Snapper::BBOX_POINT, value ? sp_str_to_bool(value) : TRUE); + nv->snap_manager.axonomgrid.setSnapTo(Inkscape::Snapper::BBOX_POINT, value ? sp_str_to_bool(value) : TRUE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_INKSCAPE_GRID_POINTS: nv->snap_manager.grid.setSnapTo(Inkscape::Snapper::SNAP_POINT, value ? sp_str_to_bool(value) : FALSE); + nv->snap_manager.axonomgrid.setSnapTo(Inkscape::Snapper::SNAP_POINT, value ? sp_str_to_bool(value) : FALSE); object->requestModified(SP_OBJECT_MODIFIED_FLAG); break; case SP_ATTR_INKSCAPE_GUIDE_BBOX: -- 2.30.2