Code

e3f996a1b33f7c40c586b5683ef1834ba97d850e
[inkscape.git] / src / live_effects / lpe-copy_rotate.cpp
1 #define INKSCAPE_LPE_COPY_ROTATE_CPP
2 /** \file
3  * LPE <copy_rotate> implementation
4  */
5 /*
6  * Authors:
7  *   Maximilian Albert
8  *
9  * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
10  * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include "live_effects/lpe-copy_rotate.h"
16 #include "sp-shape.h"
17 #include "display/curve.h"
19 #include <2geom/path.h>
20 #include <2geom/transforms.h>
21 #include <2geom/d2-sbasis.h>
23 namespace Inkscape {
24 namespace LivePathEffect {
26 LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) :
27     Effect(lpeobject),
28     angle(_("Angle"), _("Angle"), "angle", &wr, this, 30.0),
29     num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 1),
30     origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this)
31 {
32     show_orig_path = true;
34     // register all your parameters here, so Inkscape knows which parameters this effect has:
35     registerParameter( dynamic_cast<Parameter *>(&angle) );
36     registerParameter( dynamic_cast<Parameter *>(&num_copies) );
37     registerParameter( dynamic_cast<Parameter *>(&origin) );
39     num_copies.param_make_integer(true);
40 }
42 LPECopyRotate::~LPECopyRotate()
43 {
45 }
47 void
48 LPECopyRotate::doOnApply(SPLPEItem *lpeitem)
49 {
50     origin.param_setValue(SP_SHAPE(lpeitem)->curve->first_point().to_2geom());
51 }
53 Geom::Piecewise<Geom::D2<Geom::SBasis> >
54 LPECopyRotate::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
55 {
56     using namespace Geom;
58     Piecewise<D2<SBasis> > output;
60     for (int i = 1; i <= num_copies; ++i) {
61         Rotate rot(deg_to_rad(angle * i));
62         Matrix t = Translate(-origin) * rot * Translate(origin);
63         output.concat(pwd2_in * t);
64     }
66     return output;
67 }
69 /* ######################## */
71 } //namespace LivePathEffect
72 } /* namespace Inkscape */
74 /*
75   Local Variables:
76   mode:c++
77   c-file-style:"stroustrup"
78   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
79   indent-tabs-mode:nil
80   fill-column:99
81   End:
82 */
83 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :