lpe-parallel.cpp revision 3cfad782faf34c654ec837780ed7b3fe95e82c2e
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#define INKSCAPE_LPE_PARALLEL_CPP
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix/** \file
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * LPE <parallel> implementation
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix */
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix/*
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Authors:
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Maximilian Albert
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix *
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen * Copyright (C) Johan Engelen 2007-2012 <j.b.c.engelen@alumnus.utwente.nl>
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix *
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix * Released under GNU GPL, read the file 'COPYING' for more information
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix */
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#include "live_effects/lpe-parallel.h"
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#include "sp-shape.h"
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#include "display/curve.h"
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#include <2geom/path.h>
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix#include <2geom/transforms.h>
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen#include "knot-holder-entity.h"
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen#include "knotholder.h"
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixnamespace Inkscape {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixnamespace LivePathEffect {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixnamespace Pl {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelenclass KnotHolderEntityLeftEnd : public LPEKnotHolderEntity {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixpublic:
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntityLeftEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen virtual Geom::Point knot_get();
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix};
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelenclass KnotHolderEntityRightEnd : public LPEKnotHolderEntity {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixpublic:
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntityRightEnd(LPEParallel *effect) : LPEKnotHolderEntity(effect) {};
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen virtual void knot_set(Geom::Point const &p, Geom::Point const &origin, guint state);
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen virtual Geom::Point knot_get();
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix};
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix} // namespace Pl
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixLPEParallel::LPEParallel(LivePathEffectObject *lpeobject) :
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix Effect(lpeobject),
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix // initialise your parameters here:
79d46cc367c4181803d9a7a327b163643f23e8a7cilix offset_pt(_("Offset"), _("Adjust the offset"), "offset_pt", &wr, this),
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix length_left(_("Length left"), _("Specifies the left end of the parallel"), "length-left", &wr, this, 150),
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix length_right(_("Length right"), _("Specifies the right end of the parallel"), "length-right", &wr, this, 150)
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix show_orig_path = true;
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen _provides_knotholder_entities = true;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix registerParameter(dynamic_cast<Parameter *>(&offset_pt));
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix registerParameter( dynamic_cast<Parameter *>(&length_left) );
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix registerParameter( dynamic_cast<Parameter *>(&length_right) );
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixLPEParallel::~LPEParallel()
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixvoid
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixLPEParallel::doOnApply (SPLPEItem *lpeitem)
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
620d9f76e90641a5a91f0c45fcb9a2f07b3881dbJohan Engelen SPCurve const *curve = SP_SHAPE(lpeitem)->_curve;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
99fae8b11f74e464ad0f55a7bfcc02933c4c1747johanengelen A = *(curve->first_point());
99fae8b11f74e464ad0f55a7bfcc02933c4c1747johanengelen B = *(curve->last_point());
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix dir = unit_vector(B - A);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix offset_pt.param_set_and_write_new_value((A + B)/2 + dir.ccw() * 100);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixGeom::Piecewise<Geom::D2<Geom::SBasis> >
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixLPEParallel::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix using namespace Geom;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix Piecewise<D2<SBasis> > output;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix A = pwd2_in.firstValue();
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix B = pwd2_in.lastValue();
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix dir = unit_vector(B - A);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix C = offset_pt - dir * length_left;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix D = offset_pt + dir * length_right;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix output = Piecewise<D2<SBasis> >(D2<SBasis>(Linear(C[X], D[X]), Linear(C[Y], D[Y])));
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix return output + dir;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelenvoid
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. EngelenLPEParallel::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntity *e = new Pl::KnotHolderEntityLeftEnd(this);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen e->create( desktop, item, knotholder,
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen _("Adjust the \"left\" end of the parallel")
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen /*optional: knot_shape, knot_mode, knot_color*/);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen knotholder->add(e);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix }
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen {
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen KnotHolderEntity *e = new Pl::KnotHolderEntityRightEnd(this);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen e->create( desktop, item, knotholder,
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen _("Adjust the \"right\" end of the parallel")
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen /*optional: knot_shape, knot_mode, knot_color*/);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen knotholder->add(e);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen }
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen};
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelennamespace Pl {
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixvoid
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelenKnotHolderEntityLeftEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix using namespace Geom;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen Geom::Point const s = snap_knot_position(p);
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilix
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix lpe->length_left.param_set_value(-lambda);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixvoid
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelenKnotHolderEntityRightEnd::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint /*state*/)
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix using namespace Geom;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen Geom::Point const s = snap_knot_position(p);
947fb2f89245c19c5bad9dbefb9fd44c2aaed2eccilix
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelen double lambda = L2(s - lpe->offset_pt) * sgn(dot(s - lpe->offset_pt, lpe->dir));
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix lpe->length_right.param_set_value(lambda);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelenGeom::Point
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixKnotHolderEntityLeftEnd::knot_get()
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix return lpe->C;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
5b20351508dc029f37f23fb7add6d0b43bf47f20johanengelenGeom::Point
b320a8d186114a5122ddc3afbe95110eb6cb10cecilixKnotHolderEntityRightEnd::knot_get()
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix{
3cfad782faf34c654ec837780ed7b3fe95e82c2eJohan B. C. Engelen LPEParallel *lpe = dynamic_cast<LPEParallel *>(_effect);
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix return lpe->D;
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix}
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix} // namespace Pl
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix/* ######################## */
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix} //namespace LivePathEffect
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix} /* namespace Inkscape */
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix/*
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix Local Variables:
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix mode:c++
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix c-file-style:"stroustrup"
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix indent-tabs-mode:nil
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix fill-column:99
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix End:
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix*/
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :