From: cilix42 Date: Mon, 18 Aug 2008 00:32:26 +0000 (+0000) Subject: New LPE to draw infinite lines (cut by a limiting bounding box), rays and segments X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3515994554d167522343ce57417648b39370ccab;p=inkscape.git New LPE to draw infinite lines (cut by a limiting bounding box), rays and segments --- diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index 85f58d06d..3b136d204 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -72,4 +72,6 @@ live_effects_liblive_effects_a_SOURCES = \ live_effects/lpe-text_label.cpp \ live_effects/lpe-text_label.h \ live_effects/lpe-path_length.cpp \ - live_effects/lpe-path_length.h + live_effects/lpe-path_length.h \ + live_effects/lpe-line_segment.cpp \ + live_effects/lpe-line_segment.h diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 64653863b..3f12345ae 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -64,6 +64,7 @@ #include "live_effects/lpe-interpolate.h" #include "live_effects/lpe-text_label.h" #include "live_effects/lpe-path_length.h" +#include "live_effects/lpe-line_segment.h" // end of includes namespace Inkscape { @@ -87,6 +88,7 @@ const Util::EnumData LPETypeData[] = { {INTERPOLATE, N_("Interpolate Sub-Paths"), "interpolate"}, {KNOT, N_("Knot"), "knot"}, {LATTICE, N_("Lattice Deformation"), "lattice"}, + {LINE_SEGMENT, N_("Line Segment"), "line_segment"}, {MIRROR_SYMMETRY, N_("Mirror symmetry"), "mirror_symmetry"}, {OFFSET, N_("Offset"), "offset"}, {PARALLEL, N_("Parallel"), "parallel"}, @@ -196,6 +198,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case PATH_LENGTH: neweffect = static_cast ( new LPEPathLength(lpeobj) ); break; + case LINE_SEGMENT: + neweffect = static_cast ( new LPELineSegment(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 51ca6a558..c01cab5c3 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -80,6 +80,7 @@ enum EffectType { INTERPOLATE, TEXT_LABEL, PATH_LENGTH, + LINE_SEGMENT, INVALID_LPE // This must be last }; diff --git a/src/live_effects/lpe-line_segment.cpp b/src/live_effects/lpe-line_segment.cpp new file mode 100644 index 000000000..7c1cb9f3e --- /dev/null +++ b/src/live_effects/lpe-line_segment.cpp @@ -0,0 +1,103 @@ +#define INKSCAPE_LPE_LINE_SEGMENT_CPP + +/** \file + * LPE implementation + */ + +/* + * Authors: + * Maximilian Albert + * + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-line_segment.h" + +#include <2geom/pathvector.h> +#include <2geom/geom.h> +#include <2geom/bezier-curve.h> + +namespace Inkscape { +namespace LivePathEffect { + +static const Util::EnumData EndTypeData[] = { + {END_CLOSED , N_("Closed"), "closed"}, + {END_OPEN_LEFT , N_("Open left"), "open_left"}, + {END_OPEN_RIGHT , N_("Open right"), "open_right"}, + {END_OPEN_BOTH , N_("Open both"), "open_both"}, +}; +static const Util::EnumDataConverter EndTypeConverter(EndTypeData, sizeof(EndTypeData)/sizeof(*EndTypeData)); + +LPELineSegment::LPELineSegment(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + end_type(_("End type"), _("Determines on which side the line or line segment is infinite."), "end_type", EndTypeConverter, &wr, this, END_OPEN_BOTH) +{ + /* register all your parameters here, so Inkscape knows which parameters this effect has: */ + registerParameter( dynamic_cast(&end_type) ); +} + +LPELineSegment::~LPELineSegment() +{ + +} + +void +LPELineSegment::doBeforeEffect (SPLPEItem *lpeitem) +{ + SPDocument *document = SP_OBJECT_DOCUMENT(lpeitem); + w = sp_document_width(document); + h = sp_document_height(document); + +} + +std::vector +LPELineSegment::doEffect_path (std::vector const & path_in) +{ + std::vector output; + + A = Geom::initialPoint(path_in); + B = Geom::finalPoint(path_in); + + Geom::Point E(0,0); + Geom::Point F(0,h); + Geom::Point G(w,h); + Geom::Point H(w,0); + + std::vector intersections = Geom::rect_line_intersect(E, G, A, B); + + if (intersections.size() < 2) { + g_print ("Possible error - no intersection with limiting bounding box.\n"); + return path_in; + } + + if (end_type == END_OPEN_RIGHT || end_type == END_OPEN_BOTH) { + A = intersections[0]; + } + + if (end_type == END_OPEN_LEFT || end_type == END_OPEN_BOTH) { + B = intersections[1]; + } + + Geom::Path path(A); + path.appendNew(B); + + output.push_back(path); + + 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-line_segment.h b/src/live_effects/lpe-line_segment.h new file mode 100644 index 000000000..ffd93317a --- /dev/null +++ b/src/live_effects/lpe-line_segment.h @@ -0,0 +1,63 @@ +#ifndef INKSCAPE_LPE_LINE_SEGMENT_H +#define INKSCAPE_LPE_LINE_SEGMENT_H + +/** \file + * LPE implementation + */ + +/* + * Authors: + * Maximilian Albert + * + * Copyright (C) Maximilian Albert 2008 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/enum.h" + +namespace Inkscape { +namespace LivePathEffect { + +enum EndType { + END_CLOSED, + END_OPEN_LEFT, + END_OPEN_RIGHT, + END_OPEN_BOTH +}; + +class LPELineSegment : public Effect { +public: + LPELineSegment(LivePathEffectObject *lpeobject); + virtual ~LPELineSegment(); + + virtual void doBeforeEffect (SPLPEItem *lpeitem); + + virtual std::vector doEffect_path (std::vector const & path_in); + +private: + EnumParam end_type; + + Geom::Point A, B; // intersections of the line segment with the limiting bounding box + Geom::Coord w, h; // document width and height + + LPELineSegment(const LPELineSegment&); + LPELineSegment& operator=(const LPELineSegment&); +}; + +} //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 :