From: bgk Date: Sat, 17 May 2008 10:47:58 +0000 (+0000) Subject: Fix LPE for groups bounding box calculation by using the SPItem->getBounds method. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6dee13f1978edf532e28b55de684694f0b2e9449;p=inkscape.git Fix LPE for groups bounding box calculation by using the SPItem->getBounds method. Some preliminary work for LPE stacking. --- diff --git a/src/live_effects/lpegroupbbox.cpp b/src/live_effects/lpegroupbbox.cpp index 50f7599c0..f797d0358 100644 --- a/src/live_effects/lpegroupbbox.cpp +++ b/src/live_effects/lpegroupbbox.cpp @@ -7,80 +7,34 @@ */ #include "live_effects/lpegroupbbox.h" -#include "sp-shape.h" + #include "sp-item.h" -#include "sp-path.h" -#include "sp-item-group.h" +#include "libnr/nr-matrix-fns.h" #include "libnr/n-art-bpath-2geom.h" -#include "svg/svg.h" -#include "ui/widget/scalar.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 - -using std::vector; namespace Inkscape { namespace LivePathEffect { void -GroupBBoxEffect::recursive_original_bbox(SPGroup *group, Geom::Piecewise > & pwd2, std::vector & temppath) +GroupBBoxEffect::original_bbox(SPLPEItem *lpeitem, bool absolute) { - std::vector tempsubpath; - GSList const *item_list = sp_item_group_item_list(group); - - for ( GSList const *iter = item_list; iter; iter = iter->next ) - { - SPObject *subitem = static_cast(iter->data); - if (SP_IS_PATH(subitem)) - { - //if there is not an original-d, just take the d - if(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d") != NULL) - tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("inkscape:original-d")); - else - tempsubpath = SVGD_to_2GeomPath(SP_OBJECT_REPR(subitem)->attribute("d")); - - temppath.insert(temppath.end(), tempsubpath.begin(), tempsubpath.end()); - } - else if (SP_IS_GROUP(subitem)) - { - recursive_original_bbox(SP_GROUP(subitem), pwd2, temppath); - } + // Get item bounding box + SPItem* item = SP_ITEM(lpeitem); + + NR::Matrix transform; + if (absolute) { + transform = sp_item_i2doc_affine(item); } -} - -void -GroupBBoxEffect::original_bbox(SPLPEItem *lpeitem) -{ - - using namespace Geom; - Piecewise > pwd2; - std::vector temppath; - - - if (SP_IS_PATH(lpeitem)) - { - //TODO : this won't work well with LPE stacking - temppath = SVGD_to_2GeomPath( SP_OBJECT_REPR(lpeitem)->attribute("inkscape:original-d")); - } - else if (SP_IS_GROUP(lpeitem)) - { - recursive_original_bbox(SP_GROUP(lpeitem), pwd2, temppath); - } - - for (unsigned int i=0; i < temppath.size(); i++) { - pwd2.concat( temppath[i].toPwSb() ); + else { + transform = NR::identity(); } + + NR::Maybe itemBBox = item->getBounds(transform, SPItem::GEOMETRIC_BBOX); - D2 > d2pw = make_cuts_independant(pwd2); - boundingbox_X = bounds_exact(d2pw[0]); - boundingbox_Y = bounds_exact(d2pw[1]); + // NR to Geom glue + Geom::Rect geomBBox = Geom::Rect(itemBBox->min().to_2geom(), itemBBox->max().to_2geom()); + boundingbox_X = geomBBox[Geom::X]; + boundingbox_Y = geomBBox[Geom::Y]; } } // namespace LivePathEffect diff --git a/src/live_effects/lpegroupbbox.h b/src/live_effects/lpegroupbbox.h index bf1fa0902..57577d20f 100644 --- a/src/live_effects/lpegroupbbox.h +++ b/src/live_effects/lpegroupbbox.h @@ -8,35 +8,21 @@ * * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "live_effects/effect.h" -#include "live_effects/parameter/path.h" -#include "live_effects/parameter/enum.h" -#include "live_effects/parameter/bool.h" +#include "sp-lpe-item.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 <2geom/interval.h> namespace Inkscape { namespace LivePathEffect { class GroupBBoxEffect { protected: -//if we need information concerning the group Bounding box and coordinates of each subshapes. + // Bounding box of the item the path effect is applied on Geom::Interval boundingbox_X; Geom::Interval boundingbox_Y; -//This set boundingbox_X and boundingbox_Y - void original_bbox(SPLPEItem *lpeitem); - -//Here is a recursive function to calculate the bbox of a group - void recursive_original_bbox(SPGroup *group, Geom::Piecewise > & pwd2, std::vector & temppath); - - - + //This sets boundingbox_X and boundingbox_Y + void original_bbox(SPLPEItem *lpeitem, bool absolute = false); }; }; //namespace LivePathEffect diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index eaf92704c..b6a63e9b9 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -257,9 +257,10 @@ void sp_lpe_item_perform_path_effect(SPLPEItem *lpeitem, SPCurve *curve) { if (sp_lpe_item_has_path_effect(lpeitem)) { LivePathEffectObject *lpeobj = sp_lpe_item_get_livepatheffectobject(lpeitem); + lpeobj->lpe->doBeforeEffect(lpeitem); lpeobj->lpe->doEffect(curve); } - + SPObject *parent = lpeitem->parent; if (parent && SP_IS_LPE_ITEM(parent)) sp_lpe_item_perform_path_effect(SP_LPE_ITEM(parent), curve); @@ -277,11 +278,6 @@ sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool write) g_return_if_fail (lpeitem != NULL); g_return_if_fail (SP_IS_LPE_ITEM (lpeitem)); - if (sp_lpe_item_has_path_effect(lpeitem)) { - LivePathEffectObject *lpeobj = sp_lpe_item_get_livepatheffectobject(lpeitem); - lpeobj->lpe->doBeforeEffect(lpeitem); - } - if (SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (lpeitem))->update_patheffect) { SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (lpeitem))->update_patheffect (lpeitem, write); } @@ -358,13 +354,22 @@ sp_lpe_item_cleanup_original_path_recursive(SPLPEItem *lpeitem) } } -void sp_lpe_item_set_path_effect(SPLPEItem *lpeitem, gchar *value) +void sp_lpe_item_set_path_effect(SPLPEItem *lpeitem, gchar *value, bool reset) { if (!value) { sp_lpe_item_remove_path_effect(lpeitem, false); } else { SP_OBJECT_REPR(lpeitem)->setAttribute("inkscape:path-effect", value); + // Ask the path effect to reset itself if it doesn't have parameters yet + if (lpeitem->path_effect_ref && reset) { + LivePathEffectObject *lpeobj = lpeitem->path_effect_ref->lpeobject; + if (lpeobj && lpeobj->lpe) { + // has to be called when all the subitems have their lpes applied + lpeobj->lpe->resetDefaults(lpeitem); + } + } + // make sure there is an original-d for paths!!! sp_lpe_item_create_original_path_recursive(lpeitem); } @@ -374,7 +379,7 @@ void sp_lpe_item_set_path_effect(SPLPEItem *lpeitem, LivePathEffectObject * new_ { const gchar * repr_id = SP_OBJECT_REPR(new_lpeobj)->attribute("id"); gchar *hrefstr = g_strdup_printf("#%s", repr_id); - sp_lpe_item_set_path_effect(lpeitem, hrefstr); + sp_lpe_item_set_path_effect(lpeitem, hrefstr, false); g_free(hrefstr); } diff --git a/src/sp-lpe-item.h b/src/sp-lpe-item.h index b3e3d85fc..7d85bb2be 100644 --- a/src/sp-lpe-item.h +++ b/src/sp-lpe-item.h @@ -48,7 +48,7 @@ LivePathEffectObject * sp_lpe_item_get_livepatheffectobject(SPLPEItem *lpeitem); Inkscape::LivePathEffect::Effect * sp_lpe_item_get_livepatheffect(SPLPEItem *lpeitem); void sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool write); void sp_lpe_item_perform_path_effect(SPLPEItem *lpeitem, SPCurve *curve); -void sp_lpe_item_set_path_effect(SPLPEItem *lpeitem, gchar *value); +void sp_lpe_item_set_path_effect(SPLPEItem *lpeitem, gchar *value, bool reset); void sp_lpe_item_set_path_effect(SPLPEItem *lpeitem, LivePathEffectObject * new_lpeobj); void sp_lpe_item_remove_path_effect(SPLPEItem *lpeitem, bool keep_paths); bool sp_lpe_item_has_path_effect(SPLPEItem *lpeitem); diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 14f04218f..20515c4cd 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -416,8 +416,9 @@ sp_path_update_patheffect(SPLPEItem *lpeitem, bool write) SPPath *path = (SPPath *) lpeitem; if (path->original_curve) { SPCurve *curve = path->original_curve->copy(); + sp_shape_set_curve_insync(shape, curve, TRUE); sp_lpe_item_perform_path_effect(SP_LPE_ITEM(shape), curve); - sp_shape_set_curve(shape, curve, TRUE); + SP_OBJECT(shape)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); curve->unref(); if (write) { diff --git a/src/ui/dialog/livepatheffect-editor.cpp b/src/ui/dialog/livepatheffect-editor.cpp index f62556d23..d48223201 100644 --- a/src/ui/dialog/livepatheffect-editor.cpp +++ b/src/ui/dialog/livepatheffect-editor.cpp @@ -247,14 +247,9 @@ LivePathEffectEditor::onApply() Inkscape::GC::release(repr); gchar *href = g_strdup_printf("#%s", repr_id); - sp_lpe_item_set_path_effect(SP_LPE_ITEM(item), href); + sp_lpe_item_set_path_effect(SP_LPE_ITEM(item), href, true); g_free(href); - LivePathEffectObject *lpeobj = sp_lpe_item_get_livepatheffectobject(SP_LPE_ITEM(item)); - if (lpeobj && lpeobj->lpe) { - lpeobj->lpe->resetDefaults(item); - } - sp_document_done(doc, SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Create and apply path effect"));