From: cilix42 Date: Mon, 19 May 2008 16:04:34 +0000 (+0000) Subject: Forgot to add two files in commit #18667. Sorry for breaking the build for a minute! X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bce2f84f17e5ee51d8222dc076ad013a68e58a7a;p=inkscape.git Forgot to add two files in commit #18667. Sorry for breaking the build for a minute! --- diff --git a/src/live_effects/lpe-tangent_to_curve.cpp b/src/live_effects/lpe-tangent_to_curve.cpp new file mode 100644 index 000000000..e7344c9dc --- /dev/null +++ b/src/live_effects/lpe-tangent_to_curve.cpp @@ -0,0 +1,101 @@ +#define INKSCAPE_LPE_TANGENT_TO_CURVE_CPP +/** \file + * Implementation of tangent-to-curve LPE. + */ + +/* + * Authors: + * Johan Engelen + * Maximilian Albert + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-tangent_to_curve.h" +// FIXME: The following are only needed to convert the path's SPCurve* to pwd2. +// There must be a more convenient way to achieve this. +#include "sp-path.h" +#include "display/curve.h" +#include "libnr/n-art-bpath-2geom.h" + +#include <2geom/path.h> + +namespace Inkscape { +namespace LivePathEffect { + +/* FIXME: We should arguably make these member functions of LPETangentToCurve. + Is there an easy way to register member functions with knotholder? + */ +NR::Point attach_pt_get(SPItem *item) { + Inkscape::LivePathEffect::LPETangentToCurve *lpe = + (Inkscape::LivePathEffect::LPETangentToCurve *) sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item)); + + return lpe->ptA; +} + +void attach_pt_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state) { + Inkscape::LivePathEffect::LPETangentToCurve *lpe = + (Inkscape::LivePathEffect::LPETangentToCurve *) sp_lpe_item_get_livepatheffect(SP_LPE_ITEM(item)); + + using namespace Geom; + + // FIXME: There must be a better way of converting the path's SPCurve* to pwd2. + SPCurve *curve = sp_path_get_curve_for_edit (SP_PATH(item)); + const NArtBpath *bpath = curve->get_bpath(); + Piecewise > pwd2; + std::vector pathv = BPath_to_2GeomPath(bpath); + for (unsigned int i=0; i < pathv.size(); i++) { + pwd2.concat(pathv[i].toPwSb()); + } + + double t0 = nearest_point(p.to_2geom(), pwd2); + lpe->t_attach.param_set_value(t0); + + sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), true); +} + +LPETangentToCurve::LPETangentToCurve(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + t_attach(_("Location along curve"), _("Location of the point of attachment along the curve (between 0.0 and number-of-segments)"), "t_attach", &wr, this, 0.5) +{ + registerParameter( dynamic_cast(&t_attach) ); + registerKnotHolderHandle(attach_pt_set, attach_pt_get); +} + +LPETangentToCurve::~LPETangentToCurve() +{ +} + +Geom::Piecewise > +LPETangentToCurve::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) +{ + using namespace Geom; + Piecewise > output; + + ptA = pwd2_in.valueAt(t_attach); + derivA = unit_vector(derivative(pwd2_in).valueAt(t_attach)); + + Point A = ptA - derivA * 100; + Point B = ptA + derivA * 100; + + output = Piecewise >(D2(Linear(A[X], B[X]), Linear(A[Y], B[Y]))); + + return output; +} + +} //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 : diff --git a/src/live_effects/lpe-tangent_to_curve.h b/src/live_effects/lpe-tangent_to_curve.h new file mode 100644 index 000000000..d8049c176 --- /dev/null +++ b/src/live_effects/lpe-tangent_to_curve.h @@ -0,0 +1,51 @@ +#ifndef INKSCAPE_LPE_TANGENT_TO_CURVE_H +#define INKSCAPE_LPE_TANGENT_TO_CURVE_H + +/** \file + * LPE implementation, see lpe-tangent_to_curve.cpp. + */ + +/* + * Authors: + * Johan Engelen + * Maximilian Albert + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/point.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPETangentToCurve : public Effect { +public: + LPETangentToCurve(LivePathEffectObject *lpeobject); + virtual ~LPETangentToCurve(); + + virtual Geom::Piecewise > + doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + + /* the knotholder functions must be declared friends */ + friend NR::Point attach_pt_get(SPItem *item); + friend void attach_pt_set(SPItem *item, NR::Point const &p, NR::Point const &origin, guint state); + +private: + ScalarParam t_attach; + + Geom::Point ptA; + Geom::Point derivA; + + LPETangentToCurve(const LPETangentToCurve&); + LPETangentToCurve& operator=(const LPETangentToCurve&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif