From 6ba273d25f2e2e2697d502eb9b56c10da96d7c1e Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Fri, 28 Mar 2008 19:13:14 +0000 Subject: - 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) --- src/live_effects/lpe-pathalongpath.cpp | 88 ++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 19 deletions(-) (limited to 'src/live_effects/lpe-pathalongpath.cpp') 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 + * Copyright (C) Steren Giannini 2008 * * 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 #include @@ -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 > pwd2; + std::vector temppath; + + recursive_original_bbox(SP_GROUP(lpeitem), pwd2, temppath); + + for (unsigned int i=0; i < temppath.size(); i++) { + pwd2.concat( temppath[i].toPwSb() ); + } + + D2 > d2pw = make_cuts_independant(pwd2); + boundingbox_X = bounds_exact(d2pw[0]); + boundingbox_Y = bounds_exact(d2pw[1]); + } + +} + Geom::Piecewise > LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise > & pwd2_in) @@ -89,14 +117,19 @@ LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise > & pwd2 D2 > patternd2 = make_cuts_independant(pwd2_in); Piecewise x = vertical_pattern.get_value() ? Piecewise(patternd2[1]) : Piecewise(patternd2[0]); Piecewise y = vertical_pattern.get_value() ? Piecewise(patternd2[0]) : Piecewise(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 > & pwd2 if (prop_scale != 1.0) y *= prop_scale; } + Piecewise > output = compose(uskeleton,x) + y*compose(n,x); return output; } @@ -113,29 +147,45 @@ LPEPathAlongPath::doEffect_pwd2 (Geom::Piecewise > & 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 > pwd2; + std::vector 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 > pwd2; - std::vector 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 > 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( end ); bend_path.param_set_and_write_new_value( path.toPwSb() ); + + + } } void -- cgit v1.2.3