Code

Fix LPE for groups bounding box calculation by using the SPItem->getBounds method.
authorbgk <bgk@users.sourceforge.net>
Sat, 17 May 2008 10:47:58 +0000 (10:47 +0000)
committerbgk <bgk@users.sourceforge.net>
Sat, 17 May 2008 10:47:58 +0000 (10:47 +0000)
Some preliminary work for LPE stacking.

src/live_effects/lpegroupbbox.cpp
src/live_effects/lpegroupbbox.h
src/sp-lpe-item.cpp
src/sp-lpe-item.h
src/sp-path.cpp
src/ui/dialog/livepatheffect-editor.cpp

index 50f7599c0700d26f4a43b79b55f5159618fee4a4..f797d03582ef379acead9573222f6bc9a6443954 100644 (file)
@@ -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 <algorithm>
-
-using std::vector;
 
 namespace Inkscape {
 namespace LivePathEffect {
 
 void
-GroupBBoxEffect::recursive_original_bbox(SPGroup *group, Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2, std::vector<Geom::Path> & temppath)
+GroupBBoxEffect::original_bbox(SPLPEItem *lpeitem, bool absolute)
 {
-    std::vector<Geom::Path> 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<SPObject *>(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<D2<SBasis> > pwd2;
-    std::vector<Geom::Path> 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<NR::Rect> itemBBox = item->getBounds(transform, SPItem::GEOMETRIC_BBOX);
 
-    D2<Piecewise<SBasis> > 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
index bf1fa09027dcd6f78cd34048fdf82f2fb2a19225..57577d20fab73d7a14aeb6bac8823f61995da0f5 100644 (file)
@@ -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<Geom::D2<Geom::SBasis> > & pwd2, std::vector<Geom::Path> & temppath);
-
-
-
+       //This sets boundingbox_X and boundingbox_Y
+    void original_bbox(SPLPEItem *lpeitem, bool absolute = false);
 };
 
 }; //namespace LivePathEffect
index eaf92704c4aaa856e5a2f64c8d43494a709c4309..b6a63e9b92ef53fb094a22188e0f5b05e2a7d416 100644 (file)
@@ -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);
 }
 
index b3e3d85fc5d17a1b5e31cec4b1b9a5473d6daf62..7d85bb2be854a934ccfea298a8b8cbc6c9c58995 100644 (file)
@@ -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);
index 14f04218f5e1476183e1c41dd9bd3485f1780c8e..20515c4cd7c7c52f49fc567b9f2d02264870e8aa 100644 (file)
@@ -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) {
index f62556d23ae64306b3f03509f33aa623431f8e34..d482232010c383e9f272996f5a865042f48231ca 100644 (file)
@@ -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"));