From 973abb22f878b62893ded7b94b401a25362b8bc7 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 14 Sep 2007 22:50:14 +0000 Subject: [PATCH] change Y-scaling for curve stiching and path-along-path. add warning message when path effect errors due to 2geom exception. --- src/live_effects/effect.cpp | 8 +++++--- src/live_effects/lpe-curvestitch.cpp | 18 ++++++++++------ src/live_effects/lpe-curvestitch.h | 2 +- src/live_effects/lpe-skeletalstrokes.cpp | 18 ++++++++++------ src/live_effects/lpe-skeletalstrokes.h | 2 +- src/live_effects/parameter/parameter.cpp | 26 ++++++++++++++++++++++++ src/live_effects/parameter/parameter.h | 5 +++++ 7 files changed, 62 insertions(+), 17 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 29f9cb7ef..0773363dd 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -10,9 +10,9 @@ #include "xml/node-event-vector.h" #include "sp-object.h" #include "attributes.h" - +#include "message-stack.h" #include "desktop.h" - +#include "inkscape.h" #include "document.h" #include @@ -138,7 +138,9 @@ Effect::doEffect (NArtBpath * path_in) } catch (std::exception e) { g_warning("An exception occurred during execution of an LPE - %s", e.what()); - // return here + SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE, + _("An exception occurred during execution of a Path Effect.") ); + NArtBpath *path_out; unsigned ret = 0; diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 8eb35087e..57ff8a25e 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -41,21 +41,21 @@ 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) + prop_scale(_("Y scaling"), _("Scaling of the width of the stroke path"), "prop_scale", &wr, this, 1), + scale_y_rel(_("Scale Y relative to X"), _("Scale the width of the stroke path relative to its length"), "scale_y_rel", &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) ); + registerParameter( dynamic_cast(&scale_y_rel) ); nrofpaths.param_make_integer(); nrofpaths.param_set_range(2, NR_HUGE); -// startpoint_variation.param_set_range(-NR_HUGE, 1); -// endpoint_variation.param_set_range(-1, NR_HUGE); + prop_scale.param_set_digits(3); + prop_scale.param_set_increments(0.01, 0.10); } LPECurveStitch::~LPECurveStitch() @@ -95,9 +95,15 @@ LPECurveStitch::doEffect (std::vector & path_in) if (endpoint_variation.get_value() != 0) end = end + endpoint_variation * (end - start); + gdouble scaling_y = 1.0; + if (scale_y_rel.get_value()) { + scaling_y = (L2(end-start)/scaling)*prop_scale; + } else { + scaling_y = prop_scale; + } + Matrix transform; transform.setXAxis( (end-start) / scaling ); - 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 66bbbc8f0..25ddb7719 100644 --- a/src/live_effects/lpe-curvestitch.h +++ b/src/live_effects/lpe-curvestitch.h @@ -36,7 +36,7 @@ private: RandomParam startpoint_variation; RandomParam endpoint_variation; ScalarParam prop_scale; - BoolParam scale_y; + BoolParam scale_y_rel; LPECurveStitch(const LPECurveStitch&); LPECurveStitch& operator=(const LPECurveStitch&); diff --git a/src/live_effects/lpe-skeletalstrokes.cpp b/src/live_effects/lpe-skeletalstrokes.cpp index 4152a920e..8521a2cee 100644 --- a/src/live_effects/lpe-skeletalstrokes.cpp +++ b/src/live_effects/lpe-skeletalstrokes.cpp @@ -12,6 +12,7 @@ #include #include "live_effects/n-art-bpath-2geom.h" #include "svg/svg.h" +#include "ui/widget/scalar.h" #include <2geom/sbasis.h> #include <2geom/sbasis-geometric.h> @@ -58,15 +59,18 @@ static const Util::EnumDataConverter SkelCopyTypeConverter(SkelCop LPESkeletalStrokes::LPESkeletalStrokes(LivePathEffectObject *lpeobject) : Effect(lpeobject), - pattern(_("Pattern source:"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), - copytype(_("Pattern copies:"), _("How many pattern copies to place along the skeleton path"), "copytype", SkelCopyTypeConverter, &wr, this, SSCT_SINGLE_STRETCHED), - prop_scale(_("Scale ratio:"), _("Ratio between scaling the length and width of the pattern"), "prop_scale", &wr, this, 1), - scale_y(_("Scale pattern width"), _("Scale the width of the pattern (perpendicular to skeleton) with its length"), "scale_stroke_y", &wr, this, false) + pattern(_("Pattern source"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), + copytype(_("Pattern copies"), _("How many pattern copies to place along the skeleton path"), "copytype", SkelCopyTypeConverter, &wr, this, SSCT_SINGLE_STRETCHED), + prop_scale(_("Y scaling"), _("Scaling of the width of the pattern"), "prop_scale", &wr, this, 1), + scale_y_rel(_("Scale Y relative to X"), _("Scale the width of the pattern relative to its length"), "scale_y_rel", &wr, this, false) { registerParameter( dynamic_cast(&pattern) ); registerParameter( dynamic_cast(©type) ); registerParameter( dynamic_cast(&prop_scale) ); - registerParameter( dynamic_cast(&scale_y) ); + registerParameter( dynamic_cast(&scale_y_rel) ); + + prop_scale.param_set_digits(3); + prop_scale.param_set_increments(0.01, 0.10); } LPESkeletalStrokes::~LPESkeletalStrokes() @@ -126,8 +130,10 @@ LPESkeletalStrokes::doEffect (Geom::Piecewise > & pwd2_in if (scaling != 1.0) { x*=scaling; } - if ( scale_y.get_value() && (scaling*prop_scale != 1.0) ) { + if ( scale_y_rel.get_value() ) { y*=(scaling*prop_scale); + } else { + if (prop_scale != 1.0) y *= prop_scale; } double offs = 0; diff --git a/src/live_effects/lpe-skeletalstrokes.h b/src/live_effects/lpe-skeletalstrokes.h index f92b64454..1bd286680 100644 --- a/src/live_effects/lpe-skeletalstrokes.h +++ b/src/live_effects/lpe-skeletalstrokes.h @@ -36,7 +36,7 @@ private: PathParam pattern; EnumParam copytype; ScalarParam prop_scale; - BoolParam scale_y; + BoolParam scale_y_rel; void on_pattern_pasted(); diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 0e9295a20..bb7ea4c9e 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -52,6 +52,9 @@ ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip, max = NR_HUGE; integer = false; rsu = NULL; + inc_step = 0.1; + inc_page = 1; + digits = 2; } ScalarParam::~ScalarParam() @@ -132,12 +135,35 @@ ScalarParam::param_getWidget() rsu->setValue(value); if (integer) param_make_integer(); + rsu->getS()->setDigits(digits); + rsu->getS()->setIncrements(inc_step, inc_page); rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); } return dynamic_cast (rsu->getS()); } +void +ScalarParam::param_set_digits(unsigned digits) +{ + this->digits = digits; + if (rsu) { + rsu->getS()->setDigits(digits); + } +} + +void +ScalarParam::param_set_increments(double step, double page) +{ + inc_step = step; + inc_page = page; + if (rsu) { + rsu->getS()->setIncrements(inc_step, inc_page); + } +} + + + } /* namespace LivePathEffect */ } /* namespace Inkscape */ diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index e6cabbdd9..fb0bb7103 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -77,6 +77,8 @@ public: void param_set_value(gdouble val); void param_make_integer(bool yes = true); void param_set_range(gdouble min, gdouble max); + void param_set_digits(unsigned digits); + void param_set_increments(double step, double page); virtual Gtk::Widget * param_getWidget(); @@ -90,6 +92,9 @@ protected: bool integer; gdouble defvalue; Inkscape::UI::Widget::RegisteredScalar * rsu; + unsigned digits; + double inc_step; + double inc_page; private: ScalarParam(const ScalarParam&); -- 2.30.2