From: cilix42 Date: Wed, 30 Jul 2008 12:06:20 +0000 (+0000) Subject: New LPE: path length X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ecf048161ae0284d01d34ca5844204775c0d3fde;p=inkscape.git New LPE: path length --- diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index ea432e4c3..85f58d06d 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -70,5 +70,6 @@ live_effects_liblive_effects_a_SOURCES = \ live_effects/lpe-ruler.cpp \ live_effects/lpe-ruler.h \ live_effects/lpe-text_label.cpp \ - live_effects/lpe-text_label.h - + live_effects/lpe-text_label.h \ + live_effects/lpe-path_length.cpp \ + live_effects/lpe-path_length.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 701b46d36..b0cebab8d 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -64,6 +64,7 @@ #include "live_effects/lpe-boolops.h" #include "live_effects/lpe-interpolate.h" #include "live_effects/lpe-text_label.h" +#include "live_effects/lpe-path_length.h" // end of includes namespace Inkscape { @@ -90,6 +91,7 @@ const Util::EnumData LPETypeData[] = { {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, {OFFSET, N_("Offset"), "offset"}, {PARALLEL, N_("Parallel"), "parallel"}, + {PATH_LENGTH, N_("Path length"), "path_length"}, {PATTERN_ALONG_PATH, N_("Pattern Along Path"), "skeletal"}, // for historic reasons, this effect is called skeletal(strokes) in Inkscape:SVG {PERP_BISECTOR, N_("Perpendicular bisector"), "perp_bisector"}, {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, @@ -192,6 +194,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case TEXT_LABEL: neweffect = static_cast ( new LPETextLabel(lpeobj) ); break; + case PATH_LENGTH: + neweffect = static_cast ( new LPEPathLength(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 859c0ff7b..123508751 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -80,6 +80,7 @@ enum EffectType { BOOLOPS, INTERPOLATE, TEXT_LABEL, + PATH_LENGTH, INVALID_LPE // This must be last }; diff --git a/src/live_effects/lpe-path_length.cpp b/src/live_effects/lpe-path_length.cpp new file mode 100644 index 000000000..d2aea13d8 --- /dev/null +++ b/src/live_effects/lpe-path_length.cpp @@ -0,0 +1,72 @@ +#define INKSCAPE_LPE_PATH_LENGTH_CPP +/** \file + * LPE implementation. + */ +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) 2007-2008 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-path_length.h" + +#include "2geom/sbasis-geometric.h" + +namespace Inkscape { +namespace LivePathEffect { + +LPEPathLength::LPEPathLength(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + info_text(_("Info text"), _("Parameter for text creation"), "info_text", &wr, this, "") +{ + /* uncomment the next line if you want the original path to be + permanently displayed as a helperpath while the item is selected */ + //show_orig_path = true; + + registerParameter(dynamic_cast(&info_text)); +} + +LPEPathLength::~LPEPathLength() +{ + +} + +Geom::Piecewise > +LPEPathLength::doEffect_pwd2 (Geom::Piecewise > const & pwd2_in) +{ + using namespace Geom; + + gchar *arc_length = g_strdup_printf("%.2f", Geom::length(pwd2_in)); + info_text.param_setValue(arc_length); + g_free(arc_length); + + info_text.setPosAndAnchor(pwd2_in, 0.5, 20); + + Piecewise > A = integral(pwd2_in); + Point c; + double area; + if (centroid(pwd2_in, c, area)) { + g_print ("Area is zero\n"); + } + //g_print ("Area: %f\n", area); + + return pwd2_in; +} + +} //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-path_length.h b/src/live_effects/lpe-path_length.h new file mode 100644 index 000000000..db4993df5 --- /dev/null +++ b/src/live_effects/lpe-path_length.h @@ -0,0 +1,51 @@ +#ifndef INKSCAPE_LPE_PATH_LENGTH_H +#define INKSCAPE_LPE_PATH_LENGTH_H + +/** \file + * LPE implementation. + */ + +/* + * Authors: + * Maximilian Albert + * Johan Engelen + * + * Copyright (C) 2007-2008 Authors + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/text.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEPathLength : public Effect { +public: + LPEPathLength(LivePathEffectObject *lpeobject); + virtual ~LPEPathLength(); + + virtual Geom::Piecewise > doEffect_pwd2 (Geom::Piecewise > const & pwd2_in); + +private: + LPEPathLength(const LPEPathLength&); + LPEPathLength& operator=(const LPEPathLength&); + TextParam info_text; +}; + +} //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 :