Code

If a snapper needs a reference to a SPNamedView or a SPDesktop, then get that referen...
authordvlierop2 <dvlierop2@users.sourceforge.net>
Sun, 7 Sep 2008 15:12:57 +0000 (15:12 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Sun, 7 Sep 2008 15:12:57 +0000 (15:12 +0000)
14 files changed:
src/display/canvas-axonomgrid.cpp
src/display/canvas-axonomgrid.h
src/display/canvas-grid.cpp
src/display/canvas-grid.h
src/guide-snapper.cpp
src/guide-snapper.h
src/line-snapper.cpp
src/line-snapper.h
src/object-snapper.cpp
src/object-snapper.h
src/snap.cpp
src/snap.h
src/snapper.cpp
src/snapper.h

index 0c2c627c9d620d6fa769c04383fac5ec172b8201..0294f74206d744b44512d057810360b27429203a 100644 (file)
@@ -211,7 +211,7 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r
     angle_rad[Z] = deg_to_rad(angle_deg[Z]);
     tan_angle[Z] = tan(angle_rad[Z]);
 
-    snapper = new CanvasAxonomGridSnapper(this, namedview, 0);
+    snapper = new CanvasAxonomGridSnapper(this, &namedview->snap_manager, 0);
 
     if (repr) readRepr();
 }
@@ -654,7 +654,7 @@ CanvasAxonomGrid::Render (SPCanvasBuf *buf)
     }
 }
 
-CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, Geom::Coord const d) : LineSnapper(nv, d)
+CanvasAxonomGridSnapper::CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager const *sm, Geom::Coord const d) : LineSnapper(sm, d)
 {
     this->grid = grid;
 }
index f5f9019d2ef784a894149693e55a24d7495f0d36..f8dc8e25a983ae81454185c14f414378d865e643 100644 (file)
@@ -71,7 +71,7 @@ private:
 class CanvasAxonomGridSnapper : public LineSnapper
 {
 public:
-    CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SPNamedView const *nv, Geom::Coord const d);
+    CanvasAxonomGridSnapper(CanvasAxonomGrid *grid, SnapManager const *sm, Geom::Coord const d);
 
 private:    
     LineList _getSnapLines(Geom::Point const &p) const;
index 47cff6d444cf161c594d54524d107f8148258fec..6d6b5d89f17790f82a24a251f1d911412b77ee81 100644 (file)
@@ -427,7 +427,7 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPD
     spacing[NR::Y] = sp_units_get_pixels( prefs_get_double_attribute ("options.grids.xy", "spacing_y", 0.0), *(gridunit) );
     render_dotted = prefs_get_int_attribute ("options.grids.xy", "dotted", 0) == 1;
 
-    snapper = new CanvasXYGridSnapper(this, namedview, 0);
+    snapper = new CanvasXYGridSnapper(this, &namedview->snap_manager, 0);
 
     if (repr) readRepr();
 }
@@ -947,7 +947,7 @@ CanvasXYGrid::Render (SPCanvasBuf *buf)
     }
 }
 
-CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d) : LineSnapper(nv, d)
+CanvasXYGridSnapper::CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager const *sm, NR::Coord const d) : LineSnapper(sm, d)
 {
     this->grid = grid;
 }
@@ -998,7 +998,7 @@ void CanvasXYGridSnapper::_addSnappedLine(SnappedConstraints &sc, Geom::Point co
  */
 bool CanvasXYGridSnapper::ThisSnapperMightSnap() const
 {
-    return _named_view == NULL ? false : (_snap_enabled && _snap_from != 0);
+    return _snap_enabled && _snap_from != 0;
 }
 
 
index a734cac8469c34a619cbb5d61812199b430d367a..20cb314730a366125c37be7567764c451a007359 100644 (file)
@@ -161,7 +161,7 @@ private:
 class CanvasXYGridSnapper : public LineSnapper
 {
 public:
-    CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, Geom::Coord const d);
+    CanvasXYGridSnapper(CanvasXYGrid *grid, SnapManager const *sm, Geom::Coord const d);
     bool ThisSnapperMightSnap() const;
 
 private:
index 059d99a198caaac3eccf2b6c842aaa04f8a7938b..d1991e75d30decdc505ed1e3170fdc900c224131 100644 (file)
@@ -17,7 +17,7 @@
 #include "sp-namedview.h"
 #include "sp-guide.h"
 
-Inkscape::GuideSnapper::GuideSnapper(SPNamedView const *nv, Geom::Coord const d) : LineSnapper(nv, d)
+Inkscape::GuideSnapper::GuideSnapper(SnapManager const *sm, Geom::Coord const d) : LineSnapper(sm, d)
 {
 
 }
@@ -26,11 +26,11 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Poi
 {
     LineList s;
 
-    if ( NULL == _named_view || ThisSnapperMightSnap() == false) {
+    if ( NULL == _snapmanager->getNamedView() || ThisSnapperMightSnap() == false) {
         return s;
     }
 
-    for (GSList const *l = _named_view->guides; l != NULL; l = l->next) {
+    for (GSList const *l = _snapmanager->getNamedView()->guides; l != NULL; l = l->next) {
         SPGuide const *g = SP_GUIDE(l->data);
         s.push_back(std::make_pair(g->normal_to_line, g->point_on_line)); 
     }
@@ -43,7 +43,7 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(Geom::Poi
  */
 bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const
 {
-    return _named_view == NULL ? false : (_snap_enabled && _snap_from != 0 && _named_view->showguides);
+    return _snapmanager->getNamedView() == NULL ? false : (_snap_enabled && _snap_from != 0 && _snapmanager->getNamedView()->showguides);
 }
 
 void Inkscape::GuideSnapper::_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
index df6086ccfd7d16980bd4912190d4c1d189fae366..a7798c72ff3877c143c1406e47af93a6032adec5 100644 (file)
@@ -28,7 +28,7 @@ namespace Inkscape
 class GuideSnapper : public LineSnapper
 {
 public:
-    GuideSnapper(SPNamedView const *nv, Geom::Coord const d);    
+    GuideSnapper(SnapManager const *sm, Geom::Coord const d);    
     bool ThisSnapperMightSnap() const;
 
 private:
index db7a20e4f0116b9e0099e253e4e760a2a0f82984..5453c1cf27bc5d71140909251f71491785f9be70 100644 (file)
@@ -18,7 +18,7 @@
 #include "snapped-line.h"
 #include <gtk/gtk.h>
 
-Inkscape::LineSnapper::LineSnapper(SPNamedView const *nv, Geom::Coord const d) : Snapper(nv, d)
+Inkscape::LineSnapper::LineSnapper(SnapManager const *sm, Geom::Coord const d) : Snapper(sm, d)
 {
 
 }
index 6af2e87d4ce238039d9737ceb71bc6a82100d6fa..7767fe2ea5a0f25a4fbc87313ca3399b086e9c4c 100644 (file)
@@ -19,7 +19,7 @@ namespace Inkscape
 class LineSnapper : public Snapper
 {
 public:
-  LineSnapper(SPNamedView const *nv, Geom::Coord const d);
+  LineSnapper(SnapManager const *sm, Geom::Coord const d);
 
   void freeSnap(SnappedConstraints &sc,
                    Inkscape::Snapper::PointType const &t,
index c620e91cdf7e2a5c676fdde524a723de22fdf85c..884b561b19ebca598a0185817d67ed198de2ec3f 100644 (file)
@@ -44,8 +44,8 @@ Inkscape::SnapCandidate::~SnapCandidate()
 {    
 }
 
-Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, Geom::Coord const d)
-    : Snapper(nv, d), _snap_to_itemnode(true), _snap_to_itempath(true),
+Inkscape::ObjectSnapper::ObjectSnapper(SnapManager const *sm, Geom::Coord const d)
+    : Snapper(sm, d), _snap_to_itemnode(true), _snap_to_itempath(true),
       _snap_to_bboxnode(true), _snap_to_bboxpath(true), _snap_to_page_border(false),
       _strict_snapping(true), _include_item_center(false)
 {
@@ -98,8 +98,8 @@ void Inkscape::ObjectSnapper::_findCandidates(SPObject* parent,
     bbox_to_snap_incl.expandBy(getSnapperTolerance()); // see?
     
     for (SPObject* o = sp_object_first_child(parent); o != NULL; o = SP_OBJECT_NEXT(o)) {
-        g_assert(_named_view->snap_manager.getDesktop() != NULL);
-       if (SP_IS_ITEM(o) && !SP_ITEM(o)->isLocked() && !(_named_view->snap_manager.getDesktop()->itemIsHidden(SP_ITEM(o)) && !clip_or_mask)) {
+        g_assert(_snapmanager->getDesktop() != NULL);
+       if (SP_IS_ITEM(o) && !SP_ITEM(o)->isLocked() && !(_snapmanager->getDesktop()->itemIsHidden(SP_ITEM(o)) && !clip_or_mask)) {
             // Don't snap to locked items, and
             // don't snap to hidden objects, unless they're a clipped path or a mask
             /* See if this item is on the ignore list */
@@ -413,8 +413,8 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
     _collectPaths(t, first_point);
     // Now we can finally do the real snapping, using the paths collected above
     
-    g_assert(_named_view->snap_manager.getDesktop() != NULL);    
-    Geom::Point const p_doc = _named_view->snap_manager.getDesktop()->dt2doc(p);
+    g_assert(_snapmanager->getDesktop() != NULL);    
+    Geom::Point const p_doc = _snapmanager->getDesktop()->dt2doc(p);
     
     bool const node_tool_active = _snap_to_itempath && selected_path != NULL;
     
@@ -463,13 +463,13 @@ void Inkscape::ObjectSnapper::_snapPaths(SnappedConstraints &sc,
                      * piece are unselected; if they are then this piece must be stationary 
                      */                    
                     g_assert(unselected_nodes != NULL);
-                    Geom::Point start_pt = _named_view->snap_manager.getDesktop()->doc2dt(curve->pointAt(0)); 
-                    Geom::Point end_pt = _named_view->snap_manager.getDesktop()->doc2dt(curve->pointAt(1));                                    
+                    Geom::Point start_pt = _snapmanager->getDesktop()->doc2dt(curve->pointAt(0)); 
+                    Geom::Point end_pt = _snapmanager->getDesktop()->doc2dt(curve->pointAt(1));                                    
                     c1 = isUnselectedNode(start_pt, unselected_nodes);
                     c2 = isUnselectedNode(end_pt, unselected_nodes);
                 }
                 
-                Geom::Point const sp_dt = _named_view->snap_manager.getDesktop()->doc2dt(sp_doc);                
+                Geom::Point const sp_dt = _snapmanager->getDesktop()->doc2dt(sp_doc);                
                 if (!being_edited || (c1 && c2)) {
                     Geom::Coord const dist = Geom::distance(sp_doc, p_doc);
                     if (dist < getSnapperTolerance()) {
@@ -512,8 +512,8 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc,
     
     // Now we can finally do the real snapping, using the paths collected above
     
-    g_assert(_named_view->snap_manager.getDesktop() != NULL);
-    Geom::Point const p_doc = _named_view->snap_manager.getDesktop()->dt2doc(p);    
+    g_assert(_snapmanager->getDesktop() != NULL);
+    Geom::Point const p_doc = _snapmanager->getDesktop()->dt2doc(p);    
     
     Geom::Point direction_vector = c.getDirection();
     if (!is_zero(direction_vector)) {
@@ -527,8 +527,8 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc,
     // must lie within two points on the constraintline: p_min_on_cl and p_max_on_cl
     // The distance between those points is twice the snapping tolerance
     Geom::Point const p_proj_on_cl = project_on_linesegment(p, p1_on_cl, p2_on_cl);
-    Geom::Point const p_min_on_cl = _named_view->snap_manager.getDesktop()->dt2doc(p_proj_on_cl - getSnapperTolerance() * direction_vector);    
-    Geom::Point const p_max_on_cl = _named_view->snap_manager.getDesktop()->dt2doc(p_proj_on_cl + getSnapperTolerance() * direction_vector);
+    Geom::Point const p_min_on_cl = _snapmanager->getDesktop()->dt2doc(p_proj_on_cl - getSnapperTolerance() * direction_vector);    
+    Geom::Point const p_max_on_cl = _snapmanager->getDesktop()->dt2doc(p_proj_on_cl + getSnapperTolerance() * direction_vector);
     
     Geom::Path cl;
     std::vector<Geom::Path> clv;    
@@ -548,8 +548,8 @@ void Inkscape::ObjectSnapper::_snapPathsConstrained(SnappedConstraints &sc,
                         Geom::Point p_inters = p_min_on_cl + ((*m).ta) * (p_max_on_cl - p_min_on_cl);
                         // When it's within snapping range, then return it
                         // (within snapping range == between p_min_on_cl and p_max_on_cl == 0 < ta < 1)                        
-                        Geom::Coord dist = Geom::L2(_named_view->snap_manager.getDesktop()->dt2doc(p_proj_on_cl) - p_inters);
-                        SnappedPoint s(_named_view->snap_manager.getDesktop()->doc2dt(p_inters), SNAPTARGET_PATH, dist, getSnapperTolerance(), getSnapperAlwaysSnap());
+                        Geom::Coord dist = Geom::L2(_snapmanager->getDesktop()->dt2doc(p_proj_on_cl) - p_inters);
+                        SnappedPoint s(_snapmanager->getDesktop()->doc2dt(p_inters), SNAPTARGET_PATH, dist, getSnapperTolerance(), getSnapperAlwaysSnap());
                         sc.points.push_back(s);
                     }  
                 } 
@@ -567,14 +567,14 @@ void Inkscape::ObjectSnapper::freeSnap(SnappedConstraints &sc,
                                             std::vector<SPItem const *> const *it,
                                             std::vector<Geom::Point> *unselected_nodes) const
 {
-    if (_snap_enabled == false || getSnapFrom(t) == false || _named_view == NULL) {
+    if (_snap_enabled == false || getSnapFrom(t) == false ) {
         return;
     }
 
     /* Get a list of all the SPItems that we will try to snap to */
     if (first_point) {
         Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(p, p);
-        _findCandidates(sp_document_root(_named_view->document), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, Geom::identity());
+        _findCandidates(sp_document_root(_snapmanager->getDocument()), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, Geom::identity());
     }
     
     if (_snap_to_itemnode || _snap_to_bboxnode || _snap_to_page_border) {
@@ -610,14 +610,14 @@ void Inkscape::ObjectSnapper::constrainedSnap( SnappedConstraints &sc,
                                                   ConstraintLine const &c,
                                                   std::vector<SPItem const *> const *it) const
 {
-    if (_snap_enabled == false || getSnapFrom(t) == false || _named_view == NULL) {
+    if (_snap_enabled == false || getSnapFrom(t) == false) {
         return;
     }
 
     /* Get a list of all the SPItems that we will try to snap to */
     if (first_point) {
         Geom::Rect const local_bbox_to_snap = bbox_to_snap ? *bbox_to_snap : Geom::Rect(p, p);
-        _findCandidates(sp_document_root(_named_view->document), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, Geom::identity());
+        _findCandidates(sp_document_root(_snapmanager->getDocument()), it, first_point, local_bbox_to_snap, TRANSL_SNAP_XY, false, Geom::identity());
     }
     
     // A constrained snap, is a snap in only one degree of freedom (specified by the constraint line).
@@ -640,10 +640,6 @@ void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc,
                                         Geom::Point const &p,
                                         Geom::Point const &guide_normal) const
 {
-    if ( NULL == _named_view ) {
-        return;
-    }
-    
     /* Get a list of all the SPItems that we will try to snap to */
     std::vector<SPItem*> cand;
     std::vector<SPItem const *> const it; //just an empty list
@@ -667,7 +663,7 @@ void Inkscape::ObjectSnapper::guideSnap(SnappedConstraints &sc,
     // second time on an object; but should this point then be constrained to the
     // line, or can it be located anywhere?)
     
-    _findCandidates(sp_document_root(_named_view->document), &it, true, Geom::Rect(p, p), snap_dim, false, Geom::identity());
+    _findCandidates(sp_document_root(_snapmanager->getDocument()), &it, true, Geom::Rect(p, p), snap_dim, false, Geom::identity());
     _snapTranslatingGuideToNodes(sc, Inkscape::Snapper::SNAPPOINT_GUIDE, p, guide_normal);
     // _snapRotatingGuideToNodes has not been implemented yet. 
 }
@@ -697,7 +693,7 @@ void Inkscape::ObjectSnapper::_clear_paths() const
 
 Geom::PathVector* Inkscape::ObjectSnapper::_getBorderPathv() const
 {
-    Geom::Rect const border_rect = Geom::Rect(Geom::Point(0,0), Geom::Point(sp_document_width(_named_view->document),sp_document_height(_named_view->document)));
+    Geom::Rect const border_rect = Geom::Rect(Geom::Point(0,0), Geom::Point(sp_document_width(_snapmanager->getDocument()),sp_document_height(_snapmanager->getDocument())));
     return _getPathvFromRect(border_rect);        
 }
 
@@ -714,8 +710,8 @@ Geom::PathVector* Inkscape::ObjectSnapper::_getPathvFromRect(Geom::Rect const re
 
 void Inkscape::ObjectSnapper::_getBorderNodes(std::vector<Geom::Point> *points) const
 {
-    Geom::Coord w = sp_document_width(_named_view->document);
-    Geom::Coord h = sp_document_height(_named_view->document);
+    Geom::Coord w = sp_document_width(_snapmanager->getDocument());
+    Geom::Coord h = sp_document_height(_snapmanager->getDocument());
     points->push_back(Geom::Point(0,0));
     points->push_back(Geom::Point(0,h));
     points->push_back(Geom::Point(w,h));
index 02b4b422b771cb70fd4708dcbe78300bbfb191f3..c567e115be070bc43821c3222c37be5ddef1faa1 100644 (file)
@@ -46,7 +46,7 @@ class ObjectSnapper : public Snapper
 {
 
 public:
-    ObjectSnapper(SPNamedView const *nv, Geom::Coord const d);
+    ObjectSnapper(SnapManager const *sm, Geom::Coord const d);
     ~ObjectSnapper();
 
       enum DimensionToSnap {
index 15bc8658d4c56aa9dd0dfbc316a925004616d23a..c4ed536e54d86ee7d11da1784326bec0e3e00f2b 100644 (file)
@@ -44,8 +44,8 @@ using std::vector;
  */
 
 SnapManager::SnapManager(SPNamedView const *v) :
-    guide(v, 0),
-    object(v, 0),
+    guide(this, 0),
+    object(this, 0),
     _named_view(v),
     _include_item_center(false),
     _snap_enabled_globally(true)
@@ -903,6 +903,11 @@ void SnapManager::setup(SPDesktop const *desktop, bool snapindicator, std::vecto
     _unselected_nodes = unselected_nodes;   
 }
 
+SPDocument *SnapManager::getDocument() const
+{
+       return _named_view->document;
+}
+
 /*
   Local Variables:
   mode:c++
index 480ca98691fdf9dc2045276d7865bc98f5f0b283..df08602746c3609ed214ac3cadd403ab8f8cdc8a 100644 (file)
@@ -120,6 +120,8 @@ public:
     SnapperList getGridSnappers() const;
     
     SPDesktop const *getDesktop() const {return _desktop;}
+    SPNamedView const *getNamedView() const {return _named_view;}
+    SPDocument *getDocument() const;
     
     void setSnapModeBBox(bool enabled);
     void setSnapModeNode(bool enabled);
index 35aa012dc5887c94000eb57b73390520a4006e66..51ffaa42de7869b58af83d00222d217679865881 100644 (file)
@@ -23,11 +23,10 @@ Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_GUIDE = 0x4;
  *  \param nv Named view.
  *  \param d Snap tolerance.
  */
-Inkscape::Snapper::Snapper(SPNamedView const *nv, Geom::Coord const t) : _named_view(nv), _snap_enabled(true), _snapper_tolerance(t)
+Inkscape::Snapper::Snapper(SnapManager const *sm, Geom::Coord const t) : _snapmanager(sm), _snap_enabled(true), _snapper_tolerance(t)
 {
-    g_assert(_named_view != NULL);
-    g_assert(SP_IS_NAMEDVIEW(_named_view));
-
+    g_assert(_snapmanager != NULL);
+    
     setSnapFrom(SNAPPOINT_BBOX | SNAPPOINT_NODE, true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
 }
 
index 18967ebd9e6743753f1cadd57b895aa7917cb008..97068bf101b09b1b601f1da5f341a2dfacc3ebee 100644 (file)
@@ -30,7 +30,7 @@ struct SnappedConstraints {
     std::list<Inkscape::SnappedCurve> curves;
 };
 
-struct SPNamedView;
+class SnapManager;
 struct SPItem;
 
 namespace Inkscape
@@ -41,7 +41,7 @@ class Snapper
 {
 public:
     Snapper() {}
-    Snapper(SPNamedView const *nv, ::Geom::Coord const d);
+    Snapper(SnapManager const *sm, ::Geom::Coord const d);
     virtual ~Snapper() {}
 
     /// Point types to snap.
@@ -112,12 +112,12 @@ public:
                                  std::vector<SPItem const *> const */*it*/) const {};
 
 protected:
-    SPNamedView const *_named_view;
-    int _snap_from; ///< bitmap of point types that we will snap from
+       SnapManager const *_snapmanager;                
+       int _snap_from; ///< bitmap of point types that we will snap from
     bool _snap_enabled; ///< true if this snapper is enabled, otherwise false
 
 private:
-    Geom::Coord _snapper_tolerance;   ///< snap tolerance in desktop coordinates
+       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)