Code

1) Changes to snapping preferences dialog
authordvlierop2 <dvlierop2@users.sourceforge.net>
Sat, 28 Jul 2007 15:47:49 +0000 (15:47 +0000)
committerdvlierop2 <dvlierop2@users.sourceforge.net>
Sat, 28 Jul 2007 15:47:49 +0000 (15:47 +0000)
2) Strict snapping implemented, i.e. bbox only to bbox and nodes only to paths/nodes
3) Renaming of some constants to improve readability

29 files changed:
src/arc-context.cpp
src/attributes.cpp
src/attributes.h
src/box3d-context.cpp
src/connector-context.cpp
src/context-fns.cpp
src/draw-context.cpp
src/gradient-context.cpp
src/gradient-drag.cpp
src/guide-snapper.cpp
src/line-snapper.cpp
src/line-snapper.h
src/nodepath.cpp
src/object-edit.cpp
src/object-snapper.cpp
src/object-snapper.h
src/pencil-context.cpp
src/rect-context.cpp
src/selection-chemistry.cpp
src/seltrans.cpp
src/snap.cpp
src/snap.h
src/snapper.cpp
src/snapper.h
src/sp-namedview.cpp
src/spiral-context.cpp
src/star-context.cpp
src/ui/dialog/document-properties.cpp
src/ui/dialog/document-properties.h

index 4a8d6b9d1c55604b4844d7459c5b456d2a07faaf..716c547ddb5b7d1e6d2f0427d145bbbb697a4274 100644 (file)
@@ -264,7 +264,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
                 ac->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
 
                 SnapManager const &m = desktop->namedview->snap_manager;                
-                ac->center = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, ac->center, ac->item).getPoint();
+                ac->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, ac->center, ac->item).getPoint();
                 
                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                     GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -290,7 +290,7 @@ static gint sp_arc_context_root_handler(SPEventContext *event_context, GdkEvent
                 NR::Point motion_dt(desktop->w2d(motion_w));
                 
                 SnapManager const &m = desktop->namedview->snap_manager;            
-                motion_dt = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, motion_dt, ac->item).getPoint();
+                motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, ac->item).getPoint();
             
                 
                 sp_arc_drag(ac, motion_dt, event->motion.state);
index 025f1991bf78bef9bf6a6a9b9d41c4d56474fca3..245529e61e05f17f54c44b5336bb53d2e2e2cbec 100644 (file)
@@ -82,14 +82,8 @@ static SPStyleProp const props[] = {
     {SP_ATTR_INKSCAPE_WINDOW_HEIGHT, "inkscape:window-height"},
     {SP_ATTR_INKSCAPE_WINDOW_X, "inkscape:window-x"},
     {SP_ATTR_INKSCAPE_WINDOW_Y, "inkscape:window-y"},
-/*  {SP_ATTR_INKSCAPE_GRID_BBOX, "inkscape:grid-bbox"},
-    {SP_ATTR_INKSCAPE_GUIDE_BBOX, "inkscape:guide-bbox"},
-    {SP_ATTR_INKSCAPE_OBJECT_BBOX, "inkscape:object-bbox"},
-    {SP_ATTR_INKSCAPE_GRID_POINTS, "inkscape:grid-points"},
-    {SP_ATTR_INKSCAPE_GUIDE_POINTS, "inkscape:guide-points"},
-    {SP_ATTR_INKSCAPE_OBJECT_POINTS, "inkscape:object-points"},*/
-    {SP_ATTR_INKSCAPE_OBJECT_PATHS, "inkscape:object-paths"},
-    {SP_ATTR_INKSCAPE_OBJECT_NODES, "inkscape:object-nodes"},
+    {SP_ATTR_INKSCAPE_SNAP_BBOX, "inkscape:snap-bbox"},
+    {SP_ATTR_INKSCAPE_SNAP_NODES, "inkscape:snap-nodes"},
     {SP_ATTR_INKSCAPE_CURRENT_LAYER, "inkscape:current-layer"},
     {SP_ATTR_INKSCAPE_DOCUMENT_UNITS, "inkscape:document-units"},
     {SP_ATTR_INKSCAPE_CONNECTOR_SPACING, "inkscape:connector-spacing"},
index c7f1fb71edce1d8ad0156885a425fa861f414e52..bb6962304a50c4876a460b8d741fa4ef1f45b104 100644 (file)
@@ -83,14 +83,8 @@ enum SPAttributeEnum {
     SP_ATTR_INKSCAPE_WINDOW_HEIGHT,
     SP_ATTR_INKSCAPE_WINDOW_X,
     SP_ATTR_INKSCAPE_WINDOW_Y,
-    /*SP_ATTR_INKSCAPE_GRID_BBOX,
-    SP_ATTR_INKSCAPE_GUIDE_BBOX,
-    SP_ATTR_INKSCAPE_OBJECT_BBOX,
-    SP_ATTR_INKSCAPE_GRID_POINTS,
-    SP_ATTR_INKSCAPE_GUIDE_POINTS,
-    SP_ATTR_INKSCAPE_OBJECT_POINTS,*/
-    SP_ATTR_INKSCAPE_OBJECT_PATHS,
-    SP_ATTR_INKSCAPE_OBJECT_NODES,
+    SP_ATTR_INKSCAPE_SNAP_BBOX,
+    SP_ATTR_INKSCAPE_SNAP_NODES,
     SP_ATTR_INKSCAPE_CURRENT_LAYER,
     SP_ATTR_INKSCAPE_DOCUMENT_UNITS,
     SP_ATTR_INKSCAPE_CONNECTOR_SPACING,
index ada272acd2f88157d70d0758a84b55f5e36f74cc..4358d56dd560d25b71c1c9ffea7e38e41094bc01 100644 (file)
@@ -323,7 +323,7 @@ static gint sp_3dbox_context_root_handler(SPEventContext *event_context, GdkEven
 
             /* Snap center */
             SnapManager const &m = desktop->namedview->snap_manager;
-            rc->center = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
+            rc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE | Inkscape::Snapper::SNAPPOINT_BBOX,
                                     button_dt, rc->item).getPoint();
 
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
@@ -354,7 +354,7 @@ static gint sp_3dbox_context_root_handler(SPEventContext *event_context, GdkEven
             NR::Point motion_dt(desktop->w2d(motion_w));
 
             SnapManager const &m = desktop->namedview->snap_manager;
-            motion_dt = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, motion_dt, rc->item).getPoint();
+            motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, rc->item).getPoint();
 
             rc->ctrl_dragged  = event->motion.state & GDK_CONTROL_MASK;
 
@@ -375,7 +375,7 @@ static gint sp_3dbox_context_root_handler(SPEventContext *event_context, GdkEven
                 } else {
                     rc->drag_ptC = motion_dt;
                 }
-                rc->drag_ptC = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, rc->drag_ptC, rc->item).getPoint();
+                rc->drag_ptC = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, rc->drag_ptC, rc->item).getPoint();
                 if (rc->ctrl_dragged) {
                        Box3D::PerspectiveLine pl1 (NR::Point (event_context->xp, event_context->yp), Box3D::Y);
                        Box3D::PerspectiveLine pl2 (rc->drag_ptB, Box3D::X);
index 89d38bace98a69eba99ef7defd7291d058819917..195272fa2d5219bd85284e57335f666d4566bf62 100644 (file)
@@ -528,7 +528,7 @@ connector_handle_button_press(SPConnectorContext *const cc, GdkEventButton const
                         // This is the first point, so just snap it to the grid
                         // as there's no other points to go off.
                         SnapManager const &m = cc->desktop->namedview->snap_manager;
-                        p = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
+                        p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE | Inkscape::Snapper::SNAPPOINT_BBOX,
                                        p, NULL).getPoint();
                     }
                     spcc_connector_set_initial_point(cc, p);
index 15138a10b6f9f188de86ce7b794526e33691b5bd..8a131b081952a7b7d595eabf2af09e5222c48ece 100644 (file)
@@ -112,11 +112,11 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
             Inkscape::SnappedPoint s[2];
 
             /* Try to snap p[0] (the opposite corner) along the constraint vector */
-            s[0] = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT, p[0],
+            s[0] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[0],
                                      Inkscape::Snapper::ConstraintLine(p[0] - p[1]), item);
 
             /* Try to snap p[1] (the dragged corner) along the constraint vector */
-            s[1] = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT, p[1],
+            s[1] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1],
                                      Inkscape::Snapper::ConstraintLine(p[1] - p[0]), item);
 
             /* Choose the best snap and update points accordingly */
@@ -132,7 +132,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
 
             /* Our origin is the opposite corner.  Snap the drag point along the constraint vector */
             p[0] = center;
-            p[1] = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT, p[1],
+            p[1] = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1],
                                      Inkscape::Snapper::ConstraintLine(p[1] - p[0]), item).getPoint();
         }
 
@@ -147,8 +147,8 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
 
         Inkscape::SnappedPoint s[2];
 
-        s[0] = m.freeSnap(Inkscape::Snapper::SNAP_POINT, p[0], item);
-        s[1] = m.freeSnap(Inkscape::Snapper::SNAP_POINT, p[1], item);
+        s[0] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[0], item);
+        s[1] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p[1], item);
 
         if (s[0].getDistance() < s[1].getDistance()) {
             p[0] = s[0].getPoint();
@@ -162,7 +162,7 @@ NR::Rect Inkscape::snap_rectangular_box(SPDesktop const *desktop, SPItem *item,
 
         /* There's no constraint on the corner point, so just snap it to anything */
         p[0] = center;
-        p[1] = m.freeSnap(Inkscape::Snapper::SNAP_POINT, pt, item).getPoint();
+        p[1] = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, pt, item).getPoint();
     }
 
     p[0] = sp_desktop_dt2root_xy_point(desktop, p[0]);
index 30b2e612c40281b751541f04367a5a4807798e71..6742ddaf3325d3153297bbe4a6b88ac900fd798b 100644 (file)
@@ -354,7 +354,7 @@ void spdc_endpoint_snap_rotation(SPEventContext const *const ec, NR::Point &p, N
 
         /* Snap it along best vector */
         SnapManager const &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
-        p = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
+        p = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE | Inkscape::Snapper::SNAPPOINT_BBOX,
                               p, Inkscape::Snapper::ConstraintLine(best), NULL).getPoint();
     }
 }
@@ -369,7 +369,7 @@ void spdc_endpoint_snap_free(SPEventContext const * const ec, NR::Point& p, guin
 
     /* FIXME: this should be doing bbox snap as well */
     SnapManager const &m = SP_EVENT_CONTEXT_DESKTOP(ec)->namedview->snap_manager;
-    p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
+    p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
 }
 
 static SPCurve *
index e9192652a63675b2736a02c1e00c1f6dceb8a36a..6798a2feb7dcd9d71a5e3b8aab442f3159e236eb 100644 (file)
@@ -413,7 +413,7 @@ sp_gradient_context_root_handler(SPEventContext *event_context, GdkEvent *event)
             /* Snap center to nearest magnetic point */
             
             SnapManager const &m = desktop->namedview->snap_manager;
-            rc->origin = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, button_dt, NULL).getPoint();
+            rc->origin = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, button_dt, NULL).getPoint();
 
             ret = TRUE;
         }
index 5801489fe0db2114dd225072547bf570da634644..f4070079b42c07af1a38315b349ee1735afd6c0c 100644 (file)
@@ -436,7 +436,7 @@ gr_knot_moved_handler(SPKnot *knot, NR::Point const *ppointer, guint state, gpoi
     if (!((state & GDK_SHIFT_MASK) || ((state & GDK_CONTROL_MASK) && (state & GDK_MOD1_MASK)))) {
         // Try snapping to the grid or guides
         SnapManager const &m = dragger->parent->desktop->namedview->snap_manager;
-        Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT, p, NULL);
+        Inkscape::SnappedPoint s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE | Inkscape::Snapper::SNAPPOINT_BBOX, p, NULL);
         if (s.getDistance() < 1e6) {
             p = s.getPoint();
             sp_knot_moveto (knot, &p);
index 1e4eb02d835e49541de517e29900d7198587f292..decfaf3cfd0eade4c6fee7ff2da5ea9530f1bf7d 100644 (file)
@@ -49,7 +49,7 @@ Inkscape::GuideSnapper::LineList Inkscape::GuideSnapper::_getSnapLines(NR::Point
  */
 bool Inkscape::GuideSnapper::ThisSnapperMightSnap() const
 {
-    return _named_view == NULL ? false : (_enabled && _snap_to != 0 && _named_view->showguides);
+    return _named_view == NULL ? false : (_enabled && _snap_from != 0 && _named_view->showguides);
 }
 
 /*
index a2c6b944bcc28ff10c36963b8fbb1bb142901cda..4c886fea50fe684411977227aa9331eee050ef7b 100644 (file)
@@ -8,13 +8,14 @@ Inkscape::LineSnapper::LineSnapper(SPNamedView const *nv, NR::Coord const d) : S
 
 }
 
-Inkscape::SnappedPoint Inkscape::LineSnapper::_doFreeSnap(NR::Point const &p,
-                                                          std::list<SPItem const *> const &it) const
+Inkscape::SnappedPoint Inkscape::LineSnapper::_doFreeSnap(Inkscape::Snapper::PointType const &t,
+                                                                                                       NR::Point const &p,
+                                                    std::list<SPItem const *> const &it) const
 {
     /* Snap along x (ie to vertical lines) */
-    Inkscape::SnappedPoint const v = _doConstrainedSnap(p, component_vectors[NR::X], it);
+    Inkscape::SnappedPoint const v = _doConstrainedSnap(t, p, component_vectors[NR::X], it);
     /* Snap along y (ie to horizontal lines) */
-    Inkscape::SnappedPoint const h = _doConstrainedSnap(p, component_vectors[NR::Y], it);
+    Inkscape::SnappedPoint const h = _doConstrainedSnap(t, p, component_vectors[NR::Y], it);
 
     /* If we snapped to both, combine the two results.  This is so that, for example,
     ** we snap nicely to the intersection of two guidelines.
@@ -34,9 +35,10 @@ Inkscape::SnappedPoint Inkscape::LineSnapper::_doFreeSnap(NR::Point const &p,
     return h;
 }
 
-Inkscape::SnappedPoint Inkscape::LineSnapper::_doConstrainedSnap(NR::Point const &p,
-                                                                 ConstraintLine const &c,
-                                                                 std::list<SPItem const *> const &it) const
+Inkscape::SnappedPoint Inkscape::LineSnapper::_doConstrainedSnap(Inkscape::Snapper::PointType const &t, 
+                                                                                                       NR::Point const &p,
+                                                    ConstraintLine const &c,
+                                                    std::list<SPItem const *> const &it) const
 {
     Inkscape::SnappedPoint s = SnappedPoint(p, NR_HUGE);
 
index 2816b2ec01e3648d853f309ecf6732f25eabfb62..f6b467520e718016a01cbde04e03ec144f203b48 100644 (file)
@@ -25,12 +25,14 @@ protected:
   typedef std::list<std::pair<NR::Dim2, NR::Coord> > LineList;
 
 private:
-  SnappedPoint _doFreeSnap(NR::Point const &p,
-                          std::list<SPItem const *> const &it) const;
+  SnappedPoint _doFreeSnap(Inkscape::Snapper::PointType const &t,
+                                       NR::Point const &p,
+                                       std::list<SPItem const *> const &it) const;
   
-  SnappedPoint _doConstrainedSnap(NR::Point const &p,
-                                 ConstraintLine const &c,
-                                 std::list<SPItem const *> const &it) const;
+  SnappedPoint _doConstrainedSnap(Inkscape::Snapper::PointType const &t,
+                                       NR::Point const &p,
+                                       ConstraintLine const &c,
+                                       std::list<SPItem const *> const &it) const;
   
   /**
    *  \param p Point that we are trying to snap.
index 4131c8ccaaeca8e439804d672c92a12c2b738f8a..28c845492eaa515255644a302828e2f5509717e3 100644 (file)
@@ -999,7 +999,7 @@ static void sp_nodepath_selected_nodes_move(Inkscape::NodePath::Path *nodepath,
         
         for (GList *l = nodepath->selected; l != NULL; l = l->next) {
             Inkscape::NodePath::Node *n = (Inkscape::NodePath::Node *) l->data;
-            Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::Snapper::SNAP_POINT, n->pos + delta, n->subpath->nodepath->path);
+            Inkscape::SnappedPoint const s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, n->pos + delta, n->subpath->nodepath->path);
             if (s.getDistance() < best) {
                 best = s.getDistance();
                 best_pt = s.getPoint() - n->pos;
@@ -3377,9 +3377,9 @@ static gboolean node_handle_request(SPKnot *knot, NR::Point *p, guint state, gpo
             NR::Coord const scal = dot(delta, ndelta) / linelen;
             (*p) = n->pos + (scal / linelen) * ndelta;
         }
-        *p = m.constrainedSnap(Inkscape::Snapper::SNAP_POINT, *p, Inkscape::Snapper::ConstraintLine(*p, ndelta), NULL).getPoint();
+        *p = m.constrainedSnap(Inkscape::Snapper::SNAPPOINT_NODE, *p, Inkscape::Snapper::ConstraintLine(*p, ndelta), NULL).getPoint();
     } else {
-        *p = m.freeSnap(Inkscape::Snapper::SNAP_POINT, *p, NULL).getPoint();
+        *p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, *p, NULL).getPoint();
     }
 
     sp_node_adjust_handle(n, -which);
index 487caa09c503923bce9a949f5abdb701814e46cf..6eff465f8ab308b5bf19a3ce15c41f7be4fd7fd0 100644 (file)
@@ -224,7 +224,7 @@ static NR::Point snap_knot_position(SPItem *item, NR::Point const &p)
     NR::Matrix const i2d (sp_item_i2d_affine (item));
     NR::Point s = p * i2d;    
     SnapManager const &m = desktop->namedview->snap_manager;
-    s = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, s, item).getPoint();
+    s = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, s, item).getPoint();
     return s * i2d.inverse();
 }
 
index 88e143abaf9e3130b807386b694c37d526d4bfcc..1a50841c47e4bba3513e2d1c2fc97b38dfb3a022 100644 (file)
@@ -27,7 +27,8 @@
 
 
 Inkscape::ObjectSnapper::ObjectSnapper(SPNamedView const *nv, NR::Coord const d)
-    : Snapper(nv, d), _snap_to_nodes(true), _snap_to_paths(true)
+    : Snapper(nv, d), _snap_to_itemnodes(true), _snap_to_itempaths(true), 
+    _snap_to_bboxnodes(true), _snap_to_bboxpaths(true), _strict_snapping(true)
 {
 
 }
@@ -71,7 +72,8 @@ void Inkscape::ObjectSnapper::_findCandidates(std::list<SPItem*>& c,
 }
 
 
-void Inkscape::ObjectSnapper::_snapNodes(Inkscape::SnappedPoint &s,
+void Inkscape::ObjectSnapper::_snapNodes(Inkscape::Snapper::PointType const &t,
+                                                                                Inkscape::SnappedPoint &s,
                                          NR::Point const &p,
                                          std::list<SPItem*> const &cand) const
 {
@@ -81,9 +83,13 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::SnappedPoint &s,
     SPDesktop const *desktop = SP_ACTIVE_DESKTOP;
     
     // Determine the type of bounding box we should snap to
-    //TODO if (_snap_to_bbox) ???? -> will save some cpu time 
-       gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box");
-       SPItem::BBoxType bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;        
+    SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX; 
+       if (_snap_to_bboxnodes) {       
+               gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box");
+               bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;
+       }        
+       
+       bool p_is_a_node = t & Inkscape::Snapper::SNAPPOINT_NODE;        
 
     for (std::list<SPItem*>::const_iterator i = cand.begin(); i != cand.end(); i++) {
         
@@ -110,23 +116,31 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::SnappedPoint &s,
                std::list<NR::Point> points_to_snap_to;
         
         //Collect all nodes so we can snap to them
-        if (curve) {
-            int j = 0;
-            while (SP_CURVE_BPATH(curve)[j].code != NR_END) {        
-                /* Get this node in desktop coordinates */
-                NArtBpath const &bp = SP_CURVE_BPATH(curve)[j];
-                points_to_snap_to.push_back(desktop->doc2dt(bp.c(3) * i2doc));
-                j++;
-            }
+        if (_snap_to_itemnodes) {
+               if (!(_strict_snapping && !p_is_a_node)) {
+                       if (curve) {
+                           int j = 0;
+                           while (SP_CURVE_BPATH(curve)[j].code != NR_END) {        
+                               /* Get this node in desktop coordinates */
+                               NArtBpath const &bp = SP_CURVE_BPATH(curve)[j];
+                               points_to_snap_to.push_back(desktop->doc2dt(bp.c(3) * i2doc));
+                               j++;
+                           }
+                       }
+               }
         }
         
         //Collect the bounding box's corners so we can snap to them
-        NR::Maybe<NR::Rect> b = sp_item_bbox_desktop(root_item, bbox_type);
-        if (b) {
-               for ( unsigned k = 0 ; k < 4 ; k++ ) {
-                   points_to_snap_to.push_back(b->corner(k));
-               }
-        }        
+        if (_snap_to_bboxnodes) {
+               if (!(_strict_snapping && p_is_a_node)) {
+                       NR::Maybe<NR::Rect> b = sp_item_bbox_desktop(root_item, bbox_type);
+                       if (b) {
+                               for ( unsigned k = 0 ; k < 4 ; k++ ) {
+                                   points_to_snap_to.push_back(b->corner(k));
+                               }
+                       }
+               }        
+        }
         
         //Do the snapping, using all the nodes and corners collected above
         for (std::list<NR::Point>::const_iterator k = points_to_snap_to.begin(); k != points_to_snap_to.end(); k++) {
@@ -140,7 +154,8 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::SnappedPoint &s,
 }
 
 
-void Inkscape::ObjectSnapper::_snapPaths(Inkscape::SnappedPoint &s,
+void Inkscape::ObjectSnapper::_snapPaths(Inkscape::Snapper::PointType const &t,
+                                                                                Inkscape::SnappedPoint &s,
                                          NR::Point const &p,
                                          std::list<SPItem*> const &cand) const
 {
@@ -152,10 +167,14 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::SnappedPoint &s,
     NR::Point const p_doc = desktop->dt2doc(p);
     
     // Determine the type of bounding box we should snap to
-    //TODO if (_snap_to_bbox) ???? -> will save some cpu time 
-       gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box");
-       SPItem::BBoxType bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;        
-    
+    SPItem::BBoxType bbox_type = SPItem::GEOMETRIC_BBOX; 
+       if (_snap_to_bboxpaths) {       
+       gchar const *prefs_bbox = prefs_get_string_attribute("tools.select", "bounding_box");
+               bbox_type = (prefs_bbox != NULL && strcmp(prefs_bbox, "geometric")==0)? SPItem::GEOMETRIC_BBOX : SPItem::APPROXIMATE_BBOX;        
+       }
+       
+       bool p_is_a_node = t & Inkscape::Snapper::SNAPPOINT_NODE;        
+       
     for (std::list<SPItem*>::const_iterator i = cand.begin(); i != cand.end(); i++) {
 
         /* Transform the requested snap point to this item's coordinates */
@@ -174,19 +193,27 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::SnappedPoint &s,
         std::list<Path*> paths_to_snap_to;
         
         //Add the item's path to snap to
-        paths_to_snap_to.push_back(Path_for_item(root_item, true, true));
+        if (_snap_to_itempaths) {
+               if (!(_strict_snapping && !p_is_a_node)) {
+                       paths_to_snap_to.push_back(Path_for_item(root_item, true, true));
+               }
+        }
                 
         //Add the item's bounding box to snap to
-        //This will get ugly... rect -> curve -> bpath
-        NRRect rect;
-        sp_item_invoke_bbox(root_item, &rect, i2doc, TRUE, bbox_type);
-        NR::Maybe<NR::Rect> bbox = rect.upgrade();
-        SPCurve *curve = sp_curve_new_from_rect(bbox);
-        NArtBpath *bpath = SP_CURVE_BPATH(curve);
-        Path *path = bpath_to_Path(bpath);  
-        paths_to_snap_to.push_back(path);
-        delete curve;
-        delete bpath;
+        if (_snap_to_bboxpaths) {
+               if (!(_strict_snapping && p_is_a_node)) {               
+                       //This will get ugly... rect -> curve -> bpath
+                       NRRect rect;
+                       sp_item_invoke_bbox(root_item, &rect, i2doc, TRUE, bbox_type);
+                       NR::Maybe<NR::Rect> bbox = rect.upgrade();
+                       SPCurve *curve = sp_curve_new_from_rect(bbox);
+                       NArtBpath *bpath = SP_CURVE_BPATH(curve);
+                       Path *path = bpath_to_Path(bpath);  
+                       paths_to_snap_to.push_back(path);
+                       delete curve;
+                       delete bpath;
+               }
+        }
         
         //Now we can finally do the real snapping, using the paths collected above        
         for (std::list<Path*>::const_iterator k = paths_to_snap_to.begin(); k != paths_to_snap_to.end(); k++) {
@@ -214,7 +241,8 @@ void Inkscape::ObjectSnapper::_snapPaths(Inkscape::SnappedPoint &s,
 }
 
 
-Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doFreeSnap(NR::Point const &p,
+Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doFreeSnap(Inkscape::Snapper::PointType const &t,
+                                                                                                                       NR::Point const &p,
                                                             std::list<SPItem const *> const &it) const
 {
     if ( NULL == _named_view ) {
@@ -227,11 +255,11 @@ Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doFreeSnap(NR::Point const &p,
 
     SnappedPoint s(p, NR_HUGE);
 
-    if (_snap_to_nodes) {
-        _snapNodes(s, p, cand);
+    if (_snap_to_itemnodes || _snap_to_bboxnodes) {
+        _snapNodes(t, s, p, cand);
     }
-    if (_snap_to_paths) {
-        _snapPaths(s, p, cand);
+    if (_snap_to_itempaths || _snap_to_bboxpaths) {
+        _snapPaths(t, s, p, cand);
     }
 
     return s;
@@ -239,14 +267,15 @@ Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doFreeSnap(NR::Point const &p,
 
 
 
-Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doConstrainedSnap(NR::Point const &p,
+Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doConstrainedSnap(Inkscape::Snapper::PointType const &t,
+                                                                                                                                  NR::Point const &p,
                                                                    ConstraintLine const &c,
                                                                    std::list<SPItem const *> const &it) const
 {
     /* FIXME: this needs implementing properly; I think we have to do the
     ** intersection of c with the objects.
     */
-    return _doFreeSnap(p, it);
+    return _doFreeSnap(t, p, it);
 }
 
 /**
@@ -254,7 +283,8 @@ Inkscape::SnappedPoint Inkscape::ObjectSnapper::_doConstrainedSnap(NR::Point con
  */
 bool Inkscape::ObjectSnapper::ThisSnapperMightSnap() const
 {
-    return (_enabled && _snap_to != 0 && (_snap_to_paths || _snap_to_nodes));
+    bool snap_to_something = _snap_to_itempaths || _snap_to_itemnodes || _snap_to_bboxpaths || _snap_to_bboxnodes;
+    return (_enabled && _snap_from != 0 && snap_to_something);
 }
 
 
index 47ac14545aa6885f92b268a6feb2bae119843c9e..6556b0a243af612fefa860a35f7c120a627e91a8 100644 (file)
@@ -27,42 +27,77 @@ class ObjectSnapper : public Snapper
 public:
   ObjectSnapper(SPNamedView const *nv, NR::Coord const d);
 
-  void setSnapToNodes(bool s) {
-    _snap_to_nodes = s;
+  void setSnapToItemNodes(bool s) {
+    _snap_to_itemnodes = s;
   }
 
-  bool getSnapToNodes() const {
-    return _snap_to_nodes;
+  bool getSnapToItemNodes() const {
+    return _snap_to_itemnodes;
   }
 
-  void setSnapToPaths(bool s) {
-    _snap_to_paths = s;
+  void setSnapToItemPaths(bool s) {
+    _snap_to_itempaths = s;
   }
 
-  bool getSnapToPaths() const {
-    return _snap_to_paths;
+  bool getSnapToItemPaths() const {
+    return _snap_to_itempaths;
+  }
+  
+  void setSnapToBBoxNodes(bool s) {
+    _snap_to_bboxnodes = s;
+  }
+
+  bool getSnapToBBoxNodes() const {
+    return _snap_to_bboxnodes;
+  }
+
+  void setSnapToBBoxPaths(bool s) {
+    _snap_to_bboxpaths = s;
+  }
+
+  bool getSnapToBBoxPaths() const {
+    return _snap_to_bboxpaths;
+  }
+  
+  bool setStrictSnapping(bool enabled) {
+       _strict_snapping = enabled;
   }
   
   bool ThisSnapperMightSnap() const;
   
 private:
-  SnappedPoint _doFreeSnap(NR::Point const &p,
-                          std::list<SPItem const *> const &it) const;
+  SnappedPoint _doFreeSnap(Inkscape::Snapper::PointType const &t,
+                                       NR::Point const &p,
+                                       std::list<SPItem const *> const &it) const;
 
-  SnappedPoint _doConstrainedSnap(NR::Point const &p,
-                                 ConstraintLine const &c,
-                                 std::list<SPItem const *> const &it) const;
+  SnappedPoint _doConstrainedSnap(Inkscape::Snapper::PointType const &t,
+                                       NR::Point const &p,
+                                       ConstraintLine const &c,
+                                       std::list<SPItem const *> const &it) const;
   
   void _findCandidates(std::list<SPItem*>& c,
-                      SPObject* r,
-                      std::list<SPItem const *> const &it,
-                      NR::Point const &p) const;
+                               SPObject* r,
+                               std::list<SPItem const *> const &it,
+                               NR::Point const &p) const;
+  
+  void _snapNodes(Inkscape::Snapper::PointType const &t,
+                                       Inkscape::SnappedPoint &s, 
+                                       NR::Point const &p, 
+                                       std::list<SPItem*> const &cand) const;
+                                       
+  void _snapPaths(Inkscape::Snapper::PointType const &t, 
+                                       Inkscape::SnappedPoint &s, 
+                                       NR::Point const &p, 
+                                       std::list<SPItem*> const &cand) const;
   
-  void _snapNodes(Inkscape::SnappedPoint &s, NR::Point const &p, std::list<SPItem*> const &cand) const;
-  void _snapPaths(Inkscape::SnappedPoint &s, NR::Point const &p, std::list<SPItem*> const &cand) const;
+  bool _snap_to_itemnodes;
+  bool _snap_to_itempaths;
+  bool _snap_to_bboxnodes;
+  bool _snap_to_bboxpaths;
   
-  bool _snap_to_nodes;
-  bool _snap_to_paths;
+  //if enabled, then bbox corners will only snap to bboxes, 
+  //and nodes will only snap to nodes and paths
+  bool _strict_snapping; 
 };
 
 }
index d86b83c01b72f0344c5b35dd32eec2049611ecac..5ce9a171e8faa06fd73026c329c6ea9fcde2ebe1 100644 (file)
@@ -235,7 +235,7 @@ pencil_handle_button_press(SPPencilContext *const pc, GdkEventButton const &beve
                         selection->clear();
                         desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating new path"));
                         SnapManager const &m = desktop->namedview->snap_manager;
-                        p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
+                        p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
                     } else if (selection->singleItem() && SP_IS_PATH(selection->singleItem())) {
                         desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Appending to selected path"));
                     }
@@ -304,7 +304,7 @@ pencil_handle_motion_notify(SPPencilContext *const pc, GdkEventMotion const &mev
                     p = anchor->dp;
                 } else if ((mevent.state & GDK_SHIFT_MASK) == 0) {
                     SnapManager const &m = dt->namedview->snap_manager;
-                    p = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, p, NULL).getPoint();
+                    p = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, p, NULL).getPoint();
                 }
                 if ( pc->npoints != 0 ) { // buttonpress may have happened before we entered draw context!
                     spdc_add_freehand_point(pc, p, mevent.state);
index c8f9bf0f101d0b1e2cc9e3b50a79bf49b5f3dc13..329f3910dcea9c0726956686e4142914e55b9017 100644 (file)
@@ -299,7 +299,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
 
             /* Snap center */
             SnapManager const &m = desktop->namedview->snap_manager;
-            rc->center = m.freeSnap(Inkscape::Snapper::SNAP_POINT | Inkscape::Snapper::BBOX_POINT,
+            rc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE | Inkscape::Snapper::SNAPPOINT_BBOX,
                                     button_dt, rc->item).getPoint();
 
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
@@ -330,7 +330,7 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
             NR::Point motion_dt(desktop->w2d(motion_w));
             
             SnapManager const &m = desktop->namedview->snap_manager;
-            motion_dt = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, motion_dt, rc->item).getPoint();
+            motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, rc->item).getPoint();
             
             sp_rect_drag(*rc, motion_dt, event->motion.state);
             
index 188ace06bd49cc91115bec2e962df56b6e68bbb6..8e916193bae7882eedb1c1acd56b119885a77966 100644 (file)
@@ -1149,7 +1149,7 @@ void sp_selection_paste(bool in_place)
         /* Snap the offset of the new item(s) to the grid */
         SnapManager &sm = desktop->namedview->snap_manager;
         SnapManager::SnapperList gs = sm.getGridSnappers();
-        m = sm.freeSnapAlways(Inkscape::Snapper::SNAP_POINT, m, NULL, gs).getPoint();
+        m = sm.freeSnapAlways(Inkscape::Snapper::SNAPPOINT_NODE, m, NULL, gs).getPoint();
         sp_selection_move_relative(selection, m);
     }
 
index 1661bdc6009cbe9d8cbd06a24df27b241cfa8f91..465813ae0b68834f6704e25f95918d71ce70e587 100644 (file)
@@ -918,14 +918,14 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
             pt[NR::Y] > _origin[NR::Y] ? aspect_ratio : -aspect_ratio
             );
 
-        std::pair<NR::scale, bool> bb = m.constrainedSnapScale(Snapper::BBOX_POINT,
+        std::pair<NR::scale, bool> bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX,
                                                                _bbox_points,
                                                                it,
                                                                Snapper::ConstraintLine(_origin_for_bboxpoints, cv),
                                                                s,
                                                                _origin_for_bboxpoints);
 
-        std::pair<NR::scale, bool> sn = m.constrainedSnapScale(Snapper::SNAP_POINT,
+        std::pair<NR::scale, bool> sn = m.constrainedSnapScale(Snapper::SNAPPOINT_NODE,
                                                                _snap_points,
                                                                it,
                                                                Snapper::ConstraintLine(_origin_for_specpoints, cv),
@@ -946,12 +946,12 @@ gboolean Inkscape::SelTrans::scaleRequest(NR::Point &pt, guint state)
     } else {
         /* Scale aspect ratio is unlocked */
         
-        std::pair<NR::scale, bool> bb = m.freeSnapScale(Snapper::BBOX_POINT,
+        std::pair<NR::scale, bool> bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX,
                                                         _bbox_points,
                                                         it,
                                                         s,
                                                         _origin_for_bboxpoints);
-        std::pair<NR::scale, bool> sn = m.freeSnapScale(Snapper::SNAP_POINT,
+        std::pair<NR::scale, bool> sn = m.freeSnapScale(Snapper::SNAPPOINT_NODE,
                                                         _snap_points,
                                                         it,
                                                         s,
@@ -1036,7 +1036,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
         s[perp] = fabs(s[axis]);
 
         std::pair<NR::Coord, bool> const bb = m.freeSnapStretch(
-            Snapper::BBOX_POINT,
+            Snapper::SNAPPOINT_BBOX,
             _bbox_points,
             it,
             s[axis],
@@ -1045,7 +1045,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
             true);
 
         std::pair<NR::Coord, bool> const sn = m.freeSnapStretch(
-            Snapper::SNAP_POINT,
+            Snapper::SNAPPOINT_NODE,
             _snap_points,
             it,
             s[axis],
@@ -1062,7 +1062,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
     } else {
         
         std::pair<NR::Coord, bool> const bb = m.freeSnapStretch(
-            Snapper::BBOX_POINT,
+            Snapper::SNAPPOINT_BBOX,
             _bbox_points,
             it,
             s[axis],
@@ -1071,7 +1071,7 @@ gboolean Inkscape::SelTrans::stretchRequest(SPSelTransHandle const &handle, NR::
             false);
 
         std::pair<NR::Coord, bool> const sn = m.freeSnapStretch(
-            Snapper::SNAP_POINT,
+            Snapper::SNAPPOINT_NODE,
             _snap_points,
             it,
             s[axis],
@@ -1151,14 +1151,14 @@ gboolean Inkscape::SelTrans::skewRequest(SPSelTransHandle const &handle, NR::Poi
     } else {
         SnapManager const &m = _desktop->namedview->snap_manager;
 
-        std::pair<NR::Coord, bool> bb = m.freeSnapSkew(Inkscape::Snapper::BBOX_POINT,
+        std::pair<NR::Coord, bool> bb = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX,
                                                        _bbox_points,
                                                        std::list<SPItem const *>(),
                                                        skew[dim_a],
                                                        _origin_for_bboxpoints,
                                                        dim_b);
 
-        std::pair<NR::Coord, bool> sn = m.freeSnapSkew(Inkscape::Snapper::SNAP_POINT,
+        std::pair<NR::Coord, bool> sn = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE,
                                                        _snap_points,
                                                        std::list<SPItem const *>(),
                                                        skew[dim_a],
@@ -1244,7 +1244,7 @@ gboolean Inkscape::SelTrans::centerRequest(NR::Point &pt, guint state)
     using NR::Y;
 
     SnapManager const &m = _desktop->namedview->snap_manager;
-    pt = m.freeSnap(Snapper::SNAP_POINT, pt, NULL).getPoint();
+    pt = m.freeSnap(Snapper::SNAPPOINT_NODE, pt, NULL).getPoint();
 
     if (state & GDK_CONTROL_MASK) {
         if ( fabs(_point[X] - pt[X]) > fabs(_point[Y] - pt[Y]) ) {
@@ -1488,7 +1488,7 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
         ** FIXME: this will snap to more than just the grid, nowadays.
         */
 
-        dxy = m.freeSnap(Snapper::SNAP_POINT, dxy, NULL).getPoint();
+        dxy = m.freeSnap(Snapper::SNAPPOINT_NODE, dxy, NULL).getPoint();
 
     } else if (!shift) {
 
@@ -1505,13 +1505,13 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
             /* Snap to things, and also constrain to horizontal or vertical movement */
 
             for (unsigned int dim = 0; dim < 2; dim++) {
-                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::BBOX_POINT,
+                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX,
                                                          _bbox_points,
                                                          it,
                                                          Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
                                                          dxy));
                             
-                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAP_POINT,
+                s.push_back(m.constrainedSnapTranslation(Inkscape::Snapper::SNAPPOINT_NODE,
                                                          _snap_points,
                                                          it,
                                                          Inkscape::Snapper::ConstraintLine(component_vectors[dim]),
@@ -1522,9 +1522,9 @@ void Inkscape::SelTrans::moveTo(NR::Point const &xy, guint state)
 
             /* Snap to things with no constraint */
 
-            s.push_back(m.freeSnapTranslation(Inkscape::Snapper::BBOX_POINT,
+            s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_BBOX,
                                               _bbox_points, it, dxy));
-            s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAP_POINT,
+            s.push_back(m.freeSnapTranslation(Inkscape::Snapper::SNAPPOINT_NODE,
                                               _snap_points, it, dxy));
         }
 
index 3dda92ecbcd73504c982a36737f9205cdc57a693..218cbb0293de6f42c082f78fbacd57f3e8d3e0bc 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "sp-namedview.h"
 #include "snap.h"
+
 #include <libnr/nr-point-fns.h>
 #include <libnr/nr-scale-ops.h>
 #include <libnr/nr-values.h>
@@ -93,6 +94,34 @@ bool SnapManager::SomeSnapperMightSnap() const
     return (i != s.end());
 }
 
+void SnapManager::setSnapModeBBox(bool enabled)
+{
+       guide.setSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX, enabled);
+       object.setSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX, enabled);
+       object.setSnapToBBoxNodes(enabled);
+       object.setSnapToBBoxPaths(enabled);
+       object.setStrictSnapping(true);
+}
+
+bool SnapManager::getSnapModeBBox() const
+{
+       return guide.getSnapFrom(Inkscape::Snapper::SNAPPOINT_BBOX);
+}
+
+
+void SnapManager::setSnapModeNodes(bool enabled)
+{
+       guide.setSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE, enabled);
+       object.setSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE, enabled);
+       object.setSnapToItemNodes(enabled);
+       object.setSnapToItemPaths(enabled);     
+       object.setStrictSnapping(true);
+}
+
+bool SnapManager::getSnapModeNodes() const
+{
+       return guide.getSnapFrom(Inkscape::Snapper::SNAPPOINT_NODE);
+}
 
 /**
  *  Try to snap a point to any interested snappers.
index e0217948fe3cfdb4b0f7a96b2841096512dd49c1..527947e104bf17d8973bea76b4454503e81498ac 100644 (file)
@@ -52,7 +52,7 @@ public:
                                     NR::Point const &p,
                                     std::list<SPItem const *> const &it) const;
 
-     Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
+       Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t,
                                       NR::Point const &p,
                                       std::list<SPItem const *> const &it,
                                       SnapperList const &snappers ) const;
@@ -121,6 +121,11 @@ public:
 
     SnapperList getSnappers() const;
     SnapperList getGridSnappers() const;
+    
+    void setSnapModeBBox(bool enabled);
+    void setSnapModeNodes(bool enabled);
+    bool getSnapModeBBox() const;
+    bool getSnapModeNodes() const;
 
 protected:
     SPNamedView const *_named_view;
index 390e0957e983eab9f0b47b7a451d0b2b74bf17a8..7a82fe1d462f384e3be8c9ff85146c1d3f768fff 100644 (file)
@@ -13,8 +13,8 @@
 #include "inkscape.h"
 #include "desktop.h"
 
-Inkscape::Snapper::PointType const Inkscape::Snapper::BBOX_POINT = 0x1;
-Inkscape::Snapper::PointType const Inkscape::Snapper::SNAP_POINT = 0x2;
+Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_BBOX = 0x1;
+Inkscape::Snapper::PointType const Inkscape::Snapper::SNAPPOINT_NODE = 0x2;
 
 /**
  *  Construct new Snapper for named view.
@@ -26,7 +26,7 @@ Inkscape::Snapper::Snapper(SPNamedView const *nv, NR::Coord const d) : _named_vi
     g_assert(_named_view != NULL);
     g_assert(SP_IS_NAMEDVIEW(_named_view));
 
-    setSnapTo(BBOX_POINT | SNAP_POINT, true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
+    setSnapFrom(SNAPPOINT_BBOX | SNAPPOINT_NODE, true); //Snap any point. In v0.45 and earlier, this was controlled in the preferences tab
 }
 
 /**
@@ -51,12 +51,12 @@ NR::Coord Inkscape::Snapper::getDistance() const
  *  \param t Point type.
  *  \param s true to snap to this point type, otherwise false;
  */
-void Inkscape::Snapper::setSnapTo(PointType t, bool s)
+void Inkscape::Snapper::setSnapFrom(PointType t, bool s)
 {
     if (s) {
-        _snap_to |= t;
+        _snap_from |= t;
     } else {
-        _snap_to &= ~t;
+        _snap_from &= ~t;
     }
 }
 
@@ -64,9 +64,9 @@ void Inkscape::Snapper::setSnapTo(PointType t, bool s)
  *  \param t Point type.
  *  \return true if snapper will snap this type of point, otherwise false.
  */
-bool Inkscape::Snapper::getSnapTo(PointType t) const
+bool Inkscape::Snapper::getSnapFrom(PointType t) const
 {
-    return (_snap_to & t);
+    return (_snap_from & t);
 }
 
 /**
@@ -90,7 +90,7 @@ void Inkscape::Snapper::setEnabled(bool s)
  *  \return Snapped point.
  */
 
-Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType t,
+Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType const &t,
                                                    NR::Point const &p,
                                                    SPItem const *it) const
 {
@@ -111,15 +111,15 @@ Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType t,
  *  \return Snapped point.
  */
 
-Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType t,
+Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType const &t,
                                                    NR::Point const &p,
                                                    std::list<SPItem const *> const &it) const
 {
-    if (_enabled == false || getSnapTo(t) == false) {
+    if (_enabled == false || getSnapFrom(t) == false) {
         return SnappedPoint(p, NR_HUGE);
     }
 
-    return _doFreeSnap(p, it);
+    return _doFreeSnap(t, p, it);
 }
 
 
@@ -136,7 +136,7 @@ Inkscape::SnappedPoint Inkscape::Snapper::freeSnap(PointType t,
  *  \return Snapped point.
  */
 
-Inkscape::SnappedPoint Inkscape::Snapper::constrainedSnap(PointType t,
+Inkscape::SnappedPoint Inkscape::Snapper::constrainedSnap(PointType const &t,
                                                           NR::Point const &p,
                                                           ConstraintLine const &c,
                                                           SPItem const *it) const
@@ -158,16 +158,16 @@ Inkscape::SnappedPoint Inkscape::Snapper::constrainedSnap(PointType t,
  *  \return Snapped point.
  */
 
-Inkscape::SnappedPoint Inkscape::Snapper::constrainedSnap(PointType t,
+Inkscape::SnappedPoint Inkscape::Snapper::constrainedSnap(PointType const &t,
                                                           NR::Point const &p,
                                                           ConstraintLine const &c,
                                                           std::list<SPItem const *> const &it) const
 {
-    if (_enabled == false || getSnapTo(t) == false) {
+    if (_enabled == false || getSnapFrom(t) == false) {
         return SnappedPoint(p, NR_HUGE);
     }
 
-    return _doConstrainedSnap(p, c, it);
+    return _doConstrainedSnap(t, p, c, it);
 }
 
 /*
index 25e345305e7e4a2bf0e199745a0fa7f2181dbc3e..1440f64c7b44d53748c1d608834ae540d8ffe25e 100644 (file)
@@ -33,30 +33,28 @@ public:
 
     /// Point types to snap.
     typedef int PointType;
-    static const PointType SNAP_POINT;
-    static const PointType BBOX_POINT;
+    static const PointType SNAPPOINT_NODE;
+    static const PointType SNAPPOINT_BBOX;
 
-    typedef std::pair<PointType, NR::Point> PointWithType;
-
-    void setSnapTo(PointType t, bool s);
+    void setSnapFrom(PointType t, bool s);
     void setDistance(::NR::Coord d);
 
-    bool getSnapTo(PointType t) const;
+    bool getSnapFrom(PointType t) const;
     ::NR::Coord getDistance() const;
 
     /**
     *  \return true if this Snapper will snap at least one kind of point.
     */
-    virtual bool ThisSnapperMightSnap() const {return (_enabled && _snap_to != 0);} // will likely be overridden by derived classes
+    virtual bool ThisSnapperMightSnap() const {return (_enabled && _snap_from != 0);} // will likely be overridden by derived classes
 
 
     void setEnabled(bool s);
 
-    SnappedPoint freeSnap(PointType t,
+    SnappedPoint freeSnap(PointType const &t,
                           NR::Point const &p,
                           SPItem const *it) const;
 
-    SnappedPoint freeSnap(PointType t,
+    SnappedPoint freeSnap(PointType const &t,
                           NR::Point const &p,
                           std::list<SPItem const *> const &it) const;
 
@@ -85,18 +83,18 @@ public:
         NR::Point _direction;
     };
 
-    SnappedPoint constrainedSnap(PointType t,
+    SnappedPoint constrainedSnap(PointType const &t,
                                  NR::Point const &p,
                                  ConstraintLine const &c,
                                  SPItem const *it) const;
 
-    SnappedPoint constrainedSnap(PointType t,
+    SnappedPoint constrainedSnap(PointType const &t,
                                  NR::Point const &p,
                                  ConstraintLine const &c,
                                  std::list<SPItem const *> const &it) const;
 protected:
     SPNamedView const *_named_view;
-    int _snap_to; ///< bitmap of point types that we will snap to
+    int _snap_from; ///< bitmap of point types that we will snap from
     bool _enabled; ///< true if this snapper is enabled, otherwise false
     
 private:
@@ -110,7 +108,8 @@ private:
      *  \param it Items that should not be snapped to.
      *  \return Snapped point.
      */
-    virtual SnappedPoint _doFreeSnap(NR::Point const &p,
+    virtual SnappedPoint _doFreeSnap(PointType const &t,
+                                                                NR::Point const &p,
                                      std::list<SPItem const *> const &it) const = 0;
 
     /**
@@ -123,7 +122,8 @@ private:
      *  \param it Items that should not be snapped to.
      *  \return Snapped point.
      */    
-    virtual SnappedPoint _doConstrainedSnap(NR::Point const &p,
+    virtual SnappedPoint _doConstrainedSnap(PointType const &t,
+                                                                               NR::Point const &p,
                                             ConstraintLine const &c,
                                             std::list<SPItem const *> const &it) const = 0;
     
index 52d2f1189d3b9c2be4fece48c51bd3a40274d31a..7667d07f111d22130247945a528b7327f3b77deb 100644 (file)
@@ -153,14 +153,8 @@ static void sp_namedview_build(SPObject *object, SPDocument *document, Inkscape:
     sp_object_read_attr(object, "inkscape:window-height");
     sp_object_read_attr(object, "inkscape:window-x");
     sp_object_read_attr(object, "inkscape:window-y");
-/*  sp_object_read_attr(object, "inkscape:grid-bbox");
-    sp_object_read_attr(object, "inkscape:guide-bbox");
-    sp_object_read_attr(object, "inkscape:object-bbox");
-    sp_object_read_attr(object, "inkscape:grid-points");
-    sp_object_read_attr(object, "inkscape:guide-points");
-    sp_object_read_attr(object, "inkscape:object-points");*/
-    sp_object_read_attr(object, "inkscape:object-paths");
-    sp_object_read_attr(object, "inkscape:object-nodes");
+    sp_object_read_attr(object, "inkscape:snap-bbox");
+    sp_object_read_attr(object, "inkscape:snap-nodes");
     sp_object_read_attr(object, "inkscape:current-layer");
     sp_object_read_attr(object, "inkscape:connector-spacing");
 
@@ -346,12 +340,12 @@ static void sp_namedview_set(SPObject *object, unsigned int key, const gchar *va
             nv->window_y = value ? atoi(value) : -1; // -1 means not set
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             break;
-    case SP_ATTR_INKSCAPE_OBJECT_PATHS:
-            nv->snap_manager.object.setSnapToPaths(value ? sp_str_to_bool(value) : FALSE);
+    case SP_ATTR_INKSCAPE_SNAP_BBOX:
+               nv->snap_manager.setSnapModeBBox(value ? sp_str_to_bool(value) : FALSE);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             break;
-    case SP_ATTR_INKSCAPE_OBJECT_NODES:
-            nv->snap_manager.object.setSnapToNodes(value ? sp_str_to_bool(value) : FALSE);
+    case SP_ATTR_INKSCAPE_SNAP_NODES:
+            nv->snap_manager.setSnapModeNodes(value ? sp_str_to_bool(value) : FALSE);
             object->requestModified(SP_OBJECT_MODIFIED_FLAG);
             break;
        case SP_ATTR_INKSCAPE_CURRENT_LAYER:
index 1fcbc29a9eb9927aa10b110c16613ce3dc5c1b41..82ae8d351982900604ba8958769e73ac186fa55f 100644 (file)
@@ -264,7 +264,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
 
                 SnapManager const &m = desktop->namedview->snap_manager;
-                sc->center = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, sc->center, sc->item).getPoint();
+                sc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, sc->center, sc->item).getPoint();
 
                 sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                     ( GDK_KEY_PRESS_MASK |
@@ -292,7 +292,7 @@ sp_spiral_context_root_handler(SPEventContext *event_context, GdkEvent *event)
                 NR::Point motion_dt(event_context->desktop->w2d(motion_w));
                 
                 SnapManager const &m = desktop->namedview->snap_manager;
-                motion_dt = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, motion_dt, sc->item).getPoint();
+                motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, sc->item).getPoint();
             
                 sp_spiral_drag(sc, motion_dt, event->motion.state);
                 ret = TRUE;
@@ -433,7 +433,7 @@ sp_spiral_drag(SPSpiralContext *sc, NR::Point p, guint state)
     NR::Point const p0 = sp_desktop_dt2root_xy_point(desktop, sc->center);
     NR::Point p1 = sp_desktop_dt2root_xy_point(desktop, p);
     SnapManager const &m = desktop->namedview->snap_manager;
-    p1 = m.freeSnap(Inkscape::Snapper::SNAP_POINT, p1, sc->item).getPoint();
+    p1 = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1, sc->item).getPoint();
 
     SPSpiral *spiral = SP_SPIRAL(sc->item);
 
index bb002ec893215ff57d463aa650336be6ab7f4d36..cd33391a4d7273d742798185894520e9cebdfe9f 100644 (file)
@@ -276,7 +276,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
             sc->center = Inkscape::setup_for_drag_start(desktop, event_context, event);
 
             SnapManager const &m = desktop->namedview->snap_manager;
-            sc->center = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, sc->center, sc->item).getPoint();
+            sc->center = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, sc->center, sc->item).getPoint();
 
             sp_canvas_item_grab(SP_CANVAS_ITEM(desktop->acetate),
                                 GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
@@ -302,7 +302,7 @@ static gint sp_star_context_root_handler(SPEventContext *event_context, GdkEvent
             NR::Point motion_dt(event_context->desktop->w2d(motion_w));
             
             SnapManager const &m = desktop->namedview->snap_manager;
-            motion_dt = m.freeSnap(Inkscape::Snapper::BBOX_POINT | Inkscape::Snapper::SNAP_POINT, motion_dt, sc->item).getPoint();
+            motion_dt = m.freeSnap(Inkscape::Snapper::SNAPPOINT_BBOX | Inkscape::Snapper::SNAPPOINT_NODE, motion_dt, sc->item).getPoint();
             
             sp_star_drag (sc, motion_dt, event->motion.state);
             ret = TRUE;
@@ -444,7 +444,7 @@ static void sp_star_drag(SPStarContext *sc, NR::Point p, guint state)
 
     /* Snap corner point with no constraints */
     SnapManager const &m = desktop->namedview->snap_manager;
-    p1 = m.freeSnap(Inkscape::Snapper::SNAP_POINT, p1, sc->item).getPoint();
+    p1 = m.freeSnap(Inkscape::Snapper::SNAPPOINT_NODE, p1, sc->item).getPoint();
 
     SPStar *star = SP_STAR(sc->item);
 
index 0817b06aba7418c8e5cb774cf6fcf2ed1fdd5f4c..3a86238526e9901b7d33b4f48cce27356e9648c2 100644 (file)
@@ -265,13 +265,12 @@ void
 DocumentProperties::build_snap()
 {
     _page_snap.show();
-
-    _rcbsnop.init (_("Snap to object _paths"),
-                _("Snap to other object paths"),
-                "inkscape:object-paths", _wr);
-    _rcbsnon.init (_("Snap to object _nodes"),
-                _("Snap to other object nodes"),
-                "inkscape:object-nodes", _wr);
+       _rcbsnbb.init (_("Snap bounding _boxes"),
+                _("Snap bounding box corners to grid lines, to guides, and to other bounding boxes"),
+                "inkscape:snap-bbox", _wr);
+    _rcbsnn.init (_("Snap _nodes"),
+                _("Snap nodes to grid lines, to guides, to paths, and to other nodes"),
+                "inkscape:snap-nodes", _wr);
     _rsu_sno.init (_("Snap s_ensitivity:"), _("Always snap"),
                   _("Snapping distance, in screen pixels, for snapping to objects"),
                   _("If set, objects snap to the nearest object, regardless of distance"),
@@ -284,6 +283,8 @@ DocumentProperties::build_snap()
                 _("Snapping distance, in screen pixels, for snapping to guides"),
                 _("If set, objects snap to the nearest guide, regardless of distance"),
                 "guidetolerance", _wr);
+    Gtk::Label *label_g = manage (new Gtk::Label);
+    label_g->set_markup (_("<b>General</b>"));
     Gtk::Label *label_o = manage (new Gtk::Label);
     label_o->set_markup (_("<b>Object Snapping</b>"));
     Gtk::Label *label_gr = manage (new Gtk::Label);
@@ -293,16 +294,17 @@ DocumentProperties::build_snap()
 
     Gtk::Widget *const array[] =
     {
+        label_g,            0,
+        0,                  _rcbsnbb._button,
+        0,                  _rcbsnn._button,        
         label_o,            0,
-        0,                  _rcbsnop._button,
-        0,                  _rcbsnon._button,
         0,                  _rsu_sno._vbox,
         0, 0,
         label_gr,           0,
         0,                  _rsu_sn._vbox,
         0, 0,
-        label_gu,         0,
-        0,                _rsu_gusn._vbox,
+        label_gu,              0,
+        0,                     _rsu_gusn._vbox,
     };
 
     attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
@@ -413,8 +415,8 @@ DocumentProperties::update()
     _rcp_hgui.setRgba32 (nv->guidehicolor);
 
     //-----------------------------------------------------------snap
-    _rcbsnop.setActive (nv->snap_manager.object.getSnapToPaths());
-    _rcbsnon.setActive (nv->snap_manager.object.getSnapToNodes());
+    _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
+    _rcbsnn.setActive (nv->snap_manager.getSnapModeNodes());
     _rsu_sno.setValue (nv->objecttolerance);
 
     _rsu_sn.setValue (nv->gridtolerance);
index 65fd294179858085f24c8450298569d7ae05d71f..f405e71a3642ee4a3439926b3a9caf050bb6ddb6 100644 (file)
@@ -73,7 +73,7 @@ protected:
     RegisteredUnitMenu    _rum_gusn;
     RegisteredColorPicker _rcp_gui, _rcp_hgui;
     //---------------------------------------------------------------
-    RegisteredCheckButton _rcbsnop, _rcbsnon;
+    RegisteredCheckButton _rcbsnbb, _rcbsnn;
     RegisteredUnitMenu    _rumso;
     ToleranceSlider       _rsu_sno, _rsu_sn, _rsu_gusn;
     RegisteredRadioButtonPair _rrb_pix;