From b28c4e3da388087b108e7a5749d75668afcd2d58 Mon Sep 17 00:00:00 2001 From: dvlierop2 Date: Sat, 28 Jul 2007 15:47:49 +0000 Subject: [PATCH] 1) Changes to snapping preferences dialog 2) Strict snapping implemented, i.e. bbox only to bbox and nodes only to paths/nodes 3) Renaming of some constants to improve readability --- src/arc-context.cpp | 4 +- src/attributes.cpp | 10 +-- src/attributes.h | 10 +-- src/box3d-context.cpp | 6 +- src/connector-context.cpp | 2 +- src/context-fns.cpp | 12 +-- src/draw-context.cpp | 4 +- src/gradient-context.cpp | 2 +- src/gradient-drag.cpp | 2 +- src/guide-snapper.cpp | 2 +- src/line-snapper.cpp | 16 ++-- src/line-snapper.h | 12 +-- src/nodepath.cpp | 6 +- src/object-edit.cpp | 2 +- src/object-snapper.cpp | 116 ++++++++++++++++---------- src/object-snapper.h | 75 ++++++++++++----- src/pencil-context.cpp | 4 +- src/rect-context.cpp | 4 +- src/selection-chemistry.cpp | 2 +- src/seltrans.cpp | 32 +++---- src/snap.cpp | 29 +++++++ src/snap.h | 7 +- src/snapper.cpp | 32 +++---- src/snapper.h | 28 +++---- src/sp-namedview.cpp | 18 ++-- src/spiral-context.cpp | 6 +- src/star-context.cpp | 6 +- src/ui/dialog/document-properties.cpp | 28 ++++--- src/ui/dialog/document-properties.h | 2 +- 29 files changed, 283 insertions(+), 196 deletions(-) diff --git a/src/arc-context.cpp b/src/arc-context.cpp index 4a8d6b9d1..716c547dd 100644 --- a/src/arc-context.cpp +++ b/src/arc-context.cpp @@ -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); diff --git a/src/attributes.cpp b/src/attributes.cpp index 025f1991b..245529e61 100644 --- a/src/attributes.cpp +++ b/src/attributes.cpp @@ -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"}, diff --git a/src/attributes.h b/src/attributes.h index c7f1fb71e..bb6962304 100644 --- a/src/attributes.h +++ b/src/attributes.h @@ -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, diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp index ada272acd..4358d56dd 100644 --- a/src/box3d-context.cpp +++ b/src/box3d-context.cpp @@ -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); diff --git a/src/connector-context.cpp b/src/connector-context.cpp index 89d38bace..195272fa2 100644 --- a/src/connector-context.cpp +++ b/src/connector-context.cpp @@ -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); diff --git a/src/context-fns.cpp b/src/context-fns.cpp index 15138a10b..8a131b081 100644 --- a/src/context-fns.cpp +++ b/src/context-fns.cpp @@ -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]); diff --git a/src/draw-context.cpp b/src/draw-context.cpp index 30b2e612c..6742ddaf3 100644 --- a/src/draw-context.cpp +++ b/src/draw-context.cpp @@ -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 * diff --git a/src/gradient-context.cpp b/src/gradient-context.cpp index e9192652a..6798a2feb 100644 --- a/src/gradient-context.cpp +++ b/src/gradient-context.cpp @@ -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; } diff --git a/src/gradient-drag.cpp b/src/gradient-drag.cpp index 5801489fe..f4070079b 100644 --- a/src/gradient-drag.cpp +++ b/src/gradient-drag.cpp @@ -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); diff --git a/src/guide-snapper.cpp b/src/guide-snapper.cpp index 1e4eb02d8..decfaf3cf 100644 --- a/src/guide-snapper.cpp +++ b/src/guide-snapper.cpp @@ -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); } /* diff --git a/src/line-snapper.cpp b/src/line-snapper.cpp index a2c6b944b..4c886fea5 100644 --- a/src/line-snapper.cpp +++ b/src/line-snapper.cpp @@ -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 const &it) const +Inkscape::SnappedPoint Inkscape::LineSnapper::_doFreeSnap(Inkscape::Snapper::PointType const &t, + NR::Point const &p, + std::list 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 const &it) const +Inkscape::SnappedPoint Inkscape::LineSnapper::_doConstrainedSnap(Inkscape::Snapper::PointType const &t, + NR::Point const &p, + ConstraintLine const &c, + std::list const &it) const { Inkscape::SnappedPoint s = SnappedPoint(p, NR_HUGE); diff --git a/src/line-snapper.h b/src/line-snapper.h index 2816b2ec0..f6b467520 100644 --- a/src/line-snapper.h +++ b/src/line-snapper.h @@ -25,12 +25,14 @@ protected: typedef std::list > LineList; private: - SnappedPoint _doFreeSnap(NR::Point const &p, - std::list const &it) const; + SnappedPoint _doFreeSnap(Inkscape::Snapper::PointType const &t, + NR::Point const &p, + std::list const &it) const; - SnappedPoint _doConstrainedSnap(NR::Point const &p, - ConstraintLine const &c, - std::list const &it) const; + SnappedPoint _doConstrainedSnap(Inkscape::Snapper::PointType const &t, + NR::Point const &p, + ConstraintLine const &c, + std::list const &it) const; /** * \param p Point that we are trying to snap. diff --git a/src/nodepath.cpp b/src/nodepath.cpp index 4131c8cca..28c845492 100644 --- a/src/nodepath.cpp +++ b/src/nodepath.cpp @@ -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); diff --git a/src/object-edit.cpp b/src/object-edit.cpp index 487caa09c..6eff465f8 100644 --- a/src/object-edit.cpp +++ b/src/object-edit.cpp @@ -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(); } diff --git a/src/object-snapper.cpp b/src/object-snapper.cpp index 88e143aba..1a50841c4 100644 --- a/src/object-snapper.cpp +++ b/src/object-snapper.cpp @@ -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& 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 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::const_iterator i = cand.begin(); i != cand.end(); i++) { @@ -110,23 +116,31 @@ void Inkscape::ObjectSnapper::_snapNodes(Inkscape::SnappedPoint &s, std::list 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 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 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::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 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::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 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 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 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::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 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 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); } diff --git a/src/object-snapper.h b/src/object-snapper.h index 47ac14545..6556b0a24 100644 --- a/src/object-snapper.h +++ b/src/object-snapper.h @@ -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 const &it) const; + SnappedPoint _doFreeSnap(Inkscape::Snapper::PointType const &t, + NR::Point const &p, + std::list const &it) const; - SnappedPoint _doConstrainedSnap(NR::Point const &p, - ConstraintLine const &c, - std::list const &it) const; + SnappedPoint _doConstrainedSnap(Inkscape::Snapper::PointType const &t, + NR::Point const &p, + ConstraintLine const &c, + std::list const &it) const; void _findCandidates(std::list& c, - SPObject* r, - std::list const &it, - NR::Point const &p) const; + SPObject* r, + std::list const &it, + NR::Point const &p) const; + + void _snapNodes(Inkscape::Snapper::PointType const &t, + Inkscape::SnappedPoint &s, + NR::Point const &p, + std::list const &cand) const; + + void _snapPaths(Inkscape::Snapper::PointType const &t, + Inkscape::SnappedPoint &s, + NR::Point const &p, + std::list const &cand) const; - void _snapNodes(Inkscape::SnappedPoint &s, NR::Point const &p, std::list const &cand) const; - void _snapPaths(Inkscape::SnappedPoint &s, NR::Point const &p, std::list 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; }; } diff --git a/src/pencil-context.cpp b/src/pencil-context.cpp index d86b83c01..5ce9a171e 100644 --- a/src/pencil-context.cpp +++ b/src/pencil-context.cpp @@ -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); diff --git a/src/rect-context.cpp b/src/rect-context.cpp index c8f9bf0f1..329f3910d 100644 --- a/src/rect-context.cpp +++ b/src/rect-context.cpp @@ -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); diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 188ace06b..8e916193b 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -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); } diff --git a/src/seltrans.cpp b/src/seltrans.cpp index 1661bdc60..465813ae0 100644 --- a/src/seltrans.cpp +++ b/src/seltrans.cpp @@ -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 bb = m.constrainedSnapScale(Snapper::BBOX_POINT, + std::pair bb = m.constrainedSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, it, Snapper::ConstraintLine(_origin_for_bboxpoints, cv), s, _origin_for_bboxpoints); - std::pair sn = m.constrainedSnapScale(Snapper::SNAP_POINT, + std::pair 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 bb = m.freeSnapScale(Snapper::BBOX_POINT, + std::pair bb = m.freeSnapScale(Snapper::SNAPPOINT_BBOX, _bbox_points, it, s, _origin_for_bboxpoints); - std::pair sn = m.freeSnapScale(Snapper::SNAP_POINT, + std::pair 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 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 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 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 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 bb = m.freeSnapSkew(Inkscape::Snapper::BBOX_POINT, + std::pair bb = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_BBOX, _bbox_points, std::list(), skew[dim_a], _origin_for_bboxpoints, dim_b); - std::pair sn = m.freeSnapSkew(Inkscape::Snapper::SNAP_POINT, + std::pair sn = m.freeSnapSkew(Inkscape::Snapper::SNAPPOINT_NODE, _snap_points, std::list(), 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)); } diff --git a/src/snap.cpp b/src/snap.cpp index 3dda92ecb..218cbb029 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -17,6 +17,7 @@ #include "sp-namedview.h" #include "snap.h" + #include #include #include @@ -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. diff --git a/src/snap.h b/src/snap.h index e0217948f..527947e10 100644 --- a/src/snap.h +++ b/src/snap.h @@ -52,7 +52,7 @@ public: NR::Point const &p, std::list const &it) const; - Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t, + Inkscape::SnappedPoint freeSnap( Inkscape::Snapper::PointType t, NR::Point const &p, std::list 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; diff --git a/src/snapper.cpp b/src/snapper.cpp index 390e0957e..7a82fe1d4 100644 --- a/src/snapper.cpp +++ b/src/snapper.cpp @@ -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 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 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); } /* diff --git a/src/snapper.h b/src/snapper.h index 25e345305..1440f64c7 100644 --- a/src/snapper.h +++ b/src/snapper.h @@ -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 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 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 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 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 const &it) const = 0; diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 52d2f1189..7667d07f1 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -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: diff --git a/src/spiral-context.cpp b/src/spiral-context.cpp index 1fcbc29a9..82ae8d351 100644 --- a/src/spiral-context.cpp +++ b/src/spiral-context.cpp @@ -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); diff --git a/src/star-context.cpp b/src/star-context.cpp index bb002ec89..cd33391a4 100644 --- a/src/star-context.cpp +++ b/src/star-context.cpp @@ -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); diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 0817b06ab..3a8623852 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -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 (_("General")); Gtk::Label *label_o = manage (new Gtk::Label); label_o->set_markup (_("Object Snapping")); 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); diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index 65fd29417..f405e71a3 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -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; -- 2.30.2