78f31011c08503bf0d95da30e5f6326d4dd10f8acilix/** \file
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * LPE <perp_bisector> implementation.
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix */
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix/*
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Authors:
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Maximilian Albert
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Johan Engelen
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix *
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Copyright (C) Maximilin Albert 2008 <maximilian.albert@gmail.com>
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix *
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix * Released under GNU GPL, read the file 'COPYING' for more information
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix */
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
eb4caa8f4cdc2955b58dcd2de06fe770533414c8Jon A. Cruz#include <glibmm/i18n.h>
eb4caa8f4cdc2955b58dcd2de06fe770533414c8Jon A. Cruz
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix#include "live_effects/lpe-perp_bisector.h"
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix#include "display/curve.h"
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix#include "sp-path.h"
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix#include "line-geometry.h"
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix#include "sp-lpe-item.h"
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix#include <2geom/path.h>
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen#include "knot-holder-entity.h"
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen#include "knotholder.h"
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixnamespace Inkscape {
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixnamespace LivePathEffect {
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilixnamespace PB {
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilixclass KnotHolderEntityEnd : public LPEKnotHolderEntity {
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilixpublic:
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);
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilix};
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilix
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilixclass KnotHolderEntityLeftEnd : public KnotHolderEntityEnd {
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilixpublic:
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntityLeftEnd(LPEPerpBisector *effect) : KnotHolderEntityEnd(effect) {};
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen virtual Geom::Point knot_get() const;
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilix};
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilix
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilixclass KnotHolderEntityRightEnd : public KnotHolderEntityEnd {
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilixpublic:
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. Engelen virtual Geom::Point knot_get() const;
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilix};
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilix
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelenGeom::Point
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. EngelenKnotHolderEntityLeftEnd::knot_get() const {
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen LPEPerpBisector const* lpe = dynamic_cast<LPEPerpBisector const*>(_effect);
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen return Geom::Point(lpe->C);
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelenGeom::Point
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. EngelenKnotHolderEntityRightEnd::knot_get() const {
0b2d8abc1011ad865fce3b883ccb2587cb15cc90Johan B. C. Engelen LPEPerpBisector const* lpe = dynamic_cast<LPEPerpBisector const*>(_effect);
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen return Geom::Point(lpe->D);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixvoid
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;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
624e4bb114c588505c592e405dbad6570e5704feDiederik van Lierop Geom::Point const s = snap_knot_position(p, state);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński double lambda = Geom::nearest_time(s, lpe->M, lpe->perp_dir);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix if (left) {
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix lpe->C = lpe->M + lpe->perp_dir * lambda;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix lpe->length_left.param_set_value(lambda);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix } else {
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix lpe->D = lpe->M + lpe->perp_dir * lambda;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix lpe->length_right.param_set_value(-lambda);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix }
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
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);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixvoid
624e4bb114c588505c592e405dbad6570e5704feDiederik van LieropKnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
624e4bb114c588505c592e405dbad6570e5704feDiederik van Lierop bisector_end_set(p, state);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixvoid
624e4bb114c588505c592e405dbad6570e5704feDiederik van LieropKnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state) {
624e4bb114c588505c592e405dbad6570e5704feDiederik van Lierop bisector_end_set(p, state, false);
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
07bcf962fbc219b975e47bb9e5600a5d4fa087dfcilix} //namescape PB
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixLPEPerpBisector::LPEPerpBisector(LivePathEffectObject *lpeobject) :
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix Effect(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{
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix show_orig_path = true;
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen _provides_knotholder_entities = true;
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix
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) );
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixLPEPerpBisector::~LPEPerpBisector()
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix{
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixvoid
a39c187369a59e887255e3f704a3ababf2b10678Johan B. C. EngelenLPEPerpBisector::doOnApply (SPLPEItem const*/*lpeitem*/)
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix{
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix /* make the path a straight line */
aafa54db9000be62c009c65c411ed698a36714bacilix /**
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix SPCurve* curve = sp_path_get_curve_for_edit (SP_PATH(lpeitem)); // TODO: Should we use sp_shape_get_curve()?
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen Geom::Point A(curve->first_point());
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen Geom::Point B(curve->last_point());
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
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();
aafa54db9000be62c009c65c411ed698a36714bacilix **/
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixGeom::Piecewise<Geom::D2<Geom::SBasis> >
78f31011c08503bf0d95da30e5f6326d4dd10f8acilixLPEPerpBisector::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix{
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix using namespace Geom;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix Piecewise<D2<SBasis> > output;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix A = pwd2_in.firstValue();
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix B = pwd2_in.lastValue();
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix M = (A + B)/2;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix perp_dir = unit_vector((B - A).ccw());
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix C = M + perp_dir * length_left;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix D = M - perp_dir * length_right;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
76addc201c409e81eaaa73fe27cc0f79c4db097cKrzysztof Kosiński output = Piecewise<D2<SBasis> >(D2<SBasis>(SBasis(C[X], D[X]), SBasis(C[Y], D[Y])));
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix return output;
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix}
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelenvoid
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. EngelenLPEPerpBisector::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntity *e = new PB::KnotHolderEntityLeftEnd(this);
7655c8b8ffe3674dd7e7c74f450fb7194943c0deJon A. Cruz e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
33ada1c3184434af1146161adfea1ff168870007JazzyNico _("Adjust the \"left\" end of the bisector") );
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen knotholder->add(e);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen }
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntity *e = new PB::KnotHolderEntityRightEnd(this);
7655c8b8ffe3674dd7e7c74f450fb7194943c0deJon A. Cruz e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
33ada1c3184434af1146161adfea1ff168870007JazzyNico _("Adjust the \"right\" end of the bisector") );
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen knotholder->add(e);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen }
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen};
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix/* ######################## */
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix} //namespace LivePathEffect
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix} /* namespace Inkscape */
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix/*
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix Local Variables:
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix mode:c++
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 End:
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix*/
78f31011c08503bf0d95da30e5f6326d4dd10f8acilix// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :