X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fselection.cpp;h=9cef87076db5dd20c0179fd888ead40d975f9c61;hb=5a43b2bbcb81ab7da396dad781d3f9b7854eb002;hp=4ed6c0842b92ba71d7fa884fd171deb8ef77b01e;hpb=e9b6af083e34e2397a8ddbe9781920733d09d151;p=inkscape.git diff --git a/src/selection.cpp b/src/selection.cpp index 4ed6c0842..9cef87076 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -6,6 +6,7 @@ * MenTaLguY * bulia byak * Andrius R. + * Abhishek Sharma * * Copyright (C) 2006 Andrius R. * Copyright (C) 2004-2005 MenTaLguY @@ -162,24 +163,12 @@ 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); } } @@ -220,33 +209,17 @@ 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); } } @@ -344,14 +317,27 @@ GSList const *Selection::reprList() { std::list const Selection::perspList() { std::list pl; - for (std::map::iterator p = _persps.begin(); p != _persps.end(); ++p) { - pl.push_back((*p).first); + for (std::list::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) { + Persp3D *persp = box3d_get_perspective(*i); + if (std::find(pl.begin(), pl.end(), persp) == pl.end()) + pl.push_back(persp); } return pl; } -std::list const Selection::box3DList() { - return _3dboxes; +std::list const Selection::box3DList(Persp3D *persp) { + std::list boxes; + if (persp) { + SPBox3D *box; + for (std::list::iterator i = _3dboxes.begin(); i != _3dboxes.end(); ++i) { + box = *i; + if (persp == box3d_get_perspective(box)) + boxes.push_back(box); + } + } else { + boxes = _3dboxes; + } + return boxes; } SPObject *Selection::single() { @@ -383,13 +369,13 @@ 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 = unify(bbox, sp_item_bbox_desktop(SP_ITEM(i->data), type)); + bbox = unify(bbox, SP_ITEM(i->data)->getBboxDesktop(type)); } return bbox; } @@ -408,19 +394,21 @@ NRRect *Selection::boundsInDocument(NRRect *bbox, SPItem::BBoxType type) const { for ( GSList const *iter=items ; iter != NULL ; iter = iter->next ) { SPItem *item=SP_ITEM(iter->data); - Geom::Matrix i2doc(sp_item_i2doc_affine(item)); - sp_item_invoke_bbox(item, bbox, i2doc, FALSE, type); + Geom::Matrix i2doc(item->i2doc_affine()); + item->invoke_bbox( bbox, i2doc, FALSE, type); } return bbox; } -boost::optional Selection::boundsInDocument(SPItem::BBoxType type) const { +Geom::OptRect Selection::boundsInDocument(SPItem::BBoxType type) const { NRRect r; return to_2geom(boundsInDocument(&r, type)->upgrade()); } /** Extract the position of the center from the first selected object */ +// If we have a selection of multiple items, then the center of the first item +// will be returned; this is also the case in SelTrans::centerRequest() boost::optional Selection::center() const { GSList *items = (GSList *) const_cast(this)->itemList(); Geom::Point center; @@ -430,7 +418,7 @@ boost::optional Selection::center() const { return first->getCenter(); } } - boost::optional bbox = bounds(); + Geom::OptRect bbox = bounds(); if (bbox) { return bounds()->midpoint(); } else { @@ -439,50 +427,56 @@ boost::optional Selection::center() const { } /** - * Compute the list of points in the selection that are to be considered for snapping. + * Compute the list of points in the selection that are to be considered for snapping from. */ -std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { +std::vector Selection::getSnapPoints(SnapPreferences const *snapprefs) const { GSList const *items = const_cast(this)->itemList(); - + 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; + snapprefs_dummy.setSnapToItemNode(true); // consider any type of nodes as a snap source + snapprefs_dummy.setSnapSmoothNodes(true); // i.e. disregard the smooth / cusp node preference + 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, SnapPointsIter(p), &snapprefs_dummy); - + this_item->getSnappoints(p, &snapprefs_dummy); + //Include the transformation origin for snapping //For a selection or group only the overall origin is considered if (snapprefs != NULL && snapprefs->getIncludeItemCenter()) { - p.push_back(this_item->getCenter()); - } + p.push_back(Inkscape::SnapCandidatePoint(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER)); + } } return p; } - -std::vector Selection::getSnapPointsConvexHull(SnapPreferences const *snapprefs) const { +// TODO: both getSnapPoints and getSnapPointsConvexHull are called, subsequently. Can we do this more efficient? +// Why do we need to include the transformation center in one case and not the other? +std::vector Selection::getSnapPointsConvexHull(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.setSnapToItemNode(true); // consider any type of nodes as a snap source + snapprefs_dummy.setSnapSmoothNodes(true); // i.e. disregard the smooth / cusp node preference + + std::vector p; for (GSList const *iter = items; iter != NULL; iter = iter->next) { - sp_item_snappoints(SP_ITEM(iter->data), SnapPointsIter(p), snapprefs); + SP_ITEM(iter->data)->getSnappoints(p, &snapprefs_dummy); } - std::vector pHull; + std::vector pHull; if (!p.empty()) { - std::vector::iterator i; - Geom::RectHull cvh(p.front()); + std::vector::iterator i; + Geom::RectHull cvh((p.front()).getPoint()); for (i = p.begin(); i != p.end(); i++) { // these are the points we get back - cvh.add(*i); + cvh.add((*i).getPoint()); } - 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(Inkscape::SnapCandidatePoint(rHull->corner(i), SNAPSOURCE_CONVEX_HULL_CORNER)); } } } @@ -564,4 +558,4 @@ guint Selection::numberOfParents() { fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :