X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fselection.cpp;h=ed8a9d57b86034dfcaf4c36915bace17a5ff3671;hb=fce046713c4cb905f38bf489cc4a73af425f3037;hp=9b9b484851595c137eb6bb8604e778c33d0153ae;hpb=5c6771ad614c8c281c8fcf8f6c1aa727e981a823;p=inkscape.git diff --git a/src/selection.cpp b/src/selection.cpp index 9b9b48485..ed8a9d57b 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -24,6 +24,7 @@ #include "desktop-handles.h" #include "document.h" #include "selection.h" +#include "helper/recthull.h" #include "xml/repr.h" #include "sp-shape.h" @@ -223,7 +224,7 @@ void Selection::remove_box_perspective(SPBox3D *box) { Persp3D *persp = box3d_get_perspective(box); std::map::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) { @@ -382,42 +383,17 @@ NRRect *Selection::bounds(NRRect *bbox, SPItem::BBoxType type) const return bbox; } -boost::optional Selection::bounds(SPItem::BBoxType type) const +Geom::OptRect Selection::bounds(SPItem::BBoxType type) const { GSList const *items = const_cast(this)->itemList(); - boost::optional 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 const & a, Geom::Rect const &b) { - if (a) { - return union_bounds_2geom(*a, b); - } else { - return b; - } -} - -boost::optional Selection::bounds_2geom(SPItem::BBoxType type) const -{ - GSList const *items = const_cast(this)->itemList(); - - boost::optional 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 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 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 */ @@ -454,9 +430,9 @@ boost::optional Selection::center() const { return first->getCenter(); } } - boost::optional bbox = bounds(); + Geom::OptRect bbox = bounds(); if (bbox) { - return to_2geom(bounds()->midpoint()); + return bounds()->midpoint(); } else { return boost::optional(); } @@ -465,43 +441,48 @@ boost::optional Selection::center() const { /** * Compute the list of points in the selection that are to be considered for snapping. */ -std::vector Selection::getSnapPoints(bool includeItemCenter) const { +std::vector > Selection::getSnapPoints(SnapPreferences const *snapprefs) const { GSList const *items = const_cast(this)->itemList(); - std::vector 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 > 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 Selection::getSnapPointsConvexHull() const { +std::vector > Selection::getSnapPointsConvexHull(SnapPreferences const *snapprefs) const { GSList const *items = const_cast(this)->itemList(); - std::vector p; + std::vector > 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 pHull; + std::vector > pHull; if (!p.empty()) { - std::vector::iterator i; - NR::ConvexHull cvh(p.front()); + std::vector >::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 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)); } } } @@ -545,31 +526,31 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { } guint Selection::numberOfLayers() { - GSList const *items = const_cast(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(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(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(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; } }