Code

remove the old _d_changed and _typestr_changed hacks, replacing by an int-valued...
authorbuliabyak <buliabyak@users.sourceforge.net>
Wed, 12 Apr 2006 17:16:28 +0000 (17:16 +0000)
committerbuliabyak <buliabyak@users.sourceforge.net>
Wed, 12 Apr 2006 17:16:28 +0000 (17:16 +0000)
src/node-context.cpp
src/nodepath.cpp
src/nodepath.h

index ccdb6c79eec6331054034b16ba94c9774e16dd26..1e01b1af9ac59e00602c3087623db0455cd4e89e 100644 (file)
@@ -310,7 +310,6 @@ nodepath_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
                             bool is_interactive, gpointer data)
 {
     SPItem *item = NULL;
-    char const *newd = NULL, *newtypestr = NULL;
     gboolean changed = FALSE;
 
     g_assert(data);
@@ -322,21 +321,18 @@ nodepath_event_attr_changed(Inkscape::XML::Node *repr, gchar const *name,
 
     if (np) {
         item = SP_ITEM(np->path);
-        if (!strcmp(name, "d")) {
-            newd = new_value;
-            changed = nodepath_repr_d_changed(np, new_value);
-        } else if (!strcmp(name, "sodipodi:nodetypes")) {
-            newtypestr = new_value;
-            changed = nodepath_repr_typestr_changed(np, new_value);
-        } else {
-            return;
-            // With paths, we only need to act if one of the path-affecting attributes has changed.
+        if (!strcmp(name, "d") || !strcmp(name, "sodipodi:nodetypes")) { // With paths, we only need to act if one of the path-affecting attributes has changed.
+            changed = (np->local_change == 0);
+            if (np->local_change > 0)
+                np->local_change--;
         }
+
     } else if (kh) {
         item = SP_ITEM(kh->item);
         changed = !(kh->local_change);
         kh->local_change = FALSE;
     }
+
     if (np && changed) {
         GList *saved = NULL;
         SPDesktop *desktop = np->desktop;
index 97be9355cb2863be8d05a993b9324e54c182184e..b50ee90c7b6a0acae5ae6540a89024627b0eca5d 100644 (file)
@@ -182,6 +182,7 @@ Inkscape::NodePath::Path *sp_nodepath_new(SPDesktop *desktop, SPItem *item)
     np->selected    = NULL;
     np->nodeContext = NULL; //Let the context that makes this set it
     np->livarot_path = NULL;
+    np->local_change = 0;
 
     // we need to update item's transform from the repr here,
     // because they may be out of sync when we respond
@@ -294,62 +295,6 @@ static void sp_nodepath_cleanup(Inkscape::NodePath::Path *nodepath)
     g_list_free(badSubPaths);
 }
 
-
-
-/**
- * \brief Returns true if the argument nodepath and the d attribute in
- * its repr do not match.
- *
- * This may happen if repr was changed in, e.g., XML editor or by undo.
- *
- * \todo
- * UGLY HACK, think how we can eliminate it. IDEA: try instead a local_change flag in node context?
- */
-gboolean nodepath_repr_d_changed(Inkscape::NodePath::Path *np, char const *newd)
-{
-    g_assert(np);
-
-    SPCurve *curve = create_curve(np);
-
-    gchar *svgpath = sp_svg_write_path(curve->bpath);
-
-    char const *attr_d = ( newd
-                           ? newd
-                           : SP_OBJECT(np->path)->repr->attribute("d") );
-
-    gboolean ret;
-    if (attr_d && svgpath)
-        ret = strcmp(attr_d, svgpath);
-    else
-        ret = TRUE;
-
-    g_free(svgpath);
-    sp_curve_unref(curve);
-
-    return ret;
-}
-
-/**
- * \brief Returns true if the argument nodepath and the sodipodi:nodetypes
- * attribute in its repr do not match.
- *
- * This may happen if repr was changed in, e.g., the XML editor or by undo.
- * IDEA: try instead a local_change flag in node context?
- */
-gboolean nodepath_repr_typestr_changed(Inkscape::NodePath::Path *np, char const *newtypestr)
-{
-    g_assert(np);
-    gchar *typestr = create_typestr(np);
-    char const *attr_typestr = ( newtypestr
-                                 ? newtypestr
-                                 : SP_OBJECT(np->path)->repr->attribute("sodipodi:nodetypes") );
-    gboolean const ret = (attr_typestr && strcmp(attr_typestr, typestr));
-
-    g_free(typestr);
-
-    return ret;
-}
-
 /**
  * Create new nodepath from b, make it subpath of np.
  * \param t The node type.
@@ -465,8 +410,15 @@ static void update_repr_internal(Inkscape::NodePath::Path *np)
     gchar *typestr = create_typestr(np);
     gchar *svgpath = sp_svg_write_path(curve->bpath);
 
-    repr->setAttribute("d", svgpath);
-    repr->setAttribute("sodipodi:nodetypes", typestr);
+    if (repr->attribute("d") == NULL || strcmp(svgpath, repr->attribute("d"))) { // d changed
+        np->local_change++;
+        repr->setAttribute("d", svgpath);
+    }
+
+    if (repr->attribute("sodipodi:nodetypes") == NULL || strcmp(typestr, repr->attribute("sodipodi:nodetypes"))) { // nodetypes changed
+        np->local_change++;
+        repr->setAttribute("sodipodi:nodetypes", typestr);
+    }
 
     g_free(svgpath);
     g_free(typestr);
index aaa488cf3ff6f58c9d78a3c36599a1cc49d4bf66..656d64ebbe87662af748699d824fbb341a989ebb 100644 (file)
@@ -130,6 +130,9 @@ class Path {
 
       /// livarot library is used for "point on path" and "nearest position on path", so we need to maintain its path representation as well
        ::Path *livarot_path;
+
+      /// true if we changed repr, to tell this change from an external one such as from undo, simplify, or another desktop
+       uint local_change; 
 };