Code

Fixed conflicting result image names inside filter effects (bug 196126)
authorkiirala <kiirala@users.sourceforge.net>
Mon, 2 Jun 2008 15:47:48 +0000 (15:47 +0000)
committerkiirala <kiirala@users.sourceforge.net>
Mon, 2 Jun 2008 15:47:48 +0000 (15:47 +0000)
src/sp-filter.cpp
src/sp-filter.h
src/ui/dialog/filter-effects-dialog.cpp

index 150033895202aea50541345839874ed4431463a5..e020f6814f2d18d9d450a8c38e5657a617c2f0d5 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"
@@ -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();
 
@@ -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;
index 3e9bb3cb09871726142fd8f67bda45a4853dadde..d0a449c47591671e2b5457d8b59969c6485acf18 100644 (file)
@@ -16,6 +16,8 @@
 
 #include <map>
 
+#include <gtkmm.h>
+
 #include "number-opt-number.h"
 #include "sp-object.h"
 #include "sp-filter-units.h"
@@ -82,6 +84,11 @@ int sp_filter_primitive_count(SPFilter *filter);
 int sp_filter_get_image_name(SPFilter *filter, gchar const *name);
 int sp_filter_set_image_name(SPFilter *filter, gchar const *name);
 
+/*
+ * Returns a result image name that is not in use inside this filter.
+ */
+Glib::ustring sp_filter_get_new_result_name(SPFilter *filter);
+
 #endif /* !SP_FILTER_H_SEEN */
 
 /*
index c7694ef09ea696d774db4b2a7159f9ee0c560407..98951f28c4c25755d75f9f784e7b72ab069be069 100644 (file)
@@ -1917,7 +1917,7 @@ bool FilterEffectsDialog::PrimitiveList::on_button_release_event(GdkEventButton*
                         // Make sure the target has a result
                         const gchar *gres = repr->attribute("result");
                         if(!gres) {
-                            result = "result" + Glib::Ascii::dtostr(SP_FILTER(prim->parent)->_image_number_next);
+                            result = sp_filter_get_new_result_name(SP_FILTER(prim->parent));
                             repr->setAttribute("result", result.c_str());
                             in_val = result.c_str();
                         }