From f8df4b9f0c17f7a47d467583bd9e4e2e89a9237d Mon Sep 17 00:00:00 2001 From: cilix42 Date: Mon, 18 Aug 2008 00:47:13 +0000 Subject: [PATCH] Toggle button in geometry toolbar to set limiting bounding box for LPELineSegment --- src/live_effects/lpe-line_segment.cpp | 20 +++++-------- src/live_effects/lpe-line_segment.h | 2 +- src/lpe-tool-context.cpp | 23 +++++++++++--- src/lpe-tool-context.h | 1 + src/widgets/toolbox.cpp | 43 ++++++++++++++++++++++++++- 5 files changed, 70 insertions(+), 19 deletions(-) diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp index 7c1cb9f3e..fee3607e1 100644 --- a/src/live_effects/lpe-line_segment.cpp +++ b/src/live_effects/lpe-line_segment.cpp @@ -14,6 +14,7 @@ */ #include "live_effects/lpe-line_segment.h" +#include "lpe-tool-context.h" #include <2geom/pathvector.h> #include <2geom/geom.h> @@ -46,26 +47,19 @@ LPELineSegment::~LPELineSegment() void LPELineSegment::doBeforeEffect (SPLPEItem *lpeitem) { - SPDocument *document = SP_OBJECT_DOCUMENT(lpeitem); - w = sp_document_width(document); - h = sp_document_height(document); - + lpetool_get_limiting_bbox_corners(SP_OBJECT_DOCUMENT(lpeitem), bboxA, bboxB); } std::vector LPELineSegment::doEffect_path (std::vector const & path_in) { + using namespace Geom; std::vector output; - A = Geom::initialPoint(path_in); - B = Geom::finalPoint(path_in); + A = initialPoint(path_in); + B = finalPoint(path_in); - Geom::Point E(0,0); - Geom::Point F(0,h); - Geom::Point G(w,h); - Geom::Point H(w,0); - - std::vector intersections = Geom::rect_line_intersect(E, G, A, B); + std::vector intersections = rect_line_intersect(bboxA, bboxB, A, B); if (intersections.size() < 2) { g_print ("Possible error - no intersection with limiting bounding box.\n"); @@ -81,7 +75,7 @@ LPELineSegment::doEffect_path (std::vector const & path_in) } Geom::Path path(A); - path.appendNew(B); + path.appendNew(B); output.push_back(path); diff --git a/src/live_effects/lpe-line_segment.h b/src/live_effects/lpe-line_segment.h index a64eea4cb..ed57d17fe 100644 --- a/src/live_effects/lpe-line_segment.h +++ b/src/live_effects/lpe-line_segment.h @@ -41,7 +41,7 @@ public: private: Geom::Point A, B; // intersections of the line segment with the limiting bounding box - Geom::Coord w, h; // document width and height + Geom::Point bboxA, bboxB; // upper left and lower right corner of limiting bounding box LPELineSegment(const LPELineSegment&); LPELineSegment& operator=(const LPELineSegment&); diff --git a/src/lpe-tool-context.cpp b/src/lpe-tool-context.cpp index 0b3fb25bf..af92074b0 100644 --- a/src/lpe-tool-context.cpp +++ b/src/lpe-tool-context.cpp @@ -374,6 +374,20 @@ lpetool_context_switch_mode(SPLPEToolContext *lc, Inkscape::LivePathEffect::Effe } } +void +lpetool_get_limiting_bbox_corners(SPDocument *document, Geom::Point &A, Geom::Point &B) { + Geom::Coord w = sp_document_width(document); + Geom::Coord h = sp_document_height(document); + + double ulx = prefs_get_double_attribute ("tools.lpetool", "bbox_upperleftx", 0); + double uly = prefs_get_double_attribute ("tools.lpetool", "bbox_upperlefty", 0); + double lrx = prefs_get_double_attribute ("tools.lpetool", "bbox_lowerrightx", w); + double lry = prefs_get_double_attribute ("tools.lpetool", "bbox_lowerrighty", h); + + A = Geom::Point(ulx, uly); + B = Geom::Point(lrx, lry); +} + /* * Reads the limiting bounding box from preferences and draws it on the screen */ @@ -390,11 +404,12 @@ lpetool_context_reset_limiting_bbox(SPLPEToolContext *lc) return; SPDocument *document = sp_desktop_document(lc->desktop); - Geom::Coord w = sp_document_width(document); - Geom::Coord h = sp_document_height(document); - Geom::Point A(0,0); - Geom::Point B(w,h); + Geom::Point A, B; + lpetool_get_limiting_bbox_corners(document, A, B); + NR::Matrix doc2dt(lc->desktop->doc2dt()); + A *= doc2dt; + B *= doc2dt; Geom::Rect rect(A, B); SPCurve *curve = SPCurve::new_from_rect(rect); diff --git a/src/lpe-tool-context.h b/src/lpe-tool-context.h index 5ee66dbad..8f46b3041 100644 --- a/src/lpe-tool-context.h +++ b/src/lpe-tool-context.h @@ -52,6 +52,7 @@ int lpetool_mode_to_index(Inkscape::LivePathEffect::EffectType const type); int lpetool_item_has_construction(SPLPEToolContext *lc, SPItem *item); bool lpetool_try_construction(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type); void lpetool_context_switch_mode(SPLPEToolContext *lc, Inkscape::LivePathEffect::EffectType const type); +void lpetool_get_limiting_bbox_corners(SPDocument *document, Geom::Point &A, Geom::Point &B); void lpetool_context_reset_limiting_bbox(SPLPEToolContext *lc); GType sp_lpetool_context_get_type(void); diff --git a/src/widgets/toolbox.cpp b/src/widgets/toolbox.cpp index 5676529c3..9f8cf1822 100644 --- a/src/widgets/toolbox.cpp +++ b/src/widgets/toolbox.cpp @@ -446,6 +446,7 @@ static gchar const * ui_descr = " " " " " " + " " " " " " " " @@ -4849,7 +4850,7 @@ sp_lpetool_toolbox_sel_changed(Inkscape::Selection *selection, GObject *tbl) g_object_set_data(tbl, "currentlpe", lpe); g_object_set_data(tbl, "currentlpeitem", lpeitem); gtk_action_set_sensitive(w, TRUE); - ege_select_one_action_set_active(act, lpels->end_type->get_value()); + ege_select_one_action_set_active(EGE_SELECT_ONE_ACTION(w), lpels->end_type.get_value()); } else { g_print (" - unsetting item\n"); g_object_set_data(tbl, "currentlpe", NULL); @@ -4879,6 +4880,33 @@ lpetool_toggle_show_bbox (GtkToggleAction *act, gpointer data) { } } +static void +lpetool_toggle_set_bbox (GtkToggleAction *act, gpointer data) { + g_print ("lpetool_toggle_set_bbox()\n"); + SPDesktop *desktop = static_cast(data); + Inkscape::Selection *selection = desktop->selection; + + boost::optional bbox = selection->bounds(); + + if (bbox) { + Geom::Point A(bbox->min()); + Geom::Point B(bbox->max()); + + A *= desktop->doc2dt(); + B *= desktop->doc2dt(); + + // TODO: should we provide a way to store points in prefs? + prefs_set_double_attribute ("tools.lpetool", "bbox_upperleftx", A[Geom::X]); + prefs_set_double_attribute ("tools.lpetool", "bbox_upperlefty", A[Geom::Y]); + prefs_set_double_attribute ("tools.lpetool", "bbox_lowerrightx", B[Geom::X]); + prefs_set_double_attribute ("tools.lpetool", "bbox_lowerrighty", B[Geom::Y]); + + lpetool_context_reset_limiting_bbox(SP_LPETOOL_CONTEXT(desktop->event_context)); + } + + gtk_toggle_action_set_active(act, false); +} + static void sp_line_segment_build_list(GObject *tbl) { @@ -4991,6 +5019,19 @@ static void sp_lpetool_toolbox_prep(SPDesktop *desktop, GtkActionGroup* mainActi gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), prefs_get_int_attribute( "tools.lpetool", "show_bbox", 1 ) ); } + /* Set limiting bounding box to bbox of current selection */ + { + InkToggleAction* act = ink_toggle_action_new( "LPEBBoxFromSelectionAction", + _("Get limiting bounding box from selection"), + _("Set limiting bounding box (used to cut infinite lines) to the bounding box of current selection"), + "lpetool_set_bbox", + Inkscape::ICON_SIZE_DECORATION ); + gtk_action_group_add_action( mainActions, GTK_ACTION( act ) ); + g_signal_connect_after( G_OBJECT(act), "toggled", G_CALLBACK(lpetool_toggle_set_bbox), desktop ); + gtk_toggle_action_set_active( GTK_TOGGLE_ACTION(act), FALSE ); + } + + /* Combo box to choose line segment type */ { GtkListStore* model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT); -- 2.30.2