summaryrefslogtreecommitdiffstats
path: root/src/snap.cpp
diff options
context:
space:
mode:
authorKrzysztof Kosi??ski <tweenk.pl@gmail.com>2010-01-10 00:46:28 +0000
committerKrzysztof KosiƄski <tweenk.pl@gmail.com>2010-01-10 00:46:28 +0000
commitb52865a71a9f83da9719a3ec5f50a4a2cd7cdace (patch)
tree6d8def69ad0aa28aa4414dc9d501707444a5419b /src/snap.cpp
parentImplement selection linear grow (diff)
downloadinkscape-b52865a71a9f83da9719a3ec5f50a4a2cd7cdace.tar.gz
inkscape-b52865a71a9f83da9719a3ec5f50a4a2cd7cdace.zip
* Implement node snapping.
* Fix minor bug in linear grow. * Add --fixes. * Move some node selection-related functions to ControlPointSelection. Fixed bugs: - https://launchpad.net/bugs/170561 - https://launchpad.net/bugs/171893 - https://launchpad.net/bugs/182585 - https://launchpad.net/bugs/446773 (bzr r8846.2.9)
Diffstat (limited to 'src/snap.cpp')
-rw-r--r--src/snap.cpp81
1 files changed, 28 insertions, 53 deletions
diff --git a/src/snap.cpp b/src/snap.cpp
index 545607889..558f61814 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -30,6 +30,7 @@
#include "inkscape.h"
#include "desktop.h"
+#include "selection.h"
#include "sp-guide.h"
#include "preferences.h"
#include "event-context.h"
@@ -206,29 +207,15 @@ Inkscape::SnappedPoint SnapManager::freeSnap(Inkscape::SnapPreferences::PointTyp
bool first_point,
Geom::OptRect const &bbox_to_snap) const
{
- if (!someSnapperMightSnap()) {
+ if (!someSnapperMightSnap()) {
return Inkscape::SnappedPoint(p, source_type, Inkscape::SNAPTARGET_UNDEFINED, NR_HUGE, 0, false, false);
}
- std::vector<SPItem const *> *items_to_ignore;
- if (_item_to_ignore) { // If we have only a single item to ignore
- // then build a list containing this single item;
- // This single-item list will prevail over any other _items_to_ignore list, should that exist
- items_to_ignore = new std::vector<SPItem const *>;
- items_to_ignore->push_back(_item_to_ignore);
- } else {
- items_to_ignore = _items_to_ignore;
- }
-
SnappedConstraints sc;
SnapperList const snappers = getSnappers();
for (SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); i++) {
- (*i)->freeSnap(sc, point_type, p, source_type, first_point, bbox_to_snap, items_to_ignore, _unselected_nodes);
- }
-
- if (_item_to_ignore) {
- delete items_to_ignore;
+ (*i)->freeSnap(sc, point_type, p, source_type, first_point, bbox_to_snap, &_items_to_ignore, _unselected_nodes);
}
return findBestSnap(p, source_type, sc, false);
@@ -368,17 +355,6 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapPreferences::P
return Inkscape::SnappedPoint(p, source_type, Inkscape::SNAPTARGET_UNDEFINED, NR_HUGE, 0, false, false);
}
- std::vector<SPItem const *> *items_to_ignore;
- if (_item_to_ignore) { // If we have only a single item to ignore
- // then build a list containing this single item;
- // This single-item list will prevail over any other _items_to_ignore list, should that exist
- items_to_ignore = new std::vector<SPItem const *>;
- items_to_ignore->push_back(_item_to_ignore);
- } else {
- items_to_ignore = _items_to_ignore;
- }
-
-
// First project the mouse pointer onto the constraint
Geom::Point pp = constraint.projection(p);
// Then try to snap the projected point
@@ -386,11 +362,7 @@ Inkscape::SnappedPoint SnapManager::constrainedSnap(Inkscape::SnapPreferences::P
SnappedConstraints sc;
SnapperList const snappers = getSnappers();
for (SnapperList::const_iterator i = snappers.begin(); i != snappers.end(); i++) {
- (*i)->constrainedSnap(sc, point_type, pp, source_type, first_point, bbox_to_snap, constraint, items_to_ignore);
- }
-
- if (_item_to_ignore) {
- delete items_to_ignore;
+ (*i)->constrainedSnap(sc, point_type, pp, source_type, first_point, bbox_to_snap, constraint, &_items_to_ignore);
}
return findBestSnap(pp, source_type, sc, true);
@@ -1033,22 +1005,7 @@ Inkscape::SnappedPoint SnapManager::findBestSnap(Geom::Point const &p,
return bestSnappedPoint;
}
-/**
- * \brief Prepare the snap manager for the actual snapping, which includes building a list of snap targets
- * to ignore and toggling the snap indicator
- *
- * There are two overloaded setup() methods, of which this one only allows for a single item to be ignored
- * whereas the other one will take a list of items to ignore
- *
- * \param desktop Reference to the desktop to which this snap manager is attached
- * \param snapindicator If true then a snap indicator will be displayed automatically (when enabled in the preferences)
- * \param item_to_ignore This item will not be snapped to, e.g. the item that is currently being dragged. This avoids "self-snapping"
- * \param unselected_nodes Stationary nodes of the path that is currently being edited in the node tool and
- * that can be snapped too. Nodes not in this list will not be snapped to, to avoid "self-snapping". Of each
- * unselected node both the position (Geom::Point) and the type (Inkscape::SnapTargetType) will be stored
- * \param guide_to_ignore Guide that is currently being dragged and should not be snapped to
- */
-
+/// Convenience shortcut when there is only one item to ignore
void SnapManager::setup(SPDesktop const *desktop,
bool snapindicator,
SPItem const *item_to_ignore,
@@ -1056,8 +1013,8 @@ void SnapManager::setup(SPDesktop const *desktop,
SPGuide *guide_to_ignore)
{
g_assert(desktop != NULL);
- _item_to_ignore = item_to_ignore;
- _items_to_ignore = NULL;
+ _items_to_ignore.clear();
+ _items_to_ignore.push_back(item_to_ignore);
_desktop = desktop;
_snapindicator = snapindicator;
_unselected_nodes = unselected_nodes;
@@ -1082,17 +1039,35 @@ void SnapManager::setup(SPDesktop const *desktop,
void SnapManager::setup(SPDesktop const *desktop,
bool snapindicator,
- std::vector<SPItem const *> &items_to_ignore,
+ std::vector<SPItem const *> const &items_to_ignore,
std::vector<std::pair<Geom::Point, int> > *unselected_nodes,
SPGuide *guide_to_ignore)
{
g_assert(desktop != NULL);
- _item_to_ignore = NULL;
- _items_to_ignore = &items_to_ignore;
+ _items_to_ignore = items_to_ignore;
+ _desktop = desktop;
+ _snapindicator = snapindicator;
+ _unselected_nodes = unselected_nodes;
+ _guide_to_ignore = guide_to_ignore;
+}
+
+/// Setup, taking the list of items to ignore from the desktop's selection.
+void SnapManager::setupIgnoreSelection(SPDesktop const *desktop,
+ bool snapindicator,
+ std::vector<std::pair<Geom::Point, int> > *unselected_nodes,
+ SPGuide *guide_to_ignore)
+{
_desktop = desktop;
_snapindicator = snapindicator;
_unselected_nodes = unselected_nodes;
_guide_to_ignore = guide_to_ignore;
+ _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));
+ }
}
SPDocument *SnapManager::getDocument() const