summaryrefslogtreecommitdiffstats
path: root/src/live_effects/lpe-attach-path.cpp
diff options
context:
space:
mode:
authorLiam P. White <inkscapebronyat-signgmaildotcom>2014-03-02 15:29:06 +0000
committerLiam P. White <inkscapebronyat-signgmaildotcom>2014-03-02 15:29:06 +0000
commit1d854ff519b9c0867bfa4ecaf2f6329ca256f06a (patch)
tree437352a17301fbdd1787213b7dec3788b6e8eefa /src/live_effects/lpe-attach-path.cpp
parentrename variable names to prevent hiding of names in outer scopes (diff)
downloadinkscape-1d854ff519b9c0867bfa4ecaf2f6329ca256f06a.tar.gz
inkscape-1d854ff519b9c0867bfa4ecaf2f6329ca256f06a.zip
Experimental merge of Ponyscape features into trunk (will not compile)
(bzr r13090.1.1)
Diffstat (limited to 'src/live_effects/lpe-attach-path.cpp')
-rw-r--r--src/live_effects/lpe-attach-path.cpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/src/live_effects/lpe-attach-path.cpp b/src/live_effects/lpe-attach-path.cpp
new file mode 100644
index 000000000..b3d5ed9b7
--- /dev/null
+++ b/src/live_effects/lpe-attach-path.cpp
@@ -0,0 +1,203 @@
+/*
+ * Copyright (C) Johan Engelen 2012 <j.b.c.engelen@alumnus.utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include <glibmm/i18n.h>
+#include <math.h>
+
+#include "live_effects/lpe-attach-path.h"
+
+#include "display/curve.h"
+#include "sp-item.h"
+#include "2geom/path.h"
+#include "sp-shape.h"
+#include "sp-text.h"
+#include "2geom/bezier-curve.h"
+#include "2geom/path-sink.h"
+#include "parameter/parameter.h"
+#include "live_effects/parameter/point.h"
+#include "parameter/originalpath.h"
+#include "2geom/affine.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPEAttachPath::LPEAttachPath(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ start_path(_("Start path:"), _("Path to attach to the start of this path"), "startpath", &wr, this),
+ start_path_position(_("Start path position:"), _("Position to attach path start to"), "startposition", &wr, this, 0.0),
+ start_path_curve_start(_("Start path curve start:"), _("Starting curve"), "startcurvestart", &wr, this, Geom::Point(20,0)/*, true*/),
+ start_path_curve_end(_("Start path curve end:"), _("Ending curve"), "startcurveend", &wr, this, Geom::Point(20,0)/*, true*/),
+ end_path(_("End path:"), _("Path to attach to the end of this path"), "endpath", &wr, this),
+ end_path_position(_("End path position:"), _("Position to attach path end to"), "endposition", &wr, this, 0.0),
+ end_path_curve_start(_("End path curve start:"), _("Starting curve"), "endcurvestart", &wr, this, Geom::Point(20,0)/*, true*/),
+ end_path_curve_end(_("End path curve end:"), _("Ending curve"), "endcurveend", &wr, this, Geom::Point(20,0)/*, true*/)
+{
+ registerParameter( dynamic_cast<Parameter *>(&start_path) );
+ registerParameter( dynamic_cast<Parameter *>(&start_path_position) );
+ registerParameter( dynamic_cast<Parameter *>(&start_path_curve_start) );
+ registerParameter( dynamic_cast<Parameter *>(&start_path_curve_end) );
+
+ registerParameter( dynamic_cast<Parameter *>(&end_path) );
+ registerParameter( dynamic_cast<Parameter *>(&end_path_position) );
+ registerParameter( dynamic_cast<Parameter *>(&end_path_curve_start) );
+ registerParameter( dynamic_cast<Parameter *>(&end_path_curve_end) );
+
+ //perceived_path = true;
+ show_orig_path = true;
+ curve_start_previous_origin = start_path_curve_end.getOrigin();
+ curve_end_previous_origin = end_path_curve_end.getOrigin();
+}
+
+LPEAttachPath::~LPEAttachPath()
+{
+
+}
+
+void LPEAttachPath::resetDefaults(SPItem const * item)
+{
+ curve_start_previous_origin = start_path_curve_end.getOrigin();
+ curve_end_previous_origin = end_path_curve_end.getOrigin();
+}
+
+void LPEAttachPath::doBeforeEffect(const SPLPEItem *lpeitem)
+{
+ lpe_effect = lpeitem;
+}
+
+void LPEAttachPath::doEffect (SPCurve * curve)
+{
+ std::vector<Geom::Path> this_pathv = curve->get_pathvector();
+ if (lpe_effect && !this_pathv.empty()) {
+ Geom::Path p = Geom::Path(this_pathv.front().initialPoint());
+
+ bool set_start_end = start_path_curve_end.getOrigin() != curve_start_previous_origin;
+ bool set_end_end = end_path_curve_end.getOrigin() != curve_end_previous_origin;
+
+ if (start_path.linksToPath()) {
+
+ std::vector<Geom::Path> linked_pathv = start_path.get_pathvector();
+ Geom::Affine linkedtransform = start_path.getObject()->getRelativeTransform(lpe_effect);
+
+ if ( !linked_pathv.empty() )
+ {
+ Geom::Path transformedpath = linked_pathv.front() * linkedtransform;
+ start_path_curve_start.setOrigin(this_pathv.front().initialPoint());
+
+ std::vector<Geom::Point> derivs = this_pathv.front().front().pointAndDerivatives(0, 3);
+
+ for (unsigned deriv_n = 1; deriv_n < derivs.size(); deriv_n++) {
+ Geom::Coord length = derivs[deriv_n].length();
+ if ( ! Geom::are_near(length, 0) ) {
+ if (set_start_end) {
+ start_path_position.param_set_value(transformedpath.nearestPoint(start_path_curve_end.getOrigin()));
+ }
+
+ if (start_path_position > transformedpath.size()) {
+ start_path_position.param_set_value(transformedpath.size());
+ } else if (start_path_position < 0) {
+ start_path_position.param_set_value(0);
+ }
+ const Geom::Curve *c = start_path_position >= transformedpath.size() ? &transformedpath.back() : &transformedpath.at_index((int)start_path_position);
+
+ std::vector<Geom::Point> derivs_2 = c->pointAndDerivatives(start_path_position >= transformedpath.size() ? 1 : (start_path_position - (int)start_path_position), 3);
+ for (unsigned deriv_n_2 = 1; deriv_n_2 < derivs_2.size(); deriv_n_2++) {
+ Geom::Coord length_2 = derivs[deriv_n_2].length();
+ if ( ! Geom::are_near(length_2, 0) ) {
+ start_path_curve_end.setOrigin(derivs_2[0]);
+ curve_start_previous_origin = start_path_curve_end.getOrigin();
+
+ double startangle = atan2(start_path_curve_start.getVector().y(), start_path_curve_start.getVector().x());
+ double endangle = atan2(start_path_curve_end.getVector().y(), start_path_curve_end.getVector().x());
+ double startderiv = atan2(derivs[deriv_n].y(), derivs[deriv_n].x());
+ double endderiv = atan2(derivs_2[deriv_n_2].y(), derivs_2[deriv_n_2].x());
+ Geom::Point pt1 = Geom::Point(start_path_curve_start.getVector().length() * cos(startangle + startderiv), start_path_curve_start.getVector().length() * sin(startangle + startderiv));
+ Geom::Point pt2 = Geom::Point(start_path_curve_end.getVector().length() * cos(endangle + endderiv), start_path_curve_end.getVector().length() * sin(endangle + endderiv));
+ p = Geom::Path(derivs_2[0]);
+ p.appendNew<Geom::CubicBezier>(-pt2 + derivs_2[0], -pt1 + this_pathv.front().initialPoint(), this_pathv.front().initialPoint());
+ break;
+
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ p.append(this_pathv.front());
+
+ if (end_path.linksToPath()) {
+
+ std::vector<Geom::Path> linked_pathv = end_path.get_pathvector();
+ Geom::Affine linkedtransform = end_path.getObject()->getRelativeTransform(lpe_effect);
+
+ if ( !linked_pathv.empty() )
+ {
+ Geom::Path transformedpath = linked_pathv.front() * linkedtransform;
+ Geom::Curve * last_seg_reverse = this_pathv.front().back().reverse();
+
+ end_path_curve_start.setOrigin(last_seg_reverse->initialPoint());
+
+ std::vector<Geom::Point> derivs = last_seg_reverse->pointAndDerivatives(0, 3);
+ for (unsigned deriv_n = 1; deriv_n < derivs.size(); deriv_n++) {
+ Geom::Coord length = derivs[deriv_n].length();
+ if ( ! Geom::are_near(length, 0) ) {
+ if (set_end_end) {
+ end_path_position.param_set_value(transformedpath.nearestPoint(end_path_curve_end.getOrigin()));
+ }
+
+ if (end_path_position > transformedpath.size()) {
+ end_path_position.param_set_value(transformedpath.size());
+ } else if (end_path_position < 0) {
+ end_path_position.param_set_value(0);
+ }
+ const Geom::Curve *c = end_path_position >= transformedpath.size() ? &transformedpath.back() : &transformedpath.at_index((int)end_path_position);
+
+ std::vector<Geom::Point> derivs_2 = c->pointAndDerivatives(end_path_position >= transformedpath.size() ? 1 : (end_path_position - (int)end_path_position), 3);
+ for (unsigned deriv_n_2 = 1; deriv_n_2 < derivs_2.size(); deriv_n_2++) {
+ Geom::Coord length_2 = derivs[deriv_n_2].length();
+ if ( ! Geom::are_near(length_2, 0) ) {
+
+ end_path_curve_end.setOrigin(derivs_2[0]);
+ curve_end_previous_origin = end_path_curve_end.getOrigin();
+
+ double startangle = atan2(end_path_curve_start.getVector().y(), end_path_curve_start.getVector().x());
+ double endangle = atan2(end_path_curve_end.getVector().y(), end_path_curve_end.getVector().x());
+ double startderiv = atan2(derivs[deriv_n].y(), derivs[deriv_n].x());
+ double endderiv = atan2(derivs_2[deriv_n_2].y(), derivs_2[deriv_n_2].x());
+ Geom::Point pt1 = Geom::Point(end_path_curve_start.getVector().length() * cos(startangle + startderiv), end_path_curve_start.getVector().length() * sin(startangle + startderiv));
+ Geom::Point pt2 = Geom::Point(end_path_curve_end.getVector().length() * cos(endangle + endderiv), end_path_curve_end.getVector().length() * sin(endangle + endderiv));
+ p.appendNew<Geom::CubicBezier>(-pt1 + this_pathv.front().finalPoint(), -pt2 + derivs_2[0], derivs_2[0]);
+
+ break;
+
+ }
+ }
+ break;
+ }
+ }
+ delete last_seg_reverse;
+ }
+ }
+ Geom::PathVector outvector;
+ outvector.push_back(p);
+ curve->set_pathvector(outvector);
+ }
+}
+
+} // namespace LivePathEffect
+} /* namespace Inkscape */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :