From 50714133d92da517b5185385ea4c553408c80e54 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Wed, 28 Dec 2016 09:42:19 +0100 Subject: First attemp working (bzr r15356.1.1) --- src/live_effects/CMakeLists.txt | 6 ++ src/live_effects/effect.cpp | 10 +- src/live_effects/effect.h | 1 + src/live_effects/lpe-clone-original.cpp | 169 ++++++++++++++++++++++++++++++-- src/live_effects/lpe-clone-original.h | 20 +++- src/sp-ellipse.cpp | 13 ++- src/sp-item-group.cpp | 37 ++++--- src/sp-lpe-item.cpp | 21 ++-- src/sp-lpe-item.h | 3 +- src/sp-object.cpp | 14 +++ src/sp-object.h | 3 + src/sp-path.cpp | 4 +- src/ui/clipboard.cpp | 2 + 13 files changed, 261 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/live_effects/CMakeLists.txt b/src/live_effects/CMakeLists.txt index 784317090..5ffccc7c0 100644 --- a/src/live_effects/CMakeLists.txt +++ b/src/live_effects/CMakeLists.txt @@ -60,6 +60,9 @@ set(live_effects_SRC parameter/array.cpp parameter/bool.cpp parameter/filletchamferpointarray.cpp + parameter/item-reference.cpp + parameter/item.cpp + parameter/originalitem.cpp parameter/originalpath.cpp parameter/originalpatharray.cpp parameter/parameter.cpp @@ -142,6 +145,9 @@ set(live_effects_SRC parameter/bool.h parameter/enum.h parameter/filletchamferpointarray.h + parameter/item.h + parameter/item-reference.h + parameter/originalitem.h parameter/originalpath.h parameter/originalpatharray.h parameter/parameter.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 5cc0d6f20..cfd393b87 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -116,7 +116,7 @@ const Util::EnumData LPETypeData[] = { {RULER, N_("Ruler"), "ruler"}, /* 0.91 */ {POWERSTROKE, N_("Power stroke"), "powerstroke"}, - {CLONE_ORIGINAL, N_("Clone original path"), "clone_original"}, + {CLONE_ORIGINAL, N_("Clone original"), "clone_original"}, /* 0.92 */ {SIMPLIFY, N_("Simplify"), "simplify"}, {LATTICE2, N_("Lattice Deformation 2"), "lattice2"}, @@ -457,8 +457,7 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) //printf("(SPLPEITEM*) %p\n", sp_lpe_item); SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ - sp_curve = shape->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector(); + setSPCurve(shape->getCurve()); } doBeforeEffect(lpeitem); if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { @@ -468,6 +467,11 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) update_helperpath(); } +void Effect::setSPCurve(SPCurve *curve) +{ + sp_curve = curve; + pathvector_before_effect = curve->get_pathvector(); +} /** * Effects can have a parameter path set before they are applied by accepting a nonzero number of * mouse clicks. This method activates the pen context, which waits for the specified number of diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 1997ff0ca..e975deb05 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -73,6 +73,7 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); + void setSPCurve(SPCurve *curve); /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 10418a02d..be8bc9e0d 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -6,6 +6,11 @@ #include "live_effects/lpe-clone-original.h" #include "display/curve.h" +#include "svg/path-string.h" +#include "svg/svg.h" +#include +#include "xml/sp-css-attr.h" + // TODO due to internal breakage in glibmm headers, this must be last: #include @@ -14,9 +19,148 @@ namespace LivePathEffect { LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : Effect(lpeobject), - linked_path(_("Linked path:"), _("Path from which to take the original path data"), "linkedpath", &wr, this) + linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), + preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), + attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), + style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") { - registerParameter( dynamic_cast(&linked_path) ); + registerParameter(&linked_item); + registerParameter(&attributes); + registerParameter(&style_attributes); + registerParameter(&preserve_position); + attributes.param_hide_canvas_text(); + style_attributes.param_hide_canvas_text(); + apply_to_clippath_and_mask = true; +} + +void +LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...) +{ + va_list args; + va_start(args, first_attribute); + SPDocument * document = SP_ACTIVE_DOCUMENT; + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); + size_t index = 0; + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneAttrbutes(*obj_it, dest_child, live, first_attribute, args); + index++; + } + } + SPShape * shape_origin = SP_SHAPE(origin); + SPShape * shape_dest = SP_SHAPE(dest); + for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) { + std::vector elems; + boost::split(elems, att, boost::is_any_of(",")); + for (std::vector::const_iterator atts = elems.begin(); + atts != elems.end(); ++atts) { + const char* attribute = (*atts).c_str(); + if ( std::strcmp(attribute, "transform") == 0 ) { + Geom::Affine affine_dest = Geom::identity(); + sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest); + dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); + if (preserve_position) { + Geom::Affine affine_origin = Geom::identity(); + sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); + SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin; + } + } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) { + SPCurve *c = NULL; + if (std::strcmp(attribute, "d") == 0) { + c = shape_origin->getCurve(); + } else { + c = shape_origin->getCurveBeforeLPE(); + } + if (c) { + Geom::PathVector c_pv = c->get_pathvector(); + if (preserve_position) { + Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); + if (orig_bbox) { + c_pv *= Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)); + } + } + c->set_pathvector(c_pv); + shape_dest->setCurveInsync(c, TRUE); + dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); + c->unref(); + } else { + dest->getRepr()->setAttribute(attribute, NULL); + } + } else { + dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); + } + } + } + va_end(args); +} + +void +LPECloneOriginal::cloneStyleAttrbutes(SPObject *origin, SPObject *dest, const char * first_attribute, ...) +{ + va_list args; + va_start(args, first_attribute); + + if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { + std::vector< SPObject * > childs = origin->childList(true); + size_t index = 0; + for (std::vector::iterator obj_it = childs.begin(); + obj_it != childs.end(); ++obj_it) { + SPObject *dest_child = dest->nthChild(index); + cloneStyleAttrbutes(*obj_it, dest_child, first_attribute, args); + index++; + } + } + SPCSSAttr *css_origin = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css_origin, origin->getRepr()->attribute("style")); + SPCSSAttr *css_dest = sp_repr_css_attr_new(); + sp_repr_css_attr_add_from_string(css_dest, dest->getRepr()->attribute("style")); + for (const char* att = first_attribute; att != NULL; att = va_arg(args, const char*)) { + std::vector elems; + boost::split(elems, att, boost::is_any_of(",")); + for (std::vector::const_iterator atts = elems.begin(); + atts != elems.end(); ++atts) { + const char* attribute = (*atts).c_str(); + const char* origin_attribute = sp_repr_css_property(css_origin, attribute, ""); + if (origin_attribute == "") { + sp_repr_css_set_property (css_dest, attribute, NULL); + } else { + sp_repr_css_set_property (css_dest, attribute, origin_attribute); + } + } + Glib::ustring css_str; + sp_repr_css_write_string(css_dest,css_str); + dest->getRepr()->setAttribute("style", css_str.c_str()); + } + va_end(args); +} + +void +LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ + original_bbox(lpeitem); + if (linked_item.linksToItem() && sp_lpe_item) { + cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), NULL); //NULL required + cloneStyleAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), style_attributes.param_getSVGValue(), NULL); //NULL required + SPShape * shape = dynamic_cast(sp_lpe_item); + if(shape){ + this->setSPCurve(shape->getCurve()); + } + } +} + +void +LPECloneOriginal::doOnApply(SPLPEItem const* lpeitem){ + Glib::ustring attributes_value("d,transform"); + attributes.param_setValue(attributes_value); + attributes.write_to_SVG(); + Glib::ustring style_attributes_value("opacity,border-width"); + style_attributes.param_setValue(style_attributes_value); + style_attributes.write_to_SVG(); +} + +void +LPECloneOriginal::doAfterEffect (SPLPEItem const* lpeitem){ } LPECloneOriginal::~LPECloneOriginal() @@ -26,12 +170,21 @@ LPECloneOriginal::~LPECloneOriginal() void LPECloneOriginal::doEffect (SPCurve * curve) { - if ( linked_path.linksToPath() ) { - Geom::PathVector linked_pathv = linked_path.get_pathvector(); - if ( !linked_pathv.empty() ) { - curve->set_pathvector(linked_pathv); - } - } +// std::vector elems; +// const char * attrs = attributes.param_getSVGValue(); +// boost::split(elems, attrs, boost::is_any_of(",")); +// bool has_d = false; +// for (std::vector::const_iterator atts = elems.begin(); +// atts != elems.end(); ++atts) { +// const char* attribute = (*atts).c_str(); +// if (std::strcmp(attribute, "d") == 0) { +// has_d = true; +// } +// } +// if (linked_item.linksToItem() && has_d) { +// curve->reset(); +// } + curve->set_pathvector(pathvector_before_effect); } } // namespace LivePathEffect diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index abf65ded8..148590695 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -10,22 +10,32 @@ */ #include "live_effects/effect.h" -#include "live_effects/parameter/originalpath.h" +#include "live_effects/parameter/originalitem.h" +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/point.h" +#include "live_effects/parameter/text.h" +#include "live_effects/lpegroupbbox.h" namespace Inkscape { namespace LivePathEffect { -class LPECloneOriginal : public Effect { +class LPECloneOriginal : public Effect, GroupBBoxEffect { public: LPECloneOriginal(LivePathEffectObject *lpeobject); virtual ~LPECloneOriginal(); virtual void doEffect (SPCurve * curve); + virtual void doBeforeEffect (SPLPEItem const* lpeitem); + virtual void doAfterEffect (SPLPEItem const* lpeitem); + virtual void doOnApply(SPLPEItem const* lpeitem); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * first_attribute, ...); + void cloneStyleAttrbutes(SPObject *origin, SPObject *dest, const char * first_attribute, ...); private: - OriginalPathParam linked_path; - -private: + OriginalItemParam linked_item; + BoolParam preserve_position; + TextParam attributes; + TextParam style_attributes; LPECloneOriginal(const LPECloneOriginal&); LPECloneOriginal& operator=(const LPECloneOriginal&); }; diff --git a/src/sp-ellipse.cpp b/src/sp-ellipse.cpp index ed1e2b504..9589d6fce 100644 --- a/src/sp-ellipse.cpp +++ b/src/sp-ellipse.cpp @@ -445,11 +445,20 @@ void SPGenericEllipse::set_shape() if (hasPathEffect() && pathEffectsEnabled()) { SPCurve *c_lpe = curve->copy(); bool success = this->performPathEffect(c_lpe); - + if (success) { this->setCurveInsync(c_lpe, TRUE); + } else { + Inkscape::XML::Node *repr = this->getRepr(); + if (gchar const * value = repr->attribute("d")) { + Geom::PathVector pv = sp_svg_read_pathv(value); + SPCurve *oldcurve = new (std::nothrow) SPCurve(pv); + if (oldcurve) { + this->setCurveInsync(oldcurve, TRUE); + oldcurve->unref(); + } + } } - c_lpe->unref(); } diff --git a/src/sp-item-group.cpp b/src/sp-item-group.cpp index 7b2507b5e..808d475c7 100644 --- a/src/sp-item-group.cpp +++ b/src/sp-item-group.cpp @@ -950,25 +950,36 @@ sp_group_perform_patheffect(SPGroup *group, SPGroup *topgroup, bool write) } else { c = subShape->getCurve(); } - + bool success = false; // only run LPEs when the shape has a curve defined if (c) { c->transform(i2anc_affine(subitem, topgroup)); - topgroup->performPathEffect(c); + success = topgroup->performPathEffect(c, subShape); c->transform(i2anc_affine(subitem, topgroup).inverse()); - subShape->setCurve(c, TRUE); - - if (write) { + if (c && success) { + subShape->setCurve(c, TRUE); + if (write) { + Inkscape::XML::Node *repr = subitem->getRepr(); + gchar *str = sp_svg_write_path(c->get_pathvector()); + repr->setAttribute("d", str); + #ifdef GROUP_VERBOSE + g_message("sp_group_perform_patheffect writes 'd' attribute"); + #endif + g_free(str); + } + c->unref(); + } else { + // LPE was unsuccesfull or doeffect stack return null. Read the old 'd'-attribute. Inkscape::XML::Node *repr = subitem->getRepr(); - gchar *str = sp_svg_write_path(c->get_pathvector()); - repr->setAttribute("d", str); -#ifdef GROUP_VERBOSE - g_message("sp_group_perform_patheffect writes 'd' attribute"); -#endif - g_free(str); + if (gchar const * value = repr->attribute("d")) { + Geom::PathVector pv = sp_svg_read_pathv(value); + SPCurve *oldcurve = new (std::nothrow) SPCurve(pv); + if (oldcurve) { + subShape->setCurve(oldcurve, TRUE); + oldcurve->unref(); + } + } } - - c->unref(); } } } diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index e2f61bfb5..f5c930404 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -209,7 +209,7 @@ Inkscape::XML::Node* SPLPEItem::write(Inkscape::XML::Document *xml_doc, Inkscape /** * returns true when LPE was successful. */ -bool SPLPEItem::performPathEffect(SPCurve *curve, bool is_clip_or_mask) { +bool SPLPEItem::performPathEffect(SPCurve *curve, SPShape *current, bool is_clip_or_mask) { if (!curve) { return false; @@ -244,9 +244,11 @@ bool SPLPEItem::performPathEffect(SPCurve *curve, bool is_clip_or_mask) { if (!SP_IS_GROUP(this)) { lpe->doBeforeEffect_impl(this); } - + if (SP_IS_GROUP(this) && current) { + lpe->setSPCurve(current->getCurve()); + } try { - lpe->doEffect(curve); + lpe->doEffect(curve); } catch (std::exception & e) { g_warning("Exception during LPE %s execution. \n %s", lpe->getName().c_str(), e.what()); @@ -695,10 +697,10 @@ SPLPEItem::apply_to_clip_or_mask(SPItem *clip_mask, SPItem *item) try { if(SP_IS_GROUP(this)){ c->transform(i2anc_affine(SP_GROUP(item), SP_GROUP(this))); - success = this->performPathEffect(c, true); + success = this->performPathEffect(c, SP_SHAPE(clip_mask), true); c->transform(i2anc_affine(SP_GROUP(item), SP_GROUP(this)).inverse()); } else { - success = this->performPathEffect(c, true); + success = this->performPathEffect(c, NULL, true); } } catch (std::exception & e) { g_warning("Exception during LPE execution. \n %s", e.what()); @@ -709,12 +711,13 @@ SPLPEItem::apply_to_clip_or_mask(SPItem *clip_mask, SPItem *item) success = false; } Inkscape::XML::Node *repr = clip_mask->getRepr(); - if (success) { + // This c check allow to not apply LPE if curve is NULL after performPathEffect used in clone.obgets LPE + if (success && c) { gchar *str = sp_svg_write_path(c->get_pathvector()); repr->setAttribute("d", str); g_free(str); } else { - // LPE was unsuccesfull. Read the old 'd'-attribute. + // LPE was unsuccesfull or doeffect stack return null.. Read the old 'd'-attribute. if (gchar const * value = repr->attribute("d")) { Geom::PathVector pv = sp_svg_read_pathv(value); SPCurve *oldcurve = new (std::nothrow) SPCurve(pv); @@ -724,7 +727,9 @@ SPLPEItem::apply_to_clip_or_mask(SPItem *clip_mask, SPItem *item) } } } - c->unref(); + if (c) { + c->unref(); + } } } } diff --git a/src/sp-lpe-item.h b/src/sp-lpe-item.h index 9e5cb3329..9cf868cf2 100644 --- a/src/sp-lpe-item.h +++ b/src/sp-lpe-item.h @@ -23,6 +23,7 @@ class LivePathEffectObject; class SPCurve; +class SPShape; class SPDesktop; namespace Inkscape{ @@ -69,7 +70,7 @@ public: virtual void update_patheffect(bool write); - bool performPathEffect(SPCurve *curve, bool is_clip_or_mask = false); + bool performPathEffect(SPCurve *curve, SPShape *current = NULL, bool is_clip_or_mask = false); bool pathEffectsEnabled() const; bool hasPathEffect() const; diff --git a/src/sp-object.cpp b/src/sp-object.cpp index e9c60fc7d..c2122e109 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -773,6 +773,20 @@ void SPObject::appendChild(Inkscape::XML::Node *child) { repr->appendChild(child); } +SPObject* SPObject::nthChild(unsigned index) { + g_assert(this->repr); + if (hasChildren()) { + std::vector l; + unsigned counter = 0; + for (auto& child: children) { + if (counter == index) { + return &child; + } + } + } + return NULL; +} + void SPObject::addChild(Inkscape::XML::Node *child, Inkscape::XML::Node * prev) { g_assert(this->repr); diff --git a/src/sp-object.h b/src/sp-object.h index 9abbd324b..d145e966b 100644 --- a/src/sp-object.h +++ b/src/sp-object.h @@ -318,6 +318,9 @@ public: SPObject *lastChild() { return children.empty() ? nullptr : &children.back(); } SPObject const *lastChild() const { return children.empty() ? nullptr : &children.back(); } + SPObject *nthChild(unsigned index); + SPObject const *nthChild(unsigned index) const; + enum Action { ActionGeneral, ActionBBox, ActionUpdate, ActionShow }; /** diff --git a/src/sp-path.cpp b/src/sp-path.cpp index b593b7937..0a2ce4c09 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -354,9 +354,9 @@ g_message("sp_path_update_patheffect writes 'd' attribute"); if (gchar const * value = repr->attribute("d")) { Geom::PathVector pv = sp_svg_read_pathv(value); SPCurve *oldcurve = new SPCurve(pv); - if (oldcurve) { - this->setCurve(oldcurve, TRUE); + this->setCurveInsync(oldcurve, TRUE); + repr->setAttribute("d", value); oldcurve->unref(); } } diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index a8e708597..42fc2fab4 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -410,6 +410,8 @@ const gchar *ClipboardManagerImpl::getFirstObjectID() strcmp(ch->name(), "svg:use") && strcmp(ch->name(), "svg:text") && strcmp(ch->name(), "svg:image") && + strcmp(ch->name(), "svg:ellipse") && + strcmp(ch->name(), "svg:circle") && strcmp(ch->name(), "svg:rect") ) { ch = ch->next(); -- cgit v1.2.3 From dade3a4aa7da7579145341ee8e63149de053d99a Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Dec 2016 17:39:41 +0100 Subject: Fixing transforms and adding scale (bzr r15356.2.1) --- src/live_effects/lpe-clone-original.cpp | 25 +++++++++++++++++-------- src/live_effects/lpe-clone-original.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index be8bc9e0d..d702e98d5 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -20,14 +20,19 @@ namespace LivePathEffect { LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : Effect(lpeobject), linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), + scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") { registerParameter(&linked_item); + registerParameter(&scale); registerParameter(&attributes); registerParameter(&style_attributes); registerParameter(&preserve_position); + scale.param_set_range(0.01, 999999.0); + scale.param_set_increments(1, 1); + scale.param_set_digits(2); attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); apply_to_clippath_and_mask = true; @@ -58,13 +63,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co atts != elems.end(); ++atts) { const char* attribute = (*atts).c_str(); if ( std::strcmp(attribute, "transform") == 0 ) { - Geom::Affine affine_dest = Geom::identity(); - sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest); + Geom::Affine affine_dest = SP_ITEM(dest)->transform; dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); + Geom::Affine affine_origin = Geom::identity(); + sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); if (preserve_position) { - Geom::Affine affine_origin = Geom::identity(); - sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); - SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin; + SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin ; } } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) { SPCurve *c = NULL; @@ -75,11 +79,16 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co } if (c) { Geom::PathVector c_pv = c->get_pathvector(); - if (preserve_position) { - Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); - if (orig_bbox) { + Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); + if (orig_bbox) { + if (preserve_position) { c_pv *= Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)); } + if (scale != 100.0) { + double scale_affine = scale/100.0; + Geom::Affine scale = Geom::Affine(Geom::Scale(scale_affine)); + c_pv *= Geom::Translate((*orig_bbox).corner(0)) * scale * Geom::Translate((*orig_bbox).corner(0)).inverse(); + } } c->set_pathvector(c_pv); shape_dest->setCurveInsync(c, TRUE); diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index 148590695..bec835ae1 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -33,6 +33,7 @@ public: private: OriginalItemParam linked_item; + ScalarParam scale; BoolParam preserve_position; TextParam attributes; TextParam style_attributes; -- cgit v1.2.3 From fd45bf5cbe22dddb7b016a3025f3553dbb0f1e27 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Dec 2016 17:42:27 +0100 Subject: Fixing scale (bzr r15356.2.2) --- src/live_effects/lpe-clone-original.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index d702e98d5..04afe00e2 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -87,7 +87,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Affine scale = Geom::Affine(Geom::Scale(scale_affine)); - c_pv *= Geom::Translate((*orig_bbox).corner(0)) * scale * Geom::Translate((*orig_bbox).corner(0)).inverse(); + c_pv *= Geom::Translate((*orig_bbox).corner(0)).inverse() * scale * Geom::Translate((*orig_bbox).corner(0)); } } c->set_pathvector(c_pv); -- cgit v1.2.3 From 50fca17129701b09a9049e4469ca39d0c06c15a7 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Wed, 28 Dec 2016 17:46:37 +0100 Subject: Fixing scale (bzr r15356.2.3) --- src/live_effects/lpe-clone-original.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 04afe00e2..4ba752b85 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -87,7 +87,11 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Affine scale = Geom::Affine(Geom::Scale(scale_affine)); - c_pv *= Geom::Translate((*orig_bbox).corner(0)).inverse() * scale * Geom::Translate((*orig_bbox).corner(0)); + if (preserve_position) { + c_pv *= Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)).inverse() * scale * Geom::Translate(Geom::Point(boundingbox_X.min(), boundingbox_Y.min()) - (*orig_bbox).corner(0)); + } else { + c_pv *= Geom::Translate((*orig_bbox).corner(0)).inverse() * scale * Geom::Translate((*orig_bbox).corner(0)); + } } } c->set_pathvector(c_pv); -- cgit v1.2.3 From f69e17d45c7311cb8430caa03f4f41be63ac9279 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Thu, 29 Dec 2016 21:32:45 +0100 Subject: Add sp_shape to LPE chain and fixing transforms (bzr r15356.1.4) --- src/live_effects/effect.cpp | 41 ++++++++++++++++++++------------- src/live_effects/effect.h | 9 ++++---- src/live_effects/lpe-clone-original.cpp | 33 ++++++++++++++++++-------- src/live_effects/lpe-clone-original.h | 4 +++- src/sp-lpe-item.cpp | 6 ++--- 5 files changed, 60 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index cfd393b87..81a512d23 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -356,7 +356,7 @@ Effect::Effect(LivePathEffectObject *lpeobject) sp_lpe_item(NULL), current_zoom(1), upd_params(true), - sp_curve(NULL), + sp_shape(NULL), provides_own_flash_paths(true), // is automatically set to false if providesOwnFlashPaths() is not overridden is_ready(false) // is automatically set to false if providesOwnFlashPaths() is not overridden { @@ -392,9 +392,9 @@ Effect::doOnApply (SPLPEItem const*/*lpeitem*/) } void -Effect::setSelectedNodePoints(std::vector sNP) +Effect::setSelectedNodePoints(std::vector selected_np) { - selectedNodesPoints = sNP; + selected_nodes_points = selected_np; } void @@ -404,16 +404,16 @@ Effect::setCurrentZoom(double cZ) } bool -Effect::isNodePointSelected(Geom::Point const &nodePoint) const +Effect::isNodePointSelected(Geom::Point const &node_point) const { - if (selectedNodesPoints.size() > 0) { + if (selected_nodes_points.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector::const_iterator i = selectedNodesPoints.begin(); - i != selectedNodesPoints.end(); ++i) { + for (std::vector::const_iterator i = selected_nodes_points.begin(); + i != selected_nodes_points.end(); ++i) { Geom::Point p = *i; Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); - Geom::Point p2(nodePoint[X],nodePoint[Y]); + Geom::Point p2(node_point[X], node_point[Y]); p2 *= transformCoordinate; if (Geom::are_near(p, p2, 0.01)) { return true; @@ -446,20 +446,24 @@ void Effect::doOnVisibilityToggled(SPLPEItem const* /*lpeitem*/) void Effect::doOnApply_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - /*sp_curve = SP_SHAPE(sp_lpe_item)->getCurve(); - pathvector_before_effect = sp_curve->get_pathvector();*/ + SPShape * shape = dynamic_cast(sp_lpe_item); + if(shape){ + setCurrentShape(shape); + } doOnApply(lpeitem); } void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) { sp_lpe_item = const_cast(lpeitem); - //printf("(SPLPEITEM*) %p\n", sp_lpe_item); + //Groups set shape in performPathEffect before each call to doEffect SPShape * shape = dynamic_cast(sp_lpe_item); if(shape){ - setSPCurve(shape->getCurve()); + setCurrentShape(shape); } + //printf("(SPLPEITEM*) %p\n", sp_lpe_item); doBeforeEffect(lpeitem); + if (apply_to_clippath_and_mask && SP_IS_GROUP(sp_lpe_item)) { sp_lpe_item->apply_to_clippath(sp_lpe_item); sp_lpe_item->apply_to_mask(sp_lpe_item); @@ -467,10 +471,15 @@ void Effect::doBeforeEffect_impl(SPLPEItem const* lpeitem) update_helperpath(); } -void Effect::setSPCurve(SPCurve *curve) -{ - sp_curve = curve; - pathvector_before_effect = curve->get_pathvector(); +void Effect::setCurrentShape(SPShape * shape){ + if(shape){ + sp_shape = shape; + if (!(sp_curve = sp_shape->getCurve())) { + // oops + return; + } + pathvector_before_effect = sp_curve->get_pathvector(); + } } /** * Effects can have a parameter path set before they are applied by accepting a nonzero number of diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index e975deb05..5dfa3de29 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -73,8 +73,8 @@ public: static int acceptsNumClicks(EffectType type); int acceptsNumClicks() const { return acceptsNumClicks(effectType()); } void doAcceptPathPreparations(SPLPEItem *lpeitem); - void setSPCurve(SPCurve *curve); - + SPShape * getCurrentShape(){ return sp_shape; }; + void setCurrentShape(SPShape * shape); /* * isReady() indicates whether all preparations which are necessary to apply the LPE are done, * e.g., waiting for a parameter path either before the effect is created or when it needs a @@ -164,9 +164,10 @@ protected: // instead of normally 'splitting' the path into continuous pwd2 paths and calling doEffect_pwd2 for each. bool concatenate_before_pwd2; - SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them. + SPLPEItem * sp_lpe_item; // these get stored in doBeforeEffect_impl, and derived classes may do as they please with them.z + SPShape * sp_shape; // these get stored in doBeforeEffect_impl before doEffect chain, or in performPathEffects on groups, and derived classes may do as they please with them. double current_zoom; - std::vector selectedNodesPoints; + std::vector selected_nodes_points; SPCurve * sp_curve; Geom::PathVector pathvector_before_effect; private: diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 7072ad161..8176f3811 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -37,10 +37,12 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); apply_to_clippath_and_mask = true; + preserve_position_changed = !preserve_position; + preserve_affine = Geom::identity(); } void -LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes) +LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root) { SPDocument * document = SP_ACTIVE_DOCUMENT; if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { @@ -49,7 +51,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes); + cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes, false); index++; } } @@ -65,7 +67,15 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co Geom::Affine affine_origin = SP_ITEM(origin)->transform; //dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); if (preserve_position) { - SP_ITEM(dest)->transform = Geom::Translate(affine_dest.translation()) * Geom::Translate(affine_origin.translation()).inverse() * affine_origin ; + Geom::Affine dest_affine = Geom::identity(); + if (root) { + dest_affine *= Geom::Translate(preserve_affine.translation()); + preserve_affine = Geom::identity(); + } + dest_affine *= Geom::Translate(affine_dest.translation()); + dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); + dest_affine *= affine_origin; + SP_ITEM(dest)->transform = dest_affine; } else { SP_ITEM(dest)->transform = affine_origin ; } @@ -131,6 +141,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co void LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ original_bbox(lpeitem); + if ( preserve_position_changed != preserve_position ) { + if (!preserve_position) { + preserve_affine = SP_ITEM(sp_lpe_item)->transform; + } + preserve_position_changed = preserve_position; + } if (linked_path.linksToPath()) { //Legacy staff Glib::ustring attributes_value("d"); attributes.param_setValue(attributes_value); @@ -142,11 +158,7 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ linked_path.param_readSVGValue(""); } if (linked_item.linksToItem()) { - cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue()); - SPShape * shape = dynamic_cast(sp_lpe_item); - if(shape){ - this->setSPCurve(shape->getCurve()); - } + cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } @@ -205,7 +217,10 @@ LPECloneOriginal::~LPECloneOriginal() void LPECloneOriginal::doEffect (SPCurve * curve) { - curve->set_pathvector(pathvector_before_effect); + SPShape * shape = getCurrentShape(); + if(shape){ + curve->set_pathvector(shape->getCurve()->get_pathvector()); + } } } // namespace LivePathEffect diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index e232135eb..e8a9a7419 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -29,7 +29,7 @@ public: virtual void doBeforeEffect (SPLPEItem const* lpeitem); virtual void doOnApply(SPLPEItem const* lpeitem); virtual Gtk::Widget * newWidget(); - void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes); + void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); private: OriginalPathParam linked_path; @@ -38,6 +38,8 @@ private: BoolParam preserve_position; TextParam attributes; TextParam style_attributes; + bool preserve_position_changed; + Geom::Affine preserve_affine; LPECloneOriginal(const LPECloneOriginal&); LPECloneOriginal& operator=(const LPECloneOriginal&); }; diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index f5c930404..c7a800041 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -241,12 +241,12 @@ bool SPLPEItem::performPathEffect(SPCurve *curve, SPShape *current, bool is_clip } if (!is_clip_or_mask || (is_clip_or_mask && lpe->apply_to_clippath_and_mask)) { // Groups have their doBeforeEffect called elsewhere + if (SP_IS_GROUP(this) && current) { + lpe->setCurrentShape(current); + } if (!SP_IS_GROUP(this)) { lpe->doBeforeEffect_impl(this); } - if (SP_IS_GROUP(this) && current) { - lpe->setSPCurve(current->getCurve()); - } try { lpe->doEffect(curve); } -- cgit v1.2.3 From 3c16d15761bac73cba9b81b49efe8e71306a5766 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Fri, 30 Dec 2016 19:14:55 +0100 Subject: Fixing clips and masks (bzr r15356.1.6) --- src/live_effects/lpe-clone-original.cpp | 36 +++++++++++++++++++++++---------- src/sp-lpe-item.cpp | 4 ++-- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 8176f3811..81e6809f1 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -8,6 +8,8 @@ #include "display/curve.h" #include "svg/path-string.h" #include "svg/svg.h" +#include "sp-clippath.h" +#include "sp-mask.h" #include "xml/sp-css-attr.h" // TODO due to internal breakage in glibmm headers, this must be last: @@ -36,9 +38,9 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : scale.param_set_digits(2); attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); - apply_to_clippath_and_mask = true; preserve_position_changed = !preserve_position; preserve_affine = Geom::identity(); + apply_to_clippath_and_mask = true; } void @@ -60,6 +62,13 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co SPShape * shape_dest = SP_SHAPE(dest); gchar ** attarray = g_strsplit(attributes, ",", 0); gchar ** iter = attarray; +// if (SP_IS_CLIPPATH(SP_ITEM(origin)->parent) || SP_IS_MASK(SP_ITEM(origin)->parent)) { +// Geom::Affine dest_affine = Geom::identity(); +// if (root && preserve_position) { +// dest_affine *= Geom::Translate(preserve_affine.translation()); +// } +// SP_ITEM(SP_ITEM(dest)->parent)->transform = dest_affine; +// } while (*iter != NULL) { const char* attribute = (*iter); if ( std::strcmp(attribute, "transform") == 0 ) { @@ -69,11 +78,12 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (preserve_position) { Geom::Affine dest_affine = Geom::identity(); if (root) { + std::cout << "root" << preserve_affine.translation() << "\n"; dest_affine *= Geom::Translate(preserve_affine.translation()); - preserve_affine = Geom::identity(); + //preserve_affine = Geom::identity(); + dest_affine *= Geom::Translate(affine_dest.translation()); + dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); } - dest_affine *= Geom::Translate(affine_dest.translation()); - dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); dest_affine *= affine_origin; SP_ITEM(dest)->transform = dest_affine; } else { @@ -89,7 +99,7 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (c) { Geom::PathVector c_pv = c->get_pathvector(); Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); - if (orig_bbox) { + if (orig_bbox && root) { if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Scale scale = Geom::Scale(scale_affine); @@ -141,12 +151,6 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co void LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ original_bbox(lpeitem); - if ( preserve_position_changed != preserve_position ) { - if (!preserve_position) { - preserve_affine = SP_ITEM(sp_lpe_item)->transform; - } - preserve_position_changed = preserve_position; - } if (linked_path.linksToPath()) { //Legacy staff Glib::ustring attributes_value("d"); attributes.param_setValue(attributes_value); @@ -158,6 +162,16 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ linked_path.param_readSVGValue(""); } if (linked_item.linksToItem()) { + if (preserve_position) { + preserve_affine = SP_ITEM(sp_lpe_item)->transform; + } +// if ( preserve_position_changed != preserve_position ) { +// if (!preserve_position) { +// preserve_affine = SP_ITEM(sp_lpe_item)->transform; +// preserve_affine *= Geom::Translate(SP_ITEM(linked_item.getObject())->transform.translation()).inverse(); +// } +// preserve_position_changed = preserve_position; +// } cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } diff --git a/src/sp-lpe-item.cpp b/src/sp-lpe-item.cpp index c7a800041..2dd7cec5a 100644 --- a/src/sp-lpe-item.cpp +++ b/src/sp-lpe-item.cpp @@ -241,7 +241,7 @@ bool SPLPEItem::performPathEffect(SPCurve *curve, SPShape *current, bool is_clip } if (!is_clip_or_mask || (is_clip_or_mask && lpe->apply_to_clippath_and_mask)) { // Groups have their doBeforeEffect called elsewhere - if (SP_IS_GROUP(this) && current) { + if (current) { lpe->setCurrentShape(current); } if (!SP_IS_GROUP(this)) { @@ -700,7 +700,7 @@ SPLPEItem::apply_to_clip_or_mask(SPItem *clip_mask, SPItem *item) success = this->performPathEffect(c, SP_SHAPE(clip_mask), true); c->transform(i2anc_affine(SP_GROUP(item), SP_GROUP(this)).inverse()); } else { - success = this->performPathEffect(c, NULL, true); + success = this->performPathEffect(c, SP_SHAPE(clip_mask), true); } } catch (std::exception & e) { g_warning("Exception during LPE execution. \n %s", e.what()); -- cgit v1.2.3 From 088070b65c83f9a6a7d1d268e8a794776cc648a8 Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Sun, 1 Jan 2017 03:21:07 +0100 Subject: Fixing transforms,clips... (bzr r15356.1.8) --- src/live_effects/lpe-clone-original.cpp | 150 ++++++++++++++++++++++---------- src/live_effects/lpe-clone-original.h | 5 +- src/live_effects/lpe-copy_rotate.cpp | 1 - src/sp-path.cpp | 27 +++--- 4 files changed, 123 insertions(+), 60 deletions(-) (limited to 'src') diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 81e6809f1..76cc56b8f 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -24,6 +24,7 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : linked_item(_("Linked Item:"), _("Item from which to take the original data"), "linked_item", &wr, this), scale(_("Scale %"), _("Scale item %"), "scale", &wr, this, 100.0), preserve_position(_("Preserve position"), _("Preserve position"), "preserve_position", &wr, this, false), + use_center(_("Relative center of element"), _("Relative center of element"), "use_center", &wr, this, true), attributes("Attributes linked", "Attributes linked", "attributes", &wr, this,""), style_attributes("Style attributes linked", "Style attributes linked", "style_attributes", &wr, this,"") { @@ -33,14 +34,28 @@ LPECloneOriginal::LPECloneOriginal(LivePathEffectObject *lpeobject) : registerParameter(&attributes); registerParameter(&style_attributes); registerParameter(&preserve_position); + registerParameter(&use_center); scale.param_set_range(0.01, 999999.0); scale.param_set_increments(1, 1); scale.param_set_digits(2); attributes.param_hide_canvas_text(); style_attributes.param_hide_canvas_text(); - preserve_position_changed = !preserve_position; + preserve_position_changed = preserve_position; preserve_affine = Geom::identity(); - apply_to_clippath_and_mask = true; +} + +bool hasLinkedTransform( const char * attributes) { + gchar ** attarray = g_strsplit(attributes, ",", 0); + gchar ** iter = attarray; + bool has_linked_transform = false; + while (*iter != NULL) { + const char* attribute = (*iter); + if ( std::strcmp(attribute, "transform") == 0 ) { + has_linked_transform = true; + } + iter++; + } + return has_linked_transform; } void @@ -53,41 +68,69 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co for (std::vector::iterator obj_it = childs.begin(); obj_it != childs.end(); ++obj_it) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes(*obj_it, dest_child, live, attributes, style_attributes, false); + cloneAttrbutes((*obj_it), dest_child, live, attributes, style_attributes, false); index++; } } //Attributes SPShape * shape_origin = SP_SHAPE(origin); + SPPath * path_origin = SP_PATH(origin); SPShape * shape_dest = SP_SHAPE(dest); + SPMask *mask_origin = SP_ITEM(origin)->mask_ref->getObject(); + SPMask *mask_dest = SP_ITEM(dest)->mask_ref->getObject(); + if(mask_origin && mask_dest) { + std::vector mask_list = mask_origin->childList(true); + std::vector mask_list_dest = mask_dest->childList(true); + if (mask_list.size() == mask_list_dest.size()) { + size_t i = 0; + for ( std::vector::const_iterator iter=mask_list.begin();iter!=mask_list.end();++iter) { + SPObject * mask_data = *iter; + SPObject * mask_dest_data = mask_list_dest[i]; + cloneAttrbutes(mask_data, mask_dest_data, live, attributes, style_attributes, false); + i++; + } + } + } + SPClipPath *clippath_origin = SP_ITEM(origin)->clip_ref->getObject(); + SPClipPath *clippath_dest = SP_ITEM(dest)->clip_ref->getObject(); + if(clippath_origin && clippath_dest) { + std::vector clippath_list = clippath_origin->childList(true); + std::vector clippath_list_dest = clippath_dest->childList(true); + if (clippath_list.size() == clippath_list_dest.size()) { + size_t i = 0; + for ( std::vector::const_iterator iter=clippath_list.begin();iter!=clippath_list.end();++iter) { + SPObject * clippath_data = *iter; + SPObject * clippath_dest_data = clippath_list_dest[i]; + cloneAttrbutes(clippath_data, clippath_dest_data, live, attributes, style_attributes, false); + i++; + } + } + } gchar ** attarray = g_strsplit(attributes, ",", 0); gchar ** iter = attarray; -// if (SP_IS_CLIPPATH(SP_ITEM(origin)->parent) || SP_IS_MASK(SP_ITEM(origin)->parent)) { -// Geom::Affine dest_affine = Geom::identity(); -// if (root && preserve_position) { -// dest_affine *= Geom::Translate(preserve_affine.translation()); -// } -// SP_ITEM(SP_ITEM(dest)->parent)->transform = dest_affine; -// } + Geom::Affine affine_dest = Geom::identity(); + Geom::Affine affine_origin = Geom::identity(); + Geom::Affine affine_previous = Geom::identity(); + sp_svg_transform_read(SP_ITEM(dest)->getAttribute("transform"), &affine_dest); + sp_svg_transform_read(SP_ITEM(origin)->getAttribute("transform"), &affine_origin); while (*iter != NULL) { const char* attribute = (*iter); if ( std::strcmp(attribute, "transform") == 0 ) { - Geom::Affine affine_dest = SP_ITEM(dest)->transform; - Geom::Affine affine_origin = SP_ITEM(origin)->transform; - //dest->getRepr()->setAttribute(attribute, origin->getRepr()->attribute(attribute)); if (preserve_position) { Geom::Affine dest_affine = Geom::identity(); if (root) { - std::cout << "root" << preserve_affine.translation() << "\n"; - dest_affine *= Geom::Translate(preserve_affine.translation()); - //preserve_affine = Geom::identity(); - dest_affine *= Geom::Translate(affine_dest.translation()); + dest_affine *= affine_origin; + if (preserve_affine == Geom::identity()) { + dest_affine *= Geom::Translate(affine_dest.translation()); + } dest_affine *= Geom::Translate(affine_origin.translation()).inverse(); - } - dest_affine *= affine_origin; - SP_ITEM(dest)->transform = dest_affine; + dest_affine *= Geom::Translate(preserve_affine.translation()); + affine_previous = preserve_affine; + preserve_affine = Geom::identity(); + SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(dest_affine)); + } } else { - SP_ITEM(dest)->transform = affine_origin ; + SP_ITEM(dest)->getRepr()->setAttribute("transform",sp_svg_transform_write(affine_origin)); } } else if ( shape_dest && shape_origin && live && (std::strcmp(attribute, "d") == 0 || std::strcmp(attribute, "inkscape:original-d") == 0)) { SPCurve *c = NULL; @@ -99,21 +142,33 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co if (c) { Geom::PathVector c_pv = c->get_pathvector(); Geom::OptRect orig_bbox = SP_ITEM(origin)->geometricBounds(); - if (orig_bbox && root) { + Geom::OptRect dest_bbox = SP_ITEM(dest)->geometricBounds(); + if (dest_bbox && orig_bbox && root) { + Geom::Point orig_point = (*orig_bbox).corner(0); + Geom::Point dest_point = (*dest_bbox).corner(0); + if (use_center) { + orig_point = (*orig_bbox).midpoint(); + dest_point = (*dest_bbox).midpoint(); + } if (scale != 100.0) { double scale_affine = scale/100.0; Geom::Scale scale = Geom::Scale(scale_affine); - c_pv *= Geom::Translate((*orig_bbox).midpoint()).inverse(); + c_pv *= Geom::Translate(orig_point).inverse(); c_pv *= scale; - c_pv *= Geom::Translate((*orig_bbox).midpoint()); + c_pv *= Geom::Translate(orig_point); } - if (preserve_position) { - c_pv *= Geom::Translate(Geom::Point(boundingbox_X.middle(), boundingbox_Y.middle()) - (*orig_bbox).midpoint()); + if (preserve_position && hasLinkedTransform(attributes)) { + c_pv *= Geom::Translate(dest_point - orig_point); } } + c_pv *= i2anc_affine(dest, sp_lpe_item); c->set_pathvector(c_pv); - shape_dest->setCurveInsync(c, TRUE); - dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); + if (!path_origin) { + shape_dest->setCurveInsync(c, TRUE); + dest->getRepr()->setAttribute(attribute, sp_svg_write_path(c_pv)); + } else { + shape_dest->setCurve(c, TRUE); + } c->unref(); } else { dest->getRepr()->setAttribute(attribute, NULL); @@ -124,8 +179,6 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, co iter++; } g_strfreev (attarray); - - //Style Attributes SPCSSAttr *css_origin = sp_repr_css_attr_new(); sp_repr_css_attr_add_from_string(css_origin, origin->getRepr()->attribute("style")); SPCSSAttr *css_dest = sp_repr_css_attr_new(); @@ -161,17 +214,14 @@ LPECloneOriginal::doBeforeEffect (SPLPEItem const* lpeitem){ linked_item.param_readSVGValue(linked_path.param_getSVGValue()); linked_path.param_readSVGValue(""); } + if (linked_item.linksToItem()) { - if (preserve_position) { - preserve_affine = SP_ITEM(sp_lpe_item)->transform; + if ( preserve_position_changed != preserve_position ) { + if (!preserve_position) { + sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &preserve_affine); + } + preserve_position_changed = preserve_position; } -// if ( preserve_position_changed != preserve_position ) { -// if (!preserve_position) { -// preserve_affine = SP_ITEM(sp_lpe_item)->transform; -// preserve_affine *= Geom::Translate(SP_ITEM(linked_item.getObject())->transform.translation()).inverse(); -// } -// preserve_position_changed = preserve_position; -// } cloneAttrbutes(linked_item.getObject(), SP_OBJECT(sp_lpe_item), true, attributes.param_getSVGValue(), style_attributes.param_getSVGValue(), true); } } @@ -219,7 +269,7 @@ LPECloneOriginal::doOnApply(SPLPEItem const* lpeitem){ Glib::ustring attributes_value("d,transform"); attributes.param_setValue(attributes_value); attributes.write_to_SVG(); - Glib::ustring style_attributes_value("opacity,border-width"); + Glib::ustring style_attributes_value("opacity,stroke-width"); style_attributes.param_setValue(style_attributes_value); style_attributes.write_to_SVG(); } @@ -229,11 +279,23 @@ LPECloneOriginal::~LPECloneOriginal() } -void LPECloneOriginal::doEffect (SPCurve * curve) +void +LPECloneOriginal::transform_multiply(Geom::Affine const& postmul, bool set) +{ + if (linked_item.linksToItem()) { + bool changed = false; + linked_item.getObject()->requestModified(SP_OBJECT_MODIFIED_FLAG); + } +} + +void +LPECloneOriginal::doEffect (SPCurve * curve) { - SPShape * shape = getCurrentShape(); - if(shape){ - curve->set_pathvector(shape->getCurve()->get_pathvector()); + if (linked_item.linksToItem()) { + SPShape * shape = getCurrentShape(); + if(shape){ + curve->set_pathvector(shape->getCurve()->get_pathvector()); + } } } diff --git a/src/live_effects/lpe-clone-original.h b/src/live_effects/lpe-clone-original.h index e8a9a7419..064fe84b2 100644 --- a/src/live_effects/lpe-clone-original.h +++ b/src/live_effects/lpe-clone-original.h @@ -24,10 +24,10 @@ class LPECloneOriginal : public Effect, GroupBBoxEffect { public: LPECloneOriginal(LivePathEffectObject *lpeobject); virtual ~LPECloneOriginal(); - + virtual void doOnApply(SPLPEItem const* lpeitem); virtual void doEffect (SPCurve * curve); virtual void doBeforeEffect (SPLPEItem const* lpeitem); - virtual void doOnApply(SPLPEItem const* lpeitem); + virtual void transform_multiply(Geom::Affine const& postmul, bool set); virtual Gtk::Widget * newWidget(); void cloneAttrbutes(SPObject *origin, SPObject *dest, bool live, const char * attributes, const char * style_attributes, bool root); @@ -36,6 +36,7 @@ private: OriginalItemParam linked_item; ScalarParam scale; BoolParam preserve_position; + BoolParam use_center; TextParam attributes; TextParam style_attributes; bool preserve_position_changed; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 3dd35696a..aafd2c094 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -122,7 +122,6 @@ void LPECopyRotate::transform_multiply(Geom::Affine const& postmul, bool set) { // cycle through all parameters. Most parameters will not need transformation, but path and point params do. - for (std::vector::iterator it = param_vector.begin(); it != param_vector.end(); ++it) { Parameter * param = *it; param->param_transform_multiply(postmul, set); diff --git a/src/sp-path.cpp b/src/sp-path.cpp index 0a2ce4c09..6c69f3463 100644 --- a/src/sp-path.cpp +++ b/src/sp-path.cpp @@ -289,10 +289,23 @@ Geom::Affine SPPath::set_transform(Geom::Affine const &transform) { if (!_curve) { // 0 nodes, nothing to transform return Geom::identity(); } + // Adjust stroke + this->adjust_stroke(transform.descrim()); + + // Adjust pattern fill + this->adjust_pattern(transform); + + // Adjust gradient fill + this->adjust_gradient(transform); + + // Adjust LPE + this->adjust_livepatheffect(transform); // Transform the original-d path if this is a valid LPE this, other else the (ordinary) path if (_curve_before_lpe && hasPathEffectRecursive()) { - if (this->hasPathEffectOfType(Inkscape::LivePathEffect::CLONE_ORIGINAL) || this->hasPathEffectOfType(Inkscape::LivePathEffect::BEND_PATH)) { + if (this->hasPathEffectOfType(Inkscape::LivePathEffect::CLONE_ORIGINAL) || + this->hasPathEffectOfType(Inkscape::LivePathEffect::BEND_PATH)) + { // if path has the CLONE_ORIGINAL LPE applied, don't write the transform to the pathdata, but write it 'unoptimized' // also if the effect is type BEND PATH to fix bug #179842 return transform; @@ -303,18 +316,6 @@ Geom::Affine SPPath::set_transform(Geom::Affine const &transform) { _curve->transform(transform); } - // Adjust stroke - this->adjust_stroke(transform.descrim()); - - // Adjust pattern fill - this->adjust_pattern(transform); - - // Adjust gradient fill - this->adjust_gradient(transform); - - // Adjust LPE - this->adjust_livepatheffect(transform); - this->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG); // nothing remains - we've written all of the transform, so return identity -- cgit v1.2.3