diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2012-01-15 11:26:04 +0000 |
|---|---|---|
| committer | Johan Engelen <goejendaagh@zonnet.nl> | 2012-01-15 11:26:04 +0000 |
| commit | bbe40ef819359465fabfa938c86a7faba7357473 (patch) | |
| tree | 530b2435e33ade395b2248562cc13ae0cb768a1a /src/selection-chemistry.cpp | |
| parent | ege-appear-time-tracker GSEAL (diff) | |
| download | inkscape-bbe40ef819359465fabfa938c86a7faba7357473.tar.gz inkscape-bbe40ef819359465fabfa938c86a7faba7357473.zip | |
add a menu item for using the Clone original LPE efficiently.
(bzr r10889)
Diffstat (limited to 'src/selection-chemistry.cpp')
| -rw-r--r-- | src/selection-chemistry.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index f7160cea8..97bc5a39f 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2271,6 +2271,63 @@ sp_select_clone_original(SPDesktop *desktop) } } +/** +* This creates a new path, applies the Original Path LPE, and has it refer to the selection. +*/ +void sp_selection_clone_original_path_lpe(SPDesktop *desktop) +{ + if (desktop == NULL) { + return; + } + + Inkscape::Selection *selection = sp_desktop_selection(desktop); + SPItem *item = selection->singleItem(); + if (g_slist_length((GSList *) selection->itemList()) != 1 || !item) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>one</b> path to clone.")); + return; + } + if ( !(SP_IS_SHAPE(item) || SP_IS_TEXT(item)) ) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select one <b>path</b> to clone.")); + return; + } + + Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *parent = item->getRepr()->parent(); + + // create the LPE + Inkscape::XML::Node *lpe_repr = xml_doc->createElement("inkscape:path-effect"); + { + lpe_repr->setAttribute("effect", "clone_original"); + gchar *href = g_strdup_printf("#%s", item->getRepr()->attribute("id")); + lpe_repr->setAttribute("linkedpath", href); + g_free(href); + desktop->doc()->getDefs()->getRepr()->addChild(lpe_repr, NULL); // adds to <defs> and assigns the 'id' attribute + } + const gchar * lpe_id = lpe_repr->attribute("id"); + Inkscape::GC::release(lpe_repr); + + // create the new path + Inkscape::XML::Node *clone = xml_doc->createElement("svg:path"); + { + clone->setAttribute("d", "M 0 0", false); + // add the new clone to the top of the original's parent + parent->appendChild(clone); + SPObject *clone_obj = desktop->doc()->getObjectById(clone->attribute("id")); + if (SP_IS_LPE_ITEM(clone_obj)) { + gchar *href = g_strdup_printf("#%s", lpe_id); + sp_lpe_item_add_path_effect( SP_LPE_ITEM(clone_obj), href, false ); + g_free(href); + } + } + + DocumentUndo::done(sp_desktop_document(desktop), SP_VERB_EDIT_CLONE_ORIGINAL_PATH_LPE, + _("Clone original path")); + + // select the new object: + selection->set(clone); + + Inkscape::GC::release(clone); +} void sp_selection_to_marker(SPDesktop *desktop, bool apply) { |
