summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-01-12 01:37:41 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-01-12 01:37:41 +0000
commit91987e5206a235a589a712635da6ac3f039d8b8a (patch)
tree85288ab3da6007f408a612eb1ecceaa1ecbdecef /src
parentFix bad markups in km.po (diff)
downloadinkscape-91987e5206a235a589a712635da6ac3f039d8b8a.tar.gz
inkscape-91987e5206a235a589a712635da6ac3f039d8b8a.zip
Allow conversion of all selected items to guides (for items other than rectangles or 3D boxes these are simply aligned along the bounding box of the item being converted)
(bzr r4467)
Diffstat (limited to 'src')
-rw-r--r--src/selection-chemistry.cpp38
-rw-r--r--src/sp-item.cpp25
-rw-r--r--src/sp-item.h2
3 files changed, 48 insertions, 17 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp
index fc2a6a271..b1a579d8b 100644
--- a/src/selection-chemistry.cpp
+++ b/src/selection-chemistry.cpp
@@ -2442,6 +2442,20 @@ void sp_selection_to_marker(bool apply)
_("Objects to marker"));
}
+static void sp_selection_to_guides_recursive(SPItem *item) {
+ if (SP_IS_RECT(item)) {
+ sp_rect_convert_to_guides(SP_RECT(item), false);
+ } else if (SP_IS_BOX3D(item)) {
+ box3d_convert_to_guides(SP_BOX3D(item), false);
+ } else if (SP_IS_GROUP(item)) {
+ for (GSList *i = sp_item_group_item_list (SP_GROUP(item)); i != NULL; i = i->next) {
+ sp_selection_to_guides_recursive(SP_ITEM(i->data));
+ }
+ } else {
+ sp_item_convert_to_guides(item);
+ }
+}
+
void sp_selection_to_guides()
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
@@ -2452,27 +2466,17 @@ void sp_selection_to_guides()
Inkscape::Selection *selection = sp_desktop_selection(desktop);
// we need to copy the list because it gets reset when objects are deleted
GSList *items = g_slist_copy((GSList *) selection->itemList());
-
- bool performed = false;
- for (GSList const *i = items; i != NULL; i = i->next) {
- if (SP_IS_RECT(i->data)) {
- sp_rect_convert_to_guides(SP_RECT(i->data), false);
- performed = true;
- } else if (SP_IS_BOX3D(i->data)) {
- box3d_convert_to_guides(SP_BOX3D(i->data), false);
- performed = true;
- }
- }
- if (!performed) {
- desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to guides (selection must contain at least one rectangle or 3D box)."));
+ if (!items) {
+ desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to guides."));
return;
}
-
- if (performed) {
- sp_document_done (doc, SP_VERB_EDIT_SELECTION_2_GUIDES,
- _("Objects to guides"));
+
+ for (GSList const *i = items; i != NULL; i = i->next) {
+ sp_selection_to_guides_recursive(SP_ITEM(i->data));
}
+
+ sp_document_done (doc, SP_VERB_EDIT_SELECTION_2_GUIDES, _("Objects to guides"));
}
void
diff --git a/src/sp-item.cpp b/src/sp-item.cpp
index 3b9d70504..f24bf6ecc 100644
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
@@ -51,6 +51,7 @@
#include "conn-avoid-ref.h"
#include "conditions.h"
#include "sp-filter-reference.h"
+#include "sp-guide.h"
#include "libnr/nr-matrix-div.h"
#include "libnr/nr-matrix-fns.h"
@@ -1576,6 +1577,30 @@ sp_item_first_item_child (SPObject *obj)
return NULL;
}
+void
+sp_item_convert_to_guides(SPItem *item) {
+ NR::Maybe<NR::Rect> bbox = sp_item_bbox_desktop(item, SPItem::GEOMETRIC_BBOX);
+ if (!bbox) {
+ g_print ("Cannot determine bounding box. Doing nothing.\n");
+ return;
+ }
+
+ std::list<std::pair<Geom::Point, Geom::Point> > pts;
+
+ NR::Point A((*bbox).min());
+ NR::Point C((*bbox).max());
+ NR::Point B(A[NR::X], C[NR::Y]);
+ NR::Point D(C[NR::X], A[NR::Y]);
+
+ pts.push_back(std::make_pair(A.to_2geom(), B.to_2geom()));
+ pts.push_back(std::make_pair(B.to_2geom(), C.to_2geom()));
+ pts.push_back(std::make_pair(C.to_2geom(), D.to_2geom()));
+ pts.push_back(std::make_pair(D.to_2geom(), A.to_2geom()));
+
+ sp_guide_pt_pairs_to_guides(SP_OBJECT_DOCUMENT(item), pts);
+
+ SP_OBJECT(item)->deleteObject(true);
+}
/*
Local Variables:
diff --git a/src/sp-item.h b/src/sp-item.h
index e87554bfb..8816bd387 100644
--- a/src/sp-item.h
+++ b/src/sp-item.h
@@ -270,6 +270,8 @@ NR::Matrix sp_item_dt2i_affine(SPItem const *item);
int sp_item_repr_compare_position(SPItem *first, SPItem *second);
SPItem *sp_item_first_item_child (SPObject *obj);
+void sp_item_convert_to_guides(SPItem *item);
+
#endif
/*