X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fselection.cpp;h=b71f27815214e527d8059792c352bdf5d21b5e4c;hb=8b9a820756fdf348239872236be2257f854e094a;hp=d39086e8c60e56174a42d6f697026307de4d7109;hpb=6e3576be211b59b7d8a9e7afe3493d961c053b75;p=inkscape.git diff --git a/src/selection.cpp b/src/selection.cpp index d39086e8c..b71f27815 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -27,6 +27,11 @@ #include "xml/repr.h" #include "sp-shape.h" +#include "sp-path.h" +#include "sp-item-group.h" +#include "box3d.h" +#include "box3d.h" +#include "persp3d.h" #include @@ -56,7 +61,7 @@ Selection::~Selection() { /* Handler for selected objects "modified" signal */ -void Selection::_schedule_modified(SPObject *obj, guint flags) { +void Selection::_schedule_modified(SPObject */*obj*/, guint flags) { if (!this->_idle) { /* Request handling to be run in _idle loop */ this->_idle = g_idle_add_full(SP_SELECTION_UPDATE_PRIORITY, GSourceFunc(&Selection::_emit_modified), this, NULL); @@ -156,6 +161,27 @@ void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) _emitChanged(persist_selection_context); } +void Selection::add_box_perspective(SPBox3D *box) { + Persp3D *persp = box3d_get_perspective(box); + std::map::iterator p = _persps.find(persp); + if (p != _persps.end()) { + (*p).second++; + } else { + _persps[persp] = 1; + } +} + +void Selection::add_3D_boxes_recursively(SPObject *obj) { + std::list boxes = box3d_extract_boxes(obj); + + for (std::list::iterator i = boxes.begin(); i != boxes.end(); ++i) { + SPBox3D *box = *i; + box3d_add_to_selection(box); + _3dboxes.push_back(box); + add_box_perspective(box); + } +} + void Selection::_add(SPObject *obj) { // unselect any of the item's ancestors and descendants which may be selected // (to prevent double-selection) @@ -164,6 +190,8 @@ void Selection::_add(SPObject *obj) { _objs = g_slist_prepend(_objs, obj); + add_3D_boxes_recursively(obj); + _release_connections[obj] = obj->connectRelease(sigc::mem_fun(*this, (void (Selection::*)(SPObject *))&Selection::remove)); _modified_connections[obj] = obj->connectModified(sigc::mem_fun(*this, &Selection::_schedule_modified)); } @@ -191,6 +219,36 @@ void Selection::remove(SPObject *obj) { _emitChanged(); } +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"); + return; + } + if ((*p).second > 1) { + _persps[persp]--; + } else { + _persps.erase(p); + } +} + +void Selection::remove_3D_boxes_recursively(SPObject *obj) { + std::list boxes = box3d_extract_boxes(obj); + + for (std::list::iterator i = boxes.begin(); i != boxes.end(); ++i) { + SPBox3D *box = *i; + box3d_remove_from_selection(box); + std::list::iterator b = std::find(_3dboxes.begin(), _3dboxes.end(), box); + if (b == _3dboxes.end()) { + g_print ("Warning! Trying to remove unselected box from selection.\n"); + return; + } + _3dboxes.erase(b); + remove_box_perspective(box); + } +} + void Selection::_remove(SPObject *obj) { _modified_connections[obj].disconnect(); _modified_connections.erase(obj); @@ -198,6 +256,8 @@ void Selection::_remove(SPObject *obj) { _release_connections[obj].disconnect(); _release_connections.erase(obj); + remove_3D_boxes_recursively(obj); + _objs = g_slist_remove(_objs, obj); } @@ -281,6 +341,18 @@ GSList const *Selection::reprList() { return _reprs; } +std::list const Selection::perspList() { + std::list pl; + for (std::map::iterator p = _persps.begin(); p != _persps.end(); ++p) { + pl.push_back((*p).first); + } + return pl; +} + +std::list const Selection::box3DList() { + return _3dboxes; +} + SPObject *Selection::single() { if ( _objs != NULL && _objs->next == NULL ) { return reinterpret_cast(_objs->data); @@ -303,35 +375,25 @@ Inkscape::XML::Node *Selection::singleRepr() { return obj ? SP_OBJECT_REPR(obj) : NULL; } -NRRect *Selection::bounds(NRRect *bbox) const +NRRect *Selection::bounds(NRRect *bbox, SPItem::BBoxType type) const { g_return_val_if_fail (bbox != NULL, NULL); - NR::Rect const b = bounds(); - bbox->x0 = b.min()[NR::X]; - bbox->y0 = b.min()[NR::Y]; - bbox->x1 = b.max()[NR::X]; - bbox->y1 = b.max()[NR::Y]; + *bbox = NRRect(bounds(type)); return bbox; } -NR::Rect Selection::bounds() const +boost::optional Selection::bounds(SPItem::BBoxType type) const { GSList const *items = const_cast(this)->itemList(); - NR::Maybe bbox = NR::Nothing(); + boost::optional bbox; for ( GSList const *i = items ; i != NULL ; i = i->next ) { - bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data))); - } - - // TODO: return NR::Maybe - if (bbox) { - return *bbox; - } else { - return NR::Rect(NR::Point(0, 0), NR::Point(0, 0)); + bbox = NR::union_bounds(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type)); } + return bbox; } -NRRect *Selection::boundsInDocument(NRRect *bbox) const { +NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const { g_return_val_if_fail (bbox != NULL, NULL); GSList const *items=const_cast(this)->itemList(); @@ -345,49 +407,50 @@ NRRect *Selection::boundsInDocument(NRRect *bbox) const { for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) { SPItem *item=SP_ITEM(iter->data); - NR::Matrix const i2doc(sp_item_i2doc_affine(item)); - sp_item_invoke_bbox(item, bbox, i2doc, FALSE); + NR::Matrix i2doc(from_2geom(sp_item_i2doc_affine(item))); + sp_item_invoke_bbox(item, bbox, i2doc, FALSE, type); } return bbox; } -NR::Rect Selection::boundsInDocument() const { +boost::optional Selection::boundsInDocument(SPItem::BBoxType type) const { NRRect r; - NR::Maybe rect(boundsInDocument(&r)->upgrade()); - if (rect) { - return *rect; - } else { - // FIXME - return NR::Rect(NR::Point(0, 0), NR::Point(0, 0)); - } + return boundsInDocument(&r, type)->upgrade(); } /** Extract the position of the center from the first selected object */ -NR::Point Selection::center() const { +boost::optional Selection::center() const { GSList *items = (GSList *) const_cast(this)->itemList(); NR::Point center; if (items) { SPItem *first = reinterpret_cast(g_slist_last(items)->data); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly - center = first->getCenter(); - } else { - center = bounds().midpoint(); + return first->getCenter(); } + } + boost::optional bbox = bounds(); + if (bbox) { + return bounds()->midpoint(); } else { - center = bounds().midpoint(); + return boost::optional(); } - return center; } /** * Compute the list of points in the selection that are to be considered for snapping. */ -std::vector Selection::getSnapPoints() const { +std::vector Selection::getSnapPoints(bool includeItemCenter) const { GSList const *items = const_cast(this)->itemList(); std::vector p; for (GSList const *iter = items; iter != NULL; iter = iter->next) { - sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p)); + SPItem *this_item = SP_ITEM(iter->data); + sp_item_snappoints(this_item, false, SnapPointsIter(p)); + //Include the transformation origin for snapping + //For a group only the group's origin is considered + if (includeItemCenter) { + p.push_back(this_item->getCenter()); + } } return p; @@ -395,48 +458,30 @@ std::vector Selection::getSnapPoints() const { std::vector Selection::getSnapPointsConvexHull() const { GSList const *items = const_cast(this)->itemList(); + std::vector p; for (GSList const *iter = items; iter != NULL; iter = iter->next) { - sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p)); + sp_item_snappoints(SP_ITEM(iter->data), false, SnapPointsIter(p)); } - std::vector::iterator i; - NR::ConvexHull cvh(*(p.begin())); - for (i = p.begin(); i != p.end(); i++) { - // these are the points we get back - cvh.add(*i); - } - - NR::Rect rHull = cvh.bounds(); - std::vector pHull(4); - pHull[0] = rHull.corner(0); - pHull[1] = rHull.corner(1); - pHull[2] = rHull.corner(2); - pHull[3] = rHull.corner(3); - - return pHull; -} + std::vector pHull; + if (!p.empty()) { + std::vector::iterator i; + NR::ConvexHull cvh(p.front()); + for (i = p.begin(); i != p.end(); i++) { + // these are the points we get back + cvh.add(*i); + } -std::vector Selection::getBBoxPoints() const { - GSList const *items = const_cast(this)->itemList(); - std::vector p; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - NR::Maybe b = sp_item_bbox_desktop(SP_ITEM(iter->data)); - if (b) { - p.push_back(b->min()); - p.push_back(b->max()); + boost::optional rHull = cvh.bounds(); + if (rHull) { + for ( unsigned i = 0 ; i < 4 ; ++i ) { + pHull.push_back(rHull->corner(i)); + } } } - return p; -} - -std::vector Selection::getBBoxPointsOuter() const { - std::vector p; - NR::Rect bbox = bounds(); - p.push_back(bbox.min()); - p.push_back(bbox.max()); - return p; + return pHull; } void Selection::_removeObjectDescendants(SPObject *obj) {