diff options
| author | Jabier Arraiza Cenoz <jabier.arraiza@marker.es> | 2015-06-01 21:47:04 +0000 |
|---|---|---|
| committer | Jabiertxof <jtx@jtx.marker.es> | 2015-06-01 21:47:04 +0000 |
| commit | 6c85e7bc3b136ad5f831a4c289e04fdbe7451297 (patch) | |
| tree | a026eaf58deb09da7b04db6a266dfb7516f21c9a /src/snap.cpp | |
| parent | opening kaleidscope (diff) | |
| parent | Mark user-visible messages for translation (diff) | |
| download | inkscape-6c85e7bc3b136ad5f831a4c289e04fdbe7451297.tar.gz inkscape-6c85e7bc3b136ad5f831a4c289e04fdbe7451297.zip | |
update to trunk
(bzr r13708.1.29)
Diffstat (limited to 'src/snap.cpp')
| -rw-r--r-- | src/snap.cpp | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/src/snap.cpp b/src/snap.cpp index 96b5ab53c..5a308777c 100644 --- a/src/snap.cpp +++ b/src/snap.cpp @@ -43,7 +43,7 @@ SnapManager::SnapManager(SPNamedView const *v) : object(this, 0), snapprefs(), _named_view(v), - _rotation_center_source_items(NULL), + _rotation_center_source_items(std::vector<SPItem*>()), _guide_to_ignore(NULL), _desktop(NULL), _snapindicator(true), @@ -121,7 +121,8 @@ void SnapManager::freeSnapReturnByRef(Geom::Point &p, } Inkscape::SnappedPoint SnapManager::freeSnap(Inkscape::SnapCandidatePoint const &p, - Geom::OptRect const &bbox_to_snap) const + Geom::OptRect const &bbox_to_snap, + bool to_paths_only) const { if (!someSnapperMightSnap()) { return Inkscape::SnappedPoint(p, Inkscape::SNAPTARGET_UNDEFINED, Geom::infinity(), 0, false, false, false); @@ -134,16 +135,16 @@ Inkscape::SnappedPoint SnapManager::freeSnap(Inkscape::SnapCandidatePoint const (*i)->freeSnap(isr, p, bbox_to_snap, &_items_to_ignore, _unselected_nodes); } - return findBestSnap(p, isr, false); + return findBestSnap(p, isr, false, false, to_paths_only); } -void SnapManager::preSnap(Inkscape::SnapCandidatePoint const &p) +void SnapManager::preSnap(Inkscape::SnapCandidatePoint const &p, bool to_paths_only) { // setup() must have been called before calling this method! if (_snapindicator) { _snapindicator = false; // prevent other methods from drawing a snap indicator; we want to control this here - Inkscape::SnappedPoint s = freeSnap(p); + Inkscape::SnappedPoint s = freeSnap(p, Geom::OptRect(), to_paths_only); g_assert(_desktop != NULL); if (s.getSnapped()) { _desktop->snapindicator->set_new_snaptarget(s, true); @@ -855,7 +856,8 @@ Inkscape::SnappedPoint SnapManager::constrainedSnapRotate(std::vector<Inkscape:: Inkscape::SnappedPoint SnapManager::findBestSnap(Inkscape::SnapCandidatePoint const &p, IntermSnapResults const &isr, bool constrained, - bool allowOffScreen) const + bool allowOffScreen, + bool to_path_only) const { g_assert(_desktop != NULL); @@ -966,6 +968,30 @@ Inkscape::SnappedPoint SnapManager::findBestSnap(Inkscape::SnapCandidatePoint co } } + // Filter out all snap targets that do NOT include a path; this is useful when we try to insert + // a node in a path (on doubleclick in the node tool). We don't want to change the shape of the + // path, so the snapped point must be on a path, and not e.g. on a grid intersection + if (to_path_only) { + std::list<Inkscape::SnappedPoint>::iterator i = sp_list.begin(); + + while (i != sp_list.end()) { + Inkscape::SnapTargetType t = (*i).getTarget(); + if (t == Inkscape::SNAPTARGET_LINE_MIDPOINT || + t == Inkscape::SNAPTARGET_PATH || + t == Inkscape::SNAPTARGET_PATH_PERPENDICULAR || + t == Inkscape::SNAPTARGET_PATH_TANGENTIAL || + t == Inkscape::SNAPTARGET_PATH_INTERSECTION || + t == Inkscape::SNAPTARGET_PATH_GUIDE_INTERSECTION || + t == Inkscape::SNAPTARGET_PATH_CLIP || + t == Inkscape::SNAPTARGET_PATH_MASK || + t == Inkscape::SNAPTARGET_ELLIPSE_QUADRANT_POINT) { + ++i; + } else { + i = sp_list.erase(i); + } + } + } + // now let's see which snapped point gets a thumbs up Inkscape::SnappedPoint bestSnappedPoint(p.getPoint()); // std::cout << "Finding the best snap..." << std::endl; @@ -1013,7 +1039,7 @@ void SnapManager::setup(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); } void SnapManager::setup(SPDesktop const *desktop, @@ -1031,7 +1057,7 @@ void SnapManager::setup(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); } /// Setup, taking the list of items to ignore from the desktop's selection. @@ -1049,13 +1075,13 @@ void SnapManager::setupIgnoreSelection(SPDesktop const *desktop, _snapindicator = snapindicator; _unselected_nodes = unselected_nodes; _guide_to_ignore = guide_to_ignore; - _rotation_center_source_items = NULL; + _rotation_center_source_items.clear(); _items_to_ignore.clear(); Inkscape::Selection *sel = _desktop->selection; - GSList const *items = sel->itemList(); - for (GSList *i = const_cast<GSList*>(items); i; i = i->next) { - _items_to_ignore.push_back(static_cast<SPItem const *>(i->data)); + std::vector<SPItem*> const items = sel->itemList(); + for (std::vector<SPItem*>::const_iterator i=items.begin();i!=items.end();i++) { + _items_to_ignore.push_back(*i); } } |
