summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-fill-between-many.cpp
diff options
context:
space:
mode:
authorJabier Arraiza <jabier.arraiza@marker.es>2017-11-03 00:10:02 +0000
committerJabier Arraiza <jabier.arraiza@marker.es>2017-11-03 00:10:02 +0000
commitd2df0412f728dd5bb54537dfdfe7c35b34d40e0e (patch)
treee2703384779e83312c456399999997fcc289c5cf /src/live_effects/lpe-fill-between-many.cpp
parentMerge branch 'master' into powerpencil (diff)
parentchange assignment to equality (diff)
downloadinkscape-d2df0412f728dd5bb54537dfdfe7c35b34d40e0e.tar.gz
inkscape-d2df0412f728dd5bb54537dfdfe7c35b34d40e0e.zip
Merge branch 'master' into powerpencil
Diffstat (limited to 'src/live_effects/lpe-fill-between-many.cpp')
-rw-r--r--src/live_effects/lpe-fill-between-many.cpp116
1 files changed, 98 insertions, 18 deletions
diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp
index 40fa91c68..7e2131f76 100644
--- a/src/live_effects/lpe-fill-between-many.cpp
+++ b/src/live_effects/lpe-fill-between-many.cpp
@@ -6,10 +6,14 @@
#include "live_effects/lpe-fill-between-many.h"
-
+#include "live_effects/lpeobject.h"
+#include "xml/node.h"
#include "display/curve.h"
+#include "inkscape.h"
+#include "selection.h"
#include "sp-shape.h"
#include "sp-text.h"
+#include "sp-defs.h"
#include "svg/svg.h"
// TODO due to internal breakage in glibmm headers, this must be last:
#include <glibmm/i18n.h>
@@ -17,20 +21,31 @@
namespace Inkscape {
namespace LivePathEffect {
+static const Util::EnumData<Filllpemethod> FilllpemethodData[] = {
+ { FLM_ORIGINALD, N_("Without LPE's"), "originald" },
+ { FLM_BSPLINESPIRO, N_("With Spiro or BSpline"), "bsplinespiro" },
+ { FLM_D, N_("With LPE's"), "d" }
+};
+static const Util::EnumDataConverter<Filllpemethod> FLMConverter(FilllpemethodData, FLM_END);
+
LPEFillBetweenMany::LPEFillBetweenMany(LivePathEffectObject *lpeobject) :
Effect(lpeobject),
linked_paths(_("Linked path:"), _("Paths from which to take the original path data"), "linkedpaths", &wr, this),
+ method(_("LPE's on linked:"), _("LPE's on linked"), "method", FLMConverter, &wr, this, FLM_BSPLINESPIRO),
fuse(_("Fuse coincident points"), _("Fuse coincident points"), "fuse", &wr, this, false),
allow_transforms(_("Allow transforms"), _("Allow transforms"), "allow_transforms", &wr, this, false),
join(_("Join subpaths"), _("Join subpaths"), "join", &wr, this, true),
- close(_("Close"), _("Close path"), "close", &wr, this, true)
+ close(_("Close"), _("Close path"), "close", &wr, this, true),
+ applied("Store the first apply", "", "applied", &wr, this, "false", false)
{
registerParameter(&linked_paths);
+ registerParameter(&method);
registerParameter(&fuse);
registerParameter(&allow_transforms);
registerParameter(&join);
registerParameter(&close);
- transformmultiply = false;
+ registerParameter(&applied);
+ previous_method = FLM_END;
}
LPEFillBetweenMany::~LPEFillBetweenMany()
@@ -38,13 +53,73 @@ LPEFillBetweenMany::~LPEFillBetweenMany()
}
+void LPEFillBetweenMany::doOnApply (SPLPEItem const* lpeitem)
+{
+ SPDocument * document = SP_ACTIVE_DOCUMENT;
+ if (!document) {
+ return;
+ }
+ SPLPEItem *lpe_item = const_cast<SPLPEItem *>(lpeitem);
+ SPObject * parent = lpe_item->parent;
+ if (lpe_item) {
+ SPShape *shape = dynamic_cast<SPShape *>(lpe_item);
+ if (shape) {
+ Inkscape::SVGOStringStream os;
+ if (strcmp(this->lpeobj->getRepr()->attribute("applied"), "false") == 0) {
+ os << '#' << SP_ITEM(lpe_item)->getId() << ",0,1";
+
+ Inkscape::XML::Document *xml_doc = document->getReprDoc();
+ // create the LPE
+ Inkscape::XML::Node *lpe_repr = xml_doc->createElement("inkscape:path-effect");
+ {
+ lpe_repr->setAttribute("effect", "fill_between_many");
+ lpe_repr->setAttribute("linkedpaths", os.str());
+ lpe_repr->setAttribute("applied", "true");
+ lpe_repr->setAttribute("method", "partial");
+ lpe_repr->setAttribute("allow_transforms", "false");
+ document->getDefs()->getRepr()->addChild(lpe_repr, NULL); // adds to <defs> and assigns the 'id' attribute
+ }
+ std::string lpe_id_href = std::string("#") + lpe_repr->attribute("id");
+ Inkscape::GC::release(lpe_repr);
+ Inkscape::XML::Node *clone = xml_doc->createElement("svg:path");
+ {
+ clone->setAttribute("d", "M 0 0", false);
+ // add the new clone to the top of the original's parent
+ parent->appendChildRepr(clone);
+ SPObject *clone_obj = document->getObjectById(clone->attribute("id"));
+ SPLPEItem *clone_lpeitem = dynamic_cast<SPLPEItem *>(clone_obj);
+ if (clone_lpeitem) {
+ clone_lpeitem->addPathEffect(lpe_id_href, false);
+ }
+ }
+ Inkscape::Selection * sel = SP_ACTIVE_DESKTOP->getSelection();
+ sel->set(clone);
+ Inkscape::GC::release(clone);
+ lpe_item->removeCurrentPathEffect(false);
+ }
+ }
+ }
+}
+
void LPEFillBetweenMany::doEffect (SPCurve * curve)
{
+ if (previous_method != method) {
+ if (method == FLM_BSPLINESPIRO) {
+ linked_paths.allowOnlyBsplineSpiro(true);
+ linked_paths.setFromOriginalD(false);
+ } else if(method == FLM_ORIGINALD) {
+ linked_paths.allowOnlyBsplineSpiro(false);
+ linked_paths.setFromOriginalD(true);
+ } else {
+ linked_paths.allowOnlyBsplineSpiro(false);
+ linked_paths.setFromOriginalD(false);
+ }
+ previous_method = method;
+ }
Geom::PathVector res_pathv;
- SPItem * firstObj = NULL;
- for (std::vector<PathAndDirection*>::iterator iter = linked_paths._vector.begin(); iter != linked_paths._vector.end(); ++iter) {
+ for (std::vector<PathAndDirectionAndVisible*>::iterator iter = linked_paths._vector.begin(); iter != linked_paths._vector.end(); ++iter) {
SPObject *obj;
- if ((*iter)->ref.isAttached() && (obj = (*iter)->ref.getObject()) && SP_IS_ITEM(obj) && !(*iter)->_pathvector.empty()) {
+ if ((*iter)->ref.isAttached() && (obj = (*iter)->ref.getObject()) && SP_IS_ITEM(obj) && !(*iter)->_pathvector.empty() && (*iter)->visibled) {
Geom::Path linked_path;
if ((*iter)->reversed) {
linked_path = (*iter)->_pathvector.front().reversed();
@@ -53,36 +128,43 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve)
}
if (!res_pathv.empty() && join) {
- linked_path = linked_path * SP_ITEM(obj)->getRelativeTransform(firstObj);
if (!are_near(res_pathv.front().finalPoint(), linked_path.initialPoint(), 0.01) || !fuse) {
res_pathv.front().appendNew<Geom::LineSegment>(linked_path.initialPoint());
} else {
linked_path.setInitial(res_pathv.front().finalPoint());
}
+ if(!allow_transforms) {
+ Geom::Affine affine = Geom::identity();
+ sp_svg_transform_read(SP_ITEM(obj)->getAttribute("transform"), &affine);
+ linked_path *= affine;
+ }
res_pathv.front().append(linked_path);
} else {
- firstObj = SP_ITEM(obj);
if (close && !join) {
linked_path.close();
}
+ if(!allow_transforms) {
+ Geom::Affine affine = Geom::identity();
+ sp_svg_transform_read(SP_ITEM(obj)->getAttribute("transform"), &affine);
+ linked_path *= affine;
+ }
res_pathv.push_back(linked_path);
}
}
}
+
+ if(!allow_transforms && sp_lpe_item) {
+ SP_ITEM(sp_lpe_item)->transform = Geom::identity();
+ }
+
if (!res_pathv.empty() && close) {
res_pathv.front().close();
}
+
if (res_pathv.empty()) {
res_pathv = curve->get_pathvector();
}
- if(!allow_transforms && !transformmultiply) {
- Geom::Affine affine = Geom::identity();
- sp_svg_transform_read(SP_ITEM(sp_lpe_item)->getAttribute("transform"), &affine);
- res_pathv *= affine.inverse();
- }
- if(transformmultiply) {
- transformmultiply = false;
- }
+
curve->set_pathvector(res_pathv);
}
@@ -91,8 +173,6 @@ LPEFillBetweenMany::transform_multiply(Geom::Affine const& postmul, bool set)
{
if(!allow_transforms && sp_lpe_item) {
SP_ITEM(sp_lpe_item)->transform *= postmul.inverse();
- transformmultiply = true;
- sp_lpe_item_update_patheffect(sp_lpe_item, false, false);
}
}