diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2007-08-29 22:36:46 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2007-08-29 22:36:46 +0000 |
| commit | 0b4b6cf7cdf14a64844186ea1e22ef6a0dba42bb (patch) | |
| tree | 045ce745d261eeb22875310393ff32dc59beff0e | |
| parent | Dockable dialogs patch applied (diff) | |
| download | inkscape-0b4b6cf7cdf14a64844186ea1e22ef6a0dba42bb.tar.gz inkscape-0b4b6cf7cdf14a64844186ea1e22ef6a0dba42bb.zip | |
LPE:
- rename RealParam to ScalarParam, add range checking for ScalarParam, add integer only flag for it aswell.
- fix up todo.txt and create new one for parameters
- add Curve Stitch LPE
(bzr r3614)
| -rw-r--r-- | po/POTFILES.in | 1 | ||||
| -rw-r--r-- | src/live_effects/Makefile_insert | 2 | ||||
| -rw-r--r-- | src/live_effects/effect.cpp | 7 | ||||
| -rw-r--r-- | src/live_effects/effect.h | 1 | ||||
| -rw-r--r-- | src/live_effects/lpe-curvestitch.cpp | 106 | ||||
| -rw-r--r-- | src/live_effects/lpe-curvestitch.h | 44 | ||||
| -rw-r--r-- | src/live_effects/lpe-gears.h | 4 | ||||
| -rw-r--r-- | src/live_effects/lpe-skeleton.h | 2 | ||||
| -rw-r--r-- | src/live_effects/lpe-slant.h | 2 | ||||
| -rw-r--r-- | src/live_effects/lpe-test-doEffect-stack.h | 2 | ||||
| -rw-r--r-- | src/live_effects/parameter/parameter.cpp | 49 | ||||
| -rw-r--r-- | src/live_effects/parameter/parameter.h | 16 | ||||
| -rw-r--r-- | src/live_effects/parameter/todo.txt | 9 | ||||
| -rw-r--r-- | src/live_effects/todo.txt | 6 |
14 files changed, 225 insertions, 26 deletions
diff --git a/po/POTFILES.in b/po/POTFILES.in index 66779dc35..cb6a92487 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -265,6 +265,7 @@ src/livarot/ShapeSweep.cpp src/live_effects/effect.cpp src/live_effects/parameter/enum.h src/live_effects/lpe-gears.cpp +src/live_effects/lpe-curvestitch.cpp src/live_effects/lpe-skeletalstrokes.cpp src/live_effects/parameter/parameter.cpp src/live_effects/parameter/path.cpp diff --git a/src/live_effects/Makefile_insert b/src/live_effects/Makefile_insert index f285416e2..fcce5721e 100644 --- a/src/live_effects/Makefile_insert +++ b/src/live_effects/Makefile_insert @@ -16,6 +16,8 @@ live_effects_liblive_effects_a_SOURCES = \ live_effects/n-art-bpath-2geom.h \
live_effects/lpe-skeletalstrokes.cpp \
live_effects/lpe-skeletalstrokes.h \
+ live_effects/lpe-curvestitch.cpp \
+ live_effects/lpe-curvestitch.h \
live_effects/lpe-gears.cpp \
live_effects/lpe-gears.h \
live_effects/lpe-test-doEffect-stack.cpp \
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index a7f4d5781..d13de7f9e 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -30,6 +30,7 @@ #include "live_effects/lpe-slant.h"
#include "live_effects/lpe-test-doEffect-stack.h"
#include "live_effects/lpe-gears.h"
+#include "live_effects/lpe-curvestitch.h"
namespace Inkscape {
@@ -42,7 +43,8 @@ const Util::EnumData<EffectType> LPETypeData[INVALID_LPE] = { {SLANT, _("Slant"), "slant"},
{DOEFFECTSTACK_TEST, _("doEffect stack test"), "doeffectstacktest"},
#endif
- {GEARS, _("Gears"), "gears"}
+ {GEARS, _("Gears"), "gears"},
+ {CURVE_STITCH, _("Curve stitching"), "curvestitching"},
};
const Util::EnumDataConverter<EffectType> LPETypeConverter(LPETypeData, INVALID_LPE);
@@ -65,6 +67,9 @@ Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) case GEARS:
neweffect = (Effect*) new LPEGears(lpeobj);
break;
+ case CURVE_STITCH:
+ neweffect = (Effect*) new LPECurveStitch(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 37e87a7a6..f3c415269 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -47,6 +47,7 @@ enum EffectType { DOEFFECTSTACK_TEST,
#endif
GEARS,
+ CURVE_STITCH,
INVALID_LPE // This must be last
};
diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp new file mode 100644 index 000000000..1769a40a1 --- /dev/null +++ b/src/live_effects/lpe-curvestitch.cpp @@ -0,0 +1,106 @@ +#define INKSCAPE_LPE_EXPRESSION_CPP
+/** \file
+ * SVG <skeleton> implementation, used as an example for a base starting class
+ * when implementing new LivePathEffects.
+ *
+ */
+/*
+ * Authors:
+ * Johan Engelen
+*
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/lpe-curvestitch.h"
+#include "display/curve.h"
+#include <libnr/n-art-bpath.h>
+
+#include <2geom/path.h>
+#include <2geom/piecewise.h>
+#include <2geom/sbasis.h>
+#include <2geom/sbasis-geometric.h>
+#include <2geom/bezier-to-sbasis.h>
+#include <2geom/sbasis-to-bezier.h>
+#include <2geom/d2.h>
+
+#include "ui/widget/scalar.h"
+#include "libnr/nr-values.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+using namespace Geom;
+
+LPECurveStitch::LPECurveStitch(LivePathEffectObject *lpeobject) :
+ Effect(lpeobject),
+ strokepath(_("Stroke path"), _("The path that will be stroked, whatever, think of good text here."), "strokepath", &wr, this, "M0,0 L1,1"),
+ nrofpaths(_("Nr of paths"), _("The number of paths that will be generated."), "count", &wr, this, 5),
+ startpoint_variation(_("Startpoint variation"), _("..."), "startpoint_variation", &wr, this, 0),
+ endpoint_variation(_("Endpoint variation"), _("..."), "endpoint_variation", &wr, this, 0)
+{
+ registerParameter( dynamic_cast<Parameter *>(&nrofpaths) );
+// registerParameter( dynamic_cast<Parameter *>(&startpoint_variation) );
+// registerParameter( dynamic_cast<Parameter *>(&endpoint_variation) );
+
+ nrofpaths.param_make_integer();
+ nrofpaths.param_set_range(2, NR_HUGE);
+
+// startpoint_variation.param_set_range(-NR_HUGE, 1);
+// endpoint_variation.param_set_range(-1, NR_HUGE);
+}
+
+LPECurveStitch::~LPECurveStitch()
+{
+
+}
+
+std::vector<Geom::Path>
+LPECurveStitch::doEffect (std::vector<Geom::Path> & path_in)
+{
+ if (path_in.size() >= 2) {
+ std::vector<Geom::Path> path_out (nrofpaths);
+
+ // do this for all permutations if there are more than 2 paths? realllly cool!
+ Piecewise<D2<SBasis> > A = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[0].toPwSb()),2,.1);
+ Piecewise<D2<SBasis> > B = arc_length_parametrization(Piecewise<D2<SBasis> >(path_in[1].toPwSb()),2,.1);
+ Interval bndsA = A.domain();
+ Interval bndsB = B.domain();
+ gdouble incrementA = (bndsA.max()-bndsA.min()) / (nrofpaths-1);
+ gdouble incrementB = (bndsB.max()-bndsB.min()) / (nrofpaths-1);
+ gdouble tA = bndsA.min();
+ gdouble tB = bndsB.min();
+ for (int i = 0; i < nrofpaths; i++) {
+ Point start = A(tA);
+ Point end = B(tB);
+ if (startpoint_variation != 0)
+ start = start + g_random_double_range(0, startpoint_variation) * (end - start);
+ if (endpoint_variation != 0)
+ end = end + g_random_double_range(0, endpoint_variation) * (end - start);
+
+ path_out[i].start( start );
+ path_out[i].appendNew<LineSegment>( end );
+ tA += incrementA;
+ tB += incrementB;
+ }
+
+ return path_out;
+ } else {
+ return path_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-curvestitch.h b/src/live_effects/lpe-curvestitch.h new file mode 100644 index 000000000..1853e378f --- /dev/null +++ b/src/live_effects/lpe-curvestitch.h @@ -0,0 +1,44 @@ +#ifndef INKSCAPE_LPE_EXPRESSION_H
+#define INKSCAPE_LPE_EXPRESSION_H
+
+/** \file
+ * Implementation of an effect similar to Expression, see lpe-expression.cpp
+ */
+
+/*
+ * Authors:
+ * Johan Engelen
+*
+* Copyright (C) Johan Engelen 2007 <j.b.c.engelen@utwente.nl>
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "live_effects/effect.h"
+#include "live_effects/parameter/path.h"
+#include "live_effects/parameter/parameter.h"
+
+namespace Inkscape {
+namespace LivePathEffect {
+
+class LPECurveStitch : public Effect {
+public:
+ LPECurveStitch(LivePathEffectObject *lpeobject);
+ ~LPECurveStitch();
+
+ std::vector<Geom::Path> doEffect (std::vector<Geom::Path> & path_in);
+
+private:
+ PathParam strokepath;
+ ScalarParam nrofpaths;
+ ScalarParam startpoint_variation;
+ ScalarParam endpoint_variation;
+
+ LPECurveStitch(const LPECurveStitch&);
+ LPECurveStitch& operator=(const LPECurveStitch&);
+};
+
+} //namespace LivePathEffect
+} //namespace Inkscape
+
+#endif
diff --git a/src/live_effects/lpe-gears.h b/src/live_effects/lpe-gears.h index 81a4ef058..b43fbd95e 100644 --- a/src/live_effects/lpe-gears.h +++ b/src/live_effects/lpe-gears.h @@ -25,8 +25,8 @@ public: std::vector<Geom::Path> doEffect (std::vector<Geom::Path> & path_in);
private:
- RealParam teeth;
- RealParam phi;
+ ScalarParam teeth;
+ ScalarParam phi;
LPEGears(const LPEGears&);
LPEGears& operator=(const LPEGears&);
diff --git a/src/live_effects/lpe-skeleton.h b/src/live_effects/lpe-skeleton.h index cefbf0a0b..cce9bde3e 100644 --- a/src/live_effects/lpe-skeleton.h +++ b/src/live_effects/lpe-skeleton.h @@ -34,7 +34,7 @@ public: private:
// add the parameters for your effect here:
- RealParam number;
+ ScalarParam number;
// there are all kinds of parameters. Check the /live_effects/parameter directory which types exist!
LPESkeleton(const LPESkeleton&);
diff --git a/src/live_effects/lpe-slant.h b/src/live_effects/lpe-slant.h index 95d4420fa..1f3ebcdb9 100644 --- a/src/live_effects/lpe-slant.h +++ b/src/live_effects/lpe-slant.h @@ -27,7 +27,7 @@ public: void doEffect(SPCurve * curve);
private:
- RealParam factor;
+ ScalarParam factor;
PointParam center;
LPESlant(const LPESlant&);
diff --git a/src/live_effects/lpe-test-doEffect-stack.h b/src/live_effects/lpe-test-doEffect-stack.h index 57748f503..5e990868e 100644 --- a/src/live_effects/lpe-test-doEffect-stack.h +++ b/src/live_effects/lpe-test-doEffect-stack.h @@ -30,7 +30,7 @@ public: Geom::Piecewise<Geom::D2<Geom::SBasis> > doEffect (Geom::Piecewise<Geom::D2<Geom::SBasis> > & pwd2_in);
private:
- RealParam step;
+ ScalarParam step;
LPEdoEffectStackTest(const LPEdoEffectStackTest&);
LPEdoEffectStackTest& operator=(const LPEdoEffectStackTest&);
diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index 91df62e81..42dd21995 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -9,6 +9,7 @@ #include "live_effects/parameter/parameter.h"
#include "live_effects/effect.h"
#include "svg/svg.h"
+#include "libnr/nr-values.h"
#include <gtkmm.h>
#include "ui/widget/scalar.h"
@@ -40,24 +41,27 @@ Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip, /*###########################################
* REAL PARAM
*/
-RealParam::RealParam( const Glib::ustring& label, const Glib::ustring& tip,
+ScalarParam::ScalarParam( const Glib::ustring& label, const Glib::ustring& tip,
const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr,
Effect* effect, gdouble default_value)
: Parameter(label, tip, key, wr, effect)
{
defvalue = default_value;
value = defvalue;
+ min = -NR_HUGE;
+ max = NR_HUGE;
+ integer = false;
rsu = NULL;
}
-RealParam::~RealParam()
+ScalarParam::~ScalarParam()
{
if (rsu)
delete rsu;
}
bool
-RealParam::param_readSVGValue(const gchar * strvalue)
+ScalarParam::param_readSVGValue(const gchar * strvalue)
{
double newval;
unsigned int success = sp_svg_number_read_d(strvalue, &newval);
@@ -69,7 +73,7 @@ RealParam::param_readSVGValue(const gchar * strvalue) }
gchar *
-RealParam::param_writeSVGValue() const
+ScalarParam::param_writeSVGValue() const
{
Inkscape::SVGOStringStream os;
os << value;
@@ -78,27 +82,57 @@ RealParam::param_writeSVGValue() const }
void
-RealParam::param_set_default()
+ScalarParam::param_set_default()
{
param_set_value(defvalue);
}
void
-RealParam::param_set_value(gdouble val)
+ScalarParam::param_set_value(gdouble val)
{
value = val;
+ if (integer)
+ value = round(value);
+ if (value > max)
+ value = max;
+ if (value < min)
+ value = min;
+
if (rsu)
rsu->setValue(value);
}
+void
+ScalarParam::param_set_range(gdouble min, gdouble max)
+{
+ this->min = min;
+ this->max = max;
+ if (rsu)
+ rsu->getS()->setRange(min, max);
+
+ param_set_value(value);
+}
+
+void
+ScalarParam::param_make_integer(bool yes)
+{
+ integer = yes;
+ if (rsu) {
+ rsu->getS()->setDigits(0);
+ rsu->getS()->setIncrements(1, 10);
+ }
+}
Gtk::Widget *
-RealParam::param_getWidget()
+ScalarParam::param_getWidget()
{
if (!rsu) {
rsu = new Inkscape::UI::Widget::RegisteredScalar();
rsu->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc());
rsu->setValue(value);
+ if (integer)
+ param_make_integer();
+
rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter"));
}
return dynamic_cast<Gtk::Widget *> (rsu->getS());
@@ -106,7 +140,6 @@ RealParam::param_getWidget() } /* namespace LivePathEffect */
-
} /* namespace Inkscape */
/*
diff --git a/src/live_effects/parameter/parameter.h b/src/live_effects/parameter/parameter.h index 942def5b8..d8659600a 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -60,21 +60,23 @@ private: };
-class RealParam : public Parameter {
+class ScalarParam : public Parameter {
public:
- RealParam( const Glib::ustring& label,
+ ScalarParam( const Glib::ustring& label,
const Glib::ustring& tip,
const Glib::ustring& key,
Inkscape::UI::Widget::Registry* wr,
Effect* effect,
gdouble default_value = 1.0);
- ~RealParam();
+ ~ScalarParam();
bool param_readSVGValue(const gchar * strvalue);
gchar * param_writeSVGValue() const;
void param_set_default();
void param_set_value(gdouble val);
+ void param_make_integer(bool yes = true);
+ void param_set_range(gdouble min, gdouble max);
Gtk::Widget * param_getWidget();
@@ -82,15 +84,17 @@ public: { return value; };
private:
- RealParam(const RealParam&);
- RealParam& operator=(const RealParam&);
+ ScalarParam(const ScalarParam&);
+ ScalarParam& operator=(const ScalarParam&);
gdouble value;
+ gdouble min;
+ gdouble max;
+ bool integer;
gdouble defvalue;
Inkscape::UI::Widget::RegisteredScalar * rsu;
};
-
} //namespace LivePathEffect
} //namespace Inkscape
diff --git a/src/live_effects/parameter/todo.txt b/src/live_effects/parameter/todo.txt new file mode 100644 index 000000000..f1a1b4220 --- /dev/null +++ b/src/live_effects/parameter/todo.txt @@ -0,0 +1,9 @@ +reminder list
+
+- make robust
+For example, the spinbuttons for scalarparam can "hang" which is very very very annoying.
+
+- add more types!
+straightlinepaths: for example for the gears effect. (curves are not important there)
+random number: it must also store the random number generator seed!!!
+
diff --git a/src/live_effects/todo.txt b/src/live_effects/todo.txt index 87bafe4a1..51a7a3c21 100644 --- a/src/live_effects/todo.txt +++ b/src/live_effects/todo.txt @@ -9,11 +9,5 @@ ARCS !!! see sp_arc_set_elliptical_path_attribute(SPArc *arc, Inkscape::XML::No make sp_nodepath_is_over_stroke perhaps
-Parameters:
-- make robust (?)
-- add range checking etc
-- add more types! (straightlinepath, enum, bool)
-- -->> add write to svg functionality (for lpeobject->write)
-
find dir "fixme" and fix'em!
\ No newline at end of file |
