lpe-parallel.cpp revision 0b2d8abc1011ad865fce3b883ccb2587cb15cc90
493N/A/** \file
0N/A * LPE <parallel> implementation
970N/A */
0N/A/*
0N/A * Authors:
919N/A * Maximilian Albert
919N/A *
919N/A * Copyright (C) Johan Engelen 2007-2012 <j.b.c.engelen@alumnus.utwente.nl>
919N/A * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
919N/A *
0N/A * Released under GNU GPL, read the file 'COPYING' for more information
919N/A */
919N/A
919N/A#include <glibmm/i18n.h>
0N/A
919N/A#include "live_effects/lpe-parallel.h"
919N/A#include "sp-shape.h"
919N/A#include "display/curve.h"
919N/A
919N/A#include <2geom/path.h>
919N/A#include <2geom/transforms.h>
919N/A
0N/A#include "knot-holder-entity.h"
0N/A#include "knotholder.h"
0N/A
0N/Anamespace Inkscape {
0N/Anamespace LivePathEffect {
0N/A
970N/Anamespace Pl {
970N/A
970N/Aclass KnotHolderEntityLeftEnd : public LPEKnotHolderEntity {
0N/Apublic:
0N/A KnotHolderEntityLeftEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
0N/A virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
0N/A virtual Geom::Point knot_get() const;
970N/A};
493N/A
970N/Aclass KnotHolderEntityRightEnd : public LPEKnotHolderEntity {
0N/Apublic:
1003N/A KnotHolderEntityRightEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
1003N/A virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
1003N/A virtual Geom::Point knot_get() const;
1003N/A};
1003N/A
1003N/A} // namespace Pl
1003N/A
970N/ALPEParallel::LPEParallel(LivePathEffectObject *lpeobject) :
970N/A Effect(lpeobject),
0N/A // initialise your parameters here:
970N/A offset_pt(_("Offset"), _("Adjust the offset"), "offset_pt", &wr, this),
970N/A length_left(_("Length left:"), _("Specifies the left end of the parallel"), "length-left", &wr, this, 150),
731N/A length_right(_("Length right:"), _("Specifies the right end of the parallel"), "length-right", &wr, this, 150)
970N/A{
970N/A show_orig_path = true;
970N/A _provides_knotholder_entities = true;
970N/A
561N/A registerParameter(dynamic_cast<Parameter *>(&offset_pt));
493N/A registerParameter( dynamic_cast<Parameter *>(&length_left) );
970N/A registerParameter( dynamic_cast<Parameter *>(&length_right) );
970N/A}
970N/A
970N/ALPEParallel::~LPEParallel()
970N/A{
0N/A
0N/A}
0N/A
970N/Avoid
970N/ALPEParallel::doOnApply (SPLPEItem const* lpeitem)
970N/A{
0N/A SPCurve const *curve = SP_SHAPE(lpeitem)->_curve;
970N/A
970N/A A = *(curve->first_point());
970N/A B = *(curve->last_point());
970N/A dir = unit_vector(B - A);
0N/A
970N/A offset_pt.param_set_and_write_new_value((A + B)/2 + dir.ccw() * 100);
970N/A}
493N/A
970N/AGeom::Piecewise<Geom::D2<Geom::SBasis> >
29N/ALPEParallel::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
0N/A{
970N/A using namespace Geom;
970N/A
970N/A Piecewise<D2<SBasis> > output;
970N/A
970N/A A = pwd2_in.firstValue();
970N/A B = pwd2_in.lastValue();
970N/A dir = unit_vector(B - A);
970N/A
970N/A C = offset_pt - dir * length_left;
970N/A D = offset_pt + dir * length_right;
970N/A
970N/A output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
970N/A
970N/A return output + dir;
970N/A}
970N/A
970N/Avoid LPEParallel::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
970N/A {
970N/A KnotHolderEntity *e = new Pl::KnotHolderEntityLeftEnd(this);
493N/A e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
_("Adjust the \"left\" end of the parallel") );
knotholder->add(e);
}
{
KnotHolderEntity *e = new Pl::KnotHolderEntityRightEnd(this);
e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
_("Adjust the \"right\" end of the parallel") );
knotholder->add(e);
}
};
namespace Pl {
void
KnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
{
using namespace Geom;
LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
Geom::Point const s = snap_knot_position(p, state);
double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
lpe->length_left.param_set_value(-lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
}
void
KnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
{
using namespace Geom;
LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
Geom::Point const s = snap_knot_position(p, state);
double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
lpe->length_right.param_set_value(lambda);
sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
}
Geom::Point
KnotHolderEntityLeftEnd::knot_get() const
{
LPEParallel const *lpe = dynamic_cast<LPEParallel const*>(_effect);
return lpe->C;
}
Geom::Point
KnotHolderEntityRightEnd::knot_get() const
{
LPEParallel const *lpe = dynamic_cast<LPEParallel const*>(_effect);
return lpe->D;
}
} // namespace Pl
/* ######################## */
} //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 :