From 3f61bc675d5f2f0c92d7906b8552b09df3cd411f Mon Sep 17 00:00:00 2001 From: John Smith Date: Sat, 22 Sep 2012 21:14:14 +0900 Subject: Fix for 172222 : Move direct to specified layer (bzr r11695) --- src/selection-chemistry.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/selection-chemistry.cpp') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 068928d8f..4cdab4336 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -1314,6 +1314,36 @@ void sp_selection_to_prev_layer(SPDesktop *dt, bool suppressDone) g_slist_free(const_cast(items)); } +void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) +{ + Inkscape::Selection *selection = sp_desktop_selection(dt); + + // check if something is selected + if (selection->isEmpty()) { + dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select object(s) to move.")); + return; + } + + GSList const *items = g_slist_copy(const_cast(selection->itemList())); + + if (moveto) { + GSList *temp_clip = NULL; + sp_selection_copy_impl(items, &temp_clip, dt->doc()->getReprDoc()); // we're in the same doc, so no need to copy defs + sp_selection_delete_impl(items, false, false); + GSList *copied = sp_selection_paste_impl(sp_desktop_document(dt), moveto, &temp_clip); + selection->setReprList((GSList const *) copied); + g_slist_free(copied); + if (temp_clip) g_slist_free(temp_clip); + if (moveto) dt->setCurrentLayer(moveto); + if ( !suppressDone ) { + DocumentUndo::done(sp_desktop_document(dt), SP_VERB_LAYER_MOVE_TO, + _("Move selection to layer")); + } + } + + g_slist_free(const_cast(items)); +} + bool selection_contains_original(SPItem *item, Inkscape::Selection *selection) { -- cgit v1.2.3 From 370a3f5cc9e39352a081e5d5dd8c43676547a6e6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Oct 2012 11:45:44 +1000 Subject: code cleanup: add own includes to cpp files or make the functions static if they are not used elsewhere. (bzr r11735) --- src/selection-chemistry.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'src/selection-chemistry.cpp') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 4cdab4336..332e9a34e 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -256,7 +256,7 @@ void SelectionHelper::selectPrev(SPDesktop *dt) * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t', * then prepends the copy to 'clip'. */ -void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, GSList **clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, GSList **clip, Inkscape::XML::Document* xml_doc) { Inkscape::XML::Node *copy = repr->duplicate(xml_doc); @@ -275,7 +275,7 @@ void sp_selection_copy_one(Inkscape::XML::Node *repr, Geom::Affine full_t, GSLis *clip = g_slist_prepend(*clip, copy); } -void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::Document* xml_doc) +static void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::Document* xml_doc) { // Sort items: GSList *sorted_items = g_slist_copy(const_cast(items)); @@ -290,7 +290,7 @@ void sp_selection_copy_impl(GSList const *items, GSList **clip, Inkscape::XML::D g_slist_free(static_cast(sorted_items)); } -GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList **clip) +static GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList **clip) { Inkscape::XML::Document *xml_doc = doc->getReprDoc(); @@ -321,7 +321,7 @@ GSList *sp_selection_paste_impl(SPDocument *doc, SPObject *parent, GSList **clip return copied; } -void sp_selection_delete_impl(GSList const *items, bool propagate = true, bool propagate_descendants = true) +static void sp_selection_delete_impl(GSList const *items, bool propagate = true, bool propagate_descendants = true) { for (GSList const *i = items ; i ; i = i->next ) { sp_object_ref((SPObject *)i->data, NULL); @@ -372,7 +372,7 @@ void sp_selection_delete(SPDesktop *desktop) _("Delete")); } -void add_ids_recursive(std::vector &ids, SPObject *obj) +static void add_ids_recursive(std::vector &ids, SPObject *obj) { if (obj) { ids.push_back(obj->getId()); @@ -540,7 +540,7 @@ GSList *get_all_items(GSList *list, SPObject *from, SPDesktop *desktop, bool onl return list; } -void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool invert) +static void sp_edit_select_all_full(SPDesktop *dt, bool force_all_layers, bool invert) { if (!dt) return; @@ -626,7 +626,7 @@ void sp_edit_invert_in_all_layers(SPDesktop *desktop) sp_edit_select_all_full(desktop, true, true); } -void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { +static void sp_selection_group_impl(GSList *p, Inkscape::XML::Node *group, Inkscape::XML::Document *xml_doc, SPDocument *doc) { p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position); @@ -845,7 +845,7 @@ enclose_items(GSList const *items) } // TODO determine if this is intentionally different from SPObject::getPrev() -SPObject *prev_sibling(SPObject *child) +static SPObject *prev_sibling(SPObject *child) { SPObject *prev = 0; if ( child && SP_IS_GROUP(child->parent) ) { @@ -1153,7 +1153,7 @@ void sp_selection_paste_livepatheffect(SPDesktop *desktop) } -void sp_selection_remove_livepatheffect_impl(SPItem *item) +static void sp_selection_remove_livepatheffect_impl(SPItem *item) { if ( item && SP_IS_LPE_ITEM(item) && sp_lpe_item_has_path_effect(SP_LPE_ITEM(item))) { @@ -1344,7 +1344,7 @@ void sp_selection_to_layer(SPDesktop *dt, SPObject *moveto, bool suppressDone) g_slist_free(const_cast(items)); } -bool +static bool selection_contains_original(SPItem *item, Inkscape::Selection *selection) { bool contains_original = false; @@ -1371,7 +1371,7 @@ selection_contains_original(SPItem *item, Inkscape::Selection *selection) } -bool +static bool selection_contains_both_clone_and_original(Inkscape::Selection *selection) { bool clone_with_original = false; @@ -1882,7 +1882,7 @@ GSList *sp_get_same_fill_or_stroke_color(SPItem *sel, GSList *src, SPSelectStrok return matches; } -bool item_type_match (SPItem *i, SPItem *j) +static bool item_type_match (SPItem *i, SPItem *j) { if ( SP_IS_RECT(i)) { return ( SP_IS_RECT(j) ); -- cgit v1.2.3 From f304ab600788b02cb02a4413f68f466e35cf1539 Mon Sep 17 00:00:00 2001 From: Tavmjong Bah Date: Thu, 11 Oct 2012 19:54:14 +0200 Subject: Add symbols dialog. See: http://wiki.inkscape.org/wiki/index.php/SymbolsDialog (bzr r11782) --- src/selection-chemistry.cpp | 158 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) (limited to 'src/selection-chemistry.cpp') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 332e9a34e..904e21960 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -11,6 +11,7 @@ * Martin Sucha * Abhishek Sharma * Kris De Gussem + * Tavmjong Bah (Symbol additions) * * Copyright (C) 1999-2010,2012 authors * Copyright (C) 2001-2002 Ximian, Inc. @@ -71,6 +72,7 @@ SPCycleType SP_CYCLING = SP_CYCLE_FOCUS; #include "sp-gradient-reference.h" #include "sp-linear-gradient-fns.h" #include "sp-pattern.h" +#include "sp-symbol.h" #include "sp-radial-gradient-fns.h" #include "gradient-context.h" #include "sp-namedview.h" @@ -2887,6 +2889,162 @@ void sp_selection_to_guides(SPDesktop *desktop) DocumentUndo::done(doc, SP_VERB_EDIT_SELECTION_2_GUIDES, _("Objects to guides")); } +/* + * Convert to , leaving all elements referencing group unchanged. + */ +void sp_selection_symbol(SPDesktop *desktop, bool apply ) +{ + + if (desktop == NULL) { + return; + } + + SPDocument *doc = sp_desktop_document(desktop); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + + 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; + } + + SPObject* group = selection->single(); + + // 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; + } + + // 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( group ) ) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Group selection first to convert to symbol.")); + return; + } + + doc->ensureUpToDate(); + + Inkscape::XML::Node *symbol = xml_doc->createElement("svg:symbol"); + symbol->setAttribute("style", group->getAttribute("style")); + symbol->setAttribute("title", group->getAttribute("title")); + symbol->setAttribute("transform", group->getAttribute("transform")); + + Glib::ustring id = group->getAttribute("id"); + + // Now we need to copy all children of group + GSList* children = group->childList(false); + children = g_slist_reverse(children); + for (GSList* i = children; i != NULL; i = i->next ) { + SPObject* child = SP_OBJECT(i->data); + Inkscape::XML::Node *dup = child->getRepr()->duplicate(xml_doc); + symbol->appendChild(dup); + child->deleteObject(true); + } + + // 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); + + Inkscape::GC::release(symbol); + selection->clear(); + // Group just disappears, nothing to select. + + // Need to signal Symbol dialog to update + + g_slist_free(children); + + DocumentUndo::done(doc, SP_VERB_EDIT_SYMBOL, _("Group to symbol")); +} + +/* + * Convert to . All elements referencing symbol remain unchanged. + */ +void sp_selection_unsymbol(SPDesktop *desktop) +{ + + if (desktop == NULL) { + return; + } + + SPDocument *doc = sp_desktop_document(desktop); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); + + Inkscape::Selection *selection = sp_desktop_selection(desktop); + + // Check if something is selected. + if (selection->isEmpty()) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a symbol to extract objects from.")); + return; + } + + 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() ) ) { + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select only one symbol to convert to group.")); + return; + } + + doc->ensureUpToDate(); + + SPObject* symbol = use->firstChild(); + + Inkscape::XML::Node *group = xml_doc->createElement("svg:g"); + group->setAttribute("style", symbol->getAttribute("style")); + group->setAttribute("title", symbol->getAttribute("title")); + group->setAttribute("transform", symbol->getAttribute("transform")); + + Glib::ustring id = symbol->getAttribute("id"); + + // Now we need to copy all children of symbol + GSList* children = symbol->childList(false); + children = g_slist_reverse(children); + for (GSList* i = children; i != NULL; i = i->next ) { + SPObject* child = SP_OBJECT(i->data); + Inkscape::XML::Node *dup = child->getRepr()->duplicate(xml_doc); + group->appendChild(dup); + child->deleteObject(true); + } + + SPObject* parent = use->parent; // So we insert next to (easier to find) + + // Need to delete ; all other elements that referenced should + // auto-magically reference . + symbol->deleteObject(true); + group->setAttribute("id",id.c_str()); // After we delete symbol with same id. + parent->getRepr()->appendChild(group); + //use->deleteObject(true); + + SPItem *group_item = static_cast(sp_desktop_document(desktop)->getObjectByRepr(group)); + Inkscape::GC::release(group); + selection->clear(); + selection->set(group_item); + + // Need to signal Symbol dialog to update + + g_slist_free(children); + + DocumentUndo::done(doc, SP_VERB_EDIT_UNSYMBOL, _("Group from symbol")); +} + void sp_selection_tile(SPDesktop *desktop, bool apply) { -- cgit v1.2.3 From f8a5b66bb57495c83274218dc98530a071b10f27 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Sun, 11 Nov 2012 11:20:05 +0000 Subject: cppcheck: Convert more C-style pointer casts to GObject or C++ (bzr r11867) --- src/selection-chemistry.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/selection-chemistry.cpp') diff --git a/src/selection-chemistry.cpp b/src/selection-chemistry.cpp index 904e21960..3b1028ab8 100644 --- a/src/selection-chemistry.cpp +++ b/src/selection-chemistry.cpp @@ -3450,7 +3450,10 @@ void sp_selection_create_bitmap_copy(SPDesktop *desktop) // Run filter, if any if (run) { g_print("Running external filter: %s\n", run); - system(run); + int result = system(run); + + if(result == -1) + g_warning("Could not run external filter: %s\n", run); } // Import the image back -- cgit v1.2.3