lpe-perp_bisector.cpp revision 0b2d8abc1011ad865fce3b883ccb2587cb15cc90
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * LPE <perp_bisector> implementation.
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Maximilian Albert
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Johan Engelen
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com>
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Released under GNU GPL, read the file 'COPYING' for more information
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilixnamespace PB {
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilixclass KnotHolderEntityEnd : public LPEKnotHolderEntity {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntityEnd(LPEPerpBisector *effect) : LPEKnotHolderEntity(effect) {};
624e4bb114c588505c592e405dbad6570e5704feDiederik van Lierop void bisector_end_set(Geom::Point const &p, guint state, bool left = true);
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilixclass KnotHolderEntityLeftEnd : public KnotHolderEntityEnd {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntityLeftEnd(LPEPerpBisector *effect) : KnotHolderEntityEnd(effect) {};
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilixclass KnotHolderEntityRightEnd : public KnotHolderEntityEnd {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntityRightEnd(LPEPerpBisector *effect) : KnotHolderEntityEnd(effect) {};
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. EngelenKnotHolderEntityLeftEnd::knot_get() const {
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen LPEPerpBisector const* lpe = dynamic_cast<LPEPerpBisector const*>(_effect);
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. EngelenKnotHolderEntityRightEnd::knot_get() const {
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen LPEPerpBisector const* lpe = dynamic_cast<LPEPerpBisector const*>(_effect);
624e4bb114c588505c592e405dbad6570e5704feDiederik van LieropKnotHolderEntityEnd::bisector_end_set(Geom::Point const &p, guint state, bool left) {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen LPEPerpBisector *lpe = dynamic_cast<LPEPerpBisector *>(_effect);
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilix if (!lpe) return;
624e4bb114c588505c592e405dbad6570e5704feDiederik van Lierop Geom::Point const s = snap_knot_position(p, state);
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen double lambda = Geom::nearest_point(s, lpe->M, lpe->perp_dir);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), true, true);
624e4bb114c588505c592e405dbad6570e5704feDiederik van LieropKnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
624e4bb114c588505c592e405dbad6570e5704feDiederik van LieropKnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilix} //namescape PB
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixLPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) :
b8502defa91647a317b285046a49546612f66e6dKris length_left(_("Length left:"), _("Specifies the left end of the bisector"), "length-left", &wr, this, 200),
b8502defa91647a317b285046a49546612f66e6dKris length_right(_("Length right:"), _("Specifies the right end of the bisector"), "length-right", &wr, this, 200),
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix A(0,0), B(0,0), M(0,0), C(0,0), D(0,0), perp_dir(0,0)
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix // register all your parameters here, so Inkscape knows which parameters this effect has:
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix registerParameter( dynamic_cast<Parameter *>(&length_left) );
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix registerParameter( dynamic_cast<Parameter *>(&length_right) );
a39c187369a59e887255e3f704a3ababf2b10678Johan B. C. EngelenLPEPerpBisector::doOnApply (SPLPEItem const*/*lpeitem*/)
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix /* make the path a straight line */
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix SPCurve* curve = sp_path_get_curve_for_edit (SP_PATH(lpeitem)); // TODO: Should we use sp_shape_get_curve()?
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen Geom::Point A(curve->first_point());
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen Geom::Point B(curve->last_point());
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix SPCurve *c = new SPCurve();
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix c->moveto(A);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix c->lineto(B);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix // TODO: Why doesn't sp_path_set_original_curve(SP_PATH(lpeitem), c, TRUE, true) work?
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix SP_PATH(lpeitem)->original_curve = c->ref();
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix c->unref();
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixLPEPerpBisector::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix using namespace Geom;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix M = (A + B)/2;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. EngelenLPEPerpBisector::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntity *e = new PB::KnotHolderEntityLeftEnd(this);
7655c8b8ffe3674dd7e7c74f450fb7194943c0deJon A. Cruz e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
7655c8b8ffe3674dd7e7c74f450fb7194943c0deJon A. Cruz _("Adjust the bisector's \"left\" end") );
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntity *e = new PB::KnotHolderEntityRightEnd(this);
7655c8b8ffe3674dd7e7c74f450fb7194943c0deJon A. Cruz e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
7655c8b8ffe3674dd7e7c74f450fb7194943c0deJon A. Cruz _("Adjust the bisector's \"right\" end") );
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix/* ######################## */
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix} //namespace LivePathEffect
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix} /* namespace Inkscape */
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix Local Variables:
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix c-file-style:"stroustrup"
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix indent-tabs-mode:nil
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix fill-column:99
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :