diff --git a/src/selection.cpp b/src/selection.cpp
index 9b9b484851595c137eb6bb8604e778c33d0153ae..ed8a9d57b86034dfcaf4c36915bace17a5ff3671 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"
Persp3D *persp = box3d_get_perspective(box);
std::map<Persp3D *, unsigned int>::iterator p = _persps.find(persp);
if (p == _persps.end()) {
- g_print ("Warning! Trying to remove unselected perspective from selection!\n");
+ //g_print ("Warning! Trying to remove unselected perspective from selection!\n");
return;
}
if ((*p).second > 1) {
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;
}
-// TODO: This should be replaces by a proper 2geom function
-inline Geom::Rect union_bounds_2geom(boost::optional<Geom::Rect> const & a, Geom::Rect const &b) {
- if (a) {
- return union_bounds_2geom(*a, b);
- } else {
- return b;
- }
-}
-
-boost::optional<Geom::Rect> Selection::bounds_2geom(SPItem::BBoxType type) const
-{
- GSList const *items = const_cast<Selection *>(this)->itemList();
-
- boost::optional<NR::Rect> bbox;
- for ( GSList const *i = items ; i != NULL ; i = i->next ) {
- bbox = union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type));
- }
- // TODO: eliminate this conversion after the switch to 2geom
- boost::optional<Geom::Rect> bbox_ret;
- if (bbox) {
- bbox_ret = to_2geom(*bbox);
- }
- return bbox_ret;
-}
-
NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const {
g_return_val_if_fail (bbox != NULL, NULL);
@@ -439,9 +415,9 @@ 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 */
return first->getCenter();
}
}
- boost::optional<NR::Rect> bbox = bounds();
+ Geom::OptRect bbox = bounds();
if (bbox) {
- return to_2geom(bounds()->midpoint());
+ return bounds()->midpoint();
} else {
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;
}
}