Code

NR::Maybe => boost::optional
[inkscape.git] / src / sp-item-group.cpp
index 6ec5256eecba218495c671843454d2622ef122b1..186b766635f1115ee63e0817401f4fd83af249c5 100644 (file)
@@ -23,6 +23,7 @@
 #include <string>
 
 #include "display/nr-arena-group.h"
+#include "display/curve.h"
 #include "libnr/nr-matrix-ops.h"
 #include "libnr/nr-matrix-fns.h"
 #include "xml/repr.h"
@@ -42,6 +43,8 @@
 #include "inkscape.h"
 #include "desktop-handles.h"
 #include "selection.h"
+#include "live_effects/lpeobject.h"
+#include "live_effects/lpeobject-reference.h"
 
 static void sp_group_class_init (SPGroupClass *klass);
 static void sp_group_init (SPGroup *group);
@@ -54,7 +57,7 @@ static void sp_group_remove_child (SPObject * object, Inkscape::XML::Node * chil
 static void sp_group_order_changed (SPObject * object, Inkscape::XML::Node * child, Inkscape::XML::Node * old_ref, Inkscape::XML::Node * new_ref);
 static void sp_group_update (SPObject *object, SPCtx *ctx, guint flags);
 static void sp_group_modified (SPObject *object, guint flags);
-static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static Inkscape::XML::Node *sp_group_write (SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 static void sp_group_set(SPObject *object, unsigned key, char const *value);
 
 static void sp_group_bbox(SPItem const *item, NRRect *bbox, NR::Matrix const &transform, unsigned const flags);
@@ -66,6 +69,7 @@ static void sp_group_hide (SPItem * item, unsigned int key);
 static void sp_group_snappoints (SPItem const *item, SnapPointsIter p);
 
 static void sp_group_update_patheffect(SPLPEItem *lpeitem, bool write);
+static void sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup);
 
 static SPLPEItemClass * parent_class;
 
@@ -125,7 +129,7 @@ sp_group_class_init (SPGroupClass *klass)
        item_class->show = sp_group_show;
        item_class->hide = sp_group_hide;
        item_class->snappoints = sp_group_snappoints;
-       
+
        lpe_item_class->update_patheffect = sp_group_update_patheffect;
 }
 
@@ -207,11 +211,14 @@ sp_group_update (SPObject *object, SPCtx *ctx, unsigned int flags)
 static void
 sp_group_modified (SPObject *object, guint flags)
 {
+    if (((SPObjectClass *) (parent_class))->modified)
+        ((SPObjectClass *) (parent_class))->modified (object, flags);
+
     SP_GROUP(object)->group->onModified(flags);
 }
 
 static Inkscape::XML::Node *
-sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
+sp_group_write (SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, guint flags)
 {
        SPGroup *group;
        SPObject *child;
@@ -222,12 +229,11 @@ sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
        if (flags & SP_OBJECT_WRITE_BUILD) {
                GSList *l;
                if (!repr) {
-                    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object));
                     repr = xml_doc->createElement("svg:g");
                 }
                l = NULL;
                for (child = sp_object_first_child(object); child != NULL; child = SP_OBJECT_NEXT(child) ) {
-                       crepr = child->updateRepr(NULL, flags);
+                       crepr = child->updateRepr(xml_doc, NULL, flags);
                        if (crepr) l = g_slist_prepend (l, crepr);
                }
                while (l) {
@@ -254,7 +260,7 @@ sp_group_write (SPObject *object, Inkscape::XML::Node *repr, guint flags)
        }
 
        if (((SPObjectClass *) (parent_class))->write)
-               ((SPObjectClass *) (parent_class))->write (object, repr, flags);
+               ((SPObjectClass *) (parent_class))->write (object, xml_doc, repr, flags);
 
        return repr;
 }
@@ -364,7 +370,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
             gitem = SP_ITEM(group);
         }
 
-        sp_lpe_item_remove_path_effect(SP_LPE_ITEM(group), false);
+        sp_lpe_item_remove_all_path_effects(SP_LPE_ITEM(group), false);
 
        /* Step 1 - generate lists of children objects */
        GSList *items = NULL;
@@ -451,8 +457,10 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
        if (objects) {
            Inkscape::XML::Node *last_def = SP_OBJECT_REPR(defs)->lastChild();
            while (objects) {
-               SP_OBJECT_REPR(defs)->addChild((Inkscape::XML::Node *) objects->data, last_def);
-               Inkscape::GC::release((Inkscape::XML::Node *) objects->data);
+                Inkscape::XML::Node *repr = (Inkscape::XML::Node *) objects->data;
+                if (!sp_repr_is_meta_element(repr))
+                    SP_OBJECT_REPR(defs)->addChild(repr, last_def);
+                Inkscape::GC::release(repr);
                objects = g_slist_remove (objects, objects->data);
            }
        }
@@ -470,7 +478,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
                SPItem *item = (SPItem *) doc->getObjectByRepr(repr);
 
                sp_item_write_transform(item, repr, item->transform, NULL, false);
-               
+
                Inkscape::GC::release(repr);
                if (children && SP_IS_ITEM (item))
                        *children = g_slist_prepend (*children, item);
@@ -478,7 +486,7 @@ sp_item_group_ungroup (SPGroup *group, GSList **children, bool do_done)
                items = g_slist_remove (items, items->data);
        }
 
-       if (do_done) 
+       if (do_done)
                sp_document_done (doc, SP_VERB_NONE, _("Ungroup"));
 }
 
@@ -625,7 +633,7 @@ void CGroup::onChildRemoved(Inkscape::XML::Node */*child*/) {
     _group->requestModified(SP_OBJECT_MODIFIED_FLAG);
 }
 
-void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) {    
+void CGroup::onUpdate(SPCtx *ctx, unsigned int flags) {
     SPItemCtx *ictx, cctx;
 
     ictx = (SPItemCtx *) ctx;
@@ -687,20 +695,20 @@ void CGroup::onModified(guint flags) {
 }
 
 void CGroup::calculateBBox(NRRect *bbox, NR::Matrix const &transform, unsigned const flags) {
-    
-    NR::Maybe<NR::Rect> dummy_bbox = NR::Nothing();
-    
+
+    boost::optional<NR::Rect> dummy_bbox;
+
     GSList *l = _group->childList(false, SPObject::ActionBBox);
     while (l) {
         SPObject *o = SP_OBJECT (l->data);
-        if (SP_IS_ITEM(o)) {
+        if (SP_IS_ITEM(o) && !SP_ITEM(o)->isHidden()) {
             SPItem *child = SP_ITEM(o);
             NR::Matrix const ct(child->transform * transform);
             sp_item_invoke_bbox_full(child, &dummy_bbox, ct, flags, FALSE);
-        }        
+        }
         l = g_slist_remove (l, o);
     }
-    
+
     *bbox = NRRect(dummy_bbox);
 }
 
@@ -710,7 +718,7 @@ void CGroup::onPrint(SPPrintContext *ctx) {
         SPObject *o = SP_OBJECT (l->data);
         if (SP_IS_ITEM(o)) {
             sp_item_invoke_print (SP_ITEM (o), ctx);
-        }        
+        }
         l = g_slist_remove (l, o);
     }
 }
@@ -722,7 +730,7 @@ gint CGroup::getItemCount() {
             len++;
         }
     }
-    
+
     return len;
 }
 
@@ -814,11 +822,46 @@ sp_group_update_patheffect (SPLPEItem *lpeitem, bool write)
     for ( GSList const *iter = item_list; iter; iter = iter->next ) {
         SPObject *subitem = static_cast<SPObject *>(iter->data);
         if (SP_IS_LPE_ITEM(subitem)) {
-            sp_lpe_item_update_patheffect(SP_LPE_ITEM(subitem), true);
+            if (SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect) {
+                SP_LPE_ITEM_CLASS (G_OBJECT_GET_CLASS (subitem))->update_patheffect (SP_LPE_ITEM(subitem), write);
+            }
+        }
+    }
+    
+    if (sp_lpe_item_has_path_effect(lpeitem) && sp_lpe_item_path_effects_enabled(lpeitem)) {
+        for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); it++)
+        {
+            LivePathEffectObject *lpeobj = (*it)->lpeobject;
+            lpeobj->lpe->doBeforeEffect(lpeitem);
         }
+        
+        sp_group_perform_patheffect(SP_GROUP(lpeitem), SP_GROUP(lpeitem));
     }
 }
 
+static void
+sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup)
+{
+    GSList const *item_list = sp_item_group_item_list(SP_GROUP(group));
+    for ( GSList const *iter = item_list; iter; iter = iter->next ) {
+        SPObject *subitem = static_cast<SPObject *>(iter->data);
+        if (SP_IS_GROUP(subitem)) {
+            sp_group_perform_patheffect(SP_GROUP(subitem), topgroup);
+        } else if (SP_IS_SHAPE(subitem)) {
+            SPCurve * c = sp_shape_get_curve(SP_SHAPE(subitem));
+            sp_lpe_item_perform_path_effect(SP_LPE_ITEM(topgroup), c);
+            sp_shape_set_curve(SP_SHAPE(subitem), c, TRUE);
+            
+            Inkscape::XML::Node *repr = SP_OBJECT_REPR(subitem);
+            gchar *str = sp_svg_write_path(c->get_pathvector());
+            repr->setAttribute("d", str);
+            g_free(str);
+
+            c->unref();
+        }
+    }
+}
 
 /*
   Local Variables: