Code

Initial cut of eraser tool
[inkscape.git] / src / sp-path.cpp
index 26396c8f0a07657d36b368631fd7383e10d50344..99670882abab2b86ba788d8e9aab1bae8954dc3e 100644 (file)
@@ -59,7 +59,7 @@ static gchar * sp_path_description(SPItem *item);
 static void sp_path_convert_to_guides(SPItem *item);
 
 static void sp_path_update(SPObject *object, SPCtx *ctx, guint flags);
-static void sp_path_update_patheffect(SPShape *shape, bool write);
+static void sp_path_update_patheffect(SPLPEItem *lpeitem, bool write);
 
 static SPShapeClass *parent_class;
 
@@ -98,7 +98,7 @@ sp_path_class_init(SPPathClass * klass)
     GObjectClass *gobject_class = (GObjectClass *) klass;
     SPObjectClass *sp_object_class = (SPObjectClass *) klass;
     SPItemClass *item_class = (SPItemClass *) klass;
-    SPShapeClass *shape_class = (SPShapeClass *) klass;
+    SPLPEItemClass *lpe_item_class = (SPLPEItemClass *) klass;
 
     parent_class = (SPShapeClass *)g_type_class_peek_parent(klass);
 
@@ -114,7 +114,7 @@ sp_path_class_init(SPPathClass * klass)
     item_class->set_transform = sp_path_set_transform;
     item_class->convert_to_guides = sp_path_convert_to_guides;
 
-    shape_class->update_patheffect = sp_path_update_patheffect;
+    lpe_item_class->update_patheffect = sp_path_update_patheffect;
 }
 
 
@@ -136,7 +136,7 @@ static gchar *
 sp_path_description(SPItem * item)
 {
     int count = sp_nodes_in_path(SP_PATH(item));
-    if (SP_SHAPE(item)->path_effect_href) {
+    if (sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) {
         return g_strdup_printf(ngettext("<b>Path</b> (%i node, path effect)",
                                         "<b>Path</b> (%i nodes, path effect)",count), count);
     } else {
@@ -264,7 +264,7 @@ sp_path_set(SPObject *object, unsigned int key, gchar const *value)
                 object->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
             break;
        case SP_ATTR_D:
-            if (!((SPShape *) path)->path_effect_href) {
+            if (!sp_lpe_item_has_path_effect_recursive(SP_LPE_ITEM(path))) {
                 if (value) {
                     NArtBpath *bpath = sp_svg_read_path(value);
                     SPCurve *curve = sp_curve_new_from_bpath(bpath);
@@ -377,24 +377,18 @@ sp_path_set_transform(SPItem *item, NR::Matrix const &xform)
         return NR::identity();
     }
 
-    if (path->original_curve) { /* Transform the original-d path */
-        NRBPath dorigpath, sorigpath;
-        sorigpath.path = SP_CURVE_BPATH(path->original_curve);
-        nr_path_duplicate_transform(&dorigpath, &sorigpath, xform);
-        SPCurve *origcurve = sp_curve_new_from_bpath(dorigpath.path);
-        if (origcurve) {
-            sp_path_set_original_curve(path, origcurve, TRUE, true);
-            sp_curve_unref(origcurve);
-        }
-    } else {    /* Transform the path */
-        NRBPath dpath, spath;
-        spath.path = SP_CURVE_BPATH(shape->curve);
-        nr_path_duplicate_transform(&dpath, &spath, xform);
-        SPCurve *curve = sp_curve_new_from_bpath(dpath.path);
-        if (curve) {
-            sp_shape_set_curve(shape, curve, TRUE);
-            sp_curve_unref(curve);
+    // Transform the original-d path or the (ordinary) path
+    bool original_path = (bool)path->original_curve;
+    SPCurve *srccurve = original_path ? path->original_curve : shape->curve;
+    SPCurve *dstcurve = sp_curve_copy(srccurve);
+    if (dstcurve) {
+        sp_curve_transform(dstcurve, xform);
+        if (original_path) {
+            sp_path_set_original_curve(path, dstcurve, TRUE, true);
+        } else {
+            sp_shape_set_curve(shape, dstcurve, TRUE);
         }
+        sp_curve_unref(dstcurve);
     }
 
     // Adjust stroke
@@ -416,12 +410,13 @@ sp_path_set_transform(SPItem *item, NR::Matrix const &xform)
 }
 
 static void
-sp_path_update_patheffect(SPShape *shape, bool write)
+sp_path_update_patheffect(SPLPEItem *lpeitem, bool write)
 {
-    SPPath *path = (SPPath *) shape;
+    SPShape *shape = (SPShape *) lpeitem;
+    SPPath *path = (SPPath *) lpeitem;
     if (path->original_curve) {
         SPCurve *curve = sp_curve_copy (path->original_curve);
-        sp_shape_perform_path_effect(curve, shape);
+        sp_lpe_item_perform_path_effect(SP_LPE_ITEM(shape), curve);
         sp_shape_set_curve(shape, curve, TRUE);
         sp_curve_unref(curve);
 
@@ -568,10 +563,8 @@ void freehand_create_single_dot(SPEventContext *ec, NR::Point const &pt, char co
 
     sp_desktop_selection(desktop)->set(item);
 
-    unsigned int tool_code = !strcmp(tool, "tools.freehand.pencil") ? SP_VERB_CONTEXT_PENCIL : SP_VERB_CONTEXT_PEN;
-
     desktop->messageStack()->flash(Inkscape::NORMAL_MESSAGE, _("Creating single dot"));
-    sp_document_done(sp_desktop_document(desktop), tool_code, _("Create single dot"));
+    sp_document_done(sp_desktop_document(desktop), SP_VERB_NONE, _("Create single dot"));
 }
 
 /*