From 6f4a90e526af850ffc36064f58f09c190f3b633f Mon Sep 17 00:00:00 2001 From: johanengelen Date: Thu, 8 May 2008 18:52:45 +0000 Subject: [PATCH] add LPEConstructGrid --- src/live_effects/effect.cpp | 5 ++ src/live_effects/effect.h | 1 + src/live_effects/lpe-constructgrid.cpp | 103 +++++++++++++++++++++++++ src/live_effects/lpe-constructgrid.h | 43 +++++++++++ 4 files changed, 152 insertions(+) create mode 100644 src/live_effects/lpe-constructgrid.cpp create mode 100644 src/live_effects/lpe-constructgrid.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index cee0c0b21..2cd88fd8b 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -44,6 +44,7 @@ #include "live_effects/lpe-circle_with_radius.h" #include "live_effects/lpe-perspective_path.h" #include "live_effects/lpe-spiro.h" +#include "live_effects/lpe-constructgrid.h" #include "nodepath.h" @@ -67,6 +68,7 @@ const Util::EnumData LPETypeData[INVALID_LPE] = { {CIRCLE_WITH_RADIUS, N_("Circle (center+radius)"), "circle_with_radius"}, {PERSPECTIVE_PATH, N_("Perspective path"), "perspective_path"}, {SPIRO, N_("Spiro spline"), "spiro"}, + {CONSTRUCT_GRID, N_("Construct grid"), "construct_grid"}, }; const Util::EnumDataConverter LPETypeConverter(LPETypeData, INVALID_LPE); @@ -113,6 +115,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case SPIRO: neweffect = static_cast ( new LPESpiro(lpeobj) ); break; + case CONSTRUCT_GRID: + neweffect = static_cast ( new LPEConstructGrid(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 603b0715e..58010358f 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -65,6 +65,7 @@ enum EffectType { CIRCLE_WITH_RADIUS, PERSPECTIVE_PATH, SPIRO, + CONSTRUCT_GRID, INVALID_LPE // This must be last }; diff --git a/src/live_effects/lpe-constructgrid.cpp b/src/live_effects/lpe-constructgrid.cpp new file mode 100644 index 000000000..1273e8b7c --- /dev/null +++ b/src/live_effects/lpe-constructgrid.cpp @@ -0,0 +1,103 @@ +#define INKSCAPE_LPE_CONSTRUCTGRID_CPP +/** \file + * LPE Construct Grid implementation + */ +/* + * Authors: + * Johan Engelen +* +* Copyright (C) Johan Engelen 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-constructgrid.h" + +#include <2geom/path.h> +#include <2geom/transforms.h> + +#include "nodepath.h" + +namespace Inkscape { +namespace LivePathEffect { + +using namespace Geom; + +LPEConstructGrid::LPEConstructGrid(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + nr_x(_("Size X"), _("The size of the grid in X direction."), "nr_x", &wr, this, 5), + nr_y(_("Size Y"), _("The size of the grid in Y direction."), "nr_y", &wr, this, 5) +{ + registerParameter( dynamic_cast(&nr_x) ); + registerParameter( dynamic_cast(&nr_y) ); + + nr_x.param_make_integer(); + nr_y.param_make_integer(); + nr_x.param_set_range(1, NR_HUGE); + nr_y.param_set_range(1, NR_HUGE); +} + +LPEConstructGrid::~LPEConstructGrid() +{ + +} + +std::vector +LPEConstructGrid::doEffect_path (std::vector const & path_in) +{ + // Check that the path has at least 3 nodes (i.e. 2 segments), more nodes are ignored + if (path_in[0].size() >= 2) { + // read the first 3 nodes: + Geom::Path::const_iterator it ( path_in[0].begin() ); + Geom::Point first_p = (*it++).initialPoint(); + Geom::Point origin = (*it++).initialPoint(); + Geom::Point second_p = (*it++).initialPoint(); + // make first_p and second_p be the construction *vectors* of the grid: + first_p -= origin; + second_p -= origin; + Geom::Translate first_translation( first_p ); + Geom::Translate second_translation( second_p ); + + // create the gridpaths of the two directions + Geom::Path first_path( origin ); + first_path.appendNew( origin + first_p*nr_y ); + Geom::Path second_path( origin ); + second_path.appendNew( origin + second_p*nr_x ); + + // use the gridpaths and set them in the correct grid + std::vector path_out; + path_out.push_back(first_path); + for (int ix = 0; ix < nr_x; ix++) { + path_out.push_back(path_out.back() * second_translation ); + } + path_out.push_back(second_path); + for (int iy = 0; iy < nr_y; iy++) { + path_out.push_back(path_out.back() * first_translation ); + } + + return path_out; + } else { + return path_in; + } +} + +void +LPEConstructGrid::setup_nodepath(Inkscape::NodePath::Path *np) +{ + Effect::setup_nodepath(np); + sp_nodepath_make_straight_path(np); +} + +} //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-constructgrid.h b/src/live_effects/lpe-constructgrid.h new file mode 100644 index 000000000..006ff6f54 --- /dev/null +++ b/src/live_effects/lpe-constructgrid.h @@ -0,0 +1,43 @@ +#ifndef INKSCAPE_LPE_CONSTRUCTGRID_H +#define INKSCAPE_LPE_CONSTRUCTGRID_H + +/** \file + * Implementation of the construct grid LPE, see lpe-constructgrid.cpp + */ + +/* + * Authors: + * Johan Engelen +* +* Copyright (C) Johan Engelen 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEConstructGrid : public Effect { +public: + LPEConstructGrid(LivePathEffectObject *lpeobject); + virtual ~LPEConstructGrid(); + + virtual std::vector doEffect_path (std::vector const & path_in); + + virtual void setup_nodepath(Inkscape::NodePath::Path *np); + +private: + ScalarParam nr_x; + ScalarParam nr_y; + + LPEConstructGrid(const LPEConstructGrid&); + LPEConstructGrid& operator=(const LPEConstructGrid&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif // INKSCAPE_LPE_CONSTRUCTGRID_H -- 2.30.2