diff --git a/src/selection.cpp b/src/selection.cpp
index 65ec9941d1cb70cbde2da75aff9f2be873b2597e..4d92a18df77948f7de0620a8609566eb9e33075e 100644 (file)
--- a/src/selection.cpp
+++ b/src/selection.cpp
#include "desktop-handles.h"
#include "document.h"
#include "selection.h"
+#include "helper/recthull.h"
#include "xml/repr.h"
#include "sp-shape.h"
}
void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) {
- g_print ("Selection::add()\n");
g_return_if_fail(obj != NULL);
g_return_if_fail(SP_IS_OBJECT(obj));
}
void Selection::remove(SPObject *obj) {
- g_print ("Selection::remove()\n");
g_return_if_fail(obj != NULL);
g_return_if_fail(SP_IS_OBJECT(obj));
g_return_if_fail(includes(obj));
return bbox;
}
-boost::optional<NR::Rect> Selection::bounds(SPItem::BBoxType type) const
+Geom::OptRect Selection::bounds(SPItem::BBoxType type) const
{
GSList const *items = const_cast<Selection *>(this)->itemList();
- boost::optional<NR::Rect> bbox;
+ Geom::OptRect bbox;
for ( GSList const *i = items ; i != NULL ; i = i->next ) {
- bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type));
+ bbox = unify(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type));
}
return bbox;
}
@@ -416,69 +415,74 @@ NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const {
return bbox;
}
-boost::optional<NR::Rect> Selection::boundsInDocument(SPItem::BBoxType type) const {
+Geom::OptRect Selection::boundsInDocument(SPItem::BBoxType type) const {
NRRect r;
- return boundsInDocument(&r, type)->upgrade();
+ return to_2geom(boundsInDocument(&r, type)->upgrade());
}
/** Extract the position of the center from the first selected object */
-boost::optional<NR::Point> Selection::center() const {
+boost::optional<Geom::Point> Selection::center() const {
GSList *items = (GSList *) const_cast<Selection *>(this)->itemList();
- NR::Point center;
+ Geom::Point center;
if (items) {
SPItem *first = reinterpret_cast<SPItem*>(g_slist_last(items)->data); // from the first item in selection
if (first->isCenterSet()) { // only if set explicitly
return first->getCenter();
}
}
- boost::optional<NR::Rect> bbox = bounds();
+ Geom::OptRect bbox = bounds();
if (bbox) {
return bounds()->midpoint();
} else {
- return boost::optional<NR::Point>();
+ return boost::optional<Geom::Point>();
}
}
/**
* Compute the list of points in the selection that are to be considered for snapping.
*/
-std::vector<NR::Point> Selection::getSnapPoints(bool includeItemCenter) const {
+std::vector<std::pair<Geom::Point, int> > Selection::getSnapPoints(SnapPreferences const *snapprefs) const {
GSList const *items = const_cast<Selection *>(this)->itemList();
- std::vector<NR::Point> p;
+
+ SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs
+ snapprefs_dummy.setIncludeItemCenter(false); // locally disable snapping to the item center
+
+ std::vector<std::pair<Geom::Point, int> > p;
for (GSList const *iter = items; iter != NULL; iter = iter->next) {
SPItem *this_item = SP_ITEM(iter->data);
- sp_item_snappoints(this_item, false, SnapPointsIter(p));
+ sp_item_snappoints(this_item, false, p, &snapprefs_dummy);
+
//Include the transformation origin for snapping
- //For a group only the group's origin is considered
- if (includeItemCenter) {
- p.push_back(this_item->getCenter());
- }
+ //For a selection or group only the overall origin is considered
+ if (snapprefs != NULL && snapprefs->getIncludeItemCenter()) {
+ p.push_back(std::make_pair(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER));
+ }
}
return p;
}
-std::vector<NR::Point> Selection::getSnapPointsConvexHull() const {
+std::vector<std::pair<Geom::Point, int> > Selection::getSnapPointsConvexHull(SnapPreferences const *snapprefs) const {
GSList const *items = const_cast<Selection *>(this)->itemList();
- std::vector<NR::Point> p;
+ std::vector<std::pair<Geom::Point, int> > p;
for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- sp_item_snappoints(SP_ITEM(iter->data), false, SnapPointsIter(p));
+ sp_item_snappoints(SP_ITEM(iter->data), false, p, snapprefs);
}
- std::vector<NR::Point> pHull;
+ std::vector<std::pair<Geom::Point, int> > pHull;
if (!p.empty()) {
- std::vector<NR::Point>::iterator i;
- NR::ConvexHull cvh(p.front());
+ std::vector<std::pair<Geom::Point, int> >::iterator i;
+ Geom::RectHull cvh((p.front()).first);
for (i = p.begin(); i != p.end(); i++) {
// these are the points we get back
- cvh.add(*i);
+ cvh.add((*i).first);
}
- boost::optional<NR::Rect> rHull = cvh.bounds();
+ Geom::OptRect rHull = cvh.bounds();
if (rHull) {
for ( unsigned i = 0 ; i < 4 ; ++i ) {
- pHull.push_back(rHull->corner(i));
+ pHull.push_back(std::make_pair(rHull->corner(i), SNAPSOURCE_CONVEX_HULL_CORNER));
}
}
}
}
guint Selection::numberOfLayers() {
- GSList const *items = const_cast<Selection *>(this)->itemList();
- GSList *layers = NULL;
- for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- SPObject *layer = desktop()->layerForObject(SP_OBJECT(iter->data));
- if (g_slist_find (layers, layer) == NULL) {
- layers = g_slist_prepend (layers, layer);
- }
- }
- guint ret = g_slist_length (layers);
- g_slist_free (layers);
- return ret;
+ GSList const *items = const_cast<Selection *>(this)->itemList();
+ GSList *layers = NULL;
+ for (GSList const *iter = items; iter != NULL; iter = iter->next) {
+ SPObject *layer = desktop()->layerForObject(SP_OBJECT(iter->data));
+ if (g_slist_find (layers, layer) == NULL) {
+ layers = g_slist_prepend (layers, layer);
+ }
+ }
+ guint ret = g_slist_length (layers);
+ g_slist_free (layers);
+ return ret;
}
guint Selection::numberOfParents() {
- GSList const *items = const_cast<Selection *>(this)->itemList();
- GSList *parents = NULL;
- for (GSList const *iter = items; iter != NULL; iter = iter->next) {
- SPObject *parent = SP_OBJECT_PARENT(iter->data);
- if (g_slist_find (parents, parent) == NULL) {
- parents = g_slist_prepend (parents, parent);
- }
- }
- guint ret = g_slist_length (parents);
- g_slist_free (parents);
- return ret;
+ GSList const *items = const_cast<Selection *>(this)->itemList();
+ GSList *parents = NULL;
+ for (GSList const *iter = items; iter != NULL; iter = iter->next) {
+ SPObject *parent = SP_OBJECT_PARENT(iter->data);
+ if (g_slist_find (parents, parent) == NULL) {
+ parents = g_slist_prepend (parents, parent);
+ }
+ }
+ guint ret = g_slist_length (parents);
+ g_slist_free (parents);
+ return ret;
}
}