From f07bfd5a05d43a6d11f7cd442f085149092dea88 Mon Sep 17 00:00:00 2001 From: pjrm Date: Thu, 11 Oct 2007 14:30:52 +0000 Subject: [PATCH] trivial: live_effects/**: svn propset svn:eol-style native *.h *.cpp. --- src/live_effects/effect.cpp | 560 ++++++------- src/live_effects/effect.h | 224 ++--- src/live_effects/lpe-curvestitch.cpp | 270 +++--- src/live_effects/lpe-curvestitch.h | 96 +-- src/live_effects/lpe-gears.cpp | 532 ++++++------ src/live_effects/lpe-gears.h | 76 +- src/live_effects/lpe-skeletalstrokes.cpp | 338 ++++---- src/live_effects/lpe-skeletalstrokes.h | 108 +-- src/live_effects/lpe-skeleton.cpp | 218 ++--- src/live_effects/lpe-skeleton.h | 94 +-- src/live_effects/lpe-slant.cpp | 110 +-- src/live_effects/lpe-slant.h | 80 +- src/live_effects/lpe-test-doEffect-stack.cpp | 192 ++--- src/live_effects/lpe-test-doEffect-stack.h | 84 +- src/live_effects/lpeobject-reference.cpp | 322 +++---- src/live_effects/lpeobject-reference.h | 142 ++-- src/live_effects/lpeobject.cpp | 528 ++++++------ src/live_effects/lpeobject.h | 104 +-- src/live_effects/n-art-bpath-2geom.cpp | 830 +++++++++---------- src/live_effects/n-art-bpath-2geom.h | 66 +- src/live_effects/parameter/bool.cpp | 186 ++--- src/live_effects/parameter/bool.h | 118 +-- src/live_effects/parameter/enum.h | 202 ++--- src/live_effects/parameter/parameter.cpp | 362 ++++---- src/live_effects/parameter/parameter.h | 216 ++--- src/live_effects/parameter/path.cpp | 364 ++++---- src/live_effects/parameter/path.h | 132 +-- src/live_effects/parameter/point.cpp | 346 ++++---- src/live_effects/parameter/point.h | 130 +-- src/live_effects/parameter/random.cpp | 388 ++++----- src/live_effects/parameter/random.h | 152 ++-- 31 files changed, 3785 insertions(+), 3785 deletions(-) diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index 0773363dd..1c0f5318f 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -1,280 +1,280 @@ -#define INKSCAPE_LIVEPATHEFFECT_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "display/display-forward.h" -#include "xml/node-event-vector.h" -#include "sp-object.h" -#include "attributes.h" -#include "message-stack.h" -#include "desktop.h" -#include "inkscape.h" -#include "document.h" -#include - -#include "live_effects/effect.h" -#include "live_effects/lpeobject.h" -#include "live_effects/parameter/parameter.h" -#include -#include "live_effects/n-art-bpath-2geom.h" -#include "display/curve.h" -#include <2geom/sbasis-to-bezier.h> -#include - -#include - -// include effects: -#include "live_effects/lpe-skeletalstrokes.h" -#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 { - -namespace LivePathEffect { - -const Util::EnumData LPETypeData[INVALID_LPE] = { - // {constant defined in effect.h, N_("name of your effect"), "name of your effect in SVG"} - {SKELETAL_STROKES, N_("Path along path"), "skeletal"}, -#ifdef LPE_ENABLE_TEST_EFFECTS - {SLANT, N_("Slant"), "slant"}, - {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, -#endif - {GEARS, N_("Gears"), "gears"}, - {CURVE_STITCH, N_("Curve stitching"), "curvestitching"}, -}; -const Util::EnumDataConverter LPETypeConverter(LPETypeData, INVALID_LPE); - -Effect* -Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) -{ - Effect* neweffect = NULL; - switch (lpenr) { - case SKELETAL_STROKES: - neweffect = (Effect*) new LPESkeletalStrokes(lpeobj); - break; -#ifdef LPE_ENABLE_TEST_EFFECTS - case SLANT: - neweffect = (Effect*) new LPESlant(lpeobj); - break; - case DOEFFECTSTACK_TEST: - neweffect = (Effect*) new LPEdoEffectStackTest(lpeobj); - break; -#endif - 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; - break; - } - - if (neweffect) { - neweffect->readallParameters(SP_OBJECT_REPR(lpeobj)); - } - - return neweffect; -} - -Effect::Effect(LivePathEffectObject *lpeobject) -{ - vbox = NULL; - tooltips = NULL; - lpeobj = lpeobject; -} - -Effect::~Effect() -{ - if (tooltips) { - delete tooltips; - } -} - -Glib::ustring -Effect::getName() -{ - if (lpeobj->effecttype_set && lpeobj->effecttype < INVALID_LPE) - return Glib::ustring( _(LPETypeConverter.get_label(lpeobj->effecttype).c_str()) ); - else - return Glib::ustring( _("No effect") ); -} - -/* - * Here be the doEffect function chain: - */ -void -Effect::doEffect (SPCurve * curve) -{ - NArtBpath *new_bpath = doEffect(SP_CURVE_BPATH(curve)); - - if (new_bpath && new_bpath != SP_CURVE_BPATH(curve)) { // FIXME, add function to SPCurve to change bpath? or a copy function? - if (curve->_bpath) { - g_free(curve->_bpath); //delete old bpath - } - curve->_bpath = new_bpath; - } -} - -NArtBpath * -Effect::doEffect (NArtBpath * path_in) -{ - try { - std::vector orig_pathv = BPath_to_2GeomPath(path_in); - - std::vector result_pathv = doEffect(orig_pathv); - - NArtBpath *new_bpath = BPath_from_2GeomPath(result_pathv); - - return new_bpath; - } - catch (std::exception e) { - g_warning("An exception occurred during execution of an LPE - %s", e.what()); - SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE, - _("An exception occurred during execution of a Path Effect.") ); - - NArtBpath *path_out; - - unsigned ret = 0; - while ( path_in[ret].code != NR_END ) { - ++ret; - } - unsigned len = ++ret; - - path_out = g_new(NArtBpath, len); - memcpy(path_out, path_in, len * sizeof(NArtBpath)); - return path_out; - } -} - -std::vector -Effect::doEffect (std::vector & path_in) -{ - Geom::Piecewise > pwd2_in; - - for (unsigned int i=0; i < path_in.size(); i++) { - pwd2_in.concat( path_in[i].toPwSb() ); - } - - Geom::Piecewise > pwd2_out = doEffect(pwd2_in); - - std::vector path_out = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); - - return path_out; -} - -Geom::Piecewise > -Effect::doEffect (Geom::Piecewise > & pwd2_in) -{ - g_warning("Effect has no doEffect implementation"); - return pwd2_in; -} - -void -Effect::readallParameters(Inkscape::XML::Node * repr) -{ - param_map_type::iterator it = param_map.begin(); - while (it != param_map.end()) { - const gchar * key = (*it).first.c_str(); - const gchar * value = repr->attribute(key); - if(value) { - setParameter(repr, key, NULL, value); - } - it++; - } -} - -void -Effect::setParameter(Inkscape::XML::Node * repr, const gchar * key, const gchar * old_value, const gchar * new_value) -{ - Glib::ustring stringkey(key); - - param_map_type::iterator it = param_map.find(stringkey); - if (it != param_map.end()) { - if (new_value) { - bool accepted = it->second->param_readSVGValue(new_value); - if (!accepted) { - g_warning("Effect::setParameter - '%s' not accepted for %s", new_value, key); - // change was not accepted, so change it back. - // think: can this backfire and create infinite loop when started with unacceptable old_value? - // repr->setAttribute(key, old_value); - } - } else { - // set default value - it->second->param_set_default(); - } - } -} - -void -Effect::registerParameter(Parameter * param) -{ - param_map[param->param_key] = param; // inserts or updates -} - -Gtk::Widget * -Effect::getWidget() -{ - if (!vbox) { - vbox = Gtk::manage( new Gtk::VBox() ); // use manage here, because after deletion of Effect object, others might still be pointing to this widget. - //if (!tooltips) - tooltips = new Gtk::Tooltips(); - - vbox->set_border_width(5); - - param_map_type::iterator it = param_map.begin(); - while (it != param_map.end()) { - Parameter * param = it->second; - Gtk::Widget * widg = param->param_getWidget(); - Glib::ustring * tip = param->param_getTooltip(); - if (widg) { - vbox->pack_start(*widg, true, true, 2); - if (tip != NULL) { - tooltips->set_tip(*widg, *tip); - } - } - - it++; - } - } - - return dynamic_cast(vbox); -} - - -Inkscape::XML::Node * -Effect::getRepr() -{ - return SP_OBJECT_REPR(lpeobj); -} - -SPDocument * -Effect::getSPDoc() -{ - if (SP_OBJECT_DOCUMENT(lpeobj) == NULL) g_message("Effect::getSPDoc() returns NULL"); - return SP_OBJECT_DOCUMENT(lpeobj); -} - - -} /* 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 : +#define INKSCAPE_LIVEPATHEFFECT_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "display/display-forward.h" +#include "xml/node-event-vector.h" +#include "sp-object.h" +#include "attributes.h" +#include "message-stack.h" +#include "desktop.h" +#include "inkscape.h" +#include "document.h" +#include + +#include "live_effects/effect.h" +#include "live_effects/lpeobject.h" +#include "live_effects/parameter/parameter.h" +#include +#include "live_effects/n-art-bpath-2geom.h" +#include "display/curve.h" +#include <2geom/sbasis-to-bezier.h> +#include + +#include + +// include effects: +#include "live_effects/lpe-skeletalstrokes.h" +#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 { + +namespace LivePathEffect { + +const Util::EnumData LPETypeData[INVALID_LPE] = { + // {constant defined in effect.h, N_("name of your effect"), "name of your effect in SVG"} + {SKELETAL_STROKES, N_("Path along path"), "skeletal"}, +#ifdef LPE_ENABLE_TEST_EFFECTS + {SLANT, N_("Slant"), "slant"}, + {DOEFFECTSTACK_TEST, N_("doEffect stack test"), "doeffectstacktest"}, +#endif + {GEARS, N_("Gears"), "gears"}, + {CURVE_STITCH, N_("Curve stitching"), "curvestitching"}, +}; +const Util::EnumDataConverter LPETypeConverter(LPETypeData, INVALID_LPE); + +Effect* +Effect::New(EffectType lpenr, LivePathEffectObject *lpeobj) +{ + Effect* neweffect = NULL; + switch (lpenr) { + case SKELETAL_STROKES: + neweffect = (Effect*) new LPESkeletalStrokes(lpeobj); + break; +#ifdef LPE_ENABLE_TEST_EFFECTS + case SLANT: + neweffect = (Effect*) new LPESlant(lpeobj); + break; + case DOEFFECTSTACK_TEST: + neweffect = (Effect*) new LPEdoEffectStackTest(lpeobj); + break; +#endif + 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; + break; + } + + if (neweffect) { + neweffect->readallParameters(SP_OBJECT_REPR(lpeobj)); + } + + return neweffect; +} + +Effect::Effect(LivePathEffectObject *lpeobject) +{ + vbox = NULL; + tooltips = NULL; + lpeobj = lpeobject; +} + +Effect::~Effect() +{ + if (tooltips) { + delete tooltips; + } +} + +Glib::ustring +Effect::getName() +{ + if (lpeobj->effecttype_set && lpeobj->effecttype < INVALID_LPE) + return Glib::ustring( _(LPETypeConverter.get_label(lpeobj->effecttype).c_str()) ); + else + return Glib::ustring( _("No effect") ); +} + +/* + * Here be the doEffect function chain: + */ +void +Effect::doEffect (SPCurve * curve) +{ + NArtBpath *new_bpath = doEffect(SP_CURVE_BPATH(curve)); + + if (new_bpath && new_bpath != SP_CURVE_BPATH(curve)) { // FIXME, add function to SPCurve to change bpath? or a copy function? + if (curve->_bpath) { + g_free(curve->_bpath); //delete old bpath + } + curve->_bpath = new_bpath; + } +} + +NArtBpath * +Effect::doEffect (NArtBpath * path_in) +{ + try { + std::vector orig_pathv = BPath_to_2GeomPath(path_in); + + std::vector result_pathv = doEffect(orig_pathv); + + NArtBpath *new_bpath = BPath_from_2GeomPath(result_pathv); + + return new_bpath; + } + catch (std::exception e) { + g_warning("An exception occurred during execution of an LPE - %s", e.what()); + SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE, + _("An exception occurred during execution of a Path Effect.") ); + + NArtBpath *path_out; + + unsigned ret = 0; + while ( path_in[ret].code != NR_END ) { + ++ret; + } + unsigned len = ++ret; + + path_out = g_new(NArtBpath, len); + memcpy(path_out, path_in, len * sizeof(NArtBpath)); + return path_out; + } +} + +std::vector +Effect::doEffect (std::vector & path_in) +{ + Geom::Piecewise > pwd2_in; + + for (unsigned int i=0; i < path_in.size(); i++) { + pwd2_in.concat( path_in[i].toPwSb() ); + } + + Geom::Piecewise > pwd2_out = doEffect(pwd2_in); + + std::vector path_out = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); + + return path_out; +} + +Geom::Piecewise > +Effect::doEffect (Geom::Piecewise > & pwd2_in) +{ + g_warning("Effect has no doEffect implementation"); + return pwd2_in; +} + +void +Effect::readallParameters(Inkscape::XML::Node * repr) +{ + param_map_type::iterator it = param_map.begin(); + while (it != param_map.end()) { + const gchar * key = (*it).first.c_str(); + const gchar * value = repr->attribute(key); + if(value) { + setParameter(repr, key, NULL, value); + } + it++; + } +} + +void +Effect::setParameter(Inkscape::XML::Node * repr, const gchar * key, const gchar * old_value, const gchar * new_value) +{ + Glib::ustring stringkey(key); + + param_map_type::iterator it = param_map.find(stringkey); + if (it != param_map.end()) { + if (new_value) { + bool accepted = it->second->param_readSVGValue(new_value); + if (!accepted) { + g_warning("Effect::setParameter - '%s' not accepted for %s", new_value, key); + // change was not accepted, so change it back. + // think: can this backfire and create infinite loop when started with unacceptable old_value? + // repr->setAttribute(key, old_value); + } + } else { + // set default value + it->second->param_set_default(); + } + } +} + +void +Effect::registerParameter(Parameter * param) +{ + param_map[param->param_key] = param; // inserts or updates +} + +Gtk::Widget * +Effect::getWidget() +{ + if (!vbox) { + vbox = Gtk::manage( new Gtk::VBox() ); // use manage here, because after deletion of Effect object, others might still be pointing to this widget. + //if (!tooltips) + tooltips = new Gtk::Tooltips(); + + vbox->set_border_width(5); + + param_map_type::iterator it = param_map.begin(); + while (it != param_map.end()) { + Parameter * param = it->second; + Gtk::Widget * widg = param->param_getWidget(); + Glib::ustring * tip = param->param_getTooltip(); + if (widg) { + vbox->pack_start(*widg, true, true, 2); + if (tip != NULL) { + tooltips->set_tip(*widg, *tip); + } + } + + it++; + } + } + + return dynamic_cast(vbox); +} + + +Inkscape::XML::Node * +Effect::getRepr() +{ + return SP_OBJECT_REPR(lpeobj); +} + +SPDocument * +Effect::getSPDoc() +{ + if (SP_OBJECT_DOCUMENT(lpeobj) == NULL) g_message("Effect::getSPDoc() returns NULL"); + return SP_OBJECT_DOCUMENT(lpeobj); +} + + +} /* 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/effect.h b/src/live_effects/effect.h index f3c415269..5169ff22f 100644 --- a/src/live_effects/effect.h +++ b/src/live_effects/effect.h @@ -1,112 +1,112 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_H -#define INKSCAPE_LIVEPATHEFFECT_H - -/* - * Inkscape::LivePathEffect - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -#include "display/display-forward.h" -#include -#include -#include <2geom/path.h> -#include "ui/widget/registry.h" -#include "util/enums.h" - -#define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this. - -//#define LPE_ENABLE_TEST_EFFECTS - -struct SPShape; -struct SPDocument; -class NArtBpath; -struct LivePathEffectObject; - -namespace Gtk { - class Widget; - class VBox; - class Tooltips; -} - -namespace Inkscape { - -namespace XML { - class Node; -} - -namespace LivePathEffect { - -enum EffectType { - SKELETAL_STROKES = 0, -#ifdef LPE_ENABLE_TEST_EFFECTS - SLANT, - DOEFFECTSTACK_TEST, -#endif - GEARS, - CURVE_STITCH, - INVALID_LPE // This must be last -}; - -extern const Util::EnumData LPETypeData[INVALID_LPE]; -extern const Util::EnumDataConverter LPETypeConverter; - -class Parameter; - -class Effect { -public: - virtual ~Effect(); - - Glib::ustring getName(); - - virtual void doEffect (SPCurve * curve); - - static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); - - virtual Gtk::Widget * getWidget(); - - Inkscape::XML::Node * getRepr(); - SPDocument * getSPDoc(); - - void readallParameters(Inkscape::XML::Node * repr); - void setParameter(Inkscape::XML::Node * repr, const gchar * key, const gchar * old_value, const gchar * new_value); - -protected: - Effect(LivePathEffectObject *lpeobject); - - // provide a set of doEffect functions so the developer has a choice - // of what kind of input/output parameters he desires. - // the order in which they appear is the order in which they are - // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling - // doEffect(std::vector ) - virtual NArtBpath * - doEffect (NArtBpath * path_in); - virtual std::vector - doEffect (std::vector & path_in); - virtual Geom::Piecewise > - doEffect (Geom::Piecewise > & pwd2_in); - - void registerParameter(Parameter * param); - - typedef std::map param_map_type; - param_map_type param_map; - - Inkscape::UI::Widget::Registry wr; - Gtk::VBox * vbox; - Gtk::Tooltips * tooltips; - - LivePathEffectObject *lpeobj; - -private: - Effect(const Effect&); - Effect& operator=(const Effect&); -}; - - -} //namespace LivePathEffect -} //namespace Inkscape - -#endif +#ifndef INKSCAPE_LIVEPATHEFFECT_H +#define INKSCAPE_LIVEPATHEFFECT_H + +/* + * Inkscape::LivePathEffect + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "display/display-forward.h" +#include +#include +#include <2geom/path.h> +#include "ui/widget/registry.h" +#include "util/enums.h" + +#define LPE_CONVERSION_TOLERANCE 0.01 // FIXME: find good solution for this. + +//#define LPE_ENABLE_TEST_EFFECTS + +struct SPShape; +struct SPDocument; +class NArtBpath; +struct LivePathEffectObject; + +namespace Gtk { + class Widget; + class VBox; + class Tooltips; +} + +namespace Inkscape { + +namespace XML { + class Node; +} + +namespace LivePathEffect { + +enum EffectType { + SKELETAL_STROKES = 0, +#ifdef LPE_ENABLE_TEST_EFFECTS + SLANT, + DOEFFECTSTACK_TEST, +#endif + GEARS, + CURVE_STITCH, + INVALID_LPE // This must be last +}; + +extern const Util::EnumData LPETypeData[INVALID_LPE]; +extern const Util::EnumDataConverter LPETypeConverter; + +class Parameter; + +class Effect { +public: + virtual ~Effect(); + + Glib::ustring getName(); + + virtual void doEffect (SPCurve * curve); + + static Effect* New(EffectType lpenr, LivePathEffectObject *lpeobj); + + virtual Gtk::Widget * getWidget(); + + Inkscape::XML::Node * getRepr(); + SPDocument * getSPDoc(); + + void readallParameters(Inkscape::XML::Node * repr); + void setParameter(Inkscape::XML::Node * repr, const gchar * key, const gchar * old_value, const gchar * new_value); + +protected: + Effect(LivePathEffectObject *lpeobject); + + // provide a set of doEffect functions so the developer has a choice + // of what kind of input/output parameters he desires. + // the order in which they appear is the order in which they are + // called by this base class. (i.e. doEffect(SPCurve * curve) defaults to calling + // doEffect(std::vector ) + virtual NArtBpath * + doEffect (NArtBpath * path_in); + virtual std::vector + doEffect (std::vector & path_in); + virtual Geom::Piecewise > + doEffect (Geom::Piecewise > & pwd2_in); + + void registerParameter(Parameter * param); + + typedef std::map param_map_type; + param_map_type param_map; + + Inkscape::UI::Widget::Registry wr; + Gtk::VBox * vbox; + Gtk::Tooltips * tooltips; + + LivePathEffectObject *lpeobj; + +private: + Effect(const Effect&); + Effect& operator=(const Effect&); +}; + + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 7368fd55b..c39277727 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -1,135 +1,135 @@ -#define INKSCAPE_LPE_EXPRESSION_CPP -/** \file - * SVG implementation, used as an example for a base starting class - * when implementing new LivePathEffects. - * - */ -/* - * Authors: - * Johan Engelen -* -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/lpe-curvestitch.h" -#include "display/curve.h" -#include - -#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 <2geom/matrix.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,0"), - 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), - prop_scale(_("Scale width"), _("Scaling of the width of the stroke path"), "prop_scale", &wr, this, 1), - scale_y_rel(_("Scale width relative"), _("Scale the width of the stroke path relative to its length"), "scale_y_rel", &wr, this, false) -{ - registerParameter( dynamic_cast(&nrofpaths) ); - registerParameter( dynamic_cast(&startpoint_variation) ); - registerParameter( dynamic_cast(&endpoint_variation) ); - registerParameter( dynamic_cast(&strokepath) ); - registerParameter( dynamic_cast(&prop_scale) ); - registerParameter( dynamic_cast(&scale_y_rel) ); - - nrofpaths.param_make_integer(); - nrofpaths.param_set_range(2, NR_HUGE); - - prop_scale.param_set_digits(3); - prop_scale.param_set_increments(0.01, 0.10); -} - -LPECurveStitch::~LPECurveStitch() -{ - -} - -std::vector -LPECurveStitch::doEffect (std::vector & path_in) -{ - if (path_in.size() >= 2) { - startpoint_variation.resetRandomizer(); - endpoint_variation.resetRandomizer(); - - D2 > stroke = make_cuts_independant(strokepath); - Interval bndsStroke = bounds_exact(stroke[0]); - gdouble scaling = bndsStroke.max() - bndsStroke.min(); - Interval bndsStrokeY = bounds_exact(stroke[1]); - Point stroke_origin(bndsStroke.min(), (bndsStrokeY.max()+bndsStrokeY.min())/2); - - std::vector path_out (nrofpaths); - - // do this for all permutations if there are more than 2 paths? realllly cool! - Piecewise > A = arc_length_parametrization(Piecewise >(path_in[0].toPwSb()),2,.1); - Piecewise > B = arc_length_parametrization(Piecewise >(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.get_value() != 0) - start = start + startpoint_variation * (end - start); - if (endpoint_variation.get_value() != 0) - end = end + endpoint_variation * (end - start); - - gdouble scaling_y = 1.0; - if (scale_y_rel.get_value()) { - scaling_y = (L2(end-start)/scaling)*prop_scale; - } else { - scaling_y = prop_scale; - } - - Matrix transform; - transform.setXAxis( (end-start) / scaling ); - transform.setYAxis( rot90(unit_vector(end-start)) * scaling_y); - transform.setTranslation( start ); - Piecewise > pwd2_out = (strokepath-stroke_origin) * transform; - // add stuff to one big pw > and then outside the loop convert to path? - std::vector result = Geom::path_from_piecewise(pwd2_out, LPE_CONVERSION_TOLERANCE); - path_out[i] = result[0]; - 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 : +#define INKSCAPE_LPE_EXPRESSION_CPP +/** \file + * SVG implementation, used as an example for a base starting class + * when implementing new LivePathEffects. + * + */ +/* + * Authors: + * Johan Engelen +* +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-curvestitch.h" +#include "display/curve.h" +#include + +#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 <2geom/matrix.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,0"), + 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), + prop_scale(_("Scale width"), _("Scaling of the width of the stroke path"), "prop_scale", &wr, this, 1), + scale_y_rel(_("Scale width relative"), _("Scale the width of the stroke path relative to its length"), "scale_y_rel", &wr, this, false) +{ + registerParameter( dynamic_cast(&nrofpaths) ); + registerParameter( dynamic_cast(&startpoint_variation) ); + registerParameter( dynamic_cast(&endpoint_variation) ); + registerParameter( dynamic_cast(&strokepath) ); + registerParameter( dynamic_cast(&prop_scale) ); + registerParameter( dynamic_cast(&scale_y_rel) ); + + nrofpaths.param_make_integer(); + nrofpaths.param_set_range(2, NR_HUGE); + + prop_scale.param_set_digits(3); + prop_scale.param_set_increments(0.01, 0.10); +} + +LPECurveStitch::~LPECurveStitch() +{ + +} + +std::vector +LPECurveStitch::doEffect (std::vector & path_in) +{ + if (path_in.size() >= 2) { + startpoint_variation.resetRandomizer(); + endpoint_variation.resetRandomizer(); + + D2 > stroke = make_cuts_independant(strokepath); + Interval bndsStroke = bounds_exact(stroke[0]); + gdouble scaling = bndsStroke.max() - bndsStroke.min(); + Interval bndsStrokeY = bounds_exact(stroke[1]); + Point stroke_origin(bndsStroke.min(), (bndsStrokeY.max()+bndsStrokeY.min())/2); + + std::vector path_out (nrofpaths); + + // do this for all permutations if there are more than 2 paths? realllly cool! + Piecewise > A = arc_length_parametrization(Piecewise >(path_in[0].toPwSb()),2,.1); + Piecewise > B = arc_length_parametrization(Piecewise >(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.get_value() != 0) + start = start + startpoint_variation * (end - start); + if (endpoint_variation.get_value() != 0) + end = end + endpoint_variation * (end - start); + + gdouble scaling_y = 1.0; + if (scale_y_rel.get_value()) { + scaling_y = (L2(end-start)/scaling)*prop_scale; + } else { + scaling_y = prop_scale; + } + + Matrix transform; + transform.setXAxis( (end-start) / scaling ); + transform.setYAxis( rot90(unit_vector(end-start)) * scaling_y); + transform.setTranslation( start ); + Piecewise > pwd2_out = (strokepath-stroke_origin) * transform; + // add stuff to one big pw > and then outside the loop convert to path? + std::vector result = Geom::path_from_piecewise(pwd2_out, LPE_CONVERSION_TOLERANCE); + path_out[i] = result[0]; + 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 index 25ddb7719..fd41f6849 100644 --- a/src/live_effects/lpe-curvestitch.h +++ b/src/live_effects/lpe-curvestitch.h @@ -1,48 +1,48 @@ -#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 - * - * 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" -#include "live_effects/parameter/bool.h" -#include "live_effects/parameter/random.h" - -namespace Inkscape { -namespace LivePathEffect { - -class LPECurveStitch : public Effect { -public: - LPECurveStitch(LivePathEffectObject *lpeobject); - ~LPECurveStitch(); - - std::vector doEffect (std::vector & path_in); - -private: - PathParam strokepath; - ScalarParam nrofpaths; - RandomParam startpoint_variation; - RandomParam endpoint_variation; - ScalarParam prop_scale; - BoolParam scale_y_rel; - - LPECurveStitch(const LPECurveStitch&); - LPECurveStitch& operator=(const LPECurveStitch&); -}; - -} //namespace LivePathEffect -} //namespace Inkscape - -#endif +#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 + * + * 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" +#include "live_effects/parameter/bool.h" +#include "live_effects/parameter/random.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPECurveStitch : public Effect { +public: + LPECurveStitch(LivePathEffectObject *lpeobject); + ~LPECurveStitch(); + + std::vector doEffect (std::vector & path_in); + +private: + PathParam strokepath; + ScalarParam nrofpaths; + RandomParam startpoint_variation; + RandomParam endpoint_variation; + ScalarParam prop_scale; + BoolParam scale_y_rel; + + LPECurveStitch(const LPECurveStitch&); + LPECurveStitch& operator=(const LPECurveStitch&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-gears.cpp b/src/live_effects/lpe-gears.cpp index 03e19f31c..2176f3ba7 100644 --- a/src/live_effects/lpe-gears.cpp +++ b/src/live_effects/lpe-gears.cpp @@ -1,266 +1,266 @@ -#define INKSCAPE_LPE_DOEFFECT_STACK_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/lpe-gears.h" - -#include -#include <2geom/d2.h> -#include <2geom/sbasis.h> -#include <2geom/bezier-to-sbasis.h> -#include <2geom/path.h> - -using std::vector; -using namespace Geom; - -class Gear { -public: - // pitch circles touch on two properly meshed gears - // all measurements are taken from the pitch circle - double pitch_diameter() {return (_number_of_teeth * _module) / M_PI;} - double pitch_radius() {return pitch_diameter() / 2.0;} - void pitch_radius(double R) {_module = (2 * M_PI * R) / _number_of_teeth;} - - // base circle serves as the basis for the involute toothe profile - double base_diameter() {return pitch_diameter() * cos(_pressure_angle);} - double base_radius() {return base_diameter() / 2.0;} - - // diametrical pitch - double diametrical_pitch() {return _number_of_teeth / pitch_diameter();} - - // height of the tooth above the pitch circle - double addendum() {return 1.0 / diametrical_pitch();} - // depth of the tooth below the pitch circle - double dedendum() {return addendum() + _clearance;} - - // root circle specifies the bottom of the fillet between teeth - double root_radius() {return pitch_radius() - dedendum();} - double root_diameter() {return root_radius() * 2.0;} - - // outer circle is the outside diameter of the gear - double outer_radius() {return pitch_radius() + addendum();} - double outer_diameter() {return outer_radius() * 2.0;} - - // angle covered by the tooth on the pitch circle - double tooth_thickness_angle() {return M_PI / _number_of_teeth;} - - Geom::Point centre() {return _centre;} - void centre(Geom::Point c) {_centre = c;} - - double angle() {return _angle;} - void angle(double a) {_angle = a;} - - int number_of_teeth() {return _number_of_teeth;} - - Geom::Path path(); - Gear spawn(Geom::Point p); - - Gear(int n, double m, double phi) { - _number_of_teeth = n; - _module = m; - _pressure_angle = phi; - _clearance = 0.0; - _angle = 0.0; - _centre = Geom::Point(0.0,0.0); - } -private: - int _number_of_teeth; - double _pressure_angle; - double _module; - double _clearance; - double _angle; - Geom::Point _centre; - D2 _involute(double start, double stop) { - D2 B; - D2 I; - Linear bo = Linear(start,stop); - - B[0] = cos(bo,2); - B[1] = sin(bo,2); - - I = B - Linear(0,1) * derivative(B); - I = I*base_radius() + _centre; - return I; - } - D2 _arc(double start, double stop, double R) { - D2 B; - Linear bo = Linear(start,stop); - - B[0] = cos(bo,2); - B[1] = sin(bo,2); - - B = B*R + _centre; - return B; - } - // angle of the base circle used to create the involute to a certain radius - double involute_swath_angle(double R) { - if (R <= base_radius()) return 0.0; - return sqrt(R*R - base_radius()*base_radius())/base_radius(); - } - - // angle of the base circle between the origin of the involute and the intersection on another radius - double involute_intersect_angle(double R) { - if (R <= base_radius()) return 0.0; - return (sqrt(R*R - base_radius()*base_radius())/base_radius()) - acos(base_radius()/R); - } -}; - -void makeContinuous(D2 &a, Point const b) { - for(unsigned d=0;d<2;d++) - a[d][0][0] = b[d]; -} - -Geom::Path Gear::path() { - Geom::Path pb; - - // angle covered by a full tooth and fillet - double tooth_rotation = 2.0 * tooth_thickness_angle(); - // angle covered by an involute - double involute_advance = involute_intersect_angle(outer_radius()) - involute_intersect_angle(root_radius()); - // angle covered by the tooth tip - double tip_advance = tooth_thickness_angle() - (2 * (involute_intersect_angle(outer_radius()) - involute_intersect_angle(pitch_radius()))); - // angle covered by the toothe root - double root_advance = (tooth_rotation - tip_advance) - (2.0 * involute_advance); - // begin drawing the involute at t if the root circle is larger than the base circle - double involute_t = involute_swath_angle(root_radius())/involute_swath_angle(outer_radius()); - - //rewind angle to start drawing from the leading edge of the tooth - double first_tooth_angle = _angle - ((0.5 * tip_advance) + involute_advance); - - Geom::Point prev; - for (int i=0; i < _number_of_teeth; i++) - { - double cursor = first_tooth_angle + (i * tooth_rotation); - - D2 leading_I = compose(_involute(cursor, cursor + involute_swath_angle(outer_radius())), Linear(involute_t,1)); - if(i != 0) makeContinuous(leading_I, prev); - pb.append(SBasisCurve(leading_I)); - cursor += involute_advance; - prev = leading_I.at1(); - - D2 tip = _arc(cursor, cursor+tip_advance, outer_radius()); - makeContinuous(tip, prev); - pb.append(SBasisCurve(tip)); - cursor += tip_advance; - prev = tip.at1(); - - cursor += involute_advance; - D2 trailing_I = compose(_involute(cursor, cursor - involute_swath_angle(outer_radius())), Linear(1,involute_t)); - makeContinuous(trailing_I, prev); - pb.append(SBasisCurve(trailing_I)); - prev = trailing_I.at1(); - - if (base_radius() > root_radius()) { - Geom::Point leading_start = trailing_I.at1(); - Geom::Point leading_end = (root_radius() * unit_vector(leading_start - _centre)) + _centre; - prev = leading_end; - pb.appendNew(leading_end); - } - - D2 root = _arc(cursor, cursor+root_advance, root_radius()); - makeContinuous(root, prev); - pb.append(SBasisCurve(root)); - cursor += root_advance; - prev = root.at1(); - - if (base_radius() > root_radius()) { - Geom::Point trailing_start = root.at1(); - Geom::Point trailing_end = (base_radius() * unit_vector(trailing_start - _centre)) + _centre; - pb.appendNew(trailing_end); - prev = trailing_end; - } - } - - return pb; -} - -Gear Gear::spawn(Geom::Point p) { - double radius = Geom::distance(this->centre(), p) - this->pitch_radius(); - int N = (int) floor( (radius / this->pitch_radius()) * this->number_of_teeth() ); - - Gear gear(N, _module, _pressure_angle); - gear.centre(p); - - double a = atan2(p - this->centre()); - double new_angle = 0.0; - if (gear.number_of_teeth() % 2 == 0) - new_angle -= gear.tooth_thickness_angle(); - new_angle -= (_angle) * (pitch_radius() / gear.pitch_radius()); - new_angle += (a) * (pitch_radius() / gear.pitch_radius()); - gear.angle(new_angle + a); - return gear; -} - - - -// ################################################################# - - - -namespace Inkscape { -namespace LivePathEffect { - - -LPEGears::LPEGears(LivePathEffectObject *lpeobject) : - Effect(lpeobject), - teeth(_("Teeth"), _("The number of teeth"), "teeth", &wr, this, 10), - phi(_("Phi"), _("???"), "phi", &wr, this, 5) -{ - registerParameter( dynamic_cast(&teeth) ); - registerParameter( dynamic_cast(&phi) ); -} - -LPEGears::~LPEGears() -{ - -} - -std::vector -LPEGears::doEffect (std::vector & path_in) -{ - std::vector path_out; - Geom::Path gearpath = path_in[0]; - - Geom::Path::iterator it(gearpath.begin()); - if ( it == gearpath.end() ) return path_out; - - Gear * gear = new Gear(teeth, 200.0, phi * M_PI / 180); - Geom::Point gear_centre = (*it).finalPoint(); - gear->centre(gear_centre); - gear->angle(atan2((*it).initialPoint() - gear_centre)); - - it++; if ( it == gearpath.end() ) return path_out; - gear->pitch_radius(Geom::distance(gear_centre, (*it).finalPoint())); - - path_out.push_back( gear->path()); - - for (it++ ; it != gearpath.end() ; it++) { - // iterate through Geom::Curve in path_in - Gear* gearnew = new Gear(gear->spawn( (*it).finalPoint() )); - path_out.push_back( gearnew->path() ); - delete gear; - gear = gearnew; - } - delete gear; - - return path_out; -} - - -} // 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 : +#define INKSCAPE_LPE_DOEFFECT_STACK_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-gears.h" + +#include +#include <2geom/d2.h> +#include <2geom/sbasis.h> +#include <2geom/bezier-to-sbasis.h> +#include <2geom/path.h> + +using std::vector; +using namespace Geom; + +class Gear { +public: + // pitch circles touch on two properly meshed gears + // all measurements are taken from the pitch circle + double pitch_diameter() {return (_number_of_teeth * _module) / M_PI;} + double pitch_radius() {return pitch_diameter() / 2.0;} + void pitch_radius(double R) {_module = (2 * M_PI * R) / _number_of_teeth;} + + // base circle serves as the basis for the involute toothe profile + double base_diameter() {return pitch_diameter() * cos(_pressure_angle);} + double base_radius() {return base_diameter() / 2.0;} + + // diametrical pitch + double diametrical_pitch() {return _number_of_teeth / pitch_diameter();} + + // height of the tooth above the pitch circle + double addendum() {return 1.0 / diametrical_pitch();} + // depth of the tooth below the pitch circle + double dedendum() {return addendum() + _clearance;} + + // root circle specifies the bottom of the fillet between teeth + double root_radius() {return pitch_radius() - dedendum();} + double root_diameter() {return root_radius() * 2.0;} + + // outer circle is the outside diameter of the gear + double outer_radius() {return pitch_radius() + addendum();} + double outer_diameter() {return outer_radius() * 2.0;} + + // angle covered by the tooth on the pitch circle + double tooth_thickness_angle() {return M_PI / _number_of_teeth;} + + Geom::Point centre() {return _centre;} + void centre(Geom::Point c) {_centre = c;} + + double angle() {return _angle;} + void angle(double a) {_angle = a;} + + int number_of_teeth() {return _number_of_teeth;} + + Geom::Path path(); + Gear spawn(Geom::Point p); + + Gear(int n, double m, double phi) { + _number_of_teeth = n; + _module = m; + _pressure_angle = phi; + _clearance = 0.0; + _angle = 0.0; + _centre = Geom::Point(0.0,0.0); + } +private: + int _number_of_teeth; + double _pressure_angle; + double _module; + double _clearance; + double _angle; + Geom::Point _centre; + D2 _involute(double start, double stop) { + D2 B; + D2 I; + Linear bo = Linear(start,stop); + + B[0] = cos(bo,2); + B[1] = sin(bo,2); + + I = B - Linear(0,1) * derivative(B); + I = I*base_radius() + _centre; + return I; + } + D2 _arc(double start, double stop, double R) { + D2 B; + Linear bo = Linear(start,stop); + + B[0] = cos(bo,2); + B[1] = sin(bo,2); + + B = B*R + _centre; + return B; + } + // angle of the base circle used to create the involute to a certain radius + double involute_swath_angle(double R) { + if (R <= base_radius()) return 0.0; + return sqrt(R*R - base_radius()*base_radius())/base_radius(); + } + + // angle of the base circle between the origin of the involute and the intersection on another radius + double involute_intersect_angle(double R) { + if (R <= base_radius()) return 0.0; + return (sqrt(R*R - base_radius()*base_radius())/base_radius()) - acos(base_radius()/R); + } +}; + +void makeContinuous(D2 &a, Point const b) { + for(unsigned d=0;d<2;d++) + a[d][0][0] = b[d]; +} + +Geom::Path Gear::path() { + Geom::Path pb; + + // angle covered by a full tooth and fillet + double tooth_rotation = 2.0 * tooth_thickness_angle(); + // angle covered by an involute + double involute_advance = involute_intersect_angle(outer_radius()) - involute_intersect_angle(root_radius()); + // angle covered by the tooth tip + double tip_advance = tooth_thickness_angle() - (2 * (involute_intersect_angle(outer_radius()) - involute_intersect_angle(pitch_radius()))); + // angle covered by the toothe root + double root_advance = (tooth_rotation - tip_advance) - (2.0 * involute_advance); + // begin drawing the involute at t if the root circle is larger than the base circle + double involute_t = involute_swath_angle(root_radius())/involute_swath_angle(outer_radius()); + + //rewind angle to start drawing from the leading edge of the tooth + double first_tooth_angle = _angle - ((0.5 * tip_advance) + involute_advance); + + Geom::Point prev; + for (int i=0; i < _number_of_teeth; i++) + { + double cursor = first_tooth_angle + (i * tooth_rotation); + + D2 leading_I = compose(_involute(cursor, cursor + involute_swath_angle(outer_radius())), Linear(involute_t,1)); + if(i != 0) makeContinuous(leading_I, prev); + pb.append(SBasisCurve(leading_I)); + cursor += involute_advance; + prev = leading_I.at1(); + + D2 tip = _arc(cursor, cursor+tip_advance, outer_radius()); + makeContinuous(tip, prev); + pb.append(SBasisCurve(tip)); + cursor += tip_advance; + prev = tip.at1(); + + cursor += involute_advance; + D2 trailing_I = compose(_involute(cursor, cursor - involute_swath_angle(outer_radius())), Linear(1,involute_t)); + makeContinuous(trailing_I, prev); + pb.append(SBasisCurve(trailing_I)); + prev = trailing_I.at1(); + + if (base_radius() > root_radius()) { + Geom::Point leading_start = trailing_I.at1(); + Geom::Point leading_end = (root_radius() * unit_vector(leading_start - _centre)) + _centre; + prev = leading_end; + pb.appendNew(leading_end); + } + + D2 root = _arc(cursor, cursor+root_advance, root_radius()); + makeContinuous(root, prev); + pb.append(SBasisCurve(root)); + cursor += root_advance; + prev = root.at1(); + + if (base_radius() > root_radius()) { + Geom::Point trailing_start = root.at1(); + Geom::Point trailing_end = (base_radius() * unit_vector(trailing_start - _centre)) + _centre; + pb.appendNew(trailing_end); + prev = trailing_end; + } + } + + return pb; +} + +Gear Gear::spawn(Geom::Point p) { + double radius = Geom::distance(this->centre(), p) - this->pitch_radius(); + int N = (int) floor( (radius / this->pitch_radius()) * this->number_of_teeth() ); + + Gear gear(N, _module, _pressure_angle); + gear.centre(p); + + double a = atan2(p - this->centre()); + double new_angle = 0.0; + if (gear.number_of_teeth() % 2 == 0) + new_angle -= gear.tooth_thickness_angle(); + new_angle -= (_angle) * (pitch_radius() / gear.pitch_radius()); + new_angle += (a) * (pitch_radius() / gear.pitch_radius()); + gear.angle(new_angle + a); + return gear; +} + + + +// ################################################################# + + + +namespace Inkscape { +namespace LivePathEffect { + + +LPEGears::LPEGears(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + teeth(_("Teeth"), _("The number of teeth"), "teeth", &wr, this, 10), + phi(_("Phi"), _("???"), "phi", &wr, this, 5) +{ + registerParameter( dynamic_cast(&teeth) ); + registerParameter( dynamic_cast(&phi) ); +} + +LPEGears::~LPEGears() +{ + +} + +std::vector +LPEGears::doEffect (std::vector & path_in) +{ + std::vector path_out; + Geom::Path gearpath = path_in[0]; + + Geom::Path::iterator it(gearpath.begin()); + if ( it == gearpath.end() ) return path_out; + + Gear * gear = new Gear(teeth, 200.0, phi * M_PI / 180); + Geom::Point gear_centre = (*it).finalPoint(); + gear->centre(gear_centre); + gear->angle(atan2((*it).initialPoint() - gear_centre)); + + it++; if ( it == gearpath.end() ) return path_out; + gear->pitch_radius(Geom::distance(gear_centre, (*it).finalPoint())); + + path_out.push_back( gear->path()); + + for (it++ ; it != gearpath.end() ; it++) { + // iterate through Geom::Curve in path_in + Gear* gearnew = new Gear(gear->spawn( (*it).finalPoint() )); + path_out.push_back( gearnew->path() ); + delete gear; + gear = gearnew; + } + delete gear; + + return path_out; +} + + +} // 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-gears.h b/src/live_effects/lpe-gears.h index b43fbd95e..c3cea9230 100644 --- a/src/live_effects/lpe-gears.h +++ b/src/live_effects/lpe-gears.h @@ -1,38 +1,38 @@ -#ifndef INKSCAPE_LPE_GEARS_H -#define INKSCAPE_LPE_GEARS_H - -/* - * Inkscape::LPEGears - * -* Copyright (C) Johan Engelen 2007 - * - * 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 LPEGears : public Effect { -public: - LPEGears(LivePathEffectObject *lpeobject); - ~LPEGears(); - - std::vector doEffect (std::vector & path_in); - -private: - ScalarParam teeth; - ScalarParam phi; - - LPEGears(const LPEGears&); - LPEGears& operator=(const LPEGears&); -}; - -}; //namespace LivePathEffect -}; //namespace Inkscape - -#endif +#ifndef INKSCAPE_LPE_GEARS_H +#define INKSCAPE_LPE_GEARS_H + +/* + * Inkscape::LPEGears + * +* Copyright (C) Johan Engelen 2007 + * + * 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 LPEGears : public Effect { +public: + LPEGears(LivePathEffectObject *lpeobject); + ~LPEGears(); + + std::vector doEffect (std::vector & path_in); + +private: + ScalarParam teeth; + ScalarParam phi; + + LPEGears(const LPEGears&); + LPEGears& operator=(const LPEGears&); +}; + +}; //namespace LivePathEffect +}; //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-skeletalstrokes.cpp b/src/live_effects/lpe-skeletalstrokes.cpp index 31d4cfc2f..d351c3553 100644 --- a/src/live_effects/lpe-skeletalstrokes.cpp +++ b/src/live_effects/lpe-skeletalstrokes.cpp @@ -1,169 +1,169 @@ -#define INKSCAPE_LPE_SKELETAL_STROKES_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/lpe-skeletalstrokes.h" -#include "sp-shape.h" -#include "display/curve.h" -#include -#include "live_effects/n-art-bpath-2geom.h" -#include "svg/svg.h" -#include "ui/widget/scalar.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 <2geom/piecewise.h> - -#include -using std::vector; - - -/* Theory in e-mail from J.F. Barraud -Let B be the skeleton path, and P the pattern (the path to be deformed). - -P is a map t --> P(t) = ( x(t), y(t) ). -B is a map t --> B(t) = ( a(t), b(t) ). - -The first step is to re-parametrize B by its arc length: this is the parametrization in which a point p on B is located by its distance s from start. One obtains a new map s --> U(s) = (a'(s),b'(s)), that still describes the same path B, but where the distance along B from start to -U(s) is s itself. - -We also need a unit normal to the path. This can be obtained by computing a unit tangent vector, and rotate it by 90°. Call this normal vector N(s). - -The basic deformation associated to B is then given by: - - (x,y) --> U(x)+y*N(x) - -(i.e. we go for distance x along the path, and then for distance y along the normal) - -Of course this formula needs some minor adaptations (as is it depends on the absolute position of P for instance, so a little translation is needed -first) but I think we can first forget about them. -*/ - -namespace Inkscape { -namespace LivePathEffect { - -static const Util::EnumData SkelCopyTypeData[SSCT_END] = { - {SSCT_SINGLE, N_("Single"), "single"}, - {SSCT_SINGLE_STRETCHED, N_("Single, stretched"), "single_stretched"}, - {SSCT_REPEATED, N_("Repeated"), "repeated"}, - {SSCT_REPEATED_STRETCHED, N_("Repeated, stretched"), "repeated_stretched"} -}; -static const Util::EnumDataConverter SkelCopyTypeConverter(SkelCopyTypeData, SSCT_END); - -LPESkeletalStrokes::LPESkeletalStrokes(LivePathEffectObject *lpeobject) : - Effect(lpeobject), - pattern(_("Pattern source"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), - copytype(_("Pattern copies"), _("How many pattern copies to place along the skeleton path"), "copytype", SkelCopyTypeConverter, &wr, this, SSCT_SINGLE_STRETCHED), - prop_scale(_("Width"), _("Width of the pattern"), "prop_scale", &wr, this, 1), - scale_y_rel(_("Width in units of length"), _("Scale the width of the pattern in units of its length"), "scale_y_rel", &wr, this, false), - spacing(_("Spacing"), _("Space between copies of the pattern"), "spacing", &wr, this, 0), - normal_offset(_("Normal offset"), "", "normal_offset", &wr, this, 0), - tang_offset(_("Tangential offset"), "", "tang_offset", &wr, this, 0), - vertical_pattern(_("Pattern is vertical"), "", "vertical_pattern", &wr, this, false) -{ - registerParameter( dynamic_cast(&pattern) ); - registerParameter( dynamic_cast(©type) ); - registerParameter( dynamic_cast(&prop_scale) ); - registerParameter( dynamic_cast(&scale_y_rel) ); -// registerParameter( dynamic_cast(&spacing) ); -// registerParameter( dynamic_cast(&normal_offset) ); -// registerParameter( dynamic_cast(&tang_offset) ); - registerParameter( dynamic_cast(&vertical_pattern) ); - - prop_scale.param_set_digits(3); - prop_scale.param_set_increments(0.01, 0.10); -} - -LPESkeletalStrokes::~LPESkeletalStrokes() -{ - -} - - -Geom::Piecewise > -LPESkeletalStrokes::doEffect (Geom::Piecewise > & pwd2_in) -{ - using namespace Geom; - -/* Much credit should go to jfb and mgsloan of lib2geom development for the code below! */ - - SkelCopyType type = copytype.get_value(); - - Piecewise > uskeleton = arc_length_parametrization(Piecewise >(pwd2_in),2,.1); - uskeleton = remove_short_cuts(uskeleton,.01); - Piecewise > n = rot90(derivative(uskeleton)); - n = force_continuity(remove_short_cuts(n,.1)); - - D2 > patternd2 = make_cuts_independant(pattern); - Piecewise x = vertical_pattern.get_value() ? Piecewise(patternd2[1]) : Piecewise(patternd2[0]); - Piecewise y = vertical_pattern.get_value() ? Piecewise(patternd2[0]) : Piecewise(patternd2[1]); - Interval pattBnds = bounds_exact(x); - x -= pattBnds.min(); - Interval pattBndsY = bounds_exact(y); - y -= (pattBndsY.max()+pattBndsY.min())/2; - - int nbCopies = int(uskeleton.cuts.back()/pattBnds.extent()); - double scaling = 1; - - switch(type) { - case SSCT_REPEATED: - break; - - case SSCT_SINGLE: - nbCopies = (nbCopies > 0) ? 1 : 0; - break; - - case SSCT_SINGLE_STRETCHED: - nbCopies = 1; - scaling = uskeleton.cuts.back()/pattBnds.extent(); - break; - - case SSCT_REPEATED_STRETCHED: - scaling = uskeleton.cuts.back()/(((double)nbCopies)*pattBnds.extent()); - break; - - default: - return pwd2_in; - }; - - double pattWidth = pattBnds.extent() * scaling; - - if (scaling != 1.0) { - x*=scaling; - } - if ( scale_y_rel.get_value() ) { - y*=(scaling*prop_scale); - } else { - if (prop_scale != 1.0) y *= prop_scale; - } - - double offs = 0; - Piecewise > output; - for (int i=0; i + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-skeletalstrokes.h" +#include "sp-shape.h" +#include "display/curve.h" +#include +#include "live_effects/n-art-bpath-2geom.h" +#include "svg/svg.h" +#include "ui/widget/scalar.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 <2geom/piecewise.h> + +#include +using std::vector; + + +/* Theory in e-mail from J.F. Barraud +Let B be the skeleton path, and P the pattern (the path to be deformed). + +P is a map t --> P(t) = ( x(t), y(t) ). +B is a map t --> B(t) = ( a(t), b(t) ). + +The first step is to re-parametrize B by its arc length: this is the parametrization in which a point p on B is located by its distance s from start. One obtains a new map s --> U(s) = (a'(s),b'(s)), that still describes the same path B, but where the distance along B from start to +U(s) is s itself. + +We also need a unit normal to the path. This can be obtained by computing a unit tangent vector, and rotate it by 90°. Call this normal vector N(s). + +The basic deformation associated to B is then given by: + + (x,y) --> U(x)+y*N(x) + +(i.e. we go for distance x along the path, and then for distance y along the normal) + +Of course this formula needs some minor adaptations (as is it depends on the absolute position of P for instance, so a little translation is needed +first) but I think we can first forget about them. +*/ + +namespace Inkscape { +namespace LivePathEffect { + +static const Util::EnumData SkelCopyTypeData[SSCT_END] = { + {SSCT_SINGLE, N_("Single"), "single"}, + {SSCT_SINGLE_STRETCHED, N_("Single, stretched"), "single_stretched"}, + {SSCT_REPEATED, N_("Repeated"), "repeated"}, + {SSCT_REPEATED_STRETCHED, N_("Repeated, stretched"), "repeated_stretched"} +}; +static const Util::EnumDataConverter SkelCopyTypeConverter(SkelCopyTypeData, SSCT_END); + +LPESkeletalStrokes::LPESkeletalStrokes(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + pattern(_("Pattern source"), _("Path to put along the skeleton path"), "pattern", &wr, this, "M0,0 L1,0"), + copytype(_("Pattern copies"), _("How many pattern copies to place along the skeleton path"), "copytype", SkelCopyTypeConverter, &wr, this, SSCT_SINGLE_STRETCHED), + prop_scale(_("Width"), _("Width of the pattern"), "prop_scale", &wr, this, 1), + scale_y_rel(_("Width in units of length"), _("Scale the width of the pattern in units of its length"), "scale_y_rel", &wr, this, false), + spacing(_("Spacing"), _("Space between copies of the pattern"), "spacing", &wr, this, 0), + normal_offset(_("Normal offset"), "", "normal_offset", &wr, this, 0), + tang_offset(_("Tangential offset"), "", "tang_offset", &wr, this, 0), + vertical_pattern(_("Pattern is vertical"), "", "vertical_pattern", &wr, this, false) +{ + registerParameter( dynamic_cast(&pattern) ); + registerParameter( dynamic_cast(©type) ); + registerParameter( dynamic_cast(&prop_scale) ); + registerParameter( dynamic_cast(&scale_y_rel) ); +// registerParameter( dynamic_cast(&spacing) ); +// registerParameter( dynamic_cast(&normal_offset) ); +// registerParameter( dynamic_cast(&tang_offset) ); + registerParameter( dynamic_cast(&vertical_pattern) ); + + prop_scale.param_set_digits(3); + prop_scale.param_set_increments(0.01, 0.10); +} + +LPESkeletalStrokes::~LPESkeletalStrokes() +{ + +} + + +Geom::Piecewise > +LPESkeletalStrokes::doEffect (Geom::Piecewise > & pwd2_in) +{ + using namespace Geom; + +/* Much credit should go to jfb and mgsloan of lib2geom development for the code below! */ + + SkelCopyType type = copytype.get_value(); + + Piecewise > uskeleton = arc_length_parametrization(Piecewise >(pwd2_in),2,.1); + uskeleton = remove_short_cuts(uskeleton,.01); + Piecewise > n = rot90(derivative(uskeleton)); + n = force_continuity(remove_short_cuts(n,.1)); + + D2 > patternd2 = make_cuts_independant(pattern); + Piecewise x = vertical_pattern.get_value() ? Piecewise(patternd2[1]) : Piecewise(patternd2[0]); + Piecewise y = vertical_pattern.get_value() ? Piecewise(patternd2[0]) : Piecewise(patternd2[1]); + Interval pattBnds = bounds_exact(x); + x -= pattBnds.min(); + Interval pattBndsY = bounds_exact(y); + y -= (pattBndsY.max()+pattBndsY.min())/2; + + int nbCopies = int(uskeleton.cuts.back()/pattBnds.extent()); + double scaling = 1; + + switch(type) { + case SSCT_REPEATED: + break; + + case SSCT_SINGLE: + nbCopies = (nbCopies > 0) ? 1 : 0; + break; + + case SSCT_SINGLE_STRETCHED: + nbCopies = 1; + scaling = uskeleton.cuts.back()/pattBnds.extent(); + break; + + case SSCT_REPEATED_STRETCHED: + scaling = uskeleton.cuts.back()/(((double)nbCopies)*pattBnds.extent()); + break; + + default: + return pwd2_in; + }; + + double pattWidth = pattBnds.extent() * scaling; + + if (scaling != 1.0) { + x*=scaling; + } + if ( scale_y_rel.get_value() ) { + y*=(scaling*prop_scale); + } else { + if (prop_scale != 1.0) y *= prop_scale; + } + + double offs = 0; + Piecewise > output; + for (int i=0; i - * - * 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/enum.h" -#include "live_effects/parameter/bool.h" - -namespace Inkscape { -namespace LivePathEffect { - -enum SkelCopyType { - SSCT_SINGLE = 0, - SSCT_SINGLE_STRETCHED, - SSCT_REPEATED, - SSCT_REPEATED_STRETCHED, - SSCT_END // This must be last -}; - -class LPESkeletalStrokes : public Effect { -public: - LPESkeletalStrokes(LivePathEffectObject *lpeobject); - ~LPESkeletalStrokes(); - - Geom::Piecewise > doEffect (Geom::Piecewise > & pwd2_in); - -private: - PathParam pattern; - EnumParam copytype; - ScalarParam prop_scale; - BoolParam scale_y_rel; - ScalarParam spacing; - ScalarParam normal_offset; - ScalarParam tang_offset; - BoolParam vertical_pattern; - - void on_pattern_pasted(); - - LPESkeletalStrokes(const LPESkeletalStrokes&); - LPESkeletalStrokes& operator=(const LPESkeletalStrokes&); -}; - -}; //namespace LivePathEffect -}; //namespace Inkscape - -#endif +#ifndef INKSCAPE_LPE_SKELETAL_STROKES_H +#define INKSCAPE_LPE_SKELETAL_STROKES_H + +/* + * Inkscape::LPESkeletalStrokes + * +* Copyright (C) Johan Engelen 2007 + * + * 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/enum.h" +#include "live_effects/parameter/bool.h" + +namespace Inkscape { +namespace LivePathEffect { + +enum SkelCopyType { + SSCT_SINGLE = 0, + SSCT_SINGLE_STRETCHED, + SSCT_REPEATED, + SSCT_REPEATED_STRETCHED, + SSCT_END // This must be last +}; + +class LPESkeletalStrokes : public Effect { +public: + LPESkeletalStrokes(LivePathEffectObject *lpeobject); + ~LPESkeletalStrokes(); + + Geom::Piecewise > doEffect (Geom::Piecewise > & pwd2_in); + +private: + PathParam pattern; + EnumParam copytype; + ScalarParam prop_scale; + BoolParam scale_y_rel; + ScalarParam spacing; + ScalarParam normal_offset; + ScalarParam tang_offset; + BoolParam vertical_pattern; + + void on_pattern_pasted(); + + LPESkeletalStrokes(const LPESkeletalStrokes&); + LPESkeletalStrokes& operator=(const LPESkeletalStrokes&); +}; + +}; //namespace LivePathEffect +}; //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-skeleton.cpp b/src/live_effects/lpe-skeleton.cpp index a2cd470b7..13356972e 100644 --- a/src/live_effects/lpe-skeleton.cpp +++ b/src/live_effects/lpe-skeleton.cpp @@ -1,109 +1,109 @@ -#define INKSCAPE_LPE_SKELETON_CPP -/** \file - * SVG implementation, used as an example for a base starting class - * when implementing new LivePathEffects. - * - * In vi, three global search-and-replaces will let you rename everything - * in this and the .h file: - * - * :%s/SKELETON/YOURNAME/g - * :%s/Skeleton/Yourname/g - * :%s/skeleton/yourname/g - */ -/* - * Authors: - * Johan Engelen -* -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/lpe-skeleton.h" -#include "display/curve.h" -#include - -// You might need to include other 2geom files. You can add them here: -#include <2geom/path.h> - -namespace Inkscape { -namespace LivePathEffect { - -LPESkeleton::LPESkeleton(LivePathEffectObject *lpeobject) : - Effect(lpeobject), - // initialise your parameters here: - number(_("Float parameter"), _("just a real number like 1.4!"), "svgname", &wr, this, 1.2) -{ - // register all your parameters here, so Inkscape knows which parameters this effect has: - registerParameter( dynamic_cast(&number) ); -} - -LPESkeleton::~LPESkeleton() -{ - -} - - -/* ######################## - * Choose to implement one of the doEffect functions. You can delete or comment out the others. -*/ - -/* -void -LPESkeleton::doEffect (SPCurve * curve) -{ - // spice this up to make the effect actually *do* something! -} - -NArtBpath * -LPESkeleton::doEffect (NArtBpath * path_in) -{ - NArtBpath *path_out; - unsigned ret = 0; - while ( path_in[ret].code != NR_END ) { - ++ret; - } - unsigned len = ++ret; - path_out = g_new(NArtBpath, len); - - memcpy(path_out, path_in, len * sizeof(NArtBpath)); // spice this up to make the effect actually *do* something! - - return path_out; -} - -std::vector -LPESkeleton::doEffect (std::vector & path_in) -{ - std::vector path_out; - - path_out = path_in; // spice this up to make the effect actually *do* something! - - return path_out; -} -*/ - -Geom::Piecewise > -LPESkeleton::doEffect (Geom::Piecewise > & pwd2_in) -{ - Geom::Piecewise > output; - - output = pwd2_in; // spice this up to make the effect actually *do* something! - - 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 : +#define INKSCAPE_LPE_SKELETON_CPP +/** \file + * SVG implementation, used as an example for a base starting class + * when implementing new LivePathEffects. + * + * In vi, three global search-and-replaces will let you rename everything + * in this and the .h file: + * + * :%s/SKELETON/YOURNAME/g + * :%s/Skeleton/Yourname/g + * :%s/skeleton/yourname/g + */ +/* + * Authors: + * Johan Engelen +* +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-skeleton.h" +#include "display/curve.h" +#include + +// You might need to include other 2geom files. You can add them here: +#include <2geom/path.h> + +namespace Inkscape { +namespace LivePathEffect { + +LPESkeleton::LPESkeleton(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + // initialise your parameters here: + number(_("Float parameter"), _("just a real number like 1.4!"), "svgname", &wr, this, 1.2) +{ + // register all your parameters here, so Inkscape knows which parameters this effect has: + registerParameter( dynamic_cast(&number) ); +} + +LPESkeleton::~LPESkeleton() +{ + +} + + +/* ######################## + * Choose to implement one of the doEffect functions. You can delete or comment out the others. +*/ + +/* +void +LPESkeleton::doEffect (SPCurve * curve) +{ + // spice this up to make the effect actually *do* something! +} + +NArtBpath * +LPESkeleton::doEffect (NArtBpath * path_in) +{ + NArtBpath *path_out; + unsigned ret = 0; + while ( path_in[ret].code != NR_END ) { + ++ret; + } + unsigned len = ++ret; + path_out = g_new(NArtBpath, len); + + memcpy(path_out, path_in, len * sizeof(NArtBpath)); // spice this up to make the effect actually *do* something! + + return path_out; +} + +std::vector +LPESkeleton::doEffect (std::vector & path_in) +{ + std::vector path_out; + + path_out = path_in; // spice this up to make the effect actually *do* something! + + return path_out; +} +*/ + +Geom::Piecewise > +LPESkeleton::doEffect (Geom::Piecewise > & pwd2_in) +{ + Geom::Piecewise > output; + + output = pwd2_in; // spice this up to make the effect actually *do* something! + + 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-skeleton.h b/src/live_effects/lpe-skeleton.h index cce9bde3e..816b8b707 100644 --- a/src/live_effects/lpe-skeleton.h +++ b/src/live_effects/lpe-skeleton.h @@ -1,47 +1,47 @@ -#ifndef INKSCAPE_LPE_SKELETON_H -#define INKSCAPE_LPE_SKELETON_H - -/** \file - * SVG implementation, see sp-skeleton.cpp. - */ - -/* - * Authors: - * Johan Engelen -* -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/effect.h" -#include "live_effects/parameter/parameter.h" -#include "live_effects/parameter/point.h" - -namespace Inkscape { -namespace LivePathEffect { - -class LPESkeleton : public Effect { -public: - LPESkeleton(LivePathEffectObject *lpeobject); - ~LPESkeleton(); - -// Choose to implement one of the doEffect functions. You can delete or comment out the others. -// void doEffect (SPCurve * curve); -// NArtBpath * doEffect (NArtBpath * path_in); -// std::vector doEffect (std::vector & path_in); - Geom::Piecewise > doEffect (Geom::Piecewise > & pwd2_in); - -private: - // add the parameters for your effect here: - ScalarParam number; - // there are all kinds of parameters. Check the /live_effects/parameter directory which types exist! - - LPESkeleton(const LPESkeleton&); - LPESkeleton& operator=(const LPESkeleton&); -}; - -} //namespace LivePathEffect -} //namespace Inkscape - -#endif +#ifndef INKSCAPE_LPE_SKELETON_H +#define INKSCAPE_LPE_SKELETON_H + +/** \file + * SVG implementation, see sp-skeleton.cpp. + */ + +/* + * Authors: + * Johan Engelen +* +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/point.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPESkeleton : public Effect { +public: + LPESkeleton(LivePathEffectObject *lpeobject); + ~LPESkeleton(); + +// Choose to implement one of the doEffect functions. You can delete or comment out the others. +// void doEffect (SPCurve * curve); +// NArtBpath * doEffect (NArtBpath * path_in); +// std::vector doEffect (std::vector & path_in); + Geom::Piecewise > doEffect (Geom::Piecewise > & pwd2_in); + +private: + // add the parameters for your effect here: + ScalarParam number; + // there are all kinds of parameters. Check the /live_effects/parameter directory which types exist! + + LPESkeleton(const LPESkeleton&); + LPESkeleton& operator=(const LPESkeleton&); +}; + +} //namespace LivePathEffect +} //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-slant.cpp b/src/live_effects/lpe-slant.cpp index c40d5fa20..407e43992 100644 --- a/src/live_effects/lpe-slant.cpp +++ b/src/live_effects/lpe-slant.cpp @@ -1,55 +1,55 @@ -#define INKSCAPE_LPE_SLANT_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/lpe-slant.h" -#include "display/curve.h" -#include - -namespace Inkscape { -namespace LivePathEffect { - -LPESlant::LPESlant(LivePathEffectObject *lpeobject) : - Effect(lpeobject), - factor(_("Slant factor"), _("y = y + x*(slant factor)"), "factor", &wr, this), - center(_("Center"), _("The x-coord of this point is around which the slant will happen"), "center", &wr, this) -{ - registerParameter( dynamic_cast(&factor) ); - registerParameter( dynamic_cast(¢er) ); -} - -LPESlant::~LPESlant() -{ -} - -void -LPESlant::doEffect(SPCurve * curve) -{ - NArtBpath *bpath = curve->_bpath; - int i = 0; - while(bpath[i].code != NR_END) { - bpath[i].y1 += (bpath[i].x1-center[Geom::X]) * factor; - bpath[i].y2 += (bpath[i].x2-center[Geom::X]) * factor; - bpath[i].y3 += (bpath[i].x3-center[Geom::X]) * factor; - i++; - } - -} - -}; //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 : +#define INKSCAPE_LPE_SLANT_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-slant.h" +#include "display/curve.h" +#include + +namespace Inkscape { +namespace LivePathEffect { + +LPESlant::LPESlant(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + factor(_("Slant factor"), _("y = y + x*(slant factor)"), "factor", &wr, this), + center(_("Center"), _("The x-coord of this point is around which the slant will happen"), "center", &wr, this) +{ + registerParameter( dynamic_cast(&factor) ); + registerParameter( dynamic_cast(¢er) ); +} + +LPESlant::~LPESlant() +{ +} + +void +LPESlant::doEffect(SPCurve * curve) +{ + NArtBpath *bpath = curve->_bpath; + int i = 0; + while(bpath[i].code != NR_END) { + bpath[i].y1 += (bpath[i].x1-center[Geom::X]) * factor; + bpath[i].y2 += (bpath[i].x2-center[Geom::X]) * factor; + bpath[i].y3 += (bpath[i].x3-center[Geom::X]) * factor; + i++; + } + +} + +}; //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-slant.h b/src/live_effects/lpe-slant.h index 1f3ebcdb9..c92a37f80 100644 --- a/src/live_effects/lpe-slant.h +++ b/src/live_effects/lpe-slant.h @@ -1,40 +1,40 @@ -#ifndef INKSCAPE_LPE_SLANT_H -#define INKSCAPE_LPE_SLANT_H - -/* - * Inkscape::LPESlant - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/effect.h" -#include "live_effects/parameter/parameter.h" -#include "live_effects/parameter/point.h" -#include "ui/widget/registered-widget.h" - - - -namespace Inkscape { -namespace LivePathEffect { - -class LPESlant : public Effect { -public: - LPESlant(LivePathEffectObject *lpeobject); - ~LPESlant(); - - void doEffect(SPCurve * curve); - -private: - ScalarParam factor; - PointParam center; - - LPESlant(const LPESlant&); - LPESlant& operator=(const LPESlant&); -}; - -}; //namespace LivePathEffect -}; //namespace Inkscape - -#endif +#ifndef INKSCAPE_LPE_SLANT_H +#define INKSCAPE_LPE_SLANT_H + +/* + * Inkscape::LPESlant + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" +#include "live_effects/parameter/point.h" +#include "ui/widget/registered-widget.h" + + + +namespace Inkscape { +namespace LivePathEffect { + +class LPESlant : public Effect { +public: + LPESlant(LivePathEffectObject *lpeobject); + ~LPESlant(); + + void doEffect(SPCurve * curve); + +private: + ScalarParam factor; + PointParam center; + + LPESlant(const LPESlant&); + LPESlant& operator=(const LPESlant&); +}; + +}; //namespace LivePathEffect +}; //namespace Inkscape + +#endif diff --git a/src/live_effects/lpe-test-doEffect-stack.cpp b/src/live_effects/lpe-test-doEffect-stack.cpp index 19f20b5a9..d071050e9 100644 --- a/src/live_effects/lpe-test-doEffect-stack.cpp +++ b/src/live_effects/lpe-test-doEffect-stack.cpp @@ -1,96 +1,96 @@ -#define INKSCAPE_LPE_DOEFFECT_STACK_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/lpe-test-doEffect-stack.h" - -#include <2geom/piecewise.h> -#include -#include - -namespace Inkscape { -namespace LivePathEffect { - - -LPEdoEffectStackTest::LPEdoEffectStackTest(LivePathEffectObject *lpeobject) : - Effect(lpeobject), - step(_("Stack step"), (""), "step", &wr, this) -{ - registerParameter( dynamic_cast(&step) ); -} - -LPEdoEffectStackTest::~LPEdoEffectStackTest() -{ - -} - -void -LPEdoEffectStackTest::doEffect (SPCurve * curve) -{ - if (step >= 1) { - Effect::doEffect(curve); - } else { - // return here - return; - } -} - -NArtBpath * -LPEdoEffectStackTest::doEffect (NArtBpath * path_in) -{ - if (step >= 2) { - return Effect::doEffect(path_in); - } else { - // return here - NArtBpath *path_out; - - unsigned ret = 0; - while ( path_in[ret].code != NR_END ) { - ++ret; - } - unsigned len = ++ret; - - path_out = g_new(NArtBpath, len); - memcpy(path_out, path_in, len * sizeof(NArtBpath)); - return path_out; - } -} - -std::vector -LPEdoEffectStackTest::doEffect (std::vector & path_in) -{ - if (step >= 3) { - return Effect::doEffect(path_in); - } else { - // return here - std::vector path_out = path_in; - return path_out; - } -} - -Geom::Piecewise > -LPEdoEffectStackTest::doEffect (Geom::Piecewise > & pwd2_in) -{ - Geom::Piecewise > output = pwd2_in; - - 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 : +#define INKSCAPE_LPE_DOEFFECT_STACK_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/lpe-test-doEffect-stack.h" + +#include <2geom/piecewise.h> +#include +#include + +namespace Inkscape { +namespace LivePathEffect { + + +LPEdoEffectStackTest::LPEdoEffectStackTest(LivePathEffectObject *lpeobject) : + Effect(lpeobject), + step(_("Stack step"), (""), "step", &wr, this) +{ + registerParameter( dynamic_cast(&step) ); +} + +LPEdoEffectStackTest::~LPEdoEffectStackTest() +{ + +} + +void +LPEdoEffectStackTest::doEffect (SPCurve * curve) +{ + if (step >= 1) { + Effect::doEffect(curve); + } else { + // return here + return; + } +} + +NArtBpath * +LPEdoEffectStackTest::doEffect (NArtBpath * path_in) +{ + if (step >= 2) { + return Effect::doEffect(path_in); + } else { + // return here + NArtBpath *path_out; + + unsigned ret = 0; + while ( path_in[ret].code != NR_END ) { + ++ret; + } + unsigned len = ++ret; + + path_out = g_new(NArtBpath, len); + memcpy(path_out, path_in, len * sizeof(NArtBpath)); + return path_out; + } +} + +std::vector +LPEdoEffectStackTest::doEffect (std::vector & path_in) +{ + if (step >= 3) { + return Effect::doEffect(path_in); + } else { + // return here + std::vector path_out = path_in; + return path_out; + } +} + +Geom::Piecewise > +LPEdoEffectStackTest::doEffect (Geom::Piecewise > & pwd2_in) +{ + Geom::Piecewise > output = pwd2_in; + + 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-test-doEffect-stack.h b/src/live_effects/lpe-test-doEffect-stack.h index 5e990868e..0635bc06c 100644 --- a/src/live_effects/lpe-test-doEffect-stack.h +++ b/src/live_effects/lpe-test-doEffect-stack.h @@ -1,42 +1,42 @@ -#ifndef INKSCAPE_LPE_DOEFFECT_STACK_H -#define INKSCAPE_LPE_DOEFFECT_STACK_H - -/* - * Inkscape::LPEdoEffectStackTest - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information -* -* This effect is to test whether running up and down the doEffect stack does not change the original-d too much. -* i.e. for this effect, the output should match more or less exactly with the input. -* - */ - -#include "live_effects/effect.h" -#include "live_effects/parameter/parameter.h" - -namespace Inkscape { -namespace LivePathEffect { - -class LPEdoEffectStackTest : public Effect { -public: - LPEdoEffectStackTest(LivePathEffectObject *lpeobject); - ~LPEdoEffectStackTest(); - - void doEffect (SPCurve * curve); - NArtBpath * doEffect (NArtBpath * path_in); - std::vector doEffect (std::vector & path_in); - Geom::Piecewise > doEffect (Geom::Piecewise > & pwd2_in); - -private: - ScalarParam step; - - LPEdoEffectStackTest(const LPEdoEffectStackTest&); - LPEdoEffectStackTest& operator=(const LPEdoEffectStackTest&); -}; - -}; //namespace LivePathEffect -}; //namespace Inkscape - -#endif +#ifndef INKSCAPE_LPE_DOEFFECT_STACK_H +#define INKSCAPE_LPE_DOEFFECT_STACK_H + +/* + * Inkscape::LPEdoEffectStackTest + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information +* +* This effect is to test whether running up and down the doEffect stack does not change the original-d too much. +* i.e. for this effect, the output should match more or less exactly with the input. +* + */ + +#include "live_effects/effect.h" +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { +namespace LivePathEffect { + +class LPEdoEffectStackTest : public Effect { +public: + LPEdoEffectStackTest(LivePathEffectObject *lpeobject); + ~LPEdoEffectStackTest(); + + void doEffect (SPCurve * curve); + NArtBpath * doEffect (NArtBpath * path_in); + std::vector doEffect (std::vector & path_in); + Geom::Piecewise > doEffect (Geom::Piecewise > & pwd2_in); + +private: + ScalarParam step; + + LPEdoEffectStackTest(const LPEdoEffectStackTest&); + LPEdoEffectStackTest& operator=(const LPEdoEffectStackTest&); +}; + +}; //namespace LivePathEffect +}; //namespace Inkscape + +#endif diff --git a/src/live_effects/lpeobject-reference.cpp b/src/live_effects/lpeobject-reference.cpp index e4def4301..6d37a0235 100644 --- a/src/live_effects/lpeobject-reference.cpp +++ b/src/live_effects/lpeobject-reference.cpp @@ -1,161 +1,161 @@ -/* - * The reference corresponding to the inkscape:live-effect attribute - * - * Copyright (C) 2007 Johan Engelen - * - * Released under GNU GPL, read the file 'COPYING' for more information. - */ - -#include "enums.h" -#include "live_effects/lpeobject-reference.h" -#include "live_effects/lpeobject.h" - -#include "prefs-utils.h" -#include "uri.h" - -namespace Inkscape { - -namespace LivePathEffect { - -static void lpeobjectreference_href_changed(SPObject *old_ref, SPObject *ref, LPEObjectReference *lpeobjref); -static void lpeobjectreference_delete_self(SPObject *deleted, LPEObjectReference *lpeobjref); -static void lpeobjectreference_source_modified(SPObject *iSource, guint flags, LPEObjectReference *lpeobjref); - -LPEObjectReference::LPEObjectReference(SPObject* i_owner) : URIReference(i_owner) -{ - owner=i_owner; - lpeobject_href = NULL; - lpeobject_repr = NULL; - lpeobject = NULL; - _changed_connection = changedSignal().connect(sigc::bind(sigc::ptr_fun(lpeobjectreference_href_changed), this)); // listening to myself, this should be virtual instead - - user_unlink = NULL; -} - -LPEObjectReference::~LPEObjectReference(void) -{ - _changed_connection.disconnect(); // to do before unlinking - - quit_listening(); - unlink(); -} - -bool LPEObjectReference::_acceptObject(SPObject * const obj) const -{ - if (IS_LIVEPATHEFFECT(obj)) { - SPObject * const owner = getOwner(); - /* Refuse references to us or to an ancestor. */ - for ( SPObject *iter = owner ; iter ; iter = SP_OBJECT_PARENT(iter) ) { - if ( iter == obj ) { - return false; - } - } - return true; - } else { - return false; - } -} - -void -LPEObjectReference::link(char *to) -{ - if ( to == NULL ) { - quit_listening(); - unlink(); - } else { - if ( !lpeobject_href || ( strcmp(to, lpeobject_href) != 0 ) ) { - g_free(lpeobject_href); - lpeobject_href = g_strdup(to); - try { - attach(Inkscape::URI(to)); - } catch (Inkscape::BadURIException &e) { - /* TODO: Proper error handling as per - * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. - */ - g_warning("%s", e.what()); - detach(); - } - } - } -} - -void -LPEObjectReference::unlink(void) -{ - g_free(lpeobject_href); - lpeobject_href = NULL; - detach(); -} - -void -LPEObjectReference::start_listening(LivePathEffectObject* to) -{ - if ( to == NULL ) { - return; - } - lpeobject = to; - lpeobject_repr = SP_OBJECT_REPR(to); - _delete_connection = to->connectDelete(sigc::bind(sigc::ptr_fun(&lpeobjectreference_delete_self), this)); - _modified_connection = to->connectModified(sigc::bind<2>(sigc::ptr_fun(&lpeobjectreference_source_modified), this)); -} - -void -LPEObjectReference::quit_listening(void) -{ - if ( lpeobject == NULL ) { - return; - } - _modified_connection.disconnect(); - _delete_connection.disconnect(); - lpeobject_repr = NULL; - lpeobject = NULL; -} - -static void -lpeobjectreference_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, LPEObjectReference *lpeobjref) -{ - lpeobjref->quit_listening(); - LivePathEffectObject *refobj = LIVEPATHEFFECT( lpeobjref->getObject() ); - if ( refobj ) { - lpeobjref->start_listening(refobj); - } - - lpeobjref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); -} - -static void -lpeobjectreference_delete_self(SPObject */*deleted*/, LPEObjectReference *lpeobjref) -{ - guint const mode = prefs_get_int_attribute("options.cloneorphans", "value", SP_CLONE_ORPHANS_UNLINK); - - if (mode == SP_CLONE_ORPHANS_UNLINK) { - // leave it be. just forget about the source - lpeobjref->quit_listening(); - lpeobjref->unlink(); - if (lpeobjref->user_unlink) - lpeobjref->user_unlink(lpeobjref->owner); - } else if (mode == SP_CLONE_ORPHANS_DELETE) { - lpeobjref->owner->deleteObject(); - } -} - -static void -lpeobjectreference_source_modified(SPObject *iSource, guint flags, LPEObjectReference *lpeobjref) -{ - lpeobjref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); -} - -} //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 : +/* + * The reference corresponding to the inkscape:live-effect attribute + * + * Copyright (C) 2007 Johan Engelen + * + * Released under GNU GPL, read the file 'COPYING' for more information. + */ + +#include "enums.h" +#include "live_effects/lpeobject-reference.h" +#include "live_effects/lpeobject.h" + +#include "prefs-utils.h" +#include "uri.h" + +namespace Inkscape { + +namespace LivePathEffect { + +static void lpeobjectreference_href_changed(SPObject *old_ref, SPObject *ref, LPEObjectReference *lpeobjref); +static void lpeobjectreference_delete_self(SPObject *deleted, LPEObjectReference *lpeobjref); +static void lpeobjectreference_source_modified(SPObject *iSource, guint flags, LPEObjectReference *lpeobjref); + +LPEObjectReference::LPEObjectReference(SPObject* i_owner) : URIReference(i_owner) +{ + owner=i_owner; + lpeobject_href = NULL; + lpeobject_repr = NULL; + lpeobject = NULL; + _changed_connection = changedSignal().connect(sigc::bind(sigc::ptr_fun(lpeobjectreference_href_changed), this)); // listening to myself, this should be virtual instead + + user_unlink = NULL; +} + +LPEObjectReference::~LPEObjectReference(void) +{ + _changed_connection.disconnect(); // to do before unlinking + + quit_listening(); + unlink(); +} + +bool LPEObjectReference::_acceptObject(SPObject * const obj) const +{ + if (IS_LIVEPATHEFFECT(obj)) { + SPObject * const owner = getOwner(); + /* Refuse references to us or to an ancestor. */ + for ( SPObject *iter = owner ; iter ; iter = SP_OBJECT_PARENT(iter) ) { + if ( iter == obj ) { + return false; + } + } + return true; + } else { + return false; + } +} + +void +LPEObjectReference::link(char *to) +{ + if ( to == NULL ) { + quit_listening(); + unlink(); + } else { + if ( !lpeobject_href || ( strcmp(to, lpeobject_href) != 0 ) ) { + g_free(lpeobject_href); + lpeobject_href = g_strdup(to); + try { + attach(Inkscape::URI(to)); + } catch (Inkscape::BadURIException &e) { + /* TODO: Proper error handling as per + * http://www.w3.org/TR/SVG11/implnote.html#ErrorProcessing. + */ + g_warning("%s", e.what()); + detach(); + } + } + } +} + +void +LPEObjectReference::unlink(void) +{ + g_free(lpeobject_href); + lpeobject_href = NULL; + detach(); +} + +void +LPEObjectReference::start_listening(LivePathEffectObject* to) +{ + if ( to == NULL ) { + return; + } + lpeobject = to; + lpeobject_repr = SP_OBJECT_REPR(to); + _delete_connection = to->connectDelete(sigc::bind(sigc::ptr_fun(&lpeobjectreference_delete_self), this)); + _modified_connection = to->connectModified(sigc::bind<2>(sigc::ptr_fun(&lpeobjectreference_source_modified), this)); +} + +void +LPEObjectReference::quit_listening(void) +{ + if ( lpeobject == NULL ) { + return; + } + _modified_connection.disconnect(); + _delete_connection.disconnect(); + lpeobject_repr = NULL; + lpeobject = NULL; +} + +static void +lpeobjectreference_href_changed(SPObject */*old_ref*/, SPObject */*ref*/, LPEObjectReference *lpeobjref) +{ + lpeobjref->quit_listening(); + LivePathEffectObject *refobj = LIVEPATHEFFECT( lpeobjref->getObject() ); + if ( refobj ) { + lpeobjref->start_listening(refobj); + } + + lpeobjref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); +} + +static void +lpeobjectreference_delete_self(SPObject */*deleted*/, LPEObjectReference *lpeobjref) +{ + guint const mode = prefs_get_int_attribute("options.cloneorphans", "value", SP_CLONE_ORPHANS_UNLINK); + + if (mode == SP_CLONE_ORPHANS_UNLINK) { + // leave it be. just forget about the source + lpeobjref->quit_listening(); + lpeobjref->unlink(); + if (lpeobjref->user_unlink) + lpeobjref->user_unlink(lpeobjref->owner); + } else if (mode == SP_CLONE_ORPHANS_DELETE) { + lpeobjref->owner->deleteObject(); + } +} + +static void +lpeobjectreference_source_modified(SPObject *iSource, guint flags, LPEObjectReference *lpeobjref) +{ + lpeobjref->owner->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG); +} + +} //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/lpeobject-reference.h b/src/live_effects/lpeobject-reference.h index ff7556d50..ba652ff3e 100644 --- a/src/live_effects/lpeobject-reference.h +++ b/src/live_effects/lpeobject-reference.h @@ -1,71 +1,71 @@ -#ifndef SEEN_LPEOBJECT_REFERENCE_H -#define SEEN_LPEOBJECT_REFERENCE_H - -/* - * The reference corresponding to the inkscape:live-effect attribute - * - * Copyright (C) 2007 Johan Engelen - * - * Released under GNU GPL, read the file 'COPYING' for more information. - */ - -#include -#include -#include - -namespace Inkscape { -namespace XML { -struct Node; -} -} - -struct LivePathEffectObject; - -namespace Inkscape { - -namespace LivePathEffect { - -class LPEObjectReference : public Inkscape::URIReference { -public: - LPEObjectReference(SPObject *owner); - ~LPEObjectReference(); - - SPObject *owner; - - // concerning the LPEObject that is refered to: - gchar *lpeobject_href; - Inkscape::XML::Node *lpeobject_repr; - LivePathEffectObject *lpeobject; - - sigc::connection _modified_connection; - sigc::connection _delete_connection; - sigc::connection _changed_connection; - - void link(char* to); - void unlink(void); - void start_listening(LivePathEffectObject* to); - void quit_listening(void); - - void (*user_unlink) (SPObject *user); - -protected: - bool _acceptObject(SPObject * const obj) const; - -}; - -} //namespace LivePathEffect - -} // namespace inkscape - -#endif /* !SEEN_LPEOBJECT_REFERENCE_H */ - -/* - 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 : +#ifndef SEEN_LPEOBJECT_REFERENCE_H +#define SEEN_LPEOBJECT_REFERENCE_H + +/* + * The reference corresponding to the inkscape:live-effect attribute + * + * Copyright (C) 2007 Johan Engelen + * + * Released under GNU GPL, read the file 'COPYING' for more information. + */ + +#include +#include +#include + +namespace Inkscape { +namespace XML { +struct Node; +} +} + +struct LivePathEffectObject; + +namespace Inkscape { + +namespace LivePathEffect { + +class LPEObjectReference : public Inkscape::URIReference { +public: + LPEObjectReference(SPObject *owner); + ~LPEObjectReference(); + + SPObject *owner; + + // concerning the LPEObject that is refered to: + gchar *lpeobject_href; + Inkscape::XML::Node *lpeobject_repr; + LivePathEffectObject *lpeobject; + + sigc::connection _modified_connection; + sigc::connection _delete_connection; + sigc::connection _changed_connection; + + void link(char* to); + void unlink(void); + void start_listening(LivePathEffectObject* to); + void quit_listening(void); + + void (*user_unlink) (SPObject *user); + +protected: + bool _acceptObject(SPObject * const obj) const; + +}; + +} //namespace LivePathEffect + +} // namespace inkscape + +#endif /* !SEEN_LPEOBJECT_REFERENCE_H */ + +/* + 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/lpeobject.cpp b/src/live_effects/lpeobject.cpp index 8c45a4d3c..a8321b72d 100644 --- a/src/live_effects/lpeobject.cpp +++ b/src/live_effects/lpeobject.cpp @@ -1,264 +1,264 @@ -#define INKSCAPE_LIVEPATHEFFECT_OBJECT_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "xml/repr.h" -#include "xml/node-event-vector.h" -#include "sp-object.h" -#include "attributes.h" - -#include "document.h" -#include - -#include "live_effects/lpeobject.h" -#include "live_effects/effect.h" - -//#define LIVEPATHEFFECT_VERBOSE - -static void livepatheffect_class_init(LivePathEffectObjectClass *klass); -static void livepatheffect_init(LivePathEffectObject *stop); - -static void livepatheffect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); -static void livepatheffect_release(SPObject *object); - -static void livepatheffect_set(SPObject *object, unsigned key, gchar const *value); -static Inkscape::XML::Node *livepatheffect_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); - -static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); - -static SPObjectClass *livepatheffect_parent_class; -/** - * Registers the LivePathEffect class with Gdk and returns its type number. - */ -GType -livepatheffect_get_type () -{ - static GType livepatheffect_type = 0; - - if (!livepatheffect_type) { - GTypeInfo livepatheffect_info = { - sizeof (LivePathEffectObjectClass), - NULL, NULL, - (GClassInitFunc) livepatheffect_class_init, - NULL, NULL, - sizeof (LivePathEffectObject), - 16, - (GInstanceInitFunc) livepatheffect_init, - NULL, - }; - livepatheffect_type = g_type_register_static (SP_TYPE_OBJECT, "LivePathEffectObject", &livepatheffect_info, (GTypeFlags)0); - } - return livepatheffect_type; -} - -static Inkscape::XML::NodeEventVector const livepatheffect_repr_events = { - NULL, /* child_added */ - NULL, /* child_removed */ - livepatheffect_on_repr_attr_changed, - NULL, /* content_changed */ - NULL /* order_changed */ -}; - - -/** - * Callback to initialize livepatheffect vtable. - */ -static void -livepatheffect_class_init(LivePathEffectObjectClass *klass) -{ - SPObjectClass *sp_object_class = (SPObjectClass *) klass; - - livepatheffect_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); - - sp_object_class->build = livepatheffect_build; - sp_object_class->release = livepatheffect_release; - - sp_object_class->set = livepatheffect_set; - sp_object_class->write = livepatheffect_write; -} - -/** - * Callback to initialize livepatheffect object. - */ -static void -livepatheffect_init(LivePathEffectObject *lpeobj) -{ -#ifdef LIVEPATHEFFECT_VERBOSE - g_message("Init livepatheffectobject"); -#endif - lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE; - lpeobj->lpe = NULL; - - lpeobj->effecttype_set = false; -} - -/** - * Virtual build: set livepatheffect attributes from its associated XML node. - */ -static void -livepatheffect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) -{ -#ifdef LIVEPATHEFFECT_VERBOSE - g_message("Build livepatheffect"); -#endif - g_assert(object != NULL); - g_assert(SP_IS_OBJECT(object)); - - if (((SPObjectClass *) livepatheffect_parent_class)->build) - (* ((SPObjectClass *) livepatheffect_parent_class)->build)(object, document, repr); - - sp_object_read_attr(object, "effect"); - - if (repr) { - repr->addListener (&livepatheffect_repr_events, object); - } - - /* Register ourselves, is this necessary? */ -// sp_document_add_resource(document, "path-effect", object); -} - -/** - * Virtual release of livepatheffect members before destruction. - */ -static void -livepatheffect_release(SPObject *object) -{ -#ifdef LIVEPATHEFFECT_VERBOSE - g_print("Releasing livepatheffect"); -#endif - - LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object); - - SP_OBJECT_REPR(object)->removeListenerByData(object); - - -/* - if (SP_OBJECT_DOCUMENT(object)) { - // Unregister ourselves - sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "livepatheffect", SP_OBJECT(object)); - } - - if (gradient->ref) { - gradient->modified_connection.disconnect(); - gradient->ref->detach(); - delete gradient->ref; - gradient->ref = NULL; - } - - gradient->modified_connection.~connection(); - -*/ - - if (lpeobj->lpe) { - delete lpeobj->lpe; - lpeobj->lpe = NULL; - } - lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE; - - if (((SPObjectClass *) livepatheffect_parent_class)->release) - ((SPObjectClass *) livepatheffect_parent_class)->release(object); -} - -/** - * Virtual set: set attribute to value. - */ -static void -livepatheffect_set(SPObject *object, unsigned key, gchar const *value) -{ - LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object); -#ifdef LIVEPATHEFFECT_VERBOSE - g_print("Set livepatheffect"); -#endif - switch (key) { - case SP_PROP_PATH_EFFECT: - if (lpeobj->lpe) { - delete lpeobj->lpe; - lpeobj->lpe = NULL; - } - - if (value) { - lpeobj->effecttype = Inkscape::LivePathEffect::LPETypeConverter.get_id_from_key(value); - if (lpeobj->effecttype != Inkscape::LivePathEffect::INVALID_LPE) { - lpeobj->lpe = Inkscape::LivePathEffect::Effect::New(lpeobj->effecttype, lpeobj); - } - lpeobj->effecttype_set = true; - } else { - lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE; - lpeobj->effecttype_set = false; - } - object->requestModified(SP_OBJECT_MODIFIED_FLAG); - break; - } - - if (((SPObjectClass *) livepatheffect_parent_class)->set) { - ((SPObjectClass *) livepatheffect_parent_class)->set(object, key, value); - } -} - -/** - * Virtual write: write object attributes to repr. - */ -static Inkscape::XML::Node * -livepatheffect_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) -{ -#ifdef LIVEPATHEFFECT_VERBOSE - g_print("Write livepatheffect"); -#endif - - LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object); - - if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); - repr = xml_doc->createElement("inkscape:path-effect"); - } - - if ((flags & SP_OBJECT_WRITE_ALL) || lpeobj->effecttype_set) - repr->setAttribute("effect", Inkscape::LivePathEffect::LPETypeConverter.get_key(lpeobj->effecttype).c_str()); - -// lpeobj->lpe->write(repr); something like this. - - if (((SPObjectClass *) livepatheffect_parent_class)->write) - (* ((SPObjectClass *) livepatheffect_parent_class)->write)(object, repr, flags); - - return repr; -} - -static void -livepatheffect_on_repr_attr_changed ( Inkscape::XML::Node * repr, - const gchar *key, - const gchar *oldval, - const gchar *newval, - bool is_interactive, - void * data ) -{ -#ifdef LIVEPATHEFFECT_VERBOSE - g_print("livepatheffect_on_repr_attr_changed"); -#endif - - if (!data) - return; - - LivePathEffectObject *lpeobj = (LivePathEffectObject*) data; - if (!lpeobj->lpe) - return; - - lpeobj->lpe->setParameter(repr, key, oldval, newval); - - lpeobj->requestModified(SP_OBJECT_MODIFIED_FLAG); -} - - -/* - 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 : +#define INKSCAPE_LIVEPATHEFFECT_OBJECT_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "xml/repr.h" +#include "xml/node-event-vector.h" +#include "sp-object.h" +#include "attributes.h" + +#include "document.h" +#include + +#include "live_effects/lpeobject.h" +#include "live_effects/effect.h" + +//#define LIVEPATHEFFECT_VERBOSE + +static void livepatheffect_class_init(LivePathEffectObjectClass *klass); +static void livepatheffect_init(LivePathEffectObject *stop); + +static void livepatheffect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr); +static void livepatheffect_release(SPObject *object); + +static void livepatheffect_set(SPObject *object, unsigned key, gchar const *value); +static Inkscape::XML::Node *livepatheffect_write(SPObject *object, Inkscape::XML::Node *repr, guint flags); + +static void livepatheffect_on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data); + +static SPObjectClass *livepatheffect_parent_class; +/** + * Registers the LivePathEffect class with Gdk and returns its type number. + */ +GType +livepatheffect_get_type () +{ + static GType livepatheffect_type = 0; + + if (!livepatheffect_type) { + GTypeInfo livepatheffect_info = { + sizeof (LivePathEffectObjectClass), + NULL, NULL, + (GClassInitFunc) livepatheffect_class_init, + NULL, NULL, + sizeof (LivePathEffectObject), + 16, + (GInstanceInitFunc) livepatheffect_init, + NULL, + }; + livepatheffect_type = g_type_register_static (SP_TYPE_OBJECT, "LivePathEffectObject", &livepatheffect_info, (GTypeFlags)0); + } + return livepatheffect_type; +} + +static Inkscape::XML::NodeEventVector const livepatheffect_repr_events = { + NULL, /* child_added */ + NULL, /* child_removed */ + livepatheffect_on_repr_attr_changed, + NULL, /* content_changed */ + NULL /* order_changed */ +}; + + +/** + * Callback to initialize livepatheffect vtable. + */ +static void +livepatheffect_class_init(LivePathEffectObjectClass *klass) +{ + SPObjectClass *sp_object_class = (SPObjectClass *) klass; + + livepatheffect_parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT); + + sp_object_class->build = livepatheffect_build; + sp_object_class->release = livepatheffect_release; + + sp_object_class->set = livepatheffect_set; + sp_object_class->write = livepatheffect_write; +} + +/** + * Callback to initialize livepatheffect object. + */ +static void +livepatheffect_init(LivePathEffectObject *lpeobj) +{ +#ifdef LIVEPATHEFFECT_VERBOSE + g_message("Init livepatheffectobject"); +#endif + lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE; + lpeobj->lpe = NULL; + + lpeobj->effecttype_set = false; +} + +/** + * Virtual build: set livepatheffect attributes from its associated XML node. + */ +static void +livepatheffect_build(SPObject *object, SPDocument *document, Inkscape::XML::Node *repr) +{ +#ifdef LIVEPATHEFFECT_VERBOSE + g_message("Build livepatheffect"); +#endif + g_assert(object != NULL); + g_assert(SP_IS_OBJECT(object)); + + if (((SPObjectClass *) livepatheffect_parent_class)->build) + (* ((SPObjectClass *) livepatheffect_parent_class)->build)(object, document, repr); + + sp_object_read_attr(object, "effect"); + + if (repr) { + repr->addListener (&livepatheffect_repr_events, object); + } + + /* Register ourselves, is this necessary? */ +// sp_document_add_resource(document, "path-effect", object); +} + +/** + * Virtual release of livepatheffect members before destruction. + */ +static void +livepatheffect_release(SPObject *object) +{ +#ifdef LIVEPATHEFFECT_VERBOSE + g_print("Releasing livepatheffect"); +#endif + + LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object); + + SP_OBJECT_REPR(object)->removeListenerByData(object); + + +/* + if (SP_OBJECT_DOCUMENT(object)) { + // Unregister ourselves + sp_document_remove_resource(SP_OBJECT_DOCUMENT(object), "livepatheffect", SP_OBJECT(object)); + } + + if (gradient->ref) { + gradient->modified_connection.disconnect(); + gradient->ref->detach(); + delete gradient->ref; + gradient->ref = NULL; + } + + gradient->modified_connection.~connection(); + +*/ + + if (lpeobj->lpe) { + delete lpeobj->lpe; + lpeobj->lpe = NULL; + } + lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE; + + if (((SPObjectClass *) livepatheffect_parent_class)->release) + ((SPObjectClass *) livepatheffect_parent_class)->release(object); +} + +/** + * Virtual set: set attribute to value. + */ +static void +livepatheffect_set(SPObject *object, unsigned key, gchar const *value) +{ + LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object); +#ifdef LIVEPATHEFFECT_VERBOSE + g_print("Set livepatheffect"); +#endif + switch (key) { + case SP_PROP_PATH_EFFECT: + if (lpeobj->lpe) { + delete lpeobj->lpe; + lpeobj->lpe = NULL; + } + + if (value) { + lpeobj->effecttype = Inkscape::LivePathEffect::LPETypeConverter.get_id_from_key(value); + if (lpeobj->effecttype != Inkscape::LivePathEffect::INVALID_LPE) { + lpeobj->lpe = Inkscape::LivePathEffect::Effect::New(lpeobj->effecttype, lpeobj); + } + lpeobj->effecttype_set = true; + } else { + lpeobj->effecttype = Inkscape::LivePathEffect::INVALID_LPE; + lpeobj->effecttype_set = false; + } + object->requestModified(SP_OBJECT_MODIFIED_FLAG); + break; + } + + if (((SPObjectClass *) livepatheffect_parent_class)->set) { + ((SPObjectClass *) livepatheffect_parent_class)->set(object, key, value); + } +} + +/** + * Virtual write: write object attributes to repr. + */ +static Inkscape::XML::Node * +livepatheffect_write(SPObject *object, Inkscape::XML::Node *repr, guint flags) +{ +#ifdef LIVEPATHEFFECT_VERBOSE + g_print("Write livepatheffect"); +#endif + + LivePathEffectObject *lpeobj = LIVEPATHEFFECT(object); + + if ((flags & SP_OBJECT_WRITE_BUILD) && !repr) { + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(SP_OBJECT_DOCUMENT(object)); + repr = xml_doc->createElement("inkscape:path-effect"); + } + + if ((flags & SP_OBJECT_WRITE_ALL) || lpeobj->effecttype_set) + repr->setAttribute("effect", Inkscape::LivePathEffect::LPETypeConverter.get_key(lpeobj->effecttype).c_str()); + +// lpeobj->lpe->write(repr); something like this. + + if (((SPObjectClass *) livepatheffect_parent_class)->write) + (* ((SPObjectClass *) livepatheffect_parent_class)->write)(object, repr, flags); + + return repr; +} + +static void +livepatheffect_on_repr_attr_changed ( Inkscape::XML::Node * repr, + const gchar *key, + const gchar *oldval, + const gchar *newval, + bool is_interactive, + void * data ) +{ +#ifdef LIVEPATHEFFECT_VERBOSE + g_print("livepatheffect_on_repr_attr_changed"); +#endif + + if (!data) + return; + + LivePathEffectObject *lpeobj = (LivePathEffectObject*) data; + if (!lpeobj->lpe) + return; + + lpeobj->lpe->setParameter(repr, key, oldval, newval); + + lpeobj->requestModified(SP_OBJECT_MODIFIED_FLAG); +} + + +/* + 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/lpeobject.h b/src/live_effects/lpeobject.h index fff43cdcf..c2e9fafa7 100644 --- a/src/live_effects/lpeobject.h +++ b/src/live_effects/lpeobject.h @@ -1,52 +1,52 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_OBJECT_H -#define INKSCAPE_LIVEPATHEFFECT_OBJECT_H - -/* - * Inkscape::LivePathEffect - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "sp-object.h" -#include "effect.h" - -#define TYPE_LIVEPATHEFFECT (livepatheffect_get_type()) -#define LIVEPATHEFFECT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), TYPE_LIVEPATHEFFECT, LivePathEffectObject)) -#define IS_LIVEPATHEFFECT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), TYPE_LIVEPATHEFFECT)) - -/* -namespace Inkscape { -namespace LivePathEffect { - class Effect; -}; -}; -*/ - -struct LivePathEffectObject : public SPObject { - Inkscape::LivePathEffect::EffectType effecttype; // fixme: i think this is not needed - Inkscape::LivePathEffect::Effect *lpe; - - bool effecttype_set; -}; - -/// The LivePathEffect vtable. -struct LivePathEffectObjectClass { - SPObjectClass parent_class; -}; - -GType livepatheffect_get_type(); - -#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:encoding=utf-8:textwidth=99 : +#ifndef INKSCAPE_LIVEPATHEFFECT_OBJECT_H +#define INKSCAPE_LIVEPATHEFFECT_OBJECT_H + +/* + * Inkscape::LivePathEffect + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "sp-object.h" +#include "effect.h" + +#define TYPE_LIVEPATHEFFECT (livepatheffect_get_type()) +#define LIVEPATHEFFECT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), TYPE_LIVEPATHEFFECT, LivePathEffectObject)) +#define IS_LIVEPATHEFFECT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), TYPE_LIVEPATHEFFECT)) + +/* +namespace Inkscape { +namespace LivePathEffect { + class Effect; +}; +}; +*/ + +struct LivePathEffectObject : public SPObject { + Inkscape::LivePathEffect::EffectType effecttype; // fixme: i think this is not needed + Inkscape::LivePathEffect::Effect *lpe; + + bool effecttype_set; +}; + +/// The LivePathEffect vtable. +struct LivePathEffectObjectClass { + SPObjectClass parent_class; +}; + +GType livepatheffect_get_type(); + +#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:encoding=utf-8:textwidth=99 : diff --git a/src/live_effects/n-art-bpath-2geom.cpp b/src/live_effects/n-art-bpath-2geom.cpp index 9e5b966ea..72d4a6917 100644 --- a/src/live_effects/n-art-bpath-2geom.cpp +++ b/src/live_effects/n-art-bpath-2geom.cpp @@ -1,415 +1,415 @@ -#define SEEN_LIBNR_N_ART_BPATH_2GEOM_CPP - -/** \file - * Contains functions to convert from NArtBpath to 2geom's Path - * - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - - -#include "live_effects/n-art-bpath-2geom.h" -#include "svg/svg.h" -#include -#include <2geom/path.h> -#include <2geom/svg-path.h> -#include <2geom/svg-path-parser.h> -#include <2geom/sbasis-to-bezier.h> - -#define LPE_USE_2GEOM_CONVERSION - -//########################################################## - -#include -#include -#include -#include - -static void curve_to_svgd(std::ostream & f, Geom::Curve const* c) { - if(Geom::LineSegment const *line_segment = dynamic_cast(c)) { - f << boost::format("L %g,%g ") % (*line_segment)[1][0] % (*line_segment)[1][1]; - } - else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast(c)) { - f << boost::format("Q %g,%g %g,%g ") % (*quadratic_bezier)[1][0] % (*quadratic_bezier)[1][0] - % (*quadratic_bezier)[2][0] % (*quadratic_bezier)[2][1]; - } - else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(c)) { - f << boost::format("C %g,%g %g,%g %g,%g ") - % (*cubic_bezier)[1][0] % (*cubic_bezier)[1][1] - % (*cubic_bezier)[2][0] % (*cubic_bezier)[2][1] - % (*cubic_bezier)[3][0] % (*cubic_bezier)[3][1]; - } -// else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast(c)) { -// //get at the innards and spit them out as svgd -// } - else { - //this case handles sbasis as well as all other curve types - Geom::Path sbasis_path = Geom::path_from_sbasis(c->toSBasis(), 0.1); - - //recurse to convert the new path resulting from the sbasis to svgd - for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { - curve_to_svgd(f, &(*iter)); - } - } -} - -static void write_svgd(std::ostream & f, Geom::Path const &p) { - if(f == NULL) { - f << "ERRRRRRORRRRR"; - return; - } - - f << boost::format("M %g,%g ") % p.initialPoint()[0] % p.initialPoint()[1]; - - for(Geom::Path::const_iterator iter(p.begin()), end(p.end()); iter != end; ++iter) { - curve_to_svgd(f, &(*iter)); - } - if(p.closed()) - f << "Z "; -} - -static void write_svgd(std::ostream & f, std::vector const &p) { - std::vector::const_iterator it(p.begin()); - for(; it != p.end(); it++) { - write_svgd(f, *it); - } -} - -//########################################################## -#ifndef LPE_USE_2GEOM_CONVERSION - -static -Geom::Point point(double *nums, int ix) { - return Geom::Point(nums[ix], nums[ix + 1]); -} - -using namespace Geom; - -class OldPathBuilder { -public: - OldPathBuilder(double const &c = Geom_EPSILON) : _current_path(NULL) { - _continuity_tollerance = c; - } - - void startPathRel(Point const &p0) { startPath(p0 + _current_point); } - void startPath(Point const &p0) { - _pathset.push_back(Geom::Path()); - _current_path = &_pathset.back(); - _initial_point = _current_point = p0; - } - - void pushLineRel(Point const &p0) { pushLine(p0 + _current_point); } - void pushLine(Point const &p1) { - if (!_current_path) startPath(_current_point); - _current_path->appendNew(p1); - _current_point = p1; - } - - void pushLineRel(Point const &p0, Point const &p1) { pushLine(p0 + _current_point, p1 + _current_point); } - void pushLine(Point const &p0, Point const &p1) { - if(p0 != _current_point) startPath(p0); - pushLine(p1); - } - - void pushHorizontalRel(Coord y) { pushHorizontal(y + _current_point[1]); } - void pushHorizontal(Coord y) { - if (!_current_path) startPath(_current_point); - pushLine(Point(_current_point[0], y)); - } - - void pushVerticalRel(Coord x) { pushVertical(x + _current_point[0]); } - void pushVertical(Coord x) { - if (!_current_path) startPath(_current_point); - pushLine(Point(x, _current_point[1])); - } - - void pushQuadraticRel(Point const &p1, Point const &p2) { pushQuadratic(p1 + _current_point, p2 + _current_point); } - void pushQuadratic(Point const &p1, Point const &p2) { - if (!_current_path) startPath(_current_point); - _current_path->appendNew(p1, p2); - _current_point = p2; - } - - void pushQuadraticRel(Point const &p0, Point const &p1, Point const &p2) { - pushQuadratic(p0 + _current_point, p1 + _current_point, p2 + _current_point); - } - void pushQuadratic(Point const &p0, Point const &p1, Point const &p2) { - if(p0 != _current_point) startPath(p0); - pushQuadratic(p1, p2); - } - - void pushCubicRel(Point const &p1, Point const &p2, Point const &p3) { - pushCubic(p1 + _current_point, p2 + _current_point, p3 + _current_point); - } - void pushCubic(Point const &p1, Point const &p2, Point const &p3) { - if (!_current_path) startPath(_current_point); - _current_path->appendNew(p1, p2, p3); - _current_point = p3; - } - - void pushCubicRel(Point const &p0, Point const &p1, Point const &p2, Point const &p3) { - pushCubic(p0 + _current_point, p1 + _current_point, p2 + _current_point, p3 + _current_point); - } - void pushCubic(Point const &p0, Point const &p1, Point const &p2, Point const &p3) { - if(p0 != _current_point) startPath(p0); - pushCubic(p1, p2, p3); - } -/* - void pushEllipseRel(Point const &radii, double rotation, bool large, bool sweep, Point const &end) { - pushEllipse(radii, rotation, large, sweep, end + _current_point); - } - void pushEllipse(Point const &radii, double rotation, bool large, bool sweep, Point const &end) { - if (!_current_path) startPath(_current_point); - _current_path->append(SVGEllipticalArc(_current_point, radii[0], radii[1], rotation, large, sweep, end)); - _current_point = end; - } - - void pushEllipseRel(Point const &initial, Point const &radii, double rotation, bool large, bool sweep, Point const &end) { - pushEllipse(initial + _current_point, radii, rotation, large, sweep, end + _current_point); - } - void pushEllipse(Point const &initial, Point const &radii, double rotation, bool large, bool sweep, Point const &end) { - if(initial != _current_point) startPath(initial); - pushEllipse(radii, rotation, large, sweep, end); - }*/ - - void pushSBasis(SBasisCurve &sb) { - pushSBasis(sb.sbasis()); - } - void pushSBasis(D2 sb) { - Point initial = Point(sb[X][0][0], sb[Y][0][0]); - if (!_current_path) startPath(_current_point); - if (distance(initial, _current_point) > _continuity_tollerance) { - startPath(initial); - } else if (_current_point != initial) { - /* in this case there are three possible options - 1. connect the points with tiny line segments - this may well translate into bug reports from - users claiming "duplicate or extraneous nodes" - 2. fudge the initial point of the multidimsb - we've chosen to do this here but question the - numerical stability of this decision - 3. translate the whole sbasis so that initial is coincident - with _current_point. this could very well lead - to an accumulation of error for paths that expect - to meet in the end. - perhaps someday an option could be made to allow - the user to choose between these alternatives - if the need arises - */ - sb[X][0][0] = _current_point[X]; - sb[Y][0][0] = _current_point[Y]; - } - _current_path->append(sb); - } - - void closePath() { - if (_current_path) { - _current_path->close(true); - _current_path = NULL; - } - _current_point = _initial_point = Point(); - } - - std::vector const &peek() const { return _pathset; } - -private: - std::vector _pathset; - Path *_current_path; - Point _current_point; - Point _initial_point; - double _continuity_tollerance; -}; - -static -std::vector -read_svgd(std::istringstream & s) { - assert(s); - - OldPathBuilder builder; - - char mode = 0; - - double nums[7]; - int cur = 0; - while(!s.eof()) { - char ch; - s >> ch; - if((ch >= 'A' and ch <= 'Z') or (ch >= 'a' and ch <= 'z')) { - mode = ch; - cur = 0; - } else if (ch == ' ' or ch == '\t' or ch == '\n' or ch == '\r' or ch == ',') - continue; - else if ((ch >= '0' and ch <= '9') or ch == '-' or ch == '.' or ch == '+') { - s.unget(); - //TODO: use something else, perhaps. Unless the svg path number spec matches scan. - s >> nums[cur]; - cur++; - } - - switch(mode) { - //FIXME: "If a moveto is followed by multiple pairs of coordinates, the subsequent pairs are treated as implicit lineto commands." - case 'm': - if(cur >= 2) { - builder.startPathRel(point(nums, 0)); - cur = 0; - } - break; - case 'M': - if(cur >= 2) { - builder.startPath(point(nums, 0)); - cur = 0; - } - break; - case 'l': - if(cur >= 2) { - builder.pushLineRel(point(nums, 0)); - cur = 0; - } - break; - case 'L': - if(cur >= 2) { - builder.pushLine(point(nums, 0)); - cur = 0; - } - break; - case 'h': - if(cur >= 1) { - builder.pushHorizontalRel(nums[0]); - cur = 0; - } - break; - case 'H': - if(cur >= 1) { - builder.pushHorizontal(nums[0]); - cur = 0; - } - break; - case 'v': - if(cur >= 1) { - builder.pushVerticalRel(nums[0]); - cur = 0; - } - break; - case 'V': - if(cur >= 1) { - builder.pushVertical(nums[0]); - cur = 0; - } - break; - case 'c': - if(cur >= 6) { - builder.pushCubicRel(point(nums, 0), point(nums, 2), point(nums, 4)); - cur = 0; - } - break; - case 'C': - if(cur >= 6) { - builder.pushCubic(point(nums, 0), point(nums, 2), point(nums, 4)); - cur = 0; - } - break; - case 'q': - if(cur >= 4) { - builder.pushQuadraticRel(point(nums, 0), point(nums, 2)); - cur = 0; - } - break; - case 'Q': - if(cur >= 4) { - builder.pushQuadratic(point(nums, 0), point(nums, 2)); - cur = 0; - } - break; - case 'a': - if(cur >= 7) { - //builder.pushEllipseRel(point(nums, 0), nums[2], nums[3] > 0, nums[4] > 0, point(nums, 5)); - cur = 0; - } - break; - case 'A': - if(cur >= 7) { - //builder.pushEllipse(point(nums, 0), nums[2], nums[3] > 0, nums[4] > 0, point(nums, 5)); - cur = 0; - } - break; - case 'z': - case 'Z': - builder.closePath(); - break; - } - } - return builder.peek(); -} - - -#endif -//########################################################## - -std::vector -SVGD_to_2GeomPath (char const *svgd) -{ - std::vector pathv; -#ifdef LPE_USE_2GEOM_CONVERSION - try { - pathv = Geom::parse_svg_path(svgd); - } - catch (std::runtime_error e) { - g_warning("SVGPathParseError: %s", e.what()); - } -#else - std::istringstream ss; - std::string svgd_string = svgd; - ss.str(svgd_string); - pathv = read_svgd(ss); -#endif - return pathv; -} - - -std::vector -BPath_to_2GeomPath(NArtBpath const * bpath) -{ - std::vector pathv; - char *svgpath = sp_svg_write_path(bpath); - if (!svgpath) { - g_warning("BPath_to_2GeomPath - empty path returned"); - return pathv; - } - pathv = SVGD_to_2GeomPath(svgpath); - g_free(svgpath); - return pathv; -} - -char * -SVGD_from_2GeomPath(std::vector const & path) -{ - std::ostringstream ss; - write_svgd(ss, path); - ss.flush(); - std::string str = ss.str(); - char * svgd = g_strdup(str.c_str()); - return svgd; -} - -NArtBpath * -BPath_from_2GeomPath(std::vector const & path) -{ - char * svgd = SVGD_from_2GeomPath(path); - NArtBpath *bpath = sp_svg_read_path(svgd); - g_free(svgd); - return bpath; -} - - - -/* - 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 : +#define SEEN_LIBNR_N_ART_BPATH_2GEOM_CPP + +/** \file + * Contains functions to convert from NArtBpath to 2geom's Path + * + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + + +#include "live_effects/n-art-bpath-2geom.h" +#include "svg/svg.h" +#include +#include <2geom/path.h> +#include <2geom/svg-path.h> +#include <2geom/svg-path-parser.h> +#include <2geom/sbasis-to-bezier.h> + +#define LPE_USE_2GEOM_CONVERSION + +//########################################################## + +#include +#include +#include +#include + +static void curve_to_svgd(std::ostream & f, Geom::Curve const* c) { + if(Geom::LineSegment const *line_segment = dynamic_cast(c)) { + f << boost::format("L %g,%g ") % (*line_segment)[1][0] % (*line_segment)[1][1]; + } + else if(Geom::QuadraticBezier const *quadratic_bezier = dynamic_cast(c)) { + f << boost::format("Q %g,%g %g,%g ") % (*quadratic_bezier)[1][0] % (*quadratic_bezier)[1][0] + % (*quadratic_bezier)[2][0] % (*quadratic_bezier)[2][1]; + } + else if(Geom::CubicBezier const *cubic_bezier = dynamic_cast(c)) { + f << boost::format("C %g,%g %g,%g %g,%g ") + % (*cubic_bezier)[1][0] % (*cubic_bezier)[1][1] + % (*cubic_bezier)[2][0] % (*cubic_bezier)[2][1] + % (*cubic_bezier)[3][0] % (*cubic_bezier)[3][1]; + } +// else if(Geom::SVGEllipticalArc const *svg_elliptical_arc = dynamic_cast(c)) { +// //get at the innards and spit them out as svgd +// } + else { + //this case handles sbasis as well as all other curve types + Geom::Path sbasis_path = Geom::path_from_sbasis(c->toSBasis(), 0.1); + + //recurse to convert the new path resulting from the sbasis to svgd + for(Geom::Path::iterator iter = sbasis_path.begin(); iter != sbasis_path.end(); ++iter) { + curve_to_svgd(f, &(*iter)); + } + } +} + +static void write_svgd(std::ostream & f, Geom::Path const &p) { + if(f == NULL) { + f << "ERRRRRRORRRRR"; + return; + } + + f << boost::format("M %g,%g ") % p.initialPoint()[0] % p.initialPoint()[1]; + + for(Geom::Path::const_iterator iter(p.begin()), end(p.end()); iter != end; ++iter) { + curve_to_svgd(f, &(*iter)); + } + if(p.closed()) + f << "Z "; +} + +static void write_svgd(std::ostream & f, std::vector const &p) { + std::vector::const_iterator it(p.begin()); + for(; it != p.end(); it++) { + write_svgd(f, *it); + } +} + +//########################################################## +#ifndef LPE_USE_2GEOM_CONVERSION + +static +Geom::Point point(double *nums, int ix) { + return Geom::Point(nums[ix], nums[ix + 1]); +} + +using namespace Geom; + +class OldPathBuilder { +public: + OldPathBuilder(double const &c = Geom_EPSILON) : _current_path(NULL) { + _continuity_tollerance = c; + } + + void startPathRel(Point const &p0) { startPath(p0 + _current_point); } + void startPath(Point const &p0) { + _pathset.push_back(Geom::Path()); + _current_path = &_pathset.back(); + _initial_point = _current_point = p0; + } + + void pushLineRel(Point const &p0) { pushLine(p0 + _current_point); } + void pushLine(Point const &p1) { + if (!_current_path) startPath(_current_point); + _current_path->appendNew(p1); + _current_point = p1; + } + + void pushLineRel(Point const &p0, Point const &p1) { pushLine(p0 + _current_point, p1 + _current_point); } + void pushLine(Point const &p0, Point const &p1) { + if(p0 != _current_point) startPath(p0); + pushLine(p1); + } + + void pushHorizontalRel(Coord y) { pushHorizontal(y + _current_point[1]); } + void pushHorizontal(Coord y) { + if (!_current_path) startPath(_current_point); + pushLine(Point(_current_point[0], y)); + } + + void pushVerticalRel(Coord x) { pushVertical(x + _current_point[0]); } + void pushVertical(Coord x) { + if (!_current_path) startPath(_current_point); + pushLine(Point(x, _current_point[1])); + } + + void pushQuadraticRel(Point const &p1, Point const &p2) { pushQuadratic(p1 + _current_point, p2 + _current_point); } + void pushQuadratic(Point const &p1, Point const &p2) { + if (!_current_path) startPath(_current_point); + _current_path->appendNew(p1, p2); + _current_point = p2; + } + + void pushQuadraticRel(Point const &p0, Point const &p1, Point const &p2) { + pushQuadratic(p0 + _current_point, p1 + _current_point, p2 + _current_point); + } + void pushQuadratic(Point const &p0, Point const &p1, Point const &p2) { + if(p0 != _current_point) startPath(p0); + pushQuadratic(p1, p2); + } + + void pushCubicRel(Point const &p1, Point const &p2, Point const &p3) { + pushCubic(p1 + _current_point, p2 + _current_point, p3 + _current_point); + } + void pushCubic(Point const &p1, Point const &p2, Point const &p3) { + if (!_current_path) startPath(_current_point); + _current_path->appendNew(p1, p2, p3); + _current_point = p3; + } + + void pushCubicRel(Point const &p0, Point const &p1, Point const &p2, Point const &p3) { + pushCubic(p0 + _current_point, p1 + _current_point, p2 + _current_point, p3 + _current_point); + } + void pushCubic(Point const &p0, Point const &p1, Point const &p2, Point const &p3) { + if(p0 != _current_point) startPath(p0); + pushCubic(p1, p2, p3); + } +/* + void pushEllipseRel(Point const &radii, double rotation, bool large, bool sweep, Point const &end) { + pushEllipse(radii, rotation, large, sweep, end + _current_point); + } + void pushEllipse(Point const &radii, double rotation, bool large, bool sweep, Point const &end) { + if (!_current_path) startPath(_current_point); + _current_path->append(SVGEllipticalArc(_current_point, radii[0], radii[1], rotation, large, sweep, end)); + _current_point = end; + } + + void pushEllipseRel(Point const &initial, Point const &radii, double rotation, bool large, bool sweep, Point const &end) { + pushEllipse(initial + _current_point, radii, rotation, large, sweep, end + _current_point); + } + void pushEllipse(Point const &initial, Point const &radii, double rotation, bool large, bool sweep, Point const &end) { + if(initial != _current_point) startPath(initial); + pushEllipse(radii, rotation, large, sweep, end); + }*/ + + void pushSBasis(SBasisCurve &sb) { + pushSBasis(sb.sbasis()); + } + void pushSBasis(D2 sb) { + Point initial = Point(sb[X][0][0], sb[Y][0][0]); + if (!_current_path) startPath(_current_point); + if (distance(initial, _current_point) > _continuity_tollerance) { + startPath(initial); + } else if (_current_point != initial) { + /* in this case there are three possible options + 1. connect the points with tiny line segments + this may well translate into bug reports from + users claiming "duplicate or extraneous nodes" + 2. fudge the initial point of the multidimsb + we've chosen to do this here but question the + numerical stability of this decision + 3. translate the whole sbasis so that initial is coincident + with _current_point. this could very well lead + to an accumulation of error for paths that expect + to meet in the end. + perhaps someday an option could be made to allow + the user to choose between these alternatives + if the need arises + */ + sb[X][0][0] = _current_point[X]; + sb[Y][0][0] = _current_point[Y]; + } + _current_path->append(sb); + } + + void closePath() { + if (_current_path) { + _current_path->close(true); + _current_path = NULL; + } + _current_point = _initial_point = Point(); + } + + std::vector const &peek() const { return _pathset; } + +private: + std::vector _pathset; + Path *_current_path; + Point _current_point; + Point _initial_point; + double _continuity_tollerance; +}; + +static +std::vector +read_svgd(std::istringstream & s) { + assert(s); + + OldPathBuilder builder; + + char mode = 0; + + double nums[7]; + int cur = 0; + while(!s.eof()) { + char ch; + s >> ch; + if((ch >= 'A' and ch <= 'Z') or (ch >= 'a' and ch <= 'z')) { + mode = ch; + cur = 0; + } else if (ch == ' ' or ch == '\t' or ch == '\n' or ch == '\r' or ch == ',') + continue; + else if ((ch >= '0' and ch <= '9') or ch == '-' or ch == '.' or ch == '+') { + s.unget(); + //TODO: use something else, perhaps. Unless the svg path number spec matches scan. + s >> nums[cur]; + cur++; + } + + switch(mode) { + //FIXME: "If a moveto is followed by multiple pairs of coordinates, the subsequent pairs are treated as implicit lineto commands." + case 'm': + if(cur >= 2) { + builder.startPathRel(point(nums, 0)); + cur = 0; + } + break; + case 'M': + if(cur >= 2) { + builder.startPath(point(nums, 0)); + cur = 0; + } + break; + case 'l': + if(cur >= 2) { + builder.pushLineRel(point(nums, 0)); + cur = 0; + } + break; + case 'L': + if(cur >= 2) { + builder.pushLine(point(nums, 0)); + cur = 0; + } + break; + case 'h': + if(cur >= 1) { + builder.pushHorizontalRel(nums[0]); + cur = 0; + } + break; + case 'H': + if(cur >= 1) { + builder.pushHorizontal(nums[0]); + cur = 0; + } + break; + case 'v': + if(cur >= 1) { + builder.pushVerticalRel(nums[0]); + cur = 0; + } + break; + case 'V': + if(cur >= 1) { + builder.pushVertical(nums[0]); + cur = 0; + } + break; + case 'c': + if(cur >= 6) { + builder.pushCubicRel(point(nums, 0), point(nums, 2), point(nums, 4)); + cur = 0; + } + break; + case 'C': + if(cur >= 6) { + builder.pushCubic(point(nums, 0), point(nums, 2), point(nums, 4)); + cur = 0; + } + break; + case 'q': + if(cur >= 4) { + builder.pushQuadraticRel(point(nums, 0), point(nums, 2)); + cur = 0; + } + break; + case 'Q': + if(cur >= 4) { + builder.pushQuadratic(point(nums, 0), point(nums, 2)); + cur = 0; + } + break; + case 'a': + if(cur >= 7) { + //builder.pushEllipseRel(point(nums, 0), nums[2], nums[3] > 0, nums[4] > 0, point(nums, 5)); + cur = 0; + } + break; + case 'A': + if(cur >= 7) { + //builder.pushEllipse(point(nums, 0), nums[2], nums[3] > 0, nums[4] > 0, point(nums, 5)); + cur = 0; + } + break; + case 'z': + case 'Z': + builder.closePath(); + break; + } + } + return builder.peek(); +} + + +#endif +//########################################################## + +std::vector +SVGD_to_2GeomPath (char const *svgd) +{ + std::vector pathv; +#ifdef LPE_USE_2GEOM_CONVERSION + try { + pathv = Geom::parse_svg_path(svgd); + } + catch (std::runtime_error e) { + g_warning("SVGPathParseError: %s", e.what()); + } +#else + std::istringstream ss; + std::string svgd_string = svgd; + ss.str(svgd_string); + pathv = read_svgd(ss); +#endif + return pathv; +} + + +std::vector +BPath_to_2GeomPath(NArtBpath const * bpath) +{ + std::vector pathv; + char *svgpath = sp_svg_write_path(bpath); + if (!svgpath) { + g_warning("BPath_to_2GeomPath - empty path returned"); + return pathv; + } + pathv = SVGD_to_2GeomPath(svgpath); + g_free(svgpath); + return pathv; +} + +char * +SVGD_from_2GeomPath(std::vector const & path) +{ + std::ostringstream ss; + write_svgd(ss, path); + ss.flush(); + std::string str = ss.str(); + char * svgd = g_strdup(str.c_str()); + return svgd; +} + +NArtBpath * +BPath_from_2GeomPath(std::vector const & path) +{ + char * svgd = SVGD_from_2GeomPath(path); + NArtBpath *bpath = sp_svg_read_path(svgd); + g_free(svgd); + return bpath; +} + + + +/* + 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/n-art-bpath-2geom.h b/src/live_effects/n-art-bpath-2geom.h index 52b4cb9ee..21995656b 100644 --- a/src/live_effects/n-art-bpath-2geom.h +++ b/src/live_effects/n-art-bpath-2geom.h @@ -1,33 +1,33 @@ -#ifndef SEEN_LIBNR_N_ART_BPATH_2GEOM_H -#define SEEN_LIBNR_N_ART_BPATH_2GEOM_H - -/** \file - * Contains functions to convert from NArtBpath to 2geom's Path - * - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include <2geom/path.h> -#include - -std::vector SVGD_to_2GeomPath (char const *svgd); -std::vector BPath_to_2GeomPath (NArtBpath const *bpath); -char * SVGD_from_2GeomPath(std::vector const & path); -NArtBpath * BPath_from_2GeomPath (std::vector const & path); - - -#endif /* !SEEN_LIBNR_N_ART_BPATH_2GEOM_H */ - -/* - 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 : +#ifndef SEEN_LIBNR_N_ART_BPATH_2GEOM_H +#define SEEN_LIBNR_N_ART_BPATH_2GEOM_H + +/** \file + * Contains functions to convert from NArtBpath to 2geom's Path + * + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include <2geom/path.h> +#include + +std::vector SVGD_to_2GeomPath (char const *svgd); +std::vector BPath_to_2GeomPath (NArtBpath const *bpath); +char * SVGD_from_2GeomPath(std::vector const & path); +NArtBpath * BPath_from_2GeomPath (std::vector const & path); + + +#endif /* !SEEN_LIBNR_N_ART_BPATH_2GEOM_H */ + +/* + 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/parameter/bool.cpp b/src/live_effects/parameter/bool.cpp index 36806242f..78ce17939 100644 --- a/src/live_effects/parameter/bool.cpp +++ b/src/live_effects/parameter/bool.cpp @@ -1,93 +1,93 @@ -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_BOOL_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/bool.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include -#include "widgets/icon.h" - -#include "inkscape.h" -#include "verbs.h" -#include "helper-fns.h" - -#define noLPEBOOLPARAM_DEBUG - -namespace Inkscape { - -namespace LivePathEffect { - -BoolParam::BoolParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, bool default_value ) - : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value) -{ - checkwdg = NULL; -} - -BoolParam::~BoolParam() -{ - if (checkwdg) - delete checkwdg; -} - -void -BoolParam::param_set_default() -{ - param_setValue(defvalue); -} - -bool -BoolParam::param_readSVGValue(const gchar * strvalue) -{ - param_setValue(helperfns_read_bool(strvalue, defvalue)); - return true; // not correct: if value is unacceptable, should return false! -} - -gchar * -BoolParam::param_writeSVGValue() const -{ - gchar * str = g_strdup(value ? "true" : "false"); - return str; -} - -Gtk::Widget * -BoolParam::param_getWidget() -{ - if (!checkwdg) { - checkwdg = new Inkscape::UI::Widget::RegisteredCheckButton(); - checkwdg->init(param_label, param_tooltip, param_key, *param_wr, false, param_effect->getRepr(), param_effect->getSPDoc()); - checkwdg->setActive(value); - checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); - } - return dynamic_cast (checkwdg->_button); -} - -void -BoolParam::param_setValue(bool newvalue) -{ - value = newvalue; - if (checkwdg) - checkwdg->setActive(newvalue); -} - -} /* 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 : +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_BOOL_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/bool.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include +#include "widgets/icon.h" + +#include "inkscape.h" +#include "verbs.h" +#include "helper-fns.h" + +#define noLPEBOOLPARAM_DEBUG + +namespace Inkscape { + +namespace LivePathEffect { + +BoolParam::BoolParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, bool default_value ) + : Parameter(label, tip, key, wr, effect), value(default_value), defvalue(default_value) +{ + checkwdg = NULL; +} + +BoolParam::~BoolParam() +{ + if (checkwdg) + delete checkwdg; +} + +void +BoolParam::param_set_default() +{ + param_setValue(defvalue); +} + +bool +BoolParam::param_readSVGValue(const gchar * strvalue) +{ + param_setValue(helperfns_read_bool(strvalue, defvalue)); + return true; // not correct: if value is unacceptable, should return false! +} + +gchar * +BoolParam::param_writeSVGValue() const +{ + gchar * str = g_strdup(value ? "true" : "false"); + return str; +} + +Gtk::Widget * +BoolParam::param_getWidget() +{ + if (!checkwdg) { + checkwdg = new Inkscape::UI::Widget::RegisteredCheckButton(); + checkwdg->init(param_label, param_tooltip, param_key, *param_wr, false, param_effect->getRepr(), param_effect->getSPDoc()); + checkwdg->setActive(value); + checkwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change bool parameter")); + } + return dynamic_cast (checkwdg->_button); +} + +void +BoolParam::param_setValue(bool newvalue) +{ + value = newvalue; + if (checkwdg) + checkwdg->setActive(newvalue); +} + +} /* 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/parameter/bool.h b/src/live_effects/parameter/bool.h index 0a29a9439..13dc57b6c 100644 --- a/src/live_effects/parameter/bool.h +++ b/src/live_effects/parameter/bool.h @@ -1,59 +1,59 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_BOOL_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_BOOL_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - -#include "ui/widget/registry.h" -#include "ui/widget/registered-widget.h" - -#include "live_effects/parameter/parameter.h" - -namespace Inkscape { - -namespace LivePathEffect { - - -class BoolParam : public Parameter { -public: - BoolParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - bool default_value = false); - virtual ~BoolParam(); - - virtual Gtk::Widget * param_getWidget(); - - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_writeSVGValue() const; - - void param_setValue(bool newvalue); - virtual void param_set_default(); - - bool get_value() { return value; }; - -private: - BoolParam(const BoolParam&); - BoolParam& operator=(const BoolParam&); - - Inkscape::UI::Widget::RegisteredCheckButton * checkwdg; - - bool value; - bool defvalue; -}; - - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_BOOL_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_BOOL_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "ui/widget/registry.h" +#include "ui/widget/registered-widget.h" + +#include "live_effects/parameter/parameter.h" + +namespace Inkscape { + +namespace LivePathEffect { + + +class BoolParam : public Parameter { +public: + BoolParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + bool default_value = false); + virtual ~BoolParam(); + + virtual Gtk::Widget * param_getWidget(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_writeSVGValue() const; + + void param_setValue(bool newvalue); + virtual void param_set_default(); + + bool get_value() { return value; }; + +private: + BoolParam(const BoolParam&); + BoolParam& operator=(const BoolParam&); + + Inkscape::UI::Widget::RegisteredCheckButton * checkwdg; + + bool value; + bool defvalue; +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/enum.h b/src/live_effects/parameter/enum.h index 4fd948ee6..4ee28f895 100644 --- a/src/live_effects/parameter/enum.h +++ b/src/live_effects/parameter/enum.h @@ -1,101 +1,101 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include - -#include "ui/widget/registry.h" -#include "ui/widget/registered-enums.h" -#include - -#include "live_effects/parameter/parameter.h" -#include "verbs.h" - -namespace Inkscape { - -namespace LivePathEffect { - -template class EnumParam : public Parameter { -public: - EnumParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - const Util::EnumDataConverter& c, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - E default_value) - : Parameter(label, tip, key, wr, effect) - { - regenum = NULL; - enumdataconv = &c; - defvalue = default_value; - value = defvalue; - }; - ~EnumParam() { - if (regenum) - delete regenum; - }; - - Gtk::Widget * param_getWidget() { - if (!regenum) { - regenum = new Inkscape::UI::Widget::RegisteredEnum(); - regenum->init(param_label, param_tooltip, param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); - regenum->combobox()->set_active_by_id(value); - regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enum parameter")); - } - return dynamic_cast (regenum->labelled); - }; - - bool param_readSVGValue(const gchar * strvalue) { - if (!strvalue) { - param_set_default(); - return true; - } - - param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) ); - - return true; - }; - gchar * param_writeSVGValue() const { - gchar * str = g_strdup( enumdataconv->get_key(value).c_str() ); - return str; - }; - - E get_value() const { - return value; - } - - void param_set_default() { - param_set_value(defvalue); - } - - void param_set_value(E val) { - value = val; - if (regenum) - regenum->combobox()->set_active_by_id(value); - } - -private: - EnumParam(const EnumParam&); - EnumParam& operator=(const EnumParam&); - - UI::Widget::RegisteredEnum * regenum; - E value; - E defvalue; - - const Util::EnumDataConverter * enumdataconv; -}; - - -}; //namespace LivePathEffect - -}; //namespace Inkscape - -#endif +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_ENUM_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include + +#include "ui/widget/registry.h" +#include "ui/widget/registered-enums.h" +#include + +#include "live_effects/parameter/parameter.h" +#include "verbs.h" + +namespace Inkscape { + +namespace LivePathEffect { + +template class EnumParam : public Parameter { +public: + EnumParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + const Util::EnumDataConverter& c, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + E default_value) + : Parameter(label, tip, key, wr, effect) + { + regenum = NULL; + enumdataconv = &c; + defvalue = default_value; + value = defvalue; + }; + ~EnumParam() { + if (regenum) + delete regenum; + }; + + Gtk::Widget * param_getWidget() { + if (!regenum) { + regenum = new Inkscape::UI::Widget::RegisteredEnum(); + regenum->init(param_label, param_tooltip, param_key, *enumdataconv, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); + regenum->combobox()->set_active_by_id(value); + regenum->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change enum parameter")); + } + return dynamic_cast (regenum->labelled); + }; + + bool param_readSVGValue(const gchar * strvalue) { + if (!strvalue) { + param_set_default(); + return true; + } + + param_set_value( enumdataconv->get_id_from_key(Glib::ustring(strvalue)) ); + + return true; + }; + gchar * param_writeSVGValue() const { + gchar * str = g_strdup( enumdataconv->get_key(value).c_str() ); + return str; + }; + + E get_value() const { + return value; + } + + void param_set_default() { + param_set_value(defvalue); + } + + void param_set_value(E val) { + value = val; + if (regenum) + regenum->combobox()->set_active_by_id(value); + } + +private: + EnumParam(const EnumParam&); + EnumParam& operator=(const EnumParam&); + + UI::Widget::RegisteredEnum * regenum; + E value; + E defvalue; + + const Util::EnumDataConverter * enumdataconv; +}; + + +}; //namespace LivePathEffect + +}; //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/parameter.cpp b/src/live_effects/parameter/parameter.cpp index faed7c389..efca9908d 100644 --- a/src/live_effects/parameter/parameter.cpp +++ b/src/live_effects/parameter/parameter.cpp @@ -1,181 +1,181 @@ -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/parameter.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "libnr/nr-values.h" - -#include -#include "ui/widget/scalar.h" - -#include "svg/stringstream.h" - -#include "verbs.h" - -#define noLPEREALPARAM_DEBUG - -namespace Inkscape { - -namespace LivePathEffect { - - -Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect ) -{ - param_label = label; - param_tooltip = tip; - param_key = key; - param_wr = wr; - param_effect = effect; -} - - - -/*########################################### - * REAL PARAM - */ -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; - inc_step = 0.1; - inc_page = 1; - digits = 2; -} - -ScalarParam::~ScalarParam() -{ - if (rsu) - delete rsu; -} - -bool -ScalarParam::param_readSVGValue(const gchar * strvalue) -{ - double newval; - unsigned int success = sp_svg_number_read_d(strvalue, &newval); - if (success == 1) { - param_set_value(newval); - return true; - } - return false; -} - -gchar * -ScalarParam::param_writeSVGValue() const -{ - Inkscape::SVGOStringStream os; - os << value; - gchar * str = g_strdup(os.str().c_str()); - return str; -} - -void -ScalarParam::param_set_default() -{ - param_set_value(defvalue); -} - -void -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->is_updating()) - 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); // reset value to see whether it is in ranges -} - -void -ScalarParam::param_make_integer(bool yes) -{ - integer = yes; - digits = 0; - inc_step = 1; - inc_page = 10; - if (rsu) { - rsu->getS()->setDigits(digits); - rsu->getS()->setIncrements(inc_step, inc_page); - } -} - -Gtk::Widget * -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); - rsu->getS()->setDigits(digits); - rsu->getS()->setIncrements(inc_step, inc_page); - - rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); - } - return dynamic_cast (rsu->getS()); -} - -void -ScalarParam::param_set_digits(unsigned digits) -{ - this->digits = digits; - if (rsu) { - rsu->getS()->setDigits(digits); - } -} - -void -ScalarParam::param_set_increments(double step, double page) -{ - inc_step = step; - inc_page = page; - if (rsu) { - rsu->getS()->setIncrements(inc_step, inc_page); - } -} - - - - -} /* 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 : +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/parameter.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "libnr/nr-values.h" + +#include +#include "ui/widget/scalar.h" + +#include "svg/stringstream.h" + +#include "verbs.h" + +#define noLPEREALPARAM_DEBUG + +namespace Inkscape { + +namespace LivePathEffect { + + +Parameter::Parameter( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect ) +{ + param_label = label; + param_tooltip = tip; + param_key = key; + param_wr = wr; + param_effect = effect; +} + + + +/*########################################### + * REAL PARAM + */ +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; + inc_step = 0.1; + inc_page = 1; + digits = 2; +} + +ScalarParam::~ScalarParam() +{ + if (rsu) + delete rsu; +} + +bool +ScalarParam::param_readSVGValue(const gchar * strvalue) +{ + double newval; + unsigned int success = sp_svg_number_read_d(strvalue, &newval); + if (success == 1) { + param_set_value(newval); + return true; + } + return false; +} + +gchar * +ScalarParam::param_writeSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << value; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +void +ScalarParam::param_set_default() +{ + param_set_value(defvalue); +} + +void +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->is_updating()) + 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); // reset value to see whether it is in ranges +} + +void +ScalarParam::param_make_integer(bool yes) +{ + integer = yes; + digits = 0; + inc_step = 1; + inc_page = 10; + if (rsu) { + rsu->getS()->setDigits(digits); + rsu->getS()->setIncrements(inc_step, inc_page); + } +} + +Gtk::Widget * +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); + rsu->getS()->setDigits(digits); + rsu->getS()->setIncrements(inc_step, inc_page); + + rsu->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change scalar parameter")); + } + return dynamic_cast (rsu->getS()); +} + +void +ScalarParam::param_set_digits(unsigned digits) +{ + this->digits = digits; + if (rsu) { + rsu->getS()->setDigits(digits); + } +} + +void +ScalarParam::param_set_increments(double step, double page) +{ + inc_step = step; + inc_page = page; + if (rsu) { + rsu->getS()->setIncrements(inc_step, inc_page); + } +} + + + + +} /* 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/parameter/parameter.h b/src/live_effects/parameter/parameter.h index fb0bb7103..a6b05bf36 100644 --- a/src/live_effects/parameter/parameter.h +++ b/src/live_effects/parameter/parameter.h @@ -1,108 +1,108 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include <2geom/point.h> -#include <2geom/path.h> - -#include "ui/widget/registry.h" -#include "ui/widget/registered-widget.h" - -namespace Gtk { - class Widget; -} - -namespace Inkscape { - -namespace LivePathEffect { - -class Effect; - -class Parameter { -public: - Parameter( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect); - virtual ~Parameter() {}; - - virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted. - virtual gchar * param_writeSVGValue() const = 0; - - virtual void param_set_default() = 0; - - // This returns pointer to the parameter's widget to be put in the live-effects dialog. Must also create the - // necessary widget if it does not exist yet. - virtual Gtk::Widget * param_getWidget() = 0; - virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; - - Glib::ustring param_key; - Inkscape::UI::Widget::Registry * param_wr; - Glib::ustring param_label; - -protected: - Glib::ustring param_tooltip; - - Effect* param_effect; - -private: - Parameter(const Parameter&); - Parameter& operator=(const Parameter&); -}; - - -class ScalarParam : public Parameter { -public: - 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); - virtual ~ScalarParam(); - - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_writeSVGValue() const; - - virtual 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); - void param_set_digits(unsigned digits); - void param_set_increments(double step, double page); - - virtual Gtk::Widget * param_getWidget(); - - inline operator gdouble() - { return value; }; - -protected: - gdouble value; - gdouble min; - gdouble max; - bool integer; - gdouble defvalue; - Inkscape::UI::Widget::RegisteredScalar * rsu; - unsigned digits; - double inc_step; - double inc_page; - -private: - ScalarParam(const ScalarParam&); - ScalarParam& operator=(const ScalarParam&); -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include <2geom/point.h> +#include <2geom/path.h> + +#include "ui/widget/registry.h" +#include "ui/widget/registered-widget.h" + +namespace Gtk { + class Widget; +} + +namespace Inkscape { + +namespace LivePathEffect { + +class Effect; + +class Parameter { +public: + Parameter( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect); + virtual ~Parameter() {}; + + virtual bool param_readSVGValue(const gchar * strvalue) = 0; // returns true if new value is valid / accepted. + virtual gchar * param_writeSVGValue() const = 0; + + virtual void param_set_default() = 0; + + // This returns pointer to the parameter's widget to be put in the live-effects dialog. Must also create the + // necessary widget if it does not exist yet. + virtual Gtk::Widget * param_getWidget() = 0; + virtual Glib::ustring * param_getTooltip() { return ¶m_tooltip; }; + + Glib::ustring param_key; + Inkscape::UI::Widget::Registry * param_wr; + Glib::ustring param_label; + +protected: + Glib::ustring param_tooltip; + + Effect* param_effect; + +private: + Parameter(const Parameter&); + Parameter& operator=(const Parameter&); +}; + + +class ScalarParam : public Parameter { +public: + 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); + virtual ~ScalarParam(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_writeSVGValue() const; + + virtual 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); + void param_set_digits(unsigned digits); + void param_set_increments(double step, double page); + + virtual Gtk::Widget * param_getWidget(); + + inline operator gdouble() + { return value; }; + +protected: + gdouble value; + gdouble min; + gdouble max; + bool integer; + gdouble defvalue; + Inkscape::UI::Widget::RegisteredScalar * rsu; + unsigned digits; + double inc_step; + double inc_page; + +private: + ScalarParam(const ScalarParam&); + ScalarParam& operator=(const ScalarParam&); +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 4c73f0aee..ff596bfc6 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -1,182 +1,182 @@ -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_PATH_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/path.h" -#include "live_effects/effect.h" -#include "live_effects/n-art-bpath-2geom.h" -#include "svg/svg.h" -#include <2geom/svg-path-parser.h> -#include <2geom/sbasis-to-bezier.h> -#include <2geom/d2.h> - -#include "ui/widget/point.h" -#include "widgets/icon.h" -#include -#include "selection-chemistry.h" - -#include "desktop.h" -#include "inkscape.h" -#include "message-stack.h" -#include "verbs.h" -#include "document.h" - -#define noLPEPATHPARAM_DEBUG - -namespace Inkscape { - -namespace LivePathEffect { - -PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, const gchar * default_value) - : Parameter(label, tip, key, wr, effect) -{ - _widget = NULL; - _tooltips = NULL; - defvalue = g_strdup(default_value); - param_readSVGValue(defvalue); -} - -PathParam::~PathParam() -{ - if (_tooltips) - delete _tooltips; - // _widget is managed by GTK so do not delete! - - g_free(defvalue); -} - -void -PathParam::param_set_default() -{ - param_readSVGValue(defvalue); -} - -bool -PathParam::param_readSVGValue(const gchar * strvalue) -{ - if (strvalue) { - Geom::Piecewise > newpath; - std::vector temppath = SVGD_to_2GeomPath(strvalue); - for (unsigned int i=0; i < temppath.size(); i++) { - newpath.concat( temppath[i].toPwSb() ); - } - *( dynamic_cast > *> (this) ) = newpath; - signal_path_changed.emit(); - return true; - } - - return false; -} - -gchar * -PathParam::param_writeSVGValue() const -{ - const std::vector temppath = - Geom::path_from_piecewise(* dynamic_cast > *> (this), LPE_CONVERSION_TOLERANCE); - gchar * svgd = SVGD_from_2GeomPath( temppath ); - return svgd; -} - -Gtk::Widget * -PathParam::param_getWidget() -{ - if (!_widget) { - _widget = Gtk::manage(new Gtk::HBox()); - _tooltips = new Gtk::Tooltips(); - - Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); - static_cast(_widget)->pack_start(*pLabel, true, true); - _tooltips->set_tip(*pLabel, param_tooltip); - - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_edit_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - _tooltips->set_tip(*pButton, _("Edit on-canvas")); -#ifndef LPEPATHPARAM_DEBUG - pButton->set_sensitive(false); -#endif - - pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) ); - pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_paste_button_click)); - static_cast(_widget)->pack_start(*pButton, true, true); - _tooltips->set_tip(*pButton, _("Paste path")); - - static_cast(_widget)->show_all_children(); - - } - return dynamic_cast (_widget); -} - -void -PathParam::on_edit_button_click() -{ - g_message("give this path to edit on canvas!"); -} - -void -PathParam::on_paste_button_click() -{ - // check if something is in the clipboard - GSList * clipboard = sp_selection_get_clipboard(); - if (clipboard == NULL || clipboard->data == NULL) { - SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard.")); - return; - } - - Inkscape::XML::Node *repr = (Inkscape::XML::Node *) clipboard->data; - if (!strcmp (repr->name(), "svg:path")) { - const char * svgd = repr->attribute("d"); - if (svgd) { - if (strchr(svgd,'A')) { // FIXME: temporary hack until 2Geom supports arcs in SVGD - SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE, - _("This effect does not support arcs yet, try to convert to path.") ); - } else { - param_write_to_repr(svgd); - signal_path_pasted.emit(); - sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, - _("Paste path parameter")); - } - } - } else { - SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Clipboard does not contain a path.")); - } - -} - -void -PathParam::param_write_to_repr(const char * svgd) -{ - param_effect->getRepr()->setAttribute(param_key.c_str(), svgd); -} - - -} /* 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 : +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_PATH_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/path.h" +#include "live_effects/effect.h" +#include "live_effects/n-art-bpath-2geom.h" +#include "svg/svg.h" +#include <2geom/svg-path-parser.h> +#include <2geom/sbasis-to-bezier.h> +#include <2geom/d2.h> + +#include "ui/widget/point.h" +#include "widgets/icon.h" +#include +#include "selection-chemistry.h" + +#include "desktop.h" +#include "inkscape.h" +#include "message-stack.h" +#include "verbs.h" +#include "document.h" + +#define noLPEPATHPARAM_DEBUG + +namespace Inkscape { + +namespace LivePathEffect { + +PathParam::PathParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, const gchar * default_value) + : Parameter(label, tip, key, wr, effect) +{ + _widget = NULL; + _tooltips = NULL; + defvalue = g_strdup(default_value); + param_readSVGValue(defvalue); +} + +PathParam::~PathParam() +{ + if (_tooltips) + delete _tooltips; + // _widget is managed by GTK so do not delete! + + g_free(defvalue); +} + +void +PathParam::param_set_default() +{ + param_readSVGValue(defvalue); +} + +bool +PathParam::param_readSVGValue(const gchar * strvalue) +{ + if (strvalue) { + Geom::Piecewise > newpath; + std::vector temppath = SVGD_to_2GeomPath(strvalue); + for (unsigned int i=0; i < temppath.size(); i++) { + newpath.concat( temppath[i].toPwSb() ); + } + *( dynamic_cast > *> (this) ) = newpath; + signal_path_changed.emit(); + return true; + } + + return false; +} + +gchar * +PathParam::param_writeSVGValue() const +{ + const std::vector temppath = + Geom::path_from_piecewise(* dynamic_cast > *> (this), LPE_CONVERSION_TOLERANCE); + gchar * svgd = SVGD_from_2GeomPath( temppath ); + return svgd; +} + +Gtk::Widget * +PathParam::param_getWidget() +{ + if (!_widget) { + _widget = Gtk::manage(new Gtk::HBox()); + _tooltips = new Gtk::Tooltips(); + + Gtk::Label* pLabel = Gtk::manage(new Gtk::Label(param_label)); + static_cast(_widget)->pack_start(*pLabel, true, true); + _tooltips->set_tip(*pLabel, param_tooltip); + + Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_edit_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + _tooltips->set_tip(*pButton, _("Edit on-canvas")); +#ifndef LPEPATHPARAM_DEBUG + pButton->set_sensitive(false); +#endif + + pIcon = Gtk::manage( sp_icon_get_icon( GTK_STOCK_PASTE, Inkscape::ICON_SIZE_BUTTON) ); + pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PathParam::on_paste_button_click)); + static_cast(_widget)->pack_start(*pButton, true, true); + _tooltips->set_tip(*pButton, _("Paste path")); + + static_cast(_widget)->show_all_children(); + + } + return dynamic_cast (_widget); +} + +void +PathParam::on_edit_button_click() +{ + g_message("give this path to edit on canvas!"); +} + +void +PathParam::on_paste_button_click() +{ + // check if something is in the clipboard + GSList * clipboard = sp_selection_get_clipboard(); + if (clipboard == NULL || clipboard->data == NULL) { + SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard.")); + return; + } + + Inkscape::XML::Node *repr = (Inkscape::XML::Node *) clipboard->data; + if (!strcmp (repr->name(), "svg:path")) { + const char * svgd = repr->attribute("d"); + if (svgd) { + if (strchr(svgd,'A')) { // FIXME: temporary hack until 2Geom supports arcs in SVGD + SP_ACTIVE_DESKTOP->messageStack()->flash( Inkscape::WARNING_MESSAGE, + _("This effect does not support arcs yet, try to convert to path.") ); + } else { + param_write_to_repr(svgd); + signal_path_pasted.emit(); + sp_document_done(param_effect->getSPDoc(), SP_VERB_DIALOG_LIVE_PATH_EFFECT, + _("Paste path parameter")); + } + } + } else { + SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Clipboard does not contain a path.")); + } + +} + +void +PathParam::param_write_to_repr(const char * svgd) +{ + param_effect->getRepr()->setAttribute(param_key.c_str(), svgd); +} + + +} /* 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/parameter/path.h b/src/live_effects/parameter/path.h index e26611b85..e966b7ebd 100644 --- a/src/live_effects/parameter/path.h +++ b/src/live_effects/parameter/path.h @@ -1,66 +1,66 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_PATH_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_PATH_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include <2geom/path.h> - -#include "ui/widget/registry.h" -#include - -#include "live_effects/parameter/parameter.h" - -#include - -namespace Inkscape { - -namespace LivePathEffect { - -class PathParam : public Geom::Piecewise >, public Parameter { -public: - PathParam ( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - const gchar * default_value = "M0,0 L1,1"); - ~PathParam(); - - Gtk::Widget * param_getWidget(); - - bool param_readSVGValue(const gchar * strvalue); - gchar * param_writeSVGValue() const; - - void param_set_default(); - - sigc::signal signal_path_pasted; - sigc::signal signal_path_changed; - -private: - PathParam(const PathParam&); - PathParam& operator=(const PathParam&); - - Gtk::Widget * _widget; - Gtk::Tooltips * _tooltips; - - void param_write_to_repr(const char * svgd); - - void on_edit_button_click(); - void on_paste_button_click(); - - gchar * defvalue; -}; - - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_PATH_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_PATH_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include <2geom/path.h> + +#include "ui/widget/registry.h" +#include + +#include "live_effects/parameter/parameter.h" + +#include + +namespace Inkscape { + +namespace LivePathEffect { + +class PathParam : public Geom::Piecewise >, public Parameter { +public: + PathParam ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + const gchar * default_value = "M0,0 L1,1"); + ~PathParam(); + + Gtk::Widget * param_getWidget(); + + bool param_readSVGValue(const gchar * strvalue); + gchar * param_writeSVGValue() const; + + void param_set_default(); + + sigc::signal signal_path_pasted; + sigc::signal signal_path_changed; + +private: + PathParam(const PathParam&); + PathParam& operator=(const PathParam&); + + Gtk::Widget * _widget; + Gtk::Tooltips * _tooltips; + + void param_write_to_repr(const char * svgd); + + void on_edit_button_click(); + void on_paste_button_click(); + + gchar * defvalue; +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/point.cpp b/src/live_effects/parameter/point.cpp index 3c42dcbfe..caa81692f 100644 --- a/src/live_effects/parameter/point.cpp +++ b/src/live_effects/parameter/point.cpp @@ -1,173 +1,173 @@ -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/point.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "svg/stringstream.h" -#include -#include "ui/widget/point.h" -#include "widgets/icon.h" - -#include "knot.h" -#include "inkscape.h" -#include "verbs.h" - -#define noLPEPOINTPARAM_DEBUG - -#define PRM_KNOT_COLOR_NORMAL 0xffffff00 -#define PRM_KNOT_COLOR_SELECTED 0x0000ff00 - -namespace Inkscape { - -namespace LivePathEffect { - -PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, Geom::Point default_value ) - : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value) -{ - _widget = NULL; - pointwdg = NULL; - knot = NULL; - _tooltips = NULL; -} - -PointParam::~PointParam() -{ - if (pointwdg) - delete pointwdg; - if (_tooltips) - delete _tooltips; - - if (knot) - g_object_unref (G_OBJECT (knot)); -} - -void -PointParam::param_set_default() -{ - param_setValue(defvalue); -} - -bool -PointParam::param_readSVGValue(const gchar * strvalue) -{ - gchar ** strarray = g_strsplit(strvalue, ",", 2); - double newx, newy; - unsigned int success = sp_svg_number_read_d(strarray[0], &newx); - success += sp_svg_number_read_d(strarray[1], &newy); - g_strfreev (strarray); - if (success == 2) { - param_setValue( Geom::Point(newx, newy) ); - return true; - } - return false; -} - -gchar * -PointParam::param_writeSVGValue() const -{ - Inkscape::SVGOStringStream os; - os << (*this)[0] << "," << (*this)[1]; - gchar * str = g_strdup(os.str().c_str()); - return str; -} - -Gtk::Widget * -PointParam::param_getWidget() -{ - if (!_widget) { - pointwdg = new Inkscape::UI::Widget::RegisteredPoint(); - pointwdg->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); - pointwdg->setValue( (*this)[0], (*this)[1] ); - pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); - - Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); - Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); - pButton->set_relief(Gtk::RELIEF_NONE); - pIcon->show(); - pButton->add(*pIcon); - pButton->show(); - pButton->signal_clicked().connect(sigc::mem_fun(*this, &PointParam::on_button_click)); -#ifndef LPEPOINTPARAM_DEBUG - pButton->set_sensitive(false); -#endif - - _widget = Gtk::manage( new Gtk::HBox() ); - static_cast(_widget)->pack_start(*pButton, true, true); - static_cast(_widget)->pack_start(*(pointwdg->getPoint()), true, true); - static_cast(_widget)->show_all_children(); - - _tooltips = new Gtk::Tooltips(); - _tooltips->set_tip(*pButton, _("Edit on-canvas")); - } - return dynamic_cast (_widget); -} - -void -PointParam::param_setValue(Geom::Point newpoint) -{ - *dynamic_cast( this ) = newpoint; - if (pointwdg) - pointwdg->setValue(newpoint[0], newpoint[1]); -} - - -// CALLBACKS: - -void -PointParam::on_button_click() -{ - g_message("add knot to canvas on correct location :S"); - - if (!knot) { - // create the knot - knot = sp_knot_new (SP_ACTIVE_DESKTOP, NULL); - knot->setMode(SP_KNOT_MODE_XOR); - knot->setFill(PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL); - knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); - sp_knot_update_ctrl(knot); - - // move knot to the given point - sp_knot_set_position (knot, &NR::Point((*this)[0], (*this)[1]), SP_KNOT_STATE_NORMAL); - sp_knot_show (knot); -/* - // connect knot's signals - if ( (draggable) // it can be NULL if a node in unsnapped (eg. focus point unsnapped from center) - // luckily, midstops never snap to other nodes so are never unsnapped... - && ( (draggable->point_type == POINT_LG_MID) - || (draggable->point_type == POINT_RG_MID1) - || (draggable->point_type == POINT_RG_MID2) ) ) - { - this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_midpoint_handler), this); - } else { - this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_handler), this); - } - g_signal_connect (G_OBJECT (this->knot), "clicked", G_CALLBACK (gr_knot_clicked_handler), this); - g_signal_connect (G_OBJECT (this->knot), "doubleclicked", G_CALLBACK (gr_knot_doubleclicked_handler), this); - g_signal_connect (G_OBJECT (this->knot), "grabbed", G_CALLBACK (gr_knot_grabbed_handler), this); - g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (gr_knot_ungrabbed_handler), this); -*/ - } -} - -} /* 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 : +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/point.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "svg/stringstream.h" +#include +#include "ui/widget/point.h" +#include "widgets/icon.h" + +#include "knot.h" +#include "inkscape.h" +#include "verbs.h" + +#define noLPEPOINTPARAM_DEBUG + +#define PRM_KNOT_COLOR_NORMAL 0xffffff00 +#define PRM_KNOT_COLOR_SELECTED 0x0000ff00 + +namespace Inkscape { + +namespace LivePathEffect { + +PointParam::PointParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, Geom::Point default_value ) + : Geom::Point(default_value), Parameter(label, tip, key, wr, effect), defvalue(default_value) +{ + _widget = NULL; + pointwdg = NULL; + knot = NULL; + _tooltips = NULL; +} + +PointParam::~PointParam() +{ + if (pointwdg) + delete pointwdg; + if (_tooltips) + delete _tooltips; + + if (knot) + g_object_unref (G_OBJECT (knot)); +} + +void +PointParam::param_set_default() +{ + param_setValue(defvalue); +} + +bool +PointParam::param_readSVGValue(const gchar * strvalue) +{ + gchar ** strarray = g_strsplit(strvalue, ",", 2); + double newx, newy; + unsigned int success = sp_svg_number_read_d(strarray[0], &newx); + success += sp_svg_number_read_d(strarray[1], &newy); + g_strfreev (strarray); + if (success == 2) { + param_setValue( Geom::Point(newx, newy) ); + return true; + } + return false; +} + +gchar * +PointParam::param_writeSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << (*this)[0] << "," << (*this)[1]; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +Gtk::Widget * +PointParam::param_getWidget() +{ + if (!_widget) { + pointwdg = new Inkscape::UI::Widget::RegisteredPoint(); + pointwdg->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); + pointwdg->setValue( (*this)[0], (*this)[1] ); + pointwdg->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change point parameter")); + + Gtk::Widget* pIcon = Gtk::manage( sp_icon_get_icon( "draw_node", Inkscape::ICON_SIZE_BUTTON) ); + Gtk::Button * pButton = Gtk::manage(new Gtk::Button()); + pButton->set_relief(Gtk::RELIEF_NONE); + pIcon->show(); + pButton->add(*pIcon); + pButton->show(); + pButton->signal_clicked().connect(sigc::mem_fun(*this, &PointParam::on_button_click)); +#ifndef LPEPOINTPARAM_DEBUG + pButton->set_sensitive(false); +#endif + + _widget = Gtk::manage( new Gtk::HBox() ); + static_cast(_widget)->pack_start(*pButton, true, true); + static_cast(_widget)->pack_start(*(pointwdg->getPoint()), true, true); + static_cast(_widget)->show_all_children(); + + _tooltips = new Gtk::Tooltips(); + _tooltips->set_tip(*pButton, _("Edit on-canvas")); + } + return dynamic_cast (_widget); +} + +void +PointParam::param_setValue(Geom::Point newpoint) +{ + *dynamic_cast( this ) = newpoint; + if (pointwdg) + pointwdg->setValue(newpoint[0], newpoint[1]); +} + + +// CALLBACKS: + +void +PointParam::on_button_click() +{ + g_message("add knot to canvas on correct location :S"); + + if (!knot) { + // create the knot + knot = sp_knot_new (SP_ACTIVE_DESKTOP, NULL); + knot->setMode(SP_KNOT_MODE_XOR); + knot->setFill(PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL, PRM_KNOT_COLOR_NORMAL); + knot->setStroke(0x000000ff, 0x000000ff, 0x000000ff); + sp_knot_update_ctrl(knot); + + // move knot to the given point + sp_knot_set_position (knot, &NR::Point((*this)[0], (*this)[1]), SP_KNOT_STATE_NORMAL); + sp_knot_show (knot); +/* + // connect knot's signals + if ( (draggable) // it can be NULL if a node in unsnapped (eg. focus point unsnapped from center) + // luckily, midstops never snap to other nodes so are never unsnapped... + && ( (draggable->point_type == POINT_LG_MID) + || (draggable->point_type == POINT_RG_MID1) + || (draggable->point_type == POINT_RG_MID2) ) ) + { + this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_midpoint_handler), this); + } else { + this->handler_id = g_signal_connect (G_OBJECT (this->knot), "moved", G_CALLBACK (gr_knot_moved_handler), this); + } + g_signal_connect (G_OBJECT (this->knot), "clicked", G_CALLBACK (gr_knot_clicked_handler), this); + g_signal_connect (G_OBJECT (this->knot), "doubleclicked", G_CALLBACK (gr_knot_doubleclicked_handler), this); + g_signal_connect (G_OBJECT (this->knot), "grabbed", G_CALLBACK (gr_knot_grabbed_handler), this); + g_signal_connect (G_OBJECT (this->knot), "ungrabbed", G_CALLBACK (gr_knot_ungrabbed_handler), this); +*/ + } +} + +} /* 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/parameter/point.h b/src/live_effects/parameter/point.h index c1d6681a2..c3ed876f7 100644 --- a/src/live_effects/parameter/point.h +++ b/src/live_effects/parameter/point.h @@ -1,65 +1,65 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include <2geom/point.h> - -#include "ui/widget/registry.h" -#include "ui/widget/registered-widget.h" -#include - -#include "live_effects/parameter/parameter.h" - -struct SPKnot; - -namespace Inkscape { - -namespace LivePathEffect { - - -class PointParam : public Geom::Point, public Parameter { -public: - PointParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - Geom::Point default_value = Geom::Point(0,0)); - ~PointParam(); - - Gtk::Widget * param_getWidget(); - - bool param_readSVGValue(const gchar * strvalue); - gchar * param_writeSVGValue() const; - - void param_setValue(Geom::Point newpoint); - void param_set_default(); - -private: - PointParam(const PointParam&); - PointParam& operator=(const PointParam&); - - Gtk::Widget * _widget; - Gtk::Tooltips * _tooltips; - Inkscape::UI::Widget::RegisteredPoint * pointwdg; - void on_button_click(); - - SPKnot *knot; - - Geom::Point defvalue; -}; - - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_POINT_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include +#include <2geom/point.h> + +#include "ui/widget/registry.h" +#include "ui/widget/registered-widget.h" +#include + +#include "live_effects/parameter/parameter.h" + +struct SPKnot; + +namespace Inkscape { + +namespace LivePathEffect { + + +class PointParam : public Geom::Point, public Parameter { +public: + PointParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + Geom::Point default_value = Geom::Point(0,0)); + ~PointParam(); + + Gtk::Widget * param_getWidget(); + + bool param_readSVGValue(const gchar * strvalue); + gchar * param_writeSVGValue() const; + + void param_setValue(Geom::Point newpoint); + void param_set_default(); + +private: + PointParam(const PointParam&); + PointParam& operator=(const PointParam&); + + Gtk::Widget * _widget; + Gtk::Tooltips * _tooltips; + Inkscape::UI::Widget::RegisteredPoint * pointwdg; + void on_button_click(); + + SPKnot *knot; + + Geom::Point defvalue; +}; + + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif diff --git a/src/live_effects/parameter/random.cpp b/src/live_effects/parameter/random.cpp index 846c2f9e8..959b21114 100644 --- a/src/live_effects/parameter/random.cpp +++ b/src/live_effects/parameter/random.cpp @@ -1,194 +1,194 @@ -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_CPP - -/* - * Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/random.h" -#include "live_effects/effect.h" -#include "svg/svg.h" -#include "libnr/nr-values.h" - -#include -#include "ui/widget/random.h" - -#include "svg/stringstream.h" - -#include "verbs.h" - -#define noLPERANDOMPARAM_DEBUG - -namespace Inkscape { - -namespace LivePathEffect { - - -RandomParam::RandomParam( const Glib::ustring& label, const Glib::ustring& tip, - const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, - Effect* effect, gdouble default_value, long default_seed) - : Parameter(label, tip, key, wr, effect) -{ - defvalue = default_value; - value = defvalue; - min = -NR_HUGE; - max = NR_HUGE; - integer = false; - regrandom = NULL; - - defseed = default_seed; - startseed = defseed; - seed = startseed; -} - -RandomParam::~RandomParam() -{ - if (regrandom) - delete regrandom; -} - -bool -RandomParam::param_readSVGValue(const gchar * strvalue) -{ - double newval, newstartseed; - gchar** stringarray = g_strsplit (strvalue, ";", 2); - unsigned int success = sp_svg_number_read_d(stringarray[0], &newval); - if (success == 1) { - success += sp_svg_number_read_d(stringarray[1], &newstartseed); - if (success == 2) { - param_set_value(newval, newstartseed); - } else { - param_set_value(newval, defseed); - } - g_strfreev(stringarray); - return true; - } - g_strfreev(stringarray); - return false; -} - -gchar * -RandomParam::param_writeSVGValue() const -{ - Inkscape::SVGOStringStream os; - os << value << ';' << startseed; - gchar * str = g_strdup(os.str().c_str()); - return str; -} - -void -RandomParam::param_set_default() -{ - param_set_value(defvalue, defseed); -} - -void -RandomParam::param_set_value(gdouble val, long newseed) -{ - value = val; - if (integer) - value = round(value); - if (value > max) - value = max; - if (value < min) - value = min; - - startseed = setup_seed(newseed); - seed = startseed; - - if (regrandom) - regrandom->setValue(value, startseed); -} - -void -RandomParam::param_set_range(gdouble min, gdouble max) -{ - this->min = min; - this->max = max; - if (regrandom) - regrandom->getR()->setRange(min, max); - - param_set_value(value, startseed); // reset value, to check whether it is in range -} - -void -RandomParam::param_make_integer(bool yes) -{ - integer = yes; - if (regrandom) { - regrandom->getR()->setDigits(0); - regrandom->getR()->setIncrements(1, 10); - } -} - -void -RandomParam::resetRandomizer() -{ - seed = startseed; -} - - -Gtk::Widget * -RandomParam::param_getWidget() -{ - // TODO: add a button to set a different startseed - if (!regrandom) { - regrandom = new Inkscape::UI::Widget::RegisteredRandom(); - regrandom->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); - regrandom->setValue(value, startseed); - if (integer) - param_make_integer(); - - regrandom->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change random parameter")); - } - return dynamic_cast (regrandom->getR()); -} - -RandomParam::operator gdouble() -{ - return rand() * value; -}; - -/* RNG stolen from /display/nr-filter-turbulence.cpp */ -#define RAND_m 2147483647 /* 2**31 - 1 */ -#define RAND_a 16807 /* 7**5; primitive root of m */ -#define RAND_q 127773 /* m / a */ -#define RAND_r 2836 /* m % a */ -#define BSize 0x100 - -long -RandomParam::setup_seed(long lSeed) -{ - if (lSeed <= 0) lSeed = -(lSeed % (RAND_m - 1)) + 1; - if (lSeed > RAND_m - 1) lSeed = RAND_m - 1; - return lSeed; -} - -// generates random number between 0 and 1 -gdouble -RandomParam::rand() -{ - long result; - result = RAND_a * (seed % RAND_q) - RAND_r * (seed / RAND_q); - if (result <= 0) result += RAND_m; - seed = result; - - gdouble dresult = (gdouble)(result % BSize) / BSize; - return dresult; -} - - -} /* 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 : +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_CPP + +/* + * Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/random.h" +#include "live_effects/effect.h" +#include "svg/svg.h" +#include "libnr/nr-values.h" + +#include +#include "ui/widget/random.h" + +#include "svg/stringstream.h" + +#include "verbs.h" + +#define noLPERANDOMPARAM_DEBUG + +namespace Inkscape { + +namespace LivePathEffect { + + +RandomParam::RandomParam( const Glib::ustring& label, const Glib::ustring& tip, + const Glib::ustring& key, Inkscape::UI::Widget::Registry* wr, + Effect* effect, gdouble default_value, long default_seed) + : Parameter(label, tip, key, wr, effect) +{ + defvalue = default_value; + value = defvalue; + min = -NR_HUGE; + max = NR_HUGE; + integer = false; + regrandom = NULL; + + defseed = default_seed; + startseed = defseed; + seed = startseed; +} + +RandomParam::~RandomParam() +{ + if (regrandom) + delete regrandom; +} + +bool +RandomParam::param_readSVGValue(const gchar * strvalue) +{ + double newval, newstartseed; + gchar** stringarray = g_strsplit (strvalue, ";", 2); + unsigned int success = sp_svg_number_read_d(stringarray[0], &newval); + if (success == 1) { + success += sp_svg_number_read_d(stringarray[1], &newstartseed); + if (success == 2) { + param_set_value(newval, newstartseed); + } else { + param_set_value(newval, defseed); + } + g_strfreev(stringarray); + return true; + } + g_strfreev(stringarray); + return false; +} + +gchar * +RandomParam::param_writeSVGValue() const +{ + Inkscape::SVGOStringStream os; + os << value << ';' << startseed; + gchar * str = g_strdup(os.str().c_str()); + return str; +} + +void +RandomParam::param_set_default() +{ + param_set_value(defvalue, defseed); +} + +void +RandomParam::param_set_value(gdouble val, long newseed) +{ + value = val; + if (integer) + value = round(value); + if (value > max) + value = max; + if (value < min) + value = min; + + startseed = setup_seed(newseed); + seed = startseed; + + if (regrandom) + regrandom->setValue(value, startseed); +} + +void +RandomParam::param_set_range(gdouble min, gdouble max) +{ + this->min = min; + this->max = max; + if (regrandom) + regrandom->getR()->setRange(min, max); + + param_set_value(value, startseed); // reset value, to check whether it is in range +} + +void +RandomParam::param_make_integer(bool yes) +{ + integer = yes; + if (regrandom) { + regrandom->getR()->setDigits(0); + regrandom->getR()->setIncrements(1, 10); + } +} + +void +RandomParam::resetRandomizer() +{ + seed = startseed; +} + + +Gtk::Widget * +RandomParam::param_getWidget() +{ + // TODO: add a button to set a different startseed + if (!regrandom) { + regrandom = new Inkscape::UI::Widget::RegisteredRandom(); + regrandom->init(param_label, param_tooltip, param_key, *param_wr, param_effect->getRepr(), param_effect->getSPDoc()); + regrandom->setValue(value, startseed); + if (integer) + param_make_integer(); + + regrandom->set_undo_parameters(SP_VERB_DIALOG_LIVE_PATH_EFFECT, _("Change random parameter")); + } + return dynamic_cast (regrandom->getR()); +} + +RandomParam::operator gdouble() +{ + return rand() * value; +}; + +/* RNG stolen from /display/nr-filter-turbulence.cpp */ +#define RAND_m 2147483647 /* 2**31 - 1 */ +#define RAND_a 16807 /* 7**5; primitive root of m */ +#define RAND_q 127773 /* m / a */ +#define RAND_r 2836 /* m % a */ +#define BSize 0x100 + +long +RandomParam::setup_seed(long lSeed) +{ + if (lSeed <= 0) lSeed = -(lSeed % (RAND_m - 1)) + 1; + if (lSeed > RAND_m - 1) lSeed = RAND_m - 1; + return lSeed; +} + +// generates random number between 0 and 1 +gdouble +RandomParam::rand() +{ + long result; + result = RAND_a * (seed % RAND_q) - RAND_r * (seed / RAND_q); + if (result <= 0) result += RAND_m; + seed = result; + + gdouble dresult = (gdouble)(result % BSize) / BSize; + return dresult; +} + + +} /* 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/parameter/random.h b/src/live_effects/parameter/random.h index 772f46ac6..55171c973 100644 --- a/src/live_effects/parameter/random.h +++ b/src/live_effects/parameter/random.h @@ -1,76 +1,76 @@ -#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_H -#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_H - -/* - * Inkscape::LivePathEffectParameters - * -* Copyright (C) Johan Engelen 2007 - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include "live_effects/parameter/parameter.h" -#include -#include <2geom/point.h> -#include <2geom/path.h> - -#include "ui/widget/registry.h" -#include "ui/widget/registered-widget.h" - -namespace Inkscape { - -namespace LivePathEffect { - -class RandomParam : public Parameter { -public: - RandomParam( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - Inkscape::UI::Widget::Registry* wr, - Effect* effect, - gdouble default_value = 1.0, - long default_seed = 0); - virtual ~RandomParam(); - - virtual bool param_readSVGValue(const gchar * strvalue); - virtual gchar * param_writeSVGValue() const; - virtual void param_set_default(); - - virtual Gtk::Widget * param_getWidget(); - - void param_set_value(gdouble val, long newseed); - void param_make_integer(bool yes = true); - void param_set_range(gdouble min, gdouble max); - - void resetRandomizer(); - - operator gdouble(); - inline gdouble get_value() - { return value; } ; - -protected: - long startseed; - long seed; - long defseed; - - gdouble value; - gdouble min; - gdouble max; - bool integer; - gdouble defvalue; - - Inkscape::UI::Widget::RegisteredRandom * regrandom; - -private: - long setup_seed(long); - gdouble rand(); - - RandomParam(const RandomParam&); - RandomParam& operator=(const RandomParam&); -}; - -} //namespace LivePathEffect - -} //namespace Inkscape - -#endif +#ifndef INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_H +#define INKSCAPE_LIVEPATHEFFECT_PARAMETER_RANDOM_H + +/* + * Inkscape::LivePathEffectParameters + * +* Copyright (C) Johan Engelen 2007 + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "live_effects/parameter/parameter.h" +#include +#include <2geom/point.h> +#include <2geom/path.h> + +#include "ui/widget/registry.h" +#include "ui/widget/registered-widget.h" + +namespace Inkscape { + +namespace LivePathEffect { + +class RandomParam : public Parameter { +public: + RandomParam( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + Inkscape::UI::Widget::Registry* wr, + Effect* effect, + gdouble default_value = 1.0, + long default_seed = 0); + virtual ~RandomParam(); + + virtual bool param_readSVGValue(const gchar * strvalue); + virtual gchar * param_writeSVGValue() const; + virtual void param_set_default(); + + virtual Gtk::Widget * param_getWidget(); + + void param_set_value(gdouble val, long newseed); + void param_make_integer(bool yes = true); + void param_set_range(gdouble min, gdouble max); + + void resetRandomizer(); + + operator gdouble(); + inline gdouble get_value() + { return value; } ; + +protected: + long startseed; + long seed; + long defseed; + + gdouble value; + gdouble min; + gdouble max; + bool integer; + gdouble defvalue; + + Inkscape::UI::Widget::RegisteredRandom * regrandom; + +private: + long setup_seed(long); + gdouble rand(); + + RandomParam(const RandomParam&); + RandomParam& operator=(const RandomParam&); +}; + +} //namespace LivePathEffect + +} //namespace Inkscape + +#endif -- 2.30.2