summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMaximilian Albert <maximilian.albert@gmail.com>2008-03-30 16:42:27 +0000
committercilix42 <cilix42@users.sourceforge.net>2008-03-30 16:42:27 +0000
commit0289a62f1cc8c7da4a8bc890a34fb58ce8bcfcec (patch)
treeb6a7888ec7a5a21f825414496baafe0bdd7d215c /src
parentFactor out join endpoints validation & initialization code (diff)
downloadinkscape-0289a62f1cc8c7da4a8bc890a34fb58ce8bcfcec.tar.gz
inkscape-0289a62f1cc8c7da4a8bc890a34fb58ce8bcfcec.zip
New LPE: Circle (with center at the first point and passing through the last point of the original path).
This is just a proof-of-concept implementation for my tech drawing proposal for GSoC '08. (bzr r5237)
Diffstat (limited to 'src')
-rw-r--r--src/live_effects/Makefile_insert4
-rw-r--r--src/live_effects/effect.cpp7
-rw-r--r--src/live_effects/effect.h1
-rw-r--r--src/live_effects/lpe-circle_with_radius.cpp113
-rw-r--r--src/live_effects/lpe-circle_with_radius.h45
5 files changed, 168 insertions, 2 deletions
diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert
index fee34a9d6..0c6ba4a00 100644
--- a/src/live_effects/Makefile_insert
+++ b/src/live_effects/Makefile_insert
@@ -33,5 +33,7 @@ live_effects_liblive_effects_a_SOURCES = \
live_effects/lpe-test-doEffect-stack.cpp \
live_effects/lpe-test-doEffect-stack.h \
live_effects/lpe-slant.cpp \
- live_effects/lpe-slant.h
+ live_effects/lpe-slant.h \
+ live_effects/lpe-circle_with_radius.cpp \
+ live_effects/lpe-circle_with_radius.h
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp
index dc43af0d5..48a3ab9ff 100644
--- a/src/live_effects/effect.cpp
+++ b/src/live_effects/effect.cpp
@@ -42,6 +42,7 @@
#include "live_effects/lpe-test-doEffect-stack.h"
#include "live_effects/lpe-gears.h"
#include "live_effects/lpe-curvestitch.h"
+#include "live_effects/lpe-circle_with_radius.h"
#include "nodepath.h"
@@ -61,7 +62,8 @@ const Util::EnumData<EffectType> LPETypeData[INVALID_LPE] = {
{DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"},
#endif
{GEARS, N_("Gears"), "gears"},
- {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"},
+ {CURVE_STITCH, N_("Stitch Sub-Paths"), "curvestitching"},
+ {CIRCLE_WITH_RADIUS, N_("Circle (center+radius)"), "circle_with_radius"},
};
const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
@@ -100,6 +102,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj)
case CURVE_STITCH:
neweffect = (Effect*) new LPECurveStitch(lpeobj);
break;
+ case CIRCLE_WITH_RADIUS:
+ neweffect = (Effect*) new LPECircleWithRadius(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 b13ec5f6d..f3143124b 100644
--- a/src/live_effects/effect.h
+++ b/src/live_effects/effect.h
@@ -62,6 +62,7 @@ enum EffectType {
#endif
GEARS,
CURVE_STITCH,
+ CIRCLE_WITH_RADIUS,
INVALID_LPE // This must be last
};
diff --git a/src/live_effects/lpe-circle_with_radius.cpp b/src/live_effects/lpe-circle_with_radius.cpp
new file mode 100644
index 000000000..63e3dfa8a
--- /dev/null
+++ b/src/live_effects/lpe-circle_with_radius.cpp
@@ -0,0 +1,113 @@
+#define INKSCAPE_LPE_CIRCLE_WITH_RADIUS_CPP
+/** \file
+ * LPE <circle_with_radius> implementation, used as an example for a base starting class
+ * when implementing new LivePathEffects.
+ *
+ * In vi, three global search-and-replaces will let you rename everything
+ * in this and the .h file:
+ *
+ * :%s/CIRCLE_WITH_RADIUS/YOURNAME/g
+ * :%s/CircleWithRadius/Yourname/g
+ * :%s/circle_with_radius/yourname/g
+ */
+/*
+ * 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/lpe-circle_with_radius.h"
+#include "display/curve.h"
+#include <libnr/n-art-bpath.h>
+
+// You might need to include other 2geom files. You can add them here:
+#include <2geom/path.h>
+#include <2geom/sbasis.h>
+#include <2geom/bezier-to-sbasis.h>
+#include <2geom/d2.h>
+
+using namespace Geom;
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+LPECircleWithRadius::LPECircleWithRadius(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject)//,
+ // initialise your parameters here:
+ //radius(_("Float parameter"), _("just a real number like 1.4!"), "svgname", &wr, this, 50)
+{
+ // register all your parameters here, so Inkscape knows which parameters this effect has:
+ //registerParameter( dynamic_cast<Parameter *>(&radius) );
+}
+
+LPECircleWithRadius::~LPECircleWithRadius()
+{
+
+}
+
+
+/* ########################
+ * Choose to implement one of the doEffect functions. You can delete or comment out the others.
+*/
+
+D2<SBasis> _circle(Geom::Point center, double radius) {
+ D2<SBasis> B;
+ Linear bo = Linear(0, 2 * M_PI);
+
+ B[0] = cos(bo,2);
+ B[1] = sin(bo,2);
+
+ B = B*radius + center;
+ return B;
+}
+
+std::vector<Geom::Path>
+LPECircleWithRadius::doEffect_path (std::vector<Geom::Path> & path_in)
+{
+ std::vector<Geom::Path> path_out = std::vector<Geom::Path>();
+ Geom::Path pb;
+
+ Geom::Point center = path_in[0].initialPoint();
+ Geom::Point pt = path_in[0].finalPoint();
+
+ double radius = Geom::L2(pt - center);
+
+ pb.append(SBasisCurve(_circle(center, radius)));
+
+ path_out.push_back(pb);
+
+ return path_out;
+}
+
+/*
+
+Geom::Piecewise<Geom::D2<Geom::SBasis> >
+LPECircleWithRadius::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in)
+{
+ Geom::Piecewise<Geom::D2<Geom::SBasis> > output;
+
+ output = pwd2_in; // spice this up to make the effect actually *do* something!
+
+ 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-circle_with_radius.h b/src/live_effects/lpe-circle_with_radius.h
new file mode 100644
index 000000000..e783e0aab
--- /dev/null
+++ b/src/live_effects/lpe-circle_with_radius.h
@@ -0,0 +1,45 @@
+#ifndef INKSCAPE_LPE_CIRCLE_WITH_RADIUS_H
+#define INKSCAPE_LPE_CIRCLE_WITH_RADIUS_H
+
+/** \file
+ * LPE <circle_with_radius> implementation, see lpe-circle_with_radius.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/parameter.h"
+#include "live_effects/parameter/path.h"
+#include "live_effects/parameter/point.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPECircleWithRadius : public Effect {
+public:
+ LPECircleWithRadius(LivePathEffectObject *lpeobject);
+ virtual ~LPECircleWithRadius();
+
+// Choose to implement one of the doEffect functions. You can delete or comment out the others.
+ virtual std::vector<Geom::Path> doEffect_path (std::vector<Geom::Path> & path_in);
+
+private:
+ // add the parameters for your effect here:
+ //ScalarParam radius;
+ // there are all kinds of parameters. Check the /live_effects/parameter directory which types exist!
+
+ LPECircleWithRadius(const LPECircleWithRadius&);
+ LPECircleWithRadius& operator=(const LPECircleWithRadius&);
+};
+
+} //namespace LivePathEffect
+} //namespace Inkscape
+
+#endif