Code

now that selection description includes style (filtered, clipped), we need to update...
[inkscape.git] / src / sp-lpe-item.cpp
index 2b0379cd4b86475106146c93db69035491eef282..f1e4c96c28bc4949299f1659c912e100cab7c677 100644 (file)
@@ -209,19 +209,17 @@ sp_lpe_item_set(SPObject *object, unsigned int key, gchar const *value)
                         try {
                             path_effect_ref->link(href.c_str());
                         } catch (Inkscape::BadURIException e) {
-                            g_warning("BadURIException: %s", e.what());
+                            g_warning("BadURIException when trying to find LPE: %s", e.what());
                             path_effect_ref->unlink();
                             delete path_effect_ref;
                             path_effect_ref = NULL;
                         }
 
-                        if (path_effect_ref && path_effect_ref->lpeobject && path_effect_ref->lpeobject->lpe) {
-                            lpeitem->path_effect_list->push_back(path_effect_ref);
-                        } else {
-                            // something has gone wrong in finding the right patheffect. For example when the specified LPE name does not exist.
-                            path_effect_ref->unlink();
-                            delete path_effect_ref;
-                            path_effect_ref = NULL;
+                        lpeitem->path_effect_list->push_back(path_effect_ref);
+                        if ( !(path_effect_ref->lpeobject && path_effect_ref->lpeobject->get_lpe()) ) {
+                            // something has gone wrong in finding the right patheffect.
+                            g_warning("Unknown LPE type specified, LPE stack effectively disabled");
+                            // keep the effect in the lpestack, so the whole stack is effectively disabled but maintained
                         }
                     }
                 }
@@ -254,8 +252,7 @@ sp_lpe_item_update(SPObject *object, SPCtx *ctx, guint flags)
     // FIXME: ditch inkscape_active_event_context()
     SPEventContext *ec = inkscape_active_event_context();
     if (!SP_IS_NODE_CONTEXT(ec)) return;
-    SPNodeContext *nc = SP_NODE_CONTEXT(ec);
-    ShapeEditor *sh = nc->shape_editor;
+    ShapeEditor *sh = ec->shape_editor;
     g_assert(sh);
     if (!sh->has_nodepath()) return;
 
@@ -300,29 +297,38 @@ sp_lpe_item_write(SPObject *object, Inkscape::XML::Document *xml_doc, Inkscape::
     return repr;
 }
 
-void sp_lpe_item_perform_path_effect(SPLPEItem *lpeitem, SPCurve *curve) {
-    if (!lpeitem) return;
-    if (!curve) return;
+/**
+ * returns true when LPE was successful.
+ */
+bool sp_lpe_item_perform_path_effect(SPLPEItem *lpeitem, SPCurve *curve) {
+    if (!lpeitem) return false;
+    if (!curve) return false;
 
     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;
             if (!lpeobj) {
+                /** \todo Investigate the cause of this.
+                 * For example, this happens when copy pasting an object with LPE applied. Probably because the object is pasted while the effect is not yet pasted to defs, and cannot be found.
+                 */
                 g_warning("sp_lpe_item_perform_path_effect - NULL lpeobj in list!");
-                return;
+                return false;
             }
-            if (!lpeobj->lpe) {
-                g_warning("sp_lpe_item_perform_path_effect - lpeobj without lpe!");
-                return;
+            Inkscape::LivePathEffect::Effect *lpe = lpeobj->get_lpe();
+            if (!lpe) {
+                /** \todo Investigate the cause of this.
+                 * Not sure, but I think this can happen when an unknown effect type is specified...
+                 */
+                g_warning("sp_lpe_item_perform_path_effect - lpeobj with invalid lpe in the stack!");
+                return false;
             }
 
-            Inkscape::LivePathEffect::Effect *lpe = lpeobj->lpe;
             if (lpe->isVisible()) {
                 if (lpe->acceptsNumClicks() > 0 && !lpe->isReady()) {
                     // if the effect expects mouse input before being applied and the input is not finished
                     // yet, we don't alter the path
-                    return;
+                    return false;
                 }
 
                 // Groups have their doBeforeEffect called elsewhere
@@ -335,12 +341,17 @@ void sp_lpe_item_perform_path_effect(SPLPEItem *lpeitem, SPCurve *curve) {
                 }
                 catch (std::exception & e) {
                     g_warning("Exception during LPE %s execution. \n %s", lpe->getName().c_str(), e.what());
-                    SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE,
-                        _("An exception occurred during execution of the Path Effect.") );
+                    if (SP_ACTIVE_DESKTOP && SP_ACTIVE_DESKTOP->messageStack()) {
+                        SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE,
+                                        _("An exception occurred during execution of the Path Effect.") );
+                    }
+                    return false;
                 }
             }
         }
     }
+
+    return true;
 }
 
 /**
@@ -362,11 +373,13 @@ sp_lpe_item_update_patheffect (SPLPEItem *lpeitem, bool wholetree, bool write)
     PathEffectList lpelist = sp_lpe_item_get_effect_list(lpeitem);
     std::list<Inkscape::LivePathEffect::LPEObjectReference *>::iterator i;
     for (i = lpelist.begin(); i != lpelist.end(); ++i) {
-        Inkscape::LivePathEffect::Effect *lpe = (*i)->lpeobject->lpe;
-        if (dynamic_cast<Inkscape::LivePathEffect::LPEPathLength *>(lpe)) {
-            if (!lpe->isVisible()) {
-                // we manually disable text for LPEPathLength
-                dynamic_cast<Inkscape::LivePathEffect::LPEPathLength *>(lpe)->hideCanvasText();
+        if ((*i)->lpeobject) {
+            Inkscape::LivePathEffect::Effect *lpe = (*i)->lpeobject->get_lpe();
+            if (dynamic_cast<Inkscape::LivePathEffect::LPEPathLength *>(lpe)) {
+                if (!lpe->isVisible()) {
+                    // we manually disable text for LPEPathLength
+                    dynamic_cast<Inkscape::LivePathEffect::LPEPathLength *>(lpe)->hideCanvasText();
+                }
             }
         }
     }
@@ -487,8 +500,8 @@ void sp_lpe_item_add_path_effect(SPLPEItem *lpeitem, gchar *value, bool reset)
         sp_lpe_item_create_original_path_recursive(lpeitem);
 
         LivePathEffectObject *lpeobj = lpeitem->path_effect_list->back()->lpeobject;
-        if (lpeobj && lpeobj->lpe) {
-            Inkscape::LivePathEffect::Effect *lpe = lpeobj->lpe;
+        if (lpeobj && lpeobj->get_lpe()) {
+            Inkscape::LivePathEffect::Effect *lpe = lpeobj->get_lpe();
             // Ask the path effect to reset itself if it doesn't have parameters yet
             if (reset) {
                 // has to be called when all the subitems have their lpes applied
@@ -607,8 +620,9 @@ sp_lpe_item_has_path_effect_of_type(SPLPEItem *lpeitem, int type)
 {
     std::list<Inkscape::LivePathEffect::LPEObjectReference *>::iterator i;
     for (i = lpeitem->path_effect_list->begin(); i != lpeitem->path_effect_list->end(); ++i) {
-        if ((*i)->lpeobject->lpe->effectType() == type) {
-            return (*i)->lpeobject->lpe;
+        Inkscape::LivePathEffect::Effect* lpe = (*i)->lpeobject->get_lpe();
+        if (lpe && (lpe->effectType() == type)) {
+            return lpe;
         }
     }
     return NULL;
@@ -629,8 +643,8 @@ bool sp_lpe_item_can_accept_freehand_shape(SPLPEItem *lpeitem)
 void sp_lpe_item_edit_next_param_oncanvas(SPLPEItem *lpeitem, SPDesktop *dt)
 {
     Inkscape::LivePathEffect::LPEObjectReference *lperef = sp_lpe_item_get_current_lpereference(lpeitem);
-    if (lperef && lperef->lpeobject && lperef->lpeobject->lpe) {
-        lperef->lpeobject->lpe->editNextParamOncanvas(SP_ITEM(lpeitem), dt);
+    if (lperef && lperef->lpeobject && lperef->lpeobject->get_lpe()) {
+        lperef->lpeobject->get_lpe()->editNextParamOncanvas(SP_ITEM(lpeitem), dt);
     }
 }
 
@@ -714,7 +728,7 @@ Inkscape::LivePathEffect::Effect* sp_lpe_item_get_current_lpe(SPLPEItem *lpeitem
     Inkscape::LivePathEffect::LPEObjectReference* lperef = sp_lpe_item_get_current_lpereference(lpeitem);
 
     if (lperef && lperef->lpeobject)
-        return lperef->lpeobject->lpe;
+        return lperef->lpeobject->get_lpe();
     else
         return NULL;
 }