From: cilix42 Date: Sun, 30 Mar 2008 16:42:27 +0000 (+0000) Subject: New LPE: Circle (with center at the first point and passing through the last point... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8d9f5d586a04809427ce1df284a5720112177991;p=inkscape.git 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. --- 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 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 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 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 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-circle_with_radius.h" +#include "display/curve.h" +#include + +// 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(&radius) ); +} + +LPECircleWithRadius::~LPECircleWithRadius() +{ + +} + + +/* ######################## + * Choose to implement one of the doEffect functions. You can delete or comment out the others. +*/ + +D2 _circle(Geom::Point center, double radius) { + D2 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 +LPECircleWithRadius::doEffect_path (std::vector & path_in) +{ + std::vector path_out = std::vector(); + 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 > +LPECircleWithRadius::doEffect_pwd2 (Geom::Piecewise > & pwd2_in) +{ + Geom::Piecewise > 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 implementation, see lpe-circle_with_radius.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/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 doEffect_path (std::vector & 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