diff options
| author | Michael Soegtrop <MSoegtrop@yahoo.de> | 2017-06-05 13:01:17 +0000 |
|---|---|---|
| committer | Michael Soegtrop <MSoegtrop@yahoo.de> | 2017-06-05 13:01:17 +0000 |
| commit | e7248b2fa042f42a5c4dd14cd86ab6a5b4524059 (patch) | |
| tree | 9097520c54e355ded9bd0b4d6618af4e8dacdd91 /src/path-chemistry.cpp | |
| parent | updated to latest trunk (diff) | |
| parent | [Bug #1695016] Xaml export misses some radialGradients. (diff) | |
| download | inkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.tar.gz inkscape-e7248b2fa042f42a5c4dd14cd86ab6a5b4524059.zip | |
updated to latest trunk
(bzr r14876.2.4)
Diffstat (limited to 'src/path-chemistry.cpp')
| -rw-r--r-- | src/path-chemistry.cpp | 188 |
1 files changed, 98 insertions, 90 deletions
diff --git a/src/path-chemistry.cpp b/src/path-chemistry.cpp index 1a345b565..7840c4ca8 100644 --- a/src/path-chemistry.cpp +++ b/src/path-chemistry.cpp @@ -15,15 +15,13 @@ */ #ifdef HAVE_CONFIG_H -# include <config.h> +#include <config.h> #endif #include <cstring> #include <string> #include "xml/repr.h" #include "svg/svg.h" #include "display/curve.h" -#include "color.h" -#include <glib.h> #include <glibmm/i18n.h> #include "sp-path.h" #include "sp-text.h" @@ -37,12 +35,13 @@ #include "selection.h" #include "box3d.h" -#include <2geom/pathvector.h> #include "selection-chemistry.h" #include "path-chemistry.h" #include "verbs.h" +#include "object-set.h" using Inkscape::DocumentUndo; +using Inkscape::ObjectSet; inline bool less_than_items(SPItem const *first, SPItem const *second) @@ -52,39 +51,42 @@ inline bool less_than_items(SPItem const *first, SPItem const *second) } void -sp_selected_path_combine(SPDesktop *desktop, bool skip_undo) +ObjectSet::combine(bool skip_undo) { - Inkscape::Selection *selection = desktop->getSelection(); - SPDocument *doc = desktop->getDocument(); + //Inkscape::Selection *selection = desktop->getSelection(); + SPDocument *doc = document(); - std::vector<SPItem*> items(selection->itemList()); + std::vector<SPItem*> items_copy(items().begin(), items().end()); - if (items.size() < 1) { - desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine.")); + if (items_copy.size() < 1) { + if(desktop()) + desktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to combine.")); return; } - desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Combining paths...")); - // set "busy" cursor - desktop->setWaitingCursor(); + if(desktop()){ + desktop()->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Combining paths...")); + // set "busy" cursor + desktop()->setWaitingCursor(); + } - items = sp_degroup_list (items); // descend into any groups in selection + items_copy = sp_degroup_list (items_copy); // descend into any groups in selection std::vector<SPItem*> to_paths; - for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i) { + for (std::vector<SPItem*>::const_reverse_iterator i = items_copy.rbegin(); i != items_copy.rend(); ++i) { if (!dynamic_cast<SPPath *>(*i) && !dynamic_cast<SPGroup *>(*i)) { to_paths.push_back(*i); } } std::vector<Inkscape::XML::Node*> converted; - bool did = sp_item_list_to_curves(to_paths, items, converted); + bool did = sp_item_list_to_curves(to_paths, items_copy, converted); for (std::vector<Inkscape::XML::Node*>::const_iterator i = converted.begin(); i != converted.end(); ++i) - items.push_back((SPItem*)doc->getObjectByRepr(*i)); + items_copy.push_back((SPItem*)doc->getObjectByRepr(*i)); - items = sp_degroup_list (items); // converting to path may have added more groups, descend again + items_copy = sp_degroup_list (items_copy); // converting to path may have added more groups, descend again - sort(items.begin(),items.end(),less_than_items); - assert(!items.empty()); // cannot be NULL because of list length check at top of function + sort(items_copy.begin(),items_copy.end(),less_than_items); + assert(!items_copy.empty()); // cannot be NULL because of list length check at top of function // remember the position, id, transform and style of the topmost path, they will be assigned to the combined one gint position = 0; @@ -98,10 +100,10 @@ sp_selected_path_combine(SPDesktop *desktop, bool skip_undo) Inkscape::XML::Node *parent = NULL; if (did) { - selection->clear(); + clear(); } - for (std::vector<SPItem*>::const_reverse_iterator i = items.rbegin(); i != items.rend(); ++i){ + for (std::vector<SPItem*>::const_reverse_iterator i = items_copy.rbegin(); i != items_copy.rend(); ++i){ SPItem *item = *i; SPPath *path = dynamic_cast<SPPath *>(item); @@ -110,7 +112,7 @@ sp_selected_path_combine(SPDesktop *desktop, bool skip_undo) } if (!did) { - selection->clear(); + clear(); did = true; } @@ -145,7 +147,7 @@ sp_selected_path_combine(SPDesktop *desktop, bool skip_undo) first->deleteObject(false); // delete the topmost. - Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Document *xml_doc = doc->getReprDoc(); Inkscape::XML::Node *repr = xml_doc->createElement("svg:path"); // restore id, transform, path effect, and style @@ -173,37 +175,40 @@ sp_selected_path_combine(SPDesktop *desktop, bool skip_undo) // move to the position of the topmost, reduced by the number of deleted items repr->setPosition(position > 0 ? position : 0); if ( !skip_undo ) { - DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_COMBINE, + DocumentUndo::done(doc, SP_VERB_SELECTION_COMBINE, _("Combine")); } - selection->set(repr); + set(repr); Inkscape::GC::release(repr); } else { - desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to combine in the selection.")); + if(desktop()) + desktop()->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to combine in the selection.")); } - desktop->clearWaitingCursor(); + if(desktop()) + desktop()->clearWaitingCursor(); } void -sp_selected_path_break_apart(SPDesktop *desktop, bool skip_undo) +ObjectSet::breakApart(bool skip_undo) { - Inkscape::Selection *selection = desktop->getSelection(); - - if (selection->isEmpty()) { - desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to break apart.")); + if (isEmpty()) { + if(desktop()) + desktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to break apart.")); return; } - - desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Breaking apart paths...")); - // set "busy" cursor - desktop->setWaitingCursor(); + if(desktop()){ + desktop()->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Breaking apart paths...")); + // set "busy" cursor + desktop()->setWaitingCursor(); + + } bool did = false; - std::vector<SPItem*> itemlist(selection->itemList()); + std::vector<SPItem*> itemlist(items().begin(), items().end()); for (std::vector<SPItem*>::const_iterator i = itemlist.begin(); i != itemlist.end(); ++i){ SPItem *item = *i; @@ -250,8 +255,9 @@ sp_selected_path_break_apart(SPDesktop *desktop, bool skip_undo) repr->setAttribute("inkscape:original-d", str); else repr->setAttribute("d", str); + str = sp_svg_transform_write(transform); + repr->setAttribute("transform", str); g_free(str); - repr->setAttribute("transform", sp_svg_transform_write(transform)); // add the new repr to the parent parent->appendChild(repr); @@ -267,83 +273,83 @@ sp_selected_path_break_apart(SPDesktop *desktop, bool skip_undo) Inkscape::GC::release(repr); } - selection->setReprList(reprs); + setReprList(reprs); g_slist_free(list); g_free(style); g_free(path_effect); } - - desktop->clearWaitingCursor(); + + if(desktop()) + desktop()->clearWaitingCursor(); if (did) { if ( !skip_undo ) { - DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_BREAK_APART, + DocumentUndo::done(document(), SP_VERB_SELECTION_BREAK_APART, _("Break apart")); } } else { - desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to break apart in the selection.")); + if(desktop()) + desktop()->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No path(s)</b> to break apart in the selection.")); } } -/* This function is an entry point from GUI */ -void -sp_selected_path_to_curves(Inkscape::Selection *selection, SPDesktop *desktop, bool interactive) +void ObjectSet::toCurves(bool skip_undo) { - if (selection->isEmpty()) { - if (interactive && desktop) - desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to path.")); + if (isEmpty()) { + if (desktop()) + desktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to path.")); return; } bool did = false; - if (interactive && desktop) { - desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Converting objects to paths...")); + if (desktop()) { + desktop()->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Converting objects to paths...")); // set "busy" cursor - desktop->setWaitingCursor(); + desktop()->setWaitingCursor(); } - std::vector<SPItem*> selected(selection->itemList()); + std::vector<SPItem*> selected(items().begin(), items().end()); std::vector<Inkscape::XML::Node*> to_select; - selection->clear(); + clear(); std::vector<SPItem*> items(selected); did = sp_item_list_to_curves(items, selected, to_select); - selection->setReprList(to_select); - selection->addList(selected); + setReprList(to_select); + addList(selected); - if (interactive && desktop) { - desktop->clearWaitingCursor(); - if (did) { - DocumentUndo::done(desktop->getDocument(), SP_VERB_OBJECT_TO_CURVE, + if (desktop()) { + desktop()->clearWaitingCursor(); + } + if (did&& !skip_undo) { + DocumentUndo::done(document(), SP_VERB_OBJECT_TO_CURVE, _("Object to path")); - } else { - desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects</b> to convert to path in the selection.")); - return; - } + } else { + if(desktop()) + desktop()->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No objects</b> to convert to path in the selection.")); + return; } } /** Converts the selected items to LPEItems if they are not already so; e.g. SPRects) */ -void sp_selected_to_lpeitems(SPDesktop *desktop) +void ObjectSet::toLPEItems() { - Inkscape::Selection *selection = desktop->getSelection(); - if (selection->isEmpty()) { + if (isEmpty()) { return; } - std::vector<SPItem*> selected(selection->itemList()); + std::vector<SPItem*> selected(items().begin(), items().end()); std::vector<Inkscape::XML::Node*> to_select; - selection->clear(); + clear(); std::vector<SPItem*> items(selected); sp_item_list_to_curves(items, selected, to_select, true); - selection->setReprList(to_select); - selection->addList(selected); + setReprList(to_select); + addList(selected); } bool @@ -493,7 +499,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Whole text's style */ Glib::ustring style_str = - item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + item->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, item->parent ? item->parent->style : NULL); // TODO investigate posibility g_repr->setAttribute("style", style_str.c_str()); Inkscape::Text::Layout::iterator iter = te_get_layout(item)->begin(); @@ -514,7 +520,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) pos_obj = pos_obj->parent; // SPStrings don't have style } Glib::ustring style_str = - pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility + pos_obj->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, pos_obj->parent ? pos_obj->parent->style : NULL); // TODO investigate posibility // get path from iter to iter_next: SPCurve *curve = te_get_layout(item)->convertToCurves(iter, iter_next); @@ -547,7 +553,8 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) return g_repr; } - + + SP_LPE_ITEM(item)->removeAllPathEffects(true); SPCurve *curve = NULL; { SPShape *shape = dynamic_cast<SPShape *>(item); @@ -573,7 +580,7 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) /* Style */ Glib::ustring style_str = - item->style->write( SP_STYLE_FLAG_IFDIFF, item->parent ? item->parent->style : NULL); // TODO investigate posibility + item->style->write( SP_STYLE_FLAG_IFDIFF, SP_STYLE_SRC_UNSET, item->parent ? item->parent->style : NULL); // TODO investigate posibility repr->setAttribute("style", style_str.c_str()); /* Mask */ @@ -600,24 +607,24 @@ sp_selected_item_to_curved_repr(SPItem *item, guint32 /*text_grouping_policy*/) void -sp_selected_path_reverse(SPDesktop *desktop) +ObjectSet::pathReverse() { - Inkscape::Selection *selection = desktop->getSelection(); - std::vector<SPItem*> items = selection->itemList(); - - if (items.empty()) { - desktop->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse.")); + if (isEmpty()) { + if(desktop()) + desktop()->getMessageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>path(s)</b> to reverse.")); return; } // set "busy" cursor - desktop->setWaitingCursor(); - + if(desktop()){ + desktop()->setWaitingCursor(); + desktop()->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); + } + bool did = false; - desktop->messageStack()->flash(Inkscape::IMMEDIATE_MESSAGE, _("Reversing paths...")); - for (std::vector<SPItem*>::const_iterator i = items.begin(); i != items.end(); ++i){ + for (auto i = items().begin(); i != items().end(); ++i){ SPPath *path = dynamic_cast<SPPath *>(*i); if (!path) { @@ -645,14 +652,15 @@ sp_selected_path_reverse(SPDesktop *desktop) g_free(nodetypes); } } - - desktop->clearWaitingCursor(); + if(desktop()) + desktop()->clearWaitingCursor(); if (did) { - DocumentUndo::done(desktop->getDocument(), SP_VERB_SELECTION_REVERSE, + DocumentUndo::done(document(), SP_VERB_SELECTION_REVERSE, _("Reverse path")); } else { - desktop->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection.")); + if(desktop()) + desktop()->getMessageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No paths</b> to reverse in the selection.")); } } |
