diff options
| author | Bastien Bouclet <bastien.bouclet@gmail.com> | 2008-03-28 19:13:14 +0000 |
|---|---|---|
| committer | bgk <bgk@users.sourceforge.net> | 2008-03-28 19:13:14 +0000 |
| commit | 6ba273d25f2e2e2697d502eb9b56c10da96d7c1e (patch) | |
| tree | 33a74ec0fae6b19d0948ce84a49c350767c8be7d /src/live_effects | |
| parent | nr_matrix_inverse is no more, removed test from nr-matrix-test (diff) | |
| download | inkscape-6ba273d25f2e2e2697d502eb9b56c10da96d7c1e.tar.gz inkscape-6ba273d25f2e2e2697d502eb9b56c10da96d7c1e.zip | |
- Created a SPLPEItem class that handles applying a LPE to an Item
- LPEs can now be applied to groups
- Updated the bend path to work properly with groups
(bzr r5219)
Diffstat (limited to 'src/live_effects')
| -rw-r--r-- | src/live_effects/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/live_effects/effect.cpp | 7 | ||||
| -rw-r--r-- | src/live_effects/effect.h | 3 | ||||
| -rw-r--r-- | src/live_effects/lpe-pathalongpath.cpp | 88 | ||||
| -rw-r--r-- | src/live_effects/lpe-pathalongpath.h | 19 |
5 files changed, 98 insertions, 21 deletions
diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index d7cc55939..fee34a9d6 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -10,6 +10,8 @@ live_effects_liblive_effects_a_SOURCES = \ live_effects/effect.h \ live_effects/lpeobject.cpp \ live_effects/lpeobject.h \ + live_effects/lpegroupbbox.cpp \ + live_effects/lpegroupbbox.h \ live_effects/lpeobject-reference.cpp \ live_effects/lpeobject-reference.h \ live_effects/n-art-bpath-2geom.cpp \ diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 777be6e77..dc43af0d5 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -132,6 +132,13 @@ Effect::getName() return Glib::ustring( _("No effect") ); } +void +Effect::doBeforeEffect (SPLPEItem *lpeitem) +{ + //Do nothing for simple effects +} + + /* * Here be the doEffect function chain: */ diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 6b5295071..b13ec5f6d 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -16,6 +16,7 @@ #include <2geom/path.h> #include "ui/widget/registry.h" #include "util/enums.h" +#include "sp-lpe-item.h" #define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this. @@ -75,6 +76,8 @@ public: virtual ~Effect(); + virtual void doBeforeEffect (SPLPEItem *lpeitem); + virtual void doEffect (SPCurve * curve); virtual Gtk::Widget * newWidget(Gtk::Tooltips * tooltips); diff --git a/src/live_effects/lpe-pathalongpath.cpp b/src/live_effects/lpe-pathalongpath.cpp index 0475f4603..d17a0f84f 100644 --- a/src/live_effects/lpe-pathalongpath.cpp +++ b/src/live_effects/lpe-pathalongpath.cpp @@ -2,6 +2,7 @@ /* * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * Copyright (C) Steren Giannini 2008 <steren.giannini@gmail.com> * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -10,6 +11,7 @@ #include "sp-shape.h" #include "sp-item.h" #include "sp-path.h" +#include "sp-item-group.h" #include "display/curve.h" #include <libnr/n-art-bpath.h> #include <libnr/nr-matrix-fns.h> @@ -66,6 +68,8 @@ LPEPathAlongPath::LPEPathAlongPath(LivePathEffectObject *lpeobject) : prop_scale.param_set_digits(3); prop_scale.param_set_increments(0.01, 0.10); + + groupSpecialBehavior = false; } LPEPathAlongPath::~LPEPathAlongPath() @@ -73,6 +77,30 @@ LPEPathAlongPath::~LPEPathAlongPath() } +void +LPEPathAlongPath::doBeforeEffect (SPLPEItem *lpeitem) +{ + if(SP_IS_GROUP(lpeitem)) + { + groupSpecialBehavior = true; + + using namespace Geom; + Piecewise<D2<SBasis> > pwd2; + std::vector<Geom::Path> temppath; + + recursive_original_bbox(SP_GROUP(lpeitem), pwd2, temppath); + + for (unsigned int i=0; i < temppath.size(); i++) { + pwd2.concat( temppath[i].toPwSb() ); + } + + D2<Piecewise<SBasis> > d2pw = make_cuts_independant(pwd2); + boundingbox_X = bounds_exact(d2pw[0]); + boundingbox_Y = bounds_exact(d2pw[1]); + } + +} + Geom::Piecewise<Geom::D2<Geom::SBasis> > LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in) @@ -89,14 +117,19 @@ LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2 D2<Piecewise<SBasis> > patternd2 = make_cuts_independant(pwd2_in); Piecewise<SBasis> x = vertical_pattern.get_value() ? Piecewise<SBasis>(patternd2[1]) : Piecewise<SBasis>(patternd2[0]); Piecewise<SBasis> y = vertical_pattern.get_value() ? Piecewise<SBasis>(patternd2[0]) : Piecewise<SBasis>(patternd2[1]); - Interval pattBnds = bounds_exact(x); - x -= pattBnds.min(); - Interval pattBndsY = bounds_exact(y); - y -= pattBndsY.middle(); - double scaling = uskeleton.cuts.back()/pattBnds.extent(); +//We use the group bounding box size or the path bbox size to translate well x and y + if(groupSpecialBehavior == false) + { + boundingbox_X = bounds_exact(x); + boundingbox_Y = bounds_exact(y); + } + x-= boundingbox_X.min(); + y-= boundingbox_Y.middle(); + + double scaling = uskeleton.cuts.back()/boundingbox_X.extent(); - if (scaling != 1.0) { + if (scaling != 1.0) { x*=scaling; } @@ -106,6 +139,7 @@ LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2 if (prop_scale != 1.0) y *= prop_scale; } + Piecewise<D2<SBasis> > output = compose(uskeleton,x) + y*compose(n,x); return output; } @@ -113,29 +147,45 @@ LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2 void LPEPathAlongPath::resetDefaults(SPItem * item) { - if (!SP_IS_PATH(item)) return; + if (SP_IS_PATH(item) || SP_IS_GROUP(item)) + { + // set the bend path to run horizontally in the middle of the bounding box of the original path + using namespace Geom; + Piecewise<D2<SBasis> > pwd2; + std::vector<Geom::Path> temppath; + + if (SP_IS_PATH(item)) + { + //TODO : this won't work well with LPE stacking + temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d")); + } + else if (SP_IS_GROUP(item)) + { + recursive_original_bbox(SP_GROUP(item), pwd2, temppath); + } - using namespace Geom; - - // set the bend path to run horizontally in the middle of the bounding box of the original path - Piecewise<D2<SBasis> > pwd2; - std::vector<Geom::Path> temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(item)->attribute("inkscape:original-d")); for (unsigned int i=0; i < temppath.size(); i++) { pwd2.concat( temppath[i].toPwSb() ); - } + } + D2<Piecewise<SBasis> > d2pw = make_cuts_independant(pwd2); - Interval bndsX = bounds_exact(d2pw[0]); - Interval bndsY = bounds_exact(d2pw[1]); - Point start(bndsX.min(), (bndsY.max()+bndsY.min())/2); - Point end(bndsX.max(), (bndsY.max()+bndsY.min())/2); + boundingbox_X = bounds_exact(d2pw[0]); + boundingbox_Y = bounds_exact(d2pw[1]); + + + Point start(boundingbox_X.min(), (boundingbox_Y.max()+boundingbox_Y.min())/2); + Point end(boundingbox_X.max(), (boundingbox_Y.max()+boundingbox_Y.min())/2); if ( Geom::are_near(start,end) ) { - end += Point(1.,0.); - } + end += Point(1.,0.); + } Geom::Path path; path.start( start ); path.appendNew<Geom::LineSegment>( end ); bend_path.param_set_and_write_new_value( path.toPwSb() ); + + + } } void diff --git a/src/live_effects/lpe-pathalongpath.h b/src/live_effects/lpe-pathalongpath.h index 11d28530a..f1578d5bf 100644 --- a/src/live_effects/lpe-pathalongpath.h +++ b/src/live_effects/lpe-pathalongpath.h @@ -4,7 +4,8 @@ /* * Inkscape::LPEPathAlongPath * -* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl> + * Copyright (C) Steren Giannini 2008 <steren.giannini@gmail.com> * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -14,14 +15,26 @@ #include "live_effects/parameter/enum.h" #include "live_effects/parameter/bool.h" +#include <2geom/sbasis.h> +#include <2geom/sbasis-geometric.h> +#include <2geom/bezier-to-sbasis.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> +#include <2geom/piecewise.h> + +#include "live_effects/lpegroupbbox.h" + namespace Inkscape { namespace LivePathEffect { -class LPEPathAlongPath : public Effect { +//for Bend path on group : we need information concerning the group Bounding box +class LPEPathAlongPath : public Effect, LivePathEffect_group_bbox { public: LPEPathAlongPath(LivePathEffectObject *lpeobject); virtual ~LPEPathAlongPath(); + virtual void doBeforeEffect (SPLPEItem *lpeitem); + virtual Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in); virtual void resetDefaults(SPItem * item); @@ -34,6 +47,8 @@ private: BoolParam scale_y_rel; BoolParam vertical_pattern; + bool groupSpecialBehavior; + void on_pattern_pasted(); LPEPathAlongPath(const LPEPathAlongPath&); |
