Code

New LPE: Copy rotate
authorcilix42 <cilix42@users.sourceforge.net>
Wed, 18 Jun 2008 02:13:55 +0000 (02:13 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Wed, 18 Jun 2008 02:13:55 +0000 (02:13 +0000)
src/live_effects/Makefile_insert
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-copy_rotate.cpp [new file with mode: 0644]
src/live_effects/lpe-copy_rotate.h [new file with mode: 0644]

index 245a9bd60b7463e349c38d61b1bddbbddcd7b055..d0bfb5b998d68ed8fa5c7af8728668907c3549d4 100644 (file)
@@ -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
 
index 73b5a578685b9a5845e86809a7285736c6422377..08745a74ea331331117954cd5c2f5b44be2b2e76 100644 (file)
@@ -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<EffectType> 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<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
 
@@ -159,6 +161,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
         case PARALLEL:
             neweffect = static_cast<Effect*> ( new LPEParallel(lpeobj) );
             break;
+        case COPY_ROTATE:
+            neweffect = static_cast<Effect*> ( new LPECopyRotate(lpeobj) );
+            break;
         default:
             g_warning("LivePathEffect::Effect::New   called with invalid patheffect type (%d)", lpenr);
             neweffect = NULL;
index 09a07039a6de36bfec62be1d9ccb11c5e4f7253f..672b90b87cb71bcdacaf3d2b9198be920041e06a 100644 (file)
@@ -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 (file)
index 0000000..e3f996a
--- /dev/null
@@ -0,0 +1,83 @@
+#define INKSCAPE_LPE_COPY_ROTATE_CPP
+/** \file
+ * LPE <copy_rotate> implementation
+ */
+/*
+ * Authors:
+ *   Maximilian Albert
+ *
+ * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * 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<Parameter *>(&angle) );
+    registerParameter( dynamic_cast<Parameter *>(&num_copies) );
+    registerParameter( dynamic_cast<Parameter *>(&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<Geom::D2<Geom::SBasis> >
+LPECopyRotate::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in)
+{
+    using namespace Geom;
+
+    Piecewise<D2<SBasis> > 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 (file)
index 0000000..72b46b5
--- /dev/null
@@ -0,0 +1,56 @@
+#ifndef INKSCAPE_LPE_COPY_ROTATE_H
+#define INKSCAPE_LPE_COPY_ROTATE_H
+
+/** \file
+ * LPE <copy_rotate> implementation, see lpe-copy_rotate.cpp.
+ */
+
+/*
+ * Authors:
+ *   Johan Engelen
+ *
+ * Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ *
+ * 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<Geom::D2<Geom::SBasis> > doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > 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 :