Code

A simple layout document as to what, why and how is cppification.
[inkscape.git] / src / path-chemistry.cpp
index 3b5cd31364718eee2e84d029a2c2aee866a4045d..12913fd858d97fc53900b32ec71f8f4c97fe8aa4 100644 (file)
@@ -43,7 +43,7 @@ void
 sp_selected_path_combine(SPDesktop *desktop)
 {
     Inkscape::Selection *selection = sp_desktop_selection(desktop);
-    Document *doc = sp_desktop_document(desktop);
+    SPDocument *doc = sp_desktop_document(desktop);
     
     if (g_slist_length((GSList *) selection->itemList()) < 1) {
         sp_desktop_message_stack(desktop)->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine."));
@@ -86,12 +86,20 @@ sp_selected_path_combine(SPDesktop *desktop)
     SPItem *first = NULL;
     Inkscape::XML::Node *parent = NULL; 
 
+    if (did) {
+        selection->clear();
+    }
+
     for (GSList *i = items; i != NULL; i = i->next) {  // going from top to bottom
 
         SPItem *item = (SPItem *) i->data;
         if (!SP_IS_PATH(item))
             continue;
-        did = true;
+
+        if (!did) {
+            selection->clear();
+            did = true;
+        }
 
         SPCurve *c = sp_path_get_curve_for_edit(SP_PATH(item));
         if (first == NULL) {  // this is the topmost path
@@ -124,11 +132,8 @@ sp_selected_path_combine(SPDesktop *desktop)
     g_slist_free(items);
 
     if (did) {
-        selection->clear();
-
-        // delete the topmost one so that its clones don't get alerted; this object will be
-        // restored shortly, with the same id
         SP_OBJECT(first)->deleteObject(false);
+        // delete the topmost.
 
         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
         Inkscape::XML::Node *repr = xml_doc->createElement("svg:path");
@@ -157,7 +162,7 @@ sp_selected_path_combine(SPDesktop *desktop)
         // move to the position of the topmost, reduced by the number of deleted items
         repr->setPosition(position > 0 ? position : 0);
 
-        sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_COMBINE, 
+        SPDocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_COMBINE, 
                          _("Combine"));
 
         selection->set(repr);
@@ -208,8 +213,10 @@ sp_selected_path_break_apart(SPDesktop *desktop)
         gint pos = SP_OBJECT_REPR(item)->position();
         char const *id = SP_OBJECT_REPR(item)->attribute("id");
 
-        gchar *style = g_strdup(SP_OBJECT(item)->repr->attribute("style"));
-        gchar *path_effect = g_strdup(SP_OBJECT(item)->repr->attribute("inkscape:path-effect"));
+               // XML Tree being used directly here while it shouldn't be...
+        gchar *style = g_strdup(SP_OBJECT(item)->getRepr()->attribute("style"));
+               // XML Tree being used directly here while it shouldn't be...
+        gchar *path_effect = g_strdup(SP_OBJECT(item)->getRepr()->attribute("inkscape:path-effect"));
 
         Geom::PathVector apv = curve->get_pathvector() * SP_ITEM(path)->transform;
 
@@ -267,7 +274,7 @@ sp_selected_path_break_apart(SPDesktop *desktop)
     desktop->clearWaitingCursor();
 
     if (did) {
-        sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_BREAK_APART, 
+        SPDocumentUndo::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."));
@@ -309,7 +316,7 @@ sp_selected_path_to_curves(SPDesktop *desktop, bool interactive)
     if (interactive) {
         desktop->clearWaitingCursor();
         if (did) {
-            sp_document_done(sp_desktop_document(desktop), SP_VERB_OBJECT_TO_CURVE, 
+            SPDocumentUndo::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."));
@@ -318,8 +325,33 @@ sp_selected_path_to_curves(SPDesktop *desktop, bool interactive)
     }
 }
 
+/** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */
+void sp_selected_to_lpeitems(SPDesktop *desktop)
+{
+    Inkscape::Selection *selection = sp_desktop_selection(desktop);
+
+    if (selection->isEmpty()) {
+        return;
+    }
+
+    bool did = false;
+
+    GSList *selected = g_slist_copy((GSList *) selection->itemList());
+    GSList *to_select = NULL;
+    selection->clear();
+    GSList *items = g_slist_copy(selected);
+
+    did = sp_item_list_to_curves(items, &selected, &to_select, true);
+
+    g_slist_free (items);
+    selection->setReprList(to_select);
+    selection->addList(selected);
+    g_slist_free (to_select);
+    g_slist_free (selected);
+}
+
 bool
-sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select)
+sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_select, bool skip_all_lpeitems)
 {
     bool did = false;
     
@@ -328,7 +360,14 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec
          items = items->next) {
 
         SPItem *item = SP_ITEM(items->data);
-       Document *document = item->document;
+       SPDocument *document = item->document;
+
+        if ( skip_all_lpeitems &&
+             SP_IS_LPE_ITEM(item) && 
+             !SP_IS_GROUP(item) ) // also convert objects in an SPGroup when skip_all_lpeitems is set.
+        { 
+            continue;
+        }
 
         if (SP_IS_PATH(item) && !SP_PATH(item)->original_curve) {
             continue; // already a path, and no path effect
@@ -495,7 +534,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/)
 
     SPCurve *curve = NULL;
     if (SP_IS_SHAPE(item)) {
-        curve = sp_shape_get_curve(SP_SHAPE(item));
+        curve = SP_SHAPE(item)->getCurve();
     } 
 
     if (!curve)
@@ -590,7 +629,7 @@ sp_selected_path_reverse(SPDesktop *desktop)
     desktop->clearWaitingCursor();
 
     if (did) {
-        sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_REVERSE,
+        SPDocumentUndo::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."));