summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: aa90355)
raw | patch | inline | side by side (parent: aa90355)
author | cilix42 <cilix42@users.sourceforge.net> | |
Fri, 11 Jan 2008 19:01:50 +0000 (19:01 +0000) | ||
committer | cilix42 <cilix42@users.sourceforge.net> | |
Fri, 11 Jan 2008 19:01:50 +0000 (19:01 +0000) |
14 files changed:
diff --git a/src/box3d-context.cpp b/src/box3d-context.cpp
index 68480a00d4d3d98de48c4d32ec8836f18f136e68..bbc8097f5957a4dd6cf0286e2a0b3447fb015b90 100644 (file)
--- a/src/box3d-context.cpp
+++ b/src/box3d-context.cpp
#include "document.h"
#include "sp-namedview.h"
#include "selection.h"
+#include "selection-chemistry.h"
#include "desktop-handles.h"
#include "snap.h"
#include "display/curve.h"
@@ -532,6 +533,14 @@ static gint sp_box3d_context_root_handler(SPEventContext *event_context, GdkEven
ret = true;
break;
+ case GDK_g:
+ case GDK_G:
+ if (MOD__SHIFT_ONLY) {
+ sp_selection_to_guides();
+ ret = true;
+ }
+ break;
+
case GDK_P:
{
if (MOD__SHIFT && MOD__CTRL) break; // Don't catch Shift+Ctrl+P (Preferences dialog)
diff --git a/src/box3d.cpp b/src/box3d.cpp
index 082c83bbdc18311f024da2858dba4842048bce35..631d5cfc1d27be44ea582aaddfb4eb0344114fc5 100644 (file)
--- a/src/box3d.cpp
+++ b/src/box3d.cpp
#include "persp3d-reference.h"
#include "uri.h"
#include "2geom/geom.h"
+#include "sp-guide.h"
+#include "sp-namedview.h"
#include "desktop.h"
#include "macros.h"
return SP_GROUP(doc->getObjectByRepr(grepr));
}
+static void
+box3d_push_back_corner_pair(SPBox3D *box, std::list<std::pair<Geom::Point, Geom::Point> > &pts, int c1, int c2) {
+ pts.push_back(std::make_pair(box3d_get_corner_screen(box, c1).to_2geom(),
+ box3d_get_corner_screen(box, c2).to_2geom()));
+}
+
+void
+box3d_convert_to_guides(SPBox3D *box, bool write_undo) {
+ SPDocument *doc = SP_OBJECT_DOCUMENT(box);
+ //SPDesktop *desktop = inkscape_active_desktop();
+ //Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+
+ std::list<std::pair<Geom::Point, Geom::Point> > pts;
+
+ /* perspective lines in X direction */
+ box3d_push_back_corner_pair(box, pts, 0, 1);
+ box3d_push_back_corner_pair(box, pts, 2, 3);
+ box3d_push_back_corner_pair(box, pts, 4, 5);
+ box3d_push_back_corner_pair(box, pts, 6, 7);
+
+ /* perspective lines in Y direction */
+ box3d_push_back_corner_pair(box, pts, 0, 2);
+ box3d_push_back_corner_pair(box, pts, 1, 3);
+ box3d_push_back_corner_pair(box, pts, 4, 6);
+ box3d_push_back_corner_pair(box, pts, 5, 7);
+
+ /* perspective lines in Z direction */
+ box3d_push_back_corner_pair(box, pts, 0, 4);
+ box3d_push_back_corner_pair(box, pts, 1, 5);
+ box3d_push_back_corner_pair(box, pts, 2, 6);
+ box3d_push_back_corner_pair(box, pts, 3, 7);
+
+ sp_guide_pt_pairs_to_guides(doc, pts);
+
+ SP_OBJECT(box)->deleteObject(true);
+
+ if (write_undo) {
+ sp_document_done(doc, SP_VERB_CONTEXT_3DBOX, _("Convert to guides"));
+ }
+}
+
/*
Local Variables:
mode:c++
diff --git a/src/box3d.h b/src/box3d.h
index 12d6bfc4b5e59e6b84ba5076ca4d01c66e63ec22..bcbd975c5a961288f3661780a633e78e98d4c793 100644 (file)
--- a/src/box3d.h
+++ b/src/box3d.h
void box3d_switch_perspectives(SPBox3D *box, Persp3D *old_persp, Persp3D *new_persp, bool recompute_corners = false);
SPGroup *box3d_convert_to_group(SPBox3D *box);
+void box3d_convert_to_guides(SPBox3D *box, bool write_undo = true);
+
#endif /* __SP_BOX3D_H__ */
diff --git a/src/menus-skeleton.h b/src/menus-skeleton.h
index bdbbc51de3fd7bf623de750f65581e03ddb39366..b96ee230269c550cf7407e9b9ec76ad0f9ad9fb7 100644 (file)
--- a/src/menus-skeleton.h
+++ b/src/menus-skeleton.h
" <verb verb-id=\"ObjectsFromPattern\" />\n"
" </submenu>\n"
" <verb verb-id=\"ObjectsToMarker\" />\n"
+" <verb verb-id=\"ObjectsToGuides\" />\n"
" <separator/>\n"
" <verb verb-id=\"SelectionRaise\" />\n"
" <verb verb-id=\"SelectionLower\" />\n"
diff --git a/src/rect-context.cpp b/src/rect-context.cpp
index 5969c1fb2565f490dd84657d9b2e1aa2f2f37030..938b4496dca3a3186adfcd7399e7fc53bebf5759 100644 (file)
--- a/src/rect-context.cpp
+++ b/src/rect-context.cpp
#include "document.h"
#include "sp-namedview.h"
#include "selection.h"
+#include "selection-chemistry.h"
#include "desktop-handles.h"
#include "snap.h"
#include "desktop.h"
@@ -413,6 +414,14 @@ static gint sp_rect_context_root_handler(SPEventContext *event_context, GdkEvent
}
break;
+ case GDK_g:
+ case GDK_G:
+ if (MOD__SHIFT_ONLY) {
+ sp_selection_to_guides();
+ ret = true;
+ }
+ break;
+
case GDK_Escape:
sp_desktop_selection(desktop)->clear();
//TODO: make dragging escapable by Esc
diff --git a/src/select-context.cpp b/src/select-context.cpp
index cdf63785c2f33536b9b5acb715ddfec454ca2635..48afadb2bb85635447ce2b1e156eeb65d53b08c3 100644 (file)
--- a/src/select-context.cpp
+++ b/src/select-context.cpp
ret = TRUE;
}
break;
+ case GDK_g:
+ case GDK_G:
+ if (MOD__SHIFT_ONLY) {
+ sp_selection_to_guides();
+ ret = true;
+ }
+ break;
default:
break;
}
index 56ef7b01f97d334f3c61e8d537dab9ebaa58d4c9..fc2a6a271050aa1be856be2842065040f8555611 100644 (file)
#include <map>
#include "helper/units.h"
#include "sp-item.h"
+#include "box3d.h"
#include "unit-constants.h"
#include "xml/simple-document.h"
#include "sp-filter-reference.h"
#include "gradient-drag.h"
#include "uri-references.h"
#include "live_effects/lpeobject.h"
+#include "sp-rect.h"
using NR::X;
using NR::Y;
_("Objects to marker"));
}
+void sp_selection_to_guides()
+{
+ SPDesktop *desktop = SP_ACTIVE_DESKTOP;
+ if (desktop == NULL)
+ return;
+
+ SPDocument *doc = sp_desktop_document(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)."));
+ return;
+ }
+
+ if (performed) {
+ sp_document_done (doc, SP_VERB_EDIT_SELECTION_2_GUIDES,
+ _("Objects to guides"));
+ }
+}
+
void
sp_selection_tile(bool apply)
{
index 09f95733203d0176bc1a09b0829e8c8c9875afbc..0dc1da7e7ff7b1311d6a7d085b3c4959d6095e27 100644 (file)
void sp_select_clone_original ();
void sp_selection_to_marker(bool apply = true);
+void sp_selection_to_guides();
void sp_selection_tile(bool apply = true);
void sp_selection_untile();
diff --git a/src/sp-guide.cpp b/src/sp-guide.cpp
index 26d60601c58d002ff2c4767f1a35af0341ddb52d..68e322178d26c108e16510828ced53689b592ee6 100644 (file)
--- a/src/sp-guide.cpp
+++ b/src/sp-guide.cpp
#include "desktop.h"
#include "sp-namedview.h"
#include <2geom/angle.h>
+#include "document.h"
using std::vector;
@@ -235,6 +236,32 @@ static void sp_guide_set(SPObject *object, unsigned int key, const gchar *value)
}
}
+SPGuide *
+sp_guide_create(SPDocument *doc, Geom::Point const &pt1, Geom::Point const &pt2) {
+ SPDesktop *desktop = inkscape_active_desktop();
+ Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
+
+ Inkscape::XML::Node *repr = xml_doc->createElement("sodipodi:guide");
+
+ Geom::Point n = Geom::rot90(pt2 - pt1);
+
+ sp_repr_set_point(repr, "position", pt1);
+ sp_repr_set_point(repr, "orientation", n);
+
+ SP_OBJECT_REPR(desktop->namedview)->appendChild(repr);
+ Inkscape::GC::release(repr);
+
+ SPGuide *guide= SP_GUIDE(doc->getObjectByRepr(repr));
+ return guide;
+}
+
+void
+sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts) {
+ for (std::list<std::pair<Geom::Point, Geom::Point> >::iterator i = pts.begin(); i != pts.end(); ++i) {
+ sp_guide_create(doc, (*i).first, (*i).second);
+ }
+}
+
void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler)
{
SPCanvasItem *item = sp_guideline_new(group, guide->point_on_line, guide->normal_to_line.to_2geom());
diff --git a/src/sp-guide.h b/src/sp-guide.h
index dbbebadb7aee63e97b5bff94fd7517b7804c25e4..a9b04dfaa99b10195df611e4b76f19798905d1a9 100644 (file)
--- a/src/sp-guide.h
+++ b/src/sp-guide.h
GType sp_guide_get_type();
+SPGuide *sp_guide_create(SPDesktop *desktop, Geom::Point const &pt1, Geom::Point const &pt2);
+void sp_guide_pt_pairs_to_guides(SPDocument *doc, std::list<std::pair<Geom::Point, Geom::Point> > &pts);
+
void sp_guide_show(SPGuide *guide, SPCanvasGroup *group, GCallback handler);
void sp_guide_hide(SPGuide *guide, SPCanvas *canvas);
void sp_guide_sensitize(SPGuide *guide, SPCanvas *canvas, gboolean sensitive);
diff --git a/src/sp-rect.cpp b/src/sp-rect.cpp
index d9caebd5a00eaeae4464aec2536b30deaf79c57a..e8e04cc51ebc27da835b3e538665910ba461d55e 100644 (file)
--- a/src/sp-rect.cpp
+++ b/src/sp-rect.cpp
#include "sp-rect.h"
#include <glibmm/i18n.h>
#include "xml/repr.h"
+#include "sp-guide.h"
#define noRECT_VERBOSE
*p = NR::Point(rect->x.computed + rect->width.computed, rect->y.computed) * i2d;
}
+void
+sp_rect_convert_to_guides(SPRect *rect, bool write_undo) {
+ SPDocument *doc = SP_OBJECT_DOCUMENT(rect);
+ std::list<std::pair<Geom::Point, Geom::Point> > pts;
+
+ NR::Matrix const i2d (sp_item_i2d_affine(SP_ITEM(rect)));
+
+ NR::Point A1(NR::Point(rect->x.computed, rect->y.computed) * i2d);
+ NR::Point A2(NR::Point(rect->x.computed, rect->y.computed + rect->height.computed) * i2d);
+ NR::Point A3(NR::Point(rect->x.computed + rect->width.computed, rect->y.computed + rect->height.computed) * i2d);
+ NR::Point A4(NR::Point(rect->x.computed + rect->width.computed, rect->y.computed) * i2d);
+
+ pts.push_back(std::make_pair(A1.to_2geom(), A2.to_2geom()));
+ pts.push_back(std::make_pair(A2.to_2geom(), A3.to_2geom()));
+ pts.push_back(std::make_pair(A3.to_2geom(), A4.to_2geom()));
+ pts.push_back(std::make_pair(A4.to_2geom(), A1.to_2geom()));
+
+ sp_guide_pt_pairs_to_guides(doc, pts);
+
+ SP_OBJECT(rect)->deleteObject(true);
+
+ if (write_undo) {
+ sp_document_done(doc, SP_VERB_CONTEXT_RECT, _("Convert to guides"));
+ }
+}
+
/*
Local Variables:
mode:c++
diff --git a/src/sp-rect.h b/src/sp-rect.h
index 4cf3b24ba07994d03559e3cd5f56251fc72c0284..0133922e8a84e3ebce0a3f5552d6524629df23aa 100644 (file)
--- a/src/sp-rect.h
+++ b/src/sp-rect.h
void sp_rect_compensate_rxry (SPRect *rect, NR::Matrix xform);
+void sp_rect_convert_to_guides(SPRect *rect, bool write_undo = true);
+
#endif
diff --git a/src/verbs.cpp b/src/verbs.cpp
index 53650a262fa2b8b43ed79da18222b6588e6d9806..736ddc3d5201b0b8fa769b01b05c570e93d47f70 100644 (file)
--- a/src/verbs.cpp
+++ b/src/verbs.cpp
case SP_VERB_EDIT_SELECTION_2_MARKER:
sp_selection_to_marker();
break;
+ case SP_VERB_EDIT_SELECTION_2_GUIDES:
+ sp_selection_to_guides();
+ break;
case SP_VERB_EDIT_TILE:
sp_selection_tile();
break;
// TRANSLATORS: Convert selection to a line marker
new EditVerb(SP_VERB_EDIT_SELECTION_2_MARKER, "ObjectsToMarker", N_("Objects to _Marker"),
N_("Convert selection to a line marker"), NULL),
+ // TRANSLATORS: Convert selection to a collection of guidelines
+ new EditVerb(SP_VERB_EDIT_SELECTION_2_GUIDES, "ObjectsToGuides", N_("Objects to Gu_ides"),
+ N_("Convert selected objects to a collection of guidelines aligned with their edges"), NULL),
// TRANSLATORS: Convert selection to a rectangle with tiled pattern fill
new EditVerb(SP_VERB_EDIT_TILE, "ObjectsToPattern", N_("Objects to Patter_n"),
N_("Convert selection to a rectangle with tiled pattern fill"), NULL),
diff --git a/src/verbs.h b/src/verbs.h
index 9f5cbe3c81142085712175490a93f15923cd30c2..104d4db0de471f05e40f65d2331e7e1cdd0f985a 100644 (file)
--- a/src/verbs.h
+++ b/src/verbs.h
SP_VERB_EDIT_UNLINK_CLONE,
SP_VERB_EDIT_CLONE_SELECT_ORIGINAL,
SP_VERB_EDIT_SELECTION_2_MARKER,
+ SP_VERB_EDIT_SELECTION_2_GUIDES,
SP_VERB_EDIT_TILE,
SP_VERB_EDIT_UNTILE,
SP_VERB_EDIT_CLEAR_ALL,