Code

New LPE to draw infinite lines (cut by a limiting bounding box), rays and segments
authorcilix42 <cilix42@users.sourceforge.net>
Mon, 18 Aug 2008 00:32:26 +0000 (00:32 +0000)
committercilix42 <cilix42@users.sourceforge.net>
Mon, 18 Aug 2008 00:32:26 +0000 (00:32 +0000)
src/live_effects/Makefile_insert
src/live_effects/effect.cpp
src/live_effects/effect.h
src/live_effects/lpe-line_segment.cpp [new file with mode: 0644]
src/live_effects/lpe-line_segment.h [new file with mode: 0644]

index 85f58d06dc3181fbdbd353cec8991f7a06374e32..3b136d20407773fd90f57ff07ed07c1c2db7e6fa 100644 (file)
@@ -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
index 64653863b927a402cf8349c70c12323d40d777e0..3f12345ae2af7e736e8c57651302fb675574849b 100644 (file)
@@ -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<EffectType> 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<Effect*> ( new LPEPathLength(lpeobj) );
             break;
+        case LINE_SEGMENT:
+            neweffect = static_cast<Effect*> ( new LPELineSegment(lpeobj) );
+            break;
         default:
             g_warning("LivePathEffect::Effect::New   called with invalid patheffect type (%d)", lpenr);
             neweffect = NULL;
index 51ca6a558422bcb6727417804022efafbcf39a3d..c01cab5c384a45714154b553d8f2c9d1e1a28193 100644 (file)
@@ -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 (file)
index 0000000..7c1cb9f
--- /dev/null
@@ -0,0 +1,103 @@
+#define INKSCAPE_LPE_LINE_SEGMENT_CPP
+
+/** \file
+ * LPE <line_segment> implementation
+ */
+
+/*
+ * Authors:
+ *   Maximilian Albert
+ *
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * 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<EndType> 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<EndType> 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<Parameter *>(&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<Geom::Path>
+LPELineSegment::doEffect_path (std::vector<Geom::Path> const & path_in)
+{
+    std::vector<Geom::Path> 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<Geom::Point> 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<Geom::LineSegment>(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 (file)
index 0000000..ffd9331
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef INKSCAPE_LPE_LINE_SEGMENT_H
+#define INKSCAPE_LPE_LINE_SEGMENT_H
+
+/** \file
+ * LPE <line_segment> implementation
+ */
+
+/*
+ * Authors:
+ *   Maximilian Albert
+ *
+ * Copyright (C) Maximilian Albert 2008 <maximilian.albert@gmail.com>
+ *
+ * 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<Geom::Path> doEffect_path (std::vector<Geom::Path> const & path_in);
+
+private:
+    EnumParam<EndType> 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 :