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