lpe-copy_rotate.cpp revision b8502defa91647a317b285046a49546612f66e6d
0N/A/** \file
2362N/A * LPE <copy_rotate> implementation
0N/A */
0N/A/*
0N/A * Authors:
0N/A * Maximilian Albert <maximilian.albert@gmail.com>
2362N/A * Johan Engelen <j.b.c.engelen@alumnus.utwente.nl>
0N/A *
2362N/A * Copyright (C) Authors 2007-2012
0N/A *
0N/A * Released under GNU GPL, read the file 'COPYING' for more information
0N/A */
0N/A
0N/A#include <glibmm/i18n.h>
0N/A
0N/A#include "live_effects/lpe-copy_rotate.h"
0N/A#include "sp-shape.h"
0N/A#include "display/curve.h"
0N/A
0N/A#include <2geom/path.h>
2362N/A#include <2geom/transforms.h>
2362N/A#include <2geom/d2-sbasis.h>
2362N/A#include <2geom/angle.h>
0N/A
0N/A#include "knot-holder-entity.h"
0N/A#include "knotholder.h"
0N/A
0N/Anamespace Inkscape {
0N/Anamespace LivePathEffect {
0N/A
0N/Anamespace CR {
0N/A
0N/Aclass KnotHolderEntityStartingAngle : public LPEKnotHolderEntity {
0N/Apublic:
0N/A KnotHolderEntityStartingAngle(LPECopyRotate *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();
0N/A};
0N/A
0N/Aclass KnotHolderEntityRotationAngle : public LPEKnotHolderEntity {
0N/Apublic:
0N/A KnotHolderEntityRotationAngle(LPECopyRotate *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();
0N/A};
0N/A
0N/A} // namespace CR
0N/A
0N/ALPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) :
0N/A Effect(lpeobject),
0N/A starting_angle(_("Starting:"), _("Angle of the first copy"), "starting_angle", &wr, this, 0.0),
0N/A rotation_angle(_("Rotation angle:"), _("Angle between two successive copies"), "rotation_angle", &wr, this, 30.0),
0N/A num_copies(_("Number of copies:"), _("Number of copies of the original path"), "num_copies", &wr, this, 5),
0N/A origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this, "Adjust the origin of the rotation"),
0N/A dist_angle_handle(100)
0N/A{
0N/A show_orig_path = true;
0N/A _provides_knotholder_entities = true;
0N/A
0N/A // register all your parameters here, so Inkscape knows which parameters this effect has:
0N/A registerParameter( dynamic_cast<Parameter *>(&starting_angle) );
0N/A registerParameter( dynamic_cast<Parameter *>(&rotation_angle) );
0N/A registerParameter( dynamic_cast<Parameter *>(&num_copies) );
0N/A registerParameter( dynamic_cast<Parameter *>(&origin) );
0N/A
0N/A num_copies.param_make_integer(true);
0N/A num_copies.param_set_range(0, 1000);
0N/A}
0N/A
0N/ALPECopyRotate::~LPECopyRotate()
0N/A{
0N/A
0N/A}
0N/A
0N/Avoid
0N/ALPECopyRotate::doOnApply(SPLPEItem *lpeitem)
0N/A{
0N/A SPCurve *curve = SP_SHAPE(lpeitem)->_curve;
0N/A
0N/A A = *(curve->first_point());
0N/A B = *(curve->last_point());
0N/A
0N/A origin.param_setValue(A);
0N/A
0N/A dir = unit_vector(B - A);
0N/A dist_angle_handle = L2(B - A);
0N/A}
0N/A
0N/AGeom::Piecewise<Geom::D2<Geom::SBasis> >
0N/ALPECopyRotate::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
0N/A{
0N/A using namespace Geom;
0N/A
0N/A // I first suspected the minus sign to be a bug in 2geom but it is
0N/A // likely due to SVG's choice of coordinate system orientation (max)
0N/A start_pos = origin + dir * Rotate(-deg_to_rad(starting_angle)) * dist_angle_handle;
0N/A rot_pos = origin + dir * Rotate(-deg_to_rad(starting_angle + rotation_angle)) * dist_angle_handle;
0N/A
0N/A A = pwd2_in.firstValue();
0N/A B = pwd2_in.lastValue();
0N/A dir = unit_vector(B - A);
0N/A
0N/A Piecewise<D2<SBasis> > output;
0N/A
0N/A Affine pre = Translate(-origin) * Rotate(-deg_to_rad(starting_angle));
0N/A for (int i = 0; i < num_copies; ++i) {
0N/A // I first suspected the minus sign to be a bug in 2geom but it is
0N/A // likely due to SVG's choice of coordinate system orientation (max)
0N/A Rotate rot(-deg_to_rad(rotation_angle * i));
0N/A Affine t = pre * rot * Translate(origin);
0N/A output.concat(pwd2_in * t);
0N/A }
0N/A
0N/A return output;
0N/A}
0N/A
0N/Avoid
0N/ALPECopyRotate::addCanvasIndicators(SPLPEItem */*lpeitem*/, std::vector<Geom::PathVector> &hp_vec)
0N/A{
0N/A using namespace Geom;
0N/A
0N/A Path path(start_pos);
0N/A path.appendNew<LineSegment>((Geom::Point) origin);
0N/A path.appendNew<LineSegment>(rot_pos);
0N/A
0N/A PathVector pathv;
0N/A pathv.push_back(path);
0N/A hp_vec.push_back(pathv);
0N/A}
0N/A
0N/Avoid LPECopyRotate::addKnotHolderEntities(KnotHolder *knotholder, SPDesktop *desktop, SPItem *item) {
0N/A {
0N/A KnotHolderEntity *e = new CR::KnotHolderEntityStartingAngle(this);
0N/A e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
0N/A _("Adjust the starting angle") );
0N/A knotholder->add(e);
0N/A }
0N/A {
0N/A KnotHolderEntity *e = new CR::KnotHolderEntityRotationAngle(this);
0N/A e->create( desktop, item, knotholder, Inkscape::CTRL_TYPE_UNKNOWN,
0N/A _("Adjust the rotation angle") );
0N/A knotholder->add(e);
0N/A }
0N/A};
0N/A
0N/Anamespace CR {
0N/A
0N/Ausing namespace Geom;
0N/A
0N/Avoid
0N/AKnotHolderEntityStartingAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
0N/A{
0N/A LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
0N/A
0N/A Geom::Point const s = snap_knot_position(p, state);
0N/A
0N/A // I first suspected the minus sign to be a bug in 2geom but it is
0N/A // likely due to SVG's choice of coordinate system orientation (max)
0N/A lpe->starting_angle.param_set_value(rad_to_deg(-angle_between(lpe->dir, s - lpe->origin)));
0N/A if (state & GDK_SHIFT_MASK) {
0N/A lpe->dist_angle_handle = L2(lpe->B - lpe->A);
0N/A } else {
0N/A lpe->dist_angle_handle = L2(p - lpe->origin);
0N/A }
0N/A
0N/A // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
0N/A sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
0N/A}
0N/A
0N/Avoid
0N/AKnotHolderEntityRotationAngle::knot_set(Geom::Point const &p, Geom::Point const &/*origin*/, guint state)
0N/A{
0N/A LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
0N/A
0N/A Geom::Point const s = snap_knot_position(p, state);
0N/A
0N/A // I first suspected the minus sign to be a bug in 2geom but it is
0N/A // likely due to SVG's choice of coordinate system orientation (max)
0N/A lpe->rotation_angle.param_set_value(rad_to_deg(-angle_between(lpe->dir, s - lpe->origin)) - lpe->starting_angle);
0N/A if (state & GDK_SHIFT_MASK) {
0N/A lpe->dist_angle_handle = L2(lpe->B - lpe->A);
0N/A } else {
0N/A lpe->dist_angle_handle = L2(p - lpe->origin);
0N/A }
0N/A
0N/A // FIXME: this should not directly ask for updating the item. It should write to SVG, which triggers updating.
0N/A sp_lpe_item_update_patheffect (SP_LPE_ITEM(item), false, true);
0N/A}
0N/A
0N/AGeom::Point
0N/AKnotHolderEntityStartingAngle::knot_get()
0N/A{
0N/A LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
0N/A return lpe->start_pos;
0N/A}
0N/A
0N/AGeom::Point
0N/AKnotHolderEntityRotationAngle::knot_get()
0N/A{
0N/A LPECopyRotate* lpe = dynamic_cast<LPECopyRotate *>(_effect);
0N/A return lpe->rot_pos;
0N/A}
0N/A
0N/A} // namespace CR
0N/A
0N/A
0N/A
0N/A/* ######################## */
0N/A
0N/A} //namespace LivePathEffect
0N/A} /* namespace Inkscape */
0N/A
0N/A/*
0N/A Local Variables:
0N/A mode:c++
0N/A c-file-style:"stroustrup"
0N/A c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
0N/A indent-tabs-mode:nil
0N/A fill-column:99
0N/A End:
0N/A*/
0N/A// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
0N/A