summaryrefslogtreecommitdiffstats
path: root/src/live_effects
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2007-09-04 18:53:01 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2007-09-04 18:53:01 +0000
commit7b51b20d1cccdd85e7ad54100fbae1dc755185af (patch)
tree68ccc4af1fbae73c6ebd3740f08d8ea8e20df1c4 /src/live_effects
parentUpdated to match API changes in style.h (diff)
downloadinkscape-7b51b20d1cccdd85e7ad54100fbae1dc755185af.tar.gz
inkscape-7b51b20d1cccdd85e7ad54100fbae1dc755185af.zip
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)
Diffstat (limited to 'src/live_effects')
-rw-r--r--src/live_effects/effect.cpp29
-rw-r--r--src/live_effects/lpe-curvestitch.cpp4
-rw-r--r--src/live_effects/lpe-curvestitch.h1
-rw-r--r--src/live_effects/lpe-skeletalstrokes.cpp18
-rw-r--r--src/live_effects/lpe-skeletalstrokes.h3
-rw-r--r--src/live_effects/parameter/bool.cpp2
-rw-r--r--src/live_effects/parameter/bool.h10
7 files changed, 49 insertions, 18 deletions
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 <gtkmm.h>
+#include <exception>
+
// 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<Geom::Path> orig_pathv = BPath_to_2GeomPath(path_in);
+ try {
+ std::vector<Geom::Path> orig_pathv = BPath_to_2GeomPath(path_in);
- std::vector<Geom::Path> result_pathv = doEffect(orig_pathv);
+ std::vector<Geom::Path> 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<Geom::Path>
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<Parameter *>(&nrofpaths) );
registerParameter( dynamic_cast<Parameter *>(&startpoint_variation) );
registerParameter( dynamic_cast<Parameter *>(&endpoint_variation) );
registerParameter( dynamic_cast<Parameter *>(&strokepath) );
+ registerParameter( dynamic_cast<Parameter *>(&prop_scale) );
registerParameter( dynamic_cast<Parameter *>(&scale_y) );
nrofpaths.param_make_integer();
@@ -95,7 +97,7 @@ LPECurveStitch::doEffect (std::vector<Geom::Path> & 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<D2<SBasis> > 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<SkelCopyType> 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<Parameter *>(&pattern) );
registerParameter( dynamic_cast<Parameter *>(&copytype) );
+ registerParameter( dynamic_cast<Parameter *>(&prop_scale) );
+ registerParameter( dynamic_cast<Parameter *>(&scale_y) );
}
LPESkeletalStrokes::~LPESkeletalStrokes()
@@ -76,8 +80,7 @@ LPESkeletalStrokes::doEffect (Geom::Piecewise<Geom::D2<Geom::SBasis> > & 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<Geom::D2<Geom::SBasis> > & 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<Geom::D2<Geom::SBasis> > & 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<D2<SBasis> > 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<SkelCopyType> 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; };