From 3c5cd145660b50b8b96bfa8c22bd6b28d72e452c Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Mon, 22 Apr 2013 10:58:19 -0400 Subject: Add balloon symbols and connect defs modified signal. Fixed bugs: - https://launchpad.net/bugs/1170817 (bzr r12298) --- src/selection-chemistry.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'src/selection-chemistry.cpp') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index fc410897a..28dd51e81 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2973,7 +2973,6 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) */ void sp_selection_unsymbol(SPDesktop *desktop) { - if (desktop == NULL) { return; } @@ -2992,13 +2991,8 @@ void sp_selection_unsymbol(SPDesktop *desktop) SPObject* use = selection->single(); // Make sure we have only one object in selection. - if( use == NULL ) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select only one symbol to convert to group.")); - return; - } - // Require that we really have a that references a . - if( !SP_IS_USE( use ) && !SP_IS_SYMBOL( use->firstChild() ) ) { + if( use == NULL || ( !SP_IS_USE( use ) && !SP_IS_SYMBOL( use->firstChild() ))) { desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select only one symbol to convert to group.")); return; } -- cgit v1.2.3 From a40d9996c9252ebf79b951e0023340870f0347af Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Tue, 23 Apr 2013 13:40:15 -0400 Subject: Allow multiple groups to be symbolised and replace groups with clones. (bzr r12300) --- src/selection-chemistry.cpp | 70 ++++++++++++++++++++++++++------------------- 1 file changed, 41 insertions(+), 29 deletions(-) (limited to 'src/selection-chemistry.cpp') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 28dd51e81..beafc59a5 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -2892,45 +2892,52 @@ void sp_selection_to_guides(SPDesktop *desktop) /* * Convert to , leaving all elements referencing group unchanged. */ -void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) +void sp_selection_symbols(SPDesktop *desktop, bool /*apply*/ ) { - if (desktop == NULL) { return; } SPDocument *doc = sp_desktop_document(desktop); - Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + doc->ensureUpToDate(); Inkscape::Selection *selection = sp_desktop_selection(desktop); // Check if something is selected. if (selection->isEmpty()) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select one group to convert to symbol.")); - return; + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select groups to convert to symbols.")); + return; } - SPObject* group = selection->single(); + GSList *items = g_slist_copy(const_cast(selection->list())); + bool hasWorked = false; - // Make sure we have only one object in selection. - if( group == NULL ) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select only one group to convert to symbol.")); - return; - } + for ( GSList const *iter=items; iter != NULL ; iter = iter->next ) { + SPObject *object = reinterpret_cast( iter->data ); - // Make sure we convert the original. - if( SP_IS_USE( group ) ) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select original (Shift+D) to convert to symbol.")); - return; + // Require that we really have a group. + if( SP_IS_GROUP( object ) ) { + sp_selection_symbol( doc, object ); + hasWorked = true; + } } - // Require that we really have a group. - if( !SP_IS_GROUP( group ) ) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Group selection first to convert to symbol.")); - return; + g_slist_free(items); + + if( !hasWorked ) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No groups converted to symbols.")); + return; } - doc->ensureUpToDate(); + selection->clear(); + // Group just disappears, nothing to select. + + DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol")); +} + +void sp_selection_symbol(SPDocument *doc, SPObject *group) +{ + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *symbol = xml_doc->createElement("svg:symbol"); symbol->setAttribute("style", group->getAttribute("style")); @@ -2952,20 +2959,25 @@ void sp_selection_symbol(SPDesktop *desktop, bool /*apply*/ ) // Need to delete ; all elements that referenced should // auto-magically reference . doc->getDefs()->getRepr()->appendChild(symbol); - symbol->setAttribute("id",id.c_str()); // After we delete group with same id. - // Mysterious, must set symbol ID before deleting group or all - // refering to symbol get turned into groups. (Linked to unlinking clones?) - group->deleteObject(true); + // Mysterious, must set symbol ID before deleting group or all items + // get turned into groups. (Linked to unlinking clones?) + symbol->setAttribute("id",id.c_str()); - Inkscape::GC::release(symbol); - selection->clear(); - // Group just disappears, nothing to select. + // Create a clone of the symbol to replace the deleted group. + Inkscape::XML::Node *clone = xml_doc->createElement("svg:use"); + clone->setAttribute("x", "0", false); + clone->setAttribute("y", "0", false); + clone->setAttribute("xlink:href", g_strdup_printf("#%s", id.c_str()), false); - // Need to signal Symbol dialog to update + clone->setAttribute("inkscape:transform-center-x", group->getAttribute("inkscape:transform-center-x"), false); + clone->setAttribute("inkscape:transform-center-y", group->getAttribute("inkscape:transform-center-y"), false); + group->parent->getRepr()->appendChild(clone); + + group->deleteObject(true); g_slist_free(children); - DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol")); + Inkscape::GC::release(symbol); } /* -- cgit v1.2.3