=== modified file 'src/live_effects/parameter/path.cpp' --- src/live_effects/parameter/path.cpp 2016-03-18 17:34:07 +0000 +++ src/live_effects/parameter/path.cpp 2016-06-10 08:12:18 +0000 @@ -38,6 +38,8 @@ #include "uri.h" #include "sp-shape.h" #include "sp-text.h" +#include "sp-defs.h" +#include "sp-namedview.h" #include "display/curve.h" #include "ui/tools/node-tool.h" @@ -213,21 +215,46 @@ if (!tools_isactive(dt, TOOLS_NODES)) { tools_switch(dt, TOOLS_NODES); } - - Inkscape::UI::Tools::NodeTool *nt = static_cast(dt->event_context); - std::set shapes; - ShapeRecord r; - - r.role = SHAPE_ROLE_LPE_PARAM; - r.edit_transform = item->i2dt_affine(); // TODO is it right? if (!href) { - r.item = reinterpret_cast(param_effect->getLPEObj()); - r.lpe_key = param_key; + SPDocument *document = dt->getDocument(); + bool saved = DocumentUndo::getUndoSensitive(document); + DocumentUndo::setUndoSensitive(document, false); + SPDefs *defs = document->getDefs(); + Inkscape::XML::Node *path; + Inkscape::XML::Document *xml_doc = document->getReprDoc(); + path = xml_doc->createElement("svg:path"); + path->setAttribute("d", sp_svg_write_path(_pathvector)); + SPItem * item_lpe = reinterpret_cast(param_effect->getLPEObj()); + gchar * path_parameter_id = g_strdup_printf("%s%s", item_lpe->getAttribute("id"),"_pathparameter"); + SPObject * previous_object = document->getObjectById(path_parameter_id); + if (previous_object) { + Inkscape::XML::Node * prev = previous_object->getRepr(); + prev->setAttribute("d", sp_svg_write_path(_pathvector)); + Inkscape::GC::release(prev); + previous_object->updateRepr(); + SPItem *path_param = SP_ITEM(previous_object); + } else { + path->setAttribute("id", path_parameter_id); + SPItem *path_param = SP_ITEM(defs->appendChildRepr(path)); + Inkscape::GC::release(path); + path_param->updateRepr(); + } + param_write_to_repr(g_strdup_printf("#%s", path_parameter_id)); + DocumentUndo::setUndoSensitive(document, saved); + param_editOncanvas(item, dt); } else { + SPDocument *document = dt->getDocument(); + Inkscape::UI::Tools::NodeTool *nt = static_cast(dt->event_context); + std::set shapes; + ShapeRecord r; + r.role = SHAPE_ROLE_LPE_PARAM; + Inkscape::Util::Unit const * unit = dt->getNamedView()->getDisplayUnit(); + Geom::Affine inverse = Geom::Scale(1, -1) * Geom::Translate(0, document->getHeight().value("px")); + r.edit_transform = item->i2dt_affine() * inverse; // TODO is it right? r.item = ref.getObject(); + shapes.insert(r); + nt->_multipath->setItems(shapes); } - shapes.insert(r); - nt->_multipath->setItems(shapes); } void @@ -239,7 +266,7 @@ void PathParam::addCanvasIndicators(SPLPEItem const*/*lpeitem*/, std::vector &hp_vec) { - hp_vec.push_back(_pathvector); + hp_vec.push_back(_pathvector); } /* @@ -423,6 +450,8 @@ if (item != NULL) { param_editOncanvas(item, SP_ACTIVE_DESKTOP); } + DocumentUndo::done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Edit path parameter")); } void @@ -436,9 +465,9 @@ if (item != NULL) { Geom::PathVector path_clipboard = sp_svg_read_pathv(svgd); path_clipboard *= item->i2doc_affine().inverse(); + path_clipboard *= Geom::Translate(_pathvector.initialPoint()); svgd = sp_svg_write_path( path_clipboard ); } - param_write_to_repr(svgd); signal_path_pasted.emit(); }