Code

lpe-skeleton: add variable to control display of original path
[inkscape.git] / src / sp-filter.cpp
index 150033895202aea50541345839874ed4431463a5..e075087d3af3d6bd84899348e6181678e8ea90aa 100644 (file)
@@ -22,6 +22,8 @@
 using std::map;
 using std::pair;
 
+#include <gtkmm.h>
+
 #include "attributes.h"
 #include "document.h"
 #include "sp-filter.h"
@@ -34,7 +36,7 @@ using std::pair;
 #define SP_MACROS_SILENT
 #include "macros.h"
 
-#include "display/nr-filter.cpp"
+#include "display/nr-filter.h"
 
 /* Filter base class */
 
@@ -49,7 +51,7 @@ static void sp_filter_child_added(SPObject *object,
                                     Inkscape::XML::Node *child,
                                     Inkscape::XML::Node *ref);
 static void sp_filter_remove_child(SPObject *object, Inkscape::XML::Node *child);
-static Inkscape::XML::Node *sp_filter_write(SPObject *object, Inkscape::XML::Node *repr, guint flags);
+static Inkscape::XML::Node *sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags);
 
 static void filter_ref_changed(SPObject *old_ref, SPObject *ref, SPFilter *filter);
 static void filter_ref_modified(SPObject *href, guint flags, SPFilter *filter);
@@ -114,6 +116,7 @@ sp_filter_init(SPFilter *filter)
 
     filter->_image_name = new std::map<gchar *, int, ltstr>;
     filter->_image_name->clear();
+    filter->_image_number_next = 0;
 
     filter->filterRes = NumberOptNumber();
 
@@ -278,12 +281,12 @@ sp_filter_update(SPObject *object, SPCtx *ctx, guint flags)
  * Writes its settings to an incoming repr object, if any.
  */
 static Inkscape::XML::Node *
-sp_filter_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
+sp_filter_write(SPObject *object, Inkscape::XML::Document *doc, Inkscape::XML::Node *repr, guint flags)
 {
     SPFilter *filter = SP_FILTER(object);
 
     if (!repr) {
-        repr = SP_OBJECT_REPR(object)->duplicate(NULL); // FIXME
+        repr = SP_OBJECT_REPR(object)->duplicate(doc);
     }
 
     if ((flags & SP_OBJECT_WRITE_ALL) || filter->filterUnits_set) {
@@ -347,7 +350,7 @@ sp_filter_write(SPObject *object, Inkscape::XML::Node *repr, guint flags)
     }
 
     if (((SPObjectClass *) filter_parent_class)->write) {
-        ((SPObjectClass *) filter_parent_class)->write(object, repr, flags);
+        ((SPObjectClass *) filter_parent_class)->write(object, doc, repr, flags);
     }
 
     return repr;
@@ -476,6 +479,28 @@ int sp_filter_set_image_name(SPFilter *filter, gchar const *name) {
     return value;
 }
 
+Glib::ustring sp_filter_get_new_result_name(SPFilter *filter) {
+    g_assert(filter != NULL);
+    int largest = 0;
+
+    SPObject *primitive_obj = filter->children;
+    while (primitive_obj) {
+        if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
+            Inkscape::XML::Node *repr = SP_OBJECT_REPR(primitive_obj);
+            char const *result = repr->attribute("result");
+            int index;
+            if (result && sscanf(result, "result%d", &index) == 1) {
+                if (index > largest) {
+                    largest = index;
+                }
+            }
+        }
+        primitive_obj = primitive_obj->next;
+    }
+
+    return "result" + Glib::Ascii::dtostr(largest + 1);
+}
+
 bool ltstr::operator()(const char* s1, const char* s2) const
 {
     return strcmp(s1, s2) < 0;