summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6fc84a3)
raw | patch | inline | side by side (parent: 6fc84a3)
author | cilix42 <cilix42@users.sourceforge.net> | |
Sat, 12 Jan 2008 01:37:41 +0000 (01:37 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Sat, 12 Jan 2008 01:37:41 +0000 (01:37 +0000) |
src/selection-chemistry.cpp | patch | blob | history | |
src/sp-item.cpp | patch | blob | history | |
src/sp-item.h | patch | blob | history |
index fc2a6a271050aa1be856be2842065040f8555611..b1a579d8b316b766301ef28fe2cffda900b6ee42 100644 (file)
_("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;
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 3b9d70504195f931e68a4bffe6988bc327b8d707..f24bf6ecc317f1584979a2c1182cf7bf976cdf43 100644 (file)
--- a/src/sp-item.cpp
+++ b/src/sp-item.cpp
#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"
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 e87554bfb567f2ad433c2191f7daa2f0931ea0bb..8816bd3874e4e1df35a2c2b7adbd603fdcd1de43 100644 (file)
--- a/src/sp-item.h
+++ b/src/sp-item.h
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
/*