From 9abb5e658d005b3ac82afeec13fd59384a8e65eb Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Sun, 5 Jun 2016 23:20:55 +0200 Subject: Added object set (bzr r14954.1.1) --- src/object-set.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/object-set.h (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h new file mode 100644 index 000000000..a3962356b --- /dev/null +++ b/src/object-set.h @@ -0,0 +1,58 @@ +/* + * Multiindex container for selection + * + * Authors: + * Adrian Boguszewski + * + * Copyright (C) 2016 Adrian Boguszewski + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef INKSCAPE_PROTOTYPE_OBJECTSET_H +#define INKSCAPE_PROTOTYPE_OBJECTSET_H + +#include "object.h" +#include +#include +#include +#include +#include +#include +#include + +struct hashed{}; + +typedef boost::multi_index_container< + Object*, + boost::multi_index::indexed_by< + boost::multi_index::sequenced<>, + boost::multi_index::hashed_unique< + boost::multi_index::tag, + boost::multi_index::identity> + >> multi_index_container; + +class ObjectSet { +public: + ObjectSet() {}; + ~ObjectSet(); + bool add(Object* object); + bool remove(Object* object); + bool contains(Object* object); + void clear(); + int size(); + +private: + void _add(Object* object); + void _remove(Object* object); + bool _anyAncestorIsInSet(Object *object); + void _removeDescendantsFromSet(Object *object); + void _removeAncestorsFromSet(Object *object); + Object *_getMutualAncestor(Object *object); + + multi_index_container container; + std::unordered_map releaseConnections; +}; + + +#endif //INKSCAPE_PROTOTYPE_OBJECTSET_H -- cgit v1.2.3 From 1636c1dd1651780d01759676b194312529f211f7 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Sat, 25 Jun 2016 22:24:26 +0200 Subject: Moved next functions, added namespace, renamed range functions (bzr r14954.1.10) --- src/object-set.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index 05264a3ea..49a875562 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -28,6 +28,12 @@ class SPBox3D; class Persp3D; +namespace Inkscape { + +namespace XML { +class Node; +} + struct hashed{}; struct random_access{}; @@ -54,6 +60,12 @@ typedef boost::any_range< SPItem* const&, std::ptrdiff_t> SPItemRange; +typedef boost::any_range< + XML::Node*, + boost::random_access_traversal_tag, + XML::Node* const&, + std::ptrdiff_t> XMLNodeRange; + class ObjectSet { public: enum CompareSize {HORIZONTAL, VERTICAL, AREA}; @@ -144,10 +156,20 @@ public: SPItem *largestItem(CompareSize compare); /** Returns the list of selected objects. */ - SPObjectRange range(); + SPObjectRange objects(); /** Returns the list of selected SPItems. */ - std::vector itemList(); + std::vector items(); + + /** Returns a list of the xml nodes of all selected objects. */ + std::vector xmlNodes(); + + /** + * Returns a single selected object's xml node. + * + * @return NULL unless exactly one object is selected + */ + XML::Node *singleRepr(); /** * Selects exactly the specified objects. @@ -213,5 +235,6 @@ protected: }; +} // namespace Inkscape #endif //INKSCAPE_PROTOTYPE_OBJECTSET_H -- cgit v1.2.3 From a51df2ab1eb079b2588ccb9398440f403d11c34d Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Mon, 27 Jun 2016 16:59:48 +0200 Subject: Added more tests (bzr r14954.1.11) --- src/object-set.h | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index 49a875562..29083863b 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include "sp-object.h" #include "sp-item.h" @@ -84,7 +86,12 @@ public: * \param from the begin iterator * \param to the end iterator */ - void add(const std::vector::iterator& from, const std::vector::iterator& to); + template + void add(InputIterator from, InputIterator to) { + for(auto it = from; it != to; ++it) { + _add(*it); + } + } /** * Removes an item from the set of selected objects. @@ -176,14 +183,27 @@ public: * * @param objs the objects to select */ - void setList(const std::vector &objs); + template + typename boost::enable_if, void>::type + setList(const std::vector &objs) { + _clear(); + addList(objs); + } /** * Adds the specified objects to selection, without deselecting first. * * @param objs the objects to select */ - void addList(std::vector const &objs); + template + typename boost::enable_if, void>::type + addList(const std::vector &objs) { + for (auto obj: objs) { + if (!includes(obj)) { + add(obj); + } + } + } /** Returns the bounding rectangle of the selection. */ Geom::OptRect bounds(SPItem::BBoxType type) const; -- cgit v1.2.3 From 22262f2db6747eb516283b92abcfd348c700911a Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Fri, 1 Jul 2016 20:57:32 +0200 Subject: Added xmlNodes as range function (bzr r14954.1.12) --- src/object-set.h | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index 29083863b..ea6534350 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -19,6 +19,8 @@ #include #include #include +#include +#include #include #include #include @@ -39,6 +41,26 @@ class Node; struct hashed{}; struct random_access{}; +struct is_item { + bool operator()(SPObject* obj) { + return SP_IS_ITEM(obj); + } +}; + +struct object_to_item { + typedef SPItem* result_type; + SPItem* operator()(SPObject* obj) const { + return SP_ITEM(obj); + } +}; + +struct object_to_node { + typedef XML::Node* result_type; + XML::Node* operator()(SPObject* obj) const { + return obj->getRepr(); + } +}; + typedef boost::multi_index_container< SPObject*, boost::multi_index::indexed_by< @@ -56,21 +78,11 @@ typedef boost::any_range< SPObject* const&, std::ptrdiff_t> SPObjectRange; -typedef boost::any_range< - SPItem*, - boost::random_access_traversal_tag, - SPItem* const&, - std::ptrdiff_t> SPItemRange; - -typedef boost::any_range< - XML::Node*, - boost::random_access_traversal_tag, - XML::Node* const&, - std::ptrdiff_t> XMLNodeRange; - class ObjectSet { public: enum CompareSize {HORIZONTAL, VERTICAL, AREA}; + typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_item())) SPItemRange; + typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange; ObjectSet() {}; virtual ~ObjectSet(); @@ -169,7 +181,11 @@ public: std::vector items(); /** Returns a list of the xml nodes of all selected objects. */ - std::vector xmlNodes(); + XMLNodeRange xmlNodes() { + return XMLNodeRange(container.get() + | boost::adaptors::filtered(is_item()) + | boost::adaptors::transformed(object_to_node())); + } /** * Returns a single selected object's xml node. @@ -255,6 +271,9 @@ protected: }; +typedef ObjectSet::SPItemRange SPItemRange; +typedef ObjectSet::XMLNodeRange XMLNodeRange; + } // namespace Inkscape #endif //INKSCAPE_PROTOTYPE_OBJECTSET_H -- cgit v1.2.3 From 3c593bb8da3357514ff5b4f3154d08c4508ad47e Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 20 Jul 2016 11:01:17 +0200 Subject: Changed arguments and names of selection chemistry functions (bzr r14954.1.22) --- src/object-set.h | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index 0f06e373b..a0bca7889 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -26,11 +26,14 @@ #include #include #include +#include #include "sp-object.h" #include "sp-item.h" +#include "sp-item-group.h" class SPBox3D; class Persp3D; +class SPDesktop; namespace Inkscape { @@ -47,6 +50,12 @@ struct is_item { } }; +struct is_group { + bool operator()(SPObject* obj) { + return SP_IS_GROUP(obj); + } +}; + struct object_to_item { typedef SPItem* result_type; SPItem* operator()(SPObject* obj) const { @@ -61,6 +70,13 @@ struct object_to_node { } }; +struct object_to_group { + typedef SPGroup* result_type; + SPGroup* operator()(SPObject* obj) const { + return SP_GROUP(obj); + } +}; + typedef boost::multi_index_container< SPObject*, boost::multi_index::indexed_by< @@ -82,9 +98,10 @@ class ObjectSet { public: enum CompareSize {HORIZONTAL, VERTICAL, AREA}; typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_item())) SPItemRange; + typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_group()) | boost::adaptors::transformed(object_to_group())) SPGroupRange; typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange; - ObjectSet() {}; + ObjectSet(SPDesktop* desktop): _desktop(desktop) {}; virtual ~ObjectSet(); /** @@ -177,18 +194,25 @@ public: /** Returns the list of selected objects. */ SPObjectRange objects(); - /** Returns the list of selected SPItems. */ + /** Returns a range of selected SPItems. */ SPItemRange items() { return SPItemRange(container.get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_item())); }; - /** Returns a list of the xml nodes of all selected objects. */ + /** Returns a range of selected groups. */ + SPGroupRange groups() { + return SPGroupRange (container.get() + | boost::adaptors::filtered(is_group()) + | boost::adaptors::transformed(object_to_group())); + } + + /** Returns a range of the xml nodes of all selected objects. */ XMLNodeRange xmlNodes() { return XMLNodeRange(container.get() - | boost::adaptors::filtered(is_item()) - | boost::adaptors::transformed(object_to_node())); + | boost::adaptors::filtered(is_item()) + | boost::adaptors::transformed(object_to_node())); } /** @@ -254,6 +278,13 @@ public: */ std::list const box3DList(Persp3D *persp = NULL); + /** + * Returns the desktop the selection is bound to + * + * @return the desktop the selection is bound to, or NULL if in console mode + */ + SPDesktop *desktop() { return _desktop; } + protected: virtual void _connectSignals(SPObject* object) {}; virtual void _releaseSignals(SPObject* object) {}; @@ -270,12 +301,14 @@ protected: virtual void _remove_3D_boxes_recursively(SPObject *obj); multi_index_container container; + GC::soft_ptr _desktop; std::list _3dboxes; std::unordered_map releaseConnections; }; typedef ObjectSet::SPItemRange SPItemRange; +typedef ObjectSet::SPGroupRange SPGroupRange; typedef ObjectSet::XMLNodeRange XMLNodeRange; } // namespace Inkscape -- cgit v1.2.3 From a227e8d45e7eaa6bf25d8ab65fbd404bc4597306 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 20 Jul 2016 13:45:05 +0200 Subject: Changed signatures of boolean functions (bzr r14954.1.24) --- src/object-set.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index a0bca7889..c7f1921cf 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -102,6 +102,7 @@ public: typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange; ObjectSet(SPDesktop* desktop): _desktop(desktop) {}; + ObjectSet(): _desktop(nullptr) {}; virtual ~ObjectSet(); /** -- cgit v1.2.3 From d31923a399f3c7cde85aae8406191e37ad877eb7 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Fri, 22 Jul 2016 11:32:35 +0200 Subject: Improved spray tool, changed selection to object set (bzr r14954.1.25) --- src/object-set.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index c7f1921cf..b4178bd37 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -121,6 +121,7 @@ public: for(auto it = from; it != to; ++it) { _add(*it); } + _emitSignals(); } /** -- cgit v1.2.3 From 300d24dedddefb2f68ebd680fcd2234bfca53ad7 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Mon, 25 Jul 2016 22:16:54 +0200 Subject: Changed coding style (bzr r14954.1.27) --- src/object-set.h | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index b4178bd37..2772afbe2 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -198,21 +198,21 @@ public: /** Returns a range of selected SPItems. */ SPItemRange items() { - return SPItemRange(container.get() + return SPItemRange(_container.get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_item())); }; /** Returns a range of selected groups. */ SPGroupRange groups() { - return SPGroupRange (container.get() + return SPGroupRange (_container.get() | boost::adaptors::filtered(is_group()) | boost::adaptors::transformed(object_to_group())); } /** Returns a range of the xml nodes of all selected objects. */ XMLNodeRange xmlNodes() { - return XMLNodeRange(container.get() + return XMLNodeRange(_container.get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())); } @@ -299,13 +299,13 @@ protected: void _removeAncestorsFromSet(SPObject *object); SPItem *_sizeistItem(bool sml, CompareSize compare); SPObject *_getMutualAncestor(SPObject *object); - virtual void _add_3D_boxes_recursively(SPObject *obj); - virtual void _remove_3D_boxes_recursively(SPObject *obj); + virtual void _add3DBoxesRecursively(SPObject *obj); + virtual void _remove3DBoxesRecursively(SPObject *obj); - multi_index_container container; + multi_index_container _container; GC::soft_ptr _desktop; std::list _3dboxes; - std::unordered_map releaseConnections; + std::unordered_map _releaseConnections; }; @@ -316,3 +316,14 @@ typedef ObjectSet::XMLNodeRange XMLNodeRange; } // namespace Inkscape #endif //INKSCAPE_PROTOTYPE_OBJECTSET_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3 From ff4fbbc93f67afd6cbf851691833a50d6c76b350 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 27 Jul 2016 12:19:03 +0200 Subject: Renamed some functions, fixed tests (bzr r14954.1.28) --- src/object-set.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/object-set.h') diff --git a/src/object-set.h b/src/object-set.h index 2772afbe2..fae365f70 100644 --- a/src/object-set.h +++ b/src/object-set.h @@ -86,7 +86,7 @@ typedef boost::multi_index_container< boost::multi_index::hashed_unique< boost::multi_index::tag, boost::multi_index::identity> - >> multi_index_container; + >> MultiIndexContainer; typedef boost::any_range< SPObject*, @@ -97,9 +97,9 @@ typedef boost::any_range< class ObjectSet { public: enum CompareSize {HORIZONTAL, VERTICAL, AREA}; - typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_item())) SPItemRange; - typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_group()) | boost::adaptors::transformed(object_to_group())) SPGroupRange; - typedef decltype(multi_index_container().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange; + typedef decltype(MultiIndexContainer().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_item())) SPItemRange; + typedef decltype(MultiIndexContainer().get() | boost::adaptors::filtered(is_group()) | boost::adaptors::transformed(object_to_group())) SPGroupRange; + typedef decltype(MultiIndexContainer().get() | boost::adaptors::filtered(is_item()) | boost::adaptors::transformed(object_to_node())) XMLNodeRange; ObjectSet(SPDesktop* desktop): _desktop(desktop) {}; ObjectSet(): _desktop(nullptr) {}; @@ -302,7 +302,7 @@ protected: virtual void _add3DBoxesRecursively(SPObject *obj); virtual void _remove3DBoxesRecursively(SPObject *obj); - multi_index_container _container; + MultiIndexContainer _container; GC::soft_ptr _desktop; std::list _3dboxes; std::unordered_map _releaseConnections; -- cgit v1.2.3