X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fpath-chemistry.cpp;h=bec3c5cbff27f23c51bd27e83da0d13fad7c6c6c;hb=42382dfb4164b919ffcdf03766da9f8be4e43b42;hp=99ee78ade932963fbb01cabfca7e7f0411965935;hpb=09ba3247163582bf2e30e17c4c154aa259ce038a;p=inkscape.git diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 99ee78ade..bec3c5cbf 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -1,5 +1,3 @@ -#define __SP_PATH_CHEMISTRY_C__ - /* * Here are handlers for modifying selections, specific to paths * @@ -7,6 +5,8 @@ * Lauris Kaplinski * bulia byak * Jasper van de Gronde + * Jon A. Cruz + * Abhishek Sharma * * Copyright (C) 1999-2008 Authors * Copyright (C) 2001-2002 Ximian, Inc. @@ -39,6 +39,8 @@ #include "selection-chemistry.h" #include "path-chemistry.h" +using Inkscape::DocumentUndo; + void sp_selected_path_combine(SPDesktop *desktop) { @@ -86,12 +88,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,18 +134,17 @@ 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::Document *xml_doc = desktop->doc()->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); // restore id, transform, path effect, and style repr->setAttribute("id", id); - if (transform) repr->setAttribute("transform", transform); + if (transform) { + repr->setAttribute("transform", transform); + } repr->setAttribute("style", style); g_free(style); @@ -145,10 +154,11 @@ sp_selected_path_combine(SPDesktop *desktop) // set path data corresponding to new curve gchar *dstring = sp_svg_write_path(curve->get_pathvector()); curve->unref(); - if (path_effect) + if (path_effect) { repr->setAttribute("inkscape:original-d", dstring); - else + } else { repr->setAttribute("d", dstring); + } g_free(dstring); // add the new group to the parent of the topmost @@ -157,8 +167,8 @@ 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, - _("Combine")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_COMBINE, + _("Combine")); selection->set(repr); @@ -208,8 +218,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,8 +279,8 @@ sp_selected_path_break_apart(SPDesktop *desktop) desktop->clearWaitingCursor(); if (did) { - sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_BREAK_APART, - _("Break apart")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_BREAK_APART, + _("Break apart")); } else { sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("No path(s) to break apart in the selection.")); } @@ -309,8 +321,8 @@ 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, - _("Object to path")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_OBJECT_TO_CURVE, + _("Object to path")); } else { sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("No objects to convert to path in the selection.")); return; @@ -318,8 +330,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; @@ -330,6 +367,13 @@ sp_item_list_to_curves(const GSList *items, GSList **selected, GSList **to_selec SPItem *item = SP_ITEM(items->data); 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 +539,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,8 +634,8 @@ sp_selected_path_reverse(SPDesktop *desktop) desktop->clearWaitingCursor(); if (did) { - sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_REVERSE, - _("Reverse path")); + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_SELECTION_REVERSE, + _("Reverse path")); } else { sp_desktop_message_stack(desktop)->flash(Inkscape::ERROR_MESSAGE, _("No paths to reverse in the selection.")); } @@ -606,4 +650,4 @@ sp_selected_path_reverse(SPDesktop *desktop) fill-column:99 End: */ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :