Code

Convert 3D boxes to ordinary groups before tweaking, ungrouping or applying 'convert...
[inkscape.git] / src / path-chemistry.cpp
index ba181476f8add21aa3660c6c1ceb04888de58410..32e2a7beca74ce65f1ace23297ba3b9edadad1c7 100644 (file)
 #include "text-editing.h"
 #include "style.h"
 #include "inkscape.h"
+#include "desktop.h"
 #include "document.h"
 #include "message-stack.h"
 #include "selection.h"
 #include "desktop-handles.h"
+#include "box3d.h"
+
+#include "path-chemistry.h"
 
 /* Helper functions for sp_selected_path_to_curves */
 static void sp_selected_path_to_curves0(gboolean do_document_done, guint32 text_grouping_policy);
-static Inkscape::XML::Node *sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy);
 enum {
     /* Not used yet. This is the placeholder of Lauris's idea. */
     SP_TOCURVE_INTERACTIVE       = 1 << 0,
@@ -73,13 +76,15 @@ sp_selected_path_combine(void)
         }
     }
 
-    sp_selected_path_to_curves0(FALSE, 0);
-
-    items = (GSList *) selection->itemList();
+    desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Combining paths..."));
+    // set "busy" cursor
+    desktop->setWaitingCursor();
 
-    items = g_slist_copy(items);
+    sp_selected_path_to_curves0(FALSE, 0);
 
+    items = g_slist_copy((GSList *) selection->itemList());
     items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position);
+    selection->clear();
 
     // remember the position of the topmost object
     gint topmost = (SP_OBJECT_REPR((SPItem *) g_slist_last(items)->data))->position();
@@ -118,7 +123,8 @@ sp_selected_path_combine(void)
 
     g_slist_free(items);
 
-    Inkscape::XML::Node *repr = sp_repr_new("svg:path");
+    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+    Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
 
     // restore id
     repr->setAttribute("id", id);
@@ -135,7 +141,10 @@ sp_selected_path_combine(void)
     // move to the position of the topmost, reduced by the number of deleted items
     repr->setPosition(topmost > 0 ? topmost + 1 : 0);
 
-    sp_document_done(sp_desktop_document(desktop));
+    desktop->clearWaitingCursor();
+
+    sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_COMBINE, 
+                         _("Combine"));
 
     selection->set(repr);
 
@@ -154,6 +163,10 @@ sp_selected_path_break_apart(void)
         return;
     }
 
+    desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Breaking apart paths..."));
+    // set "busy" cursor
+    desktop->setWaitingCursor();
+
     bool did = false;
 
     for (GSList *items = g_slist_copy((GSList *) selection->itemList());
@@ -197,7 +210,7 @@ sp_selected_path_break_apart(void)
         for (GSList *l = list; l != NULL; l = l->next) {
             curve = (SPCurve *) l->data;
 
-            Inkscape::XML::Node *repr = sp_repr_new("svg:path");
+            Inkscape::XML::Node *repr = parent->document()->createElement("svg:path");
             repr->setAttribute("style", style);
 
             gchar *str = sp_svg_write_path(SP_CURVE_BPATH(curve));
@@ -227,8 +240,11 @@ sp_selected_path_break_apart(void)
 
     }
 
+    desktop->clearWaitingCursor();
+
     if (did) {
-        sp_document_done(sp_desktop_document(desktop));
+        sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_BREAK_APART, 
+                         _("Break apart"));
     } else {
         sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to break apart in the selection."));
         return;
@@ -243,7 +259,7 @@ sp_selected_path_to_curves(void)
 }
 
 static void
-sp_selected_path_to_curves0(gboolean interactive, guint32 text_grouping_policy)
+sp_selected_path_to_curves0(gboolean interactive, guint32 /*text_grouping_policy*/)
 {
     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
 
@@ -256,18 +272,45 @@ sp_selected_path_to_curves0(gboolean interactive, guint32 text_grouping_policy)
     }
 
     bool did = false;
+    if (interactive) {
+        desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Converting objects to paths..."));
+        // set "busy" cursor
+        desktop->setWaitingCursor();
+    }
 
-    for (GSList *items = g_slist_copy((GSList *) selection->itemList());
+    GSList *selected = g_slist_copy((GSList *) selection->itemList());
+    GSList *to_select = NULL;
+    selection->clear();
+    GSList *items = g_slist_copy(selected);
+
+    for (;
          items != NULL;
          items = items->next) {
 
         SPItem *item = SP_ITEM(items->data);
 
+        if (SP_IS_PATH(item) && !SP_PATH(item)->original_curve) {
+            continue; // already a path, and no path effect
+        }
+
+        if (SP_IS_BOX3D(item)) {
+            // convert 3D box to ordinary group of paths; replace the old element in 'selected' with the new group
+            GSList *sel_it = g_slist_find(selected, item);
+            sel_it->data = box3d_convert_to_group(SP_BOX3D(item));
+            item = SP_ITEM(sel_it->data);
+
+            did = true;
+            selected = g_slist_remove (selected, item);
+
+            continue;
+        }
+
         Inkscape::XML::Node *repr = sp_selected_item_to_curved_repr(item, 0);
         if (!repr)
             continue;
 
         did = true;
+        selected = g_slist_remove (selected, item);
 
         // remember the position of the item
         gint pos = SP_OBJECT_REPR(item)->position();
@@ -276,9 +319,7 @@ sp_selected_path_to_curves0(gboolean interactive, guint32 text_grouping_policy)
         // remember id
         char const *id = SP_OBJECT_REPR(item)->attribute("id");
 
-        selection->remove(item);
-
-        // it's going to resurrect, so we delete without advertisement
+        // It's going to resurrect, so we delete without notifying listeners.
         SP_OBJECT(item)->deleteObject(false);
 
         // restore id
@@ -288,13 +329,23 @@ sp_selected_path_to_curves0(gboolean interactive, guint32 text_grouping_policy)
         // move to the saved position
         repr->setPosition(pos > 0 ? pos : 0);
 
-        selection->add(repr);
+        /* Buglet: We don't re-add the (new version of the) object to the selection of any other
+         * desktops where it was previously selected. */
+        to_select = g_slist_prepend (to_select, repr);
         Inkscape::GC::release(repr);
     }
 
+    g_slist_free (items);
+    selection->setReprList(to_select);
+    selection->addList(selected);
+    g_slist_free (to_select);
+    g_slist_free (selected);
+
     if (interactive) {
+        desktop->clearWaitingCursor();
         if (did) {
-            sp_document_done(sp_desktop_document(desktop));
+            sp_document_done(sp_desktop_document(desktop), SP_VERB_OBJECT_TO_CURVE, 
+                             _("Object to path"));
         } else {
             sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects</b> to convert to path in the selection."));
             return;
@@ -302,8 +353,8 @@ sp_selected_path_to_curves0(gboolean interactive, guint32 text_grouping_policy)
     }
 }
 
-static Inkscape::XML::Node *
-sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy)
+Inkscape::XML::Node *
+sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
 {
     if (!item)
         return NULL;
@@ -318,7 +369,8 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy)
     if (!curve)
         return NULL;
 
-    Inkscape::XML::Node *repr = sp_repr_new("svg:path");
+    Inkscape::XML::Document *xml_doc = SP_OBJECT_REPR(item)->document();
+    Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
     /* Transformation */
     repr->setAttribute("transform", SP_OBJECT_REPR(item)->attribute("transform"));
     /* Style */
@@ -326,6 +378,17 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy)
                                                  SP_OBJECT_STYLE(SP_OBJECT_PARENT(item)));
     repr->setAttribute("style", style_str);
     g_free(style_str);
+
+    /* Mask */
+    gchar *mask_str = (gchar *) SP_OBJECT_REPR(item)->attribute("mask");
+    if ( mask_str )
+        repr->setAttribute("mask", mask_str);
+
+    /* Clip path */
+    gchar *clip_path_str = (gchar *) SP_OBJECT_REPR(item)->attribute("clip-path");
+    if ( clip_path_str )
+        repr->setAttribute("clip-path", clip_path_str);
+
     /* Rotation center */
     sp_repr_set_attr(repr, "inkscape:transform-center-x", SP_OBJECT_REPR(item)->attribute("inkscape:transform-center-x"));
     sp_repr_set_attr(repr, "inkscape:transform-center-y", SP_OBJECT_REPR(item)->attribute("inkscape:transform-center-y"));
@@ -338,6 +401,8 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 text_grouping_policy)
     return repr;
 }
 
+
+// FIXME: THIS DOES NOT REVERSE THE NODETYPES ORDER!
 void
 sp_selected_path_reverse()
 {
@@ -352,26 +417,38 @@ sp_selected_path_reverse()
     }
 
 
+    // set "busy" cursor
+    desktop->setWaitingCursor();
+
     bool did = false;
+    desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths..."));
+
     for (GSList *i = items; i != NULL; i = i->next) {
 
-        if (!SP_IS_SHAPE(i->data))
+        if (!SP_IS_PATH(i->data))
             continue;
 
         did = true;
-        SPShape *shape = SP_SHAPE(i->data);
+        SPPath *path = SP_PATH(i->data);
 
-        SPCurve *rcurve = sp_curve_reverse(shape->curve);
+        SPCurve *rcurve = sp_curve_reverse(sp_path_get_curve_reference(path));
 
         gchar *str = sp_svg_write_path(SP_CURVE_BPATH(rcurve));
-        SP_OBJECT_REPR(shape)->setAttribute("d", str);
+        if ( sp_shape_has_path_effect(SP_SHAPE(path)) ) {
+            SP_OBJECT_REPR(path)->setAttribute("inkscape:original-d", str);
+        } else {
+            SP_OBJECT_REPR(path)->setAttribute("d", str);
+        }
         g_free(str);
 
         sp_curve_unref(rcurve);
     }
 
+    desktop->clearWaitingCursor();
+
     if (did) {
-        sp_document_done(sp_desktop_document(desktop));
+        sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_REVERSE,
+                         _("Reverse path"));
     } else {
         sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection."));
     }