From 044d712d4d03f8354962d54e47cfac2346a69ccc Mon Sep 17 00:00:00 2001 From: cilix42 Date: Wed, 18 Jun 2008 02:13:55 +0000 Subject: [PATCH] New LPE: Copy rotate --- src/live_effects/Makefile_insert | 4 +- src/live_effects/effect.cpp | 5 ++ src/live_effects/effect.h | 1 + src/live_effects/lpe-copy_rotate.cpp | 83 ++++++++++++++++++++++++++++ src/live_effects/lpe-copy_rotate.h | 56 +++++++++++++++++++ 5 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 src/live_effects/lpe-copy_rotate.cpp create mode 100644 src/live_effects/lpe-copy_rotate.h diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index 245a9bd60..d0bfb5b99 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -58,5 +58,7 @@ live_effects_liblive_effects_a_SOURCES = \ live_effects/lpe-angle_bisector.cpp \ live_effects/lpe-angle_bisector.h \ live_effects/lpe-parallel.cpp \ - live_effects/lpe-parallel.h + live_effects/lpe-parallel.h \ + live_effects/lpe-copy_rotate.cpp \ + live_effects/lpe-copy_rotate.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 73b5a5786..08745a74e 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -59,6 +59,7 @@ #include "live_effects/lpe-circle_3pts.h" #include "live_effects/lpe-angle_bisector.h" #include "live_effects/lpe-parallel.h" +#include "live_effects/lpe-copy_rotate.h" // end of includes namespace Inkscape { @@ -89,6 +90,7 @@ const Util::EnumData LPETypeData[INVALID_LPE] = { {CIRCLE_3PTS, N_("Circle through 3 points"), "circle_3pts"}, {ANGLE_BISECTOR, N_("Angle bisector"), "angle_bisector"}, {PARALLEL, N_("Parallel"), "parallel"}, + {COPY_ROTATE, N_("Rotate copies"), "copy_rotate"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, INVALID_LPE); @@ -159,6 +161,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case PARALLEL: neweffect = static_cast ( new LPEParallel(lpeobj) ); break; + case COPY_ROTATE: + neweffect = static_cast ( new LPECopyRotate(lpeobj) ); + break; default: g_warning("LivePathEffect::Effect::New called with invalid patheffect type (%d)", lpenr); neweffect = NULL; diff --git a/src/live_effects/effect.h b/src/live_effects/effect.h index 09a07039a..672b90b87 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -76,6 +76,7 @@ enum EffectType { CIRCLE_3PTS, ANGLE_BISECTOR, PARALLEL, + COPY_ROTATE, INVALID_LPE // This must be last }; diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp new file mode 100644 index 000000000..e3f996a1b --- /dev/null +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -0,0 +1,83 @@ +#define INKSCAPE_LPE_COPY_ROTATE_CPP +/** \file + * LPE implementation + */ +/* + * Authors: + * Maximilian Albert + * + * Copyright (C) Johan Engelen 2007 + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-copy_rotate.h" +#include "sp-shape.h" +#include "display/curve.h" + +#include <2geom/path.h> +#include <2geom/transforms.h> +#include <2geom/d2-sbasis.h> + +namespace Inkscape { +namespace LivePathEffect { + +LPECopyRotate::LPECopyRotate(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + angle(_("Angle"), _("Angle"), "angle", &wr, this, 30.0), + num_copies(_("Number of copies"), _("Number of copies of the original path"), "num_copies", &wr, this, 1), + origin(_("Origin"), _("Origin of the rotation"), "origin", &wr, this) +{ + show_orig_path = true; + + // register all your parameters here, so Inkscape knows which parameters this effect has: + registerParameter( dynamic_cast(&angle) ); + registerParameter( dynamic_cast(&num_copies) ); + registerParameter( dynamic_cast(&origin) ); + + num_copies.param_make_integer(true); +} + +LPECopyRotate::~LPECopyRotate() +{ + +} + +void +LPECopyRotate::doOnApply(SPLPEItem *lpeitem) +{ + origin.param_setValue(SP_SHAPE(lpeitem)->curve->first_point().to_2geom()); +} + +Geom::Piecewise > +LPECopyRotate::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) +{ + using namespace Geom; + + Piecewise > output; + + for (int i = 1; i <= num_copies; ++i) { + Rotate rot(deg_to_rad(angle * i)); + Matrix t = Translate(-origin) * rot * Translate(origin); + output.concat(pwd2_in * t); + } + + return output; +} + +/* ######################## */ + +} //namespace LivePathEffect +} /* namespace Inkscape */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/live_effects/lpe-copy_rotate.h b/src/live_effects/lpe-copy_rotate.h new file mode 100644 index 000000000..72b46b5d6 --- /dev/null +++ b/src/live_effects/lpe-copy_rotate.h @@ -0,0 +1,56 @@ +#ifndef INKSCAPE_LPE_COPY_ROTATE_H +#define INKSCAPE_LPE_COPY_ROTATE_H + +/** \file + * LPE implementation, see lpe-copy_rotate.cpp. + */ + +/* + * Authors: + * Johan Engelen + * + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/point.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPECopyRotate : public Effect { +public: + LPECopyRotate(LivePathEffectObject *lpeobject); + virtual ~LPECopyRotate(); + + virtual void doOnApply (SPLPEItem *lpeitem); + + virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + +private: + ScalarParam angle; + ScalarParam num_copies; + + PointParam origin; + + LPECopyRotate(const LPECopyRotate&); + LPECopyRotate& operator=(const LPECopyRotate&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : -- 2.30.2