From 7b51b20d1cccdd85e7ad54100fbae1dc755185af Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Tue, 4 Sep 2007 18:53:01 +0000 Subject: LPE: add Paste LPE verb + menu item. add scale ratios to curve stitch and path-along-path. remove trailing space in verbs.cpp. Fix initialization of BoolParam (bzr r3675) --- src/live_effects/effect.cpp | 29 ++++++++++++++++++++++++----- src/live_effects/lpe-curvestitch.cpp | 4 +++- src/live_effects/lpe-curvestitch.h | 1 + src/live_effects/lpe-skeletalstrokes.cpp | 18 ++++++++++++------ src/live_effects/lpe-skeletalstrokes.h | 3 +++ src/live_effects/parameter/bool.cpp | 2 +- src/live_effects/parameter/bool.h | 10 +++++----- 7 files changed, 49 insertions(+), 18 deletions(-) (limited to 'src/live_effects') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 30a90d834..29f9cb7ef 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -25,6 +25,8 @@ #include <2geom/sbasis-to-bezier.h> #include +#include + // include effects: #include "live_effects/lpe-skeletalstrokes.h" #include "live_effects/lpe-slant.h" @@ -114,7 +116,7 @@ Effect::doEffect (SPCurve * curve) { NArtBpath *new_bpath = doEffect(SP_CURVE_BPATH(curve)); - if (new_bpath) { // FIXME, add function to SPCurve to change bpath? or a copy function? + if (new_bpath && new_bpath != SP_CURVE_BPATH(curve)) { // FIXME, add function to SPCurve to change bpath? or a copy function? if (curve->_bpath) { g_free(curve->_bpath); //delete old bpath } @@ -125,13 +127,30 @@ Effect::doEffect (SPCurve * curve) NArtBpath * Effect::doEffect (NArtBpath * path_in) { - std::vector orig_pathv = BPath_to_2GeomPath(path_in); + try { + std::vector orig_pathv = BPath_to_2GeomPath(path_in); - std::vector result_pathv = doEffect(orig_pathv); + std::vector result_pathv = doEffect(orig_pathv); - NArtBpath *new_bpath = BPath_from_2GeomPath(result_pathv); + NArtBpath *new_bpath = BPath_from_2GeomPath(result_pathv); - return new_bpath; + return new_bpath; + } + catch (std::exception e) { + g_warning("An exception occurred during execution of an LPE - %s", e.what()); + // return here + NArtBpath *path_out; + + unsigned ret = 0; + while ( path_in[ret].code != NR_END ) { + ++ret; + } + unsigned len = ++ret; + + path_out = g_new(NArtBpath, len); + memcpy(path_out, path_in, len * sizeof(NArtBpath)); + return path_out; + } } std::vector diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index a0a473fe7..8eb35087e 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -41,12 +41,14 @@ LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) : nrofpaths(_("Nr of paths"), _("The number of paths that will be generated."), "count", &wr, this, 5), startpoint_variation(_("Startpoint variation"), _("..."), "startpoint_variation", &wr, this, 0), endpoint_variation(_("Endpoint variation"), _("..."), "endpoint_variation", &wr, this, 0), + prop_scale(_("Scale ratio"), _("Ratio between scaling in the x and y direction of the original path"), "prop_scale", &wr, this, 1), scale_y(_("Scale stroke y"), _("Scale the height of the stroke path with its length"), "scale_stroke_y", &wr, this, false) { registerParameter( dynamic_cast(&nrofpaths) ); registerParameter( dynamic_cast(&startpoint_variation) ); registerParameter( dynamic_cast(&endpoint_variation) ); registerParameter( dynamic_cast(&strokepath) ); + registerParameter( dynamic_cast(&prop_scale) ); registerParameter( dynamic_cast(&scale_y) ); nrofpaths.param_make_integer(); @@ -95,7 +97,7 @@ LPECurveStitch::doEffect (std::vector & path_in) Matrix transform; transform.setXAxis( (end-start) / scaling ); - gdouble scaling_y = scale_y.get_value() ? L2(end-start)/scaling : 1.0; + gdouble scaling_y = scale_y.get_value() ? (L2(end-start)/scaling)*prop_scale : 1.0; transform.setYAxis( rot90(unit_vector(end-start)) * scaling_y); transform.setTranslation( start ); Piecewise > pwd2_out = (strokepath-stroke_origin) * transform; diff --git a/src/live_effects/lpe-curvestitch.h b/src/live_effects/lpe-curvestitch.h index 2b3e4553e..66bbbc8f0 100644 --- a/src/live_effects/lpe-curvestitch.h +++ b/src/live_effects/lpe-curvestitch.h @@ -35,6 +35,7 @@ private: ScalarParam nrofpaths; RandomParam startpoint_variation; RandomParam endpoint_variation; + ScalarParam prop_scale; BoolParam scale_y; LPECurveStitch(const LPECurveStitch&); diff --git a/src/live_effects/lpe-skeletalstrokes.cpp b/src/live_effects/lpe-skeletalstrokes.cpp index 162dfe8a4..459b01861 100644 --- a/src/live_effects/lpe-skeletalstrokes.cpp +++ b/src/live_effects/lpe-skeletalstrokes.cpp @@ -58,11 +58,15 @@ static const Util::EnumDataConverter SkelCopyTypeConverter(SkelCop LPESkeletalStrokes::LPESkeletalStrokes(LivePathEffectObject *lpeobject) : Effect(lpeobject), - pattern(_("Pattern"), _("Path to put along path"), "pattern", &wr, this, "M0,0 L1,1"), - copytype(_("Copytype"), _("How to shape the pattern path along the path"), "copytype", SkelCopyTypeConverter, &wr, this, SSCT_SINGLE_STRETCHED) + pattern(_("Pattern"), _("Path to put along path"), "pattern", &wr, this, "M0,0 L1,0"), + copytype(_("Copytype"), _("How to shape the pattern path along the path"), "copytype", SkelCopyTypeConverter, &wr, this, SSCT_SINGLE_STRETCHED), + prop_scale(_("Scale ratio"), _("Ratio between scaling in the x and y direction of the original path"), "prop_scale", &wr, this, 1), + scale_y(_("Scale pattern y"), _("Scale the height of the pattern path with its length"), "scale_stroke_y", &wr, this, false) { registerParameter( dynamic_cast(&pattern) ); registerParameter( dynamic_cast(©type) ); + registerParameter( dynamic_cast(&prop_scale) ); + registerParameter( dynamic_cast(&scale_y) ); } LPESkeletalStrokes::~LPESkeletalStrokes() @@ -76,8 +80,7 @@ LPESkeletalStrokes::doEffect (Geom::Piecewise > & pwd2_in { using namespace Geom; -/* LOTS OF CODE COPIED FROM 2geom/src/toys/path-along-path.cpp - * All credits should go to jfb and mgsloan of lib2geom development! */ +/* Much credit should go to jfb and mgsloan of lib2geom development for the code below! */ SkelCopyType type = copytype.get_value(); @@ -94,7 +97,6 @@ LPESkeletalStrokes::doEffect (Geom::Piecewise > & pwd2_in Interval pattBndsY = bounds_exact(y); y -= (pattBndsY.max()+pattBndsY.min())/2; - int nbCopies = int(uskeleton.cuts.back()/pattBnds.extent()); double scaling = 1; @@ -121,8 +123,12 @@ LPESkeletalStrokes::doEffect (Geom::Piecewise > & pwd2_in double pattWidth = pattBnds.extent() * scaling; - if (scaling != 1) + if (scaling != 1.0) { x*=scaling; + } + if ( scale_y.get_value() && (scaling*prop_scale != 1.0) ) { + y*=(scaling*prop_scale); + } double offs = 0; Piecewise > output; diff --git a/src/live_effects/lpe-skeletalstrokes.h b/src/live_effects/lpe-skeletalstrokes.h index b92ea8ecf..f92b64454 100644 --- a/src/live_effects/lpe-skeletalstrokes.h +++ b/src/live_effects/lpe-skeletalstrokes.h @@ -12,6 +12,7 @@ #include "live_effects/effect.h" #include "live_effects/parameter/path.h" #include "live_effects/parameter/enum.h" +#include "live_effects/parameter/bool.h" namespace Inkscape { namespace LivePathEffect { @@ -34,6 +35,8 @@ public: private: PathParam pattern; EnumParam copytype; + ScalarParam prop_scale; + BoolParam scale_y; void on_pattern_pasted(); diff --git a/src/live_effects/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index af3449dff..f0d409955 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -26,7 +26,7 @@ namespace LivePathEffect { BoolParam::BoolParam( const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, Effect* effect, bool default_value ) - : Parameter(label, tip, key, wr, effect), defvalue(default_value) + : Parameter(label, tip, key, wr, effect), defvalue(default_value), value(default_value) { checkwdg = NULL; } diff --git a/src/live_effects/parameter/bool.h b/src/live_effects/parameter/bool.h index 24c10fb3b..0a29a9439 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -29,15 +29,15 @@ public: Inkscape::UI::Widget::Registry* wr, Effect* effect, bool default_value = false); - ~BoolParam(); + virtual ~BoolParam(); - Gtk::Widget * param_getWidget(); + virtual Gtk::Widget * param_getWidget(); - bool param_readSVGValue(const gchar * strvalue); - gchar * param_writeSVGValue() const; + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_writeSVGValue() const; void param_setValue(bool newvalue); - void param_set_default(); + virtual void param_set_default(); bool get_value() { return value; }; -- cgit v1.2.3