From d0d3e7f80dafc80e47c9a95bf31c14283010a2c2 Mon Sep 17 00:00:00 2001 From: Diederik van Lierop Date: Sat, 8 Dec 2012 21:29:18 +0100 Subject: Selector tool: improve responsiveness for snapping a path's internal intersections (was unbearable already for paths having 20+ segments) (bzr r11937) --- src/selection.cpp | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index d769b402c..72f50137c 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -443,15 +443,13 @@ std::vector Selection::getSnapPoints(SnapPreferenc SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER, false); // locally disable snapping to the item center - //snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP, true); // consider any type of nodes as a snap source - //snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_NODE_SMOOTH, 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); this_item->getSnappoints(p, &snapprefs_dummy); //Include the transformation origin for snapping - //For a selection or group only the overall origin is considered + //For a selection or group only the overall center is considered, not for each item individually if (snapprefs != NULL && snapprefs->isTargetSnappable(Inkscape::SNAPTARGET_ROTATION_CENTER)) { p.push_back(Inkscape::SnapCandidatePoint(this_item->getCenter(), SNAPSOURCE_ROTATION_CENTER)); } @@ -460,36 +458,6 @@ std::vector Selection::getSnapPoints(SnapPreferenc return p; } -// 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(); - - SnapPreferences snapprefs_dummy = *snapprefs; // create a local copy of the snapping prefs - snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_NODE_CUSP, true); // consider any type of nodes as a snap source - snapprefs_dummy.setTargetSnappable(Inkscape::SNAPTARGET_NODE_SMOOTH, true); // i.e. disregard the smooth / cusp node preference - - std::vector p; - for (GSList const *iter = items; iter != NULL; iter = iter->next) { - SP_ITEM(iter->data)->getSnappoints(p, &snapprefs_dummy); - } - - std::vector pHull; - if (!p.empty()) { - Geom::Rect cvh((p.front()).getPoint(), (p.front()).getPoint()); - for (std::vector::iterator i = p.begin(); i != p.end(); ++i) { - // these are the points we get back - cvh.expandTo((*i).getPoint()); - } - - for ( unsigned i = 0 ; i < 4 ; ++i ) { - pHull.push_back(Inkscape::SnapCandidatePoint(cvh.corner(i), SNAPSOURCE_CONVEX_HULL_CORNER)); - } - } - - return pHull; -} - void Selection::_removeObjectDescendants(SPObject *obj) { GSList *iter, *next; for ( iter = _objs ; iter ; iter = next ) { -- cgit v1.2.3 From f6c82a02188953dcb6d2119123ffc0aaa8d35010 Mon Sep 17 00:00:00 2001 From: Kris De Gussem Date: Sat, 16 Mar 2013 20:42:47 +0100 Subject: cppcheck (bzr r12217) --- src/selection.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 72f50137c..564f1fdd3 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -418,7 +418,6 @@ Geom::OptRect Selection::documentBounds(SPItem::BBoxType type) const // 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; if (items) { SPItem *first = reinterpret_cast(g_slist_last(items)->data); // from the first item in selection if (first->isCenterSet()) { // only if set explicitly -- cgit v1.2.3 From c3a160589a9cb41c70a56e5e7b66a65857a0d10e Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Mon, 1 Jul 2013 21:04:32 +0100 Subject: Factored layer model out into new Inkscape::LayerModel class. This allows Inkscape::Selection to use a LayerModel that is not associated with a UI. Changed the interface of verbs (SPAction) to use a new ActionContext rather than UI::View::View, again so that verbs may be used in a console mode. Modified boolean operation verbs to work in console-only mode. Fixed up DESKTOP_IS_ACTIVE macro to work in the case of no desktops. Modified main.cpp to process selections and verbs in no-GUI mode. Other changes are all consequences of the SPDesktop, Selection and LayerModel interface changes. (bzr r12387.1.1) --- src/selection.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 564f1fdd3..76f49f544 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -21,9 +21,8 @@ #endif #include "macros.h" #include "inkscape-private.h" -#include "desktop.h" -#include "desktop-handles.h" #include "document.h" +#include "layer-model.h" #include "selection.h" #include <2geom/rect.h> #include "xml/repr.h" @@ -42,10 +41,11 @@ namespace Inkscape { -Selection::Selection(SPDesktop *desktop) : +Selection::Selection(LayerModel *layer_model, SPDesktop *desktop) : _objs(NULL), _reprs(NULL), _items(NULL), + _layer_model(layer_model), _desktop(desktop), _selection_context(NULL), _flags(0), @@ -55,7 +55,7 @@ Selection::Selection(SPDesktop *desktop) : Selection::~Selection() { _clear(); - _desktop = NULL; + _layer_model = NULL; if (_idle) { g_source_remove(_idle); _idle = 0; @@ -96,7 +96,7 @@ void Selection::_emitModified(guint flags) { void Selection::_emitChanged(bool persist_selection_context/* = false */) { if (persist_selection_context) { if (NULL == _selection_context) { - _selection_context = desktop()->currentLayer(); + _selection_context = _layer_model->currentLayer(); sp_object_ref(_selection_context, NULL); _context_release_connection = _selection_context->connectRelease(sigc::mem_fun(*this, &Selection::_releaseContext)); } @@ -139,7 +139,7 @@ void Selection::_clear() { SPObject *Selection::activeContext() { if (NULL != _selection_context) return _selection_context; - return desktop()->currentLayer(); + return _layer_model->currentLayer(); } bool Selection::includes(SPObject *obj) const { @@ -487,7 +487,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { g_return_val_if_fail(repr != NULL, NULL); gchar const *id = repr->attribute("id"); g_return_val_if_fail(id != NULL, NULL); - SPObject *object=sp_desktop_document(_desktop)->getObjectById(id); + SPObject *object=_layer_model->getDocument()->getObjectById(id); g_return_val_if_fail(object != NULL, NULL); return object; } @@ -496,7 +496,7 @@ 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)); + SPObject *layer = _layer_model->layerForObject(SP_OBJECT(iter->data)); if (g_slist_find (layers, layer) == NULL) { layers = g_slist_prepend (layers, layer); } -- cgit v1.2.3 From 104efe4e3ecadc975ab76748c66f041abf8ee7b1 Mon Sep 17 00:00:00 2001 From: Eric Greveson Date: Thu, 4 Jul 2013 15:01:44 +0100 Subject: Code readability improvements and licence changes for action-context.* based on merge request code review and feedback (bzr r12387.1.7) --- src/selection.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 76f49f544..d018aba0c 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -41,11 +41,11 @@ namespace Inkscape { -Selection::Selection(LayerModel *layer_model, SPDesktop *desktop) : +Selection::Selection(LayerModel *layers, SPDesktop *desktop) : _objs(NULL), _reprs(NULL), _items(NULL), - _layer_model(layer_model), + _layers(layers), _desktop(desktop), _selection_context(NULL), _flags(0), @@ -55,7 +55,7 @@ Selection::Selection(LayerModel *layer_model, SPDesktop *desktop) : Selection::~Selection() { _clear(); - _layer_model = NULL; + _layers = NULL; if (_idle) { g_source_remove(_idle); _idle = 0; @@ -96,7 +96,7 @@ void Selection::_emitModified(guint flags) { void Selection::_emitChanged(bool persist_selection_context/* = false */) { if (persist_selection_context) { if (NULL == _selection_context) { - _selection_context = _layer_model->currentLayer(); + _selection_context = _layers->currentLayer(); sp_object_ref(_selection_context, NULL); _context_release_connection = _selection_context->connectRelease(sigc::mem_fun(*this, &Selection::_releaseContext)); } @@ -139,7 +139,7 @@ void Selection::_clear() { SPObject *Selection::activeContext() { if (NULL != _selection_context) return _selection_context; - return _layer_model->currentLayer(); + return _layers->currentLayer(); } bool Selection::includes(SPObject *obj) const { @@ -487,7 +487,7 @@ SPObject *Selection::_objectForXMLNode(Inkscape::XML::Node *repr) const { g_return_val_if_fail(repr != NULL, NULL); gchar const *id = repr->attribute("id"); g_return_val_if_fail(id != NULL, NULL); - SPObject *object=_layer_model->getDocument()->getObjectById(id); + SPObject *object=_layers->getDocument()->getObjectById(id); g_return_val_if_fail(object != NULL, NULL); return object; } @@ -496,7 +496,7 @@ 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 = _layer_model->layerForObject(SP_OBJECT(iter->data)); + SPObject *layer = _layers->layerForObject(SP_OBJECT(iter->data)); if (g_slist_find (layers, layer) == NULL) { layers = g_slist_prepend (layers, layer); } -- cgit v1.2.3 From 80a911db81b651f38205c1eb926af4986bc033e8 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 10 Jul 2013 22:24:38 -0400 Subject: Step 2 refactoring the align functions, added some functionality to selection. (bzr r12413) --- src/selection.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index d018aba0c..83caaf459 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,6 +42,7 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : + align_point(NULL), _objs(NULL), _reprs(NULL), _items(NULL), @@ -358,6 +359,35 @@ SPItem *Selection::singleItem() { } } +SPItem *Selection::smallestItem(Selection::CompareSize compare) { + return _sizeistItem(true, compare); +} + +SPItem *Selection::largestItem(Selection::CompareSize compare) { + return _sizeistItem(false, compare); +} + +SPItem *Selection::_sizeistItem(bool small, Selection::CompareSize compare) { + GSList const *items = const_cast(this)->itemList(); + gdouble max = small ? 1e18 : 0; + SPItem *ist = NULL; + + for ( GSList const *i = items; i != NULL ; i = i->next ) { + Geom::OptRect bbox = SP_ITEM(i->data)->desktopPreferredBounds(); + if (!bbox) continue; + + gdouble size = compare == 2 ? + (*bbox)[Geom::X].extent() * (*bbox)[Geom::Y].extent() : + (*bbox)[compare == 1 ? Geom::X : Geom::Y].extent(); + size = small ? size : size * -1; + if (size < max) { + max = size; + ist = SP_ITEM(i->data); + } + } + return ist; +} + Inkscape::XML::Node *Selection::singleRepr() { SPObject *obj=single(); return obj ? obj->getRepr() : NULL; -- cgit v1.2.3 From c3074d380bbdbd8ec8f17b9cfb3059119005a30b Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 10 Jul 2013 23:08:15 -0400 Subject: Remove align point, not required any more (bzr r12414) --- src/selection.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 83caaf459..e66137f65 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -42,7 +42,6 @@ namespace Inkscape { Selection::Selection(LayerModel *layers, SPDesktop *desktop) : - align_point(NULL), _objs(NULL), _reprs(NULL), _items(NULL), -- cgit v1.2.3 From df87c3c1c14f2483a9dbfc8bf2ac69e9834a42bf Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 11 Jul 2013 06:41:25 -0400 Subject: Change small to sml to fix windows compile problem (bzr r12415) --- src/selection.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index e66137f65..8f43d8e70 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -366,9 +366,9 @@ SPItem *Selection::largestItem(Selection::CompareSize compare) { return _sizeistItem(false, compare); } -SPItem *Selection::_sizeistItem(bool small, Selection::CompareSize compare) { +SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { GSList const *items = const_cast(this)->itemList(); - gdouble max = small ? 1e18 : 0; + gdouble max = sml ? 1e18 : 0; SPItem *ist = NULL; for ( GSList const *i = items; i != NULL ; i = i->next ) { @@ -378,7 +378,7 @@ SPItem *Selection::_sizeistItem(bool small, Selection::CompareSize compare) { gdouble size = compare == 2 ? (*bbox)[Geom::X].extent() * (*bbox)[Geom::Y].extent() : (*bbox)[compare == 1 ? Geom::X : Geom::Y].extent(); - size = small ? size : size * -1; + size = sml ? size : size * -1; if (size < max) { max = size; ist = SP_ITEM(i->data); -- cgit v1.2.3 From ed6229c5b41b72df6c59878aaae328cb2b6e3559 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Fri, 12 Jul 2013 13:06:09 -0400 Subject: Use Jon Cruz info about OptRect to correctly get area height and width (bzr r12417) --- src/selection.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 8f43d8e70..784219c88 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -372,12 +372,12 @@ SPItem *Selection::_sizeistItem(bool sml, Selection::CompareSize compare) { SPItem *ist = NULL; for ( GSList const *i = items; i != NULL ; i = i->next ) { - Geom::OptRect bbox = SP_ITEM(i->data)->desktopPreferredBounds(); - if (!bbox) continue; + Geom::OptRect obox = SP_ITEM(i->data)->desktopPreferredBounds(); + if (!obox || obox.isEmpty()) continue; + Geom::Rect bbox = *obox; - gdouble size = compare == 2 ? - (*bbox)[Geom::X].extent() * (*bbox)[Geom::Y].extent() : - (*bbox)[compare == 1 ? Geom::X : Geom::Y].extent(); + gdouble size = compare == 2 ? bbox.area() : + (compare == 1 ? bbox.width() : bbox.height()); size = sml ? size : size * -1; if (size < max) { max = size; -- cgit v1.2.3 From 6777466eda0b6952746a7bfb443d5e773857185a Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Sat, 3 Aug 2013 23:39:12 +0200 Subject: reduce variable scope (bzr r12464) --- src/selection.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 784219c88..1335c5fca 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -329,11 +329,11 @@ std::list const Selection::perspList() { 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)) + SPBox3D *box = *i; + if (persp == box3d_get_perspective(box)) { boxes.push_back(box); + } } } else { boxes = _3dboxes; -- cgit v1.2.3 From cbc44da105ce8ccd6d098ba64218af028f11e38e Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 24 Sep 2013 12:32:55 -0400 Subject: Make sure selection->setList checks for dupes by routing to selection->addList. Fixed bugs: - https://launchpad.net/bugs/1229678 (bzr r12586) --- src/selection.cpp | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 1335c5fca..aea5f539c 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -238,14 +238,7 @@ void Selection::_remove(SPObject *obj) { void Selection::setList(GSList const *list) { _clear(); - - if ( list != NULL ) { - for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { - _add(reinterpret_cast(iter->data)); - } - } - - _emitChanged(); + addList(list); } void Selection::addList(GSList const *list) { @@ -257,9 +250,7 @@ void Selection::addList(GSList const *list) { for ( GSList const *iter = list ; iter != NULL ; iter = iter->next ) { SPObject *obj = reinterpret_cast(iter->data); - if (includes(obj)) { - continue; - } + if (includes(obj)) continue; _add (obj); } -- cgit v1.2.3 From deb1727d4b7dfdfe9c68fb8a3ae6736d8e90d3c3 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Thu, 31 Oct 2013 12:39:40 -0400 Subject: Remove warning on bbox and allow empty bound selection to clear existing selection. Fixed bugs: - https://launchpad.net/bugs/1243408 (bzr r12755) --- src/selection.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index aea5f539c..7c696daf0 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -237,8 +237,11 @@ void Selection::_remove(SPObject *obj) { } void Selection::setList(GSList const *list) { - _clear(); - addList(list); + // Clear and add, or just clear with emit. + if (list != NULL) { + _clear(); + addList(list); + } else clear(); } void Selection::addList(GSList const *list) { @@ -444,12 +447,7 @@ boost::optional Selection::center() const { return first->getCenter(); } } - Geom::OptRect bbox; - if (Inkscape::Preferences::get()->getInt("/tools/bounding_box") == 0) { - bbox = visualBounds(); - } else{ - bbox = geometricBounds(); - } + Geom::OptRect bbox = preferredBounds(); if (bbox) { return bbox->midpoint(); } else { -- cgit v1.2.3 From 4f797dec1d4a48a21509ae83562f5521467bc6ac Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Wed, 8 Jan 2014 15:57:01 -0500 Subject: Change my mind on the solution to the bug, protect all selection additions. Fixed bugs: - https://launchpad.net/bugs/168695 (bzr r12894) --- src/selection.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/selection.cpp') diff --git a/src/selection.cpp b/src/selection.cpp index 7c696daf0..17b7253f2 100644 --- a/src/selection.cpp +++ b/src/selection.cpp @@ -154,6 +154,7 @@ bool Selection::includes(SPObject *obj) const { void Selection::add(SPObject *obj, bool persist_selection_context/* = false */) { g_return_if_fail(obj != NULL); g_return_if_fail(SP_IS_OBJECT(obj)); + g_return_if_fail(obj->document != NULL); if (includes(obj)) { return; -- cgit v1.2.3